three.js 950 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919189201892118922189231892418925189261892718928189291893018931189321893318934189351893618937189381893918940189411894218943189441894518946189471894818949189501895118952189531895418955189561895718958189591896018961189621896318964189651896618967189681896918970189711897218973189741897518976189771897818979189801898118982189831898418985189861898718988189891899018991189921899318994189951899618997189981899919000190011900219003190041900519006190071900819009190101901119012190131901419015190161901719018190191902019021190221902319024190251902619027190281902919030190311903219033190341903519036190371903819039190401904119042190431904419045190461904719048190491905019051190521905319054190551905619057190581905919060190611906219063190641906519066190671906819069190701907119072190731907419075190761907719078190791908019081190821908319084190851908619087190881908919090190911909219093190941909519096190971909819099191001910119102191031910419105191061910719108191091911019111191121911319114191151911619117191181911919120191211912219123191241912519126191271912819129191301913119132191331913419135191361913719138191391914019141191421914319144191451914619147191481914919150191511915219153191541915519156191571915819159191601916119162191631916419165191661916719168191691917019171191721917319174191751917619177191781917919180191811918219183191841918519186191871918819189191901919119192191931919419195191961919719198191991920019201192021920319204192051920619207192081920919210192111921219213192141921519216192171921819219192201922119222192231922419225192261922719228192291923019231192321923319234192351923619237192381923919240192411924219243192441924519246192471924819249192501925119252192531925419255192561925719258192591926019261192621926319264192651926619267192681926919270192711927219273192741927519276192771927819279192801928119282192831928419285192861928719288192891929019291192921929319294192951929619297192981929919300193011930219303193041930519306193071930819309193101931119312193131931419315193161931719318193191932019321193221932319324193251932619327193281932919330193311933219333193341933519336193371933819339193401934119342193431934419345193461934719348193491935019351193521935319354193551935619357193581935919360193611936219363193641936519366193671936819369193701937119372193731937419375193761937719378193791938019381193821938319384193851938619387193881938919390193911939219393193941939519396193971939819399194001940119402194031940419405194061940719408194091941019411194121941319414194151941619417194181941919420194211942219423194241942519426194271942819429194301943119432194331943419435194361943719438194391944019441194421944319444194451944619447194481944919450194511945219453194541945519456194571945819459194601946119462194631946419465194661946719468194691947019471194721947319474194751947619477194781947919480194811948219483194841948519486194871948819489194901949119492194931949419495194961949719498194991950019501195021950319504195051950619507195081950919510195111951219513195141951519516195171951819519195201952119522195231952419525195261952719528195291953019531195321953319534195351953619537195381953919540195411954219543195441954519546195471954819549195501955119552195531955419555195561955719558195591956019561195621956319564195651956619567195681956919570195711957219573195741957519576195771957819579195801958119582195831958419585195861958719588195891959019591195921959319594195951959619597195981959919600196011960219603196041960519606196071960819609196101961119612196131961419615196161961719618196191962019621196221962319624196251962619627196281962919630196311963219633196341963519636196371963819639196401964119642196431964419645196461964719648196491965019651196521965319654196551965619657196581965919660196611966219663196641966519666196671966819669196701967119672196731967419675196761967719678196791968019681196821968319684196851968619687196881968919690196911969219693196941969519696196971969819699197001970119702197031970419705197061970719708197091971019711197121971319714197151971619717197181971919720197211972219723197241972519726197271972819729197301973119732197331973419735197361973719738197391974019741197421974319744197451974619747197481974919750197511975219753197541975519756197571975819759197601976119762197631976419765197661976719768197691977019771197721977319774197751977619777197781977919780197811978219783197841978519786197871978819789197901979119792197931979419795197961979719798197991980019801198021980319804198051980619807198081980919810198111981219813198141981519816198171981819819198201982119822198231982419825198261982719828198291983019831198321983319834198351983619837198381983919840198411984219843198441984519846198471984819849198501985119852198531985419855198561985719858198591986019861198621986319864198651986619867198681986919870198711987219873198741987519876198771987819879198801988119882198831988419885198861988719888198891989019891198921989319894198951989619897198981989919900199011990219903199041990519906199071990819909199101991119912199131991419915199161991719918199191992019921199221992319924199251992619927199281992919930199311993219933199341993519936199371993819939199401994119942199431994419945199461994719948199491995019951199521995319954199551995619957199581995919960199611996219963199641996519966199671996819969199701997119972199731997419975199761997719978199791998019981199821998319984199851998619987199881998919990199911999219993199941999519996199971999819999200002000120002200032000420005200062000720008200092001020011200122001320014200152001620017200182001920020200212002220023200242002520026200272002820029200302003120032200332003420035200362003720038200392004020041200422004320044200452004620047200482004920050200512005220053200542005520056200572005820059200602006120062200632006420065200662006720068200692007020071200722007320074200752007620077200782007920080200812008220083200842008520086200872008820089200902009120092200932009420095200962009720098200992010020101201022010320104201052010620107201082010920110201112011220113201142011520116201172011820119201202012120122201232012420125201262012720128201292013020131201322013320134201352013620137201382013920140201412014220143201442014520146201472014820149201502015120152201532015420155201562015720158201592016020161201622016320164201652016620167201682016920170201712017220173201742017520176201772017820179201802018120182201832018420185201862018720188201892019020191201922019320194201952019620197201982019920200202012020220203202042020520206202072020820209202102021120212202132021420215202162021720218202192022020221202222022320224202252022620227202282022920230202312023220233202342023520236202372023820239202402024120242202432024420245202462024720248202492025020251202522025320254202552025620257202582025920260202612026220263202642026520266202672026820269202702027120272202732027420275202762027720278202792028020281202822028320284202852028620287202882028920290202912029220293202942029520296202972029820299203002030120302203032030420305203062030720308203092031020311203122031320314203152031620317203182031920320203212032220323203242032520326203272032820329203302033120332203332033420335203362033720338203392034020341203422034320344203452034620347203482034920350203512035220353203542035520356203572035820359203602036120362203632036420365203662036720368203692037020371203722037320374203752037620377203782037920380203812038220383203842038520386203872038820389203902039120392203932039420395203962039720398203992040020401204022040320404204052040620407204082040920410204112041220413204142041520416204172041820419204202042120422204232042420425204262042720428204292043020431204322043320434204352043620437204382043920440204412044220443204442044520446204472044820449204502045120452204532045420455204562045720458204592046020461204622046320464204652046620467204682046920470204712047220473204742047520476204772047820479204802048120482204832048420485204862048720488204892049020491204922049320494204952049620497204982049920500205012050220503205042050520506205072050820509205102051120512205132051420515205162051720518205192052020521205222052320524205252052620527205282052920530205312053220533205342053520536205372053820539205402054120542205432054420545205462054720548205492055020551205522055320554205552055620557205582055920560205612056220563205642056520566205672056820569205702057120572205732057420575205762057720578205792058020581205822058320584205852058620587205882058920590205912059220593205942059520596205972059820599206002060120602206032060420605206062060720608206092061020611206122061320614206152061620617206182061920620206212062220623206242062520626206272062820629206302063120632206332063420635206362063720638206392064020641206422064320644206452064620647206482064920650206512065220653206542065520656206572065820659206602066120662206632066420665206662066720668206692067020671206722067320674206752067620677206782067920680206812068220683206842068520686206872068820689206902069120692206932069420695206962069720698206992070020701207022070320704207052070620707207082070920710207112071220713207142071520716207172071820719207202072120722207232072420725207262072720728207292073020731207322073320734207352073620737207382073920740207412074220743207442074520746207472074820749207502075120752207532075420755207562075720758207592076020761207622076320764207652076620767207682076920770207712077220773207742077520776207772077820779207802078120782207832078420785207862078720788207892079020791207922079320794207952079620797207982079920800208012080220803208042080520806208072080820809208102081120812208132081420815208162081720818208192082020821208222082320824208252082620827208282082920830208312083220833208342083520836208372083820839208402084120842208432084420845208462084720848208492085020851208522085320854208552085620857208582085920860208612086220863208642086520866208672086820869208702087120872208732087420875208762087720878208792088020881208822088320884208852088620887208882088920890208912089220893208942089520896208972089820899209002090120902209032090420905209062090720908209092091020911209122091320914209152091620917209182091920920209212092220923209242092520926209272092820929209302093120932209332093420935209362093720938209392094020941209422094320944209452094620947209482094920950209512095220953209542095520956209572095820959209602096120962209632096420965209662096720968209692097020971209722097320974209752097620977209782097920980209812098220983209842098520986209872098820989209902099120992209932099420995209962099720998209992100021001210022100321004210052100621007210082100921010210112101221013210142101521016210172101821019210202102121022210232102421025210262102721028210292103021031210322103321034210352103621037210382103921040210412104221043210442104521046210472104821049210502105121052210532105421055210562105721058210592106021061210622106321064210652106621067210682106921070210712107221073210742107521076210772107821079210802108121082210832108421085210862108721088210892109021091210922109321094210952109621097210982109921100211012110221103211042110521106211072110821109211102111121112211132111421115211162111721118211192112021121211222112321124211252112621127211282112921130211312113221133211342113521136211372113821139211402114121142211432114421145211462114721148211492115021151211522115321154211552115621157211582115921160211612116221163211642116521166211672116821169211702117121172211732117421175211762117721178211792118021181211822118321184211852118621187211882118921190211912119221193211942119521196211972119821199212002120121202212032120421205212062120721208212092121021211212122121321214212152121621217212182121921220212212122221223212242122521226212272122821229212302123121232212332123421235212362123721238212392124021241212422124321244212452124621247212482124921250212512125221253212542125521256212572125821259212602126121262212632126421265212662126721268212692127021271212722127321274212752127621277212782127921280212812128221283212842128521286212872128821289212902129121292212932129421295212962129721298212992130021301213022130321304213052130621307213082130921310213112131221313213142131521316213172131821319213202132121322213232132421325213262132721328213292133021331213322133321334213352133621337213382133921340213412134221343213442134521346213472134821349213502135121352213532135421355213562135721358213592136021361213622136321364213652136621367213682136921370213712137221373213742137521376213772137821379213802138121382213832138421385213862138721388213892139021391213922139321394213952139621397213982139921400214012140221403214042140521406214072140821409214102141121412214132141421415214162141721418214192142021421214222142321424214252142621427214282142921430214312143221433214342143521436214372143821439214402144121442214432144421445214462144721448214492145021451214522145321454214552145621457214582145921460214612146221463214642146521466214672146821469214702147121472214732147421475214762147721478214792148021481214822148321484214852148621487214882148921490214912149221493214942149521496214972149821499215002150121502215032150421505215062150721508215092151021511215122151321514215152151621517215182151921520215212152221523215242152521526215272152821529215302153121532215332153421535215362153721538215392154021541215422154321544215452154621547215482154921550215512155221553215542155521556215572155821559215602156121562215632156421565215662156721568215692157021571215722157321574215752157621577215782157921580215812158221583215842158521586215872158821589215902159121592215932159421595215962159721598215992160021601216022160321604216052160621607216082160921610216112161221613216142161521616216172161821619216202162121622216232162421625216262162721628216292163021631216322163321634216352163621637216382163921640216412164221643216442164521646216472164821649216502165121652216532165421655216562165721658216592166021661216622166321664216652166621667216682166921670216712167221673216742167521676216772167821679216802168121682216832168421685216862168721688216892169021691216922169321694216952169621697216982169921700217012170221703217042170521706217072170821709217102171121712217132171421715217162171721718217192172021721217222172321724217252172621727217282172921730217312173221733217342173521736217372173821739217402174121742217432174421745217462174721748217492175021751217522175321754217552175621757217582175921760217612176221763217642176521766217672176821769217702177121772217732177421775217762177721778217792178021781217822178321784217852178621787217882178921790217912179221793217942179521796217972179821799218002180121802218032180421805218062180721808218092181021811218122181321814218152181621817218182181921820218212182221823218242182521826218272182821829218302183121832218332183421835218362183721838218392184021841218422184321844218452184621847218482184921850218512185221853218542185521856218572185821859218602186121862218632186421865218662186721868218692187021871218722187321874218752187621877218782187921880218812188221883218842188521886218872188821889218902189121892218932189421895218962189721898218992190021901219022190321904219052190621907219082190921910219112191221913219142191521916219172191821919219202192121922219232192421925219262192721928219292193021931219322193321934219352193621937219382193921940219412194221943219442194521946219472194821949219502195121952219532195421955219562195721958219592196021961219622196321964219652196621967219682196921970219712197221973219742197521976219772197821979219802198121982219832198421985219862198721988219892199021991219922199321994219952199621997219982199922000220012200222003220042200522006220072200822009220102201122012220132201422015220162201722018220192202022021220222202322024220252202622027220282202922030220312203222033220342203522036220372203822039220402204122042220432204422045220462204722048220492205022051220522205322054220552205622057220582205922060220612206222063220642206522066220672206822069220702207122072220732207422075220762207722078220792208022081220822208322084220852208622087220882208922090220912209222093220942209522096220972209822099221002210122102221032210422105221062210722108221092211022111221122211322114221152211622117221182211922120221212212222123221242212522126221272212822129221302213122132221332213422135221362213722138221392214022141221422214322144221452214622147221482214922150221512215222153221542215522156221572215822159221602216122162221632216422165221662216722168221692217022171221722217322174221752217622177221782217922180221812218222183221842218522186221872218822189221902219122192221932219422195221962219722198221992220022201222022220322204222052220622207222082220922210222112221222213222142221522216222172221822219222202222122222222232222422225222262222722228222292223022231222322223322234222352223622237222382223922240222412224222243222442224522246222472224822249222502225122252222532225422255222562225722258222592226022261222622226322264222652226622267222682226922270222712227222273222742227522276222772227822279222802228122282222832228422285222862228722288222892229022291222922229322294222952229622297222982229922300223012230222303223042230522306223072230822309223102231122312223132231422315223162231722318223192232022321223222232322324223252232622327223282232922330223312233222333223342233522336223372233822339223402234122342223432234422345223462234722348223492235022351223522235322354223552235622357223582235922360223612236222363223642236522366223672236822369223702237122372223732237422375223762237722378223792238022381223822238322384223852238622387223882238922390223912239222393223942239522396223972239822399224002240122402224032240422405224062240722408224092241022411224122241322414224152241622417224182241922420224212242222423224242242522426224272242822429224302243122432224332243422435224362243722438224392244022441224422244322444224452244622447224482244922450224512245222453224542245522456224572245822459224602246122462224632246422465224662246722468224692247022471224722247322474224752247622477224782247922480224812248222483224842248522486224872248822489224902249122492224932249422495224962249722498224992250022501225022250322504225052250622507225082250922510225112251222513225142251522516225172251822519225202252122522225232252422525225262252722528225292253022531225322253322534225352253622537225382253922540225412254222543225442254522546225472254822549225502255122552225532255422555225562255722558225592256022561225622256322564225652256622567225682256922570225712257222573225742257522576225772257822579225802258122582225832258422585225862258722588225892259022591225922259322594225952259622597225982259922600226012260222603226042260522606226072260822609226102261122612226132261422615226162261722618226192262022621226222262322624226252262622627226282262922630226312263222633226342263522636226372263822639226402264122642226432264422645226462264722648226492265022651226522265322654226552265622657226582265922660226612266222663226642266522666226672266822669226702267122672226732267422675226762267722678226792268022681226822268322684226852268622687226882268922690226912269222693226942269522696226972269822699227002270122702227032270422705227062270722708227092271022711227122271322714227152271622717227182271922720227212272222723227242272522726227272272822729227302273122732227332273422735227362273722738227392274022741227422274322744227452274622747227482274922750227512275222753227542275522756227572275822759227602276122762227632276422765227662276722768227692277022771227722277322774227752277622777227782277922780227812278222783227842278522786227872278822789227902279122792227932279422795227962279722798227992280022801228022280322804228052280622807228082280922810228112281222813228142281522816228172281822819228202282122822228232282422825228262282722828228292283022831228322283322834228352283622837228382283922840228412284222843228442284522846228472284822849228502285122852228532285422855228562285722858228592286022861228622286322864228652286622867228682286922870228712287222873228742287522876228772287822879228802288122882228832288422885228862288722888228892289022891228922289322894228952289622897228982289922900229012290222903229042290522906229072290822909229102291122912229132291422915229162291722918229192292022921229222292322924229252292622927229282292922930229312293222933229342293522936229372293822939229402294122942229432294422945229462294722948229492295022951229522295322954229552295622957229582295922960229612296222963229642296522966229672296822969229702297122972229732297422975229762297722978229792298022981229822298322984229852298622987229882298922990229912299222993229942299522996229972299822999230002300123002230032300423005230062300723008230092301023011230122301323014230152301623017230182301923020230212302223023230242302523026230272302823029230302303123032230332303423035230362303723038230392304023041230422304323044230452304623047230482304923050230512305223053230542305523056230572305823059230602306123062230632306423065230662306723068230692307023071230722307323074230752307623077230782307923080230812308223083230842308523086230872308823089230902309123092230932309423095230962309723098230992310023101231022310323104231052310623107231082310923110231112311223113231142311523116231172311823119231202312123122231232312423125231262312723128231292313023131231322313323134231352313623137231382313923140231412314223143231442314523146231472314823149231502315123152231532315423155231562315723158231592316023161231622316323164231652316623167231682316923170231712317223173231742317523176231772317823179231802318123182231832318423185231862318723188231892319023191231922319323194231952319623197231982319923200232012320223203232042320523206232072320823209232102321123212232132321423215232162321723218232192322023221232222322323224232252322623227232282322923230232312323223233232342323523236232372323823239232402324123242232432324423245232462324723248232492325023251232522325323254232552325623257232582325923260232612326223263232642326523266232672326823269232702327123272232732327423275232762327723278232792328023281232822328323284232852328623287232882328923290232912329223293232942329523296232972329823299233002330123302233032330423305233062330723308233092331023311233122331323314233152331623317233182331923320233212332223323233242332523326233272332823329233302333123332233332333423335233362333723338233392334023341233422334323344233452334623347233482334923350233512335223353233542335523356233572335823359233602336123362233632336423365233662336723368233692337023371233722337323374233752337623377233782337923380233812338223383233842338523386233872338823389233902339123392233932339423395233962339723398233992340023401234022340323404234052340623407234082340923410234112341223413234142341523416234172341823419234202342123422234232342423425234262342723428234292343023431234322343323434234352343623437234382343923440234412344223443234442344523446234472344823449234502345123452234532345423455234562345723458234592346023461234622346323464234652346623467234682346923470234712347223473234742347523476234772347823479234802348123482234832348423485234862348723488234892349023491234922349323494234952349623497234982349923500235012350223503235042350523506235072350823509235102351123512235132351423515235162351723518235192352023521235222352323524235252352623527235282352923530235312353223533235342353523536235372353823539235402354123542235432354423545235462354723548235492355023551235522355323554235552355623557235582355923560235612356223563235642356523566235672356823569235702357123572235732357423575235762357723578235792358023581235822358323584235852358623587235882358923590235912359223593235942359523596235972359823599236002360123602236032360423605236062360723608236092361023611236122361323614236152361623617236182361923620236212362223623236242362523626236272362823629236302363123632236332363423635236362363723638236392364023641236422364323644236452364623647236482364923650236512365223653236542365523656236572365823659236602366123662236632366423665236662366723668236692367023671236722367323674236752367623677236782367923680236812368223683236842368523686236872368823689236902369123692236932369423695236962369723698236992370023701237022370323704237052370623707237082370923710237112371223713237142371523716237172371823719237202372123722237232372423725237262372723728237292373023731237322373323734237352373623737237382373923740237412374223743237442374523746237472374823749237502375123752237532375423755237562375723758237592376023761237622376323764237652376623767237682376923770237712377223773237742377523776237772377823779237802378123782237832378423785237862378723788237892379023791237922379323794237952379623797237982379923800238012380223803238042380523806238072380823809238102381123812238132381423815238162381723818238192382023821238222382323824238252382623827238282382923830238312383223833238342383523836238372383823839238402384123842238432384423845238462384723848238492385023851238522385323854238552385623857238582385923860238612386223863238642386523866238672386823869238702387123872238732387423875238762387723878238792388023881238822388323884238852388623887238882388923890238912389223893238942389523896238972389823899239002390123902239032390423905239062390723908239092391023911239122391323914239152391623917239182391923920239212392223923239242392523926239272392823929239302393123932239332393423935239362393723938239392394023941239422394323944239452394623947239482394923950239512395223953239542395523956239572395823959239602396123962239632396423965239662396723968239692397023971239722397323974239752397623977239782397923980239812398223983239842398523986239872398823989239902399123992239932399423995239962399723998239992400024001240022400324004240052400624007240082400924010240112401224013240142401524016240172401824019240202402124022240232402424025240262402724028240292403024031240322403324034240352403624037240382403924040240412404224043240442404524046240472404824049240502405124052240532405424055240562405724058240592406024061240622406324064240652406624067240682406924070240712407224073240742407524076240772407824079240802408124082240832408424085240862408724088240892409024091240922409324094240952409624097240982409924100241012410224103241042410524106241072410824109241102411124112241132411424115241162411724118241192412024121241222412324124241252412624127241282412924130241312413224133241342413524136241372413824139241402414124142241432414424145241462414724148241492415024151241522415324154241552415624157241582415924160241612416224163241642416524166241672416824169241702417124172241732417424175241762417724178241792418024181241822418324184241852418624187241882418924190241912419224193241942419524196241972419824199242002420124202242032420424205242062420724208242092421024211242122421324214242152421624217242182421924220242212422224223242242422524226242272422824229242302423124232242332423424235242362423724238242392424024241242422424324244242452424624247242482424924250242512425224253242542425524256242572425824259242602426124262242632426424265242662426724268242692427024271242722427324274242752427624277242782427924280242812428224283242842428524286242872428824289242902429124292242932429424295242962429724298242992430024301243022430324304243052430624307243082430924310243112431224313243142431524316243172431824319243202432124322243232432424325243262432724328243292433024331243322433324334243352433624337243382433924340243412434224343243442434524346243472434824349243502435124352243532435424355243562435724358243592436024361243622436324364243652436624367243682436924370243712437224373243742437524376243772437824379243802438124382243832438424385243862438724388243892439024391243922439324394243952439624397243982439924400244012440224403244042440524406244072440824409244102441124412244132441424415244162441724418244192442024421244222442324424244252442624427244282442924430244312443224433244342443524436244372443824439244402444124442244432444424445244462444724448244492445024451244522445324454244552445624457244582445924460244612446224463244642446524466244672446824469244702447124472244732447424475244762447724478244792448024481244822448324484244852448624487244882448924490244912449224493244942449524496244972449824499245002450124502245032450424505245062450724508245092451024511245122451324514245152451624517245182451924520245212452224523245242452524526245272452824529245302453124532245332453424535245362453724538245392454024541245422454324544245452454624547245482454924550245512455224553245542455524556245572455824559245602456124562245632456424565245662456724568245692457024571245722457324574245752457624577245782457924580245812458224583245842458524586245872458824589245902459124592245932459424595245962459724598245992460024601246022460324604246052460624607246082460924610246112461224613246142461524616246172461824619246202462124622246232462424625246262462724628246292463024631246322463324634246352463624637246382463924640246412464224643246442464524646246472464824649246502465124652246532465424655246562465724658246592466024661246622466324664246652466624667246682466924670246712467224673246742467524676246772467824679246802468124682246832468424685246862468724688246892469024691246922469324694246952469624697246982469924700247012470224703247042470524706247072470824709247102471124712247132471424715247162471724718247192472024721247222472324724247252472624727247282472924730247312473224733247342473524736247372473824739247402474124742247432474424745247462474724748247492475024751247522475324754247552475624757247582475924760247612476224763247642476524766247672476824769247702477124772247732477424775247762477724778247792478024781247822478324784247852478624787247882478924790247912479224793247942479524796247972479824799248002480124802248032480424805248062480724808248092481024811248122481324814248152481624817248182481924820248212482224823248242482524826248272482824829248302483124832248332483424835248362483724838248392484024841248422484324844248452484624847248482484924850248512485224853248542485524856248572485824859248602486124862248632486424865248662486724868248692487024871248722487324874248752487624877248782487924880248812488224883248842488524886248872488824889248902489124892248932489424895248962489724898248992490024901249022490324904249052490624907249082490924910249112491224913249142491524916249172491824919249202492124922249232492424925249262492724928249292493024931249322493324934249352493624937249382493924940249412494224943249442494524946249472494824949249502495124952249532495424955249562495724958249592496024961249622496324964249652496624967249682496924970249712497224973249742497524976249772497824979249802498124982249832498424985249862498724988249892499024991249922499324994249952499624997249982499925000250012500225003250042500525006250072500825009250102501125012250132501425015250162501725018250192502025021250222502325024250252502625027250282502925030250312503225033250342503525036250372503825039250402504125042250432504425045250462504725048250492505025051250522505325054250552505625057250582505925060250612506225063250642506525066250672506825069250702507125072250732507425075250762507725078250792508025081250822508325084250852508625087250882508925090250912509225093250942509525096250972509825099251002510125102251032510425105251062510725108251092511025111251122511325114251152511625117251182511925120251212512225123251242512525126251272512825129251302513125132251332513425135251362513725138251392514025141251422514325144251452514625147251482514925150251512515225153251542515525156251572515825159251602516125162251632516425165251662516725168251692517025171251722517325174251752517625177251782517925180251812518225183251842518525186251872518825189251902519125192251932519425195251962519725198251992520025201252022520325204252052520625207252082520925210252112521225213252142521525216252172521825219252202522125222252232522425225252262522725228252292523025231252322523325234252352523625237252382523925240252412524225243252442524525246252472524825249252502525125252252532525425255252562525725258252592526025261252622526325264252652526625267252682526925270252712527225273252742527525276252772527825279252802528125282252832528425285252862528725288252892529025291252922529325294252952529625297252982529925300253012530225303253042530525306253072530825309253102531125312253132531425315253162531725318253192532025321253222532325324253252532625327253282532925330253312533225333253342533525336253372533825339253402534125342253432534425345253462534725348253492535025351253522535325354253552535625357253582535925360253612536225363253642536525366253672536825369253702537125372253732537425375253762537725378253792538025381253822538325384253852538625387253882538925390253912539225393253942539525396253972539825399254002540125402254032540425405254062540725408254092541025411254122541325414254152541625417254182541925420254212542225423254242542525426254272542825429254302543125432254332543425435254362543725438254392544025441254422544325444254452544625447254482544925450254512545225453254542545525456254572545825459254602546125462254632546425465254662546725468254692547025471254722547325474254752547625477254782547925480254812548225483254842548525486254872548825489254902549125492254932549425495254962549725498254992550025501255022550325504255052550625507255082550925510255112551225513255142551525516255172551825519255202552125522255232552425525255262552725528255292553025531255322553325534255352553625537255382553925540255412554225543255442554525546255472554825549255502555125552255532555425555255562555725558255592556025561255622556325564255652556625567255682556925570255712557225573255742557525576255772557825579255802558125582255832558425585255862558725588255892559025591255922559325594255952559625597255982559925600256012560225603256042560525606256072560825609256102561125612256132561425615256162561725618256192562025621256222562325624256252562625627256282562925630256312563225633256342563525636256372563825639256402564125642256432564425645256462564725648256492565025651256522565325654256552565625657256582565925660256612566225663256642566525666256672566825669256702567125672256732567425675256762567725678256792568025681256822568325684256852568625687256882568925690256912569225693256942569525696256972569825699257002570125702257032570425705257062570725708257092571025711257122571325714257152571625717257182571925720257212572225723257242572525726257272572825729257302573125732257332573425735257362573725738257392574025741257422574325744257452574625747257482574925750257512575225753257542575525756257572575825759257602576125762257632576425765257662576725768257692577025771257722577325774257752577625777257782577925780257812578225783257842578525786257872578825789257902579125792257932579425795257962579725798257992580025801258022580325804258052580625807258082580925810258112581225813258142581525816258172581825819258202582125822258232582425825258262582725828258292583025831258322583325834258352583625837258382583925840258412584225843258442584525846258472584825849258502585125852258532585425855258562585725858258592586025861258622586325864258652586625867258682586925870258712587225873258742587525876258772587825879258802588125882258832588425885258862588725888258892589025891258922589325894258952589625897258982589925900259012590225903259042590525906259072590825909259102591125912259132591425915259162591725918259192592025921259222592325924259252592625927259282592925930259312593225933259342593525936259372593825939259402594125942259432594425945259462594725948259492595025951259522595325954259552595625957259582595925960259612596225963259642596525966259672596825969259702597125972259732597425975259762597725978259792598025981259822598325984259852598625987259882598925990259912599225993259942599525996259972599825999260002600126002260032600426005260062600726008260092601026011260122601326014260152601626017260182601926020260212602226023260242602526026260272602826029260302603126032260332603426035260362603726038260392604026041260422604326044260452604626047260482604926050260512605226053260542605526056260572605826059260602606126062260632606426065260662606726068260692607026071260722607326074260752607626077260782607926080260812608226083260842608526086260872608826089260902609126092260932609426095260962609726098260992610026101261022610326104261052610626107261082610926110261112611226113261142611526116261172611826119261202612126122261232612426125261262612726128261292613026131261322613326134261352613626137261382613926140261412614226143261442614526146261472614826149261502615126152261532615426155261562615726158261592616026161261622616326164261652616626167261682616926170261712617226173261742617526176261772617826179261802618126182261832618426185261862618726188261892619026191261922619326194261952619626197261982619926200262012620226203262042620526206262072620826209262102621126212262132621426215262162621726218262192622026221262222622326224262252622626227262282622926230262312623226233262342623526236262372623826239262402624126242262432624426245262462624726248262492625026251262522625326254262552625626257262582625926260262612626226263262642626526266262672626826269262702627126272262732627426275262762627726278262792628026281262822628326284262852628626287262882628926290262912629226293262942629526296262972629826299263002630126302263032630426305263062630726308263092631026311263122631326314263152631626317263182631926320263212632226323263242632526326263272632826329263302633126332263332633426335263362633726338263392634026341263422634326344263452634626347263482634926350263512635226353263542635526356263572635826359263602636126362263632636426365263662636726368263692637026371263722637326374263752637626377263782637926380263812638226383263842638526386263872638826389263902639126392263932639426395263962639726398263992640026401264022640326404264052640626407264082640926410264112641226413264142641526416264172641826419264202642126422264232642426425264262642726428264292643026431264322643326434264352643626437264382643926440264412644226443264442644526446264472644826449264502645126452264532645426455264562645726458264592646026461264622646326464264652646626467264682646926470264712647226473264742647526476264772647826479264802648126482264832648426485264862648726488264892649026491264922649326494264952649626497264982649926500265012650226503265042650526506265072650826509265102651126512265132651426515265162651726518265192652026521265222652326524265252652626527265282652926530265312653226533265342653526536265372653826539265402654126542265432654426545265462654726548265492655026551265522655326554265552655626557265582655926560265612656226563265642656526566265672656826569265702657126572265732657426575265762657726578265792658026581265822658326584265852658626587265882658926590265912659226593265942659526596265972659826599266002660126602266032660426605266062660726608266092661026611266122661326614266152661626617266182661926620266212662226623266242662526626266272662826629266302663126632266332663426635266362663726638266392664026641266422664326644266452664626647266482664926650266512665226653266542665526656266572665826659266602666126662266632666426665266662666726668266692667026671266722667326674266752667626677266782667926680266812668226683266842668526686266872668826689266902669126692266932669426695266962669726698266992670026701267022670326704267052670626707267082670926710267112671226713267142671526716267172671826719267202672126722267232672426725267262672726728267292673026731267322673326734267352673626737267382673926740267412674226743267442674526746267472674826749267502675126752267532675426755267562675726758267592676026761267622676326764267652676626767267682676926770267712677226773267742677526776267772677826779267802678126782267832678426785267862678726788267892679026791267922679326794267952679626797267982679926800268012680226803268042680526806268072680826809268102681126812268132681426815268162681726818268192682026821268222682326824268252682626827268282682926830268312683226833268342683526836268372683826839268402684126842268432684426845268462684726848268492685026851268522685326854268552685626857268582685926860268612686226863268642686526866268672686826869268702687126872268732687426875268762687726878268792688026881268822688326884268852688626887268882688926890268912689226893268942689526896268972689826899269002690126902269032690426905269062690726908269092691026911269122691326914269152691626917269182691926920269212692226923269242692526926269272692826929269302693126932269332693426935269362693726938269392694026941269422694326944269452694626947269482694926950269512695226953269542695526956269572695826959269602696126962269632696426965269662696726968269692697026971269722697326974269752697626977269782697926980269812698226983269842698526986269872698826989269902699126992269932699426995269962699726998269992700027001270022700327004270052700627007270082700927010270112701227013270142701527016270172701827019270202702127022270232702427025270262702727028270292703027031270322703327034270352703627037270382703927040270412704227043270442704527046270472704827049270502705127052270532705427055270562705727058270592706027061270622706327064270652706627067270682706927070270712707227073270742707527076270772707827079270802708127082270832708427085270862708727088270892709027091270922709327094270952709627097270982709927100271012710227103271042710527106271072710827109271102711127112271132711427115271162711727118271192712027121271222712327124271252712627127271282712927130271312713227133271342713527136271372713827139271402714127142271432714427145271462714727148271492715027151271522715327154271552715627157271582715927160271612716227163271642716527166271672716827169271702717127172271732717427175271762717727178271792718027181271822718327184271852718627187271882718927190271912719227193271942719527196271972719827199272002720127202272032720427205272062720727208272092721027211272122721327214272152721627217272182721927220272212722227223272242722527226272272722827229272302723127232272332723427235272362723727238272392724027241272422724327244272452724627247272482724927250272512725227253272542725527256272572725827259272602726127262272632726427265272662726727268272692727027271272722727327274272752727627277272782727927280272812728227283272842728527286272872728827289272902729127292272932729427295272962729727298272992730027301273022730327304273052730627307273082730927310273112731227313273142731527316273172731827319273202732127322273232732427325273262732727328273292733027331273322733327334273352733627337273382733927340273412734227343273442734527346273472734827349273502735127352273532735427355273562735727358273592736027361273622736327364273652736627367273682736927370273712737227373273742737527376273772737827379273802738127382273832738427385273862738727388273892739027391273922739327394273952739627397273982739927400274012740227403274042740527406274072740827409274102741127412274132741427415274162741727418274192742027421274222742327424274252742627427274282742927430274312743227433274342743527436274372743827439274402744127442274432744427445274462744727448274492745027451274522745327454274552745627457274582745927460274612746227463274642746527466274672746827469274702747127472274732747427475274762747727478274792748027481274822748327484274852748627487274882748927490274912749227493274942749527496274972749827499275002750127502275032750427505275062750727508275092751027511275122751327514275152751627517275182751927520275212752227523275242752527526275272752827529275302753127532275332753427535275362753727538275392754027541275422754327544275452754627547275482754927550275512755227553275542755527556275572755827559275602756127562275632756427565275662756727568275692757027571275722757327574275752757627577275782757927580275812758227583275842758527586275872758827589275902759127592275932759427595275962759727598275992760027601276022760327604276052760627607276082760927610276112761227613276142761527616276172761827619276202762127622276232762427625276262762727628276292763027631276322763327634276352763627637276382763927640276412764227643276442764527646276472764827649276502765127652276532765427655276562765727658276592766027661276622766327664276652766627667276682766927670276712767227673276742767527676276772767827679276802768127682276832768427685276862768727688276892769027691276922769327694276952769627697276982769927700277012770227703277042770527706277072770827709277102771127712277132771427715277162771727718277192772027721277222772327724277252772627727277282772927730277312773227733277342773527736277372773827739277402774127742277432774427745277462774727748277492775027751277522775327754277552775627757277582775927760277612776227763277642776527766277672776827769277702777127772277732777427775277762777727778277792778027781277822778327784277852778627787277882778927790277912779227793277942779527796277972779827799278002780127802278032780427805278062780727808278092781027811278122781327814278152781627817278182781927820278212782227823278242782527826278272782827829278302783127832278332783427835278362783727838278392784027841278422784327844278452784627847278482784927850278512785227853278542785527856278572785827859278602786127862278632786427865278662786727868278692787027871278722787327874278752787627877278782787927880278812788227883278842788527886278872788827889278902789127892278932789427895278962789727898278992790027901279022790327904279052790627907279082790927910279112791227913279142791527916279172791827919279202792127922279232792427925279262792727928279292793027931279322793327934279352793627937279382793927940279412794227943279442794527946279472794827949279502795127952279532795427955279562795727958279592796027961279622796327964279652796627967279682796927970279712797227973279742797527976279772797827979279802798127982279832798427985279862798727988279892799027991279922799327994279952799627997279982799928000280012800228003280042800528006280072800828009280102801128012280132801428015280162801728018280192802028021280222802328024280252802628027280282802928030280312803228033280342803528036280372803828039280402804128042280432804428045280462804728048280492805028051280522805328054280552805628057280582805928060280612806228063280642806528066280672806828069280702807128072280732807428075280762807728078280792808028081280822808328084280852808628087280882808928090280912809228093280942809528096280972809828099281002810128102281032810428105281062810728108281092811028111281122811328114281152811628117281182811928120281212812228123281242812528126281272812828129281302813128132281332813428135281362813728138281392814028141281422814328144281452814628147281482814928150281512815228153281542815528156281572815828159281602816128162281632816428165281662816728168281692817028171281722817328174281752817628177281782817928180281812818228183281842818528186281872818828189281902819128192281932819428195281962819728198281992820028201282022820328204282052820628207282082820928210282112821228213282142821528216282172821828219282202822128222282232822428225282262822728228282292823028231282322823328234282352823628237282382823928240282412824228243282442824528246282472824828249282502825128252282532825428255282562825728258282592826028261282622826328264282652826628267282682826928270282712827228273282742827528276282772827828279282802828128282282832828428285282862828728288282892829028291282922829328294282952829628297282982829928300283012830228303283042830528306283072830828309283102831128312283132831428315283162831728318283192832028321283222832328324283252832628327283282832928330283312833228333283342833528336283372833828339283402834128342283432834428345283462834728348283492835028351283522835328354283552835628357283582835928360283612836228363283642836528366283672836828369283702837128372283732837428375283762837728378283792838028381283822838328384283852838628387283882838928390283912839228393283942839528396283972839828399284002840128402284032840428405284062840728408284092841028411284122841328414284152841628417284182841928420284212842228423284242842528426284272842828429284302843128432284332843428435284362843728438284392844028441284422844328444284452844628447284482844928450284512845228453284542845528456284572845828459284602846128462284632846428465284662846728468284692847028471284722847328474284752847628477284782847928480284812848228483284842848528486284872848828489284902849128492284932849428495284962849728498284992850028501285022850328504285052850628507285082850928510285112851228513285142851528516285172851828519285202852128522285232852428525285262852728528285292853028531285322853328534285352853628537285382853928540285412854228543285442854528546285472854828549285502855128552285532855428555285562855728558285592856028561285622856328564285652856628567285682856928570285712857228573285742857528576285772857828579285802858128582285832858428585285862858728588285892859028591285922859328594285952859628597285982859928600286012860228603286042860528606286072860828609286102861128612286132861428615286162861728618286192862028621286222862328624286252862628627286282862928630286312863228633286342863528636286372863828639286402864128642286432864428645286462864728648286492865028651286522865328654286552865628657286582865928660286612866228663286642866528666286672866828669286702867128672286732867428675286762867728678286792868028681286822868328684286852868628687286882868928690286912869228693286942869528696286972869828699287002870128702287032870428705287062870728708287092871028711287122871328714287152871628717287182871928720287212872228723287242872528726287272872828729287302873128732287332873428735287362873728738287392874028741287422874328744287452874628747287482874928750287512875228753287542875528756287572875828759287602876128762287632876428765287662876728768287692877028771287722877328774287752877628777287782877928780287812878228783287842878528786287872878828789287902879128792287932879428795287962879728798287992880028801288022880328804288052880628807288082880928810288112881228813288142881528816288172881828819288202882128822288232882428825288262882728828288292883028831288322883328834288352883628837288382883928840288412884228843288442884528846288472884828849288502885128852288532885428855288562885728858288592886028861288622886328864288652886628867288682886928870288712887228873288742887528876288772887828879288802888128882288832888428885288862888728888288892889028891288922889328894288952889628897288982889928900289012890228903289042890528906289072890828909289102891128912289132891428915289162891728918289192892028921289222892328924289252892628927289282892928930289312893228933289342893528936289372893828939289402894128942289432894428945289462894728948289492895028951289522895328954289552895628957289582895928960289612896228963289642896528966289672896828969289702897128972289732897428975289762897728978289792898028981289822898328984289852898628987289882898928990289912899228993289942899528996289972899828999290002900129002290032900429005290062900729008290092901029011290122901329014290152901629017290182901929020290212902229023290242902529026290272902829029290302903129032290332903429035290362903729038290392904029041290422904329044290452904629047290482904929050290512905229053290542905529056290572905829059290602906129062290632906429065290662906729068290692907029071290722907329074290752907629077290782907929080290812908229083290842908529086290872908829089290902909129092290932909429095290962909729098290992910029101291022910329104291052910629107291082910929110291112911229113291142911529116291172911829119291202912129122291232912429125291262912729128291292913029131291322913329134291352913629137291382913929140291412914229143291442914529146291472914829149291502915129152291532915429155291562915729158291592916029161291622916329164291652916629167291682916929170291712917229173291742917529176291772917829179291802918129182291832918429185291862918729188291892919029191291922919329194291952919629197291982919929200292012920229203292042920529206292072920829209292102921129212292132921429215292162921729218292192922029221292222922329224292252922629227292282922929230292312923229233292342923529236292372923829239292402924129242292432924429245292462924729248292492925029251292522925329254292552925629257292582925929260292612926229263292642926529266292672926829269292702927129272292732927429275292762927729278292792928029281292822928329284292852928629287292882928929290292912929229293292942929529296292972929829299293002930129302293032930429305293062930729308293092931029311293122931329314293152931629317293182931929320293212932229323293242932529326293272932829329293302933129332293332933429335293362933729338293392934029341293422934329344293452934629347293482934929350293512935229353293542935529356293572935829359293602936129362293632936429365293662936729368293692937029371293722937329374293752937629377293782937929380293812938229383293842938529386293872938829389293902939129392293932939429395293962939729398293992940029401294022940329404294052940629407294082940929410294112941229413294142941529416294172941829419294202942129422294232942429425294262942729428294292943029431294322943329434294352943629437294382943929440294412944229443294442944529446294472944829449294502945129452294532945429455294562945729458294592946029461294622946329464294652946629467294682946929470294712947229473294742947529476294772947829479294802948129482294832948429485294862948729488294892949029491294922949329494294952949629497294982949929500295012950229503295042950529506295072950829509295102951129512295132951429515295162951729518295192952029521295222952329524295252952629527295282952929530295312953229533295342953529536295372953829539295402954129542295432954429545295462954729548295492955029551295522955329554295552955629557295582955929560295612956229563295642956529566295672956829569295702957129572295732957429575295762957729578295792958029581295822958329584295852958629587295882958929590295912959229593295942959529596295972959829599296002960129602296032960429605296062960729608296092961029611296122961329614296152961629617296182961929620296212962229623296242962529626296272962829629296302963129632296332963429635296362963729638296392964029641296422964329644296452964629647296482964929650296512965229653296542965529656296572965829659296602966129662296632966429665296662966729668296692967029671296722967329674296752967629677296782967929680296812968229683296842968529686296872968829689296902969129692296932969429695296962969729698296992970029701297022970329704297052970629707297082970929710297112971229713297142971529716297172971829719297202972129722297232972429725297262972729728297292973029731297322973329734297352973629737297382973929740297412974229743297442974529746297472974829749297502975129752297532975429755297562975729758297592976029761297622976329764297652976629767297682976929770297712977229773297742977529776297772977829779297802978129782297832978429785297862978729788297892979029791297922979329794297952979629797297982979929800298012980229803298042980529806298072980829809298102981129812298132981429815298162981729818298192982029821298222982329824298252982629827298282982929830298312983229833298342983529836298372983829839298402984129842298432984429845298462984729848298492985029851298522985329854298552985629857298582985929860298612986229863298642986529866298672986829869298702987129872298732987429875298762987729878298792988029881298822988329884298852988629887298882988929890298912989229893298942989529896298972989829899299002990129902299032990429905299062990729908299092991029911299122991329914299152991629917299182991929920299212992229923299242992529926299272992829929299302993129932299332993429935299362993729938299392994029941299422994329944299452994629947299482994929950299512995229953299542995529956299572995829959299602996129962299632996429965299662996729968299692997029971299722997329974299752997629977299782997929980299812998229983299842998529986299872998829989299902999129992299932999429995299962999729998299993000030001300023000330004300053000630007300083000930010300113001230013300143001530016300173001830019300203002130022300233002430025300263002730028300293003030031300323003330034300353003630037300383003930040300413004230043300443004530046300473004830049300503005130052300533005430055300563005730058300593006030061300623006330064300653006630067300683006930070300713007230073300743007530076300773007830079300803008130082300833008430085300863008730088300893009030091300923009330094300953009630097300983009930100301013010230103301043010530106301073010830109301103011130112301133011430115301163011730118301193012030121301223012330124301253012630127301283012930130301313013230133301343013530136301373013830139301403014130142301433014430145301463014730148301493015030151301523015330154301553015630157301583015930160301613016230163301643016530166301673016830169301703017130172301733017430175301763017730178301793018030181301823018330184301853018630187301883018930190301913019230193301943019530196301973019830199302003020130202302033020430205302063020730208302093021030211302123021330214302153021630217302183021930220302213022230223302243022530226302273022830229302303023130232302333023430235302363023730238302393024030241302423024330244302453024630247302483024930250302513025230253302543025530256302573025830259302603026130262302633026430265302663026730268302693027030271302723027330274302753027630277302783027930280302813028230283302843028530286302873028830289302903029130292302933029430295302963029730298302993030030301303023030330304303053030630307303083030930310303113031230313303143031530316303173031830319303203032130322303233032430325303263032730328303293033030331303323033330334303353033630337303383033930340303413034230343303443034530346303473034830349303503035130352303533035430355303563035730358303593036030361303623036330364303653036630367303683036930370303713037230373303743037530376303773037830379303803038130382303833038430385303863038730388303893039030391303923039330394303953039630397303983039930400304013040230403304043040530406304073040830409304103041130412304133041430415304163041730418304193042030421304223042330424304253042630427304283042930430304313043230433304343043530436304373043830439304403044130442304433044430445304463044730448304493045030451304523045330454304553045630457304583045930460304613046230463304643046530466304673046830469304703047130472304733047430475304763047730478304793048030481304823048330484304853048630487304883048930490304913049230493304943049530496304973049830499305003050130502305033050430505305063050730508305093051030511305123051330514305153051630517305183051930520305213052230523305243052530526305273052830529305303053130532305333053430535305363053730538305393054030541305423054330544305453054630547305483054930550305513055230553305543055530556305573055830559305603056130562305633056430565305663056730568305693057030571305723057330574305753057630577305783057930580305813058230583305843058530586305873058830589305903059130592305933059430595305963059730598305993060030601306023060330604306053060630607306083060930610306113061230613306143061530616306173061830619306203062130622306233062430625306263062730628306293063030631306323063330634306353063630637306383063930640306413064230643306443064530646306473064830649306503065130652306533065430655306563065730658306593066030661306623066330664306653066630667306683066930670306713067230673306743067530676306773067830679306803068130682306833068430685306863068730688306893069030691306923069330694306953069630697306983069930700307013070230703307043070530706307073070830709307103071130712307133071430715307163071730718307193072030721307223072330724307253072630727307283072930730307313073230733307343073530736307373073830739307403074130742307433074430745307463074730748307493075030751307523075330754307553075630757307583075930760307613076230763307643076530766307673076830769307703077130772307733077430775307763077730778307793078030781307823078330784307853078630787307883078930790307913079230793307943079530796307973079830799308003080130802308033080430805308063080730808308093081030811308123081330814308153081630817308183081930820308213082230823308243082530826308273082830829308303083130832308333083430835308363083730838308393084030841308423084330844308453084630847308483084930850308513085230853308543085530856308573085830859308603086130862308633086430865308663086730868308693087030871308723087330874308753087630877308783087930880308813088230883308843088530886308873088830889308903089130892308933089430895308963089730898308993090030901309023090330904309053090630907309083090930910309113091230913309143091530916309173091830919309203092130922309233092430925309263092730928309293093030931309323093330934309353093630937309383093930940309413094230943309443094530946309473094830949309503095130952309533095430955309563095730958309593096030961309623096330964309653096630967309683096930970309713097230973309743097530976309773097830979309803098130982309833098430985309863098730988309893099030991309923099330994309953099630997309983099931000310013100231003310043100531006310073100831009310103101131012310133101431015310163101731018310193102031021310223102331024310253102631027310283102931030310313103231033310343103531036310373103831039310403104131042310433104431045310463104731048310493105031051310523105331054310553105631057310583105931060310613106231063310643106531066310673106831069310703107131072310733107431075310763107731078310793108031081310823108331084310853108631087310883108931090310913109231093310943109531096310973109831099311003110131102311033110431105311063110731108311093111031111311123111331114311153111631117311183111931120311213112231123311243112531126311273112831129311303113131132311333113431135311363113731138311393114031141311423114331144311453114631147311483114931150311513115231153311543115531156311573115831159311603116131162311633116431165311663116731168311693117031171311723117331174311753117631177311783117931180311813118231183311843118531186311873118831189311903119131192311933119431195311963119731198311993120031201312023120331204312053120631207312083120931210312113121231213312143121531216312173121831219312203122131222312233122431225312263122731228312293123031231312323123331234312353123631237312383123931240312413124231243312443124531246312473124831249312503125131252312533125431255312563125731258312593126031261312623126331264312653126631267312683126931270312713127231273312743127531276312773127831279312803128131282312833128431285312863128731288312893129031291312923129331294312953129631297312983129931300313013130231303313043130531306313073130831309313103131131312313133131431315313163131731318313193132031321313223132331324313253132631327313283132931330313313133231333313343133531336313373133831339313403134131342313433134431345313463134731348313493135031351313523135331354313553135631357313583135931360313613136231363313643136531366313673136831369313703137131372313733137431375313763137731378313793138031381313823138331384313853138631387313883138931390313913139231393313943139531396313973139831399314003140131402314033140431405314063140731408314093141031411314123141331414314153141631417314183141931420314213142231423314243142531426314273142831429314303143131432314333143431435314363143731438314393144031441314423144331444314453144631447314483144931450314513145231453314543145531456314573145831459314603146131462314633146431465314663146731468314693147031471314723147331474314753147631477314783147931480314813148231483314843148531486314873148831489314903149131492314933149431495314963149731498314993150031501315023150331504315053150631507315083150931510315113151231513315143151531516315173151831519315203152131522315233152431525315263152731528315293153031531315323153331534315353153631537315383153931540315413154231543315443154531546315473154831549315503155131552315533155431555315563155731558315593156031561315623156331564315653156631567315683156931570315713157231573315743157531576315773157831579315803158131582315833158431585315863158731588315893159031591315923159331594315953159631597315983159931600316013160231603316043160531606316073160831609316103161131612316133161431615316163161731618316193162031621316223162331624316253162631627316283162931630316313163231633316343163531636316373163831639316403164131642316433164431645316463164731648316493165031651316523165331654316553165631657316583165931660316613166231663316643166531666316673166831669316703167131672316733167431675316763167731678316793168031681316823168331684316853168631687316883168931690316913169231693316943169531696316973169831699317003170131702317033170431705317063170731708317093171031711317123171331714317153171631717317183171931720317213172231723317243172531726317273172831729317303173131732317333173431735317363173731738317393174031741317423174331744317453174631747317483174931750317513175231753317543175531756317573175831759317603176131762317633176431765317663176731768317693177031771317723177331774317753177631777317783177931780317813178231783317843178531786317873178831789317903179131792317933179431795317963179731798317993180031801318023180331804318053180631807318083180931810318113181231813318143181531816318173181831819318203182131822318233182431825318263182731828318293183031831318323183331834318353183631837318383183931840318413184231843318443184531846318473184831849318503185131852318533185431855318563185731858318593186031861318623186331864318653186631867318683186931870318713187231873318743187531876318773187831879318803188131882318833188431885318863188731888318893189031891318923189331894318953189631897318983189931900319013190231903319043190531906319073190831909319103191131912319133191431915319163191731918319193192031921319223192331924319253192631927319283192931930319313193231933319343193531936319373193831939319403194131942319433194431945319463194731948319493195031951319523195331954319553195631957319583195931960319613196231963319643196531966319673196831969319703197131972319733197431975319763197731978319793198031981319823198331984319853198631987319883198931990319913199231993319943199531996319973199831999320003200132002320033200432005320063200732008320093201032011320123201332014320153201632017320183201932020320213202232023320243202532026320273202832029320303203132032320333203432035320363203732038320393204032041320423204332044320453204632047320483204932050320513205232053320543205532056320573205832059320603206132062320633206432065320663206732068320693207032071320723207332074320753207632077320783207932080320813208232083320843208532086320873208832089320903209132092320933209432095320963209732098320993210032101321023210332104321053210632107321083210932110321113211232113321143211532116321173211832119321203212132122321233212432125321263212732128321293213032131321323213332134321353213632137321383213932140321413214232143321443214532146321473214832149321503215132152321533215432155321563215732158321593216032161321623216332164321653216632167321683216932170321713217232173321743217532176321773217832179321803218132182321833218432185321863218732188321893219032191321923219332194321953219632197321983219932200322013220232203322043220532206322073220832209322103221132212322133221432215322163221732218322193222032221322223222332224322253222632227322283222932230322313223232233322343223532236322373223832239322403224132242322433224432245322463224732248322493225032251322523225332254322553225632257322583225932260322613226232263322643226532266322673226832269322703227132272322733227432275322763227732278322793228032281322823228332284322853228632287322883228932290322913229232293322943229532296322973229832299323003230132302323033230432305323063230732308323093231032311323123231332314323153231632317323183231932320323213232232323323243232532326323273232832329323303233132332323333233432335323363233732338323393234032341323423234332344323453234632347323483234932350323513235232353323543235532356323573235832359323603236132362323633236432365323663236732368323693237032371323723237332374323753237632377323783237932380323813238232383323843238532386323873238832389323903239132392323933239432395323963239732398323993240032401324023240332404324053240632407324083240932410324113241232413324143241532416324173241832419324203242132422324233242432425324263242732428324293243032431324323243332434324353243632437324383243932440324413244232443324443244532446324473244832449324503245132452324533245432455324563245732458324593246032461324623246332464324653246632467324683246932470324713247232473324743247532476324773247832479324803248132482324833248432485324863248732488324893249032491324923249332494324953249632497324983249932500325013250232503325043250532506325073250832509325103251132512325133251432515325163251732518325193252032521325223252332524325253252632527325283252932530325313253232533325343253532536325373253832539325403254132542325433254432545325463254732548325493255032551325523255332554325553255632557325583255932560325613256232563325643256532566325673256832569325703257132572325733257432575325763257732578325793258032581325823258332584325853258632587325883258932590325913259232593325943259532596325973259832599326003260132602326033260432605326063260732608326093261032611326123261332614326153261632617326183261932620326213262232623326243262532626326273262832629326303263132632326333263432635326363263732638326393264032641326423264332644326453264632647326483264932650326513265232653326543265532656326573265832659326603266132662326633266432665326663266732668326693267032671326723267332674326753267632677326783267932680326813268232683326843268532686326873268832689326903269132692326933269432695326963269732698326993270032701327023270332704327053270632707327083270932710327113271232713327143271532716327173271832719327203272132722327233272432725327263272732728327293273032731327323273332734327353273632737327383273932740327413274232743327443274532746327473274832749327503275132752327533275432755327563275732758327593276032761327623276332764327653276632767327683276932770327713277232773327743277532776327773277832779327803278132782327833278432785327863278732788327893279032791327923279332794327953279632797327983279932800328013280232803328043280532806328073280832809328103281132812328133281432815328163281732818328193282032821328223282332824328253282632827328283282932830328313283232833328343283532836328373283832839328403284132842328433284432845328463284732848328493285032851328523285332854328553285632857328583285932860328613286232863328643286532866328673286832869328703287132872328733287432875328763287732878328793288032881328823288332884328853288632887328883288932890328913289232893328943289532896328973289832899329003290132902329033290432905329063290732908329093291032911329123291332914329153291632917329183291932920329213292232923329243292532926329273292832929329303293132932329333293432935329363293732938329393294032941329423294332944329453294632947329483294932950329513295232953329543295532956329573295832959329603296132962329633296432965329663296732968329693297032971329723297332974329753297632977329783297932980329813298232983329843298532986329873298832989329903299132992329933299432995329963299732998329993300033001330023300333004330053300633007330083300933010330113301233013330143301533016330173301833019330203302133022330233302433025330263302733028330293303033031330323303333034330353303633037330383303933040330413304233043330443304533046330473304833049330503305133052330533305433055330563305733058330593306033061330623306333064330653306633067330683306933070330713307233073330743307533076330773307833079330803308133082330833308433085330863308733088330893309033091330923309333094330953309633097330983309933100331013310233103331043310533106331073310833109331103311133112331133311433115331163311733118331193312033121331223312333124331253312633127331283312933130331313313233133331343313533136331373313833139331403314133142331433314433145331463314733148331493315033151331523315333154331553315633157331583315933160331613316233163331643316533166331673316833169331703317133172331733317433175331763317733178331793318033181331823318333184331853318633187331883318933190331913319233193331943319533196331973319833199332003320133202332033320433205332063320733208332093321033211332123321333214332153321633217332183321933220332213322233223332243322533226332273322833229332303323133232332333323433235332363323733238332393324033241332423324333244332453324633247332483324933250332513325233253332543325533256332573325833259332603326133262332633326433265332663326733268332693327033271332723327333274332753327633277332783327933280332813328233283332843328533286332873328833289332903329133292332933329433295332963329733298332993330033301333023330333304333053330633307333083330933310333113331233313333143331533316333173331833319333203332133322333233332433325333263332733328333293333033331333323333333334333353333633337333383333933340333413334233343333443334533346333473334833349333503335133352333533335433355333563335733358333593336033361333623336333364333653336633367333683336933370333713337233373333743337533376333773337833379333803338133382333833338433385333863338733388333893339033391333923339333394333953339633397333983339933400334013340233403334043340533406334073340833409334103341133412334133341433415334163341733418334193342033421334223342333424334253342633427334283342933430334313343233433334343343533436334373343833439334403344133442334433344433445334463344733448334493345033451334523345333454334553345633457334583345933460334613346233463334643346533466334673346833469334703347133472334733347433475334763347733478334793348033481334823348333484334853348633487334883348933490334913349233493334943349533496334973349833499335003350133502335033350433505335063350733508335093351033511335123351333514335153351633517335183351933520335213352233523335243352533526335273352833529335303353133532335333353433535335363353733538335393354033541335423354333544335453354633547335483354933550335513355233553335543355533556335573355833559335603356133562335633356433565335663356733568335693357033571335723357333574335753357633577335783357933580335813358233583335843358533586335873358833589335903359133592335933359433595335963359733598335993360033601336023360333604336053360633607336083360933610336113361233613336143361533616336173361833619336203362133622336233362433625336263362733628336293363033631336323363333634336353363633637336383363933640336413364233643336443364533646336473364833649336503365133652336533365433655336563365733658336593366033661336623366333664336653366633667336683366933670336713367233673336743367533676336773367833679336803368133682336833368433685336863368733688336893369033691336923369333694336953369633697336983369933700337013370233703337043370533706337073370833709337103371133712337133371433715337163371733718337193372033721337223372333724337253372633727337283372933730337313373233733337343373533736337373373833739337403374133742337433374433745337463374733748337493375033751337523375333754337553375633757337583375933760337613376233763337643376533766337673376833769337703377133772337733377433775337763377733778337793378033781337823378333784337853378633787337883378933790337913379233793337943379533796337973379833799338003380133802338033380433805338063380733808338093381033811338123381333814338153381633817338183381933820338213382233823338243382533826338273382833829338303383133832338333383433835338363383733838338393384033841338423384333844338453384633847338483384933850338513385233853338543385533856338573385833859338603386133862338633386433865338663386733868338693387033871338723387333874338753387633877338783387933880338813388233883338843388533886338873388833889338903389133892338933389433895338963389733898338993390033901339023390333904339053390633907339083390933910339113391233913339143391533916339173391833919339203392133922339233392433925339263392733928339293393033931339323393333934339353393633937339383393933940339413394233943339443394533946339473394833949339503395133952339533395433955339563395733958339593396033961339623396333964339653396633967339683396933970339713397233973339743397533976339773397833979339803398133982339833398433985339863398733988339893399033991339923399333994339953399633997339983399934000340013400234003340043400534006340073400834009340103401134012340133401434015340163401734018340193402034021340223402334024340253402634027340283402934030340313403234033340343403534036340373403834039340403404134042340433404434045340463404734048340493405034051340523405334054340553405634057340583405934060340613406234063340643406534066340673406834069340703407134072340733407434075340763407734078340793408034081340823408334084340853408634087340883408934090340913409234093340943409534096340973409834099341003410134102341033410434105341063410734108341093411034111341123411334114341153411634117341183411934120341213412234123341243412534126341273412834129341303413134132341333413434135341363413734138341393414034141341423414334144341453414634147341483414934150341513415234153341543415534156341573415834159341603416134162341633416434165341663416734168341693417034171341723417334174341753417634177341783417934180341813418234183341843418534186341873418834189341903419134192341933419434195341963419734198341993420034201342023420334204342053420634207342083420934210342113421234213342143421534216342173421834219342203422134222342233422434225342263422734228342293423034231342323423334234342353423634237342383423934240342413424234243342443424534246342473424834249342503425134252342533425434255342563425734258342593426034261342623426334264342653426634267342683426934270342713427234273342743427534276342773427834279342803428134282342833428434285342863428734288342893429034291342923429334294342953429634297342983429934300343013430234303343043430534306343073430834309343103431134312343133431434315343163431734318343193432034321343223432334324343253432634327343283432934330343313433234333343343433534336343373433834339343403434134342343433434434345343463434734348343493435034351343523435334354343553435634357343583435934360343613436234363343643436534366343673436834369343703437134372343733437434375343763437734378343793438034381343823438334384343853438634387343883438934390343913439234393343943439534396343973439834399344003440134402344033440434405344063440734408344093441034411344123441334414344153441634417344183441934420344213442234423344243442534426344273442834429344303443134432344333443434435344363443734438344393444034441344423444334444344453444634447344483444934450344513445234453344543445534456344573445834459344603446134462344633446434465344663446734468344693447034471344723447334474344753447634477344783447934480344813448234483344843448534486344873448834489344903449134492344933449434495344963449734498344993450034501345023450334504345053450634507345083450934510345113451234513345143451534516345173451834519345203452134522345233452434525345263452734528345293453034531345323453334534345353453634537345383453934540345413454234543345443454534546345473454834549345503455134552345533455434555345563455734558345593456034561345623456334564345653456634567345683456934570345713457234573345743457534576345773457834579345803458134582345833458434585345863458734588345893459034591345923459334594345953459634597345983459934600346013460234603346043460534606346073460834609346103461134612346133461434615346163461734618346193462034621346223462334624346253462634627346283462934630346313463234633346343463534636346373463834639346403464134642346433464434645346463464734648346493465034651346523465334654346553465634657346583465934660346613466234663346643466534666346673466834669346703467134672346733467434675346763467734678346793468034681346823468334684346853468634687346883468934690346913469234693346943469534696346973469834699347003470134702347033470434705347063470734708347093471034711347123471334714347153471634717347183471934720347213472234723347243472534726347273472834729347303473134732347333473434735347363473734738347393474034741347423474334744347453474634747347483474934750347513475234753347543475534756347573475834759347603476134762347633476434765347663476734768347693477034771347723477334774347753477634777347783477934780347813478234783347843478534786347873478834789347903479134792347933479434795347963479734798347993480034801348023480334804348053480634807348083480934810348113481234813348143481534816348173481834819348203482134822348233482434825348263482734828348293483034831348323483334834348353483634837348383483934840348413484234843348443484534846348473484834849348503485134852348533485434855348563485734858348593486034861348623486334864348653486634867348683486934870348713487234873348743487534876348773487834879348803488134882348833488434885348863488734888348893489034891348923489334894348953489634897348983489934900349013490234903349043490534906349073490834909349103491134912349133491434915349163491734918349193492034921349223492334924349253492634927349283492934930349313493234933349343493534936349373493834939349403494134942349433494434945349463494734948349493495034951349523495334954349553495634957349583495934960349613496234963349643496534966349673496834969349703497134972349733497434975349763497734978349793498034981349823498334984349853498634987349883498934990349913499234993349943499534996349973499834999350003500135002350033500435005350063500735008350093501035011350123501335014350153501635017350183501935020350213502235023350243502535026350273502835029350303503135032350333503435035350363503735038350393504035041350423504335044350453504635047350483504935050350513505235053350543505535056350573505835059350603506135062350633506435065350663506735068350693507035071350723507335074350753507635077350783507935080350813508235083350843508535086350873508835089350903509135092350933509435095350963509735098350993510035101351023510335104351053510635107351083510935110351113511235113351143511535116351173511835119351203512135122351233512435125351263512735128351293513035131351323513335134351353513635137351383513935140351413514235143351443514535146351473514835149351503515135152351533515435155351563515735158351593516035161351623516335164351653516635167351683516935170351713517235173351743517535176351773517835179351803518135182351833518435185351863518735188351893519035191351923519335194351953519635197351983519935200352013520235203352043520535206352073520835209352103521135212352133521435215352163521735218352193522035221352223522335224352253522635227352283522935230352313523235233352343523535236352373523835239352403524135242352433524435245352463524735248352493525035251352523525335254352553525635257352583525935260352613526235263352643526535266352673526835269352703527135272352733527435275352763527735278352793528035281352823528335284352853528635287352883528935290352913529235293352943529535296352973529835299353003530135302353033530435305353063530735308353093531035311353123531335314353153531635317353183531935320353213532235323353243532535326353273532835329353303533135332353333533435335353363533735338353393534035341353423534335344353453534635347353483534935350353513535235353353543535535356353573535835359353603536135362353633536435365353663536735368353693537035371353723537335374353753537635377353783537935380353813538235383353843538535386353873538835389353903539135392353933539435395353963539735398353993540035401354023540335404354053540635407354083540935410354113541235413354143541535416354173541835419354203542135422354233542435425354263542735428354293543035431354323543335434354353543635437354383543935440354413544235443354443544535446354473544835449354503545135452354533545435455354563545735458354593546035461354623546335464354653546635467354683546935470354713547235473354743547535476354773547835479354803548135482354833548435485354863548735488354893549035491354923549335494354953549635497354983549935500355013550235503355043550535506355073550835509355103551135512355133551435515355163551735518355193552035521355223552335524355253552635527355283552935530355313553235533355343553535536355373553835539355403554135542355433554435545355463554735548355493555035551355523555335554355553555635557355583555935560355613556235563355643556535566355673556835569355703557135572355733557435575355763557735578355793558035581355823558335584355853558635587355883558935590355913559235593355943559535596355973559835599356003560135602356033560435605356063560735608356093561035611356123561335614356153561635617356183561935620356213562235623356243562535626356273562835629356303563135632356333563435635356363563735638356393564035641356423564335644356453564635647356483564935650356513565235653356543565535656356573565835659356603566135662356633566435665356663566735668356693567035671356723567335674356753567635677356783567935680356813568235683356843568535686356873568835689356903569135692356933569435695356963569735698356993570035701357023570335704357053570635707357083570935710357113571235713357143571535716357173571835719357203572135722357233572435725357263572735728357293573035731357323573335734357353573635737357383573935740357413574235743357443574535746357473574835749357503575135752357533575435755357563575735758357593576035761357623576335764357653576635767357683576935770357713577235773357743577535776357773577835779357803578135782357833578435785357863578735788357893579035791357923579335794357953579635797357983579935800358013580235803358043580535806358073580835809358103581135812358133581435815358163581735818358193582035821358223582335824358253582635827358283582935830358313583235833358343583535836358373583835839358403584135842358433584435845358463584735848358493585035851358523585335854358553585635857358583585935860358613586235863358643586535866358673586835869358703587135872358733587435875358763587735878358793588035881358823588335884358853588635887358883588935890358913589235893358943589535896358973589835899359003590135902359033590435905359063590735908359093591035911359123591335914359153591635917359183591935920359213592235923359243592535926359273592835929359303593135932359333593435935359363593735938359393594035941359423594335944359453594635947359483594935950359513595235953359543595535956359573595835959359603596135962359633596435965359663596735968359693597035971359723597335974359753597635977359783597935980359813598235983359843598535986359873598835989359903599135992359933599435995359963599735998359993600036001360023600336004360053600636007360083600936010360113601236013360143601536016360173601836019360203602136022360233602436025360263602736028360293603036031360323603336034360353603636037360383603936040360413604236043360443604536046360473604836049360503605136052360533605436055360563605736058360593606036061360623606336064360653606636067360683606936070360713607236073360743607536076360773607836079360803608136082360833608436085360863608736088360893609036091360923609336094360953609636097360983609936100361013610236103361043610536106361073610836109361103611136112361133611436115361163611736118361193612036121361223612336124361253612636127361283612936130361313613236133361343613536136361373613836139361403614136142361433614436145361463614736148361493615036151361523615336154361553615636157361583615936160361613616236163361643616536166361673616836169361703617136172361733617436175361763617736178361793618036181361823618336184361853618636187361883618936190361913619236193361943619536196361973619836199362003620136202362033620436205362063620736208362093621036211362123621336214362153621636217362183621936220362213622236223362243622536226362273622836229362303623136232362333623436235362363623736238362393624036241362423624336244362453624636247362483624936250362513625236253362543625536256362573625836259362603626136262362633626436265362663626736268362693627036271362723627336274362753627636277362783627936280362813628236283362843628536286362873628836289362903629136292362933629436295362963629736298362993630036301363023630336304363053630636307363083630936310363113631236313363143631536316363173631836319363203632136322363233632436325363263632736328363293633036331363323633336334363353633636337363383633936340363413634236343363443634536346363473634836349363503635136352363533635436355363563635736358363593636036361363623636336364363653636636367363683636936370363713637236373363743637536376363773637836379363803638136382363833638436385363863638736388363893639036391363923639336394363953639636397363983639936400364013640236403364043640536406364073640836409364103641136412364133641436415364163641736418364193642036421364223642336424364253642636427364283642936430364313643236433364343643536436364373643836439364403644136442364433644436445364463644736448364493645036451364523645336454364553645636457364583645936460364613646236463364643646536466364673646836469364703647136472364733647436475364763647736478364793648036481364823648336484364853648636487364883648936490364913649236493364943649536496364973649836499365003650136502365033650436505365063650736508365093651036511365123651336514365153651636517365183651936520365213652236523365243652536526365273652836529365303653136532365333653436535365363653736538365393654036541365423654336544365453654636547365483654936550365513655236553365543655536556365573655836559365603656136562365633656436565365663656736568365693657036571365723657336574365753657636577365783657936580365813658236583365843658536586365873658836589365903659136592365933659436595365963659736598365993660036601366023660336604366053660636607366083660936610366113661236613366143661536616366173661836619366203662136622366233662436625366263662736628366293663036631366323663336634366353663636637366383663936640366413664236643366443664536646366473664836649366503665136652366533665436655366563665736658366593666036661366623666336664366653666636667366683666936670366713667236673366743667536676366773667836679366803668136682366833668436685366863668736688366893669036691366923669336694366953669636697366983669936700367013670236703367043670536706367073670836709367103671136712367133671436715367163671736718367193672036721367223672336724367253672636727367283672936730367313673236733367343673536736367373673836739367403674136742367433674436745367463674736748367493675036751367523675336754367553675636757367583675936760367613676236763367643676536766367673676836769367703677136772367733677436775367763677736778367793678036781367823678336784367853678636787367883678936790367913679236793367943679536796367973679836799368003680136802368033680436805368063680736808368093681036811368123681336814368153681636817368183681936820368213682236823368243682536826368273682836829368303683136832368333683436835368363683736838368393684036841368423684336844368453684636847368483684936850368513685236853368543685536856368573685836859368603686136862368633686436865368663686736868368693687036871368723687336874368753687636877368783687936880368813688236883368843688536886368873688836889368903689136892368933689436895368963689736898368993690036901369023690336904369053690636907369083690936910369113691236913369143691536916369173691836919369203692136922369233692436925369263692736928369293693036931369323693336934369353693636937369383693936940369413694236943369443694536946369473694836949369503695136952369533695436955369563695736958369593696036961369623696336964369653696636967369683696936970369713697236973369743697536976369773697836979369803698136982369833698436985369863698736988369893699036991369923699336994369953699636997369983699937000370013700237003370043700537006370073700837009370103701137012370133701437015370163701737018370193702037021370223702337024370253702637027370283702937030370313703237033370343703537036370373703837039370403704137042370433704437045370463704737048370493705037051370523705337054370553705637057370583705937060370613706237063370643706537066370673706837069370703707137072370733707437075370763707737078370793708037081370823708337084370853708637087370883708937090370913709237093370943709537096370973709837099371003710137102371033710437105371063710737108371093711037111371123711337114371153711637117371183711937120371213712237123371243712537126371273712837129371303713137132371333713437135371363713737138371393714037141371423714337144371453714637147371483714937150371513715237153371543715537156371573715837159371603716137162371633716437165371663716737168371693717037171371723717337174371753717637177371783717937180371813718237183371843718537186371873718837189371903719137192371933719437195371963719737198371993720037201372023720337204372053720637207372083720937210372113721237213372143721537216372173721837219372203722137222372233722437225372263722737228372293723037231372323723337234372353723637237372383723937240372413724237243372443724537246372473724837249372503725137252372533725437255372563725737258372593726037261372623726337264372653726637267372683726937270372713727237273372743727537276372773727837279372803728137282372833728437285372863728737288372893729037291372923729337294372953729637297372983729937300373013730237303373043730537306373073730837309373103731137312373133731437315373163731737318373193732037321373223732337324373253732637327373283732937330373313733237333373343733537336373373733837339373403734137342373433734437345373463734737348373493735037351373523735337354373553735637357373583735937360373613736237363373643736537366373673736837369373703737137372373733737437375373763737737378373793738037381373823738337384373853738637387373883738937390373913739237393373943739537396373973739837399374003740137402374033740437405374063740737408374093741037411374123741337414374153741637417374183741937420374213742237423374243742537426374273742837429374303743137432374333743437435374363743737438374393744037441374423744337444374453744637447374483744937450374513745237453374543745537456374573745837459374603746137462374633746437465374663746737468374693747037471374723747337474374753747637477374783747937480374813748237483374843748537486374873748837489374903749137492374933749437495374963749737498374993750037501375023750337504375053750637507375083750937510375113751237513375143751537516375173751837519375203752137522375233752437525375263752737528375293753037531375323753337534375353753637537375383753937540375413754237543375443754537546375473754837549375503755137552375533755437555375563755737558375593756037561375623756337564375653756637567375683756937570375713757237573375743757537576375773757837579375803758137582375833758437585375863758737588375893759037591375923759337594375953759637597375983759937600376013760237603376043760537606376073760837609376103761137612376133761437615376163761737618376193762037621376223762337624376253762637627376283762937630376313763237633376343763537636376373763837639376403764137642376433764437645376463764737648376493765037651376523765337654376553765637657376583765937660376613766237663376643766537666376673766837669376703767137672376733767437675376763767737678376793768037681376823768337684376853768637687376883768937690376913769237693376943769537696376973769837699377003770137702377033770437705377063770737708377093771037711377123771337714377153771637717377183771937720377213772237723377243772537726377273772837729377303773137732377333773437735377363773737738377393774037741377423774337744377453774637747377483774937750377513775237753377543775537756377573775837759377603776137762377633776437765377663776737768377693777037771377723777337774377753777637777377783777937780377813778237783377843778537786377873778837789377903779137792377933779437795377963779737798377993780037801378023780337804378053780637807378083780937810378113781237813378143781537816378173781837819378203782137822378233782437825378263782737828378293783037831378323783337834378353783637837378383783937840378413784237843378443784537846378473784837849378503785137852378533785437855378563785737858378593786037861378623786337864378653786637867378683786937870378713787237873378743787537876378773787837879378803788137882378833788437885378863788737888378893789037891378923789337894378953789637897378983789937900379013790237903379043790537906379073790837909379103791137912379133791437915379163791737918379193792037921379223792337924379253792637927379283792937930379313793237933379343793537936379373793837939379403794137942379433794437945379463794737948379493795037951379523795337954379553795637957379583795937960379613796237963379643796537966379673796837969379703797137972379733797437975379763797737978379793798037981379823798337984379853798637987379883798937990379913799237993379943799537996379973799837999380003800138002380033800438005380063800738008380093801038011380123801338014380153801638017380183801938020380213802238023380243802538026380273802838029380303803138032380333803438035380363803738038380393804038041380423804338044380453804638047380483804938050380513805238053380543805538056380573805838059380603806138062380633806438065380663806738068380693807038071380723807338074380753807638077380783807938080380813808238083380843808538086380873808838089380903809138092380933809438095380963809738098380993810038101381023810338104381053810638107381083810938110381113811238113381143811538116381173811838119381203812138122381233812438125381263812738128381293813038131381323813338134381353813638137381383813938140381413814238143381443814538146381473814838149381503815138152381533815438155381563815738158381593816038161381623816338164381653816638167381683816938170381713817238173381743817538176381773817838179381803818138182381833818438185381863818738188381893819038191381923819338194381953819638197381983819938200382013820238203382043820538206382073820838209382103821138212382133821438215382163821738218382193822038221382223822338224382253822638227382283822938230382313823238233382343823538236382373823838239382403824138242382433824438245382463824738248382493825038251382523825338254382553825638257382583825938260382613826238263382643826538266382673826838269382703827138272382733827438275382763827738278382793828038281382823828338284382853828638287382883828938290382913829238293382943829538296382973829838299383003830138302383033830438305383063830738308383093831038311383123831338314383153831638317383183831938320383213832238323383243832538326383273832838329383303833138332383333833438335383363833738338383393834038341383423834338344383453834638347383483834938350383513835238353383543835538356383573835838359383603836138362383633836438365383663836738368383693837038371383723837338374383753837638377383783837938380383813838238383383843838538386383873838838389383903839138392383933839438395383963839738398383993840038401384023840338404384053840638407384083840938410384113841238413384143841538416384173841838419384203842138422384233842438425384263842738428384293843038431384323843338434384353843638437384383843938440384413844238443384443844538446384473844838449384503845138452384533845438455384563845738458384593846038461384623846338464384653846638467384683846938470384713847238473384743847538476384773847838479384803848138482384833848438485384863848738488384893849038491384923849338494384953849638497384983849938500385013850238503385043850538506385073850838509385103851138512385133851438515385163851738518385193852038521385223852338524385253852638527385283852938530385313853238533385343853538536385373853838539385403854138542385433854438545385463854738548385493855038551385523855338554385553855638557385583855938560385613856238563385643856538566385673856838569385703857138572385733857438575385763857738578385793858038581385823858338584385853858638587385883858938590385913859238593385943859538596385973859838599386003860138602386033860438605386063860738608386093861038611386123861338614386153861638617386183861938620386213862238623386243862538626386273862838629386303863138632386333863438635386363863738638386393864038641386423864338644386453864638647386483864938650386513865238653386543865538656386573865838659386603866138662386633866438665386663866738668386693867038671386723867338674386753867638677386783867938680386813868238683386843868538686386873868838689386903869138692386933869438695386963869738698386993870038701387023870338704387053870638707387083870938710387113871238713387143871538716387173871838719387203872138722387233872438725387263872738728387293873038731387323873338734387353873638737387383873938740387413874238743387443874538746387473874838749387503875138752387533875438755387563875738758387593876038761387623876338764387653876638767387683876938770387713877238773387743877538776387773877838779387803878138782387833878438785387863878738788387893879038791387923879338794387953879638797387983879938800388013880238803388043880538806388073880838809388103881138812388133881438815388163881738818388193882038821388223882338824388253882638827388283882938830388313883238833388343883538836388373883838839388403884138842388433884438845388463884738848388493885038851388523885338854388553885638857388583885938860388613886238863388643886538866388673886838869388703887138872388733887438875388763887738878388793888038881388823888338884388853888638887388883888938890388913889238893388943889538896388973889838899389003890138902389033890438905389063890738908389093891038911389123891338914389153891638917389183891938920389213892238923389243892538926389273892838929389303893138932389333893438935389363893738938389393894038941389423894338944389453894638947389483894938950389513895238953389543895538956389573895838959389603896138962389633896438965389663896738968389693897038971389723897338974389753897638977389783897938980389813898238983389843898538986389873898838989389903899138992389933899438995389963899738998389993900039001390023900339004390053900639007390083900939010390113901239013390143901539016390173901839019390203902139022390233902439025390263902739028390293903039031390323903339034390353903639037390383903939040390413904239043390443904539046390473904839049390503905139052390533905439055390563905739058390593906039061390623906339064390653906639067390683906939070390713907239073390743907539076390773907839079390803908139082390833908439085390863908739088390893909039091390923909339094390953909639097390983909939100391013910239103391043910539106391073910839109391103911139112391133911439115391163911739118391193912039121391223912339124391253912639127391283912939130391313913239133391343913539136391373913839139391403914139142391433914439145391463914739148391493915039151391523915339154391553915639157391583915939160391613916239163391643916539166391673916839169391703917139172391733917439175391763917739178391793918039181391823918339184391853918639187391883918939190391913919239193391943919539196391973919839199392003920139202392033920439205392063920739208392093921039211392123921339214392153921639217392183921939220392213922239223392243922539226392273922839229392303923139232392333923439235392363923739238392393924039241392423924339244392453924639247392483924939250392513925239253392543925539256392573925839259392603926139262392633926439265392663926739268392693927039271392723927339274392753927639277392783927939280392813928239283392843928539286392873928839289392903929139292392933929439295392963929739298392993930039301393023930339304393053930639307393083930939310393113931239313393143931539316393173931839319393203932139322393233932439325393263932739328393293933039331393323933339334393353933639337393383933939340393413934239343393443934539346393473934839349393503935139352393533935439355393563935739358393593936039361393623936339364393653936639367393683936939370393713937239373393743937539376393773937839379393803938139382393833938439385393863938739388393893939039391393923939339394393953939639397393983939939400394013940239403394043940539406394073940839409394103941139412394133941439415394163941739418394193942039421394223942339424394253942639427394283942939430394313943239433394343943539436394373943839439394403944139442394433944439445394463944739448394493945039451394523945339454394553945639457394583945939460394613946239463394643946539466394673946839469394703947139472394733947439475394763947739478394793948039481394823948339484394853948639487394883948939490394913949239493394943949539496394973949839499395003950139502395033950439505395063950739508395093951039511395123951339514395153951639517395183951939520395213952239523395243952539526395273952839529395303953139532395333953439535395363953739538395393954039541395423954339544395453954639547395483954939550395513955239553395543955539556395573955839559395603956139562395633956439565395663956739568395693957039571395723957339574395753957639577395783957939580395813958239583395843958539586395873958839589395903959139592395933959439595395963959739598395993960039601396023960339604396053960639607396083960939610396113961239613396143961539616396173961839619396203962139622396233962439625396263962739628396293963039631396323963339634396353963639637396383963939640396413964239643396443964539646396473964839649396503965139652396533965439655396563965739658396593966039661396623966339664396653966639667396683966939670396713967239673396743967539676396773967839679396803968139682396833968439685396863968739688396893969039691396923969339694396953969639697396983969939700397013970239703397043970539706397073970839709397103971139712397133971439715397163971739718397193972039721397223972339724397253972639727397283972939730397313973239733397343973539736397373973839739397403974139742397433974439745397463974739748397493975039751397523975339754397553975639757397583975939760397613976239763397643976539766397673976839769397703977139772397733977439775397763977739778397793978039781397823978339784397853978639787397883978939790397913979239793397943979539796397973979839799398003980139802398033980439805398063980739808398093981039811398123981339814398153981639817398183981939820398213982239823398243982539826398273982839829398303983139832398333983439835398363983739838398393984039841398423984339844398453984639847398483984939850398513985239853398543985539856398573985839859398603986139862398633986439865398663986739868398693987039871398723987339874398753987639877398783987939880398813988239883398843988539886398873988839889398903989139892398933989439895398963989739898398993990039901399023990339904399053990639907399083990939910399113991239913399143991539916399173991839919399203992139922399233992439925399263992739928399293993039931399323993339934399353993639937399383993939940399413994239943399443994539946399473994839949399503995139952399533995439955399563995739958399593996039961399623996339964399653996639967399683996939970399713997239973399743997539976399773997839979399803998139982399833998439985399863998739988399893999039991399923999339994399953999639997399983999940000400014000240003400044000540006400074000840009400104001140012400134001440015400164001740018400194002040021400224002340024400254002640027400284002940030400314003240033400344003540036400374003840039400404004140042400434004440045400464004740048400494005040051400524005340054400554005640057400584005940060400614006240063400644006540066400674006840069400704007140072400734007440075400764007740078400794008040081400824008340084400854008640087400884008940090400914009240093400944009540096400974009840099401004010140102401034010440105401064010740108401094011040111401124011340114401154011640117401184011940120401214012240123401244012540126401274012840129401304013140132401334013440135401364013740138401394014040141401424014340144401454014640147401484014940150401514015240153401544015540156401574015840159401604016140162401634016440165401664016740168401694017040171401724017340174401754017640177401784017940180401814018240183401844018540186401874018840189401904019140192401934019440195401964019740198401994020040201402024020340204402054020640207402084020940210402114021240213402144021540216402174021840219402204022140222402234022440225402264022740228402294023040231402324023340234402354023640237402384023940240402414024240243402444024540246402474024840249402504025140252402534025440255402564025740258402594026040261402624026340264402654026640267402684026940270402714027240273402744027540276402774027840279402804028140282402834028440285402864028740288402894029040291402924029340294402954029640297402984029940300403014030240303403044030540306403074030840309403104031140312403134031440315403164031740318403194032040321403224032340324403254032640327403284032940330403314033240333403344033540336403374033840339403404034140342403434034440345403464034740348403494035040351403524035340354403554035640357403584035940360403614036240363403644036540366403674036840369403704037140372403734037440375403764037740378403794038040381403824038340384403854038640387403884038940390403914039240393403944039540396403974039840399404004040140402404034040440405404064040740408404094041040411404124041340414404154041640417404184041940420404214042240423404244042540426404274042840429404304043140432404334043440435404364043740438404394044040441404424044340444404454044640447404484044940450404514045240453404544045540456404574045840459404604046140462404634046440465404664046740468404694047040471404724047340474404754047640477404784047940480404814048240483404844048540486404874048840489404904049140492404934049440495404964049740498404994050040501405024050340504405054050640507405084050940510405114051240513405144051540516405174051840519405204052140522405234052440525405264052740528405294053040531405324053340534405354053640537405384053940540405414054240543405444054540546405474054840549405504055140552405534055440555405564055740558405594056040561405624056340564405654056640567405684056940570405714057240573405744057540576405774057840579405804058140582405834058440585405864058740588405894059040591405924059340594405954059640597405984059940600406014060240603406044060540606406074060840609406104061140612406134061440615406164061740618406194062040621406224062340624406254062640627406284062940630406314063240633406344063540636406374063840639406404064140642406434064440645406464064740648406494065040651406524065340654406554065640657406584065940660406614066240663406644066540666406674066840669406704067140672406734067440675406764067740678406794068040681406824068340684406854068640687406884068940690406914069240693406944069540696406974069840699407004070140702407034070440705407064070740708407094071040711407124071340714407154071640717407184071940720407214072240723407244072540726407274072840729407304073140732407334073440735407364073740738407394074040741407424074340744407454074640747407484074940750407514075240753407544075540756407574075840759407604076140762407634076440765407664076740768407694077040771407724077340774407754077640777407784077940780407814078240783407844078540786407874078840789407904079140792407934079440795407964079740798407994080040801408024080340804408054080640807408084080940810408114081240813408144081540816408174081840819408204082140822408234082440825408264082740828408294083040831408324083340834408354083640837408384083940840408414084240843408444084540846408474084840849408504085140852408534085440855408564085740858408594086040861408624086340864408654086640867408684086940870408714087240873408744087540876408774087840879408804088140882408834088440885408864088740888408894089040891408924089340894408954089640897408984089940900409014090240903409044090540906409074090840909409104091140912409134091440915409164091740918409194092040921409224092340924409254092640927409284092940930409314093240933409344093540936409374093840939409404094140942409434094440945409464094740948409494095040951409524095340954409554095640957409584095940960409614096240963409644096540966409674096840969409704097140972409734097440975409764097740978409794098040981409824098340984409854098640987409884098940990409914099240993409944099540996409974099840999410004100141002410034100441005410064100741008410094101041011410124101341014410154101641017410184101941020410214102241023410244102541026410274102841029410304103141032410334103441035410364103741038410394104041041410424104341044410454104641047410484104941050410514105241053410544105541056410574105841059410604106141062410634106441065410664106741068410694107041071410724107341074410754107641077410784107941080410814108241083410844108541086410874108841089410904109141092410934109441095410964109741098410994110041101411024110341104411054110641107411084110941110411114111241113411144111541116411174111841119411204112141122411234112441125411264112741128411294113041131411324113341134411354113641137411384113941140411414114241143411444114541146411474114841149411504115141152411534115441155411564115741158411594116041161411624116341164411654116641167411684116941170411714117241173411744117541176411774117841179411804118141182411834118441185411864118741188411894119041191411924119341194411954119641197411984119941200412014120241203412044120541206412074120841209412104121141212412134121441215412164121741218412194122041221412224122341224412254122641227412284122941230412314123241233412344123541236412374123841239412404124141242412434124441245412464124741248412494125041251412524125341254412554125641257412584125941260412614126241263412644126541266412674126841269412704127141272412734127441275412764127741278412794128041281412824128341284412854128641287412884128941290412914129241293412944129541296412974129841299413004130141302413034130441305413064130741308413094131041311413124131341314413154131641317413184131941320413214132241323413244132541326413274132841329413304133141332413334133441335413364133741338413394134041341413424134341344413454134641347413484134941350413514135241353413544135541356413574135841359413604136141362413634136441365413664136741368413694137041371413724137341374413754137641377413784137941380413814138241383413844138541386413874138841389413904139141392413934139441395413964139741398413994140041401414024140341404414054140641407414084140941410414114141241413414144141541416414174141841419414204142141422414234142441425414264142741428414294143041431414324143341434414354143641437414384143941440414414144241443414444144541446414474144841449414504145141452414534145441455414564145741458414594146041461414624146341464414654146641467414684146941470414714147241473414744147541476414774147841479414804148141482414834148441485414864148741488414894149041491414924149341494414954149641497414984149941500415014150241503415044150541506415074150841509415104151141512415134151441515415164151741518415194152041521415224152341524415254152641527415284152941530415314153241533415344153541536415374153841539415404154141542415434154441545415464154741548415494155041551415524155341554415554155641557415584155941560415614156241563415644156541566415674156841569415704157141572415734157441575415764157741578415794158041581415824158341584415854158641587415884158941590415914159241593415944159541596415974159841599416004160141602416034160441605416064160741608416094161041611416124161341614416154161641617416184161941620416214162241623416244162541626416274162841629416304163141632416334163441635416364163741638416394164041641416424164341644416454164641647416484164941650416514165241653416544165541656416574165841659416604166141662416634166441665416664166741668416694167041671416724167341674416754167641677416784167941680416814168241683416844168541686416874168841689416904169141692416934169441695416964169741698416994170041701417024170341704417054170641707417084170941710417114171241713417144171541716417174171841719417204172141722417234172441725417264172741728417294173041731417324173341734417354173641737417384173941740417414174241743417444174541746417474174841749417504175141752417534175441755417564175741758417594176041761417624176341764417654176641767417684176941770417714177241773417744177541776417774177841779417804178141782417834178441785417864178741788417894179041791417924179341794417954179641797417984179941800418014180241803418044180541806418074180841809418104181141812418134181441815418164181741818418194182041821418224182341824418254182641827418284182941830418314183241833418344183541836418374183841839418404184141842418434184441845418464184741848418494185041851418524185341854418554185641857418584185941860418614186241863418644186541866418674186841869418704187141872
  1. // File:src/Three.js
  2. /**
  3. * @author mrdoob / http://mrdoob.com/
  4. */
  5. var THREE = { REVISION: '78dev' };
  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. multiply: function ( color ) {
  463. this.r *= color.r;
  464. this.g *= color.g;
  465. this.b *= color.b;
  466. return this;
  467. },
  468. multiplyScalar: function ( s ) {
  469. this.r *= s;
  470. this.g *= s;
  471. this.b *= s;
  472. return this;
  473. },
  474. lerp: function ( color, alpha ) {
  475. this.r += ( color.r - this.r ) * alpha;
  476. this.g += ( color.g - this.g ) * alpha;
  477. this.b += ( color.b - this.b ) * alpha;
  478. return this;
  479. },
  480. equals: function ( c ) {
  481. return ( c.r === this.r ) && ( c.g === this.g ) && ( c.b === this.b );
  482. },
  483. fromArray: function ( array, offset ) {
  484. if ( offset === undefined ) offset = 0;
  485. this.r = array[ offset ];
  486. this.g = array[ offset + 1 ];
  487. this.b = array[ offset + 2 ];
  488. return this;
  489. },
  490. toArray: function ( array, offset ) {
  491. if ( array === undefined ) array = [];
  492. if ( offset === undefined ) offset = 0;
  493. array[ offset ] = this.r;
  494. array[ offset + 1 ] = this.g;
  495. array[ offset + 2 ] = this.b;
  496. return array;
  497. }
  498. };
  499. THREE.ColorKeywords = { 'aliceblue': 0xF0F8FF, 'antiquewhite': 0xFAEBD7, 'aqua': 0x00FFFF, 'aquamarine': 0x7FFFD4, 'azure': 0xF0FFFF,
  500. 'beige': 0xF5F5DC, 'bisque': 0xFFE4C4, 'black': 0x000000, 'blanchedalmond': 0xFFEBCD, 'blue': 0x0000FF, 'blueviolet': 0x8A2BE2,
  501. 'brown': 0xA52A2A, 'burlywood': 0xDEB887, 'cadetblue': 0x5F9EA0, 'chartreuse': 0x7FFF00, 'chocolate': 0xD2691E, 'coral': 0xFF7F50,
  502. 'cornflowerblue': 0x6495ED, 'cornsilk': 0xFFF8DC, 'crimson': 0xDC143C, 'cyan': 0x00FFFF, 'darkblue': 0x00008B, 'darkcyan': 0x008B8B,
  503. 'darkgoldenrod': 0xB8860B, 'darkgray': 0xA9A9A9, 'darkgreen': 0x006400, 'darkgrey': 0xA9A9A9, 'darkkhaki': 0xBDB76B, 'darkmagenta': 0x8B008B,
  504. 'darkolivegreen': 0x556B2F, 'darkorange': 0xFF8C00, 'darkorchid': 0x9932CC, 'darkred': 0x8B0000, 'darksalmon': 0xE9967A, 'darkseagreen': 0x8FBC8F,
  505. 'darkslateblue': 0x483D8B, 'darkslategray': 0x2F4F4F, 'darkslategrey': 0x2F4F4F, 'darkturquoise': 0x00CED1, 'darkviolet': 0x9400D3,
  506. 'deeppink': 0xFF1493, 'deepskyblue': 0x00BFFF, 'dimgray': 0x696969, 'dimgrey': 0x696969, 'dodgerblue': 0x1E90FF, 'firebrick': 0xB22222,
  507. 'floralwhite': 0xFFFAF0, 'forestgreen': 0x228B22, 'fuchsia': 0xFF00FF, 'gainsboro': 0xDCDCDC, 'ghostwhite': 0xF8F8FF, 'gold': 0xFFD700,
  508. 'goldenrod': 0xDAA520, 'gray': 0x808080, 'green': 0x008000, 'greenyellow': 0xADFF2F, 'grey': 0x808080, 'honeydew': 0xF0FFF0, 'hotpink': 0xFF69B4,
  509. 'indianred': 0xCD5C5C, 'indigo': 0x4B0082, 'ivory': 0xFFFFF0, 'khaki': 0xF0E68C, 'lavender': 0xE6E6FA, 'lavenderblush': 0xFFF0F5, 'lawngreen': 0x7CFC00,
  510. 'lemonchiffon': 0xFFFACD, 'lightblue': 0xADD8E6, 'lightcoral': 0xF08080, 'lightcyan': 0xE0FFFF, 'lightgoldenrodyellow': 0xFAFAD2, 'lightgray': 0xD3D3D3,
  511. 'lightgreen': 0x90EE90, 'lightgrey': 0xD3D3D3, 'lightpink': 0xFFB6C1, 'lightsalmon': 0xFFA07A, 'lightseagreen': 0x20B2AA, 'lightskyblue': 0x87CEFA,
  512. 'lightslategray': 0x778899, 'lightslategrey': 0x778899, 'lightsteelblue': 0xB0C4DE, 'lightyellow': 0xFFFFE0, 'lime': 0x00FF00, 'limegreen': 0x32CD32,
  513. 'linen': 0xFAF0E6, 'magenta': 0xFF00FF, 'maroon': 0x800000, 'mediumaquamarine': 0x66CDAA, 'mediumblue': 0x0000CD, 'mediumorchid': 0xBA55D3,
  514. 'mediumpurple': 0x9370DB, 'mediumseagreen': 0x3CB371, 'mediumslateblue': 0x7B68EE, 'mediumspringgreen': 0x00FA9A, 'mediumturquoise': 0x48D1CC,
  515. 'mediumvioletred': 0xC71585, 'midnightblue': 0x191970, 'mintcream': 0xF5FFFA, 'mistyrose': 0xFFE4E1, 'moccasin': 0xFFE4B5, 'navajowhite': 0xFFDEAD,
  516. 'navy': 0x000080, 'oldlace': 0xFDF5E6, 'olive': 0x808000, 'olivedrab': 0x6B8E23, 'orange': 0xFFA500, 'orangered': 0xFF4500, 'orchid': 0xDA70D6,
  517. 'palegoldenrod': 0xEEE8AA, 'palegreen': 0x98FB98, 'paleturquoise': 0xAFEEEE, 'palevioletred': 0xDB7093, 'papayawhip': 0xFFEFD5, 'peachpuff': 0xFFDAB9,
  518. 'peru': 0xCD853F, 'pink': 0xFFC0CB, 'plum': 0xDDA0DD, 'powderblue': 0xB0E0E6, 'purple': 0x800080, 'red': 0xFF0000, 'rosybrown': 0xBC8F8F,
  519. 'royalblue': 0x4169E1, 'saddlebrown': 0x8B4513, 'salmon': 0xFA8072, 'sandybrown': 0xF4A460, 'seagreen': 0x2E8B57, 'seashell': 0xFFF5EE,
  520. 'sienna': 0xA0522D, 'silver': 0xC0C0C0, 'skyblue': 0x87CEEB, 'slateblue': 0x6A5ACD, 'slategray': 0x708090, 'slategrey': 0x708090, 'snow': 0xFFFAFA,
  521. 'springgreen': 0x00FF7F, 'steelblue': 0x4682B4, 'tan': 0xD2B48C, 'teal': 0x008080, 'thistle': 0xD8BFD8, 'tomato': 0xFF6347, 'turquoise': 0x40E0D0,
  522. 'violet': 0xEE82EE, 'wheat': 0xF5DEB3, 'white': 0xFFFFFF, 'whitesmoke': 0xF5F5F5, 'yellow': 0xFFFF00, 'yellowgreen': 0x9ACD32 };
  523. // File:src/math/Quaternion.js
  524. /**
  525. * @author mikael emtinger / http://gomo.se/
  526. * @author alteredq / http://alteredqualia.com/
  527. * @author WestLangley / http://github.com/WestLangley
  528. * @author bhouston / http://clara.io
  529. */
  530. THREE.Quaternion = function ( x, y, z, w ) {
  531. this._x = x || 0;
  532. this._y = y || 0;
  533. this._z = z || 0;
  534. this._w = ( w !== undefined ) ? w : 1;
  535. };
  536. THREE.Quaternion.prototype = {
  537. constructor: THREE.Quaternion,
  538. get x () {
  539. return this._x;
  540. },
  541. set x ( value ) {
  542. this._x = value;
  543. this.onChangeCallback();
  544. },
  545. get y () {
  546. return this._y;
  547. },
  548. set y ( value ) {
  549. this._y = value;
  550. this.onChangeCallback();
  551. },
  552. get z () {
  553. return this._z;
  554. },
  555. set z ( value ) {
  556. this._z = value;
  557. this.onChangeCallback();
  558. },
  559. get w () {
  560. return this._w;
  561. },
  562. set w ( value ) {
  563. this._w = value;
  564. this.onChangeCallback();
  565. },
  566. set: function ( x, y, z, w ) {
  567. this._x = x;
  568. this._y = y;
  569. this._z = z;
  570. this._w = w;
  571. this.onChangeCallback();
  572. return this;
  573. },
  574. clone: function () {
  575. return new this.constructor( this._x, this._y, this._z, this._w );
  576. },
  577. copy: function ( quaternion ) {
  578. this._x = quaternion.x;
  579. this._y = quaternion.y;
  580. this._z = quaternion.z;
  581. this._w = quaternion.w;
  582. this.onChangeCallback();
  583. return this;
  584. },
  585. setFromEuler: function ( euler, update ) {
  586. if ( euler instanceof THREE.Euler === false ) {
  587. throw new Error( 'THREE.Quaternion: .setFromEuler() now expects a Euler rotation rather than a Vector3 and order.' );
  588. }
  589. // http://www.mathworks.com/matlabcentral/fileexchange/
  590. // 20696-function-to-convert-between-dcm-euler-angles-quaternions-and-euler-vectors/
  591. // content/SpinCalc.m
  592. var c1 = Math.cos( euler._x / 2 );
  593. var c2 = Math.cos( euler._y / 2 );
  594. var c3 = Math.cos( euler._z / 2 );
  595. var s1 = Math.sin( euler._x / 2 );
  596. var s2 = Math.sin( euler._y / 2 );
  597. var s3 = Math.sin( euler._z / 2 );
  598. var order = euler.order;
  599. if ( order === 'XYZ' ) {
  600. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  601. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  602. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  603. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  604. } else if ( order === 'YXZ' ) {
  605. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  606. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  607. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  608. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  609. } else if ( order === 'ZXY' ) {
  610. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  611. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  612. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  613. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  614. } else if ( order === 'ZYX' ) {
  615. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  616. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  617. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  618. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  619. } else if ( order === 'YZX' ) {
  620. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  621. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  622. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  623. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  624. } else if ( order === 'XZY' ) {
  625. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  626. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  627. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  628. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  629. }
  630. if ( update !== false ) this.onChangeCallback();
  631. return this;
  632. },
  633. setFromAxisAngle: function ( axis, angle ) {
  634. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToQuaternion/index.htm
  635. // assumes axis is normalized
  636. var halfAngle = angle / 2, s = Math.sin( halfAngle );
  637. this._x = axis.x * s;
  638. this._y = axis.y * s;
  639. this._z = axis.z * s;
  640. this._w = Math.cos( halfAngle );
  641. this.onChangeCallback();
  642. return this;
  643. },
  644. setFromRotationMatrix: function ( m ) {
  645. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm
  646. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  647. var te = m.elements,
  648. m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ],
  649. m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ],
  650. m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ],
  651. trace = m11 + m22 + m33,
  652. s;
  653. if ( trace > 0 ) {
  654. s = 0.5 / Math.sqrt( trace + 1.0 );
  655. this._w = 0.25 / s;
  656. this._x = ( m32 - m23 ) * s;
  657. this._y = ( m13 - m31 ) * s;
  658. this._z = ( m21 - m12 ) * s;
  659. } else if ( m11 > m22 && m11 > m33 ) {
  660. s = 2.0 * Math.sqrt( 1.0 + m11 - m22 - m33 );
  661. this._w = ( m32 - m23 ) / s;
  662. this._x = 0.25 * s;
  663. this._y = ( m12 + m21 ) / s;
  664. this._z = ( m13 + m31 ) / s;
  665. } else if ( m22 > m33 ) {
  666. s = 2.0 * Math.sqrt( 1.0 + m22 - m11 - m33 );
  667. this._w = ( m13 - m31 ) / s;
  668. this._x = ( m12 + m21 ) / s;
  669. this._y = 0.25 * s;
  670. this._z = ( m23 + m32 ) / s;
  671. } else {
  672. s = 2.0 * Math.sqrt( 1.0 + m33 - m11 - m22 );
  673. this._w = ( m21 - m12 ) / s;
  674. this._x = ( m13 + m31 ) / s;
  675. this._y = ( m23 + m32 ) / s;
  676. this._z = 0.25 * s;
  677. }
  678. this.onChangeCallback();
  679. return this;
  680. },
  681. setFromUnitVectors: function () {
  682. // http://lolengine.net/blog/2014/02/24/quaternion-from-two-vectors-final
  683. // assumes direction vectors vFrom and vTo are normalized
  684. var v1, r;
  685. var EPS = 0.000001;
  686. return function setFromUnitVectors( vFrom, vTo ) {
  687. if ( v1 === undefined ) v1 = new THREE.Vector3();
  688. r = vFrom.dot( vTo ) + 1;
  689. if ( r < EPS ) {
  690. r = 0;
  691. if ( Math.abs( vFrom.x ) > Math.abs( vFrom.z ) ) {
  692. v1.set( - vFrom.y, vFrom.x, 0 );
  693. } else {
  694. v1.set( 0, - vFrom.z, vFrom.y );
  695. }
  696. } else {
  697. v1.crossVectors( vFrom, vTo );
  698. }
  699. this._x = v1.x;
  700. this._y = v1.y;
  701. this._z = v1.z;
  702. this._w = r;
  703. return this.normalize();
  704. };
  705. }(),
  706. inverse: function () {
  707. return this.conjugate().normalize();
  708. },
  709. conjugate: function () {
  710. this._x *= - 1;
  711. this._y *= - 1;
  712. this._z *= - 1;
  713. this.onChangeCallback();
  714. return this;
  715. },
  716. dot: function ( v ) {
  717. return this._x * v._x + this._y * v._y + this._z * v._z + this._w * v._w;
  718. },
  719. lengthSq: function () {
  720. return this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w;
  721. },
  722. length: function () {
  723. return Math.sqrt( this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w );
  724. },
  725. normalize: function () {
  726. var l = this.length();
  727. if ( l === 0 ) {
  728. this._x = 0;
  729. this._y = 0;
  730. this._z = 0;
  731. this._w = 1;
  732. } else {
  733. l = 1 / l;
  734. this._x = this._x * l;
  735. this._y = this._y * l;
  736. this._z = this._z * l;
  737. this._w = this._w * l;
  738. }
  739. this.onChangeCallback();
  740. return this;
  741. },
  742. multiply: function ( q, p ) {
  743. if ( p !== undefined ) {
  744. console.warn( 'THREE.Quaternion: .multiply() now only accepts one argument. Use .multiplyQuaternions( a, b ) instead.' );
  745. return this.multiplyQuaternions( q, p );
  746. }
  747. return this.multiplyQuaternions( this, q );
  748. },
  749. premultiply: function ( q ) {
  750. return this.multiplyQuaternions( q, this );
  751. },
  752. multiplyQuaternions: function ( a, b ) {
  753. // from http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/code/index.htm
  754. var qax = a._x, qay = a._y, qaz = a._z, qaw = a._w;
  755. var qbx = b._x, qby = b._y, qbz = b._z, qbw = b._w;
  756. this._x = qax * qbw + qaw * qbx + qay * qbz - qaz * qby;
  757. this._y = qay * qbw + qaw * qby + qaz * qbx - qax * qbz;
  758. this._z = qaz * qbw + qaw * qbz + qax * qby - qay * qbx;
  759. this._w = qaw * qbw - qax * qbx - qay * qby - qaz * qbz;
  760. this.onChangeCallback();
  761. return this;
  762. },
  763. slerp: function ( qb, t ) {
  764. if ( t === 0 ) return this;
  765. if ( t === 1 ) return this.copy( qb );
  766. var x = this._x, y = this._y, z = this._z, w = this._w;
  767. // http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/slerp/
  768. var cosHalfTheta = w * qb._w + x * qb._x + y * qb._y + z * qb._z;
  769. if ( cosHalfTheta < 0 ) {
  770. this._w = - qb._w;
  771. this._x = - qb._x;
  772. this._y = - qb._y;
  773. this._z = - qb._z;
  774. cosHalfTheta = - cosHalfTheta;
  775. } else {
  776. this.copy( qb );
  777. }
  778. if ( cosHalfTheta >= 1.0 ) {
  779. this._w = w;
  780. this._x = x;
  781. this._y = y;
  782. this._z = z;
  783. return this;
  784. }
  785. var sinHalfTheta = Math.sqrt( 1.0 - cosHalfTheta * cosHalfTheta );
  786. if ( Math.abs( sinHalfTheta ) < 0.001 ) {
  787. this._w = 0.5 * ( w + this._w );
  788. this._x = 0.5 * ( x + this._x );
  789. this._y = 0.5 * ( y + this._y );
  790. this._z = 0.5 * ( z + this._z );
  791. return this;
  792. }
  793. var halfTheta = Math.atan2( sinHalfTheta, cosHalfTheta );
  794. var ratioA = Math.sin( ( 1 - t ) * halfTheta ) / sinHalfTheta,
  795. ratioB = Math.sin( t * halfTheta ) / sinHalfTheta;
  796. this._w = ( w * ratioA + this._w * ratioB );
  797. this._x = ( x * ratioA + this._x * ratioB );
  798. this._y = ( y * ratioA + this._y * ratioB );
  799. this._z = ( z * ratioA + this._z * ratioB );
  800. this.onChangeCallback();
  801. return this;
  802. },
  803. equals: function ( quaternion ) {
  804. return ( quaternion._x === this._x ) && ( quaternion._y === this._y ) && ( quaternion._z === this._z ) && ( quaternion._w === this._w );
  805. },
  806. fromArray: function ( array, offset ) {
  807. if ( offset === undefined ) offset = 0;
  808. this._x = array[ offset ];
  809. this._y = array[ offset + 1 ];
  810. this._z = array[ offset + 2 ];
  811. this._w = array[ offset + 3 ];
  812. this.onChangeCallback();
  813. return this;
  814. },
  815. toArray: function ( array, offset ) {
  816. if ( array === undefined ) array = [];
  817. if ( offset === undefined ) offset = 0;
  818. array[ offset ] = this._x;
  819. array[ offset + 1 ] = this._y;
  820. array[ offset + 2 ] = this._z;
  821. array[ offset + 3 ] = this._w;
  822. return array;
  823. },
  824. onChange: function ( callback ) {
  825. this.onChangeCallback = callback;
  826. return this;
  827. },
  828. onChangeCallback: function () {}
  829. };
  830. Object.assign( THREE.Quaternion, {
  831. slerp: function( qa, qb, qm, t ) {
  832. return qm.copy( qa ).slerp( qb, t );
  833. },
  834. slerpFlat: function(
  835. dst, dstOffset, src0, srcOffset0, src1, srcOffset1, t ) {
  836. // fuzz-free, array-based Quaternion SLERP operation
  837. var x0 = src0[ srcOffset0 + 0 ],
  838. y0 = src0[ srcOffset0 + 1 ],
  839. z0 = src0[ srcOffset0 + 2 ],
  840. w0 = src0[ srcOffset0 + 3 ],
  841. x1 = src1[ srcOffset1 + 0 ],
  842. y1 = src1[ srcOffset1 + 1 ],
  843. z1 = src1[ srcOffset1 + 2 ],
  844. w1 = src1[ srcOffset1 + 3 ];
  845. if ( w0 !== w1 || x0 !== x1 || y0 !== y1 || z0 !== z1 ) {
  846. var s = 1 - t,
  847. cos = x0 * x1 + y0 * y1 + z0 * z1 + w0 * w1,
  848. dir = ( cos >= 0 ? 1 : - 1 ),
  849. sqrSin = 1 - cos * cos;
  850. // Skip the Slerp for tiny steps to avoid numeric problems:
  851. if ( sqrSin > Number.EPSILON ) {
  852. var sin = Math.sqrt( sqrSin ),
  853. len = Math.atan2( sin, cos * dir );
  854. s = Math.sin( s * len ) / sin;
  855. t = Math.sin( t * len ) / sin;
  856. }
  857. var tDir = t * dir;
  858. x0 = x0 * s + x1 * tDir;
  859. y0 = y0 * s + y1 * tDir;
  860. z0 = z0 * s + z1 * tDir;
  861. w0 = w0 * s + w1 * tDir;
  862. // Normalize in case we just did a lerp:
  863. if ( s === 1 - t ) {
  864. var f = 1 / Math.sqrt( x0 * x0 + y0 * y0 + z0 * z0 + w0 * w0 );
  865. x0 *= f;
  866. y0 *= f;
  867. z0 *= f;
  868. w0 *= f;
  869. }
  870. }
  871. dst[ dstOffset ] = x0;
  872. dst[ dstOffset + 1 ] = y0;
  873. dst[ dstOffset + 2 ] = z0;
  874. dst[ dstOffset + 3 ] = w0;
  875. }
  876. } );
  877. // File:src/math/Vector2.js
  878. /**
  879. * @author mrdoob / http://mrdoob.com/
  880. * @author philogb / http://blog.thejit.org/
  881. * @author egraether / http://egraether.com/
  882. * @author zz85 / http://www.lab4games.net/zz85/blog
  883. */
  884. THREE.Vector2 = function ( x, y ) {
  885. this.x = x || 0;
  886. this.y = y || 0;
  887. };
  888. THREE.Vector2.prototype = {
  889. constructor: THREE.Vector2,
  890. get width() {
  891. return this.x;
  892. },
  893. set width( value ) {
  894. this.x = value;
  895. },
  896. get height() {
  897. return this.y;
  898. },
  899. set height( value ) {
  900. this.y = value;
  901. },
  902. //
  903. set: function ( x, y ) {
  904. this.x = x;
  905. this.y = y;
  906. return this;
  907. },
  908. setScalar: function ( scalar ) {
  909. this.x = scalar;
  910. this.y = scalar;
  911. return this;
  912. },
  913. setX: function ( x ) {
  914. this.x = x;
  915. return this;
  916. },
  917. setY: function ( y ) {
  918. this.y = y;
  919. return this;
  920. },
  921. setComponent: function ( index, value ) {
  922. switch ( index ) {
  923. case 0: this.x = value; break;
  924. case 1: this.y = value; break;
  925. default: throw new Error( 'index is out of range: ' + index );
  926. }
  927. },
  928. getComponent: function ( index ) {
  929. switch ( index ) {
  930. case 0: return this.x;
  931. case 1: return this.y;
  932. default: throw new Error( 'index is out of range: ' + index );
  933. }
  934. },
  935. clone: function () {
  936. return new this.constructor( this.x, this.y );
  937. },
  938. copy: function ( v ) {
  939. this.x = v.x;
  940. this.y = v.y;
  941. return this;
  942. },
  943. add: function ( v, w ) {
  944. if ( w !== undefined ) {
  945. console.warn( 'THREE.Vector2: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  946. return this.addVectors( v, w );
  947. }
  948. this.x += v.x;
  949. this.y += v.y;
  950. return this;
  951. },
  952. addScalar: function ( s ) {
  953. this.x += s;
  954. this.y += s;
  955. return this;
  956. },
  957. addVectors: function ( a, b ) {
  958. this.x = a.x + b.x;
  959. this.y = a.y + b.y;
  960. return this;
  961. },
  962. addScaledVector: function ( v, s ) {
  963. this.x += v.x * s;
  964. this.y += v.y * s;
  965. return this;
  966. },
  967. sub: function ( v, w ) {
  968. if ( w !== undefined ) {
  969. console.warn( 'THREE.Vector2: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  970. return this.subVectors( v, w );
  971. }
  972. this.x -= v.x;
  973. this.y -= v.y;
  974. return this;
  975. },
  976. subScalar: function ( s ) {
  977. this.x -= s;
  978. this.y -= s;
  979. return this;
  980. },
  981. subVectors: function ( a, b ) {
  982. this.x = a.x - b.x;
  983. this.y = a.y - b.y;
  984. return this;
  985. },
  986. multiply: function ( v ) {
  987. this.x *= v.x;
  988. this.y *= v.y;
  989. return this;
  990. },
  991. multiplyScalar: function ( scalar ) {
  992. if ( isFinite( scalar ) ) {
  993. this.x *= scalar;
  994. this.y *= scalar;
  995. } else {
  996. this.x = 0;
  997. this.y = 0;
  998. }
  999. return this;
  1000. },
  1001. divide: function ( v ) {
  1002. this.x /= v.x;
  1003. this.y /= v.y;
  1004. return this;
  1005. },
  1006. divideScalar: function ( scalar ) {
  1007. return this.multiplyScalar( 1 / scalar );
  1008. },
  1009. min: function ( v ) {
  1010. this.x = Math.min( this.x, v.x );
  1011. this.y = Math.min( this.y, v.y );
  1012. return this;
  1013. },
  1014. max: function ( v ) {
  1015. this.x = Math.max( this.x, v.x );
  1016. this.y = Math.max( this.y, v.y );
  1017. return this;
  1018. },
  1019. clamp: function ( min, max ) {
  1020. // This function assumes min < max, if this assumption isn't true it will not operate correctly
  1021. this.x = Math.max( min.x, Math.min( max.x, this.x ) );
  1022. this.y = Math.max( min.y, Math.min( max.y, this.y ) );
  1023. return this;
  1024. },
  1025. clampScalar: function () {
  1026. var min, max;
  1027. return function clampScalar( minVal, maxVal ) {
  1028. if ( min === undefined ) {
  1029. min = new THREE.Vector2();
  1030. max = new THREE.Vector2();
  1031. }
  1032. min.set( minVal, minVal );
  1033. max.set( maxVal, maxVal );
  1034. return this.clamp( min, max );
  1035. };
  1036. }(),
  1037. clampLength: function ( min, max ) {
  1038. var length = this.length();
  1039. return this.multiplyScalar( Math.max( min, Math.min( max, length ) ) / length );
  1040. },
  1041. floor: function () {
  1042. this.x = Math.floor( this.x );
  1043. this.y = Math.floor( this.y );
  1044. return this;
  1045. },
  1046. ceil: function () {
  1047. this.x = Math.ceil( this.x );
  1048. this.y = Math.ceil( this.y );
  1049. return this;
  1050. },
  1051. round: function () {
  1052. this.x = Math.round( this.x );
  1053. this.y = Math.round( this.y );
  1054. return this;
  1055. },
  1056. roundToZero: function () {
  1057. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  1058. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  1059. return this;
  1060. },
  1061. negate: function () {
  1062. this.x = - this.x;
  1063. this.y = - this.y;
  1064. return this;
  1065. },
  1066. dot: function ( v ) {
  1067. return this.x * v.x + this.y * v.y;
  1068. },
  1069. lengthSq: function () {
  1070. return this.x * this.x + this.y * this.y;
  1071. },
  1072. length: function () {
  1073. return Math.sqrt( this.x * this.x + this.y * this.y );
  1074. },
  1075. lengthManhattan: function() {
  1076. return Math.abs( this.x ) + Math.abs( this.y );
  1077. },
  1078. normalize: function () {
  1079. return this.divideScalar( this.length() );
  1080. },
  1081. angle: function () {
  1082. // computes the angle in radians with respect to the positive x-axis
  1083. var angle = Math.atan2( this.y, this.x );
  1084. if ( angle < 0 ) angle += 2 * Math.PI;
  1085. return angle;
  1086. },
  1087. distanceTo: function ( v ) {
  1088. return Math.sqrt( this.distanceToSquared( v ) );
  1089. },
  1090. distanceToSquared: function ( v ) {
  1091. var dx = this.x - v.x, dy = this.y - v.y;
  1092. return dx * dx + dy * dy;
  1093. },
  1094. setLength: function ( length ) {
  1095. return this.multiplyScalar( length / this.length() );
  1096. },
  1097. lerp: function ( v, alpha ) {
  1098. this.x += ( v.x - this.x ) * alpha;
  1099. this.y += ( v.y - this.y ) * alpha;
  1100. return this;
  1101. },
  1102. lerpVectors: function ( v1, v2, alpha ) {
  1103. return this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  1104. },
  1105. equals: function ( v ) {
  1106. return ( ( v.x === this.x ) && ( v.y === this.y ) );
  1107. },
  1108. fromArray: function ( array, offset ) {
  1109. if ( offset === undefined ) offset = 0;
  1110. this.x = array[ offset ];
  1111. this.y = array[ offset + 1 ];
  1112. return this;
  1113. },
  1114. toArray: function ( array, offset ) {
  1115. if ( array === undefined ) array = [];
  1116. if ( offset === undefined ) offset = 0;
  1117. array[ offset ] = this.x;
  1118. array[ offset + 1 ] = this.y;
  1119. return array;
  1120. },
  1121. fromAttribute: function ( attribute, index, offset ) {
  1122. if ( offset === undefined ) offset = 0;
  1123. index = index * attribute.itemSize + offset;
  1124. this.x = attribute.array[ index ];
  1125. this.y = attribute.array[ index + 1 ];
  1126. return this;
  1127. },
  1128. rotateAround: function ( center, angle ) {
  1129. var c = Math.cos( angle ), s = Math.sin( angle );
  1130. var x = this.x - center.x;
  1131. var y = this.y - center.y;
  1132. this.x = x * c - y * s + center.x;
  1133. this.y = x * s + y * c + center.y;
  1134. return this;
  1135. }
  1136. };
  1137. // File:src/math/Vector3.js
  1138. /**
  1139. * @author mrdoob / http://mrdoob.com/
  1140. * @author *kile / http://kile.stravaganza.org/
  1141. * @author philogb / http://blog.thejit.org/
  1142. * @author mikael emtinger / http://gomo.se/
  1143. * @author egraether / http://egraether.com/
  1144. * @author WestLangley / http://github.com/WestLangley
  1145. */
  1146. THREE.Vector3 = function ( x, y, z ) {
  1147. this.x = x || 0;
  1148. this.y = y || 0;
  1149. this.z = z || 0;
  1150. };
  1151. THREE.Vector3.prototype = {
  1152. constructor: THREE.Vector3,
  1153. set: function ( x, y, z ) {
  1154. this.x = x;
  1155. this.y = y;
  1156. this.z = z;
  1157. return this;
  1158. },
  1159. setScalar: function ( scalar ) {
  1160. this.x = scalar;
  1161. this.y = scalar;
  1162. this.z = scalar;
  1163. return this;
  1164. },
  1165. setX: function ( x ) {
  1166. this.x = x;
  1167. return this;
  1168. },
  1169. setY: function ( y ) {
  1170. this.y = y;
  1171. return this;
  1172. },
  1173. setZ: function ( z ) {
  1174. this.z = z;
  1175. return this;
  1176. },
  1177. setComponent: function ( index, value ) {
  1178. switch ( index ) {
  1179. case 0: this.x = value; break;
  1180. case 1: this.y = value; break;
  1181. case 2: this.z = value; break;
  1182. default: throw new Error( 'index is out of range: ' + index );
  1183. }
  1184. },
  1185. getComponent: function ( index ) {
  1186. switch ( index ) {
  1187. case 0: return this.x;
  1188. case 1: return this.y;
  1189. case 2: return this.z;
  1190. default: throw new Error( 'index is out of range: ' + index );
  1191. }
  1192. },
  1193. clone: function () {
  1194. return new this.constructor( this.x, this.y, this.z );
  1195. },
  1196. copy: function ( v ) {
  1197. this.x = v.x;
  1198. this.y = v.y;
  1199. this.z = v.z;
  1200. return this;
  1201. },
  1202. add: function ( v, w ) {
  1203. if ( w !== undefined ) {
  1204. console.warn( 'THREE.Vector3: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  1205. return this.addVectors( v, w );
  1206. }
  1207. this.x += v.x;
  1208. this.y += v.y;
  1209. this.z += v.z;
  1210. return this;
  1211. },
  1212. addScalar: function ( s ) {
  1213. this.x += s;
  1214. this.y += s;
  1215. this.z += s;
  1216. return this;
  1217. },
  1218. addVectors: function ( a, b ) {
  1219. this.x = a.x + b.x;
  1220. this.y = a.y + b.y;
  1221. this.z = a.z + b.z;
  1222. return this;
  1223. },
  1224. addScaledVector: function ( v, s ) {
  1225. this.x += v.x * s;
  1226. this.y += v.y * s;
  1227. this.z += v.z * s;
  1228. return this;
  1229. },
  1230. sub: function ( v, w ) {
  1231. if ( w !== undefined ) {
  1232. console.warn( 'THREE.Vector3: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  1233. return this.subVectors( v, w );
  1234. }
  1235. this.x -= v.x;
  1236. this.y -= v.y;
  1237. this.z -= v.z;
  1238. return this;
  1239. },
  1240. subScalar: function ( s ) {
  1241. this.x -= s;
  1242. this.y -= s;
  1243. this.z -= s;
  1244. return this;
  1245. },
  1246. subVectors: function ( a, b ) {
  1247. this.x = a.x - b.x;
  1248. this.y = a.y - b.y;
  1249. this.z = a.z - b.z;
  1250. return this;
  1251. },
  1252. multiply: function ( v, w ) {
  1253. if ( w !== undefined ) {
  1254. console.warn( 'THREE.Vector3: .multiply() now only accepts one argument. Use .multiplyVectors( a, b ) instead.' );
  1255. return this.multiplyVectors( v, w );
  1256. }
  1257. this.x *= v.x;
  1258. this.y *= v.y;
  1259. this.z *= v.z;
  1260. return this;
  1261. },
  1262. multiplyScalar: function ( scalar ) {
  1263. if ( isFinite( scalar ) ) {
  1264. this.x *= scalar;
  1265. this.y *= scalar;
  1266. this.z *= scalar;
  1267. } else {
  1268. this.x = 0;
  1269. this.y = 0;
  1270. this.z = 0;
  1271. }
  1272. return this;
  1273. },
  1274. multiplyVectors: function ( a, b ) {
  1275. this.x = a.x * b.x;
  1276. this.y = a.y * b.y;
  1277. this.z = a.z * b.z;
  1278. return this;
  1279. },
  1280. applyEuler: function () {
  1281. var quaternion;
  1282. return function applyEuler( euler ) {
  1283. if ( euler instanceof THREE.Euler === false ) {
  1284. console.error( 'THREE.Vector3: .applyEuler() now expects an Euler rotation rather than a Vector3 and order.' );
  1285. }
  1286. if ( quaternion === undefined ) quaternion = new THREE.Quaternion();
  1287. return this.applyQuaternion( quaternion.setFromEuler( euler ) );
  1288. };
  1289. }(),
  1290. applyAxisAngle: function () {
  1291. var quaternion;
  1292. return function applyAxisAngle( axis, angle ) {
  1293. if ( quaternion === undefined ) quaternion = new THREE.Quaternion();
  1294. return this.applyQuaternion( quaternion.setFromAxisAngle( axis, angle ) );
  1295. };
  1296. }(),
  1297. applyMatrix3: function ( m ) {
  1298. var x = this.x, y = this.y, z = this.z;
  1299. var e = m.elements;
  1300. this.x = e[ 0 ] * x + e[ 3 ] * y + e[ 6 ] * z;
  1301. this.y = e[ 1 ] * x + e[ 4 ] * y + e[ 7 ] * z;
  1302. this.z = e[ 2 ] * x + e[ 5 ] * y + e[ 8 ] * z;
  1303. return this;
  1304. },
  1305. applyMatrix4: function ( m ) {
  1306. // input: THREE.Matrix4 affine matrix
  1307. var x = this.x, y = this.y, z = this.z;
  1308. var e = m.elements;
  1309. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ];
  1310. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ];
  1311. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ];
  1312. return this;
  1313. },
  1314. applyProjection: function ( m ) {
  1315. // input: THREE.Matrix4 projection matrix
  1316. var x = this.x, y = this.y, z = this.z;
  1317. var e = m.elements;
  1318. var d = 1 / ( e[ 3 ] * x + e[ 7 ] * y + e[ 11 ] * z + e[ 15 ] ); // perspective divide
  1319. this.x = ( e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ] ) * d;
  1320. this.y = ( e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ] ) * d;
  1321. this.z = ( e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ] ) * d;
  1322. return this;
  1323. },
  1324. applyQuaternion: function ( q ) {
  1325. var x = this.x, y = this.y, z = this.z;
  1326. var qx = q.x, qy = q.y, qz = q.z, qw = q.w;
  1327. // calculate quat * vector
  1328. var ix = qw * x + qy * z - qz * y;
  1329. var iy = qw * y + qz * x - qx * z;
  1330. var iz = qw * z + qx * y - qy * x;
  1331. var iw = - qx * x - qy * y - qz * z;
  1332. // calculate result * inverse quat
  1333. this.x = ix * qw + iw * - qx + iy * - qz - iz * - qy;
  1334. this.y = iy * qw + iw * - qy + iz * - qx - ix * - qz;
  1335. this.z = iz * qw + iw * - qz + ix * - qy - iy * - qx;
  1336. return this;
  1337. },
  1338. project: function () {
  1339. var matrix;
  1340. return function project( camera ) {
  1341. if ( matrix === undefined ) matrix = new THREE.Matrix4();
  1342. matrix.multiplyMatrices( camera.projectionMatrix, matrix.getInverse( camera.matrixWorld ) );
  1343. return this.applyProjection( matrix );
  1344. };
  1345. }(),
  1346. unproject: function () {
  1347. var matrix;
  1348. return function unproject( camera ) {
  1349. if ( matrix === undefined ) matrix = new THREE.Matrix4();
  1350. matrix.multiplyMatrices( camera.matrixWorld, matrix.getInverse( camera.projectionMatrix ) );
  1351. return this.applyProjection( matrix );
  1352. };
  1353. }(),
  1354. transformDirection: function ( m ) {
  1355. // input: THREE.Matrix4 affine matrix
  1356. // vector interpreted as a direction
  1357. var x = this.x, y = this.y, z = this.z;
  1358. var e = m.elements;
  1359. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z;
  1360. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z;
  1361. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z;
  1362. return this.normalize();
  1363. },
  1364. divide: function ( v ) {
  1365. this.x /= v.x;
  1366. this.y /= v.y;
  1367. this.z /= v.z;
  1368. return this;
  1369. },
  1370. divideScalar: function ( scalar ) {
  1371. return this.multiplyScalar( 1 / scalar );
  1372. },
  1373. min: function ( v ) {
  1374. this.x = Math.min( this.x, v.x );
  1375. this.y = Math.min( this.y, v.y );
  1376. this.z = Math.min( this.z, v.z );
  1377. return this;
  1378. },
  1379. max: function ( v ) {
  1380. this.x = Math.max( this.x, v.x );
  1381. this.y = Math.max( this.y, v.y );
  1382. this.z = Math.max( this.z, v.z );
  1383. return this;
  1384. },
  1385. clamp: function ( min, max ) {
  1386. // This function assumes min < max, if this assumption isn't true it will not operate correctly
  1387. this.x = Math.max( min.x, Math.min( max.x, this.x ) );
  1388. this.y = Math.max( min.y, Math.min( max.y, this.y ) );
  1389. this.z = Math.max( min.z, Math.min( max.z, this.z ) );
  1390. return this;
  1391. },
  1392. clampScalar: function () {
  1393. var min, max;
  1394. return function clampScalar( minVal, maxVal ) {
  1395. if ( min === undefined ) {
  1396. min = new THREE.Vector3();
  1397. max = new THREE.Vector3();
  1398. }
  1399. min.set( minVal, minVal, minVal );
  1400. max.set( maxVal, maxVal, maxVal );
  1401. return this.clamp( min, max );
  1402. };
  1403. }(),
  1404. clampLength: function ( min, max ) {
  1405. var length = this.length();
  1406. return this.multiplyScalar( Math.max( min, Math.min( max, length ) ) / length );
  1407. },
  1408. floor: function () {
  1409. this.x = Math.floor( this.x );
  1410. this.y = Math.floor( this.y );
  1411. this.z = Math.floor( this.z );
  1412. return this;
  1413. },
  1414. ceil: function () {
  1415. this.x = Math.ceil( this.x );
  1416. this.y = Math.ceil( this.y );
  1417. this.z = Math.ceil( this.z );
  1418. return this;
  1419. },
  1420. round: function () {
  1421. this.x = Math.round( this.x );
  1422. this.y = Math.round( this.y );
  1423. this.z = Math.round( this.z );
  1424. return this;
  1425. },
  1426. roundToZero: function () {
  1427. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  1428. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  1429. this.z = ( this.z < 0 ) ? Math.ceil( this.z ) : Math.floor( this.z );
  1430. return this;
  1431. },
  1432. negate: function () {
  1433. this.x = - this.x;
  1434. this.y = - this.y;
  1435. this.z = - this.z;
  1436. return this;
  1437. },
  1438. dot: function ( v ) {
  1439. return this.x * v.x + this.y * v.y + this.z * v.z;
  1440. },
  1441. lengthSq: function () {
  1442. return this.x * this.x + this.y * this.y + this.z * this.z;
  1443. },
  1444. length: function () {
  1445. return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z );
  1446. },
  1447. lengthManhattan: function () {
  1448. return Math.abs( this.x ) + Math.abs( this.y ) + Math.abs( this.z );
  1449. },
  1450. normalize: function () {
  1451. return this.divideScalar( this.length() );
  1452. },
  1453. setLength: function ( length ) {
  1454. return this.multiplyScalar( length / this.length() );
  1455. },
  1456. lerp: function ( v, alpha ) {
  1457. this.x += ( v.x - this.x ) * alpha;
  1458. this.y += ( v.y - this.y ) * alpha;
  1459. this.z += ( v.z - this.z ) * alpha;
  1460. return this;
  1461. },
  1462. lerpVectors: function ( v1, v2, alpha ) {
  1463. return this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  1464. },
  1465. cross: function ( v, w ) {
  1466. if ( w !== undefined ) {
  1467. console.warn( 'THREE.Vector3: .cross() now only accepts one argument. Use .crossVectors( a, b ) instead.' );
  1468. return this.crossVectors( v, w );
  1469. }
  1470. var x = this.x, y = this.y, z = this.z;
  1471. this.x = y * v.z - z * v.y;
  1472. this.y = z * v.x - x * v.z;
  1473. this.z = x * v.y - y * v.x;
  1474. return this;
  1475. },
  1476. crossVectors: function ( a, b ) {
  1477. var ax = a.x, ay = a.y, az = a.z;
  1478. var bx = b.x, by = b.y, bz = b.z;
  1479. this.x = ay * bz - az * by;
  1480. this.y = az * bx - ax * bz;
  1481. this.z = ax * by - ay * bx;
  1482. return this;
  1483. },
  1484. projectOnVector: function ( vector ) {
  1485. var scalar = vector.dot( this ) / vector.lengthSq();
  1486. return this.copy( vector ).multiplyScalar( scalar );
  1487. },
  1488. projectOnPlane: function () {
  1489. var v1;
  1490. return function projectOnPlane( planeNormal ) {
  1491. if ( v1 === undefined ) v1 = new THREE.Vector3();
  1492. v1.copy( this ).projectOnVector( planeNormal );
  1493. return this.sub( v1 );
  1494. };
  1495. }(),
  1496. reflect: function () {
  1497. // reflect incident vector off plane orthogonal to normal
  1498. // normal is assumed to have unit length
  1499. var v1;
  1500. return function reflect( normal ) {
  1501. if ( v1 === undefined ) v1 = new THREE.Vector3();
  1502. return this.sub( v1.copy( normal ).multiplyScalar( 2 * this.dot( normal ) ) );
  1503. };
  1504. }(),
  1505. angleTo: function ( v ) {
  1506. var theta = this.dot( v ) / ( Math.sqrt( this.lengthSq() * v.lengthSq() ) );
  1507. // clamp, to handle numerical problems
  1508. return Math.acos( THREE.Math.clamp( theta, - 1, 1 ) );
  1509. },
  1510. distanceTo: function ( v ) {
  1511. return Math.sqrt( this.distanceToSquared( v ) );
  1512. },
  1513. distanceToSquared: function ( v ) {
  1514. var dx = this.x - v.x, dy = this.y - v.y, dz = this.z - v.z;
  1515. return dx * dx + dy * dy + dz * dz;
  1516. },
  1517. setFromSpherical: function( s ) {
  1518. var sinPhiRadius = Math.sin( s.phi ) * s.radius;
  1519. this.x = sinPhiRadius * Math.sin( s.theta );
  1520. this.y = Math.cos( s.phi ) * s.radius;
  1521. this.z = sinPhiRadius * Math.cos( s.theta );
  1522. return this;
  1523. },
  1524. setFromMatrixPosition: function ( m ) {
  1525. return this.setFromMatrixColumn( m, 3 );
  1526. },
  1527. setFromMatrixScale: function ( m ) {
  1528. var sx = this.setFromMatrixColumn( m, 0 ).length();
  1529. var sy = this.setFromMatrixColumn( m, 1 ).length();
  1530. var sz = this.setFromMatrixColumn( m, 2 ).length();
  1531. this.x = sx;
  1532. this.y = sy;
  1533. this.z = sz;
  1534. return this;
  1535. },
  1536. setFromMatrixColumn: function ( m, index ) {
  1537. if ( typeof m === 'number' ) {
  1538. console.warn( 'THREE.Vector3: setFromMatrixColumn now expects ( matrix, index ).' );
  1539. var temp = m
  1540. m = index;
  1541. index = temp;
  1542. }
  1543. return this.fromArray( m.elements, index * 4 );
  1544. },
  1545. equals: function ( v ) {
  1546. return ( ( v.x === this.x ) && ( v.y === this.y ) && ( v.z === this.z ) );
  1547. },
  1548. fromArray: function ( array, offset ) {
  1549. if ( offset === undefined ) offset = 0;
  1550. this.x = array[ offset ];
  1551. this.y = array[ offset + 1 ];
  1552. this.z = array[ offset + 2 ];
  1553. return this;
  1554. },
  1555. toArray: function ( array, offset ) {
  1556. if ( array === undefined ) array = [];
  1557. if ( offset === undefined ) offset = 0;
  1558. array[ offset ] = this.x;
  1559. array[ offset + 1 ] = this.y;
  1560. array[ offset + 2 ] = this.z;
  1561. return array;
  1562. },
  1563. fromAttribute: function ( attribute, index, offset ) {
  1564. if ( offset === undefined ) offset = 0;
  1565. index = index * attribute.itemSize + offset;
  1566. this.x = attribute.array[ index ];
  1567. this.y = attribute.array[ index + 1 ];
  1568. this.z = attribute.array[ index + 2 ];
  1569. return this;
  1570. }
  1571. };
  1572. // File:src/math/Vector4.js
  1573. /**
  1574. * @author supereggbert / http://www.paulbrunt.co.uk/
  1575. * @author philogb / http://blog.thejit.org/
  1576. * @author mikael emtinger / http://gomo.se/
  1577. * @author egraether / http://egraether.com/
  1578. * @author WestLangley / http://github.com/WestLangley
  1579. */
  1580. THREE.Vector4 = function ( x, y, z, w ) {
  1581. this.x = x || 0;
  1582. this.y = y || 0;
  1583. this.z = z || 0;
  1584. this.w = ( w !== undefined ) ? w : 1;
  1585. };
  1586. THREE.Vector4.prototype = {
  1587. constructor: THREE.Vector4,
  1588. set: function ( x, y, z, w ) {
  1589. this.x = x;
  1590. this.y = y;
  1591. this.z = z;
  1592. this.w = w;
  1593. return this;
  1594. },
  1595. setScalar: function ( scalar ) {
  1596. this.x = scalar;
  1597. this.y = scalar;
  1598. this.z = scalar;
  1599. this.w = scalar;
  1600. return this;
  1601. },
  1602. setX: function ( x ) {
  1603. this.x = x;
  1604. return this;
  1605. },
  1606. setY: function ( y ) {
  1607. this.y = y;
  1608. return this;
  1609. },
  1610. setZ: function ( z ) {
  1611. this.z = z;
  1612. return this;
  1613. },
  1614. setW: function ( w ) {
  1615. this.w = w;
  1616. return this;
  1617. },
  1618. setComponent: function ( index, value ) {
  1619. switch ( index ) {
  1620. case 0: this.x = value; break;
  1621. case 1: this.y = value; break;
  1622. case 2: this.z = value; break;
  1623. case 3: this.w = value; break;
  1624. default: throw new Error( 'index is out of range: ' + index );
  1625. }
  1626. },
  1627. getComponent: function ( index ) {
  1628. switch ( index ) {
  1629. case 0: return this.x;
  1630. case 1: return this.y;
  1631. case 2: return this.z;
  1632. case 3: return this.w;
  1633. default: throw new Error( 'index is out of range: ' + index );
  1634. }
  1635. },
  1636. clone: function () {
  1637. return new this.constructor( this.x, this.y, this.z, this.w );
  1638. },
  1639. copy: function ( v ) {
  1640. this.x = v.x;
  1641. this.y = v.y;
  1642. this.z = v.z;
  1643. this.w = ( v.w !== undefined ) ? v.w : 1;
  1644. return this;
  1645. },
  1646. add: function ( v, w ) {
  1647. if ( w !== undefined ) {
  1648. console.warn( 'THREE.Vector4: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  1649. return this.addVectors( v, w );
  1650. }
  1651. this.x += v.x;
  1652. this.y += v.y;
  1653. this.z += v.z;
  1654. this.w += v.w;
  1655. return this;
  1656. },
  1657. addScalar: function ( s ) {
  1658. this.x += s;
  1659. this.y += s;
  1660. this.z += s;
  1661. this.w += s;
  1662. return this;
  1663. },
  1664. addVectors: function ( a, b ) {
  1665. this.x = a.x + b.x;
  1666. this.y = a.y + b.y;
  1667. this.z = a.z + b.z;
  1668. this.w = a.w + b.w;
  1669. return this;
  1670. },
  1671. addScaledVector: function ( v, s ) {
  1672. this.x += v.x * s;
  1673. this.y += v.y * s;
  1674. this.z += v.z * s;
  1675. this.w += v.w * s;
  1676. return this;
  1677. },
  1678. sub: function ( v, w ) {
  1679. if ( w !== undefined ) {
  1680. console.warn( 'THREE.Vector4: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  1681. return this.subVectors( v, w );
  1682. }
  1683. this.x -= v.x;
  1684. this.y -= v.y;
  1685. this.z -= v.z;
  1686. this.w -= v.w;
  1687. return this;
  1688. },
  1689. subScalar: function ( s ) {
  1690. this.x -= s;
  1691. this.y -= s;
  1692. this.z -= s;
  1693. this.w -= s;
  1694. return this;
  1695. },
  1696. subVectors: function ( a, b ) {
  1697. this.x = a.x - b.x;
  1698. this.y = a.y - b.y;
  1699. this.z = a.z - b.z;
  1700. this.w = a.w - b.w;
  1701. return this;
  1702. },
  1703. multiplyScalar: function ( scalar ) {
  1704. if ( isFinite( scalar ) ) {
  1705. this.x *= scalar;
  1706. this.y *= scalar;
  1707. this.z *= scalar;
  1708. this.w *= scalar;
  1709. } else {
  1710. this.x = 0;
  1711. this.y = 0;
  1712. this.z = 0;
  1713. this.w = 0;
  1714. }
  1715. return this;
  1716. },
  1717. applyMatrix4: function ( m ) {
  1718. var x = this.x, y = this.y, z = this.z, w = this.w;
  1719. var e = m.elements;
  1720. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ] * w;
  1721. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ] * w;
  1722. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ] * w;
  1723. this.w = e[ 3 ] * x + e[ 7 ] * y + e[ 11 ] * z + e[ 15 ] * w;
  1724. return this;
  1725. },
  1726. divideScalar: function ( scalar ) {
  1727. return this.multiplyScalar( 1 / scalar );
  1728. },
  1729. setAxisAngleFromQuaternion: function ( q ) {
  1730. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToAngle/index.htm
  1731. // q is assumed to be normalized
  1732. this.w = 2 * Math.acos( q.w );
  1733. var s = Math.sqrt( 1 - q.w * q.w );
  1734. if ( s < 0.0001 ) {
  1735. this.x = 1;
  1736. this.y = 0;
  1737. this.z = 0;
  1738. } else {
  1739. this.x = q.x / s;
  1740. this.y = q.y / s;
  1741. this.z = q.z / s;
  1742. }
  1743. return this;
  1744. },
  1745. setAxisAngleFromRotationMatrix: function ( m ) {
  1746. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToAngle/index.htm
  1747. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  1748. var angle, x, y, z, // variables for result
  1749. epsilon = 0.01, // margin to allow for rounding errors
  1750. epsilon2 = 0.1, // margin to distinguish between 0 and 180 degrees
  1751. te = m.elements,
  1752. m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ],
  1753. m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ],
  1754. m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ];
  1755. if ( ( Math.abs( m12 - m21 ) < epsilon ) &&
  1756. ( Math.abs( m13 - m31 ) < epsilon ) &&
  1757. ( Math.abs( m23 - m32 ) < epsilon ) ) {
  1758. // singularity found
  1759. // first check for identity matrix which must have +1 for all terms
  1760. // in leading diagonal and zero in other terms
  1761. if ( ( Math.abs( m12 + m21 ) < epsilon2 ) &&
  1762. ( Math.abs( m13 + m31 ) < epsilon2 ) &&
  1763. ( Math.abs( m23 + m32 ) < epsilon2 ) &&
  1764. ( Math.abs( m11 + m22 + m33 - 3 ) < epsilon2 ) ) {
  1765. // this singularity is identity matrix so angle = 0
  1766. this.set( 1, 0, 0, 0 );
  1767. return this; // zero angle, arbitrary axis
  1768. }
  1769. // otherwise this singularity is angle = 180
  1770. angle = Math.PI;
  1771. var xx = ( m11 + 1 ) / 2;
  1772. var yy = ( m22 + 1 ) / 2;
  1773. var zz = ( m33 + 1 ) / 2;
  1774. var xy = ( m12 + m21 ) / 4;
  1775. var xz = ( m13 + m31 ) / 4;
  1776. var yz = ( m23 + m32 ) / 4;
  1777. if ( ( xx > yy ) && ( xx > zz ) ) {
  1778. // m11 is the largest diagonal term
  1779. if ( xx < epsilon ) {
  1780. x = 0;
  1781. y = 0.707106781;
  1782. z = 0.707106781;
  1783. } else {
  1784. x = Math.sqrt( xx );
  1785. y = xy / x;
  1786. z = xz / x;
  1787. }
  1788. } else if ( yy > zz ) {
  1789. // m22 is the largest diagonal term
  1790. if ( yy < epsilon ) {
  1791. x = 0.707106781;
  1792. y = 0;
  1793. z = 0.707106781;
  1794. } else {
  1795. y = Math.sqrt( yy );
  1796. x = xy / y;
  1797. z = yz / y;
  1798. }
  1799. } else {
  1800. // m33 is the largest diagonal term so base result on this
  1801. if ( zz < epsilon ) {
  1802. x = 0.707106781;
  1803. y = 0.707106781;
  1804. z = 0;
  1805. } else {
  1806. z = Math.sqrt( zz );
  1807. x = xz / z;
  1808. y = yz / z;
  1809. }
  1810. }
  1811. this.set( x, y, z, angle );
  1812. return this; // return 180 deg rotation
  1813. }
  1814. // as we have reached here there are no singularities so we can handle normally
  1815. var s = Math.sqrt( ( m32 - m23 ) * ( m32 - m23 ) +
  1816. ( m13 - m31 ) * ( m13 - m31 ) +
  1817. ( m21 - m12 ) * ( m21 - m12 ) ); // used to normalize
  1818. if ( Math.abs( s ) < 0.001 ) s = 1;
  1819. // prevent divide by zero, should not happen if matrix is orthogonal and should be
  1820. // caught by singularity test above, but I've left it in just in case
  1821. this.x = ( m32 - m23 ) / s;
  1822. this.y = ( m13 - m31 ) / s;
  1823. this.z = ( m21 - m12 ) / s;
  1824. this.w = Math.acos( ( m11 + m22 + m33 - 1 ) / 2 );
  1825. return this;
  1826. },
  1827. min: function ( v ) {
  1828. this.x = Math.min( this.x, v.x );
  1829. this.y = Math.min( this.y, v.y );
  1830. this.z = Math.min( this.z, v.z );
  1831. this.w = Math.min( this.w, v.w );
  1832. return this;
  1833. },
  1834. max: function ( v ) {
  1835. this.x = Math.max( this.x, v.x );
  1836. this.y = Math.max( this.y, v.y );
  1837. this.z = Math.max( this.z, v.z );
  1838. this.w = Math.max( this.w, v.w );
  1839. return this;
  1840. },
  1841. clamp: function ( min, max ) {
  1842. // This function assumes min < max, if this assumption isn't true it will not operate correctly
  1843. this.x = Math.max( min.x, Math.min( max.x, this.x ) );
  1844. this.y = Math.max( min.y, Math.min( max.y, this.y ) );
  1845. this.z = Math.max( min.z, Math.min( max.z, this.z ) );
  1846. this.w = Math.max( min.w, Math.min( max.w, this.w ) );
  1847. return this;
  1848. },
  1849. clampScalar: function () {
  1850. var min, max;
  1851. return function clampScalar( minVal, maxVal ) {
  1852. if ( min === undefined ) {
  1853. min = new THREE.Vector4();
  1854. max = new THREE.Vector4();
  1855. }
  1856. min.set( minVal, minVal, minVal, minVal );
  1857. max.set( maxVal, maxVal, maxVal, maxVal );
  1858. return this.clamp( min, max );
  1859. };
  1860. }(),
  1861. floor: function () {
  1862. this.x = Math.floor( this.x );
  1863. this.y = Math.floor( this.y );
  1864. this.z = Math.floor( this.z );
  1865. this.w = Math.floor( this.w );
  1866. return this;
  1867. },
  1868. ceil: function () {
  1869. this.x = Math.ceil( this.x );
  1870. this.y = Math.ceil( this.y );
  1871. this.z = Math.ceil( this.z );
  1872. this.w = Math.ceil( this.w );
  1873. return this;
  1874. },
  1875. round: function () {
  1876. this.x = Math.round( this.x );
  1877. this.y = Math.round( this.y );
  1878. this.z = Math.round( this.z );
  1879. this.w = Math.round( this.w );
  1880. return this;
  1881. },
  1882. roundToZero: function () {
  1883. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  1884. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  1885. this.z = ( this.z < 0 ) ? Math.ceil( this.z ) : Math.floor( this.z );
  1886. this.w = ( this.w < 0 ) ? Math.ceil( this.w ) : Math.floor( this.w );
  1887. return this;
  1888. },
  1889. negate: function () {
  1890. this.x = - this.x;
  1891. this.y = - this.y;
  1892. this.z = - this.z;
  1893. this.w = - this.w;
  1894. return this;
  1895. },
  1896. dot: function ( v ) {
  1897. return this.x * v.x + this.y * v.y + this.z * v.z + this.w * v.w;
  1898. },
  1899. lengthSq: function () {
  1900. return this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w;
  1901. },
  1902. length: function () {
  1903. return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w );
  1904. },
  1905. lengthManhattan: function () {
  1906. return Math.abs( this.x ) + Math.abs( this.y ) + Math.abs( this.z ) + Math.abs( this.w );
  1907. },
  1908. normalize: function () {
  1909. return this.divideScalar( this.length() );
  1910. },
  1911. setLength: function ( length ) {
  1912. return this.multiplyScalar( length / this.length() );
  1913. },
  1914. lerp: function ( v, alpha ) {
  1915. this.x += ( v.x - this.x ) * alpha;
  1916. this.y += ( v.y - this.y ) * alpha;
  1917. this.z += ( v.z - this.z ) * alpha;
  1918. this.w += ( v.w - this.w ) * alpha;
  1919. return this;
  1920. },
  1921. lerpVectors: function ( v1, v2, alpha ) {
  1922. return this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  1923. },
  1924. equals: function ( v ) {
  1925. return ( ( v.x === this.x ) && ( v.y === this.y ) && ( v.z === this.z ) && ( v.w === this.w ) );
  1926. },
  1927. fromArray: function ( array, offset ) {
  1928. if ( offset === undefined ) offset = 0;
  1929. this.x = array[ offset ];
  1930. this.y = array[ offset + 1 ];
  1931. this.z = array[ offset + 2 ];
  1932. this.w = array[ offset + 3 ];
  1933. return this;
  1934. },
  1935. toArray: function ( array, offset ) {
  1936. if ( array === undefined ) array = [];
  1937. if ( offset === undefined ) offset = 0;
  1938. array[ offset ] = this.x;
  1939. array[ offset + 1 ] = this.y;
  1940. array[ offset + 2 ] = this.z;
  1941. array[ offset + 3 ] = this.w;
  1942. return array;
  1943. },
  1944. fromAttribute: function ( attribute, index, offset ) {
  1945. if ( offset === undefined ) offset = 0;
  1946. index = index * attribute.itemSize + offset;
  1947. this.x = attribute.array[ index ];
  1948. this.y = attribute.array[ index + 1 ];
  1949. this.z = attribute.array[ index + 2 ];
  1950. this.w = attribute.array[ index + 3 ];
  1951. return this;
  1952. }
  1953. };
  1954. // File:src/math/Euler.js
  1955. /**
  1956. * @author mrdoob / http://mrdoob.com/
  1957. * @author WestLangley / http://github.com/WestLangley
  1958. * @author bhouston / http://clara.io
  1959. */
  1960. THREE.Euler = function ( x, y, z, order ) {
  1961. this._x = x || 0;
  1962. this._y = y || 0;
  1963. this._z = z || 0;
  1964. this._order = order || THREE.Euler.DefaultOrder;
  1965. };
  1966. THREE.Euler.RotationOrders = [ 'XYZ', 'YZX', 'ZXY', 'XZY', 'YXZ', 'ZYX' ];
  1967. THREE.Euler.DefaultOrder = 'XYZ';
  1968. THREE.Euler.prototype = {
  1969. constructor: THREE.Euler,
  1970. get x () {
  1971. return this._x;
  1972. },
  1973. set x ( value ) {
  1974. this._x = value;
  1975. this.onChangeCallback();
  1976. },
  1977. get y () {
  1978. return this._y;
  1979. },
  1980. set y ( value ) {
  1981. this._y = value;
  1982. this.onChangeCallback();
  1983. },
  1984. get z () {
  1985. return this._z;
  1986. },
  1987. set z ( value ) {
  1988. this._z = value;
  1989. this.onChangeCallback();
  1990. },
  1991. get order () {
  1992. return this._order;
  1993. },
  1994. set order ( value ) {
  1995. this._order = value;
  1996. this.onChangeCallback();
  1997. },
  1998. set: function ( x, y, z, order ) {
  1999. this._x = x;
  2000. this._y = y;
  2001. this._z = z;
  2002. this._order = order || this._order;
  2003. this.onChangeCallback();
  2004. return this;
  2005. },
  2006. clone: function () {
  2007. return new this.constructor( this._x, this._y, this._z, this._order );
  2008. },
  2009. copy: function ( euler ) {
  2010. this._x = euler._x;
  2011. this._y = euler._y;
  2012. this._z = euler._z;
  2013. this._order = euler._order;
  2014. this.onChangeCallback();
  2015. return this;
  2016. },
  2017. setFromRotationMatrix: function ( m, order, update ) {
  2018. var clamp = THREE.Math.clamp;
  2019. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  2020. var te = m.elements;
  2021. var m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ];
  2022. var m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ];
  2023. var m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ];
  2024. order = order || this._order;
  2025. if ( order === 'XYZ' ) {
  2026. this._y = Math.asin( clamp( m13, - 1, 1 ) );
  2027. if ( Math.abs( m13 ) < 0.99999 ) {
  2028. this._x = Math.atan2( - m23, m33 );
  2029. this._z = Math.atan2( - m12, m11 );
  2030. } else {
  2031. this._x = Math.atan2( m32, m22 );
  2032. this._z = 0;
  2033. }
  2034. } else if ( order === 'YXZ' ) {
  2035. this._x = Math.asin( - clamp( m23, - 1, 1 ) );
  2036. if ( Math.abs( m23 ) < 0.99999 ) {
  2037. this._y = Math.atan2( m13, m33 );
  2038. this._z = Math.atan2( m21, m22 );
  2039. } else {
  2040. this._y = Math.atan2( - m31, m11 );
  2041. this._z = 0;
  2042. }
  2043. } else if ( order === 'ZXY' ) {
  2044. this._x = Math.asin( clamp( m32, - 1, 1 ) );
  2045. if ( Math.abs( m32 ) < 0.99999 ) {
  2046. this._y = Math.atan2( - m31, m33 );
  2047. this._z = Math.atan2( - m12, m22 );
  2048. } else {
  2049. this._y = 0;
  2050. this._z = Math.atan2( m21, m11 );
  2051. }
  2052. } else if ( order === 'ZYX' ) {
  2053. this._y = Math.asin( - clamp( m31, - 1, 1 ) );
  2054. if ( Math.abs( m31 ) < 0.99999 ) {
  2055. this._x = Math.atan2( m32, m33 );
  2056. this._z = Math.atan2( m21, m11 );
  2057. } else {
  2058. this._x = 0;
  2059. this._z = Math.atan2( - m12, m22 );
  2060. }
  2061. } else if ( order === 'YZX' ) {
  2062. this._z = Math.asin( clamp( m21, - 1, 1 ) );
  2063. if ( Math.abs( m21 ) < 0.99999 ) {
  2064. this._x = Math.atan2( - m23, m22 );
  2065. this._y = Math.atan2( - m31, m11 );
  2066. } else {
  2067. this._x = 0;
  2068. this._y = Math.atan2( m13, m33 );
  2069. }
  2070. } else if ( order === 'XZY' ) {
  2071. this._z = Math.asin( - clamp( m12, - 1, 1 ) );
  2072. if ( Math.abs( m12 ) < 0.99999 ) {
  2073. this._x = Math.atan2( m32, m22 );
  2074. this._y = Math.atan2( m13, m11 );
  2075. } else {
  2076. this._x = Math.atan2( - m23, m33 );
  2077. this._y = 0;
  2078. }
  2079. } else {
  2080. console.warn( 'THREE.Euler: .setFromRotationMatrix() given unsupported order: ' + order );
  2081. }
  2082. this._order = order;
  2083. if ( update !== false ) this.onChangeCallback();
  2084. return this;
  2085. },
  2086. setFromQuaternion: function () {
  2087. var matrix;
  2088. return function setFromQuaternion( q, order, update ) {
  2089. if ( matrix === undefined ) matrix = new THREE.Matrix4();
  2090. matrix.makeRotationFromQuaternion( q );
  2091. return this.setFromRotationMatrix( matrix, order, update );
  2092. };
  2093. }(),
  2094. setFromVector3: function ( v, order ) {
  2095. return this.set( v.x, v.y, v.z, order || this._order );
  2096. },
  2097. reorder: function () {
  2098. // WARNING: this discards revolution information -bhouston
  2099. var q = new THREE.Quaternion();
  2100. return function reorder( newOrder ) {
  2101. q.setFromEuler( this );
  2102. return this.setFromQuaternion( q, newOrder );
  2103. };
  2104. }(),
  2105. equals: function ( euler ) {
  2106. return ( euler._x === this._x ) && ( euler._y === this._y ) && ( euler._z === this._z ) && ( euler._order === this._order );
  2107. },
  2108. fromArray: function ( array ) {
  2109. this._x = array[ 0 ];
  2110. this._y = array[ 1 ];
  2111. this._z = array[ 2 ];
  2112. if ( array[ 3 ] !== undefined ) this._order = array[ 3 ];
  2113. this.onChangeCallback();
  2114. return this;
  2115. },
  2116. toArray: function ( array, offset ) {
  2117. if ( array === undefined ) array = [];
  2118. if ( offset === undefined ) offset = 0;
  2119. array[ offset ] = this._x;
  2120. array[ offset + 1 ] = this._y;
  2121. array[ offset + 2 ] = this._z;
  2122. array[ offset + 3 ] = this._order;
  2123. return array;
  2124. },
  2125. toVector3: function ( optionalResult ) {
  2126. if ( optionalResult ) {
  2127. return optionalResult.set( this._x, this._y, this._z );
  2128. } else {
  2129. return new THREE.Vector3( this._x, this._y, this._z );
  2130. }
  2131. },
  2132. onChange: function ( callback ) {
  2133. this.onChangeCallback = callback;
  2134. return this;
  2135. },
  2136. onChangeCallback: function () {}
  2137. };
  2138. // File:src/math/Line3.js
  2139. /**
  2140. * @author bhouston / http://clara.io
  2141. */
  2142. THREE.Line3 = function ( start, end ) {
  2143. this.start = ( start !== undefined ) ? start : new THREE.Vector3();
  2144. this.end = ( end !== undefined ) ? end : new THREE.Vector3();
  2145. };
  2146. THREE.Line3.prototype = {
  2147. constructor: THREE.Line3,
  2148. set: function ( start, end ) {
  2149. this.start.copy( start );
  2150. this.end.copy( end );
  2151. return this;
  2152. },
  2153. clone: function () {
  2154. return new this.constructor().copy( this );
  2155. },
  2156. copy: function ( line ) {
  2157. this.start.copy( line.start );
  2158. this.end.copy( line.end );
  2159. return this;
  2160. },
  2161. center: function ( optionalTarget ) {
  2162. var result = optionalTarget || new THREE.Vector3();
  2163. return result.addVectors( this.start, this.end ).multiplyScalar( 0.5 );
  2164. },
  2165. delta: function ( optionalTarget ) {
  2166. var result = optionalTarget || new THREE.Vector3();
  2167. return result.subVectors( this.end, this.start );
  2168. },
  2169. distanceSq: function () {
  2170. return this.start.distanceToSquared( this.end );
  2171. },
  2172. distance: function () {
  2173. return this.start.distanceTo( this.end );
  2174. },
  2175. at: function ( t, optionalTarget ) {
  2176. var result = optionalTarget || new THREE.Vector3();
  2177. return this.delta( result ).multiplyScalar( t ).add( this.start );
  2178. },
  2179. closestPointToPointParameter: function () {
  2180. var startP = new THREE.Vector3();
  2181. var startEnd = new THREE.Vector3();
  2182. return function closestPointToPointParameter( point, clampToLine ) {
  2183. startP.subVectors( point, this.start );
  2184. startEnd.subVectors( this.end, this.start );
  2185. var startEnd2 = startEnd.dot( startEnd );
  2186. var startEnd_startP = startEnd.dot( startP );
  2187. var t = startEnd_startP / startEnd2;
  2188. if ( clampToLine ) {
  2189. t = THREE.Math.clamp( t, 0, 1 );
  2190. }
  2191. return t;
  2192. };
  2193. }(),
  2194. closestPointToPoint: function ( point, clampToLine, optionalTarget ) {
  2195. var t = this.closestPointToPointParameter( point, clampToLine );
  2196. var result = optionalTarget || new THREE.Vector3();
  2197. return this.delta( result ).multiplyScalar( t ).add( this.start );
  2198. },
  2199. applyMatrix4: function ( matrix ) {
  2200. this.start.applyMatrix4( matrix );
  2201. this.end.applyMatrix4( matrix );
  2202. return this;
  2203. },
  2204. equals: function ( line ) {
  2205. return line.start.equals( this.start ) && line.end.equals( this.end );
  2206. }
  2207. };
  2208. // File:src/math/Box2.js
  2209. /**
  2210. * @author bhouston / http://clara.io
  2211. */
  2212. THREE.Box2 = function ( min, max ) {
  2213. this.min = ( min !== undefined ) ? min : new THREE.Vector2( + Infinity, + Infinity );
  2214. this.max = ( max !== undefined ) ? max : new THREE.Vector2( - Infinity, - Infinity );
  2215. };
  2216. THREE.Box2.prototype = {
  2217. constructor: THREE.Box2,
  2218. set: function ( min, max ) {
  2219. this.min.copy( min );
  2220. this.max.copy( max );
  2221. return this;
  2222. },
  2223. setFromPoints: function ( points ) {
  2224. this.makeEmpty();
  2225. for ( var i = 0, il = points.length; i < il; i ++ ) {
  2226. this.expandByPoint( points[ i ] );
  2227. }
  2228. return this;
  2229. },
  2230. setFromCenterAndSize: function () {
  2231. var v1 = new THREE.Vector2();
  2232. return function setFromCenterAndSize( center, size ) {
  2233. var halfSize = v1.copy( size ).multiplyScalar( 0.5 );
  2234. this.min.copy( center ).sub( halfSize );
  2235. this.max.copy( center ).add( halfSize );
  2236. return this;
  2237. };
  2238. }(),
  2239. clone: function () {
  2240. return new this.constructor().copy( this );
  2241. },
  2242. copy: function ( box ) {
  2243. this.min.copy( box.min );
  2244. this.max.copy( box.max );
  2245. return this;
  2246. },
  2247. makeEmpty: function () {
  2248. this.min.x = this.min.y = + Infinity;
  2249. this.max.x = this.max.y = - Infinity;
  2250. return this;
  2251. },
  2252. isEmpty: function () {
  2253. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  2254. return ( this.max.x < this.min.x ) || ( this.max.y < this.min.y );
  2255. },
  2256. center: function ( optionalTarget ) {
  2257. var result = optionalTarget || new THREE.Vector2();
  2258. return result.addVectors( this.min, this.max ).multiplyScalar( 0.5 );
  2259. },
  2260. size: function ( optionalTarget ) {
  2261. var result = optionalTarget || new THREE.Vector2();
  2262. return result.subVectors( this.max, this.min );
  2263. },
  2264. expandByPoint: function ( point ) {
  2265. this.min.min( point );
  2266. this.max.max( point );
  2267. return this;
  2268. },
  2269. expandByVector: function ( vector ) {
  2270. this.min.sub( vector );
  2271. this.max.add( vector );
  2272. return this;
  2273. },
  2274. expandByScalar: function ( scalar ) {
  2275. this.min.addScalar( - scalar );
  2276. this.max.addScalar( scalar );
  2277. return this;
  2278. },
  2279. containsPoint: function ( point ) {
  2280. if ( point.x < this.min.x || point.x > this.max.x ||
  2281. point.y < this.min.y || point.y > this.max.y ) {
  2282. return false;
  2283. }
  2284. return true;
  2285. },
  2286. containsBox: function ( box ) {
  2287. if ( ( this.min.x <= box.min.x ) && ( box.max.x <= this.max.x ) &&
  2288. ( this.min.y <= box.min.y ) && ( box.max.y <= this.max.y ) ) {
  2289. return true;
  2290. }
  2291. return false;
  2292. },
  2293. getParameter: function ( point, optionalTarget ) {
  2294. // This can potentially have a divide by zero if the box
  2295. // has a size dimension of 0.
  2296. var result = optionalTarget || new THREE.Vector2();
  2297. return result.set(
  2298. ( point.x - this.min.x ) / ( this.max.x - this.min.x ),
  2299. ( point.y - this.min.y ) / ( this.max.y - this.min.y )
  2300. );
  2301. },
  2302. intersectsBox: function ( box ) {
  2303. // using 6 splitting planes to rule out intersections.
  2304. if ( box.max.x < this.min.x || box.min.x > this.max.x ||
  2305. box.max.y < this.min.y || box.min.y > this.max.y ) {
  2306. return false;
  2307. }
  2308. return true;
  2309. },
  2310. clampPoint: function ( point, optionalTarget ) {
  2311. var result = optionalTarget || new THREE.Vector2();
  2312. return result.copy( point ).clamp( this.min, this.max );
  2313. },
  2314. distanceToPoint: function () {
  2315. var v1 = new THREE.Vector2();
  2316. return function distanceToPoint( point ) {
  2317. var clampedPoint = v1.copy( point ).clamp( this.min, this.max );
  2318. return clampedPoint.sub( point ).length();
  2319. };
  2320. }(),
  2321. intersect: function ( box ) {
  2322. this.min.max( box.min );
  2323. this.max.min( box.max );
  2324. return this;
  2325. },
  2326. union: function ( box ) {
  2327. this.min.min( box.min );
  2328. this.max.max( box.max );
  2329. return this;
  2330. },
  2331. translate: function ( offset ) {
  2332. this.min.add( offset );
  2333. this.max.add( offset );
  2334. return this;
  2335. },
  2336. equals: function ( box ) {
  2337. return box.min.equals( this.min ) && box.max.equals( this.max );
  2338. }
  2339. };
  2340. // File:src/math/Box3.js
  2341. /**
  2342. * @author bhouston / http://clara.io
  2343. * @author WestLangley / http://github.com/WestLangley
  2344. */
  2345. THREE.Box3 = function ( min, max ) {
  2346. this.min = ( min !== undefined ) ? min : new THREE.Vector3( + Infinity, + Infinity, + Infinity );
  2347. this.max = ( max !== undefined ) ? max : new THREE.Vector3( - Infinity, - Infinity, - Infinity );
  2348. };
  2349. THREE.Box3.prototype = {
  2350. constructor: THREE.Box3,
  2351. set: function ( min, max ) {
  2352. this.min.copy( min );
  2353. this.max.copy( max );
  2354. return this;
  2355. },
  2356. setFromArray: function ( array ) {
  2357. var minX = + Infinity;
  2358. var minY = + Infinity;
  2359. var minZ = + Infinity;
  2360. var maxX = - Infinity;
  2361. var maxY = - Infinity;
  2362. var maxZ = - Infinity;
  2363. for ( var i = 0, l = array.length; i < l; i += 3 ) {
  2364. var x = array[ i ];
  2365. var y = array[ i + 1 ];
  2366. var z = array[ i + 2 ];
  2367. if ( x < minX ) minX = x;
  2368. if ( y < minY ) minY = y;
  2369. if ( z < minZ ) minZ = z;
  2370. if ( x > maxX ) maxX = x;
  2371. if ( y > maxY ) maxY = y;
  2372. if ( z > maxZ ) maxZ = z;
  2373. }
  2374. this.min.set( minX, minY, minZ );
  2375. this.max.set( maxX, maxY, maxZ );
  2376. },
  2377. setFromPoints: function ( points ) {
  2378. this.makeEmpty();
  2379. for ( var i = 0, il = points.length; i < il; i ++ ) {
  2380. this.expandByPoint( points[ i ] );
  2381. }
  2382. return this;
  2383. },
  2384. setFromCenterAndSize: function () {
  2385. var v1 = new THREE.Vector3();
  2386. return function setFromCenterAndSize( center, size ) {
  2387. var halfSize = v1.copy( size ).multiplyScalar( 0.5 );
  2388. this.min.copy( center ).sub( halfSize );
  2389. this.max.copy( center ).add( halfSize );
  2390. return this;
  2391. };
  2392. }(),
  2393. setFromObject: function () {
  2394. // Computes the world-axis-aligned bounding box of an object (including its children),
  2395. // accounting for both the object's, and children's, world transforms
  2396. var v1 = new THREE.Vector3();
  2397. return function setFromObject( object ) {
  2398. var scope = this;
  2399. object.updateMatrixWorld( true );
  2400. this.makeEmpty();
  2401. object.traverse( function ( node ) {
  2402. var geometry = node.geometry;
  2403. if ( geometry !== undefined ) {
  2404. if ( geometry instanceof THREE.Geometry ) {
  2405. var vertices = geometry.vertices;
  2406. for ( var i = 0, il = vertices.length; i < il; i ++ ) {
  2407. v1.copy( vertices[ i ] );
  2408. v1.applyMatrix4( node.matrixWorld );
  2409. scope.expandByPoint( v1 );
  2410. }
  2411. } else if ( geometry instanceof THREE.BufferGeometry && geometry.attributes[ 'position' ] !== undefined ) {
  2412. var positions = geometry.attributes[ 'position' ].array;
  2413. for ( var i = 0, il = positions.length; i < il; i += 3 ) {
  2414. v1.fromArray( positions, i );
  2415. v1.applyMatrix4( node.matrixWorld );
  2416. scope.expandByPoint( v1 );
  2417. }
  2418. }
  2419. }
  2420. } );
  2421. return this;
  2422. };
  2423. }(),
  2424. clone: function () {
  2425. return new this.constructor().copy( this );
  2426. },
  2427. copy: function ( box ) {
  2428. this.min.copy( box.min );
  2429. this.max.copy( box.max );
  2430. return this;
  2431. },
  2432. makeEmpty: function () {
  2433. this.min.x = this.min.y = this.min.z = + Infinity;
  2434. this.max.x = this.max.y = this.max.z = - Infinity;
  2435. return this;
  2436. },
  2437. isEmpty: function () {
  2438. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  2439. return ( this.max.x < this.min.x ) || ( this.max.y < this.min.y ) || ( this.max.z < this.min.z );
  2440. },
  2441. center: function ( optionalTarget ) {
  2442. var result = optionalTarget || new THREE.Vector3();
  2443. return result.addVectors( this.min, this.max ).multiplyScalar( 0.5 );
  2444. },
  2445. size: function ( optionalTarget ) {
  2446. var result = optionalTarget || new THREE.Vector3();
  2447. return result.subVectors( this.max, this.min );
  2448. },
  2449. expandByPoint: function ( point ) {
  2450. this.min.min( point );
  2451. this.max.max( point );
  2452. return this;
  2453. },
  2454. expandByVector: function ( vector ) {
  2455. this.min.sub( vector );
  2456. this.max.add( vector );
  2457. return this;
  2458. },
  2459. expandByScalar: function ( scalar ) {
  2460. this.min.addScalar( - scalar );
  2461. this.max.addScalar( scalar );
  2462. return this;
  2463. },
  2464. containsPoint: function ( point ) {
  2465. if ( point.x < this.min.x || point.x > this.max.x ||
  2466. point.y < this.min.y || point.y > this.max.y ||
  2467. point.z < this.min.z || point.z > this.max.z ) {
  2468. return false;
  2469. }
  2470. return true;
  2471. },
  2472. containsBox: function ( box ) {
  2473. if ( ( this.min.x <= box.min.x ) && ( box.max.x <= this.max.x ) &&
  2474. ( this.min.y <= box.min.y ) && ( box.max.y <= this.max.y ) &&
  2475. ( this.min.z <= box.min.z ) && ( box.max.z <= this.max.z ) ) {
  2476. return true;
  2477. }
  2478. return false;
  2479. },
  2480. getParameter: function ( point, optionalTarget ) {
  2481. // This can potentially have a divide by zero if the box
  2482. // has a size dimension of 0.
  2483. var result = optionalTarget || new THREE.Vector3();
  2484. return result.set(
  2485. ( point.x - this.min.x ) / ( this.max.x - this.min.x ),
  2486. ( point.y - this.min.y ) / ( this.max.y - this.min.y ),
  2487. ( point.z - this.min.z ) / ( this.max.z - this.min.z )
  2488. );
  2489. },
  2490. intersectsBox: function ( box ) {
  2491. // using 6 splitting planes to rule out intersections.
  2492. if ( box.max.x < this.min.x || box.min.x > this.max.x ||
  2493. box.max.y < this.min.y || box.min.y > this.max.y ||
  2494. box.max.z < this.min.z || box.min.z > this.max.z ) {
  2495. return false;
  2496. }
  2497. return true;
  2498. },
  2499. intersectsSphere: ( function () {
  2500. var closestPoint;
  2501. return function intersectsSphere( sphere ) {
  2502. if ( closestPoint === undefined ) closestPoint = new THREE.Vector3();
  2503. // Find the point on the AABB closest to the sphere center.
  2504. this.clampPoint( sphere.center, closestPoint );
  2505. // If that point is inside the sphere, the AABB and sphere intersect.
  2506. return closestPoint.distanceToSquared( sphere.center ) <= ( sphere.radius * sphere.radius );
  2507. };
  2508. } )(),
  2509. intersectsPlane: function ( plane ) {
  2510. // We compute the minimum and maximum dot product values. If those values
  2511. // are on the same side (back or front) of the plane, then there is no intersection.
  2512. var min, max;
  2513. if ( plane.normal.x > 0 ) {
  2514. min = plane.normal.x * this.min.x;
  2515. max = plane.normal.x * this.max.x;
  2516. } else {
  2517. min = plane.normal.x * this.max.x;
  2518. max = plane.normal.x * this.min.x;
  2519. }
  2520. if ( plane.normal.y > 0 ) {
  2521. min += plane.normal.y * this.min.y;
  2522. max += plane.normal.y * this.max.y;
  2523. } else {
  2524. min += plane.normal.y * this.max.y;
  2525. max += plane.normal.y * this.min.y;
  2526. }
  2527. if ( plane.normal.z > 0 ) {
  2528. min += plane.normal.z * this.min.z;
  2529. max += plane.normal.z * this.max.z;
  2530. } else {
  2531. min += plane.normal.z * this.max.z;
  2532. max += plane.normal.z * this.min.z;
  2533. }
  2534. return ( min <= plane.constant && max >= plane.constant );
  2535. },
  2536. clampPoint: function ( point, optionalTarget ) {
  2537. var result = optionalTarget || new THREE.Vector3();
  2538. return result.copy( point ).clamp( this.min, this.max );
  2539. },
  2540. distanceToPoint: function () {
  2541. var v1 = new THREE.Vector3();
  2542. return function distanceToPoint( point ) {
  2543. var clampedPoint = v1.copy( point ).clamp( this.min, this.max );
  2544. return clampedPoint.sub( point ).length();
  2545. };
  2546. }(),
  2547. getBoundingSphere: function () {
  2548. var v1 = new THREE.Vector3();
  2549. return function getBoundingSphere( optionalTarget ) {
  2550. var result = optionalTarget || new THREE.Sphere();
  2551. result.center = this.center();
  2552. result.radius = this.size( v1 ).length() * 0.5;
  2553. return result;
  2554. };
  2555. }(),
  2556. intersect: function ( box ) {
  2557. this.min.max( box.min );
  2558. this.max.min( box.max );
  2559. // 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.
  2560. if( this.isEmpty() ) this.makeEmpty();
  2561. return this;
  2562. },
  2563. union: function ( box ) {
  2564. this.min.min( box.min );
  2565. this.max.max( box.max );
  2566. return this;
  2567. },
  2568. applyMatrix4: function () {
  2569. var points = [
  2570. new THREE.Vector3(),
  2571. new THREE.Vector3(),
  2572. new THREE.Vector3(),
  2573. new THREE.Vector3(),
  2574. new THREE.Vector3(),
  2575. new THREE.Vector3(),
  2576. new THREE.Vector3(),
  2577. new THREE.Vector3()
  2578. ];
  2579. return function applyMatrix4( matrix ) {
  2580. // transform of empty box is an empty box.
  2581. if( this.isEmpty() ) return this;
  2582. // NOTE: I am using a binary pattern to specify all 2^3 combinations below
  2583. points[ 0 ].set( this.min.x, this.min.y, this.min.z ).applyMatrix4( matrix ); // 000
  2584. points[ 1 ].set( this.min.x, this.min.y, this.max.z ).applyMatrix4( matrix ); // 001
  2585. points[ 2 ].set( this.min.x, this.max.y, this.min.z ).applyMatrix4( matrix ); // 010
  2586. points[ 3 ].set( this.min.x, this.max.y, this.max.z ).applyMatrix4( matrix ); // 011
  2587. points[ 4 ].set( this.max.x, this.min.y, this.min.z ).applyMatrix4( matrix ); // 100
  2588. points[ 5 ].set( this.max.x, this.min.y, this.max.z ).applyMatrix4( matrix ); // 101
  2589. points[ 6 ].set( this.max.x, this.max.y, this.min.z ).applyMatrix4( matrix ); // 110
  2590. points[ 7 ].set( this.max.x, this.max.y, this.max.z ).applyMatrix4( matrix ); // 111
  2591. this.setFromPoints( points );
  2592. return this;
  2593. };
  2594. }(),
  2595. translate: function ( offset ) {
  2596. this.min.add( offset );
  2597. this.max.add( offset );
  2598. return this;
  2599. },
  2600. equals: function ( box ) {
  2601. return box.min.equals( this.min ) && box.max.equals( this.max );
  2602. }
  2603. };
  2604. // File:src/math/Matrix3.js
  2605. /**
  2606. * @author alteredq / http://alteredqualia.com/
  2607. * @author WestLangley / http://github.com/WestLangley
  2608. * @author bhouston / http://clara.io
  2609. * @author tschw
  2610. */
  2611. THREE.Matrix3 = function () {
  2612. this.elements = new Float32Array( [
  2613. 1, 0, 0,
  2614. 0, 1, 0,
  2615. 0, 0, 1
  2616. ] );
  2617. if ( arguments.length > 0 ) {
  2618. console.error( 'THREE.Matrix3: the constructor no longer reads arguments. use .set() instead.' );
  2619. }
  2620. };
  2621. THREE.Matrix3.prototype = {
  2622. constructor: THREE.Matrix3,
  2623. set: function ( n11, n12, n13, n21, n22, n23, n31, n32, n33 ) {
  2624. var te = this.elements;
  2625. te[ 0 ] = n11; te[ 1 ] = n21; te[ 2 ] = n31;
  2626. te[ 3 ] = n12; te[ 4 ] = n22; te[ 5 ] = n32;
  2627. te[ 6 ] = n13; te[ 7 ] = n23; te[ 8 ] = n33;
  2628. return this;
  2629. },
  2630. identity: function () {
  2631. this.set(
  2632. 1, 0, 0,
  2633. 0, 1, 0,
  2634. 0, 0, 1
  2635. );
  2636. return this;
  2637. },
  2638. clone: function () {
  2639. return new this.constructor().fromArray( this.elements );
  2640. },
  2641. copy: function ( m ) {
  2642. var me = m.elements;
  2643. this.set(
  2644. me[ 0 ], me[ 3 ], me[ 6 ],
  2645. me[ 1 ], me[ 4 ], me[ 7 ],
  2646. me[ 2 ], me[ 5 ], me[ 8 ]
  2647. );
  2648. return this;
  2649. },
  2650. setFromMatrix4: function( m ) {
  2651. var me = m.elements;
  2652. this.set(
  2653. me[ 0 ], me[ 4 ], me[ 8 ],
  2654. me[ 1 ], me[ 5 ], me[ 9 ],
  2655. me[ 2 ], me[ 6 ], me[ 10 ]
  2656. );
  2657. return this;
  2658. },
  2659. applyToVector3Array: function () {
  2660. var v1;
  2661. return function applyToVector3Array( array, offset, length ) {
  2662. if ( v1 === undefined ) v1 = new THREE.Vector3();
  2663. if ( offset === undefined ) offset = 0;
  2664. if ( length === undefined ) length = array.length;
  2665. for ( var i = 0, j = offset; i < length; i += 3, j += 3 ) {
  2666. v1.fromArray( array, j );
  2667. v1.applyMatrix3( this );
  2668. v1.toArray( array, j );
  2669. }
  2670. return array;
  2671. };
  2672. }(),
  2673. applyToBuffer: function () {
  2674. var v1;
  2675. return function applyToBuffer( buffer, offset, length ) {
  2676. if ( v1 === undefined ) v1 = new THREE.Vector3();
  2677. if ( offset === undefined ) offset = 0;
  2678. if ( length === undefined ) length = buffer.length / buffer.itemSize;
  2679. for ( var i = 0, j = offset; i < length; i ++, j ++ ) {
  2680. v1.x = buffer.getX( j );
  2681. v1.y = buffer.getY( j );
  2682. v1.z = buffer.getZ( j );
  2683. v1.applyMatrix3( this );
  2684. buffer.setXYZ( v1.x, v1.y, v1.z );
  2685. }
  2686. return buffer;
  2687. };
  2688. }(),
  2689. multiplyScalar: function ( s ) {
  2690. var te = this.elements;
  2691. te[ 0 ] *= s; te[ 3 ] *= s; te[ 6 ] *= s;
  2692. te[ 1 ] *= s; te[ 4 ] *= s; te[ 7 ] *= s;
  2693. te[ 2 ] *= s; te[ 5 ] *= s; te[ 8 ] *= s;
  2694. return this;
  2695. },
  2696. determinant: function () {
  2697. var te = this.elements;
  2698. var a = te[ 0 ], b = te[ 1 ], c = te[ 2 ],
  2699. d = te[ 3 ], e = te[ 4 ], f = te[ 5 ],
  2700. g = te[ 6 ], h = te[ 7 ], i = te[ 8 ];
  2701. return a * e * i - a * f * h - b * d * i + b * f * g + c * d * h - c * e * g;
  2702. },
  2703. getInverse: function ( matrix, throwOnDegenerate ) {
  2704. if ( matrix instanceof THREE.Matrix4 ) {
  2705. console.error( "THREE.Matrix3.getInverse no longer takes a Matrix4 argument." );
  2706. }
  2707. var me = matrix.elements,
  2708. te = this.elements,
  2709. n11 = me[ 0 ], n21 = me[ 1 ], n31 = me[ 2 ],
  2710. n12 = me[ 3 ], n22 = me[ 4 ], n32 = me[ 5 ],
  2711. n13 = me[ 6 ], n23 = me[ 7 ], n33 = me[ 8 ],
  2712. t11 = n33 * n22 - n32 * n23,
  2713. t12 = n32 * n13 - n33 * n12,
  2714. t13 = n23 * n12 - n22 * n13,
  2715. det = n11 * t11 + n21 * t12 + n31 * t13;
  2716. if ( det === 0 ) {
  2717. var msg = "THREE.Matrix3.getInverse(): can't invert matrix, determinant is 0";
  2718. if ( throwOnDegenerate || false ) {
  2719. throw new Error( msg );
  2720. } else {
  2721. console.warn( msg );
  2722. }
  2723. return this.identity();
  2724. }
  2725. var detInv = 1 / det;
  2726. te[ 0 ] = t11 * detInv;
  2727. te[ 1 ] = ( n31 * n23 - n33 * n21 ) * detInv;
  2728. te[ 2 ] = ( n32 * n21 - n31 * n22 ) * detInv;
  2729. te[ 3 ] = t12 * detInv;
  2730. te[ 4 ] = ( n33 * n11 - n31 * n13 ) * detInv;
  2731. te[ 5 ] = ( n31 * n12 - n32 * n11 ) * detInv;
  2732. te[ 6 ] = t13 * detInv;
  2733. te[ 7 ] = ( n21 * n13 - n23 * n11 ) * detInv;
  2734. te[ 8 ] = ( n22 * n11 - n21 * n12 ) * detInv;
  2735. return this;
  2736. },
  2737. transpose: function () {
  2738. var tmp, m = this.elements;
  2739. tmp = m[ 1 ]; m[ 1 ] = m[ 3 ]; m[ 3 ] = tmp;
  2740. tmp = m[ 2 ]; m[ 2 ] = m[ 6 ]; m[ 6 ] = tmp;
  2741. tmp = m[ 5 ]; m[ 5 ] = m[ 7 ]; m[ 7 ] = tmp;
  2742. return this;
  2743. },
  2744. flattenToArrayOffset: function ( array, offset ) {
  2745. console.warn( "THREE.Matrix3: .flattenToArrayOffset is deprecated " +
  2746. "- just use .toArray instead." );
  2747. return this.toArray( array, offset );
  2748. },
  2749. getNormalMatrix: function ( matrix4 ) {
  2750. return this.setFromMatrix4( matrix4 ).getInverse( this ).transpose();
  2751. },
  2752. transposeIntoArray: function ( r ) {
  2753. var m = this.elements;
  2754. r[ 0 ] = m[ 0 ];
  2755. r[ 1 ] = m[ 3 ];
  2756. r[ 2 ] = m[ 6 ];
  2757. r[ 3 ] = m[ 1 ];
  2758. r[ 4 ] = m[ 4 ];
  2759. r[ 5 ] = m[ 7 ];
  2760. r[ 6 ] = m[ 2 ];
  2761. r[ 7 ] = m[ 5 ];
  2762. r[ 8 ] = m[ 8 ];
  2763. return this;
  2764. },
  2765. fromArray: function ( array ) {
  2766. this.elements.set( array );
  2767. return this;
  2768. },
  2769. toArray: function ( array, offset ) {
  2770. if ( array === undefined ) array = [];
  2771. if ( offset === undefined ) offset = 0;
  2772. var te = this.elements;
  2773. array[ offset ] = te[ 0 ];
  2774. array[ offset + 1 ] = te[ 1 ];
  2775. array[ offset + 2 ] = te[ 2 ];
  2776. array[ offset + 3 ] = te[ 3 ];
  2777. array[ offset + 4 ] = te[ 4 ];
  2778. array[ offset + 5 ] = te[ 5 ];
  2779. array[ offset + 6 ] = te[ 6 ];
  2780. array[ offset + 7 ] = te[ 7 ];
  2781. array[ offset + 8 ] = te[ 8 ];
  2782. return array;
  2783. }
  2784. };
  2785. // File:src/math/Matrix4.js
  2786. /**
  2787. * @author mrdoob / http://mrdoob.com/
  2788. * @author supereggbert / http://www.paulbrunt.co.uk/
  2789. * @author philogb / http://blog.thejit.org/
  2790. * @author jordi_ros / http://plattsoft.com
  2791. * @author D1plo1d / http://github.com/D1plo1d
  2792. * @author alteredq / http://alteredqualia.com/
  2793. * @author mikael emtinger / http://gomo.se/
  2794. * @author timknip / http://www.floorplanner.com/
  2795. * @author bhouston / http://clara.io
  2796. * @author WestLangley / http://github.com/WestLangley
  2797. */
  2798. THREE.Matrix4 = function () {
  2799. this.elements = new Float32Array( [
  2800. 1, 0, 0, 0,
  2801. 0, 1, 0, 0,
  2802. 0, 0, 1, 0,
  2803. 0, 0, 0, 1
  2804. ] );
  2805. if ( arguments.length > 0 ) {
  2806. console.error( 'THREE.Matrix4: the constructor no longer reads arguments. use .set() instead.' );
  2807. }
  2808. };
  2809. THREE.Matrix4.prototype = {
  2810. constructor: THREE.Matrix4,
  2811. set: function ( n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44 ) {
  2812. var te = this.elements;
  2813. te[ 0 ] = n11; te[ 4 ] = n12; te[ 8 ] = n13; te[ 12 ] = n14;
  2814. te[ 1 ] = n21; te[ 5 ] = n22; te[ 9 ] = n23; te[ 13 ] = n24;
  2815. te[ 2 ] = n31; te[ 6 ] = n32; te[ 10 ] = n33; te[ 14 ] = n34;
  2816. te[ 3 ] = n41; te[ 7 ] = n42; te[ 11 ] = n43; te[ 15 ] = n44;
  2817. return this;
  2818. },
  2819. identity: function () {
  2820. this.set(
  2821. 1, 0, 0, 0,
  2822. 0, 1, 0, 0,
  2823. 0, 0, 1, 0,
  2824. 0, 0, 0, 1
  2825. );
  2826. return this;
  2827. },
  2828. clone: function () {
  2829. return new THREE.Matrix4().fromArray( this.elements );
  2830. },
  2831. copy: function ( m ) {
  2832. this.elements.set( m.elements );
  2833. return this;
  2834. },
  2835. copyPosition: function ( m ) {
  2836. var te = this.elements;
  2837. var me = m.elements;
  2838. te[ 12 ] = me[ 12 ];
  2839. te[ 13 ] = me[ 13 ];
  2840. te[ 14 ] = me[ 14 ];
  2841. return this;
  2842. },
  2843. extractBasis: function ( xAxis, yAxis, zAxis ) {
  2844. xAxis.setFromMatrixColumn( this, 0 );
  2845. yAxis.setFromMatrixColumn( this, 1 );
  2846. zAxis.setFromMatrixColumn( this, 2 );
  2847. return this;
  2848. },
  2849. makeBasis: function ( xAxis, yAxis, zAxis ) {
  2850. this.set(
  2851. xAxis.x, yAxis.x, zAxis.x, 0,
  2852. xAxis.y, yAxis.y, zAxis.y, 0,
  2853. xAxis.z, yAxis.z, zAxis.z, 0,
  2854. 0, 0, 0, 1
  2855. );
  2856. return this;
  2857. },
  2858. extractRotation: function () {
  2859. var v1;
  2860. return function extractRotation( m ) {
  2861. if ( v1 === undefined ) v1 = new THREE.Vector3();
  2862. var te = this.elements;
  2863. var me = m.elements;
  2864. var scaleX = 1 / v1.setFromMatrixColumn( m, 0 ).length();
  2865. var scaleY = 1 / v1.setFromMatrixColumn( m, 1 ).length();
  2866. var scaleZ = 1 / v1.setFromMatrixColumn( m, 2 ).length();
  2867. te[ 0 ] = me[ 0 ] * scaleX;
  2868. te[ 1 ] = me[ 1 ] * scaleX;
  2869. te[ 2 ] = me[ 2 ] * scaleX;
  2870. te[ 4 ] = me[ 4 ] * scaleY;
  2871. te[ 5 ] = me[ 5 ] * scaleY;
  2872. te[ 6 ] = me[ 6 ] * scaleY;
  2873. te[ 8 ] = me[ 8 ] * scaleZ;
  2874. te[ 9 ] = me[ 9 ] * scaleZ;
  2875. te[ 10 ] = me[ 10 ] * scaleZ;
  2876. return this;
  2877. };
  2878. }(),
  2879. makeRotationFromEuler: function ( euler ) {
  2880. if ( euler instanceof THREE.Euler === false ) {
  2881. console.error( 'THREE.Matrix: .makeRotationFromEuler() now expects a Euler rotation rather than a Vector3 and order.' );
  2882. }
  2883. var te = this.elements;
  2884. var x = euler.x, y = euler.y, z = euler.z;
  2885. var a = Math.cos( x ), b = Math.sin( x );
  2886. var c = Math.cos( y ), d = Math.sin( y );
  2887. var e = Math.cos( z ), f = Math.sin( z );
  2888. if ( euler.order === 'XYZ' ) {
  2889. var ae = a * e, af = a * f, be = b * e, bf = b * f;
  2890. te[ 0 ] = c * e;
  2891. te[ 4 ] = - c * f;
  2892. te[ 8 ] = d;
  2893. te[ 1 ] = af + be * d;
  2894. te[ 5 ] = ae - bf * d;
  2895. te[ 9 ] = - b * c;
  2896. te[ 2 ] = bf - ae * d;
  2897. te[ 6 ] = be + af * d;
  2898. te[ 10 ] = a * c;
  2899. } else if ( euler.order === 'YXZ' ) {
  2900. var ce = c * e, cf = c * f, de = d * e, df = d * f;
  2901. te[ 0 ] = ce + df * b;
  2902. te[ 4 ] = de * b - cf;
  2903. te[ 8 ] = a * d;
  2904. te[ 1 ] = a * f;
  2905. te[ 5 ] = a * e;
  2906. te[ 9 ] = - b;
  2907. te[ 2 ] = cf * b - de;
  2908. te[ 6 ] = df + ce * b;
  2909. te[ 10 ] = a * c;
  2910. } else if ( euler.order === 'ZXY' ) {
  2911. var ce = c * e, cf = c * f, de = d * e, df = d * f;
  2912. te[ 0 ] = ce - df * b;
  2913. te[ 4 ] = - a * f;
  2914. te[ 8 ] = de + cf * b;
  2915. te[ 1 ] = cf + de * b;
  2916. te[ 5 ] = a * e;
  2917. te[ 9 ] = df - ce * b;
  2918. te[ 2 ] = - a * d;
  2919. te[ 6 ] = b;
  2920. te[ 10 ] = a * c;
  2921. } else if ( euler.order === 'ZYX' ) {
  2922. var ae = a * e, af = a * f, be = b * e, bf = b * f;
  2923. te[ 0 ] = c * e;
  2924. te[ 4 ] = be * d - af;
  2925. te[ 8 ] = ae * d + bf;
  2926. te[ 1 ] = c * f;
  2927. te[ 5 ] = bf * d + ae;
  2928. te[ 9 ] = af * d - be;
  2929. te[ 2 ] = - d;
  2930. te[ 6 ] = b * c;
  2931. te[ 10 ] = a * c;
  2932. } else if ( euler.order === 'YZX' ) {
  2933. var ac = a * c, ad = a * d, bc = b * c, bd = b * d;
  2934. te[ 0 ] = c * e;
  2935. te[ 4 ] = bd - ac * f;
  2936. te[ 8 ] = bc * f + ad;
  2937. te[ 1 ] = f;
  2938. te[ 5 ] = a * e;
  2939. te[ 9 ] = - b * e;
  2940. te[ 2 ] = - d * e;
  2941. te[ 6 ] = ad * f + bc;
  2942. te[ 10 ] = ac - bd * f;
  2943. } else if ( euler.order === 'XZY' ) {
  2944. var ac = a * c, ad = a * d, bc = b * c, bd = b * d;
  2945. te[ 0 ] = c * e;
  2946. te[ 4 ] = - f;
  2947. te[ 8 ] = d * e;
  2948. te[ 1 ] = ac * f + bd;
  2949. te[ 5 ] = a * e;
  2950. te[ 9 ] = ad * f - bc;
  2951. te[ 2 ] = bc * f - ad;
  2952. te[ 6 ] = b * e;
  2953. te[ 10 ] = bd * f + ac;
  2954. }
  2955. // last column
  2956. te[ 3 ] = 0;
  2957. te[ 7 ] = 0;
  2958. te[ 11 ] = 0;
  2959. // bottom row
  2960. te[ 12 ] = 0;
  2961. te[ 13 ] = 0;
  2962. te[ 14 ] = 0;
  2963. te[ 15 ] = 1;
  2964. return this;
  2965. },
  2966. makeRotationFromQuaternion: function ( q ) {
  2967. var te = this.elements;
  2968. var x = q.x, y = q.y, z = q.z, w = q.w;
  2969. var x2 = x + x, y2 = y + y, z2 = z + z;
  2970. var xx = x * x2, xy = x * y2, xz = x * z2;
  2971. var yy = y * y2, yz = y * z2, zz = z * z2;
  2972. var wx = w * x2, wy = w * y2, wz = w * z2;
  2973. te[ 0 ] = 1 - ( yy + zz );
  2974. te[ 4 ] = xy - wz;
  2975. te[ 8 ] = xz + wy;
  2976. te[ 1 ] = xy + wz;
  2977. te[ 5 ] = 1 - ( xx + zz );
  2978. te[ 9 ] = yz - wx;
  2979. te[ 2 ] = xz - wy;
  2980. te[ 6 ] = yz + wx;
  2981. te[ 10 ] = 1 - ( xx + yy );
  2982. // last column
  2983. te[ 3 ] = 0;
  2984. te[ 7 ] = 0;
  2985. te[ 11 ] = 0;
  2986. // bottom row
  2987. te[ 12 ] = 0;
  2988. te[ 13 ] = 0;
  2989. te[ 14 ] = 0;
  2990. te[ 15 ] = 1;
  2991. return this;
  2992. },
  2993. lookAt: function () {
  2994. var x, y, z;
  2995. return function lookAt( eye, target, up ) {
  2996. if ( x === undefined ) {
  2997. x = new THREE.Vector3();
  2998. y = new THREE.Vector3();
  2999. z = new THREE.Vector3();
  3000. }
  3001. var te = this.elements;
  3002. z.subVectors( eye, target ).normalize();
  3003. if ( z.lengthSq() === 0 ) {
  3004. z.z = 1;
  3005. }
  3006. x.crossVectors( up, z ).normalize();
  3007. if ( x.lengthSq() === 0 ) {
  3008. z.z += 0.0001;
  3009. x.crossVectors( up, z ).normalize();
  3010. }
  3011. y.crossVectors( z, x );
  3012. te[ 0 ] = x.x; te[ 4 ] = y.x; te[ 8 ] = z.x;
  3013. te[ 1 ] = x.y; te[ 5 ] = y.y; te[ 9 ] = z.y;
  3014. te[ 2 ] = x.z; te[ 6 ] = y.z; te[ 10 ] = z.z;
  3015. return this;
  3016. };
  3017. }(),
  3018. multiply: function ( m, n ) {
  3019. if ( n !== undefined ) {
  3020. console.warn( 'THREE.Matrix4: .multiply() now only accepts one argument. Use .multiplyMatrices( a, b ) instead.' );
  3021. return this.multiplyMatrices( m, n );
  3022. }
  3023. return this.multiplyMatrices( this, m );
  3024. },
  3025. premultiply: function ( m ) {
  3026. return this.multiplyMatrices( m, this );
  3027. },
  3028. multiplyMatrices: function ( a, b ) {
  3029. var ae = a.elements;
  3030. var be = b.elements;
  3031. var te = this.elements;
  3032. var a11 = ae[ 0 ], a12 = ae[ 4 ], a13 = ae[ 8 ], a14 = ae[ 12 ];
  3033. var a21 = ae[ 1 ], a22 = ae[ 5 ], a23 = ae[ 9 ], a24 = ae[ 13 ];
  3034. var a31 = ae[ 2 ], a32 = ae[ 6 ], a33 = ae[ 10 ], a34 = ae[ 14 ];
  3035. var a41 = ae[ 3 ], a42 = ae[ 7 ], a43 = ae[ 11 ], a44 = ae[ 15 ];
  3036. var b11 = be[ 0 ], b12 = be[ 4 ], b13 = be[ 8 ], b14 = be[ 12 ];
  3037. var b21 = be[ 1 ], b22 = be[ 5 ], b23 = be[ 9 ], b24 = be[ 13 ];
  3038. var b31 = be[ 2 ], b32 = be[ 6 ], b33 = be[ 10 ], b34 = be[ 14 ];
  3039. var b41 = be[ 3 ], b42 = be[ 7 ], b43 = be[ 11 ], b44 = be[ 15 ];
  3040. te[ 0 ] = a11 * b11 + a12 * b21 + a13 * b31 + a14 * b41;
  3041. te[ 4 ] = a11 * b12 + a12 * b22 + a13 * b32 + a14 * b42;
  3042. te[ 8 ] = a11 * b13 + a12 * b23 + a13 * b33 + a14 * b43;
  3043. te[ 12 ] = a11 * b14 + a12 * b24 + a13 * b34 + a14 * b44;
  3044. te[ 1 ] = a21 * b11 + a22 * b21 + a23 * b31 + a24 * b41;
  3045. te[ 5 ] = a21 * b12 + a22 * b22 + a23 * b32 + a24 * b42;
  3046. te[ 9 ] = a21 * b13 + a22 * b23 + a23 * b33 + a24 * b43;
  3047. te[ 13 ] = a21 * b14 + a22 * b24 + a23 * b34 + a24 * b44;
  3048. te[ 2 ] = a31 * b11 + a32 * b21 + a33 * b31 + a34 * b41;
  3049. te[ 6 ] = a31 * b12 + a32 * b22 + a33 * b32 + a34 * b42;
  3050. te[ 10 ] = a31 * b13 + a32 * b23 + a33 * b33 + a34 * b43;
  3051. te[ 14 ] = a31 * b14 + a32 * b24 + a33 * b34 + a34 * b44;
  3052. te[ 3 ] = a41 * b11 + a42 * b21 + a43 * b31 + a44 * b41;
  3053. te[ 7 ] = a41 * b12 + a42 * b22 + a43 * b32 + a44 * b42;
  3054. te[ 11 ] = a41 * b13 + a42 * b23 + a43 * b33 + a44 * b43;
  3055. te[ 15 ] = a41 * b14 + a42 * b24 + a43 * b34 + a44 * b44;
  3056. return this;
  3057. },
  3058. multiplyToArray: function ( a, b, r ) {
  3059. var te = this.elements;
  3060. this.multiplyMatrices( a, b );
  3061. r[ 0 ] = te[ 0 ]; r[ 1 ] = te[ 1 ]; r[ 2 ] = te[ 2 ]; r[ 3 ] = te[ 3 ];
  3062. r[ 4 ] = te[ 4 ]; r[ 5 ] = te[ 5 ]; r[ 6 ] = te[ 6 ]; r[ 7 ] = te[ 7 ];
  3063. r[ 8 ] = te[ 8 ]; r[ 9 ] = te[ 9 ]; r[ 10 ] = te[ 10 ]; r[ 11 ] = te[ 11 ];
  3064. r[ 12 ] = te[ 12 ]; r[ 13 ] = te[ 13 ]; r[ 14 ] = te[ 14 ]; r[ 15 ] = te[ 15 ];
  3065. return this;
  3066. },
  3067. multiplyScalar: function ( s ) {
  3068. var te = this.elements;
  3069. te[ 0 ] *= s; te[ 4 ] *= s; te[ 8 ] *= s; te[ 12 ] *= s;
  3070. te[ 1 ] *= s; te[ 5 ] *= s; te[ 9 ] *= s; te[ 13 ] *= s;
  3071. te[ 2 ] *= s; te[ 6 ] *= s; te[ 10 ] *= s; te[ 14 ] *= s;
  3072. te[ 3 ] *= s; te[ 7 ] *= s; te[ 11 ] *= s; te[ 15 ] *= s;
  3073. return this;
  3074. },
  3075. applyToVector3Array: function () {
  3076. var v1;
  3077. return function applyToVector3Array( array, offset, length ) {
  3078. if ( v1 === undefined ) v1 = new THREE.Vector3();
  3079. if ( offset === undefined ) offset = 0;
  3080. if ( length === undefined ) length = array.length;
  3081. for ( var i = 0, j = offset; i < length; i += 3, j += 3 ) {
  3082. v1.fromArray( array, j );
  3083. v1.applyMatrix4( this );
  3084. v1.toArray( array, j );
  3085. }
  3086. return array;
  3087. };
  3088. }(),
  3089. applyToBuffer: function () {
  3090. var v1;
  3091. return function applyToBuffer( buffer, offset, length ) {
  3092. if ( v1 === undefined ) v1 = new THREE.Vector3();
  3093. if ( offset === undefined ) offset = 0;
  3094. if ( length === undefined ) length = buffer.length / buffer.itemSize;
  3095. for ( var i = 0, j = offset; i < length; i ++, j ++ ) {
  3096. v1.x = buffer.getX( j );
  3097. v1.y = buffer.getY( j );
  3098. v1.z = buffer.getZ( j );
  3099. v1.applyMatrix4( this );
  3100. buffer.setXYZ( v1.x, v1.y, v1.z );
  3101. }
  3102. return buffer;
  3103. };
  3104. }(),
  3105. determinant: function () {
  3106. var te = this.elements;
  3107. var n11 = te[ 0 ], n12 = te[ 4 ], n13 = te[ 8 ], n14 = te[ 12 ];
  3108. var n21 = te[ 1 ], n22 = te[ 5 ], n23 = te[ 9 ], n24 = te[ 13 ];
  3109. var n31 = te[ 2 ], n32 = te[ 6 ], n33 = te[ 10 ], n34 = te[ 14 ];
  3110. var n41 = te[ 3 ], n42 = te[ 7 ], n43 = te[ 11 ], n44 = te[ 15 ];
  3111. //TODO: make this more efficient
  3112. //( based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm )
  3113. return (
  3114. n41 * (
  3115. + n14 * n23 * n32
  3116. - n13 * n24 * n32
  3117. - n14 * n22 * n33
  3118. + n12 * n24 * n33
  3119. + n13 * n22 * n34
  3120. - n12 * n23 * n34
  3121. ) +
  3122. n42 * (
  3123. + n11 * n23 * n34
  3124. - n11 * n24 * n33
  3125. + n14 * n21 * n33
  3126. - n13 * n21 * n34
  3127. + n13 * n24 * n31
  3128. - n14 * n23 * n31
  3129. ) +
  3130. n43 * (
  3131. + n11 * n24 * n32
  3132. - n11 * n22 * n34
  3133. - n14 * n21 * n32
  3134. + n12 * n21 * n34
  3135. + n14 * n22 * n31
  3136. - n12 * n24 * n31
  3137. ) +
  3138. n44 * (
  3139. - n13 * n22 * n31
  3140. - n11 * n23 * n32
  3141. + n11 * n22 * n33
  3142. + n13 * n21 * n32
  3143. - n12 * n21 * n33
  3144. + n12 * n23 * n31
  3145. )
  3146. );
  3147. },
  3148. transpose: function () {
  3149. var te = this.elements;
  3150. var tmp;
  3151. tmp = te[ 1 ]; te[ 1 ] = te[ 4 ]; te[ 4 ] = tmp;
  3152. tmp = te[ 2 ]; te[ 2 ] = te[ 8 ]; te[ 8 ] = tmp;
  3153. tmp = te[ 6 ]; te[ 6 ] = te[ 9 ]; te[ 9 ] = tmp;
  3154. tmp = te[ 3 ]; te[ 3 ] = te[ 12 ]; te[ 12 ] = tmp;
  3155. tmp = te[ 7 ]; te[ 7 ] = te[ 13 ]; te[ 13 ] = tmp;
  3156. tmp = te[ 11 ]; te[ 11 ] = te[ 14 ]; te[ 14 ] = tmp;
  3157. return this;
  3158. },
  3159. flattenToArrayOffset: function ( array, offset ) {
  3160. console.warn( "THREE.Matrix3: .flattenToArrayOffset is deprecated " +
  3161. "- just use .toArray instead." );
  3162. return this.toArray( array, offset );
  3163. },
  3164. getPosition: function () {
  3165. var v1;
  3166. return function getPosition() {
  3167. if ( v1 === undefined ) v1 = new THREE.Vector3();
  3168. console.warn( 'THREE.Matrix4: .getPosition() has been removed. Use Vector3.setFromMatrixPosition( matrix ) instead.' );
  3169. return v1.setFromMatrixColumn( this, 3 );
  3170. };
  3171. }(),
  3172. setPosition: function ( v ) {
  3173. var te = this.elements;
  3174. te[ 12 ] = v.x;
  3175. te[ 13 ] = v.y;
  3176. te[ 14 ] = v.z;
  3177. return this;
  3178. },
  3179. getInverse: function ( m, throwOnDegenerate ) {
  3180. // based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm
  3181. var te = this.elements,
  3182. me = m.elements,
  3183. n11 = me[ 0 ], n21 = me[ 1 ], n31 = me[ 2 ], n41 = me[ 3 ],
  3184. n12 = me[ 4 ], n22 = me[ 5 ], n32 = me[ 6 ], n42 = me[ 7 ],
  3185. n13 = me[ 8 ], n23 = me[ 9 ], n33 = me[ 10 ], n43 = me[ 11 ],
  3186. n14 = me[ 12 ], n24 = me[ 13 ], n34 = me[ 14 ], n44 = me[ 15 ],
  3187. t11 = n23 * n34 * n42 - n24 * n33 * n42 + n24 * n32 * n43 - n22 * n34 * n43 - n23 * n32 * n44 + n22 * n33 * n44,
  3188. t12 = n14 * n33 * n42 - n13 * n34 * n42 - n14 * n32 * n43 + n12 * n34 * n43 + n13 * n32 * n44 - n12 * n33 * n44,
  3189. t13 = n13 * n24 * n42 - n14 * n23 * n42 + n14 * n22 * n43 - n12 * n24 * n43 - n13 * n22 * n44 + n12 * n23 * n44,
  3190. t14 = n14 * n23 * n32 - n13 * n24 * n32 - n14 * n22 * n33 + n12 * n24 * n33 + n13 * n22 * n34 - n12 * n23 * n34;
  3191. var det = n11 * t11 + n21 * t12 + n31 * t13 + n41 * t14;
  3192. if ( det === 0 ) {
  3193. var msg = "THREE.Matrix4.getInverse(): can't invert matrix, determinant is 0";
  3194. if ( throwOnDegenerate || false ) {
  3195. throw new Error( msg );
  3196. } else {
  3197. console.warn( msg );
  3198. }
  3199. return this.identity();
  3200. }
  3201. var detInv = 1 / det;
  3202. te[ 0 ] = t11 * detInv;
  3203. te[ 1 ] = ( n24 * n33 * n41 - n23 * n34 * n41 - n24 * n31 * n43 + n21 * n34 * n43 + n23 * n31 * n44 - n21 * n33 * n44 ) * detInv;
  3204. te[ 2 ] = ( n22 * n34 * n41 - n24 * n32 * n41 + n24 * n31 * n42 - n21 * n34 * n42 - n22 * n31 * n44 + n21 * n32 * n44 ) * detInv;
  3205. te[ 3 ] = ( n23 * n32 * n41 - n22 * n33 * n41 - n23 * n31 * n42 + n21 * n33 * n42 + n22 * n31 * n43 - n21 * n32 * n43 ) * detInv;
  3206. te[ 4 ] = t12 * detInv;
  3207. te[ 5 ] = ( n13 * n34 * n41 - n14 * n33 * n41 + n14 * n31 * n43 - n11 * n34 * n43 - n13 * n31 * n44 + n11 * n33 * n44 ) * detInv;
  3208. te[ 6 ] = ( n14 * n32 * n41 - n12 * n34 * n41 - n14 * n31 * n42 + n11 * n34 * n42 + n12 * n31 * n44 - n11 * n32 * n44 ) * detInv;
  3209. te[ 7 ] = ( n12 * n33 * n41 - n13 * n32 * n41 + n13 * n31 * n42 - n11 * n33 * n42 - n12 * n31 * n43 + n11 * n32 * n43 ) * detInv;
  3210. te[ 8 ] = t13 * detInv;
  3211. te[ 9 ] = ( n14 * n23 * n41 - n13 * n24 * n41 - n14 * n21 * n43 + n11 * n24 * n43 + n13 * n21 * n44 - n11 * n23 * n44 ) * detInv;
  3212. te[ 10 ] = ( n12 * n24 * n41 - n14 * n22 * n41 + n14 * n21 * n42 - n11 * n24 * n42 - n12 * n21 * n44 + n11 * n22 * n44 ) * detInv;
  3213. te[ 11 ] = ( n13 * n22 * n41 - n12 * n23 * n41 - n13 * n21 * n42 + n11 * n23 * n42 + n12 * n21 * n43 - n11 * n22 * n43 ) * detInv;
  3214. te[ 12 ] = t14 * detInv;
  3215. te[ 13 ] = ( n13 * n24 * n31 - n14 * n23 * n31 + n14 * n21 * n33 - n11 * n24 * n33 - n13 * n21 * n34 + n11 * n23 * n34 ) * detInv;
  3216. te[ 14 ] = ( n14 * n22 * n31 - n12 * n24 * n31 - n14 * n21 * n32 + n11 * n24 * n32 + n12 * n21 * n34 - n11 * n22 * n34 ) * detInv;
  3217. te[ 15 ] = ( n12 * n23 * n31 - n13 * n22 * n31 + n13 * n21 * n32 - n11 * n23 * n32 - n12 * n21 * n33 + n11 * n22 * n33 ) * detInv;
  3218. return this;
  3219. },
  3220. scale: function ( v ) {
  3221. var te = this.elements;
  3222. var x = v.x, y = v.y, z = v.z;
  3223. te[ 0 ] *= x; te[ 4 ] *= y; te[ 8 ] *= z;
  3224. te[ 1 ] *= x; te[ 5 ] *= y; te[ 9 ] *= z;
  3225. te[ 2 ] *= x; te[ 6 ] *= y; te[ 10 ] *= z;
  3226. te[ 3 ] *= x; te[ 7 ] *= y; te[ 11 ] *= z;
  3227. return this;
  3228. },
  3229. getMaxScaleOnAxis: function () {
  3230. var te = this.elements;
  3231. var scaleXSq = te[ 0 ] * te[ 0 ] + te[ 1 ] * te[ 1 ] + te[ 2 ] * te[ 2 ];
  3232. var scaleYSq = te[ 4 ] * te[ 4 ] + te[ 5 ] * te[ 5 ] + te[ 6 ] * te[ 6 ];
  3233. var scaleZSq = te[ 8 ] * te[ 8 ] + te[ 9 ] * te[ 9 ] + te[ 10 ] * te[ 10 ];
  3234. return Math.sqrt( Math.max( scaleXSq, scaleYSq, scaleZSq ) );
  3235. },
  3236. makeTranslation: function ( x, y, z ) {
  3237. this.set(
  3238. 1, 0, 0, x,
  3239. 0, 1, 0, y,
  3240. 0, 0, 1, z,
  3241. 0, 0, 0, 1
  3242. );
  3243. return this;
  3244. },
  3245. makeRotationX: function ( theta ) {
  3246. var c = Math.cos( theta ), s = Math.sin( theta );
  3247. this.set(
  3248. 1, 0, 0, 0,
  3249. 0, c, - s, 0,
  3250. 0, s, c, 0,
  3251. 0, 0, 0, 1
  3252. );
  3253. return this;
  3254. },
  3255. makeRotationY: function ( theta ) {
  3256. var c = Math.cos( theta ), s = Math.sin( theta );
  3257. this.set(
  3258. c, 0, s, 0,
  3259. 0, 1, 0, 0,
  3260. - s, 0, c, 0,
  3261. 0, 0, 0, 1
  3262. );
  3263. return this;
  3264. },
  3265. makeRotationZ: function ( theta ) {
  3266. var c = Math.cos( theta ), s = Math.sin( theta );
  3267. this.set(
  3268. c, - s, 0, 0,
  3269. s, c, 0, 0,
  3270. 0, 0, 1, 0,
  3271. 0, 0, 0, 1
  3272. );
  3273. return this;
  3274. },
  3275. makeRotationAxis: function ( axis, angle ) {
  3276. // Based on http://www.gamedev.net/reference/articles/article1199.asp
  3277. var c = Math.cos( angle );
  3278. var s = Math.sin( angle );
  3279. var t = 1 - c;
  3280. var x = axis.x, y = axis.y, z = axis.z;
  3281. var tx = t * x, ty = t * y;
  3282. this.set(
  3283. tx * x + c, tx * y - s * z, tx * z + s * y, 0,
  3284. tx * y + s * z, ty * y + c, ty * z - s * x, 0,
  3285. tx * z - s * y, ty * z + s * x, t * z * z + c, 0,
  3286. 0, 0, 0, 1
  3287. );
  3288. return this;
  3289. },
  3290. makeScale: function ( x, y, z ) {
  3291. this.set(
  3292. x, 0, 0, 0,
  3293. 0, y, 0, 0,
  3294. 0, 0, z, 0,
  3295. 0, 0, 0, 1
  3296. );
  3297. return this;
  3298. },
  3299. compose: function ( position, quaternion, scale ) {
  3300. this.makeRotationFromQuaternion( quaternion );
  3301. this.scale( scale );
  3302. this.setPosition( position );
  3303. return this;
  3304. },
  3305. decompose: function () {
  3306. var vector, matrix;
  3307. return function decompose( position, quaternion, scale ) {
  3308. if ( vector === undefined ) {
  3309. vector = new THREE.Vector3();
  3310. matrix = new THREE.Matrix4();
  3311. }
  3312. var te = this.elements;
  3313. var sx = vector.set( te[ 0 ], te[ 1 ], te[ 2 ] ).length();
  3314. var sy = vector.set( te[ 4 ], te[ 5 ], te[ 6 ] ).length();
  3315. var sz = vector.set( te[ 8 ], te[ 9 ], te[ 10 ] ).length();
  3316. // if determine is negative, we need to invert one scale
  3317. var det = this.determinant();
  3318. if ( det < 0 ) {
  3319. sx = - sx;
  3320. }
  3321. position.x = te[ 12 ];
  3322. position.y = te[ 13 ];
  3323. position.z = te[ 14 ];
  3324. // scale the rotation part
  3325. matrix.elements.set( this.elements ); // at this point matrix is incomplete so we can't use .copy()
  3326. var invSX = 1 / sx;
  3327. var invSY = 1 / sy;
  3328. var invSZ = 1 / sz;
  3329. matrix.elements[ 0 ] *= invSX;
  3330. matrix.elements[ 1 ] *= invSX;
  3331. matrix.elements[ 2 ] *= invSX;
  3332. matrix.elements[ 4 ] *= invSY;
  3333. matrix.elements[ 5 ] *= invSY;
  3334. matrix.elements[ 6 ] *= invSY;
  3335. matrix.elements[ 8 ] *= invSZ;
  3336. matrix.elements[ 9 ] *= invSZ;
  3337. matrix.elements[ 10 ] *= invSZ;
  3338. quaternion.setFromRotationMatrix( matrix );
  3339. scale.x = sx;
  3340. scale.y = sy;
  3341. scale.z = sz;
  3342. return this;
  3343. };
  3344. }(),
  3345. makeFrustum: function ( left, right, bottom, top, near, far ) {
  3346. var te = this.elements;
  3347. var x = 2 * near / ( right - left );
  3348. var y = 2 * near / ( top - bottom );
  3349. var a = ( right + left ) / ( right - left );
  3350. var b = ( top + bottom ) / ( top - bottom );
  3351. var c = - ( far + near ) / ( far - near );
  3352. var d = - 2 * far * near / ( far - near );
  3353. te[ 0 ] = x; te[ 4 ] = 0; te[ 8 ] = a; te[ 12 ] = 0;
  3354. te[ 1 ] = 0; te[ 5 ] = y; te[ 9 ] = b; te[ 13 ] = 0;
  3355. te[ 2 ] = 0; te[ 6 ] = 0; te[ 10 ] = c; te[ 14 ] = d;
  3356. te[ 3 ] = 0; te[ 7 ] = 0; te[ 11 ] = - 1; te[ 15 ] = 0;
  3357. return this;
  3358. },
  3359. makePerspective: function ( fov, aspect, near, far ) {
  3360. var ymax = near * Math.tan( THREE.Math.DEG2RAD * fov * 0.5 );
  3361. var ymin = - ymax;
  3362. var xmin = ymin * aspect;
  3363. var xmax = ymax * aspect;
  3364. return this.makeFrustum( xmin, xmax, ymin, ymax, near, far );
  3365. },
  3366. makeOrthographic: function ( left, right, top, bottom, near, far ) {
  3367. var te = this.elements;
  3368. var w = 1.0 / ( right - left );
  3369. var h = 1.0 / ( top - bottom );
  3370. var p = 1.0 / ( far - near );
  3371. var x = ( right + left ) * w;
  3372. var y = ( top + bottom ) * h;
  3373. var z = ( far + near ) * p;
  3374. te[ 0 ] = 2 * w; te[ 4 ] = 0; te[ 8 ] = 0; te[ 12 ] = - x;
  3375. te[ 1 ] = 0; te[ 5 ] = 2 * h; te[ 9 ] = 0; te[ 13 ] = - y;
  3376. te[ 2 ] = 0; te[ 6 ] = 0; te[ 10 ] = - 2 * p; te[ 14 ] = - z;
  3377. te[ 3 ] = 0; te[ 7 ] = 0; te[ 11 ] = 0; te[ 15 ] = 1;
  3378. return this;
  3379. },
  3380. equals: function ( matrix ) {
  3381. var te = this.elements;
  3382. var me = matrix.elements;
  3383. for ( var i = 0; i < 16; i ++ ) {
  3384. if ( te[ i ] !== me[ i ] ) return false;
  3385. }
  3386. return true;
  3387. },
  3388. fromArray: function ( array ) {
  3389. this.elements.set( array );
  3390. return this;
  3391. },
  3392. toArray: function ( array, offset ) {
  3393. if ( array === undefined ) array = [];
  3394. if ( offset === undefined ) offset = 0;
  3395. var te = this.elements;
  3396. array[ offset ] = te[ 0 ];
  3397. array[ offset + 1 ] = te[ 1 ];
  3398. array[ offset + 2 ] = te[ 2 ];
  3399. array[ offset + 3 ] = te[ 3 ];
  3400. array[ offset + 4 ] = te[ 4 ];
  3401. array[ offset + 5 ] = te[ 5 ];
  3402. array[ offset + 6 ] = te[ 6 ];
  3403. array[ offset + 7 ] = te[ 7 ];
  3404. array[ offset + 8 ] = te[ 8 ];
  3405. array[ offset + 9 ] = te[ 9 ];
  3406. array[ offset + 10 ] = te[ 10 ];
  3407. array[ offset + 11 ] = te[ 11 ];
  3408. array[ offset + 12 ] = te[ 12 ];
  3409. array[ offset + 13 ] = te[ 13 ];
  3410. array[ offset + 14 ] = te[ 14 ];
  3411. array[ offset + 15 ] = te[ 15 ];
  3412. return array;
  3413. }
  3414. };
  3415. // File:src/math/Ray.js
  3416. /**
  3417. * @author bhouston / http://clara.io
  3418. */
  3419. THREE.Ray = function ( origin, direction ) {
  3420. this.origin = ( origin !== undefined ) ? origin : new THREE.Vector3();
  3421. this.direction = ( direction !== undefined ) ? direction : new THREE.Vector3();
  3422. };
  3423. THREE.Ray.prototype = {
  3424. constructor: THREE.Ray,
  3425. set: function ( origin, direction ) {
  3426. this.origin.copy( origin );
  3427. this.direction.copy( direction );
  3428. return this;
  3429. },
  3430. clone: function () {
  3431. return new this.constructor().copy( this );
  3432. },
  3433. copy: function ( ray ) {
  3434. this.origin.copy( ray.origin );
  3435. this.direction.copy( ray.direction );
  3436. return this;
  3437. },
  3438. at: function ( t, optionalTarget ) {
  3439. var result = optionalTarget || new THREE.Vector3();
  3440. return result.copy( this.direction ).multiplyScalar( t ).add( this.origin );
  3441. },
  3442. lookAt: function ( v ) {
  3443. this.direction.copy( v ).sub( this.origin ).normalize();
  3444. return this;
  3445. },
  3446. recast: function () {
  3447. var v1 = new THREE.Vector3();
  3448. return function recast( t ) {
  3449. this.origin.copy( this.at( t, v1 ) );
  3450. return this;
  3451. };
  3452. }(),
  3453. closestPointToPoint: function ( point, optionalTarget ) {
  3454. var result = optionalTarget || new THREE.Vector3();
  3455. result.subVectors( point, this.origin );
  3456. var directionDistance = result.dot( this.direction );
  3457. if ( directionDistance < 0 ) {
  3458. return result.copy( this.origin );
  3459. }
  3460. return result.copy( this.direction ).multiplyScalar( directionDistance ).add( this.origin );
  3461. },
  3462. distanceToPoint: function ( point ) {
  3463. return Math.sqrt( this.distanceSqToPoint( point ) );
  3464. },
  3465. distanceSqToPoint: function () {
  3466. var v1 = new THREE.Vector3();
  3467. return function distanceSqToPoint( point ) {
  3468. var directionDistance = v1.subVectors( point, this.origin ).dot( this.direction );
  3469. // point behind the ray
  3470. if ( directionDistance < 0 ) {
  3471. return this.origin.distanceToSquared( point );
  3472. }
  3473. v1.copy( this.direction ).multiplyScalar( directionDistance ).add( this.origin );
  3474. return v1.distanceToSquared( point );
  3475. };
  3476. }(),
  3477. distanceSqToSegment: function () {
  3478. var segCenter = new THREE.Vector3();
  3479. var segDir = new THREE.Vector3();
  3480. var diff = new THREE.Vector3();
  3481. return function distanceSqToSegment( v0, v1, optionalPointOnRay, optionalPointOnSegment ) {
  3482. // from http://www.geometrictools.com/GTEngine/Include/Mathematics/GteDistRaySegment.h
  3483. // It returns the min distance between the ray and the segment
  3484. // defined by v0 and v1
  3485. // It can also set two optional targets :
  3486. // - The closest point on the ray
  3487. // - The closest point on the segment
  3488. segCenter.copy( v0 ).add( v1 ).multiplyScalar( 0.5 );
  3489. segDir.copy( v1 ).sub( v0 ).normalize();
  3490. diff.copy( this.origin ).sub( segCenter );
  3491. var segExtent = v0.distanceTo( v1 ) * 0.5;
  3492. var a01 = - this.direction.dot( segDir );
  3493. var b0 = diff.dot( this.direction );
  3494. var b1 = - diff.dot( segDir );
  3495. var c = diff.lengthSq();
  3496. var det = Math.abs( 1 - a01 * a01 );
  3497. var s0, s1, sqrDist, extDet;
  3498. if ( det > 0 ) {
  3499. // The ray and segment are not parallel.
  3500. s0 = a01 * b1 - b0;
  3501. s1 = a01 * b0 - b1;
  3502. extDet = segExtent * det;
  3503. if ( s0 >= 0 ) {
  3504. if ( s1 >= - extDet ) {
  3505. if ( s1 <= extDet ) {
  3506. // region 0
  3507. // Minimum at interior points of ray and segment.
  3508. var invDet = 1 / det;
  3509. s0 *= invDet;
  3510. s1 *= invDet;
  3511. sqrDist = s0 * ( s0 + a01 * s1 + 2 * b0 ) + s1 * ( a01 * s0 + s1 + 2 * b1 ) + c;
  3512. } else {
  3513. // region 1
  3514. s1 = segExtent;
  3515. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  3516. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3517. }
  3518. } else {
  3519. // region 5
  3520. s1 = - segExtent;
  3521. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  3522. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3523. }
  3524. } else {
  3525. if ( s1 <= - extDet ) {
  3526. // region 4
  3527. s0 = Math.max( 0, - ( - a01 * segExtent + b0 ) );
  3528. s1 = ( s0 > 0 ) ? - segExtent : Math.min( Math.max( - segExtent, - b1 ), segExtent );
  3529. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3530. } else if ( s1 <= extDet ) {
  3531. // region 3
  3532. s0 = 0;
  3533. s1 = Math.min( Math.max( - segExtent, - b1 ), segExtent );
  3534. sqrDist = s1 * ( s1 + 2 * b1 ) + c;
  3535. } else {
  3536. // region 2
  3537. s0 = Math.max( 0, - ( a01 * segExtent + b0 ) );
  3538. s1 = ( s0 > 0 ) ? segExtent : Math.min( Math.max( - segExtent, - b1 ), segExtent );
  3539. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3540. }
  3541. }
  3542. } else {
  3543. // Ray and segment are parallel.
  3544. s1 = ( a01 > 0 ) ? - segExtent : segExtent;
  3545. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  3546. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3547. }
  3548. if ( optionalPointOnRay ) {
  3549. optionalPointOnRay.copy( this.direction ).multiplyScalar( s0 ).add( this.origin );
  3550. }
  3551. if ( optionalPointOnSegment ) {
  3552. optionalPointOnSegment.copy( segDir ).multiplyScalar( s1 ).add( segCenter );
  3553. }
  3554. return sqrDist;
  3555. };
  3556. }(),
  3557. intersectSphere: function () {
  3558. var v1 = new THREE.Vector3();
  3559. return function intersectSphere( sphere, optionalTarget ) {
  3560. v1.subVectors( sphere.center, this.origin );
  3561. var tca = v1.dot( this.direction );
  3562. var d2 = v1.dot( v1 ) - tca * tca;
  3563. var radius2 = sphere.radius * sphere.radius;
  3564. if ( d2 > radius2 ) return null;
  3565. var thc = Math.sqrt( radius2 - d2 );
  3566. // t0 = first intersect point - entrance on front of sphere
  3567. var t0 = tca - thc;
  3568. // t1 = second intersect point - exit point on back of sphere
  3569. var t1 = tca + thc;
  3570. // test to see if both t0 and t1 are behind the ray - if so, return null
  3571. if ( t0 < 0 && t1 < 0 ) return null;
  3572. // test to see if t0 is behind the ray:
  3573. // if it is, the ray is inside the sphere, so return the second exit point scaled by t1,
  3574. // in order to always return an intersect point that is in front of the ray.
  3575. if ( t0 < 0 ) return this.at( t1, optionalTarget );
  3576. // else t0 is in front of the ray, so return the first collision point scaled by t0
  3577. return this.at( t0, optionalTarget );
  3578. };
  3579. }(),
  3580. intersectsSphere: function ( sphere ) {
  3581. return this.distanceToPoint( sphere.center ) <= sphere.radius;
  3582. },
  3583. distanceToPlane: function ( plane ) {
  3584. var denominator = plane.normal.dot( this.direction );
  3585. if ( denominator === 0 ) {
  3586. // line is coplanar, return origin
  3587. if ( plane.distanceToPoint( this.origin ) === 0 ) {
  3588. return 0;
  3589. }
  3590. // Null is preferable to undefined since undefined means.... it is undefined
  3591. return null;
  3592. }
  3593. var t = - ( this.origin.dot( plane.normal ) + plane.constant ) / denominator;
  3594. // Return if the ray never intersects the plane
  3595. return t >= 0 ? t : null;
  3596. },
  3597. intersectPlane: function ( plane, optionalTarget ) {
  3598. var t = this.distanceToPlane( plane );
  3599. if ( t === null ) {
  3600. return null;
  3601. }
  3602. return this.at( t, optionalTarget );
  3603. },
  3604. intersectsPlane: function ( plane ) {
  3605. // check if the ray lies on the plane first
  3606. var distToPoint = plane.distanceToPoint( this.origin );
  3607. if ( distToPoint === 0 ) {
  3608. return true;
  3609. }
  3610. var denominator = plane.normal.dot( this.direction );
  3611. if ( denominator * distToPoint < 0 ) {
  3612. return true;
  3613. }
  3614. // ray origin is behind the plane (and is pointing behind it)
  3615. return false;
  3616. },
  3617. intersectBox: function ( box, optionalTarget ) {
  3618. var tmin, tmax, tymin, tymax, tzmin, tzmax;
  3619. var invdirx = 1 / this.direction.x,
  3620. invdiry = 1 / this.direction.y,
  3621. invdirz = 1 / this.direction.z;
  3622. var origin = this.origin;
  3623. if ( invdirx >= 0 ) {
  3624. tmin = ( box.min.x - origin.x ) * invdirx;
  3625. tmax = ( box.max.x - origin.x ) * invdirx;
  3626. } else {
  3627. tmin = ( box.max.x - origin.x ) * invdirx;
  3628. tmax = ( box.min.x - origin.x ) * invdirx;
  3629. }
  3630. if ( invdiry >= 0 ) {
  3631. tymin = ( box.min.y - origin.y ) * invdiry;
  3632. tymax = ( box.max.y - origin.y ) * invdiry;
  3633. } else {
  3634. tymin = ( box.max.y - origin.y ) * invdiry;
  3635. tymax = ( box.min.y - origin.y ) * invdiry;
  3636. }
  3637. if ( ( tmin > tymax ) || ( tymin > tmax ) ) return null;
  3638. // These lines also handle the case where tmin or tmax is NaN
  3639. // (result of 0 * Infinity). x !== x returns true if x is NaN
  3640. if ( tymin > tmin || tmin !== tmin ) tmin = tymin;
  3641. if ( tymax < tmax || tmax !== tmax ) tmax = tymax;
  3642. if ( invdirz >= 0 ) {
  3643. tzmin = ( box.min.z - origin.z ) * invdirz;
  3644. tzmax = ( box.max.z - origin.z ) * invdirz;
  3645. } else {
  3646. tzmin = ( box.max.z - origin.z ) * invdirz;
  3647. tzmax = ( box.min.z - origin.z ) * invdirz;
  3648. }
  3649. if ( ( tmin > tzmax ) || ( tzmin > tmax ) ) return null;
  3650. if ( tzmin > tmin || tmin !== tmin ) tmin = tzmin;
  3651. if ( tzmax < tmax || tmax !== tmax ) tmax = tzmax;
  3652. //return point closest to the ray (positive side)
  3653. if ( tmax < 0 ) return null;
  3654. return this.at( tmin >= 0 ? tmin : tmax, optionalTarget );
  3655. },
  3656. intersectsBox: ( function () {
  3657. var v = new THREE.Vector3();
  3658. return function intersectsBox( box ) {
  3659. return this.intersectBox( box, v ) !== null;
  3660. };
  3661. } )(),
  3662. intersectTriangle: function () {
  3663. // Compute the offset origin, edges, and normal.
  3664. var diff = new THREE.Vector3();
  3665. var edge1 = new THREE.Vector3();
  3666. var edge2 = new THREE.Vector3();
  3667. var normal = new THREE.Vector3();
  3668. return function intersectTriangle( a, b, c, backfaceCulling, optionalTarget ) {
  3669. // from http://www.geometrictools.com/GTEngine/Include/Mathematics/GteIntrRay3Triangle3.h
  3670. edge1.subVectors( b, a );
  3671. edge2.subVectors( c, a );
  3672. normal.crossVectors( edge1, edge2 );
  3673. // Solve Q + t*D = b1*E1 + b2*E2 (Q = kDiff, D = ray direction,
  3674. // E1 = kEdge1, E2 = kEdge2, N = Cross(E1,E2)) by
  3675. // |Dot(D,N)|*b1 = sign(Dot(D,N))*Dot(D,Cross(Q,E2))
  3676. // |Dot(D,N)|*b2 = sign(Dot(D,N))*Dot(D,Cross(E1,Q))
  3677. // |Dot(D,N)|*t = -sign(Dot(D,N))*Dot(Q,N)
  3678. var DdN = this.direction.dot( normal );
  3679. var sign;
  3680. if ( DdN > 0 ) {
  3681. if ( backfaceCulling ) return null;
  3682. sign = 1;
  3683. } else if ( DdN < 0 ) {
  3684. sign = - 1;
  3685. DdN = - DdN;
  3686. } else {
  3687. return null;
  3688. }
  3689. diff.subVectors( this.origin, a );
  3690. var DdQxE2 = sign * this.direction.dot( edge2.crossVectors( diff, edge2 ) );
  3691. // b1 < 0, no intersection
  3692. if ( DdQxE2 < 0 ) {
  3693. return null;
  3694. }
  3695. var DdE1xQ = sign * this.direction.dot( edge1.cross( diff ) );
  3696. // b2 < 0, no intersection
  3697. if ( DdE1xQ < 0 ) {
  3698. return null;
  3699. }
  3700. // b1+b2 > 1, no intersection
  3701. if ( DdQxE2 + DdE1xQ > DdN ) {
  3702. return null;
  3703. }
  3704. // Line intersects triangle, check if ray does.
  3705. var QdN = - sign * diff.dot( normal );
  3706. // t < 0, no intersection
  3707. if ( QdN < 0 ) {
  3708. return null;
  3709. }
  3710. // Ray intersects triangle.
  3711. return this.at( QdN / DdN, optionalTarget );
  3712. };
  3713. }(),
  3714. applyMatrix4: function ( matrix4 ) {
  3715. this.direction.add( this.origin ).applyMatrix4( matrix4 );
  3716. this.origin.applyMatrix4( matrix4 );
  3717. this.direction.sub( this.origin );
  3718. this.direction.normalize();
  3719. return this;
  3720. },
  3721. equals: function ( ray ) {
  3722. return ray.origin.equals( this.origin ) && ray.direction.equals( this.direction );
  3723. }
  3724. };
  3725. // File:src/math/Sphere.js
  3726. /**
  3727. * @author bhouston / http://clara.io
  3728. * @author mrdoob / http://mrdoob.com/
  3729. */
  3730. THREE.Sphere = function ( center, radius ) {
  3731. this.center = ( center !== undefined ) ? center : new THREE.Vector3();
  3732. this.radius = ( radius !== undefined ) ? radius : 0;
  3733. };
  3734. THREE.Sphere.prototype = {
  3735. constructor: THREE.Sphere,
  3736. set: function ( center, radius ) {
  3737. this.center.copy( center );
  3738. this.radius = radius;
  3739. return this;
  3740. },
  3741. setFromPoints: function () {
  3742. var box = new THREE.Box3();
  3743. return function setFromPoints( points, optionalCenter ) {
  3744. var center = this.center;
  3745. if ( optionalCenter !== undefined ) {
  3746. center.copy( optionalCenter );
  3747. } else {
  3748. box.setFromPoints( points ).center( center );
  3749. }
  3750. var maxRadiusSq = 0;
  3751. for ( var i = 0, il = points.length; i < il; i ++ ) {
  3752. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( points[ i ] ) );
  3753. }
  3754. this.radius = Math.sqrt( maxRadiusSq );
  3755. return this;
  3756. };
  3757. }(),
  3758. clone: function () {
  3759. return new this.constructor().copy( this );
  3760. },
  3761. copy: function ( sphere ) {
  3762. this.center.copy( sphere.center );
  3763. this.radius = sphere.radius;
  3764. return this;
  3765. },
  3766. empty: function () {
  3767. return ( this.radius <= 0 );
  3768. },
  3769. containsPoint: function ( point ) {
  3770. return ( point.distanceToSquared( this.center ) <= ( this.radius * this.radius ) );
  3771. },
  3772. distanceToPoint: function ( point ) {
  3773. return ( point.distanceTo( this.center ) - this.radius );
  3774. },
  3775. intersectsSphere: function ( sphere ) {
  3776. var radiusSum = this.radius + sphere.radius;
  3777. return sphere.center.distanceToSquared( this.center ) <= ( radiusSum * radiusSum );
  3778. },
  3779. intersectsBox: function ( box ) {
  3780. return box.intersectsSphere( this );
  3781. },
  3782. intersectsPlane: function ( plane ) {
  3783. // We use the following equation to compute the signed distance from
  3784. // the center of the sphere to the plane.
  3785. //
  3786. // distance = q * n - d
  3787. //
  3788. // If this distance is greater than the radius of the sphere,
  3789. // then there is no intersection.
  3790. return Math.abs( this.center.dot( plane.normal ) - plane.constant ) <= this.radius;
  3791. },
  3792. clampPoint: function ( point, optionalTarget ) {
  3793. var deltaLengthSq = this.center.distanceToSquared( point );
  3794. var result = optionalTarget || new THREE.Vector3();
  3795. result.copy( point );
  3796. if ( deltaLengthSq > ( this.radius * this.radius ) ) {
  3797. result.sub( this.center ).normalize();
  3798. result.multiplyScalar( this.radius ).add( this.center );
  3799. }
  3800. return result;
  3801. },
  3802. getBoundingBox: function ( optionalTarget ) {
  3803. var box = optionalTarget || new THREE.Box3();
  3804. box.set( this.center, this.center );
  3805. box.expandByScalar( this.radius );
  3806. return box;
  3807. },
  3808. applyMatrix4: function ( matrix ) {
  3809. this.center.applyMatrix4( matrix );
  3810. this.radius = this.radius * matrix.getMaxScaleOnAxis();
  3811. return this;
  3812. },
  3813. translate: function ( offset ) {
  3814. this.center.add( offset );
  3815. return this;
  3816. },
  3817. equals: function ( sphere ) {
  3818. return sphere.center.equals( this.center ) && ( sphere.radius === this.radius );
  3819. }
  3820. };
  3821. // File:src/math/Frustum.js
  3822. /**
  3823. * @author mrdoob / http://mrdoob.com/
  3824. * @author alteredq / http://alteredqualia.com/
  3825. * @author bhouston / http://clara.io
  3826. */
  3827. THREE.Frustum = function ( p0, p1, p2, p3, p4, p5 ) {
  3828. this.planes = [
  3829. ( p0 !== undefined ) ? p0 : new THREE.Plane(),
  3830. ( p1 !== undefined ) ? p1 : new THREE.Plane(),
  3831. ( p2 !== undefined ) ? p2 : new THREE.Plane(),
  3832. ( p3 !== undefined ) ? p3 : new THREE.Plane(),
  3833. ( p4 !== undefined ) ? p4 : new THREE.Plane(),
  3834. ( p5 !== undefined ) ? p5 : new THREE.Plane()
  3835. ];
  3836. };
  3837. THREE.Frustum.prototype = {
  3838. constructor: THREE.Frustum,
  3839. set: function ( p0, p1, p2, p3, p4, p5 ) {
  3840. var planes = this.planes;
  3841. planes[ 0 ].copy( p0 );
  3842. planes[ 1 ].copy( p1 );
  3843. planes[ 2 ].copy( p2 );
  3844. planes[ 3 ].copy( p3 );
  3845. planes[ 4 ].copy( p4 );
  3846. planes[ 5 ].copy( p5 );
  3847. return this;
  3848. },
  3849. clone: function () {
  3850. return new this.constructor().copy( this );
  3851. },
  3852. copy: function ( frustum ) {
  3853. var planes = this.planes;
  3854. for ( var i = 0; i < 6; i ++ ) {
  3855. planes[ i ].copy( frustum.planes[ i ] );
  3856. }
  3857. return this;
  3858. },
  3859. setFromMatrix: function ( m ) {
  3860. var planes = this.planes;
  3861. var me = m.elements;
  3862. var me0 = me[ 0 ], me1 = me[ 1 ], me2 = me[ 2 ], me3 = me[ 3 ];
  3863. var me4 = me[ 4 ], me5 = me[ 5 ], me6 = me[ 6 ], me7 = me[ 7 ];
  3864. var me8 = me[ 8 ], me9 = me[ 9 ], me10 = me[ 10 ], me11 = me[ 11 ];
  3865. var me12 = me[ 12 ], me13 = me[ 13 ], me14 = me[ 14 ], me15 = me[ 15 ];
  3866. planes[ 0 ].setComponents( me3 - me0, me7 - me4, me11 - me8, me15 - me12 ).normalize();
  3867. planes[ 1 ].setComponents( me3 + me0, me7 + me4, me11 + me8, me15 + me12 ).normalize();
  3868. planes[ 2 ].setComponents( me3 + me1, me7 + me5, me11 + me9, me15 + me13 ).normalize();
  3869. planes[ 3 ].setComponents( me3 - me1, me7 - me5, me11 - me9, me15 - me13 ).normalize();
  3870. planes[ 4 ].setComponents( me3 - me2, me7 - me6, me11 - me10, me15 - me14 ).normalize();
  3871. planes[ 5 ].setComponents( me3 + me2, me7 + me6, me11 + me10, me15 + me14 ).normalize();
  3872. return this;
  3873. },
  3874. intersectsObject: function () {
  3875. var sphere = new THREE.Sphere();
  3876. return function intersectsObject( object ) {
  3877. var geometry = object.geometry;
  3878. if ( geometry.boundingSphere === null )
  3879. geometry.computeBoundingSphere();
  3880. sphere.copy( geometry.boundingSphere )
  3881. .applyMatrix4( object.matrixWorld );
  3882. return this.intersectsSphere( sphere );
  3883. };
  3884. }(),
  3885. intersectsSprite: function () {
  3886. var sphere = new THREE.Sphere();
  3887. return function intersectsSprite( sprite ) {
  3888. sphere.center.set( 0, 0, 0 );
  3889. sphere.radius = 0.7071067811865476;
  3890. sphere.applyMatrix4( sprite.matrixWorld );
  3891. return this.intersectsSphere( sphere );
  3892. };
  3893. }(),
  3894. intersectsSphere: function ( sphere ) {
  3895. var planes = this.planes;
  3896. var center = sphere.center;
  3897. var negRadius = - sphere.radius;
  3898. for ( var i = 0; i < 6; i ++ ) {
  3899. var distance = planes[ i ].distanceToPoint( center );
  3900. if ( distance < negRadius ) {
  3901. return false;
  3902. }
  3903. }
  3904. return true;
  3905. },
  3906. intersectsBox: function () {
  3907. var p1 = new THREE.Vector3(),
  3908. p2 = new THREE.Vector3();
  3909. return function intersectsBox( box ) {
  3910. var planes = this.planes;
  3911. for ( var i = 0; i < 6 ; i ++ ) {
  3912. var plane = planes[ i ];
  3913. p1.x = plane.normal.x > 0 ? box.min.x : box.max.x;
  3914. p2.x = plane.normal.x > 0 ? box.max.x : box.min.x;
  3915. p1.y = plane.normal.y > 0 ? box.min.y : box.max.y;
  3916. p2.y = plane.normal.y > 0 ? box.max.y : box.min.y;
  3917. p1.z = plane.normal.z > 0 ? box.min.z : box.max.z;
  3918. p2.z = plane.normal.z > 0 ? box.max.z : box.min.z;
  3919. var d1 = plane.distanceToPoint( p1 );
  3920. var d2 = plane.distanceToPoint( p2 );
  3921. // if both outside plane, no intersection
  3922. if ( d1 < 0 && d2 < 0 ) {
  3923. return false;
  3924. }
  3925. }
  3926. return true;
  3927. };
  3928. }(),
  3929. containsPoint: function ( point ) {
  3930. var planes = this.planes;
  3931. for ( var i = 0; i < 6; i ++ ) {
  3932. if ( planes[ i ].distanceToPoint( point ) < 0 ) {
  3933. return false;
  3934. }
  3935. }
  3936. return true;
  3937. }
  3938. };
  3939. // File:src/math/Plane.js
  3940. /**
  3941. * @author bhouston / http://clara.io
  3942. */
  3943. THREE.Plane = function ( normal, constant ) {
  3944. this.normal = ( normal !== undefined ) ? normal : new THREE.Vector3( 1, 0, 0 );
  3945. this.constant = ( constant !== undefined ) ? constant : 0;
  3946. };
  3947. THREE.Plane.prototype = {
  3948. constructor: THREE.Plane,
  3949. set: function ( normal, constant ) {
  3950. this.normal.copy( normal );
  3951. this.constant = constant;
  3952. return this;
  3953. },
  3954. setComponents: function ( x, y, z, w ) {
  3955. this.normal.set( x, y, z );
  3956. this.constant = w;
  3957. return this;
  3958. },
  3959. setFromNormalAndCoplanarPoint: function ( normal, point ) {
  3960. this.normal.copy( normal );
  3961. this.constant = - point.dot( this.normal ); // must be this.normal, not normal, as this.normal is normalized
  3962. return this;
  3963. },
  3964. setFromCoplanarPoints: function () {
  3965. var v1 = new THREE.Vector3();
  3966. var v2 = new THREE.Vector3();
  3967. return function setFromCoplanarPoints( a, b, c ) {
  3968. var normal = v1.subVectors( c, b ).cross( v2.subVectors( a, b ) ).normalize();
  3969. // Q: should an error be thrown if normal is zero (e.g. degenerate plane)?
  3970. this.setFromNormalAndCoplanarPoint( normal, a );
  3971. return this;
  3972. };
  3973. }(),
  3974. clone: function () {
  3975. return new this.constructor().copy( this );
  3976. },
  3977. copy: function ( plane ) {
  3978. this.normal.copy( plane.normal );
  3979. this.constant = plane.constant;
  3980. return this;
  3981. },
  3982. normalize: function () {
  3983. // Note: will lead to a divide by zero if the plane is invalid.
  3984. var inverseNormalLength = 1.0 / this.normal.length();
  3985. this.normal.multiplyScalar( inverseNormalLength );
  3986. this.constant *= inverseNormalLength;
  3987. return this;
  3988. },
  3989. negate: function () {
  3990. this.constant *= - 1;
  3991. this.normal.negate();
  3992. return this;
  3993. },
  3994. distanceToPoint: function ( point ) {
  3995. return this.normal.dot( point ) + this.constant;
  3996. },
  3997. distanceToSphere: function ( sphere ) {
  3998. return this.distanceToPoint( sphere.center ) - sphere.radius;
  3999. },
  4000. projectPoint: function ( point, optionalTarget ) {
  4001. return this.orthoPoint( point, optionalTarget ).sub( point ).negate();
  4002. },
  4003. orthoPoint: function ( point, optionalTarget ) {
  4004. var perpendicularMagnitude = this.distanceToPoint( point );
  4005. var result = optionalTarget || new THREE.Vector3();
  4006. return result.copy( this.normal ).multiplyScalar( perpendicularMagnitude );
  4007. },
  4008. intersectLine: function () {
  4009. var v1 = new THREE.Vector3();
  4010. return function intersectLine( line, optionalTarget ) {
  4011. var result = optionalTarget || new THREE.Vector3();
  4012. var direction = line.delta( v1 );
  4013. var denominator = this.normal.dot( direction );
  4014. if ( denominator === 0 ) {
  4015. // line is coplanar, return origin
  4016. if ( this.distanceToPoint( line.start ) === 0 ) {
  4017. return result.copy( line.start );
  4018. }
  4019. // Unsure if this is the correct method to handle this case.
  4020. return undefined;
  4021. }
  4022. var t = - ( line.start.dot( this.normal ) + this.constant ) / denominator;
  4023. if ( t < 0 || t > 1 ) {
  4024. return undefined;
  4025. }
  4026. return result.copy( direction ).multiplyScalar( t ).add( line.start );
  4027. };
  4028. }(),
  4029. intersectsLine: function ( line ) {
  4030. // Note: this tests if a line intersects the plane, not whether it (or its end-points) are coplanar with it.
  4031. var startSign = this.distanceToPoint( line.start );
  4032. var endSign = this.distanceToPoint( line.end );
  4033. return ( startSign < 0 && endSign > 0 ) || ( endSign < 0 && startSign > 0 );
  4034. },
  4035. intersectsBox: function ( box ) {
  4036. return box.intersectsPlane( this );
  4037. },
  4038. intersectsSphere: function ( sphere ) {
  4039. return sphere.intersectsPlane( this );
  4040. },
  4041. coplanarPoint: function ( optionalTarget ) {
  4042. var result = optionalTarget || new THREE.Vector3();
  4043. return result.copy( this.normal ).multiplyScalar( - this.constant );
  4044. },
  4045. applyMatrix4: function () {
  4046. var v1 = new THREE.Vector3();
  4047. var m1 = new THREE.Matrix3();
  4048. return function applyMatrix4( matrix, optionalNormalMatrix ) {
  4049. var referencePoint = this.coplanarPoint( v1 ).applyMatrix4( matrix );
  4050. // transform normal based on theory here:
  4051. // http://www.songho.ca/opengl/gl_normaltransform.html
  4052. var normalMatrix = optionalNormalMatrix || m1.getNormalMatrix( matrix );
  4053. var normal = this.normal.applyMatrix3( normalMatrix ).normalize();
  4054. // recalculate constant (like in setFromNormalAndCoplanarPoint)
  4055. this.constant = - referencePoint.dot( normal );
  4056. return this;
  4057. };
  4058. }(),
  4059. translate: function ( offset ) {
  4060. this.constant = this.constant - offset.dot( this.normal );
  4061. return this;
  4062. },
  4063. equals: function ( plane ) {
  4064. return plane.normal.equals( this.normal ) && ( plane.constant === this.constant );
  4065. }
  4066. };
  4067. // File:src/math/Spherical.js
  4068. /**
  4069. * @author bhouston / http://clara.io
  4070. * @author WestLangley / http://github.com/WestLangley
  4071. *
  4072. * Ref: https://en.wikipedia.org/wiki/Spherical_coordinate_system
  4073. *
  4074. * The poles (phi) are at the positive and negative y axis.
  4075. * The equator starts at positive z.
  4076. */
  4077. THREE.Spherical = function ( radius, phi, theta ) {
  4078. this.radius = ( radius !== undefined ) ? radius : 1.0;
  4079. this.phi = ( phi !== undefined ) ? phi : 0; // up / down towards top and bottom pole
  4080. this.theta = ( theta !== undefined ) ? theta : 0; // around the equator of the sphere
  4081. return this;
  4082. };
  4083. THREE.Spherical.prototype = {
  4084. constructor: THREE.Spherical,
  4085. set: function ( radius, phi, theta ) {
  4086. this.radius = radius;
  4087. this.phi = phi;
  4088. this.theta = theta;
  4089. return this;
  4090. },
  4091. clone: function () {
  4092. return new this.constructor().copy( this );
  4093. },
  4094. copy: function ( other ) {
  4095. this.radius.copy( other.radius );
  4096. this.phi.copy( other.phi );
  4097. this.theta.copy( other.theta );
  4098. return this;
  4099. },
  4100. // restrict phi to be betwee EPS and PI-EPS
  4101. makeSafe: function() {
  4102. var EPS = 0.000001;
  4103. this.phi = Math.max( EPS, Math.min( Math.PI - EPS, this.phi ) );
  4104. return this;
  4105. },
  4106. setFromVector3: function( vec3 ) {
  4107. this.radius = vec3.length();
  4108. if ( this.radius === 0 ) {
  4109. this.theta = 0;
  4110. this.phi = 0;
  4111. } else {
  4112. this.theta = Math.atan2( vec3.x, vec3.z ); // equator angle around y-up axis
  4113. this.phi = Math.acos( THREE.Math.clamp( vec3.y / this.radius, - 1, 1 ) ); // polar angle
  4114. }
  4115. return this;
  4116. },
  4117. };
  4118. // File:src/math/Math.js
  4119. /**
  4120. * @author alteredq / http://alteredqualia.com/
  4121. * @author mrdoob / http://mrdoob.com/
  4122. */
  4123. THREE.Math = {
  4124. DEG2RAD: Math.PI / 180,
  4125. RAD2DEG: 180 / Math.PI,
  4126. generateUUID: function () {
  4127. // http://www.broofa.com/Tools/Math.uuid.htm
  4128. var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split( '' );
  4129. var uuid = new Array( 36 );
  4130. var rnd = 0, r;
  4131. return function generateUUID() {
  4132. for ( var i = 0; i < 36; i ++ ) {
  4133. if ( i === 8 || i === 13 || i === 18 || i === 23 ) {
  4134. uuid[ i ] = '-';
  4135. } else if ( i === 14 ) {
  4136. uuid[ i ] = '4';
  4137. } else {
  4138. if ( rnd <= 0x02 ) rnd = 0x2000000 + ( Math.random() * 0x1000000 ) | 0;
  4139. r = rnd & 0xf;
  4140. rnd = rnd >> 4;
  4141. uuid[ i ] = chars[ ( i === 19 ) ? ( r & 0x3 ) | 0x8 : r ];
  4142. }
  4143. }
  4144. return uuid.join( '' );
  4145. };
  4146. }(),
  4147. clamp: function ( value, min, max ) {
  4148. return Math.max( min, Math.min( max, value ) );
  4149. },
  4150. // compute euclidian modulo of m % n
  4151. // https://en.wikipedia.org/wiki/Modulo_operation
  4152. euclideanModulo: function ( n, m ) {
  4153. return ( ( n % m ) + m ) % m;
  4154. },
  4155. // Linear mapping from range <a1, a2> to range <b1, b2>
  4156. mapLinear: function ( x, a1, a2, b1, b2 ) {
  4157. return b1 + ( x - a1 ) * ( b2 - b1 ) / ( a2 - a1 );
  4158. },
  4159. // http://en.wikipedia.org/wiki/Smoothstep
  4160. smoothstep: function ( x, min, max ) {
  4161. if ( x <= min ) return 0;
  4162. if ( x >= max ) return 1;
  4163. x = ( x - min ) / ( max - min );
  4164. return x * x * ( 3 - 2 * x );
  4165. },
  4166. smootherstep: 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 * x * ( x * ( x * 6 - 15 ) + 10 );
  4171. },
  4172. random16: function () {
  4173. console.warn( 'THREE.Math.random16() has been deprecated. Use Math.random() instead.' );
  4174. return Math.random();
  4175. },
  4176. // Random integer from <low, high> interval
  4177. randInt: function ( low, high ) {
  4178. return low + Math.floor( Math.random() * ( high - low + 1 ) );
  4179. },
  4180. // Random float from <low, high> interval
  4181. randFloat: function ( low, high ) {
  4182. return low + Math.random() * ( high - low );
  4183. },
  4184. // Random float from <-range/2, range/2> interval
  4185. randFloatSpread: function ( range ) {
  4186. return range * ( 0.5 - Math.random() );
  4187. },
  4188. degToRad: function ( degrees ) {
  4189. return degrees * THREE.Math.DEG2RAD;
  4190. },
  4191. radToDeg: function ( radians ) {
  4192. return radians * THREE.Math.RAD2DEG;
  4193. },
  4194. isPowerOfTwo: function ( value ) {
  4195. return ( value & ( value - 1 ) ) === 0 && value !== 0;
  4196. },
  4197. nearestPowerOfTwo: function ( value ) {
  4198. return Math.pow( 2, Math.round( Math.log( value ) / Math.LN2 ) );
  4199. },
  4200. nextPowerOfTwo: function ( value ) {
  4201. value --;
  4202. value |= value >> 1;
  4203. value |= value >> 2;
  4204. value |= value >> 4;
  4205. value |= value >> 8;
  4206. value |= value >> 16;
  4207. value ++;
  4208. return value;
  4209. }
  4210. };
  4211. // File:src/math/Spline.js
  4212. /**
  4213. * Spline from Tween.js, slightly optimized (and trashed)
  4214. * http://sole.github.com/tween.js/examples/05_spline.html
  4215. *
  4216. * @author mrdoob / http://mrdoob.com/
  4217. * @author alteredq / http://alteredqualia.com/
  4218. */
  4219. THREE.Spline = function ( points ) {
  4220. this.points = points;
  4221. var c = [], v3 = { x: 0, y: 0, z: 0 },
  4222. point, intPoint, weight, w2, w3,
  4223. pa, pb, pc, pd;
  4224. this.initFromArray = function ( a ) {
  4225. this.points = [];
  4226. for ( var i = 0; i < a.length; i ++ ) {
  4227. this.points[ i ] = { x: a[ i ][ 0 ], y: a[ i ][ 1 ], z: a[ i ][ 2 ] };
  4228. }
  4229. };
  4230. this.getPoint = function ( k ) {
  4231. point = ( this.points.length - 1 ) * k;
  4232. intPoint = Math.floor( point );
  4233. weight = point - intPoint;
  4234. c[ 0 ] = intPoint === 0 ? intPoint : intPoint - 1;
  4235. c[ 1 ] = intPoint;
  4236. c[ 2 ] = intPoint > this.points.length - 2 ? this.points.length - 1 : intPoint + 1;
  4237. c[ 3 ] = intPoint > this.points.length - 3 ? this.points.length - 1 : intPoint + 2;
  4238. pa = this.points[ c[ 0 ] ];
  4239. pb = this.points[ c[ 1 ] ];
  4240. pc = this.points[ c[ 2 ] ];
  4241. pd = this.points[ c[ 3 ] ];
  4242. w2 = weight * weight;
  4243. w3 = weight * w2;
  4244. v3.x = interpolate( pa.x, pb.x, pc.x, pd.x, weight, w2, w3 );
  4245. v3.y = interpolate( pa.y, pb.y, pc.y, pd.y, weight, w2, w3 );
  4246. v3.z = interpolate( pa.z, pb.z, pc.z, pd.z, weight, w2, w3 );
  4247. return v3;
  4248. };
  4249. this.getControlPointsArray = function () {
  4250. var i, p, l = this.points.length,
  4251. coords = [];
  4252. for ( i = 0; i < l; i ++ ) {
  4253. p = this.points[ i ];
  4254. coords[ i ] = [ p.x, p.y, p.z ];
  4255. }
  4256. return coords;
  4257. };
  4258. // approximate length by summing linear segments
  4259. this.getLength = function ( nSubDivisions ) {
  4260. var i, index, nSamples, position,
  4261. point = 0, intPoint = 0, oldIntPoint = 0,
  4262. oldPosition = new THREE.Vector3(),
  4263. tmpVec = new THREE.Vector3(),
  4264. chunkLengths = [],
  4265. totalLength = 0;
  4266. // first point has 0 length
  4267. chunkLengths[ 0 ] = 0;
  4268. if ( ! nSubDivisions ) nSubDivisions = 100;
  4269. nSamples = this.points.length * nSubDivisions;
  4270. oldPosition.copy( this.points[ 0 ] );
  4271. for ( i = 1; i < nSamples; i ++ ) {
  4272. index = i / nSamples;
  4273. position = this.getPoint( index );
  4274. tmpVec.copy( position );
  4275. totalLength += tmpVec.distanceTo( oldPosition );
  4276. oldPosition.copy( position );
  4277. point = ( this.points.length - 1 ) * index;
  4278. intPoint = Math.floor( point );
  4279. if ( intPoint !== oldIntPoint ) {
  4280. chunkLengths[ intPoint ] = totalLength;
  4281. oldIntPoint = intPoint;
  4282. }
  4283. }
  4284. // last point ends with total length
  4285. chunkLengths[ chunkLengths.length ] = totalLength;
  4286. return { chunks: chunkLengths, total: totalLength };
  4287. };
  4288. this.reparametrizeByArcLength = function ( samplingCoef ) {
  4289. var i, j,
  4290. index, indexCurrent, indexNext,
  4291. realDistance,
  4292. sampling, position,
  4293. newpoints = [],
  4294. tmpVec = new THREE.Vector3(),
  4295. sl = this.getLength();
  4296. newpoints.push( tmpVec.copy( this.points[ 0 ] ).clone() );
  4297. for ( i = 1; i < this.points.length; i ++ ) {
  4298. //tmpVec.copy( this.points[ i - 1 ] );
  4299. //linearDistance = tmpVec.distanceTo( this.points[ i ] );
  4300. realDistance = sl.chunks[ i ] - sl.chunks[ i - 1 ];
  4301. sampling = Math.ceil( samplingCoef * realDistance / sl.total );
  4302. indexCurrent = ( i - 1 ) / ( this.points.length - 1 );
  4303. indexNext = i / ( this.points.length - 1 );
  4304. for ( j = 1; j < sampling - 1; j ++ ) {
  4305. index = indexCurrent + j * ( 1 / sampling ) * ( indexNext - indexCurrent );
  4306. position = this.getPoint( index );
  4307. newpoints.push( tmpVec.copy( position ).clone() );
  4308. }
  4309. newpoints.push( tmpVec.copy( this.points[ i ] ).clone() );
  4310. }
  4311. this.points = newpoints;
  4312. };
  4313. // Catmull-Rom
  4314. function interpolate( p0, p1, p2, p3, t, t2, t3 ) {
  4315. var v0 = ( p2 - p0 ) * 0.5,
  4316. v1 = ( p3 - p1 ) * 0.5;
  4317. return ( 2 * ( p1 - p2 ) + v0 + v1 ) * t3 + ( - 3 * ( p1 - p2 ) - 2 * v0 - v1 ) * t2 + v0 * t + p1;
  4318. }
  4319. };
  4320. // File:src/math/Triangle.js
  4321. /**
  4322. * @author bhouston / http://clara.io
  4323. * @author mrdoob / http://mrdoob.com/
  4324. */
  4325. THREE.Triangle = function ( a, b, c ) {
  4326. this.a = ( a !== undefined ) ? a : new THREE.Vector3();
  4327. this.b = ( b !== undefined ) ? b : new THREE.Vector3();
  4328. this.c = ( c !== undefined ) ? c : new THREE.Vector3();
  4329. };
  4330. THREE.Triangle.normal = function () {
  4331. var v0 = new THREE.Vector3();
  4332. return function normal( a, b, c, optionalTarget ) {
  4333. var result = optionalTarget || new THREE.Vector3();
  4334. result.subVectors( c, b );
  4335. v0.subVectors( a, b );
  4336. result.cross( v0 );
  4337. var resultLengthSq = result.lengthSq();
  4338. if ( resultLengthSq > 0 ) {
  4339. return result.multiplyScalar( 1 / Math.sqrt( resultLengthSq ) );
  4340. }
  4341. return result.set( 0, 0, 0 );
  4342. };
  4343. }();
  4344. // static/instance method to calculate barycentric coordinates
  4345. // based on: http://www.blackpawn.com/texts/pointinpoly/default.html
  4346. THREE.Triangle.barycoordFromPoint = function () {
  4347. var v0 = new THREE.Vector3();
  4348. var v1 = new THREE.Vector3();
  4349. var v2 = new THREE.Vector3();
  4350. return function barycoordFromPoint( point, a, b, c, optionalTarget ) {
  4351. v0.subVectors( c, a );
  4352. v1.subVectors( b, a );
  4353. v2.subVectors( point, a );
  4354. var dot00 = v0.dot( v0 );
  4355. var dot01 = v0.dot( v1 );
  4356. var dot02 = v0.dot( v2 );
  4357. var dot11 = v1.dot( v1 );
  4358. var dot12 = v1.dot( v2 );
  4359. var denom = ( dot00 * dot11 - dot01 * dot01 );
  4360. var result = optionalTarget || new THREE.Vector3();
  4361. // collinear or singular triangle
  4362. if ( denom === 0 ) {
  4363. // arbitrary location outside of triangle?
  4364. // not sure if this is the best idea, maybe should be returning undefined
  4365. return result.set( - 2, - 1, - 1 );
  4366. }
  4367. var invDenom = 1 / denom;
  4368. var u = ( dot11 * dot02 - dot01 * dot12 ) * invDenom;
  4369. var v = ( dot00 * dot12 - dot01 * dot02 ) * invDenom;
  4370. // barycentric coordinates must always sum to 1
  4371. return result.set( 1 - u - v, v, u );
  4372. };
  4373. }();
  4374. THREE.Triangle.containsPoint = function () {
  4375. var v1 = new THREE.Vector3();
  4376. return function containsPoint( point, a, b, c ) {
  4377. var result = THREE.Triangle.barycoordFromPoint( point, a, b, c, v1 );
  4378. return ( result.x >= 0 ) && ( result.y >= 0 ) && ( ( result.x + result.y ) <= 1 );
  4379. };
  4380. }();
  4381. THREE.Triangle.prototype = {
  4382. constructor: THREE.Triangle,
  4383. set: function ( a, b, c ) {
  4384. this.a.copy( a );
  4385. this.b.copy( b );
  4386. this.c.copy( c );
  4387. return this;
  4388. },
  4389. setFromPointsAndIndices: function ( points, i0, i1, i2 ) {
  4390. this.a.copy( points[ i0 ] );
  4391. this.b.copy( points[ i1 ] );
  4392. this.c.copy( points[ i2 ] );
  4393. return this;
  4394. },
  4395. clone: function () {
  4396. return new this.constructor().copy( this );
  4397. },
  4398. copy: function ( triangle ) {
  4399. this.a.copy( triangle.a );
  4400. this.b.copy( triangle.b );
  4401. this.c.copy( triangle.c );
  4402. return this;
  4403. },
  4404. area: function () {
  4405. var v0 = new THREE.Vector3();
  4406. var v1 = new THREE.Vector3();
  4407. return function area() {
  4408. v0.subVectors( this.c, this.b );
  4409. v1.subVectors( this.a, this.b );
  4410. return v0.cross( v1 ).length() * 0.5;
  4411. };
  4412. }(),
  4413. midpoint: function ( optionalTarget ) {
  4414. var result = optionalTarget || new THREE.Vector3();
  4415. return result.addVectors( this.a, this.b ).add( this.c ).multiplyScalar( 1 / 3 );
  4416. },
  4417. normal: function ( optionalTarget ) {
  4418. return THREE.Triangle.normal( this.a, this.b, this.c, optionalTarget );
  4419. },
  4420. plane: function ( optionalTarget ) {
  4421. var result = optionalTarget || new THREE.Plane();
  4422. return result.setFromCoplanarPoints( this.a, this.b, this.c );
  4423. },
  4424. barycoordFromPoint: function ( point, optionalTarget ) {
  4425. return THREE.Triangle.barycoordFromPoint( point, this.a, this.b, this.c, optionalTarget );
  4426. },
  4427. containsPoint: function ( point ) {
  4428. return THREE.Triangle.containsPoint( point, this.a, this.b, this.c );
  4429. },
  4430. closestPointToPoint: function () {
  4431. var plane, edgeList, projectedPoint, closestPoint;
  4432. return function closestPointToPoint( point, optionalTarget ) {
  4433. if ( plane === undefined ) {
  4434. plane = new THREE.Plane();
  4435. edgeList = [ new THREE.Line3(), new THREE.Line3(), new THREE.Line3() ];
  4436. projectedPoint = new THREE.Vector3();
  4437. closestPoint = new THREE.Vector3();
  4438. }
  4439. var result = optionalTarget || new THREE.Vector3();
  4440. var minDistance = Infinity;
  4441. // project the point onto the plane of the triangle
  4442. plane.setFromCoplanarPoints( this.a, this.b, this.c );
  4443. plane.projectPoint( point, projectedPoint );
  4444. // check if the projection lies within the triangle
  4445. if( this.containsPoint( projectedPoint ) === true ) {
  4446. // if so, this is the closest point
  4447. result.copy( projectedPoint );
  4448. } else {
  4449. // if not, the point falls outside the triangle. the result is the closest point to the triangle's edges or vertices
  4450. edgeList[ 0 ].set( this.a, this.b );
  4451. edgeList[ 1 ].set( this.b, this.c );
  4452. edgeList[ 2 ].set( this.c, this.a );
  4453. for( var i = 0; i < edgeList.length; i ++ ) {
  4454. edgeList[ i ].closestPointToPoint( projectedPoint, true, closestPoint );
  4455. var distance = projectedPoint.distanceToSquared( closestPoint );
  4456. if( distance < minDistance ) {
  4457. minDistance = distance;
  4458. result.copy( closestPoint );
  4459. }
  4460. }
  4461. }
  4462. return result;
  4463. };
  4464. }(),
  4465. equals: function ( triangle ) {
  4466. return triangle.a.equals( this.a ) && triangle.b.equals( this.b ) && triangle.c.equals( this.c );
  4467. }
  4468. };
  4469. // File:src/math/Interpolant.js
  4470. /**
  4471. * Abstract base class of interpolants over parametric samples.
  4472. *
  4473. * The parameter domain is one dimensional, typically the time or a path
  4474. * along a curve defined by the data.
  4475. *
  4476. * The sample values can have any dimensionality and derived classes may
  4477. * apply special interpretations to the data.
  4478. *
  4479. * This class provides the interval seek in a Template Method, deferring
  4480. * the actual interpolation to derived classes.
  4481. *
  4482. * Time complexity is O(1) for linear access crossing at most two points
  4483. * and O(log N) for random access, where N is the number of positions.
  4484. *
  4485. * References:
  4486. *
  4487. * http://www.oodesign.com/template-method-pattern.html
  4488. *
  4489. * @author tschw
  4490. */
  4491. THREE.Interpolant = function(
  4492. parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  4493. this.parameterPositions = parameterPositions;
  4494. this._cachedIndex = 0;
  4495. this.resultBuffer = resultBuffer !== undefined ?
  4496. resultBuffer : new sampleValues.constructor( sampleSize );
  4497. this.sampleValues = sampleValues;
  4498. this.valueSize = sampleSize;
  4499. };
  4500. THREE.Interpolant.prototype = {
  4501. constructor: THREE.Interpolant,
  4502. evaluate: function( t ) {
  4503. var pp = this.parameterPositions,
  4504. i1 = this._cachedIndex,
  4505. t1 = pp[ i1 ],
  4506. t0 = pp[ i1 - 1 ];
  4507. validate_interval: {
  4508. seek: {
  4509. var right;
  4510. linear_scan: {
  4511. //- See http://jsperf.com/comparison-to-undefined/3
  4512. //- slower code:
  4513. //-
  4514. //- if ( t >= t1 || t1 === undefined ) {
  4515. forward_scan: if ( ! ( t < t1 ) ) {
  4516. for ( var giveUpAt = i1 + 2; ;) {
  4517. if ( t1 === undefined ) {
  4518. if ( t < t0 ) break forward_scan;
  4519. // after end
  4520. i1 = pp.length;
  4521. this._cachedIndex = i1;
  4522. return this.afterEnd_( i1 - 1, t, t0 );
  4523. }
  4524. if ( i1 === giveUpAt ) break; // this loop
  4525. t0 = t1;
  4526. t1 = pp[ ++ i1 ];
  4527. if ( t < t1 ) {
  4528. // we have arrived at the sought interval
  4529. break seek;
  4530. }
  4531. }
  4532. // prepare binary search on the right side of the index
  4533. right = pp.length;
  4534. break linear_scan;
  4535. }
  4536. //- slower code:
  4537. //- if ( t < t0 || t0 === undefined ) {
  4538. if ( ! ( t >= t0 ) ) {
  4539. // looping?
  4540. var t1global = pp[ 1 ];
  4541. if ( t < t1global ) {
  4542. i1 = 2; // + 1, using the scan for the details
  4543. t0 = t1global;
  4544. }
  4545. // linear reverse scan
  4546. for ( var giveUpAt = i1 - 2; ;) {
  4547. if ( t0 === undefined ) {
  4548. // before start
  4549. this._cachedIndex = 0;
  4550. return this.beforeStart_( 0, t, t1 );
  4551. }
  4552. if ( i1 === giveUpAt ) break; // this loop
  4553. t1 = t0;
  4554. t0 = pp[ -- i1 - 1 ];
  4555. if ( t >= t0 ) {
  4556. // we have arrived at the sought interval
  4557. break seek;
  4558. }
  4559. }
  4560. // prepare binary search on the left side of the index
  4561. right = i1;
  4562. i1 = 0;
  4563. break linear_scan;
  4564. }
  4565. // the interval is valid
  4566. break validate_interval;
  4567. } // linear scan
  4568. // binary search
  4569. while ( i1 < right ) {
  4570. var mid = ( i1 + right ) >>> 1;
  4571. if ( t < pp[ mid ] ) {
  4572. right = mid;
  4573. } else {
  4574. i1 = mid + 1;
  4575. }
  4576. }
  4577. t1 = pp[ i1 ];
  4578. t0 = pp[ i1 - 1 ];
  4579. // check boundary cases, again
  4580. if ( t0 === undefined ) {
  4581. this._cachedIndex = 0;
  4582. return this.beforeStart_( 0, t, t1 );
  4583. }
  4584. if ( t1 === undefined ) {
  4585. i1 = pp.length;
  4586. this._cachedIndex = i1;
  4587. return this.afterEnd_( i1 - 1, t0, t );
  4588. }
  4589. } // seek
  4590. this._cachedIndex = i1;
  4591. this.intervalChanged_( i1, t0, t1 );
  4592. } // validate_interval
  4593. return this.interpolate_( i1, t0, t, t1 );
  4594. },
  4595. settings: null, // optional, subclass-specific settings structure
  4596. // Note: The indirection allows central control of many interpolants.
  4597. // --- Protected interface
  4598. DefaultSettings_: {},
  4599. getSettings_: function() {
  4600. return this.settings || this.DefaultSettings_;
  4601. },
  4602. copySampleValue_: function( index ) {
  4603. // copies a sample value to the result buffer
  4604. var result = this.resultBuffer,
  4605. values = this.sampleValues,
  4606. stride = this.valueSize,
  4607. offset = index * stride;
  4608. for ( var i = 0; i !== stride; ++ i ) {
  4609. result[ i ] = values[ offset + i ];
  4610. }
  4611. return result;
  4612. },
  4613. // Template methods for derived classes:
  4614. interpolate_: function( i1, t0, t, t1 ) {
  4615. throw new Error( "call to abstract method" );
  4616. // implementations shall return this.resultBuffer
  4617. },
  4618. intervalChanged_: function( i1, t0, t1 ) {
  4619. // empty
  4620. }
  4621. };
  4622. Object.assign( THREE.Interpolant.prototype, {
  4623. beforeStart_: //( 0, t, t0 ), returns this.resultBuffer
  4624. THREE.Interpolant.prototype.copySampleValue_,
  4625. afterEnd_: //( N-1, tN-1, t ), returns this.resultBuffer
  4626. THREE.Interpolant.prototype.copySampleValue_
  4627. } );
  4628. // File:src/math/interpolants/CubicInterpolant.js
  4629. /**
  4630. * Fast and simple cubic spline interpolant.
  4631. *
  4632. * It was derived from a Hermitian construction setting the first derivative
  4633. * at each sample position to the linear slope between neighboring positions
  4634. * over their parameter interval.
  4635. *
  4636. * @author tschw
  4637. */
  4638. THREE.CubicInterpolant = function(
  4639. parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  4640. THREE.Interpolant.call(
  4641. this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  4642. this._weightPrev = -0;
  4643. this._offsetPrev = -0;
  4644. this._weightNext = -0;
  4645. this._offsetNext = -0;
  4646. };
  4647. THREE.CubicInterpolant.prototype =
  4648. Object.assign( Object.create( THREE.Interpolant.prototype ), {
  4649. constructor: THREE.CubicInterpolant,
  4650. DefaultSettings_: {
  4651. endingStart: THREE.ZeroCurvatureEnding,
  4652. endingEnd: THREE.ZeroCurvatureEnding
  4653. },
  4654. intervalChanged_: function( i1, t0, t1 ) {
  4655. var pp = this.parameterPositions,
  4656. iPrev = i1 - 2,
  4657. iNext = i1 + 1,
  4658. tPrev = pp[ iPrev ],
  4659. tNext = pp[ iNext ];
  4660. if ( tPrev === undefined ) {
  4661. switch ( this.getSettings_().endingStart ) {
  4662. case THREE.ZeroSlopeEnding:
  4663. // f'(t0) = 0
  4664. iPrev = i1;
  4665. tPrev = 2 * t0 - t1;
  4666. break;
  4667. case THREE.WrapAroundEnding:
  4668. // use the other end of the curve
  4669. iPrev = pp.length - 2;
  4670. tPrev = t0 + pp[ iPrev ] - pp[ iPrev + 1 ];
  4671. break;
  4672. default: // ZeroCurvatureEnding
  4673. // f''(t0) = 0 a.k.a. Natural Spline
  4674. iPrev = i1;
  4675. tPrev = t1;
  4676. }
  4677. }
  4678. if ( tNext === undefined ) {
  4679. switch ( this.getSettings_().endingEnd ) {
  4680. case THREE.ZeroSlopeEnding:
  4681. // f'(tN) = 0
  4682. iNext = i1;
  4683. tNext = 2 * t1 - t0;
  4684. break;
  4685. case THREE.WrapAroundEnding:
  4686. // use the other end of the curve
  4687. iNext = 1;
  4688. tNext = t1 + pp[ 1 ] - pp[ 0 ];
  4689. break;
  4690. default: // ZeroCurvatureEnding
  4691. // f''(tN) = 0, a.k.a. Natural Spline
  4692. iNext = i1 - 1;
  4693. tNext = t0;
  4694. }
  4695. }
  4696. var halfDt = ( t1 - t0 ) * 0.5,
  4697. stride = this.valueSize;
  4698. this._weightPrev = halfDt / ( t0 - tPrev );
  4699. this._weightNext = halfDt / ( tNext - t1 );
  4700. this._offsetPrev = iPrev * stride;
  4701. this._offsetNext = iNext * stride;
  4702. },
  4703. interpolate_: function( i1, t0, t, t1 ) {
  4704. var result = this.resultBuffer,
  4705. values = this.sampleValues,
  4706. stride = this.valueSize,
  4707. o1 = i1 * stride, o0 = o1 - stride,
  4708. oP = this._offsetPrev, oN = this._offsetNext,
  4709. wP = this._weightPrev, wN = this._weightNext,
  4710. p = ( t - t0 ) / ( t1 - t0 ),
  4711. pp = p * p,
  4712. ppp = pp * p;
  4713. // evaluate polynomials
  4714. var sP = - wP * ppp + 2 * wP * pp - wP * p;
  4715. var s0 = ( 1 + wP ) * ppp + (-1.5 - 2 * wP ) * pp + ( -0.5 + wP ) * p + 1;
  4716. var s1 = (-1 - wN ) * ppp + ( 1.5 + wN ) * pp + 0.5 * p;
  4717. var sN = wN * ppp - wN * pp;
  4718. // combine data linearly
  4719. for ( var i = 0; i !== stride; ++ i ) {
  4720. result[ i ] =
  4721. sP * values[ oP + i ] +
  4722. s0 * values[ o0 + i ] +
  4723. s1 * values[ o1 + i ] +
  4724. sN * values[ oN + i ];
  4725. }
  4726. return result;
  4727. }
  4728. } );
  4729. // File:src/math/interpolants/DiscreteInterpolant.js
  4730. /**
  4731. *
  4732. * Interpolant that evaluates to the sample value at the position preceeding
  4733. * the parameter.
  4734. *
  4735. * @author tschw
  4736. */
  4737. THREE.DiscreteInterpolant = function(
  4738. parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  4739. THREE.Interpolant.call(
  4740. this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  4741. };
  4742. THREE.DiscreteInterpolant.prototype =
  4743. Object.assign( Object.create( THREE.Interpolant.prototype ), {
  4744. constructor: THREE.DiscreteInterpolant,
  4745. interpolate_: function( i1, t0, t, t1 ) {
  4746. return this.copySampleValue_( i1 - 1 );
  4747. }
  4748. } );
  4749. // File:src/math/interpolants/LinearInterpolant.js
  4750. /**
  4751. * @author tschw
  4752. */
  4753. THREE.LinearInterpolant = function(
  4754. parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  4755. THREE.Interpolant.call(
  4756. this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  4757. };
  4758. THREE.LinearInterpolant.prototype =
  4759. Object.assign( Object.create( THREE.Interpolant.prototype ), {
  4760. constructor: THREE.LinearInterpolant,
  4761. interpolate_: function( i1, t0, t, t1 ) {
  4762. var result = this.resultBuffer,
  4763. values = this.sampleValues,
  4764. stride = this.valueSize,
  4765. offset1 = i1 * stride,
  4766. offset0 = offset1 - stride,
  4767. weight1 = ( t - t0 ) / ( t1 - t0 ),
  4768. weight0 = 1 - weight1;
  4769. for ( var i = 0; i !== stride; ++ i ) {
  4770. result[ i ] =
  4771. values[ offset0 + i ] * weight0 +
  4772. values[ offset1 + i ] * weight1;
  4773. }
  4774. return result;
  4775. }
  4776. } );
  4777. // File:src/math/interpolants/QuaternionLinearInterpolant.js
  4778. /**
  4779. * Spherical linear unit quaternion interpolant.
  4780. *
  4781. * @author tschw
  4782. */
  4783. THREE.QuaternionLinearInterpolant = function(
  4784. parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  4785. THREE.Interpolant.call(
  4786. this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  4787. };
  4788. THREE.QuaternionLinearInterpolant.prototype =
  4789. Object.assign( Object.create( THREE.Interpolant.prototype ), {
  4790. constructor: THREE.QuaternionLinearInterpolant,
  4791. interpolate_: function( i1, t0, t, t1 ) {
  4792. var result = this.resultBuffer,
  4793. values = this.sampleValues,
  4794. stride = this.valueSize,
  4795. offset = i1 * stride,
  4796. alpha = ( t - t0 ) / ( t1 - t0 );
  4797. for ( var end = offset + stride; offset !== end; offset += 4 ) {
  4798. THREE.Quaternion.slerpFlat( result, 0,
  4799. values, offset - stride, values, offset, alpha );
  4800. }
  4801. return result;
  4802. }
  4803. } );
  4804. // File:src/core/Clock.js
  4805. /**
  4806. * @author alteredq / http://alteredqualia.com/
  4807. */
  4808. THREE.Clock = function ( autoStart ) {
  4809. this.autoStart = ( autoStart !== undefined ) ? autoStart : true;
  4810. this.startTime = 0;
  4811. this.oldTime = 0;
  4812. this.elapsedTime = 0;
  4813. this.running = false;
  4814. };
  4815. THREE.Clock.prototype = {
  4816. constructor: THREE.Clock,
  4817. start: function () {
  4818. this.startTime = ( performance || Date ).now();
  4819. this.oldTime = this.startTime;
  4820. this.running = true;
  4821. },
  4822. stop: function () {
  4823. this.getElapsedTime();
  4824. this.running = false;
  4825. },
  4826. getElapsedTime: function () {
  4827. this.getDelta();
  4828. return this.elapsedTime;
  4829. },
  4830. getDelta: function () {
  4831. var diff = 0;
  4832. if ( this.autoStart && ! this.running ) {
  4833. this.start();
  4834. }
  4835. if ( this.running ) {
  4836. var newTime = ( performance || Date ).now();
  4837. diff = ( newTime - this.oldTime ) / 1000;
  4838. this.oldTime = newTime;
  4839. this.elapsedTime += diff;
  4840. }
  4841. return diff;
  4842. }
  4843. };
  4844. // File:src/core/EventDispatcher.js
  4845. /**
  4846. * https://github.com/mrdoob/eventdispatcher.js/
  4847. */
  4848. THREE.EventDispatcher = function () {};
  4849. Object.assign( THREE.EventDispatcher.prototype, {
  4850. addEventListener: function ( type, listener ) {
  4851. if ( this._listeners === undefined ) this._listeners = {};
  4852. var listeners = this._listeners;
  4853. if ( listeners[ type ] === undefined ) {
  4854. listeners[ type ] = [];
  4855. }
  4856. if ( listeners[ type ].indexOf( listener ) === - 1 ) {
  4857. listeners[ type ].push( listener );
  4858. }
  4859. },
  4860. hasEventListener: function ( type, listener ) {
  4861. if ( this._listeners === undefined ) return false;
  4862. var listeners = this._listeners;
  4863. if ( listeners[ type ] !== undefined && listeners[ type ].indexOf( listener ) !== - 1 ) {
  4864. return true;
  4865. }
  4866. return false;
  4867. },
  4868. removeEventListener: function ( type, listener ) {
  4869. if ( this._listeners === undefined ) return;
  4870. var listeners = this._listeners;
  4871. var listenerArray = listeners[ type ];
  4872. if ( listenerArray !== undefined ) {
  4873. var index = listenerArray.indexOf( listener );
  4874. if ( index !== - 1 ) {
  4875. listenerArray.splice( index, 1 );
  4876. }
  4877. }
  4878. },
  4879. dispatchEvent: function ( event ) {
  4880. if ( this._listeners === undefined ) return;
  4881. var listeners = this._listeners;
  4882. var listenerArray = listeners[ event.type ];
  4883. if ( listenerArray !== undefined ) {
  4884. event.target = this;
  4885. var array = [], i = 0;
  4886. var length = listenerArray.length;
  4887. for ( i = 0; i < length; i ++ ) {
  4888. array[ i ] = listenerArray[ i ];
  4889. }
  4890. for ( i = 0; i < length; i ++ ) {
  4891. array[ i ].call( this, event );
  4892. }
  4893. }
  4894. }
  4895. } );
  4896. // File:src/core/Layers.js
  4897. /**
  4898. * @author mrdoob / http://mrdoob.com/
  4899. */
  4900. THREE.Layers = function () {
  4901. this.mask = 1;
  4902. };
  4903. THREE.Layers.prototype = {
  4904. constructor: THREE.Layers,
  4905. set: function ( channel ) {
  4906. this.mask = 1 << channel;
  4907. },
  4908. enable: function ( channel ) {
  4909. this.mask |= 1 << channel;
  4910. },
  4911. toggle: function ( channel ) {
  4912. this.mask ^= 1 << channel;
  4913. },
  4914. disable: function ( channel ) {
  4915. this.mask &= ~ ( 1 << channel );
  4916. },
  4917. test: function ( layers ) {
  4918. return ( this.mask & layers.mask ) !== 0;
  4919. }
  4920. };
  4921. // File:src/core/Raycaster.js
  4922. /**
  4923. * @author mrdoob / http://mrdoob.com/
  4924. * @author bhouston / http://clara.io/
  4925. * @author stephomi / http://stephaneginier.com/
  4926. */
  4927. ( function ( THREE ) {
  4928. THREE.Raycaster = function ( origin, direction, near, far ) {
  4929. this.ray = new THREE.Ray( origin, direction );
  4930. // direction is assumed to be normalized (for accurate distance calculations)
  4931. this.near = near || 0;
  4932. this.far = far || Infinity;
  4933. this.params = {
  4934. Mesh: {},
  4935. Line: {},
  4936. LOD: {},
  4937. Points: { threshold: 1 },
  4938. Sprite: {}
  4939. };
  4940. Object.defineProperties( this.params, {
  4941. PointCloud: {
  4942. get: function () {
  4943. console.warn( 'THREE.Raycaster: params.PointCloud has been renamed to params.Points.' );
  4944. return this.Points;
  4945. }
  4946. }
  4947. } );
  4948. };
  4949. function ascSort( a, b ) {
  4950. return a.distance - b.distance;
  4951. }
  4952. function intersectObject( object, raycaster, intersects, recursive ) {
  4953. if ( object.visible === false ) return;
  4954. object.raycast( raycaster, intersects );
  4955. if ( recursive === true ) {
  4956. var children = object.children;
  4957. for ( var i = 0, l = children.length; i < l; i ++ ) {
  4958. intersectObject( children[ i ], raycaster, intersects, true );
  4959. }
  4960. }
  4961. }
  4962. //
  4963. THREE.Raycaster.prototype = {
  4964. constructor: THREE.Raycaster,
  4965. linePrecision: 1,
  4966. set: function ( origin, direction ) {
  4967. // direction is assumed to be normalized (for accurate distance calculations)
  4968. this.ray.set( origin, direction );
  4969. },
  4970. setFromCamera: function ( coords, camera ) {
  4971. if ( camera instanceof THREE.PerspectiveCamera ) {
  4972. this.ray.origin.setFromMatrixPosition( camera.matrixWorld );
  4973. this.ray.direction.set( coords.x, coords.y, 0.5 ).unproject( camera ).sub( this.ray.origin ).normalize();
  4974. } else if ( camera instanceof THREE.OrthographicCamera ) {
  4975. this.ray.origin.set( coords.x, coords.y, ( camera.near + camera.far ) / ( camera.near - camera.far ) ).unproject( camera ); // set origin in plane of camera
  4976. this.ray.direction.set( 0, 0, - 1 ).transformDirection( camera.matrixWorld );
  4977. } else {
  4978. console.error( 'THREE.Raycaster: Unsupported camera type.' );
  4979. }
  4980. },
  4981. intersectObject: function ( object, recursive ) {
  4982. var intersects = [];
  4983. intersectObject( object, this, intersects, recursive );
  4984. intersects.sort( ascSort );
  4985. return intersects;
  4986. },
  4987. intersectObjects: function ( objects, recursive ) {
  4988. var intersects = [];
  4989. if ( Array.isArray( objects ) === false ) {
  4990. console.warn( 'THREE.Raycaster.intersectObjects: objects is not an Array.' );
  4991. return intersects;
  4992. }
  4993. for ( var i = 0, l = objects.length; i < l; i ++ ) {
  4994. intersectObject( objects[ i ], this, intersects, recursive );
  4995. }
  4996. intersects.sort( ascSort );
  4997. return intersects;
  4998. }
  4999. };
  5000. }( THREE ) );
  5001. // File:src/core/Object3D.js
  5002. /**
  5003. * @author mrdoob / http://mrdoob.com/
  5004. * @author mikael emtinger / http://gomo.se/
  5005. * @author alteredq / http://alteredqualia.com/
  5006. * @author WestLangley / http://github.com/WestLangley
  5007. * @author elephantatwork / www.elephantatwork.ch
  5008. */
  5009. THREE.Object3D = function () {
  5010. Object.defineProperty( this, 'id', { value: THREE.Object3DIdCount ++ } );
  5011. this.uuid = THREE.Math.generateUUID();
  5012. this.name = '';
  5013. this.type = 'Object3D';
  5014. this.parent = null;
  5015. this.children = [];
  5016. this.up = THREE.Object3D.DefaultUp.clone();
  5017. var position = new THREE.Vector3();
  5018. var rotation = new THREE.Euler();
  5019. var quaternion = new THREE.Quaternion();
  5020. var scale = new THREE.Vector3( 1, 1, 1 );
  5021. function onRotationChange() {
  5022. quaternion.setFromEuler( rotation, false );
  5023. }
  5024. function onQuaternionChange() {
  5025. rotation.setFromQuaternion( quaternion, undefined, false );
  5026. }
  5027. rotation.onChange( onRotationChange );
  5028. quaternion.onChange( onQuaternionChange );
  5029. Object.defineProperties( this, {
  5030. position: {
  5031. enumerable: true,
  5032. value: position
  5033. },
  5034. rotation: {
  5035. enumerable: true,
  5036. value: rotation
  5037. },
  5038. quaternion: {
  5039. enumerable: true,
  5040. value: quaternion
  5041. },
  5042. scale: {
  5043. enumerable: true,
  5044. value: scale
  5045. },
  5046. modelViewMatrix: {
  5047. value: new THREE.Matrix4()
  5048. },
  5049. normalMatrix: {
  5050. value: new THREE.Matrix3()
  5051. }
  5052. } );
  5053. this.matrix = new THREE.Matrix4();
  5054. this.matrixWorld = new THREE.Matrix4();
  5055. this.matrixAutoUpdate = THREE.Object3D.DefaultMatrixAutoUpdate;
  5056. this.matrixWorldNeedsUpdate = false;
  5057. this.layers = new THREE.Layers();
  5058. this.visible = true;
  5059. this.castShadow = false;
  5060. this.receiveShadow = false;
  5061. this.frustumCulled = true;
  5062. this.renderOrder = 0;
  5063. this.userData = {};
  5064. };
  5065. THREE.Object3D.DefaultUp = new THREE.Vector3( 0, 1, 0 );
  5066. THREE.Object3D.DefaultMatrixAutoUpdate = true;
  5067. Object.assign( THREE.Object3D.prototype, THREE.EventDispatcher.prototype, {
  5068. applyMatrix: function ( matrix ) {
  5069. this.matrix.multiplyMatrices( matrix, this.matrix );
  5070. this.matrix.decompose( this.position, this.quaternion, this.scale );
  5071. },
  5072. setRotationFromAxisAngle: function ( axis, angle ) {
  5073. // assumes axis is normalized
  5074. this.quaternion.setFromAxisAngle( axis, angle );
  5075. },
  5076. setRotationFromEuler: function ( euler ) {
  5077. this.quaternion.setFromEuler( euler, true );
  5078. },
  5079. setRotationFromMatrix: function ( m ) {
  5080. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  5081. this.quaternion.setFromRotationMatrix( m );
  5082. },
  5083. setRotationFromQuaternion: function ( q ) {
  5084. // assumes q is normalized
  5085. this.quaternion.copy( q );
  5086. },
  5087. rotateOnAxis: function () {
  5088. // rotate object on axis in object space
  5089. // axis is assumed to be normalized
  5090. var q1 = new THREE.Quaternion();
  5091. return function rotateOnAxis( axis, angle ) {
  5092. q1.setFromAxisAngle( axis, angle );
  5093. this.quaternion.multiply( q1 );
  5094. return this;
  5095. };
  5096. }(),
  5097. rotateX: function () {
  5098. var v1 = new THREE.Vector3( 1, 0, 0 );
  5099. return function rotateX( angle ) {
  5100. return this.rotateOnAxis( v1, angle );
  5101. };
  5102. }(),
  5103. rotateY: function () {
  5104. var v1 = new THREE.Vector3( 0, 1, 0 );
  5105. return function rotateY( angle ) {
  5106. return this.rotateOnAxis( v1, angle );
  5107. };
  5108. }(),
  5109. rotateZ: function () {
  5110. var v1 = new THREE.Vector3( 0, 0, 1 );
  5111. return function rotateZ( angle ) {
  5112. return this.rotateOnAxis( v1, angle );
  5113. };
  5114. }(),
  5115. translateOnAxis: function () {
  5116. // translate object by distance along axis in object space
  5117. // axis is assumed to be normalized
  5118. var v1 = new THREE.Vector3();
  5119. return function translateOnAxis( axis, distance ) {
  5120. v1.copy( axis ).applyQuaternion( this.quaternion );
  5121. this.position.add( v1.multiplyScalar( distance ) );
  5122. return this;
  5123. };
  5124. }(),
  5125. translateX: function () {
  5126. var v1 = new THREE.Vector3( 1, 0, 0 );
  5127. return function translateX( distance ) {
  5128. return this.translateOnAxis( v1, distance );
  5129. };
  5130. }(),
  5131. translateY: function () {
  5132. var v1 = new THREE.Vector3( 0, 1, 0 );
  5133. return function translateY( distance ) {
  5134. return this.translateOnAxis( v1, distance );
  5135. };
  5136. }(),
  5137. translateZ: function () {
  5138. var v1 = new THREE.Vector3( 0, 0, 1 );
  5139. return function translateZ( distance ) {
  5140. return this.translateOnAxis( v1, distance );
  5141. };
  5142. }(),
  5143. localToWorld: function ( vector ) {
  5144. return vector.applyMatrix4( this.matrixWorld );
  5145. },
  5146. worldToLocal: function () {
  5147. var m1 = new THREE.Matrix4();
  5148. return function worldToLocal( vector ) {
  5149. return vector.applyMatrix4( m1.getInverse( this.matrixWorld ) );
  5150. };
  5151. }(),
  5152. lookAt: function () {
  5153. // This routine does not support objects with rotated and/or translated parent(s)
  5154. var m1 = new THREE.Matrix4();
  5155. return function lookAt( vector ) {
  5156. m1.lookAt( vector, this.position, this.up );
  5157. this.quaternion.setFromRotationMatrix( m1 );
  5158. };
  5159. }(),
  5160. add: function ( object ) {
  5161. if ( arguments.length > 1 ) {
  5162. for ( var i = 0; i < arguments.length; i ++ ) {
  5163. this.add( arguments[ i ] );
  5164. }
  5165. return this;
  5166. }
  5167. if ( object === this ) {
  5168. console.error( "THREE.Object3D.add: object can't be added as a child of itself.", object );
  5169. return this;
  5170. }
  5171. if ( object instanceof THREE.Object3D ) {
  5172. if ( object.parent !== null ) {
  5173. object.parent.remove( object );
  5174. }
  5175. object.parent = this;
  5176. object.dispatchEvent( { type: 'added' } );
  5177. this.children.push( object );
  5178. } else {
  5179. console.error( "THREE.Object3D.add: object not an instance of THREE.Object3D.", object );
  5180. }
  5181. return this;
  5182. },
  5183. remove: function ( object ) {
  5184. if ( arguments.length > 1 ) {
  5185. for ( var i = 0; i < arguments.length; i ++ ) {
  5186. this.remove( arguments[ i ] );
  5187. }
  5188. }
  5189. var index = this.children.indexOf( object );
  5190. if ( index !== - 1 ) {
  5191. object.parent = null;
  5192. object.dispatchEvent( { type: 'removed' } );
  5193. this.children.splice( index, 1 );
  5194. }
  5195. },
  5196. getObjectById: function ( id ) {
  5197. return this.getObjectByProperty( 'id', id );
  5198. },
  5199. getObjectByName: function ( name ) {
  5200. return this.getObjectByProperty( 'name', name );
  5201. },
  5202. getObjectByProperty: function ( name, value ) {
  5203. if ( this[ name ] === value ) return this;
  5204. for ( var i = 0, l = this.children.length; i < l; i ++ ) {
  5205. var child = this.children[ i ];
  5206. var object = child.getObjectByProperty( name, value );
  5207. if ( object !== undefined ) {
  5208. return object;
  5209. }
  5210. }
  5211. return undefined;
  5212. },
  5213. getWorldPosition: function ( optionalTarget ) {
  5214. var result = optionalTarget || new THREE.Vector3();
  5215. this.updateMatrixWorld( true );
  5216. return result.setFromMatrixPosition( this.matrixWorld );
  5217. },
  5218. getWorldQuaternion: function () {
  5219. var position = new THREE.Vector3();
  5220. var scale = new THREE.Vector3();
  5221. return function getWorldQuaternion( optionalTarget ) {
  5222. var result = optionalTarget || new THREE.Quaternion();
  5223. this.updateMatrixWorld( true );
  5224. this.matrixWorld.decompose( position, result, scale );
  5225. return result;
  5226. };
  5227. }(),
  5228. getWorldRotation: function () {
  5229. var quaternion = new THREE.Quaternion();
  5230. return function getWorldRotation( optionalTarget ) {
  5231. var result = optionalTarget || new THREE.Euler();
  5232. this.getWorldQuaternion( quaternion );
  5233. return result.setFromQuaternion( quaternion, this.rotation.order, false );
  5234. };
  5235. }(),
  5236. getWorldScale: function () {
  5237. var position = new THREE.Vector3();
  5238. var quaternion = new THREE.Quaternion();
  5239. return function getWorldScale( optionalTarget ) {
  5240. var result = optionalTarget || new THREE.Vector3();
  5241. this.updateMatrixWorld( true );
  5242. this.matrixWorld.decompose( position, quaternion, result );
  5243. return result;
  5244. };
  5245. }(),
  5246. getWorldDirection: function () {
  5247. var quaternion = new THREE.Quaternion();
  5248. return function getWorldDirection( optionalTarget ) {
  5249. var result = optionalTarget || new THREE.Vector3();
  5250. this.getWorldQuaternion( quaternion );
  5251. return result.set( 0, 0, 1 ).applyQuaternion( quaternion );
  5252. };
  5253. }(),
  5254. raycast: function () {},
  5255. traverse: function ( callback ) {
  5256. callback( this );
  5257. var children = this.children;
  5258. for ( var i = 0, l = children.length; i < l; i ++ ) {
  5259. children[ i ].traverse( callback );
  5260. }
  5261. },
  5262. traverseVisible: function ( callback ) {
  5263. if ( this.visible === false ) return;
  5264. callback( this );
  5265. var children = this.children;
  5266. for ( var i = 0, l = children.length; i < l; i ++ ) {
  5267. children[ i ].traverseVisible( callback );
  5268. }
  5269. },
  5270. traverseAncestors: function ( callback ) {
  5271. var parent = this.parent;
  5272. if ( parent !== null ) {
  5273. callback( parent );
  5274. parent.traverseAncestors( callback );
  5275. }
  5276. },
  5277. updateMatrix: function () {
  5278. this.matrix.compose( this.position, this.quaternion, this.scale );
  5279. this.matrixWorldNeedsUpdate = true;
  5280. },
  5281. updateMatrixWorld: function ( force ) {
  5282. if ( this.matrixAutoUpdate === true ) this.updateMatrix();
  5283. if ( this.matrixWorldNeedsUpdate === true || force === true ) {
  5284. if ( this.parent === null ) {
  5285. this.matrixWorld.copy( this.matrix );
  5286. } else {
  5287. this.matrixWorld.multiplyMatrices( this.parent.matrixWorld, this.matrix );
  5288. }
  5289. this.matrixWorldNeedsUpdate = false;
  5290. force = true;
  5291. }
  5292. // update children
  5293. for ( var i = 0, l = this.children.length; i < l; i ++ ) {
  5294. this.children[ i ].updateMatrixWorld( force );
  5295. }
  5296. },
  5297. toJSON: function ( meta ) {
  5298. // meta is '' when called from JSON.stringify
  5299. var isRootObject = ( meta === undefined || meta === '' );
  5300. var output = {};
  5301. // meta is a hash used to collect geometries, materials.
  5302. // not providing it implies that this is the root object
  5303. // being serialized.
  5304. if ( isRootObject ) {
  5305. // initialize meta obj
  5306. meta = {
  5307. geometries: {},
  5308. materials: {},
  5309. textures: {},
  5310. images: {}
  5311. };
  5312. output.metadata = {
  5313. version: 4.4,
  5314. type: 'Object',
  5315. generator: 'Object3D.toJSON'
  5316. };
  5317. }
  5318. // standard Object3D serialization
  5319. var object = {};
  5320. object.uuid = this.uuid;
  5321. object.type = this.type;
  5322. if ( this.name !== '' ) object.name = this.name;
  5323. if ( JSON.stringify( this.userData ) !== '{}' ) object.userData = this.userData;
  5324. if ( this.castShadow === true ) object.castShadow = true;
  5325. if ( this.receiveShadow === true ) object.receiveShadow = true;
  5326. if ( this.visible === false ) object.visible = false;
  5327. object.matrix = this.matrix.toArray();
  5328. //
  5329. if ( this.geometry !== undefined ) {
  5330. if ( meta.geometries[ this.geometry.uuid ] === undefined ) {
  5331. meta.geometries[ this.geometry.uuid ] = this.geometry.toJSON( meta );
  5332. }
  5333. object.geometry = this.geometry.uuid;
  5334. }
  5335. if ( this.material !== undefined ) {
  5336. if ( meta.materials[ this.material.uuid ] === undefined ) {
  5337. meta.materials[ this.material.uuid ] = this.material.toJSON( meta );
  5338. }
  5339. object.material = this.material.uuid;
  5340. }
  5341. //
  5342. if ( this.children.length > 0 ) {
  5343. object.children = [];
  5344. for ( var i = 0; i < this.children.length; i ++ ) {
  5345. object.children.push( this.children[ i ].toJSON( meta ).object );
  5346. }
  5347. }
  5348. if ( isRootObject ) {
  5349. var geometries = extractFromCache( meta.geometries );
  5350. var materials = extractFromCache( meta.materials );
  5351. var textures = extractFromCache( meta.textures );
  5352. var images = extractFromCache( meta.images );
  5353. if ( geometries.length > 0 ) output.geometries = geometries;
  5354. if ( materials.length > 0 ) output.materials = materials;
  5355. if ( textures.length > 0 ) output.textures = textures;
  5356. if ( images.length > 0 ) output.images = images;
  5357. }
  5358. output.object = object;
  5359. return output;
  5360. // extract data from the cache hash
  5361. // remove metadata on each item
  5362. // and return as array
  5363. function extractFromCache ( cache ) {
  5364. var values = [];
  5365. for ( var key in cache ) {
  5366. var data = cache[ key ];
  5367. delete data.metadata;
  5368. values.push( data );
  5369. }
  5370. return values;
  5371. }
  5372. },
  5373. clone: function ( recursive ) {
  5374. return new this.constructor().copy( this, recursive );
  5375. },
  5376. copy: function ( source, recursive ) {
  5377. if ( recursive === undefined ) recursive = true;
  5378. this.name = source.name;
  5379. this.up.copy( source.up );
  5380. this.position.copy( source.position );
  5381. this.quaternion.copy( source.quaternion );
  5382. this.scale.copy( source.scale );
  5383. this.matrix.copy( source.matrix );
  5384. this.matrixWorld.copy( source.matrixWorld );
  5385. this.matrixAutoUpdate = source.matrixAutoUpdate;
  5386. this.matrixWorldNeedsUpdate = source.matrixWorldNeedsUpdate;
  5387. this.visible = source.visible;
  5388. this.castShadow = source.castShadow;
  5389. this.receiveShadow = source.receiveShadow;
  5390. this.frustumCulled = source.frustumCulled;
  5391. this.renderOrder = source.renderOrder;
  5392. this.userData = JSON.parse( JSON.stringify( source.userData ) );
  5393. if ( recursive === true ) {
  5394. for ( var i = 0; i < source.children.length; i ++ ) {
  5395. var child = source.children[ i ];
  5396. this.add( child.clone() );
  5397. }
  5398. }
  5399. return this;
  5400. }
  5401. } );
  5402. THREE.Object3DIdCount = 0;
  5403. // File:src/core/Face3.js
  5404. /**
  5405. * @author mrdoob / http://mrdoob.com/
  5406. * @author alteredq / http://alteredqualia.com/
  5407. */
  5408. THREE.Face3 = function ( a, b, c, normal, color, materialIndex ) {
  5409. this.a = a;
  5410. this.b = b;
  5411. this.c = c;
  5412. this.normal = normal instanceof THREE.Vector3 ? normal : new THREE.Vector3();
  5413. this.vertexNormals = Array.isArray( normal ) ? normal : [];
  5414. this.color = color instanceof THREE.Color ? color : new THREE.Color();
  5415. this.vertexColors = Array.isArray( color ) ? color : [];
  5416. this.materialIndex = materialIndex !== undefined ? materialIndex : 0;
  5417. };
  5418. THREE.Face3.prototype = {
  5419. constructor: THREE.Face3,
  5420. clone: function () {
  5421. return new this.constructor().copy( this );
  5422. },
  5423. copy: function ( source ) {
  5424. this.a = source.a;
  5425. this.b = source.b;
  5426. this.c = source.c;
  5427. this.normal.copy( source.normal );
  5428. this.color.copy( source.color );
  5429. this.materialIndex = source.materialIndex;
  5430. for ( var i = 0, il = source.vertexNormals.length; i < il; i ++ ) {
  5431. this.vertexNormals[ i ] = source.vertexNormals[ i ].clone();
  5432. }
  5433. for ( var i = 0, il = source.vertexColors.length; i < il; i ++ ) {
  5434. this.vertexColors[ i ] = source.vertexColors[ i ].clone();
  5435. }
  5436. return this;
  5437. }
  5438. };
  5439. // File:src/core/BufferAttribute.js
  5440. /**
  5441. * @author mrdoob / http://mrdoob.com/
  5442. */
  5443. THREE.BufferAttribute = function ( array, itemSize, normalized ) {
  5444. this.uuid = THREE.Math.generateUUID();
  5445. this.array = array;
  5446. this.itemSize = itemSize;
  5447. this.dynamic = false;
  5448. this.updateRange = { offset: 0, count: - 1 };
  5449. this.version = 0;
  5450. this.normalized = normalized === true;
  5451. };
  5452. THREE.BufferAttribute.prototype = {
  5453. constructor: THREE.BufferAttribute,
  5454. get count() {
  5455. return this.array.length / this.itemSize;
  5456. },
  5457. set needsUpdate( value ) {
  5458. if ( value === true ) this.version ++;
  5459. },
  5460. setDynamic: function ( value ) {
  5461. this.dynamic = value;
  5462. return this;
  5463. },
  5464. copy: function ( source ) {
  5465. this.array = new source.array.constructor( source.array );
  5466. this.itemSize = source.itemSize;
  5467. this.dynamic = source.dynamic;
  5468. return this;
  5469. },
  5470. copyAt: function ( index1, attribute, index2 ) {
  5471. index1 *= this.itemSize;
  5472. index2 *= attribute.itemSize;
  5473. for ( var i = 0, l = this.itemSize; i < l; i ++ ) {
  5474. this.array[ index1 + i ] = attribute.array[ index2 + i ];
  5475. }
  5476. return this;
  5477. },
  5478. copyArray: function ( array ) {
  5479. this.array.set( array );
  5480. return this;
  5481. },
  5482. copyColorsArray: function ( colors ) {
  5483. var array = this.array, offset = 0;
  5484. for ( var i = 0, l = colors.length; i < l; i ++ ) {
  5485. var color = colors[ i ];
  5486. if ( color === undefined ) {
  5487. console.warn( 'THREE.BufferAttribute.copyColorsArray(): color is undefined', i );
  5488. color = new THREE.Color();
  5489. }
  5490. array[ offset ++ ] = color.r;
  5491. array[ offset ++ ] = color.g;
  5492. array[ offset ++ ] = color.b;
  5493. }
  5494. return this;
  5495. },
  5496. copyIndicesArray: function ( indices ) {
  5497. var array = this.array, offset = 0;
  5498. for ( var i = 0, l = indices.length; i < l; i ++ ) {
  5499. var index = indices[ i ];
  5500. array[ offset ++ ] = index.a;
  5501. array[ offset ++ ] = index.b;
  5502. array[ offset ++ ] = index.c;
  5503. }
  5504. return this;
  5505. },
  5506. copyVector2sArray: function ( vectors ) {
  5507. var array = this.array, offset = 0;
  5508. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  5509. var vector = vectors[ i ];
  5510. if ( vector === undefined ) {
  5511. console.warn( 'THREE.BufferAttribute.copyVector2sArray(): vector is undefined', i );
  5512. vector = new THREE.Vector2();
  5513. }
  5514. array[ offset ++ ] = vector.x;
  5515. array[ offset ++ ] = vector.y;
  5516. }
  5517. return this;
  5518. },
  5519. copyVector3sArray: function ( vectors ) {
  5520. var array = this.array, offset = 0;
  5521. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  5522. var vector = vectors[ i ];
  5523. if ( vector === undefined ) {
  5524. console.warn( 'THREE.BufferAttribute.copyVector3sArray(): vector is undefined', i );
  5525. vector = new THREE.Vector3();
  5526. }
  5527. array[ offset ++ ] = vector.x;
  5528. array[ offset ++ ] = vector.y;
  5529. array[ offset ++ ] = vector.z;
  5530. }
  5531. return this;
  5532. },
  5533. copyVector4sArray: function ( vectors ) {
  5534. var array = this.array, offset = 0;
  5535. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  5536. var vector = vectors[ i ];
  5537. if ( vector === undefined ) {
  5538. console.warn( 'THREE.BufferAttribute.copyVector4sArray(): vector is undefined', i );
  5539. vector = new THREE.Vector4();
  5540. }
  5541. array[ offset ++ ] = vector.x;
  5542. array[ offset ++ ] = vector.y;
  5543. array[ offset ++ ] = vector.z;
  5544. array[ offset ++ ] = vector.w;
  5545. }
  5546. return this;
  5547. },
  5548. set: function ( value, offset ) {
  5549. if ( offset === undefined ) offset = 0;
  5550. this.array.set( value, offset );
  5551. return this;
  5552. },
  5553. getX: function ( index ) {
  5554. return this.array[ index * this.itemSize ];
  5555. },
  5556. setX: function ( index, x ) {
  5557. this.array[ index * this.itemSize ] = x;
  5558. return this;
  5559. },
  5560. getY: function ( index ) {
  5561. return this.array[ index * this.itemSize + 1 ];
  5562. },
  5563. setY: function ( index, y ) {
  5564. this.array[ index * this.itemSize + 1 ] = y;
  5565. return this;
  5566. },
  5567. getZ: function ( index ) {
  5568. return this.array[ index * this.itemSize + 2 ];
  5569. },
  5570. setZ: function ( index, z ) {
  5571. this.array[ index * this.itemSize + 2 ] = z;
  5572. return this;
  5573. },
  5574. getW: function ( index ) {
  5575. return this.array[ index * this.itemSize + 3 ];
  5576. },
  5577. setW: function ( index, w ) {
  5578. this.array[ index * this.itemSize + 3 ] = w;
  5579. return this;
  5580. },
  5581. setXY: function ( index, x, y ) {
  5582. index *= this.itemSize;
  5583. this.array[ index + 0 ] = x;
  5584. this.array[ index + 1 ] = y;
  5585. return this;
  5586. },
  5587. setXYZ: function ( index, x, y, z ) {
  5588. index *= this.itemSize;
  5589. this.array[ index + 0 ] = x;
  5590. this.array[ index + 1 ] = y;
  5591. this.array[ index + 2 ] = z;
  5592. return this;
  5593. },
  5594. setXYZW: function ( index, x, y, z, w ) {
  5595. index *= this.itemSize;
  5596. this.array[ index + 0 ] = x;
  5597. this.array[ index + 1 ] = y;
  5598. this.array[ index + 2 ] = z;
  5599. this.array[ index + 3 ] = w;
  5600. return this;
  5601. },
  5602. clone: function () {
  5603. return new this.constructor().copy( this );
  5604. }
  5605. };
  5606. //
  5607. THREE.Int8Attribute = function ( array, itemSize ) {
  5608. return new THREE.BufferAttribute( new Int8Array( array ), itemSize );
  5609. };
  5610. THREE.Uint8Attribute = function ( array, itemSize ) {
  5611. return new THREE.BufferAttribute( new Uint8Array( array ), itemSize );
  5612. };
  5613. THREE.Uint8ClampedAttribute = function ( array, itemSize ) {
  5614. return new THREE.BufferAttribute( new Uint8ClampedArray( array ), itemSize );
  5615. };
  5616. THREE.Int16Attribute = function ( array, itemSize ) {
  5617. return new THREE.BufferAttribute( new Int16Array( array ), itemSize );
  5618. };
  5619. THREE.Uint16Attribute = function ( array, itemSize ) {
  5620. return new THREE.BufferAttribute( new Uint16Array( array ), itemSize );
  5621. };
  5622. THREE.Int32Attribute = function ( array, itemSize ) {
  5623. return new THREE.BufferAttribute( new Int32Array( array ), itemSize );
  5624. };
  5625. THREE.Uint32Attribute = function ( array, itemSize ) {
  5626. return new THREE.BufferAttribute( new Uint32Array( array ), itemSize );
  5627. };
  5628. THREE.Float32Attribute = function ( array, itemSize ) {
  5629. return new THREE.BufferAttribute( new Float32Array( array ), itemSize );
  5630. };
  5631. THREE.Float64Attribute = function ( array, itemSize ) {
  5632. return new THREE.BufferAttribute( new Float64Array( array ), itemSize );
  5633. };
  5634. // Deprecated
  5635. THREE.DynamicBufferAttribute = function ( array, itemSize ) {
  5636. console.warn( 'THREE.DynamicBufferAttribute has been removed. Use new THREE.BufferAttribute().setDynamic( true ) instead.' );
  5637. return new THREE.BufferAttribute( array, itemSize ).setDynamic( true );
  5638. };
  5639. // File:src/core/InstancedBufferAttribute.js
  5640. /**
  5641. * @author benaadams / https://twitter.com/ben_a_adams
  5642. */
  5643. THREE.InstancedBufferAttribute = function ( array, itemSize, meshPerAttribute ) {
  5644. THREE.BufferAttribute.call( this, array, itemSize );
  5645. this.meshPerAttribute = meshPerAttribute || 1;
  5646. };
  5647. THREE.InstancedBufferAttribute.prototype = Object.create( THREE.BufferAttribute.prototype );
  5648. THREE.InstancedBufferAttribute.prototype.constructor = THREE.InstancedBufferAttribute;
  5649. THREE.InstancedBufferAttribute.prototype.copy = function ( source ) {
  5650. THREE.BufferAttribute.prototype.copy.call( this, source );
  5651. this.meshPerAttribute = source.meshPerAttribute;
  5652. return this;
  5653. };
  5654. // File:src/core/InterleavedBuffer.js
  5655. /**
  5656. * @author benaadams / https://twitter.com/ben_a_adams
  5657. */
  5658. THREE.InterleavedBuffer = function ( array, stride ) {
  5659. this.uuid = THREE.Math.generateUUID();
  5660. this.array = array;
  5661. this.stride = stride;
  5662. this.dynamic = false;
  5663. this.updateRange = { offset: 0, count: - 1 };
  5664. this.version = 0;
  5665. };
  5666. THREE.InterleavedBuffer.prototype = {
  5667. constructor: THREE.InterleavedBuffer,
  5668. get length () {
  5669. return this.array.length;
  5670. },
  5671. get count () {
  5672. return this.array.length / this.stride;
  5673. },
  5674. set needsUpdate( value ) {
  5675. if ( value === true ) this.version ++;
  5676. },
  5677. setDynamic: function ( value ) {
  5678. this.dynamic = value;
  5679. return this;
  5680. },
  5681. copy: function ( source ) {
  5682. this.array = new source.array.constructor( source.array );
  5683. this.stride = source.stride;
  5684. this.dynamic = source.dynamic;
  5685. return this;
  5686. },
  5687. copyAt: function ( index1, attribute, index2 ) {
  5688. index1 *= this.stride;
  5689. index2 *= attribute.stride;
  5690. for ( var i = 0, l = this.stride; i < l; i ++ ) {
  5691. this.array[ index1 + i ] = attribute.array[ index2 + i ];
  5692. }
  5693. return this;
  5694. },
  5695. set: function ( value, offset ) {
  5696. if ( offset === undefined ) offset = 0;
  5697. this.array.set( value, offset );
  5698. return this;
  5699. },
  5700. clone: function () {
  5701. return new this.constructor().copy( this );
  5702. }
  5703. };
  5704. // File:src/core/InstancedInterleavedBuffer.js
  5705. /**
  5706. * @author benaadams / https://twitter.com/ben_a_adams
  5707. */
  5708. THREE.InstancedInterleavedBuffer = function ( array, stride, meshPerAttribute ) {
  5709. THREE.InterleavedBuffer.call( this, array, stride );
  5710. this.meshPerAttribute = meshPerAttribute || 1;
  5711. };
  5712. THREE.InstancedInterleavedBuffer.prototype = Object.create( THREE.InterleavedBuffer.prototype );
  5713. THREE.InstancedInterleavedBuffer.prototype.constructor = THREE.InstancedInterleavedBuffer;
  5714. THREE.InstancedInterleavedBuffer.prototype.copy = function ( source ) {
  5715. THREE.InterleavedBuffer.prototype.copy.call( this, source );
  5716. this.meshPerAttribute = source.meshPerAttribute;
  5717. return this;
  5718. };
  5719. // File:src/core/InterleavedBufferAttribute.js
  5720. /**
  5721. * @author benaadams / https://twitter.com/ben_a_adams
  5722. */
  5723. THREE.InterleavedBufferAttribute = function ( interleavedBuffer, itemSize, offset ) {
  5724. this.uuid = THREE.Math.generateUUID();
  5725. this.data = interleavedBuffer;
  5726. this.itemSize = itemSize;
  5727. this.offset = offset;
  5728. };
  5729. THREE.InterleavedBufferAttribute.prototype = {
  5730. constructor: THREE.InterleavedBufferAttribute,
  5731. get length() {
  5732. console.warn( 'THREE.BufferAttribute: .length has been deprecated. Please use .count.' );
  5733. return this.array.length;
  5734. },
  5735. get count() {
  5736. return this.data.count;
  5737. },
  5738. setX: function ( index, x ) {
  5739. this.data.array[ index * this.data.stride + this.offset ] = x;
  5740. return this;
  5741. },
  5742. setY: function ( index, y ) {
  5743. this.data.array[ index * this.data.stride + this.offset + 1 ] = y;
  5744. return this;
  5745. },
  5746. setZ: function ( index, z ) {
  5747. this.data.array[ index * this.data.stride + this.offset + 2 ] = z;
  5748. return this;
  5749. },
  5750. setW: function ( index, w ) {
  5751. this.data.array[ index * this.data.stride + this.offset + 3 ] = w;
  5752. return this;
  5753. },
  5754. getX: function ( index ) {
  5755. return this.data.array[ index * this.data.stride + this.offset ];
  5756. },
  5757. getY: function ( index ) {
  5758. return this.data.array[ index * this.data.stride + this.offset + 1 ];
  5759. },
  5760. getZ: function ( index ) {
  5761. return this.data.array[ index * this.data.stride + this.offset + 2 ];
  5762. },
  5763. getW: function ( index ) {
  5764. return this.data.array[ index * this.data.stride + this.offset + 3 ];
  5765. },
  5766. setXY: function ( index, x, y ) {
  5767. index = index * this.data.stride + this.offset;
  5768. this.data.array[ index + 0 ] = x;
  5769. this.data.array[ index + 1 ] = y;
  5770. return this;
  5771. },
  5772. setXYZ: function ( index, x, y, z ) {
  5773. index = index * this.data.stride + this.offset;
  5774. this.data.array[ index + 0 ] = x;
  5775. this.data.array[ index + 1 ] = y;
  5776. this.data.array[ index + 2 ] = z;
  5777. return this;
  5778. },
  5779. setXYZW: function ( index, x, y, z, w ) {
  5780. index = index * this.data.stride + this.offset;
  5781. this.data.array[ index + 0 ] = x;
  5782. this.data.array[ index + 1 ] = y;
  5783. this.data.array[ index + 2 ] = z;
  5784. this.data.array[ index + 3 ] = w;
  5785. return this;
  5786. }
  5787. };
  5788. // File:src/core/Geometry.js
  5789. /**
  5790. * @author mrdoob / http://mrdoob.com/
  5791. * @author kile / http://kile.stravaganza.org/
  5792. * @author alteredq / http://alteredqualia.com/
  5793. * @author mikael emtinger / http://gomo.se/
  5794. * @author zz85 / http://www.lab4games.net/zz85/blog
  5795. * @author bhouston / http://clara.io
  5796. */
  5797. THREE.Geometry = function () {
  5798. Object.defineProperty( this, 'id', { value: THREE.GeometryIdCount ++ } );
  5799. this.uuid = THREE.Math.generateUUID();
  5800. this.name = '';
  5801. this.type = 'Geometry';
  5802. this.vertices = [];
  5803. this.colors = [];
  5804. this.faces = [];
  5805. this.faceVertexUvs = [ [] ];
  5806. this.morphTargets = [];
  5807. this.morphNormals = [];
  5808. this.skinWeights = [];
  5809. this.skinIndices = [];
  5810. this.lineDistances = [];
  5811. this.boundingBox = null;
  5812. this.boundingSphere = null;
  5813. // update flags
  5814. this.verticesNeedUpdate = false;
  5815. this.elementsNeedUpdate = false;
  5816. this.uvsNeedUpdate = false;
  5817. this.normalsNeedUpdate = false;
  5818. this.colorsNeedUpdate = false;
  5819. this.lineDistancesNeedUpdate = false;
  5820. this.groupsNeedUpdate = false;
  5821. };
  5822. Object.assign( THREE.Geometry.prototype, THREE.EventDispatcher.prototype, {
  5823. applyMatrix: function ( matrix ) {
  5824. var normalMatrix = new THREE.Matrix3().getNormalMatrix( matrix );
  5825. for ( var i = 0, il = this.vertices.length; i < il; i ++ ) {
  5826. var vertex = this.vertices[ i ];
  5827. vertex.applyMatrix4( matrix );
  5828. }
  5829. for ( var i = 0, il = this.faces.length; i < il; i ++ ) {
  5830. var face = this.faces[ i ];
  5831. face.normal.applyMatrix3( normalMatrix ).normalize();
  5832. for ( var j = 0, jl = face.vertexNormals.length; j < jl; j ++ ) {
  5833. face.vertexNormals[ j ].applyMatrix3( normalMatrix ).normalize();
  5834. }
  5835. }
  5836. if ( this.boundingBox !== null ) {
  5837. this.computeBoundingBox();
  5838. }
  5839. if ( this.boundingSphere !== null ) {
  5840. this.computeBoundingSphere();
  5841. }
  5842. this.verticesNeedUpdate = true;
  5843. this.normalsNeedUpdate = true;
  5844. return this;
  5845. },
  5846. rotateX: function () {
  5847. // rotate geometry around world x-axis
  5848. var m1;
  5849. return function rotateX( angle ) {
  5850. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  5851. m1.makeRotationX( angle );
  5852. this.applyMatrix( m1 );
  5853. return this;
  5854. };
  5855. }(),
  5856. rotateY: function () {
  5857. // rotate geometry around world y-axis
  5858. var m1;
  5859. return function rotateY( angle ) {
  5860. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  5861. m1.makeRotationY( angle );
  5862. this.applyMatrix( m1 );
  5863. return this;
  5864. };
  5865. }(),
  5866. rotateZ: function () {
  5867. // rotate geometry around world z-axis
  5868. var m1;
  5869. return function rotateZ( angle ) {
  5870. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  5871. m1.makeRotationZ( angle );
  5872. this.applyMatrix( m1 );
  5873. return this;
  5874. };
  5875. }(),
  5876. translate: function () {
  5877. // translate geometry
  5878. var m1;
  5879. return function translate( x, y, z ) {
  5880. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  5881. m1.makeTranslation( x, y, z );
  5882. this.applyMatrix( m1 );
  5883. return this;
  5884. };
  5885. }(),
  5886. scale: function () {
  5887. // scale geometry
  5888. var m1;
  5889. return function scale( x, y, z ) {
  5890. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  5891. m1.makeScale( x, y, z );
  5892. this.applyMatrix( m1 );
  5893. return this;
  5894. };
  5895. }(),
  5896. lookAt: function () {
  5897. var obj;
  5898. return function lookAt( vector ) {
  5899. if ( obj === undefined ) obj = new THREE.Object3D();
  5900. obj.lookAt( vector );
  5901. obj.updateMatrix();
  5902. this.applyMatrix( obj.matrix );
  5903. };
  5904. }(),
  5905. fromBufferGeometry: function ( geometry ) {
  5906. var scope = this;
  5907. var indices = geometry.index !== null ? geometry.index.array : undefined;
  5908. var attributes = geometry.attributes;
  5909. var positions = attributes.position.array;
  5910. var normals = attributes.normal !== undefined ? attributes.normal.array : undefined;
  5911. var colors = attributes.color !== undefined ? attributes.color.array : undefined;
  5912. var uvs = attributes.uv !== undefined ? attributes.uv.array : undefined;
  5913. var uvs2 = attributes.uv2 !== undefined ? attributes.uv2.array : undefined;
  5914. if ( uvs2 !== undefined ) this.faceVertexUvs[ 1 ] = [];
  5915. var tempNormals = [];
  5916. var tempUVs = [];
  5917. var tempUVs2 = [];
  5918. for ( var i = 0, j = 0; i < positions.length; i += 3, j += 2 ) {
  5919. scope.vertices.push( new THREE.Vector3( positions[ i ], positions[ i + 1 ], positions[ i + 2 ] ) );
  5920. if ( normals !== undefined ) {
  5921. tempNormals.push( new THREE.Vector3( normals[ i ], normals[ i + 1 ], normals[ i + 2 ] ) );
  5922. }
  5923. if ( colors !== undefined ) {
  5924. scope.colors.push( new THREE.Color( colors[ i ], colors[ i + 1 ], colors[ i + 2 ] ) );
  5925. }
  5926. if ( uvs !== undefined ) {
  5927. tempUVs.push( new THREE.Vector2( uvs[ j ], uvs[ j + 1 ] ) );
  5928. }
  5929. if ( uvs2 !== undefined ) {
  5930. tempUVs2.push( new THREE.Vector2( uvs2[ j ], uvs2[ j + 1 ] ) );
  5931. }
  5932. }
  5933. function addFace( a, b, c, materialIndex ) {
  5934. var vertexNormals = normals !== undefined ? [ tempNormals[ a ].clone(), tempNormals[ b ].clone(), tempNormals[ c ].clone() ] : [];
  5935. var vertexColors = colors !== undefined ? [ scope.colors[ a ].clone(), scope.colors[ b ].clone(), scope.colors[ c ].clone() ] : [];
  5936. var face = new THREE.Face3( a, b, c, vertexNormals, vertexColors, materialIndex );
  5937. scope.faces.push( face );
  5938. if ( uvs !== undefined ) {
  5939. scope.faceVertexUvs[ 0 ].push( [ tempUVs[ a ].clone(), tempUVs[ b ].clone(), tempUVs[ c ].clone() ] );
  5940. }
  5941. if ( uvs2 !== undefined ) {
  5942. scope.faceVertexUvs[ 1 ].push( [ tempUVs2[ a ].clone(), tempUVs2[ b ].clone(), tempUVs2[ c ].clone() ] );
  5943. }
  5944. }
  5945. if ( indices !== undefined ) {
  5946. var groups = geometry.groups;
  5947. if ( groups.length > 0 ) {
  5948. for ( var i = 0; i < groups.length; i ++ ) {
  5949. var group = groups[ i ];
  5950. var start = group.start;
  5951. var count = group.count;
  5952. for ( var j = start, jl = start + count; j < jl; j += 3 ) {
  5953. addFace( indices[ j ], indices[ j + 1 ], indices[ j + 2 ], group.materialIndex );
  5954. }
  5955. }
  5956. } else {
  5957. for ( var i = 0; i < indices.length; i += 3 ) {
  5958. addFace( indices[ i ], indices[ i + 1 ], indices[ i + 2 ] );
  5959. }
  5960. }
  5961. } else {
  5962. for ( var i = 0; i < positions.length / 3; i += 3 ) {
  5963. addFace( i, i + 1, i + 2 );
  5964. }
  5965. }
  5966. this.computeFaceNormals();
  5967. if ( geometry.boundingBox !== null ) {
  5968. this.boundingBox = geometry.boundingBox.clone();
  5969. }
  5970. if ( geometry.boundingSphere !== null ) {
  5971. this.boundingSphere = geometry.boundingSphere.clone();
  5972. }
  5973. return this;
  5974. },
  5975. center: function () {
  5976. this.computeBoundingBox();
  5977. var offset = this.boundingBox.center().negate();
  5978. this.translate( offset.x, offset.y, offset.z );
  5979. return offset;
  5980. },
  5981. normalize: function () {
  5982. this.computeBoundingSphere();
  5983. var center = this.boundingSphere.center;
  5984. var radius = this.boundingSphere.radius;
  5985. var s = radius === 0 ? 1 : 1.0 / radius;
  5986. var matrix = new THREE.Matrix4();
  5987. matrix.set(
  5988. s, 0, 0, - s * center.x,
  5989. 0, s, 0, - s * center.y,
  5990. 0, 0, s, - s * center.z,
  5991. 0, 0, 0, 1
  5992. );
  5993. this.applyMatrix( matrix );
  5994. return this;
  5995. },
  5996. computeFaceNormals: function () {
  5997. var cb = new THREE.Vector3(), ab = new THREE.Vector3();
  5998. for ( var f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5999. var face = this.faces[ f ];
  6000. var vA = this.vertices[ face.a ];
  6001. var vB = this.vertices[ face.b ];
  6002. var vC = this.vertices[ face.c ];
  6003. cb.subVectors( vC, vB );
  6004. ab.subVectors( vA, vB );
  6005. cb.cross( ab );
  6006. cb.normalize();
  6007. face.normal.copy( cb );
  6008. }
  6009. },
  6010. computeVertexNormals: function ( areaWeighted ) {
  6011. if ( areaWeighted === undefined ) areaWeighted = true;
  6012. var v, vl, f, fl, face, vertices;
  6013. vertices = new Array( this.vertices.length );
  6014. for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) {
  6015. vertices[ v ] = new THREE.Vector3();
  6016. }
  6017. if ( areaWeighted ) {
  6018. // vertex normals weighted by triangle areas
  6019. // http://www.iquilezles.org/www/articles/normals/normals.htm
  6020. var vA, vB, vC;
  6021. var cb = new THREE.Vector3(), ab = new THREE.Vector3();
  6022. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  6023. face = this.faces[ f ];
  6024. vA = this.vertices[ face.a ];
  6025. vB = this.vertices[ face.b ];
  6026. vC = this.vertices[ face.c ];
  6027. cb.subVectors( vC, vB );
  6028. ab.subVectors( vA, vB );
  6029. cb.cross( ab );
  6030. vertices[ face.a ].add( cb );
  6031. vertices[ face.b ].add( cb );
  6032. vertices[ face.c ].add( cb );
  6033. }
  6034. } else {
  6035. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  6036. face = this.faces[ f ];
  6037. vertices[ face.a ].add( face.normal );
  6038. vertices[ face.b ].add( face.normal );
  6039. vertices[ face.c ].add( face.normal );
  6040. }
  6041. }
  6042. for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) {
  6043. vertices[ v ].normalize();
  6044. }
  6045. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  6046. face = this.faces[ f ];
  6047. var vertexNormals = face.vertexNormals;
  6048. if ( vertexNormals.length === 3 ) {
  6049. vertexNormals[ 0 ].copy( vertices[ face.a ] );
  6050. vertexNormals[ 1 ].copy( vertices[ face.b ] );
  6051. vertexNormals[ 2 ].copy( vertices[ face.c ] );
  6052. } else {
  6053. vertexNormals[ 0 ] = vertices[ face.a ].clone();
  6054. vertexNormals[ 1 ] = vertices[ face.b ].clone();
  6055. vertexNormals[ 2 ] = vertices[ face.c ].clone();
  6056. }
  6057. }
  6058. if ( this.faces.length > 0 ) {
  6059. this.normalsNeedUpdate = true;
  6060. }
  6061. },
  6062. computeMorphNormals: function () {
  6063. var i, il, f, fl, face;
  6064. // save original normals
  6065. // - create temp variables on first access
  6066. // otherwise just copy (for faster repeated calls)
  6067. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  6068. face = this.faces[ f ];
  6069. if ( ! face.__originalFaceNormal ) {
  6070. face.__originalFaceNormal = face.normal.clone();
  6071. } else {
  6072. face.__originalFaceNormal.copy( face.normal );
  6073. }
  6074. if ( ! face.__originalVertexNormals ) face.__originalVertexNormals = [];
  6075. for ( i = 0, il = face.vertexNormals.length; i < il; i ++ ) {
  6076. if ( ! face.__originalVertexNormals[ i ] ) {
  6077. face.__originalVertexNormals[ i ] = face.vertexNormals[ i ].clone();
  6078. } else {
  6079. face.__originalVertexNormals[ i ].copy( face.vertexNormals[ i ] );
  6080. }
  6081. }
  6082. }
  6083. // use temp geometry to compute face and vertex normals for each morph
  6084. var tmpGeo = new THREE.Geometry();
  6085. tmpGeo.faces = this.faces;
  6086. for ( i = 0, il = this.morphTargets.length; i < il; i ++ ) {
  6087. // create on first access
  6088. if ( ! this.morphNormals[ i ] ) {
  6089. this.morphNormals[ i ] = {};
  6090. this.morphNormals[ i ].faceNormals = [];
  6091. this.morphNormals[ i ].vertexNormals = [];
  6092. var dstNormalsFace = this.morphNormals[ i ].faceNormals;
  6093. var dstNormalsVertex = this.morphNormals[ i ].vertexNormals;
  6094. var faceNormal, vertexNormals;
  6095. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  6096. faceNormal = new THREE.Vector3();
  6097. vertexNormals = { a: new THREE.Vector3(), b: new THREE.Vector3(), c: new THREE.Vector3() };
  6098. dstNormalsFace.push( faceNormal );
  6099. dstNormalsVertex.push( vertexNormals );
  6100. }
  6101. }
  6102. var morphNormals = this.morphNormals[ i ];
  6103. // set vertices to morph target
  6104. tmpGeo.vertices = this.morphTargets[ i ].vertices;
  6105. // compute morph normals
  6106. tmpGeo.computeFaceNormals();
  6107. tmpGeo.computeVertexNormals();
  6108. // store morph normals
  6109. var faceNormal, vertexNormals;
  6110. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  6111. face = this.faces[ f ];
  6112. faceNormal = morphNormals.faceNormals[ f ];
  6113. vertexNormals = morphNormals.vertexNormals[ f ];
  6114. faceNormal.copy( face.normal );
  6115. vertexNormals.a.copy( face.vertexNormals[ 0 ] );
  6116. vertexNormals.b.copy( face.vertexNormals[ 1 ] );
  6117. vertexNormals.c.copy( face.vertexNormals[ 2 ] );
  6118. }
  6119. }
  6120. // restore original normals
  6121. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  6122. face = this.faces[ f ];
  6123. face.normal = face.__originalFaceNormal;
  6124. face.vertexNormals = face.__originalVertexNormals;
  6125. }
  6126. },
  6127. computeTangents: function () {
  6128. console.warn( 'THREE.Geometry: .computeTangents() has been removed.' );
  6129. },
  6130. computeLineDistances: function () {
  6131. var d = 0;
  6132. var vertices = this.vertices;
  6133. for ( var i = 0, il = vertices.length; i < il; i ++ ) {
  6134. if ( i > 0 ) {
  6135. d += vertices[ i ].distanceTo( vertices[ i - 1 ] );
  6136. }
  6137. this.lineDistances[ i ] = d;
  6138. }
  6139. },
  6140. computeBoundingBox: function () {
  6141. if ( this.boundingBox === null ) {
  6142. this.boundingBox = new THREE.Box3();
  6143. }
  6144. this.boundingBox.setFromPoints( this.vertices );
  6145. },
  6146. computeBoundingSphere: function () {
  6147. if ( this.boundingSphere === null ) {
  6148. this.boundingSphere = new THREE.Sphere();
  6149. }
  6150. this.boundingSphere.setFromPoints( this.vertices );
  6151. },
  6152. merge: function ( geometry, matrix, materialIndexOffset ) {
  6153. if ( geometry instanceof THREE.Geometry === false ) {
  6154. console.error( 'THREE.Geometry.merge(): geometry not an instance of THREE.Geometry.', geometry );
  6155. return;
  6156. }
  6157. var normalMatrix,
  6158. vertexOffset = this.vertices.length,
  6159. vertices1 = this.vertices,
  6160. vertices2 = geometry.vertices,
  6161. faces1 = this.faces,
  6162. faces2 = geometry.faces,
  6163. uvs1 = this.faceVertexUvs[ 0 ],
  6164. uvs2 = geometry.faceVertexUvs[ 0 ];
  6165. if ( materialIndexOffset === undefined ) materialIndexOffset = 0;
  6166. if ( matrix !== undefined ) {
  6167. normalMatrix = new THREE.Matrix3().getNormalMatrix( matrix );
  6168. }
  6169. // vertices
  6170. for ( var i = 0, il = vertices2.length; i < il; i ++ ) {
  6171. var vertex = vertices2[ i ];
  6172. var vertexCopy = vertex.clone();
  6173. if ( matrix !== undefined ) vertexCopy.applyMatrix4( matrix );
  6174. vertices1.push( vertexCopy );
  6175. }
  6176. // faces
  6177. for ( i = 0, il = faces2.length; i < il; i ++ ) {
  6178. var face = faces2[ i ], faceCopy, normal, color,
  6179. faceVertexNormals = face.vertexNormals,
  6180. faceVertexColors = face.vertexColors;
  6181. faceCopy = new THREE.Face3( face.a + vertexOffset, face.b + vertexOffset, face.c + vertexOffset );
  6182. faceCopy.normal.copy( face.normal );
  6183. if ( normalMatrix !== undefined ) {
  6184. faceCopy.normal.applyMatrix3( normalMatrix ).normalize();
  6185. }
  6186. for ( var j = 0, jl = faceVertexNormals.length; j < jl; j ++ ) {
  6187. normal = faceVertexNormals[ j ].clone();
  6188. if ( normalMatrix !== undefined ) {
  6189. normal.applyMatrix3( normalMatrix ).normalize();
  6190. }
  6191. faceCopy.vertexNormals.push( normal );
  6192. }
  6193. faceCopy.color.copy( face.color );
  6194. for ( var j = 0, jl = faceVertexColors.length; j < jl; j ++ ) {
  6195. color = faceVertexColors[ j ];
  6196. faceCopy.vertexColors.push( color.clone() );
  6197. }
  6198. faceCopy.materialIndex = face.materialIndex + materialIndexOffset;
  6199. faces1.push( faceCopy );
  6200. }
  6201. // uvs
  6202. for ( i = 0, il = uvs2.length; i < il; i ++ ) {
  6203. var uv = uvs2[ i ], uvCopy = [];
  6204. if ( uv === undefined ) {
  6205. continue;
  6206. }
  6207. for ( var j = 0, jl = uv.length; j < jl; j ++ ) {
  6208. uvCopy.push( uv[ j ].clone() );
  6209. }
  6210. uvs1.push( uvCopy );
  6211. }
  6212. },
  6213. mergeMesh: function ( mesh ) {
  6214. if ( mesh instanceof THREE.Mesh === false ) {
  6215. console.error( 'THREE.Geometry.mergeMesh(): mesh not an instance of THREE.Mesh.', mesh );
  6216. return;
  6217. }
  6218. mesh.matrixAutoUpdate && mesh.updateMatrix();
  6219. this.merge( mesh.geometry, mesh.matrix );
  6220. },
  6221. /*
  6222. * Checks for duplicate vertices with hashmap.
  6223. * Duplicated vertices are removed
  6224. * and faces' vertices are updated.
  6225. */
  6226. mergeVertices: function () {
  6227. var verticesMap = {}; // Hashmap for looking up vertices by position coordinates (and making sure they are unique)
  6228. var unique = [], changes = [];
  6229. var v, key;
  6230. var precisionPoints = 4; // number of decimal points, e.g. 4 for epsilon of 0.0001
  6231. var precision = Math.pow( 10, precisionPoints );
  6232. var i, il, face;
  6233. var indices, j, jl;
  6234. for ( i = 0, il = this.vertices.length; i < il; i ++ ) {
  6235. v = this.vertices[ i ];
  6236. key = Math.round( v.x * precision ) + '_' + Math.round( v.y * precision ) + '_' + Math.round( v.z * precision );
  6237. if ( verticesMap[ key ] === undefined ) {
  6238. verticesMap[ key ] = i;
  6239. unique.push( this.vertices[ i ] );
  6240. changes[ i ] = unique.length - 1;
  6241. } else {
  6242. //console.log('Duplicate vertex found. ', i, ' could be using ', verticesMap[key]);
  6243. changes[ i ] = changes[ verticesMap[ key ] ];
  6244. }
  6245. }
  6246. // if faces are completely degenerate after merging vertices, we
  6247. // have to remove them from the geometry.
  6248. var faceIndicesToRemove = [];
  6249. for ( i = 0, il = this.faces.length; i < il; i ++ ) {
  6250. face = this.faces[ i ];
  6251. face.a = changes[ face.a ];
  6252. face.b = changes[ face.b ];
  6253. face.c = changes[ face.c ];
  6254. indices = [ face.a, face.b, face.c ];
  6255. var dupIndex = - 1;
  6256. // if any duplicate vertices are found in a Face3
  6257. // we have to remove the face as nothing can be saved
  6258. for ( var n = 0; n < 3; n ++ ) {
  6259. if ( indices[ n ] === indices[ ( n + 1 ) % 3 ] ) {
  6260. dupIndex = n;
  6261. faceIndicesToRemove.push( i );
  6262. break;
  6263. }
  6264. }
  6265. }
  6266. for ( i = faceIndicesToRemove.length - 1; i >= 0; i -- ) {
  6267. var idx = faceIndicesToRemove[ i ];
  6268. this.faces.splice( idx, 1 );
  6269. for ( j = 0, jl = this.faceVertexUvs.length; j < jl; j ++ ) {
  6270. this.faceVertexUvs[ j ].splice( idx, 1 );
  6271. }
  6272. }
  6273. // Use unique set of vertices
  6274. var diff = this.vertices.length - unique.length;
  6275. this.vertices = unique;
  6276. return diff;
  6277. },
  6278. sortFacesByMaterialIndex: function () {
  6279. var faces = this.faces;
  6280. var length = faces.length;
  6281. // tag faces
  6282. for ( var i = 0; i < length; i ++ ) {
  6283. faces[ i ]._id = i;
  6284. }
  6285. // sort faces
  6286. function materialIndexSort( a, b ) {
  6287. return a.materialIndex - b.materialIndex;
  6288. }
  6289. faces.sort( materialIndexSort );
  6290. // sort uvs
  6291. var uvs1 = this.faceVertexUvs[ 0 ];
  6292. var uvs2 = this.faceVertexUvs[ 1 ];
  6293. var newUvs1, newUvs2;
  6294. if ( uvs1 && uvs1.length === length ) newUvs1 = [];
  6295. if ( uvs2 && uvs2.length === length ) newUvs2 = [];
  6296. for ( var i = 0; i < length; i ++ ) {
  6297. var id = faces[ i ]._id;
  6298. if ( newUvs1 ) newUvs1.push( uvs1[ id ] );
  6299. if ( newUvs2 ) newUvs2.push( uvs2[ id ] );
  6300. }
  6301. if ( newUvs1 ) this.faceVertexUvs[ 0 ] = newUvs1;
  6302. if ( newUvs2 ) this.faceVertexUvs[ 1 ] = newUvs2;
  6303. },
  6304. toJSON: function () {
  6305. var data = {
  6306. metadata: {
  6307. version: 4.4,
  6308. type: 'Geometry',
  6309. generator: 'Geometry.toJSON'
  6310. }
  6311. };
  6312. // standard Geometry serialization
  6313. data.uuid = this.uuid;
  6314. data.type = this.type;
  6315. if ( this.name !== '' ) data.name = this.name;
  6316. if ( this.parameters !== undefined ) {
  6317. var parameters = this.parameters;
  6318. for ( var key in parameters ) {
  6319. if ( parameters[ key ] !== undefined ) data[ key ] = parameters[ key ];
  6320. }
  6321. return data;
  6322. }
  6323. var vertices = [];
  6324. for ( var i = 0; i < this.vertices.length; i ++ ) {
  6325. var vertex = this.vertices[ i ];
  6326. vertices.push( vertex.x, vertex.y, vertex.z );
  6327. }
  6328. var faces = [];
  6329. var normals = [];
  6330. var normalsHash = {};
  6331. var colors = [];
  6332. var colorsHash = {};
  6333. var uvs = [];
  6334. var uvsHash = {};
  6335. for ( var i = 0; i < this.faces.length; i ++ ) {
  6336. var face = this.faces[ i ];
  6337. var hasMaterial = true;
  6338. var hasFaceUv = false; // deprecated
  6339. var hasFaceVertexUv = this.faceVertexUvs[ 0 ][ i ] !== undefined;
  6340. var hasFaceNormal = face.normal.length() > 0;
  6341. var hasFaceVertexNormal = face.vertexNormals.length > 0;
  6342. var hasFaceColor = face.color.r !== 1 || face.color.g !== 1 || face.color.b !== 1;
  6343. var hasFaceVertexColor = face.vertexColors.length > 0;
  6344. var faceType = 0;
  6345. faceType = setBit( faceType, 0, 0 ); // isQuad
  6346. faceType = setBit( faceType, 1, hasMaterial );
  6347. faceType = setBit( faceType, 2, hasFaceUv );
  6348. faceType = setBit( faceType, 3, hasFaceVertexUv );
  6349. faceType = setBit( faceType, 4, hasFaceNormal );
  6350. faceType = setBit( faceType, 5, hasFaceVertexNormal );
  6351. faceType = setBit( faceType, 6, hasFaceColor );
  6352. faceType = setBit( faceType, 7, hasFaceVertexColor );
  6353. faces.push( faceType );
  6354. faces.push( face.a, face.b, face.c );
  6355. faces.push( face.materialIndex );
  6356. if ( hasFaceVertexUv ) {
  6357. var faceVertexUvs = this.faceVertexUvs[ 0 ][ i ];
  6358. faces.push(
  6359. getUvIndex( faceVertexUvs[ 0 ] ),
  6360. getUvIndex( faceVertexUvs[ 1 ] ),
  6361. getUvIndex( faceVertexUvs[ 2 ] )
  6362. );
  6363. }
  6364. if ( hasFaceNormal ) {
  6365. faces.push( getNormalIndex( face.normal ) );
  6366. }
  6367. if ( hasFaceVertexNormal ) {
  6368. var vertexNormals = face.vertexNormals;
  6369. faces.push(
  6370. getNormalIndex( vertexNormals[ 0 ] ),
  6371. getNormalIndex( vertexNormals[ 1 ] ),
  6372. getNormalIndex( vertexNormals[ 2 ] )
  6373. );
  6374. }
  6375. if ( hasFaceColor ) {
  6376. faces.push( getColorIndex( face.color ) );
  6377. }
  6378. if ( hasFaceVertexColor ) {
  6379. var vertexColors = face.vertexColors;
  6380. faces.push(
  6381. getColorIndex( vertexColors[ 0 ] ),
  6382. getColorIndex( vertexColors[ 1 ] ),
  6383. getColorIndex( vertexColors[ 2 ] )
  6384. );
  6385. }
  6386. }
  6387. function setBit( value, position, enabled ) {
  6388. return enabled ? value | ( 1 << position ) : value & ( ~ ( 1 << position ) );
  6389. }
  6390. function getNormalIndex( normal ) {
  6391. var hash = normal.x.toString() + normal.y.toString() + normal.z.toString();
  6392. if ( normalsHash[ hash ] !== undefined ) {
  6393. return normalsHash[ hash ];
  6394. }
  6395. normalsHash[ hash ] = normals.length / 3;
  6396. normals.push( normal.x, normal.y, normal.z );
  6397. return normalsHash[ hash ];
  6398. }
  6399. function getColorIndex( color ) {
  6400. var hash = color.r.toString() + color.g.toString() + color.b.toString();
  6401. if ( colorsHash[ hash ] !== undefined ) {
  6402. return colorsHash[ hash ];
  6403. }
  6404. colorsHash[ hash ] = colors.length;
  6405. colors.push( color.getHex() );
  6406. return colorsHash[ hash ];
  6407. }
  6408. function getUvIndex( uv ) {
  6409. var hash = uv.x.toString() + uv.y.toString();
  6410. if ( uvsHash[ hash ] !== undefined ) {
  6411. return uvsHash[ hash ];
  6412. }
  6413. uvsHash[ hash ] = uvs.length / 2;
  6414. uvs.push( uv.x, uv.y );
  6415. return uvsHash[ hash ];
  6416. }
  6417. data.data = {};
  6418. data.data.vertices = vertices;
  6419. data.data.normals = normals;
  6420. if ( colors.length > 0 ) data.data.colors = colors;
  6421. if ( uvs.length > 0 ) data.data.uvs = [ uvs ]; // temporal backward compatibility
  6422. data.data.faces = faces;
  6423. return data;
  6424. },
  6425. clone: function () {
  6426. /*
  6427. // Handle primitives
  6428. var parameters = this.parameters;
  6429. if ( parameters !== undefined ) {
  6430. var values = [];
  6431. for ( var key in parameters ) {
  6432. values.push( parameters[ key ] );
  6433. }
  6434. var geometry = Object.create( this.constructor.prototype );
  6435. this.constructor.apply( geometry, values );
  6436. return geometry;
  6437. }
  6438. return new this.constructor().copy( this );
  6439. */
  6440. return new THREE.Geometry().copy( this );
  6441. },
  6442. copy: function ( source ) {
  6443. this.vertices = [];
  6444. this.faces = [];
  6445. this.faceVertexUvs = [ [] ];
  6446. var vertices = source.vertices;
  6447. for ( var i = 0, il = vertices.length; i < il; i ++ ) {
  6448. this.vertices.push( vertices[ i ].clone() );
  6449. }
  6450. var faces = source.faces;
  6451. for ( var i = 0, il = faces.length; i < il; i ++ ) {
  6452. this.faces.push( faces[ i ].clone() );
  6453. }
  6454. for ( var i = 0, il = source.faceVertexUvs.length; i < il; i ++ ) {
  6455. var faceVertexUvs = source.faceVertexUvs[ i ];
  6456. if ( this.faceVertexUvs[ i ] === undefined ) {
  6457. this.faceVertexUvs[ i ] = [];
  6458. }
  6459. for ( var j = 0, jl = faceVertexUvs.length; j < jl; j ++ ) {
  6460. var uvs = faceVertexUvs[ j ], uvsCopy = [];
  6461. for ( var k = 0, kl = uvs.length; k < kl; k ++ ) {
  6462. var uv = uvs[ k ];
  6463. uvsCopy.push( uv.clone() );
  6464. }
  6465. this.faceVertexUvs[ i ].push( uvsCopy );
  6466. }
  6467. }
  6468. return this;
  6469. },
  6470. dispose: function () {
  6471. this.dispatchEvent( { type: 'dispose' } );
  6472. }
  6473. } );
  6474. THREE.GeometryIdCount = 0;
  6475. // File:src/core/DirectGeometry.js
  6476. /**
  6477. * @author mrdoob / http://mrdoob.com/
  6478. */
  6479. THREE.DirectGeometry = function () {
  6480. Object.defineProperty( this, 'id', { value: THREE.GeometryIdCount ++ } );
  6481. this.uuid = THREE.Math.generateUUID();
  6482. this.name = '';
  6483. this.type = 'DirectGeometry';
  6484. this.indices = [];
  6485. this.vertices = [];
  6486. this.normals = [];
  6487. this.colors = [];
  6488. this.uvs = [];
  6489. this.uvs2 = [];
  6490. this.groups = [];
  6491. this.morphTargets = {};
  6492. this.skinWeights = [];
  6493. this.skinIndices = [];
  6494. // this.lineDistances = [];
  6495. this.boundingBox = null;
  6496. this.boundingSphere = null;
  6497. // update flags
  6498. this.verticesNeedUpdate = false;
  6499. this.normalsNeedUpdate = false;
  6500. this.colorsNeedUpdate = false;
  6501. this.uvsNeedUpdate = false;
  6502. this.groupsNeedUpdate = false;
  6503. };
  6504. Object.assign( THREE.DirectGeometry.prototype, THREE.EventDispatcher.prototype, {
  6505. computeBoundingBox: THREE.Geometry.prototype.computeBoundingBox,
  6506. computeBoundingSphere: THREE.Geometry.prototype.computeBoundingSphere,
  6507. computeFaceNormals: function () {
  6508. console.warn( 'THREE.DirectGeometry: computeFaceNormals() is not a method of this type of geometry.' );
  6509. },
  6510. computeVertexNormals: function () {
  6511. console.warn( 'THREE.DirectGeometry: computeVertexNormals() is not a method of this type of geometry.' );
  6512. },
  6513. computeGroups: function ( geometry ) {
  6514. var group;
  6515. var groups = [];
  6516. var materialIndex;
  6517. var faces = geometry.faces;
  6518. for ( var i = 0; i < faces.length; i ++ ) {
  6519. var face = faces[ i ];
  6520. // materials
  6521. if ( face.materialIndex !== materialIndex ) {
  6522. materialIndex = face.materialIndex;
  6523. if ( group !== undefined ) {
  6524. group.count = ( i * 3 ) - group.start;
  6525. groups.push( group );
  6526. }
  6527. group = {
  6528. start: i * 3,
  6529. materialIndex: materialIndex
  6530. };
  6531. }
  6532. }
  6533. if ( group !== undefined ) {
  6534. group.count = ( i * 3 ) - group.start;
  6535. groups.push( group );
  6536. }
  6537. this.groups = groups;
  6538. },
  6539. fromGeometry: function ( geometry ) {
  6540. var faces = geometry.faces;
  6541. var vertices = geometry.vertices;
  6542. var faceVertexUvs = geometry.faceVertexUvs;
  6543. var hasFaceVertexUv = faceVertexUvs[ 0 ] && faceVertexUvs[ 0 ].length > 0;
  6544. var hasFaceVertexUv2 = faceVertexUvs[ 1 ] && faceVertexUvs[ 1 ].length > 0;
  6545. // morphs
  6546. var morphTargets = geometry.morphTargets;
  6547. var morphTargetsLength = morphTargets.length;
  6548. var morphTargetsPosition;
  6549. if ( morphTargetsLength > 0 ) {
  6550. morphTargetsPosition = [];
  6551. for ( var i = 0; i < morphTargetsLength; i ++ ) {
  6552. morphTargetsPosition[ i ] = [];
  6553. }
  6554. this.morphTargets.position = morphTargetsPosition;
  6555. }
  6556. var morphNormals = geometry.morphNormals;
  6557. var morphNormalsLength = morphNormals.length;
  6558. var morphTargetsNormal;
  6559. if ( morphNormalsLength > 0 ) {
  6560. morphTargetsNormal = [];
  6561. for ( var i = 0; i < morphNormalsLength; i ++ ) {
  6562. morphTargetsNormal[ i ] = [];
  6563. }
  6564. this.morphTargets.normal = morphTargetsNormal;
  6565. }
  6566. // skins
  6567. var skinIndices = geometry.skinIndices;
  6568. var skinWeights = geometry.skinWeights;
  6569. var hasSkinIndices = skinIndices.length === vertices.length;
  6570. var hasSkinWeights = skinWeights.length === vertices.length;
  6571. //
  6572. for ( var i = 0; i < faces.length; i ++ ) {
  6573. var face = faces[ i ];
  6574. this.vertices.push( vertices[ face.a ], vertices[ face.b ], vertices[ face.c ] );
  6575. var vertexNormals = face.vertexNormals;
  6576. if ( vertexNormals.length === 3 ) {
  6577. this.normals.push( vertexNormals[ 0 ], vertexNormals[ 1 ], vertexNormals[ 2 ] );
  6578. } else {
  6579. var normal = face.normal;
  6580. this.normals.push( normal, normal, normal );
  6581. }
  6582. var vertexColors = face.vertexColors;
  6583. if ( vertexColors.length === 3 ) {
  6584. this.colors.push( vertexColors[ 0 ], vertexColors[ 1 ], vertexColors[ 2 ] );
  6585. } else {
  6586. var color = face.color;
  6587. this.colors.push( color, color, color );
  6588. }
  6589. if ( hasFaceVertexUv === true ) {
  6590. var vertexUvs = faceVertexUvs[ 0 ][ i ];
  6591. if ( vertexUvs !== undefined ) {
  6592. this.uvs.push( vertexUvs[ 0 ], vertexUvs[ 1 ], vertexUvs[ 2 ] );
  6593. } else {
  6594. console.warn( 'THREE.DirectGeometry.fromGeometry(): Undefined vertexUv ', i );
  6595. this.uvs.push( new THREE.Vector2(), new THREE.Vector2(), new THREE.Vector2() );
  6596. }
  6597. }
  6598. if ( hasFaceVertexUv2 === true ) {
  6599. var vertexUvs = faceVertexUvs[ 1 ][ i ];
  6600. if ( vertexUvs !== undefined ) {
  6601. this.uvs2.push( vertexUvs[ 0 ], vertexUvs[ 1 ], vertexUvs[ 2 ] );
  6602. } else {
  6603. console.warn( 'THREE.DirectGeometry.fromGeometry(): Undefined vertexUv2 ', i );
  6604. this.uvs2.push( new THREE.Vector2(), new THREE.Vector2(), new THREE.Vector2() );
  6605. }
  6606. }
  6607. // morphs
  6608. for ( var j = 0; j < morphTargetsLength; j ++ ) {
  6609. var morphTarget = morphTargets[ j ].vertices;
  6610. morphTargetsPosition[ j ].push( morphTarget[ face.a ], morphTarget[ face.b ], morphTarget[ face.c ] );
  6611. }
  6612. for ( var j = 0; j < morphNormalsLength; j ++ ) {
  6613. var morphNormal = morphNormals[ j ].vertexNormals[ i ];
  6614. morphTargetsNormal[ j ].push( morphNormal.a, morphNormal.b, morphNormal.c );
  6615. }
  6616. // skins
  6617. if ( hasSkinIndices ) {
  6618. this.skinIndices.push( skinIndices[ face.a ], skinIndices[ face.b ], skinIndices[ face.c ] );
  6619. }
  6620. if ( hasSkinWeights ) {
  6621. this.skinWeights.push( skinWeights[ face.a ], skinWeights[ face.b ], skinWeights[ face.c ] );
  6622. }
  6623. }
  6624. this.computeGroups( geometry );
  6625. this.verticesNeedUpdate = geometry.verticesNeedUpdate;
  6626. this.normalsNeedUpdate = geometry.normalsNeedUpdate;
  6627. this.colorsNeedUpdate = geometry.colorsNeedUpdate;
  6628. this.uvsNeedUpdate = geometry.uvsNeedUpdate;
  6629. this.groupsNeedUpdate = geometry.groupsNeedUpdate;
  6630. return this;
  6631. },
  6632. dispose: function () {
  6633. this.dispatchEvent( { type: 'dispose' } );
  6634. }
  6635. } );
  6636. // File:src/core/BufferGeometry.js
  6637. /**
  6638. * @author alteredq / http://alteredqualia.com/
  6639. * @author mrdoob / http://mrdoob.com/
  6640. */
  6641. THREE.BufferGeometry = function () {
  6642. Object.defineProperty( this, 'id', { value: THREE.GeometryIdCount ++ } );
  6643. this.uuid = THREE.Math.generateUUID();
  6644. this.name = '';
  6645. this.type = 'BufferGeometry';
  6646. this.index = null;
  6647. this.attributes = {};
  6648. this.morphAttributes = {};
  6649. this.groups = [];
  6650. this.boundingBox = null;
  6651. this.boundingSphere = null;
  6652. this.drawRange = { start: 0, count: Infinity };
  6653. };
  6654. Object.assign( THREE.BufferGeometry.prototype, THREE.EventDispatcher.prototype, {
  6655. getIndex: function () {
  6656. return this.index;
  6657. },
  6658. setIndex: function ( index ) {
  6659. this.index = index;
  6660. },
  6661. addAttribute: function ( name, attribute ) {
  6662. if ( attribute instanceof THREE.BufferAttribute === false && attribute instanceof THREE.InterleavedBufferAttribute === false ) {
  6663. console.warn( 'THREE.BufferGeometry: .addAttribute() now expects ( name, attribute ).' );
  6664. this.addAttribute( name, new THREE.BufferAttribute( arguments[ 1 ], arguments[ 2 ] ) );
  6665. return;
  6666. }
  6667. if ( name === 'index' ) {
  6668. console.warn( 'THREE.BufferGeometry.addAttribute: Use .setIndex() for index attribute.' );
  6669. this.setIndex( attribute );
  6670. return;
  6671. }
  6672. this.attributes[ name ] = attribute;
  6673. return this;
  6674. },
  6675. getAttribute: function ( name ) {
  6676. return this.attributes[ name ];
  6677. },
  6678. removeAttribute: function ( name ) {
  6679. delete this.attributes[ name ];
  6680. return this;
  6681. },
  6682. addGroup: function ( start, count, materialIndex ) {
  6683. this.groups.push( {
  6684. start: start,
  6685. count: count,
  6686. materialIndex: materialIndex !== undefined ? materialIndex : 0
  6687. } );
  6688. },
  6689. clearGroups: function () {
  6690. this.groups = [];
  6691. },
  6692. setDrawRange: function ( start, count ) {
  6693. this.drawRange.start = start;
  6694. this.drawRange.count = count;
  6695. },
  6696. applyMatrix: function ( matrix ) {
  6697. var position = this.attributes.position;
  6698. if ( position !== undefined ) {
  6699. matrix.applyToVector3Array( position.array );
  6700. position.needsUpdate = true;
  6701. }
  6702. var normal = this.attributes.normal;
  6703. if ( normal !== undefined ) {
  6704. var normalMatrix = new THREE.Matrix3().getNormalMatrix( matrix );
  6705. normalMatrix.applyToVector3Array( normal.array );
  6706. normal.needsUpdate = true;
  6707. }
  6708. if ( this.boundingBox !== null ) {
  6709. this.computeBoundingBox();
  6710. }
  6711. if ( this.boundingSphere !== null ) {
  6712. this.computeBoundingSphere();
  6713. }
  6714. return this;
  6715. },
  6716. rotateX: function () {
  6717. // rotate geometry around world x-axis
  6718. var m1;
  6719. return function rotateX( angle ) {
  6720. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  6721. m1.makeRotationX( angle );
  6722. this.applyMatrix( m1 );
  6723. return this;
  6724. };
  6725. }(),
  6726. rotateY: function () {
  6727. // rotate geometry around world y-axis
  6728. var m1;
  6729. return function rotateY( angle ) {
  6730. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  6731. m1.makeRotationY( angle );
  6732. this.applyMatrix( m1 );
  6733. return this;
  6734. };
  6735. }(),
  6736. rotateZ: function () {
  6737. // rotate geometry around world z-axis
  6738. var m1;
  6739. return function rotateZ( angle ) {
  6740. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  6741. m1.makeRotationZ( angle );
  6742. this.applyMatrix( m1 );
  6743. return this;
  6744. };
  6745. }(),
  6746. translate: function () {
  6747. // translate geometry
  6748. var m1;
  6749. return function translate( x, y, z ) {
  6750. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  6751. m1.makeTranslation( x, y, z );
  6752. this.applyMatrix( m1 );
  6753. return this;
  6754. };
  6755. }(),
  6756. scale: function () {
  6757. // scale geometry
  6758. var m1;
  6759. return function scale( x, y, z ) {
  6760. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  6761. m1.makeScale( x, y, z );
  6762. this.applyMatrix( m1 );
  6763. return this;
  6764. };
  6765. }(),
  6766. lookAt: function () {
  6767. var obj;
  6768. return function lookAt( vector ) {
  6769. if ( obj === undefined ) obj = new THREE.Object3D();
  6770. obj.lookAt( vector );
  6771. obj.updateMatrix();
  6772. this.applyMatrix( obj.matrix );
  6773. };
  6774. }(),
  6775. center: function () {
  6776. this.computeBoundingBox();
  6777. var offset = this.boundingBox.center().negate();
  6778. this.translate( offset.x, offset.y, offset.z );
  6779. return offset;
  6780. },
  6781. setFromObject: function ( object ) {
  6782. // console.log( 'THREE.BufferGeometry.setFromObject(). Converting', object, this );
  6783. var geometry = object.geometry;
  6784. if ( object instanceof THREE.Points || object instanceof THREE.Line ) {
  6785. var positions = new THREE.Float32Attribute( geometry.vertices.length * 3, 3 );
  6786. var colors = new THREE.Float32Attribute( geometry.colors.length * 3, 3 );
  6787. this.addAttribute( 'position', positions.copyVector3sArray( geometry.vertices ) );
  6788. this.addAttribute( 'color', colors.copyColorsArray( geometry.colors ) );
  6789. if ( geometry.lineDistances && geometry.lineDistances.length === geometry.vertices.length ) {
  6790. var lineDistances = new THREE.Float32Attribute( geometry.lineDistances.length, 1 );
  6791. this.addAttribute( 'lineDistance', lineDistances.copyArray( geometry.lineDistances ) );
  6792. }
  6793. if ( geometry.boundingSphere !== null ) {
  6794. this.boundingSphere = geometry.boundingSphere.clone();
  6795. }
  6796. if ( geometry.boundingBox !== null ) {
  6797. this.boundingBox = geometry.boundingBox.clone();
  6798. }
  6799. } else if ( object instanceof THREE.Mesh ) {
  6800. if ( geometry instanceof THREE.Geometry ) {
  6801. this.fromGeometry( geometry );
  6802. }
  6803. }
  6804. return this;
  6805. },
  6806. updateFromObject: function ( object ) {
  6807. var geometry = object.geometry;
  6808. if ( object instanceof THREE.Mesh ) {
  6809. var direct = geometry.__directGeometry;
  6810. if ( direct === undefined ) {
  6811. return this.fromGeometry( geometry );
  6812. }
  6813. direct.verticesNeedUpdate = geometry.verticesNeedUpdate;
  6814. direct.normalsNeedUpdate = geometry.normalsNeedUpdate;
  6815. direct.colorsNeedUpdate = geometry.colorsNeedUpdate;
  6816. direct.uvsNeedUpdate = geometry.uvsNeedUpdate;
  6817. direct.groupsNeedUpdate = geometry.groupsNeedUpdate;
  6818. geometry.verticesNeedUpdate = false;
  6819. geometry.normalsNeedUpdate = false;
  6820. geometry.colorsNeedUpdate = false;
  6821. geometry.uvsNeedUpdate = false;
  6822. geometry.groupsNeedUpdate = false;
  6823. geometry = direct;
  6824. }
  6825. if ( geometry.verticesNeedUpdate === true ) {
  6826. var attribute = this.attributes.position;
  6827. if ( attribute !== undefined ) {
  6828. attribute.copyVector3sArray( geometry.vertices );
  6829. attribute.needsUpdate = true;
  6830. }
  6831. geometry.verticesNeedUpdate = false;
  6832. }
  6833. if ( geometry.normalsNeedUpdate === true ) {
  6834. var attribute = this.attributes.normal;
  6835. if ( attribute !== undefined ) {
  6836. attribute.copyVector3sArray( geometry.normals );
  6837. attribute.needsUpdate = true;
  6838. }
  6839. geometry.normalsNeedUpdate = false;
  6840. }
  6841. if ( geometry.colorsNeedUpdate === true ) {
  6842. var attribute = this.attributes.color;
  6843. if ( attribute !== undefined ) {
  6844. attribute.copyColorsArray( geometry.colors );
  6845. attribute.needsUpdate = true;
  6846. }
  6847. geometry.colorsNeedUpdate = false;
  6848. }
  6849. if ( geometry.uvsNeedUpdate ) {
  6850. var attribute = this.attributes.uv;
  6851. if ( attribute !== undefined ) {
  6852. attribute.copyVector2sArray( geometry.uvs );
  6853. attribute.needsUpdate = true;
  6854. }
  6855. geometry.uvsNeedUpdate = false;
  6856. }
  6857. if ( geometry.lineDistancesNeedUpdate ) {
  6858. var attribute = this.attributes.lineDistance;
  6859. if ( attribute !== undefined ) {
  6860. attribute.copyArray( geometry.lineDistances );
  6861. attribute.needsUpdate = true;
  6862. }
  6863. geometry.lineDistancesNeedUpdate = false;
  6864. }
  6865. if ( geometry.groupsNeedUpdate ) {
  6866. geometry.computeGroups( object.geometry );
  6867. this.groups = geometry.groups;
  6868. geometry.groupsNeedUpdate = false;
  6869. }
  6870. return this;
  6871. },
  6872. fromGeometry: function ( geometry ) {
  6873. geometry.__directGeometry = new THREE.DirectGeometry().fromGeometry( geometry );
  6874. return this.fromDirectGeometry( geometry.__directGeometry );
  6875. },
  6876. fromDirectGeometry: function ( geometry ) {
  6877. var positions = new Float32Array( geometry.vertices.length * 3 );
  6878. this.addAttribute( 'position', new THREE.BufferAttribute( positions, 3 ).copyVector3sArray( geometry.vertices ) );
  6879. if ( geometry.normals.length > 0 ) {
  6880. var normals = new Float32Array( geometry.normals.length * 3 );
  6881. this.addAttribute( 'normal', new THREE.BufferAttribute( normals, 3 ).copyVector3sArray( geometry.normals ) );
  6882. }
  6883. if ( geometry.colors.length > 0 ) {
  6884. var colors = new Float32Array( geometry.colors.length * 3 );
  6885. this.addAttribute( 'color', new THREE.BufferAttribute( colors, 3 ).copyColorsArray( geometry.colors ) );
  6886. }
  6887. if ( geometry.uvs.length > 0 ) {
  6888. var uvs = new Float32Array( geometry.uvs.length * 2 );
  6889. this.addAttribute( 'uv', new THREE.BufferAttribute( uvs, 2 ).copyVector2sArray( geometry.uvs ) );
  6890. }
  6891. if ( geometry.uvs2.length > 0 ) {
  6892. var uvs2 = new Float32Array( geometry.uvs2.length * 2 );
  6893. this.addAttribute( 'uv2', new THREE.BufferAttribute( uvs2, 2 ).copyVector2sArray( geometry.uvs2 ) );
  6894. }
  6895. if ( geometry.indices.length > 0 ) {
  6896. var TypeArray = geometry.vertices.length > 65535 ? Uint32Array : Uint16Array;
  6897. var indices = new TypeArray( geometry.indices.length * 3 );
  6898. this.setIndex( new THREE.BufferAttribute( indices, 1 ).copyIndicesArray( geometry.indices ) );
  6899. }
  6900. // groups
  6901. this.groups = geometry.groups;
  6902. // morphs
  6903. for ( var name in geometry.morphTargets ) {
  6904. var array = [];
  6905. var morphTargets = geometry.morphTargets[ name ];
  6906. for ( var i = 0, l = morphTargets.length; i < l; i ++ ) {
  6907. var morphTarget = morphTargets[ i ];
  6908. var attribute = new THREE.Float32Attribute( morphTarget.length * 3, 3 );
  6909. array.push( attribute.copyVector3sArray( morphTarget ) );
  6910. }
  6911. this.morphAttributes[ name ] = array;
  6912. }
  6913. // skinning
  6914. if ( geometry.skinIndices.length > 0 ) {
  6915. var skinIndices = new THREE.Float32Attribute( geometry.skinIndices.length * 4, 4 );
  6916. this.addAttribute( 'skinIndex', skinIndices.copyVector4sArray( geometry.skinIndices ) );
  6917. }
  6918. if ( geometry.skinWeights.length > 0 ) {
  6919. var skinWeights = new THREE.Float32Attribute( geometry.skinWeights.length * 4, 4 );
  6920. this.addAttribute( 'skinWeight', skinWeights.copyVector4sArray( geometry.skinWeights ) );
  6921. }
  6922. //
  6923. if ( geometry.boundingSphere !== null ) {
  6924. this.boundingSphere = geometry.boundingSphere.clone();
  6925. }
  6926. if ( geometry.boundingBox !== null ) {
  6927. this.boundingBox = geometry.boundingBox.clone();
  6928. }
  6929. return this;
  6930. },
  6931. computeBoundingBox: function () {
  6932. if ( this.boundingBox === null ) {
  6933. this.boundingBox = new THREE.Box3();
  6934. }
  6935. var positions = this.attributes.position.array;
  6936. if ( positions !== undefined ) {
  6937. this.boundingBox.setFromArray( positions );
  6938. } else {
  6939. this.boundingBox.makeEmpty();
  6940. }
  6941. if ( isNaN( this.boundingBox.min.x ) || isNaN( this.boundingBox.min.y ) || isNaN( this.boundingBox.min.z ) ) {
  6942. console.error( 'THREE.BufferGeometry.computeBoundingBox: Computed min/max have NaN values. The "position" attribute is likely to have NaN values.', this );
  6943. }
  6944. },
  6945. computeBoundingSphere: function () {
  6946. var box = new THREE.Box3();
  6947. var vector = new THREE.Vector3();
  6948. return function computeBoundingSphere() {
  6949. if ( this.boundingSphere === null ) {
  6950. this.boundingSphere = new THREE.Sphere();
  6951. }
  6952. var positions = this.attributes.position;
  6953. if ( positions ) {
  6954. var array = positions.array;
  6955. var center = this.boundingSphere.center;
  6956. box.setFromArray( array );
  6957. box.center( center );
  6958. // hoping to find a boundingSphere with a radius smaller than the
  6959. // boundingSphere of the boundingBox: sqrt(3) smaller in the best case
  6960. var maxRadiusSq = 0;
  6961. for ( var i = 0, il = array.length; i < il; i += 3 ) {
  6962. vector.fromArray( array, i );
  6963. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( vector ) );
  6964. }
  6965. this.boundingSphere.radius = Math.sqrt( maxRadiusSq );
  6966. if ( isNaN( this.boundingSphere.radius ) ) {
  6967. console.error( 'THREE.BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.', this );
  6968. }
  6969. }
  6970. };
  6971. }(),
  6972. computeFaceNormals: function () {
  6973. // backwards compatibility
  6974. },
  6975. computeVertexNormals: function () {
  6976. var index = this.index;
  6977. var attributes = this.attributes;
  6978. var groups = this.groups;
  6979. if ( attributes.position ) {
  6980. var positions = attributes.position.array;
  6981. if ( attributes.normal === undefined ) {
  6982. this.addAttribute( 'normal', new THREE.BufferAttribute( new Float32Array( positions.length ), 3 ) );
  6983. } else {
  6984. // reset existing normals to zero
  6985. var array = attributes.normal.array;
  6986. for ( var i = 0, il = array.length; i < il; i ++ ) {
  6987. array[ i ] = 0;
  6988. }
  6989. }
  6990. var normals = attributes.normal.array;
  6991. var vA, vB, vC,
  6992. pA = new THREE.Vector3(),
  6993. pB = new THREE.Vector3(),
  6994. pC = new THREE.Vector3(),
  6995. cb = new THREE.Vector3(),
  6996. ab = new THREE.Vector3();
  6997. // indexed elements
  6998. if ( index ) {
  6999. var indices = index.array;
  7000. if ( groups.length === 0 ) {
  7001. this.addGroup( 0, indices.length );
  7002. }
  7003. for ( var j = 0, jl = groups.length; j < jl; ++ j ) {
  7004. var group = groups[ j ];
  7005. var start = group.start;
  7006. var count = group.count;
  7007. for ( var i = start, il = start + count; i < il; i += 3 ) {
  7008. vA = indices[ i + 0 ] * 3;
  7009. vB = indices[ i + 1 ] * 3;
  7010. vC = indices[ i + 2 ] * 3;
  7011. pA.fromArray( positions, vA );
  7012. pB.fromArray( positions, vB );
  7013. pC.fromArray( positions, vC );
  7014. cb.subVectors( pC, pB );
  7015. ab.subVectors( pA, pB );
  7016. cb.cross( ab );
  7017. normals[ vA ] += cb.x;
  7018. normals[ vA + 1 ] += cb.y;
  7019. normals[ vA + 2 ] += cb.z;
  7020. normals[ vB ] += cb.x;
  7021. normals[ vB + 1 ] += cb.y;
  7022. normals[ vB + 2 ] += cb.z;
  7023. normals[ vC ] += cb.x;
  7024. normals[ vC + 1 ] += cb.y;
  7025. normals[ vC + 2 ] += cb.z;
  7026. }
  7027. }
  7028. } else {
  7029. // non-indexed elements (unconnected triangle soup)
  7030. for ( var i = 0, il = positions.length; i < il; i += 9 ) {
  7031. pA.fromArray( positions, i );
  7032. pB.fromArray( positions, i + 3 );
  7033. pC.fromArray( positions, i + 6 );
  7034. cb.subVectors( pC, pB );
  7035. ab.subVectors( pA, pB );
  7036. cb.cross( ab );
  7037. normals[ i ] = cb.x;
  7038. normals[ i + 1 ] = cb.y;
  7039. normals[ i + 2 ] = cb.z;
  7040. normals[ i + 3 ] = cb.x;
  7041. normals[ i + 4 ] = cb.y;
  7042. normals[ i + 5 ] = cb.z;
  7043. normals[ i + 6 ] = cb.x;
  7044. normals[ i + 7 ] = cb.y;
  7045. normals[ i + 8 ] = cb.z;
  7046. }
  7047. }
  7048. this.normalizeNormals();
  7049. attributes.normal.needsUpdate = true;
  7050. }
  7051. },
  7052. merge: function ( geometry, offset ) {
  7053. if ( geometry instanceof THREE.BufferGeometry === false ) {
  7054. console.error( 'THREE.BufferGeometry.merge(): geometry not an instance of THREE.BufferGeometry.', geometry );
  7055. return;
  7056. }
  7057. if ( offset === undefined ) offset = 0;
  7058. var attributes = this.attributes;
  7059. for ( var key in attributes ) {
  7060. if ( geometry.attributes[ key ] === undefined ) continue;
  7061. var attribute1 = attributes[ key ];
  7062. var attributeArray1 = attribute1.array;
  7063. var attribute2 = geometry.attributes[ key ];
  7064. var attributeArray2 = attribute2.array;
  7065. var attributeSize = attribute2.itemSize;
  7066. for ( var i = 0, j = attributeSize * offset; i < attributeArray2.length; i ++, j ++ ) {
  7067. attributeArray1[ j ] = attributeArray2[ i ];
  7068. }
  7069. }
  7070. return this;
  7071. },
  7072. normalizeNormals: function () {
  7073. var normals = this.attributes.normal.array;
  7074. var x, y, z, n;
  7075. for ( var i = 0, il = normals.length; i < il; i += 3 ) {
  7076. x = normals[ i ];
  7077. y = normals[ i + 1 ];
  7078. z = normals[ i + 2 ];
  7079. n = 1.0 / Math.sqrt( x * x + y * y + z * z );
  7080. normals[ i ] *= n;
  7081. normals[ i + 1 ] *= n;
  7082. normals[ i + 2 ] *= n;
  7083. }
  7084. },
  7085. toNonIndexed: function () {
  7086. if ( this.index === null ) {
  7087. console.warn( 'THREE.BufferGeometry.toNonIndexed(): Geometry is already non-indexed.' );
  7088. return this;
  7089. }
  7090. var geometry2 = new THREE.BufferGeometry();
  7091. var indices = this.index.array;
  7092. var attributes = this.attributes;
  7093. for ( var name in attributes ) {
  7094. var attribute = attributes[ name ];
  7095. var array = attribute.array;
  7096. var itemSize = attribute.itemSize;
  7097. var array2 = new array.constructor( indices.length * itemSize );
  7098. var index = 0, index2 = 0;
  7099. for ( var i = 0, l = indices.length; i < l; i ++ ) {
  7100. index = indices[ i ] * itemSize;
  7101. for ( var j = 0; j < itemSize; j ++ ) {
  7102. array2[ index2 ++ ] = array[ index ++ ];
  7103. }
  7104. }
  7105. geometry2.addAttribute( name, new THREE.BufferAttribute( array2, itemSize ) );
  7106. }
  7107. return geometry2;
  7108. },
  7109. toJSON: function () {
  7110. var data = {
  7111. metadata: {
  7112. version: 4.4,
  7113. type: 'BufferGeometry',
  7114. generator: 'BufferGeometry.toJSON'
  7115. }
  7116. };
  7117. // standard BufferGeometry serialization
  7118. data.uuid = this.uuid;
  7119. data.type = this.type;
  7120. if ( this.name !== '' ) data.name = this.name;
  7121. if ( this.parameters !== undefined ) {
  7122. var parameters = this.parameters;
  7123. for ( var key in parameters ) {
  7124. if ( parameters[ key ] !== undefined ) data[ key ] = parameters[ key ];
  7125. }
  7126. return data;
  7127. }
  7128. data.data = { attributes: {} };
  7129. var index = this.index;
  7130. if ( index !== null ) {
  7131. var array = Array.prototype.slice.call( index.array );
  7132. data.data.index = {
  7133. type: index.array.constructor.name,
  7134. array: array
  7135. };
  7136. }
  7137. var attributes = this.attributes;
  7138. for ( var key in attributes ) {
  7139. var attribute = attributes[ key ];
  7140. var array = Array.prototype.slice.call( attribute.array );
  7141. data.data.attributes[ key ] = {
  7142. itemSize: attribute.itemSize,
  7143. type: attribute.array.constructor.name,
  7144. array: array,
  7145. normalized: attribute.normalized
  7146. };
  7147. }
  7148. var groups = this.groups;
  7149. if ( groups.length > 0 ) {
  7150. data.data.groups = JSON.parse( JSON.stringify( groups ) );
  7151. }
  7152. var boundingSphere = this.boundingSphere;
  7153. if ( boundingSphere !== null ) {
  7154. data.data.boundingSphere = {
  7155. center: boundingSphere.center.toArray(),
  7156. radius: boundingSphere.radius
  7157. };
  7158. }
  7159. return data;
  7160. },
  7161. clone: function () {
  7162. /*
  7163. // Handle primitives
  7164. var parameters = this.parameters;
  7165. if ( parameters !== undefined ) {
  7166. var values = [];
  7167. for ( var key in parameters ) {
  7168. values.push( parameters[ key ] );
  7169. }
  7170. var geometry = Object.create( this.constructor.prototype );
  7171. this.constructor.apply( geometry, values );
  7172. return geometry;
  7173. }
  7174. return new this.constructor().copy( this );
  7175. */
  7176. return new THREE.BufferGeometry().copy( this );
  7177. },
  7178. copy: function ( source ) {
  7179. var index = source.index;
  7180. if ( index !== null ) {
  7181. this.setIndex( index.clone() );
  7182. }
  7183. var attributes = source.attributes;
  7184. for ( var name in attributes ) {
  7185. var attribute = attributes[ name ];
  7186. this.addAttribute( name, attribute.clone() );
  7187. }
  7188. var groups = source.groups;
  7189. for ( var i = 0, l = groups.length; i < l; i ++ ) {
  7190. var group = groups[ i ];
  7191. this.addGroup( group.start, group.count, group.materialIndex );
  7192. }
  7193. return this;
  7194. },
  7195. dispose: function () {
  7196. this.dispatchEvent( { type: 'dispose' } );
  7197. }
  7198. } );
  7199. THREE.BufferGeometry.MaxIndex = 65535;
  7200. // File:src/core/InstancedBufferGeometry.js
  7201. /**
  7202. * @author benaadams / https://twitter.com/ben_a_adams
  7203. */
  7204. THREE.InstancedBufferGeometry = function () {
  7205. THREE.BufferGeometry.call( this );
  7206. this.type = 'InstancedBufferGeometry';
  7207. this.maxInstancedCount = undefined;
  7208. };
  7209. THREE.InstancedBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  7210. THREE.InstancedBufferGeometry.prototype.constructor = THREE.InstancedBufferGeometry;
  7211. THREE.InstancedBufferGeometry.prototype.addGroup = function ( start, count, instances ) {
  7212. this.groups.push( {
  7213. start: start,
  7214. count: count,
  7215. instances: instances
  7216. } );
  7217. };
  7218. THREE.InstancedBufferGeometry.prototype.copy = function ( source ) {
  7219. var index = source.index;
  7220. if ( index !== null ) {
  7221. this.setIndex( index.clone() );
  7222. }
  7223. var attributes = source.attributes;
  7224. for ( var name in attributes ) {
  7225. var attribute = attributes[ name ];
  7226. this.addAttribute( name, attribute.clone() );
  7227. }
  7228. var groups = source.groups;
  7229. for ( var i = 0, l = groups.length; i < l; i ++ ) {
  7230. var group = groups[ i ];
  7231. this.addGroup( group.start, group.count, group.instances );
  7232. }
  7233. return this;
  7234. };
  7235. // File:src/core/Uniform.js
  7236. /**
  7237. * @author mrdoob / http://mrdoob.com/
  7238. */
  7239. THREE.Uniform = function ( value ) {
  7240. if ( typeof value === 'string' ) {
  7241. console.warn( 'THREE.Uniform: Type parameter is no longer needed.' );
  7242. value = arguments[ 1 ];
  7243. }
  7244. this.value = value;
  7245. this.dynamic = false;
  7246. };
  7247. THREE.Uniform.prototype = {
  7248. constructor: THREE.Uniform,
  7249. onUpdate: function ( callback ) {
  7250. this.dynamic = true;
  7251. this.onUpdateCallback = callback;
  7252. return this;
  7253. }
  7254. };
  7255. // File:src/animation/AnimationAction.js
  7256. /**
  7257. *
  7258. * Action provided by AnimationMixer for scheduling clip playback on specific
  7259. * objects.
  7260. *
  7261. * @author Ben Houston / http://clara.io/
  7262. * @author David Sarno / http://lighthaus.us/
  7263. * @author tschw
  7264. *
  7265. */
  7266. THREE.AnimationAction = function() {
  7267. throw new Error( "THREE.AnimationAction: " +
  7268. "Use mixer.clipAction for construction." );
  7269. };
  7270. THREE.AnimationAction._new =
  7271. function AnimationAction( mixer, clip, localRoot ) {
  7272. this._mixer = mixer;
  7273. this._clip = clip;
  7274. this._localRoot = localRoot || null;
  7275. var tracks = clip.tracks,
  7276. nTracks = tracks.length,
  7277. interpolants = new Array( nTracks );
  7278. var interpolantSettings = {
  7279. endingStart: THREE.ZeroCurvatureEnding,
  7280. endingEnd: THREE.ZeroCurvatureEnding
  7281. };
  7282. for ( var i = 0; i !== nTracks; ++ i ) {
  7283. var interpolant = tracks[ i ].createInterpolant( null );
  7284. interpolants[ i ] = interpolant;
  7285. interpolant.settings = interpolantSettings;
  7286. }
  7287. this._interpolantSettings = interpolantSettings;
  7288. this._interpolants = interpolants; // bound by the mixer
  7289. // inside: PropertyMixer (managed by the mixer)
  7290. this._propertyBindings = new Array( nTracks );
  7291. this._cacheIndex = null; // for the memory manager
  7292. this._byClipCacheIndex = null; // for the memory manager
  7293. this._timeScaleInterpolant = null;
  7294. this._weightInterpolant = null;
  7295. this.loop = THREE.LoopRepeat;
  7296. this._loopCount = -1;
  7297. // global mixer time when the action is to be started
  7298. // it's set back to 'null' upon start of the action
  7299. this._startTime = null;
  7300. // scaled local time of the action
  7301. // gets clamped or wrapped to 0..clip.duration according to loop
  7302. this.time = 0;
  7303. this.timeScale = 1;
  7304. this._effectiveTimeScale = 1;
  7305. this.weight = 1;
  7306. this._effectiveWeight = 1;
  7307. this.repetitions = Infinity; // no. of repetitions when looping
  7308. this.paused = false; // false -> zero effective time scale
  7309. this.enabled = true; // true -> zero effective weight
  7310. this.clampWhenFinished = false; // keep feeding the last frame?
  7311. this.zeroSlopeAtStart = true; // for smooth interpolation w/o separate
  7312. this.zeroSlopeAtEnd = true; // clips for start, loop and end
  7313. };
  7314. THREE.AnimationAction._new.prototype = {
  7315. constructor: THREE.AnimationAction._new,
  7316. // State & Scheduling
  7317. play: function() {
  7318. this._mixer._activateAction( this );
  7319. return this;
  7320. },
  7321. stop: function() {
  7322. this._mixer._deactivateAction( this );
  7323. return this.reset();
  7324. },
  7325. reset: function() {
  7326. this.paused = false;
  7327. this.enabled = true;
  7328. this.time = 0; // restart clip
  7329. this._loopCount = -1; // forget previous loops
  7330. this._startTime = null; // forget scheduling
  7331. return this.stopFading().stopWarping();
  7332. },
  7333. isRunning: function() {
  7334. var start = this._startTime;
  7335. return this.enabled && ! this.paused && this.timeScale !== 0 &&
  7336. this._startTime === null && this._mixer._isActiveAction( this );
  7337. },
  7338. // return true when play has been called
  7339. isScheduled: function() {
  7340. return this._mixer._isActiveAction( this );
  7341. },
  7342. startAt: function( time ) {
  7343. this._startTime = time;
  7344. return this;
  7345. },
  7346. setLoop: function( mode, repetitions ) {
  7347. this.loop = mode;
  7348. this.repetitions = repetitions;
  7349. return this;
  7350. },
  7351. // Weight
  7352. // set the weight stopping any scheduled fading
  7353. // although .enabled = false yields an effective weight of zero, this
  7354. // method does *not* change .enabled, because it would be confusing
  7355. setEffectiveWeight: function( weight ) {
  7356. this.weight = weight;
  7357. // note: same logic as when updated at runtime
  7358. this._effectiveWeight = this.enabled ? weight : 0;
  7359. return this.stopFading();
  7360. },
  7361. // return the weight considering fading and .enabled
  7362. getEffectiveWeight: function() {
  7363. return this._effectiveWeight;
  7364. },
  7365. fadeIn: function( duration ) {
  7366. return this._scheduleFading( duration, 0, 1 );
  7367. },
  7368. fadeOut: function( duration ) {
  7369. return this._scheduleFading( duration, 1, 0 );
  7370. },
  7371. crossFadeFrom: function( fadeOutAction, duration, warp ) {
  7372. var mixer = this._mixer;
  7373. fadeOutAction.fadeOut( duration );
  7374. this.fadeIn( duration );
  7375. if( warp ) {
  7376. var fadeInDuration = this._clip.duration,
  7377. fadeOutDuration = fadeOutAction._clip.duration,
  7378. startEndRatio = fadeOutDuration / fadeInDuration,
  7379. endStartRatio = fadeInDuration / fadeOutDuration;
  7380. fadeOutAction.warp( 1.0, startEndRatio, duration );
  7381. this.warp( endStartRatio, 1.0, duration );
  7382. }
  7383. return this;
  7384. },
  7385. crossFadeTo: function( fadeInAction, duration, warp ) {
  7386. return fadeInAction.crossFadeFrom( this, duration, warp );
  7387. },
  7388. stopFading: function() {
  7389. var weightInterpolant = this._weightInterpolant;
  7390. if ( weightInterpolant !== null ) {
  7391. this._weightInterpolant = null;
  7392. this._mixer._takeBackControlInterpolant( weightInterpolant );
  7393. }
  7394. return this;
  7395. },
  7396. // Time Scale Control
  7397. // set the weight stopping any scheduled warping
  7398. // although .paused = true yields an effective time scale of zero, this
  7399. // method does *not* change .paused, because it would be confusing
  7400. setEffectiveTimeScale: function( timeScale ) {
  7401. this.timeScale = timeScale;
  7402. this._effectiveTimeScale = this.paused ? 0 :timeScale;
  7403. return this.stopWarping();
  7404. },
  7405. // return the time scale considering warping and .paused
  7406. getEffectiveTimeScale: function() {
  7407. return this._effectiveTimeScale;
  7408. },
  7409. setDuration: function( duration ) {
  7410. this.timeScale = this._clip.duration / duration;
  7411. return this.stopWarping();
  7412. },
  7413. syncWith: function( action ) {
  7414. this.time = action.time;
  7415. this.timeScale = action.timeScale;
  7416. return this.stopWarping();
  7417. },
  7418. halt: function( duration ) {
  7419. return this.warp( this._effectiveTimeScale, 0, duration );
  7420. },
  7421. warp: function( startTimeScale, endTimeScale, duration ) {
  7422. var mixer = this._mixer, now = mixer.time,
  7423. interpolant = this._timeScaleInterpolant,
  7424. timeScale = this.timeScale;
  7425. if ( interpolant === null ) {
  7426. interpolant = mixer._lendControlInterpolant(),
  7427. this._timeScaleInterpolant = interpolant;
  7428. }
  7429. var times = interpolant.parameterPositions,
  7430. values = interpolant.sampleValues;
  7431. times[ 0 ] = now;
  7432. times[ 1 ] = now + duration;
  7433. values[ 0 ] = startTimeScale / timeScale;
  7434. values[ 1 ] = endTimeScale / timeScale;
  7435. return this;
  7436. },
  7437. stopWarping: function() {
  7438. var timeScaleInterpolant = this._timeScaleInterpolant;
  7439. if ( timeScaleInterpolant !== null ) {
  7440. this._timeScaleInterpolant = null;
  7441. this._mixer._takeBackControlInterpolant( timeScaleInterpolant );
  7442. }
  7443. return this;
  7444. },
  7445. // Object Accessors
  7446. getMixer: function() {
  7447. return this._mixer;
  7448. },
  7449. getClip: function() {
  7450. return this._clip;
  7451. },
  7452. getRoot: function() {
  7453. return this._localRoot || this._mixer._root;
  7454. },
  7455. // Interna
  7456. _update: function( time, deltaTime, timeDirection, accuIndex ) {
  7457. // called by the mixer
  7458. var startTime = this._startTime;
  7459. if ( startTime !== null ) {
  7460. // check for scheduled start of action
  7461. var timeRunning = ( time - startTime ) * timeDirection;
  7462. if ( timeRunning < 0 || timeDirection === 0 ) {
  7463. return; // yet to come / don't decide when delta = 0
  7464. }
  7465. // start
  7466. this._startTime = null; // unschedule
  7467. deltaTime = timeDirection * timeRunning;
  7468. }
  7469. // apply time scale and advance time
  7470. deltaTime *= this._updateTimeScale( time );
  7471. var clipTime = this._updateTime( deltaTime );
  7472. // note: _updateTime may disable the action resulting in
  7473. // an effective weight of 0
  7474. var weight = this._updateWeight( time );
  7475. if ( weight > 0 ) {
  7476. var interpolants = this._interpolants;
  7477. var propertyMixers = this._propertyBindings;
  7478. for ( var j = 0, m = interpolants.length; j !== m; ++ j ) {
  7479. interpolants[ j ].evaluate( clipTime );
  7480. propertyMixers[ j ].accumulate( accuIndex, weight );
  7481. }
  7482. }
  7483. },
  7484. _updateWeight: function( time ) {
  7485. var weight = 0;
  7486. if ( this.enabled ) {
  7487. weight = this.weight;
  7488. var interpolant = this._weightInterpolant;
  7489. if ( interpolant !== null ) {
  7490. var interpolantValue = interpolant.evaluate( time )[ 0 ];
  7491. weight *= interpolantValue;
  7492. if ( time > interpolant.parameterPositions[ 1 ] ) {
  7493. this.stopFading();
  7494. if ( interpolantValue === 0 ) {
  7495. // faded out, disable
  7496. this.enabled = false;
  7497. }
  7498. }
  7499. }
  7500. }
  7501. this._effectiveWeight = weight;
  7502. return weight;
  7503. },
  7504. _updateTimeScale: function( time ) {
  7505. var timeScale = 0;
  7506. if ( ! this.paused ) {
  7507. timeScale = this.timeScale;
  7508. var interpolant = this._timeScaleInterpolant;
  7509. if ( interpolant !== null ) {
  7510. var interpolantValue = interpolant.evaluate( time )[ 0 ];
  7511. timeScale *= interpolantValue;
  7512. if ( time > interpolant.parameterPositions[ 1 ] ) {
  7513. this.stopWarping();
  7514. if ( timeScale === 0 ) {
  7515. // motion has halted, pause
  7516. this.paused = true;
  7517. } else {
  7518. // warp done - apply final time scale
  7519. this.timeScale = timeScale;
  7520. }
  7521. }
  7522. }
  7523. }
  7524. this._effectiveTimeScale = timeScale;
  7525. return timeScale;
  7526. },
  7527. _updateTime: function( deltaTime ) {
  7528. var time = this.time + deltaTime;
  7529. if ( deltaTime === 0 ) return time;
  7530. var duration = this._clip.duration,
  7531. loop = this.loop,
  7532. loopCount = this._loopCount;
  7533. if ( loop === THREE.LoopOnce ) {
  7534. if ( loopCount === -1 ) {
  7535. // just started
  7536. this.loopCount = 0;
  7537. this._setEndings( true, true, false );
  7538. }
  7539. handle_stop: {
  7540. if ( time >= duration ) {
  7541. time = duration;
  7542. } else if ( time < 0 ) {
  7543. time = 0;
  7544. } else break handle_stop;
  7545. if ( this.clampWhenFinished ) this.paused = true;
  7546. else this.enabled = false;
  7547. this._mixer.dispatchEvent( {
  7548. type: 'finished', action: this,
  7549. direction: deltaTime < 0 ? -1 : 1
  7550. } );
  7551. }
  7552. } else { // repetitive Repeat or PingPong
  7553. var pingPong = ( loop === THREE.LoopPingPong );
  7554. if ( loopCount === -1 ) {
  7555. // just started
  7556. if ( deltaTime >= 0 ) {
  7557. loopCount = 0;
  7558. this._setEndings(
  7559. true, this.repetitions === 0, pingPong );
  7560. } else {
  7561. // when looping in reverse direction, the initial
  7562. // transition through zero counts as a repetition,
  7563. // so leave loopCount at -1
  7564. this._setEndings(
  7565. this.repetitions === 0, true, pingPong );
  7566. }
  7567. }
  7568. if ( time >= duration || time < 0 ) {
  7569. // wrap around
  7570. var loopDelta = Math.floor( time / duration ); // signed
  7571. time -= duration * loopDelta;
  7572. loopCount += Math.abs( loopDelta );
  7573. var pending = this.repetitions - loopCount;
  7574. if ( pending < 0 ) {
  7575. // have to stop (switch state, clamp time, fire event)
  7576. if ( this.clampWhenFinished ) this.paused = true;
  7577. else this.enabled = false;
  7578. time = deltaTime > 0 ? duration : 0;
  7579. this._mixer.dispatchEvent( {
  7580. type: 'finished', action: this,
  7581. direction: deltaTime > 0 ? 1 : -1
  7582. } );
  7583. } else {
  7584. // keep running
  7585. if ( pending === 0 ) {
  7586. // entering the last round
  7587. var atStart = deltaTime < 0;
  7588. this._setEndings( atStart, ! atStart, pingPong );
  7589. } else {
  7590. this._setEndings( false, false, pingPong );
  7591. }
  7592. this._loopCount = loopCount;
  7593. this._mixer.dispatchEvent( {
  7594. type: 'loop', action: this, loopDelta: loopDelta
  7595. } );
  7596. }
  7597. }
  7598. if ( pingPong && ( loopCount & 1 ) === 1 ) {
  7599. // invert time for the "pong round"
  7600. this.time = time;
  7601. return duration - time;
  7602. }
  7603. }
  7604. this.time = time;
  7605. return time;
  7606. },
  7607. _setEndings: function( atStart, atEnd, pingPong ) {
  7608. var settings = this._interpolantSettings;
  7609. if ( pingPong ) {
  7610. settings.endingStart = THREE.ZeroSlopeEnding;
  7611. settings.endingEnd = THREE.ZeroSlopeEnding;
  7612. } else {
  7613. // assuming for LoopOnce atStart == atEnd == true
  7614. if ( atStart ) {
  7615. settings.endingStart = this.zeroSlopeAtStart ?
  7616. THREE.ZeroSlopeEnding : THREE.ZeroCurvatureEnding;
  7617. } else {
  7618. settings.endingStart = THREE.WrapAroundEnding;
  7619. }
  7620. if ( atEnd ) {
  7621. settings.endingEnd = this.zeroSlopeAtEnd ?
  7622. THREE.ZeroSlopeEnding : THREE.ZeroCurvatureEnding;
  7623. } else {
  7624. settings.endingEnd = THREE.WrapAroundEnding;
  7625. }
  7626. }
  7627. },
  7628. _scheduleFading: function( duration, weightNow, weightThen ) {
  7629. var mixer = this._mixer, now = mixer.time,
  7630. interpolant = this._weightInterpolant;
  7631. if ( interpolant === null ) {
  7632. interpolant = mixer._lendControlInterpolant(),
  7633. this._weightInterpolant = interpolant;
  7634. }
  7635. var times = interpolant.parameterPositions,
  7636. values = interpolant.sampleValues;
  7637. times[ 0 ] = now; values[ 0 ] = weightNow;
  7638. times[ 1 ] = now + duration; values[ 1 ] = weightThen;
  7639. return this;
  7640. }
  7641. };
  7642. // File:src/animation/AnimationClip.js
  7643. /**
  7644. *
  7645. * Reusable set of Tracks that represent an animation.
  7646. *
  7647. * @author Ben Houston / http://clara.io/
  7648. * @author David Sarno / http://lighthaus.us/
  7649. */
  7650. THREE.AnimationClip = function ( name, duration, tracks ) {
  7651. this.name = name;
  7652. this.tracks = tracks;
  7653. this.duration = ( duration !== undefined ) ? duration : -1;
  7654. this.uuid = THREE.Math.generateUUID();
  7655. // this means it should figure out its duration by scanning the tracks
  7656. if ( this.duration < 0 ) {
  7657. this.resetDuration();
  7658. }
  7659. // maybe only do these on demand, as doing them here could potentially slow down loading
  7660. // but leaving these here during development as this ensures a lot of testing of these functions
  7661. this.trim();
  7662. this.optimize();
  7663. };
  7664. THREE.AnimationClip.prototype = {
  7665. constructor: THREE.AnimationClip,
  7666. resetDuration: function() {
  7667. var tracks = this.tracks,
  7668. duration = 0;
  7669. for ( var i = 0, n = tracks.length; i !== n; ++ i ) {
  7670. var track = this.tracks[ i ];
  7671. duration = Math.max(
  7672. duration, track.times[ track.times.length - 1 ] );
  7673. }
  7674. this.duration = duration;
  7675. },
  7676. trim: function() {
  7677. for ( var i = 0; i < this.tracks.length; i ++ ) {
  7678. this.tracks[ i ].trim( 0, this.duration );
  7679. }
  7680. return this;
  7681. },
  7682. optimize: function() {
  7683. for ( var i = 0; i < this.tracks.length; i ++ ) {
  7684. this.tracks[ i ].optimize();
  7685. }
  7686. return this;
  7687. }
  7688. };
  7689. // Static methods:
  7690. Object.assign( THREE.AnimationClip, {
  7691. parse: function( json ) {
  7692. var tracks = [],
  7693. jsonTracks = json.tracks,
  7694. frameTime = 1.0 / ( json.fps || 1.0 );
  7695. for ( var i = 0, n = jsonTracks.length; i !== n; ++ i ) {
  7696. tracks.push( THREE.KeyframeTrack.parse( jsonTracks[ i ] ).scale( frameTime ) );
  7697. }
  7698. return new THREE.AnimationClip( json.name, json.duration, tracks );
  7699. },
  7700. toJSON: function( clip ) {
  7701. var tracks = [],
  7702. clipTracks = clip.tracks;
  7703. var json = {
  7704. 'name': clip.name,
  7705. 'duration': clip.duration,
  7706. 'tracks': tracks
  7707. };
  7708. for ( var i = 0, n = clipTracks.length; i !== n; ++ i ) {
  7709. tracks.push( THREE.KeyframeTrack.toJSON( clipTracks[ i ] ) );
  7710. }
  7711. return json;
  7712. },
  7713. CreateFromMorphTargetSequence: function( name, morphTargetSequence, fps, noLoop ) {
  7714. var numMorphTargets = morphTargetSequence.length;
  7715. var tracks = [];
  7716. for ( var i = 0; i < numMorphTargets; i ++ ) {
  7717. var times = [];
  7718. var values = [];
  7719. times.push(
  7720. ( i + numMorphTargets - 1 ) % numMorphTargets,
  7721. i,
  7722. ( i + 1 ) % numMorphTargets );
  7723. values.push( 0, 1, 0 );
  7724. var order = THREE.AnimationUtils.getKeyframeOrder( times );
  7725. times = THREE.AnimationUtils.sortedArray( times, 1, order );
  7726. values = THREE.AnimationUtils.sortedArray( values, 1, order );
  7727. // if there is a key at the first frame, duplicate it as the
  7728. // last frame as well for perfect loop.
  7729. if ( ! noLoop && times[ 0 ] === 0 ) {
  7730. times.push( numMorphTargets );
  7731. values.push( values[ 0 ] );
  7732. }
  7733. tracks.push(
  7734. new THREE.NumberKeyframeTrack(
  7735. '.morphTargetInfluences[' + morphTargetSequence[ i ].name + ']',
  7736. times, values
  7737. ).scale( 1.0 / fps ) );
  7738. }
  7739. return new THREE.AnimationClip( name, -1, tracks );
  7740. },
  7741. findByName: function( objectOrClipArray, name ) {
  7742. var clipArray = objectOrClipArray;
  7743. if ( ! Array.isArray( objectOrClipArray ) ) {
  7744. var o = objectOrClipArray;
  7745. clipArray = o.geometry && o.geometry.animations || o.animations;
  7746. }
  7747. for ( var i = 0; i < clipArray.length; i ++ ) {
  7748. if ( clipArray[ i ].name === name ) {
  7749. return clipArray[ i ];
  7750. }
  7751. }
  7752. return null;
  7753. },
  7754. CreateClipsFromMorphTargetSequences: function( morphTargets, fps, noLoop ) {
  7755. var animationToMorphTargets = {};
  7756. // tested with https://regex101.com/ on trick sequences
  7757. // such flamingo_flyA_003, flamingo_run1_003, crdeath0059
  7758. var pattern = /^([\w-]*?)([\d]+)$/;
  7759. // sort morph target names into animation groups based
  7760. // patterns like Walk_001, Walk_002, Run_001, Run_002
  7761. for ( var i = 0, il = morphTargets.length; i < il; i ++ ) {
  7762. var morphTarget = morphTargets[ i ];
  7763. var parts = morphTarget.name.match( pattern );
  7764. if ( parts && parts.length > 1 ) {
  7765. var name = parts[ 1 ];
  7766. var animationMorphTargets = animationToMorphTargets[ name ];
  7767. if ( ! animationMorphTargets ) {
  7768. animationToMorphTargets[ name ] = animationMorphTargets = [];
  7769. }
  7770. animationMorphTargets.push( morphTarget );
  7771. }
  7772. }
  7773. var clips = [];
  7774. for ( var name in animationToMorphTargets ) {
  7775. clips.push( THREE.AnimationClip.CreateFromMorphTargetSequence( name, animationToMorphTargets[ name ], fps, noLoop ) );
  7776. }
  7777. return clips;
  7778. },
  7779. // parse the animation.hierarchy format
  7780. parseAnimation: function( animation, bones, nodeName ) {
  7781. if ( ! animation ) {
  7782. console.error( " no animation in JSONLoader data" );
  7783. return null;
  7784. }
  7785. var addNonemptyTrack = function(
  7786. trackType, trackName, animationKeys, propertyName, destTracks ) {
  7787. // only return track if there are actually keys.
  7788. if ( animationKeys.length !== 0 ) {
  7789. var times = [];
  7790. var values = [];
  7791. THREE.AnimationUtils.flattenJSON(
  7792. animationKeys, times, values, propertyName );
  7793. // empty keys are filtered out, so check again
  7794. if ( times.length !== 0 ) {
  7795. destTracks.push( new trackType( trackName, times, values ) );
  7796. }
  7797. }
  7798. };
  7799. var tracks = [];
  7800. var clipName = animation.name || 'default';
  7801. // automatic length determination in AnimationClip.
  7802. var duration = animation.length || -1;
  7803. var fps = animation.fps || 30;
  7804. var hierarchyTracks = animation.hierarchy || [];
  7805. for ( var h = 0; h < hierarchyTracks.length; h ++ ) {
  7806. var animationKeys = hierarchyTracks[ h ].keys;
  7807. // skip empty tracks
  7808. if ( ! animationKeys || animationKeys.length === 0 ) continue;
  7809. // process morph targets in a way exactly compatible
  7810. // with AnimationHandler.init( animation )
  7811. if ( animationKeys[0].morphTargets ) {
  7812. // figure out all morph targets used in this track
  7813. var morphTargetNames = {};
  7814. for ( var k = 0; k < animationKeys.length; k ++ ) {
  7815. if ( animationKeys[k].morphTargets ) {
  7816. for ( var m = 0; m < animationKeys[k].morphTargets.length; m ++ ) {
  7817. morphTargetNames[ animationKeys[k].morphTargets[m] ] = -1;
  7818. }
  7819. }
  7820. }
  7821. // create a track for each morph target with all zero
  7822. // morphTargetInfluences except for the keys in which
  7823. // the morphTarget is named.
  7824. for ( var morphTargetName in morphTargetNames ) {
  7825. var times = [];
  7826. var values = [];
  7827. for ( var m = 0;
  7828. m !== animationKeys[k].morphTargets.length; ++ m ) {
  7829. var animationKey = animationKeys[k];
  7830. times.push( animationKey.time );
  7831. values.push( ( animationKey.morphTarget === morphTargetName ) ? 1 : 0 );
  7832. }
  7833. tracks.push( new THREE.NumberKeyframeTrack(
  7834. '.morphTargetInfluence[' + morphTargetName + ']', times, values ) );
  7835. }
  7836. duration = morphTargetNames.length * ( fps || 1.0 );
  7837. } else {
  7838. // ...assume skeletal animation
  7839. var boneName = '.bones[' + bones[ h ].name + ']';
  7840. addNonemptyTrack(
  7841. THREE.VectorKeyframeTrack, boneName + '.position',
  7842. animationKeys, 'pos', tracks );
  7843. addNonemptyTrack(
  7844. THREE.QuaternionKeyframeTrack, boneName + '.quaternion',
  7845. animationKeys, 'rot', tracks );
  7846. addNonemptyTrack(
  7847. THREE.VectorKeyframeTrack, boneName + '.scale',
  7848. animationKeys, 'scl', tracks );
  7849. }
  7850. }
  7851. if ( tracks.length === 0 ) {
  7852. return null;
  7853. }
  7854. var clip = new THREE.AnimationClip( clipName, duration, tracks );
  7855. return clip;
  7856. }
  7857. } );
  7858. // File:src/animation/AnimationMixer.js
  7859. /**
  7860. *
  7861. * Player for AnimationClips.
  7862. *
  7863. *
  7864. * @author Ben Houston / http://clara.io/
  7865. * @author David Sarno / http://lighthaus.us/
  7866. * @author tschw
  7867. */
  7868. THREE.AnimationMixer = function( root ) {
  7869. this._root = root;
  7870. this._initMemoryManager();
  7871. this._accuIndex = 0;
  7872. this.time = 0;
  7873. this.timeScale = 1.0;
  7874. };
  7875. Object.assign( THREE.AnimationMixer.prototype, THREE.EventDispatcher.prototype, {
  7876. // return an action for a clip optionally using a custom root target
  7877. // object (this method allocates a lot of dynamic memory in case a
  7878. // previously unknown clip/root combination is specified)
  7879. clipAction: function( clip, optionalRoot ) {
  7880. var root = optionalRoot || this._root,
  7881. rootUuid = root.uuid,
  7882. clipObject = typeof clip === 'string' ?
  7883. THREE.AnimationClip.findByName( root, clip ) : clip,
  7884. clipUuid = clipObject !== null ? clipObject.uuid : clip,
  7885. actionsForClip = this._actionsByClip[ clipUuid ],
  7886. prototypeAction = null;
  7887. if ( actionsForClip !== undefined ) {
  7888. var existingAction =
  7889. actionsForClip.actionByRoot[ rootUuid ];
  7890. if ( existingAction !== undefined ) {
  7891. return existingAction;
  7892. }
  7893. // we know the clip, so we don't have to parse all
  7894. // the bindings again but can just copy
  7895. prototypeAction = actionsForClip.knownActions[ 0 ];
  7896. // also, take the clip from the prototype action
  7897. if ( clipObject === null )
  7898. clipObject = prototypeAction._clip;
  7899. }
  7900. // clip must be known when specified via string
  7901. if ( clipObject === null ) return null;
  7902. // allocate all resources required to run it
  7903. var newAction = new THREE.
  7904. AnimationMixer._Action( this, clipObject, optionalRoot );
  7905. this._bindAction( newAction, prototypeAction );
  7906. // and make the action known to the memory manager
  7907. this._addInactiveAction( newAction, clipUuid, rootUuid );
  7908. return newAction;
  7909. },
  7910. // get an existing action
  7911. existingAction: function( clip, optionalRoot ) {
  7912. var root = optionalRoot || this._root,
  7913. rootUuid = root.uuid,
  7914. clipObject = typeof clip === 'string' ?
  7915. THREE.AnimationClip.findByName( root, clip ) : clip,
  7916. clipUuid = clipObject ? clipObject.uuid : clip,
  7917. actionsForClip = this._actionsByClip[ clipUuid ];
  7918. if ( actionsForClip !== undefined ) {
  7919. return actionsForClip.actionByRoot[ rootUuid ] || null;
  7920. }
  7921. return null;
  7922. },
  7923. // deactivates all previously scheduled actions
  7924. stopAllAction: function() {
  7925. var actions = this._actions,
  7926. nActions = this._nActiveActions,
  7927. bindings = this._bindings,
  7928. nBindings = this._nActiveBindings;
  7929. this._nActiveActions = 0;
  7930. this._nActiveBindings = 0;
  7931. for ( var i = 0; i !== nActions; ++ i ) {
  7932. actions[ i ].reset();
  7933. }
  7934. for ( var i = 0; i !== nBindings; ++ i ) {
  7935. bindings[ i ].useCount = 0;
  7936. }
  7937. return this;
  7938. },
  7939. // advance the time and update apply the animation
  7940. update: function( deltaTime ) {
  7941. deltaTime *= this.timeScale;
  7942. var actions = this._actions,
  7943. nActions = this._nActiveActions,
  7944. time = this.time += deltaTime,
  7945. timeDirection = Math.sign( deltaTime ),
  7946. accuIndex = this._accuIndex ^= 1;
  7947. // run active actions
  7948. for ( var i = 0; i !== nActions; ++ i ) {
  7949. var action = actions[ i ];
  7950. if ( action.enabled ) {
  7951. action._update( time, deltaTime, timeDirection, accuIndex );
  7952. }
  7953. }
  7954. // update scene graph
  7955. var bindings = this._bindings,
  7956. nBindings = this._nActiveBindings;
  7957. for ( var i = 0; i !== nBindings; ++ i ) {
  7958. bindings[ i ].apply( accuIndex );
  7959. }
  7960. return this;
  7961. },
  7962. // return this mixer's root target object
  7963. getRoot: function() {
  7964. return this._root;
  7965. },
  7966. // free all resources specific to a particular clip
  7967. uncacheClip: function( clip ) {
  7968. var actions = this._actions,
  7969. clipUuid = clip.uuid,
  7970. actionsByClip = this._actionsByClip,
  7971. actionsForClip = actionsByClip[ clipUuid ];
  7972. if ( actionsForClip !== undefined ) {
  7973. // note: just calling _removeInactiveAction would mess up the
  7974. // iteration state and also require updating the state we can
  7975. // just throw away
  7976. var actionsToRemove = actionsForClip.knownActions;
  7977. for ( var i = 0, n = actionsToRemove.length; i !== n; ++ i ) {
  7978. var action = actionsToRemove[ i ];
  7979. this._deactivateAction( action );
  7980. var cacheIndex = action._cacheIndex,
  7981. lastInactiveAction = actions[ actions.length - 1 ];
  7982. action._cacheIndex = null;
  7983. action._byClipCacheIndex = null;
  7984. lastInactiveAction._cacheIndex = cacheIndex;
  7985. actions[ cacheIndex ] = lastInactiveAction;
  7986. actions.pop();
  7987. this._removeInactiveBindingsForAction( action );
  7988. }
  7989. delete actionsByClip[ clipUuid ];
  7990. }
  7991. },
  7992. // free all resources specific to a particular root target object
  7993. uncacheRoot: function( root ) {
  7994. var rootUuid = root.uuid,
  7995. actionsByClip = this._actionsByClip;
  7996. for ( var clipUuid in actionsByClip ) {
  7997. var actionByRoot = actionsByClip[ clipUuid ].actionByRoot,
  7998. action = actionByRoot[ rootUuid ];
  7999. if ( action !== undefined ) {
  8000. this._deactivateAction( action );
  8001. this._removeInactiveAction( action );
  8002. }
  8003. }
  8004. var bindingsByRoot = this._bindingsByRootAndName,
  8005. bindingByName = bindingsByRoot[ rootUuid ];
  8006. if ( bindingByName !== undefined ) {
  8007. for ( var trackName in bindingByName ) {
  8008. var binding = bindingByName[ trackName ];
  8009. binding.restoreOriginalState();
  8010. this._removeInactiveBinding( binding );
  8011. }
  8012. }
  8013. },
  8014. // remove a targeted clip from the cache
  8015. uncacheAction: function( clip, optionalRoot ) {
  8016. var action = this.existingAction( clip, optionalRoot );
  8017. if ( action !== null ) {
  8018. this._deactivateAction( action );
  8019. this._removeInactiveAction( action );
  8020. }
  8021. }
  8022. } );
  8023. THREE.AnimationMixer._Action = THREE.AnimationAction._new;
  8024. // Implementation details:
  8025. Object.assign( THREE.AnimationMixer.prototype, {
  8026. _bindAction: function( action, prototypeAction ) {
  8027. var root = action._localRoot || this._root,
  8028. tracks = action._clip.tracks,
  8029. nTracks = tracks.length,
  8030. bindings = action._propertyBindings,
  8031. interpolants = action._interpolants,
  8032. rootUuid = root.uuid,
  8033. bindingsByRoot = this._bindingsByRootAndName,
  8034. bindingsByName = bindingsByRoot[ rootUuid ];
  8035. if ( bindingsByName === undefined ) {
  8036. bindingsByName = {};
  8037. bindingsByRoot[ rootUuid ] = bindingsByName;
  8038. }
  8039. for ( var i = 0; i !== nTracks; ++ i ) {
  8040. var track = tracks[ i ],
  8041. trackName = track.name,
  8042. binding = bindingsByName[ trackName ];
  8043. if ( binding !== undefined ) {
  8044. bindings[ i ] = binding;
  8045. } else {
  8046. binding = bindings[ i ];
  8047. if ( binding !== undefined ) {
  8048. // existing binding, make sure the cache knows
  8049. if ( binding._cacheIndex === null ) {
  8050. ++ binding.referenceCount;
  8051. this._addInactiveBinding( binding, rootUuid, trackName );
  8052. }
  8053. continue;
  8054. }
  8055. var path = prototypeAction && prototypeAction.
  8056. _propertyBindings[ i ].binding.parsedPath;
  8057. binding = new THREE.PropertyMixer(
  8058. THREE.PropertyBinding.create( root, trackName, path ),
  8059. track.ValueTypeName, track.getValueSize() );
  8060. ++ binding.referenceCount;
  8061. this._addInactiveBinding( binding, rootUuid, trackName );
  8062. bindings[ i ] = binding;
  8063. }
  8064. interpolants[ i ].resultBuffer = binding.buffer;
  8065. }
  8066. },
  8067. _activateAction: function( action ) {
  8068. if ( ! this._isActiveAction( action ) ) {
  8069. if ( action._cacheIndex === null ) {
  8070. // this action has been forgotten by the cache, but the user
  8071. // appears to be still using it -> rebind
  8072. var rootUuid = ( action._localRoot || this._root ).uuid,
  8073. clipUuid = action._clip.uuid,
  8074. actionsForClip = this._actionsByClip[ clipUuid ];
  8075. this._bindAction( action,
  8076. actionsForClip && actionsForClip.knownActions[ 0 ] );
  8077. this._addInactiveAction( action, clipUuid, rootUuid );
  8078. }
  8079. var bindings = action._propertyBindings;
  8080. // increment reference counts / sort out state
  8081. for ( var i = 0, n = bindings.length; i !== n; ++ i ) {
  8082. var binding = bindings[ i ];
  8083. if ( binding.useCount ++ === 0 ) {
  8084. this._lendBinding( binding );
  8085. binding.saveOriginalState();
  8086. }
  8087. }
  8088. this._lendAction( action );
  8089. }
  8090. },
  8091. _deactivateAction: function( action ) {
  8092. if ( this._isActiveAction( action ) ) {
  8093. var bindings = action._propertyBindings;
  8094. // decrement reference counts / sort out state
  8095. for ( var i = 0, n = bindings.length; i !== n; ++ i ) {
  8096. var binding = bindings[ i ];
  8097. if ( -- binding.useCount === 0 ) {
  8098. binding.restoreOriginalState();
  8099. this._takeBackBinding( binding );
  8100. }
  8101. }
  8102. this._takeBackAction( action );
  8103. }
  8104. },
  8105. // Memory manager
  8106. _initMemoryManager: function() {
  8107. this._actions = []; // 'nActiveActions' followed by inactive ones
  8108. this._nActiveActions = 0;
  8109. this._actionsByClip = {};
  8110. // inside:
  8111. // {
  8112. // knownActions: Array< _Action > - used as prototypes
  8113. // actionByRoot: _Action - lookup
  8114. // }
  8115. this._bindings = []; // 'nActiveBindings' followed by inactive ones
  8116. this._nActiveBindings = 0;
  8117. this._bindingsByRootAndName = {}; // inside: Map< name, PropertyMixer >
  8118. this._controlInterpolants = []; // same game as above
  8119. this._nActiveControlInterpolants = 0;
  8120. var scope = this;
  8121. this.stats = {
  8122. actions: {
  8123. get total() { return scope._actions.length; },
  8124. get inUse() { return scope._nActiveActions; }
  8125. },
  8126. bindings: {
  8127. get total() { return scope._bindings.length; },
  8128. get inUse() { return scope._nActiveBindings; }
  8129. },
  8130. controlInterpolants: {
  8131. get total() { return scope._controlInterpolants.length; },
  8132. get inUse() { return scope._nActiveControlInterpolants; }
  8133. }
  8134. };
  8135. },
  8136. // Memory management for _Action objects
  8137. _isActiveAction: function( action ) {
  8138. var index = action._cacheIndex;
  8139. return index !== null && index < this._nActiveActions;
  8140. },
  8141. _addInactiveAction: function( action, clipUuid, rootUuid ) {
  8142. var actions = this._actions,
  8143. actionsByClip = this._actionsByClip,
  8144. actionsForClip = actionsByClip[ clipUuid ];
  8145. if ( actionsForClip === undefined ) {
  8146. actionsForClip = {
  8147. knownActions: [ action ],
  8148. actionByRoot: {}
  8149. };
  8150. action._byClipCacheIndex = 0;
  8151. actionsByClip[ clipUuid ] = actionsForClip;
  8152. } else {
  8153. var knownActions = actionsForClip.knownActions;
  8154. action._byClipCacheIndex = knownActions.length;
  8155. knownActions.push( action );
  8156. }
  8157. action._cacheIndex = actions.length;
  8158. actions.push( action );
  8159. actionsForClip.actionByRoot[ rootUuid ] = action;
  8160. },
  8161. _removeInactiveAction: function( action ) {
  8162. var actions = this._actions,
  8163. lastInactiveAction = actions[ actions.length - 1 ],
  8164. cacheIndex = action._cacheIndex;
  8165. lastInactiveAction._cacheIndex = cacheIndex;
  8166. actions[ cacheIndex ] = lastInactiveAction;
  8167. actions.pop();
  8168. action._cacheIndex = null;
  8169. var clipUuid = action._clip.uuid,
  8170. actionsByClip = this._actionsByClip,
  8171. actionsForClip = actionsByClip[ clipUuid ],
  8172. knownActionsForClip = actionsForClip.knownActions,
  8173. lastKnownAction =
  8174. knownActionsForClip[ knownActionsForClip.length - 1 ],
  8175. byClipCacheIndex = action._byClipCacheIndex;
  8176. lastKnownAction._byClipCacheIndex = byClipCacheIndex;
  8177. knownActionsForClip[ byClipCacheIndex ] = lastKnownAction;
  8178. knownActionsForClip.pop();
  8179. action._byClipCacheIndex = null;
  8180. var actionByRoot = actionsForClip.actionByRoot,
  8181. rootUuid = ( actions._localRoot || this._root ).uuid;
  8182. delete actionByRoot[ rootUuid ];
  8183. if ( knownActionsForClip.length === 0 ) {
  8184. delete actionsByClip[ clipUuid ];
  8185. }
  8186. this._removeInactiveBindingsForAction( action );
  8187. },
  8188. _removeInactiveBindingsForAction: function( action ) {
  8189. var bindings = action._propertyBindings;
  8190. for ( var i = 0, n = bindings.length; i !== n; ++ i ) {
  8191. var binding = bindings[ i ];
  8192. if ( -- binding.referenceCount === 0 ) {
  8193. this._removeInactiveBinding( binding );
  8194. }
  8195. }
  8196. },
  8197. _lendAction: function( action ) {
  8198. // [ active actions | inactive actions ]
  8199. // [ active actions >| inactive actions ]
  8200. // s a
  8201. // <-swap->
  8202. // a s
  8203. var actions = this._actions,
  8204. prevIndex = action._cacheIndex,
  8205. lastActiveIndex = this._nActiveActions ++,
  8206. firstInactiveAction = actions[ lastActiveIndex ];
  8207. action._cacheIndex = lastActiveIndex;
  8208. actions[ lastActiveIndex ] = action;
  8209. firstInactiveAction._cacheIndex = prevIndex;
  8210. actions[ prevIndex ] = firstInactiveAction;
  8211. },
  8212. _takeBackAction: function( action ) {
  8213. // [ active actions | inactive actions ]
  8214. // [ active actions |< inactive actions ]
  8215. // a s
  8216. // <-swap->
  8217. // s a
  8218. var actions = this._actions,
  8219. prevIndex = action._cacheIndex,
  8220. firstInactiveIndex = -- this._nActiveActions,
  8221. lastActiveAction = actions[ firstInactiveIndex ];
  8222. action._cacheIndex = firstInactiveIndex;
  8223. actions[ firstInactiveIndex ] = action;
  8224. lastActiveAction._cacheIndex = prevIndex;
  8225. actions[ prevIndex ] = lastActiveAction;
  8226. },
  8227. // Memory management for PropertyMixer objects
  8228. _addInactiveBinding: function( binding, rootUuid, trackName ) {
  8229. var bindingsByRoot = this._bindingsByRootAndName,
  8230. bindingByName = bindingsByRoot[ rootUuid ],
  8231. bindings = this._bindings;
  8232. if ( bindingByName === undefined ) {
  8233. bindingByName = {};
  8234. bindingsByRoot[ rootUuid ] = bindingByName;
  8235. }
  8236. bindingByName[ trackName ] = binding;
  8237. binding._cacheIndex = bindings.length;
  8238. bindings.push( binding );
  8239. },
  8240. _removeInactiveBinding: function( binding ) {
  8241. var bindings = this._bindings,
  8242. propBinding = binding.binding,
  8243. rootUuid = propBinding.rootNode.uuid,
  8244. trackName = propBinding.path,
  8245. bindingsByRoot = this._bindingsByRootAndName,
  8246. bindingByName = bindingsByRoot[ rootUuid ],
  8247. lastInactiveBinding = bindings[ bindings.length - 1 ],
  8248. cacheIndex = binding._cacheIndex;
  8249. lastInactiveBinding._cacheIndex = cacheIndex;
  8250. bindings[ cacheIndex ] = lastInactiveBinding;
  8251. bindings.pop();
  8252. delete bindingByName[ trackName ];
  8253. remove_empty_map: {
  8254. for ( var _ in bindingByName ) break remove_empty_map;
  8255. delete bindingsByRoot[ rootUuid ];
  8256. }
  8257. },
  8258. _lendBinding: function( binding ) {
  8259. var bindings = this._bindings,
  8260. prevIndex = binding._cacheIndex,
  8261. lastActiveIndex = this._nActiveBindings ++,
  8262. firstInactiveBinding = bindings[ lastActiveIndex ];
  8263. binding._cacheIndex = lastActiveIndex;
  8264. bindings[ lastActiveIndex ] = binding;
  8265. firstInactiveBinding._cacheIndex = prevIndex;
  8266. bindings[ prevIndex ] = firstInactiveBinding;
  8267. },
  8268. _takeBackBinding: function( binding ) {
  8269. var bindings = this._bindings,
  8270. prevIndex = binding._cacheIndex,
  8271. firstInactiveIndex = -- this._nActiveBindings,
  8272. lastActiveBinding = bindings[ firstInactiveIndex ];
  8273. binding._cacheIndex = firstInactiveIndex;
  8274. bindings[ firstInactiveIndex ] = binding;
  8275. lastActiveBinding._cacheIndex = prevIndex;
  8276. bindings[ prevIndex ] = lastActiveBinding;
  8277. },
  8278. // Memory management of Interpolants for weight and time scale
  8279. _lendControlInterpolant: function() {
  8280. var interpolants = this._controlInterpolants,
  8281. lastActiveIndex = this._nActiveControlInterpolants ++,
  8282. interpolant = interpolants[ lastActiveIndex ];
  8283. if ( interpolant === undefined ) {
  8284. interpolant = new THREE.LinearInterpolant(
  8285. new Float32Array( 2 ), new Float32Array( 2 ),
  8286. 1, this._controlInterpolantsResultBuffer );
  8287. interpolant.__cacheIndex = lastActiveIndex;
  8288. interpolants[ lastActiveIndex ] = interpolant;
  8289. }
  8290. return interpolant;
  8291. },
  8292. _takeBackControlInterpolant: function( interpolant ) {
  8293. var interpolants = this._controlInterpolants,
  8294. prevIndex = interpolant.__cacheIndex,
  8295. firstInactiveIndex = -- this._nActiveControlInterpolants,
  8296. lastActiveInterpolant = interpolants[ firstInactiveIndex ];
  8297. interpolant.__cacheIndex = firstInactiveIndex;
  8298. interpolants[ firstInactiveIndex ] = interpolant;
  8299. lastActiveInterpolant.__cacheIndex = prevIndex;
  8300. interpolants[ prevIndex ] = lastActiveInterpolant;
  8301. },
  8302. _controlInterpolantsResultBuffer: new Float32Array( 1 )
  8303. } );
  8304. // File:src/animation/AnimationObjectGroup.js
  8305. /**
  8306. *
  8307. * A group of objects that receives a shared animation state.
  8308. *
  8309. * Usage:
  8310. *
  8311. * - Add objects you would otherwise pass as 'root' to the
  8312. * constructor or the .clipAction method of AnimationMixer.
  8313. *
  8314. * - Instead pass this object as 'root'.
  8315. *
  8316. * - You can also add and remove objects later when the mixer
  8317. * is running.
  8318. *
  8319. * Note:
  8320. *
  8321. * Objects of this class appear as one object to the mixer,
  8322. * so cache control of the individual objects must be done
  8323. * on the group.
  8324. *
  8325. * Limitation:
  8326. *
  8327. * - The animated properties must be compatible among the
  8328. * all objects in the group.
  8329. *
  8330. * - A single property can either be controlled through a
  8331. * target group or directly, but not both.
  8332. *
  8333. * @author tschw
  8334. */
  8335. THREE.AnimationObjectGroup = function( var_args ) {
  8336. this.uuid = THREE.Math.generateUUID();
  8337. // cached objects followed by the active ones
  8338. this._objects = Array.prototype.slice.call( arguments );
  8339. this.nCachedObjects_ = 0; // threshold
  8340. // note: read by PropertyBinding.Composite
  8341. var indices = {};
  8342. this._indicesByUUID = indices; // for bookkeeping
  8343. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  8344. indices[ arguments[ i ].uuid ] = i;
  8345. }
  8346. this._paths = []; // inside: string
  8347. this._parsedPaths = []; // inside: { we don't care, here }
  8348. this._bindings = []; // inside: Array< PropertyBinding >
  8349. this._bindingsIndicesByPath = {}; // inside: indices in these arrays
  8350. var scope = this;
  8351. this.stats = {
  8352. objects: {
  8353. get total() { return scope._objects.length; },
  8354. get inUse() { return this.total - scope.nCachedObjects_; }
  8355. },
  8356. get bindingsPerObject() { return scope._bindings.length; }
  8357. };
  8358. };
  8359. THREE.AnimationObjectGroup.prototype = {
  8360. constructor: THREE.AnimationObjectGroup,
  8361. add: function( var_args ) {
  8362. var objects = this._objects,
  8363. nObjects = objects.length,
  8364. nCachedObjects = this.nCachedObjects_,
  8365. indicesByUUID = this._indicesByUUID,
  8366. paths = this._paths,
  8367. parsedPaths = this._parsedPaths,
  8368. bindings = this._bindings,
  8369. nBindings = bindings.length;
  8370. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  8371. var object = arguments[ i ],
  8372. uuid = object.uuid,
  8373. index = indicesByUUID[ uuid ];
  8374. if ( index === undefined ) {
  8375. // unknown object -> add it to the ACTIVE region
  8376. index = nObjects ++;
  8377. indicesByUUID[ uuid ] = index;
  8378. objects.push( object );
  8379. // accounting is done, now do the same for all bindings
  8380. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  8381. bindings[ j ].push(
  8382. new THREE.PropertyBinding(
  8383. object, paths[ j ], parsedPaths[ j ] ) );
  8384. }
  8385. } else if ( index < nCachedObjects ) {
  8386. var knownObject = objects[ index ];
  8387. // move existing object to the ACTIVE region
  8388. var firstActiveIndex = -- nCachedObjects,
  8389. lastCachedObject = objects[ firstActiveIndex ];
  8390. indicesByUUID[ lastCachedObject.uuid ] = index;
  8391. objects[ index ] = lastCachedObject;
  8392. indicesByUUID[ uuid ] = firstActiveIndex;
  8393. objects[ firstActiveIndex ] = object;
  8394. // accounting is done, now do the same for all bindings
  8395. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  8396. var bindingsForPath = bindings[ j ],
  8397. lastCached = bindingsForPath[ firstActiveIndex ],
  8398. binding = bindingsForPath[ index ];
  8399. bindingsForPath[ index ] = lastCached;
  8400. if ( binding === undefined ) {
  8401. // since we do not bother to create new bindings
  8402. // for objects that are cached, the binding may
  8403. // or may not exist
  8404. binding = new THREE.PropertyBinding(
  8405. object, paths[ j ], parsedPaths[ j ] );
  8406. }
  8407. bindingsForPath[ firstActiveIndex ] = binding;
  8408. }
  8409. } else if ( objects[ index ] !== knownObject) {
  8410. console.error( "Different objects with the same UUID " +
  8411. "detected. Clean the caches or recreate your " +
  8412. "infrastructure when reloading scenes..." );
  8413. } // else the object is already where we want it to be
  8414. } // for arguments
  8415. this.nCachedObjects_ = nCachedObjects;
  8416. },
  8417. remove: function( var_args ) {
  8418. var objects = this._objects,
  8419. nObjects = objects.length,
  8420. nCachedObjects = this.nCachedObjects_,
  8421. indicesByUUID = this._indicesByUUID,
  8422. bindings = this._bindings,
  8423. nBindings = bindings.length;
  8424. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  8425. var object = arguments[ i ],
  8426. uuid = object.uuid,
  8427. index = indicesByUUID[ uuid ];
  8428. if ( index !== undefined && index >= nCachedObjects ) {
  8429. // move existing object into the CACHED region
  8430. var lastCachedIndex = nCachedObjects ++,
  8431. firstActiveObject = objects[ lastCachedIndex ];
  8432. indicesByUUID[ firstActiveObject.uuid ] = index;
  8433. objects[ index ] = firstActiveObject;
  8434. indicesByUUID[ uuid ] = lastCachedIndex;
  8435. objects[ lastCachedIndex ] = object;
  8436. // accounting is done, now do the same for all bindings
  8437. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  8438. var bindingsForPath = bindings[ j ],
  8439. firstActive = bindingsForPath[ lastCachedIndex ],
  8440. binding = bindingsForPath[ index ];
  8441. bindingsForPath[ index ] = firstActive;
  8442. bindingsForPath[ lastCachedIndex ] = binding;
  8443. }
  8444. }
  8445. } // for arguments
  8446. this.nCachedObjects_ = nCachedObjects;
  8447. },
  8448. // remove & forget
  8449. uncache: function( var_args ) {
  8450. var objects = this._objects,
  8451. nObjects = objects.length,
  8452. nCachedObjects = this.nCachedObjects_,
  8453. indicesByUUID = this._indicesByUUID,
  8454. bindings = this._bindings,
  8455. nBindings = bindings.length;
  8456. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  8457. var object = arguments[ i ],
  8458. uuid = object.uuid,
  8459. index = indicesByUUID[ uuid ];
  8460. if ( index !== undefined ) {
  8461. delete indicesByUUID[ uuid ];
  8462. if ( index < nCachedObjects ) {
  8463. // object is cached, shrink the CACHED region
  8464. var firstActiveIndex = -- nCachedObjects,
  8465. lastCachedObject = objects[ firstActiveIndex ],
  8466. lastIndex = -- nObjects,
  8467. lastObject = objects[ lastIndex ];
  8468. // last cached object takes this object's place
  8469. indicesByUUID[ lastCachedObject.uuid ] = index;
  8470. objects[ index ] = lastCachedObject;
  8471. // last object goes to the activated slot and pop
  8472. indicesByUUID[ lastObject.uuid ] = firstActiveIndex;
  8473. objects[ firstActiveIndex ] = lastObject;
  8474. objects.pop();
  8475. // accounting is done, now do the same for all bindings
  8476. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  8477. var bindingsForPath = bindings[ j ],
  8478. lastCached = bindingsForPath[ firstActiveIndex ],
  8479. last = bindingsForPath[ lastIndex ];
  8480. bindingsForPath[ index ] = lastCached;
  8481. bindingsForPath[ firstActiveIndex ] = last;
  8482. bindingsForPath.pop();
  8483. }
  8484. } else {
  8485. // object is active, just swap with the last and pop
  8486. var lastIndex = -- nObjects,
  8487. lastObject = objects[ lastIndex ];
  8488. indicesByUUID[ lastObject.uuid ] = index;
  8489. objects[ index ] = lastObject;
  8490. objects.pop();
  8491. // accounting is done, now do the same for all bindings
  8492. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  8493. var bindingsForPath = bindings[ j ];
  8494. bindingsForPath[ index ] = bindingsForPath[ lastIndex ];
  8495. bindingsForPath.pop();
  8496. }
  8497. } // cached or active
  8498. } // if object is known
  8499. } // for arguments
  8500. this.nCachedObjects_ = nCachedObjects;
  8501. },
  8502. // Internal interface used by befriended PropertyBinding.Composite:
  8503. subscribe_: function( path, parsedPath ) {
  8504. // returns an array of bindings for the given path that is changed
  8505. // according to the contained objects in the group
  8506. var indicesByPath = this._bindingsIndicesByPath,
  8507. index = indicesByPath[ path ],
  8508. bindings = this._bindings;
  8509. if ( index !== undefined ) return bindings[ index ];
  8510. var paths = this._paths,
  8511. parsedPaths = this._parsedPaths,
  8512. objects = this._objects,
  8513. nObjects = objects.length,
  8514. nCachedObjects = this.nCachedObjects_,
  8515. bindingsForPath = new Array( nObjects );
  8516. index = bindings.length;
  8517. indicesByPath[ path ] = index;
  8518. paths.push( path );
  8519. parsedPaths.push( parsedPath );
  8520. bindings.push( bindingsForPath );
  8521. for ( var i = nCachedObjects,
  8522. n = objects.length; i !== n; ++ i ) {
  8523. var object = objects[ i ];
  8524. bindingsForPath[ i ] =
  8525. new THREE.PropertyBinding( object, path, parsedPath );
  8526. }
  8527. return bindingsForPath;
  8528. },
  8529. unsubscribe_: function( path ) {
  8530. // tells the group to forget about a property path and no longer
  8531. // update the array previously obtained with 'subscribe_'
  8532. var indicesByPath = this._bindingsIndicesByPath,
  8533. index = indicesByPath[ path ];
  8534. if ( index !== undefined ) {
  8535. var paths = this._paths,
  8536. parsedPaths = this._parsedPaths,
  8537. bindings = this._bindings,
  8538. lastBindingsIndex = bindings.length - 1,
  8539. lastBindings = bindings[ lastBindingsIndex ],
  8540. lastBindingsPath = path[ lastBindingsIndex ];
  8541. indicesByPath[ lastBindingsPath ] = index;
  8542. bindings[ index ] = lastBindings;
  8543. bindings.pop();
  8544. parsedPaths[ index ] = parsedPaths[ lastBindingsIndex ];
  8545. parsedPaths.pop();
  8546. paths[ index ] = paths[ lastBindingsIndex ];
  8547. paths.pop();
  8548. }
  8549. }
  8550. };
  8551. // File:src/animation/AnimationUtils.js
  8552. /**
  8553. * @author tschw
  8554. * @author Ben Houston / http://clara.io/
  8555. * @author David Sarno / http://lighthaus.us/
  8556. */
  8557. THREE.AnimationUtils = {
  8558. // same as Array.prototype.slice, but also works on typed arrays
  8559. arraySlice: function( array, from, to ) {
  8560. if ( THREE.AnimationUtils.isTypedArray( array ) ) {
  8561. return new array.constructor( array.subarray( from, to ) );
  8562. }
  8563. return array.slice( from, to );
  8564. },
  8565. // converts an array to a specific type
  8566. convertArray: function( array, type, forceClone ) {
  8567. if ( ! array || // let 'undefined' and 'null' pass
  8568. ! forceClone && array.constructor === type ) return array;
  8569. if ( typeof type.BYTES_PER_ELEMENT === 'number' ) {
  8570. return new type( array ); // create typed array
  8571. }
  8572. return Array.prototype.slice.call( array ); // create Array
  8573. },
  8574. isTypedArray: function( object ) {
  8575. return ArrayBuffer.isView( object ) &&
  8576. ! ( object instanceof DataView );
  8577. },
  8578. // returns an array by which times and values can be sorted
  8579. getKeyframeOrder: function( times ) {
  8580. function compareTime( i, j ) {
  8581. return times[ i ] - times[ j ];
  8582. }
  8583. var n = times.length;
  8584. var result = new Array( n );
  8585. for ( var i = 0; i !== n; ++ i ) result[ i ] = i;
  8586. result.sort( compareTime );
  8587. return result;
  8588. },
  8589. // uses the array previously returned by 'getKeyframeOrder' to sort data
  8590. sortedArray: function( values, stride, order ) {
  8591. var nValues = values.length;
  8592. var result = new values.constructor( nValues );
  8593. for ( var i = 0, dstOffset = 0; dstOffset !== nValues; ++ i ) {
  8594. var srcOffset = order[ i ] * stride;
  8595. for ( var j = 0; j !== stride; ++ j ) {
  8596. result[ dstOffset ++ ] = values[ srcOffset + j ];
  8597. }
  8598. }
  8599. return result;
  8600. },
  8601. // function for parsing AOS keyframe formats
  8602. flattenJSON: function( jsonKeys, times, values, valuePropertyName ) {
  8603. var i = 1, key = jsonKeys[ 0 ];
  8604. while ( key !== undefined && key[ valuePropertyName ] === undefined ) {
  8605. key = jsonKeys[ i ++ ];
  8606. }
  8607. if ( key === undefined ) return; // no data
  8608. var value = key[ valuePropertyName ];
  8609. if ( value === undefined ) return; // no data
  8610. if ( Array.isArray( value ) ) {
  8611. do {
  8612. value = key[ valuePropertyName ];
  8613. if ( value !== undefined ) {
  8614. times.push( key.time );
  8615. values.push.apply( values, value ); // push all elements
  8616. }
  8617. key = jsonKeys[ i ++ ];
  8618. } while ( key !== undefined );
  8619. } else if ( value.toArray !== undefined ) {
  8620. // ...assume THREE.Math-ish
  8621. do {
  8622. value = key[ valuePropertyName ];
  8623. if ( value !== undefined ) {
  8624. times.push( key.time );
  8625. value.toArray( values, values.length );
  8626. }
  8627. key = jsonKeys[ i ++ ];
  8628. } while ( key !== undefined );
  8629. } else {
  8630. // otherwise push as-is
  8631. do {
  8632. value = key[ valuePropertyName ];
  8633. if ( value !== undefined ) {
  8634. times.push( key.time );
  8635. values.push( value );
  8636. }
  8637. key = jsonKeys[ i ++ ];
  8638. } while ( key !== undefined );
  8639. }
  8640. }
  8641. };
  8642. // File:src/animation/KeyframeTrack.js
  8643. /**
  8644. *
  8645. * A timed sequence of keyframes for a specific property.
  8646. *
  8647. *
  8648. * @author Ben Houston / http://clara.io/
  8649. * @author David Sarno / http://lighthaus.us/
  8650. * @author tschw
  8651. */
  8652. THREE.KeyframeTrack = function ( name, times, values, interpolation ) {
  8653. if( name === undefined ) throw new Error( "track name is undefined" );
  8654. if( times === undefined || times.length === 0 ) {
  8655. throw new Error( "no keyframes in track named " + name );
  8656. }
  8657. this.name = name;
  8658. this.times = THREE.AnimationUtils.convertArray( times, this.TimeBufferType );
  8659. this.values = THREE.AnimationUtils.convertArray( values, this.ValueBufferType );
  8660. this.setInterpolation( interpolation || this.DefaultInterpolation );
  8661. this.validate();
  8662. this.optimize();
  8663. };
  8664. THREE.KeyframeTrack.prototype = {
  8665. constructor: THREE.KeyframeTrack,
  8666. TimeBufferType: Float32Array,
  8667. ValueBufferType: Float32Array,
  8668. DefaultInterpolation: THREE.InterpolateLinear,
  8669. InterpolantFactoryMethodDiscrete: function( result ) {
  8670. return new THREE.DiscreteInterpolant(
  8671. this.times, this.values, this.getValueSize(), result );
  8672. },
  8673. InterpolantFactoryMethodLinear: function( result ) {
  8674. return new THREE.LinearInterpolant(
  8675. this.times, this.values, this.getValueSize(), result );
  8676. },
  8677. InterpolantFactoryMethodSmooth: function( result ) {
  8678. return new THREE.CubicInterpolant(
  8679. this.times, this.values, this.getValueSize(), result );
  8680. },
  8681. setInterpolation: function( interpolation ) {
  8682. var factoryMethod;
  8683. switch ( interpolation ) {
  8684. case THREE.InterpolateDiscrete:
  8685. factoryMethod = this.InterpolantFactoryMethodDiscrete;
  8686. break;
  8687. case THREE.InterpolateLinear:
  8688. factoryMethod = this.InterpolantFactoryMethodLinear;
  8689. break;
  8690. case THREE.InterpolateSmooth:
  8691. factoryMethod = this.InterpolantFactoryMethodSmooth;
  8692. break;
  8693. }
  8694. if ( factoryMethod === undefined ) {
  8695. var message = "unsupported interpolation for " +
  8696. this.ValueTypeName + " keyframe track named " + this.name;
  8697. if ( this.createInterpolant === undefined ) {
  8698. // fall back to default, unless the default itself is messed up
  8699. if ( interpolation !== this.DefaultInterpolation ) {
  8700. this.setInterpolation( this.DefaultInterpolation );
  8701. } else {
  8702. throw new Error( message ); // fatal, in this case
  8703. }
  8704. }
  8705. console.warn( message );
  8706. return;
  8707. }
  8708. this.createInterpolant = factoryMethod;
  8709. },
  8710. getInterpolation: function() {
  8711. switch ( this.createInterpolant ) {
  8712. case this.InterpolantFactoryMethodDiscrete:
  8713. return THREE.InterpolateDiscrete;
  8714. case this.InterpolantFactoryMethodLinear:
  8715. return THREE.InterpolateLinear;
  8716. case this.InterpolantFactoryMethodSmooth:
  8717. return THREE.InterpolateSmooth;
  8718. }
  8719. },
  8720. getValueSize: function() {
  8721. return this.values.length / this.times.length;
  8722. },
  8723. // move all keyframes either forwards or backwards in time
  8724. shift: function( timeOffset ) {
  8725. if( timeOffset !== 0.0 ) {
  8726. var times = this.times;
  8727. for( var i = 0, n = times.length; i !== n; ++ i ) {
  8728. times[ i ] += timeOffset;
  8729. }
  8730. }
  8731. return this;
  8732. },
  8733. // scale all keyframe times by a factor (useful for frame <-> seconds conversions)
  8734. scale: function( timeScale ) {
  8735. if( timeScale !== 1.0 ) {
  8736. var times = this.times;
  8737. for( var i = 0, n = times.length; i !== n; ++ i ) {
  8738. times[ i ] *= timeScale;
  8739. }
  8740. }
  8741. return this;
  8742. },
  8743. // removes keyframes before and after animation without changing any values within the range [startTime, endTime].
  8744. // IMPORTANT: We do not shift around keys to the start of the track time, because for interpolated keys this will change their values
  8745. trim: function( startTime, endTime ) {
  8746. var times = this.times,
  8747. nKeys = times.length,
  8748. from = 0,
  8749. to = nKeys - 1;
  8750. while ( from !== nKeys && times[ from ] < startTime ) ++ from;
  8751. while ( to !== -1 && times[ to ] > endTime ) -- to;
  8752. ++ to; // inclusive -> exclusive bound
  8753. if( from !== 0 || to !== nKeys ) {
  8754. // empty tracks are forbidden, so keep at least one keyframe
  8755. if ( from >= to ) to = Math.max( to , 1 ), from = to - 1;
  8756. var stride = this.getValueSize();
  8757. this.times = THREE.AnimationUtils.arraySlice( times, from, to );
  8758. this.values = THREE.AnimationUtils.
  8759. arraySlice( this.values, from * stride, to * stride );
  8760. }
  8761. return this;
  8762. },
  8763. // ensure we do not get a GarbageInGarbageOut situation, make sure tracks are at least minimally viable
  8764. validate: function() {
  8765. var valid = true;
  8766. var valueSize = this.getValueSize();
  8767. if ( valueSize - Math.floor( valueSize ) !== 0 ) {
  8768. console.error( "invalid value size in track", this );
  8769. valid = false;
  8770. }
  8771. var times = this.times,
  8772. values = this.values,
  8773. nKeys = times.length;
  8774. if( nKeys === 0 ) {
  8775. console.error( "track is empty", this );
  8776. valid = false;
  8777. }
  8778. var prevTime = null;
  8779. for( var i = 0; i !== nKeys; i ++ ) {
  8780. var currTime = times[ i ];
  8781. if ( typeof currTime === 'number' && isNaN( currTime ) ) {
  8782. console.error( "time is not a valid number", this, i, currTime );
  8783. valid = false;
  8784. break;
  8785. }
  8786. if( prevTime !== null && prevTime > currTime ) {
  8787. console.error( "out of order keys", this, i, currTime, prevTime );
  8788. valid = false;
  8789. break;
  8790. }
  8791. prevTime = currTime;
  8792. }
  8793. if ( values !== undefined ) {
  8794. if ( THREE.AnimationUtils.isTypedArray( values ) ) {
  8795. for ( var i = 0, n = values.length; i !== n; ++ i ) {
  8796. var value = values[ i ];
  8797. if ( isNaN( value ) ) {
  8798. console.error( "value is not a valid number", this, i, value );
  8799. valid = false;
  8800. break;
  8801. }
  8802. }
  8803. }
  8804. }
  8805. return valid;
  8806. },
  8807. // removes equivalent sequential keys as common in morph target sequences
  8808. // (0,0,0,0,1,1,1,0,0,0,0,0,0,0) --> (0,0,1,1,0,0)
  8809. optimize: function() {
  8810. var times = this.times,
  8811. values = this.values,
  8812. stride = this.getValueSize(),
  8813. writeIndex = 1;
  8814. for( var i = 1, n = times.length - 1; i <= n; ++ i ) {
  8815. var keep = false;
  8816. var time = times[ i ];
  8817. var timeNext = times[ i + 1 ];
  8818. // remove adjacent keyframes scheduled at the same time
  8819. if ( time !== timeNext && ( i !== 1 || time !== time[ 0 ] ) ) {
  8820. // remove unnecessary keyframes same as their neighbors
  8821. var offset = i * stride,
  8822. offsetP = offset - stride,
  8823. offsetN = offset + stride;
  8824. for ( var j = 0; j !== stride; ++ j ) {
  8825. var value = values[ offset + j ];
  8826. if ( value !== values[ offsetP + j ] ||
  8827. value !== values[ offsetN + j ] ) {
  8828. keep = true;
  8829. break;
  8830. }
  8831. }
  8832. }
  8833. // in-place compaction
  8834. if ( keep ) {
  8835. if ( i !== writeIndex ) {
  8836. times[ writeIndex ] = times[ i ];
  8837. var readOffset = i * stride,
  8838. writeOffset = writeIndex * stride;
  8839. for ( var j = 0; j !== stride; ++ j ) {
  8840. values[ writeOffset + j ] = values[ readOffset + j ];
  8841. }
  8842. }
  8843. ++ writeIndex;
  8844. }
  8845. }
  8846. if ( writeIndex !== times.length ) {
  8847. this.times = THREE.AnimationUtils.arraySlice( times, 0, writeIndex );
  8848. this.values = THREE.AnimationUtils.arraySlice( values, 0, writeIndex * stride );
  8849. }
  8850. return this;
  8851. }
  8852. };
  8853. // Static methods:
  8854. Object.assign( THREE.KeyframeTrack, {
  8855. // Serialization (in static context, because of constructor invocation
  8856. // and automatic invocation of .toJSON):
  8857. parse: function( json ) {
  8858. if( json.type === undefined ) {
  8859. throw new Error( "track type undefined, can not parse" );
  8860. }
  8861. var trackType = THREE.KeyframeTrack._getTrackTypeForValueTypeName( json.type );
  8862. if ( json.times === undefined ) {
  8863. var times = [], values = [];
  8864. THREE.AnimationUtils.flattenJSON( json.keys, times, values, 'value' );
  8865. json.times = times;
  8866. json.values = values;
  8867. }
  8868. // derived classes can define a static parse method
  8869. if ( trackType.parse !== undefined ) {
  8870. return trackType.parse( json );
  8871. } else {
  8872. // by default, we asssume a constructor compatible with the base
  8873. return new trackType(
  8874. json.name, json.times, json.values, json.interpolation );
  8875. }
  8876. },
  8877. toJSON: function( track ) {
  8878. var trackType = track.constructor;
  8879. var json;
  8880. // derived classes can define a static toJSON method
  8881. if ( trackType.toJSON !== undefined ) {
  8882. json = trackType.toJSON( track );
  8883. } else {
  8884. // by default, we assume the data can be serialized as-is
  8885. json = {
  8886. 'name': track.name,
  8887. 'times': THREE.AnimationUtils.convertArray( track.times, Array ),
  8888. 'values': THREE.AnimationUtils.convertArray( track.values, Array )
  8889. };
  8890. var interpolation = track.getInterpolation();
  8891. if ( interpolation !== track.DefaultInterpolation ) {
  8892. json.interpolation = interpolation;
  8893. }
  8894. }
  8895. json.type = track.ValueTypeName; // mandatory
  8896. return json;
  8897. },
  8898. _getTrackTypeForValueTypeName: function( typeName ) {
  8899. switch( typeName.toLowerCase() ) {
  8900. case "scalar":
  8901. case "double":
  8902. case "float":
  8903. case "number":
  8904. case "integer":
  8905. return THREE.NumberKeyframeTrack;
  8906. case "vector":
  8907. case "vector2":
  8908. case "vector3":
  8909. case "vector4":
  8910. return THREE.VectorKeyframeTrack;
  8911. case "color":
  8912. return THREE.ColorKeyframeTrack;
  8913. case "quaternion":
  8914. return THREE.QuaternionKeyframeTrack;
  8915. case "bool":
  8916. case "boolean":
  8917. return THREE.BooleanKeyframeTrack;
  8918. case "string":
  8919. return THREE.StringKeyframeTrack;
  8920. }
  8921. throw new Error( "Unsupported typeName: " + typeName );
  8922. }
  8923. } );
  8924. // File:src/animation/PropertyBinding.js
  8925. /**
  8926. *
  8927. * A reference to a real property in the scene graph.
  8928. *
  8929. *
  8930. * @author Ben Houston / http://clara.io/
  8931. * @author David Sarno / http://lighthaus.us/
  8932. * @author tschw
  8933. */
  8934. THREE.PropertyBinding = function ( rootNode, path, parsedPath ) {
  8935. this.path = path;
  8936. this.parsedPath = parsedPath ||
  8937. THREE.PropertyBinding.parseTrackName( path );
  8938. this.node = THREE.PropertyBinding.findNode(
  8939. rootNode, this.parsedPath.nodeName ) || rootNode;
  8940. this.rootNode = rootNode;
  8941. };
  8942. THREE.PropertyBinding.prototype = {
  8943. constructor: THREE.PropertyBinding,
  8944. getValue: function getValue_unbound( targetArray, offset ) {
  8945. this.bind();
  8946. this.getValue( targetArray, offset );
  8947. // Note: This class uses a State pattern on a per-method basis:
  8948. // 'bind' sets 'this.getValue' / 'setValue' and shadows the
  8949. // prototype version of these methods with one that represents
  8950. // the bound state. When the property is not found, the methods
  8951. // become no-ops.
  8952. },
  8953. setValue: function getValue_unbound( sourceArray, offset ) {
  8954. this.bind();
  8955. this.setValue( sourceArray, offset );
  8956. },
  8957. // create getter / setter pair for a property in the scene graph
  8958. bind: function() {
  8959. var targetObject = this.node,
  8960. parsedPath = this.parsedPath,
  8961. objectName = parsedPath.objectName,
  8962. propertyName = parsedPath.propertyName,
  8963. propertyIndex = parsedPath.propertyIndex;
  8964. if ( ! targetObject ) {
  8965. targetObject = THREE.PropertyBinding.findNode(
  8966. this.rootNode, parsedPath.nodeName ) || this.rootNode;
  8967. this.node = targetObject;
  8968. }
  8969. // set fail state so we can just 'return' on error
  8970. this.getValue = this._getValue_unavailable;
  8971. this.setValue = this._setValue_unavailable;
  8972. // ensure there is a value node
  8973. if ( ! targetObject ) {
  8974. console.error( " trying to update node for track: " + this.path + " but it wasn't found." );
  8975. return;
  8976. }
  8977. if ( objectName ) {
  8978. var objectIndex = parsedPath.objectIndex;
  8979. // special cases were we need to reach deeper into the hierarchy to get the face materials....
  8980. switch ( objectName ) {
  8981. case 'materials':
  8982. if ( ! targetObject.material ) {
  8983. console.error( ' can not bind to material as node does not have a material', this );
  8984. return;
  8985. }
  8986. if ( ! targetObject.material.materials ) {
  8987. console.error( ' can not bind to material.materials as node.material does not have a materials array', this );
  8988. return;
  8989. }
  8990. targetObject = targetObject.material.materials;
  8991. break;
  8992. case 'bones':
  8993. if ( ! targetObject.skeleton ) {
  8994. console.error( ' can not bind to bones as node does not have a skeleton', this );
  8995. return;
  8996. }
  8997. // potential future optimization: skip this if propertyIndex is already an integer
  8998. // and convert the integer string to a true integer.
  8999. targetObject = targetObject.skeleton.bones;
  9000. // support resolving morphTarget names into indices.
  9001. for ( var i = 0; i < targetObject.length; i ++ ) {
  9002. if ( targetObject[ i ].name === objectIndex ) {
  9003. objectIndex = i;
  9004. break;
  9005. }
  9006. }
  9007. break;
  9008. default:
  9009. if ( targetObject[ objectName ] === undefined ) {
  9010. console.error( ' can not bind to objectName of node, undefined', this );
  9011. return;
  9012. }
  9013. targetObject = targetObject[ objectName ];
  9014. }
  9015. if ( objectIndex !== undefined ) {
  9016. if ( targetObject[ objectIndex ] === undefined ) {
  9017. console.error( " trying to bind to objectIndex of objectName, but is undefined:", this, targetObject );
  9018. return;
  9019. }
  9020. targetObject = targetObject[ objectIndex ];
  9021. }
  9022. }
  9023. // resolve property
  9024. var nodeProperty = targetObject[ propertyName ];
  9025. if ( nodeProperty === undefined ) {
  9026. var nodeName = parsedPath.nodeName;
  9027. console.error( " trying to update property for track: " + nodeName +
  9028. '.' + propertyName + " but it wasn't found.", targetObject );
  9029. return;
  9030. }
  9031. // determine versioning scheme
  9032. var versioning = this.Versioning.None;
  9033. if ( targetObject.needsUpdate !== undefined ) { // material
  9034. versioning = this.Versioning.NeedsUpdate;
  9035. this.targetObject = targetObject;
  9036. } else if ( targetObject.matrixWorldNeedsUpdate !== undefined ) { // node transform
  9037. versioning = this.Versioning.MatrixWorldNeedsUpdate;
  9038. this.targetObject = targetObject;
  9039. }
  9040. // determine how the property gets bound
  9041. var bindingType = this.BindingType.Direct;
  9042. if ( propertyIndex !== undefined ) {
  9043. // access a sub element of the property array (only primitives are supported right now)
  9044. if ( propertyName === "morphTargetInfluences" ) {
  9045. // potential optimization, skip this if propertyIndex is already an integer, and convert the integer string to a true integer.
  9046. // support resolving morphTarget names into indices.
  9047. if ( ! targetObject.geometry ) {
  9048. console.error( ' can not bind to morphTargetInfluences becasuse node does not have a geometry', this );
  9049. return;
  9050. }
  9051. if ( ! targetObject.geometry.morphTargets ) {
  9052. console.error( ' can not bind to morphTargetInfluences becasuse node does not have a geometry.morphTargets', this );
  9053. return;
  9054. }
  9055. for ( var i = 0; i < this.node.geometry.morphTargets.length; i ++ ) {
  9056. if ( targetObject.geometry.morphTargets[ i ].name === propertyIndex ) {
  9057. propertyIndex = i;
  9058. break;
  9059. }
  9060. }
  9061. }
  9062. bindingType = this.BindingType.ArrayElement;
  9063. this.resolvedProperty = nodeProperty;
  9064. this.propertyIndex = propertyIndex;
  9065. } else if ( nodeProperty.fromArray !== undefined && nodeProperty.toArray !== undefined ) {
  9066. // must use copy for Object3D.Euler/Quaternion
  9067. bindingType = this.BindingType.HasFromToArray;
  9068. this.resolvedProperty = nodeProperty;
  9069. } else if ( nodeProperty.length !== undefined ) {
  9070. bindingType = this.BindingType.EntireArray;
  9071. this.resolvedProperty = nodeProperty;
  9072. } else {
  9073. this.propertyName = propertyName;
  9074. }
  9075. // select getter / setter
  9076. this.getValue = this.GetterByBindingType[ bindingType ];
  9077. this.setValue = this.SetterByBindingTypeAndVersioning[ bindingType ][ versioning ];
  9078. },
  9079. unbind: function() {
  9080. this.node = null;
  9081. // back to the prototype version of getValue / setValue
  9082. // note: avoiding to mutate the shape of 'this' via 'delete'
  9083. this.getValue = this._getValue_unbound;
  9084. this.setValue = this._setValue_unbound;
  9085. }
  9086. };
  9087. Object.assign( THREE.PropertyBinding.prototype, { // prototype, continued
  9088. // these are used to "bind" a nonexistent property
  9089. _getValue_unavailable: function() {},
  9090. _setValue_unavailable: function() {},
  9091. // initial state of these methods that calls 'bind'
  9092. _getValue_unbound: THREE.PropertyBinding.prototype.getValue,
  9093. _setValue_unbound: THREE.PropertyBinding.prototype.setValue,
  9094. BindingType: {
  9095. Direct: 0,
  9096. EntireArray: 1,
  9097. ArrayElement: 2,
  9098. HasFromToArray: 3
  9099. },
  9100. Versioning: {
  9101. None: 0,
  9102. NeedsUpdate: 1,
  9103. MatrixWorldNeedsUpdate: 2
  9104. },
  9105. GetterByBindingType: [
  9106. function getValue_direct( buffer, offset ) {
  9107. buffer[ offset ] = this.node[ this.propertyName ];
  9108. },
  9109. function getValue_array( buffer, offset ) {
  9110. var source = this.resolvedProperty;
  9111. for ( var i = 0, n = source.length; i !== n; ++ i ) {
  9112. buffer[ offset ++ ] = source[ i ];
  9113. }
  9114. },
  9115. function getValue_arrayElement( buffer, offset ) {
  9116. buffer[ offset ] = this.resolvedProperty[ this.propertyIndex ];
  9117. },
  9118. function getValue_toArray( buffer, offset ) {
  9119. this.resolvedProperty.toArray( buffer, offset );
  9120. }
  9121. ],
  9122. SetterByBindingTypeAndVersioning: [
  9123. [
  9124. // Direct
  9125. function setValue_direct( buffer, offset ) {
  9126. this.node[ this.propertyName ] = buffer[ offset ];
  9127. },
  9128. function setValue_direct_setNeedsUpdate( buffer, offset ) {
  9129. this.node[ this.propertyName ] = buffer[ offset ];
  9130. this.targetObject.needsUpdate = true;
  9131. },
  9132. function setValue_direct_setMatrixWorldNeedsUpdate( buffer, offset ) {
  9133. this.node[ this.propertyName ] = buffer[ offset ];
  9134. this.targetObject.matrixWorldNeedsUpdate = true;
  9135. }
  9136. ], [
  9137. // EntireArray
  9138. function setValue_array( buffer, offset ) {
  9139. var dest = this.resolvedProperty;
  9140. for ( var i = 0, n = dest.length; i !== n; ++ i ) {
  9141. dest[ i ] = buffer[ offset ++ ];
  9142. }
  9143. },
  9144. function setValue_array_setNeedsUpdate( buffer, offset ) {
  9145. var dest = this.resolvedProperty;
  9146. for ( var i = 0, n = dest.length; i !== n; ++ i ) {
  9147. dest[ i ] = buffer[ offset ++ ];
  9148. }
  9149. this.targetObject.needsUpdate = true;
  9150. },
  9151. function setValue_array_setMatrixWorldNeedsUpdate( buffer, offset ) {
  9152. var dest = this.resolvedProperty;
  9153. for ( var i = 0, n = dest.length; i !== n; ++ i ) {
  9154. dest[ i ] = buffer[ offset ++ ];
  9155. }
  9156. this.targetObject.matrixWorldNeedsUpdate = true;
  9157. }
  9158. ], [
  9159. // ArrayElement
  9160. function setValue_arrayElement( buffer, offset ) {
  9161. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  9162. },
  9163. function setValue_arrayElement_setNeedsUpdate( buffer, offset ) {
  9164. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  9165. this.targetObject.needsUpdate = true;
  9166. },
  9167. function setValue_arrayElement_setMatrixWorldNeedsUpdate( buffer, offset ) {
  9168. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  9169. this.targetObject.matrixWorldNeedsUpdate = true;
  9170. }
  9171. ], [
  9172. // HasToFromArray
  9173. function setValue_fromArray( buffer, offset ) {
  9174. this.resolvedProperty.fromArray( buffer, offset );
  9175. },
  9176. function setValue_fromArray_setNeedsUpdate( buffer, offset ) {
  9177. this.resolvedProperty.fromArray( buffer, offset );
  9178. this.targetObject.needsUpdate = true;
  9179. },
  9180. function setValue_fromArray_setMatrixWorldNeedsUpdate( buffer, offset ) {
  9181. this.resolvedProperty.fromArray( buffer, offset );
  9182. this.targetObject.matrixWorldNeedsUpdate = true;
  9183. }
  9184. ]
  9185. ]
  9186. } );
  9187. THREE.PropertyBinding.Composite =
  9188. function( targetGroup, path, optionalParsedPath ) {
  9189. var parsedPath = optionalParsedPath ||
  9190. THREE.PropertyBinding.parseTrackName( path );
  9191. this._targetGroup = targetGroup;
  9192. this._bindings = targetGroup.subscribe_( path, parsedPath );
  9193. };
  9194. THREE.PropertyBinding.Composite.prototype = {
  9195. constructor: THREE.PropertyBinding.Composite,
  9196. getValue: function( array, offset ) {
  9197. this.bind(); // bind all binding
  9198. var firstValidIndex = this._targetGroup.nCachedObjects_,
  9199. binding = this._bindings[ firstValidIndex ];
  9200. // and only call .getValue on the first
  9201. if ( binding !== undefined ) binding.getValue( array, offset );
  9202. },
  9203. setValue: function( array, offset ) {
  9204. var bindings = this._bindings;
  9205. for ( var i = this._targetGroup.nCachedObjects_,
  9206. n = bindings.length; i !== n; ++ i ) {
  9207. bindings[ i ].setValue( array, offset );
  9208. }
  9209. },
  9210. bind: function() {
  9211. var bindings = this._bindings;
  9212. for ( var i = this._targetGroup.nCachedObjects_,
  9213. n = bindings.length; i !== n; ++ i ) {
  9214. bindings[ i ].bind();
  9215. }
  9216. },
  9217. unbind: function() {
  9218. var bindings = this._bindings;
  9219. for ( var i = this._targetGroup.nCachedObjects_,
  9220. n = bindings.length; i !== n; ++ i ) {
  9221. bindings[ i ].unbind();
  9222. }
  9223. }
  9224. };
  9225. THREE.PropertyBinding.create = function( root, path, parsedPath ) {
  9226. if ( ! ( root instanceof THREE.AnimationObjectGroup ) ) {
  9227. return new THREE.PropertyBinding( root, path, parsedPath );
  9228. } else {
  9229. return new THREE.PropertyBinding.Composite( root, path, parsedPath );
  9230. }
  9231. };
  9232. THREE.PropertyBinding.parseTrackName = function( trackName ) {
  9233. // matches strings in the form of:
  9234. // nodeName.property
  9235. // nodeName.property[accessor]
  9236. // nodeName.material.property[accessor]
  9237. // uuid.property[accessor]
  9238. // uuid.objectName[objectIndex].propertyName[propertyIndex]
  9239. // parentName/nodeName.property
  9240. // parentName/parentName/nodeName.property[index]
  9241. // .bone[Armature.DEF_cog].position
  9242. // created and tested via https://regex101.com/#javascript
  9243. var re = /^(([\w]+\/)*)([\w-\d]+)?(\.([\w]+)(\[([\w\d\[\]\_.:\- ]+)\])?)?(\.([\w.]+)(\[([\w\d\[\]\_. ]+)\])?)$/;
  9244. var matches = re.exec( trackName );
  9245. if ( ! matches ) {
  9246. throw new Error( "cannot parse trackName at all: " + trackName );
  9247. }
  9248. if ( matches.index === re.lastIndex ) {
  9249. re.lastIndex++;
  9250. }
  9251. var results = {
  9252. // directoryName: matches[ 1 ], // (tschw) currently unused
  9253. nodeName: matches[ 3 ], // allowed to be null, specified root node.
  9254. objectName: matches[ 5 ],
  9255. objectIndex: matches[ 7 ],
  9256. propertyName: matches[ 9 ],
  9257. propertyIndex: matches[ 11 ] // allowed to be null, specifies that the whole property is set.
  9258. };
  9259. if ( results.propertyName === null || results.propertyName.length === 0 ) {
  9260. throw new Error( "can not parse propertyName from trackName: " + trackName );
  9261. }
  9262. return results;
  9263. };
  9264. THREE.PropertyBinding.findNode = function( root, nodeName ) {
  9265. if ( ! nodeName || nodeName === "" || nodeName === "root" || nodeName === "." || nodeName === -1 || nodeName === root.name || nodeName === root.uuid ) {
  9266. return root;
  9267. }
  9268. // search into skeleton bones.
  9269. if ( root.skeleton ) {
  9270. var searchSkeleton = function( skeleton ) {
  9271. for( var i = 0; i < skeleton.bones.length; i ++ ) {
  9272. var bone = skeleton.bones[ i ];
  9273. if ( bone.name === nodeName ) {
  9274. return bone;
  9275. }
  9276. }
  9277. return null;
  9278. };
  9279. var bone = searchSkeleton( root.skeleton );
  9280. if ( bone ) {
  9281. return bone;
  9282. }
  9283. }
  9284. // search into node subtree.
  9285. if ( root.children ) {
  9286. var searchNodeSubtree = function( children ) {
  9287. for( var i = 0; i < children.length; i ++ ) {
  9288. var childNode = children[ i ];
  9289. if ( childNode.name === nodeName || childNode.uuid === nodeName ) {
  9290. return childNode;
  9291. }
  9292. var result = searchNodeSubtree( childNode.children );
  9293. if ( result ) return result;
  9294. }
  9295. return null;
  9296. };
  9297. var subTreeNode = searchNodeSubtree( root.children );
  9298. if ( subTreeNode ) {
  9299. return subTreeNode;
  9300. }
  9301. }
  9302. return null;
  9303. };
  9304. // File:src/animation/PropertyMixer.js
  9305. /**
  9306. *
  9307. * Buffered scene graph property that allows weighted accumulation.
  9308. *
  9309. *
  9310. * @author Ben Houston / http://clara.io/
  9311. * @author David Sarno / http://lighthaus.us/
  9312. * @author tschw
  9313. */
  9314. THREE.PropertyMixer = function ( binding, typeName, valueSize ) {
  9315. this.binding = binding;
  9316. this.valueSize = valueSize;
  9317. var bufferType = Float64Array,
  9318. mixFunction;
  9319. switch ( typeName ) {
  9320. case 'quaternion': mixFunction = this._slerp; break;
  9321. case 'string':
  9322. case 'bool':
  9323. bufferType = Array, mixFunction = this._select; break;
  9324. default: mixFunction = this._lerp;
  9325. }
  9326. this.buffer = new bufferType( valueSize * 4 );
  9327. // layout: [ incoming | accu0 | accu1 | orig ]
  9328. //
  9329. // interpolators can use .buffer as their .result
  9330. // the data then goes to 'incoming'
  9331. //
  9332. // 'accu0' and 'accu1' are used frame-interleaved for
  9333. // the cumulative result and are compared to detect
  9334. // changes
  9335. //
  9336. // 'orig' stores the original state of the property
  9337. this._mixBufferRegion = mixFunction;
  9338. this.cumulativeWeight = 0;
  9339. this.useCount = 0;
  9340. this.referenceCount = 0;
  9341. };
  9342. THREE.PropertyMixer.prototype = {
  9343. constructor: THREE.PropertyMixer,
  9344. // accumulate data in the 'incoming' region into 'accu<i>'
  9345. accumulate: function( accuIndex, weight ) {
  9346. // note: happily accumulating nothing when weight = 0, the caller knows
  9347. // the weight and shouldn't have made the call in the first place
  9348. var buffer = this.buffer,
  9349. stride = this.valueSize,
  9350. offset = accuIndex * stride + stride,
  9351. currentWeight = this.cumulativeWeight;
  9352. if ( currentWeight === 0 ) {
  9353. // accuN := incoming * weight
  9354. for ( var i = 0; i !== stride; ++ i ) {
  9355. buffer[ offset + i ] = buffer[ i ];
  9356. }
  9357. currentWeight = weight;
  9358. } else {
  9359. // accuN := accuN + incoming * weight
  9360. currentWeight += weight;
  9361. var mix = weight / currentWeight;
  9362. this._mixBufferRegion( buffer, offset, 0, mix, stride );
  9363. }
  9364. this.cumulativeWeight = currentWeight;
  9365. },
  9366. // apply the state of 'accu<i>' to the binding when accus differ
  9367. apply: function( accuIndex ) {
  9368. var stride = this.valueSize,
  9369. buffer = this.buffer,
  9370. offset = accuIndex * stride + stride,
  9371. weight = this.cumulativeWeight,
  9372. binding = this.binding;
  9373. this.cumulativeWeight = 0;
  9374. if ( weight < 1 ) {
  9375. // accuN := accuN + original * ( 1 - cumulativeWeight )
  9376. var originalValueOffset = stride * 3;
  9377. this._mixBufferRegion(
  9378. buffer, offset, originalValueOffset, 1 - weight, stride );
  9379. }
  9380. for ( var i = stride, e = stride + stride; i !== e; ++ i ) {
  9381. if ( buffer[ i ] !== buffer[ i + stride ] ) {
  9382. // value has changed -> update scene graph
  9383. binding.setValue( buffer, offset );
  9384. break;
  9385. }
  9386. }
  9387. },
  9388. // remember the state of the bound property and copy it to both accus
  9389. saveOriginalState: function() {
  9390. var binding = this.binding;
  9391. var buffer = this.buffer,
  9392. stride = this.valueSize,
  9393. originalValueOffset = stride * 3;
  9394. binding.getValue( buffer, originalValueOffset );
  9395. // accu[0..1] := orig -- initially detect changes against the original
  9396. for ( var i = stride, e = originalValueOffset; i !== e; ++ i ) {
  9397. buffer[ i ] = buffer[ originalValueOffset + ( i % stride ) ];
  9398. }
  9399. this.cumulativeWeight = 0;
  9400. },
  9401. // apply the state previously taken via 'saveOriginalState' to the binding
  9402. restoreOriginalState: function() {
  9403. var originalValueOffset = this.valueSize * 3;
  9404. this.binding.setValue( this.buffer, originalValueOffset );
  9405. },
  9406. // mix functions
  9407. _select: function( buffer, dstOffset, srcOffset, t, stride ) {
  9408. if ( t >= 0.5 ) {
  9409. for ( var i = 0; i !== stride; ++ i ) {
  9410. buffer[ dstOffset + i ] = buffer[ srcOffset + i ];
  9411. }
  9412. }
  9413. },
  9414. _slerp: function( buffer, dstOffset, srcOffset, t, stride ) {
  9415. THREE.Quaternion.slerpFlat( buffer, dstOffset,
  9416. buffer, dstOffset, buffer, srcOffset, t );
  9417. },
  9418. _lerp: function( buffer, dstOffset, srcOffset, t, stride ) {
  9419. var s = 1 - t;
  9420. for ( var i = 0; i !== stride; ++ i ) {
  9421. var j = dstOffset + i;
  9422. buffer[ j ] = buffer[ j ] * s + buffer[ srcOffset + i ] * t;
  9423. }
  9424. }
  9425. };
  9426. // File:src/animation/tracks/BooleanKeyframeTrack.js
  9427. /**
  9428. *
  9429. * A Track of Boolean keyframe values.
  9430. *
  9431. *
  9432. * @author Ben Houston / http://clara.io/
  9433. * @author David Sarno / http://lighthaus.us/
  9434. * @author tschw
  9435. */
  9436. THREE.BooleanKeyframeTrack = function ( name, times, values ) {
  9437. THREE.KeyframeTrack.call( this, name, times, values );
  9438. };
  9439. THREE.BooleanKeyframeTrack.prototype =
  9440. Object.assign( Object.create( THREE.KeyframeTrack.prototype ), {
  9441. constructor: THREE.BooleanKeyframeTrack,
  9442. ValueTypeName: 'bool',
  9443. ValueBufferType: Array,
  9444. DefaultInterpolation: THREE.InterpolateDiscrete,
  9445. InterpolantFactoryMethodLinear: undefined,
  9446. InterpolantFactoryMethodSmooth: undefined
  9447. // Note: Actually this track could have a optimized / compressed
  9448. // representation of a single value and a custom interpolant that
  9449. // computes "firstValue ^ isOdd( index )".
  9450. } );
  9451. // File:src/animation/tracks/ColorKeyframeTrack.js
  9452. /**
  9453. *
  9454. * A Track of keyframe values that represent color.
  9455. *
  9456. *
  9457. * @author Ben Houston / http://clara.io/
  9458. * @author David Sarno / http://lighthaus.us/
  9459. * @author tschw
  9460. */
  9461. THREE.ColorKeyframeTrack = function ( name, times, values, interpolation ) {
  9462. THREE.KeyframeTrack.call( this, name, times, values, interpolation );
  9463. };
  9464. THREE.ColorKeyframeTrack.prototype =
  9465. Object.assign( Object.create( THREE.KeyframeTrack.prototype ), {
  9466. constructor: THREE.ColorKeyframeTrack,
  9467. ValueTypeName: 'color'
  9468. // ValueBufferType is inherited
  9469. // DefaultInterpolation is inherited
  9470. // Note: Very basic implementation and nothing special yet.
  9471. // However, this is the place for color space parameterization.
  9472. } );
  9473. // File:src/animation/tracks/NumberKeyframeTrack.js
  9474. /**
  9475. *
  9476. * A Track of numeric keyframe values.
  9477. *
  9478. * @author Ben Houston / http://clara.io/
  9479. * @author David Sarno / http://lighthaus.us/
  9480. * @author tschw
  9481. */
  9482. THREE.NumberKeyframeTrack = function ( name, times, values, interpolation ) {
  9483. THREE.KeyframeTrack.call( this, name, times, values, interpolation );
  9484. };
  9485. THREE.NumberKeyframeTrack.prototype =
  9486. Object.assign( Object.create( THREE.KeyframeTrack.prototype ), {
  9487. constructor: THREE.NumberKeyframeTrack,
  9488. ValueTypeName: 'number',
  9489. // ValueBufferType is inherited
  9490. // DefaultInterpolation is inherited
  9491. } );
  9492. // File:src/animation/tracks/QuaternionKeyframeTrack.js
  9493. /**
  9494. *
  9495. * A Track of quaternion keyframe values.
  9496. *
  9497. * @author Ben Houston / http://clara.io/
  9498. * @author David Sarno / http://lighthaus.us/
  9499. * @author tschw
  9500. */
  9501. THREE.QuaternionKeyframeTrack = function ( name, times, values, interpolation ) {
  9502. THREE.KeyframeTrack.call( this, name, times, values, interpolation );
  9503. };
  9504. THREE.QuaternionKeyframeTrack.prototype =
  9505. Object.assign( Object.create( THREE.KeyframeTrack.prototype ), {
  9506. constructor: THREE.QuaternionKeyframeTrack,
  9507. ValueTypeName: 'quaternion',
  9508. // ValueBufferType is inherited
  9509. DefaultInterpolation: THREE.InterpolateLinear,
  9510. InterpolantFactoryMethodLinear: function( result ) {
  9511. return new THREE.QuaternionLinearInterpolant(
  9512. this.times, this.values, this.getValueSize(), result );
  9513. },
  9514. InterpolantFactoryMethodSmooth: undefined // not yet implemented
  9515. } );
  9516. // File:src/animation/tracks/StringKeyframeTrack.js
  9517. /**
  9518. *
  9519. * A Track that interpolates Strings
  9520. *
  9521. *
  9522. * @author Ben Houston / http://clara.io/
  9523. * @author David Sarno / http://lighthaus.us/
  9524. * @author tschw
  9525. */
  9526. THREE.StringKeyframeTrack = function ( name, times, values, interpolation ) {
  9527. THREE.KeyframeTrack.call( this, name, times, values, interpolation );
  9528. };
  9529. THREE.StringKeyframeTrack.prototype =
  9530. Object.assign( Object.create( THREE.KeyframeTrack.prototype ), {
  9531. constructor: THREE.StringKeyframeTrack,
  9532. ValueTypeName: 'string',
  9533. ValueBufferType: Array,
  9534. DefaultInterpolation: THREE.InterpolateDiscrete,
  9535. InterpolantFactoryMethodLinear: undefined,
  9536. InterpolantFactoryMethodSmooth: undefined
  9537. } );
  9538. // File:src/animation/tracks/VectorKeyframeTrack.js
  9539. /**
  9540. *
  9541. * A Track of vectored keyframe values.
  9542. *
  9543. *
  9544. * @author Ben Houston / http://clara.io/
  9545. * @author David Sarno / http://lighthaus.us/
  9546. * @author tschw
  9547. */
  9548. THREE.VectorKeyframeTrack = function ( name, times, values, interpolation ) {
  9549. THREE.KeyframeTrack.call( this, name, times, values, interpolation );
  9550. };
  9551. THREE.VectorKeyframeTrack.prototype =
  9552. Object.assign( Object.create( THREE.KeyframeTrack.prototype ), {
  9553. constructor: THREE.VectorKeyframeTrack,
  9554. ValueTypeName: 'vector'
  9555. // ValueBufferType is inherited
  9556. // DefaultInterpolation is inherited
  9557. } );
  9558. // File:src/audio/Audio.js
  9559. /**
  9560. * @author mrdoob / http://mrdoob.com/
  9561. * @author Reece Aaron Lecrivain / http://reecenotes.com/
  9562. */
  9563. THREE.Audio = function ( listener ) {
  9564. THREE.Object3D.call( this );
  9565. this.type = 'Audio';
  9566. this.context = listener.context;
  9567. this.source = this.context.createBufferSource();
  9568. this.source.onended = this.onEnded.bind( this );
  9569. this.gain = this.context.createGain();
  9570. this.gain.connect( listener.getInput() );
  9571. this.autoplay = false;
  9572. this.startTime = 0;
  9573. this.playbackRate = 1;
  9574. this.isPlaying = false;
  9575. this.hasPlaybackControl = true;
  9576. this.sourceType = 'empty';
  9577. this.filters = [];
  9578. };
  9579. THREE.Audio.prototype = Object.assign( Object.create( THREE.Object3D.prototype ), {
  9580. constructor: THREE.Audio,
  9581. getOutput: function () {
  9582. return this.gain;
  9583. },
  9584. setNodeSource: function ( audioNode ) {
  9585. this.hasPlaybackControl = false;
  9586. this.sourceType = 'audioNode';
  9587. this.source = audioNode;
  9588. this.connect();
  9589. return this;
  9590. },
  9591. setBuffer: function ( audioBuffer ) {
  9592. this.source.buffer = audioBuffer;
  9593. this.sourceType = 'buffer';
  9594. if ( this.autoplay ) this.play();
  9595. return this;
  9596. },
  9597. play: function () {
  9598. if ( this.isPlaying === true ) {
  9599. console.warn( 'THREE.Audio: Audio is already playing.' );
  9600. return;
  9601. }
  9602. if ( this.hasPlaybackControl === false ) {
  9603. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  9604. return;
  9605. }
  9606. var source = this.context.createBufferSource();
  9607. source.buffer = this.source.buffer;
  9608. source.loop = this.source.loop;
  9609. source.onended = this.source.onended;
  9610. source.start( 0, this.startTime );
  9611. source.playbackRate.value = this.playbackRate;
  9612. this.isPlaying = true;
  9613. this.source = source;
  9614. return this.connect();
  9615. },
  9616. pause: function () {
  9617. if ( this.hasPlaybackControl === false ) {
  9618. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  9619. return;
  9620. }
  9621. this.source.stop();
  9622. this.startTime = this.context.currentTime;
  9623. this.isPlaying = false;
  9624. return this;
  9625. },
  9626. stop: function () {
  9627. if ( this.hasPlaybackControl === false ) {
  9628. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  9629. return;
  9630. }
  9631. this.source.stop();
  9632. this.startTime = 0;
  9633. this.isPlaying = false;
  9634. return this;
  9635. },
  9636. connect: function () {
  9637. if ( this.filters.length > 0 ) {
  9638. this.source.connect( this.filters[ 0 ] );
  9639. for ( var i = 1, l = this.filters.length; i < l; i ++ ) {
  9640. this.filters[ i - 1 ].connect( this.filters[ i ] );
  9641. }
  9642. this.filters[ this.filters.length - 1 ].connect( this.getOutput() );
  9643. } else {
  9644. this.source.connect( this.getOutput() );
  9645. }
  9646. return this;
  9647. },
  9648. disconnect: function () {
  9649. if ( this.filters.length > 0 ) {
  9650. this.source.disconnect( this.filters[ 0 ] );
  9651. for ( var i = 1, l = this.filters.length; i < l; i ++ ) {
  9652. this.filters[ i - 1 ].disconnect( this.filters[ i ] );
  9653. }
  9654. this.filters[ this.filters.length - 1 ].disconnect( this.getOutput() );
  9655. } else {
  9656. this.source.disconnect( this.getOutput() );
  9657. }
  9658. return this;
  9659. },
  9660. getFilters: function () {
  9661. return this.filters;
  9662. },
  9663. setFilters: function ( value ) {
  9664. if ( ! value ) value = [];
  9665. if ( this.isPlaying === true ) {
  9666. this.disconnect();
  9667. this.filters = value;
  9668. this.connect();
  9669. } else {
  9670. this.filters = value;
  9671. }
  9672. return this;
  9673. },
  9674. getFilter: function () {
  9675. return this.getFilters()[ 0 ];
  9676. },
  9677. setFilter: function ( filter ) {
  9678. return this.setFilters( filter ? [ filter ] : [] );
  9679. },
  9680. setPlaybackRate: function ( value ) {
  9681. if ( this.hasPlaybackControl === false ) {
  9682. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  9683. return;
  9684. }
  9685. this.playbackRate = value;
  9686. if ( this.isPlaying === true ) {
  9687. this.source.playbackRate.value = this.playbackRate;
  9688. }
  9689. return this;
  9690. },
  9691. getPlaybackRate: function () {
  9692. return this.playbackRate;
  9693. },
  9694. onEnded: function () {
  9695. this.isPlaying = false;
  9696. },
  9697. getLoop: function () {
  9698. if ( this.hasPlaybackControl === false ) {
  9699. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  9700. return false;
  9701. }
  9702. return this.source.loop;
  9703. },
  9704. setLoop: function ( value ) {
  9705. if ( this.hasPlaybackControl === false ) {
  9706. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  9707. return;
  9708. }
  9709. this.source.loop = value;
  9710. },
  9711. getVolume: function () {
  9712. return this.gain.gain.value;
  9713. },
  9714. setVolume: function ( value ) {
  9715. this.gain.gain.value = value;
  9716. return this;
  9717. }
  9718. } );
  9719. // File:src/audio/AudioAnalyser.js
  9720. /**
  9721. * @author mrdoob / http://mrdoob.com/
  9722. */
  9723. THREE.AudioAnalyser = function ( audio, fftSize ) {
  9724. this.analyser = audio.context.createAnalyser();
  9725. this.analyser.fftSize = fftSize !== undefined ? fftSize : 2048;
  9726. this.data = new Uint8Array( this.analyser.frequencyBinCount );
  9727. audio.getOutput().connect( this.analyser );
  9728. };
  9729. Object.assign( THREE.AudioAnalyser.prototype, {
  9730. getFrequencyData: function () {
  9731. this.analyser.getByteFrequencyData( this.data );
  9732. return this.data;
  9733. },
  9734. getAverageFrequency: function () {
  9735. var value = 0, data = this.getFrequencyData();
  9736. for ( var i = 0; i < data.length; i ++ ) {
  9737. value += data[ i ];
  9738. }
  9739. return value / data.length;
  9740. }
  9741. } );
  9742. // File:src/audio/AudioContext.js
  9743. /**
  9744. * @author mrdoob / http://mrdoob.com/
  9745. */
  9746. Object.defineProperty( THREE, 'AudioContext', {
  9747. get: ( function () {
  9748. var context;
  9749. return function get() {
  9750. if ( context === undefined ) {
  9751. context = new ( window.AudioContext || window.webkitAudioContext )();
  9752. }
  9753. return context;
  9754. };
  9755. } )()
  9756. } );
  9757. // File:src/audio/PositionalAudio.js
  9758. /**
  9759. * @author mrdoob / http://mrdoob.com/
  9760. */
  9761. THREE.PositionalAudio = function ( listener ) {
  9762. THREE.Audio.call( this, listener );
  9763. this.panner = this.context.createPanner();
  9764. this.panner.connect( this.gain );
  9765. };
  9766. THREE.PositionalAudio.prototype = Object.assign( Object.create( THREE.Audio.prototype ), {
  9767. constructor: THREE.PositionalAudio,
  9768. getOutput: function () {
  9769. return this.panner;
  9770. },
  9771. getRefDistance: function () {
  9772. return this.panner.refDistance;
  9773. },
  9774. setRefDistance: function ( value ) {
  9775. this.panner.refDistance = value;
  9776. },
  9777. getRolloffFactor: function () {
  9778. return this.panner.rolloffFactor;
  9779. },
  9780. setRolloffFactor: function ( value ) {
  9781. this.panner.rolloffFactor = value;
  9782. },
  9783. getDistanceModel: function () {
  9784. return this.panner.distanceModel;
  9785. },
  9786. setDistanceModel: function ( value ) {
  9787. this.panner.distanceModel = value;
  9788. },
  9789. getMaxDistance: function () {
  9790. return this.panner.maxDistance;
  9791. },
  9792. setMaxDistance: function ( value ) {
  9793. this.panner.maxDistance = value;
  9794. },
  9795. updateMatrixWorld: ( function () {
  9796. var position = new THREE.Vector3();
  9797. return function updateMatrixWorld( force ) {
  9798. THREE.Object3D.prototype.updateMatrixWorld.call( this, force );
  9799. position.setFromMatrixPosition( this.matrixWorld );
  9800. this.panner.setPosition( position.x, position.y, position.z );
  9801. };
  9802. } )()
  9803. } );
  9804. // File:src/audio/AudioListener.js
  9805. /**
  9806. * @author mrdoob / http://mrdoob.com/
  9807. */
  9808. THREE.AudioListener = function () {
  9809. THREE.Object3D.call( this );
  9810. this.type = 'AudioListener';
  9811. this.context = THREE.AudioContext;
  9812. this.gain = this.context.createGain();
  9813. this.gain.connect( this.context.destination );
  9814. this.filter = null;
  9815. };
  9816. THREE.AudioListener.prototype = Object.assign( Object.create( THREE.Object3D.prototype ), {
  9817. constructor: THREE.AudioListener,
  9818. getInput: function () {
  9819. return this.gain;
  9820. },
  9821. removeFilter: function ( ) {
  9822. if ( this.filter !== null ) {
  9823. this.gain.disconnect( this.filter );
  9824. this.filter.disconnect( this.context.destination );
  9825. this.gain.connect( this.context.destination );
  9826. this.filter = null;
  9827. }
  9828. },
  9829. getFilter: function () {
  9830. return this.filter;
  9831. },
  9832. setFilter: function ( value ) {
  9833. if ( this.filter !== null ) {
  9834. this.gain.disconnect( this.filter );
  9835. this.filter.disconnect( this.context.destination );
  9836. } else {
  9837. this.gain.disconnect( this.context.destination );
  9838. }
  9839. this.filter = value;
  9840. this.gain.connect( this.filter );
  9841. this.filter.connect( this.context.destination );
  9842. },
  9843. getMasterVolume: function () {
  9844. return this.gain.gain.value;
  9845. },
  9846. setMasterVolume: function ( value ) {
  9847. this.gain.gain.value = value;
  9848. },
  9849. updateMatrixWorld: ( function () {
  9850. var position = new THREE.Vector3();
  9851. var quaternion = new THREE.Quaternion();
  9852. var scale = new THREE.Vector3();
  9853. var orientation = new THREE.Vector3();
  9854. return function updateMatrixWorld( force ) {
  9855. THREE.Object3D.prototype.updateMatrixWorld.call( this, force );
  9856. var listener = this.context.listener;
  9857. var up = this.up;
  9858. this.matrixWorld.decompose( position, quaternion, scale );
  9859. orientation.set( 0, 0, - 1 ).applyQuaternion( quaternion );
  9860. listener.setPosition( position.x, position.y, position.z );
  9861. listener.setOrientation( orientation.x, orientation.y, orientation.z, up.x, up.y, up.z );
  9862. };
  9863. } )()
  9864. } );
  9865. // File:src/cameras/Camera.js
  9866. /**
  9867. * @author mrdoob / http://mrdoob.com/
  9868. * @author mikael emtinger / http://gomo.se/
  9869. * @author WestLangley / http://github.com/WestLangley
  9870. */
  9871. THREE.Camera = function () {
  9872. THREE.Object3D.call( this );
  9873. this.type = 'Camera';
  9874. this.matrixWorldInverse = new THREE.Matrix4();
  9875. this.projectionMatrix = new THREE.Matrix4();
  9876. };
  9877. THREE.Camera.prototype = Object.create( THREE.Object3D.prototype );
  9878. THREE.Camera.prototype.constructor = THREE.Camera;
  9879. THREE.Camera.prototype.getWorldDirection = function () {
  9880. var quaternion = new THREE.Quaternion();
  9881. return function getWorldDirection( optionalTarget ) {
  9882. var result = optionalTarget || new THREE.Vector3();
  9883. this.getWorldQuaternion( quaternion );
  9884. return result.set( 0, 0, - 1 ).applyQuaternion( quaternion );
  9885. };
  9886. }();
  9887. THREE.Camera.prototype.lookAt = function () {
  9888. // This routine does not support cameras with rotated and/or translated parent(s)
  9889. var m1 = new THREE.Matrix4();
  9890. return function lookAt( vector ) {
  9891. m1.lookAt( this.position, vector, this.up );
  9892. this.quaternion.setFromRotationMatrix( m1 );
  9893. };
  9894. }();
  9895. THREE.Camera.prototype.clone = function () {
  9896. return new this.constructor().copy( this );
  9897. };
  9898. THREE.Camera.prototype.copy = function ( source ) {
  9899. THREE.Object3D.prototype.copy.call( this, source );
  9900. this.matrixWorldInverse.copy( source.matrixWorldInverse );
  9901. this.projectionMatrix.copy( source.projectionMatrix );
  9902. return this;
  9903. };
  9904. // File:src/cameras/CubeCamera.js
  9905. /**
  9906. * Camera for rendering cube maps
  9907. * - renders scene into axis-aligned cube
  9908. *
  9909. * @author alteredq / http://alteredqualia.com/
  9910. */
  9911. THREE.CubeCamera = function ( near, far, cubeResolution ) {
  9912. THREE.Object3D.call( this );
  9913. this.type = 'CubeCamera';
  9914. var fov = 90, aspect = 1;
  9915. var cameraPX = new THREE.PerspectiveCamera( fov, aspect, near, far );
  9916. cameraPX.up.set( 0, - 1, 0 );
  9917. cameraPX.lookAt( new THREE.Vector3( 1, 0, 0 ) );
  9918. this.add( cameraPX );
  9919. var cameraNX = new THREE.PerspectiveCamera( fov, aspect, near, far );
  9920. cameraNX.up.set( 0, - 1, 0 );
  9921. cameraNX.lookAt( new THREE.Vector3( - 1, 0, 0 ) );
  9922. this.add( cameraNX );
  9923. var cameraPY = new THREE.PerspectiveCamera( fov, aspect, near, far );
  9924. cameraPY.up.set( 0, 0, 1 );
  9925. cameraPY.lookAt( new THREE.Vector3( 0, 1, 0 ) );
  9926. this.add( cameraPY );
  9927. var cameraNY = new THREE.PerspectiveCamera( fov, aspect, near, far );
  9928. cameraNY.up.set( 0, 0, - 1 );
  9929. cameraNY.lookAt( new THREE.Vector3( 0, - 1, 0 ) );
  9930. this.add( cameraNY );
  9931. var cameraPZ = new THREE.PerspectiveCamera( fov, aspect, near, far );
  9932. cameraPZ.up.set( 0, - 1, 0 );
  9933. cameraPZ.lookAt( new THREE.Vector3( 0, 0, 1 ) );
  9934. this.add( cameraPZ );
  9935. var cameraNZ = new THREE.PerspectiveCamera( fov, aspect, near, far );
  9936. cameraNZ.up.set( 0, - 1, 0 );
  9937. cameraNZ.lookAt( new THREE.Vector3( 0, 0, - 1 ) );
  9938. this.add( cameraNZ );
  9939. var options = { format: THREE.RGBFormat, magFilter: THREE.LinearFilter, minFilter: THREE.LinearFilter };
  9940. this.renderTarget = new THREE.WebGLRenderTargetCube( cubeResolution, cubeResolution, options );
  9941. this.updateCubeMap = function ( renderer, scene ) {
  9942. if ( this.parent === null ) this.updateMatrixWorld();
  9943. var renderTarget = this.renderTarget;
  9944. var generateMipmaps = renderTarget.texture.generateMipmaps;
  9945. renderTarget.texture.generateMipmaps = false;
  9946. renderTarget.activeCubeFace = 0;
  9947. renderer.render( scene, cameraPX, renderTarget );
  9948. renderTarget.activeCubeFace = 1;
  9949. renderer.render( scene, cameraNX, renderTarget );
  9950. renderTarget.activeCubeFace = 2;
  9951. renderer.render( scene, cameraPY, renderTarget );
  9952. renderTarget.activeCubeFace = 3;
  9953. renderer.render( scene, cameraNY, renderTarget );
  9954. renderTarget.activeCubeFace = 4;
  9955. renderer.render( scene, cameraPZ, renderTarget );
  9956. renderTarget.texture.generateMipmaps = generateMipmaps;
  9957. renderTarget.activeCubeFace = 5;
  9958. renderer.render( scene, cameraNZ, renderTarget );
  9959. renderer.setRenderTarget( null );
  9960. };
  9961. };
  9962. THREE.CubeCamera.prototype = Object.create( THREE.Object3D.prototype );
  9963. THREE.CubeCamera.prototype.constructor = THREE.CubeCamera;
  9964. // File:src/cameras/OrthographicCamera.js
  9965. /**
  9966. * @author alteredq / http://alteredqualia.com/
  9967. * @author arose / http://github.com/arose
  9968. */
  9969. THREE.OrthographicCamera = function ( left, right, top, bottom, near, far ) {
  9970. THREE.Camera.call( this );
  9971. this.type = 'OrthographicCamera';
  9972. this.zoom = 1;
  9973. this.view = null;
  9974. this.left = left;
  9975. this.right = right;
  9976. this.top = top;
  9977. this.bottom = bottom;
  9978. this.near = ( near !== undefined ) ? near : 0.1;
  9979. this.far = ( far !== undefined ) ? far : 2000;
  9980. this.updateProjectionMatrix();
  9981. };
  9982. THREE.OrthographicCamera.prototype = Object.assign( Object.create( THREE.Camera.prototype ), {
  9983. constructor: THREE.OrthographicCamera,
  9984. copy: function ( source ) {
  9985. THREE.Camera.prototype.copy.call( this, source );
  9986. this.left = source.left;
  9987. this.right = source.right;
  9988. this.top = source.top;
  9989. this.bottom = source.bottom;
  9990. this.near = source.near;
  9991. this.far = source.far;
  9992. this.zoom = source.zoom;
  9993. this.view = source.view === null ? null : Object.assign( {}, source.view );
  9994. return this;
  9995. },
  9996. setViewOffset: function( fullWidth, fullHeight, x, y, width, height ) {
  9997. this.view = {
  9998. fullWidth: fullWidth,
  9999. fullHeight: fullHeight,
  10000. offsetX: x,
  10001. offsetY: y,
  10002. width: width,
  10003. height: height
  10004. };
  10005. this.updateProjectionMatrix();
  10006. },
  10007. clearViewOffset: function() {
  10008. this.view = null;
  10009. this.updateProjectionMatrix();
  10010. },
  10011. updateProjectionMatrix: function () {
  10012. var dx = ( this.right - this.left ) / ( 2 * this.zoom );
  10013. var dy = ( this.top - this.bottom ) / ( 2 * this.zoom );
  10014. var cx = ( this.right + this.left ) / 2;
  10015. var cy = ( this.top + this.bottom ) / 2;
  10016. var left = cx - dx;
  10017. var right = cx + dx;
  10018. var top = cy + dy;
  10019. var bottom = cy - dy;
  10020. if ( this.view !== null ) {
  10021. var zoomW = this.zoom / ( this.view.width / this.view.fullWidth );
  10022. var zoomH = this.zoom / ( this.view.height / this.view.fullHeight );
  10023. var scaleW = ( this.right - this.left ) / this.view.width;
  10024. var scaleH = ( this.top - this.bottom ) / this.view.height;
  10025. left += scaleW * ( this.view.offsetX / zoomW );
  10026. right = left + scaleW * ( this.view.width / zoomW );
  10027. top -= scaleH * ( this.view.offsetY / zoomH );
  10028. bottom = top - scaleH * ( this.view.height / zoomH );
  10029. }
  10030. this.projectionMatrix.makeOrthographic( left, right, top, bottom, this.near, this.far );
  10031. },
  10032. toJSON: function ( meta ) {
  10033. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  10034. data.object.zoom = this.zoom;
  10035. data.object.left = this.left;
  10036. data.object.right = this.right;
  10037. data.object.top = this.top;
  10038. data.object.bottom = this.bottom;
  10039. data.object.near = this.near;
  10040. data.object.far = this.far;
  10041. if ( this.view !== null ) data.object.view = Object.assign( {}, this.view );
  10042. return data;
  10043. }
  10044. } );
  10045. // File:src/cameras/PerspectiveCamera.js
  10046. /**
  10047. * @author mrdoob / http://mrdoob.com/
  10048. * @author greggman / http://games.greggman.com/
  10049. * @author zz85 / http://www.lab4games.net/zz85/blog
  10050. * @author tschw
  10051. */
  10052. THREE.PerspectiveCamera = function( fov, aspect, near, far ) {
  10053. THREE.Camera.call( this );
  10054. this.type = 'PerspectiveCamera';
  10055. this.fov = fov !== undefined ? fov : 50;
  10056. this.zoom = 1;
  10057. this.near = near !== undefined ? near : 0.1;
  10058. this.far = far !== undefined ? far : 2000;
  10059. this.focus = 10;
  10060. this.aspect = aspect !== undefined ? aspect : 1;
  10061. this.view = null;
  10062. this.filmGauge = 35; // width of the film (default in millimeters)
  10063. this.filmOffset = 0; // horizontal film offset (same unit as gauge)
  10064. this.updateProjectionMatrix();
  10065. };
  10066. THREE.PerspectiveCamera.prototype = Object.assign( Object.create( THREE.Camera.prototype ), {
  10067. constructor: THREE.PerspectiveCamera,
  10068. copy: function ( source ) {
  10069. THREE.Camera.prototype.copy.call( this, source );
  10070. this.fov = source.fov;
  10071. this.zoom = source.zoom;
  10072. this.near = source.near;
  10073. this.far = source.far;
  10074. this.focus = source.focus;
  10075. this.aspect = source.aspect;
  10076. this.view = source.view === null ? null : Object.assign( {}, source.view );
  10077. this.filmGauge = source.filmGauge;
  10078. this.filmOffset = source.filmOffset;
  10079. return this;
  10080. },
  10081. /**
  10082. * Sets the FOV by focal length in respect to the current .filmGauge.
  10083. *
  10084. * The default film gauge is 35, so that the focal length can be specified for
  10085. * a 35mm (full frame) camera.
  10086. *
  10087. * Values for focal length and film gauge must have the same unit.
  10088. */
  10089. setFocalLength: function ( focalLength ) {
  10090. // see http://www.bobatkins.com/photography/technical/field_of_view.html
  10091. var vExtentSlope = 0.5 * this.getFilmHeight() / focalLength;
  10092. this.fov = THREE.Math.RAD2DEG * 2 * Math.atan( vExtentSlope );
  10093. this.updateProjectionMatrix();
  10094. },
  10095. /**
  10096. * Calculates the focal length from the current .fov and .filmGauge.
  10097. */
  10098. getFocalLength: function () {
  10099. var vExtentSlope = Math.tan( THREE.Math.DEG2RAD * 0.5 * this.fov );
  10100. return 0.5 * this.getFilmHeight() / vExtentSlope;
  10101. },
  10102. getEffectiveFOV: function () {
  10103. return THREE.Math.RAD2DEG * 2 * Math.atan(
  10104. Math.tan( THREE.Math.DEG2RAD * 0.5 * this.fov ) / this.zoom );
  10105. },
  10106. getFilmWidth: function () {
  10107. // film not completely covered in portrait format (aspect < 1)
  10108. return this.filmGauge * Math.min( this.aspect, 1 );
  10109. },
  10110. getFilmHeight: function () {
  10111. // film not completely covered in landscape format (aspect > 1)
  10112. return this.filmGauge / Math.max( this.aspect, 1 );
  10113. },
  10114. /**
  10115. * Sets an offset in a larger frustum. This is useful for multi-window or
  10116. * multi-monitor/multi-machine setups.
  10117. *
  10118. * For example, if you have 3x2 monitors and each monitor is 1920x1080 and
  10119. * the monitors are in grid like this
  10120. *
  10121. * +---+---+---+
  10122. * | A | B | C |
  10123. * +---+---+---+
  10124. * | D | E | F |
  10125. * +---+---+---+
  10126. *
  10127. * then for each monitor you would call it like this
  10128. *
  10129. * var w = 1920;
  10130. * var h = 1080;
  10131. * var fullWidth = w * 3;
  10132. * var fullHeight = h * 2;
  10133. *
  10134. * --A--
  10135. * camera.setOffset( fullWidth, fullHeight, w * 0, h * 0, w, h );
  10136. * --B--
  10137. * camera.setOffset( fullWidth, fullHeight, w * 1, h * 0, w, h );
  10138. * --C--
  10139. * camera.setOffset( fullWidth, fullHeight, w * 2, h * 0, w, h );
  10140. * --D--
  10141. * camera.setOffset( fullWidth, fullHeight, w * 0, h * 1, w, h );
  10142. * --E--
  10143. * camera.setOffset( fullWidth, fullHeight, w * 1, h * 1, w, h );
  10144. * --F--
  10145. * camera.setOffset( fullWidth, fullHeight, w * 2, h * 1, w, h );
  10146. *
  10147. * Note there is no reason monitors have to be the same size or in a grid.
  10148. */
  10149. setViewOffset: function ( fullWidth, fullHeight, x, y, width, height ) {
  10150. this.aspect = fullWidth / fullHeight;
  10151. this.view = {
  10152. fullWidth: fullWidth,
  10153. fullHeight: fullHeight,
  10154. offsetX: x,
  10155. offsetY: y,
  10156. width: width,
  10157. height: height
  10158. };
  10159. this.updateProjectionMatrix();
  10160. },
  10161. clearViewOffset: function() {
  10162. this.view = null;
  10163. this.updateProjectionMatrix();
  10164. },
  10165. updateProjectionMatrix: function () {
  10166. var near = this.near,
  10167. top = near * Math.tan(
  10168. THREE.Math.DEG2RAD * 0.5 * this.fov ) / this.zoom,
  10169. height = 2 * top,
  10170. width = this.aspect * height,
  10171. left = - 0.5 * width,
  10172. view = this.view;
  10173. if ( view !== null ) {
  10174. var fullWidth = view.fullWidth,
  10175. fullHeight = view.fullHeight;
  10176. left += view.offsetX * width / fullWidth;
  10177. top -= view.offsetY * height / fullHeight;
  10178. width *= view.width / fullWidth;
  10179. height *= view.height / fullHeight;
  10180. }
  10181. var skew = this.filmOffset;
  10182. if ( skew !== 0 ) left += near * skew / this.getFilmWidth();
  10183. this.projectionMatrix.makeFrustum(
  10184. left, left + width, top - height, top, near, this.far );
  10185. },
  10186. toJSON: function ( meta ) {
  10187. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  10188. data.object.fov = this.fov;
  10189. data.object.zoom = this.zoom;
  10190. data.object.near = this.near;
  10191. data.object.far = this.far;
  10192. data.object.focus = this.focus;
  10193. data.object.aspect = this.aspect;
  10194. if ( this.view !== null ) data.object.view = Object.assign( {}, this.view );
  10195. data.object.filmGauge = this.filmGauge;
  10196. data.object.filmOffset = this.filmOffset;
  10197. return data;
  10198. }
  10199. } );
  10200. // File:src/cameras/StereoCamera.js
  10201. /**
  10202. * @author mrdoob / http://mrdoob.com/
  10203. */
  10204. THREE.StereoCamera = function () {
  10205. this.type = 'StereoCamera';
  10206. this.aspect = 1;
  10207. this.cameraL = new THREE.PerspectiveCamera();
  10208. this.cameraL.layers.enable( 1 );
  10209. this.cameraL.matrixAutoUpdate = false;
  10210. this.cameraR = new THREE.PerspectiveCamera();
  10211. this.cameraR.layers.enable( 2 );
  10212. this.cameraR.matrixAutoUpdate = false;
  10213. };
  10214. Object.assign( THREE.StereoCamera.prototype, {
  10215. update: ( function () {
  10216. var focus, fov, aspect, near, far;
  10217. var eyeRight = new THREE.Matrix4();
  10218. var eyeLeft = new THREE.Matrix4();
  10219. return function update( camera ) {
  10220. var needsUpdate = focus !== camera.focus || fov !== camera.fov ||
  10221. aspect !== camera.aspect * this.aspect || near !== camera.near ||
  10222. far !== camera.far;
  10223. if ( needsUpdate ) {
  10224. focus = camera.focus;
  10225. fov = camera.fov;
  10226. aspect = camera.aspect * this.aspect;
  10227. near = camera.near;
  10228. far = camera.far;
  10229. // Off-axis stereoscopic effect based on
  10230. // http://paulbourke.net/stereographics/stereorender/
  10231. var projectionMatrix = camera.projectionMatrix.clone();
  10232. var eyeSep = 0.064 / 2;
  10233. var eyeSepOnProjection = eyeSep * near / focus;
  10234. var ymax = near * Math.tan( THREE.Math.DEG2RAD * fov * 0.5 );
  10235. var xmin, xmax;
  10236. // translate xOffset
  10237. eyeLeft.elements[ 12 ] = - eyeSep;
  10238. eyeRight.elements[ 12 ] = eyeSep;
  10239. // for left eye
  10240. xmin = - ymax * aspect + eyeSepOnProjection;
  10241. xmax = ymax * aspect + eyeSepOnProjection;
  10242. projectionMatrix.elements[ 0 ] = 2 * near / ( xmax - xmin );
  10243. projectionMatrix.elements[ 8 ] = ( xmax + xmin ) / ( xmax - xmin );
  10244. this.cameraL.projectionMatrix.copy( projectionMatrix );
  10245. // for right eye
  10246. xmin = - ymax * aspect - eyeSepOnProjection;
  10247. xmax = ymax * aspect - eyeSepOnProjection;
  10248. projectionMatrix.elements[ 0 ] = 2 * near / ( xmax - xmin );
  10249. projectionMatrix.elements[ 8 ] = ( xmax + xmin ) / ( xmax - xmin );
  10250. this.cameraR.projectionMatrix.copy( projectionMatrix );
  10251. }
  10252. this.cameraL.matrixWorld.copy( camera.matrixWorld ).multiply( eyeLeft );
  10253. this.cameraR.matrixWorld.copy( camera.matrixWorld ).multiply( eyeRight );
  10254. };
  10255. } )()
  10256. } );
  10257. // File:src/lights/Light.js
  10258. /**
  10259. * @author mrdoob / http://mrdoob.com/
  10260. * @author alteredq / http://alteredqualia.com/
  10261. */
  10262. THREE.Light = function ( color, intensity ) {
  10263. THREE.Object3D.call( this );
  10264. this.type = 'Light';
  10265. this.color = new THREE.Color( color );
  10266. this.intensity = intensity !== undefined ? intensity : 1;
  10267. this.receiveShadow = undefined;
  10268. };
  10269. THREE.Light.prototype = Object.assign( Object.create( THREE.Object3D.prototype ), {
  10270. constructor: THREE.Light,
  10271. copy: function ( source ) {
  10272. THREE.Object3D.prototype.copy.call( this, source );
  10273. this.color.copy( source.color );
  10274. this.intensity = source.intensity;
  10275. return this;
  10276. },
  10277. toJSON: function ( meta ) {
  10278. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  10279. data.object.color = this.color.getHex();
  10280. data.object.intensity = this.intensity;
  10281. if ( this.groundColor !== undefined ) data.object.groundColor = this.groundColor.getHex();
  10282. if ( this.distance !== undefined ) data.object.distance = this.distance;
  10283. if ( this.angle !== undefined ) data.object.angle = this.angle;
  10284. if ( this.decay !== undefined ) data.object.decay = this.decay;
  10285. if ( this.penumbra !== undefined ) data.object.penumbra = this.penumbra;
  10286. return data;
  10287. }
  10288. } );
  10289. // File:src/lights/LightShadow.js
  10290. /**
  10291. * @author mrdoob / http://mrdoob.com/
  10292. */
  10293. THREE.LightShadow = function ( camera ) {
  10294. this.camera = camera;
  10295. this.bias = 0;
  10296. this.radius = 1;
  10297. this.mapSize = new THREE.Vector2( 512, 512 );
  10298. this.map = null;
  10299. this.matrix = new THREE.Matrix4();
  10300. };
  10301. Object.assign( THREE.LightShadow.prototype, {
  10302. copy: function ( source ) {
  10303. this.camera = source.camera.clone();
  10304. this.bias = source.bias;
  10305. this.radius = source.radius;
  10306. this.mapSize.copy( source.mapSize );
  10307. return this;
  10308. },
  10309. clone: function () {
  10310. return new this.constructor().copy( this );
  10311. }
  10312. } );
  10313. // File:src/lights/AmbientLight.js
  10314. /**
  10315. * @author mrdoob / http://mrdoob.com/
  10316. */
  10317. THREE.AmbientLight = function ( color, intensity ) {
  10318. THREE.Light.call( this, color, intensity );
  10319. this.type = 'AmbientLight';
  10320. this.castShadow = undefined;
  10321. };
  10322. THREE.AmbientLight.prototype = Object.assign( Object.create( THREE.Light.prototype ), {
  10323. constructor: THREE.AmbientLight
  10324. } );
  10325. // File:src/lights/DirectionalLight.js
  10326. /**
  10327. * @author mrdoob / http://mrdoob.com/
  10328. * @author alteredq / http://alteredqualia.com/
  10329. */
  10330. THREE.DirectionalLight = function ( color, intensity ) {
  10331. THREE.Light.call( this, color, intensity );
  10332. this.type = 'DirectionalLight';
  10333. this.position.set( 0, 1, 0 );
  10334. this.updateMatrix();
  10335. this.target = new THREE.Object3D();
  10336. this.shadow = new THREE.DirectionalLightShadow();
  10337. };
  10338. THREE.DirectionalLight.prototype = Object.assign( Object.create( THREE.Light.prototype ), {
  10339. constructor: THREE.DirectionalLight,
  10340. copy: function ( source ) {
  10341. THREE.Light.prototype.copy.call( this, source );
  10342. this.target = source.target.clone();
  10343. this.shadow = source.shadow.clone();
  10344. return this;
  10345. }
  10346. } );
  10347. // File:src/lights/DirectionalLightShadow.js
  10348. /**
  10349. * @author mrdoob / http://mrdoob.com/
  10350. */
  10351. THREE.DirectionalLightShadow = function ( light ) {
  10352. THREE.LightShadow.call( this, new THREE.OrthographicCamera( - 5, 5, 5, - 5, 0.5, 500 ) );
  10353. };
  10354. THREE.DirectionalLightShadow.prototype = Object.assign( Object.create( THREE.LightShadow.prototype ), {
  10355. constructor: THREE.DirectionalLightShadow
  10356. } );
  10357. // File:src/lights/HemisphereLight.js
  10358. /**
  10359. * @author alteredq / http://alteredqualia.com/
  10360. */
  10361. THREE.HemisphereLight = function ( skyColor, groundColor, intensity ) {
  10362. THREE.Light.call( this, skyColor, intensity );
  10363. this.type = 'HemisphereLight';
  10364. this.castShadow = undefined;
  10365. this.position.set( 0, 1, 0 );
  10366. this.updateMatrix();
  10367. this.groundColor = new THREE.Color( groundColor );
  10368. };
  10369. THREE.HemisphereLight.prototype = Object.assign( Object.create( THREE.Light.prototype ), {
  10370. constructor: THREE.HemisphereLight,
  10371. copy: function ( source ) {
  10372. THREE.Light.prototype.copy.call( this, source );
  10373. this.groundColor.copy( source.groundColor );
  10374. return this;
  10375. }
  10376. } );
  10377. // File:src/lights/PointLight.js
  10378. /**
  10379. * @author mrdoob / http://mrdoob.com/
  10380. */
  10381. THREE.PointLight = function ( color, intensity, distance, decay ) {
  10382. THREE.Light.call( this, color, intensity );
  10383. this.type = 'PointLight';
  10384. Object.defineProperty( this, 'power', {
  10385. get: function () {
  10386. // intensity = power per solid angle.
  10387. // ref: equation (15) from http://www.frostbite.com/wp-content/uploads/2014/11/course_notes_moving_frostbite_to_pbr.pdf
  10388. return this.intensity * 4 * Math.PI;
  10389. },
  10390. set: function ( power ) {
  10391. // intensity = power per solid angle.
  10392. // ref: equation (15) from http://www.frostbite.com/wp-content/uploads/2014/11/course_notes_moving_frostbite_to_pbr.pdf
  10393. this.intensity = power / ( 4 * Math.PI );
  10394. }
  10395. } );
  10396. this.distance = ( distance !== undefined ) ? distance : 0;
  10397. this.decay = ( decay !== undefined ) ? decay : 1; // for physically correct lights, should be 2.
  10398. this.shadow = new THREE.LightShadow( new THREE.PerspectiveCamera( 90, 1, 0.5, 500 ) );
  10399. };
  10400. THREE.PointLight.prototype = Object.assign( Object.create( THREE.Light.prototype ), {
  10401. constructor: THREE.PointLight,
  10402. copy: function ( source ) {
  10403. THREE.Light.prototype.copy.call( this, source );
  10404. this.distance = source.distance;
  10405. this.decay = source.decay;
  10406. this.shadow = source.shadow.clone();
  10407. return this;
  10408. }
  10409. } );
  10410. // File:src/lights/SpotLight.js
  10411. /**
  10412. * @author alteredq / http://alteredqualia.com/
  10413. */
  10414. THREE.SpotLight = function ( color, intensity, distance, angle, penumbra, decay ) {
  10415. THREE.Light.call( this, color, intensity );
  10416. this.type = 'SpotLight';
  10417. this.position.set( 0, 1, 0 );
  10418. this.updateMatrix();
  10419. this.target = new THREE.Object3D();
  10420. Object.defineProperty( this, 'power', {
  10421. get: function () {
  10422. // intensity = power per solid angle.
  10423. // ref: equation (17) from http://www.frostbite.com/wp-content/uploads/2014/11/course_notes_moving_frostbite_to_pbr.pdf
  10424. return this.intensity * Math.PI;
  10425. },
  10426. set: function ( power ) {
  10427. // intensity = power per solid angle.
  10428. // ref: equation (17) from http://www.frostbite.com/wp-content/uploads/2014/11/course_notes_moving_frostbite_to_pbr.pdf
  10429. this.intensity = power / Math.PI;
  10430. }
  10431. } );
  10432. this.distance = ( distance !== undefined ) ? distance : 0;
  10433. this.angle = ( angle !== undefined ) ? angle : Math.PI / 3;
  10434. this.penumbra = ( penumbra !== undefined ) ? penumbra : 0;
  10435. this.decay = ( decay !== undefined ) ? decay : 1; // for physically correct lights, should be 2.
  10436. this.shadow = new THREE.SpotLightShadow();
  10437. };
  10438. THREE.SpotLight.prototype = Object.assign( Object.create( THREE.Light.prototype ), {
  10439. constructor: THREE.SpotLight,
  10440. copy: function ( source ) {
  10441. THREE.Light.prototype.copy.call( this, source );
  10442. this.distance = source.distance;
  10443. this.angle = source.angle;
  10444. this.penumbra = source.penumbra;
  10445. this.decay = source.decay;
  10446. this.target = source.target.clone();
  10447. this.shadow = source.shadow.clone();
  10448. return this;
  10449. }
  10450. } );
  10451. // File:src/lights/SpotLightShadow.js
  10452. /**
  10453. * @author mrdoob / http://mrdoob.com/
  10454. */
  10455. THREE.SpotLightShadow = function () {
  10456. THREE.LightShadow.call( this, new THREE.PerspectiveCamera( 50, 1, 0.5, 500 ) );
  10457. };
  10458. THREE.SpotLightShadow.prototype = Object.assign( Object.create( THREE.LightShadow.prototype ), {
  10459. constructor: THREE.SpotLightShadow,
  10460. update: function ( light ) {
  10461. var fov = THREE.Math.RAD2DEG * 2 * light.angle;
  10462. var aspect = this.mapSize.width / this.mapSize.height;
  10463. var far = light.distance || 500;
  10464. var camera = this.camera;
  10465. if ( fov !== camera.fov || aspect !== camera.aspect || far !== camera.far ) {
  10466. camera.fov = fov;
  10467. camera.aspect = aspect;
  10468. camera.far = far;
  10469. camera.updateProjectionMatrix();
  10470. }
  10471. }
  10472. } );
  10473. // File:src/loaders/AudioLoader.js
  10474. /**
  10475. * @author Reece Aaron Lecrivain / http://reecenotes.com/
  10476. */
  10477. THREE.AudioLoader = function ( manager ) {
  10478. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  10479. };
  10480. Object.assign( THREE.AudioLoader.prototype, {
  10481. load: function ( url, onLoad, onProgress, onError ) {
  10482. var loader = new THREE.XHRLoader( this.manager );
  10483. loader.setResponseType( 'arraybuffer' );
  10484. loader.load( url, function ( buffer ) {
  10485. var context = THREE.AudioContext;
  10486. context.decodeAudioData( buffer, function ( audioBuffer ) {
  10487. onLoad( audioBuffer );
  10488. } );
  10489. }, onProgress, onError );
  10490. }
  10491. } );
  10492. // File:src/loaders/Cache.js
  10493. /**
  10494. * @author mrdoob / http://mrdoob.com/
  10495. */
  10496. THREE.Cache = {
  10497. enabled: false,
  10498. files: {},
  10499. add: function ( key, file ) {
  10500. if ( this.enabled === false ) return;
  10501. // console.log( 'THREE.Cache', 'Adding key:', key );
  10502. this.files[ key ] = file;
  10503. },
  10504. get: function ( key ) {
  10505. if ( this.enabled === false ) return;
  10506. // console.log( 'THREE.Cache', 'Checking key:', key );
  10507. return this.files[ key ];
  10508. },
  10509. remove: function ( key ) {
  10510. delete this.files[ key ];
  10511. },
  10512. clear: function () {
  10513. this.files = {};
  10514. }
  10515. };
  10516. // File:src/loaders/Loader.js
  10517. /**
  10518. * @author alteredq / http://alteredqualia.com/
  10519. */
  10520. THREE.Loader = function () {
  10521. this.onLoadStart = function () {};
  10522. this.onLoadProgress = function () {};
  10523. this.onLoadComplete = function () {};
  10524. };
  10525. THREE.Loader.prototype = {
  10526. constructor: THREE.Loader,
  10527. crossOrigin: undefined,
  10528. extractUrlBase: function ( url ) {
  10529. var parts = url.split( '/' );
  10530. if ( parts.length === 1 ) return './';
  10531. parts.pop();
  10532. return parts.join( '/' ) + '/';
  10533. },
  10534. initMaterials: function ( materials, texturePath, crossOrigin ) {
  10535. var array = [];
  10536. for ( var i = 0; i < materials.length; ++ i ) {
  10537. array[ i ] = this.createMaterial( materials[ i ], texturePath, crossOrigin );
  10538. }
  10539. return array;
  10540. },
  10541. createMaterial: ( function () {
  10542. var color, textureLoader, materialLoader;
  10543. return function createMaterial( m, texturePath, crossOrigin ) {
  10544. if ( color === undefined ) color = new THREE.Color();
  10545. if ( textureLoader === undefined ) textureLoader = new THREE.TextureLoader();
  10546. if ( materialLoader === undefined ) materialLoader = new THREE.MaterialLoader();
  10547. // convert from old material format
  10548. var textures = {};
  10549. function loadTexture( path, repeat, offset, wrap, anisotropy ) {
  10550. var fullPath = texturePath + path;
  10551. var loader = THREE.Loader.Handlers.get( fullPath );
  10552. var texture;
  10553. if ( loader !== null ) {
  10554. texture = loader.load( fullPath );
  10555. } else {
  10556. textureLoader.setCrossOrigin( crossOrigin );
  10557. texture = textureLoader.load( fullPath );
  10558. }
  10559. if ( repeat !== undefined ) {
  10560. texture.repeat.fromArray( repeat );
  10561. if ( repeat[ 0 ] !== 1 ) texture.wrapS = THREE.RepeatWrapping;
  10562. if ( repeat[ 1 ] !== 1 ) texture.wrapT = THREE.RepeatWrapping;
  10563. }
  10564. if ( offset !== undefined ) {
  10565. texture.offset.fromArray( offset );
  10566. }
  10567. if ( wrap !== undefined ) {
  10568. if ( wrap[ 0 ] === 'repeat' ) texture.wrapS = THREE.RepeatWrapping;
  10569. if ( wrap[ 0 ] === 'mirror' ) texture.wrapS = THREE.MirroredRepeatWrapping;
  10570. if ( wrap[ 1 ] === 'repeat' ) texture.wrapT = THREE.RepeatWrapping;
  10571. if ( wrap[ 1 ] === 'mirror' ) texture.wrapT = THREE.MirroredRepeatWrapping;
  10572. }
  10573. if ( anisotropy !== undefined ) {
  10574. texture.anisotropy = anisotropy;
  10575. }
  10576. var uuid = THREE.Math.generateUUID();
  10577. textures[ uuid ] = texture;
  10578. return uuid;
  10579. }
  10580. //
  10581. var json = {
  10582. uuid: THREE.Math.generateUUID(),
  10583. type: 'MeshLambertMaterial'
  10584. };
  10585. for ( var name in m ) {
  10586. var value = m[ name ];
  10587. switch ( name ) {
  10588. case 'DbgColor':
  10589. case 'DbgIndex':
  10590. case 'opticalDensity':
  10591. case 'illumination':
  10592. break;
  10593. case 'DbgName':
  10594. json.name = value;
  10595. break;
  10596. case 'blending':
  10597. json.blending = THREE[ value ];
  10598. break;
  10599. case 'colorAmbient':
  10600. case 'mapAmbient':
  10601. console.warn( 'THREE.Loader.createMaterial:', name, 'is no longer supported.' );
  10602. break;
  10603. case 'colorDiffuse':
  10604. json.color = color.fromArray( value ).getHex();
  10605. break;
  10606. case 'colorSpecular':
  10607. json.specular = color.fromArray( value ).getHex();
  10608. break;
  10609. case 'colorEmissive':
  10610. json.emissive = color.fromArray( value ).getHex();
  10611. break;
  10612. case 'specularCoef':
  10613. json.shininess = value;
  10614. break;
  10615. case 'shading':
  10616. if ( value.toLowerCase() === 'basic' ) json.type = 'MeshBasicMaterial';
  10617. if ( value.toLowerCase() === 'phong' ) json.type = 'MeshPhongMaterial';
  10618. if ( value.toLowerCase() === 'standard' ) json.type = 'MeshStandardMaterial';
  10619. break;
  10620. case 'mapDiffuse':
  10621. json.map = loadTexture( value, m.mapDiffuseRepeat, m.mapDiffuseOffset, m.mapDiffuseWrap, m.mapDiffuseAnisotropy );
  10622. break;
  10623. case 'mapDiffuseRepeat':
  10624. case 'mapDiffuseOffset':
  10625. case 'mapDiffuseWrap':
  10626. case 'mapDiffuseAnisotropy':
  10627. break;
  10628. case 'mapEmissive':
  10629. json.emissiveMap = loadTexture( value, m.mapEmissiveRepeat, m.mapEmissiveOffset, m.mapEmissiveWrap, m.mapEmissiveAnisotropy );
  10630. break;
  10631. case 'mapEmissiveRepeat':
  10632. case 'mapEmissiveOffset':
  10633. case 'mapEmissiveWrap':
  10634. case 'mapEmissiveAnisotropy':
  10635. break;
  10636. case 'mapLight':
  10637. json.lightMap = loadTexture( value, m.mapLightRepeat, m.mapLightOffset, m.mapLightWrap, m.mapLightAnisotropy );
  10638. break;
  10639. case 'mapLightRepeat':
  10640. case 'mapLightOffset':
  10641. case 'mapLightWrap':
  10642. case 'mapLightAnisotropy':
  10643. break;
  10644. case 'mapAO':
  10645. json.aoMap = loadTexture( value, m.mapAORepeat, m.mapAOOffset, m.mapAOWrap, m.mapAOAnisotropy );
  10646. break;
  10647. case 'mapAORepeat':
  10648. case 'mapAOOffset':
  10649. case 'mapAOWrap':
  10650. case 'mapAOAnisotropy':
  10651. break;
  10652. case 'mapBump':
  10653. json.bumpMap = loadTexture( value, m.mapBumpRepeat, m.mapBumpOffset, m.mapBumpWrap, m.mapBumpAnisotropy );
  10654. break;
  10655. case 'mapBumpScale':
  10656. json.bumpScale = value;
  10657. break;
  10658. case 'mapBumpRepeat':
  10659. case 'mapBumpOffset':
  10660. case 'mapBumpWrap':
  10661. case 'mapBumpAnisotropy':
  10662. break;
  10663. case 'mapNormal':
  10664. json.normalMap = loadTexture( value, m.mapNormalRepeat, m.mapNormalOffset, m.mapNormalWrap, m.mapNormalAnisotropy );
  10665. break;
  10666. case 'mapNormalFactor':
  10667. json.normalScale = [ value, value ];
  10668. break;
  10669. case 'mapNormalRepeat':
  10670. case 'mapNormalOffset':
  10671. case 'mapNormalWrap':
  10672. case 'mapNormalAnisotropy':
  10673. break;
  10674. case 'mapSpecular':
  10675. json.specularMap = loadTexture( value, m.mapSpecularRepeat, m.mapSpecularOffset, m.mapSpecularWrap, m.mapSpecularAnisotropy );
  10676. break;
  10677. case 'mapSpecularRepeat':
  10678. case 'mapSpecularOffset':
  10679. case 'mapSpecularWrap':
  10680. case 'mapSpecularAnisotropy':
  10681. break;
  10682. case 'mapMetalness':
  10683. json.metalnessMap = loadTexture( value, m.mapMetalnessRepeat, m.mapMetalnessOffset, m.mapMetalnessWrap, m.mapMetalnessAnisotropy );
  10684. break;
  10685. case 'mapMetalnessRepeat':
  10686. case 'mapMetalnessOffset':
  10687. case 'mapMetalnessWrap':
  10688. case 'mapMetalnessAnisotropy':
  10689. break;
  10690. case 'mapRoughness':
  10691. json.roughnessMap = loadTexture( value, m.mapRoughnessRepeat, m.mapRoughnessOffset, m.mapRoughnessWrap, m.mapRoughnessAnisotropy );
  10692. break;
  10693. case 'mapRoughnessRepeat':
  10694. case 'mapRoughnessOffset':
  10695. case 'mapRoughnessWrap':
  10696. case 'mapRoughnessAnisotropy':
  10697. break;
  10698. case 'mapAlpha':
  10699. json.alphaMap = loadTexture( value, m.mapAlphaRepeat, m.mapAlphaOffset, m.mapAlphaWrap, m.mapAlphaAnisotropy );
  10700. break;
  10701. case 'mapAlphaRepeat':
  10702. case 'mapAlphaOffset':
  10703. case 'mapAlphaWrap':
  10704. case 'mapAlphaAnisotropy':
  10705. break;
  10706. case 'flipSided':
  10707. json.side = THREE.BackSide;
  10708. break;
  10709. case 'doubleSided':
  10710. json.side = THREE.DoubleSide;
  10711. break;
  10712. case 'transparency':
  10713. console.warn( 'THREE.Loader.createMaterial: transparency has been renamed to opacity' );
  10714. json.opacity = value;
  10715. break;
  10716. case 'depthTest':
  10717. case 'depthWrite':
  10718. case 'colorWrite':
  10719. case 'opacity':
  10720. case 'reflectivity':
  10721. case 'transparent':
  10722. case 'visible':
  10723. case 'wireframe':
  10724. json[ name ] = value;
  10725. break;
  10726. case 'vertexColors':
  10727. if ( value === true ) json.vertexColors = THREE.VertexColors;
  10728. if ( value === 'face' ) json.vertexColors = THREE.FaceColors;
  10729. break;
  10730. default:
  10731. console.error( 'THREE.Loader.createMaterial: Unsupported', name, value );
  10732. break;
  10733. }
  10734. }
  10735. if ( json.type === 'MeshBasicMaterial' ) delete json.emissive;
  10736. if ( json.type !== 'MeshPhongMaterial' ) delete json.specular;
  10737. if ( json.opacity < 1 ) json.transparent = true;
  10738. materialLoader.setTextures( textures );
  10739. return materialLoader.parse( json );
  10740. };
  10741. } )()
  10742. };
  10743. THREE.Loader.Handlers = {
  10744. handlers: [],
  10745. add: function ( regex, loader ) {
  10746. this.handlers.push( regex, loader );
  10747. },
  10748. get: function ( file ) {
  10749. var handlers = this.handlers;
  10750. for ( var i = 0, l = handlers.length; i < l; i += 2 ) {
  10751. var regex = handlers[ i ];
  10752. var loader = handlers[ i + 1 ];
  10753. if ( regex.test( file ) ) {
  10754. return loader;
  10755. }
  10756. }
  10757. return null;
  10758. }
  10759. };
  10760. // File:src/loaders/XHRLoader.js
  10761. /**
  10762. * @author mrdoob / http://mrdoob.com/
  10763. */
  10764. THREE.XHRLoader = function ( manager ) {
  10765. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  10766. };
  10767. Object.assign( THREE.XHRLoader.prototype, {
  10768. load: function ( url, onLoad, onProgress, onError ) {
  10769. if ( this.path !== undefined ) url = this.path + url;
  10770. var scope = this;
  10771. var cached = THREE.Cache.get( url );
  10772. if ( cached !== undefined ) {
  10773. if ( onLoad ) {
  10774. setTimeout( function () {
  10775. onLoad( cached );
  10776. }, 0 );
  10777. }
  10778. return cached;
  10779. }
  10780. var request = new XMLHttpRequest();
  10781. request.overrideMimeType( 'text/plain' );
  10782. request.open( 'GET', url, true );
  10783. request.addEventListener( 'load', function ( event ) {
  10784. var response = event.target.response;
  10785. THREE.Cache.add( url, response );
  10786. if ( this.status === 200 ) {
  10787. if ( onLoad ) onLoad( response );
  10788. scope.manager.itemEnd( url );
  10789. } else if ( this.status === 0 ) {
  10790. // Some browsers return HTTP Status 0 when using non-http protocol
  10791. // e.g. 'file://' or 'data://'. Handle as success.
  10792. console.warn( 'THREE.XHRLoader: HTTP Status 0 received.' );
  10793. if ( onLoad ) onLoad( response );
  10794. scope.manager.itemEnd( url );
  10795. } else {
  10796. if ( onError ) onError( event );
  10797. scope.manager.itemError( url );
  10798. }
  10799. }, false );
  10800. if ( onProgress !== undefined ) {
  10801. request.addEventListener( 'progress', function ( event ) {
  10802. onProgress( event );
  10803. }, false );
  10804. }
  10805. request.addEventListener( 'error', function ( event ) {
  10806. if ( onError ) onError( event );
  10807. scope.manager.itemError( url );
  10808. }, false );
  10809. if ( this.responseType !== undefined ) request.responseType = this.responseType;
  10810. if ( this.withCredentials !== undefined ) request.withCredentials = this.withCredentials;
  10811. request.send( null );
  10812. scope.manager.itemStart( url );
  10813. return request;
  10814. },
  10815. setPath: function ( value ) {
  10816. this.path = value;
  10817. return this;
  10818. },
  10819. setResponseType: function ( value ) {
  10820. this.responseType = value;
  10821. return this;
  10822. },
  10823. setWithCredentials: function ( value ) {
  10824. this.withCredentials = value;
  10825. return this;
  10826. }
  10827. } );
  10828. // File:src/loaders/FontLoader.js
  10829. /**
  10830. * @author mrdoob / http://mrdoob.com/
  10831. */
  10832. THREE.FontLoader = function ( manager ) {
  10833. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  10834. };
  10835. Object.assign( THREE.FontLoader.prototype, {
  10836. load: function ( url, onLoad, onProgress, onError ) {
  10837. var scope = this;
  10838. var loader = new THREE.XHRLoader( this.manager );
  10839. loader.load( url, function ( text ) {
  10840. var json;
  10841. try {
  10842. json = JSON.parse( text );
  10843. } catch ( e ) {
  10844. console.warn( 'THREE.FontLoader: typeface.js support is being deprecated. Use typeface.json instead.' );
  10845. json = JSON.parse( text.substring( 65, text.length - 2 ) );
  10846. }
  10847. var font = scope.parse( json );
  10848. if ( onLoad ) onLoad( font );
  10849. }, onProgress, onError );
  10850. },
  10851. parse: function ( json ) {
  10852. return new THREE.Font( json );
  10853. }
  10854. } );
  10855. // File:src/loaders/ImageLoader.js
  10856. /**
  10857. * @author mrdoob / http://mrdoob.com/
  10858. */
  10859. THREE.ImageLoader = function ( manager ) {
  10860. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  10861. };
  10862. Object.assign( THREE.ImageLoader.prototype, {
  10863. load: function ( url, onLoad, onProgress, onError ) {
  10864. var image = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'img' );
  10865. image.onload = function () {
  10866. URL.revokeObjectURL( image.src );
  10867. if ( onLoad ) onLoad( image );
  10868. };
  10869. if ( url.indexOf( 'data:' ) === 0 ) {
  10870. image.src = url;
  10871. } else {
  10872. var loader = new THREE.XHRLoader( this.manager );
  10873. loader.setPath( this.path );
  10874. loader.setResponseType( 'blob' );
  10875. loader.load( url, function ( blob ) {
  10876. image.src = URL.createObjectURL( blob );
  10877. }, onProgress, onError );
  10878. }
  10879. return image;
  10880. },
  10881. setCrossOrigin: function ( value ) {
  10882. this.crossOrigin = value;
  10883. return this;
  10884. },
  10885. setPath: function ( value ) {
  10886. this.path = value;
  10887. return this;
  10888. }
  10889. } );
  10890. // File:src/loaders/JSONLoader.js
  10891. /**
  10892. * @author mrdoob / http://mrdoob.com/
  10893. * @author alteredq / http://alteredqualia.com/
  10894. */
  10895. THREE.JSONLoader = function ( manager ) {
  10896. if ( typeof manager === 'boolean' ) {
  10897. console.warn( 'THREE.JSONLoader: showStatus parameter has been removed from constructor.' );
  10898. manager = undefined;
  10899. }
  10900. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  10901. this.withCredentials = false;
  10902. };
  10903. Object.assign( THREE.JSONLoader.prototype, {
  10904. load: function( url, onLoad, onProgress, onError ) {
  10905. var scope = this;
  10906. var texturePath = this.texturePath && ( typeof this.texturePath === "string" ) ? this.texturePath : THREE.Loader.prototype.extractUrlBase( url );
  10907. var loader = new THREE.XHRLoader( this.manager );
  10908. loader.setWithCredentials( this.withCredentials );
  10909. loader.load( url, function ( text ) {
  10910. var json = JSON.parse( text );
  10911. var metadata = json.metadata;
  10912. if ( metadata !== undefined ) {
  10913. var type = metadata.type;
  10914. if ( type !== undefined ) {
  10915. if ( type.toLowerCase() === 'object' ) {
  10916. console.error( 'THREE.JSONLoader: ' + url + ' should be loaded with THREE.ObjectLoader instead.' );
  10917. return;
  10918. }
  10919. if ( type.toLowerCase() === 'scene' ) {
  10920. console.error( 'THREE.JSONLoader: ' + url + ' should be loaded with THREE.SceneLoader instead.' );
  10921. return;
  10922. }
  10923. }
  10924. }
  10925. var object = scope.parse( json, texturePath );
  10926. onLoad( object.geometry, object.materials );
  10927. }, onProgress, onError );
  10928. },
  10929. setTexturePath: function ( value ) {
  10930. this.texturePath = value;
  10931. },
  10932. parse: function ( json, texturePath ) {
  10933. var geometry = new THREE.Geometry(),
  10934. scale = ( json.scale !== undefined ) ? 1.0 / json.scale : 1.0;
  10935. parseModel( scale );
  10936. parseSkin();
  10937. parseMorphing( scale );
  10938. parseAnimations();
  10939. geometry.computeFaceNormals();
  10940. geometry.computeBoundingSphere();
  10941. function parseModel( scale ) {
  10942. function isBitSet( value, position ) {
  10943. return value & ( 1 << position );
  10944. }
  10945. var i, j, fi,
  10946. offset, zLength,
  10947. colorIndex, normalIndex, uvIndex, materialIndex,
  10948. type,
  10949. isQuad,
  10950. hasMaterial,
  10951. hasFaceVertexUv,
  10952. hasFaceNormal, hasFaceVertexNormal,
  10953. hasFaceColor, hasFaceVertexColor,
  10954. vertex, face, faceA, faceB, hex, normal,
  10955. uvLayer, uv, u, v,
  10956. faces = json.faces,
  10957. vertices = json.vertices,
  10958. normals = json.normals,
  10959. colors = json.colors,
  10960. nUvLayers = 0;
  10961. if ( json.uvs !== undefined ) {
  10962. // disregard empty arrays
  10963. for ( i = 0; i < json.uvs.length; i ++ ) {
  10964. if ( json.uvs[ i ].length ) nUvLayers ++;
  10965. }
  10966. for ( i = 0; i < nUvLayers; i ++ ) {
  10967. geometry.faceVertexUvs[ i ] = [];
  10968. }
  10969. }
  10970. offset = 0;
  10971. zLength = vertices.length;
  10972. while ( offset < zLength ) {
  10973. vertex = new THREE.Vector3();
  10974. vertex.x = vertices[ offset ++ ] * scale;
  10975. vertex.y = vertices[ offset ++ ] * scale;
  10976. vertex.z = vertices[ offset ++ ] * scale;
  10977. geometry.vertices.push( vertex );
  10978. }
  10979. offset = 0;
  10980. zLength = faces.length;
  10981. while ( offset < zLength ) {
  10982. type = faces[ offset ++ ];
  10983. isQuad = isBitSet( type, 0 );
  10984. hasMaterial = isBitSet( type, 1 );
  10985. hasFaceVertexUv = isBitSet( type, 3 );
  10986. hasFaceNormal = isBitSet( type, 4 );
  10987. hasFaceVertexNormal = isBitSet( type, 5 );
  10988. hasFaceColor = isBitSet( type, 6 );
  10989. hasFaceVertexColor = isBitSet( type, 7 );
  10990. // console.log("type", type, "bits", isQuad, hasMaterial, hasFaceVertexUv, hasFaceNormal, hasFaceVertexNormal, hasFaceColor, hasFaceVertexColor);
  10991. if ( isQuad ) {
  10992. faceA = new THREE.Face3();
  10993. faceA.a = faces[ offset ];
  10994. faceA.b = faces[ offset + 1 ];
  10995. faceA.c = faces[ offset + 3 ];
  10996. faceB = new THREE.Face3();
  10997. faceB.a = faces[ offset + 1 ];
  10998. faceB.b = faces[ offset + 2 ];
  10999. faceB.c = faces[ offset + 3 ];
  11000. offset += 4;
  11001. if ( hasMaterial ) {
  11002. materialIndex = faces[ offset ++ ];
  11003. faceA.materialIndex = materialIndex;
  11004. faceB.materialIndex = materialIndex;
  11005. }
  11006. // to get face <=> uv index correspondence
  11007. fi = geometry.faces.length;
  11008. if ( hasFaceVertexUv ) {
  11009. for ( i = 0; i < nUvLayers; i ++ ) {
  11010. uvLayer = json.uvs[ i ];
  11011. geometry.faceVertexUvs[ i ][ fi ] = [];
  11012. geometry.faceVertexUvs[ i ][ fi + 1 ] = [];
  11013. for ( j = 0; j < 4; j ++ ) {
  11014. uvIndex = faces[ offset ++ ];
  11015. u = uvLayer[ uvIndex * 2 ];
  11016. v = uvLayer[ uvIndex * 2 + 1 ];
  11017. uv = new THREE.Vector2( u, v );
  11018. if ( j !== 2 ) geometry.faceVertexUvs[ i ][ fi ].push( uv );
  11019. if ( j !== 0 ) geometry.faceVertexUvs[ i ][ fi + 1 ].push( uv );
  11020. }
  11021. }
  11022. }
  11023. if ( hasFaceNormal ) {
  11024. normalIndex = faces[ offset ++ ] * 3;
  11025. faceA.normal.set(
  11026. normals[ normalIndex ++ ],
  11027. normals[ normalIndex ++ ],
  11028. normals[ normalIndex ]
  11029. );
  11030. faceB.normal.copy( faceA.normal );
  11031. }
  11032. if ( hasFaceVertexNormal ) {
  11033. for ( i = 0; i < 4; i ++ ) {
  11034. normalIndex = faces[ offset ++ ] * 3;
  11035. normal = new THREE.Vector3(
  11036. normals[ normalIndex ++ ],
  11037. normals[ normalIndex ++ ],
  11038. normals[ normalIndex ]
  11039. );
  11040. if ( i !== 2 ) faceA.vertexNormals.push( normal );
  11041. if ( i !== 0 ) faceB.vertexNormals.push( normal );
  11042. }
  11043. }
  11044. if ( hasFaceColor ) {
  11045. colorIndex = faces[ offset ++ ];
  11046. hex = colors[ colorIndex ];
  11047. faceA.color.setHex( hex );
  11048. faceB.color.setHex( hex );
  11049. }
  11050. if ( hasFaceVertexColor ) {
  11051. for ( i = 0; i < 4; i ++ ) {
  11052. colorIndex = faces[ offset ++ ];
  11053. hex = colors[ colorIndex ];
  11054. if ( i !== 2 ) faceA.vertexColors.push( new THREE.Color( hex ) );
  11055. if ( i !== 0 ) faceB.vertexColors.push( new THREE.Color( hex ) );
  11056. }
  11057. }
  11058. geometry.faces.push( faceA );
  11059. geometry.faces.push( faceB );
  11060. } else {
  11061. face = new THREE.Face3();
  11062. face.a = faces[ offset ++ ];
  11063. face.b = faces[ offset ++ ];
  11064. face.c = faces[ offset ++ ];
  11065. if ( hasMaterial ) {
  11066. materialIndex = faces[ offset ++ ];
  11067. face.materialIndex = materialIndex;
  11068. }
  11069. // to get face <=> uv index correspondence
  11070. fi = geometry.faces.length;
  11071. if ( hasFaceVertexUv ) {
  11072. for ( i = 0; i < nUvLayers; i ++ ) {
  11073. uvLayer = json.uvs[ i ];
  11074. geometry.faceVertexUvs[ i ][ fi ] = [];
  11075. for ( j = 0; j < 3; j ++ ) {
  11076. uvIndex = faces[ offset ++ ];
  11077. u = uvLayer[ uvIndex * 2 ];
  11078. v = uvLayer[ uvIndex * 2 + 1 ];
  11079. uv = new THREE.Vector2( u, v );
  11080. geometry.faceVertexUvs[ i ][ fi ].push( uv );
  11081. }
  11082. }
  11083. }
  11084. if ( hasFaceNormal ) {
  11085. normalIndex = faces[ offset ++ ] * 3;
  11086. face.normal.set(
  11087. normals[ normalIndex ++ ],
  11088. normals[ normalIndex ++ ],
  11089. normals[ normalIndex ]
  11090. );
  11091. }
  11092. if ( hasFaceVertexNormal ) {
  11093. for ( i = 0; i < 3; i ++ ) {
  11094. normalIndex = faces[ offset ++ ] * 3;
  11095. normal = new THREE.Vector3(
  11096. normals[ normalIndex ++ ],
  11097. normals[ normalIndex ++ ],
  11098. normals[ normalIndex ]
  11099. );
  11100. face.vertexNormals.push( normal );
  11101. }
  11102. }
  11103. if ( hasFaceColor ) {
  11104. colorIndex = faces[ offset ++ ];
  11105. face.color.setHex( colors[ colorIndex ] );
  11106. }
  11107. if ( hasFaceVertexColor ) {
  11108. for ( i = 0; i < 3; i ++ ) {
  11109. colorIndex = faces[ offset ++ ];
  11110. face.vertexColors.push( new THREE.Color( colors[ colorIndex ] ) );
  11111. }
  11112. }
  11113. geometry.faces.push( face );
  11114. }
  11115. }
  11116. }
  11117. function parseSkin() {
  11118. var influencesPerVertex = ( json.influencesPerVertex !== undefined ) ? json.influencesPerVertex : 2;
  11119. if ( json.skinWeights ) {
  11120. for ( var i = 0, l = json.skinWeights.length; i < l; i += influencesPerVertex ) {
  11121. var x = json.skinWeights[ i ];
  11122. var y = ( influencesPerVertex > 1 ) ? json.skinWeights[ i + 1 ] : 0;
  11123. var z = ( influencesPerVertex > 2 ) ? json.skinWeights[ i + 2 ] : 0;
  11124. var w = ( influencesPerVertex > 3 ) ? json.skinWeights[ i + 3 ] : 0;
  11125. geometry.skinWeights.push( new THREE.Vector4( x, y, z, w ) );
  11126. }
  11127. }
  11128. if ( json.skinIndices ) {
  11129. for ( var i = 0, l = json.skinIndices.length; i < l; i += influencesPerVertex ) {
  11130. var a = json.skinIndices[ i ];
  11131. var b = ( influencesPerVertex > 1 ) ? json.skinIndices[ i + 1 ] : 0;
  11132. var c = ( influencesPerVertex > 2 ) ? json.skinIndices[ i + 2 ] : 0;
  11133. var d = ( influencesPerVertex > 3 ) ? json.skinIndices[ i + 3 ] : 0;
  11134. geometry.skinIndices.push( new THREE.Vector4( a, b, c, d ) );
  11135. }
  11136. }
  11137. geometry.bones = json.bones;
  11138. if ( geometry.bones && geometry.bones.length > 0 && ( geometry.skinWeights.length !== geometry.skinIndices.length || geometry.skinIndices.length !== geometry.vertices.length ) ) {
  11139. console.warn( 'When skinning, number of vertices (' + geometry.vertices.length + '), skinIndices (' +
  11140. geometry.skinIndices.length + '), and skinWeights (' + geometry.skinWeights.length + ') should match.' );
  11141. }
  11142. }
  11143. function parseMorphing( scale ) {
  11144. if ( json.morphTargets !== undefined ) {
  11145. for ( var i = 0, l = json.morphTargets.length; i < l; i ++ ) {
  11146. geometry.morphTargets[ i ] = {};
  11147. geometry.morphTargets[ i ].name = json.morphTargets[ i ].name;
  11148. geometry.morphTargets[ i ].vertices = [];
  11149. var dstVertices = geometry.morphTargets[ i ].vertices;
  11150. var srcVertices = json.morphTargets[ i ].vertices;
  11151. for ( var v = 0, vl = srcVertices.length; v < vl; v += 3 ) {
  11152. var vertex = new THREE.Vector3();
  11153. vertex.x = srcVertices[ v ] * scale;
  11154. vertex.y = srcVertices[ v + 1 ] * scale;
  11155. vertex.z = srcVertices[ v + 2 ] * scale;
  11156. dstVertices.push( vertex );
  11157. }
  11158. }
  11159. }
  11160. if ( json.morphColors !== undefined && json.morphColors.length > 0 ) {
  11161. console.warn( 'THREE.JSONLoader: "morphColors" no longer supported. Using them as face colors.' );
  11162. var faces = geometry.faces;
  11163. var morphColors = json.morphColors[ 0 ].colors;
  11164. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  11165. faces[ i ].color.fromArray( morphColors, i * 3 );
  11166. }
  11167. }
  11168. }
  11169. function parseAnimations() {
  11170. var outputAnimations = [];
  11171. // parse old style Bone/Hierarchy animations
  11172. var animations = [];
  11173. if ( json.animation !== undefined ) {
  11174. animations.push( json.animation );
  11175. }
  11176. if ( json.animations !== undefined ) {
  11177. if ( json.animations.length ) {
  11178. animations = animations.concat( json.animations );
  11179. } else {
  11180. animations.push( json.animations );
  11181. }
  11182. }
  11183. for ( var i = 0; i < animations.length; i ++ ) {
  11184. var clip = THREE.AnimationClip.parseAnimation( animations[ i ], geometry.bones );
  11185. if ( clip ) outputAnimations.push( clip );
  11186. }
  11187. // parse implicit morph animations
  11188. if ( geometry.morphTargets ) {
  11189. // TODO: Figure out what an appropraite FPS is for morph target animations -- defaulting to 10, but really it is completely arbitrary.
  11190. var morphAnimationClips = THREE.AnimationClip.CreateClipsFromMorphTargetSequences( geometry.morphTargets, 10 );
  11191. outputAnimations = outputAnimations.concat( morphAnimationClips );
  11192. }
  11193. if ( outputAnimations.length > 0 ) geometry.animations = outputAnimations;
  11194. }
  11195. if ( json.materials === undefined || json.materials.length === 0 ) {
  11196. return { geometry: geometry };
  11197. } else {
  11198. var materials = THREE.Loader.prototype.initMaterials( json.materials, texturePath, this.crossOrigin );
  11199. return { geometry: geometry, materials: materials };
  11200. }
  11201. }
  11202. } );
  11203. // File:src/loaders/LoadingManager.js
  11204. /**
  11205. * @author mrdoob / http://mrdoob.com/
  11206. */
  11207. THREE.LoadingManager = function ( onLoad, onProgress, onError ) {
  11208. var scope = this;
  11209. var isLoading = false, itemsLoaded = 0, itemsTotal = 0;
  11210. this.onStart = undefined;
  11211. this.onLoad = onLoad;
  11212. this.onProgress = onProgress;
  11213. this.onError = onError;
  11214. this.itemStart = function ( url ) {
  11215. itemsTotal ++;
  11216. if ( isLoading === false ) {
  11217. if ( scope.onStart !== undefined ) {
  11218. scope.onStart( url, itemsLoaded, itemsTotal );
  11219. }
  11220. }
  11221. isLoading = true;
  11222. };
  11223. this.itemEnd = function ( url ) {
  11224. itemsLoaded ++;
  11225. if ( scope.onProgress !== undefined ) {
  11226. scope.onProgress( url, itemsLoaded, itemsTotal );
  11227. }
  11228. if ( itemsLoaded === itemsTotal ) {
  11229. isLoading = false;
  11230. if ( scope.onLoad !== undefined ) {
  11231. scope.onLoad();
  11232. }
  11233. }
  11234. };
  11235. this.itemError = function ( url ) {
  11236. if ( scope.onError !== undefined ) {
  11237. scope.onError( url );
  11238. }
  11239. };
  11240. };
  11241. THREE.DefaultLoadingManager = new THREE.LoadingManager();
  11242. // File:src/loaders/BufferGeometryLoader.js
  11243. /**
  11244. * @author mrdoob / http://mrdoob.com/
  11245. */
  11246. THREE.BufferGeometryLoader = function ( manager ) {
  11247. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  11248. };
  11249. Object.assign( THREE.BufferGeometryLoader.prototype, {
  11250. load: function ( url, onLoad, onProgress, onError ) {
  11251. var scope = this;
  11252. var loader = new THREE.XHRLoader( scope.manager );
  11253. loader.load( url, function ( text ) {
  11254. onLoad( scope.parse( JSON.parse( text ) ) );
  11255. }, onProgress, onError );
  11256. },
  11257. parse: function ( json ) {
  11258. var geometry = new THREE.BufferGeometry();
  11259. var index = json.data.index;
  11260. var TYPED_ARRAYS = {
  11261. 'Int8Array': Int8Array,
  11262. 'Uint8Array': Uint8Array,
  11263. 'Uint8ClampedArray': Uint8ClampedArray,
  11264. 'Int16Array': Int16Array,
  11265. 'Uint16Array': Uint16Array,
  11266. 'Int32Array': Int32Array,
  11267. 'Uint32Array': Uint32Array,
  11268. 'Float32Array': Float32Array,
  11269. 'Float64Array': Float64Array
  11270. };
  11271. if ( index !== undefined ) {
  11272. var typedArray = new TYPED_ARRAYS[ index.type ]( index.array );
  11273. geometry.setIndex( new THREE.BufferAttribute( typedArray, 1 ) );
  11274. }
  11275. var attributes = json.data.attributes;
  11276. for ( var key in attributes ) {
  11277. var attribute = attributes[ key ];
  11278. var typedArray = new TYPED_ARRAYS[ attribute.type ]( attribute.array );
  11279. geometry.addAttribute( key, new THREE.BufferAttribute( typedArray, attribute.itemSize, attribute.normalized ) );
  11280. }
  11281. var groups = json.data.groups || json.data.drawcalls || json.data.offsets;
  11282. if ( groups !== undefined ) {
  11283. for ( var i = 0, n = groups.length; i !== n; ++ i ) {
  11284. var group = groups[ i ];
  11285. geometry.addGroup( group.start, group.count, group.materialIndex );
  11286. }
  11287. }
  11288. var boundingSphere = json.data.boundingSphere;
  11289. if ( boundingSphere !== undefined ) {
  11290. var center = new THREE.Vector3();
  11291. if ( boundingSphere.center !== undefined ) {
  11292. center.fromArray( boundingSphere.center );
  11293. }
  11294. geometry.boundingSphere = new THREE.Sphere( center, boundingSphere.radius );
  11295. }
  11296. return geometry;
  11297. }
  11298. } );
  11299. // File:src/loaders/MaterialLoader.js
  11300. /**
  11301. * @author mrdoob / http://mrdoob.com/
  11302. */
  11303. THREE.MaterialLoader = function ( manager ) {
  11304. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  11305. this.textures = {};
  11306. };
  11307. Object.assign( THREE.MaterialLoader.prototype, {
  11308. load: function ( url, onLoad, onProgress, onError ) {
  11309. var scope = this;
  11310. var loader = new THREE.XHRLoader( scope.manager );
  11311. loader.load( url, function ( text ) {
  11312. onLoad( scope.parse( JSON.parse( text ) ) );
  11313. }, onProgress, onError );
  11314. },
  11315. setTextures: function ( value ) {
  11316. this.textures = value;
  11317. },
  11318. getTexture: function ( name ) {
  11319. var textures = this.textures;
  11320. if ( textures[ name ] === undefined ) {
  11321. console.warn( 'THREE.MaterialLoader: Undefined texture', name );
  11322. }
  11323. return textures[ name ];
  11324. },
  11325. parse: function ( json ) {
  11326. var material = new THREE[ json.type ];
  11327. if ( json.uuid !== undefined ) material.uuid = json.uuid;
  11328. if ( json.name !== undefined ) material.name = json.name;
  11329. if ( json.color !== undefined ) material.color.setHex( json.color );
  11330. if ( json.roughness !== undefined ) material.roughness = json.roughness;
  11331. if ( json.metalness !== undefined ) material.metalness = json.metalness;
  11332. if ( json.emissive !== undefined ) material.emissive.setHex( json.emissive );
  11333. if ( json.specular !== undefined ) material.specular.setHex( json.specular );
  11334. if ( json.shininess !== undefined ) material.shininess = json.shininess;
  11335. if ( json.uniforms !== undefined ) material.uniforms = json.uniforms;
  11336. if ( json.vertexShader !== undefined ) material.vertexShader = json.vertexShader;
  11337. if ( json.fragmentShader !== undefined ) material.fragmentShader = json.fragmentShader;
  11338. if ( json.vertexColors !== undefined ) material.vertexColors = json.vertexColors;
  11339. if ( json.shading !== undefined ) material.shading = json.shading;
  11340. if ( json.blending !== undefined ) material.blending = json.blending;
  11341. if ( json.side !== undefined ) material.side = json.side;
  11342. if ( json.opacity !== undefined ) material.opacity = json.opacity;
  11343. if ( json.transparent !== undefined ) material.transparent = json.transparent;
  11344. if ( json.alphaTest !== undefined ) material.alphaTest = json.alphaTest;
  11345. if ( json.depthTest !== undefined ) material.depthTest = json.depthTest;
  11346. if ( json.depthWrite !== undefined ) material.depthWrite = json.depthWrite;
  11347. if ( json.colorWrite !== undefined ) material.colorWrite = json.colorWrite;
  11348. if ( json.wireframe !== undefined ) material.wireframe = json.wireframe;
  11349. if ( json.wireframeLinewidth !== undefined ) material.wireframeLinewidth = json.wireframeLinewidth;
  11350. // for PointsMaterial
  11351. if ( json.size !== undefined ) material.size = json.size;
  11352. if ( json.sizeAttenuation !== undefined ) material.sizeAttenuation = json.sizeAttenuation;
  11353. // maps
  11354. if ( json.map !== undefined ) material.map = this.getTexture( json.map );
  11355. if ( json.alphaMap !== undefined ) {
  11356. material.alphaMap = this.getTexture( json.alphaMap );
  11357. material.transparent = true;
  11358. }
  11359. if ( json.bumpMap !== undefined ) material.bumpMap = this.getTexture( json.bumpMap );
  11360. if ( json.bumpScale !== undefined ) material.bumpScale = json.bumpScale;
  11361. if ( json.normalMap !== undefined ) material.normalMap = this.getTexture( json.normalMap );
  11362. if ( json.normalScale !== undefined ) {
  11363. var normalScale = json.normalScale;
  11364. if ( Array.isArray( normalScale ) === false ) {
  11365. // Blender exporter used to export a scalar. See #7459
  11366. normalScale = [ normalScale, normalScale ];
  11367. }
  11368. material.normalScale = new THREE.Vector2().fromArray( normalScale );
  11369. }
  11370. if ( json.displacementMap !== undefined ) material.displacementMap = this.getTexture( json.displacementMap );
  11371. if ( json.displacementScale !== undefined ) material.displacementScale = json.displacementScale;
  11372. if ( json.displacementBias !== undefined ) material.displacementBias = json.displacementBias;
  11373. if ( json.roughnessMap !== undefined ) material.roughnessMap = this.getTexture( json.roughnessMap );
  11374. if ( json.metalnessMap !== undefined ) material.metalnessMap = this.getTexture( json.metalnessMap );
  11375. if ( json.emissiveMap !== undefined ) material.emissiveMap = this.getTexture( json.emissiveMap );
  11376. if ( json.emissiveIntensity !== undefined ) material.emissiveIntensity = json.emissiveIntensity;
  11377. if ( json.specularMap !== undefined ) material.specularMap = this.getTexture( json.specularMap );
  11378. if ( json.envMap !== undefined ) {
  11379. material.envMap = this.getTexture( json.envMap );
  11380. material.combine = THREE.MultiplyOperation;
  11381. }
  11382. if ( json.reflectivity !== undefined ) material.reflectivity = json.reflectivity;
  11383. if ( json.lightMap !== undefined ) material.lightMap = this.getTexture( json.lightMap );
  11384. if ( json.lightMapIntensity !== undefined ) material.lightMapIntensity = json.lightMapIntensity;
  11385. if ( json.aoMap !== undefined ) material.aoMap = this.getTexture( json.aoMap );
  11386. if ( json.aoMapIntensity !== undefined ) material.aoMapIntensity = json.aoMapIntensity;
  11387. // MultiMaterial
  11388. if ( json.materials !== undefined ) {
  11389. for ( var i = 0, l = json.materials.length; i < l; i ++ ) {
  11390. material.materials.push( this.parse( json.materials[ i ] ) );
  11391. }
  11392. }
  11393. return material;
  11394. }
  11395. } );
  11396. // File:src/loaders/ObjectLoader.js
  11397. /**
  11398. * @author mrdoob / http://mrdoob.com/
  11399. */
  11400. THREE.ObjectLoader = function ( manager ) {
  11401. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  11402. this.texturePath = '';
  11403. };
  11404. Object.assign( THREE.ObjectLoader.prototype, {
  11405. load: function ( url, onLoad, onProgress, onError ) {
  11406. if ( this.texturePath === '' ) {
  11407. this.texturePath = url.substring( 0, url.lastIndexOf( '/' ) + 1 );
  11408. }
  11409. var scope = this;
  11410. var loader = new THREE.XHRLoader( scope.manager );
  11411. loader.load( url, function ( text ) {
  11412. scope.parse( JSON.parse( text ), onLoad );
  11413. }, onProgress, onError );
  11414. },
  11415. setTexturePath: function ( value ) {
  11416. this.texturePath = value;
  11417. },
  11418. setCrossOrigin: function ( value ) {
  11419. this.crossOrigin = value;
  11420. },
  11421. parse: function ( json, onLoad ) {
  11422. var geometries = this.parseGeometries( json.geometries );
  11423. var images = this.parseImages( json.images, function () {
  11424. if ( onLoad !== undefined ) onLoad( object );
  11425. } );
  11426. var textures = this.parseTextures( json.textures, images );
  11427. var materials = this.parseMaterials( json.materials, textures );
  11428. var object = this.parseObject( json.object, geometries, materials );
  11429. if ( json.animations ) {
  11430. object.animations = this.parseAnimations( json.animations );
  11431. }
  11432. if ( json.images === undefined || json.images.length === 0 ) {
  11433. if ( onLoad !== undefined ) onLoad( object );
  11434. }
  11435. return object;
  11436. },
  11437. parseGeometries: function ( json ) {
  11438. var geometries = {};
  11439. if ( json !== undefined ) {
  11440. var geometryLoader = new THREE.JSONLoader();
  11441. var bufferGeometryLoader = new THREE.BufferGeometryLoader();
  11442. for ( var i = 0, l = json.length; i < l; i ++ ) {
  11443. var geometry;
  11444. var data = json[ i ];
  11445. switch ( data.type ) {
  11446. case 'PlaneGeometry':
  11447. case 'PlaneBufferGeometry':
  11448. geometry = new THREE[ data.type ](
  11449. data.width,
  11450. data.height,
  11451. data.widthSegments,
  11452. data.heightSegments
  11453. );
  11454. break;
  11455. case 'BoxGeometry':
  11456. case 'BoxBufferGeometry':
  11457. case 'CubeGeometry': // backwards compatible
  11458. geometry = new THREE[ data.type ](
  11459. data.width,
  11460. data.height,
  11461. data.depth,
  11462. data.widthSegments,
  11463. data.heightSegments,
  11464. data.depthSegments
  11465. );
  11466. break;
  11467. case 'CircleGeometry':
  11468. case 'CircleBufferGeometry':
  11469. geometry = new THREE[ data.type ](
  11470. data.radius,
  11471. data.segments,
  11472. data.thetaStart,
  11473. data.thetaLength
  11474. );
  11475. break;
  11476. case 'CylinderGeometry':
  11477. case 'CylinderBufferGeometry':
  11478. geometry = new THREE[ data.type ](
  11479. data.radiusTop,
  11480. data.radiusBottom,
  11481. data.height,
  11482. data.radialSegments,
  11483. data.heightSegments,
  11484. data.openEnded,
  11485. data.thetaStart,
  11486. data.thetaLength
  11487. );
  11488. break;
  11489. case 'ConeGeometry':
  11490. case 'ConeBufferGeometry':
  11491. geometry = new THREE [ data.type ](
  11492. data.radius,
  11493. data.height,
  11494. data.radialSegments,
  11495. data.heightSegments,
  11496. data.openEnded,
  11497. data.thetaStart,
  11498. data.thetaLength
  11499. );
  11500. break;
  11501. case 'SphereGeometry':
  11502. case 'SphereBufferGeometry':
  11503. geometry = new THREE[ data.type ](
  11504. data.radius,
  11505. data.widthSegments,
  11506. data.heightSegments,
  11507. data.phiStart,
  11508. data.phiLength,
  11509. data.thetaStart,
  11510. data.thetaLength
  11511. );
  11512. break;
  11513. case 'DodecahedronGeometry':
  11514. case 'IcosahedronGeometry':
  11515. case 'OctahedronGeometry':
  11516. case 'TetrahedronGeometry':
  11517. geometry = new THREE[ data.type ](
  11518. data.radius,
  11519. data.detail
  11520. );
  11521. break;
  11522. case 'RingGeometry':
  11523. case 'RingBufferGeometry':
  11524. geometry = new THREE[ data.type ](
  11525. data.innerRadius,
  11526. data.outerRadius,
  11527. data.thetaSegments,
  11528. data.phiSegments,
  11529. data.thetaStart,
  11530. data.thetaLength
  11531. );
  11532. break;
  11533. case 'TorusGeometry':
  11534. case 'TorusBufferGeometry':
  11535. geometry = new THREE[ data.type ](
  11536. data.radius,
  11537. data.tube,
  11538. data.radialSegments,
  11539. data.tubularSegments,
  11540. data.arc
  11541. );
  11542. break;
  11543. case 'TorusKnotGeometry':
  11544. case 'TorusKnotBufferGeometry':
  11545. geometry = new THREE[ data.type ](
  11546. data.radius,
  11547. data.tube,
  11548. data.tubularSegments,
  11549. data.radialSegments,
  11550. data.p,
  11551. data.q
  11552. );
  11553. break;
  11554. case 'LatheGeometry':
  11555. case 'LatheBufferGeometry':
  11556. geometry = new THREE[ data.type ](
  11557. data.points,
  11558. data.segments,
  11559. data.phiStart,
  11560. data.phiLength
  11561. );
  11562. break;
  11563. case 'BufferGeometry':
  11564. geometry = bufferGeometryLoader.parse( data );
  11565. break;
  11566. case 'Geometry':
  11567. geometry = geometryLoader.parse( data.data, this.texturePath ).geometry;
  11568. break;
  11569. default:
  11570. console.warn( 'THREE.ObjectLoader: Unsupported geometry type "' + data.type + '"' );
  11571. continue;
  11572. }
  11573. geometry.uuid = data.uuid;
  11574. if ( data.name !== undefined ) geometry.name = data.name;
  11575. geometries[ data.uuid ] = geometry;
  11576. }
  11577. }
  11578. return geometries;
  11579. },
  11580. parseMaterials: function ( json, textures ) {
  11581. var materials = {};
  11582. if ( json !== undefined ) {
  11583. var loader = new THREE.MaterialLoader();
  11584. loader.setTextures( textures );
  11585. for ( var i = 0, l = json.length; i < l; i ++ ) {
  11586. var material = loader.parse( json[ i ] );
  11587. materials[ material.uuid ] = material;
  11588. }
  11589. }
  11590. return materials;
  11591. },
  11592. parseAnimations: function ( json ) {
  11593. var animations = [];
  11594. for ( var i = 0; i < json.length; i ++ ) {
  11595. var clip = THREE.AnimationClip.parse( json[ i ] );
  11596. animations.push( clip );
  11597. }
  11598. return animations;
  11599. },
  11600. parseImages: function ( json, onLoad ) {
  11601. var scope = this;
  11602. var images = {};
  11603. function loadImage( url ) {
  11604. scope.manager.itemStart( url );
  11605. return loader.load( url, function () {
  11606. scope.manager.itemEnd( url );
  11607. } );
  11608. }
  11609. if ( json !== undefined && json.length > 0 ) {
  11610. var manager = new THREE.LoadingManager( onLoad );
  11611. var loader = new THREE.ImageLoader( manager );
  11612. loader.setCrossOrigin( this.crossOrigin );
  11613. for ( var i = 0, l = json.length; i < l; i ++ ) {
  11614. var image = json[ i ];
  11615. var path = /^(\/\/)|([a-z]+:(\/\/)?)/i.test( image.url ) ? image.url : scope.texturePath + image.url;
  11616. images[ image.uuid ] = loadImage( path );
  11617. }
  11618. }
  11619. return images;
  11620. },
  11621. parseTextures: function ( json, images ) {
  11622. function parseConstant( value ) {
  11623. if ( typeof( value ) === 'number' ) return value;
  11624. console.warn( 'THREE.ObjectLoader.parseTexture: Constant should be in numeric form.', value );
  11625. return THREE[ value ];
  11626. }
  11627. var textures = {};
  11628. if ( json !== undefined ) {
  11629. for ( var i = 0, l = json.length; i < l; i ++ ) {
  11630. var data = json[ i ];
  11631. if ( data.image === undefined ) {
  11632. console.warn( 'THREE.ObjectLoader: No "image" specified for', data.uuid );
  11633. }
  11634. if ( images[ data.image ] === undefined ) {
  11635. console.warn( 'THREE.ObjectLoader: Undefined image', data.image );
  11636. }
  11637. var texture = new THREE.Texture( images[ data.image ] );
  11638. texture.needsUpdate = true;
  11639. texture.uuid = data.uuid;
  11640. if ( data.name !== undefined ) texture.name = data.name;
  11641. if ( data.mapping !== undefined ) texture.mapping = parseConstant( data.mapping );
  11642. if ( data.offset !== undefined ) texture.offset = new THREE.Vector2( data.offset[ 0 ], data.offset[ 1 ] );
  11643. if ( data.repeat !== undefined ) texture.repeat = new THREE.Vector2( data.repeat[ 0 ], data.repeat[ 1 ] );
  11644. if ( data.minFilter !== undefined ) texture.minFilter = parseConstant( data.minFilter );
  11645. if ( data.magFilter !== undefined ) texture.magFilter = parseConstant( data.magFilter );
  11646. if ( data.anisotropy !== undefined ) texture.anisotropy = data.anisotropy;
  11647. if ( Array.isArray( data.wrap ) ) {
  11648. texture.wrapS = parseConstant( data.wrap[ 0 ] );
  11649. texture.wrapT = parseConstant( data.wrap[ 1 ] );
  11650. }
  11651. textures[ data.uuid ] = texture;
  11652. }
  11653. }
  11654. return textures;
  11655. },
  11656. parseObject: function () {
  11657. var matrix = new THREE.Matrix4();
  11658. return function parseObject( data, geometries, materials ) {
  11659. var object;
  11660. function getGeometry( name ) {
  11661. if ( geometries[ name ] === undefined ) {
  11662. console.warn( 'THREE.ObjectLoader: Undefined geometry', name );
  11663. }
  11664. return geometries[ name ];
  11665. }
  11666. function getMaterial( name ) {
  11667. if ( name === undefined ) return undefined;
  11668. if ( materials[ name ] === undefined ) {
  11669. console.warn( 'THREE.ObjectLoader: Undefined material', name );
  11670. }
  11671. return materials[ name ];
  11672. }
  11673. switch ( data.type ) {
  11674. case 'Scene':
  11675. object = new THREE.Scene();
  11676. break;
  11677. case 'PerspectiveCamera':
  11678. object = new THREE.PerspectiveCamera( data.fov, data.aspect, data.near, data.far );
  11679. if ( data.focus !== undefined ) object.focus = data.focus;
  11680. if ( data.zoom !== undefined ) object.zoom = data.zoom;
  11681. if ( data.filmGauge !== undefined ) object.filmGauge = data.filmGauge;
  11682. if ( data.filmOffset !== undefined ) object.filmOffset = data.filmOffset;
  11683. if ( data.view !== undefined ) object.view = Object.assign( {}, data.view );
  11684. break;
  11685. case 'OrthographicCamera':
  11686. object = new THREE.OrthographicCamera( data.left, data.right, data.top, data.bottom, data.near, data.far );
  11687. break;
  11688. case 'AmbientLight':
  11689. object = new THREE.AmbientLight( data.color, data.intensity );
  11690. break;
  11691. case 'DirectionalLight':
  11692. object = new THREE.DirectionalLight( data.color, data.intensity );
  11693. break;
  11694. case 'PointLight':
  11695. object = new THREE.PointLight( data.color, data.intensity, data.distance, data.decay );
  11696. break;
  11697. case 'SpotLight':
  11698. object = new THREE.SpotLight( data.color, data.intensity, data.distance, data.angle, data.penumbra, data.decay );
  11699. break;
  11700. case 'HemisphereLight':
  11701. object = new THREE.HemisphereLight( data.color, data.groundColor, data.intensity );
  11702. break;
  11703. case 'Mesh':
  11704. var geometry = getGeometry( data.geometry );
  11705. var material = getMaterial( data.material );
  11706. if ( geometry.bones && geometry.bones.length > 0 ) {
  11707. object = new THREE.SkinnedMesh( geometry, material );
  11708. } else {
  11709. object = new THREE.Mesh( geometry, material );
  11710. }
  11711. break;
  11712. case 'LOD':
  11713. object = new THREE.LOD();
  11714. break;
  11715. case 'Line':
  11716. object = new THREE.Line( getGeometry( data.geometry ), getMaterial( data.material ), data.mode );
  11717. break;
  11718. case 'PointCloud':
  11719. case 'Points':
  11720. object = new THREE.Points( getGeometry( data.geometry ), getMaterial( data.material ) );
  11721. break;
  11722. case 'Sprite':
  11723. object = new THREE.Sprite( getMaterial( data.material ) );
  11724. break;
  11725. case 'Group':
  11726. object = new THREE.Group();
  11727. break;
  11728. default:
  11729. object = new THREE.Object3D();
  11730. }
  11731. object.uuid = data.uuid;
  11732. if ( data.name !== undefined ) object.name = data.name;
  11733. if ( data.matrix !== undefined ) {
  11734. matrix.fromArray( data.matrix );
  11735. matrix.decompose( object.position, object.quaternion, object.scale );
  11736. } else {
  11737. if ( data.position !== undefined ) object.position.fromArray( data.position );
  11738. if ( data.rotation !== undefined ) object.rotation.fromArray( data.rotation );
  11739. if ( data.scale !== undefined ) object.scale.fromArray( data.scale );
  11740. }
  11741. if ( data.castShadow !== undefined ) object.castShadow = data.castShadow;
  11742. if ( data.receiveShadow !== undefined ) object.receiveShadow = data.receiveShadow;
  11743. if ( data.visible !== undefined ) object.visible = data.visible;
  11744. if ( data.userData !== undefined ) object.userData = data.userData;
  11745. if ( data.children !== undefined ) {
  11746. for ( var child in data.children ) {
  11747. object.add( this.parseObject( data.children[ child ], geometries, materials ) );
  11748. }
  11749. }
  11750. if ( data.type === 'LOD' ) {
  11751. var levels = data.levels;
  11752. for ( var l = 0; l < levels.length; l ++ ) {
  11753. var level = levels[ l ];
  11754. var child = object.getObjectByProperty( 'uuid', level.object );
  11755. if ( child !== undefined ) {
  11756. object.addLevel( child, level.distance );
  11757. }
  11758. }
  11759. }
  11760. return object;
  11761. };
  11762. }()
  11763. } );
  11764. // File:src/loaders/TextureLoader.js
  11765. /**
  11766. * @author mrdoob / http://mrdoob.com/
  11767. */
  11768. THREE.TextureLoader = function ( manager ) {
  11769. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  11770. };
  11771. Object.assign( THREE.TextureLoader.prototype, {
  11772. load: function ( url, onLoad, onProgress, onError ) {
  11773. var texture = new THREE.Texture();
  11774. var loader = new THREE.ImageLoader( this.manager );
  11775. loader.setCrossOrigin( this.crossOrigin );
  11776. loader.setPath( this.path );
  11777. loader.load( url, function ( image ) {
  11778. texture.image = image;
  11779. texture.needsUpdate = true;
  11780. if ( onLoad !== undefined ) {
  11781. onLoad( texture );
  11782. }
  11783. }, onProgress, onError );
  11784. return texture;
  11785. },
  11786. setCrossOrigin: function ( value ) {
  11787. this.crossOrigin = value;
  11788. return this;
  11789. },
  11790. setPath: function ( value ) {
  11791. this.path = value;
  11792. return this;
  11793. }
  11794. } );
  11795. // File:src/loaders/CubeTextureLoader.js
  11796. /**
  11797. * @author mrdoob / http://mrdoob.com/
  11798. */
  11799. THREE.CubeTextureLoader = function ( manager ) {
  11800. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  11801. };
  11802. Object.assign( THREE.CubeTextureLoader.prototype, {
  11803. load: function ( urls, onLoad, onProgress, onError ) {
  11804. var texture = new THREE.CubeTexture();
  11805. var loader = new THREE.ImageLoader( this.manager );
  11806. loader.setCrossOrigin( this.crossOrigin );
  11807. loader.setPath( this.path );
  11808. var loaded = 0;
  11809. function loadTexture( i ) {
  11810. loader.load( urls[ i ], function ( image ) {
  11811. texture.images[ i ] = image;
  11812. loaded ++;
  11813. if ( loaded === 6 ) {
  11814. texture.needsUpdate = true;
  11815. if ( onLoad ) onLoad( texture );
  11816. }
  11817. }, undefined, onError );
  11818. }
  11819. for ( var i = 0; i < urls.length; ++ i ) {
  11820. loadTexture( i );
  11821. }
  11822. return texture;
  11823. },
  11824. setCrossOrigin: function ( value ) {
  11825. this.crossOrigin = value;
  11826. return this;
  11827. },
  11828. setPath: function ( value ) {
  11829. this.path = value;
  11830. return this;
  11831. }
  11832. } );
  11833. // File:src/loaders/BinaryTextureLoader.js
  11834. /**
  11835. * @author Nikos M. / https://github.com/foo123/
  11836. *
  11837. * Abstract Base class to load generic binary textures formats (rgbe, hdr, ...)
  11838. */
  11839. THREE.DataTextureLoader = THREE.BinaryTextureLoader = function ( manager ) {
  11840. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  11841. // override in sub classes
  11842. this._parser = null;
  11843. };
  11844. Object.assign( THREE.BinaryTextureLoader.prototype, {
  11845. load: function ( url, onLoad, onProgress, onError ) {
  11846. var scope = this;
  11847. var texture = new THREE.DataTexture();
  11848. var loader = new THREE.XHRLoader( this.manager );
  11849. loader.setResponseType( 'arraybuffer' );
  11850. loader.load( url, function ( buffer ) {
  11851. var texData = scope._parser( buffer );
  11852. if ( ! texData ) return;
  11853. if ( undefined !== texData.image ) {
  11854. texture.image = texData.image;
  11855. } else if ( undefined !== texData.data ) {
  11856. texture.image.width = texData.width;
  11857. texture.image.height = texData.height;
  11858. texture.image.data = texData.data;
  11859. }
  11860. texture.wrapS = undefined !== texData.wrapS ? texData.wrapS : THREE.ClampToEdgeWrapping;
  11861. texture.wrapT = undefined !== texData.wrapT ? texData.wrapT : THREE.ClampToEdgeWrapping;
  11862. texture.magFilter = undefined !== texData.magFilter ? texData.magFilter : THREE.LinearFilter;
  11863. texture.minFilter = undefined !== texData.minFilter ? texData.minFilter : THREE.LinearMipMapLinearFilter;
  11864. texture.anisotropy = undefined !== texData.anisotropy ? texData.anisotropy : 1;
  11865. if ( undefined !== texData.format ) {
  11866. texture.format = texData.format;
  11867. }
  11868. if ( undefined !== texData.type ) {
  11869. texture.type = texData.type;
  11870. }
  11871. if ( undefined !== texData.mipmaps ) {
  11872. texture.mipmaps = texData.mipmaps;
  11873. }
  11874. if ( 1 === texData.mipmapCount ) {
  11875. texture.minFilter = THREE.LinearFilter;
  11876. }
  11877. texture.needsUpdate = true;
  11878. if ( onLoad ) onLoad( texture, texData );
  11879. }, onProgress, onError );
  11880. return texture;
  11881. }
  11882. } );
  11883. // File:src/loaders/CompressedTextureLoader.js
  11884. /**
  11885. * @author mrdoob / http://mrdoob.com/
  11886. *
  11887. * Abstract Base class to block based textures loader (dds, pvr, ...)
  11888. */
  11889. THREE.CompressedTextureLoader = function ( manager ) {
  11890. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  11891. // override in sub classes
  11892. this._parser = null;
  11893. };
  11894. Object.assign( THREE.CompressedTextureLoader.prototype, {
  11895. load: function ( url, onLoad, onProgress, onError ) {
  11896. var scope = this;
  11897. var images = [];
  11898. var texture = new THREE.CompressedTexture();
  11899. texture.image = images;
  11900. var loader = new THREE.XHRLoader( this.manager );
  11901. loader.setPath( this.path );
  11902. loader.setResponseType( 'arraybuffer' );
  11903. function loadTexture( i ) {
  11904. loader.load( url[ i ], function ( buffer ) {
  11905. var texDatas = scope._parser( buffer, true );
  11906. images[ i ] = {
  11907. width: texDatas.width,
  11908. height: texDatas.height,
  11909. format: texDatas.format,
  11910. mipmaps: texDatas.mipmaps
  11911. };
  11912. loaded += 1;
  11913. if ( loaded === 6 ) {
  11914. if ( texDatas.mipmapCount === 1 )
  11915. texture.minFilter = THREE.LinearFilter;
  11916. texture.format = texDatas.format;
  11917. texture.needsUpdate = true;
  11918. if ( onLoad ) onLoad( texture );
  11919. }
  11920. }, onProgress, onError );
  11921. }
  11922. if ( Array.isArray( url ) ) {
  11923. var loaded = 0;
  11924. for ( var i = 0, il = url.length; i < il; ++ i ) {
  11925. loadTexture( i );
  11926. }
  11927. } else {
  11928. // compressed cubemap texture stored in a single DDS file
  11929. loader.load( url, function ( buffer ) {
  11930. var texDatas = scope._parser( buffer, true );
  11931. if ( texDatas.isCubemap ) {
  11932. var faces = texDatas.mipmaps.length / texDatas.mipmapCount;
  11933. for ( var f = 0; f < faces; f ++ ) {
  11934. images[ f ] = { mipmaps : [] };
  11935. for ( var i = 0; i < texDatas.mipmapCount; i ++ ) {
  11936. images[ f ].mipmaps.push( texDatas.mipmaps[ f * texDatas.mipmapCount + i ] );
  11937. images[ f ].format = texDatas.format;
  11938. images[ f ].width = texDatas.width;
  11939. images[ f ].height = texDatas.height;
  11940. }
  11941. }
  11942. } else {
  11943. texture.image.width = texDatas.width;
  11944. texture.image.height = texDatas.height;
  11945. texture.mipmaps = texDatas.mipmaps;
  11946. }
  11947. if ( texDatas.mipmapCount === 1 ) {
  11948. texture.minFilter = THREE.LinearFilter;
  11949. }
  11950. texture.format = texDatas.format;
  11951. texture.needsUpdate = true;
  11952. if ( onLoad ) onLoad( texture );
  11953. }, onProgress, onError );
  11954. }
  11955. return texture;
  11956. },
  11957. setPath: function ( value ) {
  11958. this.path = value;
  11959. return this;
  11960. }
  11961. } );
  11962. // File:src/materials/Material.js
  11963. /**
  11964. * @author mrdoob / http://mrdoob.com/
  11965. * @author alteredq / http://alteredqualia.com/
  11966. */
  11967. THREE.Material = function () {
  11968. Object.defineProperty( this, 'id', { value: THREE.MaterialIdCount ++ } );
  11969. this.uuid = THREE.Math.generateUUID();
  11970. this.name = '';
  11971. this.type = 'Material';
  11972. this.fog = true;
  11973. this.lights = true;
  11974. this.blending = THREE.NormalBlending;
  11975. this.side = THREE.FrontSide;
  11976. this.shading = THREE.SmoothShading; // THREE.FlatShading, THREE.SmoothShading
  11977. this.vertexColors = THREE.NoColors; // THREE.NoColors, THREE.VertexColors, THREE.FaceColors
  11978. this.opacity = 1;
  11979. this.transparent = false;
  11980. this.blendSrc = THREE.SrcAlphaFactor;
  11981. this.blendDst = THREE.OneMinusSrcAlphaFactor;
  11982. this.blendEquation = THREE.AddEquation;
  11983. this.blendSrcAlpha = null;
  11984. this.blendDstAlpha = null;
  11985. this.blendEquationAlpha = null;
  11986. this.depthFunc = THREE.LessEqualDepth;
  11987. this.depthTest = true;
  11988. this.depthWrite = true;
  11989. this.clippingPlanes = null;
  11990. this.clipShadows = false;
  11991. this.colorWrite = true;
  11992. this.precision = null; // override the renderer's default precision for this material
  11993. this.polygonOffset = false;
  11994. this.polygonOffsetFactor = 0;
  11995. this.polygonOffsetUnits = 0;
  11996. this.alphaTest = 0;
  11997. this.premultipliedAlpha = false;
  11998. this.overdraw = 0; // Overdrawn pixels (typically between 0 and 1) for fixing antialiasing gaps in CanvasRenderer
  11999. this.visible = true;
  12000. this._needsUpdate = true;
  12001. };
  12002. THREE.Material.prototype = {
  12003. constructor: THREE.Material,
  12004. get needsUpdate() {
  12005. return this._needsUpdate;
  12006. },
  12007. set needsUpdate( value ) {
  12008. if ( value === true ) this.update();
  12009. this._needsUpdate = value;
  12010. },
  12011. setValues: function ( values ) {
  12012. if ( values === undefined ) return;
  12013. for ( var key in values ) {
  12014. var newValue = values[ key ];
  12015. if ( newValue === undefined ) {
  12016. console.warn( "THREE.Material: '" + key + "' parameter is undefined." );
  12017. continue;
  12018. }
  12019. var currentValue = this[ key ];
  12020. if ( currentValue === undefined ) {
  12021. console.warn( "THREE." + this.type + ": '" + key + "' is not a property of this material." );
  12022. continue;
  12023. }
  12024. if ( currentValue instanceof THREE.Color ) {
  12025. currentValue.set( newValue );
  12026. } else if ( currentValue instanceof THREE.Vector3 && newValue instanceof THREE.Vector3 ) {
  12027. currentValue.copy( newValue );
  12028. } else if ( key === 'overdraw' ) {
  12029. // ensure overdraw is backwards-compatible with legacy boolean type
  12030. this[ key ] = Number( newValue );
  12031. } else {
  12032. this[ key ] = newValue;
  12033. }
  12034. }
  12035. },
  12036. toJSON: function ( meta ) {
  12037. var isRoot = meta === undefined;
  12038. if ( isRoot ) {
  12039. meta = {
  12040. textures: {},
  12041. images: {}
  12042. };
  12043. }
  12044. var data = {
  12045. metadata: {
  12046. version: 4.4,
  12047. type: 'Material',
  12048. generator: 'Material.toJSON'
  12049. }
  12050. };
  12051. // standard Material serialization
  12052. data.uuid = this.uuid;
  12053. data.type = this.type;
  12054. if ( this.name !== '' ) data.name = this.name;
  12055. if ( this.color instanceof THREE.Color ) data.color = this.color.getHex();
  12056. if ( this.roughness !== undefined ) data.roughness = this.roughness;
  12057. if ( this.metalness !== undefined ) data.metalness = this.metalness;
  12058. if ( this.emissive instanceof THREE.Color ) data.emissive = this.emissive.getHex();
  12059. if ( this.specular instanceof THREE.Color ) data.specular = this.specular.getHex();
  12060. if ( this.shininess !== undefined ) data.shininess = this.shininess;
  12061. if ( this.map instanceof THREE.Texture ) data.map = this.map.toJSON( meta ).uuid;
  12062. if ( this.alphaMap instanceof THREE.Texture ) data.alphaMap = this.alphaMap.toJSON( meta ).uuid;
  12063. if ( this.lightMap instanceof THREE.Texture ) data.lightMap = this.lightMap.toJSON( meta ).uuid;
  12064. if ( this.bumpMap instanceof THREE.Texture ) {
  12065. data.bumpMap = this.bumpMap.toJSON( meta ).uuid;
  12066. data.bumpScale = this.bumpScale;
  12067. }
  12068. if ( this.normalMap instanceof THREE.Texture ) {
  12069. data.normalMap = this.normalMap.toJSON( meta ).uuid;
  12070. data.normalScale = this.normalScale.toArray();
  12071. }
  12072. if ( this.displacementMap instanceof THREE.Texture ) {
  12073. data.displacementMap = this.displacementMap.toJSON( meta ).uuid;
  12074. data.displacementScale = this.displacementScale;
  12075. data.displacementBias = this.displacementBias;
  12076. }
  12077. if ( this.roughnessMap instanceof THREE.Texture ) data.roughnessMap = this.roughnessMap.toJSON( meta ).uuid;
  12078. if ( this.metalnessMap instanceof THREE.Texture ) data.metalnessMap = this.metalnessMap.toJSON( meta ).uuid;
  12079. if ( this.emissiveMap instanceof THREE.Texture ) data.emissiveMap = this.emissiveMap.toJSON( meta ).uuid;
  12080. if ( this.specularMap instanceof THREE.Texture ) data.specularMap = this.specularMap.toJSON( meta ).uuid;
  12081. if ( this.envMap instanceof THREE.Texture ) {
  12082. data.envMap = this.envMap.toJSON( meta ).uuid;
  12083. data.reflectivity = this.reflectivity; // Scale behind envMap
  12084. }
  12085. if ( this.size !== undefined ) data.size = this.size;
  12086. if ( this.sizeAttenuation !== undefined ) data.sizeAttenuation = this.sizeAttenuation;
  12087. if ( this.blending !== THREE.NormalBlending ) data.blending = this.blending;
  12088. if ( this.shading !== THREE.SmoothShading ) data.shading = this.shading;
  12089. if ( this.side !== THREE.FrontSide ) data.side = this.side;
  12090. if ( this.vertexColors !== THREE.NoColors ) data.vertexColors = this.vertexColors;
  12091. if ( this.opacity < 1 ) data.opacity = this.opacity;
  12092. if ( this.transparent === true ) data.transparent = this.transparent;
  12093. if ( this.alphaTest > 0 ) data.alphaTest = this.alphaTest;
  12094. if ( this.premultipliedAlpha === true ) data.premultipliedAlpha = this.premultipliedAlpha;
  12095. if ( this.wireframe === true ) data.wireframe = this.wireframe;
  12096. if ( this.wireframeLinewidth > 1 ) data.wireframeLinewidth = this.wireframeLinewidth;
  12097. // TODO: Copied from Object3D.toJSON
  12098. function extractFromCache ( cache ) {
  12099. var values = [];
  12100. for ( var key in cache ) {
  12101. var data = cache[ key ];
  12102. delete data.metadata;
  12103. values.push( data );
  12104. }
  12105. return values;
  12106. }
  12107. if ( isRoot ) {
  12108. var textures = extractFromCache( meta.textures );
  12109. var images = extractFromCache( meta.images );
  12110. if ( textures.length > 0 ) data.textures = textures;
  12111. if ( images.length > 0 ) data.images = images;
  12112. }
  12113. return data;
  12114. },
  12115. clone: function () {
  12116. return new this.constructor().copy( this );
  12117. },
  12118. copy: function ( source ) {
  12119. this.name = source.name;
  12120. this.fog = source.fog;
  12121. this.lights = source.lights;
  12122. this.blending = source.blending;
  12123. this.side = source.side;
  12124. this.shading = source.shading;
  12125. this.vertexColors = source.vertexColors;
  12126. this.opacity = source.opacity;
  12127. this.transparent = source.transparent;
  12128. this.blendSrc = source.blendSrc;
  12129. this.blendDst = source.blendDst;
  12130. this.blendEquation = source.blendEquation;
  12131. this.blendSrcAlpha = source.blendSrcAlpha;
  12132. this.blendDstAlpha = source.blendDstAlpha;
  12133. this.blendEquationAlpha = source.blendEquationAlpha;
  12134. this.depthFunc = source.depthFunc;
  12135. this.depthTest = source.depthTest;
  12136. this.depthWrite = source.depthWrite;
  12137. this.colorWrite = source.colorWrite;
  12138. this.precision = source.precision;
  12139. this.polygonOffset = source.polygonOffset;
  12140. this.polygonOffsetFactor = source.polygonOffsetFactor;
  12141. this.polygonOffsetUnits = source.polygonOffsetUnits;
  12142. this.alphaTest = source.alphaTest;
  12143. this.premultipliedAlpha = source.premultipliedAlpha;
  12144. this.overdraw = source.overdraw;
  12145. this.visible = source.visible;
  12146. this.clipShadows = source.clipShadows;
  12147. var srcPlanes = source.clippingPlanes,
  12148. dstPlanes = null;
  12149. if ( srcPlanes !== null ) {
  12150. var n = srcPlanes.length;
  12151. dstPlanes = new Array( n );
  12152. for ( var i = 0; i !== n; ++ i )
  12153. dstPlanes[ i ] = srcPlanes[ i ].clone();
  12154. }
  12155. this.clippingPlanes = dstPlanes;
  12156. return this;
  12157. },
  12158. update: function () {
  12159. this.dispatchEvent( { type: 'update' } );
  12160. },
  12161. dispose: function () {
  12162. this.dispatchEvent( { type: 'dispose' } );
  12163. }
  12164. };
  12165. Object.assign( THREE.Material.prototype, THREE.EventDispatcher.prototype );
  12166. THREE.MaterialIdCount = 0;
  12167. // File:src/materials/LineBasicMaterial.js
  12168. /**
  12169. * @author mrdoob / http://mrdoob.com/
  12170. * @author alteredq / http://alteredqualia.com/
  12171. *
  12172. * parameters = {
  12173. * color: <hex>,
  12174. * opacity: <float>,
  12175. *
  12176. * linewidth: <float>,
  12177. * linecap: "round",
  12178. * linejoin: "round"
  12179. * }
  12180. */
  12181. THREE.LineBasicMaterial = function ( parameters ) {
  12182. THREE.Material.call( this );
  12183. this.type = 'LineBasicMaterial';
  12184. this.color = new THREE.Color( 0xffffff );
  12185. this.linewidth = 1;
  12186. this.linecap = 'round';
  12187. this.linejoin = 'round';
  12188. this.lights = false;
  12189. this.setValues( parameters );
  12190. };
  12191. THREE.LineBasicMaterial.prototype = Object.create( THREE.Material.prototype );
  12192. THREE.LineBasicMaterial.prototype.constructor = THREE.LineBasicMaterial;
  12193. THREE.LineBasicMaterial.prototype.copy = function ( source ) {
  12194. THREE.Material.prototype.copy.call( this, source );
  12195. this.color.copy( source.color );
  12196. this.linewidth = source.linewidth;
  12197. this.linecap = source.linecap;
  12198. this.linejoin = source.linejoin;
  12199. return this;
  12200. };
  12201. // File:src/materials/LineDashedMaterial.js
  12202. /**
  12203. * @author alteredq / http://alteredqualia.com/
  12204. *
  12205. * parameters = {
  12206. * color: <hex>,
  12207. * opacity: <float>,
  12208. *
  12209. * linewidth: <float>,
  12210. *
  12211. * scale: <float>,
  12212. * dashSize: <float>,
  12213. * gapSize: <float>
  12214. * }
  12215. */
  12216. THREE.LineDashedMaterial = function ( parameters ) {
  12217. THREE.Material.call( this );
  12218. this.type = 'LineDashedMaterial';
  12219. this.color = new THREE.Color( 0xffffff );
  12220. this.linewidth = 1;
  12221. this.scale = 1;
  12222. this.dashSize = 3;
  12223. this.gapSize = 1;
  12224. this.lights = false;
  12225. this.setValues( parameters );
  12226. };
  12227. THREE.LineDashedMaterial.prototype = Object.create( THREE.Material.prototype );
  12228. THREE.LineDashedMaterial.prototype.constructor = THREE.LineDashedMaterial;
  12229. THREE.LineDashedMaterial.prototype.copy = function ( source ) {
  12230. THREE.Material.prototype.copy.call( this, source );
  12231. this.color.copy( source.color );
  12232. this.linewidth = source.linewidth;
  12233. this.scale = source.scale;
  12234. this.dashSize = source.dashSize;
  12235. this.gapSize = source.gapSize;
  12236. return this;
  12237. };
  12238. // File:src/materials/MeshBasicMaterial.js
  12239. /**
  12240. * @author mrdoob / http://mrdoob.com/
  12241. * @author alteredq / http://alteredqualia.com/
  12242. *
  12243. * parameters = {
  12244. * color: <hex>,
  12245. * opacity: <float>,
  12246. * map: new THREE.Texture( <Image> ),
  12247. *
  12248. * aoMap: new THREE.Texture( <Image> ),
  12249. * aoMapIntensity: <float>
  12250. *
  12251. * specularMap: new THREE.Texture( <Image> ),
  12252. *
  12253. * alphaMap: new THREE.Texture( <Image> ),
  12254. *
  12255. * envMap: new THREE.TextureCube( [posx, negx, posy, negy, posz, negz] ),
  12256. * combine: THREE.Multiply,
  12257. * reflectivity: <float>,
  12258. * refractionRatio: <float>,
  12259. *
  12260. * shading: THREE.SmoothShading,
  12261. * depthTest: <bool>,
  12262. * depthWrite: <bool>,
  12263. *
  12264. * wireframe: <boolean>,
  12265. * wireframeLinewidth: <float>,
  12266. *
  12267. * skinning: <bool>,
  12268. * morphTargets: <bool>
  12269. * }
  12270. */
  12271. THREE.MeshBasicMaterial = function ( parameters ) {
  12272. THREE.Material.call( this );
  12273. this.type = 'MeshBasicMaterial';
  12274. this.color = new THREE.Color( 0xffffff ); // emissive
  12275. this.map = null;
  12276. this.aoMap = null;
  12277. this.aoMapIntensity = 1.0;
  12278. this.specularMap = null;
  12279. this.alphaMap = null;
  12280. this.envMap = null;
  12281. this.combine = THREE.MultiplyOperation;
  12282. this.reflectivity = 1;
  12283. this.refractionRatio = 0.98;
  12284. this.wireframe = false;
  12285. this.wireframeLinewidth = 1;
  12286. this.wireframeLinecap = 'round';
  12287. this.wireframeLinejoin = 'round';
  12288. this.skinning = false;
  12289. this.morphTargets = false;
  12290. this.lights = false;
  12291. this.setValues( parameters );
  12292. };
  12293. THREE.MeshBasicMaterial.prototype = Object.create( THREE.Material.prototype );
  12294. THREE.MeshBasicMaterial.prototype.constructor = THREE.MeshBasicMaterial;
  12295. THREE.MeshBasicMaterial.prototype.copy = function ( source ) {
  12296. THREE.Material.prototype.copy.call( this, source );
  12297. this.color.copy( source.color );
  12298. this.map = source.map;
  12299. this.aoMap = source.aoMap;
  12300. this.aoMapIntensity = source.aoMapIntensity;
  12301. this.specularMap = source.specularMap;
  12302. this.alphaMap = source.alphaMap;
  12303. this.envMap = source.envMap;
  12304. this.combine = source.combine;
  12305. this.reflectivity = source.reflectivity;
  12306. this.refractionRatio = source.refractionRatio;
  12307. this.wireframe = source.wireframe;
  12308. this.wireframeLinewidth = source.wireframeLinewidth;
  12309. this.wireframeLinecap = source.wireframeLinecap;
  12310. this.wireframeLinejoin = source.wireframeLinejoin;
  12311. this.skinning = source.skinning;
  12312. this.morphTargets = source.morphTargets;
  12313. return this;
  12314. };
  12315. // File:src/materials/MeshDepthMaterial.js
  12316. /**
  12317. * @author mrdoob / http://mrdoob.com/
  12318. * @author alteredq / http://alteredqualia.com/
  12319. * @author bhouston / https://clara.io
  12320. * @author WestLangley / http://github.com/WestLangley
  12321. *
  12322. * parameters = {
  12323. *
  12324. * opacity: <float>,
  12325. *
  12326. * map: new THREE.Texture( <Image> ),
  12327. *
  12328. * alphaMap: new THREE.Texture( <Image> ),
  12329. *
  12330. * displacementMap: new THREE.Texture( <Image> ),
  12331. * displacementScale: <float>,
  12332. * displacementBias: <float>,
  12333. *
  12334. * wireframe: <boolean>,
  12335. * wireframeLinewidth: <float>
  12336. * }
  12337. */
  12338. THREE.MeshDepthMaterial = function ( parameters ) {
  12339. THREE.Material.call( this );
  12340. this.type = 'MeshDepthMaterial';
  12341. this.depthPacking = THREE.BasicDepthPacking;
  12342. this.skinning = false;
  12343. this.morphTargets = false;
  12344. this.map = null;
  12345. this.alphaMap = null;
  12346. this.displacementMap = null;
  12347. this.displacementScale = 1;
  12348. this.displacementBias = 0;
  12349. this.wireframe = false;
  12350. this.wireframeLinewidth = 1;
  12351. this.fog = false;
  12352. this.lights = false;
  12353. this.setValues( parameters );
  12354. };
  12355. THREE.MeshDepthMaterial.prototype = Object.create( THREE.Material.prototype );
  12356. THREE.MeshDepthMaterial.prototype.constructor = THREE.MeshDepthMaterial;
  12357. THREE.MeshDepthMaterial.prototype.copy = function ( source ) {
  12358. THREE.Material.prototype.copy.call( this, source );
  12359. this.depthPacking = source.depthPacking;
  12360. this.skinning = source.skinning;
  12361. this.morphTargets = source.morphTargets;
  12362. this.map = source.map;
  12363. this.alphaMap = source.alphaMap;
  12364. this.displacementMap = source.displacementMap;
  12365. this.displacementScale = source.displacementScale;
  12366. this.displacementBias = source.displacementBias;
  12367. this.wireframe = source.wireframe;
  12368. this.wireframeLinewidth = source.wireframeLinewidth;
  12369. return this;
  12370. };
  12371. // File:src/materials/MeshLambertMaterial.js
  12372. /**
  12373. * @author mrdoob / http://mrdoob.com/
  12374. * @author alteredq / http://alteredqualia.com/
  12375. *
  12376. * parameters = {
  12377. * color: <hex>,
  12378. * opacity: <float>,
  12379. *
  12380. * map: new THREE.Texture( <Image> ),
  12381. *
  12382. * lightMap: new THREE.Texture( <Image> ),
  12383. * lightMapIntensity: <float>
  12384. *
  12385. * aoMap: new THREE.Texture( <Image> ),
  12386. * aoMapIntensity: <float>
  12387. *
  12388. * emissive: <hex>,
  12389. * emissiveIntensity: <float>
  12390. * emissiveMap: new THREE.Texture( <Image> ),
  12391. *
  12392. * specularMap: new THREE.Texture( <Image> ),
  12393. *
  12394. * alphaMap: new THREE.Texture( <Image> ),
  12395. *
  12396. * envMap: new THREE.TextureCube( [posx, negx, posy, negy, posz, negz] ),
  12397. * combine: THREE.Multiply,
  12398. * reflectivity: <float>,
  12399. * refractionRatio: <float>,
  12400. *
  12401. * wireframe: <boolean>,
  12402. * wireframeLinewidth: <float>,
  12403. *
  12404. * skinning: <bool>,
  12405. * morphTargets: <bool>,
  12406. * morphNormals: <bool>
  12407. * }
  12408. */
  12409. THREE.MeshLambertMaterial = function ( parameters ) {
  12410. THREE.Material.call( this );
  12411. this.type = 'MeshLambertMaterial';
  12412. this.color = new THREE.Color( 0xffffff ); // diffuse
  12413. this.map = null;
  12414. this.lightMap = null;
  12415. this.lightMapIntensity = 1.0;
  12416. this.aoMap = null;
  12417. this.aoMapIntensity = 1.0;
  12418. this.emissive = new THREE.Color( 0x000000 );
  12419. this.emissiveIntensity = 1.0;
  12420. this.emissiveMap = null;
  12421. this.specularMap = null;
  12422. this.alphaMap = null;
  12423. this.envMap = null;
  12424. this.combine = THREE.MultiplyOperation;
  12425. this.reflectivity = 1;
  12426. this.refractionRatio = 0.98;
  12427. this.wireframe = false;
  12428. this.wireframeLinewidth = 1;
  12429. this.wireframeLinecap = 'round';
  12430. this.wireframeLinejoin = 'round';
  12431. this.skinning = false;
  12432. this.morphTargets = false;
  12433. this.morphNormals = false;
  12434. this.setValues( parameters );
  12435. };
  12436. THREE.MeshLambertMaterial.prototype = Object.create( THREE.Material.prototype );
  12437. THREE.MeshLambertMaterial.prototype.constructor = THREE.MeshLambertMaterial;
  12438. THREE.MeshLambertMaterial.prototype.copy = function ( source ) {
  12439. THREE.Material.prototype.copy.call( this, source );
  12440. this.color.copy( source.color );
  12441. this.map = source.map;
  12442. this.lightMap = source.lightMap;
  12443. this.lightMapIntensity = source.lightMapIntensity;
  12444. this.aoMap = source.aoMap;
  12445. this.aoMapIntensity = source.aoMapIntensity;
  12446. this.emissive.copy( source.emissive );
  12447. this.emissiveMap = source.emissiveMap;
  12448. this.emissiveIntensity = source.emissiveIntensity;
  12449. this.specularMap = source.specularMap;
  12450. this.alphaMap = source.alphaMap;
  12451. this.envMap = source.envMap;
  12452. this.combine = source.combine;
  12453. this.reflectivity = source.reflectivity;
  12454. this.refractionRatio = source.refractionRatio;
  12455. this.wireframe = source.wireframe;
  12456. this.wireframeLinewidth = source.wireframeLinewidth;
  12457. this.wireframeLinecap = source.wireframeLinecap;
  12458. this.wireframeLinejoin = source.wireframeLinejoin;
  12459. this.skinning = source.skinning;
  12460. this.morphTargets = source.morphTargets;
  12461. this.morphNormals = source.morphNormals;
  12462. return this;
  12463. };
  12464. // File:src/materials/MeshNormalMaterial.js
  12465. /**
  12466. * @author mrdoob / http://mrdoob.com/
  12467. *
  12468. * parameters = {
  12469. * opacity: <float>,
  12470. *
  12471. * wireframe: <boolean>,
  12472. * wireframeLinewidth: <float>
  12473. * }
  12474. */
  12475. THREE.MeshNormalMaterial = function ( parameters ) {
  12476. THREE.Material.call( this, parameters );
  12477. this.type = 'MeshNormalMaterial';
  12478. this.wireframe = false;
  12479. this.wireframeLinewidth = 1;
  12480. this.fog = false;
  12481. this.lights = false;
  12482. this.morphTargets = false;
  12483. this.setValues( parameters );
  12484. };
  12485. THREE.MeshNormalMaterial.prototype = Object.create( THREE.Material.prototype );
  12486. THREE.MeshNormalMaterial.prototype.constructor = THREE.MeshNormalMaterial;
  12487. THREE.MeshNormalMaterial.prototype.copy = function ( source ) {
  12488. THREE.Material.prototype.copy.call( this, source );
  12489. this.wireframe = source.wireframe;
  12490. this.wireframeLinewidth = source.wireframeLinewidth;
  12491. return this;
  12492. };
  12493. // File:src/materials/MeshPhongMaterial.js
  12494. /**
  12495. * @author mrdoob / http://mrdoob.com/
  12496. * @author alteredq / http://alteredqualia.com/
  12497. *
  12498. * parameters = {
  12499. * color: <hex>,
  12500. * specular: <hex>,
  12501. * shininess: <float>,
  12502. * opacity: <float>,
  12503. *
  12504. * map: new THREE.Texture( <Image> ),
  12505. *
  12506. * lightMap: new THREE.Texture( <Image> ),
  12507. * lightMapIntensity: <float>
  12508. *
  12509. * aoMap: new THREE.Texture( <Image> ),
  12510. * aoMapIntensity: <float>
  12511. *
  12512. * emissive: <hex>,
  12513. * emissiveIntensity: <float>
  12514. * emissiveMap: new THREE.Texture( <Image> ),
  12515. *
  12516. * bumpMap: new THREE.Texture( <Image> ),
  12517. * bumpScale: <float>,
  12518. *
  12519. * normalMap: new THREE.Texture( <Image> ),
  12520. * normalScale: <Vector2>,
  12521. *
  12522. * displacementMap: new THREE.Texture( <Image> ),
  12523. * displacementScale: <float>,
  12524. * displacementBias: <float>,
  12525. *
  12526. * specularMap: new THREE.Texture( <Image> ),
  12527. *
  12528. * alphaMap: new THREE.Texture( <Image> ),
  12529. *
  12530. * envMap: new THREE.TextureCube( [posx, negx, posy, negy, posz, negz] ),
  12531. * combine: THREE.Multiply,
  12532. * reflectivity: <float>,
  12533. * refractionRatio: <float>,
  12534. *
  12535. * wireframe: <boolean>,
  12536. * wireframeLinewidth: <float>,
  12537. *
  12538. * skinning: <bool>,
  12539. * morphTargets: <bool>,
  12540. * morphNormals: <bool>
  12541. * }
  12542. */
  12543. THREE.MeshPhongMaterial = function ( parameters ) {
  12544. THREE.Material.call( this );
  12545. this.type = 'MeshPhongMaterial';
  12546. this.color = new THREE.Color( 0xffffff ); // diffuse
  12547. this.specular = new THREE.Color( 0x111111 );
  12548. this.shininess = 30;
  12549. this.map = null;
  12550. this.lightMap = null;
  12551. this.lightMapIntensity = 1.0;
  12552. this.aoMap = null;
  12553. this.aoMapIntensity = 1.0;
  12554. this.emissive = new THREE.Color( 0x000000 );
  12555. this.emissiveIntensity = 1.0;
  12556. this.emissiveMap = null;
  12557. this.bumpMap = null;
  12558. this.bumpScale = 1;
  12559. this.normalMap = null;
  12560. this.normalScale = new THREE.Vector2( 1, 1 );
  12561. this.displacementMap = null;
  12562. this.displacementScale = 1;
  12563. this.displacementBias = 0;
  12564. this.specularMap = null;
  12565. this.alphaMap = null;
  12566. this.envMap = null;
  12567. this.combine = THREE.MultiplyOperation;
  12568. this.reflectivity = 1;
  12569. this.refractionRatio = 0.98;
  12570. this.wireframe = false;
  12571. this.wireframeLinewidth = 1;
  12572. this.wireframeLinecap = 'round';
  12573. this.wireframeLinejoin = 'round';
  12574. this.skinning = false;
  12575. this.morphTargets = false;
  12576. this.morphNormals = false;
  12577. this.setValues( parameters );
  12578. };
  12579. THREE.MeshPhongMaterial.prototype = Object.create( THREE.Material.prototype );
  12580. THREE.MeshPhongMaterial.prototype.constructor = THREE.MeshPhongMaterial;
  12581. THREE.MeshPhongMaterial.prototype.copy = function ( source ) {
  12582. THREE.Material.prototype.copy.call( this, source );
  12583. this.color.copy( source.color );
  12584. this.specular.copy( source.specular );
  12585. this.shininess = source.shininess;
  12586. this.map = source.map;
  12587. this.lightMap = source.lightMap;
  12588. this.lightMapIntensity = source.lightMapIntensity;
  12589. this.aoMap = source.aoMap;
  12590. this.aoMapIntensity = source.aoMapIntensity;
  12591. this.emissive.copy( source.emissive );
  12592. this.emissiveMap = source.emissiveMap;
  12593. this.emissiveIntensity = source.emissiveIntensity;
  12594. this.bumpMap = source.bumpMap;
  12595. this.bumpScale = source.bumpScale;
  12596. this.normalMap = source.normalMap;
  12597. this.normalScale.copy( source.normalScale );
  12598. this.displacementMap = source.displacementMap;
  12599. this.displacementScale = source.displacementScale;
  12600. this.displacementBias = source.displacementBias;
  12601. this.specularMap = source.specularMap;
  12602. this.alphaMap = source.alphaMap;
  12603. this.envMap = source.envMap;
  12604. this.combine = source.combine;
  12605. this.reflectivity = source.reflectivity;
  12606. this.refractionRatio = source.refractionRatio;
  12607. this.wireframe = source.wireframe;
  12608. this.wireframeLinewidth = source.wireframeLinewidth;
  12609. this.wireframeLinecap = source.wireframeLinecap;
  12610. this.wireframeLinejoin = source.wireframeLinejoin;
  12611. this.skinning = source.skinning;
  12612. this.morphTargets = source.morphTargets;
  12613. this.morphNormals = source.morphNormals;
  12614. return this;
  12615. };
  12616. // File:src/materials/MeshStandardMaterial.js
  12617. /**
  12618. * @author WestLangley / http://github.com/WestLangley
  12619. *
  12620. * parameters = {
  12621. * color: <hex>,
  12622. * roughness: <float>,
  12623. * metalness: <float>,
  12624. * opacity: <float>,
  12625. *
  12626. * map: new THREE.Texture( <Image> ),
  12627. *
  12628. * lightMap: new THREE.Texture( <Image> ),
  12629. * lightMapIntensity: <float>
  12630. *
  12631. * aoMap: new THREE.Texture( <Image> ),
  12632. * aoMapIntensity: <float>
  12633. *
  12634. * emissive: <hex>,
  12635. * emissiveIntensity: <float>
  12636. * emissiveMap: new THREE.Texture( <Image> ),
  12637. *
  12638. * bumpMap: new THREE.Texture( <Image> ),
  12639. * bumpScale: <float>,
  12640. *
  12641. * normalMap: new THREE.Texture( <Image> ),
  12642. * normalScale: <Vector2>,
  12643. *
  12644. * displacementMap: new THREE.Texture( <Image> ),
  12645. * displacementScale: <float>,
  12646. * displacementBias: <float>,
  12647. *
  12648. * roughnessMap: new THREE.Texture( <Image> ),
  12649. *
  12650. * metalnessMap: new THREE.Texture( <Image> ),
  12651. *
  12652. * alphaMap: new THREE.Texture( <Image> ),
  12653. *
  12654. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  12655. * envMapIntensity: <float>
  12656. *
  12657. * refractionRatio: <float>,
  12658. *
  12659. * wireframe: <boolean>,
  12660. * wireframeLinewidth: <float>,
  12661. *
  12662. * skinning: <bool>,
  12663. * morphTargets: <bool>,
  12664. * morphNormals: <bool>
  12665. * }
  12666. */
  12667. THREE.MeshStandardMaterial = function ( parameters ) {
  12668. THREE.Material.call( this );
  12669. this.defines = { 'STANDARD': '' };
  12670. this.type = 'MeshStandardMaterial';
  12671. this.color = new THREE.Color( 0xffffff ); // diffuse
  12672. this.roughness = 0.5;
  12673. this.metalness = 0.5;
  12674. this.map = null;
  12675. this.lightMap = null;
  12676. this.lightMapIntensity = 1.0;
  12677. this.aoMap = null;
  12678. this.aoMapIntensity = 1.0;
  12679. this.emissive = new THREE.Color( 0x000000 );
  12680. this.emissiveIntensity = 1.0;
  12681. this.emissiveMap = null;
  12682. this.bumpMap = null;
  12683. this.bumpScale = 1;
  12684. this.normalMap = null;
  12685. this.normalScale = new THREE.Vector2( 1, 1 );
  12686. this.displacementMap = null;
  12687. this.displacementScale = 1;
  12688. this.displacementBias = 0;
  12689. this.roughnessMap = null;
  12690. this.metalnessMap = null;
  12691. this.alphaMap = null;
  12692. this.envMap = null;
  12693. this.envMapIntensity = 1.0;
  12694. this.refractionRatio = 0.98;
  12695. this.wireframe = false;
  12696. this.wireframeLinewidth = 1;
  12697. this.wireframeLinecap = 'round';
  12698. this.wireframeLinejoin = 'round';
  12699. this.skinning = false;
  12700. this.morphTargets = false;
  12701. this.morphNormals = false;
  12702. this.setValues( parameters );
  12703. };
  12704. THREE.MeshStandardMaterial.prototype = Object.create( THREE.Material.prototype );
  12705. THREE.MeshStandardMaterial.prototype.constructor = THREE.MeshStandardMaterial;
  12706. THREE.MeshStandardMaterial.prototype.copy = function ( source ) {
  12707. THREE.Material.prototype.copy.call( this, source );
  12708. this.defines = { 'STANDARD': '' };
  12709. this.color.copy( source.color );
  12710. this.roughness = source.roughness;
  12711. this.metalness = source.metalness;
  12712. this.map = source.map;
  12713. this.lightMap = source.lightMap;
  12714. this.lightMapIntensity = source.lightMapIntensity;
  12715. this.aoMap = source.aoMap;
  12716. this.aoMapIntensity = source.aoMapIntensity;
  12717. this.emissive.copy( source.emissive );
  12718. this.emissiveMap = source.emissiveMap;
  12719. this.emissiveIntensity = source.emissiveIntensity;
  12720. this.bumpMap = source.bumpMap;
  12721. this.bumpScale = source.bumpScale;
  12722. this.normalMap = source.normalMap;
  12723. this.normalScale.copy( source.normalScale );
  12724. this.displacementMap = source.displacementMap;
  12725. this.displacementScale = source.displacementScale;
  12726. this.displacementBias = source.displacementBias;
  12727. this.roughnessMap = source.roughnessMap;
  12728. this.metalnessMap = source.metalnessMap;
  12729. this.alphaMap = source.alphaMap;
  12730. this.envMap = source.envMap;
  12731. this.envMapIntensity = source.envMapIntensity;
  12732. this.refractionRatio = source.refractionRatio;
  12733. this.wireframe = source.wireframe;
  12734. this.wireframeLinewidth = source.wireframeLinewidth;
  12735. this.wireframeLinecap = source.wireframeLinecap;
  12736. this.wireframeLinejoin = source.wireframeLinejoin;
  12737. this.skinning = source.skinning;
  12738. this.morphTargets = source.morphTargets;
  12739. this.morphNormals = source.morphNormals;
  12740. return this;
  12741. };
  12742. // File:src/materials/MeshPhysicalMaterial.js
  12743. /**
  12744. * @author WestLangley / http://github.com/WestLangley
  12745. *
  12746. * parameters = {
  12747. * reflectivity: <float>
  12748. * }
  12749. */
  12750. THREE.MeshPhysicalMaterial = function ( parameters ) {
  12751. THREE.MeshStandardMaterial.call( this );
  12752. this.defines = { 'PHYSICAL': '' };
  12753. this.type = 'MeshPhysicalMaterial';
  12754. this.reflectivity = 0.5; // maps to F0 = 0.04
  12755. this.clearCoat = 0.0;
  12756. this.clearCoatRoughness = 0.0;
  12757. this.setValues( parameters );
  12758. };
  12759. THREE.MeshPhysicalMaterial.prototype = Object.create( THREE.MeshStandardMaterial.prototype );
  12760. THREE.MeshPhysicalMaterial.prototype.constructor = THREE.MeshPhysicalMaterial;
  12761. THREE.MeshPhysicalMaterial.prototype.copy = function ( source ) {
  12762. THREE.MeshStandardMaterial.prototype.copy.call( this, source );
  12763. this.defines = { 'PHYSICAL': '' };
  12764. this.reflectivity = source.reflectivity;
  12765. this.clearCoat = source.clearCoat;
  12766. this.clearCoatRoughness = source.clearCoatRoughness;
  12767. return this;
  12768. };
  12769. // File:src/materials/MultiMaterial.js
  12770. /**
  12771. * @author mrdoob / http://mrdoob.com/
  12772. */
  12773. THREE.MultiMaterial = function ( materials ) {
  12774. this.uuid = THREE.Math.generateUUID();
  12775. this.type = 'MultiMaterial';
  12776. this.materials = materials instanceof Array ? materials : [];
  12777. this.visible = true;
  12778. };
  12779. THREE.MultiMaterial.prototype = {
  12780. constructor: THREE.MultiMaterial,
  12781. toJSON: function ( meta ) {
  12782. var output = {
  12783. metadata: {
  12784. version: 4.2,
  12785. type: 'material',
  12786. generator: 'MaterialExporter'
  12787. },
  12788. uuid: this.uuid,
  12789. type: this.type,
  12790. materials: []
  12791. };
  12792. var materials = this.materials;
  12793. for ( var i = 0, l = materials.length; i < l; i ++ ) {
  12794. var material = materials[ i ].toJSON( meta );
  12795. delete material.metadata;
  12796. output.materials.push( material );
  12797. }
  12798. output.visible = this.visible;
  12799. return output;
  12800. },
  12801. clone: function () {
  12802. var material = new this.constructor();
  12803. for ( var i = 0; i < this.materials.length; i ++ ) {
  12804. material.materials.push( this.materials[ i ].clone() );
  12805. }
  12806. material.visible = this.visible;
  12807. return material;
  12808. }
  12809. };
  12810. // File:src/materials/PointsMaterial.js
  12811. /**
  12812. * @author mrdoob / http://mrdoob.com/
  12813. * @author alteredq / http://alteredqualia.com/
  12814. *
  12815. * parameters = {
  12816. * color: <hex>,
  12817. * opacity: <float>,
  12818. * map: new THREE.Texture( <Image> ),
  12819. *
  12820. * size: <float>,
  12821. * sizeAttenuation: <bool>
  12822. * }
  12823. */
  12824. THREE.PointsMaterial = function ( parameters ) {
  12825. THREE.Material.call( this );
  12826. this.type = 'PointsMaterial';
  12827. this.color = new THREE.Color( 0xffffff );
  12828. this.map = null;
  12829. this.size = 1;
  12830. this.sizeAttenuation = true;
  12831. this.lights = false;
  12832. this.setValues( parameters );
  12833. };
  12834. THREE.PointsMaterial.prototype = Object.create( THREE.Material.prototype );
  12835. THREE.PointsMaterial.prototype.constructor = THREE.PointsMaterial;
  12836. THREE.PointsMaterial.prototype.copy = function ( source ) {
  12837. THREE.Material.prototype.copy.call( this, source );
  12838. this.color.copy( source.color );
  12839. this.map = source.map;
  12840. this.size = source.size;
  12841. this.sizeAttenuation = source.sizeAttenuation;
  12842. return this;
  12843. };
  12844. // File:src/materials/ShaderMaterial.js
  12845. /**
  12846. * @author alteredq / http://alteredqualia.com/
  12847. *
  12848. * parameters = {
  12849. * defines: { "label" : "value" },
  12850. * uniforms: { "parameter1": { value: 1.0 }, "parameter2": { value2: 2 } },
  12851. *
  12852. * fragmentShader: <string>,
  12853. * vertexShader: <string>,
  12854. *
  12855. * wireframe: <boolean>,
  12856. * wireframeLinewidth: <float>,
  12857. *
  12858. * lights: <bool>,
  12859. *
  12860. * skinning: <bool>,
  12861. * morphTargets: <bool>,
  12862. * morphNormals: <bool>
  12863. * }
  12864. */
  12865. THREE.ShaderMaterial = function ( parameters ) {
  12866. THREE.Material.call( this );
  12867. this.type = 'ShaderMaterial';
  12868. this.defines = {};
  12869. this.uniforms = {};
  12870. this.vertexShader = 'void main() {\n\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}';
  12871. this.fragmentShader = 'void main() {\n\tgl_FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );\n}';
  12872. this.linewidth = 1;
  12873. this.wireframe = false;
  12874. this.wireframeLinewidth = 1;
  12875. this.fog = false; // set to use scene fog
  12876. this.lights = false; // set to use scene lights
  12877. this.clipping = false; // set to use user-defined clipping planes
  12878. this.skinning = false; // set to use skinning attribute streams
  12879. this.morphTargets = false; // set to use morph targets
  12880. this.morphNormals = false; // set to use morph normals
  12881. this.extensions = {
  12882. derivatives: false, // set to use derivatives
  12883. fragDepth: false, // set to use fragment depth values
  12884. drawBuffers: false, // set to use draw buffers
  12885. shaderTextureLOD: false // set to use shader texture LOD
  12886. };
  12887. // When rendered geometry doesn't include these attributes but the material does,
  12888. // use these default values in WebGL. This avoids errors when buffer data is missing.
  12889. this.defaultAttributeValues = {
  12890. 'color': [ 1, 1, 1 ],
  12891. 'uv': [ 0, 0 ],
  12892. 'uv2': [ 0, 0 ]
  12893. };
  12894. this.index0AttributeName = undefined;
  12895. if ( parameters !== undefined ) {
  12896. if ( parameters.attributes !== undefined ) {
  12897. console.error( 'THREE.ShaderMaterial: attributes should now be defined in THREE.BufferGeometry instead.' );
  12898. }
  12899. this.setValues( parameters );
  12900. }
  12901. };
  12902. THREE.ShaderMaterial.prototype = Object.create( THREE.Material.prototype );
  12903. THREE.ShaderMaterial.prototype.constructor = THREE.ShaderMaterial;
  12904. THREE.ShaderMaterial.prototype.copy = function ( source ) {
  12905. THREE.Material.prototype.copy.call( this, source );
  12906. this.fragmentShader = source.fragmentShader;
  12907. this.vertexShader = source.vertexShader;
  12908. this.uniforms = THREE.UniformsUtils.clone( source.uniforms );
  12909. this.defines = source.defines;
  12910. this.wireframe = source.wireframe;
  12911. this.wireframeLinewidth = source.wireframeLinewidth;
  12912. this.lights = source.lights;
  12913. this.clipping = source.clipping;
  12914. this.skinning = source.skinning;
  12915. this.morphTargets = source.morphTargets;
  12916. this.morphNormals = source.morphNormals;
  12917. this.extensions = source.extensions;
  12918. return this;
  12919. };
  12920. THREE.ShaderMaterial.prototype.toJSON = function ( meta ) {
  12921. var data = THREE.Material.prototype.toJSON.call( this, meta );
  12922. data.uniforms = this.uniforms;
  12923. data.vertexShader = this.vertexShader;
  12924. data.fragmentShader = this.fragmentShader;
  12925. return data;
  12926. };
  12927. // File:src/materials/RawShaderMaterial.js
  12928. /**
  12929. * @author mrdoob / http://mrdoob.com/
  12930. */
  12931. THREE.RawShaderMaterial = function ( parameters ) {
  12932. THREE.ShaderMaterial.call( this, parameters );
  12933. this.type = 'RawShaderMaterial';
  12934. };
  12935. THREE.RawShaderMaterial.prototype = Object.create( THREE.ShaderMaterial.prototype );
  12936. THREE.RawShaderMaterial.prototype.constructor = THREE.RawShaderMaterial;
  12937. // File:src/materials/SpriteMaterial.js
  12938. /**
  12939. * @author alteredq / http://alteredqualia.com/
  12940. *
  12941. * parameters = {
  12942. * color: <hex>,
  12943. * opacity: <float>,
  12944. * map: new THREE.Texture( <Image> ),
  12945. *
  12946. * uvOffset: new THREE.Vector2(),
  12947. * uvScale: new THREE.Vector2()
  12948. * }
  12949. */
  12950. THREE.SpriteMaterial = function ( parameters ) {
  12951. THREE.Material.call( this );
  12952. this.type = 'SpriteMaterial';
  12953. this.color = new THREE.Color( 0xffffff );
  12954. this.map = null;
  12955. this.rotation = 0;
  12956. this.fog = false;
  12957. this.lights = false;
  12958. this.setValues( parameters );
  12959. };
  12960. THREE.SpriteMaterial.prototype = Object.create( THREE.Material.prototype );
  12961. THREE.SpriteMaterial.prototype.constructor = THREE.SpriteMaterial;
  12962. THREE.SpriteMaterial.prototype.copy = function ( source ) {
  12963. THREE.Material.prototype.copy.call( this, source );
  12964. this.color.copy( source.color );
  12965. this.map = source.map;
  12966. this.rotation = source.rotation;
  12967. return this;
  12968. };
  12969. // File:src/materials/ShadowMaterial.js
  12970. /**
  12971. * @author mrdoob / http://mrdoob.com/
  12972. */
  12973. THREE.ShadowMaterial = function () {
  12974. THREE.ShaderMaterial.call( this, {
  12975. uniforms: THREE.UniformsUtils.merge( [
  12976. THREE.UniformsLib[ "lights" ],
  12977. {
  12978. opacity: { value: 1.0 }
  12979. }
  12980. ] ),
  12981. vertexShader: THREE.ShaderChunk[ 'shadow_vert' ],
  12982. fragmentShader: THREE.ShaderChunk[ 'shadow_frag' ]
  12983. } );
  12984. this.lights = true;
  12985. this.transparent = true;
  12986. Object.defineProperties( this, {
  12987. opacity: {
  12988. enumerable: true,
  12989. get: function () {
  12990. return this.uniforms.opacity.value;
  12991. },
  12992. set: function ( value ) {
  12993. this.uniforms.opacity.value = value;
  12994. }
  12995. }
  12996. } );
  12997. };
  12998. THREE.ShadowMaterial.prototype = Object.create( THREE.ShaderMaterial.prototype );
  12999. THREE.ShadowMaterial.prototype.constructor = THREE.ShadowMaterial;
  13000. // File:src/textures/Texture.js
  13001. /**
  13002. * @author mrdoob / http://mrdoob.com/
  13003. * @author alteredq / http://alteredqualia.com/
  13004. * @author szimek / https://github.com/szimek/
  13005. */
  13006. THREE.Texture = function ( image, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding ) {
  13007. Object.defineProperty( this, 'id', { value: THREE.TextureIdCount ++ } );
  13008. this.uuid = THREE.Math.generateUUID();
  13009. this.name = '';
  13010. this.sourceFile = '';
  13011. this.image = image !== undefined ? image : THREE.Texture.DEFAULT_IMAGE;
  13012. this.mipmaps = [];
  13013. this.mapping = mapping !== undefined ? mapping : THREE.Texture.DEFAULT_MAPPING;
  13014. this.wrapS = wrapS !== undefined ? wrapS : THREE.ClampToEdgeWrapping;
  13015. this.wrapT = wrapT !== undefined ? wrapT : THREE.ClampToEdgeWrapping;
  13016. this.magFilter = magFilter !== undefined ? magFilter : THREE.LinearFilter;
  13017. this.minFilter = minFilter !== undefined ? minFilter : THREE.LinearMipMapLinearFilter;
  13018. this.anisotropy = anisotropy !== undefined ? anisotropy : 1;
  13019. this.format = format !== undefined ? format : THREE.RGBAFormat;
  13020. this.type = type !== undefined ? type : THREE.UnsignedByteType;
  13021. this.offset = new THREE.Vector2( 0, 0 );
  13022. this.repeat = new THREE.Vector2( 1, 1 );
  13023. this.generateMipmaps = true;
  13024. this.premultiplyAlpha = false;
  13025. this.flipY = true;
  13026. this.unpackAlignment = 4; // valid values: 1, 2, 4, 8 (see http://www.khronos.org/opengles/sdk/docs/man/xhtml/glPixelStorei.xml)
  13027. // Values of encoding !== THREE.LinearEncoding only supported on map, envMap and emissiveMap.
  13028. //
  13029. // Also changing the encoding after already used by a Material will not automatically make the Material
  13030. // update. You need to explicitly call Material.needsUpdate to trigger it to recompile.
  13031. this.encoding = encoding !== undefined ? encoding : THREE.LinearEncoding;
  13032. this.version = 0;
  13033. this.onUpdate = null;
  13034. };
  13035. THREE.Texture.DEFAULT_IMAGE = undefined;
  13036. THREE.Texture.DEFAULT_MAPPING = THREE.UVMapping;
  13037. THREE.Texture.prototype = {
  13038. constructor: THREE.Texture,
  13039. set needsUpdate( value ) {
  13040. if ( value === true ) this.version ++;
  13041. },
  13042. clone: function () {
  13043. return new this.constructor().copy( this );
  13044. },
  13045. copy: function ( source ) {
  13046. this.image = source.image;
  13047. this.mipmaps = source.mipmaps.slice( 0 );
  13048. this.mapping = source.mapping;
  13049. this.wrapS = source.wrapS;
  13050. this.wrapT = source.wrapT;
  13051. this.magFilter = source.magFilter;
  13052. this.minFilter = source.minFilter;
  13053. this.anisotropy = source.anisotropy;
  13054. this.format = source.format;
  13055. this.type = source.type;
  13056. this.offset.copy( source.offset );
  13057. this.repeat.copy( source.repeat );
  13058. this.generateMipmaps = source.generateMipmaps;
  13059. this.premultiplyAlpha = source.premultiplyAlpha;
  13060. this.flipY = source.flipY;
  13061. this.unpackAlignment = source.unpackAlignment;
  13062. this.encoding = source.encoding;
  13063. return this;
  13064. },
  13065. toJSON: function ( meta ) {
  13066. if ( meta.textures[ this.uuid ] !== undefined ) {
  13067. return meta.textures[ this.uuid ];
  13068. }
  13069. function getDataURL( image ) {
  13070. var canvas;
  13071. if ( image.toDataURL !== undefined ) {
  13072. canvas = image;
  13073. } else {
  13074. canvas = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' );
  13075. canvas.width = image.width;
  13076. canvas.height = image.height;
  13077. canvas.getContext( '2d' ).drawImage( image, 0, 0, image.width, image.height );
  13078. }
  13079. if ( canvas.width > 2048 || canvas.height > 2048 ) {
  13080. return canvas.toDataURL( 'image/jpeg', 0.6 );
  13081. } else {
  13082. return canvas.toDataURL( 'image/png' );
  13083. }
  13084. }
  13085. var output = {
  13086. metadata: {
  13087. version: 4.4,
  13088. type: 'Texture',
  13089. generator: 'Texture.toJSON'
  13090. },
  13091. uuid: this.uuid,
  13092. name: this.name,
  13093. mapping: this.mapping,
  13094. repeat: [ this.repeat.x, this.repeat.y ],
  13095. offset: [ this.offset.x, this.offset.y ],
  13096. wrap: [ this.wrapS, this.wrapT ],
  13097. minFilter: this.minFilter,
  13098. magFilter: this.magFilter,
  13099. anisotropy: this.anisotropy
  13100. };
  13101. if ( this.image !== undefined ) {
  13102. // TODO: Move to THREE.Image
  13103. var image = this.image;
  13104. if ( image.uuid === undefined ) {
  13105. image.uuid = THREE.Math.generateUUID(); // UGH
  13106. }
  13107. if ( meta.images[ image.uuid ] === undefined ) {
  13108. meta.images[ image.uuid ] = {
  13109. uuid: image.uuid,
  13110. url: getDataURL( image )
  13111. };
  13112. }
  13113. output.image = image.uuid;
  13114. }
  13115. meta.textures[ this.uuid ] = output;
  13116. return output;
  13117. },
  13118. dispose: function () {
  13119. this.dispatchEvent( { type: 'dispose' } );
  13120. },
  13121. transformUv: function ( uv ) {
  13122. if ( this.mapping !== THREE.UVMapping ) return;
  13123. uv.multiply( this.repeat );
  13124. uv.add( this.offset );
  13125. if ( uv.x < 0 || uv.x > 1 ) {
  13126. switch ( this.wrapS ) {
  13127. case THREE.RepeatWrapping:
  13128. uv.x = uv.x - Math.floor( uv.x );
  13129. break;
  13130. case THREE.ClampToEdgeWrapping:
  13131. uv.x = uv.x < 0 ? 0 : 1;
  13132. break;
  13133. case THREE.MirroredRepeatWrapping:
  13134. if ( Math.abs( Math.floor( uv.x ) % 2 ) === 1 ) {
  13135. uv.x = Math.ceil( uv.x ) - uv.x;
  13136. } else {
  13137. uv.x = uv.x - Math.floor( uv.x );
  13138. }
  13139. break;
  13140. }
  13141. }
  13142. if ( uv.y < 0 || uv.y > 1 ) {
  13143. switch ( this.wrapT ) {
  13144. case THREE.RepeatWrapping:
  13145. uv.y = uv.y - Math.floor( uv.y );
  13146. break;
  13147. case THREE.ClampToEdgeWrapping:
  13148. uv.y = uv.y < 0 ? 0 : 1;
  13149. break;
  13150. case THREE.MirroredRepeatWrapping:
  13151. if ( Math.abs( Math.floor( uv.y ) % 2 ) === 1 ) {
  13152. uv.y = Math.ceil( uv.y ) - uv.y;
  13153. } else {
  13154. uv.y = uv.y - Math.floor( uv.y );
  13155. }
  13156. break;
  13157. }
  13158. }
  13159. if ( this.flipY ) {
  13160. uv.y = 1 - uv.y;
  13161. }
  13162. }
  13163. };
  13164. Object.assign( THREE.Texture.prototype, THREE.EventDispatcher.prototype );
  13165. THREE.TextureIdCount = 0;
  13166. // File:src/textures/DepthTexture.js
  13167. /**
  13168. * @author Matt DesLauriers / @mattdesl
  13169. */
  13170. THREE.DepthTexture = function ( width, height, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy ) {
  13171. THREE.Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, THREE.DepthFormat, type, anisotropy );
  13172. this.image = { width: width, height: height };
  13173. this.type = type !== undefined ? type : THREE.UnsignedShortType;
  13174. this.magFilter = magFilter !== undefined ? magFilter : THREE.NearestFilter;
  13175. this.minFilter = minFilter !== undefined ? minFilter : THREE.NearestFilter;
  13176. this.flipY = false;
  13177. this.generateMipmaps = false;
  13178. };
  13179. THREE.DepthTexture.prototype = Object.create( THREE.Texture.prototype );
  13180. THREE.DepthTexture.prototype.constructor = THREE.DepthTexture;
  13181. // File:src/textures/CanvasTexture.js
  13182. /**
  13183. * @author mrdoob / http://mrdoob.com/
  13184. */
  13185. THREE.CanvasTexture = function ( canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  13186. THREE.Texture.call( this, canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  13187. this.needsUpdate = true;
  13188. };
  13189. THREE.CanvasTexture.prototype = Object.create( THREE.Texture.prototype );
  13190. THREE.CanvasTexture.prototype.constructor = THREE.CanvasTexture;
  13191. // File:src/textures/CubeTexture.js
  13192. /**
  13193. * @author mrdoob / http://mrdoob.com/
  13194. */
  13195. THREE.CubeTexture = function ( images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding ) {
  13196. images = images !== undefined ? images : [];
  13197. mapping = mapping !== undefined ? mapping : THREE.CubeReflectionMapping;
  13198. THREE.Texture.call( this, images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding );
  13199. this.flipY = false;
  13200. };
  13201. THREE.CubeTexture.prototype = Object.create( THREE.Texture.prototype );
  13202. THREE.CubeTexture.prototype.constructor = THREE.CubeTexture;
  13203. Object.defineProperty( THREE.CubeTexture.prototype, 'images', {
  13204. get: function () {
  13205. return this.image;
  13206. },
  13207. set: function ( value ) {
  13208. this.image = value;
  13209. }
  13210. } );
  13211. // File:src/textures/CompressedTexture.js
  13212. /**
  13213. * @author alteredq / http://alteredqualia.com/
  13214. */
  13215. THREE.CompressedTexture = function ( mipmaps, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, encoding ) {
  13216. THREE.Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding );
  13217. this.image = { width: width, height: height };
  13218. this.mipmaps = mipmaps;
  13219. // no flipping for cube textures
  13220. // (also flipping doesn't work for compressed textures )
  13221. this.flipY = false;
  13222. // can't generate mipmaps for compressed textures
  13223. // mips must be embedded in DDS files
  13224. this.generateMipmaps = false;
  13225. };
  13226. THREE.CompressedTexture.prototype = Object.create( THREE.Texture.prototype );
  13227. THREE.CompressedTexture.prototype.constructor = THREE.CompressedTexture;
  13228. // File:src/textures/DataTexture.js
  13229. /**
  13230. * @author alteredq / http://alteredqualia.com/
  13231. */
  13232. THREE.DataTexture = function ( data, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, encoding ) {
  13233. THREE.Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding );
  13234. this.image = { data: data, width: width, height: height };
  13235. this.magFilter = magFilter !== undefined ? magFilter : THREE.NearestFilter;
  13236. this.minFilter = minFilter !== undefined ? minFilter : THREE.NearestFilter;
  13237. this.flipY = false;
  13238. this.generateMipmaps = false;
  13239. };
  13240. THREE.DataTexture.prototype = Object.create( THREE.Texture.prototype );
  13241. THREE.DataTexture.prototype.constructor = THREE.DataTexture;
  13242. // File:src/textures/VideoTexture.js
  13243. /**
  13244. * @author mrdoob / http://mrdoob.com/
  13245. */
  13246. THREE.VideoTexture = function ( video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  13247. THREE.Texture.call( this, video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  13248. this.generateMipmaps = false;
  13249. var scope = this;
  13250. function update() {
  13251. requestAnimationFrame( update );
  13252. if ( video.readyState >= video.HAVE_CURRENT_DATA ) {
  13253. scope.needsUpdate = true;
  13254. }
  13255. }
  13256. update();
  13257. };
  13258. THREE.VideoTexture.prototype = Object.create( THREE.Texture.prototype );
  13259. THREE.VideoTexture.prototype.constructor = THREE.VideoTexture;
  13260. // File:src/objects/Group.js
  13261. /**
  13262. * @author mrdoob / http://mrdoob.com/
  13263. */
  13264. THREE.Group = function () {
  13265. THREE.Object3D.call( this );
  13266. this.type = 'Group';
  13267. };
  13268. THREE.Group.prototype = Object.assign( Object.create( THREE.Object3D.prototype ), {
  13269. constructor: THREE.Group
  13270. } );
  13271. // File:src/objects/Points.js
  13272. /**
  13273. * @author alteredq / http://alteredqualia.com/
  13274. */
  13275. THREE.Points = function ( geometry, material ) {
  13276. THREE.Object3D.call( this );
  13277. this.type = 'Points';
  13278. this.geometry = geometry !== undefined ? geometry : new THREE.BufferGeometry();
  13279. this.material = material !== undefined ? material : new THREE.PointsMaterial( { color: Math.random() * 0xffffff } );
  13280. };
  13281. THREE.Points.prototype = Object.assign( Object.create( THREE.Object3D.prototype ), {
  13282. constructor: THREE.Points,
  13283. raycast: ( function () {
  13284. var inverseMatrix = new THREE.Matrix4();
  13285. var ray = new THREE.Ray();
  13286. var sphere = new THREE.Sphere();
  13287. return function raycast( raycaster, intersects ) {
  13288. var object = this;
  13289. var geometry = this.geometry;
  13290. var matrixWorld = this.matrixWorld;
  13291. var threshold = raycaster.params.Points.threshold;
  13292. // Checking boundingSphere distance to ray
  13293. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  13294. sphere.copy( geometry.boundingSphere );
  13295. sphere.applyMatrix4( matrixWorld );
  13296. if ( raycaster.ray.intersectsSphere( sphere ) === false ) return;
  13297. //
  13298. inverseMatrix.getInverse( matrixWorld );
  13299. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  13300. var localThreshold = threshold / ( ( this.scale.x + this.scale.y + this.scale.z ) / 3 );
  13301. var localThresholdSq = localThreshold * localThreshold;
  13302. var position = new THREE.Vector3();
  13303. function testPoint( point, index ) {
  13304. var rayPointDistanceSq = ray.distanceSqToPoint( point );
  13305. if ( rayPointDistanceSq < localThresholdSq ) {
  13306. var intersectPoint = ray.closestPointToPoint( point );
  13307. intersectPoint.applyMatrix4( matrixWorld );
  13308. var distance = raycaster.ray.origin.distanceTo( intersectPoint );
  13309. if ( distance < raycaster.near || distance > raycaster.far ) return;
  13310. intersects.push( {
  13311. distance: distance,
  13312. distanceToRay: Math.sqrt( rayPointDistanceSq ),
  13313. point: intersectPoint.clone(),
  13314. index: index,
  13315. face: null,
  13316. object: object
  13317. } );
  13318. }
  13319. }
  13320. if ( geometry instanceof THREE.BufferGeometry ) {
  13321. var index = geometry.index;
  13322. var attributes = geometry.attributes;
  13323. var positions = attributes.position.array;
  13324. if ( index !== null ) {
  13325. var indices = index.array;
  13326. for ( var i = 0, il = indices.length; i < il; i ++ ) {
  13327. var a = indices[ i ];
  13328. position.fromArray( positions, a * 3 );
  13329. testPoint( position, a );
  13330. }
  13331. } else {
  13332. for ( var i = 0, l = positions.length / 3; i < l; i ++ ) {
  13333. position.fromArray( positions, i * 3 );
  13334. testPoint( position, i );
  13335. }
  13336. }
  13337. } else {
  13338. var vertices = geometry.vertices;
  13339. for ( var i = 0, l = vertices.length; i < l; i ++ ) {
  13340. testPoint( vertices[ i ], i );
  13341. }
  13342. }
  13343. };
  13344. }() ),
  13345. clone: function () {
  13346. return new this.constructor( this.geometry, this.material ).copy( this );
  13347. }
  13348. } );
  13349. // File:src/objects/Line.js
  13350. /**
  13351. * @author mrdoob / http://mrdoob.com/
  13352. */
  13353. THREE.Line = function ( geometry, material, mode ) {
  13354. if ( mode === 1 ) {
  13355. console.warn( 'THREE.Line: parameter THREE.LinePieces no longer supported. Created THREE.LineSegments instead.' );
  13356. return new THREE.LineSegments( geometry, material );
  13357. }
  13358. THREE.Object3D.call( this );
  13359. this.type = 'Line';
  13360. this.geometry = geometry !== undefined ? geometry : new THREE.BufferGeometry();
  13361. this.material = material !== undefined ? material : new THREE.LineBasicMaterial( { color: Math.random() * 0xffffff } );
  13362. };
  13363. THREE.Line.prototype = Object.assign( Object.create( THREE.Object3D.prototype ), {
  13364. constructor: THREE.Line,
  13365. raycast: ( function () {
  13366. var inverseMatrix = new THREE.Matrix4();
  13367. var ray = new THREE.Ray();
  13368. var sphere = new THREE.Sphere();
  13369. return function raycast( raycaster, intersects ) {
  13370. var precision = raycaster.linePrecision;
  13371. var precisionSq = precision * precision;
  13372. var geometry = this.geometry;
  13373. var matrixWorld = this.matrixWorld;
  13374. // Checking boundingSphere distance to ray
  13375. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  13376. sphere.copy( geometry.boundingSphere );
  13377. sphere.applyMatrix4( matrixWorld );
  13378. if ( raycaster.ray.intersectsSphere( sphere ) === false ) return;
  13379. //
  13380. inverseMatrix.getInverse( matrixWorld );
  13381. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  13382. var vStart = new THREE.Vector3();
  13383. var vEnd = new THREE.Vector3();
  13384. var interSegment = new THREE.Vector3();
  13385. var interRay = new THREE.Vector3();
  13386. var step = this instanceof THREE.LineSegments ? 2 : 1;
  13387. if ( geometry instanceof THREE.BufferGeometry ) {
  13388. var index = geometry.index;
  13389. var attributes = geometry.attributes;
  13390. var positions = attributes.position.array;
  13391. if ( index !== null ) {
  13392. var indices = index.array;
  13393. for ( var i = 0, l = indices.length - 1; i < l; i += step ) {
  13394. var a = indices[ i ];
  13395. var b = indices[ i + 1 ];
  13396. vStart.fromArray( positions, a * 3 );
  13397. vEnd.fromArray( positions, b * 3 );
  13398. var distSq = ray.distanceSqToSegment( vStart, vEnd, interRay, interSegment );
  13399. if ( distSq > precisionSq ) continue;
  13400. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  13401. var distance = raycaster.ray.origin.distanceTo( interRay );
  13402. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  13403. intersects.push( {
  13404. distance: distance,
  13405. // What do we want? intersection point on the ray or on the segment??
  13406. // point: raycaster.ray.at( distance ),
  13407. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  13408. index: i,
  13409. face: null,
  13410. faceIndex: null,
  13411. object: this
  13412. } );
  13413. }
  13414. } else {
  13415. for ( var i = 0, l = positions.length / 3 - 1; i < l; i += step ) {
  13416. vStart.fromArray( positions, 3 * i );
  13417. vEnd.fromArray( positions, 3 * i + 3 );
  13418. var distSq = ray.distanceSqToSegment( vStart, vEnd, interRay, interSegment );
  13419. if ( distSq > precisionSq ) continue;
  13420. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  13421. var distance = raycaster.ray.origin.distanceTo( interRay );
  13422. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  13423. intersects.push( {
  13424. distance: distance,
  13425. // What do we want? intersection point on the ray or on the segment??
  13426. // point: raycaster.ray.at( distance ),
  13427. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  13428. index: i,
  13429. face: null,
  13430. faceIndex: null,
  13431. object: this
  13432. } );
  13433. }
  13434. }
  13435. } else if ( geometry instanceof THREE.Geometry ) {
  13436. var vertices = geometry.vertices;
  13437. var nbVertices = vertices.length;
  13438. for ( var i = 0; i < nbVertices - 1; i += step ) {
  13439. var distSq = ray.distanceSqToSegment( vertices[ i ], vertices[ i + 1 ], interRay, interSegment );
  13440. if ( distSq > precisionSq ) continue;
  13441. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  13442. var distance = raycaster.ray.origin.distanceTo( interRay );
  13443. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  13444. intersects.push( {
  13445. distance: distance,
  13446. // What do we want? intersection point on the ray or on the segment??
  13447. // point: raycaster.ray.at( distance ),
  13448. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  13449. index: i,
  13450. face: null,
  13451. faceIndex: null,
  13452. object: this
  13453. } );
  13454. }
  13455. }
  13456. };
  13457. }() ),
  13458. clone: function () {
  13459. return new this.constructor( this.geometry, this.material ).copy( this );
  13460. }
  13461. } );
  13462. // File:src/objects/LineSegments.js
  13463. /**
  13464. * @author mrdoob / http://mrdoob.com/
  13465. */
  13466. THREE.LineSegments = function ( geometry, material ) {
  13467. THREE.Line.call( this, geometry, material );
  13468. this.type = 'LineSegments';
  13469. };
  13470. THREE.LineSegments.prototype = Object.assign( Object.create( THREE.Line.prototype ), {
  13471. constructor: THREE.LineSegments
  13472. } );
  13473. // File:src/objects/Mesh.js
  13474. /**
  13475. * @author mrdoob / http://mrdoob.com/
  13476. * @author alteredq / http://alteredqualia.com/
  13477. * @author mikael emtinger / http://gomo.se/
  13478. * @author jonobr1 / http://jonobr1.com/
  13479. */
  13480. THREE.Mesh = function ( geometry, material ) {
  13481. THREE.Object3D.call( this );
  13482. this.type = 'Mesh';
  13483. this.geometry = geometry !== undefined ? geometry : new THREE.BufferGeometry();
  13484. this.material = material !== undefined ? material : new THREE.MeshBasicMaterial( { color: Math.random() * 0xffffff } );
  13485. this.drawMode = THREE.TrianglesDrawMode;
  13486. this.updateMorphTargets();
  13487. };
  13488. THREE.Mesh.prototype = Object.assign( Object.create( THREE.Object3D.prototype ), {
  13489. constructor: THREE.Mesh,
  13490. setDrawMode: function ( value ) {
  13491. this.drawMode = value;
  13492. },
  13493. copy: function ( source ) {
  13494. THREE.Object3D.prototype.copy.call( this, source );
  13495. this.drawMode = source.drawMode;
  13496. return this;
  13497. },
  13498. updateMorphTargets: function () {
  13499. if ( this.geometry.morphTargets !== undefined && this.geometry.morphTargets.length > 0 ) {
  13500. this.morphTargetBase = - 1;
  13501. this.morphTargetInfluences = [];
  13502. this.morphTargetDictionary = {};
  13503. for ( var m = 0, ml = this.geometry.morphTargets.length; m < ml; m ++ ) {
  13504. this.morphTargetInfluences.push( 0 );
  13505. this.morphTargetDictionary[ this.geometry.morphTargets[ m ].name ] = m;
  13506. }
  13507. }
  13508. },
  13509. getMorphTargetIndexByName: function ( name ) {
  13510. if ( this.morphTargetDictionary[ name ] !== undefined ) {
  13511. return this.morphTargetDictionary[ name ];
  13512. }
  13513. console.warn( 'THREE.Mesh.getMorphTargetIndexByName: morph target ' + name + ' does not exist. Returning 0.' );
  13514. return 0;
  13515. },
  13516. raycast: ( function () {
  13517. var inverseMatrix = new THREE.Matrix4();
  13518. var ray = new THREE.Ray();
  13519. var sphere = new THREE.Sphere();
  13520. var vA = new THREE.Vector3();
  13521. var vB = new THREE.Vector3();
  13522. var vC = new THREE.Vector3();
  13523. var tempA = new THREE.Vector3();
  13524. var tempB = new THREE.Vector3();
  13525. var tempC = new THREE.Vector3();
  13526. var uvA = new THREE.Vector2();
  13527. var uvB = new THREE.Vector2();
  13528. var uvC = new THREE.Vector2();
  13529. var barycoord = new THREE.Vector3();
  13530. var intersectionPoint = new THREE.Vector3();
  13531. var intersectionPointWorld = new THREE.Vector3();
  13532. function uvIntersection( point, p1, p2, p3, uv1, uv2, uv3 ) {
  13533. THREE.Triangle.barycoordFromPoint( point, p1, p2, p3, barycoord );
  13534. uv1.multiplyScalar( barycoord.x );
  13535. uv2.multiplyScalar( barycoord.y );
  13536. uv3.multiplyScalar( barycoord.z );
  13537. uv1.add( uv2 ).add( uv3 );
  13538. return uv1.clone();
  13539. }
  13540. function checkIntersection( object, raycaster, ray, pA, pB, pC, point ) {
  13541. var intersect;
  13542. var material = object.material;
  13543. if ( material.side === THREE.BackSide ) {
  13544. intersect = ray.intersectTriangle( pC, pB, pA, true, point );
  13545. } else {
  13546. intersect = ray.intersectTriangle( pA, pB, pC, material.side !== THREE.DoubleSide, point );
  13547. }
  13548. if ( intersect === null ) return null;
  13549. intersectionPointWorld.copy( point );
  13550. intersectionPointWorld.applyMatrix4( object.matrixWorld );
  13551. var distance = raycaster.ray.origin.distanceTo( intersectionPointWorld );
  13552. if ( distance < raycaster.near || distance > raycaster.far ) return null;
  13553. return {
  13554. distance: distance,
  13555. point: intersectionPointWorld.clone(),
  13556. object: object
  13557. };
  13558. }
  13559. function checkBufferGeometryIntersection( object, raycaster, ray, positions, uvs, a, b, c ) {
  13560. vA.fromArray( positions, a * 3 );
  13561. vB.fromArray( positions, b * 3 );
  13562. vC.fromArray( positions, c * 3 );
  13563. var intersection = checkIntersection( object, raycaster, ray, vA, vB, vC, intersectionPoint );
  13564. if ( intersection ) {
  13565. if ( uvs ) {
  13566. uvA.fromArray( uvs, a * 2 );
  13567. uvB.fromArray( uvs, b * 2 );
  13568. uvC.fromArray( uvs, c * 2 );
  13569. intersection.uv = uvIntersection( intersectionPoint, vA, vB, vC, uvA, uvB, uvC );
  13570. }
  13571. intersection.face = new THREE.Face3( a, b, c, THREE.Triangle.normal( vA, vB, vC ) );
  13572. intersection.faceIndex = a;
  13573. }
  13574. return intersection;
  13575. }
  13576. return function raycast( raycaster, intersects ) {
  13577. var geometry = this.geometry;
  13578. var material = this.material;
  13579. var matrixWorld = this.matrixWorld;
  13580. if ( material === undefined ) return;
  13581. // Checking boundingSphere distance to ray
  13582. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  13583. sphere.copy( geometry.boundingSphere );
  13584. sphere.applyMatrix4( matrixWorld );
  13585. if ( raycaster.ray.intersectsSphere( sphere ) === false ) return;
  13586. //
  13587. inverseMatrix.getInverse( matrixWorld );
  13588. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  13589. // Check boundingBox before continuing
  13590. if ( geometry.boundingBox !== null ) {
  13591. if ( ray.intersectsBox( geometry.boundingBox ) === false ) return;
  13592. }
  13593. var uvs, intersection;
  13594. if ( geometry instanceof THREE.BufferGeometry ) {
  13595. var a, b, c;
  13596. var index = geometry.index;
  13597. var attributes = geometry.attributes;
  13598. var positions = attributes.position.array;
  13599. if ( attributes.uv !== undefined ) {
  13600. uvs = attributes.uv.array;
  13601. }
  13602. if ( index !== null ) {
  13603. var indices = index.array;
  13604. for ( var i = 0, l = indices.length; i < l; i += 3 ) {
  13605. a = indices[ i ];
  13606. b = indices[ i + 1 ];
  13607. c = indices[ i + 2 ];
  13608. intersection = checkBufferGeometryIntersection( this, raycaster, ray, positions, uvs, a, b, c );
  13609. if ( intersection ) {
  13610. intersection.faceIndex = Math.floor( i / 3 ); // triangle number in indices buffer semantics
  13611. intersects.push( intersection );
  13612. }
  13613. }
  13614. } else {
  13615. for ( var i = 0, l = positions.length; i < l; i += 9 ) {
  13616. a = i / 3;
  13617. b = a + 1;
  13618. c = a + 2;
  13619. intersection = checkBufferGeometryIntersection( this, raycaster, ray, positions, uvs, a, b, c );
  13620. if ( intersection ) {
  13621. intersection.index = a; // triangle number in positions buffer semantics
  13622. intersects.push( intersection );
  13623. }
  13624. }
  13625. }
  13626. } else if ( geometry instanceof THREE.Geometry ) {
  13627. var fvA, fvB, fvC;
  13628. var isFaceMaterial = material instanceof THREE.MultiMaterial;
  13629. var materials = isFaceMaterial === true ? material.materials : null;
  13630. var vertices = geometry.vertices;
  13631. var faces = geometry.faces;
  13632. var faceVertexUvs = geometry.faceVertexUvs[ 0 ];
  13633. if ( faceVertexUvs.length > 0 ) uvs = faceVertexUvs;
  13634. for ( var f = 0, fl = faces.length; f < fl; f ++ ) {
  13635. var face = faces[ f ];
  13636. var faceMaterial = isFaceMaterial === true ? materials[ face.materialIndex ] : material;
  13637. if ( faceMaterial === undefined ) continue;
  13638. fvA = vertices[ face.a ];
  13639. fvB = vertices[ face.b ];
  13640. fvC = vertices[ face.c ];
  13641. if ( faceMaterial.morphTargets === true ) {
  13642. var morphTargets = geometry.morphTargets;
  13643. var morphInfluences = this.morphTargetInfluences;
  13644. vA.set( 0, 0, 0 );
  13645. vB.set( 0, 0, 0 );
  13646. vC.set( 0, 0, 0 );
  13647. for ( var t = 0, tl = morphTargets.length; t < tl; t ++ ) {
  13648. var influence = morphInfluences[ t ];
  13649. if ( influence === 0 ) continue;
  13650. var targets = morphTargets[ t ].vertices;
  13651. vA.addScaledVector( tempA.subVectors( targets[ face.a ], fvA ), influence );
  13652. vB.addScaledVector( tempB.subVectors( targets[ face.b ], fvB ), influence );
  13653. vC.addScaledVector( tempC.subVectors( targets[ face.c ], fvC ), influence );
  13654. }
  13655. vA.add( fvA );
  13656. vB.add( fvB );
  13657. vC.add( fvC );
  13658. fvA = vA;
  13659. fvB = vB;
  13660. fvC = vC;
  13661. }
  13662. intersection = checkIntersection( this, raycaster, ray, fvA, fvB, fvC, intersectionPoint );
  13663. if ( intersection ) {
  13664. if ( uvs ) {
  13665. var uvs_f = uvs[ f ];
  13666. uvA.copy( uvs_f[ 0 ] );
  13667. uvB.copy( uvs_f[ 1 ] );
  13668. uvC.copy( uvs_f[ 2 ] );
  13669. intersection.uv = uvIntersection( intersectionPoint, fvA, fvB, fvC, uvA, uvB, uvC );
  13670. }
  13671. intersection.face = face;
  13672. intersection.faceIndex = f;
  13673. intersects.push( intersection );
  13674. }
  13675. }
  13676. }
  13677. };
  13678. }() ),
  13679. clone: function () {
  13680. return new this.constructor( this.geometry, this.material ).copy( this );
  13681. }
  13682. } );
  13683. // File:src/objects/Bone.js
  13684. /**
  13685. * @author mikael emtinger / http://gomo.se/
  13686. * @author alteredq / http://alteredqualia.com/
  13687. * @author ikerr / http://verold.com
  13688. */
  13689. THREE.Bone = function ( skin ) {
  13690. THREE.Object3D.call( this );
  13691. this.type = 'Bone';
  13692. this.skin = skin;
  13693. };
  13694. THREE.Bone.prototype = Object.assign( Object.create( THREE.Object3D.prototype ), {
  13695. constructor: THREE.Bone,
  13696. copy: function ( source ) {
  13697. THREE.Object3D.prototype.copy.call( this, source );
  13698. this.skin = source.skin;
  13699. return this;
  13700. }
  13701. } );
  13702. // File:src/objects/Skeleton.js
  13703. /**
  13704. * @author mikael emtinger / http://gomo.se/
  13705. * @author alteredq / http://alteredqualia.com/
  13706. * @author michael guerrero / http://realitymeltdown.com
  13707. * @author ikerr / http://verold.com
  13708. */
  13709. THREE.Skeleton = function ( bones, boneInverses, useVertexTexture ) {
  13710. this.useVertexTexture = useVertexTexture !== undefined ? useVertexTexture : true;
  13711. this.identityMatrix = new THREE.Matrix4();
  13712. // copy the bone array
  13713. bones = bones || [];
  13714. this.bones = bones.slice( 0 );
  13715. // create a bone texture or an array of floats
  13716. if ( this.useVertexTexture ) {
  13717. // layout (1 matrix = 4 pixels)
  13718. // RGBA RGBA RGBA RGBA (=> column1, column2, column3, column4)
  13719. // with 8x8 pixel texture max 16 bones * 4 pixels = (8 * 8)
  13720. // 16x16 pixel texture max 64 bones * 4 pixels = (16 * 16)
  13721. // 32x32 pixel texture max 256 bones * 4 pixels = (32 * 32)
  13722. // 64x64 pixel texture max 1024 bones * 4 pixels = (64 * 64)
  13723. var size = Math.sqrt( this.bones.length * 4 ); // 4 pixels needed for 1 matrix
  13724. size = THREE.Math.nextPowerOfTwo( Math.ceil( size ) );
  13725. size = Math.max( size, 4 );
  13726. this.boneTextureWidth = size;
  13727. this.boneTextureHeight = size;
  13728. this.boneMatrices = new Float32Array( this.boneTextureWidth * this.boneTextureHeight * 4 ); // 4 floats per RGBA pixel
  13729. this.boneTexture = new THREE.DataTexture( this.boneMatrices, this.boneTextureWidth, this.boneTextureHeight, THREE.RGBAFormat, THREE.FloatType );
  13730. } else {
  13731. this.boneMatrices = new Float32Array( 16 * this.bones.length );
  13732. }
  13733. // use the supplied bone inverses or calculate the inverses
  13734. if ( boneInverses === undefined ) {
  13735. this.calculateInverses();
  13736. } else {
  13737. if ( this.bones.length === boneInverses.length ) {
  13738. this.boneInverses = boneInverses.slice( 0 );
  13739. } else {
  13740. console.warn( 'THREE.Skeleton bonInverses is the wrong length.' );
  13741. this.boneInverses = [];
  13742. for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
  13743. this.boneInverses.push( new THREE.Matrix4() );
  13744. }
  13745. }
  13746. }
  13747. };
  13748. Object.assign( THREE.Skeleton.prototype, {
  13749. calculateInverses: function () {
  13750. this.boneInverses = [];
  13751. for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
  13752. var inverse = new THREE.Matrix4();
  13753. if ( this.bones[ b ] ) {
  13754. inverse.getInverse( this.bones[ b ].matrixWorld );
  13755. }
  13756. this.boneInverses.push( inverse );
  13757. }
  13758. },
  13759. pose: function () {
  13760. var bone;
  13761. // recover the bind-time world matrices
  13762. for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
  13763. bone = this.bones[ b ];
  13764. if ( bone ) {
  13765. bone.matrixWorld.getInverse( this.boneInverses[ b ] );
  13766. }
  13767. }
  13768. // compute the local matrices, positions, rotations and scales
  13769. for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
  13770. bone = this.bones[ b ];
  13771. if ( bone ) {
  13772. if ( bone.parent instanceof THREE.Bone ) {
  13773. bone.matrix.getInverse( bone.parent.matrixWorld );
  13774. bone.matrix.multiply( bone.matrixWorld );
  13775. } else {
  13776. bone.matrix.copy( bone.matrixWorld );
  13777. }
  13778. bone.matrix.decompose( bone.position, bone.quaternion, bone.scale );
  13779. }
  13780. }
  13781. },
  13782. update: ( function () {
  13783. var offsetMatrix = new THREE.Matrix4();
  13784. return function update() {
  13785. // flatten bone matrices to array
  13786. for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
  13787. // compute the offset between the current and the original transform
  13788. var matrix = this.bones[ b ] ? this.bones[ b ].matrixWorld : this.identityMatrix;
  13789. offsetMatrix.multiplyMatrices( matrix, this.boneInverses[ b ] );
  13790. offsetMatrix.toArray( this.boneMatrices, b * 16 );
  13791. }
  13792. if ( this.useVertexTexture ) {
  13793. this.boneTexture.needsUpdate = true;
  13794. }
  13795. };
  13796. } )(),
  13797. clone: function () {
  13798. return new THREE.Skeleton( this.bones, this.boneInverses, this.useVertexTexture );
  13799. }
  13800. } );
  13801. // File:src/objects/SkinnedMesh.js
  13802. /**
  13803. * @author mikael emtinger / http://gomo.se/
  13804. * @author alteredq / http://alteredqualia.com/
  13805. * @author ikerr / http://verold.com
  13806. */
  13807. THREE.SkinnedMesh = function ( geometry, material, useVertexTexture ) {
  13808. THREE.Mesh.call( this, geometry, material );
  13809. this.type = 'SkinnedMesh';
  13810. this.bindMode = "attached";
  13811. this.bindMatrix = new THREE.Matrix4();
  13812. this.bindMatrixInverse = new THREE.Matrix4();
  13813. // init bones
  13814. // TODO: remove bone creation as there is no reason (other than
  13815. // convenience) for THREE.SkinnedMesh to do this.
  13816. var bones = [];
  13817. if ( this.geometry && this.geometry.bones !== undefined ) {
  13818. var bone, gbone;
  13819. for ( var b = 0, bl = this.geometry.bones.length; b < bl; ++ b ) {
  13820. gbone = this.geometry.bones[ b ];
  13821. bone = new THREE.Bone( this );
  13822. bones.push( bone );
  13823. bone.name = gbone.name;
  13824. bone.position.fromArray( gbone.pos );
  13825. bone.quaternion.fromArray( gbone.rotq );
  13826. if ( gbone.scl !== undefined ) bone.scale.fromArray( gbone.scl );
  13827. }
  13828. for ( var b = 0, bl = this.geometry.bones.length; b < bl; ++ b ) {
  13829. gbone = this.geometry.bones[ b ];
  13830. if ( gbone.parent !== - 1 && gbone.parent !== null &&
  13831. bones[ gbone.parent ] !== undefined ) {
  13832. bones[ gbone.parent ].add( bones[ b ] );
  13833. } else {
  13834. this.add( bones[ b ] );
  13835. }
  13836. }
  13837. }
  13838. this.normalizeSkinWeights();
  13839. this.updateMatrixWorld( true );
  13840. this.bind( new THREE.Skeleton( bones, undefined, useVertexTexture ), this.matrixWorld );
  13841. };
  13842. THREE.SkinnedMesh.prototype = Object.assign( Object.create( THREE.Mesh.prototype ), {
  13843. constructor: THREE.SkinnedMesh,
  13844. bind: function( skeleton, bindMatrix ) {
  13845. this.skeleton = skeleton;
  13846. if ( bindMatrix === undefined ) {
  13847. this.updateMatrixWorld( true );
  13848. this.skeleton.calculateInverses();
  13849. bindMatrix = this.matrixWorld;
  13850. }
  13851. this.bindMatrix.copy( bindMatrix );
  13852. this.bindMatrixInverse.getInverse( bindMatrix );
  13853. },
  13854. pose: function () {
  13855. this.skeleton.pose();
  13856. },
  13857. normalizeSkinWeights: function () {
  13858. if ( this.geometry instanceof THREE.Geometry ) {
  13859. for ( var i = 0; i < this.geometry.skinWeights.length; i ++ ) {
  13860. var sw = this.geometry.skinWeights[ i ];
  13861. var scale = 1.0 / sw.lengthManhattan();
  13862. if ( scale !== Infinity ) {
  13863. sw.multiplyScalar( scale );
  13864. } else {
  13865. sw.set( 1, 0, 0, 0 ); // do something reasonable
  13866. }
  13867. }
  13868. } else if ( this.geometry instanceof THREE.BufferGeometry ) {
  13869. var vec = new THREE.Vector4();
  13870. var skinWeight = this.geometry.attributes.skinWeight;
  13871. for ( var i = 0; i < skinWeight.count; i ++ ) {
  13872. vec.x = skinWeight.getX( i );
  13873. vec.y = skinWeight.getY( i );
  13874. vec.z = skinWeight.getZ( i );
  13875. vec.w = skinWeight.getW( i );
  13876. var scale = 1.0 / vec.lengthManhattan();
  13877. if ( scale !== Infinity ) {
  13878. vec.multiplyScalar( scale );
  13879. } else {
  13880. vec.set( 1, 0, 0, 0 ); // do something reasonable
  13881. }
  13882. skinWeight.setXYZW( i, vec.x, vec.y, vec.z, vec.w );
  13883. }
  13884. }
  13885. },
  13886. updateMatrixWorld: function( force ) {
  13887. THREE.Mesh.prototype.updateMatrixWorld.call( this, true );
  13888. if ( this.bindMode === "attached" ) {
  13889. this.bindMatrixInverse.getInverse( this.matrixWorld );
  13890. } else if ( this.bindMode === "detached" ) {
  13891. this.bindMatrixInverse.getInverse( this.bindMatrix );
  13892. } else {
  13893. console.warn( 'THREE.SkinnedMesh unrecognized bindMode: ' + this.bindMode );
  13894. }
  13895. },
  13896. clone: function() {
  13897. return new this.constructor( this.geometry, this.material, this.skeleton.useVertexTexture ).copy( this );
  13898. }
  13899. } );
  13900. // File:src/objects/LOD.js
  13901. /**
  13902. * @author mikael emtinger / http://gomo.se/
  13903. * @author alteredq / http://alteredqualia.com/
  13904. * @author mrdoob / http://mrdoob.com/
  13905. */
  13906. THREE.LOD = function () {
  13907. THREE.Object3D.call( this );
  13908. this.type = 'LOD';
  13909. Object.defineProperties( this, {
  13910. levels: {
  13911. enumerable: true,
  13912. value: []
  13913. }
  13914. } );
  13915. };
  13916. THREE.LOD.prototype = Object.assign( Object.create( THREE.Object3D.prototype ), {
  13917. constructor: THREE.LOD,
  13918. copy: function ( source ) {
  13919. THREE.Object3D.prototype.copy.call( this, source, false );
  13920. var levels = source.levels;
  13921. for ( var i = 0, l = levels.length; i < l; i ++ ) {
  13922. var level = levels[ i ];
  13923. this.addLevel( level.object.clone(), level.distance );
  13924. }
  13925. return this;
  13926. },
  13927. addLevel: function ( object, distance ) {
  13928. if ( distance === undefined ) distance = 0;
  13929. distance = Math.abs( distance );
  13930. var levels = this.levels;
  13931. for ( var l = 0; l < levels.length; l ++ ) {
  13932. if ( distance < levels[ l ].distance ) {
  13933. break;
  13934. }
  13935. }
  13936. levels.splice( l, 0, { distance: distance, object: object } );
  13937. this.add( object );
  13938. },
  13939. getObjectForDistance: function ( distance ) {
  13940. var levels = this.levels;
  13941. for ( var i = 1, l = levels.length; i < l; i ++ ) {
  13942. if ( distance < levels[ i ].distance ) {
  13943. break;
  13944. }
  13945. }
  13946. return levels[ i - 1 ].object;
  13947. },
  13948. raycast: ( function () {
  13949. var matrixPosition = new THREE.Vector3();
  13950. return function raycast( raycaster, intersects ) {
  13951. matrixPosition.setFromMatrixPosition( this.matrixWorld );
  13952. var distance = raycaster.ray.origin.distanceTo( matrixPosition );
  13953. this.getObjectForDistance( distance ).raycast( raycaster, intersects );
  13954. };
  13955. }() ),
  13956. update: function () {
  13957. var v1 = new THREE.Vector3();
  13958. var v2 = new THREE.Vector3();
  13959. return function update( camera ) {
  13960. var levels = this.levels;
  13961. if ( levels.length > 1 ) {
  13962. v1.setFromMatrixPosition( camera.matrixWorld );
  13963. v2.setFromMatrixPosition( this.matrixWorld );
  13964. var distance = v1.distanceTo( v2 );
  13965. levels[ 0 ].object.visible = true;
  13966. for ( var i = 1, l = levels.length; i < l; i ++ ) {
  13967. if ( distance >= levels[ i ].distance ) {
  13968. levels[ i - 1 ].object.visible = false;
  13969. levels[ i ].object.visible = true;
  13970. } else {
  13971. break;
  13972. }
  13973. }
  13974. for ( ; i < l; i ++ ) {
  13975. levels[ i ].object.visible = false;
  13976. }
  13977. }
  13978. };
  13979. }(),
  13980. toJSON: function ( meta ) {
  13981. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  13982. data.object.levels = [];
  13983. var levels = this.levels;
  13984. for ( var i = 0, l = levels.length; i < l; i ++ ) {
  13985. var level = levels[ i ];
  13986. data.object.levels.push( {
  13987. object: level.object.uuid,
  13988. distance: level.distance
  13989. } );
  13990. }
  13991. return data;
  13992. }
  13993. } );
  13994. // File:src/objects/Sprite.js
  13995. /**
  13996. * @author mikael emtinger / http://gomo.se/
  13997. * @author alteredq / http://alteredqualia.com/
  13998. */
  13999. THREE.Sprite = function ( material ) {
  14000. THREE.Object3D.call( this );
  14001. this.type = 'Sprite';
  14002. this.material = ( material !== undefined ) ? material : new THREE.SpriteMaterial();
  14003. };
  14004. THREE.Sprite.prototype = Object.assign( Object.create( THREE.Object3D.prototype ), {
  14005. constructor: THREE.Sprite,
  14006. raycast: ( function () {
  14007. var matrixPosition = new THREE.Vector3();
  14008. return function raycast( raycaster, intersects ) {
  14009. matrixPosition.setFromMatrixPosition( this.matrixWorld );
  14010. var distanceSq = raycaster.ray.distanceSqToPoint( matrixPosition );
  14011. var guessSizeSq = this.scale.x * this.scale.y / 4;
  14012. if ( distanceSq > guessSizeSq ) {
  14013. return;
  14014. }
  14015. intersects.push( {
  14016. distance: Math.sqrt( distanceSq ),
  14017. point: this.position,
  14018. face: null,
  14019. object: this
  14020. } );
  14021. };
  14022. }() ),
  14023. clone: function () {
  14024. return new this.constructor( this.material ).copy( this );
  14025. }
  14026. } );
  14027. // File:src/objects/LensFlare.js
  14028. /**
  14029. * @author mikael emtinger / http://gomo.se/
  14030. * @author alteredq / http://alteredqualia.com/
  14031. */
  14032. THREE.LensFlare = function ( texture, size, distance, blending, color ) {
  14033. THREE.Object3D.call( this );
  14034. this.lensFlares = [];
  14035. this.positionScreen = new THREE.Vector3();
  14036. this.customUpdateCallback = undefined;
  14037. if ( texture !== undefined ) {
  14038. this.add( texture, size, distance, blending, color );
  14039. }
  14040. };
  14041. THREE.LensFlare.prototype = Object.assign( Object.create( THREE.Object3D.prototype ), {
  14042. constructor: THREE.LensFlare,
  14043. copy: function ( source ) {
  14044. THREE.Object3D.prototype.copy.call( this, source );
  14045. this.positionScreen.copy( source.positionScreen );
  14046. this.customUpdateCallback = source.customUpdateCallback;
  14047. for ( var i = 0, l = source.lensFlares.length; i < l; i ++ ) {
  14048. this.lensFlares.push( source.lensFlares[ i ] );
  14049. }
  14050. return this;
  14051. },
  14052. add: function ( texture, size, distance, blending, color, opacity ) {
  14053. if ( size === undefined ) size = - 1;
  14054. if ( distance === undefined ) distance = 0;
  14055. if ( opacity === undefined ) opacity = 1;
  14056. if ( color === undefined ) color = new THREE.Color( 0xffffff );
  14057. if ( blending === undefined ) blending = THREE.NormalBlending;
  14058. distance = Math.min( distance, Math.max( 0, distance ) );
  14059. this.lensFlares.push( {
  14060. texture: texture, // THREE.Texture
  14061. size: size, // size in pixels (-1 = use texture.width)
  14062. distance: distance, // distance (0-1) from light source (0=at light source)
  14063. x: 0, y: 0, z: 0, // screen position (-1 => 1) z = 0 is in front z = 1 is back
  14064. scale: 1, // scale
  14065. rotation: 0, // rotation
  14066. opacity: opacity, // opacity
  14067. color: color, // color
  14068. blending: blending // blending
  14069. } );
  14070. },
  14071. /*
  14072. * Update lens flares update positions on all flares based on the screen position
  14073. * Set myLensFlare.customUpdateCallback to alter the flares in your project specific way.
  14074. */
  14075. updateLensFlares: function () {
  14076. var f, fl = this.lensFlares.length;
  14077. var flare;
  14078. var vecX = - this.positionScreen.x * 2;
  14079. var vecY = - this.positionScreen.y * 2;
  14080. for ( f = 0; f < fl; f ++ ) {
  14081. flare = this.lensFlares[ f ];
  14082. flare.x = this.positionScreen.x + vecX * flare.distance;
  14083. flare.y = this.positionScreen.y + vecY * flare.distance;
  14084. flare.wantedRotation = flare.x * Math.PI * 0.25;
  14085. flare.rotation += ( flare.wantedRotation - flare.rotation ) * 0.25;
  14086. }
  14087. }
  14088. } );
  14089. // File:src/scenes/Scene.js
  14090. /**
  14091. * @author mrdoob / http://mrdoob.com/
  14092. */
  14093. THREE.Scene = function () {
  14094. THREE.Object3D.call( this );
  14095. this.type = 'Scene';
  14096. this.background = null;
  14097. this.fog = null;
  14098. this.overrideMaterial = null;
  14099. this.autoUpdate = true; // checked by the renderer
  14100. };
  14101. THREE.Scene.prototype = Object.create( THREE.Object3D.prototype );
  14102. THREE.Scene.prototype.constructor = THREE.Scene;
  14103. THREE.Scene.prototype.copy = function ( source, recursive ) {
  14104. THREE.Object3D.prototype.copy.call( this, source, recursive );
  14105. if ( source.background !== null ) this.background = source.background.clone();
  14106. if ( source.fog !== null ) this.fog = source.fog.clone();
  14107. if ( source.overrideMaterial !== null ) this.overrideMaterial = source.overrideMaterial.clone();
  14108. this.autoUpdate = source.autoUpdate;
  14109. this.matrixAutoUpdate = source.matrixAutoUpdate;
  14110. return this;
  14111. };
  14112. // File:src/scenes/Fog.js
  14113. /**
  14114. * @author mrdoob / http://mrdoob.com/
  14115. * @author alteredq / http://alteredqualia.com/
  14116. */
  14117. THREE.Fog = function ( color, near, far ) {
  14118. this.name = '';
  14119. this.color = new THREE.Color( color );
  14120. this.near = ( near !== undefined ) ? near : 1;
  14121. this.far = ( far !== undefined ) ? far : 1000;
  14122. };
  14123. THREE.Fog.prototype.clone = function () {
  14124. return new THREE.Fog( this.color.getHex(), this.near, this.far );
  14125. };
  14126. // File:src/scenes/FogExp2.js
  14127. /**
  14128. * @author mrdoob / http://mrdoob.com/
  14129. * @author alteredq / http://alteredqualia.com/
  14130. */
  14131. THREE.FogExp2 = function ( color, density ) {
  14132. this.name = '';
  14133. this.color = new THREE.Color( color );
  14134. this.density = ( density !== undefined ) ? density : 0.00025;
  14135. };
  14136. THREE.FogExp2.prototype.clone = function () {
  14137. return new THREE.FogExp2( this.color.getHex(), this.density );
  14138. };
  14139. // File:src/renderers/shaders/ShaderChunk.js
  14140. THREE.ShaderChunk = {};
  14141. // File:src/renderers/shaders/ShaderChunk/alphamap_fragment.glsl
  14142. THREE.ShaderChunk[ 'alphamap_fragment' ] = "#ifdef USE_ALPHAMAP\n diffuseColor.a *= texture2D( alphaMap, vUv ).g;\n#endif\n";
  14143. // File:src/renderers/shaders/ShaderChunk/alphamap_pars_fragment.glsl
  14144. THREE.ShaderChunk[ 'alphamap_pars_fragment' ] = "#ifdef USE_ALPHAMAP\n uniform sampler2D alphaMap;\n#endif\n";
  14145. // File:src/renderers/shaders/ShaderChunk/alphatest_fragment.glsl
  14146. THREE.ShaderChunk[ 'alphatest_fragment' ] = "#ifdef ALPHATEST\n if ( diffuseColor.a < ALPHATEST ) discard;\n#endif\n";
  14147. // File:src/renderers/shaders/ShaderChunk/aomap_fragment.glsl
  14148. 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";
  14149. // File:src/renderers/shaders/ShaderChunk/aomap_pars_fragment.glsl
  14150. THREE.ShaderChunk[ 'aomap_pars_fragment' ] = "#ifdef USE_AOMAP\n uniform sampler2D aoMap;\n uniform float aoMapIntensity;\n#endif";
  14151. // File:src/renderers/shaders/ShaderChunk/begin_vertex.glsl
  14152. THREE.ShaderChunk[ 'begin_vertex' ] = "\nvec3 transformed = vec3( position );\n";
  14153. // File:src/renderers/shaders/ShaderChunk/beginnormal_vertex.glsl
  14154. THREE.ShaderChunk[ 'beginnormal_vertex' ] = "\nvec3 objectNormal = vec3( normal );\n";
  14155. // File:src/renderers/shaders/ShaderChunk/bsdfs.glsl
  14156. 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";
  14157. // File:src/renderers/shaders/ShaderChunk/bumpmap_pars_fragment.glsl
  14158. 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";
  14159. // File:src/renderers/shaders/ShaderChunk/clipping_planes_fragment.glsl
  14160. 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";
  14161. // File:src/renderers/shaders/ShaderChunk/clipping_planes_pars_fragment.glsl
  14162. 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";
  14163. // File:src/renderers/shaders/ShaderChunk/clipping_planes_pars_vertex.glsl
  14164. THREE.ShaderChunk[ 'clipping_planes_pars_vertex' ] = "#if NUM_CLIPPING_PLANES > 0 && ! defined( PHYSICAL ) && ! defined( PHONG )\n varying vec3 vViewPosition;\n#endif\n";
  14165. // File:src/renderers/shaders/ShaderChunk/clipping_planes_vertex.glsl
  14166. THREE.ShaderChunk[ 'clipping_planes_vertex' ] = "#if NUM_CLIPPING_PLANES > 0 && ! defined( PHYSICAL ) && ! defined( PHONG )\n vViewPosition = - mvPosition.xyz;\n#endif\n";
  14167. // File:src/renderers/shaders/ShaderChunk/color_fragment.glsl
  14168. THREE.ShaderChunk[ 'color_fragment' ] = "#ifdef USE_COLOR\n diffuseColor.rgb *= vColor;\n#endif";
  14169. // File:src/renderers/shaders/ShaderChunk/color_pars_fragment.glsl
  14170. THREE.ShaderChunk[ 'color_pars_fragment' ] = "#ifdef USE_COLOR\n varying vec3 vColor;\n#endif\n";
  14171. // File:src/renderers/shaders/ShaderChunk/color_pars_vertex.glsl
  14172. THREE.ShaderChunk[ 'color_pars_vertex' ] = "#ifdef USE_COLOR\n varying vec3 vColor;\n#endif";
  14173. // File:src/renderers/shaders/ShaderChunk/color_vertex.glsl
  14174. THREE.ShaderChunk[ 'color_vertex' ] = "#ifdef USE_COLOR\n vColor.xyz = color.xyz;\n#endif";
  14175. // File:src/renderers/shaders/ShaderChunk/common.glsl
  14176. 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";
  14177. // File:src/renderers/shaders/ShaderChunk/cube_uv_reflection_fragment.glsl
  14178. 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";
  14179. // File:src/renderers/shaders/ShaderChunk/defaultnormal_vertex.glsl
  14180. THREE.ShaderChunk[ 'defaultnormal_vertex' ] = "#ifdef FLIP_SIDED\n objectNormal = -objectNormal;\n#endif\nvec3 transformedNormal = normalMatrix * objectNormal;\n";
  14181. // File:src/renderers/shaders/ShaderChunk/displacementmap_vertex.glsl
  14182. THREE.ShaderChunk[ 'displacementmap_vertex' ] = "#ifdef USE_DISPLACEMENTMAP\n transformed += normal * ( texture2D( displacementMap, uv ).x * displacementScale + displacementBias );\n#endif\n";
  14183. // File:src/renderers/shaders/ShaderChunk/displacementmap_pars_vertex.glsl
  14184. THREE.ShaderChunk[ 'displacementmap_pars_vertex' ] = "#ifdef USE_DISPLACEMENTMAP\n uniform sampler2D displacementMap;\n uniform float displacementScale;\n uniform float displacementBias;\n#endif\n";
  14185. // File:src/renderers/shaders/ShaderChunk/emissivemap_fragment.glsl
  14186. 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";
  14187. // File:src/renderers/shaders/ShaderChunk/emissivemap_pars_fragment.glsl
  14188. THREE.ShaderChunk[ 'emissivemap_pars_fragment' ] = "#ifdef USE_EMISSIVEMAP\n uniform sampler2D emissiveMap;\n#endif\n";
  14189. // File:src/renderers/shaders/ShaderChunk/encodings_pars_fragment.glsl
  14190. 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";
  14191. // File:src/renderers/shaders/ShaderChunk/encodings_fragment.glsl
  14192. THREE.ShaderChunk[ 'encodings_fragment' ] = " gl_FragColor = linearToOutputTexel( gl_FragColor );\n";
  14193. // File:src/renderers/shaders/ShaderChunk/envmap_fragment.glsl
  14194. 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";
  14195. // File:src/renderers/shaders/ShaderChunk/envmap_pars_fragment.glsl
  14196. 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";
  14197. // File:src/renderers/shaders/ShaderChunk/envmap_pars_vertex.glsl
  14198. 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";
  14199. // File:src/renderers/shaders/ShaderChunk/envmap_vertex.glsl
  14200. 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";
  14201. // File:src/renderers/shaders/ShaderChunk/fog_fragment.glsl
  14202. 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";
  14203. // File:src/renderers/shaders/ShaderChunk/fog_pars_fragment.glsl
  14204. 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";
  14205. // File:src/renderers/shaders/ShaderChunk/lightmap_fragment.glsl
  14206. THREE.ShaderChunk[ 'lightmap_fragment' ] = "#ifdef USE_LIGHTMAP\n reflectedLight.indirectDiffuse += PI * texture2D( lightMap, vUv2 ).xyz * lightMapIntensity;\n#endif\n";
  14207. // File:src/renderers/shaders/ShaderChunk/lightmap_pars_fragment.glsl
  14208. THREE.ShaderChunk[ 'lightmap_pars_fragment' ] = "#ifdef USE_LIGHTMAP\n uniform sampler2D lightMap;\n uniform float lightMapIntensity;\n#endif";
  14209. // File:src/renderers/shaders/ShaderChunk/lights_lambert_vertex.glsl
  14210. 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";
  14211. // File:src/renderers/shaders/ShaderChunk/lights_pars.glsl
  14212. 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";
  14213. // File:src/renderers/shaders/ShaderChunk/lights_phong_fragment.glsl
  14214. THREE.ShaderChunk[ 'lights_phong_fragment' ] = "BlinnPhongMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;\nmaterial.specularColor = specular;\nmaterial.specularShininess = shininess;\nmaterial.specularStrength = specularStrength;\n";
  14215. // File:src/renderers/shaders/ShaderChunk/lights_phong_pars_fragment.glsl
  14216. 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";
  14217. // File:src/renderers/shaders/ShaderChunk/lights_physical_fragment.glsl
  14218. 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";
  14219. // File:src/renderers/shaders/ShaderChunk/lights_physical_pars_fragment.glsl
  14220. 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";
  14221. // File:src/renderers/shaders/ShaderChunk/lights_template.glsl
  14222. 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";
  14223. // File:src/renderers/shaders/ShaderChunk/logdepthbuf_fragment.glsl
  14224. THREE.ShaderChunk[ 'logdepthbuf_fragment' ] = "#if defined(USE_LOGDEPTHBUF) && defined(USE_LOGDEPTHBUF_EXT)\n gl_FragDepthEXT = log2(vFragDepth) * logDepthBufFC * 0.5;\n#endif";
  14225. // File:src/renderers/shaders/ShaderChunk/logdepthbuf_pars_fragment.glsl
  14226. 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";
  14227. // File:src/renderers/shaders/ShaderChunk/logdepthbuf_pars_vertex.glsl
  14228. 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";
  14229. // File:src/renderers/shaders/ShaderChunk/logdepthbuf_vertex.glsl
  14230. 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";
  14231. // File:src/renderers/shaders/ShaderChunk/map_fragment.glsl
  14232. THREE.ShaderChunk[ 'map_fragment' ] = "#ifdef USE_MAP\n vec4 texelColor = texture2D( map, vUv );\n texelColor = mapTexelToLinear( texelColor );\n diffuseColor *= texelColor;\n#endif\n";
  14233. // File:src/renderers/shaders/ShaderChunk/map_pars_fragment.glsl
  14234. THREE.ShaderChunk[ 'map_pars_fragment' ] = "#ifdef USE_MAP\n uniform sampler2D map;\n#endif\n";
  14235. // File:src/renderers/shaders/ShaderChunk/map_particle_fragment.glsl
  14236. 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";
  14237. // File:src/renderers/shaders/ShaderChunk/map_particle_pars_fragment.glsl
  14238. THREE.ShaderChunk[ 'map_particle_pars_fragment' ] = "#ifdef USE_MAP\n uniform vec4 offsetRepeat;\n uniform sampler2D map;\n#endif\n";
  14239. // File:src/renderers/shaders/ShaderChunk/metalnessmap_fragment.glsl
  14240. THREE.ShaderChunk[ 'metalnessmap_fragment' ] = "float metalnessFactor = metalness;\n#ifdef USE_METALNESSMAP\n vec4 texelMetalness = texture2D( metalnessMap, vUv );\n metalnessFactor *= texelMetalness.r;\n#endif\n";
  14241. // File:src/renderers/shaders/ShaderChunk/metalnessmap_pars_fragment.glsl
  14242. THREE.ShaderChunk[ 'metalnessmap_pars_fragment' ] = "#ifdef USE_METALNESSMAP\n uniform sampler2D metalnessMap;\n#endif";
  14243. // File:src/renderers/shaders/ShaderChunk/morphnormal_vertex.glsl
  14244. 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";
  14245. // File:src/renderers/shaders/ShaderChunk/morphtarget_pars_vertex.glsl
  14246. 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";
  14247. // File:src/renderers/shaders/ShaderChunk/morphtarget_vertex.glsl
  14248. 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";
  14249. // File:src/renderers/shaders/ShaderChunk/normal_flip.glsl
  14250. 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";
  14251. // File:src/renderers/shaders/ShaderChunk/normal_fragment.glsl
  14252. 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";
  14253. // File:src/renderers/shaders/ShaderChunk/normalmap_pars_fragment.glsl
  14254. 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";
  14255. // File:src/renderers/shaders/ShaderChunk/packing.glsl
  14256. 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";
  14257. // File:src/renderers/shaders/ShaderChunk/premultiplied_alpha_fragment.glsl
  14258. THREE.ShaderChunk[ 'premultiplied_alpha_fragment' ] = "#ifdef PREMULTIPLIED_ALPHA\n gl_FragColor.rgb *= gl_FragColor.a;\n#endif\n";
  14259. // File:src/renderers/shaders/ShaderChunk/project_vertex.glsl
  14260. 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";
  14261. // File:src/renderers/shaders/ShaderChunk/roughnessmap_fragment.glsl
  14262. THREE.ShaderChunk[ 'roughnessmap_fragment' ] = "float roughnessFactor = roughness;\n#ifdef USE_ROUGHNESSMAP\n vec4 texelRoughness = texture2D( roughnessMap, vUv );\n roughnessFactor *= texelRoughness.r;\n#endif\n";
  14263. // File:src/renderers/shaders/ShaderChunk/roughnessmap_pars_fragment.glsl
  14264. THREE.ShaderChunk[ 'roughnessmap_pars_fragment' ] = "#ifdef USE_ROUGHNESSMAP\n uniform sampler2D roughnessMap;\n#endif";
  14265. // File:src/renderers/shaders/ShaderChunk/shadowmap_pars_fragment.glsl
  14266. 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";
  14267. // File:src/renderers/shaders/ShaderChunk/shadowmap_pars_vertex.glsl
  14268. 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";
  14269. // File:src/renderers/shaders/ShaderChunk/shadowmap_vertex.glsl
  14270. 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";
  14271. // File:src/renderers/shaders/ShaderChunk/shadowmask_pars_fragment.glsl
  14272. 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";
  14273. // File:src/renderers/shaders/ShaderChunk/skinbase_vertex.glsl
  14274. 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";
  14275. // File:src/renderers/shaders/ShaderChunk/skinning_pars_vertex.glsl
  14276. 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";
  14277. // File:src/renderers/shaders/ShaderChunk/skinning_vertex.glsl
  14278. 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";
  14279. // File:src/renderers/shaders/ShaderChunk/skinnormal_vertex.glsl
  14280. 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";
  14281. // File:src/renderers/shaders/ShaderChunk/specularmap_fragment.glsl
  14282. 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";
  14283. // File:src/renderers/shaders/ShaderChunk/specularmap_pars_fragment.glsl
  14284. THREE.ShaderChunk[ 'specularmap_pars_fragment' ] = "#ifdef USE_SPECULARMAP\n uniform sampler2D specularMap;\n#endif";
  14285. // File:src/renderers/shaders/ShaderChunk/tonemapping_fragment.glsl
  14286. THREE.ShaderChunk[ 'tonemapping_fragment' ] = "#if defined( TONE_MAPPING )\n gl_FragColor.rgb = toneMapping( gl_FragColor.rgb );\n#endif\n";
  14287. // File:src/renderers/shaders/ShaderChunk/tonemapping_pars_fragment.glsl
  14288. 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";
  14289. // File:src/renderers/shaders/ShaderChunk/uv2_pars_fragment.glsl
  14290. THREE.ShaderChunk[ 'uv2_pars_fragment' ] = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n varying vec2 vUv2;\n#endif";
  14291. // File:src/renderers/shaders/ShaderChunk/uv2_pars_vertex.glsl
  14292. THREE.ShaderChunk[ 'uv2_pars_vertex' ] = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n attribute vec2 uv2;\n varying vec2 vUv2;\n#endif";
  14293. // File:src/renderers/shaders/ShaderChunk/uv2_vertex.glsl
  14294. THREE.ShaderChunk[ 'uv2_vertex' ] = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n vUv2 = uv2;\n#endif";
  14295. // File:src/renderers/shaders/ShaderChunk/uv_pars_fragment.glsl
  14296. 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";
  14297. // File:src/renderers/shaders/ShaderChunk/uv_pars_vertex.glsl
  14298. 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";
  14299. // File:src/renderers/shaders/ShaderChunk/uv_vertex.glsl
  14300. 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";
  14301. // File:src/renderers/shaders/ShaderChunk/worldpos_vertex.glsl
  14302. 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";
  14303. // File:src/renderers/shaders/UniformsUtils.js
  14304. /**
  14305. * Uniform Utilities
  14306. */
  14307. THREE.UniformsUtils = {
  14308. merge: function ( uniforms ) {
  14309. var merged = {};
  14310. for ( var u = 0; u < uniforms.length; u ++ ) {
  14311. var tmp = this.clone( uniforms[ u ] );
  14312. for ( var p in tmp ) {
  14313. merged[ p ] = tmp[ p ];
  14314. }
  14315. }
  14316. return merged;
  14317. },
  14318. clone: function ( uniforms_src ) {
  14319. var uniforms_dst = {};
  14320. for ( var u in uniforms_src ) {
  14321. uniforms_dst[ u ] = {};
  14322. for ( var p in uniforms_src[ u ] ) {
  14323. var parameter_src = uniforms_src[ u ][ p ];
  14324. if ( parameter_src instanceof THREE.Color ||
  14325. parameter_src instanceof THREE.Vector2 ||
  14326. parameter_src instanceof THREE.Vector3 ||
  14327. parameter_src instanceof THREE.Vector4 ||
  14328. parameter_src instanceof THREE.Matrix3 ||
  14329. parameter_src instanceof THREE.Matrix4 ||
  14330. parameter_src instanceof THREE.Texture ) {
  14331. uniforms_dst[ u ][ p ] = parameter_src.clone();
  14332. } else if ( Array.isArray( parameter_src ) ) {
  14333. uniforms_dst[ u ][ p ] = parameter_src.slice();
  14334. } else {
  14335. uniforms_dst[ u ][ p ] = parameter_src;
  14336. }
  14337. }
  14338. }
  14339. return uniforms_dst;
  14340. }
  14341. };
  14342. // File:src/renderers/shaders/UniformsLib.js
  14343. /**
  14344. * Uniforms library for shared webgl shaders
  14345. */
  14346. THREE.UniformsLib = {
  14347. common: {
  14348. "diffuse": { value: new THREE.Color( 0xeeeeee ) },
  14349. "opacity": { value: 1.0 },
  14350. "map": { value: null },
  14351. "offsetRepeat": { value: new THREE.Vector4( 0, 0, 1, 1 ) },
  14352. "specularMap": { value: null },
  14353. "alphaMap": { value: null },
  14354. "envMap": { value: null },
  14355. "flipEnvMap": { value: - 1 },
  14356. "reflectivity": { value: 1.0 },
  14357. "refractionRatio": { value: 0.98 }
  14358. },
  14359. aomap: {
  14360. "aoMap": { value: null },
  14361. "aoMapIntensity": { value: 1 }
  14362. },
  14363. lightmap: {
  14364. "lightMap": { value: null },
  14365. "lightMapIntensity": { value: 1 }
  14366. },
  14367. emissivemap: {
  14368. "emissiveMap": { value: null }
  14369. },
  14370. bumpmap: {
  14371. "bumpMap": { value: null },
  14372. "bumpScale": { value: 1 }
  14373. },
  14374. normalmap: {
  14375. "normalMap": { value: null },
  14376. "normalScale": { value: new THREE.Vector2( 1, 1 ) }
  14377. },
  14378. displacementmap: {
  14379. "displacementMap": { value: null },
  14380. "displacementScale": { value: 1 },
  14381. "displacementBias": { value: 0 }
  14382. },
  14383. roughnessmap: {
  14384. "roughnessMap": { value: null }
  14385. },
  14386. metalnessmap: {
  14387. "metalnessMap": { value: null }
  14388. },
  14389. fog: {
  14390. "fogDensity": { value: 0.00025 },
  14391. "fogNear": { value: 1 },
  14392. "fogFar": { value: 2000 },
  14393. "fogColor": { value: new THREE.Color( 0xffffff ) }
  14394. },
  14395. lights: {
  14396. "ambientLightColor": { value: [] },
  14397. "directionalLights": { value: [], properties: {
  14398. "direction": {},
  14399. "color": {},
  14400. "shadow": {},
  14401. "shadowBias": {},
  14402. "shadowRadius": {},
  14403. "shadowMapSize": {}
  14404. } },
  14405. "directionalShadowMap": { value: [] },
  14406. "directionalShadowMatrix": { value: [] },
  14407. "spotLights": { value: [], properties: {
  14408. "color": {},
  14409. "position": {},
  14410. "direction": {},
  14411. "distance": {},
  14412. "coneCos": {},
  14413. "penumbraCos": {},
  14414. "decay": {},
  14415. "shadow": {},
  14416. "shadowBias": {},
  14417. "shadowRadius": {},
  14418. "shadowMapSize": {}
  14419. } },
  14420. "spotShadowMap": { value: [] },
  14421. "spotShadowMatrix": { value: [] },
  14422. "pointLights": { value: [], properties: {
  14423. "color": {},
  14424. "position": {},
  14425. "decay": {},
  14426. "distance": {},
  14427. "shadow": {},
  14428. "shadowBias": {},
  14429. "shadowRadius": {},
  14430. "shadowMapSize": {}
  14431. } },
  14432. "pointShadowMap": { value: [] },
  14433. "pointShadowMatrix": { value: [] },
  14434. "hemisphereLights": { value: [], properties: {
  14435. "direction": {},
  14436. "skyColor": {},
  14437. "groundColor": {}
  14438. } }
  14439. },
  14440. points: {
  14441. "diffuse": { value: new THREE.Color( 0xeeeeee ) },
  14442. "opacity": { value: 1.0 },
  14443. "size": { value: 1.0 },
  14444. "scale": { value: 1.0 },
  14445. "map": { value: null },
  14446. "offsetRepeat": { value: new THREE.Vector4( 0, 0, 1, 1 ) }
  14447. }
  14448. };
  14449. // File:src/renderers/shaders/ShaderLib/cube_frag.glsl
  14450. THREE.ShaderChunk[ 'cube_frag' ] = "uniform samplerCube tCube;\nuniform float tFlip;\nvarying vec3 vWorldPosition;\n#include <common>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n #include <clipping_planes_fragment>\n gl_FragColor = textureCube( tCube, vec3( tFlip * vWorldPosition.x, vWorldPosition.yz ) );\n #include <logdepthbuf_fragment>\n}\n";
  14451. // File:src/renderers/shaders/ShaderLib/cube_vert.glsl
  14452. 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";
  14453. // File:src/renderers/shaders/ShaderLib/depth_frag.glsl
  14454. 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";
  14455. // File:src/renderers/shaders/ShaderLib/depth_vert.glsl
  14456. 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";
  14457. // File:src/renderers/shaders/ShaderLib/distanceRGBA_frag.glsl
  14458. 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";
  14459. // File:src/renderers/shaders/ShaderLib/distanceRGBA_vert.glsl
  14460. 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";
  14461. // File:src/renderers/shaders/ShaderLib/equirect_frag.glsl
  14462. 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";
  14463. // File:src/renderers/shaders/ShaderLib/equirect_vert.glsl
  14464. 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";
  14465. // File:src/renderers/shaders/ShaderLib/linedashed_frag.glsl
  14466. 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";
  14467. // File:src/renderers/shaders/ShaderLib/linedashed_vert.glsl
  14468. 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";
  14469. // File:src/renderers/shaders/ShaderLib/meshbasic_frag.glsl
  14470. 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";
  14471. // File:src/renderers/shaders/ShaderLib/meshbasic_vert.glsl
  14472. 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";
  14473. // File:src/renderers/shaders/ShaderLib/meshlambert_frag.glsl
  14474. 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";
  14475. // File:src/renderers/shaders/ShaderLib/meshlambert_vert.glsl
  14476. 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";
  14477. // File:src/renderers/shaders/ShaderLib/meshphong_frag.glsl
  14478. 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";
  14479. // File:src/renderers/shaders/ShaderLib/meshphong_vert.glsl
  14480. 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";
  14481. // File:src/renderers/shaders/ShaderLib/meshphysical_frag.glsl
  14482. 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";
  14483. // File:src/renderers/shaders/ShaderLib/meshphysical_vert.glsl
  14484. 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";
  14485. // File:src/renderers/shaders/ShaderLib/normal_frag.glsl
  14486. 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";
  14487. // File:src/renderers/shaders/ShaderLib/normal_vert.glsl
  14488. 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";
  14489. // File:src/renderers/shaders/ShaderLib/points_frag.glsl
  14490. 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";
  14491. // File:src/renderers/shaders/ShaderLib/points_vert.glsl
  14492. 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";
  14493. // File:src/renderers/shaders/ShaderLib/shadow_frag.glsl
  14494. 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";
  14495. // File:src/renderers/shaders/ShaderLib/shadow_vert.glsl
  14496. 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";
  14497. // File:src/renderers/shaders/ShaderLib.js
  14498. /**
  14499. * Webgl Shader Library for three.js
  14500. *
  14501. * @author alteredq / http://alteredqualia.com/
  14502. * @author mrdoob / http://mrdoob.com/
  14503. * @author mikael emtinger / http://gomo.se/
  14504. */
  14505. THREE.ShaderLib = {
  14506. 'basic': {
  14507. uniforms: THREE.UniformsUtils.merge( [
  14508. THREE.UniformsLib[ 'common' ],
  14509. THREE.UniformsLib[ 'aomap' ],
  14510. THREE.UniformsLib[ 'fog' ]
  14511. ] ),
  14512. vertexShader: THREE.ShaderChunk[ 'meshbasic_vert' ],
  14513. fragmentShader: THREE.ShaderChunk[ 'meshbasic_frag' ]
  14514. },
  14515. 'lambert': {
  14516. uniforms: THREE.UniformsUtils.merge( [
  14517. THREE.UniformsLib[ 'common' ],
  14518. THREE.UniformsLib[ 'aomap' ],
  14519. THREE.UniformsLib[ 'lightmap' ],
  14520. THREE.UniformsLib[ 'emissivemap' ],
  14521. THREE.UniformsLib[ 'fog' ],
  14522. THREE.UniformsLib[ 'lights' ],
  14523. {
  14524. "emissive" : { value: new THREE.Color( 0x000000 ) }
  14525. }
  14526. ] ),
  14527. vertexShader: THREE.ShaderChunk[ 'meshlambert_vert' ],
  14528. fragmentShader: THREE.ShaderChunk[ 'meshlambert_frag' ]
  14529. },
  14530. 'phong': {
  14531. uniforms: THREE.UniformsUtils.merge( [
  14532. THREE.UniformsLib[ 'common' ],
  14533. THREE.UniformsLib[ 'aomap' ],
  14534. THREE.UniformsLib[ 'lightmap' ],
  14535. THREE.UniformsLib[ 'emissivemap' ],
  14536. THREE.UniformsLib[ 'bumpmap' ],
  14537. THREE.UniformsLib[ 'normalmap' ],
  14538. THREE.UniformsLib[ 'displacementmap' ],
  14539. THREE.UniformsLib[ 'fog' ],
  14540. THREE.UniformsLib[ 'lights' ],
  14541. {
  14542. "emissive" : { value: new THREE.Color( 0x000000 ) },
  14543. "specular" : { value: new THREE.Color( 0x111111 ) },
  14544. "shininess": { value: 30 }
  14545. }
  14546. ] ),
  14547. vertexShader: THREE.ShaderChunk[ 'meshphong_vert' ],
  14548. fragmentShader: THREE.ShaderChunk[ 'meshphong_frag' ]
  14549. },
  14550. 'standard': {
  14551. uniforms: THREE.UniformsUtils.merge( [
  14552. THREE.UniformsLib[ 'common' ],
  14553. THREE.UniformsLib[ 'aomap' ],
  14554. THREE.UniformsLib[ 'lightmap' ],
  14555. THREE.UniformsLib[ 'emissivemap' ],
  14556. THREE.UniformsLib[ 'bumpmap' ],
  14557. THREE.UniformsLib[ 'normalmap' ],
  14558. THREE.UniformsLib[ 'displacementmap' ],
  14559. THREE.UniformsLib[ 'roughnessmap' ],
  14560. THREE.UniformsLib[ 'metalnessmap' ],
  14561. THREE.UniformsLib[ 'fog' ],
  14562. THREE.UniformsLib[ 'lights' ],
  14563. {
  14564. "emissive" : { value: new THREE.Color( 0x000000 ) },
  14565. "roughness": { value: 0.5 },
  14566. "metalness": { value: 0 },
  14567. "envMapIntensity" : { value: 1 }, // temporary
  14568. }
  14569. ] ),
  14570. vertexShader: THREE.ShaderChunk[ 'meshphysical_vert' ],
  14571. fragmentShader: THREE.ShaderChunk[ 'meshphysical_frag' ]
  14572. },
  14573. 'points': {
  14574. uniforms: THREE.UniformsUtils.merge( [
  14575. THREE.UniformsLib[ 'points' ],
  14576. THREE.UniformsLib[ 'fog' ]
  14577. ] ),
  14578. vertexShader: THREE.ShaderChunk[ 'points_vert' ],
  14579. fragmentShader: THREE.ShaderChunk[ 'points_frag' ]
  14580. },
  14581. 'dashed': {
  14582. uniforms: THREE.UniformsUtils.merge( [
  14583. THREE.UniformsLib[ 'common' ],
  14584. THREE.UniformsLib[ 'fog' ],
  14585. {
  14586. "scale" : { value: 1 },
  14587. "dashSize" : { value: 1 },
  14588. "totalSize": { value: 2 }
  14589. }
  14590. ] ),
  14591. vertexShader: THREE.ShaderChunk[ 'linedashed_vert' ],
  14592. fragmentShader: THREE.ShaderChunk[ 'linedashed_frag' ]
  14593. },
  14594. 'depth': {
  14595. uniforms: THREE.UniformsUtils.merge( [
  14596. THREE.UniformsLib[ 'common' ],
  14597. THREE.UniformsLib[ 'displacementmap' ]
  14598. ] ),
  14599. vertexShader: THREE.ShaderChunk[ 'depth_vert' ],
  14600. fragmentShader: THREE.ShaderChunk[ 'depth_frag' ]
  14601. },
  14602. 'normal': {
  14603. uniforms: {
  14604. "opacity" : { value: 1.0 }
  14605. },
  14606. vertexShader: THREE.ShaderChunk[ 'normal_vert' ],
  14607. fragmentShader: THREE.ShaderChunk[ 'normal_frag' ]
  14608. },
  14609. /* -------------------------------------------------------------------------
  14610. // Cube map shader
  14611. ------------------------------------------------------------------------- */
  14612. 'cube': {
  14613. uniforms: {
  14614. "tCube": { value: null },
  14615. "tFlip": { value: - 1 }
  14616. },
  14617. vertexShader: THREE.ShaderChunk[ 'cube_vert' ],
  14618. fragmentShader: THREE.ShaderChunk[ 'cube_frag' ]
  14619. },
  14620. /* -------------------------------------------------------------------------
  14621. // Cube map shader
  14622. ------------------------------------------------------------------------- */
  14623. 'equirect': {
  14624. uniforms: {
  14625. "tEquirect": { value: null },
  14626. "tFlip": { value: - 1 }
  14627. },
  14628. vertexShader: THREE.ShaderChunk[ 'equirect_vert' ],
  14629. fragmentShader: THREE.ShaderChunk[ 'equirect_frag' ]
  14630. },
  14631. 'distanceRGBA': {
  14632. uniforms: {
  14633. "lightPos": { value: new THREE.Vector3() }
  14634. },
  14635. vertexShader: THREE.ShaderChunk[ 'distanceRGBA_vert' ],
  14636. fragmentShader: THREE.ShaderChunk[ 'distanceRGBA_frag' ]
  14637. }
  14638. };
  14639. THREE.ShaderLib[ 'physical' ] = {
  14640. uniforms: THREE.UniformsUtils.merge( [
  14641. THREE.ShaderLib[ 'standard' ].uniforms,
  14642. {
  14643. "clearCoat": { value: 0 },
  14644. "clearCoatRoughness": { value: 0 }
  14645. }
  14646. ] ),
  14647. vertexShader: THREE.ShaderChunk[ 'meshphysical_vert' ],
  14648. fragmentShader: THREE.ShaderChunk[ 'meshphysical_frag' ]
  14649. };
  14650. // File:src/renderers/WebGLRenderer.js
  14651. /**
  14652. * @author supereggbert / http://www.paulbrunt.co.uk/
  14653. * @author mrdoob / http://mrdoob.com/
  14654. * @author alteredq / http://alteredqualia.com/
  14655. * @author szimek / https://github.com/szimek/
  14656. * @author tschw
  14657. */
  14658. THREE.WebGLRenderer = function ( parameters ) {
  14659. console.log( 'THREE.WebGLRenderer', THREE.REVISION );
  14660. parameters = parameters || {};
  14661. var _canvas = parameters.canvas !== undefined ? parameters.canvas : document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' ),
  14662. _context = parameters.context !== undefined ? parameters.context : null,
  14663. _alpha = parameters.alpha !== undefined ? parameters.alpha : false,
  14664. _depth = parameters.depth !== undefined ? parameters.depth : true,
  14665. _stencil = parameters.stencil !== undefined ? parameters.stencil : true,
  14666. _antialias = parameters.antialias !== undefined ? parameters.antialias : false,
  14667. _premultipliedAlpha = parameters.premultipliedAlpha !== undefined ? parameters.premultipliedAlpha : true,
  14668. _preserveDrawingBuffer = parameters.preserveDrawingBuffer !== undefined ? parameters.preserveDrawingBuffer : false;
  14669. var lights = [];
  14670. var opaqueObjects = [];
  14671. var opaqueObjectsLastIndex = - 1;
  14672. var transparentObjects = [];
  14673. var transparentObjectsLastIndex = - 1;
  14674. var morphInfluences = new Float32Array( 8 );
  14675. var sprites = [];
  14676. var lensFlares = [];
  14677. // public properties
  14678. this.domElement = _canvas;
  14679. this.context = null;
  14680. // clearing
  14681. this.autoClear = true;
  14682. this.autoClearColor = true;
  14683. this.autoClearDepth = true;
  14684. this.autoClearStencil = true;
  14685. // scene graph
  14686. this.sortObjects = true;
  14687. // user-defined clipping
  14688. this.clippingPlanes = [];
  14689. this.localClippingEnabled = false;
  14690. // physically based shading
  14691. this.gammaFactor = 2.0; // for backwards compatibility
  14692. this.gammaInput = false;
  14693. this.gammaOutput = false;
  14694. // physical lights
  14695. this.physicallyCorrectLights = false;
  14696. // tone mapping
  14697. this.toneMapping = THREE.LinearToneMapping;
  14698. this.toneMappingExposure = 1.0;
  14699. this.toneMappingWhitePoint = 1.0;
  14700. // morphs
  14701. this.maxMorphTargets = 8;
  14702. this.maxMorphNormals = 4;
  14703. // internal properties
  14704. var _this = this,
  14705. // internal state cache
  14706. _currentProgram = null,
  14707. _currentRenderTarget = null,
  14708. _currentFramebuffer = null,
  14709. _currentMaterialId = - 1,
  14710. _currentGeometryProgram = '',
  14711. _currentCamera = null,
  14712. _currentScissor = new THREE.Vector4(),
  14713. _currentScissorTest = null,
  14714. _currentViewport = new THREE.Vector4(),
  14715. //
  14716. _usedTextureUnits = 0,
  14717. //
  14718. _clearColor = new THREE.Color( 0x000000 ),
  14719. _clearAlpha = 0,
  14720. _width = _canvas.width,
  14721. _height = _canvas.height,
  14722. _pixelRatio = 1,
  14723. _scissor = new THREE.Vector4( 0, 0, _width, _height ),
  14724. _scissorTest = false,
  14725. _viewport = new THREE.Vector4( 0, 0, _width, _height ),
  14726. // frustum
  14727. _frustum = new THREE.Frustum(),
  14728. // clipping
  14729. _clipping = new THREE.WebGLClipping(),
  14730. _clippingEnabled = false,
  14731. _localClippingEnabled = false,
  14732. _sphere = new THREE.Sphere(),
  14733. // camera matrices cache
  14734. _projScreenMatrix = new THREE.Matrix4(),
  14735. _vector3 = new THREE.Vector3(),
  14736. // light arrays cache
  14737. _lights = {
  14738. hash: '',
  14739. ambient: [ 0, 0, 0 ],
  14740. directional: [],
  14741. directionalShadowMap: [],
  14742. directionalShadowMatrix: [],
  14743. spot: [],
  14744. spotShadowMap: [],
  14745. spotShadowMatrix: [],
  14746. point: [],
  14747. pointShadowMap: [],
  14748. pointShadowMatrix: [],
  14749. hemi: [],
  14750. shadows: []
  14751. },
  14752. // info
  14753. _infoRender = {
  14754. calls: 0,
  14755. vertices: 0,
  14756. faces: 0,
  14757. points: 0
  14758. };
  14759. this.info = {
  14760. render: _infoRender,
  14761. memory: {
  14762. geometries: 0,
  14763. textures: 0
  14764. },
  14765. programs: null
  14766. };
  14767. // initialize
  14768. var _gl;
  14769. try {
  14770. var attributes = {
  14771. alpha: _alpha,
  14772. depth: _depth,
  14773. stencil: _stencil,
  14774. antialias: _antialias,
  14775. premultipliedAlpha: _premultipliedAlpha,
  14776. preserveDrawingBuffer: _preserveDrawingBuffer
  14777. };
  14778. _gl = _context || _canvas.getContext( 'webgl', attributes ) || _canvas.getContext( 'experimental-webgl', attributes );
  14779. if ( _gl === null ) {
  14780. if ( _canvas.getContext( 'webgl' ) !== null ) {
  14781. throw 'Error creating WebGL context with your selected attributes.';
  14782. } else {
  14783. throw 'Error creating WebGL context.';
  14784. }
  14785. }
  14786. // Some experimental-webgl implementations do not have getShaderPrecisionFormat
  14787. if ( _gl.getShaderPrecisionFormat === undefined ) {
  14788. _gl.getShaderPrecisionFormat = function () {
  14789. return { 'rangeMin': 1, 'rangeMax': 1, 'precision': 1 };
  14790. };
  14791. }
  14792. _canvas.addEventListener( 'webglcontextlost', onContextLost, false );
  14793. } catch ( error ) {
  14794. console.error( 'THREE.WebGLRenderer: ' + error );
  14795. }
  14796. var extensions = new THREE.WebGLExtensions( _gl );
  14797. extensions.get( 'WEBGL_depth_texture' );
  14798. extensions.get( 'OES_texture_float' );
  14799. extensions.get( 'OES_texture_float_linear' );
  14800. extensions.get( 'OES_texture_half_float' );
  14801. extensions.get( 'OES_texture_half_float_linear' );
  14802. extensions.get( 'OES_standard_derivatives' );
  14803. extensions.get( 'ANGLE_instanced_arrays' );
  14804. if ( extensions.get( 'OES_element_index_uint' ) ) {
  14805. THREE.BufferGeometry.MaxIndex = 4294967296;
  14806. }
  14807. var capabilities = new THREE.WebGLCapabilities( _gl, extensions, parameters );
  14808. var state = new THREE.WebGLState( _gl, extensions, paramThreeToGL );
  14809. var properties = new THREE.WebGLProperties();
  14810. var textures = new THREE.WebGLTextures( _gl, extensions, state, properties, capabilities, paramThreeToGL, this.info );
  14811. var objects = new THREE.WebGLObjects( _gl, properties, this.info );
  14812. var programCache = new THREE.WebGLPrograms( this, capabilities );
  14813. var lightCache = new THREE.WebGLLights();
  14814. this.info.programs = programCache.programs;
  14815. var bufferRenderer = new THREE.WebGLBufferRenderer( _gl, extensions, _infoRender );
  14816. var indexedBufferRenderer = new THREE.WebGLIndexedBufferRenderer( _gl, extensions, _infoRender );
  14817. //
  14818. var backgroundCamera = new THREE.OrthographicCamera( - 1, 1, 1, - 1, 0, 1 );
  14819. var backgroundCamera2 = new THREE.PerspectiveCamera();
  14820. var backgroundPlaneMesh = new THREE.Mesh(
  14821. new THREE.PlaneBufferGeometry( 2, 2 ),
  14822. new THREE.MeshBasicMaterial( { depthTest: false, depthWrite: false } )
  14823. );
  14824. var backgroundBoxShader = THREE.ShaderLib[ 'cube' ];
  14825. var backgroundBoxMesh = new THREE.Mesh(
  14826. new THREE.BoxBufferGeometry( 5, 5, 5 ),
  14827. new THREE.ShaderMaterial( {
  14828. uniforms: backgroundBoxShader.uniforms,
  14829. vertexShader: backgroundBoxShader.vertexShader,
  14830. fragmentShader: backgroundBoxShader.fragmentShader,
  14831. depthTest: false,
  14832. depthWrite: false,
  14833. side: THREE.BackSide
  14834. } )
  14835. );
  14836. objects.update( backgroundPlaneMesh );
  14837. objects.update( backgroundBoxMesh );
  14838. //
  14839. function getTargetPixelRatio() {
  14840. return _currentRenderTarget === null ? _pixelRatio : 1;
  14841. }
  14842. function glClearColor( r, g, b, a ) {
  14843. if ( _premultipliedAlpha === true ) {
  14844. r *= a; g *= a; b *= a;
  14845. }
  14846. state.clearColor( r, g, b, a );
  14847. }
  14848. function setDefaultGLState() {
  14849. state.init();
  14850. state.scissor( _currentScissor.copy( _scissor ).multiplyScalar( _pixelRatio ) );
  14851. state.viewport( _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio ) );
  14852. glClearColor( _clearColor.r, _clearColor.g, _clearColor.b, _clearAlpha );
  14853. }
  14854. function resetGLState() {
  14855. _currentProgram = null;
  14856. _currentCamera = null;
  14857. _currentGeometryProgram = '';
  14858. _currentMaterialId = - 1;
  14859. state.reset();
  14860. }
  14861. setDefaultGLState();
  14862. this.context = _gl;
  14863. this.capabilities = capabilities;
  14864. this.extensions = extensions;
  14865. this.properties = properties;
  14866. this.state = state;
  14867. // shadow map
  14868. var shadowMap = new THREE.WebGLShadowMap( this, _lights, objects );
  14869. this.shadowMap = shadowMap;
  14870. // Plugins
  14871. var spritePlugin = new THREE.SpritePlugin( this, sprites );
  14872. var lensFlarePlugin = new THREE.LensFlarePlugin( this, lensFlares );
  14873. // API
  14874. this.getContext = function () {
  14875. return _gl;
  14876. };
  14877. this.getContextAttributes = function () {
  14878. return _gl.getContextAttributes();
  14879. };
  14880. this.forceContextLoss = function () {
  14881. extensions.get( 'WEBGL_lose_context' ).loseContext();
  14882. };
  14883. this.getMaxAnisotropy = function () {
  14884. return capabilities.getMaxAnisotropy();
  14885. };
  14886. this.getPrecision = function () {
  14887. return capabilities.precision;
  14888. };
  14889. this.getPixelRatio = function () {
  14890. return _pixelRatio;
  14891. };
  14892. this.setPixelRatio = function ( value ) {
  14893. if ( value === undefined ) return;
  14894. _pixelRatio = value;
  14895. this.setSize( _viewport.z, _viewport.w, false );
  14896. };
  14897. this.getSize = function () {
  14898. return {
  14899. width: _width,
  14900. height: _height
  14901. };
  14902. };
  14903. this.setSize = function ( width, height, updateStyle ) {
  14904. _width = width;
  14905. _height = height;
  14906. _canvas.width = width * _pixelRatio;
  14907. _canvas.height = height * _pixelRatio;
  14908. if ( updateStyle !== false ) {
  14909. _canvas.style.width = width + 'px';
  14910. _canvas.style.height = height + 'px';
  14911. }
  14912. this.setViewport( 0, 0, width, height );
  14913. };
  14914. this.setViewport = function ( x, y, width, height ) {
  14915. state.viewport( _viewport.set( x, y, width, height ) );
  14916. };
  14917. this.setScissor = function ( x, y, width, height ) {
  14918. state.scissor( _scissor.set( x, y, width, height ) );
  14919. };
  14920. this.setScissorTest = function ( boolean ) {
  14921. state.setScissorTest( _scissorTest = boolean );
  14922. };
  14923. // Clearing
  14924. this.getClearColor = function () {
  14925. return _clearColor;
  14926. };
  14927. this.setClearColor = function ( color, alpha ) {
  14928. _clearColor.set( color );
  14929. _clearAlpha = alpha !== undefined ? alpha : 1;
  14930. glClearColor( _clearColor.r, _clearColor.g, _clearColor.b, _clearAlpha );
  14931. };
  14932. this.getClearAlpha = function () {
  14933. return _clearAlpha;
  14934. };
  14935. this.setClearAlpha = function ( alpha ) {
  14936. _clearAlpha = alpha;
  14937. glClearColor( _clearColor.r, _clearColor.g, _clearColor.b, _clearAlpha );
  14938. };
  14939. this.clear = function ( color, depth, stencil ) {
  14940. var bits = 0;
  14941. if ( color === undefined || color ) bits |= _gl.COLOR_BUFFER_BIT;
  14942. if ( depth === undefined || depth ) bits |= _gl.DEPTH_BUFFER_BIT;
  14943. if ( stencil === undefined || stencil ) bits |= _gl.STENCIL_BUFFER_BIT;
  14944. _gl.clear( bits );
  14945. };
  14946. this.clearColor = function () {
  14947. this.clear( true, false, false );
  14948. };
  14949. this.clearDepth = function () {
  14950. this.clear( false, true, false );
  14951. };
  14952. this.clearStencil = function () {
  14953. this.clear( false, false, true );
  14954. };
  14955. this.clearTarget = function ( renderTarget, color, depth, stencil ) {
  14956. this.setRenderTarget( renderTarget );
  14957. this.clear( color, depth, stencil );
  14958. };
  14959. // Reset
  14960. this.resetGLState = resetGLState;
  14961. this.dispose = function() {
  14962. transparentObjects = [];
  14963. transparentObjectsLastIndex = -1;
  14964. opaqueObjects = [];
  14965. opaqueObjectsLastIndex = -1;
  14966. _canvas.removeEventListener( 'webglcontextlost', onContextLost, false );
  14967. };
  14968. // Events
  14969. function onContextLost( event ) {
  14970. event.preventDefault();
  14971. resetGLState();
  14972. setDefaultGLState();
  14973. properties.clear();
  14974. }
  14975. function onMaterialDispose( event ) {
  14976. var material = event.target;
  14977. material.removeEventListener( 'dispose', onMaterialDispose );
  14978. deallocateMaterial( material );
  14979. }
  14980. // Buffer deallocation
  14981. function deallocateMaterial( material ) {
  14982. releaseMaterialProgramReference( material );
  14983. properties.delete( material );
  14984. }
  14985. function releaseMaterialProgramReference( material ) {
  14986. var programInfo = properties.get( material ).program;
  14987. material.program = undefined;
  14988. if ( programInfo !== undefined ) {
  14989. programCache.releaseProgram( programInfo );
  14990. }
  14991. }
  14992. // Buffer rendering
  14993. this.renderBufferImmediate = function ( object, program, material ) {
  14994. state.initAttributes();
  14995. var buffers = properties.get( object );
  14996. if ( object.hasPositions && ! buffers.position ) buffers.position = _gl.createBuffer();
  14997. if ( object.hasNormals && ! buffers.normal ) buffers.normal = _gl.createBuffer();
  14998. if ( object.hasUvs && ! buffers.uv ) buffers.uv = _gl.createBuffer();
  14999. if ( object.hasColors && ! buffers.color ) buffers.color = _gl.createBuffer();
  15000. var attributes = program.getAttributes();
  15001. if ( object.hasPositions ) {
  15002. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffers.position );
  15003. _gl.bufferData( _gl.ARRAY_BUFFER, object.positionArray, _gl.DYNAMIC_DRAW );
  15004. state.enableAttribute( attributes.position );
  15005. _gl.vertexAttribPointer( attributes.position, 3, _gl.FLOAT, false, 0, 0 );
  15006. }
  15007. if ( object.hasNormals ) {
  15008. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffers.normal );
  15009. if ( material.type !== 'MeshPhongMaterial' && material.type !== 'MeshStandardMaterial' && material.type !== 'MeshPhysicalMaterial' && material.shading === THREE.FlatShading ) {
  15010. for ( var i = 0, l = object.count * 3; i < l; i += 9 ) {
  15011. var array = object.normalArray;
  15012. var nx = ( array[ i + 0 ] + array[ i + 3 ] + array[ i + 6 ] ) / 3;
  15013. var ny = ( array[ i + 1 ] + array[ i + 4 ] + array[ i + 7 ] ) / 3;
  15014. var nz = ( array[ i + 2 ] + array[ i + 5 ] + array[ i + 8 ] ) / 3;
  15015. array[ i + 0 ] = nx;
  15016. array[ i + 1 ] = ny;
  15017. array[ i + 2 ] = nz;
  15018. array[ i + 3 ] = nx;
  15019. array[ i + 4 ] = ny;
  15020. array[ i + 5 ] = nz;
  15021. array[ i + 6 ] = nx;
  15022. array[ i + 7 ] = ny;
  15023. array[ i + 8 ] = nz;
  15024. }
  15025. }
  15026. _gl.bufferData( _gl.ARRAY_BUFFER, object.normalArray, _gl.DYNAMIC_DRAW );
  15027. state.enableAttribute( attributes.normal );
  15028. _gl.vertexAttribPointer( attributes.normal, 3, _gl.FLOAT, false, 0, 0 );
  15029. }
  15030. if ( object.hasUvs && material.map ) {
  15031. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffers.uv );
  15032. _gl.bufferData( _gl.ARRAY_BUFFER, object.uvArray, _gl.DYNAMIC_DRAW );
  15033. state.enableAttribute( attributes.uv );
  15034. _gl.vertexAttribPointer( attributes.uv, 2, _gl.FLOAT, false, 0, 0 );
  15035. }
  15036. if ( object.hasColors && material.vertexColors !== THREE.NoColors ) {
  15037. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffers.color );
  15038. _gl.bufferData( _gl.ARRAY_BUFFER, object.colorArray, _gl.DYNAMIC_DRAW );
  15039. state.enableAttribute( attributes.color );
  15040. _gl.vertexAttribPointer( attributes.color, 3, _gl.FLOAT, false, 0, 0 );
  15041. }
  15042. state.disableUnusedAttributes();
  15043. _gl.drawArrays( _gl.TRIANGLES, 0, object.count );
  15044. object.count = 0;
  15045. };
  15046. this.renderBufferDirect = function ( camera, fog, geometry, material, object, group ) {
  15047. setMaterial( material );
  15048. var program = setProgram( camera, fog, material, object );
  15049. var updateBuffers = false;
  15050. var geometryProgram = geometry.id + '_' + program.id + '_' + material.wireframe;
  15051. if ( geometryProgram !== _currentGeometryProgram ) {
  15052. _currentGeometryProgram = geometryProgram;
  15053. updateBuffers = true;
  15054. }
  15055. // morph targets
  15056. var morphTargetInfluences = object.morphTargetInfluences;
  15057. if ( morphTargetInfluences !== undefined ) {
  15058. var activeInfluences = [];
  15059. for ( var i = 0, l = morphTargetInfluences.length; i < l; i ++ ) {
  15060. var influence = morphTargetInfluences[ i ];
  15061. activeInfluences.push( [ influence, i ] );
  15062. }
  15063. activeInfluences.sort( absNumericalSort );
  15064. if ( activeInfluences.length > 8 ) {
  15065. activeInfluences.length = 8;
  15066. }
  15067. var morphAttributes = geometry.morphAttributes;
  15068. for ( var i = 0, l = activeInfluences.length; i < l; i ++ ) {
  15069. var influence = activeInfluences[ i ];
  15070. morphInfluences[ i ] = influence[ 0 ];
  15071. if ( influence[ 0 ] !== 0 ) {
  15072. var index = influence[ 1 ];
  15073. if ( material.morphTargets === true && morphAttributes.position ) geometry.addAttribute( 'morphTarget' + i, morphAttributes.position[ index ] );
  15074. if ( material.morphNormals === true && morphAttributes.normal ) geometry.addAttribute( 'morphNormal' + i, morphAttributes.normal[ index ] );
  15075. } else {
  15076. if ( material.morphTargets === true ) geometry.removeAttribute( 'morphTarget' + i );
  15077. if ( material.morphNormals === true ) geometry.removeAttribute( 'morphNormal' + i );
  15078. }
  15079. }
  15080. program.getUniforms().setValue(
  15081. _gl, 'morphTargetInfluences', morphInfluences );
  15082. updateBuffers = true;
  15083. }
  15084. //
  15085. var index = geometry.index;
  15086. var position = geometry.attributes.position;
  15087. if ( material.wireframe === true ) {
  15088. index = objects.getWireframeAttribute( geometry );
  15089. }
  15090. var renderer;
  15091. if ( index !== null ) {
  15092. renderer = indexedBufferRenderer;
  15093. renderer.setIndex( index );
  15094. } else {
  15095. renderer = bufferRenderer;
  15096. }
  15097. if ( updateBuffers ) {
  15098. setupVertexAttributes( material, program, geometry );
  15099. if ( index !== null ) {
  15100. _gl.bindBuffer( _gl.ELEMENT_ARRAY_BUFFER, objects.getAttributeBuffer( index ) );
  15101. }
  15102. }
  15103. //
  15104. var dataStart = 0;
  15105. var dataCount = Infinity;
  15106. if ( index !== null ) {
  15107. dataCount = index.count;
  15108. } else if ( position !== undefined ) {
  15109. dataCount = position.count;
  15110. }
  15111. var rangeStart = geometry.drawRange.start;
  15112. var rangeCount = geometry.drawRange.count;
  15113. var groupStart = group !== null ? group.start : 0;
  15114. var groupCount = group !== null ? group.count : Infinity;
  15115. var drawStart = Math.max( dataStart, rangeStart, groupStart );
  15116. var drawEnd = Math.min( dataStart + dataCount, rangeStart + rangeCount, groupStart + groupCount ) - 1;
  15117. var drawCount = Math.max( 0, drawEnd - drawStart + 1 );
  15118. //
  15119. if ( object instanceof THREE.Mesh ) {
  15120. if ( material.wireframe === true ) {
  15121. state.setLineWidth( material.wireframeLinewidth * getTargetPixelRatio() );
  15122. renderer.setMode( _gl.LINES );
  15123. } else {
  15124. switch ( object.drawMode ) {
  15125. case THREE.TrianglesDrawMode:
  15126. renderer.setMode( _gl.TRIANGLES );
  15127. break;
  15128. case THREE.TriangleStripDrawMode:
  15129. renderer.setMode( _gl.TRIANGLE_STRIP );
  15130. break;
  15131. case THREE.TriangleFanDrawMode:
  15132. renderer.setMode( _gl.TRIANGLE_FAN );
  15133. break;
  15134. }
  15135. }
  15136. } else if ( object instanceof THREE.Line ) {
  15137. var lineWidth = material.linewidth;
  15138. if ( lineWidth === undefined ) lineWidth = 1; // Not using Line*Material
  15139. state.setLineWidth( lineWidth * getTargetPixelRatio() );
  15140. if ( object instanceof THREE.LineSegments ) {
  15141. renderer.setMode( _gl.LINES );
  15142. } else {
  15143. renderer.setMode( _gl.LINE_STRIP );
  15144. }
  15145. } else if ( object instanceof THREE.Points ) {
  15146. renderer.setMode( _gl.POINTS );
  15147. }
  15148. if ( geometry instanceof THREE.InstancedBufferGeometry ) {
  15149. if ( geometry.maxInstancedCount > 0 ) {
  15150. renderer.renderInstances( geometry, drawStart, drawCount );
  15151. }
  15152. } else {
  15153. renderer.render( drawStart, drawCount );
  15154. }
  15155. };
  15156. function setupVertexAttributes( material, program, geometry, startIndex ) {
  15157. var extension;
  15158. if ( geometry instanceof THREE.InstancedBufferGeometry ) {
  15159. extension = extensions.get( 'ANGLE_instanced_arrays' );
  15160. if ( extension === null ) {
  15161. console.error( 'THREE.WebGLRenderer.setupVertexAttributes: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  15162. return;
  15163. }
  15164. }
  15165. if ( startIndex === undefined ) startIndex = 0;
  15166. state.initAttributes();
  15167. var geometryAttributes = geometry.attributes;
  15168. var programAttributes = program.getAttributes();
  15169. var materialDefaultAttributeValues = material.defaultAttributeValues;
  15170. for ( var name in programAttributes ) {
  15171. var programAttribute = programAttributes[ name ];
  15172. if ( programAttribute >= 0 ) {
  15173. var geometryAttribute = geometryAttributes[ name ];
  15174. if ( geometryAttribute !== undefined ) {
  15175. var type = _gl.FLOAT;
  15176. var array = geometryAttribute.array;
  15177. var normalized = geometryAttribute.normalized;
  15178. if ( array instanceof Float32Array ) {
  15179. type = _gl.FLOAT;
  15180. } else if ( array instanceof Float64Array ) {
  15181. console.warn("Unsupported data buffer format: Float64Array");
  15182. } else if ( array instanceof Uint16Array ) {
  15183. type = _gl.UNSIGNED_SHORT;
  15184. } else if ( array instanceof Int16Array ) {
  15185. type = _gl.SHORT;
  15186. } else if ( array instanceof Uint32Array ) {
  15187. type = _gl.UNSIGNED_INT;
  15188. } else if ( array instanceof Int32Array ) {
  15189. type = _gl.INT;
  15190. } else if ( array instanceof Int8Array ) {
  15191. type = _gl.BYTE;
  15192. } else if ( array instanceof Uint8Array ) {
  15193. type = _gl.UNSIGNED_BYTE;
  15194. }
  15195. var size = geometryAttribute.itemSize;
  15196. var buffer = objects.getAttributeBuffer( geometryAttribute );
  15197. if ( geometryAttribute instanceof THREE.InterleavedBufferAttribute ) {
  15198. var data = geometryAttribute.data;
  15199. var stride = data.stride;
  15200. var offset = geometryAttribute.offset;
  15201. if ( data instanceof THREE.InstancedInterleavedBuffer ) {
  15202. state.enableAttributeAndDivisor( programAttribute, data.meshPerAttribute, extension );
  15203. if ( geometry.maxInstancedCount === undefined ) {
  15204. geometry.maxInstancedCount = data.meshPerAttribute * data.count;
  15205. }
  15206. } else {
  15207. state.enableAttribute( programAttribute );
  15208. }
  15209. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffer );
  15210. _gl.vertexAttribPointer( programAttribute, size, type, normalized, stride * data.array.BYTES_PER_ELEMENT, ( startIndex * stride + offset ) * data.array.BYTES_PER_ELEMENT );
  15211. } else {
  15212. if ( geometryAttribute instanceof THREE.InstancedBufferAttribute ) {
  15213. state.enableAttributeAndDivisor( programAttribute, geometryAttribute.meshPerAttribute, extension );
  15214. if ( geometry.maxInstancedCount === undefined ) {
  15215. geometry.maxInstancedCount = geometryAttribute.meshPerAttribute * geometryAttribute.count;
  15216. }
  15217. } else {
  15218. state.enableAttribute( programAttribute );
  15219. }
  15220. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffer );
  15221. _gl.vertexAttribPointer( programAttribute, size, type, normalized, 0, startIndex * size * geometryAttribute.array.BYTES_PER_ELEMENT );
  15222. }
  15223. } else if ( materialDefaultAttributeValues !== undefined ) {
  15224. var value = materialDefaultAttributeValues[ name ];
  15225. if ( value !== undefined ) {
  15226. switch ( value.length ) {
  15227. case 2:
  15228. _gl.vertexAttrib2fv( programAttribute, value );
  15229. break;
  15230. case 3:
  15231. _gl.vertexAttrib3fv( programAttribute, value );
  15232. break;
  15233. case 4:
  15234. _gl.vertexAttrib4fv( programAttribute, value );
  15235. break;
  15236. default:
  15237. _gl.vertexAttrib1fv( programAttribute, value );
  15238. }
  15239. }
  15240. }
  15241. }
  15242. }
  15243. state.disableUnusedAttributes();
  15244. }
  15245. // Sorting
  15246. function absNumericalSort( a, b ) {
  15247. return Math.abs( b[ 0 ] ) - Math.abs( a[ 0 ] );
  15248. }
  15249. function painterSortStable ( a, b ) {
  15250. if ( a.object.renderOrder !== b.object.renderOrder ) {
  15251. return a.object.renderOrder - b.object.renderOrder;
  15252. } else if ( a.material.id !== b.material.id ) {
  15253. return a.material.id - b.material.id;
  15254. } else if ( a.z !== b.z ) {
  15255. return a.z - b.z;
  15256. } else {
  15257. return a.id - b.id;
  15258. }
  15259. }
  15260. function reversePainterSortStable ( a, b ) {
  15261. if ( a.object.renderOrder !== b.object.renderOrder ) {
  15262. return a.object.renderOrder - b.object.renderOrder;
  15263. } if ( a.z !== b.z ) {
  15264. return b.z - a.z;
  15265. } else {
  15266. return a.id - b.id;
  15267. }
  15268. }
  15269. // Rendering
  15270. this.render = function ( scene, camera, renderTarget, forceClear ) {
  15271. if ( camera instanceof THREE.Camera === false ) {
  15272. console.error( 'THREE.WebGLRenderer.render: camera is not an instance of THREE.Camera.' );
  15273. return;
  15274. }
  15275. var fog = scene.fog;
  15276. // reset caching for this frame
  15277. _currentGeometryProgram = '';
  15278. _currentMaterialId = - 1;
  15279. _currentCamera = null;
  15280. // update scene graph
  15281. if ( scene.autoUpdate === true ) scene.updateMatrixWorld();
  15282. // update camera matrices and frustum
  15283. if ( camera.parent === null ) camera.updateMatrixWorld();
  15284. camera.matrixWorldInverse.getInverse( camera.matrixWorld );
  15285. _projScreenMatrix.multiplyMatrices( camera.projectionMatrix, camera.matrixWorldInverse );
  15286. _frustum.setFromMatrix( _projScreenMatrix );
  15287. lights.length = 0;
  15288. opaqueObjectsLastIndex = - 1;
  15289. transparentObjectsLastIndex = - 1;
  15290. sprites.length = 0;
  15291. lensFlares.length = 0;
  15292. _localClippingEnabled = this.localClippingEnabled;
  15293. _clippingEnabled = _clipping.init( this.clippingPlanes, _localClippingEnabled, camera );
  15294. projectObject( scene, camera );
  15295. opaqueObjects.length = opaqueObjectsLastIndex + 1;
  15296. transparentObjects.length = transparentObjectsLastIndex + 1;
  15297. if ( _this.sortObjects === true ) {
  15298. opaqueObjects.sort( painterSortStable );
  15299. transparentObjects.sort( reversePainterSortStable );
  15300. }
  15301. //
  15302. if ( _clippingEnabled ) _clipping.beginShadows();
  15303. setupShadows( lights );
  15304. shadowMap.render( scene, camera );
  15305. setupLights( lights, camera );
  15306. if ( _clippingEnabled ) _clipping.endShadows();
  15307. //
  15308. _infoRender.calls = 0;
  15309. _infoRender.vertices = 0;
  15310. _infoRender.faces = 0;
  15311. _infoRender.points = 0;
  15312. if ( renderTarget === undefined ) {
  15313. renderTarget = null;
  15314. }
  15315. this.setRenderTarget( renderTarget );
  15316. //
  15317. var background = scene.background;
  15318. if ( background === null ) {
  15319. glClearColor( _clearColor.r, _clearColor.g, _clearColor.b, _clearAlpha );
  15320. } else if ( background instanceof THREE.Color ) {
  15321. glClearColor( background.r, background.g, background.b, 1 );
  15322. }
  15323. if ( this.autoClear || forceClear ) {
  15324. this.clear( this.autoClearColor, this.autoClearDepth, this.autoClearStencil );
  15325. }
  15326. if ( background instanceof THREE.CubeTexture ) {
  15327. backgroundCamera2.projectionMatrix.copy( camera.projectionMatrix );
  15328. backgroundCamera2.matrixWorld.extractRotation( camera.matrixWorld );
  15329. backgroundCamera2.matrixWorldInverse.getInverse( backgroundCamera2.matrixWorld );
  15330. backgroundBoxMesh.material.uniforms[ "tCube" ].value = background;
  15331. backgroundBoxMesh.modelViewMatrix.multiplyMatrices( backgroundCamera2.matrixWorldInverse, backgroundBoxMesh.matrixWorld );
  15332. _this.renderBufferDirect( backgroundCamera2, null, backgroundBoxMesh.geometry, backgroundBoxMesh.material, backgroundBoxMesh, null );
  15333. } else if ( background instanceof THREE.Texture ) {
  15334. backgroundPlaneMesh.material.map = background;
  15335. _this.renderBufferDirect( backgroundCamera, null, backgroundPlaneMesh.geometry, backgroundPlaneMesh.material, backgroundPlaneMesh, null );
  15336. }
  15337. //
  15338. if ( scene.overrideMaterial ) {
  15339. var overrideMaterial = scene.overrideMaterial;
  15340. renderObjects( opaqueObjects, camera, fog, overrideMaterial );
  15341. renderObjects( transparentObjects, camera, fog, overrideMaterial );
  15342. } else {
  15343. // opaque pass (front-to-back order)
  15344. state.setBlending( THREE.NoBlending );
  15345. renderObjects( opaqueObjects, camera, fog );
  15346. // transparent pass (back-to-front order)
  15347. renderObjects( transparentObjects, camera, fog );
  15348. }
  15349. // custom render plugins (post pass)
  15350. spritePlugin.render( scene, camera );
  15351. lensFlarePlugin.render( scene, camera, _currentViewport );
  15352. // Generate mipmap if we're using any kind of mipmap filtering
  15353. if ( renderTarget ) {
  15354. textures.updateRenderTargetMipmap( renderTarget );
  15355. }
  15356. // Ensure depth buffer writing is enabled so it can be cleared on next render
  15357. state.setDepthTest( true );
  15358. state.setDepthWrite( true );
  15359. state.setColorWrite( true );
  15360. // _gl.finish();
  15361. };
  15362. function pushRenderItem( object, geometry, material, z, group ) {
  15363. var array, index;
  15364. // allocate the next position in the appropriate array
  15365. if ( material.transparent ) {
  15366. array = transparentObjects;
  15367. index = ++ transparentObjectsLastIndex;
  15368. } else {
  15369. array = opaqueObjects;
  15370. index = ++ opaqueObjectsLastIndex;
  15371. }
  15372. // recycle existing render item or grow the array
  15373. var renderItem = array[ index ];
  15374. if ( renderItem !== undefined ) {
  15375. renderItem.id = object.id;
  15376. renderItem.object = object;
  15377. renderItem.geometry = geometry;
  15378. renderItem.material = material;
  15379. renderItem.z = _vector3.z;
  15380. renderItem.group = group;
  15381. } else {
  15382. renderItem = {
  15383. id: object.id,
  15384. object: object,
  15385. geometry: geometry,
  15386. material: material,
  15387. z: _vector3.z,
  15388. group: group
  15389. };
  15390. // assert( index === array.length );
  15391. array.push( renderItem );
  15392. }
  15393. }
  15394. // TODO Duplicated code (Frustum)
  15395. function isObjectViewable( object ) {
  15396. var geometry = object.geometry;
  15397. if ( geometry.boundingSphere === null )
  15398. geometry.computeBoundingSphere();
  15399. _sphere.copy( geometry.boundingSphere ).
  15400. applyMatrix4( object.matrixWorld );
  15401. return isSphereViewable( _sphere );
  15402. }
  15403. function isSpriteViewable( sprite ) {
  15404. _sphere.center.set( 0, 0, 0 );
  15405. _sphere.radius = 0.7071067811865476;
  15406. _sphere.applyMatrix4( sprite.matrixWorld );
  15407. return isSphereViewable( _sphere );
  15408. }
  15409. function isSphereViewable( sphere ) {
  15410. if ( ! _frustum.intersectsSphere( sphere ) ) return false;
  15411. var numPlanes = _clipping.numPlanes;
  15412. if ( numPlanes === 0 ) return true;
  15413. var planes = _this.clippingPlanes,
  15414. center = sphere.center,
  15415. negRad = - sphere.radius,
  15416. i = 0;
  15417. do {
  15418. // out when deeper than radius in the negative halfspace
  15419. if ( planes[ i ].distanceToPoint( center ) < negRad ) return false;
  15420. } while ( ++ i !== numPlanes );
  15421. return true;
  15422. }
  15423. function projectObject( object, camera ) {
  15424. if ( object.visible === false ) return;
  15425. if ( object.layers.test( camera.layers ) ) {
  15426. if ( object instanceof THREE.Light ) {
  15427. lights.push( object );
  15428. } else if ( object instanceof THREE.Sprite ) {
  15429. if ( object.frustumCulled === false || isSpriteViewable( object ) === true ) {
  15430. sprites.push( object );
  15431. }
  15432. } else if ( object instanceof THREE.LensFlare ) {
  15433. lensFlares.push( object );
  15434. } else if ( object instanceof THREE.ImmediateRenderObject ) {
  15435. if ( _this.sortObjects === true ) {
  15436. _vector3.setFromMatrixPosition( object.matrixWorld );
  15437. _vector3.applyProjection( _projScreenMatrix );
  15438. }
  15439. pushRenderItem( object, null, object.material, _vector3.z, null );
  15440. } else if ( object instanceof THREE.Mesh || object instanceof THREE.Line || object instanceof THREE.Points ) {
  15441. if ( object instanceof THREE.SkinnedMesh ) {
  15442. object.skeleton.update();
  15443. }
  15444. if ( object.frustumCulled === false || isObjectViewable( object ) === true ) {
  15445. var material = object.material;
  15446. if ( material.visible === true ) {
  15447. if ( _this.sortObjects === true ) {
  15448. _vector3.setFromMatrixPosition( object.matrixWorld );
  15449. _vector3.applyProjection( _projScreenMatrix );
  15450. }
  15451. var geometry = objects.update( object );
  15452. if ( material instanceof THREE.MultiMaterial ) {
  15453. var groups = geometry.groups;
  15454. var materials = material.materials;
  15455. for ( var i = 0, l = groups.length; i < l; i ++ ) {
  15456. var group = groups[ i ];
  15457. var groupMaterial = materials[ group.materialIndex ];
  15458. if ( groupMaterial.visible === true ) {
  15459. pushRenderItem( object, geometry, groupMaterial, _vector3.z, group );
  15460. }
  15461. }
  15462. } else {
  15463. pushRenderItem( object, geometry, material, _vector3.z, null );
  15464. }
  15465. }
  15466. }
  15467. }
  15468. }
  15469. var children = object.children;
  15470. for ( var i = 0, l = children.length; i < l; i ++ ) {
  15471. projectObject( children[ i ], camera );
  15472. }
  15473. }
  15474. function renderObjects( renderList, camera, fog, overrideMaterial ) {
  15475. for ( var i = 0, l = renderList.length; i < l; i ++ ) {
  15476. var renderItem = renderList[ i ];
  15477. var object = renderItem.object;
  15478. var geometry = renderItem.geometry;
  15479. var material = overrideMaterial === undefined ? renderItem.material : overrideMaterial;
  15480. var group = renderItem.group;
  15481. object.modelViewMatrix.multiplyMatrices( camera.matrixWorldInverse, object.matrixWorld );
  15482. object.normalMatrix.getNormalMatrix( object.modelViewMatrix );
  15483. if ( object instanceof THREE.ImmediateRenderObject ) {
  15484. setMaterial( material );
  15485. var program = setProgram( camera, fog, material, object );
  15486. _currentGeometryProgram = '';
  15487. object.render( function ( object ) {
  15488. _this.renderBufferImmediate( object, program, material );
  15489. } );
  15490. } else {
  15491. _this.renderBufferDirect( camera, fog, geometry, material, object, group );
  15492. }
  15493. }
  15494. }
  15495. function initMaterial( material, fog, object ) {
  15496. var materialProperties = properties.get( material );
  15497. var parameters = programCache.getParameters(
  15498. material, _lights, fog, _clipping.numPlanes, object );
  15499. var code = programCache.getProgramCode( material, parameters );
  15500. var program = materialProperties.program;
  15501. var programChange = true;
  15502. if ( program === undefined ) {
  15503. // new material
  15504. material.addEventListener( 'dispose', onMaterialDispose );
  15505. } else if ( program.code !== code ) {
  15506. // changed glsl or parameters
  15507. releaseMaterialProgramReference( material );
  15508. } else if ( parameters.shaderID !== undefined ) {
  15509. // same glsl and uniform list
  15510. return;
  15511. } else {
  15512. // only rebuild uniform list
  15513. programChange = false;
  15514. }
  15515. if ( programChange ) {
  15516. if ( parameters.shaderID ) {
  15517. var shader = THREE.ShaderLib[ parameters.shaderID ];
  15518. materialProperties.__webglShader = {
  15519. name: material.type,
  15520. uniforms: THREE.UniformsUtils.clone( shader.uniforms ),
  15521. vertexShader: shader.vertexShader,
  15522. fragmentShader: shader.fragmentShader
  15523. };
  15524. } else {
  15525. materialProperties.__webglShader = {
  15526. name: material.type,
  15527. uniforms: material.uniforms,
  15528. vertexShader: material.vertexShader,
  15529. fragmentShader: material.fragmentShader
  15530. };
  15531. }
  15532. material.__webglShader = materialProperties.__webglShader;
  15533. program = programCache.acquireProgram( material, parameters, code );
  15534. materialProperties.program = program;
  15535. material.program = program;
  15536. }
  15537. var attributes = program.getAttributes();
  15538. if ( material.morphTargets ) {
  15539. material.numSupportedMorphTargets = 0;
  15540. for ( var i = 0; i < _this.maxMorphTargets; i ++ ) {
  15541. if ( attributes[ 'morphTarget' + i ] >= 0 ) {
  15542. material.numSupportedMorphTargets ++;
  15543. }
  15544. }
  15545. }
  15546. if ( material.morphNormals ) {
  15547. material.numSupportedMorphNormals = 0;
  15548. for ( var i = 0; i < _this.maxMorphNormals; i ++ ) {
  15549. if ( attributes[ 'morphNormal' + i ] >= 0 ) {
  15550. material.numSupportedMorphNormals ++;
  15551. }
  15552. }
  15553. }
  15554. var uniforms = materialProperties.__webglShader.uniforms;
  15555. if ( ! ( material instanceof THREE.ShaderMaterial ) &&
  15556. ! ( material instanceof THREE.RawShaderMaterial ) ||
  15557. material.clipping === true ) {
  15558. materialProperties.numClippingPlanes = _clipping.numPlanes;
  15559. uniforms.clippingPlanes = _clipping.uniform;
  15560. }
  15561. if ( material.lights ) {
  15562. // store the light setup it was created for
  15563. materialProperties.lightsHash = _lights.hash;
  15564. // wire up the material to this renderer's lighting state
  15565. uniforms.ambientLightColor.value = _lights.ambient;
  15566. uniforms.directionalLights.value = _lights.directional;
  15567. uniforms.spotLights.value = _lights.spot;
  15568. uniforms.pointLights.value = _lights.point;
  15569. uniforms.hemisphereLights.value = _lights.hemi;
  15570. uniforms.directionalShadowMap.value = _lights.directionalShadowMap;
  15571. uniforms.directionalShadowMatrix.value = _lights.directionalShadowMatrix;
  15572. uniforms.spotShadowMap.value = _lights.spotShadowMap;
  15573. uniforms.spotShadowMatrix.value = _lights.spotShadowMatrix;
  15574. uniforms.pointShadowMap.value = _lights.pointShadowMap;
  15575. uniforms.pointShadowMatrix.value = _lights.pointShadowMatrix;
  15576. }
  15577. var progUniforms = materialProperties.program.getUniforms(),
  15578. uniformsList =
  15579. THREE.WebGLUniforms.seqWithValue( progUniforms.seq, uniforms );
  15580. materialProperties.uniformsList = uniformsList;
  15581. materialProperties.dynamicUniforms =
  15582. THREE.WebGLUniforms.splitDynamic( uniformsList, uniforms );
  15583. }
  15584. function setMaterial( material ) {
  15585. if ( material.side !== THREE.DoubleSide )
  15586. state.enable( _gl.CULL_FACE );
  15587. else
  15588. state.disable( _gl.CULL_FACE );
  15589. state.setFlipSided( material.side === THREE.BackSide );
  15590. if ( material.transparent === true ) {
  15591. state.setBlending( material.blending, material.blendEquation, material.blendSrc, material.blendDst, material.blendEquationAlpha, material.blendSrcAlpha, material.blendDstAlpha, material.premultipliedAlpha );
  15592. } else {
  15593. state.setBlending( THREE.NoBlending );
  15594. }
  15595. state.setDepthFunc( material.depthFunc );
  15596. state.setDepthTest( material.depthTest );
  15597. state.setDepthWrite( material.depthWrite );
  15598. state.setColorWrite( material.colorWrite );
  15599. state.setPolygonOffset( material.polygonOffset, material.polygonOffsetFactor, material.polygonOffsetUnits );
  15600. }
  15601. function setProgram( camera, fog, material, object ) {
  15602. _usedTextureUnits = 0;
  15603. var materialProperties = properties.get( material );
  15604. if ( _clippingEnabled ) {
  15605. if ( _localClippingEnabled || camera !== _currentCamera ) {
  15606. var useCache =
  15607. camera === _currentCamera &&
  15608. material.id === _currentMaterialId;
  15609. // we might want to call this function with some ClippingGroup
  15610. // object instead of the material, once it becomes feasible
  15611. // (#8465, #8379)
  15612. _clipping.setState(
  15613. material.clippingPlanes, material.clipShadows,
  15614. camera, materialProperties, useCache );
  15615. }
  15616. if ( materialProperties.numClippingPlanes !== undefined &&
  15617. materialProperties.numClippingPlanes !== _clipping.numPlanes ) {
  15618. material.needsUpdate = true;
  15619. }
  15620. }
  15621. if ( materialProperties.program === undefined ) {
  15622. material.needsUpdate = true;
  15623. }
  15624. if ( materialProperties.lightsHash !== undefined &&
  15625. materialProperties.lightsHash !== _lights.hash ) {
  15626. material.needsUpdate = true;
  15627. }
  15628. if ( material.needsUpdate ) {
  15629. initMaterial( material, fog, object );
  15630. material.needsUpdate = false;
  15631. }
  15632. var refreshProgram = false;
  15633. var refreshMaterial = false;
  15634. var refreshLights = false;
  15635. var program = materialProperties.program,
  15636. p_uniforms = program.getUniforms(),
  15637. m_uniforms = materialProperties.__webglShader.uniforms;
  15638. if ( program.id !== _currentProgram ) {
  15639. _gl.useProgram( program.program );
  15640. _currentProgram = program.id;
  15641. refreshProgram = true;
  15642. refreshMaterial = true;
  15643. refreshLights = true;
  15644. }
  15645. if ( material.id !== _currentMaterialId ) {
  15646. _currentMaterialId = material.id;
  15647. refreshMaterial = true;
  15648. }
  15649. if ( refreshProgram || camera !== _currentCamera ) {
  15650. p_uniforms.set( _gl, camera, 'projectionMatrix' );
  15651. if ( capabilities.logarithmicDepthBuffer ) {
  15652. p_uniforms.setValue( _gl, 'logDepthBufFC',
  15653. 2.0 / ( Math.log( camera.far + 1.0 ) / Math.LN2 ) );
  15654. }
  15655. if ( camera !== _currentCamera ) {
  15656. _currentCamera = camera;
  15657. // lighting uniforms depend on the camera so enforce an update
  15658. // now, in case this material supports lights - or later, when
  15659. // the next material that does gets activated:
  15660. refreshMaterial = true; // set to true on material change
  15661. refreshLights = true; // remains set until update done
  15662. }
  15663. // load material specific uniforms
  15664. // (shader material also gets them for the sake of genericity)
  15665. if ( material instanceof THREE.ShaderMaterial ||
  15666. material instanceof THREE.MeshPhongMaterial ||
  15667. material instanceof THREE.MeshStandardMaterial ||
  15668. material.envMap ) {
  15669. var uCamPos = p_uniforms.map.cameraPosition;
  15670. if ( uCamPos !== undefined ) {
  15671. uCamPos.setValue( _gl,
  15672. _vector3.setFromMatrixPosition( camera.matrixWorld ) );
  15673. }
  15674. }
  15675. if ( material instanceof THREE.MeshPhongMaterial ||
  15676. material instanceof THREE.MeshLambertMaterial ||
  15677. material instanceof THREE.MeshBasicMaterial ||
  15678. material instanceof THREE.MeshStandardMaterial ||
  15679. material instanceof THREE.ShaderMaterial ||
  15680. material.skinning ) {
  15681. p_uniforms.setValue( _gl, 'viewMatrix', camera.matrixWorldInverse );
  15682. }
  15683. p_uniforms.set( _gl, _this, 'toneMappingExposure' );
  15684. p_uniforms.set( _gl, _this, 'toneMappingWhitePoint' );
  15685. }
  15686. // skinning uniforms must be set even if material didn't change
  15687. // auto-setting of texture unit for bone texture must go before other textures
  15688. // not sure why, but otherwise weird things happen
  15689. if ( material.skinning ) {
  15690. p_uniforms.setOptional( _gl, object, 'bindMatrix' );
  15691. p_uniforms.setOptional( _gl, object, 'bindMatrixInverse' );
  15692. var skeleton = object.skeleton;
  15693. if ( skeleton ) {
  15694. if ( capabilities.floatVertexTextures && skeleton.useVertexTexture ) {
  15695. p_uniforms.set( _gl, skeleton, 'boneTexture' );
  15696. p_uniforms.set( _gl, skeleton, 'boneTextureWidth' );
  15697. p_uniforms.set( _gl, skeleton, 'boneTextureHeight' );
  15698. } else {
  15699. p_uniforms.setOptional( _gl, skeleton, 'boneMatrices' );
  15700. }
  15701. }
  15702. }
  15703. if ( refreshMaterial ) {
  15704. if ( material.lights ) {
  15705. // the current material requires lighting info
  15706. // note: all lighting uniforms are always set correctly
  15707. // they simply reference the renderer's state for their
  15708. // values
  15709. //
  15710. // use the current material's .needsUpdate flags to set
  15711. // the GL state when required
  15712. markUniformsLightsNeedsUpdate( m_uniforms, refreshLights );
  15713. }
  15714. // refresh uniforms common to several materials
  15715. if ( fog && material.fog ) {
  15716. refreshUniformsFog( m_uniforms, fog );
  15717. }
  15718. if ( material instanceof THREE.MeshBasicMaterial ||
  15719. material instanceof THREE.MeshLambertMaterial ||
  15720. material instanceof THREE.MeshPhongMaterial ||
  15721. material instanceof THREE.MeshStandardMaterial ||
  15722. material instanceof THREE.MeshDepthMaterial ) {
  15723. refreshUniformsCommon( m_uniforms, material );
  15724. }
  15725. // refresh single material specific uniforms
  15726. if ( material instanceof THREE.LineBasicMaterial ) {
  15727. refreshUniformsLine( m_uniforms, material );
  15728. } else if ( material instanceof THREE.LineDashedMaterial ) {
  15729. refreshUniformsLine( m_uniforms, material );
  15730. refreshUniformsDash( m_uniforms, material );
  15731. } else if ( material instanceof THREE.PointsMaterial ) {
  15732. refreshUniformsPoints( m_uniforms, material );
  15733. } else if ( material instanceof THREE.MeshLambertMaterial ) {
  15734. refreshUniformsLambert( m_uniforms, material );
  15735. } else if ( material instanceof THREE.MeshPhongMaterial ) {
  15736. refreshUniformsPhong( m_uniforms, material );
  15737. } else if ( material instanceof THREE.MeshPhysicalMaterial ) {
  15738. refreshUniformsPhysical( m_uniforms, material );
  15739. } else if ( material instanceof THREE.MeshStandardMaterial ) {
  15740. refreshUniformsStandard( m_uniforms, material );
  15741. } else if ( material instanceof THREE.MeshDepthMaterial ) {
  15742. if ( material.displacementMap ) {
  15743. m_uniforms.displacementMap.value = material.displacementMap;
  15744. m_uniforms.displacementScale.value = material.displacementScale;
  15745. m_uniforms.displacementBias.value = material.displacementBias;
  15746. }
  15747. } else if ( material instanceof THREE.MeshNormalMaterial ) {
  15748. m_uniforms.opacity.value = material.opacity;
  15749. }
  15750. THREE.WebGLUniforms.upload(
  15751. _gl, materialProperties.uniformsList, m_uniforms, _this );
  15752. }
  15753. // common matrices
  15754. p_uniforms.set( _gl, object, 'modelViewMatrix' );
  15755. p_uniforms.set( _gl, object, 'normalMatrix' );
  15756. p_uniforms.setValue( _gl, 'modelMatrix', object.matrixWorld );
  15757. // dynamic uniforms
  15758. var dynUniforms = materialProperties.dynamicUniforms;
  15759. if ( dynUniforms !== null ) {
  15760. THREE.WebGLUniforms.evalDynamic(
  15761. dynUniforms, m_uniforms, object, camera );
  15762. THREE.WebGLUniforms.upload( _gl, dynUniforms, m_uniforms, _this );
  15763. }
  15764. return program;
  15765. }
  15766. // Uniforms (refresh uniforms objects)
  15767. function refreshUniformsCommon ( uniforms, material ) {
  15768. uniforms.opacity.value = material.opacity;
  15769. uniforms.diffuse.value = material.color;
  15770. if ( material.emissive ) {
  15771. uniforms.emissive.value.copy( material.emissive ).multiplyScalar( material.emissiveIntensity );
  15772. }
  15773. uniforms.map.value = material.map;
  15774. uniforms.specularMap.value = material.specularMap;
  15775. uniforms.alphaMap.value = material.alphaMap;
  15776. if ( material.aoMap ) {
  15777. uniforms.aoMap.value = material.aoMap;
  15778. uniforms.aoMapIntensity.value = material.aoMapIntensity;
  15779. }
  15780. // uv repeat and offset setting priorities
  15781. // 1. color map
  15782. // 2. specular map
  15783. // 3. normal map
  15784. // 4. bump map
  15785. // 5. alpha map
  15786. // 6. emissive map
  15787. var uvScaleMap;
  15788. if ( material.map ) {
  15789. uvScaleMap = material.map;
  15790. } else if ( material.specularMap ) {
  15791. uvScaleMap = material.specularMap;
  15792. } else if ( material.displacementMap ) {
  15793. uvScaleMap = material.displacementMap;
  15794. } else if ( material.normalMap ) {
  15795. uvScaleMap = material.normalMap;
  15796. } else if ( material.bumpMap ) {
  15797. uvScaleMap = material.bumpMap;
  15798. } else if ( material.roughnessMap ) {
  15799. uvScaleMap = material.roughnessMap;
  15800. } else if ( material.metalnessMap ) {
  15801. uvScaleMap = material.metalnessMap;
  15802. } else if ( material.alphaMap ) {
  15803. uvScaleMap = material.alphaMap;
  15804. } else if ( material.emissiveMap ) {
  15805. uvScaleMap = material.emissiveMap;
  15806. }
  15807. if ( uvScaleMap !== undefined ) {
  15808. // backwards compatibility
  15809. if ( uvScaleMap instanceof THREE.WebGLRenderTarget ) {
  15810. uvScaleMap = uvScaleMap.texture;
  15811. }
  15812. var offset = uvScaleMap.offset;
  15813. var repeat = uvScaleMap.repeat;
  15814. uniforms.offsetRepeat.value.set( offset.x, offset.y, repeat.x, repeat.y );
  15815. }
  15816. uniforms.envMap.value = material.envMap;
  15817. // don't flip CubeTexture envMaps, flip everything else:
  15818. // WebGLRenderTargetCube will be flipped for backwards compatibility
  15819. // WebGLRenderTargetCube.texture will be flipped because it's a Texture and NOT a CubeTexture
  15820. // this check must be handled differently, or removed entirely, if WebGLRenderTargetCube uses a CubeTexture in the future
  15821. uniforms.flipEnvMap.value = ( ! ( material.envMap instanceof THREE.CubeTexture ) ) ? 1 : - 1;
  15822. uniforms.reflectivity.value = material.reflectivity;
  15823. uniforms.refractionRatio.value = material.refractionRatio;
  15824. }
  15825. function refreshUniformsLine ( uniforms, material ) {
  15826. uniforms.diffuse.value = material.color;
  15827. uniforms.opacity.value = material.opacity;
  15828. }
  15829. function refreshUniformsDash ( uniforms, material ) {
  15830. uniforms.dashSize.value = material.dashSize;
  15831. uniforms.totalSize.value = material.dashSize + material.gapSize;
  15832. uniforms.scale.value = material.scale;
  15833. }
  15834. function refreshUniformsPoints ( uniforms, material ) {
  15835. uniforms.diffuse.value = material.color;
  15836. uniforms.opacity.value = material.opacity;
  15837. uniforms.size.value = material.size * _pixelRatio;
  15838. uniforms.scale.value = _canvas.clientHeight * 0.5;
  15839. uniforms.map.value = material.map;
  15840. if ( material.map !== null ) {
  15841. var offset = material.map.offset;
  15842. var repeat = material.map.repeat;
  15843. uniforms.offsetRepeat.value.set( offset.x, offset.y, repeat.x, repeat.y );
  15844. }
  15845. }
  15846. function refreshUniformsFog ( uniforms, fog ) {
  15847. uniforms.fogColor.value = fog.color;
  15848. if ( fog instanceof THREE.Fog ) {
  15849. uniforms.fogNear.value = fog.near;
  15850. uniforms.fogFar.value = fog.far;
  15851. } else if ( fog instanceof THREE.FogExp2 ) {
  15852. uniforms.fogDensity.value = fog.density;
  15853. }
  15854. }
  15855. function refreshUniformsLambert ( uniforms, material ) {
  15856. if ( material.lightMap ) {
  15857. uniforms.lightMap.value = material.lightMap;
  15858. uniforms.lightMapIntensity.value = material.lightMapIntensity;
  15859. }
  15860. if ( material.emissiveMap ) {
  15861. uniforms.emissiveMap.value = material.emissiveMap;
  15862. }
  15863. }
  15864. function refreshUniformsPhong ( uniforms, material ) {
  15865. uniforms.specular.value = material.specular;
  15866. uniforms.shininess.value = Math.max( material.shininess, 1e-4 ); // to prevent pow( 0.0, 0.0 )
  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. if ( material.bumpMap ) {
  15875. uniforms.bumpMap.value = material.bumpMap;
  15876. uniforms.bumpScale.value = material.bumpScale;
  15877. }
  15878. if ( material.normalMap ) {
  15879. uniforms.normalMap.value = material.normalMap;
  15880. uniforms.normalScale.value.copy( material.normalScale );
  15881. }
  15882. if ( material.displacementMap ) {
  15883. uniforms.displacementMap.value = material.displacementMap;
  15884. uniforms.displacementScale.value = material.displacementScale;
  15885. uniforms.displacementBias.value = material.displacementBias;
  15886. }
  15887. }
  15888. function refreshUniformsStandard ( uniforms, material ) {
  15889. uniforms.roughness.value = material.roughness;
  15890. uniforms.metalness.value = material.metalness;
  15891. if ( material.roughnessMap ) {
  15892. uniforms.roughnessMap.value = material.roughnessMap;
  15893. }
  15894. if ( material.metalnessMap ) {
  15895. uniforms.metalnessMap.value = material.metalnessMap;
  15896. }
  15897. if ( material.lightMap ) {
  15898. uniforms.lightMap.value = material.lightMap;
  15899. uniforms.lightMapIntensity.value = material.lightMapIntensity;
  15900. }
  15901. if ( material.emissiveMap ) {
  15902. uniforms.emissiveMap.value = material.emissiveMap;
  15903. }
  15904. if ( material.bumpMap ) {
  15905. uniforms.bumpMap.value = material.bumpMap;
  15906. uniforms.bumpScale.value = material.bumpScale;
  15907. }
  15908. if ( material.normalMap ) {
  15909. uniforms.normalMap.value = material.normalMap;
  15910. uniforms.normalScale.value.copy( material.normalScale );
  15911. }
  15912. if ( material.displacementMap ) {
  15913. uniforms.displacementMap.value = material.displacementMap;
  15914. uniforms.displacementScale.value = material.displacementScale;
  15915. uniforms.displacementBias.value = material.displacementBias;
  15916. }
  15917. if ( material.envMap ) {
  15918. //uniforms.envMap.value = material.envMap; // part of uniforms common
  15919. uniforms.envMapIntensity.value = material.envMapIntensity;
  15920. }
  15921. }
  15922. function refreshUniformsPhysical ( uniforms, material ) {
  15923. uniforms.clearCoat.value = material.clearCoat;
  15924. uniforms.clearCoatRoughness.value = material.clearCoatRoughness;
  15925. refreshUniformsStandard( uniforms, material );
  15926. }
  15927. // If uniforms are marked as clean, they don't need to be loaded to the GPU.
  15928. function markUniformsLightsNeedsUpdate ( uniforms, value ) {
  15929. uniforms.ambientLightColor.needsUpdate = value;
  15930. uniforms.directionalLights.needsUpdate = value;
  15931. uniforms.pointLights.needsUpdate = value;
  15932. uniforms.spotLights.needsUpdate = value;
  15933. uniforms.hemisphereLights.needsUpdate = value;
  15934. }
  15935. // Lighting
  15936. function setupShadows ( lights ) {
  15937. var lightShadowsLength = 0;
  15938. for ( var i = 0, l = lights.length; i < l; i ++ ) {
  15939. var light = lights[ i ];
  15940. if ( light.castShadow ) {
  15941. _lights.shadows[ lightShadowsLength ++ ] = light;
  15942. }
  15943. }
  15944. _lights.shadows.length = lightShadowsLength;
  15945. }
  15946. function setupLights ( lights, camera ) {
  15947. var l, ll, light,
  15948. r = 0, g = 0, b = 0,
  15949. color,
  15950. intensity,
  15951. distance,
  15952. shadowMap,
  15953. viewMatrix = camera.matrixWorldInverse,
  15954. directionalLength = 0,
  15955. pointLength = 0,
  15956. spotLength = 0,
  15957. hemiLength = 0;
  15958. for ( l = 0, ll = lights.length; l < ll; l ++ ) {
  15959. light = lights[ l ];
  15960. color = light.color;
  15961. intensity = light.intensity;
  15962. distance = light.distance;
  15963. shadowMap = ( light.shadow && light.shadow.map ) ? light.shadow.map.texture : null;
  15964. if ( light instanceof THREE.AmbientLight ) {
  15965. r += color.r * intensity;
  15966. g += color.g * intensity;
  15967. b += color.b * intensity;
  15968. } else if ( light instanceof THREE.DirectionalLight ) {
  15969. var uniforms = lightCache.get( light );
  15970. uniforms.color.copy( light.color ).multiplyScalar( light.intensity );
  15971. uniforms.direction.setFromMatrixPosition( light.matrixWorld );
  15972. _vector3.setFromMatrixPosition( light.target.matrixWorld );
  15973. uniforms.direction.sub( _vector3 );
  15974. uniforms.direction.transformDirection( viewMatrix );
  15975. uniforms.shadow = light.castShadow;
  15976. if ( light.castShadow ) {
  15977. uniforms.shadowBias = light.shadow.bias;
  15978. uniforms.shadowRadius = light.shadow.radius;
  15979. uniforms.shadowMapSize = light.shadow.mapSize;
  15980. }
  15981. _lights.directionalShadowMap[ directionalLength ] = shadowMap;
  15982. _lights.directionalShadowMatrix[ directionalLength ] = light.shadow.matrix;
  15983. _lights.directional[ directionalLength ++ ] = uniforms;
  15984. } else if ( light instanceof THREE.SpotLight ) {
  15985. var uniforms = lightCache.get( light );
  15986. uniforms.position.setFromMatrixPosition( light.matrixWorld );
  15987. uniforms.position.applyMatrix4( viewMatrix );
  15988. uniforms.color.copy( color ).multiplyScalar( intensity );
  15989. uniforms.distance = distance;
  15990. uniforms.direction.setFromMatrixPosition( light.matrixWorld );
  15991. _vector3.setFromMatrixPosition( light.target.matrixWorld );
  15992. uniforms.direction.sub( _vector3 );
  15993. uniforms.direction.transformDirection( viewMatrix );
  15994. uniforms.coneCos = Math.cos( light.angle );
  15995. uniforms.penumbraCos = Math.cos( light.angle * ( 1 - light.penumbra ) );
  15996. uniforms.decay = ( light.distance === 0 ) ? 0.0 : light.decay;
  15997. uniforms.shadow = light.castShadow;
  15998. if ( light.castShadow ) {
  15999. uniforms.shadowBias = light.shadow.bias;
  16000. uniforms.shadowRadius = light.shadow.radius;
  16001. uniforms.shadowMapSize = light.shadow.mapSize;
  16002. }
  16003. _lights.spotShadowMap[ spotLength ] = shadowMap;
  16004. _lights.spotShadowMatrix[ spotLength ] = light.shadow.matrix;
  16005. _lights.spot[ spotLength ++ ] = uniforms;
  16006. } else if ( light instanceof THREE.PointLight ) {
  16007. var uniforms = lightCache.get( light );
  16008. uniforms.position.setFromMatrixPosition( light.matrixWorld );
  16009. uniforms.position.applyMatrix4( viewMatrix );
  16010. uniforms.color.copy( light.color ).multiplyScalar( light.intensity );
  16011. uniforms.distance = light.distance;
  16012. uniforms.decay = ( light.distance === 0 ) ? 0.0 : light.decay;
  16013. uniforms.shadow = light.castShadow;
  16014. if ( light.castShadow ) {
  16015. uniforms.shadowBias = light.shadow.bias;
  16016. uniforms.shadowRadius = light.shadow.radius;
  16017. uniforms.shadowMapSize = light.shadow.mapSize;
  16018. }
  16019. _lights.pointShadowMap[ pointLength ] = shadowMap;
  16020. if ( _lights.pointShadowMatrix[ pointLength ] === undefined ) {
  16021. _lights.pointShadowMatrix[ pointLength ] = new THREE.Matrix4();
  16022. }
  16023. // for point lights we set the shadow matrix to be a translation-only matrix
  16024. // equal to inverse of the light's position
  16025. _vector3.setFromMatrixPosition( light.matrixWorld ).negate();
  16026. _lights.pointShadowMatrix[ pointLength ].identity().setPosition( _vector3 );
  16027. _lights.point[ pointLength ++ ] = uniforms;
  16028. } else if ( light instanceof THREE.HemisphereLight ) {
  16029. var uniforms = lightCache.get( light );
  16030. uniforms.direction.setFromMatrixPosition( light.matrixWorld );
  16031. uniforms.direction.transformDirection( viewMatrix );
  16032. uniforms.direction.normalize();
  16033. uniforms.skyColor.copy( light.color ).multiplyScalar( intensity );
  16034. uniforms.groundColor.copy( light.groundColor ).multiplyScalar( intensity );
  16035. _lights.hemi[ hemiLength ++ ] = uniforms;
  16036. }
  16037. }
  16038. _lights.ambient[ 0 ] = r;
  16039. _lights.ambient[ 1 ] = g;
  16040. _lights.ambient[ 2 ] = b;
  16041. _lights.directional.length = directionalLength;
  16042. _lights.spot.length = spotLength;
  16043. _lights.point.length = pointLength;
  16044. _lights.hemi.length = hemiLength;
  16045. _lights.hash = directionalLength + ',' + pointLength + ',' + spotLength + ',' + hemiLength + ',' + _lights.shadows.length;
  16046. }
  16047. // GL state setting
  16048. this.setFaceCulling = function ( cullFace, frontFaceDirection ) {
  16049. state.setCullFace( cullFace );
  16050. state.setFlipSided( frontFaceDirection === THREE.FrontFaceDirectionCW );
  16051. };
  16052. // Textures
  16053. function allocTextureUnit() {
  16054. var textureUnit = _usedTextureUnits;
  16055. if ( textureUnit >= capabilities.maxTextures ) {
  16056. console.warn( 'WebGLRenderer: trying to use ' + textureUnit + ' texture units while this GPU supports only ' + capabilities.maxTextures );
  16057. }
  16058. _usedTextureUnits += 1;
  16059. return textureUnit;
  16060. }
  16061. this.allocTextureUnit = allocTextureUnit;
  16062. // this.setTexture2D = setTexture2D;
  16063. this.setTexture2D = ( function() {
  16064. var warned = false;
  16065. // backwards compatibility: peel texture.texture
  16066. return function setTexture2D( texture, slot ) {
  16067. if ( texture instanceof THREE.WebGLRenderTarget ) {
  16068. if ( ! warned ) {
  16069. console.warn( "THREE.WebGLRenderer.setTexture2D: don't use render targets as textures. Use their .texture property instead." );
  16070. warned = true;
  16071. }
  16072. texture = texture.texture;
  16073. }
  16074. textures.setTexture2D( texture, slot );
  16075. };
  16076. }() );
  16077. this.setTexture = ( function() {
  16078. var warned = false;
  16079. return function setTexture( texture, slot ) {
  16080. if ( ! warned ) {
  16081. console.warn( "THREE.WebGLRenderer: .setTexture is deprecated, use setTexture2D instead." );
  16082. warned = true;
  16083. }
  16084. textures.setTexture2D( texture, slot );
  16085. };
  16086. }() );
  16087. this.setTextureCube = ( function() {
  16088. var warned = false;
  16089. return function setTextureCube( texture, slot ) {
  16090. // backwards compatibility: peel texture.texture
  16091. if ( texture instanceof THREE.WebGLRenderTargetCube ) {
  16092. if ( ! warned ) {
  16093. console.warn( "THREE.WebGLRenderer.setTextureCube: don't use cube render targets as textures. Use their .texture property instead." );
  16094. warned = true;
  16095. }
  16096. texture = texture.texture;
  16097. }
  16098. // currently relying on the fact that WebGLRenderTargetCube.texture is a Texture and NOT a CubeTexture
  16099. // TODO: unify these code paths
  16100. if ( texture instanceof THREE.CubeTexture ||
  16101. ( Array.isArray( texture.image ) && texture.image.length === 6 ) ) {
  16102. // CompressedTexture can have Array in image :/
  16103. // this function alone should take care of cube textures
  16104. textures.setTextureCube( texture, slot );
  16105. } else {
  16106. // assumed: texture property of THREE.WebGLRenderTargetCube
  16107. textures.setTextureCubeDynamic( texture, slot );
  16108. }
  16109. };
  16110. }() );
  16111. this.getCurrentRenderTarget = function() {
  16112. return _currentRenderTarget;
  16113. };
  16114. this.setRenderTarget = function ( renderTarget ) {
  16115. _currentRenderTarget = renderTarget;
  16116. if ( renderTarget && properties.get( renderTarget ).__webglFramebuffer === undefined ) {
  16117. textures.setupRenderTarget( renderTarget );
  16118. }
  16119. var isCube = ( renderTarget instanceof THREE.WebGLRenderTargetCube );
  16120. var framebuffer;
  16121. if ( renderTarget ) {
  16122. var renderTargetProperties = properties.get( renderTarget );
  16123. if ( isCube ) {
  16124. framebuffer = renderTargetProperties.__webglFramebuffer[ renderTarget.activeCubeFace ];
  16125. } else {
  16126. framebuffer = renderTargetProperties.__webglFramebuffer;
  16127. }
  16128. _currentScissor.copy( renderTarget.scissor );
  16129. _currentScissorTest = renderTarget.scissorTest;
  16130. _currentViewport.copy( renderTarget.viewport );
  16131. } else {
  16132. framebuffer = null;
  16133. _currentScissor.copy( _scissor ).multiplyScalar( _pixelRatio );
  16134. _currentScissorTest = _scissorTest;
  16135. _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio );
  16136. }
  16137. if ( _currentFramebuffer !== framebuffer ) {
  16138. _gl.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
  16139. _currentFramebuffer = framebuffer;
  16140. }
  16141. state.scissor( _currentScissor );
  16142. state.setScissorTest( _currentScissorTest );
  16143. state.viewport( _currentViewport );
  16144. if ( isCube ) {
  16145. var textureProperties = properties.get( renderTarget.texture );
  16146. _gl.framebufferTexture2D( _gl.FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, _gl.TEXTURE_CUBE_MAP_POSITIVE_X + renderTarget.activeCubeFace, textureProperties.__webglTexture, renderTarget.activeMipMapLevel );
  16147. }
  16148. };
  16149. this.readRenderTargetPixels = function ( renderTarget, x, y, width, height, buffer ) {
  16150. if ( renderTarget instanceof THREE.WebGLRenderTarget === false ) {
  16151. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.' );
  16152. return;
  16153. }
  16154. var framebuffer = properties.get( renderTarget ).__webglFramebuffer;
  16155. if ( framebuffer ) {
  16156. var restore = false;
  16157. if ( framebuffer !== _currentFramebuffer ) {
  16158. _gl.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
  16159. restore = true;
  16160. }
  16161. try {
  16162. var texture = renderTarget.texture;
  16163. if ( texture.format !== THREE.RGBAFormat && paramThreeToGL( texture.format ) !== _gl.getParameter( _gl.IMPLEMENTATION_COLOR_READ_FORMAT ) ) {
  16164. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA or implementation defined format.' );
  16165. return;
  16166. }
  16167. if ( texture.type !== THREE.UnsignedByteType &&
  16168. paramThreeToGL( texture.type ) !== _gl.getParameter( _gl.IMPLEMENTATION_COLOR_READ_TYPE ) &&
  16169. ! ( texture.type === THREE.FloatType && extensions.get( 'WEBGL_color_buffer_float' ) ) &&
  16170. ! ( texture.type === THREE.HalfFloatType && extensions.get( 'EXT_color_buffer_half_float' ) ) ) {
  16171. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in UnsignedByteType or implementation defined type.' );
  16172. return;
  16173. }
  16174. if ( _gl.checkFramebufferStatus( _gl.FRAMEBUFFER ) === _gl.FRAMEBUFFER_COMPLETE ) {
  16175. // the following if statement ensures valid read requests (no out-of-bounds pixels, see #8604)
  16176. if ( ( x >= 0 && x <= ( renderTarget.width - width ) ) && ( y >= 0 && y <= ( renderTarget.height - height ) ) ) {
  16177. _gl.readPixels( x, y, width, height, paramThreeToGL( texture.format ), paramThreeToGL( texture.type ), buffer );
  16178. }
  16179. } else {
  16180. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: readPixels from renderTarget failed. Framebuffer not complete.' );
  16181. }
  16182. } finally {
  16183. if ( restore ) {
  16184. _gl.bindFramebuffer( _gl.FRAMEBUFFER, _currentFramebuffer );
  16185. }
  16186. }
  16187. }
  16188. };
  16189. // Map three.js constants to WebGL constants
  16190. function paramThreeToGL ( p ) {
  16191. var extension;
  16192. if ( p === THREE.RepeatWrapping ) return _gl.REPEAT;
  16193. if ( p === THREE.ClampToEdgeWrapping ) return _gl.CLAMP_TO_EDGE;
  16194. if ( p === THREE.MirroredRepeatWrapping ) return _gl.MIRRORED_REPEAT;
  16195. if ( p === THREE.NearestFilter ) return _gl.NEAREST;
  16196. if ( p === THREE.NearestMipMapNearestFilter ) return _gl.NEAREST_MIPMAP_NEAREST;
  16197. if ( p === THREE.NearestMipMapLinearFilter ) return _gl.NEAREST_MIPMAP_LINEAR;
  16198. if ( p === THREE.LinearFilter ) return _gl.LINEAR;
  16199. if ( p === THREE.LinearMipMapNearestFilter ) return _gl.LINEAR_MIPMAP_NEAREST;
  16200. if ( p === THREE.LinearMipMapLinearFilter ) return _gl.LINEAR_MIPMAP_LINEAR;
  16201. if ( p === THREE.UnsignedByteType ) return _gl.UNSIGNED_BYTE;
  16202. if ( p === THREE.UnsignedShort4444Type ) return _gl.UNSIGNED_SHORT_4_4_4_4;
  16203. if ( p === THREE.UnsignedShort5551Type ) return _gl.UNSIGNED_SHORT_5_5_5_1;
  16204. if ( p === THREE.UnsignedShort565Type ) return _gl.UNSIGNED_SHORT_5_6_5;
  16205. if ( p === THREE.ByteType ) return _gl.BYTE;
  16206. if ( p === THREE.ShortType ) return _gl.SHORT;
  16207. if ( p === THREE.UnsignedShortType ) return _gl.UNSIGNED_SHORT;
  16208. if ( p === THREE.IntType ) return _gl.INT;
  16209. if ( p === THREE.UnsignedIntType ) return _gl.UNSIGNED_INT;
  16210. if ( p === THREE.FloatType ) return _gl.FLOAT;
  16211. extension = extensions.get( 'OES_texture_half_float' );
  16212. if ( extension !== null ) {
  16213. if ( p === THREE.HalfFloatType ) return extension.HALF_FLOAT_OES;
  16214. }
  16215. if ( p === THREE.AlphaFormat ) return _gl.ALPHA;
  16216. if ( p === THREE.RGBFormat ) return _gl.RGB;
  16217. if ( p === THREE.RGBAFormat ) return _gl.RGBA;
  16218. if ( p === THREE.LuminanceFormat ) return _gl.LUMINANCE;
  16219. if ( p === THREE.LuminanceAlphaFormat ) return _gl.LUMINANCE_ALPHA;
  16220. if ( p === THREE.DepthFormat ) return _gl.DEPTH_COMPONENT;
  16221. if ( p === THREE.AddEquation ) return _gl.FUNC_ADD;
  16222. if ( p === THREE.SubtractEquation ) return _gl.FUNC_SUBTRACT;
  16223. if ( p === THREE.ReverseSubtractEquation ) return _gl.FUNC_REVERSE_SUBTRACT;
  16224. if ( p === THREE.ZeroFactor ) return _gl.ZERO;
  16225. if ( p === THREE.OneFactor ) return _gl.ONE;
  16226. if ( p === THREE.SrcColorFactor ) return _gl.SRC_COLOR;
  16227. if ( p === THREE.OneMinusSrcColorFactor ) return _gl.ONE_MINUS_SRC_COLOR;
  16228. if ( p === THREE.SrcAlphaFactor ) return _gl.SRC_ALPHA;
  16229. if ( p === THREE.OneMinusSrcAlphaFactor ) return _gl.ONE_MINUS_SRC_ALPHA;
  16230. if ( p === THREE.DstAlphaFactor ) return _gl.DST_ALPHA;
  16231. if ( p === THREE.OneMinusDstAlphaFactor ) return _gl.ONE_MINUS_DST_ALPHA;
  16232. if ( p === THREE.DstColorFactor ) return _gl.DST_COLOR;
  16233. if ( p === THREE.OneMinusDstColorFactor ) return _gl.ONE_MINUS_DST_COLOR;
  16234. if ( p === THREE.SrcAlphaSaturateFactor ) return _gl.SRC_ALPHA_SATURATE;
  16235. extension = extensions.get( 'WEBGL_compressed_texture_s3tc' );
  16236. if ( extension !== null ) {
  16237. if ( p === THREE.RGB_S3TC_DXT1_Format ) return extension.COMPRESSED_RGB_S3TC_DXT1_EXT;
  16238. if ( p === THREE.RGBA_S3TC_DXT1_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT1_EXT;
  16239. if ( p === THREE.RGBA_S3TC_DXT3_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT3_EXT;
  16240. if ( p === THREE.RGBA_S3TC_DXT5_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT5_EXT;
  16241. }
  16242. extension = extensions.get( 'WEBGL_compressed_texture_pvrtc' );
  16243. if ( extension !== null ) {
  16244. if ( p === THREE.RGB_PVRTC_4BPPV1_Format ) return extension.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;
  16245. if ( p === THREE.RGB_PVRTC_2BPPV1_Format ) return extension.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;
  16246. if ( p === THREE.RGBA_PVRTC_4BPPV1_Format ) return extension.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;
  16247. if ( p === THREE.RGBA_PVRTC_2BPPV1_Format ) return extension.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG;
  16248. }
  16249. extension = extensions.get( 'WEBGL_compressed_texture_etc1' );
  16250. if ( extension !== null ) {
  16251. if ( p === THREE.RGB_ETC1_Format ) return extension.COMPRESSED_RGB_ETC1_WEBGL;
  16252. }
  16253. extension = extensions.get( 'EXT_blend_minmax' );
  16254. if ( extension !== null ) {
  16255. if ( p === THREE.MinEquation ) return extension.MIN_EXT;
  16256. if ( p === THREE.MaxEquation ) return extension.MAX_EXT;
  16257. }
  16258. return 0;
  16259. }
  16260. };
  16261. // File:src/renderers/WebGLRenderTarget.js
  16262. /**
  16263. * @author szimek / https://github.com/szimek/
  16264. * @author alteredq / http://alteredqualia.com/
  16265. * @author Marius Kintel / https://github.com/kintel
  16266. */
  16267. /*
  16268. In options, we can specify:
  16269. * Texture parameters for an auto-generated target texture
  16270. * depthBuffer/stencilBuffer: Booleans to indicate if we should generate these buffers
  16271. */
  16272. THREE.WebGLRenderTarget = function ( width, height, options ) {
  16273. this.uuid = THREE.Math.generateUUID();
  16274. this.width = width;
  16275. this.height = height;
  16276. this.scissor = new THREE.Vector4( 0, 0, width, height );
  16277. this.scissorTest = false;
  16278. this.viewport = new THREE.Vector4( 0, 0, width, height );
  16279. options = options || {};
  16280. if ( options.minFilter === undefined ) options.minFilter = THREE.LinearFilter;
  16281. this.texture = new THREE.Texture( undefined, undefined, options.wrapS, options.wrapT, options.magFilter, options.minFilter, options.format, options.type, options.anisotropy, options.encoding );
  16282. this.depthBuffer = options.depthBuffer !== undefined ? options.depthBuffer : true;
  16283. this.stencilBuffer = options.stencilBuffer !== undefined ? options.stencilBuffer : true;
  16284. this.depthTexture = null;
  16285. };
  16286. Object.assign( THREE.WebGLRenderTarget.prototype, THREE.EventDispatcher.prototype, {
  16287. setSize: function ( width, height ) {
  16288. if ( this.width !== width || this.height !== height ) {
  16289. this.width = width;
  16290. this.height = height;
  16291. this.dispose();
  16292. }
  16293. this.viewport.set( 0, 0, width, height );
  16294. this.scissor.set( 0, 0, width, height );
  16295. },
  16296. clone: function () {
  16297. return new this.constructor().copy( this );
  16298. },
  16299. copy: function ( source ) {
  16300. this.width = source.width;
  16301. this.height = source.height;
  16302. this.viewport.copy( source.viewport );
  16303. this.texture = source.texture.clone();
  16304. this.depthBuffer = source.depthBuffer;
  16305. this.stencilBuffer = source.stencilBuffer;
  16306. this.depthTexture = source.depthTexture;
  16307. return this;
  16308. },
  16309. dispose: function () {
  16310. this.dispatchEvent( { type: 'dispose' } );
  16311. }
  16312. } );
  16313. // File:src/renderers/WebGLRenderTargetCube.js
  16314. /**
  16315. * @author alteredq / http://alteredqualia.com
  16316. */
  16317. THREE.WebGLRenderTargetCube = function ( width, height, options ) {
  16318. THREE.WebGLRenderTarget.call( this, width, height, options );
  16319. this.activeCubeFace = 0; // PX 0, NX 1, PY 2, NY 3, PZ 4, NZ 5
  16320. this.activeMipMapLevel = 0;
  16321. };
  16322. THREE.WebGLRenderTargetCube.prototype = Object.create( THREE.WebGLRenderTarget.prototype );
  16323. THREE.WebGLRenderTargetCube.prototype.constructor = THREE.WebGLRenderTargetCube;
  16324. // File:src/renderers/webgl/WebGLBufferRenderer.js
  16325. /**
  16326. * @author mrdoob / http://mrdoob.com/
  16327. */
  16328. THREE.WebGLBufferRenderer = function ( _gl, extensions, _infoRender ) {
  16329. var mode;
  16330. function setMode( value ) {
  16331. mode = value;
  16332. }
  16333. function render( start, count ) {
  16334. _gl.drawArrays( mode, start, count );
  16335. _infoRender.calls ++;
  16336. _infoRender.vertices += count;
  16337. if ( mode === _gl.TRIANGLES ) _infoRender.faces += count / 3;
  16338. }
  16339. function renderInstances( geometry ) {
  16340. var extension = extensions.get( 'ANGLE_instanced_arrays' );
  16341. if ( extension === null ) {
  16342. console.error( 'THREE.WebGLBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  16343. return;
  16344. }
  16345. var position = geometry.attributes.position;
  16346. var count = 0;
  16347. if ( position instanceof THREE.InterleavedBufferAttribute ) {
  16348. count = position.data.count;
  16349. extension.drawArraysInstancedANGLE( mode, 0, count, geometry.maxInstancedCount );
  16350. } else {
  16351. count = position.count;
  16352. extension.drawArraysInstancedANGLE( mode, 0, count, geometry.maxInstancedCount );
  16353. }
  16354. _infoRender.calls ++;
  16355. _infoRender.vertices += count * geometry.maxInstancedCount;
  16356. if ( mode === _gl.TRIANGLES ) _infoRender.faces += geometry.maxInstancedCount * count / 3;
  16357. }
  16358. this.setMode = setMode;
  16359. this.render = render;
  16360. this.renderInstances = renderInstances;
  16361. };
  16362. // File:src/renderers/webgl/WebGLClipping.js
  16363. THREE.WebGLClipping = function() {
  16364. var scope = this,
  16365. globalState = null,
  16366. numGlobalPlanes = 0,
  16367. localClippingEnabled = false,
  16368. renderingShadows = false,
  16369. plane = new THREE.Plane(),
  16370. viewNormalMatrix = new THREE.Matrix3(),
  16371. uniform = { value: null, needsUpdate: false };
  16372. this.uniform = uniform;
  16373. this.numPlanes = 0;
  16374. this.init = function( planes, enableLocalClipping, camera ) {
  16375. var enabled =
  16376. planes.length !== 0 ||
  16377. enableLocalClipping ||
  16378. // enable state of previous frame - the clipping code has to
  16379. // run another frame in order to reset the state:
  16380. numGlobalPlanes !== 0 ||
  16381. localClippingEnabled;
  16382. localClippingEnabled = enableLocalClipping;
  16383. globalState = projectPlanes( planes, camera, 0 );
  16384. numGlobalPlanes = planes.length;
  16385. return enabled;
  16386. };
  16387. this.beginShadows = function() {
  16388. renderingShadows = true;
  16389. projectPlanes( null );
  16390. };
  16391. this.endShadows = function() {
  16392. renderingShadows = false;
  16393. resetGlobalState();
  16394. };
  16395. this.setState = function( planes, clipShadows, camera, cache, fromCache ) {
  16396. if ( ! localClippingEnabled ||
  16397. planes === null || planes.length === 0 ||
  16398. renderingShadows && ! clipShadows ) {
  16399. // there's no local clipping
  16400. if ( renderingShadows ) {
  16401. // there's no global clipping
  16402. projectPlanes( null );
  16403. } else {
  16404. resetGlobalState();
  16405. }
  16406. } else {
  16407. var nGlobal = renderingShadows ? 0 : numGlobalPlanes,
  16408. lGlobal = nGlobal * 4,
  16409. dstArray = cache.clippingState || null;
  16410. uniform.value = dstArray; // ensure unique state
  16411. dstArray = projectPlanes( planes, camera, lGlobal, fromCache );
  16412. for ( var i = 0; i !== lGlobal; ++ i ) {
  16413. dstArray[ i ] = globalState[ i ];
  16414. }
  16415. cache.clippingState = dstArray;
  16416. this.numPlanes += nGlobal;
  16417. }
  16418. };
  16419. function resetGlobalState() {
  16420. if ( uniform.value !== globalState ) {
  16421. uniform.value = globalState;
  16422. uniform.needsUpdate = numGlobalPlanes > 0;
  16423. }
  16424. scope.numPlanes = numGlobalPlanes;
  16425. }
  16426. function projectPlanes( planes, camera, dstOffset, skipTransform ) {
  16427. var nPlanes = planes !== null ? planes.length : 0,
  16428. dstArray = null;
  16429. if ( nPlanes !== 0 ) {
  16430. dstArray = uniform.value;
  16431. if ( skipTransform !== true || dstArray === null ) {
  16432. var flatSize = dstOffset + nPlanes * 4,
  16433. viewMatrix = camera.matrixWorldInverse;
  16434. viewNormalMatrix.getNormalMatrix( viewMatrix );
  16435. if ( dstArray === null || dstArray.length < flatSize ) {
  16436. dstArray = new Float32Array( flatSize );
  16437. }
  16438. for ( var i = 0, i4 = dstOffset;
  16439. i !== nPlanes; ++ i, i4 += 4 ) {
  16440. plane.copy( planes[ i ] ).
  16441. applyMatrix4( viewMatrix, viewNormalMatrix );
  16442. plane.normal.toArray( dstArray, i4 );
  16443. dstArray[ i4 + 3 ] = plane.constant;
  16444. }
  16445. }
  16446. uniform.value = dstArray;
  16447. uniform.needsUpdate = true;
  16448. }
  16449. scope.numPlanes = nPlanes;
  16450. return dstArray;
  16451. }
  16452. };
  16453. // File:src/renderers/webgl/WebGLIndexedBufferRenderer.js
  16454. /**
  16455. * @author mrdoob / http://mrdoob.com/
  16456. */
  16457. THREE.WebGLIndexedBufferRenderer = function ( _gl, extensions, _infoRender ) {
  16458. var mode;
  16459. function setMode( value ) {
  16460. mode = value;
  16461. }
  16462. var type, size;
  16463. function setIndex( index ) {
  16464. if ( index.array instanceof Uint32Array && extensions.get( 'OES_element_index_uint' ) ) {
  16465. type = _gl.UNSIGNED_INT;
  16466. size = 4;
  16467. } else {
  16468. type = _gl.UNSIGNED_SHORT;
  16469. size = 2;
  16470. }
  16471. }
  16472. function render( start, count ) {
  16473. _gl.drawElements( mode, count, type, start * size );
  16474. _infoRender.calls ++;
  16475. _infoRender.vertices += count;
  16476. if ( mode === _gl.TRIANGLES ) _infoRender.faces += count / 3;
  16477. }
  16478. function renderInstances( geometry, start, count ) {
  16479. var extension = extensions.get( 'ANGLE_instanced_arrays' );
  16480. if ( extension === null ) {
  16481. console.error( 'THREE.WebGLBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  16482. return;
  16483. }
  16484. extension.drawElementsInstancedANGLE( mode, count, type, start * size, geometry.maxInstancedCount );
  16485. _infoRender.calls ++;
  16486. _infoRender.vertices += count * geometry.maxInstancedCount;
  16487. if ( mode === _gl.TRIANGLES ) _infoRender.faces += geometry.maxInstancedCount * count / 3;
  16488. }
  16489. this.setMode = setMode;
  16490. this.setIndex = setIndex;
  16491. this.render = render;
  16492. this.renderInstances = renderInstances;
  16493. };
  16494. // File:src/renderers/webgl/WebGLExtensions.js
  16495. /**
  16496. * @author mrdoob / http://mrdoob.com/
  16497. */
  16498. THREE.WebGLExtensions = function ( gl ) {
  16499. var extensions = {};
  16500. this.get = function ( name ) {
  16501. if ( extensions[ name ] !== undefined ) {
  16502. return extensions[ name ];
  16503. }
  16504. var extension;
  16505. switch ( name ) {
  16506. case 'WEBGL_depth_texture':
  16507. extension = gl.getExtension( 'WEBGL_depth_texture' ) || gl.getExtension( 'MOZ_WEBGL_depth_texture' ) || gl.getExtension( 'WEBKIT_WEBGL_depth_texture' );
  16508. break;
  16509. case 'EXT_texture_filter_anisotropic':
  16510. extension = gl.getExtension( 'EXT_texture_filter_anisotropic' ) || gl.getExtension( 'MOZ_EXT_texture_filter_anisotropic' ) || gl.getExtension( 'WEBKIT_EXT_texture_filter_anisotropic' );
  16511. break;
  16512. case 'WEBGL_compressed_texture_s3tc':
  16513. extension = gl.getExtension( 'WEBGL_compressed_texture_s3tc' ) || gl.getExtension( 'MOZ_WEBGL_compressed_texture_s3tc' ) || gl.getExtension( 'WEBKIT_WEBGL_compressed_texture_s3tc' );
  16514. break;
  16515. case 'WEBGL_compressed_texture_pvrtc':
  16516. extension = gl.getExtension( 'WEBGL_compressed_texture_pvrtc' ) || gl.getExtension( 'WEBKIT_WEBGL_compressed_texture_pvrtc' );
  16517. break;
  16518. case 'WEBGL_compressed_texture_etc1':
  16519. extension = gl.getExtension( 'WEBGL_compressed_texture_etc1' );
  16520. break;
  16521. default:
  16522. extension = gl.getExtension( name );
  16523. }
  16524. if ( extension === null ) {
  16525. console.warn( 'THREE.WebGLRenderer: ' + name + ' extension not supported.' );
  16526. }
  16527. extensions[ name ] = extension;
  16528. return extension;
  16529. };
  16530. };
  16531. // File:src/renderers/webgl/WebGLCapabilities.js
  16532. THREE.WebGLCapabilities = function ( gl, extensions, parameters ) {
  16533. var maxAnisotropy;
  16534. function getMaxAnisotropy() {
  16535. if ( maxAnisotropy !== undefined ) return maxAnisotropy;
  16536. var extension = extensions.get( 'EXT_texture_filter_anisotropic' );
  16537. if ( extension !== null ) {
  16538. maxAnisotropy = gl.getParameter( extension.MAX_TEXTURE_MAX_ANISOTROPY_EXT );
  16539. } else {
  16540. maxAnisotropy = 0;
  16541. }
  16542. return maxAnisotropy;
  16543. }
  16544. function getMaxPrecision( precision ) {
  16545. if ( precision === 'highp' ) {
  16546. if ( gl.getShaderPrecisionFormat( gl.VERTEX_SHADER, gl.HIGH_FLOAT ).precision > 0 &&
  16547. gl.getShaderPrecisionFormat( gl.FRAGMENT_SHADER, gl.HIGH_FLOAT ).precision > 0 ) {
  16548. return 'highp';
  16549. }
  16550. precision = 'mediump';
  16551. }
  16552. if ( precision === 'mediump' ) {
  16553. if ( gl.getShaderPrecisionFormat( gl.VERTEX_SHADER, gl.MEDIUM_FLOAT ).precision > 0 &&
  16554. gl.getShaderPrecisionFormat( gl.FRAGMENT_SHADER, gl.MEDIUM_FLOAT ).precision > 0 ) {
  16555. return 'mediump';
  16556. }
  16557. }
  16558. return 'lowp';
  16559. }
  16560. this.getMaxAnisotropy = getMaxAnisotropy;
  16561. this.getMaxPrecision = getMaxPrecision;
  16562. this.precision = parameters.precision !== undefined ? parameters.precision : 'highp';
  16563. this.logarithmicDepthBuffer = parameters.logarithmicDepthBuffer !== undefined ? parameters.logarithmicDepthBuffer : false;
  16564. this.maxTextures = gl.getParameter( gl.MAX_TEXTURE_IMAGE_UNITS );
  16565. this.maxVertexTextures = gl.getParameter( gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS );
  16566. this.maxTextureSize = gl.getParameter( gl.MAX_TEXTURE_SIZE );
  16567. this.maxCubemapSize = gl.getParameter( gl.MAX_CUBE_MAP_TEXTURE_SIZE );
  16568. this.maxAttributes = gl.getParameter( gl.MAX_VERTEX_ATTRIBS );
  16569. this.maxVertexUniforms = gl.getParameter( gl.MAX_VERTEX_UNIFORM_VECTORS );
  16570. this.maxVaryings = gl.getParameter( gl.MAX_VARYING_VECTORS );
  16571. this.maxFragmentUniforms = gl.getParameter( gl.MAX_FRAGMENT_UNIFORM_VECTORS );
  16572. this.vertexTextures = this.maxVertexTextures > 0;
  16573. this.floatFragmentTextures = !! extensions.get( 'OES_texture_float' );
  16574. this.floatVertexTextures = this.vertexTextures && this.floatFragmentTextures;
  16575. var _maxPrecision = getMaxPrecision( this.precision );
  16576. if ( _maxPrecision !== this.precision ) {
  16577. console.warn( 'THREE.WebGLRenderer:', this.precision, 'not supported, using', _maxPrecision, 'instead.' );
  16578. this.precision = _maxPrecision;
  16579. }
  16580. if ( this.logarithmicDepthBuffer ) {
  16581. this.logarithmicDepthBuffer = !! extensions.get( 'EXT_frag_depth' );
  16582. }
  16583. };
  16584. // File:src/renderers/webgl/WebGLGeometries.js
  16585. /**
  16586. * @author mrdoob / http://mrdoob.com/
  16587. */
  16588. THREE.WebGLGeometries = function ( gl, properties, info ) {
  16589. var geometries = {};
  16590. function get( object ) {
  16591. var geometry = object.geometry;
  16592. if ( geometries[ geometry.id ] !== undefined ) {
  16593. return geometries[ geometry.id ];
  16594. }
  16595. geometry.addEventListener( 'dispose', onGeometryDispose );
  16596. var buffergeometry;
  16597. if ( geometry instanceof THREE.BufferGeometry ) {
  16598. buffergeometry = geometry;
  16599. } else if ( geometry instanceof THREE.Geometry ) {
  16600. if ( geometry._bufferGeometry === undefined ) {
  16601. geometry._bufferGeometry = new THREE.BufferGeometry().setFromObject( object );
  16602. }
  16603. buffergeometry = geometry._bufferGeometry;
  16604. }
  16605. geometries[ geometry.id ] = buffergeometry;
  16606. info.memory.geometries ++;
  16607. return buffergeometry;
  16608. }
  16609. function onGeometryDispose( event ) {
  16610. var geometry = event.target;
  16611. var buffergeometry = geometries[ geometry.id ];
  16612. if ( buffergeometry.index !== null ) {
  16613. deleteAttribute( buffergeometry.index );
  16614. }
  16615. deleteAttributes( buffergeometry.attributes );
  16616. geometry.removeEventListener( 'dispose', onGeometryDispose );
  16617. delete geometries[ geometry.id ];
  16618. // TODO
  16619. var property = properties.get( geometry );
  16620. if ( property.wireframe ) {
  16621. deleteAttribute( property.wireframe );
  16622. }
  16623. properties.delete( geometry );
  16624. var bufferproperty = properties.get( buffergeometry );
  16625. if ( bufferproperty.wireframe ) {
  16626. deleteAttribute( bufferproperty.wireframe );
  16627. }
  16628. properties.delete( buffergeometry );
  16629. //
  16630. info.memory.geometries --;
  16631. }
  16632. function getAttributeBuffer( attribute ) {
  16633. if ( attribute instanceof THREE.InterleavedBufferAttribute ) {
  16634. return properties.get( attribute.data ).__webglBuffer;
  16635. }
  16636. return properties.get( attribute ).__webglBuffer;
  16637. }
  16638. function deleteAttribute( attribute ) {
  16639. var buffer = getAttributeBuffer( attribute );
  16640. if ( buffer !== undefined ) {
  16641. gl.deleteBuffer( buffer );
  16642. removeAttributeBuffer( attribute );
  16643. }
  16644. }
  16645. function deleteAttributes( attributes ) {
  16646. for ( var name in attributes ) {
  16647. deleteAttribute( attributes[ name ] );
  16648. }
  16649. }
  16650. function removeAttributeBuffer( attribute ) {
  16651. if ( attribute instanceof THREE.InterleavedBufferAttribute ) {
  16652. properties.delete( attribute.data );
  16653. } else {
  16654. properties.delete( attribute );
  16655. }
  16656. }
  16657. this.get = get;
  16658. };
  16659. // File:src/renderers/webgl/WebGLLights.js
  16660. /**
  16661. * @author mrdoob / http://mrdoob.com/
  16662. */
  16663. THREE.WebGLLights = function () {
  16664. var lights = {};
  16665. this.get = function ( light ) {
  16666. if ( lights[ light.id ] !== undefined ) {
  16667. return lights[ light.id ];
  16668. }
  16669. var uniforms;
  16670. switch ( light.type ) {
  16671. case 'DirectionalLight':
  16672. uniforms = {
  16673. direction: new THREE.Vector3(),
  16674. color: new THREE.Color(),
  16675. shadow: false,
  16676. shadowBias: 0,
  16677. shadowRadius: 1,
  16678. shadowMapSize: new THREE.Vector2()
  16679. };
  16680. break;
  16681. case 'SpotLight':
  16682. uniforms = {
  16683. position: new THREE.Vector3(),
  16684. direction: new THREE.Vector3(),
  16685. color: new THREE.Color(),
  16686. distance: 0,
  16687. coneCos: 0,
  16688. penumbraCos: 0,
  16689. decay: 0,
  16690. shadow: false,
  16691. shadowBias: 0,
  16692. shadowRadius: 1,
  16693. shadowMapSize: new THREE.Vector2()
  16694. };
  16695. break;
  16696. case 'PointLight':
  16697. uniforms = {
  16698. position: new THREE.Vector3(),
  16699. color: new THREE.Color(),
  16700. distance: 0,
  16701. decay: 0,
  16702. shadow: false,
  16703. shadowBias: 0,
  16704. shadowRadius: 1,
  16705. shadowMapSize: new THREE.Vector2()
  16706. };
  16707. break;
  16708. case 'HemisphereLight':
  16709. uniforms = {
  16710. direction: new THREE.Vector3(),
  16711. skyColor: new THREE.Color(),
  16712. groundColor: new THREE.Color()
  16713. };
  16714. break;
  16715. }
  16716. lights[ light.id ] = uniforms;
  16717. return uniforms;
  16718. };
  16719. };
  16720. // File:src/renderers/webgl/WebGLObjects.js
  16721. /**
  16722. * @author mrdoob / http://mrdoob.com/
  16723. */
  16724. THREE.WebGLObjects = function ( gl, properties, info ) {
  16725. var geometries = new THREE.WebGLGeometries( gl, properties, info );
  16726. //
  16727. function update( object ) {
  16728. // TODO: Avoid updating twice (when using shadowMap). Maybe add frame counter.
  16729. var geometry = geometries.get( object );
  16730. if ( object.geometry instanceof THREE.Geometry ) {
  16731. geometry.updateFromObject( object );
  16732. }
  16733. var index = geometry.index;
  16734. var attributes = geometry.attributes;
  16735. if ( index !== null ) {
  16736. updateAttribute( index, gl.ELEMENT_ARRAY_BUFFER );
  16737. }
  16738. for ( var name in attributes ) {
  16739. updateAttribute( attributes[ name ], gl.ARRAY_BUFFER );
  16740. }
  16741. // morph targets
  16742. var morphAttributes = geometry.morphAttributes;
  16743. for ( var name in morphAttributes ) {
  16744. var array = morphAttributes[ name ];
  16745. for ( var i = 0, l = array.length; i < l; i ++ ) {
  16746. updateAttribute( array[ i ], gl.ARRAY_BUFFER );
  16747. }
  16748. }
  16749. return geometry;
  16750. }
  16751. function updateAttribute( attribute, bufferType ) {
  16752. var data = ( attribute instanceof THREE.InterleavedBufferAttribute ) ? attribute.data : attribute;
  16753. var attributeProperties = properties.get( data );
  16754. if ( attributeProperties.__webglBuffer === undefined ) {
  16755. createBuffer( attributeProperties, data, bufferType );
  16756. } else if ( attributeProperties.version !== data.version ) {
  16757. updateBuffer( attributeProperties, data, bufferType );
  16758. }
  16759. }
  16760. function createBuffer( attributeProperties, data, bufferType ) {
  16761. attributeProperties.__webglBuffer = gl.createBuffer();
  16762. gl.bindBuffer( bufferType, attributeProperties.__webglBuffer );
  16763. var usage = data.dynamic ? gl.DYNAMIC_DRAW : gl.STATIC_DRAW;
  16764. gl.bufferData( bufferType, data.array, usage );
  16765. attributeProperties.version = data.version;
  16766. }
  16767. function updateBuffer( attributeProperties, data, bufferType ) {
  16768. gl.bindBuffer( bufferType, attributeProperties.__webglBuffer );
  16769. if ( data.dynamic === false || data.updateRange.count === - 1 ) {
  16770. // Not using update ranges
  16771. gl.bufferSubData( bufferType, 0, data.array );
  16772. } else if ( data.updateRange.count === 0 ) {
  16773. 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.' );
  16774. } else {
  16775. gl.bufferSubData( bufferType, data.updateRange.offset * data.array.BYTES_PER_ELEMENT,
  16776. data.array.subarray( data.updateRange.offset, data.updateRange.offset + data.updateRange.count ) );
  16777. data.updateRange.count = 0; // reset range
  16778. }
  16779. attributeProperties.version = data.version;
  16780. }
  16781. function getAttributeBuffer( attribute ) {
  16782. if ( attribute instanceof THREE.InterleavedBufferAttribute ) {
  16783. return properties.get( attribute.data ).__webglBuffer;
  16784. }
  16785. return properties.get( attribute ).__webglBuffer;
  16786. }
  16787. function getWireframeAttribute( geometry ) {
  16788. var property = properties.get( geometry );
  16789. if ( property.wireframe !== undefined ) {
  16790. return property.wireframe;
  16791. }
  16792. var indices = [];
  16793. var index = geometry.index;
  16794. var attributes = geometry.attributes;
  16795. var position = attributes.position;
  16796. // console.time( 'wireframe' );
  16797. if ( index !== null ) {
  16798. var edges = {};
  16799. var array = index.array;
  16800. for ( var i = 0, l = array.length; i < l; i += 3 ) {
  16801. var a = array[ i + 0 ];
  16802. var b = array[ i + 1 ];
  16803. var c = array[ i + 2 ];
  16804. if ( checkEdge( edges, a, b ) ) indices.push( a, b );
  16805. if ( checkEdge( edges, b, c ) ) indices.push( b, c );
  16806. if ( checkEdge( edges, c, a ) ) indices.push( c, a );
  16807. }
  16808. } else {
  16809. var array = attributes.position.array;
  16810. for ( var i = 0, l = ( array.length / 3 ) - 1; i < l; i += 3 ) {
  16811. var a = i + 0;
  16812. var b = i + 1;
  16813. var c = i + 2;
  16814. indices.push( a, b, b, c, c, a );
  16815. }
  16816. }
  16817. // console.timeEnd( 'wireframe' );
  16818. var TypeArray = position.count > 65535 ? Uint32Array : Uint16Array;
  16819. var attribute = new THREE.BufferAttribute( new TypeArray( indices ), 1 );
  16820. updateAttribute( attribute, gl.ELEMENT_ARRAY_BUFFER );
  16821. property.wireframe = attribute;
  16822. return attribute;
  16823. }
  16824. function checkEdge( edges, a, b ) {
  16825. if ( a > b ) {
  16826. var tmp = a;
  16827. a = b;
  16828. b = tmp;
  16829. }
  16830. var list = edges[ a ];
  16831. if ( list === undefined ) {
  16832. edges[ a ] = [ b ];
  16833. return true;
  16834. } else if ( list.indexOf( b ) === -1 ) {
  16835. list.push( b );
  16836. return true;
  16837. }
  16838. return false;
  16839. }
  16840. this.getAttributeBuffer = getAttributeBuffer;
  16841. this.getWireframeAttribute = getWireframeAttribute;
  16842. this.update = update;
  16843. };
  16844. // File:src/renderers/webgl/WebGLProgram.js
  16845. THREE.WebGLProgram = ( function () {
  16846. var programIdCount = 0;
  16847. function getEncodingComponents( encoding ) {
  16848. switch ( encoding ) {
  16849. case THREE.LinearEncoding:
  16850. return [ 'Linear','( value )' ];
  16851. case THREE.sRGBEncoding:
  16852. return [ 'sRGB','( value )' ];
  16853. case THREE.RGBEEncoding:
  16854. return [ 'RGBE','( value )' ];
  16855. case THREE.RGBM7Encoding:
  16856. return [ 'RGBM','( value, 7.0 )' ];
  16857. case THREE.RGBM16Encoding:
  16858. return [ 'RGBM','( value, 16.0 )' ];
  16859. case THREE.RGBDEncoding:
  16860. return [ 'RGBD','( value, 256.0 )' ];
  16861. case THREE.GammaEncoding:
  16862. return [ 'Gamma','( value, float( GAMMA_FACTOR ) )' ];
  16863. default:
  16864. throw new Error( 'unsupported encoding: ' + encoding );
  16865. }
  16866. }
  16867. function getTexelDecodingFunction( functionName, encoding ) {
  16868. var components = getEncodingComponents( encoding );
  16869. return "vec4 " + functionName + "( vec4 value ) { return " + components[ 0 ] + "ToLinear" + components[ 1 ] + "; }";
  16870. }
  16871. function getTexelEncodingFunction( functionName, encoding ) {
  16872. var components = getEncodingComponents( encoding );
  16873. return "vec4 " + functionName + "( vec4 value ) { return LinearTo" + components[ 0 ] + components[ 1 ] + "; }";
  16874. }
  16875. function getToneMappingFunction( functionName, toneMapping ) {
  16876. var toneMappingName;
  16877. switch ( toneMapping ) {
  16878. case THREE.LinearToneMapping:
  16879. toneMappingName = "Linear";
  16880. break;
  16881. case THREE.ReinhardToneMapping:
  16882. toneMappingName = "Reinhard";
  16883. break;
  16884. case THREE.Uncharted2ToneMapping:
  16885. toneMappingName = "Uncharted2";
  16886. break;
  16887. case THREE.CineonToneMapping:
  16888. toneMappingName = "OptimizedCineon";
  16889. break;
  16890. default:
  16891. throw new Error( 'unsupported toneMapping: ' + toneMapping );
  16892. }
  16893. return "vec3 " + functionName + "( vec3 color ) { return " + toneMappingName + "ToneMapping( color ); }";
  16894. }
  16895. function generateExtensions( extensions, parameters, rendererExtensions ) {
  16896. extensions = extensions || {};
  16897. var chunks = [
  16898. ( extensions.derivatives || parameters.envMapCubeUV || parameters.bumpMap || parameters.normalMap || parameters.flatShading ) ? '#extension GL_OES_standard_derivatives : enable' : '',
  16899. ( extensions.fragDepth || parameters.logarithmicDepthBuffer ) && rendererExtensions.get( 'EXT_frag_depth' ) ? '#extension GL_EXT_frag_depth : enable' : '',
  16900. ( extensions.drawBuffers ) && rendererExtensions.get( 'WEBGL_draw_buffers' ) ? '#extension GL_EXT_draw_buffers : require' : '',
  16901. ( extensions.shaderTextureLOD || parameters.envMap ) && rendererExtensions.get( 'EXT_shader_texture_lod' ) ? '#extension GL_EXT_shader_texture_lod : enable' : '',
  16902. ];
  16903. return chunks.filter( filterEmptyLine ).join( '\n' );
  16904. }
  16905. function generateDefines( defines ) {
  16906. var chunks = [];
  16907. for ( var name in defines ) {
  16908. var value = defines[ name ];
  16909. if ( value === false ) continue;
  16910. chunks.push( '#define ' + name + ' ' + value );
  16911. }
  16912. return chunks.join( '\n' );
  16913. }
  16914. function fetchAttributeLocations( gl, program, identifiers ) {
  16915. var attributes = {};
  16916. var n = gl.getProgramParameter( program, gl.ACTIVE_ATTRIBUTES );
  16917. for ( var i = 0; i < n; i ++ ) {
  16918. var info = gl.getActiveAttrib( program, i );
  16919. var name = info.name;
  16920. // console.log("THREE.WebGLProgram: ACTIVE VERTEX ATTRIBUTE:", name, i );
  16921. attributes[ name ] = gl.getAttribLocation( program, name );
  16922. }
  16923. return attributes;
  16924. }
  16925. function filterEmptyLine( string ) {
  16926. return string !== '';
  16927. }
  16928. function replaceLightNums( string, parameters ) {
  16929. return string
  16930. .replace( /NUM_DIR_LIGHTS/g, parameters.numDirLights )
  16931. .replace( /NUM_SPOT_LIGHTS/g, parameters.numSpotLights )
  16932. .replace( /NUM_POINT_LIGHTS/g, parameters.numPointLights )
  16933. .replace( /NUM_HEMI_LIGHTS/g, parameters.numHemiLights );
  16934. }
  16935. function parseIncludes( string ) {
  16936. var pattern = /#include +<([\w\d.]+)>/g;
  16937. function replace( match, include ) {
  16938. var replace = THREE.ShaderChunk[ include ];
  16939. if ( replace === undefined ) {
  16940. throw new Error( 'Can not resolve #include <' + include + '>' );
  16941. }
  16942. return parseIncludes( replace );
  16943. }
  16944. return string.replace( pattern, replace );
  16945. }
  16946. function unrollLoops( string ) {
  16947. var pattern = /for \( int i \= (\d+)\; i < (\d+)\; i \+\+ \) \{([\s\S]+?)(?=\})\}/g;
  16948. function replace( match, start, end, snippet ) {
  16949. var unroll = '';
  16950. for ( var i = parseInt( start ); i < parseInt( end ); i ++ ) {
  16951. unroll += snippet.replace( /\[ i \]/g, '[ ' + i + ' ]' );
  16952. }
  16953. return unroll;
  16954. }
  16955. return string.replace( pattern, replace );
  16956. }
  16957. return function WebGLProgram( renderer, code, material, parameters ) {
  16958. var gl = renderer.context;
  16959. var extensions = material.extensions;
  16960. var defines = material.defines;
  16961. var vertexShader = material.__webglShader.vertexShader;
  16962. var fragmentShader = material.__webglShader.fragmentShader;
  16963. var shadowMapTypeDefine = 'SHADOWMAP_TYPE_BASIC';
  16964. if ( parameters.shadowMapType === THREE.PCFShadowMap ) {
  16965. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF';
  16966. } else if ( parameters.shadowMapType === THREE.PCFSoftShadowMap ) {
  16967. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF_SOFT';
  16968. }
  16969. var envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  16970. var envMapModeDefine = 'ENVMAP_MODE_REFLECTION';
  16971. var envMapBlendingDefine = 'ENVMAP_BLENDING_MULTIPLY';
  16972. if ( parameters.envMap ) {
  16973. switch ( material.envMap.mapping ) {
  16974. case THREE.CubeReflectionMapping:
  16975. case THREE.CubeRefractionMapping:
  16976. envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  16977. break;
  16978. case THREE.CubeUVReflectionMapping:
  16979. case THREE.CubeUVRefractionMapping:
  16980. envMapTypeDefine = 'ENVMAP_TYPE_CUBE_UV';
  16981. break;
  16982. case THREE.EquirectangularReflectionMapping:
  16983. case THREE.EquirectangularRefractionMapping:
  16984. envMapTypeDefine = 'ENVMAP_TYPE_EQUIREC';
  16985. break;
  16986. case THREE.SphericalReflectionMapping:
  16987. envMapTypeDefine = 'ENVMAP_TYPE_SPHERE';
  16988. break;
  16989. }
  16990. switch ( material.envMap.mapping ) {
  16991. case THREE.CubeRefractionMapping:
  16992. case THREE.EquirectangularRefractionMapping:
  16993. envMapModeDefine = 'ENVMAP_MODE_REFRACTION';
  16994. break;
  16995. }
  16996. switch ( material.combine ) {
  16997. case THREE.MultiplyOperation:
  16998. envMapBlendingDefine = 'ENVMAP_BLENDING_MULTIPLY';
  16999. break;
  17000. case THREE.MixOperation:
  17001. envMapBlendingDefine = 'ENVMAP_BLENDING_MIX';
  17002. break;
  17003. case THREE.AddOperation:
  17004. envMapBlendingDefine = 'ENVMAP_BLENDING_ADD';
  17005. break;
  17006. }
  17007. }
  17008. var gammaFactorDefine = ( renderer.gammaFactor > 0 ) ? renderer.gammaFactor : 1.0;
  17009. // console.log( 'building new program ' );
  17010. //
  17011. var customExtensions = generateExtensions( extensions, parameters, renderer.extensions );
  17012. var customDefines = generateDefines( defines );
  17013. //
  17014. var program = gl.createProgram();
  17015. var prefixVertex, prefixFragment;
  17016. if ( material instanceof THREE.RawShaderMaterial ) {
  17017. prefixVertex = [
  17018. customDefines
  17019. ].filter( filterEmptyLine ).join( '\n' );
  17020. prefixFragment = [
  17021. customDefines
  17022. ].filter( filterEmptyLine ).join( '\n' );
  17023. } else {
  17024. prefixVertex = [
  17025. 'precision ' + parameters.precision + ' float;',
  17026. 'precision ' + parameters.precision + ' int;',
  17027. '#define SHADER_NAME ' + material.__webglShader.name,
  17028. customDefines,
  17029. parameters.supportsVertexTextures ? '#define VERTEX_TEXTURES' : '',
  17030. '#define GAMMA_FACTOR ' + gammaFactorDefine,
  17031. '#define MAX_BONES ' + parameters.maxBones,
  17032. parameters.map ? '#define USE_MAP' : '',
  17033. parameters.envMap ? '#define USE_ENVMAP' : '',
  17034. parameters.envMap ? '#define ' + envMapModeDefine : '',
  17035. parameters.lightMap ? '#define USE_LIGHTMAP' : '',
  17036. parameters.aoMap ? '#define USE_AOMAP' : '',
  17037. parameters.emissiveMap ? '#define USE_EMISSIVEMAP' : '',
  17038. parameters.bumpMap ? '#define USE_BUMPMAP' : '',
  17039. parameters.normalMap ? '#define USE_NORMALMAP' : '',
  17040. parameters.displacementMap && parameters.supportsVertexTextures ? '#define USE_DISPLACEMENTMAP' : '',
  17041. parameters.specularMap ? '#define USE_SPECULARMAP' : '',
  17042. parameters.roughnessMap ? '#define USE_ROUGHNESSMAP' : '',
  17043. parameters.metalnessMap ? '#define USE_METALNESSMAP' : '',
  17044. parameters.alphaMap ? '#define USE_ALPHAMAP' : '',
  17045. parameters.vertexColors ? '#define USE_COLOR' : '',
  17046. parameters.flatShading ? '#define FLAT_SHADED' : '',
  17047. parameters.skinning ? '#define USE_SKINNING' : '',
  17048. parameters.useVertexTexture ? '#define BONE_TEXTURE' : '',
  17049. parameters.morphTargets ? '#define USE_MORPHTARGETS' : '',
  17050. parameters.morphNormals && parameters.flatShading === false ? '#define USE_MORPHNORMALS' : '',
  17051. parameters.doubleSided ? '#define DOUBLE_SIDED' : '',
  17052. parameters.flipSided ? '#define FLIP_SIDED' : '',
  17053. '#define NUM_CLIPPING_PLANES ' + parameters.numClippingPlanes,
  17054. parameters.shadowMapEnabled ? '#define USE_SHADOWMAP' : '',
  17055. parameters.shadowMapEnabled ? '#define ' + shadowMapTypeDefine : '',
  17056. parameters.sizeAttenuation ? '#define USE_SIZEATTENUATION' : '',
  17057. parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
  17058. parameters.logarithmicDepthBuffer && renderer.extensions.get( 'EXT_frag_depth' ) ? '#define USE_LOGDEPTHBUF_EXT' : '',
  17059. 'uniform mat4 modelMatrix;',
  17060. 'uniform mat4 modelViewMatrix;',
  17061. 'uniform mat4 projectionMatrix;',
  17062. 'uniform mat4 viewMatrix;',
  17063. 'uniform mat3 normalMatrix;',
  17064. 'uniform vec3 cameraPosition;',
  17065. 'attribute vec3 position;',
  17066. 'attribute vec3 normal;',
  17067. 'attribute vec2 uv;',
  17068. '#ifdef USE_COLOR',
  17069. ' attribute vec3 color;',
  17070. '#endif',
  17071. '#ifdef USE_MORPHTARGETS',
  17072. ' attribute vec3 morphTarget0;',
  17073. ' attribute vec3 morphTarget1;',
  17074. ' attribute vec3 morphTarget2;',
  17075. ' attribute vec3 morphTarget3;',
  17076. ' #ifdef USE_MORPHNORMALS',
  17077. ' attribute vec3 morphNormal0;',
  17078. ' attribute vec3 morphNormal1;',
  17079. ' attribute vec3 morphNormal2;',
  17080. ' attribute vec3 morphNormal3;',
  17081. ' #else',
  17082. ' attribute vec3 morphTarget4;',
  17083. ' attribute vec3 morphTarget5;',
  17084. ' attribute vec3 morphTarget6;',
  17085. ' attribute vec3 morphTarget7;',
  17086. ' #endif',
  17087. '#endif',
  17088. '#ifdef USE_SKINNING',
  17089. ' attribute vec4 skinIndex;',
  17090. ' attribute vec4 skinWeight;',
  17091. '#endif',
  17092. '\n'
  17093. ].filter( filterEmptyLine ).join( '\n' );
  17094. prefixFragment = [
  17095. customExtensions,
  17096. 'precision ' + parameters.precision + ' float;',
  17097. 'precision ' + parameters.precision + ' int;',
  17098. '#define SHADER_NAME ' + material.__webglShader.name,
  17099. customDefines,
  17100. parameters.alphaTest ? '#define ALPHATEST ' + parameters.alphaTest : '',
  17101. '#define GAMMA_FACTOR ' + gammaFactorDefine,
  17102. ( parameters.useFog && parameters.fog ) ? '#define USE_FOG' : '',
  17103. ( parameters.useFog && parameters.fogExp ) ? '#define FOG_EXP2' : '',
  17104. parameters.map ? '#define USE_MAP' : '',
  17105. parameters.envMap ? '#define USE_ENVMAP' : '',
  17106. parameters.envMap ? '#define ' + envMapTypeDefine : '',
  17107. parameters.envMap ? '#define ' + envMapModeDefine : '',
  17108. parameters.envMap ? '#define ' + envMapBlendingDefine : '',
  17109. parameters.lightMap ? '#define USE_LIGHTMAP' : '',
  17110. parameters.aoMap ? '#define USE_AOMAP' : '',
  17111. parameters.emissiveMap ? '#define USE_EMISSIVEMAP' : '',
  17112. parameters.bumpMap ? '#define USE_BUMPMAP' : '',
  17113. parameters.normalMap ? '#define USE_NORMALMAP' : '',
  17114. parameters.specularMap ? '#define USE_SPECULARMAP' : '',
  17115. parameters.roughnessMap ? '#define USE_ROUGHNESSMAP' : '',
  17116. parameters.metalnessMap ? '#define USE_METALNESSMAP' : '',
  17117. parameters.alphaMap ? '#define USE_ALPHAMAP' : '',
  17118. parameters.vertexColors ? '#define USE_COLOR' : '',
  17119. parameters.flatShading ? '#define FLAT_SHADED' : '',
  17120. parameters.doubleSided ? '#define DOUBLE_SIDED' : '',
  17121. parameters.flipSided ? '#define FLIP_SIDED' : '',
  17122. '#define NUM_CLIPPING_PLANES ' + parameters.numClippingPlanes,
  17123. parameters.shadowMapEnabled ? '#define USE_SHADOWMAP' : '',
  17124. parameters.shadowMapEnabled ? '#define ' + shadowMapTypeDefine : '',
  17125. parameters.premultipliedAlpha ? "#define PREMULTIPLIED_ALPHA" : '',
  17126. parameters.physicallyCorrectLights ? "#define PHYSICALLY_CORRECT_LIGHTS" : '',
  17127. parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
  17128. parameters.logarithmicDepthBuffer && renderer.extensions.get( 'EXT_frag_depth' ) ? '#define USE_LOGDEPTHBUF_EXT' : '',
  17129. parameters.envMap && renderer.extensions.get( 'EXT_shader_texture_lod' ) ? '#define TEXTURE_LOD_EXT' : '',
  17130. 'uniform mat4 viewMatrix;',
  17131. 'uniform vec3 cameraPosition;',
  17132. ( parameters.toneMapping !== THREE.NoToneMapping ) ? "#define TONE_MAPPING" : '',
  17133. ( parameters.toneMapping !== THREE.NoToneMapping ) ? THREE.ShaderChunk[ 'tonemapping_pars_fragment' ] : '', // this code is required here because it is used by the toneMapping() function defined below
  17134. ( parameters.toneMapping !== THREE.NoToneMapping ) ? getToneMappingFunction( "toneMapping", parameters.toneMapping ) : '',
  17135. ( 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
  17136. parameters.mapEncoding ? getTexelDecodingFunction( 'mapTexelToLinear', parameters.mapEncoding ) : '',
  17137. parameters.envMapEncoding ? getTexelDecodingFunction( 'envMapTexelToLinear', parameters.envMapEncoding ) : '',
  17138. parameters.emissiveMapEncoding ? getTexelDecodingFunction( 'emissiveMapTexelToLinear', parameters.emissiveMapEncoding ) : '',
  17139. parameters.outputEncoding ? getTexelEncodingFunction( "linearToOutputTexel", parameters.outputEncoding ) : '',
  17140. parameters.depthPacking ? "#define DEPTH_PACKING " + material.depthPacking : '',
  17141. '\n'
  17142. ].filter( filterEmptyLine ).join( '\n' );
  17143. }
  17144. vertexShader = parseIncludes( vertexShader, parameters );
  17145. vertexShader = replaceLightNums( vertexShader, parameters );
  17146. fragmentShader = parseIncludes( fragmentShader, parameters );
  17147. fragmentShader = replaceLightNums( fragmentShader, parameters );
  17148. if ( material instanceof THREE.ShaderMaterial === false ) {
  17149. vertexShader = unrollLoops( vertexShader );
  17150. fragmentShader = unrollLoops( fragmentShader );
  17151. }
  17152. var vertexGlsl = prefixVertex + vertexShader;
  17153. var fragmentGlsl = prefixFragment + fragmentShader;
  17154. // console.log( '*VERTEX*', vertexGlsl );
  17155. // console.log( '*FRAGMENT*', fragmentGlsl );
  17156. var glVertexShader = THREE.WebGLShader( gl, gl.VERTEX_SHADER, vertexGlsl );
  17157. var glFragmentShader = THREE.WebGLShader( gl, gl.FRAGMENT_SHADER, fragmentGlsl );
  17158. gl.attachShader( program, glVertexShader );
  17159. gl.attachShader( program, glFragmentShader );
  17160. // Force a particular attribute to index 0.
  17161. if ( material.index0AttributeName !== undefined ) {
  17162. gl.bindAttribLocation( program, 0, material.index0AttributeName );
  17163. } else if ( parameters.morphTargets === true ) {
  17164. // programs with morphTargets displace position out of attribute 0
  17165. gl.bindAttribLocation( program, 0, 'position' );
  17166. }
  17167. gl.linkProgram( program );
  17168. var programLog = gl.getProgramInfoLog( program );
  17169. var vertexLog = gl.getShaderInfoLog( glVertexShader );
  17170. var fragmentLog = gl.getShaderInfoLog( glFragmentShader );
  17171. var runnable = true;
  17172. var haveDiagnostics = true;
  17173. // console.log( '**VERTEX**', gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( glVertexShader ) );
  17174. // console.log( '**FRAGMENT**', gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( glFragmentShader ) );
  17175. if ( gl.getProgramParameter( program, gl.LINK_STATUS ) === false ) {
  17176. runnable = false;
  17177. console.error( 'THREE.WebGLProgram: shader error: ', gl.getError(), 'gl.VALIDATE_STATUS', gl.getProgramParameter( program, gl.VALIDATE_STATUS ), 'gl.getProgramInfoLog', programLog, vertexLog, fragmentLog );
  17178. } else if ( programLog !== '' ) {
  17179. console.warn( 'THREE.WebGLProgram: gl.getProgramInfoLog()', programLog );
  17180. } else if ( vertexLog === '' || fragmentLog === '' ) {
  17181. haveDiagnostics = false;
  17182. }
  17183. if ( haveDiagnostics ) {
  17184. this.diagnostics = {
  17185. runnable: runnable,
  17186. material: material,
  17187. programLog: programLog,
  17188. vertexShader: {
  17189. log: vertexLog,
  17190. prefix: prefixVertex
  17191. },
  17192. fragmentShader: {
  17193. log: fragmentLog,
  17194. prefix: prefixFragment
  17195. }
  17196. };
  17197. }
  17198. // clean up
  17199. gl.deleteShader( glVertexShader );
  17200. gl.deleteShader( glFragmentShader );
  17201. // set up caching for uniform locations
  17202. var cachedUniforms;
  17203. this.getUniforms = function() {
  17204. if ( cachedUniforms === undefined ) {
  17205. cachedUniforms =
  17206. new THREE.WebGLUniforms( gl, program, renderer );
  17207. }
  17208. return cachedUniforms;
  17209. };
  17210. // set up caching for attribute locations
  17211. var cachedAttributes;
  17212. this.getAttributes = function() {
  17213. if ( cachedAttributes === undefined ) {
  17214. cachedAttributes = fetchAttributeLocations( gl, program );
  17215. }
  17216. return cachedAttributes;
  17217. };
  17218. // free resource
  17219. this.destroy = function() {
  17220. gl.deleteProgram( program );
  17221. this.program = undefined;
  17222. };
  17223. // DEPRECATED
  17224. Object.defineProperties( this, {
  17225. uniforms: {
  17226. get: function() {
  17227. console.warn( 'THREE.WebGLProgram: .uniforms is now .getUniforms().' );
  17228. return this.getUniforms();
  17229. }
  17230. },
  17231. attributes: {
  17232. get: function() {
  17233. console.warn( 'THREE.WebGLProgram: .attributes is now .getAttributes().' );
  17234. return this.getAttributes();
  17235. }
  17236. }
  17237. } );
  17238. //
  17239. this.id = programIdCount ++;
  17240. this.code = code;
  17241. this.usedTimes = 1;
  17242. this.program = program;
  17243. this.vertexShader = glVertexShader;
  17244. this.fragmentShader = glFragmentShader;
  17245. return this;
  17246. };
  17247. } )();
  17248. // File:src/renderers/webgl/WebGLPrograms.js
  17249. THREE.WebGLPrograms = function ( renderer, capabilities ) {
  17250. var programs = [];
  17251. var shaderIDs = {
  17252. MeshDepthMaterial: 'depth',
  17253. MeshNormalMaterial: 'normal',
  17254. MeshBasicMaterial: 'basic',
  17255. MeshLambertMaterial: 'lambert',
  17256. MeshPhongMaterial: 'phong',
  17257. MeshStandardMaterial: 'physical',
  17258. MeshPhysicalMaterial: 'physical',
  17259. LineBasicMaterial: 'basic',
  17260. LineDashedMaterial: 'dashed',
  17261. PointsMaterial: 'points'
  17262. };
  17263. var parameterNames = [
  17264. "precision", "supportsVertexTextures", "map", "mapEncoding", "envMap", "envMapMode", "envMapEncoding",
  17265. "lightMap", "aoMap", "emissiveMap", "emissiveMapEncoding", "bumpMap", "normalMap", "displacementMap", "specularMap",
  17266. "roughnessMap", "metalnessMap",
  17267. "alphaMap", "combine", "vertexColors", "fog", "useFog", "fogExp",
  17268. "flatShading", "sizeAttenuation", "logarithmicDepthBuffer", "skinning",
  17269. "maxBones", "useVertexTexture", "morphTargets", "morphNormals",
  17270. "maxMorphTargets", "maxMorphNormals", "premultipliedAlpha",
  17271. "numDirLights", "numPointLights", "numSpotLights", "numHemiLights",
  17272. "shadowMapEnabled", "shadowMapType", "toneMapping", 'physicallyCorrectLights',
  17273. "alphaTest", "doubleSided", "flipSided", "numClippingPlanes", "depthPacking"
  17274. ];
  17275. function allocateBones ( object ) {
  17276. if ( capabilities.floatVertexTextures && object && object.skeleton && object.skeleton.useVertexTexture ) {
  17277. return 1024;
  17278. } else {
  17279. // default for when object is not specified
  17280. // ( for example when prebuilding shader to be used with multiple objects )
  17281. //
  17282. // - leave some extra space for other uniforms
  17283. // - limit here is ANGLE's 254 max uniform vectors
  17284. // (up to 54 should be safe)
  17285. var nVertexUniforms = capabilities.maxVertexUniforms;
  17286. var nVertexMatrices = Math.floor( ( nVertexUniforms - 20 ) / 4 );
  17287. var maxBones = nVertexMatrices;
  17288. if ( object !== undefined && object instanceof THREE.SkinnedMesh ) {
  17289. maxBones = Math.min( object.skeleton.bones.length, maxBones );
  17290. if ( maxBones < object.skeleton.bones.length ) {
  17291. console.warn( 'WebGLRenderer: too many bones - ' + object.skeleton.bones.length + ', this GPU supports just ' + maxBones + ' (try OpenGL instead of ANGLE)' );
  17292. }
  17293. }
  17294. return maxBones;
  17295. }
  17296. }
  17297. function getTextureEncodingFromMap( map, gammaOverrideLinear ) {
  17298. var encoding;
  17299. if ( ! map ) {
  17300. encoding = THREE.LinearEncoding;
  17301. } else if ( map instanceof THREE.Texture ) {
  17302. encoding = map.encoding;
  17303. } else if ( map instanceof THREE.WebGLRenderTarget ) {
  17304. console.warn( "THREE.WebGLPrograms.getTextureEncodingFromMap: don't use render targets as textures. Use their .texture property instead." );
  17305. encoding = map.texture.encoding;
  17306. }
  17307. // add backwards compatibility for WebGLRenderer.gammaInput/gammaOutput parameter, should probably be removed at some point.
  17308. if ( encoding === THREE.LinearEncoding && gammaOverrideLinear ) {
  17309. encoding = THREE.GammaEncoding;
  17310. }
  17311. return encoding;
  17312. }
  17313. this.getParameters = function ( material, lights, fog, nClipPlanes, object ) {
  17314. var shaderID = shaderIDs[ material.type ];
  17315. // heuristics to create shader parameters according to lights in the scene
  17316. // (not to blow over maxLights budget)
  17317. var maxBones = allocateBones( object );
  17318. var precision = renderer.getPrecision();
  17319. if ( material.precision !== null ) {
  17320. precision = capabilities.getMaxPrecision( material.precision );
  17321. if ( precision !== material.precision ) {
  17322. console.warn( 'THREE.WebGLProgram.getParameters:', material.precision, 'not supported, using', precision, 'instead.' );
  17323. }
  17324. }
  17325. var currentRenderTarget = renderer.getCurrentRenderTarget();
  17326. var parameters = {
  17327. shaderID: shaderID,
  17328. precision: precision,
  17329. supportsVertexTextures: capabilities.vertexTextures,
  17330. outputEncoding: getTextureEncodingFromMap( ( ! currentRenderTarget ) ? null : currentRenderTarget.texture, renderer.gammaOutput ),
  17331. map: !! material.map,
  17332. mapEncoding: getTextureEncodingFromMap( material.map, renderer.gammaInput ),
  17333. envMap: !! material.envMap,
  17334. envMapMode: material.envMap && material.envMap.mapping,
  17335. envMapEncoding: getTextureEncodingFromMap( material.envMap, renderer.gammaInput ),
  17336. envMapCubeUV: ( !! material.envMap ) && ( ( material.envMap.mapping === THREE.CubeUVReflectionMapping ) || ( material.envMap.mapping === THREE.CubeUVRefractionMapping ) ),
  17337. lightMap: !! material.lightMap,
  17338. aoMap: !! material.aoMap,
  17339. emissiveMap: !! material.emissiveMap,
  17340. emissiveMapEncoding: getTextureEncodingFromMap( material.emissiveMap, renderer.gammaInput ),
  17341. bumpMap: !! material.bumpMap,
  17342. normalMap: !! material.normalMap,
  17343. displacementMap: !! material.displacementMap,
  17344. roughnessMap: !! material.roughnessMap,
  17345. metalnessMap: !! material.metalnessMap,
  17346. specularMap: !! material.specularMap,
  17347. alphaMap: !! material.alphaMap,
  17348. combine: material.combine,
  17349. vertexColors: material.vertexColors,
  17350. fog: fog,
  17351. useFog: material.fog,
  17352. fogExp: fog instanceof THREE.FogExp2,
  17353. flatShading: material.shading === THREE.FlatShading,
  17354. sizeAttenuation: material.sizeAttenuation,
  17355. logarithmicDepthBuffer: capabilities.logarithmicDepthBuffer,
  17356. skinning: material.skinning,
  17357. maxBones: maxBones,
  17358. useVertexTexture: capabilities.floatVertexTextures && object && object.skeleton && object.skeleton.useVertexTexture,
  17359. morphTargets: material.morphTargets,
  17360. morphNormals: material.morphNormals,
  17361. maxMorphTargets: renderer.maxMorphTargets,
  17362. maxMorphNormals: renderer.maxMorphNormals,
  17363. numDirLights: lights.directional.length,
  17364. numPointLights: lights.point.length,
  17365. numSpotLights: lights.spot.length,
  17366. numHemiLights: lights.hemi.length,
  17367. numClippingPlanes: nClipPlanes,
  17368. shadowMapEnabled: renderer.shadowMap.enabled && object.receiveShadow && lights.shadows.length > 0,
  17369. shadowMapType: renderer.shadowMap.type,
  17370. toneMapping: renderer.toneMapping,
  17371. physicallyCorrectLights: renderer.physicallyCorrectLights,
  17372. premultipliedAlpha: material.premultipliedAlpha,
  17373. alphaTest: material.alphaTest,
  17374. doubleSided: material.side === THREE.DoubleSide,
  17375. flipSided: material.side === THREE.BackSide,
  17376. depthPacking: ( material.depthPacking !== undefined ) ? material.depthPacking : false
  17377. };
  17378. return parameters;
  17379. };
  17380. this.getProgramCode = function ( material, parameters ) {
  17381. var array = [];
  17382. if ( parameters.shaderID ) {
  17383. array.push( parameters.shaderID );
  17384. } else {
  17385. array.push( material.fragmentShader );
  17386. array.push( material.vertexShader );
  17387. }
  17388. if ( material.defines !== undefined ) {
  17389. for ( var name in material.defines ) {
  17390. array.push( name );
  17391. array.push( material.defines[ name ] );
  17392. }
  17393. }
  17394. for ( var i = 0; i < parameterNames.length; i ++ ) {
  17395. array.push( parameters[ parameterNames[ i ] ] );
  17396. }
  17397. return array.join();
  17398. };
  17399. this.acquireProgram = function ( material, parameters, code ) {
  17400. var program;
  17401. // Check if code has been already compiled
  17402. for ( var p = 0, pl = programs.length; p < pl; p ++ ) {
  17403. var programInfo = programs[ p ];
  17404. if ( programInfo.code === code ) {
  17405. program = programInfo;
  17406. ++ program.usedTimes;
  17407. break;
  17408. }
  17409. }
  17410. if ( program === undefined ) {
  17411. program = new THREE.WebGLProgram( renderer, code, material, parameters );
  17412. programs.push( program );
  17413. }
  17414. return program;
  17415. };
  17416. this.releaseProgram = function( program ) {
  17417. if ( -- program.usedTimes === 0 ) {
  17418. // Remove from unordered set
  17419. var i = programs.indexOf( program );
  17420. programs[ i ] = programs[ programs.length - 1 ];
  17421. programs.pop();
  17422. // Free WebGL resources
  17423. program.destroy();
  17424. }
  17425. };
  17426. // Exposed for resource monitoring & error feedback via renderer.info:
  17427. this.programs = programs;
  17428. };
  17429. // File:src/renderers/webgl/WebGLProperties.js
  17430. /**
  17431. * @author fordacious / fordacious.github.io
  17432. */
  17433. THREE.WebGLProperties = function () {
  17434. var properties = {};
  17435. this.get = function ( object ) {
  17436. var uuid = object.uuid;
  17437. var map = properties[ uuid ];
  17438. if ( map === undefined ) {
  17439. map = {};
  17440. properties[ uuid ] = map;
  17441. }
  17442. return map;
  17443. };
  17444. this.delete = function ( object ) {
  17445. delete properties[ object.uuid ];
  17446. };
  17447. this.clear = function () {
  17448. properties = {};
  17449. };
  17450. };
  17451. // File:src/renderers/webgl/WebGLShader.js
  17452. THREE.WebGLShader = ( function () {
  17453. function addLineNumbers( string ) {
  17454. var lines = string.split( '\n' );
  17455. for ( var i = 0; i < lines.length; i ++ ) {
  17456. lines[ i ] = ( i + 1 ) + ': ' + lines[ i ];
  17457. }
  17458. return lines.join( '\n' );
  17459. }
  17460. return function WebGLShader( gl, type, string ) {
  17461. var shader = gl.createShader( type );
  17462. gl.shaderSource( shader, string );
  17463. gl.compileShader( shader );
  17464. if ( gl.getShaderParameter( shader, gl.COMPILE_STATUS ) === false ) {
  17465. console.error( 'THREE.WebGLShader: Shader couldn\'t compile.' );
  17466. }
  17467. if ( gl.getShaderInfoLog( shader ) !== '' ) {
  17468. console.warn( 'THREE.WebGLShader: gl.getShaderInfoLog()', type === gl.VERTEX_SHADER ? 'vertex' : 'fragment', gl.getShaderInfoLog( shader ), addLineNumbers( string ) );
  17469. }
  17470. // --enable-privileged-webgl-extension
  17471. // console.log( type, gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( shader ) );
  17472. return shader;
  17473. };
  17474. } )();
  17475. // File:src/renderers/webgl/WebGLShadowMap.js
  17476. /**
  17477. * @author alteredq / http://alteredqualia.com/
  17478. * @author mrdoob / http://mrdoob.com/
  17479. */
  17480. THREE.WebGLShadowMap = function ( _renderer, _lights, _objects ) {
  17481. var _gl = _renderer.context,
  17482. _state = _renderer.state,
  17483. _frustum = new THREE.Frustum(),
  17484. _projScreenMatrix = new THREE.Matrix4(),
  17485. _lightShadows = _lights.shadows,
  17486. _shadowMapSize = new THREE.Vector2(),
  17487. _lookTarget = new THREE.Vector3(),
  17488. _lightPositionWorld = new THREE.Vector3(),
  17489. _renderList = [],
  17490. _MorphingFlag = 1,
  17491. _SkinningFlag = 2,
  17492. _NumberOfMaterialVariants = ( _MorphingFlag | _SkinningFlag ) + 1,
  17493. _depthMaterials = new Array( _NumberOfMaterialVariants ),
  17494. _distanceMaterials = new Array( _NumberOfMaterialVariants ),
  17495. _materialCache = {};
  17496. var cubeDirections = [
  17497. new THREE.Vector3( 1, 0, 0 ), new THREE.Vector3( - 1, 0, 0 ), new THREE.Vector3( 0, 0, 1 ),
  17498. new THREE.Vector3( 0, 0, - 1 ), new THREE.Vector3( 0, 1, 0 ), new THREE.Vector3( 0, - 1, 0 )
  17499. ];
  17500. var cubeUps = [
  17501. new THREE.Vector3( 0, 1, 0 ), new THREE.Vector3( 0, 1, 0 ), new THREE.Vector3( 0, 1, 0 ),
  17502. new THREE.Vector3( 0, 1, 0 ), new THREE.Vector3( 0, 0, 1 ), new THREE.Vector3( 0, 0, - 1 )
  17503. ];
  17504. var cube2DViewPorts = [
  17505. new THREE.Vector4(), new THREE.Vector4(), new THREE.Vector4(),
  17506. new THREE.Vector4(), new THREE.Vector4(), new THREE.Vector4()
  17507. ];
  17508. // init
  17509. var depthMaterialTemplate = new THREE.MeshDepthMaterial();
  17510. depthMaterialTemplate.depthPacking = THREE.RGBADepthPacking;
  17511. depthMaterialTemplate.clipping = true;
  17512. var distanceShader = THREE.ShaderLib[ "distanceRGBA" ];
  17513. var distanceUniforms = THREE.UniformsUtils.clone( distanceShader.uniforms );
  17514. for ( var i = 0; i !== _NumberOfMaterialVariants; ++ i ) {
  17515. var useMorphing = ( i & _MorphingFlag ) !== 0;
  17516. var useSkinning = ( i & _SkinningFlag ) !== 0;
  17517. var depthMaterial = depthMaterialTemplate.clone();
  17518. depthMaterial.morphTargets = useMorphing;
  17519. depthMaterial.skinning = useSkinning;
  17520. _depthMaterials[ i ] = depthMaterial;
  17521. var distanceMaterial = new THREE.ShaderMaterial( {
  17522. defines: {
  17523. 'USE_SHADOWMAP': ''
  17524. },
  17525. uniforms: distanceUniforms,
  17526. vertexShader: distanceShader.vertexShader,
  17527. fragmentShader: distanceShader.fragmentShader,
  17528. morphTargets: useMorphing,
  17529. skinning: useSkinning,
  17530. clipping: true
  17531. } );
  17532. _distanceMaterials[ i ] = distanceMaterial;
  17533. }
  17534. //
  17535. var scope = this;
  17536. this.enabled = false;
  17537. this.autoUpdate = true;
  17538. this.needsUpdate = false;
  17539. this.type = THREE.PCFShadowMap;
  17540. this.renderReverseSided = true;
  17541. this.renderSingleSided = true;
  17542. this.render = function ( scene, camera ) {
  17543. if ( scope.enabled === false ) return;
  17544. if ( scope.autoUpdate === false && scope.needsUpdate === false ) return;
  17545. if ( _lightShadows.length === 0 ) return;
  17546. // Set GL state for depth map.
  17547. _state.clearColor( 1, 1, 1, 1 );
  17548. _state.disable( _gl.BLEND );
  17549. _state.setDepthTest( true );
  17550. _state.setScissorTest( false );
  17551. // render depth map
  17552. var faceCount, isPointLight;
  17553. for ( var i = 0, il = _lightShadows.length; i < il; i ++ ) {
  17554. var light = _lightShadows[ i ];
  17555. var shadow = light.shadow;
  17556. if ( shadow === undefined ) {
  17557. console.warn( 'THREE.WebGLShadowMap:', light, 'has no shadow.' );
  17558. continue;
  17559. }
  17560. var shadowCamera = shadow.camera;
  17561. _shadowMapSize.copy( shadow.mapSize );
  17562. if ( light instanceof THREE.PointLight ) {
  17563. faceCount = 6;
  17564. isPointLight = true;
  17565. var vpWidth = _shadowMapSize.x;
  17566. var vpHeight = _shadowMapSize.y;
  17567. // These viewports map a cube-map onto a 2D texture with the
  17568. // following orientation:
  17569. //
  17570. // xzXZ
  17571. // y Y
  17572. //
  17573. // X - Positive x direction
  17574. // x - Negative x direction
  17575. // Y - Positive y direction
  17576. // y - Negative y direction
  17577. // Z - Positive z direction
  17578. // z - Negative z direction
  17579. // positive X
  17580. cube2DViewPorts[ 0 ].set( vpWidth * 2, vpHeight, vpWidth, vpHeight );
  17581. // negative X
  17582. cube2DViewPorts[ 1 ].set( 0, vpHeight, vpWidth, vpHeight );
  17583. // positive Z
  17584. cube2DViewPorts[ 2 ].set( vpWidth * 3, vpHeight, vpWidth, vpHeight );
  17585. // negative Z
  17586. cube2DViewPorts[ 3 ].set( vpWidth, vpHeight, vpWidth, vpHeight );
  17587. // positive Y
  17588. cube2DViewPorts[ 4 ].set( vpWidth * 3, 0, vpWidth, vpHeight );
  17589. // negative Y
  17590. cube2DViewPorts[ 5 ].set( vpWidth, 0, vpWidth, vpHeight );
  17591. _shadowMapSize.x *= 4.0;
  17592. _shadowMapSize.y *= 2.0;
  17593. } else {
  17594. faceCount = 1;
  17595. isPointLight = false;
  17596. }
  17597. if ( shadow.map === null ) {
  17598. var pars = { minFilter: THREE.NearestFilter, magFilter: THREE.NearestFilter, format: THREE.RGBAFormat };
  17599. shadow.map = new THREE.WebGLRenderTarget( _shadowMapSize.x, _shadowMapSize.y, pars );
  17600. shadowCamera.updateProjectionMatrix();
  17601. }
  17602. if ( shadow instanceof THREE.SpotLightShadow ) {
  17603. shadow.update( light );
  17604. }
  17605. var shadowMap = shadow.map;
  17606. var shadowMatrix = shadow.matrix;
  17607. _lightPositionWorld.setFromMatrixPosition( light.matrixWorld );
  17608. shadowCamera.position.copy( _lightPositionWorld );
  17609. _renderer.setRenderTarget( shadowMap );
  17610. _renderer.clear();
  17611. // render shadow map for each cube face (if omni-directional) or
  17612. // run a single pass if not
  17613. for ( var face = 0; face < faceCount; face ++ ) {
  17614. if ( isPointLight ) {
  17615. _lookTarget.copy( shadowCamera.position );
  17616. _lookTarget.add( cubeDirections[ face ] );
  17617. shadowCamera.up.copy( cubeUps[ face ] );
  17618. shadowCamera.lookAt( _lookTarget );
  17619. var vpDimensions = cube2DViewPorts[ face ];
  17620. _state.viewport( vpDimensions );
  17621. } else {
  17622. _lookTarget.setFromMatrixPosition( light.target.matrixWorld );
  17623. shadowCamera.lookAt( _lookTarget );
  17624. }
  17625. shadowCamera.updateMatrixWorld();
  17626. shadowCamera.matrixWorldInverse.getInverse( shadowCamera.matrixWorld );
  17627. // compute shadow matrix
  17628. shadowMatrix.set(
  17629. 0.5, 0.0, 0.0, 0.5,
  17630. 0.0, 0.5, 0.0, 0.5,
  17631. 0.0, 0.0, 0.5, 0.5,
  17632. 0.0, 0.0, 0.0, 1.0
  17633. );
  17634. shadowMatrix.multiply( shadowCamera.projectionMatrix );
  17635. shadowMatrix.multiply( shadowCamera.matrixWorldInverse );
  17636. // update camera matrices and frustum
  17637. _projScreenMatrix.multiplyMatrices( shadowCamera.projectionMatrix, shadowCamera.matrixWorldInverse );
  17638. _frustum.setFromMatrix( _projScreenMatrix );
  17639. // set object matrices & frustum culling
  17640. _renderList.length = 0;
  17641. projectObject( scene, camera, shadowCamera );
  17642. // render shadow map
  17643. // render regular objects
  17644. for ( var j = 0, jl = _renderList.length; j < jl; j ++ ) {
  17645. var object = _renderList[ j ];
  17646. var geometry = _objects.update( object );
  17647. var material = object.material;
  17648. if ( material instanceof THREE.MultiMaterial ) {
  17649. var groups = geometry.groups;
  17650. var materials = material.materials;
  17651. for ( var k = 0, kl = groups.length; k < kl; k ++ ) {
  17652. var group = groups[ k ];
  17653. var groupMaterial = materials[ group.materialIndex ];
  17654. if ( groupMaterial.visible === true ) {
  17655. var depthMaterial = getDepthMaterial( object, groupMaterial, isPointLight, _lightPositionWorld );
  17656. _renderer.renderBufferDirect( shadowCamera, null, geometry, depthMaterial, object, group );
  17657. }
  17658. }
  17659. } else {
  17660. var depthMaterial = getDepthMaterial( object, material, isPointLight, _lightPositionWorld );
  17661. _renderer.renderBufferDirect( shadowCamera, null, geometry, depthMaterial, object, null );
  17662. }
  17663. }
  17664. }
  17665. }
  17666. // Restore GL state.
  17667. var clearColor = _renderer.getClearColor(),
  17668. clearAlpha = _renderer.getClearAlpha();
  17669. _renderer.setClearColor( clearColor, clearAlpha );
  17670. scope.needsUpdate = false;
  17671. };
  17672. function getDepthMaterial( object, material, isPointLight, lightPositionWorld ) {
  17673. var geometry = object.geometry;
  17674. var result = null;
  17675. var materialVariants = _depthMaterials;
  17676. var customMaterial = object.customDepthMaterial;
  17677. if ( isPointLight ) {
  17678. materialVariants = _distanceMaterials;
  17679. customMaterial = object.customDistanceMaterial;
  17680. }
  17681. if ( ! customMaterial ) {
  17682. var useMorphing = geometry.morphTargets !== undefined &&
  17683. geometry.morphTargets.length > 0 && material.morphTargets;
  17684. var useSkinning = object instanceof THREE.SkinnedMesh && material.skinning;
  17685. var variantIndex = 0;
  17686. if ( useMorphing ) variantIndex |= _MorphingFlag;
  17687. if ( useSkinning ) variantIndex |= _SkinningFlag;
  17688. result = materialVariants[ variantIndex ];
  17689. } else {
  17690. result = customMaterial;
  17691. }
  17692. if ( _renderer.localClippingEnabled &&
  17693. material.clipShadows === true &&
  17694. material.clippingPlanes.length !== 0 ) {
  17695. // in this case we need a unique material instance reflecting the
  17696. // appropriate state
  17697. var keyA = result.uuid, keyB = material.uuid;
  17698. var materialsForVariant = _materialCache[ keyA ];
  17699. if ( materialsForVariant === undefined ) {
  17700. materialsForVariant = {};
  17701. _materialCache[ keyA ] = materialsForVariant;
  17702. }
  17703. var cachedMaterial = materialsForVariant[ keyB ];
  17704. if ( cachedMaterial === undefined ) {
  17705. cachedMaterial = result.clone();
  17706. materialsForVariant[ keyB ] = cachedMaterial;
  17707. }
  17708. result = cachedMaterial;
  17709. }
  17710. result.visible = material.visible;
  17711. result.wireframe = material.wireframe;
  17712. var side = material.side;
  17713. if ( scope.renderSingleSided && side == THREE.DoubleSide ) {
  17714. side = THREE.FrontSide;
  17715. }
  17716. if ( scope.renderReverseSided ) {
  17717. if ( side === THREE.FrontSide ) side = THREE.BackSide;
  17718. else if ( side === THREE.BackSide ) side = THREE.FrontSide;
  17719. }
  17720. result.side = side;
  17721. result.clipShadows = material.clipShadows;
  17722. result.clippingPlanes = material.clippingPlanes;
  17723. result.wireframeLinewidth = material.wireframeLinewidth;
  17724. result.linewidth = material.linewidth;
  17725. if ( isPointLight && result.uniforms.lightPos !== undefined ) {
  17726. result.uniforms.lightPos.value.copy( lightPositionWorld );
  17727. }
  17728. return result;
  17729. }
  17730. function projectObject( object, camera, shadowCamera ) {
  17731. if ( object.visible === false ) return;
  17732. if ( object.layers.test( camera.layers ) && ( object instanceof THREE.Mesh || object instanceof THREE.Line || object instanceof THREE.Points ) ) {
  17733. if ( object.castShadow && ( object.frustumCulled === false || _frustum.intersectsObject( object ) === true ) ) {
  17734. var material = object.material;
  17735. if ( material.visible === true ) {
  17736. object.modelViewMatrix.multiplyMatrices( shadowCamera.matrixWorldInverse, object.matrixWorld );
  17737. _renderList.push( object );
  17738. }
  17739. }
  17740. }
  17741. var children = object.children;
  17742. for ( var i = 0, l = children.length; i < l; i ++ ) {
  17743. projectObject( children[ i ], camera, shadowCamera );
  17744. }
  17745. }
  17746. };
  17747. // File:src/renderers/webgl/WebGLState.js
  17748. /**
  17749. * @author mrdoob / http://mrdoob.com/
  17750. */
  17751. THREE.WebGLState = function ( gl, extensions, paramThreeToGL ) {
  17752. var _this = this;
  17753. this.buffers = {
  17754. color: new THREE.WebGLColorBuffer( gl, this ),
  17755. depth: new THREE.WebGLDepthBuffer( gl, this ),
  17756. stencil: new THREE.WebGLStencilBuffer( gl, this )
  17757. };
  17758. var maxVertexAttributes = gl.getParameter( gl.MAX_VERTEX_ATTRIBS );
  17759. var newAttributes = new Uint8Array( maxVertexAttributes );
  17760. var enabledAttributes = new Uint8Array( maxVertexAttributes );
  17761. var attributeDivisors = new Uint8Array( maxVertexAttributes );
  17762. var capabilities = {};
  17763. var compressedTextureFormats = null;
  17764. var currentBlending = null;
  17765. var currentBlendEquation = null;
  17766. var currentBlendSrc = null;
  17767. var currentBlendDst = null;
  17768. var currentBlendEquationAlpha = null;
  17769. var currentBlendSrcAlpha = null;
  17770. var currentBlendDstAlpha = null;
  17771. var currentPremultipledAlpha = false;
  17772. var currentFlipSided = null;
  17773. var currentCullFace = null;
  17774. var currentLineWidth = null;
  17775. var currentPolygonOffsetFactor = null;
  17776. var currentPolygonOffsetUnits = null;
  17777. var currentScissorTest = null;
  17778. var maxTextures = gl.getParameter( gl.MAX_TEXTURE_IMAGE_UNITS );
  17779. var currentTextureSlot = null;
  17780. var currentBoundTextures = {};
  17781. var currentScissor = new THREE.Vector4();
  17782. var currentViewport = new THREE.Vector4();
  17783. function createTexture( type, target, count ) {
  17784. var data = new Uint8Array( 4 ); // 4 is required to match default unpack alignment of 4.
  17785. var texture = gl.createTexture();
  17786. gl.bindTexture( type, texture );
  17787. gl.texParameteri( type, gl.TEXTURE_MIN_FILTER, gl.NEAREST );
  17788. gl.texParameteri( type, gl.TEXTURE_MAG_FILTER, gl.NEAREST );
  17789. for ( var i = 0; i < count; i ++ ) {
  17790. gl.texImage2D( target + i, 0, gl.RGBA, 1, 1, 0, gl.RGBA, gl.UNSIGNED_BYTE, data );
  17791. }
  17792. return texture;
  17793. }
  17794. var emptyTextures = {};
  17795. emptyTextures[ gl.TEXTURE_2D ] = createTexture( gl.TEXTURE_2D, gl.TEXTURE_2D, 1 );
  17796. emptyTextures[ gl.TEXTURE_CUBE_MAP ] = createTexture( gl.TEXTURE_CUBE_MAP, gl.TEXTURE_CUBE_MAP_POSITIVE_X, 6 );
  17797. //
  17798. this.init = function () {
  17799. this.clearColor( 0, 0, 0, 1 );
  17800. this.clearDepth( 1 );
  17801. this.clearStencil( 0 );
  17802. this.enable( gl.DEPTH_TEST );
  17803. this.setDepthFunc( THREE.LessEqualDepth );
  17804. this.setFlipSided( false );
  17805. this.setCullFace( THREE.CullFaceBack );
  17806. this.enable( gl.CULL_FACE );
  17807. this.enable( gl.BLEND );
  17808. this.setBlending( THREE.NormalBlending );
  17809. };
  17810. this.initAttributes = function () {
  17811. for ( var i = 0, l = newAttributes.length; i < l; i ++ ) {
  17812. newAttributes[ i ] = 0;
  17813. }
  17814. };
  17815. this.enableAttribute = function ( attribute ) {
  17816. newAttributes[ attribute ] = 1;
  17817. if ( enabledAttributes[ attribute ] === 0 ) {
  17818. gl.enableVertexAttribArray( attribute );
  17819. enabledAttributes[ attribute ] = 1;
  17820. }
  17821. if ( attributeDivisors[ attribute ] !== 0 ) {
  17822. var extension = extensions.get( 'ANGLE_instanced_arrays' );
  17823. extension.vertexAttribDivisorANGLE( attribute, 0 );
  17824. attributeDivisors[ attribute ] = 0;
  17825. }
  17826. };
  17827. this.enableAttributeAndDivisor = function ( attribute, meshPerAttribute, extension ) {
  17828. newAttributes[ attribute ] = 1;
  17829. if ( enabledAttributes[ attribute ] === 0 ) {
  17830. gl.enableVertexAttribArray( attribute );
  17831. enabledAttributes[ attribute ] = 1;
  17832. }
  17833. if ( attributeDivisors[ attribute ] !== meshPerAttribute ) {
  17834. extension.vertexAttribDivisorANGLE( attribute, meshPerAttribute );
  17835. attributeDivisors[ attribute ] = meshPerAttribute;
  17836. }
  17837. };
  17838. this.disableUnusedAttributes = function () {
  17839. for ( var i = 0, l = enabledAttributes.length; i !== l; ++ i ) {
  17840. if ( enabledAttributes[ i ] !== newAttributes[ i ] ) {
  17841. gl.disableVertexAttribArray( i );
  17842. enabledAttributes[ i ] = 0;
  17843. }
  17844. }
  17845. };
  17846. this.enable = function ( id ) {
  17847. if ( capabilities[ id ] !== true ) {
  17848. gl.enable( id );
  17849. capabilities[ id ] = true;
  17850. }
  17851. };
  17852. this.disable = function ( id ) {
  17853. if ( capabilities[ id ] !== false ) {
  17854. gl.disable( id );
  17855. capabilities[ id ] = false;
  17856. }
  17857. };
  17858. this.getCompressedTextureFormats = function () {
  17859. if ( compressedTextureFormats === null ) {
  17860. compressedTextureFormats = [];
  17861. if ( extensions.get( 'WEBGL_compressed_texture_pvrtc' ) ||
  17862. extensions.get( 'WEBGL_compressed_texture_s3tc' ) ||
  17863. extensions.get( 'WEBGL_compressed_texture_etc1' ) ) {
  17864. var formats = gl.getParameter( gl.COMPRESSED_TEXTURE_FORMATS );
  17865. for ( var i = 0; i < formats.length; i ++ ) {
  17866. compressedTextureFormats.push( formats[ i ] );
  17867. }
  17868. }
  17869. }
  17870. return compressedTextureFormats;
  17871. };
  17872. this.setBlending = function ( blending, blendEquation, blendSrc, blendDst, blendEquationAlpha, blendSrcAlpha, blendDstAlpha, premultipliedAlpha ) {
  17873. if ( blending !== THREE.NoBlending ) {
  17874. this.enable( gl.BLEND );
  17875. } else {
  17876. this.disable( gl.BLEND );
  17877. currentBlending = blending; // no blending, that is
  17878. return;
  17879. }
  17880. if ( blending !== currentBlending || premultipliedAlpha !== currentPremultipledAlpha ) {
  17881. if ( blending === THREE.AdditiveBlending ) {
  17882. if ( premultipliedAlpha ) {
  17883. gl.blendEquationSeparate( gl.FUNC_ADD, gl.FUNC_ADD );
  17884. gl.blendFuncSeparate( gl.ONE, gl.ONE, gl.ONE, gl.ONE );
  17885. } else {
  17886. gl.blendEquation( gl.FUNC_ADD );
  17887. gl.blendFunc( gl.SRC_ALPHA, gl.ONE );
  17888. }
  17889. } else if ( blending === THREE.SubtractiveBlending ) {
  17890. if ( premultipliedAlpha ) {
  17891. gl.blendEquationSeparate( gl.FUNC_ADD, gl.FUNC_ADD );
  17892. gl.blendFuncSeparate( gl.ZERO, gl.ZERO, gl.ONE_MINUS_SRC_COLOR, gl.ONE_MINUS_SRC_ALPHA );
  17893. } else {
  17894. gl.blendEquation( gl.FUNC_ADD );
  17895. gl.blendFunc( gl.ZERO, gl.ONE_MINUS_SRC_COLOR );
  17896. }
  17897. } else if ( blending === THREE.MultiplyBlending ) {
  17898. if ( premultipliedAlpha ) {
  17899. gl.blendEquationSeparate( gl.FUNC_ADD, gl.FUNC_ADD );
  17900. gl.blendFuncSeparate( gl.ZERO, gl.SRC_COLOR, gl.ZERO, gl.SRC_ALPHA );
  17901. } else {
  17902. gl.blendEquation( gl.FUNC_ADD );
  17903. gl.blendFunc( gl.ZERO, gl.SRC_COLOR );
  17904. }
  17905. } else {
  17906. if ( premultipliedAlpha ) {
  17907. gl.blendEquationSeparate( gl.FUNC_ADD, gl.FUNC_ADD );
  17908. gl.blendFuncSeparate( gl.ONE, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA );
  17909. } else {
  17910. gl.blendEquationSeparate( gl.FUNC_ADD, gl.FUNC_ADD );
  17911. gl.blendFuncSeparate( gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA );
  17912. }
  17913. }
  17914. currentBlending = blending;
  17915. currentPremultipledAlpha = premultipliedAlpha;
  17916. }
  17917. if ( blending === THREE.CustomBlending ) {
  17918. blendEquationAlpha = blendEquationAlpha || blendEquation;
  17919. blendSrcAlpha = blendSrcAlpha || blendSrc;
  17920. blendDstAlpha = blendDstAlpha || blendDst;
  17921. if ( blendEquation !== currentBlendEquation || blendEquationAlpha !== currentBlendEquationAlpha ) {
  17922. gl.blendEquationSeparate( paramThreeToGL( blendEquation ), paramThreeToGL( blendEquationAlpha ) );
  17923. currentBlendEquation = blendEquation;
  17924. currentBlendEquationAlpha = blendEquationAlpha;
  17925. }
  17926. if ( blendSrc !== currentBlendSrc || blendDst !== currentBlendDst || blendSrcAlpha !== currentBlendSrcAlpha || blendDstAlpha !== currentBlendDstAlpha ) {
  17927. gl.blendFuncSeparate( paramThreeToGL( blendSrc ), paramThreeToGL( blendDst ), paramThreeToGL( blendSrcAlpha ), paramThreeToGL( blendDstAlpha ) );
  17928. currentBlendSrc = blendSrc;
  17929. currentBlendDst = blendDst;
  17930. currentBlendSrcAlpha = blendSrcAlpha;
  17931. currentBlendDstAlpha = blendDstAlpha;
  17932. }
  17933. } else {
  17934. currentBlendEquation = null;
  17935. currentBlendSrc = null;
  17936. currentBlendDst = null;
  17937. currentBlendEquationAlpha = null;
  17938. currentBlendSrcAlpha = null;
  17939. currentBlendDstAlpha = null;
  17940. }
  17941. };
  17942. // TODO Deprecate
  17943. this.setColorWrite = function ( colorWrite ) {
  17944. this.buffers.color.setMask( colorWrite );
  17945. };
  17946. this.setDepthTest = function ( depthTest ) {
  17947. this.buffers.depth.setTest( depthTest );
  17948. };
  17949. this.setDepthWrite = function ( depthWrite ) {
  17950. this.buffers.depth.setMask( depthWrite );
  17951. };
  17952. this.setDepthFunc = function ( depthFunc ) {
  17953. this.buffers.depth.setFunc( depthFunc );
  17954. };
  17955. this.setStencilTest = function ( stencilTest ) {
  17956. this.buffers.stencil.setTest( stencilTest );
  17957. };
  17958. this.setStencilWrite = function ( stencilWrite ) {
  17959. this.buffers.stencil.setMask( stencilWrite );
  17960. };
  17961. this.setStencilFunc = function ( stencilFunc, stencilRef, stencilMask ) {
  17962. this.buffers.stencil.setFunc( stencilFunc, stencilRef, stencilMask );
  17963. };
  17964. this.setStencilOp = function ( stencilFail, stencilZFail, stencilZPass ) {
  17965. this.buffers.stencil.setOp( stencilFail, stencilZFail, stencilZPass );
  17966. };
  17967. //
  17968. this.setFlipSided = function ( flipSided ) {
  17969. if ( currentFlipSided !== flipSided ) {
  17970. if ( flipSided ) {
  17971. gl.frontFace( gl.CW );
  17972. } else {
  17973. gl.frontFace( gl.CCW );
  17974. }
  17975. currentFlipSided = flipSided;
  17976. }
  17977. };
  17978. this.setCullFace = function ( cullFace ) {
  17979. if ( cullFace !== THREE.CullFaceNone ) {
  17980. this.enable( gl.CULL_FACE );
  17981. if ( cullFace !== currentCullFace ) {
  17982. if ( cullFace === THREE.CullFaceBack ) {
  17983. gl.cullFace( gl.BACK );
  17984. } else if ( cullFace === THREE.CullFaceFront ) {
  17985. gl.cullFace( gl.FRONT );
  17986. } else {
  17987. gl.cullFace( gl.FRONT_AND_BACK );
  17988. }
  17989. }
  17990. } else {
  17991. this.disable( gl.CULL_FACE );
  17992. }
  17993. currentCullFace = cullFace;
  17994. };
  17995. this.setLineWidth = function ( width ) {
  17996. if ( width !== currentLineWidth ) {
  17997. gl.lineWidth( width );
  17998. currentLineWidth = width;
  17999. }
  18000. };
  18001. this.setPolygonOffset = function ( polygonOffset, factor, units ) {
  18002. if ( polygonOffset ) {
  18003. this.enable( gl.POLYGON_OFFSET_FILL );
  18004. if ( currentPolygonOffsetFactor !== factor || currentPolygonOffsetUnits !== units ) {
  18005. gl.polygonOffset( factor, units );
  18006. currentPolygonOffsetFactor = factor;
  18007. currentPolygonOffsetUnits = units;
  18008. }
  18009. } else {
  18010. this.disable( gl.POLYGON_OFFSET_FILL );
  18011. }
  18012. };
  18013. this.getScissorTest = function () {
  18014. return currentScissorTest;
  18015. };
  18016. this.setScissorTest = function ( scissorTest ) {
  18017. currentScissorTest = scissorTest;
  18018. if ( scissorTest ) {
  18019. this.enable( gl.SCISSOR_TEST );
  18020. } else {
  18021. this.disable( gl.SCISSOR_TEST );
  18022. }
  18023. };
  18024. // texture
  18025. this.activeTexture = function ( webglSlot ) {
  18026. if ( webglSlot === undefined ) webglSlot = gl.TEXTURE0 + maxTextures - 1;
  18027. if ( currentTextureSlot !== webglSlot ) {
  18028. gl.activeTexture( webglSlot );
  18029. currentTextureSlot = webglSlot;
  18030. }
  18031. };
  18032. this.bindTexture = function ( webglType, webglTexture ) {
  18033. if ( currentTextureSlot === null ) {
  18034. _this.activeTexture();
  18035. }
  18036. var boundTexture = currentBoundTextures[ currentTextureSlot ];
  18037. if ( boundTexture === undefined ) {
  18038. boundTexture = { type: undefined, texture: undefined };
  18039. currentBoundTextures[ currentTextureSlot ] = boundTexture;
  18040. }
  18041. if ( boundTexture.type !== webglType || boundTexture.texture !== webglTexture ) {
  18042. gl.bindTexture( webglType, webglTexture || emptyTextures[ webglType ] );
  18043. boundTexture.type = webglType;
  18044. boundTexture.texture = webglTexture;
  18045. }
  18046. };
  18047. this.compressedTexImage2D = function () {
  18048. try {
  18049. gl.compressedTexImage2D.apply( gl, arguments );
  18050. } catch ( error ) {
  18051. console.error( error );
  18052. }
  18053. };
  18054. this.texImage2D = function () {
  18055. try {
  18056. gl.texImage2D.apply( gl, arguments );
  18057. } catch ( error ) {
  18058. console.error( error );
  18059. }
  18060. };
  18061. // TODO Deprecate
  18062. this.clearColor = function ( r, g, b, a ) {
  18063. this.buffers.color.setClear( r, g, b, a );
  18064. };
  18065. this.clearDepth = function ( depth ) {
  18066. this.buffers.depth.setClear( depth );
  18067. };
  18068. this.clearStencil = function ( stencil ) {
  18069. this.buffers.stencil.setClear( stencil );
  18070. };
  18071. //
  18072. this.scissor = function ( scissor ) {
  18073. if ( currentScissor.equals( scissor ) === false ) {
  18074. gl.scissor( scissor.x, scissor.y, scissor.z, scissor.w );
  18075. currentScissor.copy( scissor );
  18076. }
  18077. };
  18078. this.viewport = function ( viewport ) {
  18079. if ( currentViewport.equals( viewport ) === false ) {
  18080. gl.viewport( viewport.x, viewport.y, viewport.z, viewport.w );
  18081. currentViewport.copy( viewport );
  18082. }
  18083. };
  18084. //
  18085. this.reset = function () {
  18086. for ( var i = 0; i < enabledAttributes.length; i ++ ) {
  18087. if ( enabledAttributes[ i ] === 1 ) {
  18088. gl.disableVertexAttribArray( i );
  18089. enabledAttributes[ i ] = 0;
  18090. }
  18091. }
  18092. capabilities = {};
  18093. compressedTextureFormats = null;
  18094. currentTextureSlot = null;
  18095. currentBoundTextures = {};
  18096. currentBlending = null;
  18097. currentFlipSided = null;
  18098. currentCullFace = null;
  18099. this.buffers.color.reset();
  18100. this.buffers.depth.reset();
  18101. this.buffers.stencil.reset();
  18102. };
  18103. };
  18104. THREE.WebGLColorBuffer = function ( gl, state ) {
  18105. var locked = false;
  18106. var color = new THREE.Vector4();
  18107. var currentColorMask = null;
  18108. var currentColorClear = new THREE.Vector4();
  18109. this.setMask = function ( colorMask ) {
  18110. if ( currentColorMask !== colorMask && ! locked ) {
  18111. gl.colorMask( colorMask, colorMask, colorMask, colorMask );
  18112. currentColorMask = colorMask;
  18113. }
  18114. };
  18115. this.setLocked = function ( lock ) {
  18116. locked = lock;
  18117. };
  18118. this.setClear = function ( r, g, b, a ) {
  18119. color.set( r, g, b, a );
  18120. if ( currentColorClear.equals( color ) === false ) {
  18121. gl.clearColor( r, g, b, a );
  18122. currentColorClear.copy( color );
  18123. }
  18124. };
  18125. this.reset = function () {
  18126. locked = false;
  18127. currentColorMask = null;
  18128. currentColorClear = new THREE.Vector4();
  18129. };
  18130. };
  18131. THREE.WebGLDepthBuffer = function( gl, state ) {
  18132. var locked = false;
  18133. var currentDepthMask = null;
  18134. var currentDepthFunc = null;
  18135. var currentDepthClear = null;
  18136. this.setTest = function ( depthTest ) {
  18137. if ( depthTest ) {
  18138. state.enable( gl.DEPTH_TEST );
  18139. } else {
  18140. state.disable( gl.DEPTH_TEST );
  18141. }
  18142. };
  18143. this.setMask = function( depthMask ){
  18144. if ( currentDepthMask !== depthMask && ! locked ) {
  18145. gl.depthMask( depthMask );
  18146. currentDepthMask = depthMask;
  18147. }
  18148. };
  18149. this.setFunc = function ( depthFunc ) {
  18150. if ( currentDepthFunc !== depthFunc ) {
  18151. if ( depthFunc ) {
  18152. switch ( depthFunc ) {
  18153. case THREE.NeverDepth:
  18154. gl.depthFunc( gl.NEVER );
  18155. break;
  18156. case THREE.AlwaysDepth:
  18157. gl.depthFunc( gl.ALWAYS );
  18158. break;
  18159. case THREE.LessDepth:
  18160. gl.depthFunc( gl.LESS );
  18161. break;
  18162. case THREE.LessEqualDepth:
  18163. gl.depthFunc( gl.LEQUAL );
  18164. break;
  18165. case THREE.EqualDepth:
  18166. gl.depthFunc( gl.EQUAL );
  18167. break;
  18168. case THREE.GreaterEqualDepth:
  18169. gl.depthFunc( gl.GEQUAL );
  18170. break;
  18171. case THREE.GreaterDepth:
  18172. gl.depthFunc( gl.GREATER );
  18173. break;
  18174. case THREE.NotEqualDepth:
  18175. gl.depthFunc( gl.NOTEQUAL );
  18176. break;
  18177. default:
  18178. gl.depthFunc( gl.LEQUAL );
  18179. }
  18180. } else {
  18181. gl.depthFunc( gl.LEQUAL );
  18182. }
  18183. currentDepthFunc = depthFunc;
  18184. }
  18185. };
  18186. this.setLocked = function ( lock ) {
  18187. locked = lock;
  18188. };
  18189. this.setClear = function ( depth ) {
  18190. if ( currentDepthClear !== depth ) {
  18191. gl.clearDepth( depth );
  18192. currentDepthClear = depth;
  18193. }
  18194. };
  18195. this.reset = function () {
  18196. locked = false;
  18197. currentDepthMask = null;
  18198. currentDepthFunc = null;
  18199. currentDepthClear = null;
  18200. };
  18201. };
  18202. THREE.WebGLStencilBuffer = function ( gl, state ) {
  18203. var locked = false;
  18204. var currentStencilMask = null;
  18205. var currentStencilFunc = null;
  18206. var currentStencilRef = null;
  18207. var currentStencilFuncMask = null;
  18208. var currentStencilFail = null;
  18209. var currentStencilZFail = null;
  18210. var currentStencilZPass = null;
  18211. var currentStencilClear = null;
  18212. this.setTest = function ( stencilTest ) {
  18213. if ( stencilTest ) {
  18214. state.enable( gl.STENCIL_TEST );
  18215. } else {
  18216. state.disable( gl.STENCIL_TEST );
  18217. }
  18218. };
  18219. this.setMask = function ( stencilMask ) {
  18220. if ( currentStencilMask !== stencilMask && ! locked ) {
  18221. gl.stencilMask( stencilMask );
  18222. currentStencilMask = stencilMask;
  18223. }
  18224. };
  18225. this.setFunc = function ( stencilFunc, stencilRef, stencilMask ) {
  18226. if ( currentStencilFunc !== stencilFunc ||
  18227. currentStencilRef !== stencilRef ||
  18228. currentStencilFuncMask !== stencilMask ) {
  18229. gl.stencilFunc( stencilFunc, stencilRef, stencilMask );
  18230. currentStencilFunc = stencilFunc;
  18231. currentStencilRef = stencilRef;
  18232. currentStencilFuncMask = stencilMask;
  18233. }
  18234. };
  18235. this.setOp = function ( stencilFail, stencilZFail, stencilZPass ) {
  18236. if ( currentStencilFail !== stencilFail ||
  18237. currentStencilZFail !== stencilZFail ||
  18238. currentStencilZPass !== stencilZPass ) {
  18239. gl.stencilOp( stencilFail, stencilZFail, stencilZPass );
  18240. currentStencilFail = stencilFail;
  18241. currentStencilZFail = stencilZFail;
  18242. currentStencilZPass = stencilZPass;
  18243. }
  18244. };
  18245. this.setLocked = function ( lock ) {
  18246. locked = lock;
  18247. };
  18248. this.setClear = function ( stencil ) {
  18249. if ( currentStencilClear !== stencil ) {
  18250. gl.clearStencil( stencil );
  18251. currentStencilClear = stencil;
  18252. }
  18253. };
  18254. this.reset = function () {
  18255. locked = false;
  18256. currentStencilMask = null;
  18257. currentStencilFunc = null;
  18258. currentStencilRef = null;
  18259. currentStencilFuncMask = null;
  18260. currentStencilFail = null;
  18261. currentStencilZFail = null;
  18262. currentStencilZPass = null;
  18263. currentStencilClear = null;
  18264. };
  18265. };
  18266. // File:src/renderers/webgl/WebGLTextures.js
  18267. /**
  18268. * @author mrdoob / http://mrdoob.com/
  18269. */
  18270. THREE.WebGLTextures = function ( _gl, extensions, state, properties, capabilities, paramThreeToGL, info ) {
  18271. var _infoMemory = info.memory;
  18272. var _isWebGL2 = ( typeof WebGL2RenderingContext !== 'undefined' && _gl instanceof WebGL2RenderingContext );
  18273. //
  18274. function clampToMaxSize ( image, maxSize ) {
  18275. if ( image.width > maxSize || image.height > maxSize ) {
  18276. // Warning: Scaling through the canvas will only work with images that use
  18277. // premultiplied alpha.
  18278. var scale = maxSize / Math.max( image.width, image.height );
  18279. var canvas = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' );
  18280. canvas.width = Math.floor( image.width * scale );
  18281. canvas.height = Math.floor( image.height * scale );
  18282. var context = canvas.getContext( '2d' );
  18283. context.drawImage( image, 0, 0, image.width, image.height, 0, 0, canvas.width, canvas.height );
  18284. console.warn( 'THREE.WebGLRenderer: image is too big (' + image.width + 'x' + image.height + '). Resized to ' + canvas.width + 'x' + canvas.height, image );
  18285. return canvas;
  18286. }
  18287. return image;
  18288. }
  18289. function isPowerOfTwo( image ) {
  18290. return THREE.Math.isPowerOfTwo( image.width ) && THREE.Math.isPowerOfTwo( image.height );
  18291. }
  18292. function makePowerOfTwo( image ) {
  18293. if ( image instanceof HTMLImageElement || image instanceof HTMLCanvasElement ) {
  18294. var canvas = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' );
  18295. canvas.width = THREE.Math.nearestPowerOfTwo( image.width );
  18296. canvas.height = THREE.Math.nearestPowerOfTwo( image.height );
  18297. var context = canvas.getContext( '2d' );
  18298. context.drawImage( image, 0, 0, canvas.width, canvas.height );
  18299. console.warn( 'THREE.WebGLRenderer: image is not power of two (' + image.width + 'x' + image.height + '). Resized to ' + canvas.width + 'x' + canvas.height, image );
  18300. return canvas;
  18301. }
  18302. return image;
  18303. }
  18304. function textureNeedsPowerOfTwo( texture ) {
  18305. if ( texture.wrapS !== THREE.ClampToEdgeWrapping || texture.wrapT !== THREE.ClampToEdgeWrapping ) return true;
  18306. if ( texture.minFilter !== THREE.NearestFilter && texture.minFilter !== THREE.LinearFilter ) return true;
  18307. return false;
  18308. }
  18309. // Fallback filters for non-power-of-2 textures
  18310. function filterFallback ( f ) {
  18311. if ( f === THREE.NearestFilter || f === THREE.NearestMipMapNearestFilter || f === THREE.NearestMipMapLinearFilter ) {
  18312. return _gl.NEAREST;
  18313. }
  18314. return _gl.LINEAR;
  18315. }
  18316. //
  18317. function onTextureDispose( event ) {
  18318. var texture = event.target;
  18319. texture.removeEventListener( 'dispose', onTextureDispose );
  18320. deallocateTexture( texture );
  18321. _infoMemory.textures --;
  18322. }
  18323. function onRenderTargetDispose( event ) {
  18324. var renderTarget = event.target;
  18325. renderTarget.removeEventListener( 'dispose', onRenderTargetDispose );
  18326. deallocateRenderTarget( renderTarget );
  18327. _infoMemory.textures --;
  18328. }
  18329. //
  18330. function deallocateTexture( texture ) {
  18331. var textureProperties = properties.get( texture );
  18332. if ( texture.image && textureProperties.__image__webglTextureCube ) {
  18333. // cube texture
  18334. _gl.deleteTexture( textureProperties.__image__webglTextureCube );
  18335. } else {
  18336. // 2D texture
  18337. if ( textureProperties.__webglInit === undefined ) return;
  18338. _gl.deleteTexture( textureProperties.__webglTexture );
  18339. }
  18340. // remove all webgl properties
  18341. properties.delete( texture );
  18342. }
  18343. function deallocateRenderTarget( renderTarget ) {
  18344. var renderTargetProperties = properties.get( renderTarget );
  18345. var textureProperties = properties.get( renderTarget.texture );
  18346. if ( ! renderTarget ) return;
  18347. if ( textureProperties.__webglTexture !== undefined ) {
  18348. _gl.deleteTexture( textureProperties.__webglTexture );
  18349. }
  18350. if ( renderTarget.depthTexture ) {
  18351. renderTarget.depthTexture.dispose();
  18352. }
  18353. if ( renderTarget instanceof THREE.WebGLRenderTargetCube ) {
  18354. for ( var i = 0; i < 6; i ++ ) {
  18355. _gl.deleteFramebuffer( renderTargetProperties.__webglFramebuffer[ i ] );
  18356. if ( renderTargetProperties.__webglDepthbuffer ) _gl.deleteRenderbuffer( renderTargetProperties.__webglDepthbuffer[ i ] );
  18357. }
  18358. } else {
  18359. _gl.deleteFramebuffer( renderTargetProperties.__webglFramebuffer );
  18360. if ( renderTargetProperties.__webglDepthbuffer ) _gl.deleteRenderbuffer( renderTargetProperties.__webglDepthbuffer );
  18361. }
  18362. properties.delete( renderTarget.texture );
  18363. properties.delete( renderTarget );
  18364. }
  18365. //
  18366. function setTexture2D( texture, slot ) {
  18367. var textureProperties = properties.get( texture );
  18368. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  18369. var image = texture.image;
  18370. if ( image === undefined ) {
  18371. console.warn( 'THREE.WebGLRenderer: Texture marked for update but image is undefined', texture );
  18372. } else if ( image.complete === false ) {
  18373. console.warn( 'THREE.WebGLRenderer: Texture marked for update but image is incomplete', texture );
  18374. } else {
  18375. uploadTexture( textureProperties, texture, slot );
  18376. return;
  18377. }
  18378. }
  18379. state.activeTexture( _gl.TEXTURE0 + slot );
  18380. state.bindTexture( _gl.TEXTURE_2D, textureProperties.__webglTexture );
  18381. }
  18382. function setTextureCube ( texture, slot ) {
  18383. var textureProperties = properties.get( texture );
  18384. if ( texture.image.length === 6 ) {
  18385. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  18386. if ( ! textureProperties.__image__webglTextureCube ) {
  18387. texture.addEventListener( 'dispose', onTextureDispose );
  18388. textureProperties.__image__webglTextureCube = _gl.createTexture();
  18389. _infoMemory.textures ++;
  18390. }
  18391. state.activeTexture( _gl.TEXTURE0 + slot );
  18392. state.bindTexture( _gl.TEXTURE_CUBE_MAP, textureProperties.__image__webglTextureCube );
  18393. _gl.pixelStorei( _gl.UNPACK_FLIP_Y_WEBGL, texture.flipY );
  18394. var isCompressed = texture instanceof THREE.CompressedTexture;
  18395. var isDataTexture = texture.image[ 0 ] instanceof THREE.DataTexture;
  18396. var cubeImage = [];
  18397. for ( var i = 0; i < 6; i ++ ) {
  18398. if ( ! isCompressed && ! isDataTexture ) {
  18399. cubeImage[ i ] = clampToMaxSize( texture.image[ i ], capabilities.maxCubemapSize );
  18400. } else {
  18401. cubeImage[ i ] = isDataTexture ? texture.image[ i ].image : texture.image[ i ];
  18402. }
  18403. }
  18404. var image = cubeImage[ 0 ],
  18405. isPowerOfTwoImage = isPowerOfTwo( image ),
  18406. glFormat = paramThreeToGL( texture.format ),
  18407. glType = paramThreeToGL( texture.type );
  18408. setTextureParameters( _gl.TEXTURE_CUBE_MAP, texture, isPowerOfTwoImage );
  18409. for ( var i = 0; i < 6; i ++ ) {
  18410. if ( ! isCompressed ) {
  18411. if ( isDataTexture ) {
  18412. state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, glFormat, cubeImage[ i ].width, cubeImage[ i ].height, 0, glFormat, glType, cubeImage[ i ].data );
  18413. } else {
  18414. state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, glFormat, glFormat, glType, cubeImage[ i ] );
  18415. }
  18416. } else {
  18417. var mipmap, mipmaps = cubeImage[ i ].mipmaps;
  18418. for ( var j = 0, jl = mipmaps.length; j < jl; j ++ ) {
  18419. mipmap = mipmaps[ j ];
  18420. if ( texture.format !== THREE.RGBAFormat && texture.format !== THREE.RGBFormat ) {
  18421. if ( state.getCompressedTextureFormats().indexOf( glFormat ) > - 1 ) {
  18422. state.compressedTexImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, j, glFormat, mipmap.width, mipmap.height, 0, mipmap.data );
  18423. } else {
  18424. console.warn( "THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .setTextureCube()" );
  18425. }
  18426. } else {
  18427. state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, j, glFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  18428. }
  18429. }
  18430. }
  18431. }
  18432. if ( texture.generateMipmaps && isPowerOfTwoImage ) {
  18433. _gl.generateMipmap( _gl.TEXTURE_CUBE_MAP );
  18434. }
  18435. textureProperties.__version = texture.version;
  18436. if ( texture.onUpdate ) texture.onUpdate( texture );
  18437. } else {
  18438. state.activeTexture( _gl.TEXTURE0 + slot );
  18439. state.bindTexture( _gl.TEXTURE_CUBE_MAP, textureProperties.__image__webglTextureCube );
  18440. }
  18441. }
  18442. }
  18443. function setTextureCubeDynamic ( texture, slot ) {
  18444. state.activeTexture( _gl.TEXTURE0 + slot );
  18445. state.bindTexture( _gl.TEXTURE_CUBE_MAP, properties.get( texture ).__webglTexture );
  18446. }
  18447. function setTextureParameters ( textureType, texture, isPowerOfTwoImage ) {
  18448. var extension;
  18449. if ( isPowerOfTwoImage ) {
  18450. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_S, paramThreeToGL( texture.wrapS ) );
  18451. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_T, paramThreeToGL( texture.wrapT ) );
  18452. _gl.texParameteri( textureType, _gl.TEXTURE_MAG_FILTER, paramThreeToGL( texture.magFilter ) );
  18453. _gl.texParameteri( textureType, _gl.TEXTURE_MIN_FILTER, paramThreeToGL( texture.minFilter ) );
  18454. } else {
  18455. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_S, _gl.CLAMP_TO_EDGE );
  18456. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_T, _gl.CLAMP_TO_EDGE );
  18457. if ( texture.wrapS !== THREE.ClampToEdgeWrapping || texture.wrapT !== THREE.ClampToEdgeWrapping ) {
  18458. console.warn( 'THREE.WebGLRenderer: Texture is not power of two. Texture.wrapS and Texture.wrapT should be set to THREE.ClampToEdgeWrapping.', texture );
  18459. }
  18460. _gl.texParameteri( textureType, _gl.TEXTURE_MAG_FILTER, filterFallback( texture.magFilter ) );
  18461. _gl.texParameteri( textureType, _gl.TEXTURE_MIN_FILTER, filterFallback( texture.minFilter ) );
  18462. if ( texture.minFilter !== THREE.NearestFilter && texture.minFilter !== THREE.LinearFilter ) {
  18463. console.warn( 'THREE.WebGLRenderer: Texture is not power of two. Texture.minFilter should be set to THREE.NearestFilter or THREE.LinearFilter.', texture );
  18464. }
  18465. }
  18466. extension = extensions.get( 'EXT_texture_filter_anisotropic' );
  18467. if ( extension ) {
  18468. if ( texture.type === THREE.FloatType && extensions.get( 'OES_texture_float_linear' ) === null ) return;
  18469. if ( texture.type === THREE.HalfFloatType && extensions.get( 'OES_texture_half_float_linear' ) === null ) return;
  18470. if ( texture.anisotropy > 1 || properties.get( texture ).__currentAnisotropy ) {
  18471. _gl.texParameterf( textureType, extension.TEXTURE_MAX_ANISOTROPY_EXT, Math.min( texture.anisotropy, capabilities.getMaxAnisotropy() ) );
  18472. properties.get( texture ).__currentAnisotropy = texture.anisotropy;
  18473. }
  18474. }
  18475. }
  18476. function uploadTexture( textureProperties, texture, slot ) {
  18477. if ( textureProperties.__webglInit === undefined ) {
  18478. textureProperties.__webglInit = true;
  18479. texture.addEventListener( 'dispose', onTextureDispose );
  18480. textureProperties.__webglTexture = _gl.createTexture();
  18481. _infoMemory.textures ++;
  18482. }
  18483. state.activeTexture( _gl.TEXTURE0 + slot );
  18484. state.bindTexture( _gl.TEXTURE_2D, textureProperties.__webglTexture );
  18485. _gl.pixelStorei( _gl.UNPACK_FLIP_Y_WEBGL, texture.flipY );
  18486. _gl.pixelStorei( _gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, texture.premultiplyAlpha );
  18487. _gl.pixelStorei( _gl.UNPACK_ALIGNMENT, texture.unpackAlignment );
  18488. var image = clampToMaxSize( texture.image, capabilities.maxTextureSize );
  18489. if ( textureNeedsPowerOfTwo( texture ) && isPowerOfTwo( image ) === false ) {
  18490. image = makePowerOfTwo( image );
  18491. }
  18492. var isPowerOfTwoImage = isPowerOfTwo( image ),
  18493. glFormat = paramThreeToGL( texture.format ),
  18494. glType = paramThreeToGL( texture.type );
  18495. setTextureParameters( _gl.TEXTURE_2D, texture, isPowerOfTwoImage );
  18496. var mipmap, mipmaps = texture.mipmaps;
  18497. if ( texture instanceof THREE.DepthTexture ) {
  18498. // populate depth texture with dummy data
  18499. var internalFormat = _gl.DEPTH_COMPONENT;
  18500. if ( texture.type === THREE.FloatType ) {
  18501. if ( !_isWebGL2 ) throw new Error('Float Depth Texture only supported in WebGL2.0');
  18502. internalFormat = _gl.DEPTH_COMPONENT32F;
  18503. } else if ( _isWebGL2 ) {
  18504. // WebGL 2.0 requires signed internalformat for glTexImage2D
  18505. internalFormat = _gl.DEPTH_COMPONENT16;
  18506. }
  18507. state.texImage2D( _gl.TEXTURE_2D, 0, internalFormat, image.width, image.height, 0, glFormat, glType, null );
  18508. } else if ( texture instanceof THREE.DataTexture ) {
  18509. // use manually created mipmaps if available
  18510. // if there are no manual mipmaps
  18511. // set 0 level mipmap and then use GL to generate other mipmap levels
  18512. if ( mipmaps.length > 0 && isPowerOfTwoImage ) {
  18513. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  18514. mipmap = mipmaps[ i ];
  18515. state.texImage2D( _gl.TEXTURE_2D, i, glFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  18516. }
  18517. texture.generateMipmaps = false;
  18518. } else {
  18519. state.texImage2D( _gl.TEXTURE_2D, 0, glFormat, image.width, image.height, 0, glFormat, glType, image.data );
  18520. }
  18521. } else if ( texture instanceof THREE.CompressedTexture ) {
  18522. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  18523. mipmap = mipmaps[ i ];
  18524. if ( texture.format !== THREE.RGBAFormat && texture.format !== THREE.RGBFormat ) {
  18525. if ( state.getCompressedTextureFormats().indexOf( glFormat ) > - 1 ) {
  18526. state.compressedTexImage2D( _gl.TEXTURE_2D, i, glFormat, mipmap.width, mipmap.height, 0, mipmap.data );
  18527. } else {
  18528. console.warn( "THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()" );
  18529. }
  18530. } else {
  18531. state.texImage2D( _gl.TEXTURE_2D, i, glFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  18532. }
  18533. }
  18534. } else {
  18535. // regular Texture (image, video, canvas)
  18536. // use manually created mipmaps if available
  18537. // if there are no manual mipmaps
  18538. // set 0 level mipmap and then use GL to generate other mipmap levels
  18539. if ( mipmaps.length > 0 && isPowerOfTwoImage ) {
  18540. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  18541. mipmap = mipmaps[ i ];
  18542. state.texImage2D( _gl.TEXTURE_2D, i, glFormat, glFormat, glType, mipmap );
  18543. }
  18544. texture.generateMipmaps = false;
  18545. } else {
  18546. state.texImage2D( _gl.TEXTURE_2D, 0, glFormat, glFormat, glType, image );
  18547. }
  18548. }
  18549. if ( texture.generateMipmaps && isPowerOfTwoImage ) _gl.generateMipmap( _gl.TEXTURE_2D );
  18550. textureProperties.__version = texture.version;
  18551. if ( texture.onUpdate ) texture.onUpdate( texture );
  18552. }
  18553. // Render targets
  18554. // Setup storage for target texture and bind it to correct framebuffer
  18555. function setupFrameBufferTexture ( framebuffer, renderTarget, attachment, textureTarget ) {
  18556. var glFormat = paramThreeToGL( renderTarget.texture.format );
  18557. var glType = paramThreeToGL( renderTarget.texture.type );
  18558. state.texImage2D( textureTarget, 0, glFormat, renderTarget.width, renderTarget.height, 0, glFormat, glType, null );
  18559. _gl.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
  18560. _gl.framebufferTexture2D( _gl.FRAMEBUFFER, attachment, textureTarget, properties.get( renderTarget.texture ).__webglTexture, 0 );
  18561. _gl.bindFramebuffer( _gl.FRAMEBUFFER, null );
  18562. }
  18563. // Setup storage for internal depth/stencil buffers and bind to correct framebuffer
  18564. function setupRenderBufferStorage ( renderbuffer, renderTarget ) {
  18565. _gl.bindRenderbuffer( _gl.RENDERBUFFER, renderbuffer );
  18566. if ( renderTarget.depthBuffer && ! renderTarget.stencilBuffer ) {
  18567. _gl.renderbufferStorage( _gl.RENDERBUFFER, _gl.DEPTH_COMPONENT16, renderTarget.width, renderTarget.height );
  18568. _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.DEPTH_ATTACHMENT, _gl.RENDERBUFFER, renderbuffer );
  18569. } else if ( renderTarget.depthBuffer && renderTarget.stencilBuffer ) {
  18570. _gl.renderbufferStorage( _gl.RENDERBUFFER, _gl.DEPTH_STENCIL, renderTarget.width, renderTarget.height );
  18571. _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.DEPTH_STENCIL_ATTACHMENT, _gl.RENDERBUFFER, renderbuffer );
  18572. } else {
  18573. // FIXME: We don't support !depth !stencil
  18574. _gl.renderbufferStorage( _gl.RENDERBUFFER, _gl.RGBA4, renderTarget.width, renderTarget.height );
  18575. }
  18576. _gl.bindRenderbuffer( _gl.RENDERBUFFER, null );
  18577. }
  18578. // Setup resources for a Depth Texture for a FBO (needs an extension)
  18579. function setupDepthTexture ( framebuffer, renderTarget ) {
  18580. var isCube = ( renderTarget instanceof THREE.WebGLRenderTargetCube );
  18581. if ( isCube ) throw new Error('Depth Texture with cube render targets is not supported!');
  18582. _gl.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
  18583. if ( !( renderTarget.depthTexture instanceof THREE.DepthTexture ) ) {
  18584. throw new Error('renderTarget.depthTexture must be an instance of THREE.DepthTexture');
  18585. }
  18586. // upload an empty depth texture with framebuffer size
  18587. if ( !properties.get( renderTarget.depthTexture ).__webglTexture ||
  18588. renderTarget.depthTexture.image.width !== renderTarget.width ||
  18589. renderTarget.depthTexture.image.height !== renderTarget.height ) {
  18590. renderTarget.depthTexture.image.width = renderTarget.width;
  18591. renderTarget.depthTexture.image.height = renderTarget.height;
  18592. renderTarget.depthTexture.needsUpdate = true;
  18593. }
  18594. setTexture2D( renderTarget.depthTexture, 0 );
  18595. var webglDepthTexture = properties.get( renderTarget.depthTexture ).__webglTexture;
  18596. _gl.framebufferTexture2D( _gl.FRAMEBUFFER, _gl.DEPTH_ATTACHMENT, _gl.TEXTURE_2D, webglDepthTexture, 0 );
  18597. }
  18598. // Setup GL resources for a non-texture depth buffer
  18599. function setupDepthRenderbuffer( renderTarget ) {
  18600. var renderTargetProperties = properties.get( renderTarget );
  18601. var isCube = ( renderTarget instanceof THREE.WebGLRenderTargetCube );
  18602. if ( renderTarget.depthTexture ) {
  18603. if ( isCube ) throw new Error('target.depthTexture not supported in Cube render targets');
  18604. setupDepthTexture( renderTargetProperties.__webglFramebuffer, renderTarget );
  18605. } else {
  18606. if ( isCube ) {
  18607. renderTargetProperties.__webglDepthbuffer = [];
  18608. for ( var i = 0; i < 6; i ++ ) {
  18609. _gl.bindFramebuffer( _gl.FRAMEBUFFER, renderTargetProperties.__webglFramebuffer[ i ] );
  18610. renderTargetProperties.__webglDepthbuffer[ i ] = _gl.createRenderbuffer();
  18611. setupRenderBufferStorage( renderTargetProperties.__webglDepthbuffer[ i ], renderTarget );
  18612. }
  18613. } else {
  18614. _gl.bindFramebuffer( _gl.FRAMEBUFFER, renderTargetProperties.__webglFramebuffer );
  18615. renderTargetProperties.__webglDepthbuffer = _gl.createRenderbuffer();
  18616. setupRenderBufferStorage( renderTargetProperties.__webglDepthbuffer, renderTarget );
  18617. }
  18618. }
  18619. _gl.bindFramebuffer( _gl.FRAMEBUFFER, null );
  18620. }
  18621. // Set up GL resources for the render target
  18622. function setupRenderTarget( renderTarget ) {
  18623. var renderTargetProperties = properties.get( renderTarget );
  18624. var textureProperties = properties.get( renderTarget.texture );
  18625. renderTarget.addEventListener( 'dispose', onRenderTargetDispose );
  18626. textureProperties.__webglTexture = _gl.createTexture();
  18627. _infoMemory.textures ++;
  18628. var isCube = ( renderTarget instanceof THREE.WebGLRenderTargetCube );
  18629. var isTargetPowerOfTwo = isPowerOfTwo( renderTarget );
  18630. // Setup framebuffer
  18631. if ( isCube ) {
  18632. renderTargetProperties.__webglFramebuffer = [];
  18633. for ( var i = 0; i < 6; i ++ ) {
  18634. renderTargetProperties.__webglFramebuffer[ i ] = _gl.createFramebuffer();
  18635. }
  18636. } else {
  18637. renderTargetProperties.__webglFramebuffer = _gl.createFramebuffer();
  18638. }
  18639. // Setup color buffer
  18640. if ( isCube ) {
  18641. state.bindTexture( _gl.TEXTURE_CUBE_MAP, textureProperties.__webglTexture );
  18642. setTextureParameters( _gl.TEXTURE_CUBE_MAP, renderTarget.texture, isTargetPowerOfTwo );
  18643. for ( var i = 0; i < 6; i ++ ) {
  18644. setupFrameBufferTexture( renderTargetProperties.__webglFramebuffer[ i ], renderTarget, _gl.COLOR_ATTACHMENT0, _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i );
  18645. }
  18646. if ( renderTarget.texture.generateMipmaps && isTargetPowerOfTwo ) _gl.generateMipmap( _gl.TEXTURE_CUBE_MAP );
  18647. state.bindTexture( _gl.TEXTURE_CUBE_MAP, null );
  18648. } else {
  18649. state.bindTexture( _gl.TEXTURE_2D, textureProperties.__webglTexture );
  18650. setTextureParameters( _gl.TEXTURE_2D, renderTarget.texture, isTargetPowerOfTwo );
  18651. setupFrameBufferTexture( renderTargetProperties.__webglFramebuffer, renderTarget, _gl.COLOR_ATTACHMENT0, _gl.TEXTURE_2D );
  18652. if ( renderTarget.texture.generateMipmaps && isTargetPowerOfTwo ) _gl.generateMipmap( _gl.TEXTURE_2D );
  18653. state.bindTexture( _gl.TEXTURE_2D, null );
  18654. }
  18655. // Setup depth and stencil buffers
  18656. if ( renderTarget.depthBuffer ) {
  18657. setupDepthRenderbuffer( renderTarget );
  18658. }
  18659. }
  18660. function updateRenderTargetMipmap( renderTarget ) {
  18661. var texture = renderTarget.texture;
  18662. if ( texture.generateMipmaps && isPowerOfTwo( renderTarget ) &&
  18663. texture.minFilter !== THREE.NearestFilter &&
  18664. texture.minFilter !== THREE.LinearFilter ) {
  18665. var target = renderTarget instanceof THREE.WebGLRenderTargetCube ? _gl.TEXTURE_CUBE_MAP : _gl.TEXTURE_2D;
  18666. var webglTexture = properties.get( texture ).__webglTexture;
  18667. state.bindTexture( target, webglTexture );
  18668. _gl.generateMipmap( target );
  18669. state.bindTexture( target, null );
  18670. }
  18671. }
  18672. this.setTexture2D = setTexture2D;
  18673. this.setTextureCube = setTextureCube;
  18674. this.setTextureCubeDynamic = setTextureCubeDynamic;
  18675. this.setupRenderTarget = setupRenderTarget;
  18676. this.updateRenderTargetMipmap = updateRenderTargetMipmap;
  18677. };
  18678. // File:src/renderers/webgl/WebGLUniforms.js
  18679. /**
  18680. *
  18681. * Uniforms of a program.
  18682. * Those form a tree structure with a special top-level container for the root,
  18683. * which you get by calling 'new WebGLUniforms( gl, program, renderer )'.
  18684. *
  18685. *
  18686. * Properties of inner nodes including the top-level container:
  18687. *
  18688. * .seq - array of nested uniforms
  18689. * .map - nested uniforms by name
  18690. *
  18691. *
  18692. * Methods of all nodes except the top-level container:
  18693. *
  18694. * .setValue( gl, value, [renderer] )
  18695. *
  18696. * uploads a uniform value(s)
  18697. * the 'renderer' parameter is needed for sampler uniforms
  18698. *
  18699. *
  18700. * Static methods of the top-level container (renderer factorizations):
  18701. *
  18702. * .upload( gl, seq, values, renderer )
  18703. *
  18704. * sets uniforms in 'seq' to 'values[id].value'
  18705. *
  18706. * .seqWithValue( seq, values ) : filteredSeq
  18707. *
  18708. * filters 'seq' entries with corresponding entry in values
  18709. *
  18710. * .splitDynamic( seq, values ) : filteredSeq
  18711. *
  18712. * filters 'seq' entries with dynamic entry and removes them from 'seq'
  18713. *
  18714. *
  18715. * Methods of the top-level container (renderer factorizations):
  18716. *
  18717. * .setValue( gl, name, value )
  18718. *
  18719. * sets uniform with name 'name' to 'value'
  18720. *
  18721. * .set( gl, obj, prop )
  18722. *
  18723. * sets uniform from object and property with same name than uniform
  18724. *
  18725. * .setOptional( gl, obj, prop )
  18726. *
  18727. * like .set for an optional property of the object
  18728. *
  18729. *
  18730. * @author tschw
  18731. *
  18732. */
  18733. THREE.WebGLUniforms = ( function() { // scope
  18734. var emptyTexture = new THREE.Texture();
  18735. var emptyCubeTexture = new THREE.CubeTexture();
  18736. // --- Base for inner nodes (including the root) ---
  18737. var UniformContainer = function() {
  18738. this.seq = [];
  18739. this.map = {};
  18740. },
  18741. // --- Utilities ---
  18742. // Array Caches (provide typed arrays for temporary by size)
  18743. arrayCacheF32 = [],
  18744. arrayCacheI32 = [],
  18745. uncacheTemporaryArrays = function() {
  18746. arrayCacheF32.length = 0;
  18747. arrayCacheI32.length = 0;
  18748. },
  18749. // Flattening for arrays of vectors and matrices
  18750. flatten = function( array, nBlocks, blockSize ) {
  18751. var firstElem = array[ 0 ];
  18752. if ( firstElem <= 0 || firstElem > 0 ) return array;
  18753. // unoptimized: ! isNaN( firstElem )
  18754. // see http://jacksondunstan.com/articles/983
  18755. var n = nBlocks * blockSize,
  18756. r = arrayCacheF32[ n ];
  18757. if ( r === undefined ) {
  18758. r = new Float32Array( n );
  18759. arrayCacheF32[ n ] = r;
  18760. }
  18761. if ( nBlocks !== 0 ) {
  18762. firstElem.toArray( r, 0 );
  18763. for ( var i = 1, offset = 0; i !== nBlocks; ++ i ) {
  18764. offset += blockSize;
  18765. array[ i ].toArray( r, offset );
  18766. }
  18767. }
  18768. return r;
  18769. },
  18770. // Texture unit allocation
  18771. allocTexUnits = function( renderer, n ) {
  18772. var r = arrayCacheI32[ n ];
  18773. if ( r === undefined ) {
  18774. r = new Int32Array( n );
  18775. arrayCacheI32[ n ] = r;
  18776. }
  18777. for ( var i = 0; i !== n; ++ i )
  18778. r[ i ] = renderer.allocTextureUnit();
  18779. return r;
  18780. },
  18781. // --- Setters ---
  18782. // Note: Defining these methods externally, because they come in a bunch
  18783. // and this way their names minify.
  18784. // Single scalar
  18785. setValue1f = function( gl, v ) { gl.uniform1f( this.addr, v ); },
  18786. setValue1i = function( gl, v ) { gl.uniform1i( this.addr, v ); },
  18787. // Single float vector (from flat array or THREE.VectorN)
  18788. setValue2fv = function( gl, v ) {
  18789. if ( v.x === undefined ) gl.uniform2fv( this.addr, v );
  18790. else gl.uniform2f( this.addr, v.x, v.y );
  18791. },
  18792. setValue3fv = function( gl, v ) {
  18793. if ( v.x !== undefined )
  18794. gl.uniform3f( this.addr, v.x, v.y, v.z );
  18795. else if ( v.r !== undefined )
  18796. gl.uniform3f( this.addr, v.r, v.g, v.b );
  18797. else
  18798. gl.uniform3fv( this.addr, v );
  18799. },
  18800. setValue4fv = function( gl, v ) {
  18801. if ( v.x === undefined ) gl.uniform4fv( this.addr, v );
  18802. else gl.uniform4f( this.addr, v.x, v.y, v.z, v.w );
  18803. },
  18804. // Single matrix (from flat array or MatrixN)
  18805. setValue2fm = function( gl, v ) {
  18806. gl.uniformMatrix2fv( this.addr, false, v.elements || v );
  18807. },
  18808. setValue3fm = function( gl, v ) {
  18809. gl.uniformMatrix3fv( this.addr, false, v.elements || v );
  18810. },
  18811. setValue4fm = function( gl, v ) {
  18812. gl.uniformMatrix4fv( this.addr, false, v.elements || v );
  18813. },
  18814. // Single texture (2D / Cube)
  18815. setValueT1 = function( gl, v, renderer ) {
  18816. var unit = renderer.allocTextureUnit();
  18817. gl.uniform1i( this.addr, unit );
  18818. renderer.setTexture2D( v || emptyTexture, unit );
  18819. },
  18820. setValueT6 = function( gl, v, renderer ) {
  18821. var unit = renderer.allocTextureUnit();
  18822. gl.uniform1i( this.addr, unit );
  18823. renderer.setTextureCube( v || emptyCubeTexture, unit );
  18824. },
  18825. // Integer / Boolean vectors or arrays thereof (always flat arrays)
  18826. setValue2iv = function( gl, v ) { gl.uniform2iv( this.addr, v ); },
  18827. setValue3iv = function( gl, v ) { gl.uniform3iv( this.addr, v ); },
  18828. setValue4iv = function( gl, v ) { gl.uniform4iv( this.addr, v ); },
  18829. // Helper to pick the right setter for the singular case
  18830. getSingularSetter = function( type ) {
  18831. switch ( type ) {
  18832. case 0x1406: return setValue1f; // FLOAT
  18833. case 0x8b50: return setValue2fv; // _VEC2
  18834. case 0x8b51: return setValue3fv; // _VEC3
  18835. case 0x8b52: return setValue4fv; // _VEC4
  18836. case 0x8b5a: return setValue2fm; // _MAT2
  18837. case 0x8b5b: return setValue3fm; // _MAT3
  18838. case 0x8b5c: return setValue4fm; // _MAT4
  18839. case 0x8b5e: return setValueT1; // SAMPLER_2D
  18840. case 0x8b60: return setValueT6; // SAMPLER_CUBE
  18841. case 0x1404: case 0x8b56: return setValue1i; // INT, BOOL
  18842. case 0x8b53: case 0x8b57: return setValue2iv; // _VEC2
  18843. case 0x8b54: case 0x8b58: return setValue3iv; // _VEC3
  18844. case 0x8b55: case 0x8b59: return setValue4iv; // _VEC4
  18845. }
  18846. },
  18847. // Array of scalars
  18848. setValue1fv = function( gl, v ) { gl.uniform1fv( this.addr, v ); },
  18849. setValue1iv = function( gl, v ) { gl.uniform1iv( this.addr, v ); },
  18850. // Array of vectors (flat or from THREE classes)
  18851. setValueV2a = function( gl, v ) {
  18852. gl.uniform2fv( this.addr, flatten( v, this.size, 2 ) );
  18853. },
  18854. setValueV3a = function( gl, v ) {
  18855. gl.uniform3fv( this.addr, flatten( v, this.size, 3 ) );
  18856. },
  18857. setValueV4a = function( gl, v ) {
  18858. gl.uniform4fv( this.addr, flatten( v, this.size, 4 ) );
  18859. },
  18860. // Array of matrices (flat or from THREE clases)
  18861. setValueM2a = function( gl, v ) {
  18862. gl.uniformMatrix2fv( this.addr, false, flatten( v, this.size, 4 ) );
  18863. },
  18864. setValueM3a = function( gl, v ) {
  18865. gl.uniformMatrix3fv( this.addr, false, flatten( v, this.size, 9 ) );
  18866. },
  18867. setValueM4a = function( gl, v ) {
  18868. gl.uniformMatrix4fv( this.addr, false, flatten( v, this.size, 16 ) );
  18869. },
  18870. // Array of textures (2D / Cube)
  18871. setValueT1a = function( gl, v, renderer ) {
  18872. var n = v.length,
  18873. units = allocTexUnits( renderer, n );
  18874. gl.uniform1iv( this.addr, units );
  18875. for ( var i = 0; i !== n; ++ i ) {
  18876. renderer.setTexture2D( v[ i ] || emptyTexture, units[ i ] );
  18877. }
  18878. },
  18879. setValueT6a = function( gl, v, renderer ) {
  18880. var n = v.length,
  18881. units = allocTexUnits( renderer, n );
  18882. gl.uniform1iv( this.addr, units );
  18883. for ( var i = 0; i !== n; ++ i ) {
  18884. renderer.setTextureCube( v[ i ] || emptyCubeTexture, units[ i ] );
  18885. }
  18886. },
  18887. // Helper to pick the right setter for a pure (bottom-level) array
  18888. getPureArraySetter = function( type ) {
  18889. switch ( type ) {
  18890. case 0x1406: return setValue1fv; // FLOAT
  18891. case 0x8b50: return setValueV2a; // _VEC2
  18892. case 0x8b51: return setValueV3a; // _VEC3
  18893. case 0x8b52: return setValueV4a; // _VEC4
  18894. case 0x8b5a: return setValueM2a; // _MAT2
  18895. case 0x8b5b: return setValueM3a; // _MAT3
  18896. case 0x8b5c: return setValueM4a; // _MAT4
  18897. case 0x8b5e: return setValueT1a; // SAMPLER_2D
  18898. case 0x8b60: return setValueT6a; // SAMPLER_CUBE
  18899. case 0x1404: case 0x8b56: return setValue1iv; // INT, BOOL
  18900. case 0x8b53: case 0x8b57: return setValue2iv; // _VEC2
  18901. case 0x8b54: case 0x8b58: return setValue3iv; // _VEC3
  18902. case 0x8b55: case 0x8b59: return setValue4iv; // _VEC4
  18903. }
  18904. },
  18905. // --- Uniform Classes ---
  18906. SingleUniform = function SingleUniform( id, activeInfo, addr ) {
  18907. this.id = id;
  18908. this.addr = addr;
  18909. this.setValue = getSingularSetter( activeInfo.type );
  18910. // this.path = activeInfo.name; // DEBUG
  18911. },
  18912. PureArrayUniform = function( id, activeInfo, addr ) {
  18913. this.id = id;
  18914. this.addr = addr;
  18915. this.size = activeInfo.size;
  18916. this.setValue = getPureArraySetter( activeInfo.type );
  18917. // this.path = activeInfo.name; // DEBUG
  18918. },
  18919. StructuredUniform = function( id ) {
  18920. this.id = id;
  18921. UniformContainer.call( this ); // mix-in
  18922. };
  18923. StructuredUniform.prototype.setValue = function( gl, value ) {
  18924. // Note: Don't need an extra 'renderer' parameter, since samplers
  18925. // are not allowed in structured uniforms.
  18926. var seq = this.seq;
  18927. for ( var i = 0, n = seq.length; i !== n; ++ i ) {
  18928. var u = seq[ i ];
  18929. u.setValue( gl, value[ u.id ] );
  18930. }
  18931. };
  18932. // --- Top-level ---
  18933. // Parser - builds up the property tree from the path strings
  18934. var RePathPart = /([\w\d_]+)(\])?(\[|\.)?/g,
  18935. // extracts
  18936. // - the identifier (member name or array index)
  18937. // - followed by an optional right bracket (found when array index)
  18938. // - followed by an optional left bracket or dot (type of subscript)
  18939. //
  18940. // Note: These portions can be read in a non-overlapping fashion and
  18941. // allow straightforward parsing of the hierarchy that WebGL encodes
  18942. // in the uniform names.
  18943. addUniform = function( container, uniformObject ) {
  18944. container.seq.push( uniformObject );
  18945. container.map[ uniformObject.id ] = uniformObject;
  18946. },
  18947. parseUniform = function( activeInfo, addr, container ) {
  18948. var path = activeInfo.name,
  18949. pathLength = path.length;
  18950. // reset RegExp object, because of the early exit of a previous run
  18951. RePathPart.lastIndex = 0;
  18952. for (; ;) {
  18953. var match = RePathPart.exec( path ),
  18954. matchEnd = RePathPart.lastIndex,
  18955. id = match[ 1 ],
  18956. idIsIndex = match[ 2 ] === ']',
  18957. subscript = match[ 3 ];
  18958. if ( idIsIndex ) id = id | 0; // convert to integer
  18959. if ( subscript === undefined ||
  18960. subscript === '[' && matchEnd + 2 === pathLength ) {
  18961. // bare name or "pure" bottom-level array "[0]" suffix
  18962. addUniform( container, subscript === undefined ?
  18963. new SingleUniform( id, activeInfo, addr ) :
  18964. new PureArrayUniform( id, activeInfo, addr ) );
  18965. break;
  18966. } else {
  18967. // step into inner node / create it in case it doesn't exist
  18968. var map = container.map,
  18969. next = map[ id ];
  18970. if ( next === undefined ) {
  18971. next = new StructuredUniform( id );
  18972. addUniform( container, next );
  18973. }
  18974. container = next;
  18975. }
  18976. }
  18977. },
  18978. // Root Container
  18979. WebGLUniforms = function WebGLUniforms( gl, program, renderer ) {
  18980. UniformContainer.call( this );
  18981. this.renderer = renderer;
  18982. var n = gl.getProgramParameter( program, gl.ACTIVE_UNIFORMS );
  18983. for ( var i = 0; i !== n; ++ i ) {
  18984. var info = gl.getActiveUniform( program, i ),
  18985. path = info.name,
  18986. addr = gl.getUniformLocation( program, path );
  18987. parseUniform( info, addr, this );
  18988. }
  18989. };
  18990. WebGLUniforms.prototype.setValue = function( gl, name, value ) {
  18991. var u = this.map[ name ];
  18992. if ( u !== undefined ) u.setValue( gl, value, this.renderer );
  18993. };
  18994. WebGLUniforms.prototype.set = function( gl, object, name ) {
  18995. var u = this.map[ name ];
  18996. if ( u !== undefined ) u.setValue( gl, object[ name ], this.renderer );
  18997. };
  18998. WebGLUniforms.prototype.setOptional = function( gl, object, name ) {
  18999. var v = object[ name ];
  19000. if ( v !== undefined ) this.setValue( gl, name, v );
  19001. };
  19002. // Static interface
  19003. WebGLUniforms.upload = function( gl, seq, values, renderer ) {
  19004. for ( var i = 0, n = seq.length; i !== n; ++ i ) {
  19005. var u = seq[ i ],
  19006. v = values[ u.id ];
  19007. if ( v.needsUpdate !== false ) {
  19008. // note: always updating when .needsUpdate is undefined
  19009. u.setValue( gl, v.value, renderer );
  19010. }
  19011. }
  19012. };
  19013. WebGLUniforms.seqWithValue = function( seq, values ) {
  19014. var r = [];
  19015. for ( var i = 0, n = seq.length; i !== n; ++ i ) {
  19016. var u = seq[ i ];
  19017. if ( u.id in values ) r.push( u );
  19018. }
  19019. return r;
  19020. };
  19021. WebGLUniforms.splitDynamic = function( seq, values ) {
  19022. var r = null,
  19023. n = seq.length,
  19024. w = 0;
  19025. for ( var i = 0; i !== n; ++ i ) {
  19026. var u = seq[ i ],
  19027. v = values[ u.id ];
  19028. if ( v && v.dynamic === true ) {
  19029. if ( r === null ) r = [];
  19030. r.push( u );
  19031. } else {
  19032. // in-place compact 'seq', removing the matches
  19033. if ( w < i ) seq[ w ] = u;
  19034. ++ w;
  19035. }
  19036. }
  19037. if ( w < n ) seq.length = w;
  19038. return r;
  19039. };
  19040. WebGLUniforms.evalDynamic = function( seq, values, object, camera ) {
  19041. for ( var i = 0, n = seq.length; i !== n; ++ i ) {
  19042. var v = values[ seq[ i ].id ],
  19043. f = v.onUpdateCallback;
  19044. if ( f !== undefined ) f.call( v, object, camera );
  19045. }
  19046. };
  19047. return WebGLUniforms;
  19048. } )();
  19049. // File:src/renderers/webgl/plugins/LensFlarePlugin.js
  19050. /**
  19051. * @author mikael emtinger / http://gomo.se/
  19052. * @author alteredq / http://alteredqualia.com/
  19053. */
  19054. THREE.LensFlarePlugin = function ( renderer, flares ) {
  19055. var gl = renderer.context;
  19056. var state = renderer.state;
  19057. var vertexBuffer, elementBuffer;
  19058. var shader, program, attributes, uniforms;
  19059. var tempTexture, occlusionTexture;
  19060. function init() {
  19061. var vertices = new Float32Array( [
  19062. - 1, - 1, 0, 0,
  19063. 1, - 1, 1, 0,
  19064. 1, 1, 1, 1,
  19065. - 1, 1, 0, 1
  19066. ] );
  19067. var faces = new Uint16Array( [
  19068. 0, 1, 2,
  19069. 0, 2, 3
  19070. ] );
  19071. // buffers
  19072. vertexBuffer = gl.createBuffer();
  19073. elementBuffer = gl.createBuffer();
  19074. gl.bindBuffer( gl.ARRAY_BUFFER, vertexBuffer );
  19075. gl.bufferData( gl.ARRAY_BUFFER, vertices, gl.STATIC_DRAW );
  19076. gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, elementBuffer );
  19077. gl.bufferData( gl.ELEMENT_ARRAY_BUFFER, faces, gl.STATIC_DRAW );
  19078. // textures
  19079. tempTexture = gl.createTexture();
  19080. occlusionTexture = gl.createTexture();
  19081. state.bindTexture( gl.TEXTURE_2D, tempTexture );
  19082. gl.texImage2D( gl.TEXTURE_2D, 0, gl.RGB, 16, 16, 0, gl.RGB, gl.UNSIGNED_BYTE, null );
  19083. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE );
  19084. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE );
  19085. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST );
  19086. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST );
  19087. state.bindTexture( gl.TEXTURE_2D, occlusionTexture );
  19088. gl.texImage2D( gl.TEXTURE_2D, 0, gl.RGBA, 16, 16, 0, gl.RGBA, gl.UNSIGNED_BYTE, null );
  19089. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE );
  19090. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE );
  19091. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST );
  19092. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST );
  19093. shader = {
  19094. vertexShader: [
  19095. "uniform lowp int renderType;",
  19096. "uniform vec3 screenPosition;",
  19097. "uniform vec2 scale;",
  19098. "uniform float rotation;",
  19099. "uniform sampler2D occlusionMap;",
  19100. "attribute vec2 position;",
  19101. "attribute vec2 uv;",
  19102. "varying vec2 vUV;",
  19103. "varying float vVisibility;",
  19104. "void main() {",
  19105. "vUV = uv;",
  19106. "vec2 pos = position;",
  19107. "if ( renderType == 2 ) {",
  19108. "vec4 visibility = texture2D( occlusionMap, vec2( 0.1, 0.1 ) );",
  19109. "visibility += texture2D( occlusionMap, vec2( 0.5, 0.1 ) );",
  19110. "visibility += texture2D( occlusionMap, vec2( 0.9, 0.1 ) );",
  19111. "visibility += texture2D( occlusionMap, vec2( 0.9, 0.5 ) );",
  19112. "visibility += texture2D( occlusionMap, vec2( 0.9, 0.9 ) );",
  19113. "visibility += texture2D( occlusionMap, vec2( 0.5, 0.9 ) );",
  19114. "visibility += texture2D( occlusionMap, vec2( 0.1, 0.9 ) );",
  19115. "visibility += texture2D( occlusionMap, vec2( 0.1, 0.5 ) );",
  19116. "visibility += texture2D( occlusionMap, vec2( 0.5, 0.5 ) );",
  19117. "vVisibility = visibility.r / 9.0;",
  19118. "vVisibility *= 1.0 - visibility.g / 9.0;",
  19119. "vVisibility *= visibility.b / 9.0;",
  19120. "vVisibility *= 1.0 - visibility.a / 9.0;",
  19121. "pos.x = cos( rotation ) * position.x - sin( rotation ) * position.y;",
  19122. "pos.y = sin( rotation ) * position.x + cos( rotation ) * position.y;",
  19123. "}",
  19124. "gl_Position = vec4( ( pos * scale + screenPosition.xy ).xy, screenPosition.z, 1.0 );",
  19125. "}"
  19126. ].join( "\n" ),
  19127. fragmentShader: [
  19128. "uniform lowp int renderType;",
  19129. "uniform sampler2D map;",
  19130. "uniform float opacity;",
  19131. "uniform vec3 color;",
  19132. "varying vec2 vUV;",
  19133. "varying float vVisibility;",
  19134. "void main() {",
  19135. // pink square
  19136. "if ( renderType == 0 ) {",
  19137. "gl_FragColor = vec4( 1.0, 0.0, 1.0, 0.0 );",
  19138. // restore
  19139. "} else if ( renderType == 1 ) {",
  19140. "gl_FragColor = texture2D( map, vUV );",
  19141. // flare
  19142. "} else {",
  19143. "vec4 texture = texture2D( map, vUV );",
  19144. "texture.a *= opacity * vVisibility;",
  19145. "gl_FragColor = texture;",
  19146. "gl_FragColor.rgb *= color;",
  19147. "}",
  19148. "}"
  19149. ].join( "\n" )
  19150. };
  19151. program = createProgram( shader );
  19152. attributes = {
  19153. vertex: gl.getAttribLocation ( program, "position" ),
  19154. uv: gl.getAttribLocation ( program, "uv" )
  19155. };
  19156. uniforms = {
  19157. renderType: gl.getUniformLocation( program, "renderType" ),
  19158. map: gl.getUniformLocation( program, "map" ),
  19159. occlusionMap: gl.getUniformLocation( program, "occlusionMap" ),
  19160. opacity: gl.getUniformLocation( program, "opacity" ),
  19161. color: gl.getUniformLocation( program, "color" ),
  19162. scale: gl.getUniformLocation( program, "scale" ),
  19163. rotation: gl.getUniformLocation( program, "rotation" ),
  19164. screenPosition: gl.getUniformLocation( program, "screenPosition" )
  19165. };
  19166. }
  19167. /*
  19168. * Render lens flares
  19169. * Method: renders 16x16 0xff00ff-colored points scattered over the light source area,
  19170. * reads these back and calculates occlusion.
  19171. */
  19172. this.render = function ( scene, camera, viewport ) {
  19173. if ( flares.length === 0 ) return;
  19174. var tempPosition = new THREE.Vector3();
  19175. var invAspect = viewport.w / viewport.z,
  19176. halfViewportWidth = viewport.z * 0.5,
  19177. halfViewportHeight = viewport.w * 0.5;
  19178. var size = 16 / viewport.w,
  19179. scale = new THREE.Vector2( size * invAspect, size );
  19180. var screenPosition = new THREE.Vector3( 1, 1, 0 ),
  19181. screenPositionPixels = new THREE.Vector2( 1, 1 );
  19182. var validArea = new THREE.Box2();
  19183. validArea.min.set( 0, 0 );
  19184. validArea.max.set( viewport.z - 16, viewport.w - 16 );
  19185. if ( program === undefined ) {
  19186. init();
  19187. }
  19188. gl.useProgram( program );
  19189. state.initAttributes();
  19190. state.enableAttribute( attributes.vertex );
  19191. state.enableAttribute( attributes.uv );
  19192. state.disableUnusedAttributes();
  19193. // loop through all lens flares to update their occlusion and positions
  19194. // setup gl and common used attribs/uniforms
  19195. gl.uniform1i( uniforms.occlusionMap, 0 );
  19196. gl.uniform1i( uniforms.map, 1 );
  19197. gl.bindBuffer( gl.ARRAY_BUFFER, vertexBuffer );
  19198. gl.vertexAttribPointer( attributes.vertex, 2, gl.FLOAT, false, 2 * 8, 0 );
  19199. gl.vertexAttribPointer( attributes.uv, 2, gl.FLOAT, false, 2 * 8, 8 );
  19200. gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, elementBuffer );
  19201. state.disable( gl.CULL_FACE );
  19202. state.setDepthWrite( false );
  19203. for ( var i = 0, l = flares.length; i < l; i ++ ) {
  19204. size = 16 / viewport.w;
  19205. scale.set( size * invAspect, size );
  19206. // calc object screen position
  19207. var flare = flares[ i ];
  19208. tempPosition.set( flare.matrixWorld.elements[ 12 ], flare.matrixWorld.elements[ 13 ], flare.matrixWorld.elements[ 14 ] );
  19209. tempPosition.applyMatrix4( camera.matrixWorldInverse );
  19210. tempPosition.applyProjection( camera.projectionMatrix );
  19211. // setup arrays for gl programs
  19212. screenPosition.copy( tempPosition );
  19213. // horizontal and vertical coordinate of the lower left corner of the pixels to copy
  19214. screenPositionPixels.x = viewport.x + ( screenPosition.x * halfViewportWidth ) + halfViewportWidth - 8;
  19215. screenPositionPixels.y = viewport.y + ( screenPosition.y * halfViewportHeight ) + halfViewportHeight - 8;
  19216. // screen cull
  19217. if ( validArea.containsPoint( screenPositionPixels ) === true ) {
  19218. // save current RGB to temp texture
  19219. state.activeTexture( gl.TEXTURE0 );
  19220. state.bindTexture( gl.TEXTURE_2D, null );
  19221. state.activeTexture( gl.TEXTURE1 );
  19222. state.bindTexture( gl.TEXTURE_2D, tempTexture );
  19223. gl.copyTexImage2D( gl.TEXTURE_2D, 0, gl.RGB, screenPositionPixels.x, screenPositionPixels.y, 16, 16, 0 );
  19224. // render pink quad
  19225. gl.uniform1i( uniforms.renderType, 0 );
  19226. gl.uniform2f( uniforms.scale, scale.x, scale.y );
  19227. gl.uniform3f( uniforms.screenPosition, screenPosition.x, screenPosition.y, screenPosition.z );
  19228. state.disable( gl.BLEND );
  19229. state.enable( gl.DEPTH_TEST );
  19230. gl.drawElements( gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 );
  19231. // copy result to occlusionMap
  19232. state.activeTexture( gl.TEXTURE0 );
  19233. state.bindTexture( gl.TEXTURE_2D, occlusionTexture );
  19234. gl.copyTexImage2D( gl.TEXTURE_2D, 0, gl.RGBA, screenPositionPixels.x, screenPositionPixels.y, 16, 16, 0 );
  19235. // restore graphics
  19236. gl.uniform1i( uniforms.renderType, 1 );
  19237. state.disable( gl.DEPTH_TEST );
  19238. state.activeTexture( gl.TEXTURE1 );
  19239. state.bindTexture( gl.TEXTURE_2D, tempTexture );
  19240. gl.drawElements( gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 );
  19241. // update object positions
  19242. flare.positionScreen.copy( screenPosition );
  19243. if ( flare.customUpdateCallback ) {
  19244. flare.customUpdateCallback( flare );
  19245. } else {
  19246. flare.updateLensFlares();
  19247. }
  19248. // render flares
  19249. gl.uniform1i( uniforms.renderType, 2 );
  19250. state.enable( gl.BLEND );
  19251. for ( var j = 0, jl = flare.lensFlares.length; j < jl; j ++ ) {
  19252. var sprite = flare.lensFlares[ j ];
  19253. if ( sprite.opacity > 0.001 && sprite.scale > 0.001 ) {
  19254. screenPosition.x = sprite.x;
  19255. screenPosition.y = sprite.y;
  19256. screenPosition.z = sprite.z;
  19257. size = sprite.size * sprite.scale / viewport.w;
  19258. scale.x = size * invAspect;
  19259. scale.y = size;
  19260. gl.uniform3f( uniforms.screenPosition, screenPosition.x, screenPosition.y, screenPosition.z );
  19261. gl.uniform2f( uniforms.scale, scale.x, scale.y );
  19262. gl.uniform1f( uniforms.rotation, sprite.rotation );
  19263. gl.uniform1f( uniforms.opacity, sprite.opacity );
  19264. gl.uniform3f( uniforms.color, sprite.color.r, sprite.color.g, sprite.color.b );
  19265. state.setBlending( sprite.blending, sprite.blendEquation, sprite.blendSrc, sprite.blendDst );
  19266. renderer.setTexture2D( sprite.texture, 1 );
  19267. gl.drawElements( gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 );
  19268. }
  19269. }
  19270. }
  19271. }
  19272. // restore gl
  19273. state.enable( gl.CULL_FACE );
  19274. state.enable( gl.DEPTH_TEST );
  19275. state.setDepthWrite( true );
  19276. renderer.resetGLState();
  19277. };
  19278. function createProgram ( shader ) {
  19279. var program = gl.createProgram();
  19280. var fragmentShader = gl.createShader( gl.FRAGMENT_SHADER );
  19281. var vertexShader = gl.createShader( gl.VERTEX_SHADER );
  19282. var prefix = "precision " + renderer.getPrecision() + " float;\n";
  19283. gl.shaderSource( fragmentShader, prefix + shader.fragmentShader );
  19284. gl.shaderSource( vertexShader, prefix + shader.vertexShader );
  19285. gl.compileShader( fragmentShader );
  19286. gl.compileShader( vertexShader );
  19287. gl.attachShader( program, fragmentShader );
  19288. gl.attachShader( program, vertexShader );
  19289. gl.linkProgram( program );
  19290. return program;
  19291. }
  19292. };
  19293. // File:src/renderers/webgl/plugins/SpritePlugin.js
  19294. /**
  19295. * @author mikael emtinger / http://gomo.se/
  19296. * @author alteredq / http://alteredqualia.com/
  19297. */
  19298. THREE.SpritePlugin = function ( renderer, sprites ) {
  19299. var gl = renderer.context;
  19300. var state = renderer.state;
  19301. var vertexBuffer, elementBuffer;
  19302. var program, attributes, uniforms;
  19303. var texture;
  19304. // decompose matrixWorld
  19305. var spritePosition = new THREE.Vector3();
  19306. var spriteRotation = new THREE.Quaternion();
  19307. var spriteScale = new THREE.Vector3();
  19308. function init() {
  19309. var vertices = new Float32Array( [
  19310. - 0.5, - 0.5, 0, 0,
  19311. 0.5, - 0.5, 1, 0,
  19312. 0.5, 0.5, 1, 1,
  19313. - 0.5, 0.5, 0, 1
  19314. ] );
  19315. var faces = new Uint16Array( [
  19316. 0, 1, 2,
  19317. 0, 2, 3
  19318. ] );
  19319. vertexBuffer = gl.createBuffer();
  19320. elementBuffer = gl.createBuffer();
  19321. gl.bindBuffer( gl.ARRAY_BUFFER, vertexBuffer );
  19322. gl.bufferData( gl.ARRAY_BUFFER, vertices, gl.STATIC_DRAW );
  19323. gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, elementBuffer );
  19324. gl.bufferData( gl.ELEMENT_ARRAY_BUFFER, faces, gl.STATIC_DRAW );
  19325. program = createProgram();
  19326. attributes = {
  19327. position: gl.getAttribLocation ( program, 'position' ),
  19328. uv: gl.getAttribLocation ( program, 'uv' )
  19329. };
  19330. uniforms = {
  19331. uvOffset: gl.getUniformLocation( program, 'uvOffset' ),
  19332. uvScale: gl.getUniformLocation( program, 'uvScale' ),
  19333. rotation: gl.getUniformLocation( program, 'rotation' ),
  19334. scale: gl.getUniformLocation( program, 'scale' ),
  19335. color: gl.getUniformLocation( program, 'color' ),
  19336. map: gl.getUniformLocation( program, 'map' ),
  19337. opacity: gl.getUniformLocation( program, 'opacity' ),
  19338. modelViewMatrix: gl.getUniformLocation( program, 'modelViewMatrix' ),
  19339. projectionMatrix: gl.getUniformLocation( program, 'projectionMatrix' ),
  19340. fogType: gl.getUniformLocation( program, 'fogType' ),
  19341. fogDensity: gl.getUniformLocation( program, 'fogDensity' ),
  19342. fogNear: gl.getUniformLocation( program, 'fogNear' ),
  19343. fogFar: gl.getUniformLocation( program, 'fogFar' ),
  19344. fogColor: gl.getUniformLocation( program, 'fogColor' ),
  19345. alphaTest: gl.getUniformLocation( program, 'alphaTest' )
  19346. };
  19347. var canvas = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' );
  19348. canvas.width = 8;
  19349. canvas.height = 8;
  19350. var context = canvas.getContext( '2d' );
  19351. context.fillStyle = 'white';
  19352. context.fillRect( 0, 0, 8, 8 );
  19353. texture = new THREE.Texture( canvas );
  19354. texture.needsUpdate = true;
  19355. }
  19356. this.render = function ( scene, camera ) {
  19357. if ( sprites.length === 0 ) return;
  19358. // setup gl
  19359. if ( program === undefined ) {
  19360. init();
  19361. }
  19362. gl.useProgram( program );
  19363. state.initAttributes();
  19364. state.enableAttribute( attributes.position );
  19365. state.enableAttribute( attributes.uv );
  19366. state.disableUnusedAttributes();
  19367. state.disable( gl.CULL_FACE );
  19368. state.enable( gl.BLEND );
  19369. gl.bindBuffer( gl.ARRAY_BUFFER, vertexBuffer );
  19370. gl.vertexAttribPointer( attributes.position, 2, gl.FLOAT, false, 2 * 8, 0 );
  19371. gl.vertexAttribPointer( attributes.uv, 2, gl.FLOAT, false, 2 * 8, 8 );
  19372. gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, elementBuffer );
  19373. gl.uniformMatrix4fv( uniforms.projectionMatrix, false, camera.projectionMatrix.elements );
  19374. state.activeTexture( gl.TEXTURE0 );
  19375. gl.uniform1i( uniforms.map, 0 );
  19376. var oldFogType = 0;
  19377. var sceneFogType = 0;
  19378. var fog = scene.fog;
  19379. if ( fog ) {
  19380. gl.uniform3f( uniforms.fogColor, fog.color.r, fog.color.g, fog.color.b );
  19381. if ( fog instanceof THREE.Fog ) {
  19382. gl.uniform1f( uniforms.fogNear, fog.near );
  19383. gl.uniform1f( uniforms.fogFar, fog.far );
  19384. gl.uniform1i( uniforms.fogType, 1 );
  19385. oldFogType = 1;
  19386. sceneFogType = 1;
  19387. } else if ( fog instanceof THREE.FogExp2 ) {
  19388. gl.uniform1f( uniforms.fogDensity, fog.density );
  19389. gl.uniform1i( uniforms.fogType, 2 );
  19390. oldFogType = 2;
  19391. sceneFogType = 2;
  19392. }
  19393. } else {
  19394. gl.uniform1i( uniforms.fogType, 0 );
  19395. oldFogType = 0;
  19396. sceneFogType = 0;
  19397. }
  19398. // update positions and sort
  19399. for ( var i = 0, l = sprites.length; i < l; i ++ ) {
  19400. var sprite = sprites[ i ];
  19401. sprite.modelViewMatrix.multiplyMatrices( camera.matrixWorldInverse, sprite.matrixWorld );
  19402. sprite.z = - sprite.modelViewMatrix.elements[ 14 ];
  19403. }
  19404. sprites.sort( painterSortStable );
  19405. // render all sprites
  19406. var scale = [];
  19407. for ( var i = 0, l = sprites.length; i < l; i ++ ) {
  19408. var sprite = sprites[ i ];
  19409. var material = sprite.material;
  19410. gl.uniform1f( uniforms.alphaTest, material.alphaTest );
  19411. gl.uniformMatrix4fv( uniforms.modelViewMatrix, false, sprite.modelViewMatrix.elements );
  19412. sprite.matrixWorld.decompose( spritePosition, spriteRotation, spriteScale );
  19413. scale[ 0 ] = spriteScale.x;
  19414. scale[ 1 ] = spriteScale.y;
  19415. var fogType = 0;
  19416. if ( scene.fog && material.fog ) {
  19417. fogType = sceneFogType;
  19418. }
  19419. if ( oldFogType !== fogType ) {
  19420. gl.uniform1i( uniforms.fogType, fogType );
  19421. oldFogType = fogType;
  19422. }
  19423. if ( material.map !== null ) {
  19424. gl.uniform2f( uniforms.uvOffset, material.map.offset.x, material.map.offset.y );
  19425. gl.uniform2f( uniforms.uvScale, material.map.repeat.x, material.map.repeat.y );
  19426. } else {
  19427. gl.uniform2f( uniforms.uvOffset, 0, 0 );
  19428. gl.uniform2f( uniforms.uvScale, 1, 1 );
  19429. }
  19430. gl.uniform1f( uniforms.opacity, material.opacity );
  19431. gl.uniform3f( uniforms.color, material.color.r, material.color.g, material.color.b );
  19432. gl.uniform1f( uniforms.rotation, material.rotation );
  19433. gl.uniform2fv( uniforms.scale, scale );
  19434. state.setBlending( material.blending, material.blendEquation, material.blendSrc, material.blendDst );
  19435. state.setDepthTest( material.depthTest );
  19436. state.setDepthWrite( material.depthWrite );
  19437. if ( material.map ) {
  19438. renderer.setTexture2D( material.map, 0 );
  19439. } else {
  19440. renderer.setTexture2D( texture, 0 );
  19441. }
  19442. gl.drawElements( gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 );
  19443. }
  19444. // restore gl
  19445. state.enable( gl.CULL_FACE );
  19446. renderer.resetGLState();
  19447. };
  19448. function createProgram () {
  19449. var program = gl.createProgram();
  19450. var vertexShader = gl.createShader( gl.VERTEX_SHADER );
  19451. var fragmentShader = gl.createShader( gl.FRAGMENT_SHADER );
  19452. gl.shaderSource( vertexShader, [
  19453. 'precision ' + renderer.getPrecision() + ' float;',
  19454. 'uniform mat4 modelViewMatrix;',
  19455. 'uniform mat4 projectionMatrix;',
  19456. 'uniform float rotation;',
  19457. 'uniform vec2 scale;',
  19458. 'uniform vec2 uvOffset;',
  19459. 'uniform vec2 uvScale;',
  19460. 'attribute vec2 position;',
  19461. 'attribute vec2 uv;',
  19462. 'varying vec2 vUV;',
  19463. 'void main() {',
  19464. 'vUV = uvOffset + uv * uvScale;',
  19465. 'vec2 alignedPosition = position * scale;',
  19466. 'vec2 rotatedPosition;',
  19467. 'rotatedPosition.x = cos( rotation ) * alignedPosition.x - sin( rotation ) * alignedPosition.y;',
  19468. 'rotatedPosition.y = sin( rotation ) * alignedPosition.x + cos( rotation ) * alignedPosition.y;',
  19469. 'vec4 finalPosition;',
  19470. 'finalPosition = modelViewMatrix * vec4( 0.0, 0.0, 0.0, 1.0 );',
  19471. 'finalPosition.xy += rotatedPosition;',
  19472. 'finalPosition = projectionMatrix * finalPosition;',
  19473. 'gl_Position = finalPosition;',
  19474. '}'
  19475. ].join( '\n' ) );
  19476. gl.shaderSource( fragmentShader, [
  19477. 'precision ' + renderer.getPrecision() + ' float;',
  19478. 'uniform vec3 color;',
  19479. 'uniform sampler2D map;',
  19480. 'uniform float opacity;',
  19481. 'uniform int fogType;',
  19482. 'uniform vec3 fogColor;',
  19483. 'uniform float fogDensity;',
  19484. 'uniform float fogNear;',
  19485. 'uniform float fogFar;',
  19486. 'uniform float alphaTest;',
  19487. 'varying vec2 vUV;',
  19488. 'void main() {',
  19489. 'vec4 texture = texture2D( map, vUV );',
  19490. 'if ( texture.a < alphaTest ) discard;',
  19491. 'gl_FragColor = vec4( color * texture.xyz, texture.a * opacity );',
  19492. 'if ( fogType > 0 ) {',
  19493. 'float depth = gl_FragCoord.z / gl_FragCoord.w;',
  19494. 'float fogFactor = 0.0;',
  19495. 'if ( fogType == 1 ) {',
  19496. 'fogFactor = smoothstep( fogNear, fogFar, depth );',
  19497. '} else {',
  19498. 'const float LOG2 = 1.442695;',
  19499. 'fogFactor = exp2( - fogDensity * fogDensity * depth * depth * LOG2 );',
  19500. 'fogFactor = 1.0 - clamp( fogFactor, 0.0, 1.0 );',
  19501. '}',
  19502. 'gl_FragColor = mix( gl_FragColor, vec4( fogColor, gl_FragColor.w ), fogFactor );',
  19503. '}',
  19504. '}'
  19505. ].join( '\n' ) );
  19506. gl.compileShader( vertexShader );
  19507. gl.compileShader( fragmentShader );
  19508. gl.attachShader( program, vertexShader );
  19509. gl.attachShader( program, fragmentShader );
  19510. gl.linkProgram( program );
  19511. return program;
  19512. }
  19513. function painterSortStable ( a, b ) {
  19514. if ( a.renderOrder !== b.renderOrder ) {
  19515. return a.renderOrder - b.renderOrder;
  19516. } else if ( a.z !== b.z ) {
  19517. return b.z - a.z;
  19518. } else {
  19519. return b.id - a.id;
  19520. }
  19521. }
  19522. };
  19523. // File:src/Three.Legacy.js
  19524. /**
  19525. * @author mrdoob / http://mrdoob.com/
  19526. */
  19527. Object.assign( THREE, {
  19528. Face4: function ( a, b, c, d, normal, color, materialIndex ) {
  19529. console.warn( 'THREE.Face4 has been removed. A THREE.Face3 will be created instead.' );
  19530. return new THREE.Face3( a, b, c, normal, color, materialIndex );
  19531. },
  19532. LineStrip: 0,
  19533. LinePieces: 1,
  19534. MeshFaceMaterial: THREE.MultiMaterial,
  19535. PointCloud: function ( geometry, material ) {
  19536. console.warn( 'THREE.PointCloud has been renamed to THREE.Points.' );
  19537. return new THREE.Points( geometry, material );
  19538. },
  19539. Particle: THREE.Sprite,
  19540. ParticleSystem: function ( geometry, material ) {
  19541. console.warn( 'THREE.ParticleSystem has been renamed to THREE.Points.' );
  19542. return new THREE.Points( geometry, material );
  19543. },
  19544. PointCloudMaterial: function ( parameters ) {
  19545. console.warn( 'THREE.PointCloudMaterial has been renamed to THREE.PointsMaterial.' );
  19546. return new THREE.PointsMaterial( parameters );
  19547. },
  19548. ParticleBasicMaterial: function ( parameters ) {
  19549. console.warn( 'THREE.ParticleBasicMaterial has been renamed to THREE.PointsMaterial.' );
  19550. return new THREE.PointsMaterial( parameters );
  19551. },
  19552. ParticleSystemMaterial: function ( parameters ) {
  19553. console.warn( 'THREE.ParticleSystemMaterial has been renamed to THREE.PointsMaterial.' );
  19554. return new THREE.PointsMaterial( parameters );
  19555. },
  19556. Vertex: function ( x, y, z ) {
  19557. console.warn( 'THREE.Vertex has been removed. Use THREE.Vector3 instead.' );
  19558. return new THREE.Vector3( x, y, z );
  19559. }
  19560. } );
  19561. //
  19562. Object.assign( THREE.Box2.prototype, {
  19563. empty: function () {
  19564. console.warn( 'THREE.Box2: .empty() has been renamed to .isEmpty().' );
  19565. return this.isEmpty();
  19566. },
  19567. isIntersectionBox: function ( box ) {
  19568. console.warn( 'THREE.Box2: .isIntersectionBox() has been renamed to .intersectsBox().' );
  19569. return this.intersectsBox( box );
  19570. }
  19571. } );
  19572. Object.assign( THREE.Box3.prototype, {
  19573. empty: function () {
  19574. console.warn( 'THREE.Box3: .empty() has been renamed to .isEmpty().' );
  19575. return this.isEmpty();
  19576. },
  19577. isIntersectionBox: function ( box ) {
  19578. console.warn( 'THREE.Box3: .isIntersectionBox() has been renamed to .intersectsBox().' );
  19579. return this.intersectsBox( box );
  19580. },
  19581. isIntersectionSphere: function ( sphere ) {
  19582. console.warn( 'THREE.Box3: .isIntersectionSphere() has been renamed to .intersectsSphere().' );
  19583. return this.intersectsSphere( sphere );
  19584. }
  19585. } );
  19586. Object.assign( THREE.Matrix3.prototype, {
  19587. multiplyVector3: function ( vector ) {
  19588. console.warn( 'THREE.Matrix3: .multiplyVector3() has been removed. Use vector.applyMatrix3( matrix ) instead.' );
  19589. return vector.applyMatrix3( this );
  19590. },
  19591. multiplyVector3Array: function ( a ) {
  19592. console.warn( 'THREE.Matrix3: .multiplyVector3Array() has been renamed. Use matrix.applyToVector3Array( array ) instead.' );
  19593. return this.applyToVector3Array( a );
  19594. }
  19595. } );
  19596. Object.assign( THREE.Matrix4.prototype, {
  19597. extractPosition: function ( m ) {
  19598. console.warn( 'THREE.Matrix4: .extractPosition() has been renamed to .copyPosition().' );
  19599. return this.copyPosition( m );
  19600. },
  19601. setRotationFromQuaternion: function ( q ) {
  19602. console.warn( 'THREE.Matrix4: .setRotationFromQuaternion() has been renamed to .makeRotationFromQuaternion().' );
  19603. return this.makeRotationFromQuaternion( q );
  19604. },
  19605. multiplyVector3: function ( vector ) {
  19606. console.warn( 'THREE.Matrix4: .multiplyVector3() has been removed. Use vector.applyMatrix4( matrix ) or vector.applyProjection( matrix ) instead.' );
  19607. return vector.applyProjection( this );
  19608. },
  19609. multiplyVector4: function ( vector ) {
  19610. console.warn( 'THREE.Matrix4: .multiplyVector4() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
  19611. return vector.applyMatrix4( this );
  19612. },
  19613. multiplyVector3Array: function ( a ) {
  19614. console.warn( 'THREE.Matrix4: .multiplyVector3Array() has been renamed. Use matrix.applyToVector3Array( array ) instead.' );
  19615. return this.applyToVector3Array( a );
  19616. },
  19617. rotateAxis: function ( v ) {
  19618. console.warn( 'THREE.Matrix4: .rotateAxis() has been removed. Use Vector3.transformDirection( matrix ) instead.' );
  19619. v.transformDirection( this );
  19620. },
  19621. crossVector: function ( vector ) {
  19622. console.warn( 'THREE.Matrix4: .crossVector() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
  19623. return vector.applyMatrix4( this );
  19624. },
  19625. translate: function ( v ) {
  19626. console.error( 'THREE.Matrix4: .translate() has been removed.' );
  19627. },
  19628. rotateX: function ( angle ) {
  19629. console.error( 'THREE.Matrix4: .rotateX() has been removed.' );
  19630. },
  19631. rotateY: function ( angle ) {
  19632. console.error( 'THREE.Matrix4: .rotateY() has been removed.' );
  19633. },
  19634. rotateZ: function ( angle ) {
  19635. console.error( 'THREE.Matrix4: .rotateZ() has been removed.' );
  19636. },
  19637. rotateByAxis: function ( axis, angle ) {
  19638. console.error( 'THREE.Matrix4: .rotateByAxis() has been removed.' );
  19639. }
  19640. } );
  19641. Object.assign( THREE.Plane.prototype, {
  19642. isIntersectionLine: function ( line ) {
  19643. console.warn( 'THREE.Plane: .isIntersectionLine() has been renamed to .intersectsLine().' );
  19644. return this.intersectsLine( line );
  19645. }
  19646. } );
  19647. Object.assign( THREE.Quaternion.prototype, {
  19648. multiplyVector3: function ( vector ) {
  19649. console.warn( 'THREE.Quaternion: .multiplyVector3() has been removed. Use is now vector.applyQuaternion( quaternion ) instead.' );
  19650. return vector.applyQuaternion( this );
  19651. }
  19652. } );
  19653. Object.assign( THREE.Ray.prototype, {
  19654. isIntersectionBox: function ( box ) {
  19655. console.warn( 'THREE.Ray: .isIntersectionBox() has been renamed to .intersectsBox().' );
  19656. return this.intersectsBox( box );
  19657. },
  19658. isIntersectionPlane: function ( plane ) {
  19659. console.warn( 'THREE.Ray: .isIntersectionPlane() has been renamed to .intersectsPlane().' );
  19660. return this.intersectsPlane( plane );
  19661. },
  19662. isIntersectionSphere: function ( sphere ) {
  19663. console.warn( 'THREE.Ray: .isIntersectionSphere() has been renamed to .intersectsSphere().' );
  19664. return this.intersectsSphere( sphere );
  19665. }
  19666. } );
  19667. Object.assign( THREE.Vector3.prototype, {
  19668. setEulerFromRotationMatrix: function () {
  19669. console.error( 'THREE.Vector3: .setEulerFromRotationMatrix() has been removed. Use Euler.setFromRotationMatrix() instead.' );
  19670. },
  19671. setEulerFromQuaternion: function () {
  19672. console.error( 'THREE.Vector3: .setEulerFromQuaternion() has been removed. Use Euler.setFromQuaternion() instead.' );
  19673. },
  19674. getPositionFromMatrix: function ( m ) {
  19675. console.warn( 'THREE.Vector3: .getPositionFromMatrix() has been renamed to .setFromMatrixPosition().' );
  19676. return this.setFromMatrixPosition( m );
  19677. },
  19678. getScaleFromMatrix: function ( m ) {
  19679. console.warn( 'THREE.Vector3: .getScaleFromMatrix() has been renamed to .setFromMatrixScale().' );
  19680. return this.setFromMatrixScale( m );
  19681. },
  19682. getColumnFromMatrix: function ( index, matrix ) {
  19683. console.warn( 'THREE.Vector3: .getColumnFromMatrix() has been renamed to .setFromMatrixColumn().' );
  19684. return this.setFromMatrixColumn( matrix, index );
  19685. }
  19686. } );
  19687. //
  19688. Object.assign( THREE.Object3D.prototype, {
  19689. getChildByName: function ( name ) {
  19690. console.warn( 'THREE.Object3D: .getChildByName() has been renamed to .getObjectByName().' );
  19691. return this.getObjectByName( name );
  19692. },
  19693. renderDepth: function ( value ) {
  19694. console.warn( 'THREE.Object3D: .renderDepth has been removed. Use .renderOrder, instead.' );
  19695. },
  19696. translate: function ( distance, axis ) {
  19697. console.warn( 'THREE.Object3D: .translate() has been removed. Use .translateOnAxis( axis, distance ) instead.' );
  19698. return this.translateOnAxis( axis, distance );
  19699. }
  19700. } );
  19701. Object.defineProperties( THREE.Object3D.prototype, {
  19702. eulerOrder: {
  19703. get: function () {
  19704. console.warn( 'THREE.Object3D: .eulerOrder is now .rotation.order.' );
  19705. return this.rotation.order;
  19706. },
  19707. set: function ( value ) {
  19708. console.warn( 'THREE.Object3D: .eulerOrder is now .rotation.order.' );
  19709. this.rotation.order = value;
  19710. }
  19711. },
  19712. useQuaternion: {
  19713. get: function () {
  19714. console.warn( 'THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.' );
  19715. },
  19716. set: function ( value ) {
  19717. console.warn( 'THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.' );
  19718. }
  19719. }
  19720. } );
  19721. Object.defineProperties( THREE.LOD.prototype, {
  19722. objects: {
  19723. get: function () {
  19724. console.warn( 'THREE.LOD: .objects has been renamed to .levels.' );
  19725. return this.levels;
  19726. }
  19727. }
  19728. } );
  19729. //
  19730. THREE.PerspectiveCamera.prototype.setLens = function ( focalLength, filmGauge ) {
  19731. console.warn( "THREE.PerspectiveCamera.setLens is deprecated. " +
  19732. "Use .setFocalLength and .filmGauge for a photographic setup." );
  19733. if ( filmGauge !== undefined ) this.filmGauge = filmGauge;
  19734. this.setFocalLength( focalLength );
  19735. };
  19736. //
  19737. Object.defineProperties( THREE.Light.prototype, {
  19738. onlyShadow: {
  19739. set: function ( value ) {
  19740. console.warn( 'THREE.Light: .onlyShadow has been removed.' );
  19741. }
  19742. },
  19743. shadowCameraFov: {
  19744. set: function ( value ) {
  19745. console.warn( 'THREE.Light: .shadowCameraFov is now .shadow.camera.fov.' );
  19746. this.shadow.camera.fov = value;
  19747. }
  19748. },
  19749. shadowCameraLeft: {
  19750. set: function ( value ) {
  19751. console.warn( 'THREE.Light: .shadowCameraLeft is now .shadow.camera.left.' );
  19752. this.shadow.camera.left = value;
  19753. }
  19754. },
  19755. shadowCameraRight: {
  19756. set: function ( value ) {
  19757. console.warn( 'THREE.Light: .shadowCameraRight is now .shadow.camera.right.' );
  19758. this.shadow.camera.right = value;
  19759. }
  19760. },
  19761. shadowCameraTop: {
  19762. set: function ( value ) {
  19763. console.warn( 'THREE.Light: .shadowCameraTop is now .shadow.camera.top.' );
  19764. this.shadow.camera.top = value;
  19765. }
  19766. },
  19767. shadowCameraBottom: {
  19768. set: function ( value ) {
  19769. console.warn( 'THREE.Light: .shadowCameraBottom is now .shadow.camera.bottom.' );
  19770. this.shadow.camera.bottom = value;
  19771. }
  19772. },
  19773. shadowCameraNear: {
  19774. set: function ( value ) {
  19775. console.warn( 'THREE.Light: .shadowCameraNear is now .shadow.camera.near.' );
  19776. this.shadow.camera.near = value;
  19777. }
  19778. },
  19779. shadowCameraFar: {
  19780. set: function ( value ) {
  19781. console.warn( 'THREE.Light: .shadowCameraFar is now .shadow.camera.far.' );
  19782. this.shadow.camera.far = value;
  19783. }
  19784. },
  19785. shadowCameraVisible: {
  19786. set: function ( value ) {
  19787. console.warn( 'THREE.Light: .shadowCameraVisible has been removed. Use new THREE.CameraHelper( light.shadow.camera ) instead.' );
  19788. }
  19789. },
  19790. shadowBias: {
  19791. set: function ( value ) {
  19792. console.warn( 'THREE.Light: .shadowBias is now .shadow.bias.' );
  19793. this.shadow.bias = value;
  19794. }
  19795. },
  19796. shadowDarkness: {
  19797. set: function ( value ) {
  19798. console.warn( 'THREE.Light: .shadowDarkness has been removed.' );
  19799. }
  19800. },
  19801. shadowMapWidth: {
  19802. set: function ( value ) {
  19803. console.warn( 'THREE.Light: .shadowMapWidth is now .shadow.mapSize.width.' );
  19804. this.shadow.mapSize.width = value;
  19805. }
  19806. },
  19807. shadowMapHeight: {
  19808. set: function ( value ) {
  19809. console.warn( 'THREE.Light: .shadowMapHeight is now .shadow.mapSize.height.' );
  19810. this.shadow.mapSize.height = value;
  19811. }
  19812. }
  19813. } );
  19814. //
  19815. Object.defineProperties( THREE.BufferAttribute.prototype, {
  19816. length: {
  19817. get: function () {
  19818. console.warn( 'THREE.BufferAttribute: .length has been deprecated. Please use .count.' );
  19819. return this.array.length;
  19820. }
  19821. }
  19822. } );
  19823. Object.assign( THREE.BufferGeometry.prototype, {
  19824. addIndex: function ( index ) {
  19825. console.warn( 'THREE.BufferGeometry: .addIndex() has been renamed to .setIndex().' );
  19826. this.setIndex( index );
  19827. },
  19828. addDrawCall: function ( start, count, indexOffset ) {
  19829. if ( indexOffset !== undefined ) {
  19830. console.warn( 'THREE.BufferGeometry: .addDrawCall() no longer supports indexOffset.' );
  19831. }
  19832. console.warn( 'THREE.BufferGeometry: .addDrawCall() is now .addGroup().' );
  19833. this.addGroup( start, count );
  19834. },
  19835. clearDrawCalls: function () {
  19836. console.warn( 'THREE.BufferGeometry: .clearDrawCalls() is now .clearGroups().' );
  19837. this.clearGroups();
  19838. },
  19839. computeTangents: function () {
  19840. console.warn( 'THREE.BufferGeometry: .computeTangents() has been removed.' );
  19841. },
  19842. computeOffsets: function () {
  19843. console.warn( 'THREE.BufferGeometry: .computeOffsets() has been removed.' );
  19844. }
  19845. } );
  19846. Object.defineProperties( THREE.BufferGeometry.prototype, {
  19847. drawcalls: {
  19848. get: function () {
  19849. console.error( 'THREE.BufferGeometry: .drawcalls has been renamed to .groups.' );
  19850. return this.groups;
  19851. }
  19852. },
  19853. offsets: {
  19854. get: function () {
  19855. console.warn( 'THREE.BufferGeometry: .offsets has been renamed to .groups.' );
  19856. return this.groups;
  19857. }
  19858. }
  19859. } );
  19860. //
  19861. Object.defineProperties( THREE.Material.prototype, {
  19862. wrapAround: {
  19863. get: function () {
  19864. console.warn( 'THREE.' + this.type + ': .wrapAround has been removed.' );
  19865. },
  19866. set: function ( value ) {
  19867. console.warn( 'THREE.' + this.type + ': .wrapAround has been removed.' );
  19868. }
  19869. },
  19870. wrapRGB: {
  19871. get: function () {
  19872. console.warn( 'THREE.' + this.type + ': .wrapRGB has been removed.' );
  19873. return new THREE.Color();
  19874. }
  19875. }
  19876. } );
  19877. Object.defineProperties( THREE.MeshPhongMaterial.prototype, {
  19878. metal: {
  19879. get: function () {
  19880. console.warn( 'THREE.MeshPhongMaterial: .metal has been removed. Use THREE.MeshStandardMaterial instead.' );
  19881. return false;
  19882. },
  19883. set: function ( value ) {
  19884. console.warn( 'THREE.MeshPhongMaterial: .metal has been removed. Use THREE.MeshStandardMaterial instead' );
  19885. }
  19886. }
  19887. } );
  19888. Object.defineProperties( THREE.ShaderMaterial.prototype, {
  19889. derivatives: {
  19890. get: function () {
  19891. console.warn( 'THREE.ShaderMaterial: .derivatives has been moved to .extensions.derivatives.' );
  19892. return this.extensions.derivatives;
  19893. },
  19894. set: function ( value ) {
  19895. console.warn( 'THREE. ShaderMaterial: .derivatives has been moved to .extensions.derivatives.' );
  19896. this.extensions.derivatives = value;
  19897. }
  19898. }
  19899. } );
  19900. //
  19901. THREE.EventDispatcher.prototype = Object.assign( Object.create( {
  19902. // Note: Extra base ensures these properties are not 'assign'ed.
  19903. constructor: THREE.EventDispatcher,
  19904. apply: function ( target ) {
  19905. console.warn( "THREE.EventDispatcher: .apply is deprecated, " +
  19906. "just inherit or Object.assign the prototype to mix-in." );
  19907. Object.assign( target, this );
  19908. }
  19909. } ), THREE.EventDispatcher.prototype );
  19910. //
  19911. Object.assign( THREE.WebGLRenderer.prototype, {
  19912. supportsFloatTextures: function () {
  19913. console.warn( 'THREE.WebGLRenderer: .supportsFloatTextures() is now .extensions.get( \'OES_texture_float\' ).' );
  19914. return this.extensions.get( 'OES_texture_float' );
  19915. },
  19916. supportsHalfFloatTextures: function () {
  19917. console.warn( 'THREE.WebGLRenderer: .supportsHalfFloatTextures() is now .extensions.get( \'OES_texture_half_float\' ).' );
  19918. return this.extensions.get( 'OES_texture_half_float' );
  19919. },
  19920. supportsStandardDerivatives: function () {
  19921. console.warn( 'THREE.WebGLRenderer: .supportsStandardDerivatives() is now .extensions.get( \'OES_standard_derivatives\' ).' );
  19922. return this.extensions.get( 'OES_standard_derivatives' );
  19923. },
  19924. supportsCompressedTextureS3TC: function () {
  19925. console.warn( 'THREE.WebGLRenderer: .supportsCompressedTextureS3TC() is now .extensions.get( \'WEBGL_compressed_texture_s3tc\' ).' );
  19926. return this.extensions.get( 'WEBGL_compressed_texture_s3tc' );
  19927. },
  19928. supportsCompressedTexturePVRTC: function () {
  19929. console.warn( 'THREE.WebGLRenderer: .supportsCompressedTexturePVRTC() is now .extensions.get( \'WEBGL_compressed_texture_pvrtc\' ).' );
  19930. return this.extensions.get( 'WEBGL_compressed_texture_pvrtc' );
  19931. },
  19932. supportsBlendMinMax: function () {
  19933. console.warn( 'THREE.WebGLRenderer: .supportsBlendMinMax() is now .extensions.get( \'EXT_blend_minmax\' ).' );
  19934. return this.extensions.get( 'EXT_blend_minmax' );
  19935. },
  19936. supportsVertexTextures: function () {
  19937. return this.capabilities.vertexTextures;
  19938. },
  19939. supportsInstancedArrays: function () {
  19940. console.warn( 'THREE.WebGLRenderer: .supportsInstancedArrays() is now .extensions.get( \'ANGLE_instanced_arrays\' ).' );
  19941. return this.extensions.get( 'ANGLE_instanced_arrays' );
  19942. },
  19943. enableScissorTest: function ( boolean ) {
  19944. console.warn( 'THREE.WebGLRenderer: .enableScissorTest() is now .setScissorTest().' );
  19945. this.setScissorTest( boolean );
  19946. },
  19947. initMaterial: function () {
  19948. console.warn( 'THREE.WebGLRenderer: .initMaterial() has been removed.' );
  19949. },
  19950. addPrePlugin: function () {
  19951. console.warn( 'THREE.WebGLRenderer: .addPrePlugin() has been removed.' );
  19952. },
  19953. addPostPlugin: function () {
  19954. console.warn( 'THREE.WebGLRenderer: .addPostPlugin() has been removed.' );
  19955. },
  19956. updateShadowMap: function () {
  19957. console.warn( 'THREE.WebGLRenderer: .updateShadowMap() has been removed.' );
  19958. }
  19959. } );
  19960. Object.defineProperties( THREE.WebGLRenderer.prototype, {
  19961. shadowMapEnabled: {
  19962. get: function () {
  19963. return this.shadowMap.enabled;
  19964. },
  19965. set: function ( value ) {
  19966. console.warn( 'THREE.WebGLRenderer: .shadowMapEnabled is now .shadowMap.enabled.' );
  19967. this.shadowMap.enabled = value;
  19968. }
  19969. },
  19970. shadowMapType: {
  19971. get: function () {
  19972. return this.shadowMap.type;
  19973. },
  19974. set: function ( value ) {
  19975. console.warn( 'THREE.WebGLRenderer: .shadowMapType is now .shadowMap.type.' );
  19976. this.shadowMap.type = value;
  19977. }
  19978. },
  19979. shadowMapCullFace: {
  19980. get: function () {
  19981. return this.shadowMap.cullFace;
  19982. },
  19983. set: function ( value ) {
  19984. console.warn( 'THREE.WebGLRenderer: .shadowMapCullFace is now .shadowMap.cullFace.' );
  19985. this.shadowMap.cullFace = value;
  19986. }
  19987. }
  19988. } );
  19989. Object.defineProperties( THREE.WebGLShadowMap.prototype, {
  19990. cullFace: {
  19991. get: function () {
  19992. return this.renderReverseSided ? THREE.CullFaceFront : THREE.CullFaceBack;
  19993. },
  19994. set: function ( cullFace ) {
  19995. var value = ( cullFace !== THREE.CullFaceBack );
  19996. console.warn( "WebGLRenderer: .shadowMap.cullFace is deprecated. Set .shadowMap.renderReverseSided to " + value + "." );
  19997. this.renderReverseSided = value;
  19998. }
  19999. }
  20000. } );
  20001. //
  20002. Object.defineProperties( THREE.WebGLRenderTarget.prototype, {
  20003. wrapS: {
  20004. get: function () {
  20005. console.warn( 'THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.' );
  20006. return this.texture.wrapS;
  20007. },
  20008. set: function ( value ) {
  20009. console.warn( 'THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.' );
  20010. this.texture.wrapS = value;
  20011. }
  20012. },
  20013. wrapT: {
  20014. get: function () {
  20015. console.warn( 'THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.' );
  20016. return this.texture.wrapT;
  20017. },
  20018. set: function ( value ) {
  20019. console.warn( 'THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.' );
  20020. this.texture.wrapT = value;
  20021. }
  20022. },
  20023. magFilter: {
  20024. get: function () {
  20025. console.warn( 'THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.' );
  20026. return this.texture.magFilter;
  20027. },
  20028. set: function ( value ) {
  20029. console.warn( 'THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.' );
  20030. this.texture.magFilter = value;
  20031. }
  20032. },
  20033. minFilter: {
  20034. get: function () {
  20035. console.warn( 'THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.' );
  20036. return this.texture.minFilter;
  20037. },
  20038. set: function ( value ) {
  20039. console.warn( 'THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.' );
  20040. this.texture.minFilter = value;
  20041. }
  20042. },
  20043. anisotropy: {
  20044. get: function () {
  20045. console.warn( 'THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy.' );
  20046. return this.texture.anisotropy;
  20047. },
  20048. set: function ( value ) {
  20049. console.warn( 'THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy.' );
  20050. this.texture.anisotropy = value;
  20051. }
  20052. },
  20053. offset: {
  20054. get: function () {
  20055. console.warn( 'THREE.WebGLRenderTarget: .offset is now .texture.offset.' );
  20056. return this.texture.offset;
  20057. },
  20058. set: function ( value ) {
  20059. console.warn( 'THREE.WebGLRenderTarget: .offset is now .texture.offset.' );
  20060. this.texture.offset = value;
  20061. }
  20062. },
  20063. repeat: {
  20064. get: function () {
  20065. console.warn( 'THREE.WebGLRenderTarget: .repeat is now .texture.repeat.' );
  20066. return this.texture.repeat;
  20067. },
  20068. set: function ( value ) {
  20069. console.warn( 'THREE.WebGLRenderTarget: .repeat is now .texture.repeat.' );
  20070. this.texture.repeat = value;
  20071. }
  20072. },
  20073. format: {
  20074. get: function () {
  20075. console.warn( 'THREE.WebGLRenderTarget: .format is now .texture.format.' );
  20076. return this.texture.format;
  20077. },
  20078. set: function ( value ) {
  20079. console.warn( 'THREE.WebGLRenderTarget: .format is now .texture.format.' );
  20080. this.texture.format = value;
  20081. }
  20082. },
  20083. type: {
  20084. get: function () {
  20085. console.warn( 'THREE.WebGLRenderTarget: .type is now .texture.type.' );
  20086. return this.texture.type;
  20087. },
  20088. set: function ( value ) {
  20089. console.warn( 'THREE.WebGLRenderTarget: .type is now .texture.type.' );
  20090. this.texture.type = value;
  20091. }
  20092. },
  20093. generateMipmaps: {
  20094. get: function () {
  20095. console.warn( 'THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps.' );
  20096. return this.texture.generateMipmaps;
  20097. },
  20098. set: function ( value ) {
  20099. console.warn( 'THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps.' );
  20100. this.texture.generateMipmaps = value;
  20101. }
  20102. }
  20103. } );
  20104. //
  20105. Object.assign( THREE.Audio.prototype, {
  20106. load: function ( file ) {
  20107. console.warn( 'THREE.Audio: .load has been deprecated. Please use THREE.AudioLoader.' );
  20108. var scope = this;
  20109. var audioLoader = new THREE.AudioLoader();
  20110. audioLoader.load( file, function ( buffer ) {
  20111. scope.setBuffer( buffer );
  20112. } );
  20113. return this;
  20114. }
  20115. } );
  20116. Object.assign( THREE.AudioAnalyser.prototype, {
  20117. getData: function ( file ) {
  20118. console.warn( 'THREE.AudioAnalyser: .getData() is now .getFrequencyData().' );
  20119. return this.getFrequencyData();
  20120. }
  20121. } );
  20122. //
  20123. THREE.GeometryUtils = {
  20124. merge: function ( geometry1, geometry2, materialIndexOffset ) {
  20125. console.warn( 'THREE.GeometryUtils: .merge() has been moved to Geometry. Use geometry.merge( geometry2, matrix, materialIndexOffset ) instead.' );
  20126. var matrix;
  20127. if ( geometry2 instanceof THREE.Mesh ) {
  20128. geometry2.matrixAutoUpdate && geometry2.updateMatrix();
  20129. matrix = geometry2.matrix;
  20130. geometry2 = geometry2.geometry;
  20131. }
  20132. geometry1.merge( geometry2, matrix, materialIndexOffset );
  20133. },
  20134. center: function ( geometry ) {
  20135. console.warn( 'THREE.GeometryUtils: .center() has been moved to Geometry. Use geometry.center() instead.' );
  20136. return geometry.center();
  20137. }
  20138. };
  20139. THREE.ImageUtils = {
  20140. crossOrigin: undefined,
  20141. loadTexture: function ( url, mapping, onLoad, onError ) {
  20142. console.warn( 'THREE.ImageUtils.loadTexture has been deprecated. Use THREE.TextureLoader() instead.' );
  20143. var loader = new THREE.TextureLoader();
  20144. loader.setCrossOrigin( this.crossOrigin );
  20145. var texture = loader.load( url, onLoad, undefined, onError );
  20146. if ( mapping ) texture.mapping = mapping;
  20147. return texture;
  20148. },
  20149. loadTextureCube: function ( urls, mapping, onLoad, onError ) {
  20150. console.warn( 'THREE.ImageUtils.loadTextureCube has been deprecated. Use THREE.CubeTextureLoader() instead.' );
  20151. var loader = new THREE.CubeTextureLoader();
  20152. loader.setCrossOrigin( this.crossOrigin );
  20153. var texture = loader.load( urls, onLoad, undefined, onError );
  20154. if ( mapping ) texture.mapping = mapping;
  20155. return texture;
  20156. },
  20157. loadCompressedTexture: function () {
  20158. console.error( 'THREE.ImageUtils.loadCompressedTexture has been removed. Use THREE.DDSLoader instead.' );
  20159. },
  20160. loadCompressedTextureCube: function () {
  20161. console.error( 'THREE.ImageUtils.loadCompressedTextureCube has been removed. Use THREE.DDSLoader instead.' );
  20162. }
  20163. };
  20164. //
  20165. THREE.Projector = function () {
  20166. console.error( 'THREE.Projector has been moved to /examples/js/renderers/Projector.js.' );
  20167. this.projectVector = function ( vector, camera ) {
  20168. console.warn( 'THREE.Projector: .projectVector() is now vector.project().' );
  20169. vector.project( camera );
  20170. };
  20171. this.unprojectVector = function ( vector, camera ) {
  20172. console.warn( 'THREE.Projector: .unprojectVector() is now vector.unproject().' );
  20173. vector.unproject( camera );
  20174. };
  20175. this.pickingRay = function ( vector, camera ) {
  20176. console.error( 'THREE.Projector: .pickingRay() is now raycaster.setFromCamera().' );
  20177. };
  20178. };
  20179. //
  20180. THREE.CanvasRenderer = function () {
  20181. console.error( 'THREE.CanvasRenderer has been moved to /examples/js/renderers/CanvasRenderer.js' );
  20182. this.domElement = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' );
  20183. this.clear = function () {};
  20184. this.render = function () {};
  20185. this.setClearColor = function () {};
  20186. this.setSize = function () {};
  20187. };
  20188. // File:src/extras/CurveUtils.js
  20189. /**
  20190. * @author zz85 / http://www.lab4games.net/zz85/blog
  20191. */
  20192. THREE.CurveUtils = {
  20193. tangentQuadraticBezier: function ( t, p0, p1, p2 ) {
  20194. return 2 * ( 1 - t ) * ( p1 - p0 ) + 2 * t * ( p2 - p1 );
  20195. },
  20196. // Puay Bing, thanks for helping with this derivative!
  20197. tangentCubicBezier: function ( t, p0, p1, p2, p3 ) {
  20198. return - 3 * p0 * ( 1 - t ) * ( 1 - t ) +
  20199. 3 * p1 * ( 1 - t ) * ( 1 - t ) - 6 * t * p1 * ( 1 - t ) +
  20200. 6 * t * p2 * ( 1 - t ) - 3 * t * t * p2 +
  20201. 3 * t * t * p3;
  20202. },
  20203. tangentSpline: function ( t, p0, p1, p2, p3 ) {
  20204. // To check if my formulas are correct
  20205. var h00 = 6 * t * t - 6 * t; // derived from 2t^3 − 3t^2 + 1
  20206. var h10 = 3 * t * t - 4 * t + 1; // t^3 − 2t^2 + t
  20207. var h01 = - 6 * t * t + 6 * t; // − 2t3 + 3t2
  20208. var h11 = 3 * t * t - 2 * t; // t3 − t2
  20209. return h00 + h10 + h01 + h11;
  20210. },
  20211. // Catmull-Rom
  20212. interpolate: function( p0, p1, p2, p3, t ) {
  20213. var v0 = ( p2 - p0 ) * 0.5;
  20214. var v1 = ( p3 - p1 ) * 0.5;
  20215. var t2 = t * t;
  20216. var t3 = t * t2;
  20217. return ( 2 * p1 - 2 * p2 + v0 + v1 ) * t3 + ( - 3 * p1 + 3 * p2 - 2 * v0 - v1 ) * t2 + v0 * t + p1;
  20218. }
  20219. };
  20220. // File:src/extras/SceneUtils.js
  20221. /**
  20222. * @author alteredq / http://alteredqualia.com/
  20223. */
  20224. THREE.SceneUtils = {
  20225. createMultiMaterialObject: function ( geometry, materials ) {
  20226. var group = new THREE.Group();
  20227. for ( var i = 0, l = materials.length; i < l; i ++ ) {
  20228. group.add( new THREE.Mesh( geometry, materials[ i ] ) );
  20229. }
  20230. return group;
  20231. },
  20232. detach: function ( child, parent, scene ) {
  20233. child.applyMatrix( parent.matrixWorld );
  20234. parent.remove( child );
  20235. scene.add( child );
  20236. },
  20237. attach: function ( child, scene, parent ) {
  20238. var matrixWorldInverse = new THREE.Matrix4();
  20239. matrixWorldInverse.getInverse( parent.matrixWorld );
  20240. child.applyMatrix( matrixWorldInverse );
  20241. scene.remove( child );
  20242. parent.add( child );
  20243. }
  20244. };
  20245. // File:src/extras/ShapeUtils.js
  20246. /**
  20247. * @author zz85 / http://www.lab4games.net/zz85/blog
  20248. */
  20249. THREE.ShapeUtils = {
  20250. // calculate area of the contour polygon
  20251. area: function ( contour ) {
  20252. var n = contour.length;
  20253. var a = 0.0;
  20254. for ( var p = n - 1, q = 0; q < n; p = q ++ ) {
  20255. a += contour[ p ].x * contour[ q ].y - contour[ q ].x * contour[ p ].y;
  20256. }
  20257. return a * 0.5;
  20258. },
  20259. triangulate: ( function () {
  20260. /**
  20261. * This code is a quick port of code written in C++ which was submitted to
  20262. * flipcode.com by John W. Ratcliff // July 22, 2000
  20263. * See original code and more information here:
  20264. * http://www.flipcode.com/archives/Efficient_Polygon_Triangulation.shtml
  20265. *
  20266. * ported to actionscript by Zevan Rosser
  20267. * www.actionsnippet.com
  20268. *
  20269. * ported to javascript by Joshua Koo
  20270. * http://www.lab4games.net/zz85/blog
  20271. *
  20272. */
  20273. function snip( contour, u, v, w, n, verts ) {
  20274. var p;
  20275. var ax, ay, bx, by;
  20276. var cx, cy, px, py;
  20277. ax = contour[ verts[ u ] ].x;
  20278. ay = contour[ verts[ u ] ].y;
  20279. bx = contour[ verts[ v ] ].x;
  20280. by = contour[ verts[ v ] ].y;
  20281. cx = contour[ verts[ w ] ].x;
  20282. cy = contour[ verts[ w ] ].y;
  20283. if ( Number.EPSILON > ( ( ( bx - ax ) * ( cy - ay ) ) - ( ( by - ay ) * ( cx - ax ) ) ) ) return false;
  20284. var aX, aY, bX, bY, cX, cY;
  20285. var apx, apy, bpx, bpy, cpx, cpy;
  20286. var cCROSSap, bCROSScp, aCROSSbp;
  20287. aX = cx - bx; aY = cy - by;
  20288. bX = ax - cx; bY = ay - cy;
  20289. cX = bx - ax; cY = by - ay;
  20290. for ( p = 0; p < n; p ++ ) {
  20291. px = contour[ verts[ p ] ].x;
  20292. py = contour[ verts[ p ] ].y;
  20293. if ( ( ( px === ax ) && ( py === ay ) ) ||
  20294. ( ( px === bx ) && ( py === by ) ) ||
  20295. ( ( px === cx ) && ( py === cy ) ) ) continue;
  20296. apx = px - ax; apy = py - ay;
  20297. bpx = px - bx; bpy = py - by;
  20298. cpx = px - cx; cpy = py - cy;
  20299. // see if p is inside triangle abc
  20300. aCROSSbp = aX * bpy - aY * bpx;
  20301. cCROSSap = cX * apy - cY * apx;
  20302. bCROSScp = bX * cpy - bY * cpx;
  20303. if ( ( aCROSSbp >= - Number.EPSILON ) && ( bCROSScp >= - Number.EPSILON ) && ( cCROSSap >= - Number.EPSILON ) ) return false;
  20304. }
  20305. return true;
  20306. }
  20307. // takes in an contour array and returns
  20308. return function triangulate( contour, indices ) {
  20309. var n = contour.length;
  20310. if ( n < 3 ) return null;
  20311. var result = [],
  20312. verts = [],
  20313. vertIndices = [];
  20314. /* we want a counter-clockwise polygon in verts */
  20315. var u, v, w;
  20316. if ( THREE.ShapeUtils.area( contour ) > 0.0 ) {
  20317. for ( v = 0; v < n; v ++ ) verts[ v ] = v;
  20318. } else {
  20319. for ( v = 0; v < n; v ++ ) verts[ v ] = ( n - 1 ) - v;
  20320. }
  20321. var nv = n;
  20322. /* remove nv - 2 vertices, creating 1 triangle every time */
  20323. var count = 2 * nv; /* error detection */
  20324. for ( v = nv - 1; nv > 2; ) {
  20325. /* if we loop, it is probably a non-simple polygon */
  20326. if ( ( count -- ) <= 0 ) {
  20327. //** Triangulate: ERROR - probable bad polygon!
  20328. //throw ( "Warning, unable to triangulate polygon!" );
  20329. //return null;
  20330. // Sometimes warning is fine, especially polygons are triangulated in reverse.
  20331. console.warn( 'THREE.ShapeUtils: Unable to triangulate polygon! in triangulate()' );
  20332. if ( indices ) return vertIndices;
  20333. return result;
  20334. }
  20335. /* three consecutive vertices in current polygon, <u,v,w> */
  20336. u = v; if ( nv <= u ) u = 0; /* previous */
  20337. v = u + 1; if ( nv <= v ) v = 0; /* new v */
  20338. w = v + 1; if ( nv <= w ) w = 0; /* next */
  20339. if ( snip( contour, u, v, w, nv, verts ) ) {
  20340. var a, b, c, s, t;
  20341. /* true names of the vertices */
  20342. a = verts[ u ];
  20343. b = verts[ v ];
  20344. c = verts[ w ];
  20345. /* output Triangle */
  20346. result.push( [ contour[ a ],
  20347. contour[ b ],
  20348. contour[ c ] ] );
  20349. vertIndices.push( [ verts[ u ], verts[ v ], verts[ w ] ] );
  20350. /* remove v from the remaining polygon */
  20351. for ( s = v, t = v + 1; t < nv; s ++, t ++ ) {
  20352. verts[ s ] = verts[ t ];
  20353. }
  20354. nv --;
  20355. /* reset error detection counter */
  20356. count = 2 * nv;
  20357. }
  20358. }
  20359. if ( indices ) return vertIndices;
  20360. return result;
  20361. }
  20362. } )(),
  20363. triangulateShape: function ( contour, holes ) {
  20364. function point_in_segment_2D_colin( inSegPt1, inSegPt2, inOtherPt ) {
  20365. // inOtherPt needs to be collinear to the inSegment
  20366. if ( inSegPt1.x !== inSegPt2.x ) {
  20367. if ( inSegPt1.x < inSegPt2.x ) {
  20368. return ( ( inSegPt1.x <= inOtherPt.x ) && ( inOtherPt.x <= inSegPt2.x ) );
  20369. } else {
  20370. return ( ( inSegPt2.x <= inOtherPt.x ) && ( inOtherPt.x <= inSegPt1.x ) );
  20371. }
  20372. } else {
  20373. if ( inSegPt1.y < inSegPt2.y ) {
  20374. return ( ( inSegPt1.y <= inOtherPt.y ) && ( inOtherPt.y <= inSegPt2.y ) );
  20375. } else {
  20376. return ( ( inSegPt2.y <= inOtherPt.y ) && ( inOtherPt.y <= inSegPt1.y ) );
  20377. }
  20378. }
  20379. }
  20380. function intersect_segments_2D( inSeg1Pt1, inSeg1Pt2, inSeg2Pt1, inSeg2Pt2, inExcludeAdjacentSegs ) {
  20381. var seg1dx = inSeg1Pt2.x - inSeg1Pt1.x, seg1dy = inSeg1Pt2.y - inSeg1Pt1.y;
  20382. var seg2dx = inSeg2Pt2.x - inSeg2Pt1.x, seg2dy = inSeg2Pt2.y - inSeg2Pt1.y;
  20383. var seg1seg2dx = inSeg1Pt1.x - inSeg2Pt1.x;
  20384. var seg1seg2dy = inSeg1Pt1.y - inSeg2Pt1.y;
  20385. var limit = seg1dy * seg2dx - seg1dx * seg2dy;
  20386. var perpSeg1 = seg1dy * seg1seg2dx - seg1dx * seg1seg2dy;
  20387. if ( Math.abs( limit ) > Number.EPSILON ) {
  20388. // not parallel
  20389. var perpSeg2;
  20390. if ( limit > 0 ) {
  20391. if ( ( perpSeg1 < 0 ) || ( perpSeg1 > limit ) ) return [];
  20392. perpSeg2 = seg2dy * seg1seg2dx - seg2dx * seg1seg2dy;
  20393. if ( ( perpSeg2 < 0 ) || ( perpSeg2 > limit ) ) return [];
  20394. } else {
  20395. if ( ( perpSeg1 > 0 ) || ( perpSeg1 < limit ) ) return [];
  20396. perpSeg2 = seg2dy * seg1seg2dx - seg2dx * seg1seg2dy;
  20397. if ( ( perpSeg2 > 0 ) || ( perpSeg2 < limit ) ) return [];
  20398. }
  20399. // i.e. to reduce rounding errors
  20400. // intersection at endpoint of segment#1?
  20401. if ( perpSeg2 === 0 ) {
  20402. if ( ( inExcludeAdjacentSegs ) &&
  20403. ( ( perpSeg1 === 0 ) || ( perpSeg1 === limit ) ) ) return [];
  20404. return [ inSeg1Pt1 ];
  20405. }
  20406. if ( perpSeg2 === limit ) {
  20407. if ( ( inExcludeAdjacentSegs ) &&
  20408. ( ( perpSeg1 === 0 ) || ( perpSeg1 === limit ) ) ) return [];
  20409. return [ inSeg1Pt2 ];
  20410. }
  20411. // intersection at endpoint of segment#2?
  20412. if ( perpSeg1 === 0 ) return [ inSeg2Pt1 ];
  20413. if ( perpSeg1 === limit ) return [ inSeg2Pt2 ];
  20414. // return real intersection point
  20415. var factorSeg1 = perpSeg2 / limit;
  20416. return [ { x: inSeg1Pt1.x + factorSeg1 * seg1dx,
  20417. y: inSeg1Pt1.y + factorSeg1 * seg1dy } ];
  20418. } else {
  20419. // parallel or collinear
  20420. if ( ( perpSeg1 !== 0 ) ||
  20421. ( seg2dy * seg1seg2dx !== seg2dx * seg1seg2dy ) ) return [];
  20422. // they are collinear or degenerate
  20423. var seg1Pt = ( ( seg1dx === 0 ) && ( seg1dy === 0 ) ); // segment1 is just a point?
  20424. var seg2Pt = ( ( seg2dx === 0 ) && ( seg2dy === 0 ) ); // segment2 is just a point?
  20425. // both segments are points
  20426. if ( seg1Pt && seg2Pt ) {
  20427. if ( ( inSeg1Pt1.x !== inSeg2Pt1.x ) ||
  20428. ( inSeg1Pt1.y !== inSeg2Pt1.y ) ) return []; // they are distinct points
  20429. return [ inSeg1Pt1 ]; // they are the same point
  20430. }
  20431. // segment#1 is a single point
  20432. if ( seg1Pt ) {
  20433. if ( ! point_in_segment_2D_colin( inSeg2Pt1, inSeg2Pt2, inSeg1Pt1 ) ) return []; // but not in segment#2
  20434. return [ inSeg1Pt1 ];
  20435. }
  20436. // segment#2 is a single point
  20437. if ( seg2Pt ) {
  20438. if ( ! point_in_segment_2D_colin( inSeg1Pt1, inSeg1Pt2, inSeg2Pt1 ) ) return []; // but not in segment#1
  20439. return [ inSeg2Pt1 ];
  20440. }
  20441. // they are collinear segments, which might overlap
  20442. var seg1min, seg1max, seg1minVal, seg1maxVal;
  20443. var seg2min, seg2max, seg2minVal, seg2maxVal;
  20444. if ( seg1dx !== 0 ) {
  20445. // the segments are NOT on a vertical line
  20446. if ( inSeg1Pt1.x < inSeg1Pt2.x ) {
  20447. seg1min = inSeg1Pt1; seg1minVal = inSeg1Pt1.x;
  20448. seg1max = inSeg1Pt2; seg1maxVal = inSeg1Pt2.x;
  20449. } else {
  20450. seg1min = inSeg1Pt2; seg1minVal = inSeg1Pt2.x;
  20451. seg1max = inSeg1Pt1; seg1maxVal = inSeg1Pt1.x;
  20452. }
  20453. if ( inSeg2Pt1.x < inSeg2Pt2.x ) {
  20454. seg2min = inSeg2Pt1; seg2minVal = inSeg2Pt1.x;
  20455. seg2max = inSeg2Pt2; seg2maxVal = inSeg2Pt2.x;
  20456. } else {
  20457. seg2min = inSeg2Pt2; seg2minVal = inSeg2Pt2.x;
  20458. seg2max = inSeg2Pt1; seg2maxVal = inSeg2Pt1.x;
  20459. }
  20460. } else {
  20461. // the segments are on a vertical line
  20462. if ( inSeg1Pt1.y < inSeg1Pt2.y ) {
  20463. seg1min = inSeg1Pt1; seg1minVal = inSeg1Pt1.y;
  20464. seg1max = inSeg1Pt2; seg1maxVal = inSeg1Pt2.y;
  20465. } else {
  20466. seg1min = inSeg1Pt2; seg1minVal = inSeg1Pt2.y;
  20467. seg1max = inSeg1Pt1; seg1maxVal = inSeg1Pt1.y;
  20468. }
  20469. if ( inSeg2Pt1.y < inSeg2Pt2.y ) {
  20470. seg2min = inSeg2Pt1; seg2minVal = inSeg2Pt1.y;
  20471. seg2max = inSeg2Pt2; seg2maxVal = inSeg2Pt2.y;
  20472. } else {
  20473. seg2min = inSeg2Pt2; seg2minVal = inSeg2Pt2.y;
  20474. seg2max = inSeg2Pt1; seg2maxVal = inSeg2Pt1.y;
  20475. }
  20476. }
  20477. if ( seg1minVal <= seg2minVal ) {
  20478. if ( seg1maxVal < seg2minVal ) return [];
  20479. if ( seg1maxVal === seg2minVal ) {
  20480. if ( inExcludeAdjacentSegs ) return [];
  20481. return [ seg2min ];
  20482. }
  20483. if ( seg1maxVal <= seg2maxVal ) return [ seg2min, seg1max ];
  20484. return [ seg2min, seg2max ];
  20485. } else {
  20486. if ( seg1minVal > seg2maxVal ) return [];
  20487. if ( seg1minVal === seg2maxVal ) {
  20488. if ( inExcludeAdjacentSegs ) return [];
  20489. return [ seg1min ];
  20490. }
  20491. if ( seg1maxVal <= seg2maxVal ) return [ seg1min, seg1max ];
  20492. return [ seg1min, seg2max ];
  20493. }
  20494. }
  20495. }
  20496. function isPointInsideAngle( inVertex, inLegFromPt, inLegToPt, inOtherPt ) {
  20497. // The order of legs is important
  20498. // translation of all points, so that Vertex is at (0,0)
  20499. var legFromPtX = inLegFromPt.x - inVertex.x, legFromPtY = inLegFromPt.y - inVertex.y;
  20500. var legToPtX = inLegToPt.x - inVertex.x, legToPtY = inLegToPt.y - inVertex.y;
  20501. var otherPtX = inOtherPt.x - inVertex.x, otherPtY = inOtherPt.y - inVertex.y;
  20502. // main angle >0: < 180 deg.; 0: 180 deg.; <0: > 180 deg.
  20503. var from2toAngle = legFromPtX * legToPtY - legFromPtY * legToPtX;
  20504. var from2otherAngle = legFromPtX * otherPtY - legFromPtY * otherPtX;
  20505. if ( Math.abs( from2toAngle ) > Number.EPSILON ) {
  20506. // angle != 180 deg.
  20507. var other2toAngle = otherPtX * legToPtY - otherPtY * legToPtX;
  20508. // console.log( "from2to: " + from2toAngle + ", from2other: " + from2otherAngle + ", other2to: " + other2toAngle );
  20509. if ( from2toAngle > 0 ) {
  20510. // main angle < 180 deg.
  20511. return ( ( from2otherAngle >= 0 ) && ( other2toAngle >= 0 ) );
  20512. } else {
  20513. // main angle > 180 deg.
  20514. return ( ( from2otherAngle >= 0 ) || ( other2toAngle >= 0 ) );
  20515. }
  20516. } else {
  20517. // angle == 180 deg.
  20518. // console.log( "from2to: 180 deg., from2other: " + from2otherAngle );
  20519. return ( from2otherAngle > 0 );
  20520. }
  20521. }
  20522. function removeHoles( contour, holes ) {
  20523. var shape = contour.concat(); // work on this shape
  20524. var hole;
  20525. function isCutLineInsideAngles( inShapeIdx, inHoleIdx ) {
  20526. // Check if hole point lies within angle around shape point
  20527. var lastShapeIdx = shape.length - 1;
  20528. var prevShapeIdx = inShapeIdx - 1;
  20529. if ( prevShapeIdx < 0 ) prevShapeIdx = lastShapeIdx;
  20530. var nextShapeIdx = inShapeIdx + 1;
  20531. if ( nextShapeIdx > lastShapeIdx ) nextShapeIdx = 0;
  20532. var insideAngle = isPointInsideAngle( shape[ inShapeIdx ], shape[ prevShapeIdx ], shape[ nextShapeIdx ], hole[ inHoleIdx ] );
  20533. if ( ! insideAngle ) {
  20534. // console.log( "Vertex (Shape): " + inShapeIdx + ", Point: " + hole[inHoleIdx].x + "/" + hole[inHoleIdx].y );
  20535. return false;
  20536. }
  20537. // Check if shape point lies within angle around hole point
  20538. var lastHoleIdx = hole.length - 1;
  20539. var prevHoleIdx = inHoleIdx - 1;
  20540. if ( prevHoleIdx < 0 ) prevHoleIdx = lastHoleIdx;
  20541. var nextHoleIdx = inHoleIdx + 1;
  20542. if ( nextHoleIdx > lastHoleIdx ) nextHoleIdx = 0;
  20543. insideAngle = isPointInsideAngle( hole[ inHoleIdx ], hole[ prevHoleIdx ], hole[ nextHoleIdx ], shape[ inShapeIdx ] );
  20544. if ( ! insideAngle ) {
  20545. // console.log( "Vertex (Hole): " + inHoleIdx + ", Point: " + shape[inShapeIdx].x + "/" + shape[inShapeIdx].y );
  20546. return false;
  20547. }
  20548. return true;
  20549. }
  20550. function intersectsShapeEdge( inShapePt, inHolePt ) {
  20551. // checks for intersections with shape edges
  20552. var sIdx, nextIdx, intersection;
  20553. for ( sIdx = 0; sIdx < shape.length; sIdx ++ ) {
  20554. nextIdx = sIdx + 1; nextIdx %= shape.length;
  20555. intersection = intersect_segments_2D( inShapePt, inHolePt, shape[ sIdx ], shape[ nextIdx ], true );
  20556. if ( intersection.length > 0 ) return true;
  20557. }
  20558. return false;
  20559. }
  20560. var indepHoles = [];
  20561. function intersectsHoleEdge( inShapePt, inHolePt ) {
  20562. // checks for intersections with hole edges
  20563. var ihIdx, chkHole,
  20564. hIdx, nextIdx, intersection;
  20565. for ( ihIdx = 0; ihIdx < indepHoles.length; ihIdx ++ ) {
  20566. chkHole = holes[ indepHoles[ ihIdx ]];
  20567. for ( hIdx = 0; hIdx < chkHole.length; hIdx ++ ) {
  20568. nextIdx = hIdx + 1; nextIdx %= chkHole.length;
  20569. intersection = intersect_segments_2D( inShapePt, inHolePt, chkHole[ hIdx ], chkHole[ nextIdx ], true );
  20570. if ( intersection.length > 0 ) return true;
  20571. }
  20572. }
  20573. return false;
  20574. }
  20575. var holeIndex, shapeIndex,
  20576. shapePt, holePt,
  20577. holeIdx, cutKey, failedCuts = [],
  20578. tmpShape1, tmpShape2,
  20579. tmpHole1, tmpHole2;
  20580. for ( var h = 0, hl = holes.length; h < hl; h ++ ) {
  20581. indepHoles.push( h );
  20582. }
  20583. var minShapeIndex = 0;
  20584. var counter = indepHoles.length * 2;
  20585. while ( indepHoles.length > 0 ) {
  20586. counter --;
  20587. if ( counter < 0 ) {
  20588. console.log( "Infinite Loop! Holes left:" + indepHoles.length + ", Probably Hole outside Shape!" );
  20589. break;
  20590. }
  20591. // search for shape-vertex and hole-vertex,
  20592. // which can be connected without intersections
  20593. for ( shapeIndex = minShapeIndex; shapeIndex < shape.length; shapeIndex ++ ) {
  20594. shapePt = shape[ shapeIndex ];
  20595. holeIndex = - 1;
  20596. // search for hole which can be reached without intersections
  20597. for ( var h = 0; h < indepHoles.length; h ++ ) {
  20598. holeIdx = indepHoles[ h ];
  20599. // prevent multiple checks
  20600. cutKey = shapePt.x + ":" + shapePt.y + ":" + holeIdx;
  20601. if ( failedCuts[ cutKey ] !== undefined ) continue;
  20602. hole = holes[ holeIdx ];
  20603. for ( var h2 = 0; h2 < hole.length; h2 ++ ) {
  20604. holePt = hole[ h2 ];
  20605. if ( ! isCutLineInsideAngles( shapeIndex, h2 ) ) continue;
  20606. if ( intersectsShapeEdge( shapePt, holePt ) ) continue;
  20607. if ( intersectsHoleEdge( shapePt, holePt ) ) continue;
  20608. holeIndex = h2;
  20609. indepHoles.splice( h, 1 );
  20610. tmpShape1 = shape.slice( 0, shapeIndex + 1 );
  20611. tmpShape2 = shape.slice( shapeIndex );
  20612. tmpHole1 = hole.slice( holeIndex );
  20613. tmpHole2 = hole.slice( 0, holeIndex + 1 );
  20614. shape = tmpShape1.concat( tmpHole1 ).concat( tmpHole2 ).concat( tmpShape2 );
  20615. minShapeIndex = shapeIndex;
  20616. // Debug only, to show the selected cuts
  20617. // glob_CutLines.push( [ shapePt, holePt ] );
  20618. break;
  20619. }
  20620. if ( holeIndex >= 0 ) break; // hole-vertex found
  20621. failedCuts[ cutKey ] = true; // remember failure
  20622. }
  20623. if ( holeIndex >= 0 ) break; // hole-vertex found
  20624. }
  20625. }
  20626. return shape; /* shape with no holes */
  20627. }
  20628. var i, il, f, face,
  20629. key, index,
  20630. allPointsMap = {};
  20631. // 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.
  20632. var allpoints = contour.concat();
  20633. for ( var h = 0, hl = holes.length; h < hl; h ++ ) {
  20634. Array.prototype.push.apply( allpoints, holes[ h ] );
  20635. }
  20636. //console.log( "allpoints",allpoints, allpoints.length );
  20637. // prepare all points map
  20638. for ( i = 0, il = allpoints.length; i < il; i ++ ) {
  20639. key = allpoints[ i ].x + ":" + allpoints[ i ].y;
  20640. if ( allPointsMap[ key ] !== undefined ) {
  20641. console.warn( "THREE.Shape: Duplicate point", key );
  20642. }
  20643. allPointsMap[ key ] = i;
  20644. }
  20645. // remove holes by cutting paths to holes and adding them to the shape
  20646. var shapeWithoutHoles = removeHoles( contour, holes );
  20647. var triangles = THREE.ShapeUtils.triangulate( shapeWithoutHoles, false ); // True returns indices for points of spooled shape
  20648. //console.log( "triangles",triangles, triangles.length );
  20649. // check all face vertices against all points map
  20650. for ( i = 0, il = triangles.length; i < il; i ++ ) {
  20651. face = triangles[ i ];
  20652. for ( f = 0; f < 3; f ++ ) {
  20653. key = face[ f ].x + ":" + face[ f ].y;
  20654. index = allPointsMap[ key ];
  20655. if ( index !== undefined ) {
  20656. face[ f ] = index;
  20657. }
  20658. }
  20659. }
  20660. return triangles.concat();
  20661. },
  20662. isClockWise: function ( pts ) {
  20663. return THREE.ShapeUtils.area( pts ) < 0;
  20664. },
  20665. // Bezier Curves formulas obtained from
  20666. // http://en.wikipedia.org/wiki/B%C3%A9zier_curve
  20667. // Quad Bezier Functions
  20668. b2: ( function () {
  20669. function b2p0( t, p ) {
  20670. var k = 1 - t;
  20671. return k * k * p;
  20672. }
  20673. function b2p1( t, p ) {
  20674. return 2 * ( 1 - t ) * t * p;
  20675. }
  20676. function b2p2( t, p ) {
  20677. return t * t * p;
  20678. }
  20679. return function b2( t, p0, p1, p2 ) {
  20680. return b2p0( t, p0 ) + b2p1( t, p1 ) + b2p2( t, p2 );
  20681. };
  20682. } )(),
  20683. // Cubic Bezier Functions
  20684. b3: ( function () {
  20685. function b3p0( t, p ) {
  20686. var k = 1 - t;
  20687. return k * k * k * p;
  20688. }
  20689. function b3p1( t, p ) {
  20690. var k = 1 - t;
  20691. return 3 * k * k * t * p;
  20692. }
  20693. function b3p2( t, p ) {
  20694. var k = 1 - t;
  20695. return 3 * k * t * t * p;
  20696. }
  20697. function b3p3( t, p ) {
  20698. return t * t * t * p;
  20699. }
  20700. return function b3( t, p0, p1, p2, p3 ) {
  20701. return b3p0( t, p0 ) + b3p1( t, p1 ) + b3p2( t, p2 ) + b3p3( t, p3 );
  20702. };
  20703. } )()
  20704. };
  20705. // File:src/extras/core/Curve.js
  20706. /**
  20707. * @author zz85 / http://www.lab4games.net/zz85/blog
  20708. * Extensible curve object
  20709. *
  20710. * Some common of Curve methods
  20711. * .getPoint(t), getTangent(t)
  20712. * .getPointAt(u), getTagentAt(u)
  20713. * .getPoints(), .getSpacedPoints()
  20714. * .getLength()
  20715. * .updateArcLengths()
  20716. *
  20717. * This following classes subclasses THREE.Curve:
  20718. *
  20719. * -- 2d classes --
  20720. * THREE.LineCurve
  20721. * THREE.QuadraticBezierCurve
  20722. * THREE.CubicBezierCurve
  20723. * THREE.SplineCurve
  20724. * THREE.ArcCurve
  20725. * THREE.EllipseCurve
  20726. *
  20727. * -- 3d classes --
  20728. * THREE.LineCurve3
  20729. * THREE.QuadraticBezierCurve3
  20730. * THREE.CubicBezierCurve3
  20731. * THREE.SplineCurve3
  20732. *
  20733. * A series of curves can be represented as a THREE.CurvePath
  20734. *
  20735. **/
  20736. /**************************************************************
  20737. * Abstract Curve base class
  20738. **************************************************************/
  20739. THREE.Curve = function () {
  20740. };
  20741. THREE.Curve.prototype = {
  20742. constructor: THREE.Curve,
  20743. // Virtual base class method to overwrite and implement in subclasses
  20744. // - t [0 .. 1]
  20745. getPoint: function ( t ) {
  20746. console.warn( "THREE.Curve: Warning, getPoint() not implemented!" );
  20747. return null;
  20748. },
  20749. // Get point at relative position in curve according to arc length
  20750. // - u [0 .. 1]
  20751. getPointAt: function ( u ) {
  20752. var t = this.getUtoTmapping( u );
  20753. return this.getPoint( t );
  20754. },
  20755. // Get sequence of points using getPoint( t )
  20756. getPoints: function ( divisions ) {
  20757. if ( ! divisions ) divisions = 5;
  20758. var d, pts = [];
  20759. for ( d = 0; d <= divisions; d ++ ) {
  20760. pts.push( this.getPoint( d / divisions ) );
  20761. }
  20762. return pts;
  20763. },
  20764. // Get sequence of points using getPointAt( u )
  20765. getSpacedPoints: function ( divisions ) {
  20766. if ( ! divisions ) divisions = 5;
  20767. var d, pts = [];
  20768. for ( d = 0; d <= divisions; d ++ ) {
  20769. pts.push( this.getPointAt( d / divisions ) );
  20770. }
  20771. return pts;
  20772. },
  20773. // Get total curve arc length
  20774. getLength: function () {
  20775. var lengths = this.getLengths();
  20776. return lengths[ lengths.length - 1 ];
  20777. },
  20778. // Get list of cumulative segment lengths
  20779. getLengths: function ( divisions ) {
  20780. if ( ! divisions ) divisions = ( this.__arcLengthDivisions ) ? ( this.__arcLengthDivisions ) : 200;
  20781. if ( this.cacheArcLengths
  20782. && ( this.cacheArcLengths.length === divisions + 1 )
  20783. && ! this.needsUpdate ) {
  20784. //console.log( "cached", this.cacheArcLengths );
  20785. return this.cacheArcLengths;
  20786. }
  20787. this.needsUpdate = false;
  20788. var cache = [];
  20789. var current, last = this.getPoint( 0 );
  20790. var p, sum = 0;
  20791. cache.push( 0 );
  20792. for ( p = 1; p <= divisions; p ++ ) {
  20793. current = this.getPoint ( p / divisions );
  20794. sum += current.distanceTo( last );
  20795. cache.push( sum );
  20796. last = current;
  20797. }
  20798. this.cacheArcLengths = cache;
  20799. return cache; // { sums: cache, sum:sum }; Sum is in the last element.
  20800. },
  20801. updateArcLengths: function() {
  20802. this.needsUpdate = true;
  20803. this.getLengths();
  20804. },
  20805. // Given u ( 0 .. 1 ), get a t to find p. This gives you points which are equidistant
  20806. getUtoTmapping: function ( u, distance ) {
  20807. var arcLengths = this.getLengths();
  20808. var i = 0, il = arcLengths.length;
  20809. var targetArcLength; // The targeted u distance value to get
  20810. if ( distance ) {
  20811. targetArcLength = distance;
  20812. } else {
  20813. targetArcLength = u * arcLengths[ il - 1 ];
  20814. }
  20815. //var time = Date.now();
  20816. // binary search for the index with largest value smaller than target u distance
  20817. var low = 0, high = il - 1, comparison;
  20818. while ( low <= high ) {
  20819. 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
  20820. comparison = arcLengths[ i ] - targetArcLength;
  20821. if ( comparison < 0 ) {
  20822. low = i + 1;
  20823. } else if ( comparison > 0 ) {
  20824. high = i - 1;
  20825. } else {
  20826. high = i;
  20827. break;
  20828. // DONE
  20829. }
  20830. }
  20831. i = high;
  20832. //console.log('b' , i, low, high, Date.now()- time);
  20833. if ( arcLengths[ i ] === targetArcLength ) {
  20834. var t = i / ( il - 1 );
  20835. return t;
  20836. }
  20837. // we could get finer grain at lengths, or use simple interpolation between two points
  20838. var lengthBefore = arcLengths[ i ];
  20839. var lengthAfter = arcLengths[ i + 1 ];
  20840. var segmentLength = lengthAfter - lengthBefore;
  20841. // determine where we are between the 'before' and 'after' points
  20842. var segmentFraction = ( targetArcLength - lengthBefore ) / segmentLength;
  20843. // add that fractional amount to t
  20844. var t = ( i + segmentFraction ) / ( il - 1 );
  20845. return t;
  20846. },
  20847. // Returns a unit vector tangent at t
  20848. // In case any sub curve does not implement its tangent derivation,
  20849. // 2 points a small delta apart will be used to find its gradient
  20850. // which seems to give a reasonable approximation
  20851. getTangent: function( t ) {
  20852. var delta = 0.0001;
  20853. var t1 = t - delta;
  20854. var t2 = t + delta;
  20855. // Capping in case of danger
  20856. if ( t1 < 0 ) t1 = 0;
  20857. if ( t2 > 1 ) t2 = 1;
  20858. var pt1 = this.getPoint( t1 );
  20859. var pt2 = this.getPoint( t2 );
  20860. var vec = pt2.clone().sub( pt1 );
  20861. return vec.normalize();
  20862. },
  20863. getTangentAt: function ( u ) {
  20864. var t = this.getUtoTmapping( u );
  20865. return this.getTangent( t );
  20866. }
  20867. };
  20868. // TODO: Transformation for Curves?
  20869. /**************************************************************
  20870. * 3D Curves
  20871. **************************************************************/
  20872. // A Factory method for creating new curve subclasses
  20873. THREE.Curve.create = function ( constructor, getPointFunc ) {
  20874. constructor.prototype = Object.create( THREE.Curve.prototype );
  20875. constructor.prototype.constructor = constructor;
  20876. constructor.prototype.getPoint = getPointFunc;
  20877. return constructor;
  20878. };
  20879. // File:src/extras/core/CurvePath.js
  20880. /**
  20881. * @author zz85 / http://www.lab4games.net/zz85/blog
  20882. *
  20883. **/
  20884. /**************************************************************
  20885. * Curved Path - a curve path is simply a array of connected
  20886. * curves, but retains the api of a curve
  20887. **************************************************************/
  20888. THREE.CurvePath = function () {
  20889. this.curves = [];
  20890. this.autoClose = false; // Automatically closes the path
  20891. };
  20892. THREE.CurvePath.prototype = Object.assign( Object.create( THREE.Curve.prototype ), {
  20893. constructor: THREE.CurvePath,
  20894. add: function ( curve ) {
  20895. this.curves.push( curve );
  20896. },
  20897. closePath: function () {
  20898. // TODO Test
  20899. // and verify for vector3 (needs to implement equals)
  20900. // Add a line curve if start and end of lines are not connected
  20901. var startPoint = this.curves[ 0 ].getPoint( 0 );
  20902. var endPoint = this.curves[ this.curves.length - 1 ].getPoint( 1 );
  20903. if ( ! startPoint.equals( endPoint ) ) {
  20904. this.curves.push( new THREE.LineCurve( endPoint, startPoint ) );
  20905. }
  20906. },
  20907. // To get accurate point with reference to
  20908. // entire path distance at time t,
  20909. // following has to be done:
  20910. // 1. Length of each sub path have to be known
  20911. // 2. Locate and identify type of curve
  20912. // 3. Get t for the curve
  20913. // 4. Return curve.getPointAt(t')
  20914. getPoint: function ( t ) {
  20915. var d = t * this.getLength();
  20916. var curveLengths = this.getCurveLengths();
  20917. var i = 0;
  20918. // To think about boundaries points.
  20919. while ( i < curveLengths.length ) {
  20920. if ( curveLengths[ i ] >= d ) {
  20921. var diff = curveLengths[ i ] - d;
  20922. var curve = this.curves[ i ];
  20923. var u = 1 - diff / curve.getLength();
  20924. return curve.getPointAt( u );
  20925. }
  20926. i ++;
  20927. }
  20928. return null;
  20929. // loop where sum != 0, sum > d , sum+1 <d
  20930. },
  20931. // We cannot use the default THREE.Curve getPoint() with getLength() because in
  20932. // THREE.Curve, getLength() depends on getPoint() but in THREE.CurvePath
  20933. // getPoint() depends on getLength
  20934. getLength: function () {
  20935. var lens = this.getCurveLengths();
  20936. return lens[ lens.length - 1 ];
  20937. },
  20938. // cacheLengths must be recalculated.
  20939. updateArcLengths: function () {
  20940. this.needsUpdate = true;
  20941. this.cacheLengths = null;
  20942. this.getLengths();
  20943. },
  20944. // Compute lengths and cache them
  20945. // We cannot overwrite getLengths() because UtoT mapping uses it.
  20946. getCurveLengths: function () {
  20947. // We use cache values if curves and cache array are same length
  20948. if ( this.cacheLengths && this.cacheLengths.length === this.curves.length ) {
  20949. return this.cacheLengths;
  20950. }
  20951. // Get length of sub-curve
  20952. // Push sums into cached array
  20953. var lengths = [], sums = 0;
  20954. for ( var i = 0, l = this.curves.length; i < l; i ++ ) {
  20955. sums += this.curves[ i ].getLength();
  20956. lengths.push( sums );
  20957. }
  20958. this.cacheLengths = lengths;
  20959. return lengths;
  20960. },
  20961. /**************************************************************
  20962. * Create Geometries Helpers
  20963. **************************************************************/
  20964. /// Generate geometry from path points (for Line or Points objects)
  20965. createPointsGeometry: function ( divisions ) {
  20966. var pts = this.getPoints( divisions );
  20967. return this.createGeometry( pts );
  20968. },
  20969. // Generate geometry from equidistant sampling along the path
  20970. createSpacedPointsGeometry: function ( divisions ) {
  20971. var pts = this.getSpacedPoints( divisions );
  20972. return this.createGeometry( pts );
  20973. },
  20974. createGeometry: function ( points ) {
  20975. var geometry = new THREE.Geometry();
  20976. for ( var i = 0, l = points.length; i < l; i ++ ) {
  20977. var point = points[ i ];
  20978. geometry.vertices.push( new THREE.Vector3( point.x, point.y, point.z || 0 ) );
  20979. }
  20980. return geometry;
  20981. }
  20982. } );
  20983. // File:src/extras/core/Font.js
  20984. /**
  20985. * @author zz85 / http://www.lab4games.net/zz85/blog
  20986. * @author mrdoob / http://mrdoob.com/
  20987. */
  20988. THREE.Font = function ( data ) {
  20989. this.data = data;
  20990. };
  20991. Object.assign( THREE.Font.prototype, {
  20992. generateShapes: function ( text, size, divisions ) {
  20993. function createPaths( text ) {
  20994. var chars = String( text ).split( '' );
  20995. var scale = size / data.resolution;
  20996. var offset = 0;
  20997. var paths = [];
  20998. for ( var i = 0; i < chars.length; i ++ ) {
  20999. var ret = createPath( chars[ i ], scale, offset );
  21000. offset += ret.offset;
  21001. paths.push( ret.path );
  21002. }
  21003. return paths;
  21004. }
  21005. function createPath( c, scale, offset ) {
  21006. var glyph = data.glyphs[ c ] || data.glyphs[ '?' ];
  21007. if ( ! glyph ) return;
  21008. var path = new THREE.Path();
  21009. var pts = [], b2 = THREE.ShapeUtils.b2, b3 = THREE.ShapeUtils.b3;
  21010. var x, y, cpx, cpy, cpx0, cpy0, cpx1, cpy1, cpx2, cpy2, laste;
  21011. if ( glyph.o ) {
  21012. var outline = glyph._cachedOutline || ( glyph._cachedOutline = glyph.o.split( ' ' ) );
  21013. for ( var i = 0, l = outline.length; i < l; ) {
  21014. var action = outline[ i ++ ];
  21015. switch ( action ) {
  21016. case 'm': // moveTo
  21017. x = outline[ i ++ ] * scale + offset;
  21018. y = outline[ i ++ ] * scale;
  21019. path.moveTo( x, y );
  21020. break;
  21021. case 'l': // lineTo
  21022. x = outline[ i ++ ] * scale + offset;
  21023. y = outline[ i ++ ] * scale;
  21024. path.lineTo( x, y );
  21025. break;
  21026. case 'q': // quadraticCurveTo
  21027. cpx = outline[ i ++ ] * scale + offset;
  21028. cpy = outline[ i ++ ] * scale;
  21029. cpx1 = outline[ i ++ ] * scale + offset;
  21030. cpy1 = outline[ i ++ ] * scale;
  21031. path.quadraticCurveTo( cpx1, cpy1, cpx, cpy );
  21032. laste = pts[ pts.length - 1 ];
  21033. if ( laste ) {
  21034. cpx0 = laste.x;
  21035. cpy0 = laste.y;
  21036. for ( var i2 = 1; i2 <= divisions; i2 ++ ) {
  21037. var t = i2 / divisions;
  21038. b2( t, cpx0, cpx1, cpx );
  21039. b2( t, cpy0, cpy1, cpy );
  21040. }
  21041. }
  21042. break;
  21043. case 'b': // bezierCurveTo
  21044. cpx = outline[ i ++ ] * scale + offset;
  21045. cpy = outline[ i ++ ] * scale;
  21046. cpx1 = outline[ i ++ ] * scale + offset;
  21047. cpy1 = outline[ i ++ ] * scale;
  21048. cpx2 = outline[ i ++ ] * scale + offset;
  21049. cpy2 = outline[ i ++ ] * scale;
  21050. path.bezierCurveTo( cpx1, cpy1, cpx2, cpy2, cpx, cpy );
  21051. laste = pts[ pts.length - 1 ];
  21052. if ( laste ) {
  21053. cpx0 = laste.x;
  21054. cpy0 = laste.y;
  21055. for ( var i2 = 1; i2 <= divisions; i2 ++ ) {
  21056. var t = i2 / divisions;
  21057. b3( t, cpx0, cpx1, cpx2, cpx );
  21058. b3( t, cpy0, cpy1, cpy2, cpy );
  21059. }
  21060. }
  21061. break;
  21062. }
  21063. }
  21064. }
  21065. return { offset: glyph.ha * scale, path: path };
  21066. }
  21067. //
  21068. if ( size === undefined ) size = 100;
  21069. if ( divisions === undefined ) divisions = 4;
  21070. var data = this.data;
  21071. var paths = createPaths( text );
  21072. var shapes = [];
  21073. for ( var p = 0, pl = paths.length; p < pl; p ++ ) {
  21074. Array.prototype.push.apply( shapes, paths[ p ].toShapes() );
  21075. }
  21076. return shapes;
  21077. }
  21078. } );
  21079. // File:src/extras/core/Path.js
  21080. /**
  21081. * @author zz85 / http://www.lab4games.net/zz85/blog
  21082. * Creates free form 2d path using series of points, lines or curves.
  21083. *
  21084. **/
  21085. THREE.Path = function ( points ) {
  21086. THREE.CurvePath.call( this );
  21087. this.actions = [];
  21088. if ( points ) {
  21089. this.fromPoints( points );
  21090. }
  21091. };
  21092. THREE.Path.prototype = Object.assign( Object.create( THREE.CurvePath.prototype ), {
  21093. constructor: THREE.Path,
  21094. // TODO Clean up PATH API
  21095. // Create path using straight lines to connect all points
  21096. // - vectors: array of Vector2
  21097. fromPoints: function ( vectors ) {
  21098. this.moveTo( vectors[ 0 ].x, vectors[ 0 ].y );
  21099. for ( var i = 1, l = vectors.length; i < l; i ++ ) {
  21100. this.lineTo( vectors[ i ].x, vectors[ i ].y );
  21101. }
  21102. },
  21103. moveTo: function ( x, y ) {
  21104. this.actions.push( { action: 'moveTo', args: [ x, y ] } );
  21105. },
  21106. lineTo: function ( x, y ) {
  21107. var lastargs = this.actions[ this.actions.length - 1 ].args;
  21108. var x0 = lastargs[ lastargs.length - 2 ];
  21109. var y0 = lastargs[ lastargs.length - 1 ];
  21110. var curve = new THREE.LineCurve( new THREE.Vector2( x0, y0 ), new THREE.Vector2( x, y ) );
  21111. this.curves.push( curve );
  21112. this.actions.push( { action: 'lineTo', args: [ x, y ] } );
  21113. },
  21114. quadraticCurveTo: function ( aCPx, aCPy, aX, aY ) {
  21115. var lastargs = this.actions[ this.actions.length - 1 ].args;
  21116. var x0 = lastargs[ lastargs.length - 2 ];
  21117. var y0 = lastargs[ lastargs.length - 1 ];
  21118. var curve = new THREE.QuadraticBezierCurve(
  21119. new THREE.Vector2( x0, y0 ),
  21120. new THREE.Vector2( aCPx, aCPy ),
  21121. new THREE.Vector2( aX, aY )
  21122. );
  21123. this.curves.push( curve );
  21124. this.actions.push( { action: 'quadraticCurveTo', args: [ aCPx, aCPy, aX, aY ] } );
  21125. },
  21126. bezierCurveTo: function ( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY ) {
  21127. var lastargs = this.actions[ this.actions.length - 1 ].args;
  21128. var x0 = lastargs[ lastargs.length - 2 ];
  21129. var y0 = lastargs[ lastargs.length - 1 ];
  21130. var curve = new THREE.CubicBezierCurve(
  21131. new THREE.Vector2( x0, y0 ),
  21132. new THREE.Vector2( aCP1x, aCP1y ),
  21133. new THREE.Vector2( aCP2x, aCP2y ),
  21134. new THREE.Vector2( aX, aY )
  21135. );
  21136. this.curves.push( curve );
  21137. this.actions.push( { action: 'bezierCurveTo', args: [ aCP1x, aCP1y, aCP2x, aCP2y, aX, aY ] } );
  21138. },
  21139. splineThru: function ( pts /*Array of Vector*/ ) {
  21140. var args = Array.prototype.slice.call( arguments );
  21141. var lastargs = this.actions[ this.actions.length - 1 ].args;
  21142. var x0 = lastargs[ lastargs.length - 2 ];
  21143. var y0 = lastargs[ lastargs.length - 1 ];
  21144. var npts = [ new THREE.Vector2( x0, y0 ) ];
  21145. Array.prototype.push.apply( npts, pts );
  21146. var curve = new THREE.SplineCurve( npts );
  21147. this.curves.push( curve );
  21148. var lastPoint = pts[ pts.length - 1 ];
  21149. args.push( lastPoint.x );
  21150. args.push( lastPoint.y );
  21151. this.actions.push( { action: 'splineThru', args: args } );
  21152. },
  21153. arc: function ( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  21154. var lastargs = this.actions[ this.actions.length - 1 ].args;
  21155. var x0 = lastargs[ lastargs.length - 2 ];
  21156. var y0 = lastargs[ lastargs.length - 1 ];
  21157. this.absarc( aX + x0, aY + y0, aRadius,
  21158. aStartAngle, aEndAngle, aClockwise );
  21159. },
  21160. absarc: function ( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  21161. this.absellipse( aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise );
  21162. },
  21163. ellipse: function ( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  21164. var lastargs = this.actions[ this.actions.length - 1 ].args;
  21165. var x0 = lastargs[ lastargs.length - 2 ];
  21166. var y0 = lastargs[ lastargs.length - 1 ];
  21167. this.absellipse( aX + x0, aY + y0, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation );
  21168. },
  21169. absellipse: function ( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  21170. var args = [
  21171. aX, aY,
  21172. xRadius, yRadius,
  21173. aStartAngle, aEndAngle,
  21174. aClockwise,
  21175. aRotation || 0 // aRotation is optional.
  21176. ];
  21177. var curve = new THREE.EllipseCurve( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation );
  21178. this.curves.push( curve );
  21179. var lastPoint = curve.getPoint( 1 );
  21180. args.push( lastPoint.x );
  21181. args.push( lastPoint.y );
  21182. this.actions.push( { action: 'ellipse', args: args } );
  21183. },
  21184. getSpacedPoints: function ( divisions ) {
  21185. if ( ! divisions ) divisions = 40;
  21186. var points = [];
  21187. for ( var i = 0; i < divisions; i ++ ) {
  21188. points.push( this.getPoint( i / divisions ) );
  21189. //if ( !this.getPoint( i / divisions ) ) throw "DIE";
  21190. }
  21191. if ( this.autoClose ) {
  21192. points.push( points[ 0 ] );
  21193. }
  21194. return points;
  21195. },
  21196. getPoints: function ( divisions ) {
  21197. divisions = divisions || 12;
  21198. var b2 = THREE.ShapeUtils.b2;
  21199. var b3 = THREE.ShapeUtils.b3;
  21200. var points = [];
  21201. var cpx, cpy, cpx2, cpy2, cpx1, cpy1, cpx0, cpy0,
  21202. laste, tx, ty;
  21203. for ( var i = 0, l = this.actions.length; i < l; i ++ ) {
  21204. var item = this.actions[ i ];
  21205. var action = item.action;
  21206. var args = item.args;
  21207. switch ( action ) {
  21208. case 'moveTo':
  21209. points.push( new THREE.Vector2( args[ 0 ], args[ 1 ] ) );
  21210. break;
  21211. case 'lineTo':
  21212. points.push( new THREE.Vector2( args[ 0 ], args[ 1 ] ) );
  21213. break;
  21214. case 'quadraticCurveTo':
  21215. cpx = args[ 2 ];
  21216. cpy = args[ 3 ];
  21217. cpx1 = args[ 0 ];
  21218. cpy1 = args[ 1 ];
  21219. if ( points.length > 0 ) {
  21220. laste = points[ points.length - 1 ];
  21221. cpx0 = laste.x;
  21222. cpy0 = laste.y;
  21223. } else {
  21224. laste = this.actions[ i - 1 ].args;
  21225. cpx0 = laste[ laste.length - 2 ];
  21226. cpy0 = laste[ laste.length - 1 ];
  21227. }
  21228. for ( var j = 1; j <= divisions; j ++ ) {
  21229. var t = j / divisions;
  21230. tx = b2( t, cpx0, cpx1, cpx );
  21231. ty = b2( t, cpy0, cpy1, cpy );
  21232. points.push( new THREE.Vector2( tx, ty ) );
  21233. }
  21234. break;
  21235. case 'bezierCurveTo':
  21236. cpx = args[ 4 ];
  21237. cpy = args[ 5 ];
  21238. cpx1 = args[ 0 ];
  21239. cpy1 = args[ 1 ];
  21240. cpx2 = args[ 2 ];
  21241. cpy2 = args[ 3 ];
  21242. if ( points.length > 0 ) {
  21243. laste = points[ points.length - 1 ];
  21244. cpx0 = laste.x;
  21245. cpy0 = laste.y;
  21246. } else {
  21247. laste = this.actions[ i - 1 ].args;
  21248. cpx0 = laste[ laste.length - 2 ];
  21249. cpy0 = laste[ laste.length - 1 ];
  21250. }
  21251. for ( var j = 1; j <= divisions; j ++ ) {
  21252. var t = j / divisions;
  21253. tx = b3( t, cpx0, cpx1, cpx2, cpx );
  21254. ty = b3( t, cpy0, cpy1, cpy2, cpy );
  21255. points.push( new THREE.Vector2( tx, ty ) );
  21256. }
  21257. break;
  21258. case 'splineThru':
  21259. laste = this.actions[ i - 1 ].args;
  21260. var last = new THREE.Vector2( laste[ laste.length - 2 ], laste[ laste.length - 1 ] );
  21261. var spts = [ last ];
  21262. var n = divisions * args[ 0 ].length;
  21263. spts = spts.concat( args[ 0 ] );
  21264. var spline = new THREE.SplineCurve( spts );
  21265. for ( var j = 1; j <= n; j ++ ) {
  21266. points.push( spline.getPointAt( j / n ) );
  21267. }
  21268. break;
  21269. case 'arc':
  21270. var aX = args[ 0 ], aY = args[ 1 ],
  21271. aRadius = args[ 2 ],
  21272. aStartAngle = args[ 3 ], aEndAngle = args[ 4 ],
  21273. aClockwise = !! args[ 5 ];
  21274. var deltaAngle = aEndAngle - aStartAngle;
  21275. var angle;
  21276. var tdivisions = divisions * 2;
  21277. for ( var j = 1; j <= tdivisions; j ++ ) {
  21278. var t = j / tdivisions;
  21279. if ( ! aClockwise ) {
  21280. t = 1 - t;
  21281. }
  21282. angle = aStartAngle + t * deltaAngle;
  21283. tx = aX + aRadius * Math.cos( angle );
  21284. ty = aY + aRadius * Math.sin( angle );
  21285. //console.log('t', t, 'angle', angle, 'tx', tx, 'ty', ty);
  21286. points.push( new THREE.Vector2( tx, ty ) );
  21287. }
  21288. //console.log(points);
  21289. break;
  21290. case 'ellipse':
  21291. var aX = args[ 0 ], aY = args[ 1 ],
  21292. xRadius = args[ 2 ],
  21293. yRadius = args[ 3 ],
  21294. aStartAngle = args[ 4 ], aEndAngle = args[ 5 ],
  21295. aClockwise = !! args[ 6 ],
  21296. aRotation = args[ 7 ];
  21297. var deltaAngle = aEndAngle - aStartAngle;
  21298. var angle;
  21299. var tdivisions = divisions * 2;
  21300. var cos, sin;
  21301. if ( aRotation !== 0 ) {
  21302. cos = Math.cos( aRotation );
  21303. sin = Math.sin( aRotation );
  21304. }
  21305. for ( var j = 1; j <= tdivisions; j ++ ) {
  21306. var t = j / tdivisions;
  21307. if ( ! aClockwise ) {
  21308. t = 1 - t;
  21309. }
  21310. angle = aStartAngle + t * deltaAngle;
  21311. tx = aX + xRadius * Math.cos( angle );
  21312. ty = aY + yRadius * Math.sin( angle );
  21313. if ( aRotation !== 0 ) {
  21314. var x = tx, y = ty;
  21315. // Rotate the point about the center of the ellipse.
  21316. tx = ( x - aX ) * cos - ( y - aY ) * sin + aX;
  21317. ty = ( x - aX ) * sin + ( y - aY ) * cos + aY;
  21318. }
  21319. //console.log('t', t, 'angle', angle, 'tx', tx, 'ty', ty);
  21320. points.push( new THREE.Vector2( tx, ty ) );
  21321. }
  21322. //console.log(points);
  21323. break;
  21324. } // end switch
  21325. }
  21326. // Normalize to remove the closing point by default.
  21327. var lastPoint = points[ points.length - 1 ];
  21328. if ( Math.abs( lastPoint.x - points[ 0 ].x ) < Number.EPSILON &&
  21329. Math.abs( lastPoint.y - points[ 0 ].y ) < Number.EPSILON )
  21330. points.splice( points.length - 1, 1 );
  21331. if ( this.autoClose ) {
  21332. points.push( points[ 0 ] );
  21333. }
  21334. return points;
  21335. },
  21336. toShapes: function ( isCCW, noHoles ) {
  21337. function extractSubpaths( inActions ) {
  21338. var subPaths = [], lastPath = new THREE.Path();
  21339. for ( var i = 0, l = inActions.length; i < l; i ++ ) {
  21340. var item = inActions[ i ];
  21341. var args = item.args;
  21342. var action = item.action;
  21343. if ( action === 'moveTo' ) {
  21344. if ( lastPath.actions.length !== 0 ) {
  21345. subPaths.push( lastPath );
  21346. lastPath = new THREE.Path();
  21347. }
  21348. }
  21349. lastPath[ action ].apply( lastPath, args );
  21350. }
  21351. if ( lastPath.actions.length !== 0 ) {
  21352. subPaths.push( lastPath );
  21353. }
  21354. // console.log(subPaths);
  21355. return subPaths;
  21356. }
  21357. function toShapesNoHoles( inSubpaths ) {
  21358. var shapes = [];
  21359. for ( var i = 0, l = inSubpaths.length; i < l; i ++ ) {
  21360. var tmpPath = inSubpaths[ i ];
  21361. var tmpShape = new THREE.Shape();
  21362. tmpShape.actions = tmpPath.actions;
  21363. tmpShape.curves = tmpPath.curves;
  21364. shapes.push( tmpShape );
  21365. }
  21366. //console.log("shape", shapes);
  21367. return shapes;
  21368. }
  21369. function isPointInsidePolygon( inPt, inPolygon ) {
  21370. var polyLen = inPolygon.length;
  21371. // inPt on polygon contour => immediate success or
  21372. // toggling of inside/outside at every single! intersection point of an edge
  21373. // with the horizontal line through inPt, left of inPt
  21374. // not counting lowerY endpoints of edges and whole edges on that line
  21375. var inside = false;
  21376. for ( var p = polyLen - 1, q = 0; q < polyLen; p = q ++ ) {
  21377. var edgeLowPt = inPolygon[ p ];
  21378. var edgeHighPt = inPolygon[ q ];
  21379. var edgeDx = edgeHighPt.x - edgeLowPt.x;
  21380. var edgeDy = edgeHighPt.y - edgeLowPt.y;
  21381. if ( Math.abs( edgeDy ) > Number.EPSILON ) {
  21382. // not parallel
  21383. if ( edgeDy < 0 ) {
  21384. edgeLowPt = inPolygon[ q ]; edgeDx = - edgeDx;
  21385. edgeHighPt = inPolygon[ p ]; edgeDy = - edgeDy;
  21386. }
  21387. if ( ( inPt.y < edgeLowPt.y ) || ( inPt.y > edgeHighPt.y ) ) continue;
  21388. if ( inPt.y === edgeLowPt.y ) {
  21389. if ( inPt.x === edgeLowPt.x ) return true; // inPt is on contour ?
  21390. // continue; // no intersection or edgeLowPt => doesn't count !!!
  21391. } else {
  21392. var perpEdge = edgeDy * ( inPt.x - edgeLowPt.x ) - edgeDx * ( inPt.y - edgeLowPt.y );
  21393. if ( perpEdge === 0 ) return true; // inPt is on contour ?
  21394. if ( perpEdge < 0 ) continue;
  21395. inside = ! inside; // true intersection left of inPt
  21396. }
  21397. } else {
  21398. // parallel or collinear
  21399. if ( inPt.y !== edgeLowPt.y ) continue; // parallel
  21400. // edge lies on the same horizontal line as inPt
  21401. if ( ( ( edgeHighPt.x <= inPt.x ) && ( inPt.x <= edgeLowPt.x ) ) ||
  21402. ( ( edgeLowPt.x <= inPt.x ) && ( inPt.x <= edgeHighPt.x ) ) ) return true; // inPt: Point on contour !
  21403. // continue;
  21404. }
  21405. }
  21406. return inside;
  21407. }
  21408. var isClockWise = THREE.ShapeUtils.isClockWise;
  21409. var subPaths = extractSubpaths( this.actions );
  21410. if ( subPaths.length === 0 ) return [];
  21411. if ( noHoles === true ) return toShapesNoHoles( subPaths );
  21412. var solid, tmpPath, tmpShape, shapes = [];
  21413. if ( subPaths.length === 1 ) {
  21414. tmpPath = subPaths[ 0 ];
  21415. tmpShape = new THREE.Shape();
  21416. tmpShape.actions = tmpPath.actions;
  21417. tmpShape.curves = tmpPath.curves;
  21418. shapes.push( tmpShape );
  21419. return shapes;
  21420. }
  21421. var holesFirst = ! isClockWise( subPaths[ 0 ].getPoints() );
  21422. holesFirst = isCCW ? ! holesFirst : holesFirst;
  21423. // console.log("Holes first", holesFirst);
  21424. var betterShapeHoles = [];
  21425. var newShapes = [];
  21426. var newShapeHoles = [];
  21427. var mainIdx = 0;
  21428. var tmpPoints;
  21429. newShapes[ mainIdx ] = undefined;
  21430. newShapeHoles[ mainIdx ] = [];
  21431. for ( var i = 0, l = subPaths.length; i < l; i ++ ) {
  21432. tmpPath = subPaths[ i ];
  21433. tmpPoints = tmpPath.getPoints();
  21434. solid = isClockWise( tmpPoints );
  21435. solid = isCCW ? ! solid : solid;
  21436. if ( solid ) {
  21437. if ( ( ! holesFirst ) && ( newShapes[ mainIdx ] ) ) mainIdx ++;
  21438. newShapes[ mainIdx ] = { s: new THREE.Shape(), p: tmpPoints };
  21439. newShapes[ mainIdx ].s.actions = tmpPath.actions;
  21440. newShapes[ mainIdx ].s.curves = tmpPath.curves;
  21441. if ( holesFirst ) mainIdx ++;
  21442. newShapeHoles[ mainIdx ] = [];
  21443. //console.log('cw', i);
  21444. } else {
  21445. newShapeHoles[ mainIdx ].push( { h: tmpPath, p: tmpPoints[ 0 ] } );
  21446. //console.log('ccw', i);
  21447. }
  21448. }
  21449. // only Holes? -> probably all Shapes with wrong orientation
  21450. if ( ! newShapes[ 0 ] ) return toShapesNoHoles( subPaths );
  21451. if ( newShapes.length > 1 ) {
  21452. var ambiguous = false;
  21453. var toChange = [];
  21454. for ( var sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx ++ ) {
  21455. betterShapeHoles[ sIdx ] = [];
  21456. }
  21457. for ( var sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx ++ ) {
  21458. var sho = newShapeHoles[ sIdx ];
  21459. for ( var hIdx = 0; hIdx < sho.length; hIdx ++ ) {
  21460. var ho = sho[ hIdx ];
  21461. var hole_unassigned = true;
  21462. for ( var s2Idx = 0; s2Idx < newShapes.length; s2Idx ++ ) {
  21463. if ( isPointInsidePolygon( ho.p, newShapes[ s2Idx ].p ) ) {
  21464. if ( sIdx !== s2Idx ) toChange.push( { froms: sIdx, tos: s2Idx, hole: hIdx } );
  21465. if ( hole_unassigned ) {
  21466. hole_unassigned = false;
  21467. betterShapeHoles[ s2Idx ].push( ho );
  21468. } else {
  21469. ambiguous = true;
  21470. }
  21471. }
  21472. }
  21473. if ( hole_unassigned ) {
  21474. betterShapeHoles[ sIdx ].push( ho );
  21475. }
  21476. }
  21477. }
  21478. // console.log("ambiguous: ", ambiguous);
  21479. if ( toChange.length > 0 ) {
  21480. // console.log("to change: ", toChange);
  21481. if ( ! ambiguous ) newShapeHoles = betterShapeHoles;
  21482. }
  21483. }
  21484. var tmpHoles;
  21485. for ( var i = 0, il = newShapes.length; i < il; i ++ ) {
  21486. tmpShape = newShapes[ i ].s;
  21487. shapes.push( tmpShape );
  21488. tmpHoles = newShapeHoles[ i ];
  21489. for ( var j = 0, jl = tmpHoles.length; j < jl; j ++ ) {
  21490. tmpShape.holes.push( tmpHoles[ j ].h );
  21491. }
  21492. }
  21493. //console.log("shape", shapes);
  21494. return shapes;
  21495. }
  21496. } );
  21497. // File:src/extras/core/Shape.js
  21498. /**
  21499. * @author zz85 / http://www.lab4games.net/zz85/blog
  21500. * Defines a 2d shape plane using paths.
  21501. **/
  21502. // STEP 1 Create a path.
  21503. // STEP 2 Turn path into shape.
  21504. // STEP 3 ExtrudeGeometry takes in Shape/Shapes
  21505. // STEP 3a - Extract points from each shape, turn to vertices
  21506. // STEP 3b - Triangulate each shape, add faces.
  21507. THREE.Shape = function () {
  21508. THREE.Path.apply( this, arguments );
  21509. this.holes = [];
  21510. };
  21511. THREE.Shape.prototype = Object.assign( Object.create( THREE.Path.prototype ), {
  21512. constructor: THREE.Shape,
  21513. // Convenience method to return ExtrudeGeometry
  21514. extrude: function ( options ) {
  21515. return new THREE.ExtrudeGeometry( this, options );
  21516. },
  21517. // Convenience method to return ShapeGeometry
  21518. makeGeometry: function ( options ) {
  21519. return new THREE.ShapeGeometry( this, options );
  21520. },
  21521. getPointsHoles: function ( divisions ) {
  21522. var holesPts = [];
  21523. for ( var i = 0, l = this.holes.length; i < l; i ++ ) {
  21524. holesPts[ i ] = this.holes[ i ].getPoints( divisions );
  21525. }
  21526. return holesPts;
  21527. },
  21528. // Get points of shape and holes (keypoints based on segments parameter)
  21529. extractAllPoints: function ( divisions ) {
  21530. return {
  21531. shape: this.getPoints( divisions ),
  21532. holes: this.getPointsHoles( divisions )
  21533. };
  21534. },
  21535. extractPoints: function ( divisions ) {
  21536. return this.extractAllPoints( divisions );
  21537. }
  21538. } );
  21539. // File:src/extras/curves/LineCurve.js
  21540. /**************************************************************
  21541. * Line
  21542. **************************************************************/
  21543. THREE.LineCurve = function ( v1, v2 ) {
  21544. this.v1 = v1;
  21545. this.v2 = v2;
  21546. };
  21547. THREE.LineCurve.prototype = Object.create( THREE.Curve.prototype );
  21548. THREE.LineCurve.prototype.constructor = THREE.LineCurve;
  21549. THREE.LineCurve.prototype.getPoint = function ( t ) {
  21550. var point = this.v2.clone().sub( this.v1 );
  21551. point.multiplyScalar( t ).add( this.v1 );
  21552. return point;
  21553. };
  21554. // Line curve is linear, so we can overwrite default getPointAt
  21555. THREE.LineCurve.prototype.getPointAt = function ( u ) {
  21556. return this.getPoint( u );
  21557. };
  21558. THREE.LineCurve.prototype.getTangent = function( t ) {
  21559. var tangent = this.v2.clone().sub( this.v1 );
  21560. return tangent.normalize();
  21561. };
  21562. // File:src/extras/curves/QuadraticBezierCurve.js
  21563. /**************************************************************
  21564. * Quadratic Bezier curve
  21565. **************************************************************/
  21566. THREE.QuadraticBezierCurve = function ( v0, v1, v2 ) {
  21567. this.v0 = v0;
  21568. this.v1 = v1;
  21569. this.v2 = v2;
  21570. };
  21571. THREE.QuadraticBezierCurve.prototype = Object.create( THREE.Curve.prototype );
  21572. THREE.QuadraticBezierCurve.prototype.constructor = THREE.QuadraticBezierCurve;
  21573. THREE.QuadraticBezierCurve.prototype.getPoint = function ( t ) {
  21574. var b2 = THREE.ShapeUtils.b2;
  21575. return new THREE.Vector2(
  21576. b2( t, this.v0.x, this.v1.x, this.v2.x ),
  21577. b2( t, this.v0.y, this.v1.y, this.v2.y )
  21578. );
  21579. };
  21580. THREE.QuadraticBezierCurve.prototype.getTangent = function( t ) {
  21581. var tangentQuadraticBezier = THREE.CurveUtils.tangentQuadraticBezier;
  21582. return new THREE.Vector2(
  21583. tangentQuadraticBezier( t, this.v0.x, this.v1.x, this.v2.x ),
  21584. tangentQuadraticBezier( t, this.v0.y, this.v1.y, this.v2.y )
  21585. ).normalize();
  21586. };
  21587. // File:src/extras/curves/CubicBezierCurve.js
  21588. /**************************************************************
  21589. * Cubic Bezier curve
  21590. **************************************************************/
  21591. THREE.CubicBezierCurve = function ( v0, v1, v2, v3 ) {
  21592. this.v0 = v0;
  21593. this.v1 = v1;
  21594. this.v2 = v2;
  21595. this.v3 = v3;
  21596. };
  21597. THREE.CubicBezierCurve.prototype = Object.create( THREE.Curve.prototype );
  21598. THREE.CubicBezierCurve.prototype.constructor = THREE.CubicBezierCurve;
  21599. THREE.CubicBezierCurve.prototype.getPoint = function ( t ) {
  21600. var b3 = THREE.ShapeUtils.b3;
  21601. return new THREE.Vector2(
  21602. b3( t, this.v0.x, this.v1.x, this.v2.x, this.v3.x ),
  21603. b3( t, this.v0.y, this.v1.y, this.v2.y, this.v3.y )
  21604. );
  21605. };
  21606. THREE.CubicBezierCurve.prototype.getTangent = function( t ) {
  21607. var tangentCubicBezier = THREE.CurveUtils.tangentCubicBezier;
  21608. return new THREE.Vector2(
  21609. tangentCubicBezier( t, this.v0.x, this.v1.x, this.v2.x, this.v3.x ),
  21610. tangentCubicBezier( t, this.v0.y, this.v1.y, this.v2.y, this.v3.y )
  21611. ).normalize();
  21612. };
  21613. // File:src/extras/curves/SplineCurve.js
  21614. /**************************************************************
  21615. * Spline curve
  21616. **************************************************************/
  21617. THREE.SplineCurve = function ( points /* array of Vector2 */ ) {
  21618. this.points = ( points == undefined ) ? [] : points;
  21619. };
  21620. THREE.SplineCurve.prototype = Object.create( THREE.Curve.prototype );
  21621. THREE.SplineCurve.prototype.constructor = THREE.SplineCurve;
  21622. THREE.SplineCurve.prototype.getPoint = function ( t ) {
  21623. var points = this.points;
  21624. var point = ( points.length - 1 ) * t;
  21625. var intPoint = Math.floor( point );
  21626. var weight = point - intPoint;
  21627. var point0 = points[ intPoint === 0 ? intPoint : intPoint - 1 ];
  21628. var point1 = points[ intPoint ];
  21629. var point2 = points[ intPoint > points.length - 2 ? points.length - 1 : intPoint + 1 ];
  21630. var point3 = points[ intPoint > points.length - 3 ? points.length - 1 : intPoint + 2 ];
  21631. var interpolate = THREE.CurveUtils.interpolate;
  21632. return new THREE.Vector2(
  21633. interpolate( point0.x, point1.x, point2.x, point3.x, weight ),
  21634. interpolate( point0.y, point1.y, point2.y, point3.y, weight )
  21635. );
  21636. };
  21637. // File:src/extras/curves/EllipseCurve.js
  21638. /**************************************************************
  21639. * Ellipse curve
  21640. **************************************************************/
  21641. THREE.EllipseCurve = function ( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  21642. this.aX = aX;
  21643. this.aY = aY;
  21644. this.xRadius = xRadius;
  21645. this.yRadius = yRadius;
  21646. this.aStartAngle = aStartAngle;
  21647. this.aEndAngle = aEndAngle;
  21648. this.aClockwise = aClockwise;
  21649. this.aRotation = aRotation || 0;
  21650. };
  21651. THREE.EllipseCurve.prototype = Object.create( THREE.Curve.prototype );
  21652. THREE.EllipseCurve.prototype.constructor = THREE.EllipseCurve;
  21653. THREE.EllipseCurve.prototype.getPoint = function ( t ) {
  21654. var deltaAngle = this.aEndAngle - this.aStartAngle;
  21655. if ( deltaAngle < 0 ) deltaAngle += Math.PI * 2;
  21656. if ( deltaAngle > Math.PI * 2 ) deltaAngle -= Math.PI * 2;
  21657. var angle;
  21658. if ( this.aClockwise === true ) {
  21659. angle = this.aEndAngle + ( 1 - t ) * ( Math.PI * 2 - deltaAngle );
  21660. } else {
  21661. angle = this.aStartAngle + t * deltaAngle;
  21662. }
  21663. var x = this.aX + this.xRadius * Math.cos( angle );
  21664. var y = this.aY + this.yRadius * Math.sin( angle );
  21665. if ( this.aRotation !== 0 ) {
  21666. var cos = Math.cos( this.aRotation );
  21667. var sin = Math.sin( this.aRotation );
  21668. var tx = x, ty = y;
  21669. // Rotate the point about the center of the ellipse.
  21670. x = ( tx - this.aX ) * cos - ( ty - this.aY ) * sin + this.aX;
  21671. y = ( tx - this.aX ) * sin + ( ty - this.aY ) * cos + this.aY;
  21672. }
  21673. return new THREE.Vector2( x, y );
  21674. };
  21675. // File:src/extras/curves/ArcCurve.js
  21676. /**************************************************************
  21677. * Arc curve
  21678. **************************************************************/
  21679. THREE.ArcCurve = function ( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  21680. THREE.EllipseCurve.call( this, aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise );
  21681. };
  21682. THREE.ArcCurve.prototype = Object.create( THREE.EllipseCurve.prototype );
  21683. THREE.ArcCurve.prototype.constructor = THREE.ArcCurve;
  21684. // File:src/extras/curves/LineCurve3.js
  21685. /**************************************************************
  21686. * Line3D
  21687. **************************************************************/
  21688. THREE.LineCurve3 = THREE.Curve.create(
  21689. function ( v1, v2 ) {
  21690. this.v1 = v1;
  21691. this.v2 = v2;
  21692. },
  21693. function ( t ) {
  21694. var vector = new THREE.Vector3();
  21695. vector.subVectors( this.v2, this.v1 ); // diff
  21696. vector.multiplyScalar( t );
  21697. vector.add( this.v1 );
  21698. return vector;
  21699. }
  21700. );
  21701. // File:src/extras/curves/QuadraticBezierCurve3.js
  21702. /**************************************************************
  21703. * Quadratic Bezier 3D curve
  21704. **************************************************************/
  21705. THREE.QuadraticBezierCurve3 = THREE.Curve.create(
  21706. function ( v0, v1, v2 ) {
  21707. this.v0 = v0;
  21708. this.v1 = v1;
  21709. this.v2 = v2;
  21710. },
  21711. function ( t ) {
  21712. var b2 = THREE.ShapeUtils.b2;
  21713. return new THREE.Vector3(
  21714. b2( t, this.v0.x, this.v1.x, this.v2.x ),
  21715. b2( t, this.v0.y, this.v1.y, this.v2.y ),
  21716. b2( t, this.v0.z, this.v1.z, this.v2.z )
  21717. );
  21718. }
  21719. );
  21720. // File:src/extras/curves/CubicBezierCurve3.js
  21721. /**************************************************************
  21722. * Cubic Bezier 3D curve
  21723. **************************************************************/
  21724. THREE.CubicBezierCurve3 = THREE.Curve.create(
  21725. function ( v0, v1, v2, v3 ) {
  21726. this.v0 = v0;
  21727. this.v1 = v1;
  21728. this.v2 = v2;
  21729. this.v3 = v3;
  21730. },
  21731. function ( t ) {
  21732. var b3 = THREE.ShapeUtils.b3;
  21733. return new THREE.Vector3(
  21734. b3( t, this.v0.x, this.v1.x, this.v2.x, this.v3.x ),
  21735. b3( t, this.v0.y, this.v1.y, this.v2.y, this.v3.y ),
  21736. b3( t, this.v0.z, this.v1.z, this.v2.z, this.v3.z )
  21737. );
  21738. }
  21739. );
  21740. // File:src/extras/curves/SplineCurve3.js
  21741. /**************************************************************
  21742. * Spline 3D curve
  21743. **************************************************************/
  21744. THREE.SplineCurve3 = THREE.Curve.create(
  21745. function ( points /* array of Vector3 */ ) {
  21746. console.warn( 'THREE.SplineCurve3 will be deprecated. Please use THREE.CatmullRomCurve3' );
  21747. this.points = ( points == undefined ) ? [] : points;
  21748. },
  21749. function ( t ) {
  21750. var points = this.points;
  21751. var point = ( points.length - 1 ) * t;
  21752. var intPoint = Math.floor( point );
  21753. var weight = point - intPoint;
  21754. var point0 = points[ intPoint == 0 ? intPoint : intPoint - 1 ];
  21755. var point1 = points[ intPoint ];
  21756. var point2 = points[ intPoint > points.length - 2 ? points.length - 1 : intPoint + 1 ];
  21757. var point3 = points[ intPoint > points.length - 3 ? points.length - 1 : intPoint + 2 ];
  21758. var interpolate = THREE.CurveUtils.interpolate;
  21759. return new THREE.Vector3(
  21760. interpolate( point0.x, point1.x, point2.x, point3.x, weight ),
  21761. interpolate( point0.y, point1.y, point2.y, point3.y, weight ),
  21762. interpolate( point0.z, point1.z, point2.z, point3.z, weight )
  21763. );
  21764. }
  21765. );
  21766. // File:src/extras/curves/CatmullRomCurve3.js
  21767. /**
  21768. * @author zz85 https://github.com/zz85
  21769. *
  21770. * Centripetal CatmullRom Curve - which is useful for avoiding
  21771. * cusps and self-intersections in non-uniform catmull rom curves.
  21772. * http://www.cemyuksel.com/research/catmullrom_param/catmullrom.pdf
  21773. *
  21774. * curve.type accepts centripetal(default), chordal and catmullrom
  21775. * curve.tension is used for catmullrom which defaults to 0.5
  21776. */
  21777. THREE.CatmullRomCurve3 = ( function() {
  21778. var
  21779. tmp = new THREE.Vector3(),
  21780. px = new CubicPoly(),
  21781. py = new CubicPoly(),
  21782. pz = new CubicPoly();
  21783. /*
  21784. Based on an optimized c++ solution in
  21785. - http://stackoverflow.com/questions/9489736/catmull-rom-curve-with-no-cusps-and-no-self-intersections/
  21786. - http://ideone.com/NoEbVM
  21787. This CubicPoly class could be used for reusing some variables and calculations,
  21788. but for three.js curve use, it could be possible inlined and flatten into a single function call
  21789. which can be placed in CurveUtils.
  21790. */
  21791. function CubicPoly() {
  21792. }
  21793. /*
  21794. * Compute coefficients for a cubic polynomial
  21795. * p(s) = c0 + c1*s + c2*s^2 + c3*s^3
  21796. * such that
  21797. * p(0) = x0, p(1) = x1
  21798. * and
  21799. * p'(0) = t0, p'(1) = t1.
  21800. */
  21801. CubicPoly.prototype.init = function( x0, x1, t0, t1 ) {
  21802. this.c0 = x0;
  21803. this.c1 = t0;
  21804. this.c2 = - 3 * x0 + 3 * x1 - 2 * t0 - t1;
  21805. this.c3 = 2 * x0 - 2 * x1 + t0 + t1;
  21806. };
  21807. CubicPoly.prototype.initNonuniformCatmullRom = function( x0, x1, x2, x3, dt0, dt1, dt2 ) {
  21808. // compute tangents when parameterized in [t1,t2]
  21809. var t1 = ( x1 - x0 ) / dt0 - ( x2 - x0 ) / ( dt0 + dt1 ) + ( x2 - x1 ) / dt1;
  21810. var t2 = ( x2 - x1 ) / dt1 - ( x3 - x1 ) / ( dt1 + dt2 ) + ( x3 - x2 ) / dt2;
  21811. // rescale tangents for parametrization in [0,1]
  21812. t1 *= dt1;
  21813. t2 *= dt1;
  21814. // initCubicPoly
  21815. this.init( x1, x2, t1, t2 );
  21816. };
  21817. // standard Catmull-Rom spline: interpolate between x1 and x2 with previous/following points x1/x4
  21818. CubicPoly.prototype.initCatmullRom = function( x0, x1, x2, x3, tension ) {
  21819. this.init( x1, x2, tension * ( x2 - x0 ), tension * ( x3 - x1 ) );
  21820. };
  21821. CubicPoly.prototype.calc = function( t ) {
  21822. var t2 = t * t;
  21823. var t3 = t2 * t;
  21824. return this.c0 + this.c1 * t + this.c2 * t2 + this.c3 * t3;
  21825. };
  21826. // Subclass Three.js curve
  21827. return THREE.Curve.create(
  21828. function ( p /* array of Vector3 */ ) {
  21829. this.points = p || [];
  21830. this.closed = false;
  21831. },
  21832. function ( t ) {
  21833. var points = this.points,
  21834. point, intPoint, weight, l;
  21835. l = points.length;
  21836. if ( l < 2 ) console.log( 'duh, you need at least 2 points' );
  21837. point = ( l - ( this.closed ? 0 : 1 ) ) * t;
  21838. intPoint = Math.floor( point );
  21839. weight = point - intPoint;
  21840. if ( this.closed ) {
  21841. intPoint += intPoint > 0 ? 0 : ( Math.floor( Math.abs( intPoint ) / points.length ) + 1 ) * points.length;
  21842. } else if ( weight === 0 && intPoint === l - 1 ) {
  21843. intPoint = l - 2;
  21844. weight = 1;
  21845. }
  21846. var p0, p1, p2, p3; // 4 points
  21847. if ( this.closed || intPoint > 0 ) {
  21848. p0 = points[ ( intPoint - 1 ) % l ];
  21849. } else {
  21850. // extrapolate first point
  21851. tmp.subVectors( points[ 0 ], points[ 1 ] ).add( points[ 0 ] );
  21852. p0 = tmp;
  21853. }
  21854. p1 = points[ intPoint % l ];
  21855. p2 = points[ ( intPoint + 1 ) % l ];
  21856. if ( this.closed || intPoint + 2 < l ) {
  21857. p3 = points[ ( intPoint + 2 ) % l ];
  21858. } else {
  21859. // extrapolate last point
  21860. tmp.subVectors( points[ l - 1 ], points[ l - 2 ] ).add( points[ l - 1 ] );
  21861. p3 = tmp;
  21862. }
  21863. if ( this.type === undefined || this.type === 'centripetal' || this.type === 'chordal' ) {
  21864. // init Centripetal / Chordal Catmull-Rom
  21865. var pow = this.type === 'chordal' ? 0.5 : 0.25;
  21866. var dt0 = Math.pow( p0.distanceToSquared( p1 ), pow );
  21867. var dt1 = Math.pow( p1.distanceToSquared( p2 ), pow );
  21868. var dt2 = Math.pow( p2.distanceToSquared( p3 ), pow );
  21869. // safety check for repeated points
  21870. if ( dt1 < 1e-4 ) dt1 = 1.0;
  21871. if ( dt0 < 1e-4 ) dt0 = dt1;
  21872. if ( dt2 < 1e-4 ) dt2 = dt1;
  21873. px.initNonuniformCatmullRom( p0.x, p1.x, p2.x, p3.x, dt0, dt1, dt2 );
  21874. py.initNonuniformCatmullRom( p0.y, p1.y, p2.y, p3.y, dt0, dt1, dt2 );
  21875. pz.initNonuniformCatmullRom( p0.z, p1.z, p2.z, p3.z, dt0, dt1, dt2 );
  21876. } else if ( this.type === 'catmullrom' ) {
  21877. var tension = this.tension !== undefined ? this.tension : 0.5;
  21878. px.initCatmullRom( p0.x, p1.x, p2.x, p3.x, tension );
  21879. py.initCatmullRom( p0.y, p1.y, p2.y, p3.y, tension );
  21880. pz.initCatmullRom( p0.z, p1.z, p2.z, p3.z, tension );
  21881. }
  21882. var v = new THREE.Vector3(
  21883. px.calc( weight ),
  21884. py.calc( weight ),
  21885. pz.calc( weight )
  21886. );
  21887. return v;
  21888. }
  21889. );
  21890. } )();
  21891. // File:src/extras/curves/ClosedSplineCurve3.js
  21892. /**************************************************************
  21893. * Closed Spline 3D curve
  21894. **************************************************************/
  21895. THREE.ClosedSplineCurve3 = function ( points ) {
  21896. console.warn( 'THREE.ClosedSplineCurve3 has been deprecated. Please use THREE.CatmullRomCurve3.' );
  21897. THREE.CatmullRomCurve3.call( this, points );
  21898. this.type = 'catmullrom';
  21899. this.closed = true;
  21900. };
  21901. THREE.ClosedSplineCurve3.prototype = Object.create( THREE.CatmullRomCurve3.prototype );
  21902. // File:src/extras/geometries/BoxGeometry.js
  21903. /**
  21904. * @author mrdoob / http://mrdoob.com/
  21905. * based on http://papervision3d.googlecode.com/svn/trunk/as3/trunk/src/org/papervision3d/objects/primitives/Cube.as
  21906. */
  21907. THREE.BoxGeometry = function ( width, height, depth, widthSegments, heightSegments, depthSegments ) {
  21908. THREE.Geometry.call( this );
  21909. this.type = 'BoxGeometry';
  21910. this.parameters = {
  21911. width: width,
  21912. height: height,
  21913. depth: depth,
  21914. widthSegments: widthSegments,
  21915. heightSegments: heightSegments,
  21916. depthSegments: depthSegments
  21917. };
  21918. this.fromBufferGeometry( new THREE.BoxBufferGeometry( width, height, depth, widthSegments, heightSegments, depthSegments ) );
  21919. this.mergeVertices();
  21920. };
  21921. THREE.BoxGeometry.prototype = Object.create( THREE.Geometry.prototype );
  21922. THREE.BoxGeometry.prototype.constructor = THREE.BoxGeometry;
  21923. THREE.CubeGeometry = THREE.BoxGeometry;
  21924. // File:src/extras/geometries/BoxBufferGeometry.js
  21925. /**
  21926. * @author Mugen87 / https://github.com/Mugen87
  21927. */
  21928. THREE.BoxBufferGeometry = function ( width, height, depth, widthSegments, heightSegments, depthSegments ) {
  21929. THREE.BufferGeometry.call( this );
  21930. this.type = 'BoxBufferGeometry';
  21931. this.parameters = {
  21932. width: width,
  21933. height: height,
  21934. depth: depth,
  21935. widthSegments: widthSegments,
  21936. heightSegments: heightSegments,
  21937. depthSegments: depthSegments
  21938. };
  21939. var scope = this;
  21940. // segments
  21941. widthSegments = Math.floor( widthSegments ) || 1;
  21942. heightSegments = Math.floor( heightSegments ) || 1;
  21943. depthSegments = Math.floor( depthSegments ) || 1;
  21944. // these are used to calculate buffer length
  21945. var vertexCount = calculateVertexCount( widthSegments, heightSegments, depthSegments );
  21946. var indexCount = calculateIndexCount( widthSegments, heightSegments, depthSegments );
  21947. // buffers
  21948. var indices = new ( indexCount > 65535 ? Uint32Array : Uint16Array )( indexCount );
  21949. var vertices = new Float32Array( vertexCount * 3 );
  21950. var normals = new Float32Array( vertexCount * 3 );
  21951. var uvs = new Float32Array( vertexCount * 2 );
  21952. // offset variables
  21953. var vertexBufferOffset = 0;
  21954. var uvBufferOffset = 0;
  21955. var indexBufferOffset = 0;
  21956. var numberOfVertices = 0;
  21957. // group variables
  21958. var groupStart = 0;
  21959. // build each side of the box geometry
  21960. buildPlane( 'z', 'y', 'x', - 1, - 1, depth, height, width, depthSegments, heightSegments, 0 ); // px
  21961. buildPlane( 'z', 'y', 'x', 1, - 1, depth, height, - width, depthSegments, heightSegments, 1 ); // nx
  21962. buildPlane( 'x', 'z', 'y', 1, 1, width, depth, height, widthSegments, depthSegments, 2 ); // py
  21963. buildPlane( 'x', 'z', 'y', 1, - 1, width, depth, - height, widthSegments, depthSegments, 3 ); // ny
  21964. buildPlane( 'x', 'y', 'z', 1, - 1, width, height, depth, widthSegments, heightSegments, 4 ); // pz
  21965. buildPlane( 'x', 'y', 'z', - 1, - 1, width, height, - depth, widthSegments, heightSegments, 5 ); // nz
  21966. // build geometry
  21967. this.setIndex( new THREE.BufferAttribute( indices, 1 ) );
  21968. this.addAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) );
  21969. this.addAttribute( 'normal', new THREE.BufferAttribute( normals, 3 ) );
  21970. this.addAttribute( 'uv', new THREE.BufferAttribute( uvs, 2 ) );
  21971. // helper functions
  21972. function calculateVertexCount ( w, h, d ) {
  21973. var vertices = 0;
  21974. // calculate the amount of vertices for each side (plane)
  21975. vertices += (w + 1) * (h + 1) * 2; // xy
  21976. vertices += (w + 1) * (d + 1) * 2; // xz
  21977. vertices += (d + 1) * (h + 1) * 2; // zy
  21978. return vertices;
  21979. }
  21980. function calculateIndexCount ( w, h, d ) {
  21981. var index = 0;
  21982. // calculate the amount of squares for each side
  21983. index += w * h * 2; // xy
  21984. index += w * d * 2; // xz
  21985. index += d * h * 2; // zy
  21986. return index * 6; // two triangles per square => six vertices per square
  21987. }
  21988. function buildPlane ( u, v, w, udir, vdir, width, height, depth, gridX, gridY, materialIndex ) {
  21989. var segmentWidth = width / gridX;
  21990. var segmentHeight = height / gridY;
  21991. var widthHalf = width / 2;
  21992. var heightHalf = height / 2;
  21993. var depthHalf = depth / 2;
  21994. var gridX1 = gridX + 1;
  21995. var gridY1 = gridY + 1;
  21996. var vertexCounter = 0;
  21997. var groupCount = 0;
  21998. var vector = new THREE.Vector3();
  21999. // generate vertices, normals and uvs
  22000. for ( var iy = 0; iy < gridY1; iy ++ ) {
  22001. var y = iy * segmentHeight - heightHalf;
  22002. for ( var ix = 0; ix < gridX1; ix ++ ) {
  22003. var x = ix * segmentWidth - widthHalf;
  22004. // set values to correct vector component
  22005. vector[ u ] = x * udir;
  22006. vector[ v ] = y * vdir;
  22007. vector[ w ] = depthHalf;
  22008. // now apply vector to vertex buffer
  22009. vertices[ vertexBufferOffset ] = vector.x;
  22010. vertices[ vertexBufferOffset + 1 ] = vector.y;
  22011. vertices[ vertexBufferOffset + 2 ] = vector.z;
  22012. // set values to correct vector component
  22013. vector[ u ] = 0;
  22014. vector[ v ] = 0;
  22015. vector[ w ] = depth > 0 ? 1 : - 1;
  22016. // now apply vector to normal buffer
  22017. normals[ vertexBufferOffset ] = vector.x;
  22018. normals[ vertexBufferOffset + 1 ] = vector.y;
  22019. normals[ vertexBufferOffset + 2 ] = vector.z;
  22020. // uvs
  22021. uvs[ uvBufferOffset ] = ix / gridX;
  22022. uvs[ uvBufferOffset + 1 ] = 1 - ( iy / gridY );
  22023. // update offsets and counters
  22024. vertexBufferOffset += 3;
  22025. uvBufferOffset += 2;
  22026. vertexCounter += 1;
  22027. }
  22028. }
  22029. // 1. you need three indices to draw a single face
  22030. // 2. a single segment consists of two faces
  22031. // 3. so we need to generate six (2*3) indices per segment
  22032. for ( iy = 0; iy < gridY; iy ++ ) {
  22033. for ( ix = 0; ix < gridX; ix ++ ) {
  22034. // indices
  22035. var a = numberOfVertices + ix + gridX1 * iy;
  22036. var b = numberOfVertices + ix + gridX1 * ( iy + 1 );
  22037. var c = numberOfVertices + ( ix + 1 ) + gridX1 * ( iy + 1 );
  22038. var d = numberOfVertices + ( ix + 1 ) + gridX1 * iy;
  22039. // face one
  22040. indices[ indexBufferOffset ] = a;
  22041. indices[ indexBufferOffset + 1 ] = b;
  22042. indices[ indexBufferOffset + 2 ] = d;
  22043. // face two
  22044. indices[ indexBufferOffset + 3 ] = b;
  22045. indices[ indexBufferOffset + 4 ] = c;
  22046. indices[ indexBufferOffset + 5 ] = d;
  22047. // update offsets and counters
  22048. indexBufferOffset += 6;
  22049. groupCount += 6;
  22050. }
  22051. }
  22052. // add a group to the geometry. this will ensure multi material support
  22053. scope.addGroup( groupStart, groupCount, materialIndex );
  22054. // calculate new start value for groups
  22055. groupStart += groupCount;
  22056. // update total number of vertices
  22057. numberOfVertices += vertexCounter;
  22058. }
  22059. };
  22060. THREE.BoxBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  22061. THREE.BoxBufferGeometry.prototype.constructor = THREE.BoxBufferGeometry;
  22062. // File:src/extras/geometries/CircleGeometry.js
  22063. /**
  22064. * @author hughes
  22065. */
  22066. THREE.CircleGeometry = function ( radius, segments, thetaStart, thetaLength ) {
  22067. THREE.Geometry.call( this );
  22068. this.type = 'CircleGeometry';
  22069. this.parameters = {
  22070. radius: radius,
  22071. segments: segments,
  22072. thetaStart: thetaStart,
  22073. thetaLength: thetaLength
  22074. };
  22075. this.fromBufferGeometry( new THREE.CircleBufferGeometry( radius, segments, thetaStart, thetaLength ) );
  22076. };
  22077. THREE.CircleGeometry.prototype = Object.create( THREE.Geometry.prototype );
  22078. THREE.CircleGeometry.prototype.constructor = THREE.CircleGeometry;
  22079. // File:src/extras/geometries/CircleBufferGeometry.js
  22080. /**
  22081. * @author benaadams / https://twitter.com/ben_a_adams
  22082. */
  22083. THREE.CircleBufferGeometry = function ( radius, segments, thetaStart, thetaLength ) {
  22084. THREE.BufferGeometry.call( this );
  22085. this.type = 'CircleBufferGeometry';
  22086. this.parameters = {
  22087. radius: radius,
  22088. segments: segments,
  22089. thetaStart: thetaStart,
  22090. thetaLength: thetaLength
  22091. };
  22092. radius = radius || 50;
  22093. segments = segments !== undefined ? Math.max( 3, segments ) : 8;
  22094. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  22095. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  22096. var vertices = segments + 2;
  22097. var positions = new Float32Array( vertices * 3 );
  22098. var normals = new Float32Array( vertices * 3 );
  22099. var uvs = new Float32Array( vertices * 2 );
  22100. // center data is already zero, but need to set a few extras
  22101. normals[ 2 ] = 1.0;
  22102. uvs[ 0 ] = 0.5;
  22103. uvs[ 1 ] = 0.5;
  22104. for ( var s = 0, i = 3, ii = 2 ; s <= segments; s ++, i += 3, ii += 2 ) {
  22105. var segment = thetaStart + s / segments * thetaLength;
  22106. positions[ i ] = radius * Math.cos( segment );
  22107. positions[ i + 1 ] = radius * Math.sin( segment );
  22108. normals[ i + 2 ] = 1; // normal z
  22109. uvs[ ii ] = ( positions[ i ] / radius + 1 ) / 2;
  22110. uvs[ ii + 1 ] = ( positions[ i + 1 ] / radius + 1 ) / 2;
  22111. }
  22112. var indices = [];
  22113. for ( var i = 1; i <= segments; i ++ ) {
  22114. indices.push( i, i + 1, 0 );
  22115. }
  22116. this.setIndex( new THREE.BufferAttribute( new Uint16Array( indices ), 1 ) );
  22117. this.addAttribute( 'position', new THREE.BufferAttribute( positions, 3 ) );
  22118. this.addAttribute( 'normal', new THREE.BufferAttribute( normals, 3 ) );
  22119. this.addAttribute( 'uv', new THREE.BufferAttribute( uvs, 2 ) );
  22120. this.boundingSphere = new THREE.Sphere( new THREE.Vector3(), radius );
  22121. };
  22122. THREE.CircleBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  22123. THREE.CircleBufferGeometry.prototype.constructor = THREE.CircleBufferGeometry;
  22124. // File:src/extras/geometries/CylinderBufferGeometry.js
  22125. /**
  22126. * @author Mugen87 / https://github.com/Mugen87
  22127. */
  22128. THREE.CylinderBufferGeometry = function( radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  22129. THREE.BufferGeometry.call( this );
  22130. this.type = 'CylinderBufferGeometry';
  22131. this.parameters = {
  22132. radiusTop: radiusTop,
  22133. radiusBottom: radiusBottom,
  22134. height: height,
  22135. radialSegments: radialSegments,
  22136. heightSegments: heightSegments,
  22137. openEnded: openEnded,
  22138. thetaStart: thetaStart,
  22139. thetaLength: thetaLength
  22140. };
  22141. var scope = this;
  22142. radiusTop = radiusTop !== undefined ? radiusTop : 20;
  22143. radiusBottom = radiusBottom !== undefined ? radiusBottom : 20;
  22144. height = height !== undefined ? height : 100;
  22145. radialSegments = Math.floor( radialSegments ) || 8;
  22146. heightSegments = Math.floor( heightSegments ) || 1;
  22147. openEnded = openEnded !== undefined ? openEnded : false;
  22148. thetaStart = thetaStart !== undefined ? thetaStart : 0.0;
  22149. thetaLength = thetaLength !== undefined ? thetaLength : 2.0 * Math.PI;
  22150. // used to calculate buffer length
  22151. var nbCap = 0;
  22152. if ( openEnded === false ) {
  22153. if ( radiusTop > 0 ) nbCap ++;
  22154. if ( radiusBottom > 0 ) nbCap ++;
  22155. }
  22156. var vertexCount = calculateVertexCount();
  22157. var indexCount = calculateIndexCount();
  22158. // buffers
  22159. var indices = new THREE.BufferAttribute( new ( indexCount > 65535 ? Uint32Array : Uint16Array )( indexCount ), 1 );
  22160. var vertices = new THREE.BufferAttribute( new Float32Array( vertexCount * 3 ), 3 );
  22161. var normals = new THREE.BufferAttribute( new Float32Array( vertexCount * 3 ), 3 );
  22162. var uvs = new THREE.BufferAttribute( new Float32Array( vertexCount * 2 ), 2 );
  22163. // helper variables
  22164. var index = 0,
  22165. indexOffset = 0,
  22166. indexArray = [],
  22167. halfHeight = height / 2;
  22168. // group variables
  22169. var groupStart = 0;
  22170. // generate geometry
  22171. generateTorso();
  22172. if ( openEnded === false ) {
  22173. if ( radiusTop > 0 ) generateCap( true );
  22174. if ( radiusBottom > 0 ) generateCap( false );
  22175. }
  22176. // build geometry
  22177. this.setIndex( indices );
  22178. this.addAttribute( 'position', vertices );
  22179. this.addAttribute( 'normal', normals );
  22180. this.addAttribute( 'uv', uvs );
  22181. // helper functions
  22182. function calculateVertexCount() {
  22183. var count = ( radialSegments + 1 ) * ( heightSegments + 1 );
  22184. if ( openEnded === false ) {
  22185. count += ( ( radialSegments + 1 ) * nbCap ) + ( radialSegments * nbCap );
  22186. }
  22187. return count;
  22188. }
  22189. function calculateIndexCount() {
  22190. var count = radialSegments * heightSegments * 2 * 3;
  22191. if ( openEnded === false ) {
  22192. count += radialSegments * nbCap * 3;
  22193. }
  22194. return count;
  22195. }
  22196. function generateTorso() {
  22197. var x, y;
  22198. var normal = new THREE.Vector3();
  22199. var vertex = new THREE.Vector3();
  22200. var groupCount = 0;
  22201. // this will be used to calculate the normal
  22202. var tanTheta = ( radiusBottom - radiusTop ) / height;
  22203. // generate vertices, normals and uvs
  22204. for ( y = 0; y <= heightSegments; y ++ ) {
  22205. var indexRow = [];
  22206. var v = y / heightSegments;
  22207. // calculate the radius of the current row
  22208. var radius = v * ( radiusBottom - radiusTop ) + radiusTop;
  22209. for ( x = 0; x <= radialSegments; x ++ ) {
  22210. var u = x / radialSegments;
  22211. // vertex
  22212. vertex.x = radius * Math.sin( u * thetaLength + thetaStart );
  22213. vertex.y = - v * height + halfHeight;
  22214. vertex.z = radius * Math.cos( u * thetaLength + thetaStart );
  22215. vertices.setXYZ( index, vertex.x, vertex.y, vertex.z );
  22216. // normal
  22217. normal.copy( vertex );
  22218. // handle special case if radiusTop/radiusBottom is zero
  22219. if ( ( radiusTop === 0 && y === 0 ) || ( radiusBottom === 0 && y === heightSegments ) ) {
  22220. normal.x = Math.sin( u * thetaLength + thetaStart );
  22221. normal.z = Math.cos( u * thetaLength + thetaStart );
  22222. }
  22223. normal.setY( Math.sqrt( normal.x * normal.x + normal.z * normal.z ) * tanTheta ).normalize();
  22224. normals.setXYZ( index, normal.x, normal.y, normal.z );
  22225. // uv
  22226. uvs.setXY( index, u, 1 - v );
  22227. // save index of vertex in respective row
  22228. indexRow.push( index );
  22229. // increase index
  22230. index ++;
  22231. }
  22232. // now save vertices of the row in our index array
  22233. indexArray.push( indexRow );
  22234. }
  22235. // generate indices
  22236. for ( x = 0; x < radialSegments; x ++ ) {
  22237. for ( y = 0; y < heightSegments; y ++ ) {
  22238. // we use the index array to access the correct indices
  22239. var i1 = indexArray[ y ][ x ];
  22240. var i2 = indexArray[ y + 1 ][ x ];
  22241. var i3 = indexArray[ y + 1 ][ x + 1 ];
  22242. var i4 = indexArray[ y ][ x + 1 ];
  22243. // face one
  22244. indices.setX( indexOffset, i1 ); indexOffset ++;
  22245. indices.setX( indexOffset, i2 ); indexOffset ++;
  22246. indices.setX( indexOffset, i4 ); indexOffset ++;
  22247. // face two
  22248. indices.setX( indexOffset, i2 ); indexOffset ++;
  22249. indices.setX( indexOffset, i3 ); indexOffset ++;
  22250. indices.setX( indexOffset, i4 ); indexOffset ++;
  22251. // update counters
  22252. groupCount += 6;
  22253. }
  22254. }
  22255. // add a group to the geometry. this will ensure multi material support
  22256. scope.addGroup( groupStart, groupCount, 0 );
  22257. // calculate new start value for groups
  22258. groupStart += groupCount;
  22259. }
  22260. function generateCap( top ) {
  22261. var x, centerIndexStart, centerIndexEnd;
  22262. var uv = new THREE.Vector2();
  22263. var vertex = new THREE.Vector3();
  22264. var groupCount = 0;
  22265. var radius = ( top === true ) ? radiusTop : radiusBottom;
  22266. var sign = ( top === true ) ? 1 : - 1;
  22267. // save the index of the first center vertex
  22268. centerIndexStart = index;
  22269. // first we generate the center vertex data of the cap.
  22270. // because the geometry needs one set of uvs per face,
  22271. // we must generate a center vertex per face/segment
  22272. for ( x = 1; x <= radialSegments; x ++ ) {
  22273. // vertex
  22274. vertices.setXYZ( index, 0, halfHeight * sign, 0 );
  22275. // normal
  22276. normals.setXYZ( index, 0, sign, 0 );
  22277. // uv
  22278. uv.x = 0.5;
  22279. uv.y = 0.5;
  22280. uvs.setXY( index, uv.x, uv.y );
  22281. // increase index
  22282. index ++;
  22283. }
  22284. // save the index of the last center vertex
  22285. centerIndexEnd = index;
  22286. // now we generate the surrounding vertices, normals and uvs
  22287. for ( x = 0; x <= radialSegments; x ++ ) {
  22288. var u = x / radialSegments;
  22289. var theta = u * thetaLength + thetaStart;
  22290. var cosTheta = Math.cos( theta );
  22291. var sinTheta = Math.sin( theta );
  22292. // vertex
  22293. vertex.x = radius * sinTheta;
  22294. vertex.y = halfHeight * sign;
  22295. vertex.z = radius * cosTheta;
  22296. vertices.setXYZ( index, vertex.x, vertex.y, vertex.z );
  22297. // normal
  22298. normals.setXYZ( index, 0, sign, 0 );
  22299. // uv
  22300. uv.x = ( cosTheta * 0.5 ) + 0.5;
  22301. uv.y = ( sinTheta * 0.5 * sign ) + 0.5;
  22302. uvs.setXY( index, uv.x, uv.y );
  22303. // increase index
  22304. index ++;
  22305. }
  22306. // generate indices
  22307. for ( x = 0; x < radialSegments; x ++ ) {
  22308. var c = centerIndexStart + x;
  22309. var i = centerIndexEnd + x;
  22310. if ( top === true ) {
  22311. // face top
  22312. indices.setX( indexOffset, i ); indexOffset ++;
  22313. indices.setX( indexOffset, i + 1 ); indexOffset ++;
  22314. indices.setX( indexOffset, c ); indexOffset ++;
  22315. } else {
  22316. // face bottom
  22317. indices.setX( indexOffset, i + 1 ); indexOffset ++;
  22318. indices.setX( indexOffset, i ); indexOffset ++;
  22319. indices.setX( indexOffset, c ); indexOffset ++;
  22320. }
  22321. // update counters
  22322. groupCount += 3;
  22323. }
  22324. // add a group to the geometry. this will ensure multi material support
  22325. scope.addGroup( groupStart, groupCount, top === true ? 1 : 2 );
  22326. // calculate new start value for groups
  22327. groupStart += groupCount;
  22328. }
  22329. };
  22330. THREE.CylinderBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  22331. THREE.CylinderBufferGeometry.prototype.constructor = THREE.CylinderBufferGeometry;
  22332. // File:src/extras/geometries/CylinderGeometry.js
  22333. /**
  22334. * @author mrdoob / http://mrdoob.com/
  22335. */
  22336. THREE.CylinderGeometry = function ( radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  22337. THREE.Geometry.call( this );
  22338. this.type = 'CylinderGeometry';
  22339. this.parameters = {
  22340. radiusTop: radiusTop,
  22341. radiusBottom: radiusBottom,
  22342. height: height,
  22343. radialSegments: radialSegments,
  22344. heightSegments: heightSegments,
  22345. openEnded: openEnded,
  22346. thetaStart: thetaStart,
  22347. thetaLength: thetaLength
  22348. };
  22349. this.fromBufferGeometry( new THREE.CylinderBufferGeometry( radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) );
  22350. this.mergeVertices();
  22351. };
  22352. THREE.CylinderGeometry.prototype = Object.create( THREE.Geometry.prototype );
  22353. THREE.CylinderGeometry.prototype.constructor = THREE.CylinderGeometry;
  22354. // File:src/extras/geometries/ConeBufferGeometry.js
  22355. /*
  22356. * @author: abelnation / http://github.com/abelnation
  22357. */
  22358. THREE.ConeBufferGeometry = function (
  22359. radius, height,
  22360. radialSegments, heightSegments,
  22361. openEnded, thetaStart, thetaLength ) {
  22362. THREE.CylinderBufferGeometry.call( this,
  22363. 0, radius, height,
  22364. radialSegments, heightSegments,
  22365. openEnded, thetaStart, thetaLength );
  22366. this.type = 'ConeBufferGeometry';
  22367. this.parameters = {
  22368. radius: radius,
  22369. height: height,
  22370. radialSegments: radialSegments,
  22371. heightSegments: heightSegments,
  22372. thetaStart: thetaStart,
  22373. thetaLength: thetaLength
  22374. };
  22375. };
  22376. THREE.ConeBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  22377. THREE.ConeBufferGeometry.prototype.constructor = THREE.ConeBufferGeometry;
  22378. // File:src/extras/geometries/ConeGeometry.js
  22379. /**
  22380. * @author abelnation / http://github.com/abelnation
  22381. */
  22382. THREE.ConeGeometry = function (
  22383. radius, height,
  22384. radialSegments, heightSegments,
  22385. openEnded, thetaStart, thetaLength ) {
  22386. THREE.CylinderGeometry.call( this,
  22387. 0, radius, height,
  22388. radialSegments, heightSegments,
  22389. openEnded, thetaStart, thetaLength );
  22390. this.type = 'ConeGeometry';
  22391. this.parameters = {
  22392. radius: radius,
  22393. height: height,
  22394. radialSegments: radialSegments,
  22395. heightSegments: heightSegments,
  22396. openEnded: openEnded,
  22397. thetaStart: thetaStart,
  22398. thetaLength: thetaLength
  22399. };
  22400. };
  22401. THREE.ConeGeometry.prototype = Object.create( THREE.CylinderGeometry.prototype );
  22402. THREE.ConeGeometry.prototype.constructor = THREE.ConeGeometry;
  22403. // File:src/extras/geometries/EdgesGeometry.js
  22404. /**
  22405. * @author WestLangley / http://github.com/WestLangley
  22406. */
  22407. THREE.EdgesGeometry = function ( geometry, thresholdAngle ) {
  22408. THREE.BufferGeometry.call( this );
  22409. thresholdAngle = ( thresholdAngle !== undefined ) ? thresholdAngle : 1;
  22410. var thresholdDot = Math.cos( THREE.Math.DEG2RAD * thresholdAngle );
  22411. var edge = [ 0, 0 ], hash = {};
  22412. function sortFunction( a, b ) {
  22413. return a - b;
  22414. }
  22415. var keys = [ 'a', 'b', 'c' ];
  22416. var geometry2;
  22417. if ( geometry instanceof THREE.BufferGeometry ) {
  22418. geometry2 = new THREE.Geometry();
  22419. geometry2.fromBufferGeometry( geometry );
  22420. } else {
  22421. geometry2 = geometry.clone();
  22422. }
  22423. geometry2.mergeVertices();
  22424. geometry2.computeFaceNormals();
  22425. var vertices = geometry2.vertices;
  22426. var faces = geometry2.faces;
  22427. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  22428. var face = faces[ i ];
  22429. for ( var j = 0; j < 3; j ++ ) {
  22430. edge[ 0 ] = face[ keys[ j ] ];
  22431. edge[ 1 ] = face[ keys[ ( j + 1 ) % 3 ] ];
  22432. edge.sort( sortFunction );
  22433. var key = edge.toString();
  22434. if ( hash[ key ] === undefined ) {
  22435. hash[ key ] = { vert1: edge[ 0 ], vert2: edge[ 1 ], face1: i, face2: undefined };
  22436. } else {
  22437. hash[ key ].face2 = i;
  22438. }
  22439. }
  22440. }
  22441. var coords = [];
  22442. for ( var key in hash ) {
  22443. var h = hash[ key ];
  22444. if ( h.face2 === undefined || faces[ h.face1 ].normal.dot( faces[ h.face2 ].normal ) <= thresholdDot ) {
  22445. var vertex = vertices[ h.vert1 ];
  22446. coords.push( vertex.x );
  22447. coords.push( vertex.y );
  22448. coords.push( vertex.z );
  22449. vertex = vertices[ h.vert2 ];
  22450. coords.push( vertex.x );
  22451. coords.push( vertex.y );
  22452. coords.push( vertex.z );
  22453. }
  22454. }
  22455. this.addAttribute( 'position', new THREE.BufferAttribute( new Float32Array( coords ), 3 ) );
  22456. };
  22457. THREE.EdgesGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  22458. THREE.EdgesGeometry.prototype.constructor = THREE.EdgesGeometry;
  22459. // File:src/extras/geometries/ExtrudeGeometry.js
  22460. /**
  22461. * @author zz85 / http://www.lab4games.net/zz85/blog
  22462. *
  22463. * Creates extruded geometry from a path shape.
  22464. *
  22465. * parameters = {
  22466. *
  22467. * curveSegments: <int>, // number of points on the curves
  22468. * steps: <int>, // number of points for z-side extrusions / used for subdividing segments of extrude spline too
  22469. * amount: <int>, // Depth to extrude the shape
  22470. *
  22471. * bevelEnabled: <bool>, // turn on bevel
  22472. * bevelThickness: <float>, // how deep into the original shape bevel goes
  22473. * bevelSize: <float>, // how far from shape outline is bevel
  22474. * bevelSegments: <int>, // number of bevel layers
  22475. *
  22476. * extrudePath: <THREE.CurvePath> // 3d spline path to extrude shape along. (creates Frames if .frames aren't defined)
  22477. * frames: <THREE.TubeGeometry.FrenetFrames> // containing arrays of tangents, normals, binormals
  22478. *
  22479. * uvGenerator: <Object> // object that provides UV generator functions
  22480. *
  22481. * }
  22482. **/
  22483. THREE.ExtrudeGeometry = function ( shapes, options ) {
  22484. if ( typeof( shapes ) === "undefined" ) {
  22485. shapes = [];
  22486. return;
  22487. }
  22488. THREE.Geometry.call( this );
  22489. this.type = 'ExtrudeGeometry';
  22490. shapes = Array.isArray( shapes ) ? shapes : [ shapes ];
  22491. this.addShapeList( shapes, options );
  22492. this.computeFaceNormals();
  22493. // can't really use automatic vertex normals
  22494. // as then front and back sides get smoothed too
  22495. // should do separate smoothing just for sides
  22496. //this.computeVertexNormals();
  22497. //console.log( "took", ( Date.now() - startTime ) );
  22498. };
  22499. THREE.ExtrudeGeometry.prototype = Object.create( THREE.Geometry.prototype );
  22500. THREE.ExtrudeGeometry.prototype.constructor = THREE.ExtrudeGeometry;
  22501. THREE.ExtrudeGeometry.prototype.addShapeList = function ( shapes, options ) {
  22502. var sl = shapes.length;
  22503. for ( var s = 0; s < sl; s ++ ) {
  22504. var shape = shapes[ s ];
  22505. this.addShape( shape, options );
  22506. }
  22507. };
  22508. THREE.ExtrudeGeometry.prototype.addShape = function ( shape, options ) {
  22509. var amount = options.amount !== undefined ? options.amount : 100;
  22510. var bevelThickness = options.bevelThickness !== undefined ? options.bevelThickness : 6; // 10
  22511. var bevelSize = options.bevelSize !== undefined ? options.bevelSize : bevelThickness - 2; // 8
  22512. var bevelSegments = options.bevelSegments !== undefined ? options.bevelSegments : 3;
  22513. var bevelEnabled = options.bevelEnabled !== undefined ? options.bevelEnabled : true; // false
  22514. var curveSegments = options.curveSegments !== undefined ? options.curveSegments : 12;
  22515. var steps = options.steps !== undefined ? options.steps : 1;
  22516. var extrudePath = options.extrudePath;
  22517. var extrudePts, extrudeByPath = false;
  22518. // Use default WorldUVGenerator if no UV generators are specified.
  22519. var uvgen = options.UVGenerator !== undefined ? options.UVGenerator : THREE.ExtrudeGeometry.WorldUVGenerator;
  22520. var splineTube, binormal, normal, position2;
  22521. if ( extrudePath ) {
  22522. extrudePts = extrudePath.getSpacedPoints( steps );
  22523. extrudeByPath = true;
  22524. bevelEnabled = false; // bevels not supported for path extrusion
  22525. // SETUP TNB variables
  22526. // Reuse TNB from TubeGeomtry for now.
  22527. // TODO1 - have a .isClosed in spline?
  22528. splineTube = options.frames !== undefined ? options.frames : new THREE.TubeGeometry.FrenetFrames( extrudePath, steps, false );
  22529. // console.log(splineTube, 'splineTube', splineTube.normals.length, 'steps', steps, 'extrudePts', extrudePts.length);
  22530. binormal = new THREE.Vector3();
  22531. normal = new THREE.Vector3();
  22532. position2 = new THREE.Vector3();
  22533. }
  22534. // Safeguards if bevels are not enabled
  22535. if ( ! bevelEnabled ) {
  22536. bevelSegments = 0;
  22537. bevelThickness = 0;
  22538. bevelSize = 0;
  22539. }
  22540. // Variables initialization
  22541. var ahole, h, hl; // looping of holes
  22542. var scope = this;
  22543. var shapesOffset = this.vertices.length;
  22544. var shapePoints = shape.extractPoints( curveSegments );
  22545. var vertices = shapePoints.shape;
  22546. var holes = shapePoints.holes;
  22547. var reverse = ! THREE.ShapeUtils.isClockWise( vertices );
  22548. if ( reverse ) {
  22549. vertices = vertices.reverse();
  22550. // Maybe we should also check if holes are in the opposite direction, just to be safe ...
  22551. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  22552. ahole = holes[ h ];
  22553. if ( THREE.ShapeUtils.isClockWise( ahole ) ) {
  22554. holes[ h ] = ahole.reverse();
  22555. }
  22556. }
  22557. reverse = false; // If vertices are in order now, we shouldn't need to worry about them again (hopefully)!
  22558. }
  22559. var faces = THREE.ShapeUtils.triangulateShape( vertices, holes );
  22560. /* Vertices */
  22561. var contour = vertices; // vertices has all points but contour has only points of circumference
  22562. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  22563. ahole = holes[ h ];
  22564. vertices = vertices.concat( ahole );
  22565. }
  22566. function scalePt2 ( pt, vec, size ) {
  22567. if ( ! vec ) console.error( "THREE.ExtrudeGeometry: vec does not exist" );
  22568. return vec.clone().multiplyScalar( size ).add( pt );
  22569. }
  22570. var b, bs, t, z,
  22571. vert, vlen = vertices.length,
  22572. face, flen = faces.length;
  22573. // Find directions for point movement
  22574. function getBevelVec( inPt, inPrev, inNext ) {
  22575. // computes for inPt the corresponding point inPt' on a new contour
  22576. // shifted by 1 unit (length of normalized vector) to the left
  22577. // if we walk along contour clockwise, this new contour is outside the old one
  22578. //
  22579. // inPt' is the intersection of the two lines parallel to the two
  22580. // adjacent edges of inPt at a distance of 1 unit on the left side.
  22581. var v_trans_x, v_trans_y, shrink_by = 1; // resulting translation vector for inPt
  22582. // good reading for geometry algorithms (here: line-line intersection)
  22583. // http://geomalgorithms.com/a05-_intersect-1.html
  22584. var v_prev_x = inPt.x - inPrev.x, v_prev_y = inPt.y - inPrev.y;
  22585. var v_next_x = inNext.x - inPt.x, v_next_y = inNext.y - inPt.y;
  22586. var v_prev_lensq = ( v_prev_x * v_prev_x + v_prev_y * v_prev_y );
  22587. // check for collinear edges
  22588. var collinear0 = ( v_prev_x * v_next_y - v_prev_y * v_next_x );
  22589. if ( Math.abs( collinear0 ) > Number.EPSILON ) {
  22590. // not collinear
  22591. // length of vectors for normalizing
  22592. var v_prev_len = Math.sqrt( v_prev_lensq );
  22593. var v_next_len = Math.sqrt( v_next_x * v_next_x + v_next_y * v_next_y );
  22594. // shift adjacent points by unit vectors to the left
  22595. var ptPrevShift_x = ( inPrev.x - v_prev_y / v_prev_len );
  22596. var ptPrevShift_y = ( inPrev.y + v_prev_x / v_prev_len );
  22597. var ptNextShift_x = ( inNext.x - v_next_y / v_next_len );
  22598. var ptNextShift_y = ( inNext.y + v_next_x / v_next_len );
  22599. // scaling factor for v_prev to intersection point
  22600. var sf = ( ( ptNextShift_x - ptPrevShift_x ) * v_next_y -
  22601. ( ptNextShift_y - ptPrevShift_y ) * v_next_x ) /
  22602. ( v_prev_x * v_next_y - v_prev_y * v_next_x );
  22603. // vector from inPt to intersection point
  22604. v_trans_x = ( ptPrevShift_x + v_prev_x * sf - inPt.x );
  22605. v_trans_y = ( ptPrevShift_y + v_prev_y * sf - inPt.y );
  22606. // Don't normalize!, otherwise sharp corners become ugly
  22607. // but prevent crazy spikes
  22608. var v_trans_lensq = ( v_trans_x * v_trans_x + v_trans_y * v_trans_y );
  22609. if ( v_trans_lensq <= 2 ) {
  22610. return new THREE.Vector2( v_trans_x, v_trans_y );
  22611. } else {
  22612. shrink_by = Math.sqrt( v_trans_lensq / 2 );
  22613. }
  22614. } else {
  22615. // handle special case of collinear edges
  22616. var direction_eq = false; // assumes: opposite
  22617. if ( v_prev_x > Number.EPSILON ) {
  22618. if ( v_next_x > Number.EPSILON ) {
  22619. direction_eq = true;
  22620. }
  22621. } else {
  22622. if ( v_prev_x < - Number.EPSILON ) {
  22623. if ( v_next_x < - Number.EPSILON ) {
  22624. direction_eq = true;
  22625. }
  22626. } else {
  22627. if ( Math.sign( v_prev_y ) === Math.sign( v_next_y ) ) {
  22628. direction_eq = true;
  22629. }
  22630. }
  22631. }
  22632. if ( direction_eq ) {
  22633. // console.log("Warning: lines are a straight sequence");
  22634. v_trans_x = - v_prev_y;
  22635. v_trans_y = v_prev_x;
  22636. shrink_by = Math.sqrt( v_prev_lensq );
  22637. } else {
  22638. // console.log("Warning: lines are a straight spike");
  22639. v_trans_x = v_prev_x;
  22640. v_trans_y = v_prev_y;
  22641. shrink_by = Math.sqrt( v_prev_lensq / 2 );
  22642. }
  22643. }
  22644. return new THREE.Vector2( v_trans_x / shrink_by, v_trans_y / shrink_by );
  22645. }
  22646. var contourMovements = [];
  22647. for ( var i = 0, il = contour.length, j = il - 1, k = i + 1; i < il; i ++, j ++, k ++ ) {
  22648. if ( j === il ) j = 0;
  22649. if ( k === il ) k = 0;
  22650. // (j)---(i)---(k)
  22651. // console.log('i,j,k', i, j , k)
  22652. contourMovements[ i ] = getBevelVec( contour[ i ], contour[ j ], contour[ k ] );
  22653. }
  22654. var holesMovements = [], oneHoleMovements, verticesMovements = contourMovements.concat();
  22655. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  22656. ahole = holes[ h ];
  22657. oneHoleMovements = [];
  22658. for ( i = 0, il = ahole.length, j = il - 1, k = i + 1; i < il; i ++, j ++, k ++ ) {
  22659. if ( j === il ) j = 0;
  22660. if ( k === il ) k = 0;
  22661. // (j)---(i)---(k)
  22662. oneHoleMovements[ i ] = getBevelVec( ahole[ i ], ahole[ j ], ahole[ k ] );
  22663. }
  22664. holesMovements.push( oneHoleMovements );
  22665. verticesMovements = verticesMovements.concat( oneHoleMovements );
  22666. }
  22667. // Loop bevelSegments, 1 for the front, 1 for the back
  22668. for ( b = 0; b < bevelSegments; b ++ ) {
  22669. //for ( b = bevelSegments; b > 0; b -- ) {
  22670. t = b / bevelSegments;
  22671. z = bevelThickness * ( 1 - t );
  22672. //z = bevelThickness * t;
  22673. bs = bevelSize * ( Math.sin ( t * Math.PI / 2 ) ); // curved
  22674. //bs = bevelSize * t; // linear
  22675. // contract shape
  22676. for ( i = 0, il = contour.length; i < il; i ++ ) {
  22677. vert = scalePt2( contour[ i ], contourMovements[ i ], bs );
  22678. v( vert.x, vert.y, - z );
  22679. }
  22680. // expand holes
  22681. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  22682. ahole = holes[ h ];
  22683. oneHoleMovements = holesMovements[ h ];
  22684. for ( i = 0, il = ahole.length; i < il; i ++ ) {
  22685. vert = scalePt2( ahole[ i ], oneHoleMovements[ i ], bs );
  22686. v( vert.x, vert.y, - z );
  22687. }
  22688. }
  22689. }
  22690. bs = bevelSize;
  22691. // Back facing vertices
  22692. for ( i = 0; i < vlen; i ++ ) {
  22693. vert = bevelEnabled ? scalePt2( vertices[ i ], verticesMovements[ i ], bs ) : vertices[ i ];
  22694. if ( ! extrudeByPath ) {
  22695. v( vert.x, vert.y, 0 );
  22696. } else {
  22697. // v( vert.x, vert.y + extrudePts[ 0 ].y, extrudePts[ 0 ].x );
  22698. normal.copy( splineTube.normals[ 0 ] ).multiplyScalar( vert.x );
  22699. binormal.copy( splineTube.binormals[ 0 ] ).multiplyScalar( vert.y );
  22700. position2.copy( extrudePts[ 0 ] ).add( normal ).add( binormal );
  22701. v( position2.x, position2.y, position2.z );
  22702. }
  22703. }
  22704. // Add stepped vertices...
  22705. // Including front facing vertices
  22706. var s;
  22707. for ( s = 1; s <= steps; s ++ ) {
  22708. for ( i = 0; i < vlen; i ++ ) {
  22709. vert = bevelEnabled ? scalePt2( vertices[ i ], verticesMovements[ i ], bs ) : vertices[ i ];
  22710. if ( ! extrudeByPath ) {
  22711. v( vert.x, vert.y, amount / steps * s );
  22712. } else {
  22713. // v( vert.x, vert.y + extrudePts[ s - 1 ].y, extrudePts[ s - 1 ].x );
  22714. normal.copy( splineTube.normals[ s ] ).multiplyScalar( vert.x );
  22715. binormal.copy( splineTube.binormals[ s ] ).multiplyScalar( vert.y );
  22716. position2.copy( extrudePts[ s ] ).add( normal ).add( binormal );
  22717. v( position2.x, position2.y, position2.z );
  22718. }
  22719. }
  22720. }
  22721. // Add bevel segments planes
  22722. //for ( b = 1; b <= bevelSegments; b ++ ) {
  22723. for ( b = bevelSegments - 1; b >= 0; b -- ) {
  22724. t = b / bevelSegments;
  22725. z = bevelThickness * ( 1 - t );
  22726. //bs = bevelSize * ( 1-Math.sin ( ( 1 - t ) * Math.PI/2 ) );
  22727. bs = bevelSize * Math.sin ( t * Math.PI / 2 );
  22728. // contract shape
  22729. for ( i = 0, il = contour.length; i < il; i ++ ) {
  22730. vert = scalePt2( contour[ i ], contourMovements[ i ], bs );
  22731. v( vert.x, vert.y, amount + z );
  22732. }
  22733. // expand holes
  22734. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  22735. ahole = holes[ h ];
  22736. oneHoleMovements = holesMovements[ h ];
  22737. for ( i = 0, il = ahole.length; i < il; i ++ ) {
  22738. vert = scalePt2( ahole[ i ], oneHoleMovements[ i ], bs );
  22739. if ( ! extrudeByPath ) {
  22740. v( vert.x, vert.y, amount + z );
  22741. } else {
  22742. v( vert.x, vert.y + extrudePts[ steps - 1 ].y, extrudePts[ steps - 1 ].x + z );
  22743. }
  22744. }
  22745. }
  22746. }
  22747. /* Faces */
  22748. // Top and bottom faces
  22749. buildLidFaces();
  22750. // Sides faces
  22751. buildSideFaces();
  22752. ///// Internal functions
  22753. function buildLidFaces() {
  22754. if ( bevelEnabled ) {
  22755. var layer = 0; // steps + 1
  22756. var offset = vlen * layer;
  22757. // Bottom faces
  22758. for ( i = 0; i < flen; i ++ ) {
  22759. face = faces[ i ];
  22760. f3( face[ 2 ] + offset, face[ 1 ] + offset, face[ 0 ] + offset );
  22761. }
  22762. layer = steps + bevelSegments * 2;
  22763. offset = vlen * layer;
  22764. // Top faces
  22765. for ( i = 0; i < flen; i ++ ) {
  22766. face = faces[ i ];
  22767. f3( face[ 0 ] + offset, face[ 1 ] + offset, face[ 2 ] + offset );
  22768. }
  22769. } else {
  22770. // Bottom faces
  22771. for ( i = 0; i < flen; i ++ ) {
  22772. face = faces[ i ];
  22773. f3( face[ 2 ], face[ 1 ], face[ 0 ] );
  22774. }
  22775. // Top faces
  22776. for ( i = 0; i < flen; i ++ ) {
  22777. face = faces[ i ];
  22778. f3( face[ 0 ] + vlen * steps, face[ 1 ] + vlen * steps, face[ 2 ] + vlen * steps );
  22779. }
  22780. }
  22781. }
  22782. // Create faces for the z-sides of the shape
  22783. function buildSideFaces() {
  22784. var layeroffset = 0;
  22785. sidewalls( contour, layeroffset );
  22786. layeroffset += contour.length;
  22787. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  22788. ahole = holes[ h ];
  22789. sidewalls( ahole, layeroffset );
  22790. //, true
  22791. layeroffset += ahole.length;
  22792. }
  22793. }
  22794. function sidewalls( contour, layeroffset ) {
  22795. var j, k;
  22796. i = contour.length;
  22797. while ( -- i >= 0 ) {
  22798. j = i;
  22799. k = i - 1;
  22800. if ( k < 0 ) k = contour.length - 1;
  22801. //console.log('b', i,j, i-1, k,vertices.length);
  22802. var s = 0, sl = steps + bevelSegments * 2;
  22803. for ( s = 0; s < sl; s ++ ) {
  22804. var slen1 = vlen * s;
  22805. var slen2 = vlen * ( s + 1 );
  22806. var a = layeroffset + j + slen1,
  22807. b = layeroffset + k + slen1,
  22808. c = layeroffset + k + slen2,
  22809. d = layeroffset + j + slen2;
  22810. f4( a, b, c, d, contour, s, sl, j, k );
  22811. }
  22812. }
  22813. }
  22814. function v( x, y, z ) {
  22815. scope.vertices.push( new THREE.Vector3( x, y, z ) );
  22816. }
  22817. function f3( a, b, c ) {
  22818. a += shapesOffset;
  22819. b += shapesOffset;
  22820. c += shapesOffset;
  22821. scope.faces.push( new THREE.Face3( a, b, c, null, null, 0 ) );
  22822. var uvs = uvgen.generateTopUV( scope, a, b, c );
  22823. scope.faceVertexUvs[ 0 ].push( uvs );
  22824. }
  22825. function f4( a, b, c, d, wallContour, stepIndex, stepsLength, contourIndex1, contourIndex2 ) {
  22826. a += shapesOffset;
  22827. b += shapesOffset;
  22828. c += shapesOffset;
  22829. d += shapesOffset;
  22830. scope.faces.push( new THREE.Face3( a, b, d, null, null, 1 ) );
  22831. scope.faces.push( new THREE.Face3( b, c, d, null, null, 1 ) );
  22832. var uvs = uvgen.generateSideWallUV( scope, a, b, c, d );
  22833. scope.faceVertexUvs[ 0 ].push( [ uvs[ 0 ], uvs[ 1 ], uvs[ 3 ] ] );
  22834. scope.faceVertexUvs[ 0 ].push( [ uvs[ 1 ], uvs[ 2 ], uvs[ 3 ] ] );
  22835. }
  22836. };
  22837. THREE.ExtrudeGeometry.WorldUVGenerator = {
  22838. generateTopUV: function ( geometry, indexA, indexB, indexC ) {
  22839. var vertices = geometry.vertices;
  22840. var a = vertices[ indexA ];
  22841. var b = vertices[ indexB ];
  22842. var c = vertices[ indexC ];
  22843. return [
  22844. new THREE.Vector2( a.x, a.y ),
  22845. new THREE.Vector2( b.x, b.y ),
  22846. new THREE.Vector2( c.x, c.y )
  22847. ];
  22848. },
  22849. generateSideWallUV: function ( geometry, indexA, indexB, indexC, indexD ) {
  22850. var vertices = geometry.vertices;
  22851. var a = vertices[ indexA ];
  22852. var b = vertices[ indexB ];
  22853. var c = vertices[ indexC ];
  22854. var d = vertices[ indexD ];
  22855. if ( Math.abs( a.y - b.y ) < 0.01 ) {
  22856. return [
  22857. new THREE.Vector2( a.x, 1 - a.z ),
  22858. new THREE.Vector2( b.x, 1 - b.z ),
  22859. new THREE.Vector2( c.x, 1 - c.z ),
  22860. new THREE.Vector2( d.x, 1 - d.z )
  22861. ];
  22862. } else {
  22863. return [
  22864. new THREE.Vector2( a.y, 1 - a.z ),
  22865. new THREE.Vector2( b.y, 1 - b.z ),
  22866. new THREE.Vector2( c.y, 1 - c.z ),
  22867. new THREE.Vector2( d.y, 1 - d.z )
  22868. ];
  22869. }
  22870. }
  22871. };
  22872. // File:src/extras/geometries/ShapeGeometry.js
  22873. /**
  22874. * @author jonobr1 / http://jonobr1.com
  22875. *
  22876. * Creates a one-sided polygonal geometry from a path shape. Similar to
  22877. * ExtrudeGeometry.
  22878. *
  22879. * parameters = {
  22880. *
  22881. * curveSegments: <int>, // number of points on the curves. NOT USED AT THE MOMENT.
  22882. *
  22883. * material: <int> // material index for front and back faces
  22884. * uvGenerator: <Object> // object that provides UV generator functions
  22885. *
  22886. * }
  22887. **/
  22888. THREE.ShapeGeometry = function ( shapes, options ) {
  22889. THREE.Geometry.call( this );
  22890. this.type = 'ShapeGeometry';
  22891. if ( Array.isArray( shapes ) === false ) shapes = [ shapes ];
  22892. this.addShapeList( shapes, options );
  22893. this.computeFaceNormals();
  22894. };
  22895. THREE.ShapeGeometry.prototype = Object.create( THREE.Geometry.prototype );
  22896. THREE.ShapeGeometry.prototype.constructor = THREE.ShapeGeometry;
  22897. /**
  22898. * Add an array of shapes to THREE.ShapeGeometry.
  22899. */
  22900. THREE.ShapeGeometry.prototype.addShapeList = function ( shapes, options ) {
  22901. for ( var i = 0, l = shapes.length; i < l; i ++ ) {
  22902. this.addShape( shapes[ i ], options );
  22903. }
  22904. return this;
  22905. };
  22906. /**
  22907. * Adds a shape to THREE.ShapeGeometry, based on THREE.ExtrudeGeometry.
  22908. */
  22909. THREE.ShapeGeometry.prototype.addShape = function ( shape, options ) {
  22910. if ( options === undefined ) options = {};
  22911. var curveSegments = options.curveSegments !== undefined ? options.curveSegments : 12;
  22912. var material = options.material;
  22913. var uvgen = options.UVGenerator === undefined ? THREE.ExtrudeGeometry.WorldUVGenerator : options.UVGenerator;
  22914. //
  22915. var i, l, hole;
  22916. var shapesOffset = this.vertices.length;
  22917. var shapePoints = shape.extractPoints( curveSegments );
  22918. var vertices = shapePoints.shape;
  22919. var holes = shapePoints.holes;
  22920. var reverse = ! THREE.ShapeUtils.isClockWise( vertices );
  22921. if ( reverse ) {
  22922. vertices = vertices.reverse();
  22923. // Maybe we should also check if holes are in the opposite direction, just to be safe...
  22924. for ( i = 0, l = holes.length; i < l; i ++ ) {
  22925. hole = holes[ i ];
  22926. if ( THREE.ShapeUtils.isClockWise( hole ) ) {
  22927. holes[ i ] = hole.reverse();
  22928. }
  22929. }
  22930. reverse = false;
  22931. }
  22932. var faces = THREE.ShapeUtils.triangulateShape( vertices, holes );
  22933. // Vertices
  22934. for ( i = 0, l = holes.length; i < l; i ++ ) {
  22935. hole = holes[ i ];
  22936. vertices = vertices.concat( hole );
  22937. }
  22938. //
  22939. var vert, vlen = vertices.length;
  22940. var face, flen = faces.length;
  22941. for ( i = 0; i < vlen; i ++ ) {
  22942. vert = vertices[ i ];
  22943. this.vertices.push( new THREE.Vector3( vert.x, vert.y, 0 ) );
  22944. }
  22945. for ( i = 0; i < flen; i ++ ) {
  22946. face = faces[ i ];
  22947. var a = face[ 0 ] + shapesOffset;
  22948. var b = face[ 1 ] + shapesOffset;
  22949. var c = face[ 2 ] + shapesOffset;
  22950. this.faces.push( new THREE.Face3( a, b, c, null, null, material ) );
  22951. this.faceVertexUvs[ 0 ].push( uvgen.generateTopUV( this, a, b, c ) );
  22952. }
  22953. };
  22954. // File:src/extras/geometries/LatheBufferGeometry.js
  22955. /**
  22956. * @author Mugen87 / https://github.com/Mugen87
  22957. */
  22958. // points - to create a closed torus, one must use a set of points
  22959. // like so: [ a, b, c, d, a ], see first is the same as last.
  22960. // segments - the number of circumference segments to create
  22961. // phiStart - the starting radian
  22962. // phiLength - the radian (0 to 2PI) range of the lathed section
  22963. // 2PI is a closed lathe, less than 2PI is a portion.
  22964. THREE.LatheBufferGeometry = function ( points, segments, phiStart, phiLength ) {
  22965. THREE.BufferGeometry.call( this );
  22966. this.type = 'LatheBufferGeometry';
  22967. this.parameters = {
  22968. points: points,
  22969. segments: segments,
  22970. phiStart: phiStart,
  22971. phiLength: phiLength
  22972. };
  22973. segments = Math.floor( segments ) || 12;
  22974. phiStart = phiStart || 0;
  22975. phiLength = phiLength || Math.PI * 2;
  22976. // clamp phiLength so it's in range of [ 0, 2PI ]
  22977. phiLength = THREE.Math.clamp( phiLength, 0, Math.PI * 2 );
  22978. // these are used to calculate buffer length
  22979. var vertexCount = ( segments + 1 ) * points.length;
  22980. var indexCount = segments * points.length * 2 * 3;
  22981. // buffers
  22982. var indices = new THREE.BufferAttribute( new ( indexCount > 65535 ? Uint32Array : Uint16Array )( indexCount ) , 1 );
  22983. var vertices = new THREE.BufferAttribute( new Float32Array( vertexCount * 3 ), 3 );
  22984. var uvs = new THREE.BufferAttribute( new Float32Array( vertexCount * 2 ), 2 );
  22985. // helper variables
  22986. var index = 0, indexOffset = 0, base;
  22987. var inversePointLength = 1.0 / ( points.length - 1 );
  22988. var inverseSegments = 1.0 / segments;
  22989. var vertex = new THREE.Vector3();
  22990. var uv = new THREE.Vector2();
  22991. var i, j;
  22992. // generate vertices and uvs
  22993. for ( i = 0; i <= segments; i ++ ) {
  22994. var phi = phiStart + i * inverseSegments * phiLength;
  22995. var sin = Math.sin( phi );
  22996. var cos = Math.cos( phi );
  22997. for ( j = 0; j <= ( points.length - 1 ); j ++ ) {
  22998. // vertex
  22999. vertex.x = points[ j ].x * sin;
  23000. vertex.y = points[ j ].y;
  23001. vertex.z = points[ j ].x * cos;
  23002. vertices.setXYZ( index, vertex.x, vertex.y, vertex.z );
  23003. // uv
  23004. uv.x = i / segments;
  23005. uv.y = j / ( points.length - 1 );
  23006. uvs.setXY( index, uv.x, uv.y );
  23007. // increase index
  23008. index ++;
  23009. }
  23010. }
  23011. // generate indices
  23012. for ( i = 0; i < segments; i ++ ) {
  23013. for ( j = 0; j < ( points.length - 1 ); j ++ ) {
  23014. base = j + i * points.length;
  23015. // indices
  23016. var a = base;
  23017. var b = base + points.length;
  23018. var c = base + points.length + 1;
  23019. var d = base + 1;
  23020. // face one
  23021. indices.setX( indexOffset, a ); indexOffset++;
  23022. indices.setX( indexOffset, b ); indexOffset++;
  23023. indices.setX( indexOffset, d ); indexOffset++;
  23024. // face two
  23025. indices.setX( indexOffset, b ); indexOffset++;
  23026. indices.setX( indexOffset, c ); indexOffset++;
  23027. indices.setX( indexOffset, d ); indexOffset++;
  23028. }
  23029. }
  23030. // build geometry
  23031. this.setIndex( indices );
  23032. this.addAttribute( 'position', vertices );
  23033. this.addAttribute( 'uv', uvs );
  23034. // generate normals
  23035. this.computeVertexNormals();
  23036. // if the geometry is closed, we need to average the normals along the seam.
  23037. // because the corresponding vertices are identical (but still have different UVs).
  23038. if( phiLength === Math.PI * 2 ) {
  23039. var normals = this.attributes.normal.array;
  23040. var n1 = new THREE.Vector3();
  23041. var n2 = new THREE.Vector3();
  23042. var n = new THREE.Vector3();
  23043. // this is the buffer offset for the last line of vertices
  23044. base = segments * points.length * 3;
  23045. for( i = 0, j = 0; i < points.length; i ++, j += 3 ) {
  23046. // select the normal of the vertex in the first line
  23047. n1.x = normals[ j + 0 ];
  23048. n1.y = normals[ j + 1 ];
  23049. n1.z = normals[ j + 2 ];
  23050. // select the normal of the vertex in the last line
  23051. n2.x = normals[ base + j + 0 ];
  23052. n2.y = normals[ base + j + 1 ];
  23053. n2.z = normals[ base + j + 2 ];
  23054. // average normals
  23055. n.addVectors( n1, n2 ).normalize();
  23056. // assign the new values to both normals
  23057. normals[ j + 0 ] = normals[ base + j + 0 ] = n.x;
  23058. normals[ j + 1 ] = normals[ base + j + 1 ] = n.y;
  23059. normals[ j + 2 ] = normals[ base + j + 2 ] = n.z;
  23060. } // next row
  23061. }
  23062. };
  23063. THREE.LatheBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  23064. THREE.LatheBufferGeometry.prototype.constructor = THREE.LatheBufferGeometry;
  23065. // File:src/extras/geometries/LatheGeometry.js
  23066. /**
  23067. * @author astrodud / http://astrodud.isgreat.org/
  23068. * @author zz85 / https://github.com/zz85
  23069. * @author bhouston / http://clara.io
  23070. */
  23071. // points - to create a closed torus, one must use a set of points
  23072. // like so: [ a, b, c, d, a ], see first is the same as last.
  23073. // segments - the number of circumference segments to create
  23074. // phiStart - the starting radian
  23075. // phiLength - the radian (0 to 2PI) range of the lathed section
  23076. // 2PI is a closed lathe, less than 2PI is a portion.
  23077. THREE.LatheGeometry = function ( points, segments, phiStart, phiLength ) {
  23078. THREE.Geometry.call( this );
  23079. this.type = 'LatheGeometry';
  23080. this.parameters = {
  23081. points: points,
  23082. segments: segments,
  23083. phiStart: phiStart,
  23084. phiLength: phiLength
  23085. };
  23086. this.fromBufferGeometry( new THREE.LatheBufferGeometry( points, segments, phiStart, phiLength ) );
  23087. this.mergeVertices();
  23088. };
  23089. THREE.LatheGeometry.prototype = Object.create( THREE.Geometry.prototype );
  23090. THREE.LatheGeometry.prototype.constructor = THREE.LatheGeometry;
  23091. // File:src/extras/geometries/PlaneGeometry.js
  23092. /**
  23093. * @author mrdoob / http://mrdoob.com/
  23094. * based on http://papervision3d.googlecode.com/svn/trunk/as3/trunk/src/org/papervision3d/objects/primitives/Plane.as
  23095. */
  23096. THREE.PlaneGeometry = function ( width, height, widthSegments, heightSegments ) {
  23097. THREE.Geometry.call( this );
  23098. this.type = 'PlaneGeometry';
  23099. this.parameters = {
  23100. width: width,
  23101. height: height,
  23102. widthSegments: widthSegments,
  23103. heightSegments: heightSegments
  23104. };
  23105. this.fromBufferGeometry( new THREE.PlaneBufferGeometry( width, height, widthSegments, heightSegments ) );
  23106. };
  23107. THREE.PlaneGeometry.prototype = Object.create( THREE.Geometry.prototype );
  23108. THREE.PlaneGeometry.prototype.constructor = THREE.PlaneGeometry;
  23109. // File:src/extras/geometries/PlaneBufferGeometry.js
  23110. /**
  23111. * @author mrdoob / http://mrdoob.com/
  23112. * based on http://papervision3d.googlecode.com/svn/trunk/as3/trunk/src/org/papervision3d/objects/primitives/Plane.as
  23113. */
  23114. THREE.PlaneBufferGeometry = function ( width, height, widthSegments, heightSegments ) {
  23115. THREE.BufferGeometry.call( this );
  23116. this.type = 'PlaneBufferGeometry';
  23117. this.parameters = {
  23118. width: width,
  23119. height: height,
  23120. widthSegments: widthSegments,
  23121. heightSegments: heightSegments
  23122. };
  23123. var width_half = width / 2;
  23124. var height_half = height / 2;
  23125. var gridX = Math.floor( widthSegments ) || 1;
  23126. var gridY = Math.floor( heightSegments ) || 1;
  23127. var gridX1 = gridX + 1;
  23128. var gridY1 = gridY + 1;
  23129. var segment_width = width / gridX;
  23130. var segment_height = height / gridY;
  23131. var vertices = new Float32Array( gridX1 * gridY1 * 3 );
  23132. var normals = new Float32Array( gridX1 * gridY1 * 3 );
  23133. var uvs = new Float32Array( gridX1 * gridY1 * 2 );
  23134. var offset = 0;
  23135. var offset2 = 0;
  23136. for ( var iy = 0; iy < gridY1; iy ++ ) {
  23137. var y = iy * segment_height - height_half;
  23138. for ( var ix = 0; ix < gridX1; ix ++ ) {
  23139. var x = ix * segment_width - width_half;
  23140. vertices[ offset ] = x;
  23141. vertices[ offset + 1 ] = - y;
  23142. normals[ offset + 2 ] = 1;
  23143. uvs[ offset2 ] = ix / gridX;
  23144. uvs[ offset2 + 1 ] = 1 - ( iy / gridY );
  23145. offset += 3;
  23146. offset2 += 2;
  23147. }
  23148. }
  23149. offset = 0;
  23150. var indices = new ( ( vertices.length / 3 ) > 65535 ? Uint32Array : Uint16Array )( gridX * gridY * 6 );
  23151. for ( var iy = 0; iy < gridY; iy ++ ) {
  23152. for ( var ix = 0; ix < gridX; ix ++ ) {
  23153. var a = ix + gridX1 * iy;
  23154. var b = ix + gridX1 * ( iy + 1 );
  23155. var c = ( ix + 1 ) + gridX1 * ( iy + 1 );
  23156. var d = ( ix + 1 ) + gridX1 * iy;
  23157. indices[ offset ] = a;
  23158. indices[ offset + 1 ] = b;
  23159. indices[ offset + 2 ] = d;
  23160. indices[ offset + 3 ] = b;
  23161. indices[ offset + 4 ] = c;
  23162. indices[ offset + 5 ] = d;
  23163. offset += 6;
  23164. }
  23165. }
  23166. this.setIndex( new THREE.BufferAttribute( indices, 1 ) );
  23167. this.addAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) );
  23168. this.addAttribute( 'normal', new THREE.BufferAttribute( normals, 3 ) );
  23169. this.addAttribute( 'uv', new THREE.BufferAttribute( uvs, 2 ) );
  23170. };
  23171. THREE.PlaneBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  23172. THREE.PlaneBufferGeometry.prototype.constructor = THREE.PlaneBufferGeometry;
  23173. // File:src/extras/geometries/RingBufferGeometry.js
  23174. /**
  23175. * @author Mugen87 / https://github.com/Mugen87
  23176. */
  23177. THREE.RingBufferGeometry = function ( innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength ) {
  23178. THREE.BufferGeometry.call( this );
  23179. this.type = 'RingBufferGeometry';
  23180. this.parameters = {
  23181. innerRadius: innerRadius,
  23182. outerRadius: outerRadius,
  23183. thetaSegments: thetaSegments,
  23184. phiSegments: phiSegments,
  23185. thetaStart: thetaStart,
  23186. thetaLength: thetaLength
  23187. };
  23188. innerRadius = innerRadius || 20;
  23189. outerRadius = outerRadius || 50;
  23190. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  23191. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  23192. thetaSegments = thetaSegments !== undefined ? Math.max( 3, thetaSegments ) : 8;
  23193. phiSegments = phiSegments !== undefined ? Math.max( 1, phiSegments ) : 1;
  23194. // these are used to calculate buffer length
  23195. var vertexCount = ( thetaSegments + 1 ) * ( phiSegments + 1 );
  23196. var indexCount = thetaSegments * phiSegments * 2 * 3;
  23197. // buffers
  23198. var indices = new THREE.BufferAttribute( new ( indexCount > 65535 ? Uint32Array : Uint16Array )( indexCount ) , 1 );
  23199. var vertices = new THREE.BufferAttribute( new Float32Array( vertexCount * 3 ), 3 );
  23200. var normals = new THREE.BufferAttribute( new Float32Array( vertexCount * 3 ), 3 );
  23201. var uvs = new THREE.BufferAttribute( new Float32Array( vertexCount * 2 ), 2 );
  23202. // some helper variables
  23203. var index = 0, indexOffset = 0, segment;
  23204. var radius = innerRadius;
  23205. var radiusStep = ( ( outerRadius - innerRadius ) / phiSegments );
  23206. var vertex = new THREE.Vector3();
  23207. var uv = new THREE.Vector2();
  23208. var j, i;
  23209. // generate vertices, normals and uvs
  23210. // values are generate from the inside of the ring to the outside
  23211. for ( j = 0; j <= phiSegments; j ++ ) {
  23212. for ( i = 0; i <= thetaSegments; i ++ ) {
  23213. segment = thetaStart + i / thetaSegments * thetaLength;
  23214. // vertex
  23215. vertex.x = radius * Math.cos( segment );
  23216. vertex.y = radius * Math.sin( segment );
  23217. vertices.setXYZ( index, vertex.x, vertex.y, vertex.z );
  23218. // normal
  23219. normals.setXYZ( index, 0, 0, 1 );
  23220. // uv
  23221. uv.x = ( vertex.x / outerRadius + 1 ) / 2;
  23222. uv.y = ( vertex.y / outerRadius + 1 ) / 2;
  23223. uvs.setXY( index, uv.x, uv.y );
  23224. // increase index
  23225. index++;
  23226. }
  23227. // increase the radius for next row of vertices
  23228. radius += radiusStep;
  23229. }
  23230. // generate indices
  23231. for ( j = 0; j < phiSegments; j ++ ) {
  23232. var thetaSegmentLevel = j * ( thetaSegments + 1 );
  23233. for ( i = 0; i < thetaSegments; i ++ ) {
  23234. segment = i + thetaSegmentLevel;
  23235. // indices
  23236. var a = segment;
  23237. var b = segment + thetaSegments + 1;
  23238. var c = segment + thetaSegments + 2;
  23239. var d = segment + 1;
  23240. // face one
  23241. indices.setX( indexOffset, a ); indexOffset++;
  23242. indices.setX( indexOffset, b ); indexOffset++;
  23243. indices.setX( indexOffset, c ); indexOffset++;
  23244. // face two
  23245. indices.setX( indexOffset, a ); indexOffset++;
  23246. indices.setX( indexOffset, c ); indexOffset++;
  23247. indices.setX( indexOffset, d ); indexOffset++;
  23248. }
  23249. }
  23250. // build geometry
  23251. this.setIndex( indices );
  23252. this.addAttribute( 'position', vertices );
  23253. this.addAttribute( 'normal', normals );
  23254. this.addAttribute( 'uv', uvs );
  23255. };
  23256. THREE.RingBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  23257. THREE.RingBufferGeometry.prototype.constructor = THREE.RingBufferGeometry;
  23258. // File:src/extras/geometries/RingGeometry.js
  23259. /**
  23260. * @author Kaleb Murphy
  23261. */
  23262. THREE.RingGeometry = function ( innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength ) {
  23263. THREE.Geometry.call( this );
  23264. this.type = 'RingGeometry';
  23265. this.parameters = {
  23266. innerRadius: innerRadius,
  23267. outerRadius: outerRadius,
  23268. thetaSegments: thetaSegments,
  23269. phiSegments: phiSegments,
  23270. thetaStart: thetaStart,
  23271. thetaLength: thetaLength
  23272. };
  23273. this.fromBufferGeometry( new THREE.RingBufferGeometry( innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength ) );
  23274. };
  23275. THREE.RingGeometry.prototype = Object.create( THREE.Geometry.prototype );
  23276. THREE.RingGeometry.prototype.constructor = THREE.RingGeometry;
  23277. // File:src/extras/geometries/SphereGeometry.js
  23278. /**
  23279. * @author mrdoob / http://mrdoob.com/
  23280. */
  23281. THREE.SphereGeometry = function ( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) {
  23282. THREE.Geometry.call( this );
  23283. this.type = 'SphereGeometry';
  23284. this.parameters = {
  23285. radius: radius,
  23286. widthSegments: widthSegments,
  23287. heightSegments: heightSegments,
  23288. phiStart: phiStart,
  23289. phiLength: phiLength,
  23290. thetaStart: thetaStart,
  23291. thetaLength: thetaLength
  23292. };
  23293. this.fromBufferGeometry( new THREE.SphereBufferGeometry( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) );
  23294. };
  23295. THREE.SphereGeometry.prototype = Object.create( THREE.Geometry.prototype );
  23296. THREE.SphereGeometry.prototype.constructor = THREE.SphereGeometry;
  23297. // File:src/extras/geometries/SphereBufferGeometry.js
  23298. /**
  23299. * @author benaadams / https://twitter.com/ben_a_adams
  23300. * based on THREE.SphereGeometry
  23301. */
  23302. THREE.SphereBufferGeometry = function ( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) {
  23303. THREE.BufferGeometry.call( this );
  23304. this.type = 'SphereBufferGeometry';
  23305. this.parameters = {
  23306. radius: radius,
  23307. widthSegments: widthSegments,
  23308. heightSegments: heightSegments,
  23309. phiStart: phiStart,
  23310. phiLength: phiLength,
  23311. thetaStart: thetaStart,
  23312. thetaLength: thetaLength
  23313. };
  23314. radius = radius || 50;
  23315. widthSegments = Math.max( 3, Math.floor( widthSegments ) || 8 );
  23316. heightSegments = Math.max( 2, Math.floor( heightSegments ) || 6 );
  23317. phiStart = phiStart !== undefined ? phiStart : 0;
  23318. phiLength = phiLength !== undefined ? phiLength : Math.PI * 2;
  23319. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  23320. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI;
  23321. var thetaEnd = thetaStart + thetaLength;
  23322. var vertexCount = ( ( widthSegments + 1 ) * ( heightSegments + 1 ) );
  23323. var positions = new THREE.BufferAttribute( new Float32Array( vertexCount * 3 ), 3 );
  23324. var normals = new THREE.BufferAttribute( new Float32Array( vertexCount * 3 ), 3 );
  23325. var uvs = new THREE.BufferAttribute( new Float32Array( vertexCount * 2 ), 2 );
  23326. var index = 0, vertices = [], normal = new THREE.Vector3();
  23327. for ( var y = 0; y <= heightSegments; y ++ ) {
  23328. var verticesRow = [];
  23329. var v = y / heightSegments;
  23330. for ( var x = 0; x <= widthSegments; x ++ ) {
  23331. var u = x / widthSegments;
  23332. var px = - radius * Math.cos( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  23333. var py = radius * Math.cos( thetaStart + v * thetaLength );
  23334. var pz = radius * Math.sin( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  23335. normal.set( px, py, pz ).normalize();
  23336. positions.setXYZ( index, px, py, pz );
  23337. normals.setXYZ( index, normal.x, normal.y, normal.z );
  23338. uvs.setXY( index, u, 1 - v );
  23339. verticesRow.push( index );
  23340. index ++;
  23341. }
  23342. vertices.push( verticesRow );
  23343. }
  23344. var indices = [];
  23345. for ( var y = 0; y < heightSegments; y ++ ) {
  23346. for ( var x = 0; x < widthSegments; x ++ ) {
  23347. var v1 = vertices[ y ][ x + 1 ];
  23348. var v2 = vertices[ y ][ x ];
  23349. var v3 = vertices[ y + 1 ][ x ];
  23350. var v4 = vertices[ y + 1 ][ x + 1 ];
  23351. if ( y !== 0 || thetaStart > 0 ) indices.push( v1, v2, v4 );
  23352. if ( y !== heightSegments - 1 || thetaEnd < Math.PI ) indices.push( v2, v3, v4 );
  23353. }
  23354. }
  23355. this.setIndex( new ( positions.count > 65535 ? THREE.Uint32Attribute : THREE.Uint16Attribute )( indices, 1 ) );
  23356. this.addAttribute( 'position', positions );
  23357. this.addAttribute( 'normal', normals );
  23358. this.addAttribute( 'uv', uvs );
  23359. this.boundingSphere = new THREE.Sphere( new THREE.Vector3(), radius );
  23360. };
  23361. THREE.SphereBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  23362. THREE.SphereBufferGeometry.prototype.constructor = THREE.SphereBufferGeometry;
  23363. // File:src/extras/geometries/TextGeometry.js
  23364. /**
  23365. * @author zz85 / http://www.lab4games.net/zz85/blog
  23366. * @author alteredq / http://alteredqualia.com/
  23367. *
  23368. * Text = 3D Text
  23369. *
  23370. * parameters = {
  23371. * font: <THREE.Font>, // font
  23372. *
  23373. * size: <float>, // size of the text
  23374. * height: <float>, // thickness to extrude text
  23375. * curveSegments: <int>, // number of points on the curves
  23376. *
  23377. * bevelEnabled: <bool>, // turn on bevel
  23378. * bevelThickness: <float>, // how deep into text bevel goes
  23379. * bevelSize: <float> // how far from text outline is bevel
  23380. * }
  23381. */
  23382. THREE.TextGeometry = function ( text, parameters ) {
  23383. parameters = parameters || {};
  23384. var font = parameters.font;
  23385. if ( font instanceof THREE.Font === false ) {
  23386. console.error( 'THREE.TextGeometry: font parameter is not an instance of THREE.Font.' );
  23387. return new THREE.Geometry();
  23388. }
  23389. var shapes = font.generateShapes( text, parameters.size, parameters.curveSegments );
  23390. // translate parameters to ExtrudeGeometry API
  23391. parameters.amount = parameters.height !== undefined ? parameters.height : 50;
  23392. // defaults
  23393. if ( parameters.bevelThickness === undefined ) parameters.bevelThickness = 10;
  23394. if ( parameters.bevelSize === undefined ) parameters.bevelSize = 8;
  23395. if ( parameters.bevelEnabled === undefined ) parameters.bevelEnabled = false;
  23396. THREE.ExtrudeGeometry.call( this, shapes, parameters );
  23397. this.type = 'TextGeometry';
  23398. };
  23399. THREE.TextGeometry.prototype = Object.create( THREE.ExtrudeGeometry.prototype );
  23400. THREE.TextGeometry.prototype.constructor = THREE.TextGeometry;
  23401. // File:src/extras/geometries/TorusBufferGeometry.js
  23402. /**
  23403. * @author Mugen87 / https://github.com/Mugen87
  23404. */
  23405. THREE.TorusBufferGeometry = function ( radius, tube, radialSegments, tubularSegments, arc ) {
  23406. THREE.BufferGeometry.call( this );
  23407. this.type = 'TorusBufferGeometry';
  23408. this.parameters = {
  23409. radius: radius,
  23410. tube: tube,
  23411. radialSegments: radialSegments,
  23412. tubularSegments: tubularSegments,
  23413. arc: arc
  23414. };
  23415. radius = radius || 100;
  23416. tube = tube || 40;
  23417. radialSegments = Math.floor( radialSegments ) || 8;
  23418. tubularSegments = Math.floor( tubularSegments ) || 6;
  23419. arc = arc || Math.PI * 2;
  23420. // used to calculate buffer length
  23421. var vertexCount = ( ( radialSegments + 1 ) * ( tubularSegments + 1 ) );
  23422. var indexCount = radialSegments * tubularSegments * 2 * 3;
  23423. // buffers
  23424. var indices = new ( indexCount > 65535 ? Uint32Array : Uint16Array )( indexCount );
  23425. var vertices = new Float32Array( vertexCount * 3 );
  23426. var normals = new Float32Array( vertexCount * 3 );
  23427. var uvs = new Float32Array( vertexCount * 2 );
  23428. // offset variables
  23429. var vertexBufferOffset = 0;
  23430. var uvBufferOffset = 0;
  23431. var indexBufferOffset = 0;
  23432. // helper variables
  23433. var center = new THREE.Vector3();
  23434. var vertex = new THREE.Vector3();
  23435. var normal = new THREE.Vector3();
  23436. var j, i;
  23437. // generate vertices, normals and uvs
  23438. for ( j = 0; j <= radialSegments; j ++ ) {
  23439. for ( i = 0; i <= tubularSegments; i ++ ) {
  23440. var u = i / tubularSegments * arc;
  23441. var v = j / radialSegments * Math.PI * 2;
  23442. // vertex
  23443. vertex.x = ( radius + tube * Math.cos( v ) ) * Math.cos( u );
  23444. vertex.y = ( radius + tube * Math.cos( v ) ) * Math.sin( u );
  23445. vertex.z = tube * Math.sin( v );
  23446. vertices[ vertexBufferOffset ] = vertex.x;
  23447. vertices[ vertexBufferOffset + 1 ] = vertex.y;
  23448. vertices[ vertexBufferOffset + 2 ] = vertex.z;
  23449. // this vector is used to calculate the normal
  23450. center.x = radius * Math.cos( u );
  23451. center.y = radius * Math.sin( u );
  23452. // normal
  23453. normal.subVectors( vertex, center ).normalize();
  23454. normals[ vertexBufferOffset ] = normal.x;
  23455. normals[ vertexBufferOffset + 1 ] = normal.y;
  23456. normals[ vertexBufferOffset + 2 ] = normal.z;
  23457. // uv
  23458. uvs[ uvBufferOffset ] = i / tubularSegments;
  23459. uvs[ uvBufferOffset + 1 ] = j / radialSegments;
  23460. // update offsets
  23461. vertexBufferOffset += 3;
  23462. uvBufferOffset += 2;
  23463. }
  23464. }
  23465. // generate indices
  23466. for ( j = 1; j <= radialSegments; j ++ ) {
  23467. for ( i = 1; i <= tubularSegments; i ++ ) {
  23468. // indices
  23469. var a = ( tubularSegments + 1 ) * j + i - 1;
  23470. var b = ( tubularSegments + 1 ) * ( j - 1 ) + i - 1;
  23471. var c = ( tubularSegments + 1 ) * ( j - 1 ) + i;
  23472. var d = ( tubularSegments + 1 ) * j + i;
  23473. // face one
  23474. indices[ indexBufferOffset ] = a;
  23475. indices[ indexBufferOffset + 1 ] = b;
  23476. indices[ indexBufferOffset + 2 ] = d;
  23477. // face two
  23478. indices[ indexBufferOffset + 3 ] = b;
  23479. indices[ indexBufferOffset + 4 ] = c;
  23480. indices[ indexBufferOffset + 5 ] = d;
  23481. // update offset
  23482. indexBufferOffset += 6;
  23483. }
  23484. }
  23485. // build geometry
  23486. this.setIndex( new THREE.BufferAttribute( indices, 1 ) );
  23487. this.addAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) );
  23488. this.addAttribute( 'normal', new THREE.BufferAttribute( normals, 3 ) );
  23489. this.addAttribute( 'uv', new THREE.BufferAttribute( uvs, 2 ) );
  23490. };
  23491. THREE.TorusBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  23492. THREE.TorusBufferGeometry.prototype.constructor = THREE.TorusBufferGeometry;
  23493. // File:src/extras/geometries/TorusGeometry.js
  23494. /**
  23495. * @author oosmoxiecode
  23496. * @author mrdoob / http://mrdoob.com/
  23497. * based on http://code.google.com/p/away3d/source/browse/trunk/fp10/Away3DLite/src/away3dlite/primitives/Torus.as?r=2888
  23498. */
  23499. THREE.TorusGeometry = function ( radius, tube, radialSegments, tubularSegments, arc ) {
  23500. THREE.Geometry.call( this );
  23501. this.type = 'TorusGeometry';
  23502. this.parameters = {
  23503. radius: radius,
  23504. tube: tube,
  23505. radialSegments: radialSegments,
  23506. tubularSegments: tubularSegments,
  23507. arc: arc
  23508. };
  23509. this.fromBufferGeometry( new THREE.TorusBufferGeometry( radius, tube, radialSegments, tubularSegments, arc ) );
  23510. };
  23511. THREE.TorusGeometry.prototype = Object.create( THREE.Geometry.prototype );
  23512. THREE.TorusGeometry.prototype.constructor = THREE.TorusGeometry;
  23513. // File:src/extras/geometries/TorusKnotBufferGeometry.js
  23514. /**
  23515. * @author Mugen87 / https://github.com/Mugen87
  23516. *
  23517. * see: http://www.blackpawn.com/texts/pqtorus/
  23518. */
  23519. THREE.TorusKnotBufferGeometry = function ( radius, tube, tubularSegments, radialSegments, p, q ) {
  23520. THREE.BufferGeometry.call( this );
  23521. this.type = 'TorusKnotBufferGeometry';
  23522. this.parameters = {
  23523. radius: radius,
  23524. tube: tube,
  23525. tubularSegments: tubularSegments,
  23526. radialSegments: radialSegments,
  23527. p: p,
  23528. q: q
  23529. };
  23530. radius = radius || 100;
  23531. tube = tube || 40;
  23532. tubularSegments = Math.floor( tubularSegments ) || 64;
  23533. radialSegments = Math.floor( radialSegments ) || 8;
  23534. p = p || 2;
  23535. q = q || 3;
  23536. // used to calculate buffer length
  23537. var vertexCount = ( ( radialSegments + 1 ) * ( tubularSegments + 1 ) );
  23538. var indexCount = radialSegments * tubularSegments * 2 * 3;
  23539. // buffers
  23540. var indices = new THREE.BufferAttribute( new ( indexCount > 65535 ? Uint32Array : Uint16Array )( indexCount ) , 1 );
  23541. var vertices = new THREE.BufferAttribute( new Float32Array( vertexCount * 3 ), 3 );
  23542. var normals = new THREE.BufferAttribute( new Float32Array( vertexCount * 3 ), 3 );
  23543. var uvs = new THREE.BufferAttribute( new Float32Array( vertexCount * 2 ), 2 );
  23544. // helper variables
  23545. var i, j, index = 0, indexOffset = 0;
  23546. var vertex = new THREE.Vector3();
  23547. var normal = new THREE.Vector3();
  23548. var uv = new THREE.Vector2();
  23549. var P1 = new THREE.Vector3();
  23550. var P2 = new THREE.Vector3();
  23551. var B = new THREE.Vector3();
  23552. var T = new THREE.Vector3();
  23553. var N = new THREE.Vector3();
  23554. // generate vertices, normals and uvs
  23555. for ( i = 0; i <= tubularSegments; ++ i ) {
  23556. // the radian "u" is used to calculate the position on the torus curve of the current tubular segement
  23557. var u = i / tubularSegments * p * Math.PI * 2;
  23558. // now we calculate two points. P1 is our current position on the curve, P2 is a little farther ahead.
  23559. // these points are used to create a special "coordinate space", which is necessary to calculate the correct vertex positions
  23560. calculatePositionOnCurve( u, p, q, radius, P1 );
  23561. calculatePositionOnCurve( u + 0.01, p, q, radius, P2 );
  23562. // calculate orthonormal basis
  23563. T.subVectors( P2, P1 );
  23564. N.addVectors( P2, P1 );
  23565. B.crossVectors( T, N );
  23566. N.crossVectors( B, T );
  23567. // normalize B, N. T can be ignored, we don't use it
  23568. B.normalize();
  23569. N.normalize();
  23570. for ( j = 0; j <= radialSegments; ++ j ) {
  23571. // now calculate the vertices. they are nothing more than an extrusion of the torus curve.
  23572. // because we extrude a shape in the xy-plane, there is no need to calculate a z-value.
  23573. var v = j / radialSegments * Math.PI * 2;
  23574. var cx = - tube * Math.cos( v );
  23575. var cy = tube * Math.sin( v );
  23576. // now calculate the final vertex position.
  23577. // first we orient the extrusion with our basis vectos, then we add it to the current position on the curve
  23578. vertex.x = P1.x + ( cx * N.x + cy * B.x );
  23579. vertex.y = P1.y + ( cx * N.y + cy * B.y );
  23580. vertex.z = P1.z + ( cx * N.z + cy * B.z );
  23581. // vertex
  23582. vertices.setXYZ( index, vertex.x, vertex.y, vertex.z );
  23583. // normal (P1 is always the center/origin of the extrusion, thus we can use it to calculate the normal)
  23584. normal.subVectors( vertex, P1 ).normalize();
  23585. normals.setXYZ( index, normal.x, normal.y, normal.z );
  23586. // uv
  23587. uv.x = i / tubularSegments;
  23588. uv.y = j / radialSegments;
  23589. uvs.setXY( index, uv.x, uv.y );
  23590. // increase index
  23591. index ++;
  23592. }
  23593. }
  23594. // generate indices
  23595. for ( j = 1; j <= tubularSegments; j ++ ) {
  23596. for ( i = 1; i <= radialSegments; i ++ ) {
  23597. // indices
  23598. var a = ( radialSegments + 1 ) * ( j - 1 ) + ( i - 1 );
  23599. var b = ( radialSegments + 1 ) * j + ( i - 1 );
  23600. var c = ( radialSegments + 1 ) * j + i;
  23601. var d = ( radialSegments + 1 ) * ( j - 1 ) + i;
  23602. // face one
  23603. indices.setX( indexOffset, a ); indexOffset++;
  23604. indices.setX( indexOffset, b ); indexOffset++;
  23605. indices.setX( indexOffset, d ); indexOffset++;
  23606. // face two
  23607. indices.setX( indexOffset, b ); indexOffset++;
  23608. indices.setX( indexOffset, c ); indexOffset++;
  23609. indices.setX( indexOffset, d ); indexOffset++;
  23610. }
  23611. }
  23612. // build geometry
  23613. this.setIndex( indices );
  23614. this.addAttribute( 'position', vertices );
  23615. this.addAttribute( 'normal', normals );
  23616. this.addAttribute( 'uv', uvs );
  23617. // this function calculates the current position on the torus curve
  23618. function calculatePositionOnCurve( u, p, q, radius, position ) {
  23619. var cu = Math.cos( u );
  23620. var su = Math.sin( u );
  23621. var quOverP = q / p * u;
  23622. var cs = Math.cos( quOverP );
  23623. position.x = radius * ( 2 + cs ) * 0.5 * cu;
  23624. position.y = radius * ( 2 + cs ) * su * 0.5;
  23625. position.z = radius * Math.sin( quOverP ) * 0.5;
  23626. }
  23627. };
  23628. THREE.TorusKnotBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  23629. THREE.TorusKnotBufferGeometry.prototype.constructor = THREE.TorusKnotBufferGeometry;
  23630. // File:src/extras/geometries/TorusKnotGeometry.js
  23631. /**
  23632. * @author oosmoxiecode
  23633. */
  23634. THREE.TorusKnotGeometry = function ( radius, tube, tubularSegments, radialSegments, p, q, heightScale ) {
  23635. THREE.Geometry.call( this );
  23636. this.type = 'TorusKnotGeometry';
  23637. this.parameters = {
  23638. radius: radius,
  23639. tube: tube,
  23640. tubularSegments: tubularSegments,
  23641. radialSegments: radialSegments,
  23642. p: p,
  23643. q: q
  23644. };
  23645. if( heightScale !== undefined ) console.warn( 'THREE.TorusKnotGeometry: heightScale has been deprecated. Use .scale( x, y, z ) instead.' );
  23646. this.fromBufferGeometry( new THREE.TorusKnotBufferGeometry( radius, tube, tubularSegments, radialSegments, p, q ) );
  23647. this.mergeVertices();
  23648. };
  23649. THREE.TorusKnotGeometry.prototype = Object.create( THREE.Geometry.prototype );
  23650. THREE.TorusKnotGeometry.prototype.constructor = THREE.TorusKnotGeometry;
  23651. // File:src/extras/geometries/TubeGeometry.js
  23652. /**
  23653. * @author WestLangley / https://github.com/WestLangley
  23654. * @author zz85 / https://github.com/zz85
  23655. * @author miningold / https://github.com/miningold
  23656. * @author jonobr1 / https://github.com/jonobr1
  23657. *
  23658. * Modified from the TorusKnotGeometry by @oosmoxiecode
  23659. *
  23660. * Creates a tube which extrudes along a 3d spline
  23661. *
  23662. * Uses parallel transport frames as described in
  23663. * http://www.cs.indiana.edu/pub/techreports/TR425.pdf
  23664. */
  23665. THREE.TubeGeometry = function ( path, segments, radius, radialSegments, closed, taper ) {
  23666. THREE.Geometry.call( this );
  23667. this.type = 'TubeGeometry';
  23668. this.parameters = {
  23669. path: path,
  23670. segments: segments,
  23671. radius: radius,
  23672. radialSegments: radialSegments,
  23673. closed: closed,
  23674. taper: taper
  23675. };
  23676. segments = segments || 64;
  23677. radius = radius || 1;
  23678. radialSegments = radialSegments || 8;
  23679. closed = closed || false;
  23680. taper = taper || THREE.TubeGeometry.NoTaper;
  23681. var grid = [];
  23682. var scope = this,
  23683. tangent,
  23684. normal,
  23685. binormal,
  23686. numpoints = segments + 1,
  23687. u, v, r,
  23688. cx, cy,
  23689. pos, pos2 = new THREE.Vector3(),
  23690. i, j,
  23691. ip, jp,
  23692. a, b, c, d,
  23693. uva, uvb, uvc, uvd;
  23694. var frames = new THREE.TubeGeometry.FrenetFrames( path, segments, closed ),
  23695. tangents = frames.tangents,
  23696. normals = frames.normals,
  23697. binormals = frames.binormals;
  23698. // proxy internals
  23699. this.tangents = tangents;
  23700. this.normals = normals;
  23701. this.binormals = binormals;
  23702. function vert( x, y, z ) {
  23703. return scope.vertices.push( new THREE.Vector3( x, y, z ) ) - 1;
  23704. }
  23705. // construct the grid
  23706. for ( i = 0; i < numpoints; i ++ ) {
  23707. grid[ i ] = [];
  23708. u = i / ( numpoints - 1 );
  23709. pos = path.getPointAt( u );
  23710. tangent = tangents[ i ];
  23711. normal = normals[ i ];
  23712. binormal = binormals[ i ];
  23713. r = radius * taper( u );
  23714. for ( j = 0; j < radialSegments; j ++ ) {
  23715. v = j / radialSegments * 2 * Math.PI;
  23716. cx = - r * Math.cos( v ); // TODO: Hack: Negating it so it faces outside.
  23717. cy = r * Math.sin( v );
  23718. pos2.copy( pos );
  23719. pos2.x += cx * normal.x + cy * binormal.x;
  23720. pos2.y += cx * normal.y + cy * binormal.y;
  23721. pos2.z += cx * normal.z + cy * binormal.z;
  23722. grid[ i ][ j ] = vert( pos2.x, pos2.y, pos2.z );
  23723. }
  23724. }
  23725. // construct the mesh
  23726. for ( i = 0; i < segments; i ++ ) {
  23727. for ( j = 0; j < radialSegments; j ++ ) {
  23728. ip = ( closed ) ? ( i + 1 ) % segments : i + 1;
  23729. jp = ( j + 1 ) % radialSegments;
  23730. a = grid[ i ][ j ]; // *** NOT NECESSARILY PLANAR ! ***
  23731. b = grid[ ip ][ j ];
  23732. c = grid[ ip ][ jp ];
  23733. d = grid[ i ][ jp ];
  23734. uva = new THREE.Vector2( i / segments, j / radialSegments );
  23735. uvb = new THREE.Vector2( ( i + 1 ) / segments, j / radialSegments );
  23736. uvc = new THREE.Vector2( ( i + 1 ) / segments, ( j + 1 ) / radialSegments );
  23737. uvd = new THREE.Vector2( i / segments, ( j + 1 ) / radialSegments );
  23738. this.faces.push( new THREE.Face3( a, b, d ) );
  23739. this.faceVertexUvs[ 0 ].push( [ uva, uvb, uvd ] );
  23740. this.faces.push( new THREE.Face3( b, c, d ) );
  23741. this.faceVertexUvs[ 0 ].push( [ uvb.clone(), uvc, uvd.clone() ] );
  23742. }
  23743. }
  23744. this.computeFaceNormals();
  23745. this.computeVertexNormals();
  23746. };
  23747. THREE.TubeGeometry.prototype = Object.create( THREE.Geometry.prototype );
  23748. THREE.TubeGeometry.prototype.constructor = THREE.TubeGeometry;
  23749. THREE.TubeGeometry.NoTaper = function ( u ) {
  23750. return 1;
  23751. };
  23752. THREE.TubeGeometry.SinusoidalTaper = function ( u ) {
  23753. return Math.sin( Math.PI * u );
  23754. };
  23755. // For computing of Frenet frames, exposing the tangents, normals and binormals the spline
  23756. THREE.TubeGeometry.FrenetFrames = function ( path, segments, closed ) {
  23757. var normal = new THREE.Vector3(),
  23758. tangents = [],
  23759. normals = [],
  23760. binormals = [],
  23761. vec = new THREE.Vector3(),
  23762. mat = new THREE.Matrix4(),
  23763. numpoints = segments + 1,
  23764. theta,
  23765. smallest,
  23766. tx, ty, tz,
  23767. i, u;
  23768. // expose internals
  23769. this.tangents = tangents;
  23770. this.normals = normals;
  23771. this.binormals = binormals;
  23772. // compute the tangent vectors for each segment on the path
  23773. for ( i = 0; i < numpoints; i ++ ) {
  23774. u = i / ( numpoints - 1 );
  23775. tangents[ i ] = path.getTangentAt( u );
  23776. tangents[ i ].normalize();
  23777. }
  23778. initialNormal3();
  23779. /*
  23780. function initialNormal1(lastBinormal) {
  23781. // fixed start binormal. Has dangers of 0 vectors
  23782. normals[ 0 ] = new THREE.Vector3();
  23783. binormals[ 0 ] = new THREE.Vector3();
  23784. if (lastBinormal===undefined) lastBinormal = new THREE.Vector3( 0, 0, 1 );
  23785. normals[ 0 ].crossVectors( lastBinormal, tangents[ 0 ] ).normalize();
  23786. binormals[ 0 ].crossVectors( tangents[ 0 ], normals[ 0 ] ).normalize();
  23787. }
  23788. function initialNormal2() {
  23789. // This uses the Frenet-Serret formula for deriving binormal
  23790. var t2 = path.getTangentAt( epsilon );
  23791. normals[ 0 ] = new THREE.Vector3().subVectors( t2, tangents[ 0 ] ).normalize();
  23792. binormals[ 0 ] = new THREE.Vector3().crossVectors( tangents[ 0 ], normals[ 0 ] );
  23793. normals[ 0 ].crossVectors( binormals[ 0 ], tangents[ 0 ] ).normalize(); // last binormal x tangent
  23794. binormals[ 0 ].crossVectors( tangents[ 0 ], normals[ 0 ] ).normalize();
  23795. }
  23796. */
  23797. function initialNormal3() {
  23798. // select an initial normal vector perpendicular to the first tangent vector,
  23799. // and in the direction of the smallest tangent xyz component
  23800. normals[ 0 ] = new THREE.Vector3();
  23801. binormals[ 0 ] = new THREE.Vector3();
  23802. smallest = Number.MAX_VALUE;
  23803. tx = Math.abs( tangents[ 0 ].x );
  23804. ty = Math.abs( tangents[ 0 ].y );
  23805. tz = Math.abs( tangents[ 0 ].z );
  23806. if ( tx <= smallest ) {
  23807. smallest = tx;
  23808. normal.set( 1, 0, 0 );
  23809. }
  23810. if ( ty <= smallest ) {
  23811. smallest = ty;
  23812. normal.set( 0, 1, 0 );
  23813. }
  23814. if ( tz <= smallest ) {
  23815. normal.set( 0, 0, 1 );
  23816. }
  23817. vec.crossVectors( tangents[ 0 ], normal ).normalize();
  23818. normals[ 0 ].crossVectors( tangents[ 0 ], vec );
  23819. binormals[ 0 ].crossVectors( tangents[ 0 ], normals[ 0 ] );
  23820. }
  23821. // compute the slowly-varying normal and binormal vectors for each segment on the path
  23822. for ( i = 1; i < numpoints; i ++ ) {
  23823. normals[ i ] = normals[ i - 1 ].clone();
  23824. binormals[ i ] = binormals[ i - 1 ].clone();
  23825. vec.crossVectors( tangents[ i - 1 ], tangents[ i ] );
  23826. if ( vec.length() > Number.EPSILON ) {
  23827. vec.normalize();
  23828. theta = Math.acos( THREE.Math.clamp( tangents[ i - 1 ].dot( tangents[ i ] ), - 1, 1 ) ); // clamp for floating pt errors
  23829. normals[ i ].applyMatrix4( mat.makeRotationAxis( vec, theta ) );
  23830. }
  23831. binormals[ i ].crossVectors( tangents[ i ], normals[ i ] );
  23832. }
  23833. // if the curve is closed, postprocess the vectors so the first and last normal vectors are the same
  23834. if ( closed ) {
  23835. theta = Math.acos( THREE.Math.clamp( normals[ 0 ].dot( normals[ numpoints - 1 ] ), - 1, 1 ) );
  23836. theta /= ( numpoints - 1 );
  23837. if ( tangents[ 0 ].dot( vec.crossVectors( normals[ 0 ], normals[ numpoints - 1 ] ) ) > 0 ) {
  23838. theta = - theta;
  23839. }
  23840. for ( i = 1; i < numpoints; i ++ ) {
  23841. // twist a little...
  23842. normals[ i ].applyMatrix4( mat.makeRotationAxis( tangents[ i ], theta * i ) );
  23843. binormals[ i ].crossVectors( tangents[ i ], normals[ i ] );
  23844. }
  23845. }
  23846. };
  23847. // File:src/extras/geometries/PolyhedronGeometry.js
  23848. /**
  23849. * @author clockworkgeek / https://github.com/clockworkgeek
  23850. * @author timothypratley / https://github.com/timothypratley
  23851. * @author WestLangley / http://github.com/WestLangley
  23852. */
  23853. THREE.PolyhedronGeometry = function ( vertices, indices, radius, detail ) {
  23854. THREE.Geometry.call( this );
  23855. this.type = 'PolyhedronGeometry';
  23856. this.parameters = {
  23857. vertices: vertices,
  23858. indices: indices,
  23859. radius: radius,
  23860. detail: detail
  23861. };
  23862. radius = radius || 1;
  23863. detail = detail || 0;
  23864. var that = this;
  23865. for ( var i = 0, l = vertices.length; i < l; i += 3 ) {
  23866. prepare( new THREE.Vector3( vertices[ i ], vertices[ i + 1 ], vertices[ i + 2 ] ) );
  23867. }
  23868. var p = this.vertices;
  23869. var faces = [];
  23870. for ( var i = 0, j = 0, l = indices.length; i < l; i += 3, j ++ ) {
  23871. var v1 = p[ indices[ i ] ];
  23872. var v2 = p[ indices[ i + 1 ] ];
  23873. var v3 = p[ indices[ i + 2 ] ];
  23874. faces[ j ] = new THREE.Face3( v1.index, v2.index, v3.index, [ v1.clone(), v2.clone(), v3.clone() ] );
  23875. }
  23876. var centroid = new THREE.Vector3();
  23877. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  23878. subdivide( faces[ i ], detail );
  23879. }
  23880. // Handle case when face straddles the seam
  23881. for ( var i = 0, l = this.faceVertexUvs[ 0 ].length; i < l; i ++ ) {
  23882. var uvs = this.faceVertexUvs[ 0 ][ i ];
  23883. var x0 = uvs[ 0 ].x;
  23884. var x1 = uvs[ 1 ].x;
  23885. var x2 = uvs[ 2 ].x;
  23886. var max = Math.max( x0, x1, x2 );
  23887. var min = Math.min( x0, x1, x2 );
  23888. if ( max > 0.9 && min < 0.1 ) {
  23889. // 0.9 is somewhat arbitrary
  23890. if ( x0 < 0.2 ) uvs[ 0 ].x += 1;
  23891. if ( x1 < 0.2 ) uvs[ 1 ].x += 1;
  23892. if ( x2 < 0.2 ) uvs[ 2 ].x += 1;
  23893. }
  23894. }
  23895. // Apply radius
  23896. for ( var i = 0, l = this.vertices.length; i < l; i ++ ) {
  23897. this.vertices[ i ].multiplyScalar( radius );
  23898. }
  23899. // Merge vertices
  23900. this.mergeVertices();
  23901. this.computeFaceNormals();
  23902. this.boundingSphere = new THREE.Sphere( new THREE.Vector3(), radius );
  23903. // Project vector onto sphere's surface
  23904. function prepare( vector ) {
  23905. var vertex = vector.normalize().clone();
  23906. vertex.index = that.vertices.push( vertex ) - 1;
  23907. // Texture coords are equivalent to map coords, calculate angle and convert to fraction of a circle.
  23908. var u = azimuth( vector ) / 2 / Math.PI + 0.5;
  23909. var v = inclination( vector ) / Math.PI + 0.5;
  23910. vertex.uv = new THREE.Vector2( u, 1 - v );
  23911. return vertex;
  23912. }
  23913. // Approximate a curved face with recursively sub-divided triangles.
  23914. function make( v1, v2, v3 ) {
  23915. var face = new THREE.Face3( v1.index, v2.index, v3.index, [ v1.clone(), v2.clone(), v3.clone() ] );
  23916. that.faces.push( face );
  23917. centroid.copy( v1 ).add( v2 ).add( v3 ).divideScalar( 3 );
  23918. var azi = azimuth( centroid );
  23919. that.faceVertexUvs[ 0 ].push( [
  23920. correctUV( v1.uv, v1, azi ),
  23921. correctUV( v2.uv, v2, azi ),
  23922. correctUV( v3.uv, v3, azi )
  23923. ] );
  23924. }
  23925. // Analytically subdivide a face to the required detail level.
  23926. function subdivide( face, detail ) {
  23927. var cols = Math.pow( 2, detail );
  23928. var a = prepare( that.vertices[ face.a ] );
  23929. var b = prepare( that.vertices[ face.b ] );
  23930. var c = prepare( that.vertices[ face.c ] );
  23931. var v = [];
  23932. // Construct all of the vertices for this subdivision.
  23933. for ( var i = 0 ; i <= cols; i ++ ) {
  23934. v[ i ] = [];
  23935. var aj = prepare( a.clone().lerp( c, i / cols ) );
  23936. var bj = prepare( b.clone().lerp( c, i / cols ) );
  23937. var rows = cols - i;
  23938. for ( var j = 0; j <= rows; j ++ ) {
  23939. if ( j === 0 && i === cols ) {
  23940. v[ i ][ j ] = aj;
  23941. } else {
  23942. v[ i ][ j ] = prepare( aj.clone().lerp( bj, j / rows ) );
  23943. }
  23944. }
  23945. }
  23946. // Construct all of the faces.
  23947. for ( var i = 0; i < cols ; i ++ ) {
  23948. for ( var j = 0; j < 2 * ( cols - i ) - 1; j ++ ) {
  23949. var k = Math.floor( j / 2 );
  23950. if ( j % 2 === 0 ) {
  23951. make(
  23952. v[ i ][ k + 1 ],
  23953. v[ i + 1 ][ k ],
  23954. v[ i ][ k ]
  23955. );
  23956. } else {
  23957. make(
  23958. v[ i ][ k + 1 ],
  23959. v[ i + 1 ][ k + 1 ],
  23960. v[ i + 1 ][ k ]
  23961. );
  23962. }
  23963. }
  23964. }
  23965. }
  23966. // Angle around the Y axis, counter-clockwise when looking from above.
  23967. function azimuth( vector ) {
  23968. return Math.atan2( vector.z, - vector.x );
  23969. }
  23970. // Angle above the XZ plane.
  23971. function inclination( vector ) {
  23972. return Math.atan2( - vector.y, Math.sqrt( ( vector.x * vector.x ) + ( vector.z * vector.z ) ) );
  23973. }
  23974. // Texture fixing helper. Spheres have some odd behaviours.
  23975. function correctUV( uv, vector, azimuth ) {
  23976. if ( ( azimuth < 0 ) && ( uv.x === 1 ) ) uv = new THREE.Vector2( uv.x - 1, uv.y );
  23977. if ( ( vector.x === 0 ) && ( vector.z === 0 ) ) uv = new THREE.Vector2( azimuth / 2 / Math.PI + 0.5, uv.y );
  23978. return uv.clone();
  23979. }
  23980. };
  23981. THREE.PolyhedronGeometry.prototype = Object.create( THREE.Geometry.prototype );
  23982. THREE.PolyhedronGeometry.prototype.constructor = THREE.PolyhedronGeometry;
  23983. // File:src/extras/geometries/DodecahedronGeometry.js
  23984. /**
  23985. * @author Abe Pazos / https://hamoid.com
  23986. */
  23987. THREE.DodecahedronGeometry = function ( radius, detail ) {
  23988. var t = ( 1 + Math.sqrt( 5 ) ) / 2;
  23989. var r = 1 / t;
  23990. var vertices = [
  23991. // (±1, ±1, ±1)
  23992. - 1, - 1, - 1, - 1, - 1, 1,
  23993. - 1, 1, - 1, - 1, 1, 1,
  23994. 1, - 1, - 1, 1, - 1, 1,
  23995. 1, 1, - 1, 1, 1, 1,
  23996. // (0, ±1/φ, ±φ)
  23997. 0, - r, - t, 0, - r, t,
  23998. 0, r, - t, 0, r, t,
  23999. // (±1/φ, ±φ, 0)
  24000. - r, - t, 0, - r, t, 0,
  24001. r, - t, 0, r, t, 0,
  24002. // (±φ, 0, ±1/φ)
  24003. - t, 0, - r, t, 0, - r,
  24004. - t, 0, r, t, 0, r
  24005. ];
  24006. var indices = [
  24007. 3, 11, 7, 3, 7, 15, 3, 15, 13,
  24008. 7, 19, 17, 7, 17, 6, 7, 6, 15,
  24009. 17, 4, 8, 17, 8, 10, 17, 10, 6,
  24010. 8, 0, 16, 8, 16, 2, 8, 2, 10,
  24011. 0, 12, 1, 0, 1, 18, 0, 18, 16,
  24012. 6, 10, 2, 6, 2, 13, 6, 13, 15,
  24013. 2, 16, 18, 2, 18, 3, 2, 3, 13,
  24014. 18, 1, 9, 18, 9, 11, 18, 11, 3,
  24015. 4, 14, 12, 4, 12, 0, 4, 0, 8,
  24016. 11, 9, 5, 11, 5, 19, 11, 19, 7,
  24017. 19, 5, 14, 19, 14, 4, 19, 4, 17,
  24018. 1, 12, 14, 1, 14, 5, 1, 5, 9
  24019. ];
  24020. THREE.PolyhedronGeometry.call( this, vertices, indices, radius, detail );
  24021. this.type = 'DodecahedronGeometry';
  24022. this.parameters = {
  24023. radius: radius,
  24024. detail: detail
  24025. };
  24026. };
  24027. THREE.DodecahedronGeometry.prototype = Object.create( THREE.PolyhedronGeometry.prototype );
  24028. THREE.DodecahedronGeometry.prototype.constructor = THREE.DodecahedronGeometry;
  24029. // File:src/extras/geometries/IcosahedronGeometry.js
  24030. /**
  24031. * @author timothypratley / https://github.com/timothypratley
  24032. */
  24033. THREE.IcosahedronGeometry = function ( radius, detail ) {
  24034. var t = ( 1 + Math.sqrt( 5 ) ) / 2;
  24035. var vertices = [
  24036. - 1, t, 0, 1, t, 0, - 1, - t, 0, 1, - t, 0,
  24037. 0, - 1, t, 0, 1, t, 0, - 1, - t, 0, 1, - t,
  24038. t, 0, - 1, t, 0, 1, - t, 0, - 1, - t, 0, 1
  24039. ];
  24040. var indices = [
  24041. 0, 11, 5, 0, 5, 1, 0, 1, 7, 0, 7, 10, 0, 10, 11,
  24042. 1, 5, 9, 5, 11, 4, 11, 10, 2, 10, 7, 6, 7, 1, 8,
  24043. 3, 9, 4, 3, 4, 2, 3, 2, 6, 3, 6, 8, 3, 8, 9,
  24044. 4, 9, 5, 2, 4, 11, 6, 2, 10, 8, 6, 7, 9, 8, 1
  24045. ];
  24046. THREE.PolyhedronGeometry.call( this, vertices, indices, radius, detail );
  24047. this.type = 'IcosahedronGeometry';
  24048. this.parameters = {
  24049. radius: radius,
  24050. detail: detail
  24051. };
  24052. };
  24053. THREE.IcosahedronGeometry.prototype = Object.create( THREE.PolyhedronGeometry.prototype );
  24054. THREE.IcosahedronGeometry.prototype.constructor = THREE.IcosahedronGeometry;
  24055. // File:src/extras/geometries/OctahedronGeometry.js
  24056. /**
  24057. * @author timothypratley / https://github.com/timothypratley
  24058. */
  24059. THREE.OctahedronGeometry = function ( radius, detail ) {
  24060. var vertices = [
  24061. 1, 0, 0, - 1, 0, 0, 0, 1, 0, 0, - 1, 0, 0, 0, 1, 0, 0, - 1
  24062. ];
  24063. var indices = [
  24064. 0, 2, 4, 0, 4, 3, 0, 3, 5, 0, 5, 2, 1, 2, 5, 1, 5, 3, 1, 3, 4, 1, 4, 2
  24065. ];
  24066. THREE.PolyhedronGeometry.call( this, vertices, indices, radius, detail );
  24067. this.type = 'OctahedronGeometry';
  24068. this.parameters = {
  24069. radius: radius,
  24070. detail: detail
  24071. };
  24072. };
  24073. THREE.OctahedronGeometry.prototype = Object.create( THREE.PolyhedronGeometry.prototype );
  24074. THREE.OctahedronGeometry.prototype.constructor = THREE.OctahedronGeometry;
  24075. // File:src/extras/geometries/TetrahedronGeometry.js
  24076. /**
  24077. * @author timothypratley / https://github.com/timothypratley
  24078. */
  24079. THREE.TetrahedronGeometry = function ( radius, detail ) {
  24080. var vertices = [
  24081. 1, 1, 1, - 1, - 1, 1, - 1, 1, - 1, 1, - 1, - 1
  24082. ];
  24083. var indices = [
  24084. 2, 1, 0, 0, 3, 2, 1, 3, 0, 2, 3, 1
  24085. ];
  24086. THREE.PolyhedronGeometry.call( this, vertices, indices, radius, detail );
  24087. this.type = 'TetrahedronGeometry';
  24088. this.parameters = {
  24089. radius: radius,
  24090. detail: detail
  24091. };
  24092. };
  24093. THREE.TetrahedronGeometry.prototype = Object.create( THREE.PolyhedronGeometry.prototype );
  24094. THREE.TetrahedronGeometry.prototype.constructor = THREE.TetrahedronGeometry;
  24095. // File:src/extras/geometries/ParametricGeometry.js
  24096. /**
  24097. * @author zz85 / https://github.com/zz85
  24098. * Parametric Surfaces Geometry
  24099. * based on the brilliant article by @prideout http://prideout.net/blog/?p=44
  24100. *
  24101. * new THREE.ParametricGeometry( parametricFunction, uSegments, ySegements );
  24102. *
  24103. */
  24104. THREE.ParametricGeometry = function ( func, slices, stacks ) {
  24105. THREE.Geometry.call( this );
  24106. this.type = 'ParametricGeometry';
  24107. this.parameters = {
  24108. func: func,
  24109. slices: slices,
  24110. stacks: stacks
  24111. };
  24112. var verts = this.vertices;
  24113. var faces = this.faces;
  24114. var uvs = this.faceVertexUvs[ 0 ];
  24115. var i, j, p;
  24116. var u, v;
  24117. var sliceCount = slices + 1;
  24118. for ( i = 0; i <= stacks; i ++ ) {
  24119. v = i / stacks;
  24120. for ( j = 0; j <= slices; j ++ ) {
  24121. u = j / slices;
  24122. p = func( u, v );
  24123. verts.push( p );
  24124. }
  24125. }
  24126. var a, b, c, d;
  24127. var uva, uvb, uvc, uvd;
  24128. for ( i = 0; i < stacks; i ++ ) {
  24129. for ( j = 0; j < slices; j ++ ) {
  24130. a = i * sliceCount + j;
  24131. b = i * sliceCount + j + 1;
  24132. c = ( i + 1 ) * sliceCount + j + 1;
  24133. d = ( i + 1 ) * sliceCount + j;
  24134. uva = new THREE.Vector2( j / slices, i / stacks );
  24135. uvb = new THREE.Vector2( ( j + 1 ) / slices, i / stacks );
  24136. uvc = new THREE.Vector2( ( j + 1 ) / slices, ( i + 1 ) / stacks );
  24137. uvd = new THREE.Vector2( j / slices, ( i + 1 ) / stacks );
  24138. faces.push( new THREE.Face3( a, b, d ) );
  24139. uvs.push( [ uva, uvb, uvd ] );
  24140. faces.push( new THREE.Face3( b, c, d ) );
  24141. uvs.push( [ uvb.clone(), uvc, uvd.clone() ] );
  24142. }
  24143. }
  24144. // console.log(this);
  24145. // magic bullet
  24146. // var diff = this.mergeVertices();
  24147. // console.log('removed ', diff, ' vertices by merging');
  24148. this.computeFaceNormals();
  24149. this.computeVertexNormals();
  24150. };
  24151. THREE.ParametricGeometry.prototype = Object.create( THREE.Geometry.prototype );
  24152. THREE.ParametricGeometry.prototype.constructor = THREE.ParametricGeometry;
  24153. // File:src/extras/geometries/WireframeGeometry.js
  24154. /**
  24155. * @author mrdoob / http://mrdoob.com/
  24156. */
  24157. THREE.WireframeGeometry = function ( geometry ) {
  24158. THREE.BufferGeometry.call( this );
  24159. var edge = [ 0, 0 ], hash = {};
  24160. function sortFunction( a, b ) {
  24161. return a - b;
  24162. }
  24163. var keys = [ 'a', 'b', 'c' ];
  24164. if ( geometry instanceof THREE.Geometry ) {
  24165. var vertices = geometry.vertices;
  24166. var faces = geometry.faces;
  24167. var numEdges = 0;
  24168. // allocate maximal size
  24169. var edges = new Uint32Array( 6 * faces.length );
  24170. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  24171. var face = faces[ i ];
  24172. for ( var j = 0; j < 3; j ++ ) {
  24173. edge[ 0 ] = face[ keys[ j ] ];
  24174. edge[ 1 ] = face[ keys[ ( j + 1 ) % 3 ] ];
  24175. edge.sort( sortFunction );
  24176. var key = edge.toString();
  24177. if ( hash[ key ] === undefined ) {
  24178. edges[ 2 * numEdges ] = edge[ 0 ];
  24179. edges[ 2 * numEdges + 1 ] = edge[ 1 ];
  24180. hash[ key ] = true;
  24181. numEdges ++;
  24182. }
  24183. }
  24184. }
  24185. var coords = new Float32Array( numEdges * 2 * 3 );
  24186. for ( var i = 0, l = numEdges; i < l; i ++ ) {
  24187. for ( var j = 0; j < 2; j ++ ) {
  24188. var vertex = vertices[ edges [ 2 * i + j ] ];
  24189. var index = 6 * i + 3 * j;
  24190. coords[ index + 0 ] = vertex.x;
  24191. coords[ index + 1 ] = vertex.y;
  24192. coords[ index + 2 ] = vertex.z;
  24193. }
  24194. }
  24195. this.addAttribute( 'position', new THREE.BufferAttribute( coords, 3 ) );
  24196. } else if ( geometry instanceof THREE.BufferGeometry ) {
  24197. if ( geometry.index !== null ) {
  24198. // Indexed BufferGeometry
  24199. var indices = geometry.index.array;
  24200. var vertices = geometry.attributes.position;
  24201. var groups = geometry.groups;
  24202. var numEdges = 0;
  24203. if ( groups.length === 0 ) {
  24204. geometry.addGroup( 0, indices.length );
  24205. }
  24206. // allocate maximal size
  24207. var edges = new Uint32Array( 2 * indices.length );
  24208. for ( var o = 0, ol = groups.length; o < ol; ++ o ) {
  24209. var group = groups[ o ];
  24210. var start = group.start;
  24211. var count = group.count;
  24212. for ( var i = start, il = start + count; i < il; i += 3 ) {
  24213. for ( var j = 0; j < 3; j ++ ) {
  24214. edge[ 0 ] = indices[ i + j ];
  24215. edge[ 1 ] = indices[ i + ( j + 1 ) % 3 ];
  24216. edge.sort( sortFunction );
  24217. var key = edge.toString();
  24218. if ( hash[ key ] === undefined ) {
  24219. edges[ 2 * numEdges ] = edge[ 0 ];
  24220. edges[ 2 * numEdges + 1 ] = edge[ 1 ];
  24221. hash[ key ] = true;
  24222. numEdges ++;
  24223. }
  24224. }
  24225. }
  24226. }
  24227. var coords = new Float32Array( numEdges * 2 * 3 );
  24228. for ( var i = 0, l = numEdges; i < l; i ++ ) {
  24229. for ( var j = 0; j < 2; j ++ ) {
  24230. var index = 6 * i + 3 * j;
  24231. var index2 = edges[ 2 * i + j ];
  24232. coords[ index + 0 ] = vertices.getX( index2 );
  24233. coords[ index + 1 ] = vertices.getY( index2 );
  24234. coords[ index + 2 ] = vertices.getZ( index2 );
  24235. }
  24236. }
  24237. this.addAttribute( 'position', new THREE.BufferAttribute( coords, 3 ) );
  24238. } else {
  24239. // non-indexed BufferGeometry
  24240. var vertices = geometry.attributes.position.array;
  24241. var numEdges = vertices.length / 3;
  24242. var numTris = numEdges / 3;
  24243. var coords = new Float32Array( numEdges * 2 * 3 );
  24244. for ( var i = 0, l = numTris; i < l; i ++ ) {
  24245. for ( var j = 0; j < 3; j ++ ) {
  24246. var index = 18 * i + 6 * j;
  24247. var index1 = 9 * i + 3 * j;
  24248. coords[ index + 0 ] = vertices[ index1 ];
  24249. coords[ index + 1 ] = vertices[ index1 + 1 ];
  24250. coords[ index + 2 ] = vertices[ index1 + 2 ];
  24251. var index2 = 9 * i + 3 * ( ( j + 1 ) % 3 );
  24252. coords[ index + 3 ] = vertices[ index2 ];
  24253. coords[ index + 4 ] = vertices[ index2 + 1 ];
  24254. coords[ index + 5 ] = vertices[ index2 + 2 ];
  24255. }
  24256. }
  24257. this.addAttribute( 'position', new THREE.BufferAttribute( coords, 3 ) );
  24258. }
  24259. }
  24260. };
  24261. THREE.WireframeGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  24262. THREE.WireframeGeometry.prototype.constructor = THREE.WireframeGeometry;
  24263. // File:src/extras/helpers/AxisHelper.js
  24264. /**
  24265. * @author sroucheray / http://sroucheray.org/
  24266. * @author mrdoob / http://mrdoob.com/
  24267. */
  24268. THREE.AxisHelper = function ( size ) {
  24269. size = size || 1;
  24270. var vertices = new Float32Array( [
  24271. 0, 0, 0, size, 0, 0,
  24272. 0, 0, 0, 0, size, 0,
  24273. 0, 0, 0, 0, 0, size
  24274. ] );
  24275. var colors = new Float32Array( [
  24276. 1, 0, 0, 1, 0.6, 0,
  24277. 0, 1, 0, 0.6, 1, 0,
  24278. 0, 0, 1, 0, 0.6, 1
  24279. ] );
  24280. var geometry = new THREE.BufferGeometry();
  24281. geometry.addAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) );
  24282. geometry.addAttribute( 'color', new THREE.BufferAttribute( colors, 3 ) );
  24283. var material = new THREE.LineBasicMaterial( { vertexColors: THREE.VertexColors } );
  24284. THREE.LineSegments.call( this, geometry, material );
  24285. };
  24286. THREE.AxisHelper.prototype = Object.create( THREE.LineSegments.prototype );
  24287. THREE.AxisHelper.prototype.constructor = THREE.AxisHelper;
  24288. // File:src/extras/helpers/ArrowHelper.js
  24289. /**
  24290. * @author WestLangley / http://github.com/WestLangley
  24291. * @author zz85 / http://github.com/zz85
  24292. * @author bhouston / http://clara.io
  24293. *
  24294. * Creates an arrow for visualizing directions
  24295. *
  24296. * Parameters:
  24297. * dir - Vector3
  24298. * origin - Vector3
  24299. * length - Number
  24300. * color - color in hex value
  24301. * headLength - Number
  24302. * headWidth - Number
  24303. */
  24304. THREE.ArrowHelper = ( function () {
  24305. var lineGeometry = new THREE.BufferGeometry();
  24306. lineGeometry.addAttribute( 'position', new THREE.Float32Attribute( [ 0, 0, 0, 0, 1, 0 ], 3 ) );
  24307. var coneGeometry = new THREE.CylinderBufferGeometry( 0, 0.5, 1, 5, 1 );
  24308. coneGeometry.translate( 0, - 0.5, 0 );
  24309. return function ArrowHelper( dir, origin, length, color, headLength, headWidth ) {
  24310. // dir is assumed to be normalized
  24311. THREE.Object3D.call( this );
  24312. if ( color === undefined ) color = 0xffff00;
  24313. if ( length === undefined ) length = 1;
  24314. if ( headLength === undefined ) headLength = 0.2 * length;
  24315. if ( headWidth === undefined ) headWidth = 0.2 * headLength;
  24316. this.position.copy( origin );
  24317. this.line = new THREE.Line( lineGeometry, new THREE.LineBasicMaterial( { color: color } ) );
  24318. this.line.matrixAutoUpdate = false;
  24319. this.add( this.line );
  24320. this.cone = new THREE.Mesh( coneGeometry, new THREE.MeshBasicMaterial( { color: color } ) );
  24321. this.cone.matrixAutoUpdate = false;
  24322. this.add( this.cone );
  24323. this.setDirection( dir );
  24324. this.setLength( length, headLength, headWidth );
  24325. };
  24326. }() );
  24327. THREE.ArrowHelper.prototype = Object.create( THREE.Object3D.prototype );
  24328. THREE.ArrowHelper.prototype.constructor = THREE.ArrowHelper;
  24329. THREE.ArrowHelper.prototype.setDirection = ( function () {
  24330. var axis = new THREE.Vector3();
  24331. var radians;
  24332. return function setDirection( dir ) {
  24333. // dir is assumed to be normalized
  24334. if ( dir.y > 0.99999 ) {
  24335. this.quaternion.set( 0, 0, 0, 1 );
  24336. } else if ( dir.y < - 0.99999 ) {
  24337. this.quaternion.set( 1, 0, 0, 0 );
  24338. } else {
  24339. axis.set( dir.z, 0, - dir.x ).normalize();
  24340. radians = Math.acos( dir.y );
  24341. this.quaternion.setFromAxisAngle( axis, radians );
  24342. }
  24343. };
  24344. }() );
  24345. THREE.ArrowHelper.prototype.setLength = function ( length, headLength, headWidth ) {
  24346. if ( headLength === undefined ) headLength = 0.2 * length;
  24347. if ( headWidth === undefined ) headWidth = 0.2 * headLength;
  24348. this.line.scale.set( 1, Math.max( 0, length - headLength ), 1 );
  24349. this.line.updateMatrix();
  24350. this.cone.scale.set( headWidth, headLength, headWidth );
  24351. this.cone.position.y = length;
  24352. this.cone.updateMatrix();
  24353. };
  24354. THREE.ArrowHelper.prototype.setColor = function ( color ) {
  24355. this.line.material.color.copy( color );
  24356. this.cone.material.color.copy( color );
  24357. };
  24358. // File:src/extras/helpers/BoxHelper.js
  24359. /**
  24360. * @author mrdoob / http://mrdoob.com/
  24361. */
  24362. THREE.BoxHelper = function ( object, color ) {
  24363. if ( color === undefined ) color = 0xffff00;
  24364. 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 ] );
  24365. var positions = new Float32Array( 8 * 3 );
  24366. var geometry = new THREE.BufferGeometry();
  24367. geometry.setIndex( new THREE.BufferAttribute( indices, 1 ) );
  24368. geometry.addAttribute( 'position', new THREE.BufferAttribute( positions, 3 ) );
  24369. THREE.LineSegments.call( this, geometry, new THREE.LineBasicMaterial( { color: color } ) );
  24370. if ( object !== undefined ) {
  24371. this.update( object );
  24372. }
  24373. };
  24374. THREE.BoxHelper.prototype = Object.create( THREE.LineSegments.prototype );
  24375. THREE.BoxHelper.prototype.constructor = THREE.BoxHelper;
  24376. THREE.BoxHelper.prototype.update = ( function () {
  24377. var box = new THREE.Box3();
  24378. return function update( object ) {
  24379. if ( object instanceof THREE.Box3 ) {
  24380. box.copy( object );
  24381. } else {
  24382. box.setFromObject( object );
  24383. }
  24384. if ( box.isEmpty() ) return;
  24385. var min = box.min;
  24386. var max = box.max;
  24387. /*
  24388. 5____4
  24389. 1/___0/|
  24390. | 6__|_7
  24391. 2/___3/
  24392. 0: max.x, max.y, max.z
  24393. 1: min.x, max.y, max.z
  24394. 2: min.x, min.y, max.z
  24395. 3: max.x, min.y, max.z
  24396. 4: max.x, max.y, min.z
  24397. 5: min.x, max.y, min.z
  24398. 6: min.x, min.y, min.z
  24399. 7: max.x, min.y, min.z
  24400. */
  24401. var position = this.geometry.attributes.position;
  24402. var array = position.array;
  24403. array[ 0 ] = max.x; array[ 1 ] = max.y; array[ 2 ] = max.z;
  24404. array[ 3 ] = min.x; array[ 4 ] = max.y; array[ 5 ] = max.z;
  24405. array[ 6 ] = min.x; array[ 7 ] = min.y; array[ 8 ] = max.z;
  24406. array[ 9 ] = max.x; array[ 10 ] = min.y; array[ 11 ] = max.z;
  24407. array[ 12 ] = max.x; array[ 13 ] = max.y; array[ 14 ] = min.z;
  24408. array[ 15 ] = min.x; array[ 16 ] = max.y; array[ 17 ] = min.z;
  24409. array[ 18 ] = min.x; array[ 19 ] = min.y; array[ 20 ] = min.z;
  24410. array[ 21 ] = max.x; array[ 22 ] = min.y; array[ 23 ] = min.z;
  24411. position.needsUpdate = true;
  24412. this.geometry.computeBoundingSphere();
  24413. };
  24414. } )();
  24415. // File:src/extras/helpers/BoundingBoxHelper.js
  24416. /**
  24417. * @author WestLangley / http://github.com/WestLangley
  24418. */
  24419. // a helper to show the world-axis-aligned bounding box for an object
  24420. THREE.BoundingBoxHelper = function ( object, hex ) {
  24421. var color = ( hex !== undefined ) ? hex : 0x888888;
  24422. this.object = object;
  24423. this.box = new THREE.Box3();
  24424. THREE.Mesh.call( this, new THREE.BoxGeometry( 1, 1, 1 ), new THREE.MeshBasicMaterial( { color: color, wireframe: true } ) );
  24425. };
  24426. THREE.BoundingBoxHelper.prototype = Object.create( THREE.Mesh.prototype );
  24427. THREE.BoundingBoxHelper.prototype.constructor = THREE.BoundingBoxHelper;
  24428. THREE.BoundingBoxHelper.prototype.update = function () {
  24429. this.box.setFromObject( this.object );
  24430. this.box.size( this.scale );
  24431. this.box.center( this.position );
  24432. };
  24433. // File:src/extras/helpers/CameraHelper.js
  24434. /**
  24435. * @author alteredq / http://alteredqualia.com/
  24436. *
  24437. * - shows frustum, line of sight and up of the camera
  24438. * - suitable for fast updates
  24439. * - based on frustum visualization in lightgl.js shadowmap example
  24440. * http://evanw.github.com/lightgl.js/tests/shadowmap.html
  24441. */
  24442. THREE.CameraHelper = function ( camera ) {
  24443. var geometry = new THREE.Geometry();
  24444. var material = new THREE.LineBasicMaterial( { color: 0xffffff, vertexColors: THREE.FaceColors } );
  24445. var pointMap = {};
  24446. // colors
  24447. var hexFrustum = 0xffaa00;
  24448. var hexCone = 0xff0000;
  24449. var hexUp = 0x00aaff;
  24450. var hexTarget = 0xffffff;
  24451. var hexCross = 0x333333;
  24452. // near
  24453. addLine( "n1", "n2", hexFrustum );
  24454. addLine( "n2", "n4", hexFrustum );
  24455. addLine( "n4", "n3", hexFrustum );
  24456. addLine( "n3", "n1", hexFrustum );
  24457. // far
  24458. addLine( "f1", "f2", hexFrustum );
  24459. addLine( "f2", "f4", hexFrustum );
  24460. addLine( "f4", "f3", hexFrustum );
  24461. addLine( "f3", "f1", hexFrustum );
  24462. // sides
  24463. addLine( "n1", "f1", hexFrustum );
  24464. addLine( "n2", "f2", hexFrustum );
  24465. addLine( "n3", "f3", hexFrustum );
  24466. addLine( "n4", "f4", hexFrustum );
  24467. // cone
  24468. addLine( "p", "n1", hexCone );
  24469. addLine( "p", "n2", hexCone );
  24470. addLine( "p", "n3", hexCone );
  24471. addLine( "p", "n4", hexCone );
  24472. // up
  24473. addLine( "u1", "u2", hexUp );
  24474. addLine( "u2", "u3", hexUp );
  24475. addLine( "u3", "u1", hexUp );
  24476. // target
  24477. addLine( "c", "t", hexTarget );
  24478. addLine( "p", "c", hexCross );
  24479. // cross
  24480. addLine( "cn1", "cn2", hexCross );
  24481. addLine( "cn3", "cn4", hexCross );
  24482. addLine( "cf1", "cf2", hexCross );
  24483. addLine( "cf3", "cf4", hexCross );
  24484. function addLine( a, b, hex ) {
  24485. addPoint( a, hex );
  24486. addPoint( b, hex );
  24487. }
  24488. function addPoint( id, hex ) {
  24489. geometry.vertices.push( new THREE.Vector3() );
  24490. geometry.colors.push( new THREE.Color( hex ) );
  24491. if ( pointMap[ id ] === undefined ) {
  24492. pointMap[ id ] = [];
  24493. }
  24494. pointMap[ id ].push( geometry.vertices.length - 1 );
  24495. }
  24496. THREE.LineSegments.call( this, geometry, material );
  24497. this.camera = camera;
  24498. if( this.camera.updateProjectionMatrix ) this.camera.updateProjectionMatrix();
  24499. this.matrix = camera.matrixWorld;
  24500. this.matrixAutoUpdate = false;
  24501. this.pointMap = pointMap;
  24502. this.update();
  24503. };
  24504. THREE.CameraHelper.prototype = Object.create( THREE.LineSegments.prototype );
  24505. THREE.CameraHelper.prototype.constructor = THREE.CameraHelper;
  24506. THREE.CameraHelper.prototype.update = function () {
  24507. var geometry, pointMap;
  24508. var vector = new THREE.Vector3();
  24509. var camera = new THREE.Camera();
  24510. function setPoint( point, x, y, z ) {
  24511. vector.set( x, y, z ).unproject( camera );
  24512. var points = pointMap[ point ];
  24513. if ( points !== undefined ) {
  24514. for ( var i = 0, il = points.length; i < il; i ++ ) {
  24515. geometry.vertices[ points[ i ] ].copy( vector );
  24516. }
  24517. }
  24518. }
  24519. return function update() {
  24520. geometry = this.geometry;
  24521. pointMap = this.pointMap;
  24522. var w = 1, h = 1;
  24523. // we need just camera projection matrix
  24524. // world matrix must be identity
  24525. camera.projectionMatrix.copy( this.camera.projectionMatrix );
  24526. // center / target
  24527. setPoint( "c", 0, 0, - 1 );
  24528. setPoint( "t", 0, 0, 1 );
  24529. // near
  24530. setPoint( "n1", - w, - h, - 1 );
  24531. setPoint( "n2", w, - h, - 1 );
  24532. setPoint( "n3", - w, h, - 1 );
  24533. setPoint( "n4", w, h, - 1 );
  24534. // far
  24535. setPoint( "f1", - w, - h, 1 );
  24536. setPoint( "f2", w, - h, 1 );
  24537. setPoint( "f3", - w, h, 1 );
  24538. setPoint( "f4", w, h, 1 );
  24539. // up
  24540. setPoint( "u1", w * 0.7, h * 1.1, - 1 );
  24541. setPoint( "u2", - w * 0.7, h * 1.1, - 1 );
  24542. setPoint( "u3", 0, h * 2, - 1 );
  24543. // cross
  24544. setPoint( "cf1", - w, 0, 1 );
  24545. setPoint( "cf2", w, 0, 1 );
  24546. setPoint( "cf3", 0, - h, 1 );
  24547. setPoint( "cf4", 0, h, 1 );
  24548. setPoint( "cn1", - w, 0, - 1 );
  24549. setPoint( "cn2", w, 0, - 1 );
  24550. setPoint( "cn3", 0, - h, - 1 );
  24551. setPoint( "cn4", 0, h, - 1 );
  24552. geometry.verticesNeedUpdate = true;
  24553. };
  24554. }();
  24555. // File:src/extras/helpers/DirectionalLightHelper.js
  24556. /**
  24557. * @author alteredq / http://alteredqualia.com/
  24558. * @author mrdoob / http://mrdoob.com/
  24559. * @author WestLangley / http://github.com/WestLangley
  24560. */
  24561. THREE.DirectionalLightHelper = function ( light, size ) {
  24562. THREE.Object3D.call( this );
  24563. this.light = light;
  24564. this.light.updateMatrixWorld();
  24565. this.matrix = light.matrixWorld;
  24566. this.matrixAutoUpdate = false;
  24567. if ( size === undefined ) size = 1;
  24568. var geometry = new THREE.BufferGeometry();
  24569. geometry.addAttribute( 'position', new THREE.Float32Attribute( [
  24570. - size, size, 0,
  24571. size, size, 0,
  24572. size, - size, 0,
  24573. - size, - size, 0,
  24574. - size, size, 0
  24575. ], 3 ) );
  24576. var material = new THREE.LineBasicMaterial( { fog: false } );
  24577. this.add( new THREE.Line( geometry, material ) );
  24578. geometry = new THREE.BufferGeometry();
  24579. geometry.addAttribute( 'position', new THREE.Float32Attribute( [ 0, 0, 0, 0, 0, 1 ], 3 ) );
  24580. this.add( new THREE.Line( geometry, material ));
  24581. this.update();
  24582. };
  24583. THREE.DirectionalLightHelper.prototype = Object.create( THREE.Object3D.prototype );
  24584. THREE.DirectionalLightHelper.prototype.constructor = THREE.DirectionalLightHelper;
  24585. THREE.DirectionalLightHelper.prototype.dispose = function () {
  24586. var lightPlane = this.children[ 0 ];
  24587. var targetLine = this.children[ 1 ];
  24588. lightPlane.geometry.dispose();
  24589. lightPlane.material.dispose();
  24590. targetLine.geometry.dispose();
  24591. targetLine.material.dispose();
  24592. };
  24593. THREE.DirectionalLightHelper.prototype.update = function () {
  24594. var v1 = new THREE.Vector3();
  24595. var v2 = new THREE.Vector3();
  24596. var v3 = new THREE.Vector3();
  24597. return function update() {
  24598. v1.setFromMatrixPosition( this.light.matrixWorld );
  24599. v2.setFromMatrixPosition( this.light.target.matrixWorld );
  24600. v3.subVectors( v2, v1 );
  24601. var lightPlane = this.children[ 0 ];
  24602. var targetLine = this.children[ 1 ];
  24603. lightPlane.lookAt( v3 );
  24604. lightPlane.material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  24605. targetLine.lookAt( v3 );
  24606. targetLine.scale.z = v3.length();
  24607. };
  24608. }();
  24609. // File:src/extras/helpers/EdgesHelper.js
  24610. /**
  24611. * @author WestLangley / http://github.com/WestLangley
  24612. * @param object THREE.Mesh whose geometry will be used
  24613. * @param hex line color
  24614. * @param thresholdAngle the minimum angle (in degrees),
  24615. * between the face normals of adjacent faces,
  24616. * that is required to render an edge. A value of 10 means
  24617. * an edge is only rendered if the angle is at least 10 degrees.
  24618. */
  24619. THREE.EdgesHelper = function ( object, hex, thresholdAngle ) {
  24620. var color = ( hex !== undefined ) ? hex : 0xffffff;
  24621. THREE.LineSegments.call( this, new THREE.EdgesGeometry( object.geometry, thresholdAngle ), new THREE.LineBasicMaterial( { color: color } ) );
  24622. this.matrix = object.matrixWorld;
  24623. this.matrixAutoUpdate = false;
  24624. };
  24625. THREE.EdgesHelper.prototype = Object.create( THREE.LineSegments.prototype );
  24626. THREE.EdgesHelper.prototype.constructor = THREE.EdgesHelper;
  24627. // File:src/extras/helpers/FaceNormalsHelper.js
  24628. /**
  24629. * @author mrdoob / http://mrdoob.com/
  24630. * @author WestLangley / http://github.com/WestLangley
  24631. */
  24632. THREE.FaceNormalsHelper = function ( object, size, hex, linewidth ) {
  24633. // FaceNormalsHelper only supports THREE.Geometry
  24634. this.object = object;
  24635. this.size = ( size !== undefined ) ? size : 1;
  24636. var color = ( hex !== undefined ) ? hex : 0xffff00;
  24637. var width = ( linewidth !== undefined ) ? linewidth : 1;
  24638. //
  24639. var nNormals = 0;
  24640. var objGeometry = this.object.geometry;
  24641. if ( objGeometry instanceof THREE.Geometry ) {
  24642. nNormals = objGeometry.faces.length;
  24643. } else {
  24644. console.warn( 'THREE.FaceNormalsHelper: only THREE.Geometry is supported. Use THREE.VertexNormalsHelper, instead.' );
  24645. }
  24646. //
  24647. var geometry = new THREE.BufferGeometry();
  24648. var positions = new THREE.Float32Attribute( nNormals * 2 * 3, 3 );
  24649. geometry.addAttribute( 'position', positions );
  24650. THREE.LineSegments.call( this, geometry, new THREE.LineBasicMaterial( { color: color, linewidth: width } ) );
  24651. //
  24652. this.matrixAutoUpdate = false;
  24653. this.update();
  24654. };
  24655. THREE.FaceNormalsHelper.prototype = Object.create( THREE.LineSegments.prototype );
  24656. THREE.FaceNormalsHelper.prototype.constructor = THREE.FaceNormalsHelper;
  24657. THREE.FaceNormalsHelper.prototype.update = ( function () {
  24658. var v1 = new THREE.Vector3();
  24659. var v2 = new THREE.Vector3();
  24660. var normalMatrix = new THREE.Matrix3();
  24661. return function update() {
  24662. this.object.updateMatrixWorld( true );
  24663. normalMatrix.getNormalMatrix( this.object.matrixWorld );
  24664. var matrixWorld = this.object.matrixWorld;
  24665. var position = this.geometry.attributes.position;
  24666. //
  24667. var objGeometry = this.object.geometry;
  24668. var vertices = objGeometry.vertices;
  24669. var faces = objGeometry.faces;
  24670. var idx = 0;
  24671. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  24672. var face = faces[ i ];
  24673. var normal = face.normal;
  24674. v1.copy( vertices[ face.a ] )
  24675. .add( vertices[ face.b ] )
  24676. .add( vertices[ face.c ] )
  24677. .divideScalar( 3 )
  24678. .applyMatrix4( matrixWorld );
  24679. v2.copy( normal ).applyMatrix3( normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
  24680. position.setXYZ( idx, v1.x, v1.y, v1.z );
  24681. idx = idx + 1;
  24682. position.setXYZ( idx, v2.x, v2.y, v2.z );
  24683. idx = idx + 1;
  24684. }
  24685. position.needsUpdate = true;
  24686. return this;
  24687. };
  24688. }() );
  24689. // File:src/extras/helpers/GridHelper.js
  24690. /**
  24691. * @author mrdoob / http://mrdoob.com/
  24692. */
  24693. THREE.GridHelper = function ( size, step, color1, color2 ) {
  24694. color1 = new THREE.Color( color1 !== undefined ? color1 : 0x444444 );
  24695. color2 = new THREE.Color( color2 !== undefined ? color2 : 0x888888 );
  24696. var vertices = [];
  24697. var colors = [];
  24698. for ( var i = - size, j = 0; i <= size; i += step ) {
  24699. vertices.push( - size, 0, i, size, 0, i );
  24700. vertices.push( i, 0, - size, i, 0, size );
  24701. var color = i === 0 ? color1 : color2;
  24702. color.toArray( colors, j ); j += 3;
  24703. color.toArray( colors, j ); j += 3;
  24704. color.toArray( colors, j ); j += 3;
  24705. color.toArray( colors, j ); j += 3;
  24706. }
  24707. var geometry = new THREE.BufferGeometry();
  24708. geometry.addAttribute( 'position', new THREE.Float32Attribute( vertices, 3 ) );
  24709. geometry.addAttribute( 'color', new THREE.Float32Attribute( colors, 3 ) );
  24710. var material = new THREE.LineBasicMaterial( { vertexColors: THREE.VertexColors } );
  24711. THREE.LineSegments.call( this, geometry, material );
  24712. };
  24713. THREE.GridHelper.prototype = Object.create( THREE.LineSegments.prototype );
  24714. THREE.GridHelper.prototype.constructor = THREE.GridHelper;
  24715. THREE.GridHelper.prototype.setColors = function () {
  24716. console.error( 'THREE.GridHelper: setColors() has been deprecated, pass them in the constructor instead.' );
  24717. };
  24718. // File:src/extras/helpers/HemisphereLightHelper.js
  24719. /**
  24720. * @author alteredq / http://alteredqualia.com/
  24721. * @author mrdoob / http://mrdoob.com/
  24722. */
  24723. THREE.HemisphereLightHelper = function ( light, sphereSize ) {
  24724. THREE.Object3D.call( this );
  24725. this.light = light;
  24726. this.light.updateMatrixWorld();
  24727. this.matrix = light.matrixWorld;
  24728. this.matrixAutoUpdate = false;
  24729. this.colors = [ new THREE.Color(), new THREE.Color() ];
  24730. var geometry = new THREE.SphereGeometry( sphereSize, 4, 2 );
  24731. geometry.rotateX( - Math.PI / 2 );
  24732. for ( var i = 0, il = 8; i < il; i ++ ) {
  24733. geometry.faces[ i ].color = this.colors[ i < 4 ? 0 : 1 ];
  24734. }
  24735. var material = new THREE.MeshBasicMaterial( { vertexColors: THREE.FaceColors, wireframe: true } );
  24736. this.lightSphere = new THREE.Mesh( geometry, material );
  24737. this.add( this.lightSphere );
  24738. this.update();
  24739. };
  24740. THREE.HemisphereLightHelper.prototype = Object.create( THREE.Object3D.prototype );
  24741. THREE.HemisphereLightHelper.prototype.constructor = THREE.HemisphereLightHelper;
  24742. THREE.HemisphereLightHelper.prototype.dispose = function () {
  24743. this.lightSphere.geometry.dispose();
  24744. this.lightSphere.material.dispose();
  24745. };
  24746. THREE.HemisphereLightHelper.prototype.update = function () {
  24747. var vector = new THREE.Vector3();
  24748. return function update() {
  24749. this.colors[ 0 ].copy( this.light.color ).multiplyScalar( this.light.intensity );
  24750. this.colors[ 1 ].copy( this.light.groundColor ).multiplyScalar( this.light.intensity );
  24751. this.lightSphere.lookAt( vector.setFromMatrixPosition( this.light.matrixWorld ).negate() );
  24752. this.lightSphere.geometry.colorsNeedUpdate = true;
  24753. };
  24754. }();
  24755. // File:src/extras/helpers/PointLightHelper.js
  24756. /**
  24757. * @author alteredq / http://alteredqualia.com/
  24758. * @author mrdoob / http://mrdoob.com/
  24759. */
  24760. THREE.PointLightHelper = function ( light, sphereSize ) {
  24761. this.light = light;
  24762. this.light.updateMatrixWorld();
  24763. var geometry = new THREE.SphereBufferGeometry( sphereSize, 4, 2 );
  24764. var material = new THREE.MeshBasicMaterial( { wireframe: true, fog: false } );
  24765. material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  24766. THREE.Mesh.call( this, geometry, material );
  24767. this.matrix = this.light.matrixWorld;
  24768. this.matrixAutoUpdate = false;
  24769. /*
  24770. var distanceGeometry = new THREE.IcosahedronGeometry( 1, 2 );
  24771. var distanceMaterial = new THREE.MeshBasicMaterial( { color: hexColor, fog: false, wireframe: true, opacity: 0.1, transparent: true } );
  24772. this.lightSphere = new THREE.Mesh( bulbGeometry, bulbMaterial );
  24773. this.lightDistance = new THREE.Mesh( distanceGeometry, distanceMaterial );
  24774. var d = light.distance;
  24775. if ( d === 0.0 ) {
  24776. this.lightDistance.visible = false;
  24777. } else {
  24778. this.lightDistance.scale.set( d, d, d );
  24779. }
  24780. this.add( this.lightDistance );
  24781. */
  24782. };
  24783. THREE.PointLightHelper.prototype = Object.create( THREE.Mesh.prototype );
  24784. THREE.PointLightHelper.prototype.constructor = THREE.PointLightHelper;
  24785. THREE.PointLightHelper.prototype.dispose = function () {
  24786. this.geometry.dispose();
  24787. this.material.dispose();
  24788. };
  24789. THREE.PointLightHelper.prototype.update = function () {
  24790. this.material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  24791. /*
  24792. var d = this.light.distance;
  24793. if ( d === 0.0 ) {
  24794. this.lightDistance.visible = false;
  24795. } else {
  24796. this.lightDistance.visible = true;
  24797. this.lightDistance.scale.set( d, d, d );
  24798. }
  24799. */
  24800. };
  24801. // File:src/extras/helpers/SkeletonHelper.js
  24802. /**
  24803. * @author Sean Griffin / http://twitter.com/sgrif
  24804. * @author Michael Guerrero / http://realitymeltdown.com
  24805. * @author mrdoob / http://mrdoob.com/
  24806. * @author ikerr / http://verold.com
  24807. */
  24808. THREE.SkeletonHelper = function ( object ) {
  24809. this.bones = this.getBoneList( object );
  24810. var geometry = new THREE.Geometry();
  24811. for ( var i = 0; i < this.bones.length; i ++ ) {
  24812. var bone = this.bones[ i ];
  24813. if ( bone.parent instanceof THREE.Bone ) {
  24814. geometry.vertices.push( new THREE.Vector3() );
  24815. geometry.vertices.push( new THREE.Vector3() );
  24816. geometry.colors.push( new THREE.Color( 0, 0, 1 ) );
  24817. geometry.colors.push( new THREE.Color( 0, 1, 0 ) );
  24818. }
  24819. }
  24820. geometry.dynamic = true;
  24821. var material = new THREE.LineBasicMaterial( { vertexColors: THREE.VertexColors, depthTest: false, depthWrite: false, transparent: true } );
  24822. THREE.LineSegments.call( this, geometry, material );
  24823. this.root = object;
  24824. this.matrix = object.matrixWorld;
  24825. this.matrixAutoUpdate = false;
  24826. this.update();
  24827. };
  24828. THREE.SkeletonHelper.prototype = Object.create( THREE.LineSegments.prototype );
  24829. THREE.SkeletonHelper.prototype.constructor = THREE.SkeletonHelper;
  24830. THREE.SkeletonHelper.prototype.getBoneList = function( object ) {
  24831. var boneList = [];
  24832. if ( object instanceof THREE.Bone ) {
  24833. boneList.push( object );
  24834. }
  24835. for ( var i = 0; i < object.children.length; i ++ ) {
  24836. boneList.push.apply( boneList, this.getBoneList( object.children[ i ] ) );
  24837. }
  24838. return boneList;
  24839. };
  24840. THREE.SkeletonHelper.prototype.update = function () {
  24841. var geometry = this.geometry;
  24842. var matrixWorldInv = new THREE.Matrix4().getInverse( this.root.matrixWorld );
  24843. var boneMatrix = new THREE.Matrix4();
  24844. var j = 0;
  24845. for ( var i = 0; i < this.bones.length; i ++ ) {
  24846. var bone = this.bones[ i ];
  24847. if ( bone.parent instanceof THREE.Bone ) {
  24848. boneMatrix.multiplyMatrices( matrixWorldInv, bone.matrixWorld );
  24849. geometry.vertices[ j ].setFromMatrixPosition( boneMatrix );
  24850. boneMatrix.multiplyMatrices( matrixWorldInv, bone.parent.matrixWorld );
  24851. geometry.vertices[ j + 1 ].setFromMatrixPosition( boneMatrix );
  24852. j += 2;
  24853. }
  24854. }
  24855. geometry.verticesNeedUpdate = true;
  24856. geometry.computeBoundingSphere();
  24857. };
  24858. // File:src/extras/helpers/SpotLightHelper.js
  24859. /**
  24860. * @author alteredq / http://alteredqualia.com/
  24861. * @author mrdoob / http://mrdoob.com/
  24862. * @author WestLangley / http://github.com/WestLangley
  24863. */
  24864. THREE.SpotLightHelper = function ( light ) {
  24865. THREE.Object3D.call( this );
  24866. this.light = light;
  24867. this.light.updateMatrixWorld();
  24868. this.matrix = light.matrixWorld;
  24869. this.matrixAutoUpdate = false;
  24870. var geometry = new THREE.BufferGeometry();
  24871. var positions = [
  24872. 0, 0, 0, 0, 0, 1,
  24873. 0, 0, 0, 1, 0, 1,
  24874. 0, 0, 0, - 1, 0, 1,
  24875. 0, 0, 0, 0, 1, 1,
  24876. 0, 0, 0, 0, - 1, 1
  24877. ];
  24878. for ( var i = 0, j = 1, l = 32; i < l; i ++, j ++ ) {
  24879. var p1 = ( i / l ) * Math.PI * 2;
  24880. var p2 = ( j / l ) * Math.PI * 2;
  24881. positions.push(
  24882. Math.cos( p1 ), Math.sin( p1 ), 1,
  24883. Math.cos( p2 ), Math.sin( p2 ), 1
  24884. );
  24885. }
  24886. geometry.addAttribute( 'position', new THREE.Float32Attribute( positions, 3 ) );
  24887. var material = new THREE.LineBasicMaterial( { fog: false } );
  24888. this.cone = new THREE.LineSegments( geometry, material );
  24889. this.add( this.cone );
  24890. this.update();
  24891. };
  24892. THREE.SpotLightHelper.prototype = Object.create( THREE.Object3D.prototype );
  24893. THREE.SpotLightHelper.prototype.constructor = THREE.SpotLightHelper;
  24894. THREE.SpotLightHelper.prototype.dispose = function () {
  24895. this.cone.geometry.dispose();
  24896. this.cone.material.dispose();
  24897. };
  24898. THREE.SpotLightHelper.prototype.update = function () {
  24899. var vector = new THREE.Vector3();
  24900. var vector2 = new THREE.Vector3();
  24901. return function update() {
  24902. var coneLength = this.light.distance ? this.light.distance : 1000;
  24903. var coneWidth = coneLength * Math.tan( this.light.angle );
  24904. this.cone.scale.set( coneWidth, coneWidth, coneLength );
  24905. vector.setFromMatrixPosition( this.light.matrixWorld );
  24906. vector2.setFromMatrixPosition( this.light.target.matrixWorld );
  24907. this.cone.lookAt( vector2.sub( vector ) );
  24908. this.cone.material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  24909. };
  24910. }();
  24911. // File:src/extras/helpers/VertexNormalsHelper.js
  24912. /**
  24913. * @author mrdoob / http://mrdoob.com/
  24914. * @author WestLangley / http://github.com/WestLangley
  24915. */
  24916. THREE.VertexNormalsHelper = function ( object, size, hex, linewidth ) {
  24917. this.object = object;
  24918. this.size = ( size !== undefined ) ? size : 1;
  24919. var color = ( hex !== undefined ) ? hex : 0xff0000;
  24920. var width = ( linewidth !== undefined ) ? linewidth : 1;
  24921. //
  24922. var nNormals = 0;
  24923. var objGeometry = this.object.geometry;
  24924. if ( objGeometry instanceof THREE.Geometry ) {
  24925. nNormals = objGeometry.faces.length * 3;
  24926. } else if ( objGeometry instanceof THREE.BufferGeometry ) {
  24927. nNormals = objGeometry.attributes.normal.count;
  24928. }
  24929. //
  24930. var geometry = new THREE.BufferGeometry();
  24931. var positions = new THREE.Float32Attribute( nNormals * 2 * 3, 3 );
  24932. geometry.addAttribute( 'position', positions );
  24933. THREE.LineSegments.call( this, geometry, new THREE.LineBasicMaterial( { color: color, linewidth: width } ) );
  24934. //
  24935. this.matrixAutoUpdate = false;
  24936. this.update();
  24937. };
  24938. THREE.VertexNormalsHelper.prototype = Object.create( THREE.LineSegments.prototype );
  24939. THREE.VertexNormalsHelper.prototype.constructor = THREE.VertexNormalsHelper;
  24940. THREE.VertexNormalsHelper.prototype.update = ( function () {
  24941. var v1 = new THREE.Vector3();
  24942. var v2 = new THREE.Vector3();
  24943. var normalMatrix = new THREE.Matrix3();
  24944. return function update() {
  24945. var keys = [ 'a', 'b', 'c' ];
  24946. this.object.updateMatrixWorld( true );
  24947. normalMatrix.getNormalMatrix( this.object.matrixWorld );
  24948. var matrixWorld = this.object.matrixWorld;
  24949. var position = this.geometry.attributes.position;
  24950. //
  24951. var objGeometry = this.object.geometry;
  24952. if ( objGeometry instanceof THREE.Geometry ) {
  24953. var vertices = objGeometry.vertices;
  24954. var faces = objGeometry.faces;
  24955. var idx = 0;
  24956. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  24957. var face = faces[ i ];
  24958. for ( var j = 0, jl = face.vertexNormals.length; j < jl; j ++ ) {
  24959. var vertex = vertices[ face[ keys[ j ] ] ];
  24960. var normal = face.vertexNormals[ j ];
  24961. v1.copy( vertex ).applyMatrix4( matrixWorld );
  24962. v2.copy( normal ).applyMatrix3( normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
  24963. position.setXYZ( idx, v1.x, v1.y, v1.z );
  24964. idx = idx + 1;
  24965. position.setXYZ( idx, v2.x, v2.y, v2.z );
  24966. idx = idx + 1;
  24967. }
  24968. }
  24969. } else if ( objGeometry instanceof THREE.BufferGeometry ) {
  24970. var objPos = objGeometry.attributes.position;
  24971. var objNorm = objGeometry.attributes.normal;
  24972. var idx = 0;
  24973. // for simplicity, ignore index and drawcalls, and render every normal
  24974. for ( var j = 0, jl = objPos.count; j < jl; j ++ ) {
  24975. v1.set( objPos.getX( j ), objPos.getY( j ), objPos.getZ( j ) ).applyMatrix4( matrixWorld );
  24976. v2.set( objNorm.getX( j ), objNorm.getY( j ), objNorm.getZ( j ) );
  24977. v2.applyMatrix3( normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
  24978. position.setXYZ( idx, v1.x, v1.y, v1.z );
  24979. idx = idx + 1;
  24980. position.setXYZ( idx, v2.x, v2.y, v2.z );
  24981. idx = idx + 1;
  24982. }
  24983. }
  24984. position.needsUpdate = true;
  24985. return this;
  24986. };
  24987. }() );
  24988. // File:src/extras/helpers/WireframeHelper.js
  24989. /**
  24990. * @author mrdoob / http://mrdoob.com/
  24991. */
  24992. THREE.WireframeHelper = function ( object, hex ) {
  24993. var color = ( hex !== undefined ) ? hex : 0xffffff;
  24994. THREE.LineSegments.call( this, new THREE.WireframeGeometry( object.geometry ), new THREE.LineBasicMaterial( { color: color } ) );
  24995. this.matrix = object.matrixWorld;
  24996. this.matrixAutoUpdate = false;
  24997. };
  24998. THREE.WireframeHelper.prototype = Object.create( THREE.LineSegments.prototype );
  24999. THREE.WireframeHelper.prototype.constructor = THREE.WireframeHelper;
  25000. // File:src/extras/objects/ImmediateRenderObject.js
  25001. /**
  25002. * @author alteredq / http://alteredqualia.com/
  25003. */
  25004. THREE.ImmediateRenderObject = function ( material ) {
  25005. THREE.Object3D.call( this );
  25006. this.material = material;
  25007. this.render = function ( renderCallback ) {};
  25008. };
  25009. THREE.ImmediateRenderObject.prototype = Object.create( THREE.Object3D.prototype );
  25010. THREE.ImmediateRenderObject.prototype.constructor = THREE.ImmediateRenderObject;
  25011. // File:src/extras/objects/MorphBlendMesh.js
  25012. /**
  25013. * @author alteredq / http://alteredqualia.com/
  25014. */
  25015. THREE.MorphBlendMesh = function( geometry, material ) {
  25016. THREE.Mesh.call( this, geometry, material );
  25017. this.animationsMap = {};
  25018. this.animationsList = [];
  25019. // prepare default animation
  25020. // (all frames played together in 1 second)
  25021. var numFrames = this.geometry.morphTargets.length;
  25022. var name = "__default";
  25023. var startFrame = 0;
  25024. var endFrame = numFrames - 1;
  25025. var fps = numFrames / 1;
  25026. this.createAnimation( name, startFrame, endFrame, fps );
  25027. this.setAnimationWeight( name, 1 );
  25028. };
  25029. THREE.MorphBlendMesh.prototype = Object.create( THREE.Mesh.prototype );
  25030. THREE.MorphBlendMesh.prototype.constructor = THREE.MorphBlendMesh;
  25031. THREE.MorphBlendMesh.prototype.createAnimation = function ( name, start, end, fps ) {
  25032. var animation = {
  25033. start: start,
  25034. end: end,
  25035. length: end - start + 1,
  25036. fps: fps,
  25037. duration: ( end - start ) / fps,
  25038. lastFrame: 0,
  25039. currentFrame: 0,
  25040. active: false,
  25041. time: 0,
  25042. direction: 1,
  25043. weight: 1,
  25044. directionBackwards: false,
  25045. mirroredLoop: false
  25046. };
  25047. this.animationsMap[ name ] = animation;
  25048. this.animationsList.push( animation );
  25049. };
  25050. THREE.MorphBlendMesh.prototype.autoCreateAnimations = function ( fps ) {
  25051. var pattern = /([a-z]+)_?(\d+)/i;
  25052. var firstAnimation, frameRanges = {};
  25053. var geometry = this.geometry;
  25054. for ( var i = 0, il = geometry.morphTargets.length; i < il; i ++ ) {
  25055. var morph = geometry.morphTargets[ i ];
  25056. var chunks = morph.name.match( pattern );
  25057. if ( chunks && chunks.length > 1 ) {
  25058. var name = chunks[ 1 ];
  25059. if ( ! frameRanges[ name ] ) frameRanges[ name ] = { start: Infinity, end: - Infinity };
  25060. var range = frameRanges[ name ];
  25061. if ( i < range.start ) range.start = i;
  25062. if ( i > range.end ) range.end = i;
  25063. if ( ! firstAnimation ) firstAnimation = name;
  25064. }
  25065. }
  25066. for ( var name in frameRanges ) {
  25067. var range = frameRanges[ name ];
  25068. this.createAnimation( name, range.start, range.end, fps );
  25069. }
  25070. this.firstAnimation = firstAnimation;
  25071. };
  25072. THREE.MorphBlendMesh.prototype.setAnimationDirectionForward = function ( name ) {
  25073. var animation = this.animationsMap[ name ];
  25074. if ( animation ) {
  25075. animation.direction = 1;
  25076. animation.directionBackwards = false;
  25077. }
  25078. };
  25079. THREE.MorphBlendMesh.prototype.setAnimationDirectionBackward = function ( name ) {
  25080. var animation = this.animationsMap[ name ];
  25081. if ( animation ) {
  25082. animation.direction = - 1;
  25083. animation.directionBackwards = true;
  25084. }
  25085. };
  25086. THREE.MorphBlendMesh.prototype.setAnimationFPS = function ( name, fps ) {
  25087. var animation = this.animationsMap[ name ];
  25088. if ( animation ) {
  25089. animation.fps = fps;
  25090. animation.duration = ( animation.end - animation.start ) / animation.fps;
  25091. }
  25092. };
  25093. THREE.MorphBlendMesh.prototype.setAnimationDuration = function ( name, duration ) {
  25094. var animation = this.animationsMap[ name ];
  25095. if ( animation ) {
  25096. animation.duration = duration;
  25097. animation.fps = ( animation.end - animation.start ) / animation.duration;
  25098. }
  25099. };
  25100. THREE.MorphBlendMesh.prototype.setAnimationWeight = function ( name, weight ) {
  25101. var animation = this.animationsMap[ name ];
  25102. if ( animation ) {
  25103. animation.weight = weight;
  25104. }
  25105. };
  25106. THREE.MorphBlendMesh.prototype.setAnimationTime = function ( name, time ) {
  25107. var animation = this.animationsMap[ name ];
  25108. if ( animation ) {
  25109. animation.time = time;
  25110. }
  25111. };
  25112. THREE.MorphBlendMesh.prototype.getAnimationTime = function ( name ) {
  25113. var time = 0;
  25114. var animation = this.animationsMap[ name ];
  25115. if ( animation ) {
  25116. time = animation.time;
  25117. }
  25118. return time;
  25119. };
  25120. THREE.MorphBlendMesh.prototype.getAnimationDuration = function ( name ) {
  25121. var duration = - 1;
  25122. var animation = this.animationsMap[ name ];
  25123. if ( animation ) {
  25124. duration = animation.duration;
  25125. }
  25126. return duration;
  25127. };
  25128. THREE.MorphBlendMesh.prototype.playAnimation = function ( name ) {
  25129. var animation = this.animationsMap[ name ];
  25130. if ( animation ) {
  25131. animation.time = 0;
  25132. animation.active = true;
  25133. } else {
  25134. console.warn( "THREE.MorphBlendMesh: animation[" + name + "] undefined in .playAnimation()" );
  25135. }
  25136. };
  25137. THREE.MorphBlendMesh.prototype.stopAnimation = function ( name ) {
  25138. var animation = this.animationsMap[ name ];
  25139. if ( animation ) {
  25140. animation.active = false;
  25141. }
  25142. };
  25143. THREE.MorphBlendMesh.prototype.update = function ( delta ) {
  25144. for ( var i = 0, il = this.animationsList.length; i < il; i ++ ) {
  25145. var animation = this.animationsList[ i ];
  25146. if ( ! animation.active ) continue;
  25147. var frameTime = animation.duration / animation.length;
  25148. animation.time += animation.direction * delta;
  25149. if ( animation.mirroredLoop ) {
  25150. if ( animation.time > animation.duration || animation.time < 0 ) {
  25151. animation.direction *= - 1;
  25152. if ( animation.time > animation.duration ) {
  25153. animation.time = animation.duration;
  25154. animation.directionBackwards = true;
  25155. }
  25156. if ( animation.time < 0 ) {
  25157. animation.time = 0;
  25158. animation.directionBackwards = false;
  25159. }
  25160. }
  25161. } else {
  25162. animation.time = animation.time % animation.duration;
  25163. if ( animation.time < 0 ) animation.time += animation.duration;
  25164. }
  25165. var keyframe = animation.start + THREE.Math.clamp( Math.floor( animation.time / frameTime ), 0, animation.length - 1 );
  25166. var weight = animation.weight;
  25167. if ( keyframe !== animation.currentFrame ) {
  25168. this.morphTargetInfluences[ animation.lastFrame ] = 0;
  25169. this.morphTargetInfluences[ animation.currentFrame ] = 1 * weight;
  25170. this.morphTargetInfluences[ keyframe ] = 0;
  25171. animation.lastFrame = animation.currentFrame;
  25172. animation.currentFrame = keyframe;
  25173. }
  25174. var mix = ( animation.time % frameTime ) / frameTime;
  25175. if ( animation.directionBackwards ) mix = 1 - mix;
  25176. if ( animation.currentFrame !== animation.lastFrame ) {
  25177. this.morphTargetInfluences[ animation.currentFrame ] = mix * weight;
  25178. this.morphTargetInfluences[ animation.lastFrame ] = ( 1 - mix ) * weight;
  25179. } else {
  25180. this.morphTargetInfluences[ animation.currentFrame ] = weight;
  25181. }
  25182. }
  25183. };