three.js 947 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234242352423624237242382423924240242412424224243242442424524246242472424824249242502425124252242532425424255242562425724258242592426024261242622426324264242652426624267242682426924270242712427224273242742427524276242772427824279242802428124282242832428424285242862428724288242892429024291242922429324294242952429624297242982429924300243012430224303243042430524306243072430824309243102431124312243132431424315243162431724318243192432024321243222432324324243252432624327243282432924330243312433224333243342433524336243372433824339243402434124342243432434424345243462434724348243492435024351243522435324354243552435624357243582435924360243612436224363243642436524366243672436824369243702437124372243732437424375243762437724378243792438024381243822438324384243852438624387243882438924390243912439224393243942439524396243972439824399244002440124402244032440424405244062440724408244092441024411244122441324414244152441624417244182441924420244212442224423244242442524426244272442824429244302443124432244332443424435244362443724438244392444024441244422444324444244452444624447244482444924450244512445224453244542445524456244572445824459244602446124462244632446424465244662446724468244692447024471244722447324474244752447624477244782447924480244812448224483244842448524486244872448824489244902449124492244932449424495244962449724498244992450024501245022450324504245052450624507245082450924510245112451224513245142451524516245172451824519245202452124522245232452424525245262452724528245292453024531245322453324534245352453624537245382453924540245412454224543245442454524546245472454824549245502455124552245532455424555245562455724558245592456024561245622456324564245652456624567245682456924570245712457224573245742457524576245772457824579245802458124582245832458424585245862458724588245892459024591245922459324594245952459624597245982459924600246012460224603246042460524606246072460824609246102461124612246132461424615246162461724618246192462024621246222462324624246252462624627246282462924630246312463224633246342463524636246372463824639246402464124642246432464424645246462464724648246492465024651246522465324654246552465624657246582465924660246612466224663246642466524666246672466824669246702467124672246732467424675246762467724678246792468024681246822468324684246852468624687246882468924690246912469224693246942469524696246972469824699247002470124702247032470424705247062470724708247092471024711247122471324714247152471624717247182471924720247212472224723247242472524726247272472824729247302473124732247332473424735247362473724738247392474024741247422474324744247452474624747247482474924750247512475224753247542475524756247572475824759247602476124762247632476424765247662476724768247692477024771247722477324774247752477624777247782477924780247812478224783247842478524786247872478824789247902479124792247932479424795247962479724798247992480024801248022480324804248052480624807248082480924810248112481224813248142481524816248172481824819248202482124822248232482424825248262482724828248292483024831248322483324834248352483624837248382483924840248412484224843248442484524846248472484824849248502485124852248532485424855248562485724858248592486024861248622486324864248652486624867248682486924870248712487224873248742487524876248772487824879248802488124882248832488424885248862488724888248892489024891248922489324894248952489624897248982489924900249012490224903249042490524906249072490824909249102491124912249132491424915249162491724918249192492024921249222492324924249252492624927249282492924930249312493224933249342493524936249372493824939249402494124942249432494424945249462494724948249492495024951249522495324954249552495624957249582495924960249612496224963249642496524966249672496824969249702497124972249732497424975249762497724978249792498024981249822498324984249852498624987249882498924990249912499224993249942499524996249972499824999250002500125002250032500425005250062500725008250092501025011250122501325014250152501625017250182501925020250212502225023250242502525026250272502825029250302503125032250332503425035250362503725038250392504025041250422504325044250452504625047250482504925050250512505225053250542505525056250572505825059250602506125062250632506425065250662506725068250692507025071250722507325074250752507625077250782507925080250812508225083250842508525086250872508825089250902509125092250932509425095250962509725098250992510025101251022510325104251052510625107251082510925110251112511225113251142511525116251172511825119251202512125122251232512425125251262512725128251292513025131251322513325134251352513625137251382513925140251412514225143251442514525146251472514825149251502515125152251532515425155251562515725158251592516025161251622516325164251652516625167251682516925170251712517225173251742517525176251772517825179251802518125182251832518425185251862518725188251892519025191251922519325194251952519625197251982519925200252012520225203252042520525206252072520825209252102521125212252132521425215252162521725218252192522025221252222522325224252252522625227252282522925230252312523225233252342523525236252372523825239252402524125242252432524425245252462524725248252492525025251252522525325254252552525625257252582525925260252612526225263252642526525266252672526825269252702527125272252732527425275252762527725278252792528025281252822528325284252852528625287252882528925290252912529225293252942529525296252972529825299253002530125302253032530425305253062530725308253092531025311253122531325314253152531625317253182531925320253212532225323253242532525326253272532825329253302533125332253332533425335253362533725338253392534025341253422534325344253452534625347253482534925350253512535225353253542535525356253572535825359253602536125362253632536425365253662536725368253692537025371253722537325374253752537625377253782537925380253812538225383253842538525386253872538825389253902539125392253932539425395253962539725398253992540025401254022540325404254052540625407254082540925410254112541225413254142541525416254172541825419254202542125422254232542425425254262542725428254292543025431254322543325434254352543625437254382543925440254412544225443254442544525446254472544825449254502545125452254532545425455254562545725458254592546025461254622546325464254652546625467254682546925470254712547225473254742547525476254772547825479254802548125482254832548425485254862548725488254892549025491254922549325494254952549625497254982549925500255012550225503255042550525506255072550825509255102551125512255132551425515255162551725518255192552025521255222552325524255252552625527255282552925530255312553225533255342553525536255372553825539255402554125542255432554425545255462554725548255492555025551255522555325554255552555625557255582555925560255612556225563255642556525566255672556825569255702557125572255732557425575255762557725578255792558025581255822558325584255852558625587255882558925590255912559225593255942559525596255972559825599256002560125602256032560425605256062560725608256092561025611256122561325614256152561625617256182561925620256212562225623256242562525626256272562825629256302563125632256332563425635256362563725638256392564025641256422564325644256452564625647256482564925650256512565225653256542565525656256572565825659256602566125662256632566425665256662566725668256692567025671256722567325674256752567625677256782567925680256812568225683256842568525686256872568825689256902569125692256932569425695256962569725698256992570025701257022570325704257052570625707257082570925710257112571225713257142571525716257172571825719257202572125722257232572425725257262572725728257292573025731257322573325734257352573625737257382573925740257412574225743257442574525746257472574825749257502575125752257532575425755257562575725758257592576025761257622576325764257652576625767257682576925770257712577225773257742577525776257772577825779257802578125782257832578425785257862578725788257892579025791257922579325794257952579625797257982579925800258012580225803258042580525806258072580825809258102581125812258132581425815258162581725818258192582025821258222582325824258252582625827258282582925830258312583225833258342583525836258372583825839258402584125842258432584425845258462584725848258492585025851258522585325854258552585625857258582585925860258612586225863258642586525866258672586825869258702587125872258732587425875258762587725878258792588025881258822588325884258852588625887258882588925890258912589225893258942589525896258972589825899259002590125902259032590425905259062590725908259092591025911259122591325914259152591625917259182591925920259212592225923259242592525926259272592825929259302593125932259332593425935259362593725938259392594025941259422594325944259452594625947259482594925950259512595225953259542595525956259572595825959259602596125962259632596425965259662596725968259692597025971259722597325974259752597625977259782597925980259812598225983259842598525986259872598825989259902599125992259932599425995259962599725998259992600026001260022600326004260052600626007260082600926010260112601226013260142601526016260172601826019260202602126022260232602426025260262602726028260292603026031260322603326034260352603626037260382603926040260412604226043260442604526046260472604826049260502605126052260532605426055260562605726058260592606026061260622606326064260652606626067260682606926070260712607226073260742607526076260772607826079260802608126082260832608426085260862608726088260892609026091260922609326094260952609626097260982609926100261012610226103261042610526106261072610826109261102611126112261132611426115261162611726118261192612026121261222612326124261252612626127261282612926130261312613226133261342613526136261372613826139261402614126142261432614426145261462614726148261492615026151261522615326154261552615626157261582615926160261612616226163261642616526166261672616826169261702617126172261732617426175261762617726178261792618026181261822618326184261852618626187261882618926190261912619226193261942619526196261972619826199262002620126202262032620426205262062620726208262092621026211262122621326214262152621626217262182621926220262212622226223262242622526226262272622826229262302623126232262332623426235262362623726238262392624026241262422624326244262452624626247262482624926250262512625226253262542625526256262572625826259262602626126262262632626426265262662626726268262692627026271262722627326274262752627626277262782627926280262812628226283262842628526286262872628826289262902629126292262932629426295262962629726298262992630026301263022630326304263052630626307263082630926310263112631226313263142631526316263172631826319263202632126322263232632426325263262632726328263292633026331263322633326334263352633626337263382633926340263412634226343263442634526346263472634826349263502635126352263532635426355263562635726358263592636026361263622636326364263652636626367263682636926370263712637226373263742637526376263772637826379263802638126382263832638426385263862638726388263892639026391263922639326394263952639626397263982639926400264012640226403264042640526406264072640826409264102641126412264132641426415264162641726418264192642026421264222642326424264252642626427264282642926430264312643226433264342643526436264372643826439264402644126442264432644426445264462644726448264492645026451264522645326454264552645626457264582645926460264612646226463264642646526466264672646826469264702647126472264732647426475264762647726478264792648026481264822648326484264852648626487264882648926490264912649226493264942649526496264972649826499265002650126502265032650426505265062650726508265092651026511265122651326514265152651626517265182651926520265212652226523265242652526526265272652826529265302653126532265332653426535265362653726538265392654026541265422654326544265452654626547265482654926550265512655226553265542655526556265572655826559265602656126562265632656426565265662656726568265692657026571265722657326574265752657626577265782657926580265812658226583265842658526586265872658826589265902659126592265932659426595265962659726598265992660026601266022660326604266052660626607266082660926610266112661226613266142661526616266172661826619266202662126622266232662426625266262662726628266292663026631266322663326634266352663626637266382663926640266412664226643266442664526646266472664826649266502665126652266532665426655266562665726658266592666026661266622666326664266652666626667266682666926670266712667226673266742667526676266772667826679266802668126682266832668426685266862668726688266892669026691266922669326694266952669626697266982669926700267012670226703267042670526706267072670826709267102671126712267132671426715267162671726718267192672026721267222672326724267252672626727267282672926730267312673226733267342673526736267372673826739267402674126742267432674426745267462674726748267492675026751267522675326754267552675626757267582675926760267612676226763267642676526766267672676826769267702677126772267732677426775267762677726778267792678026781267822678326784267852678626787267882678926790267912679226793267942679526796267972679826799268002680126802268032680426805268062680726808268092681026811268122681326814268152681626817268182681926820268212682226823268242682526826268272682826829268302683126832268332683426835268362683726838268392684026841268422684326844268452684626847268482684926850268512685226853268542685526856268572685826859268602686126862268632686426865268662686726868268692687026871268722687326874268752687626877268782687926880268812688226883268842688526886268872688826889268902689126892268932689426895268962689726898268992690026901269022690326904269052690626907269082690926910269112691226913269142691526916269172691826919269202692126922269232692426925269262692726928269292693026931269322693326934269352693626937269382693926940269412694226943269442694526946269472694826949269502695126952269532695426955269562695726958269592696026961269622696326964269652696626967269682696926970269712697226973269742697526976269772697826979269802698126982269832698426985269862698726988269892699026991269922699326994269952699626997269982699927000270012700227003270042700527006270072700827009270102701127012270132701427015270162701727018270192702027021270222702327024270252702627027270282702927030270312703227033270342703527036270372703827039270402704127042270432704427045270462704727048270492705027051270522705327054270552705627057270582705927060270612706227063270642706527066270672706827069270702707127072270732707427075270762707727078270792708027081270822708327084270852708627087270882708927090270912709227093270942709527096270972709827099271002710127102271032710427105271062710727108271092711027111271122711327114271152711627117271182711927120271212712227123271242712527126271272712827129271302713127132271332713427135271362713727138271392714027141271422714327144271452714627147271482714927150271512715227153271542715527156271572715827159271602716127162271632716427165271662716727168271692717027171271722717327174271752717627177271782717927180271812718227183271842718527186271872718827189271902719127192271932719427195271962719727198271992720027201272022720327204272052720627207272082720927210272112721227213272142721527216272172721827219272202722127222272232722427225272262722727228272292723027231272322723327234272352723627237272382723927240272412724227243272442724527246272472724827249272502725127252272532725427255272562725727258272592726027261272622726327264272652726627267272682726927270272712727227273272742727527276272772727827279272802728127282272832728427285272862728727288272892729027291272922729327294272952729627297272982729927300273012730227303273042730527306273072730827309273102731127312273132731427315273162731727318273192732027321273222732327324273252732627327273282732927330273312733227333273342733527336273372733827339273402734127342273432734427345273462734727348273492735027351273522735327354273552735627357273582735927360273612736227363273642736527366273672736827369273702737127372273732737427375273762737727378273792738027381273822738327384273852738627387273882738927390273912739227393273942739527396273972739827399274002740127402274032740427405274062740727408274092741027411274122741327414274152741627417274182741927420274212742227423274242742527426274272742827429274302743127432274332743427435274362743727438274392744027441274422744327444274452744627447274482744927450274512745227453274542745527456274572745827459274602746127462274632746427465274662746727468274692747027471274722747327474274752747627477274782747927480274812748227483274842748527486274872748827489274902749127492274932749427495274962749727498274992750027501275022750327504275052750627507275082750927510275112751227513275142751527516275172751827519275202752127522275232752427525275262752727528275292753027531275322753327534275352753627537275382753927540275412754227543275442754527546275472754827549275502755127552275532755427555275562755727558275592756027561275622756327564275652756627567275682756927570275712757227573275742757527576275772757827579275802758127582275832758427585275862758727588275892759027591275922759327594275952759627597275982759927600276012760227603276042760527606276072760827609276102761127612276132761427615276162761727618276192762027621276222762327624276252762627627276282762927630276312763227633276342763527636276372763827639276402764127642276432764427645276462764727648276492765027651276522765327654276552765627657276582765927660276612766227663276642766527666276672766827669276702767127672276732767427675276762767727678276792768027681276822768327684276852768627687276882768927690276912769227693276942769527696276972769827699277002770127702277032770427705277062770727708277092771027711277122771327714277152771627717277182771927720277212772227723277242772527726277272772827729277302773127732277332773427735277362773727738277392774027741277422774327744277452774627747277482774927750277512775227753277542775527756277572775827759277602776127762277632776427765277662776727768277692777027771277722777327774277752777627777277782777927780277812778227783277842778527786277872778827789277902779127792277932779427795277962779727798277992780027801278022780327804278052780627807278082780927810278112781227813278142781527816278172781827819278202782127822278232782427825278262782727828278292783027831278322783327834278352783627837278382783927840278412784227843278442784527846278472784827849278502785127852278532785427855278562785727858278592786027861278622786327864278652786627867278682786927870278712787227873278742787527876278772787827879278802788127882278832788427885278862788727888278892789027891278922789327894278952789627897278982789927900279012790227903279042790527906279072790827909279102791127912279132791427915279162791727918279192792027921279222792327924279252792627927279282792927930279312793227933279342793527936279372793827939279402794127942279432794427945279462794727948279492795027951279522795327954279552795627957279582795927960279612796227963279642796527966279672796827969279702797127972279732797427975279762797727978279792798027981279822798327984279852798627987279882798927990279912799227993279942799527996279972799827999280002800128002280032800428005280062800728008280092801028011280122801328014280152801628017280182801928020280212802228023280242802528026280272802828029280302803128032280332803428035280362803728038280392804028041280422804328044280452804628047280482804928050280512805228053280542805528056280572805828059280602806128062280632806428065280662806728068280692807028071280722807328074280752807628077280782807928080280812808228083280842808528086280872808828089280902809128092280932809428095280962809728098280992810028101281022810328104281052810628107281082810928110281112811228113281142811528116281172811828119281202812128122281232812428125281262812728128281292813028131281322813328134281352813628137281382813928140281412814228143281442814528146281472814828149281502815128152281532815428155281562815728158281592816028161281622816328164281652816628167281682816928170281712817228173281742817528176281772817828179281802818128182281832818428185281862818728188281892819028191281922819328194281952819628197281982819928200282012820228203282042820528206282072820828209282102821128212282132821428215282162821728218282192822028221282222822328224282252822628227282282822928230282312823228233282342823528236282372823828239282402824128242282432824428245282462824728248282492825028251282522825328254282552825628257282582825928260282612826228263282642826528266282672826828269282702827128272282732827428275282762827728278282792828028281282822828328284282852828628287282882828928290282912829228293282942829528296282972829828299283002830128302283032830428305283062830728308283092831028311283122831328314283152831628317283182831928320283212832228323283242832528326283272832828329283302833128332283332833428335283362833728338283392834028341283422834328344283452834628347283482834928350283512835228353283542835528356283572835828359283602836128362283632836428365283662836728368283692837028371283722837328374283752837628377283782837928380283812838228383283842838528386283872838828389283902839128392283932839428395283962839728398283992840028401284022840328404284052840628407284082840928410284112841228413284142841528416284172841828419284202842128422284232842428425284262842728428284292843028431284322843328434284352843628437284382843928440284412844228443284442844528446284472844828449284502845128452284532845428455284562845728458284592846028461284622846328464284652846628467284682846928470284712847228473284742847528476284772847828479284802848128482284832848428485284862848728488284892849028491284922849328494284952849628497284982849928500285012850228503285042850528506285072850828509285102851128512285132851428515285162851728518285192852028521285222852328524285252852628527285282852928530285312853228533285342853528536285372853828539285402854128542285432854428545285462854728548285492855028551285522855328554285552855628557285582855928560285612856228563285642856528566285672856828569285702857128572285732857428575285762857728578285792858028581285822858328584285852858628587285882858928590285912859228593285942859528596285972859828599286002860128602286032860428605286062860728608286092861028611286122861328614286152861628617286182861928620286212862228623286242862528626286272862828629286302863128632286332863428635286362863728638286392864028641286422864328644286452864628647286482864928650286512865228653286542865528656286572865828659286602866128662286632866428665286662866728668286692867028671286722867328674286752867628677286782867928680286812868228683286842868528686286872868828689286902869128692286932869428695286962869728698286992870028701287022870328704287052870628707287082870928710287112871228713287142871528716287172871828719287202872128722287232872428725287262872728728287292873028731287322873328734287352873628737287382873928740287412874228743287442874528746287472874828749287502875128752287532875428755287562875728758287592876028761287622876328764287652876628767287682876928770287712877228773287742877528776287772877828779287802878128782287832878428785287862878728788287892879028791287922879328794287952879628797287982879928800288012880228803288042880528806288072880828809288102881128812288132881428815288162881728818288192882028821288222882328824288252882628827288282882928830288312883228833288342883528836288372883828839288402884128842288432884428845288462884728848288492885028851288522885328854288552885628857288582885928860288612886228863288642886528866288672886828869288702887128872288732887428875288762887728878288792888028881288822888328884288852888628887288882888928890288912889228893288942889528896288972889828899289002890128902289032890428905289062890728908289092891028911289122891328914289152891628917289182891928920289212892228923289242892528926289272892828929289302893128932289332893428935289362893728938289392894028941289422894328944289452894628947289482894928950289512895228953289542895528956289572895828959289602896128962289632896428965289662896728968289692897028971289722897328974289752897628977289782897928980289812898228983289842898528986289872898828989289902899128992289932899428995289962899728998289992900029001290022900329004290052900629007290082900929010290112901229013290142901529016290172901829019290202902129022290232902429025290262902729028290292903029031290322903329034290352903629037290382903929040290412904229043290442904529046290472904829049290502905129052290532905429055290562905729058290592906029061290622906329064290652906629067290682906929070290712907229073290742907529076290772907829079290802908129082290832908429085290862908729088290892909029091290922909329094290952909629097290982909929100291012910229103291042910529106291072910829109291102911129112291132911429115291162911729118291192912029121291222912329124291252912629127291282912929130291312913229133291342913529136291372913829139291402914129142291432914429145291462914729148291492915029151291522915329154291552915629157291582915929160291612916229163291642916529166291672916829169291702917129172291732917429175291762917729178291792918029181291822918329184291852918629187291882918929190291912919229193291942919529196291972919829199292002920129202292032920429205292062920729208292092921029211292122921329214292152921629217292182921929220292212922229223292242922529226292272922829229292302923129232292332923429235292362923729238292392924029241292422924329244292452924629247292482924929250292512925229253292542925529256292572925829259292602926129262292632926429265292662926729268292692927029271292722927329274292752927629277292782927929280292812928229283292842928529286292872928829289292902929129292292932929429295292962929729298292992930029301293022930329304293052930629307293082930929310293112931229313293142931529316293172931829319293202932129322293232932429325293262932729328293292933029331293322933329334293352933629337293382933929340293412934229343293442934529346293472934829349293502935129352293532935429355293562935729358293592936029361293622936329364293652936629367293682936929370293712937229373293742937529376293772937829379293802938129382293832938429385293862938729388293892939029391293922939329394293952939629397293982939929400294012940229403294042940529406294072940829409294102941129412294132941429415294162941729418294192942029421294222942329424294252942629427294282942929430294312943229433294342943529436294372943829439294402944129442294432944429445294462944729448294492945029451294522945329454294552945629457294582945929460294612946229463294642946529466294672946829469294702947129472294732947429475294762947729478294792948029481294822948329484294852948629487294882948929490294912949229493294942949529496294972949829499295002950129502295032950429505295062950729508295092951029511295122951329514295152951629517295182951929520295212952229523295242952529526295272952829529295302953129532295332953429535295362953729538295392954029541295422954329544295452954629547295482954929550295512955229553295542955529556295572955829559295602956129562295632956429565295662956729568295692957029571295722957329574295752957629577295782957929580295812958229583295842958529586295872958829589295902959129592295932959429595295962959729598295992960029601296022960329604296052960629607296082960929610296112961229613296142961529616296172961829619296202962129622296232962429625296262962729628296292963029631296322963329634296352963629637296382963929640296412964229643296442964529646296472964829649296502965129652296532965429655296562965729658296592966029661296622966329664296652966629667296682966929670296712967229673296742967529676296772967829679296802968129682296832968429685296862968729688296892969029691296922969329694296952969629697296982969929700297012970229703297042970529706297072970829709297102971129712297132971429715297162971729718297192972029721297222972329724297252972629727297282972929730297312973229733297342973529736297372973829739297402974129742297432974429745297462974729748297492975029751297522975329754297552975629757297582975929760297612976229763297642976529766297672976829769297702977129772297732977429775297762977729778297792978029781297822978329784297852978629787297882978929790297912979229793297942979529796297972979829799298002980129802298032980429805298062980729808298092981029811298122981329814298152981629817298182981929820298212982229823298242982529826298272982829829298302983129832298332983429835298362983729838298392984029841298422984329844298452984629847298482984929850298512985229853298542985529856298572985829859298602986129862298632986429865298662986729868298692987029871298722987329874298752987629877298782987929880298812988229883298842988529886298872988829889298902989129892298932989429895298962989729898298992990029901299022990329904299052990629907299082990929910299112991229913299142991529916299172991829919299202992129922299232992429925299262992729928299292993029931299322993329934299352993629937299382993929940299412994229943299442994529946299472994829949299502995129952299532995429955299562995729958299592996029961299622996329964299652996629967299682996929970299712997229973299742997529976299772997829979299802998129982299832998429985299862998729988299892999029991299922999329994299952999629997299982999930000300013000230003300043000530006300073000830009300103001130012300133001430015300163001730018300193002030021300223002330024300253002630027300283002930030300313003230033300343003530036300373003830039300403004130042300433004430045300463004730048300493005030051300523005330054300553005630057300583005930060300613006230063300643006530066300673006830069300703007130072300733007430075300763007730078300793008030081300823008330084300853008630087300883008930090300913009230093300943009530096300973009830099301003010130102301033010430105301063010730108301093011030111301123011330114301153011630117301183011930120301213012230123301243012530126301273012830129301303013130132301333013430135301363013730138301393014030141301423014330144301453014630147301483014930150301513015230153301543015530156301573015830159301603016130162301633016430165301663016730168301693017030171301723017330174301753017630177301783017930180301813018230183301843018530186301873018830189301903019130192301933019430195301963019730198301993020030201302023020330204302053020630207302083020930210302113021230213302143021530216302173021830219302203022130222302233022430225302263022730228302293023030231302323023330234302353023630237302383023930240302413024230243302443024530246302473024830249302503025130252302533025430255302563025730258302593026030261302623026330264302653026630267302683026930270302713027230273302743027530276302773027830279302803028130282302833028430285302863028730288302893029030291302923029330294302953029630297302983029930300303013030230303303043030530306303073030830309303103031130312303133031430315303163031730318303193032030321303223032330324303253032630327303283032930330303313033230333303343033530336303373033830339303403034130342303433034430345303463034730348303493035030351303523035330354303553035630357303583035930360303613036230363303643036530366303673036830369303703037130372303733037430375303763037730378303793038030381303823038330384303853038630387303883038930390303913039230393303943039530396303973039830399304003040130402304033040430405304063040730408304093041030411304123041330414304153041630417304183041930420304213042230423304243042530426304273042830429304303043130432304333043430435304363043730438304393044030441304423044330444304453044630447304483044930450304513045230453304543045530456304573045830459304603046130462304633046430465304663046730468304693047030471304723047330474304753047630477304783047930480304813048230483304843048530486304873048830489304903049130492304933049430495304963049730498304993050030501305023050330504305053050630507305083050930510305113051230513305143051530516305173051830519305203052130522305233052430525305263052730528305293053030531305323053330534305353053630537305383053930540305413054230543305443054530546305473054830549305503055130552305533055430555305563055730558305593056030561305623056330564305653056630567305683056930570305713057230573305743057530576305773057830579305803058130582305833058430585305863058730588305893059030591305923059330594305953059630597305983059930600306013060230603306043060530606306073060830609306103061130612306133061430615306163061730618306193062030621306223062330624306253062630627306283062930630306313063230633306343063530636306373063830639306403064130642306433064430645306463064730648306493065030651306523065330654306553065630657306583065930660306613066230663306643066530666306673066830669306703067130672306733067430675306763067730678306793068030681306823068330684306853068630687306883068930690306913069230693306943069530696306973069830699307003070130702307033070430705307063070730708307093071030711307123071330714307153071630717307183071930720307213072230723307243072530726307273072830729307303073130732307333073430735307363073730738307393074030741307423074330744307453074630747307483074930750307513075230753307543075530756307573075830759307603076130762307633076430765307663076730768307693077030771307723077330774307753077630777307783077930780307813078230783307843078530786307873078830789307903079130792307933079430795307963079730798307993080030801308023080330804308053080630807308083080930810308113081230813308143081530816308173081830819308203082130822308233082430825308263082730828308293083030831308323083330834308353083630837308383083930840308413084230843308443084530846308473084830849308503085130852308533085430855308563085730858308593086030861308623086330864308653086630867308683086930870308713087230873308743087530876308773087830879308803088130882308833088430885308863088730888308893089030891308923089330894308953089630897308983089930900309013090230903309043090530906309073090830909309103091130912309133091430915309163091730918309193092030921309223092330924309253092630927309283092930930309313093230933309343093530936309373093830939309403094130942309433094430945309463094730948309493095030951309523095330954309553095630957309583095930960309613096230963309643096530966309673096830969309703097130972309733097430975309763097730978309793098030981309823098330984309853098630987309883098930990309913099230993309943099530996309973099830999310003100131002310033100431005310063100731008310093101031011310123101331014310153101631017310183101931020310213102231023310243102531026310273102831029310303103131032310333103431035310363103731038310393104031041310423104331044310453104631047310483104931050310513105231053310543105531056310573105831059310603106131062310633106431065310663106731068310693107031071310723107331074310753107631077310783107931080310813108231083310843108531086310873108831089310903109131092310933109431095310963109731098310993110031101311023110331104311053110631107311083110931110311113111231113311143111531116311173111831119311203112131122311233112431125311263112731128311293113031131311323113331134311353113631137311383113931140311413114231143311443114531146311473114831149311503115131152311533115431155311563115731158311593116031161311623116331164311653116631167311683116931170311713117231173311743117531176311773117831179311803118131182311833118431185311863118731188311893119031191311923119331194311953119631197311983119931200312013120231203312043120531206312073120831209312103121131212312133121431215312163121731218312193122031221312223122331224312253122631227312283122931230312313123231233312343123531236312373123831239312403124131242312433124431245312463124731248312493125031251312523125331254312553125631257312583125931260312613126231263312643126531266312673126831269312703127131272312733127431275312763127731278312793128031281312823128331284312853128631287312883128931290312913129231293312943129531296312973129831299313003130131302313033130431305313063130731308313093131031311313123131331314313153131631317313183131931320313213132231323313243132531326313273132831329313303133131332313333133431335313363133731338313393134031341313423134331344313453134631347313483134931350313513135231353313543135531356313573135831359313603136131362313633136431365313663136731368313693137031371313723137331374313753137631377313783137931380313813138231383313843138531386313873138831389313903139131392313933139431395313963139731398313993140031401314023140331404314053140631407314083140931410314113141231413314143141531416314173141831419314203142131422314233142431425314263142731428314293143031431314323143331434314353143631437314383143931440314413144231443314443144531446314473144831449314503145131452314533145431455314563145731458314593146031461314623146331464314653146631467314683146931470314713147231473314743147531476314773147831479314803148131482314833148431485314863148731488314893149031491314923149331494314953149631497314983149931500315013150231503315043150531506315073150831509315103151131512315133151431515315163151731518315193152031521315223152331524315253152631527315283152931530315313153231533315343153531536315373153831539315403154131542315433154431545315463154731548315493155031551315523155331554315553155631557315583155931560315613156231563315643156531566315673156831569315703157131572315733157431575315763157731578315793158031581315823158331584315853158631587315883158931590315913159231593315943159531596315973159831599316003160131602316033160431605316063160731608316093161031611316123161331614316153161631617316183161931620316213162231623316243162531626316273162831629316303163131632316333163431635316363163731638316393164031641316423164331644316453164631647316483164931650316513165231653316543165531656316573165831659316603166131662316633166431665316663166731668316693167031671316723167331674316753167631677316783167931680316813168231683316843168531686316873168831689316903169131692316933169431695316963169731698316993170031701317023170331704317053170631707317083170931710317113171231713317143171531716317173171831719317203172131722317233172431725317263172731728317293173031731317323173331734317353173631737317383173931740317413174231743317443174531746317473174831749317503175131752317533175431755317563175731758317593176031761317623176331764317653176631767317683176931770317713177231773317743177531776317773177831779317803178131782317833178431785317863178731788317893179031791317923179331794317953179631797317983179931800318013180231803318043180531806318073180831809318103181131812318133181431815318163181731818318193182031821318223182331824318253182631827318283182931830318313183231833318343183531836318373183831839318403184131842318433184431845318463184731848318493185031851318523185331854318553185631857318583185931860318613186231863318643186531866318673186831869318703187131872318733187431875318763187731878318793188031881318823188331884318853188631887318883188931890318913189231893318943189531896318973189831899319003190131902319033190431905319063190731908319093191031911319123191331914319153191631917319183191931920319213192231923319243192531926319273192831929319303193131932319333193431935319363193731938319393194031941319423194331944319453194631947319483194931950319513195231953319543195531956319573195831959319603196131962319633196431965319663196731968319693197031971319723197331974319753197631977319783197931980319813198231983319843198531986319873198831989319903199131992319933199431995319963199731998319993200032001320023200332004320053200632007320083200932010320113201232013320143201532016320173201832019320203202132022320233202432025320263202732028320293203032031320323203332034320353203632037320383203932040320413204232043320443204532046320473204832049320503205132052320533205432055320563205732058320593206032061320623206332064320653206632067320683206932070320713207232073320743207532076320773207832079320803208132082320833208432085320863208732088320893209032091320923209332094320953209632097320983209932100321013210232103321043210532106321073210832109321103211132112321133211432115321163211732118321193212032121321223212332124321253212632127321283212932130321313213232133321343213532136321373213832139321403214132142321433214432145321463214732148321493215032151321523215332154321553215632157321583215932160321613216232163321643216532166321673216832169321703217132172321733217432175321763217732178321793218032181321823218332184321853218632187321883218932190321913219232193321943219532196321973219832199322003220132202322033220432205322063220732208322093221032211322123221332214322153221632217322183221932220322213222232223322243222532226322273222832229322303223132232322333223432235322363223732238322393224032241322423224332244322453224632247322483224932250322513225232253322543225532256322573225832259322603226132262322633226432265322663226732268322693227032271322723227332274322753227632277322783227932280322813228232283322843228532286322873228832289322903229132292322933229432295322963229732298322993230032301323023230332304323053230632307323083230932310323113231232313323143231532316323173231832319323203232132322323233232432325323263232732328323293233032331323323233332334323353233632337323383233932340323413234232343323443234532346323473234832349323503235132352323533235432355323563235732358323593236032361323623236332364323653236632367323683236932370323713237232373323743237532376323773237832379323803238132382323833238432385323863238732388323893239032391323923239332394323953239632397323983239932400324013240232403324043240532406324073240832409324103241132412324133241432415324163241732418324193242032421324223242332424324253242632427324283242932430324313243232433324343243532436324373243832439324403244132442324433244432445324463244732448324493245032451324523245332454324553245632457324583245932460324613246232463324643246532466324673246832469324703247132472324733247432475324763247732478324793248032481324823248332484324853248632487324883248932490324913249232493324943249532496324973249832499325003250132502325033250432505325063250732508325093251032511325123251332514325153251632517325183251932520325213252232523325243252532526325273252832529325303253132532325333253432535325363253732538325393254032541325423254332544325453254632547325483254932550325513255232553325543255532556325573255832559325603256132562325633256432565325663256732568325693257032571325723257332574325753257632577325783257932580325813258232583325843258532586325873258832589325903259132592325933259432595325963259732598325993260032601326023260332604326053260632607326083260932610326113261232613326143261532616326173261832619326203262132622326233262432625326263262732628326293263032631326323263332634326353263632637326383263932640326413264232643326443264532646326473264832649326503265132652326533265432655326563265732658326593266032661326623266332664326653266632667326683266932670326713267232673326743267532676326773267832679326803268132682326833268432685326863268732688326893269032691326923269332694326953269632697326983269932700327013270232703327043270532706327073270832709327103271132712327133271432715327163271732718327193272032721327223272332724327253272632727327283272932730327313273232733327343273532736327373273832739327403274132742327433274432745327463274732748327493275032751327523275332754327553275632757327583275932760327613276232763327643276532766327673276832769327703277132772327733277432775327763277732778327793278032781327823278332784327853278632787327883278932790327913279232793327943279532796327973279832799328003280132802328033280432805328063280732808328093281032811328123281332814328153281632817328183281932820328213282232823328243282532826328273282832829328303283132832328333283432835328363283732838328393284032841328423284332844328453284632847328483284932850328513285232853328543285532856328573285832859328603286132862328633286432865328663286732868328693287032871328723287332874328753287632877328783287932880328813288232883328843288532886328873288832889328903289132892328933289432895328963289732898328993290032901329023290332904329053290632907329083290932910329113291232913329143291532916329173291832919329203292132922329233292432925329263292732928329293293032931329323293332934329353293632937329383293932940329413294232943329443294532946329473294832949329503295132952329533295432955329563295732958329593296032961329623296332964329653296632967329683296932970329713297232973329743297532976329773297832979329803298132982329833298432985329863298732988329893299032991329923299332994329953299632997329983299933000330013300233003330043300533006330073300833009330103301133012330133301433015330163301733018330193302033021330223302333024330253302633027330283302933030330313303233033330343303533036330373303833039330403304133042330433304433045330463304733048330493305033051330523305333054330553305633057330583305933060330613306233063330643306533066330673306833069330703307133072330733307433075330763307733078330793308033081330823308333084330853308633087330883308933090330913309233093330943309533096330973309833099331003310133102331033310433105331063310733108331093311033111331123311333114331153311633117331183311933120331213312233123331243312533126331273312833129331303313133132331333313433135331363313733138331393314033141331423314333144331453314633147331483314933150331513315233153331543315533156331573315833159331603316133162331633316433165331663316733168331693317033171331723317333174331753317633177331783317933180331813318233183331843318533186331873318833189331903319133192331933319433195331963319733198331993320033201332023320333204332053320633207332083320933210332113321233213332143321533216332173321833219332203322133222332233322433225332263322733228332293323033231332323323333234332353323633237332383323933240332413324233243332443324533246332473324833249332503325133252332533325433255332563325733258332593326033261332623326333264332653326633267332683326933270332713327233273332743327533276332773327833279332803328133282332833328433285332863328733288332893329033291332923329333294332953329633297332983329933300333013330233303333043330533306333073330833309333103331133312333133331433315333163331733318333193332033321333223332333324333253332633327333283332933330333313333233333333343333533336333373333833339333403334133342333433334433345333463334733348333493335033351333523335333354333553335633357333583335933360333613336233363333643336533366333673336833369333703337133372333733337433375333763337733378333793338033381333823338333384333853338633387333883338933390333913339233393333943339533396333973339833399334003340133402334033340433405334063340733408334093341033411334123341333414334153341633417334183341933420334213342233423334243342533426334273342833429334303343133432334333343433435334363343733438334393344033441334423344333444334453344633447334483344933450334513345233453334543345533456334573345833459334603346133462334633346433465334663346733468334693347033471334723347333474334753347633477334783347933480334813348233483334843348533486334873348833489334903349133492334933349433495334963349733498334993350033501335023350333504335053350633507335083350933510335113351233513335143351533516335173351833519335203352133522335233352433525335263352733528335293353033531335323353333534335353353633537335383353933540335413354233543335443354533546335473354833549335503355133552335533355433555335563355733558335593356033561335623356333564335653356633567335683356933570335713357233573335743357533576335773357833579335803358133582335833358433585335863358733588335893359033591335923359333594335953359633597335983359933600336013360233603336043360533606336073360833609336103361133612336133361433615336163361733618336193362033621336223362333624336253362633627336283362933630336313363233633336343363533636336373363833639336403364133642336433364433645336463364733648336493365033651336523365333654336553365633657336583365933660336613366233663336643366533666336673366833669336703367133672336733367433675336763367733678336793368033681336823368333684336853368633687336883368933690336913369233693336943369533696336973369833699337003370133702337033370433705337063370733708337093371033711337123371333714337153371633717337183371933720337213372233723337243372533726337273372833729337303373133732337333373433735337363373733738337393374033741337423374333744337453374633747337483374933750337513375233753337543375533756337573375833759337603376133762337633376433765337663376733768337693377033771337723377333774337753377633777337783377933780337813378233783337843378533786337873378833789337903379133792337933379433795337963379733798337993380033801338023380333804338053380633807338083380933810338113381233813338143381533816338173381833819338203382133822338233382433825338263382733828338293383033831338323383333834338353383633837338383383933840338413384233843338443384533846338473384833849338503385133852338533385433855338563385733858338593386033861338623386333864338653386633867338683386933870338713387233873338743387533876338773387833879338803388133882338833388433885338863388733888338893389033891338923389333894338953389633897338983389933900339013390233903339043390533906339073390833909339103391133912339133391433915339163391733918339193392033921339223392333924339253392633927339283392933930339313393233933339343393533936339373393833939339403394133942339433394433945339463394733948339493395033951339523395333954339553395633957339583395933960339613396233963339643396533966339673396833969339703397133972339733397433975339763397733978339793398033981339823398333984339853398633987339883398933990339913399233993339943399533996339973399833999340003400134002340033400434005340063400734008340093401034011340123401334014340153401634017340183401934020340213402234023340243402534026340273402834029340303403134032340333403434035340363403734038340393404034041340423404334044340453404634047340483404934050340513405234053340543405534056340573405834059340603406134062340633406434065340663406734068340693407034071340723407334074340753407634077340783407934080340813408234083340843408534086340873408834089340903409134092340933409434095340963409734098340993410034101341023410334104341053410634107341083410934110341113411234113341143411534116341173411834119341203412134122341233412434125341263412734128341293413034131341323413334134341353413634137341383413934140341413414234143341443414534146341473414834149341503415134152341533415434155341563415734158341593416034161341623416334164341653416634167341683416934170341713417234173341743417534176341773417834179341803418134182341833418434185341863418734188341893419034191341923419334194341953419634197341983419934200342013420234203342043420534206342073420834209342103421134212342133421434215342163421734218342193422034221342223422334224342253422634227342283422934230342313423234233342343423534236342373423834239342403424134242342433424434245342463424734248342493425034251342523425334254342553425634257342583425934260342613426234263342643426534266342673426834269342703427134272342733427434275342763427734278342793428034281342823428334284342853428634287342883428934290342913429234293342943429534296342973429834299343003430134302343033430434305343063430734308343093431034311343123431334314343153431634317343183431934320343213432234323343243432534326343273432834329343303433134332343333433434335343363433734338343393434034341343423434334344343453434634347343483434934350343513435234353343543435534356343573435834359343603436134362343633436434365343663436734368343693437034371343723437334374343753437634377343783437934380343813438234383343843438534386343873438834389343903439134392343933439434395343963439734398343993440034401344023440334404344053440634407344083440934410344113441234413344143441534416344173441834419344203442134422344233442434425344263442734428344293443034431344323443334434344353443634437344383443934440344413444234443344443444534446344473444834449344503445134452344533445434455344563445734458344593446034461344623446334464344653446634467344683446934470344713447234473344743447534476344773447834479344803448134482344833448434485344863448734488344893449034491344923449334494344953449634497344983449934500345013450234503345043450534506345073450834509345103451134512345133451434515345163451734518345193452034521345223452334524345253452634527345283452934530345313453234533345343453534536345373453834539345403454134542345433454434545345463454734548345493455034551345523455334554345553455634557345583455934560345613456234563345643456534566345673456834569345703457134572345733457434575345763457734578345793458034581345823458334584345853458634587345883458934590345913459234593345943459534596345973459834599346003460134602346033460434605346063460734608346093461034611346123461334614346153461634617346183461934620346213462234623346243462534626346273462834629346303463134632346333463434635346363463734638346393464034641346423464334644346453464634647346483464934650346513465234653346543465534656346573465834659346603466134662346633466434665346663466734668346693467034671346723467334674346753467634677346783467934680346813468234683346843468534686346873468834689346903469134692346933469434695346963469734698346993470034701347023470334704347053470634707347083470934710347113471234713347143471534716347173471834719347203472134722347233472434725347263472734728347293473034731347323473334734347353473634737347383473934740347413474234743347443474534746347473474834749347503475134752347533475434755347563475734758347593476034761347623476334764347653476634767347683476934770347713477234773347743477534776347773477834779347803478134782347833478434785347863478734788347893479034791347923479334794347953479634797347983479934800348013480234803348043480534806348073480834809348103481134812348133481434815348163481734818348193482034821348223482334824348253482634827348283482934830348313483234833348343483534836348373483834839348403484134842348433484434845348463484734848348493485034851348523485334854348553485634857348583485934860348613486234863348643486534866348673486834869348703487134872348733487434875348763487734878348793488034881348823488334884348853488634887348883488934890348913489234893348943489534896348973489834899349003490134902349033490434905349063490734908349093491034911349123491334914349153491634917349183491934920349213492234923349243492534926349273492834929349303493134932349333493434935349363493734938349393494034941349423494334944349453494634947349483494934950349513495234953349543495534956349573495834959349603496134962349633496434965349663496734968349693497034971349723497334974349753497634977349783497934980349813498234983349843498534986349873498834989349903499134992349933499434995349963499734998349993500035001350023500335004350053500635007350083500935010350113501235013350143501535016350173501835019350203502135022350233502435025350263502735028350293503035031350323503335034350353503635037350383503935040350413504235043350443504535046350473504835049350503505135052350533505435055350563505735058350593506035061350623506335064350653506635067350683506935070350713507235073350743507535076350773507835079350803508135082350833508435085350863508735088350893509035091350923509335094350953509635097350983509935100351013510235103351043510535106351073510835109351103511135112351133511435115351163511735118351193512035121351223512335124351253512635127351283512935130351313513235133351343513535136351373513835139351403514135142351433514435145351463514735148351493515035151351523515335154351553515635157351583515935160351613516235163351643516535166351673516835169351703517135172351733517435175351763517735178351793518035181351823518335184351853518635187351883518935190351913519235193351943519535196351973519835199352003520135202352033520435205352063520735208352093521035211352123521335214352153521635217352183521935220352213522235223352243522535226352273522835229352303523135232352333523435235352363523735238352393524035241352423524335244352453524635247352483524935250352513525235253352543525535256352573525835259352603526135262352633526435265352663526735268352693527035271352723527335274352753527635277352783527935280352813528235283352843528535286352873528835289352903529135292352933529435295352963529735298352993530035301353023530335304353053530635307353083530935310353113531235313353143531535316353173531835319353203532135322353233532435325353263532735328353293533035331353323533335334353353533635337353383533935340353413534235343353443534535346353473534835349353503535135352353533535435355353563535735358353593536035361353623536335364353653536635367353683536935370353713537235373353743537535376353773537835379353803538135382353833538435385353863538735388353893539035391353923539335394353953539635397353983539935400354013540235403354043540535406354073540835409354103541135412354133541435415354163541735418354193542035421354223542335424354253542635427354283542935430354313543235433354343543535436354373543835439354403544135442354433544435445354463544735448354493545035451354523545335454354553545635457354583545935460354613546235463354643546535466354673546835469354703547135472354733547435475354763547735478354793548035481354823548335484354853548635487354883548935490354913549235493354943549535496354973549835499355003550135502355033550435505355063550735508355093551035511355123551335514355153551635517355183551935520355213552235523355243552535526355273552835529355303553135532355333553435535355363553735538355393554035541355423554335544355453554635547355483554935550355513555235553355543555535556355573555835559355603556135562355633556435565355663556735568355693557035571355723557335574355753557635577355783557935580355813558235583355843558535586355873558835589355903559135592355933559435595355963559735598355993560035601356023560335604356053560635607356083560935610356113561235613356143561535616356173561835619356203562135622356233562435625356263562735628356293563035631356323563335634356353563635637356383563935640356413564235643356443564535646356473564835649356503565135652356533565435655356563565735658356593566035661356623566335664356653566635667356683566935670356713567235673356743567535676356773567835679356803568135682356833568435685356863568735688356893569035691356923569335694356953569635697356983569935700357013570235703357043570535706357073570835709357103571135712357133571435715357163571735718357193572035721357223572335724357253572635727357283572935730357313573235733357343573535736357373573835739357403574135742357433574435745357463574735748357493575035751357523575335754357553575635757357583575935760357613576235763357643576535766357673576835769357703577135772357733577435775357763577735778357793578035781357823578335784357853578635787357883578935790357913579235793357943579535796357973579835799358003580135802358033580435805358063580735808358093581035811358123581335814358153581635817358183581935820358213582235823358243582535826358273582835829358303583135832358333583435835358363583735838358393584035841358423584335844358453584635847358483584935850358513585235853358543585535856358573585835859358603586135862358633586435865358663586735868358693587035871358723587335874358753587635877358783587935880358813588235883358843588535886358873588835889358903589135892358933589435895358963589735898358993590035901359023590335904359053590635907359083590935910359113591235913359143591535916359173591835919359203592135922359233592435925359263592735928359293593035931359323593335934359353593635937359383593935940359413594235943359443594535946359473594835949359503595135952359533595435955359563595735958359593596035961359623596335964359653596635967359683596935970359713597235973359743597535976359773597835979359803598135982359833598435985359863598735988359893599035991359923599335994359953599635997359983599936000360013600236003360043600536006360073600836009360103601136012360133601436015360163601736018360193602036021360223602336024360253602636027360283602936030360313603236033360343603536036360373603836039360403604136042360433604436045360463604736048360493605036051360523605336054360553605636057360583605936060360613606236063360643606536066360673606836069360703607136072360733607436075360763607736078360793608036081360823608336084360853608636087360883608936090360913609236093360943609536096360973609836099361003610136102361033610436105361063610736108361093611036111361123611336114361153611636117361183611936120361213612236123361243612536126361273612836129361303613136132361333613436135361363613736138361393614036141361423614336144361453614636147361483614936150361513615236153361543615536156361573615836159361603616136162361633616436165361663616736168361693617036171361723617336174361753617636177361783617936180361813618236183361843618536186361873618836189361903619136192361933619436195361963619736198361993620036201362023620336204362053620636207362083620936210362113621236213362143621536216362173621836219362203622136222362233622436225362263622736228362293623036231362323623336234362353623636237362383623936240362413624236243362443624536246362473624836249362503625136252362533625436255362563625736258362593626036261362623626336264362653626636267362683626936270362713627236273362743627536276362773627836279362803628136282362833628436285362863628736288362893629036291362923629336294362953629636297362983629936300363013630236303363043630536306363073630836309363103631136312363133631436315363163631736318363193632036321363223632336324363253632636327363283632936330363313633236333363343633536336363373633836339363403634136342363433634436345363463634736348363493635036351363523635336354363553635636357363583635936360363613636236363363643636536366363673636836369363703637136372363733637436375363763637736378363793638036381363823638336384363853638636387363883638936390363913639236393363943639536396363973639836399364003640136402364033640436405364063640736408364093641036411364123641336414364153641636417364183641936420364213642236423364243642536426364273642836429364303643136432364333643436435364363643736438364393644036441364423644336444364453644636447364483644936450364513645236453364543645536456364573645836459364603646136462364633646436465364663646736468364693647036471364723647336474364753647636477364783647936480364813648236483364843648536486364873648836489364903649136492364933649436495364963649736498364993650036501365023650336504365053650636507365083650936510365113651236513365143651536516365173651836519365203652136522365233652436525365263652736528365293653036531365323653336534365353653636537365383653936540365413654236543365443654536546365473654836549365503655136552365533655436555365563655736558365593656036561365623656336564365653656636567365683656936570365713657236573365743657536576365773657836579365803658136582365833658436585365863658736588365893659036591365923659336594365953659636597365983659936600366013660236603366043660536606366073660836609366103661136612366133661436615366163661736618366193662036621366223662336624366253662636627366283662936630366313663236633366343663536636366373663836639366403664136642366433664436645366463664736648366493665036651366523665336654366553665636657366583665936660366613666236663366643666536666366673666836669366703667136672366733667436675366763667736678366793668036681366823668336684366853668636687366883668936690366913669236693366943669536696366973669836699367003670136702367033670436705367063670736708367093671036711367123671336714367153671636717367183671936720367213672236723367243672536726367273672836729367303673136732367333673436735367363673736738367393674036741367423674336744367453674636747367483674936750367513675236753367543675536756367573675836759367603676136762367633676436765367663676736768367693677036771367723677336774367753677636777367783677936780367813678236783367843678536786367873678836789367903679136792367933679436795367963679736798367993680036801368023680336804368053680636807368083680936810368113681236813368143681536816368173681836819368203682136822368233682436825368263682736828368293683036831368323683336834368353683636837368383683936840368413684236843368443684536846368473684836849368503685136852368533685436855368563685736858368593686036861368623686336864368653686636867368683686936870368713687236873368743687536876368773687836879368803688136882368833688436885368863688736888368893689036891368923689336894368953689636897368983689936900369013690236903369043690536906369073690836909369103691136912369133691436915369163691736918369193692036921369223692336924369253692636927369283692936930369313693236933369343693536936369373693836939369403694136942369433694436945369463694736948369493695036951369523695336954369553695636957369583695936960369613696236963369643696536966369673696836969369703697136972369733697436975369763697736978369793698036981369823698336984369853698636987369883698936990369913699236993369943699536996369973699836999370003700137002370033700437005370063700737008370093701037011370123701337014370153701637017370183701937020370213702237023370243702537026370273702837029370303703137032370333703437035370363703737038370393704037041370423704337044370453704637047370483704937050370513705237053370543705537056370573705837059370603706137062370633706437065370663706737068370693707037071370723707337074370753707637077370783707937080370813708237083370843708537086370873708837089370903709137092370933709437095370963709737098370993710037101371023710337104371053710637107371083710937110371113711237113371143711537116371173711837119371203712137122371233712437125371263712737128371293713037131371323713337134371353713637137371383713937140371413714237143371443714537146371473714837149371503715137152371533715437155371563715737158371593716037161371623716337164371653716637167371683716937170371713717237173371743717537176371773717837179371803718137182371833718437185371863718737188371893719037191371923719337194371953719637197371983719937200372013720237203372043720537206372073720837209372103721137212372133721437215372163721737218372193722037221372223722337224372253722637227372283722937230372313723237233372343723537236372373723837239372403724137242372433724437245372463724737248372493725037251372523725337254372553725637257372583725937260372613726237263372643726537266372673726837269372703727137272372733727437275372763727737278372793728037281372823728337284372853728637287372883728937290372913729237293372943729537296372973729837299373003730137302373033730437305373063730737308373093731037311373123731337314373153731637317373183731937320373213732237323373243732537326373273732837329373303733137332373333733437335373363733737338373393734037341373423734337344373453734637347373483734937350373513735237353373543735537356373573735837359373603736137362373633736437365373663736737368373693737037371373723737337374373753737637377373783737937380373813738237383373843738537386373873738837389373903739137392373933739437395373963739737398373993740037401374023740337404374053740637407374083740937410374113741237413374143741537416374173741837419374203742137422374233742437425374263742737428374293743037431374323743337434374353743637437374383743937440374413744237443374443744537446374473744837449374503745137452374533745437455374563745737458374593746037461374623746337464374653746637467374683746937470374713747237473374743747537476374773747837479374803748137482374833748437485374863748737488374893749037491374923749337494374953749637497374983749937500375013750237503375043750537506375073750837509375103751137512375133751437515375163751737518375193752037521375223752337524375253752637527375283752937530375313753237533375343753537536375373753837539375403754137542375433754437545375463754737548375493755037551375523755337554375553755637557375583755937560375613756237563375643756537566375673756837569375703757137572375733757437575375763757737578375793758037581375823758337584375853758637587375883758937590375913759237593375943759537596375973759837599376003760137602376033760437605376063760737608376093761037611376123761337614376153761637617376183761937620376213762237623376243762537626376273762837629376303763137632376333763437635376363763737638376393764037641376423764337644376453764637647376483764937650376513765237653376543765537656376573765837659376603766137662376633766437665376663766737668376693767037671376723767337674376753767637677376783767937680376813768237683376843768537686376873768837689376903769137692376933769437695376963769737698376993770037701377023770337704377053770637707377083770937710377113771237713377143771537716377173771837719377203772137722377233772437725377263772737728377293773037731377323773337734377353773637737377383773937740377413774237743377443774537746377473774837749377503775137752377533775437755377563775737758377593776037761377623776337764377653776637767377683776937770377713777237773377743777537776377773777837779377803778137782377833778437785377863778737788377893779037791377923779337794377953779637797377983779937800378013780237803378043780537806378073780837809378103781137812378133781437815378163781737818378193782037821378223782337824378253782637827378283782937830378313783237833378343783537836378373783837839378403784137842378433784437845378463784737848378493785037851378523785337854378553785637857378583785937860378613786237863378643786537866378673786837869378703787137872378733787437875378763787737878378793788037881378823788337884378853788637887378883788937890378913789237893378943789537896378973789837899379003790137902379033790437905379063790737908379093791037911379123791337914379153791637917379183791937920379213792237923379243792537926379273792837929379303793137932379333793437935379363793737938379393794037941379423794337944379453794637947379483794937950379513795237953379543795537956379573795837959379603796137962379633796437965379663796737968379693797037971379723797337974379753797637977379783797937980379813798237983379843798537986379873798837989379903799137992379933799437995379963799737998379993800038001380023800338004380053800638007380083800938010380113801238013380143801538016380173801838019380203802138022380233802438025380263802738028380293803038031380323803338034380353803638037380383803938040380413804238043380443804538046380473804838049380503805138052380533805438055380563805738058380593806038061380623806338064380653806638067380683806938070380713807238073380743807538076380773807838079380803808138082380833808438085380863808738088380893809038091380923809338094380953809638097380983809938100381013810238103381043810538106381073810838109381103811138112381133811438115381163811738118381193812038121381223812338124381253812638127381283812938130381313813238133381343813538136381373813838139381403814138142381433814438145381463814738148381493815038151381523815338154381553815638157381583815938160381613816238163381643816538166381673816838169381703817138172381733817438175381763817738178381793818038181381823818338184381853818638187381883818938190381913819238193381943819538196381973819838199382003820138202382033820438205382063820738208382093821038211382123821338214382153821638217382183821938220382213822238223382243822538226382273822838229382303823138232382333823438235382363823738238382393824038241382423824338244382453824638247382483824938250382513825238253382543825538256382573825838259382603826138262382633826438265382663826738268382693827038271382723827338274382753827638277382783827938280382813828238283382843828538286382873828838289382903829138292382933829438295382963829738298382993830038301383023830338304383053830638307383083830938310383113831238313383143831538316383173831838319383203832138322383233832438325383263832738328383293833038331383323833338334383353833638337383383833938340383413834238343383443834538346383473834838349383503835138352383533835438355383563835738358383593836038361383623836338364383653836638367383683836938370383713837238373383743837538376383773837838379383803838138382383833838438385383863838738388383893839038391383923839338394383953839638397383983839938400384013840238403384043840538406384073840838409384103841138412384133841438415384163841738418384193842038421384223842338424384253842638427384283842938430384313843238433384343843538436384373843838439384403844138442384433844438445384463844738448384493845038451384523845338454384553845638457384583845938460384613846238463384643846538466384673846838469384703847138472384733847438475384763847738478384793848038481384823848338484384853848638487384883848938490384913849238493384943849538496384973849838499385003850138502385033850438505385063850738508385093851038511385123851338514385153851638517385183851938520385213852238523385243852538526385273852838529385303853138532385333853438535385363853738538385393854038541385423854338544385453854638547385483854938550385513855238553385543855538556385573855838559385603856138562385633856438565385663856738568385693857038571385723857338574385753857638577385783857938580385813858238583385843858538586385873858838589385903859138592385933859438595385963859738598385993860038601386023860338604386053860638607386083860938610386113861238613386143861538616386173861838619386203862138622386233862438625386263862738628386293863038631386323863338634386353863638637386383863938640386413864238643386443864538646386473864838649386503865138652386533865438655386563865738658386593866038661386623866338664386653866638667386683866938670386713867238673386743867538676386773867838679386803868138682386833868438685386863868738688386893869038691386923869338694386953869638697386983869938700387013870238703387043870538706387073870838709387103871138712387133871438715387163871738718387193872038721387223872338724387253872638727387283872938730387313873238733387343873538736387373873838739387403874138742387433874438745387463874738748387493875038751387523875338754387553875638757387583875938760387613876238763387643876538766387673876838769387703877138772387733877438775387763877738778387793878038781387823878338784387853878638787387883878938790387913879238793387943879538796387973879838799388003880138802388033880438805388063880738808388093881038811388123881338814388153881638817388183881938820388213882238823388243882538826388273882838829388303883138832388333883438835388363883738838388393884038841388423884338844388453884638847388483884938850388513885238853388543885538856388573885838859388603886138862388633886438865388663886738868388693887038871388723887338874388753887638877388783887938880388813888238883388843888538886388873888838889388903889138892388933889438895388963889738898388993890038901389023890338904389053890638907389083890938910389113891238913389143891538916389173891838919389203892138922389233892438925389263892738928389293893038931389323893338934389353893638937389383893938940389413894238943389443894538946389473894838949389503895138952389533895438955389563895738958389593896038961389623896338964389653896638967389683896938970389713897238973389743897538976389773897838979389803898138982389833898438985389863898738988389893899038991389923899338994389953899638997389983899939000390013900239003390043900539006390073900839009390103901139012390133901439015390163901739018390193902039021390223902339024390253902639027390283902939030390313903239033390343903539036390373903839039390403904139042390433904439045390463904739048390493905039051390523905339054390553905639057390583905939060390613906239063390643906539066390673906839069390703907139072390733907439075390763907739078390793908039081390823908339084390853908639087390883908939090390913909239093390943909539096390973909839099391003910139102391033910439105391063910739108391093911039111391123911339114391153911639117391183911939120391213912239123391243912539126391273912839129391303913139132391333913439135391363913739138391393914039141391423914339144391453914639147391483914939150391513915239153391543915539156391573915839159391603916139162391633916439165391663916739168391693917039171391723917339174391753917639177391783917939180391813918239183391843918539186391873918839189391903919139192391933919439195391963919739198391993920039201392023920339204392053920639207392083920939210392113921239213392143921539216392173921839219392203922139222392233922439225392263922739228392293923039231392323923339234392353923639237392383923939240392413924239243392443924539246392473924839249392503925139252392533925439255392563925739258392593926039261392623926339264392653926639267392683926939270392713927239273392743927539276392773927839279392803928139282392833928439285392863928739288392893929039291392923929339294392953929639297392983929939300393013930239303393043930539306393073930839309393103931139312393133931439315393163931739318393193932039321393223932339324393253932639327393283932939330393313933239333393343933539336393373933839339393403934139342393433934439345393463934739348393493935039351393523935339354393553935639357393583935939360393613936239363393643936539366393673936839369393703937139372393733937439375393763937739378393793938039381393823938339384393853938639387393883938939390393913939239393393943939539396393973939839399394003940139402394033940439405394063940739408394093941039411394123941339414394153941639417394183941939420394213942239423394243942539426394273942839429394303943139432394333943439435394363943739438394393944039441394423944339444394453944639447394483944939450394513945239453394543945539456394573945839459394603946139462394633946439465394663946739468394693947039471394723947339474394753947639477394783947939480394813948239483394843948539486394873948839489394903949139492394933949439495394963949739498394993950039501395023950339504395053950639507395083950939510395113951239513395143951539516395173951839519395203952139522395233952439525395263952739528395293953039531395323953339534395353953639537395383953939540395413954239543395443954539546395473954839549395503955139552395533955439555395563955739558395593956039561395623956339564395653956639567395683956939570395713957239573395743957539576395773957839579395803958139582395833958439585395863958739588395893959039591395923959339594395953959639597395983959939600396013960239603396043960539606396073960839609396103961139612396133961439615396163961739618396193962039621396223962339624396253962639627396283962939630396313963239633396343963539636396373963839639396403964139642396433964439645396463964739648396493965039651396523965339654396553965639657396583965939660396613966239663396643966539666396673966839669396703967139672396733967439675396763967739678396793968039681396823968339684396853968639687396883968939690396913969239693396943969539696396973969839699397003970139702397033970439705397063970739708397093971039711397123971339714397153971639717397183971939720397213972239723397243972539726397273972839729397303973139732397333973439735397363973739738397393974039741397423974339744397453974639747397483974939750397513975239753397543975539756397573975839759397603976139762397633976439765397663976739768397693977039771397723977339774397753977639777397783977939780397813978239783397843978539786397873978839789397903979139792397933979439795397963979739798397993980039801398023980339804398053980639807398083980939810398113981239813398143981539816398173981839819398203982139822398233982439825398263982739828398293983039831398323983339834398353983639837398383983939840398413984239843398443984539846398473984839849398503985139852398533985439855398563985739858398593986039861398623986339864398653986639867398683986939870398713987239873398743987539876398773987839879398803988139882398833988439885398863988739888398893989039891398923989339894398953989639897398983989939900399013990239903399043990539906399073990839909399103991139912399133991439915399163991739918399193992039921399223992339924399253992639927399283992939930399313993239933399343993539936399373993839939399403994139942399433994439945399463994739948399493995039951399523995339954399553995639957399583995939960399613996239963399643996539966399673996839969399703997139972399733997439975399763997739978399793998039981399823998339984399853998639987399883998939990399913999239993399943999539996399973999839999400004000140002400034000440005400064000740008400094001040011400124001340014400154001640017400184001940020400214002240023400244002540026400274002840029400304003140032400334003440035400364003740038400394004040041400424004340044400454004640047400484004940050400514005240053400544005540056400574005840059400604006140062400634006440065400664006740068400694007040071400724007340074400754007640077400784007940080400814008240083400844008540086400874008840089400904009140092400934009440095400964009740098400994010040101401024010340104401054010640107401084010940110401114011240113401144011540116401174011840119401204012140122401234012440125401264012740128401294013040131401324013340134401354013640137401384013940140401414014240143401444014540146401474014840149401504015140152401534015440155401564015740158401594016040161401624016340164401654016640167401684016940170401714017240173401744017540176401774017840179401804018140182401834018440185401864018740188401894019040191401924019340194401954019640197401984019940200402014020240203402044020540206402074020840209402104021140212402134021440215402164021740218402194022040221402224022340224402254022640227402284022940230402314023240233402344023540236402374023840239402404024140242402434024440245402464024740248402494025040251402524025340254402554025640257402584025940260402614026240263402644026540266402674026840269402704027140272402734027440275402764027740278402794028040281402824028340284402854028640287402884028940290402914029240293402944029540296402974029840299403004030140302403034030440305403064030740308403094031040311403124031340314403154031640317403184031940320403214032240323403244032540326403274032840329403304033140332403334033440335403364033740338403394034040341403424034340344403454034640347403484034940350403514035240353403544035540356403574035840359403604036140362403634036440365403664036740368403694037040371403724037340374403754037640377403784037940380403814038240383403844038540386403874038840389403904039140392403934039440395403964039740398403994040040401404024040340404404054040640407404084040940410404114041240413404144041540416404174041840419404204042140422404234042440425404264042740428404294043040431404324043340434404354043640437404384043940440404414044240443404444044540446404474044840449404504045140452404534045440455404564045740458404594046040461404624046340464404654046640467404684046940470404714047240473404744047540476404774047840479404804048140482404834048440485404864048740488404894049040491404924049340494404954049640497404984049940500405014050240503405044050540506405074050840509405104051140512405134051440515405164051740518405194052040521405224052340524405254052640527405284052940530405314053240533405344053540536405374053840539405404054140542405434054440545405464054740548405494055040551405524055340554405554055640557405584055940560405614056240563405644056540566405674056840569405704057140572405734057440575405764057740578405794058040581405824058340584405854058640587405884058940590405914059240593405944059540596405974059840599406004060140602406034060440605406064060740608406094061040611406124061340614406154061640617406184061940620406214062240623406244062540626406274062840629406304063140632406334063440635406364063740638406394064040641406424064340644406454064640647406484064940650406514065240653406544065540656406574065840659406604066140662406634066440665406664066740668406694067040671406724067340674406754067640677406784067940680406814068240683406844068540686406874068840689406904069140692406934069440695406964069740698406994070040701407024070340704407054070640707407084070940710407114071240713407144071540716407174071840719407204072140722407234072440725407264072740728407294073040731407324073340734407354073640737407384073940740407414074240743407444074540746407474074840749407504075140752407534075440755407564075740758407594076040761407624076340764407654076640767407684076940770407714077240773407744077540776407774077840779407804078140782407834078440785407864078740788407894079040791407924079340794407954079640797407984079940800408014080240803408044080540806408074080840809408104081140812408134081440815408164081740818408194082040821408224082340824408254082640827408284082940830408314083240833408344083540836408374083840839408404084140842408434084440845408464084740848408494085040851408524085340854408554085640857408584085940860408614086240863408644086540866408674086840869408704087140872408734087440875408764087740878408794088040881408824088340884408854088640887408884088940890408914089240893408944089540896408974089840899409004090140902409034090440905409064090740908409094091040911409124091340914409154091640917409184091940920409214092240923409244092540926409274092840929409304093140932409334093440935409364093740938409394094040941409424094340944409454094640947409484094940950409514095240953409544095540956409574095840959409604096140962409634096440965409664096740968409694097040971409724097340974409754097640977409784097940980409814098240983409844098540986409874098840989409904099140992409934099440995409964099740998409994100041001410024100341004410054100641007410084100941010410114101241013410144101541016410174101841019410204102141022410234102441025410264102741028410294103041031410324103341034410354103641037410384103941040410414104241043410444104541046410474104841049410504105141052410534105441055410564105741058410594106041061410624106341064410654106641067410684106941070410714107241073410744107541076410774107841079410804108141082410834108441085410864108741088410894109041091410924109341094410954109641097410984109941100411014110241103411044110541106411074110841109411104111141112411134111441115411164111741118411194112041121411224112341124411254112641127411284112941130411314113241133411344113541136411374113841139411404114141142411434114441145411464114741148411494115041151411524115341154411554115641157411584115941160411614116241163411644116541166411674116841169411704117141172411734117441175411764117741178411794118041181411824118341184411854118641187411884118941190411914119241193411944119541196411974119841199412004120141202412034120441205412064120741208412094121041211412124121341214412154121641217412184121941220412214122241223412244122541226412274122841229412304123141232412334123441235412364123741238412394124041241412424124341244412454124641247412484124941250412514125241253412544125541256412574125841259412604126141262412634126441265412664126741268412694127041271412724127341274412754127641277412784127941280412814128241283412844128541286412874128841289412904129141292412934129441295412964129741298412994130041301413024130341304413054130641307413084130941310413114131241313413144131541316413174131841319413204132141322413234132441325413264132741328413294133041331413324133341334413354133641337413384133941340413414134241343413444134541346413474134841349413504135141352413534135441355413564135741358413594136041361413624136341364413654136641367413684136941370413714137241373413744137541376413774137841379413804138141382413834138441385413864138741388413894139041391413924139341394413954139641397413984139941400414014140241403414044140541406414074140841409414104141141412414134141441415414164141741418414194142041421414224142341424414254142641427414284142941430414314143241433414344143541436414374143841439414404144141442414434144441445414464144741448414494145041451414524145341454414554145641457414584145941460414614146241463414644146541466414674146841469414704147141472414734147441475414764147741478414794148041481414824148341484414854148641487414884148941490414914149241493414944149541496414974149841499415004150141502415034150441505415064150741508415094151041511415124151341514415154151641517415184151941520415214152241523415244152541526415274152841529415304153141532415334153441535415364153741538415394154041541415424154341544415454154641547415484154941550415514155241553415544155541556415574155841559415604156141562415634156441565415664156741568415694157041571415724157341574415754157641577415784157941580415814158241583415844158541586415874158841589415904159141592415934159441595415964159741598415994160041601416024160341604416054160641607416084160941610416114161241613416144161541616416174161841619416204162141622416234162441625416264162741628416294163041631416324163341634416354163641637416384163941640416414164241643416444164541646416474164841649416504165141652416534165441655416564165741658416594166041661416624166341664416654166641667416684166941670
  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. setLength: function ( length ) {
  1101. return this.multiplyScalar( length / this.length() );
  1102. },
  1103. lerp: function ( v, alpha ) {
  1104. this.x += ( v.x - this.x ) * alpha;
  1105. this.y += ( v.y - this.y ) * alpha;
  1106. return this;
  1107. },
  1108. lerpVectors: function ( v1, v2, alpha ) {
  1109. return this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  1110. },
  1111. equals: function ( v ) {
  1112. return ( ( v.x === this.x ) && ( v.y === this.y ) );
  1113. },
  1114. fromArray: function ( array, offset ) {
  1115. if ( offset === undefined ) offset = 0;
  1116. this.x = array[ offset ];
  1117. this.y = array[ offset + 1 ];
  1118. return this;
  1119. },
  1120. toArray: function ( array, offset ) {
  1121. if ( array === undefined ) array = [];
  1122. if ( offset === undefined ) offset = 0;
  1123. array[ offset ] = this.x;
  1124. array[ offset + 1 ] = this.y;
  1125. return array;
  1126. },
  1127. fromAttribute: function ( attribute, index, offset ) {
  1128. if ( offset === undefined ) offset = 0;
  1129. index = index * attribute.itemSize + offset;
  1130. this.x = attribute.array[ index ];
  1131. this.y = attribute.array[ index + 1 ];
  1132. return this;
  1133. },
  1134. rotateAround: function ( center, angle ) {
  1135. var c = Math.cos( angle ), s = Math.sin( angle );
  1136. var x = this.x - center.x;
  1137. var y = this.y - center.y;
  1138. this.x = x * c - y * s + center.x;
  1139. this.y = x * s + y * c + center.y;
  1140. return this;
  1141. }
  1142. };
  1143. // File:src/math/Vector3.js
  1144. /**
  1145. * @author mrdoob / http://mrdoob.com/
  1146. * @author *kile / http://kile.stravaganza.org/
  1147. * @author philogb / http://blog.thejit.org/
  1148. * @author mikael emtinger / http://gomo.se/
  1149. * @author egraether / http://egraether.com/
  1150. * @author WestLangley / http://github.com/WestLangley
  1151. */
  1152. THREE.Vector3 = function ( x, y, z ) {
  1153. this.x = x || 0;
  1154. this.y = y || 0;
  1155. this.z = z || 0;
  1156. };
  1157. THREE.Vector3.prototype = {
  1158. constructor: THREE.Vector3,
  1159. set: function ( x, y, z ) {
  1160. this.x = x;
  1161. this.y = y;
  1162. this.z = z;
  1163. return this;
  1164. },
  1165. setScalar: function ( scalar ) {
  1166. this.x = scalar;
  1167. this.y = scalar;
  1168. this.z = scalar;
  1169. return this;
  1170. },
  1171. setX: function ( x ) {
  1172. this.x = x;
  1173. return this;
  1174. },
  1175. setY: function ( y ) {
  1176. this.y = y;
  1177. return this;
  1178. },
  1179. setZ: function ( z ) {
  1180. this.z = z;
  1181. return this;
  1182. },
  1183. setComponent: function ( index, value ) {
  1184. switch ( index ) {
  1185. case 0: this.x = value; break;
  1186. case 1: this.y = value; break;
  1187. case 2: this.z = value; break;
  1188. default: throw new Error( 'index is out of range: ' + index );
  1189. }
  1190. },
  1191. getComponent: function ( index ) {
  1192. switch ( index ) {
  1193. case 0: return this.x;
  1194. case 1: return this.y;
  1195. case 2: return this.z;
  1196. default: throw new Error( 'index is out of range: ' + index );
  1197. }
  1198. },
  1199. clone: function () {
  1200. return new this.constructor( this.x, this.y, this.z );
  1201. },
  1202. copy: function ( v ) {
  1203. this.x = v.x;
  1204. this.y = v.y;
  1205. this.z = v.z;
  1206. return this;
  1207. },
  1208. add: function ( v, w ) {
  1209. if ( w !== undefined ) {
  1210. console.warn( 'THREE.Vector3: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  1211. return this.addVectors( v, w );
  1212. }
  1213. this.x += v.x;
  1214. this.y += v.y;
  1215. this.z += v.z;
  1216. return this;
  1217. },
  1218. addScalar: function ( s ) {
  1219. this.x += s;
  1220. this.y += s;
  1221. this.z += s;
  1222. return this;
  1223. },
  1224. addVectors: function ( a, b ) {
  1225. this.x = a.x + b.x;
  1226. this.y = a.y + b.y;
  1227. this.z = a.z + b.z;
  1228. return this;
  1229. },
  1230. addScaledVector: function ( v, s ) {
  1231. this.x += v.x * s;
  1232. this.y += v.y * s;
  1233. this.z += v.z * s;
  1234. return this;
  1235. },
  1236. sub: function ( v, w ) {
  1237. if ( w !== undefined ) {
  1238. console.warn( 'THREE.Vector3: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  1239. return this.subVectors( v, w );
  1240. }
  1241. this.x -= v.x;
  1242. this.y -= v.y;
  1243. this.z -= v.z;
  1244. return this;
  1245. },
  1246. subScalar: function ( s ) {
  1247. this.x -= s;
  1248. this.y -= s;
  1249. this.z -= s;
  1250. return this;
  1251. },
  1252. subVectors: function ( a, b ) {
  1253. this.x = a.x - b.x;
  1254. this.y = a.y - b.y;
  1255. this.z = a.z - b.z;
  1256. return this;
  1257. },
  1258. multiply: function ( v, w ) {
  1259. if ( w !== undefined ) {
  1260. console.warn( 'THREE.Vector3: .multiply() now only accepts one argument. Use .multiplyVectors( a, b ) instead.' );
  1261. return this.multiplyVectors( v, w );
  1262. }
  1263. this.x *= v.x;
  1264. this.y *= v.y;
  1265. this.z *= v.z;
  1266. return this;
  1267. },
  1268. multiplyScalar: function ( scalar ) {
  1269. if ( isFinite( scalar ) ) {
  1270. this.x *= scalar;
  1271. this.y *= scalar;
  1272. this.z *= scalar;
  1273. } else {
  1274. this.x = 0;
  1275. this.y = 0;
  1276. this.z = 0;
  1277. }
  1278. return this;
  1279. },
  1280. multiplyVectors: function ( a, b ) {
  1281. this.x = a.x * b.x;
  1282. this.y = a.y * b.y;
  1283. this.z = a.z * b.z;
  1284. return this;
  1285. },
  1286. applyEuler: function () {
  1287. var quaternion;
  1288. return function applyEuler( euler ) {
  1289. if ( euler instanceof THREE.Euler === false ) {
  1290. console.error( 'THREE.Vector3: .applyEuler() now expects an Euler rotation rather than a Vector3 and order.' );
  1291. }
  1292. if ( quaternion === undefined ) quaternion = new THREE.Quaternion();
  1293. return this.applyQuaternion( quaternion.setFromEuler( euler ) );
  1294. };
  1295. }(),
  1296. applyAxisAngle: function () {
  1297. var quaternion;
  1298. return function applyAxisAngle( axis, angle ) {
  1299. if ( quaternion === undefined ) quaternion = new THREE.Quaternion();
  1300. return this.applyQuaternion( quaternion.setFromAxisAngle( axis, angle ) );
  1301. };
  1302. }(),
  1303. applyMatrix3: function ( m ) {
  1304. var x = this.x, y = this.y, z = this.z;
  1305. var e = m.elements;
  1306. this.x = e[ 0 ] * x + e[ 3 ] * y + e[ 6 ] * z;
  1307. this.y = e[ 1 ] * x + e[ 4 ] * y + e[ 7 ] * z;
  1308. this.z = e[ 2 ] * x + e[ 5 ] * y + e[ 8 ] * z;
  1309. return this;
  1310. },
  1311. applyMatrix4: function ( m ) {
  1312. // input: THREE.Matrix4 affine matrix
  1313. var x = this.x, y = this.y, z = this.z;
  1314. var e = m.elements;
  1315. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ];
  1316. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ];
  1317. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ];
  1318. return this;
  1319. },
  1320. applyProjection: function ( m ) {
  1321. // input: THREE.Matrix4 projection matrix
  1322. var x = this.x, y = this.y, z = this.z;
  1323. var e = m.elements;
  1324. var d = 1 / ( e[ 3 ] * x + e[ 7 ] * y + e[ 11 ] * z + e[ 15 ] ); // perspective divide
  1325. this.x = ( e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ] ) * d;
  1326. this.y = ( e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ] ) * d;
  1327. this.z = ( e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ] ) * d;
  1328. return this;
  1329. },
  1330. applyQuaternion: function ( q ) {
  1331. var x = this.x, y = this.y, z = this.z;
  1332. var qx = q.x, qy = q.y, qz = q.z, qw = q.w;
  1333. // calculate quat * vector
  1334. var ix = qw * x + qy * z - qz * y;
  1335. var iy = qw * y + qz * x - qx * z;
  1336. var iz = qw * z + qx * y - qy * x;
  1337. var iw = - qx * x - qy * y - qz * z;
  1338. // calculate result * inverse quat
  1339. this.x = ix * qw + iw * - qx + iy * - qz - iz * - qy;
  1340. this.y = iy * qw + iw * - qy + iz * - qx - ix * - qz;
  1341. this.z = iz * qw + iw * - qz + ix * - qy - iy * - qx;
  1342. return this;
  1343. },
  1344. project: function () {
  1345. var matrix;
  1346. return function project( camera ) {
  1347. if ( matrix === undefined ) matrix = new THREE.Matrix4();
  1348. matrix.multiplyMatrices( camera.projectionMatrix, matrix.getInverse( camera.matrixWorld ) );
  1349. return this.applyProjection( matrix );
  1350. };
  1351. }(),
  1352. unproject: function () {
  1353. var matrix;
  1354. return function unproject( camera ) {
  1355. if ( matrix === undefined ) matrix = new THREE.Matrix4();
  1356. matrix.multiplyMatrices( camera.matrixWorld, matrix.getInverse( camera.projectionMatrix ) );
  1357. return this.applyProjection( matrix );
  1358. };
  1359. }(),
  1360. transformDirection: function ( m ) {
  1361. // input: THREE.Matrix4 affine matrix
  1362. // vector interpreted as a direction
  1363. var x = this.x, y = this.y, z = this.z;
  1364. var e = m.elements;
  1365. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z;
  1366. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z;
  1367. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z;
  1368. return this.normalize();
  1369. },
  1370. divide: function ( v ) {
  1371. this.x /= v.x;
  1372. this.y /= v.y;
  1373. this.z /= v.z;
  1374. return this;
  1375. },
  1376. divideScalar: function ( scalar ) {
  1377. return this.multiplyScalar( 1 / scalar );
  1378. },
  1379. min: function ( v ) {
  1380. this.x = Math.min( this.x, v.x );
  1381. this.y = Math.min( this.y, v.y );
  1382. this.z = Math.min( this.z, v.z );
  1383. return this;
  1384. },
  1385. max: function ( v ) {
  1386. this.x = Math.max( this.x, v.x );
  1387. this.y = Math.max( this.y, v.y );
  1388. this.z = Math.max( this.z, v.z );
  1389. return this;
  1390. },
  1391. clamp: function ( min, max ) {
  1392. // This function assumes min < max, if this assumption isn't true it will not operate correctly
  1393. this.x = Math.max( min.x, Math.min( max.x, this.x ) );
  1394. this.y = Math.max( min.y, Math.min( max.y, this.y ) );
  1395. this.z = Math.max( min.z, Math.min( max.z, this.z ) );
  1396. return this;
  1397. },
  1398. clampScalar: function () {
  1399. var min, max;
  1400. return function clampScalar( minVal, maxVal ) {
  1401. if ( min === undefined ) {
  1402. min = new THREE.Vector3();
  1403. max = new THREE.Vector3();
  1404. }
  1405. min.set( minVal, minVal, minVal );
  1406. max.set( maxVal, maxVal, maxVal );
  1407. return this.clamp( min, max );
  1408. };
  1409. }(),
  1410. clampLength: function ( min, max ) {
  1411. var length = this.length();
  1412. return this.multiplyScalar( Math.max( min, Math.min( max, length ) ) / length );
  1413. },
  1414. floor: function () {
  1415. this.x = Math.floor( this.x );
  1416. this.y = Math.floor( this.y );
  1417. this.z = Math.floor( this.z );
  1418. return this;
  1419. },
  1420. ceil: function () {
  1421. this.x = Math.ceil( this.x );
  1422. this.y = Math.ceil( this.y );
  1423. this.z = Math.ceil( this.z );
  1424. return this;
  1425. },
  1426. round: function () {
  1427. this.x = Math.round( this.x );
  1428. this.y = Math.round( this.y );
  1429. this.z = Math.round( this.z );
  1430. return this;
  1431. },
  1432. roundToZero: function () {
  1433. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  1434. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  1435. this.z = ( this.z < 0 ) ? Math.ceil( this.z ) : Math.floor( this.z );
  1436. return this;
  1437. },
  1438. negate: function () {
  1439. this.x = - this.x;
  1440. this.y = - this.y;
  1441. this.z = - this.z;
  1442. return this;
  1443. },
  1444. dot: function ( v ) {
  1445. return this.x * v.x + this.y * v.y + this.z * v.z;
  1446. },
  1447. lengthSq: function () {
  1448. return this.x * this.x + this.y * this.y + this.z * this.z;
  1449. },
  1450. length: function () {
  1451. return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z );
  1452. },
  1453. lengthManhattan: function () {
  1454. return Math.abs( this.x ) + Math.abs( this.y ) + Math.abs( this.z );
  1455. },
  1456. normalize: function () {
  1457. return this.divideScalar( this.length() );
  1458. },
  1459. setLength: function ( length ) {
  1460. return this.multiplyScalar( length / this.length() );
  1461. },
  1462. lerp: function ( v, alpha ) {
  1463. this.x += ( v.x - this.x ) * alpha;
  1464. this.y += ( v.y - this.y ) * alpha;
  1465. this.z += ( v.z - this.z ) * alpha;
  1466. return this;
  1467. },
  1468. lerpVectors: function ( v1, v2, alpha ) {
  1469. return this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  1470. },
  1471. cross: function ( v, w ) {
  1472. if ( w !== undefined ) {
  1473. console.warn( 'THREE.Vector3: .cross() now only accepts one argument. Use .crossVectors( a, b ) instead.' );
  1474. return this.crossVectors( v, w );
  1475. }
  1476. var x = this.x, y = this.y, z = this.z;
  1477. this.x = y * v.z - z * v.y;
  1478. this.y = z * v.x - x * v.z;
  1479. this.z = x * v.y - y * v.x;
  1480. return this;
  1481. },
  1482. crossVectors: function ( a, b ) {
  1483. var ax = a.x, ay = a.y, az = a.z;
  1484. var bx = b.x, by = b.y, bz = b.z;
  1485. this.x = ay * bz - az * by;
  1486. this.y = az * bx - ax * bz;
  1487. this.z = ax * by - ay * bx;
  1488. return this;
  1489. },
  1490. projectOnVector: function ( vector ) {
  1491. var scalar = vector.dot( this ) / vector.lengthSq();
  1492. return this.copy( vector ).multiplyScalar( scalar );
  1493. },
  1494. projectOnPlane: function () {
  1495. var v1;
  1496. return function projectOnPlane( planeNormal ) {
  1497. if ( v1 === undefined ) v1 = new THREE.Vector3();
  1498. v1.copy( this ).projectOnVector( planeNormal );
  1499. return this.sub( v1 );
  1500. };
  1501. }(),
  1502. reflect: function () {
  1503. // reflect incident vector off plane orthogonal to normal
  1504. // normal is assumed to have unit length
  1505. var v1;
  1506. return function reflect( normal ) {
  1507. if ( v1 === undefined ) v1 = new THREE.Vector3();
  1508. return this.sub( v1.copy( normal ).multiplyScalar( 2 * this.dot( normal ) ) );
  1509. };
  1510. }(),
  1511. angleTo: function ( v ) {
  1512. var theta = this.dot( v ) / ( Math.sqrt( this.lengthSq() * v.lengthSq() ) );
  1513. // clamp, to handle numerical problems
  1514. return Math.acos( THREE.Math.clamp( theta, - 1, 1 ) );
  1515. },
  1516. distanceTo: function ( v ) {
  1517. return Math.sqrt( this.distanceToSquared( v ) );
  1518. },
  1519. distanceToSquared: function ( v ) {
  1520. var dx = this.x - v.x, dy = this.y - v.y, dz = this.z - v.z;
  1521. return dx * dx + dy * dy + dz * dz;
  1522. },
  1523. setFromSpherical: function( s ) {
  1524. var sinPhiRadius = Math.sin( s.phi ) * s.radius;
  1525. this.x = sinPhiRadius * Math.sin( s.theta );
  1526. this.y = Math.cos( s.phi ) * s.radius;
  1527. this.z = sinPhiRadius * Math.cos( s.theta );
  1528. return this;
  1529. },
  1530. setFromMatrixPosition: function ( m ) {
  1531. return this.setFromMatrixColumn( m, 3 );
  1532. },
  1533. setFromMatrixScale: function ( m ) {
  1534. var sx = this.setFromMatrixColumn( m, 0 ).length();
  1535. var sy = this.setFromMatrixColumn( m, 1 ).length();
  1536. var sz = this.setFromMatrixColumn( m, 2 ).length();
  1537. this.x = sx;
  1538. this.y = sy;
  1539. this.z = sz;
  1540. return this;
  1541. },
  1542. setFromMatrixColumn: function ( m, index ) {
  1543. if ( typeof m === 'number' ) {
  1544. console.warn( 'THREE.Vector3: setFromMatrixColumn now expects ( matrix, index ).' );
  1545. var temp = m
  1546. m = index;
  1547. index = temp;
  1548. }
  1549. return this.fromArray( m.elements, index * 4 );
  1550. },
  1551. equals: function ( v ) {
  1552. return ( ( v.x === this.x ) && ( v.y === this.y ) && ( v.z === this.z ) );
  1553. },
  1554. fromArray: function ( array, offset ) {
  1555. if ( offset === undefined ) offset = 0;
  1556. this.x = array[ offset ];
  1557. this.y = array[ offset + 1 ];
  1558. this.z = array[ offset + 2 ];
  1559. return this;
  1560. },
  1561. toArray: function ( array, offset ) {
  1562. if ( array === undefined ) array = [];
  1563. if ( offset === undefined ) offset = 0;
  1564. array[ offset ] = this.x;
  1565. array[ offset + 1 ] = this.y;
  1566. array[ offset + 2 ] = this.z;
  1567. return array;
  1568. },
  1569. fromAttribute: function ( attribute, index, offset ) {
  1570. if ( offset === undefined ) offset = 0;
  1571. index = index * attribute.itemSize + offset;
  1572. this.x = attribute.array[ index ];
  1573. this.y = attribute.array[ index + 1 ];
  1574. this.z = attribute.array[ index + 2 ];
  1575. return this;
  1576. }
  1577. };
  1578. // File:src/math/Vector4.js
  1579. /**
  1580. * @author supereggbert / http://www.paulbrunt.co.uk/
  1581. * @author philogb / http://blog.thejit.org/
  1582. * @author mikael emtinger / http://gomo.se/
  1583. * @author egraether / http://egraether.com/
  1584. * @author WestLangley / http://github.com/WestLangley
  1585. */
  1586. THREE.Vector4 = function ( x, y, z, w ) {
  1587. this.x = x || 0;
  1588. this.y = y || 0;
  1589. this.z = z || 0;
  1590. this.w = ( w !== undefined ) ? w : 1;
  1591. };
  1592. THREE.Vector4.prototype = {
  1593. constructor: THREE.Vector4,
  1594. set: function ( x, y, z, w ) {
  1595. this.x = x;
  1596. this.y = y;
  1597. this.z = z;
  1598. this.w = w;
  1599. return this;
  1600. },
  1601. setScalar: function ( scalar ) {
  1602. this.x = scalar;
  1603. this.y = scalar;
  1604. this.z = scalar;
  1605. this.w = scalar;
  1606. return this;
  1607. },
  1608. setX: function ( x ) {
  1609. this.x = x;
  1610. return this;
  1611. },
  1612. setY: function ( y ) {
  1613. this.y = y;
  1614. return this;
  1615. },
  1616. setZ: function ( z ) {
  1617. this.z = z;
  1618. return this;
  1619. },
  1620. setW: function ( w ) {
  1621. this.w = w;
  1622. return this;
  1623. },
  1624. setComponent: function ( index, value ) {
  1625. switch ( index ) {
  1626. case 0: this.x = value; break;
  1627. case 1: this.y = value; break;
  1628. case 2: this.z = value; break;
  1629. case 3: this.w = value; break;
  1630. default: throw new Error( 'index is out of range: ' + index );
  1631. }
  1632. },
  1633. getComponent: function ( index ) {
  1634. switch ( index ) {
  1635. case 0: return this.x;
  1636. case 1: return this.y;
  1637. case 2: return this.z;
  1638. case 3: return this.w;
  1639. default: throw new Error( 'index is out of range: ' + index );
  1640. }
  1641. },
  1642. clone: function () {
  1643. return new this.constructor( this.x, this.y, this.z, this.w );
  1644. },
  1645. copy: function ( v ) {
  1646. this.x = v.x;
  1647. this.y = v.y;
  1648. this.z = v.z;
  1649. this.w = ( v.w !== undefined ) ? v.w : 1;
  1650. return this;
  1651. },
  1652. add: function ( v, w ) {
  1653. if ( w !== undefined ) {
  1654. console.warn( 'THREE.Vector4: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  1655. return this.addVectors( v, w );
  1656. }
  1657. this.x += v.x;
  1658. this.y += v.y;
  1659. this.z += v.z;
  1660. this.w += v.w;
  1661. return this;
  1662. },
  1663. addScalar: function ( s ) {
  1664. this.x += s;
  1665. this.y += s;
  1666. this.z += s;
  1667. this.w += s;
  1668. return this;
  1669. },
  1670. addVectors: function ( a, b ) {
  1671. this.x = a.x + b.x;
  1672. this.y = a.y + b.y;
  1673. this.z = a.z + b.z;
  1674. this.w = a.w + b.w;
  1675. return this;
  1676. },
  1677. addScaledVector: function ( v, s ) {
  1678. this.x += v.x * s;
  1679. this.y += v.y * s;
  1680. this.z += v.z * s;
  1681. this.w += v.w * s;
  1682. return this;
  1683. },
  1684. sub: function ( v, w ) {
  1685. if ( w !== undefined ) {
  1686. console.warn( 'THREE.Vector4: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  1687. return this.subVectors( v, w );
  1688. }
  1689. this.x -= v.x;
  1690. this.y -= v.y;
  1691. this.z -= v.z;
  1692. this.w -= v.w;
  1693. return this;
  1694. },
  1695. subScalar: function ( s ) {
  1696. this.x -= s;
  1697. this.y -= s;
  1698. this.z -= s;
  1699. this.w -= s;
  1700. return this;
  1701. },
  1702. subVectors: function ( a, b ) {
  1703. this.x = a.x - b.x;
  1704. this.y = a.y - b.y;
  1705. this.z = a.z - b.z;
  1706. this.w = a.w - b.w;
  1707. return this;
  1708. },
  1709. multiplyScalar: function ( scalar ) {
  1710. if ( isFinite( scalar ) ) {
  1711. this.x *= scalar;
  1712. this.y *= scalar;
  1713. this.z *= scalar;
  1714. this.w *= scalar;
  1715. } else {
  1716. this.x = 0;
  1717. this.y = 0;
  1718. this.z = 0;
  1719. this.w = 0;
  1720. }
  1721. return this;
  1722. },
  1723. applyMatrix4: function ( m ) {
  1724. var x = this.x, y = this.y, z = this.z, w = this.w;
  1725. var e = m.elements;
  1726. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ] * w;
  1727. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ] * w;
  1728. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ] * w;
  1729. this.w = e[ 3 ] * x + e[ 7 ] * y + e[ 11 ] * z + e[ 15 ] * w;
  1730. return this;
  1731. },
  1732. divideScalar: function ( scalar ) {
  1733. return this.multiplyScalar( 1 / scalar );
  1734. },
  1735. setAxisAngleFromQuaternion: function ( q ) {
  1736. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToAngle/index.htm
  1737. // q is assumed to be normalized
  1738. this.w = 2 * Math.acos( q.w );
  1739. var s = Math.sqrt( 1 - q.w * q.w );
  1740. if ( s < 0.0001 ) {
  1741. this.x = 1;
  1742. this.y = 0;
  1743. this.z = 0;
  1744. } else {
  1745. this.x = q.x / s;
  1746. this.y = q.y / s;
  1747. this.z = q.z / s;
  1748. }
  1749. return this;
  1750. },
  1751. setAxisAngleFromRotationMatrix: function ( m ) {
  1752. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToAngle/index.htm
  1753. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  1754. var angle, x, y, z, // variables for result
  1755. epsilon = 0.01, // margin to allow for rounding errors
  1756. epsilon2 = 0.1, // margin to distinguish between 0 and 180 degrees
  1757. te = m.elements,
  1758. m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ],
  1759. m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ],
  1760. m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ];
  1761. if ( ( Math.abs( m12 - m21 ) < epsilon ) &&
  1762. ( Math.abs( m13 - m31 ) < epsilon ) &&
  1763. ( Math.abs( m23 - m32 ) < epsilon ) ) {
  1764. // singularity found
  1765. // first check for identity matrix which must have +1 for all terms
  1766. // in leading diagonal and zero in other terms
  1767. if ( ( Math.abs( m12 + m21 ) < epsilon2 ) &&
  1768. ( Math.abs( m13 + m31 ) < epsilon2 ) &&
  1769. ( Math.abs( m23 + m32 ) < epsilon2 ) &&
  1770. ( Math.abs( m11 + m22 + m33 - 3 ) < epsilon2 ) ) {
  1771. // this singularity is identity matrix so angle = 0
  1772. this.set( 1, 0, 0, 0 );
  1773. return this; // zero angle, arbitrary axis
  1774. }
  1775. // otherwise this singularity is angle = 180
  1776. angle = Math.PI;
  1777. var xx = ( m11 + 1 ) / 2;
  1778. var yy = ( m22 + 1 ) / 2;
  1779. var zz = ( m33 + 1 ) / 2;
  1780. var xy = ( m12 + m21 ) / 4;
  1781. var xz = ( m13 + m31 ) / 4;
  1782. var yz = ( m23 + m32 ) / 4;
  1783. if ( ( xx > yy ) && ( xx > zz ) ) {
  1784. // m11 is the largest diagonal term
  1785. if ( xx < epsilon ) {
  1786. x = 0;
  1787. y = 0.707106781;
  1788. z = 0.707106781;
  1789. } else {
  1790. x = Math.sqrt( xx );
  1791. y = xy / x;
  1792. z = xz / x;
  1793. }
  1794. } else if ( yy > zz ) {
  1795. // m22 is the largest diagonal term
  1796. if ( yy < epsilon ) {
  1797. x = 0.707106781;
  1798. y = 0;
  1799. z = 0.707106781;
  1800. } else {
  1801. y = Math.sqrt( yy );
  1802. x = xy / y;
  1803. z = yz / y;
  1804. }
  1805. } else {
  1806. // m33 is the largest diagonal term so base result on this
  1807. if ( zz < epsilon ) {
  1808. x = 0.707106781;
  1809. y = 0.707106781;
  1810. z = 0;
  1811. } else {
  1812. z = Math.sqrt( zz );
  1813. x = xz / z;
  1814. y = yz / z;
  1815. }
  1816. }
  1817. this.set( x, y, z, angle );
  1818. return this; // return 180 deg rotation
  1819. }
  1820. // as we have reached here there are no singularities so we can handle normally
  1821. var s = Math.sqrt( ( m32 - m23 ) * ( m32 - m23 ) +
  1822. ( m13 - m31 ) * ( m13 - m31 ) +
  1823. ( m21 - m12 ) * ( m21 - m12 ) ); // used to normalize
  1824. if ( Math.abs( s ) < 0.001 ) s = 1;
  1825. // prevent divide by zero, should not happen if matrix is orthogonal and should be
  1826. // caught by singularity test above, but I've left it in just in case
  1827. this.x = ( m32 - m23 ) / s;
  1828. this.y = ( m13 - m31 ) / s;
  1829. this.z = ( m21 - m12 ) / s;
  1830. this.w = Math.acos( ( m11 + m22 + m33 - 1 ) / 2 );
  1831. return this;
  1832. },
  1833. min: function ( v ) {
  1834. this.x = Math.min( this.x, v.x );
  1835. this.y = Math.min( this.y, v.y );
  1836. this.z = Math.min( this.z, v.z );
  1837. this.w = Math.min( this.w, v.w );
  1838. return this;
  1839. },
  1840. max: function ( v ) {
  1841. this.x = Math.max( this.x, v.x );
  1842. this.y = Math.max( this.y, v.y );
  1843. this.z = Math.max( this.z, v.z );
  1844. this.w = Math.max( this.w, v.w );
  1845. return this;
  1846. },
  1847. clamp: function ( min, max ) {
  1848. // This function assumes min < max, if this assumption isn't true it will not operate correctly
  1849. this.x = Math.max( min.x, Math.min( max.x, this.x ) );
  1850. this.y = Math.max( min.y, Math.min( max.y, this.y ) );
  1851. this.z = Math.max( min.z, Math.min( max.z, this.z ) );
  1852. this.w = Math.max( min.w, Math.min( max.w, this.w ) );
  1853. return this;
  1854. },
  1855. clampScalar: function () {
  1856. var min, max;
  1857. return function clampScalar( minVal, maxVal ) {
  1858. if ( min === undefined ) {
  1859. min = new THREE.Vector4();
  1860. max = new THREE.Vector4();
  1861. }
  1862. min.set( minVal, minVal, minVal, minVal );
  1863. max.set( maxVal, maxVal, maxVal, maxVal );
  1864. return this.clamp( min, max );
  1865. };
  1866. }(),
  1867. floor: function () {
  1868. this.x = Math.floor( this.x );
  1869. this.y = Math.floor( this.y );
  1870. this.z = Math.floor( this.z );
  1871. this.w = Math.floor( this.w );
  1872. return this;
  1873. },
  1874. ceil: function () {
  1875. this.x = Math.ceil( this.x );
  1876. this.y = Math.ceil( this.y );
  1877. this.z = Math.ceil( this.z );
  1878. this.w = Math.ceil( this.w );
  1879. return this;
  1880. },
  1881. round: function () {
  1882. this.x = Math.round( this.x );
  1883. this.y = Math.round( this.y );
  1884. this.z = Math.round( this.z );
  1885. this.w = Math.round( this.w );
  1886. return this;
  1887. },
  1888. roundToZero: function () {
  1889. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  1890. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  1891. this.z = ( this.z < 0 ) ? Math.ceil( this.z ) : Math.floor( this.z );
  1892. this.w = ( this.w < 0 ) ? Math.ceil( this.w ) : Math.floor( this.w );
  1893. return this;
  1894. },
  1895. negate: function () {
  1896. this.x = - this.x;
  1897. this.y = - this.y;
  1898. this.z = - this.z;
  1899. this.w = - this.w;
  1900. return this;
  1901. },
  1902. dot: function ( v ) {
  1903. return this.x * v.x + this.y * v.y + this.z * v.z + this.w * v.w;
  1904. },
  1905. lengthSq: function () {
  1906. return this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w;
  1907. },
  1908. length: function () {
  1909. return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w );
  1910. },
  1911. lengthManhattan: function () {
  1912. return Math.abs( this.x ) + Math.abs( this.y ) + Math.abs( this.z ) + Math.abs( this.w );
  1913. },
  1914. normalize: function () {
  1915. return this.divideScalar( this.length() );
  1916. },
  1917. setLength: function ( length ) {
  1918. return this.multiplyScalar( length / this.length() );
  1919. },
  1920. lerp: function ( v, alpha ) {
  1921. this.x += ( v.x - this.x ) * alpha;
  1922. this.y += ( v.y - this.y ) * alpha;
  1923. this.z += ( v.z - this.z ) * alpha;
  1924. this.w += ( v.w - this.w ) * alpha;
  1925. return this;
  1926. },
  1927. lerpVectors: function ( v1, v2, alpha ) {
  1928. return this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  1929. },
  1930. equals: function ( v ) {
  1931. return ( ( v.x === this.x ) && ( v.y === this.y ) && ( v.z === this.z ) && ( v.w === this.w ) );
  1932. },
  1933. fromArray: function ( array, offset ) {
  1934. if ( offset === undefined ) offset = 0;
  1935. this.x = array[ offset ];
  1936. this.y = array[ offset + 1 ];
  1937. this.z = array[ offset + 2 ];
  1938. this.w = array[ offset + 3 ];
  1939. return this;
  1940. },
  1941. toArray: function ( array, offset ) {
  1942. if ( array === undefined ) array = [];
  1943. if ( offset === undefined ) offset = 0;
  1944. array[ offset ] = this.x;
  1945. array[ offset + 1 ] = this.y;
  1946. array[ offset + 2 ] = this.z;
  1947. array[ offset + 3 ] = this.w;
  1948. return array;
  1949. },
  1950. fromAttribute: function ( attribute, index, offset ) {
  1951. if ( offset === undefined ) offset = 0;
  1952. index = index * attribute.itemSize + offset;
  1953. this.x = attribute.array[ index ];
  1954. this.y = attribute.array[ index + 1 ];
  1955. this.z = attribute.array[ index + 2 ];
  1956. this.w = attribute.array[ index + 3 ];
  1957. return this;
  1958. }
  1959. };
  1960. // File:src/math/Euler.js
  1961. /**
  1962. * @author mrdoob / http://mrdoob.com/
  1963. * @author WestLangley / http://github.com/WestLangley
  1964. * @author bhouston / http://clara.io
  1965. */
  1966. THREE.Euler = function ( x, y, z, order ) {
  1967. this._x = x || 0;
  1968. this._y = y || 0;
  1969. this._z = z || 0;
  1970. this._order = order || THREE.Euler.DefaultOrder;
  1971. };
  1972. THREE.Euler.RotationOrders = [ 'XYZ', 'YZX', 'ZXY', 'XZY', 'YXZ', 'ZYX' ];
  1973. THREE.Euler.DefaultOrder = 'XYZ';
  1974. THREE.Euler.prototype = {
  1975. constructor: THREE.Euler,
  1976. get x () {
  1977. return this._x;
  1978. },
  1979. set x ( value ) {
  1980. this._x = value;
  1981. this.onChangeCallback();
  1982. },
  1983. get y () {
  1984. return this._y;
  1985. },
  1986. set y ( value ) {
  1987. this._y = value;
  1988. this.onChangeCallback();
  1989. },
  1990. get z () {
  1991. return this._z;
  1992. },
  1993. set z ( value ) {
  1994. this._z = value;
  1995. this.onChangeCallback();
  1996. },
  1997. get order () {
  1998. return this._order;
  1999. },
  2000. set order ( value ) {
  2001. this._order = value;
  2002. this.onChangeCallback();
  2003. },
  2004. set: function ( x, y, z, order ) {
  2005. this._x = x;
  2006. this._y = y;
  2007. this._z = z;
  2008. this._order = order || this._order;
  2009. this.onChangeCallback();
  2010. return this;
  2011. },
  2012. clone: function () {
  2013. return new this.constructor( this._x, this._y, this._z, this._order );
  2014. },
  2015. copy: function ( euler ) {
  2016. this._x = euler._x;
  2017. this._y = euler._y;
  2018. this._z = euler._z;
  2019. this._order = euler._order;
  2020. this.onChangeCallback();
  2021. return this;
  2022. },
  2023. setFromRotationMatrix: function ( m, order, update ) {
  2024. var clamp = THREE.Math.clamp;
  2025. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  2026. var te = m.elements;
  2027. var m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ];
  2028. var m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ];
  2029. var m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ];
  2030. order = order || this._order;
  2031. if ( order === 'XYZ' ) {
  2032. this._y = Math.asin( clamp( m13, - 1, 1 ) );
  2033. if ( Math.abs( m13 ) < 0.99999 ) {
  2034. this._x = Math.atan2( - m23, m33 );
  2035. this._z = Math.atan2( - m12, m11 );
  2036. } else {
  2037. this._x = Math.atan2( m32, m22 );
  2038. this._z = 0;
  2039. }
  2040. } else if ( order === 'YXZ' ) {
  2041. this._x = Math.asin( - clamp( m23, - 1, 1 ) );
  2042. if ( Math.abs( m23 ) < 0.99999 ) {
  2043. this._y = Math.atan2( m13, m33 );
  2044. this._z = Math.atan2( m21, m22 );
  2045. } else {
  2046. this._y = Math.atan2( - m31, m11 );
  2047. this._z = 0;
  2048. }
  2049. } else if ( order === 'ZXY' ) {
  2050. this._x = Math.asin( clamp( m32, - 1, 1 ) );
  2051. if ( Math.abs( m32 ) < 0.99999 ) {
  2052. this._y = Math.atan2( - m31, m33 );
  2053. this._z = Math.atan2( - m12, m22 );
  2054. } else {
  2055. this._y = 0;
  2056. this._z = Math.atan2( m21, m11 );
  2057. }
  2058. } else if ( order === 'ZYX' ) {
  2059. this._y = Math.asin( - clamp( m31, - 1, 1 ) );
  2060. if ( Math.abs( m31 ) < 0.99999 ) {
  2061. this._x = Math.atan2( m32, m33 );
  2062. this._z = Math.atan2( m21, m11 );
  2063. } else {
  2064. this._x = 0;
  2065. this._z = Math.atan2( - m12, m22 );
  2066. }
  2067. } else if ( order === 'YZX' ) {
  2068. this._z = Math.asin( clamp( m21, - 1, 1 ) );
  2069. if ( Math.abs( m21 ) < 0.99999 ) {
  2070. this._x = Math.atan2( - m23, m22 );
  2071. this._y = Math.atan2( - m31, m11 );
  2072. } else {
  2073. this._x = 0;
  2074. this._y = Math.atan2( m13, m33 );
  2075. }
  2076. } else if ( order === 'XZY' ) {
  2077. this._z = Math.asin( - clamp( m12, - 1, 1 ) );
  2078. if ( Math.abs( m12 ) < 0.99999 ) {
  2079. this._x = Math.atan2( m32, m22 );
  2080. this._y = Math.atan2( m13, m11 );
  2081. } else {
  2082. this._x = Math.atan2( - m23, m33 );
  2083. this._y = 0;
  2084. }
  2085. } else {
  2086. console.warn( 'THREE.Euler: .setFromRotationMatrix() given unsupported order: ' + order );
  2087. }
  2088. this._order = order;
  2089. if ( update !== false ) this.onChangeCallback();
  2090. return this;
  2091. },
  2092. setFromQuaternion: function () {
  2093. var matrix;
  2094. return function setFromQuaternion( q, order, update ) {
  2095. if ( matrix === undefined ) matrix = new THREE.Matrix4();
  2096. matrix.makeRotationFromQuaternion( q );
  2097. return this.setFromRotationMatrix( matrix, order, update );
  2098. };
  2099. }(),
  2100. setFromVector3: function ( v, order ) {
  2101. return this.set( v.x, v.y, v.z, order || this._order );
  2102. },
  2103. reorder: function () {
  2104. // WARNING: this discards revolution information -bhouston
  2105. var q = new THREE.Quaternion();
  2106. return function reorder( newOrder ) {
  2107. q.setFromEuler( this );
  2108. return this.setFromQuaternion( q, newOrder );
  2109. };
  2110. }(),
  2111. equals: function ( euler ) {
  2112. return ( euler._x === this._x ) && ( euler._y === this._y ) && ( euler._z === this._z ) && ( euler._order === this._order );
  2113. },
  2114. fromArray: function ( array ) {
  2115. this._x = array[ 0 ];
  2116. this._y = array[ 1 ];
  2117. this._z = array[ 2 ];
  2118. if ( array[ 3 ] !== undefined ) this._order = array[ 3 ];
  2119. this.onChangeCallback();
  2120. return this;
  2121. },
  2122. toArray: function ( array, offset ) {
  2123. if ( array === undefined ) array = [];
  2124. if ( offset === undefined ) offset = 0;
  2125. array[ offset ] = this._x;
  2126. array[ offset + 1 ] = this._y;
  2127. array[ offset + 2 ] = this._z;
  2128. array[ offset + 3 ] = this._order;
  2129. return array;
  2130. },
  2131. toVector3: function ( optionalResult ) {
  2132. if ( optionalResult ) {
  2133. return optionalResult.set( this._x, this._y, this._z );
  2134. } else {
  2135. return new THREE.Vector3( this._x, this._y, this._z );
  2136. }
  2137. },
  2138. onChange: function ( callback ) {
  2139. this.onChangeCallback = callback;
  2140. return this;
  2141. },
  2142. onChangeCallback: function () {}
  2143. };
  2144. // File:src/math/Line3.js
  2145. /**
  2146. * @author bhouston / http://clara.io
  2147. */
  2148. THREE.Line3 = function ( start, end ) {
  2149. this.start = ( start !== undefined ) ? start : new THREE.Vector3();
  2150. this.end = ( end !== undefined ) ? end : new THREE.Vector3();
  2151. };
  2152. THREE.Line3.prototype = {
  2153. constructor: THREE.Line3,
  2154. set: function ( start, end ) {
  2155. this.start.copy( start );
  2156. this.end.copy( end );
  2157. return this;
  2158. },
  2159. clone: function () {
  2160. return new this.constructor().copy( this );
  2161. },
  2162. copy: function ( line ) {
  2163. this.start.copy( line.start );
  2164. this.end.copy( line.end );
  2165. return this;
  2166. },
  2167. center: function ( optionalTarget ) {
  2168. var result = optionalTarget || new THREE.Vector3();
  2169. return result.addVectors( this.start, this.end ).multiplyScalar( 0.5 );
  2170. },
  2171. delta: function ( optionalTarget ) {
  2172. var result = optionalTarget || new THREE.Vector3();
  2173. return result.subVectors( this.end, this.start );
  2174. },
  2175. distanceSq: function () {
  2176. return this.start.distanceToSquared( this.end );
  2177. },
  2178. distance: function () {
  2179. return this.start.distanceTo( this.end );
  2180. },
  2181. at: function ( t, optionalTarget ) {
  2182. var result = optionalTarget || new THREE.Vector3();
  2183. return this.delta( result ).multiplyScalar( t ).add( this.start );
  2184. },
  2185. closestPointToPointParameter: function () {
  2186. var startP = new THREE.Vector3();
  2187. var startEnd = new THREE.Vector3();
  2188. return function closestPointToPointParameter( point, clampToLine ) {
  2189. startP.subVectors( point, this.start );
  2190. startEnd.subVectors( this.end, this.start );
  2191. var startEnd2 = startEnd.dot( startEnd );
  2192. var startEnd_startP = startEnd.dot( startP );
  2193. var t = startEnd_startP / startEnd2;
  2194. if ( clampToLine ) {
  2195. t = THREE.Math.clamp( t, 0, 1 );
  2196. }
  2197. return t;
  2198. };
  2199. }(),
  2200. closestPointToPoint: function ( point, clampToLine, optionalTarget ) {
  2201. var t = this.closestPointToPointParameter( point, clampToLine );
  2202. var result = optionalTarget || new THREE.Vector3();
  2203. return this.delta( result ).multiplyScalar( t ).add( this.start );
  2204. },
  2205. applyMatrix4: function ( matrix ) {
  2206. this.start.applyMatrix4( matrix );
  2207. this.end.applyMatrix4( matrix );
  2208. return this;
  2209. },
  2210. equals: function ( line ) {
  2211. return line.start.equals( this.start ) && line.end.equals( this.end );
  2212. }
  2213. };
  2214. // File:src/math/Box2.js
  2215. /**
  2216. * @author bhouston / http://clara.io
  2217. */
  2218. THREE.Box2 = function ( min, max ) {
  2219. this.min = ( min !== undefined ) ? min : new THREE.Vector2( + Infinity, + Infinity );
  2220. this.max = ( max !== undefined ) ? max : new THREE.Vector2( - Infinity, - Infinity );
  2221. };
  2222. THREE.Box2.prototype = {
  2223. constructor: THREE.Box2,
  2224. set: function ( min, max ) {
  2225. this.min.copy( min );
  2226. this.max.copy( max );
  2227. return this;
  2228. },
  2229. setFromPoints: function ( points ) {
  2230. this.makeEmpty();
  2231. for ( var i = 0, il = points.length; i < il; i ++ ) {
  2232. this.expandByPoint( points[ i ] );
  2233. }
  2234. return this;
  2235. },
  2236. setFromCenterAndSize: function () {
  2237. var v1 = new THREE.Vector2();
  2238. return function setFromCenterAndSize( center, size ) {
  2239. var halfSize = v1.copy( size ).multiplyScalar( 0.5 );
  2240. this.min.copy( center ).sub( halfSize );
  2241. this.max.copy( center ).add( halfSize );
  2242. return this;
  2243. };
  2244. }(),
  2245. clone: function () {
  2246. return new this.constructor().copy( this );
  2247. },
  2248. copy: function ( box ) {
  2249. this.min.copy( box.min );
  2250. this.max.copy( box.max );
  2251. return this;
  2252. },
  2253. makeEmpty: function () {
  2254. this.min.x = this.min.y = + Infinity;
  2255. this.max.x = this.max.y = - Infinity;
  2256. return this;
  2257. },
  2258. isEmpty: function () {
  2259. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  2260. return ( this.max.x < this.min.x ) || ( this.max.y < this.min.y );
  2261. },
  2262. center: function ( optionalTarget ) {
  2263. var result = optionalTarget || new THREE.Vector2();
  2264. return result.addVectors( this.min, this.max ).multiplyScalar( 0.5 );
  2265. },
  2266. size: function ( optionalTarget ) {
  2267. var result = optionalTarget || new THREE.Vector2();
  2268. return result.subVectors( this.max, this.min );
  2269. },
  2270. expandByPoint: function ( point ) {
  2271. this.min.min( point );
  2272. this.max.max( point );
  2273. return this;
  2274. },
  2275. expandByVector: function ( vector ) {
  2276. this.min.sub( vector );
  2277. this.max.add( vector );
  2278. return this;
  2279. },
  2280. expandByScalar: function ( scalar ) {
  2281. this.min.addScalar( - scalar );
  2282. this.max.addScalar( scalar );
  2283. return this;
  2284. },
  2285. containsPoint: function ( point ) {
  2286. if ( point.x < this.min.x || point.x > this.max.x ||
  2287. point.y < this.min.y || point.y > this.max.y ) {
  2288. return false;
  2289. }
  2290. return true;
  2291. },
  2292. containsBox: function ( box ) {
  2293. if ( ( this.min.x <= box.min.x ) && ( box.max.x <= this.max.x ) &&
  2294. ( this.min.y <= box.min.y ) && ( box.max.y <= this.max.y ) ) {
  2295. return true;
  2296. }
  2297. return false;
  2298. },
  2299. getParameter: function ( point, optionalTarget ) {
  2300. // This can potentially have a divide by zero if the box
  2301. // has a size dimension of 0.
  2302. var result = optionalTarget || new THREE.Vector2();
  2303. return result.set(
  2304. ( point.x - this.min.x ) / ( this.max.x - this.min.x ),
  2305. ( point.y - this.min.y ) / ( this.max.y - this.min.y )
  2306. );
  2307. },
  2308. intersectsBox: function ( box ) {
  2309. // using 6 splitting planes to rule out intersections.
  2310. if ( box.max.x < this.min.x || box.min.x > this.max.x ||
  2311. box.max.y < this.min.y || box.min.y > this.max.y ) {
  2312. return false;
  2313. }
  2314. return true;
  2315. },
  2316. clampPoint: function ( point, optionalTarget ) {
  2317. var result = optionalTarget || new THREE.Vector2();
  2318. return result.copy( point ).clamp( this.min, this.max );
  2319. },
  2320. distanceToPoint: function () {
  2321. var v1 = new THREE.Vector2();
  2322. return function distanceToPoint( point ) {
  2323. var clampedPoint = v1.copy( point ).clamp( this.min, this.max );
  2324. return clampedPoint.sub( point ).length();
  2325. };
  2326. }(),
  2327. intersect: function ( box ) {
  2328. this.min.max( box.min );
  2329. this.max.min( box.max );
  2330. return this;
  2331. },
  2332. union: function ( box ) {
  2333. this.min.min( box.min );
  2334. this.max.max( box.max );
  2335. return this;
  2336. },
  2337. translate: function ( offset ) {
  2338. this.min.add( offset );
  2339. this.max.add( offset );
  2340. return this;
  2341. },
  2342. equals: function ( box ) {
  2343. return box.min.equals( this.min ) && box.max.equals( this.max );
  2344. }
  2345. };
  2346. // File:src/math/Box3.js
  2347. /**
  2348. * @author bhouston / http://clara.io
  2349. * @author WestLangley / http://github.com/WestLangley
  2350. */
  2351. THREE.Box3 = function ( min, max ) {
  2352. this.min = ( min !== undefined ) ? min : new THREE.Vector3( + Infinity, + Infinity, + Infinity );
  2353. this.max = ( max !== undefined ) ? max : new THREE.Vector3( - Infinity, - Infinity, - Infinity );
  2354. };
  2355. THREE.Box3.prototype = {
  2356. constructor: THREE.Box3,
  2357. set: function ( min, max ) {
  2358. this.min.copy( min );
  2359. this.max.copy( max );
  2360. return this;
  2361. },
  2362. setFromArray: function ( array ) {
  2363. var minX = + Infinity;
  2364. var minY = + Infinity;
  2365. var minZ = + Infinity;
  2366. var maxX = - Infinity;
  2367. var maxY = - Infinity;
  2368. var maxZ = - Infinity;
  2369. for ( var i = 0, l = array.length; i < l; i += 3 ) {
  2370. var x = array[ i ];
  2371. var y = array[ i + 1 ];
  2372. var z = array[ i + 2 ];
  2373. if ( x < minX ) minX = x;
  2374. if ( y < minY ) minY = y;
  2375. if ( z < minZ ) minZ = z;
  2376. if ( x > maxX ) maxX = x;
  2377. if ( y > maxY ) maxY = y;
  2378. if ( z > maxZ ) maxZ = z;
  2379. }
  2380. this.min.set( minX, minY, minZ );
  2381. this.max.set( maxX, maxY, maxZ );
  2382. },
  2383. setFromPoints: function ( points ) {
  2384. this.makeEmpty();
  2385. for ( var i = 0, il = points.length; i < il; i ++ ) {
  2386. this.expandByPoint( points[ i ] );
  2387. }
  2388. return this;
  2389. },
  2390. setFromCenterAndSize: function () {
  2391. var v1 = new THREE.Vector3();
  2392. return function setFromCenterAndSize( center, size ) {
  2393. var halfSize = v1.copy( size ).multiplyScalar( 0.5 );
  2394. this.min.copy( center ).sub( halfSize );
  2395. this.max.copy( center ).add( halfSize );
  2396. return this;
  2397. };
  2398. }(),
  2399. setFromObject: function () {
  2400. // Computes the world-axis-aligned bounding box of an object (including its children),
  2401. // accounting for both the object's, and children's, world transforms
  2402. var v1 = new THREE.Vector3();
  2403. return function setFromObject( object ) {
  2404. var scope = this;
  2405. object.updateMatrixWorld( true );
  2406. this.makeEmpty();
  2407. object.traverse( function ( node ) {
  2408. var geometry = node.geometry;
  2409. if ( geometry !== undefined ) {
  2410. if ( geometry instanceof THREE.Geometry ) {
  2411. var vertices = geometry.vertices;
  2412. for ( var i = 0, il = vertices.length; i < il; i ++ ) {
  2413. v1.copy( vertices[ i ] );
  2414. v1.applyMatrix4( node.matrixWorld );
  2415. scope.expandByPoint( v1 );
  2416. }
  2417. } else if ( geometry instanceof THREE.BufferGeometry && geometry.attributes[ 'position' ] !== undefined ) {
  2418. var positions = geometry.attributes[ 'position' ].array;
  2419. for ( var i = 0, il = positions.length; i < il; i += 3 ) {
  2420. v1.fromArray( positions, i );
  2421. v1.applyMatrix4( node.matrixWorld );
  2422. scope.expandByPoint( v1 );
  2423. }
  2424. }
  2425. }
  2426. } );
  2427. return this;
  2428. };
  2429. }(),
  2430. clone: function () {
  2431. return new this.constructor().copy( this );
  2432. },
  2433. copy: function ( box ) {
  2434. this.min.copy( box.min );
  2435. this.max.copy( box.max );
  2436. return this;
  2437. },
  2438. makeEmpty: function () {
  2439. this.min.x = this.min.y = this.min.z = + Infinity;
  2440. this.max.x = this.max.y = this.max.z = - Infinity;
  2441. return this;
  2442. },
  2443. isEmpty: function () {
  2444. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  2445. return ( this.max.x < this.min.x ) || ( this.max.y < this.min.y ) || ( this.max.z < this.min.z );
  2446. },
  2447. center: function ( optionalTarget ) {
  2448. var result = optionalTarget || new THREE.Vector3();
  2449. return result.addVectors( this.min, this.max ).multiplyScalar( 0.5 );
  2450. },
  2451. size: function ( optionalTarget ) {
  2452. var result = optionalTarget || new THREE.Vector3();
  2453. return result.subVectors( this.max, this.min );
  2454. },
  2455. expandByPoint: function ( point ) {
  2456. this.min.min( point );
  2457. this.max.max( point );
  2458. return this;
  2459. },
  2460. expandByVector: function ( vector ) {
  2461. this.min.sub( vector );
  2462. this.max.add( vector );
  2463. return this;
  2464. },
  2465. expandByScalar: function ( scalar ) {
  2466. this.min.addScalar( - scalar );
  2467. this.max.addScalar( scalar );
  2468. return this;
  2469. },
  2470. containsPoint: function ( point ) {
  2471. if ( point.x < this.min.x || point.x > this.max.x ||
  2472. point.y < this.min.y || point.y > this.max.y ||
  2473. point.z < this.min.z || point.z > this.max.z ) {
  2474. return false;
  2475. }
  2476. return true;
  2477. },
  2478. containsBox: function ( box ) {
  2479. if ( ( this.min.x <= box.min.x ) && ( box.max.x <= this.max.x ) &&
  2480. ( this.min.y <= box.min.y ) && ( box.max.y <= this.max.y ) &&
  2481. ( this.min.z <= box.min.z ) && ( box.max.z <= this.max.z ) ) {
  2482. return true;
  2483. }
  2484. return false;
  2485. },
  2486. getParameter: function ( point, optionalTarget ) {
  2487. // This can potentially have a divide by zero if the box
  2488. // has a size dimension of 0.
  2489. var result = optionalTarget || new THREE.Vector3();
  2490. return result.set(
  2491. ( point.x - this.min.x ) / ( this.max.x - this.min.x ),
  2492. ( point.y - this.min.y ) / ( this.max.y - this.min.y ),
  2493. ( point.z - this.min.z ) / ( this.max.z - this.min.z )
  2494. );
  2495. },
  2496. intersectsBox: function ( box ) {
  2497. // using 6 splitting planes to rule out intersections.
  2498. if ( box.max.x < this.min.x || box.min.x > this.max.x ||
  2499. box.max.y < this.min.y || box.min.y > this.max.y ||
  2500. box.max.z < this.min.z || box.min.z > this.max.z ) {
  2501. return false;
  2502. }
  2503. return true;
  2504. },
  2505. intersectsSphere: ( function () {
  2506. var closestPoint;
  2507. return function intersectsSphere( sphere ) {
  2508. if ( closestPoint === undefined ) closestPoint = new THREE.Vector3();
  2509. // Find the point on the AABB closest to the sphere center.
  2510. this.clampPoint( sphere.center, closestPoint );
  2511. // If that point is inside the sphere, the AABB and sphere intersect.
  2512. return closestPoint.distanceToSquared( sphere.center ) <= ( sphere.radius * sphere.radius );
  2513. };
  2514. } )(),
  2515. intersectsPlane: function ( plane ) {
  2516. // We compute the minimum and maximum dot product values. If those values
  2517. // are on the same side (back or front) of the plane, then there is no intersection.
  2518. var min, max;
  2519. if ( plane.normal.x > 0 ) {
  2520. min = plane.normal.x * this.min.x;
  2521. max = plane.normal.x * this.max.x;
  2522. } else {
  2523. min = plane.normal.x * this.max.x;
  2524. max = plane.normal.x * this.min.x;
  2525. }
  2526. if ( plane.normal.y > 0 ) {
  2527. min += plane.normal.y * this.min.y;
  2528. max += plane.normal.y * this.max.y;
  2529. } else {
  2530. min += plane.normal.y * this.max.y;
  2531. max += plane.normal.y * this.min.y;
  2532. }
  2533. if ( plane.normal.z > 0 ) {
  2534. min += plane.normal.z * this.min.z;
  2535. max += plane.normal.z * this.max.z;
  2536. } else {
  2537. min += plane.normal.z * this.max.z;
  2538. max += plane.normal.z * this.min.z;
  2539. }
  2540. return ( min <= plane.constant && max >= plane.constant );
  2541. },
  2542. clampPoint: function ( point, optionalTarget ) {
  2543. var result = optionalTarget || new THREE.Vector3();
  2544. return result.copy( point ).clamp( this.min, this.max );
  2545. },
  2546. distanceToPoint: function () {
  2547. var v1 = new THREE.Vector3();
  2548. return function distanceToPoint( point ) {
  2549. var clampedPoint = v1.copy( point ).clamp( this.min, this.max );
  2550. return clampedPoint.sub( point ).length();
  2551. };
  2552. }(),
  2553. getBoundingSphere: function () {
  2554. var v1 = new THREE.Vector3();
  2555. return function getBoundingSphere( optionalTarget ) {
  2556. var result = optionalTarget || new THREE.Sphere();
  2557. result.center = this.center();
  2558. result.radius = this.size( v1 ).length() * 0.5;
  2559. return result;
  2560. };
  2561. }(),
  2562. intersect: function ( box ) {
  2563. this.min.max( box.min );
  2564. this.max.min( box.max );
  2565. // 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.
  2566. if( this.isEmpty() ) this.makeEmpty();
  2567. return this;
  2568. },
  2569. union: function ( box ) {
  2570. this.min.min( box.min );
  2571. this.max.max( box.max );
  2572. return this;
  2573. },
  2574. applyMatrix4: function () {
  2575. var points = [
  2576. new THREE.Vector3(),
  2577. new THREE.Vector3(),
  2578. new THREE.Vector3(),
  2579. new THREE.Vector3(),
  2580. new THREE.Vector3(),
  2581. new THREE.Vector3(),
  2582. new THREE.Vector3(),
  2583. new THREE.Vector3()
  2584. ];
  2585. return function applyMatrix4( matrix ) {
  2586. // transform of empty box is an empty box.
  2587. if( this.isEmpty() ) return this;
  2588. // NOTE: I am using a binary pattern to specify all 2^3 combinations below
  2589. points[ 0 ].set( this.min.x, this.min.y, this.min.z ).applyMatrix4( matrix ); // 000
  2590. points[ 1 ].set( this.min.x, this.min.y, this.max.z ).applyMatrix4( matrix ); // 001
  2591. points[ 2 ].set( this.min.x, this.max.y, this.min.z ).applyMatrix4( matrix ); // 010
  2592. points[ 3 ].set( this.min.x, this.max.y, this.max.z ).applyMatrix4( matrix ); // 011
  2593. points[ 4 ].set( this.max.x, this.min.y, this.min.z ).applyMatrix4( matrix ); // 100
  2594. points[ 5 ].set( this.max.x, this.min.y, this.max.z ).applyMatrix4( matrix ); // 101
  2595. points[ 6 ].set( this.max.x, this.max.y, this.min.z ).applyMatrix4( matrix ); // 110
  2596. points[ 7 ].set( this.max.x, this.max.y, this.max.z ).applyMatrix4( matrix ); // 111
  2597. this.setFromPoints( points );
  2598. return this;
  2599. };
  2600. }(),
  2601. translate: function ( offset ) {
  2602. this.min.add( offset );
  2603. this.max.add( offset );
  2604. return this;
  2605. },
  2606. equals: function ( box ) {
  2607. return box.min.equals( this.min ) && box.max.equals( this.max );
  2608. }
  2609. };
  2610. // File:src/math/Matrix3.js
  2611. /**
  2612. * @author alteredq / http://alteredqualia.com/
  2613. * @author WestLangley / http://github.com/WestLangley
  2614. * @author bhouston / http://clara.io
  2615. * @author tschw
  2616. */
  2617. THREE.Matrix3 = function () {
  2618. this.elements = new Float32Array( [
  2619. 1, 0, 0,
  2620. 0, 1, 0,
  2621. 0, 0, 1
  2622. ] );
  2623. if ( arguments.length > 0 ) {
  2624. console.error( 'THREE.Matrix3: the constructor no longer reads arguments. use .set() instead.' );
  2625. }
  2626. };
  2627. THREE.Matrix3.prototype = {
  2628. constructor: THREE.Matrix3,
  2629. set: function ( n11, n12, n13, n21, n22, n23, n31, n32, n33 ) {
  2630. var te = this.elements;
  2631. te[ 0 ] = n11; te[ 1 ] = n21; te[ 2 ] = n31;
  2632. te[ 3 ] = n12; te[ 4 ] = n22; te[ 5 ] = n32;
  2633. te[ 6 ] = n13; te[ 7 ] = n23; te[ 8 ] = n33;
  2634. return this;
  2635. },
  2636. identity: function () {
  2637. this.set(
  2638. 1, 0, 0,
  2639. 0, 1, 0,
  2640. 0, 0, 1
  2641. );
  2642. return this;
  2643. },
  2644. clone: function () {
  2645. return new this.constructor().fromArray( this.elements );
  2646. },
  2647. copy: function ( m ) {
  2648. var me = m.elements;
  2649. this.set(
  2650. me[ 0 ], me[ 3 ], me[ 6 ],
  2651. me[ 1 ], me[ 4 ], me[ 7 ],
  2652. me[ 2 ], me[ 5 ], me[ 8 ]
  2653. );
  2654. return this;
  2655. },
  2656. setFromMatrix4: function( m ) {
  2657. var me = m.elements;
  2658. this.set(
  2659. me[ 0 ], me[ 4 ], me[ 8 ],
  2660. me[ 1 ], me[ 5 ], me[ 9 ],
  2661. me[ 2 ], me[ 6 ], me[ 10 ]
  2662. );
  2663. return this;
  2664. },
  2665. applyToVector3Array: function () {
  2666. var v1;
  2667. return function applyToVector3Array( array, offset, length ) {
  2668. if ( v1 === undefined ) v1 = new THREE.Vector3();
  2669. if ( offset === undefined ) offset = 0;
  2670. if ( length === undefined ) length = array.length;
  2671. for ( var i = 0, j = offset; i < length; i += 3, j += 3 ) {
  2672. v1.fromArray( array, j );
  2673. v1.applyMatrix3( this );
  2674. v1.toArray( array, j );
  2675. }
  2676. return array;
  2677. };
  2678. }(),
  2679. applyToBuffer: function () {
  2680. var v1;
  2681. return function applyToBuffer( buffer, offset, length ) {
  2682. if ( v1 === undefined ) v1 = new THREE.Vector3();
  2683. if ( offset === undefined ) offset = 0;
  2684. if ( length === undefined ) length = buffer.length / buffer.itemSize;
  2685. for ( var i = 0, j = offset; i < length; i ++, j ++ ) {
  2686. v1.x = buffer.getX( j );
  2687. v1.y = buffer.getY( j );
  2688. v1.z = buffer.getZ( j );
  2689. v1.applyMatrix3( this );
  2690. buffer.setXYZ( v1.x, v1.y, v1.z );
  2691. }
  2692. return buffer;
  2693. };
  2694. }(),
  2695. multiplyScalar: function ( s ) {
  2696. var te = this.elements;
  2697. te[ 0 ] *= s; te[ 3 ] *= s; te[ 6 ] *= s;
  2698. te[ 1 ] *= s; te[ 4 ] *= s; te[ 7 ] *= s;
  2699. te[ 2 ] *= s; te[ 5 ] *= s; te[ 8 ] *= s;
  2700. return this;
  2701. },
  2702. determinant: function () {
  2703. var te = this.elements;
  2704. var a = te[ 0 ], b = te[ 1 ], c = te[ 2 ],
  2705. d = te[ 3 ], e = te[ 4 ], f = te[ 5 ],
  2706. g = te[ 6 ], h = te[ 7 ], i = te[ 8 ];
  2707. return a * e * i - a * f * h - b * d * i + b * f * g + c * d * h - c * e * g;
  2708. },
  2709. getInverse: function ( matrix, throwOnDegenerate ) {
  2710. if ( matrix instanceof THREE.Matrix4 ) {
  2711. console.error( "THREE.Matrix3.getInverse no longer takes a Matrix4 argument." );
  2712. }
  2713. var me = matrix.elements,
  2714. te = this.elements,
  2715. n11 = me[ 0 ], n21 = me[ 1 ], n31 = me[ 2 ],
  2716. n12 = me[ 3 ], n22 = me[ 4 ], n32 = me[ 5 ],
  2717. n13 = me[ 6 ], n23 = me[ 7 ], n33 = me[ 8 ],
  2718. t11 = n33 * n22 - n32 * n23,
  2719. t12 = n32 * n13 - n33 * n12,
  2720. t13 = n23 * n12 - n22 * n13,
  2721. det = n11 * t11 + n21 * t12 + n31 * t13;
  2722. if ( det === 0 ) {
  2723. var msg = "THREE.Matrix3.getInverse(): can't invert matrix, determinant is 0";
  2724. if ( throwOnDegenerate || false ) {
  2725. throw new Error( msg );
  2726. } else {
  2727. console.warn( msg );
  2728. }
  2729. return this.identity();
  2730. }
  2731. var detInv = 1 / det;
  2732. te[ 0 ] = t11 * detInv;
  2733. te[ 1 ] = ( n31 * n23 - n33 * n21 ) * detInv;
  2734. te[ 2 ] = ( n32 * n21 - n31 * n22 ) * detInv;
  2735. te[ 3 ] = t12 * detInv;
  2736. te[ 4 ] = ( n33 * n11 - n31 * n13 ) * detInv;
  2737. te[ 5 ] = ( n31 * n12 - n32 * n11 ) * detInv;
  2738. te[ 6 ] = t13 * detInv;
  2739. te[ 7 ] = ( n21 * n13 - n23 * n11 ) * detInv;
  2740. te[ 8 ] = ( n22 * n11 - n21 * n12 ) * detInv;
  2741. return this;
  2742. },
  2743. transpose: function () {
  2744. var tmp, m = this.elements;
  2745. tmp = m[ 1 ]; m[ 1 ] = m[ 3 ]; m[ 3 ] = tmp;
  2746. tmp = m[ 2 ]; m[ 2 ] = m[ 6 ]; m[ 6 ] = tmp;
  2747. tmp = m[ 5 ]; m[ 5 ] = m[ 7 ]; m[ 7 ] = tmp;
  2748. return this;
  2749. },
  2750. flattenToArrayOffset: function ( array, offset ) {
  2751. console.warn( "THREE.Matrix3: .flattenToArrayOffset is deprecated " +
  2752. "- just use .toArray instead." );
  2753. return this.toArray( array, offset );
  2754. },
  2755. getNormalMatrix: function ( matrix4 ) {
  2756. return this.setFromMatrix4( matrix4 ).getInverse( this ).transpose();
  2757. },
  2758. transposeIntoArray: function ( r ) {
  2759. var m = this.elements;
  2760. r[ 0 ] = m[ 0 ];
  2761. r[ 1 ] = m[ 3 ];
  2762. r[ 2 ] = m[ 6 ];
  2763. r[ 3 ] = m[ 1 ];
  2764. r[ 4 ] = m[ 4 ];
  2765. r[ 5 ] = m[ 7 ];
  2766. r[ 6 ] = m[ 2 ];
  2767. r[ 7 ] = m[ 5 ];
  2768. r[ 8 ] = m[ 8 ];
  2769. return this;
  2770. },
  2771. fromArray: function ( array ) {
  2772. this.elements.set( array );
  2773. return this;
  2774. },
  2775. toArray: function ( array, offset ) {
  2776. if ( array === undefined ) array = [];
  2777. if ( offset === undefined ) offset = 0;
  2778. var te = this.elements;
  2779. array[ offset ] = te[ 0 ];
  2780. array[ offset + 1 ] = te[ 1 ];
  2781. array[ offset + 2 ] = te[ 2 ];
  2782. array[ offset + 3 ] = te[ 3 ];
  2783. array[ offset + 4 ] = te[ 4 ];
  2784. array[ offset + 5 ] = te[ 5 ];
  2785. array[ offset + 6 ] = te[ 6 ];
  2786. array[ offset + 7 ] = te[ 7 ];
  2787. array[ offset + 8 ] = te[ 8 ];
  2788. return array;
  2789. }
  2790. };
  2791. // File:src/math/Matrix4.js
  2792. /**
  2793. * @author mrdoob / http://mrdoob.com/
  2794. * @author supereggbert / http://www.paulbrunt.co.uk/
  2795. * @author philogb / http://blog.thejit.org/
  2796. * @author jordi_ros / http://plattsoft.com
  2797. * @author D1plo1d / http://github.com/D1plo1d
  2798. * @author alteredq / http://alteredqualia.com/
  2799. * @author mikael emtinger / http://gomo.se/
  2800. * @author timknip / http://www.floorplanner.com/
  2801. * @author bhouston / http://clara.io
  2802. * @author WestLangley / http://github.com/WestLangley
  2803. */
  2804. THREE.Matrix4 = function () {
  2805. this.elements = new Float32Array( [
  2806. 1, 0, 0, 0,
  2807. 0, 1, 0, 0,
  2808. 0, 0, 1, 0,
  2809. 0, 0, 0, 1
  2810. ] );
  2811. if ( arguments.length > 0 ) {
  2812. console.error( 'THREE.Matrix4: the constructor no longer reads arguments. use .set() instead.' );
  2813. }
  2814. };
  2815. THREE.Matrix4.prototype = {
  2816. constructor: THREE.Matrix4,
  2817. set: function ( n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44 ) {
  2818. var te = this.elements;
  2819. te[ 0 ] = n11; te[ 4 ] = n12; te[ 8 ] = n13; te[ 12 ] = n14;
  2820. te[ 1 ] = n21; te[ 5 ] = n22; te[ 9 ] = n23; te[ 13 ] = n24;
  2821. te[ 2 ] = n31; te[ 6 ] = n32; te[ 10 ] = n33; te[ 14 ] = n34;
  2822. te[ 3 ] = n41; te[ 7 ] = n42; te[ 11 ] = n43; te[ 15 ] = n44;
  2823. return this;
  2824. },
  2825. identity: function () {
  2826. this.set(
  2827. 1, 0, 0, 0,
  2828. 0, 1, 0, 0,
  2829. 0, 0, 1, 0,
  2830. 0, 0, 0, 1
  2831. );
  2832. return this;
  2833. },
  2834. clone: function () {
  2835. return new THREE.Matrix4().fromArray( this.elements );
  2836. },
  2837. copy: function ( m ) {
  2838. this.elements.set( m.elements );
  2839. return this;
  2840. },
  2841. copyPosition: function ( m ) {
  2842. var te = this.elements;
  2843. var me = m.elements;
  2844. te[ 12 ] = me[ 12 ];
  2845. te[ 13 ] = me[ 13 ];
  2846. te[ 14 ] = me[ 14 ];
  2847. return this;
  2848. },
  2849. extractBasis: function ( xAxis, yAxis, zAxis ) {
  2850. xAxis.setFromMatrixColumn( this, 0 );
  2851. yAxis.setFromMatrixColumn( this, 1 );
  2852. zAxis.setFromMatrixColumn( this, 2 );
  2853. return this;
  2854. },
  2855. makeBasis: function ( xAxis, yAxis, zAxis ) {
  2856. this.set(
  2857. xAxis.x, yAxis.x, zAxis.x, 0,
  2858. xAxis.y, yAxis.y, zAxis.y, 0,
  2859. xAxis.z, yAxis.z, zAxis.z, 0,
  2860. 0, 0, 0, 1
  2861. );
  2862. return this;
  2863. },
  2864. extractRotation: function () {
  2865. var v1;
  2866. return function extractRotation( m ) {
  2867. if ( v1 === undefined ) v1 = new THREE.Vector3();
  2868. var te = this.elements;
  2869. var me = m.elements;
  2870. var scaleX = 1 / v1.setFromMatrixColumn( m, 0 ).length();
  2871. var scaleY = 1 / v1.setFromMatrixColumn( m, 1 ).length();
  2872. var scaleZ = 1 / v1.setFromMatrixColumn( m, 2 ).length();
  2873. te[ 0 ] = me[ 0 ] * scaleX;
  2874. te[ 1 ] = me[ 1 ] * scaleX;
  2875. te[ 2 ] = me[ 2 ] * scaleX;
  2876. te[ 4 ] = me[ 4 ] * scaleY;
  2877. te[ 5 ] = me[ 5 ] * scaleY;
  2878. te[ 6 ] = me[ 6 ] * scaleY;
  2879. te[ 8 ] = me[ 8 ] * scaleZ;
  2880. te[ 9 ] = me[ 9 ] * scaleZ;
  2881. te[ 10 ] = me[ 10 ] * scaleZ;
  2882. return this;
  2883. };
  2884. }(),
  2885. makeRotationFromEuler: function ( euler ) {
  2886. if ( euler instanceof THREE.Euler === false ) {
  2887. console.error( 'THREE.Matrix: .makeRotationFromEuler() now expects a Euler rotation rather than a Vector3 and order.' );
  2888. }
  2889. var te = this.elements;
  2890. var x = euler.x, y = euler.y, z = euler.z;
  2891. var a = Math.cos( x ), b = Math.sin( x );
  2892. var c = Math.cos( y ), d = Math.sin( y );
  2893. var e = Math.cos( z ), f = Math.sin( z );
  2894. if ( euler.order === 'XYZ' ) {
  2895. var ae = a * e, af = a * f, be = b * e, bf = b * f;
  2896. te[ 0 ] = c * e;
  2897. te[ 4 ] = - c * f;
  2898. te[ 8 ] = d;
  2899. te[ 1 ] = af + be * d;
  2900. te[ 5 ] = ae - bf * d;
  2901. te[ 9 ] = - b * c;
  2902. te[ 2 ] = bf - ae * d;
  2903. te[ 6 ] = be + af * d;
  2904. te[ 10 ] = a * c;
  2905. } else if ( euler.order === 'YXZ' ) {
  2906. var ce = c * e, cf = c * f, de = d * e, df = d * f;
  2907. te[ 0 ] = ce + df * b;
  2908. te[ 4 ] = de * b - cf;
  2909. te[ 8 ] = a * d;
  2910. te[ 1 ] = a * f;
  2911. te[ 5 ] = a * e;
  2912. te[ 9 ] = - b;
  2913. te[ 2 ] = cf * b - de;
  2914. te[ 6 ] = df + ce * b;
  2915. te[ 10 ] = a * c;
  2916. } else if ( euler.order === 'ZXY' ) {
  2917. var ce = c * e, cf = c * f, de = d * e, df = d * f;
  2918. te[ 0 ] = ce - df * b;
  2919. te[ 4 ] = - a * f;
  2920. te[ 8 ] = de + cf * b;
  2921. te[ 1 ] = cf + de * b;
  2922. te[ 5 ] = a * e;
  2923. te[ 9 ] = df - ce * b;
  2924. te[ 2 ] = - a * d;
  2925. te[ 6 ] = b;
  2926. te[ 10 ] = a * c;
  2927. } else if ( euler.order === 'ZYX' ) {
  2928. var ae = a * e, af = a * f, be = b * e, bf = b * f;
  2929. te[ 0 ] = c * e;
  2930. te[ 4 ] = be * d - af;
  2931. te[ 8 ] = ae * d + bf;
  2932. te[ 1 ] = c * f;
  2933. te[ 5 ] = bf * d + ae;
  2934. te[ 9 ] = af * d - be;
  2935. te[ 2 ] = - d;
  2936. te[ 6 ] = b * c;
  2937. te[ 10 ] = a * c;
  2938. } else if ( euler.order === 'YZX' ) {
  2939. var ac = a * c, ad = a * d, bc = b * c, bd = b * d;
  2940. te[ 0 ] = c * e;
  2941. te[ 4 ] = bd - ac * f;
  2942. te[ 8 ] = bc * f + ad;
  2943. te[ 1 ] = f;
  2944. te[ 5 ] = a * e;
  2945. te[ 9 ] = - b * e;
  2946. te[ 2 ] = - d * e;
  2947. te[ 6 ] = ad * f + bc;
  2948. te[ 10 ] = ac - bd * f;
  2949. } else if ( euler.order === 'XZY' ) {
  2950. var ac = a * c, ad = a * d, bc = b * c, bd = b * d;
  2951. te[ 0 ] = c * e;
  2952. te[ 4 ] = - f;
  2953. te[ 8 ] = d * e;
  2954. te[ 1 ] = ac * f + bd;
  2955. te[ 5 ] = a * e;
  2956. te[ 9 ] = ad * f - bc;
  2957. te[ 2 ] = bc * f - ad;
  2958. te[ 6 ] = b * e;
  2959. te[ 10 ] = bd * f + ac;
  2960. }
  2961. // last column
  2962. te[ 3 ] = 0;
  2963. te[ 7 ] = 0;
  2964. te[ 11 ] = 0;
  2965. // bottom row
  2966. te[ 12 ] = 0;
  2967. te[ 13 ] = 0;
  2968. te[ 14 ] = 0;
  2969. te[ 15 ] = 1;
  2970. return this;
  2971. },
  2972. makeRotationFromQuaternion: function ( q ) {
  2973. var te = this.elements;
  2974. var x = q.x, y = q.y, z = q.z, w = q.w;
  2975. var x2 = x + x, y2 = y + y, z2 = z + z;
  2976. var xx = x * x2, xy = x * y2, xz = x * z2;
  2977. var yy = y * y2, yz = y * z2, zz = z * z2;
  2978. var wx = w * x2, wy = w * y2, wz = w * z2;
  2979. te[ 0 ] = 1 - ( yy + zz );
  2980. te[ 4 ] = xy - wz;
  2981. te[ 8 ] = xz + wy;
  2982. te[ 1 ] = xy + wz;
  2983. te[ 5 ] = 1 - ( xx + zz );
  2984. te[ 9 ] = yz - wx;
  2985. te[ 2 ] = xz - wy;
  2986. te[ 6 ] = yz + wx;
  2987. te[ 10 ] = 1 - ( xx + yy );
  2988. // last column
  2989. te[ 3 ] = 0;
  2990. te[ 7 ] = 0;
  2991. te[ 11 ] = 0;
  2992. // bottom row
  2993. te[ 12 ] = 0;
  2994. te[ 13 ] = 0;
  2995. te[ 14 ] = 0;
  2996. te[ 15 ] = 1;
  2997. return this;
  2998. },
  2999. lookAt: function () {
  3000. var x, y, z;
  3001. return function lookAt( eye, target, up ) {
  3002. if ( x === undefined ) {
  3003. x = new THREE.Vector3();
  3004. y = new THREE.Vector3();
  3005. z = new THREE.Vector3();
  3006. }
  3007. var te = this.elements;
  3008. z.subVectors( eye, target ).normalize();
  3009. if ( z.lengthSq() === 0 ) {
  3010. z.z = 1;
  3011. }
  3012. x.crossVectors( up, z ).normalize();
  3013. if ( x.lengthSq() === 0 ) {
  3014. z.z += 0.0001;
  3015. x.crossVectors( up, z ).normalize();
  3016. }
  3017. y.crossVectors( z, x );
  3018. te[ 0 ] = x.x; te[ 4 ] = y.x; te[ 8 ] = z.x;
  3019. te[ 1 ] = x.y; te[ 5 ] = y.y; te[ 9 ] = z.y;
  3020. te[ 2 ] = x.z; te[ 6 ] = y.z; te[ 10 ] = z.z;
  3021. return this;
  3022. };
  3023. }(),
  3024. multiply: function ( m, n ) {
  3025. if ( n !== undefined ) {
  3026. console.warn( 'THREE.Matrix4: .multiply() now only accepts one argument. Use .multiplyMatrices( a, b ) instead.' );
  3027. return this.multiplyMatrices( m, n );
  3028. }
  3029. return this.multiplyMatrices( this, m );
  3030. },
  3031. premultiply: function ( m ) {
  3032. return this.multiplyMatrices( m, this );
  3033. },
  3034. multiplyMatrices: function ( a, b ) {
  3035. var ae = a.elements;
  3036. var be = b.elements;
  3037. var te = this.elements;
  3038. var a11 = ae[ 0 ], a12 = ae[ 4 ], a13 = ae[ 8 ], a14 = ae[ 12 ];
  3039. var a21 = ae[ 1 ], a22 = ae[ 5 ], a23 = ae[ 9 ], a24 = ae[ 13 ];
  3040. var a31 = ae[ 2 ], a32 = ae[ 6 ], a33 = ae[ 10 ], a34 = ae[ 14 ];
  3041. var a41 = ae[ 3 ], a42 = ae[ 7 ], a43 = ae[ 11 ], a44 = ae[ 15 ];
  3042. var b11 = be[ 0 ], b12 = be[ 4 ], b13 = be[ 8 ], b14 = be[ 12 ];
  3043. var b21 = be[ 1 ], b22 = be[ 5 ], b23 = be[ 9 ], b24 = be[ 13 ];
  3044. var b31 = be[ 2 ], b32 = be[ 6 ], b33 = be[ 10 ], b34 = be[ 14 ];
  3045. var b41 = be[ 3 ], b42 = be[ 7 ], b43 = be[ 11 ], b44 = be[ 15 ];
  3046. te[ 0 ] = a11 * b11 + a12 * b21 + a13 * b31 + a14 * b41;
  3047. te[ 4 ] = a11 * b12 + a12 * b22 + a13 * b32 + a14 * b42;
  3048. te[ 8 ] = a11 * b13 + a12 * b23 + a13 * b33 + a14 * b43;
  3049. te[ 12 ] = a11 * b14 + a12 * b24 + a13 * b34 + a14 * b44;
  3050. te[ 1 ] = a21 * b11 + a22 * b21 + a23 * b31 + a24 * b41;
  3051. te[ 5 ] = a21 * b12 + a22 * b22 + a23 * b32 + a24 * b42;
  3052. te[ 9 ] = a21 * b13 + a22 * b23 + a23 * b33 + a24 * b43;
  3053. te[ 13 ] = a21 * b14 + a22 * b24 + a23 * b34 + a24 * b44;
  3054. te[ 2 ] = a31 * b11 + a32 * b21 + a33 * b31 + a34 * b41;
  3055. te[ 6 ] = a31 * b12 + a32 * b22 + a33 * b32 + a34 * b42;
  3056. te[ 10 ] = a31 * b13 + a32 * b23 + a33 * b33 + a34 * b43;
  3057. te[ 14 ] = a31 * b14 + a32 * b24 + a33 * b34 + a34 * b44;
  3058. te[ 3 ] = a41 * b11 + a42 * b21 + a43 * b31 + a44 * b41;
  3059. te[ 7 ] = a41 * b12 + a42 * b22 + a43 * b32 + a44 * b42;
  3060. te[ 11 ] = a41 * b13 + a42 * b23 + a43 * b33 + a44 * b43;
  3061. te[ 15 ] = a41 * b14 + a42 * b24 + a43 * b34 + a44 * b44;
  3062. return this;
  3063. },
  3064. multiplyToArray: function ( a, b, r ) {
  3065. var te = this.elements;
  3066. this.multiplyMatrices( a, b );
  3067. r[ 0 ] = te[ 0 ]; r[ 1 ] = te[ 1 ]; r[ 2 ] = te[ 2 ]; r[ 3 ] = te[ 3 ];
  3068. r[ 4 ] = te[ 4 ]; r[ 5 ] = te[ 5 ]; r[ 6 ] = te[ 6 ]; r[ 7 ] = te[ 7 ];
  3069. r[ 8 ] = te[ 8 ]; r[ 9 ] = te[ 9 ]; r[ 10 ] = te[ 10 ]; r[ 11 ] = te[ 11 ];
  3070. r[ 12 ] = te[ 12 ]; r[ 13 ] = te[ 13 ]; r[ 14 ] = te[ 14 ]; r[ 15 ] = te[ 15 ];
  3071. return this;
  3072. },
  3073. multiplyScalar: function ( s ) {
  3074. var te = this.elements;
  3075. te[ 0 ] *= s; te[ 4 ] *= s; te[ 8 ] *= s; te[ 12 ] *= s;
  3076. te[ 1 ] *= s; te[ 5 ] *= s; te[ 9 ] *= s; te[ 13 ] *= s;
  3077. te[ 2 ] *= s; te[ 6 ] *= s; te[ 10 ] *= s; te[ 14 ] *= s;
  3078. te[ 3 ] *= s; te[ 7 ] *= s; te[ 11 ] *= s; te[ 15 ] *= s;
  3079. return this;
  3080. },
  3081. applyToVector3Array: function () {
  3082. var v1;
  3083. return function applyToVector3Array( array, offset, length ) {
  3084. if ( v1 === undefined ) v1 = new THREE.Vector3();
  3085. if ( offset === undefined ) offset = 0;
  3086. if ( length === undefined ) length = array.length;
  3087. for ( var i = 0, j = offset; i < length; i += 3, j += 3 ) {
  3088. v1.fromArray( array, j );
  3089. v1.applyMatrix4( this );
  3090. v1.toArray( array, j );
  3091. }
  3092. return array;
  3093. };
  3094. }(),
  3095. applyToBuffer: function () {
  3096. var v1;
  3097. return function applyToBuffer( buffer, offset, length ) {
  3098. if ( v1 === undefined ) v1 = new THREE.Vector3();
  3099. if ( offset === undefined ) offset = 0;
  3100. if ( length === undefined ) length = buffer.length / buffer.itemSize;
  3101. for ( var i = 0, j = offset; i < length; i ++, j ++ ) {
  3102. v1.x = buffer.getX( j );
  3103. v1.y = buffer.getY( j );
  3104. v1.z = buffer.getZ( j );
  3105. v1.applyMatrix4( this );
  3106. buffer.setXYZ( v1.x, v1.y, v1.z );
  3107. }
  3108. return buffer;
  3109. };
  3110. }(),
  3111. determinant: function () {
  3112. var te = this.elements;
  3113. var n11 = te[ 0 ], n12 = te[ 4 ], n13 = te[ 8 ], n14 = te[ 12 ];
  3114. var n21 = te[ 1 ], n22 = te[ 5 ], n23 = te[ 9 ], n24 = te[ 13 ];
  3115. var n31 = te[ 2 ], n32 = te[ 6 ], n33 = te[ 10 ], n34 = te[ 14 ];
  3116. var n41 = te[ 3 ], n42 = te[ 7 ], n43 = te[ 11 ], n44 = te[ 15 ];
  3117. //TODO: make this more efficient
  3118. //( based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm )
  3119. return (
  3120. n41 * (
  3121. + n14 * n23 * n32
  3122. - n13 * n24 * n32
  3123. - n14 * n22 * n33
  3124. + n12 * n24 * n33
  3125. + n13 * n22 * n34
  3126. - n12 * n23 * n34
  3127. ) +
  3128. n42 * (
  3129. + n11 * n23 * n34
  3130. - n11 * n24 * n33
  3131. + n14 * n21 * n33
  3132. - n13 * n21 * n34
  3133. + n13 * n24 * n31
  3134. - n14 * n23 * n31
  3135. ) +
  3136. n43 * (
  3137. + n11 * n24 * n32
  3138. - n11 * n22 * n34
  3139. - n14 * n21 * n32
  3140. + n12 * n21 * n34
  3141. + n14 * n22 * n31
  3142. - n12 * n24 * n31
  3143. ) +
  3144. n44 * (
  3145. - n13 * n22 * n31
  3146. - n11 * n23 * n32
  3147. + n11 * n22 * n33
  3148. + n13 * n21 * n32
  3149. - n12 * n21 * n33
  3150. + n12 * n23 * n31
  3151. )
  3152. );
  3153. },
  3154. transpose: function () {
  3155. var te = this.elements;
  3156. var tmp;
  3157. tmp = te[ 1 ]; te[ 1 ] = te[ 4 ]; te[ 4 ] = tmp;
  3158. tmp = te[ 2 ]; te[ 2 ] = te[ 8 ]; te[ 8 ] = tmp;
  3159. tmp = te[ 6 ]; te[ 6 ] = te[ 9 ]; te[ 9 ] = tmp;
  3160. tmp = te[ 3 ]; te[ 3 ] = te[ 12 ]; te[ 12 ] = tmp;
  3161. tmp = te[ 7 ]; te[ 7 ] = te[ 13 ]; te[ 13 ] = tmp;
  3162. tmp = te[ 11 ]; te[ 11 ] = te[ 14 ]; te[ 14 ] = tmp;
  3163. return this;
  3164. },
  3165. flattenToArrayOffset: function ( array, offset ) {
  3166. console.warn( "THREE.Matrix3: .flattenToArrayOffset is deprecated " +
  3167. "- just use .toArray instead." );
  3168. return this.toArray( array, offset );
  3169. },
  3170. getPosition: function () {
  3171. var v1;
  3172. return function getPosition() {
  3173. if ( v1 === undefined ) v1 = new THREE.Vector3();
  3174. console.warn( 'THREE.Matrix4: .getPosition() has been removed. Use Vector3.setFromMatrixPosition( matrix ) instead.' );
  3175. return v1.setFromMatrixColumn( this, 3 );
  3176. };
  3177. }(),
  3178. setPosition: function ( v ) {
  3179. var te = this.elements;
  3180. te[ 12 ] = v.x;
  3181. te[ 13 ] = v.y;
  3182. te[ 14 ] = v.z;
  3183. return this;
  3184. },
  3185. getInverse: function ( m, throwOnDegenerate ) {
  3186. // based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm
  3187. var te = this.elements,
  3188. me = m.elements,
  3189. n11 = me[ 0 ], n21 = me[ 1 ], n31 = me[ 2 ], n41 = me[ 3 ],
  3190. n12 = me[ 4 ], n22 = me[ 5 ], n32 = me[ 6 ], n42 = me[ 7 ],
  3191. n13 = me[ 8 ], n23 = me[ 9 ], n33 = me[ 10 ], n43 = me[ 11 ],
  3192. n14 = me[ 12 ], n24 = me[ 13 ], n34 = me[ 14 ], n44 = me[ 15 ],
  3193. t11 = n23 * n34 * n42 - n24 * n33 * n42 + n24 * n32 * n43 - n22 * n34 * n43 - n23 * n32 * n44 + n22 * n33 * n44,
  3194. t12 = n14 * n33 * n42 - n13 * n34 * n42 - n14 * n32 * n43 + n12 * n34 * n43 + n13 * n32 * n44 - n12 * n33 * n44,
  3195. t13 = n13 * n24 * n42 - n14 * n23 * n42 + n14 * n22 * n43 - n12 * n24 * n43 - n13 * n22 * n44 + n12 * n23 * n44,
  3196. t14 = n14 * n23 * n32 - n13 * n24 * n32 - n14 * n22 * n33 + n12 * n24 * n33 + n13 * n22 * n34 - n12 * n23 * n34;
  3197. var det = n11 * t11 + n21 * t12 + n31 * t13 + n41 * t14;
  3198. if ( det === 0 ) {
  3199. var msg = "THREE.Matrix4.getInverse(): can't invert matrix, determinant is 0";
  3200. if ( throwOnDegenerate || false ) {
  3201. throw new Error( msg );
  3202. } else {
  3203. console.warn( msg );
  3204. }
  3205. return this.identity();
  3206. }
  3207. var detInv = 1 / det;
  3208. te[ 0 ] = t11 * detInv;
  3209. te[ 1 ] = ( n24 * n33 * n41 - n23 * n34 * n41 - n24 * n31 * n43 + n21 * n34 * n43 + n23 * n31 * n44 - n21 * n33 * n44 ) * detInv;
  3210. te[ 2 ] = ( n22 * n34 * n41 - n24 * n32 * n41 + n24 * n31 * n42 - n21 * n34 * n42 - n22 * n31 * n44 + n21 * n32 * n44 ) * detInv;
  3211. te[ 3 ] = ( n23 * n32 * n41 - n22 * n33 * n41 - n23 * n31 * n42 + n21 * n33 * n42 + n22 * n31 * n43 - n21 * n32 * n43 ) * detInv;
  3212. te[ 4 ] = t12 * detInv;
  3213. te[ 5 ] = ( n13 * n34 * n41 - n14 * n33 * n41 + n14 * n31 * n43 - n11 * n34 * n43 - n13 * n31 * n44 + n11 * n33 * n44 ) * detInv;
  3214. te[ 6 ] = ( n14 * n32 * n41 - n12 * n34 * n41 - n14 * n31 * n42 + n11 * n34 * n42 + n12 * n31 * n44 - n11 * n32 * n44 ) * detInv;
  3215. te[ 7 ] = ( n12 * n33 * n41 - n13 * n32 * n41 + n13 * n31 * n42 - n11 * n33 * n42 - n12 * n31 * n43 + n11 * n32 * n43 ) * detInv;
  3216. te[ 8 ] = t13 * detInv;
  3217. te[ 9 ] = ( n14 * n23 * n41 - n13 * n24 * n41 - n14 * n21 * n43 + n11 * n24 * n43 + n13 * n21 * n44 - n11 * n23 * n44 ) * detInv;
  3218. te[ 10 ] = ( n12 * n24 * n41 - n14 * n22 * n41 + n14 * n21 * n42 - n11 * n24 * n42 - n12 * n21 * n44 + n11 * n22 * n44 ) * detInv;
  3219. te[ 11 ] = ( n13 * n22 * n41 - n12 * n23 * n41 - n13 * n21 * n42 + n11 * n23 * n42 + n12 * n21 * n43 - n11 * n22 * n43 ) * detInv;
  3220. te[ 12 ] = t14 * detInv;
  3221. te[ 13 ] = ( n13 * n24 * n31 - n14 * n23 * n31 + n14 * n21 * n33 - n11 * n24 * n33 - n13 * n21 * n34 + n11 * n23 * n34 ) * detInv;
  3222. te[ 14 ] = ( n14 * n22 * n31 - n12 * n24 * n31 - n14 * n21 * n32 + n11 * n24 * n32 + n12 * n21 * n34 - n11 * n22 * n34 ) * detInv;
  3223. te[ 15 ] = ( n12 * n23 * n31 - n13 * n22 * n31 + n13 * n21 * n32 - n11 * n23 * n32 - n12 * n21 * n33 + n11 * n22 * n33 ) * detInv;
  3224. return this;
  3225. },
  3226. scale: function ( v ) {
  3227. var te = this.elements;
  3228. var x = v.x, y = v.y, z = v.z;
  3229. te[ 0 ] *= x; te[ 4 ] *= y; te[ 8 ] *= z;
  3230. te[ 1 ] *= x; te[ 5 ] *= y; te[ 9 ] *= z;
  3231. te[ 2 ] *= x; te[ 6 ] *= y; te[ 10 ] *= z;
  3232. te[ 3 ] *= x; te[ 7 ] *= y; te[ 11 ] *= z;
  3233. return this;
  3234. },
  3235. getMaxScaleOnAxis: function () {
  3236. var te = this.elements;
  3237. var scaleXSq = te[ 0 ] * te[ 0 ] + te[ 1 ] * te[ 1 ] + te[ 2 ] * te[ 2 ];
  3238. var scaleYSq = te[ 4 ] * te[ 4 ] + te[ 5 ] * te[ 5 ] + te[ 6 ] * te[ 6 ];
  3239. var scaleZSq = te[ 8 ] * te[ 8 ] + te[ 9 ] * te[ 9 ] + te[ 10 ] * te[ 10 ];
  3240. return Math.sqrt( Math.max( scaleXSq, scaleYSq, scaleZSq ) );
  3241. },
  3242. makeTranslation: function ( x, y, z ) {
  3243. this.set(
  3244. 1, 0, 0, x,
  3245. 0, 1, 0, y,
  3246. 0, 0, 1, z,
  3247. 0, 0, 0, 1
  3248. );
  3249. return this;
  3250. },
  3251. makeRotationX: function ( theta ) {
  3252. var c = Math.cos( theta ), s = Math.sin( theta );
  3253. this.set(
  3254. 1, 0, 0, 0,
  3255. 0, c, - s, 0,
  3256. 0, s, c, 0,
  3257. 0, 0, 0, 1
  3258. );
  3259. return this;
  3260. },
  3261. makeRotationY: function ( theta ) {
  3262. var c = Math.cos( theta ), s = Math.sin( theta );
  3263. this.set(
  3264. c, 0, s, 0,
  3265. 0, 1, 0, 0,
  3266. - s, 0, c, 0,
  3267. 0, 0, 0, 1
  3268. );
  3269. return this;
  3270. },
  3271. makeRotationZ: function ( theta ) {
  3272. var c = Math.cos( theta ), s = Math.sin( theta );
  3273. this.set(
  3274. c, - s, 0, 0,
  3275. s, c, 0, 0,
  3276. 0, 0, 1, 0,
  3277. 0, 0, 0, 1
  3278. );
  3279. return this;
  3280. },
  3281. makeRotationAxis: function ( axis, angle ) {
  3282. // Based on http://www.gamedev.net/reference/articles/article1199.asp
  3283. var c = Math.cos( angle );
  3284. var s = Math.sin( angle );
  3285. var t = 1 - c;
  3286. var x = axis.x, y = axis.y, z = axis.z;
  3287. var tx = t * x, ty = t * y;
  3288. this.set(
  3289. tx * x + c, tx * y - s * z, tx * z + s * y, 0,
  3290. tx * y + s * z, ty * y + c, ty * z - s * x, 0,
  3291. tx * z - s * y, ty * z + s * x, t * z * z + c, 0,
  3292. 0, 0, 0, 1
  3293. );
  3294. return this;
  3295. },
  3296. makeScale: function ( x, y, z ) {
  3297. this.set(
  3298. x, 0, 0, 0,
  3299. 0, y, 0, 0,
  3300. 0, 0, z, 0,
  3301. 0, 0, 0, 1
  3302. );
  3303. return this;
  3304. },
  3305. compose: function ( position, quaternion, scale ) {
  3306. this.makeRotationFromQuaternion( quaternion );
  3307. this.scale( scale );
  3308. this.setPosition( position );
  3309. return this;
  3310. },
  3311. decompose: function () {
  3312. var vector, matrix;
  3313. return function decompose( position, quaternion, scale ) {
  3314. if ( vector === undefined ) {
  3315. vector = new THREE.Vector3();
  3316. matrix = new THREE.Matrix4();
  3317. }
  3318. var te = this.elements;
  3319. var sx = vector.set( te[ 0 ], te[ 1 ], te[ 2 ] ).length();
  3320. var sy = vector.set( te[ 4 ], te[ 5 ], te[ 6 ] ).length();
  3321. var sz = vector.set( te[ 8 ], te[ 9 ], te[ 10 ] ).length();
  3322. // if determine is negative, we need to invert one scale
  3323. var det = this.determinant();
  3324. if ( det < 0 ) {
  3325. sx = - sx;
  3326. }
  3327. position.x = te[ 12 ];
  3328. position.y = te[ 13 ];
  3329. position.z = te[ 14 ];
  3330. // scale the rotation part
  3331. matrix.elements.set( this.elements ); // at this point matrix is incomplete so we can't use .copy()
  3332. var invSX = 1 / sx;
  3333. var invSY = 1 / sy;
  3334. var invSZ = 1 / sz;
  3335. matrix.elements[ 0 ] *= invSX;
  3336. matrix.elements[ 1 ] *= invSX;
  3337. matrix.elements[ 2 ] *= invSX;
  3338. matrix.elements[ 4 ] *= invSY;
  3339. matrix.elements[ 5 ] *= invSY;
  3340. matrix.elements[ 6 ] *= invSY;
  3341. matrix.elements[ 8 ] *= invSZ;
  3342. matrix.elements[ 9 ] *= invSZ;
  3343. matrix.elements[ 10 ] *= invSZ;
  3344. quaternion.setFromRotationMatrix( matrix );
  3345. scale.x = sx;
  3346. scale.y = sy;
  3347. scale.z = sz;
  3348. return this;
  3349. };
  3350. }(),
  3351. makeFrustum: function ( left, right, bottom, top, near, far ) {
  3352. var te = this.elements;
  3353. var x = 2 * near / ( right - left );
  3354. var y = 2 * near / ( top - bottom );
  3355. var a = ( right + left ) / ( right - left );
  3356. var b = ( top + bottom ) / ( top - bottom );
  3357. var c = - ( far + near ) / ( far - near );
  3358. var d = - 2 * far * near / ( far - near );
  3359. te[ 0 ] = x; te[ 4 ] = 0; te[ 8 ] = a; te[ 12 ] = 0;
  3360. te[ 1 ] = 0; te[ 5 ] = y; te[ 9 ] = b; te[ 13 ] = 0;
  3361. te[ 2 ] = 0; te[ 6 ] = 0; te[ 10 ] = c; te[ 14 ] = d;
  3362. te[ 3 ] = 0; te[ 7 ] = 0; te[ 11 ] = - 1; te[ 15 ] = 0;
  3363. return this;
  3364. },
  3365. makePerspective: function ( fov, aspect, near, far ) {
  3366. var ymax = near * Math.tan( THREE.Math.DEG2RAD * fov * 0.5 );
  3367. var ymin = - ymax;
  3368. var xmin = ymin * aspect;
  3369. var xmax = ymax * aspect;
  3370. return this.makeFrustum( xmin, xmax, ymin, ymax, near, far );
  3371. },
  3372. makeOrthographic: function ( left, right, top, bottom, near, far ) {
  3373. var te = this.elements;
  3374. var w = 1.0 / ( right - left );
  3375. var h = 1.0 / ( top - bottom );
  3376. var p = 1.0 / ( far - near );
  3377. var x = ( right + left ) * w;
  3378. var y = ( top + bottom ) * h;
  3379. var z = ( far + near ) * p;
  3380. te[ 0 ] = 2 * w; te[ 4 ] = 0; te[ 8 ] = 0; te[ 12 ] = - x;
  3381. te[ 1 ] = 0; te[ 5 ] = 2 * h; te[ 9 ] = 0; te[ 13 ] = - y;
  3382. te[ 2 ] = 0; te[ 6 ] = 0; te[ 10 ] = - 2 * p; te[ 14 ] = - z;
  3383. te[ 3 ] = 0; te[ 7 ] = 0; te[ 11 ] = 0; te[ 15 ] = 1;
  3384. return this;
  3385. },
  3386. equals: function ( matrix ) {
  3387. var te = this.elements;
  3388. var me = matrix.elements;
  3389. for ( var i = 0; i < 16; i ++ ) {
  3390. if ( te[ i ] !== me[ i ] ) return false;
  3391. }
  3392. return true;
  3393. },
  3394. fromArray: function ( array ) {
  3395. this.elements.set( array );
  3396. return this;
  3397. },
  3398. toArray: function ( array, offset ) {
  3399. if ( array === undefined ) array = [];
  3400. if ( offset === undefined ) offset = 0;
  3401. var te = this.elements;
  3402. array[ offset ] = te[ 0 ];
  3403. array[ offset + 1 ] = te[ 1 ];
  3404. array[ offset + 2 ] = te[ 2 ];
  3405. array[ offset + 3 ] = te[ 3 ];
  3406. array[ offset + 4 ] = te[ 4 ];
  3407. array[ offset + 5 ] = te[ 5 ];
  3408. array[ offset + 6 ] = te[ 6 ];
  3409. array[ offset + 7 ] = te[ 7 ];
  3410. array[ offset + 8 ] = te[ 8 ];
  3411. array[ offset + 9 ] = te[ 9 ];
  3412. array[ offset + 10 ] = te[ 10 ];
  3413. array[ offset + 11 ] = te[ 11 ];
  3414. array[ offset + 12 ] = te[ 12 ];
  3415. array[ offset + 13 ] = te[ 13 ];
  3416. array[ offset + 14 ] = te[ 14 ];
  3417. array[ offset + 15 ] = te[ 15 ];
  3418. return array;
  3419. }
  3420. };
  3421. // File:src/math/Ray.js
  3422. /**
  3423. * @author bhouston / http://clara.io
  3424. */
  3425. THREE.Ray = function ( origin, direction ) {
  3426. this.origin = ( origin !== undefined ) ? origin : new THREE.Vector3();
  3427. this.direction = ( direction !== undefined ) ? direction : new THREE.Vector3();
  3428. };
  3429. THREE.Ray.prototype = {
  3430. constructor: THREE.Ray,
  3431. set: function ( origin, direction ) {
  3432. this.origin.copy( origin );
  3433. this.direction.copy( direction );
  3434. return this;
  3435. },
  3436. clone: function () {
  3437. return new this.constructor().copy( this );
  3438. },
  3439. copy: function ( ray ) {
  3440. this.origin.copy( ray.origin );
  3441. this.direction.copy( ray.direction );
  3442. return this;
  3443. },
  3444. at: function ( t, optionalTarget ) {
  3445. var result = optionalTarget || new THREE.Vector3();
  3446. return result.copy( this.direction ).multiplyScalar( t ).add( this.origin );
  3447. },
  3448. lookAt: function ( v ) {
  3449. this.direction.copy( v ).sub( this.origin ).normalize();
  3450. return this;
  3451. },
  3452. recast: function () {
  3453. var v1 = new THREE.Vector3();
  3454. return function recast( t ) {
  3455. this.origin.copy( this.at( t, v1 ) );
  3456. return this;
  3457. };
  3458. }(),
  3459. closestPointToPoint: function ( point, optionalTarget ) {
  3460. var result = optionalTarget || new THREE.Vector3();
  3461. result.subVectors( point, this.origin );
  3462. var directionDistance = result.dot( this.direction );
  3463. if ( directionDistance < 0 ) {
  3464. return result.copy( this.origin );
  3465. }
  3466. return result.copy( this.direction ).multiplyScalar( directionDistance ).add( this.origin );
  3467. },
  3468. distanceToPoint: function ( point ) {
  3469. return Math.sqrt( this.distanceSqToPoint( point ) );
  3470. },
  3471. distanceSqToPoint: function () {
  3472. var v1 = new THREE.Vector3();
  3473. return function distanceSqToPoint( point ) {
  3474. var directionDistance = v1.subVectors( point, this.origin ).dot( this.direction );
  3475. // point behind the ray
  3476. if ( directionDistance < 0 ) {
  3477. return this.origin.distanceToSquared( point );
  3478. }
  3479. v1.copy( this.direction ).multiplyScalar( directionDistance ).add( this.origin );
  3480. return v1.distanceToSquared( point );
  3481. };
  3482. }(),
  3483. distanceSqToSegment: function () {
  3484. var segCenter = new THREE.Vector3();
  3485. var segDir = new THREE.Vector3();
  3486. var diff = new THREE.Vector3();
  3487. return function distanceSqToSegment( v0, v1, optionalPointOnRay, optionalPointOnSegment ) {
  3488. // from http://www.geometrictools.com/GTEngine/Include/Mathematics/GteDistRaySegment.h
  3489. // It returns the min distance between the ray and the segment
  3490. // defined by v0 and v1
  3491. // It can also set two optional targets :
  3492. // - The closest point on the ray
  3493. // - The closest point on the segment
  3494. segCenter.copy( v0 ).add( v1 ).multiplyScalar( 0.5 );
  3495. segDir.copy( v1 ).sub( v0 ).normalize();
  3496. diff.copy( this.origin ).sub( segCenter );
  3497. var segExtent = v0.distanceTo( v1 ) * 0.5;
  3498. var a01 = - this.direction.dot( segDir );
  3499. var b0 = diff.dot( this.direction );
  3500. var b1 = - diff.dot( segDir );
  3501. var c = diff.lengthSq();
  3502. var det = Math.abs( 1 - a01 * a01 );
  3503. var s0, s1, sqrDist, extDet;
  3504. if ( det > 0 ) {
  3505. // The ray and segment are not parallel.
  3506. s0 = a01 * b1 - b0;
  3507. s1 = a01 * b0 - b1;
  3508. extDet = segExtent * det;
  3509. if ( s0 >= 0 ) {
  3510. if ( s1 >= - extDet ) {
  3511. if ( s1 <= extDet ) {
  3512. // region 0
  3513. // Minimum at interior points of ray and segment.
  3514. var invDet = 1 / det;
  3515. s0 *= invDet;
  3516. s1 *= invDet;
  3517. sqrDist = s0 * ( s0 + a01 * s1 + 2 * b0 ) + s1 * ( a01 * s0 + s1 + 2 * b1 ) + c;
  3518. } else {
  3519. // region 1
  3520. s1 = segExtent;
  3521. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  3522. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3523. }
  3524. } else {
  3525. // region 5
  3526. s1 = - segExtent;
  3527. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  3528. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3529. }
  3530. } else {
  3531. if ( s1 <= - extDet ) {
  3532. // region 4
  3533. s0 = Math.max( 0, - ( - a01 * segExtent + b0 ) );
  3534. s1 = ( s0 > 0 ) ? - segExtent : Math.min( Math.max( - segExtent, - b1 ), segExtent );
  3535. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3536. } else if ( s1 <= extDet ) {
  3537. // region 3
  3538. s0 = 0;
  3539. s1 = Math.min( Math.max( - segExtent, - b1 ), segExtent );
  3540. sqrDist = s1 * ( s1 + 2 * b1 ) + c;
  3541. } else {
  3542. // region 2
  3543. s0 = Math.max( 0, - ( a01 * segExtent + b0 ) );
  3544. s1 = ( s0 > 0 ) ? segExtent : Math.min( Math.max( - segExtent, - b1 ), segExtent );
  3545. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3546. }
  3547. }
  3548. } else {
  3549. // Ray and segment are parallel.
  3550. s1 = ( a01 > 0 ) ? - segExtent : segExtent;
  3551. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  3552. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3553. }
  3554. if ( optionalPointOnRay ) {
  3555. optionalPointOnRay.copy( this.direction ).multiplyScalar( s0 ).add( this.origin );
  3556. }
  3557. if ( optionalPointOnSegment ) {
  3558. optionalPointOnSegment.copy( segDir ).multiplyScalar( s1 ).add( segCenter );
  3559. }
  3560. return sqrDist;
  3561. };
  3562. }(),
  3563. intersectSphere: function () {
  3564. var v1 = new THREE.Vector3();
  3565. return function intersectSphere( sphere, optionalTarget ) {
  3566. v1.subVectors( sphere.center, this.origin );
  3567. var tca = v1.dot( this.direction );
  3568. var d2 = v1.dot( v1 ) - tca * tca;
  3569. var radius2 = sphere.radius * sphere.radius;
  3570. if ( d2 > radius2 ) return null;
  3571. var thc = Math.sqrt( radius2 - d2 );
  3572. // t0 = first intersect point - entrance on front of sphere
  3573. var t0 = tca - thc;
  3574. // t1 = second intersect point - exit point on back of sphere
  3575. var t1 = tca + thc;
  3576. // test to see if both t0 and t1 are behind the ray - if so, return null
  3577. if ( t0 < 0 && t1 < 0 ) return null;
  3578. // test to see if t0 is behind the ray:
  3579. // if it is, the ray is inside the sphere, so return the second exit point scaled by t1,
  3580. // in order to always return an intersect point that is in front of the ray.
  3581. if ( t0 < 0 ) return this.at( t1, optionalTarget );
  3582. // else t0 is in front of the ray, so return the first collision point scaled by t0
  3583. return this.at( t0, optionalTarget );
  3584. };
  3585. }(),
  3586. intersectsSphere: function ( sphere ) {
  3587. return this.distanceToPoint( sphere.center ) <= sphere.radius;
  3588. },
  3589. distanceToPlane: function ( plane ) {
  3590. var denominator = plane.normal.dot( this.direction );
  3591. if ( denominator === 0 ) {
  3592. // line is coplanar, return origin
  3593. if ( plane.distanceToPoint( this.origin ) === 0 ) {
  3594. return 0;
  3595. }
  3596. // Null is preferable to undefined since undefined means.... it is undefined
  3597. return null;
  3598. }
  3599. var t = - ( this.origin.dot( plane.normal ) + plane.constant ) / denominator;
  3600. // Return if the ray never intersects the plane
  3601. return t >= 0 ? t : null;
  3602. },
  3603. intersectPlane: function ( plane, optionalTarget ) {
  3604. var t = this.distanceToPlane( plane );
  3605. if ( t === null ) {
  3606. return null;
  3607. }
  3608. return this.at( t, optionalTarget );
  3609. },
  3610. intersectsPlane: function ( plane ) {
  3611. // check if the ray lies on the plane first
  3612. var distToPoint = plane.distanceToPoint( this.origin );
  3613. if ( distToPoint === 0 ) {
  3614. return true;
  3615. }
  3616. var denominator = plane.normal.dot( this.direction );
  3617. if ( denominator * distToPoint < 0 ) {
  3618. return true;
  3619. }
  3620. // ray origin is behind the plane (and is pointing behind it)
  3621. return false;
  3622. },
  3623. intersectBox: function ( box, optionalTarget ) {
  3624. var tmin, tmax, tymin, tymax, tzmin, tzmax;
  3625. var invdirx = 1 / this.direction.x,
  3626. invdiry = 1 / this.direction.y,
  3627. invdirz = 1 / this.direction.z;
  3628. var origin = this.origin;
  3629. if ( invdirx >= 0 ) {
  3630. tmin = ( box.min.x - origin.x ) * invdirx;
  3631. tmax = ( box.max.x - origin.x ) * invdirx;
  3632. } else {
  3633. tmin = ( box.max.x - origin.x ) * invdirx;
  3634. tmax = ( box.min.x - origin.x ) * invdirx;
  3635. }
  3636. if ( invdiry >= 0 ) {
  3637. tymin = ( box.min.y - origin.y ) * invdiry;
  3638. tymax = ( box.max.y - origin.y ) * invdiry;
  3639. } else {
  3640. tymin = ( box.max.y - origin.y ) * invdiry;
  3641. tymax = ( box.min.y - origin.y ) * invdiry;
  3642. }
  3643. if ( ( tmin > tymax ) || ( tymin > tmax ) ) return null;
  3644. // These lines also handle the case where tmin or tmax is NaN
  3645. // (result of 0 * Infinity). x !== x returns true if x is NaN
  3646. if ( tymin > tmin || tmin !== tmin ) tmin = tymin;
  3647. if ( tymax < tmax || tmax !== tmax ) tmax = tymax;
  3648. if ( invdirz >= 0 ) {
  3649. tzmin = ( box.min.z - origin.z ) * invdirz;
  3650. tzmax = ( box.max.z - origin.z ) * invdirz;
  3651. } else {
  3652. tzmin = ( box.max.z - origin.z ) * invdirz;
  3653. tzmax = ( box.min.z - origin.z ) * invdirz;
  3654. }
  3655. if ( ( tmin > tzmax ) || ( tzmin > tmax ) ) return null;
  3656. if ( tzmin > tmin || tmin !== tmin ) tmin = tzmin;
  3657. if ( tzmax < tmax || tmax !== tmax ) tmax = tzmax;
  3658. //return point closest to the ray (positive side)
  3659. if ( tmax < 0 ) return null;
  3660. return this.at( tmin >= 0 ? tmin : tmax, optionalTarget );
  3661. },
  3662. intersectsBox: ( function () {
  3663. var v = new THREE.Vector3();
  3664. return function intersectsBox( box ) {
  3665. return this.intersectBox( box, v ) !== null;
  3666. };
  3667. } )(),
  3668. intersectTriangle: function () {
  3669. // Compute the offset origin, edges, and normal.
  3670. var diff = new THREE.Vector3();
  3671. var edge1 = new THREE.Vector3();
  3672. var edge2 = new THREE.Vector3();
  3673. var normal = new THREE.Vector3();
  3674. return function intersectTriangle( a, b, c, backfaceCulling, optionalTarget ) {
  3675. // from http://www.geometrictools.com/GTEngine/Include/Mathematics/GteIntrRay3Triangle3.h
  3676. edge1.subVectors( b, a );
  3677. edge2.subVectors( c, a );
  3678. normal.crossVectors( edge1, edge2 );
  3679. // Solve Q + t*D = b1*E1 + b2*E2 (Q = kDiff, D = ray direction,
  3680. // E1 = kEdge1, E2 = kEdge2, N = Cross(E1,E2)) by
  3681. // |Dot(D,N)|*b1 = sign(Dot(D,N))*Dot(D,Cross(Q,E2))
  3682. // |Dot(D,N)|*b2 = sign(Dot(D,N))*Dot(D,Cross(E1,Q))
  3683. // |Dot(D,N)|*t = -sign(Dot(D,N))*Dot(Q,N)
  3684. var DdN = this.direction.dot( normal );
  3685. var sign;
  3686. if ( DdN > 0 ) {
  3687. if ( backfaceCulling ) return null;
  3688. sign = 1;
  3689. } else if ( DdN < 0 ) {
  3690. sign = - 1;
  3691. DdN = - DdN;
  3692. } else {
  3693. return null;
  3694. }
  3695. diff.subVectors( this.origin, a );
  3696. var DdQxE2 = sign * this.direction.dot( edge2.crossVectors( diff, edge2 ) );
  3697. // b1 < 0, no intersection
  3698. if ( DdQxE2 < 0 ) {
  3699. return null;
  3700. }
  3701. var DdE1xQ = sign * this.direction.dot( edge1.cross( diff ) );
  3702. // b2 < 0, no intersection
  3703. if ( DdE1xQ < 0 ) {
  3704. return null;
  3705. }
  3706. // b1+b2 > 1, no intersection
  3707. if ( DdQxE2 + DdE1xQ > DdN ) {
  3708. return null;
  3709. }
  3710. // Line intersects triangle, check if ray does.
  3711. var QdN = - sign * diff.dot( normal );
  3712. // t < 0, no intersection
  3713. if ( QdN < 0 ) {
  3714. return null;
  3715. }
  3716. // Ray intersects triangle.
  3717. return this.at( QdN / DdN, optionalTarget );
  3718. };
  3719. }(),
  3720. applyMatrix4: function ( matrix4 ) {
  3721. this.direction.add( this.origin ).applyMatrix4( matrix4 );
  3722. this.origin.applyMatrix4( matrix4 );
  3723. this.direction.sub( this.origin );
  3724. this.direction.normalize();
  3725. return this;
  3726. },
  3727. equals: function ( ray ) {
  3728. return ray.origin.equals( this.origin ) && ray.direction.equals( this.direction );
  3729. }
  3730. };
  3731. // File:src/math/Sphere.js
  3732. /**
  3733. * @author bhouston / http://clara.io
  3734. * @author mrdoob / http://mrdoob.com/
  3735. */
  3736. THREE.Sphere = function ( center, radius ) {
  3737. this.center = ( center !== undefined ) ? center : new THREE.Vector3();
  3738. this.radius = ( radius !== undefined ) ? radius : 0;
  3739. };
  3740. THREE.Sphere.prototype = {
  3741. constructor: THREE.Sphere,
  3742. set: function ( center, radius ) {
  3743. this.center.copy( center );
  3744. this.radius = radius;
  3745. return this;
  3746. },
  3747. setFromPoints: function () {
  3748. var box = new THREE.Box3();
  3749. return function setFromPoints( points, optionalCenter ) {
  3750. var center = this.center;
  3751. if ( optionalCenter !== undefined ) {
  3752. center.copy( optionalCenter );
  3753. } else {
  3754. box.setFromPoints( points ).center( center );
  3755. }
  3756. var maxRadiusSq = 0;
  3757. for ( var i = 0, il = points.length; i < il; i ++ ) {
  3758. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( points[ i ] ) );
  3759. }
  3760. this.radius = Math.sqrt( maxRadiusSq );
  3761. return this;
  3762. };
  3763. }(),
  3764. clone: function () {
  3765. return new this.constructor().copy( this );
  3766. },
  3767. copy: function ( sphere ) {
  3768. this.center.copy( sphere.center );
  3769. this.radius = sphere.radius;
  3770. return this;
  3771. },
  3772. empty: function () {
  3773. return ( this.radius <= 0 );
  3774. },
  3775. containsPoint: function ( point ) {
  3776. return ( point.distanceToSquared( this.center ) <= ( this.radius * this.radius ) );
  3777. },
  3778. distanceToPoint: function ( point ) {
  3779. return ( point.distanceTo( this.center ) - this.radius );
  3780. },
  3781. intersectsSphere: function ( sphere ) {
  3782. var radiusSum = this.radius + sphere.radius;
  3783. return sphere.center.distanceToSquared( this.center ) <= ( radiusSum * radiusSum );
  3784. },
  3785. intersectsBox: function ( box ) {
  3786. return box.intersectsSphere( this );
  3787. },
  3788. intersectsPlane: function ( plane ) {
  3789. // We use the following equation to compute the signed distance from
  3790. // the center of the sphere to the plane.
  3791. //
  3792. // distance = q * n - d
  3793. //
  3794. // If this distance is greater than the radius of the sphere,
  3795. // then there is no intersection.
  3796. return Math.abs( this.center.dot( plane.normal ) - plane.constant ) <= this.radius;
  3797. },
  3798. clampPoint: function ( point, optionalTarget ) {
  3799. var deltaLengthSq = this.center.distanceToSquared( point );
  3800. var result = optionalTarget || new THREE.Vector3();
  3801. result.copy( point );
  3802. if ( deltaLengthSq > ( this.radius * this.radius ) ) {
  3803. result.sub( this.center ).normalize();
  3804. result.multiplyScalar( this.radius ).add( this.center );
  3805. }
  3806. return result;
  3807. },
  3808. getBoundingBox: function ( optionalTarget ) {
  3809. var box = optionalTarget || new THREE.Box3();
  3810. box.set( this.center, this.center );
  3811. box.expandByScalar( this.radius );
  3812. return box;
  3813. },
  3814. applyMatrix4: function ( matrix ) {
  3815. this.center.applyMatrix4( matrix );
  3816. this.radius = this.radius * matrix.getMaxScaleOnAxis();
  3817. return this;
  3818. },
  3819. translate: function ( offset ) {
  3820. this.center.add( offset );
  3821. return this;
  3822. },
  3823. equals: function ( sphere ) {
  3824. return sphere.center.equals( this.center ) && ( sphere.radius === this.radius );
  3825. }
  3826. };
  3827. // File:src/math/Frustum.js
  3828. /**
  3829. * @author mrdoob / http://mrdoob.com/
  3830. * @author alteredq / http://alteredqualia.com/
  3831. * @author bhouston / http://clara.io
  3832. */
  3833. THREE.Frustum = function ( p0, p1, p2, p3, p4, p5 ) {
  3834. this.planes = [
  3835. ( p0 !== undefined ) ? p0 : new THREE.Plane(),
  3836. ( p1 !== undefined ) ? p1 : new THREE.Plane(),
  3837. ( p2 !== undefined ) ? p2 : new THREE.Plane(),
  3838. ( p3 !== undefined ) ? p3 : new THREE.Plane(),
  3839. ( p4 !== undefined ) ? p4 : new THREE.Plane(),
  3840. ( p5 !== undefined ) ? p5 : new THREE.Plane()
  3841. ];
  3842. };
  3843. THREE.Frustum.prototype = {
  3844. constructor: THREE.Frustum,
  3845. set: function ( p0, p1, p2, p3, p4, p5 ) {
  3846. var planes = this.planes;
  3847. planes[ 0 ].copy( p0 );
  3848. planes[ 1 ].copy( p1 );
  3849. planes[ 2 ].copy( p2 );
  3850. planes[ 3 ].copy( p3 );
  3851. planes[ 4 ].copy( p4 );
  3852. planes[ 5 ].copy( p5 );
  3853. return this;
  3854. },
  3855. clone: function () {
  3856. return new this.constructor().copy( this );
  3857. },
  3858. copy: function ( frustum ) {
  3859. var planes = this.planes;
  3860. for ( var i = 0; i < 6; i ++ ) {
  3861. planes[ i ].copy( frustum.planes[ i ] );
  3862. }
  3863. return this;
  3864. },
  3865. setFromMatrix: function ( m ) {
  3866. var planes = this.planes;
  3867. var me = m.elements;
  3868. var me0 = me[ 0 ], me1 = me[ 1 ], me2 = me[ 2 ], me3 = me[ 3 ];
  3869. var me4 = me[ 4 ], me5 = me[ 5 ], me6 = me[ 6 ], me7 = me[ 7 ];
  3870. var me8 = me[ 8 ], me9 = me[ 9 ], me10 = me[ 10 ], me11 = me[ 11 ];
  3871. var me12 = me[ 12 ], me13 = me[ 13 ], me14 = me[ 14 ], me15 = me[ 15 ];
  3872. planes[ 0 ].setComponents( me3 - me0, me7 - me4, me11 - me8, me15 - me12 ).normalize();
  3873. planes[ 1 ].setComponents( me3 + me0, me7 + me4, me11 + me8, me15 + me12 ).normalize();
  3874. planes[ 2 ].setComponents( me3 + me1, me7 + me5, me11 + me9, me15 + me13 ).normalize();
  3875. planes[ 3 ].setComponents( me3 - me1, me7 - me5, me11 - me9, me15 - me13 ).normalize();
  3876. planes[ 4 ].setComponents( me3 - me2, me7 - me6, me11 - me10, me15 - me14 ).normalize();
  3877. planes[ 5 ].setComponents( me3 + me2, me7 + me6, me11 + me10, me15 + me14 ).normalize();
  3878. return this;
  3879. },
  3880. intersectsObject: function () {
  3881. var sphere = new THREE.Sphere();
  3882. return function intersectsObject( object ) {
  3883. var geometry = object.geometry;
  3884. if ( geometry.boundingSphere === null )
  3885. geometry.computeBoundingSphere();
  3886. sphere.copy( geometry.boundingSphere )
  3887. .applyMatrix4( object.matrixWorld );
  3888. return this.intersectsSphere( sphere );
  3889. };
  3890. }(),
  3891. intersectsSprite: function () {
  3892. var sphere = new THREE.Sphere();
  3893. return function intersectsSprite( sprite ) {
  3894. sphere.center.set( 0, 0, 0 );
  3895. sphere.radius = 0.7071067811865476;
  3896. sphere.applyMatrix4( sprite.matrixWorld );
  3897. return this.intersectsSphere( sphere );
  3898. };
  3899. }(),
  3900. intersectsSphere: function ( sphere ) {
  3901. var planes = this.planes;
  3902. var center = sphere.center;
  3903. var negRadius = - sphere.radius;
  3904. for ( var i = 0; i < 6; i ++ ) {
  3905. var distance = planes[ i ].distanceToPoint( center );
  3906. if ( distance < negRadius ) {
  3907. return false;
  3908. }
  3909. }
  3910. return true;
  3911. },
  3912. intersectsBox: function () {
  3913. var p1 = new THREE.Vector3(),
  3914. p2 = new THREE.Vector3();
  3915. return function intersectsBox( box ) {
  3916. var planes = this.planes;
  3917. for ( var i = 0; i < 6 ; i ++ ) {
  3918. var plane = planes[ i ];
  3919. p1.x = plane.normal.x > 0 ? box.min.x : box.max.x;
  3920. p2.x = plane.normal.x > 0 ? box.max.x : box.min.x;
  3921. p1.y = plane.normal.y > 0 ? box.min.y : box.max.y;
  3922. p2.y = plane.normal.y > 0 ? box.max.y : box.min.y;
  3923. p1.z = plane.normal.z > 0 ? box.min.z : box.max.z;
  3924. p2.z = plane.normal.z > 0 ? box.max.z : box.min.z;
  3925. var d1 = plane.distanceToPoint( p1 );
  3926. var d2 = plane.distanceToPoint( p2 );
  3927. // if both outside plane, no intersection
  3928. if ( d1 < 0 && d2 < 0 ) {
  3929. return false;
  3930. }
  3931. }
  3932. return true;
  3933. };
  3934. }(),
  3935. containsPoint: function ( point ) {
  3936. var planes = this.planes;
  3937. for ( var i = 0; i < 6; i ++ ) {
  3938. if ( planes[ i ].distanceToPoint( point ) < 0 ) {
  3939. return false;
  3940. }
  3941. }
  3942. return true;
  3943. }
  3944. };
  3945. // File:src/math/Plane.js
  3946. /**
  3947. * @author bhouston / http://clara.io
  3948. */
  3949. THREE.Plane = function ( normal, constant ) {
  3950. this.normal = ( normal !== undefined ) ? normal : new THREE.Vector3( 1, 0, 0 );
  3951. this.constant = ( constant !== undefined ) ? constant : 0;
  3952. };
  3953. THREE.Plane.prototype = {
  3954. constructor: THREE.Plane,
  3955. set: function ( normal, constant ) {
  3956. this.normal.copy( normal );
  3957. this.constant = constant;
  3958. return this;
  3959. },
  3960. setComponents: function ( x, y, z, w ) {
  3961. this.normal.set( x, y, z );
  3962. this.constant = w;
  3963. return this;
  3964. },
  3965. setFromNormalAndCoplanarPoint: function ( normal, point ) {
  3966. this.normal.copy( normal );
  3967. this.constant = - point.dot( this.normal ); // must be this.normal, not normal, as this.normal is normalized
  3968. return this;
  3969. },
  3970. setFromCoplanarPoints: function () {
  3971. var v1 = new THREE.Vector3();
  3972. var v2 = new THREE.Vector3();
  3973. return function setFromCoplanarPoints( a, b, c ) {
  3974. var normal = v1.subVectors( c, b ).cross( v2.subVectors( a, b ) ).normalize();
  3975. // Q: should an error be thrown if normal is zero (e.g. degenerate plane)?
  3976. this.setFromNormalAndCoplanarPoint( normal, a );
  3977. return this;
  3978. };
  3979. }(),
  3980. clone: function () {
  3981. return new this.constructor().copy( this );
  3982. },
  3983. copy: function ( plane ) {
  3984. this.normal.copy( plane.normal );
  3985. this.constant = plane.constant;
  3986. return this;
  3987. },
  3988. normalize: function () {
  3989. // Note: will lead to a divide by zero if the plane is invalid.
  3990. var inverseNormalLength = 1.0 / this.normal.length();
  3991. this.normal.multiplyScalar( inverseNormalLength );
  3992. this.constant *= inverseNormalLength;
  3993. return this;
  3994. },
  3995. negate: function () {
  3996. this.constant *= - 1;
  3997. this.normal.negate();
  3998. return this;
  3999. },
  4000. distanceToPoint: function ( point ) {
  4001. return this.normal.dot( point ) + this.constant;
  4002. },
  4003. distanceToSphere: function ( sphere ) {
  4004. return this.distanceToPoint( sphere.center ) - sphere.radius;
  4005. },
  4006. projectPoint: function ( point, optionalTarget ) {
  4007. return this.orthoPoint( point, optionalTarget ).sub( point ).negate();
  4008. },
  4009. orthoPoint: function ( point, optionalTarget ) {
  4010. var perpendicularMagnitude = this.distanceToPoint( point );
  4011. var result = optionalTarget || new THREE.Vector3();
  4012. return result.copy( this.normal ).multiplyScalar( perpendicularMagnitude );
  4013. },
  4014. intersectLine: function () {
  4015. var v1 = new THREE.Vector3();
  4016. return function intersectLine( line, optionalTarget ) {
  4017. var result = optionalTarget || new THREE.Vector3();
  4018. var direction = line.delta( v1 );
  4019. var denominator = this.normal.dot( direction );
  4020. if ( denominator === 0 ) {
  4021. // line is coplanar, return origin
  4022. if ( this.distanceToPoint( line.start ) === 0 ) {
  4023. return result.copy( line.start );
  4024. }
  4025. // Unsure if this is the correct method to handle this case.
  4026. return undefined;
  4027. }
  4028. var t = - ( line.start.dot( this.normal ) + this.constant ) / denominator;
  4029. if ( t < 0 || t > 1 ) {
  4030. return undefined;
  4031. }
  4032. return result.copy( direction ).multiplyScalar( t ).add( line.start );
  4033. };
  4034. }(),
  4035. intersectsLine: function ( line ) {
  4036. // Note: this tests if a line intersects the plane, not whether it (or its end-points) are coplanar with it.
  4037. var startSign = this.distanceToPoint( line.start );
  4038. var endSign = this.distanceToPoint( line.end );
  4039. return ( startSign < 0 && endSign > 0 ) || ( endSign < 0 && startSign > 0 );
  4040. },
  4041. intersectsBox: function ( box ) {
  4042. return box.intersectsPlane( this );
  4043. },
  4044. intersectsSphere: function ( sphere ) {
  4045. return sphere.intersectsPlane( this );
  4046. },
  4047. coplanarPoint: function ( optionalTarget ) {
  4048. var result = optionalTarget || new THREE.Vector3();
  4049. return result.copy( this.normal ).multiplyScalar( - this.constant );
  4050. },
  4051. applyMatrix4: function () {
  4052. var v1 = new THREE.Vector3();
  4053. var m1 = new THREE.Matrix3();
  4054. return function applyMatrix4( matrix, optionalNormalMatrix ) {
  4055. var referencePoint = this.coplanarPoint( v1 ).applyMatrix4( matrix );
  4056. // transform normal based on theory here:
  4057. // http://www.songho.ca/opengl/gl_normaltransform.html
  4058. var normalMatrix = optionalNormalMatrix || m1.getNormalMatrix( matrix );
  4059. var normal = this.normal.applyMatrix3( normalMatrix ).normalize();
  4060. // recalculate constant (like in setFromNormalAndCoplanarPoint)
  4061. this.constant = - referencePoint.dot( normal );
  4062. return this;
  4063. };
  4064. }(),
  4065. translate: function ( offset ) {
  4066. this.constant = this.constant - offset.dot( this.normal );
  4067. return this;
  4068. },
  4069. equals: function ( plane ) {
  4070. return plane.normal.equals( this.normal ) && ( plane.constant === this.constant );
  4071. }
  4072. };
  4073. // File:src/math/Spherical.js
  4074. /**
  4075. * @author bhouston / http://clara.io
  4076. * @author WestLangley / http://github.com/WestLangley
  4077. *
  4078. * Ref: https://en.wikipedia.org/wiki/Spherical_coordinate_system
  4079. *
  4080. * The poles (phi) are at the positive and negative y axis.
  4081. * The equator starts at positive z.
  4082. */
  4083. THREE.Spherical = function ( radius, phi, theta ) {
  4084. this.radius = ( radius !== undefined ) ? radius : 1.0;
  4085. this.phi = ( phi !== undefined ) ? phi : 0; // up / down towards top and bottom pole
  4086. this.theta = ( theta !== undefined ) ? theta : 0; // around the equator of the sphere
  4087. return this;
  4088. };
  4089. THREE.Spherical.prototype = {
  4090. constructor: THREE.Spherical,
  4091. set: function ( radius, phi, theta ) {
  4092. this.radius = radius;
  4093. this.phi = phi;
  4094. this.theta = theta;
  4095. return this;
  4096. },
  4097. clone: function () {
  4098. return new this.constructor().copy( this );
  4099. },
  4100. copy: function ( other ) {
  4101. this.radius.copy( other.radius );
  4102. this.phi.copy( other.phi );
  4103. this.theta.copy( other.theta );
  4104. return this;
  4105. },
  4106. // restrict phi to be betwee EPS and PI-EPS
  4107. makeSafe: function() {
  4108. var EPS = 0.000001;
  4109. this.phi = Math.max( EPS, Math.min( Math.PI - EPS, this.phi ) );
  4110. return this;
  4111. },
  4112. setFromVector3: function( vec3 ) {
  4113. this.radius = vec3.length();
  4114. if ( this.radius === 0 ) {
  4115. this.theta = 0;
  4116. this.phi = 0;
  4117. } else {
  4118. this.theta = Math.atan2( vec3.x, vec3.z ); // equator angle around y-up axis
  4119. this.phi = Math.acos( THREE.Math.clamp( vec3.y / this.radius, - 1, 1 ) ); // polar angle
  4120. }
  4121. return this;
  4122. },
  4123. };
  4124. // File:src/math/Math.js
  4125. /**
  4126. * @author alteredq / http://alteredqualia.com/
  4127. * @author mrdoob / http://mrdoob.com/
  4128. */
  4129. THREE.Math = {
  4130. DEG2RAD: Math.PI / 180,
  4131. RAD2DEG: 180 / Math.PI,
  4132. generateUUID: function () {
  4133. // http://www.broofa.com/Tools/Math.uuid.htm
  4134. var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split( '' );
  4135. var uuid = new Array( 36 );
  4136. var rnd = 0, r;
  4137. return function generateUUID() {
  4138. for ( var i = 0; i < 36; i ++ ) {
  4139. if ( i === 8 || i === 13 || i === 18 || i === 23 ) {
  4140. uuid[ i ] = '-';
  4141. } else if ( i === 14 ) {
  4142. uuid[ i ] = '4';
  4143. } else {
  4144. if ( rnd <= 0x02 ) rnd = 0x2000000 + ( Math.random() * 0x1000000 ) | 0;
  4145. r = rnd & 0xf;
  4146. rnd = rnd >> 4;
  4147. uuid[ i ] = chars[ ( i === 19 ) ? ( r & 0x3 ) | 0x8 : r ];
  4148. }
  4149. }
  4150. return uuid.join( '' );
  4151. };
  4152. }(),
  4153. clamp: function ( value, min, max ) {
  4154. return Math.max( min, Math.min( max, value ) );
  4155. },
  4156. // compute euclidian modulo of m % n
  4157. // https://en.wikipedia.org/wiki/Modulo_operation
  4158. euclideanModulo: function ( n, m ) {
  4159. return ( ( n % m ) + m ) % m;
  4160. },
  4161. // Linear mapping from range <a1, a2> to range <b1, b2>
  4162. mapLinear: function ( x, a1, a2, b1, b2 ) {
  4163. return b1 + ( x - a1 ) * ( b2 - b1 ) / ( a2 - a1 );
  4164. },
  4165. // http://en.wikipedia.org/wiki/Smoothstep
  4166. smoothstep: function ( x, min, max ) {
  4167. if ( x <= min ) return 0;
  4168. if ( x >= max ) return 1;
  4169. x = ( x - min ) / ( max - min );
  4170. return x * x * ( 3 - 2 * x );
  4171. },
  4172. smootherstep: function ( x, min, max ) {
  4173. if ( x <= min ) return 0;
  4174. if ( x >= max ) return 1;
  4175. x = ( x - min ) / ( max - min );
  4176. return x * x * x * ( x * ( x * 6 - 15 ) + 10 );
  4177. },
  4178. random16: function () {
  4179. console.warn( 'THREE.Math.random16() has been deprecated. Use Math.random() instead.' );
  4180. return Math.random();
  4181. },
  4182. // Random integer from <low, high> interval
  4183. randInt: function ( low, high ) {
  4184. return low + Math.floor( Math.random() * ( high - low + 1 ) );
  4185. },
  4186. // Random float from <low, high> interval
  4187. randFloat: function ( low, high ) {
  4188. return low + Math.random() * ( high - low );
  4189. },
  4190. // Random float from <-range/2, range/2> interval
  4191. randFloatSpread: function ( range ) {
  4192. return range * ( 0.5 - Math.random() );
  4193. },
  4194. degToRad: function ( degrees ) {
  4195. return degrees * THREE.Math.DEG2RAD;
  4196. },
  4197. radToDeg: function ( radians ) {
  4198. return radians * THREE.Math.RAD2DEG;
  4199. },
  4200. isPowerOfTwo: function ( value ) {
  4201. return ( value & ( value - 1 ) ) === 0 && value !== 0;
  4202. },
  4203. nearestPowerOfTwo: function ( value ) {
  4204. return Math.pow( 2, Math.round( Math.log( value ) / Math.LN2 ) );
  4205. },
  4206. nextPowerOfTwo: function ( value ) {
  4207. value --;
  4208. value |= value >> 1;
  4209. value |= value >> 2;
  4210. value |= value >> 4;
  4211. value |= value >> 8;
  4212. value |= value >> 16;
  4213. value ++;
  4214. return value;
  4215. }
  4216. };
  4217. // File:src/math/Spline.js
  4218. /**
  4219. * Spline from Tween.js, slightly optimized (and trashed)
  4220. * http://sole.github.com/tween.js/examples/05_spline.html
  4221. *
  4222. * @author mrdoob / http://mrdoob.com/
  4223. * @author alteredq / http://alteredqualia.com/
  4224. */
  4225. THREE.Spline = function ( points ) {
  4226. this.points = points;
  4227. var c = [], v3 = { x: 0, y: 0, z: 0 },
  4228. point, intPoint, weight, w2, w3,
  4229. pa, pb, pc, pd;
  4230. this.initFromArray = function ( a ) {
  4231. this.points = [];
  4232. for ( var i = 0; i < a.length; i ++ ) {
  4233. this.points[ i ] = { x: a[ i ][ 0 ], y: a[ i ][ 1 ], z: a[ i ][ 2 ] };
  4234. }
  4235. };
  4236. this.getPoint = function ( k ) {
  4237. point = ( this.points.length - 1 ) * k;
  4238. intPoint = Math.floor( point );
  4239. weight = point - intPoint;
  4240. c[ 0 ] = intPoint === 0 ? intPoint : intPoint - 1;
  4241. c[ 1 ] = intPoint;
  4242. c[ 2 ] = intPoint > this.points.length - 2 ? this.points.length - 1 : intPoint + 1;
  4243. c[ 3 ] = intPoint > this.points.length - 3 ? this.points.length - 1 : intPoint + 2;
  4244. pa = this.points[ c[ 0 ] ];
  4245. pb = this.points[ c[ 1 ] ];
  4246. pc = this.points[ c[ 2 ] ];
  4247. pd = this.points[ c[ 3 ] ];
  4248. w2 = weight * weight;
  4249. w3 = weight * w2;
  4250. v3.x = interpolate( pa.x, pb.x, pc.x, pd.x, weight, w2, w3 );
  4251. v3.y = interpolate( pa.y, pb.y, pc.y, pd.y, weight, w2, w3 );
  4252. v3.z = interpolate( pa.z, pb.z, pc.z, pd.z, weight, w2, w3 );
  4253. return v3;
  4254. };
  4255. this.getControlPointsArray = function () {
  4256. var i, p, l = this.points.length,
  4257. coords = [];
  4258. for ( i = 0; i < l; i ++ ) {
  4259. p = this.points[ i ];
  4260. coords[ i ] = [ p.x, p.y, p.z ];
  4261. }
  4262. return coords;
  4263. };
  4264. // approximate length by summing linear segments
  4265. this.getLength = function ( nSubDivisions ) {
  4266. var i, index, nSamples, position,
  4267. point = 0, intPoint = 0, oldIntPoint = 0,
  4268. oldPosition = new THREE.Vector3(),
  4269. tmpVec = new THREE.Vector3(),
  4270. chunkLengths = [],
  4271. totalLength = 0;
  4272. // first point has 0 length
  4273. chunkLengths[ 0 ] = 0;
  4274. if ( ! nSubDivisions ) nSubDivisions = 100;
  4275. nSamples = this.points.length * nSubDivisions;
  4276. oldPosition.copy( this.points[ 0 ] );
  4277. for ( i = 1; i < nSamples; i ++ ) {
  4278. index = i / nSamples;
  4279. position = this.getPoint( index );
  4280. tmpVec.copy( position );
  4281. totalLength += tmpVec.distanceTo( oldPosition );
  4282. oldPosition.copy( position );
  4283. point = ( this.points.length - 1 ) * index;
  4284. intPoint = Math.floor( point );
  4285. if ( intPoint !== oldIntPoint ) {
  4286. chunkLengths[ intPoint ] = totalLength;
  4287. oldIntPoint = intPoint;
  4288. }
  4289. }
  4290. // last point ends with total length
  4291. chunkLengths[ chunkLengths.length ] = totalLength;
  4292. return { chunks: chunkLengths, total: totalLength };
  4293. };
  4294. this.reparametrizeByArcLength = function ( samplingCoef ) {
  4295. var i, j,
  4296. index, indexCurrent, indexNext,
  4297. realDistance,
  4298. sampling, position,
  4299. newpoints = [],
  4300. tmpVec = new THREE.Vector3(),
  4301. sl = this.getLength();
  4302. newpoints.push( tmpVec.copy( this.points[ 0 ] ).clone() );
  4303. for ( i = 1; i < this.points.length; i ++ ) {
  4304. //tmpVec.copy( this.points[ i - 1 ] );
  4305. //linearDistance = tmpVec.distanceTo( this.points[ i ] );
  4306. realDistance = sl.chunks[ i ] - sl.chunks[ i - 1 ];
  4307. sampling = Math.ceil( samplingCoef * realDistance / sl.total );
  4308. indexCurrent = ( i - 1 ) / ( this.points.length - 1 );
  4309. indexNext = i / ( this.points.length - 1 );
  4310. for ( j = 1; j < sampling - 1; j ++ ) {
  4311. index = indexCurrent + j * ( 1 / sampling ) * ( indexNext - indexCurrent );
  4312. position = this.getPoint( index );
  4313. newpoints.push( tmpVec.copy( position ).clone() );
  4314. }
  4315. newpoints.push( tmpVec.copy( this.points[ i ] ).clone() );
  4316. }
  4317. this.points = newpoints;
  4318. };
  4319. // Catmull-Rom
  4320. function interpolate( p0, p1, p2, p3, t, t2, t3 ) {
  4321. var v0 = ( p2 - p0 ) * 0.5,
  4322. v1 = ( p3 - p1 ) * 0.5;
  4323. return ( 2 * ( p1 - p2 ) + v0 + v1 ) * t3 + ( - 3 * ( p1 - p2 ) - 2 * v0 - v1 ) * t2 + v0 * t + p1;
  4324. }
  4325. };
  4326. // File:src/math/Triangle.js
  4327. /**
  4328. * @author bhouston / http://clara.io
  4329. * @author mrdoob / http://mrdoob.com/
  4330. */
  4331. THREE.Triangle = function ( a, b, c ) {
  4332. this.a = ( a !== undefined ) ? a : new THREE.Vector3();
  4333. this.b = ( b !== undefined ) ? b : new THREE.Vector3();
  4334. this.c = ( c !== undefined ) ? c : new THREE.Vector3();
  4335. };
  4336. THREE.Triangle.normal = function () {
  4337. var v0 = new THREE.Vector3();
  4338. return function normal( a, b, c, optionalTarget ) {
  4339. var result = optionalTarget || new THREE.Vector3();
  4340. result.subVectors( c, b );
  4341. v0.subVectors( a, b );
  4342. result.cross( v0 );
  4343. var resultLengthSq = result.lengthSq();
  4344. if ( resultLengthSq > 0 ) {
  4345. return result.multiplyScalar( 1 / Math.sqrt( resultLengthSq ) );
  4346. }
  4347. return result.set( 0, 0, 0 );
  4348. };
  4349. }();
  4350. // static/instance method to calculate barycentric coordinates
  4351. // based on: http://www.blackpawn.com/texts/pointinpoly/default.html
  4352. THREE.Triangle.barycoordFromPoint = function () {
  4353. var v0 = new THREE.Vector3();
  4354. var v1 = new THREE.Vector3();
  4355. var v2 = new THREE.Vector3();
  4356. return function barycoordFromPoint( point, a, b, c, optionalTarget ) {
  4357. v0.subVectors( c, a );
  4358. v1.subVectors( b, a );
  4359. v2.subVectors( point, a );
  4360. var dot00 = v0.dot( v0 );
  4361. var dot01 = v0.dot( v1 );
  4362. var dot02 = v0.dot( v2 );
  4363. var dot11 = v1.dot( v1 );
  4364. var dot12 = v1.dot( v2 );
  4365. var denom = ( dot00 * dot11 - dot01 * dot01 );
  4366. var result = optionalTarget || new THREE.Vector3();
  4367. // collinear or singular triangle
  4368. if ( denom === 0 ) {
  4369. // arbitrary location outside of triangle?
  4370. // not sure if this is the best idea, maybe should be returning undefined
  4371. return result.set( - 2, - 1, - 1 );
  4372. }
  4373. var invDenom = 1 / denom;
  4374. var u = ( dot11 * dot02 - dot01 * dot12 ) * invDenom;
  4375. var v = ( dot00 * dot12 - dot01 * dot02 ) * invDenom;
  4376. // barycentric coordinates must always sum to 1
  4377. return result.set( 1 - u - v, v, u );
  4378. };
  4379. }();
  4380. THREE.Triangle.containsPoint = function () {
  4381. var v1 = new THREE.Vector3();
  4382. return function containsPoint( point, a, b, c ) {
  4383. var result = THREE.Triangle.barycoordFromPoint( point, a, b, c, v1 );
  4384. return ( result.x >= 0 ) && ( result.y >= 0 ) && ( ( result.x + result.y ) <= 1 );
  4385. };
  4386. }();
  4387. THREE.Triangle.prototype = {
  4388. constructor: THREE.Triangle,
  4389. set: function ( a, b, c ) {
  4390. this.a.copy( a );
  4391. this.b.copy( b );
  4392. this.c.copy( c );
  4393. return this;
  4394. },
  4395. setFromPointsAndIndices: function ( points, i0, i1, i2 ) {
  4396. this.a.copy( points[ i0 ] );
  4397. this.b.copy( points[ i1 ] );
  4398. this.c.copy( points[ i2 ] );
  4399. return this;
  4400. },
  4401. clone: function () {
  4402. return new this.constructor().copy( this );
  4403. },
  4404. copy: function ( triangle ) {
  4405. this.a.copy( triangle.a );
  4406. this.b.copy( triangle.b );
  4407. this.c.copy( triangle.c );
  4408. return this;
  4409. },
  4410. area: function () {
  4411. var v0 = new THREE.Vector3();
  4412. var v1 = new THREE.Vector3();
  4413. return function area() {
  4414. v0.subVectors( this.c, this.b );
  4415. v1.subVectors( this.a, this.b );
  4416. return v0.cross( v1 ).length() * 0.5;
  4417. };
  4418. }(),
  4419. midpoint: function ( optionalTarget ) {
  4420. var result = optionalTarget || new THREE.Vector3();
  4421. return result.addVectors( this.a, this.b ).add( this.c ).multiplyScalar( 1 / 3 );
  4422. },
  4423. normal: function ( optionalTarget ) {
  4424. return THREE.Triangle.normal( this.a, this.b, this.c, optionalTarget );
  4425. },
  4426. plane: function ( optionalTarget ) {
  4427. var result = optionalTarget || new THREE.Plane();
  4428. return result.setFromCoplanarPoints( this.a, this.b, this.c );
  4429. },
  4430. barycoordFromPoint: function ( point, optionalTarget ) {
  4431. return THREE.Triangle.barycoordFromPoint( point, this.a, this.b, this.c, optionalTarget );
  4432. },
  4433. containsPoint: function ( point ) {
  4434. return THREE.Triangle.containsPoint( point, this.a, this.b, this.c );
  4435. },
  4436. closestPointToPoint: function () {
  4437. var plane, edgeList, projectedPoint, closestPoint;
  4438. return function closestPointToPoint( point, optionalTarget ) {
  4439. if ( plane === undefined ) {
  4440. plane = new THREE.Plane();
  4441. edgeList = [ new THREE.Line3(), new THREE.Line3(), new THREE.Line3() ];
  4442. projectedPoint = new THREE.Vector3();
  4443. closestPoint = new THREE.Vector3();
  4444. }
  4445. var result = optionalTarget || new THREE.Vector3();
  4446. var minDistance = Infinity;
  4447. // project the point onto the plane of the triangle
  4448. plane.setFromCoplanarPoints( this.a, this.b, this.c );
  4449. plane.projectPoint( point, projectedPoint );
  4450. // check if the projection lies within the triangle
  4451. if( this.containsPoint( projectedPoint ) === true ) {
  4452. // if so, this is the closest point
  4453. result.copy( projectedPoint );
  4454. } else {
  4455. // if not, the point falls outside the triangle. the result is the closest point to the triangle's edges or vertices
  4456. edgeList[ 0 ].set( this.a, this.b );
  4457. edgeList[ 1 ].set( this.b, this.c );
  4458. edgeList[ 2 ].set( this.c, this.a );
  4459. for( var i = 0; i < edgeList.length; i ++ ) {
  4460. edgeList[ i ].closestPointToPoint( projectedPoint, true, closestPoint );
  4461. var distance = projectedPoint.distanceToSquared( closestPoint );
  4462. if( distance < minDistance ) {
  4463. minDistance = distance;
  4464. result.copy( closestPoint );
  4465. }
  4466. }
  4467. }
  4468. return result;
  4469. };
  4470. }(),
  4471. equals: function ( triangle ) {
  4472. return triangle.a.equals( this.a ) && triangle.b.equals( this.b ) && triangle.c.equals( this.c );
  4473. }
  4474. };
  4475. // File:src/math/Interpolant.js
  4476. /**
  4477. * Abstract base class of interpolants over parametric samples.
  4478. *
  4479. * The parameter domain is one dimensional, typically the time or a path
  4480. * along a curve defined by the data.
  4481. *
  4482. * The sample values can have any dimensionality and derived classes may
  4483. * apply special interpretations to the data.
  4484. *
  4485. * This class provides the interval seek in a Template Method, deferring
  4486. * the actual interpolation to derived classes.
  4487. *
  4488. * Time complexity is O(1) for linear access crossing at most two points
  4489. * and O(log N) for random access, where N is the number of positions.
  4490. *
  4491. * References:
  4492. *
  4493. * http://www.oodesign.com/template-method-pattern.html
  4494. *
  4495. * @author tschw
  4496. */
  4497. THREE.Interpolant = function(
  4498. parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  4499. this.parameterPositions = parameterPositions;
  4500. this._cachedIndex = 0;
  4501. this.resultBuffer = resultBuffer !== undefined ?
  4502. resultBuffer : new sampleValues.constructor( sampleSize );
  4503. this.sampleValues = sampleValues;
  4504. this.valueSize = sampleSize;
  4505. };
  4506. THREE.Interpolant.prototype = {
  4507. constructor: THREE.Interpolant,
  4508. evaluate: function( t ) {
  4509. var pp = this.parameterPositions,
  4510. i1 = this._cachedIndex,
  4511. t1 = pp[ i1 ],
  4512. t0 = pp[ i1 - 1 ];
  4513. validate_interval: {
  4514. seek: {
  4515. var right;
  4516. linear_scan: {
  4517. //- See http://jsperf.com/comparison-to-undefined/3
  4518. //- slower code:
  4519. //-
  4520. //- if ( t >= t1 || t1 === undefined ) {
  4521. forward_scan: if ( ! ( t < t1 ) ) {
  4522. for ( var giveUpAt = i1 + 2; ;) {
  4523. if ( t1 === undefined ) {
  4524. if ( t < t0 ) break forward_scan;
  4525. // after end
  4526. i1 = pp.length;
  4527. this._cachedIndex = i1;
  4528. return this.afterEnd_( i1 - 1, t, t0 );
  4529. }
  4530. if ( i1 === giveUpAt ) break; // this loop
  4531. t0 = t1;
  4532. t1 = pp[ ++ i1 ];
  4533. if ( t < t1 ) {
  4534. // we have arrived at the sought interval
  4535. break seek;
  4536. }
  4537. }
  4538. // prepare binary search on the right side of the index
  4539. right = pp.length;
  4540. break linear_scan;
  4541. }
  4542. //- slower code:
  4543. //- if ( t < t0 || t0 === undefined ) {
  4544. if ( ! ( t >= t0 ) ) {
  4545. // looping?
  4546. var t1global = pp[ 1 ];
  4547. if ( t < t1global ) {
  4548. i1 = 2; // + 1, using the scan for the details
  4549. t0 = t1global;
  4550. }
  4551. // linear reverse scan
  4552. for ( var giveUpAt = i1 - 2; ;) {
  4553. if ( t0 === undefined ) {
  4554. // before start
  4555. this._cachedIndex = 0;
  4556. return this.beforeStart_( 0, t, t1 );
  4557. }
  4558. if ( i1 === giveUpAt ) break; // this loop
  4559. t1 = t0;
  4560. t0 = pp[ -- i1 - 1 ];
  4561. if ( t >= t0 ) {
  4562. // we have arrived at the sought interval
  4563. break seek;
  4564. }
  4565. }
  4566. // prepare binary search on the left side of the index
  4567. right = i1;
  4568. i1 = 0;
  4569. break linear_scan;
  4570. }
  4571. // the interval is valid
  4572. break validate_interval;
  4573. } // linear scan
  4574. // binary search
  4575. while ( i1 < right ) {
  4576. var mid = ( i1 + right ) >>> 1;
  4577. if ( t < pp[ mid ] ) {
  4578. right = mid;
  4579. } else {
  4580. i1 = mid + 1;
  4581. }
  4582. }
  4583. t1 = pp[ i1 ];
  4584. t0 = pp[ i1 - 1 ];
  4585. // check boundary cases, again
  4586. if ( t0 === undefined ) {
  4587. this._cachedIndex = 0;
  4588. return this.beforeStart_( 0, t, t1 );
  4589. }
  4590. if ( t1 === undefined ) {
  4591. i1 = pp.length;
  4592. this._cachedIndex = i1;
  4593. return this.afterEnd_( i1 - 1, t0, t );
  4594. }
  4595. } // seek
  4596. this._cachedIndex = i1;
  4597. this.intervalChanged_( i1, t0, t1 );
  4598. } // validate_interval
  4599. return this.interpolate_( i1, t0, t, t1 );
  4600. },
  4601. settings: null, // optional, subclass-specific settings structure
  4602. // Note: The indirection allows central control of many interpolants.
  4603. // --- Protected interface
  4604. DefaultSettings_: {},
  4605. getSettings_: function() {
  4606. return this.settings || this.DefaultSettings_;
  4607. },
  4608. copySampleValue_: function( index ) {
  4609. // copies a sample value to the result buffer
  4610. var result = this.resultBuffer,
  4611. values = this.sampleValues,
  4612. stride = this.valueSize,
  4613. offset = index * stride;
  4614. for ( var i = 0; i !== stride; ++ i ) {
  4615. result[ i ] = values[ offset + i ];
  4616. }
  4617. return result;
  4618. },
  4619. // Template methods for derived classes:
  4620. interpolate_: function( i1, t0, t, t1 ) {
  4621. throw new Error( "call to abstract method" );
  4622. // implementations shall return this.resultBuffer
  4623. },
  4624. intervalChanged_: function( i1, t0, t1 ) {
  4625. // empty
  4626. }
  4627. };
  4628. Object.assign( THREE.Interpolant.prototype, {
  4629. beforeStart_: //( 0, t, t0 ), returns this.resultBuffer
  4630. THREE.Interpolant.prototype.copySampleValue_,
  4631. afterEnd_: //( N-1, tN-1, t ), returns this.resultBuffer
  4632. THREE.Interpolant.prototype.copySampleValue_
  4633. } );
  4634. // File:src/math/interpolants/CubicInterpolant.js
  4635. /**
  4636. * Fast and simple cubic spline interpolant.
  4637. *
  4638. * It was derived from a Hermitian construction setting the first derivative
  4639. * at each sample position to the linear slope between neighboring positions
  4640. * over their parameter interval.
  4641. *
  4642. * @author tschw
  4643. */
  4644. THREE.CubicInterpolant = function(
  4645. parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  4646. THREE.Interpolant.call(
  4647. this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  4648. this._weightPrev = -0;
  4649. this._offsetPrev = -0;
  4650. this._weightNext = -0;
  4651. this._offsetNext = -0;
  4652. };
  4653. THREE.CubicInterpolant.prototype =
  4654. Object.assign( Object.create( THREE.Interpolant.prototype ), {
  4655. constructor: THREE.CubicInterpolant,
  4656. DefaultSettings_: {
  4657. endingStart: THREE.ZeroCurvatureEnding,
  4658. endingEnd: THREE.ZeroCurvatureEnding
  4659. },
  4660. intervalChanged_: function( i1, t0, t1 ) {
  4661. var pp = this.parameterPositions,
  4662. iPrev = i1 - 2,
  4663. iNext = i1 + 1,
  4664. tPrev = pp[ iPrev ],
  4665. tNext = pp[ iNext ];
  4666. if ( tPrev === undefined ) {
  4667. switch ( this.getSettings_().endingStart ) {
  4668. case THREE.ZeroSlopeEnding:
  4669. // f'(t0) = 0
  4670. iPrev = i1;
  4671. tPrev = 2 * t0 - t1;
  4672. break;
  4673. case THREE.WrapAroundEnding:
  4674. // use the other end of the curve
  4675. iPrev = pp.length - 2;
  4676. tPrev = t0 + pp[ iPrev ] - pp[ iPrev + 1 ];
  4677. break;
  4678. default: // ZeroCurvatureEnding
  4679. // f''(t0) = 0 a.k.a. Natural Spline
  4680. iPrev = i1;
  4681. tPrev = t1;
  4682. }
  4683. }
  4684. if ( tNext === undefined ) {
  4685. switch ( this.getSettings_().endingEnd ) {
  4686. case THREE.ZeroSlopeEnding:
  4687. // f'(tN) = 0
  4688. iNext = i1;
  4689. tNext = 2 * t1 - t0;
  4690. break;
  4691. case THREE.WrapAroundEnding:
  4692. // use the other end of the curve
  4693. iNext = 1;
  4694. tNext = t1 + pp[ 1 ] - pp[ 0 ];
  4695. break;
  4696. default: // ZeroCurvatureEnding
  4697. // f''(tN) = 0, a.k.a. Natural Spline
  4698. iNext = i1 - 1;
  4699. tNext = t0;
  4700. }
  4701. }
  4702. var halfDt = ( t1 - t0 ) * 0.5,
  4703. stride = this.valueSize;
  4704. this._weightPrev = halfDt / ( t0 - tPrev );
  4705. this._weightNext = halfDt / ( tNext - t1 );
  4706. this._offsetPrev = iPrev * stride;
  4707. this._offsetNext = iNext * stride;
  4708. },
  4709. interpolate_: function( i1, t0, t, t1 ) {
  4710. var result = this.resultBuffer,
  4711. values = this.sampleValues,
  4712. stride = this.valueSize,
  4713. o1 = i1 * stride, o0 = o1 - stride,
  4714. oP = this._offsetPrev, oN = this._offsetNext,
  4715. wP = this._weightPrev, wN = this._weightNext,
  4716. p = ( t - t0 ) / ( t1 - t0 ),
  4717. pp = p * p,
  4718. ppp = pp * p;
  4719. // evaluate polynomials
  4720. var sP = - wP * ppp + 2 * wP * pp - wP * p;
  4721. var s0 = ( 1 + wP ) * ppp + (-1.5 - 2 * wP ) * pp + ( -0.5 + wP ) * p + 1;
  4722. var s1 = (-1 - wN ) * ppp + ( 1.5 + wN ) * pp + 0.5 * p;
  4723. var sN = wN * ppp - wN * pp;
  4724. // combine data linearly
  4725. for ( var i = 0; i !== stride; ++ i ) {
  4726. result[ i ] =
  4727. sP * values[ oP + i ] +
  4728. s0 * values[ o0 + i ] +
  4729. s1 * values[ o1 + i ] +
  4730. sN * values[ oN + i ];
  4731. }
  4732. return result;
  4733. }
  4734. } );
  4735. // File:src/math/interpolants/DiscreteInterpolant.js
  4736. /**
  4737. *
  4738. * Interpolant that evaluates to the sample value at the position preceeding
  4739. * the parameter.
  4740. *
  4741. * @author tschw
  4742. */
  4743. THREE.DiscreteInterpolant = function(
  4744. parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  4745. THREE.Interpolant.call(
  4746. this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  4747. };
  4748. THREE.DiscreteInterpolant.prototype =
  4749. Object.assign( Object.create( THREE.Interpolant.prototype ), {
  4750. constructor: THREE.DiscreteInterpolant,
  4751. interpolate_: function( i1, t0, t, t1 ) {
  4752. return this.copySampleValue_( i1 - 1 );
  4753. }
  4754. } );
  4755. // File:src/math/interpolants/LinearInterpolant.js
  4756. /**
  4757. * @author tschw
  4758. */
  4759. THREE.LinearInterpolant = function(
  4760. parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  4761. THREE.Interpolant.call(
  4762. this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  4763. };
  4764. THREE.LinearInterpolant.prototype =
  4765. Object.assign( Object.create( THREE.Interpolant.prototype ), {
  4766. constructor: THREE.LinearInterpolant,
  4767. interpolate_: function( i1, t0, t, t1 ) {
  4768. var result = this.resultBuffer,
  4769. values = this.sampleValues,
  4770. stride = this.valueSize,
  4771. offset1 = i1 * stride,
  4772. offset0 = offset1 - stride,
  4773. weight1 = ( t - t0 ) / ( t1 - t0 ),
  4774. weight0 = 1 - weight1;
  4775. for ( var i = 0; i !== stride; ++ i ) {
  4776. result[ i ] =
  4777. values[ offset0 + i ] * weight0 +
  4778. values[ offset1 + i ] * weight1;
  4779. }
  4780. return result;
  4781. }
  4782. } );
  4783. // File:src/math/interpolants/QuaternionLinearInterpolant.js
  4784. /**
  4785. * Spherical linear unit quaternion interpolant.
  4786. *
  4787. * @author tschw
  4788. */
  4789. THREE.QuaternionLinearInterpolant = function(
  4790. parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  4791. THREE.Interpolant.call(
  4792. this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  4793. };
  4794. THREE.QuaternionLinearInterpolant.prototype =
  4795. Object.assign( Object.create( THREE.Interpolant.prototype ), {
  4796. constructor: THREE.QuaternionLinearInterpolant,
  4797. interpolate_: function( i1, t0, t, t1 ) {
  4798. var result = this.resultBuffer,
  4799. values = this.sampleValues,
  4800. stride = this.valueSize,
  4801. offset = i1 * stride,
  4802. alpha = ( t - t0 ) / ( t1 - t0 );
  4803. for ( var end = offset + stride; offset !== end; offset += 4 ) {
  4804. THREE.Quaternion.slerpFlat( result, 0,
  4805. values, offset - stride, values, offset, alpha );
  4806. }
  4807. return result;
  4808. }
  4809. } );
  4810. // File:src/core/Clock.js
  4811. /**
  4812. * @author alteredq / http://alteredqualia.com/
  4813. */
  4814. THREE.Clock = function ( autoStart ) {
  4815. this.autoStart = ( autoStart !== undefined ) ? autoStart : true;
  4816. this.startTime = 0;
  4817. this.oldTime = 0;
  4818. this.elapsedTime = 0;
  4819. this.running = false;
  4820. };
  4821. THREE.Clock.prototype = {
  4822. constructor: THREE.Clock,
  4823. start: function () {
  4824. this.startTime = ( performance || Date ).now();
  4825. this.oldTime = this.startTime;
  4826. this.running = true;
  4827. },
  4828. stop: function () {
  4829. this.getElapsedTime();
  4830. this.running = false;
  4831. },
  4832. getElapsedTime: function () {
  4833. this.getDelta();
  4834. return this.elapsedTime;
  4835. },
  4836. getDelta: function () {
  4837. var diff = 0;
  4838. if ( this.autoStart && ! this.running ) {
  4839. this.start();
  4840. }
  4841. if ( this.running ) {
  4842. var newTime = ( performance || Date ).now();
  4843. diff = ( newTime - this.oldTime ) / 1000;
  4844. this.oldTime = newTime;
  4845. this.elapsedTime += diff;
  4846. }
  4847. return diff;
  4848. }
  4849. };
  4850. // File:src/core/EventDispatcher.js
  4851. /**
  4852. * https://github.com/mrdoob/eventdispatcher.js/
  4853. */
  4854. THREE.EventDispatcher = function () {};
  4855. Object.assign( THREE.EventDispatcher.prototype, {
  4856. addEventListener: function ( type, listener ) {
  4857. if ( this._listeners === undefined ) this._listeners = {};
  4858. var listeners = this._listeners;
  4859. if ( listeners[ type ] === undefined ) {
  4860. listeners[ type ] = [];
  4861. }
  4862. if ( listeners[ type ].indexOf( listener ) === - 1 ) {
  4863. listeners[ type ].push( listener );
  4864. }
  4865. },
  4866. hasEventListener: function ( type, listener ) {
  4867. if ( this._listeners === undefined ) return false;
  4868. var listeners = this._listeners;
  4869. if ( listeners[ type ] !== undefined && listeners[ type ].indexOf( listener ) !== - 1 ) {
  4870. return true;
  4871. }
  4872. return false;
  4873. },
  4874. removeEventListener: function ( type, listener ) {
  4875. if ( this._listeners === undefined ) return;
  4876. var listeners = this._listeners;
  4877. var listenerArray = listeners[ type ];
  4878. if ( listenerArray !== undefined ) {
  4879. var index = listenerArray.indexOf( listener );
  4880. if ( index !== - 1 ) {
  4881. listenerArray.splice( index, 1 );
  4882. }
  4883. }
  4884. },
  4885. dispatchEvent: function ( event ) {
  4886. if ( this._listeners === undefined ) return;
  4887. var listeners = this._listeners;
  4888. var listenerArray = listeners[ event.type ];
  4889. if ( listenerArray !== undefined ) {
  4890. event.target = this;
  4891. var array = [], i = 0;
  4892. var length = listenerArray.length;
  4893. for ( i = 0; i < length; i ++ ) {
  4894. array[ i ] = listenerArray[ i ];
  4895. }
  4896. for ( i = 0; i < length; i ++ ) {
  4897. array[ i ].call( this, event );
  4898. }
  4899. }
  4900. }
  4901. } );
  4902. // File:src/core/Layers.js
  4903. /**
  4904. * @author mrdoob / http://mrdoob.com/
  4905. */
  4906. THREE.Layers = function () {
  4907. this.mask = 1;
  4908. };
  4909. THREE.Layers.prototype = {
  4910. constructor: THREE.Layers,
  4911. set: function ( channel ) {
  4912. this.mask = 1 << channel;
  4913. },
  4914. enable: function ( channel ) {
  4915. this.mask |= 1 << channel;
  4916. },
  4917. toggle: function ( channel ) {
  4918. this.mask ^= 1 << channel;
  4919. },
  4920. disable: function ( channel ) {
  4921. this.mask &= ~ ( 1 << channel );
  4922. },
  4923. test: function ( layers ) {
  4924. return ( this.mask & layers.mask ) !== 0;
  4925. }
  4926. };
  4927. // File:src/core/Raycaster.js
  4928. /**
  4929. * @author mrdoob / http://mrdoob.com/
  4930. * @author bhouston / http://clara.io/
  4931. * @author stephomi / http://stephaneginier.com/
  4932. */
  4933. ( function ( THREE ) {
  4934. THREE.Raycaster = function ( origin, direction, near, far ) {
  4935. this.ray = new THREE.Ray( origin, direction );
  4936. // direction is assumed to be normalized (for accurate distance calculations)
  4937. this.near = near || 0;
  4938. this.far = far || Infinity;
  4939. this.params = {
  4940. Mesh: {},
  4941. Line: {},
  4942. LOD: {},
  4943. Points: { threshold: 1 },
  4944. Sprite: {}
  4945. };
  4946. Object.defineProperties( this.params, {
  4947. PointCloud: {
  4948. get: function () {
  4949. console.warn( 'THREE.Raycaster: params.PointCloud has been renamed to params.Points.' );
  4950. return this.Points;
  4951. }
  4952. }
  4953. } );
  4954. };
  4955. function ascSort( a, b ) {
  4956. return a.distance - b.distance;
  4957. }
  4958. function intersectObject( object, raycaster, intersects, recursive ) {
  4959. if ( object.visible === false ) return;
  4960. object.raycast( raycaster, intersects );
  4961. if ( recursive === true ) {
  4962. var children = object.children;
  4963. for ( var i = 0, l = children.length; i < l; i ++ ) {
  4964. intersectObject( children[ i ], raycaster, intersects, true );
  4965. }
  4966. }
  4967. }
  4968. //
  4969. THREE.Raycaster.prototype = {
  4970. constructor: THREE.Raycaster,
  4971. linePrecision: 1,
  4972. set: function ( origin, direction ) {
  4973. // direction is assumed to be normalized (for accurate distance calculations)
  4974. this.ray.set( origin, direction );
  4975. },
  4976. setFromCamera: function ( coords, camera ) {
  4977. if ( camera instanceof THREE.PerspectiveCamera ) {
  4978. this.ray.origin.setFromMatrixPosition( camera.matrixWorld );
  4979. this.ray.direction.set( coords.x, coords.y, 0.5 ).unproject( camera ).sub( this.ray.origin ).normalize();
  4980. } else if ( camera instanceof THREE.OrthographicCamera ) {
  4981. this.ray.origin.set( coords.x, coords.y, ( camera.near + camera.far ) / ( camera.near - camera.far ) ).unproject( camera ); // set origin in plane of camera
  4982. this.ray.direction.set( 0, 0, - 1 ).transformDirection( camera.matrixWorld );
  4983. } else {
  4984. console.error( 'THREE.Raycaster: Unsupported camera type.' );
  4985. }
  4986. },
  4987. intersectObject: function ( object, recursive ) {
  4988. var intersects = [];
  4989. intersectObject( object, this, intersects, recursive );
  4990. intersects.sort( ascSort );
  4991. return intersects;
  4992. },
  4993. intersectObjects: function ( objects, recursive ) {
  4994. var intersects = [];
  4995. if ( Array.isArray( objects ) === false ) {
  4996. console.warn( 'THREE.Raycaster.intersectObjects: objects is not an Array.' );
  4997. return intersects;
  4998. }
  4999. for ( var i = 0, l = objects.length; i < l; i ++ ) {
  5000. intersectObject( objects[ i ], this, intersects, recursive );
  5001. }
  5002. intersects.sort( ascSort );
  5003. return intersects;
  5004. }
  5005. };
  5006. }( THREE ) );
  5007. // File:src/core/Object3D.js
  5008. /**
  5009. * @author mrdoob / http://mrdoob.com/
  5010. * @author mikael emtinger / http://gomo.se/
  5011. * @author alteredq / http://alteredqualia.com/
  5012. * @author WestLangley / http://github.com/WestLangley
  5013. * @author elephantatwork / www.elephantatwork.ch
  5014. */
  5015. THREE.Object3D = function () {
  5016. Object.defineProperty( this, 'id', { value: THREE.Object3DIdCount ++ } );
  5017. this.uuid = THREE.Math.generateUUID();
  5018. this.name = '';
  5019. this.type = 'Object3D';
  5020. this.parent = null;
  5021. this.children = [];
  5022. this.up = THREE.Object3D.DefaultUp.clone();
  5023. var position = new THREE.Vector3();
  5024. var rotation = new THREE.Euler();
  5025. var quaternion = new THREE.Quaternion();
  5026. var scale = new THREE.Vector3( 1, 1, 1 );
  5027. function onRotationChange() {
  5028. quaternion.setFromEuler( rotation, false );
  5029. }
  5030. function onQuaternionChange() {
  5031. rotation.setFromQuaternion( quaternion, undefined, false );
  5032. }
  5033. rotation.onChange( onRotationChange );
  5034. quaternion.onChange( onQuaternionChange );
  5035. Object.defineProperties( this, {
  5036. position: {
  5037. enumerable: true,
  5038. value: position
  5039. },
  5040. rotation: {
  5041. enumerable: true,
  5042. value: rotation
  5043. },
  5044. quaternion: {
  5045. enumerable: true,
  5046. value: quaternion
  5047. },
  5048. scale: {
  5049. enumerable: true,
  5050. value: scale
  5051. },
  5052. modelViewMatrix: {
  5053. value: new THREE.Matrix4()
  5054. },
  5055. normalMatrix: {
  5056. value: new THREE.Matrix3()
  5057. }
  5058. } );
  5059. this.matrix = new THREE.Matrix4();
  5060. this.matrixWorld = new THREE.Matrix4();
  5061. this.matrixAutoUpdate = THREE.Object3D.DefaultMatrixAutoUpdate;
  5062. this.matrixWorldNeedsUpdate = false;
  5063. this.layers = new THREE.Layers();
  5064. this.visible = true;
  5065. this.castShadow = false;
  5066. this.receiveShadow = false;
  5067. this.frustumCulled = true;
  5068. this.renderOrder = 0;
  5069. this.userData = {};
  5070. };
  5071. THREE.Object3D.DefaultUp = new THREE.Vector3( 0, 1, 0 );
  5072. THREE.Object3D.DefaultMatrixAutoUpdate = true;
  5073. Object.assign( THREE.Object3D.prototype, THREE.EventDispatcher.prototype, {
  5074. applyMatrix: function ( matrix ) {
  5075. this.matrix.multiplyMatrices( matrix, this.matrix );
  5076. this.matrix.decompose( this.position, this.quaternion, this.scale );
  5077. },
  5078. setRotationFromAxisAngle: function ( axis, angle ) {
  5079. // assumes axis is normalized
  5080. this.quaternion.setFromAxisAngle( axis, angle );
  5081. },
  5082. setRotationFromEuler: function ( euler ) {
  5083. this.quaternion.setFromEuler( euler, true );
  5084. },
  5085. setRotationFromMatrix: function ( m ) {
  5086. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  5087. this.quaternion.setFromRotationMatrix( m );
  5088. },
  5089. setRotationFromQuaternion: function ( q ) {
  5090. // assumes q is normalized
  5091. this.quaternion.copy( q );
  5092. },
  5093. rotateOnAxis: function () {
  5094. // rotate object on axis in object space
  5095. // axis is assumed to be normalized
  5096. var q1 = new THREE.Quaternion();
  5097. return function rotateOnAxis( axis, angle ) {
  5098. q1.setFromAxisAngle( axis, angle );
  5099. this.quaternion.multiply( q1 );
  5100. return this;
  5101. };
  5102. }(),
  5103. rotateX: function () {
  5104. var v1 = new THREE.Vector3( 1, 0, 0 );
  5105. return function rotateX( angle ) {
  5106. return this.rotateOnAxis( v1, angle );
  5107. };
  5108. }(),
  5109. rotateY: function () {
  5110. var v1 = new THREE.Vector3( 0, 1, 0 );
  5111. return function rotateY( angle ) {
  5112. return this.rotateOnAxis( v1, angle );
  5113. };
  5114. }(),
  5115. rotateZ: function () {
  5116. var v1 = new THREE.Vector3( 0, 0, 1 );
  5117. return function rotateZ( angle ) {
  5118. return this.rotateOnAxis( v1, angle );
  5119. };
  5120. }(),
  5121. translateOnAxis: function () {
  5122. // translate object by distance along axis in object space
  5123. // axis is assumed to be normalized
  5124. var v1 = new THREE.Vector3();
  5125. return function translateOnAxis( axis, distance ) {
  5126. v1.copy( axis ).applyQuaternion( this.quaternion );
  5127. this.position.add( v1.multiplyScalar( distance ) );
  5128. return this;
  5129. };
  5130. }(),
  5131. translateX: function () {
  5132. var v1 = new THREE.Vector3( 1, 0, 0 );
  5133. return function translateX( distance ) {
  5134. return this.translateOnAxis( v1, distance );
  5135. };
  5136. }(),
  5137. translateY: function () {
  5138. var v1 = new THREE.Vector3( 0, 1, 0 );
  5139. return function translateY( distance ) {
  5140. return this.translateOnAxis( v1, distance );
  5141. };
  5142. }(),
  5143. translateZ: function () {
  5144. var v1 = new THREE.Vector3( 0, 0, 1 );
  5145. return function translateZ( distance ) {
  5146. return this.translateOnAxis( v1, distance );
  5147. };
  5148. }(),
  5149. localToWorld: function ( vector ) {
  5150. return vector.applyMatrix4( this.matrixWorld );
  5151. },
  5152. worldToLocal: function () {
  5153. var m1 = new THREE.Matrix4();
  5154. return function worldToLocal( vector ) {
  5155. return vector.applyMatrix4( m1.getInverse( this.matrixWorld ) );
  5156. };
  5157. }(),
  5158. lookAt: function () {
  5159. // This routine does not support objects with rotated and/or translated parent(s)
  5160. var m1 = new THREE.Matrix4();
  5161. return function lookAt( vector ) {
  5162. m1.lookAt( vector, this.position, this.up );
  5163. this.quaternion.setFromRotationMatrix( m1 );
  5164. };
  5165. }(),
  5166. add: function ( object ) {
  5167. if ( arguments.length > 1 ) {
  5168. for ( var i = 0; i < arguments.length; i ++ ) {
  5169. this.add( arguments[ i ] );
  5170. }
  5171. return this;
  5172. }
  5173. if ( object === this ) {
  5174. console.error( "THREE.Object3D.add: object can't be added as a child of itself.", object );
  5175. return this;
  5176. }
  5177. if ( object instanceof THREE.Object3D ) {
  5178. if ( object.parent !== null ) {
  5179. object.parent.remove( object );
  5180. }
  5181. object.parent = this;
  5182. object.dispatchEvent( { type: 'added' } );
  5183. this.children.push( object );
  5184. } else {
  5185. console.error( "THREE.Object3D.add: object not an instance of THREE.Object3D.", object );
  5186. }
  5187. return this;
  5188. },
  5189. remove: function ( object ) {
  5190. if ( arguments.length > 1 ) {
  5191. for ( var i = 0; i < arguments.length; i ++ ) {
  5192. this.remove( arguments[ i ] );
  5193. }
  5194. }
  5195. var index = this.children.indexOf( object );
  5196. if ( index !== - 1 ) {
  5197. object.parent = null;
  5198. object.dispatchEvent( { type: 'removed' } );
  5199. this.children.splice( index, 1 );
  5200. }
  5201. },
  5202. getObjectById: function ( id ) {
  5203. return this.getObjectByProperty( 'id', id );
  5204. },
  5205. getObjectByName: function ( name ) {
  5206. return this.getObjectByProperty( 'name', name );
  5207. },
  5208. getObjectByProperty: function ( name, value ) {
  5209. if ( this[ name ] === value ) return this;
  5210. for ( var i = 0, l = this.children.length; i < l; i ++ ) {
  5211. var child = this.children[ i ];
  5212. var object = child.getObjectByProperty( name, value );
  5213. if ( object !== undefined ) {
  5214. return object;
  5215. }
  5216. }
  5217. return undefined;
  5218. },
  5219. getWorldPosition: function ( optionalTarget ) {
  5220. var result = optionalTarget || new THREE.Vector3();
  5221. this.updateMatrixWorld( true );
  5222. return result.setFromMatrixPosition( this.matrixWorld );
  5223. },
  5224. getWorldQuaternion: function () {
  5225. var position = new THREE.Vector3();
  5226. var scale = new THREE.Vector3();
  5227. return function getWorldQuaternion( optionalTarget ) {
  5228. var result = optionalTarget || new THREE.Quaternion();
  5229. this.updateMatrixWorld( true );
  5230. this.matrixWorld.decompose( position, result, scale );
  5231. return result;
  5232. };
  5233. }(),
  5234. getWorldRotation: function () {
  5235. var quaternion = new THREE.Quaternion();
  5236. return function getWorldRotation( optionalTarget ) {
  5237. var result = optionalTarget || new THREE.Euler();
  5238. this.getWorldQuaternion( quaternion );
  5239. return result.setFromQuaternion( quaternion, this.rotation.order, false );
  5240. };
  5241. }(),
  5242. getWorldScale: function () {
  5243. var position = new THREE.Vector3();
  5244. var quaternion = new THREE.Quaternion();
  5245. return function getWorldScale( optionalTarget ) {
  5246. var result = optionalTarget || new THREE.Vector3();
  5247. this.updateMatrixWorld( true );
  5248. this.matrixWorld.decompose( position, quaternion, result );
  5249. return result;
  5250. };
  5251. }(),
  5252. getWorldDirection: function () {
  5253. var quaternion = new THREE.Quaternion();
  5254. return function getWorldDirection( optionalTarget ) {
  5255. var result = optionalTarget || new THREE.Vector3();
  5256. this.getWorldQuaternion( quaternion );
  5257. return result.set( 0, 0, 1 ).applyQuaternion( quaternion );
  5258. };
  5259. }(),
  5260. raycast: function () {},
  5261. traverse: function ( callback ) {
  5262. callback( this );
  5263. var children = this.children;
  5264. for ( var i = 0, l = children.length; i < l; i ++ ) {
  5265. children[ i ].traverse( callback );
  5266. }
  5267. },
  5268. traverseVisible: function ( callback ) {
  5269. if ( this.visible === false ) return;
  5270. callback( this );
  5271. var children = this.children;
  5272. for ( var i = 0, l = children.length; i < l; i ++ ) {
  5273. children[ i ].traverseVisible( callback );
  5274. }
  5275. },
  5276. traverseAncestors: function ( callback ) {
  5277. var parent = this.parent;
  5278. if ( parent !== null ) {
  5279. callback( parent );
  5280. parent.traverseAncestors( callback );
  5281. }
  5282. },
  5283. updateMatrix: function () {
  5284. this.matrix.compose( this.position, this.quaternion, this.scale );
  5285. this.matrixWorldNeedsUpdate = true;
  5286. },
  5287. updateMatrixWorld: function ( force ) {
  5288. if ( this.matrixAutoUpdate === true ) this.updateMatrix();
  5289. if ( this.matrixWorldNeedsUpdate === true || force === true ) {
  5290. if ( this.parent === null ) {
  5291. this.matrixWorld.copy( this.matrix );
  5292. } else {
  5293. this.matrixWorld.multiplyMatrices( this.parent.matrixWorld, this.matrix );
  5294. }
  5295. this.matrixWorldNeedsUpdate = false;
  5296. force = true;
  5297. }
  5298. // update children
  5299. for ( var i = 0, l = this.children.length; i < l; i ++ ) {
  5300. this.children[ i ].updateMatrixWorld( force );
  5301. }
  5302. },
  5303. toJSON: function ( meta ) {
  5304. // meta is '' when called from JSON.stringify
  5305. var isRootObject = ( meta === undefined || meta === '' );
  5306. var output = {};
  5307. // meta is a hash used to collect geometries, materials.
  5308. // not providing it implies that this is the root object
  5309. // being serialized.
  5310. if ( isRootObject ) {
  5311. // initialize meta obj
  5312. meta = {
  5313. geometries: {},
  5314. materials: {},
  5315. textures: {},
  5316. images: {}
  5317. };
  5318. output.metadata = {
  5319. version: 4.4,
  5320. type: 'Object',
  5321. generator: 'Object3D.toJSON'
  5322. };
  5323. }
  5324. // standard Object3D serialization
  5325. var object = {};
  5326. object.uuid = this.uuid;
  5327. object.type = this.type;
  5328. if ( this.name !== '' ) object.name = this.name;
  5329. if ( JSON.stringify( this.userData ) !== '{}' ) object.userData = this.userData;
  5330. if ( this.castShadow === true ) object.castShadow = true;
  5331. if ( this.receiveShadow === true ) object.receiveShadow = true;
  5332. if ( this.visible === false ) object.visible = false;
  5333. object.matrix = this.matrix.toArray();
  5334. //
  5335. if ( this.geometry !== undefined ) {
  5336. if ( meta.geometries[ this.geometry.uuid ] === undefined ) {
  5337. meta.geometries[ this.geometry.uuid ] = this.geometry.toJSON( meta );
  5338. }
  5339. object.geometry = this.geometry.uuid;
  5340. }
  5341. if ( this.material !== undefined ) {
  5342. if ( meta.materials[ this.material.uuid ] === undefined ) {
  5343. meta.materials[ this.material.uuid ] = this.material.toJSON( meta );
  5344. }
  5345. object.material = this.material.uuid;
  5346. }
  5347. //
  5348. if ( this.children.length > 0 ) {
  5349. object.children = [];
  5350. for ( var i = 0; i < this.children.length; i ++ ) {
  5351. object.children.push( this.children[ i ].toJSON( meta ).object );
  5352. }
  5353. }
  5354. if ( isRootObject ) {
  5355. var geometries = extractFromCache( meta.geometries );
  5356. var materials = extractFromCache( meta.materials );
  5357. var textures = extractFromCache( meta.textures );
  5358. var images = extractFromCache( meta.images );
  5359. if ( geometries.length > 0 ) output.geometries = geometries;
  5360. if ( materials.length > 0 ) output.materials = materials;
  5361. if ( textures.length > 0 ) output.textures = textures;
  5362. if ( images.length > 0 ) output.images = images;
  5363. }
  5364. output.object = object;
  5365. return output;
  5366. // extract data from the cache hash
  5367. // remove metadata on each item
  5368. // and return as array
  5369. function extractFromCache ( cache ) {
  5370. var values = [];
  5371. for ( var key in cache ) {
  5372. var data = cache[ key ];
  5373. delete data.metadata;
  5374. values.push( data );
  5375. }
  5376. return values;
  5377. }
  5378. },
  5379. clone: function ( recursive ) {
  5380. return new this.constructor().copy( this, recursive );
  5381. },
  5382. copy: function ( source, recursive ) {
  5383. if ( recursive === undefined ) recursive = true;
  5384. this.name = source.name;
  5385. this.up.copy( source.up );
  5386. this.position.copy( source.position );
  5387. this.quaternion.copy( source.quaternion );
  5388. this.scale.copy( source.scale );
  5389. this.matrix.copy( source.matrix );
  5390. this.matrixWorld.copy( source.matrixWorld );
  5391. this.matrixAutoUpdate = source.matrixAutoUpdate;
  5392. this.matrixWorldNeedsUpdate = source.matrixWorldNeedsUpdate;
  5393. this.visible = source.visible;
  5394. this.castShadow = source.castShadow;
  5395. this.receiveShadow = source.receiveShadow;
  5396. this.frustumCulled = source.frustumCulled;
  5397. this.renderOrder = source.renderOrder;
  5398. this.userData = JSON.parse( JSON.stringify( source.userData ) );
  5399. if ( recursive === true ) {
  5400. for ( var i = 0; i < source.children.length; i ++ ) {
  5401. var child = source.children[ i ];
  5402. this.add( child.clone() );
  5403. }
  5404. }
  5405. return this;
  5406. }
  5407. } );
  5408. THREE.Object3DIdCount = 0;
  5409. // File:src/core/Face3.js
  5410. /**
  5411. * @author mrdoob / http://mrdoob.com/
  5412. * @author alteredq / http://alteredqualia.com/
  5413. */
  5414. THREE.Face3 = function ( a, b, c, normal, color, materialIndex ) {
  5415. this.a = a;
  5416. this.b = b;
  5417. this.c = c;
  5418. this.normal = normal instanceof THREE.Vector3 ? normal : new THREE.Vector3();
  5419. this.vertexNormals = Array.isArray( normal ) ? normal : [];
  5420. this.color = color instanceof THREE.Color ? color : new THREE.Color();
  5421. this.vertexColors = Array.isArray( color ) ? color : [];
  5422. this.materialIndex = materialIndex !== undefined ? materialIndex : 0;
  5423. };
  5424. THREE.Face3.prototype = {
  5425. constructor: THREE.Face3,
  5426. clone: function () {
  5427. return new this.constructor().copy( this );
  5428. },
  5429. copy: function ( source ) {
  5430. this.a = source.a;
  5431. this.b = source.b;
  5432. this.c = source.c;
  5433. this.normal.copy( source.normal );
  5434. this.color.copy( source.color );
  5435. this.materialIndex = source.materialIndex;
  5436. for ( var i = 0, il = source.vertexNormals.length; i < il; i ++ ) {
  5437. this.vertexNormals[ i ] = source.vertexNormals[ i ].clone();
  5438. }
  5439. for ( var i = 0, il = source.vertexColors.length; i < il; i ++ ) {
  5440. this.vertexColors[ i ] = source.vertexColors[ i ].clone();
  5441. }
  5442. return this;
  5443. }
  5444. };
  5445. // File:src/core/BufferAttribute.js
  5446. /**
  5447. * @author mrdoob / http://mrdoob.com/
  5448. */
  5449. THREE.BufferAttribute = function ( array, itemSize, normalized ) {
  5450. this.uuid = THREE.Math.generateUUID();
  5451. this.array = array;
  5452. this.itemSize = itemSize;
  5453. this.dynamic = false;
  5454. this.updateRange = { offset: 0, count: - 1 };
  5455. this.version = 0;
  5456. this.normalized = normalized === true;
  5457. };
  5458. THREE.BufferAttribute.prototype = {
  5459. constructor: THREE.BufferAttribute,
  5460. get count() {
  5461. return this.array.length / this.itemSize;
  5462. },
  5463. set needsUpdate( value ) {
  5464. if ( value === true ) this.version ++;
  5465. },
  5466. setDynamic: function ( value ) {
  5467. this.dynamic = value;
  5468. return this;
  5469. },
  5470. copy: function ( source ) {
  5471. this.array = new source.array.constructor( source.array );
  5472. this.itemSize = source.itemSize;
  5473. this.dynamic = source.dynamic;
  5474. return this;
  5475. },
  5476. copyAt: function ( index1, attribute, index2 ) {
  5477. index1 *= this.itemSize;
  5478. index2 *= attribute.itemSize;
  5479. for ( var i = 0, l = this.itemSize; i < l; i ++ ) {
  5480. this.array[ index1 + i ] = attribute.array[ index2 + i ];
  5481. }
  5482. return this;
  5483. },
  5484. copyArray: function ( array ) {
  5485. this.array.set( array );
  5486. return this;
  5487. },
  5488. copyColorsArray: function ( colors ) {
  5489. var array = this.array, offset = 0;
  5490. for ( var i = 0, l = colors.length; i < l; i ++ ) {
  5491. var color = colors[ i ];
  5492. if ( color === undefined ) {
  5493. console.warn( 'THREE.BufferAttribute.copyColorsArray(): color is undefined', i );
  5494. color = new THREE.Color();
  5495. }
  5496. array[ offset ++ ] = color.r;
  5497. array[ offset ++ ] = color.g;
  5498. array[ offset ++ ] = color.b;
  5499. }
  5500. return this;
  5501. },
  5502. copyIndicesArray: function ( indices ) {
  5503. var array = this.array, offset = 0;
  5504. for ( var i = 0, l = indices.length; i < l; i ++ ) {
  5505. var index = indices[ i ];
  5506. array[ offset ++ ] = index.a;
  5507. array[ offset ++ ] = index.b;
  5508. array[ offset ++ ] = index.c;
  5509. }
  5510. return this;
  5511. },
  5512. copyVector2sArray: function ( vectors ) {
  5513. var array = this.array, offset = 0;
  5514. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  5515. var vector = vectors[ i ];
  5516. if ( vector === undefined ) {
  5517. console.warn( 'THREE.BufferAttribute.copyVector2sArray(): vector is undefined', i );
  5518. vector = new THREE.Vector2();
  5519. }
  5520. array[ offset ++ ] = vector.x;
  5521. array[ offset ++ ] = vector.y;
  5522. }
  5523. return this;
  5524. },
  5525. copyVector3sArray: function ( vectors ) {
  5526. var array = this.array, offset = 0;
  5527. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  5528. var vector = vectors[ i ];
  5529. if ( vector === undefined ) {
  5530. console.warn( 'THREE.BufferAttribute.copyVector3sArray(): vector is undefined', i );
  5531. vector = new THREE.Vector3();
  5532. }
  5533. array[ offset ++ ] = vector.x;
  5534. array[ offset ++ ] = vector.y;
  5535. array[ offset ++ ] = vector.z;
  5536. }
  5537. return this;
  5538. },
  5539. copyVector4sArray: function ( vectors ) {
  5540. var array = this.array, offset = 0;
  5541. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  5542. var vector = vectors[ i ];
  5543. if ( vector === undefined ) {
  5544. console.warn( 'THREE.BufferAttribute.copyVector4sArray(): vector is undefined', i );
  5545. vector = new THREE.Vector4();
  5546. }
  5547. array[ offset ++ ] = vector.x;
  5548. array[ offset ++ ] = vector.y;
  5549. array[ offset ++ ] = vector.z;
  5550. array[ offset ++ ] = vector.w;
  5551. }
  5552. return this;
  5553. },
  5554. set: function ( value, offset ) {
  5555. if ( offset === undefined ) offset = 0;
  5556. this.array.set( value, offset );
  5557. return this;
  5558. },
  5559. getX: function ( index ) {
  5560. return this.array[ index * this.itemSize ];
  5561. },
  5562. setX: function ( index, x ) {
  5563. this.array[ index * this.itemSize ] = x;
  5564. return this;
  5565. },
  5566. getY: function ( index ) {
  5567. return this.array[ index * this.itemSize + 1 ];
  5568. },
  5569. setY: function ( index, y ) {
  5570. this.array[ index * this.itemSize + 1 ] = y;
  5571. return this;
  5572. },
  5573. getZ: function ( index ) {
  5574. return this.array[ index * this.itemSize + 2 ];
  5575. },
  5576. setZ: function ( index, z ) {
  5577. this.array[ index * this.itemSize + 2 ] = z;
  5578. return this;
  5579. },
  5580. getW: function ( index ) {
  5581. return this.array[ index * this.itemSize + 3 ];
  5582. },
  5583. setW: function ( index, w ) {
  5584. this.array[ index * this.itemSize + 3 ] = w;
  5585. return this;
  5586. },
  5587. setXY: function ( index, x, y ) {
  5588. index *= this.itemSize;
  5589. this.array[ index + 0 ] = x;
  5590. this.array[ index + 1 ] = y;
  5591. return this;
  5592. },
  5593. setXYZ: function ( index, x, y, z ) {
  5594. index *= this.itemSize;
  5595. this.array[ index + 0 ] = x;
  5596. this.array[ index + 1 ] = y;
  5597. this.array[ index + 2 ] = z;
  5598. return this;
  5599. },
  5600. setXYZW: function ( index, x, y, z, w ) {
  5601. index *= this.itemSize;
  5602. this.array[ index + 0 ] = x;
  5603. this.array[ index + 1 ] = y;
  5604. this.array[ index + 2 ] = z;
  5605. this.array[ index + 3 ] = w;
  5606. return this;
  5607. },
  5608. clone: function () {
  5609. return new this.constructor().copy( this );
  5610. }
  5611. };
  5612. //
  5613. THREE.Int8Attribute = function ( array, itemSize ) {
  5614. return new THREE.BufferAttribute( new Int8Array( array ), itemSize );
  5615. };
  5616. THREE.Uint8Attribute = function ( array, itemSize ) {
  5617. return new THREE.BufferAttribute( new Uint8Array( array ), itemSize );
  5618. };
  5619. THREE.Uint8ClampedAttribute = function ( array, itemSize ) {
  5620. return new THREE.BufferAttribute( new Uint8ClampedArray( array ), itemSize );
  5621. };
  5622. THREE.Int16Attribute = function ( array, itemSize ) {
  5623. return new THREE.BufferAttribute( new Int16Array( array ), itemSize );
  5624. };
  5625. THREE.Uint16Attribute = function ( array, itemSize ) {
  5626. return new THREE.BufferAttribute( new Uint16Array( array ), itemSize );
  5627. };
  5628. THREE.Int32Attribute = function ( array, itemSize ) {
  5629. return new THREE.BufferAttribute( new Int32Array( array ), itemSize );
  5630. };
  5631. THREE.Uint32Attribute = function ( array, itemSize ) {
  5632. return new THREE.BufferAttribute( new Uint32Array( array ), itemSize );
  5633. };
  5634. THREE.Float32Attribute = function ( array, itemSize ) {
  5635. return new THREE.BufferAttribute( new Float32Array( array ), itemSize );
  5636. };
  5637. THREE.Float64Attribute = function ( array, itemSize ) {
  5638. return new THREE.BufferAttribute( new Float64Array( array ), itemSize );
  5639. };
  5640. // Deprecated
  5641. THREE.DynamicBufferAttribute = function ( array, itemSize ) {
  5642. console.warn( 'THREE.DynamicBufferAttribute has been removed. Use new THREE.BufferAttribute().setDynamic( true ) instead.' );
  5643. return new THREE.BufferAttribute( array, itemSize ).setDynamic( true );
  5644. };
  5645. // File:src/core/InstancedBufferAttribute.js
  5646. /**
  5647. * @author benaadams / https://twitter.com/ben_a_adams
  5648. */
  5649. THREE.InstancedBufferAttribute = function ( array, itemSize, meshPerAttribute ) {
  5650. THREE.BufferAttribute.call( this, array, itemSize );
  5651. this.meshPerAttribute = meshPerAttribute || 1;
  5652. };
  5653. THREE.InstancedBufferAttribute.prototype = Object.create( THREE.BufferAttribute.prototype );
  5654. THREE.InstancedBufferAttribute.prototype.constructor = THREE.InstancedBufferAttribute;
  5655. THREE.InstancedBufferAttribute.prototype.copy = function ( source ) {
  5656. THREE.BufferAttribute.prototype.copy.call( this, source );
  5657. this.meshPerAttribute = source.meshPerAttribute;
  5658. return this;
  5659. };
  5660. // File:src/core/InterleavedBuffer.js
  5661. /**
  5662. * @author benaadams / https://twitter.com/ben_a_adams
  5663. */
  5664. THREE.InterleavedBuffer = function ( array, stride ) {
  5665. this.uuid = THREE.Math.generateUUID();
  5666. this.array = array;
  5667. this.stride = stride;
  5668. this.dynamic = false;
  5669. this.updateRange = { offset: 0, count: - 1 };
  5670. this.version = 0;
  5671. };
  5672. THREE.InterleavedBuffer.prototype = {
  5673. constructor: THREE.InterleavedBuffer,
  5674. get length () {
  5675. return this.array.length;
  5676. },
  5677. get count () {
  5678. return this.array.length / this.stride;
  5679. },
  5680. set needsUpdate( value ) {
  5681. if ( value === true ) this.version ++;
  5682. },
  5683. setDynamic: function ( value ) {
  5684. this.dynamic = value;
  5685. return this;
  5686. },
  5687. copy: function ( source ) {
  5688. this.array = new source.array.constructor( source.array );
  5689. this.stride = source.stride;
  5690. this.dynamic = source.dynamic;
  5691. return this;
  5692. },
  5693. copyAt: function ( index1, attribute, index2 ) {
  5694. index1 *= this.stride;
  5695. index2 *= attribute.stride;
  5696. for ( var i = 0, l = this.stride; i < l; i ++ ) {
  5697. this.array[ index1 + i ] = attribute.array[ index2 + i ];
  5698. }
  5699. return this;
  5700. },
  5701. set: function ( value, offset ) {
  5702. if ( offset === undefined ) offset = 0;
  5703. this.array.set( value, offset );
  5704. return this;
  5705. },
  5706. clone: function () {
  5707. return new this.constructor().copy( this );
  5708. }
  5709. };
  5710. // File:src/core/InstancedInterleavedBuffer.js
  5711. /**
  5712. * @author benaadams / https://twitter.com/ben_a_adams
  5713. */
  5714. THREE.InstancedInterleavedBuffer = function ( array, stride, meshPerAttribute ) {
  5715. THREE.InterleavedBuffer.call( this, array, stride );
  5716. this.meshPerAttribute = meshPerAttribute || 1;
  5717. };
  5718. THREE.InstancedInterleavedBuffer.prototype = Object.create( THREE.InterleavedBuffer.prototype );
  5719. THREE.InstancedInterleavedBuffer.prototype.constructor = THREE.InstancedInterleavedBuffer;
  5720. THREE.InstancedInterleavedBuffer.prototype.copy = function ( source ) {
  5721. THREE.InterleavedBuffer.prototype.copy.call( this, source );
  5722. this.meshPerAttribute = source.meshPerAttribute;
  5723. return this;
  5724. };
  5725. // File:src/core/InterleavedBufferAttribute.js
  5726. /**
  5727. * @author benaadams / https://twitter.com/ben_a_adams
  5728. */
  5729. THREE.InterleavedBufferAttribute = function ( interleavedBuffer, itemSize, offset ) {
  5730. this.uuid = THREE.Math.generateUUID();
  5731. this.data = interleavedBuffer;
  5732. this.itemSize = itemSize;
  5733. this.offset = offset;
  5734. };
  5735. THREE.InterleavedBufferAttribute.prototype = {
  5736. constructor: THREE.InterleavedBufferAttribute,
  5737. get length() {
  5738. console.warn( 'THREE.BufferAttribute: .length has been deprecated. Please use .count.' );
  5739. return this.array.length;
  5740. },
  5741. get count() {
  5742. return this.data.count;
  5743. },
  5744. setX: function ( index, x ) {
  5745. this.data.array[ index * this.data.stride + this.offset ] = x;
  5746. return this;
  5747. },
  5748. setY: function ( index, y ) {
  5749. this.data.array[ index * this.data.stride + this.offset + 1 ] = y;
  5750. return this;
  5751. },
  5752. setZ: function ( index, z ) {
  5753. this.data.array[ index * this.data.stride + this.offset + 2 ] = z;
  5754. return this;
  5755. },
  5756. setW: function ( index, w ) {
  5757. this.data.array[ index * this.data.stride + this.offset + 3 ] = w;
  5758. return this;
  5759. },
  5760. getX: function ( index ) {
  5761. return this.data.array[ index * this.data.stride + this.offset ];
  5762. },
  5763. getY: function ( index ) {
  5764. return this.data.array[ index * this.data.stride + this.offset + 1 ];
  5765. },
  5766. getZ: function ( index ) {
  5767. return this.data.array[ index * this.data.stride + this.offset + 2 ];
  5768. },
  5769. getW: function ( index ) {
  5770. return this.data.array[ index * this.data.stride + this.offset + 3 ];
  5771. },
  5772. setXY: function ( index, x, y ) {
  5773. index = index * this.data.stride + this.offset;
  5774. this.data.array[ index + 0 ] = x;
  5775. this.data.array[ index + 1 ] = y;
  5776. return this;
  5777. },
  5778. setXYZ: function ( index, x, y, z ) {
  5779. index = index * this.data.stride + this.offset;
  5780. this.data.array[ index + 0 ] = x;
  5781. this.data.array[ index + 1 ] = y;
  5782. this.data.array[ index + 2 ] = z;
  5783. return this;
  5784. },
  5785. setXYZW: function ( index, x, y, z, w ) {
  5786. index = index * this.data.stride + this.offset;
  5787. this.data.array[ index + 0 ] = x;
  5788. this.data.array[ index + 1 ] = y;
  5789. this.data.array[ index + 2 ] = z;
  5790. this.data.array[ index + 3 ] = w;
  5791. return this;
  5792. }
  5793. };
  5794. // File:src/core/Geometry.js
  5795. /**
  5796. * @author mrdoob / http://mrdoob.com/
  5797. * @author kile / http://kile.stravaganza.org/
  5798. * @author alteredq / http://alteredqualia.com/
  5799. * @author mikael emtinger / http://gomo.se/
  5800. * @author zz85 / http://www.lab4games.net/zz85/blog
  5801. * @author bhouston / http://clara.io
  5802. */
  5803. THREE.Geometry = function () {
  5804. Object.defineProperty( this, 'id', { value: THREE.GeometryIdCount ++ } );
  5805. this.uuid = THREE.Math.generateUUID();
  5806. this.name = '';
  5807. this.type = 'Geometry';
  5808. this.vertices = [];
  5809. this.colors = [];
  5810. this.faces = [];
  5811. this.faceVertexUvs = [ [] ];
  5812. this.morphTargets = [];
  5813. this.morphNormals = [];
  5814. this.skinWeights = [];
  5815. this.skinIndices = [];
  5816. this.lineDistances = [];
  5817. this.boundingBox = null;
  5818. this.boundingSphere = null;
  5819. // update flags
  5820. this.elementsNeedUpdate = false;
  5821. this.verticesNeedUpdate = false;
  5822. this.uvsNeedUpdate = false;
  5823. this.normalsNeedUpdate = false;
  5824. this.colorsNeedUpdate = false;
  5825. this.lineDistancesNeedUpdate = false;
  5826. this.groupsNeedUpdate = false;
  5827. };
  5828. Object.assign( THREE.Geometry.prototype, THREE.EventDispatcher.prototype, {
  5829. applyMatrix: function ( matrix ) {
  5830. var normalMatrix = new THREE.Matrix3().getNormalMatrix( matrix );
  5831. for ( var i = 0, il = this.vertices.length; i < il; i ++ ) {
  5832. var vertex = this.vertices[ i ];
  5833. vertex.applyMatrix4( matrix );
  5834. }
  5835. for ( var i = 0, il = this.faces.length; i < il; i ++ ) {
  5836. var face = this.faces[ i ];
  5837. face.normal.applyMatrix3( normalMatrix ).normalize();
  5838. for ( var j = 0, jl = face.vertexNormals.length; j < jl; j ++ ) {
  5839. face.vertexNormals[ j ].applyMatrix3( normalMatrix ).normalize();
  5840. }
  5841. }
  5842. if ( this.boundingBox !== null ) {
  5843. this.computeBoundingBox();
  5844. }
  5845. if ( this.boundingSphere !== null ) {
  5846. this.computeBoundingSphere();
  5847. }
  5848. this.verticesNeedUpdate = true;
  5849. this.normalsNeedUpdate = true;
  5850. return this;
  5851. },
  5852. rotateX: function () {
  5853. // rotate geometry around world x-axis
  5854. var m1;
  5855. return function rotateX( angle ) {
  5856. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  5857. m1.makeRotationX( angle );
  5858. this.applyMatrix( m1 );
  5859. return this;
  5860. };
  5861. }(),
  5862. rotateY: function () {
  5863. // rotate geometry around world y-axis
  5864. var m1;
  5865. return function rotateY( angle ) {
  5866. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  5867. m1.makeRotationY( angle );
  5868. this.applyMatrix( m1 );
  5869. return this;
  5870. };
  5871. }(),
  5872. rotateZ: function () {
  5873. // rotate geometry around world z-axis
  5874. var m1;
  5875. return function rotateZ( angle ) {
  5876. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  5877. m1.makeRotationZ( angle );
  5878. this.applyMatrix( m1 );
  5879. return this;
  5880. };
  5881. }(),
  5882. translate: function () {
  5883. // translate geometry
  5884. var m1;
  5885. return function translate( x, y, z ) {
  5886. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  5887. m1.makeTranslation( x, y, z );
  5888. this.applyMatrix( m1 );
  5889. return this;
  5890. };
  5891. }(),
  5892. scale: function () {
  5893. // scale geometry
  5894. var m1;
  5895. return function scale( x, y, z ) {
  5896. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  5897. m1.makeScale( x, y, z );
  5898. this.applyMatrix( m1 );
  5899. return this;
  5900. };
  5901. }(),
  5902. lookAt: function () {
  5903. var obj;
  5904. return function lookAt( vector ) {
  5905. if ( obj === undefined ) obj = new THREE.Object3D();
  5906. obj.lookAt( vector );
  5907. obj.updateMatrix();
  5908. this.applyMatrix( obj.matrix );
  5909. };
  5910. }(),
  5911. fromBufferGeometry: function ( geometry ) {
  5912. var scope = this;
  5913. var indices = geometry.index !== null ? geometry.index.array : undefined;
  5914. var attributes = geometry.attributes;
  5915. var positions = attributes.position.array;
  5916. var normals = attributes.normal !== undefined ? attributes.normal.array : undefined;
  5917. var colors = attributes.color !== undefined ? attributes.color.array : undefined;
  5918. var uvs = attributes.uv !== undefined ? attributes.uv.array : undefined;
  5919. var uvs2 = attributes.uv2 !== undefined ? attributes.uv2.array : undefined;
  5920. if ( uvs2 !== undefined ) this.faceVertexUvs[ 1 ] = [];
  5921. var tempNormals = [];
  5922. var tempUVs = [];
  5923. var tempUVs2 = [];
  5924. for ( var i = 0, j = 0; i < positions.length; i += 3, j += 2 ) {
  5925. scope.vertices.push( new THREE.Vector3( positions[ i ], positions[ i + 1 ], positions[ i + 2 ] ) );
  5926. if ( normals !== undefined ) {
  5927. tempNormals.push( new THREE.Vector3( normals[ i ], normals[ i + 1 ], normals[ i + 2 ] ) );
  5928. }
  5929. if ( colors !== undefined ) {
  5930. scope.colors.push( new THREE.Color( colors[ i ], colors[ i + 1 ], colors[ i + 2 ] ) );
  5931. }
  5932. if ( uvs !== undefined ) {
  5933. tempUVs.push( new THREE.Vector2( uvs[ j ], uvs[ j + 1 ] ) );
  5934. }
  5935. if ( uvs2 !== undefined ) {
  5936. tempUVs2.push( new THREE.Vector2( uvs2[ j ], uvs2[ j + 1 ] ) );
  5937. }
  5938. }
  5939. function addFace( a, b, c, materialIndex ) {
  5940. var vertexNormals = normals !== undefined ? [ tempNormals[ a ].clone(), tempNormals[ b ].clone(), tempNormals[ c ].clone() ] : [];
  5941. var vertexColors = colors !== undefined ? [ scope.colors[ a ].clone(), scope.colors[ b ].clone(), scope.colors[ c ].clone() ] : [];
  5942. var face = new THREE.Face3( a, b, c, vertexNormals, vertexColors, materialIndex );
  5943. scope.faces.push( face );
  5944. if ( uvs !== undefined ) {
  5945. scope.faceVertexUvs[ 0 ].push( [ tempUVs[ a ].clone(), tempUVs[ b ].clone(), tempUVs[ c ].clone() ] );
  5946. }
  5947. if ( uvs2 !== undefined ) {
  5948. scope.faceVertexUvs[ 1 ].push( [ tempUVs2[ a ].clone(), tempUVs2[ b ].clone(), tempUVs2[ c ].clone() ] );
  5949. }
  5950. }
  5951. if ( indices !== undefined ) {
  5952. var groups = geometry.groups;
  5953. if ( groups.length > 0 ) {
  5954. for ( var i = 0; i < groups.length; i ++ ) {
  5955. var group = groups[ i ];
  5956. var start = group.start;
  5957. var count = group.count;
  5958. for ( var j = start, jl = start + count; j < jl; j += 3 ) {
  5959. addFace( indices[ j ], indices[ j + 1 ], indices[ j + 2 ], group.materialIndex );
  5960. }
  5961. }
  5962. } else {
  5963. for ( var i = 0; i < indices.length; i += 3 ) {
  5964. addFace( indices[ i ], indices[ i + 1 ], indices[ i + 2 ] );
  5965. }
  5966. }
  5967. } else {
  5968. for ( var i = 0; i < positions.length / 3; i += 3 ) {
  5969. addFace( i, i + 1, i + 2 );
  5970. }
  5971. }
  5972. this.computeFaceNormals();
  5973. if ( geometry.boundingBox !== null ) {
  5974. this.boundingBox = geometry.boundingBox.clone();
  5975. }
  5976. if ( geometry.boundingSphere !== null ) {
  5977. this.boundingSphere = geometry.boundingSphere.clone();
  5978. }
  5979. return this;
  5980. },
  5981. center: function () {
  5982. this.computeBoundingBox();
  5983. var offset = this.boundingBox.center().negate();
  5984. this.translate( offset.x, offset.y, offset.z );
  5985. return offset;
  5986. },
  5987. normalize: function () {
  5988. this.computeBoundingSphere();
  5989. var center = this.boundingSphere.center;
  5990. var radius = this.boundingSphere.radius;
  5991. var s = radius === 0 ? 1 : 1.0 / radius;
  5992. var matrix = new THREE.Matrix4();
  5993. matrix.set(
  5994. s, 0, 0, - s * center.x,
  5995. 0, s, 0, - s * center.y,
  5996. 0, 0, s, - s * center.z,
  5997. 0, 0, 0, 1
  5998. );
  5999. this.applyMatrix( matrix );
  6000. return this;
  6001. },
  6002. computeFaceNormals: function () {
  6003. var cb = new THREE.Vector3(), ab = new THREE.Vector3();
  6004. for ( var f = 0, fl = this.faces.length; f < fl; f ++ ) {
  6005. var face = this.faces[ f ];
  6006. var vA = this.vertices[ face.a ];
  6007. var vB = this.vertices[ face.b ];
  6008. var vC = this.vertices[ face.c ];
  6009. cb.subVectors( vC, vB );
  6010. ab.subVectors( vA, vB );
  6011. cb.cross( ab );
  6012. cb.normalize();
  6013. face.normal.copy( cb );
  6014. }
  6015. },
  6016. computeVertexNormals: function ( areaWeighted ) {
  6017. if ( areaWeighted === undefined ) areaWeighted = true;
  6018. var v, vl, f, fl, face, vertices;
  6019. vertices = new Array( this.vertices.length );
  6020. for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) {
  6021. vertices[ v ] = new THREE.Vector3();
  6022. }
  6023. if ( areaWeighted ) {
  6024. // vertex normals weighted by triangle areas
  6025. // http://www.iquilezles.org/www/articles/normals/normals.htm
  6026. var vA, vB, vC;
  6027. var cb = new THREE.Vector3(), ab = new THREE.Vector3();
  6028. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  6029. face = this.faces[ f ];
  6030. vA = this.vertices[ face.a ];
  6031. vB = this.vertices[ face.b ];
  6032. vC = this.vertices[ face.c ];
  6033. cb.subVectors( vC, vB );
  6034. ab.subVectors( vA, vB );
  6035. cb.cross( ab );
  6036. vertices[ face.a ].add( cb );
  6037. vertices[ face.b ].add( cb );
  6038. vertices[ face.c ].add( cb );
  6039. }
  6040. } else {
  6041. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  6042. face = this.faces[ f ];
  6043. vertices[ face.a ].add( face.normal );
  6044. vertices[ face.b ].add( face.normal );
  6045. vertices[ face.c ].add( face.normal );
  6046. }
  6047. }
  6048. for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) {
  6049. vertices[ v ].normalize();
  6050. }
  6051. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  6052. face = this.faces[ f ];
  6053. var vertexNormals = face.vertexNormals;
  6054. if ( vertexNormals.length === 3 ) {
  6055. vertexNormals[ 0 ].copy( vertices[ face.a ] );
  6056. vertexNormals[ 1 ].copy( vertices[ face.b ] );
  6057. vertexNormals[ 2 ].copy( vertices[ face.c ] );
  6058. } else {
  6059. vertexNormals[ 0 ] = vertices[ face.a ].clone();
  6060. vertexNormals[ 1 ] = vertices[ face.b ].clone();
  6061. vertexNormals[ 2 ] = vertices[ face.c ].clone();
  6062. }
  6063. }
  6064. if ( this.faces.length > 0 ) {
  6065. this.normalsNeedUpdate = true;
  6066. }
  6067. },
  6068. computeMorphNormals: function () {
  6069. var i, il, f, fl, face;
  6070. // save original normals
  6071. // - create temp variables on first access
  6072. // otherwise just copy (for faster repeated calls)
  6073. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  6074. face = this.faces[ f ];
  6075. if ( ! face.__originalFaceNormal ) {
  6076. face.__originalFaceNormal = face.normal.clone();
  6077. } else {
  6078. face.__originalFaceNormal.copy( face.normal );
  6079. }
  6080. if ( ! face.__originalVertexNormals ) face.__originalVertexNormals = [];
  6081. for ( i = 0, il = face.vertexNormals.length; i < il; i ++ ) {
  6082. if ( ! face.__originalVertexNormals[ i ] ) {
  6083. face.__originalVertexNormals[ i ] = face.vertexNormals[ i ].clone();
  6084. } else {
  6085. face.__originalVertexNormals[ i ].copy( face.vertexNormals[ i ] );
  6086. }
  6087. }
  6088. }
  6089. // use temp geometry to compute face and vertex normals for each morph
  6090. var tmpGeo = new THREE.Geometry();
  6091. tmpGeo.faces = this.faces;
  6092. for ( i = 0, il = this.morphTargets.length; i < il; i ++ ) {
  6093. // create on first access
  6094. if ( ! this.morphNormals[ i ] ) {
  6095. this.morphNormals[ i ] = {};
  6096. this.morphNormals[ i ].faceNormals = [];
  6097. this.morphNormals[ i ].vertexNormals = [];
  6098. var dstNormalsFace = this.morphNormals[ i ].faceNormals;
  6099. var dstNormalsVertex = this.morphNormals[ i ].vertexNormals;
  6100. var faceNormal, vertexNormals;
  6101. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  6102. faceNormal = new THREE.Vector3();
  6103. vertexNormals = { a: new THREE.Vector3(), b: new THREE.Vector3(), c: new THREE.Vector3() };
  6104. dstNormalsFace.push( faceNormal );
  6105. dstNormalsVertex.push( vertexNormals );
  6106. }
  6107. }
  6108. var morphNormals = this.morphNormals[ i ];
  6109. // set vertices to morph target
  6110. tmpGeo.vertices = this.morphTargets[ i ].vertices;
  6111. // compute morph normals
  6112. tmpGeo.computeFaceNormals();
  6113. tmpGeo.computeVertexNormals();
  6114. // store morph normals
  6115. var faceNormal, vertexNormals;
  6116. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  6117. face = this.faces[ f ];
  6118. faceNormal = morphNormals.faceNormals[ f ];
  6119. vertexNormals = morphNormals.vertexNormals[ f ];
  6120. faceNormal.copy( face.normal );
  6121. vertexNormals.a.copy( face.vertexNormals[ 0 ] );
  6122. vertexNormals.b.copy( face.vertexNormals[ 1 ] );
  6123. vertexNormals.c.copy( face.vertexNormals[ 2 ] );
  6124. }
  6125. }
  6126. // restore original normals
  6127. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  6128. face = this.faces[ f ];
  6129. face.normal = face.__originalFaceNormal;
  6130. face.vertexNormals = face.__originalVertexNormals;
  6131. }
  6132. },
  6133. computeTangents: function () {
  6134. console.warn( 'THREE.Geometry: .computeTangents() has been removed.' );
  6135. },
  6136. computeLineDistances: function () {
  6137. var d = 0;
  6138. var vertices = this.vertices;
  6139. for ( var i = 0, il = vertices.length; i < il; i ++ ) {
  6140. if ( i > 0 ) {
  6141. d += vertices[ i ].distanceTo( vertices[ i - 1 ] );
  6142. }
  6143. this.lineDistances[ i ] = d;
  6144. }
  6145. },
  6146. computeBoundingBox: function () {
  6147. if ( this.boundingBox === null ) {
  6148. this.boundingBox = new THREE.Box3();
  6149. }
  6150. this.boundingBox.setFromPoints( this.vertices );
  6151. },
  6152. computeBoundingSphere: function () {
  6153. if ( this.boundingSphere === null ) {
  6154. this.boundingSphere = new THREE.Sphere();
  6155. }
  6156. this.boundingSphere.setFromPoints( this.vertices );
  6157. },
  6158. merge: function ( geometry, matrix, materialIndexOffset ) {
  6159. if ( geometry instanceof THREE.Geometry === false ) {
  6160. console.error( 'THREE.Geometry.merge(): geometry not an instance of THREE.Geometry.', geometry );
  6161. return;
  6162. }
  6163. var normalMatrix,
  6164. vertexOffset = this.vertices.length,
  6165. vertices1 = this.vertices,
  6166. vertices2 = geometry.vertices,
  6167. faces1 = this.faces,
  6168. faces2 = geometry.faces,
  6169. uvs1 = this.faceVertexUvs[ 0 ],
  6170. uvs2 = geometry.faceVertexUvs[ 0 ];
  6171. if ( materialIndexOffset === undefined ) materialIndexOffset = 0;
  6172. if ( matrix !== undefined ) {
  6173. normalMatrix = new THREE.Matrix3().getNormalMatrix( matrix );
  6174. }
  6175. // vertices
  6176. for ( var i = 0, il = vertices2.length; i < il; i ++ ) {
  6177. var vertex = vertices2[ i ];
  6178. var vertexCopy = vertex.clone();
  6179. if ( matrix !== undefined ) vertexCopy.applyMatrix4( matrix );
  6180. vertices1.push( vertexCopy );
  6181. }
  6182. // faces
  6183. for ( i = 0, il = faces2.length; i < il; i ++ ) {
  6184. var face = faces2[ i ], faceCopy, normal, color,
  6185. faceVertexNormals = face.vertexNormals,
  6186. faceVertexColors = face.vertexColors;
  6187. faceCopy = new THREE.Face3( face.a + vertexOffset, face.b + vertexOffset, face.c + vertexOffset );
  6188. faceCopy.normal.copy( face.normal );
  6189. if ( normalMatrix !== undefined ) {
  6190. faceCopy.normal.applyMatrix3( normalMatrix ).normalize();
  6191. }
  6192. for ( var j = 0, jl = faceVertexNormals.length; j < jl; j ++ ) {
  6193. normal = faceVertexNormals[ j ].clone();
  6194. if ( normalMatrix !== undefined ) {
  6195. normal.applyMatrix3( normalMatrix ).normalize();
  6196. }
  6197. faceCopy.vertexNormals.push( normal );
  6198. }
  6199. faceCopy.color.copy( face.color );
  6200. for ( var j = 0, jl = faceVertexColors.length; j < jl; j ++ ) {
  6201. color = faceVertexColors[ j ];
  6202. faceCopy.vertexColors.push( color.clone() );
  6203. }
  6204. faceCopy.materialIndex = face.materialIndex + materialIndexOffset;
  6205. faces1.push( faceCopy );
  6206. }
  6207. // uvs
  6208. for ( i = 0, il = uvs2.length; i < il; i ++ ) {
  6209. var uv = uvs2[ i ], uvCopy = [];
  6210. if ( uv === undefined ) {
  6211. continue;
  6212. }
  6213. for ( var j = 0, jl = uv.length; j < jl; j ++ ) {
  6214. uvCopy.push( uv[ j ].clone() );
  6215. }
  6216. uvs1.push( uvCopy );
  6217. }
  6218. },
  6219. mergeMesh: function ( mesh ) {
  6220. if ( mesh instanceof THREE.Mesh === false ) {
  6221. console.error( 'THREE.Geometry.mergeMesh(): mesh not an instance of THREE.Mesh.', mesh );
  6222. return;
  6223. }
  6224. mesh.matrixAutoUpdate && mesh.updateMatrix();
  6225. this.merge( mesh.geometry, mesh.matrix );
  6226. },
  6227. /*
  6228. * Checks for duplicate vertices with hashmap.
  6229. * Duplicated vertices are removed
  6230. * and faces' vertices are updated.
  6231. */
  6232. mergeVertices: function () {
  6233. var verticesMap = {}; // Hashmap for looking up vertices by position coordinates (and making sure they are unique)
  6234. var unique = [], changes = [];
  6235. var v, key;
  6236. var precisionPoints = 4; // number of decimal points, e.g. 4 for epsilon of 0.0001
  6237. var precision = Math.pow( 10, precisionPoints );
  6238. var i, il, face;
  6239. var indices, j, jl;
  6240. for ( i = 0, il = this.vertices.length; i < il; i ++ ) {
  6241. v = this.vertices[ i ];
  6242. key = Math.round( v.x * precision ) + '_' + Math.round( v.y * precision ) + '_' + Math.round( v.z * precision );
  6243. if ( verticesMap[ key ] === undefined ) {
  6244. verticesMap[ key ] = i;
  6245. unique.push( this.vertices[ i ] );
  6246. changes[ i ] = unique.length - 1;
  6247. } else {
  6248. //console.log('Duplicate vertex found. ', i, ' could be using ', verticesMap[key]);
  6249. changes[ i ] = changes[ verticesMap[ key ] ];
  6250. }
  6251. }
  6252. // if faces are completely degenerate after merging vertices, we
  6253. // have to remove them from the geometry.
  6254. var faceIndicesToRemove = [];
  6255. for ( i = 0, il = this.faces.length; i < il; i ++ ) {
  6256. face = this.faces[ i ];
  6257. face.a = changes[ face.a ];
  6258. face.b = changes[ face.b ];
  6259. face.c = changes[ face.c ];
  6260. indices = [ face.a, face.b, face.c ];
  6261. var dupIndex = - 1;
  6262. // if any duplicate vertices are found in a Face3
  6263. // we have to remove the face as nothing can be saved
  6264. for ( var n = 0; n < 3; n ++ ) {
  6265. if ( indices[ n ] === indices[ ( n + 1 ) % 3 ] ) {
  6266. dupIndex = n;
  6267. faceIndicesToRemove.push( i );
  6268. break;
  6269. }
  6270. }
  6271. }
  6272. for ( i = faceIndicesToRemove.length - 1; i >= 0; i -- ) {
  6273. var idx = faceIndicesToRemove[ i ];
  6274. this.faces.splice( idx, 1 );
  6275. for ( j = 0, jl = this.faceVertexUvs.length; j < jl; j ++ ) {
  6276. this.faceVertexUvs[ j ].splice( idx, 1 );
  6277. }
  6278. }
  6279. // Use unique set of vertices
  6280. var diff = this.vertices.length - unique.length;
  6281. this.vertices = unique;
  6282. return diff;
  6283. },
  6284. sortFacesByMaterialIndex: function () {
  6285. var faces = this.faces;
  6286. var length = faces.length;
  6287. // tag faces
  6288. for ( var i = 0; i < length; i ++ ) {
  6289. faces[ i ]._id = i;
  6290. }
  6291. // sort faces
  6292. function materialIndexSort( a, b ) {
  6293. return a.materialIndex - b.materialIndex;
  6294. }
  6295. faces.sort( materialIndexSort );
  6296. // sort uvs
  6297. var uvs1 = this.faceVertexUvs[ 0 ];
  6298. var uvs2 = this.faceVertexUvs[ 1 ];
  6299. var newUvs1, newUvs2;
  6300. if ( uvs1 && uvs1.length === length ) newUvs1 = [];
  6301. if ( uvs2 && uvs2.length === length ) newUvs2 = [];
  6302. for ( var i = 0; i < length; i ++ ) {
  6303. var id = faces[ i ]._id;
  6304. if ( newUvs1 ) newUvs1.push( uvs1[ id ] );
  6305. if ( newUvs2 ) newUvs2.push( uvs2[ id ] );
  6306. }
  6307. if ( newUvs1 ) this.faceVertexUvs[ 0 ] = newUvs1;
  6308. if ( newUvs2 ) this.faceVertexUvs[ 1 ] = newUvs2;
  6309. },
  6310. toJSON: function () {
  6311. var data = {
  6312. metadata: {
  6313. version: 4.4,
  6314. type: 'Geometry',
  6315. generator: 'Geometry.toJSON'
  6316. }
  6317. };
  6318. // standard Geometry serialization
  6319. data.uuid = this.uuid;
  6320. data.type = this.type;
  6321. if ( this.name !== '' ) data.name = this.name;
  6322. if ( this.parameters !== undefined ) {
  6323. var parameters = this.parameters;
  6324. for ( var key in parameters ) {
  6325. if ( parameters[ key ] !== undefined ) data[ key ] = parameters[ key ];
  6326. }
  6327. return data;
  6328. }
  6329. var vertices = [];
  6330. for ( var i = 0; i < this.vertices.length; i ++ ) {
  6331. var vertex = this.vertices[ i ];
  6332. vertices.push( vertex.x, vertex.y, vertex.z );
  6333. }
  6334. var faces = [];
  6335. var normals = [];
  6336. var normalsHash = {};
  6337. var colors = [];
  6338. var colorsHash = {};
  6339. var uvs = [];
  6340. var uvsHash = {};
  6341. for ( var i = 0; i < this.faces.length; i ++ ) {
  6342. var face = this.faces[ i ];
  6343. var hasMaterial = true;
  6344. var hasFaceUv = false; // deprecated
  6345. var hasFaceVertexUv = this.faceVertexUvs[ 0 ][ i ] !== undefined;
  6346. var hasFaceNormal = face.normal.length() > 0;
  6347. var hasFaceVertexNormal = face.vertexNormals.length > 0;
  6348. var hasFaceColor = face.color.r !== 1 || face.color.g !== 1 || face.color.b !== 1;
  6349. var hasFaceVertexColor = face.vertexColors.length > 0;
  6350. var faceType = 0;
  6351. faceType = setBit( faceType, 0, 0 ); // isQuad
  6352. faceType = setBit( faceType, 1, hasMaterial );
  6353. faceType = setBit( faceType, 2, hasFaceUv );
  6354. faceType = setBit( faceType, 3, hasFaceVertexUv );
  6355. faceType = setBit( faceType, 4, hasFaceNormal );
  6356. faceType = setBit( faceType, 5, hasFaceVertexNormal );
  6357. faceType = setBit( faceType, 6, hasFaceColor );
  6358. faceType = setBit( faceType, 7, hasFaceVertexColor );
  6359. faces.push( faceType );
  6360. faces.push( face.a, face.b, face.c );
  6361. faces.push( face.materialIndex );
  6362. if ( hasFaceVertexUv ) {
  6363. var faceVertexUvs = this.faceVertexUvs[ 0 ][ i ];
  6364. faces.push(
  6365. getUvIndex( faceVertexUvs[ 0 ] ),
  6366. getUvIndex( faceVertexUvs[ 1 ] ),
  6367. getUvIndex( faceVertexUvs[ 2 ] )
  6368. );
  6369. }
  6370. if ( hasFaceNormal ) {
  6371. faces.push( getNormalIndex( face.normal ) );
  6372. }
  6373. if ( hasFaceVertexNormal ) {
  6374. var vertexNormals = face.vertexNormals;
  6375. faces.push(
  6376. getNormalIndex( vertexNormals[ 0 ] ),
  6377. getNormalIndex( vertexNormals[ 1 ] ),
  6378. getNormalIndex( vertexNormals[ 2 ] )
  6379. );
  6380. }
  6381. if ( hasFaceColor ) {
  6382. faces.push( getColorIndex( face.color ) );
  6383. }
  6384. if ( hasFaceVertexColor ) {
  6385. var vertexColors = face.vertexColors;
  6386. faces.push(
  6387. getColorIndex( vertexColors[ 0 ] ),
  6388. getColorIndex( vertexColors[ 1 ] ),
  6389. getColorIndex( vertexColors[ 2 ] )
  6390. );
  6391. }
  6392. }
  6393. function setBit( value, position, enabled ) {
  6394. return enabled ? value | ( 1 << position ) : value & ( ~ ( 1 << position ) );
  6395. }
  6396. function getNormalIndex( normal ) {
  6397. var hash = normal.x.toString() + normal.y.toString() + normal.z.toString();
  6398. if ( normalsHash[ hash ] !== undefined ) {
  6399. return normalsHash[ hash ];
  6400. }
  6401. normalsHash[ hash ] = normals.length / 3;
  6402. normals.push( normal.x, normal.y, normal.z );
  6403. return normalsHash[ hash ];
  6404. }
  6405. function getColorIndex( color ) {
  6406. var hash = color.r.toString() + color.g.toString() + color.b.toString();
  6407. if ( colorsHash[ hash ] !== undefined ) {
  6408. return colorsHash[ hash ];
  6409. }
  6410. colorsHash[ hash ] = colors.length;
  6411. colors.push( color.getHex() );
  6412. return colorsHash[ hash ];
  6413. }
  6414. function getUvIndex( uv ) {
  6415. var hash = uv.x.toString() + uv.y.toString();
  6416. if ( uvsHash[ hash ] !== undefined ) {
  6417. return uvsHash[ hash ];
  6418. }
  6419. uvsHash[ hash ] = uvs.length / 2;
  6420. uvs.push( uv.x, uv.y );
  6421. return uvsHash[ hash ];
  6422. }
  6423. data.data = {};
  6424. data.data.vertices = vertices;
  6425. data.data.normals = normals;
  6426. if ( colors.length > 0 ) data.data.colors = colors;
  6427. if ( uvs.length > 0 ) data.data.uvs = [ uvs ]; // temporal backward compatibility
  6428. data.data.faces = faces;
  6429. return data;
  6430. },
  6431. clone: function () {
  6432. /*
  6433. // Handle primitives
  6434. var parameters = this.parameters;
  6435. if ( parameters !== undefined ) {
  6436. var values = [];
  6437. for ( var key in parameters ) {
  6438. values.push( parameters[ key ] );
  6439. }
  6440. var geometry = Object.create( this.constructor.prototype );
  6441. this.constructor.apply( geometry, values );
  6442. return geometry;
  6443. }
  6444. return new this.constructor().copy( this );
  6445. */
  6446. return new THREE.Geometry().copy( this );
  6447. },
  6448. copy: function ( source ) {
  6449. this.vertices = [];
  6450. this.faces = [];
  6451. this.faceVertexUvs = [ [] ];
  6452. var vertices = source.vertices;
  6453. for ( var i = 0, il = vertices.length; i < il; i ++ ) {
  6454. this.vertices.push( vertices[ i ].clone() );
  6455. }
  6456. var faces = source.faces;
  6457. for ( var i = 0, il = faces.length; i < il; i ++ ) {
  6458. this.faces.push( faces[ i ].clone() );
  6459. }
  6460. for ( var i = 0, il = source.faceVertexUvs.length; i < il; i ++ ) {
  6461. var faceVertexUvs = source.faceVertexUvs[ i ];
  6462. if ( this.faceVertexUvs[ i ] === undefined ) {
  6463. this.faceVertexUvs[ i ] = [];
  6464. }
  6465. for ( var j = 0, jl = faceVertexUvs.length; j < jl; j ++ ) {
  6466. var uvs = faceVertexUvs[ j ], uvsCopy = [];
  6467. for ( var k = 0, kl = uvs.length; k < kl; k ++ ) {
  6468. var uv = uvs[ k ];
  6469. uvsCopy.push( uv.clone() );
  6470. }
  6471. this.faceVertexUvs[ i ].push( uvsCopy );
  6472. }
  6473. }
  6474. return this;
  6475. },
  6476. dispose: function () {
  6477. this.dispatchEvent( { type: 'dispose' } );
  6478. }
  6479. } );
  6480. THREE.GeometryIdCount = 0;
  6481. // File:src/core/DirectGeometry.js
  6482. /**
  6483. * @author mrdoob / http://mrdoob.com/
  6484. */
  6485. THREE.DirectGeometry = function () {
  6486. Object.defineProperty( this, 'id', { value: THREE.GeometryIdCount ++ } );
  6487. this.uuid = THREE.Math.generateUUID();
  6488. this.name = '';
  6489. this.type = 'DirectGeometry';
  6490. this.indices = [];
  6491. this.vertices = [];
  6492. this.normals = [];
  6493. this.colors = [];
  6494. this.uvs = [];
  6495. this.uvs2 = [];
  6496. this.groups = [];
  6497. this.morphTargets = {};
  6498. this.skinWeights = [];
  6499. this.skinIndices = [];
  6500. // this.lineDistances = [];
  6501. this.boundingBox = null;
  6502. this.boundingSphere = null;
  6503. // update flags
  6504. this.verticesNeedUpdate = false;
  6505. this.normalsNeedUpdate = false;
  6506. this.colorsNeedUpdate = false;
  6507. this.uvsNeedUpdate = false;
  6508. this.groupsNeedUpdate = false;
  6509. };
  6510. Object.assign( THREE.DirectGeometry.prototype, THREE.EventDispatcher.prototype, {
  6511. computeBoundingBox: THREE.Geometry.prototype.computeBoundingBox,
  6512. computeBoundingSphere: THREE.Geometry.prototype.computeBoundingSphere,
  6513. computeFaceNormals: function () {
  6514. console.warn( 'THREE.DirectGeometry: computeFaceNormals() is not a method of this type of geometry.' );
  6515. },
  6516. computeVertexNormals: function () {
  6517. console.warn( 'THREE.DirectGeometry: computeVertexNormals() is not a method of this type of geometry.' );
  6518. },
  6519. computeGroups: function ( geometry ) {
  6520. var group;
  6521. var groups = [];
  6522. var materialIndex;
  6523. var faces = geometry.faces;
  6524. for ( var i = 0; i < faces.length; i ++ ) {
  6525. var face = faces[ i ];
  6526. // materials
  6527. if ( face.materialIndex !== materialIndex ) {
  6528. materialIndex = face.materialIndex;
  6529. if ( group !== undefined ) {
  6530. group.count = ( i * 3 ) - group.start;
  6531. groups.push( group );
  6532. }
  6533. group = {
  6534. start: i * 3,
  6535. materialIndex: materialIndex
  6536. };
  6537. }
  6538. }
  6539. if ( group !== undefined ) {
  6540. group.count = ( i * 3 ) - group.start;
  6541. groups.push( group );
  6542. }
  6543. this.groups = groups;
  6544. },
  6545. fromGeometry: function ( geometry ) {
  6546. var faces = geometry.faces;
  6547. var vertices = geometry.vertices;
  6548. var faceVertexUvs = geometry.faceVertexUvs;
  6549. var hasFaceVertexUv = faceVertexUvs[ 0 ] && faceVertexUvs[ 0 ].length > 0;
  6550. var hasFaceVertexUv2 = faceVertexUvs[ 1 ] && faceVertexUvs[ 1 ].length > 0;
  6551. // morphs
  6552. var morphTargets = geometry.morphTargets;
  6553. var morphTargetsLength = morphTargets.length;
  6554. var morphTargetsPosition;
  6555. if ( morphTargetsLength > 0 ) {
  6556. morphTargetsPosition = [];
  6557. for ( var i = 0; i < morphTargetsLength; i ++ ) {
  6558. morphTargetsPosition[ i ] = [];
  6559. }
  6560. this.morphTargets.position = morphTargetsPosition;
  6561. }
  6562. var morphNormals = geometry.morphNormals;
  6563. var morphNormalsLength = morphNormals.length;
  6564. var morphTargetsNormal;
  6565. if ( morphNormalsLength > 0 ) {
  6566. morphTargetsNormal = [];
  6567. for ( var i = 0; i < morphNormalsLength; i ++ ) {
  6568. morphTargetsNormal[ i ] = [];
  6569. }
  6570. this.morphTargets.normal = morphTargetsNormal;
  6571. }
  6572. // skins
  6573. var skinIndices = geometry.skinIndices;
  6574. var skinWeights = geometry.skinWeights;
  6575. var hasSkinIndices = skinIndices.length === vertices.length;
  6576. var hasSkinWeights = skinWeights.length === vertices.length;
  6577. //
  6578. for ( var i = 0; i < faces.length; i ++ ) {
  6579. var face = faces[ i ];
  6580. this.vertices.push( vertices[ face.a ], vertices[ face.b ], vertices[ face.c ] );
  6581. var vertexNormals = face.vertexNormals;
  6582. if ( vertexNormals.length === 3 ) {
  6583. this.normals.push( vertexNormals[ 0 ], vertexNormals[ 1 ], vertexNormals[ 2 ] );
  6584. } else {
  6585. var normal = face.normal;
  6586. this.normals.push( normal, normal, normal );
  6587. }
  6588. var vertexColors = face.vertexColors;
  6589. if ( vertexColors.length === 3 ) {
  6590. this.colors.push( vertexColors[ 0 ], vertexColors[ 1 ], vertexColors[ 2 ] );
  6591. } else {
  6592. var color = face.color;
  6593. this.colors.push( color, color, color );
  6594. }
  6595. if ( hasFaceVertexUv === true ) {
  6596. var vertexUvs = faceVertexUvs[ 0 ][ i ];
  6597. if ( vertexUvs !== undefined ) {
  6598. this.uvs.push( vertexUvs[ 0 ], vertexUvs[ 1 ], vertexUvs[ 2 ] );
  6599. } else {
  6600. console.warn( 'THREE.DirectGeometry.fromGeometry(): Undefined vertexUv ', i );
  6601. this.uvs.push( new THREE.Vector2(), new THREE.Vector2(), new THREE.Vector2() );
  6602. }
  6603. }
  6604. if ( hasFaceVertexUv2 === true ) {
  6605. var vertexUvs = faceVertexUvs[ 1 ][ i ];
  6606. if ( vertexUvs !== undefined ) {
  6607. this.uvs2.push( vertexUvs[ 0 ], vertexUvs[ 1 ], vertexUvs[ 2 ] );
  6608. } else {
  6609. console.warn( 'THREE.DirectGeometry.fromGeometry(): Undefined vertexUv2 ', i );
  6610. this.uvs2.push( new THREE.Vector2(), new THREE.Vector2(), new THREE.Vector2() );
  6611. }
  6612. }
  6613. // morphs
  6614. for ( var j = 0; j < morphTargetsLength; j ++ ) {
  6615. var morphTarget = morphTargets[ j ].vertices;
  6616. morphTargetsPosition[ j ].push( morphTarget[ face.a ], morphTarget[ face.b ], morphTarget[ face.c ] );
  6617. }
  6618. for ( var j = 0; j < morphNormalsLength; j ++ ) {
  6619. var morphNormal = morphNormals[ j ].vertexNormals[ i ];
  6620. morphTargetsNormal[ j ].push( morphNormal.a, morphNormal.b, morphNormal.c );
  6621. }
  6622. // skins
  6623. if ( hasSkinIndices ) {
  6624. this.skinIndices.push( skinIndices[ face.a ], skinIndices[ face.b ], skinIndices[ face.c ] );
  6625. }
  6626. if ( hasSkinWeights ) {
  6627. this.skinWeights.push( skinWeights[ face.a ], skinWeights[ face.b ], skinWeights[ face.c ] );
  6628. }
  6629. }
  6630. this.computeGroups( geometry );
  6631. this.verticesNeedUpdate = geometry.verticesNeedUpdate;
  6632. this.normalsNeedUpdate = geometry.normalsNeedUpdate;
  6633. this.colorsNeedUpdate = geometry.colorsNeedUpdate;
  6634. this.uvsNeedUpdate = geometry.uvsNeedUpdate;
  6635. this.groupsNeedUpdate = geometry.groupsNeedUpdate;
  6636. return this;
  6637. },
  6638. dispose: function () {
  6639. this.dispatchEvent( { type: 'dispose' } );
  6640. }
  6641. } );
  6642. // File:src/core/BufferGeometry.js
  6643. /**
  6644. * @author alteredq / http://alteredqualia.com/
  6645. * @author mrdoob / http://mrdoob.com/
  6646. */
  6647. THREE.BufferGeometry = function () {
  6648. Object.defineProperty( this, 'id', { value: THREE.GeometryIdCount ++ } );
  6649. this.uuid = THREE.Math.generateUUID();
  6650. this.name = '';
  6651. this.type = 'BufferGeometry';
  6652. this.index = null;
  6653. this.attributes = {};
  6654. this.morphAttributes = {};
  6655. this.groups = [];
  6656. this.boundingBox = null;
  6657. this.boundingSphere = null;
  6658. this.drawRange = { start: 0, count: Infinity };
  6659. };
  6660. Object.assign( THREE.BufferGeometry.prototype, THREE.EventDispatcher.prototype, {
  6661. getIndex: function () {
  6662. return this.index;
  6663. },
  6664. setIndex: function ( index ) {
  6665. this.index = index;
  6666. },
  6667. addAttribute: function ( name, attribute ) {
  6668. if ( attribute instanceof THREE.BufferAttribute === false && attribute instanceof THREE.InterleavedBufferAttribute === false ) {
  6669. console.warn( 'THREE.BufferGeometry: .addAttribute() now expects ( name, attribute ).' );
  6670. this.addAttribute( name, new THREE.BufferAttribute( arguments[ 1 ], arguments[ 2 ] ) );
  6671. return;
  6672. }
  6673. if ( name === 'index' ) {
  6674. console.warn( 'THREE.BufferGeometry.addAttribute: Use .setIndex() for index attribute.' );
  6675. this.setIndex( attribute );
  6676. return;
  6677. }
  6678. this.attributes[ name ] = attribute;
  6679. return this;
  6680. },
  6681. getAttribute: function ( name ) {
  6682. return this.attributes[ name ];
  6683. },
  6684. removeAttribute: function ( name ) {
  6685. delete this.attributes[ name ];
  6686. return this;
  6687. },
  6688. addGroup: function ( start, count, materialIndex ) {
  6689. this.groups.push( {
  6690. start: start,
  6691. count: count,
  6692. materialIndex: materialIndex !== undefined ? materialIndex : 0
  6693. } );
  6694. },
  6695. clearGroups: function () {
  6696. this.groups = [];
  6697. },
  6698. setDrawRange: function ( start, count ) {
  6699. this.drawRange.start = start;
  6700. this.drawRange.count = count;
  6701. },
  6702. applyMatrix: function ( matrix ) {
  6703. var position = this.attributes.position;
  6704. if ( position !== undefined ) {
  6705. matrix.applyToVector3Array( position.array );
  6706. position.needsUpdate = true;
  6707. }
  6708. var normal = this.attributes.normal;
  6709. if ( normal !== undefined ) {
  6710. var normalMatrix = new THREE.Matrix3().getNormalMatrix( matrix );
  6711. normalMatrix.applyToVector3Array( normal.array );
  6712. normal.needsUpdate = true;
  6713. }
  6714. if ( this.boundingBox !== null ) {
  6715. this.computeBoundingBox();
  6716. }
  6717. if ( this.boundingSphere !== null ) {
  6718. this.computeBoundingSphere();
  6719. }
  6720. return this;
  6721. },
  6722. rotateX: function () {
  6723. // rotate geometry around world x-axis
  6724. var m1;
  6725. return function rotateX( angle ) {
  6726. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  6727. m1.makeRotationX( angle );
  6728. this.applyMatrix( m1 );
  6729. return this;
  6730. };
  6731. }(),
  6732. rotateY: function () {
  6733. // rotate geometry around world y-axis
  6734. var m1;
  6735. return function rotateY( angle ) {
  6736. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  6737. m1.makeRotationY( angle );
  6738. this.applyMatrix( m1 );
  6739. return this;
  6740. };
  6741. }(),
  6742. rotateZ: function () {
  6743. // rotate geometry around world z-axis
  6744. var m1;
  6745. return function rotateZ( angle ) {
  6746. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  6747. m1.makeRotationZ( angle );
  6748. this.applyMatrix( m1 );
  6749. return this;
  6750. };
  6751. }(),
  6752. translate: function () {
  6753. // translate geometry
  6754. var m1;
  6755. return function translate( x, y, z ) {
  6756. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  6757. m1.makeTranslation( x, y, z );
  6758. this.applyMatrix( m1 );
  6759. return this;
  6760. };
  6761. }(),
  6762. scale: function () {
  6763. // scale geometry
  6764. var m1;
  6765. return function scale( x, y, z ) {
  6766. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  6767. m1.makeScale( x, y, z );
  6768. this.applyMatrix( m1 );
  6769. return this;
  6770. };
  6771. }(),
  6772. lookAt: function () {
  6773. var obj;
  6774. return function lookAt( vector ) {
  6775. if ( obj === undefined ) obj = new THREE.Object3D();
  6776. obj.lookAt( vector );
  6777. obj.updateMatrix();
  6778. this.applyMatrix( obj.matrix );
  6779. };
  6780. }(),
  6781. center: function () {
  6782. this.computeBoundingBox();
  6783. var offset = this.boundingBox.center().negate();
  6784. this.translate( offset.x, offset.y, offset.z );
  6785. return offset;
  6786. },
  6787. setFromObject: function ( object ) {
  6788. // console.log( 'THREE.BufferGeometry.setFromObject(). Converting', object, this );
  6789. var geometry = object.geometry;
  6790. if ( object instanceof THREE.Points || object instanceof THREE.Line ) {
  6791. var positions = new THREE.Float32Attribute( geometry.vertices.length * 3, 3 );
  6792. var colors = new THREE.Float32Attribute( geometry.colors.length * 3, 3 );
  6793. this.addAttribute( 'position', positions.copyVector3sArray( geometry.vertices ) );
  6794. this.addAttribute( 'color', colors.copyColorsArray( geometry.colors ) );
  6795. if ( geometry.lineDistances && geometry.lineDistances.length === geometry.vertices.length ) {
  6796. var lineDistances = new THREE.Float32Attribute( geometry.lineDistances.length, 1 );
  6797. this.addAttribute( 'lineDistance', lineDistances.copyArray( geometry.lineDistances ) );
  6798. }
  6799. if ( geometry.boundingSphere !== null ) {
  6800. this.boundingSphere = geometry.boundingSphere.clone();
  6801. }
  6802. if ( geometry.boundingBox !== null ) {
  6803. this.boundingBox = geometry.boundingBox.clone();
  6804. }
  6805. } else if ( object instanceof THREE.Mesh ) {
  6806. if ( geometry instanceof THREE.Geometry ) {
  6807. this.fromGeometry( geometry );
  6808. }
  6809. }
  6810. return this;
  6811. },
  6812. updateFromObject: function ( object ) {
  6813. var geometry = object.geometry;
  6814. if ( object instanceof THREE.Mesh ) {
  6815. var direct = geometry.__directGeometry;
  6816. if ( direct === undefined || geometry.elementsNeedUpdate === true ) {
  6817. return this.fromGeometry( geometry );
  6818. }
  6819. direct.verticesNeedUpdate = geometry.verticesNeedUpdate || geometry.elementsNeedUpdate;
  6820. direct.normalsNeedUpdate = geometry.normalsNeedUpdate || geometry.elementsNeedUpdate;
  6821. direct.colorsNeedUpdate = geometry.colorsNeedUpdate || geometry.elementsNeedUpdate;
  6822. direct.uvsNeedUpdate = geometry.uvsNeedUpdate || geometry.elementsNeedUpdate;
  6823. direct.groupsNeedUpdate = geometry.groupsNeedUpdate || geometry.elementsNeedUpdate;
  6824. geometry.elementsNeedUpdate = false;
  6825. geometry.verticesNeedUpdate = false;
  6826. geometry.normalsNeedUpdate = false;
  6827. geometry.colorsNeedUpdate = false;
  6828. geometry.uvsNeedUpdate = false;
  6829. geometry.groupsNeedUpdate = false;
  6830. geometry = direct;
  6831. }
  6832. var attribute;
  6833. if ( geometry.verticesNeedUpdate === true ) {
  6834. attribute = this.attributes.position;
  6835. if ( attribute !== undefined ) {
  6836. attribute.copyVector3sArray( geometry.vertices );
  6837. attribute.needsUpdate = true;
  6838. }
  6839. geometry.verticesNeedUpdate = false;
  6840. }
  6841. if ( geometry.normalsNeedUpdate === true ) {
  6842. attribute = this.attributes.normal;
  6843. if ( attribute !== undefined ) {
  6844. attribute.copyVector3sArray( geometry.normals );
  6845. attribute.needsUpdate = true;
  6846. }
  6847. geometry.normalsNeedUpdate = false;
  6848. }
  6849. if ( geometry.colorsNeedUpdate === true ) {
  6850. attribute = this.attributes.color;
  6851. if ( attribute !== undefined ) {
  6852. attribute.copyColorsArray( geometry.colors );
  6853. attribute.needsUpdate = true;
  6854. }
  6855. geometry.colorsNeedUpdate = false;
  6856. }
  6857. if ( geometry.uvsNeedUpdate ) {
  6858. attribute = this.attributes.uv;
  6859. if ( attribute !== undefined ) {
  6860. attribute.copyVector2sArray( geometry.uvs );
  6861. attribute.needsUpdate = true;
  6862. }
  6863. geometry.uvsNeedUpdate = false;
  6864. }
  6865. if ( geometry.lineDistancesNeedUpdate ) {
  6866. attribute = this.attributes.lineDistance;
  6867. if ( attribute !== undefined ) {
  6868. attribute.copyArray( geometry.lineDistances );
  6869. attribute.needsUpdate = true;
  6870. }
  6871. geometry.lineDistancesNeedUpdate = false;
  6872. }
  6873. if ( geometry.groupsNeedUpdate ) {
  6874. geometry.computeGroups( object.geometry );
  6875. this.groups = geometry.groups;
  6876. geometry.groupsNeedUpdate = false;
  6877. }
  6878. return this;
  6879. },
  6880. fromGeometry: function ( geometry ) {
  6881. geometry.__directGeometry = new THREE.DirectGeometry().fromGeometry( geometry );
  6882. return this.fromDirectGeometry( geometry.__directGeometry );
  6883. },
  6884. fromDirectGeometry: function ( geometry ) {
  6885. var positions = new Float32Array( geometry.vertices.length * 3 );
  6886. this.addAttribute( 'position', new THREE.BufferAttribute( positions, 3 ).copyVector3sArray( geometry.vertices ) );
  6887. if ( geometry.normals.length > 0 ) {
  6888. var normals = new Float32Array( geometry.normals.length * 3 );
  6889. this.addAttribute( 'normal', new THREE.BufferAttribute( normals, 3 ).copyVector3sArray( geometry.normals ) );
  6890. }
  6891. if ( geometry.colors.length > 0 ) {
  6892. var colors = new Float32Array( geometry.colors.length * 3 );
  6893. this.addAttribute( 'color', new THREE.BufferAttribute( colors, 3 ).copyColorsArray( geometry.colors ) );
  6894. }
  6895. if ( geometry.uvs.length > 0 ) {
  6896. var uvs = new Float32Array( geometry.uvs.length * 2 );
  6897. this.addAttribute( 'uv', new THREE.BufferAttribute( uvs, 2 ).copyVector2sArray( geometry.uvs ) );
  6898. }
  6899. if ( geometry.uvs2.length > 0 ) {
  6900. var uvs2 = new Float32Array( geometry.uvs2.length * 2 );
  6901. this.addAttribute( 'uv2', new THREE.BufferAttribute( uvs2, 2 ).copyVector2sArray( geometry.uvs2 ) );
  6902. }
  6903. if ( geometry.indices.length > 0 ) {
  6904. var TypeArray = geometry.vertices.length > 65535 ? Uint32Array : Uint16Array;
  6905. var indices = new TypeArray( geometry.indices.length * 3 );
  6906. this.setIndex( new THREE.BufferAttribute( indices, 1 ).copyIndicesArray( geometry.indices ) );
  6907. }
  6908. // groups
  6909. this.groups = geometry.groups;
  6910. // morphs
  6911. for ( var name in geometry.morphTargets ) {
  6912. var array = [];
  6913. var morphTargets = geometry.morphTargets[ name ];
  6914. for ( var i = 0, l = morphTargets.length; i < l; i ++ ) {
  6915. var morphTarget = morphTargets[ i ];
  6916. var attribute = new THREE.Float32Attribute( morphTarget.length * 3, 3 );
  6917. array.push( attribute.copyVector3sArray( morphTarget ) );
  6918. }
  6919. this.morphAttributes[ name ] = array;
  6920. }
  6921. // skinning
  6922. if ( geometry.skinIndices.length > 0 ) {
  6923. var skinIndices = new THREE.Float32Attribute( geometry.skinIndices.length * 4, 4 );
  6924. this.addAttribute( 'skinIndex', skinIndices.copyVector4sArray( geometry.skinIndices ) );
  6925. }
  6926. if ( geometry.skinWeights.length > 0 ) {
  6927. var skinWeights = new THREE.Float32Attribute( geometry.skinWeights.length * 4, 4 );
  6928. this.addAttribute( 'skinWeight', skinWeights.copyVector4sArray( geometry.skinWeights ) );
  6929. }
  6930. //
  6931. if ( geometry.boundingSphere !== null ) {
  6932. this.boundingSphere = geometry.boundingSphere.clone();
  6933. }
  6934. if ( geometry.boundingBox !== null ) {
  6935. this.boundingBox = geometry.boundingBox.clone();
  6936. }
  6937. return this;
  6938. },
  6939. computeBoundingBox: function () {
  6940. if ( this.boundingBox === null ) {
  6941. this.boundingBox = new THREE.Box3();
  6942. }
  6943. var positions = this.attributes.position.array;
  6944. if ( positions !== undefined ) {
  6945. this.boundingBox.setFromArray( positions );
  6946. } else {
  6947. this.boundingBox.makeEmpty();
  6948. }
  6949. if ( isNaN( this.boundingBox.min.x ) || isNaN( this.boundingBox.min.y ) || isNaN( this.boundingBox.min.z ) ) {
  6950. console.error( 'THREE.BufferGeometry.computeBoundingBox: Computed min/max have NaN values. The "position" attribute is likely to have NaN values.', this );
  6951. }
  6952. },
  6953. computeBoundingSphere: function () {
  6954. var box = new THREE.Box3();
  6955. var vector = new THREE.Vector3();
  6956. return function computeBoundingSphere() {
  6957. if ( this.boundingSphere === null ) {
  6958. this.boundingSphere = new THREE.Sphere();
  6959. }
  6960. var positions = this.attributes.position;
  6961. if ( positions ) {
  6962. var array = positions.array;
  6963. var center = this.boundingSphere.center;
  6964. box.setFromArray( array );
  6965. box.center( center );
  6966. // hoping to find a boundingSphere with a radius smaller than the
  6967. // boundingSphere of the boundingBox: sqrt(3) smaller in the best case
  6968. var maxRadiusSq = 0;
  6969. for ( var i = 0, il = array.length; i < il; i += 3 ) {
  6970. vector.fromArray( array, i );
  6971. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( vector ) );
  6972. }
  6973. this.boundingSphere.radius = Math.sqrt( maxRadiusSq );
  6974. if ( isNaN( this.boundingSphere.radius ) ) {
  6975. console.error( 'THREE.BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.', this );
  6976. }
  6977. }
  6978. };
  6979. }(),
  6980. computeFaceNormals: function () {
  6981. // backwards compatibility
  6982. },
  6983. computeVertexNormals: function () {
  6984. var index = this.index;
  6985. var attributes = this.attributes;
  6986. var groups = this.groups;
  6987. if ( attributes.position ) {
  6988. var positions = attributes.position.array;
  6989. if ( attributes.normal === undefined ) {
  6990. this.addAttribute( 'normal', new THREE.BufferAttribute( new Float32Array( positions.length ), 3 ) );
  6991. } else {
  6992. // reset existing normals to zero
  6993. var array = attributes.normal.array;
  6994. for ( var i = 0, il = array.length; i < il; i ++ ) {
  6995. array[ i ] = 0;
  6996. }
  6997. }
  6998. var normals = attributes.normal.array;
  6999. var vA, vB, vC,
  7000. pA = new THREE.Vector3(),
  7001. pB = new THREE.Vector3(),
  7002. pC = new THREE.Vector3(),
  7003. cb = new THREE.Vector3(),
  7004. ab = new THREE.Vector3();
  7005. // indexed elements
  7006. if ( index ) {
  7007. var indices = index.array;
  7008. if ( groups.length === 0 ) {
  7009. this.addGroup( 0, indices.length );
  7010. }
  7011. for ( var j = 0, jl = groups.length; j < jl; ++ j ) {
  7012. var group = groups[ j ];
  7013. var start = group.start;
  7014. var count = group.count;
  7015. for ( var i = start, il = start + count; i < il; i += 3 ) {
  7016. vA = indices[ i + 0 ] * 3;
  7017. vB = indices[ i + 1 ] * 3;
  7018. vC = indices[ i + 2 ] * 3;
  7019. pA.fromArray( positions, vA );
  7020. pB.fromArray( positions, vB );
  7021. pC.fromArray( positions, vC );
  7022. cb.subVectors( pC, pB );
  7023. ab.subVectors( pA, pB );
  7024. cb.cross( ab );
  7025. normals[ vA ] += cb.x;
  7026. normals[ vA + 1 ] += cb.y;
  7027. normals[ vA + 2 ] += cb.z;
  7028. normals[ vB ] += cb.x;
  7029. normals[ vB + 1 ] += cb.y;
  7030. normals[ vB + 2 ] += cb.z;
  7031. normals[ vC ] += cb.x;
  7032. normals[ vC + 1 ] += cb.y;
  7033. normals[ vC + 2 ] += cb.z;
  7034. }
  7035. }
  7036. } else {
  7037. // non-indexed elements (unconnected triangle soup)
  7038. for ( var i = 0, il = positions.length; i < il; i += 9 ) {
  7039. pA.fromArray( positions, i );
  7040. pB.fromArray( positions, i + 3 );
  7041. pC.fromArray( positions, i + 6 );
  7042. cb.subVectors( pC, pB );
  7043. ab.subVectors( pA, pB );
  7044. cb.cross( ab );
  7045. normals[ i ] = cb.x;
  7046. normals[ i + 1 ] = cb.y;
  7047. normals[ i + 2 ] = cb.z;
  7048. normals[ i + 3 ] = cb.x;
  7049. normals[ i + 4 ] = cb.y;
  7050. normals[ i + 5 ] = cb.z;
  7051. normals[ i + 6 ] = cb.x;
  7052. normals[ i + 7 ] = cb.y;
  7053. normals[ i + 8 ] = cb.z;
  7054. }
  7055. }
  7056. this.normalizeNormals();
  7057. attributes.normal.needsUpdate = true;
  7058. }
  7059. },
  7060. merge: function ( geometry, offset ) {
  7061. if ( geometry instanceof THREE.BufferGeometry === false ) {
  7062. console.error( 'THREE.BufferGeometry.merge(): geometry not an instance of THREE.BufferGeometry.', geometry );
  7063. return;
  7064. }
  7065. if ( offset === undefined ) offset = 0;
  7066. var attributes = this.attributes;
  7067. for ( var key in attributes ) {
  7068. if ( geometry.attributes[ key ] === undefined ) continue;
  7069. var attribute1 = attributes[ key ];
  7070. var attributeArray1 = attribute1.array;
  7071. var attribute2 = geometry.attributes[ key ];
  7072. var attributeArray2 = attribute2.array;
  7073. var attributeSize = attribute2.itemSize;
  7074. for ( var i = 0, j = attributeSize * offset; i < attributeArray2.length; i ++, j ++ ) {
  7075. attributeArray1[ j ] = attributeArray2[ i ];
  7076. }
  7077. }
  7078. return this;
  7079. },
  7080. normalizeNormals: function () {
  7081. var normals = this.attributes.normal.array;
  7082. var x, y, z, n;
  7083. for ( var i = 0, il = normals.length; i < il; i += 3 ) {
  7084. x = normals[ i ];
  7085. y = normals[ i + 1 ];
  7086. z = normals[ i + 2 ];
  7087. n = 1.0 / Math.sqrt( x * x + y * y + z * z );
  7088. normals[ i ] *= n;
  7089. normals[ i + 1 ] *= n;
  7090. normals[ i + 2 ] *= n;
  7091. }
  7092. },
  7093. toNonIndexed: function () {
  7094. if ( this.index === null ) {
  7095. console.warn( 'THREE.BufferGeometry.toNonIndexed(): Geometry is already non-indexed.' );
  7096. return this;
  7097. }
  7098. var geometry2 = new THREE.BufferGeometry();
  7099. var indices = this.index.array;
  7100. var attributes = this.attributes;
  7101. for ( var name in attributes ) {
  7102. var attribute = attributes[ name ];
  7103. var array = attribute.array;
  7104. var itemSize = attribute.itemSize;
  7105. var array2 = new array.constructor( indices.length * itemSize );
  7106. var index = 0, index2 = 0;
  7107. for ( var i = 0, l = indices.length; i < l; i ++ ) {
  7108. index = indices[ i ] * itemSize;
  7109. for ( var j = 0; j < itemSize; j ++ ) {
  7110. array2[ index2 ++ ] = array[ index ++ ];
  7111. }
  7112. }
  7113. geometry2.addAttribute( name, new THREE.BufferAttribute( array2, itemSize ) );
  7114. }
  7115. return geometry2;
  7116. },
  7117. toJSON: function () {
  7118. var data = {
  7119. metadata: {
  7120. version: 4.4,
  7121. type: 'BufferGeometry',
  7122. generator: 'BufferGeometry.toJSON'
  7123. }
  7124. };
  7125. // standard BufferGeometry serialization
  7126. data.uuid = this.uuid;
  7127. data.type = this.type;
  7128. if ( this.name !== '' ) data.name = this.name;
  7129. if ( this.parameters !== undefined ) {
  7130. var parameters = this.parameters;
  7131. for ( var key in parameters ) {
  7132. if ( parameters[ key ] !== undefined ) data[ key ] = parameters[ key ];
  7133. }
  7134. return data;
  7135. }
  7136. data.data = { attributes: {} };
  7137. var index = this.index;
  7138. if ( index !== null ) {
  7139. var array = Array.prototype.slice.call( index.array );
  7140. data.data.index = {
  7141. type: index.array.constructor.name,
  7142. array: array
  7143. };
  7144. }
  7145. var attributes = this.attributes;
  7146. for ( var key in attributes ) {
  7147. var attribute = attributes[ key ];
  7148. var array = Array.prototype.slice.call( attribute.array );
  7149. data.data.attributes[ key ] = {
  7150. itemSize: attribute.itemSize,
  7151. type: attribute.array.constructor.name,
  7152. array: array,
  7153. normalized: attribute.normalized
  7154. };
  7155. }
  7156. var groups = this.groups;
  7157. if ( groups.length > 0 ) {
  7158. data.data.groups = JSON.parse( JSON.stringify( groups ) );
  7159. }
  7160. var boundingSphere = this.boundingSphere;
  7161. if ( boundingSphere !== null ) {
  7162. data.data.boundingSphere = {
  7163. center: boundingSphere.center.toArray(),
  7164. radius: boundingSphere.radius
  7165. };
  7166. }
  7167. return data;
  7168. },
  7169. clone: function () {
  7170. /*
  7171. // Handle primitives
  7172. var parameters = this.parameters;
  7173. if ( parameters !== undefined ) {
  7174. var values = [];
  7175. for ( var key in parameters ) {
  7176. values.push( parameters[ key ] );
  7177. }
  7178. var geometry = Object.create( this.constructor.prototype );
  7179. this.constructor.apply( geometry, values );
  7180. return geometry;
  7181. }
  7182. return new this.constructor().copy( this );
  7183. */
  7184. return new THREE.BufferGeometry().copy( this );
  7185. },
  7186. copy: function ( source ) {
  7187. var index = source.index;
  7188. if ( index !== null ) {
  7189. this.setIndex( index.clone() );
  7190. }
  7191. var attributes = source.attributes;
  7192. for ( var name in attributes ) {
  7193. var attribute = attributes[ name ];
  7194. this.addAttribute( name, attribute.clone() );
  7195. }
  7196. var groups = source.groups;
  7197. for ( var i = 0, l = groups.length; i < l; i ++ ) {
  7198. var group = groups[ i ];
  7199. this.addGroup( group.start, group.count, group.materialIndex );
  7200. }
  7201. return this;
  7202. },
  7203. dispose: function () {
  7204. this.dispatchEvent( { type: 'dispose' } );
  7205. }
  7206. } );
  7207. THREE.BufferGeometry.MaxIndex = 65535;
  7208. // File:src/core/InstancedBufferGeometry.js
  7209. /**
  7210. * @author benaadams / https://twitter.com/ben_a_adams
  7211. */
  7212. THREE.InstancedBufferGeometry = function () {
  7213. THREE.BufferGeometry.call( this );
  7214. this.type = 'InstancedBufferGeometry';
  7215. this.maxInstancedCount = undefined;
  7216. };
  7217. THREE.InstancedBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  7218. THREE.InstancedBufferGeometry.prototype.constructor = THREE.InstancedBufferGeometry;
  7219. THREE.InstancedBufferGeometry.prototype.addGroup = function ( start, count, instances ) {
  7220. this.groups.push( {
  7221. start: start,
  7222. count: count,
  7223. instances: instances
  7224. } );
  7225. };
  7226. THREE.InstancedBufferGeometry.prototype.copy = function ( source ) {
  7227. var index = source.index;
  7228. if ( index !== null ) {
  7229. this.setIndex( index.clone() );
  7230. }
  7231. var attributes = source.attributes;
  7232. for ( var name in attributes ) {
  7233. var attribute = attributes[ name ];
  7234. this.addAttribute( name, attribute.clone() );
  7235. }
  7236. var groups = source.groups;
  7237. for ( var i = 0, l = groups.length; i < l; i ++ ) {
  7238. var group = groups[ i ];
  7239. this.addGroup( group.start, group.count, group.instances );
  7240. }
  7241. return this;
  7242. };
  7243. // File:src/core/Uniform.js
  7244. /**
  7245. * @author mrdoob / http://mrdoob.com/
  7246. */
  7247. THREE.Uniform = function ( value ) {
  7248. if ( typeof value === 'string' ) {
  7249. console.warn( 'THREE.Uniform: Type parameter is no longer needed.' );
  7250. value = arguments[ 1 ];
  7251. }
  7252. this.value = value;
  7253. this.dynamic = false;
  7254. };
  7255. THREE.Uniform.prototype = {
  7256. constructor: THREE.Uniform,
  7257. onUpdate: function ( callback ) {
  7258. this.dynamic = true;
  7259. this.onUpdateCallback = callback;
  7260. return this;
  7261. }
  7262. };
  7263. // File:src/animation/AnimationAction.js
  7264. /**
  7265. *
  7266. * Action provided by AnimationMixer for scheduling clip playback on specific
  7267. * objects.
  7268. *
  7269. * @author Ben Houston / http://clara.io/
  7270. * @author David Sarno / http://lighthaus.us/
  7271. * @author tschw
  7272. *
  7273. */
  7274. THREE.AnimationAction = function() {
  7275. throw new Error( "THREE.AnimationAction: " +
  7276. "Use mixer.clipAction for construction." );
  7277. };
  7278. THREE.AnimationAction._new =
  7279. function AnimationAction( mixer, clip, localRoot ) {
  7280. this._mixer = mixer;
  7281. this._clip = clip;
  7282. this._localRoot = localRoot || null;
  7283. var tracks = clip.tracks,
  7284. nTracks = tracks.length,
  7285. interpolants = new Array( nTracks );
  7286. var interpolantSettings = {
  7287. endingStart: THREE.ZeroCurvatureEnding,
  7288. endingEnd: THREE.ZeroCurvatureEnding
  7289. };
  7290. for ( var i = 0; i !== nTracks; ++ i ) {
  7291. var interpolant = tracks[ i ].createInterpolant( null );
  7292. interpolants[ i ] = interpolant;
  7293. interpolant.settings = interpolantSettings;
  7294. }
  7295. this._interpolantSettings = interpolantSettings;
  7296. this._interpolants = interpolants; // bound by the mixer
  7297. // inside: PropertyMixer (managed by the mixer)
  7298. this._propertyBindings = new Array( nTracks );
  7299. this._cacheIndex = null; // for the memory manager
  7300. this._byClipCacheIndex = null; // for the memory manager
  7301. this._timeScaleInterpolant = null;
  7302. this._weightInterpolant = null;
  7303. this.loop = THREE.LoopRepeat;
  7304. this._loopCount = -1;
  7305. // global mixer time when the action is to be started
  7306. // it's set back to 'null' upon start of the action
  7307. this._startTime = null;
  7308. // scaled local time of the action
  7309. // gets clamped or wrapped to 0..clip.duration according to loop
  7310. this.time = 0;
  7311. this.timeScale = 1;
  7312. this._effectiveTimeScale = 1;
  7313. this.weight = 1;
  7314. this._effectiveWeight = 1;
  7315. this.repetitions = Infinity; // no. of repetitions when looping
  7316. this.paused = false; // false -> zero effective time scale
  7317. this.enabled = true; // true -> zero effective weight
  7318. this.clampWhenFinished = false; // keep feeding the last frame?
  7319. this.zeroSlopeAtStart = true; // for smooth interpolation w/o separate
  7320. this.zeroSlopeAtEnd = true; // clips for start, loop and end
  7321. };
  7322. THREE.AnimationAction._new.prototype = {
  7323. constructor: THREE.AnimationAction._new,
  7324. // State & Scheduling
  7325. play: function() {
  7326. this._mixer._activateAction( this );
  7327. return this;
  7328. },
  7329. stop: function() {
  7330. this._mixer._deactivateAction( this );
  7331. return this.reset();
  7332. },
  7333. reset: function() {
  7334. this.paused = false;
  7335. this.enabled = true;
  7336. this.time = 0; // restart clip
  7337. this._loopCount = -1; // forget previous loops
  7338. this._startTime = null; // forget scheduling
  7339. return this.stopFading().stopWarping();
  7340. },
  7341. isRunning: function() {
  7342. var start = this._startTime;
  7343. return this.enabled && ! this.paused && this.timeScale !== 0 &&
  7344. this._startTime === null && this._mixer._isActiveAction( this );
  7345. },
  7346. // return true when play has been called
  7347. isScheduled: function() {
  7348. return this._mixer._isActiveAction( this );
  7349. },
  7350. startAt: function( time ) {
  7351. this._startTime = time;
  7352. return this;
  7353. },
  7354. setLoop: function( mode, repetitions ) {
  7355. this.loop = mode;
  7356. this.repetitions = repetitions;
  7357. return this;
  7358. },
  7359. // Weight
  7360. // set the weight stopping any scheduled fading
  7361. // although .enabled = false yields an effective weight of zero, this
  7362. // method does *not* change .enabled, because it would be confusing
  7363. setEffectiveWeight: function( weight ) {
  7364. this.weight = weight;
  7365. // note: same logic as when updated at runtime
  7366. this._effectiveWeight = this.enabled ? weight : 0;
  7367. return this.stopFading();
  7368. },
  7369. // return the weight considering fading and .enabled
  7370. getEffectiveWeight: function() {
  7371. return this._effectiveWeight;
  7372. },
  7373. fadeIn: function( duration ) {
  7374. return this._scheduleFading( duration, 0, 1 );
  7375. },
  7376. fadeOut: function( duration ) {
  7377. return this._scheduleFading( duration, 1, 0 );
  7378. },
  7379. crossFadeFrom: function( fadeOutAction, duration, warp ) {
  7380. var mixer = this._mixer;
  7381. fadeOutAction.fadeOut( duration );
  7382. this.fadeIn( duration );
  7383. if( warp ) {
  7384. var fadeInDuration = this._clip.duration,
  7385. fadeOutDuration = fadeOutAction._clip.duration,
  7386. startEndRatio = fadeOutDuration / fadeInDuration,
  7387. endStartRatio = fadeInDuration / fadeOutDuration;
  7388. fadeOutAction.warp( 1.0, startEndRatio, duration );
  7389. this.warp( endStartRatio, 1.0, duration );
  7390. }
  7391. return this;
  7392. },
  7393. crossFadeTo: function( fadeInAction, duration, warp ) {
  7394. return fadeInAction.crossFadeFrom( this, duration, warp );
  7395. },
  7396. stopFading: function() {
  7397. var weightInterpolant = this._weightInterpolant;
  7398. if ( weightInterpolant !== null ) {
  7399. this._weightInterpolant = null;
  7400. this._mixer._takeBackControlInterpolant( weightInterpolant );
  7401. }
  7402. return this;
  7403. },
  7404. // Time Scale Control
  7405. // set the weight stopping any scheduled warping
  7406. // although .paused = true yields an effective time scale of zero, this
  7407. // method does *not* change .paused, because it would be confusing
  7408. setEffectiveTimeScale: function( timeScale ) {
  7409. this.timeScale = timeScale;
  7410. this._effectiveTimeScale = this.paused ? 0 :timeScale;
  7411. return this.stopWarping();
  7412. },
  7413. // return the time scale considering warping and .paused
  7414. getEffectiveTimeScale: function() {
  7415. return this._effectiveTimeScale;
  7416. },
  7417. setDuration: function( duration ) {
  7418. this.timeScale = this._clip.duration / duration;
  7419. return this.stopWarping();
  7420. },
  7421. syncWith: function( action ) {
  7422. this.time = action.time;
  7423. this.timeScale = action.timeScale;
  7424. return this.stopWarping();
  7425. },
  7426. halt: function( duration ) {
  7427. return this.warp( this._effectiveTimeScale, 0, duration );
  7428. },
  7429. warp: function( startTimeScale, endTimeScale, duration ) {
  7430. var mixer = this._mixer, now = mixer.time,
  7431. interpolant = this._timeScaleInterpolant,
  7432. timeScale = this.timeScale;
  7433. if ( interpolant === null ) {
  7434. interpolant = mixer._lendControlInterpolant(),
  7435. this._timeScaleInterpolant = interpolant;
  7436. }
  7437. var times = interpolant.parameterPositions,
  7438. values = interpolant.sampleValues;
  7439. times[ 0 ] = now;
  7440. times[ 1 ] = now + duration;
  7441. values[ 0 ] = startTimeScale / timeScale;
  7442. values[ 1 ] = endTimeScale / timeScale;
  7443. return this;
  7444. },
  7445. stopWarping: function() {
  7446. var timeScaleInterpolant = this._timeScaleInterpolant;
  7447. if ( timeScaleInterpolant !== null ) {
  7448. this._timeScaleInterpolant = null;
  7449. this._mixer._takeBackControlInterpolant( timeScaleInterpolant );
  7450. }
  7451. return this;
  7452. },
  7453. // Object Accessors
  7454. getMixer: function() {
  7455. return this._mixer;
  7456. },
  7457. getClip: function() {
  7458. return this._clip;
  7459. },
  7460. getRoot: function() {
  7461. return this._localRoot || this._mixer._root;
  7462. },
  7463. // Interna
  7464. _update: function( time, deltaTime, timeDirection, accuIndex ) {
  7465. // called by the mixer
  7466. var startTime = this._startTime;
  7467. if ( startTime !== null ) {
  7468. // check for scheduled start of action
  7469. var timeRunning = ( time - startTime ) * timeDirection;
  7470. if ( timeRunning < 0 || timeDirection === 0 ) {
  7471. return; // yet to come / don't decide when delta = 0
  7472. }
  7473. // start
  7474. this._startTime = null; // unschedule
  7475. deltaTime = timeDirection * timeRunning;
  7476. }
  7477. // apply time scale and advance time
  7478. deltaTime *= this._updateTimeScale( time );
  7479. var clipTime = this._updateTime( deltaTime );
  7480. // note: _updateTime may disable the action resulting in
  7481. // an effective weight of 0
  7482. var weight = this._updateWeight( time );
  7483. if ( weight > 0 ) {
  7484. var interpolants = this._interpolants;
  7485. var propertyMixers = this._propertyBindings;
  7486. for ( var j = 0, m = interpolants.length; j !== m; ++ j ) {
  7487. interpolants[ j ].evaluate( clipTime );
  7488. propertyMixers[ j ].accumulate( accuIndex, weight );
  7489. }
  7490. }
  7491. },
  7492. _updateWeight: function( time ) {
  7493. var weight = 0;
  7494. if ( this.enabled ) {
  7495. weight = this.weight;
  7496. var interpolant = this._weightInterpolant;
  7497. if ( interpolant !== null ) {
  7498. var interpolantValue = interpolant.evaluate( time )[ 0 ];
  7499. weight *= interpolantValue;
  7500. if ( time > interpolant.parameterPositions[ 1 ] ) {
  7501. this.stopFading();
  7502. if ( interpolantValue === 0 ) {
  7503. // faded out, disable
  7504. this.enabled = false;
  7505. }
  7506. }
  7507. }
  7508. }
  7509. this._effectiveWeight = weight;
  7510. return weight;
  7511. },
  7512. _updateTimeScale: function( time ) {
  7513. var timeScale = 0;
  7514. if ( ! this.paused ) {
  7515. timeScale = this.timeScale;
  7516. var interpolant = this._timeScaleInterpolant;
  7517. if ( interpolant !== null ) {
  7518. var interpolantValue = interpolant.evaluate( time )[ 0 ];
  7519. timeScale *= interpolantValue;
  7520. if ( time > interpolant.parameterPositions[ 1 ] ) {
  7521. this.stopWarping();
  7522. if ( timeScale === 0 ) {
  7523. // motion has halted, pause
  7524. this.paused = true;
  7525. } else {
  7526. // warp done - apply final time scale
  7527. this.timeScale = timeScale;
  7528. }
  7529. }
  7530. }
  7531. }
  7532. this._effectiveTimeScale = timeScale;
  7533. return timeScale;
  7534. },
  7535. _updateTime: function( deltaTime ) {
  7536. var time = this.time + deltaTime;
  7537. if ( deltaTime === 0 ) return time;
  7538. var duration = this._clip.duration,
  7539. loop = this.loop,
  7540. loopCount = this._loopCount;
  7541. if ( loop === THREE.LoopOnce ) {
  7542. if ( loopCount === -1 ) {
  7543. // just started
  7544. this.loopCount = 0;
  7545. this._setEndings( true, true, false );
  7546. }
  7547. handle_stop: {
  7548. if ( time >= duration ) {
  7549. time = duration;
  7550. } else if ( time < 0 ) {
  7551. time = 0;
  7552. } else break handle_stop;
  7553. if ( this.clampWhenFinished ) this.paused = true;
  7554. else this.enabled = false;
  7555. this._mixer.dispatchEvent( {
  7556. type: 'finished', action: this,
  7557. direction: deltaTime < 0 ? -1 : 1
  7558. } );
  7559. }
  7560. } else { // repetitive Repeat or PingPong
  7561. var pingPong = ( loop === THREE.LoopPingPong );
  7562. if ( loopCount === -1 ) {
  7563. // just started
  7564. if ( deltaTime >= 0 ) {
  7565. loopCount = 0;
  7566. this._setEndings(
  7567. true, this.repetitions === 0, pingPong );
  7568. } else {
  7569. // when looping in reverse direction, the initial
  7570. // transition through zero counts as a repetition,
  7571. // so leave loopCount at -1
  7572. this._setEndings(
  7573. this.repetitions === 0, true, pingPong );
  7574. }
  7575. }
  7576. if ( time >= duration || time < 0 ) {
  7577. // wrap around
  7578. var loopDelta = Math.floor( time / duration ); // signed
  7579. time -= duration * loopDelta;
  7580. loopCount += Math.abs( loopDelta );
  7581. var pending = this.repetitions - loopCount;
  7582. if ( pending < 0 ) {
  7583. // have to stop (switch state, clamp time, fire event)
  7584. if ( this.clampWhenFinished ) this.paused = true;
  7585. else this.enabled = false;
  7586. time = deltaTime > 0 ? duration : 0;
  7587. this._mixer.dispatchEvent( {
  7588. type: 'finished', action: this,
  7589. direction: deltaTime > 0 ? 1 : -1
  7590. } );
  7591. } else {
  7592. // keep running
  7593. if ( pending === 0 ) {
  7594. // entering the last round
  7595. var atStart = deltaTime < 0;
  7596. this._setEndings( atStart, ! atStart, pingPong );
  7597. } else {
  7598. this._setEndings( false, false, pingPong );
  7599. }
  7600. this._loopCount = loopCount;
  7601. this._mixer.dispatchEvent( {
  7602. type: 'loop', action: this, loopDelta: loopDelta
  7603. } );
  7604. }
  7605. }
  7606. if ( pingPong && ( loopCount & 1 ) === 1 ) {
  7607. // invert time for the "pong round"
  7608. this.time = time;
  7609. return duration - time;
  7610. }
  7611. }
  7612. this.time = time;
  7613. return time;
  7614. },
  7615. _setEndings: function( atStart, atEnd, pingPong ) {
  7616. var settings = this._interpolantSettings;
  7617. if ( pingPong ) {
  7618. settings.endingStart = THREE.ZeroSlopeEnding;
  7619. settings.endingEnd = THREE.ZeroSlopeEnding;
  7620. } else {
  7621. // assuming for LoopOnce atStart == atEnd == true
  7622. if ( atStart ) {
  7623. settings.endingStart = this.zeroSlopeAtStart ?
  7624. THREE.ZeroSlopeEnding : THREE.ZeroCurvatureEnding;
  7625. } else {
  7626. settings.endingStart = THREE.WrapAroundEnding;
  7627. }
  7628. if ( atEnd ) {
  7629. settings.endingEnd = this.zeroSlopeAtEnd ?
  7630. THREE.ZeroSlopeEnding : THREE.ZeroCurvatureEnding;
  7631. } else {
  7632. settings.endingEnd = THREE.WrapAroundEnding;
  7633. }
  7634. }
  7635. },
  7636. _scheduleFading: function( duration, weightNow, weightThen ) {
  7637. var mixer = this._mixer, now = mixer.time,
  7638. interpolant = this._weightInterpolant;
  7639. if ( interpolant === null ) {
  7640. interpolant = mixer._lendControlInterpolant(),
  7641. this._weightInterpolant = interpolant;
  7642. }
  7643. var times = interpolant.parameterPositions,
  7644. values = interpolant.sampleValues;
  7645. times[ 0 ] = now; values[ 0 ] = weightNow;
  7646. times[ 1 ] = now + duration; values[ 1 ] = weightThen;
  7647. return this;
  7648. }
  7649. };
  7650. // File:src/animation/AnimationClip.js
  7651. /**
  7652. *
  7653. * Reusable set of Tracks that represent an animation.
  7654. *
  7655. * @author Ben Houston / http://clara.io/
  7656. * @author David Sarno / http://lighthaus.us/
  7657. */
  7658. THREE.AnimationClip = function ( name, duration, tracks ) {
  7659. this.name = name;
  7660. this.tracks = tracks;
  7661. this.duration = ( duration !== undefined ) ? duration : -1;
  7662. this.uuid = THREE.Math.generateUUID();
  7663. // this means it should figure out its duration by scanning the tracks
  7664. if ( this.duration < 0 ) {
  7665. this.resetDuration();
  7666. }
  7667. // maybe only do these on demand, as doing them here could potentially slow down loading
  7668. // but leaving these here during development as this ensures a lot of testing of these functions
  7669. this.trim();
  7670. this.optimize();
  7671. };
  7672. THREE.AnimationClip.prototype = {
  7673. constructor: THREE.AnimationClip,
  7674. resetDuration: function() {
  7675. var tracks = this.tracks,
  7676. duration = 0;
  7677. for ( var i = 0, n = tracks.length; i !== n; ++ i ) {
  7678. var track = this.tracks[ i ];
  7679. duration = Math.max(
  7680. duration, track.times[ track.times.length - 1 ] );
  7681. }
  7682. this.duration = duration;
  7683. },
  7684. trim: function() {
  7685. for ( var i = 0; i < this.tracks.length; i ++ ) {
  7686. this.tracks[ i ].trim( 0, this.duration );
  7687. }
  7688. return this;
  7689. },
  7690. optimize: function() {
  7691. for ( var i = 0; i < this.tracks.length; i ++ ) {
  7692. this.tracks[ i ].optimize();
  7693. }
  7694. return this;
  7695. }
  7696. };
  7697. // Static methods:
  7698. Object.assign( THREE.AnimationClip, {
  7699. parse: function( json ) {
  7700. var tracks = [],
  7701. jsonTracks = json.tracks,
  7702. frameTime = 1.0 / ( json.fps || 1.0 );
  7703. for ( var i = 0, n = jsonTracks.length; i !== n; ++ i ) {
  7704. tracks.push( THREE.KeyframeTrack.parse( jsonTracks[ i ] ).scale( frameTime ) );
  7705. }
  7706. return new THREE.AnimationClip( json.name, json.duration, tracks );
  7707. },
  7708. toJSON: function( clip ) {
  7709. var tracks = [],
  7710. clipTracks = clip.tracks;
  7711. var json = {
  7712. 'name': clip.name,
  7713. 'duration': clip.duration,
  7714. 'tracks': tracks
  7715. };
  7716. for ( var i = 0, n = clipTracks.length; i !== n; ++ i ) {
  7717. tracks.push( THREE.KeyframeTrack.toJSON( clipTracks[ i ] ) );
  7718. }
  7719. return json;
  7720. },
  7721. CreateFromMorphTargetSequence: function( name, morphTargetSequence, fps, noLoop ) {
  7722. var numMorphTargets = morphTargetSequence.length;
  7723. var tracks = [];
  7724. for ( var i = 0; i < numMorphTargets; i ++ ) {
  7725. var times = [];
  7726. var values = [];
  7727. times.push(
  7728. ( i + numMorphTargets - 1 ) % numMorphTargets,
  7729. i,
  7730. ( i + 1 ) % numMorphTargets );
  7731. values.push( 0, 1, 0 );
  7732. var order = THREE.AnimationUtils.getKeyframeOrder( times );
  7733. times = THREE.AnimationUtils.sortedArray( times, 1, order );
  7734. values = THREE.AnimationUtils.sortedArray( values, 1, order );
  7735. // if there is a key at the first frame, duplicate it as the
  7736. // last frame as well for perfect loop.
  7737. if ( ! noLoop && times[ 0 ] === 0 ) {
  7738. times.push( numMorphTargets );
  7739. values.push( values[ 0 ] );
  7740. }
  7741. tracks.push(
  7742. new THREE.NumberKeyframeTrack(
  7743. '.morphTargetInfluences[' + morphTargetSequence[ i ].name + ']',
  7744. times, values
  7745. ).scale( 1.0 / fps ) );
  7746. }
  7747. return new THREE.AnimationClip( name, -1, tracks );
  7748. },
  7749. findByName: function( objectOrClipArray, name ) {
  7750. var clipArray = objectOrClipArray;
  7751. if ( ! Array.isArray( objectOrClipArray ) ) {
  7752. var o = objectOrClipArray;
  7753. clipArray = o.geometry && o.geometry.animations || o.animations;
  7754. }
  7755. for ( var i = 0; i < clipArray.length; i ++ ) {
  7756. if ( clipArray[ i ].name === name ) {
  7757. return clipArray[ i ];
  7758. }
  7759. }
  7760. return null;
  7761. },
  7762. CreateClipsFromMorphTargetSequences: function( morphTargets, fps, noLoop ) {
  7763. var animationToMorphTargets = {};
  7764. // tested with https://regex101.com/ on trick sequences
  7765. // such flamingo_flyA_003, flamingo_run1_003, crdeath0059
  7766. var pattern = /^([\w-]*?)([\d]+)$/;
  7767. // sort morph target names into animation groups based
  7768. // patterns like Walk_001, Walk_002, Run_001, Run_002
  7769. for ( var i = 0, il = morphTargets.length; i < il; i ++ ) {
  7770. var morphTarget = morphTargets[ i ];
  7771. var parts = morphTarget.name.match( pattern );
  7772. if ( parts && parts.length > 1 ) {
  7773. var name = parts[ 1 ];
  7774. var animationMorphTargets = animationToMorphTargets[ name ];
  7775. if ( ! animationMorphTargets ) {
  7776. animationToMorphTargets[ name ] = animationMorphTargets = [];
  7777. }
  7778. animationMorphTargets.push( morphTarget );
  7779. }
  7780. }
  7781. var clips = [];
  7782. for ( var name in animationToMorphTargets ) {
  7783. clips.push( THREE.AnimationClip.CreateFromMorphTargetSequence( name, animationToMorphTargets[ name ], fps, noLoop ) );
  7784. }
  7785. return clips;
  7786. },
  7787. // parse the animation.hierarchy format
  7788. parseAnimation: function( animation, bones, nodeName ) {
  7789. if ( ! animation ) {
  7790. console.error( " no animation in JSONLoader data" );
  7791. return null;
  7792. }
  7793. var addNonemptyTrack = function(
  7794. trackType, trackName, animationKeys, propertyName, destTracks ) {
  7795. // only return track if there are actually keys.
  7796. if ( animationKeys.length !== 0 ) {
  7797. var times = [];
  7798. var values = [];
  7799. THREE.AnimationUtils.flattenJSON(
  7800. animationKeys, times, values, propertyName );
  7801. // empty keys are filtered out, so check again
  7802. if ( times.length !== 0 ) {
  7803. destTracks.push( new trackType( trackName, times, values ) );
  7804. }
  7805. }
  7806. };
  7807. var tracks = [];
  7808. var clipName = animation.name || 'default';
  7809. // automatic length determination in AnimationClip.
  7810. var duration = animation.length || -1;
  7811. var fps = animation.fps || 30;
  7812. var hierarchyTracks = animation.hierarchy || [];
  7813. for ( var h = 0; h < hierarchyTracks.length; h ++ ) {
  7814. var animationKeys = hierarchyTracks[ h ].keys;
  7815. // skip empty tracks
  7816. if ( ! animationKeys || animationKeys.length === 0 ) continue;
  7817. // process morph targets in a way exactly compatible
  7818. // with AnimationHandler.init( animation )
  7819. if ( animationKeys[0].morphTargets ) {
  7820. // figure out all morph targets used in this track
  7821. var morphTargetNames = {};
  7822. for ( var k = 0; k < animationKeys.length; k ++ ) {
  7823. if ( animationKeys[k].morphTargets ) {
  7824. for ( var m = 0; m < animationKeys[k].morphTargets.length; m ++ ) {
  7825. morphTargetNames[ animationKeys[k].morphTargets[m] ] = -1;
  7826. }
  7827. }
  7828. }
  7829. // create a track for each morph target with all zero
  7830. // morphTargetInfluences except for the keys in which
  7831. // the morphTarget is named.
  7832. for ( var morphTargetName in morphTargetNames ) {
  7833. var times = [];
  7834. var values = [];
  7835. for ( var m = 0;
  7836. m !== animationKeys[k].morphTargets.length; ++ m ) {
  7837. var animationKey = animationKeys[k];
  7838. times.push( animationKey.time );
  7839. values.push( ( animationKey.morphTarget === morphTargetName ) ? 1 : 0 );
  7840. }
  7841. tracks.push( new THREE.NumberKeyframeTrack(
  7842. '.morphTargetInfluence[' + morphTargetName + ']', times, values ) );
  7843. }
  7844. duration = morphTargetNames.length * ( fps || 1.0 );
  7845. } else {
  7846. // ...assume skeletal animation
  7847. var boneName = '.bones[' + bones[ h ].name + ']';
  7848. addNonemptyTrack(
  7849. THREE.VectorKeyframeTrack, boneName + '.position',
  7850. animationKeys, 'pos', tracks );
  7851. addNonemptyTrack(
  7852. THREE.QuaternionKeyframeTrack, boneName + '.quaternion',
  7853. animationKeys, 'rot', tracks );
  7854. addNonemptyTrack(
  7855. THREE.VectorKeyframeTrack, boneName + '.scale',
  7856. animationKeys, 'scl', tracks );
  7857. }
  7858. }
  7859. if ( tracks.length === 0 ) {
  7860. return null;
  7861. }
  7862. var clip = new THREE.AnimationClip( clipName, duration, tracks );
  7863. return clip;
  7864. }
  7865. } );
  7866. // File:src/animation/AnimationMixer.js
  7867. /**
  7868. *
  7869. * Player for AnimationClips.
  7870. *
  7871. *
  7872. * @author Ben Houston / http://clara.io/
  7873. * @author David Sarno / http://lighthaus.us/
  7874. * @author tschw
  7875. */
  7876. THREE.AnimationMixer = function( root ) {
  7877. this._root = root;
  7878. this._initMemoryManager();
  7879. this._accuIndex = 0;
  7880. this.time = 0;
  7881. this.timeScale = 1.0;
  7882. };
  7883. Object.assign( THREE.AnimationMixer.prototype, THREE.EventDispatcher.prototype, {
  7884. // return an action for a clip optionally using a custom root target
  7885. // object (this method allocates a lot of dynamic memory in case a
  7886. // previously unknown clip/root combination is specified)
  7887. clipAction: function( clip, optionalRoot ) {
  7888. var root = optionalRoot || this._root,
  7889. rootUuid = root.uuid,
  7890. clipObject = typeof clip === 'string' ?
  7891. THREE.AnimationClip.findByName( root, clip ) : clip,
  7892. clipUuid = clipObject !== null ? clipObject.uuid : clip,
  7893. actionsForClip = this._actionsByClip[ clipUuid ],
  7894. prototypeAction = null;
  7895. if ( actionsForClip !== undefined ) {
  7896. var existingAction =
  7897. actionsForClip.actionByRoot[ rootUuid ];
  7898. if ( existingAction !== undefined ) {
  7899. return existingAction;
  7900. }
  7901. // we know the clip, so we don't have to parse all
  7902. // the bindings again but can just copy
  7903. prototypeAction = actionsForClip.knownActions[ 0 ];
  7904. // also, take the clip from the prototype action
  7905. if ( clipObject === null )
  7906. clipObject = prototypeAction._clip;
  7907. }
  7908. // clip must be known when specified via string
  7909. if ( clipObject === null ) return null;
  7910. // allocate all resources required to run it
  7911. var newAction = new THREE.
  7912. AnimationMixer._Action( this, clipObject, optionalRoot );
  7913. this._bindAction( newAction, prototypeAction );
  7914. // and make the action known to the memory manager
  7915. this._addInactiveAction( newAction, clipUuid, rootUuid );
  7916. return newAction;
  7917. },
  7918. // get an existing action
  7919. existingAction: function( clip, optionalRoot ) {
  7920. var root = optionalRoot || this._root,
  7921. rootUuid = root.uuid,
  7922. clipObject = typeof clip === 'string' ?
  7923. THREE.AnimationClip.findByName( root, clip ) : clip,
  7924. clipUuid = clipObject ? clipObject.uuid : clip,
  7925. actionsForClip = this._actionsByClip[ clipUuid ];
  7926. if ( actionsForClip !== undefined ) {
  7927. return actionsForClip.actionByRoot[ rootUuid ] || null;
  7928. }
  7929. return null;
  7930. },
  7931. // deactivates all previously scheduled actions
  7932. stopAllAction: function() {
  7933. var actions = this._actions,
  7934. nActions = this._nActiveActions,
  7935. bindings = this._bindings,
  7936. nBindings = this._nActiveBindings;
  7937. this._nActiveActions = 0;
  7938. this._nActiveBindings = 0;
  7939. for ( var i = 0; i !== nActions; ++ i ) {
  7940. actions[ i ].reset();
  7941. }
  7942. for ( var i = 0; i !== nBindings; ++ i ) {
  7943. bindings[ i ].useCount = 0;
  7944. }
  7945. return this;
  7946. },
  7947. // advance the time and update apply the animation
  7948. update: function( deltaTime ) {
  7949. deltaTime *= this.timeScale;
  7950. var actions = this._actions,
  7951. nActions = this._nActiveActions,
  7952. time = this.time += deltaTime,
  7953. timeDirection = Math.sign( deltaTime ),
  7954. accuIndex = this._accuIndex ^= 1;
  7955. // run active actions
  7956. for ( var i = 0; i !== nActions; ++ i ) {
  7957. var action = actions[ i ];
  7958. if ( action.enabled ) {
  7959. action._update( time, deltaTime, timeDirection, accuIndex );
  7960. }
  7961. }
  7962. // update scene graph
  7963. var bindings = this._bindings,
  7964. nBindings = this._nActiveBindings;
  7965. for ( var i = 0; i !== nBindings; ++ i ) {
  7966. bindings[ i ].apply( accuIndex );
  7967. }
  7968. return this;
  7969. },
  7970. // return this mixer's root target object
  7971. getRoot: function() {
  7972. return this._root;
  7973. },
  7974. // free all resources specific to a particular clip
  7975. uncacheClip: function( clip ) {
  7976. var actions = this._actions,
  7977. clipUuid = clip.uuid,
  7978. actionsByClip = this._actionsByClip,
  7979. actionsForClip = actionsByClip[ clipUuid ];
  7980. if ( actionsForClip !== undefined ) {
  7981. // note: just calling _removeInactiveAction would mess up the
  7982. // iteration state and also require updating the state we can
  7983. // just throw away
  7984. var actionsToRemove = actionsForClip.knownActions;
  7985. for ( var i = 0, n = actionsToRemove.length; i !== n; ++ i ) {
  7986. var action = actionsToRemove[ i ];
  7987. this._deactivateAction( action );
  7988. var cacheIndex = action._cacheIndex,
  7989. lastInactiveAction = actions[ actions.length - 1 ];
  7990. action._cacheIndex = null;
  7991. action._byClipCacheIndex = null;
  7992. lastInactiveAction._cacheIndex = cacheIndex;
  7993. actions[ cacheIndex ] = lastInactiveAction;
  7994. actions.pop();
  7995. this._removeInactiveBindingsForAction( action );
  7996. }
  7997. delete actionsByClip[ clipUuid ];
  7998. }
  7999. },
  8000. // free all resources specific to a particular root target object
  8001. uncacheRoot: function( root ) {
  8002. var rootUuid = root.uuid,
  8003. actionsByClip = this._actionsByClip;
  8004. for ( var clipUuid in actionsByClip ) {
  8005. var actionByRoot = actionsByClip[ clipUuid ].actionByRoot,
  8006. action = actionByRoot[ rootUuid ];
  8007. if ( action !== undefined ) {
  8008. this._deactivateAction( action );
  8009. this._removeInactiveAction( action );
  8010. }
  8011. }
  8012. var bindingsByRoot = this._bindingsByRootAndName,
  8013. bindingByName = bindingsByRoot[ rootUuid ];
  8014. if ( bindingByName !== undefined ) {
  8015. for ( var trackName in bindingByName ) {
  8016. var binding = bindingByName[ trackName ];
  8017. binding.restoreOriginalState();
  8018. this._removeInactiveBinding( binding );
  8019. }
  8020. }
  8021. },
  8022. // remove a targeted clip from the cache
  8023. uncacheAction: function( clip, optionalRoot ) {
  8024. var action = this.existingAction( clip, optionalRoot );
  8025. if ( action !== null ) {
  8026. this._deactivateAction( action );
  8027. this._removeInactiveAction( action );
  8028. }
  8029. }
  8030. } );
  8031. THREE.AnimationMixer._Action = THREE.AnimationAction._new;
  8032. // Implementation details:
  8033. Object.assign( THREE.AnimationMixer.prototype, {
  8034. _bindAction: function( action, prototypeAction ) {
  8035. var root = action._localRoot || this._root,
  8036. tracks = action._clip.tracks,
  8037. nTracks = tracks.length,
  8038. bindings = action._propertyBindings,
  8039. interpolants = action._interpolants,
  8040. rootUuid = root.uuid,
  8041. bindingsByRoot = this._bindingsByRootAndName,
  8042. bindingsByName = bindingsByRoot[ rootUuid ];
  8043. if ( bindingsByName === undefined ) {
  8044. bindingsByName = {};
  8045. bindingsByRoot[ rootUuid ] = bindingsByName;
  8046. }
  8047. for ( var i = 0; i !== nTracks; ++ i ) {
  8048. var track = tracks[ i ],
  8049. trackName = track.name,
  8050. binding = bindingsByName[ trackName ];
  8051. if ( binding !== undefined ) {
  8052. bindings[ i ] = binding;
  8053. } else {
  8054. binding = bindings[ i ];
  8055. if ( binding !== undefined ) {
  8056. // existing binding, make sure the cache knows
  8057. if ( binding._cacheIndex === null ) {
  8058. ++ binding.referenceCount;
  8059. this._addInactiveBinding( binding, rootUuid, trackName );
  8060. }
  8061. continue;
  8062. }
  8063. var path = prototypeAction && prototypeAction.
  8064. _propertyBindings[ i ].binding.parsedPath;
  8065. binding = new THREE.PropertyMixer(
  8066. THREE.PropertyBinding.create( root, trackName, path ),
  8067. track.ValueTypeName, track.getValueSize() );
  8068. ++ binding.referenceCount;
  8069. this._addInactiveBinding( binding, rootUuid, trackName );
  8070. bindings[ i ] = binding;
  8071. }
  8072. interpolants[ i ].resultBuffer = binding.buffer;
  8073. }
  8074. },
  8075. _activateAction: function( action ) {
  8076. if ( ! this._isActiveAction( action ) ) {
  8077. if ( action._cacheIndex === null ) {
  8078. // this action has been forgotten by the cache, but the user
  8079. // appears to be still using it -> rebind
  8080. var rootUuid = ( action._localRoot || this._root ).uuid,
  8081. clipUuid = action._clip.uuid,
  8082. actionsForClip = this._actionsByClip[ clipUuid ];
  8083. this._bindAction( action,
  8084. actionsForClip && actionsForClip.knownActions[ 0 ] );
  8085. this._addInactiveAction( action, clipUuid, rootUuid );
  8086. }
  8087. var bindings = action._propertyBindings;
  8088. // increment reference counts / sort out state
  8089. for ( var i = 0, n = bindings.length; i !== n; ++ i ) {
  8090. var binding = bindings[ i ];
  8091. if ( binding.useCount ++ === 0 ) {
  8092. this._lendBinding( binding );
  8093. binding.saveOriginalState();
  8094. }
  8095. }
  8096. this._lendAction( action );
  8097. }
  8098. },
  8099. _deactivateAction: function( action ) {
  8100. if ( this._isActiveAction( action ) ) {
  8101. var bindings = action._propertyBindings;
  8102. // decrement reference counts / sort out state
  8103. for ( var i = 0, n = bindings.length; i !== n; ++ i ) {
  8104. var binding = bindings[ i ];
  8105. if ( -- binding.useCount === 0 ) {
  8106. binding.restoreOriginalState();
  8107. this._takeBackBinding( binding );
  8108. }
  8109. }
  8110. this._takeBackAction( action );
  8111. }
  8112. },
  8113. // Memory manager
  8114. _initMemoryManager: function() {
  8115. this._actions = []; // 'nActiveActions' followed by inactive ones
  8116. this._nActiveActions = 0;
  8117. this._actionsByClip = {};
  8118. // inside:
  8119. // {
  8120. // knownActions: Array< _Action > - used as prototypes
  8121. // actionByRoot: _Action - lookup
  8122. // }
  8123. this._bindings = []; // 'nActiveBindings' followed by inactive ones
  8124. this._nActiveBindings = 0;
  8125. this._bindingsByRootAndName = {}; // inside: Map< name, PropertyMixer >
  8126. this._controlInterpolants = []; // same game as above
  8127. this._nActiveControlInterpolants = 0;
  8128. var scope = this;
  8129. this.stats = {
  8130. actions: {
  8131. get total() { return scope._actions.length; },
  8132. get inUse() { return scope._nActiveActions; }
  8133. },
  8134. bindings: {
  8135. get total() { return scope._bindings.length; },
  8136. get inUse() { return scope._nActiveBindings; }
  8137. },
  8138. controlInterpolants: {
  8139. get total() { return scope._controlInterpolants.length; },
  8140. get inUse() { return scope._nActiveControlInterpolants; }
  8141. }
  8142. };
  8143. },
  8144. // Memory management for _Action objects
  8145. _isActiveAction: function( action ) {
  8146. var index = action._cacheIndex;
  8147. return index !== null && index < this._nActiveActions;
  8148. },
  8149. _addInactiveAction: function( action, clipUuid, rootUuid ) {
  8150. var actions = this._actions,
  8151. actionsByClip = this._actionsByClip,
  8152. actionsForClip = actionsByClip[ clipUuid ];
  8153. if ( actionsForClip === undefined ) {
  8154. actionsForClip = {
  8155. knownActions: [ action ],
  8156. actionByRoot: {}
  8157. };
  8158. action._byClipCacheIndex = 0;
  8159. actionsByClip[ clipUuid ] = actionsForClip;
  8160. } else {
  8161. var knownActions = actionsForClip.knownActions;
  8162. action._byClipCacheIndex = knownActions.length;
  8163. knownActions.push( action );
  8164. }
  8165. action._cacheIndex = actions.length;
  8166. actions.push( action );
  8167. actionsForClip.actionByRoot[ rootUuid ] = action;
  8168. },
  8169. _removeInactiveAction: function( action ) {
  8170. var actions = this._actions,
  8171. lastInactiveAction = actions[ actions.length - 1 ],
  8172. cacheIndex = action._cacheIndex;
  8173. lastInactiveAction._cacheIndex = cacheIndex;
  8174. actions[ cacheIndex ] = lastInactiveAction;
  8175. actions.pop();
  8176. action._cacheIndex = null;
  8177. var clipUuid = action._clip.uuid,
  8178. actionsByClip = this._actionsByClip,
  8179. actionsForClip = actionsByClip[ clipUuid ],
  8180. knownActionsForClip = actionsForClip.knownActions,
  8181. lastKnownAction =
  8182. knownActionsForClip[ knownActionsForClip.length - 1 ],
  8183. byClipCacheIndex = action._byClipCacheIndex;
  8184. lastKnownAction._byClipCacheIndex = byClipCacheIndex;
  8185. knownActionsForClip[ byClipCacheIndex ] = lastKnownAction;
  8186. knownActionsForClip.pop();
  8187. action._byClipCacheIndex = null;
  8188. var actionByRoot = actionsForClip.actionByRoot,
  8189. rootUuid = ( actions._localRoot || this._root ).uuid;
  8190. delete actionByRoot[ rootUuid ];
  8191. if ( knownActionsForClip.length === 0 ) {
  8192. delete actionsByClip[ clipUuid ];
  8193. }
  8194. this._removeInactiveBindingsForAction( action );
  8195. },
  8196. _removeInactiveBindingsForAction: function( action ) {
  8197. var bindings = action._propertyBindings;
  8198. for ( var i = 0, n = bindings.length; i !== n; ++ i ) {
  8199. var binding = bindings[ i ];
  8200. if ( -- binding.referenceCount === 0 ) {
  8201. this._removeInactiveBinding( binding );
  8202. }
  8203. }
  8204. },
  8205. _lendAction: function( action ) {
  8206. // [ active actions | inactive actions ]
  8207. // [ active actions >| inactive actions ]
  8208. // s a
  8209. // <-swap->
  8210. // a s
  8211. var actions = this._actions,
  8212. prevIndex = action._cacheIndex,
  8213. lastActiveIndex = this._nActiveActions ++,
  8214. firstInactiveAction = actions[ lastActiveIndex ];
  8215. action._cacheIndex = lastActiveIndex;
  8216. actions[ lastActiveIndex ] = action;
  8217. firstInactiveAction._cacheIndex = prevIndex;
  8218. actions[ prevIndex ] = firstInactiveAction;
  8219. },
  8220. _takeBackAction: function( action ) {
  8221. // [ active actions | inactive actions ]
  8222. // [ active actions |< inactive actions ]
  8223. // a s
  8224. // <-swap->
  8225. // s a
  8226. var actions = this._actions,
  8227. prevIndex = action._cacheIndex,
  8228. firstInactiveIndex = -- this._nActiveActions,
  8229. lastActiveAction = actions[ firstInactiveIndex ];
  8230. action._cacheIndex = firstInactiveIndex;
  8231. actions[ firstInactiveIndex ] = action;
  8232. lastActiveAction._cacheIndex = prevIndex;
  8233. actions[ prevIndex ] = lastActiveAction;
  8234. },
  8235. // Memory management for PropertyMixer objects
  8236. _addInactiveBinding: function( binding, rootUuid, trackName ) {
  8237. var bindingsByRoot = this._bindingsByRootAndName,
  8238. bindingByName = bindingsByRoot[ rootUuid ],
  8239. bindings = this._bindings;
  8240. if ( bindingByName === undefined ) {
  8241. bindingByName = {};
  8242. bindingsByRoot[ rootUuid ] = bindingByName;
  8243. }
  8244. bindingByName[ trackName ] = binding;
  8245. binding._cacheIndex = bindings.length;
  8246. bindings.push( binding );
  8247. },
  8248. _removeInactiveBinding: function( binding ) {
  8249. var bindings = this._bindings,
  8250. propBinding = binding.binding,
  8251. rootUuid = propBinding.rootNode.uuid,
  8252. trackName = propBinding.path,
  8253. bindingsByRoot = this._bindingsByRootAndName,
  8254. bindingByName = bindingsByRoot[ rootUuid ],
  8255. lastInactiveBinding = bindings[ bindings.length - 1 ],
  8256. cacheIndex = binding._cacheIndex;
  8257. lastInactiveBinding._cacheIndex = cacheIndex;
  8258. bindings[ cacheIndex ] = lastInactiveBinding;
  8259. bindings.pop();
  8260. delete bindingByName[ trackName ];
  8261. remove_empty_map: {
  8262. for ( var _ in bindingByName ) break remove_empty_map;
  8263. delete bindingsByRoot[ rootUuid ];
  8264. }
  8265. },
  8266. _lendBinding: function( binding ) {
  8267. var bindings = this._bindings,
  8268. prevIndex = binding._cacheIndex,
  8269. lastActiveIndex = this._nActiveBindings ++,
  8270. firstInactiveBinding = bindings[ lastActiveIndex ];
  8271. binding._cacheIndex = lastActiveIndex;
  8272. bindings[ lastActiveIndex ] = binding;
  8273. firstInactiveBinding._cacheIndex = prevIndex;
  8274. bindings[ prevIndex ] = firstInactiveBinding;
  8275. },
  8276. _takeBackBinding: function( binding ) {
  8277. var bindings = this._bindings,
  8278. prevIndex = binding._cacheIndex,
  8279. firstInactiveIndex = -- this._nActiveBindings,
  8280. lastActiveBinding = bindings[ firstInactiveIndex ];
  8281. binding._cacheIndex = firstInactiveIndex;
  8282. bindings[ firstInactiveIndex ] = binding;
  8283. lastActiveBinding._cacheIndex = prevIndex;
  8284. bindings[ prevIndex ] = lastActiveBinding;
  8285. },
  8286. // Memory management of Interpolants for weight and time scale
  8287. _lendControlInterpolant: function() {
  8288. var interpolants = this._controlInterpolants,
  8289. lastActiveIndex = this._nActiveControlInterpolants ++,
  8290. interpolant = interpolants[ lastActiveIndex ];
  8291. if ( interpolant === undefined ) {
  8292. interpolant = new THREE.LinearInterpolant(
  8293. new Float32Array( 2 ), new Float32Array( 2 ),
  8294. 1, this._controlInterpolantsResultBuffer );
  8295. interpolant.__cacheIndex = lastActiveIndex;
  8296. interpolants[ lastActiveIndex ] = interpolant;
  8297. }
  8298. return interpolant;
  8299. },
  8300. _takeBackControlInterpolant: function( interpolant ) {
  8301. var interpolants = this._controlInterpolants,
  8302. prevIndex = interpolant.__cacheIndex,
  8303. firstInactiveIndex = -- this._nActiveControlInterpolants,
  8304. lastActiveInterpolant = interpolants[ firstInactiveIndex ];
  8305. interpolant.__cacheIndex = firstInactiveIndex;
  8306. interpolants[ firstInactiveIndex ] = interpolant;
  8307. lastActiveInterpolant.__cacheIndex = prevIndex;
  8308. interpolants[ prevIndex ] = lastActiveInterpolant;
  8309. },
  8310. _controlInterpolantsResultBuffer: new Float32Array( 1 )
  8311. } );
  8312. // File:src/animation/AnimationObjectGroup.js
  8313. /**
  8314. *
  8315. * A group of objects that receives a shared animation state.
  8316. *
  8317. * Usage:
  8318. *
  8319. * - Add objects you would otherwise pass as 'root' to the
  8320. * constructor or the .clipAction method of AnimationMixer.
  8321. *
  8322. * - Instead pass this object as 'root'.
  8323. *
  8324. * - You can also add and remove objects later when the mixer
  8325. * is running.
  8326. *
  8327. * Note:
  8328. *
  8329. * Objects of this class appear as one object to the mixer,
  8330. * so cache control of the individual objects must be done
  8331. * on the group.
  8332. *
  8333. * Limitation:
  8334. *
  8335. * - The animated properties must be compatible among the
  8336. * all objects in the group.
  8337. *
  8338. * - A single property can either be controlled through a
  8339. * target group or directly, but not both.
  8340. *
  8341. * @author tschw
  8342. */
  8343. THREE.AnimationObjectGroup = function( var_args ) {
  8344. this.uuid = THREE.Math.generateUUID();
  8345. // cached objects followed by the active ones
  8346. this._objects = Array.prototype.slice.call( arguments );
  8347. this.nCachedObjects_ = 0; // threshold
  8348. // note: read by PropertyBinding.Composite
  8349. var indices = {};
  8350. this._indicesByUUID = indices; // for bookkeeping
  8351. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  8352. indices[ arguments[ i ].uuid ] = i;
  8353. }
  8354. this._paths = []; // inside: string
  8355. this._parsedPaths = []; // inside: { we don't care, here }
  8356. this._bindings = []; // inside: Array< PropertyBinding >
  8357. this._bindingsIndicesByPath = {}; // inside: indices in these arrays
  8358. var scope = this;
  8359. this.stats = {
  8360. objects: {
  8361. get total() { return scope._objects.length; },
  8362. get inUse() { return this.total - scope.nCachedObjects_; }
  8363. },
  8364. get bindingsPerObject() { return scope._bindings.length; }
  8365. };
  8366. };
  8367. THREE.AnimationObjectGroup.prototype = {
  8368. constructor: THREE.AnimationObjectGroup,
  8369. add: function( var_args ) {
  8370. var objects = this._objects,
  8371. nObjects = objects.length,
  8372. nCachedObjects = this.nCachedObjects_,
  8373. indicesByUUID = this._indicesByUUID,
  8374. paths = this._paths,
  8375. parsedPaths = this._parsedPaths,
  8376. bindings = this._bindings,
  8377. nBindings = bindings.length;
  8378. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  8379. var object = arguments[ i ],
  8380. uuid = object.uuid,
  8381. index = indicesByUUID[ uuid ];
  8382. if ( index === undefined ) {
  8383. // unknown object -> add it to the ACTIVE region
  8384. index = nObjects ++;
  8385. indicesByUUID[ uuid ] = index;
  8386. objects.push( object );
  8387. // accounting is done, now do the same for all bindings
  8388. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  8389. bindings[ j ].push(
  8390. new THREE.PropertyBinding(
  8391. object, paths[ j ], parsedPaths[ j ] ) );
  8392. }
  8393. } else if ( index < nCachedObjects ) {
  8394. var knownObject = objects[ index ];
  8395. // move existing object to the ACTIVE region
  8396. var firstActiveIndex = -- nCachedObjects,
  8397. lastCachedObject = objects[ firstActiveIndex ];
  8398. indicesByUUID[ lastCachedObject.uuid ] = index;
  8399. objects[ index ] = lastCachedObject;
  8400. indicesByUUID[ uuid ] = firstActiveIndex;
  8401. objects[ firstActiveIndex ] = object;
  8402. // accounting is done, now do the same for all bindings
  8403. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  8404. var bindingsForPath = bindings[ j ],
  8405. lastCached = bindingsForPath[ firstActiveIndex ],
  8406. binding = bindingsForPath[ index ];
  8407. bindingsForPath[ index ] = lastCached;
  8408. if ( binding === undefined ) {
  8409. // since we do not bother to create new bindings
  8410. // for objects that are cached, the binding may
  8411. // or may not exist
  8412. binding = new THREE.PropertyBinding(
  8413. object, paths[ j ], parsedPaths[ j ] );
  8414. }
  8415. bindingsForPath[ firstActiveIndex ] = binding;
  8416. }
  8417. } else if ( objects[ index ] !== knownObject) {
  8418. console.error( "Different objects with the same UUID " +
  8419. "detected. Clean the caches or recreate your " +
  8420. "infrastructure when reloading scenes..." );
  8421. } // else the object is already where we want it to be
  8422. } // for arguments
  8423. this.nCachedObjects_ = nCachedObjects;
  8424. },
  8425. remove: function( var_args ) {
  8426. var objects = this._objects,
  8427. nObjects = objects.length,
  8428. nCachedObjects = this.nCachedObjects_,
  8429. indicesByUUID = this._indicesByUUID,
  8430. bindings = this._bindings,
  8431. nBindings = bindings.length;
  8432. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  8433. var object = arguments[ i ],
  8434. uuid = object.uuid,
  8435. index = indicesByUUID[ uuid ];
  8436. if ( index !== undefined && index >= nCachedObjects ) {
  8437. // move existing object into the CACHED region
  8438. var lastCachedIndex = nCachedObjects ++,
  8439. firstActiveObject = objects[ lastCachedIndex ];
  8440. indicesByUUID[ firstActiveObject.uuid ] = index;
  8441. objects[ index ] = firstActiveObject;
  8442. indicesByUUID[ uuid ] = lastCachedIndex;
  8443. objects[ lastCachedIndex ] = object;
  8444. // accounting is done, now do the same for all bindings
  8445. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  8446. var bindingsForPath = bindings[ j ],
  8447. firstActive = bindingsForPath[ lastCachedIndex ],
  8448. binding = bindingsForPath[ index ];
  8449. bindingsForPath[ index ] = firstActive;
  8450. bindingsForPath[ lastCachedIndex ] = binding;
  8451. }
  8452. }
  8453. } // for arguments
  8454. this.nCachedObjects_ = nCachedObjects;
  8455. },
  8456. // remove & forget
  8457. uncache: function( var_args ) {
  8458. var objects = this._objects,
  8459. nObjects = objects.length,
  8460. nCachedObjects = this.nCachedObjects_,
  8461. indicesByUUID = this._indicesByUUID,
  8462. bindings = this._bindings,
  8463. nBindings = bindings.length;
  8464. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  8465. var object = arguments[ i ],
  8466. uuid = object.uuid,
  8467. index = indicesByUUID[ uuid ];
  8468. if ( index !== undefined ) {
  8469. delete indicesByUUID[ uuid ];
  8470. if ( index < nCachedObjects ) {
  8471. // object is cached, shrink the CACHED region
  8472. var firstActiveIndex = -- nCachedObjects,
  8473. lastCachedObject = objects[ firstActiveIndex ],
  8474. lastIndex = -- nObjects,
  8475. lastObject = objects[ lastIndex ];
  8476. // last cached object takes this object's place
  8477. indicesByUUID[ lastCachedObject.uuid ] = index;
  8478. objects[ index ] = lastCachedObject;
  8479. // last object goes to the activated slot and pop
  8480. indicesByUUID[ lastObject.uuid ] = firstActiveIndex;
  8481. objects[ firstActiveIndex ] = lastObject;
  8482. objects.pop();
  8483. // accounting is done, now do the same for all bindings
  8484. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  8485. var bindingsForPath = bindings[ j ],
  8486. lastCached = bindingsForPath[ firstActiveIndex ],
  8487. last = bindingsForPath[ lastIndex ];
  8488. bindingsForPath[ index ] = lastCached;
  8489. bindingsForPath[ firstActiveIndex ] = last;
  8490. bindingsForPath.pop();
  8491. }
  8492. } else {
  8493. // object is active, just swap with the last and pop
  8494. var lastIndex = -- nObjects,
  8495. lastObject = objects[ lastIndex ];
  8496. indicesByUUID[ lastObject.uuid ] = index;
  8497. objects[ index ] = lastObject;
  8498. objects.pop();
  8499. // accounting is done, now do the same for all bindings
  8500. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  8501. var bindingsForPath = bindings[ j ];
  8502. bindingsForPath[ index ] = bindingsForPath[ lastIndex ];
  8503. bindingsForPath.pop();
  8504. }
  8505. } // cached or active
  8506. } // if object is known
  8507. } // for arguments
  8508. this.nCachedObjects_ = nCachedObjects;
  8509. },
  8510. // Internal interface used by befriended PropertyBinding.Composite:
  8511. subscribe_: function( path, parsedPath ) {
  8512. // returns an array of bindings for the given path that is changed
  8513. // according to the contained objects in the group
  8514. var indicesByPath = this._bindingsIndicesByPath,
  8515. index = indicesByPath[ path ],
  8516. bindings = this._bindings;
  8517. if ( index !== undefined ) return bindings[ index ];
  8518. var paths = this._paths,
  8519. parsedPaths = this._parsedPaths,
  8520. objects = this._objects,
  8521. nObjects = objects.length,
  8522. nCachedObjects = this.nCachedObjects_,
  8523. bindingsForPath = new Array( nObjects );
  8524. index = bindings.length;
  8525. indicesByPath[ path ] = index;
  8526. paths.push( path );
  8527. parsedPaths.push( parsedPath );
  8528. bindings.push( bindingsForPath );
  8529. for ( var i = nCachedObjects,
  8530. n = objects.length; i !== n; ++ i ) {
  8531. var object = objects[ i ];
  8532. bindingsForPath[ i ] =
  8533. new THREE.PropertyBinding( object, path, parsedPath );
  8534. }
  8535. return bindingsForPath;
  8536. },
  8537. unsubscribe_: function( path ) {
  8538. // tells the group to forget about a property path and no longer
  8539. // update the array previously obtained with 'subscribe_'
  8540. var indicesByPath = this._bindingsIndicesByPath,
  8541. index = indicesByPath[ path ];
  8542. if ( index !== undefined ) {
  8543. var paths = this._paths,
  8544. parsedPaths = this._parsedPaths,
  8545. bindings = this._bindings,
  8546. lastBindingsIndex = bindings.length - 1,
  8547. lastBindings = bindings[ lastBindingsIndex ],
  8548. lastBindingsPath = path[ lastBindingsIndex ];
  8549. indicesByPath[ lastBindingsPath ] = index;
  8550. bindings[ index ] = lastBindings;
  8551. bindings.pop();
  8552. parsedPaths[ index ] = parsedPaths[ lastBindingsIndex ];
  8553. parsedPaths.pop();
  8554. paths[ index ] = paths[ lastBindingsIndex ];
  8555. paths.pop();
  8556. }
  8557. }
  8558. };
  8559. // File:src/animation/AnimationUtils.js
  8560. /**
  8561. * @author tschw
  8562. * @author Ben Houston / http://clara.io/
  8563. * @author David Sarno / http://lighthaus.us/
  8564. */
  8565. THREE.AnimationUtils = {
  8566. // same as Array.prototype.slice, but also works on typed arrays
  8567. arraySlice: function( array, from, to ) {
  8568. if ( THREE.AnimationUtils.isTypedArray( array ) ) {
  8569. return new array.constructor( array.subarray( from, to ) );
  8570. }
  8571. return array.slice( from, to );
  8572. },
  8573. // converts an array to a specific type
  8574. convertArray: function( array, type, forceClone ) {
  8575. if ( ! array || // let 'undefined' and 'null' pass
  8576. ! forceClone && array.constructor === type ) return array;
  8577. if ( typeof type.BYTES_PER_ELEMENT === 'number' ) {
  8578. return new type( array ); // create typed array
  8579. }
  8580. return Array.prototype.slice.call( array ); // create Array
  8581. },
  8582. isTypedArray: function( object ) {
  8583. return ArrayBuffer.isView( object ) &&
  8584. ! ( object instanceof DataView );
  8585. },
  8586. // returns an array by which times and values can be sorted
  8587. getKeyframeOrder: function( times ) {
  8588. function compareTime( i, j ) {
  8589. return times[ i ] - times[ j ];
  8590. }
  8591. var n = times.length;
  8592. var result = new Array( n );
  8593. for ( var i = 0; i !== n; ++ i ) result[ i ] = i;
  8594. result.sort( compareTime );
  8595. return result;
  8596. },
  8597. // uses the array previously returned by 'getKeyframeOrder' to sort data
  8598. sortedArray: function( values, stride, order ) {
  8599. var nValues = values.length;
  8600. var result = new values.constructor( nValues );
  8601. for ( var i = 0, dstOffset = 0; dstOffset !== nValues; ++ i ) {
  8602. var srcOffset = order[ i ] * stride;
  8603. for ( var j = 0; j !== stride; ++ j ) {
  8604. result[ dstOffset ++ ] = values[ srcOffset + j ];
  8605. }
  8606. }
  8607. return result;
  8608. },
  8609. // function for parsing AOS keyframe formats
  8610. flattenJSON: function( jsonKeys, times, values, valuePropertyName ) {
  8611. var i = 1, key = jsonKeys[ 0 ];
  8612. while ( key !== undefined && key[ valuePropertyName ] === undefined ) {
  8613. key = jsonKeys[ i ++ ];
  8614. }
  8615. if ( key === undefined ) return; // no data
  8616. var value = key[ valuePropertyName ];
  8617. if ( value === undefined ) return; // no data
  8618. if ( Array.isArray( value ) ) {
  8619. do {
  8620. value = key[ valuePropertyName ];
  8621. if ( value !== undefined ) {
  8622. times.push( key.time );
  8623. values.push.apply( values, value ); // push all elements
  8624. }
  8625. key = jsonKeys[ i ++ ];
  8626. } while ( key !== undefined );
  8627. } else if ( value.toArray !== undefined ) {
  8628. // ...assume THREE.Math-ish
  8629. do {
  8630. value = key[ valuePropertyName ];
  8631. if ( value !== undefined ) {
  8632. times.push( key.time );
  8633. value.toArray( values, values.length );
  8634. }
  8635. key = jsonKeys[ i ++ ];
  8636. } while ( key !== undefined );
  8637. } else {
  8638. // otherwise push as-is
  8639. do {
  8640. value = key[ valuePropertyName ];
  8641. if ( value !== undefined ) {
  8642. times.push( key.time );
  8643. values.push( value );
  8644. }
  8645. key = jsonKeys[ i ++ ];
  8646. } while ( key !== undefined );
  8647. }
  8648. }
  8649. };
  8650. // File:src/animation/KeyframeTrack.js
  8651. /**
  8652. *
  8653. * A timed sequence of keyframes for a specific property.
  8654. *
  8655. *
  8656. * @author Ben Houston / http://clara.io/
  8657. * @author David Sarno / http://lighthaus.us/
  8658. * @author tschw
  8659. */
  8660. THREE.KeyframeTrack = function ( name, times, values, interpolation ) {
  8661. if( name === undefined ) throw new Error( "track name is undefined" );
  8662. if( times === undefined || times.length === 0 ) {
  8663. throw new Error( "no keyframes in track named " + name );
  8664. }
  8665. this.name = name;
  8666. this.times = THREE.AnimationUtils.convertArray( times, this.TimeBufferType );
  8667. this.values = THREE.AnimationUtils.convertArray( values, this.ValueBufferType );
  8668. this.setInterpolation( interpolation || this.DefaultInterpolation );
  8669. this.validate();
  8670. this.optimize();
  8671. };
  8672. THREE.KeyframeTrack.prototype = {
  8673. constructor: THREE.KeyframeTrack,
  8674. TimeBufferType: Float32Array,
  8675. ValueBufferType: Float32Array,
  8676. DefaultInterpolation: THREE.InterpolateLinear,
  8677. InterpolantFactoryMethodDiscrete: function( result ) {
  8678. return new THREE.DiscreteInterpolant(
  8679. this.times, this.values, this.getValueSize(), result );
  8680. },
  8681. InterpolantFactoryMethodLinear: function( result ) {
  8682. return new THREE.LinearInterpolant(
  8683. this.times, this.values, this.getValueSize(), result );
  8684. },
  8685. InterpolantFactoryMethodSmooth: function( result ) {
  8686. return new THREE.CubicInterpolant(
  8687. this.times, this.values, this.getValueSize(), result );
  8688. },
  8689. setInterpolation: function( interpolation ) {
  8690. var factoryMethod;
  8691. switch ( interpolation ) {
  8692. case THREE.InterpolateDiscrete:
  8693. factoryMethod = this.InterpolantFactoryMethodDiscrete;
  8694. break;
  8695. case THREE.InterpolateLinear:
  8696. factoryMethod = this.InterpolantFactoryMethodLinear;
  8697. break;
  8698. case THREE.InterpolateSmooth:
  8699. factoryMethod = this.InterpolantFactoryMethodSmooth;
  8700. break;
  8701. }
  8702. if ( factoryMethod === undefined ) {
  8703. var message = "unsupported interpolation for " +
  8704. this.ValueTypeName + " keyframe track named " + this.name;
  8705. if ( this.createInterpolant === undefined ) {
  8706. // fall back to default, unless the default itself is messed up
  8707. if ( interpolation !== this.DefaultInterpolation ) {
  8708. this.setInterpolation( this.DefaultInterpolation );
  8709. } else {
  8710. throw new Error( message ); // fatal, in this case
  8711. }
  8712. }
  8713. console.warn( message );
  8714. return;
  8715. }
  8716. this.createInterpolant = factoryMethod;
  8717. },
  8718. getInterpolation: function() {
  8719. switch ( this.createInterpolant ) {
  8720. case this.InterpolantFactoryMethodDiscrete:
  8721. return THREE.InterpolateDiscrete;
  8722. case this.InterpolantFactoryMethodLinear:
  8723. return THREE.InterpolateLinear;
  8724. case this.InterpolantFactoryMethodSmooth:
  8725. return THREE.InterpolateSmooth;
  8726. }
  8727. },
  8728. getValueSize: function() {
  8729. return this.values.length / this.times.length;
  8730. },
  8731. // move all keyframes either forwards or backwards in time
  8732. shift: function( timeOffset ) {
  8733. if( timeOffset !== 0.0 ) {
  8734. var times = this.times;
  8735. for( var i = 0, n = times.length; i !== n; ++ i ) {
  8736. times[ i ] += timeOffset;
  8737. }
  8738. }
  8739. return this;
  8740. },
  8741. // scale all keyframe times by a factor (useful for frame <-> seconds conversions)
  8742. scale: function( timeScale ) {
  8743. if( timeScale !== 1.0 ) {
  8744. var times = this.times;
  8745. for( var i = 0, n = times.length; i !== n; ++ i ) {
  8746. times[ i ] *= timeScale;
  8747. }
  8748. }
  8749. return this;
  8750. },
  8751. // removes keyframes before and after animation without changing any values within the range [startTime, endTime].
  8752. // IMPORTANT: We do not shift around keys to the start of the track time, because for interpolated keys this will change their values
  8753. trim: function( startTime, endTime ) {
  8754. var times = this.times,
  8755. nKeys = times.length,
  8756. from = 0,
  8757. to = nKeys - 1;
  8758. while ( from !== nKeys && times[ from ] < startTime ) ++ from;
  8759. while ( to !== -1 && times[ to ] > endTime ) -- to;
  8760. ++ to; // inclusive -> exclusive bound
  8761. if( from !== 0 || to !== nKeys ) {
  8762. // empty tracks are forbidden, so keep at least one keyframe
  8763. if ( from >= to ) to = Math.max( to , 1 ), from = to - 1;
  8764. var stride = this.getValueSize();
  8765. this.times = THREE.AnimationUtils.arraySlice( times, from, to );
  8766. this.values = THREE.AnimationUtils.
  8767. arraySlice( this.values, from * stride, to * stride );
  8768. }
  8769. return this;
  8770. },
  8771. // ensure we do not get a GarbageInGarbageOut situation, make sure tracks are at least minimally viable
  8772. validate: function() {
  8773. var valid = true;
  8774. var valueSize = this.getValueSize();
  8775. if ( valueSize - Math.floor( valueSize ) !== 0 ) {
  8776. console.error( "invalid value size in track", this );
  8777. valid = false;
  8778. }
  8779. var times = this.times,
  8780. values = this.values,
  8781. nKeys = times.length;
  8782. if( nKeys === 0 ) {
  8783. console.error( "track is empty", this );
  8784. valid = false;
  8785. }
  8786. var prevTime = null;
  8787. for( var i = 0; i !== nKeys; i ++ ) {
  8788. var currTime = times[ i ];
  8789. if ( typeof currTime === 'number' && isNaN( currTime ) ) {
  8790. console.error( "time is not a valid number", this, i, currTime );
  8791. valid = false;
  8792. break;
  8793. }
  8794. if( prevTime !== null && prevTime > currTime ) {
  8795. console.error( "out of order keys", this, i, currTime, prevTime );
  8796. valid = false;
  8797. break;
  8798. }
  8799. prevTime = currTime;
  8800. }
  8801. if ( values !== undefined ) {
  8802. if ( THREE.AnimationUtils.isTypedArray( values ) ) {
  8803. for ( var i = 0, n = values.length; i !== n; ++ i ) {
  8804. var value = values[ i ];
  8805. if ( isNaN( value ) ) {
  8806. console.error( "value is not a valid number", this, i, value );
  8807. valid = false;
  8808. break;
  8809. }
  8810. }
  8811. }
  8812. }
  8813. return valid;
  8814. },
  8815. // removes equivalent sequential keys as common in morph target sequences
  8816. // (0,0,0,0,1,1,1,0,0,0,0,0,0,0) --> (0,0,1,1,0,0)
  8817. optimize: function() {
  8818. var times = this.times,
  8819. values = this.values,
  8820. stride = this.getValueSize(),
  8821. writeIndex = 1;
  8822. for( var i = 1, n = times.length - 1; i <= n; ++ i ) {
  8823. var keep = false;
  8824. var time = times[ i ];
  8825. var timeNext = times[ i + 1 ];
  8826. // remove adjacent keyframes scheduled at the same time
  8827. if ( time !== timeNext && ( i !== 1 || time !== time[ 0 ] ) ) {
  8828. // remove unnecessary keyframes same as their neighbors
  8829. var offset = i * stride,
  8830. offsetP = offset - stride,
  8831. offsetN = offset + stride;
  8832. for ( var j = 0; j !== stride; ++ j ) {
  8833. var value = values[ offset + j ];
  8834. if ( value !== values[ offsetP + j ] ||
  8835. value !== values[ offsetN + j ] ) {
  8836. keep = true;
  8837. break;
  8838. }
  8839. }
  8840. }
  8841. // in-place compaction
  8842. if ( keep ) {
  8843. if ( i !== writeIndex ) {
  8844. times[ writeIndex ] = times[ i ];
  8845. var readOffset = i * stride,
  8846. writeOffset = writeIndex * stride;
  8847. for ( var j = 0; j !== stride; ++ j ) {
  8848. values[ writeOffset + j ] = values[ readOffset + j ];
  8849. }
  8850. }
  8851. ++ writeIndex;
  8852. }
  8853. }
  8854. if ( writeIndex !== times.length ) {
  8855. this.times = THREE.AnimationUtils.arraySlice( times, 0, writeIndex );
  8856. this.values = THREE.AnimationUtils.arraySlice( values, 0, writeIndex * stride );
  8857. }
  8858. return this;
  8859. }
  8860. };
  8861. // Static methods:
  8862. Object.assign( THREE.KeyframeTrack, {
  8863. // Serialization (in static context, because of constructor invocation
  8864. // and automatic invocation of .toJSON):
  8865. parse: function( json ) {
  8866. if( json.type === undefined ) {
  8867. throw new Error( "track type undefined, can not parse" );
  8868. }
  8869. var trackType = THREE.KeyframeTrack._getTrackTypeForValueTypeName( json.type );
  8870. if ( json.times === undefined ) {
  8871. var times = [], values = [];
  8872. THREE.AnimationUtils.flattenJSON( json.keys, times, values, 'value' );
  8873. json.times = times;
  8874. json.values = values;
  8875. }
  8876. // derived classes can define a static parse method
  8877. if ( trackType.parse !== undefined ) {
  8878. return trackType.parse( json );
  8879. } else {
  8880. // by default, we asssume a constructor compatible with the base
  8881. return new trackType(
  8882. json.name, json.times, json.values, json.interpolation );
  8883. }
  8884. },
  8885. toJSON: function( track ) {
  8886. var trackType = track.constructor;
  8887. var json;
  8888. // derived classes can define a static toJSON method
  8889. if ( trackType.toJSON !== undefined ) {
  8890. json = trackType.toJSON( track );
  8891. } else {
  8892. // by default, we assume the data can be serialized as-is
  8893. json = {
  8894. 'name': track.name,
  8895. 'times': THREE.AnimationUtils.convertArray( track.times, Array ),
  8896. 'values': THREE.AnimationUtils.convertArray( track.values, Array )
  8897. };
  8898. var interpolation = track.getInterpolation();
  8899. if ( interpolation !== track.DefaultInterpolation ) {
  8900. json.interpolation = interpolation;
  8901. }
  8902. }
  8903. json.type = track.ValueTypeName; // mandatory
  8904. return json;
  8905. },
  8906. _getTrackTypeForValueTypeName: function( typeName ) {
  8907. switch( typeName.toLowerCase() ) {
  8908. case "scalar":
  8909. case "double":
  8910. case "float":
  8911. case "number":
  8912. case "integer":
  8913. return THREE.NumberKeyframeTrack;
  8914. case "vector":
  8915. case "vector2":
  8916. case "vector3":
  8917. case "vector4":
  8918. return THREE.VectorKeyframeTrack;
  8919. case "color":
  8920. return THREE.ColorKeyframeTrack;
  8921. case "quaternion":
  8922. return THREE.QuaternionKeyframeTrack;
  8923. case "bool":
  8924. case "boolean":
  8925. return THREE.BooleanKeyframeTrack;
  8926. case "string":
  8927. return THREE.StringKeyframeTrack;
  8928. }
  8929. throw new Error( "Unsupported typeName: " + typeName );
  8930. }
  8931. } );
  8932. // File:src/animation/PropertyBinding.js
  8933. /**
  8934. *
  8935. * A reference to a real property in the scene graph.
  8936. *
  8937. *
  8938. * @author Ben Houston / http://clara.io/
  8939. * @author David Sarno / http://lighthaus.us/
  8940. * @author tschw
  8941. */
  8942. THREE.PropertyBinding = function ( rootNode, path, parsedPath ) {
  8943. this.path = path;
  8944. this.parsedPath = parsedPath ||
  8945. THREE.PropertyBinding.parseTrackName( path );
  8946. this.node = THREE.PropertyBinding.findNode(
  8947. rootNode, this.parsedPath.nodeName ) || rootNode;
  8948. this.rootNode = rootNode;
  8949. };
  8950. THREE.PropertyBinding.prototype = {
  8951. constructor: THREE.PropertyBinding,
  8952. getValue: function getValue_unbound( targetArray, offset ) {
  8953. this.bind();
  8954. this.getValue( targetArray, offset );
  8955. // Note: This class uses a State pattern on a per-method basis:
  8956. // 'bind' sets 'this.getValue' / 'setValue' and shadows the
  8957. // prototype version of these methods with one that represents
  8958. // the bound state. When the property is not found, the methods
  8959. // become no-ops.
  8960. },
  8961. setValue: function getValue_unbound( sourceArray, offset ) {
  8962. this.bind();
  8963. this.setValue( sourceArray, offset );
  8964. },
  8965. // create getter / setter pair for a property in the scene graph
  8966. bind: function() {
  8967. var targetObject = this.node,
  8968. parsedPath = this.parsedPath,
  8969. objectName = parsedPath.objectName,
  8970. propertyName = parsedPath.propertyName,
  8971. propertyIndex = parsedPath.propertyIndex;
  8972. if ( ! targetObject ) {
  8973. targetObject = THREE.PropertyBinding.findNode(
  8974. this.rootNode, parsedPath.nodeName ) || this.rootNode;
  8975. this.node = targetObject;
  8976. }
  8977. // set fail state so we can just 'return' on error
  8978. this.getValue = this._getValue_unavailable;
  8979. this.setValue = this._setValue_unavailable;
  8980. // ensure there is a value node
  8981. if ( ! targetObject ) {
  8982. console.error( " trying to update node for track: " + this.path + " but it wasn't found." );
  8983. return;
  8984. }
  8985. if ( objectName ) {
  8986. var objectIndex = parsedPath.objectIndex;
  8987. // special cases were we need to reach deeper into the hierarchy to get the face materials....
  8988. switch ( objectName ) {
  8989. case 'materials':
  8990. if ( ! targetObject.material ) {
  8991. console.error( ' can not bind to material as node does not have a material', this );
  8992. return;
  8993. }
  8994. if ( ! targetObject.material.materials ) {
  8995. console.error( ' can not bind to material.materials as node.material does not have a materials array', this );
  8996. return;
  8997. }
  8998. targetObject = targetObject.material.materials;
  8999. break;
  9000. case 'bones':
  9001. if ( ! targetObject.skeleton ) {
  9002. console.error( ' can not bind to bones as node does not have a skeleton', this );
  9003. return;
  9004. }
  9005. // potential future optimization: skip this if propertyIndex is already an integer
  9006. // and convert the integer string to a true integer.
  9007. targetObject = targetObject.skeleton.bones;
  9008. // support resolving morphTarget names into indices.
  9009. for ( var i = 0; i < targetObject.length; i ++ ) {
  9010. if ( targetObject[ i ].name === objectIndex ) {
  9011. objectIndex = i;
  9012. break;
  9013. }
  9014. }
  9015. break;
  9016. default:
  9017. if ( targetObject[ objectName ] === undefined ) {
  9018. console.error( ' can not bind to objectName of node, undefined', this );
  9019. return;
  9020. }
  9021. targetObject = targetObject[ objectName ];
  9022. }
  9023. if ( objectIndex !== undefined ) {
  9024. if ( targetObject[ objectIndex ] === undefined ) {
  9025. console.error( " trying to bind to objectIndex of objectName, but is undefined:", this, targetObject );
  9026. return;
  9027. }
  9028. targetObject = targetObject[ objectIndex ];
  9029. }
  9030. }
  9031. // resolve property
  9032. var nodeProperty = targetObject[ propertyName ];
  9033. if ( nodeProperty === undefined ) {
  9034. var nodeName = parsedPath.nodeName;
  9035. console.error( " trying to update property for track: " + nodeName +
  9036. '.' + propertyName + " but it wasn't found.", targetObject );
  9037. return;
  9038. }
  9039. // determine versioning scheme
  9040. var versioning = this.Versioning.None;
  9041. if ( targetObject.needsUpdate !== undefined ) { // material
  9042. versioning = this.Versioning.NeedsUpdate;
  9043. this.targetObject = targetObject;
  9044. } else if ( targetObject.matrixWorldNeedsUpdate !== undefined ) { // node transform
  9045. versioning = this.Versioning.MatrixWorldNeedsUpdate;
  9046. this.targetObject = targetObject;
  9047. }
  9048. // determine how the property gets bound
  9049. var bindingType = this.BindingType.Direct;
  9050. if ( propertyIndex !== undefined ) {
  9051. // access a sub element of the property array (only primitives are supported right now)
  9052. if ( propertyName === "morphTargetInfluences" ) {
  9053. // potential optimization, skip this if propertyIndex is already an integer, and convert the integer string to a true integer.
  9054. // support resolving morphTarget names into indices.
  9055. if ( ! targetObject.geometry ) {
  9056. console.error( ' can not bind to morphTargetInfluences becasuse node does not have a geometry', this );
  9057. return;
  9058. }
  9059. if ( ! targetObject.geometry.morphTargets ) {
  9060. console.error( ' can not bind to morphTargetInfluences becasuse node does not have a geometry.morphTargets', this );
  9061. return;
  9062. }
  9063. for ( var i = 0; i < this.node.geometry.morphTargets.length; i ++ ) {
  9064. if ( targetObject.geometry.morphTargets[ i ].name === propertyIndex ) {
  9065. propertyIndex = i;
  9066. break;
  9067. }
  9068. }
  9069. }
  9070. bindingType = this.BindingType.ArrayElement;
  9071. this.resolvedProperty = nodeProperty;
  9072. this.propertyIndex = propertyIndex;
  9073. } else if ( nodeProperty.fromArray !== undefined && nodeProperty.toArray !== undefined ) {
  9074. // must use copy for Object3D.Euler/Quaternion
  9075. bindingType = this.BindingType.HasFromToArray;
  9076. this.resolvedProperty = nodeProperty;
  9077. } else if ( nodeProperty.length !== undefined ) {
  9078. bindingType = this.BindingType.EntireArray;
  9079. this.resolvedProperty = nodeProperty;
  9080. } else {
  9081. this.propertyName = propertyName;
  9082. }
  9083. // select getter / setter
  9084. this.getValue = this.GetterByBindingType[ bindingType ];
  9085. this.setValue = this.SetterByBindingTypeAndVersioning[ bindingType ][ versioning ];
  9086. },
  9087. unbind: function() {
  9088. this.node = null;
  9089. // back to the prototype version of getValue / setValue
  9090. // note: avoiding to mutate the shape of 'this' via 'delete'
  9091. this.getValue = this._getValue_unbound;
  9092. this.setValue = this._setValue_unbound;
  9093. }
  9094. };
  9095. Object.assign( THREE.PropertyBinding.prototype, { // prototype, continued
  9096. // these are used to "bind" a nonexistent property
  9097. _getValue_unavailable: function() {},
  9098. _setValue_unavailable: function() {},
  9099. // initial state of these methods that calls 'bind'
  9100. _getValue_unbound: THREE.PropertyBinding.prototype.getValue,
  9101. _setValue_unbound: THREE.PropertyBinding.prototype.setValue,
  9102. BindingType: {
  9103. Direct: 0,
  9104. EntireArray: 1,
  9105. ArrayElement: 2,
  9106. HasFromToArray: 3
  9107. },
  9108. Versioning: {
  9109. None: 0,
  9110. NeedsUpdate: 1,
  9111. MatrixWorldNeedsUpdate: 2
  9112. },
  9113. GetterByBindingType: [
  9114. function getValue_direct( buffer, offset ) {
  9115. buffer[ offset ] = this.node[ this.propertyName ];
  9116. },
  9117. function getValue_array( buffer, offset ) {
  9118. var source = this.resolvedProperty;
  9119. for ( var i = 0, n = source.length; i !== n; ++ i ) {
  9120. buffer[ offset ++ ] = source[ i ];
  9121. }
  9122. },
  9123. function getValue_arrayElement( buffer, offset ) {
  9124. buffer[ offset ] = this.resolvedProperty[ this.propertyIndex ];
  9125. },
  9126. function getValue_toArray( buffer, offset ) {
  9127. this.resolvedProperty.toArray( buffer, offset );
  9128. }
  9129. ],
  9130. SetterByBindingTypeAndVersioning: [
  9131. [
  9132. // Direct
  9133. function setValue_direct( buffer, offset ) {
  9134. this.node[ this.propertyName ] = buffer[ offset ];
  9135. },
  9136. function setValue_direct_setNeedsUpdate( buffer, offset ) {
  9137. this.node[ this.propertyName ] = buffer[ offset ];
  9138. this.targetObject.needsUpdate = true;
  9139. },
  9140. function setValue_direct_setMatrixWorldNeedsUpdate( buffer, offset ) {
  9141. this.node[ this.propertyName ] = buffer[ offset ];
  9142. this.targetObject.matrixWorldNeedsUpdate = true;
  9143. }
  9144. ], [
  9145. // EntireArray
  9146. function setValue_array( buffer, offset ) {
  9147. var dest = this.resolvedProperty;
  9148. for ( var i = 0, n = dest.length; i !== n; ++ i ) {
  9149. dest[ i ] = buffer[ offset ++ ];
  9150. }
  9151. },
  9152. function setValue_array_setNeedsUpdate( buffer, offset ) {
  9153. var dest = this.resolvedProperty;
  9154. for ( var i = 0, n = dest.length; i !== n; ++ i ) {
  9155. dest[ i ] = buffer[ offset ++ ];
  9156. }
  9157. this.targetObject.needsUpdate = true;
  9158. },
  9159. function setValue_array_setMatrixWorldNeedsUpdate( buffer, offset ) {
  9160. var dest = this.resolvedProperty;
  9161. for ( var i = 0, n = dest.length; i !== n; ++ i ) {
  9162. dest[ i ] = buffer[ offset ++ ];
  9163. }
  9164. this.targetObject.matrixWorldNeedsUpdate = true;
  9165. }
  9166. ], [
  9167. // ArrayElement
  9168. function setValue_arrayElement( buffer, offset ) {
  9169. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  9170. },
  9171. function setValue_arrayElement_setNeedsUpdate( buffer, offset ) {
  9172. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  9173. this.targetObject.needsUpdate = true;
  9174. },
  9175. function setValue_arrayElement_setMatrixWorldNeedsUpdate( buffer, offset ) {
  9176. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  9177. this.targetObject.matrixWorldNeedsUpdate = true;
  9178. }
  9179. ], [
  9180. // HasToFromArray
  9181. function setValue_fromArray( buffer, offset ) {
  9182. this.resolvedProperty.fromArray( buffer, offset );
  9183. },
  9184. function setValue_fromArray_setNeedsUpdate( buffer, offset ) {
  9185. this.resolvedProperty.fromArray( buffer, offset );
  9186. this.targetObject.needsUpdate = true;
  9187. },
  9188. function setValue_fromArray_setMatrixWorldNeedsUpdate( buffer, offset ) {
  9189. this.resolvedProperty.fromArray( buffer, offset );
  9190. this.targetObject.matrixWorldNeedsUpdate = true;
  9191. }
  9192. ]
  9193. ]
  9194. } );
  9195. THREE.PropertyBinding.Composite =
  9196. function( targetGroup, path, optionalParsedPath ) {
  9197. var parsedPath = optionalParsedPath ||
  9198. THREE.PropertyBinding.parseTrackName( path );
  9199. this._targetGroup = targetGroup;
  9200. this._bindings = targetGroup.subscribe_( path, parsedPath );
  9201. };
  9202. THREE.PropertyBinding.Composite.prototype = {
  9203. constructor: THREE.PropertyBinding.Composite,
  9204. getValue: function( array, offset ) {
  9205. this.bind(); // bind all binding
  9206. var firstValidIndex = this._targetGroup.nCachedObjects_,
  9207. binding = this._bindings[ firstValidIndex ];
  9208. // and only call .getValue on the first
  9209. if ( binding !== undefined ) binding.getValue( array, offset );
  9210. },
  9211. setValue: function( array, offset ) {
  9212. var bindings = this._bindings;
  9213. for ( var i = this._targetGroup.nCachedObjects_,
  9214. n = bindings.length; i !== n; ++ i ) {
  9215. bindings[ i ].setValue( array, offset );
  9216. }
  9217. },
  9218. bind: function() {
  9219. var bindings = this._bindings;
  9220. for ( var i = this._targetGroup.nCachedObjects_,
  9221. n = bindings.length; i !== n; ++ i ) {
  9222. bindings[ i ].bind();
  9223. }
  9224. },
  9225. unbind: function() {
  9226. var bindings = this._bindings;
  9227. for ( var i = this._targetGroup.nCachedObjects_,
  9228. n = bindings.length; i !== n; ++ i ) {
  9229. bindings[ i ].unbind();
  9230. }
  9231. }
  9232. };
  9233. THREE.PropertyBinding.create = function( root, path, parsedPath ) {
  9234. if ( ! ( root instanceof THREE.AnimationObjectGroup ) ) {
  9235. return new THREE.PropertyBinding( root, path, parsedPath );
  9236. } else {
  9237. return new THREE.PropertyBinding.Composite( root, path, parsedPath );
  9238. }
  9239. };
  9240. THREE.PropertyBinding.parseTrackName = function( trackName ) {
  9241. // matches strings in the form of:
  9242. // nodeName.property
  9243. // nodeName.property[accessor]
  9244. // nodeName.material.property[accessor]
  9245. // uuid.property[accessor]
  9246. // uuid.objectName[objectIndex].propertyName[propertyIndex]
  9247. // parentName/nodeName.property
  9248. // parentName/parentName/nodeName.property[index]
  9249. // .bone[Armature.DEF_cog].position
  9250. // created and tested via https://regex101.com/#javascript
  9251. var re = /^(([\w]+\/)*)([\w-\d]+)?(\.([\w]+)(\[([\w\d\[\]\_.:\- ]+)\])?)?(\.([\w.]+)(\[([\w\d\[\]\_. ]+)\])?)$/;
  9252. var matches = re.exec( trackName );
  9253. if ( ! matches ) {
  9254. throw new Error( "cannot parse trackName at all: " + trackName );
  9255. }
  9256. if ( matches.index === re.lastIndex ) {
  9257. re.lastIndex++;
  9258. }
  9259. var results = {
  9260. // directoryName: matches[ 1 ], // (tschw) currently unused
  9261. nodeName: matches[ 3 ], // allowed to be null, specified root node.
  9262. objectName: matches[ 5 ],
  9263. objectIndex: matches[ 7 ],
  9264. propertyName: matches[ 9 ],
  9265. propertyIndex: matches[ 11 ] // allowed to be null, specifies that the whole property is set.
  9266. };
  9267. if ( results.propertyName === null || results.propertyName.length === 0 ) {
  9268. throw new Error( "can not parse propertyName from trackName: " + trackName );
  9269. }
  9270. return results;
  9271. };
  9272. THREE.PropertyBinding.findNode = function( root, nodeName ) {
  9273. if ( ! nodeName || nodeName === "" || nodeName === "root" || nodeName === "." || nodeName === -1 || nodeName === root.name || nodeName === root.uuid ) {
  9274. return root;
  9275. }
  9276. // search into skeleton bones.
  9277. if ( root.skeleton ) {
  9278. var searchSkeleton = function( skeleton ) {
  9279. for( var i = 0; i < skeleton.bones.length; i ++ ) {
  9280. var bone = skeleton.bones[ i ];
  9281. if ( bone.name === nodeName ) {
  9282. return bone;
  9283. }
  9284. }
  9285. return null;
  9286. };
  9287. var bone = searchSkeleton( root.skeleton );
  9288. if ( bone ) {
  9289. return bone;
  9290. }
  9291. }
  9292. // search into node subtree.
  9293. if ( root.children ) {
  9294. var searchNodeSubtree = function( children ) {
  9295. for( var i = 0; i < children.length; i ++ ) {
  9296. var childNode = children[ i ];
  9297. if ( childNode.name === nodeName || childNode.uuid === nodeName ) {
  9298. return childNode;
  9299. }
  9300. var result = searchNodeSubtree( childNode.children );
  9301. if ( result ) return result;
  9302. }
  9303. return null;
  9304. };
  9305. var subTreeNode = searchNodeSubtree( root.children );
  9306. if ( subTreeNode ) {
  9307. return subTreeNode;
  9308. }
  9309. }
  9310. return null;
  9311. };
  9312. // File:src/animation/PropertyMixer.js
  9313. /**
  9314. *
  9315. * Buffered scene graph property that allows weighted accumulation.
  9316. *
  9317. *
  9318. * @author Ben Houston / http://clara.io/
  9319. * @author David Sarno / http://lighthaus.us/
  9320. * @author tschw
  9321. */
  9322. THREE.PropertyMixer = function ( binding, typeName, valueSize ) {
  9323. this.binding = binding;
  9324. this.valueSize = valueSize;
  9325. var bufferType = Float64Array,
  9326. mixFunction;
  9327. switch ( typeName ) {
  9328. case 'quaternion': mixFunction = this._slerp; break;
  9329. case 'string':
  9330. case 'bool':
  9331. bufferType = Array, mixFunction = this._select; break;
  9332. default: mixFunction = this._lerp;
  9333. }
  9334. this.buffer = new bufferType( valueSize * 4 );
  9335. // layout: [ incoming | accu0 | accu1 | orig ]
  9336. //
  9337. // interpolators can use .buffer as their .result
  9338. // the data then goes to 'incoming'
  9339. //
  9340. // 'accu0' and 'accu1' are used frame-interleaved for
  9341. // the cumulative result and are compared to detect
  9342. // changes
  9343. //
  9344. // 'orig' stores the original state of the property
  9345. this._mixBufferRegion = mixFunction;
  9346. this.cumulativeWeight = 0;
  9347. this.useCount = 0;
  9348. this.referenceCount = 0;
  9349. };
  9350. THREE.PropertyMixer.prototype = {
  9351. constructor: THREE.PropertyMixer,
  9352. // accumulate data in the 'incoming' region into 'accu<i>'
  9353. accumulate: function( accuIndex, weight ) {
  9354. // note: happily accumulating nothing when weight = 0, the caller knows
  9355. // the weight and shouldn't have made the call in the first place
  9356. var buffer = this.buffer,
  9357. stride = this.valueSize,
  9358. offset = accuIndex * stride + stride,
  9359. currentWeight = this.cumulativeWeight;
  9360. if ( currentWeight === 0 ) {
  9361. // accuN := incoming * weight
  9362. for ( var i = 0; i !== stride; ++ i ) {
  9363. buffer[ offset + i ] = buffer[ i ];
  9364. }
  9365. currentWeight = weight;
  9366. } else {
  9367. // accuN := accuN + incoming * weight
  9368. currentWeight += weight;
  9369. var mix = weight / currentWeight;
  9370. this._mixBufferRegion( buffer, offset, 0, mix, stride );
  9371. }
  9372. this.cumulativeWeight = currentWeight;
  9373. },
  9374. // apply the state of 'accu<i>' to the binding when accus differ
  9375. apply: function( accuIndex ) {
  9376. var stride = this.valueSize,
  9377. buffer = this.buffer,
  9378. offset = accuIndex * stride + stride,
  9379. weight = this.cumulativeWeight,
  9380. binding = this.binding;
  9381. this.cumulativeWeight = 0;
  9382. if ( weight < 1 ) {
  9383. // accuN := accuN + original * ( 1 - cumulativeWeight )
  9384. var originalValueOffset = stride * 3;
  9385. this._mixBufferRegion(
  9386. buffer, offset, originalValueOffset, 1 - weight, stride );
  9387. }
  9388. for ( var i = stride, e = stride + stride; i !== e; ++ i ) {
  9389. if ( buffer[ i ] !== buffer[ i + stride ] ) {
  9390. // value has changed -> update scene graph
  9391. binding.setValue( buffer, offset );
  9392. break;
  9393. }
  9394. }
  9395. },
  9396. // remember the state of the bound property and copy it to both accus
  9397. saveOriginalState: function() {
  9398. var binding = this.binding;
  9399. var buffer = this.buffer,
  9400. stride = this.valueSize,
  9401. originalValueOffset = stride * 3;
  9402. binding.getValue( buffer, originalValueOffset );
  9403. // accu[0..1] := orig -- initially detect changes against the original
  9404. for ( var i = stride, e = originalValueOffset; i !== e; ++ i ) {
  9405. buffer[ i ] = buffer[ originalValueOffset + ( i % stride ) ];
  9406. }
  9407. this.cumulativeWeight = 0;
  9408. },
  9409. // apply the state previously taken via 'saveOriginalState' to the binding
  9410. restoreOriginalState: function() {
  9411. var originalValueOffset = this.valueSize * 3;
  9412. this.binding.setValue( this.buffer, originalValueOffset );
  9413. },
  9414. // mix functions
  9415. _select: function( buffer, dstOffset, srcOffset, t, stride ) {
  9416. if ( t >= 0.5 ) {
  9417. for ( var i = 0; i !== stride; ++ i ) {
  9418. buffer[ dstOffset + i ] = buffer[ srcOffset + i ];
  9419. }
  9420. }
  9421. },
  9422. _slerp: function( buffer, dstOffset, srcOffset, t, stride ) {
  9423. THREE.Quaternion.slerpFlat( buffer, dstOffset,
  9424. buffer, dstOffset, buffer, srcOffset, t );
  9425. },
  9426. _lerp: function( buffer, dstOffset, srcOffset, t, stride ) {
  9427. var s = 1 - t;
  9428. for ( var i = 0; i !== stride; ++ i ) {
  9429. var j = dstOffset + i;
  9430. buffer[ j ] = buffer[ j ] * s + buffer[ srcOffset + i ] * t;
  9431. }
  9432. }
  9433. };
  9434. // File:src/animation/tracks/BooleanKeyframeTrack.js
  9435. /**
  9436. *
  9437. * A Track of Boolean keyframe values.
  9438. *
  9439. *
  9440. * @author Ben Houston / http://clara.io/
  9441. * @author David Sarno / http://lighthaus.us/
  9442. * @author tschw
  9443. */
  9444. THREE.BooleanKeyframeTrack = function ( name, times, values ) {
  9445. THREE.KeyframeTrack.call( this, name, times, values );
  9446. };
  9447. THREE.BooleanKeyframeTrack.prototype =
  9448. Object.assign( Object.create( THREE.KeyframeTrack.prototype ), {
  9449. constructor: THREE.BooleanKeyframeTrack,
  9450. ValueTypeName: 'bool',
  9451. ValueBufferType: Array,
  9452. DefaultInterpolation: THREE.InterpolateDiscrete,
  9453. InterpolantFactoryMethodLinear: undefined,
  9454. InterpolantFactoryMethodSmooth: undefined
  9455. // Note: Actually this track could have a optimized / compressed
  9456. // representation of a single value and a custom interpolant that
  9457. // computes "firstValue ^ isOdd( index )".
  9458. } );
  9459. // File:src/animation/tracks/ColorKeyframeTrack.js
  9460. /**
  9461. *
  9462. * A Track of keyframe values that represent color.
  9463. *
  9464. *
  9465. * @author Ben Houston / http://clara.io/
  9466. * @author David Sarno / http://lighthaus.us/
  9467. * @author tschw
  9468. */
  9469. THREE.ColorKeyframeTrack = function ( name, times, values, interpolation ) {
  9470. THREE.KeyframeTrack.call( this, name, times, values, interpolation );
  9471. };
  9472. THREE.ColorKeyframeTrack.prototype =
  9473. Object.assign( Object.create( THREE.KeyframeTrack.prototype ), {
  9474. constructor: THREE.ColorKeyframeTrack,
  9475. ValueTypeName: 'color'
  9476. // ValueBufferType is inherited
  9477. // DefaultInterpolation is inherited
  9478. // Note: Very basic implementation and nothing special yet.
  9479. // However, this is the place for color space parameterization.
  9480. } );
  9481. // File:src/animation/tracks/NumberKeyframeTrack.js
  9482. /**
  9483. *
  9484. * A Track of numeric keyframe values.
  9485. *
  9486. * @author Ben Houston / http://clara.io/
  9487. * @author David Sarno / http://lighthaus.us/
  9488. * @author tschw
  9489. */
  9490. THREE.NumberKeyframeTrack = function ( name, times, values, interpolation ) {
  9491. THREE.KeyframeTrack.call( this, name, times, values, interpolation );
  9492. };
  9493. THREE.NumberKeyframeTrack.prototype =
  9494. Object.assign( Object.create( THREE.KeyframeTrack.prototype ), {
  9495. constructor: THREE.NumberKeyframeTrack,
  9496. ValueTypeName: 'number',
  9497. // ValueBufferType is inherited
  9498. // DefaultInterpolation is inherited
  9499. } );
  9500. // File:src/animation/tracks/QuaternionKeyframeTrack.js
  9501. /**
  9502. *
  9503. * A Track of quaternion keyframe values.
  9504. *
  9505. * @author Ben Houston / http://clara.io/
  9506. * @author David Sarno / http://lighthaus.us/
  9507. * @author tschw
  9508. */
  9509. THREE.QuaternionKeyframeTrack = function ( name, times, values, interpolation ) {
  9510. THREE.KeyframeTrack.call( this, name, times, values, interpolation );
  9511. };
  9512. THREE.QuaternionKeyframeTrack.prototype =
  9513. Object.assign( Object.create( THREE.KeyframeTrack.prototype ), {
  9514. constructor: THREE.QuaternionKeyframeTrack,
  9515. ValueTypeName: 'quaternion',
  9516. // ValueBufferType is inherited
  9517. DefaultInterpolation: THREE.InterpolateLinear,
  9518. InterpolantFactoryMethodLinear: function( result ) {
  9519. return new THREE.QuaternionLinearInterpolant(
  9520. this.times, this.values, this.getValueSize(), result );
  9521. },
  9522. InterpolantFactoryMethodSmooth: undefined // not yet implemented
  9523. } );
  9524. // File:src/animation/tracks/StringKeyframeTrack.js
  9525. /**
  9526. *
  9527. * A Track that interpolates Strings
  9528. *
  9529. *
  9530. * @author Ben Houston / http://clara.io/
  9531. * @author David Sarno / http://lighthaus.us/
  9532. * @author tschw
  9533. */
  9534. THREE.StringKeyframeTrack = function ( name, times, values, interpolation ) {
  9535. THREE.KeyframeTrack.call( this, name, times, values, interpolation );
  9536. };
  9537. THREE.StringKeyframeTrack.prototype =
  9538. Object.assign( Object.create( THREE.KeyframeTrack.prototype ), {
  9539. constructor: THREE.StringKeyframeTrack,
  9540. ValueTypeName: 'string',
  9541. ValueBufferType: Array,
  9542. DefaultInterpolation: THREE.InterpolateDiscrete,
  9543. InterpolantFactoryMethodLinear: undefined,
  9544. InterpolantFactoryMethodSmooth: undefined
  9545. } );
  9546. // File:src/animation/tracks/VectorKeyframeTrack.js
  9547. /**
  9548. *
  9549. * A Track of vectored keyframe values.
  9550. *
  9551. *
  9552. * @author Ben Houston / http://clara.io/
  9553. * @author David Sarno / http://lighthaus.us/
  9554. * @author tschw
  9555. */
  9556. THREE.VectorKeyframeTrack = function ( name, times, values, interpolation ) {
  9557. THREE.KeyframeTrack.call( this, name, times, values, interpolation );
  9558. };
  9559. THREE.VectorKeyframeTrack.prototype =
  9560. Object.assign( Object.create( THREE.KeyframeTrack.prototype ), {
  9561. constructor: THREE.VectorKeyframeTrack,
  9562. ValueTypeName: 'vector'
  9563. // ValueBufferType is inherited
  9564. // DefaultInterpolation is inherited
  9565. } );
  9566. // File:src/audio/Audio.js
  9567. /**
  9568. * @author mrdoob / http://mrdoob.com/
  9569. * @author Reece Aaron Lecrivain / http://reecenotes.com/
  9570. */
  9571. THREE.Audio = function ( listener ) {
  9572. THREE.Object3D.call( this );
  9573. this.type = 'Audio';
  9574. this.context = listener.context;
  9575. this.source = this.context.createBufferSource();
  9576. this.source.onended = this.onEnded.bind( this );
  9577. this.gain = this.context.createGain();
  9578. this.gain.connect( listener.getInput() );
  9579. this.autoplay = false;
  9580. this.startTime = 0;
  9581. this.playbackRate = 1;
  9582. this.isPlaying = false;
  9583. this.hasPlaybackControl = true;
  9584. this.sourceType = 'empty';
  9585. this.filters = [];
  9586. };
  9587. THREE.Audio.prototype = Object.assign( Object.create( THREE.Object3D.prototype ), {
  9588. constructor: THREE.Audio,
  9589. getOutput: function () {
  9590. return this.gain;
  9591. },
  9592. setNodeSource: function ( audioNode ) {
  9593. this.hasPlaybackControl = false;
  9594. this.sourceType = 'audioNode';
  9595. this.source = audioNode;
  9596. this.connect();
  9597. return this;
  9598. },
  9599. setBuffer: function ( audioBuffer ) {
  9600. this.source.buffer = audioBuffer;
  9601. this.sourceType = 'buffer';
  9602. if ( this.autoplay ) this.play();
  9603. return this;
  9604. },
  9605. play: function () {
  9606. if ( this.isPlaying === true ) {
  9607. console.warn( 'THREE.Audio: Audio is already playing.' );
  9608. return;
  9609. }
  9610. if ( this.hasPlaybackControl === false ) {
  9611. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  9612. return;
  9613. }
  9614. var source = this.context.createBufferSource();
  9615. source.buffer = this.source.buffer;
  9616. source.loop = this.source.loop;
  9617. source.onended = this.source.onended;
  9618. source.start( 0, this.startTime );
  9619. source.playbackRate.value = this.playbackRate;
  9620. this.isPlaying = true;
  9621. this.source = source;
  9622. return this.connect();
  9623. },
  9624. pause: function () {
  9625. if ( this.hasPlaybackControl === false ) {
  9626. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  9627. return;
  9628. }
  9629. this.source.stop();
  9630. this.startTime = this.context.currentTime;
  9631. this.isPlaying = false;
  9632. return this;
  9633. },
  9634. stop: function () {
  9635. if ( this.hasPlaybackControl === false ) {
  9636. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  9637. return;
  9638. }
  9639. this.source.stop();
  9640. this.startTime = 0;
  9641. this.isPlaying = false;
  9642. return this;
  9643. },
  9644. connect: function () {
  9645. if ( this.filters.length > 0 ) {
  9646. this.source.connect( this.filters[ 0 ] );
  9647. for ( var i = 1, l = this.filters.length; i < l; i ++ ) {
  9648. this.filters[ i - 1 ].connect( this.filters[ i ] );
  9649. }
  9650. this.filters[ this.filters.length - 1 ].connect( this.getOutput() );
  9651. } else {
  9652. this.source.connect( this.getOutput() );
  9653. }
  9654. return this;
  9655. },
  9656. disconnect: function () {
  9657. if ( this.filters.length > 0 ) {
  9658. this.source.disconnect( this.filters[ 0 ] );
  9659. for ( var i = 1, l = this.filters.length; i < l; i ++ ) {
  9660. this.filters[ i - 1 ].disconnect( this.filters[ i ] );
  9661. }
  9662. this.filters[ this.filters.length - 1 ].disconnect( this.getOutput() );
  9663. } else {
  9664. this.source.disconnect( this.getOutput() );
  9665. }
  9666. return this;
  9667. },
  9668. getFilters: function () {
  9669. return this.filters;
  9670. },
  9671. setFilters: function ( value ) {
  9672. if ( ! value ) value = [];
  9673. if ( this.isPlaying === true ) {
  9674. this.disconnect();
  9675. this.filters = value;
  9676. this.connect();
  9677. } else {
  9678. this.filters = value;
  9679. }
  9680. return this;
  9681. },
  9682. getFilter: function () {
  9683. return this.getFilters()[ 0 ];
  9684. },
  9685. setFilter: function ( filter ) {
  9686. return this.setFilters( filter ? [ filter ] : [] );
  9687. },
  9688. setPlaybackRate: function ( value ) {
  9689. if ( this.hasPlaybackControl === false ) {
  9690. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  9691. return;
  9692. }
  9693. this.playbackRate = value;
  9694. if ( this.isPlaying === true ) {
  9695. this.source.playbackRate.value = this.playbackRate;
  9696. }
  9697. return this;
  9698. },
  9699. getPlaybackRate: function () {
  9700. return this.playbackRate;
  9701. },
  9702. onEnded: function () {
  9703. this.isPlaying = false;
  9704. },
  9705. getLoop: function () {
  9706. if ( this.hasPlaybackControl === false ) {
  9707. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  9708. return false;
  9709. }
  9710. return this.source.loop;
  9711. },
  9712. setLoop: function ( value ) {
  9713. if ( this.hasPlaybackControl === false ) {
  9714. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  9715. return;
  9716. }
  9717. this.source.loop = value;
  9718. },
  9719. getVolume: function () {
  9720. return this.gain.gain.value;
  9721. },
  9722. setVolume: function ( value ) {
  9723. this.gain.gain.value = value;
  9724. return this;
  9725. }
  9726. } );
  9727. // File:src/audio/AudioAnalyser.js
  9728. /**
  9729. * @author mrdoob / http://mrdoob.com/
  9730. */
  9731. THREE.AudioAnalyser = function ( audio, fftSize ) {
  9732. this.analyser = audio.context.createAnalyser();
  9733. this.analyser.fftSize = fftSize !== undefined ? fftSize : 2048;
  9734. this.data = new Uint8Array( this.analyser.frequencyBinCount );
  9735. audio.getOutput().connect( this.analyser );
  9736. };
  9737. Object.assign( THREE.AudioAnalyser.prototype, {
  9738. getFrequencyData: function () {
  9739. this.analyser.getByteFrequencyData( this.data );
  9740. return this.data;
  9741. },
  9742. getAverageFrequency: function () {
  9743. var value = 0, data = this.getFrequencyData();
  9744. for ( var i = 0; i < data.length; i ++ ) {
  9745. value += data[ i ];
  9746. }
  9747. return value / data.length;
  9748. }
  9749. } );
  9750. // File:src/audio/AudioContext.js
  9751. /**
  9752. * @author mrdoob / http://mrdoob.com/
  9753. */
  9754. Object.defineProperty( THREE, 'AudioContext', {
  9755. get: ( function () {
  9756. var context;
  9757. return function get() {
  9758. if ( context === undefined ) {
  9759. context = new ( window.AudioContext || window.webkitAudioContext )();
  9760. }
  9761. return context;
  9762. };
  9763. } )()
  9764. } );
  9765. // File:src/audio/PositionalAudio.js
  9766. /**
  9767. * @author mrdoob / http://mrdoob.com/
  9768. */
  9769. THREE.PositionalAudio = function ( listener ) {
  9770. THREE.Audio.call( this, listener );
  9771. this.panner = this.context.createPanner();
  9772. this.panner.connect( this.gain );
  9773. };
  9774. THREE.PositionalAudio.prototype = Object.assign( Object.create( THREE.Audio.prototype ), {
  9775. constructor: THREE.PositionalAudio,
  9776. getOutput: function () {
  9777. return this.panner;
  9778. },
  9779. getRefDistance: function () {
  9780. return this.panner.refDistance;
  9781. },
  9782. setRefDistance: function ( value ) {
  9783. this.panner.refDistance = value;
  9784. },
  9785. getRolloffFactor: function () {
  9786. return this.panner.rolloffFactor;
  9787. },
  9788. setRolloffFactor: function ( value ) {
  9789. this.panner.rolloffFactor = value;
  9790. },
  9791. getDistanceModel: function () {
  9792. return this.panner.distanceModel;
  9793. },
  9794. setDistanceModel: function ( value ) {
  9795. this.panner.distanceModel = value;
  9796. },
  9797. getMaxDistance: function () {
  9798. return this.panner.maxDistance;
  9799. },
  9800. setMaxDistance: function ( value ) {
  9801. this.panner.maxDistance = value;
  9802. },
  9803. updateMatrixWorld: ( function () {
  9804. var position = new THREE.Vector3();
  9805. return function updateMatrixWorld( force ) {
  9806. THREE.Object3D.prototype.updateMatrixWorld.call( this, force );
  9807. position.setFromMatrixPosition( this.matrixWorld );
  9808. this.panner.setPosition( position.x, position.y, position.z );
  9809. };
  9810. } )()
  9811. } );
  9812. // File:src/audio/AudioListener.js
  9813. /**
  9814. * @author mrdoob / http://mrdoob.com/
  9815. */
  9816. THREE.AudioListener = function () {
  9817. THREE.Object3D.call( this );
  9818. this.type = 'AudioListener';
  9819. this.context = THREE.AudioContext;
  9820. this.gain = this.context.createGain();
  9821. this.gain.connect( this.context.destination );
  9822. this.filter = null;
  9823. };
  9824. THREE.AudioListener.prototype = Object.assign( Object.create( THREE.Object3D.prototype ), {
  9825. constructor: THREE.AudioListener,
  9826. getInput: function () {
  9827. return this.gain;
  9828. },
  9829. removeFilter: function ( ) {
  9830. if ( this.filter !== null ) {
  9831. this.gain.disconnect( this.filter );
  9832. this.filter.disconnect( this.context.destination );
  9833. this.gain.connect( this.context.destination );
  9834. this.filter = null;
  9835. }
  9836. },
  9837. getFilter: function () {
  9838. return this.filter;
  9839. },
  9840. setFilter: function ( value ) {
  9841. if ( this.filter !== null ) {
  9842. this.gain.disconnect( this.filter );
  9843. this.filter.disconnect( this.context.destination );
  9844. } else {
  9845. this.gain.disconnect( this.context.destination );
  9846. }
  9847. this.filter = value;
  9848. this.gain.connect( this.filter );
  9849. this.filter.connect( this.context.destination );
  9850. },
  9851. getMasterVolume: function () {
  9852. return this.gain.gain.value;
  9853. },
  9854. setMasterVolume: function ( value ) {
  9855. this.gain.gain.value = value;
  9856. },
  9857. updateMatrixWorld: ( function () {
  9858. var position = new THREE.Vector3();
  9859. var quaternion = new THREE.Quaternion();
  9860. var scale = new THREE.Vector3();
  9861. var orientation = new THREE.Vector3();
  9862. return function updateMatrixWorld( force ) {
  9863. THREE.Object3D.prototype.updateMatrixWorld.call( this, force );
  9864. var listener = this.context.listener;
  9865. var up = this.up;
  9866. this.matrixWorld.decompose( position, quaternion, scale );
  9867. orientation.set( 0, 0, - 1 ).applyQuaternion( quaternion );
  9868. listener.setPosition( position.x, position.y, position.z );
  9869. listener.setOrientation( orientation.x, orientation.y, orientation.z, up.x, up.y, up.z );
  9870. };
  9871. } )()
  9872. } );
  9873. // File:src/cameras/Camera.js
  9874. /**
  9875. * @author mrdoob / http://mrdoob.com/
  9876. * @author mikael emtinger / http://gomo.se/
  9877. * @author WestLangley / http://github.com/WestLangley
  9878. */
  9879. THREE.Camera = function () {
  9880. THREE.Object3D.call( this );
  9881. this.type = 'Camera';
  9882. this.matrixWorldInverse = new THREE.Matrix4();
  9883. this.projectionMatrix = new THREE.Matrix4();
  9884. };
  9885. THREE.Camera.prototype = Object.create( THREE.Object3D.prototype );
  9886. THREE.Camera.prototype.constructor = THREE.Camera;
  9887. THREE.Camera.prototype.getWorldDirection = function () {
  9888. var quaternion = new THREE.Quaternion();
  9889. return function getWorldDirection( optionalTarget ) {
  9890. var result = optionalTarget || new THREE.Vector3();
  9891. this.getWorldQuaternion( quaternion );
  9892. return result.set( 0, 0, - 1 ).applyQuaternion( quaternion );
  9893. };
  9894. }();
  9895. THREE.Camera.prototype.lookAt = function () {
  9896. // This routine does not support cameras with rotated and/or translated parent(s)
  9897. var m1 = new THREE.Matrix4();
  9898. return function lookAt( vector ) {
  9899. m1.lookAt( this.position, vector, this.up );
  9900. this.quaternion.setFromRotationMatrix( m1 );
  9901. };
  9902. }();
  9903. THREE.Camera.prototype.clone = function () {
  9904. return new this.constructor().copy( this );
  9905. };
  9906. THREE.Camera.prototype.copy = function ( source ) {
  9907. THREE.Object3D.prototype.copy.call( this, source );
  9908. this.matrixWorldInverse.copy( source.matrixWorldInverse );
  9909. this.projectionMatrix.copy( source.projectionMatrix );
  9910. return this;
  9911. };
  9912. // File:src/cameras/CubeCamera.js
  9913. /**
  9914. * Camera for rendering cube maps
  9915. * - renders scene into axis-aligned cube
  9916. *
  9917. * @author alteredq / http://alteredqualia.com/
  9918. */
  9919. THREE.CubeCamera = function ( near, far, cubeResolution ) {
  9920. THREE.Object3D.call( this );
  9921. this.type = 'CubeCamera';
  9922. var fov = 90, aspect = 1;
  9923. var cameraPX = new THREE.PerspectiveCamera( fov, aspect, near, far );
  9924. cameraPX.up.set( 0, - 1, 0 );
  9925. cameraPX.lookAt( new THREE.Vector3( 1, 0, 0 ) );
  9926. this.add( cameraPX );
  9927. var cameraNX = new THREE.PerspectiveCamera( fov, aspect, near, far );
  9928. cameraNX.up.set( 0, - 1, 0 );
  9929. cameraNX.lookAt( new THREE.Vector3( - 1, 0, 0 ) );
  9930. this.add( cameraNX );
  9931. var cameraPY = new THREE.PerspectiveCamera( fov, aspect, near, far );
  9932. cameraPY.up.set( 0, 0, 1 );
  9933. cameraPY.lookAt( new THREE.Vector3( 0, 1, 0 ) );
  9934. this.add( cameraPY );
  9935. var cameraNY = new THREE.PerspectiveCamera( fov, aspect, near, far );
  9936. cameraNY.up.set( 0, 0, - 1 );
  9937. cameraNY.lookAt( new THREE.Vector3( 0, - 1, 0 ) );
  9938. this.add( cameraNY );
  9939. var cameraPZ = new THREE.PerspectiveCamera( fov, aspect, near, far );
  9940. cameraPZ.up.set( 0, - 1, 0 );
  9941. cameraPZ.lookAt( new THREE.Vector3( 0, 0, 1 ) );
  9942. this.add( cameraPZ );
  9943. var cameraNZ = new THREE.PerspectiveCamera( fov, aspect, near, far );
  9944. cameraNZ.up.set( 0, - 1, 0 );
  9945. cameraNZ.lookAt( new THREE.Vector3( 0, 0, - 1 ) );
  9946. this.add( cameraNZ );
  9947. var options = { format: THREE.RGBFormat, magFilter: THREE.LinearFilter, minFilter: THREE.LinearFilter };
  9948. this.renderTarget = new THREE.WebGLRenderTargetCube( cubeResolution, cubeResolution, options );
  9949. this.updateCubeMap = function ( renderer, scene ) {
  9950. if ( this.parent === null ) this.updateMatrixWorld();
  9951. var renderTarget = this.renderTarget;
  9952. var generateMipmaps = renderTarget.texture.generateMipmaps;
  9953. renderTarget.texture.generateMipmaps = false;
  9954. renderTarget.activeCubeFace = 0;
  9955. renderer.render( scene, cameraPX, renderTarget );
  9956. renderTarget.activeCubeFace = 1;
  9957. renderer.render( scene, cameraNX, renderTarget );
  9958. renderTarget.activeCubeFace = 2;
  9959. renderer.render( scene, cameraPY, renderTarget );
  9960. renderTarget.activeCubeFace = 3;
  9961. renderer.render( scene, cameraNY, renderTarget );
  9962. renderTarget.activeCubeFace = 4;
  9963. renderer.render( scene, cameraPZ, renderTarget );
  9964. renderTarget.texture.generateMipmaps = generateMipmaps;
  9965. renderTarget.activeCubeFace = 5;
  9966. renderer.render( scene, cameraNZ, renderTarget );
  9967. renderer.setRenderTarget( null );
  9968. };
  9969. };
  9970. THREE.CubeCamera.prototype = Object.create( THREE.Object3D.prototype );
  9971. THREE.CubeCamera.prototype.constructor = THREE.CubeCamera;
  9972. // File:src/cameras/OrthographicCamera.js
  9973. /**
  9974. * @author alteredq / http://alteredqualia.com/
  9975. * @author arose / http://github.com/arose
  9976. */
  9977. THREE.OrthographicCamera = function ( left, right, top, bottom, near, far ) {
  9978. THREE.Camera.call( this );
  9979. this.type = 'OrthographicCamera';
  9980. this.zoom = 1;
  9981. this.view = null;
  9982. this.left = left;
  9983. this.right = right;
  9984. this.top = top;
  9985. this.bottom = bottom;
  9986. this.near = ( near !== undefined ) ? near : 0.1;
  9987. this.far = ( far !== undefined ) ? far : 2000;
  9988. this.updateProjectionMatrix();
  9989. };
  9990. THREE.OrthographicCamera.prototype = Object.assign( Object.create( THREE.Camera.prototype ), {
  9991. constructor: THREE.OrthographicCamera,
  9992. copy: function ( source ) {
  9993. THREE.Camera.prototype.copy.call( this, source );
  9994. this.left = source.left;
  9995. this.right = source.right;
  9996. this.top = source.top;
  9997. this.bottom = source.bottom;
  9998. this.near = source.near;
  9999. this.far = source.far;
  10000. this.zoom = source.zoom;
  10001. this.view = source.view === null ? null : Object.assign( {}, source.view );
  10002. return this;
  10003. },
  10004. setViewOffset: function( fullWidth, fullHeight, x, y, width, height ) {
  10005. this.view = {
  10006. fullWidth: fullWidth,
  10007. fullHeight: fullHeight,
  10008. offsetX: x,
  10009. offsetY: y,
  10010. width: width,
  10011. height: height
  10012. };
  10013. this.updateProjectionMatrix();
  10014. },
  10015. clearViewOffset: function() {
  10016. this.view = null;
  10017. this.updateProjectionMatrix();
  10018. },
  10019. updateProjectionMatrix: function () {
  10020. var dx = ( this.right - this.left ) / ( 2 * this.zoom );
  10021. var dy = ( this.top - this.bottom ) / ( 2 * this.zoom );
  10022. var cx = ( this.right + this.left ) / 2;
  10023. var cy = ( this.top + this.bottom ) / 2;
  10024. var left = cx - dx;
  10025. var right = cx + dx;
  10026. var top = cy + dy;
  10027. var bottom = cy - dy;
  10028. if ( this.view !== null ) {
  10029. var zoomW = this.zoom / ( this.view.width / this.view.fullWidth );
  10030. var zoomH = this.zoom / ( this.view.height / this.view.fullHeight );
  10031. var scaleW = ( this.right - this.left ) / this.view.width;
  10032. var scaleH = ( this.top - this.bottom ) / this.view.height;
  10033. left += scaleW * ( this.view.offsetX / zoomW );
  10034. right = left + scaleW * ( this.view.width / zoomW );
  10035. top -= scaleH * ( this.view.offsetY / zoomH );
  10036. bottom = top - scaleH * ( this.view.height / zoomH );
  10037. }
  10038. this.projectionMatrix.makeOrthographic( left, right, top, bottom, this.near, this.far );
  10039. },
  10040. toJSON: function ( meta ) {
  10041. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  10042. data.object.zoom = this.zoom;
  10043. data.object.left = this.left;
  10044. data.object.right = this.right;
  10045. data.object.top = this.top;
  10046. data.object.bottom = this.bottom;
  10047. data.object.near = this.near;
  10048. data.object.far = this.far;
  10049. if ( this.view !== null ) data.object.view = Object.assign( {}, this.view );
  10050. return data;
  10051. }
  10052. } );
  10053. // File:src/cameras/PerspectiveCamera.js
  10054. /**
  10055. * @author mrdoob / http://mrdoob.com/
  10056. * @author greggman / http://games.greggman.com/
  10057. * @author zz85 / http://www.lab4games.net/zz85/blog
  10058. * @author tschw
  10059. */
  10060. THREE.PerspectiveCamera = function( fov, aspect, near, far ) {
  10061. THREE.Camera.call( this );
  10062. this.type = 'PerspectiveCamera';
  10063. this.fov = fov !== undefined ? fov : 50;
  10064. this.zoom = 1;
  10065. this.near = near !== undefined ? near : 0.1;
  10066. this.far = far !== undefined ? far : 2000;
  10067. this.focus = 10;
  10068. this.aspect = aspect !== undefined ? aspect : 1;
  10069. this.view = null;
  10070. this.filmGauge = 35; // width of the film (default in millimeters)
  10071. this.filmOffset = 0; // horizontal film offset (same unit as gauge)
  10072. this.updateProjectionMatrix();
  10073. };
  10074. THREE.PerspectiveCamera.prototype = Object.assign( Object.create( THREE.Camera.prototype ), {
  10075. constructor: THREE.PerspectiveCamera,
  10076. copy: function ( source ) {
  10077. THREE.Camera.prototype.copy.call( this, source );
  10078. this.fov = source.fov;
  10079. this.zoom = source.zoom;
  10080. this.near = source.near;
  10081. this.far = source.far;
  10082. this.focus = source.focus;
  10083. this.aspect = source.aspect;
  10084. this.view = source.view === null ? null : Object.assign( {}, source.view );
  10085. this.filmGauge = source.filmGauge;
  10086. this.filmOffset = source.filmOffset;
  10087. return this;
  10088. },
  10089. /**
  10090. * Sets the FOV by focal length in respect to the current .filmGauge.
  10091. *
  10092. * The default film gauge is 35, so that the focal length can be specified for
  10093. * a 35mm (full frame) camera.
  10094. *
  10095. * Values for focal length and film gauge must have the same unit.
  10096. */
  10097. setFocalLength: function ( focalLength ) {
  10098. // see http://www.bobatkins.com/photography/technical/field_of_view.html
  10099. var vExtentSlope = 0.5 * this.getFilmHeight() / focalLength;
  10100. this.fov = THREE.Math.RAD2DEG * 2 * Math.atan( vExtentSlope );
  10101. this.updateProjectionMatrix();
  10102. },
  10103. /**
  10104. * Calculates the focal length from the current .fov and .filmGauge.
  10105. */
  10106. getFocalLength: function () {
  10107. var vExtentSlope = Math.tan( THREE.Math.DEG2RAD * 0.5 * this.fov );
  10108. return 0.5 * this.getFilmHeight() / vExtentSlope;
  10109. },
  10110. getEffectiveFOV: function () {
  10111. return THREE.Math.RAD2DEG * 2 * Math.atan(
  10112. Math.tan( THREE.Math.DEG2RAD * 0.5 * this.fov ) / this.zoom );
  10113. },
  10114. getFilmWidth: function () {
  10115. // film not completely covered in portrait format (aspect < 1)
  10116. return this.filmGauge * Math.min( this.aspect, 1 );
  10117. },
  10118. getFilmHeight: function () {
  10119. // film not completely covered in landscape format (aspect > 1)
  10120. return this.filmGauge / Math.max( this.aspect, 1 );
  10121. },
  10122. /**
  10123. * Sets an offset in a larger frustum. This is useful for multi-window or
  10124. * multi-monitor/multi-machine setups.
  10125. *
  10126. * For example, if you have 3x2 monitors and each monitor is 1920x1080 and
  10127. * the monitors are in grid like this
  10128. *
  10129. * +---+---+---+
  10130. * | A | B | C |
  10131. * +---+---+---+
  10132. * | D | E | F |
  10133. * +---+---+---+
  10134. *
  10135. * then for each monitor you would call it like this
  10136. *
  10137. * var w = 1920;
  10138. * var h = 1080;
  10139. * var fullWidth = w * 3;
  10140. * var fullHeight = h * 2;
  10141. *
  10142. * --A--
  10143. * camera.setOffset( fullWidth, fullHeight, w * 0, h * 0, w, h );
  10144. * --B--
  10145. * camera.setOffset( fullWidth, fullHeight, w * 1, h * 0, w, h );
  10146. * --C--
  10147. * camera.setOffset( fullWidth, fullHeight, w * 2, h * 0, w, h );
  10148. * --D--
  10149. * camera.setOffset( fullWidth, fullHeight, w * 0, h * 1, w, h );
  10150. * --E--
  10151. * camera.setOffset( fullWidth, fullHeight, w * 1, h * 1, w, h );
  10152. * --F--
  10153. * camera.setOffset( fullWidth, fullHeight, w * 2, h * 1, w, h );
  10154. *
  10155. * Note there is no reason monitors have to be the same size or in a grid.
  10156. */
  10157. setViewOffset: function ( fullWidth, fullHeight, x, y, width, height ) {
  10158. this.aspect = fullWidth / fullHeight;
  10159. this.view = {
  10160. fullWidth: fullWidth,
  10161. fullHeight: fullHeight,
  10162. offsetX: x,
  10163. offsetY: y,
  10164. width: width,
  10165. height: height
  10166. };
  10167. this.updateProjectionMatrix();
  10168. },
  10169. clearViewOffset: function() {
  10170. this.view = null;
  10171. this.updateProjectionMatrix();
  10172. },
  10173. updateProjectionMatrix: function () {
  10174. var near = this.near,
  10175. top = near * Math.tan(
  10176. THREE.Math.DEG2RAD * 0.5 * this.fov ) / this.zoom,
  10177. height = 2 * top,
  10178. width = this.aspect * height,
  10179. left = - 0.5 * width,
  10180. view = this.view;
  10181. if ( view !== null ) {
  10182. var fullWidth = view.fullWidth,
  10183. fullHeight = view.fullHeight;
  10184. left += view.offsetX * width / fullWidth;
  10185. top -= view.offsetY * height / fullHeight;
  10186. width *= view.width / fullWidth;
  10187. height *= view.height / fullHeight;
  10188. }
  10189. var skew = this.filmOffset;
  10190. if ( skew !== 0 ) left += near * skew / this.getFilmWidth();
  10191. this.projectionMatrix.makeFrustum(
  10192. left, left + width, top - height, top, near, this.far );
  10193. },
  10194. toJSON: function ( meta ) {
  10195. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  10196. data.object.fov = this.fov;
  10197. data.object.zoom = this.zoom;
  10198. data.object.near = this.near;
  10199. data.object.far = this.far;
  10200. data.object.focus = this.focus;
  10201. data.object.aspect = this.aspect;
  10202. if ( this.view !== null ) data.object.view = Object.assign( {}, this.view );
  10203. data.object.filmGauge = this.filmGauge;
  10204. data.object.filmOffset = this.filmOffset;
  10205. return data;
  10206. }
  10207. } );
  10208. // File:src/cameras/StereoCamera.js
  10209. /**
  10210. * @author mrdoob / http://mrdoob.com/
  10211. */
  10212. THREE.StereoCamera = function () {
  10213. this.type = 'StereoCamera';
  10214. this.aspect = 1;
  10215. this.cameraL = new THREE.PerspectiveCamera();
  10216. this.cameraL.layers.enable( 1 );
  10217. this.cameraL.matrixAutoUpdate = false;
  10218. this.cameraR = new THREE.PerspectiveCamera();
  10219. this.cameraR.layers.enable( 2 );
  10220. this.cameraR.matrixAutoUpdate = false;
  10221. };
  10222. Object.assign( THREE.StereoCamera.prototype, {
  10223. update: ( function () {
  10224. var focus, fov, aspect, near, far;
  10225. var eyeRight = new THREE.Matrix4();
  10226. var eyeLeft = new THREE.Matrix4();
  10227. return function update( camera ) {
  10228. var needsUpdate = focus !== camera.focus || fov !== camera.fov ||
  10229. aspect !== camera.aspect * this.aspect || near !== camera.near ||
  10230. far !== camera.far;
  10231. if ( needsUpdate ) {
  10232. focus = camera.focus;
  10233. fov = camera.fov;
  10234. aspect = camera.aspect * this.aspect;
  10235. near = camera.near;
  10236. far = camera.far;
  10237. // Off-axis stereoscopic effect based on
  10238. // http://paulbourke.net/stereographics/stereorender/
  10239. var projectionMatrix = camera.projectionMatrix.clone();
  10240. var eyeSep = 0.064 / 2;
  10241. var eyeSepOnProjection = eyeSep * near / focus;
  10242. var ymax = near * Math.tan( THREE.Math.DEG2RAD * fov * 0.5 );
  10243. var xmin, xmax;
  10244. // translate xOffset
  10245. eyeLeft.elements[ 12 ] = - eyeSep;
  10246. eyeRight.elements[ 12 ] = eyeSep;
  10247. // for left eye
  10248. xmin = - ymax * aspect + eyeSepOnProjection;
  10249. xmax = ymax * aspect + eyeSepOnProjection;
  10250. projectionMatrix.elements[ 0 ] = 2 * near / ( xmax - xmin );
  10251. projectionMatrix.elements[ 8 ] = ( xmax + xmin ) / ( xmax - xmin );
  10252. this.cameraL.projectionMatrix.copy( projectionMatrix );
  10253. // for right eye
  10254. xmin = - ymax * aspect - eyeSepOnProjection;
  10255. xmax = ymax * aspect - eyeSepOnProjection;
  10256. projectionMatrix.elements[ 0 ] = 2 * near / ( xmax - xmin );
  10257. projectionMatrix.elements[ 8 ] = ( xmax + xmin ) / ( xmax - xmin );
  10258. this.cameraR.projectionMatrix.copy( projectionMatrix );
  10259. }
  10260. this.cameraL.matrixWorld.copy( camera.matrixWorld ).multiply( eyeLeft );
  10261. this.cameraR.matrixWorld.copy( camera.matrixWorld ).multiply( eyeRight );
  10262. };
  10263. } )()
  10264. } );
  10265. // File:src/lights/Light.js
  10266. /**
  10267. * @author mrdoob / http://mrdoob.com/
  10268. * @author alteredq / http://alteredqualia.com/
  10269. */
  10270. THREE.Light = function ( color, intensity ) {
  10271. THREE.Object3D.call( this );
  10272. this.type = 'Light';
  10273. this.color = new THREE.Color( color );
  10274. this.intensity = intensity !== undefined ? intensity : 1;
  10275. this.receiveShadow = undefined;
  10276. };
  10277. THREE.Light.prototype = Object.assign( Object.create( THREE.Object3D.prototype ), {
  10278. constructor: THREE.Light,
  10279. copy: function ( source ) {
  10280. THREE.Object3D.prototype.copy.call( this, source );
  10281. this.color.copy( source.color );
  10282. this.intensity = source.intensity;
  10283. return this;
  10284. },
  10285. toJSON: function ( meta ) {
  10286. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  10287. data.object.color = this.color.getHex();
  10288. data.object.intensity = this.intensity;
  10289. if ( this.groundColor !== undefined ) data.object.groundColor = this.groundColor.getHex();
  10290. if ( this.distance !== undefined ) data.object.distance = this.distance;
  10291. if ( this.angle !== undefined ) data.object.angle = this.angle;
  10292. if ( this.decay !== undefined ) data.object.decay = this.decay;
  10293. if ( this.penumbra !== undefined ) data.object.penumbra = this.penumbra;
  10294. return data;
  10295. }
  10296. } );
  10297. // File:src/lights/LightShadow.js
  10298. /**
  10299. * @author mrdoob / http://mrdoob.com/
  10300. */
  10301. THREE.LightShadow = function ( camera ) {
  10302. this.camera = camera;
  10303. this.bias = 0;
  10304. this.radius = 1;
  10305. this.mapSize = new THREE.Vector2( 512, 512 );
  10306. this.map = null;
  10307. this.matrix = new THREE.Matrix4();
  10308. };
  10309. Object.assign( THREE.LightShadow.prototype, {
  10310. copy: function ( source ) {
  10311. this.camera = source.camera.clone();
  10312. this.bias = source.bias;
  10313. this.radius = source.radius;
  10314. this.mapSize.copy( source.mapSize );
  10315. return this;
  10316. },
  10317. clone: function () {
  10318. return new this.constructor().copy( this );
  10319. }
  10320. } );
  10321. // File:src/lights/AmbientLight.js
  10322. /**
  10323. * @author mrdoob / http://mrdoob.com/
  10324. */
  10325. THREE.AmbientLight = function ( color, intensity ) {
  10326. THREE.Light.call( this, color, intensity );
  10327. this.type = 'AmbientLight';
  10328. this.castShadow = undefined;
  10329. };
  10330. THREE.AmbientLight.prototype = Object.assign( Object.create( THREE.Light.prototype ), {
  10331. constructor: THREE.AmbientLight
  10332. } );
  10333. // File:src/lights/DirectionalLight.js
  10334. /**
  10335. * @author mrdoob / http://mrdoob.com/
  10336. * @author alteredq / http://alteredqualia.com/
  10337. */
  10338. THREE.DirectionalLight = function ( color, intensity ) {
  10339. THREE.Light.call( this, color, intensity );
  10340. this.type = 'DirectionalLight';
  10341. this.position.set( 0, 1, 0 );
  10342. this.updateMatrix();
  10343. this.target = new THREE.Object3D();
  10344. this.shadow = new THREE.DirectionalLightShadow();
  10345. };
  10346. THREE.DirectionalLight.prototype = Object.assign( Object.create( THREE.Light.prototype ), {
  10347. constructor: THREE.DirectionalLight,
  10348. copy: function ( source ) {
  10349. THREE.Light.prototype.copy.call( this, source );
  10350. this.target = source.target.clone();
  10351. this.shadow = source.shadow.clone();
  10352. return this;
  10353. }
  10354. } );
  10355. // File:src/lights/DirectionalLightShadow.js
  10356. /**
  10357. * @author mrdoob / http://mrdoob.com/
  10358. */
  10359. THREE.DirectionalLightShadow = function ( light ) {
  10360. THREE.LightShadow.call( this, new THREE.OrthographicCamera( - 5, 5, 5, - 5, 0.5, 500 ) );
  10361. };
  10362. THREE.DirectionalLightShadow.prototype = Object.assign( Object.create( THREE.LightShadow.prototype ), {
  10363. constructor: THREE.DirectionalLightShadow
  10364. } );
  10365. // File:src/lights/HemisphereLight.js
  10366. /**
  10367. * @author alteredq / http://alteredqualia.com/
  10368. */
  10369. THREE.HemisphereLight = function ( skyColor, groundColor, intensity ) {
  10370. THREE.Light.call( this, skyColor, intensity );
  10371. this.type = 'HemisphereLight';
  10372. this.castShadow = undefined;
  10373. this.position.set( 0, 1, 0 );
  10374. this.updateMatrix();
  10375. this.groundColor = new THREE.Color( groundColor );
  10376. };
  10377. THREE.HemisphereLight.prototype = Object.assign( Object.create( THREE.Light.prototype ), {
  10378. constructor: THREE.HemisphereLight,
  10379. copy: function ( source ) {
  10380. THREE.Light.prototype.copy.call( this, source );
  10381. this.groundColor.copy( source.groundColor );
  10382. return this;
  10383. }
  10384. } );
  10385. // File:src/lights/PointLight.js
  10386. /**
  10387. * @author mrdoob / http://mrdoob.com/
  10388. */
  10389. THREE.PointLight = function ( color, intensity, distance, decay ) {
  10390. THREE.Light.call( this, color, intensity );
  10391. this.type = 'PointLight';
  10392. Object.defineProperty( this, 'power', {
  10393. get: function () {
  10394. // intensity = power per solid angle.
  10395. // ref: equation (15) from http://www.frostbite.com/wp-content/uploads/2014/11/course_notes_moving_frostbite_to_pbr.pdf
  10396. return this.intensity * 4 * Math.PI;
  10397. },
  10398. set: function ( power ) {
  10399. // intensity = power per solid angle.
  10400. // ref: equation (15) from http://www.frostbite.com/wp-content/uploads/2014/11/course_notes_moving_frostbite_to_pbr.pdf
  10401. this.intensity = power / ( 4 * Math.PI );
  10402. }
  10403. } );
  10404. this.distance = ( distance !== undefined ) ? distance : 0;
  10405. this.decay = ( decay !== undefined ) ? decay : 1; // for physically correct lights, should be 2.
  10406. this.shadow = new THREE.LightShadow( new THREE.PerspectiveCamera( 90, 1, 0.5, 500 ) );
  10407. };
  10408. THREE.PointLight.prototype = Object.assign( Object.create( THREE.Light.prototype ), {
  10409. constructor: THREE.PointLight,
  10410. copy: function ( source ) {
  10411. THREE.Light.prototype.copy.call( this, source );
  10412. this.distance = source.distance;
  10413. this.decay = source.decay;
  10414. this.shadow = source.shadow.clone();
  10415. return this;
  10416. }
  10417. } );
  10418. // File:src/lights/SpotLight.js
  10419. /**
  10420. * @author alteredq / http://alteredqualia.com/
  10421. */
  10422. THREE.SpotLight = function ( color, intensity, distance, angle, penumbra, decay ) {
  10423. THREE.Light.call( this, color, intensity );
  10424. this.type = 'SpotLight';
  10425. this.position.set( 0, 1, 0 );
  10426. this.updateMatrix();
  10427. this.target = new THREE.Object3D();
  10428. Object.defineProperty( this, 'power', {
  10429. get: function () {
  10430. // intensity = power per solid angle.
  10431. // ref: equation (17) from http://www.frostbite.com/wp-content/uploads/2014/11/course_notes_moving_frostbite_to_pbr.pdf
  10432. return this.intensity * Math.PI;
  10433. },
  10434. set: function ( power ) {
  10435. // intensity = power per solid angle.
  10436. // ref: equation (17) from http://www.frostbite.com/wp-content/uploads/2014/11/course_notes_moving_frostbite_to_pbr.pdf
  10437. this.intensity = power / Math.PI;
  10438. }
  10439. } );
  10440. this.distance = ( distance !== undefined ) ? distance : 0;
  10441. this.angle = ( angle !== undefined ) ? angle : Math.PI / 3;
  10442. this.penumbra = ( penumbra !== undefined ) ? penumbra : 0;
  10443. this.decay = ( decay !== undefined ) ? decay : 1; // for physically correct lights, should be 2.
  10444. this.shadow = new THREE.SpotLightShadow();
  10445. };
  10446. THREE.SpotLight.prototype = Object.assign( Object.create( THREE.Light.prototype ), {
  10447. constructor: THREE.SpotLight,
  10448. copy: function ( source ) {
  10449. THREE.Light.prototype.copy.call( this, source );
  10450. this.distance = source.distance;
  10451. this.angle = source.angle;
  10452. this.penumbra = source.penumbra;
  10453. this.decay = source.decay;
  10454. this.target = source.target.clone();
  10455. this.shadow = source.shadow.clone();
  10456. return this;
  10457. }
  10458. } );
  10459. // File:src/lights/SpotLightShadow.js
  10460. /**
  10461. * @author mrdoob / http://mrdoob.com/
  10462. */
  10463. THREE.SpotLightShadow = function () {
  10464. THREE.LightShadow.call( this, new THREE.PerspectiveCamera( 50, 1, 0.5, 500 ) );
  10465. };
  10466. THREE.SpotLightShadow.prototype = Object.assign( Object.create( THREE.LightShadow.prototype ), {
  10467. constructor: THREE.SpotLightShadow,
  10468. update: function ( light ) {
  10469. var fov = THREE.Math.RAD2DEG * 2 * light.angle;
  10470. var aspect = this.mapSize.width / this.mapSize.height;
  10471. var far = light.distance || 500;
  10472. var camera = this.camera;
  10473. if ( fov !== camera.fov || aspect !== camera.aspect || far !== camera.far ) {
  10474. camera.fov = fov;
  10475. camera.aspect = aspect;
  10476. camera.far = far;
  10477. camera.updateProjectionMatrix();
  10478. }
  10479. }
  10480. } );
  10481. // File:src/loaders/AudioLoader.js
  10482. /**
  10483. * @author Reece Aaron Lecrivain / http://reecenotes.com/
  10484. */
  10485. THREE.AudioLoader = function ( manager ) {
  10486. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  10487. };
  10488. Object.assign( THREE.AudioLoader.prototype, {
  10489. load: function ( url, onLoad, onProgress, onError ) {
  10490. var loader = new THREE.XHRLoader( this.manager );
  10491. loader.setResponseType( 'arraybuffer' );
  10492. loader.load( url, function ( buffer ) {
  10493. var context = THREE.AudioContext;
  10494. context.decodeAudioData( buffer, function ( audioBuffer ) {
  10495. onLoad( audioBuffer );
  10496. } );
  10497. }, onProgress, onError );
  10498. }
  10499. } );
  10500. // File:src/loaders/Cache.js
  10501. /**
  10502. * @author mrdoob / http://mrdoob.com/
  10503. */
  10504. THREE.Cache = {
  10505. enabled: false,
  10506. files: {},
  10507. add: function ( key, file ) {
  10508. if ( this.enabled === false ) return;
  10509. // console.log( 'THREE.Cache', 'Adding key:', key );
  10510. this.files[ key ] = file;
  10511. },
  10512. get: function ( key ) {
  10513. if ( this.enabled === false ) return;
  10514. // console.log( 'THREE.Cache', 'Checking key:', key );
  10515. return this.files[ key ];
  10516. },
  10517. remove: function ( key ) {
  10518. delete this.files[ key ];
  10519. },
  10520. clear: function () {
  10521. this.files = {};
  10522. }
  10523. };
  10524. // File:src/loaders/Loader.js
  10525. /**
  10526. * @author alteredq / http://alteredqualia.com/
  10527. */
  10528. THREE.Loader = function () {
  10529. this.onLoadStart = function () {};
  10530. this.onLoadProgress = function () {};
  10531. this.onLoadComplete = function () {};
  10532. };
  10533. THREE.Loader.prototype = {
  10534. constructor: THREE.Loader,
  10535. crossOrigin: undefined,
  10536. extractUrlBase: function ( url ) {
  10537. var parts = url.split( '/' );
  10538. if ( parts.length === 1 ) return './';
  10539. parts.pop();
  10540. return parts.join( '/' ) + '/';
  10541. },
  10542. initMaterials: function ( materials, texturePath, crossOrigin ) {
  10543. var array = [];
  10544. for ( var i = 0; i < materials.length; ++ i ) {
  10545. array[ i ] = this.createMaterial( materials[ i ], texturePath, crossOrigin );
  10546. }
  10547. return array;
  10548. },
  10549. createMaterial: ( function () {
  10550. var color, textureLoader, materialLoader;
  10551. return function createMaterial( m, texturePath, crossOrigin ) {
  10552. if ( color === undefined ) color = new THREE.Color();
  10553. if ( textureLoader === undefined ) textureLoader = new THREE.TextureLoader();
  10554. if ( materialLoader === undefined ) materialLoader = new THREE.MaterialLoader();
  10555. // convert from old material format
  10556. var textures = {};
  10557. function loadTexture( path, repeat, offset, wrap, anisotropy ) {
  10558. var fullPath = texturePath + path;
  10559. var loader = THREE.Loader.Handlers.get( fullPath );
  10560. var texture;
  10561. if ( loader !== null ) {
  10562. texture = loader.load( fullPath );
  10563. } else {
  10564. textureLoader.setCrossOrigin( crossOrigin );
  10565. texture = textureLoader.load( fullPath );
  10566. }
  10567. if ( repeat !== undefined ) {
  10568. texture.repeat.fromArray( repeat );
  10569. if ( repeat[ 0 ] !== 1 ) texture.wrapS = THREE.RepeatWrapping;
  10570. if ( repeat[ 1 ] !== 1 ) texture.wrapT = THREE.RepeatWrapping;
  10571. }
  10572. if ( offset !== undefined ) {
  10573. texture.offset.fromArray( offset );
  10574. }
  10575. if ( wrap !== undefined ) {
  10576. if ( wrap[ 0 ] === 'repeat' ) texture.wrapS = THREE.RepeatWrapping;
  10577. if ( wrap[ 0 ] === 'mirror' ) texture.wrapS = THREE.MirroredRepeatWrapping;
  10578. if ( wrap[ 1 ] === 'repeat' ) texture.wrapT = THREE.RepeatWrapping;
  10579. if ( wrap[ 1 ] === 'mirror' ) texture.wrapT = THREE.MirroredRepeatWrapping;
  10580. }
  10581. if ( anisotropy !== undefined ) {
  10582. texture.anisotropy = anisotropy;
  10583. }
  10584. var uuid = THREE.Math.generateUUID();
  10585. textures[ uuid ] = texture;
  10586. return uuid;
  10587. }
  10588. //
  10589. var json = {
  10590. uuid: THREE.Math.generateUUID(),
  10591. type: 'MeshLambertMaterial'
  10592. };
  10593. for ( var name in m ) {
  10594. var value = m[ name ];
  10595. switch ( name ) {
  10596. case 'DbgColor':
  10597. case 'DbgIndex':
  10598. case 'opticalDensity':
  10599. case 'illumination':
  10600. break;
  10601. case 'DbgName':
  10602. json.name = value;
  10603. break;
  10604. case 'blending':
  10605. json.blending = THREE[ value ];
  10606. break;
  10607. case 'colorAmbient':
  10608. case 'mapAmbient':
  10609. console.warn( 'THREE.Loader.createMaterial:', name, 'is no longer supported.' );
  10610. break;
  10611. case 'colorDiffuse':
  10612. json.color = color.fromArray( value ).getHex();
  10613. break;
  10614. case 'colorSpecular':
  10615. json.specular = color.fromArray( value ).getHex();
  10616. break;
  10617. case 'colorEmissive':
  10618. json.emissive = color.fromArray( value ).getHex();
  10619. break;
  10620. case 'specularCoef':
  10621. json.shininess = value;
  10622. break;
  10623. case 'shading':
  10624. if ( value.toLowerCase() === 'basic' ) json.type = 'MeshBasicMaterial';
  10625. if ( value.toLowerCase() === 'phong' ) json.type = 'MeshPhongMaterial';
  10626. if ( value.toLowerCase() === 'standard' ) json.type = 'MeshStandardMaterial';
  10627. break;
  10628. case 'mapDiffuse':
  10629. json.map = loadTexture( value, m.mapDiffuseRepeat, m.mapDiffuseOffset, m.mapDiffuseWrap, m.mapDiffuseAnisotropy );
  10630. break;
  10631. case 'mapDiffuseRepeat':
  10632. case 'mapDiffuseOffset':
  10633. case 'mapDiffuseWrap':
  10634. case 'mapDiffuseAnisotropy':
  10635. break;
  10636. case 'mapEmissive':
  10637. json.emissiveMap = loadTexture( value, m.mapEmissiveRepeat, m.mapEmissiveOffset, m.mapEmissiveWrap, m.mapEmissiveAnisotropy );
  10638. break;
  10639. case 'mapEmissiveRepeat':
  10640. case 'mapEmissiveOffset':
  10641. case 'mapEmissiveWrap':
  10642. case 'mapEmissiveAnisotropy':
  10643. break;
  10644. case 'mapLight':
  10645. json.lightMap = loadTexture( value, m.mapLightRepeat, m.mapLightOffset, m.mapLightWrap, m.mapLightAnisotropy );
  10646. break;
  10647. case 'mapLightRepeat':
  10648. case 'mapLightOffset':
  10649. case 'mapLightWrap':
  10650. case 'mapLightAnisotropy':
  10651. break;
  10652. case 'mapAO':
  10653. json.aoMap = loadTexture( value, m.mapAORepeat, m.mapAOOffset, m.mapAOWrap, m.mapAOAnisotropy );
  10654. break;
  10655. case 'mapAORepeat':
  10656. case 'mapAOOffset':
  10657. case 'mapAOWrap':
  10658. case 'mapAOAnisotropy':
  10659. break;
  10660. case 'mapBump':
  10661. json.bumpMap = loadTexture( value, m.mapBumpRepeat, m.mapBumpOffset, m.mapBumpWrap, m.mapBumpAnisotropy );
  10662. break;
  10663. case 'mapBumpScale':
  10664. json.bumpScale = value;
  10665. break;
  10666. case 'mapBumpRepeat':
  10667. case 'mapBumpOffset':
  10668. case 'mapBumpWrap':
  10669. case 'mapBumpAnisotropy':
  10670. break;
  10671. case 'mapNormal':
  10672. json.normalMap = loadTexture( value, m.mapNormalRepeat, m.mapNormalOffset, m.mapNormalWrap, m.mapNormalAnisotropy );
  10673. break;
  10674. case 'mapNormalFactor':
  10675. json.normalScale = [ value, value ];
  10676. break;
  10677. case 'mapNormalRepeat':
  10678. case 'mapNormalOffset':
  10679. case 'mapNormalWrap':
  10680. case 'mapNormalAnisotropy':
  10681. break;
  10682. case 'mapSpecular':
  10683. json.specularMap = loadTexture( value, m.mapSpecularRepeat, m.mapSpecularOffset, m.mapSpecularWrap, m.mapSpecularAnisotropy );
  10684. break;
  10685. case 'mapSpecularRepeat':
  10686. case 'mapSpecularOffset':
  10687. case 'mapSpecularWrap':
  10688. case 'mapSpecularAnisotropy':
  10689. break;
  10690. case 'mapMetalness':
  10691. json.metalnessMap = loadTexture( value, m.mapMetalnessRepeat, m.mapMetalnessOffset, m.mapMetalnessWrap, m.mapMetalnessAnisotropy );
  10692. break;
  10693. case 'mapMetalnessRepeat':
  10694. case 'mapMetalnessOffset':
  10695. case 'mapMetalnessWrap':
  10696. case 'mapMetalnessAnisotropy':
  10697. break;
  10698. case 'mapRoughness':
  10699. json.roughnessMap = loadTexture( value, m.mapRoughnessRepeat, m.mapRoughnessOffset, m.mapRoughnessWrap, m.mapRoughnessAnisotropy );
  10700. break;
  10701. case 'mapRoughnessRepeat':
  10702. case 'mapRoughnessOffset':
  10703. case 'mapRoughnessWrap':
  10704. case 'mapRoughnessAnisotropy':
  10705. break;
  10706. case 'mapAlpha':
  10707. json.alphaMap = loadTexture( value, m.mapAlphaRepeat, m.mapAlphaOffset, m.mapAlphaWrap, m.mapAlphaAnisotropy );
  10708. break;
  10709. case 'mapAlphaRepeat':
  10710. case 'mapAlphaOffset':
  10711. case 'mapAlphaWrap':
  10712. case 'mapAlphaAnisotropy':
  10713. break;
  10714. case 'flipSided':
  10715. json.side = THREE.BackSide;
  10716. break;
  10717. case 'doubleSided':
  10718. json.side = THREE.DoubleSide;
  10719. break;
  10720. case 'transparency':
  10721. console.warn( 'THREE.Loader.createMaterial: transparency has been renamed to opacity' );
  10722. json.opacity = value;
  10723. break;
  10724. case 'depthTest':
  10725. case 'depthWrite':
  10726. case 'colorWrite':
  10727. case 'opacity':
  10728. case 'reflectivity':
  10729. case 'transparent':
  10730. case 'visible':
  10731. case 'wireframe':
  10732. json[ name ] = value;
  10733. break;
  10734. case 'vertexColors':
  10735. if ( value === true ) json.vertexColors = THREE.VertexColors;
  10736. if ( value === 'face' ) json.vertexColors = THREE.FaceColors;
  10737. break;
  10738. default:
  10739. console.error( 'THREE.Loader.createMaterial: Unsupported', name, value );
  10740. break;
  10741. }
  10742. }
  10743. if ( json.type === 'MeshBasicMaterial' ) delete json.emissive;
  10744. if ( json.type !== 'MeshPhongMaterial' ) delete json.specular;
  10745. if ( json.opacity < 1 ) json.transparent = true;
  10746. materialLoader.setTextures( textures );
  10747. return materialLoader.parse( json );
  10748. };
  10749. } )()
  10750. };
  10751. THREE.Loader.Handlers = {
  10752. handlers: [],
  10753. add: function ( regex, loader ) {
  10754. this.handlers.push( regex, loader );
  10755. },
  10756. get: function ( file ) {
  10757. var handlers = this.handlers;
  10758. for ( var i = 0, l = handlers.length; i < l; i += 2 ) {
  10759. var regex = handlers[ i ];
  10760. var loader = handlers[ i + 1 ];
  10761. if ( regex.test( file ) ) {
  10762. return loader;
  10763. }
  10764. }
  10765. return null;
  10766. }
  10767. };
  10768. // File:src/loaders/XHRLoader.js
  10769. /**
  10770. * @author mrdoob / http://mrdoob.com/
  10771. */
  10772. THREE.XHRLoader = function ( manager ) {
  10773. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  10774. };
  10775. Object.assign( THREE.XHRLoader.prototype, {
  10776. load: function ( url, onLoad, onProgress, onError ) {
  10777. if ( this.path !== undefined ) url = this.path + url;
  10778. var scope = this;
  10779. var cached = THREE.Cache.get( url );
  10780. if ( cached !== undefined ) {
  10781. if ( onLoad ) {
  10782. setTimeout( function () {
  10783. onLoad( cached );
  10784. }, 0 );
  10785. }
  10786. return cached;
  10787. }
  10788. var request = new XMLHttpRequest();
  10789. request.overrideMimeType( 'text/plain' );
  10790. request.open( 'GET', url, true );
  10791. request.addEventListener( 'load', function ( event ) {
  10792. var response = event.target.response;
  10793. THREE.Cache.add( url, response );
  10794. if ( this.status === 200 ) {
  10795. if ( onLoad ) onLoad( response );
  10796. scope.manager.itemEnd( url );
  10797. } else if ( this.status === 0 ) {
  10798. // Some browsers return HTTP Status 0 when using non-http protocol
  10799. // e.g. 'file://' or 'data://'. Handle as success.
  10800. console.warn( 'THREE.XHRLoader: HTTP Status 0 received.' );
  10801. if ( onLoad ) onLoad( response );
  10802. scope.manager.itemEnd( url );
  10803. } else {
  10804. if ( onError ) onError( event );
  10805. scope.manager.itemError( url );
  10806. }
  10807. }, false );
  10808. if ( onProgress !== undefined ) {
  10809. request.addEventListener( 'progress', function ( event ) {
  10810. onProgress( event );
  10811. }, false );
  10812. }
  10813. request.addEventListener( 'error', function ( event ) {
  10814. if ( onError ) onError( event );
  10815. scope.manager.itemError( url );
  10816. }, false );
  10817. if ( this.responseType !== undefined ) request.responseType = this.responseType;
  10818. if ( this.withCredentials !== undefined ) request.withCredentials = this.withCredentials;
  10819. request.send( null );
  10820. scope.manager.itemStart( url );
  10821. return request;
  10822. },
  10823. setPath: function ( value ) {
  10824. this.path = value;
  10825. return this;
  10826. },
  10827. setResponseType: function ( value ) {
  10828. this.responseType = value;
  10829. return this;
  10830. },
  10831. setWithCredentials: function ( value ) {
  10832. this.withCredentials = value;
  10833. return this;
  10834. }
  10835. } );
  10836. // File:src/loaders/FontLoader.js
  10837. /**
  10838. * @author mrdoob / http://mrdoob.com/
  10839. */
  10840. THREE.FontLoader = function ( manager ) {
  10841. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  10842. };
  10843. Object.assign( THREE.FontLoader.prototype, {
  10844. load: function ( url, onLoad, onProgress, onError ) {
  10845. var scope = this;
  10846. var loader = new THREE.XHRLoader( this.manager );
  10847. loader.load( url, function ( text ) {
  10848. var json;
  10849. try {
  10850. json = JSON.parse( text );
  10851. } catch ( e ) {
  10852. console.warn( 'THREE.FontLoader: typeface.js support is being deprecated. Use typeface.json instead.' );
  10853. json = JSON.parse( text.substring( 65, text.length - 2 ) );
  10854. }
  10855. var font = scope.parse( json );
  10856. if ( onLoad ) onLoad( font );
  10857. }, onProgress, onError );
  10858. },
  10859. parse: function ( json ) {
  10860. return new THREE.Font( json );
  10861. }
  10862. } );
  10863. // File:src/loaders/ImageLoader.js
  10864. /**
  10865. * @author mrdoob / http://mrdoob.com/
  10866. */
  10867. THREE.ImageLoader = function ( manager ) {
  10868. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  10869. };
  10870. Object.assign( THREE.ImageLoader.prototype, {
  10871. load: function ( url, onLoad, onProgress, onError ) {
  10872. var image = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'img' );
  10873. image.onload = function () {
  10874. URL.revokeObjectURL( image.src );
  10875. if ( onLoad ) onLoad( image );
  10876. };
  10877. if ( url.indexOf( 'data:' ) === 0 ) {
  10878. image.src = url;
  10879. } else {
  10880. var loader = new THREE.XHRLoader( this.manager );
  10881. loader.setPath( this.path );
  10882. loader.setResponseType( 'blob' );
  10883. loader.load( url, function ( blob ) {
  10884. image.src = URL.createObjectURL( blob );
  10885. }, onProgress, onError );
  10886. }
  10887. return image;
  10888. },
  10889. setCrossOrigin: function ( value ) {
  10890. this.crossOrigin = value;
  10891. return this;
  10892. },
  10893. setPath: function ( value ) {
  10894. this.path = value;
  10895. return this;
  10896. }
  10897. } );
  10898. // File:src/loaders/JSONLoader.js
  10899. /**
  10900. * @author mrdoob / http://mrdoob.com/
  10901. * @author alteredq / http://alteredqualia.com/
  10902. */
  10903. THREE.JSONLoader = function ( manager ) {
  10904. if ( typeof manager === 'boolean' ) {
  10905. console.warn( 'THREE.JSONLoader: showStatus parameter has been removed from constructor.' );
  10906. manager = undefined;
  10907. }
  10908. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  10909. this.withCredentials = false;
  10910. };
  10911. Object.assign( THREE.JSONLoader.prototype, {
  10912. load: function( url, onLoad, onProgress, onError ) {
  10913. var scope = this;
  10914. var texturePath = this.texturePath && ( typeof this.texturePath === "string" ) ? this.texturePath : THREE.Loader.prototype.extractUrlBase( url );
  10915. var loader = new THREE.XHRLoader( this.manager );
  10916. loader.setWithCredentials( this.withCredentials );
  10917. loader.load( url, function ( text ) {
  10918. var json = JSON.parse( text );
  10919. var metadata = json.metadata;
  10920. if ( metadata !== undefined ) {
  10921. var type = metadata.type;
  10922. if ( type !== undefined ) {
  10923. if ( type.toLowerCase() === 'object' ) {
  10924. console.error( 'THREE.JSONLoader: ' + url + ' should be loaded with THREE.ObjectLoader instead.' );
  10925. return;
  10926. }
  10927. if ( type.toLowerCase() === 'scene' ) {
  10928. console.error( 'THREE.JSONLoader: ' + url + ' should be loaded with THREE.SceneLoader instead.' );
  10929. return;
  10930. }
  10931. }
  10932. }
  10933. var object = scope.parse( json, texturePath );
  10934. onLoad( object.geometry, object.materials );
  10935. }, onProgress, onError );
  10936. },
  10937. setTexturePath: function ( value ) {
  10938. this.texturePath = value;
  10939. },
  10940. parse: function ( json, texturePath ) {
  10941. var geometry = new THREE.Geometry(),
  10942. scale = ( json.scale !== undefined ) ? 1.0 / json.scale : 1.0;
  10943. parseModel( scale );
  10944. parseSkin();
  10945. parseMorphing( scale );
  10946. parseAnimations();
  10947. geometry.computeFaceNormals();
  10948. geometry.computeBoundingSphere();
  10949. function parseModel( scale ) {
  10950. function isBitSet( value, position ) {
  10951. return value & ( 1 << position );
  10952. }
  10953. var i, j, fi,
  10954. offset, zLength,
  10955. colorIndex, normalIndex, uvIndex, materialIndex,
  10956. type,
  10957. isQuad,
  10958. hasMaterial,
  10959. hasFaceVertexUv,
  10960. hasFaceNormal, hasFaceVertexNormal,
  10961. hasFaceColor, hasFaceVertexColor,
  10962. vertex, face, faceA, faceB, hex, normal,
  10963. uvLayer, uv, u, v,
  10964. faces = json.faces,
  10965. vertices = json.vertices,
  10966. normals = json.normals,
  10967. colors = json.colors,
  10968. nUvLayers = 0;
  10969. if ( json.uvs !== undefined ) {
  10970. // disregard empty arrays
  10971. for ( i = 0; i < json.uvs.length; i ++ ) {
  10972. if ( json.uvs[ i ].length ) nUvLayers ++;
  10973. }
  10974. for ( i = 0; i < nUvLayers; i ++ ) {
  10975. geometry.faceVertexUvs[ i ] = [];
  10976. }
  10977. }
  10978. offset = 0;
  10979. zLength = vertices.length;
  10980. while ( offset < zLength ) {
  10981. vertex = new THREE.Vector3();
  10982. vertex.x = vertices[ offset ++ ] * scale;
  10983. vertex.y = vertices[ offset ++ ] * scale;
  10984. vertex.z = vertices[ offset ++ ] * scale;
  10985. geometry.vertices.push( vertex );
  10986. }
  10987. offset = 0;
  10988. zLength = faces.length;
  10989. while ( offset < zLength ) {
  10990. type = faces[ offset ++ ];
  10991. isQuad = isBitSet( type, 0 );
  10992. hasMaterial = isBitSet( type, 1 );
  10993. hasFaceVertexUv = isBitSet( type, 3 );
  10994. hasFaceNormal = isBitSet( type, 4 );
  10995. hasFaceVertexNormal = isBitSet( type, 5 );
  10996. hasFaceColor = isBitSet( type, 6 );
  10997. hasFaceVertexColor = isBitSet( type, 7 );
  10998. // console.log("type", type, "bits", isQuad, hasMaterial, hasFaceVertexUv, hasFaceNormal, hasFaceVertexNormal, hasFaceColor, hasFaceVertexColor);
  10999. if ( isQuad ) {
  11000. faceA = new THREE.Face3();
  11001. faceA.a = faces[ offset ];
  11002. faceA.b = faces[ offset + 1 ];
  11003. faceA.c = faces[ offset + 3 ];
  11004. faceB = new THREE.Face3();
  11005. faceB.a = faces[ offset + 1 ];
  11006. faceB.b = faces[ offset + 2 ];
  11007. faceB.c = faces[ offset + 3 ];
  11008. offset += 4;
  11009. if ( hasMaterial ) {
  11010. materialIndex = faces[ offset ++ ];
  11011. faceA.materialIndex = materialIndex;
  11012. faceB.materialIndex = materialIndex;
  11013. }
  11014. // to get face <=> uv index correspondence
  11015. fi = geometry.faces.length;
  11016. if ( hasFaceVertexUv ) {
  11017. for ( i = 0; i < nUvLayers; i ++ ) {
  11018. uvLayer = json.uvs[ i ];
  11019. geometry.faceVertexUvs[ i ][ fi ] = [];
  11020. geometry.faceVertexUvs[ i ][ fi + 1 ] = [];
  11021. for ( j = 0; j < 4; j ++ ) {
  11022. uvIndex = faces[ offset ++ ];
  11023. u = uvLayer[ uvIndex * 2 ];
  11024. v = uvLayer[ uvIndex * 2 + 1 ];
  11025. uv = new THREE.Vector2( u, v );
  11026. if ( j !== 2 ) geometry.faceVertexUvs[ i ][ fi ].push( uv );
  11027. if ( j !== 0 ) geometry.faceVertexUvs[ i ][ fi + 1 ].push( uv );
  11028. }
  11029. }
  11030. }
  11031. if ( hasFaceNormal ) {
  11032. normalIndex = faces[ offset ++ ] * 3;
  11033. faceA.normal.set(
  11034. normals[ normalIndex ++ ],
  11035. normals[ normalIndex ++ ],
  11036. normals[ normalIndex ]
  11037. );
  11038. faceB.normal.copy( faceA.normal );
  11039. }
  11040. if ( hasFaceVertexNormal ) {
  11041. for ( i = 0; i < 4; i ++ ) {
  11042. normalIndex = faces[ offset ++ ] * 3;
  11043. normal = new THREE.Vector3(
  11044. normals[ normalIndex ++ ],
  11045. normals[ normalIndex ++ ],
  11046. normals[ normalIndex ]
  11047. );
  11048. if ( i !== 2 ) faceA.vertexNormals.push( normal );
  11049. if ( i !== 0 ) faceB.vertexNormals.push( normal );
  11050. }
  11051. }
  11052. if ( hasFaceColor ) {
  11053. colorIndex = faces[ offset ++ ];
  11054. hex = colors[ colorIndex ];
  11055. faceA.color.setHex( hex );
  11056. faceB.color.setHex( hex );
  11057. }
  11058. if ( hasFaceVertexColor ) {
  11059. for ( i = 0; i < 4; i ++ ) {
  11060. colorIndex = faces[ offset ++ ];
  11061. hex = colors[ colorIndex ];
  11062. if ( i !== 2 ) faceA.vertexColors.push( new THREE.Color( hex ) );
  11063. if ( i !== 0 ) faceB.vertexColors.push( new THREE.Color( hex ) );
  11064. }
  11065. }
  11066. geometry.faces.push( faceA );
  11067. geometry.faces.push( faceB );
  11068. } else {
  11069. face = new THREE.Face3();
  11070. face.a = faces[ offset ++ ];
  11071. face.b = faces[ offset ++ ];
  11072. face.c = faces[ offset ++ ];
  11073. if ( hasMaterial ) {
  11074. materialIndex = faces[ offset ++ ];
  11075. face.materialIndex = materialIndex;
  11076. }
  11077. // to get face <=> uv index correspondence
  11078. fi = geometry.faces.length;
  11079. if ( hasFaceVertexUv ) {
  11080. for ( i = 0; i < nUvLayers; i ++ ) {
  11081. uvLayer = json.uvs[ i ];
  11082. geometry.faceVertexUvs[ i ][ fi ] = [];
  11083. for ( j = 0; j < 3; j ++ ) {
  11084. uvIndex = faces[ offset ++ ];
  11085. u = uvLayer[ uvIndex * 2 ];
  11086. v = uvLayer[ uvIndex * 2 + 1 ];
  11087. uv = new THREE.Vector2( u, v );
  11088. geometry.faceVertexUvs[ i ][ fi ].push( uv );
  11089. }
  11090. }
  11091. }
  11092. if ( hasFaceNormal ) {
  11093. normalIndex = faces[ offset ++ ] * 3;
  11094. face.normal.set(
  11095. normals[ normalIndex ++ ],
  11096. normals[ normalIndex ++ ],
  11097. normals[ normalIndex ]
  11098. );
  11099. }
  11100. if ( hasFaceVertexNormal ) {
  11101. for ( i = 0; i < 3; i ++ ) {
  11102. normalIndex = faces[ offset ++ ] * 3;
  11103. normal = new THREE.Vector3(
  11104. normals[ normalIndex ++ ],
  11105. normals[ normalIndex ++ ],
  11106. normals[ normalIndex ]
  11107. );
  11108. face.vertexNormals.push( normal );
  11109. }
  11110. }
  11111. if ( hasFaceColor ) {
  11112. colorIndex = faces[ offset ++ ];
  11113. face.color.setHex( colors[ colorIndex ] );
  11114. }
  11115. if ( hasFaceVertexColor ) {
  11116. for ( i = 0; i < 3; i ++ ) {
  11117. colorIndex = faces[ offset ++ ];
  11118. face.vertexColors.push( new THREE.Color( colors[ colorIndex ] ) );
  11119. }
  11120. }
  11121. geometry.faces.push( face );
  11122. }
  11123. }
  11124. }
  11125. function parseSkin() {
  11126. var influencesPerVertex = ( json.influencesPerVertex !== undefined ) ? json.influencesPerVertex : 2;
  11127. if ( json.skinWeights ) {
  11128. for ( var i = 0, l = json.skinWeights.length; i < l; i += influencesPerVertex ) {
  11129. var x = json.skinWeights[ i ];
  11130. var y = ( influencesPerVertex > 1 ) ? json.skinWeights[ i + 1 ] : 0;
  11131. var z = ( influencesPerVertex > 2 ) ? json.skinWeights[ i + 2 ] : 0;
  11132. var w = ( influencesPerVertex > 3 ) ? json.skinWeights[ i + 3 ] : 0;
  11133. geometry.skinWeights.push( new THREE.Vector4( x, y, z, w ) );
  11134. }
  11135. }
  11136. if ( json.skinIndices ) {
  11137. for ( var i = 0, l = json.skinIndices.length; i < l; i += influencesPerVertex ) {
  11138. var a = json.skinIndices[ i ];
  11139. var b = ( influencesPerVertex > 1 ) ? json.skinIndices[ i + 1 ] : 0;
  11140. var c = ( influencesPerVertex > 2 ) ? json.skinIndices[ i + 2 ] : 0;
  11141. var d = ( influencesPerVertex > 3 ) ? json.skinIndices[ i + 3 ] : 0;
  11142. geometry.skinIndices.push( new THREE.Vector4( a, b, c, d ) );
  11143. }
  11144. }
  11145. geometry.bones = json.bones;
  11146. if ( geometry.bones && geometry.bones.length > 0 && ( geometry.skinWeights.length !== geometry.skinIndices.length || geometry.skinIndices.length !== geometry.vertices.length ) ) {
  11147. console.warn( 'When skinning, number of vertices (' + geometry.vertices.length + '), skinIndices (' +
  11148. geometry.skinIndices.length + '), and skinWeights (' + geometry.skinWeights.length + ') should match.' );
  11149. }
  11150. }
  11151. function parseMorphing( scale ) {
  11152. if ( json.morphTargets !== undefined ) {
  11153. for ( var i = 0, l = json.morphTargets.length; i < l; i ++ ) {
  11154. geometry.morphTargets[ i ] = {};
  11155. geometry.morphTargets[ i ].name = json.morphTargets[ i ].name;
  11156. geometry.morphTargets[ i ].vertices = [];
  11157. var dstVertices = geometry.morphTargets[ i ].vertices;
  11158. var srcVertices = json.morphTargets[ i ].vertices;
  11159. for ( var v = 0, vl = srcVertices.length; v < vl; v += 3 ) {
  11160. var vertex = new THREE.Vector3();
  11161. vertex.x = srcVertices[ v ] * scale;
  11162. vertex.y = srcVertices[ v + 1 ] * scale;
  11163. vertex.z = srcVertices[ v + 2 ] * scale;
  11164. dstVertices.push( vertex );
  11165. }
  11166. }
  11167. }
  11168. if ( json.morphColors !== undefined && json.morphColors.length > 0 ) {
  11169. console.warn( 'THREE.JSONLoader: "morphColors" no longer supported. Using them as face colors.' );
  11170. var faces = geometry.faces;
  11171. var morphColors = json.morphColors[ 0 ].colors;
  11172. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  11173. faces[ i ].color.fromArray( morphColors, i * 3 );
  11174. }
  11175. }
  11176. }
  11177. function parseAnimations() {
  11178. var outputAnimations = [];
  11179. // parse old style Bone/Hierarchy animations
  11180. var animations = [];
  11181. if ( json.animation !== undefined ) {
  11182. animations.push( json.animation );
  11183. }
  11184. if ( json.animations !== undefined ) {
  11185. if ( json.animations.length ) {
  11186. animations = animations.concat( json.animations );
  11187. } else {
  11188. animations.push( json.animations );
  11189. }
  11190. }
  11191. for ( var i = 0; i < animations.length; i ++ ) {
  11192. var clip = THREE.AnimationClip.parseAnimation( animations[ i ], geometry.bones );
  11193. if ( clip ) outputAnimations.push( clip );
  11194. }
  11195. // parse implicit morph animations
  11196. if ( geometry.morphTargets ) {
  11197. // TODO: Figure out what an appropraite FPS is for morph target animations -- defaulting to 10, but really it is completely arbitrary.
  11198. var morphAnimationClips = THREE.AnimationClip.CreateClipsFromMorphTargetSequences( geometry.morphTargets, 10 );
  11199. outputAnimations = outputAnimations.concat( morphAnimationClips );
  11200. }
  11201. if ( outputAnimations.length > 0 ) geometry.animations = outputAnimations;
  11202. }
  11203. if ( json.materials === undefined || json.materials.length === 0 ) {
  11204. return { geometry: geometry };
  11205. } else {
  11206. var materials = THREE.Loader.prototype.initMaterials( json.materials, texturePath, this.crossOrigin );
  11207. return { geometry: geometry, materials: materials };
  11208. }
  11209. }
  11210. } );
  11211. // File:src/loaders/LoadingManager.js
  11212. /**
  11213. * @author mrdoob / http://mrdoob.com/
  11214. */
  11215. THREE.LoadingManager = function ( onLoad, onProgress, onError ) {
  11216. var scope = this;
  11217. var isLoading = false, itemsLoaded = 0, itemsTotal = 0;
  11218. this.onStart = undefined;
  11219. this.onLoad = onLoad;
  11220. this.onProgress = onProgress;
  11221. this.onError = onError;
  11222. this.itemStart = function ( url ) {
  11223. itemsTotal ++;
  11224. if ( isLoading === false ) {
  11225. if ( scope.onStart !== undefined ) {
  11226. scope.onStart( url, itemsLoaded, itemsTotal );
  11227. }
  11228. }
  11229. isLoading = true;
  11230. };
  11231. this.itemEnd = function ( url ) {
  11232. itemsLoaded ++;
  11233. if ( scope.onProgress !== undefined ) {
  11234. scope.onProgress( url, itemsLoaded, itemsTotal );
  11235. }
  11236. if ( itemsLoaded === itemsTotal ) {
  11237. isLoading = false;
  11238. if ( scope.onLoad !== undefined ) {
  11239. scope.onLoad();
  11240. }
  11241. }
  11242. };
  11243. this.itemError = function ( url ) {
  11244. if ( scope.onError !== undefined ) {
  11245. scope.onError( url );
  11246. }
  11247. };
  11248. };
  11249. THREE.DefaultLoadingManager = new THREE.LoadingManager();
  11250. // File:src/loaders/BufferGeometryLoader.js
  11251. /**
  11252. * @author mrdoob / http://mrdoob.com/
  11253. */
  11254. THREE.BufferGeometryLoader = function ( manager ) {
  11255. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  11256. };
  11257. Object.assign( THREE.BufferGeometryLoader.prototype, {
  11258. load: function ( url, onLoad, onProgress, onError ) {
  11259. var scope = this;
  11260. var loader = new THREE.XHRLoader( scope.manager );
  11261. loader.load( url, function ( text ) {
  11262. onLoad( scope.parse( JSON.parse( text ) ) );
  11263. }, onProgress, onError );
  11264. },
  11265. parse: function ( json ) {
  11266. var geometry = new THREE.BufferGeometry();
  11267. var index = json.data.index;
  11268. var TYPED_ARRAYS = {
  11269. 'Int8Array': Int8Array,
  11270. 'Uint8Array': Uint8Array,
  11271. 'Uint8ClampedArray': Uint8ClampedArray,
  11272. 'Int16Array': Int16Array,
  11273. 'Uint16Array': Uint16Array,
  11274. 'Int32Array': Int32Array,
  11275. 'Uint32Array': Uint32Array,
  11276. 'Float32Array': Float32Array,
  11277. 'Float64Array': Float64Array
  11278. };
  11279. if ( index !== undefined ) {
  11280. var typedArray = new TYPED_ARRAYS[ index.type ]( index.array );
  11281. geometry.setIndex( new THREE.BufferAttribute( typedArray, 1 ) );
  11282. }
  11283. var attributes = json.data.attributes;
  11284. for ( var key in attributes ) {
  11285. var attribute = attributes[ key ];
  11286. var typedArray = new TYPED_ARRAYS[ attribute.type ]( attribute.array );
  11287. geometry.addAttribute( key, new THREE.BufferAttribute( typedArray, attribute.itemSize, attribute.normalized ) );
  11288. }
  11289. var groups = json.data.groups || json.data.drawcalls || json.data.offsets;
  11290. if ( groups !== undefined ) {
  11291. for ( var i = 0, n = groups.length; i !== n; ++ i ) {
  11292. var group = groups[ i ];
  11293. geometry.addGroup( group.start, group.count, group.materialIndex );
  11294. }
  11295. }
  11296. var boundingSphere = json.data.boundingSphere;
  11297. if ( boundingSphere !== undefined ) {
  11298. var center = new THREE.Vector3();
  11299. if ( boundingSphere.center !== undefined ) {
  11300. center.fromArray( boundingSphere.center );
  11301. }
  11302. geometry.boundingSphere = new THREE.Sphere( center, boundingSphere.radius );
  11303. }
  11304. return geometry;
  11305. }
  11306. } );
  11307. // File:src/loaders/MaterialLoader.js
  11308. /**
  11309. * @author mrdoob / http://mrdoob.com/
  11310. */
  11311. THREE.MaterialLoader = function ( manager ) {
  11312. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  11313. this.textures = {};
  11314. };
  11315. Object.assign( THREE.MaterialLoader.prototype, {
  11316. load: function ( url, onLoad, onProgress, onError ) {
  11317. var scope = this;
  11318. var loader = new THREE.XHRLoader( scope.manager );
  11319. loader.load( url, function ( text ) {
  11320. onLoad( scope.parse( JSON.parse( text ) ) );
  11321. }, onProgress, onError );
  11322. },
  11323. setTextures: function ( value ) {
  11324. this.textures = value;
  11325. },
  11326. getTexture: function ( name ) {
  11327. var textures = this.textures;
  11328. if ( textures[ name ] === undefined ) {
  11329. console.warn( 'THREE.MaterialLoader: Undefined texture', name );
  11330. }
  11331. return textures[ name ];
  11332. },
  11333. parse: function ( json ) {
  11334. var material = new THREE[ json.type ];
  11335. if ( json.uuid !== undefined ) material.uuid = json.uuid;
  11336. if ( json.name !== undefined ) material.name = json.name;
  11337. if ( json.color !== undefined ) material.color.setHex( json.color );
  11338. if ( json.roughness !== undefined ) material.roughness = json.roughness;
  11339. if ( json.metalness !== undefined ) material.metalness = json.metalness;
  11340. if ( json.emissive !== undefined ) material.emissive.setHex( json.emissive );
  11341. if ( json.specular !== undefined ) material.specular.setHex( json.specular );
  11342. if ( json.shininess !== undefined ) material.shininess = json.shininess;
  11343. if ( json.uniforms !== undefined ) material.uniforms = json.uniforms;
  11344. if ( json.vertexShader !== undefined ) material.vertexShader = json.vertexShader;
  11345. if ( json.fragmentShader !== undefined ) material.fragmentShader = json.fragmentShader;
  11346. if ( json.vertexColors !== undefined ) material.vertexColors = json.vertexColors;
  11347. if ( json.shading !== undefined ) material.shading = json.shading;
  11348. if ( json.blending !== undefined ) material.blending = json.blending;
  11349. if ( json.side !== undefined ) material.side = json.side;
  11350. if ( json.opacity !== undefined ) material.opacity = json.opacity;
  11351. if ( json.transparent !== undefined ) material.transparent = json.transparent;
  11352. if ( json.alphaTest !== undefined ) material.alphaTest = json.alphaTest;
  11353. if ( json.depthTest !== undefined ) material.depthTest = json.depthTest;
  11354. if ( json.depthWrite !== undefined ) material.depthWrite = json.depthWrite;
  11355. if ( json.colorWrite !== undefined ) material.colorWrite = json.colorWrite;
  11356. if ( json.wireframe !== undefined ) material.wireframe = json.wireframe;
  11357. if ( json.wireframeLinewidth !== undefined ) material.wireframeLinewidth = json.wireframeLinewidth;
  11358. // for PointsMaterial
  11359. if ( json.size !== undefined ) material.size = json.size;
  11360. if ( json.sizeAttenuation !== undefined ) material.sizeAttenuation = json.sizeAttenuation;
  11361. // maps
  11362. if ( json.map !== undefined ) material.map = this.getTexture( json.map );
  11363. if ( json.alphaMap !== undefined ) {
  11364. material.alphaMap = this.getTexture( json.alphaMap );
  11365. material.transparent = true;
  11366. }
  11367. if ( json.bumpMap !== undefined ) material.bumpMap = this.getTexture( json.bumpMap );
  11368. if ( json.bumpScale !== undefined ) material.bumpScale = json.bumpScale;
  11369. if ( json.normalMap !== undefined ) material.normalMap = this.getTexture( json.normalMap );
  11370. if ( json.normalScale !== undefined ) {
  11371. var normalScale = json.normalScale;
  11372. if ( Array.isArray( normalScale ) === false ) {
  11373. // Blender exporter used to export a scalar. See #7459
  11374. normalScale = [ normalScale, normalScale ];
  11375. }
  11376. material.normalScale = new THREE.Vector2().fromArray( normalScale );
  11377. }
  11378. if ( json.displacementMap !== undefined ) material.displacementMap = this.getTexture( json.displacementMap );
  11379. if ( json.displacementScale !== undefined ) material.displacementScale = json.displacementScale;
  11380. if ( json.displacementBias !== undefined ) material.displacementBias = json.displacementBias;
  11381. if ( json.roughnessMap !== undefined ) material.roughnessMap = this.getTexture( json.roughnessMap );
  11382. if ( json.metalnessMap !== undefined ) material.metalnessMap = this.getTexture( json.metalnessMap );
  11383. if ( json.emissiveMap !== undefined ) material.emissiveMap = this.getTexture( json.emissiveMap );
  11384. if ( json.emissiveIntensity !== undefined ) material.emissiveIntensity = json.emissiveIntensity;
  11385. if ( json.specularMap !== undefined ) material.specularMap = this.getTexture( json.specularMap );
  11386. if ( json.envMap !== undefined ) {
  11387. material.envMap = this.getTexture( json.envMap );
  11388. material.combine = THREE.MultiplyOperation;
  11389. }
  11390. if ( json.reflectivity !== undefined ) material.reflectivity = json.reflectivity;
  11391. if ( json.lightMap !== undefined ) material.lightMap = this.getTexture( json.lightMap );
  11392. if ( json.lightMapIntensity !== undefined ) material.lightMapIntensity = json.lightMapIntensity;
  11393. if ( json.aoMap !== undefined ) material.aoMap = this.getTexture( json.aoMap );
  11394. if ( json.aoMapIntensity !== undefined ) material.aoMapIntensity = json.aoMapIntensity;
  11395. // MultiMaterial
  11396. if ( json.materials !== undefined ) {
  11397. for ( var i = 0, l = json.materials.length; i < l; i ++ ) {
  11398. material.materials.push( this.parse( json.materials[ i ] ) );
  11399. }
  11400. }
  11401. return material;
  11402. }
  11403. } );
  11404. // File:src/loaders/ObjectLoader.js
  11405. /**
  11406. * @author mrdoob / http://mrdoob.com/
  11407. */
  11408. THREE.ObjectLoader = function ( manager ) {
  11409. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  11410. this.texturePath = '';
  11411. };
  11412. Object.assign( THREE.ObjectLoader.prototype, {
  11413. load: function ( url, onLoad, onProgress, onError ) {
  11414. if ( this.texturePath === '' ) {
  11415. this.texturePath = url.substring( 0, url.lastIndexOf( '/' ) + 1 );
  11416. }
  11417. var scope = this;
  11418. var loader = new THREE.XHRLoader( scope.manager );
  11419. loader.load( url, function ( text ) {
  11420. scope.parse( JSON.parse( text ), onLoad );
  11421. }, onProgress, onError );
  11422. },
  11423. setTexturePath: function ( value ) {
  11424. this.texturePath = value;
  11425. },
  11426. setCrossOrigin: function ( value ) {
  11427. this.crossOrigin = value;
  11428. },
  11429. parse: function ( json, onLoad ) {
  11430. var geometries = this.parseGeometries( json.geometries );
  11431. var images = this.parseImages( json.images, function () {
  11432. if ( onLoad !== undefined ) onLoad( object );
  11433. } );
  11434. var textures = this.parseTextures( json.textures, images );
  11435. var materials = this.parseMaterials( json.materials, textures );
  11436. var object = this.parseObject( json.object, geometries, materials );
  11437. if ( json.animations ) {
  11438. object.animations = this.parseAnimations( json.animations );
  11439. }
  11440. if ( json.images === undefined || json.images.length === 0 ) {
  11441. if ( onLoad !== undefined ) onLoad( object );
  11442. }
  11443. return object;
  11444. },
  11445. parseGeometries: function ( json ) {
  11446. var geometries = {};
  11447. if ( json !== undefined ) {
  11448. var geometryLoader = new THREE.JSONLoader();
  11449. var bufferGeometryLoader = new THREE.BufferGeometryLoader();
  11450. for ( var i = 0, l = json.length; i < l; i ++ ) {
  11451. var geometry;
  11452. var data = json[ i ];
  11453. switch ( data.type ) {
  11454. case 'PlaneGeometry':
  11455. case 'PlaneBufferGeometry':
  11456. geometry = new THREE[ data.type ](
  11457. data.width,
  11458. data.height,
  11459. data.widthSegments,
  11460. data.heightSegments
  11461. );
  11462. break;
  11463. case 'BoxGeometry':
  11464. case 'BoxBufferGeometry':
  11465. case 'CubeGeometry': // backwards compatible
  11466. geometry = new THREE[ data.type ](
  11467. data.width,
  11468. data.height,
  11469. data.depth,
  11470. data.widthSegments,
  11471. data.heightSegments,
  11472. data.depthSegments
  11473. );
  11474. break;
  11475. case 'CircleGeometry':
  11476. case 'CircleBufferGeometry':
  11477. geometry = new THREE[ data.type ](
  11478. data.radius,
  11479. data.segments,
  11480. data.thetaStart,
  11481. data.thetaLength
  11482. );
  11483. break;
  11484. case 'CylinderGeometry':
  11485. case 'CylinderBufferGeometry':
  11486. geometry = new THREE[ data.type ](
  11487. data.radiusTop,
  11488. data.radiusBottom,
  11489. data.height,
  11490. data.radialSegments,
  11491. data.heightSegments,
  11492. data.openEnded,
  11493. data.thetaStart,
  11494. data.thetaLength
  11495. );
  11496. break;
  11497. case 'ConeGeometry':
  11498. case 'ConeBufferGeometry':
  11499. geometry = new THREE [ data.type ](
  11500. data.radius,
  11501. data.height,
  11502. data.radialSegments,
  11503. data.heightSegments,
  11504. data.openEnded,
  11505. data.thetaStart,
  11506. data.thetaLength
  11507. );
  11508. break;
  11509. case 'SphereGeometry':
  11510. case 'SphereBufferGeometry':
  11511. geometry = new THREE[ data.type ](
  11512. data.radius,
  11513. data.widthSegments,
  11514. data.heightSegments,
  11515. data.phiStart,
  11516. data.phiLength,
  11517. data.thetaStart,
  11518. data.thetaLength
  11519. );
  11520. break;
  11521. case 'DodecahedronGeometry':
  11522. case 'IcosahedronGeometry':
  11523. case 'OctahedronGeometry':
  11524. case 'TetrahedronGeometry':
  11525. geometry = new THREE[ data.type ](
  11526. data.radius,
  11527. data.detail
  11528. );
  11529. break;
  11530. case 'RingGeometry':
  11531. case 'RingBufferGeometry':
  11532. geometry = new THREE[ data.type ](
  11533. data.innerRadius,
  11534. data.outerRadius,
  11535. data.thetaSegments,
  11536. data.phiSegments,
  11537. data.thetaStart,
  11538. data.thetaLength
  11539. );
  11540. break;
  11541. case 'TorusGeometry':
  11542. case 'TorusBufferGeometry':
  11543. geometry = new THREE[ data.type ](
  11544. data.radius,
  11545. data.tube,
  11546. data.radialSegments,
  11547. data.tubularSegments,
  11548. data.arc
  11549. );
  11550. break;
  11551. case 'TorusKnotGeometry':
  11552. case 'TorusKnotBufferGeometry':
  11553. geometry = new THREE[ data.type ](
  11554. data.radius,
  11555. data.tube,
  11556. data.tubularSegments,
  11557. data.radialSegments,
  11558. data.p,
  11559. data.q
  11560. );
  11561. break;
  11562. case 'LatheGeometry':
  11563. case 'LatheBufferGeometry':
  11564. geometry = new THREE[ data.type ](
  11565. data.points,
  11566. data.segments,
  11567. data.phiStart,
  11568. data.phiLength
  11569. );
  11570. break;
  11571. case 'BufferGeometry':
  11572. geometry = bufferGeometryLoader.parse( data );
  11573. break;
  11574. case 'Geometry':
  11575. geometry = geometryLoader.parse( data.data, this.texturePath ).geometry;
  11576. break;
  11577. default:
  11578. console.warn( 'THREE.ObjectLoader: Unsupported geometry type "' + data.type + '"' );
  11579. continue;
  11580. }
  11581. geometry.uuid = data.uuid;
  11582. if ( data.name !== undefined ) geometry.name = data.name;
  11583. geometries[ data.uuid ] = geometry;
  11584. }
  11585. }
  11586. return geometries;
  11587. },
  11588. parseMaterials: function ( json, textures ) {
  11589. var materials = {};
  11590. if ( json !== undefined ) {
  11591. var loader = new THREE.MaterialLoader();
  11592. loader.setTextures( textures );
  11593. for ( var i = 0, l = json.length; i < l; i ++ ) {
  11594. var material = loader.parse( json[ i ] );
  11595. materials[ material.uuid ] = material;
  11596. }
  11597. }
  11598. return materials;
  11599. },
  11600. parseAnimations: function ( json ) {
  11601. var animations = [];
  11602. for ( var i = 0; i < json.length; i ++ ) {
  11603. var clip = THREE.AnimationClip.parse( json[ i ] );
  11604. animations.push( clip );
  11605. }
  11606. return animations;
  11607. },
  11608. parseImages: function ( json, onLoad ) {
  11609. var scope = this;
  11610. var images = {};
  11611. function loadImage( url ) {
  11612. scope.manager.itemStart( url );
  11613. return loader.load( url, function () {
  11614. scope.manager.itemEnd( url );
  11615. } );
  11616. }
  11617. if ( json !== undefined && json.length > 0 ) {
  11618. var manager = new THREE.LoadingManager( onLoad );
  11619. var loader = new THREE.ImageLoader( manager );
  11620. loader.setCrossOrigin( this.crossOrigin );
  11621. for ( var i = 0, l = json.length; i < l; i ++ ) {
  11622. var image = json[ i ];
  11623. var path = /^(\/\/)|([a-z]+:(\/\/)?)/i.test( image.url ) ? image.url : scope.texturePath + image.url;
  11624. images[ image.uuid ] = loadImage( path );
  11625. }
  11626. }
  11627. return images;
  11628. },
  11629. parseTextures: function ( json, images ) {
  11630. function parseConstant( value ) {
  11631. if ( typeof( value ) === 'number' ) return value;
  11632. console.warn( 'THREE.ObjectLoader.parseTexture: Constant should be in numeric form.', value );
  11633. return THREE[ value ];
  11634. }
  11635. var textures = {};
  11636. if ( json !== undefined ) {
  11637. for ( var i = 0, l = json.length; i < l; i ++ ) {
  11638. var data = json[ i ];
  11639. if ( data.image === undefined ) {
  11640. console.warn( 'THREE.ObjectLoader: No "image" specified for', data.uuid );
  11641. }
  11642. if ( images[ data.image ] === undefined ) {
  11643. console.warn( 'THREE.ObjectLoader: Undefined image', data.image );
  11644. }
  11645. var texture = new THREE.Texture( images[ data.image ] );
  11646. texture.needsUpdate = true;
  11647. texture.uuid = data.uuid;
  11648. if ( data.name !== undefined ) texture.name = data.name;
  11649. if ( data.mapping !== undefined ) texture.mapping = parseConstant( data.mapping );
  11650. if ( data.offset !== undefined ) texture.offset = new THREE.Vector2( data.offset[ 0 ], data.offset[ 1 ] );
  11651. if ( data.repeat !== undefined ) texture.repeat = new THREE.Vector2( data.repeat[ 0 ], data.repeat[ 1 ] );
  11652. if ( data.minFilter !== undefined ) texture.minFilter = parseConstant( data.minFilter );
  11653. if ( data.magFilter !== undefined ) texture.magFilter = parseConstant( data.magFilter );
  11654. if ( data.anisotropy !== undefined ) texture.anisotropy = data.anisotropy;
  11655. if ( Array.isArray( data.wrap ) ) {
  11656. texture.wrapS = parseConstant( data.wrap[ 0 ] );
  11657. texture.wrapT = parseConstant( data.wrap[ 1 ] );
  11658. }
  11659. textures[ data.uuid ] = texture;
  11660. }
  11661. }
  11662. return textures;
  11663. },
  11664. parseObject: function () {
  11665. var matrix = new THREE.Matrix4();
  11666. return function parseObject( data, geometries, materials ) {
  11667. var object;
  11668. function getGeometry( name ) {
  11669. if ( geometries[ name ] === undefined ) {
  11670. console.warn( 'THREE.ObjectLoader: Undefined geometry', name );
  11671. }
  11672. return geometries[ name ];
  11673. }
  11674. function getMaterial( name ) {
  11675. if ( name === undefined ) return undefined;
  11676. if ( materials[ name ] === undefined ) {
  11677. console.warn( 'THREE.ObjectLoader: Undefined material', name );
  11678. }
  11679. return materials[ name ];
  11680. }
  11681. switch ( data.type ) {
  11682. case 'Scene':
  11683. object = new THREE.Scene();
  11684. break;
  11685. case 'PerspectiveCamera':
  11686. object = new THREE.PerspectiveCamera( data.fov, data.aspect, data.near, data.far );
  11687. if ( data.focus !== undefined ) object.focus = data.focus;
  11688. if ( data.zoom !== undefined ) object.zoom = data.zoom;
  11689. if ( data.filmGauge !== undefined ) object.filmGauge = data.filmGauge;
  11690. if ( data.filmOffset !== undefined ) object.filmOffset = data.filmOffset;
  11691. if ( data.view !== undefined ) object.view = Object.assign( {}, data.view );
  11692. break;
  11693. case 'OrthographicCamera':
  11694. object = new THREE.OrthographicCamera( data.left, data.right, data.top, data.bottom, data.near, data.far );
  11695. break;
  11696. case 'AmbientLight':
  11697. object = new THREE.AmbientLight( data.color, data.intensity );
  11698. break;
  11699. case 'DirectionalLight':
  11700. object = new THREE.DirectionalLight( data.color, data.intensity );
  11701. break;
  11702. case 'PointLight':
  11703. object = new THREE.PointLight( data.color, data.intensity, data.distance, data.decay );
  11704. break;
  11705. case 'SpotLight':
  11706. object = new THREE.SpotLight( data.color, data.intensity, data.distance, data.angle, data.penumbra, data.decay );
  11707. break;
  11708. case 'HemisphereLight':
  11709. object = new THREE.HemisphereLight( data.color, data.groundColor, data.intensity );
  11710. break;
  11711. case 'Mesh':
  11712. var geometry = getGeometry( data.geometry );
  11713. var material = getMaterial( data.material );
  11714. if ( geometry.bones && geometry.bones.length > 0 ) {
  11715. object = new THREE.SkinnedMesh( geometry, material );
  11716. } else {
  11717. object = new THREE.Mesh( geometry, material );
  11718. }
  11719. break;
  11720. case 'LOD':
  11721. object = new THREE.LOD();
  11722. break;
  11723. case 'Line':
  11724. object = new THREE.Line( getGeometry( data.geometry ), getMaterial( data.material ), data.mode );
  11725. break;
  11726. case 'PointCloud':
  11727. case 'Points':
  11728. object = new THREE.Points( getGeometry( data.geometry ), getMaterial( data.material ) );
  11729. break;
  11730. case 'Sprite':
  11731. object = new THREE.Sprite( getMaterial( data.material ) );
  11732. break;
  11733. case 'Group':
  11734. object = new THREE.Group();
  11735. break;
  11736. default:
  11737. object = new THREE.Object3D();
  11738. }
  11739. object.uuid = data.uuid;
  11740. if ( data.name !== undefined ) object.name = data.name;
  11741. if ( data.matrix !== undefined ) {
  11742. matrix.fromArray( data.matrix );
  11743. matrix.decompose( object.position, object.quaternion, object.scale );
  11744. } else {
  11745. if ( data.position !== undefined ) object.position.fromArray( data.position );
  11746. if ( data.rotation !== undefined ) object.rotation.fromArray( data.rotation );
  11747. if ( data.scale !== undefined ) object.scale.fromArray( data.scale );
  11748. }
  11749. if ( data.castShadow !== undefined ) object.castShadow = data.castShadow;
  11750. if ( data.receiveShadow !== undefined ) object.receiveShadow = data.receiveShadow;
  11751. if ( data.visible !== undefined ) object.visible = data.visible;
  11752. if ( data.userData !== undefined ) object.userData = data.userData;
  11753. if ( data.children !== undefined ) {
  11754. for ( var child in data.children ) {
  11755. object.add( this.parseObject( data.children[ child ], geometries, materials ) );
  11756. }
  11757. }
  11758. if ( data.type === 'LOD' ) {
  11759. var levels = data.levels;
  11760. for ( var l = 0; l < levels.length; l ++ ) {
  11761. var level = levels[ l ];
  11762. var child = object.getObjectByProperty( 'uuid', level.object );
  11763. if ( child !== undefined ) {
  11764. object.addLevel( child, level.distance );
  11765. }
  11766. }
  11767. }
  11768. return object;
  11769. };
  11770. }()
  11771. } );
  11772. // File:src/loaders/TextureLoader.js
  11773. /**
  11774. * @author mrdoob / http://mrdoob.com/
  11775. */
  11776. THREE.TextureLoader = function ( manager ) {
  11777. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  11778. };
  11779. Object.assign( THREE.TextureLoader.prototype, {
  11780. load: function ( url, onLoad, onProgress, onError ) {
  11781. var texture = new THREE.Texture();
  11782. var loader = new THREE.ImageLoader( this.manager );
  11783. loader.setCrossOrigin( this.crossOrigin );
  11784. loader.setPath( this.path );
  11785. loader.load( url, function ( image ) {
  11786. texture.image = image;
  11787. texture.needsUpdate = true;
  11788. if ( onLoad !== undefined ) {
  11789. onLoad( texture );
  11790. }
  11791. }, onProgress, onError );
  11792. return texture;
  11793. },
  11794. setCrossOrigin: function ( value ) {
  11795. this.crossOrigin = value;
  11796. return this;
  11797. },
  11798. setPath: function ( value ) {
  11799. this.path = value;
  11800. return this;
  11801. }
  11802. } );
  11803. // File:src/loaders/CubeTextureLoader.js
  11804. /**
  11805. * @author mrdoob / http://mrdoob.com/
  11806. */
  11807. THREE.CubeTextureLoader = function ( manager ) {
  11808. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  11809. };
  11810. Object.assign( THREE.CubeTextureLoader.prototype, {
  11811. load: function ( urls, onLoad, onProgress, onError ) {
  11812. var texture = new THREE.CubeTexture();
  11813. var loader = new THREE.ImageLoader( this.manager );
  11814. loader.setCrossOrigin( this.crossOrigin );
  11815. loader.setPath( this.path );
  11816. var loaded = 0;
  11817. function loadTexture( i ) {
  11818. loader.load( urls[ i ], function ( image ) {
  11819. texture.images[ i ] = image;
  11820. loaded ++;
  11821. if ( loaded === 6 ) {
  11822. texture.needsUpdate = true;
  11823. if ( onLoad ) onLoad( texture );
  11824. }
  11825. }, undefined, onError );
  11826. }
  11827. for ( var i = 0; i < urls.length; ++ i ) {
  11828. loadTexture( i );
  11829. }
  11830. return texture;
  11831. },
  11832. setCrossOrigin: function ( value ) {
  11833. this.crossOrigin = value;
  11834. return this;
  11835. },
  11836. setPath: function ( value ) {
  11837. this.path = value;
  11838. return this;
  11839. }
  11840. } );
  11841. // File:src/loaders/BinaryTextureLoader.js
  11842. /**
  11843. * @author Nikos M. / https://github.com/foo123/
  11844. *
  11845. * Abstract Base class to load generic binary textures formats (rgbe, hdr, ...)
  11846. */
  11847. THREE.DataTextureLoader = THREE.BinaryTextureLoader = function ( manager ) {
  11848. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  11849. // override in sub classes
  11850. this._parser = null;
  11851. };
  11852. Object.assign( THREE.BinaryTextureLoader.prototype, {
  11853. load: function ( url, onLoad, onProgress, onError ) {
  11854. var scope = this;
  11855. var texture = new THREE.DataTexture();
  11856. var loader = new THREE.XHRLoader( this.manager );
  11857. loader.setResponseType( 'arraybuffer' );
  11858. loader.load( url, function ( buffer ) {
  11859. var texData = scope._parser( buffer );
  11860. if ( ! texData ) return;
  11861. if ( undefined !== texData.image ) {
  11862. texture.image = texData.image;
  11863. } else if ( undefined !== texData.data ) {
  11864. texture.image.width = texData.width;
  11865. texture.image.height = texData.height;
  11866. texture.image.data = texData.data;
  11867. }
  11868. texture.wrapS = undefined !== texData.wrapS ? texData.wrapS : THREE.ClampToEdgeWrapping;
  11869. texture.wrapT = undefined !== texData.wrapT ? texData.wrapT : THREE.ClampToEdgeWrapping;
  11870. texture.magFilter = undefined !== texData.magFilter ? texData.magFilter : THREE.LinearFilter;
  11871. texture.minFilter = undefined !== texData.minFilter ? texData.minFilter : THREE.LinearMipMapLinearFilter;
  11872. texture.anisotropy = undefined !== texData.anisotropy ? texData.anisotropy : 1;
  11873. if ( undefined !== texData.format ) {
  11874. texture.format = texData.format;
  11875. }
  11876. if ( undefined !== texData.type ) {
  11877. texture.type = texData.type;
  11878. }
  11879. if ( undefined !== texData.mipmaps ) {
  11880. texture.mipmaps = texData.mipmaps;
  11881. }
  11882. if ( 1 === texData.mipmapCount ) {
  11883. texture.minFilter = THREE.LinearFilter;
  11884. }
  11885. texture.needsUpdate = true;
  11886. if ( onLoad ) onLoad( texture, texData );
  11887. }, onProgress, onError );
  11888. return texture;
  11889. }
  11890. } );
  11891. // File:src/loaders/CompressedTextureLoader.js
  11892. /**
  11893. * @author mrdoob / http://mrdoob.com/
  11894. *
  11895. * Abstract Base class to block based textures loader (dds, pvr, ...)
  11896. */
  11897. THREE.CompressedTextureLoader = function ( manager ) {
  11898. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  11899. // override in sub classes
  11900. this._parser = null;
  11901. };
  11902. Object.assign( THREE.CompressedTextureLoader.prototype, {
  11903. load: function ( url, onLoad, onProgress, onError ) {
  11904. var scope = this;
  11905. var images = [];
  11906. var texture = new THREE.CompressedTexture();
  11907. texture.image = images;
  11908. var loader = new THREE.XHRLoader( this.manager );
  11909. loader.setPath( this.path );
  11910. loader.setResponseType( 'arraybuffer' );
  11911. function loadTexture( i ) {
  11912. loader.load( url[ i ], function ( buffer ) {
  11913. var texDatas = scope._parser( buffer, true );
  11914. images[ i ] = {
  11915. width: texDatas.width,
  11916. height: texDatas.height,
  11917. format: texDatas.format,
  11918. mipmaps: texDatas.mipmaps
  11919. };
  11920. loaded += 1;
  11921. if ( loaded === 6 ) {
  11922. if ( texDatas.mipmapCount === 1 )
  11923. texture.minFilter = THREE.LinearFilter;
  11924. texture.format = texDatas.format;
  11925. texture.needsUpdate = true;
  11926. if ( onLoad ) onLoad( texture );
  11927. }
  11928. }, onProgress, onError );
  11929. }
  11930. if ( Array.isArray( url ) ) {
  11931. var loaded = 0;
  11932. for ( var i = 0, il = url.length; i < il; ++ i ) {
  11933. loadTexture( i );
  11934. }
  11935. } else {
  11936. // compressed cubemap texture stored in a single DDS file
  11937. loader.load( url, function ( buffer ) {
  11938. var texDatas = scope._parser( buffer, true );
  11939. if ( texDatas.isCubemap ) {
  11940. var faces = texDatas.mipmaps.length / texDatas.mipmapCount;
  11941. for ( var f = 0; f < faces; f ++ ) {
  11942. images[ f ] = { mipmaps : [] };
  11943. for ( var i = 0; i < texDatas.mipmapCount; i ++ ) {
  11944. images[ f ].mipmaps.push( texDatas.mipmaps[ f * texDatas.mipmapCount + i ] );
  11945. images[ f ].format = texDatas.format;
  11946. images[ f ].width = texDatas.width;
  11947. images[ f ].height = texDatas.height;
  11948. }
  11949. }
  11950. } else {
  11951. texture.image.width = texDatas.width;
  11952. texture.image.height = texDatas.height;
  11953. texture.mipmaps = texDatas.mipmaps;
  11954. }
  11955. if ( texDatas.mipmapCount === 1 ) {
  11956. texture.minFilter = THREE.LinearFilter;
  11957. }
  11958. texture.format = texDatas.format;
  11959. texture.needsUpdate = true;
  11960. if ( onLoad ) onLoad( texture );
  11961. }, onProgress, onError );
  11962. }
  11963. return texture;
  11964. },
  11965. setPath: function ( value ) {
  11966. this.path = value;
  11967. return this;
  11968. }
  11969. } );
  11970. // File:src/materials/Material.js
  11971. /**
  11972. * @author mrdoob / http://mrdoob.com/
  11973. * @author alteredq / http://alteredqualia.com/
  11974. */
  11975. THREE.Material = function () {
  11976. Object.defineProperty( this, 'id', { value: THREE.MaterialIdCount ++ } );
  11977. this.uuid = THREE.Math.generateUUID();
  11978. this.name = '';
  11979. this.type = 'Material';
  11980. this.fog = true;
  11981. this.lights = true;
  11982. this.blending = THREE.NormalBlending;
  11983. this.side = THREE.FrontSide;
  11984. this.shading = THREE.SmoothShading; // THREE.FlatShading, THREE.SmoothShading
  11985. this.vertexColors = THREE.NoColors; // THREE.NoColors, THREE.VertexColors, THREE.FaceColors
  11986. this.opacity = 1;
  11987. this.transparent = false;
  11988. this.blendSrc = THREE.SrcAlphaFactor;
  11989. this.blendDst = THREE.OneMinusSrcAlphaFactor;
  11990. this.blendEquation = THREE.AddEquation;
  11991. this.blendSrcAlpha = null;
  11992. this.blendDstAlpha = null;
  11993. this.blendEquationAlpha = null;
  11994. this.depthFunc = THREE.LessEqualDepth;
  11995. this.depthTest = true;
  11996. this.depthWrite = true;
  11997. this.clippingPlanes = null;
  11998. this.clipShadows = false;
  11999. this.colorWrite = true;
  12000. this.precision = null; // override the renderer's default precision for this material
  12001. this.polygonOffset = false;
  12002. this.polygonOffsetFactor = 0;
  12003. this.polygonOffsetUnits = 0;
  12004. this.alphaTest = 0;
  12005. this.premultipliedAlpha = false;
  12006. this.overdraw = 0; // Overdrawn pixels (typically between 0 and 1) for fixing antialiasing gaps in CanvasRenderer
  12007. this.visible = true;
  12008. this._needsUpdate = true;
  12009. };
  12010. THREE.Material.prototype = {
  12011. constructor: THREE.Material,
  12012. get needsUpdate() {
  12013. return this._needsUpdate;
  12014. },
  12015. set needsUpdate( value ) {
  12016. if ( value === true ) this.update();
  12017. this._needsUpdate = value;
  12018. },
  12019. setValues: function ( values ) {
  12020. if ( values === undefined ) return;
  12021. for ( var key in values ) {
  12022. var newValue = values[ key ];
  12023. if ( newValue === undefined ) {
  12024. console.warn( "THREE.Material: '" + key + "' parameter is undefined." );
  12025. continue;
  12026. }
  12027. var currentValue = this[ key ];
  12028. if ( currentValue === undefined ) {
  12029. console.warn( "THREE." + this.type + ": '" + key + "' is not a property of this material." );
  12030. continue;
  12031. }
  12032. if ( currentValue instanceof THREE.Color ) {
  12033. currentValue.set( newValue );
  12034. } else if ( currentValue instanceof THREE.Vector3 && newValue instanceof THREE.Vector3 ) {
  12035. currentValue.copy( newValue );
  12036. } else if ( key === 'overdraw' ) {
  12037. // ensure overdraw is backwards-compatible with legacy boolean type
  12038. this[ key ] = Number( newValue );
  12039. } else {
  12040. this[ key ] = newValue;
  12041. }
  12042. }
  12043. },
  12044. toJSON: function ( meta ) {
  12045. var isRoot = meta === undefined;
  12046. if ( isRoot ) {
  12047. meta = {
  12048. textures: {},
  12049. images: {}
  12050. };
  12051. }
  12052. var data = {
  12053. metadata: {
  12054. version: 4.4,
  12055. type: 'Material',
  12056. generator: 'Material.toJSON'
  12057. }
  12058. };
  12059. // standard Material serialization
  12060. data.uuid = this.uuid;
  12061. data.type = this.type;
  12062. if ( this.name !== '' ) data.name = this.name;
  12063. if ( this.color instanceof THREE.Color ) data.color = this.color.getHex();
  12064. if ( this.roughness !== undefined ) data.roughness = this.roughness;
  12065. if ( this.metalness !== undefined ) data.metalness = this.metalness;
  12066. if ( this.emissive instanceof THREE.Color ) data.emissive = this.emissive.getHex();
  12067. if ( this.specular instanceof THREE.Color ) data.specular = this.specular.getHex();
  12068. if ( this.shininess !== undefined ) data.shininess = this.shininess;
  12069. if ( this.map instanceof THREE.Texture ) data.map = this.map.toJSON( meta ).uuid;
  12070. if ( this.alphaMap instanceof THREE.Texture ) data.alphaMap = this.alphaMap.toJSON( meta ).uuid;
  12071. if ( this.lightMap instanceof THREE.Texture ) data.lightMap = this.lightMap.toJSON( meta ).uuid;
  12072. if ( this.bumpMap instanceof THREE.Texture ) {
  12073. data.bumpMap = this.bumpMap.toJSON( meta ).uuid;
  12074. data.bumpScale = this.bumpScale;
  12075. }
  12076. if ( this.normalMap instanceof THREE.Texture ) {
  12077. data.normalMap = this.normalMap.toJSON( meta ).uuid;
  12078. data.normalScale = this.normalScale.toArray();
  12079. }
  12080. if ( this.displacementMap instanceof THREE.Texture ) {
  12081. data.displacementMap = this.displacementMap.toJSON( meta ).uuid;
  12082. data.displacementScale = this.displacementScale;
  12083. data.displacementBias = this.displacementBias;
  12084. }
  12085. if ( this.roughnessMap instanceof THREE.Texture ) data.roughnessMap = this.roughnessMap.toJSON( meta ).uuid;
  12086. if ( this.metalnessMap instanceof THREE.Texture ) data.metalnessMap = this.metalnessMap.toJSON( meta ).uuid;
  12087. if ( this.emissiveMap instanceof THREE.Texture ) data.emissiveMap = this.emissiveMap.toJSON( meta ).uuid;
  12088. if ( this.specularMap instanceof THREE.Texture ) data.specularMap = this.specularMap.toJSON( meta ).uuid;
  12089. if ( this.envMap instanceof THREE.Texture ) {
  12090. data.envMap = this.envMap.toJSON( meta ).uuid;
  12091. data.reflectivity = this.reflectivity; // Scale behind envMap
  12092. }
  12093. if ( this.size !== undefined ) data.size = this.size;
  12094. if ( this.sizeAttenuation !== undefined ) data.sizeAttenuation = this.sizeAttenuation;
  12095. if ( this.blending !== THREE.NormalBlending ) data.blending = this.blending;
  12096. if ( this.shading !== THREE.SmoothShading ) data.shading = this.shading;
  12097. if ( this.side !== THREE.FrontSide ) data.side = this.side;
  12098. if ( this.vertexColors !== THREE.NoColors ) data.vertexColors = this.vertexColors;
  12099. if ( this.opacity < 1 ) data.opacity = this.opacity;
  12100. if ( this.transparent === true ) data.transparent = this.transparent;
  12101. if ( this.alphaTest > 0 ) data.alphaTest = this.alphaTest;
  12102. if ( this.premultipliedAlpha === true ) data.premultipliedAlpha = this.premultipliedAlpha;
  12103. if ( this.wireframe === true ) data.wireframe = this.wireframe;
  12104. if ( this.wireframeLinewidth > 1 ) data.wireframeLinewidth = this.wireframeLinewidth;
  12105. // TODO: Copied from Object3D.toJSON
  12106. function extractFromCache ( cache ) {
  12107. var values = [];
  12108. for ( var key in cache ) {
  12109. var data = cache[ key ];
  12110. delete data.metadata;
  12111. values.push( data );
  12112. }
  12113. return values;
  12114. }
  12115. if ( isRoot ) {
  12116. var textures = extractFromCache( meta.textures );
  12117. var images = extractFromCache( meta.images );
  12118. if ( textures.length > 0 ) data.textures = textures;
  12119. if ( images.length > 0 ) data.images = images;
  12120. }
  12121. return data;
  12122. },
  12123. clone: function () {
  12124. return new this.constructor().copy( this );
  12125. },
  12126. copy: function ( source ) {
  12127. this.name = source.name;
  12128. this.fog = source.fog;
  12129. this.lights = source.lights;
  12130. this.blending = source.blending;
  12131. this.side = source.side;
  12132. this.shading = source.shading;
  12133. this.vertexColors = source.vertexColors;
  12134. this.opacity = source.opacity;
  12135. this.transparent = source.transparent;
  12136. this.blendSrc = source.blendSrc;
  12137. this.blendDst = source.blendDst;
  12138. this.blendEquation = source.blendEquation;
  12139. this.blendSrcAlpha = source.blendSrcAlpha;
  12140. this.blendDstAlpha = source.blendDstAlpha;
  12141. this.blendEquationAlpha = source.blendEquationAlpha;
  12142. this.depthFunc = source.depthFunc;
  12143. this.depthTest = source.depthTest;
  12144. this.depthWrite = source.depthWrite;
  12145. this.colorWrite = source.colorWrite;
  12146. this.precision = source.precision;
  12147. this.polygonOffset = source.polygonOffset;
  12148. this.polygonOffsetFactor = source.polygonOffsetFactor;
  12149. this.polygonOffsetUnits = source.polygonOffsetUnits;
  12150. this.alphaTest = source.alphaTest;
  12151. this.premultipliedAlpha = source.premultipliedAlpha;
  12152. this.overdraw = source.overdraw;
  12153. this.visible = source.visible;
  12154. this.clipShadows = source.clipShadows;
  12155. var srcPlanes = source.clippingPlanes,
  12156. dstPlanes = null;
  12157. if ( srcPlanes !== null ) {
  12158. var n = srcPlanes.length;
  12159. dstPlanes = new Array( n );
  12160. for ( var i = 0; i !== n; ++ i )
  12161. dstPlanes[ i ] = srcPlanes[ i ].clone();
  12162. }
  12163. this.clippingPlanes = dstPlanes;
  12164. return this;
  12165. },
  12166. update: function () {
  12167. this.dispatchEvent( { type: 'update' } );
  12168. },
  12169. dispose: function () {
  12170. this.dispatchEvent( { type: 'dispose' } );
  12171. }
  12172. };
  12173. Object.assign( THREE.Material.prototype, THREE.EventDispatcher.prototype );
  12174. THREE.MaterialIdCount = 0;
  12175. // File:src/materials/LineBasicMaterial.js
  12176. /**
  12177. * @author mrdoob / http://mrdoob.com/
  12178. * @author alteredq / http://alteredqualia.com/
  12179. *
  12180. * parameters = {
  12181. * color: <hex>,
  12182. * opacity: <float>,
  12183. *
  12184. * linewidth: <float>,
  12185. * linecap: "round",
  12186. * linejoin: "round"
  12187. * }
  12188. */
  12189. THREE.LineBasicMaterial = function ( parameters ) {
  12190. THREE.Material.call( this );
  12191. this.type = 'LineBasicMaterial';
  12192. this.color = new THREE.Color( 0xffffff );
  12193. this.linewidth = 1;
  12194. this.linecap = 'round';
  12195. this.linejoin = 'round';
  12196. this.lights = false;
  12197. this.setValues( parameters );
  12198. };
  12199. THREE.LineBasicMaterial.prototype = Object.create( THREE.Material.prototype );
  12200. THREE.LineBasicMaterial.prototype.constructor = THREE.LineBasicMaterial;
  12201. THREE.LineBasicMaterial.prototype.copy = function ( source ) {
  12202. THREE.Material.prototype.copy.call( this, source );
  12203. this.color.copy( source.color );
  12204. this.linewidth = source.linewidth;
  12205. this.linecap = source.linecap;
  12206. this.linejoin = source.linejoin;
  12207. return this;
  12208. };
  12209. // File:src/materials/LineDashedMaterial.js
  12210. /**
  12211. * @author alteredq / http://alteredqualia.com/
  12212. *
  12213. * parameters = {
  12214. * color: <hex>,
  12215. * opacity: <float>,
  12216. *
  12217. * linewidth: <float>,
  12218. *
  12219. * scale: <float>,
  12220. * dashSize: <float>,
  12221. * gapSize: <float>
  12222. * }
  12223. */
  12224. THREE.LineDashedMaterial = function ( parameters ) {
  12225. THREE.Material.call( this );
  12226. this.type = 'LineDashedMaterial';
  12227. this.color = new THREE.Color( 0xffffff );
  12228. this.linewidth = 1;
  12229. this.scale = 1;
  12230. this.dashSize = 3;
  12231. this.gapSize = 1;
  12232. this.lights = false;
  12233. this.setValues( parameters );
  12234. };
  12235. THREE.LineDashedMaterial.prototype = Object.create( THREE.Material.prototype );
  12236. THREE.LineDashedMaterial.prototype.constructor = THREE.LineDashedMaterial;
  12237. THREE.LineDashedMaterial.prototype.copy = function ( source ) {
  12238. THREE.Material.prototype.copy.call( this, source );
  12239. this.color.copy( source.color );
  12240. this.linewidth = source.linewidth;
  12241. this.scale = source.scale;
  12242. this.dashSize = source.dashSize;
  12243. this.gapSize = source.gapSize;
  12244. return this;
  12245. };
  12246. // File:src/materials/MeshBasicMaterial.js
  12247. /**
  12248. * @author mrdoob / http://mrdoob.com/
  12249. * @author alteredq / http://alteredqualia.com/
  12250. *
  12251. * parameters = {
  12252. * color: <hex>,
  12253. * opacity: <float>,
  12254. * map: new THREE.Texture( <Image> ),
  12255. *
  12256. * aoMap: new THREE.Texture( <Image> ),
  12257. * aoMapIntensity: <float>
  12258. *
  12259. * specularMap: new THREE.Texture( <Image> ),
  12260. *
  12261. * alphaMap: new THREE.Texture( <Image> ),
  12262. *
  12263. * envMap: new THREE.TextureCube( [posx, negx, posy, negy, posz, negz] ),
  12264. * combine: THREE.Multiply,
  12265. * reflectivity: <float>,
  12266. * refractionRatio: <float>,
  12267. *
  12268. * shading: THREE.SmoothShading,
  12269. * depthTest: <bool>,
  12270. * depthWrite: <bool>,
  12271. *
  12272. * wireframe: <boolean>,
  12273. * wireframeLinewidth: <float>,
  12274. *
  12275. * skinning: <bool>,
  12276. * morphTargets: <bool>
  12277. * }
  12278. */
  12279. THREE.MeshBasicMaterial = function ( parameters ) {
  12280. THREE.Material.call( this );
  12281. this.type = 'MeshBasicMaterial';
  12282. this.color = new THREE.Color( 0xffffff ); // emissive
  12283. this.map = null;
  12284. this.aoMap = null;
  12285. this.aoMapIntensity = 1.0;
  12286. this.specularMap = null;
  12287. this.alphaMap = null;
  12288. this.envMap = null;
  12289. this.combine = THREE.MultiplyOperation;
  12290. this.reflectivity = 1;
  12291. this.refractionRatio = 0.98;
  12292. this.wireframe = false;
  12293. this.wireframeLinewidth = 1;
  12294. this.wireframeLinecap = 'round';
  12295. this.wireframeLinejoin = 'round';
  12296. this.skinning = false;
  12297. this.morphTargets = false;
  12298. this.lights = false;
  12299. this.setValues( parameters );
  12300. };
  12301. THREE.MeshBasicMaterial.prototype = Object.create( THREE.Material.prototype );
  12302. THREE.MeshBasicMaterial.prototype.constructor = THREE.MeshBasicMaterial;
  12303. THREE.MeshBasicMaterial.prototype.copy = function ( source ) {
  12304. THREE.Material.prototype.copy.call( this, source );
  12305. this.color.copy( source.color );
  12306. this.map = source.map;
  12307. this.aoMap = source.aoMap;
  12308. this.aoMapIntensity = source.aoMapIntensity;
  12309. this.specularMap = source.specularMap;
  12310. this.alphaMap = source.alphaMap;
  12311. this.envMap = source.envMap;
  12312. this.combine = source.combine;
  12313. this.reflectivity = source.reflectivity;
  12314. this.refractionRatio = source.refractionRatio;
  12315. this.wireframe = source.wireframe;
  12316. this.wireframeLinewidth = source.wireframeLinewidth;
  12317. this.wireframeLinecap = source.wireframeLinecap;
  12318. this.wireframeLinejoin = source.wireframeLinejoin;
  12319. this.skinning = source.skinning;
  12320. this.morphTargets = source.morphTargets;
  12321. return this;
  12322. };
  12323. // File:src/materials/MeshDepthMaterial.js
  12324. /**
  12325. * @author mrdoob / http://mrdoob.com/
  12326. * @author alteredq / http://alteredqualia.com/
  12327. * @author bhouston / https://clara.io
  12328. * @author WestLangley / http://github.com/WestLangley
  12329. *
  12330. * parameters = {
  12331. *
  12332. * opacity: <float>,
  12333. *
  12334. * map: new THREE.Texture( <Image> ),
  12335. *
  12336. * alphaMap: new THREE.Texture( <Image> ),
  12337. *
  12338. * displacementMap: new THREE.Texture( <Image> ),
  12339. * displacementScale: <float>,
  12340. * displacementBias: <float>,
  12341. *
  12342. * wireframe: <boolean>,
  12343. * wireframeLinewidth: <float>
  12344. * }
  12345. */
  12346. THREE.MeshDepthMaterial = function ( parameters ) {
  12347. THREE.Material.call( this );
  12348. this.type = 'MeshDepthMaterial';
  12349. this.depthPacking = THREE.BasicDepthPacking;
  12350. this.skinning = false;
  12351. this.morphTargets = false;
  12352. this.map = null;
  12353. this.alphaMap = null;
  12354. this.displacementMap = null;
  12355. this.displacementScale = 1;
  12356. this.displacementBias = 0;
  12357. this.wireframe = false;
  12358. this.wireframeLinewidth = 1;
  12359. this.fog = false;
  12360. this.lights = false;
  12361. this.setValues( parameters );
  12362. };
  12363. THREE.MeshDepthMaterial.prototype = Object.create( THREE.Material.prototype );
  12364. THREE.MeshDepthMaterial.prototype.constructor = THREE.MeshDepthMaterial;
  12365. THREE.MeshDepthMaterial.prototype.copy = function ( source ) {
  12366. THREE.Material.prototype.copy.call( this, source );
  12367. this.depthPacking = source.depthPacking;
  12368. this.skinning = source.skinning;
  12369. this.morphTargets = source.morphTargets;
  12370. this.map = source.map;
  12371. this.alphaMap = source.alphaMap;
  12372. this.displacementMap = source.displacementMap;
  12373. this.displacementScale = source.displacementScale;
  12374. this.displacementBias = source.displacementBias;
  12375. this.wireframe = source.wireframe;
  12376. this.wireframeLinewidth = source.wireframeLinewidth;
  12377. return this;
  12378. };
  12379. // File:src/materials/MeshLambertMaterial.js
  12380. /**
  12381. * @author mrdoob / http://mrdoob.com/
  12382. * @author alteredq / http://alteredqualia.com/
  12383. *
  12384. * parameters = {
  12385. * color: <hex>,
  12386. * opacity: <float>,
  12387. *
  12388. * map: new THREE.Texture( <Image> ),
  12389. *
  12390. * lightMap: new THREE.Texture( <Image> ),
  12391. * lightMapIntensity: <float>
  12392. *
  12393. * aoMap: new THREE.Texture( <Image> ),
  12394. * aoMapIntensity: <float>
  12395. *
  12396. * emissive: <hex>,
  12397. * emissiveIntensity: <float>
  12398. * emissiveMap: new THREE.Texture( <Image> ),
  12399. *
  12400. * specularMap: new THREE.Texture( <Image> ),
  12401. *
  12402. * alphaMap: new THREE.Texture( <Image> ),
  12403. *
  12404. * envMap: new THREE.TextureCube( [posx, negx, posy, negy, posz, negz] ),
  12405. * combine: THREE.Multiply,
  12406. * reflectivity: <float>,
  12407. * refractionRatio: <float>,
  12408. *
  12409. * wireframe: <boolean>,
  12410. * wireframeLinewidth: <float>,
  12411. *
  12412. * skinning: <bool>,
  12413. * morphTargets: <bool>,
  12414. * morphNormals: <bool>
  12415. * }
  12416. */
  12417. THREE.MeshLambertMaterial = function ( parameters ) {
  12418. THREE.Material.call( this );
  12419. this.type = 'MeshLambertMaterial';
  12420. this.color = new THREE.Color( 0xffffff ); // diffuse
  12421. this.map = null;
  12422. this.lightMap = null;
  12423. this.lightMapIntensity = 1.0;
  12424. this.aoMap = null;
  12425. this.aoMapIntensity = 1.0;
  12426. this.emissive = new THREE.Color( 0x000000 );
  12427. this.emissiveIntensity = 1.0;
  12428. this.emissiveMap = null;
  12429. this.specularMap = null;
  12430. this.alphaMap = null;
  12431. this.envMap = null;
  12432. this.combine = THREE.MultiplyOperation;
  12433. this.reflectivity = 1;
  12434. this.refractionRatio = 0.98;
  12435. this.wireframe = false;
  12436. this.wireframeLinewidth = 1;
  12437. this.wireframeLinecap = 'round';
  12438. this.wireframeLinejoin = 'round';
  12439. this.skinning = false;
  12440. this.morphTargets = false;
  12441. this.morphNormals = false;
  12442. this.setValues( parameters );
  12443. };
  12444. THREE.MeshLambertMaterial.prototype = Object.create( THREE.Material.prototype );
  12445. THREE.MeshLambertMaterial.prototype.constructor = THREE.MeshLambertMaterial;
  12446. THREE.MeshLambertMaterial.prototype.copy = function ( source ) {
  12447. THREE.Material.prototype.copy.call( this, source );
  12448. this.color.copy( source.color );
  12449. this.map = source.map;
  12450. this.lightMap = source.lightMap;
  12451. this.lightMapIntensity = source.lightMapIntensity;
  12452. this.aoMap = source.aoMap;
  12453. this.aoMapIntensity = source.aoMapIntensity;
  12454. this.emissive.copy( source.emissive );
  12455. this.emissiveMap = source.emissiveMap;
  12456. this.emissiveIntensity = source.emissiveIntensity;
  12457. this.specularMap = source.specularMap;
  12458. this.alphaMap = source.alphaMap;
  12459. this.envMap = source.envMap;
  12460. this.combine = source.combine;
  12461. this.reflectivity = source.reflectivity;
  12462. this.refractionRatio = source.refractionRatio;
  12463. this.wireframe = source.wireframe;
  12464. this.wireframeLinewidth = source.wireframeLinewidth;
  12465. this.wireframeLinecap = source.wireframeLinecap;
  12466. this.wireframeLinejoin = source.wireframeLinejoin;
  12467. this.skinning = source.skinning;
  12468. this.morphTargets = source.morphTargets;
  12469. this.morphNormals = source.morphNormals;
  12470. return this;
  12471. };
  12472. // File:src/materials/MeshNormalMaterial.js
  12473. /**
  12474. * @author mrdoob / http://mrdoob.com/
  12475. *
  12476. * parameters = {
  12477. * opacity: <float>,
  12478. *
  12479. * wireframe: <boolean>,
  12480. * wireframeLinewidth: <float>
  12481. * }
  12482. */
  12483. THREE.MeshNormalMaterial = function ( parameters ) {
  12484. THREE.Material.call( this, parameters );
  12485. this.type = 'MeshNormalMaterial';
  12486. this.wireframe = false;
  12487. this.wireframeLinewidth = 1;
  12488. this.fog = false;
  12489. this.lights = false;
  12490. this.morphTargets = false;
  12491. this.setValues( parameters );
  12492. };
  12493. THREE.MeshNormalMaterial.prototype = Object.create( THREE.Material.prototype );
  12494. THREE.MeshNormalMaterial.prototype.constructor = THREE.MeshNormalMaterial;
  12495. THREE.MeshNormalMaterial.prototype.copy = function ( source ) {
  12496. THREE.Material.prototype.copy.call( this, source );
  12497. this.wireframe = source.wireframe;
  12498. this.wireframeLinewidth = source.wireframeLinewidth;
  12499. return this;
  12500. };
  12501. // File:src/materials/MeshPhongMaterial.js
  12502. /**
  12503. * @author mrdoob / http://mrdoob.com/
  12504. * @author alteredq / http://alteredqualia.com/
  12505. *
  12506. * parameters = {
  12507. * color: <hex>,
  12508. * specular: <hex>,
  12509. * shininess: <float>,
  12510. * opacity: <float>,
  12511. *
  12512. * map: new THREE.Texture( <Image> ),
  12513. *
  12514. * lightMap: new THREE.Texture( <Image> ),
  12515. * lightMapIntensity: <float>
  12516. *
  12517. * aoMap: new THREE.Texture( <Image> ),
  12518. * aoMapIntensity: <float>
  12519. *
  12520. * emissive: <hex>,
  12521. * emissiveIntensity: <float>
  12522. * emissiveMap: new THREE.Texture( <Image> ),
  12523. *
  12524. * bumpMap: new THREE.Texture( <Image> ),
  12525. * bumpScale: <float>,
  12526. *
  12527. * normalMap: new THREE.Texture( <Image> ),
  12528. * normalScale: <Vector2>,
  12529. *
  12530. * displacementMap: new THREE.Texture( <Image> ),
  12531. * displacementScale: <float>,
  12532. * displacementBias: <float>,
  12533. *
  12534. * specularMap: new THREE.Texture( <Image> ),
  12535. *
  12536. * alphaMap: new THREE.Texture( <Image> ),
  12537. *
  12538. * envMap: new THREE.TextureCube( [posx, negx, posy, negy, posz, negz] ),
  12539. * combine: THREE.Multiply,
  12540. * reflectivity: <float>,
  12541. * refractionRatio: <float>,
  12542. *
  12543. * wireframe: <boolean>,
  12544. * wireframeLinewidth: <float>,
  12545. *
  12546. * skinning: <bool>,
  12547. * morphTargets: <bool>,
  12548. * morphNormals: <bool>
  12549. * }
  12550. */
  12551. THREE.MeshPhongMaterial = function ( parameters ) {
  12552. THREE.Material.call( this );
  12553. this.type = 'MeshPhongMaterial';
  12554. this.color = new THREE.Color( 0xffffff ); // diffuse
  12555. this.specular = new THREE.Color( 0x111111 );
  12556. this.shininess = 30;
  12557. this.map = null;
  12558. this.lightMap = null;
  12559. this.lightMapIntensity = 1.0;
  12560. this.aoMap = null;
  12561. this.aoMapIntensity = 1.0;
  12562. this.emissive = new THREE.Color( 0x000000 );
  12563. this.emissiveIntensity = 1.0;
  12564. this.emissiveMap = null;
  12565. this.bumpMap = null;
  12566. this.bumpScale = 1;
  12567. this.normalMap = null;
  12568. this.normalScale = new THREE.Vector2( 1, 1 );
  12569. this.displacementMap = null;
  12570. this.displacementScale = 1;
  12571. this.displacementBias = 0;
  12572. this.specularMap = null;
  12573. this.alphaMap = null;
  12574. this.envMap = null;
  12575. this.combine = THREE.MultiplyOperation;
  12576. this.reflectivity = 1;
  12577. this.refractionRatio = 0.98;
  12578. this.wireframe = false;
  12579. this.wireframeLinewidth = 1;
  12580. this.wireframeLinecap = 'round';
  12581. this.wireframeLinejoin = 'round';
  12582. this.skinning = false;
  12583. this.morphTargets = false;
  12584. this.morphNormals = false;
  12585. this.setValues( parameters );
  12586. };
  12587. THREE.MeshPhongMaterial.prototype = Object.create( THREE.Material.prototype );
  12588. THREE.MeshPhongMaterial.prototype.constructor = THREE.MeshPhongMaterial;
  12589. THREE.MeshPhongMaterial.prototype.copy = function ( source ) {
  12590. THREE.Material.prototype.copy.call( this, source );
  12591. this.color.copy( source.color );
  12592. this.specular.copy( source.specular );
  12593. this.shininess = source.shininess;
  12594. this.map = source.map;
  12595. this.lightMap = source.lightMap;
  12596. this.lightMapIntensity = source.lightMapIntensity;
  12597. this.aoMap = source.aoMap;
  12598. this.aoMapIntensity = source.aoMapIntensity;
  12599. this.emissive.copy( source.emissive );
  12600. this.emissiveMap = source.emissiveMap;
  12601. this.emissiveIntensity = source.emissiveIntensity;
  12602. this.bumpMap = source.bumpMap;
  12603. this.bumpScale = source.bumpScale;
  12604. this.normalMap = source.normalMap;
  12605. this.normalScale.copy( source.normalScale );
  12606. this.displacementMap = source.displacementMap;
  12607. this.displacementScale = source.displacementScale;
  12608. this.displacementBias = source.displacementBias;
  12609. this.specularMap = source.specularMap;
  12610. this.alphaMap = source.alphaMap;
  12611. this.envMap = source.envMap;
  12612. this.combine = source.combine;
  12613. this.reflectivity = source.reflectivity;
  12614. this.refractionRatio = source.refractionRatio;
  12615. this.wireframe = source.wireframe;
  12616. this.wireframeLinewidth = source.wireframeLinewidth;
  12617. this.wireframeLinecap = source.wireframeLinecap;
  12618. this.wireframeLinejoin = source.wireframeLinejoin;
  12619. this.skinning = source.skinning;
  12620. this.morphTargets = source.morphTargets;
  12621. this.morphNormals = source.morphNormals;
  12622. return this;
  12623. };
  12624. // File:src/materials/MeshStandardMaterial.js
  12625. /**
  12626. * @author WestLangley / http://github.com/WestLangley
  12627. *
  12628. * parameters = {
  12629. * color: <hex>,
  12630. * roughness: <float>,
  12631. * metalness: <float>,
  12632. * opacity: <float>,
  12633. *
  12634. * map: new THREE.Texture( <Image> ),
  12635. *
  12636. * lightMap: new THREE.Texture( <Image> ),
  12637. * lightMapIntensity: <float>
  12638. *
  12639. * aoMap: new THREE.Texture( <Image> ),
  12640. * aoMapIntensity: <float>
  12641. *
  12642. * emissive: <hex>,
  12643. * emissiveIntensity: <float>
  12644. * emissiveMap: new THREE.Texture( <Image> ),
  12645. *
  12646. * bumpMap: new THREE.Texture( <Image> ),
  12647. * bumpScale: <float>,
  12648. *
  12649. * normalMap: new THREE.Texture( <Image> ),
  12650. * normalScale: <Vector2>,
  12651. *
  12652. * displacementMap: new THREE.Texture( <Image> ),
  12653. * displacementScale: <float>,
  12654. * displacementBias: <float>,
  12655. *
  12656. * roughnessMap: new THREE.Texture( <Image> ),
  12657. *
  12658. * metalnessMap: new THREE.Texture( <Image> ),
  12659. *
  12660. * alphaMap: new THREE.Texture( <Image> ),
  12661. *
  12662. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  12663. * envMapIntensity: <float>
  12664. *
  12665. * refractionRatio: <float>,
  12666. *
  12667. * wireframe: <boolean>,
  12668. * wireframeLinewidth: <float>,
  12669. *
  12670. * skinning: <bool>,
  12671. * morphTargets: <bool>,
  12672. * morphNormals: <bool>
  12673. * }
  12674. */
  12675. THREE.MeshStandardMaterial = function ( parameters ) {
  12676. THREE.Material.call( this );
  12677. this.defines = { 'STANDARD': '' };
  12678. this.type = 'MeshStandardMaterial';
  12679. this.color = new THREE.Color( 0xffffff ); // diffuse
  12680. this.roughness = 0.5;
  12681. this.metalness = 0.5;
  12682. this.map = null;
  12683. this.lightMap = null;
  12684. this.lightMapIntensity = 1.0;
  12685. this.aoMap = null;
  12686. this.aoMapIntensity = 1.0;
  12687. this.emissive = new THREE.Color( 0x000000 );
  12688. this.emissiveIntensity = 1.0;
  12689. this.emissiveMap = null;
  12690. this.bumpMap = null;
  12691. this.bumpScale = 1;
  12692. this.normalMap = null;
  12693. this.normalScale = new THREE.Vector2( 1, 1 );
  12694. this.displacementMap = null;
  12695. this.displacementScale = 1;
  12696. this.displacementBias = 0;
  12697. this.roughnessMap = null;
  12698. this.metalnessMap = null;
  12699. this.alphaMap = null;
  12700. this.envMap = null;
  12701. this.envMapIntensity = 1.0;
  12702. this.refractionRatio = 0.98;
  12703. this.wireframe = false;
  12704. this.wireframeLinewidth = 1;
  12705. this.wireframeLinecap = 'round';
  12706. this.wireframeLinejoin = 'round';
  12707. this.skinning = false;
  12708. this.morphTargets = false;
  12709. this.morphNormals = false;
  12710. this.setValues( parameters );
  12711. };
  12712. THREE.MeshStandardMaterial.prototype = Object.create( THREE.Material.prototype );
  12713. THREE.MeshStandardMaterial.prototype.constructor = THREE.MeshStandardMaterial;
  12714. THREE.MeshStandardMaterial.prototype.copy = function ( source ) {
  12715. THREE.Material.prototype.copy.call( this, source );
  12716. this.defines = { 'STANDARD': '' };
  12717. this.color.copy( source.color );
  12718. this.roughness = source.roughness;
  12719. this.metalness = source.metalness;
  12720. this.map = source.map;
  12721. this.lightMap = source.lightMap;
  12722. this.lightMapIntensity = source.lightMapIntensity;
  12723. this.aoMap = source.aoMap;
  12724. this.aoMapIntensity = source.aoMapIntensity;
  12725. this.emissive.copy( source.emissive );
  12726. this.emissiveMap = source.emissiveMap;
  12727. this.emissiveIntensity = source.emissiveIntensity;
  12728. this.bumpMap = source.bumpMap;
  12729. this.bumpScale = source.bumpScale;
  12730. this.normalMap = source.normalMap;
  12731. this.normalScale.copy( source.normalScale );
  12732. this.displacementMap = source.displacementMap;
  12733. this.displacementScale = source.displacementScale;
  12734. this.displacementBias = source.displacementBias;
  12735. this.roughnessMap = source.roughnessMap;
  12736. this.metalnessMap = source.metalnessMap;
  12737. this.alphaMap = source.alphaMap;
  12738. this.envMap = source.envMap;
  12739. this.envMapIntensity = source.envMapIntensity;
  12740. this.refractionRatio = source.refractionRatio;
  12741. this.wireframe = source.wireframe;
  12742. this.wireframeLinewidth = source.wireframeLinewidth;
  12743. this.wireframeLinecap = source.wireframeLinecap;
  12744. this.wireframeLinejoin = source.wireframeLinejoin;
  12745. this.skinning = source.skinning;
  12746. this.morphTargets = source.morphTargets;
  12747. this.morphNormals = source.morphNormals;
  12748. return this;
  12749. };
  12750. // File:src/materials/MeshPhysicalMaterial.js
  12751. /**
  12752. * @author WestLangley / http://github.com/WestLangley
  12753. *
  12754. * parameters = {
  12755. * reflectivity: <float>
  12756. * }
  12757. */
  12758. THREE.MeshPhysicalMaterial = function ( parameters ) {
  12759. THREE.MeshStandardMaterial.call( this );
  12760. this.defines = { 'PHYSICAL': '' };
  12761. this.type = 'MeshPhysicalMaterial';
  12762. this.reflectivity = 0.5; // maps to F0 = 0.04
  12763. this.clearCoat = 0.0;
  12764. this.clearCoatRoughness = 0.0;
  12765. this.setValues( parameters );
  12766. };
  12767. THREE.MeshPhysicalMaterial.prototype = Object.create( THREE.MeshStandardMaterial.prototype );
  12768. THREE.MeshPhysicalMaterial.prototype.constructor = THREE.MeshPhysicalMaterial;
  12769. THREE.MeshPhysicalMaterial.prototype.copy = function ( source ) {
  12770. THREE.MeshStandardMaterial.prototype.copy.call( this, source );
  12771. this.defines = { 'PHYSICAL': '' };
  12772. this.reflectivity = source.reflectivity;
  12773. this.clearCoat = source.clearCoat;
  12774. this.clearCoatRoughness = source.clearCoatRoughness;
  12775. return this;
  12776. };
  12777. // File:src/materials/MultiMaterial.js
  12778. /**
  12779. * @author mrdoob / http://mrdoob.com/
  12780. */
  12781. THREE.MultiMaterial = function ( materials ) {
  12782. this.uuid = THREE.Math.generateUUID();
  12783. this.type = 'MultiMaterial';
  12784. this.materials = materials instanceof Array ? materials : [];
  12785. this.visible = true;
  12786. };
  12787. THREE.MultiMaterial.prototype = {
  12788. constructor: THREE.MultiMaterial,
  12789. toJSON: function ( meta ) {
  12790. var output = {
  12791. metadata: {
  12792. version: 4.2,
  12793. type: 'material',
  12794. generator: 'MaterialExporter'
  12795. },
  12796. uuid: this.uuid,
  12797. type: this.type,
  12798. materials: []
  12799. };
  12800. var materials = this.materials;
  12801. for ( var i = 0, l = materials.length; i < l; i ++ ) {
  12802. var material = materials[ i ].toJSON( meta );
  12803. delete material.metadata;
  12804. output.materials.push( material );
  12805. }
  12806. output.visible = this.visible;
  12807. return output;
  12808. },
  12809. clone: function () {
  12810. var material = new this.constructor();
  12811. for ( var i = 0; i < this.materials.length; i ++ ) {
  12812. material.materials.push( this.materials[ i ].clone() );
  12813. }
  12814. material.visible = this.visible;
  12815. return material;
  12816. }
  12817. };
  12818. // File:src/materials/PointsMaterial.js
  12819. /**
  12820. * @author mrdoob / http://mrdoob.com/
  12821. * @author alteredq / http://alteredqualia.com/
  12822. *
  12823. * parameters = {
  12824. * color: <hex>,
  12825. * opacity: <float>,
  12826. * map: new THREE.Texture( <Image> ),
  12827. *
  12828. * size: <float>,
  12829. * sizeAttenuation: <bool>
  12830. * }
  12831. */
  12832. THREE.PointsMaterial = function ( parameters ) {
  12833. THREE.Material.call( this );
  12834. this.type = 'PointsMaterial';
  12835. this.color = new THREE.Color( 0xffffff );
  12836. this.map = null;
  12837. this.size = 1;
  12838. this.sizeAttenuation = true;
  12839. this.lights = false;
  12840. this.setValues( parameters );
  12841. };
  12842. THREE.PointsMaterial.prototype = Object.create( THREE.Material.prototype );
  12843. THREE.PointsMaterial.prototype.constructor = THREE.PointsMaterial;
  12844. THREE.PointsMaterial.prototype.copy = function ( source ) {
  12845. THREE.Material.prototype.copy.call( this, source );
  12846. this.color.copy( source.color );
  12847. this.map = source.map;
  12848. this.size = source.size;
  12849. this.sizeAttenuation = source.sizeAttenuation;
  12850. return this;
  12851. };
  12852. // File:src/materials/ShaderMaterial.js
  12853. /**
  12854. * @author alteredq / http://alteredqualia.com/
  12855. *
  12856. * parameters = {
  12857. * defines: { "label" : "value" },
  12858. * uniforms: { "parameter1": { value: 1.0 }, "parameter2": { value2: 2 } },
  12859. *
  12860. * fragmentShader: <string>,
  12861. * vertexShader: <string>,
  12862. *
  12863. * wireframe: <boolean>,
  12864. * wireframeLinewidth: <float>,
  12865. *
  12866. * lights: <bool>,
  12867. *
  12868. * skinning: <bool>,
  12869. * morphTargets: <bool>,
  12870. * morphNormals: <bool>
  12871. * }
  12872. */
  12873. THREE.ShaderMaterial = function ( parameters ) {
  12874. THREE.Material.call( this );
  12875. this.type = 'ShaderMaterial';
  12876. this.defines = {};
  12877. this.uniforms = {};
  12878. this.vertexShader = 'void main() {\n\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}';
  12879. this.fragmentShader = 'void main() {\n\tgl_FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );\n}';
  12880. this.linewidth = 1;
  12881. this.wireframe = false;
  12882. this.wireframeLinewidth = 1;
  12883. this.fog = false; // set to use scene fog
  12884. this.lights = false; // set to use scene lights
  12885. this.clipping = false; // set to use user-defined clipping planes
  12886. this.skinning = false; // set to use skinning attribute streams
  12887. this.morphTargets = false; // set to use morph targets
  12888. this.morphNormals = false; // set to use morph normals
  12889. this.extensions = {
  12890. derivatives: false, // set to use derivatives
  12891. fragDepth: false, // set to use fragment depth values
  12892. drawBuffers: false, // set to use draw buffers
  12893. shaderTextureLOD: false // set to use shader texture LOD
  12894. };
  12895. // When rendered geometry doesn't include these attributes but the material does,
  12896. // use these default values in WebGL. This avoids errors when buffer data is missing.
  12897. this.defaultAttributeValues = {
  12898. 'color': [ 1, 1, 1 ],
  12899. 'uv': [ 0, 0 ],
  12900. 'uv2': [ 0, 0 ]
  12901. };
  12902. this.index0AttributeName = undefined;
  12903. if ( parameters !== undefined ) {
  12904. if ( parameters.attributes !== undefined ) {
  12905. console.error( 'THREE.ShaderMaterial: attributes should now be defined in THREE.BufferGeometry instead.' );
  12906. }
  12907. this.setValues( parameters );
  12908. }
  12909. };
  12910. THREE.ShaderMaterial.prototype = Object.create( THREE.Material.prototype );
  12911. THREE.ShaderMaterial.prototype.constructor = THREE.ShaderMaterial;
  12912. THREE.ShaderMaterial.prototype.copy = function ( source ) {
  12913. THREE.Material.prototype.copy.call( this, source );
  12914. this.fragmentShader = source.fragmentShader;
  12915. this.vertexShader = source.vertexShader;
  12916. this.uniforms = THREE.UniformsUtils.clone( source.uniforms );
  12917. this.defines = source.defines;
  12918. this.wireframe = source.wireframe;
  12919. this.wireframeLinewidth = source.wireframeLinewidth;
  12920. this.lights = source.lights;
  12921. this.clipping = source.clipping;
  12922. this.skinning = source.skinning;
  12923. this.morphTargets = source.morphTargets;
  12924. this.morphNormals = source.morphNormals;
  12925. this.extensions = source.extensions;
  12926. return this;
  12927. };
  12928. THREE.ShaderMaterial.prototype.toJSON = function ( meta ) {
  12929. var data = THREE.Material.prototype.toJSON.call( this, meta );
  12930. data.uniforms = this.uniforms;
  12931. data.vertexShader = this.vertexShader;
  12932. data.fragmentShader = this.fragmentShader;
  12933. return data;
  12934. };
  12935. // File:src/materials/RawShaderMaterial.js
  12936. /**
  12937. * @author mrdoob / http://mrdoob.com/
  12938. */
  12939. THREE.RawShaderMaterial = function ( parameters ) {
  12940. THREE.ShaderMaterial.call( this, parameters );
  12941. this.type = 'RawShaderMaterial';
  12942. };
  12943. THREE.RawShaderMaterial.prototype = Object.create( THREE.ShaderMaterial.prototype );
  12944. THREE.RawShaderMaterial.prototype.constructor = THREE.RawShaderMaterial;
  12945. // File:src/materials/SpriteMaterial.js
  12946. /**
  12947. * @author alteredq / http://alteredqualia.com/
  12948. *
  12949. * parameters = {
  12950. * color: <hex>,
  12951. * opacity: <float>,
  12952. * map: new THREE.Texture( <Image> ),
  12953. *
  12954. * uvOffset: new THREE.Vector2(),
  12955. * uvScale: new THREE.Vector2()
  12956. * }
  12957. */
  12958. THREE.SpriteMaterial = function ( parameters ) {
  12959. THREE.Material.call( this );
  12960. this.type = 'SpriteMaterial';
  12961. this.color = new THREE.Color( 0xffffff );
  12962. this.map = null;
  12963. this.rotation = 0;
  12964. this.fog = false;
  12965. this.lights = false;
  12966. this.setValues( parameters );
  12967. };
  12968. THREE.SpriteMaterial.prototype = Object.create( THREE.Material.prototype );
  12969. THREE.SpriteMaterial.prototype.constructor = THREE.SpriteMaterial;
  12970. THREE.SpriteMaterial.prototype.copy = function ( source ) {
  12971. THREE.Material.prototype.copy.call( this, source );
  12972. this.color.copy( source.color );
  12973. this.map = source.map;
  12974. this.rotation = source.rotation;
  12975. return this;
  12976. };
  12977. // File:src/materials/ShadowMaterial.js
  12978. /**
  12979. * @author mrdoob / http://mrdoob.com/
  12980. */
  12981. THREE.ShadowMaterial = function () {
  12982. THREE.ShaderMaterial.call( this, {
  12983. uniforms: THREE.UniformsUtils.merge( [
  12984. THREE.UniformsLib[ "lights" ],
  12985. {
  12986. opacity: { value: 1.0 }
  12987. }
  12988. ] ),
  12989. vertexShader: THREE.ShaderChunk[ 'shadow_vert' ],
  12990. fragmentShader: THREE.ShaderChunk[ 'shadow_frag' ]
  12991. } );
  12992. this.lights = true;
  12993. this.transparent = true;
  12994. Object.defineProperties( this, {
  12995. opacity: {
  12996. enumerable: true,
  12997. get: function () {
  12998. return this.uniforms.opacity.value;
  12999. },
  13000. set: function ( value ) {
  13001. this.uniforms.opacity.value = value;
  13002. }
  13003. }
  13004. } );
  13005. };
  13006. THREE.ShadowMaterial.prototype = Object.create( THREE.ShaderMaterial.prototype );
  13007. THREE.ShadowMaterial.prototype.constructor = THREE.ShadowMaterial;
  13008. // File:src/textures/Texture.js
  13009. /**
  13010. * @author mrdoob / http://mrdoob.com/
  13011. * @author alteredq / http://alteredqualia.com/
  13012. * @author szimek / https://github.com/szimek/
  13013. */
  13014. THREE.Texture = function ( image, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding ) {
  13015. Object.defineProperty( this, 'id', { value: THREE.TextureIdCount ++ } );
  13016. this.uuid = THREE.Math.generateUUID();
  13017. this.name = '';
  13018. this.sourceFile = '';
  13019. this.image = image !== undefined ? image : THREE.Texture.DEFAULT_IMAGE;
  13020. this.mipmaps = [];
  13021. this.mapping = mapping !== undefined ? mapping : THREE.Texture.DEFAULT_MAPPING;
  13022. this.wrapS = wrapS !== undefined ? wrapS : THREE.ClampToEdgeWrapping;
  13023. this.wrapT = wrapT !== undefined ? wrapT : THREE.ClampToEdgeWrapping;
  13024. this.magFilter = magFilter !== undefined ? magFilter : THREE.LinearFilter;
  13025. this.minFilter = minFilter !== undefined ? minFilter : THREE.LinearMipMapLinearFilter;
  13026. this.anisotropy = anisotropy !== undefined ? anisotropy : 1;
  13027. this.format = format !== undefined ? format : THREE.RGBAFormat;
  13028. this.type = type !== undefined ? type : THREE.UnsignedByteType;
  13029. this.offset = new THREE.Vector2( 0, 0 );
  13030. this.repeat = new THREE.Vector2( 1, 1 );
  13031. this.generateMipmaps = true;
  13032. this.premultiplyAlpha = false;
  13033. this.flipY = true;
  13034. this.unpackAlignment = 4; // valid values: 1, 2, 4, 8 (see http://www.khronos.org/opengles/sdk/docs/man/xhtml/glPixelStorei.xml)
  13035. // Values of encoding !== THREE.LinearEncoding only supported on map, envMap and emissiveMap.
  13036. //
  13037. // Also changing the encoding after already used by a Material will not automatically make the Material
  13038. // update. You need to explicitly call Material.needsUpdate to trigger it to recompile.
  13039. this.encoding = encoding !== undefined ? encoding : THREE.LinearEncoding;
  13040. this.version = 0;
  13041. this.onUpdate = null;
  13042. };
  13043. THREE.Texture.DEFAULT_IMAGE = undefined;
  13044. THREE.Texture.DEFAULT_MAPPING = THREE.UVMapping;
  13045. THREE.Texture.prototype = {
  13046. constructor: THREE.Texture,
  13047. set needsUpdate( value ) {
  13048. if ( value === true ) this.version ++;
  13049. },
  13050. clone: function () {
  13051. return new this.constructor().copy( this );
  13052. },
  13053. copy: function ( source ) {
  13054. this.image = source.image;
  13055. this.mipmaps = source.mipmaps.slice( 0 );
  13056. this.mapping = source.mapping;
  13057. this.wrapS = source.wrapS;
  13058. this.wrapT = source.wrapT;
  13059. this.magFilter = source.magFilter;
  13060. this.minFilter = source.minFilter;
  13061. this.anisotropy = source.anisotropy;
  13062. this.format = source.format;
  13063. this.type = source.type;
  13064. this.offset.copy( source.offset );
  13065. this.repeat.copy( source.repeat );
  13066. this.generateMipmaps = source.generateMipmaps;
  13067. this.premultiplyAlpha = source.premultiplyAlpha;
  13068. this.flipY = source.flipY;
  13069. this.unpackAlignment = source.unpackAlignment;
  13070. this.encoding = source.encoding;
  13071. return this;
  13072. },
  13073. toJSON: function ( meta ) {
  13074. if ( meta.textures[ this.uuid ] !== undefined ) {
  13075. return meta.textures[ this.uuid ];
  13076. }
  13077. function getDataURL( image ) {
  13078. var canvas;
  13079. if ( image.toDataURL !== undefined ) {
  13080. canvas = image;
  13081. } else {
  13082. canvas = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' );
  13083. canvas.width = image.width;
  13084. canvas.height = image.height;
  13085. canvas.getContext( '2d' ).drawImage( image, 0, 0, image.width, image.height );
  13086. }
  13087. if ( canvas.width > 2048 || canvas.height > 2048 ) {
  13088. return canvas.toDataURL( 'image/jpeg', 0.6 );
  13089. } else {
  13090. return canvas.toDataURL( 'image/png' );
  13091. }
  13092. }
  13093. var output = {
  13094. metadata: {
  13095. version: 4.4,
  13096. type: 'Texture',
  13097. generator: 'Texture.toJSON'
  13098. },
  13099. uuid: this.uuid,
  13100. name: this.name,
  13101. mapping: this.mapping,
  13102. repeat: [ this.repeat.x, this.repeat.y ],
  13103. offset: [ this.offset.x, this.offset.y ],
  13104. wrap: [ this.wrapS, this.wrapT ],
  13105. minFilter: this.minFilter,
  13106. magFilter: this.magFilter,
  13107. anisotropy: this.anisotropy
  13108. };
  13109. if ( this.image !== undefined ) {
  13110. // TODO: Move to THREE.Image
  13111. var image = this.image;
  13112. if ( image.uuid === undefined ) {
  13113. image.uuid = THREE.Math.generateUUID(); // UGH
  13114. }
  13115. if ( meta.images[ image.uuid ] === undefined ) {
  13116. meta.images[ image.uuid ] = {
  13117. uuid: image.uuid,
  13118. url: getDataURL( image )
  13119. };
  13120. }
  13121. output.image = image.uuid;
  13122. }
  13123. meta.textures[ this.uuid ] = output;
  13124. return output;
  13125. },
  13126. dispose: function () {
  13127. this.dispatchEvent( { type: 'dispose' } );
  13128. },
  13129. transformUv: function ( uv ) {
  13130. if ( this.mapping !== THREE.UVMapping ) return;
  13131. uv.multiply( this.repeat );
  13132. uv.add( this.offset );
  13133. if ( uv.x < 0 || uv.x > 1 ) {
  13134. switch ( this.wrapS ) {
  13135. case THREE.RepeatWrapping:
  13136. uv.x = uv.x - Math.floor( uv.x );
  13137. break;
  13138. case THREE.ClampToEdgeWrapping:
  13139. uv.x = uv.x < 0 ? 0 : 1;
  13140. break;
  13141. case THREE.MirroredRepeatWrapping:
  13142. if ( Math.abs( Math.floor( uv.x ) % 2 ) === 1 ) {
  13143. uv.x = Math.ceil( uv.x ) - uv.x;
  13144. } else {
  13145. uv.x = uv.x - Math.floor( uv.x );
  13146. }
  13147. break;
  13148. }
  13149. }
  13150. if ( uv.y < 0 || uv.y > 1 ) {
  13151. switch ( this.wrapT ) {
  13152. case THREE.RepeatWrapping:
  13153. uv.y = uv.y - Math.floor( uv.y );
  13154. break;
  13155. case THREE.ClampToEdgeWrapping:
  13156. uv.y = uv.y < 0 ? 0 : 1;
  13157. break;
  13158. case THREE.MirroredRepeatWrapping:
  13159. if ( Math.abs( Math.floor( uv.y ) % 2 ) === 1 ) {
  13160. uv.y = Math.ceil( uv.y ) - uv.y;
  13161. } else {
  13162. uv.y = uv.y - Math.floor( uv.y );
  13163. }
  13164. break;
  13165. }
  13166. }
  13167. if ( this.flipY ) {
  13168. uv.y = 1 - uv.y;
  13169. }
  13170. }
  13171. };
  13172. Object.assign( THREE.Texture.prototype, THREE.EventDispatcher.prototype );
  13173. THREE.TextureIdCount = 0;
  13174. // File:src/textures/DepthTexture.js
  13175. /**
  13176. * @author Matt DesLauriers / @mattdesl
  13177. */
  13178. THREE.DepthTexture = function ( width, height, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy ) {
  13179. THREE.Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, THREE.DepthFormat, type, anisotropy );
  13180. this.image = { width: width, height: height };
  13181. this.type = type !== undefined ? type : THREE.UnsignedShortType;
  13182. this.magFilter = magFilter !== undefined ? magFilter : THREE.NearestFilter;
  13183. this.minFilter = minFilter !== undefined ? minFilter : THREE.NearestFilter;
  13184. this.flipY = false;
  13185. this.generateMipmaps = false;
  13186. };
  13187. THREE.DepthTexture.prototype = Object.create( THREE.Texture.prototype );
  13188. THREE.DepthTexture.prototype.constructor = THREE.DepthTexture;
  13189. // File:src/textures/CanvasTexture.js
  13190. /**
  13191. * @author mrdoob / http://mrdoob.com/
  13192. */
  13193. THREE.CanvasTexture = function ( canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  13194. THREE.Texture.call( this, canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  13195. this.needsUpdate = true;
  13196. };
  13197. THREE.CanvasTexture.prototype = Object.create( THREE.Texture.prototype );
  13198. THREE.CanvasTexture.prototype.constructor = THREE.CanvasTexture;
  13199. // File:src/textures/CubeTexture.js
  13200. /**
  13201. * @author mrdoob / http://mrdoob.com/
  13202. */
  13203. THREE.CubeTexture = function ( images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding ) {
  13204. images = images !== undefined ? images : [];
  13205. mapping = mapping !== undefined ? mapping : THREE.CubeReflectionMapping;
  13206. THREE.Texture.call( this, images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding );
  13207. this.flipY = false;
  13208. };
  13209. THREE.CubeTexture.prototype = Object.create( THREE.Texture.prototype );
  13210. THREE.CubeTexture.prototype.constructor = THREE.CubeTexture;
  13211. Object.defineProperty( THREE.CubeTexture.prototype, 'images', {
  13212. get: function () {
  13213. return this.image;
  13214. },
  13215. set: function ( value ) {
  13216. this.image = value;
  13217. }
  13218. } );
  13219. // File:src/textures/CompressedTexture.js
  13220. /**
  13221. * @author alteredq / http://alteredqualia.com/
  13222. */
  13223. THREE.CompressedTexture = function ( mipmaps, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, encoding ) {
  13224. THREE.Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding );
  13225. this.image = { width: width, height: height };
  13226. this.mipmaps = mipmaps;
  13227. // no flipping for cube textures
  13228. // (also flipping doesn't work for compressed textures )
  13229. this.flipY = false;
  13230. // can't generate mipmaps for compressed textures
  13231. // mips must be embedded in DDS files
  13232. this.generateMipmaps = false;
  13233. };
  13234. THREE.CompressedTexture.prototype = Object.create( THREE.Texture.prototype );
  13235. THREE.CompressedTexture.prototype.constructor = THREE.CompressedTexture;
  13236. // File:src/textures/DataTexture.js
  13237. /**
  13238. * @author alteredq / http://alteredqualia.com/
  13239. */
  13240. THREE.DataTexture = function ( data, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, encoding ) {
  13241. THREE.Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding );
  13242. this.image = { data: data, width: width, height: height };
  13243. this.magFilter = magFilter !== undefined ? magFilter : THREE.NearestFilter;
  13244. this.minFilter = minFilter !== undefined ? minFilter : THREE.NearestFilter;
  13245. this.flipY = false;
  13246. this.generateMipmaps = false;
  13247. };
  13248. THREE.DataTexture.prototype = Object.create( THREE.Texture.prototype );
  13249. THREE.DataTexture.prototype.constructor = THREE.DataTexture;
  13250. // File:src/textures/VideoTexture.js
  13251. /**
  13252. * @author mrdoob / http://mrdoob.com/
  13253. */
  13254. THREE.VideoTexture = function ( video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  13255. THREE.Texture.call( this, video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  13256. this.generateMipmaps = false;
  13257. var scope = this;
  13258. function update() {
  13259. requestAnimationFrame( update );
  13260. if ( video.readyState >= video.HAVE_CURRENT_DATA ) {
  13261. scope.needsUpdate = true;
  13262. }
  13263. }
  13264. update();
  13265. };
  13266. THREE.VideoTexture.prototype = Object.create( THREE.Texture.prototype );
  13267. THREE.VideoTexture.prototype.constructor = THREE.VideoTexture;
  13268. // File:src/objects/Group.js
  13269. /**
  13270. * @author mrdoob / http://mrdoob.com/
  13271. */
  13272. THREE.Group = function () {
  13273. THREE.Object3D.call( this );
  13274. this.type = 'Group';
  13275. };
  13276. THREE.Group.prototype = Object.assign( Object.create( THREE.Object3D.prototype ), {
  13277. constructor: THREE.Group
  13278. } );
  13279. // File:src/objects/Points.js
  13280. /**
  13281. * @author alteredq / http://alteredqualia.com/
  13282. */
  13283. THREE.Points = function ( geometry, material ) {
  13284. THREE.Object3D.call( this );
  13285. this.type = 'Points';
  13286. this.geometry = geometry !== undefined ? geometry : new THREE.BufferGeometry();
  13287. this.material = material !== undefined ? material : new THREE.PointsMaterial( { color: Math.random() * 0xffffff } );
  13288. };
  13289. THREE.Points.prototype = Object.assign( Object.create( THREE.Object3D.prototype ), {
  13290. constructor: THREE.Points,
  13291. raycast: ( function () {
  13292. var inverseMatrix = new THREE.Matrix4();
  13293. var ray = new THREE.Ray();
  13294. var sphere = new THREE.Sphere();
  13295. return function raycast( raycaster, intersects ) {
  13296. var object = this;
  13297. var geometry = this.geometry;
  13298. var matrixWorld = this.matrixWorld;
  13299. var threshold = raycaster.params.Points.threshold;
  13300. // Checking boundingSphere distance to ray
  13301. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  13302. sphere.copy( geometry.boundingSphere );
  13303. sphere.applyMatrix4( matrixWorld );
  13304. if ( raycaster.ray.intersectsSphere( sphere ) === false ) return;
  13305. //
  13306. inverseMatrix.getInverse( matrixWorld );
  13307. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  13308. var localThreshold = threshold / ( ( this.scale.x + this.scale.y + this.scale.z ) / 3 );
  13309. var localThresholdSq = localThreshold * localThreshold;
  13310. var position = new THREE.Vector3();
  13311. function testPoint( point, index ) {
  13312. var rayPointDistanceSq = ray.distanceSqToPoint( point );
  13313. if ( rayPointDistanceSq < localThresholdSq ) {
  13314. var intersectPoint = ray.closestPointToPoint( point );
  13315. intersectPoint.applyMatrix4( matrixWorld );
  13316. var distance = raycaster.ray.origin.distanceTo( intersectPoint );
  13317. if ( distance < raycaster.near || distance > raycaster.far ) return;
  13318. intersects.push( {
  13319. distance: distance,
  13320. distanceToRay: Math.sqrt( rayPointDistanceSq ),
  13321. point: intersectPoint.clone(),
  13322. index: index,
  13323. face: null,
  13324. object: object
  13325. } );
  13326. }
  13327. }
  13328. if ( geometry instanceof THREE.BufferGeometry ) {
  13329. var index = geometry.index;
  13330. var attributes = geometry.attributes;
  13331. var positions = attributes.position.array;
  13332. if ( index !== null ) {
  13333. var indices = index.array;
  13334. for ( var i = 0, il = indices.length; i < il; i ++ ) {
  13335. var a = indices[ i ];
  13336. position.fromArray( positions, a * 3 );
  13337. testPoint( position, a );
  13338. }
  13339. } else {
  13340. for ( var i = 0, l = positions.length / 3; i < l; i ++ ) {
  13341. position.fromArray( positions, i * 3 );
  13342. testPoint( position, i );
  13343. }
  13344. }
  13345. } else {
  13346. var vertices = geometry.vertices;
  13347. for ( var i = 0, l = vertices.length; i < l; i ++ ) {
  13348. testPoint( vertices[ i ], i );
  13349. }
  13350. }
  13351. };
  13352. }() ),
  13353. clone: function () {
  13354. return new this.constructor( this.geometry, this.material ).copy( this );
  13355. }
  13356. } );
  13357. // File:src/objects/Line.js
  13358. /**
  13359. * @author mrdoob / http://mrdoob.com/
  13360. */
  13361. THREE.Line = function ( geometry, material, mode ) {
  13362. if ( mode === 1 ) {
  13363. console.warn( 'THREE.Line: parameter THREE.LinePieces no longer supported. Created THREE.LineSegments instead.' );
  13364. return new THREE.LineSegments( geometry, material );
  13365. }
  13366. THREE.Object3D.call( this );
  13367. this.type = 'Line';
  13368. this.geometry = geometry !== undefined ? geometry : new THREE.BufferGeometry();
  13369. this.material = material !== undefined ? material : new THREE.LineBasicMaterial( { color: Math.random() * 0xffffff } );
  13370. };
  13371. THREE.Line.prototype = Object.assign( Object.create( THREE.Object3D.prototype ), {
  13372. constructor: THREE.Line,
  13373. raycast: ( function () {
  13374. var inverseMatrix = new THREE.Matrix4();
  13375. var ray = new THREE.Ray();
  13376. var sphere = new THREE.Sphere();
  13377. return function raycast( raycaster, intersects ) {
  13378. var precision = raycaster.linePrecision;
  13379. var precisionSq = precision * precision;
  13380. var geometry = this.geometry;
  13381. var matrixWorld = this.matrixWorld;
  13382. // Checking boundingSphere distance to ray
  13383. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  13384. sphere.copy( geometry.boundingSphere );
  13385. sphere.applyMatrix4( matrixWorld );
  13386. if ( raycaster.ray.intersectsSphere( sphere ) === false ) return;
  13387. //
  13388. inverseMatrix.getInverse( matrixWorld );
  13389. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  13390. var vStart = new THREE.Vector3();
  13391. var vEnd = new THREE.Vector3();
  13392. var interSegment = new THREE.Vector3();
  13393. var interRay = new THREE.Vector3();
  13394. var step = this instanceof THREE.LineSegments ? 2 : 1;
  13395. if ( geometry instanceof THREE.BufferGeometry ) {
  13396. var index = geometry.index;
  13397. var attributes = geometry.attributes;
  13398. var positions = attributes.position.array;
  13399. if ( index !== null ) {
  13400. var indices = index.array;
  13401. for ( var i = 0, l = indices.length - 1; i < l; i += step ) {
  13402. var a = indices[ i ];
  13403. var b = indices[ i + 1 ];
  13404. vStart.fromArray( positions, a * 3 );
  13405. vEnd.fromArray( positions, b * 3 );
  13406. var distSq = ray.distanceSqToSegment( vStart, vEnd, interRay, interSegment );
  13407. if ( distSq > precisionSq ) continue;
  13408. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  13409. var distance = raycaster.ray.origin.distanceTo( interRay );
  13410. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  13411. intersects.push( {
  13412. distance: distance,
  13413. // What do we want? intersection point on the ray or on the segment??
  13414. // point: raycaster.ray.at( distance ),
  13415. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  13416. index: i,
  13417. face: null,
  13418. faceIndex: null,
  13419. object: this
  13420. } );
  13421. }
  13422. } else {
  13423. for ( var i = 0, l = positions.length / 3 - 1; i < l; i += step ) {
  13424. vStart.fromArray( positions, 3 * i );
  13425. vEnd.fromArray( positions, 3 * i + 3 );
  13426. var distSq = ray.distanceSqToSegment( vStart, vEnd, interRay, interSegment );
  13427. if ( distSq > precisionSq ) continue;
  13428. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  13429. var distance = raycaster.ray.origin.distanceTo( interRay );
  13430. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  13431. intersects.push( {
  13432. distance: distance,
  13433. // What do we want? intersection point on the ray or on the segment??
  13434. // point: raycaster.ray.at( distance ),
  13435. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  13436. index: i,
  13437. face: null,
  13438. faceIndex: null,
  13439. object: this
  13440. } );
  13441. }
  13442. }
  13443. } else if ( geometry instanceof THREE.Geometry ) {
  13444. var vertices = geometry.vertices;
  13445. var nbVertices = vertices.length;
  13446. for ( var i = 0; i < nbVertices - 1; i += step ) {
  13447. var distSq = ray.distanceSqToSegment( vertices[ i ], vertices[ i + 1 ], interRay, interSegment );
  13448. if ( distSq > precisionSq ) continue;
  13449. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  13450. var distance = raycaster.ray.origin.distanceTo( interRay );
  13451. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  13452. intersects.push( {
  13453. distance: distance,
  13454. // What do we want? intersection point on the ray or on the segment??
  13455. // point: raycaster.ray.at( distance ),
  13456. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  13457. index: i,
  13458. face: null,
  13459. faceIndex: null,
  13460. object: this
  13461. } );
  13462. }
  13463. }
  13464. };
  13465. }() ),
  13466. clone: function () {
  13467. return new this.constructor( this.geometry, this.material ).copy( this );
  13468. }
  13469. } );
  13470. // File:src/objects/LineSegments.js
  13471. /**
  13472. * @author mrdoob / http://mrdoob.com/
  13473. */
  13474. THREE.LineSegments = function ( geometry, material ) {
  13475. THREE.Line.call( this, geometry, material );
  13476. this.type = 'LineSegments';
  13477. };
  13478. THREE.LineSegments.prototype = Object.assign( Object.create( THREE.Line.prototype ), {
  13479. constructor: THREE.LineSegments
  13480. } );
  13481. // File:src/objects/Mesh.js
  13482. /**
  13483. * @author mrdoob / http://mrdoob.com/
  13484. * @author alteredq / http://alteredqualia.com/
  13485. * @author mikael emtinger / http://gomo.se/
  13486. * @author jonobr1 / http://jonobr1.com/
  13487. */
  13488. THREE.Mesh = function ( geometry, material ) {
  13489. THREE.Object3D.call( this );
  13490. this.type = 'Mesh';
  13491. this.geometry = geometry !== undefined ? geometry : new THREE.BufferGeometry();
  13492. this.material = material !== undefined ? material : new THREE.MeshBasicMaterial( { color: Math.random() * 0xffffff } );
  13493. this.drawMode = THREE.TrianglesDrawMode;
  13494. this.updateMorphTargets();
  13495. };
  13496. THREE.Mesh.prototype = Object.assign( Object.create( THREE.Object3D.prototype ), {
  13497. constructor: THREE.Mesh,
  13498. setDrawMode: function ( value ) {
  13499. this.drawMode = value;
  13500. },
  13501. copy: function ( source ) {
  13502. THREE.Object3D.prototype.copy.call( this, source );
  13503. this.drawMode = source.drawMode;
  13504. return this;
  13505. },
  13506. updateMorphTargets: function () {
  13507. if ( this.geometry.morphTargets !== undefined && this.geometry.morphTargets.length > 0 ) {
  13508. this.morphTargetBase = - 1;
  13509. this.morphTargetInfluences = [];
  13510. this.morphTargetDictionary = {};
  13511. for ( var m = 0, ml = this.geometry.morphTargets.length; m < ml; m ++ ) {
  13512. this.morphTargetInfluences.push( 0 );
  13513. this.morphTargetDictionary[ this.geometry.morphTargets[ m ].name ] = m;
  13514. }
  13515. }
  13516. },
  13517. getMorphTargetIndexByName: function ( name ) {
  13518. if ( this.morphTargetDictionary[ name ] !== undefined ) {
  13519. return this.morphTargetDictionary[ name ];
  13520. }
  13521. console.warn( 'THREE.Mesh.getMorphTargetIndexByName: morph target ' + name + ' does not exist. Returning 0.' );
  13522. return 0;
  13523. },
  13524. raycast: ( function () {
  13525. var inverseMatrix = new THREE.Matrix4();
  13526. var ray = new THREE.Ray();
  13527. var sphere = new THREE.Sphere();
  13528. var vA = new THREE.Vector3();
  13529. var vB = new THREE.Vector3();
  13530. var vC = new THREE.Vector3();
  13531. var tempA = new THREE.Vector3();
  13532. var tempB = new THREE.Vector3();
  13533. var tempC = new THREE.Vector3();
  13534. var uvA = new THREE.Vector2();
  13535. var uvB = new THREE.Vector2();
  13536. var uvC = new THREE.Vector2();
  13537. var barycoord = new THREE.Vector3();
  13538. var intersectionPoint = new THREE.Vector3();
  13539. var intersectionPointWorld = new THREE.Vector3();
  13540. function uvIntersection( point, p1, p2, p3, uv1, uv2, uv3 ) {
  13541. THREE.Triangle.barycoordFromPoint( point, p1, p2, p3, barycoord );
  13542. uv1.multiplyScalar( barycoord.x );
  13543. uv2.multiplyScalar( barycoord.y );
  13544. uv3.multiplyScalar( barycoord.z );
  13545. uv1.add( uv2 ).add( uv3 );
  13546. return uv1.clone();
  13547. }
  13548. function checkIntersection( object, raycaster, ray, pA, pB, pC, point ) {
  13549. var intersect;
  13550. var material = object.material;
  13551. if ( material.side === THREE.BackSide ) {
  13552. intersect = ray.intersectTriangle( pC, pB, pA, true, point );
  13553. } else {
  13554. intersect = ray.intersectTriangle( pA, pB, pC, material.side !== THREE.DoubleSide, point );
  13555. }
  13556. if ( intersect === null ) return null;
  13557. intersectionPointWorld.copy( point );
  13558. intersectionPointWorld.applyMatrix4( object.matrixWorld );
  13559. var distance = raycaster.ray.origin.distanceTo( intersectionPointWorld );
  13560. if ( distance < raycaster.near || distance > raycaster.far ) return null;
  13561. return {
  13562. distance: distance,
  13563. point: intersectionPointWorld.clone(),
  13564. object: object
  13565. };
  13566. }
  13567. function checkBufferGeometryIntersection( object, raycaster, ray, positions, uvs, a, b, c ) {
  13568. vA.fromArray( positions, a * 3 );
  13569. vB.fromArray( positions, b * 3 );
  13570. vC.fromArray( positions, c * 3 );
  13571. var intersection = checkIntersection( object, raycaster, ray, vA, vB, vC, intersectionPoint );
  13572. if ( intersection ) {
  13573. if ( uvs ) {
  13574. uvA.fromArray( uvs, a * 2 );
  13575. uvB.fromArray( uvs, b * 2 );
  13576. uvC.fromArray( uvs, c * 2 );
  13577. intersection.uv = uvIntersection( intersectionPoint, vA, vB, vC, uvA, uvB, uvC );
  13578. }
  13579. intersection.face = new THREE.Face3( a, b, c, THREE.Triangle.normal( vA, vB, vC ) );
  13580. intersection.faceIndex = a;
  13581. }
  13582. return intersection;
  13583. }
  13584. return function raycast( raycaster, intersects ) {
  13585. var geometry = this.geometry;
  13586. var material = this.material;
  13587. var matrixWorld = this.matrixWorld;
  13588. if ( material === undefined ) return;
  13589. // Checking boundingSphere distance to ray
  13590. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  13591. sphere.copy( geometry.boundingSphere );
  13592. sphere.applyMatrix4( matrixWorld );
  13593. if ( raycaster.ray.intersectsSphere( sphere ) === false ) return;
  13594. //
  13595. inverseMatrix.getInverse( matrixWorld );
  13596. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  13597. // Check boundingBox before continuing
  13598. if ( geometry.boundingBox !== null ) {
  13599. if ( ray.intersectsBox( geometry.boundingBox ) === false ) return;
  13600. }
  13601. var uvs, intersection;
  13602. if ( geometry instanceof THREE.BufferGeometry ) {
  13603. var a, b, c;
  13604. var index = geometry.index;
  13605. var attributes = geometry.attributes;
  13606. var positions = attributes.position.array;
  13607. if ( attributes.uv !== undefined ) {
  13608. uvs = attributes.uv.array;
  13609. }
  13610. if ( index !== null ) {
  13611. var indices = index.array;
  13612. for ( var i = 0, l = indices.length; i < l; i += 3 ) {
  13613. a = indices[ i ];
  13614. b = indices[ i + 1 ];
  13615. c = indices[ i + 2 ];
  13616. intersection = checkBufferGeometryIntersection( this, raycaster, ray, positions, uvs, a, b, c );
  13617. if ( intersection ) {
  13618. intersection.faceIndex = Math.floor( i / 3 ); // triangle number in indices buffer semantics
  13619. intersects.push( intersection );
  13620. }
  13621. }
  13622. } else {
  13623. for ( var i = 0, l = positions.length; i < l; i += 9 ) {
  13624. a = i / 3;
  13625. b = a + 1;
  13626. c = a + 2;
  13627. intersection = checkBufferGeometryIntersection( this, raycaster, ray, positions, uvs, a, b, c );
  13628. if ( intersection ) {
  13629. intersection.index = a; // triangle number in positions buffer semantics
  13630. intersects.push( intersection );
  13631. }
  13632. }
  13633. }
  13634. } else if ( geometry instanceof THREE.Geometry ) {
  13635. var fvA, fvB, fvC;
  13636. var isFaceMaterial = material instanceof THREE.MultiMaterial;
  13637. var materials = isFaceMaterial === true ? material.materials : null;
  13638. var vertices = geometry.vertices;
  13639. var faces = geometry.faces;
  13640. var faceVertexUvs = geometry.faceVertexUvs[ 0 ];
  13641. if ( faceVertexUvs.length > 0 ) uvs = faceVertexUvs;
  13642. for ( var f = 0, fl = faces.length; f < fl; f ++ ) {
  13643. var face = faces[ f ];
  13644. var faceMaterial = isFaceMaterial === true ? materials[ face.materialIndex ] : material;
  13645. if ( faceMaterial === undefined ) continue;
  13646. fvA = vertices[ face.a ];
  13647. fvB = vertices[ face.b ];
  13648. fvC = vertices[ face.c ];
  13649. if ( faceMaterial.morphTargets === true ) {
  13650. var morphTargets = geometry.morphTargets;
  13651. var morphInfluences = this.morphTargetInfluences;
  13652. vA.set( 0, 0, 0 );
  13653. vB.set( 0, 0, 0 );
  13654. vC.set( 0, 0, 0 );
  13655. for ( var t = 0, tl = morphTargets.length; t < tl; t ++ ) {
  13656. var influence = morphInfluences[ t ];
  13657. if ( influence === 0 ) continue;
  13658. var targets = morphTargets[ t ].vertices;
  13659. vA.addScaledVector( tempA.subVectors( targets[ face.a ], fvA ), influence );
  13660. vB.addScaledVector( tempB.subVectors( targets[ face.b ], fvB ), influence );
  13661. vC.addScaledVector( tempC.subVectors( targets[ face.c ], fvC ), influence );
  13662. }
  13663. vA.add( fvA );
  13664. vB.add( fvB );
  13665. vC.add( fvC );
  13666. fvA = vA;
  13667. fvB = vB;
  13668. fvC = vC;
  13669. }
  13670. intersection = checkIntersection( this, raycaster, ray, fvA, fvB, fvC, intersectionPoint );
  13671. if ( intersection ) {
  13672. if ( uvs ) {
  13673. var uvs_f = uvs[ f ];
  13674. uvA.copy( uvs_f[ 0 ] );
  13675. uvB.copy( uvs_f[ 1 ] );
  13676. uvC.copy( uvs_f[ 2 ] );
  13677. intersection.uv = uvIntersection( intersectionPoint, fvA, fvB, fvC, uvA, uvB, uvC );
  13678. }
  13679. intersection.face = face;
  13680. intersection.faceIndex = f;
  13681. intersects.push( intersection );
  13682. }
  13683. }
  13684. }
  13685. };
  13686. }() ),
  13687. clone: function () {
  13688. return new this.constructor( this.geometry, this.material ).copy( this );
  13689. }
  13690. } );
  13691. // File:src/objects/Bone.js
  13692. /**
  13693. * @author mikael emtinger / http://gomo.se/
  13694. * @author alteredq / http://alteredqualia.com/
  13695. * @author ikerr / http://verold.com
  13696. */
  13697. THREE.Bone = function ( skin ) {
  13698. THREE.Object3D.call( this );
  13699. this.type = 'Bone';
  13700. this.skin = skin;
  13701. };
  13702. THREE.Bone.prototype = Object.assign( Object.create( THREE.Object3D.prototype ), {
  13703. constructor: THREE.Bone,
  13704. copy: function ( source ) {
  13705. THREE.Object3D.prototype.copy.call( this, source );
  13706. this.skin = source.skin;
  13707. return this;
  13708. }
  13709. } );
  13710. // File:src/objects/Skeleton.js
  13711. /**
  13712. * @author mikael emtinger / http://gomo.se/
  13713. * @author alteredq / http://alteredqualia.com/
  13714. * @author michael guerrero / http://realitymeltdown.com
  13715. * @author ikerr / http://verold.com
  13716. */
  13717. THREE.Skeleton = function ( bones, boneInverses, useVertexTexture ) {
  13718. this.useVertexTexture = useVertexTexture !== undefined ? useVertexTexture : true;
  13719. this.identityMatrix = new THREE.Matrix4();
  13720. // copy the bone array
  13721. bones = bones || [];
  13722. this.bones = bones.slice( 0 );
  13723. // create a bone texture or an array of floats
  13724. if ( this.useVertexTexture ) {
  13725. // layout (1 matrix = 4 pixels)
  13726. // RGBA RGBA RGBA RGBA (=> column1, column2, column3, column4)
  13727. // with 8x8 pixel texture max 16 bones * 4 pixels = (8 * 8)
  13728. // 16x16 pixel texture max 64 bones * 4 pixels = (16 * 16)
  13729. // 32x32 pixel texture max 256 bones * 4 pixels = (32 * 32)
  13730. // 64x64 pixel texture max 1024 bones * 4 pixels = (64 * 64)
  13731. var size = Math.sqrt( this.bones.length * 4 ); // 4 pixels needed for 1 matrix
  13732. size = THREE.Math.nextPowerOfTwo( Math.ceil( size ) );
  13733. size = Math.max( size, 4 );
  13734. this.boneTextureWidth = size;
  13735. this.boneTextureHeight = size;
  13736. this.boneMatrices = new Float32Array( this.boneTextureWidth * this.boneTextureHeight * 4 ); // 4 floats per RGBA pixel
  13737. this.boneTexture = new THREE.DataTexture( this.boneMatrices, this.boneTextureWidth, this.boneTextureHeight, THREE.RGBAFormat, THREE.FloatType );
  13738. } else {
  13739. this.boneMatrices = new Float32Array( 16 * this.bones.length );
  13740. }
  13741. // use the supplied bone inverses or calculate the inverses
  13742. if ( boneInverses === undefined ) {
  13743. this.calculateInverses();
  13744. } else {
  13745. if ( this.bones.length === boneInverses.length ) {
  13746. this.boneInverses = boneInverses.slice( 0 );
  13747. } else {
  13748. console.warn( 'THREE.Skeleton bonInverses is the wrong length.' );
  13749. this.boneInverses = [];
  13750. for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
  13751. this.boneInverses.push( new THREE.Matrix4() );
  13752. }
  13753. }
  13754. }
  13755. };
  13756. Object.assign( THREE.Skeleton.prototype, {
  13757. calculateInverses: function () {
  13758. this.boneInverses = [];
  13759. for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
  13760. var inverse = new THREE.Matrix4();
  13761. if ( this.bones[ b ] ) {
  13762. inverse.getInverse( this.bones[ b ].matrixWorld );
  13763. }
  13764. this.boneInverses.push( inverse );
  13765. }
  13766. },
  13767. pose: function () {
  13768. var bone;
  13769. // recover the bind-time world matrices
  13770. for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
  13771. bone = this.bones[ b ];
  13772. if ( bone ) {
  13773. bone.matrixWorld.getInverse( this.boneInverses[ b ] );
  13774. }
  13775. }
  13776. // compute the local matrices, positions, rotations and scales
  13777. for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
  13778. bone = this.bones[ b ];
  13779. if ( bone ) {
  13780. if ( bone.parent instanceof THREE.Bone ) {
  13781. bone.matrix.getInverse( bone.parent.matrixWorld );
  13782. bone.matrix.multiply( bone.matrixWorld );
  13783. } else {
  13784. bone.matrix.copy( bone.matrixWorld );
  13785. }
  13786. bone.matrix.decompose( bone.position, bone.quaternion, bone.scale );
  13787. }
  13788. }
  13789. },
  13790. update: ( function () {
  13791. var offsetMatrix = new THREE.Matrix4();
  13792. return function update() {
  13793. // flatten bone matrices to array
  13794. for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
  13795. // compute the offset between the current and the original transform
  13796. var matrix = this.bones[ b ] ? this.bones[ b ].matrixWorld : this.identityMatrix;
  13797. offsetMatrix.multiplyMatrices( matrix, this.boneInverses[ b ] );
  13798. offsetMatrix.toArray( this.boneMatrices, b * 16 );
  13799. }
  13800. if ( this.useVertexTexture ) {
  13801. this.boneTexture.needsUpdate = true;
  13802. }
  13803. };
  13804. } )(),
  13805. clone: function () {
  13806. return new THREE.Skeleton( this.bones, this.boneInverses, this.useVertexTexture );
  13807. }
  13808. } );
  13809. // File:src/objects/SkinnedMesh.js
  13810. /**
  13811. * @author mikael emtinger / http://gomo.se/
  13812. * @author alteredq / http://alteredqualia.com/
  13813. * @author ikerr / http://verold.com
  13814. */
  13815. THREE.SkinnedMesh = function ( geometry, material, useVertexTexture ) {
  13816. THREE.Mesh.call( this, geometry, material );
  13817. this.type = 'SkinnedMesh';
  13818. this.bindMode = "attached";
  13819. this.bindMatrix = new THREE.Matrix4();
  13820. this.bindMatrixInverse = new THREE.Matrix4();
  13821. // init bones
  13822. // TODO: remove bone creation as there is no reason (other than
  13823. // convenience) for THREE.SkinnedMesh to do this.
  13824. var bones = [];
  13825. if ( this.geometry && this.geometry.bones !== undefined ) {
  13826. var bone, gbone;
  13827. for ( var b = 0, bl = this.geometry.bones.length; b < bl; ++ b ) {
  13828. gbone = this.geometry.bones[ b ];
  13829. bone = new THREE.Bone( this );
  13830. bones.push( bone );
  13831. bone.name = gbone.name;
  13832. bone.position.fromArray( gbone.pos );
  13833. bone.quaternion.fromArray( gbone.rotq );
  13834. if ( gbone.scl !== undefined ) bone.scale.fromArray( gbone.scl );
  13835. }
  13836. for ( var b = 0, bl = this.geometry.bones.length; b < bl; ++ b ) {
  13837. gbone = this.geometry.bones[ b ];
  13838. if ( gbone.parent !== - 1 && gbone.parent !== null &&
  13839. bones[ gbone.parent ] !== undefined ) {
  13840. bones[ gbone.parent ].add( bones[ b ] );
  13841. } else {
  13842. this.add( bones[ b ] );
  13843. }
  13844. }
  13845. }
  13846. this.normalizeSkinWeights();
  13847. this.updateMatrixWorld( true );
  13848. this.bind( new THREE.Skeleton( bones, undefined, useVertexTexture ), this.matrixWorld );
  13849. };
  13850. THREE.SkinnedMesh.prototype = Object.assign( Object.create( THREE.Mesh.prototype ), {
  13851. constructor: THREE.SkinnedMesh,
  13852. bind: function( skeleton, bindMatrix ) {
  13853. this.skeleton = skeleton;
  13854. if ( bindMatrix === undefined ) {
  13855. this.updateMatrixWorld( true );
  13856. this.skeleton.calculateInverses();
  13857. bindMatrix = this.matrixWorld;
  13858. }
  13859. this.bindMatrix.copy( bindMatrix );
  13860. this.bindMatrixInverse.getInverse( bindMatrix );
  13861. },
  13862. pose: function () {
  13863. this.skeleton.pose();
  13864. },
  13865. normalizeSkinWeights: function () {
  13866. if ( this.geometry instanceof THREE.Geometry ) {
  13867. for ( var i = 0; i < this.geometry.skinWeights.length; i ++ ) {
  13868. var sw = this.geometry.skinWeights[ i ];
  13869. var scale = 1.0 / sw.lengthManhattan();
  13870. if ( scale !== Infinity ) {
  13871. sw.multiplyScalar( scale );
  13872. } else {
  13873. sw.set( 1, 0, 0, 0 ); // do something reasonable
  13874. }
  13875. }
  13876. } else if ( this.geometry instanceof THREE.BufferGeometry ) {
  13877. var vec = new THREE.Vector4();
  13878. var skinWeight = this.geometry.attributes.skinWeight;
  13879. for ( var i = 0; i < skinWeight.count; i ++ ) {
  13880. vec.x = skinWeight.getX( i );
  13881. vec.y = skinWeight.getY( i );
  13882. vec.z = skinWeight.getZ( i );
  13883. vec.w = skinWeight.getW( i );
  13884. var scale = 1.0 / vec.lengthManhattan();
  13885. if ( scale !== Infinity ) {
  13886. vec.multiplyScalar( scale );
  13887. } else {
  13888. vec.set( 1, 0, 0, 0 ); // do something reasonable
  13889. }
  13890. skinWeight.setXYZW( i, vec.x, vec.y, vec.z, vec.w );
  13891. }
  13892. }
  13893. },
  13894. updateMatrixWorld: function( force ) {
  13895. THREE.Mesh.prototype.updateMatrixWorld.call( this, true );
  13896. if ( this.bindMode === "attached" ) {
  13897. this.bindMatrixInverse.getInverse( this.matrixWorld );
  13898. } else if ( this.bindMode === "detached" ) {
  13899. this.bindMatrixInverse.getInverse( this.bindMatrix );
  13900. } else {
  13901. console.warn( 'THREE.SkinnedMesh unrecognized bindMode: ' + this.bindMode );
  13902. }
  13903. },
  13904. clone: function() {
  13905. return new this.constructor( this.geometry, this.material, this.skeleton.useVertexTexture ).copy( this );
  13906. }
  13907. } );
  13908. // File:src/objects/LOD.js
  13909. /**
  13910. * @author mikael emtinger / http://gomo.se/
  13911. * @author alteredq / http://alteredqualia.com/
  13912. * @author mrdoob / http://mrdoob.com/
  13913. */
  13914. THREE.LOD = function () {
  13915. THREE.Object3D.call( this );
  13916. this.type = 'LOD';
  13917. Object.defineProperties( this, {
  13918. levels: {
  13919. enumerable: true,
  13920. value: []
  13921. }
  13922. } );
  13923. };
  13924. THREE.LOD.prototype = Object.assign( Object.create( THREE.Object3D.prototype ), {
  13925. constructor: THREE.LOD,
  13926. copy: function ( source ) {
  13927. THREE.Object3D.prototype.copy.call( this, source, false );
  13928. var levels = source.levels;
  13929. for ( var i = 0, l = levels.length; i < l; i ++ ) {
  13930. var level = levels[ i ];
  13931. this.addLevel( level.object.clone(), level.distance );
  13932. }
  13933. return this;
  13934. },
  13935. addLevel: function ( object, distance ) {
  13936. if ( distance === undefined ) distance = 0;
  13937. distance = Math.abs( distance );
  13938. var levels = this.levels;
  13939. for ( var l = 0; l < levels.length; l ++ ) {
  13940. if ( distance < levels[ l ].distance ) {
  13941. break;
  13942. }
  13943. }
  13944. levels.splice( l, 0, { distance: distance, object: object } );
  13945. this.add( object );
  13946. },
  13947. getObjectForDistance: function ( distance ) {
  13948. var levels = this.levels;
  13949. for ( var i = 1, l = levels.length; i < l; i ++ ) {
  13950. if ( distance < levels[ i ].distance ) {
  13951. break;
  13952. }
  13953. }
  13954. return levels[ i - 1 ].object;
  13955. },
  13956. raycast: ( function () {
  13957. var matrixPosition = new THREE.Vector3();
  13958. return function raycast( raycaster, intersects ) {
  13959. matrixPosition.setFromMatrixPosition( this.matrixWorld );
  13960. var distance = raycaster.ray.origin.distanceTo( matrixPosition );
  13961. this.getObjectForDistance( distance ).raycast( raycaster, intersects );
  13962. };
  13963. }() ),
  13964. update: function () {
  13965. var v1 = new THREE.Vector3();
  13966. var v2 = new THREE.Vector3();
  13967. return function update( camera ) {
  13968. var levels = this.levels;
  13969. if ( levels.length > 1 ) {
  13970. v1.setFromMatrixPosition( camera.matrixWorld );
  13971. v2.setFromMatrixPosition( this.matrixWorld );
  13972. var distance = v1.distanceTo( v2 );
  13973. levels[ 0 ].object.visible = true;
  13974. for ( var i = 1, l = levels.length; i < l; i ++ ) {
  13975. if ( distance >= levels[ i ].distance ) {
  13976. levels[ i - 1 ].object.visible = false;
  13977. levels[ i ].object.visible = true;
  13978. } else {
  13979. break;
  13980. }
  13981. }
  13982. for ( ; i < l; i ++ ) {
  13983. levels[ i ].object.visible = false;
  13984. }
  13985. }
  13986. };
  13987. }(),
  13988. toJSON: function ( meta ) {
  13989. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  13990. data.object.levels = [];
  13991. var levels = this.levels;
  13992. for ( var i = 0, l = levels.length; i < l; i ++ ) {
  13993. var level = levels[ i ];
  13994. data.object.levels.push( {
  13995. object: level.object.uuid,
  13996. distance: level.distance
  13997. } );
  13998. }
  13999. return data;
  14000. }
  14001. } );
  14002. // File:src/objects/Sprite.js
  14003. /**
  14004. * @author mikael emtinger / http://gomo.se/
  14005. * @author alteredq / http://alteredqualia.com/
  14006. */
  14007. THREE.Sprite = function ( material ) {
  14008. THREE.Object3D.call( this );
  14009. this.type = 'Sprite';
  14010. this.material = ( material !== undefined ) ? material : new THREE.SpriteMaterial();
  14011. };
  14012. THREE.Sprite.prototype = Object.assign( Object.create( THREE.Object3D.prototype ), {
  14013. constructor: THREE.Sprite,
  14014. raycast: ( function () {
  14015. var matrixPosition = new THREE.Vector3();
  14016. return function raycast( raycaster, intersects ) {
  14017. matrixPosition.setFromMatrixPosition( this.matrixWorld );
  14018. var distanceSq = raycaster.ray.distanceSqToPoint( matrixPosition );
  14019. var guessSizeSq = this.scale.x * this.scale.y / 4;
  14020. if ( distanceSq > guessSizeSq ) {
  14021. return;
  14022. }
  14023. intersects.push( {
  14024. distance: Math.sqrt( distanceSq ),
  14025. point: this.position,
  14026. face: null,
  14027. object: this
  14028. } );
  14029. };
  14030. }() ),
  14031. clone: function () {
  14032. return new this.constructor( this.material ).copy( this );
  14033. }
  14034. } );
  14035. // File:src/objects/LensFlare.js
  14036. /**
  14037. * @author mikael emtinger / http://gomo.se/
  14038. * @author alteredq / http://alteredqualia.com/
  14039. */
  14040. THREE.LensFlare = function ( texture, size, distance, blending, color ) {
  14041. THREE.Object3D.call( this );
  14042. this.lensFlares = [];
  14043. this.positionScreen = new THREE.Vector3();
  14044. this.customUpdateCallback = undefined;
  14045. if ( texture !== undefined ) {
  14046. this.add( texture, size, distance, blending, color );
  14047. }
  14048. };
  14049. THREE.LensFlare.prototype = Object.assign( Object.create( THREE.Object3D.prototype ), {
  14050. constructor: THREE.LensFlare,
  14051. copy: function ( source ) {
  14052. THREE.Object3D.prototype.copy.call( this, source );
  14053. this.positionScreen.copy( source.positionScreen );
  14054. this.customUpdateCallback = source.customUpdateCallback;
  14055. for ( var i = 0, l = source.lensFlares.length; i < l; i ++ ) {
  14056. this.lensFlares.push( source.lensFlares[ i ] );
  14057. }
  14058. return this;
  14059. },
  14060. add: function ( texture, size, distance, blending, color, opacity ) {
  14061. if ( size === undefined ) size = - 1;
  14062. if ( distance === undefined ) distance = 0;
  14063. if ( opacity === undefined ) opacity = 1;
  14064. if ( color === undefined ) color = new THREE.Color( 0xffffff );
  14065. if ( blending === undefined ) blending = THREE.NormalBlending;
  14066. distance = Math.min( distance, Math.max( 0, distance ) );
  14067. this.lensFlares.push( {
  14068. texture: texture, // THREE.Texture
  14069. size: size, // size in pixels (-1 = use texture.width)
  14070. distance: distance, // distance (0-1) from light source (0=at light source)
  14071. x: 0, y: 0, z: 0, // screen position (-1 => 1) z = 0 is in front z = 1 is back
  14072. scale: 1, // scale
  14073. rotation: 0, // rotation
  14074. opacity: opacity, // opacity
  14075. color: color, // color
  14076. blending: blending // blending
  14077. } );
  14078. },
  14079. /*
  14080. * Update lens flares update positions on all flares based on the screen position
  14081. * Set myLensFlare.customUpdateCallback to alter the flares in your project specific way.
  14082. */
  14083. updateLensFlares: function () {
  14084. var f, fl = this.lensFlares.length;
  14085. var flare;
  14086. var vecX = - this.positionScreen.x * 2;
  14087. var vecY = - this.positionScreen.y * 2;
  14088. for ( f = 0; f < fl; f ++ ) {
  14089. flare = this.lensFlares[ f ];
  14090. flare.x = this.positionScreen.x + vecX * flare.distance;
  14091. flare.y = this.positionScreen.y + vecY * flare.distance;
  14092. flare.wantedRotation = flare.x * Math.PI * 0.25;
  14093. flare.rotation += ( flare.wantedRotation - flare.rotation ) * 0.25;
  14094. }
  14095. }
  14096. } );
  14097. // File:src/scenes/Scene.js
  14098. /**
  14099. * @author mrdoob / http://mrdoob.com/
  14100. */
  14101. THREE.Scene = function () {
  14102. THREE.Object3D.call( this );
  14103. this.type = 'Scene';
  14104. this.background = null;
  14105. this.fog = null;
  14106. this.overrideMaterial = null;
  14107. this.autoUpdate = true; // checked by the renderer
  14108. };
  14109. THREE.Scene.prototype = Object.create( THREE.Object3D.prototype );
  14110. THREE.Scene.prototype.constructor = THREE.Scene;
  14111. THREE.Scene.prototype.copy = function ( source, recursive ) {
  14112. THREE.Object3D.prototype.copy.call( this, source, recursive );
  14113. if ( source.background !== null ) this.background = source.background.clone();
  14114. if ( source.fog !== null ) this.fog = source.fog.clone();
  14115. if ( source.overrideMaterial !== null ) this.overrideMaterial = source.overrideMaterial.clone();
  14116. this.autoUpdate = source.autoUpdate;
  14117. this.matrixAutoUpdate = source.matrixAutoUpdate;
  14118. return this;
  14119. };
  14120. // File:src/scenes/Fog.js
  14121. /**
  14122. * @author mrdoob / http://mrdoob.com/
  14123. * @author alteredq / http://alteredqualia.com/
  14124. */
  14125. THREE.Fog = function ( color, near, far ) {
  14126. this.name = '';
  14127. this.color = new THREE.Color( color );
  14128. this.near = ( near !== undefined ) ? near : 1;
  14129. this.far = ( far !== undefined ) ? far : 1000;
  14130. };
  14131. THREE.Fog.prototype.clone = function () {
  14132. return new THREE.Fog( this.color.getHex(), this.near, this.far );
  14133. };
  14134. // File:src/scenes/FogExp2.js
  14135. /**
  14136. * @author mrdoob / http://mrdoob.com/
  14137. * @author alteredq / http://alteredqualia.com/
  14138. */
  14139. THREE.FogExp2 = function ( color, density ) {
  14140. this.name = '';
  14141. this.color = new THREE.Color( color );
  14142. this.density = ( density !== undefined ) ? density : 0.00025;
  14143. };
  14144. THREE.FogExp2.prototype.clone = function () {
  14145. return new THREE.FogExp2( this.color.getHex(), this.density );
  14146. };
  14147. // File:src/renderers/shaders/ShaderChunk.js
  14148. THREE.ShaderChunk = {};
  14149. // File:src/renderers/shaders/ShaderChunk/alphamap_fragment.glsl
  14150. THREE.ShaderChunk[ 'alphamap_fragment' ] = "#ifdef USE_ALPHAMAP\n diffuseColor.a *= texture2D( alphaMap, vUv ).g;\n#endif\n";
  14151. // File:src/renderers/shaders/ShaderChunk/alphamap_pars_fragment.glsl
  14152. THREE.ShaderChunk[ 'alphamap_pars_fragment' ] = "#ifdef USE_ALPHAMAP\n uniform sampler2D alphaMap;\n#endif\n";
  14153. // File:src/renderers/shaders/ShaderChunk/alphatest_fragment.glsl
  14154. THREE.ShaderChunk[ 'alphatest_fragment' ] = "#ifdef ALPHATEST\n if ( diffuseColor.a < ALPHATEST ) discard;\n#endif\n";
  14155. // File:src/renderers/shaders/ShaderChunk/aomap_fragment.glsl
  14156. 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";
  14157. // File:src/renderers/shaders/ShaderChunk/aomap_pars_fragment.glsl
  14158. THREE.ShaderChunk[ 'aomap_pars_fragment' ] = "#ifdef USE_AOMAP\n uniform sampler2D aoMap;\n uniform float aoMapIntensity;\n#endif";
  14159. // File:src/renderers/shaders/ShaderChunk/begin_vertex.glsl
  14160. THREE.ShaderChunk[ 'begin_vertex' ] = "\nvec3 transformed = vec3( position );\n";
  14161. // File:src/renderers/shaders/ShaderChunk/beginnormal_vertex.glsl
  14162. THREE.ShaderChunk[ 'beginnormal_vertex' ] = "\nvec3 objectNormal = vec3( normal );\n";
  14163. // File:src/renderers/shaders/ShaderChunk/bsdfs.glsl
  14164. 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";
  14165. // File:src/renderers/shaders/ShaderChunk/bumpmap_pars_fragment.glsl
  14166. 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";
  14167. // File:src/renderers/shaders/ShaderChunk/clipping_planes_fragment.glsl
  14168. 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";
  14169. // File:src/renderers/shaders/ShaderChunk/clipping_planes_pars_fragment.glsl
  14170. 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";
  14171. // File:src/renderers/shaders/ShaderChunk/clipping_planes_pars_vertex.glsl
  14172. THREE.ShaderChunk[ 'clipping_planes_pars_vertex' ] = "#if NUM_CLIPPING_PLANES > 0 && ! defined( PHYSICAL ) && ! defined( PHONG )\n varying vec3 vViewPosition;\n#endif\n";
  14173. // File:src/renderers/shaders/ShaderChunk/clipping_planes_vertex.glsl
  14174. THREE.ShaderChunk[ 'clipping_planes_vertex' ] = "#if NUM_CLIPPING_PLANES > 0 && ! defined( PHYSICAL ) && ! defined( PHONG )\n vViewPosition = - mvPosition.xyz;\n#endif\n";
  14175. // File:src/renderers/shaders/ShaderChunk/color_fragment.glsl
  14176. THREE.ShaderChunk[ 'color_fragment' ] = "#ifdef USE_COLOR\n diffuseColor.rgb *= vColor;\n#endif";
  14177. // File:src/renderers/shaders/ShaderChunk/color_pars_fragment.glsl
  14178. THREE.ShaderChunk[ 'color_pars_fragment' ] = "#ifdef USE_COLOR\n varying vec3 vColor;\n#endif\n";
  14179. // File:src/renderers/shaders/ShaderChunk/color_pars_vertex.glsl
  14180. THREE.ShaderChunk[ 'color_pars_vertex' ] = "#ifdef USE_COLOR\n varying vec3 vColor;\n#endif";
  14181. // File:src/renderers/shaders/ShaderChunk/color_vertex.glsl
  14182. THREE.ShaderChunk[ 'color_vertex' ] = "#ifdef USE_COLOR\n vColor.xyz = color.xyz;\n#endif";
  14183. // File:src/renderers/shaders/ShaderChunk/common.glsl
  14184. 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";
  14185. // File:src/renderers/shaders/ShaderChunk/cube_uv_reflection_fragment.glsl
  14186. 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";
  14187. // File:src/renderers/shaders/ShaderChunk/defaultnormal_vertex.glsl
  14188. THREE.ShaderChunk[ 'defaultnormal_vertex' ] = "#ifdef FLIP_SIDED\n objectNormal = -objectNormal;\n#endif\nvec3 transformedNormal = normalMatrix * objectNormal;\n";
  14189. // File:src/renderers/shaders/ShaderChunk/displacementmap_vertex.glsl
  14190. THREE.ShaderChunk[ 'displacementmap_vertex' ] = "#ifdef USE_DISPLACEMENTMAP\n transformed += normal * ( texture2D( displacementMap, uv ).x * displacementScale + displacementBias );\n#endif\n";
  14191. // File:src/renderers/shaders/ShaderChunk/displacementmap_pars_vertex.glsl
  14192. THREE.ShaderChunk[ 'displacementmap_pars_vertex' ] = "#ifdef USE_DISPLACEMENTMAP\n uniform sampler2D displacementMap;\n uniform float displacementScale;\n uniform float displacementBias;\n#endif\n";
  14193. // File:src/renderers/shaders/ShaderChunk/emissivemap_fragment.glsl
  14194. 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";
  14195. // File:src/renderers/shaders/ShaderChunk/emissivemap_pars_fragment.glsl
  14196. THREE.ShaderChunk[ 'emissivemap_pars_fragment' ] = "#ifdef USE_EMISSIVEMAP\n uniform sampler2D emissiveMap;\n#endif\n";
  14197. // File:src/renderers/shaders/ShaderChunk/encodings_pars_fragment.glsl
  14198. 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";
  14199. // File:src/renderers/shaders/ShaderChunk/encodings_fragment.glsl
  14200. THREE.ShaderChunk[ 'encodings_fragment' ] = " gl_FragColor = linearToOutputTexel( gl_FragColor );\n";
  14201. // File:src/renderers/shaders/ShaderChunk/envmap_fragment.glsl
  14202. 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";
  14203. // File:src/renderers/shaders/ShaderChunk/envmap_pars_fragment.glsl
  14204. 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";
  14205. // File:src/renderers/shaders/ShaderChunk/envmap_pars_vertex.glsl
  14206. 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";
  14207. // File:src/renderers/shaders/ShaderChunk/envmap_vertex.glsl
  14208. 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";
  14209. // File:src/renderers/shaders/ShaderChunk/fog_fragment.glsl
  14210. 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";
  14211. // File:src/renderers/shaders/ShaderChunk/fog_pars_fragment.glsl
  14212. 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";
  14213. // File:src/renderers/shaders/ShaderChunk/lightmap_fragment.glsl
  14214. THREE.ShaderChunk[ 'lightmap_fragment' ] = "#ifdef USE_LIGHTMAP\n reflectedLight.indirectDiffuse += PI * texture2D( lightMap, vUv2 ).xyz * lightMapIntensity;\n#endif\n";
  14215. // File:src/renderers/shaders/ShaderChunk/lightmap_pars_fragment.glsl
  14216. THREE.ShaderChunk[ 'lightmap_pars_fragment' ] = "#ifdef USE_LIGHTMAP\n uniform sampler2D lightMap;\n uniform float lightMapIntensity;\n#endif";
  14217. // File:src/renderers/shaders/ShaderChunk/lights_lambert_vertex.glsl
  14218. 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";
  14219. // File:src/renderers/shaders/ShaderChunk/lights_pars.glsl
  14220. 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";
  14221. // File:src/renderers/shaders/ShaderChunk/lights_phong_fragment.glsl
  14222. THREE.ShaderChunk[ 'lights_phong_fragment' ] = "BlinnPhongMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;\nmaterial.specularColor = specular;\nmaterial.specularShininess = shininess;\nmaterial.specularStrength = specularStrength;\n";
  14223. // File:src/renderers/shaders/ShaderChunk/lights_phong_pars_fragment.glsl
  14224. 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";
  14225. // File:src/renderers/shaders/ShaderChunk/lights_physical_fragment.glsl
  14226. 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";
  14227. // File:src/renderers/shaders/ShaderChunk/lights_physical_pars_fragment.glsl
  14228. 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\nvoid RE_Direct_Physical( const in IncidentLight directLight, const in GeometricContext geometry, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {\n float dotNL = saturate( dot( geometry.normal, directLight.direction ) );\n vec3 irradiance = dotNL * directLight.color;\n #ifndef PHYSICALLY_CORRECT_LIGHTS\n irradiance *= PI;\n #endif\n reflectedLight.directSpecular += irradiance * BRDF_Specular_GGX( directLight, geometry, material.specularColor, material.specularRoughness );\n reflectedLight.directDiffuse += 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 reflectedLight.indirectSpecular += 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";
  14229. // File:src/renderers/shaders/ShaderChunk/lights_template.glsl
  14230. 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";
  14231. // File:src/renderers/shaders/ShaderChunk/logdepthbuf_fragment.glsl
  14232. THREE.ShaderChunk[ 'logdepthbuf_fragment' ] = "#if defined(USE_LOGDEPTHBUF) && defined(USE_LOGDEPTHBUF_EXT)\n gl_FragDepthEXT = log2(vFragDepth) * logDepthBufFC * 0.5;\n#endif";
  14233. // File:src/renderers/shaders/ShaderChunk/logdepthbuf_pars_fragment.glsl
  14234. 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";
  14235. // File:src/renderers/shaders/ShaderChunk/logdepthbuf_pars_vertex.glsl
  14236. 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";
  14237. // File:src/renderers/shaders/ShaderChunk/logdepthbuf_vertex.glsl
  14238. 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";
  14239. // File:src/renderers/shaders/ShaderChunk/map_fragment.glsl
  14240. THREE.ShaderChunk[ 'map_fragment' ] = "#ifdef USE_MAP\n vec4 texelColor = texture2D( map, vUv );\n texelColor = mapTexelToLinear( texelColor );\n diffuseColor *= texelColor;\n#endif\n";
  14241. // File:src/renderers/shaders/ShaderChunk/map_pars_fragment.glsl
  14242. THREE.ShaderChunk[ 'map_pars_fragment' ] = "#ifdef USE_MAP\n uniform sampler2D map;\n#endif\n";
  14243. // File:src/renderers/shaders/ShaderChunk/map_particle_fragment.glsl
  14244. 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";
  14245. // File:src/renderers/shaders/ShaderChunk/map_particle_pars_fragment.glsl
  14246. THREE.ShaderChunk[ 'map_particle_pars_fragment' ] = "#ifdef USE_MAP\n uniform vec4 offsetRepeat;\n uniform sampler2D map;\n#endif\n";
  14247. // File:src/renderers/shaders/ShaderChunk/metalnessmap_fragment.glsl
  14248. THREE.ShaderChunk[ 'metalnessmap_fragment' ] = "float metalnessFactor = metalness;\n#ifdef USE_METALNESSMAP\n vec4 texelMetalness = texture2D( metalnessMap, vUv );\n metalnessFactor *= texelMetalness.r;\n#endif\n";
  14249. // File:src/renderers/shaders/ShaderChunk/metalnessmap_pars_fragment.glsl
  14250. THREE.ShaderChunk[ 'metalnessmap_pars_fragment' ] = "#ifdef USE_METALNESSMAP\n uniform sampler2D metalnessMap;\n#endif";
  14251. // File:src/renderers/shaders/ShaderChunk/morphnormal_vertex.glsl
  14252. 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";
  14253. // File:src/renderers/shaders/ShaderChunk/morphtarget_pars_vertex.glsl
  14254. 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";
  14255. // File:src/renderers/shaders/ShaderChunk/morphtarget_vertex.glsl
  14256. 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";
  14257. // File:src/renderers/shaders/ShaderChunk/normal_flip.glsl
  14258. 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";
  14259. // File:src/renderers/shaders/ShaderChunk/normal_fragment.glsl
  14260. 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";
  14261. // File:src/renderers/shaders/ShaderChunk/normalmap_pars_fragment.glsl
  14262. 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";
  14263. // File:src/renderers/shaders/ShaderChunk/packing.glsl
  14264. 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";
  14265. // File:src/renderers/shaders/ShaderChunk/premultiplied_alpha_fragment.glsl
  14266. THREE.ShaderChunk[ 'premultiplied_alpha_fragment' ] = "#ifdef PREMULTIPLIED_ALPHA\n gl_FragColor.rgb *= gl_FragColor.a;\n#endif\n";
  14267. // File:src/renderers/shaders/ShaderChunk/project_vertex.glsl
  14268. 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";
  14269. // File:src/renderers/shaders/ShaderChunk/roughnessmap_fragment.glsl
  14270. THREE.ShaderChunk[ 'roughnessmap_fragment' ] = "float roughnessFactor = roughness;\n#ifdef USE_ROUGHNESSMAP\n vec4 texelRoughness = texture2D( roughnessMap, vUv );\n roughnessFactor *= texelRoughness.r;\n#endif\n";
  14271. // File:src/renderers/shaders/ShaderChunk/roughnessmap_pars_fragment.glsl
  14272. THREE.ShaderChunk[ 'roughnessmap_pars_fragment' ] = "#ifdef USE_ROUGHNESSMAP\n uniform sampler2D roughnessMap;\n#endif";
  14273. // File:src/renderers/shaders/ShaderChunk/shadowmap_pars_fragment.glsl
  14274. 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";
  14275. // File:src/renderers/shaders/ShaderChunk/shadowmap_pars_vertex.glsl
  14276. 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";
  14277. // File:src/renderers/shaders/ShaderChunk/shadowmap_vertex.glsl
  14278. 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";
  14279. // File:src/renderers/shaders/ShaderChunk/shadowmask_pars_fragment.glsl
  14280. 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";
  14281. // File:src/renderers/shaders/ShaderChunk/skinbase_vertex.glsl
  14282. 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";
  14283. // File:src/renderers/shaders/ShaderChunk/skinning_pars_vertex.glsl
  14284. 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";
  14285. // File:src/renderers/shaders/ShaderChunk/skinning_vertex.glsl
  14286. 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";
  14287. // File:src/renderers/shaders/ShaderChunk/skinnormal_vertex.glsl
  14288. 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";
  14289. // File:src/renderers/shaders/ShaderChunk/specularmap_fragment.glsl
  14290. 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";
  14291. // File:src/renderers/shaders/ShaderChunk/specularmap_pars_fragment.glsl
  14292. THREE.ShaderChunk[ 'specularmap_pars_fragment' ] = "#ifdef USE_SPECULARMAP\n uniform sampler2D specularMap;\n#endif";
  14293. // File:src/renderers/shaders/ShaderChunk/tonemapping_fragment.glsl
  14294. THREE.ShaderChunk[ 'tonemapping_fragment' ] = "#if defined( TONE_MAPPING )\n gl_FragColor.rgb = toneMapping( gl_FragColor.rgb );\n#endif\n";
  14295. // File:src/renderers/shaders/ShaderChunk/tonemapping_pars_fragment.glsl
  14296. 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";
  14297. // File:src/renderers/shaders/ShaderChunk/uv2_pars_fragment.glsl
  14298. THREE.ShaderChunk[ 'uv2_pars_fragment' ] = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n varying vec2 vUv2;\n#endif";
  14299. // File:src/renderers/shaders/ShaderChunk/uv2_pars_vertex.glsl
  14300. THREE.ShaderChunk[ 'uv2_pars_vertex' ] = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n attribute vec2 uv2;\n varying vec2 vUv2;\n#endif";
  14301. // File:src/renderers/shaders/ShaderChunk/uv2_vertex.glsl
  14302. THREE.ShaderChunk[ 'uv2_vertex' ] = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n vUv2 = uv2;\n#endif";
  14303. // File:src/renderers/shaders/ShaderChunk/uv_pars_fragment.glsl
  14304. 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";
  14305. // File:src/renderers/shaders/ShaderChunk/uv_pars_vertex.glsl
  14306. 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";
  14307. // File:src/renderers/shaders/ShaderChunk/uv_vertex.glsl
  14308. 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";
  14309. // File:src/renderers/shaders/ShaderChunk/worldpos_vertex.glsl
  14310. 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";
  14311. // File:src/renderers/shaders/UniformsUtils.js
  14312. /**
  14313. * Uniform Utilities
  14314. */
  14315. THREE.UniformsUtils = {
  14316. merge: function ( uniforms ) {
  14317. var merged = {};
  14318. for ( var u = 0; u < uniforms.length; u ++ ) {
  14319. var tmp = this.clone( uniforms[ u ] );
  14320. for ( var p in tmp ) {
  14321. merged[ p ] = tmp[ p ];
  14322. }
  14323. }
  14324. return merged;
  14325. },
  14326. clone: function ( uniforms_src ) {
  14327. var uniforms_dst = {};
  14328. for ( var u in uniforms_src ) {
  14329. uniforms_dst[ u ] = {};
  14330. for ( var p in uniforms_src[ u ] ) {
  14331. var parameter_src = uniforms_src[ u ][ p ];
  14332. if ( parameter_src instanceof THREE.Color ||
  14333. parameter_src instanceof THREE.Vector2 ||
  14334. parameter_src instanceof THREE.Vector3 ||
  14335. parameter_src instanceof THREE.Vector4 ||
  14336. parameter_src instanceof THREE.Matrix3 ||
  14337. parameter_src instanceof THREE.Matrix4 ||
  14338. parameter_src instanceof THREE.Texture ) {
  14339. uniforms_dst[ u ][ p ] = parameter_src.clone();
  14340. } else if ( Array.isArray( parameter_src ) ) {
  14341. uniforms_dst[ u ][ p ] = parameter_src.slice();
  14342. } else {
  14343. uniforms_dst[ u ][ p ] = parameter_src;
  14344. }
  14345. }
  14346. }
  14347. return uniforms_dst;
  14348. }
  14349. };
  14350. // File:src/renderers/shaders/UniformsLib.js
  14351. /**
  14352. * Uniforms library for shared webgl shaders
  14353. */
  14354. THREE.UniformsLib = {
  14355. common: {
  14356. "diffuse": { value: new THREE.Color( 0xeeeeee ) },
  14357. "opacity": { value: 1.0 },
  14358. "map": { value: null },
  14359. "offsetRepeat": { value: new THREE.Vector4( 0, 0, 1, 1 ) },
  14360. "specularMap": { value: null },
  14361. "alphaMap": { value: null },
  14362. "envMap": { value: null },
  14363. "flipEnvMap": { value: - 1 },
  14364. "reflectivity": { value: 1.0 },
  14365. "refractionRatio": { value: 0.98 }
  14366. },
  14367. aomap: {
  14368. "aoMap": { value: null },
  14369. "aoMapIntensity": { value: 1 }
  14370. },
  14371. lightmap: {
  14372. "lightMap": { value: null },
  14373. "lightMapIntensity": { value: 1 }
  14374. },
  14375. emissivemap: {
  14376. "emissiveMap": { value: null }
  14377. },
  14378. bumpmap: {
  14379. "bumpMap": { value: null },
  14380. "bumpScale": { value: 1 }
  14381. },
  14382. normalmap: {
  14383. "normalMap": { value: null },
  14384. "normalScale": { value: new THREE.Vector2( 1, 1 ) }
  14385. },
  14386. displacementmap: {
  14387. "displacementMap": { value: null },
  14388. "displacementScale": { value: 1 },
  14389. "displacementBias": { value: 0 }
  14390. },
  14391. roughnessmap: {
  14392. "roughnessMap": { value: null }
  14393. },
  14394. metalnessmap: {
  14395. "metalnessMap": { value: null }
  14396. },
  14397. fog: {
  14398. "fogDensity": { value: 0.00025 },
  14399. "fogNear": { value: 1 },
  14400. "fogFar": { value: 2000 },
  14401. "fogColor": { value: new THREE.Color( 0xffffff ) }
  14402. },
  14403. lights: {
  14404. "ambientLightColor": { value: [] },
  14405. "directionalLights": { value: [], properties: {
  14406. "direction": {},
  14407. "color": {},
  14408. "shadow": {},
  14409. "shadowBias": {},
  14410. "shadowRadius": {},
  14411. "shadowMapSize": {}
  14412. } },
  14413. "directionalShadowMap": { value: [] },
  14414. "directionalShadowMatrix": { value: [] },
  14415. "spotLights": { value: [], properties: {
  14416. "color": {},
  14417. "position": {},
  14418. "direction": {},
  14419. "distance": {},
  14420. "coneCos": {},
  14421. "penumbraCos": {},
  14422. "decay": {},
  14423. "shadow": {},
  14424. "shadowBias": {},
  14425. "shadowRadius": {},
  14426. "shadowMapSize": {}
  14427. } },
  14428. "spotShadowMap": { value: [] },
  14429. "spotShadowMatrix": { value: [] },
  14430. "pointLights": { value: [], properties: {
  14431. "color": {},
  14432. "position": {},
  14433. "decay": {},
  14434. "distance": {},
  14435. "shadow": {},
  14436. "shadowBias": {},
  14437. "shadowRadius": {},
  14438. "shadowMapSize": {}
  14439. } },
  14440. "pointShadowMap": { value: [] },
  14441. "pointShadowMatrix": { value: [] },
  14442. "hemisphereLights": { value: [], properties: {
  14443. "direction": {},
  14444. "skyColor": {},
  14445. "groundColor": {}
  14446. } }
  14447. },
  14448. points: {
  14449. "diffuse": { value: new THREE.Color( 0xeeeeee ) },
  14450. "opacity": { value: 1.0 },
  14451. "size": { value: 1.0 },
  14452. "scale": { value: 1.0 },
  14453. "map": { value: null },
  14454. "offsetRepeat": { value: new THREE.Vector4( 0, 0, 1, 1 ) }
  14455. }
  14456. };
  14457. // File:src/renderers/shaders/ShaderLib/cube_frag.glsl
  14458. THREE.ShaderChunk[ 'cube_frag' ] = "uniform samplerCube tCube;\nuniform float tFlip;\nuniform float opacity;\nvarying vec3 vWorldPosition;\n#include <common>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n #include <clipping_planes_fragment>\n gl_FragColor = textureCube( tCube, vec3( tFlip * vWorldPosition.x, vWorldPosition.yz ) );\n gl_FragColor.a *= opacity;\n #include <logdepthbuf_fragment>\n}\n";
  14459. // File:src/renderers/shaders/ShaderLib/cube_vert.glsl
  14460. THREE.ShaderChunk[ 'cube_vert' ] = "varying vec3 vWorldPosition;\n#include <common>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n vWorldPosition = transformDirection( position, modelMatrix );\n #include <begin_vertex>\n #include <project_vertex>\n #include <logdepthbuf_vertex>\n #include <clipping_planes_vertex>\n}\n";
  14461. // File:src/renderers/shaders/ShaderLib/depth_frag.glsl
  14462. 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";
  14463. // File:src/renderers/shaders/ShaderLib/depth_vert.glsl
  14464. 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";
  14465. // File:src/renderers/shaders/ShaderLib/distanceRGBA_frag.glsl
  14466. 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";
  14467. // File:src/renderers/shaders/ShaderLib/distanceRGBA_vert.glsl
  14468. 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";
  14469. // File:src/renderers/shaders/ShaderLib/equirect_frag.glsl
  14470. THREE.ShaderChunk[ 'equirect_frag' ] = "uniform sampler2D tEquirect;\nuniform float tFlip;\nvarying vec3 vWorldPosition;\n#include <common>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n #include <clipping_planes_fragment>\n vec3 direction = normalize( vWorldPosition );\n vec2 sampleUV;\n sampleUV.y = saturate( tFlip * direction.y * -0.5 + 0.5 );\n sampleUV.x = atan( direction.z, direction.x ) * RECIPROCAL_PI2 + 0.5;\n gl_FragColor = texture2D( tEquirect, sampleUV );\n #include <logdepthbuf_fragment>\n}\n";
  14471. // File:src/renderers/shaders/ShaderLib/equirect_vert.glsl
  14472. THREE.ShaderChunk[ 'equirect_vert' ] = "varying vec3 vWorldPosition;\n#include <common>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n vWorldPosition = transformDirection( position, modelMatrix );\n #include <begin_vertex>\n #include <project_vertex>\n #include <logdepthbuf_vertex>\n #include <clipping_planes_vertex>\n}\n";
  14473. // File:src/renderers/shaders/ShaderLib/linedashed_frag.glsl
  14474. 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";
  14475. // File:src/renderers/shaders/ShaderLib/linedashed_vert.glsl
  14476. 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";
  14477. // File:src/renderers/shaders/ShaderLib/meshbasic_frag.glsl
  14478. 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";
  14479. // File:src/renderers/shaders/ShaderLib/meshbasic_vert.glsl
  14480. 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";
  14481. // File:src/renderers/shaders/ShaderLib/meshlambert_frag.glsl
  14482. 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";
  14483. // File:src/renderers/shaders/ShaderLib/meshlambert_vert.glsl
  14484. 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";
  14485. // File:src/renderers/shaders/ShaderLib/meshphong_frag.glsl
  14486. 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";
  14487. // File:src/renderers/shaders/ShaderLib/meshphong_vert.glsl
  14488. 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";
  14489. // File:src/renderers/shaders/ShaderLib/meshphysical_frag.glsl
  14490. 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";
  14491. // File:src/renderers/shaders/ShaderLib/meshphysical_vert.glsl
  14492. 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";
  14493. // File:src/renderers/shaders/ShaderLib/normal_frag.glsl
  14494. 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";
  14495. // File:src/renderers/shaders/ShaderLib/normal_vert.glsl
  14496. 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";
  14497. // File:src/renderers/shaders/ShaderLib/points_frag.glsl
  14498. 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";
  14499. // File:src/renderers/shaders/ShaderLib/points_vert.glsl
  14500. 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";
  14501. // File:src/renderers/shaders/ShaderLib/shadow_frag.glsl
  14502. 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";
  14503. // File:src/renderers/shaders/ShaderLib/shadow_vert.glsl
  14504. 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";
  14505. // File:src/renderers/shaders/ShaderLib.js
  14506. /**
  14507. * Webgl Shader Library for three.js
  14508. *
  14509. * @author alteredq / http://alteredqualia.com/
  14510. * @author mrdoob / http://mrdoob.com/
  14511. * @author mikael emtinger / http://gomo.se/
  14512. */
  14513. THREE.ShaderLib = {
  14514. 'basic': {
  14515. uniforms: THREE.UniformsUtils.merge( [
  14516. THREE.UniformsLib[ 'common' ],
  14517. THREE.UniformsLib[ 'aomap' ],
  14518. THREE.UniformsLib[ 'fog' ]
  14519. ] ),
  14520. vertexShader: THREE.ShaderChunk[ 'meshbasic_vert' ],
  14521. fragmentShader: THREE.ShaderChunk[ 'meshbasic_frag' ]
  14522. },
  14523. 'lambert': {
  14524. uniforms: THREE.UniformsUtils.merge( [
  14525. THREE.UniformsLib[ 'common' ],
  14526. THREE.UniformsLib[ 'aomap' ],
  14527. THREE.UniformsLib[ 'lightmap' ],
  14528. THREE.UniformsLib[ 'emissivemap' ],
  14529. THREE.UniformsLib[ 'fog' ],
  14530. THREE.UniformsLib[ 'lights' ],
  14531. {
  14532. "emissive" : { value: new THREE.Color( 0x000000 ) }
  14533. }
  14534. ] ),
  14535. vertexShader: THREE.ShaderChunk[ 'meshlambert_vert' ],
  14536. fragmentShader: THREE.ShaderChunk[ 'meshlambert_frag' ]
  14537. },
  14538. 'phong': {
  14539. uniforms: THREE.UniformsUtils.merge( [
  14540. THREE.UniformsLib[ 'common' ],
  14541. THREE.UniformsLib[ 'aomap' ],
  14542. THREE.UniformsLib[ 'lightmap' ],
  14543. THREE.UniformsLib[ 'emissivemap' ],
  14544. THREE.UniformsLib[ 'bumpmap' ],
  14545. THREE.UniformsLib[ 'normalmap' ],
  14546. THREE.UniformsLib[ 'displacementmap' ],
  14547. THREE.UniformsLib[ 'fog' ],
  14548. THREE.UniformsLib[ 'lights' ],
  14549. {
  14550. "emissive" : { value: new THREE.Color( 0x000000 ) },
  14551. "specular" : { value: new THREE.Color( 0x111111 ) },
  14552. "shininess": { value: 30 }
  14553. }
  14554. ] ),
  14555. vertexShader: THREE.ShaderChunk[ 'meshphong_vert' ],
  14556. fragmentShader: THREE.ShaderChunk[ 'meshphong_frag' ]
  14557. },
  14558. 'standard': {
  14559. uniforms: THREE.UniformsUtils.merge( [
  14560. THREE.UniformsLib[ 'common' ],
  14561. THREE.UniformsLib[ 'aomap' ],
  14562. THREE.UniformsLib[ 'lightmap' ],
  14563. THREE.UniformsLib[ 'emissivemap' ],
  14564. THREE.UniformsLib[ 'bumpmap' ],
  14565. THREE.UniformsLib[ 'normalmap' ],
  14566. THREE.UniformsLib[ 'displacementmap' ],
  14567. THREE.UniformsLib[ 'roughnessmap' ],
  14568. THREE.UniformsLib[ 'metalnessmap' ],
  14569. THREE.UniformsLib[ 'fog' ],
  14570. THREE.UniformsLib[ 'lights' ],
  14571. {
  14572. "emissive" : { value: new THREE.Color( 0x000000 ) },
  14573. "roughness": { value: 0.5 },
  14574. "metalness": { value: 0 },
  14575. "envMapIntensity" : { value: 1 }, // temporary
  14576. }
  14577. ] ),
  14578. vertexShader: THREE.ShaderChunk[ 'meshphysical_vert' ],
  14579. fragmentShader: THREE.ShaderChunk[ 'meshphysical_frag' ]
  14580. },
  14581. 'points': {
  14582. uniforms: THREE.UniformsUtils.merge( [
  14583. THREE.UniformsLib[ 'points' ],
  14584. THREE.UniformsLib[ 'fog' ]
  14585. ] ),
  14586. vertexShader: THREE.ShaderChunk[ 'points_vert' ],
  14587. fragmentShader: THREE.ShaderChunk[ 'points_frag' ]
  14588. },
  14589. 'dashed': {
  14590. uniforms: THREE.UniformsUtils.merge( [
  14591. THREE.UniformsLib[ 'common' ],
  14592. THREE.UniformsLib[ 'fog' ],
  14593. {
  14594. "scale" : { value: 1 },
  14595. "dashSize" : { value: 1 },
  14596. "totalSize": { value: 2 }
  14597. }
  14598. ] ),
  14599. vertexShader: THREE.ShaderChunk[ 'linedashed_vert' ],
  14600. fragmentShader: THREE.ShaderChunk[ 'linedashed_frag' ]
  14601. },
  14602. 'depth': {
  14603. uniforms: THREE.UniformsUtils.merge( [
  14604. THREE.UniformsLib[ 'common' ],
  14605. THREE.UniformsLib[ 'displacementmap' ]
  14606. ] ),
  14607. vertexShader: THREE.ShaderChunk[ 'depth_vert' ],
  14608. fragmentShader: THREE.ShaderChunk[ 'depth_frag' ]
  14609. },
  14610. 'normal': {
  14611. uniforms: {
  14612. "opacity" : { value: 1.0 }
  14613. },
  14614. vertexShader: THREE.ShaderChunk[ 'normal_vert' ],
  14615. fragmentShader: THREE.ShaderChunk[ 'normal_frag' ]
  14616. },
  14617. /* -------------------------------------------------------------------------
  14618. // Cube map shader
  14619. ------------------------------------------------------------------------- */
  14620. 'cube': {
  14621. uniforms: {
  14622. "tCube": { value: null },
  14623. "tFlip": { value: - 1 },
  14624. "opacity": { value: 1.0 }
  14625. },
  14626. vertexShader: THREE.ShaderChunk[ 'cube_vert' ],
  14627. fragmentShader: THREE.ShaderChunk[ 'cube_frag' ]
  14628. },
  14629. /* -------------------------------------------------------------------------
  14630. // Cube map shader
  14631. ------------------------------------------------------------------------- */
  14632. 'equirect': {
  14633. uniforms: {
  14634. "tEquirect": { value: null },
  14635. "tFlip": { value: - 1 }
  14636. },
  14637. vertexShader: THREE.ShaderChunk[ 'equirect_vert' ],
  14638. fragmentShader: THREE.ShaderChunk[ 'equirect_frag' ]
  14639. },
  14640. 'distanceRGBA': {
  14641. uniforms: {
  14642. "lightPos": { value: new THREE.Vector3() }
  14643. },
  14644. vertexShader: THREE.ShaderChunk[ 'distanceRGBA_vert' ],
  14645. fragmentShader: THREE.ShaderChunk[ 'distanceRGBA_frag' ]
  14646. }
  14647. };
  14648. THREE.ShaderLib[ 'physical' ] = {
  14649. uniforms: THREE.UniformsUtils.merge( [
  14650. THREE.ShaderLib[ 'standard' ].uniforms,
  14651. {
  14652. "clearCoat": { value: 0 },
  14653. "clearCoatRoughness": { value: 0 }
  14654. }
  14655. ] ),
  14656. vertexShader: THREE.ShaderChunk[ 'meshphysical_vert' ],
  14657. fragmentShader: THREE.ShaderChunk[ 'meshphysical_frag' ]
  14658. };
  14659. // File:src/renderers/WebGLRenderer.js
  14660. /**
  14661. * @author supereggbert / http://www.paulbrunt.co.uk/
  14662. * @author mrdoob / http://mrdoob.com/
  14663. * @author alteredq / http://alteredqualia.com/
  14664. * @author szimek / https://github.com/szimek/
  14665. * @author tschw
  14666. */
  14667. THREE.WebGLRenderer = function ( parameters ) {
  14668. console.log( 'THREE.WebGLRenderer', THREE.REVISION );
  14669. parameters = parameters || {};
  14670. var _canvas = parameters.canvas !== undefined ? parameters.canvas : document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' ),
  14671. _context = parameters.context !== undefined ? parameters.context : null,
  14672. _alpha = parameters.alpha !== undefined ? parameters.alpha : false,
  14673. _depth = parameters.depth !== undefined ? parameters.depth : true,
  14674. _stencil = parameters.stencil !== undefined ? parameters.stencil : true,
  14675. _antialias = parameters.antialias !== undefined ? parameters.antialias : false,
  14676. _premultipliedAlpha = parameters.premultipliedAlpha !== undefined ? parameters.premultipliedAlpha : true,
  14677. _preserveDrawingBuffer = parameters.preserveDrawingBuffer !== undefined ? parameters.preserveDrawingBuffer : false;
  14678. var lights = [];
  14679. var opaqueObjects = [];
  14680. var opaqueObjectsLastIndex = - 1;
  14681. var transparentObjects = [];
  14682. var transparentObjectsLastIndex = - 1;
  14683. var morphInfluences = new Float32Array( 8 );
  14684. var sprites = [];
  14685. var lensFlares = [];
  14686. // public properties
  14687. this.domElement = _canvas;
  14688. this.context = null;
  14689. // clearing
  14690. this.autoClear = true;
  14691. this.autoClearColor = true;
  14692. this.autoClearDepth = true;
  14693. this.autoClearStencil = true;
  14694. // scene graph
  14695. this.sortObjects = true;
  14696. // user-defined clipping
  14697. this.clippingPlanes = [];
  14698. this.localClippingEnabled = false;
  14699. // physically based shading
  14700. this.gammaFactor = 2.0; // for backwards compatibility
  14701. this.gammaInput = false;
  14702. this.gammaOutput = false;
  14703. // physical lights
  14704. this.physicallyCorrectLights = false;
  14705. // tone mapping
  14706. this.toneMapping = THREE.LinearToneMapping;
  14707. this.toneMappingExposure = 1.0;
  14708. this.toneMappingWhitePoint = 1.0;
  14709. // morphs
  14710. this.maxMorphTargets = 8;
  14711. this.maxMorphNormals = 4;
  14712. // internal properties
  14713. var _this = this,
  14714. // internal state cache
  14715. _currentProgram = null,
  14716. _currentRenderTarget = null,
  14717. _currentFramebuffer = null,
  14718. _currentMaterialId = - 1,
  14719. _currentGeometryProgram = '',
  14720. _currentCamera = null,
  14721. _currentScissor = new THREE.Vector4(),
  14722. _currentScissorTest = null,
  14723. _currentViewport = new THREE.Vector4(),
  14724. //
  14725. _usedTextureUnits = 0,
  14726. //
  14727. _clearColor = new THREE.Color( 0x000000 ),
  14728. _clearAlpha = 0,
  14729. _width = _canvas.width,
  14730. _height = _canvas.height,
  14731. _pixelRatio = 1,
  14732. _scissor = new THREE.Vector4( 0, 0, _width, _height ),
  14733. _scissorTest = false,
  14734. _viewport = new THREE.Vector4( 0, 0, _width, _height ),
  14735. // frustum
  14736. _frustum = new THREE.Frustum(),
  14737. // clipping
  14738. _clipping = new THREE.WebGLClipping(),
  14739. _clippingEnabled = false,
  14740. _localClippingEnabled = false,
  14741. _sphere = new THREE.Sphere(),
  14742. // camera matrices cache
  14743. _projScreenMatrix = new THREE.Matrix4(),
  14744. _vector3 = new THREE.Vector3(),
  14745. // light arrays cache
  14746. _lights = {
  14747. hash: '',
  14748. ambient: [ 0, 0, 0 ],
  14749. directional: [],
  14750. directionalShadowMap: [],
  14751. directionalShadowMatrix: [],
  14752. spot: [],
  14753. spotShadowMap: [],
  14754. spotShadowMatrix: [],
  14755. point: [],
  14756. pointShadowMap: [],
  14757. pointShadowMatrix: [],
  14758. hemi: [],
  14759. shadows: []
  14760. },
  14761. // info
  14762. _infoRender = {
  14763. calls: 0,
  14764. vertices: 0,
  14765. faces: 0,
  14766. points: 0
  14767. };
  14768. this.info = {
  14769. render: _infoRender,
  14770. memory: {
  14771. geometries: 0,
  14772. textures: 0
  14773. },
  14774. programs: null
  14775. };
  14776. // initialize
  14777. var _gl;
  14778. try {
  14779. var attributes = {
  14780. alpha: _alpha,
  14781. depth: _depth,
  14782. stencil: _stencil,
  14783. antialias: _antialias,
  14784. premultipliedAlpha: _premultipliedAlpha,
  14785. preserveDrawingBuffer: _preserveDrawingBuffer
  14786. };
  14787. _gl = _context || _canvas.getContext( 'webgl', attributes ) || _canvas.getContext( 'experimental-webgl', attributes );
  14788. if ( _gl === null ) {
  14789. if ( _canvas.getContext( 'webgl' ) !== null ) {
  14790. throw 'Error creating WebGL context with your selected attributes.';
  14791. } else {
  14792. throw 'Error creating WebGL context.';
  14793. }
  14794. }
  14795. // Some experimental-webgl implementations do not have getShaderPrecisionFormat
  14796. if ( _gl.getShaderPrecisionFormat === undefined ) {
  14797. _gl.getShaderPrecisionFormat = function () {
  14798. return { 'rangeMin': 1, 'rangeMax': 1, 'precision': 1 };
  14799. };
  14800. }
  14801. _canvas.addEventListener( 'webglcontextlost', onContextLost, false );
  14802. } catch ( error ) {
  14803. console.error( 'THREE.WebGLRenderer: ' + error );
  14804. }
  14805. var extensions = new THREE.WebGLExtensions( _gl );
  14806. extensions.get( 'WEBGL_depth_texture' );
  14807. extensions.get( 'OES_texture_float' );
  14808. extensions.get( 'OES_texture_float_linear' );
  14809. extensions.get( 'OES_texture_half_float' );
  14810. extensions.get( 'OES_texture_half_float_linear' );
  14811. extensions.get( 'OES_standard_derivatives' );
  14812. extensions.get( 'ANGLE_instanced_arrays' );
  14813. if ( extensions.get( 'OES_element_index_uint' ) ) {
  14814. THREE.BufferGeometry.MaxIndex = 4294967296;
  14815. }
  14816. var capabilities = new THREE.WebGLCapabilities( _gl, extensions, parameters );
  14817. var state = new THREE.WebGLState( _gl, extensions, paramThreeToGL );
  14818. var properties = new THREE.WebGLProperties();
  14819. var textures = new THREE.WebGLTextures( _gl, extensions, state, properties, capabilities, paramThreeToGL, this.info );
  14820. var objects = new THREE.WebGLObjects( _gl, properties, this.info );
  14821. var programCache = new THREE.WebGLPrograms( this, capabilities );
  14822. var lightCache = new THREE.WebGLLights();
  14823. this.info.programs = programCache.programs;
  14824. var bufferRenderer = new THREE.WebGLBufferRenderer( _gl, extensions, _infoRender );
  14825. var indexedBufferRenderer = new THREE.WebGLIndexedBufferRenderer( _gl, extensions, _infoRender );
  14826. //
  14827. var backgroundCamera = new THREE.OrthographicCamera( - 1, 1, 1, - 1, 0, 1 );
  14828. var backgroundCamera2 = new THREE.PerspectiveCamera();
  14829. var backgroundPlaneMesh = new THREE.Mesh(
  14830. new THREE.PlaneBufferGeometry( 2, 2 ),
  14831. new THREE.MeshBasicMaterial( { depthTest: false, depthWrite: false } )
  14832. );
  14833. var backgroundBoxShader = THREE.ShaderLib[ 'cube' ];
  14834. var backgroundBoxMesh = new THREE.Mesh(
  14835. new THREE.BoxBufferGeometry( 5, 5, 5 ),
  14836. new THREE.ShaderMaterial( {
  14837. uniforms: backgroundBoxShader.uniforms,
  14838. vertexShader: backgroundBoxShader.vertexShader,
  14839. fragmentShader: backgroundBoxShader.fragmentShader,
  14840. depthTest: false,
  14841. depthWrite: false,
  14842. side: THREE.BackSide
  14843. } )
  14844. );
  14845. objects.update( backgroundPlaneMesh );
  14846. objects.update( backgroundBoxMesh );
  14847. //
  14848. function getTargetPixelRatio() {
  14849. return _currentRenderTarget === null ? _pixelRatio : 1;
  14850. }
  14851. function glClearColor( r, g, b, a ) {
  14852. if ( _premultipliedAlpha === true ) {
  14853. r *= a; g *= a; b *= a;
  14854. }
  14855. state.clearColor( r, g, b, a );
  14856. }
  14857. function setDefaultGLState() {
  14858. state.init();
  14859. state.scissor( _currentScissor.copy( _scissor ).multiplyScalar( _pixelRatio ) );
  14860. state.viewport( _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio ) );
  14861. glClearColor( _clearColor.r, _clearColor.g, _clearColor.b, _clearAlpha );
  14862. }
  14863. function resetGLState() {
  14864. _currentProgram = null;
  14865. _currentCamera = null;
  14866. _currentGeometryProgram = '';
  14867. _currentMaterialId = - 1;
  14868. state.reset();
  14869. }
  14870. setDefaultGLState();
  14871. this.context = _gl;
  14872. this.capabilities = capabilities;
  14873. this.extensions = extensions;
  14874. this.properties = properties;
  14875. this.state = state;
  14876. // shadow map
  14877. var shadowMap = new THREE.WebGLShadowMap( this, _lights, objects );
  14878. this.shadowMap = shadowMap;
  14879. // Plugins
  14880. var spritePlugin = new THREE.SpritePlugin( this, sprites );
  14881. var lensFlarePlugin = new THREE.LensFlarePlugin( this, lensFlares );
  14882. // API
  14883. this.getContext = function () {
  14884. return _gl;
  14885. };
  14886. this.getContextAttributes = function () {
  14887. return _gl.getContextAttributes();
  14888. };
  14889. this.forceContextLoss = function () {
  14890. extensions.get( 'WEBGL_lose_context' ).loseContext();
  14891. };
  14892. this.getMaxAnisotropy = function () {
  14893. return capabilities.getMaxAnisotropy();
  14894. };
  14895. this.getPrecision = function () {
  14896. return capabilities.precision;
  14897. };
  14898. this.getPixelRatio = function () {
  14899. return _pixelRatio;
  14900. };
  14901. this.setPixelRatio = function ( value ) {
  14902. if ( value === undefined ) return;
  14903. _pixelRatio = value;
  14904. this.setSize( _viewport.z, _viewport.w, false );
  14905. };
  14906. this.getSize = function () {
  14907. return {
  14908. width: _width,
  14909. height: _height
  14910. };
  14911. };
  14912. this.setSize = function ( width, height, updateStyle ) {
  14913. _width = width;
  14914. _height = height;
  14915. _canvas.width = width * _pixelRatio;
  14916. _canvas.height = height * _pixelRatio;
  14917. if ( updateStyle !== false ) {
  14918. _canvas.style.width = width + 'px';
  14919. _canvas.style.height = height + 'px';
  14920. }
  14921. this.setViewport( 0, 0, width, height );
  14922. };
  14923. this.setViewport = function ( x, y, width, height ) {
  14924. state.viewport( _viewport.set( x, y, width, height ) );
  14925. };
  14926. this.setScissor = function ( x, y, width, height ) {
  14927. state.scissor( _scissor.set( x, y, width, height ) );
  14928. };
  14929. this.setScissorTest = function ( boolean ) {
  14930. state.setScissorTest( _scissorTest = boolean );
  14931. };
  14932. // Clearing
  14933. this.getClearColor = function () {
  14934. return _clearColor;
  14935. };
  14936. this.setClearColor = function ( color, alpha ) {
  14937. _clearColor.set( color );
  14938. _clearAlpha = alpha !== undefined ? alpha : 1;
  14939. glClearColor( _clearColor.r, _clearColor.g, _clearColor.b, _clearAlpha );
  14940. };
  14941. this.getClearAlpha = function () {
  14942. return _clearAlpha;
  14943. };
  14944. this.setClearAlpha = function ( alpha ) {
  14945. _clearAlpha = alpha;
  14946. glClearColor( _clearColor.r, _clearColor.g, _clearColor.b, _clearAlpha );
  14947. };
  14948. this.clear = function ( color, depth, stencil ) {
  14949. var bits = 0;
  14950. if ( color === undefined || color ) bits |= _gl.COLOR_BUFFER_BIT;
  14951. if ( depth === undefined || depth ) bits |= _gl.DEPTH_BUFFER_BIT;
  14952. if ( stencil === undefined || stencil ) bits |= _gl.STENCIL_BUFFER_BIT;
  14953. _gl.clear( bits );
  14954. };
  14955. this.clearColor = function () {
  14956. this.clear( true, false, false );
  14957. };
  14958. this.clearDepth = function () {
  14959. this.clear( false, true, false );
  14960. };
  14961. this.clearStencil = function () {
  14962. this.clear( false, false, true );
  14963. };
  14964. this.clearTarget = function ( renderTarget, color, depth, stencil ) {
  14965. this.setRenderTarget( renderTarget );
  14966. this.clear( color, depth, stencil );
  14967. };
  14968. // Reset
  14969. this.resetGLState = resetGLState;
  14970. this.dispose = function() {
  14971. transparentObjects = [];
  14972. transparentObjectsLastIndex = -1;
  14973. opaqueObjects = [];
  14974. opaqueObjectsLastIndex = -1;
  14975. _canvas.removeEventListener( 'webglcontextlost', onContextLost, false );
  14976. };
  14977. // Events
  14978. function onContextLost( event ) {
  14979. event.preventDefault();
  14980. resetGLState();
  14981. setDefaultGLState();
  14982. properties.clear();
  14983. }
  14984. function onMaterialDispose( event ) {
  14985. var material = event.target;
  14986. material.removeEventListener( 'dispose', onMaterialDispose );
  14987. deallocateMaterial( material );
  14988. }
  14989. // Buffer deallocation
  14990. function deallocateMaterial( material ) {
  14991. releaseMaterialProgramReference( material );
  14992. properties.delete( material );
  14993. }
  14994. function releaseMaterialProgramReference( material ) {
  14995. var programInfo = properties.get( material ).program;
  14996. material.program = undefined;
  14997. if ( programInfo !== undefined ) {
  14998. programCache.releaseProgram( programInfo );
  14999. }
  15000. }
  15001. // Buffer rendering
  15002. this.renderBufferImmediate = function ( object, program, material ) {
  15003. state.initAttributes();
  15004. var buffers = properties.get( object );
  15005. if ( object.hasPositions && ! buffers.position ) buffers.position = _gl.createBuffer();
  15006. if ( object.hasNormals && ! buffers.normal ) buffers.normal = _gl.createBuffer();
  15007. if ( object.hasUvs && ! buffers.uv ) buffers.uv = _gl.createBuffer();
  15008. if ( object.hasColors && ! buffers.color ) buffers.color = _gl.createBuffer();
  15009. var attributes = program.getAttributes();
  15010. if ( object.hasPositions ) {
  15011. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffers.position );
  15012. _gl.bufferData( _gl.ARRAY_BUFFER, object.positionArray, _gl.DYNAMIC_DRAW );
  15013. state.enableAttribute( attributes.position );
  15014. _gl.vertexAttribPointer( attributes.position, 3, _gl.FLOAT, false, 0, 0 );
  15015. }
  15016. if ( object.hasNormals ) {
  15017. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffers.normal );
  15018. if ( material.type !== 'MeshPhongMaterial' && material.type !== 'MeshStandardMaterial' && material.type !== 'MeshPhysicalMaterial' && material.shading === THREE.FlatShading ) {
  15019. for ( var i = 0, l = object.count * 3; i < l; i += 9 ) {
  15020. var array = object.normalArray;
  15021. var nx = ( array[ i + 0 ] + array[ i + 3 ] + array[ i + 6 ] ) / 3;
  15022. var ny = ( array[ i + 1 ] + array[ i + 4 ] + array[ i + 7 ] ) / 3;
  15023. var nz = ( array[ i + 2 ] + array[ i + 5 ] + array[ i + 8 ] ) / 3;
  15024. array[ i + 0 ] = nx;
  15025. array[ i + 1 ] = ny;
  15026. array[ i + 2 ] = nz;
  15027. array[ i + 3 ] = nx;
  15028. array[ i + 4 ] = ny;
  15029. array[ i + 5 ] = nz;
  15030. array[ i + 6 ] = nx;
  15031. array[ i + 7 ] = ny;
  15032. array[ i + 8 ] = nz;
  15033. }
  15034. }
  15035. _gl.bufferData( _gl.ARRAY_BUFFER, object.normalArray, _gl.DYNAMIC_DRAW );
  15036. state.enableAttribute( attributes.normal );
  15037. _gl.vertexAttribPointer( attributes.normal, 3, _gl.FLOAT, false, 0, 0 );
  15038. }
  15039. if ( object.hasUvs && material.map ) {
  15040. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffers.uv );
  15041. _gl.bufferData( _gl.ARRAY_BUFFER, object.uvArray, _gl.DYNAMIC_DRAW );
  15042. state.enableAttribute( attributes.uv );
  15043. _gl.vertexAttribPointer( attributes.uv, 2, _gl.FLOAT, false, 0, 0 );
  15044. }
  15045. if ( object.hasColors && material.vertexColors !== THREE.NoColors ) {
  15046. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffers.color );
  15047. _gl.bufferData( _gl.ARRAY_BUFFER, object.colorArray, _gl.DYNAMIC_DRAW );
  15048. state.enableAttribute( attributes.color );
  15049. _gl.vertexAttribPointer( attributes.color, 3, _gl.FLOAT, false, 0, 0 );
  15050. }
  15051. state.disableUnusedAttributes();
  15052. _gl.drawArrays( _gl.TRIANGLES, 0, object.count );
  15053. object.count = 0;
  15054. };
  15055. this.renderBufferDirect = function ( camera, fog, geometry, material, object, group ) {
  15056. setMaterial( material );
  15057. var program = setProgram( camera, fog, material, object );
  15058. var updateBuffers = false;
  15059. var geometryProgram = geometry.id + '_' + program.id + '_' + material.wireframe;
  15060. if ( geometryProgram !== _currentGeometryProgram ) {
  15061. _currentGeometryProgram = geometryProgram;
  15062. updateBuffers = true;
  15063. }
  15064. // morph targets
  15065. var morphTargetInfluences = object.morphTargetInfluences;
  15066. if ( morphTargetInfluences !== undefined ) {
  15067. var activeInfluences = [];
  15068. for ( var i = 0, l = morphTargetInfluences.length; i < l; i ++ ) {
  15069. var influence = morphTargetInfluences[ i ];
  15070. activeInfluences.push( [ influence, i ] );
  15071. }
  15072. activeInfluences.sort( absNumericalSort );
  15073. if ( activeInfluences.length > 8 ) {
  15074. activeInfluences.length = 8;
  15075. }
  15076. var morphAttributes = geometry.morphAttributes;
  15077. for ( var i = 0, l = activeInfluences.length; i < l; i ++ ) {
  15078. var influence = activeInfluences[ i ];
  15079. morphInfluences[ i ] = influence[ 0 ];
  15080. if ( influence[ 0 ] !== 0 ) {
  15081. var index = influence[ 1 ];
  15082. if ( material.morphTargets === true && morphAttributes.position ) geometry.addAttribute( 'morphTarget' + i, morphAttributes.position[ index ] );
  15083. if ( material.morphNormals === true && morphAttributes.normal ) geometry.addAttribute( 'morphNormal' + i, morphAttributes.normal[ index ] );
  15084. } else {
  15085. if ( material.morphTargets === true ) geometry.removeAttribute( 'morphTarget' + i );
  15086. if ( material.morphNormals === true ) geometry.removeAttribute( 'morphNormal' + i );
  15087. }
  15088. }
  15089. program.getUniforms().setValue(
  15090. _gl, 'morphTargetInfluences', morphInfluences );
  15091. updateBuffers = true;
  15092. }
  15093. //
  15094. var index = geometry.index;
  15095. var position = geometry.attributes.position;
  15096. if ( material.wireframe === true ) {
  15097. index = objects.getWireframeAttribute( geometry );
  15098. }
  15099. var renderer;
  15100. if ( index !== null ) {
  15101. renderer = indexedBufferRenderer;
  15102. renderer.setIndex( index );
  15103. } else {
  15104. renderer = bufferRenderer;
  15105. }
  15106. if ( updateBuffers ) {
  15107. setupVertexAttributes( material, program, geometry );
  15108. if ( index !== null ) {
  15109. _gl.bindBuffer( _gl.ELEMENT_ARRAY_BUFFER, objects.getAttributeBuffer( index ) );
  15110. }
  15111. }
  15112. //
  15113. var dataStart = 0;
  15114. var dataCount = Infinity;
  15115. if ( index !== null ) {
  15116. dataCount = index.count;
  15117. } else if ( position !== undefined ) {
  15118. dataCount = position.count;
  15119. }
  15120. var rangeStart = geometry.drawRange.start;
  15121. var rangeCount = geometry.drawRange.count;
  15122. var groupStart = group !== null ? group.start : 0;
  15123. var groupCount = group !== null ? group.count : Infinity;
  15124. var drawStart = Math.max( dataStart, rangeStart, groupStart );
  15125. var drawEnd = Math.min( dataStart + dataCount, rangeStart + rangeCount, groupStart + groupCount ) - 1;
  15126. var drawCount = Math.max( 0, drawEnd - drawStart + 1 );
  15127. //
  15128. if ( object instanceof THREE.Mesh ) {
  15129. if ( material.wireframe === true ) {
  15130. state.setLineWidth( material.wireframeLinewidth * getTargetPixelRatio() );
  15131. renderer.setMode( _gl.LINES );
  15132. } else {
  15133. switch ( object.drawMode ) {
  15134. case THREE.TrianglesDrawMode:
  15135. renderer.setMode( _gl.TRIANGLES );
  15136. break;
  15137. case THREE.TriangleStripDrawMode:
  15138. renderer.setMode( _gl.TRIANGLE_STRIP );
  15139. break;
  15140. case THREE.TriangleFanDrawMode:
  15141. renderer.setMode( _gl.TRIANGLE_FAN );
  15142. break;
  15143. }
  15144. }
  15145. } else if ( object instanceof THREE.Line ) {
  15146. var lineWidth = material.linewidth;
  15147. if ( lineWidth === undefined ) lineWidth = 1; // Not using Line*Material
  15148. state.setLineWidth( lineWidth * getTargetPixelRatio() );
  15149. if ( object instanceof THREE.LineSegments ) {
  15150. renderer.setMode( _gl.LINES );
  15151. } else {
  15152. renderer.setMode( _gl.LINE_STRIP );
  15153. }
  15154. } else if ( object instanceof THREE.Points ) {
  15155. renderer.setMode( _gl.POINTS );
  15156. }
  15157. if ( geometry instanceof THREE.InstancedBufferGeometry ) {
  15158. if ( geometry.maxInstancedCount > 0 ) {
  15159. renderer.renderInstances( geometry, drawStart, drawCount );
  15160. }
  15161. } else {
  15162. renderer.render( drawStart, drawCount );
  15163. }
  15164. };
  15165. function setupVertexAttributes( material, program, geometry, startIndex ) {
  15166. var extension;
  15167. if ( geometry instanceof THREE.InstancedBufferGeometry ) {
  15168. extension = extensions.get( 'ANGLE_instanced_arrays' );
  15169. if ( extension === null ) {
  15170. console.error( 'THREE.WebGLRenderer.setupVertexAttributes: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  15171. return;
  15172. }
  15173. }
  15174. if ( startIndex === undefined ) startIndex = 0;
  15175. state.initAttributes();
  15176. var geometryAttributes = geometry.attributes;
  15177. var programAttributes = program.getAttributes();
  15178. var materialDefaultAttributeValues = material.defaultAttributeValues;
  15179. for ( var name in programAttributes ) {
  15180. var programAttribute = programAttributes[ name ];
  15181. if ( programAttribute >= 0 ) {
  15182. var geometryAttribute = geometryAttributes[ name ];
  15183. if ( geometryAttribute !== undefined ) {
  15184. var type = _gl.FLOAT;
  15185. var array = geometryAttribute.array;
  15186. var normalized = geometryAttribute.normalized;
  15187. if ( array instanceof Float32Array ) {
  15188. type = _gl.FLOAT;
  15189. } else if ( array instanceof Float64Array ) {
  15190. console.warn("Unsupported data buffer format: Float64Array");
  15191. } else if ( array instanceof Uint16Array ) {
  15192. type = _gl.UNSIGNED_SHORT;
  15193. } else if ( array instanceof Int16Array ) {
  15194. type = _gl.SHORT;
  15195. } else if ( array instanceof Uint32Array ) {
  15196. type = _gl.UNSIGNED_INT;
  15197. } else if ( array instanceof Int32Array ) {
  15198. type = _gl.INT;
  15199. } else if ( array instanceof Int8Array ) {
  15200. type = _gl.BYTE;
  15201. } else if ( array instanceof Uint8Array ) {
  15202. type = _gl.UNSIGNED_BYTE;
  15203. }
  15204. var size = geometryAttribute.itemSize;
  15205. var buffer = objects.getAttributeBuffer( geometryAttribute );
  15206. if ( geometryAttribute instanceof THREE.InterleavedBufferAttribute ) {
  15207. var data = geometryAttribute.data;
  15208. var stride = data.stride;
  15209. var offset = geometryAttribute.offset;
  15210. if ( data instanceof THREE.InstancedInterleavedBuffer ) {
  15211. state.enableAttributeAndDivisor( programAttribute, data.meshPerAttribute, extension );
  15212. if ( geometry.maxInstancedCount === undefined ) {
  15213. geometry.maxInstancedCount = data.meshPerAttribute * data.count;
  15214. }
  15215. } else {
  15216. state.enableAttribute( programAttribute );
  15217. }
  15218. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffer );
  15219. _gl.vertexAttribPointer( programAttribute, size, type, normalized, stride * data.array.BYTES_PER_ELEMENT, ( startIndex * stride + offset ) * data.array.BYTES_PER_ELEMENT );
  15220. } else {
  15221. if ( geometryAttribute instanceof THREE.InstancedBufferAttribute ) {
  15222. state.enableAttributeAndDivisor( programAttribute, geometryAttribute.meshPerAttribute, extension );
  15223. if ( geometry.maxInstancedCount === undefined ) {
  15224. geometry.maxInstancedCount = geometryAttribute.meshPerAttribute * geometryAttribute.count;
  15225. }
  15226. } else {
  15227. state.enableAttribute( programAttribute );
  15228. }
  15229. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffer );
  15230. _gl.vertexAttribPointer( programAttribute, size, type, normalized, 0, startIndex * size * geometryAttribute.array.BYTES_PER_ELEMENT );
  15231. }
  15232. } else if ( materialDefaultAttributeValues !== undefined ) {
  15233. var value = materialDefaultAttributeValues[ name ];
  15234. if ( value !== undefined ) {
  15235. switch ( value.length ) {
  15236. case 2:
  15237. _gl.vertexAttrib2fv( programAttribute, value );
  15238. break;
  15239. case 3:
  15240. _gl.vertexAttrib3fv( programAttribute, value );
  15241. break;
  15242. case 4:
  15243. _gl.vertexAttrib4fv( programAttribute, value );
  15244. break;
  15245. default:
  15246. _gl.vertexAttrib1fv( programAttribute, value );
  15247. }
  15248. }
  15249. }
  15250. }
  15251. }
  15252. state.disableUnusedAttributes();
  15253. }
  15254. // Sorting
  15255. function absNumericalSort( a, b ) {
  15256. return Math.abs( b[ 0 ] ) - Math.abs( a[ 0 ] );
  15257. }
  15258. function painterSortStable ( a, b ) {
  15259. if ( a.object.renderOrder !== b.object.renderOrder ) {
  15260. return a.object.renderOrder - b.object.renderOrder;
  15261. } else if ( a.material.program && b.material.program && a.material.program !== b.material.program ) {
  15262. return a.material.program.id - b.material.program.id;
  15263. } else if ( a.material.id !== b.material.id ) {
  15264. return a.material.id - b.material.id;
  15265. } else if ( a.z !== b.z ) {
  15266. return a.z - b.z;
  15267. } else {
  15268. return a.id - b.id;
  15269. }
  15270. }
  15271. function reversePainterSortStable ( a, b ) {
  15272. if ( a.object.renderOrder !== b.object.renderOrder ) {
  15273. return a.object.renderOrder - b.object.renderOrder;
  15274. } if ( a.z !== b.z ) {
  15275. return b.z - a.z;
  15276. } else {
  15277. return a.id - b.id;
  15278. }
  15279. }
  15280. // Rendering
  15281. this.render = function ( scene, camera, renderTarget, forceClear ) {
  15282. if ( camera instanceof THREE.Camera === false ) {
  15283. console.error( 'THREE.WebGLRenderer.render: camera is not an instance of THREE.Camera.' );
  15284. return;
  15285. }
  15286. var fog = scene.fog;
  15287. // reset caching for this frame
  15288. _currentGeometryProgram = '';
  15289. _currentMaterialId = - 1;
  15290. _currentCamera = null;
  15291. // update scene graph
  15292. if ( scene.autoUpdate === true ) scene.updateMatrixWorld();
  15293. // update camera matrices and frustum
  15294. if ( camera.parent === null ) camera.updateMatrixWorld();
  15295. camera.matrixWorldInverse.getInverse( camera.matrixWorld );
  15296. _projScreenMatrix.multiplyMatrices( camera.projectionMatrix, camera.matrixWorldInverse );
  15297. _frustum.setFromMatrix( _projScreenMatrix );
  15298. lights.length = 0;
  15299. opaqueObjectsLastIndex = - 1;
  15300. transparentObjectsLastIndex = - 1;
  15301. sprites.length = 0;
  15302. lensFlares.length = 0;
  15303. _localClippingEnabled = this.localClippingEnabled;
  15304. _clippingEnabled = _clipping.init( this.clippingPlanes, _localClippingEnabled, camera );
  15305. projectObject( scene, camera );
  15306. opaqueObjects.length = opaqueObjectsLastIndex + 1;
  15307. transparentObjects.length = transparentObjectsLastIndex + 1;
  15308. if ( _this.sortObjects === true ) {
  15309. opaqueObjects.sort( painterSortStable );
  15310. transparentObjects.sort( reversePainterSortStable );
  15311. }
  15312. //
  15313. if ( _clippingEnabled ) _clipping.beginShadows();
  15314. setupShadows( lights );
  15315. shadowMap.render( scene, camera );
  15316. setupLights( lights, camera );
  15317. if ( _clippingEnabled ) _clipping.endShadows();
  15318. //
  15319. _infoRender.calls = 0;
  15320. _infoRender.vertices = 0;
  15321. _infoRender.faces = 0;
  15322. _infoRender.points = 0;
  15323. if ( renderTarget === undefined ) {
  15324. renderTarget = null;
  15325. }
  15326. this.setRenderTarget( renderTarget );
  15327. //
  15328. var background = scene.background;
  15329. if ( background === null ) {
  15330. glClearColor( _clearColor.r, _clearColor.g, _clearColor.b, _clearAlpha );
  15331. } else if ( background instanceof THREE.Color ) {
  15332. glClearColor( background.r, background.g, background.b, 1 );
  15333. }
  15334. if ( this.autoClear || forceClear ) {
  15335. this.clear( this.autoClearColor, this.autoClearDepth, this.autoClearStencil );
  15336. }
  15337. if ( background instanceof THREE.CubeTexture ) {
  15338. backgroundCamera2.projectionMatrix.copy( camera.projectionMatrix );
  15339. backgroundCamera2.matrixWorld.extractRotation( camera.matrixWorld );
  15340. backgroundCamera2.matrixWorldInverse.getInverse( backgroundCamera2.matrixWorld );
  15341. backgroundBoxMesh.material.uniforms[ "tCube" ].value = background;
  15342. backgroundBoxMesh.modelViewMatrix.multiplyMatrices( backgroundCamera2.matrixWorldInverse, backgroundBoxMesh.matrixWorld );
  15343. _this.renderBufferDirect( backgroundCamera2, null, backgroundBoxMesh.geometry, backgroundBoxMesh.material, backgroundBoxMesh, null );
  15344. } else if ( background instanceof THREE.Texture ) {
  15345. backgroundPlaneMesh.material.map = background;
  15346. _this.renderBufferDirect( backgroundCamera, null, backgroundPlaneMesh.geometry, backgroundPlaneMesh.material, backgroundPlaneMesh, null );
  15347. }
  15348. //
  15349. if ( scene.overrideMaterial ) {
  15350. var overrideMaterial = scene.overrideMaterial;
  15351. renderObjects( opaqueObjects, camera, fog, overrideMaterial );
  15352. renderObjects( transparentObjects, camera, fog, overrideMaterial );
  15353. } else {
  15354. // opaque pass (front-to-back order)
  15355. state.setBlending( THREE.NoBlending );
  15356. renderObjects( opaqueObjects, camera, fog );
  15357. // transparent pass (back-to-front order)
  15358. renderObjects( transparentObjects, camera, fog );
  15359. }
  15360. // custom render plugins (post pass)
  15361. spritePlugin.render( scene, camera );
  15362. lensFlarePlugin.render( scene, camera, _currentViewport );
  15363. // Generate mipmap if we're using any kind of mipmap filtering
  15364. if ( renderTarget ) {
  15365. textures.updateRenderTargetMipmap( renderTarget );
  15366. }
  15367. // Ensure depth buffer writing is enabled so it can be cleared on next render
  15368. state.setDepthTest( true );
  15369. state.setDepthWrite( true );
  15370. state.setColorWrite( true );
  15371. // _gl.finish();
  15372. };
  15373. function pushRenderItem( object, geometry, material, z, group ) {
  15374. var array, index;
  15375. // allocate the next position in the appropriate array
  15376. if ( material.transparent ) {
  15377. array = transparentObjects;
  15378. index = ++ transparentObjectsLastIndex;
  15379. } else {
  15380. array = opaqueObjects;
  15381. index = ++ opaqueObjectsLastIndex;
  15382. }
  15383. // recycle existing render item or grow the array
  15384. var renderItem = array[ index ];
  15385. if ( renderItem !== undefined ) {
  15386. renderItem.id = object.id;
  15387. renderItem.object = object;
  15388. renderItem.geometry = geometry;
  15389. renderItem.material = material;
  15390. renderItem.z = _vector3.z;
  15391. renderItem.group = group;
  15392. } else {
  15393. renderItem = {
  15394. id: object.id,
  15395. object: object,
  15396. geometry: geometry,
  15397. material: material,
  15398. z: _vector3.z,
  15399. group: group
  15400. };
  15401. // assert( index === array.length );
  15402. array.push( renderItem );
  15403. }
  15404. }
  15405. // TODO Duplicated code (Frustum)
  15406. function isObjectViewable( object ) {
  15407. var geometry = object.geometry;
  15408. if ( geometry.boundingSphere === null )
  15409. geometry.computeBoundingSphere();
  15410. _sphere.copy( geometry.boundingSphere ).
  15411. applyMatrix4( object.matrixWorld );
  15412. return isSphereViewable( _sphere );
  15413. }
  15414. function isSpriteViewable( sprite ) {
  15415. _sphere.center.set( 0, 0, 0 );
  15416. _sphere.radius = 0.7071067811865476;
  15417. _sphere.applyMatrix4( sprite.matrixWorld );
  15418. return isSphereViewable( _sphere );
  15419. }
  15420. function isSphereViewable( sphere ) {
  15421. if ( ! _frustum.intersectsSphere( sphere ) ) return false;
  15422. var numPlanes = _clipping.numPlanes;
  15423. if ( numPlanes === 0 ) return true;
  15424. var planes = _this.clippingPlanes,
  15425. center = sphere.center,
  15426. negRad = - sphere.radius,
  15427. i = 0;
  15428. do {
  15429. // out when deeper than radius in the negative halfspace
  15430. if ( planes[ i ].distanceToPoint( center ) < negRad ) return false;
  15431. } while ( ++ i !== numPlanes );
  15432. return true;
  15433. }
  15434. function projectObject( object, camera ) {
  15435. if ( object.visible === false ) return;
  15436. if ( object.layers.test( camera.layers ) ) {
  15437. if ( object instanceof THREE.Light ) {
  15438. lights.push( object );
  15439. } else if ( object instanceof THREE.Sprite ) {
  15440. if ( object.frustumCulled === false || isSpriteViewable( object ) === true ) {
  15441. sprites.push( object );
  15442. }
  15443. } else if ( object instanceof THREE.LensFlare ) {
  15444. lensFlares.push( object );
  15445. } else if ( object instanceof THREE.ImmediateRenderObject ) {
  15446. if ( _this.sortObjects === true ) {
  15447. _vector3.setFromMatrixPosition( object.matrixWorld );
  15448. _vector3.applyProjection( _projScreenMatrix );
  15449. }
  15450. pushRenderItem( object, null, object.material, _vector3.z, null );
  15451. } else if ( object instanceof THREE.Mesh || object instanceof THREE.Line || object instanceof THREE.Points ) {
  15452. if ( object instanceof THREE.SkinnedMesh ) {
  15453. object.skeleton.update();
  15454. }
  15455. if ( object.frustumCulled === false || isObjectViewable( object ) === true ) {
  15456. var material = object.material;
  15457. if ( material.visible === true ) {
  15458. if ( _this.sortObjects === true ) {
  15459. _vector3.setFromMatrixPosition( object.matrixWorld );
  15460. _vector3.applyProjection( _projScreenMatrix );
  15461. }
  15462. var geometry = objects.update( object );
  15463. if ( material instanceof THREE.MultiMaterial ) {
  15464. var groups = geometry.groups;
  15465. var materials = material.materials;
  15466. for ( var i = 0, l = groups.length; i < l; i ++ ) {
  15467. var group = groups[ i ];
  15468. var groupMaterial = materials[ group.materialIndex ];
  15469. if ( groupMaterial.visible === true ) {
  15470. pushRenderItem( object, geometry, groupMaterial, _vector3.z, group );
  15471. }
  15472. }
  15473. } else {
  15474. pushRenderItem( object, geometry, material, _vector3.z, null );
  15475. }
  15476. }
  15477. }
  15478. }
  15479. }
  15480. var children = object.children;
  15481. for ( var i = 0, l = children.length; i < l; i ++ ) {
  15482. projectObject( children[ i ], camera );
  15483. }
  15484. }
  15485. function renderObjects( renderList, camera, fog, overrideMaterial ) {
  15486. for ( var i = 0, l = renderList.length; i < l; i ++ ) {
  15487. var renderItem = renderList[ i ];
  15488. var object = renderItem.object;
  15489. var geometry = renderItem.geometry;
  15490. var material = overrideMaterial === undefined ? renderItem.material : overrideMaterial;
  15491. var group = renderItem.group;
  15492. object.modelViewMatrix.multiplyMatrices( camera.matrixWorldInverse, object.matrixWorld );
  15493. object.normalMatrix.getNormalMatrix( object.modelViewMatrix );
  15494. if ( object instanceof THREE.ImmediateRenderObject ) {
  15495. setMaterial( material );
  15496. var program = setProgram( camera, fog, material, object );
  15497. _currentGeometryProgram = '';
  15498. object.render( function ( object ) {
  15499. _this.renderBufferImmediate( object, program, material );
  15500. } );
  15501. } else {
  15502. _this.renderBufferDirect( camera, fog, geometry, material, object, group );
  15503. }
  15504. }
  15505. }
  15506. function initMaterial( material, fog, object ) {
  15507. var materialProperties = properties.get( material );
  15508. var parameters = programCache.getParameters(
  15509. material, _lights, fog, _clipping.numPlanes, object );
  15510. var code = programCache.getProgramCode( material, parameters );
  15511. var program = materialProperties.program;
  15512. var programChange = true;
  15513. if ( program === undefined ) {
  15514. // new material
  15515. material.addEventListener( 'dispose', onMaterialDispose );
  15516. } else if ( program.code !== code ) {
  15517. // changed glsl or parameters
  15518. releaseMaterialProgramReference( material );
  15519. } else if ( parameters.shaderID !== undefined ) {
  15520. // same glsl and uniform list
  15521. return;
  15522. } else {
  15523. // only rebuild uniform list
  15524. programChange = false;
  15525. }
  15526. if ( programChange ) {
  15527. if ( parameters.shaderID ) {
  15528. var shader = THREE.ShaderLib[ parameters.shaderID ];
  15529. materialProperties.__webglShader = {
  15530. name: material.type,
  15531. uniforms: THREE.UniformsUtils.clone( shader.uniforms ),
  15532. vertexShader: shader.vertexShader,
  15533. fragmentShader: shader.fragmentShader
  15534. };
  15535. } else {
  15536. materialProperties.__webglShader = {
  15537. name: material.type,
  15538. uniforms: material.uniforms,
  15539. vertexShader: material.vertexShader,
  15540. fragmentShader: material.fragmentShader
  15541. };
  15542. }
  15543. material.__webglShader = materialProperties.__webglShader;
  15544. program = programCache.acquireProgram( material, parameters, code );
  15545. materialProperties.program = program;
  15546. material.program = program;
  15547. }
  15548. var attributes = program.getAttributes();
  15549. if ( material.morphTargets ) {
  15550. material.numSupportedMorphTargets = 0;
  15551. for ( var i = 0; i < _this.maxMorphTargets; i ++ ) {
  15552. if ( attributes[ 'morphTarget' + i ] >= 0 ) {
  15553. material.numSupportedMorphTargets ++;
  15554. }
  15555. }
  15556. }
  15557. if ( material.morphNormals ) {
  15558. material.numSupportedMorphNormals = 0;
  15559. for ( var i = 0; i < _this.maxMorphNormals; i ++ ) {
  15560. if ( attributes[ 'morphNormal' + i ] >= 0 ) {
  15561. material.numSupportedMorphNormals ++;
  15562. }
  15563. }
  15564. }
  15565. var uniforms = materialProperties.__webglShader.uniforms;
  15566. if ( ! ( material instanceof THREE.ShaderMaterial ) &&
  15567. ! ( material instanceof THREE.RawShaderMaterial ) ||
  15568. material.clipping === true ) {
  15569. materialProperties.numClippingPlanes = _clipping.numPlanes;
  15570. uniforms.clippingPlanes = _clipping.uniform;
  15571. }
  15572. if ( material.lights ) {
  15573. // store the light setup it was created for
  15574. materialProperties.lightsHash = _lights.hash;
  15575. // wire up the material to this renderer's lighting state
  15576. uniforms.ambientLightColor.value = _lights.ambient;
  15577. uniforms.directionalLights.value = _lights.directional;
  15578. uniforms.spotLights.value = _lights.spot;
  15579. uniforms.pointLights.value = _lights.point;
  15580. uniforms.hemisphereLights.value = _lights.hemi;
  15581. uniforms.directionalShadowMap.value = _lights.directionalShadowMap;
  15582. uniforms.directionalShadowMatrix.value = _lights.directionalShadowMatrix;
  15583. uniforms.spotShadowMap.value = _lights.spotShadowMap;
  15584. uniforms.spotShadowMatrix.value = _lights.spotShadowMatrix;
  15585. uniforms.pointShadowMap.value = _lights.pointShadowMap;
  15586. uniforms.pointShadowMatrix.value = _lights.pointShadowMatrix;
  15587. }
  15588. var progUniforms = materialProperties.program.getUniforms(),
  15589. uniformsList =
  15590. THREE.WebGLUniforms.seqWithValue( progUniforms.seq, uniforms );
  15591. materialProperties.uniformsList = uniformsList;
  15592. materialProperties.dynamicUniforms =
  15593. THREE.WebGLUniforms.splitDynamic( uniformsList, uniforms );
  15594. }
  15595. function setMaterial( material ) {
  15596. if ( material.side !== THREE.DoubleSide )
  15597. state.enable( _gl.CULL_FACE );
  15598. else
  15599. state.disable( _gl.CULL_FACE );
  15600. state.setFlipSided( material.side === THREE.BackSide );
  15601. if ( material.transparent === true ) {
  15602. state.setBlending( material.blending, material.blendEquation, material.blendSrc, material.blendDst, material.blendEquationAlpha, material.blendSrcAlpha, material.blendDstAlpha, material.premultipliedAlpha );
  15603. } else {
  15604. state.setBlending( THREE.NoBlending );
  15605. }
  15606. state.setDepthFunc( material.depthFunc );
  15607. state.setDepthTest( material.depthTest );
  15608. state.setDepthWrite( material.depthWrite );
  15609. state.setColorWrite( material.colorWrite );
  15610. state.setPolygonOffset( material.polygonOffset, material.polygonOffsetFactor, material.polygonOffsetUnits );
  15611. }
  15612. function setProgram( camera, fog, material, object ) {
  15613. _usedTextureUnits = 0;
  15614. var materialProperties = properties.get( material );
  15615. if ( _clippingEnabled ) {
  15616. if ( _localClippingEnabled || camera !== _currentCamera ) {
  15617. var useCache =
  15618. camera === _currentCamera &&
  15619. material.id === _currentMaterialId;
  15620. // we might want to call this function with some ClippingGroup
  15621. // object instead of the material, once it becomes feasible
  15622. // (#8465, #8379)
  15623. _clipping.setState(
  15624. material.clippingPlanes, material.clipShadows,
  15625. camera, materialProperties, useCache );
  15626. }
  15627. if ( materialProperties.numClippingPlanes !== undefined &&
  15628. materialProperties.numClippingPlanes !== _clipping.numPlanes ) {
  15629. material.needsUpdate = true;
  15630. }
  15631. }
  15632. if ( materialProperties.program === undefined ) {
  15633. material.needsUpdate = true;
  15634. }
  15635. if ( materialProperties.lightsHash !== undefined &&
  15636. materialProperties.lightsHash !== _lights.hash ) {
  15637. material.needsUpdate = true;
  15638. }
  15639. if ( material.needsUpdate ) {
  15640. initMaterial( material, fog, object );
  15641. material.needsUpdate = false;
  15642. }
  15643. var refreshProgram = false;
  15644. var refreshMaterial = false;
  15645. var refreshLights = false;
  15646. var program = materialProperties.program,
  15647. p_uniforms = program.getUniforms(),
  15648. m_uniforms = materialProperties.__webglShader.uniforms;
  15649. if ( program.id !== _currentProgram ) {
  15650. _gl.useProgram( program.program );
  15651. _currentProgram = program.id;
  15652. refreshProgram = true;
  15653. refreshMaterial = true;
  15654. refreshLights = true;
  15655. }
  15656. if ( material.id !== _currentMaterialId ) {
  15657. _currentMaterialId = material.id;
  15658. refreshMaterial = true;
  15659. }
  15660. if ( refreshProgram || camera !== _currentCamera ) {
  15661. p_uniforms.set( _gl, camera, 'projectionMatrix' );
  15662. if ( capabilities.logarithmicDepthBuffer ) {
  15663. p_uniforms.setValue( _gl, 'logDepthBufFC',
  15664. 2.0 / ( Math.log( camera.far + 1.0 ) / Math.LN2 ) );
  15665. }
  15666. if ( camera !== _currentCamera ) {
  15667. _currentCamera = camera;
  15668. // lighting uniforms depend on the camera so enforce an update
  15669. // now, in case this material supports lights - or later, when
  15670. // the next material that does gets activated:
  15671. refreshMaterial = true; // set to true on material change
  15672. refreshLights = true; // remains set until update done
  15673. }
  15674. // load material specific uniforms
  15675. // (shader material also gets them for the sake of genericity)
  15676. if ( material instanceof THREE.ShaderMaterial ||
  15677. material instanceof THREE.MeshPhongMaterial ||
  15678. material instanceof THREE.MeshStandardMaterial ||
  15679. material.envMap ) {
  15680. var uCamPos = p_uniforms.map.cameraPosition;
  15681. if ( uCamPos !== undefined ) {
  15682. uCamPos.setValue( _gl,
  15683. _vector3.setFromMatrixPosition( camera.matrixWorld ) );
  15684. }
  15685. }
  15686. if ( material instanceof THREE.MeshPhongMaterial ||
  15687. material instanceof THREE.MeshLambertMaterial ||
  15688. material instanceof THREE.MeshBasicMaterial ||
  15689. material instanceof THREE.MeshStandardMaterial ||
  15690. material instanceof THREE.ShaderMaterial ||
  15691. material.skinning ) {
  15692. p_uniforms.setValue( _gl, 'viewMatrix', camera.matrixWorldInverse );
  15693. }
  15694. p_uniforms.set( _gl, _this, 'toneMappingExposure' );
  15695. p_uniforms.set( _gl, _this, 'toneMappingWhitePoint' );
  15696. }
  15697. // skinning uniforms must be set even if material didn't change
  15698. // auto-setting of texture unit for bone texture must go before other textures
  15699. // not sure why, but otherwise weird things happen
  15700. if ( material.skinning ) {
  15701. p_uniforms.setOptional( _gl, object, 'bindMatrix' );
  15702. p_uniforms.setOptional( _gl, object, 'bindMatrixInverse' );
  15703. var skeleton = object.skeleton;
  15704. if ( skeleton ) {
  15705. if ( capabilities.floatVertexTextures && skeleton.useVertexTexture ) {
  15706. p_uniforms.set( _gl, skeleton, 'boneTexture' );
  15707. p_uniforms.set( _gl, skeleton, 'boneTextureWidth' );
  15708. p_uniforms.set( _gl, skeleton, 'boneTextureHeight' );
  15709. } else {
  15710. p_uniforms.setOptional( _gl, skeleton, 'boneMatrices' );
  15711. }
  15712. }
  15713. }
  15714. if ( refreshMaterial ) {
  15715. if ( material.lights ) {
  15716. // the current material requires lighting info
  15717. // note: all lighting uniforms are always set correctly
  15718. // they simply reference the renderer's state for their
  15719. // values
  15720. //
  15721. // use the current material's .needsUpdate flags to set
  15722. // the GL state when required
  15723. markUniformsLightsNeedsUpdate( m_uniforms, refreshLights );
  15724. }
  15725. // refresh uniforms common to several materials
  15726. if ( fog && material.fog ) {
  15727. refreshUniformsFog( m_uniforms, fog );
  15728. }
  15729. if ( material instanceof THREE.MeshBasicMaterial ||
  15730. material instanceof THREE.MeshLambertMaterial ||
  15731. material instanceof THREE.MeshPhongMaterial ||
  15732. material instanceof THREE.MeshStandardMaterial ||
  15733. material instanceof THREE.MeshDepthMaterial ) {
  15734. refreshUniformsCommon( m_uniforms, material );
  15735. }
  15736. // refresh single material specific uniforms
  15737. if ( material instanceof THREE.LineBasicMaterial ) {
  15738. refreshUniformsLine( m_uniforms, material );
  15739. } else if ( material instanceof THREE.LineDashedMaterial ) {
  15740. refreshUniformsLine( m_uniforms, material );
  15741. refreshUniformsDash( m_uniforms, material );
  15742. } else if ( material instanceof THREE.PointsMaterial ) {
  15743. refreshUniformsPoints( m_uniforms, material );
  15744. } else if ( material instanceof THREE.MeshLambertMaterial ) {
  15745. refreshUniformsLambert( m_uniforms, material );
  15746. } else if ( material instanceof THREE.MeshPhongMaterial ) {
  15747. refreshUniformsPhong( m_uniforms, material );
  15748. } else if ( material instanceof THREE.MeshPhysicalMaterial ) {
  15749. refreshUniformsPhysical( m_uniforms, material );
  15750. } else if ( material instanceof THREE.MeshStandardMaterial ) {
  15751. refreshUniformsStandard( m_uniforms, material );
  15752. } else if ( material instanceof THREE.MeshDepthMaterial ) {
  15753. if ( material.displacementMap ) {
  15754. m_uniforms.displacementMap.value = material.displacementMap;
  15755. m_uniforms.displacementScale.value = material.displacementScale;
  15756. m_uniforms.displacementBias.value = material.displacementBias;
  15757. }
  15758. } else if ( material instanceof THREE.MeshNormalMaterial ) {
  15759. m_uniforms.opacity.value = material.opacity;
  15760. }
  15761. THREE.WebGLUniforms.upload(
  15762. _gl, materialProperties.uniformsList, m_uniforms, _this );
  15763. }
  15764. // common matrices
  15765. p_uniforms.set( _gl, object, 'modelViewMatrix' );
  15766. p_uniforms.set( _gl, object, 'normalMatrix' );
  15767. p_uniforms.setValue( _gl, 'modelMatrix', object.matrixWorld );
  15768. // dynamic uniforms
  15769. var dynUniforms = materialProperties.dynamicUniforms;
  15770. if ( dynUniforms !== null ) {
  15771. THREE.WebGLUniforms.evalDynamic(
  15772. dynUniforms, m_uniforms, object, camera );
  15773. THREE.WebGLUniforms.upload( _gl, dynUniforms, m_uniforms, _this );
  15774. }
  15775. return program;
  15776. }
  15777. // Uniforms (refresh uniforms objects)
  15778. function refreshUniformsCommon ( uniforms, material ) {
  15779. uniforms.opacity.value = material.opacity;
  15780. uniforms.diffuse.value = material.color;
  15781. if ( material.emissive ) {
  15782. uniforms.emissive.value.copy( material.emissive ).multiplyScalar( material.emissiveIntensity );
  15783. }
  15784. uniforms.map.value = material.map;
  15785. uniforms.specularMap.value = material.specularMap;
  15786. uniforms.alphaMap.value = material.alphaMap;
  15787. if ( material.aoMap ) {
  15788. uniforms.aoMap.value = material.aoMap;
  15789. uniforms.aoMapIntensity.value = material.aoMapIntensity;
  15790. }
  15791. // uv repeat and offset setting priorities
  15792. // 1. color map
  15793. // 2. specular map
  15794. // 3. normal map
  15795. // 4. bump map
  15796. // 5. alpha map
  15797. // 6. emissive map
  15798. var uvScaleMap;
  15799. if ( material.map ) {
  15800. uvScaleMap = material.map;
  15801. } else if ( material.specularMap ) {
  15802. uvScaleMap = material.specularMap;
  15803. } else if ( material.displacementMap ) {
  15804. uvScaleMap = material.displacementMap;
  15805. } else if ( material.normalMap ) {
  15806. uvScaleMap = material.normalMap;
  15807. } else if ( material.bumpMap ) {
  15808. uvScaleMap = material.bumpMap;
  15809. } else if ( material.roughnessMap ) {
  15810. uvScaleMap = material.roughnessMap;
  15811. } else if ( material.metalnessMap ) {
  15812. uvScaleMap = material.metalnessMap;
  15813. } else if ( material.alphaMap ) {
  15814. uvScaleMap = material.alphaMap;
  15815. } else if ( material.emissiveMap ) {
  15816. uvScaleMap = material.emissiveMap;
  15817. }
  15818. if ( uvScaleMap !== undefined ) {
  15819. // backwards compatibility
  15820. if ( uvScaleMap instanceof THREE.WebGLRenderTarget ) {
  15821. uvScaleMap = uvScaleMap.texture;
  15822. }
  15823. var offset = uvScaleMap.offset;
  15824. var repeat = uvScaleMap.repeat;
  15825. uniforms.offsetRepeat.value.set( offset.x, offset.y, repeat.x, repeat.y );
  15826. }
  15827. uniforms.envMap.value = material.envMap;
  15828. // don't flip CubeTexture envMaps, flip everything else:
  15829. // WebGLRenderTargetCube will be flipped for backwards compatibility
  15830. // WebGLRenderTargetCube.texture will be flipped because it's a Texture and NOT a CubeTexture
  15831. // this check must be handled differently, or removed entirely, if WebGLRenderTargetCube uses a CubeTexture in the future
  15832. uniforms.flipEnvMap.value = ( ! ( material.envMap instanceof THREE.CubeTexture ) ) ? 1 : - 1;
  15833. uniforms.reflectivity.value = material.reflectivity;
  15834. uniforms.refractionRatio.value = material.refractionRatio;
  15835. }
  15836. function refreshUniformsLine ( uniforms, material ) {
  15837. uniforms.diffuse.value = material.color;
  15838. uniforms.opacity.value = material.opacity;
  15839. }
  15840. function refreshUniformsDash ( uniforms, material ) {
  15841. uniforms.dashSize.value = material.dashSize;
  15842. uniforms.totalSize.value = material.dashSize + material.gapSize;
  15843. uniforms.scale.value = material.scale;
  15844. }
  15845. function refreshUniformsPoints ( uniforms, material ) {
  15846. uniforms.diffuse.value = material.color;
  15847. uniforms.opacity.value = material.opacity;
  15848. uniforms.size.value = material.size * _pixelRatio;
  15849. uniforms.scale.value = _canvas.clientHeight * 0.5;
  15850. uniforms.map.value = material.map;
  15851. if ( material.map !== null ) {
  15852. var offset = material.map.offset;
  15853. var repeat = material.map.repeat;
  15854. uniforms.offsetRepeat.value.set( offset.x, offset.y, repeat.x, repeat.y );
  15855. }
  15856. }
  15857. function refreshUniformsFog ( uniforms, fog ) {
  15858. uniforms.fogColor.value = fog.color;
  15859. if ( fog instanceof THREE.Fog ) {
  15860. uniforms.fogNear.value = fog.near;
  15861. uniforms.fogFar.value = fog.far;
  15862. } else if ( fog instanceof THREE.FogExp2 ) {
  15863. uniforms.fogDensity.value = fog.density;
  15864. }
  15865. }
  15866. function refreshUniformsLambert ( uniforms, material ) {
  15867. if ( material.lightMap ) {
  15868. uniforms.lightMap.value = material.lightMap;
  15869. uniforms.lightMapIntensity.value = material.lightMapIntensity;
  15870. }
  15871. if ( material.emissiveMap ) {
  15872. uniforms.emissiveMap.value = material.emissiveMap;
  15873. }
  15874. }
  15875. function refreshUniformsPhong ( uniforms, material ) {
  15876. uniforms.specular.value = material.specular;
  15877. uniforms.shininess.value = Math.max( material.shininess, 1e-4 ); // to prevent pow( 0.0, 0.0 )
  15878. if ( material.lightMap ) {
  15879. uniforms.lightMap.value = material.lightMap;
  15880. uniforms.lightMapIntensity.value = material.lightMapIntensity;
  15881. }
  15882. if ( material.emissiveMap ) {
  15883. uniforms.emissiveMap.value = material.emissiveMap;
  15884. }
  15885. if ( material.bumpMap ) {
  15886. uniforms.bumpMap.value = material.bumpMap;
  15887. uniforms.bumpScale.value = material.bumpScale;
  15888. }
  15889. if ( material.normalMap ) {
  15890. uniforms.normalMap.value = material.normalMap;
  15891. uniforms.normalScale.value.copy( material.normalScale );
  15892. }
  15893. if ( material.displacementMap ) {
  15894. uniforms.displacementMap.value = material.displacementMap;
  15895. uniforms.displacementScale.value = material.displacementScale;
  15896. uniforms.displacementBias.value = material.displacementBias;
  15897. }
  15898. }
  15899. function refreshUniformsStandard ( uniforms, material ) {
  15900. uniforms.roughness.value = material.roughness;
  15901. uniforms.metalness.value = material.metalness;
  15902. if ( material.roughnessMap ) {
  15903. uniforms.roughnessMap.value = material.roughnessMap;
  15904. }
  15905. if ( material.metalnessMap ) {
  15906. uniforms.metalnessMap.value = material.metalnessMap;
  15907. }
  15908. if ( material.lightMap ) {
  15909. uniforms.lightMap.value = material.lightMap;
  15910. uniforms.lightMapIntensity.value = material.lightMapIntensity;
  15911. }
  15912. if ( material.emissiveMap ) {
  15913. uniforms.emissiveMap.value = material.emissiveMap;
  15914. }
  15915. if ( material.bumpMap ) {
  15916. uniforms.bumpMap.value = material.bumpMap;
  15917. uniforms.bumpScale.value = material.bumpScale;
  15918. }
  15919. if ( material.normalMap ) {
  15920. uniforms.normalMap.value = material.normalMap;
  15921. uniforms.normalScale.value.copy( material.normalScale );
  15922. }
  15923. if ( material.displacementMap ) {
  15924. uniforms.displacementMap.value = material.displacementMap;
  15925. uniforms.displacementScale.value = material.displacementScale;
  15926. uniforms.displacementBias.value = material.displacementBias;
  15927. }
  15928. if ( material.envMap ) {
  15929. //uniforms.envMap.value = material.envMap; // part of uniforms common
  15930. uniforms.envMapIntensity.value = material.envMapIntensity;
  15931. }
  15932. }
  15933. function refreshUniformsPhysical ( uniforms, material ) {
  15934. uniforms.clearCoat.value = material.clearCoat;
  15935. uniforms.clearCoatRoughness.value = material.clearCoatRoughness;
  15936. refreshUniformsStandard( uniforms, material );
  15937. }
  15938. // If uniforms are marked as clean, they don't need to be loaded to the GPU.
  15939. function markUniformsLightsNeedsUpdate ( uniforms, value ) {
  15940. uniforms.ambientLightColor.needsUpdate = value;
  15941. uniforms.directionalLights.needsUpdate = value;
  15942. uniforms.pointLights.needsUpdate = value;
  15943. uniforms.spotLights.needsUpdate = value;
  15944. uniforms.hemisphereLights.needsUpdate = value;
  15945. }
  15946. // Lighting
  15947. function setupShadows ( lights ) {
  15948. var lightShadowsLength = 0;
  15949. for ( var i = 0, l = lights.length; i < l; i ++ ) {
  15950. var light = lights[ i ];
  15951. if ( light.castShadow ) {
  15952. _lights.shadows[ lightShadowsLength ++ ] = light;
  15953. }
  15954. }
  15955. _lights.shadows.length = lightShadowsLength;
  15956. }
  15957. function setupLights ( lights, camera ) {
  15958. var l, ll, light,
  15959. r = 0, g = 0, b = 0,
  15960. color,
  15961. intensity,
  15962. distance,
  15963. shadowMap,
  15964. viewMatrix = camera.matrixWorldInverse,
  15965. directionalLength = 0,
  15966. pointLength = 0,
  15967. spotLength = 0,
  15968. hemiLength = 0;
  15969. for ( l = 0, ll = lights.length; l < ll; l ++ ) {
  15970. light = lights[ l ];
  15971. color = light.color;
  15972. intensity = light.intensity;
  15973. distance = light.distance;
  15974. shadowMap = ( light.shadow && light.shadow.map ) ? light.shadow.map.texture : null;
  15975. if ( light instanceof THREE.AmbientLight ) {
  15976. r += color.r * intensity;
  15977. g += color.g * intensity;
  15978. b += color.b * intensity;
  15979. } else if ( light instanceof THREE.DirectionalLight ) {
  15980. var uniforms = lightCache.get( light );
  15981. uniforms.color.copy( light.color ).multiplyScalar( light.intensity );
  15982. uniforms.direction.setFromMatrixPosition( light.matrixWorld );
  15983. _vector3.setFromMatrixPosition( light.target.matrixWorld );
  15984. uniforms.direction.sub( _vector3 );
  15985. uniforms.direction.transformDirection( viewMatrix );
  15986. uniforms.shadow = light.castShadow;
  15987. if ( light.castShadow ) {
  15988. uniforms.shadowBias = light.shadow.bias;
  15989. uniforms.shadowRadius = light.shadow.radius;
  15990. uniforms.shadowMapSize = light.shadow.mapSize;
  15991. }
  15992. _lights.directionalShadowMap[ directionalLength ] = shadowMap;
  15993. _lights.directionalShadowMatrix[ directionalLength ] = light.shadow.matrix;
  15994. _lights.directional[ directionalLength ++ ] = uniforms;
  15995. } else if ( light instanceof THREE.SpotLight ) {
  15996. var uniforms = lightCache.get( light );
  15997. uniforms.position.setFromMatrixPosition( light.matrixWorld );
  15998. uniforms.position.applyMatrix4( viewMatrix );
  15999. uniforms.color.copy( color ).multiplyScalar( intensity );
  16000. uniforms.distance = distance;
  16001. uniforms.direction.setFromMatrixPosition( light.matrixWorld );
  16002. _vector3.setFromMatrixPosition( light.target.matrixWorld );
  16003. uniforms.direction.sub( _vector3 );
  16004. uniforms.direction.transformDirection( viewMatrix );
  16005. uniforms.coneCos = Math.cos( light.angle );
  16006. uniforms.penumbraCos = Math.cos( light.angle * ( 1 - light.penumbra ) );
  16007. uniforms.decay = ( light.distance === 0 ) ? 0.0 : light.decay;
  16008. uniforms.shadow = light.castShadow;
  16009. if ( light.castShadow ) {
  16010. uniforms.shadowBias = light.shadow.bias;
  16011. uniforms.shadowRadius = light.shadow.radius;
  16012. uniforms.shadowMapSize = light.shadow.mapSize;
  16013. }
  16014. _lights.spotShadowMap[ spotLength ] = shadowMap;
  16015. _lights.spotShadowMatrix[ spotLength ] = light.shadow.matrix;
  16016. _lights.spot[ spotLength ++ ] = uniforms;
  16017. } else if ( light instanceof THREE.PointLight ) {
  16018. var uniforms = lightCache.get( light );
  16019. uniforms.position.setFromMatrixPosition( light.matrixWorld );
  16020. uniforms.position.applyMatrix4( viewMatrix );
  16021. uniforms.color.copy( light.color ).multiplyScalar( light.intensity );
  16022. uniforms.distance = light.distance;
  16023. uniforms.decay = ( light.distance === 0 ) ? 0.0 : light.decay;
  16024. uniforms.shadow = light.castShadow;
  16025. if ( light.castShadow ) {
  16026. uniforms.shadowBias = light.shadow.bias;
  16027. uniforms.shadowRadius = light.shadow.radius;
  16028. uniforms.shadowMapSize = light.shadow.mapSize;
  16029. }
  16030. _lights.pointShadowMap[ pointLength ] = shadowMap;
  16031. if ( _lights.pointShadowMatrix[ pointLength ] === undefined ) {
  16032. _lights.pointShadowMatrix[ pointLength ] = new THREE.Matrix4();
  16033. }
  16034. // for point lights we set the shadow matrix to be a translation-only matrix
  16035. // equal to inverse of the light's position
  16036. _vector3.setFromMatrixPosition( light.matrixWorld ).negate();
  16037. _lights.pointShadowMatrix[ pointLength ].identity().setPosition( _vector3 );
  16038. _lights.point[ pointLength ++ ] = uniforms;
  16039. } else if ( light instanceof THREE.HemisphereLight ) {
  16040. var uniforms = lightCache.get( light );
  16041. uniforms.direction.setFromMatrixPosition( light.matrixWorld );
  16042. uniforms.direction.transformDirection( viewMatrix );
  16043. uniforms.direction.normalize();
  16044. uniforms.skyColor.copy( light.color ).multiplyScalar( intensity );
  16045. uniforms.groundColor.copy( light.groundColor ).multiplyScalar( intensity );
  16046. _lights.hemi[ hemiLength ++ ] = uniforms;
  16047. }
  16048. }
  16049. _lights.ambient[ 0 ] = r;
  16050. _lights.ambient[ 1 ] = g;
  16051. _lights.ambient[ 2 ] = b;
  16052. _lights.directional.length = directionalLength;
  16053. _lights.spot.length = spotLength;
  16054. _lights.point.length = pointLength;
  16055. _lights.hemi.length = hemiLength;
  16056. _lights.hash = directionalLength + ',' + pointLength + ',' + spotLength + ',' + hemiLength + ',' + _lights.shadows.length;
  16057. }
  16058. // GL state setting
  16059. this.setFaceCulling = function ( cullFace, frontFaceDirection ) {
  16060. state.setCullFace( cullFace );
  16061. state.setFlipSided( frontFaceDirection === THREE.FrontFaceDirectionCW );
  16062. };
  16063. // Textures
  16064. function allocTextureUnit() {
  16065. var textureUnit = _usedTextureUnits;
  16066. if ( textureUnit >= capabilities.maxTextures ) {
  16067. console.warn( 'WebGLRenderer: trying to use ' + textureUnit + ' texture units while this GPU supports only ' + capabilities.maxTextures );
  16068. }
  16069. _usedTextureUnits += 1;
  16070. return textureUnit;
  16071. }
  16072. this.allocTextureUnit = allocTextureUnit;
  16073. // this.setTexture2D = setTexture2D;
  16074. this.setTexture2D = ( function() {
  16075. var warned = false;
  16076. // backwards compatibility: peel texture.texture
  16077. return function setTexture2D( texture, slot ) {
  16078. if ( texture instanceof THREE.WebGLRenderTarget ) {
  16079. if ( ! warned ) {
  16080. console.warn( "THREE.WebGLRenderer.setTexture2D: don't use render targets as textures. Use their .texture property instead." );
  16081. warned = true;
  16082. }
  16083. texture = texture.texture;
  16084. }
  16085. textures.setTexture2D( texture, slot );
  16086. };
  16087. }() );
  16088. this.setTexture = ( function() {
  16089. var warned = false;
  16090. return function setTexture( texture, slot ) {
  16091. if ( ! warned ) {
  16092. console.warn( "THREE.WebGLRenderer: .setTexture is deprecated, use setTexture2D instead." );
  16093. warned = true;
  16094. }
  16095. textures.setTexture2D( texture, slot );
  16096. };
  16097. }() );
  16098. this.setTextureCube = ( function() {
  16099. var warned = false;
  16100. return function setTextureCube( texture, slot ) {
  16101. // backwards compatibility: peel texture.texture
  16102. if ( texture instanceof THREE.WebGLRenderTargetCube ) {
  16103. if ( ! warned ) {
  16104. console.warn( "THREE.WebGLRenderer.setTextureCube: don't use cube render targets as textures. Use their .texture property instead." );
  16105. warned = true;
  16106. }
  16107. texture = texture.texture;
  16108. }
  16109. // currently relying on the fact that WebGLRenderTargetCube.texture is a Texture and NOT a CubeTexture
  16110. // TODO: unify these code paths
  16111. if ( texture instanceof THREE.CubeTexture ||
  16112. ( Array.isArray( texture.image ) && texture.image.length === 6 ) ) {
  16113. // CompressedTexture can have Array in image :/
  16114. // this function alone should take care of cube textures
  16115. textures.setTextureCube( texture, slot );
  16116. } else {
  16117. // assumed: texture property of THREE.WebGLRenderTargetCube
  16118. textures.setTextureCubeDynamic( texture, slot );
  16119. }
  16120. };
  16121. }() );
  16122. this.getCurrentRenderTarget = function() {
  16123. return _currentRenderTarget;
  16124. };
  16125. this.setRenderTarget = function ( renderTarget ) {
  16126. _currentRenderTarget = renderTarget;
  16127. if ( renderTarget && properties.get( renderTarget ).__webglFramebuffer === undefined ) {
  16128. textures.setupRenderTarget( renderTarget );
  16129. }
  16130. var isCube = ( renderTarget instanceof THREE.WebGLRenderTargetCube );
  16131. var framebuffer;
  16132. if ( renderTarget ) {
  16133. var renderTargetProperties = properties.get( renderTarget );
  16134. if ( isCube ) {
  16135. framebuffer = renderTargetProperties.__webglFramebuffer[ renderTarget.activeCubeFace ];
  16136. } else {
  16137. framebuffer = renderTargetProperties.__webglFramebuffer;
  16138. }
  16139. _currentScissor.copy( renderTarget.scissor );
  16140. _currentScissorTest = renderTarget.scissorTest;
  16141. _currentViewport.copy( renderTarget.viewport );
  16142. } else {
  16143. framebuffer = null;
  16144. _currentScissor.copy( _scissor ).multiplyScalar( _pixelRatio );
  16145. _currentScissorTest = _scissorTest;
  16146. _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio );
  16147. }
  16148. if ( _currentFramebuffer !== framebuffer ) {
  16149. _gl.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
  16150. _currentFramebuffer = framebuffer;
  16151. }
  16152. state.scissor( _currentScissor );
  16153. state.setScissorTest( _currentScissorTest );
  16154. state.viewport( _currentViewport );
  16155. if ( isCube ) {
  16156. var textureProperties = properties.get( renderTarget.texture );
  16157. _gl.framebufferTexture2D( _gl.FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, _gl.TEXTURE_CUBE_MAP_POSITIVE_X + renderTarget.activeCubeFace, textureProperties.__webglTexture, renderTarget.activeMipMapLevel );
  16158. }
  16159. };
  16160. this.readRenderTargetPixels = function ( renderTarget, x, y, width, height, buffer ) {
  16161. if ( renderTarget instanceof THREE.WebGLRenderTarget === false ) {
  16162. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.' );
  16163. return;
  16164. }
  16165. var framebuffer = properties.get( renderTarget ).__webglFramebuffer;
  16166. if ( framebuffer ) {
  16167. var restore = false;
  16168. if ( framebuffer !== _currentFramebuffer ) {
  16169. _gl.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
  16170. restore = true;
  16171. }
  16172. try {
  16173. var texture = renderTarget.texture;
  16174. if ( texture.format !== THREE.RGBAFormat && paramThreeToGL( texture.format ) !== _gl.getParameter( _gl.IMPLEMENTATION_COLOR_READ_FORMAT ) ) {
  16175. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA or implementation defined format.' );
  16176. return;
  16177. }
  16178. if ( texture.type !== THREE.UnsignedByteType &&
  16179. paramThreeToGL( texture.type ) !== _gl.getParameter( _gl.IMPLEMENTATION_COLOR_READ_TYPE ) &&
  16180. ! ( texture.type === THREE.FloatType && extensions.get( 'WEBGL_color_buffer_float' ) ) &&
  16181. ! ( texture.type === THREE.HalfFloatType && extensions.get( 'EXT_color_buffer_half_float' ) ) ) {
  16182. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in UnsignedByteType or implementation defined type.' );
  16183. return;
  16184. }
  16185. if ( _gl.checkFramebufferStatus( _gl.FRAMEBUFFER ) === _gl.FRAMEBUFFER_COMPLETE ) {
  16186. // the following if statement ensures valid read requests (no out-of-bounds pixels, see #8604)
  16187. if ( ( x >= 0 && x <= ( renderTarget.width - width ) ) && ( y >= 0 && y <= ( renderTarget.height - height ) ) ) {
  16188. _gl.readPixels( x, y, width, height, paramThreeToGL( texture.format ), paramThreeToGL( texture.type ), buffer );
  16189. }
  16190. } else {
  16191. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: readPixels from renderTarget failed. Framebuffer not complete.' );
  16192. }
  16193. } finally {
  16194. if ( restore ) {
  16195. _gl.bindFramebuffer( _gl.FRAMEBUFFER, _currentFramebuffer );
  16196. }
  16197. }
  16198. }
  16199. };
  16200. // Map three.js constants to WebGL constants
  16201. function paramThreeToGL ( p ) {
  16202. var extension;
  16203. if ( p === THREE.RepeatWrapping ) return _gl.REPEAT;
  16204. if ( p === THREE.ClampToEdgeWrapping ) return _gl.CLAMP_TO_EDGE;
  16205. if ( p === THREE.MirroredRepeatWrapping ) return _gl.MIRRORED_REPEAT;
  16206. if ( p === THREE.NearestFilter ) return _gl.NEAREST;
  16207. if ( p === THREE.NearestMipMapNearestFilter ) return _gl.NEAREST_MIPMAP_NEAREST;
  16208. if ( p === THREE.NearestMipMapLinearFilter ) return _gl.NEAREST_MIPMAP_LINEAR;
  16209. if ( p === THREE.LinearFilter ) return _gl.LINEAR;
  16210. if ( p === THREE.LinearMipMapNearestFilter ) return _gl.LINEAR_MIPMAP_NEAREST;
  16211. if ( p === THREE.LinearMipMapLinearFilter ) return _gl.LINEAR_MIPMAP_LINEAR;
  16212. if ( p === THREE.UnsignedByteType ) return _gl.UNSIGNED_BYTE;
  16213. if ( p === THREE.UnsignedShort4444Type ) return _gl.UNSIGNED_SHORT_4_4_4_4;
  16214. if ( p === THREE.UnsignedShort5551Type ) return _gl.UNSIGNED_SHORT_5_5_5_1;
  16215. if ( p === THREE.UnsignedShort565Type ) return _gl.UNSIGNED_SHORT_5_6_5;
  16216. if ( p === THREE.ByteType ) return _gl.BYTE;
  16217. if ( p === THREE.ShortType ) return _gl.SHORT;
  16218. if ( p === THREE.UnsignedShortType ) return _gl.UNSIGNED_SHORT;
  16219. if ( p === THREE.IntType ) return _gl.INT;
  16220. if ( p === THREE.UnsignedIntType ) return _gl.UNSIGNED_INT;
  16221. if ( p === THREE.FloatType ) return _gl.FLOAT;
  16222. extension = extensions.get( 'OES_texture_half_float' );
  16223. if ( extension !== null ) {
  16224. if ( p === THREE.HalfFloatType ) return extension.HALF_FLOAT_OES;
  16225. }
  16226. if ( p === THREE.AlphaFormat ) return _gl.ALPHA;
  16227. if ( p === THREE.RGBFormat ) return _gl.RGB;
  16228. if ( p === THREE.RGBAFormat ) return _gl.RGBA;
  16229. if ( p === THREE.LuminanceFormat ) return _gl.LUMINANCE;
  16230. if ( p === THREE.LuminanceAlphaFormat ) return _gl.LUMINANCE_ALPHA;
  16231. if ( p === THREE.DepthFormat ) return _gl.DEPTH_COMPONENT;
  16232. if ( p === THREE.AddEquation ) return _gl.FUNC_ADD;
  16233. if ( p === THREE.SubtractEquation ) return _gl.FUNC_SUBTRACT;
  16234. if ( p === THREE.ReverseSubtractEquation ) return _gl.FUNC_REVERSE_SUBTRACT;
  16235. if ( p === THREE.ZeroFactor ) return _gl.ZERO;
  16236. if ( p === THREE.OneFactor ) return _gl.ONE;
  16237. if ( p === THREE.SrcColorFactor ) return _gl.SRC_COLOR;
  16238. if ( p === THREE.OneMinusSrcColorFactor ) return _gl.ONE_MINUS_SRC_COLOR;
  16239. if ( p === THREE.SrcAlphaFactor ) return _gl.SRC_ALPHA;
  16240. if ( p === THREE.OneMinusSrcAlphaFactor ) return _gl.ONE_MINUS_SRC_ALPHA;
  16241. if ( p === THREE.DstAlphaFactor ) return _gl.DST_ALPHA;
  16242. if ( p === THREE.OneMinusDstAlphaFactor ) return _gl.ONE_MINUS_DST_ALPHA;
  16243. if ( p === THREE.DstColorFactor ) return _gl.DST_COLOR;
  16244. if ( p === THREE.OneMinusDstColorFactor ) return _gl.ONE_MINUS_DST_COLOR;
  16245. if ( p === THREE.SrcAlphaSaturateFactor ) return _gl.SRC_ALPHA_SATURATE;
  16246. extension = extensions.get( 'WEBGL_compressed_texture_s3tc' );
  16247. if ( extension !== null ) {
  16248. if ( p === THREE.RGB_S3TC_DXT1_Format ) return extension.COMPRESSED_RGB_S3TC_DXT1_EXT;
  16249. if ( p === THREE.RGBA_S3TC_DXT1_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT1_EXT;
  16250. if ( p === THREE.RGBA_S3TC_DXT3_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT3_EXT;
  16251. if ( p === THREE.RGBA_S3TC_DXT5_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT5_EXT;
  16252. }
  16253. extension = extensions.get( 'WEBGL_compressed_texture_pvrtc' );
  16254. if ( extension !== null ) {
  16255. if ( p === THREE.RGB_PVRTC_4BPPV1_Format ) return extension.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;
  16256. if ( p === THREE.RGB_PVRTC_2BPPV1_Format ) return extension.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;
  16257. if ( p === THREE.RGBA_PVRTC_4BPPV1_Format ) return extension.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;
  16258. if ( p === THREE.RGBA_PVRTC_2BPPV1_Format ) return extension.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG;
  16259. }
  16260. extension = extensions.get( 'WEBGL_compressed_texture_etc1' );
  16261. if ( extension !== null ) {
  16262. if ( p === THREE.RGB_ETC1_Format ) return extension.COMPRESSED_RGB_ETC1_WEBGL;
  16263. }
  16264. extension = extensions.get( 'EXT_blend_minmax' );
  16265. if ( extension !== null ) {
  16266. if ( p === THREE.MinEquation ) return extension.MIN_EXT;
  16267. if ( p === THREE.MaxEquation ) return extension.MAX_EXT;
  16268. }
  16269. return 0;
  16270. }
  16271. };
  16272. // File:src/renderers/WebGLRenderTarget.js
  16273. /**
  16274. * @author szimek / https://github.com/szimek/
  16275. * @author alteredq / http://alteredqualia.com/
  16276. * @author Marius Kintel / https://github.com/kintel
  16277. */
  16278. /*
  16279. In options, we can specify:
  16280. * Texture parameters for an auto-generated target texture
  16281. * depthBuffer/stencilBuffer: Booleans to indicate if we should generate these buffers
  16282. */
  16283. THREE.WebGLRenderTarget = function ( width, height, options ) {
  16284. this.uuid = THREE.Math.generateUUID();
  16285. this.width = width;
  16286. this.height = height;
  16287. this.scissor = new THREE.Vector4( 0, 0, width, height );
  16288. this.scissorTest = false;
  16289. this.viewport = new THREE.Vector4( 0, 0, width, height );
  16290. options = options || {};
  16291. if ( options.minFilter === undefined ) options.minFilter = THREE.LinearFilter;
  16292. this.texture = new THREE.Texture( undefined, undefined, options.wrapS, options.wrapT, options.magFilter, options.minFilter, options.format, options.type, options.anisotropy, options.encoding );
  16293. this.depthBuffer = options.depthBuffer !== undefined ? options.depthBuffer : true;
  16294. this.stencilBuffer = options.stencilBuffer !== undefined ? options.stencilBuffer : true;
  16295. this.depthTexture = null;
  16296. };
  16297. Object.assign( THREE.WebGLRenderTarget.prototype, THREE.EventDispatcher.prototype, {
  16298. setSize: function ( width, height ) {
  16299. if ( this.width !== width || this.height !== height ) {
  16300. this.width = width;
  16301. this.height = height;
  16302. this.dispose();
  16303. }
  16304. this.viewport.set( 0, 0, width, height );
  16305. this.scissor.set( 0, 0, width, height );
  16306. },
  16307. clone: function () {
  16308. return new this.constructor().copy( this );
  16309. },
  16310. copy: function ( source ) {
  16311. this.width = source.width;
  16312. this.height = source.height;
  16313. this.viewport.copy( source.viewport );
  16314. this.texture = source.texture.clone();
  16315. this.depthBuffer = source.depthBuffer;
  16316. this.stencilBuffer = source.stencilBuffer;
  16317. this.depthTexture = source.depthTexture;
  16318. return this;
  16319. },
  16320. dispose: function () {
  16321. this.dispatchEvent( { type: 'dispose' } );
  16322. }
  16323. } );
  16324. // File:src/renderers/WebGLRenderTargetCube.js
  16325. /**
  16326. * @author alteredq / http://alteredqualia.com
  16327. */
  16328. THREE.WebGLRenderTargetCube = function ( width, height, options ) {
  16329. THREE.WebGLRenderTarget.call( this, width, height, options );
  16330. this.activeCubeFace = 0; // PX 0, NX 1, PY 2, NY 3, PZ 4, NZ 5
  16331. this.activeMipMapLevel = 0;
  16332. };
  16333. THREE.WebGLRenderTargetCube.prototype = Object.create( THREE.WebGLRenderTarget.prototype );
  16334. THREE.WebGLRenderTargetCube.prototype.constructor = THREE.WebGLRenderTargetCube;
  16335. // File:src/renderers/webgl/WebGLBufferRenderer.js
  16336. /**
  16337. * @author mrdoob / http://mrdoob.com/
  16338. */
  16339. THREE.WebGLBufferRenderer = function ( _gl, extensions, _infoRender ) {
  16340. var mode;
  16341. function setMode( value ) {
  16342. mode = value;
  16343. }
  16344. function render( start, count ) {
  16345. _gl.drawArrays( mode, start, count );
  16346. _infoRender.calls ++;
  16347. _infoRender.vertices += count;
  16348. if ( mode === _gl.TRIANGLES ) _infoRender.faces += count / 3;
  16349. }
  16350. function renderInstances( geometry ) {
  16351. var extension = extensions.get( 'ANGLE_instanced_arrays' );
  16352. if ( extension === null ) {
  16353. console.error( 'THREE.WebGLBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  16354. return;
  16355. }
  16356. var position = geometry.attributes.position;
  16357. var count = 0;
  16358. if ( position instanceof THREE.InterleavedBufferAttribute ) {
  16359. count = position.data.count;
  16360. extension.drawArraysInstancedANGLE( mode, 0, count, geometry.maxInstancedCount );
  16361. } else {
  16362. count = position.count;
  16363. extension.drawArraysInstancedANGLE( mode, 0, count, geometry.maxInstancedCount );
  16364. }
  16365. _infoRender.calls ++;
  16366. _infoRender.vertices += count * geometry.maxInstancedCount;
  16367. if ( mode === _gl.TRIANGLES ) _infoRender.faces += geometry.maxInstancedCount * count / 3;
  16368. }
  16369. this.setMode = setMode;
  16370. this.render = render;
  16371. this.renderInstances = renderInstances;
  16372. };
  16373. // File:src/renderers/webgl/WebGLClipping.js
  16374. THREE.WebGLClipping = function() {
  16375. var scope = this,
  16376. globalState = null,
  16377. numGlobalPlanes = 0,
  16378. localClippingEnabled = false,
  16379. renderingShadows = false,
  16380. plane = new THREE.Plane(),
  16381. viewNormalMatrix = new THREE.Matrix3(),
  16382. uniform = { value: null, needsUpdate: false };
  16383. this.uniform = uniform;
  16384. this.numPlanes = 0;
  16385. this.init = function( planes, enableLocalClipping, camera ) {
  16386. var enabled =
  16387. planes.length !== 0 ||
  16388. enableLocalClipping ||
  16389. // enable state of previous frame - the clipping code has to
  16390. // run another frame in order to reset the state:
  16391. numGlobalPlanes !== 0 ||
  16392. localClippingEnabled;
  16393. localClippingEnabled = enableLocalClipping;
  16394. globalState = projectPlanes( planes, camera, 0 );
  16395. numGlobalPlanes = planes.length;
  16396. return enabled;
  16397. };
  16398. this.beginShadows = function() {
  16399. renderingShadows = true;
  16400. projectPlanes( null );
  16401. };
  16402. this.endShadows = function() {
  16403. renderingShadows = false;
  16404. resetGlobalState();
  16405. };
  16406. this.setState = function( planes, clipShadows, camera, cache, fromCache ) {
  16407. if ( ! localClippingEnabled ||
  16408. planes === null || planes.length === 0 ||
  16409. renderingShadows && ! clipShadows ) {
  16410. // there's no local clipping
  16411. if ( renderingShadows ) {
  16412. // there's no global clipping
  16413. projectPlanes( null );
  16414. } else {
  16415. resetGlobalState();
  16416. }
  16417. } else {
  16418. var nGlobal = renderingShadows ? 0 : numGlobalPlanes,
  16419. lGlobal = nGlobal * 4,
  16420. dstArray = cache.clippingState || null;
  16421. uniform.value = dstArray; // ensure unique state
  16422. dstArray = projectPlanes( planes, camera, lGlobal, fromCache );
  16423. for ( var i = 0; i !== lGlobal; ++ i ) {
  16424. dstArray[ i ] = globalState[ i ];
  16425. }
  16426. cache.clippingState = dstArray;
  16427. this.numPlanes += nGlobal;
  16428. }
  16429. };
  16430. function resetGlobalState() {
  16431. if ( uniform.value !== globalState ) {
  16432. uniform.value = globalState;
  16433. uniform.needsUpdate = numGlobalPlanes > 0;
  16434. }
  16435. scope.numPlanes = numGlobalPlanes;
  16436. }
  16437. function projectPlanes( planes, camera, dstOffset, skipTransform ) {
  16438. var nPlanes = planes !== null ? planes.length : 0,
  16439. dstArray = null;
  16440. if ( nPlanes !== 0 ) {
  16441. dstArray = uniform.value;
  16442. if ( skipTransform !== true || dstArray === null ) {
  16443. var flatSize = dstOffset + nPlanes * 4,
  16444. viewMatrix = camera.matrixWorldInverse;
  16445. viewNormalMatrix.getNormalMatrix( viewMatrix );
  16446. if ( dstArray === null || dstArray.length < flatSize ) {
  16447. dstArray = new Float32Array( flatSize );
  16448. }
  16449. for ( var i = 0, i4 = dstOffset;
  16450. i !== nPlanes; ++ i, i4 += 4 ) {
  16451. plane.copy( planes[ i ] ).
  16452. applyMatrix4( viewMatrix, viewNormalMatrix );
  16453. plane.normal.toArray( dstArray, i4 );
  16454. dstArray[ i4 + 3 ] = plane.constant;
  16455. }
  16456. }
  16457. uniform.value = dstArray;
  16458. uniform.needsUpdate = true;
  16459. }
  16460. scope.numPlanes = nPlanes;
  16461. return dstArray;
  16462. }
  16463. };
  16464. // File:src/renderers/webgl/WebGLIndexedBufferRenderer.js
  16465. /**
  16466. * @author mrdoob / http://mrdoob.com/
  16467. */
  16468. THREE.WebGLIndexedBufferRenderer = function ( _gl, extensions, _infoRender ) {
  16469. var mode;
  16470. function setMode( value ) {
  16471. mode = value;
  16472. }
  16473. var type, size;
  16474. function setIndex( index ) {
  16475. if ( index.array instanceof Uint32Array && extensions.get( 'OES_element_index_uint' ) ) {
  16476. type = _gl.UNSIGNED_INT;
  16477. size = 4;
  16478. } else {
  16479. type = _gl.UNSIGNED_SHORT;
  16480. size = 2;
  16481. }
  16482. }
  16483. function render( start, count ) {
  16484. _gl.drawElements( mode, count, type, start * size );
  16485. _infoRender.calls ++;
  16486. _infoRender.vertices += count;
  16487. if ( mode === _gl.TRIANGLES ) _infoRender.faces += count / 3;
  16488. }
  16489. function renderInstances( geometry, start, count ) {
  16490. var extension = extensions.get( 'ANGLE_instanced_arrays' );
  16491. if ( extension === null ) {
  16492. console.error( 'THREE.WebGLBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  16493. return;
  16494. }
  16495. extension.drawElementsInstancedANGLE( mode, count, type, start * size, geometry.maxInstancedCount );
  16496. _infoRender.calls ++;
  16497. _infoRender.vertices += count * geometry.maxInstancedCount;
  16498. if ( mode === _gl.TRIANGLES ) _infoRender.faces += geometry.maxInstancedCount * count / 3;
  16499. }
  16500. this.setMode = setMode;
  16501. this.setIndex = setIndex;
  16502. this.render = render;
  16503. this.renderInstances = renderInstances;
  16504. };
  16505. // File:src/renderers/webgl/WebGLExtensions.js
  16506. /**
  16507. * @author mrdoob / http://mrdoob.com/
  16508. */
  16509. THREE.WebGLExtensions = function ( gl ) {
  16510. var extensions = {};
  16511. this.get = function ( name ) {
  16512. if ( extensions[ name ] !== undefined ) {
  16513. return extensions[ name ];
  16514. }
  16515. var extension;
  16516. switch ( name ) {
  16517. case 'WEBGL_depth_texture':
  16518. extension = gl.getExtension( 'WEBGL_depth_texture' ) || gl.getExtension( 'MOZ_WEBGL_depth_texture' ) || gl.getExtension( 'WEBKIT_WEBGL_depth_texture' );
  16519. break;
  16520. case 'EXT_texture_filter_anisotropic':
  16521. extension = gl.getExtension( 'EXT_texture_filter_anisotropic' ) || gl.getExtension( 'MOZ_EXT_texture_filter_anisotropic' ) || gl.getExtension( 'WEBKIT_EXT_texture_filter_anisotropic' );
  16522. break;
  16523. case 'WEBGL_compressed_texture_s3tc':
  16524. extension = gl.getExtension( 'WEBGL_compressed_texture_s3tc' ) || gl.getExtension( 'MOZ_WEBGL_compressed_texture_s3tc' ) || gl.getExtension( 'WEBKIT_WEBGL_compressed_texture_s3tc' );
  16525. break;
  16526. case 'WEBGL_compressed_texture_pvrtc':
  16527. extension = gl.getExtension( 'WEBGL_compressed_texture_pvrtc' ) || gl.getExtension( 'WEBKIT_WEBGL_compressed_texture_pvrtc' );
  16528. break;
  16529. case 'WEBGL_compressed_texture_etc1':
  16530. extension = gl.getExtension( 'WEBGL_compressed_texture_etc1' );
  16531. break;
  16532. default:
  16533. extension = gl.getExtension( name );
  16534. }
  16535. if ( extension === null ) {
  16536. console.warn( 'THREE.WebGLRenderer: ' + name + ' extension not supported.' );
  16537. }
  16538. extensions[ name ] = extension;
  16539. return extension;
  16540. };
  16541. };
  16542. // File:src/renderers/webgl/WebGLCapabilities.js
  16543. THREE.WebGLCapabilities = function ( gl, extensions, parameters ) {
  16544. var maxAnisotropy;
  16545. function getMaxAnisotropy() {
  16546. if ( maxAnisotropy !== undefined ) return maxAnisotropy;
  16547. var extension = extensions.get( 'EXT_texture_filter_anisotropic' );
  16548. if ( extension !== null ) {
  16549. maxAnisotropy = gl.getParameter( extension.MAX_TEXTURE_MAX_ANISOTROPY_EXT );
  16550. } else {
  16551. maxAnisotropy = 0;
  16552. }
  16553. return maxAnisotropy;
  16554. }
  16555. function getMaxPrecision( precision ) {
  16556. if ( precision === 'highp' ) {
  16557. if ( gl.getShaderPrecisionFormat( gl.VERTEX_SHADER, gl.HIGH_FLOAT ).precision > 0 &&
  16558. gl.getShaderPrecisionFormat( gl.FRAGMENT_SHADER, gl.HIGH_FLOAT ).precision > 0 ) {
  16559. return 'highp';
  16560. }
  16561. precision = 'mediump';
  16562. }
  16563. if ( precision === 'mediump' ) {
  16564. if ( gl.getShaderPrecisionFormat( gl.VERTEX_SHADER, gl.MEDIUM_FLOAT ).precision > 0 &&
  16565. gl.getShaderPrecisionFormat( gl.FRAGMENT_SHADER, gl.MEDIUM_FLOAT ).precision > 0 ) {
  16566. return 'mediump';
  16567. }
  16568. }
  16569. return 'lowp';
  16570. }
  16571. this.getMaxAnisotropy = getMaxAnisotropy;
  16572. this.getMaxPrecision = getMaxPrecision;
  16573. this.precision = parameters.precision !== undefined ? parameters.precision : 'highp';
  16574. this.logarithmicDepthBuffer = parameters.logarithmicDepthBuffer !== undefined ? parameters.logarithmicDepthBuffer : false;
  16575. this.maxTextures = gl.getParameter( gl.MAX_TEXTURE_IMAGE_UNITS );
  16576. this.maxVertexTextures = gl.getParameter( gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS );
  16577. this.maxTextureSize = gl.getParameter( gl.MAX_TEXTURE_SIZE );
  16578. this.maxCubemapSize = gl.getParameter( gl.MAX_CUBE_MAP_TEXTURE_SIZE );
  16579. this.maxAttributes = gl.getParameter( gl.MAX_VERTEX_ATTRIBS );
  16580. this.maxVertexUniforms = gl.getParameter( gl.MAX_VERTEX_UNIFORM_VECTORS );
  16581. this.maxVaryings = gl.getParameter( gl.MAX_VARYING_VECTORS );
  16582. this.maxFragmentUniforms = gl.getParameter( gl.MAX_FRAGMENT_UNIFORM_VECTORS );
  16583. this.vertexTextures = this.maxVertexTextures > 0;
  16584. this.floatFragmentTextures = !! extensions.get( 'OES_texture_float' );
  16585. this.floatVertexTextures = this.vertexTextures && this.floatFragmentTextures;
  16586. var _maxPrecision = getMaxPrecision( this.precision );
  16587. if ( _maxPrecision !== this.precision ) {
  16588. console.warn( 'THREE.WebGLRenderer:', this.precision, 'not supported, using', _maxPrecision, 'instead.' );
  16589. this.precision = _maxPrecision;
  16590. }
  16591. if ( this.logarithmicDepthBuffer ) {
  16592. this.logarithmicDepthBuffer = !! extensions.get( 'EXT_frag_depth' );
  16593. }
  16594. };
  16595. // File:src/renderers/webgl/WebGLGeometries.js
  16596. /**
  16597. * @author mrdoob / http://mrdoob.com/
  16598. */
  16599. THREE.WebGLGeometries = function ( gl, properties, info ) {
  16600. var geometries = {};
  16601. function get( object ) {
  16602. var geometry = object.geometry;
  16603. if ( geometries[ geometry.id ] !== undefined ) {
  16604. return geometries[ geometry.id ];
  16605. }
  16606. geometry.addEventListener( 'dispose', onGeometryDispose );
  16607. var buffergeometry;
  16608. if ( geometry instanceof THREE.BufferGeometry ) {
  16609. buffergeometry = geometry;
  16610. } else if ( geometry instanceof THREE.Geometry ) {
  16611. if ( geometry._bufferGeometry === undefined ) {
  16612. geometry._bufferGeometry = new THREE.BufferGeometry().setFromObject( object );
  16613. }
  16614. buffergeometry = geometry._bufferGeometry;
  16615. }
  16616. geometries[ geometry.id ] = buffergeometry;
  16617. info.memory.geometries ++;
  16618. return buffergeometry;
  16619. }
  16620. function onGeometryDispose( event ) {
  16621. var geometry = event.target;
  16622. var buffergeometry = geometries[ geometry.id ];
  16623. if ( buffergeometry.index !== null ) {
  16624. deleteAttribute( buffergeometry.index );
  16625. }
  16626. deleteAttributes( buffergeometry.attributes );
  16627. geometry.removeEventListener( 'dispose', onGeometryDispose );
  16628. delete geometries[ geometry.id ];
  16629. // TODO
  16630. var property = properties.get( geometry );
  16631. if ( property.wireframe ) {
  16632. deleteAttribute( property.wireframe );
  16633. }
  16634. properties.delete( geometry );
  16635. var bufferproperty = properties.get( buffergeometry );
  16636. if ( bufferproperty.wireframe ) {
  16637. deleteAttribute( bufferproperty.wireframe );
  16638. }
  16639. properties.delete( buffergeometry );
  16640. //
  16641. info.memory.geometries --;
  16642. }
  16643. function getAttributeBuffer( attribute ) {
  16644. if ( attribute instanceof THREE.InterleavedBufferAttribute ) {
  16645. return properties.get( attribute.data ).__webglBuffer;
  16646. }
  16647. return properties.get( attribute ).__webglBuffer;
  16648. }
  16649. function deleteAttribute( attribute ) {
  16650. var buffer = getAttributeBuffer( attribute );
  16651. if ( buffer !== undefined ) {
  16652. gl.deleteBuffer( buffer );
  16653. removeAttributeBuffer( attribute );
  16654. }
  16655. }
  16656. function deleteAttributes( attributes ) {
  16657. for ( var name in attributes ) {
  16658. deleteAttribute( attributes[ name ] );
  16659. }
  16660. }
  16661. function removeAttributeBuffer( attribute ) {
  16662. if ( attribute instanceof THREE.InterleavedBufferAttribute ) {
  16663. properties.delete( attribute.data );
  16664. } else {
  16665. properties.delete( attribute );
  16666. }
  16667. }
  16668. this.get = get;
  16669. };
  16670. // File:src/renderers/webgl/WebGLLights.js
  16671. /**
  16672. * @author mrdoob / http://mrdoob.com/
  16673. */
  16674. THREE.WebGLLights = function () {
  16675. var lights = {};
  16676. this.get = function ( light ) {
  16677. if ( lights[ light.id ] !== undefined ) {
  16678. return lights[ light.id ];
  16679. }
  16680. var uniforms;
  16681. switch ( light.type ) {
  16682. case 'DirectionalLight':
  16683. uniforms = {
  16684. direction: new THREE.Vector3(),
  16685. color: new THREE.Color(),
  16686. shadow: false,
  16687. shadowBias: 0,
  16688. shadowRadius: 1,
  16689. shadowMapSize: new THREE.Vector2()
  16690. };
  16691. break;
  16692. case 'SpotLight':
  16693. uniforms = {
  16694. position: new THREE.Vector3(),
  16695. direction: new THREE.Vector3(),
  16696. color: new THREE.Color(),
  16697. distance: 0,
  16698. coneCos: 0,
  16699. penumbraCos: 0,
  16700. decay: 0,
  16701. shadow: false,
  16702. shadowBias: 0,
  16703. shadowRadius: 1,
  16704. shadowMapSize: new THREE.Vector2()
  16705. };
  16706. break;
  16707. case 'PointLight':
  16708. uniforms = {
  16709. position: new THREE.Vector3(),
  16710. color: new THREE.Color(),
  16711. distance: 0,
  16712. decay: 0,
  16713. shadow: false,
  16714. shadowBias: 0,
  16715. shadowRadius: 1,
  16716. shadowMapSize: new THREE.Vector2()
  16717. };
  16718. break;
  16719. case 'HemisphereLight':
  16720. uniforms = {
  16721. direction: new THREE.Vector3(),
  16722. skyColor: new THREE.Color(),
  16723. groundColor: new THREE.Color()
  16724. };
  16725. break;
  16726. }
  16727. lights[ light.id ] = uniforms;
  16728. return uniforms;
  16729. };
  16730. };
  16731. // File:src/renderers/webgl/WebGLObjects.js
  16732. /**
  16733. * @author mrdoob / http://mrdoob.com/
  16734. */
  16735. THREE.WebGLObjects = function ( gl, properties, info ) {
  16736. var geometries = new THREE.WebGLGeometries( gl, properties, info );
  16737. //
  16738. function update( object ) {
  16739. // TODO: Avoid updating twice (when using shadowMap). Maybe add frame counter.
  16740. var geometry = geometries.get( object );
  16741. if ( object.geometry instanceof THREE.Geometry ) {
  16742. geometry.updateFromObject( object );
  16743. }
  16744. var index = geometry.index;
  16745. var attributes = geometry.attributes;
  16746. if ( index !== null ) {
  16747. updateAttribute( index, gl.ELEMENT_ARRAY_BUFFER );
  16748. }
  16749. for ( var name in attributes ) {
  16750. updateAttribute( attributes[ name ], gl.ARRAY_BUFFER );
  16751. }
  16752. // morph targets
  16753. var morphAttributes = geometry.morphAttributes;
  16754. for ( var name in morphAttributes ) {
  16755. var array = morphAttributes[ name ];
  16756. for ( var i = 0, l = array.length; i < l; i ++ ) {
  16757. updateAttribute( array[ i ], gl.ARRAY_BUFFER );
  16758. }
  16759. }
  16760. return geometry;
  16761. }
  16762. function updateAttribute( attribute, bufferType ) {
  16763. var data = ( attribute instanceof THREE.InterleavedBufferAttribute ) ? attribute.data : attribute;
  16764. var attributeProperties = properties.get( data );
  16765. if ( attributeProperties.__webglBuffer === undefined ) {
  16766. createBuffer( attributeProperties, data, bufferType );
  16767. } else if ( attributeProperties.version !== data.version ) {
  16768. updateBuffer( attributeProperties, data, bufferType );
  16769. }
  16770. }
  16771. function createBuffer( attributeProperties, data, bufferType ) {
  16772. attributeProperties.__webglBuffer = gl.createBuffer();
  16773. gl.bindBuffer( bufferType, attributeProperties.__webglBuffer );
  16774. var usage = data.dynamic ? gl.DYNAMIC_DRAW : gl.STATIC_DRAW;
  16775. gl.bufferData( bufferType, data.array, usage );
  16776. attributeProperties.version = data.version;
  16777. }
  16778. function updateBuffer( attributeProperties, data, bufferType ) {
  16779. gl.bindBuffer( bufferType, attributeProperties.__webglBuffer );
  16780. if ( data.dynamic === false || data.updateRange.count === - 1 ) {
  16781. // Not using update ranges
  16782. gl.bufferSubData( bufferType, 0, data.array );
  16783. } else if ( data.updateRange.count === 0 ) {
  16784. 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.' );
  16785. } else {
  16786. gl.bufferSubData( bufferType, data.updateRange.offset * data.array.BYTES_PER_ELEMENT,
  16787. data.array.subarray( data.updateRange.offset, data.updateRange.offset + data.updateRange.count ) );
  16788. data.updateRange.count = 0; // reset range
  16789. }
  16790. attributeProperties.version = data.version;
  16791. }
  16792. function getAttributeBuffer( attribute ) {
  16793. if ( attribute instanceof THREE.InterleavedBufferAttribute ) {
  16794. return properties.get( attribute.data ).__webglBuffer;
  16795. }
  16796. return properties.get( attribute ).__webglBuffer;
  16797. }
  16798. function getWireframeAttribute( geometry ) {
  16799. var property = properties.get( geometry );
  16800. if ( property.wireframe !== undefined ) {
  16801. return property.wireframe;
  16802. }
  16803. var indices = [];
  16804. var index = geometry.index;
  16805. var attributes = geometry.attributes;
  16806. var position = attributes.position;
  16807. // console.time( 'wireframe' );
  16808. if ( index !== null ) {
  16809. var edges = {};
  16810. var array = index.array;
  16811. for ( var i = 0, l = array.length; i < l; i += 3 ) {
  16812. var a = array[ i + 0 ];
  16813. var b = array[ i + 1 ];
  16814. var c = array[ i + 2 ];
  16815. if ( checkEdge( edges, a, b ) ) indices.push( a, b );
  16816. if ( checkEdge( edges, b, c ) ) indices.push( b, c );
  16817. if ( checkEdge( edges, c, a ) ) indices.push( c, a );
  16818. }
  16819. } else {
  16820. var array = attributes.position.array;
  16821. for ( var i = 0, l = ( array.length / 3 ) - 1; i < l; i += 3 ) {
  16822. var a = i + 0;
  16823. var b = i + 1;
  16824. var c = i + 2;
  16825. indices.push( a, b, b, c, c, a );
  16826. }
  16827. }
  16828. // console.timeEnd( 'wireframe' );
  16829. var TypeArray = position.count > 65535 ? Uint32Array : Uint16Array;
  16830. var attribute = new THREE.BufferAttribute( new TypeArray( indices ), 1 );
  16831. updateAttribute( attribute, gl.ELEMENT_ARRAY_BUFFER );
  16832. property.wireframe = attribute;
  16833. return attribute;
  16834. }
  16835. function checkEdge( edges, a, b ) {
  16836. if ( a > b ) {
  16837. var tmp = a;
  16838. a = b;
  16839. b = tmp;
  16840. }
  16841. var list = edges[ a ];
  16842. if ( list === undefined ) {
  16843. edges[ a ] = [ b ];
  16844. return true;
  16845. } else if ( list.indexOf( b ) === -1 ) {
  16846. list.push( b );
  16847. return true;
  16848. }
  16849. return false;
  16850. }
  16851. this.getAttributeBuffer = getAttributeBuffer;
  16852. this.getWireframeAttribute = getWireframeAttribute;
  16853. this.update = update;
  16854. };
  16855. // File:src/renderers/webgl/WebGLProgram.js
  16856. THREE.WebGLProgram = ( function () {
  16857. var programIdCount = 0;
  16858. function getEncodingComponents( encoding ) {
  16859. switch ( encoding ) {
  16860. case THREE.LinearEncoding:
  16861. return [ 'Linear','( value )' ];
  16862. case THREE.sRGBEncoding:
  16863. return [ 'sRGB','( value )' ];
  16864. case THREE.RGBEEncoding:
  16865. return [ 'RGBE','( value )' ];
  16866. case THREE.RGBM7Encoding:
  16867. return [ 'RGBM','( value, 7.0 )' ];
  16868. case THREE.RGBM16Encoding:
  16869. return [ 'RGBM','( value, 16.0 )' ];
  16870. case THREE.RGBDEncoding:
  16871. return [ 'RGBD','( value, 256.0 )' ];
  16872. case THREE.GammaEncoding:
  16873. return [ 'Gamma','( value, float( GAMMA_FACTOR ) )' ];
  16874. default:
  16875. throw new Error( 'unsupported encoding: ' + encoding );
  16876. }
  16877. }
  16878. function getTexelDecodingFunction( functionName, encoding ) {
  16879. var components = getEncodingComponents( encoding );
  16880. return "vec4 " + functionName + "( vec4 value ) { return " + components[ 0 ] + "ToLinear" + components[ 1 ] + "; }";
  16881. }
  16882. function getTexelEncodingFunction( functionName, encoding ) {
  16883. var components = getEncodingComponents( encoding );
  16884. return "vec4 " + functionName + "( vec4 value ) { return LinearTo" + components[ 0 ] + components[ 1 ] + "; }";
  16885. }
  16886. function getToneMappingFunction( functionName, toneMapping ) {
  16887. var toneMappingName;
  16888. switch ( toneMapping ) {
  16889. case THREE.LinearToneMapping:
  16890. toneMappingName = "Linear";
  16891. break;
  16892. case THREE.ReinhardToneMapping:
  16893. toneMappingName = "Reinhard";
  16894. break;
  16895. case THREE.Uncharted2ToneMapping:
  16896. toneMappingName = "Uncharted2";
  16897. break;
  16898. case THREE.CineonToneMapping:
  16899. toneMappingName = "OptimizedCineon";
  16900. break;
  16901. default:
  16902. throw new Error( 'unsupported toneMapping: ' + toneMapping );
  16903. }
  16904. return "vec3 " + functionName + "( vec3 color ) { return " + toneMappingName + "ToneMapping( color ); }";
  16905. }
  16906. function generateExtensions( extensions, parameters, rendererExtensions ) {
  16907. extensions = extensions || {};
  16908. var chunks = [
  16909. ( extensions.derivatives || parameters.envMapCubeUV || parameters.bumpMap || parameters.normalMap || parameters.flatShading ) ? '#extension GL_OES_standard_derivatives : enable' : '',
  16910. ( extensions.fragDepth || parameters.logarithmicDepthBuffer ) && rendererExtensions.get( 'EXT_frag_depth' ) ? '#extension GL_EXT_frag_depth : enable' : '',
  16911. ( extensions.drawBuffers ) && rendererExtensions.get( 'WEBGL_draw_buffers' ) ? '#extension GL_EXT_draw_buffers : require' : '',
  16912. ( extensions.shaderTextureLOD || parameters.envMap ) && rendererExtensions.get( 'EXT_shader_texture_lod' ) ? '#extension GL_EXT_shader_texture_lod : enable' : '',
  16913. ];
  16914. return chunks.filter( filterEmptyLine ).join( '\n' );
  16915. }
  16916. function generateDefines( defines ) {
  16917. var chunks = [];
  16918. for ( var name in defines ) {
  16919. var value = defines[ name ];
  16920. if ( value === false ) continue;
  16921. chunks.push( '#define ' + name + ' ' + value );
  16922. }
  16923. return chunks.join( '\n' );
  16924. }
  16925. function fetchAttributeLocations( gl, program, identifiers ) {
  16926. var attributes = {};
  16927. var n = gl.getProgramParameter( program, gl.ACTIVE_ATTRIBUTES );
  16928. for ( var i = 0; i < n; i ++ ) {
  16929. var info = gl.getActiveAttrib( program, i );
  16930. var name = info.name;
  16931. // console.log("THREE.WebGLProgram: ACTIVE VERTEX ATTRIBUTE:", name, i );
  16932. attributes[ name ] = gl.getAttribLocation( program, name );
  16933. }
  16934. return attributes;
  16935. }
  16936. function filterEmptyLine( string ) {
  16937. return string !== '';
  16938. }
  16939. function replaceLightNums( string, parameters ) {
  16940. return string
  16941. .replace( /NUM_DIR_LIGHTS/g, parameters.numDirLights )
  16942. .replace( /NUM_SPOT_LIGHTS/g, parameters.numSpotLights )
  16943. .replace( /NUM_POINT_LIGHTS/g, parameters.numPointLights )
  16944. .replace( /NUM_HEMI_LIGHTS/g, parameters.numHemiLights );
  16945. }
  16946. function parseIncludes( string ) {
  16947. var pattern = /#include +<([\w\d.]+)>/g;
  16948. function replace( match, include ) {
  16949. var replace = THREE.ShaderChunk[ include ];
  16950. if ( replace === undefined ) {
  16951. throw new Error( 'Can not resolve #include <' + include + '>' );
  16952. }
  16953. return parseIncludes( replace );
  16954. }
  16955. return string.replace( pattern, replace );
  16956. }
  16957. function unrollLoops( string ) {
  16958. var pattern = /for \( int i \= (\d+)\; i < (\d+)\; i \+\+ \) \{([\s\S]+?)(?=\})\}/g;
  16959. function replace( match, start, end, snippet ) {
  16960. var unroll = '';
  16961. for ( var i = parseInt( start ); i < parseInt( end ); i ++ ) {
  16962. unroll += snippet.replace( /\[ i \]/g, '[ ' + i + ' ]' );
  16963. }
  16964. return unroll;
  16965. }
  16966. return string.replace( pattern, replace );
  16967. }
  16968. return function WebGLProgram( renderer, code, material, parameters ) {
  16969. var gl = renderer.context;
  16970. var extensions = material.extensions;
  16971. var defines = material.defines;
  16972. var vertexShader = material.__webglShader.vertexShader;
  16973. var fragmentShader = material.__webglShader.fragmentShader;
  16974. var shadowMapTypeDefine = 'SHADOWMAP_TYPE_BASIC';
  16975. if ( parameters.shadowMapType === THREE.PCFShadowMap ) {
  16976. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF';
  16977. } else if ( parameters.shadowMapType === THREE.PCFSoftShadowMap ) {
  16978. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF_SOFT';
  16979. }
  16980. var envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  16981. var envMapModeDefine = 'ENVMAP_MODE_REFLECTION';
  16982. var envMapBlendingDefine = 'ENVMAP_BLENDING_MULTIPLY';
  16983. if ( parameters.envMap ) {
  16984. switch ( material.envMap.mapping ) {
  16985. case THREE.CubeReflectionMapping:
  16986. case THREE.CubeRefractionMapping:
  16987. envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  16988. break;
  16989. case THREE.CubeUVReflectionMapping:
  16990. case THREE.CubeUVRefractionMapping:
  16991. envMapTypeDefine = 'ENVMAP_TYPE_CUBE_UV';
  16992. break;
  16993. case THREE.EquirectangularReflectionMapping:
  16994. case THREE.EquirectangularRefractionMapping:
  16995. envMapTypeDefine = 'ENVMAP_TYPE_EQUIREC';
  16996. break;
  16997. case THREE.SphericalReflectionMapping:
  16998. envMapTypeDefine = 'ENVMAP_TYPE_SPHERE';
  16999. break;
  17000. }
  17001. switch ( material.envMap.mapping ) {
  17002. case THREE.CubeRefractionMapping:
  17003. case THREE.EquirectangularRefractionMapping:
  17004. envMapModeDefine = 'ENVMAP_MODE_REFRACTION';
  17005. break;
  17006. }
  17007. switch ( material.combine ) {
  17008. case THREE.MultiplyOperation:
  17009. envMapBlendingDefine = 'ENVMAP_BLENDING_MULTIPLY';
  17010. break;
  17011. case THREE.MixOperation:
  17012. envMapBlendingDefine = 'ENVMAP_BLENDING_MIX';
  17013. break;
  17014. case THREE.AddOperation:
  17015. envMapBlendingDefine = 'ENVMAP_BLENDING_ADD';
  17016. break;
  17017. }
  17018. }
  17019. var gammaFactorDefine = ( renderer.gammaFactor > 0 ) ? renderer.gammaFactor : 1.0;
  17020. // console.log( 'building new program ' );
  17021. //
  17022. var customExtensions = generateExtensions( extensions, parameters, renderer.extensions );
  17023. var customDefines = generateDefines( defines );
  17024. //
  17025. var program = gl.createProgram();
  17026. var prefixVertex, prefixFragment;
  17027. if ( material instanceof THREE.RawShaderMaterial ) {
  17028. prefixVertex = [
  17029. customDefines
  17030. ].filter( filterEmptyLine ).join( '\n' );
  17031. prefixFragment = [
  17032. customDefines
  17033. ].filter( filterEmptyLine ).join( '\n' );
  17034. } else {
  17035. prefixVertex = [
  17036. 'precision ' + parameters.precision + ' float;',
  17037. 'precision ' + parameters.precision + ' int;',
  17038. '#define SHADER_NAME ' + material.__webglShader.name,
  17039. customDefines,
  17040. parameters.supportsVertexTextures ? '#define VERTEX_TEXTURES' : '',
  17041. '#define GAMMA_FACTOR ' + gammaFactorDefine,
  17042. '#define MAX_BONES ' + parameters.maxBones,
  17043. parameters.map ? '#define USE_MAP' : '',
  17044. parameters.envMap ? '#define USE_ENVMAP' : '',
  17045. parameters.envMap ? '#define ' + envMapModeDefine : '',
  17046. parameters.lightMap ? '#define USE_LIGHTMAP' : '',
  17047. parameters.aoMap ? '#define USE_AOMAP' : '',
  17048. parameters.emissiveMap ? '#define USE_EMISSIVEMAP' : '',
  17049. parameters.bumpMap ? '#define USE_BUMPMAP' : '',
  17050. parameters.normalMap ? '#define USE_NORMALMAP' : '',
  17051. parameters.displacementMap && parameters.supportsVertexTextures ? '#define USE_DISPLACEMENTMAP' : '',
  17052. parameters.specularMap ? '#define USE_SPECULARMAP' : '',
  17053. parameters.roughnessMap ? '#define USE_ROUGHNESSMAP' : '',
  17054. parameters.metalnessMap ? '#define USE_METALNESSMAP' : '',
  17055. parameters.alphaMap ? '#define USE_ALPHAMAP' : '',
  17056. parameters.vertexColors ? '#define USE_COLOR' : '',
  17057. parameters.flatShading ? '#define FLAT_SHADED' : '',
  17058. parameters.skinning ? '#define USE_SKINNING' : '',
  17059. parameters.useVertexTexture ? '#define BONE_TEXTURE' : '',
  17060. parameters.morphTargets ? '#define USE_MORPHTARGETS' : '',
  17061. parameters.morphNormals && parameters.flatShading === false ? '#define USE_MORPHNORMALS' : '',
  17062. parameters.doubleSided ? '#define DOUBLE_SIDED' : '',
  17063. parameters.flipSided ? '#define FLIP_SIDED' : '',
  17064. '#define NUM_CLIPPING_PLANES ' + parameters.numClippingPlanes,
  17065. parameters.shadowMapEnabled ? '#define USE_SHADOWMAP' : '',
  17066. parameters.shadowMapEnabled ? '#define ' + shadowMapTypeDefine : '',
  17067. parameters.sizeAttenuation ? '#define USE_SIZEATTENUATION' : '',
  17068. parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
  17069. parameters.logarithmicDepthBuffer && renderer.extensions.get( 'EXT_frag_depth' ) ? '#define USE_LOGDEPTHBUF_EXT' : '',
  17070. 'uniform mat4 modelMatrix;',
  17071. 'uniform mat4 modelViewMatrix;',
  17072. 'uniform mat4 projectionMatrix;',
  17073. 'uniform mat4 viewMatrix;',
  17074. 'uniform mat3 normalMatrix;',
  17075. 'uniform vec3 cameraPosition;',
  17076. 'attribute vec3 position;',
  17077. 'attribute vec3 normal;',
  17078. 'attribute vec2 uv;',
  17079. '#ifdef USE_COLOR',
  17080. ' attribute vec3 color;',
  17081. '#endif',
  17082. '#ifdef USE_MORPHTARGETS',
  17083. ' attribute vec3 morphTarget0;',
  17084. ' attribute vec3 morphTarget1;',
  17085. ' attribute vec3 morphTarget2;',
  17086. ' attribute vec3 morphTarget3;',
  17087. ' #ifdef USE_MORPHNORMALS',
  17088. ' attribute vec3 morphNormal0;',
  17089. ' attribute vec3 morphNormal1;',
  17090. ' attribute vec3 morphNormal2;',
  17091. ' attribute vec3 morphNormal3;',
  17092. ' #else',
  17093. ' attribute vec3 morphTarget4;',
  17094. ' attribute vec3 morphTarget5;',
  17095. ' attribute vec3 morphTarget6;',
  17096. ' attribute vec3 morphTarget7;',
  17097. ' #endif',
  17098. '#endif',
  17099. '#ifdef USE_SKINNING',
  17100. ' attribute vec4 skinIndex;',
  17101. ' attribute vec4 skinWeight;',
  17102. '#endif',
  17103. '\n'
  17104. ].filter( filterEmptyLine ).join( '\n' );
  17105. prefixFragment = [
  17106. customExtensions,
  17107. 'precision ' + parameters.precision + ' float;',
  17108. 'precision ' + parameters.precision + ' int;',
  17109. '#define SHADER_NAME ' + material.__webglShader.name,
  17110. customDefines,
  17111. parameters.alphaTest ? '#define ALPHATEST ' + parameters.alphaTest : '',
  17112. '#define GAMMA_FACTOR ' + gammaFactorDefine,
  17113. ( parameters.useFog && parameters.fog ) ? '#define USE_FOG' : '',
  17114. ( parameters.useFog && parameters.fogExp ) ? '#define FOG_EXP2' : '',
  17115. parameters.map ? '#define USE_MAP' : '',
  17116. parameters.envMap ? '#define USE_ENVMAP' : '',
  17117. parameters.envMap ? '#define ' + envMapTypeDefine : '',
  17118. parameters.envMap ? '#define ' + envMapModeDefine : '',
  17119. parameters.envMap ? '#define ' + envMapBlendingDefine : '',
  17120. parameters.lightMap ? '#define USE_LIGHTMAP' : '',
  17121. parameters.aoMap ? '#define USE_AOMAP' : '',
  17122. parameters.emissiveMap ? '#define USE_EMISSIVEMAP' : '',
  17123. parameters.bumpMap ? '#define USE_BUMPMAP' : '',
  17124. parameters.normalMap ? '#define USE_NORMALMAP' : '',
  17125. parameters.specularMap ? '#define USE_SPECULARMAP' : '',
  17126. parameters.roughnessMap ? '#define USE_ROUGHNESSMAP' : '',
  17127. parameters.metalnessMap ? '#define USE_METALNESSMAP' : '',
  17128. parameters.alphaMap ? '#define USE_ALPHAMAP' : '',
  17129. parameters.vertexColors ? '#define USE_COLOR' : '',
  17130. parameters.flatShading ? '#define FLAT_SHADED' : '',
  17131. parameters.doubleSided ? '#define DOUBLE_SIDED' : '',
  17132. parameters.flipSided ? '#define FLIP_SIDED' : '',
  17133. '#define NUM_CLIPPING_PLANES ' + parameters.numClippingPlanes,
  17134. parameters.shadowMapEnabled ? '#define USE_SHADOWMAP' : '',
  17135. parameters.shadowMapEnabled ? '#define ' + shadowMapTypeDefine : '',
  17136. parameters.premultipliedAlpha ? "#define PREMULTIPLIED_ALPHA" : '',
  17137. parameters.physicallyCorrectLights ? "#define PHYSICALLY_CORRECT_LIGHTS" : '',
  17138. parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
  17139. parameters.logarithmicDepthBuffer && renderer.extensions.get( 'EXT_frag_depth' ) ? '#define USE_LOGDEPTHBUF_EXT' : '',
  17140. parameters.envMap && renderer.extensions.get( 'EXT_shader_texture_lod' ) ? '#define TEXTURE_LOD_EXT' : '',
  17141. 'uniform mat4 viewMatrix;',
  17142. 'uniform vec3 cameraPosition;',
  17143. ( parameters.toneMapping !== THREE.NoToneMapping ) ? "#define TONE_MAPPING" : '',
  17144. ( parameters.toneMapping !== THREE.NoToneMapping ) ? THREE.ShaderChunk[ 'tonemapping_pars_fragment' ] : '', // this code is required here because it is used by the toneMapping() function defined below
  17145. ( parameters.toneMapping !== THREE.NoToneMapping ) ? getToneMappingFunction( "toneMapping", parameters.toneMapping ) : '',
  17146. ( 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
  17147. parameters.mapEncoding ? getTexelDecodingFunction( 'mapTexelToLinear', parameters.mapEncoding ) : '',
  17148. parameters.envMapEncoding ? getTexelDecodingFunction( 'envMapTexelToLinear', parameters.envMapEncoding ) : '',
  17149. parameters.emissiveMapEncoding ? getTexelDecodingFunction( 'emissiveMapTexelToLinear', parameters.emissiveMapEncoding ) : '',
  17150. parameters.outputEncoding ? getTexelEncodingFunction( "linearToOutputTexel", parameters.outputEncoding ) : '',
  17151. parameters.depthPacking ? "#define DEPTH_PACKING " + material.depthPacking : '',
  17152. '\n'
  17153. ].filter( filterEmptyLine ).join( '\n' );
  17154. }
  17155. vertexShader = parseIncludes( vertexShader, parameters );
  17156. vertexShader = replaceLightNums( vertexShader, parameters );
  17157. fragmentShader = parseIncludes( fragmentShader, parameters );
  17158. fragmentShader = replaceLightNums( fragmentShader, parameters );
  17159. if ( material instanceof THREE.ShaderMaterial === false ) {
  17160. vertexShader = unrollLoops( vertexShader );
  17161. fragmentShader = unrollLoops( fragmentShader );
  17162. }
  17163. var vertexGlsl = prefixVertex + vertexShader;
  17164. var fragmentGlsl = prefixFragment + fragmentShader;
  17165. // console.log( '*VERTEX*', vertexGlsl );
  17166. // console.log( '*FRAGMENT*', fragmentGlsl );
  17167. var glVertexShader = THREE.WebGLShader( gl, gl.VERTEX_SHADER, vertexGlsl );
  17168. var glFragmentShader = THREE.WebGLShader( gl, gl.FRAGMENT_SHADER, fragmentGlsl );
  17169. gl.attachShader( program, glVertexShader );
  17170. gl.attachShader( program, glFragmentShader );
  17171. // Force a particular attribute to index 0.
  17172. if ( material.index0AttributeName !== undefined ) {
  17173. gl.bindAttribLocation( program, 0, material.index0AttributeName );
  17174. } else if ( parameters.morphTargets === true ) {
  17175. // programs with morphTargets displace position out of attribute 0
  17176. gl.bindAttribLocation( program, 0, 'position' );
  17177. }
  17178. gl.linkProgram( program );
  17179. var programLog = gl.getProgramInfoLog( program );
  17180. var vertexLog = gl.getShaderInfoLog( glVertexShader );
  17181. var fragmentLog = gl.getShaderInfoLog( glFragmentShader );
  17182. var runnable = true;
  17183. var haveDiagnostics = true;
  17184. // console.log( '**VERTEX**', gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( glVertexShader ) );
  17185. // console.log( '**FRAGMENT**', gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( glFragmentShader ) );
  17186. if ( gl.getProgramParameter( program, gl.LINK_STATUS ) === false ) {
  17187. runnable = false;
  17188. console.error( 'THREE.WebGLProgram: shader error: ', gl.getError(), 'gl.VALIDATE_STATUS', gl.getProgramParameter( program, gl.VALIDATE_STATUS ), 'gl.getProgramInfoLog', programLog, vertexLog, fragmentLog );
  17189. } else if ( programLog !== '' ) {
  17190. console.warn( 'THREE.WebGLProgram: gl.getProgramInfoLog()', programLog );
  17191. } else if ( vertexLog === '' || fragmentLog === '' ) {
  17192. haveDiagnostics = false;
  17193. }
  17194. if ( haveDiagnostics ) {
  17195. this.diagnostics = {
  17196. runnable: runnable,
  17197. material: material,
  17198. programLog: programLog,
  17199. vertexShader: {
  17200. log: vertexLog,
  17201. prefix: prefixVertex
  17202. },
  17203. fragmentShader: {
  17204. log: fragmentLog,
  17205. prefix: prefixFragment
  17206. }
  17207. };
  17208. }
  17209. // clean up
  17210. gl.deleteShader( glVertexShader );
  17211. gl.deleteShader( glFragmentShader );
  17212. // set up caching for uniform locations
  17213. var cachedUniforms;
  17214. this.getUniforms = function() {
  17215. if ( cachedUniforms === undefined ) {
  17216. cachedUniforms =
  17217. new THREE.WebGLUniforms( gl, program, renderer );
  17218. }
  17219. return cachedUniforms;
  17220. };
  17221. // set up caching for attribute locations
  17222. var cachedAttributes;
  17223. this.getAttributes = function() {
  17224. if ( cachedAttributes === undefined ) {
  17225. cachedAttributes = fetchAttributeLocations( gl, program );
  17226. }
  17227. return cachedAttributes;
  17228. };
  17229. // free resource
  17230. this.destroy = function() {
  17231. gl.deleteProgram( program );
  17232. this.program = undefined;
  17233. };
  17234. // DEPRECATED
  17235. Object.defineProperties( this, {
  17236. uniforms: {
  17237. get: function() {
  17238. console.warn( 'THREE.WebGLProgram: .uniforms is now .getUniforms().' );
  17239. return this.getUniforms();
  17240. }
  17241. },
  17242. attributes: {
  17243. get: function() {
  17244. console.warn( 'THREE.WebGLProgram: .attributes is now .getAttributes().' );
  17245. return this.getAttributes();
  17246. }
  17247. }
  17248. } );
  17249. //
  17250. this.id = programIdCount ++;
  17251. this.code = code;
  17252. this.usedTimes = 1;
  17253. this.program = program;
  17254. this.vertexShader = glVertexShader;
  17255. this.fragmentShader = glFragmentShader;
  17256. return this;
  17257. };
  17258. } )();
  17259. // File:src/renderers/webgl/WebGLPrograms.js
  17260. THREE.WebGLPrograms = function ( renderer, capabilities ) {
  17261. var programs = [];
  17262. var shaderIDs = {
  17263. MeshDepthMaterial: 'depth',
  17264. MeshNormalMaterial: 'normal',
  17265. MeshBasicMaterial: 'basic',
  17266. MeshLambertMaterial: 'lambert',
  17267. MeshPhongMaterial: 'phong',
  17268. MeshStandardMaterial: 'physical',
  17269. MeshPhysicalMaterial: 'physical',
  17270. LineBasicMaterial: 'basic',
  17271. LineDashedMaterial: 'dashed',
  17272. PointsMaterial: 'points'
  17273. };
  17274. var parameterNames = [
  17275. "precision", "supportsVertexTextures", "map", "mapEncoding", "envMap", "envMapMode", "envMapEncoding",
  17276. "lightMap", "aoMap", "emissiveMap", "emissiveMapEncoding", "bumpMap", "normalMap", "displacementMap", "specularMap",
  17277. "roughnessMap", "metalnessMap",
  17278. "alphaMap", "combine", "vertexColors", "fog", "useFog", "fogExp",
  17279. "flatShading", "sizeAttenuation", "logarithmicDepthBuffer", "skinning",
  17280. "maxBones", "useVertexTexture", "morphTargets", "morphNormals",
  17281. "maxMorphTargets", "maxMorphNormals", "premultipliedAlpha",
  17282. "numDirLights", "numPointLights", "numSpotLights", "numHemiLights",
  17283. "shadowMapEnabled", "shadowMapType", "toneMapping", 'physicallyCorrectLights',
  17284. "alphaTest", "doubleSided", "flipSided", "numClippingPlanes", "depthPacking"
  17285. ];
  17286. function allocateBones ( object ) {
  17287. if ( capabilities.floatVertexTextures && object && object.skeleton && object.skeleton.useVertexTexture ) {
  17288. return 1024;
  17289. } else {
  17290. // default for when object is not specified
  17291. // ( for example when prebuilding shader to be used with multiple objects )
  17292. //
  17293. // - leave some extra space for other uniforms
  17294. // - limit here is ANGLE's 254 max uniform vectors
  17295. // (up to 54 should be safe)
  17296. var nVertexUniforms = capabilities.maxVertexUniforms;
  17297. var nVertexMatrices = Math.floor( ( nVertexUniforms - 20 ) / 4 );
  17298. var maxBones = nVertexMatrices;
  17299. if ( object !== undefined && object instanceof THREE.SkinnedMesh ) {
  17300. maxBones = Math.min( object.skeleton.bones.length, maxBones );
  17301. if ( maxBones < object.skeleton.bones.length ) {
  17302. console.warn( 'WebGLRenderer: too many bones - ' + object.skeleton.bones.length + ', this GPU supports just ' + maxBones + ' (try OpenGL instead of ANGLE)' );
  17303. }
  17304. }
  17305. return maxBones;
  17306. }
  17307. }
  17308. function getTextureEncodingFromMap( map, gammaOverrideLinear ) {
  17309. var encoding;
  17310. if ( ! map ) {
  17311. encoding = THREE.LinearEncoding;
  17312. } else if ( map instanceof THREE.Texture ) {
  17313. encoding = map.encoding;
  17314. } else if ( map instanceof THREE.WebGLRenderTarget ) {
  17315. console.warn( "THREE.WebGLPrograms.getTextureEncodingFromMap: don't use render targets as textures. Use their .texture property instead." );
  17316. encoding = map.texture.encoding;
  17317. }
  17318. // add backwards compatibility for WebGLRenderer.gammaInput/gammaOutput parameter, should probably be removed at some point.
  17319. if ( encoding === THREE.LinearEncoding && gammaOverrideLinear ) {
  17320. encoding = THREE.GammaEncoding;
  17321. }
  17322. return encoding;
  17323. }
  17324. this.getParameters = function ( material, lights, fog, nClipPlanes, object ) {
  17325. var shaderID = shaderIDs[ material.type ];
  17326. // heuristics to create shader parameters according to lights in the scene
  17327. // (not to blow over maxLights budget)
  17328. var maxBones = allocateBones( object );
  17329. var precision = renderer.getPrecision();
  17330. if ( material.precision !== null ) {
  17331. precision = capabilities.getMaxPrecision( material.precision );
  17332. if ( precision !== material.precision ) {
  17333. console.warn( 'THREE.WebGLProgram.getParameters:', material.precision, 'not supported, using', precision, 'instead.' );
  17334. }
  17335. }
  17336. var currentRenderTarget = renderer.getCurrentRenderTarget();
  17337. var parameters = {
  17338. shaderID: shaderID,
  17339. precision: precision,
  17340. supportsVertexTextures: capabilities.vertexTextures,
  17341. outputEncoding: getTextureEncodingFromMap( ( ! currentRenderTarget ) ? null : currentRenderTarget.texture, renderer.gammaOutput ),
  17342. map: !! material.map,
  17343. mapEncoding: getTextureEncodingFromMap( material.map, renderer.gammaInput ),
  17344. envMap: !! material.envMap,
  17345. envMapMode: material.envMap && material.envMap.mapping,
  17346. envMapEncoding: getTextureEncodingFromMap( material.envMap, renderer.gammaInput ),
  17347. envMapCubeUV: ( !! material.envMap ) && ( ( material.envMap.mapping === THREE.CubeUVReflectionMapping ) || ( material.envMap.mapping === THREE.CubeUVRefractionMapping ) ),
  17348. lightMap: !! material.lightMap,
  17349. aoMap: !! material.aoMap,
  17350. emissiveMap: !! material.emissiveMap,
  17351. emissiveMapEncoding: getTextureEncodingFromMap( material.emissiveMap, renderer.gammaInput ),
  17352. bumpMap: !! material.bumpMap,
  17353. normalMap: !! material.normalMap,
  17354. displacementMap: !! material.displacementMap,
  17355. roughnessMap: !! material.roughnessMap,
  17356. metalnessMap: !! material.metalnessMap,
  17357. specularMap: !! material.specularMap,
  17358. alphaMap: !! material.alphaMap,
  17359. combine: material.combine,
  17360. vertexColors: material.vertexColors,
  17361. fog: fog,
  17362. useFog: material.fog,
  17363. fogExp: fog instanceof THREE.FogExp2,
  17364. flatShading: material.shading === THREE.FlatShading,
  17365. sizeAttenuation: material.sizeAttenuation,
  17366. logarithmicDepthBuffer: capabilities.logarithmicDepthBuffer,
  17367. skinning: material.skinning,
  17368. maxBones: maxBones,
  17369. useVertexTexture: capabilities.floatVertexTextures && object && object.skeleton && object.skeleton.useVertexTexture,
  17370. morphTargets: material.morphTargets,
  17371. morphNormals: material.morphNormals,
  17372. maxMorphTargets: renderer.maxMorphTargets,
  17373. maxMorphNormals: renderer.maxMorphNormals,
  17374. numDirLights: lights.directional.length,
  17375. numPointLights: lights.point.length,
  17376. numSpotLights: lights.spot.length,
  17377. numHemiLights: lights.hemi.length,
  17378. numClippingPlanes: nClipPlanes,
  17379. shadowMapEnabled: renderer.shadowMap.enabled && object.receiveShadow && lights.shadows.length > 0,
  17380. shadowMapType: renderer.shadowMap.type,
  17381. toneMapping: renderer.toneMapping,
  17382. physicallyCorrectLights: renderer.physicallyCorrectLights,
  17383. premultipliedAlpha: material.premultipliedAlpha,
  17384. alphaTest: material.alphaTest,
  17385. doubleSided: material.side === THREE.DoubleSide,
  17386. flipSided: material.side === THREE.BackSide,
  17387. depthPacking: ( material.depthPacking !== undefined ) ? material.depthPacking : false
  17388. };
  17389. return parameters;
  17390. };
  17391. this.getProgramCode = function ( material, parameters ) {
  17392. var array = [];
  17393. if ( parameters.shaderID ) {
  17394. array.push( parameters.shaderID );
  17395. } else {
  17396. array.push( material.fragmentShader );
  17397. array.push( material.vertexShader );
  17398. }
  17399. if ( material.defines !== undefined ) {
  17400. for ( var name in material.defines ) {
  17401. array.push( name );
  17402. array.push( material.defines[ name ] );
  17403. }
  17404. }
  17405. for ( var i = 0; i < parameterNames.length; i ++ ) {
  17406. array.push( parameters[ parameterNames[ i ] ] );
  17407. }
  17408. return array.join();
  17409. };
  17410. this.acquireProgram = function ( material, parameters, code ) {
  17411. var program;
  17412. // Check if code has been already compiled
  17413. for ( var p = 0, pl = programs.length; p < pl; p ++ ) {
  17414. var programInfo = programs[ p ];
  17415. if ( programInfo.code === code ) {
  17416. program = programInfo;
  17417. ++ program.usedTimes;
  17418. break;
  17419. }
  17420. }
  17421. if ( program === undefined ) {
  17422. program = new THREE.WebGLProgram( renderer, code, material, parameters );
  17423. programs.push( program );
  17424. }
  17425. return program;
  17426. };
  17427. this.releaseProgram = function( program ) {
  17428. if ( -- program.usedTimes === 0 ) {
  17429. // Remove from unordered set
  17430. var i = programs.indexOf( program );
  17431. programs[ i ] = programs[ programs.length - 1 ];
  17432. programs.pop();
  17433. // Free WebGL resources
  17434. program.destroy();
  17435. }
  17436. };
  17437. // Exposed for resource monitoring & error feedback via renderer.info:
  17438. this.programs = programs;
  17439. };
  17440. // File:src/renderers/webgl/WebGLProperties.js
  17441. /**
  17442. * @author fordacious / fordacious.github.io
  17443. */
  17444. THREE.WebGLProperties = function () {
  17445. var properties = {};
  17446. this.get = function ( object ) {
  17447. var uuid = object.uuid;
  17448. var map = properties[ uuid ];
  17449. if ( map === undefined ) {
  17450. map = {};
  17451. properties[ uuid ] = map;
  17452. }
  17453. return map;
  17454. };
  17455. this.delete = function ( object ) {
  17456. delete properties[ object.uuid ];
  17457. };
  17458. this.clear = function () {
  17459. properties = {};
  17460. };
  17461. };
  17462. // File:src/renderers/webgl/WebGLShader.js
  17463. THREE.WebGLShader = ( function () {
  17464. function addLineNumbers( string ) {
  17465. var lines = string.split( '\n' );
  17466. for ( var i = 0; i < lines.length; i ++ ) {
  17467. lines[ i ] = ( i + 1 ) + ': ' + lines[ i ];
  17468. }
  17469. return lines.join( '\n' );
  17470. }
  17471. return function WebGLShader( gl, type, string ) {
  17472. var shader = gl.createShader( type );
  17473. gl.shaderSource( shader, string );
  17474. gl.compileShader( shader );
  17475. if ( gl.getShaderParameter( shader, gl.COMPILE_STATUS ) === false ) {
  17476. console.error( 'THREE.WebGLShader: Shader couldn\'t compile.' );
  17477. }
  17478. if ( gl.getShaderInfoLog( shader ) !== '' ) {
  17479. console.warn( 'THREE.WebGLShader: gl.getShaderInfoLog()', type === gl.VERTEX_SHADER ? 'vertex' : 'fragment', gl.getShaderInfoLog( shader ), addLineNumbers( string ) );
  17480. }
  17481. // --enable-privileged-webgl-extension
  17482. // console.log( type, gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( shader ) );
  17483. return shader;
  17484. };
  17485. } )();
  17486. // File:src/renderers/webgl/WebGLShadowMap.js
  17487. /**
  17488. * @author alteredq / http://alteredqualia.com/
  17489. * @author mrdoob / http://mrdoob.com/
  17490. */
  17491. THREE.WebGLShadowMap = function ( _renderer, _lights, _objects ) {
  17492. var _gl = _renderer.context,
  17493. _state = _renderer.state,
  17494. _frustum = new THREE.Frustum(),
  17495. _projScreenMatrix = new THREE.Matrix4(),
  17496. _lightShadows = _lights.shadows,
  17497. _shadowMapSize = new THREE.Vector2(),
  17498. _lookTarget = new THREE.Vector3(),
  17499. _lightPositionWorld = new THREE.Vector3(),
  17500. _renderList = [],
  17501. _MorphingFlag = 1,
  17502. _SkinningFlag = 2,
  17503. _NumberOfMaterialVariants = ( _MorphingFlag | _SkinningFlag ) + 1,
  17504. _depthMaterials = new Array( _NumberOfMaterialVariants ),
  17505. _distanceMaterials = new Array( _NumberOfMaterialVariants ),
  17506. _materialCache = {};
  17507. var cubeDirections = [
  17508. new THREE.Vector3( 1, 0, 0 ), new THREE.Vector3( - 1, 0, 0 ), new THREE.Vector3( 0, 0, 1 ),
  17509. new THREE.Vector3( 0, 0, - 1 ), new THREE.Vector3( 0, 1, 0 ), new THREE.Vector3( 0, - 1, 0 )
  17510. ];
  17511. var cubeUps = [
  17512. new THREE.Vector3( 0, 1, 0 ), new THREE.Vector3( 0, 1, 0 ), new THREE.Vector3( 0, 1, 0 ),
  17513. new THREE.Vector3( 0, 1, 0 ), new THREE.Vector3( 0, 0, 1 ), new THREE.Vector3( 0, 0, - 1 )
  17514. ];
  17515. var cube2DViewPorts = [
  17516. new THREE.Vector4(), new THREE.Vector4(), new THREE.Vector4(),
  17517. new THREE.Vector4(), new THREE.Vector4(), new THREE.Vector4()
  17518. ];
  17519. // init
  17520. var depthMaterialTemplate = new THREE.MeshDepthMaterial();
  17521. depthMaterialTemplate.depthPacking = THREE.RGBADepthPacking;
  17522. depthMaterialTemplate.clipping = true;
  17523. var distanceShader = THREE.ShaderLib[ "distanceRGBA" ];
  17524. var distanceUniforms = THREE.UniformsUtils.clone( distanceShader.uniforms );
  17525. for ( var i = 0; i !== _NumberOfMaterialVariants; ++ i ) {
  17526. var useMorphing = ( i & _MorphingFlag ) !== 0;
  17527. var useSkinning = ( i & _SkinningFlag ) !== 0;
  17528. var depthMaterial = depthMaterialTemplate.clone();
  17529. depthMaterial.morphTargets = useMorphing;
  17530. depthMaterial.skinning = useSkinning;
  17531. _depthMaterials[ i ] = depthMaterial;
  17532. var distanceMaterial = new THREE.ShaderMaterial( {
  17533. defines: {
  17534. 'USE_SHADOWMAP': ''
  17535. },
  17536. uniforms: distanceUniforms,
  17537. vertexShader: distanceShader.vertexShader,
  17538. fragmentShader: distanceShader.fragmentShader,
  17539. morphTargets: useMorphing,
  17540. skinning: useSkinning,
  17541. clipping: true
  17542. } );
  17543. _distanceMaterials[ i ] = distanceMaterial;
  17544. }
  17545. //
  17546. var scope = this;
  17547. this.enabled = false;
  17548. this.autoUpdate = true;
  17549. this.needsUpdate = false;
  17550. this.type = THREE.PCFShadowMap;
  17551. this.renderReverseSided = true;
  17552. this.renderSingleSided = true;
  17553. this.render = function ( scene, camera ) {
  17554. if ( scope.enabled === false ) return;
  17555. if ( scope.autoUpdate === false && scope.needsUpdate === false ) return;
  17556. if ( _lightShadows.length === 0 ) return;
  17557. // Set GL state for depth map.
  17558. _state.clearColor( 1, 1, 1, 1 );
  17559. _state.disable( _gl.BLEND );
  17560. _state.setDepthTest( true );
  17561. _state.setScissorTest( false );
  17562. // render depth map
  17563. var faceCount, isPointLight;
  17564. for ( var i = 0, il = _lightShadows.length; i < il; i ++ ) {
  17565. var light = _lightShadows[ i ];
  17566. var shadow = light.shadow;
  17567. if ( shadow === undefined ) {
  17568. console.warn( 'THREE.WebGLShadowMap:', light, 'has no shadow.' );
  17569. continue;
  17570. }
  17571. var shadowCamera = shadow.camera;
  17572. _shadowMapSize.copy( shadow.mapSize );
  17573. if ( light instanceof THREE.PointLight ) {
  17574. faceCount = 6;
  17575. isPointLight = true;
  17576. var vpWidth = _shadowMapSize.x;
  17577. var vpHeight = _shadowMapSize.y;
  17578. // These viewports map a cube-map onto a 2D texture with the
  17579. // following orientation:
  17580. //
  17581. // xzXZ
  17582. // y Y
  17583. //
  17584. // X - Positive x direction
  17585. // x - Negative x direction
  17586. // Y - Positive y direction
  17587. // y - Negative y direction
  17588. // Z - Positive z direction
  17589. // z - Negative z direction
  17590. // positive X
  17591. cube2DViewPorts[ 0 ].set( vpWidth * 2, vpHeight, vpWidth, vpHeight );
  17592. // negative X
  17593. cube2DViewPorts[ 1 ].set( 0, vpHeight, vpWidth, vpHeight );
  17594. // positive Z
  17595. cube2DViewPorts[ 2 ].set( vpWidth * 3, vpHeight, vpWidth, vpHeight );
  17596. // negative Z
  17597. cube2DViewPorts[ 3 ].set( vpWidth, vpHeight, vpWidth, vpHeight );
  17598. // positive Y
  17599. cube2DViewPorts[ 4 ].set( vpWidth * 3, 0, vpWidth, vpHeight );
  17600. // negative Y
  17601. cube2DViewPorts[ 5 ].set( vpWidth, 0, vpWidth, vpHeight );
  17602. _shadowMapSize.x *= 4.0;
  17603. _shadowMapSize.y *= 2.0;
  17604. } else {
  17605. faceCount = 1;
  17606. isPointLight = false;
  17607. }
  17608. if ( shadow.map === null ) {
  17609. var pars = { minFilter: THREE.NearestFilter, magFilter: THREE.NearestFilter, format: THREE.RGBAFormat };
  17610. shadow.map = new THREE.WebGLRenderTarget( _shadowMapSize.x, _shadowMapSize.y, pars );
  17611. shadowCamera.updateProjectionMatrix();
  17612. }
  17613. if ( shadow instanceof THREE.SpotLightShadow ) {
  17614. shadow.update( light );
  17615. }
  17616. var shadowMap = shadow.map;
  17617. var shadowMatrix = shadow.matrix;
  17618. _lightPositionWorld.setFromMatrixPosition( light.matrixWorld );
  17619. shadowCamera.position.copy( _lightPositionWorld );
  17620. _renderer.setRenderTarget( shadowMap );
  17621. _renderer.clear();
  17622. // render shadow map for each cube face (if omni-directional) or
  17623. // run a single pass if not
  17624. for ( var face = 0; face < faceCount; face ++ ) {
  17625. if ( isPointLight ) {
  17626. _lookTarget.copy( shadowCamera.position );
  17627. _lookTarget.add( cubeDirections[ face ] );
  17628. shadowCamera.up.copy( cubeUps[ face ] );
  17629. shadowCamera.lookAt( _lookTarget );
  17630. var vpDimensions = cube2DViewPorts[ face ];
  17631. _state.viewport( vpDimensions );
  17632. } else {
  17633. _lookTarget.setFromMatrixPosition( light.target.matrixWorld );
  17634. shadowCamera.lookAt( _lookTarget );
  17635. }
  17636. shadowCamera.updateMatrixWorld();
  17637. shadowCamera.matrixWorldInverse.getInverse( shadowCamera.matrixWorld );
  17638. // compute shadow matrix
  17639. shadowMatrix.set(
  17640. 0.5, 0.0, 0.0, 0.5,
  17641. 0.0, 0.5, 0.0, 0.5,
  17642. 0.0, 0.0, 0.5, 0.5,
  17643. 0.0, 0.0, 0.0, 1.0
  17644. );
  17645. shadowMatrix.multiply( shadowCamera.projectionMatrix );
  17646. shadowMatrix.multiply( shadowCamera.matrixWorldInverse );
  17647. // update camera matrices and frustum
  17648. _projScreenMatrix.multiplyMatrices( shadowCamera.projectionMatrix, shadowCamera.matrixWorldInverse );
  17649. _frustum.setFromMatrix( _projScreenMatrix );
  17650. // set object matrices & frustum culling
  17651. _renderList.length = 0;
  17652. projectObject( scene, camera, shadowCamera );
  17653. // render shadow map
  17654. // render regular objects
  17655. for ( var j = 0, jl = _renderList.length; j < jl; j ++ ) {
  17656. var object = _renderList[ j ];
  17657. var geometry = _objects.update( object );
  17658. var material = object.material;
  17659. if ( material instanceof THREE.MultiMaterial ) {
  17660. var groups = geometry.groups;
  17661. var materials = material.materials;
  17662. for ( var k = 0, kl = groups.length; k < kl; k ++ ) {
  17663. var group = groups[ k ];
  17664. var groupMaterial = materials[ group.materialIndex ];
  17665. if ( groupMaterial.visible === true ) {
  17666. var depthMaterial = getDepthMaterial( object, groupMaterial, isPointLight, _lightPositionWorld );
  17667. _renderer.renderBufferDirect( shadowCamera, null, geometry, depthMaterial, object, group );
  17668. }
  17669. }
  17670. } else {
  17671. var depthMaterial = getDepthMaterial( object, material, isPointLight, _lightPositionWorld );
  17672. _renderer.renderBufferDirect( shadowCamera, null, geometry, depthMaterial, object, null );
  17673. }
  17674. }
  17675. }
  17676. }
  17677. // Restore GL state.
  17678. var clearColor = _renderer.getClearColor(),
  17679. clearAlpha = _renderer.getClearAlpha();
  17680. _renderer.setClearColor( clearColor, clearAlpha );
  17681. scope.needsUpdate = false;
  17682. };
  17683. function getDepthMaterial( object, material, isPointLight, lightPositionWorld ) {
  17684. var geometry = object.geometry;
  17685. var result = null;
  17686. var materialVariants = _depthMaterials;
  17687. var customMaterial = object.customDepthMaterial;
  17688. if ( isPointLight ) {
  17689. materialVariants = _distanceMaterials;
  17690. customMaterial = object.customDistanceMaterial;
  17691. }
  17692. if ( ! customMaterial ) {
  17693. var useMorphing = geometry.morphTargets !== undefined &&
  17694. geometry.morphTargets.length > 0 && material.morphTargets;
  17695. var useSkinning = object instanceof THREE.SkinnedMesh && material.skinning;
  17696. var variantIndex = 0;
  17697. if ( useMorphing ) variantIndex |= _MorphingFlag;
  17698. if ( useSkinning ) variantIndex |= _SkinningFlag;
  17699. result = materialVariants[ variantIndex ];
  17700. } else {
  17701. result = customMaterial;
  17702. }
  17703. if ( _renderer.localClippingEnabled &&
  17704. material.clipShadows === true &&
  17705. material.clippingPlanes.length !== 0 ) {
  17706. // in this case we need a unique material instance reflecting the
  17707. // appropriate state
  17708. var keyA = result.uuid, keyB = material.uuid;
  17709. var materialsForVariant = _materialCache[ keyA ];
  17710. if ( materialsForVariant === undefined ) {
  17711. materialsForVariant = {};
  17712. _materialCache[ keyA ] = materialsForVariant;
  17713. }
  17714. var cachedMaterial = materialsForVariant[ keyB ];
  17715. if ( cachedMaterial === undefined ) {
  17716. cachedMaterial = result.clone();
  17717. materialsForVariant[ keyB ] = cachedMaterial;
  17718. }
  17719. result = cachedMaterial;
  17720. }
  17721. result.visible = material.visible;
  17722. result.wireframe = material.wireframe;
  17723. var side = material.side;
  17724. if ( scope.renderSingleSided && side == THREE.DoubleSide ) {
  17725. side = THREE.FrontSide;
  17726. }
  17727. if ( scope.renderReverseSided ) {
  17728. if ( side === THREE.FrontSide ) side = THREE.BackSide;
  17729. else if ( side === THREE.BackSide ) side = THREE.FrontSide;
  17730. }
  17731. result.side = side;
  17732. result.clipShadows = material.clipShadows;
  17733. result.clippingPlanes = material.clippingPlanes;
  17734. result.wireframeLinewidth = material.wireframeLinewidth;
  17735. result.linewidth = material.linewidth;
  17736. if ( isPointLight && result.uniforms.lightPos !== undefined ) {
  17737. result.uniforms.lightPos.value.copy( lightPositionWorld );
  17738. }
  17739. return result;
  17740. }
  17741. function projectObject( object, camera, shadowCamera ) {
  17742. if ( object.visible === false ) return;
  17743. if ( object.layers.test( camera.layers ) && ( object instanceof THREE.Mesh || object instanceof THREE.Line || object instanceof THREE.Points ) ) {
  17744. if ( object.castShadow && ( object.frustumCulled === false || _frustum.intersectsObject( object ) === true ) ) {
  17745. var material = object.material;
  17746. if ( material.visible === true ) {
  17747. object.modelViewMatrix.multiplyMatrices( shadowCamera.matrixWorldInverse, object.matrixWorld );
  17748. _renderList.push( object );
  17749. }
  17750. }
  17751. }
  17752. var children = object.children;
  17753. for ( var i = 0, l = children.length; i < l; i ++ ) {
  17754. projectObject( children[ i ], camera, shadowCamera );
  17755. }
  17756. }
  17757. };
  17758. // File:src/renderers/webgl/WebGLState.js
  17759. /**
  17760. * @author mrdoob / http://mrdoob.com/
  17761. */
  17762. THREE.WebGLState = function ( gl, extensions, paramThreeToGL ) {
  17763. var _this = this;
  17764. this.buffers = {
  17765. color: new THREE.WebGLColorBuffer( gl, this ),
  17766. depth: new THREE.WebGLDepthBuffer( gl, this ),
  17767. stencil: new THREE.WebGLStencilBuffer( gl, this )
  17768. };
  17769. var maxVertexAttributes = gl.getParameter( gl.MAX_VERTEX_ATTRIBS );
  17770. var newAttributes = new Uint8Array( maxVertexAttributes );
  17771. var enabledAttributes = new Uint8Array( maxVertexAttributes );
  17772. var attributeDivisors = new Uint8Array( maxVertexAttributes );
  17773. var capabilities = {};
  17774. var compressedTextureFormats = null;
  17775. var currentBlending = null;
  17776. var currentBlendEquation = null;
  17777. var currentBlendSrc = null;
  17778. var currentBlendDst = null;
  17779. var currentBlendEquationAlpha = null;
  17780. var currentBlendSrcAlpha = null;
  17781. var currentBlendDstAlpha = null;
  17782. var currentPremultipledAlpha = false;
  17783. var currentFlipSided = null;
  17784. var currentCullFace = null;
  17785. var currentLineWidth = null;
  17786. var currentPolygonOffsetFactor = null;
  17787. var currentPolygonOffsetUnits = null;
  17788. var currentScissorTest = null;
  17789. var maxTextures = gl.getParameter( gl.MAX_TEXTURE_IMAGE_UNITS );
  17790. var currentTextureSlot = null;
  17791. var currentBoundTextures = {};
  17792. var currentScissor = new THREE.Vector4();
  17793. var currentViewport = new THREE.Vector4();
  17794. function createTexture( type, target, count ) {
  17795. var data = new Uint8Array( 4 ); // 4 is required to match default unpack alignment of 4.
  17796. var texture = gl.createTexture();
  17797. gl.bindTexture( type, texture );
  17798. gl.texParameteri( type, gl.TEXTURE_MIN_FILTER, gl.NEAREST );
  17799. gl.texParameteri( type, gl.TEXTURE_MAG_FILTER, gl.NEAREST );
  17800. for ( var i = 0; i < count; i ++ ) {
  17801. gl.texImage2D( target + i, 0, gl.RGBA, 1, 1, 0, gl.RGBA, gl.UNSIGNED_BYTE, data );
  17802. }
  17803. return texture;
  17804. }
  17805. var emptyTextures = {};
  17806. emptyTextures[ gl.TEXTURE_2D ] = createTexture( gl.TEXTURE_2D, gl.TEXTURE_2D, 1 );
  17807. emptyTextures[ gl.TEXTURE_CUBE_MAP ] = createTexture( gl.TEXTURE_CUBE_MAP, gl.TEXTURE_CUBE_MAP_POSITIVE_X, 6 );
  17808. //
  17809. this.init = function () {
  17810. this.clearColor( 0, 0, 0, 1 );
  17811. this.clearDepth( 1 );
  17812. this.clearStencil( 0 );
  17813. this.enable( gl.DEPTH_TEST );
  17814. this.setDepthFunc( THREE.LessEqualDepth );
  17815. this.setFlipSided( false );
  17816. this.setCullFace( THREE.CullFaceBack );
  17817. this.enable( gl.CULL_FACE );
  17818. this.enable( gl.BLEND );
  17819. this.setBlending( THREE.NormalBlending );
  17820. };
  17821. this.initAttributes = function () {
  17822. for ( var i = 0, l = newAttributes.length; i < l; i ++ ) {
  17823. newAttributes[ i ] = 0;
  17824. }
  17825. };
  17826. this.enableAttribute = function ( attribute ) {
  17827. newAttributes[ attribute ] = 1;
  17828. if ( enabledAttributes[ attribute ] === 0 ) {
  17829. gl.enableVertexAttribArray( attribute );
  17830. enabledAttributes[ attribute ] = 1;
  17831. }
  17832. if ( attributeDivisors[ attribute ] !== 0 ) {
  17833. var extension = extensions.get( 'ANGLE_instanced_arrays' );
  17834. extension.vertexAttribDivisorANGLE( attribute, 0 );
  17835. attributeDivisors[ attribute ] = 0;
  17836. }
  17837. };
  17838. this.enableAttributeAndDivisor = function ( attribute, meshPerAttribute, extension ) {
  17839. newAttributes[ attribute ] = 1;
  17840. if ( enabledAttributes[ attribute ] === 0 ) {
  17841. gl.enableVertexAttribArray( attribute );
  17842. enabledAttributes[ attribute ] = 1;
  17843. }
  17844. if ( attributeDivisors[ attribute ] !== meshPerAttribute ) {
  17845. extension.vertexAttribDivisorANGLE( attribute, meshPerAttribute );
  17846. attributeDivisors[ attribute ] = meshPerAttribute;
  17847. }
  17848. };
  17849. this.disableUnusedAttributes = function () {
  17850. for ( var i = 0, l = enabledAttributes.length; i !== l; ++ i ) {
  17851. if ( enabledAttributes[ i ] !== newAttributes[ i ] ) {
  17852. gl.disableVertexAttribArray( i );
  17853. enabledAttributes[ i ] = 0;
  17854. }
  17855. }
  17856. };
  17857. this.enable = function ( id ) {
  17858. if ( capabilities[ id ] !== true ) {
  17859. gl.enable( id );
  17860. capabilities[ id ] = true;
  17861. }
  17862. };
  17863. this.disable = function ( id ) {
  17864. if ( capabilities[ id ] !== false ) {
  17865. gl.disable( id );
  17866. capabilities[ id ] = false;
  17867. }
  17868. };
  17869. this.getCompressedTextureFormats = function () {
  17870. if ( compressedTextureFormats === null ) {
  17871. compressedTextureFormats = [];
  17872. if ( extensions.get( 'WEBGL_compressed_texture_pvrtc' ) ||
  17873. extensions.get( 'WEBGL_compressed_texture_s3tc' ) ||
  17874. extensions.get( 'WEBGL_compressed_texture_etc1' ) ) {
  17875. var formats = gl.getParameter( gl.COMPRESSED_TEXTURE_FORMATS );
  17876. for ( var i = 0; i < formats.length; i ++ ) {
  17877. compressedTextureFormats.push( formats[ i ] );
  17878. }
  17879. }
  17880. }
  17881. return compressedTextureFormats;
  17882. };
  17883. this.setBlending = function ( blending, blendEquation, blendSrc, blendDst, blendEquationAlpha, blendSrcAlpha, blendDstAlpha, premultipliedAlpha ) {
  17884. if ( blending !== THREE.NoBlending ) {
  17885. this.enable( gl.BLEND );
  17886. } else {
  17887. this.disable( gl.BLEND );
  17888. currentBlending = blending; // no blending, that is
  17889. return;
  17890. }
  17891. if ( blending !== currentBlending || premultipliedAlpha !== currentPremultipledAlpha ) {
  17892. if ( blending === THREE.AdditiveBlending ) {
  17893. if ( premultipliedAlpha ) {
  17894. gl.blendEquationSeparate( gl.FUNC_ADD, gl.FUNC_ADD );
  17895. gl.blendFuncSeparate( gl.ONE, gl.ONE, gl.ONE, gl.ONE );
  17896. } else {
  17897. gl.blendEquation( gl.FUNC_ADD );
  17898. gl.blendFunc( gl.SRC_ALPHA, gl.ONE );
  17899. }
  17900. } else if ( blending === THREE.SubtractiveBlending ) {
  17901. if ( premultipliedAlpha ) {
  17902. gl.blendEquationSeparate( gl.FUNC_ADD, gl.FUNC_ADD );
  17903. gl.blendFuncSeparate( gl.ZERO, gl.ZERO, gl.ONE_MINUS_SRC_COLOR, gl.ONE_MINUS_SRC_ALPHA );
  17904. } else {
  17905. gl.blendEquation( gl.FUNC_ADD );
  17906. gl.blendFunc( gl.ZERO, gl.ONE_MINUS_SRC_COLOR );
  17907. }
  17908. } else if ( blending === THREE.MultiplyBlending ) {
  17909. if ( premultipliedAlpha ) {
  17910. gl.blendEquationSeparate( gl.FUNC_ADD, gl.FUNC_ADD );
  17911. gl.blendFuncSeparate( gl.ZERO, gl.SRC_COLOR, gl.ZERO, gl.SRC_ALPHA );
  17912. } else {
  17913. gl.blendEquation( gl.FUNC_ADD );
  17914. gl.blendFunc( gl.ZERO, gl.SRC_COLOR );
  17915. }
  17916. } else {
  17917. if ( premultipliedAlpha ) {
  17918. gl.blendEquationSeparate( gl.FUNC_ADD, gl.FUNC_ADD );
  17919. gl.blendFuncSeparate( gl.ONE, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA );
  17920. } else {
  17921. gl.blendEquationSeparate( gl.FUNC_ADD, gl.FUNC_ADD );
  17922. gl.blendFuncSeparate( gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA );
  17923. }
  17924. }
  17925. currentBlending = blending;
  17926. currentPremultipledAlpha = premultipliedAlpha;
  17927. }
  17928. if ( blending === THREE.CustomBlending ) {
  17929. blendEquationAlpha = blendEquationAlpha || blendEquation;
  17930. blendSrcAlpha = blendSrcAlpha || blendSrc;
  17931. blendDstAlpha = blendDstAlpha || blendDst;
  17932. if ( blendEquation !== currentBlendEquation || blendEquationAlpha !== currentBlendEquationAlpha ) {
  17933. gl.blendEquationSeparate( paramThreeToGL( blendEquation ), paramThreeToGL( blendEquationAlpha ) );
  17934. currentBlendEquation = blendEquation;
  17935. currentBlendEquationAlpha = blendEquationAlpha;
  17936. }
  17937. if ( blendSrc !== currentBlendSrc || blendDst !== currentBlendDst || blendSrcAlpha !== currentBlendSrcAlpha || blendDstAlpha !== currentBlendDstAlpha ) {
  17938. gl.blendFuncSeparate( paramThreeToGL( blendSrc ), paramThreeToGL( blendDst ), paramThreeToGL( blendSrcAlpha ), paramThreeToGL( blendDstAlpha ) );
  17939. currentBlendSrc = blendSrc;
  17940. currentBlendDst = blendDst;
  17941. currentBlendSrcAlpha = blendSrcAlpha;
  17942. currentBlendDstAlpha = blendDstAlpha;
  17943. }
  17944. } else {
  17945. currentBlendEquation = null;
  17946. currentBlendSrc = null;
  17947. currentBlendDst = null;
  17948. currentBlendEquationAlpha = null;
  17949. currentBlendSrcAlpha = null;
  17950. currentBlendDstAlpha = null;
  17951. }
  17952. };
  17953. // TODO Deprecate
  17954. this.setColorWrite = function ( colorWrite ) {
  17955. this.buffers.color.setMask( colorWrite );
  17956. };
  17957. this.setDepthTest = function ( depthTest ) {
  17958. this.buffers.depth.setTest( depthTest );
  17959. };
  17960. this.setDepthWrite = function ( depthWrite ) {
  17961. this.buffers.depth.setMask( depthWrite );
  17962. };
  17963. this.setDepthFunc = function ( depthFunc ) {
  17964. this.buffers.depth.setFunc( depthFunc );
  17965. };
  17966. this.setStencilTest = function ( stencilTest ) {
  17967. this.buffers.stencil.setTest( stencilTest );
  17968. };
  17969. this.setStencilWrite = function ( stencilWrite ) {
  17970. this.buffers.stencil.setMask( stencilWrite );
  17971. };
  17972. this.setStencilFunc = function ( stencilFunc, stencilRef, stencilMask ) {
  17973. this.buffers.stencil.setFunc( stencilFunc, stencilRef, stencilMask );
  17974. };
  17975. this.setStencilOp = function ( stencilFail, stencilZFail, stencilZPass ) {
  17976. this.buffers.stencil.setOp( stencilFail, stencilZFail, stencilZPass );
  17977. };
  17978. //
  17979. this.setFlipSided = function ( flipSided ) {
  17980. if ( currentFlipSided !== flipSided ) {
  17981. if ( flipSided ) {
  17982. gl.frontFace( gl.CW );
  17983. } else {
  17984. gl.frontFace( gl.CCW );
  17985. }
  17986. currentFlipSided = flipSided;
  17987. }
  17988. };
  17989. this.setCullFace = function ( cullFace ) {
  17990. if ( cullFace !== THREE.CullFaceNone ) {
  17991. this.enable( gl.CULL_FACE );
  17992. if ( cullFace !== currentCullFace ) {
  17993. if ( cullFace === THREE.CullFaceBack ) {
  17994. gl.cullFace( gl.BACK );
  17995. } else if ( cullFace === THREE.CullFaceFront ) {
  17996. gl.cullFace( gl.FRONT );
  17997. } else {
  17998. gl.cullFace( gl.FRONT_AND_BACK );
  17999. }
  18000. }
  18001. } else {
  18002. this.disable( gl.CULL_FACE );
  18003. }
  18004. currentCullFace = cullFace;
  18005. };
  18006. this.setLineWidth = function ( width ) {
  18007. if ( width !== currentLineWidth ) {
  18008. gl.lineWidth( width );
  18009. currentLineWidth = width;
  18010. }
  18011. };
  18012. this.setPolygonOffset = function ( polygonOffset, factor, units ) {
  18013. if ( polygonOffset ) {
  18014. this.enable( gl.POLYGON_OFFSET_FILL );
  18015. if ( currentPolygonOffsetFactor !== factor || currentPolygonOffsetUnits !== units ) {
  18016. gl.polygonOffset( factor, units );
  18017. currentPolygonOffsetFactor = factor;
  18018. currentPolygonOffsetUnits = units;
  18019. }
  18020. } else {
  18021. this.disable( gl.POLYGON_OFFSET_FILL );
  18022. }
  18023. };
  18024. this.getScissorTest = function () {
  18025. return currentScissorTest;
  18026. };
  18027. this.setScissorTest = function ( scissorTest ) {
  18028. currentScissorTest = scissorTest;
  18029. if ( scissorTest ) {
  18030. this.enable( gl.SCISSOR_TEST );
  18031. } else {
  18032. this.disable( gl.SCISSOR_TEST );
  18033. }
  18034. };
  18035. // texture
  18036. this.activeTexture = function ( webglSlot ) {
  18037. if ( webglSlot === undefined ) webglSlot = gl.TEXTURE0 + maxTextures - 1;
  18038. if ( currentTextureSlot !== webglSlot ) {
  18039. gl.activeTexture( webglSlot );
  18040. currentTextureSlot = webglSlot;
  18041. }
  18042. };
  18043. this.bindTexture = function ( webglType, webglTexture ) {
  18044. if ( currentTextureSlot === null ) {
  18045. _this.activeTexture();
  18046. }
  18047. var boundTexture = currentBoundTextures[ currentTextureSlot ];
  18048. if ( boundTexture === undefined ) {
  18049. boundTexture = { type: undefined, texture: undefined };
  18050. currentBoundTextures[ currentTextureSlot ] = boundTexture;
  18051. }
  18052. if ( boundTexture.type !== webglType || boundTexture.texture !== webglTexture ) {
  18053. gl.bindTexture( webglType, webglTexture || emptyTextures[ webglType ] );
  18054. boundTexture.type = webglType;
  18055. boundTexture.texture = webglTexture;
  18056. }
  18057. };
  18058. this.compressedTexImage2D = function () {
  18059. try {
  18060. gl.compressedTexImage2D.apply( gl, arguments );
  18061. } catch ( error ) {
  18062. console.error( error );
  18063. }
  18064. };
  18065. this.texImage2D = function () {
  18066. try {
  18067. gl.texImage2D.apply( gl, arguments );
  18068. } catch ( error ) {
  18069. console.error( error );
  18070. }
  18071. };
  18072. // TODO Deprecate
  18073. this.clearColor = function ( r, g, b, a ) {
  18074. this.buffers.color.setClear( r, g, b, a );
  18075. };
  18076. this.clearDepth = function ( depth ) {
  18077. this.buffers.depth.setClear( depth );
  18078. };
  18079. this.clearStencil = function ( stencil ) {
  18080. this.buffers.stencil.setClear( stencil );
  18081. };
  18082. //
  18083. this.scissor = function ( scissor ) {
  18084. if ( currentScissor.equals( scissor ) === false ) {
  18085. gl.scissor( scissor.x, scissor.y, scissor.z, scissor.w );
  18086. currentScissor.copy( scissor );
  18087. }
  18088. };
  18089. this.viewport = function ( viewport ) {
  18090. if ( currentViewport.equals( viewport ) === false ) {
  18091. gl.viewport( viewport.x, viewport.y, viewport.z, viewport.w );
  18092. currentViewport.copy( viewport );
  18093. }
  18094. };
  18095. //
  18096. this.reset = function () {
  18097. for ( var i = 0; i < enabledAttributes.length; i ++ ) {
  18098. if ( enabledAttributes[ i ] === 1 ) {
  18099. gl.disableVertexAttribArray( i );
  18100. enabledAttributes[ i ] = 0;
  18101. }
  18102. }
  18103. capabilities = {};
  18104. compressedTextureFormats = null;
  18105. currentTextureSlot = null;
  18106. currentBoundTextures = {};
  18107. currentBlending = null;
  18108. currentFlipSided = null;
  18109. currentCullFace = null;
  18110. this.buffers.color.reset();
  18111. this.buffers.depth.reset();
  18112. this.buffers.stencil.reset();
  18113. };
  18114. };
  18115. THREE.WebGLColorBuffer = function ( gl, state ) {
  18116. var locked = false;
  18117. var color = new THREE.Vector4();
  18118. var currentColorMask = null;
  18119. var currentColorClear = new THREE.Vector4();
  18120. this.setMask = function ( colorMask ) {
  18121. if ( currentColorMask !== colorMask && ! locked ) {
  18122. gl.colorMask( colorMask, colorMask, colorMask, colorMask );
  18123. currentColorMask = colorMask;
  18124. }
  18125. };
  18126. this.setLocked = function ( lock ) {
  18127. locked = lock;
  18128. };
  18129. this.setClear = function ( r, g, b, a ) {
  18130. color.set( r, g, b, a );
  18131. if ( currentColorClear.equals( color ) === false ) {
  18132. gl.clearColor( r, g, b, a );
  18133. currentColorClear.copy( color );
  18134. }
  18135. };
  18136. this.reset = function () {
  18137. locked = false;
  18138. currentColorMask = null;
  18139. currentColorClear = new THREE.Vector4();
  18140. };
  18141. };
  18142. THREE.WebGLDepthBuffer = function( gl, state ) {
  18143. var locked = false;
  18144. var currentDepthMask = null;
  18145. var currentDepthFunc = null;
  18146. var currentDepthClear = null;
  18147. this.setTest = function ( depthTest ) {
  18148. if ( depthTest ) {
  18149. state.enable( gl.DEPTH_TEST );
  18150. } else {
  18151. state.disable( gl.DEPTH_TEST );
  18152. }
  18153. };
  18154. this.setMask = function( depthMask ){
  18155. if ( currentDepthMask !== depthMask && ! locked ) {
  18156. gl.depthMask( depthMask );
  18157. currentDepthMask = depthMask;
  18158. }
  18159. };
  18160. this.setFunc = function ( depthFunc ) {
  18161. if ( currentDepthFunc !== depthFunc ) {
  18162. if ( depthFunc ) {
  18163. switch ( depthFunc ) {
  18164. case THREE.NeverDepth:
  18165. gl.depthFunc( gl.NEVER );
  18166. break;
  18167. case THREE.AlwaysDepth:
  18168. gl.depthFunc( gl.ALWAYS );
  18169. break;
  18170. case THREE.LessDepth:
  18171. gl.depthFunc( gl.LESS );
  18172. break;
  18173. case THREE.LessEqualDepth:
  18174. gl.depthFunc( gl.LEQUAL );
  18175. break;
  18176. case THREE.EqualDepth:
  18177. gl.depthFunc( gl.EQUAL );
  18178. break;
  18179. case THREE.GreaterEqualDepth:
  18180. gl.depthFunc( gl.GEQUAL );
  18181. break;
  18182. case THREE.GreaterDepth:
  18183. gl.depthFunc( gl.GREATER );
  18184. break;
  18185. case THREE.NotEqualDepth:
  18186. gl.depthFunc( gl.NOTEQUAL );
  18187. break;
  18188. default:
  18189. gl.depthFunc( gl.LEQUAL );
  18190. }
  18191. } else {
  18192. gl.depthFunc( gl.LEQUAL );
  18193. }
  18194. currentDepthFunc = depthFunc;
  18195. }
  18196. };
  18197. this.setLocked = function ( lock ) {
  18198. locked = lock;
  18199. };
  18200. this.setClear = function ( depth ) {
  18201. if ( currentDepthClear !== depth ) {
  18202. gl.clearDepth( depth );
  18203. currentDepthClear = depth;
  18204. }
  18205. };
  18206. this.reset = function () {
  18207. locked = false;
  18208. currentDepthMask = null;
  18209. currentDepthFunc = null;
  18210. currentDepthClear = null;
  18211. };
  18212. };
  18213. THREE.WebGLStencilBuffer = function ( gl, state ) {
  18214. var locked = false;
  18215. var currentStencilMask = null;
  18216. var currentStencilFunc = null;
  18217. var currentStencilRef = null;
  18218. var currentStencilFuncMask = null;
  18219. var currentStencilFail = null;
  18220. var currentStencilZFail = null;
  18221. var currentStencilZPass = null;
  18222. var currentStencilClear = null;
  18223. this.setTest = function ( stencilTest ) {
  18224. if ( stencilTest ) {
  18225. state.enable( gl.STENCIL_TEST );
  18226. } else {
  18227. state.disable( gl.STENCIL_TEST );
  18228. }
  18229. };
  18230. this.setMask = function ( stencilMask ) {
  18231. if ( currentStencilMask !== stencilMask && ! locked ) {
  18232. gl.stencilMask( stencilMask );
  18233. currentStencilMask = stencilMask;
  18234. }
  18235. };
  18236. this.setFunc = function ( stencilFunc, stencilRef, stencilMask ) {
  18237. if ( currentStencilFunc !== stencilFunc ||
  18238. currentStencilRef !== stencilRef ||
  18239. currentStencilFuncMask !== stencilMask ) {
  18240. gl.stencilFunc( stencilFunc, stencilRef, stencilMask );
  18241. currentStencilFunc = stencilFunc;
  18242. currentStencilRef = stencilRef;
  18243. currentStencilFuncMask = stencilMask;
  18244. }
  18245. };
  18246. this.setOp = function ( stencilFail, stencilZFail, stencilZPass ) {
  18247. if ( currentStencilFail !== stencilFail ||
  18248. currentStencilZFail !== stencilZFail ||
  18249. currentStencilZPass !== stencilZPass ) {
  18250. gl.stencilOp( stencilFail, stencilZFail, stencilZPass );
  18251. currentStencilFail = stencilFail;
  18252. currentStencilZFail = stencilZFail;
  18253. currentStencilZPass = stencilZPass;
  18254. }
  18255. };
  18256. this.setLocked = function ( lock ) {
  18257. locked = lock;
  18258. };
  18259. this.setClear = function ( stencil ) {
  18260. if ( currentStencilClear !== stencil ) {
  18261. gl.clearStencil( stencil );
  18262. currentStencilClear = stencil;
  18263. }
  18264. };
  18265. this.reset = function () {
  18266. locked = false;
  18267. currentStencilMask = null;
  18268. currentStencilFunc = null;
  18269. currentStencilRef = null;
  18270. currentStencilFuncMask = null;
  18271. currentStencilFail = null;
  18272. currentStencilZFail = null;
  18273. currentStencilZPass = null;
  18274. currentStencilClear = null;
  18275. };
  18276. };
  18277. // File:src/renderers/webgl/WebGLTextures.js
  18278. /**
  18279. * @author mrdoob / http://mrdoob.com/
  18280. */
  18281. THREE.WebGLTextures = function ( _gl, extensions, state, properties, capabilities, paramThreeToGL, info ) {
  18282. var _infoMemory = info.memory;
  18283. var _isWebGL2 = ( typeof WebGL2RenderingContext !== 'undefined' && _gl instanceof WebGL2RenderingContext );
  18284. //
  18285. function clampToMaxSize ( image, maxSize ) {
  18286. if ( image.width > maxSize || image.height > maxSize ) {
  18287. // Warning: Scaling through the canvas will only work with images that use
  18288. // premultiplied alpha.
  18289. var scale = maxSize / Math.max( image.width, image.height );
  18290. var canvas = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' );
  18291. canvas.width = Math.floor( image.width * scale );
  18292. canvas.height = Math.floor( image.height * scale );
  18293. var context = canvas.getContext( '2d' );
  18294. context.drawImage( image, 0, 0, image.width, image.height, 0, 0, canvas.width, canvas.height );
  18295. console.warn( 'THREE.WebGLRenderer: image is too big (' + image.width + 'x' + image.height + '). Resized to ' + canvas.width + 'x' + canvas.height, image );
  18296. return canvas;
  18297. }
  18298. return image;
  18299. }
  18300. function isPowerOfTwo( image ) {
  18301. return THREE.Math.isPowerOfTwo( image.width ) && THREE.Math.isPowerOfTwo( image.height );
  18302. }
  18303. function makePowerOfTwo( image ) {
  18304. if ( image instanceof HTMLImageElement || image instanceof HTMLCanvasElement ) {
  18305. var canvas = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' );
  18306. canvas.width = THREE.Math.nearestPowerOfTwo( image.width );
  18307. canvas.height = THREE.Math.nearestPowerOfTwo( image.height );
  18308. var context = canvas.getContext( '2d' );
  18309. context.drawImage( image, 0, 0, canvas.width, canvas.height );
  18310. console.warn( 'THREE.WebGLRenderer: image is not power of two (' + image.width + 'x' + image.height + '). Resized to ' + canvas.width + 'x' + canvas.height, image );
  18311. return canvas;
  18312. }
  18313. return image;
  18314. }
  18315. function textureNeedsPowerOfTwo( texture ) {
  18316. if ( texture.wrapS !== THREE.ClampToEdgeWrapping || texture.wrapT !== THREE.ClampToEdgeWrapping ) return true;
  18317. if ( texture.minFilter !== THREE.NearestFilter && texture.minFilter !== THREE.LinearFilter ) return true;
  18318. return false;
  18319. }
  18320. // Fallback filters for non-power-of-2 textures
  18321. function filterFallback ( f ) {
  18322. if ( f === THREE.NearestFilter || f === THREE.NearestMipMapNearestFilter || f === THREE.NearestMipMapLinearFilter ) {
  18323. return _gl.NEAREST;
  18324. }
  18325. return _gl.LINEAR;
  18326. }
  18327. //
  18328. function onTextureDispose( event ) {
  18329. var texture = event.target;
  18330. texture.removeEventListener( 'dispose', onTextureDispose );
  18331. deallocateTexture( texture );
  18332. _infoMemory.textures --;
  18333. }
  18334. function onRenderTargetDispose( event ) {
  18335. var renderTarget = event.target;
  18336. renderTarget.removeEventListener( 'dispose', onRenderTargetDispose );
  18337. deallocateRenderTarget( renderTarget );
  18338. _infoMemory.textures --;
  18339. }
  18340. //
  18341. function deallocateTexture( texture ) {
  18342. var textureProperties = properties.get( texture );
  18343. if ( texture.image && textureProperties.__image__webglTextureCube ) {
  18344. // cube texture
  18345. _gl.deleteTexture( textureProperties.__image__webglTextureCube );
  18346. } else {
  18347. // 2D texture
  18348. if ( textureProperties.__webglInit === undefined ) return;
  18349. _gl.deleteTexture( textureProperties.__webglTexture );
  18350. }
  18351. // remove all webgl properties
  18352. properties.delete( texture );
  18353. }
  18354. function deallocateRenderTarget( renderTarget ) {
  18355. var renderTargetProperties = properties.get( renderTarget );
  18356. var textureProperties = properties.get( renderTarget.texture );
  18357. if ( ! renderTarget ) return;
  18358. if ( textureProperties.__webglTexture !== undefined ) {
  18359. _gl.deleteTexture( textureProperties.__webglTexture );
  18360. }
  18361. if ( renderTarget.depthTexture ) {
  18362. renderTarget.depthTexture.dispose();
  18363. }
  18364. if ( renderTarget instanceof THREE.WebGLRenderTargetCube ) {
  18365. for ( var i = 0; i < 6; i ++ ) {
  18366. _gl.deleteFramebuffer( renderTargetProperties.__webglFramebuffer[ i ] );
  18367. if ( renderTargetProperties.__webglDepthbuffer ) _gl.deleteRenderbuffer( renderTargetProperties.__webglDepthbuffer[ i ] );
  18368. }
  18369. } else {
  18370. _gl.deleteFramebuffer( renderTargetProperties.__webglFramebuffer );
  18371. if ( renderTargetProperties.__webglDepthbuffer ) _gl.deleteRenderbuffer( renderTargetProperties.__webglDepthbuffer );
  18372. }
  18373. properties.delete( renderTarget.texture );
  18374. properties.delete( renderTarget );
  18375. }
  18376. //
  18377. function setTexture2D( texture, slot ) {
  18378. var textureProperties = properties.get( texture );
  18379. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  18380. var image = texture.image;
  18381. if ( image === undefined ) {
  18382. console.warn( 'THREE.WebGLRenderer: Texture marked for update but image is undefined', texture );
  18383. } else if ( image.complete === false ) {
  18384. console.warn( 'THREE.WebGLRenderer: Texture marked for update but image is incomplete', texture );
  18385. } else {
  18386. uploadTexture( textureProperties, texture, slot );
  18387. return;
  18388. }
  18389. }
  18390. state.activeTexture( _gl.TEXTURE0 + slot );
  18391. state.bindTexture( _gl.TEXTURE_2D, textureProperties.__webglTexture );
  18392. }
  18393. function setTextureCube ( texture, slot ) {
  18394. var textureProperties = properties.get( texture );
  18395. if ( texture.image.length === 6 ) {
  18396. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  18397. if ( ! textureProperties.__image__webglTextureCube ) {
  18398. texture.addEventListener( 'dispose', onTextureDispose );
  18399. textureProperties.__image__webglTextureCube = _gl.createTexture();
  18400. _infoMemory.textures ++;
  18401. }
  18402. state.activeTexture( _gl.TEXTURE0 + slot );
  18403. state.bindTexture( _gl.TEXTURE_CUBE_MAP, textureProperties.__image__webglTextureCube );
  18404. _gl.pixelStorei( _gl.UNPACK_FLIP_Y_WEBGL, texture.flipY );
  18405. var isCompressed = texture instanceof THREE.CompressedTexture;
  18406. var isDataTexture = texture.image[ 0 ] instanceof THREE.DataTexture;
  18407. var cubeImage = [];
  18408. for ( var i = 0; i < 6; i ++ ) {
  18409. if ( ! isCompressed && ! isDataTexture ) {
  18410. cubeImage[ i ] = clampToMaxSize( texture.image[ i ], capabilities.maxCubemapSize );
  18411. } else {
  18412. cubeImage[ i ] = isDataTexture ? texture.image[ i ].image : texture.image[ i ];
  18413. }
  18414. }
  18415. var image = cubeImage[ 0 ],
  18416. isPowerOfTwoImage = isPowerOfTwo( image ),
  18417. glFormat = paramThreeToGL( texture.format ),
  18418. glType = paramThreeToGL( texture.type );
  18419. setTextureParameters( _gl.TEXTURE_CUBE_MAP, texture, isPowerOfTwoImage );
  18420. for ( var i = 0; i < 6; i ++ ) {
  18421. if ( ! isCompressed ) {
  18422. if ( isDataTexture ) {
  18423. state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, glFormat, cubeImage[ i ].width, cubeImage[ i ].height, 0, glFormat, glType, cubeImage[ i ].data );
  18424. } else {
  18425. state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, glFormat, glFormat, glType, cubeImage[ i ] );
  18426. }
  18427. } else {
  18428. var mipmap, mipmaps = cubeImage[ i ].mipmaps;
  18429. for ( var j = 0, jl = mipmaps.length; j < jl; j ++ ) {
  18430. mipmap = mipmaps[ j ];
  18431. if ( texture.format !== THREE.RGBAFormat && texture.format !== THREE.RGBFormat ) {
  18432. if ( state.getCompressedTextureFormats().indexOf( glFormat ) > - 1 ) {
  18433. state.compressedTexImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, j, glFormat, mipmap.width, mipmap.height, 0, mipmap.data );
  18434. } else {
  18435. console.warn( "THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .setTextureCube()" );
  18436. }
  18437. } else {
  18438. state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, j, glFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  18439. }
  18440. }
  18441. }
  18442. }
  18443. if ( texture.generateMipmaps && isPowerOfTwoImage ) {
  18444. _gl.generateMipmap( _gl.TEXTURE_CUBE_MAP );
  18445. }
  18446. textureProperties.__version = texture.version;
  18447. if ( texture.onUpdate ) texture.onUpdate( texture );
  18448. } else {
  18449. state.activeTexture( _gl.TEXTURE0 + slot );
  18450. state.bindTexture( _gl.TEXTURE_CUBE_MAP, textureProperties.__image__webglTextureCube );
  18451. }
  18452. }
  18453. }
  18454. function setTextureCubeDynamic ( texture, slot ) {
  18455. state.activeTexture( _gl.TEXTURE0 + slot );
  18456. state.bindTexture( _gl.TEXTURE_CUBE_MAP, properties.get( texture ).__webglTexture );
  18457. }
  18458. function setTextureParameters ( textureType, texture, isPowerOfTwoImage ) {
  18459. var extension;
  18460. if ( isPowerOfTwoImage ) {
  18461. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_S, paramThreeToGL( texture.wrapS ) );
  18462. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_T, paramThreeToGL( texture.wrapT ) );
  18463. _gl.texParameteri( textureType, _gl.TEXTURE_MAG_FILTER, paramThreeToGL( texture.magFilter ) );
  18464. _gl.texParameteri( textureType, _gl.TEXTURE_MIN_FILTER, paramThreeToGL( texture.minFilter ) );
  18465. } else {
  18466. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_S, _gl.CLAMP_TO_EDGE );
  18467. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_T, _gl.CLAMP_TO_EDGE );
  18468. if ( texture.wrapS !== THREE.ClampToEdgeWrapping || texture.wrapT !== THREE.ClampToEdgeWrapping ) {
  18469. console.warn( 'THREE.WebGLRenderer: Texture is not power of two. Texture.wrapS and Texture.wrapT should be set to THREE.ClampToEdgeWrapping.', texture );
  18470. }
  18471. _gl.texParameteri( textureType, _gl.TEXTURE_MAG_FILTER, filterFallback( texture.magFilter ) );
  18472. _gl.texParameteri( textureType, _gl.TEXTURE_MIN_FILTER, filterFallback( texture.minFilter ) );
  18473. if ( texture.minFilter !== THREE.NearestFilter && texture.minFilter !== THREE.LinearFilter ) {
  18474. console.warn( 'THREE.WebGLRenderer: Texture is not power of two. Texture.minFilter should be set to THREE.NearestFilter or THREE.LinearFilter.', texture );
  18475. }
  18476. }
  18477. extension = extensions.get( 'EXT_texture_filter_anisotropic' );
  18478. if ( extension ) {
  18479. if ( texture.type === THREE.FloatType && extensions.get( 'OES_texture_float_linear' ) === null ) return;
  18480. if ( texture.type === THREE.HalfFloatType && extensions.get( 'OES_texture_half_float_linear' ) === null ) return;
  18481. if ( texture.anisotropy > 1 || properties.get( texture ).__currentAnisotropy ) {
  18482. _gl.texParameterf( textureType, extension.TEXTURE_MAX_ANISOTROPY_EXT, Math.min( texture.anisotropy, capabilities.getMaxAnisotropy() ) );
  18483. properties.get( texture ).__currentAnisotropy = texture.anisotropy;
  18484. }
  18485. }
  18486. }
  18487. function uploadTexture( textureProperties, texture, slot ) {
  18488. if ( textureProperties.__webglInit === undefined ) {
  18489. textureProperties.__webglInit = true;
  18490. texture.addEventListener( 'dispose', onTextureDispose );
  18491. textureProperties.__webglTexture = _gl.createTexture();
  18492. _infoMemory.textures ++;
  18493. }
  18494. state.activeTexture( _gl.TEXTURE0 + slot );
  18495. state.bindTexture( _gl.TEXTURE_2D, textureProperties.__webglTexture );
  18496. _gl.pixelStorei( _gl.UNPACK_FLIP_Y_WEBGL, texture.flipY );
  18497. _gl.pixelStorei( _gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, texture.premultiplyAlpha );
  18498. _gl.pixelStorei( _gl.UNPACK_ALIGNMENT, texture.unpackAlignment );
  18499. var image = clampToMaxSize( texture.image, capabilities.maxTextureSize );
  18500. if ( textureNeedsPowerOfTwo( texture ) && isPowerOfTwo( image ) === false ) {
  18501. image = makePowerOfTwo( image );
  18502. }
  18503. var isPowerOfTwoImage = isPowerOfTwo( image ),
  18504. glFormat = paramThreeToGL( texture.format ),
  18505. glType = paramThreeToGL( texture.type );
  18506. setTextureParameters( _gl.TEXTURE_2D, texture, isPowerOfTwoImage );
  18507. var mipmap, mipmaps = texture.mipmaps;
  18508. if ( texture instanceof THREE.DepthTexture ) {
  18509. // populate depth texture with dummy data
  18510. var internalFormat = _gl.DEPTH_COMPONENT;
  18511. if ( texture.type === THREE.FloatType ) {
  18512. if ( !_isWebGL2 ) throw new Error('Float Depth Texture only supported in WebGL2.0');
  18513. internalFormat = _gl.DEPTH_COMPONENT32F;
  18514. } else if ( _isWebGL2 ) {
  18515. // WebGL 2.0 requires signed internalformat for glTexImage2D
  18516. internalFormat = _gl.DEPTH_COMPONENT16;
  18517. }
  18518. state.texImage2D( _gl.TEXTURE_2D, 0, internalFormat, image.width, image.height, 0, glFormat, glType, null );
  18519. } else if ( texture instanceof THREE.DataTexture ) {
  18520. // use manually created mipmaps if available
  18521. // if there are no manual mipmaps
  18522. // set 0 level mipmap and then use GL to generate other mipmap levels
  18523. if ( mipmaps.length > 0 && isPowerOfTwoImage ) {
  18524. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  18525. mipmap = mipmaps[ i ];
  18526. state.texImage2D( _gl.TEXTURE_2D, i, glFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  18527. }
  18528. texture.generateMipmaps = false;
  18529. } else {
  18530. state.texImage2D( _gl.TEXTURE_2D, 0, glFormat, image.width, image.height, 0, glFormat, glType, image.data );
  18531. }
  18532. } else if ( texture instanceof THREE.CompressedTexture ) {
  18533. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  18534. mipmap = mipmaps[ i ];
  18535. if ( texture.format !== THREE.RGBAFormat && texture.format !== THREE.RGBFormat ) {
  18536. if ( state.getCompressedTextureFormats().indexOf( glFormat ) > - 1 ) {
  18537. state.compressedTexImage2D( _gl.TEXTURE_2D, i, glFormat, mipmap.width, mipmap.height, 0, mipmap.data );
  18538. } else {
  18539. console.warn( "THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()" );
  18540. }
  18541. } else {
  18542. state.texImage2D( _gl.TEXTURE_2D, i, glFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  18543. }
  18544. }
  18545. } else {
  18546. // regular Texture (image, video, canvas)
  18547. // use manually created mipmaps if available
  18548. // if there are no manual mipmaps
  18549. // set 0 level mipmap and then use GL to generate other mipmap levels
  18550. if ( mipmaps.length > 0 && isPowerOfTwoImage ) {
  18551. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  18552. mipmap = mipmaps[ i ];
  18553. state.texImage2D( _gl.TEXTURE_2D, i, glFormat, glFormat, glType, mipmap );
  18554. }
  18555. texture.generateMipmaps = false;
  18556. } else {
  18557. state.texImage2D( _gl.TEXTURE_2D, 0, glFormat, glFormat, glType, image );
  18558. }
  18559. }
  18560. if ( texture.generateMipmaps && isPowerOfTwoImage ) _gl.generateMipmap( _gl.TEXTURE_2D );
  18561. textureProperties.__version = texture.version;
  18562. if ( texture.onUpdate ) texture.onUpdate( texture );
  18563. }
  18564. // Render targets
  18565. // Setup storage for target texture and bind it to correct framebuffer
  18566. function setupFrameBufferTexture ( framebuffer, renderTarget, attachment, textureTarget ) {
  18567. var glFormat = paramThreeToGL( renderTarget.texture.format );
  18568. var glType = paramThreeToGL( renderTarget.texture.type );
  18569. state.texImage2D( textureTarget, 0, glFormat, renderTarget.width, renderTarget.height, 0, glFormat, glType, null );
  18570. _gl.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
  18571. _gl.framebufferTexture2D( _gl.FRAMEBUFFER, attachment, textureTarget, properties.get( renderTarget.texture ).__webglTexture, 0 );
  18572. _gl.bindFramebuffer( _gl.FRAMEBUFFER, null );
  18573. }
  18574. // Setup storage for internal depth/stencil buffers and bind to correct framebuffer
  18575. function setupRenderBufferStorage ( renderbuffer, renderTarget ) {
  18576. _gl.bindRenderbuffer( _gl.RENDERBUFFER, renderbuffer );
  18577. if ( renderTarget.depthBuffer && ! renderTarget.stencilBuffer ) {
  18578. _gl.renderbufferStorage( _gl.RENDERBUFFER, _gl.DEPTH_COMPONENT16, renderTarget.width, renderTarget.height );
  18579. _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.DEPTH_ATTACHMENT, _gl.RENDERBUFFER, renderbuffer );
  18580. } else if ( renderTarget.depthBuffer && renderTarget.stencilBuffer ) {
  18581. _gl.renderbufferStorage( _gl.RENDERBUFFER, _gl.DEPTH_STENCIL, renderTarget.width, renderTarget.height );
  18582. _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.DEPTH_STENCIL_ATTACHMENT, _gl.RENDERBUFFER, renderbuffer );
  18583. } else {
  18584. // FIXME: We don't support !depth !stencil
  18585. _gl.renderbufferStorage( _gl.RENDERBUFFER, _gl.RGBA4, renderTarget.width, renderTarget.height );
  18586. }
  18587. _gl.bindRenderbuffer( _gl.RENDERBUFFER, null );
  18588. }
  18589. // Setup resources for a Depth Texture for a FBO (needs an extension)
  18590. function setupDepthTexture ( framebuffer, renderTarget ) {
  18591. var isCube = ( renderTarget instanceof THREE.WebGLRenderTargetCube );
  18592. if ( isCube ) throw new Error('Depth Texture with cube render targets is not supported!');
  18593. _gl.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
  18594. if ( !( renderTarget.depthTexture instanceof THREE.DepthTexture ) ) {
  18595. throw new Error('renderTarget.depthTexture must be an instance of THREE.DepthTexture');
  18596. }
  18597. // upload an empty depth texture with framebuffer size
  18598. if ( !properties.get( renderTarget.depthTexture ).__webglTexture ||
  18599. renderTarget.depthTexture.image.width !== renderTarget.width ||
  18600. renderTarget.depthTexture.image.height !== renderTarget.height ) {
  18601. renderTarget.depthTexture.image.width = renderTarget.width;
  18602. renderTarget.depthTexture.image.height = renderTarget.height;
  18603. renderTarget.depthTexture.needsUpdate = true;
  18604. }
  18605. setTexture2D( renderTarget.depthTexture, 0 );
  18606. var webglDepthTexture = properties.get( renderTarget.depthTexture ).__webglTexture;
  18607. _gl.framebufferTexture2D( _gl.FRAMEBUFFER, _gl.DEPTH_ATTACHMENT, _gl.TEXTURE_2D, webglDepthTexture, 0 );
  18608. }
  18609. // Setup GL resources for a non-texture depth buffer
  18610. function setupDepthRenderbuffer( renderTarget ) {
  18611. var renderTargetProperties = properties.get( renderTarget );
  18612. var isCube = ( renderTarget instanceof THREE.WebGLRenderTargetCube );
  18613. if ( renderTarget.depthTexture ) {
  18614. if ( isCube ) throw new Error('target.depthTexture not supported in Cube render targets');
  18615. setupDepthTexture( renderTargetProperties.__webglFramebuffer, renderTarget );
  18616. } else {
  18617. if ( isCube ) {
  18618. renderTargetProperties.__webglDepthbuffer = [];
  18619. for ( var i = 0; i < 6; i ++ ) {
  18620. _gl.bindFramebuffer( _gl.FRAMEBUFFER, renderTargetProperties.__webglFramebuffer[ i ] );
  18621. renderTargetProperties.__webglDepthbuffer[ i ] = _gl.createRenderbuffer();
  18622. setupRenderBufferStorage( renderTargetProperties.__webglDepthbuffer[ i ], renderTarget );
  18623. }
  18624. } else {
  18625. _gl.bindFramebuffer( _gl.FRAMEBUFFER, renderTargetProperties.__webglFramebuffer );
  18626. renderTargetProperties.__webglDepthbuffer = _gl.createRenderbuffer();
  18627. setupRenderBufferStorage( renderTargetProperties.__webglDepthbuffer, renderTarget );
  18628. }
  18629. }
  18630. _gl.bindFramebuffer( _gl.FRAMEBUFFER, null );
  18631. }
  18632. // Set up GL resources for the render target
  18633. function setupRenderTarget( renderTarget ) {
  18634. var renderTargetProperties = properties.get( renderTarget );
  18635. var textureProperties = properties.get( renderTarget.texture );
  18636. renderTarget.addEventListener( 'dispose', onRenderTargetDispose );
  18637. textureProperties.__webglTexture = _gl.createTexture();
  18638. _infoMemory.textures ++;
  18639. var isCube = ( renderTarget instanceof THREE.WebGLRenderTargetCube );
  18640. var isTargetPowerOfTwo = isPowerOfTwo( renderTarget );
  18641. // Setup framebuffer
  18642. if ( isCube ) {
  18643. renderTargetProperties.__webglFramebuffer = [];
  18644. for ( var i = 0; i < 6; i ++ ) {
  18645. renderTargetProperties.__webglFramebuffer[ i ] = _gl.createFramebuffer();
  18646. }
  18647. } else {
  18648. renderTargetProperties.__webglFramebuffer = _gl.createFramebuffer();
  18649. }
  18650. // Setup color buffer
  18651. if ( isCube ) {
  18652. state.bindTexture( _gl.TEXTURE_CUBE_MAP, textureProperties.__webglTexture );
  18653. setTextureParameters( _gl.TEXTURE_CUBE_MAP, renderTarget.texture, isTargetPowerOfTwo );
  18654. for ( var i = 0; i < 6; i ++ ) {
  18655. setupFrameBufferTexture( renderTargetProperties.__webglFramebuffer[ i ], renderTarget, _gl.COLOR_ATTACHMENT0, _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i );
  18656. }
  18657. if ( renderTarget.texture.generateMipmaps && isTargetPowerOfTwo ) _gl.generateMipmap( _gl.TEXTURE_CUBE_MAP );
  18658. state.bindTexture( _gl.TEXTURE_CUBE_MAP, null );
  18659. } else {
  18660. state.bindTexture( _gl.TEXTURE_2D, textureProperties.__webglTexture );
  18661. setTextureParameters( _gl.TEXTURE_2D, renderTarget.texture, isTargetPowerOfTwo );
  18662. setupFrameBufferTexture( renderTargetProperties.__webglFramebuffer, renderTarget, _gl.COLOR_ATTACHMENT0, _gl.TEXTURE_2D );
  18663. if ( renderTarget.texture.generateMipmaps && isTargetPowerOfTwo ) _gl.generateMipmap( _gl.TEXTURE_2D );
  18664. state.bindTexture( _gl.TEXTURE_2D, null );
  18665. }
  18666. // Setup depth and stencil buffers
  18667. if ( renderTarget.depthBuffer ) {
  18668. setupDepthRenderbuffer( renderTarget );
  18669. }
  18670. }
  18671. function updateRenderTargetMipmap( renderTarget ) {
  18672. var texture = renderTarget.texture;
  18673. if ( texture.generateMipmaps && isPowerOfTwo( renderTarget ) &&
  18674. texture.minFilter !== THREE.NearestFilter &&
  18675. texture.minFilter !== THREE.LinearFilter ) {
  18676. var target = renderTarget instanceof THREE.WebGLRenderTargetCube ? _gl.TEXTURE_CUBE_MAP : _gl.TEXTURE_2D;
  18677. var webglTexture = properties.get( texture ).__webglTexture;
  18678. state.bindTexture( target, webglTexture );
  18679. _gl.generateMipmap( target );
  18680. state.bindTexture( target, null );
  18681. }
  18682. }
  18683. this.setTexture2D = setTexture2D;
  18684. this.setTextureCube = setTextureCube;
  18685. this.setTextureCubeDynamic = setTextureCubeDynamic;
  18686. this.setupRenderTarget = setupRenderTarget;
  18687. this.updateRenderTargetMipmap = updateRenderTargetMipmap;
  18688. };
  18689. // File:src/renderers/webgl/WebGLUniforms.js
  18690. /**
  18691. *
  18692. * Uniforms of a program.
  18693. * Those form a tree structure with a special top-level container for the root,
  18694. * which you get by calling 'new WebGLUniforms( gl, program, renderer )'.
  18695. *
  18696. *
  18697. * Properties of inner nodes including the top-level container:
  18698. *
  18699. * .seq - array of nested uniforms
  18700. * .map - nested uniforms by name
  18701. *
  18702. *
  18703. * Methods of all nodes except the top-level container:
  18704. *
  18705. * .setValue( gl, value, [renderer] )
  18706. *
  18707. * uploads a uniform value(s)
  18708. * the 'renderer' parameter is needed for sampler uniforms
  18709. *
  18710. *
  18711. * Static methods of the top-level container (renderer factorizations):
  18712. *
  18713. * .upload( gl, seq, values, renderer )
  18714. *
  18715. * sets uniforms in 'seq' to 'values[id].value'
  18716. *
  18717. * .seqWithValue( seq, values ) : filteredSeq
  18718. *
  18719. * filters 'seq' entries with corresponding entry in values
  18720. *
  18721. * .splitDynamic( seq, values ) : filteredSeq
  18722. *
  18723. * filters 'seq' entries with dynamic entry and removes them from 'seq'
  18724. *
  18725. *
  18726. * Methods of the top-level container (renderer factorizations):
  18727. *
  18728. * .setValue( gl, name, value )
  18729. *
  18730. * sets uniform with name 'name' to 'value'
  18731. *
  18732. * .set( gl, obj, prop )
  18733. *
  18734. * sets uniform from object and property with same name than uniform
  18735. *
  18736. * .setOptional( gl, obj, prop )
  18737. *
  18738. * like .set for an optional property of the object
  18739. *
  18740. *
  18741. * @author tschw
  18742. *
  18743. */
  18744. THREE.WebGLUniforms = ( function() { // scope
  18745. var emptyTexture = new THREE.Texture();
  18746. var emptyCubeTexture = new THREE.CubeTexture();
  18747. // --- Base for inner nodes (including the root) ---
  18748. var UniformContainer = function() {
  18749. this.seq = [];
  18750. this.map = {};
  18751. },
  18752. // --- Utilities ---
  18753. // Array Caches (provide typed arrays for temporary by size)
  18754. arrayCacheF32 = [],
  18755. arrayCacheI32 = [],
  18756. uncacheTemporaryArrays = function() {
  18757. arrayCacheF32.length = 0;
  18758. arrayCacheI32.length = 0;
  18759. },
  18760. // Flattening for arrays of vectors and matrices
  18761. flatten = function( array, nBlocks, blockSize ) {
  18762. var firstElem = array[ 0 ];
  18763. if ( firstElem <= 0 || firstElem > 0 ) return array;
  18764. // unoptimized: ! isNaN( firstElem )
  18765. // see http://jacksondunstan.com/articles/983
  18766. var n = nBlocks * blockSize,
  18767. r = arrayCacheF32[ n ];
  18768. if ( r === undefined ) {
  18769. r = new Float32Array( n );
  18770. arrayCacheF32[ n ] = r;
  18771. }
  18772. if ( nBlocks !== 0 ) {
  18773. firstElem.toArray( r, 0 );
  18774. for ( var i = 1, offset = 0; i !== nBlocks; ++ i ) {
  18775. offset += blockSize;
  18776. array[ i ].toArray( r, offset );
  18777. }
  18778. }
  18779. return r;
  18780. },
  18781. // Texture unit allocation
  18782. allocTexUnits = function( renderer, n ) {
  18783. var r = arrayCacheI32[ n ];
  18784. if ( r === undefined ) {
  18785. r = new Int32Array( n );
  18786. arrayCacheI32[ n ] = r;
  18787. }
  18788. for ( var i = 0; i !== n; ++ i )
  18789. r[ i ] = renderer.allocTextureUnit();
  18790. return r;
  18791. },
  18792. // --- Setters ---
  18793. // Note: Defining these methods externally, because they come in a bunch
  18794. // and this way their names minify.
  18795. // Single scalar
  18796. setValue1f = function( gl, v ) { gl.uniform1f( this.addr, v ); },
  18797. setValue1i = function( gl, v ) { gl.uniform1i( this.addr, v ); },
  18798. // Single float vector (from flat array or THREE.VectorN)
  18799. setValue2fv = function( gl, v ) {
  18800. if ( v.x === undefined ) gl.uniform2fv( this.addr, v );
  18801. else gl.uniform2f( this.addr, v.x, v.y );
  18802. },
  18803. setValue3fv = function( gl, v ) {
  18804. if ( v.x !== undefined )
  18805. gl.uniform3f( this.addr, v.x, v.y, v.z );
  18806. else if ( v.r !== undefined )
  18807. gl.uniform3f( this.addr, v.r, v.g, v.b );
  18808. else
  18809. gl.uniform3fv( this.addr, v );
  18810. },
  18811. setValue4fv = function( gl, v ) {
  18812. if ( v.x === undefined ) gl.uniform4fv( this.addr, v );
  18813. else gl.uniform4f( this.addr, v.x, v.y, v.z, v.w );
  18814. },
  18815. // Single matrix (from flat array or MatrixN)
  18816. setValue2fm = function( gl, v ) {
  18817. gl.uniformMatrix2fv( this.addr, false, v.elements || v );
  18818. },
  18819. setValue3fm = function( gl, v ) {
  18820. gl.uniformMatrix3fv( this.addr, false, v.elements || v );
  18821. },
  18822. setValue4fm = function( gl, v ) {
  18823. gl.uniformMatrix4fv( this.addr, false, v.elements || v );
  18824. },
  18825. // Single texture (2D / Cube)
  18826. setValueT1 = function( gl, v, renderer ) {
  18827. var unit = renderer.allocTextureUnit();
  18828. gl.uniform1i( this.addr, unit );
  18829. renderer.setTexture2D( v || emptyTexture, unit );
  18830. },
  18831. setValueT6 = function( gl, v, renderer ) {
  18832. var unit = renderer.allocTextureUnit();
  18833. gl.uniform1i( this.addr, unit );
  18834. renderer.setTextureCube( v || emptyCubeTexture, unit );
  18835. },
  18836. // Integer / Boolean vectors or arrays thereof (always flat arrays)
  18837. setValue2iv = function( gl, v ) { gl.uniform2iv( this.addr, v ); },
  18838. setValue3iv = function( gl, v ) { gl.uniform3iv( this.addr, v ); },
  18839. setValue4iv = function( gl, v ) { gl.uniform4iv( this.addr, v ); },
  18840. // Helper to pick the right setter for the singular case
  18841. getSingularSetter = function( type ) {
  18842. switch ( type ) {
  18843. case 0x1406: return setValue1f; // FLOAT
  18844. case 0x8b50: return setValue2fv; // _VEC2
  18845. case 0x8b51: return setValue3fv; // _VEC3
  18846. case 0x8b52: return setValue4fv; // _VEC4
  18847. case 0x8b5a: return setValue2fm; // _MAT2
  18848. case 0x8b5b: return setValue3fm; // _MAT3
  18849. case 0x8b5c: return setValue4fm; // _MAT4
  18850. case 0x8b5e: return setValueT1; // SAMPLER_2D
  18851. case 0x8b60: return setValueT6; // SAMPLER_CUBE
  18852. case 0x1404: case 0x8b56: return setValue1i; // INT, BOOL
  18853. case 0x8b53: case 0x8b57: return setValue2iv; // _VEC2
  18854. case 0x8b54: case 0x8b58: return setValue3iv; // _VEC3
  18855. case 0x8b55: case 0x8b59: return setValue4iv; // _VEC4
  18856. }
  18857. },
  18858. // Array of scalars
  18859. setValue1fv = function( gl, v ) { gl.uniform1fv( this.addr, v ); },
  18860. setValue1iv = function( gl, v ) { gl.uniform1iv( this.addr, v ); },
  18861. // Array of vectors (flat or from THREE classes)
  18862. setValueV2a = function( gl, v ) {
  18863. gl.uniform2fv( this.addr, flatten( v, this.size, 2 ) );
  18864. },
  18865. setValueV3a = function( gl, v ) {
  18866. gl.uniform3fv( this.addr, flatten( v, this.size, 3 ) );
  18867. },
  18868. setValueV4a = function( gl, v ) {
  18869. gl.uniform4fv( this.addr, flatten( v, this.size, 4 ) );
  18870. },
  18871. // Array of matrices (flat or from THREE clases)
  18872. setValueM2a = function( gl, v ) {
  18873. gl.uniformMatrix2fv( this.addr, false, flatten( v, this.size, 4 ) );
  18874. },
  18875. setValueM3a = function( gl, v ) {
  18876. gl.uniformMatrix3fv( this.addr, false, flatten( v, this.size, 9 ) );
  18877. },
  18878. setValueM4a = function( gl, v ) {
  18879. gl.uniformMatrix4fv( this.addr, false, flatten( v, this.size, 16 ) );
  18880. },
  18881. // Array of textures (2D / Cube)
  18882. setValueT1a = function( gl, v, renderer ) {
  18883. var n = v.length,
  18884. units = allocTexUnits( renderer, n );
  18885. gl.uniform1iv( this.addr, units );
  18886. for ( var i = 0; i !== n; ++ i ) {
  18887. renderer.setTexture2D( v[ i ] || emptyTexture, units[ i ] );
  18888. }
  18889. },
  18890. setValueT6a = function( gl, v, renderer ) {
  18891. var n = v.length,
  18892. units = allocTexUnits( renderer, n );
  18893. gl.uniform1iv( this.addr, units );
  18894. for ( var i = 0; i !== n; ++ i ) {
  18895. renderer.setTextureCube( v[ i ] || emptyCubeTexture, units[ i ] );
  18896. }
  18897. },
  18898. // Helper to pick the right setter for a pure (bottom-level) array
  18899. getPureArraySetter = function( type ) {
  18900. switch ( type ) {
  18901. case 0x1406: return setValue1fv; // FLOAT
  18902. case 0x8b50: return setValueV2a; // _VEC2
  18903. case 0x8b51: return setValueV3a; // _VEC3
  18904. case 0x8b52: return setValueV4a; // _VEC4
  18905. case 0x8b5a: return setValueM2a; // _MAT2
  18906. case 0x8b5b: return setValueM3a; // _MAT3
  18907. case 0x8b5c: return setValueM4a; // _MAT4
  18908. case 0x8b5e: return setValueT1a; // SAMPLER_2D
  18909. case 0x8b60: return setValueT6a; // SAMPLER_CUBE
  18910. case 0x1404: case 0x8b56: return setValue1iv; // INT, BOOL
  18911. case 0x8b53: case 0x8b57: return setValue2iv; // _VEC2
  18912. case 0x8b54: case 0x8b58: return setValue3iv; // _VEC3
  18913. case 0x8b55: case 0x8b59: return setValue4iv; // _VEC4
  18914. }
  18915. },
  18916. // --- Uniform Classes ---
  18917. SingleUniform = function SingleUniform( id, activeInfo, addr ) {
  18918. this.id = id;
  18919. this.addr = addr;
  18920. this.setValue = getSingularSetter( activeInfo.type );
  18921. // this.path = activeInfo.name; // DEBUG
  18922. },
  18923. PureArrayUniform = function( id, activeInfo, addr ) {
  18924. this.id = id;
  18925. this.addr = addr;
  18926. this.size = activeInfo.size;
  18927. this.setValue = getPureArraySetter( activeInfo.type );
  18928. // this.path = activeInfo.name; // DEBUG
  18929. },
  18930. StructuredUniform = function( id ) {
  18931. this.id = id;
  18932. UniformContainer.call( this ); // mix-in
  18933. };
  18934. StructuredUniform.prototype.setValue = function( gl, value ) {
  18935. // Note: Don't need an extra 'renderer' parameter, since samplers
  18936. // are not allowed in structured uniforms.
  18937. var seq = this.seq;
  18938. for ( var i = 0, n = seq.length; i !== n; ++ i ) {
  18939. var u = seq[ i ];
  18940. u.setValue( gl, value[ u.id ] );
  18941. }
  18942. };
  18943. // --- Top-level ---
  18944. // Parser - builds up the property tree from the path strings
  18945. var RePathPart = /([\w\d_]+)(\])?(\[|\.)?/g,
  18946. // extracts
  18947. // - the identifier (member name or array index)
  18948. // - followed by an optional right bracket (found when array index)
  18949. // - followed by an optional left bracket or dot (type of subscript)
  18950. //
  18951. // Note: These portions can be read in a non-overlapping fashion and
  18952. // allow straightforward parsing of the hierarchy that WebGL encodes
  18953. // in the uniform names.
  18954. addUniform = function( container, uniformObject ) {
  18955. container.seq.push( uniformObject );
  18956. container.map[ uniformObject.id ] = uniformObject;
  18957. },
  18958. parseUniform = function( activeInfo, addr, container ) {
  18959. var path = activeInfo.name,
  18960. pathLength = path.length;
  18961. // reset RegExp object, because of the early exit of a previous run
  18962. RePathPart.lastIndex = 0;
  18963. for (; ;) {
  18964. var match = RePathPart.exec( path ),
  18965. matchEnd = RePathPart.lastIndex,
  18966. id = match[ 1 ],
  18967. idIsIndex = match[ 2 ] === ']',
  18968. subscript = match[ 3 ];
  18969. if ( idIsIndex ) id = id | 0; // convert to integer
  18970. if ( subscript === undefined ||
  18971. subscript === '[' && matchEnd + 2 === pathLength ) {
  18972. // bare name or "pure" bottom-level array "[0]" suffix
  18973. addUniform( container, subscript === undefined ?
  18974. new SingleUniform( id, activeInfo, addr ) :
  18975. new PureArrayUniform( id, activeInfo, addr ) );
  18976. break;
  18977. } else {
  18978. // step into inner node / create it in case it doesn't exist
  18979. var map = container.map,
  18980. next = map[ id ];
  18981. if ( next === undefined ) {
  18982. next = new StructuredUniform( id );
  18983. addUniform( container, next );
  18984. }
  18985. container = next;
  18986. }
  18987. }
  18988. },
  18989. // Root Container
  18990. WebGLUniforms = function WebGLUniforms( gl, program, renderer ) {
  18991. UniformContainer.call( this );
  18992. this.renderer = renderer;
  18993. var n = gl.getProgramParameter( program, gl.ACTIVE_UNIFORMS );
  18994. for ( var i = 0; i !== n; ++ i ) {
  18995. var info = gl.getActiveUniform( program, i ),
  18996. path = info.name,
  18997. addr = gl.getUniformLocation( program, path );
  18998. parseUniform( info, addr, this );
  18999. }
  19000. };
  19001. WebGLUniforms.prototype.setValue = function( gl, name, value ) {
  19002. var u = this.map[ name ];
  19003. if ( u !== undefined ) u.setValue( gl, value, this.renderer );
  19004. };
  19005. WebGLUniforms.prototype.set = function( gl, object, name ) {
  19006. var u = this.map[ name ];
  19007. if ( u !== undefined ) u.setValue( gl, object[ name ], this.renderer );
  19008. };
  19009. WebGLUniforms.prototype.setOptional = function( gl, object, name ) {
  19010. var v = object[ name ];
  19011. if ( v !== undefined ) this.setValue( gl, name, v );
  19012. };
  19013. // Static interface
  19014. WebGLUniforms.upload = function( gl, seq, values, renderer ) {
  19015. for ( var i = 0, n = seq.length; i !== n; ++ i ) {
  19016. var u = seq[ i ],
  19017. v = values[ u.id ];
  19018. if ( v.needsUpdate !== false ) {
  19019. // note: always updating when .needsUpdate is undefined
  19020. u.setValue( gl, v.value, renderer );
  19021. }
  19022. }
  19023. };
  19024. WebGLUniforms.seqWithValue = function( seq, values ) {
  19025. var r = [];
  19026. for ( var i = 0, n = seq.length; i !== n; ++ i ) {
  19027. var u = seq[ i ];
  19028. if ( u.id in values ) r.push( u );
  19029. }
  19030. return r;
  19031. };
  19032. WebGLUniforms.splitDynamic = function( seq, values ) {
  19033. var r = null,
  19034. n = seq.length,
  19035. w = 0;
  19036. for ( var i = 0; i !== n; ++ i ) {
  19037. var u = seq[ i ],
  19038. v = values[ u.id ];
  19039. if ( v && v.dynamic === true ) {
  19040. if ( r === null ) r = [];
  19041. r.push( u );
  19042. } else {
  19043. // in-place compact 'seq', removing the matches
  19044. if ( w < i ) seq[ w ] = u;
  19045. ++ w;
  19046. }
  19047. }
  19048. if ( w < n ) seq.length = w;
  19049. return r;
  19050. };
  19051. WebGLUniforms.evalDynamic = function( seq, values, object, camera ) {
  19052. for ( var i = 0, n = seq.length; i !== n; ++ i ) {
  19053. var v = values[ seq[ i ].id ],
  19054. f = v.onUpdateCallback;
  19055. if ( f !== undefined ) f.call( v, object, camera );
  19056. }
  19057. };
  19058. return WebGLUniforms;
  19059. } )();
  19060. // File:src/renderers/webgl/plugins/LensFlarePlugin.js
  19061. /**
  19062. * @author mikael emtinger / http://gomo.se/
  19063. * @author alteredq / http://alteredqualia.com/
  19064. */
  19065. THREE.LensFlarePlugin = function ( renderer, flares ) {
  19066. var gl = renderer.context;
  19067. var state = renderer.state;
  19068. var vertexBuffer, elementBuffer;
  19069. var shader, program, attributes, uniforms;
  19070. var tempTexture, occlusionTexture;
  19071. function init() {
  19072. var vertices = new Float32Array( [
  19073. - 1, - 1, 0, 0,
  19074. 1, - 1, 1, 0,
  19075. 1, 1, 1, 1,
  19076. - 1, 1, 0, 1
  19077. ] );
  19078. var faces = new Uint16Array( [
  19079. 0, 1, 2,
  19080. 0, 2, 3
  19081. ] );
  19082. // buffers
  19083. vertexBuffer = gl.createBuffer();
  19084. elementBuffer = gl.createBuffer();
  19085. gl.bindBuffer( gl.ARRAY_BUFFER, vertexBuffer );
  19086. gl.bufferData( gl.ARRAY_BUFFER, vertices, gl.STATIC_DRAW );
  19087. gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, elementBuffer );
  19088. gl.bufferData( gl.ELEMENT_ARRAY_BUFFER, faces, gl.STATIC_DRAW );
  19089. // textures
  19090. tempTexture = gl.createTexture();
  19091. occlusionTexture = gl.createTexture();
  19092. state.bindTexture( gl.TEXTURE_2D, tempTexture );
  19093. gl.texImage2D( gl.TEXTURE_2D, 0, gl.RGB, 16, 16, 0, gl.RGB, gl.UNSIGNED_BYTE, null );
  19094. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE );
  19095. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE );
  19096. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST );
  19097. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST );
  19098. state.bindTexture( gl.TEXTURE_2D, occlusionTexture );
  19099. gl.texImage2D( gl.TEXTURE_2D, 0, gl.RGBA, 16, 16, 0, gl.RGBA, gl.UNSIGNED_BYTE, null );
  19100. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE );
  19101. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE );
  19102. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST );
  19103. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST );
  19104. shader = {
  19105. vertexShader: [
  19106. "uniform lowp int renderType;",
  19107. "uniform vec3 screenPosition;",
  19108. "uniform vec2 scale;",
  19109. "uniform float rotation;",
  19110. "uniform sampler2D occlusionMap;",
  19111. "attribute vec2 position;",
  19112. "attribute vec2 uv;",
  19113. "varying vec2 vUV;",
  19114. "varying float vVisibility;",
  19115. "void main() {",
  19116. "vUV = uv;",
  19117. "vec2 pos = position;",
  19118. "if ( renderType == 2 ) {",
  19119. "vec4 visibility = texture2D( occlusionMap, vec2( 0.1, 0.1 ) );",
  19120. "visibility += texture2D( occlusionMap, vec2( 0.5, 0.1 ) );",
  19121. "visibility += texture2D( occlusionMap, vec2( 0.9, 0.1 ) );",
  19122. "visibility += texture2D( occlusionMap, vec2( 0.9, 0.5 ) );",
  19123. "visibility += texture2D( occlusionMap, vec2( 0.9, 0.9 ) );",
  19124. "visibility += texture2D( occlusionMap, vec2( 0.5, 0.9 ) );",
  19125. "visibility += texture2D( occlusionMap, vec2( 0.1, 0.9 ) );",
  19126. "visibility += texture2D( occlusionMap, vec2( 0.1, 0.5 ) );",
  19127. "visibility += texture2D( occlusionMap, vec2( 0.5, 0.5 ) );",
  19128. "vVisibility = visibility.r / 9.0;",
  19129. "vVisibility *= 1.0 - visibility.g / 9.0;",
  19130. "vVisibility *= visibility.b / 9.0;",
  19131. "vVisibility *= 1.0 - visibility.a / 9.0;",
  19132. "pos.x = cos( rotation ) * position.x - sin( rotation ) * position.y;",
  19133. "pos.y = sin( rotation ) * position.x + cos( rotation ) * position.y;",
  19134. "}",
  19135. "gl_Position = vec4( ( pos * scale + screenPosition.xy ).xy, screenPosition.z, 1.0 );",
  19136. "}"
  19137. ].join( "\n" ),
  19138. fragmentShader: [
  19139. "uniform lowp int renderType;",
  19140. "uniform sampler2D map;",
  19141. "uniform float opacity;",
  19142. "uniform vec3 color;",
  19143. "varying vec2 vUV;",
  19144. "varying float vVisibility;",
  19145. "void main() {",
  19146. // pink square
  19147. "if ( renderType == 0 ) {",
  19148. "gl_FragColor = vec4( 1.0, 0.0, 1.0, 0.0 );",
  19149. // restore
  19150. "} else if ( renderType == 1 ) {",
  19151. "gl_FragColor = texture2D( map, vUV );",
  19152. // flare
  19153. "} else {",
  19154. "vec4 texture = texture2D( map, vUV );",
  19155. "texture.a *= opacity * vVisibility;",
  19156. "gl_FragColor = texture;",
  19157. "gl_FragColor.rgb *= color;",
  19158. "}",
  19159. "}"
  19160. ].join( "\n" )
  19161. };
  19162. program = createProgram( shader );
  19163. attributes = {
  19164. vertex: gl.getAttribLocation ( program, "position" ),
  19165. uv: gl.getAttribLocation ( program, "uv" )
  19166. };
  19167. uniforms = {
  19168. renderType: gl.getUniformLocation( program, "renderType" ),
  19169. map: gl.getUniformLocation( program, "map" ),
  19170. occlusionMap: gl.getUniformLocation( program, "occlusionMap" ),
  19171. opacity: gl.getUniformLocation( program, "opacity" ),
  19172. color: gl.getUniformLocation( program, "color" ),
  19173. scale: gl.getUniformLocation( program, "scale" ),
  19174. rotation: gl.getUniformLocation( program, "rotation" ),
  19175. screenPosition: gl.getUniformLocation( program, "screenPosition" )
  19176. };
  19177. }
  19178. /*
  19179. * Render lens flares
  19180. * Method: renders 16x16 0xff00ff-colored points scattered over the light source area,
  19181. * reads these back and calculates occlusion.
  19182. */
  19183. this.render = function ( scene, camera, viewport ) {
  19184. if ( flares.length === 0 ) return;
  19185. var tempPosition = new THREE.Vector3();
  19186. var invAspect = viewport.w / viewport.z,
  19187. halfViewportWidth = viewport.z * 0.5,
  19188. halfViewportHeight = viewport.w * 0.5;
  19189. var size = 16 / viewport.w,
  19190. scale = new THREE.Vector2( size * invAspect, size );
  19191. var screenPosition = new THREE.Vector3( 1, 1, 0 ),
  19192. screenPositionPixels = new THREE.Vector2( 1, 1 );
  19193. var validArea = new THREE.Box2();
  19194. validArea.min.set( 0, 0 );
  19195. validArea.max.set( viewport.z - 16, viewport.w - 16 );
  19196. if ( program === undefined ) {
  19197. init();
  19198. }
  19199. gl.useProgram( program );
  19200. state.initAttributes();
  19201. state.enableAttribute( attributes.vertex );
  19202. state.enableAttribute( attributes.uv );
  19203. state.disableUnusedAttributes();
  19204. // loop through all lens flares to update their occlusion and positions
  19205. // setup gl and common used attribs/uniforms
  19206. gl.uniform1i( uniforms.occlusionMap, 0 );
  19207. gl.uniform1i( uniforms.map, 1 );
  19208. gl.bindBuffer( gl.ARRAY_BUFFER, vertexBuffer );
  19209. gl.vertexAttribPointer( attributes.vertex, 2, gl.FLOAT, false, 2 * 8, 0 );
  19210. gl.vertexAttribPointer( attributes.uv, 2, gl.FLOAT, false, 2 * 8, 8 );
  19211. gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, elementBuffer );
  19212. state.disable( gl.CULL_FACE );
  19213. state.setDepthWrite( false );
  19214. for ( var i = 0, l = flares.length; i < l; i ++ ) {
  19215. size = 16 / viewport.w;
  19216. scale.set( size * invAspect, size );
  19217. // calc object screen position
  19218. var flare = flares[ i ];
  19219. tempPosition.set( flare.matrixWorld.elements[ 12 ], flare.matrixWorld.elements[ 13 ], flare.matrixWorld.elements[ 14 ] );
  19220. tempPosition.applyMatrix4( camera.matrixWorldInverse );
  19221. tempPosition.applyProjection( camera.projectionMatrix );
  19222. // setup arrays for gl programs
  19223. screenPosition.copy( tempPosition );
  19224. // horizontal and vertical coordinate of the lower left corner of the pixels to copy
  19225. screenPositionPixels.x = viewport.x + ( screenPosition.x * halfViewportWidth ) + halfViewportWidth - 8;
  19226. screenPositionPixels.y = viewport.y + ( screenPosition.y * halfViewportHeight ) + halfViewportHeight - 8;
  19227. // screen cull
  19228. if ( validArea.containsPoint( screenPositionPixels ) === true ) {
  19229. // save current RGB to temp texture
  19230. state.activeTexture( gl.TEXTURE0 );
  19231. state.bindTexture( gl.TEXTURE_2D, null );
  19232. state.activeTexture( gl.TEXTURE1 );
  19233. state.bindTexture( gl.TEXTURE_2D, tempTexture );
  19234. gl.copyTexImage2D( gl.TEXTURE_2D, 0, gl.RGB, screenPositionPixels.x, screenPositionPixels.y, 16, 16, 0 );
  19235. // render pink quad
  19236. gl.uniform1i( uniforms.renderType, 0 );
  19237. gl.uniform2f( uniforms.scale, scale.x, scale.y );
  19238. gl.uniform3f( uniforms.screenPosition, screenPosition.x, screenPosition.y, screenPosition.z );
  19239. state.disable( gl.BLEND );
  19240. state.enable( gl.DEPTH_TEST );
  19241. gl.drawElements( gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 );
  19242. // copy result to occlusionMap
  19243. state.activeTexture( gl.TEXTURE0 );
  19244. state.bindTexture( gl.TEXTURE_2D, occlusionTexture );
  19245. gl.copyTexImage2D( gl.TEXTURE_2D, 0, gl.RGBA, screenPositionPixels.x, screenPositionPixels.y, 16, 16, 0 );
  19246. // restore graphics
  19247. gl.uniform1i( uniforms.renderType, 1 );
  19248. state.disable( gl.DEPTH_TEST );
  19249. state.activeTexture( gl.TEXTURE1 );
  19250. state.bindTexture( gl.TEXTURE_2D, tempTexture );
  19251. gl.drawElements( gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 );
  19252. // update object positions
  19253. flare.positionScreen.copy( screenPosition );
  19254. if ( flare.customUpdateCallback ) {
  19255. flare.customUpdateCallback( flare );
  19256. } else {
  19257. flare.updateLensFlares();
  19258. }
  19259. // render flares
  19260. gl.uniform1i( uniforms.renderType, 2 );
  19261. state.enable( gl.BLEND );
  19262. for ( var j = 0, jl = flare.lensFlares.length; j < jl; j ++ ) {
  19263. var sprite = flare.lensFlares[ j ];
  19264. if ( sprite.opacity > 0.001 && sprite.scale > 0.001 ) {
  19265. screenPosition.x = sprite.x;
  19266. screenPosition.y = sprite.y;
  19267. screenPosition.z = sprite.z;
  19268. size = sprite.size * sprite.scale / viewport.w;
  19269. scale.x = size * invAspect;
  19270. scale.y = size;
  19271. gl.uniform3f( uniforms.screenPosition, screenPosition.x, screenPosition.y, screenPosition.z );
  19272. gl.uniform2f( uniforms.scale, scale.x, scale.y );
  19273. gl.uniform1f( uniforms.rotation, sprite.rotation );
  19274. gl.uniform1f( uniforms.opacity, sprite.opacity );
  19275. gl.uniform3f( uniforms.color, sprite.color.r, sprite.color.g, sprite.color.b );
  19276. state.setBlending( sprite.blending, sprite.blendEquation, sprite.blendSrc, sprite.blendDst );
  19277. renderer.setTexture2D( sprite.texture, 1 );
  19278. gl.drawElements( gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 );
  19279. }
  19280. }
  19281. }
  19282. }
  19283. // restore gl
  19284. state.enable( gl.CULL_FACE );
  19285. state.enable( gl.DEPTH_TEST );
  19286. state.setDepthWrite( true );
  19287. renderer.resetGLState();
  19288. };
  19289. function createProgram ( shader ) {
  19290. var program = gl.createProgram();
  19291. var fragmentShader = gl.createShader( gl.FRAGMENT_SHADER );
  19292. var vertexShader = gl.createShader( gl.VERTEX_SHADER );
  19293. var prefix = "precision " + renderer.getPrecision() + " float;\n";
  19294. gl.shaderSource( fragmentShader, prefix + shader.fragmentShader );
  19295. gl.shaderSource( vertexShader, prefix + shader.vertexShader );
  19296. gl.compileShader( fragmentShader );
  19297. gl.compileShader( vertexShader );
  19298. gl.attachShader( program, fragmentShader );
  19299. gl.attachShader( program, vertexShader );
  19300. gl.linkProgram( program );
  19301. return program;
  19302. }
  19303. };
  19304. // File:src/renderers/webgl/plugins/SpritePlugin.js
  19305. /**
  19306. * @author mikael emtinger / http://gomo.se/
  19307. * @author alteredq / http://alteredqualia.com/
  19308. */
  19309. THREE.SpritePlugin = function ( renderer, sprites ) {
  19310. var gl = renderer.context;
  19311. var state = renderer.state;
  19312. var vertexBuffer, elementBuffer;
  19313. var program, attributes, uniforms;
  19314. var texture;
  19315. // decompose matrixWorld
  19316. var spritePosition = new THREE.Vector3();
  19317. var spriteRotation = new THREE.Quaternion();
  19318. var spriteScale = new THREE.Vector3();
  19319. function init() {
  19320. var vertices = new Float32Array( [
  19321. - 0.5, - 0.5, 0, 0,
  19322. 0.5, - 0.5, 1, 0,
  19323. 0.5, 0.5, 1, 1,
  19324. - 0.5, 0.5, 0, 1
  19325. ] );
  19326. var faces = new Uint16Array( [
  19327. 0, 1, 2,
  19328. 0, 2, 3
  19329. ] );
  19330. vertexBuffer = gl.createBuffer();
  19331. elementBuffer = gl.createBuffer();
  19332. gl.bindBuffer( gl.ARRAY_BUFFER, vertexBuffer );
  19333. gl.bufferData( gl.ARRAY_BUFFER, vertices, gl.STATIC_DRAW );
  19334. gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, elementBuffer );
  19335. gl.bufferData( gl.ELEMENT_ARRAY_BUFFER, faces, gl.STATIC_DRAW );
  19336. program = createProgram();
  19337. attributes = {
  19338. position: gl.getAttribLocation ( program, 'position' ),
  19339. uv: gl.getAttribLocation ( program, 'uv' )
  19340. };
  19341. uniforms = {
  19342. uvOffset: gl.getUniformLocation( program, 'uvOffset' ),
  19343. uvScale: gl.getUniformLocation( program, 'uvScale' ),
  19344. rotation: gl.getUniformLocation( program, 'rotation' ),
  19345. scale: gl.getUniformLocation( program, 'scale' ),
  19346. color: gl.getUniformLocation( program, 'color' ),
  19347. map: gl.getUniformLocation( program, 'map' ),
  19348. opacity: gl.getUniformLocation( program, 'opacity' ),
  19349. modelViewMatrix: gl.getUniformLocation( program, 'modelViewMatrix' ),
  19350. projectionMatrix: gl.getUniformLocation( program, 'projectionMatrix' ),
  19351. fogType: gl.getUniformLocation( program, 'fogType' ),
  19352. fogDensity: gl.getUniformLocation( program, 'fogDensity' ),
  19353. fogNear: gl.getUniformLocation( program, 'fogNear' ),
  19354. fogFar: gl.getUniformLocation( program, 'fogFar' ),
  19355. fogColor: gl.getUniformLocation( program, 'fogColor' ),
  19356. alphaTest: gl.getUniformLocation( program, 'alphaTest' )
  19357. };
  19358. var canvas = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' );
  19359. canvas.width = 8;
  19360. canvas.height = 8;
  19361. var context = canvas.getContext( '2d' );
  19362. context.fillStyle = 'white';
  19363. context.fillRect( 0, 0, 8, 8 );
  19364. texture = new THREE.Texture( canvas );
  19365. texture.needsUpdate = true;
  19366. }
  19367. this.render = function ( scene, camera ) {
  19368. if ( sprites.length === 0 ) return;
  19369. // setup gl
  19370. if ( program === undefined ) {
  19371. init();
  19372. }
  19373. gl.useProgram( program );
  19374. state.initAttributes();
  19375. state.enableAttribute( attributes.position );
  19376. state.enableAttribute( attributes.uv );
  19377. state.disableUnusedAttributes();
  19378. state.disable( gl.CULL_FACE );
  19379. state.enable( gl.BLEND );
  19380. gl.bindBuffer( gl.ARRAY_BUFFER, vertexBuffer );
  19381. gl.vertexAttribPointer( attributes.position, 2, gl.FLOAT, false, 2 * 8, 0 );
  19382. gl.vertexAttribPointer( attributes.uv, 2, gl.FLOAT, false, 2 * 8, 8 );
  19383. gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, elementBuffer );
  19384. gl.uniformMatrix4fv( uniforms.projectionMatrix, false, camera.projectionMatrix.elements );
  19385. state.activeTexture( gl.TEXTURE0 );
  19386. gl.uniform1i( uniforms.map, 0 );
  19387. var oldFogType = 0;
  19388. var sceneFogType = 0;
  19389. var fog = scene.fog;
  19390. if ( fog ) {
  19391. gl.uniform3f( uniforms.fogColor, fog.color.r, fog.color.g, fog.color.b );
  19392. if ( fog instanceof THREE.Fog ) {
  19393. gl.uniform1f( uniforms.fogNear, fog.near );
  19394. gl.uniform1f( uniforms.fogFar, fog.far );
  19395. gl.uniform1i( uniforms.fogType, 1 );
  19396. oldFogType = 1;
  19397. sceneFogType = 1;
  19398. } else if ( fog instanceof THREE.FogExp2 ) {
  19399. gl.uniform1f( uniforms.fogDensity, fog.density );
  19400. gl.uniform1i( uniforms.fogType, 2 );
  19401. oldFogType = 2;
  19402. sceneFogType = 2;
  19403. }
  19404. } else {
  19405. gl.uniform1i( uniforms.fogType, 0 );
  19406. oldFogType = 0;
  19407. sceneFogType = 0;
  19408. }
  19409. // update positions and sort
  19410. for ( var i = 0, l = sprites.length; i < l; i ++ ) {
  19411. var sprite = sprites[ i ];
  19412. sprite.modelViewMatrix.multiplyMatrices( camera.matrixWorldInverse, sprite.matrixWorld );
  19413. sprite.z = - sprite.modelViewMatrix.elements[ 14 ];
  19414. }
  19415. sprites.sort( painterSortStable );
  19416. // render all sprites
  19417. var scale = [];
  19418. for ( var i = 0, l = sprites.length; i < l; i ++ ) {
  19419. var sprite = sprites[ i ];
  19420. var material = sprite.material;
  19421. gl.uniform1f( uniforms.alphaTest, material.alphaTest );
  19422. gl.uniformMatrix4fv( uniforms.modelViewMatrix, false, sprite.modelViewMatrix.elements );
  19423. sprite.matrixWorld.decompose( spritePosition, spriteRotation, spriteScale );
  19424. scale[ 0 ] = spriteScale.x;
  19425. scale[ 1 ] = spriteScale.y;
  19426. var fogType = 0;
  19427. if ( scene.fog && material.fog ) {
  19428. fogType = sceneFogType;
  19429. }
  19430. if ( oldFogType !== fogType ) {
  19431. gl.uniform1i( uniforms.fogType, fogType );
  19432. oldFogType = fogType;
  19433. }
  19434. if ( material.map !== null ) {
  19435. gl.uniform2f( uniforms.uvOffset, material.map.offset.x, material.map.offset.y );
  19436. gl.uniform2f( uniforms.uvScale, material.map.repeat.x, material.map.repeat.y );
  19437. } else {
  19438. gl.uniform2f( uniforms.uvOffset, 0, 0 );
  19439. gl.uniform2f( uniforms.uvScale, 1, 1 );
  19440. }
  19441. gl.uniform1f( uniforms.opacity, material.opacity );
  19442. gl.uniform3f( uniforms.color, material.color.r, material.color.g, material.color.b );
  19443. gl.uniform1f( uniforms.rotation, material.rotation );
  19444. gl.uniform2fv( uniforms.scale, scale );
  19445. state.setBlending( material.blending, material.blendEquation, material.blendSrc, material.blendDst );
  19446. state.setDepthTest( material.depthTest );
  19447. state.setDepthWrite( material.depthWrite );
  19448. if ( material.map ) {
  19449. renderer.setTexture2D( material.map, 0 );
  19450. } else {
  19451. renderer.setTexture2D( texture, 0 );
  19452. }
  19453. gl.drawElements( gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 );
  19454. }
  19455. // restore gl
  19456. state.enable( gl.CULL_FACE );
  19457. renderer.resetGLState();
  19458. };
  19459. function createProgram () {
  19460. var program = gl.createProgram();
  19461. var vertexShader = gl.createShader( gl.VERTEX_SHADER );
  19462. var fragmentShader = gl.createShader( gl.FRAGMENT_SHADER );
  19463. gl.shaderSource( vertexShader, [
  19464. 'precision ' + renderer.getPrecision() + ' float;',
  19465. 'uniform mat4 modelViewMatrix;',
  19466. 'uniform mat4 projectionMatrix;',
  19467. 'uniform float rotation;',
  19468. 'uniform vec2 scale;',
  19469. 'uniform vec2 uvOffset;',
  19470. 'uniform vec2 uvScale;',
  19471. 'attribute vec2 position;',
  19472. 'attribute vec2 uv;',
  19473. 'varying vec2 vUV;',
  19474. 'void main() {',
  19475. 'vUV = uvOffset + uv * uvScale;',
  19476. 'vec2 alignedPosition = position * scale;',
  19477. 'vec2 rotatedPosition;',
  19478. 'rotatedPosition.x = cos( rotation ) * alignedPosition.x - sin( rotation ) * alignedPosition.y;',
  19479. 'rotatedPosition.y = sin( rotation ) * alignedPosition.x + cos( rotation ) * alignedPosition.y;',
  19480. 'vec4 finalPosition;',
  19481. 'finalPosition = modelViewMatrix * vec4( 0.0, 0.0, 0.0, 1.0 );',
  19482. 'finalPosition.xy += rotatedPosition;',
  19483. 'finalPosition = projectionMatrix * finalPosition;',
  19484. 'gl_Position = finalPosition;',
  19485. '}'
  19486. ].join( '\n' ) );
  19487. gl.shaderSource( fragmentShader, [
  19488. 'precision ' + renderer.getPrecision() + ' float;',
  19489. 'uniform vec3 color;',
  19490. 'uniform sampler2D map;',
  19491. 'uniform float opacity;',
  19492. 'uniform int fogType;',
  19493. 'uniform vec3 fogColor;',
  19494. 'uniform float fogDensity;',
  19495. 'uniform float fogNear;',
  19496. 'uniform float fogFar;',
  19497. 'uniform float alphaTest;',
  19498. 'varying vec2 vUV;',
  19499. 'void main() {',
  19500. 'vec4 texture = texture2D( map, vUV );',
  19501. 'if ( texture.a < alphaTest ) discard;',
  19502. 'gl_FragColor = vec4( color * texture.xyz, texture.a * opacity );',
  19503. 'if ( fogType > 0 ) {',
  19504. 'float depth = gl_FragCoord.z / gl_FragCoord.w;',
  19505. 'float fogFactor = 0.0;',
  19506. 'if ( fogType == 1 ) {',
  19507. 'fogFactor = smoothstep( fogNear, fogFar, depth );',
  19508. '} else {',
  19509. 'const float LOG2 = 1.442695;',
  19510. 'fogFactor = exp2( - fogDensity * fogDensity * depth * depth * LOG2 );',
  19511. 'fogFactor = 1.0 - clamp( fogFactor, 0.0, 1.0 );',
  19512. '}',
  19513. 'gl_FragColor = mix( gl_FragColor, vec4( fogColor, gl_FragColor.w ), fogFactor );',
  19514. '}',
  19515. '}'
  19516. ].join( '\n' ) );
  19517. gl.compileShader( vertexShader );
  19518. gl.compileShader( fragmentShader );
  19519. gl.attachShader( program, vertexShader );
  19520. gl.attachShader( program, fragmentShader );
  19521. gl.linkProgram( program );
  19522. return program;
  19523. }
  19524. function painterSortStable ( a, b ) {
  19525. if ( a.renderOrder !== b.renderOrder ) {
  19526. return a.renderOrder - b.renderOrder;
  19527. } else if ( a.z !== b.z ) {
  19528. return b.z - a.z;
  19529. } else {
  19530. return b.id - a.id;
  19531. }
  19532. }
  19533. };
  19534. // File:src/Three.Legacy.js
  19535. /**
  19536. * @author mrdoob / http://mrdoob.com/
  19537. */
  19538. Object.assign( THREE, {
  19539. Face4: function ( a, b, c, d, normal, color, materialIndex ) {
  19540. console.warn( 'THREE.Face4 has been removed. A THREE.Face3 will be created instead.' );
  19541. return new THREE.Face3( a, b, c, normal, color, materialIndex );
  19542. },
  19543. LineStrip: 0,
  19544. LinePieces: 1,
  19545. MeshFaceMaterial: THREE.MultiMaterial,
  19546. PointCloud: function ( geometry, material ) {
  19547. console.warn( 'THREE.PointCloud has been renamed to THREE.Points.' );
  19548. return new THREE.Points( geometry, material );
  19549. },
  19550. Particle: THREE.Sprite,
  19551. ParticleSystem: function ( geometry, material ) {
  19552. console.warn( 'THREE.ParticleSystem has been renamed to THREE.Points.' );
  19553. return new THREE.Points( geometry, material );
  19554. },
  19555. PointCloudMaterial: function ( parameters ) {
  19556. console.warn( 'THREE.PointCloudMaterial has been renamed to THREE.PointsMaterial.' );
  19557. return new THREE.PointsMaterial( parameters );
  19558. },
  19559. ParticleBasicMaterial: function ( parameters ) {
  19560. console.warn( 'THREE.ParticleBasicMaterial has been renamed to THREE.PointsMaterial.' );
  19561. return new THREE.PointsMaterial( parameters );
  19562. },
  19563. ParticleSystemMaterial: function ( parameters ) {
  19564. console.warn( 'THREE.ParticleSystemMaterial has been renamed to THREE.PointsMaterial.' );
  19565. return new THREE.PointsMaterial( parameters );
  19566. },
  19567. Vertex: function ( x, y, z ) {
  19568. console.warn( 'THREE.Vertex has been removed. Use THREE.Vector3 instead.' );
  19569. return new THREE.Vector3( x, y, z );
  19570. }
  19571. } );
  19572. //
  19573. Object.assign( THREE.Box2.prototype, {
  19574. empty: function () {
  19575. console.warn( 'THREE.Box2: .empty() has been renamed to .isEmpty().' );
  19576. return this.isEmpty();
  19577. },
  19578. isIntersectionBox: function ( box ) {
  19579. console.warn( 'THREE.Box2: .isIntersectionBox() has been renamed to .intersectsBox().' );
  19580. return this.intersectsBox( box );
  19581. }
  19582. } );
  19583. Object.assign( THREE.Box3.prototype, {
  19584. empty: function () {
  19585. console.warn( 'THREE.Box3: .empty() has been renamed to .isEmpty().' );
  19586. return this.isEmpty();
  19587. },
  19588. isIntersectionBox: function ( box ) {
  19589. console.warn( 'THREE.Box3: .isIntersectionBox() has been renamed to .intersectsBox().' );
  19590. return this.intersectsBox( box );
  19591. },
  19592. isIntersectionSphere: function ( sphere ) {
  19593. console.warn( 'THREE.Box3: .isIntersectionSphere() has been renamed to .intersectsSphere().' );
  19594. return this.intersectsSphere( sphere );
  19595. }
  19596. } );
  19597. Object.assign( THREE.Matrix3.prototype, {
  19598. multiplyVector3: function ( vector ) {
  19599. console.warn( 'THREE.Matrix3: .multiplyVector3() has been removed. Use vector.applyMatrix3( matrix ) instead.' );
  19600. return vector.applyMatrix3( this );
  19601. },
  19602. multiplyVector3Array: function ( a ) {
  19603. console.warn( 'THREE.Matrix3: .multiplyVector3Array() has been renamed. Use matrix.applyToVector3Array( array ) instead.' );
  19604. return this.applyToVector3Array( a );
  19605. }
  19606. } );
  19607. Object.assign( THREE.Matrix4.prototype, {
  19608. extractPosition: function ( m ) {
  19609. console.warn( 'THREE.Matrix4: .extractPosition() has been renamed to .copyPosition().' );
  19610. return this.copyPosition( m );
  19611. },
  19612. setRotationFromQuaternion: function ( q ) {
  19613. console.warn( 'THREE.Matrix4: .setRotationFromQuaternion() has been renamed to .makeRotationFromQuaternion().' );
  19614. return this.makeRotationFromQuaternion( q );
  19615. },
  19616. multiplyVector3: function ( vector ) {
  19617. console.warn( 'THREE.Matrix4: .multiplyVector3() has been removed. Use vector.applyMatrix4( matrix ) or vector.applyProjection( matrix ) instead.' );
  19618. return vector.applyProjection( this );
  19619. },
  19620. multiplyVector4: function ( vector ) {
  19621. console.warn( 'THREE.Matrix4: .multiplyVector4() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
  19622. return vector.applyMatrix4( this );
  19623. },
  19624. multiplyVector3Array: function ( a ) {
  19625. console.warn( 'THREE.Matrix4: .multiplyVector3Array() has been renamed. Use matrix.applyToVector3Array( array ) instead.' );
  19626. return this.applyToVector3Array( a );
  19627. },
  19628. rotateAxis: function ( v ) {
  19629. console.warn( 'THREE.Matrix4: .rotateAxis() has been removed. Use Vector3.transformDirection( matrix ) instead.' );
  19630. v.transformDirection( this );
  19631. },
  19632. crossVector: function ( vector ) {
  19633. console.warn( 'THREE.Matrix4: .crossVector() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
  19634. return vector.applyMatrix4( this );
  19635. },
  19636. translate: function ( v ) {
  19637. console.error( 'THREE.Matrix4: .translate() has been removed.' );
  19638. },
  19639. rotateX: function ( angle ) {
  19640. console.error( 'THREE.Matrix4: .rotateX() has been removed.' );
  19641. },
  19642. rotateY: function ( angle ) {
  19643. console.error( 'THREE.Matrix4: .rotateY() has been removed.' );
  19644. },
  19645. rotateZ: function ( angle ) {
  19646. console.error( 'THREE.Matrix4: .rotateZ() has been removed.' );
  19647. },
  19648. rotateByAxis: function ( axis, angle ) {
  19649. console.error( 'THREE.Matrix4: .rotateByAxis() has been removed.' );
  19650. }
  19651. } );
  19652. Object.assign( THREE.Plane.prototype, {
  19653. isIntersectionLine: function ( line ) {
  19654. console.warn( 'THREE.Plane: .isIntersectionLine() has been renamed to .intersectsLine().' );
  19655. return this.intersectsLine( line );
  19656. }
  19657. } );
  19658. Object.assign( THREE.Quaternion.prototype, {
  19659. multiplyVector3: function ( vector ) {
  19660. console.warn( 'THREE.Quaternion: .multiplyVector3() has been removed. Use is now vector.applyQuaternion( quaternion ) instead.' );
  19661. return vector.applyQuaternion( this );
  19662. }
  19663. } );
  19664. Object.assign( THREE.Ray.prototype, {
  19665. isIntersectionBox: function ( box ) {
  19666. console.warn( 'THREE.Ray: .isIntersectionBox() has been renamed to .intersectsBox().' );
  19667. return this.intersectsBox( box );
  19668. },
  19669. isIntersectionPlane: function ( plane ) {
  19670. console.warn( 'THREE.Ray: .isIntersectionPlane() has been renamed to .intersectsPlane().' );
  19671. return this.intersectsPlane( plane );
  19672. },
  19673. isIntersectionSphere: function ( sphere ) {
  19674. console.warn( 'THREE.Ray: .isIntersectionSphere() has been renamed to .intersectsSphere().' );
  19675. return this.intersectsSphere( sphere );
  19676. }
  19677. } );
  19678. Object.assign( THREE.Vector3.prototype, {
  19679. setEulerFromRotationMatrix: function () {
  19680. console.error( 'THREE.Vector3: .setEulerFromRotationMatrix() has been removed. Use Euler.setFromRotationMatrix() instead.' );
  19681. },
  19682. setEulerFromQuaternion: function () {
  19683. console.error( 'THREE.Vector3: .setEulerFromQuaternion() has been removed. Use Euler.setFromQuaternion() instead.' );
  19684. },
  19685. getPositionFromMatrix: function ( m ) {
  19686. console.warn( 'THREE.Vector3: .getPositionFromMatrix() has been renamed to .setFromMatrixPosition().' );
  19687. return this.setFromMatrixPosition( m );
  19688. },
  19689. getScaleFromMatrix: function ( m ) {
  19690. console.warn( 'THREE.Vector3: .getScaleFromMatrix() has been renamed to .setFromMatrixScale().' );
  19691. return this.setFromMatrixScale( m );
  19692. },
  19693. getColumnFromMatrix: function ( index, matrix ) {
  19694. console.warn( 'THREE.Vector3: .getColumnFromMatrix() has been renamed to .setFromMatrixColumn().' );
  19695. return this.setFromMatrixColumn( matrix, index );
  19696. }
  19697. } );
  19698. //
  19699. Object.assign( THREE.Object3D.prototype, {
  19700. getChildByName: function ( name ) {
  19701. console.warn( 'THREE.Object3D: .getChildByName() has been renamed to .getObjectByName().' );
  19702. return this.getObjectByName( name );
  19703. },
  19704. renderDepth: function ( value ) {
  19705. console.warn( 'THREE.Object3D: .renderDepth has been removed. Use .renderOrder, instead.' );
  19706. },
  19707. translate: function ( distance, axis ) {
  19708. console.warn( 'THREE.Object3D: .translate() has been removed. Use .translateOnAxis( axis, distance ) instead.' );
  19709. return this.translateOnAxis( axis, distance );
  19710. }
  19711. } );
  19712. Object.defineProperties( THREE.Object3D.prototype, {
  19713. eulerOrder: {
  19714. get: function () {
  19715. console.warn( 'THREE.Object3D: .eulerOrder is now .rotation.order.' );
  19716. return this.rotation.order;
  19717. },
  19718. set: function ( value ) {
  19719. console.warn( 'THREE.Object3D: .eulerOrder is now .rotation.order.' );
  19720. this.rotation.order = value;
  19721. }
  19722. },
  19723. useQuaternion: {
  19724. get: function () {
  19725. console.warn( 'THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.' );
  19726. },
  19727. set: function ( value ) {
  19728. console.warn( 'THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.' );
  19729. }
  19730. }
  19731. } );
  19732. Object.defineProperties( THREE.LOD.prototype, {
  19733. objects: {
  19734. get: function () {
  19735. console.warn( 'THREE.LOD: .objects has been renamed to .levels.' );
  19736. return this.levels;
  19737. }
  19738. }
  19739. } );
  19740. //
  19741. THREE.PerspectiveCamera.prototype.setLens = function ( focalLength, filmGauge ) {
  19742. console.warn( "THREE.PerspectiveCamera.setLens is deprecated. " +
  19743. "Use .setFocalLength and .filmGauge for a photographic setup." );
  19744. if ( filmGauge !== undefined ) this.filmGauge = filmGauge;
  19745. this.setFocalLength( focalLength );
  19746. };
  19747. //
  19748. Object.defineProperties( THREE.Light.prototype, {
  19749. onlyShadow: {
  19750. set: function ( value ) {
  19751. console.warn( 'THREE.Light: .onlyShadow has been removed.' );
  19752. }
  19753. },
  19754. shadowCameraFov: {
  19755. set: function ( value ) {
  19756. console.warn( 'THREE.Light: .shadowCameraFov is now .shadow.camera.fov.' );
  19757. this.shadow.camera.fov = value;
  19758. }
  19759. },
  19760. shadowCameraLeft: {
  19761. set: function ( value ) {
  19762. console.warn( 'THREE.Light: .shadowCameraLeft is now .shadow.camera.left.' );
  19763. this.shadow.camera.left = value;
  19764. }
  19765. },
  19766. shadowCameraRight: {
  19767. set: function ( value ) {
  19768. console.warn( 'THREE.Light: .shadowCameraRight is now .shadow.camera.right.' );
  19769. this.shadow.camera.right = value;
  19770. }
  19771. },
  19772. shadowCameraTop: {
  19773. set: function ( value ) {
  19774. console.warn( 'THREE.Light: .shadowCameraTop is now .shadow.camera.top.' );
  19775. this.shadow.camera.top = value;
  19776. }
  19777. },
  19778. shadowCameraBottom: {
  19779. set: function ( value ) {
  19780. console.warn( 'THREE.Light: .shadowCameraBottom is now .shadow.camera.bottom.' );
  19781. this.shadow.camera.bottom = value;
  19782. }
  19783. },
  19784. shadowCameraNear: {
  19785. set: function ( value ) {
  19786. console.warn( 'THREE.Light: .shadowCameraNear is now .shadow.camera.near.' );
  19787. this.shadow.camera.near = value;
  19788. }
  19789. },
  19790. shadowCameraFar: {
  19791. set: function ( value ) {
  19792. console.warn( 'THREE.Light: .shadowCameraFar is now .shadow.camera.far.' );
  19793. this.shadow.camera.far = value;
  19794. }
  19795. },
  19796. shadowCameraVisible: {
  19797. set: function ( value ) {
  19798. console.warn( 'THREE.Light: .shadowCameraVisible has been removed. Use new THREE.CameraHelper( light.shadow.camera ) instead.' );
  19799. }
  19800. },
  19801. shadowBias: {
  19802. set: function ( value ) {
  19803. console.warn( 'THREE.Light: .shadowBias is now .shadow.bias.' );
  19804. this.shadow.bias = value;
  19805. }
  19806. },
  19807. shadowDarkness: {
  19808. set: function ( value ) {
  19809. console.warn( 'THREE.Light: .shadowDarkness has been removed.' );
  19810. }
  19811. },
  19812. shadowMapWidth: {
  19813. set: function ( value ) {
  19814. console.warn( 'THREE.Light: .shadowMapWidth is now .shadow.mapSize.width.' );
  19815. this.shadow.mapSize.width = value;
  19816. }
  19817. },
  19818. shadowMapHeight: {
  19819. set: function ( value ) {
  19820. console.warn( 'THREE.Light: .shadowMapHeight is now .shadow.mapSize.height.' );
  19821. this.shadow.mapSize.height = value;
  19822. }
  19823. }
  19824. } );
  19825. //
  19826. Object.defineProperties( THREE.BufferAttribute.prototype, {
  19827. length: {
  19828. get: function () {
  19829. console.warn( 'THREE.BufferAttribute: .length has been deprecated. Please use .count.' );
  19830. return this.array.length;
  19831. }
  19832. }
  19833. } );
  19834. Object.assign( THREE.BufferGeometry.prototype, {
  19835. addIndex: function ( index ) {
  19836. console.warn( 'THREE.BufferGeometry: .addIndex() has been renamed to .setIndex().' );
  19837. this.setIndex( index );
  19838. },
  19839. addDrawCall: function ( start, count, indexOffset ) {
  19840. if ( indexOffset !== undefined ) {
  19841. console.warn( 'THREE.BufferGeometry: .addDrawCall() no longer supports indexOffset.' );
  19842. }
  19843. console.warn( 'THREE.BufferGeometry: .addDrawCall() is now .addGroup().' );
  19844. this.addGroup( start, count );
  19845. },
  19846. clearDrawCalls: function () {
  19847. console.warn( 'THREE.BufferGeometry: .clearDrawCalls() is now .clearGroups().' );
  19848. this.clearGroups();
  19849. },
  19850. computeTangents: function () {
  19851. console.warn( 'THREE.BufferGeometry: .computeTangents() has been removed.' );
  19852. },
  19853. computeOffsets: function () {
  19854. console.warn( 'THREE.BufferGeometry: .computeOffsets() has been removed.' );
  19855. }
  19856. } );
  19857. Object.defineProperties( THREE.BufferGeometry.prototype, {
  19858. drawcalls: {
  19859. get: function () {
  19860. console.error( 'THREE.BufferGeometry: .drawcalls has been renamed to .groups.' );
  19861. return this.groups;
  19862. }
  19863. },
  19864. offsets: {
  19865. get: function () {
  19866. console.warn( 'THREE.BufferGeometry: .offsets has been renamed to .groups.' );
  19867. return this.groups;
  19868. }
  19869. }
  19870. } );
  19871. //
  19872. Object.defineProperties( THREE.Material.prototype, {
  19873. wrapAround: {
  19874. get: function () {
  19875. console.warn( 'THREE.' + this.type + ': .wrapAround has been removed.' );
  19876. },
  19877. set: function ( value ) {
  19878. console.warn( 'THREE.' + this.type + ': .wrapAround has been removed.' );
  19879. }
  19880. },
  19881. wrapRGB: {
  19882. get: function () {
  19883. console.warn( 'THREE.' + this.type + ': .wrapRGB has been removed.' );
  19884. return new THREE.Color();
  19885. }
  19886. }
  19887. } );
  19888. Object.defineProperties( THREE.MeshPhongMaterial.prototype, {
  19889. metal: {
  19890. get: function () {
  19891. console.warn( 'THREE.MeshPhongMaterial: .metal has been removed. Use THREE.MeshStandardMaterial instead.' );
  19892. return false;
  19893. },
  19894. set: function ( value ) {
  19895. console.warn( 'THREE.MeshPhongMaterial: .metal has been removed. Use THREE.MeshStandardMaterial instead' );
  19896. }
  19897. }
  19898. } );
  19899. Object.defineProperties( THREE.ShaderMaterial.prototype, {
  19900. derivatives: {
  19901. get: function () {
  19902. console.warn( 'THREE.ShaderMaterial: .derivatives has been moved to .extensions.derivatives.' );
  19903. return this.extensions.derivatives;
  19904. },
  19905. set: function ( value ) {
  19906. console.warn( 'THREE. ShaderMaterial: .derivatives has been moved to .extensions.derivatives.' );
  19907. this.extensions.derivatives = value;
  19908. }
  19909. }
  19910. } );
  19911. //
  19912. THREE.EventDispatcher.prototype = Object.assign( Object.create( {
  19913. // Note: Extra base ensures these properties are not 'assign'ed.
  19914. constructor: THREE.EventDispatcher,
  19915. apply: function ( target ) {
  19916. console.warn( "THREE.EventDispatcher: .apply is deprecated, " +
  19917. "just inherit or Object.assign the prototype to mix-in." );
  19918. Object.assign( target, this );
  19919. }
  19920. } ), THREE.EventDispatcher.prototype );
  19921. //
  19922. Object.assign( THREE.WebGLRenderer.prototype, {
  19923. supportsFloatTextures: function () {
  19924. console.warn( 'THREE.WebGLRenderer: .supportsFloatTextures() is now .extensions.get( \'OES_texture_float\' ).' );
  19925. return this.extensions.get( 'OES_texture_float' );
  19926. },
  19927. supportsHalfFloatTextures: function () {
  19928. console.warn( 'THREE.WebGLRenderer: .supportsHalfFloatTextures() is now .extensions.get( \'OES_texture_half_float\' ).' );
  19929. return this.extensions.get( 'OES_texture_half_float' );
  19930. },
  19931. supportsStandardDerivatives: function () {
  19932. console.warn( 'THREE.WebGLRenderer: .supportsStandardDerivatives() is now .extensions.get( \'OES_standard_derivatives\' ).' );
  19933. return this.extensions.get( 'OES_standard_derivatives' );
  19934. },
  19935. supportsCompressedTextureS3TC: function () {
  19936. console.warn( 'THREE.WebGLRenderer: .supportsCompressedTextureS3TC() is now .extensions.get( \'WEBGL_compressed_texture_s3tc\' ).' );
  19937. return this.extensions.get( 'WEBGL_compressed_texture_s3tc' );
  19938. },
  19939. supportsCompressedTexturePVRTC: function () {
  19940. console.warn( 'THREE.WebGLRenderer: .supportsCompressedTexturePVRTC() is now .extensions.get( \'WEBGL_compressed_texture_pvrtc\' ).' );
  19941. return this.extensions.get( 'WEBGL_compressed_texture_pvrtc' );
  19942. },
  19943. supportsBlendMinMax: function () {
  19944. console.warn( 'THREE.WebGLRenderer: .supportsBlendMinMax() is now .extensions.get( \'EXT_blend_minmax\' ).' );
  19945. return this.extensions.get( 'EXT_blend_minmax' );
  19946. },
  19947. supportsVertexTextures: function () {
  19948. return this.capabilities.vertexTextures;
  19949. },
  19950. supportsInstancedArrays: function () {
  19951. console.warn( 'THREE.WebGLRenderer: .supportsInstancedArrays() is now .extensions.get( \'ANGLE_instanced_arrays\' ).' );
  19952. return this.extensions.get( 'ANGLE_instanced_arrays' );
  19953. },
  19954. enableScissorTest: function ( boolean ) {
  19955. console.warn( 'THREE.WebGLRenderer: .enableScissorTest() is now .setScissorTest().' );
  19956. this.setScissorTest( boolean );
  19957. },
  19958. initMaterial: function () {
  19959. console.warn( 'THREE.WebGLRenderer: .initMaterial() has been removed.' );
  19960. },
  19961. addPrePlugin: function () {
  19962. console.warn( 'THREE.WebGLRenderer: .addPrePlugin() has been removed.' );
  19963. },
  19964. addPostPlugin: function () {
  19965. console.warn( 'THREE.WebGLRenderer: .addPostPlugin() has been removed.' );
  19966. },
  19967. updateShadowMap: function () {
  19968. console.warn( 'THREE.WebGLRenderer: .updateShadowMap() has been removed.' );
  19969. }
  19970. } );
  19971. Object.defineProperties( THREE.WebGLRenderer.prototype, {
  19972. shadowMapEnabled: {
  19973. get: function () {
  19974. return this.shadowMap.enabled;
  19975. },
  19976. set: function ( value ) {
  19977. console.warn( 'THREE.WebGLRenderer: .shadowMapEnabled is now .shadowMap.enabled.' );
  19978. this.shadowMap.enabled = value;
  19979. }
  19980. },
  19981. shadowMapType: {
  19982. get: function () {
  19983. return this.shadowMap.type;
  19984. },
  19985. set: function ( value ) {
  19986. console.warn( 'THREE.WebGLRenderer: .shadowMapType is now .shadowMap.type.' );
  19987. this.shadowMap.type = value;
  19988. }
  19989. },
  19990. shadowMapCullFace: {
  19991. get: function () {
  19992. return this.shadowMap.cullFace;
  19993. },
  19994. set: function ( value ) {
  19995. console.warn( 'THREE.WebGLRenderer: .shadowMapCullFace is now .shadowMap.cullFace.' );
  19996. this.shadowMap.cullFace = value;
  19997. }
  19998. }
  19999. } );
  20000. Object.defineProperties( THREE.WebGLShadowMap.prototype, {
  20001. cullFace: {
  20002. get: function () {
  20003. return this.renderReverseSided ? THREE.CullFaceFront : THREE.CullFaceBack;
  20004. },
  20005. set: function ( cullFace ) {
  20006. var value = ( cullFace !== THREE.CullFaceBack );
  20007. console.warn( "WebGLRenderer: .shadowMap.cullFace is deprecated. Set .shadowMap.renderReverseSided to " + value + "." );
  20008. this.renderReverseSided = value;
  20009. }
  20010. }
  20011. } );
  20012. //
  20013. Object.defineProperties( THREE.WebGLRenderTarget.prototype, {
  20014. wrapS: {
  20015. get: function () {
  20016. console.warn( 'THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.' );
  20017. return this.texture.wrapS;
  20018. },
  20019. set: function ( value ) {
  20020. console.warn( 'THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.' );
  20021. this.texture.wrapS = value;
  20022. }
  20023. },
  20024. wrapT: {
  20025. get: function () {
  20026. console.warn( 'THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.' );
  20027. return this.texture.wrapT;
  20028. },
  20029. set: function ( value ) {
  20030. console.warn( 'THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.' );
  20031. this.texture.wrapT = value;
  20032. }
  20033. },
  20034. magFilter: {
  20035. get: function () {
  20036. console.warn( 'THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.' );
  20037. return this.texture.magFilter;
  20038. },
  20039. set: function ( value ) {
  20040. console.warn( 'THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.' );
  20041. this.texture.magFilter = value;
  20042. }
  20043. },
  20044. minFilter: {
  20045. get: function () {
  20046. console.warn( 'THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.' );
  20047. return this.texture.minFilter;
  20048. },
  20049. set: function ( value ) {
  20050. console.warn( 'THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.' );
  20051. this.texture.minFilter = value;
  20052. }
  20053. },
  20054. anisotropy: {
  20055. get: function () {
  20056. console.warn( 'THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy.' );
  20057. return this.texture.anisotropy;
  20058. },
  20059. set: function ( value ) {
  20060. console.warn( 'THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy.' );
  20061. this.texture.anisotropy = value;
  20062. }
  20063. },
  20064. offset: {
  20065. get: function () {
  20066. console.warn( 'THREE.WebGLRenderTarget: .offset is now .texture.offset.' );
  20067. return this.texture.offset;
  20068. },
  20069. set: function ( value ) {
  20070. console.warn( 'THREE.WebGLRenderTarget: .offset is now .texture.offset.' );
  20071. this.texture.offset = value;
  20072. }
  20073. },
  20074. repeat: {
  20075. get: function () {
  20076. console.warn( 'THREE.WebGLRenderTarget: .repeat is now .texture.repeat.' );
  20077. return this.texture.repeat;
  20078. },
  20079. set: function ( value ) {
  20080. console.warn( 'THREE.WebGLRenderTarget: .repeat is now .texture.repeat.' );
  20081. this.texture.repeat = value;
  20082. }
  20083. },
  20084. format: {
  20085. get: function () {
  20086. console.warn( 'THREE.WebGLRenderTarget: .format is now .texture.format.' );
  20087. return this.texture.format;
  20088. },
  20089. set: function ( value ) {
  20090. console.warn( 'THREE.WebGLRenderTarget: .format is now .texture.format.' );
  20091. this.texture.format = value;
  20092. }
  20093. },
  20094. type: {
  20095. get: function () {
  20096. console.warn( 'THREE.WebGLRenderTarget: .type is now .texture.type.' );
  20097. return this.texture.type;
  20098. },
  20099. set: function ( value ) {
  20100. console.warn( 'THREE.WebGLRenderTarget: .type is now .texture.type.' );
  20101. this.texture.type = value;
  20102. }
  20103. },
  20104. generateMipmaps: {
  20105. get: function () {
  20106. console.warn( 'THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps.' );
  20107. return this.texture.generateMipmaps;
  20108. },
  20109. set: function ( value ) {
  20110. console.warn( 'THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps.' );
  20111. this.texture.generateMipmaps = value;
  20112. }
  20113. }
  20114. } );
  20115. //
  20116. Object.assign( THREE.Audio.prototype, {
  20117. load: function ( file ) {
  20118. console.warn( 'THREE.Audio: .load has been deprecated. Please use THREE.AudioLoader.' );
  20119. var scope = this;
  20120. var audioLoader = new THREE.AudioLoader();
  20121. audioLoader.load( file, function ( buffer ) {
  20122. scope.setBuffer( buffer );
  20123. } );
  20124. return this;
  20125. }
  20126. } );
  20127. Object.assign( THREE.AudioAnalyser.prototype, {
  20128. getData: function ( file ) {
  20129. console.warn( 'THREE.AudioAnalyser: .getData() is now .getFrequencyData().' );
  20130. return this.getFrequencyData();
  20131. }
  20132. } );
  20133. //
  20134. THREE.GeometryUtils = {
  20135. merge: function ( geometry1, geometry2, materialIndexOffset ) {
  20136. console.warn( 'THREE.GeometryUtils: .merge() has been moved to Geometry. Use geometry.merge( geometry2, matrix, materialIndexOffset ) instead.' );
  20137. var matrix;
  20138. if ( geometry2 instanceof THREE.Mesh ) {
  20139. geometry2.matrixAutoUpdate && geometry2.updateMatrix();
  20140. matrix = geometry2.matrix;
  20141. geometry2 = geometry2.geometry;
  20142. }
  20143. geometry1.merge( geometry2, matrix, materialIndexOffset );
  20144. },
  20145. center: function ( geometry ) {
  20146. console.warn( 'THREE.GeometryUtils: .center() has been moved to Geometry. Use geometry.center() instead.' );
  20147. return geometry.center();
  20148. }
  20149. };
  20150. THREE.ImageUtils = {
  20151. crossOrigin: undefined,
  20152. loadTexture: function ( url, mapping, onLoad, onError ) {
  20153. console.warn( 'THREE.ImageUtils.loadTexture has been deprecated. Use THREE.TextureLoader() instead.' );
  20154. var loader = new THREE.TextureLoader();
  20155. loader.setCrossOrigin( this.crossOrigin );
  20156. var texture = loader.load( url, onLoad, undefined, onError );
  20157. if ( mapping ) texture.mapping = mapping;
  20158. return texture;
  20159. },
  20160. loadTextureCube: function ( urls, mapping, onLoad, onError ) {
  20161. console.warn( 'THREE.ImageUtils.loadTextureCube has been deprecated. Use THREE.CubeTextureLoader() instead.' );
  20162. var loader = new THREE.CubeTextureLoader();
  20163. loader.setCrossOrigin( this.crossOrigin );
  20164. var texture = loader.load( urls, onLoad, undefined, onError );
  20165. if ( mapping ) texture.mapping = mapping;
  20166. return texture;
  20167. },
  20168. loadCompressedTexture: function () {
  20169. console.error( 'THREE.ImageUtils.loadCompressedTexture has been removed. Use THREE.DDSLoader instead.' );
  20170. },
  20171. loadCompressedTextureCube: function () {
  20172. console.error( 'THREE.ImageUtils.loadCompressedTextureCube has been removed. Use THREE.DDSLoader instead.' );
  20173. }
  20174. };
  20175. //
  20176. THREE.Projector = function () {
  20177. console.error( 'THREE.Projector has been moved to /examples/js/renderers/Projector.js.' );
  20178. this.projectVector = function ( vector, camera ) {
  20179. console.warn( 'THREE.Projector: .projectVector() is now vector.project().' );
  20180. vector.project( camera );
  20181. };
  20182. this.unprojectVector = function ( vector, camera ) {
  20183. console.warn( 'THREE.Projector: .unprojectVector() is now vector.unproject().' );
  20184. vector.unproject( camera );
  20185. };
  20186. this.pickingRay = function ( vector, camera ) {
  20187. console.error( 'THREE.Projector: .pickingRay() is now raycaster.setFromCamera().' );
  20188. };
  20189. };
  20190. //
  20191. THREE.CanvasRenderer = function () {
  20192. console.error( 'THREE.CanvasRenderer has been moved to /examples/js/renderers/CanvasRenderer.js' );
  20193. this.domElement = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' );
  20194. this.clear = function () {};
  20195. this.render = function () {};
  20196. this.setClearColor = function () {};
  20197. this.setSize = function () {};
  20198. };
  20199. // File:src/extras/CurveUtils.js
  20200. /**
  20201. * @author zz85 / http://www.lab4games.net/zz85/blog
  20202. */
  20203. THREE.CurveUtils = {
  20204. tangentQuadraticBezier: function ( t, p0, p1, p2 ) {
  20205. return 2 * ( 1 - t ) * ( p1 - p0 ) + 2 * t * ( p2 - p1 );
  20206. },
  20207. // Puay Bing, thanks for helping with this derivative!
  20208. tangentCubicBezier: function ( t, p0, p1, p2, p3 ) {
  20209. return - 3 * p0 * ( 1 - t ) * ( 1 - t ) +
  20210. 3 * p1 * ( 1 - t ) * ( 1 - t ) - 6 * t * p1 * ( 1 - t ) +
  20211. 6 * t * p2 * ( 1 - t ) - 3 * t * t * p2 +
  20212. 3 * t * t * p3;
  20213. },
  20214. tangentSpline: function ( t, p0, p1, p2, p3 ) {
  20215. // To check if my formulas are correct
  20216. var h00 = 6 * t * t - 6 * t; // derived from 2t^3 − 3t^2 + 1
  20217. var h10 = 3 * t * t - 4 * t + 1; // t^3 − 2t^2 + t
  20218. var h01 = - 6 * t * t + 6 * t; // − 2t3 + 3t2
  20219. var h11 = 3 * t * t - 2 * t; // t3 − t2
  20220. return h00 + h10 + h01 + h11;
  20221. },
  20222. // Catmull-Rom
  20223. interpolate: function( p0, p1, p2, p3, t ) {
  20224. var v0 = ( p2 - p0 ) * 0.5;
  20225. var v1 = ( p3 - p1 ) * 0.5;
  20226. var t2 = t * t;
  20227. var t3 = t * t2;
  20228. return ( 2 * p1 - 2 * p2 + v0 + v1 ) * t3 + ( - 3 * p1 + 3 * p2 - 2 * v0 - v1 ) * t2 + v0 * t + p1;
  20229. }
  20230. };
  20231. // File:src/extras/SceneUtils.js
  20232. /**
  20233. * @author alteredq / http://alteredqualia.com/
  20234. */
  20235. THREE.SceneUtils = {
  20236. createMultiMaterialObject: function ( geometry, materials ) {
  20237. var group = new THREE.Group();
  20238. for ( var i = 0, l = materials.length; i < l; i ++ ) {
  20239. group.add( new THREE.Mesh( geometry, materials[ i ] ) );
  20240. }
  20241. return group;
  20242. },
  20243. detach: function ( child, parent, scene ) {
  20244. child.applyMatrix( parent.matrixWorld );
  20245. parent.remove( child );
  20246. scene.add( child );
  20247. },
  20248. attach: function ( child, scene, parent ) {
  20249. var matrixWorldInverse = new THREE.Matrix4();
  20250. matrixWorldInverse.getInverse( parent.matrixWorld );
  20251. child.applyMatrix( matrixWorldInverse );
  20252. scene.remove( child );
  20253. parent.add( child );
  20254. }
  20255. };
  20256. // File:src/extras/ShapeUtils.js
  20257. /**
  20258. * @author zz85 / http://www.lab4games.net/zz85/blog
  20259. */
  20260. THREE.ShapeUtils = {
  20261. // calculate area of the contour polygon
  20262. area: function ( contour ) {
  20263. var n = contour.length;
  20264. var a = 0.0;
  20265. for ( var p = n - 1, q = 0; q < n; p = q ++ ) {
  20266. a += contour[ p ].x * contour[ q ].y - contour[ q ].x * contour[ p ].y;
  20267. }
  20268. return a * 0.5;
  20269. },
  20270. triangulate: ( function () {
  20271. /**
  20272. * This code is a quick port of code written in C++ which was submitted to
  20273. * flipcode.com by John W. Ratcliff // July 22, 2000
  20274. * See original code and more information here:
  20275. * http://www.flipcode.com/archives/Efficient_Polygon_Triangulation.shtml
  20276. *
  20277. * ported to actionscript by Zevan Rosser
  20278. * www.actionsnippet.com
  20279. *
  20280. * ported to javascript by Joshua Koo
  20281. * http://www.lab4games.net/zz85/blog
  20282. *
  20283. */
  20284. function snip( contour, u, v, w, n, verts ) {
  20285. var p;
  20286. var ax, ay, bx, by;
  20287. var cx, cy, px, py;
  20288. ax = contour[ verts[ u ] ].x;
  20289. ay = contour[ verts[ u ] ].y;
  20290. bx = contour[ verts[ v ] ].x;
  20291. by = contour[ verts[ v ] ].y;
  20292. cx = contour[ verts[ w ] ].x;
  20293. cy = contour[ verts[ w ] ].y;
  20294. if ( Number.EPSILON > ( ( ( bx - ax ) * ( cy - ay ) ) - ( ( by - ay ) * ( cx - ax ) ) ) ) return false;
  20295. var aX, aY, bX, bY, cX, cY;
  20296. var apx, apy, bpx, bpy, cpx, cpy;
  20297. var cCROSSap, bCROSScp, aCROSSbp;
  20298. aX = cx - bx; aY = cy - by;
  20299. bX = ax - cx; bY = ay - cy;
  20300. cX = bx - ax; cY = by - ay;
  20301. for ( p = 0; p < n; p ++ ) {
  20302. px = contour[ verts[ p ] ].x;
  20303. py = contour[ verts[ p ] ].y;
  20304. if ( ( ( px === ax ) && ( py === ay ) ) ||
  20305. ( ( px === bx ) && ( py === by ) ) ||
  20306. ( ( px === cx ) && ( py === cy ) ) ) continue;
  20307. apx = px - ax; apy = py - ay;
  20308. bpx = px - bx; bpy = py - by;
  20309. cpx = px - cx; cpy = py - cy;
  20310. // see if p is inside triangle abc
  20311. aCROSSbp = aX * bpy - aY * bpx;
  20312. cCROSSap = cX * apy - cY * apx;
  20313. bCROSScp = bX * cpy - bY * cpx;
  20314. if ( ( aCROSSbp >= - Number.EPSILON ) && ( bCROSScp >= - Number.EPSILON ) && ( cCROSSap >= - Number.EPSILON ) ) return false;
  20315. }
  20316. return true;
  20317. }
  20318. // takes in an contour array and returns
  20319. return function triangulate( contour, indices ) {
  20320. var n = contour.length;
  20321. if ( n < 3 ) return null;
  20322. var result = [],
  20323. verts = [],
  20324. vertIndices = [];
  20325. /* we want a counter-clockwise polygon in verts */
  20326. var u, v, w;
  20327. if ( THREE.ShapeUtils.area( contour ) > 0.0 ) {
  20328. for ( v = 0; v < n; v ++ ) verts[ v ] = v;
  20329. } else {
  20330. for ( v = 0; v < n; v ++ ) verts[ v ] = ( n - 1 ) - v;
  20331. }
  20332. var nv = n;
  20333. /* remove nv - 2 vertices, creating 1 triangle every time */
  20334. var count = 2 * nv; /* error detection */
  20335. for ( v = nv - 1; nv > 2; ) {
  20336. /* if we loop, it is probably a non-simple polygon */
  20337. if ( ( count -- ) <= 0 ) {
  20338. //** Triangulate: ERROR - probable bad polygon!
  20339. //throw ( "Warning, unable to triangulate polygon!" );
  20340. //return null;
  20341. // Sometimes warning is fine, especially polygons are triangulated in reverse.
  20342. console.warn( 'THREE.ShapeUtils: Unable to triangulate polygon! in triangulate()' );
  20343. if ( indices ) return vertIndices;
  20344. return result;
  20345. }
  20346. /* three consecutive vertices in current polygon, <u,v,w> */
  20347. u = v; if ( nv <= u ) u = 0; /* previous */
  20348. v = u + 1; if ( nv <= v ) v = 0; /* new v */
  20349. w = v + 1; if ( nv <= w ) w = 0; /* next */
  20350. if ( snip( contour, u, v, w, nv, verts ) ) {
  20351. var a, b, c, s, t;
  20352. /* true names of the vertices */
  20353. a = verts[ u ];
  20354. b = verts[ v ];
  20355. c = verts[ w ];
  20356. /* output Triangle */
  20357. result.push( [ contour[ a ],
  20358. contour[ b ],
  20359. contour[ c ] ] );
  20360. vertIndices.push( [ verts[ u ], verts[ v ], verts[ w ] ] );
  20361. /* remove v from the remaining polygon */
  20362. for ( s = v, t = v + 1; t < nv; s ++, t ++ ) {
  20363. verts[ s ] = verts[ t ];
  20364. }
  20365. nv --;
  20366. /* reset error detection counter */
  20367. count = 2 * nv;
  20368. }
  20369. }
  20370. if ( indices ) return vertIndices;
  20371. return result;
  20372. }
  20373. } )(),
  20374. triangulateShape: function ( contour, holes ) {
  20375. function removeDupEndPts(points) {
  20376. var l = points.length;
  20377. if ( l > 2 && points[ l - 1 ].equals( points[ 0 ] ) ) {
  20378. points.pop();
  20379. }
  20380. }
  20381. removeDupEndPts( contour );
  20382. holes.forEach( removeDupEndPts );
  20383. function point_in_segment_2D_colin( inSegPt1, inSegPt2, inOtherPt ) {
  20384. // inOtherPt needs to be collinear to the inSegment
  20385. if ( inSegPt1.x !== inSegPt2.x ) {
  20386. if ( inSegPt1.x < inSegPt2.x ) {
  20387. return ( ( inSegPt1.x <= inOtherPt.x ) && ( inOtherPt.x <= inSegPt2.x ) );
  20388. } else {
  20389. return ( ( inSegPt2.x <= inOtherPt.x ) && ( inOtherPt.x <= inSegPt1.x ) );
  20390. }
  20391. } else {
  20392. if ( inSegPt1.y < inSegPt2.y ) {
  20393. return ( ( inSegPt1.y <= inOtherPt.y ) && ( inOtherPt.y <= inSegPt2.y ) );
  20394. } else {
  20395. return ( ( inSegPt2.y <= inOtherPt.y ) && ( inOtherPt.y <= inSegPt1.y ) );
  20396. }
  20397. }
  20398. }
  20399. function intersect_segments_2D( inSeg1Pt1, inSeg1Pt2, inSeg2Pt1, inSeg2Pt2, inExcludeAdjacentSegs ) {
  20400. var seg1dx = inSeg1Pt2.x - inSeg1Pt1.x, seg1dy = inSeg1Pt2.y - inSeg1Pt1.y;
  20401. var seg2dx = inSeg2Pt2.x - inSeg2Pt1.x, seg2dy = inSeg2Pt2.y - inSeg2Pt1.y;
  20402. var seg1seg2dx = inSeg1Pt1.x - inSeg2Pt1.x;
  20403. var seg1seg2dy = inSeg1Pt1.y - inSeg2Pt1.y;
  20404. var limit = seg1dy * seg2dx - seg1dx * seg2dy;
  20405. var perpSeg1 = seg1dy * seg1seg2dx - seg1dx * seg1seg2dy;
  20406. if ( Math.abs( limit ) > Number.EPSILON ) {
  20407. // not parallel
  20408. var perpSeg2;
  20409. if ( limit > 0 ) {
  20410. if ( ( perpSeg1 < 0 ) || ( perpSeg1 > limit ) ) return [];
  20411. perpSeg2 = seg2dy * seg1seg2dx - seg2dx * seg1seg2dy;
  20412. if ( ( perpSeg2 < 0 ) || ( perpSeg2 > limit ) ) return [];
  20413. } else {
  20414. if ( ( perpSeg1 > 0 ) || ( perpSeg1 < limit ) ) return [];
  20415. perpSeg2 = seg2dy * seg1seg2dx - seg2dx * seg1seg2dy;
  20416. if ( ( perpSeg2 > 0 ) || ( perpSeg2 < limit ) ) return [];
  20417. }
  20418. // i.e. to reduce rounding errors
  20419. // intersection at endpoint of segment#1?
  20420. if ( perpSeg2 === 0 ) {
  20421. if ( ( inExcludeAdjacentSegs ) &&
  20422. ( ( perpSeg1 === 0 ) || ( perpSeg1 === limit ) ) ) return [];
  20423. return [ inSeg1Pt1 ];
  20424. }
  20425. if ( perpSeg2 === limit ) {
  20426. if ( ( inExcludeAdjacentSegs ) &&
  20427. ( ( perpSeg1 === 0 ) || ( perpSeg1 === limit ) ) ) return [];
  20428. return [ inSeg1Pt2 ];
  20429. }
  20430. // intersection at endpoint of segment#2?
  20431. if ( perpSeg1 === 0 ) return [ inSeg2Pt1 ];
  20432. if ( perpSeg1 === limit ) return [ inSeg2Pt2 ];
  20433. // return real intersection point
  20434. var factorSeg1 = perpSeg2 / limit;
  20435. return [ { x: inSeg1Pt1.x + factorSeg1 * seg1dx,
  20436. y: inSeg1Pt1.y + factorSeg1 * seg1dy } ];
  20437. } else {
  20438. // parallel or collinear
  20439. if ( ( perpSeg1 !== 0 ) ||
  20440. ( seg2dy * seg1seg2dx !== seg2dx * seg1seg2dy ) ) return [];
  20441. // they are collinear or degenerate
  20442. var seg1Pt = ( ( seg1dx === 0 ) && ( seg1dy === 0 ) ); // segment1 is just a point?
  20443. var seg2Pt = ( ( seg2dx === 0 ) && ( seg2dy === 0 ) ); // segment2 is just a point?
  20444. // both segments are points
  20445. if ( seg1Pt && seg2Pt ) {
  20446. if ( ( inSeg1Pt1.x !== inSeg2Pt1.x ) ||
  20447. ( inSeg1Pt1.y !== inSeg2Pt1.y ) ) return []; // they are distinct points
  20448. return [ inSeg1Pt1 ]; // they are the same point
  20449. }
  20450. // segment#1 is a single point
  20451. if ( seg1Pt ) {
  20452. if ( ! point_in_segment_2D_colin( inSeg2Pt1, inSeg2Pt2, inSeg1Pt1 ) ) return []; // but not in segment#2
  20453. return [ inSeg1Pt1 ];
  20454. }
  20455. // segment#2 is a single point
  20456. if ( seg2Pt ) {
  20457. if ( ! point_in_segment_2D_colin( inSeg1Pt1, inSeg1Pt2, inSeg2Pt1 ) ) return []; // but not in segment#1
  20458. return [ inSeg2Pt1 ];
  20459. }
  20460. // they are collinear segments, which might overlap
  20461. var seg1min, seg1max, seg1minVal, seg1maxVal;
  20462. var seg2min, seg2max, seg2minVal, seg2maxVal;
  20463. if ( seg1dx !== 0 ) {
  20464. // the segments are NOT on a vertical line
  20465. if ( inSeg1Pt1.x < inSeg1Pt2.x ) {
  20466. seg1min = inSeg1Pt1; seg1minVal = inSeg1Pt1.x;
  20467. seg1max = inSeg1Pt2; seg1maxVal = inSeg1Pt2.x;
  20468. } else {
  20469. seg1min = inSeg1Pt2; seg1minVal = inSeg1Pt2.x;
  20470. seg1max = inSeg1Pt1; seg1maxVal = inSeg1Pt1.x;
  20471. }
  20472. if ( inSeg2Pt1.x < inSeg2Pt2.x ) {
  20473. seg2min = inSeg2Pt1; seg2minVal = inSeg2Pt1.x;
  20474. seg2max = inSeg2Pt2; seg2maxVal = inSeg2Pt2.x;
  20475. } else {
  20476. seg2min = inSeg2Pt2; seg2minVal = inSeg2Pt2.x;
  20477. seg2max = inSeg2Pt1; seg2maxVal = inSeg2Pt1.x;
  20478. }
  20479. } else {
  20480. // the segments are on a vertical line
  20481. if ( inSeg1Pt1.y < inSeg1Pt2.y ) {
  20482. seg1min = inSeg1Pt1; seg1minVal = inSeg1Pt1.y;
  20483. seg1max = inSeg1Pt2; seg1maxVal = inSeg1Pt2.y;
  20484. } else {
  20485. seg1min = inSeg1Pt2; seg1minVal = inSeg1Pt2.y;
  20486. seg1max = inSeg1Pt1; seg1maxVal = inSeg1Pt1.y;
  20487. }
  20488. if ( inSeg2Pt1.y < inSeg2Pt2.y ) {
  20489. seg2min = inSeg2Pt1; seg2minVal = inSeg2Pt1.y;
  20490. seg2max = inSeg2Pt2; seg2maxVal = inSeg2Pt2.y;
  20491. } else {
  20492. seg2min = inSeg2Pt2; seg2minVal = inSeg2Pt2.y;
  20493. seg2max = inSeg2Pt1; seg2maxVal = inSeg2Pt1.y;
  20494. }
  20495. }
  20496. if ( seg1minVal <= seg2minVal ) {
  20497. if ( seg1maxVal < seg2minVal ) return [];
  20498. if ( seg1maxVal === seg2minVal ) {
  20499. if ( inExcludeAdjacentSegs ) return [];
  20500. return [ seg2min ];
  20501. }
  20502. if ( seg1maxVal <= seg2maxVal ) return [ seg2min, seg1max ];
  20503. return [ seg2min, seg2max ];
  20504. } else {
  20505. if ( seg1minVal > seg2maxVal ) return [];
  20506. if ( seg1minVal === seg2maxVal ) {
  20507. if ( inExcludeAdjacentSegs ) return [];
  20508. return [ seg1min ];
  20509. }
  20510. if ( seg1maxVal <= seg2maxVal ) return [ seg1min, seg1max ];
  20511. return [ seg1min, seg2max ];
  20512. }
  20513. }
  20514. }
  20515. function isPointInsideAngle( inVertex, inLegFromPt, inLegToPt, inOtherPt ) {
  20516. // The order of legs is important
  20517. // translation of all points, so that Vertex is at (0,0)
  20518. var legFromPtX = inLegFromPt.x - inVertex.x, legFromPtY = inLegFromPt.y - inVertex.y;
  20519. var legToPtX = inLegToPt.x - inVertex.x, legToPtY = inLegToPt.y - inVertex.y;
  20520. var otherPtX = inOtherPt.x - inVertex.x, otherPtY = inOtherPt.y - inVertex.y;
  20521. // main angle >0: < 180 deg.; 0: 180 deg.; <0: > 180 deg.
  20522. var from2toAngle = legFromPtX * legToPtY - legFromPtY * legToPtX;
  20523. var from2otherAngle = legFromPtX * otherPtY - legFromPtY * otherPtX;
  20524. if ( Math.abs( from2toAngle ) > Number.EPSILON ) {
  20525. // angle != 180 deg.
  20526. var other2toAngle = otherPtX * legToPtY - otherPtY * legToPtX;
  20527. // console.log( "from2to: " + from2toAngle + ", from2other: " + from2otherAngle + ", other2to: " + other2toAngle );
  20528. if ( from2toAngle > 0 ) {
  20529. // main angle < 180 deg.
  20530. return ( ( from2otherAngle >= 0 ) && ( other2toAngle >= 0 ) );
  20531. } else {
  20532. // main angle > 180 deg.
  20533. return ( ( from2otherAngle >= 0 ) || ( other2toAngle >= 0 ) );
  20534. }
  20535. } else {
  20536. // angle == 180 deg.
  20537. // console.log( "from2to: 180 deg., from2other: " + from2otherAngle );
  20538. return ( from2otherAngle > 0 );
  20539. }
  20540. }
  20541. function removeHoles( contour, holes ) {
  20542. var shape = contour.concat(); // work on this shape
  20543. var hole;
  20544. function isCutLineInsideAngles( inShapeIdx, inHoleIdx ) {
  20545. // Check if hole point lies within angle around shape point
  20546. var lastShapeIdx = shape.length - 1;
  20547. var prevShapeIdx = inShapeIdx - 1;
  20548. if ( prevShapeIdx < 0 ) prevShapeIdx = lastShapeIdx;
  20549. var nextShapeIdx = inShapeIdx + 1;
  20550. if ( nextShapeIdx > lastShapeIdx ) nextShapeIdx = 0;
  20551. var insideAngle = isPointInsideAngle( shape[ inShapeIdx ], shape[ prevShapeIdx ], shape[ nextShapeIdx ], hole[ inHoleIdx ] );
  20552. if ( ! insideAngle ) {
  20553. // console.log( "Vertex (Shape): " + inShapeIdx + ", Point: " + hole[inHoleIdx].x + "/" + hole[inHoleIdx].y );
  20554. return false;
  20555. }
  20556. // Check if shape point lies within angle around hole point
  20557. var lastHoleIdx = hole.length - 1;
  20558. var prevHoleIdx = inHoleIdx - 1;
  20559. if ( prevHoleIdx < 0 ) prevHoleIdx = lastHoleIdx;
  20560. var nextHoleIdx = inHoleIdx + 1;
  20561. if ( nextHoleIdx > lastHoleIdx ) nextHoleIdx = 0;
  20562. insideAngle = isPointInsideAngle( hole[ inHoleIdx ], hole[ prevHoleIdx ], hole[ nextHoleIdx ], shape[ inShapeIdx ] );
  20563. if ( ! insideAngle ) {
  20564. // console.log( "Vertex (Hole): " + inHoleIdx + ", Point: " + shape[inShapeIdx].x + "/" + shape[inShapeIdx].y );
  20565. return false;
  20566. }
  20567. return true;
  20568. }
  20569. function intersectsShapeEdge( inShapePt, inHolePt ) {
  20570. // checks for intersections with shape edges
  20571. var sIdx, nextIdx, intersection;
  20572. for ( sIdx = 0; sIdx < shape.length; sIdx ++ ) {
  20573. nextIdx = sIdx + 1; nextIdx %= shape.length;
  20574. intersection = intersect_segments_2D( inShapePt, inHolePt, shape[ sIdx ], shape[ nextIdx ], true );
  20575. if ( intersection.length > 0 ) return true;
  20576. }
  20577. return false;
  20578. }
  20579. var indepHoles = [];
  20580. function intersectsHoleEdge( inShapePt, inHolePt ) {
  20581. // checks for intersections with hole edges
  20582. var ihIdx, chkHole,
  20583. hIdx, nextIdx, intersection;
  20584. for ( ihIdx = 0; ihIdx < indepHoles.length; ihIdx ++ ) {
  20585. chkHole = holes[ indepHoles[ ihIdx ]];
  20586. for ( hIdx = 0; hIdx < chkHole.length; hIdx ++ ) {
  20587. nextIdx = hIdx + 1; nextIdx %= chkHole.length;
  20588. intersection = intersect_segments_2D( inShapePt, inHolePt, chkHole[ hIdx ], chkHole[ nextIdx ], true );
  20589. if ( intersection.length > 0 ) return true;
  20590. }
  20591. }
  20592. return false;
  20593. }
  20594. var holeIndex, shapeIndex,
  20595. shapePt, holePt,
  20596. holeIdx, cutKey, failedCuts = [],
  20597. tmpShape1, tmpShape2,
  20598. tmpHole1, tmpHole2;
  20599. for ( var h = 0, hl = holes.length; h < hl; h ++ ) {
  20600. indepHoles.push( h );
  20601. }
  20602. var minShapeIndex = 0;
  20603. var counter = indepHoles.length * 2;
  20604. while ( indepHoles.length > 0 ) {
  20605. counter --;
  20606. if ( counter < 0 ) {
  20607. console.log( "Infinite Loop! Holes left:" + indepHoles.length + ", Probably Hole outside Shape!" );
  20608. break;
  20609. }
  20610. // search for shape-vertex and hole-vertex,
  20611. // which can be connected without intersections
  20612. for ( shapeIndex = minShapeIndex; shapeIndex < shape.length; shapeIndex ++ ) {
  20613. shapePt = shape[ shapeIndex ];
  20614. holeIndex = - 1;
  20615. // search for hole which can be reached without intersections
  20616. for ( var h = 0; h < indepHoles.length; h ++ ) {
  20617. holeIdx = indepHoles[ h ];
  20618. // prevent multiple checks
  20619. cutKey = shapePt.x + ":" + shapePt.y + ":" + holeIdx;
  20620. if ( failedCuts[ cutKey ] !== undefined ) continue;
  20621. hole = holes[ holeIdx ];
  20622. for ( var h2 = 0; h2 < hole.length; h2 ++ ) {
  20623. holePt = hole[ h2 ];
  20624. if ( ! isCutLineInsideAngles( shapeIndex, h2 ) ) continue;
  20625. if ( intersectsShapeEdge( shapePt, holePt ) ) continue;
  20626. if ( intersectsHoleEdge( shapePt, holePt ) ) continue;
  20627. holeIndex = h2;
  20628. indepHoles.splice( h, 1 );
  20629. tmpShape1 = shape.slice( 0, shapeIndex + 1 );
  20630. tmpShape2 = shape.slice( shapeIndex );
  20631. tmpHole1 = hole.slice( holeIndex );
  20632. tmpHole2 = hole.slice( 0, holeIndex + 1 );
  20633. shape = tmpShape1.concat( tmpHole1 ).concat( tmpHole2 ).concat( tmpShape2 );
  20634. minShapeIndex = shapeIndex;
  20635. // Debug only, to show the selected cuts
  20636. // glob_CutLines.push( [ shapePt, holePt ] );
  20637. break;
  20638. }
  20639. if ( holeIndex >= 0 ) break; // hole-vertex found
  20640. failedCuts[ cutKey ] = true; // remember failure
  20641. }
  20642. if ( holeIndex >= 0 ) break; // hole-vertex found
  20643. }
  20644. }
  20645. return shape; /* shape with no holes */
  20646. }
  20647. var i, il, f, face,
  20648. key, index,
  20649. allPointsMap = {};
  20650. // 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.
  20651. var allpoints = contour.concat();
  20652. for ( var h = 0, hl = holes.length; h < hl; h ++ ) {
  20653. Array.prototype.push.apply( allpoints, holes[ h ] );
  20654. }
  20655. //console.log( "allpoints",allpoints, allpoints.length );
  20656. // prepare all points map
  20657. for ( i = 0, il = allpoints.length; i < il; i ++ ) {
  20658. key = allpoints[ i ].x + ":" + allpoints[ i ].y;
  20659. if ( allPointsMap[ key ] !== undefined ) {
  20660. console.warn( "THREE.ShapeUtils: Duplicate point", key, i );
  20661. }
  20662. allPointsMap[ key ] = i;
  20663. }
  20664. // remove holes by cutting paths to holes and adding them to the shape
  20665. var shapeWithoutHoles = removeHoles( contour, holes );
  20666. var triangles = THREE.ShapeUtils.triangulate( shapeWithoutHoles, false ); // True returns indices for points of spooled shape
  20667. //console.log( "triangles",triangles, triangles.length );
  20668. // check all face vertices against all points map
  20669. for ( i = 0, il = triangles.length; i < il; i ++ ) {
  20670. face = triangles[ i ];
  20671. for ( f = 0; f < 3; f ++ ) {
  20672. key = face[ f ].x + ":" + face[ f ].y;
  20673. index = allPointsMap[ key ];
  20674. if ( index !== undefined ) {
  20675. face[ f ] = index;
  20676. }
  20677. }
  20678. }
  20679. return triangles.concat();
  20680. },
  20681. isClockWise: function ( pts ) {
  20682. return THREE.ShapeUtils.area( pts ) < 0;
  20683. },
  20684. // Bezier Curves formulas obtained from
  20685. // http://en.wikipedia.org/wiki/B%C3%A9zier_curve
  20686. // Quad Bezier Functions
  20687. b2: ( function () {
  20688. function b2p0( t, p ) {
  20689. var k = 1 - t;
  20690. return k * k * p;
  20691. }
  20692. function b2p1( t, p ) {
  20693. return 2 * ( 1 - t ) * t * p;
  20694. }
  20695. function b2p2( t, p ) {
  20696. return t * t * p;
  20697. }
  20698. return function b2( t, p0, p1, p2 ) {
  20699. return b2p0( t, p0 ) + b2p1( t, p1 ) + b2p2( t, p2 );
  20700. };
  20701. } )(),
  20702. // Cubic Bezier Functions
  20703. b3: ( function () {
  20704. function b3p0( t, p ) {
  20705. var k = 1 - t;
  20706. return k * k * k * p;
  20707. }
  20708. function b3p1( t, p ) {
  20709. var k = 1 - t;
  20710. return 3 * k * k * t * p;
  20711. }
  20712. function b3p2( t, p ) {
  20713. var k = 1 - t;
  20714. return 3 * k * t * t * p;
  20715. }
  20716. function b3p3( t, p ) {
  20717. return t * t * t * p;
  20718. }
  20719. return function b3( t, p0, p1, p2, p3 ) {
  20720. return b3p0( t, p0 ) + b3p1( t, p1 ) + b3p2( t, p2 ) + b3p3( t, p3 );
  20721. };
  20722. } )()
  20723. };
  20724. // File:src/extras/core/Curve.js
  20725. /**
  20726. * @author zz85 / http://www.lab4games.net/zz85/blog
  20727. * Extensible curve object
  20728. *
  20729. * Some common of Curve methods
  20730. * .getPoint(t), getTangent(t)
  20731. * .getPointAt(u), getTagentAt(u)
  20732. * .getPoints(), .getSpacedPoints()
  20733. * .getLength()
  20734. * .updateArcLengths()
  20735. *
  20736. * This following classes subclasses THREE.Curve:
  20737. *
  20738. * -- 2d classes --
  20739. * THREE.LineCurve
  20740. * THREE.QuadraticBezierCurve
  20741. * THREE.CubicBezierCurve
  20742. * THREE.SplineCurve
  20743. * THREE.ArcCurve
  20744. * THREE.EllipseCurve
  20745. *
  20746. * -- 3d classes --
  20747. * THREE.LineCurve3
  20748. * THREE.QuadraticBezierCurve3
  20749. * THREE.CubicBezierCurve3
  20750. * THREE.SplineCurve3
  20751. *
  20752. * A series of curves can be represented as a THREE.CurvePath
  20753. *
  20754. **/
  20755. /**************************************************************
  20756. * Abstract Curve base class
  20757. **************************************************************/
  20758. THREE.Curve = function () {
  20759. };
  20760. THREE.Curve.prototype = {
  20761. constructor: THREE.Curve,
  20762. // Virtual base class method to overwrite and implement in subclasses
  20763. // - t [0 .. 1]
  20764. getPoint: function ( t ) {
  20765. console.warn( "THREE.Curve: Warning, getPoint() not implemented!" );
  20766. return null;
  20767. },
  20768. // Get point at relative position in curve according to arc length
  20769. // - u [0 .. 1]
  20770. getPointAt: function ( u ) {
  20771. var t = this.getUtoTmapping( u );
  20772. return this.getPoint( t );
  20773. },
  20774. // Get sequence of points using getPoint( t )
  20775. getPoints: function ( divisions ) {
  20776. if ( ! divisions ) divisions = 5;
  20777. var points = [];
  20778. for ( var d = 0; d <= divisions; d ++ ) {
  20779. points.push( this.getPoint( d / divisions ) );
  20780. }
  20781. return points;
  20782. },
  20783. // Get sequence of points using getPointAt( u )
  20784. getSpacedPoints: function ( divisions ) {
  20785. if ( ! divisions ) divisions = 5;
  20786. var points = [];
  20787. for ( var d = 0; d <= divisions; d ++ ) {
  20788. points.push( this.getPointAt( d / divisions ) );
  20789. }
  20790. return points;
  20791. },
  20792. // Get total curve arc length
  20793. getLength: function () {
  20794. var lengths = this.getLengths();
  20795. return lengths[ lengths.length - 1 ];
  20796. },
  20797. // Get list of cumulative segment lengths
  20798. getLengths: function ( divisions ) {
  20799. if ( ! divisions ) divisions = ( this.__arcLengthDivisions ) ? ( this.__arcLengthDivisions ) : 200;
  20800. if ( this.cacheArcLengths
  20801. && ( this.cacheArcLengths.length === divisions + 1 )
  20802. && ! this.needsUpdate ) {
  20803. //console.log( "cached", this.cacheArcLengths );
  20804. return this.cacheArcLengths;
  20805. }
  20806. this.needsUpdate = false;
  20807. var cache = [];
  20808. var current, last = this.getPoint( 0 );
  20809. var p, sum = 0;
  20810. cache.push( 0 );
  20811. for ( p = 1; p <= divisions; p ++ ) {
  20812. current = this.getPoint ( p / divisions );
  20813. sum += current.distanceTo( last );
  20814. cache.push( sum );
  20815. last = current;
  20816. }
  20817. this.cacheArcLengths = cache;
  20818. return cache; // { sums: cache, sum:sum }; Sum is in the last element.
  20819. },
  20820. updateArcLengths: function() {
  20821. this.needsUpdate = true;
  20822. this.getLengths();
  20823. },
  20824. // Given u ( 0 .. 1 ), get a t to find p. This gives you points which are equidistant
  20825. getUtoTmapping: function ( u, distance ) {
  20826. var arcLengths = this.getLengths();
  20827. var i = 0, il = arcLengths.length;
  20828. var targetArcLength; // The targeted u distance value to get
  20829. if ( distance ) {
  20830. targetArcLength = distance;
  20831. } else {
  20832. targetArcLength = u * arcLengths[ il - 1 ];
  20833. }
  20834. //var time = Date.now();
  20835. // binary search for the index with largest value smaller than target u distance
  20836. var low = 0, high = il - 1, comparison;
  20837. while ( low <= high ) {
  20838. 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
  20839. comparison = arcLengths[ i ] - targetArcLength;
  20840. if ( comparison < 0 ) {
  20841. low = i + 1;
  20842. } else if ( comparison > 0 ) {
  20843. high = i - 1;
  20844. } else {
  20845. high = i;
  20846. break;
  20847. // DONE
  20848. }
  20849. }
  20850. i = high;
  20851. //console.log('b' , i, low, high, Date.now()- time);
  20852. if ( arcLengths[ i ] === targetArcLength ) {
  20853. var t = i / ( il - 1 );
  20854. return t;
  20855. }
  20856. // we could get finer grain at lengths, or use simple interpolation between two points
  20857. var lengthBefore = arcLengths[ i ];
  20858. var lengthAfter = arcLengths[ i + 1 ];
  20859. var segmentLength = lengthAfter - lengthBefore;
  20860. // determine where we are between the 'before' and 'after' points
  20861. var segmentFraction = ( targetArcLength - lengthBefore ) / segmentLength;
  20862. // add that fractional amount to t
  20863. var t = ( i + segmentFraction ) / ( il - 1 );
  20864. return t;
  20865. },
  20866. // Returns a unit vector tangent at t
  20867. // In case any sub curve does not implement its tangent derivation,
  20868. // 2 points a small delta apart will be used to find its gradient
  20869. // which seems to give a reasonable approximation
  20870. getTangent: function( t ) {
  20871. var delta = 0.0001;
  20872. var t1 = t - delta;
  20873. var t2 = t + delta;
  20874. // Capping in case of danger
  20875. if ( t1 < 0 ) t1 = 0;
  20876. if ( t2 > 1 ) t2 = 1;
  20877. var pt1 = this.getPoint( t1 );
  20878. var pt2 = this.getPoint( t2 );
  20879. var vec = pt2.clone().sub( pt1 );
  20880. return vec.normalize();
  20881. },
  20882. getTangentAt: function ( u ) {
  20883. var t = this.getUtoTmapping( u );
  20884. return this.getTangent( t );
  20885. }
  20886. };
  20887. // TODO: Transformation for Curves?
  20888. /**************************************************************
  20889. * 3D Curves
  20890. **************************************************************/
  20891. // A Factory method for creating new curve subclasses
  20892. THREE.Curve.create = function ( constructor, getPointFunc ) {
  20893. constructor.prototype = Object.create( THREE.Curve.prototype );
  20894. constructor.prototype.constructor = constructor;
  20895. constructor.prototype.getPoint = getPointFunc;
  20896. return constructor;
  20897. };
  20898. // File:src/extras/core/CurvePath.js
  20899. /**
  20900. * @author zz85 / http://www.lab4games.net/zz85/blog
  20901. *
  20902. **/
  20903. /**************************************************************
  20904. * Curved Path - a curve path is simply a array of connected
  20905. * curves, but retains the api of a curve
  20906. **************************************************************/
  20907. THREE.CurvePath = function () {
  20908. this.curves = [];
  20909. this.autoClose = false; // Automatically closes the path
  20910. };
  20911. THREE.CurvePath.prototype = Object.assign( Object.create( THREE.Curve.prototype ), {
  20912. constructor: THREE.CurvePath,
  20913. add: function ( curve ) {
  20914. this.curves.push( curve );
  20915. },
  20916. closePath: function () {
  20917. // Add a line curve if start and end of lines are not connected
  20918. var startPoint = this.curves[ 0 ].getPoint( 0 );
  20919. var endPoint = this.curves[ this.curves.length - 1 ].getPoint( 1 );
  20920. if ( ! startPoint.equals( endPoint ) ) {
  20921. this.curves.push( new THREE.LineCurve( endPoint, startPoint ) );
  20922. }
  20923. },
  20924. // To get accurate point with reference to
  20925. // entire path distance at time t,
  20926. // following has to be done:
  20927. // 1. Length of each sub path have to be known
  20928. // 2. Locate and identify type of curve
  20929. // 3. Get t for the curve
  20930. // 4. Return curve.getPointAt(t')
  20931. getPoint: function ( t ) {
  20932. var d = t * this.getLength();
  20933. var curveLengths = this.getCurveLengths();
  20934. var i = 0;
  20935. // To think about boundaries points.
  20936. while ( i < curveLengths.length ) {
  20937. if ( curveLengths[ i ] >= d ) {
  20938. var diff = curveLengths[ i ] - d;
  20939. var curve = this.curves[ i ];
  20940. var segmentLength = curve.getLength();
  20941. var u = segmentLength === 0 ? 0 : 1 - diff / segmentLength;
  20942. return curve.getPointAt( u );
  20943. }
  20944. i ++;
  20945. }
  20946. return null;
  20947. // loop where sum != 0, sum > d , sum+1 <d
  20948. },
  20949. // We cannot use the default THREE.Curve getPoint() with getLength() because in
  20950. // THREE.Curve, getLength() depends on getPoint() but in THREE.CurvePath
  20951. // getPoint() depends on getLength
  20952. getLength: function () {
  20953. var lens = this.getCurveLengths();
  20954. return lens[ lens.length - 1 ];
  20955. },
  20956. // cacheLengths must be recalculated.
  20957. updateArcLengths: function () {
  20958. this.needsUpdate = true;
  20959. this.cacheLengths = null;
  20960. this.getLengths();
  20961. },
  20962. // Compute lengths and cache them
  20963. // We cannot overwrite getLengths() because UtoT mapping uses it.
  20964. getCurveLengths: function () {
  20965. // We use cache values if curves and cache array are same length
  20966. if ( this.cacheLengths && this.cacheLengths.length === this.curves.length ) {
  20967. return this.cacheLengths;
  20968. }
  20969. // Get length of sub-curve
  20970. // Push sums into cached array
  20971. var lengths = [], sums = 0;
  20972. for ( var i = 0, l = this.curves.length; i < l; i ++ ) {
  20973. sums += this.curves[ i ].getLength();
  20974. lengths.push( sums );
  20975. }
  20976. this.cacheLengths = lengths;
  20977. return lengths;
  20978. },
  20979. getSpacedPoints: function ( divisions ) {
  20980. if ( ! divisions ) divisions = 40;
  20981. var points = [];
  20982. for ( var i = 0; i <= divisions; i ++ ) {
  20983. points.push( this.getPoint( i / divisions ) );
  20984. }
  20985. if ( this.autoClose ) {
  20986. points.push( points[ 0 ] );
  20987. }
  20988. return points;
  20989. },
  20990. getPoints: function ( divisions ) {
  20991. divisions = divisions || 12;
  20992. var points = [], last;
  20993. for ( var i = 0, curves = this.curves; i < curves.length; i ++ ) {
  20994. var curve = curves[ i ];
  20995. var pts = curve.getPoints( curve instanceof THREE.LineCurve ? 1 : divisions );
  20996. for ( var j = 0; j < pts.length; j++ ) {
  20997. var point = pts[ j ];
  20998. if ( last && last.equals( point ) ) continue; // ensures no consecutive points are duplicates
  20999. points.push( point );
  21000. last = point;
  21001. }
  21002. }
  21003. if ( this.autoClose && points.length > 1 && !points[ points.length - 1 ].equals( points[ 0 ] ) ) {
  21004. points.push( points[ 0 ] );
  21005. }
  21006. return points;
  21007. },
  21008. /**************************************************************
  21009. * Create Geometries Helpers
  21010. **************************************************************/
  21011. /// Generate geometry from path points (for Line or Points objects)
  21012. createPointsGeometry: function ( divisions ) {
  21013. var pts = this.getPoints( divisions );
  21014. return this.createGeometry( pts );
  21015. },
  21016. // Generate geometry from equidistant sampling along the path
  21017. createSpacedPointsGeometry: function ( divisions ) {
  21018. var pts = this.getSpacedPoints( divisions );
  21019. return this.createGeometry( pts );
  21020. },
  21021. createGeometry: function ( points ) {
  21022. var geometry = new THREE.Geometry();
  21023. for ( var i = 0, l = points.length; i < l; i ++ ) {
  21024. var point = points[ i ];
  21025. geometry.vertices.push( new THREE.Vector3( point.x, point.y, point.z || 0 ) );
  21026. }
  21027. return geometry;
  21028. }
  21029. } );
  21030. // File:src/extras/core/Font.js
  21031. /**
  21032. * @author zz85 / http://www.lab4games.net/zz85/blog
  21033. * @author mrdoob / http://mrdoob.com/
  21034. */
  21035. THREE.Font = function ( data ) {
  21036. this.data = data;
  21037. };
  21038. Object.assign( THREE.Font.prototype, {
  21039. generateShapes: function ( text, size, divisions ) {
  21040. function createPaths( text ) {
  21041. var chars = String( text ).split( '' );
  21042. var scale = size / data.resolution;
  21043. var offset = 0;
  21044. var paths = [];
  21045. for ( var i = 0; i < chars.length; i ++ ) {
  21046. var ret = createPath( chars[ i ], scale, offset );
  21047. offset += ret.offset;
  21048. paths.push( ret.path );
  21049. }
  21050. return paths;
  21051. }
  21052. function createPath( c, scale, offset ) {
  21053. var glyph = data.glyphs[ c ] || data.glyphs[ '?' ];
  21054. if ( ! glyph ) return;
  21055. var path = new THREE.ShapePath();
  21056. var pts = [], b2 = THREE.ShapeUtils.b2, b3 = THREE.ShapeUtils.b3;
  21057. var x, y, cpx, cpy, cpx0, cpy0, cpx1, cpy1, cpx2, cpy2, laste;
  21058. if ( glyph.o ) {
  21059. var outline = glyph._cachedOutline || ( glyph._cachedOutline = glyph.o.split( ' ' ) );
  21060. for ( var i = 0, l = outline.length; i < l; ) {
  21061. var action = outline[ i ++ ];
  21062. switch ( action ) {
  21063. case 'm': // moveTo
  21064. x = outline[ i ++ ] * scale + offset;
  21065. y = outline[ i ++ ] * scale;
  21066. path.moveTo( x, y );
  21067. break;
  21068. case 'l': // lineTo
  21069. x = outline[ i ++ ] * scale + offset;
  21070. y = outline[ i ++ ] * scale;
  21071. path.lineTo( x, y );
  21072. break;
  21073. case 'q': // quadraticCurveTo
  21074. cpx = outline[ i ++ ] * scale + offset;
  21075. cpy = outline[ i ++ ] * scale;
  21076. cpx1 = outline[ i ++ ] * scale + offset;
  21077. cpy1 = outline[ i ++ ] * scale;
  21078. path.quadraticCurveTo( cpx1, cpy1, cpx, cpy );
  21079. laste = pts[ pts.length - 1 ];
  21080. if ( laste ) {
  21081. cpx0 = laste.x;
  21082. cpy0 = laste.y;
  21083. for ( var i2 = 1; i2 <= divisions; i2 ++ ) {
  21084. var t = i2 / divisions;
  21085. b2( t, cpx0, cpx1, cpx );
  21086. b2( t, cpy0, cpy1, cpy );
  21087. }
  21088. }
  21089. break;
  21090. case 'b': // bezierCurveTo
  21091. cpx = outline[ i ++ ] * scale + offset;
  21092. cpy = outline[ i ++ ] * scale;
  21093. cpx1 = outline[ i ++ ] * scale + offset;
  21094. cpy1 = outline[ i ++ ] * scale;
  21095. cpx2 = outline[ i ++ ] * scale + offset;
  21096. cpy2 = outline[ i ++ ] * scale;
  21097. path.bezierCurveTo( cpx1, cpy1, cpx2, cpy2, cpx, cpy );
  21098. laste = pts[ pts.length - 1 ];
  21099. if ( laste ) {
  21100. cpx0 = laste.x;
  21101. cpy0 = laste.y;
  21102. for ( var i2 = 1; i2 <= divisions; i2 ++ ) {
  21103. var t = i2 / divisions;
  21104. b3( t, cpx0, cpx1, cpx2, cpx );
  21105. b3( t, cpy0, cpy1, cpy2, cpy );
  21106. }
  21107. }
  21108. break;
  21109. }
  21110. }
  21111. }
  21112. return { offset: glyph.ha * scale, path: path };
  21113. }
  21114. //
  21115. if ( size === undefined ) size = 100;
  21116. if ( divisions === undefined ) divisions = 4;
  21117. var data = this.data;
  21118. var paths = createPaths( text );
  21119. var shapes = [];
  21120. for ( var p = 0, pl = paths.length; p < pl; p ++ ) {
  21121. Array.prototype.push.apply( shapes, paths[ p ].toShapes() );
  21122. }
  21123. return shapes;
  21124. }
  21125. } );
  21126. // File:src/extras/core/Path.js
  21127. /**
  21128. * @author zz85 / http://www.lab4games.net/zz85/blog
  21129. * Creates free form 2d path using series of points, lines or curves.
  21130. *
  21131. **/
  21132. THREE.Path = function ( points ) {
  21133. THREE.CurvePath.call( this );
  21134. this.currentPoint = new THREE.Vector2();
  21135. if ( points ) {
  21136. this.fromPoints( points );
  21137. }
  21138. };
  21139. THREE.Path.prototype = Object.assign( Object.create( THREE.CurvePath.prototype ), {
  21140. constructor: THREE.Path,
  21141. // Create path using straight lines to connect all points
  21142. // - vectors: array of Vector2
  21143. fromPoints: function ( vectors ) {
  21144. this.moveTo( vectors[ 0 ].x, vectors[ 0 ].y );
  21145. for ( var i = 1, l = vectors.length; i < l; i ++ ) {
  21146. this.lineTo( vectors[ i ].x, vectors[ i ].y );
  21147. }
  21148. },
  21149. moveTo: function ( x, y ) {
  21150. this.currentPoint.set( x, y ); // TODO consider referencing vectors instead of copying?
  21151. },
  21152. lineTo: function ( x, y ) {
  21153. var curve = new THREE.LineCurve( this.currentPoint.clone(), new THREE.Vector2( x, y ) );
  21154. this.curves.push( curve );
  21155. this.currentPoint.set( x, y );
  21156. },
  21157. quadraticCurveTo: function ( aCPx, aCPy, aX, aY ) {
  21158. var curve = new THREE.QuadraticBezierCurve(
  21159. this.currentPoint.clone(),
  21160. new THREE.Vector2( aCPx, aCPy ),
  21161. new THREE.Vector2( aX, aY )
  21162. );
  21163. this.curves.push( curve );
  21164. this.currentPoint.set( aX, aY );
  21165. },
  21166. bezierCurveTo: function ( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY ) {
  21167. var curve = new THREE.CubicBezierCurve(
  21168. this.currentPoint.clone(),
  21169. new THREE.Vector2( aCP1x, aCP1y ),
  21170. new THREE.Vector2( aCP2x, aCP2y ),
  21171. new THREE.Vector2( aX, aY )
  21172. );
  21173. this.curves.push( curve );
  21174. this.currentPoint.set( aX, aY );
  21175. },
  21176. splineThru: function ( pts /*Array of Vector*/ ) {
  21177. var npts = [ this.currentPoint.clone() ].concat( pts );
  21178. var curve = new THREE.SplineCurve( npts );
  21179. this.curves.push( curve );
  21180. this.currentPoint.copy( pts[ pts.length - 1 ] );
  21181. },
  21182. arc: function ( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  21183. var x0 = this.currentPoint.x;
  21184. var y0 = this.currentPoint.y;
  21185. this.absarc( aX + x0, aY + y0, aRadius,
  21186. aStartAngle, aEndAngle, aClockwise );
  21187. },
  21188. absarc: function ( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  21189. this.absellipse( aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise );
  21190. },
  21191. ellipse: function ( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  21192. var x0 = this.currentPoint.x;
  21193. var y0 = this.currentPoint.y;
  21194. this.absellipse( aX + x0, aY + y0, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation );
  21195. },
  21196. absellipse: function ( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  21197. var curve = new THREE.EllipseCurve( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation );
  21198. if ( this.curves.length > 0 ) {
  21199. // if a previous curve is present, attempt to join
  21200. var firstPoint = curve.getPoint( 0 );
  21201. if ( ! firstPoint.equals( this.currentPoint ) ) {
  21202. this.lineTo( firstPoint.x, firstPoint.y );
  21203. }
  21204. }
  21205. this.curves.push( curve );
  21206. var lastPoint = curve.getPoint( 1 );
  21207. this.currentPoint.copy( lastPoint );
  21208. }
  21209. } );
  21210. // minimal class for proxing functions to Path. Replaces old "extractSubpaths()"
  21211. THREE.ShapePath = function() {
  21212. this.subPaths = [];
  21213. this.currentPath = null;
  21214. }
  21215. THREE.ShapePath.prototype = {
  21216. moveTo: function ( x, y ) {
  21217. this.currentPath = new THREE.Path();
  21218. this.subPaths.push(this.currentPath);
  21219. this.currentPath.moveTo( x, y );
  21220. },
  21221. lineTo: function ( x, y ) {
  21222. this.currentPath.lineTo( x, y );
  21223. },
  21224. quadraticCurveTo: function ( aCPx, aCPy, aX, aY ) {
  21225. this.currentPath.quadraticCurveTo( aCPx, aCPy, aX, aY );
  21226. },
  21227. bezierCurveTo: function ( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY ) {
  21228. this.currentPath.bezierCurveTo( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY );
  21229. },
  21230. splineThru: function ( pts ) {
  21231. this.currentPath.splineThru( pts );
  21232. },
  21233. toShapes: function ( isCCW, noHoles ) {
  21234. function toShapesNoHoles( inSubpaths ) {
  21235. var shapes = [];
  21236. for ( var i = 0, l = inSubpaths.length; i < l; i ++ ) {
  21237. var tmpPath = inSubpaths[ i ];
  21238. var tmpShape = new THREE.Shape();
  21239. tmpShape.curves = tmpPath.curves;
  21240. shapes.push( tmpShape );
  21241. }
  21242. return shapes;
  21243. }
  21244. function isPointInsidePolygon( inPt, inPolygon ) {
  21245. var polyLen = inPolygon.length;
  21246. // inPt on polygon contour => immediate success or
  21247. // toggling of inside/outside at every single! intersection point of an edge
  21248. // with the horizontal line through inPt, left of inPt
  21249. // not counting lowerY endpoints of edges and whole edges on that line
  21250. var inside = false;
  21251. for ( var p = polyLen - 1, q = 0; q < polyLen; p = q ++ ) {
  21252. var edgeLowPt = inPolygon[ p ];
  21253. var edgeHighPt = inPolygon[ q ];
  21254. var edgeDx = edgeHighPt.x - edgeLowPt.x;
  21255. var edgeDy = edgeHighPt.y - edgeLowPt.y;
  21256. if ( Math.abs( edgeDy ) > Number.EPSILON ) {
  21257. // not parallel
  21258. if ( edgeDy < 0 ) {
  21259. edgeLowPt = inPolygon[ q ]; edgeDx = - edgeDx;
  21260. edgeHighPt = inPolygon[ p ]; edgeDy = - edgeDy;
  21261. }
  21262. if ( ( inPt.y < edgeLowPt.y ) || ( inPt.y > edgeHighPt.y ) ) continue;
  21263. if ( inPt.y === edgeLowPt.y ) {
  21264. if ( inPt.x === edgeLowPt.x ) return true; // inPt is on contour ?
  21265. // continue; // no intersection or edgeLowPt => doesn't count !!!
  21266. } else {
  21267. var perpEdge = edgeDy * ( inPt.x - edgeLowPt.x ) - edgeDx * ( inPt.y - edgeLowPt.y );
  21268. if ( perpEdge === 0 ) return true; // inPt is on contour ?
  21269. if ( perpEdge < 0 ) continue;
  21270. inside = ! inside; // true intersection left of inPt
  21271. }
  21272. } else {
  21273. // parallel or collinear
  21274. if ( inPt.y !== edgeLowPt.y ) continue; // parallel
  21275. // edge lies on the same horizontal line as inPt
  21276. if ( ( ( edgeHighPt.x <= inPt.x ) && ( inPt.x <= edgeLowPt.x ) ) ||
  21277. ( ( edgeLowPt.x <= inPt.x ) && ( inPt.x <= edgeHighPt.x ) ) ) return true; // inPt: Point on contour !
  21278. // continue;
  21279. }
  21280. }
  21281. return inside;
  21282. }
  21283. var isClockWise = THREE.ShapeUtils.isClockWise;
  21284. var subPaths = this.subPaths;
  21285. if ( subPaths.length === 0 ) return [];
  21286. if ( noHoles === true ) return toShapesNoHoles( subPaths );
  21287. var solid, tmpPath, tmpShape, shapes = [];
  21288. if ( subPaths.length === 1 ) {
  21289. tmpPath = subPaths[ 0 ];
  21290. tmpShape = new THREE.Shape();
  21291. tmpShape.curves = tmpPath.curves;
  21292. shapes.push( tmpShape );
  21293. return shapes;
  21294. }
  21295. var holesFirst = ! isClockWise( subPaths[ 0 ].getPoints() );
  21296. holesFirst = isCCW ? ! holesFirst : holesFirst;
  21297. // console.log("Holes first", holesFirst);
  21298. var betterShapeHoles = [];
  21299. var newShapes = [];
  21300. var newShapeHoles = [];
  21301. var mainIdx = 0;
  21302. var tmpPoints;
  21303. newShapes[ mainIdx ] = undefined;
  21304. newShapeHoles[ mainIdx ] = [];
  21305. for ( var i = 0, l = subPaths.length; i < l; i ++ ) {
  21306. tmpPath = subPaths[ i ];
  21307. tmpPoints = tmpPath.getPoints();
  21308. solid = isClockWise( tmpPoints );
  21309. solid = isCCW ? ! solid : solid;
  21310. if ( solid ) {
  21311. if ( ( ! holesFirst ) && ( newShapes[ mainIdx ] ) ) mainIdx ++;
  21312. newShapes[ mainIdx ] = { s: new THREE.Shape(), p: tmpPoints };
  21313. newShapes[ mainIdx ].s.curves = tmpPath.curves;
  21314. if ( holesFirst ) mainIdx ++;
  21315. newShapeHoles[ mainIdx ] = [];
  21316. //console.log('cw', i);
  21317. } else {
  21318. newShapeHoles[ mainIdx ].push( { h: tmpPath, p: tmpPoints[ 0 ] } );
  21319. //console.log('ccw', i);
  21320. }
  21321. }
  21322. // only Holes? -> probably all Shapes with wrong orientation
  21323. if ( ! newShapes[ 0 ] ) return toShapesNoHoles( subPaths );
  21324. if ( newShapes.length > 1 ) {
  21325. var ambiguous = false;
  21326. var toChange = [];
  21327. for ( var sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx ++ ) {
  21328. betterShapeHoles[ sIdx ] = [];
  21329. }
  21330. for ( var sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx ++ ) {
  21331. var sho = newShapeHoles[ sIdx ];
  21332. for ( var hIdx = 0; hIdx < sho.length; hIdx ++ ) {
  21333. var ho = sho[ hIdx ];
  21334. var hole_unassigned = true;
  21335. for ( var s2Idx = 0; s2Idx < newShapes.length; s2Idx ++ ) {
  21336. if ( isPointInsidePolygon( ho.p, newShapes[ s2Idx ].p ) ) {
  21337. if ( sIdx !== s2Idx ) toChange.push( { froms: sIdx, tos: s2Idx, hole: hIdx } );
  21338. if ( hole_unassigned ) {
  21339. hole_unassigned = false;
  21340. betterShapeHoles[ s2Idx ].push( ho );
  21341. } else {
  21342. ambiguous = true;
  21343. }
  21344. }
  21345. }
  21346. if ( hole_unassigned ) {
  21347. betterShapeHoles[ sIdx ].push( ho );
  21348. }
  21349. }
  21350. }
  21351. // console.log("ambiguous: ", ambiguous);
  21352. if ( toChange.length > 0 ) {
  21353. // console.log("to change: ", toChange);
  21354. if ( ! ambiguous ) newShapeHoles = betterShapeHoles;
  21355. }
  21356. }
  21357. var tmpHoles;
  21358. for ( var i = 0, il = newShapes.length; i < il; i ++ ) {
  21359. tmpShape = newShapes[ i ].s;
  21360. shapes.push( tmpShape );
  21361. tmpHoles = newShapeHoles[ i ];
  21362. for ( var j = 0, jl = tmpHoles.length; j < jl; j ++ ) {
  21363. tmpShape.holes.push( tmpHoles[ j ].h );
  21364. }
  21365. }
  21366. //console.log("shape", shapes);
  21367. return shapes;
  21368. }
  21369. }
  21370. // File:src/extras/core/Shape.js
  21371. /**
  21372. * @author zz85 / http://www.lab4games.net/zz85/blog
  21373. * Defines a 2d shape plane using paths.
  21374. **/
  21375. // STEP 1 Create a path.
  21376. // STEP 2 Turn path into shape.
  21377. // STEP 3 ExtrudeGeometry takes in Shape/Shapes
  21378. // STEP 3a - Extract points from each shape, turn to vertices
  21379. // STEP 3b - Triangulate each shape, add faces.
  21380. THREE.Shape = function () {
  21381. THREE.Path.apply( this, arguments );
  21382. this.holes = [];
  21383. };
  21384. THREE.Shape.prototype = Object.assign( Object.create( THREE.Path.prototype ), {
  21385. constructor: THREE.Shape,
  21386. // Convenience method to return ExtrudeGeometry
  21387. extrude: function ( options ) {
  21388. return new THREE.ExtrudeGeometry( this, options );
  21389. },
  21390. // Convenience method to return ShapeGeometry
  21391. makeGeometry: function ( options ) {
  21392. return new THREE.ShapeGeometry( this, options );
  21393. },
  21394. getPointsHoles: function ( divisions ) {
  21395. var holesPts = [];
  21396. for ( var i = 0, l = this.holes.length; i < l; i ++ ) {
  21397. holesPts[ i ] = this.holes[ i ].getPoints( divisions );
  21398. }
  21399. return holesPts;
  21400. },
  21401. // Get points of shape and holes (keypoints based on segments parameter)
  21402. extractAllPoints: function ( divisions ) {
  21403. return {
  21404. shape: this.getPoints( divisions ),
  21405. holes: this.getPointsHoles( divisions )
  21406. };
  21407. },
  21408. extractPoints: function ( divisions ) {
  21409. return this.extractAllPoints( divisions );
  21410. }
  21411. } );
  21412. // File:src/extras/curves/LineCurve.js
  21413. /**************************************************************
  21414. * Line
  21415. **************************************************************/
  21416. THREE.LineCurve = function ( v1, v2 ) {
  21417. this.v1 = v1;
  21418. this.v2 = v2;
  21419. };
  21420. THREE.LineCurve.prototype = Object.create( THREE.Curve.prototype );
  21421. THREE.LineCurve.prototype.constructor = THREE.LineCurve;
  21422. THREE.LineCurve.prototype.getPoint = function ( t ) {
  21423. if ( t === 1 ) {
  21424. return this.v2.clone();
  21425. }
  21426. var point = this.v2.clone().sub( this.v1 );
  21427. point.multiplyScalar( t ).add( this.v1 );
  21428. return point;
  21429. };
  21430. // Line curve is linear, so we can overwrite default getPointAt
  21431. THREE.LineCurve.prototype.getPointAt = function ( u ) {
  21432. return this.getPoint( u );
  21433. };
  21434. THREE.LineCurve.prototype.getTangent = function( t ) {
  21435. var tangent = this.v2.clone().sub( this.v1 );
  21436. return tangent.normalize();
  21437. };
  21438. // File:src/extras/curves/QuadraticBezierCurve.js
  21439. /**************************************************************
  21440. * Quadratic Bezier curve
  21441. **************************************************************/
  21442. THREE.QuadraticBezierCurve = function ( v0, v1, v2 ) {
  21443. this.v0 = v0;
  21444. this.v1 = v1;
  21445. this.v2 = v2;
  21446. };
  21447. THREE.QuadraticBezierCurve.prototype = Object.create( THREE.Curve.prototype );
  21448. THREE.QuadraticBezierCurve.prototype.constructor = THREE.QuadraticBezierCurve;
  21449. THREE.QuadraticBezierCurve.prototype.getPoint = function ( t ) {
  21450. var b2 = THREE.ShapeUtils.b2;
  21451. return new THREE.Vector2(
  21452. b2( t, this.v0.x, this.v1.x, this.v2.x ),
  21453. b2( t, this.v0.y, this.v1.y, this.v2.y )
  21454. );
  21455. };
  21456. THREE.QuadraticBezierCurve.prototype.getTangent = function( t ) {
  21457. var tangentQuadraticBezier = THREE.CurveUtils.tangentQuadraticBezier;
  21458. return new THREE.Vector2(
  21459. tangentQuadraticBezier( t, this.v0.x, this.v1.x, this.v2.x ),
  21460. tangentQuadraticBezier( t, this.v0.y, this.v1.y, this.v2.y )
  21461. ).normalize();
  21462. };
  21463. // File:src/extras/curves/CubicBezierCurve.js
  21464. /**************************************************************
  21465. * Cubic Bezier curve
  21466. **************************************************************/
  21467. THREE.CubicBezierCurve = function ( v0, v1, v2, v3 ) {
  21468. this.v0 = v0;
  21469. this.v1 = v1;
  21470. this.v2 = v2;
  21471. this.v3 = v3;
  21472. };
  21473. THREE.CubicBezierCurve.prototype = Object.create( THREE.Curve.prototype );
  21474. THREE.CubicBezierCurve.prototype.constructor = THREE.CubicBezierCurve;
  21475. THREE.CubicBezierCurve.prototype.getPoint = function ( t ) {
  21476. var b3 = THREE.ShapeUtils.b3;
  21477. return new THREE.Vector2(
  21478. b3( t, this.v0.x, this.v1.x, this.v2.x, this.v3.x ),
  21479. b3( t, this.v0.y, this.v1.y, this.v2.y, this.v3.y )
  21480. );
  21481. };
  21482. THREE.CubicBezierCurve.prototype.getTangent = function( t ) {
  21483. var tangentCubicBezier = THREE.CurveUtils.tangentCubicBezier;
  21484. return new THREE.Vector2(
  21485. tangentCubicBezier( t, this.v0.x, this.v1.x, this.v2.x, this.v3.x ),
  21486. tangentCubicBezier( t, this.v0.y, this.v1.y, this.v2.y, this.v3.y )
  21487. ).normalize();
  21488. };
  21489. // File:src/extras/curves/SplineCurve.js
  21490. /**************************************************************
  21491. * Spline curve
  21492. **************************************************************/
  21493. THREE.SplineCurve = function ( points /* array of Vector2 */ ) {
  21494. this.points = ( points == undefined ) ? [] : points;
  21495. };
  21496. THREE.SplineCurve.prototype = Object.create( THREE.Curve.prototype );
  21497. THREE.SplineCurve.prototype.constructor = THREE.SplineCurve;
  21498. THREE.SplineCurve.prototype.getPoint = function ( t ) {
  21499. var points = this.points;
  21500. var point = ( points.length - 1 ) * t;
  21501. var intPoint = Math.floor( point );
  21502. var weight = point - intPoint;
  21503. var point0 = points[ intPoint === 0 ? intPoint : intPoint - 1 ];
  21504. var point1 = points[ intPoint ];
  21505. var point2 = points[ intPoint > points.length - 2 ? points.length - 1 : intPoint + 1 ];
  21506. var point3 = points[ intPoint > points.length - 3 ? points.length - 1 : intPoint + 2 ];
  21507. var interpolate = THREE.CurveUtils.interpolate;
  21508. return new THREE.Vector2(
  21509. interpolate( point0.x, point1.x, point2.x, point3.x, weight ),
  21510. interpolate( point0.y, point1.y, point2.y, point3.y, weight )
  21511. );
  21512. };
  21513. // File:src/extras/curves/EllipseCurve.js
  21514. /**************************************************************
  21515. * Ellipse curve
  21516. **************************************************************/
  21517. THREE.EllipseCurve = function( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  21518. this.aX = aX;
  21519. this.aY = aY;
  21520. this.xRadius = xRadius;
  21521. this.yRadius = yRadius;
  21522. this.aStartAngle = aStartAngle;
  21523. this.aEndAngle = aEndAngle;
  21524. this.aClockwise = aClockwise;
  21525. this.aRotation = aRotation || 0;
  21526. };
  21527. THREE.EllipseCurve.prototype = Object.create( THREE.Curve.prototype );
  21528. THREE.EllipseCurve.prototype.constructor = THREE.EllipseCurve;
  21529. THREE.EllipseCurve.prototype.getPoint = function( t ) {
  21530. var twoPi = Math.PI * 2;
  21531. var deltaAngle = this.aEndAngle - this.aStartAngle;
  21532. var samePoints = Math.abs( deltaAngle ) < Number.EPSILON;
  21533. // ensures that deltaAngle is 0 .. 2 PI
  21534. while ( deltaAngle < 0 ) deltaAngle += twoPi;
  21535. while ( deltaAngle > twoPi ) deltaAngle -= twoPi;
  21536. if ( deltaAngle < Number.EPSILON ) {
  21537. if ( samePoints ) {
  21538. deltaAngle = 0;
  21539. } else {
  21540. deltaAngle = twoPi;
  21541. }
  21542. }
  21543. if ( this.aClockwise === true && deltaAngle != twoPi && ! samePoints ) {
  21544. deltaAngle = deltaAngle - twoPi;
  21545. }
  21546. var angle = this.aStartAngle + t * deltaAngle;
  21547. var x = this.aX + this.xRadius * Math.cos( angle );
  21548. var y = this.aY + this.yRadius * Math.sin( angle );
  21549. if ( this.aRotation !== 0 ) {
  21550. var cos = Math.cos( this.aRotation );
  21551. var sin = Math.sin( this.aRotation );
  21552. var tx = x - this.aX;
  21553. var ty = y - this.aY;
  21554. // Rotate the point about the center of the ellipse.
  21555. x = tx * cos - ty * sin + this.aX;
  21556. y = tx * sin + ty * cos + this.aY;
  21557. }
  21558. return new THREE.Vector2( x, y );
  21559. };
  21560. // File:src/extras/curves/ArcCurve.js
  21561. /**************************************************************
  21562. * Arc curve
  21563. **************************************************************/
  21564. THREE.ArcCurve = function ( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  21565. THREE.EllipseCurve.call( this, aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise );
  21566. };
  21567. THREE.ArcCurve.prototype = Object.create( THREE.EllipseCurve.prototype );
  21568. THREE.ArcCurve.prototype.constructor = THREE.ArcCurve;
  21569. // File:src/extras/curves/LineCurve3.js
  21570. /**************************************************************
  21571. * Line3D
  21572. **************************************************************/
  21573. THREE.LineCurve3 = THREE.Curve.create(
  21574. function ( v1, v2 ) {
  21575. this.v1 = v1;
  21576. this.v2 = v2;
  21577. },
  21578. function ( t ) {
  21579. if ( t === 1 ) {
  21580. return this.v2.clone();
  21581. }
  21582. var vector = new THREE.Vector3();
  21583. vector.subVectors( this.v2, this.v1 ); // diff
  21584. vector.multiplyScalar( t );
  21585. vector.add( this.v1 );
  21586. return vector;
  21587. }
  21588. );
  21589. // File:src/extras/curves/QuadraticBezierCurve3.js
  21590. /**************************************************************
  21591. * Quadratic Bezier 3D curve
  21592. **************************************************************/
  21593. THREE.QuadraticBezierCurve3 = THREE.Curve.create(
  21594. function ( v0, v1, v2 ) {
  21595. this.v0 = v0;
  21596. this.v1 = v1;
  21597. this.v2 = v2;
  21598. },
  21599. function ( t ) {
  21600. var b2 = THREE.ShapeUtils.b2;
  21601. return new THREE.Vector3(
  21602. b2( t, this.v0.x, this.v1.x, this.v2.x ),
  21603. b2( t, this.v0.y, this.v1.y, this.v2.y ),
  21604. b2( t, this.v0.z, this.v1.z, this.v2.z )
  21605. );
  21606. }
  21607. );
  21608. // File:src/extras/curves/CubicBezierCurve3.js
  21609. /**************************************************************
  21610. * Cubic Bezier 3D curve
  21611. **************************************************************/
  21612. THREE.CubicBezierCurve3 = THREE.Curve.create(
  21613. function ( v0, v1, v2, v3 ) {
  21614. this.v0 = v0;
  21615. this.v1 = v1;
  21616. this.v2 = v2;
  21617. this.v3 = v3;
  21618. },
  21619. function ( t ) {
  21620. var b3 = THREE.ShapeUtils.b3;
  21621. return new THREE.Vector3(
  21622. b3( t, this.v0.x, this.v1.x, this.v2.x, this.v3.x ),
  21623. b3( t, this.v0.y, this.v1.y, this.v2.y, this.v3.y ),
  21624. b3( t, this.v0.z, this.v1.z, this.v2.z, this.v3.z )
  21625. );
  21626. }
  21627. );
  21628. // File:src/extras/curves/SplineCurve3.js
  21629. /**************************************************************
  21630. * Spline 3D curve
  21631. **************************************************************/
  21632. THREE.SplineCurve3 = THREE.Curve.create(
  21633. function ( points /* array of Vector3 */ ) {
  21634. console.warn( 'THREE.SplineCurve3 will be deprecated. Please use THREE.CatmullRomCurve3' );
  21635. this.points = ( points == undefined ) ? [] : points;
  21636. },
  21637. function ( t ) {
  21638. var points = this.points;
  21639. var point = ( points.length - 1 ) * t;
  21640. var intPoint = Math.floor( point );
  21641. var weight = point - intPoint;
  21642. var point0 = points[ intPoint == 0 ? intPoint : intPoint - 1 ];
  21643. var point1 = points[ intPoint ];
  21644. var point2 = points[ intPoint > points.length - 2 ? points.length - 1 : intPoint + 1 ];
  21645. var point3 = points[ intPoint > points.length - 3 ? points.length - 1 : intPoint + 2 ];
  21646. var interpolate = THREE.CurveUtils.interpolate;
  21647. return new THREE.Vector3(
  21648. interpolate( point0.x, point1.x, point2.x, point3.x, weight ),
  21649. interpolate( point0.y, point1.y, point2.y, point3.y, weight ),
  21650. interpolate( point0.z, point1.z, point2.z, point3.z, weight )
  21651. );
  21652. }
  21653. );
  21654. // File:src/extras/curves/CatmullRomCurve3.js
  21655. /**
  21656. * @author zz85 https://github.com/zz85
  21657. *
  21658. * Centripetal CatmullRom Curve - which is useful for avoiding
  21659. * cusps and self-intersections in non-uniform catmull rom curves.
  21660. * http://www.cemyuksel.com/research/catmullrom_param/catmullrom.pdf
  21661. *
  21662. * curve.type accepts centripetal(default), chordal and catmullrom
  21663. * curve.tension is used for catmullrom which defaults to 0.5
  21664. */
  21665. THREE.CatmullRomCurve3 = ( function() {
  21666. var
  21667. tmp = new THREE.Vector3(),
  21668. px = new CubicPoly(),
  21669. py = new CubicPoly(),
  21670. pz = new CubicPoly();
  21671. /*
  21672. Based on an optimized c++ solution in
  21673. - http://stackoverflow.com/questions/9489736/catmull-rom-curve-with-no-cusps-and-no-self-intersections/
  21674. - http://ideone.com/NoEbVM
  21675. This CubicPoly class could be used for reusing some variables and calculations,
  21676. but for three.js curve use, it could be possible inlined and flatten into a single function call
  21677. which can be placed in CurveUtils.
  21678. */
  21679. function CubicPoly() {
  21680. }
  21681. /*
  21682. * Compute coefficients for a cubic polynomial
  21683. * p(s) = c0 + c1*s + c2*s^2 + c3*s^3
  21684. * such that
  21685. * p(0) = x0, p(1) = x1
  21686. * and
  21687. * p'(0) = t0, p'(1) = t1.
  21688. */
  21689. CubicPoly.prototype.init = function( x0, x1, t0, t1 ) {
  21690. this.c0 = x0;
  21691. this.c1 = t0;
  21692. this.c2 = - 3 * x0 + 3 * x1 - 2 * t0 - t1;
  21693. this.c3 = 2 * x0 - 2 * x1 + t0 + t1;
  21694. };
  21695. CubicPoly.prototype.initNonuniformCatmullRom = function( x0, x1, x2, x3, dt0, dt1, dt2 ) {
  21696. // compute tangents when parameterized in [t1,t2]
  21697. var t1 = ( x1 - x0 ) / dt0 - ( x2 - x0 ) / ( dt0 + dt1 ) + ( x2 - x1 ) / dt1;
  21698. var t2 = ( x2 - x1 ) / dt1 - ( x3 - x1 ) / ( dt1 + dt2 ) + ( x3 - x2 ) / dt2;
  21699. // rescale tangents for parametrization in [0,1]
  21700. t1 *= dt1;
  21701. t2 *= dt1;
  21702. // initCubicPoly
  21703. this.init( x1, x2, t1, t2 );
  21704. };
  21705. // standard Catmull-Rom spline: interpolate between x1 and x2 with previous/following points x1/x4
  21706. CubicPoly.prototype.initCatmullRom = function( x0, x1, x2, x3, tension ) {
  21707. this.init( x1, x2, tension * ( x2 - x0 ), tension * ( x3 - x1 ) );
  21708. };
  21709. CubicPoly.prototype.calc = function( t ) {
  21710. var t2 = t * t;
  21711. var t3 = t2 * t;
  21712. return this.c0 + this.c1 * t + this.c2 * t2 + this.c3 * t3;
  21713. };
  21714. // Subclass Three.js curve
  21715. return THREE.Curve.create(
  21716. function ( p /* array of Vector3 */ ) {
  21717. this.points = p || [];
  21718. this.closed = false;
  21719. },
  21720. function ( t ) {
  21721. var points = this.points,
  21722. point, intPoint, weight, l;
  21723. l = points.length;
  21724. if ( l < 2 ) console.log( 'duh, you need at least 2 points' );
  21725. point = ( l - ( this.closed ? 0 : 1 ) ) * t;
  21726. intPoint = Math.floor( point );
  21727. weight = point - intPoint;
  21728. if ( this.closed ) {
  21729. intPoint += intPoint > 0 ? 0 : ( Math.floor( Math.abs( intPoint ) / points.length ) + 1 ) * points.length;
  21730. } else if ( weight === 0 && intPoint === l - 1 ) {
  21731. intPoint = l - 2;
  21732. weight = 1;
  21733. }
  21734. var p0, p1, p2, p3; // 4 points
  21735. if ( this.closed || intPoint > 0 ) {
  21736. p0 = points[ ( intPoint - 1 ) % l ];
  21737. } else {
  21738. // extrapolate first point
  21739. tmp.subVectors( points[ 0 ], points[ 1 ] ).add( points[ 0 ] );
  21740. p0 = tmp;
  21741. }
  21742. p1 = points[ intPoint % l ];
  21743. p2 = points[ ( intPoint + 1 ) % l ];
  21744. if ( this.closed || intPoint + 2 < l ) {
  21745. p3 = points[ ( intPoint + 2 ) % l ];
  21746. } else {
  21747. // extrapolate last point
  21748. tmp.subVectors( points[ l - 1 ], points[ l - 2 ] ).add( points[ l - 1 ] );
  21749. p3 = tmp;
  21750. }
  21751. if ( this.type === undefined || this.type === 'centripetal' || this.type === 'chordal' ) {
  21752. // init Centripetal / Chordal Catmull-Rom
  21753. var pow = this.type === 'chordal' ? 0.5 : 0.25;
  21754. var dt0 = Math.pow( p0.distanceToSquared( p1 ), pow );
  21755. var dt1 = Math.pow( p1.distanceToSquared( p2 ), pow );
  21756. var dt2 = Math.pow( p2.distanceToSquared( p3 ), pow );
  21757. // safety check for repeated points
  21758. if ( dt1 < 1e-4 ) dt1 = 1.0;
  21759. if ( dt0 < 1e-4 ) dt0 = dt1;
  21760. if ( dt2 < 1e-4 ) dt2 = dt1;
  21761. px.initNonuniformCatmullRom( p0.x, p1.x, p2.x, p3.x, dt0, dt1, dt2 );
  21762. py.initNonuniformCatmullRom( p0.y, p1.y, p2.y, p3.y, dt0, dt1, dt2 );
  21763. pz.initNonuniformCatmullRom( p0.z, p1.z, p2.z, p3.z, dt0, dt1, dt2 );
  21764. } else if ( this.type === 'catmullrom' ) {
  21765. var tension = this.tension !== undefined ? this.tension : 0.5;
  21766. px.initCatmullRom( p0.x, p1.x, p2.x, p3.x, tension );
  21767. py.initCatmullRom( p0.y, p1.y, p2.y, p3.y, tension );
  21768. pz.initCatmullRom( p0.z, p1.z, p2.z, p3.z, tension );
  21769. }
  21770. var v = new THREE.Vector3(
  21771. px.calc( weight ),
  21772. py.calc( weight ),
  21773. pz.calc( weight )
  21774. );
  21775. return v;
  21776. }
  21777. );
  21778. } )();
  21779. // File:src/extras/curves/ClosedSplineCurve3.js
  21780. /**************************************************************
  21781. * Closed Spline 3D curve
  21782. **************************************************************/
  21783. THREE.ClosedSplineCurve3 = function ( points ) {
  21784. console.warn( 'THREE.ClosedSplineCurve3 has been deprecated. Please use THREE.CatmullRomCurve3.' );
  21785. THREE.CatmullRomCurve3.call( this, points );
  21786. this.type = 'catmullrom';
  21787. this.closed = true;
  21788. };
  21789. THREE.ClosedSplineCurve3.prototype = Object.create( THREE.CatmullRomCurve3.prototype );
  21790. // File:src/extras/geometries/BoxGeometry.js
  21791. /**
  21792. * @author mrdoob / http://mrdoob.com/
  21793. * based on http://papervision3d.googlecode.com/svn/trunk/as3/trunk/src/org/papervision3d/objects/primitives/Cube.as
  21794. */
  21795. THREE.BoxGeometry = function ( width, height, depth, widthSegments, heightSegments, depthSegments ) {
  21796. THREE.Geometry.call( this );
  21797. this.type = 'BoxGeometry';
  21798. this.parameters = {
  21799. width: width,
  21800. height: height,
  21801. depth: depth,
  21802. widthSegments: widthSegments,
  21803. heightSegments: heightSegments,
  21804. depthSegments: depthSegments
  21805. };
  21806. this.fromBufferGeometry( new THREE.BoxBufferGeometry( width, height, depth, widthSegments, heightSegments, depthSegments ) );
  21807. this.mergeVertices();
  21808. };
  21809. THREE.BoxGeometry.prototype = Object.create( THREE.Geometry.prototype );
  21810. THREE.BoxGeometry.prototype.constructor = THREE.BoxGeometry;
  21811. THREE.CubeGeometry = THREE.BoxGeometry;
  21812. // File:src/extras/geometries/BoxBufferGeometry.js
  21813. /**
  21814. * @author Mugen87 / https://github.com/Mugen87
  21815. */
  21816. THREE.BoxBufferGeometry = function ( width, height, depth, widthSegments, heightSegments, depthSegments ) {
  21817. THREE.BufferGeometry.call( this );
  21818. this.type = 'BoxBufferGeometry';
  21819. this.parameters = {
  21820. width: width,
  21821. height: height,
  21822. depth: depth,
  21823. widthSegments: widthSegments,
  21824. heightSegments: heightSegments,
  21825. depthSegments: depthSegments
  21826. };
  21827. var scope = this;
  21828. // segments
  21829. widthSegments = Math.floor( widthSegments ) || 1;
  21830. heightSegments = Math.floor( heightSegments ) || 1;
  21831. depthSegments = Math.floor( depthSegments ) || 1;
  21832. // these are used to calculate buffer length
  21833. var vertexCount = calculateVertexCount( widthSegments, heightSegments, depthSegments );
  21834. var indexCount = calculateIndexCount( widthSegments, heightSegments, depthSegments );
  21835. // buffers
  21836. var indices = new ( indexCount > 65535 ? Uint32Array : Uint16Array )( indexCount );
  21837. var vertices = new Float32Array( vertexCount * 3 );
  21838. var normals = new Float32Array( vertexCount * 3 );
  21839. var uvs = new Float32Array( vertexCount * 2 );
  21840. // offset variables
  21841. var vertexBufferOffset = 0;
  21842. var uvBufferOffset = 0;
  21843. var indexBufferOffset = 0;
  21844. var numberOfVertices = 0;
  21845. // group variables
  21846. var groupStart = 0;
  21847. // build each side of the box geometry
  21848. buildPlane( 'z', 'y', 'x', - 1, - 1, depth, height, width, depthSegments, heightSegments, 0 ); // px
  21849. buildPlane( 'z', 'y', 'x', 1, - 1, depth, height, - width, depthSegments, heightSegments, 1 ); // nx
  21850. buildPlane( 'x', 'z', 'y', 1, 1, width, depth, height, widthSegments, depthSegments, 2 ); // py
  21851. buildPlane( 'x', 'z', 'y', 1, - 1, width, depth, - height, widthSegments, depthSegments, 3 ); // ny
  21852. buildPlane( 'x', 'y', 'z', 1, - 1, width, height, depth, widthSegments, heightSegments, 4 ); // pz
  21853. buildPlane( 'x', 'y', 'z', - 1, - 1, width, height, - depth, widthSegments, heightSegments, 5 ); // nz
  21854. // build geometry
  21855. this.setIndex( new THREE.BufferAttribute( indices, 1 ) );
  21856. this.addAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) );
  21857. this.addAttribute( 'normal', new THREE.BufferAttribute( normals, 3 ) );
  21858. this.addAttribute( 'uv', new THREE.BufferAttribute( uvs, 2 ) );
  21859. // helper functions
  21860. function calculateVertexCount ( w, h, d ) {
  21861. var vertices = 0;
  21862. // calculate the amount of vertices for each side (plane)
  21863. vertices += (w + 1) * (h + 1) * 2; // xy
  21864. vertices += (w + 1) * (d + 1) * 2; // xz
  21865. vertices += (d + 1) * (h + 1) * 2; // zy
  21866. return vertices;
  21867. }
  21868. function calculateIndexCount ( w, h, d ) {
  21869. var index = 0;
  21870. // calculate the amount of squares for each side
  21871. index += w * h * 2; // xy
  21872. index += w * d * 2; // xz
  21873. index += d * h * 2; // zy
  21874. return index * 6; // two triangles per square => six vertices per square
  21875. }
  21876. function buildPlane ( u, v, w, udir, vdir, width, height, depth, gridX, gridY, materialIndex ) {
  21877. var segmentWidth = width / gridX;
  21878. var segmentHeight = height / gridY;
  21879. var widthHalf = width / 2;
  21880. var heightHalf = height / 2;
  21881. var depthHalf = depth / 2;
  21882. var gridX1 = gridX + 1;
  21883. var gridY1 = gridY + 1;
  21884. var vertexCounter = 0;
  21885. var groupCount = 0;
  21886. var vector = new THREE.Vector3();
  21887. // generate vertices, normals and uvs
  21888. for ( var iy = 0; iy < gridY1; iy ++ ) {
  21889. var y = iy * segmentHeight - heightHalf;
  21890. for ( var ix = 0; ix < gridX1; ix ++ ) {
  21891. var x = ix * segmentWidth - widthHalf;
  21892. // set values to correct vector component
  21893. vector[ u ] = x * udir;
  21894. vector[ v ] = y * vdir;
  21895. vector[ w ] = depthHalf;
  21896. // now apply vector to vertex buffer
  21897. vertices[ vertexBufferOffset ] = vector.x;
  21898. vertices[ vertexBufferOffset + 1 ] = vector.y;
  21899. vertices[ vertexBufferOffset + 2 ] = vector.z;
  21900. // set values to correct vector component
  21901. vector[ u ] = 0;
  21902. vector[ v ] = 0;
  21903. vector[ w ] = depth > 0 ? 1 : - 1;
  21904. // now apply vector to normal buffer
  21905. normals[ vertexBufferOffset ] = vector.x;
  21906. normals[ vertexBufferOffset + 1 ] = vector.y;
  21907. normals[ vertexBufferOffset + 2 ] = vector.z;
  21908. // uvs
  21909. uvs[ uvBufferOffset ] = ix / gridX;
  21910. uvs[ uvBufferOffset + 1 ] = 1 - ( iy / gridY );
  21911. // update offsets and counters
  21912. vertexBufferOffset += 3;
  21913. uvBufferOffset += 2;
  21914. vertexCounter += 1;
  21915. }
  21916. }
  21917. // 1. you need three indices to draw a single face
  21918. // 2. a single segment consists of two faces
  21919. // 3. so we need to generate six (2*3) indices per segment
  21920. for ( iy = 0; iy < gridY; iy ++ ) {
  21921. for ( ix = 0; ix < gridX; ix ++ ) {
  21922. // indices
  21923. var a = numberOfVertices + ix + gridX1 * iy;
  21924. var b = numberOfVertices + ix + gridX1 * ( iy + 1 );
  21925. var c = numberOfVertices + ( ix + 1 ) + gridX1 * ( iy + 1 );
  21926. var d = numberOfVertices + ( ix + 1 ) + gridX1 * iy;
  21927. // face one
  21928. indices[ indexBufferOffset ] = a;
  21929. indices[ indexBufferOffset + 1 ] = b;
  21930. indices[ indexBufferOffset + 2 ] = d;
  21931. // face two
  21932. indices[ indexBufferOffset + 3 ] = b;
  21933. indices[ indexBufferOffset + 4 ] = c;
  21934. indices[ indexBufferOffset + 5 ] = d;
  21935. // update offsets and counters
  21936. indexBufferOffset += 6;
  21937. groupCount += 6;
  21938. }
  21939. }
  21940. // add a group to the geometry. this will ensure multi material support
  21941. scope.addGroup( groupStart, groupCount, materialIndex );
  21942. // calculate new start value for groups
  21943. groupStart += groupCount;
  21944. // update total number of vertices
  21945. numberOfVertices += vertexCounter;
  21946. }
  21947. };
  21948. THREE.BoxBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  21949. THREE.BoxBufferGeometry.prototype.constructor = THREE.BoxBufferGeometry;
  21950. // File:src/extras/geometries/CircleGeometry.js
  21951. /**
  21952. * @author hughes
  21953. */
  21954. THREE.CircleGeometry = function ( radius, segments, thetaStart, thetaLength ) {
  21955. THREE.Geometry.call( this );
  21956. this.type = 'CircleGeometry';
  21957. this.parameters = {
  21958. radius: radius,
  21959. segments: segments,
  21960. thetaStart: thetaStart,
  21961. thetaLength: thetaLength
  21962. };
  21963. this.fromBufferGeometry( new THREE.CircleBufferGeometry( radius, segments, thetaStart, thetaLength ) );
  21964. };
  21965. THREE.CircleGeometry.prototype = Object.create( THREE.Geometry.prototype );
  21966. THREE.CircleGeometry.prototype.constructor = THREE.CircleGeometry;
  21967. // File:src/extras/geometries/CircleBufferGeometry.js
  21968. /**
  21969. * @author benaadams / https://twitter.com/ben_a_adams
  21970. */
  21971. THREE.CircleBufferGeometry = function ( radius, segments, thetaStart, thetaLength ) {
  21972. THREE.BufferGeometry.call( this );
  21973. this.type = 'CircleBufferGeometry';
  21974. this.parameters = {
  21975. radius: radius,
  21976. segments: segments,
  21977. thetaStart: thetaStart,
  21978. thetaLength: thetaLength
  21979. };
  21980. radius = radius || 50;
  21981. segments = segments !== undefined ? Math.max( 3, segments ) : 8;
  21982. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  21983. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  21984. var vertices = segments + 2;
  21985. var positions = new Float32Array( vertices * 3 );
  21986. var normals = new Float32Array( vertices * 3 );
  21987. var uvs = new Float32Array( vertices * 2 );
  21988. // center data is already zero, but need to set a few extras
  21989. normals[ 2 ] = 1.0;
  21990. uvs[ 0 ] = 0.5;
  21991. uvs[ 1 ] = 0.5;
  21992. for ( var s = 0, i = 3, ii = 2 ; s <= segments; s ++, i += 3, ii += 2 ) {
  21993. var segment = thetaStart + s / segments * thetaLength;
  21994. positions[ i ] = radius * Math.cos( segment );
  21995. positions[ i + 1 ] = radius * Math.sin( segment );
  21996. normals[ i + 2 ] = 1; // normal z
  21997. uvs[ ii ] = ( positions[ i ] / radius + 1 ) / 2;
  21998. uvs[ ii + 1 ] = ( positions[ i + 1 ] / radius + 1 ) / 2;
  21999. }
  22000. var indices = [];
  22001. for ( var i = 1; i <= segments; i ++ ) {
  22002. indices.push( i, i + 1, 0 );
  22003. }
  22004. this.setIndex( new THREE.BufferAttribute( new Uint16Array( indices ), 1 ) );
  22005. this.addAttribute( 'position', new THREE.BufferAttribute( positions, 3 ) );
  22006. this.addAttribute( 'normal', new THREE.BufferAttribute( normals, 3 ) );
  22007. this.addAttribute( 'uv', new THREE.BufferAttribute( uvs, 2 ) );
  22008. this.boundingSphere = new THREE.Sphere( new THREE.Vector3(), radius );
  22009. };
  22010. THREE.CircleBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  22011. THREE.CircleBufferGeometry.prototype.constructor = THREE.CircleBufferGeometry;
  22012. // File:src/extras/geometries/CylinderBufferGeometry.js
  22013. /**
  22014. * @author Mugen87 / https://github.com/Mugen87
  22015. */
  22016. THREE.CylinderBufferGeometry = function( radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  22017. THREE.BufferGeometry.call( this );
  22018. this.type = 'CylinderBufferGeometry';
  22019. this.parameters = {
  22020. radiusTop: radiusTop,
  22021. radiusBottom: radiusBottom,
  22022. height: height,
  22023. radialSegments: radialSegments,
  22024. heightSegments: heightSegments,
  22025. openEnded: openEnded,
  22026. thetaStart: thetaStart,
  22027. thetaLength: thetaLength
  22028. };
  22029. var scope = this;
  22030. radiusTop = radiusTop !== undefined ? radiusTop : 20;
  22031. radiusBottom = radiusBottom !== undefined ? radiusBottom : 20;
  22032. height = height !== undefined ? height : 100;
  22033. radialSegments = Math.floor( radialSegments ) || 8;
  22034. heightSegments = Math.floor( heightSegments ) || 1;
  22035. openEnded = openEnded !== undefined ? openEnded : false;
  22036. thetaStart = thetaStart !== undefined ? thetaStart : 0.0;
  22037. thetaLength = thetaLength !== undefined ? thetaLength : 2.0 * Math.PI;
  22038. // used to calculate buffer length
  22039. var nbCap = 0;
  22040. if ( openEnded === false ) {
  22041. if ( radiusTop > 0 ) nbCap ++;
  22042. if ( radiusBottom > 0 ) nbCap ++;
  22043. }
  22044. var vertexCount = calculateVertexCount();
  22045. var indexCount = calculateIndexCount();
  22046. // buffers
  22047. var indices = new THREE.BufferAttribute( new ( indexCount > 65535 ? Uint32Array : Uint16Array )( indexCount ), 1 );
  22048. var vertices = new THREE.BufferAttribute( new Float32Array( vertexCount * 3 ), 3 );
  22049. var normals = new THREE.BufferAttribute( new Float32Array( vertexCount * 3 ), 3 );
  22050. var uvs = new THREE.BufferAttribute( new Float32Array( vertexCount * 2 ), 2 );
  22051. // helper variables
  22052. var index = 0,
  22053. indexOffset = 0,
  22054. indexArray = [],
  22055. halfHeight = height / 2;
  22056. // group variables
  22057. var groupStart = 0;
  22058. // generate geometry
  22059. generateTorso();
  22060. if ( openEnded === false ) {
  22061. if ( radiusTop > 0 ) generateCap( true );
  22062. if ( radiusBottom > 0 ) generateCap( false );
  22063. }
  22064. // build geometry
  22065. this.setIndex( indices );
  22066. this.addAttribute( 'position', vertices );
  22067. this.addAttribute( 'normal', normals );
  22068. this.addAttribute( 'uv', uvs );
  22069. // helper functions
  22070. function calculateVertexCount() {
  22071. var count = ( radialSegments + 1 ) * ( heightSegments + 1 );
  22072. if ( openEnded === false ) {
  22073. count += ( ( radialSegments + 1 ) * nbCap ) + ( radialSegments * nbCap );
  22074. }
  22075. return count;
  22076. }
  22077. function calculateIndexCount() {
  22078. var count = radialSegments * heightSegments * 2 * 3;
  22079. if ( openEnded === false ) {
  22080. count += radialSegments * nbCap * 3;
  22081. }
  22082. return count;
  22083. }
  22084. function generateTorso() {
  22085. var x, y;
  22086. var normal = new THREE.Vector3();
  22087. var vertex = new THREE.Vector3();
  22088. var groupCount = 0;
  22089. // this will be used to calculate the normal
  22090. var tanTheta = ( radiusBottom - radiusTop ) / height;
  22091. // generate vertices, normals and uvs
  22092. for ( y = 0; y <= heightSegments; y ++ ) {
  22093. var indexRow = [];
  22094. var v = y / heightSegments;
  22095. // calculate the radius of the current row
  22096. var radius = v * ( radiusBottom - radiusTop ) + radiusTop;
  22097. for ( x = 0; x <= radialSegments; x ++ ) {
  22098. var u = x / radialSegments;
  22099. // vertex
  22100. vertex.x = radius * Math.sin( u * thetaLength + thetaStart );
  22101. vertex.y = - v * height + halfHeight;
  22102. vertex.z = radius * Math.cos( u * thetaLength + thetaStart );
  22103. vertices.setXYZ( index, vertex.x, vertex.y, vertex.z );
  22104. // normal
  22105. normal.copy( vertex );
  22106. // handle special case if radiusTop/radiusBottom is zero
  22107. if ( ( radiusTop === 0 && y === 0 ) || ( radiusBottom === 0 && y === heightSegments ) ) {
  22108. normal.x = Math.sin( u * thetaLength + thetaStart );
  22109. normal.z = Math.cos( u * thetaLength + thetaStart );
  22110. }
  22111. normal.setY( Math.sqrt( normal.x * normal.x + normal.z * normal.z ) * tanTheta ).normalize();
  22112. normals.setXYZ( index, normal.x, normal.y, normal.z );
  22113. // uv
  22114. uvs.setXY( index, u, 1 - v );
  22115. // save index of vertex in respective row
  22116. indexRow.push( index );
  22117. // increase index
  22118. index ++;
  22119. }
  22120. // now save vertices of the row in our index array
  22121. indexArray.push( indexRow );
  22122. }
  22123. // generate indices
  22124. for ( x = 0; x < radialSegments; x ++ ) {
  22125. for ( y = 0; y < heightSegments; y ++ ) {
  22126. // we use the index array to access the correct indices
  22127. var i1 = indexArray[ y ][ x ];
  22128. var i2 = indexArray[ y + 1 ][ x ];
  22129. var i3 = indexArray[ y + 1 ][ x + 1 ];
  22130. var i4 = indexArray[ y ][ x + 1 ];
  22131. // face one
  22132. indices.setX( indexOffset, i1 ); indexOffset ++;
  22133. indices.setX( indexOffset, i2 ); indexOffset ++;
  22134. indices.setX( indexOffset, i4 ); indexOffset ++;
  22135. // face two
  22136. indices.setX( indexOffset, i2 ); indexOffset ++;
  22137. indices.setX( indexOffset, i3 ); indexOffset ++;
  22138. indices.setX( indexOffset, i4 ); indexOffset ++;
  22139. // update counters
  22140. groupCount += 6;
  22141. }
  22142. }
  22143. // add a group to the geometry. this will ensure multi material support
  22144. scope.addGroup( groupStart, groupCount, 0 );
  22145. // calculate new start value for groups
  22146. groupStart += groupCount;
  22147. }
  22148. function generateCap( top ) {
  22149. var x, centerIndexStart, centerIndexEnd;
  22150. var uv = new THREE.Vector2();
  22151. var vertex = new THREE.Vector3();
  22152. var groupCount = 0;
  22153. var radius = ( top === true ) ? radiusTop : radiusBottom;
  22154. var sign = ( top === true ) ? 1 : - 1;
  22155. // save the index of the first center vertex
  22156. centerIndexStart = index;
  22157. // first we generate the center vertex data of the cap.
  22158. // because the geometry needs one set of uvs per face,
  22159. // we must generate a center vertex per face/segment
  22160. for ( x = 1; x <= radialSegments; x ++ ) {
  22161. // vertex
  22162. vertices.setXYZ( index, 0, halfHeight * sign, 0 );
  22163. // normal
  22164. normals.setXYZ( index, 0, sign, 0 );
  22165. // uv
  22166. uv.x = 0.5;
  22167. uv.y = 0.5;
  22168. uvs.setXY( index, uv.x, uv.y );
  22169. // increase index
  22170. index ++;
  22171. }
  22172. // save the index of the last center vertex
  22173. centerIndexEnd = index;
  22174. // now we generate the surrounding vertices, normals and uvs
  22175. for ( x = 0; x <= radialSegments; x ++ ) {
  22176. var u = x / radialSegments;
  22177. var theta = u * thetaLength + thetaStart;
  22178. var cosTheta = Math.cos( theta );
  22179. var sinTheta = Math.sin( theta );
  22180. // vertex
  22181. vertex.x = radius * sinTheta;
  22182. vertex.y = halfHeight * sign;
  22183. vertex.z = radius * cosTheta;
  22184. vertices.setXYZ( index, vertex.x, vertex.y, vertex.z );
  22185. // normal
  22186. normals.setXYZ( index, 0, sign, 0 );
  22187. // uv
  22188. uv.x = ( cosTheta * 0.5 ) + 0.5;
  22189. uv.y = ( sinTheta * 0.5 * sign ) + 0.5;
  22190. uvs.setXY( index, uv.x, uv.y );
  22191. // increase index
  22192. index ++;
  22193. }
  22194. // generate indices
  22195. for ( x = 0; x < radialSegments; x ++ ) {
  22196. var c = centerIndexStart + x;
  22197. var i = centerIndexEnd + x;
  22198. if ( top === true ) {
  22199. // face top
  22200. indices.setX( indexOffset, i ); indexOffset ++;
  22201. indices.setX( indexOffset, i + 1 ); indexOffset ++;
  22202. indices.setX( indexOffset, c ); indexOffset ++;
  22203. } else {
  22204. // face bottom
  22205. indices.setX( indexOffset, i + 1 ); indexOffset ++;
  22206. indices.setX( indexOffset, i ); indexOffset ++;
  22207. indices.setX( indexOffset, c ); indexOffset ++;
  22208. }
  22209. // update counters
  22210. groupCount += 3;
  22211. }
  22212. // add a group to the geometry. this will ensure multi material support
  22213. scope.addGroup( groupStart, groupCount, top === true ? 1 : 2 );
  22214. // calculate new start value for groups
  22215. groupStart += groupCount;
  22216. }
  22217. };
  22218. THREE.CylinderBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  22219. THREE.CylinderBufferGeometry.prototype.constructor = THREE.CylinderBufferGeometry;
  22220. // File:src/extras/geometries/CylinderGeometry.js
  22221. /**
  22222. * @author mrdoob / http://mrdoob.com/
  22223. */
  22224. THREE.CylinderGeometry = function ( radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  22225. THREE.Geometry.call( this );
  22226. this.type = 'CylinderGeometry';
  22227. this.parameters = {
  22228. radiusTop: radiusTop,
  22229. radiusBottom: radiusBottom,
  22230. height: height,
  22231. radialSegments: radialSegments,
  22232. heightSegments: heightSegments,
  22233. openEnded: openEnded,
  22234. thetaStart: thetaStart,
  22235. thetaLength: thetaLength
  22236. };
  22237. this.fromBufferGeometry( new THREE.CylinderBufferGeometry( radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) );
  22238. this.mergeVertices();
  22239. };
  22240. THREE.CylinderGeometry.prototype = Object.create( THREE.Geometry.prototype );
  22241. THREE.CylinderGeometry.prototype.constructor = THREE.CylinderGeometry;
  22242. // File:src/extras/geometries/ConeBufferGeometry.js
  22243. /*
  22244. * @author: abelnation / http://github.com/abelnation
  22245. */
  22246. THREE.ConeBufferGeometry = function (
  22247. radius, height,
  22248. radialSegments, heightSegments,
  22249. openEnded, thetaStart, thetaLength ) {
  22250. THREE.CylinderBufferGeometry.call( this,
  22251. 0, radius, height,
  22252. radialSegments, heightSegments,
  22253. openEnded, thetaStart, thetaLength );
  22254. this.type = 'ConeBufferGeometry';
  22255. this.parameters = {
  22256. radius: radius,
  22257. height: height,
  22258. radialSegments: radialSegments,
  22259. heightSegments: heightSegments,
  22260. thetaStart: thetaStart,
  22261. thetaLength: thetaLength
  22262. };
  22263. };
  22264. THREE.ConeBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  22265. THREE.ConeBufferGeometry.prototype.constructor = THREE.ConeBufferGeometry;
  22266. // File:src/extras/geometries/ConeGeometry.js
  22267. /**
  22268. * @author abelnation / http://github.com/abelnation
  22269. */
  22270. THREE.ConeGeometry = function (
  22271. radius, height,
  22272. radialSegments, heightSegments,
  22273. openEnded, thetaStart, thetaLength ) {
  22274. THREE.CylinderGeometry.call( this,
  22275. 0, radius, height,
  22276. radialSegments, heightSegments,
  22277. openEnded, thetaStart, thetaLength );
  22278. this.type = 'ConeGeometry';
  22279. this.parameters = {
  22280. radius: radius,
  22281. height: height,
  22282. radialSegments: radialSegments,
  22283. heightSegments: heightSegments,
  22284. openEnded: openEnded,
  22285. thetaStart: thetaStart,
  22286. thetaLength: thetaLength
  22287. };
  22288. };
  22289. THREE.ConeGeometry.prototype = Object.create( THREE.CylinderGeometry.prototype );
  22290. THREE.ConeGeometry.prototype.constructor = THREE.ConeGeometry;
  22291. // File:src/extras/geometries/EdgesGeometry.js
  22292. /**
  22293. * @author WestLangley / http://github.com/WestLangley
  22294. */
  22295. THREE.EdgesGeometry = function ( geometry, thresholdAngle ) {
  22296. THREE.BufferGeometry.call( this );
  22297. thresholdAngle = ( thresholdAngle !== undefined ) ? thresholdAngle : 1;
  22298. var thresholdDot = Math.cos( THREE.Math.DEG2RAD * thresholdAngle );
  22299. var edge = [ 0, 0 ], hash = {};
  22300. function sortFunction( a, b ) {
  22301. return a - b;
  22302. }
  22303. var keys = [ 'a', 'b', 'c' ];
  22304. var geometry2;
  22305. if ( geometry instanceof THREE.BufferGeometry ) {
  22306. geometry2 = new THREE.Geometry();
  22307. geometry2.fromBufferGeometry( geometry );
  22308. } else {
  22309. geometry2 = geometry.clone();
  22310. }
  22311. geometry2.mergeVertices();
  22312. geometry2.computeFaceNormals();
  22313. var vertices = geometry2.vertices;
  22314. var faces = geometry2.faces;
  22315. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  22316. var face = faces[ i ];
  22317. for ( var j = 0; j < 3; j ++ ) {
  22318. edge[ 0 ] = face[ keys[ j ] ];
  22319. edge[ 1 ] = face[ keys[ ( j + 1 ) % 3 ] ];
  22320. edge.sort( sortFunction );
  22321. var key = edge.toString();
  22322. if ( hash[ key ] === undefined ) {
  22323. hash[ key ] = { vert1: edge[ 0 ], vert2: edge[ 1 ], face1: i, face2: undefined };
  22324. } else {
  22325. hash[ key ].face2 = i;
  22326. }
  22327. }
  22328. }
  22329. var coords = [];
  22330. for ( var key in hash ) {
  22331. var h = hash[ key ];
  22332. if ( h.face2 === undefined || faces[ h.face1 ].normal.dot( faces[ h.face2 ].normal ) <= thresholdDot ) {
  22333. var vertex = vertices[ h.vert1 ];
  22334. coords.push( vertex.x );
  22335. coords.push( vertex.y );
  22336. coords.push( vertex.z );
  22337. vertex = vertices[ h.vert2 ];
  22338. coords.push( vertex.x );
  22339. coords.push( vertex.y );
  22340. coords.push( vertex.z );
  22341. }
  22342. }
  22343. this.addAttribute( 'position', new THREE.BufferAttribute( new Float32Array( coords ), 3 ) );
  22344. };
  22345. THREE.EdgesGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  22346. THREE.EdgesGeometry.prototype.constructor = THREE.EdgesGeometry;
  22347. // File:src/extras/geometries/ExtrudeGeometry.js
  22348. /**
  22349. * @author zz85 / http://www.lab4games.net/zz85/blog
  22350. *
  22351. * Creates extruded geometry from a path shape.
  22352. *
  22353. * parameters = {
  22354. *
  22355. * curveSegments: <int>, // number of points on the curves
  22356. * steps: <int>, // number of points for z-side extrusions / used for subdividing segments of extrude spline too
  22357. * amount: <int>, // Depth to extrude the shape
  22358. *
  22359. * bevelEnabled: <bool>, // turn on bevel
  22360. * bevelThickness: <float>, // how deep into the original shape bevel goes
  22361. * bevelSize: <float>, // how far from shape outline is bevel
  22362. * bevelSegments: <int>, // number of bevel layers
  22363. *
  22364. * extrudePath: <THREE.CurvePath> // 3d spline path to extrude shape along. (creates Frames if .frames aren't defined)
  22365. * frames: <THREE.TubeGeometry.FrenetFrames> // containing arrays of tangents, normals, binormals
  22366. *
  22367. * uvGenerator: <Object> // object that provides UV generator functions
  22368. *
  22369. * }
  22370. **/
  22371. THREE.ExtrudeGeometry = function ( shapes, options ) {
  22372. if ( typeof( shapes ) === "undefined" ) {
  22373. shapes = [];
  22374. return;
  22375. }
  22376. THREE.Geometry.call( this );
  22377. this.type = 'ExtrudeGeometry';
  22378. shapes = Array.isArray( shapes ) ? shapes : [ shapes ];
  22379. this.addShapeList( shapes, options );
  22380. this.computeFaceNormals();
  22381. // can't really use automatic vertex normals
  22382. // as then front and back sides get smoothed too
  22383. // should do separate smoothing just for sides
  22384. //this.computeVertexNormals();
  22385. //console.log( "took", ( Date.now() - startTime ) );
  22386. };
  22387. THREE.ExtrudeGeometry.prototype = Object.create( THREE.Geometry.prototype );
  22388. THREE.ExtrudeGeometry.prototype.constructor = THREE.ExtrudeGeometry;
  22389. THREE.ExtrudeGeometry.prototype.addShapeList = function ( shapes, options ) {
  22390. var sl = shapes.length;
  22391. for ( var s = 0; s < sl; s ++ ) {
  22392. var shape = shapes[ s ];
  22393. this.addShape( shape, options );
  22394. }
  22395. };
  22396. THREE.ExtrudeGeometry.prototype.addShape = function ( shape, options ) {
  22397. var amount = options.amount !== undefined ? options.amount : 100;
  22398. var bevelThickness = options.bevelThickness !== undefined ? options.bevelThickness : 6; // 10
  22399. var bevelSize = options.bevelSize !== undefined ? options.bevelSize : bevelThickness - 2; // 8
  22400. var bevelSegments = options.bevelSegments !== undefined ? options.bevelSegments : 3;
  22401. var bevelEnabled = options.bevelEnabled !== undefined ? options.bevelEnabled : true; // false
  22402. var curveSegments = options.curveSegments !== undefined ? options.curveSegments : 12;
  22403. var steps = options.steps !== undefined ? options.steps : 1;
  22404. var extrudePath = options.extrudePath;
  22405. var extrudePts, extrudeByPath = false;
  22406. // Use default WorldUVGenerator if no UV generators are specified.
  22407. var uvgen = options.UVGenerator !== undefined ? options.UVGenerator : THREE.ExtrudeGeometry.WorldUVGenerator;
  22408. var splineTube, binormal, normal, position2;
  22409. if ( extrudePath ) {
  22410. extrudePts = extrudePath.getSpacedPoints( steps );
  22411. extrudeByPath = true;
  22412. bevelEnabled = false; // bevels not supported for path extrusion
  22413. // SETUP TNB variables
  22414. // Reuse TNB from TubeGeomtry for now.
  22415. // TODO1 - have a .isClosed in spline?
  22416. splineTube = options.frames !== undefined ? options.frames : new THREE.TubeGeometry.FrenetFrames( extrudePath, steps, false );
  22417. // console.log(splineTube, 'splineTube', splineTube.normals.length, 'steps', steps, 'extrudePts', extrudePts.length);
  22418. binormal = new THREE.Vector3();
  22419. normal = new THREE.Vector3();
  22420. position2 = new THREE.Vector3();
  22421. }
  22422. // Safeguards if bevels are not enabled
  22423. if ( ! bevelEnabled ) {
  22424. bevelSegments = 0;
  22425. bevelThickness = 0;
  22426. bevelSize = 0;
  22427. }
  22428. // Variables initialization
  22429. var ahole, h, hl; // looping of holes
  22430. var scope = this;
  22431. var shapesOffset = this.vertices.length;
  22432. var shapePoints = shape.extractPoints( curveSegments );
  22433. var vertices = shapePoints.shape;
  22434. var holes = shapePoints.holes;
  22435. var reverse = ! THREE.ShapeUtils.isClockWise( vertices );
  22436. if ( reverse ) {
  22437. vertices = vertices.reverse();
  22438. // Maybe we should also check if holes are in the opposite direction, just to be safe ...
  22439. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  22440. ahole = holes[ h ];
  22441. if ( THREE.ShapeUtils.isClockWise( ahole ) ) {
  22442. holes[ h ] = ahole.reverse();
  22443. }
  22444. }
  22445. reverse = false; // If vertices are in order now, we shouldn't need to worry about them again (hopefully)!
  22446. }
  22447. var faces = THREE.ShapeUtils.triangulateShape( vertices, holes );
  22448. /* Vertices */
  22449. var contour = vertices; // vertices has all points but contour has only points of circumference
  22450. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  22451. ahole = holes[ h ];
  22452. vertices = vertices.concat( ahole );
  22453. }
  22454. function scalePt2 ( pt, vec, size ) {
  22455. if ( ! vec ) console.error( "THREE.ExtrudeGeometry: vec does not exist" );
  22456. return vec.clone().multiplyScalar( size ).add( pt );
  22457. }
  22458. var b, bs, t, z,
  22459. vert, vlen = vertices.length,
  22460. face, flen = faces.length;
  22461. // Find directions for point movement
  22462. function getBevelVec( inPt, inPrev, inNext ) {
  22463. // computes for inPt the corresponding point inPt' on a new contour
  22464. // shifted by 1 unit (length of normalized vector) to the left
  22465. // if we walk along contour clockwise, this new contour is outside the old one
  22466. //
  22467. // inPt' is the intersection of the two lines parallel to the two
  22468. // adjacent edges of inPt at a distance of 1 unit on the left side.
  22469. var v_trans_x, v_trans_y, shrink_by = 1; // resulting translation vector for inPt
  22470. // good reading for geometry algorithms (here: line-line intersection)
  22471. // http://geomalgorithms.com/a05-_intersect-1.html
  22472. var v_prev_x = inPt.x - inPrev.x, v_prev_y = inPt.y - inPrev.y;
  22473. var v_next_x = inNext.x - inPt.x, v_next_y = inNext.y - inPt.y;
  22474. var v_prev_lensq = ( v_prev_x * v_prev_x + v_prev_y * v_prev_y );
  22475. // check for collinear edges
  22476. var collinear0 = ( v_prev_x * v_next_y - v_prev_y * v_next_x );
  22477. if ( Math.abs( collinear0 ) > Number.EPSILON ) {
  22478. // not collinear
  22479. // length of vectors for normalizing
  22480. var v_prev_len = Math.sqrt( v_prev_lensq );
  22481. var v_next_len = Math.sqrt( v_next_x * v_next_x + v_next_y * v_next_y );
  22482. // shift adjacent points by unit vectors to the left
  22483. var ptPrevShift_x = ( inPrev.x - v_prev_y / v_prev_len );
  22484. var ptPrevShift_y = ( inPrev.y + v_prev_x / v_prev_len );
  22485. var ptNextShift_x = ( inNext.x - v_next_y / v_next_len );
  22486. var ptNextShift_y = ( inNext.y + v_next_x / v_next_len );
  22487. // scaling factor for v_prev to intersection point
  22488. var sf = ( ( ptNextShift_x - ptPrevShift_x ) * v_next_y -
  22489. ( ptNextShift_y - ptPrevShift_y ) * v_next_x ) /
  22490. ( v_prev_x * v_next_y - v_prev_y * v_next_x );
  22491. // vector from inPt to intersection point
  22492. v_trans_x = ( ptPrevShift_x + v_prev_x * sf - inPt.x );
  22493. v_trans_y = ( ptPrevShift_y + v_prev_y * sf - inPt.y );
  22494. // Don't normalize!, otherwise sharp corners become ugly
  22495. // but prevent crazy spikes
  22496. var v_trans_lensq = ( v_trans_x * v_trans_x + v_trans_y * v_trans_y );
  22497. if ( v_trans_lensq <= 2 ) {
  22498. return new THREE.Vector2( v_trans_x, v_trans_y );
  22499. } else {
  22500. shrink_by = Math.sqrt( v_trans_lensq / 2 );
  22501. }
  22502. } else {
  22503. // handle special case of collinear edges
  22504. var direction_eq = false; // assumes: opposite
  22505. if ( v_prev_x > Number.EPSILON ) {
  22506. if ( v_next_x > Number.EPSILON ) {
  22507. direction_eq = true;
  22508. }
  22509. } else {
  22510. if ( v_prev_x < - Number.EPSILON ) {
  22511. if ( v_next_x < - Number.EPSILON ) {
  22512. direction_eq = true;
  22513. }
  22514. } else {
  22515. if ( Math.sign( v_prev_y ) === Math.sign( v_next_y ) ) {
  22516. direction_eq = true;
  22517. }
  22518. }
  22519. }
  22520. if ( direction_eq ) {
  22521. // console.log("Warning: lines are a straight sequence");
  22522. v_trans_x = - v_prev_y;
  22523. v_trans_y = v_prev_x;
  22524. shrink_by = Math.sqrt( v_prev_lensq );
  22525. } else {
  22526. // console.log("Warning: lines are a straight spike");
  22527. v_trans_x = v_prev_x;
  22528. v_trans_y = v_prev_y;
  22529. shrink_by = Math.sqrt( v_prev_lensq / 2 );
  22530. }
  22531. }
  22532. return new THREE.Vector2( v_trans_x / shrink_by, v_trans_y / shrink_by );
  22533. }
  22534. var contourMovements = [];
  22535. for ( var i = 0, il = contour.length, j = il - 1, k = i + 1; i < il; i ++, j ++, k ++ ) {
  22536. if ( j === il ) j = 0;
  22537. if ( k === il ) k = 0;
  22538. // (j)---(i)---(k)
  22539. // console.log('i,j,k', i, j , k)
  22540. contourMovements[ i ] = getBevelVec( contour[ i ], contour[ j ], contour[ k ] );
  22541. }
  22542. var holesMovements = [], oneHoleMovements, verticesMovements = contourMovements.concat();
  22543. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  22544. ahole = holes[ h ];
  22545. oneHoleMovements = [];
  22546. for ( i = 0, il = ahole.length, j = il - 1, k = i + 1; i < il; i ++, j ++, k ++ ) {
  22547. if ( j === il ) j = 0;
  22548. if ( k === il ) k = 0;
  22549. // (j)---(i)---(k)
  22550. oneHoleMovements[ i ] = getBevelVec( ahole[ i ], ahole[ j ], ahole[ k ] );
  22551. }
  22552. holesMovements.push( oneHoleMovements );
  22553. verticesMovements = verticesMovements.concat( oneHoleMovements );
  22554. }
  22555. // Loop bevelSegments, 1 for the front, 1 for the back
  22556. for ( b = 0; b < bevelSegments; b ++ ) {
  22557. //for ( b = bevelSegments; b > 0; b -- ) {
  22558. t = b / bevelSegments;
  22559. z = bevelThickness * ( 1 - t );
  22560. //z = bevelThickness * t;
  22561. bs = bevelSize * ( Math.sin ( t * Math.PI / 2 ) ); // curved
  22562. //bs = bevelSize * t; // linear
  22563. // contract shape
  22564. for ( i = 0, il = contour.length; i < il; i ++ ) {
  22565. vert = scalePt2( contour[ i ], contourMovements[ i ], bs );
  22566. v( vert.x, vert.y, - z );
  22567. }
  22568. // expand holes
  22569. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  22570. ahole = holes[ h ];
  22571. oneHoleMovements = holesMovements[ h ];
  22572. for ( i = 0, il = ahole.length; i < il; i ++ ) {
  22573. vert = scalePt2( ahole[ i ], oneHoleMovements[ i ], bs );
  22574. v( vert.x, vert.y, - z );
  22575. }
  22576. }
  22577. }
  22578. bs = bevelSize;
  22579. // Back facing vertices
  22580. for ( i = 0; i < vlen; i ++ ) {
  22581. vert = bevelEnabled ? scalePt2( vertices[ i ], verticesMovements[ i ], bs ) : vertices[ i ];
  22582. if ( ! extrudeByPath ) {
  22583. v( vert.x, vert.y, 0 );
  22584. } else {
  22585. // v( vert.x, vert.y + extrudePts[ 0 ].y, extrudePts[ 0 ].x );
  22586. normal.copy( splineTube.normals[ 0 ] ).multiplyScalar( vert.x );
  22587. binormal.copy( splineTube.binormals[ 0 ] ).multiplyScalar( vert.y );
  22588. position2.copy( extrudePts[ 0 ] ).add( normal ).add( binormal );
  22589. v( position2.x, position2.y, position2.z );
  22590. }
  22591. }
  22592. // Add stepped vertices...
  22593. // Including front facing vertices
  22594. var s;
  22595. for ( s = 1; s <= steps; s ++ ) {
  22596. for ( i = 0; i < vlen; i ++ ) {
  22597. vert = bevelEnabled ? scalePt2( vertices[ i ], verticesMovements[ i ], bs ) : vertices[ i ];
  22598. if ( ! extrudeByPath ) {
  22599. v( vert.x, vert.y, amount / steps * s );
  22600. } else {
  22601. // v( vert.x, vert.y + extrudePts[ s - 1 ].y, extrudePts[ s - 1 ].x );
  22602. normal.copy( splineTube.normals[ s ] ).multiplyScalar( vert.x );
  22603. binormal.copy( splineTube.binormals[ s ] ).multiplyScalar( vert.y );
  22604. position2.copy( extrudePts[ s ] ).add( normal ).add( binormal );
  22605. v( position2.x, position2.y, position2.z );
  22606. }
  22607. }
  22608. }
  22609. // Add bevel segments planes
  22610. //for ( b = 1; b <= bevelSegments; b ++ ) {
  22611. for ( b = bevelSegments - 1; b >= 0; b -- ) {
  22612. t = b / bevelSegments;
  22613. z = bevelThickness * ( 1 - t );
  22614. //bs = bevelSize * ( 1-Math.sin ( ( 1 - t ) * Math.PI/2 ) );
  22615. bs = bevelSize * Math.sin ( t * Math.PI / 2 );
  22616. // contract shape
  22617. for ( i = 0, il = contour.length; i < il; i ++ ) {
  22618. vert = scalePt2( contour[ i ], contourMovements[ i ], bs );
  22619. v( vert.x, vert.y, amount + z );
  22620. }
  22621. // expand holes
  22622. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  22623. ahole = holes[ h ];
  22624. oneHoleMovements = holesMovements[ h ];
  22625. for ( i = 0, il = ahole.length; i < il; i ++ ) {
  22626. vert = scalePt2( ahole[ i ], oneHoleMovements[ i ], bs );
  22627. if ( ! extrudeByPath ) {
  22628. v( vert.x, vert.y, amount + z );
  22629. } else {
  22630. v( vert.x, vert.y + extrudePts[ steps - 1 ].y, extrudePts[ steps - 1 ].x + z );
  22631. }
  22632. }
  22633. }
  22634. }
  22635. /* Faces */
  22636. // Top and bottom faces
  22637. buildLidFaces();
  22638. // Sides faces
  22639. buildSideFaces();
  22640. ///// Internal functions
  22641. function buildLidFaces() {
  22642. if ( bevelEnabled ) {
  22643. var layer = 0; // steps + 1
  22644. var offset = vlen * layer;
  22645. // Bottom faces
  22646. for ( i = 0; i < flen; i ++ ) {
  22647. face = faces[ i ];
  22648. f3( face[ 2 ] + offset, face[ 1 ] + offset, face[ 0 ] + offset );
  22649. }
  22650. layer = steps + bevelSegments * 2;
  22651. offset = vlen * layer;
  22652. // Top faces
  22653. for ( i = 0; i < flen; i ++ ) {
  22654. face = faces[ i ];
  22655. f3( face[ 0 ] + offset, face[ 1 ] + offset, face[ 2 ] + offset );
  22656. }
  22657. } else {
  22658. // Bottom faces
  22659. for ( i = 0; i < flen; i ++ ) {
  22660. face = faces[ i ];
  22661. f3( face[ 2 ], face[ 1 ], face[ 0 ] );
  22662. }
  22663. // Top faces
  22664. for ( i = 0; i < flen; i ++ ) {
  22665. face = faces[ i ];
  22666. f3( face[ 0 ] + vlen * steps, face[ 1 ] + vlen * steps, face[ 2 ] + vlen * steps );
  22667. }
  22668. }
  22669. }
  22670. // Create faces for the z-sides of the shape
  22671. function buildSideFaces() {
  22672. var layeroffset = 0;
  22673. sidewalls( contour, layeroffset );
  22674. layeroffset += contour.length;
  22675. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  22676. ahole = holes[ h ];
  22677. sidewalls( ahole, layeroffset );
  22678. //, true
  22679. layeroffset += ahole.length;
  22680. }
  22681. }
  22682. function sidewalls( contour, layeroffset ) {
  22683. var j, k;
  22684. i = contour.length;
  22685. while ( -- i >= 0 ) {
  22686. j = i;
  22687. k = i - 1;
  22688. if ( k < 0 ) k = contour.length - 1;
  22689. //console.log('b', i,j, i-1, k,vertices.length);
  22690. var s = 0, sl = steps + bevelSegments * 2;
  22691. for ( s = 0; s < sl; s ++ ) {
  22692. var slen1 = vlen * s;
  22693. var slen2 = vlen * ( s + 1 );
  22694. var a = layeroffset + j + slen1,
  22695. b = layeroffset + k + slen1,
  22696. c = layeroffset + k + slen2,
  22697. d = layeroffset + j + slen2;
  22698. f4( a, b, c, d, contour, s, sl, j, k );
  22699. }
  22700. }
  22701. }
  22702. function v( x, y, z ) {
  22703. scope.vertices.push( new THREE.Vector3( x, y, z ) );
  22704. }
  22705. function f3( a, b, c ) {
  22706. a += shapesOffset;
  22707. b += shapesOffset;
  22708. c += shapesOffset;
  22709. scope.faces.push( new THREE.Face3( a, b, c, null, null, 0 ) );
  22710. var uvs = uvgen.generateTopUV( scope, a, b, c );
  22711. scope.faceVertexUvs[ 0 ].push( uvs );
  22712. }
  22713. function f4( a, b, c, d, wallContour, stepIndex, stepsLength, contourIndex1, contourIndex2 ) {
  22714. a += shapesOffset;
  22715. b += shapesOffset;
  22716. c += shapesOffset;
  22717. d += shapesOffset;
  22718. scope.faces.push( new THREE.Face3( a, b, d, null, null, 1 ) );
  22719. scope.faces.push( new THREE.Face3( b, c, d, null, null, 1 ) );
  22720. var uvs = uvgen.generateSideWallUV( scope, a, b, c, d );
  22721. scope.faceVertexUvs[ 0 ].push( [ uvs[ 0 ], uvs[ 1 ], uvs[ 3 ] ] );
  22722. scope.faceVertexUvs[ 0 ].push( [ uvs[ 1 ], uvs[ 2 ], uvs[ 3 ] ] );
  22723. }
  22724. };
  22725. THREE.ExtrudeGeometry.WorldUVGenerator = {
  22726. generateTopUV: function ( geometry, indexA, indexB, indexC ) {
  22727. var vertices = geometry.vertices;
  22728. var a = vertices[ indexA ];
  22729. var b = vertices[ indexB ];
  22730. var c = vertices[ indexC ];
  22731. return [
  22732. new THREE.Vector2( a.x, a.y ),
  22733. new THREE.Vector2( b.x, b.y ),
  22734. new THREE.Vector2( c.x, c.y )
  22735. ];
  22736. },
  22737. generateSideWallUV: function ( geometry, indexA, indexB, indexC, indexD ) {
  22738. var vertices = geometry.vertices;
  22739. var a = vertices[ indexA ];
  22740. var b = vertices[ indexB ];
  22741. var c = vertices[ indexC ];
  22742. var d = vertices[ indexD ];
  22743. if ( Math.abs( a.y - b.y ) < 0.01 ) {
  22744. return [
  22745. new THREE.Vector2( a.x, 1 - a.z ),
  22746. new THREE.Vector2( b.x, 1 - b.z ),
  22747. new THREE.Vector2( c.x, 1 - c.z ),
  22748. new THREE.Vector2( d.x, 1 - d.z )
  22749. ];
  22750. } else {
  22751. return [
  22752. new THREE.Vector2( a.y, 1 - a.z ),
  22753. new THREE.Vector2( b.y, 1 - b.z ),
  22754. new THREE.Vector2( c.y, 1 - c.z ),
  22755. new THREE.Vector2( d.y, 1 - d.z )
  22756. ];
  22757. }
  22758. }
  22759. };
  22760. // File:src/extras/geometries/ShapeGeometry.js
  22761. /**
  22762. * @author jonobr1 / http://jonobr1.com
  22763. *
  22764. * Creates a one-sided polygonal geometry from a path shape. Similar to
  22765. * ExtrudeGeometry.
  22766. *
  22767. * parameters = {
  22768. *
  22769. * curveSegments: <int>, // number of points on the curves. NOT USED AT THE MOMENT.
  22770. *
  22771. * material: <int> // material index for front and back faces
  22772. * uvGenerator: <Object> // object that provides UV generator functions
  22773. *
  22774. * }
  22775. **/
  22776. THREE.ShapeGeometry = function ( shapes, options ) {
  22777. THREE.Geometry.call( this );
  22778. this.type = 'ShapeGeometry';
  22779. if ( Array.isArray( shapes ) === false ) shapes = [ shapes ];
  22780. this.addShapeList( shapes, options );
  22781. this.computeFaceNormals();
  22782. };
  22783. THREE.ShapeGeometry.prototype = Object.create( THREE.Geometry.prototype );
  22784. THREE.ShapeGeometry.prototype.constructor = THREE.ShapeGeometry;
  22785. /**
  22786. * Add an array of shapes to THREE.ShapeGeometry.
  22787. */
  22788. THREE.ShapeGeometry.prototype.addShapeList = function ( shapes, options ) {
  22789. for ( var i = 0, l = shapes.length; i < l; i ++ ) {
  22790. this.addShape( shapes[ i ], options );
  22791. }
  22792. return this;
  22793. };
  22794. /**
  22795. * Adds a shape to THREE.ShapeGeometry, based on THREE.ExtrudeGeometry.
  22796. */
  22797. THREE.ShapeGeometry.prototype.addShape = function ( shape, options ) {
  22798. if ( options === undefined ) options = {};
  22799. var curveSegments = options.curveSegments !== undefined ? options.curveSegments : 12;
  22800. var material = options.material;
  22801. var uvgen = options.UVGenerator === undefined ? THREE.ExtrudeGeometry.WorldUVGenerator : options.UVGenerator;
  22802. //
  22803. var i, l, hole;
  22804. var shapesOffset = this.vertices.length;
  22805. var shapePoints = shape.extractPoints( curveSegments );
  22806. var vertices = shapePoints.shape;
  22807. var holes = shapePoints.holes;
  22808. var reverse = ! THREE.ShapeUtils.isClockWise( vertices );
  22809. if ( reverse ) {
  22810. vertices = vertices.reverse();
  22811. // Maybe we should also check if holes are in the opposite direction, just to be safe...
  22812. for ( i = 0, l = holes.length; i < l; i ++ ) {
  22813. hole = holes[ i ];
  22814. if ( THREE.ShapeUtils.isClockWise( hole ) ) {
  22815. holes[ i ] = hole.reverse();
  22816. }
  22817. }
  22818. reverse = false;
  22819. }
  22820. var faces = THREE.ShapeUtils.triangulateShape( vertices, holes );
  22821. // Vertices
  22822. for ( i = 0, l = holes.length; i < l; i ++ ) {
  22823. hole = holes[ i ];
  22824. vertices = vertices.concat( hole );
  22825. }
  22826. //
  22827. var vert, vlen = vertices.length;
  22828. var face, flen = faces.length;
  22829. for ( i = 0; i < vlen; i ++ ) {
  22830. vert = vertices[ i ];
  22831. this.vertices.push( new THREE.Vector3( vert.x, vert.y, 0 ) );
  22832. }
  22833. for ( i = 0; i < flen; i ++ ) {
  22834. face = faces[ i ];
  22835. var a = face[ 0 ] + shapesOffset;
  22836. var b = face[ 1 ] + shapesOffset;
  22837. var c = face[ 2 ] + shapesOffset;
  22838. this.faces.push( new THREE.Face3( a, b, c, null, null, material ) );
  22839. this.faceVertexUvs[ 0 ].push( uvgen.generateTopUV( this, a, b, c ) );
  22840. }
  22841. };
  22842. // File:src/extras/geometries/LatheBufferGeometry.js
  22843. /**
  22844. * @author Mugen87 / https://github.com/Mugen87
  22845. */
  22846. // points - to create a closed torus, one must use a set of points
  22847. // like so: [ a, b, c, d, a ], see first is the same as last.
  22848. // segments - the number of circumference segments to create
  22849. // phiStart - the starting radian
  22850. // phiLength - the radian (0 to 2PI) range of the lathed section
  22851. // 2PI is a closed lathe, less than 2PI is a portion.
  22852. THREE.LatheBufferGeometry = function ( points, segments, phiStart, phiLength ) {
  22853. THREE.BufferGeometry.call( this );
  22854. this.type = 'LatheBufferGeometry';
  22855. this.parameters = {
  22856. points: points,
  22857. segments: segments,
  22858. phiStart: phiStart,
  22859. phiLength: phiLength
  22860. };
  22861. segments = Math.floor( segments ) || 12;
  22862. phiStart = phiStart || 0;
  22863. phiLength = phiLength || Math.PI * 2;
  22864. // clamp phiLength so it's in range of [ 0, 2PI ]
  22865. phiLength = THREE.Math.clamp( phiLength, 0, Math.PI * 2 );
  22866. // these are used to calculate buffer length
  22867. var vertexCount = ( segments + 1 ) * points.length;
  22868. var indexCount = segments * points.length * 2 * 3;
  22869. // buffers
  22870. var indices = new THREE.BufferAttribute( new ( indexCount > 65535 ? Uint32Array : Uint16Array )( indexCount ) , 1 );
  22871. var vertices = new THREE.BufferAttribute( new Float32Array( vertexCount * 3 ), 3 );
  22872. var uvs = new THREE.BufferAttribute( new Float32Array( vertexCount * 2 ), 2 );
  22873. // helper variables
  22874. var index = 0, indexOffset = 0, base;
  22875. var inversePointLength = 1.0 / ( points.length - 1 );
  22876. var inverseSegments = 1.0 / segments;
  22877. var vertex = new THREE.Vector3();
  22878. var uv = new THREE.Vector2();
  22879. var i, j;
  22880. // generate vertices and uvs
  22881. for ( i = 0; i <= segments; i ++ ) {
  22882. var phi = phiStart + i * inverseSegments * phiLength;
  22883. var sin = Math.sin( phi );
  22884. var cos = Math.cos( phi );
  22885. for ( j = 0; j <= ( points.length - 1 ); j ++ ) {
  22886. // vertex
  22887. vertex.x = points[ j ].x * sin;
  22888. vertex.y = points[ j ].y;
  22889. vertex.z = points[ j ].x * cos;
  22890. vertices.setXYZ( index, vertex.x, vertex.y, vertex.z );
  22891. // uv
  22892. uv.x = i / segments;
  22893. uv.y = j / ( points.length - 1 );
  22894. uvs.setXY( index, uv.x, uv.y );
  22895. // increase index
  22896. index ++;
  22897. }
  22898. }
  22899. // generate indices
  22900. for ( i = 0; i < segments; i ++ ) {
  22901. for ( j = 0; j < ( points.length - 1 ); j ++ ) {
  22902. base = j + i * points.length;
  22903. // indices
  22904. var a = base;
  22905. var b = base + points.length;
  22906. var c = base + points.length + 1;
  22907. var d = base + 1;
  22908. // face one
  22909. indices.setX( indexOffset, a ); indexOffset++;
  22910. indices.setX( indexOffset, b ); indexOffset++;
  22911. indices.setX( indexOffset, d ); indexOffset++;
  22912. // face two
  22913. indices.setX( indexOffset, b ); indexOffset++;
  22914. indices.setX( indexOffset, c ); indexOffset++;
  22915. indices.setX( indexOffset, d ); indexOffset++;
  22916. }
  22917. }
  22918. // build geometry
  22919. this.setIndex( indices );
  22920. this.addAttribute( 'position', vertices );
  22921. this.addAttribute( 'uv', uvs );
  22922. // generate normals
  22923. this.computeVertexNormals();
  22924. // if the geometry is closed, we need to average the normals along the seam.
  22925. // because the corresponding vertices are identical (but still have different UVs).
  22926. if( phiLength === Math.PI * 2 ) {
  22927. var normals = this.attributes.normal.array;
  22928. var n1 = new THREE.Vector3();
  22929. var n2 = new THREE.Vector3();
  22930. var n = new THREE.Vector3();
  22931. // this is the buffer offset for the last line of vertices
  22932. base = segments * points.length * 3;
  22933. for( i = 0, j = 0; i < points.length; i ++, j += 3 ) {
  22934. // select the normal of the vertex in the first line
  22935. n1.x = normals[ j + 0 ];
  22936. n1.y = normals[ j + 1 ];
  22937. n1.z = normals[ j + 2 ];
  22938. // select the normal of the vertex in the last line
  22939. n2.x = normals[ base + j + 0 ];
  22940. n2.y = normals[ base + j + 1 ];
  22941. n2.z = normals[ base + j + 2 ];
  22942. // average normals
  22943. n.addVectors( n1, n2 ).normalize();
  22944. // assign the new values to both normals
  22945. normals[ j + 0 ] = normals[ base + j + 0 ] = n.x;
  22946. normals[ j + 1 ] = normals[ base + j + 1 ] = n.y;
  22947. normals[ j + 2 ] = normals[ base + j + 2 ] = n.z;
  22948. } // next row
  22949. }
  22950. };
  22951. THREE.LatheBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  22952. THREE.LatheBufferGeometry.prototype.constructor = THREE.LatheBufferGeometry;
  22953. // File:src/extras/geometries/LatheGeometry.js
  22954. /**
  22955. * @author astrodud / http://astrodud.isgreat.org/
  22956. * @author zz85 / https://github.com/zz85
  22957. * @author bhouston / http://clara.io
  22958. */
  22959. // points - to create a closed torus, one must use a set of points
  22960. // like so: [ a, b, c, d, a ], see first is the same as last.
  22961. // segments - the number of circumference segments to create
  22962. // phiStart - the starting radian
  22963. // phiLength - the radian (0 to 2PI) range of the lathed section
  22964. // 2PI is a closed lathe, less than 2PI is a portion.
  22965. THREE.LatheGeometry = function ( points, segments, phiStart, phiLength ) {
  22966. THREE.Geometry.call( this );
  22967. this.type = 'LatheGeometry';
  22968. this.parameters = {
  22969. points: points,
  22970. segments: segments,
  22971. phiStart: phiStart,
  22972. phiLength: phiLength
  22973. };
  22974. this.fromBufferGeometry( new THREE.LatheBufferGeometry( points, segments, phiStart, phiLength ) );
  22975. this.mergeVertices();
  22976. };
  22977. THREE.LatheGeometry.prototype = Object.create( THREE.Geometry.prototype );
  22978. THREE.LatheGeometry.prototype.constructor = THREE.LatheGeometry;
  22979. // File:src/extras/geometries/PlaneGeometry.js
  22980. /**
  22981. * @author mrdoob / http://mrdoob.com/
  22982. * based on http://papervision3d.googlecode.com/svn/trunk/as3/trunk/src/org/papervision3d/objects/primitives/Plane.as
  22983. */
  22984. THREE.PlaneGeometry = function ( width, height, widthSegments, heightSegments ) {
  22985. THREE.Geometry.call( this );
  22986. this.type = 'PlaneGeometry';
  22987. this.parameters = {
  22988. width: width,
  22989. height: height,
  22990. widthSegments: widthSegments,
  22991. heightSegments: heightSegments
  22992. };
  22993. this.fromBufferGeometry( new THREE.PlaneBufferGeometry( width, height, widthSegments, heightSegments ) );
  22994. };
  22995. THREE.PlaneGeometry.prototype = Object.create( THREE.Geometry.prototype );
  22996. THREE.PlaneGeometry.prototype.constructor = THREE.PlaneGeometry;
  22997. // File:src/extras/geometries/PlaneBufferGeometry.js
  22998. /**
  22999. * @author mrdoob / http://mrdoob.com/
  23000. * based on http://papervision3d.googlecode.com/svn/trunk/as3/trunk/src/org/papervision3d/objects/primitives/Plane.as
  23001. */
  23002. THREE.PlaneBufferGeometry = function ( width, height, widthSegments, heightSegments ) {
  23003. THREE.BufferGeometry.call( this );
  23004. this.type = 'PlaneBufferGeometry';
  23005. this.parameters = {
  23006. width: width,
  23007. height: height,
  23008. widthSegments: widthSegments,
  23009. heightSegments: heightSegments
  23010. };
  23011. var width_half = width / 2;
  23012. var height_half = height / 2;
  23013. var gridX = Math.floor( widthSegments ) || 1;
  23014. var gridY = Math.floor( heightSegments ) || 1;
  23015. var gridX1 = gridX + 1;
  23016. var gridY1 = gridY + 1;
  23017. var segment_width = width / gridX;
  23018. var segment_height = height / gridY;
  23019. var vertices = new Float32Array( gridX1 * gridY1 * 3 );
  23020. var normals = new Float32Array( gridX1 * gridY1 * 3 );
  23021. var uvs = new Float32Array( gridX1 * gridY1 * 2 );
  23022. var offset = 0;
  23023. var offset2 = 0;
  23024. for ( var iy = 0; iy < gridY1; iy ++ ) {
  23025. var y = iy * segment_height - height_half;
  23026. for ( var ix = 0; ix < gridX1; ix ++ ) {
  23027. var x = ix * segment_width - width_half;
  23028. vertices[ offset ] = x;
  23029. vertices[ offset + 1 ] = - y;
  23030. normals[ offset + 2 ] = 1;
  23031. uvs[ offset2 ] = ix / gridX;
  23032. uvs[ offset2 + 1 ] = 1 - ( iy / gridY );
  23033. offset += 3;
  23034. offset2 += 2;
  23035. }
  23036. }
  23037. offset = 0;
  23038. var indices = new ( ( vertices.length / 3 ) > 65535 ? Uint32Array : Uint16Array )( gridX * gridY * 6 );
  23039. for ( var iy = 0; iy < gridY; iy ++ ) {
  23040. for ( var ix = 0; ix < gridX; ix ++ ) {
  23041. var a = ix + gridX1 * iy;
  23042. var b = ix + gridX1 * ( iy + 1 );
  23043. var c = ( ix + 1 ) + gridX1 * ( iy + 1 );
  23044. var d = ( ix + 1 ) + gridX1 * iy;
  23045. indices[ offset ] = a;
  23046. indices[ offset + 1 ] = b;
  23047. indices[ offset + 2 ] = d;
  23048. indices[ offset + 3 ] = b;
  23049. indices[ offset + 4 ] = c;
  23050. indices[ offset + 5 ] = d;
  23051. offset += 6;
  23052. }
  23053. }
  23054. this.setIndex( new THREE.BufferAttribute( indices, 1 ) );
  23055. this.addAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) );
  23056. this.addAttribute( 'normal', new THREE.BufferAttribute( normals, 3 ) );
  23057. this.addAttribute( 'uv', new THREE.BufferAttribute( uvs, 2 ) );
  23058. };
  23059. THREE.PlaneBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  23060. THREE.PlaneBufferGeometry.prototype.constructor = THREE.PlaneBufferGeometry;
  23061. // File:src/extras/geometries/RingBufferGeometry.js
  23062. /**
  23063. * @author Mugen87 / https://github.com/Mugen87
  23064. */
  23065. THREE.RingBufferGeometry = function ( innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength ) {
  23066. THREE.BufferGeometry.call( this );
  23067. this.type = 'RingBufferGeometry';
  23068. this.parameters = {
  23069. innerRadius: innerRadius,
  23070. outerRadius: outerRadius,
  23071. thetaSegments: thetaSegments,
  23072. phiSegments: phiSegments,
  23073. thetaStart: thetaStart,
  23074. thetaLength: thetaLength
  23075. };
  23076. innerRadius = innerRadius || 20;
  23077. outerRadius = outerRadius || 50;
  23078. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  23079. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  23080. thetaSegments = thetaSegments !== undefined ? Math.max( 3, thetaSegments ) : 8;
  23081. phiSegments = phiSegments !== undefined ? Math.max( 1, phiSegments ) : 1;
  23082. // these are used to calculate buffer length
  23083. var vertexCount = ( thetaSegments + 1 ) * ( phiSegments + 1 );
  23084. var indexCount = thetaSegments * phiSegments * 2 * 3;
  23085. // buffers
  23086. var indices = new THREE.BufferAttribute( new ( indexCount > 65535 ? Uint32Array : Uint16Array )( indexCount ) , 1 );
  23087. var vertices = new THREE.BufferAttribute( new Float32Array( vertexCount * 3 ), 3 );
  23088. var normals = new THREE.BufferAttribute( new Float32Array( vertexCount * 3 ), 3 );
  23089. var uvs = new THREE.BufferAttribute( new Float32Array( vertexCount * 2 ), 2 );
  23090. // some helper variables
  23091. var index = 0, indexOffset = 0, segment;
  23092. var radius = innerRadius;
  23093. var radiusStep = ( ( outerRadius - innerRadius ) / phiSegments );
  23094. var vertex = new THREE.Vector3();
  23095. var uv = new THREE.Vector2();
  23096. var j, i;
  23097. // generate vertices, normals and uvs
  23098. // values are generate from the inside of the ring to the outside
  23099. for ( j = 0; j <= phiSegments; j ++ ) {
  23100. for ( i = 0; i <= thetaSegments; i ++ ) {
  23101. segment = thetaStart + i / thetaSegments * thetaLength;
  23102. // vertex
  23103. vertex.x = radius * Math.cos( segment );
  23104. vertex.y = radius * Math.sin( segment );
  23105. vertices.setXYZ( index, vertex.x, vertex.y, vertex.z );
  23106. // normal
  23107. normals.setXYZ( index, 0, 0, 1 );
  23108. // uv
  23109. uv.x = ( vertex.x / outerRadius + 1 ) / 2;
  23110. uv.y = ( vertex.y / outerRadius + 1 ) / 2;
  23111. uvs.setXY( index, uv.x, uv.y );
  23112. // increase index
  23113. index++;
  23114. }
  23115. // increase the radius for next row of vertices
  23116. radius += radiusStep;
  23117. }
  23118. // generate indices
  23119. for ( j = 0; j < phiSegments; j ++ ) {
  23120. var thetaSegmentLevel = j * ( thetaSegments + 1 );
  23121. for ( i = 0; i < thetaSegments; i ++ ) {
  23122. segment = i + thetaSegmentLevel;
  23123. // indices
  23124. var a = segment;
  23125. var b = segment + thetaSegments + 1;
  23126. var c = segment + thetaSegments + 2;
  23127. var d = segment + 1;
  23128. // face one
  23129. indices.setX( indexOffset, a ); indexOffset++;
  23130. indices.setX( indexOffset, b ); indexOffset++;
  23131. indices.setX( indexOffset, c ); indexOffset++;
  23132. // face two
  23133. indices.setX( indexOffset, a ); indexOffset++;
  23134. indices.setX( indexOffset, c ); indexOffset++;
  23135. indices.setX( indexOffset, d ); indexOffset++;
  23136. }
  23137. }
  23138. // build geometry
  23139. this.setIndex( indices );
  23140. this.addAttribute( 'position', vertices );
  23141. this.addAttribute( 'normal', normals );
  23142. this.addAttribute( 'uv', uvs );
  23143. };
  23144. THREE.RingBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  23145. THREE.RingBufferGeometry.prototype.constructor = THREE.RingBufferGeometry;
  23146. // File:src/extras/geometries/RingGeometry.js
  23147. /**
  23148. * @author Kaleb Murphy
  23149. */
  23150. THREE.RingGeometry = function ( innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength ) {
  23151. THREE.Geometry.call( this );
  23152. this.type = 'RingGeometry';
  23153. this.parameters = {
  23154. innerRadius: innerRadius,
  23155. outerRadius: outerRadius,
  23156. thetaSegments: thetaSegments,
  23157. phiSegments: phiSegments,
  23158. thetaStart: thetaStart,
  23159. thetaLength: thetaLength
  23160. };
  23161. this.fromBufferGeometry( new THREE.RingBufferGeometry( innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength ) );
  23162. };
  23163. THREE.RingGeometry.prototype = Object.create( THREE.Geometry.prototype );
  23164. THREE.RingGeometry.prototype.constructor = THREE.RingGeometry;
  23165. // File:src/extras/geometries/SphereGeometry.js
  23166. /**
  23167. * @author mrdoob / http://mrdoob.com/
  23168. */
  23169. THREE.SphereGeometry = function ( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) {
  23170. THREE.Geometry.call( this );
  23171. this.type = 'SphereGeometry';
  23172. this.parameters = {
  23173. radius: radius,
  23174. widthSegments: widthSegments,
  23175. heightSegments: heightSegments,
  23176. phiStart: phiStart,
  23177. phiLength: phiLength,
  23178. thetaStart: thetaStart,
  23179. thetaLength: thetaLength
  23180. };
  23181. this.fromBufferGeometry( new THREE.SphereBufferGeometry( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) );
  23182. };
  23183. THREE.SphereGeometry.prototype = Object.create( THREE.Geometry.prototype );
  23184. THREE.SphereGeometry.prototype.constructor = THREE.SphereGeometry;
  23185. // File:src/extras/geometries/SphereBufferGeometry.js
  23186. /**
  23187. * @author benaadams / https://twitter.com/ben_a_adams
  23188. * based on THREE.SphereGeometry
  23189. */
  23190. THREE.SphereBufferGeometry = function ( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) {
  23191. THREE.BufferGeometry.call( this );
  23192. this.type = 'SphereBufferGeometry';
  23193. this.parameters = {
  23194. radius: radius,
  23195. widthSegments: widthSegments,
  23196. heightSegments: heightSegments,
  23197. phiStart: phiStart,
  23198. phiLength: phiLength,
  23199. thetaStart: thetaStart,
  23200. thetaLength: thetaLength
  23201. };
  23202. radius = radius || 50;
  23203. widthSegments = Math.max( 3, Math.floor( widthSegments ) || 8 );
  23204. heightSegments = Math.max( 2, Math.floor( heightSegments ) || 6 );
  23205. phiStart = phiStart !== undefined ? phiStart : 0;
  23206. phiLength = phiLength !== undefined ? phiLength : Math.PI * 2;
  23207. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  23208. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI;
  23209. var thetaEnd = thetaStart + thetaLength;
  23210. var vertexCount = ( ( widthSegments + 1 ) * ( heightSegments + 1 ) );
  23211. var positions = new THREE.BufferAttribute( new Float32Array( vertexCount * 3 ), 3 );
  23212. var normals = new THREE.BufferAttribute( new Float32Array( vertexCount * 3 ), 3 );
  23213. var uvs = new THREE.BufferAttribute( new Float32Array( vertexCount * 2 ), 2 );
  23214. var index = 0, vertices = [], normal = new THREE.Vector3();
  23215. for ( var y = 0; y <= heightSegments; y ++ ) {
  23216. var verticesRow = [];
  23217. var v = y / heightSegments;
  23218. for ( var x = 0; x <= widthSegments; x ++ ) {
  23219. var u = x / widthSegments;
  23220. var px = - radius * Math.cos( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  23221. var py = radius * Math.cos( thetaStart + v * thetaLength );
  23222. var pz = radius * Math.sin( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  23223. normal.set( px, py, pz ).normalize();
  23224. positions.setXYZ( index, px, py, pz );
  23225. normals.setXYZ( index, normal.x, normal.y, normal.z );
  23226. uvs.setXY( index, u, 1 - v );
  23227. verticesRow.push( index );
  23228. index ++;
  23229. }
  23230. vertices.push( verticesRow );
  23231. }
  23232. var indices = [];
  23233. for ( var y = 0; y < heightSegments; y ++ ) {
  23234. for ( var x = 0; x < widthSegments; x ++ ) {
  23235. var v1 = vertices[ y ][ x + 1 ];
  23236. var v2 = vertices[ y ][ x ];
  23237. var v3 = vertices[ y + 1 ][ x ];
  23238. var v4 = vertices[ y + 1 ][ x + 1 ];
  23239. if ( y !== 0 || thetaStart > 0 ) indices.push( v1, v2, v4 );
  23240. if ( y !== heightSegments - 1 || thetaEnd < Math.PI ) indices.push( v2, v3, v4 );
  23241. }
  23242. }
  23243. this.setIndex( new ( positions.count > 65535 ? THREE.Uint32Attribute : THREE.Uint16Attribute )( indices, 1 ) );
  23244. this.addAttribute( 'position', positions );
  23245. this.addAttribute( 'normal', normals );
  23246. this.addAttribute( 'uv', uvs );
  23247. this.boundingSphere = new THREE.Sphere( new THREE.Vector3(), radius );
  23248. };
  23249. THREE.SphereBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  23250. THREE.SphereBufferGeometry.prototype.constructor = THREE.SphereBufferGeometry;
  23251. // File:src/extras/geometries/TextGeometry.js
  23252. /**
  23253. * @author zz85 / http://www.lab4games.net/zz85/blog
  23254. * @author alteredq / http://alteredqualia.com/
  23255. *
  23256. * Text = 3D Text
  23257. *
  23258. * parameters = {
  23259. * font: <THREE.Font>, // font
  23260. *
  23261. * size: <float>, // size of the text
  23262. * height: <float>, // thickness to extrude text
  23263. * curveSegments: <int>, // number of points on the curves
  23264. *
  23265. * bevelEnabled: <bool>, // turn on bevel
  23266. * bevelThickness: <float>, // how deep into text bevel goes
  23267. * bevelSize: <float> // how far from text outline is bevel
  23268. * }
  23269. */
  23270. THREE.TextGeometry = function ( text, parameters ) {
  23271. parameters = parameters || {};
  23272. var font = parameters.font;
  23273. if ( font instanceof THREE.Font === false ) {
  23274. console.error( 'THREE.TextGeometry: font parameter is not an instance of THREE.Font.' );
  23275. return new THREE.Geometry();
  23276. }
  23277. var shapes = font.generateShapes( text, parameters.size, parameters.curveSegments );
  23278. // translate parameters to ExtrudeGeometry API
  23279. parameters.amount = parameters.height !== undefined ? parameters.height : 50;
  23280. // defaults
  23281. if ( parameters.bevelThickness === undefined ) parameters.bevelThickness = 10;
  23282. if ( parameters.bevelSize === undefined ) parameters.bevelSize = 8;
  23283. if ( parameters.bevelEnabled === undefined ) parameters.bevelEnabled = false;
  23284. THREE.ExtrudeGeometry.call( this, shapes, parameters );
  23285. this.type = 'TextGeometry';
  23286. };
  23287. THREE.TextGeometry.prototype = Object.create( THREE.ExtrudeGeometry.prototype );
  23288. THREE.TextGeometry.prototype.constructor = THREE.TextGeometry;
  23289. // File:src/extras/geometries/TorusBufferGeometry.js
  23290. /**
  23291. * @author Mugen87 / https://github.com/Mugen87
  23292. */
  23293. THREE.TorusBufferGeometry = function ( radius, tube, radialSegments, tubularSegments, arc ) {
  23294. THREE.BufferGeometry.call( this );
  23295. this.type = 'TorusBufferGeometry';
  23296. this.parameters = {
  23297. radius: radius,
  23298. tube: tube,
  23299. radialSegments: radialSegments,
  23300. tubularSegments: tubularSegments,
  23301. arc: arc
  23302. };
  23303. radius = radius || 100;
  23304. tube = tube || 40;
  23305. radialSegments = Math.floor( radialSegments ) || 8;
  23306. tubularSegments = Math.floor( tubularSegments ) || 6;
  23307. arc = arc || Math.PI * 2;
  23308. // used to calculate buffer length
  23309. var vertexCount = ( ( radialSegments + 1 ) * ( tubularSegments + 1 ) );
  23310. var indexCount = radialSegments * tubularSegments * 2 * 3;
  23311. // buffers
  23312. var indices = new ( indexCount > 65535 ? Uint32Array : Uint16Array )( indexCount );
  23313. var vertices = new Float32Array( vertexCount * 3 );
  23314. var normals = new Float32Array( vertexCount * 3 );
  23315. var uvs = new Float32Array( vertexCount * 2 );
  23316. // offset variables
  23317. var vertexBufferOffset = 0;
  23318. var uvBufferOffset = 0;
  23319. var indexBufferOffset = 0;
  23320. // helper variables
  23321. var center = new THREE.Vector3();
  23322. var vertex = new THREE.Vector3();
  23323. var normal = new THREE.Vector3();
  23324. var j, i;
  23325. // generate vertices, normals and uvs
  23326. for ( j = 0; j <= radialSegments; j ++ ) {
  23327. for ( i = 0; i <= tubularSegments; i ++ ) {
  23328. var u = i / tubularSegments * arc;
  23329. var v = j / radialSegments * Math.PI * 2;
  23330. // vertex
  23331. vertex.x = ( radius + tube * Math.cos( v ) ) * Math.cos( u );
  23332. vertex.y = ( radius + tube * Math.cos( v ) ) * Math.sin( u );
  23333. vertex.z = tube * Math.sin( v );
  23334. vertices[ vertexBufferOffset ] = vertex.x;
  23335. vertices[ vertexBufferOffset + 1 ] = vertex.y;
  23336. vertices[ vertexBufferOffset + 2 ] = vertex.z;
  23337. // this vector is used to calculate the normal
  23338. center.x = radius * Math.cos( u );
  23339. center.y = radius * Math.sin( u );
  23340. // normal
  23341. normal.subVectors( vertex, center ).normalize();
  23342. normals[ vertexBufferOffset ] = normal.x;
  23343. normals[ vertexBufferOffset + 1 ] = normal.y;
  23344. normals[ vertexBufferOffset + 2 ] = normal.z;
  23345. // uv
  23346. uvs[ uvBufferOffset ] = i / tubularSegments;
  23347. uvs[ uvBufferOffset + 1 ] = j / radialSegments;
  23348. // update offsets
  23349. vertexBufferOffset += 3;
  23350. uvBufferOffset += 2;
  23351. }
  23352. }
  23353. // generate indices
  23354. for ( j = 1; j <= radialSegments; j ++ ) {
  23355. for ( i = 1; i <= tubularSegments; i ++ ) {
  23356. // indices
  23357. var a = ( tubularSegments + 1 ) * j + i - 1;
  23358. var b = ( tubularSegments + 1 ) * ( j - 1 ) + i - 1;
  23359. var c = ( tubularSegments + 1 ) * ( j - 1 ) + i;
  23360. var d = ( tubularSegments + 1 ) * j + i;
  23361. // face one
  23362. indices[ indexBufferOffset ] = a;
  23363. indices[ indexBufferOffset + 1 ] = b;
  23364. indices[ indexBufferOffset + 2 ] = d;
  23365. // face two
  23366. indices[ indexBufferOffset + 3 ] = b;
  23367. indices[ indexBufferOffset + 4 ] = c;
  23368. indices[ indexBufferOffset + 5 ] = d;
  23369. // update offset
  23370. indexBufferOffset += 6;
  23371. }
  23372. }
  23373. // build geometry
  23374. this.setIndex( new THREE.BufferAttribute( indices, 1 ) );
  23375. this.addAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) );
  23376. this.addAttribute( 'normal', new THREE.BufferAttribute( normals, 3 ) );
  23377. this.addAttribute( 'uv', new THREE.BufferAttribute( uvs, 2 ) );
  23378. };
  23379. THREE.TorusBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  23380. THREE.TorusBufferGeometry.prototype.constructor = THREE.TorusBufferGeometry;
  23381. // File:src/extras/geometries/TorusGeometry.js
  23382. /**
  23383. * @author oosmoxiecode
  23384. * @author mrdoob / http://mrdoob.com/
  23385. * based on http://code.google.com/p/away3d/source/browse/trunk/fp10/Away3DLite/src/away3dlite/primitives/Torus.as?r=2888
  23386. */
  23387. THREE.TorusGeometry = function ( radius, tube, radialSegments, tubularSegments, arc ) {
  23388. THREE.Geometry.call( this );
  23389. this.type = 'TorusGeometry';
  23390. this.parameters = {
  23391. radius: radius,
  23392. tube: tube,
  23393. radialSegments: radialSegments,
  23394. tubularSegments: tubularSegments,
  23395. arc: arc
  23396. };
  23397. this.fromBufferGeometry( new THREE.TorusBufferGeometry( radius, tube, radialSegments, tubularSegments, arc ) );
  23398. };
  23399. THREE.TorusGeometry.prototype = Object.create( THREE.Geometry.prototype );
  23400. THREE.TorusGeometry.prototype.constructor = THREE.TorusGeometry;
  23401. // File:src/extras/geometries/TorusKnotBufferGeometry.js
  23402. /**
  23403. * @author Mugen87 / https://github.com/Mugen87
  23404. *
  23405. * see: http://www.blackpawn.com/texts/pqtorus/
  23406. */
  23407. THREE.TorusKnotBufferGeometry = function ( radius, tube, tubularSegments, radialSegments, p, q ) {
  23408. THREE.BufferGeometry.call( this );
  23409. this.type = 'TorusKnotBufferGeometry';
  23410. this.parameters = {
  23411. radius: radius,
  23412. tube: tube,
  23413. tubularSegments: tubularSegments,
  23414. radialSegments: radialSegments,
  23415. p: p,
  23416. q: q
  23417. };
  23418. radius = radius || 100;
  23419. tube = tube || 40;
  23420. tubularSegments = Math.floor( tubularSegments ) || 64;
  23421. radialSegments = Math.floor( radialSegments ) || 8;
  23422. p = p || 2;
  23423. q = q || 3;
  23424. // used to calculate buffer length
  23425. var vertexCount = ( ( radialSegments + 1 ) * ( tubularSegments + 1 ) );
  23426. var indexCount = radialSegments * tubularSegments * 2 * 3;
  23427. // buffers
  23428. var indices = new THREE.BufferAttribute( new ( indexCount > 65535 ? Uint32Array : Uint16Array )( indexCount ) , 1 );
  23429. var vertices = new THREE.BufferAttribute( new Float32Array( vertexCount * 3 ), 3 );
  23430. var normals = new THREE.BufferAttribute( new Float32Array( vertexCount * 3 ), 3 );
  23431. var uvs = new THREE.BufferAttribute( new Float32Array( vertexCount * 2 ), 2 );
  23432. // helper variables
  23433. var i, j, index = 0, indexOffset = 0;
  23434. var vertex = new THREE.Vector3();
  23435. var normal = new THREE.Vector3();
  23436. var uv = new THREE.Vector2();
  23437. var P1 = new THREE.Vector3();
  23438. var P2 = new THREE.Vector3();
  23439. var B = new THREE.Vector3();
  23440. var T = new THREE.Vector3();
  23441. var N = new THREE.Vector3();
  23442. // generate vertices, normals and uvs
  23443. for ( i = 0; i <= tubularSegments; ++ i ) {
  23444. // the radian "u" is used to calculate the position on the torus curve of the current tubular segement
  23445. var u = i / tubularSegments * p * Math.PI * 2;
  23446. // now we calculate two points. P1 is our current position on the curve, P2 is a little farther ahead.
  23447. // these points are used to create a special "coordinate space", which is necessary to calculate the correct vertex positions
  23448. calculatePositionOnCurve( u, p, q, radius, P1 );
  23449. calculatePositionOnCurve( u + 0.01, p, q, radius, P2 );
  23450. // calculate orthonormal basis
  23451. T.subVectors( P2, P1 );
  23452. N.addVectors( P2, P1 );
  23453. B.crossVectors( T, N );
  23454. N.crossVectors( B, T );
  23455. // normalize B, N. T can be ignored, we don't use it
  23456. B.normalize();
  23457. N.normalize();
  23458. for ( j = 0; j <= radialSegments; ++ j ) {
  23459. // now calculate the vertices. they are nothing more than an extrusion of the torus curve.
  23460. // because we extrude a shape in the xy-plane, there is no need to calculate a z-value.
  23461. var v = j / radialSegments * Math.PI * 2;
  23462. var cx = - tube * Math.cos( v );
  23463. var cy = tube * Math.sin( v );
  23464. // now calculate the final vertex position.
  23465. // first we orient the extrusion with our basis vectos, then we add it to the current position on the curve
  23466. vertex.x = P1.x + ( cx * N.x + cy * B.x );
  23467. vertex.y = P1.y + ( cx * N.y + cy * B.y );
  23468. vertex.z = P1.z + ( cx * N.z + cy * B.z );
  23469. // vertex
  23470. vertices.setXYZ( index, vertex.x, vertex.y, vertex.z );
  23471. // normal (P1 is always the center/origin of the extrusion, thus we can use it to calculate the normal)
  23472. normal.subVectors( vertex, P1 ).normalize();
  23473. normals.setXYZ( index, normal.x, normal.y, normal.z );
  23474. // uv
  23475. uv.x = i / tubularSegments;
  23476. uv.y = j / radialSegments;
  23477. uvs.setXY( index, uv.x, uv.y );
  23478. // increase index
  23479. index ++;
  23480. }
  23481. }
  23482. // generate indices
  23483. for ( j = 1; j <= tubularSegments; j ++ ) {
  23484. for ( i = 1; i <= radialSegments; i ++ ) {
  23485. // indices
  23486. var a = ( radialSegments + 1 ) * ( j - 1 ) + ( i - 1 );
  23487. var b = ( radialSegments + 1 ) * j + ( i - 1 );
  23488. var c = ( radialSegments + 1 ) * j + i;
  23489. var d = ( radialSegments + 1 ) * ( j - 1 ) + i;
  23490. // face one
  23491. indices.setX( indexOffset, a ); indexOffset++;
  23492. indices.setX( indexOffset, b ); indexOffset++;
  23493. indices.setX( indexOffset, d ); indexOffset++;
  23494. // face two
  23495. indices.setX( indexOffset, b ); indexOffset++;
  23496. indices.setX( indexOffset, c ); indexOffset++;
  23497. indices.setX( indexOffset, d ); indexOffset++;
  23498. }
  23499. }
  23500. // build geometry
  23501. this.setIndex( indices );
  23502. this.addAttribute( 'position', vertices );
  23503. this.addAttribute( 'normal', normals );
  23504. this.addAttribute( 'uv', uvs );
  23505. // this function calculates the current position on the torus curve
  23506. function calculatePositionOnCurve( u, p, q, radius, position ) {
  23507. var cu = Math.cos( u );
  23508. var su = Math.sin( u );
  23509. var quOverP = q / p * u;
  23510. var cs = Math.cos( quOverP );
  23511. position.x = radius * ( 2 + cs ) * 0.5 * cu;
  23512. position.y = radius * ( 2 + cs ) * su * 0.5;
  23513. position.z = radius * Math.sin( quOverP ) * 0.5;
  23514. }
  23515. };
  23516. THREE.TorusKnotBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  23517. THREE.TorusKnotBufferGeometry.prototype.constructor = THREE.TorusKnotBufferGeometry;
  23518. // File:src/extras/geometries/TorusKnotGeometry.js
  23519. /**
  23520. * @author oosmoxiecode
  23521. */
  23522. THREE.TorusKnotGeometry = function ( radius, tube, tubularSegments, radialSegments, p, q, heightScale ) {
  23523. THREE.Geometry.call( this );
  23524. this.type = 'TorusKnotGeometry';
  23525. this.parameters = {
  23526. radius: radius,
  23527. tube: tube,
  23528. tubularSegments: tubularSegments,
  23529. radialSegments: radialSegments,
  23530. p: p,
  23531. q: q
  23532. };
  23533. if( heightScale !== undefined ) console.warn( 'THREE.TorusKnotGeometry: heightScale has been deprecated. Use .scale( x, y, z ) instead.' );
  23534. this.fromBufferGeometry( new THREE.TorusKnotBufferGeometry( radius, tube, tubularSegments, radialSegments, p, q ) );
  23535. this.mergeVertices();
  23536. };
  23537. THREE.TorusKnotGeometry.prototype = Object.create( THREE.Geometry.prototype );
  23538. THREE.TorusKnotGeometry.prototype.constructor = THREE.TorusKnotGeometry;
  23539. // File:src/extras/geometries/TubeGeometry.js
  23540. /**
  23541. * @author WestLangley / https://github.com/WestLangley
  23542. * @author zz85 / https://github.com/zz85
  23543. * @author miningold / https://github.com/miningold
  23544. * @author jonobr1 / https://github.com/jonobr1
  23545. *
  23546. * Modified from the TorusKnotGeometry by @oosmoxiecode
  23547. *
  23548. * Creates a tube which extrudes along a 3d spline
  23549. *
  23550. * Uses parallel transport frames as described in
  23551. * http://www.cs.indiana.edu/pub/techreports/TR425.pdf
  23552. */
  23553. THREE.TubeGeometry = function ( path, segments, radius, radialSegments, closed, taper ) {
  23554. THREE.Geometry.call( this );
  23555. this.type = 'TubeGeometry';
  23556. this.parameters = {
  23557. path: path,
  23558. segments: segments,
  23559. radius: radius,
  23560. radialSegments: radialSegments,
  23561. closed: closed,
  23562. taper: taper
  23563. };
  23564. segments = segments || 64;
  23565. radius = radius || 1;
  23566. radialSegments = radialSegments || 8;
  23567. closed = closed || false;
  23568. taper = taper || THREE.TubeGeometry.NoTaper;
  23569. var grid = [];
  23570. var scope = this,
  23571. tangent,
  23572. normal,
  23573. binormal,
  23574. numpoints = segments + 1,
  23575. u, v, r,
  23576. cx, cy,
  23577. pos, pos2 = new THREE.Vector3(),
  23578. i, j,
  23579. ip, jp,
  23580. a, b, c, d,
  23581. uva, uvb, uvc, uvd;
  23582. var frames = new THREE.TubeGeometry.FrenetFrames( path, segments, closed ),
  23583. tangents = frames.tangents,
  23584. normals = frames.normals,
  23585. binormals = frames.binormals;
  23586. // proxy internals
  23587. this.tangents = tangents;
  23588. this.normals = normals;
  23589. this.binormals = binormals;
  23590. function vert( x, y, z ) {
  23591. return scope.vertices.push( new THREE.Vector3( x, y, z ) ) - 1;
  23592. }
  23593. // construct the grid
  23594. for ( i = 0; i < numpoints; i ++ ) {
  23595. grid[ i ] = [];
  23596. u = i / ( numpoints - 1 );
  23597. pos = path.getPointAt( u );
  23598. tangent = tangents[ i ];
  23599. normal = normals[ i ];
  23600. binormal = binormals[ i ];
  23601. r = radius * taper( u );
  23602. for ( j = 0; j < radialSegments; j ++ ) {
  23603. v = j / radialSegments * 2 * Math.PI;
  23604. cx = - r * Math.cos( v ); // TODO: Hack: Negating it so it faces outside.
  23605. cy = r * Math.sin( v );
  23606. pos2.copy( pos );
  23607. pos2.x += cx * normal.x + cy * binormal.x;
  23608. pos2.y += cx * normal.y + cy * binormal.y;
  23609. pos2.z += cx * normal.z + cy * binormal.z;
  23610. grid[ i ][ j ] = vert( pos2.x, pos2.y, pos2.z );
  23611. }
  23612. }
  23613. // construct the mesh
  23614. for ( i = 0; i < segments; i ++ ) {
  23615. for ( j = 0; j < radialSegments; j ++ ) {
  23616. ip = ( closed ) ? ( i + 1 ) % segments : i + 1;
  23617. jp = ( j + 1 ) % radialSegments;
  23618. a = grid[ i ][ j ]; // *** NOT NECESSARILY PLANAR ! ***
  23619. b = grid[ ip ][ j ];
  23620. c = grid[ ip ][ jp ];
  23621. d = grid[ i ][ jp ];
  23622. uva = new THREE.Vector2( i / segments, j / radialSegments );
  23623. uvb = new THREE.Vector2( ( i + 1 ) / segments, j / radialSegments );
  23624. uvc = new THREE.Vector2( ( i + 1 ) / segments, ( j + 1 ) / radialSegments );
  23625. uvd = new THREE.Vector2( i / segments, ( j + 1 ) / radialSegments );
  23626. this.faces.push( new THREE.Face3( a, b, d ) );
  23627. this.faceVertexUvs[ 0 ].push( [ uva, uvb, uvd ] );
  23628. this.faces.push( new THREE.Face3( b, c, d ) );
  23629. this.faceVertexUvs[ 0 ].push( [ uvb.clone(), uvc, uvd.clone() ] );
  23630. }
  23631. }
  23632. this.computeFaceNormals();
  23633. this.computeVertexNormals();
  23634. };
  23635. THREE.TubeGeometry.prototype = Object.create( THREE.Geometry.prototype );
  23636. THREE.TubeGeometry.prototype.constructor = THREE.TubeGeometry;
  23637. THREE.TubeGeometry.NoTaper = function ( u ) {
  23638. return 1;
  23639. };
  23640. THREE.TubeGeometry.SinusoidalTaper = function ( u ) {
  23641. return Math.sin( Math.PI * u );
  23642. };
  23643. // For computing of Frenet frames, exposing the tangents, normals and binormals the spline
  23644. THREE.TubeGeometry.FrenetFrames = function ( path, segments, closed ) {
  23645. var normal = new THREE.Vector3(),
  23646. tangents = [],
  23647. normals = [],
  23648. binormals = [],
  23649. vec = new THREE.Vector3(),
  23650. mat = new THREE.Matrix4(),
  23651. numpoints = segments + 1,
  23652. theta,
  23653. smallest,
  23654. tx, ty, tz,
  23655. i, u;
  23656. // expose internals
  23657. this.tangents = tangents;
  23658. this.normals = normals;
  23659. this.binormals = binormals;
  23660. // compute the tangent vectors for each segment on the path
  23661. for ( i = 0; i < numpoints; i ++ ) {
  23662. u = i / ( numpoints - 1 );
  23663. tangents[ i ] = path.getTangentAt( u );
  23664. tangents[ i ].normalize();
  23665. }
  23666. initialNormal3();
  23667. /*
  23668. function initialNormal1(lastBinormal) {
  23669. // fixed start binormal. Has dangers of 0 vectors
  23670. normals[ 0 ] = new THREE.Vector3();
  23671. binormals[ 0 ] = new THREE.Vector3();
  23672. if (lastBinormal===undefined) lastBinormal = new THREE.Vector3( 0, 0, 1 );
  23673. normals[ 0 ].crossVectors( lastBinormal, tangents[ 0 ] ).normalize();
  23674. binormals[ 0 ].crossVectors( tangents[ 0 ], normals[ 0 ] ).normalize();
  23675. }
  23676. function initialNormal2() {
  23677. // This uses the Frenet-Serret formula for deriving binormal
  23678. var t2 = path.getTangentAt( epsilon );
  23679. normals[ 0 ] = new THREE.Vector3().subVectors( t2, tangents[ 0 ] ).normalize();
  23680. binormals[ 0 ] = new THREE.Vector3().crossVectors( tangents[ 0 ], normals[ 0 ] );
  23681. normals[ 0 ].crossVectors( binormals[ 0 ], tangents[ 0 ] ).normalize(); // last binormal x tangent
  23682. binormals[ 0 ].crossVectors( tangents[ 0 ], normals[ 0 ] ).normalize();
  23683. }
  23684. */
  23685. function initialNormal3() {
  23686. // select an initial normal vector perpendicular to the first tangent vector,
  23687. // and in the direction of the smallest tangent xyz component
  23688. normals[ 0 ] = new THREE.Vector3();
  23689. binormals[ 0 ] = new THREE.Vector3();
  23690. smallest = Number.MAX_VALUE;
  23691. tx = Math.abs( tangents[ 0 ].x );
  23692. ty = Math.abs( tangents[ 0 ].y );
  23693. tz = Math.abs( tangents[ 0 ].z );
  23694. if ( tx <= smallest ) {
  23695. smallest = tx;
  23696. normal.set( 1, 0, 0 );
  23697. }
  23698. if ( ty <= smallest ) {
  23699. smallest = ty;
  23700. normal.set( 0, 1, 0 );
  23701. }
  23702. if ( tz <= smallest ) {
  23703. normal.set( 0, 0, 1 );
  23704. }
  23705. vec.crossVectors( tangents[ 0 ], normal ).normalize();
  23706. normals[ 0 ].crossVectors( tangents[ 0 ], vec );
  23707. binormals[ 0 ].crossVectors( tangents[ 0 ], normals[ 0 ] );
  23708. }
  23709. // compute the slowly-varying normal and binormal vectors for each segment on the path
  23710. for ( i = 1; i < numpoints; i ++ ) {
  23711. normals[ i ] = normals[ i - 1 ].clone();
  23712. binormals[ i ] = binormals[ i - 1 ].clone();
  23713. vec.crossVectors( tangents[ i - 1 ], tangents[ i ] );
  23714. if ( vec.length() > Number.EPSILON ) {
  23715. vec.normalize();
  23716. theta = Math.acos( THREE.Math.clamp( tangents[ i - 1 ].dot( tangents[ i ] ), - 1, 1 ) ); // clamp for floating pt errors
  23717. normals[ i ].applyMatrix4( mat.makeRotationAxis( vec, theta ) );
  23718. }
  23719. binormals[ i ].crossVectors( tangents[ i ], normals[ i ] );
  23720. }
  23721. // if the curve is closed, postprocess the vectors so the first and last normal vectors are the same
  23722. if ( closed ) {
  23723. theta = Math.acos( THREE.Math.clamp( normals[ 0 ].dot( normals[ numpoints - 1 ] ), - 1, 1 ) );
  23724. theta /= ( numpoints - 1 );
  23725. if ( tangents[ 0 ].dot( vec.crossVectors( normals[ 0 ], normals[ numpoints - 1 ] ) ) > 0 ) {
  23726. theta = - theta;
  23727. }
  23728. for ( i = 1; i < numpoints; i ++ ) {
  23729. // twist a little...
  23730. normals[ i ].applyMatrix4( mat.makeRotationAxis( tangents[ i ], theta * i ) );
  23731. binormals[ i ].crossVectors( tangents[ i ], normals[ i ] );
  23732. }
  23733. }
  23734. };
  23735. // File:src/extras/geometries/PolyhedronGeometry.js
  23736. /**
  23737. * @author clockworkgeek / https://github.com/clockworkgeek
  23738. * @author timothypratley / https://github.com/timothypratley
  23739. * @author WestLangley / http://github.com/WestLangley
  23740. */
  23741. THREE.PolyhedronGeometry = function ( vertices, indices, radius, detail ) {
  23742. THREE.Geometry.call( this );
  23743. this.type = 'PolyhedronGeometry';
  23744. this.parameters = {
  23745. vertices: vertices,
  23746. indices: indices,
  23747. radius: radius,
  23748. detail: detail
  23749. };
  23750. radius = radius || 1;
  23751. detail = detail || 0;
  23752. var that = this;
  23753. for ( var i = 0, l = vertices.length; i < l; i += 3 ) {
  23754. prepare( new THREE.Vector3( vertices[ i ], vertices[ i + 1 ], vertices[ i + 2 ] ) );
  23755. }
  23756. var p = this.vertices;
  23757. var faces = [];
  23758. for ( var i = 0, j = 0, l = indices.length; i < l; i += 3, j ++ ) {
  23759. var v1 = p[ indices[ i ] ];
  23760. var v2 = p[ indices[ i + 1 ] ];
  23761. var v3 = p[ indices[ i + 2 ] ];
  23762. faces[ j ] = new THREE.Face3( v1.index, v2.index, v3.index, [ v1.clone(), v2.clone(), v3.clone() ] );
  23763. }
  23764. var centroid = new THREE.Vector3();
  23765. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  23766. subdivide( faces[ i ], detail );
  23767. }
  23768. // Handle case when face straddles the seam
  23769. for ( var i = 0, l = this.faceVertexUvs[ 0 ].length; i < l; i ++ ) {
  23770. var uvs = this.faceVertexUvs[ 0 ][ i ];
  23771. var x0 = uvs[ 0 ].x;
  23772. var x1 = uvs[ 1 ].x;
  23773. var x2 = uvs[ 2 ].x;
  23774. var max = Math.max( x0, x1, x2 );
  23775. var min = Math.min( x0, x1, x2 );
  23776. if ( max > 0.9 && min < 0.1 ) {
  23777. // 0.9 is somewhat arbitrary
  23778. if ( x0 < 0.2 ) uvs[ 0 ].x += 1;
  23779. if ( x1 < 0.2 ) uvs[ 1 ].x += 1;
  23780. if ( x2 < 0.2 ) uvs[ 2 ].x += 1;
  23781. }
  23782. }
  23783. // Apply radius
  23784. for ( var i = 0, l = this.vertices.length; i < l; i ++ ) {
  23785. this.vertices[ i ].multiplyScalar( radius );
  23786. }
  23787. // Merge vertices
  23788. this.mergeVertices();
  23789. this.computeFaceNormals();
  23790. this.boundingSphere = new THREE.Sphere( new THREE.Vector3(), radius );
  23791. // Project vector onto sphere's surface
  23792. function prepare( vector ) {
  23793. var vertex = vector.normalize().clone();
  23794. vertex.index = that.vertices.push( vertex ) - 1;
  23795. // Texture coords are equivalent to map coords, calculate angle and convert to fraction of a circle.
  23796. var u = azimuth( vector ) / 2 / Math.PI + 0.5;
  23797. var v = inclination( vector ) / Math.PI + 0.5;
  23798. vertex.uv = new THREE.Vector2( u, 1 - v );
  23799. return vertex;
  23800. }
  23801. // Approximate a curved face with recursively sub-divided triangles.
  23802. function make( v1, v2, v3 ) {
  23803. var face = new THREE.Face3( v1.index, v2.index, v3.index, [ v1.clone(), v2.clone(), v3.clone() ] );
  23804. that.faces.push( face );
  23805. centroid.copy( v1 ).add( v2 ).add( v3 ).divideScalar( 3 );
  23806. var azi = azimuth( centroid );
  23807. that.faceVertexUvs[ 0 ].push( [
  23808. correctUV( v1.uv, v1, azi ),
  23809. correctUV( v2.uv, v2, azi ),
  23810. correctUV( v3.uv, v3, azi )
  23811. ] );
  23812. }
  23813. // Analytically subdivide a face to the required detail level.
  23814. function subdivide( face, detail ) {
  23815. var cols = Math.pow( 2, detail );
  23816. var a = prepare( that.vertices[ face.a ] );
  23817. var b = prepare( that.vertices[ face.b ] );
  23818. var c = prepare( that.vertices[ face.c ] );
  23819. var v = [];
  23820. // Construct all of the vertices for this subdivision.
  23821. for ( var i = 0 ; i <= cols; i ++ ) {
  23822. v[ i ] = [];
  23823. var aj = prepare( a.clone().lerp( c, i / cols ) );
  23824. var bj = prepare( b.clone().lerp( c, i / cols ) );
  23825. var rows = cols - i;
  23826. for ( var j = 0; j <= rows; j ++ ) {
  23827. if ( j === 0 && i === cols ) {
  23828. v[ i ][ j ] = aj;
  23829. } else {
  23830. v[ i ][ j ] = prepare( aj.clone().lerp( bj, j / rows ) );
  23831. }
  23832. }
  23833. }
  23834. // Construct all of the faces.
  23835. for ( var i = 0; i < cols ; i ++ ) {
  23836. for ( var j = 0; j < 2 * ( cols - i ) - 1; j ++ ) {
  23837. var k = Math.floor( j / 2 );
  23838. if ( j % 2 === 0 ) {
  23839. make(
  23840. v[ i ][ k + 1 ],
  23841. v[ i + 1 ][ k ],
  23842. v[ i ][ k ]
  23843. );
  23844. } else {
  23845. make(
  23846. v[ i ][ k + 1 ],
  23847. v[ i + 1 ][ k + 1 ],
  23848. v[ i + 1 ][ k ]
  23849. );
  23850. }
  23851. }
  23852. }
  23853. }
  23854. // Angle around the Y axis, counter-clockwise when looking from above.
  23855. function azimuth( vector ) {
  23856. return Math.atan2( vector.z, - vector.x );
  23857. }
  23858. // Angle above the XZ plane.
  23859. function inclination( vector ) {
  23860. return Math.atan2( - vector.y, Math.sqrt( ( vector.x * vector.x ) + ( vector.z * vector.z ) ) );
  23861. }
  23862. // Texture fixing helper. Spheres have some odd behaviours.
  23863. function correctUV( uv, vector, azimuth ) {
  23864. if ( ( azimuth < 0 ) && ( uv.x === 1 ) ) uv = new THREE.Vector2( uv.x - 1, uv.y );
  23865. if ( ( vector.x === 0 ) && ( vector.z === 0 ) ) uv = new THREE.Vector2( azimuth / 2 / Math.PI + 0.5, uv.y );
  23866. return uv.clone();
  23867. }
  23868. };
  23869. THREE.PolyhedronGeometry.prototype = Object.create( THREE.Geometry.prototype );
  23870. THREE.PolyhedronGeometry.prototype.constructor = THREE.PolyhedronGeometry;
  23871. // File:src/extras/geometries/DodecahedronGeometry.js
  23872. /**
  23873. * @author Abe Pazos / https://hamoid.com
  23874. */
  23875. THREE.DodecahedronGeometry = function ( radius, detail ) {
  23876. var t = ( 1 + Math.sqrt( 5 ) ) / 2;
  23877. var r = 1 / t;
  23878. var vertices = [
  23879. // (±1, ±1, ±1)
  23880. - 1, - 1, - 1, - 1, - 1, 1,
  23881. - 1, 1, - 1, - 1, 1, 1,
  23882. 1, - 1, - 1, 1, - 1, 1,
  23883. 1, 1, - 1, 1, 1, 1,
  23884. // (0, ±1/φ, ±φ)
  23885. 0, - r, - t, 0, - r, t,
  23886. 0, r, - t, 0, r, t,
  23887. // (±1/φ, ±φ, 0)
  23888. - r, - t, 0, - r, t, 0,
  23889. r, - t, 0, r, t, 0,
  23890. // (±φ, 0, ±1/φ)
  23891. - t, 0, - r, t, 0, - r,
  23892. - t, 0, r, t, 0, r
  23893. ];
  23894. var indices = [
  23895. 3, 11, 7, 3, 7, 15, 3, 15, 13,
  23896. 7, 19, 17, 7, 17, 6, 7, 6, 15,
  23897. 17, 4, 8, 17, 8, 10, 17, 10, 6,
  23898. 8, 0, 16, 8, 16, 2, 8, 2, 10,
  23899. 0, 12, 1, 0, 1, 18, 0, 18, 16,
  23900. 6, 10, 2, 6, 2, 13, 6, 13, 15,
  23901. 2, 16, 18, 2, 18, 3, 2, 3, 13,
  23902. 18, 1, 9, 18, 9, 11, 18, 11, 3,
  23903. 4, 14, 12, 4, 12, 0, 4, 0, 8,
  23904. 11, 9, 5, 11, 5, 19, 11, 19, 7,
  23905. 19, 5, 14, 19, 14, 4, 19, 4, 17,
  23906. 1, 12, 14, 1, 14, 5, 1, 5, 9
  23907. ];
  23908. THREE.PolyhedronGeometry.call( this, vertices, indices, radius, detail );
  23909. this.type = 'DodecahedronGeometry';
  23910. this.parameters = {
  23911. radius: radius,
  23912. detail: detail
  23913. };
  23914. };
  23915. THREE.DodecahedronGeometry.prototype = Object.create( THREE.PolyhedronGeometry.prototype );
  23916. THREE.DodecahedronGeometry.prototype.constructor = THREE.DodecahedronGeometry;
  23917. // File:src/extras/geometries/IcosahedronGeometry.js
  23918. /**
  23919. * @author timothypratley / https://github.com/timothypratley
  23920. */
  23921. THREE.IcosahedronGeometry = function ( radius, detail ) {
  23922. var t = ( 1 + Math.sqrt( 5 ) ) / 2;
  23923. var vertices = [
  23924. - 1, t, 0, 1, t, 0, - 1, - t, 0, 1, - t, 0,
  23925. 0, - 1, t, 0, 1, t, 0, - 1, - t, 0, 1, - t,
  23926. t, 0, - 1, t, 0, 1, - t, 0, - 1, - t, 0, 1
  23927. ];
  23928. var indices = [
  23929. 0, 11, 5, 0, 5, 1, 0, 1, 7, 0, 7, 10, 0, 10, 11,
  23930. 1, 5, 9, 5, 11, 4, 11, 10, 2, 10, 7, 6, 7, 1, 8,
  23931. 3, 9, 4, 3, 4, 2, 3, 2, 6, 3, 6, 8, 3, 8, 9,
  23932. 4, 9, 5, 2, 4, 11, 6, 2, 10, 8, 6, 7, 9, 8, 1
  23933. ];
  23934. THREE.PolyhedronGeometry.call( this, vertices, indices, radius, detail );
  23935. this.type = 'IcosahedronGeometry';
  23936. this.parameters = {
  23937. radius: radius,
  23938. detail: detail
  23939. };
  23940. };
  23941. THREE.IcosahedronGeometry.prototype = Object.create( THREE.PolyhedronGeometry.prototype );
  23942. THREE.IcosahedronGeometry.prototype.constructor = THREE.IcosahedronGeometry;
  23943. // File:src/extras/geometries/OctahedronGeometry.js
  23944. /**
  23945. * @author timothypratley / https://github.com/timothypratley
  23946. */
  23947. THREE.OctahedronGeometry = function ( radius, detail ) {
  23948. var vertices = [
  23949. 1, 0, 0, - 1, 0, 0, 0, 1, 0, 0, - 1, 0, 0, 0, 1, 0, 0, - 1
  23950. ];
  23951. var indices = [
  23952. 0, 2, 4, 0, 4, 3, 0, 3, 5, 0, 5, 2, 1, 2, 5, 1, 5, 3, 1, 3, 4, 1, 4, 2
  23953. ];
  23954. THREE.PolyhedronGeometry.call( this, vertices, indices, radius, detail );
  23955. this.type = 'OctahedronGeometry';
  23956. this.parameters = {
  23957. radius: radius,
  23958. detail: detail
  23959. };
  23960. };
  23961. THREE.OctahedronGeometry.prototype = Object.create( THREE.PolyhedronGeometry.prototype );
  23962. THREE.OctahedronGeometry.prototype.constructor = THREE.OctahedronGeometry;
  23963. // File:src/extras/geometries/TetrahedronGeometry.js
  23964. /**
  23965. * @author timothypratley / https://github.com/timothypratley
  23966. */
  23967. THREE.TetrahedronGeometry = function ( radius, detail ) {
  23968. var vertices = [
  23969. 1, 1, 1, - 1, - 1, 1, - 1, 1, - 1, 1, - 1, - 1
  23970. ];
  23971. var indices = [
  23972. 2, 1, 0, 0, 3, 2, 1, 3, 0, 2, 3, 1
  23973. ];
  23974. THREE.PolyhedronGeometry.call( this, vertices, indices, radius, detail );
  23975. this.type = 'TetrahedronGeometry';
  23976. this.parameters = {
  23977. radius: radius,
  23978. detail: detail
  23979. };
  23980. };
  23981. THREE.TetrahedronGeometry.prototype = Object.create( THREE.PolyhedronGeometry.prototype );
  23982. THREE.TetrahedronGeometry.prototype.constructor = THREE.TetrahedronGeometry;
  23983. // File:src/extras/geometries/ParametricGeometry.js
  23984. /**
  23985. * @author zz85 / https://github.com/zz85
  23986. * Parametric Surfaces Geometry
  23987. * based on the brilliant article by @prideout http://prideout.net/blog/?p=44
  23988. *
  23989. * new THREE.ParametricGeometry( parametricFunction, uSegments, ySegements );
  23990. *
  23991. */
  23992. THREE.ParametricGeometry = function ( func, slices, stacks ) {
  23993. THREE.Geometry.call( this );
  23994. this.type = 'ParametricGeometry';
  23995. this.parameters = {
  23996. func: func,
  23997. slices: slices,
  23998. stacks: stacks
  23999. };
  24000. var verts = this.vertices;
  24001. var faces = this.faces;
  24002. var uvs = this.faceVertexUvs[ 0 ];
  24003. var i, j, p;
  24004. var u, v;
  24005. var sliceCount = slices + 1;
  24006. for ( i = 0; i <= stacks; i ++ ) {
  24007. v = i / stacks;
  24008. for ( j = 0; j <= slices; j ++ ) {
  24009. u = j / slices;
  24010. p = func( u, v );
  24011. verts.push( p );
  24012. }
  24013. }
  24014. var a, b, c, d;
  24015. var uva, uvb, uvc, uvd;
  24016. for ( i = 0; i < stacks; i ++ ) {
  24017. for ( j = 0; j < slices; j ++ ) {
  24018. a = i * sliceCount + j;
  24019. b = i * sliceCount + j + 1;
  24020. c = ( i + 1 ) * sliceCount + j + 1;
  24021. d = ( i + 1 ) * sliceCount + j;
  24022. uva = new THREE.Vector2( j / slices, i / stacks );
  24023. uvb = new THREE.Vector2( ( j + 1 ) / slices, i / stacks );
  24024. uvc = new THREE.Vector2( ( j + 1 ) / slices, ( i + 1 ) / stacks );
  24025. uvd = new THREE.Vector2( j / slices, ( i + 1 ) / stacks );
  24026. faces.push( new THREE.Face3( a, b, d ) );
  24027. uvs.push( [ uva, uvb, uvd ] );
  24028. faces.push( new THREE.Face3( b, c, d ) );
  24029. uvs.push( [ uvb.clone(), uvc, uvd.clone() ] );
  24030. }
  24031. }
  24032. // console.log(this);
  24033. // magic bullet
  24034. // var diff = this.mergeVertices();
  24035. // console.log('removed ', diff, ' vertices by merging');
  24036. this.computeFaceNormals();
  24037. this.computeVertexNormals();
  24038. };
  24039. THREE.ParametricGeometry.prototype = Object.create( THREE.Geometry.prototype );
  24040. THREE.ParametricGeometry.prototype.constructor = THREE.ParametricGeometry;
  24041. // File:src/extras/geometries/WireframeGeometry.js
  24042. /**
  24043. * @author mrdoob / http://mrdoob.com/
  24044. */
  24045. THREE.WireframeGeometry = function ( geometry ) {
  24046. THREE.BufferGeometry.call( this );
  24047. var edge = [ 0, 0 ], hash = {};
  24048. function sortFunction( a, b ) {
  24049. return a - b;
  24050. }
  24051. var keys = [ 'a', 'b', 'c' ];
  24052. if ( geometry instanceof THREE.Geometry ) {
  24053. var vertices = geometry.vertices;
  24054. var faces = geometry.faces;
  24055. var numEdges = 0;
  24056. // allocate maximal size
  24057. var edges = new Uint32Array( 6 * faces.length );
  24058. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  24059. var face = faces[ i ];
  24060. for ( var j = 0; j < 3; j ++ ) {
  24061. edge[ 0 ] = face[ keys[ j ] ];
  24062. edge[ 1 ] = face[ keys[ ( j + 1 ) % 3 ] ];
  24063. edge.sort( sortFunction );
  24064. var key = edge.toString();
  24065. if ( hash[ key ] === undefined ) {
  24066. edges[ 2 * numEdges ] = edge[ 0 ];
  24067. edges[ 2 * numEdges + 1 ] = edge[ 1 ];
  24068. hash[ key ] = true;
  24069. numEdges ++;
  24070. }
  24071. }
  24072. }
  24073. var coords = new Float32Array( numEdges * 2 * 3 );
  24074. for ( var i = 0, l = numEdges; i < l; i ++ ) {
  24075. for ( var j = 0; j < 2; j ++ ) {
  24076. var vertex = vertices[ edges [ 2 * i + j ] ];
  24077. var index = 6 * i + 3 * j;
  24078. coords[ index + 0 ] = vertex.x;
  24079. coords[ index + 1 ] = vertex.y;
  24080. coords[ index + 2 ] = vertex.z;
  24081. }
  24082. }
  24083. this.addAttribute( 'position', new THREE.BufferAttribute( coords, 3 ) );
  24084. } else if ( geometry instanceof THREE.BufferGeometry ) {
  24085. if ( geometry.index !== null ) {
  24086. // Indexed BufferGeometry
  24087. var indices = geometry.index.array;
  24088. var vertices = geometry.attributes.position;
  24089. var groups = geometry.groups;
  24090. var numEdges = 0;
  24091. if ( groups.length === 0 ) {
  24092. geometry.addGroup( 0, indices.length );
  24093. }
  24094. // allocate maximal size
  24095. var edges = new Uint32Array( 2 * indices.length );
  24096. for ( var o = 0, ol = groups.length; o < ol; ++ o ) {
  24097. var group = groups[ o ];
  24098. var start = group.start;
  24099. var count = group.count;
  24100. for ( var i = start, il = start + count; i < il; i += 3 ) {
  24101. for ( var j = 0; j < 3; j ++ ) {
  24102. edge[ 0 ] = indices[ i + j ];
  24103. edge[ 1 ] = indices[ i + ( j + 1 ) % 3 ];
  24104. edge.sort( sortFunction );
  24105. var key = edge.toString();
  24106. if ( hash[ key ] === undefined ) {
  24107. edges[ 2 * numEdges ] = edge[ 0 ];
  24108. edges[ 2 * numEdges + 1 ] = edge[ 1 ];
  24109. hash[ key ] = true;
  24110. numEdges ++;
  24111. }
  24112. }
  24113. }
  24114. }
  24115. var coords = new Float32Array( numEdges * 2 * 3 );
  24116. for ( var i = 0, l = numEdges; i < l; i ++ ) {
  24117. for ( var j = 0; j < 2; j ++ ) {
  24118. var index = 6 * i + 3 * j;
  24119. var index2 = edges[ 2 * i + j ];
  24120. coords[ index + 0 ] = vertices.getX( index2 );
  24121. coords[ index + 1 ] = vertices.getY( index2 );
  24122. coords[ index + 2 ] = vertices.getZ( index2 );
  24123. }
  24124. }
  24125. this.addAttribute( 'position', new THREE.BufferAttribute( coords, 3 ) );
  24126. } else {
  24127. // non-indexed BufferGeometry
  24128. var vertices = geometry.attributes.position.array;
  24129. var numEdges = vertices.length / 3;
  24130. var numTris = numEdges / 3;
  24131. var coords = new Float32Array( numEdges * 2 * 3 );
  24132. for ( var i = 0, l = numTris; i < l; i ++ ) {
  24133. for ( var j = 0; j < 3; j ++ ) {
  24134. var index = 18 * i + 6 * j;
  24135. var index1 = 9 * i + 3 * j;
  24136. coords[ index + 0 ] = vertices[ index1 ];
  24137. coords[ index + 1 ] = vertices[ index1 + 1 ];
  24138. coords[ index + 2 ] = vertices[ index1 + 2 ];
  24139. var index2 = 9 * i + 3 * ( ( j + 1 ) % 3 );
  24140. coords[ index + 3 ] = vertices[ index2 ];
  24141. coords[ index + 4 ] = vertices[ index2 + 1 ];
  24142. coords[ index + 5 ] = vertices[ index2 + 2 ];
  24143. }
  24144. }
  24145. this.addAttribute( 'position', new THREE.BufferAttribute( coords, 3 ) );
  24146. }
  24147. }
  24148. };
  24149. THREE.WireframeGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  24150. THREE.WireframeGeometry.prototype.constructor = THREE.WireframeGeometry;
  24151. // File:src/extras/helpers/AxisHelper.js
  24152. /**
  24153. * @author sroucheray / http://sroucheray.org/
  24154. * @author mrdoob / http://mrdoob.com/
  24155. */
  24156. THREE.AxisHelper = function ( size ) {
  24157. size = size || 1;
  24158. var vertices = new Float32Array( [
  24159. 0, 0, 0, size, 0, 0,
  24160. 0, 0, 0, 0, size, 0,
  24161. 0, 0, 0, 0, 0, size
  24162. ] );
  24163. var colors = new Float32Array( [
  24164. 1, 0, 0, 1, 0.6, 0,
  24165. 0, 1, 0, 0.6, 1, 0,
  24166. 0, 0, 1, 0, 0.6, 1
  24167. ] );
  24168. var geometry = new THREE.BufferGeometry();
  24169. geometry.addAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) );
  24170. geometry.addAttribute( 'color', new THREE.BufferAttribute( colors, 3 ) );
  24171. var material = new THREE.LineBasicMaterial( { vertexColors: THREE.VertexColors } );
  24172. THREE.LineSegments.call( this, geometry, material );
  24173. };
  24174. THREE.AxisHelper.prototype = Object.create( THREE.LineSegments.prototype );
  24175. THREE.AxisHelper.prototype.constructor = THREE.AxisHelper;
  24176. // File:src/extras/helpers/ArrowHelper.js
  24177. /**
  24178. * @author WestLangley / http://github.com/WestLangley
  24179. * @author zz85 / http://github.com/zz85
  24180. * @author bhouston / http://clara.io
  24181. *
  24182. * Creates an arrow for visualizing directions
  24183. *
  24184. * Parameters:
  24185. * dir - Vector3
  24186. * origin - Vector3
  24187. * length - Number
  24188. * color - color in hex value
  24189. * headLength - Number
  24190. * headWidth - Number
  24191. */
  24192. THREE.ArrowHelper = ( function () {
  24193. var lineGeometry = new THREE.BufferGeometry();
  24194. lineGeometry.addAttribute( 'position', new THREE.Float32Attribute( [ 0, 0, 0, 0, 1, 0 ], 3 ) );
  24195. var coneGeometry = new THREE.CylinderBufferGeometry( 0, 0.5, 1, 5, 1 );
  24196. coneGeometry.translate( 0, - 0.5, 0 );
  24197. return function ArrowHelper( dir, origin, length, color, headLength, headWidth ) {
  24198. // dir is assumed to be normalized
  24199. THREE.Object3D.call( this );
  24200. if ( color === undefined ) color = 0xffff00;
  24201. if ( length === undefined ) length = 1;
  24202. if ( headLength === undefined ) headLength = 0.2 * length;
  24203. if ( headWidth === undefined ) headWidth = 0.2 * headLength;
  24204. this.position.copy( origin );
  24205. this.line = new THREE.Line( lineGeometry, new THREE.LineBasicMaterial( { color: color } ) );
  24206. this.line.matrixAutoUpdate = false;
  24207. this.add( this.line );
  24208. this.cone = new THREE.Mesh( coneGeometry, new THREE.MeshBasicMaterial( { color: color } ) );
  24209. this.cone.matrixAutoUpdate = false;
  24210. this.add( this.cone );
  24211. this.setDirection( dir );
  24212. this.setLength( length, headLength, headWidth );
  24213. };
  24214. }() );
  24215. THREE.ArrowHelper.prototype = Object.create( THREE.Object3D.prototype );
  24216. THREE.ArrowHelper.prototype.constructor = THREE.ArrowHelper;
  24217. THREE.ArrowHelper.prototype.setDirection = ( function () {
  24218. var axis = new THREE.Vector3();
  24219. var radians;
  24220. return function setDirection( dir ) {
  24221. // dir is assumed to be normalized
  24222. if ( dir.y > 0.99999 ) {
  24223. this.quaternion.set( 0, 0, 0, 1 );
  24224. } else if ( dir.y < - 0.99999 ) {
  24225. this.quaternion.set( 1, 0, 0, 0 );
  24226. } else {
  24227. axis.set( dir.z, 0, - dir.x ).normalize();
  24228. radians = Math.acos( dir.y );
  24229. this.quaternion.setFromAxisAngle( axis, radians );
  24230. }
  24231. };
  24232. }() );
  24233. THREE.ArrowHelper.prototype.setLength = function ( length, headLength, headWidth ) {
  24234. if ( headLength === undefined ) headLength = 0.2 * length;
  24235. if ( headWidth === undefined ) headWidth = 0.2 * headLength;
  24236. this.line.scale.set( 1, Math.max( 0, length - headLength ), 1 );
  24237. this.line.updateMatrix();
  24238. this.cone.scale.set( headWidth, headLength, headWidth );
  24239. this.cone.position.y = length;
  24240. this.cone.updateMatrix();
  24241. };
  24242. THREE.ArrowHelper.prototype.setColor = function ( color ) {
  24243. this.line.material.color.copy( color );
  24244. this.cone.material.color.copy( color );
  24245. };
  24246. // File:src/extras/helpers/BoxHelper.js
  24247. /**
  24248. * @author mrdoob / http://mrdoob.com/
  24249. */
  24250. THREE.BoxHelper = function ( object, color ) {
  24251. if ( color === undefined ) color = 0xffff00;
  24252. var indices = new Uint16Array( [ 0, 1, 1, 2, 2, 3, 3, 0, 4, 5, 5, 6, 6, 7, 7, 4, 0, 4, 1, 5, 2, 6, 3, 7 ] );
  24253. var positions = new Float32Array( 8 * 3 );
  24254. var geometry = new THREE.BufferGeometry();
  24255. geometry.setIndex( new THREE.BufferAttribute( indices, 1 ) );
  24256. geometry.addAttribute( 'position', new THREE.BufferAttribute( positions, 3 ) );
  24257. THREE.LineSegments.call( this, geometry, new THREE.LineBasicMaterial( { color: color } ) );
  24258. if ( object !== undefined ) {
  24259. this.update( object );
  24260. }
  24261. };
  24262. THREE.BoxHelper.prototype = Object.create( THREE.LineSegments.prototype );
  24263. THREE.BoxHelper.prototype.constructor = THREE.BoxHelper;
  24264. THREE.BoxHelper.prototype.update = ( function () {
  24265. var box = new THREE.Box3();
  24266. return function update( object ) {
  24267. if ( object instanceof THREE.Box3 ) {
  24268. box.copy( object );
  24269. } else {
  24270. box.setFromObject( object );
  24271. }
  24272. if ( box.isEmpty() ) return;
  24273. var min = box.min;
  24274. var max = box.max;
  24275. /*
  24276. 5____4
  24277. 1/___0/|
  24278. | 6__|_7
  24279. 2/___3/
  24280. 0: max.x, max.y, max.z
  24281. 1: min.x, max.y, max.z
  24282. 2: min.x, min.y, max.z
  24283. 3: max.x, min.y, max.z
  24284. 4: max.x, max.y, min.z
  24285. 5: min.x, max.y, min.z
  24286. 6: min.x, min.y, min.z
  24287. 7: max.x, min.y, min.z
  24288. */
  24289. var position = this.geometry.attributes.position;
  24290. var array = position.array;
  24291. array[ 0 ] = max.x; array[ 1 ] = max.y; array[ 2 ] = max.z;
  24292. array[ 3 ] = min.x; array[ 4 ] = max.y; array[ 5 ] = max.z;
  24293. array[ 6 ] = min.x; array[ 7 ] = min.y; array[ 8 ] = max.z;
  24294. array[ 9 ] = max.x; array[ 10 ] = min.y; array[ 11 ] = max.z;
  24295. array[ 12 ] = max.x; array[ 13 ] = max.y; array[ 14 ] = min.z;
  24296. array[ 15 ] = min.x; array[ 16 ] = max.y; array[ 17 ] = min.z;
  24297. array[ 18 ] = min.x; array[ 19 ] = min.y; array[ 20 ] = min.z;
  24298. array[ 21 ] = max.x; array[ 22 ] = min.y; array[ 23 ] = min.z;
  24299. position.needsUpdate = true;
  24300. this.geometry.computeBoundingSphere();
  24301. };
  24302. } )();
  24303. // File:src/extras/helpers/BoundingBoxHelper.js
  24304. /**
  24305. * @author WestLangley / http://github.com/WestLangley
  24306. */
  24307. // a helper to show the world-axis-aligned bounding box for an object
  24308. THREE.BoundingBoxHelper = function ( object, hex ) {
  24309. var color = ( hex !== undefined ) ? hex : 0x888888;
  24310. this.object = object;
  24311. this.box = new THREE.Box3();
  24312. THREE.Mesh.call( this, new THREE.BoxGeometry( 1, 1, 1 ), new THREE.MeshBasicMaterial( { color: color, wireframe: true } ) );
  24313. };
  24314. THREE.BoundingBoxHelper.prototype = Object.create( THREE.Mesh.prototype );
  24315. THREE.BoundingBoxHelper.prototype.constructor = THREE.BoundingBoxHelper;
  24316. THREE.BoundingBoxHelper.prototype.update = function () {
  24317. this.box.setFromObject( this.object );
  24318. this.box.size( this.scale );
  24319. this.box.center( this.position );
  24320. };
  24321. // File:src/extras/helpers/CameraHelper.js
  24322. /**
  24323. * @author alteredq / http://alteredqualia.com/
  24324. *
  24325. * - shows frustum, line of sight and up of the camera
  24326. * - suitable for fast updates
  24327. * - based on frustum visualization in lightgl.js shadowmap example
  24328. * http://evanw.github.com/lightgl.js/tests/shadowmap.html
  24329. */
  24330. THREE.CameraHelper = function ( camera ) {
  24331. var geometry = new THREE.Geometry();
  24332. var material = new THREE.LineBasicMaterial( { color: 0xffffff, vertexColors: THREE.FaceColors } );
  24333. var pointMap = {};
  24334. // colors
  24335. var hexFrustum = 0xffaa00;
  24336. var hexCone = 0xff0000;
  24337. var hexUp = 0x00aaff;
  24338. var hexTarget = 0xffffff;
  24339. var hexCross = 0x333333;
  24340. // near
  24341. addLine( "n1", "n2", hexFrustum );
  24342. addLine( "n2", "n4", hexFrustum );
  24343. addLine( "n4", "n3", hexFrustum );
  24344. addLine( "n3", "n1", hexFrustum );
  24345. // far
  24346. addLine( "f1", "f2", hexFrustum );
  24347. addLine( "f2", "f4", hexFrustum );
  24348. addLine( "f4", "f3", hexFrustum );
  24349. addLine( "f3", "f1", hexFrustum );
  24350. // sides
  24351. addLine( "n1", "f1", hexFrustum );
  24352. addLine( "n2", "f2", hexFrustum );
  24353. addLine( "n3", "f3", hexFrustum );
  24354. addLine( "n4", "f4", hexFrustum );
  24355. // cone
  24356. addLine( "p", "n1", hexCone );
  24357. addLine( "p", "n2", hexCone );
  24358. addLine( "p", "n3", hexCone );
  24359. addLine( "p", "n4", hexCone );
  24360. // up
  24361. addLine( "u1", "u2", hexUp );
  24362. addLine( "u2", "u3", hexUp );
  24363. addLine( "u3", "u1", hexUp );
  24364. // target
  24365. addLine( "c", "t", hexTarget );
  24366. addLine( "p", "c", hexCross );
  24367. // cross
  24368. addLine( "cn1", "cn2", hexCross );
  24369. addLine( "cn3", "cn4", hexCross );
  24370. addLine( "cf1", "cf2", hexCross );
  24371. addLine( "cf3", "cf4", hexCross );
  24372. function addLine( a, b, hex ) {
  24373. addPoint( a, hex );
  24374. addPoint( b, hex );
  24375. }
  24376. function addPoint( id, hex ) {
  24377. geometry.vertices.push( new THREE.Vector3() );
  24378. geometry.colors.push( new THREE.Color( hex ) );
  24379. if ( pointMap[ id ] === undefined ) {
  24380. pointMap[ id ] = [];
  24381. }
  24382. pointMap[ id ].push( geometry.vertices.length - 1 );
  24383. }
  24384. THREE.LineSegments.call( this, geometry, material );
  24385. this.camera = camera;
  24386. if( this.camera.updateProjectionMatrix ) this.camera.updateProjectionMatrix();
  24387. this.matrix = camera.matrixWorld;
  24388. this.matrixAutoUpdate = false;
  24389. this.pointMap = pointMap;
  24390. this.update();
  24391. };
  24392. THREE.CameraHelper.prototype = Object.create( THREE.LineSegments.prototype );
  24393. THREE.CameraHelper.prototype.constructor = THREE.CameraHelper;
  24394. THREE.CameraHelper.prototype.update = function () {
  24395. var geometry, pointMap;
  24396. var vector = new THREE.Vector3();
  24397. var camera = new THREE.Camera();
  24398. function setPoint( point, x, y, z ) {
  24399. vector.set( x, y, z ).unproject( camera );
  24400. var points = pointMap[ point ];
  24401. if ( points !== undefined ) {
  24402. for ( var i = 0, il = points.length; i < il; i ++ ) {
  24403. geometry.vertices[ points[ i ] ].copy( vector );
  24404. }
  24405. }
  24406. }
  24407. return function update() {
  24408. geometry = this.geometry;
  24409. pointMap = this.pointMap;
  24410. var w = 1, h = 1;
  24411. // we need just camera projection matrix
  24412. // world matrix must be identity
  24413. camera.projectionMatrix.copy( this.camera.projectionMatrix );
  24414. // center / target
  24415. setPoint( "c", 0, 0, - 1 );
  24416. setPoint( "t", 0, 0, 1 );
  24417. // near
  24418. setPoint( "n1", - w, - h, - 1 );
  24419. setPoint( "n2", w, - h, - 1 );
  24420. setPoint( "n3", - w, h, - 1 );
  24421. setPoint( "n4", w, h, - 1 );
  24422. // far
  24423. setPoint( "f1", - w, - h, 1 );
  24424. setPoint( "f2", w, - h, 1 );
  24425. setPoint( "f3", - w, h, 1 );
  24426. setPoint( "f4", w, h, 1 );
  24427. // up
  24428. setPoint( "u1", w * 0.7, h * 1.1, - 1 );
  24429. setPoint( "u2", - w * 0.7, h * 1.1, - 1 );
  24430. setPoint( "u3", 0, h * 2, - 1 );
  24431. // cross
  24432. setPoint( "cf1", - w, 0, 1 );
  24433. setPoint( "cf2", w, 0, 1 );
  24434. setPoint( "cf3", 0, - h, 1 );
  24435. setPoint( "cf4", 0, h, 1 );
  24436. setPoint( "cn1", - w, 0, - 1 );
  24437. setPoint( "cn2", w, 0, - 1 );
  24438. setPoint( "cn3", 0, - h, - 1 );
  24439. setPoint( "cn4", 0, h, - 1 );
  24440. geometry.verticesNeedUpdate = true;
  24441. };
  24442. }();
  24443. // File:src/extras/helpers/DirectionalLightHelper.js
  24444. /**
  24445. * @author alteredq / http://alteredqualia.com/
  24446. * @author mrdoob / http://mrdoob.com/
  24447. * @author WestLangley / http://github.com/WestLangley
  24448. */
  24449. THREE.DirectionalLightHelper = function ( light, size ) {
  24450. THREE.Object3D.call( this );
  24451. this.light = light;
  24452. this.light.updateMatrixWorld();
  24453. this.matrix = light.matrixWorld;
  24454. this.matrixAutoUpdate = false;
  24455. if ( size === undefined ) size = 1;
  24456. var geometry = new THREE.BufferGeometry();
  24457. geometry.addAttribute( 'position', new THREE.Float32Attribute( [
  24458. - size, size, 0,
  24459. size, size, 0,
  24460. size, - size, 0,
  24461. - size, - size, 0,
  24462. - size, size, 0
  24463. ], 3 ) );
  24464. var material = new THREE.LineBasicMaterial( { fog: false } );
  24465. this.add( new THREE.Line( geometry, material ) );
  24466. geometry = new THREE.BufferGeometry();
  24467. geometry.addAttribute( 'position', new THREE.Float32Attribute( [ 0, 0, 0, 0, 0, 1 ], 3 ) );
  24468. this.add( new THREE.Line( geometry, material ));
  24469. this.update();
  24470. };
  24471. THREE.DirectionalLightHelper.prototype = Object.create( THREE.Object3D.prototype );
  24472. THREE.DirectionalLightHelper.prototype.constructor = THREE.DirectionalLightHelper;
  24473. THREE.DirectionalLightHelper.prototype.dispose = function () {
  24474. var lightPlane = this.children[ 0 ];
  24475. var targetLine = this.children[ 1 ];
  24476. lightPlane.geometry.dispose();
  24477. lightPlane.material.dispose();
  24478. targetLine.geometry.dispose();
  24479. targetLine.material.dispose();
  24480. };
  24481. THREE.DirectionalLightHelper.prototype.update = function () {
  24482. var v1 = new THREE.Vector3();
  24483. var v2 = new THREE.Vector3();
  24484. var v3 = new THREE.Vector3();
  24485. return function update() {
  24486. v1.setFromMatrixPosition( this.light.matrixWorld );
  24487. v2.setFromMatrixPosition( this.light.target.matrixWorld );
  24488. v3.subVectors( v2, v1 );
  24489. var lightPlane = this.children[ 0 ];
  24490. var targetLine = this.children[ 1 ];
  24491. lightPlane.lookAt( v3 );
  24492. lightPlane.material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  24493. targetLine.lookAt( v3 );
  24494. targetLine.scale.z = v3.length();
  24495. };
  24496. }();
  24497. // File:src/extras/helpers/EdgesHelper.js
  24498. /**
  24499. * @author WestLangley / http://github.com/WestLangley
  24500. * @param object THREE.Mesh whose geometry will be used
  24501. * @param hex line color
  24502. * @param thresholdAngle the minimum angle (in degrees),
  24503. * between the face normals of adjacent faces,
  24504. * that is required to render an edge. A value of 10 means
  24505. * an edge is only rendered if the angle is at least 10 degrees.
  24506. */
  24507. THREE.EdgesHelper = function ( object, hex, thresholdAngle ) {
  24508. var color = ( hex !== undefined ) ? hex : 0xffffff;
  24509. THREE.LineSegments.call( this, new THREE.EdgesGeometry( object.geometry, thresholdAngle ), new THREE.LineBasicMaterial( { color: color } ) );
  24510. this.matrix = object.matrixWorld;
  24511. this.matrixAutoUpdate = false;
  24512. };
  24513. THREE.EdgesHelper.prototype = Object.create( THREE.LineSegments.prototype );
  24514. THREE.EdgesHelper.prototype.constructor = THREE.EdgesHelper;
  24515. // File:src/extras/helpers/FaceNormalsHelper.js
  24516. /**
  24517. * @author mrdoob / http://mrdoob.com/
  24518. * @author WestLangley / http://github.com/WestLangley
  24519. */
  24520. THREE.FaceNormalsHelper = function ( object, size, hex, linewidth ) {
  24521. // FaceNormalsHelper only supports THREE.Geometry
  24522. this.object = object;
  24523. this.size = ( size !== undefined ) ? size : 1;
  24524. var color = ( hex !== undefined ) ? hex : 0xffff00;
  24525. var width = ( linewidth !== undefined ) ? linewidth : 1;
  24526. //
  24527. var nNormals = 0;
  24528. var objGeometry = this.object.geometry;
  24529. if ( objGeometry instanceof THREE.Geometry ) {
  24530. nNormals = objGeometry.faces.length;
  24531. } else {
  24532. console.warn( 'THREE.FaceNormalsHelper: only THREE.Geometry is supported. Use THREE.VertexNormalsHelper, instead.' );
  24533. }
  24534. //
  24535. var geometry = new THREE.BufferGeometry();
  24536. var positions = new THREE.Float32Attribute( nNormals * 2 * 3, 3 );
  24537. geometry.addAttribute( 'position', positions );
  24538. THREE.LineSegments.call( this, geometry, new THREE.LineBasicMaterial( { color: color, linewidth: width } ) );
  24539. //
  24540. this.matrixAutoUpdate = false;
  24541. this.update();
  24542. };
  24543. THREE.FaceNormalsHelper.prototype = Object.create( THREE.LineSegments.prototype );
  24544. THREE.FaceNormalsHelper.prototype.constructor = THREE.FaceNormalsHelper;
  24545. THREE.FaceNormalsHelper.prototype.update = ( function () {
  24546. var v1 = new THREE.Vector3();
  24547. var v2 = new THREE.Vector3();
  24548. var normalMatrix = new THREE.Matrix3();
  24549. return function update() {
  24550. this.object.updateMatrixWorld( true );
  24551. normalMatrix.getNormalMatrix( this.object.matrixWorld );
  24552. var matrixWorld = this.object.matrixWorld;
  24553. var position = this.geometry.attributes.position;
  24554. //
  24555. var objGeometry = this.object.geometry;
  24556. var vertices = objGeometry.vertices;
  24557. var faces = objGeometry.faces;
  24558. var idx = 0;
  24559. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  24560. var face = faces[ i ];
  24561. var normal = face.normal;
  24562. v1.copy( vertices[ face.a ] )
  24563. .add( vertices[ face.b ] )
  24564. .add( vertices[ face.c ] )
  24565. .divideScalar( 3 )
  24566. .applyMatrix4( matrixWorld );
  24567. v2.copy( normal ).applyMatrix3( normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
  24568. position.setXYZ( idx, v1.x, v1.y, v1.z );
  24569. idx = idx + 1;
  24570. position.setXYZ( idx, v2.x, v2.y, v2.z );
  24571. idx = idx + 1;
  24572. }
  24573. position.needsUpdate = true;
  24574. return this;
  24575. };
  24576. }() );
  24577. // File:src/extras/helpers/GridHelper.js
  24578. /**
  24579. * @author mrdoob / http://mrdoob.com/
  24580. */
  24581. THREE.GridHelper = function ( size, divisions, color1, color2 ) {
  24582. divisions = divisions || 1;
  24583. color1 = new THREE.Color( color1 !== undefined ? color1 : 0x444444 );
  24584. color2 = new THREE.Color( color2 !== undefined ? color2 : 0x888888 );
  24585. var center = divisions / 2;
  24586. var step = ( size * 2 ) / divisions;
  24587. var vertices = [], colors = [];
  24588. for ( var i = 0, j = 0, k = - size; i <= divisions; i ++, k += step ) {
  24589. vertices.push( - size, 0, k, size, 0, k );
  24590. vertices.push( k, 0, - size, k, 0, size );
  24591. var color = i === center ? color1 : color2;
  24592. color.toArray( colors, j ); j += 3;
  24593. color.toArray( colors, j ); j += 3;
  24594. color.toArray( colors, j ); j += 3;
  24595. color.toArray( colors, j ); j += 3;
  24596. }
  24597. var geometry = new THREE.BufferGeometry();
  24598. geometry.addAttribute( 'position', new THREE.Float32Attribute( vertices, 3 ) );
  24599. geometry.addAttribute( 'color', new THREE.Float32Attribute( colors, 3 ) );
  24600. var material = new THREE.LineBasicMaterial( { vertexColors: THREE.VertexColors } );
  24601. THREE.LineSegments.call( this, geometry, material );
  24602. };
  24603. THREE.GridHelper.prototype = Object.create( THREE.LineSegments.prototype );
  24604. THREE.GridHelper.prototype.constructor = THREE.GridHelper;
  24605. THREE.GridHelper.prototype.setColors = function () {
  24606. console.error( 'THREE.GridHelper: setColors() has been deprecated, pass them in the constructor instead.' );
  24607. };
  24608. // File:src/extras/helpers/HemisphereLightHelper.js
  24609. /**
  24610. * @author alteredq / http://alteredqualia.com/
  24611. * @author mrdoob / http://mrdoob.com/
  24612. */
  24613. THREE.HemisphereLightHelper = function ( light, sphereSize ) {
  24614. THREE.Object3D.call( this );
  24615. this.light = light;
  24616. this.light.updateMatrixWorld();
  24617. this.matrix = light.matrixWorld;
  24618. this.matrixAutoUpdate = false;
  24619. this.colors = [ new THREE.Color(), new THREE.Color() ];
  24620. var geometry = new THREE.SphereGeometry( sphereSize, 4, 2 );
  24621. geometry.rotateX( - Math.PI / 2 );
  24622. for ( var i = 0, il = 8; i < il; i ++ ) {
  24623. geometry.faces[ i ].color = this.colors[ i < 4 ? 0 : 1 ];
  24624. }
  24625. var material = new THREE.MeshBasicMaterial( { vertexColors: THREE.FaceColors, wireframe: true } );
  24626. this.lightSphere = new THREE.Mesh( geometry, material );
  24627. this.add( this.lightSphere );
  24628. this.update();
  24629. };
  24630. THREE.HemisphereLightHelper.prototype = Object.create( THREE.Object3D.prototype );
  24631. THREE.HemisphereLightHelper.prototype.constructor = THREE.HemisphereLightHelper;
  24632. THREE.HemisphereLightHelper.prototype.dispose = function () {
  24633. this.lightSphere.geometry.dispose();
  24634. this.lightSphere.material.dispose();
  24635. };
  24636. THREE.HemisphereLightHelper.prototype.update = function () {
  24637. var vector = new THREE.Vector3();
  24638. return function update() {
  24639. this.colors[ 0 ].copy( this.light.color ).multiplyScalar( this.light.intensity );
  24640. this.colors[ 1 ].copy( this.light.groundColor ).multiplyScalar( this.light.intensity );
  24641. this.lightSphere.lookAt( vector.setFromMatrixPosition( this.light.matrixWorld ).negate() );
  24642. this.lightSphere.geometry.colorsNeedUpdate = true;
  24643. };
  24644. }();
  24645. // File:src/extras/helpers/PointLightHelper.js
  24646. /**
  24647. * @author alteredq / http://alteredqualia.com/
  24648. * @author mrdoob / http://mrdoob.com/
  24649. */
  24650. THREE.PointLightHelper = function ( light, sphereSize ) {
  24651. this.light = light;
  24652. this.light.updateMatrixWorld();
  24653. var geometry = new THREE.SphereBufferGeometry( sphereSize, 4, 2 );
  24654. var material = new THREE.MeshBasicMaterial( { wireframe: true, fog: false } );
  24655. material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  24656. THREE.Mesh.call( this, geometry, material );
  24657. this.matrix = this.light.matrixWorld;
  24658. this.matrixAutoUpdate = false;
  24659. /*
  24660. var distanceGeometry = new THREE.IcosahedronGeometry( 1, 2 );
  24661. var distanceMaterial = new THREE.MeshBasicMaterial( { color: hexColor, fog: false, wireframe: true, opacity: 0.1, transparent: true } );
  24662. this.lightSphere = new THREE.Mesh( bulbGeometry, bulbMaterial );
  24663. this.lightDistance = new THREE.Mesh( distanceGeometry, distanceMaterial );
  24664. var d = light.distance;
  24665. if ( d === 0.0 ) {
  24666. this.lightDistance.visible = false;
  24667. } else {
  24668. this.lightDistance.scale.set( d, d, d );
  24669. }
  24670. this.add( this.lightDistance );
  24671. */
  24672. };
  24673. THREE.PointLightHelper.prototype = Object.create( THREE.Mesh.prototype );
  24674. THREE.PointLightHelper.prototype.constructor = THREE.PointLightHelper;
  24675. THREE.PointLightHelper.prototype.dispose = function () {
  24676. this.geometry.dispose();
  24677. this.material.dispose();
  24678. };
  24679. THREE.PointLightHelper.prototype.update = function () {
  24680. this.material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  24681. /*
  24682. var d = this.light.distance;
  24683. if ( d === 0.0 ) {
  24684. this.lightDistance.visible = false;
  24685. } else {
  24686. this.lightDistance.visible = true;
  24687. this.lightDistance.scale.set( d, d, d );
  24688. }
  24689. */
  24690. };
  24691. // File:src/extras/helpers/SkeletonHelper.js
  24692. /**
  24693. * @author Sean Griffin / http://twitter.com/sgrif
  24694. * @author Michael Guerrero / http://realitymeltdown.com
  24695. * @author mrdoob / http://mrdoob.com/
  24696. * @author ikerr / http://verold.com
  24697. */
  24698. THREE.SkeletonHelper = function ( object ) {
  24699. this.bones = this.getBoneList( object );
  24700. var geometry = new THREE.Geometry();
  24701. for ( var i = 0; i < this.bones.length; i ++ ) {
  24702. var bone = this.bones[ i ];
  24703. if ( bone.parent instanceof THREE.Bone ) {
  24704. geometry.vertices.push( new THREE.Vector3() );
  24705. geometry.vertices.push( new THREE.Vector3() );
  24706. geometry.colors.push( new THREE.Color( 0, 0, 1 ) );
  24707. geometry.colors.push( new THREE.Color( 0, 1, 0 ) );
  24708. }
  24709. }
  24710. geometry.dynamic = true;
  24711. var material = new THREE.LineBasicMaterial( { vertexColors: THREE.VertexColors, depthTest: false, depthWrite: false, transparent: true } );
  24712. THREE.LineSegments.call( this, geometry, material );
  24713. this.root = object;
  24714. this.matrix = object.matrixWorld;
  24715. this.matrixAutoUpdate = false;
  24716. this.update();
  24717. };
  24718. THREE.SkeletonHelper.prototype = Object.create( THREE.LineSegments.prototype );
  24719. THREE.SkeletonHelper.prototype.constructor = THREE.SkeletonHelper;
  24720. THREE.SkeletonHelper.prototype.getBoneList = function( object ) {
  24721. var boneList = [];
  24722. if ( object instanceof THREE.Bone ) {
  24723. boneList.push( object );
  24724. }
  24725. for ( var i = 0; i < object.children.length; i ++ ) {
  24726. boneList.push.apply( boneList, this.getBoneList( object.children[ i ] ) );
  24727. }
  24728. return boneList;
  24729. };
  24730. THREE.SkeletonHelper.prototype.update = function () {
  24731. var geometry = this.geometry;
  24732. var matrixWorldInv = new THREE.Matrix4().getInverse( this.root.matrixWorld );
  24733. var boneMatrix = new THREE.Matrix4();
  24734. var j = 0;
  24735. for ( var i = 0; i < this.bones.length; i ++ ) {
  24736. var bone = this.bones[ i ];
  24737. if ( bone.parent instanceof THREE.Bone ) {
  24738. boneMatrix.multiplyMatrices( matrixWorldInv, bone.matrixWorld );
  24739. geometry.vertices[ j ].setFromMatrixPosition( boneMatrix );
  24740. boneMatrix.multiplyMatrices( matrixWorldInv, bone.parent.matrixWorld );
  24741. geometry.vertices[ j + 1 ].setFromMatrixPosition( boneMatrix );
  24742. j += 2;
  24743. }
  24744. }
  24745. geometry.verticesNeedUpdate = true;
  24746. geometry.computeBoundingSphere();
  24747. };
  24748. // File:src/extras/helpers/SpotLightHelper.js
  24749. /**
  24750. * @author alteredq / http://alteredqualia.com/
  24751. * @author mrdoob / http://mrdoob.com/
  24752. * @author WestLangley / http://github.com/WestLangley
  24753. */
  24754. THREE.SpotLightHelper = function ( light ) {
  24755. THREE.Object3D.call( this );
  24756. this.light = light;
  24757. this.light.updateMatrixWorld();
  24758. this.matrix = light.matrixWorld;
  24759. this.matrixAutoUpdate = false;
  24760. var geometry = new THREE.BufferGeometry();
  24761. var positions = [
  24762. 0, 0, 0, 0, 0, 1,
  24763. 0, 0, 0, 1, 0, 1,
  24764. 0, 0, 0, - 1, 0, 1,
  24765. 0, 0, 0, 0, 1, 1,
  24766. 0, 0, 0, 0, - 1, 1
  24767. ];
  24768. for ( var i = 0, j = 1, l = 32; i < l; i ++, j ++ ) {
  24769. var p1 = ( i / l ) * Math.PI * 2;
  24770. var p2 = ( j / l ) * Math.PI * 2;
  24771. positions.push(
  24772. Math.cos( p1 ), Math.sin( p1 ), 1,
  24773. Math.cos( p2 ), Math.sin( p2 ), 1
  24774. );
  24775. }
  24776. geometry.addAttribute( 'position', new THREE.Float32Attribute( positions, 3 ) );
  24777. var material = new THREE.LineBasicMaterial( { fog: false } );
  24778. this.cone = new THREE.LineSegments( geometry, material );
  24779. this.add( this.cone );
  24780. this.update();
  24781. };
  24782. THREE.SpotLightHelper.prototype = Object.create( THREE.Object3D.prototype );
  24783. THREE.SpotLightHelper.prototype.constructor = THREE.SpotLightHelper;
  24784. THREE.SpotLightHelper.prototype.dispose = function () {
  24785. this.cone.geometry.dispose();
  24786. this.cone.material.dispose();
  24787. };
  24788. THREE.SpotLightHelper.prototype.update = function () {
  24789. var vector = new THREE.Vector3();
  24790. var vector2 = new THREE.Vector3();
  24791. return function update() {
  24792. var coneLength = this.light.distance ? this.light.distance : 1000;
  24793. var coneWidth = coneLength * Math.tan( this.light.angle );
  24794. this.cone.scale.set( coneWidth, coneWidth, coneLength );
  24795. vector.setFromMatrixPosition( this.light.matrixWorld );
  24796. vector2.setFromMatrixPosition( this.light.target.matrixWorld );
  24797. this.cone.lookAt( vector2.sub( vector ) );
  24798. this.cone.material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  24799. };
  24800. }();
  24801. // File:src/extras/helpers/VertexNormalsHelper.js
  24802. /**
  24803. * @author mrdoob / http://mrdoob.com/
  24804. * @author WestLangley / http://github.com/WestLangley
  24805. */
  24806. THREE.VertexNormalsHelper = function ( object, size, hex, linewidth ) {
  24807. this.object = object;
  24808. this.size = ( size !== undefined ) ? size : 1;
  24809. var color = ( hex !== undefined ) ? hex : 0xff0000;
  24810. var width = ( linewidth !== undefined ) ? linewidth : 1;
  24811. //
  24812. var nNormals = 0;
  24813. var objGeometry = this.object.geometry;
  24814. if ( objGeometry instanceof THREE.Geometry ) {
  24815. nNormals = objGeometry.faces.length * 3;
  24816. } else if ( objGeometry instanceof THREE.BufferGeometry ) {
  24817. nNormals = objGeometry.attributes.normal.count;
  24818. }
  24819. //
  24820. var geometry = new THREE.BufferGeometry();
  24821. var positions = new THREE.Float32Attribute( nNormals * 2 * 3, 3 );
  24822. geometry.addAttribute( 'position', positions );
  24823. THREE.LineSegments.call( this, geometry, new THREE.LineBasicMaterial( { color: color, linewidth: width } ) );
  24824. //
  24825. this.matrixAutoUpdate = false;
  24826. this.update();
  24827. };
  24828. THREE.VertexNormalsHelper.prototype = Object.create( THREE.LineSegments.prototype );
  24829. THREE.VertexNormalsHelper.prototype.constructor = THREE.VertexNormalsHelper;
  24830. THREE.VertexNormalsHelper.prototype.update = ( function () {
  24831. var v1 = new THREE.Vector3();
  24832. var v2 = new THREE.Vector3();
  24833. var normalMatrix = new THREE.Matrix3();
  24834. return function update() {
  24835. var keys = [ 'a', 'b', 'c' ];
  24836. this.object.updateMatrixWorld( true );
  24837. normalMatrix.getNormalMatrix( this.object.matrixWorld );
  24838. var matrixWorld = this.object.matrixWorld;
  24839. var position = this.geometry.attributes.position;
  24840. //
  24841. var objGeometry = this.object.geometry;
  24842. if ( objGeometry instanceof THREE.Geometry ) {
  24843. var vertices = objGeometry.vertices;
  24844. var faces = objGeometry.faces;
  24845. var idx = 0;
  24846. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  24847. var face = faces[ i ];
  24848. for ( var j = 0, jl = face.vertexNormals.length; j < jl; j ++ ) {
  24849. var vertex = vertices[ face[ keys[ j ] ] ];
  24850. var normal = face.vertexNormals[ j ];
  24851. v1.copy( vertex ).applyMatrix4( matrixWorld );
  24852. v2.copy( normal ).applyMatrix3( normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
  24853. position.setXYZ( idx, v1.x, v1.y, v1.z );
  24854. idx = idx + 1;
  24855. position.setXYZ( idx, v2.x, v2.y, v2.z );
  24856. idx = idx + 1;
  24857. }
  24858. }
  24859. } else if ( objGeometry instanceof THREE.BufferGeometry ) {
  24860. var objPos = objGeometry.attributes.position;
  24861. var objNorm = objGeometry.attributes.normal;
  24862. var idx = 0;
  24863. // for simplicity, ignore index and drawcalls, and render every normal
  24864. for ( var j = 0, jl = objPos.count; j < jl; j ++ ) {
  24865. v1.set( objPos.getX( j ), objPos.getY( j ), objPos.getZ( j ) ).applyMatrix4( matrixWorld );
  24866. v2.set( objNorm.getX( j ), objNorm.getY( j ), objNorm.getZ( j ) );
  24867. v2.applyMatrix3( normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
  24868. position.setXYZ( idx, v1.x, v1.y, v1.z );
  24869. idx = idx + 1;
  24870. position.setXYZ( idx, v2.x, v2.y, v2.z );
  24871. idx = idx + 1;
  24872. }
  24873. }
  24874. position.needsUpdate = true;
  24875. return this;
  24876. };
  24877. }() );
  24878. // File:src/extras/helpers/WireframeHelper.js
  24879. /**
  24880. * @author mrdoob / http://mrdoob.com/
  24881. */
  24882. THREE.WireframeHelper = function ( object, hex ) {
  24883. var color = ( hex !== undefined ) ? hex : 0xffffff;
  24884. THREE.LineSegments.call( this, new THREE.WireframeGeometry( object.geometry ), new THREE.LineBasicMaterial( { color: color } ) );
  24885. this.matrix = object.matrixWorld;
  24886. this.matrixAutoUpdate = false;
  24887. };
  24888. THREE.WireframeHelper.prototype = Object.create( THREE.LineSegments.prototype );
  24889. THREE.WireframeHelper.prototype.constructor = THREE.WireframeHelper;
  24890. // File:src/extras/objects/ImmediateRenderObject.js
  24891. /**
  24892. * @author alteredq / http://alteredqualia.com/
  24893. */
  24894. THREE.ImmediateRenderObject = function ( material ) {
  24895. THREE.Object3D.call( this );
  24896. this.material = material;
  24897. this.render = function ( renderCallback ) {};
  24898. };
  24899. THREE.ImmediateRenderObject.prototype = Object.create( THREE.Object3D.prototype );
  24900. THREE.ImmediateRenderObject.prototype.constructor = THREE.ImmediateRenderObject;
  24901. // File:src/extras/objects/MorphBlendMesh.js
  24902. /**
  24903. * @author alteredq / http://alteredqualia.com/
  24904. */
  24905. THREE.MorphBlendMesh = function( geometry, material ) {
  24906. THREE.Mesh.call( this, geometry, material );
  24907. this.animationsMap = {};
  24908. this.animationsList = [];
  24909. // prepare default animation
  24910. // (all frames played together in 1 second)
  24911. var numFrames = this.geometry.morphTargets.length;
  24912. var name = "__default";
  24913. var startFrame = 0;
  24914. var endFrame = numFrames - 1;
  24915. var fps = numFrames / 1;
  24916. this.createAnimation( name, startFrame, endFrame, fps );
  24917. this.setAnimationWeight( name, 1 );
  24918. };
  24919. THREE.MorphBlendMesh.prototype = Object.create( THREE.Mesh.prototype );
  24920. THREE.MorphBlendMesh.prototype.constructor = THREE.MorphBlendMesh;
  24921. THREE.MorphBlendMesh.prototype.createAnimation = function ( name, start, end, fps ) {
  24922. var animation = {
  24923. start: start,
  24924. end: end,
  24925. length: end - start + 1,
  24926. fps: fps,
  24927. duration: ( end - start ) / fps,
  24928. lastFrame: 0,
  24929. currentFrame: 0,
  24930. active: false,
  24931. time: 0,
  24932. direction: 1,
  24933. weight: 1,
  24934. directionBackwards: false,
  24935. mirroredLoop: false
  24936. };
  24937. this.animationsMap[ name ] = animation;
  24938. this.animationsList.push( animation );
  24939. };
  24940. THREE.MorphBlendMesh.prototype.autoCreateAnimations = function ( fps ) {
  24941. var pattern = /([a-z]+)_?(\d+)/i;
  24942. var firstAnimation, frameRanges = {};
  24943. var geometry = this.geometry;
  24944. for ( var i = 0, il = geometry.morphTargets.length; i < il; i ++ ) {
  24945. var morph = geometry.morphTargets[ i ];
  24946. var chunks = morph.name.match( pattern );
  24947. if ( chunks && chunks.length > 1 ) {
  24948. var name = chunks[ 1 ];
  24949. if ( ! frameRanges[ name ] ) frameRanges[ name ] = { start: Infinity, end: - Infinity };
  24950. var range = frameRanges[ name ];
  24951. if ( i < range.start ) range.start = i;
  24952. if ( i > range.end ) range.end = i;
  24953. if ( ! firstAnimation ) firstAnimation = name;
  24954. }
  24955. }
  24956. for ( var name in frameRanges ) {
  24957. var range = frameRanges[ name ];
  24958. this.createAnimation( name, range.start, range.end, fps );
  24959. }
  24960. this.firstAnimation = firstAnimation;
  24961. };
  24962. THREE.MorphBlendMesh.prototype.setAnimationDirectionForward = function ( name ) {
  24963. var animation = this.animationsMap[ name ];
  24964. if ( animation ) {
  24965. animation.direction = 1;
  24966. animation.directionBackwards = false;
  24967. }
  24968. };
  24969. THREE.MorphBlendMesh.prototype.setAnimationDirectionBackward = function ( name ) {
  24970. var animation = this.animationsMap[ name ];
  24971. if ( animation ) {
  24972. animation.direction = - 1;
  24973. animation.directionBackwards = true;
  24974. }
  24975. };
  24976. THREE.MorphBlendMesh.prototype.setAnimationFPS = function ( name, fps ) {
  24977. var animation = this.animationsMap[ name ];
  24978. if ( animation ) {
  24979. animation.fps = fps;
  24980. animation.duration = ( animation.end - animation.start ) / animation.fps;
  24981. }
  24982. };
  24983. THREE.MorphBlendMesh.prototype.setAnimationDuration = function ( name, duration ) {
  24984. var animation = this.animationsMap[ name ];
  24985. if ( animation ) {
  24986. animation.duration = duration;
  24987. animation.fps = ( animation.end - animation.start ) / animation.duration;
  24988. }
  24989. };
  24990. THREE.MorphBlendMesh.prototype.setAnimationWeight = function ( name, weight ) {
  24991. var animation = this.animationsMap[ name ];
  24992. if ( animation ) {
  24993. animation.weight = weight;
  24994. }
  24995. };
  24996. THREE.MorphBlendMesh.prototype.setAnimationTime = function ( name, time ) {
  24997. var animation = this.animationsMap[ name ];
  24998. if ( animation ) {
  24999. animation.time = time;
  25000. }
  25001. };
  25002. THREE.MorphBlendMesh.prototype.getAnimationTime = function ( name ) {
  25003. var time = 0;
  25004. var animation = this.animationsMap[ name ];
  25005. if ( animation ) {
  25006. time = animation.time;
  25007. }
  25008. return time;
  25009. };
  25010. THREE.MorphBlendMesh.prototype.getAnimationDuration = function ( name ) {
  25011. var duration = - 1;
  25012. var animation = this.animationsMap[ name ];
  25013. if ( animation ) {
  25014. duration = animation.duration;
  25015. }
  25016. return duration;
  25017. };
  25018. THREE.MorphBlendMesh.prototype.playAnimation = function ( name ) {
  25019. var animation = this.animationsMap[ name ];
  25020. if ( animation ) {
  25021. animation.time = 0;
  25022. animation.active = true;
  25023. } else {
  25024. console.warn( "THREE.MorphBlendMesh: animation[" + name + "] undefined in .playAnimation()" );
  25025. }
  25026. };
  25027. THREE.MorphBlendMesh.prototype.stopAnimation = function ( name ) {
  25028. var animation = this.animationsMap[ name ];
  25029. if ( animation ) {
  25030. animation.active = false;
  25031. }
  25032. };
  25033. THREE.MorphBlendMesh.prototype.update = function ( delta ) {
  25034. for ( var i = 0, il = this.animationsList.length; i < il; i ++ ) {
  25035. var animation = this.animationsList[ i ];
  25036. if ( ! animation.active ) continue;
  25037. var frameTime = animation.duration / animation.length;
  25038. animation.time += animation.direction * delta;
  25039. if ( animation.mirroredLoop ) {
  25040. if ( animation.time > animation.duration || animation.time < 0 ) {
  25041. animation.direction *= - 1;
  25042. if ( animation.time > animation.duration ) {
  25043. animation.time = animation.duration;
  25044. animation.directionBackwards = true;
  25045. }
  25046. if ( animation.time < 0 ) {
  25047. animation.time = 0;
  25048. animation.directionBackwards = false;
  25049. }
  25050. }
  25051. } else {
  25052. animation.time = animation.time % animation.duration;
  25053. if ( animation.time < 0 ) animation.time += animation.duration;
  25054. }
  25055. var keyframe = animation.start + THREE.Math.clamp( Math.floor( animation.time / frameTime ), 0, animation.length - 1 );
  25056. var weight = animation.weight;
  25057. if ( keyframe !== animation.currentFrame ) {
  25058. this.morphTargetInfluences[ animation.lastFrame ] = 0;
  25059. this.morphTargetInfluences[ animation.currentFrame ] = 1 * weight;
  25060. this.morphTargetInfluences[ keyframe ] = 0;
  25061. animation.lastFrame = animation.currentFrame;
  25062. animation.currentFrame = keyframe;
  25063. }
  25064. var mix = ( animation.time % frameTime ) / frameTime;
  25065. if ( animation.directionBackwards ) mix = 1 - mix;
  25066. if ( animation.currentFrame !== animation.lastFrame ) {
  25067. this.morphTargetInfluences[ animation.currentFrame ] = mix * weight;
  25068. this.morphTargetInfluences[ animation.lastFrame ] = ( 1 - mix ) * weight;
  25069. } else {
  25070. this.morphTargetInfluences[ animation.currentFrame ] = weight;
  25071. }
  25072. }
  25073. };