three.js 1.1 MB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234242352423624237242382423924240242412424224243242442424524246242472424824249242502425124252242532425424255242562425724258242592426024261242622426324264242652426624267242682426924270242712427224273242742427524276242772427824279242802428124282242832428424285242862428724288242892429024291242922429324294242952429624297242982429924300243012430224303243042430524306243072430824309243102431124312243132431424315243162431724318243192432024321243222432324324243252432624327243282432924330243312433224333243342433524336243372433824339243402434124342243432434424345243462434724348243492435024351243522435324354243552435624357243582435924360243612436224363243642436524366243672436824369243702437124372243732437424375243762437724378243792438024381243822438324384243852438624387243882438924390243912439224393243942439524396243972439824399244002440124402244032440424405244062440724408244092441024411244122441324414244152441624417244182441924420244212442224423244242442524426244272442824429244302443124432244332443424435244362443724438244392444024441244422444324444244452444624447244482444924450244512445224453244542445524456244572445824459244602446124462244632446424465244662446724468244692447024471244722447324474244752447624477244782447924480244812448224483244842448524486244872448824489244902449124492244932449424495244962449724498244992450024501245022450324504245052450624507245082450924510245112451224513245142451524516245172451824519245202452124522245232452424525245262452724528245292453024531245322453324534245352453624537245382453924540245412454224543245442454524546245472454824549245502455124552245532455424555245562455724558245592456024561245622456324564245652456624567245682456924570245712457224573245742457524576245772457824579245802458124582245832458424585245862458724588245892459024591245922459324594245952459624597245982459924600246012460224603246042460524606246072460824609246102461124612246132461424615246162461724618246192462024621246222462324624246252462624627246282462924630246312463224633246342463524636246372463824639246402464124642246432464424645246462464724648246492465024651246522465324654246552465624657246582465924660246612466224663246642466524666246672466824669246702467124672246732467424675246762467724678246792468024681246822468324684246852468624687246882468924690246912469224693246942469524696246972469824699247002470124702247032470424705247062470724708247092471024711247122471324714247152471624717247182471924720247212472224723247242472524726247272472824729247302473124732247332473424735247362473724738247392474024741247422474324744247452474624747247482474924750247512475224753247542475524756247572475824759247602476124762247632476424765247662476724768247692477024771247722477324774247752477624777247782477924780247812478224783247842478524786247872478824789247902479124792247932479424795247962479724798247992480024801248022480324804248052480624807248082480924810248112481224813248142481524816248172481824819248202482124822248232482424825248262482724828248292483024831248322483324834248352483624837248382483924840248412484224843248442484524846248472484824849248502485124852248532485424855248562485724858248592486024861248622486324864248652486624867248682486924870248712487224873248742487524876248772487824879248802488124882248832488424885248862488724888248892489024891248922489324894248952489624897248982489924900249012490224903249042490524906249072490824909249102491124912249132491424915249162491724918249192492024921249222492324924249252492624927249282492924930249312493224933249342493524936249372493824939249402494124942249432494424945249462494724948249492495024951249522495324954249552495624957249582495924960249612496224963249642496524966249672496824969249702497124972249732497424975249762497724978249792498024981249822498324984249852498624987249882498924990249912499224993249942499524996249972499824999250002500125002250032500425005250062500725008250092501025011250122501325014250152501625017250182501925020250212502225023250242502525026250272502825029250302503125032250332503425035250362503725038250392504025041250422504325044250452504625047250482504925050250512505225053250542505525056250572505825059250602506125062250632506425065250662506725068250692507025071250722507325074250752507625077250782507925080250812508225083250842508525086250872508825089250902509125092250932509425095250962509725098250992510025101251022510325104251052510625107251082510925110251112511225113251142511525116251172511825119251202512125122251232512425125251262512725128251292513025131251322513325134251352513625137251382513925140251412514225143251442514525146251472514825149251502515125152251532515425155251562515725158251592516025161251622516325164251652516625167251682516925170251712517225173251742517525176251772517825179251802518125182251832518425185251862518725188251892519025191251922519325194251952519625197251982519925200252012520225203252042520525206252072520825209252102521125212252132521425215252162521725218252192522025221252222522325224252252522625227252282522925230252312523225233252342523525236252372523825239252402524125242252432524425245252462524725248252492525025251252522525325254252552525625257252582525925260252612526225263252642526525266252672526825269252702527125272252732527425275252762527725278252792528025281252822528325284252852528625287252882528925290252912529225293252942529525296252972529825299253002530125302253032530425305253062530725308253092531025311253122531325314253152531625317253182531925320253212532225323253242532525326253272532825329253302533125332253332533425335253362533725338253392534025341253422534325344253452534625347253482534925350253512535225353253542535525356253572535825359253602536125362253632536425365253662536725368253692537025371253722537325374253752537625377253782537925380253812538225383253842538525386253872538825389253902539125392253932539425395253962539725398253992540025401254022540325404254052540625407254082540925410254112541225413254142541525416254172541825419254202542125422254232542425425254262542725428254292543025431254322543325434254352543625437254382543925440254412544225443254442544525446254472544825449254502545125452254532545425455254562545725458254592546025461254622546325464254652546625467254682546925470254712547225473254742547525476254772547825479254802548125482254832548425485254862548725488254892549025491254922549325494254952549625497254982549925500255012550225503255042550525506255072550825509255102551125512255132551425515255162551725518255192552025521255222552325524255252552625527255282552925530255312553225533255342553525536255372553825539255402554125542255432554425545255462554725548255492555025551255522555325554255552555625557255582555925560255612556225563255642556525566255672556825569255702557125572255732557425575255762557725578255792558025581255822558325584255852558625587255882558925590255912559225593255942559525596255972559825599256002560125602256032560425605256062560725608256092561025611256122561325614256152561625617256182561925620256212562225623256242562525626256272562825629256302563125632256332563425635256362563725638256392564025641256422564325644256452564625647256482564925650256512565225653256542565525656256572565825659256602566125662256632566425665256662566725668256692567025671256722567325674256752567625677256782567925680256812568225683256842568525686256872568825689256902569125692256932569425695256962569725698256992570025701257022570325704257052570625707257082570925710257112571225713257142571525716257172571825719257202572125722257232572425725257262572725728257292573025731257322573325734257352573625737257382573925740257412574225743257442574525746257472574825749257502575125752257532575425755257562575725758257592576025761257622576325764257652576625767257682576925770257712577225773257742577525776257772577825779257802578125782257832578425785257862578725788257892579025791257922579325794257952579625797257982579925800258012580225803258042580525806258072580825809258102581125812258132581425815258162581725818258192582025821258222582325824258252582625827258282582925830258312583225833258342583525836258372583825839258402584125842258432584425845258462584725848258492585025851258522585325854258552585625857258582585925860258612586225863258642586525866258672586825869258702587125872258732587425875258762587725878258792588025881258822588325884258852588625887258882588925890258912589225893258942589525896258972589825899259002590125902259032590425905259062590725908259092591025911259122591325914259152591625917259182591925920259212592225923259242592525926259272592825929259302593125932259332593425935259362593725938259392594025941259422594325944259452594625947259482594925950259512595225953259542595525956259572595825959259602596125962259632596425965259662596725968259692597025971259722597325974259752597625977259782597925980259812598225983259842598525986259872598825989259902599125992259932599425995259962599725998259992600026001260022600326004260052600626007260082600926010260112601226013260142601526016260172601826019260202602126022260232602426025260262602726028260292603026031260322603326034260352603626037260382603926040260412604226043260442604526046260472604826049260502605126052260532605426055260562605726058260592606026061260622606326064260652606626067260682606926070260712607226073260742607526076260772607826079260802608126082260832608426085260862608726088260892609026091260922609326094260952609626097260982609926100261012610226103261042610526106261072610826109261102611126112261132611426115261162611726118261192612026121261222612326124261252612626127261282612926130261312613226133261342613526136261372613826139261402614126142261432614426145261462614726148261492615026151261522615326154261552615626157261582615926160261612616226163261642616526166261672616826169261702617126172261732617426175261762617726178261792618026181261822618326184261852618626187261882618926190261912619226193261942619526196261972619826199262002620126202262032620426205262062620726208262092621026211262122621326214262152621626217262182621926220262212622226223262242622526226262272622826229262302623126232262332623426235262362623726238262392624026241262422624326244262452624626247262482624926250262512625226253262542625526256262572625826259262602626126262262632626426265262662626726268262692627026271262722627326274262752627626277262782627926280262812628226283262842628526286262872628826289262902629126292262932629426295262962629726298262992630026301263022630326304263052630626307263082630926310263112631226313263142631526316263172631826319263202632126322263232632426325263262632726328263292633026331263322633326334263352633626337263382633926340263412634226343263442634526346263472634826349263502635126352263532635426355263562635726358263592636026361263622636326364263652636626367263682636926370263712637226373263742637526376263772637826379263802638126382263832638426385263862638726388263892639026391263922639326394263952639626397263982639926400264012640226403264042640526406264072640826409264102641126412264132641426415264162641726418264192642026421264222642326424264252642626427264282642926430264312643226433264342643526436264372643826439264402644126442264432644426445264462644726448264492645026451264522645326454264552645626457264582645926460264612646226463264642646526466264672646826469264702647126472264732647426475264762647726478264792648026481264822648326484264852648626487264882648926490264912649226493264942649526496264972649826499265002650126502265032650426505265062650726508265092651026511265122651326514265152651626517265182651926520265212652226523265242652526526265272652826529265302653126532265332653426535265362653726538265392654026541265422654326544265452654626547265482654926550265512655226553265542655526556265572655826559265602656126562265632656426565265662656726568265692657026571265722657326574265752657626577265782657926580265812658226583265842658526586265872658826589265902659126592265932659426595265962659726598265992660026601266022660326604266052660626607266082660926610266112661226613266142661526616266172661826619266202662126622266232662426625266262662726628266292663026631266322663326634266352663626637266382663926640266412664226643266442664526646266472664826649266502665126652266532665426655266562665726658266592666026661266622666326664266652666626667266682666926670266712667226673266742667526676266772667826679266802668126682266832668426685266862668726688266892669026691266922669326694266952669626697266982669926700267012670226703267042670526706267072670826709267102671126712267132671426715267162671726718267192672026721267222672326724267252672626727267282672926730267312673226733267342673526736267372673826739267402674126742267432674426745267462674726748267492675026751267522675326754267552675626757267582675926760267612676226763267642676526766267672676826769267702677126772267732677426775267762677726778267792678026781267822678326784267852678626787267882678926790267912679226793267942679526796267972679826799268002680126802268032680426805268062680726808268092681026811268122681326814268152681626817268182681926820268212682226823268242682526826268272682826829268302683126832268332683426835268362683726838268392684026841268422684326844268452684626847268482684926850268512685226853268542685526856268572685826859268602686126862268632686426865268662686726868268692687026871268722687326874268752687626877268782687926880268812688226883268842688526886268872688826889268902689126892268932689426895268962689726898268992690026901269022690326904269052690626907269082690926910269112691226913269142691526916269172691826919269202692126922269232692426925269262692726928269292693026931269322693326934269352693626937269382693926940269412694226943269442694526946269472694826949269502695126952269532695426955269562695726958269592696026961269622696326964269652696626967269682696926970269712697226973269742697526976269772697826979269802698126982269832698426985269862698726988269892699026991269922699326994269952699626997269982699927000270012700227003270042700527006270072700827009270102701127012270132701427015270162701727018270192702027021270222702327024270252702627027270282702927030270312703227033270342703527036270372703827039270402704127042270432704427045270462704727048270492705027051270522705327054270552705627057270582705927060270612706227063270642706527066270672706827069270702707127072270732707427075270762707727078270792708027081270822708327084270852708627087270882708927090270912709227093270942709527096270972709827099271002710127102271032710427105271062710727108271092711027111271122711327114271152711627117271182711927120271212712227123271242712527126271272712827129271302713127132271332713427135271362713727138271392714027141271422714327144271452714627147271482714927150271512715227153271542715527156271572715827159271602716127162271632716427165271662716727168271692717027171271722717327174271752717627177271782717927180271812718227183271842718527186271872718827189271902719127192271932719427195271962719727198271992720027201272022720327204272052720627207272082720927210272112721227213272142721527216272172721827219272202722127222272232722427225272262722727228272292723027231272322723327234272352723627237272382723927240272412724227243272442724527246272472724827249272502725127252272532725427255272562725727258272592726027261272622726327264272652726627267272682726927270272712727227273272742727527276272772727827279272802728127282272832728427285272862728727288272892729027291272922729327294272952729627297272982729927300273012730227303273042730527306273072730827309273102731127312273132731427315273162731727318273192732027321273222732327324273252732627327273282732927330273312733227333273342733527336273372733827339273402734127342273432734427345273462734727348273492735027351273522735327354273552735627357273582735927360273612736227363273642736527366273672736827369273702737127372273732737427375273762737727378273792738027381273822738327384273852738627387273882738927390273912739227393273942739527396273972739827399274002740127402274032740427405274062740727408274092741027411274122741327414274152741627417274182741927420274212742227423274242742527426274272742827429274302743127432274332743427435274362743727438274392744027441274422744327444274452744627447274482744927450274512745227453274542745527456274572745827459274602746127462274632746427465274662746727468274692747027471274722747327474274752747627477274782747927480274812748227483274842748527486274872748827489274902749127492274932749427495274962749727498274992750027501275022750327504275052750627507275082750927510275112751227513275142751527516275172751827519275202752127522275232752427525275262752727528275292753027531275322753327534275352753627537275382753927540275412754227543275442754527546275472754827549275502755127552275532755427555275562755727558275592756027561275622756327564275652756627567275682756927570275712757227573275742757527576275772757827579275802758127582275832758427585275862758727588275892759027591275922759327594275952759627597275982759927600276012760227603276042760527606276072760827609276102761127612276132761427615276162761727618276192762027621276222762327624276252762627627276282762927630276312763227633276342763527636276372763827639276402764127642276432764427645276462764727648276492765027651276522765327654276552765627657276582765927660276612766227663276642766527666276672766827669276702767127672276732767427675276762767727678276792768027681276822768327684276852768627687276882768927690276912769227693276942769527696276972769827699277002770127702277032770427705277062770727708277092771027711277122771327714277152771627717277182771927720277212772227723277242772527726277272772827729277302773127732277332773427735277362773727738277392774027741277422774327744277452774627747277482774927750277512775227753277542775527756277572775827759277602776127762277632776427765277662776727768277692777027771277722777327774277752777627777277782777927780277812778227783277842778527786277872778827789277902779127792277932779427795277962779727798277992780027801278022780327804278052780627807278082780927810278112781227813278142781527816278172781827819278202782127822278232782427825278262782727828278292783027831278322783327834278352783627837278382783927840278412784227843278442784527846278472784827849278502785127852278532785427855278562785727858278592786027861278622786327864278652786627867278682786927870278712787227873278742787527876278772787827879278802788127882278832788427885278862788727888278892789027891278922789327894278952789627897278982789927900279012790227903279042790527906279072790827909279102791127912279132791427915279162791727918279192792027921279222792327924279252792627927279282792927930279312793227933279342793527936279372793827939279402794127942279432794427945279462794727948279492795027951279522795327954279552795627957279582795927960279612796227963279642796527966279672796827969279702797127972279732797427975279762797727978279792798027981279822798327984279852798627987279882798927990279912799227993279942799527996279972799827999280002800128002280032800428005280062800728008280092801028011280122801328014280152801628017280182801928020280212802228023280242802528026280272802828029280302803128032280332803428035280362803728038280392804028041280422804328044280452804628047280482804928050280512805228053280542805528056280572805828059280602806128062280632806428065280662806728068280692807028071280722807328074280752807628077280782807928080280812808228083280842808528086280872808828089280902809128092280932809428095280962809728098280992810028101281022810328104281052810628107281082810928110281112811228113281142811528116281172811828119281202812128122281232812428125281262812728128281292813028131281322813328134281352813628137281382813928140281412814228143281442814528146281472814828149281502815128152281532815428155281562815728158281592816028161281622816328164281652816628167281682816928170281712817228173281742817528176281772817828179281802818128182281832818428185281862818728188281892819028191281922819328194281952819628197281982819928200282012820228203282042820528206282072820828209282102821128212282132821428215282162821728218282192822028221282222822328224282252822628227282282822928230282312823228233282342823528236282372823828239282402824128242282432824428245282462824728248282492825028251282522825328254282552825628257282582825928260282612826228263282642826528266282672826828269282702827128272282732827428275282762827728278282792828028281282822828328284282852828628287282882828928290282912829228293282942829528296282972829828299283002830128302283032830428305283062830728308283092831028311283122831328314283152831628317283182831928320283212832228323283242832528326283272832828329283302833128332283332833428335283362833728338283392834028341283422834328344283452834628347283482834928350283512835228353283542835528356283572835828359283602836128362283632836428365283662836728368283692837028371283722837328374283752837628377283782837928380283812838228383283842838528386283872838828389283902839128392283932839428395283962839728398283992840028401284022840328404284052840628407284082840928410284112841228413284142841528416284172841828419284202842128422284232842428425284262842728428284292843028431284322843328434284352843628437284382843928440284412844228443284442844528446284472844828449284502845128452284532845428455284562845728458284592846028461284622846328464284652846628467284682846928470284712847228473284742847528476284772847828479284802848128482284832848428485284862848728488284892849028491284922849328494284952849628497284982849928500285012850228503285042850528506285072850828509285102851128512285132851428515285162851728518285192852028521285222852328524285252852628527285282852928530285312853228533285342853528536285372853828539285402854128542285432854428545285462854728548285492855028551285522855328554285552855628557285582855928560285612856228563285642856528566285672856828569285702857128572285732857428575285762857728578285792858028581285822858328584285852858628587285882858928590285912859228593285942859528596285972859828599286002860128602286032860428605286062860728608286092861028611286122861328614286152861628617286182861928620286212862228623286242862528626286272862828629286302863128632286332863428635286362863728638286392864028641286422864328644286452864628647286482864928650286512865228653286542865528656286572865828659286602866128662286632866428665286662866728668286692867028671286722867328674286752867628677286782867928680286812868228683286842868528686286872868828689286902869128692286932869428695286962869728698286992870028701287022870328704287052870628707287082870928710287112871228713287142871528716287172871828719287202872128722287232872428725287262872728728287292873028731287322873328734287352873628737287382873928740287412874228743287442874528746287472874828749287502875128752287532875428755287562875728758287592876028761287622876328764287652876628767287682876928770287712877228773287742877528776287772877828779287802878128782287832878428785287862878728788287892879028791287922879328794287952879628797287982879928800288012880228803288042880528806288072880828809288102881128812288132881428815288162881728818288192882028821288222882328824288252882628827288282882928830288312883228833288342883528836288372883828839288402884128842288432884428845288462884728848288492885028851288522885328854288552885628857288582885928860288612886228863288642886528866288672886828869288702887128872288732887428875288762887728878288792888028881288822888328884288852888628887288882888928890288912889228893288942889528896288972889828899289002890128902289032890428905289062890728908289092891028911289122891328914289152891628917289182891928920289212892228923289242892528926289272892828929289302893128932289332893428935289362893728938289392894028941289422894328944289452894628947289482894928950289512895228953289542895528956289572895828959289602896128962289632896428965289662896728968289692897028971289722897328974289752897628977289782897928980289812898228983289842898528986289872898828989289902899128992289932899428995289962899728998289992900029001290022900329004290052900629007290082900929010290112901229013290142901529016290172901829019290202902129022290232902429025290262902729028290292903029031290322903329034290352903629037290382903929040290412904229043290442904529046290472904829049290502905129052290532905429055290562905729058290592906029061290622906329064290652906629067290682906929070290712907229073290742907529076290772907829079290802908129082290832908429085290862908729088290892909029091290922909329094290952909629097290982909929100291012910229103291042910529106291072910829109291102911129112291132911429115291162911729118291192912029121291222912329124291252912629127291282912929130291312913229133291342913529136291372913829139291402914129142291432914429145291462914729148291492915029151291522915329154291552915629157291582915929160291612916229163291642916529166291672916829169291702917129172291732917429175291762917729178291792918029181291822918329184291852918629187291882918929190291912919229193291942919529196291972919829199292002920129202292032920429205292062920729208292092921029211292122921329214292152921629217292182921929220292212922229223292242922529226292272922829229292302923129232292332923429235292362923729238292392924029241292422924329244292452924629247292482924929250292512925229253292542925529256292572925829259292602926129262292632926429265292662926729268292692927029271292722927329274292752927629277292782927929280292812928229283292842928529286292872928829289292902929129292292932929429295292962929729298292992930029301293022930329304293052930629307293082930929310293112931229313293142931529316293172931829319293202932129322293232932429325293262932729328293292933029331293322933329334293352933629337293382933929340293412934229343293442934529346293472934829349293502935129352293532935429355293562935729358293592936029361293622936329364293652936629367293682936929370293712937229373293742937529376293772937829379293802938129382293832938429385293862938729388293892939029391293922939329394293952939629397293982939929400294012940229403294042940529406294072940829409294102941129412294132941429415294162941729418294192942029421294222942329424294252942629427294282942929430294312943229433294342943529436294372943829439294402944129442294432944429445294462944729448294492945029451294522945329454294552945629457294582945929460294612946229463294642946529466294672946829469294702947129472294732947429475294762947729478294792948029481294822948329484294852948629487294882948929490294912949229493294942949529496294972949829499295002950129502295032950429505295062950729508295092951029511295122951329514295152951629517295182951929520295212952229523295242952529526295272952829529295302953129532295332953429535295362953729538295392954029541295422954329544295452954629547295482954929550295512955229553295542955529556295572955829559295602956129562295632956429565295662956729568295692957029571295722957329574295752957629577295782957929580295812958229583295842958529586295872958829589295902959129592295932959429595295962959729598295992960029601296022960329604296052960629607296082960929610296112961229613296142961529616296172961829619296202962129622296232962429625296262962729628296292963029631296322963329634296352963629637296382963929640296412964229643296442964529646296472964829649296502965129652296532965429655296562965729658296592966029661296622966329664296652966629667296682966929670296712967229673296742967529676296772967829679296802968129682296832968429685296862968729688296892969029691296922969329694296952969629697296982969929700297012970229703297042970529706297072970829709297102971129712297132971429715297162971729718297192972029721297222972329724297252972629727297282972929730297312973229733297342973529736297372973829739297402974129742297432974429745297462974729748297492975029751297522975329754297552975629757297582975929760297612976229763297642976529766297672976829769297702977129772297732977429775297762977729778297792978029781297822978329784297852978629787297882978929790297912979229793297942979529796297972979829799298002980129802298032980429805298062980729808298092981029811298122981329814298152981629817298182981929820298212982229823298242982529826298272982829829298302983129832298332983429835298362983729838298392984029841298422984329844298452984629847298482984929850298512985229853298542985529856298572985829859298602986129862298632986429865298662986729868298692987029871298722987329874298752987629877298782987929880298812988229883298842988529886298872988829889298902989129892298932989429895298962989729898298992990029901299022990329904299052990629907299082990929910299112991229913299142991529916299172991829919299202992129922299232992429925299262992729928299292993029931299322993329934299352993629937299382993929940299412994229943299442994529946299472994829949299502995129952299532995429955299562995729958299592996029961299622996329964299652996629967299682996929970299712997229973299742997529976299772997829979299802998129982299832998429985299862998729988299892999029991299922999329994299952999629997299982999930000300013000230003300043000530006300073000830009300103001130012300133001430015300163001730018300193002030021300223002330024300253002630027300283002930030300313003230033300343003530036300373003830039300403004130042300433004430045300463004730048300493005030051300523005330054300553005630057300583005930060300613006230063300643006530066300673006830069300703007130072300733007430075300763007730078300793008030081300823008330084300853008630087300883008930090300913009230093300943009530096300973009830099301003010130102301033010430105301063010730108301093011030111301123011330114301153011630117301183011930120301213012230123301243012530126301273012830129301303013130132301333013430135301363013730138301393014030141301423014330144301453014630147301483014930150301513015230153301543015530156301573015830159301603016130162301633016430165301663016730168301693017030171301723017330174301753017630177301783017930180301813018230183301843018530186301873018830189301903019130192301933019430195301963019730198301993020030201302023020330204302053020630207302083020930210302113021230213302143021530216302173021830219302203022130222302233022430225302263022730228302293023030231302323023330234302353023630237302383023930240302413024230243302443024530246302473024830249302503025130252302533025430255302563025730258302593026030261302623026330264302653026630267302683026930270302713027230273302743027530276302773027830279302803028130282302833028430285302863028730288302893029030291302923029330294302953029630297302983029930300303013030230303303043030530306303073030830309303103031130312303133031430315303163031730318303193032030321303223032330324303253032630327303283032930330303313033230333303343033530336303373033830339303403034130342303433034430345303463034730348303493035030351303523035330354303553035630357303583035930360303613036230363303643036530366303673036830369303703037130372303733037430375303763037730378303793038030381303823038330384303853038630387303883038930390303913039230393303943039530396303973039830399304003040130402304033040430405304063040730408304093041030411304123041330414304153041630417304183041930420304213042230423304243042530426304273042830429304303043130432304333043430435304363043730438304393044030441304423044330444304453044630447304483044930450304513045230453304543045530456304573045830459304603046130462304633046430465304663046730468304693047030471304723047330474304753047630477304783047930480304813048230483304843048530486304873048830489304903049130492304933049430495304963049730498304993050030501305023050330504305053050630507305083050930510305113051230513305143051530516305173051830519305203052130522305233052430525305263052730528305293053030531305323053330534305353053630537305383053930540305413054230543305443054530546305473054830549305503055130552305533055430555305563055730558305593056030561305623056330564305653056630567305683056930570305713057230573305743057530576305773057830579305803058130582305833058430585305863058730588305893059030591305923059330594305953059630597305983059930600306013060230603306043060530606306073060830609306103061130612306133061430615306163061730618306193062030621306223062330624306253062630627306283062930630306313063230633306343063530636306373063830639306403064130642306433064430645306463064730648306493065030651306523065330654306553065630657306583065930660306613066230663306643066530666306673066830669306703067130672306733067430675306763067730678306793068030681306823068330684306853068630687306883068930690306913069230693306943069530696306973069830699307003070130702307033070430705307063070730708307093071030711307123071330714307153071630717307183071930720307213072230723307243072530726307273072830729307303073130732307333073430735307363073730738307393074030741307423074330744307453074630747307483074930750307513075230753307543075530756307573075830759307603076130762307633076430765307663076730768307693077030771307723077330774307753077630777307783077930780307813078230783307843078530786307873078830789307903079130792307933079430795307963079730798307993080030801308023080330804308053080630807308083080930810308113081230813308143081530816308173081830819308203082130822308233082430825308263082730828308293083030831308323083330834308353083630837308383083930840308413084230843308443084530846308473084830849308503085130852308533085430855308563085730858308593086030861308623086330864308653086630867308683086930870308713087230873308743087530876308773087830879308803088130882308833088430885308863088730888308893089030891308923089330894308953089630897308983089930900309013090230903309043090530906309073090830909309103091130912309133091430915309163091730918309193092030921309223092330924309253092630927309283092930930309313093230933309343093530936309373093830939309403094130942309433094430945309463094730948309493095030951309523095330954309553095630957309583095930960309613096230963309643096530966309673096830969309703097130972309733097430975309763097730978309793098030981309823098330984309853098630987309883098930990309913099230993309943099530996309973099830999310003100131002310033100431005310063100731008310093101031011310123101331014310153101631017310183101931020310213102231023310243102531026310273102831029310303103131032310333103431035310363103731038310393104031041310423104331044310453104631047310483104931050310513105231053310543105531056310573105831059310603106131062310633106431065310663106731068310693107031071310723107331074310753107631077310783107931080310813108231083310843108531086310873108831089310903109131092310933109431095310963109731098310993110031101311023110331104311053110631107311083110931110311113111231113311143111531116311173111831119311203112131122311233112431125311263112731128311293113031131311323113331134311353113631137311383113931140311413114231143311443114531146311473114831149311503115131152311533115431155311563115731158311593116031161311623116331164311653116631167311683116931170311713117231173311743117531176311773117831179311803118131182311833118431185311863118731188311893119031191311923119331194311953119631197311983119931200312013120231203312043120531206312073120831209312103121131212312133121431215312163121731218312193122031221312223122331224312253122631227312283122931230312313123231233312343123531236312373123831239312403124131242312433124431245312463124731248312493125031251312523125331254312553125631257312583125931260312613126231263312643126531266312673126831269312703127131272312733127431275312763127731278312793128031281312823128331284312853128631287312883128931290312913129231293312943129531296312973129831299313003130131302313033130431305313063130731308313093131031311313123131331314313153131631317313183131931320313213132231323313243132531326313273132831329313303133131332313333133431335313363133731338313393134031341313423134331344313453134631347313483134931350313513135231353313543135531356313573135831359313603136131362313633136431365313663136731368313693137031371313723137331374313753137631377313783137931380313813138231383313843138531386313873138831389313903139131392313933139431395313963139731398313993140031401314023140331404314053140631407314083140931410314113141231413314143141531416314173141831419314203142131422314233142431425314263142731428314293143031431314323143331434314353143631437314383143931440314413144231443314443144531446314473144831449314503145131452314533145431455314563145731458314593146031461314623146331464314653146631467314683146931470314713147231473314743147531476314773147831479314803148131482314833148431485314863148731488314893149031491314923149331494314953149631497314983149931500315013150231503315043150531506315073150831509315103151131512315133151431515315163151731518315193152031521315223152331524315253152631527315283152931530315313153231533315343153531536315373153831539315403154131542315433154431545315463154731548315493155031551315523155331554315553155631557315583155931560315613156231563315643156531566315673156831569315703157131572315733157431575315763157731578315793158031581315823158331584315853158631587315883158931590315913159231593315943159531596315973159831599316003160131602316033160431605316063160731608316093161031611316123161331614316153161631617316183161931620316213162231623316243162531626316273162831629316303163131632316333163431635316363163731638316393164031641316423164331644316453164631647316483164931650316513165231653316543165531656316573165831659316603166131662316633166431665316663166731668316693167031671316723167331674316753167631677316783167931680316813168231683316843168531686316873168831689316903169131692316933169431695316963169731698316993170031701317023170331704317053170631707317083170931710317113171231713317143171531716317173171831719317203172131722317233172431725317263172731728317293173031731317323173331734317353173631737317383173931740317413174231743317443174531746317473174831749317503175131752317533175431755317563175731758317593176031761317623176331764317653176631767317683176931770317713177231773317743177531776317773177831779317803178131782317833178431785317863178731788317893179031791317923179331794317953179631797317983179931800318013180231803318043180531806318073180831809318103181131812318133181431815318163181731818318193182031821318223182331824318253182631827318283182931830318313183231833318343183531836318373183831839318403184131842318433184431845318463184731848318493185031851318523185331854318553185631857318583185931860318613186231863318643186531866318673186831869318703187131872318733187431875318763187731878318793188031881318823188331884318853188631887318883188931890318913189231893318943189531896318973189831899319003190131902319033190431905319063190731908319093191031911319123191331914319153191631917319183191931920319213192231923319243192531926319273192831929319303193131932319333193431935319363193731938319393194031941319423194331944319453194631947319483194931950319513195231953319543195531956319573195831959319603196131962319633196431965319663196731968319693197031971319723197331974319753197631977319783197931980319813198231983319843198531986319873198831989319903199131992319933199431995319963199731998319993200032001320023200332004320053200632007320083200932010320113201232013320143201532016320173201832019320203202132022320233202432025320263202732028320293203032031320323203332034320353203632037320383203932040320413204232043320443204532046320473204832049320503205132052320533205432055320563205732058320593206032061320623206332064320653206632067320683206932070320713207232073320743207532076320773207832079320803208132082320833208432085320863208732088320893209032091320923209332094320953209632097320983209932100321013210232103321043210532106321073210832109321103211132112321133211432115321163211732118321193212032121321223212332124321253212632127321283212932130321313213232133321343213532136321373213832139321403214132142321433214432145321463214732148321493215032151321523215332154321553215632157321583215932160321613216232163321643216532166321673216832169321703217132172321733217432175321763217732178321793218032181321823218332184321853218632187321883218932190321913219232193321943219532196321973219832199322003220132202322033220432205322063220732208322093221032211322123221332214322153221632217322183221932220322213222232223322243222532226322273222832229322303223132232322333223432235322363223732238322393224032241322423224332244322453224632247322483224932250322513225232253322543225532256322573225832259322603226132262322633226432265322663226732268322693227032271322723227332274322753227632277322783227932280322813228232283322843228532286322873228832289322903229132292322933229432295322963229732298322993230032301323023230332304323053230632307323083230932310323113231232313323143231532316323173231832319323203232132322323233232432325323263232732328323293233032331323323233332334323353233632337323383233932340323413234232343323443234532346323473234832349323503235132352323533235432355323563235732358323593236032361323623236332364323653236632367323683236932370323713237232373323743237532376323773237832379323803238132382323833238432385323863238732388323893239032391323923239332394323953239632397323983239932400324013240232403324043240532406324073240832409324103241132412324133241432415324163241732418324193242032421324223242332424324253242632427324283242932430324313243232433324343243532436324373243832439324403244132442324433244432445324463244732448324493245032451324523245332454324553245632457324583245932460324613246232463324643246532466324673246832469324703247132472324733247432475324763247732478324793248032481324823248332484324853248632487324883248932490324913249232493324943249532496324973249832499325003250132502325033250432505325063250732508325093251032511325123251332514325153251632517325183251932520325213252232523325243252532526325273252832529325303253132532325333253432535325363253732538325393254032541325423254332544325453254632547325483254932550325513255232553325543255532556325573255832559325603256132562325633256432565325663256732568325693257032571325723257332574325753257632577325783257932580325813258232583325843258532586325873258832589325903259132592325933259432595325963259732598325993260032601326023260332604326053260632607326083260932610326113261232613326143261532616326173261832619326203262132622326233262432625326263262732628326293263032631326323263332634326353263632637326383263932640326413264232643326443264532646326473264832649326503265132652326533265432655326563265732658326593266032661326623266332664326653266632667326683266932670326713267232673326743267532676326773267832679326803268132682326833268432685326863268732688326893269032691326923269332694326953269632697326983269932700327013270232703327043270532706327073270832709327103271132712327133271432715327163271732718327193272032721327223272332724327253272632727327283272932730327313273232733327343273532736327373273832739327403274132742327433274432745327463274732748327493275032751327523275332754327553275632757327583275932760327613276232763327643276532766327673276832769327703277132772327733277432775327763277732778327793278032781327823278332784327853278632787327883278932790327913279232793327943279532796327973279832799328003280132802328033280432805328063280732808328093281032811328123281332814328153281632817328183281932820328213282232823328243282532826328273282832829328303283132832328333283432835328363283732838328393284032841328423284332844328453284632847328483284932850328513285232853328543285532856328573285832859328603286132862328633286432865328663286732868328693287032871328723287332874328753287632877328783287932880328813288232883328843288532886328873288832889328903289132892328933289432895328963289732898328993290032901329023290332904329053290632907329083290932910329113291232913329143291532916329173291832919329203292132922329233292432925329263292732928329293293032931329323293332934329353293632937329383293932940329413294232943329443294532946329473294832949329503295132952329533295432955329563295732958329593296032961329623296332964329653296632967329683296932970329713297232973329743297532976329773297832979329803298132982329833298432985329863298732988329893299032991329923299332994329953299632997329983299933000330013300233003330043300533006330073300833009330103301133012330133301433015330163301733018330193302033021330223302333024330253302633027330283302933030330313303233033330343303533036330373303833039330403304133042330433304433045330463304733048330493305033051330523305333054330553305633057330583305933060330613306233063330643306533066330673306833069330703307133072330733307433075330763307733078330793308033081330823308333084330853308633087330883308933090330913309233093330943309533096330973309833099331003310133102331033310433105331063310733108331093311033111331123311333114331153311633117331183311933120331213312233123331243312533126331273312833129331303313133132331333313433135331363313733138331393314033141331423314333144331453314633147331483314933150331513315233153331543315533156331573315833159331603316133162331633316433165331663316733168331693317033171331723317333174331753317633177331783317933180331813318233183331843318533186331873318833189331903319133192331933319433195331963319733198331993320033201332023320333204332053320633207332083320933210332113321233213332143321533216332173321833219332203322133222332233322433225332263322733228332293323033231332323323333234332353323633237332383323933240332413324233243332443324533246332473324833249332503325133252332533325433255332563325733258332593326033261332623326333264332653326633267332683326933270332713327233273332743327533276332773327833279332803328133282332833328433285332863328733288332893329033291332923329333294332953329633297332983329933300333013330233303333043330533306333073330833309333103331133312333133331433315333163331733318333193332033321333223332333324333253332633327333283332933330333313333233333333343333533336333373333833339333403334133342333433334433345333463334733348333493335033351333523335333354333553335633357333583335933360333613336233363333643336533366333673336833369333703337133372333733337433375333763337733378333793338033381333823338333384333853338633387333883338933390333913339233393333943339533396333973339833399334003340133402334033340433405334063340733408334093341033411334123341333414334153341633417334183341933420334213342233423334243342533426334273342833429334303343133432334333343433435334363343733438334393344033441334423344333444334453344633447334483344933450334513345233453334543345533456334573345833459334603346133462334633346433465334663346733468334693347033471334723347333474334753347633477334783347933480334813348233483334843348533486334873348833489334903349133492334933349433495334963349733498334993350033501335023350333504335053350633507335083350933510335113351233513335143351533516335173351833519335203352133522335233352433525335263352733528335293353033531335323353333534335353353633537335383353933540335413354233543335443354533546335473354833549335503355133552335533355433555335563355733558335593356033561335623356333564335653356633567335683356933570335713357233573335743357533576335773357833579335803358133582335833358433585335863358733588335893359033591335923359333594335953359633597335983359933600336013360233603336043360533606336073360833609336103361133612336133361433615336163361733618336193362033621336223362333624336253362633627336283362933630336313363233633336343363533636336373363833639336403364133642336433364433645336463364733648336493365033651336523365333654336553365633657336583365933660336613366233663336643366533666336673366833669336703367133672336733367433675336763367733678336793368033681336823368333684336853368633687336883368933690336913369233693336943369533696336973369833699337003370133702337033370433705337063370733708337093371033711337123371333714337153371633717337183371933720337213372233723337243372533726337273372833729337303373133732337333373433735337363373733738337393374033741337423374333744337453374633747337483374933750337513375233753337543375533756337573375833759337603376133762337633376433765337663376733768337693377033771337723377333774337753377633777337783377933780337813378233783337843378533786337873378833789337903379133792337933379433795337963379733798337993380033801338023380333804338053380633807338083380933810338113381233813338143381533816338173381833819338203382133822338233382433825338263382733828338293383033831338323383333834338353383633837338383383933840338413384233843338443384533846338473384833849338503385133852338533385433855338563385733858338593386033861338623386333864338653386633867338683386933870338713387233873338743387533876338773387833879338803388133882338833388433885338863388733888338893389033891338923389333894338953389633897338983389933900339013390233903339043390533906339073390833909339103391133912339133391433915339163391733918339193392033921339223392333924339253392633927339283392933930339313393233933339343393533936339373393833939339403394133942339433394433945339463394733948339493395033951339523395333954339553395633957339583395933960339613396233963339643396533966339673396833969339703397133972339733397433975339763397733978339793398033981339823398333984339853398633987339883398933990339913399233993339943399533996339973399833999340003400134002340033400434005340063400734008340093401034011340123401334014340153401634017340183401934020340213402234023340243402534026340273402834029340303403134032340333403434035340363403734038340393404034041340423404334044340453404634047340483404934050340513405234053340543405534056340573405834059340603406134062340633406434065340663406734068340693407034071340723407334074340753407634077340783407934080340813408234083340843408534086340873408834089340903409134092340933409434095340963409734098340993410034101341023410334104341053410634107341083410934110341113411234113341143411534116341173411834119341203412134122341233412434125341263412734128341293413034131341323413334134341353413634137341383413934140341413414234143341443414534146341473414834149341503415134152341533415434155341563415734158341593416034161341623416334164341653416634167341683416934170341713417234173341743417534176341773417834179341803418134182341833418434185341863418734188341893419034191341923419334194341953419634197341983419934200342013420234203342043420534206342073420834209342103421134212342133421434215342163421734218342193422034221342223422334224342253422634227342283422934230342313423234233342343423534236342373423834239342403424134242342433424434245342463424734248342493425034251342523425334254342553425634257342583425934260342613426234263342643426534266342673426834269342703427134272342733427434275342763427734278342793428034281342823428334284342853428634287342883428934290342913429234293342943429534296342973429834299343003430134302343033430434305343063430734308343093431034311343123431334314343153431634317343183431934320343213432234323343243432534326343273432834329343303433134332343333433434335343363433734338343393434034341343423434334344343453434634347343483434934350343513435234353343543435534356343573435834359343603436134362343633436434365343663436734368343693437034371343723437334374343753437634377343783437934380343813438234383343843438534386343873438834389343903439134392343933439434395343963439734398343993440034401344023440334404344053440634407344083440934410344113441234413344143441534416344173441834419344203442134422344233442434425344263442734428344293443034431344323443334434344353443634437344383443934440344413444234443344443444534446344473444834449344503445134452344533445434455344563445734458344593446034461344623446334464344653446634467344683446934470344713447234473344743447534476344773447834479344803448134482344833448434485344863448734488344893449034491344923449334494344953449634497344983449934500345013450234503345043450534506345073450834509345103451134512345133451434515345163451734518345193452034521345223452334524345253452634527345283452934530345313453234533345343453534536345373453834539345403454134542345433454434545345463454734548345493455034551345523455334554345553455634557345583455934560345613456234563345643456534566345673456834569345703457134572345733457434575345763457734578345793458034581345823458334584345853458634587345883458934590345913459234593345943459534596345973459834599346003460134602346033460434605346063460734608346093461034611346123461334614346153461634617346183461934620346213462234623346243462534626346273462834629346303463134632346333463434635346363463734638346393464034641346423464334644346453464634647346483464934650346513465234653346543465534656346573465834659346603466134662346633466434665346663466734668346693467034671346723467334674346753467634677346783467934680346813468234683346843468534686346873468834689346903469134692346933469434695346963469734698346993470034701347023470334704347053470634707347083470934710347113471234713347143471534716347173471834719347203472134722347233472434725347263472734728347293473034731347323473334734347353473634737347383473934740347413474234743347443474534746347473474834749347503475134752347533475434755347563475734758347593476034761347623476334764347653476634767347683476934770347713477234773347743477534776347773477834779347803478134782347833478434785347863478734788347893479034791347923479334794347953479634797347983479934800348013480234803348043480534806348073480834809348103481134812348133481434815348163481734818348193482034821348223482334824348253482634827348283482934830348313483234833348343483534836348373483834839348403484134842348433484434845348463484734848348493485034851348523485334854348553485634857348583485934860348613486234863348643486534866348673486834869348703487134872348733487434875348763487734878348793488034881348823488334884348853488634887348883488934890348913489234893348943489534896348973489834899349003490134902349033490434905349063490734908349093491034911349123491334914349153491634917349183491934920349213492234923349243492534926349273492834929349303493134932349333493434935349363493734938349393494034941349423494334944349453494634947349483494934950349513495234953349543495534956349573495834959349603496134962349633496434965349663496734968349693497034971349723497334974349753497634977349783497934980349813498234983349843498534986349873498834989349903499134992349933499434995349963499734998349993500035001350023500335004350053500635007350083500935010350113501235013350143501535016350173501835019350203502135022350233502435025350263502735028350293503035031350323503335034350353503635037350383503935040350413504235043350443504535046350473504835049350503505135052350533505435055350563505735058350593506035061350623506335064350653506635067350683506935070350713507235073350743507535076350773507835079350803508135082350833508435085350863508735088350893509035091350923509335094350953509635097350983509935100351013510235103351043510535106351073510835109351103511135112351133511435115351163511735118351193512035121351223512335124351253512635127351283512935130351313513235133351343513535136351373513835139351403514135142351433514435145351463514735148351493515035151351523515335154351553515635157351583515935160351613516235163351643516535166351673516835169351703517135172351733517435175351763517735178351793518035181351823518335184351853518635187351883518935190351913519235193351943519535196351973519835199352003520135202352033520435205352063520735208352093521035211352123521335214352153521635217352183521935220352213522235223352243522535226352273522835229352303523135232352333523435235352363523735238352393524035241352423524335244352453524635247352483524935250352513525235253352543525535256352573525835259352603526135262352633526435265352663526735268352693527035271352723527335274352753527635277352783527935280352813528235283352843528535286352873528835289352903529135292352933529435295352963529735298352993530035301353023530335304353053530635307353083530935310353113531235313353143531535316353173531835319353203532135322353233532435325353263532735328353293533035331353323533335334353353533635337353383533935340353413534235343353443534535346353473534835349353503535135352353533535435355353563535735358353593536035361353623536335364353653536635367353683536935370353713537235373353743537535376353773537835379353803538135382353833538435385353863538735388353893539035391353923539335394353953539635397353983539935400354013540235403354043540535406354073540835409354103541135412354133541435415354163541735418354193542035421354223542335424354253542635427354283542935430354313543235433354343543535436354373543835439354403544135442354433544435445354463544735448354493545035451354523545335454354553545635457354583545935460354613546235463354643546535466354673546835469354703547135472354733547435475354763547735478354793548035481354823548335484354853548635487354883548935490354913549235493354943549535496354973549835499355003550135502355033550435505355063550735508355093551035511355123551335514355153551635517355183551935520355213552235523355243552535526355273552835529355303553135532355333553435535355363553735538355393554035541355423554335544355453554635547355483554935550355513555235553355543555535556355573555835559355603556135562355633556435565355663556735568355693557035571355723557335574355753557635577355783557935580355813558235583355843558535586355873558835589355903559135592355933559435595355963559735598355993560035601356023560335604356053560635607356083560935610356113561235613356143561535616356173561835619356203562135622356233562435625356263562735628356293563035631356323563335634356353563635637356383563935640356413564235643356443564535646356473564835649356503565135652356533565435655356563565735658356593566035661356623566335664356653566635667356683566935670356713567235673356743567535676356773567835679356803568135682356833568435685356863568735688356893569035691356923569335694356953569635697356983569935700357013570235703357043570535706357073570835709357103571135712357133571435715357163571735718357193572035721357223572335724357253572635727357283572935730357313573235733357343573535736357373573835739357403574135742357433574435745357463574735748357493575035751357523575335754357553575635757357583575935760357613576235763357643576535766357673576835769357703577135772357733577435775357763577735778357793578035781357823578335784357853578635787357883578935790357913579235793357943579535796357973579835799358003580135802358033580435805358063580735808358093581035811358123581335814358153581635817358183581935820358213582235823358243582535826358273582835829358303583135832358333583435835358363583735838358393584035841358423584335844358453584635847358483584935850358513585235853358543585535856358573585835859358603586135862358633586435865358663586735868358693587035871358723587335874358753587635877358783587935880358813588235883358843588535886358873588835889358903589135892358933589435895358963589735898358993590035901359023590335904359053590635907359083590935910359113591235913359143591535916359173591835919359203592135922359233592435925359263592735928359293593035931359323593335934359353593635937359383593935940359413594235943359443594535946359473594835949359503595135952359533595435955359563595735958359593596035961359623596335964359653596635967359683596935970359713597235973359743597535976359773597835979359803598135982359833598435985359863598735988359893599035991359923599335994359953599635997359983599936000360013600236003360043600536006360073600836009360103601136012360133601436015360163601736018360193602036021360223602336024360253602636027360283602936030360313603236033360343603536036360373603836039360403604136042360433604436045360463604736048360493605036051360523605336054360553605636057360583605936060360613606236063360643606536066360673606836069360703607136072360733607436075360763607736078360793608036081360823608336084360853608636087360883608936090360913609236093360943609536096360973609836099361003610136102361033610436105361063610736108361093611036111361123611336114361153611636117361183611936120361213612236123361243612536126361273612836129361303613136132361333613436135361363613736138361393614036141361423614336144361453614636147361483614936150361513615236153361543615536156361573615836159361603616136162361633616436165361663616736168361693617036171361723617336174361753617636177361783617936180361813618236183361843618536186361873618836189361903619136192361933619436195361963619736198361993620036201362023620336204362053620636207362083620936210362113621236213362143621536216362173621836219362203622136222362233622436225362263622736228362293623036231362323623336234362353623636237362383623936240362413624236243362443624536246362473624836249362503625136252362533625436255362563625736258362593626036261362623626336264362653626636267362683626936270362713627236273362743627536276362773627836279362803628136282362833628436285362863628736288362893629036291362923629336294362953629636297362983629936300363013630236303363043630536306363073630836309363103631136312363133631436315363163631736318363193632036321363223632336324363253632636327363283632936330363313633236333363343633536336363373633836339363403634136342363433634436345363463634736348363493635036351363523635336354363553635636357363583635936360363613636236363363643636536366363673636836369363703637136372363733637436375363763637736378363793638036381363823638336384363853638636387363883638936390363913639236393363943639536396363973639836399364003640136402364033640436405364063640736408364093641036411364123641336414364153641636417364183641936420364213642236423364243642536426364273642836429364303643136432364333643436435364363643736438364393644036441364423644336444364453644636447364483644936450364513645236453364543645536456364573645836459364603646136462364633646436465364663646736468364693647036471364723647336474364753647636477364783647936480364813648236483364843648536486364873648836489364903649136492364933649436495364963649736498364993650036501365023650336504365053650636507365083650936510365113651236513365143651536516365173651836519365203652136522365233652436525365263652736528365293653036531365323653336534365353653636537365383653936540365413654236543365443654536546365473654836549365503655136552365533655436555365563655736558365593656036561365623656336564365653656636567365683656936570365713657236573365743657536576365773657836579365803658136582365833658436585365863658736588365893659036591365923659336594365953659636597365983659936600366013660236603366043660536606366073660836609366103661136612366133661436615366163661736618366193662036621366223662336624366253662636627366283662936630366313663236633366343663536636366373663836639366403664136642366433664436645366463664736648366493665036651366523665336654366553665636657366583665936660366613666236663366643666536666366673666836669366703667136672366733667436675366763667736678366793668036681366823668336684366853668636687366883668936690366913669236693366943669536696366973669836699367003670136702367033670436705367063670736708367093671036711367123671336714367153671636717367183671936720367213672236723367243672536726367273672836729367303673136732367333673436735367363673736738367393674036741367423674336744367453674636747367483674936750367513675236753367543675536756367573675836759367603676136762367633676436765367663676736768367693677036771367723677336774367753677636777367783677936780367813678236783367843678536786367873678836789367903679136792367933679436795367963679736798367993680036801368023680336804368053680636807368083680936810368113681236813368143681536816368173681836819368203682136822368233682436825368263682736828368293683036831368323683336834368353683636837368383683936840368413684236843368443684536846368473684836849368503685136852368533685436855368563685736858368593686036861368623686336864368653686636867368683686936870368713687236873368743687536876368773687836879368803688136882368833688436885368863688736888368893689036891368923689336894368953689636897368983689936900369013690236903369043690536906369073690836909369103691136912369133691436915369163691736918369193692036921369223692336924369253692636927369283692936930369313693236933369343693536936369373693836939369403694136942369433694436945369463694736948369493695036951369523695336954369553695636957369583695936960369613696236963369643696536966369673696836969369703697136972369733697436975369763697736978369793698036981369823698336984369853698636987369883698936990369913699236993369943699536996369973699836999370003700137002370033700437005370063700737008370093701037011370123701337014370153701637017370183701937020370213702237023370243702537026370273702837029370303703137032370333703437035370363703737038370393704037041370423704337044370453704637047370483704937050370513705237053370543705537056370573705837059370603706137062370633706437065370663706737068370693707037071370723707337074370753707637077370783707937080370813708237083370843708537086370873708837089370903709137092370933709437095370963709737098370993710037101371023710337104371053710637107371083710937110371113711237113371143711537116371173711837119371203712137122371233712437125371263712737128371293713037131371323713337134371353713637137371383713937140371413714237143371443714537146371473714837149371503715137152371533715437155371563715737158371593716037161371623716337164371653716637167371683716937170371713717237173371743717537176371773717837179371803718137182371833718437185371863718737188371893719037191371923719337194371953719637197371983719937200372013720237203372043720537206372073720837209372103721137212372133721437215372163721737218372193722037221372223722337224372253722637227372283722937230372313723237233372343723537236372373723837239372403724137242372433724437245372463724737248372493725037251372523725337254372553725637257372583725937260372613726237263372643726537266372673726837269372703727137272372733727437275372763727737278372793728037281372823728337284372853728637287372883728937290372913729237293372943729537296372973729837299373003730137302373033730437305373063730737308373093731037311373123731337314373153731637317373183731937320373213732237323373243732537326373273732837329373303733137332373333733437335373363733737338373393734037341373423734337344373453734637347373483734937350373513735237353373543735537356373573735837359373603736137362373633736437365373663736737368373693737037371373723737337374373753737637377373783737937380373813738237383373843738537386373873738837389373903739137392373933739437395373963739737398373993740037401374023740337404374053740637407374083740937410374113741237413374143741537416374173741837419374203742137422374233742437425374263742737428374293743037431374323743337434374353743637437374383743937440374413744237443374443744537446374473744837449374503745137452374533745437455374563745737458374593746037461374623746337464374653746637467374683746937470374713747237473374743747537476374773747837479374803748137482374833748437485374863748737488374893749037491374923749337494374953749637497374983749937500375013750237503375043750537506375073750837509375103751137512375133751437515375163751737518375193752037521375223752337524375253752637527375283752937530375313753237533375343753537536375373753837539375403754137542375433754437545375463754737548375493755037551375523755337554375553755637557375583755937560375613756237563375643756537566375673756837569375703757137572375733757437575375763757737578375793758037581375823758337584375853758637587375883758937590375913759237593375943759537596375973759837599376003760137602376033760437605376063760737608376093761037611376123761337614376153761637617376183761937620376213762237623376243762537626376273762837629376303763137632376333763437635376363763737638376393764037641376423764337644376453764637647376483764937650376513765237653376543765537656376573765837659376603766137662376633766437665376663766737668376693767037671376723767337674376753767637677376783767937680376813768237683376843768537686376873768837689376903769137692376933769437695376963769737698376993770037701377023770337704377053770637707377083770937710377113771237713377143771537716377173771837719377203772137722377233772437725377263772737728377293773037731377323773337734377353773637737377383773937740377413774237743377443774537746377473774837749377503775137752377533775437755377563775737758377593776037761377623776337764377653776637767377683776937770377713777237773377743777537776377773777837779377803778137782377833778437785377863778737788377893779037791377923779337794377953779637797377983779937800378013780237803378043780537806378073780837809378103781137812378133781437815378163781737818378193782037821378223782337824378253782637827378283782937830378313783237833378343783537836378373783837839378403784137842378433784437845378463784737848378493785037851378523785337854378553785637857378583785937860378613786237863378643786537866378673786837869378703787137872378733787437875378763787737878378793788037881378823788337884378853788637887378883788937890378913789237893378943789537896378973789837899379003790137902379033790437905379063790737908379093791037911379123791337914379153791637917379183791937920379213792237923379243792537926379273792837929379303793137932379333793437935379363793737938379393794037941379423794337944379453794637947379483794937950379513795237953379543795537956379573795837959379603796137962379633796437965379663796737968379693797037971379723797337974379753797637977379783797937980379813798237983379843798537986379873798837989379903799137992379933799437995379963799737998379993800038001380023800338004380053800638007380083800938010380113801238013380143801538016380173801838019380203802138022380233802438025380263802738028380293803038031380323803338034380353803638037380383803938040380413804238043380443804538046380473804838049380503805138052380533805438055380563805738058380593806038061380623806338064380653806638067380683806938070380713807238073380743807538076380773807838079380803808138082380833808438085380863808738088380893809038091380923809338094380953809638097380983809938100381013810238103381043810538106381073810838109381103811138112381133811438115381163811738118381193812038121381223812338124381253812638127381283812938130381313813238133381343813538136381373813838139381403814138142381433814438145381463814738148381493815038151381523815338154381553815638157381583815938160381613816238163381643816538166381673816838169381703817138172381733817438175381763817738178381793818038181381823818338184381853818638187381883818938190381913819238193381943819538196381973819838199382003820138202382033820438205382063820738208382093821038211382123821338214382153821638217382183821938220382213822238223382243822538226382273822838229382303823138232382333823438235382363823738238382393824038241382423824338244382453824638247382483824938250382513825238253382543825538256382573825838259382603826138262382633826438265382663826738268382693827038271382723827338274382753827638277382783827938280382813828238283382843828538286382873828838289382903829138292382933829438295382963829738298382993830038301383023830338304383053830638307383083830938310383113831238313383143831538316383173831838319383203832138322383233832438325383263832738328383293833038331383323833338334383353833638337383383833938340383413834238343383443834538346383473834838349383503835138352383533835438355383563835738358383593836038361383623836338364383653836638367383683836938370383713837238373383743837538376383773837838379383803838138382383833838438385383863838738388383893839038391383923839338394383953839638397383983839938400384013840238403384043840538406384073840838409384103841138412384133841438415384163841738418384193842038421384223842338424384253842638427384283842938430384313843238433384343843538436384373843838439384403844138442384433844438445384463844738448384493845038451384523845338454384553845638457384583845938460384613846238463384643846538466384673846838469384703847138472384733847438475384763847738478384793848038481384823848338484384853848638487384883848938490384913849238493384943849538496384973849838499385003850138502385033850438505385063850738508385093851038511385123851338514385153851638517385183851938520385213852238523385243852538526385273852838529385303853138532385333853438535385363853738538385393854038541385423854338544385453854638547385483854938550385513855238553385543855538556385573855838559385603856138562385633856438565385663856738568385693857038571385723857338574385753857638577385783857938580385813858238583385843858538586385873858838589385903859138592385933859438595385963859738598385993860038601386023860338604386053860638607386083860938610386113861238613386143861538616386173861838619386203862138622386233862438625386263862738628386293863038631386323863338634386353863638637386383863938640386413864238643386443864538646386473864838649386503865138652386533865438655386563865738658386593866038661386623866338664386653866638667386683866938670386713867238673386743867538676386773867838679386803868138682386833868438685386863868738688386893869038691386923869338694386953869638697386983869938700387013870238703387043870538706387073870838709387103871138712387133871438715387163871738718387193872038721387223872338724387253872638727387283872938730387313873238733387343873538736387373873838739387403874138742387433874438745387463874738748387493875038751387523875338754387553875638757387583875938760387613876238763387643876538766387673876838769387703877138772387733877438775387763877738778387793878038781387823878338784387853878638787387883878938790387913879238793387943879538796387973879838799388003880138802388033880438805388063880738808388093881038811388123881338814388153881638817388183881938820388213882238823388243882538826388273882838829388303883138832388333883438835388363883738838388393884038841388423884338844388453884638847388483884938850388513885238853388543885538856388573885838859388603886138862388633886438865388663886738868388693887038871388723887338874388753887638877388783887938880388813888238883388843888538886388873888838889388903889138892388933889438895388963889738898388993890038901389023890338904389053890638907389083890938910389113891238913389143891538916389173891838919389203892138922389233892438925389263892738928389293893038931389323893338934389353893638937389383893938940389413894238943389443894538946389473894838949389503895138952389533895438955389563895738958389593896038961389623896338964389653896638967389683896938970389713897238973389743897538976389773897838979389803898138982389833898438985389863898738988389893899038991389923899338994389953899638997389983899939000390013900239003390043900539006390073900839009390103901139012390133901439015390163901739018390193902039021390223902339024390253902639027390283902939030390313903239033390343903539036390373903839039390403904139042390433904439045390463904739048390493905039051390523905339054390553905639057390583905939060390613906239063390643906539066390673906839069390703907139072390733907439075390763907739078390793908039081390823908339084390853908639087390883908939090390913909239093390943909539096390973909839099391003910139102391033910439105391063910739108391093911039111391123911339114391153911639117391183911939120391213912239123391243912539126391273912839129391303913139132391333913439135391363913739138391393914039141391423914339144391453914639147391483914939150391513915239153391543915539156391573915839159391603916139162391633916439165391663916739168391693917039171391723917339174391753917639177391783917939180391813918239183391843918539186391873918839189391903919139192391933919439195391963919739198391993920039201392023920339204392053920639207392083920939210392113921239213392143921539216392173921839219392203922139222392233922439225392263922739228392293923039231392323923339234392353923639237392383923939240392413924239243392443924539246392473924839249392503925139252392533925439255392563925739258392593926039261392623926339264392653926639267392683926939270392713927239273392743927539276392773927839279392803928139282392833928439285392863928739288392893929039291392923929339294392953929639297392983929939300393013930239303393043930539306393073930839309393103931139312393133931439315393163931739318393193932039321393223932339324393253932639327393283932939330393313933239333393343933539336393373933839339393403934139342393433934439345393463934739348393493935039351393523935339354393553935639357393583935939360393613936239363393643936539366393673936839369393703937139372393733937439375393763937739378393793938039381393823938339384393853938639387393883938939390393913939239393393943939539396393973939839399394003940139402394033940439405394063940739408394093941039411394123941339414394153941639417394183941939420394213942239423394243942539426394273942839429394303943139432394333943439435394363943739438394393944039441394423944339444394453944639447394483944939450394513945239453394543945539456394573945839459394603946139462394633946439465394663946739468394693947039471394723947339474394753947639477394783947939480394813948239483394843948539486394873948839489394903949139492394933949439495394963949739498394993950039501395023950339504395053950639507395083950939510395113951239513395143951539516395173951839519395203952139522395233952439525395263952739528395293953039531395323953339534395353953639537395383953939540395413954239543395443954539546395473954839549395503955139552395533955439555395563955739558395593956039561395623956339564395653956639567395683956939570395713957239573395743957539576395773957839579395803958139582395833958439585395863958739588395893959039591395923959339594395953959639597395983959939600396013960239603396043960539606396073960839609396103961139612396133961439615396163961739618396193962039621396223962339624396253962639627396283962939630396313963239633396343963539636396373963839639396403964139642396433964439645396463964739648396493965039651396523965339654396553965639657396583965939660396613966239663396643966539666396673966839669396703967139672396733967439675396763967739678396793968039681396823968339684396853968639687396883968939690396913969239693396943969539696396973969839699397003970139702397033970439705397063970739708397093971039711397123971339714397153971639717397183971939720397213972239723397243972539726397273972839729397303973139732397333973439735397363973739738397393974039741397423974339744397453974639747397483974939750397513975239753397543975539756397573975839759397603976139762397633976439765397663976739768397693977039771397723977339774397753977639777397783977939780397813978239783397843978539786397873978839789397903979139792397933979439795397963979739798397993980039801398023980339804398053980639807398083980939810398113981239813398143981539816398173981839819398203982139822398233982439825398263982739828398293983039831398323983339834398353983639837398383983939840398413984239843398443984539846398473984839849398503985139852398533985439855398563985739858398593986039861398623986339864398653986639867398683986939870398713987239873398743987539876398773987839879398803988139882398833988439885398863988739888398893989039891398923989339894398953989639897398983989939900399013990239903399043990539906399073990839909399103991139912399133991439915399163991739918399193992039921399223992339924399253992639927399283992939930399313993239933399343993539936399373993839939399403994139942399433994439945399463994739948399493995039951399523995339954399553995639957399583995939960399613996239963399643996539966399673996839969399703997139972399733997439975399763997739978399793998039981399823998339984399853998639987399883998939990399913999239993399943999539996399973999839999400004000140002400034000440005400064000740008400094001040011400124001340014400154001640017400184001940020400214002240023400244002540026400274002840029400304003140032400334003440035400364003740038400394004040041400424004340044400454004640047400484004940050400514005240053400544005540056400574005840059400604006140062400634006440065400664006740068400694007040071400724007340074400754007640077400784007940080400814008240083400844008540086400874008840089400904009140092400934009440095400964009740098400994010040101401024010340104401054010640107401084010940110401114011240113401144011540116401174011840119401204012140122401234012440125401264012740128401294013040131401324013340134401354013640137401384013940140401414014240143401444014540146401474014840149401504015140152401534015440155401564015740158401594016040161401624016340164401654016640167401684016940170401714017240173401744017540176401774017840179401804018140182401834018440185401864018740188401894019040191401924019340194401954019640197401984019940200402014020240203402044020540206402074020840209402104021140212402134021440215402164021740218402194022040221402224022340224402254022640227402284022940230402314023240233402344023540236402374023840239402404024140242402434024440245402464024740248402494025040251402524025340254402554025640257402584025940260402614026240263402644026540266402674026840269402704027140272402734027440275402764027740278402794028040281402824028340284402854028640287402884028940290402914029240293402944029540296402974029840299403004030140302403034030440305403064030740308403094031040311403124031340314403154031640317403184031940320403214032240323403244032540326403274032840329403304033140332403334033440335403364033740338403394034040341403424034340344403454034640347403484034940350403514035240353403544035540356403574035840359403604036140362403634036440365403664036740368403694037040371403724037340374403754037640377403784037940380403814038240383403844038540386403874038840389403904039140392403934039440395403964039740398403994040040401404024040340404404054040640407404084040940410404114041240413404144041540416404174041840419404204042140422404234042440425404264042740428404294043040431404324043340434404354043640437404384043940440404414044240443404444044540446404474044840449404504045140452404534045440455404564045740458404594046040461404624046340464404654046640467404684046940470404714047240473404744047540476404774047840479404804048140482404834048440485404864048740488404894049040491404924049340494404954049640497404984049940500405014050240503405044050540506405074050840509405104051140512405134051440515405164051740518405194052040521405224052340524405254052640527405284052940530405314053240533405344053540536405374053840539405404054140542405434054440545405464054740548405494055040551405524055340554405554055640557405584055940560405614056240563405644056540566405674056840569405704057140572405734057440575405764057740578405794058040581405824058340584405854058640587405884058940590405914059240593405944059540596405974059840599406004060140602406034060440605406064060740608406094061040611406124061340614406154061640617406184061940620406214062240623406244062540626406274062840629406304063140632406334063440635406364063740638406394064040641406424064340644406454064640647406484064940650406514065240653406544065540656406574065840659406604066140662406634066440665406664066740668406694067040671406724067340674406754067640677406784067940680406814068240683406844068540686406874068840689406904069140692406934069440695406964069740698406994070040701407024070340704407054070640707407084070940710407114071240713407144071540716407174071840719407204072140722407234072440725407264072740728407294073040731407324073340734407354073640737407384073940740407414074240743407444074540746407474074840749407504075140752407534075440755407564075740758407594076040761407624076340764407654076640767407684076940770407714077240773407744077540776407774077840779407804078140782407834078440785407864078740788407894079040791407924079340794407954079640797407984079940800408014080240803408044080540806408074080840809408104081140812408134081440815408164081740818408194082040821408224082340824408254082640827408284082940830408314083240833408344083540836408374083840839408404084140842408434084440845408464084740848408494085040851408524085340854408554085640857408584085940860408614086240863408644086540866408674086840869408704087140872408734087440875408764087740878408794088040881408824088340884408854088640887408884088940890408914089240893408944089540896408974089840899409004090140902409034090440905409064090740908409094091040911409124091340914409154091640917409184091940920409214092240923409244092540926409274092840929409304093140932409334093440935409364093740938409394094040941409424094340944409454094640947409484094940950409514095240953409544095540956409574095840959409604096140962409634096440965409664096740968409694097040971409724097340974409754097640977409784097940980409814098240983409844098540986409874098840989409904099140992409934099440995409964099740998409994100041001410024100341004410054100641007410084100941010410114101241013410144101541016410174101841019410204102141022410234102441025410264102741028410294103041031410324103341034410354103641037410384103941040410414104241043410444104541046410474104841049410504105141052410534105441055410564105741058410594106041061410624106341064410654106641067410684106941070410714107241073410744107541076410774107841079410804108141082410834108441085410864108741088410894109041091410924109341094410954109641097410984109941100411014110241103411044110541106411074110841109411104111141112411134111441115411164111741118411194112041121411224112341124411254112641127411284112941130411314113241133411344113541136411374113841139411404114141142411434114441145411464114741148411494115041151411524115341154411554115641157411584115941160411614116241163411644116541166411674116841169411704117141172411734117441175411764117741178411794118041181411824118341184411854118641187411884118941190411914119241193411944119541196411974119841199412004120141202412034120441205412064120741208412094121041211412124121341214412154121641217412184121941220412214122241223412244122541226412274122841229412304123141232412334123441235412364123741238412394124041241412424124341244412454124641247412484124941250412514125241253412544125541256412574125841259412604126141262412634126441265412664126741268412694127041271412724127341274412754127641277412784127941280412814128241283412844128541286412874128841289412904129141292412934129441295412964129741298412994130041301413024130341304413054130641307413084130941310413114131241313413144131541316413174131841319413204132141322413234132441325413264132741328413294133041331413324133341334413354133641337413384133941340413414134241343413444134541346413474134841349413504135141352413534135441355413564135741358413594136041361413624136341364413654136641367413684136941370413714137241373413744137541376413774137841379413804138141382413834138441385413864138741388413894139041391413924139341394413954139641397413984139941400414014140241403414044140541406414074140841409414104141141412414134141441415414164141741418414194142041421414224142341424414254142641427414284142941430414314143241433414344143541436414374143841439414404144141442414434144441445414464144741448414494145041451414524145341454414554145641457414584145941460414614146241463414644146541466414674146841469414704147141472414734147441475414764147741478414794148041481414824148341484414854148641487414884148941490414914149241493414944149541496414974149841499415004150141502415034150441505415064150741508415094151041511415124151341514415154151641517415184151941520415214152241523415244152541526415274152841529415304153141532415334153441535415364153741538415394154041541415424154341544415454154641547415484154941550415514155241553415544155541556415574155841559415604156141562415634156441565415664156741568415694157041571415724157341574415754157641577415784157941580415814158241583415844158541586415874158841589415904159141592415934159441595415964159741598415994160041601416024160341604416054160641607416084160941610416114161241613416144161541616416174161841619416204162141622416234162441625416264162741628416294163041631416324163341634416354163641637416384163941640416414164241643416444164541646416474164841649416504165141652416534165441655416564165741658416594166041661416624166341664416654166641667416684166941670416714167241673416744167541676416774167841679416804168141682416834168441685416864168741688416894169041691416924169341694416954169641697416984169941700417014170241703417044170541706417074170841709417104171141712417134171441715417164171741718417194172041721417224172341724417254172641727417284172941730417314173241733417344173541736417374173841739417404174141742417434174441745417464174741748417494175041751417524175341754417554175641757417584175941760417614176241763417644176541766417674176841769417704177141772417734177441775417764177741778417794178041781417824178341784417854178641787417884178941790417914179241793417944179541796417974179841799418004180141802418034180441805418064180741808418094181041811418124181341814418154181641817418184181941820418214182241823418244182541826418274182841829418304183141832418334183441835418364183741838418394184041841418424184341844418454184641847418484184941850418514185241853418544185541856418574185841859418604186141862418634186441865418664186741868418694187041871418724187341874418754187641877418784187941880418814188241883418844188541886418874188841889418904189141892418934189441895418964189741898418994190041901419024190341904419054190641907419084190941910419114191241913419144191541916419174191841919419204192141922419234192441925419264192741928419294193041931419324193341934419354193641937419384193941940419414194241943419444194541946419474194841949419504195141952419534195441955419564195741958419594196041961419624196341964419654196641967419684196941970419714197241973419744197541976419774197841979419804198141982419834198441985419864198741988419894199041991419924199341994419954199641997419984199942000420014200242003420044200542006420074200842009420104201142012420134201442015420164201742018420194202042021420224202342024420254202642027420284202942030420314203242033420344203542036420374203842039420404204142042420434204442045420464204742048420494205042051420524205342054420554205642057420584205942060420614206242063420644206542066420674206842069420704207142072420734207442075420764207742078420794208042081420824208342084420854208642087420884208942090420914209242093420944209542096420974209842099421004210142102421034210442105421064210742108421094211042111421124211342114421154211642117421184211942120421214212242123421244212542126421274212842129421304213142132421334213442135421364213742138421394214042141421424214342144421454214642147421484214942150421514215242153421544215542156421574215842159421604216142162421634216442165421664216742168421694217042171421724217342174421754217642177421784217942180421814218242183421844218542186421874218842189421904219142192421934219442195421964219742198421994220042201422024220342204422054220642207422084220942210422114221242213422144221542216422174221842219422204222142222422234222442225422264222742228422294223042231422324223342234422354223642237422384223942240422414224242243422444224542246422474224842249422504225142252422534225442255422564225742258422594226042261422624226342264422654226642267422684226942270422714227242273422744227542276422774227842279422804228142282422834228442285422864228742288422894229042291422924229342294422954229642297422984229942300423014230242303423044230542306423074230842309423104231142312423134231442315423164231742318423194232042321423224232342324423254232642327423284232942330423314233242333423344233542336423374233842339423404234142342423434234442345423464234742348423494235042351423524235342354423554235642357423584235942360423614236242363423644236542366423674236842369423704237142372423734237442375423764237742378423794238042381423824238342384423854238642387423884238942390423914239242393423944239542396423974239842399424004240142402424034240442405424064240742408424094241042411424124241342414424154241642417424184241942420424214242242423424244242542426424274242842429424304243142432424334243442435424364243742438424394244042441424424244342444424454244642447424484244942450424514245242453424544245542456424574245842459424604246142462424634246442465424664246742468424694247042471424724247342474424754247642477424784247942480424814248242483424844248542486424874248842489424904249142492424934249442495424964249742498424994250042501425024250342504425054250642507425084250942510425114251242513425144251542516425174251842519425204252142522425234252442525425264252742528425294253042531425324253342534425354253642537425384253942540425414254242543425444254542546425474254842549425504255142552425534255442555425564255742558425594256042561425624256342564425654256642567425684256942570425714257242573425744257542576425774257842579425804258142582425834258442585425864258742588425894259042591425924259342594425954259642597425984259942600426014260242603426044260542606426074260842609426104261142612426134261442615426164261742618426194262042621426224262342624426254262642627426284262942630426314263242633426344263542636426374263842639426404264142642426434264442645426464264742648426494265042651426524265342654426554265642657426584265942660426614266242663426644266542666426674266842669426704267142672426734267442675426764267742678426794268042681426824268342684426854268642687426884268942690426914269242693426944269542696426974269842699427004270142702427034270442705427064270742708427094271042711427124271342714427154271642717427184271942720427214272242723427244272542726427274272842729427304273142732427334273442735427364273742738427394274042741427424274342744427454274642747427484274942750427514275242753427544275542756427574275842759427604276142762427634276442765427664276742768427694277042771427724277342774427754277642777427784277942780427814278242783427844278542786427874278842789427904279142792427934279442795427964279742798427994280042801428024280342804428054280642807428084280942810428114281242813428144281542816428174281842819428204282142822428234282442825428264282742828428294283042831428324283342834428354283642837428384283942840428414284242843428444284542846428474284842849428504285142852428534285442855428564285742858428594286042861428624286342864428654286642867428684286942870428714287242873428744287542876428774287842879428804288142882428834288442885428864288742888428894289042891428924289342894428954289642897428984289942900429014290242903429044290542906429074290842909429104291142912429134291442915429164291742918429194292042921429224292342924429254292642927429284292942930429314293242933429344293542936429374293842939429404294142942429434294442945429464294742948429494295042951429524295342954429554295642957429584295942960429614296242963429644296542966429674296842969429704297142972429734297442975429764297742978429794298042981429824298342984429854298642987429884298942990429914299242993429944299542996429974299842999430004300143002430034300443005430064300743008430094301043011430124301343014430154301643017430184301943020430214302243023430244302543026430274302843029430304303143032430334303443035430364303743038430394304043041430424304343044430454304643047430484304943050430514305243053430544305543056430574305843059430604306143062430634306443065430664306743068430694307043071430724307343074430754307643077430784307943080430814308243083430844308543086430874308843089430904309143092430934309443095430964309743098430994310043101431024310343104431054310643107431084310943110431114311243113431144311543116431174311843119431204312143122431234312443125431264312743128431294313043131431324313343134431354313643137431384313943140431414314243143431444314543146431474314843149431504315143152431534315443155431564315743158431594316043161431624316343164431654316643167431684316943170431714317243173431744317543176431774317843179431804318143182431834318443185431864318743188431894319043191431924319343194431954319643197431984319943200432014320243203432044320543206432074320843209432104321143212432134321443215432164321743218432194322043221432224322343224432254322643227432284322943230432314323243233432344323543236432374323843239432404324143242432434324443245432464324743248432494325043251432524325343254432554325643257432584325943260432614326243263432644326543266432674326843269432704327143272432734327443275432764327743278432794328043281432824328343284432854328643287432884328943290432914329243293432944329543296432974329843299433004330143302433034330443305433064330743308433094331043311433124331343314433154331643317433184331943320433214332243323433244332543326433274332843329433304333143332433334333443335433364333743338433394334043341433424334343344433454334643347433484334943350433514335243353433544335543356433574335843359433604336143362433634336443365433664336743368433694337043371433724337343374433754337643377433784337943380433814338243383433844338543386433874338843389433904339143392433934339443395433964339743398433994340043401434024340343404434054340643407434084340943410434114341243413434144341543416434174341843419434204342143422434234342443425434264342743428434294343043431434324343343434434354343643437434384343943440434414344243443434444344543446434474344843449434504345143452434534345443455434564345743458434594346043461434624346343464434654346643467434684346943470434714347243473434744347543476434774347843479434804348143482434834348443485434864348743488434894349043491434924349343494434954349643497434984349943500435014350243503435044350543506435074350843509435104351143512435134351443515435164351743518435194352043521435224352343524435254352643527435284352943530435314353243533435344353543536435374353843539435404354143542435434354443545435464354743548435494355043551435524355343554435554355643557435584355943560435614356243563435644356543566435674356843569435704357143572435734357443575435764357743578435794358043581435824358343584435854358643587435884358943590435914359243593435944359543596435974359843599436004360143602436034360443605436064360743608436094361043611436124361343614436154361643617436184361943620436214362243623436244362543626436274362843629436304363143632436334363443635436364363743638436394364043641436424364343644436454364643647436484364943650436514365243653436544365543656436574365843659436604366143662436634366443665436664366743668436694367043671436724367343674436754367643677436784367943680436814368243683436844368543686436874368843689436904369143692436934369443695436964369743698436994370043701437024370343704437054370643707437084370943710437114371243713437144371543716437174371843719437204372143722437234372443725437264372743728437294373043731437324373343734437354373643737437384373943740437414374243743437444374543746437474374843749437504375143752437534375443755437564375743758437594376043761437624376343764437654376643767437684376943770437714377243773437744377543776437774377843779437804378143782437834378443785437864378743788437894379043791437924379343794437954379643797437984379943800438014380243803438044380543806438074380843809438104381143812438134381443815438164381743818438194382043821438224382343824438254382643827438284382943830438314383243833438344383543836438374383843839438404384143842438434384443845438464384743848438494385043851438524385343854438554385643857438584385943860438614386243863438644386543866438674386843869438704387143872438734387443875438764387743878438794388043881438824388343884438854388643887438884388943890438914389243893438944389543896438974389843899439004390143902439034390443905439064390743908439094391043911439124391343914439154391643917439184391943920439214392243923439244392543926439274392843929439304393143932439334393443935439364393743938439394394043941439424394343944439454394643947439484394943950439514395243953439544395543956439574395843959439604396143962439634396443965439664396743968439694397043971439724397343974439754397643977439784397943980439814398243983439844398543986439874398843989439904399143992439934399443995439964399743998439994400044001440024400344004440054400644007440084400944010440114401244013440144401544016440174401844019440204402144022440234402444025440264402744028440294403044031440324403344034440354403644037440384403944040440414404244043440444404544046440474404844049440504405144052440534405444055440564405744058440594406044061440624406344064440654406644067440684406944070440714407244073440744407544076440774407844079440804408144082440834408444085440864408744088440894409044091440924409344094440954409644097440984409944100441014410244103441044410544106441074410844109441104411144112441134411444115441164411744118441194412044121441224412344124441254412644127441284412944130441314413244133441344413544136441374413844139441404414144142441434414444145441464414744148441494415044151441524415344154441554415644157441584415944160441614416244163441644416544166441674416844169441704417144172441734417444175441764417744178441794418044181441824418344184441854418644187441884418944190441914419244193441944419544196441974419844199442004420144202442034420444205442064420744208442094421044211442124421344214442154421644217442184421944220442214422244223442244422544226442274422844229442304423144232442334423444235442364423744238442394424044241442424424344244442454424644247442484424944250442514425244253442544425544256442574425844259442604426144262442634426444265442664426744268442694427044271442724427344274442754427644277442784427944280442814428244283442844428544286442874428844289442904429144292442934429444295442964429744298442994430044301443024430344304443054430644307443084430944310443114431244313443144431544316443174431844319443204432144322443234432444325443264432744328443294433044331443324433344334443354433644337443384433944340443414434244343443444434544346443474434844349443504435144352443534435444355443564435744358443594436044361443624436344364443654436644367443684436944370443714437244373443744437544376443774437844379443804438144382443834438444385443864438744388443894439044391443924439344394443954439644397443984439944400444014440244403444044440544406444074440844409444104441144412444134441444415444164441744418444194442044421444224442344424444254442644427444284442944430444314443244433444344443544436444374443844439444404444144442444434444444445444464444744448444494445044451444524445344454444554445644457444584445944460444614446244463444644446544466444674446844469444704447144472444734447444475444764447744478444794448044481444824448344484444854448644487444884448944490444914449244493444944449544496444974449844499445004450144502445034450444505445064450744508445094451044511445124451344514445154451644517445184451944520445214452244523445244452544526445274452844529445304453144532445334453444535445364453744538445394454044541445424454344544445454454644547445484454944550445514455244553445544455544556445574455844559445604456144562445634456444565445664456744568445694457044571445724457344574445754457644577445784457944580445814458244583445844458544586445874458844589445904459144592445934459444595445964459744598445994460044601446024460344604446054460644607446084460944610446114461244613446144461544616446174461844619446204462144622446234462444625446264462744628446294463044631446324463344634446354463644637446384463944640446414464244643446444464544646446474464844649446504465144652446534465444655446564465744658446594466044661446624466344664446654466644667446684466944670446714467244673446744467544676446774467844679446804468144682446834468444685446864468744688446894469044691446924469344694446954469644697446984469944700447014470244703447044470544706447074470844709447104471144712447134471444715447164471744718447194472044721447224472344724447254472644727447284472944730447314473244733447344473544736447374473844739447404474144742447434474444745447464474744748447494475044751447524475344754447554475644757447584475944760447614476244763447644476544766447674476844769447704477144772447734477444775447764477744778447794478044781447824478344784447854478644787447884478944790447914479244793447944479544796447974479844799448004480144802448034480444805448064480744808448094481044811448124481344814448154481644817448184481944820448214482244823448244482544826448274482844829448304483144832448334483444835448364483744838448394484044841448424484344844448454484644847448484484944850448514485244853448544485544856448574485844859448604486144862448634486444865448664486744868448694487044871448724487344874448754487644877448784487944880448814488244883448844488544886448874488844889448904489144892448934489444895448964489744898448994490044901449024490344904449054490644907449084490944910449114491244913449144491544916449174491844919449204492144922449234492444925449264492744928449294493044931449324493344934449354493644937449384493944940449414494244943449444494544946449474494844949449504495144952449534495444955449564495744958449594496044961449624496344964449654496644967449684496944970449714497244973449744497544976449774497844979449804498144982449834498444985449864498744988449894499044991449924499344994449954499644997449984499945000450014500245003450044500545006450074500845009450104501145012450134501445015450164501745018450194502045021450224502345024450254502645027450284502945030450314503245033450344503545036450374503845039450404504145042450434504445045450464504745048450494505045051450524505345054450554505645057450584505945060450614506245063450644506545066450674506845069450704507145072450734507445075450764507745078450794508045081450824508345084450854508645087450884508945090450914509245093450944509545096450974509845099451004510145102451034510445105451064510745108451094511045111451124511345114451154511645117451184511945120451214512245123451244512545126451274512845129451304513145132451334513445135451364513745138451394514045141451424514345144451454514645147451484514945150451514515245153451544515545156451574515845159451604516145162451634516445165451664516745168451694517045171451724517345174451754517645177451784517945180451814518245183451844518545186451874518845189451904519145192451934519445195451964519745198451994520045201452024520345204452054520645207452084520945210452114521245213452144521545216452174521845219452204522145222452234522445225452264522745228452294523045231452324523345234452354523645237452384523945240452414524245243452444524545246452474524845249452504525145252452534525445255452564525745258452594526045261452624526345264452654526645267452684526945270452714527245273452744527545276452774527845279452804528145282452834528445285452864528745288452894529045291452924529345294452954529645297452984529945300453014530245303453044530545306453074530845309453104531145312453134531445315453164531745318453194532045321453224532345324453254532645327453284532945330453314533245333453344533545336453374533845339453404534145342453434534445345453464534745348453494535045351453524535345354453554535645357453584535945360453614536245363453644536545366453674536845369453704537145372453734537445375453764537745378453794538045381453824538345384453854538645387453884538945390453914539245393453944539545396453974539845399454004540145402454034540445405454064540745408454094541045411454124541345414454154541645417454184541945420454214542245423454244542545426454274542845429454304543145432454334543445435454364543745438454394544045441454424544345444454454544645447454484544945450454514545245453454544545545456454574545845459454604546145462454634546445465454664546745468454694547045471454724547345474454754547645477454784547945480454814548245483454844548545486454874548845489454904549145492454934549445495454964549745498454994550045501455024550345504455054550645507455084550945510455114551245513455144551545516455174551845519455204552145522455234552445525455264552745528455294553045531455324553345534455354553645537455384553945540455414554245543455444554545546455474554845549455504555145552455534555445555455564555745558455594556045561455624556345564455654556645567455684556945570455714557245573455744557545576455774557845579455804558145582455834558445585455864558745588455894559045591455924559345594455954559645597455984559945600456014560245603456044560545606456074560845609456104561145612456134561445615456164561745618456194562045621456224562345624456254562645627456284562945630456314563245633456344563545636456374563845639456404564145642456434564445645456464564745648456494565045651456524565345654456554565645657456584565945660456614566245663456644566545666456674566845669456704567145672456734567445675456764567745678456794568045681456824568345684456854568645687456884568945690456914569245693456944569545696456974569845699457004570145702457034570445705457064570745708457094571045711457124571345714457154571645717457184571945720457214572245723457244572545726457274572845729457304573145732457334573445735457364573745738457394574045741457424574345744457454574645747457484574945750457514575245753457544575545756457574575845759457604576145762457634576445765457664576745768457694577045771457724577345774457754577645777457784577945780457814578245783457844578545786457874578845789457904579145792457934579445795457964579745798457994580045801458024580345804458054580645807458084580945810458114581245813458144581545816458174581845819458204582145822458234582445825458264582745828458294583045831458324583345834458354583645837458384583945840458414584245843458444584545846458474584845849458504585145852458534585445855458564585745858458594586045861458624586345864458654586645867458684586945870458714587245873458744587545876458774587845879458804588145882458834588445885458864588745888458894589045891458924589345894458954589645897458984589945900459014590245903459044590545906459074590845909459104591145912459134591445915459164591745918459194592045921459224592345924459254592645927459284592945930459314593245933459344593545936459374593845939459404594145942459434594445945459464594745948459494595045951459524595345954459554595645957459584595945960459614596245963459644596545966459674596845969459704597145972459734597445975459764597745978459794598045981459824598345984459854598645987459884598945990459914599245993459944599545996459974599845999460004600146002460034600446005460064600746008460094601046011460124601346014460154601646017460184601946020460214602246023460244602546026460274602846029460304603146032460334603446035460364603746038460394604046041460424604346044460454604646047460484604946050460514605246053460544605546056460574605846059460604606146062460634606446065460664606746068460694607046071460724607346074460754607646077460784607946080460814608246083460844608546086460874608846089460904609146092460934609446095460964609746098460994610046101461024610346104461054610646107461084610946110461114611246113461144611546116461174611846119461204612146122461234612446125461264612746128461294613046131461324613346134461354613646137461384613946140461414614246143461444614546146461474614846149461504615146152461534615446155461564615746158461594616046161461624616346164461654616646167461684616946170461714617246173461744617546176461774617846179461804618146182461834618446185461864618746188461894619046191461924619346194461954619646197461984619946200462014620246203462044620546206462074620846209462104621146212462134621446215462164621746218462194622046221462224622346224462254622646227462284622946230462314623246233462344623546236462374623846239462404624146242462434624446245462464624746248462494625046251462524625346254462554625646257462584625946260462614626246263462644626546266462674626846269462704627146272462734627446275462764627746278462794628046281462824628346284462854628646287462884628946290462914629246293462944629546296462974629846299463004630146302463034630446305463064630746308463094631046311463124631346314463154631646317463184631946320463214632246323463244632546326463274632846329463304633146332463334633446335463364633746338463394634046341463424634346344463454634646347463484634946350463514635246353463544635546356463574635846359463604636146362463634636446365463664636746368463694637046371463724637346374463754637646377463784637946380463814638246383463844638546386463874638846389463904639146392463934639446395463964639746398463994640046401464024640346404464054640646407464084640946410464114641246413464144641546416464174641846419464204642146422464234642446425464264642746428464294643046431464324643346434464354643646437464384643946440464414644246443464444644546446464474644846449464504645146452464534645446455464564645746458464594646046461464624646346464464654646646467464684646946470464714647246473464744647546476464774647846479464804648146482464834648446485464864648746488464894649046491464924649346494464954649646497464984649946500465014650246503465044650546506465074650846509465104651146512465134651446515465164651746518465194652046521465224652346524465254652646527465284652946530465314653246533465344653546536465374653846539465404654146542465434654446545465464654746548465494655046551465524655346554465554655646557465584655946560465614656246563465644656546566465674656846569465704657146572465734657446575465764657746578465794658046581465824658346584465854658646587465884658946590465914659246593465944659546596465974659846599466004660146602466034660446605466064660746608466094661046611466124661346614466154661646617466184661946620466214662246623466244662546626466274662846629466304663146632466334663446635466364663746638466394664046641466424664346644466454664646647466484664946650466514665246653466544665546656466574665846659466604666146662466634666446665466664666746668466694667046671466724667346674466754667646677466784667946680466814668246683466844668546686466874668846689466904669146692466934669446695466964669746698466994670046701467024670346704467054670646707467084670946710467114671246713467144671546716467174671846719467204672146722467234672446725467264672746728467294673046731467324673346734467354673646737467384673946740467414674246743467444674546746467474674846749467504675146752467534675446755467564675746758467594676046761467624676346764467654676646767467684676946770467714677246773467744677546776467774677846779467804678146782467834678446785467864678746788467894679046791467924679346794467954679646797467984679946800468014680246803468044680546806468074680846809468104681146812468134681446815468164681746818468194682046821468224682346824468254682646827468284682946830468314683246833468344683546836468374683846839468404684146842468434684446845468464684746848468494685046851468524685346854468554685646857468584685946860468614686246863468644686546866468674686846869468704687146872468734687446875468764687746878468794688046881468824688346884468854688646887468884688946890468914689246893468944689546896468974689846899469004690146902469034690446905469064690746908469094691046911469124691346914469154691646917469184691946920469214692246923469244692546926469274692846929469304693146932469334693446935469364693746938469394694046941469424694346944469454694646947469484694946950469514695246953469544695546956469574695846959469604696146962469634696446965469664696746968469694697046971469724697346974469754697646977469784697946980469814698246983469844698546986469874698846989469904699146992469934699446995469964699746998469994700047001470024700347004470054700647007470084700947010470114701247013470144701547016470174701847019470204702147022470234702447025470264702747028470294703047031470324703347034470354703647037470384703947040470414704247043470444704547046470474704847049470504705147052470534705447055470564705747058470594706047061470624706347064470654706647067470684706947070470714707247073470744707547076470774707847079470804708147082470834708447085470864708747088470894709047091470924709347094470954709647097470984709947100471014710247103471044710547106471074710847109471104711147112471134711447115471164711747118471194712047121471224712347124471254712647127471284712947130471314713247133471344713547136471374713847139471404714147142471434714447145471464714747148471494715047151471524715347154471554715647157471584715947160471614716247163471644716547166471674716847169471704717147172471734717447175471764717747178471794718047181471824718347184471854718647187471884718947190471914719247193471944719547196471974719847199472004720147202472034720447205472064720747208472094721047211472124721347214472154721647217472184721947220472214722247223472244722547226472274722847229472304723147232472334723447235472364723747238472394724047241472424724347244472454724647247472484724947250472514725247253472544725547256472574725847259472604726147262472634726447265472664726747268472694727047271472724727347274472754727647277472784727947280472814728247283472844728547286472874728847289472904729147292472934729447295472964729747298472994730047301473024730347304473054730647307473084730947310473114731247313473144731547316473174731847319473204732147322473234732447325473264732747328473294733047331473324733347334473354733647337473384733947340473414734247343473444734547346473474734847349473504735147352473534735447355473564735747358473594736047361473624736347364473654736647367473684736947370473714737247373473744737547376473774737847379473804738147382473834738447385473864738747388473894739047391473924739347394473954739647397473984739947400474014740247403474044740547406474074740847409474104741147412474134741447415474164741747418474194742047421474224742347424474254742647427474284742947430474314743247433474344743547436474374743847439474404744147442474434744447445474464744747448474494745047451474524745347454474554745647457474584745947460474614746247463474644746547466474674746847469474704747147472474734747447475474764747747478474794748047481474824748347484474854748647487474884748947490474914749247493474944749547496474974749847499475004750147502475034750447505475064750747508475094751047511475124751347514475154751647517475184751947520475214752247523475244752547526475274752847529475304753147532475334753447535475364753747538475394754047541475424754347544475454754647547475484754947550475514755247553475544755547556475574755847559475604756147562475634756447565475664756747568475694757047571475724757347574475754757647577475784757947580475814758247583475844758547586475874758847589475904759147592475934759447595475964759747598475994760047601476024760347604476054760647607476084760947610476114761247613476144761547616476174761847619476204762147622476234762447625476264762747628476294763047631476324763347634476354763647637476384763947640476414764247643476444764547646476474764847649476504765147652476534765447655476564765747658476594766047661476624766347664476654766647667476684766947670476714767247673476744767547676476774767847679476804768147682476834768447685476864768747688476894769047691476924769347694476954769647697476984769947700477014770247703477044770547706477074770847709477104771147712477134771447715477164771747718477194772047721477224772347724477254772647727477284772947730477314773247733477344773547736477374773847739477404774147742477434774447745477464774747748477494775047751477524775347754477554775647757477584775947760477614776247763477644776547766477674776847769477704777147772477734777447775477764777747778477794778047781477824778347784477854778647787477884778947790477914779247793477944779547796477974779847799478004780147802478034780447805478064780747808478094781047811478124781347814478154781647817478184781947820478214782247823478244782547826478274782847829478304783147832478334783447835478364783747838478394784047841478424784347844478454784647847478484784947850478514785247853478544785547856478574785847859478604786147862478634786447865478664786747868478694787047871478724787347874478754787647877478784787947880478814788247883478844788547886478874788847889478904789147892478934789447895478964789747898478994790047901479024790347904479054790647907479084790947910479114791247913479144791547916479174791847919479204792147922479234792447925479264792747928479294793047931479324793347934479354793647937479384793947940479414794247943479444794547946479474794847949479504795147952479534795447955479564795747958479594796047961479624796347964479654796647967479684796947970479714797247973479744797547976479774797847979479804798147982479834798447985479864798747988479894799047991479924799347994479954799647997479984799948000480014800248003480044800548006480074800848009480104801148012480134801448015480164801748018480194802048021480224802348024480254802648027480284802948030480314803248033480344803548036480374803848039480404804148042480434804448045480464804748048480494805048051480524805348054480554805648057480584805948060480614806248063480644806548066480674806848069480704807148072480734807448075480764807748078480794808048081480824808348084480854808648087480884808948090480914809248093480944809548096480974809848099481004810148102481034810448105481064810748108481094811048111481124811348114481154811648117481184811948120481214812248123481244812548126481274812848129481304813148132481334813448135481364813748138481394814048141481424814348144481454814648147481484814948150481514815248153481544815548156481574815848159481604816148162481634816448165481664816748168481694817048171481724817348174481754817648177481784817948180481814818248183481844818548186481874818848189481904819148192481934819448195481964819748198481994820048201482024820348204482054820648207482084820948210482114821248213482144821548216482174821848219482204822148222482234822448225482264822748228482294823048231482324823348234482354823648237482384823948240482414824248243482444824548246482474824848249482504825148252482534825448255482564825748258482594826048261482624826348264482654826648267482684826948270482714827248273482744827548276482774827848279482804828148282482834828448285482864828748288482894829048291482924829348294482954829648297482984829948300483014830248303483044830548306483074830848309483104831148312483134831448315483164831748318483194832048321483224832348324483254832648327483284832948330483314833248333483344833548336483374833848339483404834148342483434834448345483464834748348483494835048351483524835348354483554835648357483584835948360
  1. (function (global, factory) {
  2. typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
  3. typeof define === 'function' && define.amd ? define(['exports'], factory) :
  4. (global = global || self, factory(global.THREE = {}));
  5. }(this, function (exports) { 'use strict';
  6. // Polyfills
  7. if ( Number.EPSILON === undefined ) {
  8. Number.EPSILON = Math.pow( 2, - 52 );
  9. }
  10. if ( Number.isInteger === undefined ) {
  11. // Missing in IE
  12. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isInteger
  13. Number.isInteger = function ( value ) {
  14. return typeof value === 'number' && isFinite( value ) && Math.floor( value ) === value;
  15. };
  16. }
  17. //
  18. if ( Math.sign === undefined ) {
  19. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sign
  20. Math.sign = function ( x ) {
  21. return ( x < 0 ) ? - 1 : ( x > 0 ) ? 1 : + x;
  22. };
  23. }
  24. if ( 'name' in Function.prototype === false ) {
  25. // Missing in IE
  26. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/name
  27. Object.defineProperty( Function.prototype, 'name', {
  28. get: function () {
  29. return this.toString().match( /^\s*function\s*([^\(\s]*)/ )[ 1 ];
  30. }
  31. } );
  32. }
  33. if ( Object.assign === undefined ) {
  34. // Missing in IE
  35. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign
  36. ( function () {
  37. Object.assign = function ( target ) {
  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. * https://github.com/mrdoob/eventdispatcher.js/
  58. */
  59. function EventDispatcher() {}
  60. Object.assign( EventDispatcher.prototype, {
  61. addEventListener: function ( type, listener ) {
  62. if ( this._listeners === undefined ) this._listeners = {};
  63. var listeners = this._listeners;
  64. if ( listeners[ type ] === undefined ) {
  65. listeners[ type ] = [];
  66. }
  67. if ( listeners[ type ].indexOf( listener ) === - 1 ) {
  68. listeners[ type ].push( listener );
  69. }
  70. },
  71. hasEventListener: function ( type, listener ) {
  72. if ( this._listeners === undefined ) return false;
  73. var listeners = this._listeners;
  74. return listeners[ type ] !== undefined && listeners[ type ].indexOf( listener ) !== - 1;
  75. },
  76. removeEventListener: function ( type, listener ) {
  77. if ( this._listeners === undefined ) return;
  78. var listeners = this._listeners;
  79. var listenerArray = listeners[ type ];
  80. if ( listenerArray !== undefined ) {
  81. var index = listenerArray.indexOf( listener );
  82. if ( index !== - 1 ) {
  83. listenerArray.splice( index, 1 );
  84. }
  85. }
  86. },
  87. dispatchEvent: function ( event ) {
  88. if ( this._listeners === undefined ) return;
  89. var listeners = this._listeners;
  90. var listenerArray = listeners[ event.type ];
  91. if ( listenerArray !== undefined ) {
  92. event.target = this;
  93. var array = listenerArray.slice( 0 );
  94. for ( var i = 0, l = array.length; i < l; i ++ ) {
  95. array[ i ].call( this, event );
  96. }
  97. }
  98. }
  99. } );
  100. var REVISION = '102';
  101. var MOUSE = { LEFT: 0, MIDDLE: 1, RIGHT: 2 };
  102. var CullFaceNone = 0;
  103. var CullFaceBack = 1;
  104. var CullFaceFront = 2;
  105. var CullFaceFrontBack = 3;
  106. var FrontFaceDirectionCW = 0;
  107. var FrontFaceDirectionCCW = 1;
  108. var BasicShadowMap = 0;
  109. var PCFShadowMap = 1;
  110. var PCFSoftShadowMap = 2;
  111. var FrontSide = 0;
  112. var BackSide = 1;
  113. var DoubleSide = 2;
  114. var FlatShading = 1;
  115. var SmoothShading = 2;
  116. var NoColors = 0;
  117. var FaceColors = 1;
  118. var VertexColors = 2;
  119. var NoBlending = 0;
  120. var NormalBlending = 1;
  121. var AdditiveBlending = 2;
  122. var SubtractiveBlending = 3;
  123. var MultiplyBlending = 4;
  124. var CustomBlending = 5;
  125. var AddEquation = 100;
  126. var SubtractEquation = 101;
  127. var ReverseSubtractEquation = 102;
  128. var MinEquation = 103;
  129. var MaxEquation = 104;
  130. var ZeroFactor = 200;
  131. var OneFactor = 201;
  132. var SrcColorFactor = 202;
  133. var OneMinusSrcColorFactor = 203;
  134. var SrcAlphaFactor = 204;
  135. var OneMinusSrcAlphaFactor = 205;
  136. var DstAlphaFactor = 206;
  137. var OneMinusDstAlphaFactor = 207;
  138. var DstColorFactor = 208;
  139. var OneMinusDstColorFactor = 209;
  140. var SrcAlphaSaturateFactor = 210;
  141. var NeverDepth = 0;
  142. var AlwaysDepth = 1;
  143. var LessDepth = 2;
  144. var LessEqualDepth = 3;
  145. var EqualDepth = 4;
  146. var GreaterEqualDepth = 5;
  147. var GreaterDepth = 6;
  148. var NotEqualDepth = 7;
  149. var MultiplyOperation = 0;
  150. var MixOperation = 1;
  151. var AddOperation = 2;
  152. var NoToneMapping = 0;
  153. var LinearToneMapping = 1;
  154. var ReinhardToneMapping = 2;
  155. var Uncharted2ToneMapping = 3;
  156. var CineonToneMapping = 4;
  157. var ACESFilmicToneMapping = 5;
  158. var UVMapping = 300;
  159. var CubeReflectionMapping = 301;
  160. var CubeRefractionMapping = 302;
  161. var EquirectangularReflectionMapping = 303;
  162. var EquirectangularRefractionMapping = 304;
  163. var SphericalReflectionMapping = 305;
  164. var CubeUVReflectionMapping = 306;
  165. var CubeUVRefractionMapping = 307;
  166. var RepeatWrapping = 1000;
  167. var ClampToEdgeWrapping = 1001;
  168. var MirroredRepeatWrapping = 1002;
  169. var NearestFilter = 1003;
  170. var NearestMipMapNearestFilter = 1004;
  171. var NearestMipMapLinearFilter = 1005;
  172. var LinearFilter = 1006;
  173. var LinearMipMapNearestFilter = 1007;
  174. var LinearMipMapLinearFilter = 1008;
  175. var UnsignedByteType = 1009;
  176. var ByteType = 1010;
  177. var ShortType = 1011;
  178. var UnsignedShortType = 1012;
  179. var IntType = 1013;
  180. var UnsignedIntType = 1014;
  181. var FloatType = 1015;
  182. var HalfFloatType = 1016;
  183. var UnsignedShort4444Type = 1017;
  184. var UnsignedShort5551Type = 1018;
  185. var UnsignedShort565Type = 1019;
  186. var UnsignedInt248Type = 1020;
  187. var AlphaFormat = 1021;
  188. var RGBFormat = 1022;
  189. var RGBAFormat = 1023;
  190. var LuminanceFormat = 1024;
  191. var LuminanceAlphaFormat = 1025;
  192. var RGBEFormat = RGBAFormat;
  193. var DepthFormat = 1026;
  194. var DepthStencilFormat = 1027;
  195. var RedFormat = 1028;
  196. var RGB_S3TC_DXT1_Format = 33776;
  197. var RGBA_S3TC_DXT1_Format = 33777;
  198. var RGBA_S3TC_DXT3_Format = 33778;
  199. var RGBA_S3TC_DXT5_Format = 33779;
  200. var RGB_PVRTC_4BPPV1_Format = 35840;
  201. var RGB_PVRTC_2BPPV1_Format = 35841;
  202. var RGBA_PVRTC_4BPPV1_Format = 35842;
  203. var RGBA_PVRTC_2BPPV1_Format = 35843;
  204. var RGB_ETC1_Format = 36196;
  205. var RGBA_ASTC_4x4_Format = 37808;
  206. var RGBA_ASTC_5x4_Format = 37809;
  207. var RGBA_ASTC_5x5_Format = 37810;
  208. var RGBA_ASTC_6x5_Format = 37811;
  209. var RGBA_ASTC_6x6_Format = 37812;
  210. var RGBA_ASTC_8x5_Format = 37813;
  211. var RGBA_ASTC_8x6_Format = 37814;
  212. var RGBA_ASTC_8x8_Format = 37815;
  213. var RGBA_ASTC_10x5_Format = 37816;
  214. var RGBA_ASTC_10x6_Format = 37817;
  215. var RGBA_ASTC_10x8_Format = 37818;
  216. var RGBA_ASTC_10x10_Format = 37819;
  217. var RGBA_ASTC_12x10_Format = 37820;
  218. var RGBA_ASTC_12x12_Format = 37821;
  219. var LoopOnce = 2200;
  220. var LoopRepeat = 2201;
  221. var LoopPingPong = 2202;
  222. var InterpolateDiscrete = 2300;
  223. var InterpolateLinear = 2301;
  224. var InterpolateSmooth = 2302;
  225. var ZeroCurvatureEnding = 2400;
  226. var ZeroSlopeEnding = 2401;
  227. var WrapAroundEnding = 2402;
  228. var TrianglesDrawMode = 0;
  229. var TriangleStripDrawMode = 1;
  230. var TriangleFanDrawMode = 2;
  231. var LinearEncoding = 3000;
  232. var sRGBEncoding = 3001;
  233. var GammaEncoding = 3007;
  234. var RGBEEncoding = 3002;
  235. var LogLuvEncoding = 3003;
  236. var RGBM7Encoding = 3004;
  237. var RGBM16Encoding = 3005;
  238. var RGBDEncoding = 3006;
  239. var BasicDepthPacking = 3200;
  240. var RGBADepthPacking = 3201;
  241. var TangentSpaceNormalMap = 0;
  242. var ObjectSpaceNormalMap = 1;
  243. /**
  244. * @author alteredq / http://alteredqualia.com/
  245. * @author mrdoob / http://mrdoob.com/
  246. */
  247. var _Math = {
  248. DEG2RAD: Math.PI / 180,
  249. RAD2DEG: 180 / Math.PI,
  250. generateUUID: ( function () {
  251. // http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript/21963136#21963136
  252. var lut = [];
  253. for ( var i = 0; i < 256; i ++ ) {
  254. lut[ i ] = ( i < 16 ? '0' : '' ) + ( i ).toString( 16 );
  255. }
  256. return function generateUUID() {
  257. var d0 = Math.random() * 0xffffffff | 0;
  258. var d1 = Math.random() * 0xffffffff | 0;
  259. var d2 = Math.random() * 0xffffffff | 0;
  260. var d3 = Math.random() * 0xffffffff | 0;
  261. var uuid = lut[ d0 & 0xff ] + lut[ d0 >> 8 & 0xff ] + lut[ d0 >> 16 & 0xff ] + lut[ d0 >> 24 & 0xff ] + '-' +
  262. lut[ d1 & 0xff ] + lut[ d1 >> 8 & 0xff ] + '-' + lut[ d1 >> 16 & 0x0f | 0x40 ] + lut[ d1 >> 24 & 0xff ] + '-' +
  263. lut[ d2 & 0x3f | 0x80 ] + lut[ d2 >> 8 & 0xff ] + '-' + lut[ d2 >> 16 & 0xff ] + lut[ d2 >> 24 & 0xff ] +
  264. lut[ d3 & 0xff ] + lut[ d3 >> 8 & 0xff ] + lut[ d3 >> 16 & 0xff ] + lut[ d3 >> 24 & 0xff ];
  265. // .toUpperCase() here flattens concatenated strings to save heap memory space.
  266. return uuid.toUpperCase();
  267. };
  268. } )(),
  269. clamp: function ( value, min, max ) {
  270. return Math.max( min, Math.min( max, value ) );
  271. },
  272. // compute euclidian modulo of m % n
  273. // https://en.wikipedia.org/wiki/Modulo_operation
  274. euclideanModulo: function ( n, m ) {
  275. return ( ( n % m ) + m ) % m;
  276. },
  277. // Linear mapping from range <a1, a2> to range <b1, b2>
  278. mapLinear: function ( x, a1, a2, b1, b2 ) {
  279. return b1 + ( x - a1 ) * ( b2 - b1 ) / ( a2 - a1 );
  280. },
  281. // https://en.wikipedia.org/wiki/Linear_interpolation
  282. lerp: function ( x, y, t ) {
  283. return ( 1 - t ) * x + t * y;
  284. },
  285. // http://en.wikipedia.org/wiki/Smoothstep
  286. smoothstep: function ( x, min, max ) {
  287. if ( x <= min ) return 0;
  288. if ( x >= max ) return 1;
  289. x = ( x - min ) / ( max - min );
  290. return x * x * ( 3 - 2 * x );
  291. },
  292. smootherstep: function ( x, min, max ) {
  293. if ( x <= min ) return 0;
  294. if ( x >= max ) return 1;
  295. x = ( x - min ) / ( max - min );
  296. return x * x * x * ( x * ( x * 6 - 15 ) + 10 );
  297. },
  298. // Random integer from <low, high> interval
  299. randInt: function ( low, high ) {
  300. return low + Math.floor( Math.random() * ( high - low + 1 ) );
  301. },
  302. // Random float from <low, high> interval
  303. randFloat: function ( low, high ) {
  304. return low + Math.random() * ( high - low );
  305. },
  306. // Random float from <-range/2, range/2> interval
  307. randFloatSpread: function ( range ) {
  308. return range * ( 0.5 - Math.random() );
  309. },
  310. degToRad: function ( degrees ) {
  311. return degrees * _Math.DEG2RAD;
  312. },
  313. radToDeg: function ( radians ) {
  314. return radians * _Math.RAD2DEG;
  315. },
  316. isPowerOfTwo: function ( value ) {
  317. return ( value & ( value - 1 ) ) === 0 && value !== 0;
  318. },
  319. ceilPowerOfTwo: function ( value ) {
  320. return Math.pow( 2, Math.ceil( Math.log( value ) / Math.LN2 ) );
  321. },
  322. floorPowerOfTwo: function ( value ) {
  323. return Math.pow( 2, Math.floor( Math.log( value ) / Math.LN2 ) );
  324. }
  325. };
  326. /**
  327. * @author mrdoob / http://mrdoob.com/
  328. * @author philogb / http://blog.thejit.org/
  329. * @author egraether / http://egraether.com/
  330. * @author zz85 / http://www.lab4games.net/zz85/blog
  331. */
  332. function Vector2( x, y ) {
  333. this.x = x || 0;
  334. this.y = y || 0;
  335. }
  336. Object.defineProperties( Vector2.prototype, {
  337. "width": {
  338. get: function () {
  339. return this.x;
  340. },
  341. set: function ( value ) {
  342. this.x = value;
  343. }
  344. },
  345. "height": {
  346. get: function () {
  347. return this.y;
  348. },
  349. set: function ( value ) {
  350. this.y = value;
  351. }
  352. }
  353. } );
  354. Object.assign( Vector2.prototype, {
  355. isVector2: true,
  356. set: function ( x, y ) {
  357. this.x = x;
  358. this.y = y;
  359. return this;
  360. },
  361. setScalar: function ( scalar ) {
  362. this.x = scalar;
  363. this.y = scalar;
  364. return this;
  365. },
  366. setX: function ( x ) {
  367. this.x = x;
  368. return this;
  369. },
  370. setY: function ( y ) {
  371. this.y = y;
  372. return this;
  373. },
  374. setComponent: function ( index, value ) {
  375. switch ( index ) {
  376. case 0: this.x = value; break;
  377. case 1: this.y = value; break;
  378. default: throw new Error( 'index is out of range: ' + index );
  379. }
  380. return this;
  381. },
  382. getComponent: function ( index ) {
  383. switch ( index ) {
  384. case 0: return this.x;
  385. case 1: return this.y;
  386. default: throw new Error( 'index is out of range: ' + index );
  387. }
  388. },
  389. clone: function () {
  390. return new this.constructor( this.x, this.y );
  391. },
  392. copy: function ( v ) {
  393. this.x = v.x;
  394. this.y = v.y;
  395. return this;
  396. },
  397. add: function ( v, w ) {
  398. if ( w !== undefined ) {
  399. console.warn( 'THREE.Vector2: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  400. return this.addVectors( v, w );
  401. }
  402. this.x += v.x;
  403. this.y += v.y;
  404. return this;
  405. },
  406. addScalar: function ( s ) {
  407. this.x += s;
  408. this.y += s;
  409. return this;
  410. },
  411. addVectors: function ( a, b ) {
  412. this.x = a.x + b.x;
  413. this.y = a.y + b.y;
  414. return this;
  415. },
  416. addScaledVector: function ( v, s ) {
  417. this.x += v.x * s;
  418. this.y += v.y * s;
  419. return this;
  420. },
  421. sub: function ( v, w ) {
  422. if ( w !== undefined ) {
  423. console.warn( 'THREE.Vector2: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  424. return this.subVectors( v, w );
  425. }
  426. this.x -= v.x;
  427. this.y -= v.y;
  428. return this;
  429. },
  430. subScalar: function ( s ) {
  431. this.x -= s;
  432. this.y -= s;
  433. return this;
  434. },
  435. subVectors: function ( a, b ) {
  436. this.x = a.x - b.x;
  437. this.y = a.y - b.y;
  438. return this;
  439. },
  440. multiply: function ( v ) {
  441. this.x *= v.x;
  442. this.y *= v.y;
  443. return this;
  444. },
  445. multiplyScalar: function ( scalar ) {
  446. this.x *= scalar;
  447. this.y *= scalar;
  448. return this;
  449. },
  450. divide: function ( v ) {
  451. this.x /= v.x;
  452. this.y /= v.y;
  453. return this;
  454. },
  455. divideScalar: function ( scalar ) {
  456. return this.multiplyScalar( 1 / scalar );
  457. },
  458. applyMatrix3: function ( m ) {
  459. var x = this.x, y = this.y;
  460. var e = m.elements;
  461. this.x = e[ 0 ] * x + e[ 3 ] * y + e[ 6 ];
  462. this.y = e[ 1 ] * x + e[ 4 ] * y + e[ 7 ];
  463. return this;
  464. },
  465. min: function ( v ) {
  466. this.x = Math.min( this.x, v.x );
  467. this.y = Math.min( this.y, v.y );
  468. return this;
  469. },
  470. max: function ( v ) {
  471. this.x = Math.max( this.x, v.x );
  472. this.y = Math.max( this.y, v.y );
  473. return this;
  474. },
  475. clamp: function ( min, max ) {
  476. // assumes min < max, componentwise
  477. this.x = Math.max( min.x, Math.min( max.x, this.x ) );
  478. this.y = Math.max( min.y, Math.min( max.y, this.y ) );
  479. return this;
  480. },
  481. clampScalar: function () {
  482. var min = new Vector2();
  483. var max = new Vector2();
  484. return function clampScalar( minVal, maxVal ) {
  485. min.set( minVal, minVal );
  486. max.set( maxVal, maxVal );
  487. return this.clamp( min, max );
  488. };
  489. }(),
  490. clampLength: function ( min, max ) {
  491. var length = this.length();
  492. return this.divideScalar( length || 1 ).multiplyScalar( Math.max( min, Math.min( max, length ) ) );
  493. },
  494. floor: function () {
  495. this.x = Math.floor( this.x );
  496. this.y = Math.floor( this.y );
  497. return this;
  498. },
  499. ceil: function () {
  500. this.x = Math.ceil( this.x );
  501. this.y = Math.ceil( this.y );
  502. return this;
  503. },
  504. round: function () {
  505. this.x = Math.round( this.x );
  506. this.y = Math.round( this.y );
  507. return this;
  508. },
  509. roundToZero: function () {
  510. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  511. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  512. return this;
  513. },
  514. negate: function () {
  515. this.x = - this.x;
  516. this.y = - this.y;
  517. return this;
  518. },
  519. dot: function ( v ) {
  520. return this.x * v.x + this.y * v.y;
  521. },
  522. cross: function ( v ) {
  523. return this.x * v.y - this.y * v.x;
  524. },
  525. lengthSq: function () {
  526. return this.x * this.x + this.y * this.y;
  527. },
  528. length: function () {
  529. return Math.sqrt( this.x * this.x + this.y * this.y );
  530. },
  531. manhattanLength: function () {
  532. return Math.abs( this.x ) + Math.abs( this.y );
  533. },
  534. normalize: function () {
  535. return this.divideScalar( this.length() || 1 );
  536. },
  537. angle: function () {
  538. // computes the angle in radians with respect to the positive x-axis
  539. var angle = Math.atan2( this.y, this.x );
  540. if ( angle < 0 ) angle += 2 * Math.PI;
  541. return angle;
  542. },
  543. distanceTo: function ( v ) {
  544. return Math.sqrt( this.distanceToSquared( v ) );
  545. },
  546. distanceToSquared: function ( v ) {
  547. var dx = this.x - v.x, dy = this.y - v.y;
  548. return dx * dx + dy * dy;
  549. },
  550. manhattanDistanceTo: function ( v ) {
  551. return Math.abs( this.x - v.x ) + Math.abs( this.y - v.y );
  552. },
  553. setLength: function ( length ) {
  554. return this.normalize().multiplyScalar( length );
  555. },
  556. lerp: function ( v, alpha ) {
  557. this.x += ( v.x - this.x ) * alpha;
  558. this.y += ( v.y - this.y ) * alpha;
  559. return this;
  560. },
  561. lerpVectors: function ( v1, v2, alpha ) {
  562. return this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  563. },
  564. equals: function ( v ) {
  565. return ( ( v.x === this.x ) && ( v.y === this.y ) );
  566. },
  567. fromArray: function ( array, offset ) {
  568. if ( offset === undefined ) offset = 0;
  569. this.x = array[ offset ];
  570. this.y = array[ offset + 1 ];
  571. return this;
  572. },
  573. toArray: function ( array, offset ) {
  574. if ( array === undefined ) array = [];
  575. if ( offset === undefined ) offset = 0;
  576. array[ offset ] = this.x;
  577. array[ offset + 1 ] = this.y;
  578. return array;
  579. },
  580. fromBufferAttribute: function ( attribute, index, offset ) {
  581. if ( offset !== undefined ) {
  582. console.warn( 'THREE.Vector2: offset has been removed from .fromBufferAttribute().' );
  583. }
  584. this.x = attribute.getX( index );
  585. this.y = attribute.getY( index );
  586. return this;
  587. },
  588. rotateAround: function ( center, angle ) {
  589. var c = Math.cos( angle ), s = Math.sin( angle );
  590. var x = this.x - center.x;
  591. var y = this.y - center.y;
  592. this.x = x * c - y * s + center.x;
  593. this.y = x * s + y * c + center.y;
  594. return this;
  595. }
  596. } );
  597. /**
  598. * @author mrdoob / http://mrdoob.com/
  599. * @author supereggbert / http://www.paulbrunt.co.uk/
  600. * @author philogb / http://blog.thejit.org/
  601. * @author jordi_ros / http://plattsoft.com
  602. * @author D1plo1d / http://github.com/D1plo1d
  603. * @author alteredq / http://alteredqualia.com/
  604. * @author mikael emtinger / http://gomo.se/
  605. * @author timknip / http://www.floorplanner.com/
  606. * @author bhouston / http://clara.io
  607. * @author WestLangley / http://github.com/WestLangley
  608. */
  609. function Matrix4() {
  610. this.elements = [
  611. 1, 0, 0, 0,
  612. 0, 1, 0, 0,
  613. 0, 0, 1, 0,
  614. 0, 0, 0, 1
  615. ];
  616. if ( arguments.length > 0 ) {
  617. console.error( 'THREE.Matrix4: the constructor no longer reads arguments. use .set() instead.' );
  618. }
  619. }
  620. Object.assign( Matrix4.prototype, {
  621. isMatrix4: true,
  622. set: function ( n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44 ) {
  623. var te = this.elements;
  624. te[ 0 ] = n11; te[ 4 ] = n12; te[ 8 ] = n13; te[ 12 ] = n14;
  625. te[ 1 ] = n21; te[ 5 ] = n22; te[ 9 ] = n23; te[ 13 ] = n24;
  626. te[ 2 ] = n31; te[ 6 ] = n32; te[ 10 ] = n33; te[ 14 ] = n34;
  627. te[ 3 ] = n41; te[ 7 ] = n42; te[ 11 ] = n43; te[ 15 ] = n44;
  628. return this;
  629. },
  630. identity: function () {
  631. this.set(
  632. 1, 0, 0, 0,
  633. 0, 1, 0, 0,
  634. 0, 0, 1, 0,
  635. 0, 0, 0, 1
  636. );
  637. return this;
  638. },
  639. clone: function () {
  640. return new Matrix4().fromArray( this.elements );
  641. },
  642. copy: function ( m ) {
  643. var te = this.elements;
  644. var me = m.elements;
  645. te[ 0 ] = me[ 0 ]; te[ 1 ] = me[ 1 ]; te[ 2 ] = me[ 2 ]; te[ 3 ] = me[ 3 ];
  646. te[ 4 ] = me[ 4 ]; te[ 5 ] = me[ 5 ]; te[ 6 ] = me[ 6 ]; te[ 7 ] = me[ 7 ];
  647. te[ 8 ] = me[ 8 ]; te[ 9 ] = me[ 9 ]; te[ 10 ] = me[ 10 ]; te[ 11 ] = me[ 11 ];
  648. te[ 12 ] = me[ 12 ]; te[ 13 ] = me[ 13 ]; te[ 14 ] = me[ 14 ]; te[ 15 ] = me[ 15 ];
  649. return this;
  650. },
  651. copyPosition: function ( m ) {
  652. var te = this.elements, me = m.elements;
  653. te[ 12 ] = me[ 12 ];
  654. te[ 13 ] = me[ 13 ];
  655. te[ 14 ] = me[ 14 ];
  656. return this;
  657. },
  658. extractBasis: function ( xAxis, yAxis, zAxis ) {
  659. xAxis.setFromMatrixColumn( this, 0 );
  660. yAxis.setFromMatrixColumn( this, 1 );
  661. zAxis.setFromMatrixColumn( this, 2 );
  662. return this;
  663. },
  664. makeBasis: function ( xAxis, yAxis, zAxis ) {
  665. this.set(
  666. xAxis.x, yAxis.x, zAxis.x, 0,
  667. xAxis.y, yAxis.y, zAxis.y, 0,
  668. xAxis.z, yAxis.z, zAxis.z, 0,
  669. 0, 0, 0, 1
  670. );
  671. return this;
  672. },
  673. extractRotation: function () {
  674. var v1 = new Vector3();
  675. return function extractRotation( m ) {
  676. // this method does not support reflection matrices
  677. var te = this.elements;
  678. var me = m.elements;
  679. var scaleX = 1 / v1.setFromMatrixColumn( m, 0 ).length();
  680. var scaleY = 1 / v1.setFromMatrixColumn( m, 1 ).length();
  681. var scaleZ = 1 / v1.setFromMatrixColumn( m, 2 ).length();
  682. te[ 0 ] = me[ 0 ] * scaleX;
  683. te[ 1 ] = me[ 1 ] * scaleX;
  684. te[ 2 ] = me[ 2 ] * scaleX;
  685. te[ 3 ] = 0;
  686. te[ 4 ] = me[ 4 ] * scaleY;
  687. te[ 5 ] = me[ 5 ] * scaleY;
  688. te[ 6 ] = me[ 6 ] * scaleY;
  689. te[ 7 ] = 0;
  690. te[ 8 ] = me[ 8 ] * scaleZ;
  691. te[ 9 ] = me[ 9 ] * scaleZ;
  692. te[ 10 ] = me[ 10 ] * scaleZ;
  693. te[ 11 ] = 0;
  694. te[ 12 ] = 0;
  695. te[ 13 ] = 0;
  696. te[ 14 ] = 0;
  697. te[ 15 ] = 1;
  698. return this;
  699. };
  700. }(),
  701. makeRotationFromEuler: function ( euler ) {
  702. if ( ! ( euler && euler.isEuler ) ) {
  703. console.error( 'THREE.Matrix4: .makeRotationFromEuler() now expects a Euler rotation rather than a Vector3 and order.' );
  704. }
  705. var te = this.elements;
  706. var x = euler.x, y = euler.y, z = euler.z;
  707. var a = Math.cos( x ), b = Math.sin( x );
  708. var c = Math.cos( y ), d = Math.sin( y );
  709. var e = Math.cos( z ), f = Math.sin( z );
  710. if ( euler.order === 'XYZ' ) {
  711. var ae = a * e, af = a * f, be = b * e, bf = b * f;
  712. te[ 0 ] = c * e;
  713. te[ 4 ] = - c * f;
  714. te[ 8 ] = d;
  715. te[ 1 ] = af + be * d;
  716. te[ 5 ] = ae - bf * d;
  717. te[ 9 ] = - b * c;
  718. te[ 2 ] = bf - ae * d;
  719. te[ 6 ] = be + af * d;
  720. te[ 10 ] = a * c;
  721. } else if ( euler.order === 'YXZ' ) {
  722. var ce = c * e, cf = c * f, de = d * e, df = d * f;
  723. te[ 0 ] = ce + df * b;
  724. te[ 4 ] = de * b - cf;
  725. te[ 8 ] = a * d;
  726. te[ 1 ] = a * f;
  727. te[ 5 ] = a * e;
  728. te[ 9 ] = - b;
  729. te[ 2 ] = cf * b - de;
  730. te[ 6 ] = df + ce * b;
  731. te[ 10 ] = a * c;
  732. } else if ( euler.order === 'ZXY' ) {
  733. var ce = c * e, cf = c * f, de = d * e, df = d * f;
  734. te[ 0 ] = ce - df * b;
  735. te[ 4 ] = - a * f;
  736. te[ 8 ] = de + cf * b;
  737. te[ 1 ] = cf + de * b;
  738. te[ 5 ] = a * e;
  739. te[ 9 ] = df - ce * b;
  740. te[ 2 ] = - a * d;
  741. te[ 6 ] = b;
  742. te[ 10 ] = a * c;
  743. } else if ( euler.order === 'ZYX' ) {
  744. var ae = a * e, af = a * f, be = b * e, bf = b * f;
  745. te[ 0 ] = c * e;
  746. te[ 4 ] = be * d - af;
  747. te[ 8 ] = ae * d + bf;
  748. te[ 1 ] = c * f;
  749. te[ 5 ] = bf * d + ae;
  750. te[ 9 ] = af * d - be;
  751. te[ 2 ] = - d;
  752. te[ 6 ] = b * c;
  753. te[ 10 ] = a * c;
  754. } else if ( euler.order === 'YZX' ) {
  755. var ac = a * c, ad = a * d, bc = b * c, bd = b * d;
  756. te[ 0 ] = c * e;
  757. te[ 4 ] = bd - ac * f;
  758. te[ 8 ] = bc * f + ad;
  759. te[ 1 ] = f;
  760. te[ 5 ] = a * e;
  761. te[ 9 ] = - b * e;
  762. te[ 2 ] = - d * e;
  763. te[ 6 ] = ad * f + bc;
  764. te[ 10 ] = ac - bd * f;
  765. } else if ( euler.order === 'XZY' ) {
  766. var ac = a * c, ad = a * d, bc = b * c, bd = b * d;
  767. te[ 0 ] = c * e;
  768. te[ 4 ] = - f;
  769. te[ 8 ] = d * e;
  770. te[ 1 ] = ac * f + bd;
  771. te[ 5 ] = a * e;
  772. te[ 9 ] = ad * f - bc;
  773. te[ 2 ] = bc * f - ad;
  774. te[ 6 ] = b * e;
  775. te[ 10 ] = bd * f + ac;
  776. }
  777. // bottom row
  778. te[ 3 ] = 0;
  779. te[ 7 ] = 0;
  780. te[ 11 ] = 0;
  781. // last column
  782. te[ 12 ] = 0;
  783. te[ 13 ] = 0;
  784. te[ 14 ] = 0;
  785. te[ 15 ] = 1;
  786. return this;
  787. },
  788. makeRotationFromQuaternion: function () {
  789. var zero = new Vector3( 0, 0, 0 );
  790. var one = new Vector3( 1, 1, 1 );
  791. return function makeRotationFromQuaternion( q ) {
  792. return this.compose( zero, q, one );
  793. };
  794. }(),
  795. lookAt: function () {
  796. var x = new Vector3();
  797. var y = new Vector3();
  798. var z = new Vector3();
  799. return function lookAt( eye, target, up ) {
  800. var te = this.elements;
  801. z.subVectors( eye, target );
  802. if ( z.lengthSq() === 0 ) {
  803. // eye and target are in the same position
  804. z.z = 1;
  805. }
  806. z.normalize();
  807. x.crossVectors( up, z );
  808. if ( x.lengthSq() === 0 ) {
  809. // up and z are parallel
  810. if ( Math.abs( up.z ) === 1 ) {
  811. z.x += 0.0001;
  812. } else {
  813. z.z += 0.0001;
  814. }
  815. z.normalize();
  816. x.crossVectors( up, z );
  817. }
  818. x.normalize();
  819. y.crossVectors( z, x );
  820. te[ 0 ] = x.x; te[ 4 ] = y.x; te[ 8 ] = z.x;
  821. te[ 1 ] = x.y; te[ 5 ] = y.y; te[ 9 ] = z.y;
  822. te[ 2 ] = x.z; te[ 6 ] = y.z; te[ 10 ] = z.z;
  823. return this;
  824. };
  825. }(),
  826. multiply: function ( m, n ) {
  827. if ( n !== undefined ) {
  828. console.warn( 'THREE.Matrix4: .multiply() now only accepts one argument. Use .multiplyMatrices( a, b ) instead.' );
  829. return this.multiplyMatrices( m, n );
  830. }
  831. return this.multiplyMatrices( this, m );
  832. },
  833. premultiply: function ( m ) {
  834. return this.multiplyMatrices( m, this );
  835. },
  836. multiplyMatrices: function ( a, b ) {
  837. var ae = a.elements;
  838. var be = b.elements;
  839. var te = this.elements;
  840. var a11 = ae[ 0 ], a12 = ae[ 4 ], a13 = ae[ 8 ], a14 = ae[ 12 ];
  841. var a21 = ae[ 1 ], a22 = ae[ 5 ], a23 = ae[ 9 ], a24 = ae[ 13 ];
  842. var a31 = ae[ 2 ], a32 = ae[ 6 ], a33 = ae[ 10 ], a34 = ae[ 14 ];
  843. var a41 = ae[ 3 ], a42 = ae[ 7 ], a43 = ae[ 11 ], a44 = ae[ 15 ];
  844. var b11 = be[ 0 ], b12 = be[ 4 ], b13 = be[ 8 ], b14 = be[ 12 ];
  845. var b21 = be[ 1 ], b22 = be[ 5 ], b23 = be[ 9 ], b24 = be[ 13 ];
  846. var b31 = be[ 2 ], b32 = be[ 6 ], b33 = be[ 10 ], b34 = be[ 14 ];
  847. var b41 = be[ 3 ], b42 = be[ 7 ], b43 = be[ 11 ], b44 = be[ 15 ];
  848. te[ 0 ] = a11 * b11 + a12 * b21 + a13 * b31 + a14 * b41;
  849. te[ 4 ] = a11 * b12 + a12 * b22 + a13 * b32 + a14 * b42;
  850. te[ 8 ] = a11 * b13 + a12 * b23 + a13 * b33 + a14 * b43;
  851. te[ 12 ] = a11 * b14 + a12 * b24 + a13 * b34 + a14 * b44;
  852. te[ 1 ] = a21 * b11 + a22 * b21 + a23 * b31 + a24 * b41;
  853. te[ 5 ] = a21 * b12 + a22 * b22 + a23 * b32 + a24 * b42;
  854. te[ 9 ] = a21 * b13 + a22 * b23 + a23 * b33 + a24 * b43;
  855. te[ 13 ] = a21 * b14 + a22 * b24 + a23 * b34 + a24 * b44;
  856. te[ 2 ] = a31 * b11 + a32 * b21 + a33 * b31 + a34 * b41;
  857. te[ 6 ] = a31 * b12 + a32 * b22 + a33 * b32 + a34 * b42;
  858. te[ 10 ] = a31 * b13 + a32 * b23 + a33 * b33 + a34 * b43;
  859. te[ 14 ] = a31 * b14 + a32 * b24 + a33 * b34 + a34 * b44;
  860. te[ 3 ] = a41 * b11 + a42 * b21 + a43 * b31 + a44 * b41;
  861. te[ 7 ] = a41 * b12 + a42 * b22 + a43 * b32 + a44 * b42;
  862. te[ 11 ] = a41 * b13 + a42 * b23 + a43 * b33 + a44 * b43;
  863. te[ 15 ] = a41 * b14 + a42 * b24 + a43 * b34 + a44 * b44;
  864. return this;
  865. },
  866. multiplyScalar: function ( s ) {
  867. var te = this.elements;
  868. te[ 0 ] *= s; te[ 4 ] *= s; te[ 8 ] *= s; te[ 12 ] *= s;
  869. te[ 1 ] *= s; te[ 5 ] *= s; te[ 9 ] *= s; te[ 13 ] *= s;
  870. te[ 2 ] *= s; te[ 6 ] *= s; te[ 10 ] *= s; te[ 14 ] *= s;
  871. te[ 3 ] *= s; te[ 7 ] *= s; te[ 11 ] *= s; te[ 15 ] *= s;
  872. return this;
  873. },
  874. applyToBufferAttribute: function () {
  875. var v1 = new Vector3();
  876. return function applyToBufferAttribute( attribute ) {
  877. for ( var i = 0, l = attribute.count; i < l; i ++ ) {
  878. v1.x = attribute.getX( i );
  879. v1.y = attribute.getY( i );
  880. v1.z = attribute.getZ( i );
  881. v1.applyMatrix4( this );
  882. attribute.setXYZ( i, v1.x, v1.y, v1.z );
  883. }
  884. return attribute;
  885. };
  886. }(),
  887. determinant: function () {
  888. var te = this.elements;
  889. var n11 = te[ 0 ], n12 = te[ 4 ], n13 = te[ 8 ], n14 = te[ 12 ];
  890. var n21 = te[ 1 ], n22 = te[ 5 ], n23 = te[ 9 ], n24 = te[ 13 ];
  891. var n31 = te[ 2 ], n32 = te[ 6 ], n33 = te[ 10 ], n34 = te[ 14 ];
  892. var n41 = te[ 3 ], n42 = te[ 7 ], n43 = te[ 11 ], n44 = te[ 15 ];
  893. //TODO: make this more efficient
  894. //( based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm )
  895. return (
  896. n41 * (
  897. + n14 * n23 * n32
  898. - n13 * n24 * n32
  899. - n14 * n22 * n33
  900. + n12 * n24 * n33
  901. + n13 * n22 * n34
  902. - n12 * n23 * n34
  903. ) +
  904. n42 * (
  905. + n11 * n23 * n34
  906. - n11 * n24 * n33
  907. + n14 * n21 * n33
  908. - n13 * n21 * n34
  909. + n13 * n24 * n31
  910. - n14 * n23 * n31
  911. ) +
  912. n43 * (
  913. + n11 * n24 * n32
  914. - n11 * n22 * n34
  915. - n14 * n21 * n32
  916. + n12 * n21 * n34
  917. + n14 * n22 * n31
  918. - n12 * n24 * n31
  919. ) +
  920. n44 * (
  921. - n13 * n22 * n31
  922. - n11 * n23 * n32
  923. + n11 * n22 * n33
  924. + n13 * n21 * n32
  925. - n12 * n21 * n33
  926. + n12 * n23 * n31
  927. )
  928. );
  929. },
  930. transpose: function () {
  931. var te = this.elements;
  932. var tmp;
  933. tmp = te[ 1 ]; te[ 1 ] = te[ 4 ]; te[ 4 ] = tmp;
  934. tmp = te[ 2 ]; te[ 2 ] = te[ 8 ]; te[ 8 ] = tmp;
  935. tmp = te[ 6 ]; te[ 6 ] = te[ 9 ]; te[ 9 ] = tmp;
  936. tmp = te[ 3 ]; te[ 3 ] = te[ 12 ]; te[ 12 ] = tmp;
  937. tmp = te[ 7 ]; te[ 7 ] = te[ 13 ]; te[ 13 ] = tmp;
  938. tmp = te[ 11 ]; te[ 11 ] = te[ 14 ]; te[ 14 ] = tmp;
  939. return this;
  940. },
  941. setPosition: function ( v ) {
  942. var te = this.elements;
  943. te[ 12 ] = v.x;
  944. te[ 13 ] = v.y;
  945. te[ 14 ] = v.z;
  946. return this;
  947. },
  948. getInverse: function ( m, throwOnDegenerate ) {
  949. // based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm
  950. var te = this.elements,
  951. me = m.elements,
  952. n11 = me[ 0 ], n21 = me[ 1 ], n31 = me[ 2 ], n41 = me[ 3 ],
  953. n12 = me[ 4 ], n22 = me[ 5 ], n32 = me[ 6 ], n42 = me[ 7 ],
  954. n13 = me[ 8 ], n23 = me[ 9 ], n33 = me[ 10 ], n43 = me[ 11 ],
  955. n14 = me[ 12 ], n24 = me[ 13 ], n34 = me[ 14 ], n44 = me[ 15 ],
  956. t11 = n23 * n34 * n42 - n24 * n33 * n42 + n24 * n32 * n43 - n22 * n34 * n43 - n23 * n32 * n44 + n22 * n33 * n44,
  957. t12 = n14 * n33 * n42 - n13 * n34 * n42 - n14 * n32 * n43 + n12 * n34 * n43 + n13 * n32 * n44 - n12 * n33 * n44,
  958. t13 = n13 * n24 * n42 - n14 * n23 * n42 + n14 * n22 * n43 - n12 * n24 * n43 - n13 * n22 * n44 + n12 * n23 * n44,
  959. t14 = n14 * n23 * n32 - n13 * n24 * n32 - n14 * n22 * n33 + n12 * n24 * n33 + n13 * n22 * n34 - n12 * n23 * n34;
  960. var det = n11 * t11 + n21 * t12 + n31 * t13 + n41 * t14;
  961. if ( det === 0 ) {
  962. var msg = "THREE.Matrix4: .getInverse() can't invert matrix, determinant is 0";
  963. if ( throwOnDegenerate === true ) {
  964. throw new Error( msg );
  965. } else {
  966. console.warn( msg );
  967. }
  968. return this.identity();
  969. }
  970. var detInv = 1 / det;
  971. te[ 0 ] = t11 * detInv;
  972. te[ 1 ] = ( n24 * n33 * n41 - n23 * n34 * n41 - n24 * n31 * n43 + n21 * n34 * n43 + n23 * n31 * n44 - n21 * n33 * n44 ) * detInv;
  973. te[ 2 ] = ( n22 * n34 * n41 - n24 * n32 * n41 + n24 * n31 * n42 - n21 * n34 * n42 - n22 * n31 * n44 + n21 * n32 * n44 ) * detInv;
  974. te[ 3 ] = ( n23 * n32 * n41 - n22 * n33 * n41 - n23 * n31 * n42 + n21 * n33 * n42 + n22 * n31 * n43 - n21 * n32 * n43 ) * detInv;
  975. te[ 4 ] = t12 * detInv;
  976. te[ 5 ] = ( n13 * n34 * n41 - n14 * n33 * n41 + n14 * n31 * n43 - n11 * n34 * n43 - n13 * n31 * n44 + n11 * n33 * n44 ) * detInv;
  977. te[ 6 ] = ( n14 * n32 * n41 - n12 * n34 * n41 - n14 * n31 * n42 + n11 * n34 * n42 + n12 * n31 * n44 - n11 * n32 * n44 ) * detInv;
  978. te[ 7 ] = ( n12 * n33 * n41 - n13 * n32 * n41 + n13 * n31 * n42 - n11 * n33 * n42 - n12 * n31 * n43 + n11 * n32 * n43 ) * detInv;
  979. te[ 8 ] = t13 * detInv;
  980. te[ 9 ] = ( n14 * n23 * n41 - n13 * n24 * n41 - n14 * n21 * n43 + n11 * n24 * n43 + n13 * n21 * n44 - n11 * n23 * n44 ) * detInv;
  981. te[ 10 ] = ( n12 * n24 * n41 - n14 * n22 * n41 + n14 * n21 * n42 - n11 * n24 * n42 - n12 * n21 * n44 + n11 * n22 * n44 ) * detInv;
  982. te[ 11 ] = ( n13 * n22 * n41 - n12 * n23 * n41 - n13 * n21 * n42 + n11 * n23 * n42 + n12 * n21 * n43 - n11 * n22 * n43 ) * detInv;
  983. te[ 12 ] = t14 * detInv;
  984. te[ 13 ] = ( n13 * n24 * n31 - n14 * n23 * n31 + n14 * n21 * n33 - n11 * n24 * n33 - n13 * n21 * n34 + n11 * n23 * n34 ) * detInv;
  985. te[ 14 ] = ( n14 * n22 * n31 - n12 * n24 * n31 - n14 * n21 * n32 + n11 * n24 * n32 + n12 * n21 * n34 - n11 * n22 * n34 ) * detInv;
  986. te[ 15 ] = ( n12 * n23 * n31 - n13 * n22 * n31 + n13 * n21 * n32 - n11 * n23 * n32 - n12 * n21 * n33 + n11 * n22 * n33 ) * detInv;
  987. return this;
  988. },
  989. scale: function ( v ) {
  990. var te = this.elements;
  991. var x = v.x, y = v.y, z = v.z;
  992. te[ 0 ] *= x; te[ 4 ] *= y; te[ 8 ] *= z;
  993. te[ 1 ] *= x; te[ 5 ] *= y; te[ 9 ] *= z;
  994. te[ 2 ] *= x; te[ 6 ] *= y; te[ 10 ] *= z;
  995. te[ 3 ] *= x; te[ 7 ] *= y; te[ 11 ] *= z;
  996. return this;
  997. },
  998. getMaxScaleOnAxis: function () {
  999. var te = this.elements;
  1000. var scaleXSq = te[ 0 ] * te[ 0 ] + te[ 1 ] * te[ 1 ] + te[ 2 ] * te[ 2 ];
  1001. var scaleYSq = te[ 4 ] * te[ 4 ] + te[ 5 ] * te[ 5 ] + te[ 6 ] * te[ 6 ];
  1002. var scaleZSq = te[ 8 ] * te[ 8 ] + te[ 9 ] * te[ 9 ] + te[ 10 ] * te[ 10 ];
  1003. return Math.sqrt( Math.max( scaleXSq, scaleYSq, scaleZSq ) );
  1004. },
  1005. makeTranslation: function ( x, y, z ) {
  1006. this.set(
  1007. 1, 0, 0, x,
  1008. 0, 1, 0, y,
  1009. 0, 0, 1, z,
  1010. 0, 0, 0, 1
  1011. );
  1012. return this;
  1013. },
  1014. makeRotationX: function ( theta ) {
  1015. var c = Math.cos( theta ), s = Math.sin( theta );
  1016. this.set(
  1017. 1, 0, 0, 0,
  1018. 0, c, - s, 0,
  1019. 0, s, c, 0,
  1020. 0, 0, 0, 1
  1021. );
  1022. return this;
  1023. },
  1024. makeRotationY: function ( theta ) {
  1025. var c = Math.cos( theta ), s = Math.sin( theta );
  1026. this.set(
  1027. c, 0, s, 0,
  1028. 0, 1, 0, 0,
  1029. - s, 0, c, 0,
  1030. 0, 0, 0, 1
  1031. );
  1032. return this;
  1033. },
  1034. makeRotationZ: function ( theta ) {
  1035. var c = Math.cos( theta ), s = Math.sin( theta );
  1036. this.set(
  1037. c, - s, 0, 0,
  1038. s, c, 0, 0,
  1039. 0, 0, 1, 0,
  1040. 0, 0, 0, 1
  1041. );
  1042. return this;
  1043. },
  1044. makeRotationAxis: function ( axis, angle ) {
  1045. // Based on http://www.gamedev.net/reference/articles/article1199.asp
  1046. var c = Math.cos( angle );
  1047. var s = Math.sin( angle );
  1048. var t = 1 - c;
  1049. var x = axis.x, y = axis.y, z = axis.z;
  1050. var tx = t * x, ty = t * y;
  1051. this.set(
  1052. tx * x + c, tx * y - s * z, tx * z + s * y, 0,
  1053. tx * y + s * z, ty * y + c, ty * z - s * x, 0,
  1054. tx * z - s * y, ty * z + s * x, t * z * z + c, 0,
  1055. 0, 0, 0, 1
  1056. );
  1057. return this;
  1058. },
  1059. makeScale: function ( x, y, z ) {
  1060. this.set(
  1061. x, 0, 0, 0,
  1062. 0, y, 0, 0,
  1063. 0, 0, z, 0,
  1064. 0, 0, 0, 1
  1065. );
  1066. return this;
  1067. },
  1068. makeShear: function ( x, y, z ) {
  1069. this.set(
  1070. 1, y, z, 0,
  1071. x, 1, z, 0,
  1072. x, y, 1, 0,
  1073. 0, 0, 0, 1
  1074. );
  1075. return this;
  1076. },
  1077. compose: function ( position, quaternion, scale ) {
  1078. var te = this.elements;
  1079. var x = quaternion._x, y = quaternion._y, z = quaternion._z, w = quaternion._w;
  1080. var x2 = x + x, y2 = y + y, z2 = z + z;
  1081. var xx = x * x2, xy = x * y2, xz = x * z2;
  1082. var yy = y * y2, yz = y * z2, zz = z * z2;
  1083. var wx = w * x2, wy = w * y2, wz = w * z2;
  1084. var sx = scale.x, sy = scale.y, sz = scale.z;
  1085. te[ 0 ] = ( 1 - ( yy + zz ) ) * sx;
  1086. te[ 1 ] = ( xy + wz ) * sx;
  1087. te[ 2 ] = ( xz - wy ) * sx;
  1088. te[ 3 ] = 0;
  1089. te[ 4 ] = ( xy - wz ) * sy;
  1090. te[ 5 ] = ( 1 - ( xx + zz ) ) * sy;
  1091. te[ 6 ] = ( yz + wx ) * sy;
  1092. te[ 7 ] = 0;
  1093. te[ 8 ] = ( xz + wy ) * sz;
  1094. te[ 9 ] = ( yz - wx ) * sz;
  1095. te[ 10 ] = ( 1 - ( xx + yy ) ) * sz;
  1096. te[ 11 ] = 0;
  1097. te[ 12 ] = position.x;
  1098. te[ 13 ] = position.y;
  1099. te[ 14 ] = position.z;
  1100. te[ 15 ] = 1;
  1101. return this;
  1102. },
  1103. decompose: function () {
  1104. var vector = new Vector3();
  1105. var matrix = new Matrix4();
  1106. return function decompose( position, quaternion, scale ) {
  1107. var te = this.elements;
  1108. var sx = vector.set( te[ 0 ], te[ 1 ], te[ 2 ] ).length();
  1109. var sy = vector.set( te[ 4 ], te[ 5 ], te[ 6 ] ).length();
  1110. var sz = vector.set( te[ 8 ], te[ 9 ], te[ 10 ] ).length();
  1111. // if determine is negative, we need to invert one scale
  1112. var det = this.determinant();
  1113. if ( det < 0 ) sx = - sx;
  1114. position.x = te[ 12 ];
  1115. position.y = te[ 13 ];
  1116. position.z = te[ 14 ];
  1117. // scale the rotation part
  1118. matrix.copy( this );
  1119. var invSX = 1 / sx;
  1120. var invSY = 1 / sy;
  1121. var invSZ = 1 / sz;
  1122. matrix.elements[ 0 ] *= invSX;
  1123. matrix.elements[ 1 ] *= invSX;
  1124. matrix.elements[ 2 ] *= invSX;
  1125. matrix.elements[ 4 ] *= invSY;
  1126. matrix.elements[ 5 ] *= invSY;
  1127. matrix.elements[ 6 ] *= invSY;
  1128. matrix.elements[ 8 ] *= invSZ;
  1129. matrix.elements[ 9 ] *= invSZ;
  1130. matrix.elements[ 10 ] *= invSZ;
  1131. quaternion.setFromRotationMatrix( matrix );
  1132. scale.x = sx;
  1133. scale.y = sy;
  1134. scale.z = sz;
  1135. return this;
  1136. };
  1137. }(),
  1138. makePerspective: function ( left, right, top, bottom, near, far ) {
  1139. if ( far === undefined ) {
  1140. console.warn( 'THREE.Matrix4: .makePerspective() has been redefined and has a new signature. Please check the docs.' );
  1141. }
  1142. var te = this.elements;
  1143. var x = 2 * near / ( right - left );
  1144. var y = 2 * near / ( top - bottom );
  1145. var a = ( right + left ) / ( right - left );
  1146. var b = ( top + bottom ) / ( top - bottom );
  1147. var c = - ( far + near ) / ( far - near );
  1148. var d = - 2 * far * near / ( far - near );
  1149. te[ 0 ] = x; te[ 4 ] = 0; te[ 8 ] = a; te[ 12 ] = 0;
  1150. te[ 1 ] = 0; te[ 5 ] = y; te[ 9 ] = b; te[ 13 ] = 0;
  1151. te[ 2 ] = 0; te[ 6 ] = 0; te[ 10 ] = c; te[ 14 ] = d;
  1152. te[ 3 ] = 0; te[ 7 ] = 0; te[ 11 ] = - 1; te[ 15 ] = 0;
  1153. return this;
  1154. },
  1155. makeOrthographic: function ( left, right, top, bottom, near, far ) {
  1156. var te = this.elements;
  1157. var w = 1.0 / ( right - left );
  1158. var h = 1.0 / ( top - bottom );
  1159. var p = 1.0 / ( far - near );
  1160. var x = ( right + left ) * w;
  1161. var y = ( top + bottom ) * h;
  1162. var z = ( far + near ) * p;
  1163. te[ 0 ] = 2 * w; te[ 4 ] = 0; te[ 8 ] = 0; te[ 12 ] = - x;
  1164. te[ 1 ] = 0; te[ 5 ] = 2 * h; te[ 9 ] = 0; te[ 13 ] = - y;
  1165. te[ 2 ] = 0; te[ 6 ] = 0; te[ 10 ] = - 2 * p; te[ 14 ] = - z;
  1166. te[ 3 ] = 0; te[ 7 ] = 0; te[ 11 ] = 0; te[ 15 ] = 1;
  1167. return this;
  1168. },
  1169. equals: function ( matrix ) {
  1170. var te = this.elements;
  1171. var me = matrix.elements;
  1172. for ( var i = 0; i < 16; i ++ ) {
  1173. if ( te[ i ] !== me[ i ] ) return false;
  1174. }
  1175. return true;
  1176. },
  1177. fromArray: function ( array, offset ) {
  1178. if ( offset === undefined ) offset = 0;
  1179. for ( var i = 0; i < 16; i ++ ) {
  1180. this.elements[ i ] = array[ i + offset ];
  1181. }
  1182. return this;
  1183. },
  1184. toArray: function ( array, offset ) {
  1185. if ( array === undefined ) array = [];
  1186. if ( offset === undefined ) offset = 0;
  1187. var te = this.elements;
  1188. array[ offset ] = te[ 0 ];
  1189. array[ offset + 1 ] = te[ 1 ];
  1190. array[ offset + 2 ] = te[ 2 ];
  1191. array[ offset + 3 ] = te[ 3 ];
  1192. array[ offset + 4 ] = te[ 4 ];
  1193. array[ offset + 5 ] = te[ 5 ];
  1194. array[ offset + 6 ] = te[ 6 ];
  1195. array[ offset + 7 ] = te[ 7 ];
  1196. array[ offset + 8 ] = te[ 8 ];
  1197. array[ offset + 9 ] = te[ 9 ];
  1198. array[ offset + 10 ] = te[ 10 ];
  1199. array[ offset + 11 ] = te[ 11 ];
  1200. array[ offset + 12 ] = te[ 12 ];
  1201. array[ offset + 13 ] = te[ 13 ];
  1202. array[ offset + 14 ] = te[ 14 ];
  1203. array[ offset + 15 ] = te[ 15 ];
  1204. return array;
  1205. }
  1206. } );
  1207. /**
  1208. * @author mikael emtinger / http://gomo.se/
  1209. * @author alteredq / http://alteredqualia.com/
  1210. * @author WestLangley / http://github.com/WestLangley
  1211. * @author bhouston / http://clara.io
  1212. */
  1213. function Quaternion( x, y, z, w ) {
  1214. this._x = x || 0;
  1215. this._y = y || 0;
  1216. this._z = z || 0;
  1217. this._w = ( w !== undefined ) ? w : 1;
  1218. }
  1219. Object.assign( Quaternion, {
  1220. slerp: function ( qa, qb, qm, t ) {
  1221. return qm.copy( qa ).slerp( qb, t );
  1222. },
  1223. slerpFlat: function ( dst, dstOffset, src0, srcOffset0, src1, srcOffset1, t ) {
  1224. // fuzz-free, array-based Quaternion SLERP operation
  1225. var x0 = src0[ srcOffset0 + 0 ],
  1226. y0 = src0[ srcOffset0 + 1 ],
  1227. z0 = src0[ srcOffset0 + 2 ],
  1228. w0 = src0[ srcOffset0 + 3 ],
  1229. x1 = src1[ srcOffset1 + 0 ],
  1230. y1 = src1[ srcOffset1 + 1 ],
  1231. z1 = src1[ srcOffset1 + 2 ],
  1232. w1 = src1[ srcOffset1 + 3 ];
  1233. if ( w0 !== w1 || x0 !== x1 || y0 !== y1 || z0 !== z1 ) {
  1234. var s = 1 - t,
  1235. cos = x0 * x1 + y0 * y1 + z0 * z1 + w0 * w1,
  1236. dir = ( cos >= 0 ? 1 : - 1 ),
  1237. sqrSin = 1 - cos * cos;
  1238. // Skip the Slerp for tiny steps to avoid numeric problems:
  1239. if ( sqrSin > Number.EPSILON ) {
  1240. var sin = Math.sqrt( sqrSin ),
  1241. len = Math.atan2( sin, cos * dir );
  1242. s = Math.sin( s * len ) / sin;
  1243. t = Math.sin( t * len ) / sin;
  1244. }
  1245. var tDir = t * dir;
  1246. x0 = x0 * s + x1 * tDir;
  1247. y0 = y0 * s + y1 * tDir;
  1248. z0 = z0 * s + z1 * tDir;
  1249. w0 = w0 * s + w1 * tDir;
  1250. // Normalize in case we just did a lerp:
  1251. if ( s === 1 - t ) {
  1252. var f = 1 / Math.sqrt( x0 * x0 + y0 * y0 + z0 * z0 + w0 * w0 );
  1253. x0 *= f;
  1254. y0 *= f;
  1255. z0 *= f;
  1256. w0 *= f;
  1257. }
  1258. }
  1259. dst[ dstOffset ] = x0;
  1260. dst[ dstOffset + 1 ] = y0;
  1261. dst[ dstOffset + 2 ] = z0;
  1262. dst[ dstOffset + 3 ] = w0;
  1263. }
  1264. } );
  1265. Object.defineProperties( Quaternion.prototype, {
  1266. x: {
  1267. get: function () {
  1268. return this._x;
  1269. },
  1270. set: function ( value ) {
  1271. this._x = value;
  1272. this.onChangeCallback();
  1273. }
  1274. },
  1275. y: {
  1276. get: function () {
  1277. return this._y;
  1278. },
  1279. set: function ( value ) {
  1280. this._y = value;
  1281. this.onChangeCallback();
  1282. }
  1283. },
  1284. z: {
  1285. get: function () {
  1286. return this._z;
  1287. },
  1288. set: function ( value ) {
  1289. this._z = value;
  1290. this.onChangeCallback();
  1291. }
  1292. },
  1293. w: {
  1294. get: function () {
  1295. return this._w;
  1296. },
  1297. set: function ( value ) {
  1298. this._w = value;
  1299. this.onChangeCallback();
  1300. }
  1301. }
  1302. } );
  1303. Object.assign( Quaternion.prototype, {
  1304. isQuaternion: true,
  1305. set: function ( x, y, z, w ) {
  1306. this._x = x;
  1307. this._y = y;
  1308. this._z = z;
  1309. this._w = w;
  1310. this.onChangeCallback();
  1311. return this;
  1312. },
  1313. clone: function () {
  1314. return new this.constructor( this._x, this._y, this._z, this._w );
  1315. },
  1316. copy: function ( quaternion ) {
  1317. this._x = quaternion.x;
  1318. this._y = quaternion.y;
  1319. this._z = quaternion.z;
  1320. this._w = quaternion.w;
  1321. this.onChangeCallback();
  1322. return this;
  1323. },
  1324. setFromEuler: function ( euler, update ) {
  1325. if ( ! ( euler && euler.isEuler ) ) {
  1326. throw new Error( 'THREE.Quaternion: .setFromEuler() now expects an Euler rotation rather than a Vector3 and order.' );
  1327. }
  1328. var x = euler._x, y = euler._y, z = euler._z, order = euler.order;
  1329. // http://www.mathworks.com/matlabcentral/fileexchange/
  1330. // 20696-function-to-convert-between-dcm-euler-angles-quaternions-and-euler-vectors/
  1331. // content/SpinCalc.m
  1332. var cos = Math.cos;
  1333. var sin = Math.sin;
  1334. var c1 = cos( x / 2 );
  1335. var c2 = cos( y / 2 );
  1336. var c3 = cos( z / 2 );
  1337. var s1 = sin( x / 2 );
  1338. var s2 = sin( y / 2 );
  1339. var s3 = sin( z / 2 );
  1340. if ( order === 'XYZ' ) {
  1341. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  1342. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  1343. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  1344. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  1345. } else if ( order === 'YXZ' ) {
  1346. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  1347. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  1348. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  1349. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  1350. } else if ( order === 'ZXY' ) {
  1351. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  1352. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  1353. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  1354. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  1355. } else if ( order === 'ZYX' ) {
  1356. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  1357. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  1358. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  1359. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  1360. } else if ( order === 'YZX' ) {
  1361. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  1362. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  1363. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  1364. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  1365. } else if ( order === 'XZY' ) {
  1366. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  1367. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  1368. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  1369. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  1370. }
  1371. if ( update !== false ) this.onChangeCallback();
  1372. return this;
  1373. },
  1374. setFromAxisAngle: function ( axis, angle ) {
  1375. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToQuaternion/index.htm
  1376. // assumes axis is normalized
  1377. var halfAngle = angle / 2, s = Math.sin( halfAngle );
  1378. this._x = axis.x * s;
  1379. this._y = axis.y * s;
  1380. this._z = axis.z * s;
  1381. this._w = Math.cos( halfAngle );
  1382. this.onChangeCallback();
  1383. return this;
  1384. },
  1385. setFromRotationMatrix: function ( m ) {
  1386. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm
  1387. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  1388. var te = m.elements,
  1389. m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ],
  1390. m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ],
  1391. m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ],
  1392. trace = m11 + m22 + m33,
  1393. s;
  1394. if ( trace > 0 ) {
  1395. s = 0.5 / Math.sqrt( trace + 1.0 );
  1396. this._w = 0.25 / s;
  1397. this._x = ( m32 - m23 ) * s;
  1398. this._y = ( m13 - m31 ) * s;
  1399. this._z = ( m21 - m12 ) * s;
  1400. } else if ( m11 > m22 && m11 > m33 ) {
  1401. s = 2.0 * Math.sqrt( 1.0 + m11 - m22 - m33 );
  1402. this._w = ( m32 - m23 ) / s;
  1403. this._x = 0.25 * s;
  1404. this._y = ( m12 + m21 ) / s;
  1405. this._z = ( m13 + m31 ) / s;
  1406. } else if ( m22 > m33 ) {
  1407. s = 2.0 * Math.sqrt( 1.0 + m22 - m11 - m33 );
  1408. this._w = ( m13 - m31 ) / s;
  1409. this._x = ( m12 + m21 ) / s;
  1410. this._y = 0.25 * s;
  1411. this._z = ( m23 + m32 ) / s;
  1412. } else {
  1413. s = 2.0 * Math.sqrt( 1.0 + m33 - m11 - m22 );
  1414. this._w = ( m21 - m12 ) / s;
  1415. this._x = ( m13 + m31 ) / s;
  1416. this._y = ( m23 + m32 ) / s;
  1417. this._z = 0.25 * s;
  1418. }
  1419. this.onChangeCallback();
  1420. return this;
  1421. },
  1422. setFromUnitVectors: function () {
  1423. // assumes direction vectors vFrom and vTo are normalized
  1424. var v1 = new Vector3();
  1425. var r;
  1426. var EPS = 0.000001;
  1427. return function setFromUnitVectors( vFrom, vTo ) {
  1428. if ( v1 === undefined ) v1 = new Vector3();
  1429. r = vFrom.dot( vTo ) + 1;
  1430. if ( r < EPS ) {
  1431. r = 0;
  1432. if ( Math.abs( vFrom.x ) > Math.abs( vFrom.z ) ) {
  1433. v1.set( - vFrom.y, vFrom.x, 0 );
  1434. } else {
  1435. v1.set( 0, - vFrom.z, vFrom.y );
  1436. }
  1437. } else {
  1438. v1.crossVectors( vFrom, vTo );
  1439. }
  1440. this._x = v1.x;
  1441. this._y = v1.y;
  1442. this._z = v1.z;
  1443. this._w = r;
  1444. return this.normalize();
  1445. };
  1446. }(),
  1447. angleTo: function ( q ) {
  1448. return 2 * Math.acos( Math.abs( _Math.clamp( this.dot( q ), - 1, 1 ) ) );
  1449. },
  1450. rotateTowards: function ( q, step ) {
  1451. var angle = this.angleTo( q );
  1452. if ( angle === 0 ) return this;
  1453. var t = Math.min( 1, step / angle );
  1454. this.slerp( q, t );
  1455. return this;
  1456. },
  1457. inverse: function () {
  1458. // quaternion is assumed to have unit length
  1459. return this.conjugate();
  1460. },
  1461. conjugate: function () {
  1462. this._x *= - 1;
  1463. this._y *= - 1;
  1464. this._z *= - 1;
  1465. this.onChangeCallback();
  1466. return this;
  1467. },
  1468. dot: function ( v ) {
  1469. return this._x * v._x + this._y * v._y + this._z * v._z + this._w * v._w;
  1470. },
  1471. lengthSq: function () {
  1472. return this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w;
  1473. },
  1474. length: function () {
  1475. return Math.sqrt( this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w );
  1476. },
  1477. normalize: function () {
  1478. var l = this.length();
  1479. if ( l === 0 ) {
  1480. this._x = 0;
  1481. this._y = 0;
  1482. this._z = 0;
  1483. this._w = 1;
  1484. } else {
  1485. l = 1 / l;
  1486. this._x = this._x * l;
  1487. this._y = this._y * l;
  1488. this._z = this._z * l;
  1489. this._w = this._w * l;
  1490. }
  1491. this.onChangeCallback();
  1492. return this;
  1493. },
  1494. multiply: function ( q, p ) {
  1495. if ( p !== undefined ) {
  1496. console.warn( 'THREE.Quaternion: .multiply() now only accepts one argument. Use .multiplyQuaternions( a, b ) instead.' );
  1497. return this.multiplyQuaternions( q, p );
  1498. }
  1499. return this.multiplyQuaternions( this, q );
  1500. },
  1501. premultiply: function ( q ) {
  1502. return this.multiplyQuaternions( q, this );
  1503. },
  1504. multiplyQuaternions: function ( a, b ) {
  1505. // from http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/code/index.htm
  1506. var qax = a._x, qay = a._y, qaz = a._z, qaw = a._w;
  1507. var qbx = b._x, qby = b._y, qbz = b._z, qbw = b._w;
  1508. this._x = qax * qbw + qaw * qbx + qay * qbz - qaz * qby;
  1509. this._y = qay * qbw + qaw * qby + qaz * qbx - qax * qbz;
  1510. this._z = qaz * qbw + qaw * qbz + qax * qby - qay * qbx;
  1511. this._w = qaw * qbw - qax * qbx - qay * qby - qaz * qbz;
  1512. this.onChangeCallback();
  1513. return this;
  1514. },
  1515. slerp: function ( qb, t ) {
  1516. if ( t === 0 ) return this;
  1517. if ( t === 1 ) return this.copy( qb );
  1518. var x = this._x, y = this._y, z = this._z, w = this._w;
  1519. // http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/slerp/
  1520. var cosHalfTheta = w * qb._w + x * qb._x + y * qb._y + z * qb._z;
  1521. if ( cosHalfTheta < 0 ) {
  1522. this._w = - qb._w;
  1523. this._x = - qb._x;
  1524. this._y = - qb._y;
  1525. this._z = - qb._z;
  1526. cosHalfTheta = - cosHalfTheta;
  1527. } else {
  1528. this.copy( qb );
  1529. }
  1530. if ( cosHalfTheta >= 1.0 ) {
  1531. this._w = w;
  1532. this._x = x;
  1533. this._y = y;
  1534. this._z = z;
  1535. return this;
  1536. }
  1537. var sqrSinHalfTheta = 1.0 - cosHalfTheta * cosHalfTheta;
  1538. if ( sqrSinHalfTheta <= Number.EPSILON ) {
  1539. var s = 1 - t;
  1540. this._w = s * w + t * this._w;
  1541. this._x = s * x + t * this._x;
  1542. this._y = s * y + t * this._y;
  1543. this._z = s * z + t * this._z;
  1544. return this.normalize();
  1545. }
  1546. var sinHalfTheta = Math.sqrt( sqrSinHalfTheta );
  1547. var halfTheta = Math.atan2( sinHalfTheta, cosHalfTheta );
  1548. var ratioA = Math.sin( ( 1 - t ) * halfTheta ) / sinHalfTheta,
  1549. ratioB = Math.sin( t * halfTheta ) / sinHalfTheta;
  1550. this._w = ( w * ratioA + this._w * ratioB );
  1551. this._x = ( x * ratioA + this._x * ratioB );
  1552. this._y = ( y * ratioA + this._y * ratioB );
  1553. this._z = ( z * ratioA + this._z * ratioB );
  1554. this.onChangeCallback();
  1555. return this;
  1556. },
  1557. equals: function ( quaternion ) {
  1558. return ( quaternion._x === this._x ) && ( quaternion._y === this._y ) && ( quaternion._z === this._z ) && ( quaternion._w === this._w );
  1559. },
  1560. fromArray: function ( array, offset ) {
  1561. if ( offset === undefined ) offset = 0;
  1562. this._x = array[ offset ];
  1563. this._y = array[ offset + 1 ];
  1564. this._z = array[ offset + 2 ];
  1565. this._w = array[ offset + 3 ];
  1566. this.onChangeCallback();
  1567. return this;
  1568. },
  1569. toArray: function ( array, offset ) {
  1570. if ( array === undefined ) array = [];
  1571. if ( offset === undefined ) offset = 0;
  1572. array[ offset ] = this._x;
  1573. array[ offset + 1 ] = this._y;
  1574. array[ offset + 2 ] = this._z;
  1575. array[ offset + 3 ] = this._w;
  1576. return array;
  1577. },
  1578. onChange: function ( callback ) {
  1579. this.onChangeCallback = callback;
  1580. return this;
  1581. },
  1582. onChangeCallback: function () {}
  1583. } );
  1584. /**
  1585. * @author mrdoob / http://mrdoob.com/
  1586. * @author kile / http://kile.stravaganza.org/
  1587. * @author philogb / http://blog.thejit.org/
  1588. * @author mikael emtinger / http://gomo.se/
  1589. * @author egraether / http://egraether.com/
  1590. * @author WestLangley / http://github.com/WestLangley
  1591. */
  1592. function Vector3( x, y, z ) {
  1593. this.x = x || 0;
  1594. this.y = y || 0;
  1595. this.z = z || 0;
  1596. }
  1597. Object.assign( Vector3.prototype, {
  1598. isVector3: true,
  1599. set: function ( x, y, z ) {
  1600. this.x = x;
  1601. this.y = y;
  1602. this.z = z;
  1603. return this;
  1604. },
  1605. setScalar: function ( scalar ) {
  1606. this.x = scalar;
  1607. this.y = scalar;
  1608. this.z = scalar;
  1609. return this;
  1610. },
  1611. setX: function ( x ) {
  1612. this.x = x;
  1613. return this;
  1614. },
  1615. setY: function ( y ) {
  1616. this.y = y;
  1617. return this;
  1618. },
  1619. setZ: function ( z ) {
  1620. this.z = z;
  1621. return this;
  1622. },
  1623. setComponent: function ( index, value ) {
  1624. switch ( index ) {
  1625. case 0: this.x = value; break;
  1626. case 1: this.y = value; break;
  1627. case 2: this.z = value; break;
  1628. default: throw new Error( 'index is out of range: ' + index );
  1629. }
  1630. return this;
  1631. },
  1632. getComponent: function ( index ) {
  1633. switch ( index ) {
  1634. case 0: return this.x;
  1635. case 1: return this.y;
  1636. case 2: return this.z;
  1637. default: throw new Error( 'index is out of range: ' + index );
  1638. }
  1639. },
  1640. clone: function () {
  1641. return new this.constructor( this.x, this.y, this.z );
  1642. },
  1643. copy: function ( v ) {
  1644. this.x = v.x;
  1645. this.y = v.y;
  1646. this.z = v.z;
  1647. return this;
  1648. },
  1649. add: function ( v, w ) {
  1650. if ( w !== undefined ) {
  1651. console.warn( 'THREE.Vector3: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  1652. return this.addVectors( v, w );
  1653. }
  1654. this.x += v.x;
  1655. this.y += v.y;
  1656. this.z += v.z;
  1657. return this;
  1658. },
  1659. addScalar: function ( s ) {
  1660. this.x += s;
  1661. this.y += s;
  1662. this.z += s;
  1663. return this;
  1664. },
  1665. addVectors: function ( a, b ) {
  1666. this.x = a.x + b.x;
  1667. this.y = a.y + b.y;
  1668. this.z = a.z + b.z;
  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. return this;
  1676. },
  1677. sub: function ( v, w ) {
  1678. if ( w !== undefined ) {
  1679. console.warn( 'THREE.Vector3: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  1680. return this.subVectors( v, w );
  1681. }
  1682. this.x -= v.x;
  1683. this.y -= v.y;
  1684. this.z -= v.z;
  1685. return this;
  1686. },
  1687. subScalar: function ( s ) {
  1688. this.x -= s;
  1689. this.y -= s;
  1690. this.z -= s;
  1691. return this;
  1692. },
  1693. subVectors: function ( a, b ) {
  1694. this.x = a.x - b.x;
  1695. this.y = a.y - b.y;
  1696. this.z = a.z - b.z;
  1697. return this;
  1698. },
  1699. multiply: function ( v, w ) {
  1700. if ( w !== undefined ) {
  1701. console.warn( 'THREE.Vector3: .multiply() now only accepts one argument. Use .multiplyVectors( a, b ) instead.' );
  1702. return this.multiplyVectors( v, w );
  1703. }
  1704. this.x *= v.x;
  1705. this.y *= v.y;
  1706. this.z *= v.z;
  1707. return this;
  1708. },
  1709. multiplyScalar: function ( scalar ) {
  1710. this.x *= scalar;
  1711. this.y *= scalar;
  1712. this.z *= scalar;
  1713. return this;
  1714. },
  1715. multiplyVectors: function ( a, b ) {
  1716. this.x = a.x * b.x;
  1717. this.y = a.y * b.y;
  1718. this.z = a.z * b.z;
  1719. return this;
  1720. },
  1721. applyEuler: function () {
  1722. var quaternion = new Quaternion();
  1723. return function applyEuler( euler ) {
  1724. if ( ! ( euler && euler.isEuler ) ) {
  1725. console.error( 'THREE.Vector3: .applyEuler() now expects an Euler rotation rather than a Vector3 and order.' );
  1726. }
  1727. return this.applyQuaternion( quaternion.setFromEuler( euler ) );
  1728. };
  1729. }(),
  1730. applyAxisAngle: function () {
  1731. var quaternion = new Quaternion();
  1732. return function applyAxisAngle( axis, angle ) {
  1733. return this.applyQuaternion( quaternion.setFromAxisAngle( axis, angle ) );
  1734. };
  1735. }(),
  1736. applyMatrix3: function ( m ) {
  1737. var x = this.x, y = this.y, z = this.z;
  1738. var e = m.elements;
  1739. this.x = e[ 0 ] * x + e[ 3 ] * y + e[ 6 ] * z;
  1740. this.y = e[ 1 ] * x + e[ 4 ] * y + e[ 7 ] * z;
  1741. this.z = e[ 2 ] * x + e[ 5 ] * y + e[ 8 ] * z;
  1742. return this;
  1743. },
  1744. applyMatrix4: function ( m ) {
  1745. var x = this.x, y = this.y, z = this.z;
  1746. var e = m.elements;
  1747. var w = 1 / ( e[ 3 ] * x + e[ 7 ] * y + e[ 11 ] * z + e[ 15 ] );
  1748. this.x = ( e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ] ) * w;
  1749. this.y = ( e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ] ) * w;
  1750. this.z = ( e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ] ) * w;
  1751. return this;
  1752. },
  1753. applyQuaternion: function ( q ) {
  1754. var x = this.x, y = this.y, z = this.z;
  1755. var qx = q.x, qy = q.y, qz = q.z, qw = q.w;
  1756. // calculate quat * vector
  1757. var ix = qw * x + qy * z - qz * y;
  1758. var iy = qw * y + qz * x - qx * z;
  1759. var iz = qw * z + qx * y - qy * x;
  1760. var iw = - qx * x - qy * y - qz * z;
  1761. // calculate result * inverse quat
  1762. this.x = ix * qw + iw * - qx + iy * - qz - iz * - qy;
  1763. this.y = iy * qw + iw * - qy + iz * - qx - ix * - qz;
  1764. this.z = iz * qw + iw * - qz + ix * - qy - iy * - qx;
  1765. return this;
  1766. },
  1767. project: function ( camera ) {
  1768. return this.applyMatrix4( camera.matrixWorldInverse ).applyMatrix4( camera.projectionMatrix );
  1769. },
  1770. unproject: function () {
  1771. var matrix = new Matrix4();
  1772. return function unproject( camera ) {
  1773. return this.applyMatrix4( matrix.getInverse( camera.projectionMatrix ) ).applyMatrix4( camera.matrixWorld );
  1774. };
  1775. }(),
  1776. transformDirection: function ( m ) {
  1777. // input: THREE.Matrix4 affine matrix
  1778. // vector interpreted as a direction
  1779. var x = this.x, y = this.y, z = this.z;
  1780. var e = m.elements;
  1781. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z;
  1782. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z;
  1783. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z;
  1784. return this.normalize();
  1785. },
  1786. divide: function ( v ) {
  1787. this.x /= v.x;
  1788. this.y /= v.y;
  1789. this.z /= v.z;
  1790. return this;
  1791. },
  1792. divideScalar: function ( scalar ) {
  1793. return this.multiplyScalar( 1 / scalar );
  1794. },
  1795. min: function ( v ) {
  1796. this.x = Math.min( this.x, v.x );
  1797. this.y = Math.min( this.y, v.y );
  1798. this.z = Math.min( this.z, v.z );
  1799. return this;
  1800. },
  1801. max: function ( v ) {
  1802. this.x = Math.max( this.x, v.x );
  1803. this.y = Math.max( this.y, v.y );
  1804. this.z = Math.max( this.z, v.z );
  1805. return this;
  1806. },
  1807. clamp: function ( min, max ) {
  1808. // assumes min < max, componentwise
  1809. this.x = Math.max( min.x, Math.min( max.x, this.x ) );
  1810. this.y = Math.max( min.y, Math.min( max.y, this.y ) );
  1811. this.z = Math.max( min.z, Math.min( max.z, this.z ) );
  1812. return this;
  1813. },
  1814. clampScalar: function () {
  1815. var min = new Vector3();
  1816. var max = new Vector3();
  1817. return function clampScalar( minVal, maxVal ) {
  1818. min.set( minVal, minVal, minVal );
  1819. max.set( maxVal, maxVal, maxVal );
  1820. return this.clamp( min, max );
  1821. };
  1822. }(),
  1823. clampLength: function ( min, max ) {
  1824. var length = this.length();
  1825. return this.divideScalar( length || 1 ).multiplyScalar( Math.max( min, Math.min( max, length ) ) );
  1826. },
  1827. floor: function () {
  1828. this.x = Math.floor( this.x );
  1829. this.y = Math.floor( this.y );
  1830. this.z = Math.floor( this.z );
  1831. return this;
  1832. },
  1833. ceil: function () {
  1834. this.x = Math.ceil( this.x );
  1835. this.y = Math.ceil( this.y );
  1836. this.z = Math.ceil( this.z );
  1837. return this;
  1838. },
  1839. round: function () {
  1840. this.x = Math.round( this.x );
  1841. this.y = Math.round( this.y );
  1842. this.z = Math.round( this.z );
  1843. return this;
  1844. },
  1845. roundToZero: function () {
  1846. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  1847. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  1848. this.z = ( this.z < 0 ) ? Math.ceil( this.z ) : Math.floor( this.z );
  1849. return this;
  1850. },
  1851. negate: function () {
  1852. this.x = - this.x;
  1853. this.y = - this.y;
  1854. this.z = - this.z;
  1855. return this;
  1856. },
  1857. dot: function ( v ) {
  1858. return this.x * v.x + this.y * v.y + this.z * v.z;
  1859. },
  1860. // TODO lengthSquared?
  1861. lengthSq: function () {
  1862. return this.x * this.x + this.y * this.y + this.z * this.z;
  1863. },
  1864. length: function () {
  1865. return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z );
  1866. },
  1867. manhattanLength: function () {
  1868. return Math.abs( this.x ) + Math.abs( this.y ) + Math.abs( this.z );
  1869. },
  1870. normalize: function () {
  1871. return this.divideScalar( this.length() || 1 );
  1872. },
  1873. setLength: function ( length ) {
  1874. return this.normalize().multiplyScalar( length );
  1875. },
  1876. lerp: function ( v, alpha ) {
  1877. this.x += ( v.x - this.x ) * alpha;
  1878. this.y += ( v.y - this.y ) * alpha;
  1879. this.z += ( v.z - this.z ) * alpha;
  1880. return this;
  1881. },
  1882. lerpVectors: function ( v1, v2, alpha ) {
  1883. return this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  1884. },
  1885. cross: function ( v, w ) {
  1886. if ( w !== undefined ) {
  1887. console.warn( 'THREE.Vector3: .cross() now only accepts one argument. Use .crossVectors( a, b ) instead.' );
  1888. return this.crossVectors( v, w );
  1889. }
  1890. return this.crossVectors( this, v );
  1891. },
  1892. crossVectors: function ( a, b ) {
  1893. var ax = a.x, ay = a.y, az = a.z;
  1894. var bx = b.x, by = b.y, bz = b.z;
  1895. this.x = ay * bz - az * by;
  1896. this.y = az * bx - ax * bz;
  1897. this.z = ax * by - ay * bx;
  1898. return this;
  1899. },
  1900. projectOnVector: function ( vector ) {
  1901. var scalar = vector.dot( this ) / vector.lengthSq();
  1902. return this.copy( vector ).multiplyScalar( scalar );
  1903. },
  1904. projectOnPlane: function () {
  1905. var v1 = new Vector3();
  1906. return function projectOnPlane( planeNormal ) {
  1907. v1.copy( this ).projectOnVector( planeNormal );
  1908. return this.sub( v1 );
  1909. };
  1910. }(),
  1911. reflect: function () {
  1912. // reflect incident vector off plane orthogonal to normal
  1913. // normal is assumed to have unit length
  1914. var v1 = new Vector3();
  1915. return function reflect( normal ) {
  1916. return this.sub( v1.copy( normal ).multiplyScalar( 2 * this.dot( normal ) ) );
  1917. };
  1918. }(),
  1919. angleTo: function ( v ) {
  1920. var theta = this.dot( v ) / ( Math.sqrt( this.lengthSq() * v.lengthSq() ) );
  1921. // clamp, to handle numerical problems
  1922. return Math.acos( _Math.clamp( theta, - 1, 1 ) );
  1923. },
  1924. distanceTo: function ( v ) {
  1925. return Math.sqrt( this.distanceToSquared( v ) );
  1926. },
  1927. distanceToSquared: function ( v ) {
  1928. var dx = this.x - v.x, dy = this.y - v.y, dz = this.z - v.z;
  1929. return dx * dx + dy * dy + dz * dz;
  1930. },
  1931. manhattanDistanceTo: function ( v ) {
  1932. return Math.abs( this.x - v.x ) + Math.abs( this.y - v.y ) + Math.abs( this.z - v.z );
  1933. },
  1934. setFromSpherical: function ( s ) {
  1935. return this.setFromSphericalCoords( s.radius, s.phi, s.theta );
  1936. },
  1937. setFromSphericalCoords: function ( radius, phi, theta ) {
  1938. var sinPhiRadius = Math.sin( phi ) * radius;
  1939. this.x = sinPhiRadius * Math.sin( theta );
  1940. this.y = Math.cos( phi ) * radius;
  1941. this.z = sinPhiRadius * Math.cos( theta );
  1942. return this;
  1943. },
  1944. setFromCylindrical: function ( c ) {
  1945. return this.setFromCylindricalCoords( c.radius, c.theta, c.y );
  1946. },
  1947. setFromCylindricalCoords: function ( radius, theta, y ) {
  1948. this.x = radius * Math.sin( theta );
  1949. this.y = y;
  1950. this.z = radius * Math.cos( theta );
  1951. return this;
  1952. },
  1953. setFromMatrixPosition: function ( m ) {
  1954. var e = m.elements;
  1955. this.x = e[ 12 ];
  1956. this.y = e[ 13 ];
  1957. this.z = e[ 14 ];
  1958. return this;
  1959. },
  1960. setFromMatrixScale: function ( m ) {
  1961. var sx = this.setFromMatrixColumn( m, 0 ).length();
  1962. var sy = this.setFromMatrixColumn( m, 1 ).length();
  1963. var sz = this.setFromMatrixColumn( m, 2 ).length();
  1964. this.x = sx;
  1965. this.y = sy;
  1966. this.z = sz;
  1967. return this;
  1968. },
  1969. setFromMatrixColumn: function ( m, index ) {
  1970. return this.fromArray( m.elements, index * 4 );
  1971. },
  1972. equals: function ( v ) {
  1973. return ( ( v.x === this.x ) && ( v.y === this.y ) && ( v.z === this.z ) );
  1974. },
  1975. fromArray: function ( array, offset ) {
  1976. if ( offset === undefined ) offset = 0;
  1977. this.x = array[ offset ];
  1978. this.y = array[ offset + 1 ];
  1979. this.z = array[ offset + 2 ];
  1980. return this;
  1981. },
  1982. toArray: function ( array, offset ) {
  1983. if ( array === undefined ) array = [];
  1984. if ( offset === undefined ) offset = 0;
  1985. array[ offset ] = this.x;
  1986. array[ offset + 1 ] = this.y;
  1987. array[ offset + 2 ] = this.z;
  1988. return array;
  1989. },
  1990. fromBufferAttribute: function ( attribute, index, offset ) {
  1991. if ( offset !== undefined ) {
  1992. console.warn( 'THREE.Vector3: offset has been removed from .fromBufferAttribute().' );
  1993. }
  1994. this.x = attribute.getX( index );
  1995. this.y = attribute.getY( index );
  1996. this.z = attribute.getZ( index );
  1997. return this;
  1998. }
  1999. } );
  2000. /**
  2001. * @author alteredq / http://alteredqualia.com/
  2002. * @author WestLangley / http://github.com/WestLangley
  2003. * @author bhouston / http://clara.io
  2004. * @author tschw
  2005. */
  2006. function Matrix3() {
  2007. this.elements = [
  2008. 1, 0, 0,
  2009. 0, 1, 0,
  2010. 0, 0, 1
  2011. ];
  2012. if ( arguments.length > 0 ) {
  2013. console.error( 'THREE.Matrix3: the constructor no longer reads arguments. use .set() instead.' );
  2014. }
  2015. }
  2016. Object.assign( Matrix3.prototype, {
  2017. isMatrix3: true,
  2018. set: function ( n11, n12, n13, n21, n22, n23, n31, n32, n33 ) {
  2019. var te = this.elements;
  2020. te[ 0 ] = n11; te[ 1 ] = n21; te[ 2 ] = n31;
  2021. te[ 3 ] = n12; te[ 4 ] = n22; te[ 5 ] = n32;
  2022. te[ 6 ] = n13; te[ 7 ] = n23; te[ 8 ] = n33;
  2023. return this;
  2024. },
  2025. identity: function () {
  2026. this.set(
  2027. 1, 0, 0,
  2028. 0, 1, 0,
  2029. 0, 0, 1
  2030. );
  2031. return this;
  2032. },
  2033. clone: function () {
  2034. return new this.constructor().fromArray( this.elements );
  2035. },
  2036. copy: function ( m ) {
  2037. var te = this.elements;
  2038. var me = m.elements;
  2039. te[ 0 ] = me[ 0 ]; te[ 1 ] = me[ 1 ]; te[ 2 ] = me[ 2 ];
  2040. te[ 3 ] = me[ 3 ]; te[ 4 ] = me[ 4 ]; te[ 5 ] = me[ 5 ];
  2041. te[ 6 ] = me[ 6 ]; te[ 7 ] = me[ 7 ]; te[ 8 ] = me[ 8 ];
  2042. return this;
  2043. },
  2044. setFromMatrix4: function ( m ) {
  2045. var me = m.elements;
  2046. this.set(
  2047. me[ 0 ], me[ 4 ], me[ 8 ],
  2048. me[ 1 ], me[ 5 ], me[ 9 ],
  2049. me[ 2 ], me[ 6 ], me[ 10 ]
  2050. );
  2051. return this;
  2052. },
  2053. applyToBufferAttribute: function () {
  2054. var v1 = new Vector3();
  2055. return function applyToBufferAttribute( attribute ) {
  2056. for ( var i = 0, l = attribute.count; i < l; i ++ ) {
  2057. v1.x = attribute.getX( i );
  2058. v1.y = attribute.getY( i );
  2059. v1.z = attribute.getZ( i );
  2060. v1.applyMatrix3( this );
  2061. attribute.setXYZ( i, v1.x, v1.y, v1.z );
  2062. }
  2063. return attribute;
  2064. };
  2065. }(),
  2066. multiply: function ( m ) {
  2067. return this.multiplyMatrices( this, m );
  2068. },
  2069. premultiply: function ( m ) {
  2070. return this.multiplyMatrices( m, this );
  2071. },
  2072. multiplyMatrices: function ( a, b ) {
  2073. var ae = a.elements;
  2074. var be = b.elements;
  2075. var te = this.elements;
  2076. var a11 = ae[ 0 ], a12 = ae[ 3 ], a13 = ae[ 6 ];
  2077. var a21 = ae[ 1 ], a22 = ae[ 4 ], a23 = ae[ 7 ];
  2078. var a31 = ae[ 2 ], a32 = ae[ 5 ], a33 = ae[ 8 ];
  2079. var b11 = be[ 0 ], b12 = be[ 3 ], b13 = be[ 6 ];
  2080. var b21 = be[ 1 ], b22 = be[ 4 ], b23 = be[ 7 ];
  2081. var b31 = be[ 2 ], b32 = be[ 5 ], b33 = be[ 8 ];
  2082. te[ 0 ] = a11 * b11 + a12 * b21 + a13 * b31;
  2083. te[ 3 ] = a11 * b12 + a12 * b22 + a13 * b32;
  2084. te[ 6 ] = a11 * b13 + a12 * b23 + a13 * b33;
  2085. te[ 1 ] = a21 * b11 + a22 * b21 + a23 * b31;
  2086. te[ 4 ] = a21 * b12 + a22 * b22 + a23 * b32;
  2087. te[ 7 ] = a21 * b13 + a22 * b23 + a23 * b33;
  2088. te[ 2 ] = a31 * b11 + a32 * b21 + a33 * b31;
  2089. te[ 5 ] = a31 * b12 + a32 * b22 + a33 * b32;
  2090. te[ 8 ] = a31 * b13 + a32 * b23 + a33 * b33;
  2091. return this;
  2092. },
  2093. multiplyScalar: function ( s ) {
  2094. var te = this.elements;
  2095. te[ 0 ] *= s; te[ 3 ] *= s; te[ 6 ] *= s;
  2096. te[ 1 ] *= s; te[ 4 ] *= s; te[ 7 ] *= s;
  2097. te[ 2 ] *= s; te[ 5 ] *= s; te[ 8 ] *= s;
  2098. return this;
  2099. },
  2100. determinant: function () {
  2101. var te = this.elements;
  2102. var a = te[ 0 ], b = te[ 1 ], c = te[ 2 ],
  2103. d = te[ 3 ], e = te[ 4 ], f = te[ 5 ],
  2104. g = te[ 6 ], h = te[ 7 ], i = te[ 8 ];
  2105. return a * e * i - a * f * h - b * d * i + b * f * g + c * d * h - c * e * g;
  2106. },
  2107. getInverse: function ( matrix, throwOnDegenerate ) {
  2108. if ( matrix && matrix.isMatrix4 ) {
  2109. console.error( "THREE.Matrix3: .getInverse() no longer takes a Matrix4 argument." );
  2110. }
  2111. var me = matrix.elements,
  2112. te = this.elements,
  2113. n11 = me[ 0 ], n21 = me[ 1 ], n31 = me[ 2 ],
  2114. n12 = me[ 3 ], n22 = me[ 4 ], n32 = me[ 5 ],
  2115. n13 = me[ 6 ], n23 = me[ 7 ], n33 = me[ 8 ],
  2116. t11 = n33 * n22 - n32 * n23,
  2117. t12 = n32 * n13 - n33 * n12,
  2118. t13 = n23 * n12 - n22 * n13,
  2119. det = n11 * t11 + n21 * t12 + n31 * t13;
  2120. if ( det === 0 ) {
  2121. var msg = "THREE.Matrix3: .getInverse() can't invert matrix, determinant is 0";
  2122. if ( throwOnDegenerate === true ) {
  2123. throw new Error( msg );
  2124. } else {
  2125. console.warn( msg );
  2126. }
  2127. return this.identity();
  2128. }
  2129. var detInv = 1 / det;
  2130. te[ 0 ] = t11 * detInv;
  2131. te[ 1 ] = ( n31 * n23 - n33 * n21 ) * detInv;
  2132. te[ 2 ] = ( n32 * n21 - n31 * n22 ) * detInv;
  2133. te[ 3 ] = t12 * detInv;
  2134. te[ 4 ] = ( n33 * n11 - n31 * n13 ) * detInv;
  2135. te[ 5 ] = ( n31 * n12 - n32 * n11 ) * detInv;
  2136. te[ 6 ] = t13 * detInv;
  2137. te[ 7 ] = ( n21 * n13 - n23 * n11 ) * detInv;
  2138. te[ 8 ] = ( n22 * n11 - n21 * n12 ) * detInv;
  2139. return this;
  2140. },
  2141. transpose: function () {
  2142. var tmp, m = this.elements;
  2143. tmp = m[ 1 ]; m[ 1 ] = m[ 3 ]; m[ 3 ] = tmp;
  2144. tmp = m[ 2 ]; m[ 2 ] = m[ 6 ]; m[ 6 ] = tmp;
  2145. tmp = m[ 5 ]; m[ 5 ] = m[ 7 ]; m[ 7 ] = tmp;
  2146. return this;
  2147. },
  2148. getNormalMatrix: function ( matrix4 ) {
  2149. return this.setFromMatrix4( matrix4 ).getInverse( this ).transpose();
  2150. },
  2151. transposeIntoArray: function ( r ) {
  2152. var m = this.elements;
  2153. r[ 0 ] = m[ 0 ];
  2154. r[ 1 ] = m[ 3 ];
  2155. r[ 2 ] = m[ 6 ];
  2156. r[ 3 ] = m[ 1 ];
  2157. r[ 4 ] = m[ 4 ];
  2158. r[ 5 ] = m[ 7 ];
  2159. r[ 6 ] = m[ 2 ];
  2160. r[ 7 ] = m[ 5 ];
  2161. r[ 8 ] = m[ 8 ];
  2162. return this;
  2163. },
  2164. setUvTransform: function ( tx, ty, sx, sy, rotation, cx, cy ) {
  2165. var c = Math.cos( rotation );
  2166. var s = Math.sin( rotation );
  2167. this.set(
  2168. sx * c, sx * s, - sx * ( c * cx + s * cy ) + cx + tx,
  2169. - sy * s, sy * c, - sy * ( - s * cx + c * cy ) + cy + ty,
  2170. 0, 0, 1
  2171. );
  2172. },
  2173. scale: function ( sx, sy ) {
  2174. var te = this.elements;
  2175. te[ 0 ] *= sx; te[ 3 ] *= sx; te[ 6 ] *= sx;
  2176. te[ 1 ] *= sy; te[ 4 ] *= sy; te[ 7 ] *= sy;
  2177. return this;
  2178. },
  2179. rotate: function ( theta ) {
  2180. var c = Math.cos( theta );
  2181. var s = Math.sin( theta );
  2182. var te = this.elements;
  2183. var a11 = te[ 0 ], a12 = te[ 3 ], a13 = te[ 6 ];
  2184. var a21 = te[ 1 ], a22 = te[ 4 ], a23 = te[ 7 ];
  2185. te[ 0 ] = c * a11 + s * a21;
  2186. te[ 3 ] = c * a12 + s * a22;
  2187. te[ 6 ] = c * a13 + s * a23;
  2188. te[ 1 ] = - s * a11 + c * a21;
  2189. te[ 4 ] = - s * a12 + c * a22;
  2190. te[ 7 ] = - s * a13 + c * a23;
  2191. return this;
  2192. },
  2193. translate: function ( tx, ty ) {
  2194. var te = this.elements;
  2195. te[ 0 ] += tx * te[ 2 ]; te[ 3 ] += tx * te[ 5 ]; te[ 6 ] += tx * te[ 8 ];
  2196. te[ 1 ] += ty * te[ 2 ]; te[ 4 ] += ty * te[ 5 ]; te[ 7 ] += ty * te[ 8 ];
  2197. return this;
  2198. },
  2199. equals: function ( matrix ) {
  2200. var te = this.elements;
  2201. var me = matrix.elements;
  2202. for ( var i = 0; i < 9; i ++ ) {
  2203. if ( te[ i ] !== me[ i ] ) return false;
  2204. }
  2205. return true;
  2206. },
  2207. fromArray: function ( array, offset ) {
  2208. if ( offset === undefined ) offset = 0;
  2209. for ( var i = 0; i < 9; i ++ ) {
  2210. this.elements[ i ] = array[ i + offset ];
  2211. }
  2212. return this;
  2213. },
  2214. toArray: function ( array, offset ) {
  2215. if ( array === undefined ) array = [];
  2216. if ( offset === undefined ) offset = 0;
  2217. var te = this.elements;
  2218. array[ offset ] = te[ 0 ];
  2219. array[ offset + 1 ] = te[ 1 ];
  2220. array[ offset + 2 ] = te[ 2 ];
  2221. array[ offset + 3 ] = te[ 3 ];
  2222. array[ offset + 4 ] = te[ 4 ];
  2223. array[ offset + 5 ] = te[ 5 ];
  2224. array[ offset + 6 ] = te[ 6 ];
  2225. array[ offset + 7 ] = te[ 7 ];
  2226. array[ offset + 8 ] = te[ 8 ];
  2227. return array;
  2228. }
  2229. } );
  2230. /**
  2231. * @author mrdoob / http://mrdoob.com/
  2232. * @author alteredq / http://alteredqualia.com/
  2233. * @author szimek / https://github.com/szimek/
  2234. */
  2235. var _canvas;
  2236. var ImageUtils = {
  2237. getDataURL: function ( image ) {
  2238. var canvas;
  2239. if ( typeof HTMLCanvasElement == 'undefined' ) {
  2240. return image.src;
  2241. } else if ( image instanceof HTMLCanvasElement ) {
  2242. canvas = image;
  2243. } else {
  2244. if ( _canvas === undefined ) _canvas = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' );
  2245. _canvas.width = image.width;
  2246. _canvas.height = image.height;
  2247. var context = _canvas.getContext( '2d' );
  2248. if ( image instanceof ImageData ) {
  2249. context.putImageData( image, 0, 0 );
  2250. } else {
  2251. context.drawImage( image, 0, 0, image.width, image.height );
  2252. }
  2253. canvas = _canvas;
  2254. }
  2255. if ( canvas.width > 2048 || canvas.height > 2048 ) {
  2256. return canvas.toDataURL( 'image/jpeg', 0.6 );
  2257. } else {
  2258. return canvas.toDataURL( 'image/png' );
  2259. }
  2260. }
  2261. };
  2262. /**
  2263. * @author mrdoob / http://mrdoob.com/
  2264. * @author alteredq / http://alteredqualia.com/
  2265. * @author szimek / https://github.com/szimek/
  2266. */
  2267. var textureId = 0;
  2268. function Texture( image, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding ) {
  2269. Object.defineProperty( this, 'id', { value: textureId ++ } );
  2270. this.uuid = _Math.generateUUID();
  2271. this.name = '';
  2272. this.image = image !== undefined ? image : Texture.DEFAULT_IMAGE;
  2273. this.mipmaps = [];
  2274. this.mapping = mapping !== undefined ? mapping : Texture.DEFAULT_MAPPING;
  2275. this.wrapS = wrapS !== undefined ? wrapS : ClampToEdgeWrapping;
  2276. this.wrapT = wrapT !== undefined ? wrapT : ClampToEdgeWrapping;
  2277. this.magFilter = magFilter !== undefined ? magFilter : LinearFilter;
  2278. this.minFilter = minFilter !== undefined ? minFilter : LinearMipMapLinearFilter;
  2279. this.anisotropy = anisotropy !== undefined ? anisotropy : 1;
  2280. this.format = format !== undefined ? format : RGBAFormat;
  2281. this.type = type !== undefined ? type : UnsignedByteType;
  2282. this.offset = new Vector2( 0, 0 );
  2283. this.repeat = new Vector2( 1, 1 );
  2284. this.center = new Vector2( 0, 0 );
  2285. this.rotation = 0;
  2286. this.matrixAutoUpdate = true;
  2287. this.matrix = new Matrix3();
  2288. this.generateMipmaps = true;
  2289. this.premultiplyAlpha = false;
  2290. this.flipY = true;
  2291. this.unpackAlignment = 4; // valid values: 1, 2, 4, 8 (see http://www.khronos.org/opengles/sdk/docs/man/xhtml/glPixelStorei.xml)
  2292. // Values of encoding !== THREE.LinearEncoding only supported on map, envMap and emissiveMap.
  2293. //
  2294. // Also changing the encoding after already used by a Material will not automatically make the Material
  2295. // update. You need to explicitly call Material.needsUpdate to trigger it to recompile.
  2296. this.encoding = encoding !== undefined ? encoding : LinearEncoding;
  2297. this.version = 0;
  2298. this.onUpdate = null;
  2299. }
  2300. Texture.DEFAULT_IMAGE = undefined;
  2301. Texture.DEFAULT_MAPPING = UVMapping;
  2302. Texture.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  2303. constructor: Texture,
  2304. isTexture: true,
  2305. updateMatrix: function () {
  2306. this.matrix.setUvTransform( this.offset.x, this.offset.y, this.repeat.x, this.repeat.y, this.rotation, this.center.x, this.center.y );
  2307. },
  2308. clone: function () {
  2309. return new this.constructor().copy( this );
  2310. },
  2311. copy: function ( source ) {
  2312. this.name = source.name;
  2313. this.image = source.image;
  2314. this.mipmaps = source.mipmaps.slice( 0 );
  2315. this.mapping = source.mapping;
  2316. this.wrapS = source.wrapS;
  2317. this.wrapT = source.wrapT;
  2318. this.magFilter = source.magFilter;
  2319. this.minFilter = source.minFilter;
  2320. this.anisotropy = source.anisotropy;
  2321. this.format = source.format;
  2322. this.type = source.type;
  2323. this.offset.copy( source.offset );
  2324. this.repeat.copy( source.repeat );
  2325. this.center.copy( source.center );
  2326. this.rotation = source.rotation;
  2327. this.matrixAutoUpdate = source.matrixAutoUpdate;
  2328. this.matrix.copy( source.matrix );
  2329. this.generateMipmaps = source.generateMipmaps;
  2330. this.premultiplyAlpha = source.premultiplyAlpha;
  2331. this.flipY = source.flipY;
  2332. this.unpackAlignment = source.unpackAlignment;
  2333. this.encoding = source.encoding;
  2334. return this;
  2335. },
  2336. toJSON: function ( meta ) {
  2337. var isRootObject = ( meta === undefined || typeof meta === 'string' );
  2338. if ( ! isRootObject && meta.textures[ this.uuid ] !== undefined ) {
  2339. return meta.textures[ this.uuid ];
  2340. }
  2341. var output = {
  2342. metadata: {
  2343. version: 4.5,
  2344. type: 'Texture',
  2345. generator: 'Texture.toJSON'
  2346. },
  2347. uuid: this.uuid,
  2348. name: this.name,
  2349. mapping: this.mapping,
  2350. repeat: [ this.repeat.x, this.repeat.y ],
  2351. offset: [ this.offset.x, this.offset.y ],
  2352. center: [ this.center.x, this.center.y ],
  2353. rotation: this.rotation,
  2354. wrap: [ this.wrapS, this.wrapT ],
  2355. format: this.format,
  2356. type: this.type,
  2357. encoding: this.encoding,
  2358. minFilter: this.minFilter,
  2359. magFilter: this.magFilter,
  2360. anisotropy: this.anisotropy,
  2361. flipY: this.flipY,
  2362. premultiplyAlpha: this.premultiplyAlpha,
  2363. unpackAlignment: this.unpackAlignment
  2364. };
  2365. if ( this.image !== undefined ) {
  2366. // TODO: Move to THREE.Image
  2367. var image = this.image;
  2368. if ( image.uuid === undefined ) {
  2369. image.uuid = _Math.generateUUID(); // UGH
  2370. }
  2371. if ( ! isRootObject && meta.images[ image.uuid ] === undefined ) {
  2372. var url;
  2373. if ( Array.isArray( image ) ) {
  2374. // process array of images e.g. CubeTexture
  2375. url = [];
  2376. for ( var i = 0, l = image.length; i < l; i ++ ) {
  2377. url.push( ImageUtils.getDataURL( image[ i ] ) );
  2378. }
  2379. } else {
  2380. // process single image
  2381. url = ImageUtils.getDataURL( image );
  2382. }
  2383. meta.images[ image.uuid ] = {
  2384. uuid: image.uuid,
  2385. url: url
  2386. };
  2387. }
  2388. output.image = image.uuid;
  2389. }
  2390. if ( ! isRootObject ) {
  2391. meta.textures[ this.uuid ] = output;
  2392. }
  2393. return output;
  2394. },
  2395. dispose: function () {
  2396. this.dispatchEvent( { type: 'dispose' } );
  2397. },
  2398. transformUv: function ( uv ) {
  2399. if ( this.mapping !== UVMapping ) return uv;
  2400. uv.applyMatrix3( this.matrix );
  2401. if ( uv.x < 0 || uv.x > 1 ) {
  2402. switch ( this.wrapS ) {
  2403. case RepeatWrapping:
  2404. uv.x = uv.x - Math.floor( uv.x );
  2405. break;
  2406. case ClampToEdgeWrapping:
  2407. uv.x = uv.x < 0 ? 0 : 1;
  2408. break;
  2409. case MirroredRepeatWrapping:
  2410. if ( Math.abs( Math.floor( uv.x ) % 2 ) === 1 ) {
  2411. uv.x = Math.ceil( uv.x ) - uv.x;
  2412. } else {
  2413. uv.x = uv.x - Math.floor( uv.x );
  2414. }
  2415. break;
  2416. }
  2417. }
  2418. if ( uv.y < 0 || uv.y > 1 ) {
  2419. switch ( this.wrapT ) {
  2420. case RepeatWrapping:
  2421. uv.y = uv.y - Math.floor( uv.y );
  2422. break;
  2423. case ClampToEdgeWrapping:
  2424. uv.y = uv.y < 0 ? 0 : 1;
  2425. break;
  2426. case MirroredRepeatWrapping:
  2427. if ( Math.abs( Math.floor( uv.y ) % 2 ) === 1 ) {
  2428. uv.y = Math.ceil( uv.y ) - uv.y;
  2429. } else {
  2430. uv.y = uv.y - Math.floor( uv.y );
  2431. }
  2432. break;
  2433. }
  2434. }
  2435. if ( this.flipY ) {
  2436. uv.y = 1 - uv.y;
  2437. }
  2438. return uv;
  2439. }
  2440. } );
  2441. Object.defineProperty( Texture.prototype, "needsUpdate", {
  2442. set: function ( value ) {
  2443. if ( value === true ) this.version ++;
  2444. }
  2445. } );
  2446. /**
  2447. * @author supereggbert / http://www.paulbrunt.co.uk/
  2448. * @author philogb / http://blog.thejit.org/
  2449. * @author mikael emtinger / http://gomo.se/
  2450. * @author egraether / http://egraether.com/
  2451. * @author WestLangley / http://github.com/WestLangley
  2452. */
  2453. function Vector4( x, y, z, w ) {
  2454. this.x = x || 0;
  2455. this.y = y || 0;
  2456. this.z = z || 0;
  2457. this.w = ( w !== undefined ) ? w : 1;
  2458. }
  2459. Object.assign( Vector4.prototype, {
  2460. isVector4: true,
  2461. set: function ( x, y, z, w ) {
  2462. this.x = x;
  2463. this.y = y;
  2464. this.z = z;
  2465. this.w = w;
  2466. return this;
  2467. },
  2468. setScalar: function ( scalar ) {
  2469. this.x = scalar;
  2470. this.y = scalar;
  2471. this.z = scalar;
  2472. this.w = scalar;
  2473. return this;
  2474. },
  2475. setX: function ( x ) {
  2476. this.x = x;
  2477. return this;
  2478. },
  2479. setY: function ( y ) {
  2480. this.y = y;
  2481. return this;
  2482. },
  2483. setZ: function ( z ) {
  2484. this.z = z;
  2485. return this;
  2486. },
  2487. setW: function ( w ) {
  2488. this.w = w;
  2489. return this;
  2490. },
  2491. setComponent: function ( index, value ) {
  2492. switch ( index ) {
  2493. case 0: this.x = value; break;
  2494. case 1: this.y = value; break;
  2495. case 2: this.z = value; break;
  2496. case 3: this.w = value; break;
  2497. default: throw new Error( 'index is out of range: ' + index );
  2498. }
  2499. return this;
  2500. },
  2501. getComponent: function ( index ) {
  2502. switch ( index ) {
  2503. case 0: return this.x;
  2504. case 1: return this.y;
  2505. case 2: return this.z;
  2506. case 3: return this.w;
  2507. default: throw new Error( 'index is out of range: ' + index );
  2508. }
  2509. },
  2510. clone: function () {
  2511. return new this.constructor( this.x, this.y, this.z, this.w );
  2512. },
  2513. copy: function ( v ) {
  2514. this.x = v.x;
  2515. this.y = v.y;
  2516. this.z = v.z;
  2517. this.w = ( v.w !== undefined ) ? v.w : 1;
  2518. return this;
  2519. },
  2520. add: function ( v, w ) {
  2521. if ( w !== undefined ) {
  2522. console.warn( 'THREE.Vector4: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  2523. return this.addVectors( v, w );
  2524. }
  2525. this.x += v.x;
  2526. this.y += v.y;
  2527. this.z += v.z;
  2528. this.w += v.w;
  2529. return this;
  2530. },
  2531. addScalar: function ( s ) {
  2532. this.x += s;
  2533. this.y += s;
  2534. this.z += s;
  2535. this.w += s;
  2536. return this;
  2537. },
  2538. addVectors: function ( a, b ) {
  2539. this.x = a.x + b.x;
  2540. this.y = a.y + b.y;
  2541. this.z = a.z + b.z;
  2542. this.w = a.w + b.w;
  2543. return this;
  2544. },
  2545. addScaledVector: function ( v, s ) {
  2546. this.x += v.x * s;
  2547. this.y += v.y * s;
  2548. this.z += v.z * s;
  2549. this.w += v.w * s;
  2550. return this;
  2551. },
  2552. sub: function ( v, w ) {
  2553. if ( w !== undefined ) {
  2554. console.warn( 'THREE.Vector4: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  2555. return this.subVectors( v, w );
  2556. }
  2557. this.x -= v.x;
  2558. this.y -= v.y;
  2559. this.z -= v.z;
  2560. this.w -= v.w;
  2561. return this;
  2562. },
  2563. subScalar: function ( s ) {
  2564. this.x -= s;
  2565. this.y -= s;
  2566. this.z -= s;
  2567. this.w -= s;
  2568. return this;
  2569. },
  2570. subVectors: function ( a, b ) {
  2571. this.x = a.x - b.x;
  2572. this.y = a.y - b.y;
  2573. this.z = a.z - b.z;
  2574. this.w = a.w - b.w;
  2575. return this;
  2576. },
  2577. multiplyScalar: function ( scalar ) {
  2578. this.x *= scalar;
  2579. this.y *= scalar;
  2580. this.z *= scalar;
  2581. this.w *= scalar;
  2582. return this;
  2583. },
  2584. applyMatrix4: function ( m ) {
  2585. var x = this.x, y = this.y, z = this.z, w = this.w;
  2586. var e = m.elements;
  2587. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ] * w;
  2588. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ] * w;
  2589. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ] * w;
  2590. this.w = e[ 3 ] * x + e[ 7 ] * y + e[ 11 ] * z + e[ 15 ] * w;
  2591. return this;
  2592. },
  2593. divideScalar: function ( scalar ) {
  2594. return this.multiplyScalar( 1 / scalar );
  2595. },
  2596. setAxisAngleFromQuaternion: function ( q ) {
  2597. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToAngle/index.htm
  2598. // q is assumed to be normalized
  2599. this.w = 2 * Math.acos( q.w );
  2600. var s = Math.sqrt( 1 - q.w * q.w );
  2601. if ( s < 0.0001 ) {
  2602. this.x = 1;
  2603. this.y = 0;
  2604. this.z = 0;
  2605. } else {
  2606. this.x = q.x / s;
  2607. this.y = q.y / s;
  2608. this.z = q.z / s;
  2609. }
  2610. return this;
  2611. },
  2612. setAxisAngleFromRotationMatrix: function ( m ) {
  2613. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToAngle/index.htm
  2614. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  2615. var angle, x, y, z, // variables for result
  2616. epsilon = 0.01, // margin to allow for rounding errors
  2617. epsilon2 = 0.1, // margin to distinguish between 0 and 180 degrees
  2618. te = m.elements,
  2619. m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ],
  2620. m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ],
  2621. m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ];
  2622. if ( ( Math.abs( m12 - m21 ) < epsilon ) &&
  2623. ( Math.abs( m13 - m31 ) < epsilon ) &&
  2624. ( Math.abs( m23 - m32 ) < epsilon ) ) {
  2625. // singularity found
  2626. // first check for identity matrix which must have +1 for all terms
  2627. // in leading diagonal and zero in other terms
  2628. if ( ( Math.abs( m12 + m21 ) < epsilon2 ) &&
  2629. ( Math.abs( m13 + m31 ) < epsilon2 ) &&
  2630. ( Math.abs( m23 + m32 ) < epsilon2 ) &&
  2631. ( Math.abs( m11 + m22 + m33 - 3 ) < epsilon2 ) ) {
  2632. // this singularity is identity matrix so angle = 0
  2633. this.set( 1, 0, 0, 0 );
  2634. return this; // zero angle, arbitrary axis
  2635. }
  2636. // otherwise this singularity is angle = 180
  2637. angle = Math.PI;
  2638. var xx = ( m11 + 1 ) / 2;
  2639. var yy = ( m22 + 1 ) / 2;
  2640. var zz = ( m33 + 1 ) / 2;
  2641. var xy = ( m12 + m21 ) / 4;
  2642. var xz = ( m13 + m31 ) / 4;
  2643. var yz = ( m23 + m32 ) / 4;
  2644. if ( ( xx > yy ) && ( xx > zz ) ) {
  2645. // m11 is the largest diagonal term
  2646. if ( xx < epsilon ) {
  2647. x = 0;
  2648. y = 0.707106781;
  2649. z = 0.707106781;
  2650. } else {
  2651. x = Math.sqrt( xx );
  2652. y = xy / x;
  2653. z = xz / x;
  2654. }
  2655. } else if ( yy > zz ) {
  2656. // m22 is the largest diagonal term
  2657. if ( yy < epsilon ) {
  2658. x = 0.707106781;
  2659. y = 0;
  2660. z = 0.707106781;
  2661. } else {
  2662. y = Math.sqrt( yy );
  2663. x = xy / y;
  2664. z = yz / y;
  2665. }
  2666. } else {
  2667. // m33 is the largest diagonal term so base result on this
  2668. if ( zz < epsilon ) {
  2669. x = 0.707106781;
  2670. y = 0.707106781;
  2671. z = 0;
  2672. } else {
  2673. z = Math.sqrt( zz );
  2674. x = xz / z;
  2675. y = yz / z;
  2676. }
  2677. }
  2678. this.set( x, y, z, angle );
  2679. return this; // return 180 deg rotation
  2680. }
  2681. // as we have reached here there are no singularities so we can handle normally
  2682. var s = Math.sqrt( ( m32 - m23 ) * ( m32 - m23 ) +
  2683. ( m13 - m31 ) * ( m13 - m31 ) +
  2684. ( m21 - m12 ) * ( m21 - m12 ) ); // used to normalize
  2685. if ( Math.abs( s ) < 0.001 ) s = 1;
  2686. // prevent divide by zero, should not happen if matrix is orthogonal and should be
  2687. // caught by singularity test above, but I've left it in just in case
  2688. this.x = ( m32 - m23 ) / s;
  2689. this.y = ( m13 - m31 ) / s;
  2690. this.z = ( m21 - m12 ) / s;
  2691. this.w = Math.acos( ( m11 + m22 + m33 - 1 ) / 2 );
  2692. return this;
  2693. },
  2694. min: function ( v ) {
  2695. this.x = Math.min( this.x, v.x );
  2696. this.y = Math.min( this.y, v.y );
  2697. this.z = Math.min( this.z, v.z );
  2698. this.w = Math.min( this.w, v.w );
  2699. return this;
  2700. },
  2701. max: function ( v ) {
  2702. this.x = Math.max( this.x, v.x );
  2703. this.y = Math.max( this.y, v.y );
  2704. this.z = Math.max( this.z, v.z );
  2705. this.w = Math.max( this.w, v.w );
  2706. return this;
  2707. },
  2708. clamp: function ( min, max ) {
  2709. // assumes min < max, componentwise
  2710. this.x = Math.max( min.x, Math.min( max.x, this.x ) );
  2711. this.y = Math.max( min.y, Math.min( max.y, this.y ) );
  2712. this.z = Math.max( min.z, Math.min( max.z, this.z ) );
  2713. this.w = Math.max( min.w, Math.min( max.w, this.w ) );
  2714. return this;
  2715. },
  2716. clampScalar: function () {
  2717. var min, max;
  2718. return function clampScalar( minVal, maxVal ) {
  2719. if ( min === undefined ) {
  2720. min = new Vector4();
  2721. max = new Vector4();
  2722. }
  2723. min.set( minVal, minVal, minVal, minVal );
  2724. max.set( maxVal, maxVal, maxVal, maxVal );
  2725. return this.clamp( min, max );
  2726. };
  2727. }(),
  2728. clampLength: function ( min, max ) {
  2729. var length = this.length();
  2730. return this.divideScalar( length || 1 ).multiplyScalar( Math.max( min, Math.min( max, length ) ) );
  2731. },
  2732. floor: function () {
  2733. this.x = Math.floor( this.x );
  2734. this.y = Math.floor( this.y );
  2735. this.z = Math.floor( this.z );
  2736. this.w = Math.floor( this.w );
  2737. return this;
  2738. },
  2739. ceil: function () {
  2740. this.x = Math.ceil( this.x );
  2741. this.y = Math.ceil( this.y );
  2742. this.z = Math.ceil( this.z );
  2743. this.w = Math.ceil( this.w );
  2744. return this;
  2745. },
  2746. round: function () {
  2747. this.x = Math.round( this.x );
  2748. this.y = Math.round( this.y );
  2749. this.z = Math.round( this.z );
  2750. this.w = Math.round( this.w );
  2751. return this;
  2752. },
  2753. roundToZero: function () {
  2754. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  2755. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  2756. this.z = ( this.z < 0 ) ? Math.ceil( this.z ) : Math.floor( this.z );
  2757. this.w = ( this.w < 0 ) ? Math.ceil( this.w ) : Math.floor( this.w );
  2758. return this;
  2759. },
  2760. negate: function () {
  2761. this.x = - this.x;
  2762. this.y = - this.y;
  2763. this.z = - this.z;
  2764. this.w = - this.w;
  2765. return this;
  2766. },
  2767. dot: function ( v ) {
  2768. return this.x * v.x + this.y * v.y + this.z * v.z + this.w * v.w;
  2769. },
  2770. lengthSq: function () {
  2771. return this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w;
  2772. },
  2773. length: function () {
  2774. return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w );
  2775. },
  2776. manhattanLength: function () {
  2777. return Math.abs( this.x ) + Math.abs( this.y ) + Math.abs( this.z ) + Math.abs( this.w );
  2778. },
  2779. normalize: function () {
  2780. return this.divideScalar( this.length() || 1 );
  2781. },
  2782. setLength: function ( length ) {
  2783. return this.normalize().multiplyScalar( length );
  2784. },
  2785. lerp: function ( v, alpha ) {
  2786. this.x += ( v.x - this.x ) * alpha;
  2787. this.y += ( v.y - this.y ) * alpha;
  2788. this.z += ( v.z - this.z ) * alpha;
  2789. this.w += ( v.w - this.w ) * alpha;
  2790. return this;
  2791. },
  2792. lerpVectors: function ( v1, v2, alpha ) {
  2793. return this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  2794. },
  2795. equals: function ( v ) {
  2796. return ( ( v.x === this.x ) && ( v.y === this.y ) && ( v.z === this.z ) && ( v.w === this.w ) );
  2797. },
  2798. fromArray: function ( array, offset ) {
  2799. if ( offset === undefined ) offset = 0;
  2800. this.x = array[ offset ];
  2801. this.y = array[ offset + 1 ];
  2802. this.z = array[ offset + 2 ];
  2803. this.w = array[ offset + 3 ];
  2804. return this;
  2805. },
  2806. toArray: function ( array, offset ) {
  2807. if ( array === undefined ) array = [];
  2808. if ( offset === undefined ) offset = 0;
  2809. array[ offset ] = this.x;
  2810. array[ offset + 1 ] = this.y;
  2811. array[ offset + 2 ] = this.z;
  2812. array[ offset + 3 ] = this.w;
  2813. return array;
  2814. },
  2815. fromBufferAttribute: function ( attribute, index, offset ) {
  2816. if ( offset !== undefined ) {
  2817. console.warn( 'THREE.Vector4: offset has been removed from .fromBufferAttribute().' );
  2818. }
  2819. this.x = attribute.getX( index );
  2820. this.y = attribute.getY( index );
  2821. this.z = attribute.getZ( index );
  2822. this.w = attribute.getW( index );
  2823. return this;
  2824. }
  2825. } );
  2826. /**
  2827. * @author szimek / https://github.com/szimek/
  2828. * @author alteredq / http://alteredqualia.com/
  2829. * @author Marius Kintel / https://github.com/kintel
  2830. */
  2831. /*
  2832. In options, we can specify:
  2833. * Texture parameters for an auto-generated target texture
  2834. * depthBuffer/stencilBuffer: Booleans to indicate if we should generate these buffers
  2835. */
  2836. function WebGLRenderTarget( width, height, options ) {
  2837. this.width = width;
  2838. this.height = height;
  2839. this.scissor = new Vector4( 0, 0, width, height );
  2840. this.scissorTest = false;
  2841. this.viewport = new Vector4( 0, 0, width, height );
  2842. options = options || {};
  2843. this.texture = new Texture( undefined, undefined, options.wrapS, options.wrapT, options.magFilter, options.minFilter, options.format, options.type, options.anisotropy, options.encoding );
  2844. this.texture.generateMipmaps = options.generateMipmaps !== undefined ? options.generateMipmaps : false;
  2845. this.texture.minFilter = options.minFilter !== undefined ? options.minFilter : LinearFilter;
  2846. this.depthBuffer = options.depthBuffer !== undefined ? options.depthBuffer : true;
  2847. this.stencilBuffer = options.stencilBuffer !== undefined ? options.stencilBuffer : true;
  2848. this.depthTexture = options.depthTexture !== undefined ? options.depthTexture : null;
  2849. }
  2850. WebGLRenderTarget.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  2851. constructor: WebGLRenderTarget,
  2852. isWebGLRenderTarget: true,
  2853. setSize: function ( width, height ) {
  2854. if ( this.width !== width || this.height !== height ) {
  2855. this.width = width;
  2856. this.height = height;
  2857. this.dispose();
  2858. }
  2859. this.viewport.set( 0, 0, width, height );
  2860. this.scissor.set( 0, 0, width, height );
  2861. },
  2862. clone: function () {
  2863. return new this.constructor().copy( this );
  2864. },
  2865. copy: function ( source ) {
  2866. this.width = source.width;
  2867. this.height = source.height;
  2868. this.viewport.copy( source.viewport );
  2869. this.texture = source.texture.clone();
  2870. this.depthBuffer = source.depthBuffer;
  2871. this.stencilBuffer = source.stencilBuffer;
  2872. this.depthTexture = source.depthTexture;
  2873. return this;
  2874. },
  2875. dispose: function () {
  2876. this.dispatchEvent( { type: 'dispose' } );
  2877. }
  2878. } );
  2879. /**
  2880. * @author Mugen87 / https://github.com/Mugen87
  2881. * @author Matt DesLauriers / @mattdesl
  2882. */
  2883. function WebGLMultisampleRenderTarget( width, height, options ) {
  2884. WebGLRenderTarget.call( this, width, height, options );
  2885. this.samples = 4;
  2886. }
  2887. WebGLMultisampleRenderTarget.prototype = Object.assign( Object.create( WebGLRenderTarget.prototype ), {
  2888. constructor: WebGLMultisampleRenderTarget,
  2889. isWebGLMultisampleRenderTarget: true,
  2890. copy: function ( source ) {
  2891. WebGLRenderTarget.prototype.copy.call( this, source );
  2892. this.samples = source.samples;
  2893. return this;
  2894. }
  2895. } );
  2896. /**
  2897. * @author alteredq / http://alteredqualia.com
  2898. */
  2899. function WebGLRenderTargetCube( width, height, options ) {
  2900. WebGLRenderTarget.call( this, width, height, options );
  2901. }
  2902. WebGLRenderTargetCube.prototype = Object.create( WebGLRenderTarget.prototype );
  2903. WebGLRenderTargetCube.prototype.constructor = WebGLRenderTargetCube;
  2904. WebGLRenderTargetCube.prototype.isWebGLRenderTargetCube = true;
  2905. /**
  2906. * @author alteredq / http://alteredqualia.com/
  2907. */
  2908. function DataTexture( data, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, encoding ) {
  2909. Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding );
  2910. this.image = { data: data, width: width, height: height };
  2911. this.magFilter = magFilter !== undefined ? magFilter : NearestFilter;
  2912. this.minFilter = minFilter !== undefined ? minFilter : NearestFilter;
  2913. this.generateMipmaps = false;
  2914. this.flipY = false;
  2915. this.unpackAlignment = 1;
  2916. }
  2917. DataTexture.prototype = Object.create( Texture.prototype );
  2918. DataTexture.prototype.constructor = DataTexture;
  2919. DataTexture.prototype.isDataTexture = true;
  2920. /**
  2921. * @author bhouston / http://clara.io
  2922. * @author WestLangley / http://github.com/WestLangley
  2923. */
  2924. function Box3( min, max ) {
  2925. this.min = ( min !== undefined ) ? min : new Vector3( + Infinity, + Infinity, + Infinity );
  2926. this.max = ( max !== undefined ) ? max : new Vector3( - Infinity, - Infinity, - Infinity );
  2927. }
  2928. Object.assign( Box3.prototype, {
  2929. isBox3: true,
  2930. set: function ( min, max ) {
  2931. this.min.copy( min );
  2932. this.max.copy( max );
  2933. return this;
  2934. },
  2935. setFromArray: function ( array ) {
  2936. var minX = + Infinity;
  2937. var minY = + Infinity;
  2938. var minZ = + Infinity;
  2939. var maxX = - Infinity;
  2940. var maxY = - Infinity;
  2941. var maxZ = - Infinity;
  2942. for ( var i = 0, l = array.length; i < l; i += 3 ) {
  2943. var x = array[ i ];
  2944. var y = array[ i + 1 ];
  2945. var z = array[ i + 2 ];
  2946. if ( x < minX ) minX = x;
  2947. if ( y < minY ) minY = y;
  2948. if ( z < minZ ) minZ = z;
  2949. if ( x > maxX ) maxX = x;
  2950. if ( y > maxY ) maxY = y;
  2951. if ( z > maxZ ) maxZ = z;
  2952. }
  2953. this.min.set( minX, minY, minZ );
  2954. this.max.set( maxX, maxY, maxZ );
  2955. return this;
  2956. },
  2957. setFromBufferAttribute: function ( attribute ) {
  2958. var minX = + Infinity;
  2959. var minY = + Infinity;
  2960. var minZ = + Infinity;
  2961. var maxX = - Infinity;
  2962. var maxY = - Infinity;
  2963. var maxZ = - Infinity;
  2964. for ( var i = 0, l = attribute.count; i < l; i ++ ) {
  2965. var x = attribute.getX( i );
  2966. var y = attribute.getY( i );
  2967. var z = attribute.getZ( i );
  2968. if ( x < minX ) minX = x;
  2969. if ( y < minY ) minY = y;
  2970. if ( z < minZ ) minZ = z;
  2971. if ( x > maxX ) maxX = x;
  2972. if ( y > maxY ) maxY = y;
  2973. if ( z > maxZ ) maxZ = z;
  2974. }
  2975. this.min.set( minX, minY, minZ );
  2976. this.max.set( maxX, maxY, maxZ );
  2977. return this;
  2978. },
  2979. setFromPoints: function ( points ) {
  2980. this.makeEmpty();
  2981. for ( var i = 0, il = points.length; i < il; i ++ ) {
  2982. this.expandByPoint( points[ i ] );
  2983. }
  2984. return this;
  2985. },
  2986. setFromCenterAndSize: function () {
  2987. var v1 = new Vector3();
  2988. return function setFromCenterAndSize( center, size ) {
  2989. var halfSize = v1.copy( size ).multiplyScalar( 0.5 );
  2990. this.min.copy( center ).sub( halfSize );
  2991. this.max.copy( center ).add( halfSize );
  2992. return this;
  2993. };
  2994. }(),
  2995. setFromObject: function ( object ) {
  2996. this.makeEmpty();
  2997. return this.expandByObject( object );
  2998. },
  2999. clone: function () {
  3000. return new this.constructor().copy( this );
  3001. },
  3002. copy: function ( box ) {
  3003. this.min.copy( box.min );
  3004. this.max.copy( box.max );
  3005. return this;
  3006. },
  3007. makeEmpty: function () {
  3008. this.min.x = this.min.y = this.min.z = + Infinity;
  3009. this.max.x = this.max.y = this.max.z = - Infinity;
  3010. return this;
  3011. },
  3012. isEmpty: function () {
  3013. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  3014. return ( this.max.x < this.min.x ) || ( this.max.y < this.min.y ) || ( this.max.z < this.min.z );
  3015. },
  3016. getCenter: function ( target ) {
  3017. if ( target === undefined ) {
  3018. console.warn( 'THREE.Box3: .getCenter() target is now required' );
  3019. target = new Vector3();
  3020. }
  3021. return this.isEmpty() ? target.set( 0, 0, 0 ) : target.addVectors( this.min, this.max ).multiplyScalar( 0.5 );
  3022. },
  3023. getSize: function ( target ) {
  3024. if ( target === undefined ) {
  3025. console.warn( 'THREE.Box3: .getSize() target is now required' );
  3026. target = new Vector3();
  3027. }
  3028. return this.isEmpty() ? target.set( 0, 0, 0 ) : target.subVectors( this.max, this.min );
  3029. },
  3030. expandByPoint: function ( point ) {
  3031. this.min.min( point );
  3032. this.max.max( point );
  3033. return this;
  3034. },
  3035. expandByVector: function ( vector ) {
  3036. this.min.sub( vector );
  3037. this.max.add( vector );
  3038. return this;
  3039. },
  3040. expandByScalar: function ( scalar ) {
  3041. this.min.addScalar( - scalar );
  3042. this.max.addScalar( scalar );
  3043. return this;
  3044. },
  3045. expandByObject: function () {
  3046. // Computes the world-axis-aligned bounding box of an object (including its children),
  3047. // accounting for both the object's, and children's, world transforms
  3048. var scope, i, l;
  3049. var v1 = new Vector3();
  3050. function traverse( node ) {
  3051. var geometry = node.geometry;
  3052. if ( geometry !== undefined ) {
  3053. if ( geometry.isGeometry ) {
  3054. var vertices = geometry.vertices;
  3055. for ( i = 0, l = vertices.length; i < l; i ++ ) {
  3056. v1.copy( vertices[ i ] );
  3057. v1.applyMatrix4( node.matrixWorld );
  3058. scope.expandByPoint( v1 );
  3059. }
  3060. } else if ( geometry.isBufferGeometry ) {
  3061. var attribute = geometry.attributes.position;
  3062. if ( attribute !== undefined ) {
  3063. for ( i = 0, l = attribute.count; i < l; i ++ ) {
  3064. v1.fromBufferAttribute( attribute, i ).applyMatrix4( node.matrixWorld );
  3065. scope.expandByPoint( v1 );
  3066. }
  3067. }
  3068. }
  3069. }
  3070. }
  3071. return function expandByObject( object ) {
  3072. scope = this;
  3073. object.updateMatrixWorld( true );
  3074. object.traverse( traverse );
  3075. return this;
  3076. };
  3077. }(),
  3078. containsPoint: function ( point ) {
  3079. return point.x < this.min.x || point.x > this.max.x ||
  3080. point.y < this.min.y || point.y > this.max.y ||
  3081. point.z < this.min.z || point.z > this.max.z ? false : true;
  3082. },
  3083. containsBox: function ( box ) {
  3084. return this.min.x <= box.min.x && box.max.x <= this.max.x &&
  3085. this.min.y <= box.min.y && box.max.y <= this.max.y &&
  3086. this.min.z <= box.min.z && box.max.z <= this.max.z;
  3087. },
  3088. getParameter: function ( point, target ) {
  3089. // This can potentially have a divide by zero if the box
  3090. // has a size dimension of 0.
  3091. if ( target === undefined ) {
  3092. console.warn( 'THREE.Box3: .getParameter() target is now required' );
  3093. target = new Vector3();
  3094. }
  3095. return target.set(
  3096. ( point.x - this.min.x ) / ( this.max.x - this.min.x ),
  3097. ( point.y - this.min.y ) / ( this.max.y - this.min.y ),
  3098. ( point.z - this.min.z ) / ( this.max.z - this.min.z )
  3099. );
  3100. },
  3101. intersectsBox: function ( box ) {
  3102. // using 6 splitting planes to rule out intersections.
  3103. return box.max.x < this.min.x || box.min.x > this.max.x ||
  3104. box.max.y < this.min.y || box.min.y > this.max.y ||
  3105. box.max.z < this.min.z || box.min.z > this.max.z ? false : true;
  3106. },
  3107. intersectsSphere: ( function () {
  3108. var closestPoint = new Vector3();
  3109. return function intersectsSphere( sphere ) {
  3110. // Find the point on the AABB closest to the sphere center.
  3111. this.clampPoint( sphere.center, closestPoint );
  3112. // If that point is inside the sphere, the AABB and sphere intersect.
  3113. return closestPoint.distanceToSquared( sphere.center ) <= ( sphere.radius * sphere.radius );
  3114. };
  3115. } )(),
  3116. intersectsPlane: function ( plane ) {
  3117. // We compute the minimum and maximum dot product values. If those values
  3118. // are on the same side (back or front) of the plane, then there is no intersection.
  3119. var min, max;
  3120. if ( plane.normal.x > 0 ) {
  3121. min = plane.normal.x * this.min.x;
  3122. max = plane.normal.x * this.max.x;
  3123. } else {
  3124. min = plane.normal.x * this.max.x;
  3125. max = plane.normal.x * this.min.x;
  3126. }
  3127. if ( plane.normal.y > 0 ) {
  3128. min += plane.normal.y * this.min.y;
  3129. max += plane.normal.y * this.max.y;
  3130. } else {
  3131. min += plane.normal.y * this.max.y;
  3132. max += plane.normal.y * this.min.y;
  3133. }
  3134. if ( plane.normal.z > 0 ) {
  3135. min += plane.normal.z * this.min.z;
  3136. max += plane.normal.z * this.max.z;
  3137. } else {
  3138. min += plane.normal.z * this.max.z;
  3139. max += plane.normal.z * this.min.z;
  3140. }
  3141. return ( min <= - plane.constant && max >= - plane.constant );
  3142. },
  3143. intersectsTriangle: ( function () {
  3144. // triangle centered vertices
  3145. var v0 = new Vector3();
  3146. var v1 = new Vector3();
  3147. var v2 = new Vector3();
  3148. // triangle edge vectors
  3149. var f0 = new Vector3();
  3150. var f1 = new Vector3();
  3151. var f2 = new Vector3();
  3152. var testAxis = new Vector3();
  3153. var center = new Vector3();
  3154. var extents = new Vector3();
  3155. var triangleNormal = new Vector3();
  3156. function satForAxes( axes ) {
  3157. var i, j;
  3158. for ( i = 0, j = axes.length - 3; i <= j; i += 3 ) {
  3159. testAxis.fromArray( axes, i );
  3160. // project the aabb onto the seperating axis
  3161. var r = extents.x * Math.abs( testAxis.x ) + extents.y * Math.abs( testAxis.y ) + extents.z * Math.abs( testAxis.z );
  3162. // project all 3 vertices of the triangle onto the seperating axis
  3163. var p0 = v0.dot( testAxis );
  3164. var p1 = v1.dot( testAxis );
  3165. var p2 = v2.dot( testAxis );
  3166. // actual test, basically see if either of the most extreme of the triangle points intersects r
  3167. if ( Math.max( - Math.max( p0, p1, p2 ), Math.min( p0, p1, p2 ) ) > r ) {
  3168. // points of the projected triangle are outside the projected half-length of the aabb
  3169. // the axis is seperating and we can exit
  3170. return false;
  3171. }
  3172. }
  3173. return true;
  3174. }
  3175. return function intersectsTriangle( triangle ) {
  3176. if ( this.isEmpty() ) {
  3177. return false;
  3178. }
  3179. // compute box center and extents
  3180. this.getCenter( center );
  3181. extents.subVectors( this.max, center );
  3182. // translate triangle to aabb origin
  3183. v0.subVectors( triangle.a, center );
  3184. v1.subVectors( triangle.b, center );
  3185. v2.subVectors( triangle.c, center );
  3186. // compute edge vectors for triangle
  3187. f0.subVectors( v1, v0 );
  3188. f1.subVectors( v2, v1 );
  3189. f2.subVectors( v0, v2 );
  3190. // test against axes that are given by cross product combinations of the edges of the triangle and the edges of the aabb
  3191. // make an axis testing of each of the 3 sides of the aabb against each of the 3 sides of the triangle = 9 axis of separation
  3192. // axis_ij = u_i x f_j (u0, u1, u2 = face normals of aabb = x,y,z axes vectors since aabb is axis aligned)
  3193. var axes = [
  3194. 0, - f0.z, f0.y, 0, - f1.z, f1.y, 0, - f2.z, f2.y,
  3195. f0.z, 0, - f0.x, f1.z, 0, - f1.x, f2.z, 0, - f2.x,
  3196. - f0.y, f0.x, 0, - f1.y, f1.x, 0, - f2.y, f2.x, 0
  3197. ];
  3198. if ( ! satForAxes( axes ) ) {
  3199. return false;
  3200. }
  3201. // test 3 face normals from the aabb
  3202. axes = [ 1, 0, 0, 0, 1, 0, 0, 0, 1 ];
  3203. if ( ! satForAxes( axes ) ) {
  3204. return false;
  3205. }
  3206. // finally testing the face normal of the triangle
  3207. // use already existing triangle edge vectors here
  3208. triangleNormal.crossVectors( f0, f1 );
  3209. axes = [ triangleNormal.x, triangleNormal.y, triangleNormal.z ];
  3210. return satForAxes( axes );
  3211. };
  3212. } )(),
  3213. clampPoint: function ( point, target ) {
  3214. if ( target === undefined ) {
  3215. console.warn( 'THREE.Box3: .clampPoint() target is now required' );
  3216. target = new Vector3();
  3217. }
  3218. return target.copy( point ).clamp( this.min, this.max );
  3219. },
  3220. distanceToPoint: function () {
  3221. var v1 = new Vector3();
  3222. return function distanceToPoint( point ) {
  3223. var clampedPoint = v1.copy( point ).clamp( this.min, this.max );
  3224. return clampedPoint.sub( point ).length();
  3225. };
  3226. }(),
  3227. getBoundingSphere: function () {
  3228. var v1 = new Vector3();
  3229. return function getBoundingSphere( target ) {
  3230. if ( target === undefined ) {
  3231. console.warn( 'THREE.Box3: .getBoundingSphere() target is now required' );
  3232. target = new Sphere();
  3233. }
  3234. this.getCenter( target.center );
  3235. target.radius = this.getSize( v1 ).length() * 0.5;
  3236. return target;
  3237. };
  3238. }(),
  3239. intersect: function ( box ) {
  3240. this.min.max( box.min );
  3241. this.max.min( box.max );
  3242. // 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.
  3243. if ( this.isEmpty() ) this.makeEmpty();
  3244. return this;
  3245. },
  3246. union: function ( box ) {
  3247. this.min.min( box.min );
  3248. this.max.max( box.max );
  3249. return this;
  3250. },
  3251. applyMatrix4: function () {
  3252. var points = [
  3253. new Vector3(),
  3254. new Vector3(),
  3255. new Vector3(),
  3256. new Vector3(),
  3257. new Vector3(),
  3258. new Vector3(),
  3259. new Vector3(),
  3260. new Vector3()
  3261. ];
  3262. return function applyMatrix4( matrix ) {
  3263. // transform of empty box is an empty box.
  3264. if ( this.isEmpty() ) return this;
  3265. // NOTE: I am using a binary pattern to specify all 2^3 combinations below
  3266. points[ 0 ].set( this.min.x, this.min.y, this.min.z ).applyMatrix4( matrix ); // 000
  3267. points[ 1 ].set( this.min.x, this.min.y, this.max.z ).applyMatrix4( matrix ); // 001
  3268. points[ 2 ].set( this.min.x, this.max.y, this.min.z ).applyMatrix4( matrix ); // 010
  3269. points[ 3 ].set( this.min.x, this.max.y, this.max.z ).applyMatrix4( matrix ); // 011
  3270. points[ 4 ].set( this.max.x, this.min.y, this.min.z ).applyMatrix4( matrix ); // 100
  3271. points[ 5 ].set( this.max.x, this.min.y, this.max.z ).applyMatrix4( matrix ); // 101
  3272. points[ 6 ].set( this.max.x, this.max.y, this.min.z ).applyMatrix4( matrix ); // 110
  3273. points[ 7 ].set( this.max.x, this.max.y, this.max.z ).applyMatrix4( matrix ); // 111
  3274. this.setFromPoints( points );
  3275. return this;
  3276. };
  3277. }(),
  3278. translate: function ( offset ) {
  3279. this.min.add( offset );
  3280. this.max.add( offset );
  3281. return this;
  3282. },
  3283. equals: function ( box ) {
  3284. return box.min.equals( this.min ) && box.max.equals( this.max );
  3285. }
  3286. } );
  3287. /**
  3288. * @author bhouston / http://clara.io
  3289. * @author mrdoob / http://mrdoob.com/
  3290. */
  3291. function Sphere( center, radius ) {
  3292. this.center = ( center !== undefined ) ? center : new Vector3();
  3293. this.radius = ( radius !== undefined ) ? radius : 0;
  3294. }
  3295. Object.assign( Sphere.prototype, {
  3296. set: function ( center, radius ) {
  3297. this.center.copy( center );
  3298. this.radius = radius;
  3299. return this;
  3300. },
  3301. setFromPoints: function () {
  3302. var box = new Box3();
  3303. return function setFromPoints( points, optionalCenter ) {
  3304. var center = this.center;
  3305. if ( optionalCenter !== undefined ) {
  3306. center.copy( optionalCenter );
  3307. } else {
  3308. box.setFromPoints( points ).getCenter( center );
  3309. }
  3310. var maxRadiusSq = 0;
  3311. for ( var i = 0, il = points.length; i < il; i ++ ) {
  3312. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( points[ i ] ) );
  3313. }
  3314. this.radius = Math.sqrt( maxRadiusSq );
  3315. return this;
  3316. };
  3317. }(),
  3318. clone: function () {
  3319. return new this.constructor().copy( this );
  3320. },
  3321. copy: function ( sphere ) {
  3322. this.center.copy( sphere.center );
  3323. this.radius = sphere.radius;
  3324. return this;
  3325. },
  3326. empty: function () {
  3327. return ( this.radius <= 0 );
  3328. },
  3329. containsPoint: function ( point ) {
  3330. return ( point.distanceToSquared( this.center ) <= ( this.radius * this.radius ) );
  3331. },
  3332. distanceToPoint: function ( point ) {
  3333. return ( point.distanceTo( this.center ) - this.radius );
  3334. },
  3335. intersectsSphere: function ( sphere ) {
  3336. var radiusSum = this.radius + sphere.radius;
  3337. return sphere.center.distanceToSquared( this.center ) <= ( radiusSum * radiusSum );
  3338. },
  3339. intersectsBox: function ( box ) {
  3340. return box.intersectsSphere( this );
  3341. },
  3342. intersectsPlane: function ( plane ) {
  3343. return Math.abs( plane.distanceToPoint( this.center ) ) <= this.radius;
  3344. },
  3345. clampPoint: function ( point, target ) {
  3346. var deltaLengthSq = this.center.distanceToSquared( point );
  3347. if ( target === undefined ) {
  3348. console.warn( 'THREE.Sphere: .clampPoint() target is now required' );
  3349. target = new Vector3();
  3350. }
  3351. target.copy( point );
  3352. if ( deltaLengthSq > ( this.radius * this.radius ) ) {
  3353. target.sub( this.center ).normalize();
  3354. target.multiplyScalar( this.radius ).add( this.center );
  3355. }
  3356. return target;
  3357. },
  3358. getBoundingBox: function ( target ) {
  3359. if ( target === undefined ) {
  3360. console.warn( 'THREE.Sphere: .getBoundingBox() target is now required' );
  3361. target = new Box3();
  3362. }
  3363. target.set( this.center, this.center );
  3364. target.expandByScalar( this.radius );
  3365. return target;
  3366. },
  3367. applyMatrix4: function ( matrix ) {
  3368. this.center.applyMatrix4( matrix );
  3369. this.radius = this.radius * matrix.getMaxScaleOnAxis();
  3370. return this;
  3371. },
  3372. translate: function ( offset ) {
  3373. this.center.add( offset );
  3374. return this;
  3375. },
  3376. equals: function ( sphere ) {
  3377. return sphere.center.equals( this.center ) && ( sphere.radius === this.radius );
  3378. }
  3379. } );
  3380. /**
  3381. * @author bhouston / http://clara.io
  3382. */
  3383. function Plane( normal, constant ) {
  3384. // normal is assumed to be normalized
  3385. this.normal = ( normal !== undefined ) ? normal : new Vector3( 1, 0, 0 );
  3386. this.constant = ( constant !== undefined ) ? constant : 0;
  3387. }
  3388. Object.assign( Plane.prototype, {
  3389. set: function ( normal, constant ) {
  3390. this.normal.copy( normal );
  3391. this.constant = constant;
  3392. return this;
  3393. },
  3394. setComponents: function ( x, y, z, w ) {
  3395. this.normal.set( x, y, z );
  3396. this.constant = w;
  3397. return this;
  3398. },
  3399. setFromNormalAndCoplanarPoint: function ( normal, point ) {
  3400. this.normal.copy( normal );
  3401. this.constant = - point.dot( this.normal );
  3402. return this;
  3403. },
  3404. setFromCoplanarPoints: function () {
  3405. var v1 = new Vector3();
  3406. var v2 = new Vector3();
  3407. return function setFromCoplanarPoints( a, b, c ) {
  3408. var normal = v1.subVectors( c, b ).cross( v2.subVectors( a, b ) ).normalize();
  3409. // Q: should an error be thrown if normal is zero (e.g. degenerate plane)?
  3410. this.setFromNormalAndCoplanarPoint( normal, a );
  3411. return this;
  3412. };
  3413. }(),
  3414. clone: function () {
  3415. return new this.constructor().copy( this );
  3416. },
  3417. copy: function ( plane ) {
  3418. this.normal.copy( plane.normal );
  3419. this.constant = plane.constant;
  3420. return this;
  3421. },
  3422. normalize: function () {
  3423. // Note: will lead to a divide by zero if the plane is invalid.
  3424. var inverseNormalLength = 1.0 / this.normal.length();
  3425. this.normal.multiplyScalar( inverseNormalLength );
  3426. this.constant *= inverseNormalLength;
  3427. return this;
  3428. },
  3429. negate: function () {
  3430. this.constant *= - 1;
  3431. this.normal.negate();
  3432. return this;
  3433. },
  3434. distanceToPoint: function ( point ) {
  3435. return this.normal.dot( point ) + this.constant;
  3436. },
  3437. distanceToSphere: function ( sphere ) {
  3438. return this.distanceToPoint( sphere.center ) - sphere.radius;
  3439. },
  3440. projectPoint: function ( point, target ) {
  3441. if ( target === undefined ) {
  3442. console.warn( 'THREE.Plane: .projectPoint() target is now required' );
  3443. target = new Vector3();
  3444. }
  3445. return target.copy( this.normal ).multiplyScalar( - this.distanceToPoint( point ) ).add( point );
  3446. },
  3447. intersectLine: function () {
  3448. var v1 = new Vector3();
  3449. return function intersectLine( line, target ) {
  3450. if ( target === undefined ) {
  3451. console.warn( 'THREE.Plane: .intersectLine() target is now required' );
  3452. target = new Vector3();
  3453. }
  3454. var direction = line.delta( v1 );
  3455. var denominator = this.normal.dot( direction );
  3456. if ( denominator === 0 ) {
  3457. // line is coplanar, return origin
  3458. if ( this.distanceToPoint( line.start ) === 0 ) {
  3459. return target.copy( line.start );
  3460. }
  3461. // Unsure if this is the correct method to handle this case.
  3462. return undefined;
  3463. }
  3464. var t = - ( line.start.dot( this.normal ) + this.constant ) / denominator;
  3465. if ( t < 0 || t > 1 ) {
  3466. return undefined;
  3467. }
  3468. return target.copy( direction ).multiplyScalar( t ).add( line.start );
  3469. };
  3470. }(),
  3471. intersectsLine: function ( line ) {
  3472. // Note: this tests if a line intersects the plane, not whether it (or its end-points) are coplanar with it.
  3473. var startSign = this.distanceToPoint( line.start );
  3474. var endSign = this.distanceToPoint( line.end );
  3475. return ( startSign < 0 && endSign > 0 ) || ( endSign < 0 && startSign > 0 );
  3476. },
  3477. intersectsBox: function ( box ) {
  3478. return box.intersectsPlane( this );
  3479. },
  3480. intersectsSphere: function ( sphere ) {
  3481. return sphere.intersectsPlane( this );
  3482. },
  3483. coplanarPoint: function ( target ) {
  3484. if ( target === undefined ) {
  3485. console.warn( 'THREE.Plane: .coplanarPoint() target is now required' );
  3486. target = new Vector3();
  3487. }
  3488. return target.copy( this.normal ).multiplyScalar( - this.constant );
  3489. },
  3490. applyMatrix4: function () {
  3491. var v1 = new Vector3();
  3492. var m1 = new Matrix3();
  3493. return function applyMatrix4( matrix, optionalNormalMatrix ) {
  3494. var normalMatrix = optionalNormalMatrix || m1.getNormalMatrix( matrix );
  3495. var referencePoint = this.coplanarPoint( v1 ).applyMatrix4( matrix );
  3496. var normal = this.normal.applyMatrix3( normalMatrix ).normalize();
  3497. this.constant = - referencePoint.dot( normal );
  3498. return this;
  3499. };
  3500. }(),
  3501. translate: function ( offset ) {
  3502. this.constant -= offset.dot( this.normal );
  3503. return this;
  3504. },
  3505. equals: function ( plane ) {
  3506. return plane.normal.equals( this.normal ) && ( plane.constant === this.constant );
  3507. }
  3508. } );
  3509. /**
  3510. * @author mrdoob / http://mrdoob.com/
  3511. * @author alteredq / http://alteredqualia.com/
  3512. * @author bhouston / http://clara.io
  3513. */
  3514. function Frustum( p0, p1, p2, p3, p4, p5 ) {
  3515. this.planes = [
  3516. ( p0 !== undefined ) ? p0 : new Plane(),
  3517. ( p1 !== undefined ) ? p1 : new Plane(),
  3518. ( p2 !== undefined ) ? p2 : new Plane(),
  3519. ( p3 !== undefined ) ? p3 : new Plane(),
  3520. ( p4 !== undefined ) ? p4 : new Plane(),
  3521. ( p5 !== undefined ) ? p5 : new Plane()
  3522. ];
  3523. }
  3524. Object.assign( Frustum.prototype, {
  3525. set: function ( p0, p1, p2, p3, p4, p5 ) {
  3526. var planes = this.planes;
  3527. planes[ 0 ].copy( p0 );
  3528. planes[ 1 ].copy( p1 );
  3529. planes[ 2 ].copy( p2 );
  3530. planes[ 3 ].copy( p3 );
  3531. planes[ 4 ].copy( p4 );
  3532. planes[ 5 ].copy( p5 );
  3533. return this;
  3534. },
  3535. clone: function () {
  3536. return new this.constructor().copy( this );
  3537. },
  3538. copy: function ( frustum ) {
  3539. var planes = this.planes;
  3540. for ( var i = 0; i < 6; i ++ ) {
  3541. planes[ i ].copy( frustum.planes[ i ] );
  3542. }
  3543. return this;
  3544. },
  3545. setFromMatrix: function ( m ) {
  3546. var planes = this.planes;
  3547. var me = m.elements;
  3548. var me0 = me[ 0 ], me1 = me[ 1 ], me2 = me[ 2 ], me3 = me[ 3 ];
  3549. var me4 = me[ 4 ], me5 = me[ 5 ], me6 = me[ 6 ], me7 = me[ 7 ];
  3550. var me8 = me[ 8 ], me9 = me[ 9 ], me10 = me[ 10 ], me11 = me[ 11 ];
  3551. var me12 = me[ 12 ], me13 = me[ 13 ], me14 = me[ 14 ], me15 = me[ 15 ];
  3552. planes[ 0 ].setComponents( me3 - me0, me7 - me4, me11 - me8, me15 - me12 ).normalize();
  3553. planes[ 1 ].setComponents( me3 + me0, me7 + me4, me11 + me8, me15 + me12 ).normalize();
  3554. planes[ 2 ].setComponents( me3 + me1, me7 + me5, me11 + me9, me15 + me13 ).normalize();
  3555. planes[ 3 ].setComponents( me3 - me1, me7 - me5, me11 - me9, me15 - me13 ).normalize();
  3556. planes[ 4 ].setComponents( me3 - me2, me7 - me6, me11 - me10, me15 - me14 ).normalize();
  3557. planes[ 5 ].setComponents( me3 + me2, me7 + me6, me11 + me10, me15 + me14 ).normalize();
  3558. return this;
  3559. },
  3560. intersectsObject: function () {
  3561. var sphere = new Sphere();
  3562. return function intersectsObject( object ) {
  3563. var geometry = object.geometry;
  3564. if ( geometry.boundingSphere === null )
  3565. geometry.computeBoundingSphere();
  3566. sphere.copy( geometry.boundingSphere )
  3567. .applyMatrix4( object.matrixWorld );
  3568. return this.intersectsSphere( sphere );
  3569. };
  3570. }(),
  3571. intersectsSprite: function () {
  3572. var sphere = new Sphere();
  3573. return function intersectsSprite( sprite ) {
  3574. sphere.center.set( 0, 0, 0 );
  3575. sphere.radius = 0.7071067811865476;
  3576. sphere.applyMatrix4( sprite.matrixWorld );
  3577. return this.intersectsSphere( sphere );
  3578. };
  3579. }(),
  3580. intersectsSphere: function ( sphere ) {
  3581. var planes = this.planes;
  3582. var center = sphere.center;
  3583. var negRadius = - sphere.radius;
  3584. for ( var i = 0; i < 6; i ++ ) {
  3585. var distance = planes[ i ].distanceToPoint( center );
  3586. if ( distance < negRadius ) {
  3587. return false;
  3588. }
  3589. }
  3590. return true;
  3591. },
  3592. intersectsBox: function () {
  3593. var p = new Vector3();
  3594. return function intersectsBox( box ) {
  3595. var planes = this.planes;
  3596. for ( var i = 0; i < 6; i ++ ) {
  3597. var plane = planes[ i ];
  3598. // corner at max distance
  3599. p.x = plane.normal.x > 0 ? box.max.x : box.min.x;
  3600. p.y = plane.normal.y > 0 ? box.max.y : box.min.y;
  3601. p.z = plane.normal.z > 0 ? box.max.z : box.min.z;
  3602. if ( plane.distanceToPoint( p ) < 0 ) {
  3603. return false;
  3604. }
  3605. }
  3606. return true;
  3607. };
  3608. }(),
  3609. containsPoint: function ( point ) {
  3610. var planes = this.planes;
  3611. for ( var i = 0; i < 6; i ++ ) {
  3612. if ( planes[ i ].distanceToPoint( point ) < 0 ) {
  3613. return false;
  3614. }
  3615. }
  3616. return true;
  3617. }
  3618. } );
  3619. var alphamap_fragment = "#ifdef USE_ALPHAMAP\n\tdiffuseColor.a *= texture2D( alphaMap, vUv ).g;\n#endif";
  3620. var alphamap_pars_fragment = "#ifdef USE_ALPHAMAP\n\tuniform sampler2D alphaMap;\n#endif";
  3621. var alphatest_fragment = "#ifdef ALPHATEST\n\tif ( diffuseColor.a < ALPHATEST ) discard;\n#endif";
  3622. var aomap_fragment = "#ifdef USE_AOMAP\n\tfloat ambientOcclusion = ( texture2D( aoMap, vUv2 ).r - 1.0 ) * aoMapIntensity + 1.0;\n\treflectedLight.indirectDiffuse *= ambientOcclusion;\n\t#if defined( USE_ENVMAP ) && defined( PHYSICAL )\n\t\tfloat dotNV = saturate( dot( geometry.normal, geometry.viewDir ) );\n\t\treflectedLight.indirectSpecular *= computeSpecularOcclusion( dotNV, ambientOcclusion, material.specularRoughness );\n\t#endif\n#endif";
  3623. var aomap_pars_fragment = "#ifdef USE_AOMAP\n\tuniform sampler2D aoMap;\n\tuniform float aoMapIntensity;\n#endif";
  3624. var begin_vertex = "vec3 transformed = vec3( position );";
  3625. var beginnormal_vertex = "vec3 objectNormal = vec3( normal );\n#ifdef USE_TANGENT\n\tvec3 objectTangent = vec3( tangent.xyz );\n#endif";
  3626. var bsdfs = "vec2 integrateSpecularBRDF( const in float dotNV, const in float roughness ) {\n\tconst vec4 c0 = vec4( - 1, - 0.0275, - 0.572, 0.022 );\n\tconst vec4 c1 = vec4( 1, 0.0425, 1.04, - 0.04 );\n\tvec4 r = roughness * c0 + c1;\n\tfloat a004 = min( r.x * r.x, exp2( - 9.28 * dotNV ) ) * r.x + r.y;\n\treturn vec2( -1.04, 1.04 ) * a004 + r.zw;\n}\nfloat punctualLightIntensityToIrradianceFactor( const in float lightDistance, const in float cutoffDistance, const in float decayExponent ) {\n#if defined ( PHYSICALLY_CORRECT_LIGHTS )\n\tfloat distanceFalloff = 1.0 / max( pow( lightDistance, decayExponent ), 0.01 );\n\tif( cutoffDistance > 0.0 ) {\n\t\tdistanceFalloff *= pow2( saturate( 1.0 - pow4( lightDistance / cutoffDistance ) ) );\n\t}\n\treturn distanceFalloff;\n#else\n\tif( cutoffDistance > 0.0 && decayExponent > 0.0 ) {\n\t\treturn pow( saturate( -lightDistance / cutoffDistance + 1.0 ), decayExponent );\n\t}\n\treturn 1.0;\n#endif\n}\nvec3 BRDF_Diffuse_Lambert( const in vec3 diffuseColor ) {\n\treturn RECIPROCAL_PI * diffuseColor;\n}\nvec3 F_Schlick( const in vec3 specularColor, const in float dotLH ) {\n\tfloat fresnel = exp2( ( -5.55473 * dotLH - 6.98316 ) * dotLH );\n\treturn ( 1.0 - specularColor ) * fresnel + specularColor;\n}\nfloat G_GGX_Smith( const in float alpha, const in float dotNL, const in float dotNV ) {\n\tfloat a2 = pow2( alpha );\n\tfloat gl = dotNL + sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNL ) );\n\tfloat gv = dotNV + sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNV ) );\n\treturn 1.0 / ( gl * gv );\n}\nfloat G_GGX_SmithCorrelated( const in float alpha, const in float dotNL, const in float dotNV ) {\n\tfloat a2 = pow2( alpha );\n\tfloat gv = dotNL * sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNV ) );\n\tfloat gl = dotNV * sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNL ) );\n\treturn 0.5 / max( gv + gl, EPSILON );\n}\nfloat D_GGX( const in float alpha, const in float dotNH ) {\n\tfloat a2 = pow2( alpha );\n\tfloat denom = pow2( dotNH ) * ( a2 - 1.0 ) + 1.0;\n\treturn 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\tfloat alpha = pow2( roughness );\n\tvec3 halfDir = normalize( incidentLight.direction + geometry.viewDir );\n\tfloat dotNL = saturate( dot( geometry.normal, incidentLight.direction ) );\n\tfloat dotNV = saturate( dot( geometry.normal, geometry.viewDir ) );\n\tfloat dotNH = saturate( dot( geometry.normal, halfDir ) );\n\tfloat dotLH = saturate( dot( incidentLight.direction, halfDir ) );\n\tvec3 F = F_Schlick( specularColor, dotLH );\n\tfloat G = G_GGX_SmithCorrelated( alpha, dotNL, dotNV );\n\tfloat D = D_GGX( alpha, dotNH );\n\treturn F * ( G * D );\n}\nvec2 LTC_Uv( const in vec3 N, const in vec3 V, const in float roughness ) {\n\tconst float LUT_SIZE = 64.0;\n\tconst float LUT_SCALE = ( LUT_SIZE - 1.0 ) / LUT_SIZE;\n\tconst float LUT_BIAS = 0.5 / LUT_SIZE;\n\tfloat dotNV = saturate( dot( N, V ) );\n\tvec2 uv = vec2( roughness, sqrt( 1.0 - dotNV ) );\n\tuv = uv * LUT_SCALE + LUT_BIAS;\n\treturn uv;\n}\nfloat LTC_ClippedSphereFormFactor( const in vec3 f ) {\n\tfloat l = length( f );\n\treturn max( ( l * l + f.z ) / ( l + 1.0 ), 0.0 );\n}\nvec3 LTC_EdgeVectorFormFactor( const in vec3 v1, const in vec3 v2 ) {\n\tfloat x = dot( v1, v2 );\n\tfloat y = abs( x );\n\tfloat a = 0.8543985 + ( 0.4965155 + 0.0145206 * y ) * y;\n\tfloat b = 3.4175940 + ( 4.1616724 + y ) * y;\n\tfloat v = a / b;\n\tfloat theta_sintheta = ( x > 0.0 ) ? v : 0.5 * inversesqrt( max( 1.0 - x * x, 1e-7 ) ) - v;\n\treturn cross( v1, v2 ) * theta_sintheta;\n}\nvec3 LTC_Evaluate( const in vec3 N, const in vec3 V, const in vec3 P, const in mat3 mInv, const in vec3 rectCoords[ 4 ] ) {\n\tvec3 v1 = rectCoords[ 1 ] - rectCoords[ 0 ];\n\tvec3 v2 = rectCoords[ 3 ] - rectCoords[ 0 ];\n\tvec3 lightNormal = cross( v1, v2 );\n\tif( dot( lightNormal, P - rectCoords[ 0 ] ) < 0.0 ) return vec3( 0.0 );\n\tvec3 T1, T2;\n\tT1 = normalize( V - N * dot( V, N ) );\n\tT2 = - cross( N, T1 );\n\tmat3 mat = mInv * transposeMat3( mat3( T1, T2, N ) );\n\tvec3 coords[ 4 ];\n\tcoords[ 0 ] = mat * ( rectCoords[ 0 ] - P );\n\tcoords[ 1 ] = mat * ( rectCoords[ 1 ] - P );\n\tcoords[ 2 ] = mat * ( rectCoords[ 2 ] - P );\n\tcoords[ 3 ] = mat * ( rectCoords[ 3 ] - P );\n\tcoords[ 0 ] = normalize( coords[ 0 ] );\n\tcoords[ 1 ] = normalize( coords[ 1 ] );\n\tcoords[ 2 ] = normalize( coords[ 2 ] );\n\tcoords[ 3 ] = normalize( coords[ 3 ] );\n\tvec3 vectorFormFactor = vec3( 0.0 );\n\tvectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 0 ], coords[ 1 ] );\n\tvectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 1 ], coords[ 2 ] );\n\tvectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 2 ], coords[ 3 ] );\n\tvectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 3 ], coords[ 0 ] );\n\tfloat result = LTC_ClippedSphereFormFactor( vectorFormFactor );\n\treturn vec3( result );\n}\nvec3 BRDF_Specular_GGX_Environment( const in GeometricContext geometry, const in vec3 specularColor, const in float roughness ) {\n\tfloat dotNV = saturate( dot( geometry.normal, geometry.viewDir ) );\n\tvec2 brdf = integrateSpecularBRDF( dotNV, roughness );\n\treturn specularColor * brdf.x + brdf.y;\n}\nvoid BRDF_Specular_Multiscattering_Environment( const in GeometricContext geometry, const in vec3 specularColor, const in float roughness, inout vec3 singleScatter, inout vec3 multiScatter ) {\n\tfloat dotNV = saturate( dot( geometry.normal, geometry.viewDir ) );\n\tvec3 F = F_Schlick( specularColor, dotNV );\n\tvec2 brdf = integrateSpecularBRDF( dotNV, roughness );\n\tvec3 FssEss = F * brdf.x + brdf.y;\n\tfloat Ess = brdf.x + brdf.y;\n\tfloat Ems = 1.0 - Ess;\n\tvec3 Favg = specularColor + ( 1.0 - specularColor ) * 0.047619;\tvec3 Fms = FssEss * Favg / ( 1.0 - Ems * Favg );\n\tsingleScatter += FssEss;\n\tmultiScatter += Fms * Ems;\n}\nfloat G_BlinnPhong_Implicit( ) {\n\treturn 0.25;\n}\nfloat D_BlinnPhong( const in float shininess, const in float dotNH ) {\n\treturn 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\tvec3 halfDir = normalize( incidentLight.direction + geometry.viewDir );\n\tfloat dotNH = saturate( dot( geometry.normal, halfDir ) );\n\tfloat dotLH = saturate( dot( incidentLight.direction, halfDir ) );\n\tvec3 F = F_Schlick( specularColor, dotLH );\n\tfloat G = G_BlinnPhong_Implicit( );\n\tfloat D = D_BlinnPhong( shininess, dotNH );\n\treturn F * ( G * D );\n}\nfloat GGXRoughnessToBlinnExponent( const in float ggxRoughness ) {\n\treturn ( 2.0 / pow2( ggxRoughness + 0.0001 ) - 2.0 );\n}\nfloat BlinnExponentToGGXRoughness( const in float blinnExponent ) {\n\treturn sqrt( 2.0 / ( blinnExponent + 2.0 ) );\n}";
  3627. var bumpmap_pars_fragment = "#ifdef USE_BUMPMAP\n\tuniform sampler2D bumpMap;\n\tuniform float bumpScale;\n\tvec2 dHdxy_fwd() {\n\t\tvec2 dSTdx = dFdx( vUv );\n\t\tvec2 dSTdy = dFdy( vUv );\n\t\tfloat Hll = bumpScale * texture2D( bumpMap, vUv ).x;\n\t\tfloat dBx = bumpScale * texture2D( bumpMap, vUv + dSTdx ).x - Hll;\n\t\tfloat dBy = bumpScale * texture2D( bumpMap, vUv + dSTdy ).x - Hll;\n\t\treturn vec2( dBx, dBy );\n\t}\n\tvec3 perturbNormalArb( vec3 surf_pos, vec3 surf_norm, vec2 dHdxy ) {\n\t\tvec3 vSigmaX = vec3( dFdx( surf_pos.x ), dFdx( surf_pos.y ), dFdx( surf_pos.z ) );\n\t\tvec3 vSigmaY = vec3( dFdy( surf_pos.x ), dFdy( surf_pos.y ), dFdy( surf_pos.z ) );\n\t\tvec3 vN = surf_norm;\n\t\tvec3 R1 = cross( vSigmaY, vN );\n\t\tvec3 R2 = cross( vN, vSigmaX );\n\t\tfloat fDet = dot( vSigmaX, R1 );\n\t\tfDet *= ( float( gl_FrontFacing ) * 2.0 - 1.0 );\n\t\tvec3 vGrad = sign( fDet ) * ( dHdxy.x * R1 + dHdxy.y * R2 );\n\t\treturn normalize( abs( fDet ) * surf_norm - vGrad );\n\t}\n#endif";
  3628. var clipping_planes_fragment = "#if NUM_CLIPPING_PLANES > 0\n\tvec4 plane;\n\t#pragma unroll_loop\n\tfor ( int i = 0; i < UNION_CLIPPING_PLANES; i ++ ) {\n\t\tplane = clippingPlanes[ i ];\n\t\tif ( dot( vViewPosition, plane.xyz ) > plane.w ) discard;\n\t}\n\t#if UNION_CLIPPING_PLANES < NUM_CLIPPING_PLANES\n\t\tbool clipped = true;\n\t\t#pragma unroll_loop\n\t\tfor ( int i = UNION_CLIPPING_PLANES; i < NUM_CLIPPING_PLANES; i ++ ) {\n\t\t\tplane = clippingPlanes[ i ];\n\t\t\tclipped = ( dot( vViewPosition, plane.xyz ) > plane.w ) && clipped;\n\t\t}\n\t\tif ( clipped ) discard;\n\t#endif\n#endif";
  3629. var clipping_planes_pars_fragment = "#if NUM_CLIPPING_PLANES > 0\n\t#if ! defined( PHYSICAL ) && ! defined( PHONG ) && ! defined( MATCAP )\n\t\tvarying vec3 vViewPosition;\n\t#endif\n\tuniform vec4 clippingPlanes[ NUM_CLIPPING_PLANES ];\n#endif";
  3630. var clipping_planes_pars_vertex = "#if NUM_CLIPPING_PLANES > 0 && ! defined( PHYSICAL ) && ! defined( PHONG ) && ! defined( MATCAP )\n\tvarying vec3 vViewPosition;\n#endif";
  3631. var clipping_planes_vertex = "#if NUM_CLIPPING_PLANES > 0 && ! defined( PHYSICAL ) && ! defined( PHONG ) && ! defined( MATCAP )\n\tvViewPosition = - mvPosition.xyz;\n#endif";
  3632. var color_fragment = "#ifdef USE_COLOR\n\tdiffuseColor.rgb *= vColor;\n#endif";
  3633. var color_pars_fragment = "#ifdef USE_COLOR\n\tvarying vec3 vColor;\n#endif";
  3634. var color_pars_vertex = "#ifdef USE_COLOR\n\tvarying vec3 vColor;\n#endif";
  3635. var color_vertex = "#ifdef USE_COLOR\n\tvColor.xyz = color.xyz;\n#endif";
  3636. var common = "#define PI 3.14159265359\n#define PI2 6.28318530718\n#define PI_HALF 1.5707963267949\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\tconst highp float a = 12.9898, b = 78.233, c = 43758.5453;\n\thighp float dt = dot( uv.xy, vec2( a,b ) ), sn = mod( dt, PI );\n\treturn fract(sin(sn) * c);\n}\nstruct IncidentLight {\n\tvec3 color;\n\tvec3 direction;\n\tbool visible;\n};\nstruct ReflectedLight {\n\tvec3 directDiffuse;\n\tvec3 directSpecular;\n\tvec3 indirectDiffuse;\n\tvec3 indirectSpecular;\n};\nstruct GeometricContext {\n\tvec3 position;\n\tvec3 normal;\n\tvec3 viewDir;\n};\nvec3 transformDirection( in vec3 dir, in mat4 matrix ) {\n\treturn normalize( ( matrix * vec4( dir, 0.0 ) ).xyz );\n}\nvec3 inverseTransformDirection( in vec3 dir, in mat4 matrix ) {\n\treturn normalize( ( vec4( dir, 0.0 ) * matrix ).xyz );\n}\nvec3 projectOnPlane(in vec3 point, in vec3 pointOnPlane, in vec3 planeNormal ) {\n\tfloat distance = dot( planeNormal, point - pointOnPlane );\n\treturn - distance * planeNormal + point;\n}\nfloat sideOfPlane( in vec3 point, in vec3 pointOnPlane, in vec3 planeNormal ) {\n\treturn sign( dot( point - pointOnPlane, planeNormal ) );\n}\nvec3 linePlaneIntersect( in vec3 pointOnLine, in vec3 lineDirection, in vec3 pointOnPlane, in vec3 planeNormal ) {\n\treturn lineDirection * ( dot( planeNormal, pointOnPlane - pointOnLine ) / dot( planeNormal, lineDirection ) ) + pointOnLine;\n}\nmat3 transposeMat3( const in mat3 m ) {\n\tmat3 tmp;\n\ttmp[ 0 ] = vec3( m[ 0 ].x, m[ 1 ].x, m[ 2 ].x );\n\ttmp[ 1 ] = vec3( m[ 0 ].y, m[ 1 ].y, m[ 2 ].y );\n\ttmp[ 2 ] = vec3( m[ 0 ].z, m[ 1 ].z, m[ 2 ].z );\n\treturn tmp;\n}\nfloat linearToRelativeLuminance( const in vec3 color ) {\n\tvec3 weights = vec3( 0.2126, 0.7152, 0.0722 );\n\treturn dot( weights, color.rgb );\n}";
  3637. var cube_uv_reflection_fragment = "#ifdef ENVMAP_TYPE_CUBE_UV\n#define cubeUV_textureSize (1024.0)\nint getFaceFromDirection(vec3 direction) {\n\tvec3 absDirection = abs(direction);\n\tint face = -1;\n\tif( absDirection.x > absDirection.z ) {\n\t\tif(absDirection.x > absDirection.y )\n\t\t\tface = direction.x > 0.0 ? 0 : 3;\n\t\telse\n\t\t\tface = direction.y > 0.0 ? 1 : 4;\n\t}\n\telse {\n\t\tif(absDirection.z > absDirection.y )\n\t\t\tface = direction.z > 0.0 ? 2 : 5;\n\t\telse\n\t\t\tface = direction.y > 0.0 ? 1 : 4;\n\t}\n\treturn 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\tfloat scale = exp2(cubeUV_maxLods1 - roughnessLevel);\n\tfloat dxRoughness = dFdx(roughness);\n\tfloat dyRoughness = dFdy(roughness);\n\tvec3 dx = dFdx( vec * scale * dxRoughness );\n\tvec3 dy = dFdy( vec * scale * dyRoughness );\n\tfloat d = max( dot( dx, dx ), dot( dy, dy ) );\n\td = clamp(d, 1.0, cubeUV_rangeClamp);\n\tfloat mipLevel = 0.5 * log2(d);\n\treturn 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\tmipLevel = roughnessLevel > cubeUV_maxLods2 - 3.0 ? 0.0 : mipLevel;\n\tfloat a = 16.0 * cubeUV_rcpTextureSize;\n\tvec2 exp2_packed = exp2( vec2( roughnessLevel, mipLevel ) );\n\tvec2 rcp_exp2_packed = vec2( 1.0 ) / exp2_packed;\n\tfloat powScale = exp2_packed.x * exp2_packed.y;\n\tfloat scale = rcp_exp2_packed.x * rcp_exp2_packed.y * 0.25;\n\tfloat mipOffset = 0.75*(1.0 - rcp_exp2_packed.y) * rcp_exp2_packed.x;\n\tbool bRes = mipLevel == 0.0;\n\tscale = bRes && (scale < a) ? a : scale;\n\tvec3 r;\n\tvec2 offset;\n\tint face = getFaceFromDirection(direction);\n\tfloat rcpPowScale = 1.0 / powScale;\n\tif( face == 0) {\n\t\tr = vec3(direction.x, -direction.z, direction.y);\n\t\toffset = vec2(0.0+mipOffset,0.75 * rcpPowScale);\n\t\toffset.y = bRes && (offset.y < 2.0*a) ? a : offset.y;\n\t}\n\telse if( face == 1) {\n\t\tr = vec3(direction.y, direction.x, direction.z);\n\t\toffset = vec2(scale+mipOffset, 0.75 * rcpPowScale);\n\t\toffset.y = bRes && (offset.y < 2.0*a) ? a : offset.y;\n\t}\n\telse if( face == 2) {\n\t\tr = vec3(direction.z, direction.x, direction.y);\n\t\toffset = vec2(2.0*scale+mipOffset, 0.75 * rcpPowScale);\n\t\toffset.y = bRes && (offset.y < 2.0*a) ? a : offset.y;\n\t}\n\telse if( face == 3) {\n\t\tr = vec3(direction.x, direction.z, direction.y);\n\t\toffset = vec2(0.0+mipOffset,0.5 * rcpPowScale);\n\t\toffset.y = bRes && (offset.y < 2.0*a) ? 0.0 : offset.y;\n\t}\n\telse if( face == 4) {\n\t\tr = vec3(direction.y, direction.x, -direction.z);\n\t\toffset = vec2(scale+mipOffset, 0.5 * rcpPowScale);\n\t\toffset.y = bRes && (offset.y < 2.0*a) ? 0.0 : offset.y;\n\t}\n\telse {\n\t\tr = vec3(direction.z, -direction.x, direction.y);\n\t\toffset = vec2(2.0*scale+mipOffset, 0.5 * rcpPowScale);\n\t\toffset.y = bRes && (offset.y < 2.0*a) ? 0.0 : offset.y;\n\t}\n\tr = normalize(r);\n\tfloat texelOffset = 0.5 * cubeUV_rcpTextureSize;\n\tvec2 s = ( r.yz / abs( r.x ) + vec2( 1.0 ) ) * 0.5;\n\tvec2 base = offset + vec2( texelOffset );\n\treturn base + s * ( scale - 2.0 * texelOffset );\n}\n#define cubeUV_maxLods3 (log2(cubeUV_textureSize*0.25) - 3.0)\nvec4 textureCubeUV( sampler2D envMap, vec3 reflectedDirection, float roughness ) {\n\tfloat roughnessVal = roughness* cubeUV_maxLods3;\n\tfloat r1 = floor(roughnessVal);\n\tfloat r2 = r1 + 1.0;\n\tfloat t = fract(roughnessVal);\n\tvec2 mipInfo = MipLevelInfo(reflectedDirection, r1, roughness);\n\tfloat s = mipInfo.y;\n\tfloat level0 = mipInfo.x;\n\tfloat level1 = level0 + 1.0;\n\tlevel1 = level1 > 5.0 ? 5.0 : level1;\n\tlevel0 += min( floor( s + 0.5 ), 5.0 );\n\tvec2 uv_10 = getCubeUV(reflectedDirection, r1, level0);\n\tvec4 color10 = envMapTexelToLinear(texture2D(envMap, uv_10));\n\tvec2 uv_20 = getCubeUV(reflectedDirection, r2, level0);\n\tvec4 color20 = envMapTexelToLinear(texture2D(envMap, uv_20));\n\tvec4 result = mix(color10, color20, t);\n\treturn vec4(result.rgb, 1.0);\n}\n#endif";
  3638. var defaultnormal_vertex = "vec3 transformedNormal = normalMatrix * objectNormal;\n#ifdef FLIP_SIDED\n\ttransformedNormal = - transformedNormal;\n#endif\n#ifdef USE_TANGENT\n\tvec3 transformedTangent = normalMatrix * objectTangent;\n\t#ifdef FLIP_SIDED\n\t\ttransformedTangent = - transformedTangent;\n\t#endif\n#endif";
  3639. var displacementmap_pars_vertex = "#ifdef USE_DISPLACEMENTMAP\n\tuniform sampler2D displacementMap;\n\tuniform float displacementScale;\n\tuniform float displacementBias;\n#endif";
  3640. var displacementmap_vertex = "#ifdef USE_DISPLACEMENTMAP\n\ttransformed += normalize( objectNormal ) * ( texture2D( displacementMap, uv ).x * displacementScale + displacementBias );\n#endif";
  3641. var emissivemap_fragment = "#ifdef USE_EMISSIVEMAP\n\tvec4 emissiveColor = texture2D( emissiveMap, vUv );\n\temissiveColor.rgb = emissiveMapTexelToLinear( emissiveColor ).rgb;\n\ttotalEmissiveRadiance *= emissiveColor.rgb;\n#endif";
  3642. var emissivemap_pars_fragment = "#ifdef USE_EMISSIVEMAP\n\tuniform sampler2D emissiveMap;\n#endif";
  3643. var encodings_fragment = "gl_FragColor = linearToOutputTexel( gl_FragColor );";
  3644. var encodings_pars_fragment = "\nvec4 LinearToLinear( in vec4 value ) {\n\treturn value;\n}\nvec4 GammaToLinear( in vec4 value, in float gammaFactor ) {\n\treturn vec4( pow( value.rgb, vec3( gammaFactor ) ), value.a );\n}\nvec4 LinearToGamma( in vec4 value, in float gammaFactor ) {\n\treturn vec4( pow( value.rgb, vec3( 1.0 / gammaFactor ) ), value.a );\n}\nvec4 sRGBToLinear( in vec4 value ) {\n\treturn 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.a );\n}\nvec4 LinearTosRGB( in vec4 value ) {\n\treturn 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.a );\n}\nvec4 RGBEToLinear( in vec4 value ) {\n\treturn vec4( value.rgb * exp2( value.a * 255.0 - 128.0 ), 1.0 );\n}\nvec4 LinearToRGBE( in vec4 value ) {\n\tfloat maxComponent = max( max( value.r, value.g ), value.b );\n\tfloat fExp = clamp( ceil( log2( maxComponent ) ), -128.0, 127.0 );\n\treturn vec4( value.rgb / exp2( fExp ), ( fExp + 128.0 ) / 255.0 );\n}\nvec4 RGBMToLinear( in vec4 value, in float maxRange ) {\n\treturn vec4( value.rgb * value.a * maxRange, 1.0 );\n}\nvec4 LinearToRGBM( in vec4 value, in float maxRange ) {\n\tfloat maxRGB = max( value.r, max( value.g, value.b ) );\n\tfloat M = clamp( maxRGB / maxRange, 0.0, 1.0 );\n\tM = ceil( M * 255.0 ) / 255.0;\n\treturn vec4( value.rgb / ( M * maxRange ), M );\n}\nvec4 RGBDToLinear( in vec4 value, in float maxRange ) {\n\treturn vec4( value.rgb * ( ( maxRange / 255.0 ) / value.a ), 1.0 );\n}\nvec4 LinearToRGBD( in vec4 value, in float maxRange ) {\n\tfloat maxRGB = max( value.r, max( value.g, value.b ) );\n\tfloat D = max( maxRange / maxRGB, 1.0 );\n\tD = min( floor( D ) / 255.0, 1.0 );\n\treturn 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\tvec3 Xp_Y_XYZp = cLogLuvM * value.rgb;\n\tXp_Y_XYZp = max( Xp_Y_XYZp, vec3( 1e-6, 1e-6, 1e-6 ) );\n\tvec4 vResult;\n\tvResult.xy = Xp_Y_XYZp.xy / Xp_Y_XYZp.z;\n\tfloat Le = 2.0 * log2(Xp_Y_XYZp.y) + 127.0;\n\tvResult.w = fract( Le );\n\tvResult.z = ( Le - ( floor( vResult.w * 255.0 ) ) / 255.0 ) / 255.0;\n\treturn 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\tfloat Le = value.z * 255.0 + value.w;\n\tvec3 Xp_Y_XYZp;\n\tXp_Y_XYZp.y = exp2( ( Le - 127.0 ) / 2.0 );\n\tXp_Y_XYZp.z = Xp_Y_XYZp.y / value.y;\n\tXp_Y_XYZp.x = value.x * Xp_Y_XYZp.z;\n\tvec3 vRGB = cLogLuvInverseM * Xp_Y_XYZp.rgb;\n\treturn vec4( max( vRGB, 0.0 ), 1.0 );\n}";
  3645. var envmap_fragment = "#ifdef USE_ENVMAP\n\t#if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG )\n\t\tvec3 cameraToVertex = normalize( vWorldPosition - cameraPosition );\n\t\tvec3 worldNormal = inverseTransformDirection( normal, viewMatrix );\n\t\t#ifdef ENVMAP_MODE_REFLECTION\n\t\t\tvec3 reflectVec = reflect( cameraToVertex, worldNormal );\n\t\t#else\n\t\t\tvec3 reflectVec = refract( cameraToVertex, worldNormal, refractionRatio );\n\t\t#endif\n\t#else\n\t\tvec3 reflectVec = vReflect;\n\t#endif\n\t#ifdef ENVMAP_TYPE_CUBE\n\t\tvec4 envColor = textureCube( envMap, vec3( flipEnvMap * reflectVec.x, reflectVec.yz ) );\n\t#elif defined( ENVMAP_TYPE_EQUIREC )\n\t\tvec2 sampleUV;\n\t\treflectVec = normalize( reflectVec );\n\t\tsampleUV.y = asin( clamp( reflectVec.y, - 1.0, 1.0 ) ) * RECIPROCAL_PI + 0.5;\n\t\tsampleUV.x = atan( reflectVec.z, reflectVec.x ) * RECIPROCAL_PI2 + 0.5;\n\t\tvec4 envColor = texture2D( envMap, sampleUV );\n\t#elif defined( ENVMAP_TYPE_SPHERE )\n\t\treflectVec = normalize( reflectVec );\n\t\tvec3 reflectView = normalize( ( viewMatrix * vec4( reflectVec, 0.0 ) ).xyz + vec3( 0.0, 0.0, 1.0 ) );\n\t\tvec4 envColor = texture2D( envMap, reflectView.xy * 0.5 + 0.5 );\n\t#else\n\t\tvec4 envColor = vec4( 0.0 );\n\t#endif\n\tenvColor = envMapTexelToLinear( envColor );\n\t#ifdef ENVMAP_BLENDING_MULTIPLY\n\t\toutgoingLight = mix( outgoingLight, outgoingLight * envColor.xyz, specularStrength * reflectivity );\n\t#elif defined( ENVMAP_BLENDING_MIX )\n\t\toutgoingLight = mix( outgoingLight, envColor.xyz, specularStrength * reflectivity );\n\t#elif defined( ENVMAP_BLENDING_ADD )\n\t\toutgoingLight += envColor.xyz * specularStrength * reflectivity;\n\t#endif\n#endif";
  3646. var envmap_pars_fragment = "#if defined( USE_ENVMAP ) || defined( PHYSICAL )\n\tuniform float reflectivity;\n\tuniform float envMapIntensity;\n#endif\n#ifdef USE_ENVMAP\n\t#if ! defined( PHYSICAL ) && ( defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG ) )\n\t\tvarying vec3 vWorldPosition;\n\t#endif\n\t#ifdef ENVMAP_TYPE_CUBE\n\t\tuniform samplerCube envMap;\n\t#else\n\t\tuniform sampler2D envMap;\n\t#endif\n\tuniform float flipEnvMap;\n\tuniform int maxMipLevel;\n\t#if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG ) || defined( PHYSICAL )\n\t\tuniform float refractionRatio;\n\t#else\n\t\tvarying vec3 vReflect;\n\t#endif\n#endif";
  3647. var envmap_pars_vertex = "#ifdef USE_ENVMAP\n\t#if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG )\n\t\tvarying vec3 vWorldPosition;\n\t#else\n\t\tvarying vec3 vReflect;\n\t\tuniform float refractionRatio;\n\t#endif\n#endif";
  3648. var envmap_vertex = "#ifdef USE_ENVMAP\n\t#if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG )\n\t\tvWorldPosition = worldPosition.xyz;\n\t#else\n\t\tvec3 cameraToVertex = normalize( worldPosition.xyz - cameraPosition );\n\t\tvec3 worldNormal = inverseTransformDirection( transformedNormal, viewMatrix );\n\t\t#ifdef ENVMAP_MODE_REFLECTION\n\t\t\tvReflect = reflect( cameraToVertex, worldNormal );\n\t\t#else\n\t\t\tvReflect = refract( cameraToVertex, worldNormal, refractionRatio );\n\t\t#endif\n\t#endif\n#endif";
  3649. var fog_vertex = "#ifdef USE_FOG\n\tfogDepth = -mvPosition.z;\n#endif";
  3650. var fog_pars_vertex = "#ifdef USE_FOG\n\tvarying float fogDepth;\n#endif";
  3651. var fog_fragment = "#ifdef USE_FOG\n\t#ifdef FOG_EXP2\n\t\tfloat fogFactor = whiteCompliment( exp2( - fogDensity * fogDensity * fogDepth * fogDepth * LOG2 ) );\n\t#else\n\t\tfloat fogFactor = smoothstep( fogNear, fogFar, fogDepth );\n\t#endif\n\tgl_FragColor.rgb = mix( gl_FragColor.rgb, fogColor, fogFactor );\n#endif";
  3652. var fog_pars_fragment = "#ifdef USE_FOG\n\tuniform vec3 fogColor;\n\tvarying float fogDepth;\n\t#ifdef FOG_EXP2\n\t\tuniform float fogDensity;\n\t#else\n\t\tuniform float fogNear;\n\t\tuniform float fogFar;\n\t#endif\n#endif";
  3653. var gradientmap_pars_fragment = "#ifdef TOON\n\tuniform sampler2D gradientMap;\n\tvec3 getGradientIrradiance( vec3 normal, vec3 lightDirection ) {\n\t\tfloat dotNL = dot( normal, lightDirection );\n\t\tvec2 coord = vec2( dotNL * 0.5 + 0.5, 0.0 );\n\t\t#ifdef USE_GRADIENTMAP\n\t\t\treturn texture2D( gradientMap, coord ).rgb;\n\t\t#else\n\t\t\treturn ( coord.x < 0.7 ) ? vec3( 0.7 ) : vec3( 1.0 );\n\t\t#endif\n\t}\n#endif";
  3654. var lightmap_fragment = "#ifdef USE_LIGHTMAP\n\treflectedLight.indirectDiffuse += PI * texture2D( lightMap, vUv2 ).xyz * lightMapIntensity;\n#endif";
  3655. var lightmap_pars_fragment = "#ifdef USE_LIGHTMAP\n\tuniform sampler2D lightMap;\n\tuniform float lightMapIntensity;\n#endif";
  3656. var 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 );\nvIndirectFront = vec3( 0.0 );\n#ifdef DOUBLE_SIDED\n\tvLightBack = vec3( 0.0 );\n\tvIndirectBack = vec3( 0.0 );\n#endif\nIncidentLight directLight;\nfloat dotNL;\nvec3 directLightColor_Diffuse;\n#if NUM_POINT_LIGHTS > 0\n\t#pragma unroll_loop\n\tfor ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) {\n\t\tgetPointDirectLightIrradiance( pointLights[ i ], geometry, directLight );\n\t\tdotNL = dot( geometry.normal, directLight.direction );\n\t\tdirectLightColor_Diffuse = PI * directLight.color;\n\t\tvLightFront += saturate( dotNL ) * directLightColor_Diffuse;\n\t\t#ifdef DOUBLE_SIDED\n\t\t\tvLightBack += saturate( -dotNL ) * directLightColor_Diffuse;\n\t\t#endif\n\t}\n#endif\n#if NUM_SPOT_LIGHTS > 0\n\t#pragma unroll_loop\n\tfor ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) {\n\t\tgetSpotDirectLightIrradiance( spotLights[ i ], geometry, directLight );\n\t\tdotNL = dot( geometry.normal, directLight.direction );\n\t\tdirectLightColor_Diffuse = PI * directLight.color;\n\t\tvLightFront += saturate( dotNL ) * directLightColor_Diffuse;\n\t\t#ifdef DOUBLE_SIDED\n\t\t\tvLightBack += saturate( -dotNL ) * directLightColor_Diffuse;\n\t\t#endif\n\t}\n#endif\n#if NUM_DIR_LIGHTS > 0\n\t#pragma unroll_loop\n\tfor ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {\n\t\tgetDirectionalDirectLightIrradiance( directionalLights[ i ], geometry, directLight );\n\t\tdotNL = dot( geometry.normal, directLight.direction );\n\t\tdirectLightColor_Diffuse = PI * directLight.color;\n\t\tvLightFront += saturate( dotNL ) * directLightColor_Diffuse;\n\t\t#ifdef DOUBLE_SIDED\n\t\t\tvLightBack += saturate( -dotNL ) * directLightColor_Diffuse;\n\t\t#endif\n\t}\n#endif\n#if NUM_HEMI_LIGHTS > 0\n\t#pragma unroll_loop\n\tfor ( int i = 0; i < NUM_HEMI_LIGHTS; i ++ ) {\n\t\tvIndirectFront += getHemisphereLightIrradiance( hemisphereLights[ i ], geometry );\n\t\t#ifdef DOUBLE_SIDED\n\t\t\tvIndirectBack += getHemisphereLightIrradiance( hemisphereLights[ i ], backGeometry );\n\t\t#endif\n\t}\n#endif";
  3657. var lights_pars_begin = "uniform vec3 ambientLightColor;\nvec3 getAmbientLightIrradiance( const in vec3 ambientLightColor ) {\n\tvec3 irradiance = ambientLightColor;\n\t#ifndef PHYSICALLY_CORRECT_LIGHTS\n\t\tirradiance *= PI;\n\t#endif\n\treturn irradiance;\n}\n#if NUM_DIR_LIGHTS > 0\n\tstruct DirectionalLight {\n\t\tvec3 direction;\n\t\tvec3 color;\n\t\tint shadow;\n\t\tfloat shadowBias;\n\t\tfloat shadowRadius;\n\t\tvec2 shadowMapSize;\n\t};\n\tuniform DirectionalLight directionalLights[ NUM_DIR_LIGHTS ];\n\tvoid getDirectionalDirectLightIrradiance( const in DirectionalLight directionalLight, const in GeometricContext geometry, out IncidentLight directLight ) {\n\t\tdirectLight.color = directionalLight.color;\n\t\tdirectLight.direction = directionalLight.direction;\n\t\tdirectLight.visible = true;\n\t}\n#endif\n#if NUM_POINT_LIGHTS > 0\n\tstruct PointLight {\n\t\tvec3 position;\n\t\tvec3 color;\n\t\tfloat distance;\n\t\tfloat decay;\n\t\tint shadow;\n\t\tfloat shadowBias;\n\t\tfloat shadowRadius;\n\t\tvec2 shadowMapSize;\n\t\tfloat shadowCameraNear;\n\t\tfloat shadowCameraFar;\n\t};\n\tuniform PointLight pointLights[ NUM_POINT_LIGHTS ];\n\tvoid getPointDirectLightIrradiance( const in PointLight pointLight, const in GeometricContext geometry, out IncidentLight directLight ) {\n\t\tvec3 lVector = pointLight.position - geometry.position;\n\t\tdirectLight.direction = normalize( lVector );\n\t\tfloat lightDistance = length( lVector );\n\t\tdirectLight.color = pointLight.color;\n\t\tdirectLight.color *= punctualLightIntensityToIrradianceFactor( lightDistance, pointLight.distance, pointLight.decay );\n\t\tdirectLight.visible = ( directLight.color != vec3( 0.0 ) );\n\t}\n#endif\n#if NUM_SPOT_LIGHTS > 0\n\tstruct SpotLight {\n\t\tvec3 position;\n\t\tvec3 direction;\n\t\tvec3 color;\n\t\tfloat distance;\n\t\tfloat decay;\n\t\tfloat coneCos;\n\t\tfloat penumbraCos;\n\t\tint shadow;\n\t\tfloat shadowBias;\n\t\tfloat shadowRadius;\n\t\tvec2 shadowMapSize;\n\t};\n\tuniform SpotLight spotLights[ NUM_SPOT_LIGHTS ];\n\tvoid getSpotDirectLightIrradiance( const in SpotLight spotLight, const in GeometricContext geometry, out IncidentLight directLight ) {\n\t\tvec3 lVector = spotLight.position - geometry.position;\n\t\tdirectLight.direction = normalize( lVector );\n\t\tfloat lightDistance = length( lVector );\n\t\tfloat angleCos = dot( directLight.direction, spotLight.direction );\n\t\tif ( angleCos > spotLight.coneCos ) {\n\t\t\tfloat spotEffect = smoothstep( spotLight.coneCos, spotLight.penumbraCos, angleCos );\n\t\t\tdirectLight.color = spotLight.color;\n\t\t\tdirectLight.color *= spotEffect * punctualLightIntensityToIrradianceFactor( lightDistance, spotLight.distance, spotLight.decay );\n\t\t\tdirectLight.visible = true;\n\t\t} else {\n\t\t\tdirectLight.color = vec3( 0.0 );\n\t\t\tdirectLight.visible = false;\n\t\t}\n\t}\n#endif\n#if NUM_RECT_AREA_LIGHTS > 0\n\tstruct RectAreaLight {\n\t\tvec3 color;\n\t\tvec3 position;\n\t\tvec3 halfWidth;\n\t\tvec3 halfHeight;\n\t};\n\tuniform sampler2D ltc_1;\tuniform sampler2D ltc_2;\n\tuniform RectAreaLight rectAreaLights[ NUM_RECT_AREA_LIGHTS ];\n#endif\n#if NUM_HEMI_LIGHTS > 0\n\tstruct HemisphereLight {\n\t\tvec3 direction;\n\t\tvec3 skyColor;\n\t\tvec3 groundColor;\n\t};\n\tuniform HemisphereLight hemisphereLights[ NUM_HEMI_LIGHTS ];\n\tvec3 getHemisphereLightIrradiance( const in HemisphereLight hemiLight, const in GeometricContext geometry ) {\n\t\tfloat dotNL = dot( geometry.normal, hemiLight.direction );\n\t\tfloat hemiDiffuseWeight = 0.5 * dotNL + 0.5;\n\t\tvec3 irradiance = mix( hemiLight.groundColor, hemiLight.skyColor, hemiDiffuseWeight );\n\t\t#ifndef PHYSICALLY_CORRECT_LIGHTS\n\t\t\tirradiance *= PI;\n\t\t#endif\n\t\treturn irradiance;\n\t}\n#endif";
  3658. var envmap_physical_pars_fragment = "#if defined( USE_ENVMAP ) && defined( PHYSICAL )\n\tvec3 getLightProbeIndirectIrradiance( const in GeometricContext geometry, const in int maxMIPLevel ) {\n\t\tvec3 worldNormal = inverseTransformDirection( geometry.normal, viewMatrix );\n\t\t#ifdef ENVMAP_TYPE_CUBE\n\t\t\tvec3 queryVec = vec3( flipEnvMap * worldNormal.x, worldNormal.yz );\n\t\t\t#ifdef TEXTURE_LOD_EXT\n\t\t\t\tvec4 envMapColor = textureCubeLodEXT( envMap, queryVec, float( maxMIPLevel ) );\n\t\t\t#else\n\t\t\t\tvec4 envMapColor = textureCube( envMap, queryVec, float( maxMIPLevel ) );\n\t\t\t#endif\n\t\t\tenvMapColor.rgb = envMapTexelToLinear( envMapColor ).rgb;\n\t\t#elif defined( ENVMAP_TYPE_CUBE_UV )\n\t\t\tvec3 queryVec = vec3( flipEnvMap * worldNormal.x, worldNormal.yz );\n\t\t\tvec4 envMapColor = textureCubeUV( envMap, queryVec, 1.0 );\n\t\t#else\n\t\t\tvec4 envMapColor = vec4( 0.0 );\n\t\t#endif\n\t\treturn PI * envMapColor.rgb * envMapIntensity;\n\t}\n\tfloat getSpecularMIPLevel( const in float blinnShininessExponent, const in int maxMIPLevel ) {\n\t\tfloat maxMIPLevelScalar = float( maxMIPLevel );\n\t\tfloat desiredMIPLevel = maxMIPLevelScalar + 0.79248 - 0.5 * log2( pow2( blinnShininessExponent ) + 1.0 );\n\t\treturn clamp( desiredMIPLevel, 0.0, maxMIPLevelScalar );\n\t}\n\tvec3 getLightProbeIndirectRadiance( const in GeometricContext geometry, const in float blinnShininessExponent, const in int maxMIPLevel ) {\n\t\t#ifdef ENVMAP_MODE_REFLECTION\n\t\t\tvec3 reflectVec = reflect( -geometry.viewDir, geometry.normal );\n\t\t#else\n\t\t\tvec3 reflectVec = refract( -geometry.viewDir, geometry.normal, refractionRatio );\n\t\t#endif\n\t\treflectVec = inverseTransformDirection( reflectVec, viewMatrix );\n\t\tfloat specularMIPLevel = getSpecularMIPLevel( blinnShininessExponent, maxMIPLevel );\n\t\t#ifdef ENVMAP_TYPE_CUBE\n\t\t\tvec3 queryReflectVec = vec3( flipEnvMap * reflectVec.x, reflectVec.yz );\n\t\t\t#ifdef TEXTURE_LOD_EXT\n\t\t\t\tvec4 envMapColor = textureCubeLodEXT( envMap, queryReflectVec, specularMIPLevel );\n\t\t\t#else\n\t\t\t\tvec4 envMapColor = textureCube( envMap, queryReflectVec, specularMIPLevel );\n\t\t\t#endif\n\t\t\tenvMapColor.rgb = envMapTexelToLinear( envMapColor ).rgb;\n\t\t#elif defined( ENVMAP_TYPE_CUBE_UV )\n\t\t\tvec3 queryReflectVec = vec3( flipEnvMap * reflectVec.x, reflectVec.yz );\n\t\t\tvec4 envMapColor = textureCubeUV( envMap, queryReflectVec, BlinnExponentToGGXRoughness(blinnShininessExponent ));\n\t\t#elif defined( ENVMAP_TYPE_EQUIREC )\n\t\t\tvec2 sampleUV;\n\t\t\tsampleUV.y = asin( clamp( reflectVec.y, - 1.0, 1.0 ) ) * RECIPROCAL_PI + 0.5;\n\t\t\tsampleUV.x = atan( reflectVec.z, reflectVec.x ) * RECIPROCAL_PI2 + 0.5;\n\t\t\t#ifdef TEXTURE_LOD_EXT\n\t\t\t\tvec4 envMapColor = texture2DLodEXT( envMap, sampleUV, specularMIPLevel );\n\t\t\t#else\n\t\t\t\tvec4 envMapColor = texture2D( envMap, sampleUV, specularMIPLevel );\n\t\t\t#endif\n\t\t\tenvMapColor.rgb = envMapTexelToLinear( envMapColor ).rgb;\n\t\t#elif defined( ENVMAP_TYPE_SPHERE )\n\t\t\tvec3 reflectView = normalize( ( viewMatrix * vec4( reflectVec, 0.0 ) ).xyz + vec3( 0.0,0.0,1.0 ) );\n\t\t\t#ifdef TEXTURE_LOD_EXT\n\t\t\t\tvec4 envMapColor = texture2DLodEXT( envMap, reflectView.xy * 0.5 + 0.5, specularMIPLevel );\n\t\t\t#else\n\t\t\t\tvec4 envMapColor = texture2D( envMap, reflectView.xy * 0.5 + 0.5, specularMIPLevel );\n\t\t\t#endif\n\t\t\tenvMapColor.rgb = envMapTexelToLinear( envMapColor ).rgb;\n\t\t#endif\n\t\treturn envMapColor.rgb * envMapIntensity;\n\t}\n#endif";
  3659. var lights_phong_fragment = "BlinnPhongMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;\nmaterial.specularColor = specular;\nmaterial.specularShininess = shininess;\nmaterial.specularStrength = specularStrength;";
  3660. var lights_phong_pars_fragment = "varying vec3 vViewPosition;\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n#endif\nstruct BlinnPhongMaterial {\n\tvec3\tdiffuseColor;\n\tvec3\tspecularColor;\n\tfloat\tspecularShininess;\n\tfloat\tspecularStrength;\n};\nvoid RE_Direct_BlinnPhong( const in IncidentLight directLight, const in GeometricContext geometry, const in BlinnPhongMaterial material, inout ReflectedLight reflectedLight ) {\n\t#ifdef TOON\n\t\tvec3 irradiance = getGradientIrradiance( geometry.normal, directLight.direction ) * directLight.color;\n\t#else\n\t\tfloat dotNL = saturate( dot( geometry.normal, directLight.direction ) );\n\t\tvec3 irradiance = dotNL * directLight.color;\n\t#endif\n\t#ifndef PHYSICALLY_CORRECT_LIGHTS\n\t\tirradiance *= PI;\n\t#endif\n\treflectedLight.directDiffuse += irradiance * BRDF_Diffuse_Lambert( material.diffuseColor );\n\treflectedLight.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\treflectedLight.indirectDiffuse += irradiance * BRDF_Diffuse_Lambert( material.diffuseColor );\n}\n#define RE_Direct\t\t\t\tRE_Direct_BlinnPhong\n#define RE_IndirectDiffuse\t\tRE_IndirectDiffuse_BlinnPhong\n#define Material_LightProbeLOD( material )\t(0)";
  3661. var lights_physical_fragment = "PhysicalMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb * ( 1.0 - metalnessFactor );\nmaterial.specularRoughness = clamp( roughnessFactor, 0.04, 1.0 );\n#ifdef STANDARD\n\tmaterial.specularColor = mix( vec3( DEFAULT_SPECULAR_COEFFICIENT ), diffuseColor.rgb, metalnessFactor );\n#else\n\tmaterial.specularColor = mix( vec3( MAXIMUM_SPECULAR_COEFFICIENT * pow2( reflectivity ) ), diffuseColor.rgb, metalnessFactor );\n\tmaterial.clearCoat = saturate( clearCoat );\tmaterial.clearCoatRoughness = clamp( clearCoatRoughness, 0.04, 1.0 );\n#endif";
  3662. var lights_physical_pars_fragment = "struct PhysicalMaterial {\n\tvec3\tdiffuseColor;\n\tfloat\tspecularRoughness;\n\tvec3\tspecularColor;\n\t#ifndef STANDARD\n\t\tfloat clearCoat;\n\t\tfloat clearCoatRoughness;\n\t#endif\n};\n#define MAXIMUM_SPECULAR_COEFFICIENT 0.16\n#define DEFAULT_SPECULAR_COEFFICIENT 0.04\nfloat clearCoatDHRApprox( const in float roughness, const in float dotNL ) {\n\treturn DEFAULT_SPECULAR_COEFFICIENT + ( 1.0 - DEFAULT_SPECULAR_COEFFICIENT ) * ( pow( 1.0 - dotNL, 5.0 ) * pow( 1.0 - roughness, 2.0 ) );\n}\n#if NUM_RECT_AREA_LIGHTS > 0\n\tvoid RE_Direct_RectArea_Physical( const in RectAreaLight rectAreaLight, const in GeometricContext geometry, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {\n\t\tvec3 normal = geometry.normal;\n\t\tvec3 viewDir = geometry.viewDir;\n\t\tvec3 position = geometry.position;\n\t\tvec3 lightPos = rectAreaLight.position;\n\t\tvec3 halfWidth = rectAreaLight.halfWidth;\n\t\tvec3 halfHeight = rectAreaLight.halfHeight;\n\t\tvec3 lightColor = rectAreaLight.color;\n\t\tfloat roughness = material.specularRoughness;\n\t\tvec3 rectCoords[ 4 ];\n\t\trectCoords[ 0 ] = lightPos + halfWidth - halfHeight;\t\trectCoords[ 1 ] = lightPos - halfWidth - halfHeight;\n\t\trectCoords[ 2 ] = lightPos - halfWidth + halfHeight;\n\t\trectCoords[ 3 ] = lightPos + halfWidth + halfHeight;\n\t\tvec2 uv = LTC_Uv( normal, viewDir, roughness );\n\t\tvec4 t1 = texture2D( ltc_1, uv );\n\t\tvec4 t2 = texture2D( ltc_2, uv );\n\t\tmat3 mInv = mat3(\n\t\t\tvec3( t1.x, 0, t1.y ),\n\t\t\tvec3( 0, 1, 0 ),\n\t\t\tvec3( t1.z, 0, t1.w )\n\t\t);\n\t\tvec3 fresnel = ( material.specularColor * t2.x + ( vec3( 1.0 ) - material.specularColor ) * t2.y );\n\t\treflectedLight.directSpecular += lightColor * fresnel * LTC_Evaluate( normal, viewDir, position, mInv, rectCoords );\n\t\treflectedLight.directDiffuse += lightColor * material.diffuseColor * LTC_Evaluate( normal, viewDir, position, mat3( 1.0 ), rectCoords );\n\t}\n#endif\nvoid RE_Direct_Physical( const in IncidentLight directLight, const in GeometricContext geometry, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {\n\tfloat dotNL = saturate( dot( geometry.normal, directLight.direction ) );\n\tvec3 irradiance = dotNL * directLight.color;\n\t#ifndef PHYSICALLY_CORRECT_LIGHTS\n\t\tirradiance *= PI;\n\t#endif\n\t#ifndef STANDARD\n\t\tfloat clearCoatDHR = material.clearCoat * clearCoatDHRApprox( material.clearCoatRoughness, dotNL );\n\t#else\n\t\tfloat clearCoatDHR = 0.0;\n\t#endif\n\treflectedLight.directSpecular += ( 1.0 - clearCoatDHR ) * irradiance * BRDF_Specular_GGX( directLight, geometry, material.specularColor, material.specularRoughness );\n\treflectedLight.directDiffuse += ( 1.0 - clearCoatDHR ) * irradiance * BRDF_Diffuse_Lambert( material.diffuseColor );\n\t#ifndef STANDARD\n\t\treflectedLight.directSpecular += irradiance * material.clearCoat * BRDF_Specular_GGX( directLight, geometry, vec3( DEFAULT_SPECULAR_COEFFICIENT ), material.clearCoatRoughness );\n\t#endif\n}\nvoid RE_IndirectDiffuse_Physical( const in vec3 irradiance, const in GeometricContext geometry, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {\n\t#ifndef ENVMAP_TYPE_CUBE_UV\n\t\treflectedLight.indirectDiffuse += irradiance * BRDF_Diffuse_Lambert( material.diffuseColor );\n\t#endif\n}\nvoid RE_IndirectSpecular_Physical( const in vec3 radiance, const in vec3 irradiance, const in vec3 clearCoatRadiance, const in GeometricContext geometry, const in PhysicalMaterial material, inout ReflectedLight reflectedLight) {\n\t#ifndef STANDARD\n\t\tfloat dotNV = saturate( dot( geometry.normal, geometry.viewDir ) );\n\t\tfloat dotNL = dotNV;\n\t\tfloat clearCoatDHR = material.clearCoat * clearCoatDHRApprox( material.clearCoatRoughness, dotNL );\n\t#else\n\t\tfloat clearCoatDHR = 0.0;\n\t#endif\n\tfloat clearCoatInv = 1.0 - clearCoatDHR;\n\t#if defined( ENVMAP_TYPE_CUBE_UV )\n\t\tvec3 singleScattering = vec3( 0.0 );\n\t\tvec3 multiScattering = vec3( 0.0 );\n\t\tvec3 cosineWeightedIrradiance = irradiance * RECIPROCAL_PI;\n\t\tBRDF_Specular_Multiscattering_Environment( geometry, material.specularColor, material.specularRoughness, singleScattering, multiScattering );\n\t\tvec3 diffuse = material.diffuseColor;\n\t\treflectedLight.indirectSpecular += clearCoatInv * radiance * singleScattering;\n\t\treflectedLight.indirectDiffuse += multiScattering * cosineWeightedIrradiance;\n\t\treflectedLight.indirectDiffuse += diffuse * cosineWeightedIrradiance;\n\t#else\n\t\treflectedLight.indirectSpecular += clearCoatInv * radiance * BRDF_Specular_GGX_Environment( geometry, material.specularColor, material.specularRoughness );\n\t#endif\n\t#ifndef STANDARD\n\t\treflectedLight.indirectSpecular += clearCoatRadiance * material.clearCoat * BRDF_Specular_GGX_Environment( geometry, vec3( DEFAULT_SPECULAR_COEFFICIENT ), material.clearCoatRoughness );\n\t#endif\n}\n#define RE_Direct\t\t\t\tRE_Direct_Physical\n#define RE_Direct_RectArea\t\tRE_Direct_RectArea_Physical\n#define RE_IndirectDiffuse\t\tRE_IndirectDiffuse_Physical\n#define RE_IndirectSpecular\t\tRE_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\treturn saturate( pow( dotNV + ambientOcclusion, exp2( - 16.0 * roughness - 1.0 ) ) - 1.0 + ambientOcclusion );\n}";
  3663. var lights_fragment_begin = "\nGeometricContext geometry;\ngeometry.position = - vViewPosition;\ngeometry.normal = normal;\ngeometry.viewDir = normalize( vViewPosition );\nIncidentLight directLight;\n#if ( NUM_POINT_LIGHTS > 0 ) && defined( RE_Direct )\n\tPointLight pointLight;\n\t#pragma unroll_loop\n\tfor ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) {\n\t\tpointLight = pointLights[ i ];\n\t\tgetPointDirectLightIrradiance( pointLight, geometry, directLight );\n\t\t#ifdef USE_SHADOWMAP\n\t\tdirectLight.color *= all( bvec2( pointLight.shadow, directLight.visible ) ) ? getPointShadow( pointShadowMap[ i ], pointLight.shadowMapSize, pointLight.shadowBias, pointLight.shadowRadius, vPointShadowCoord[ i ], pointLight.shadowCameraNear, pointLight.shadowCameraFar ) : 1.0;\n\t\t#endif\n\t\tRE_Direct( directLight, geometry, material, reflectedLight );\n\t}\n#endif\n#if ( NUM_SPOT_LIGHTS > 0 ) && defined( RE_Direct )\n\tSpotLight spotLight;\n\t#pragma unroll_loop\n\tfor ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) {\n\t\tspotLight = spotLights[ i ];\n\t\tgetSpotDirectLightIrradiance( spotLight, geometry, directLight );\n\t\t#ifdef USE_SHADOWMAP\n\t\tdirectLight.color *= all( bvec2( spotLight.shadow, directLight.visible ) ) ? getShadow( spotShadowMap[ i ], spotLight.shadowMapSize, spotLight.shadowBias, spotLight.shadowRadius, vSpotShadowCoord[ i ] ) : 1.0;\n\t\t#endif\n\t\tRE_Direct( directLight, geometry, material, reflectedLight );\n\t}\n#endif\n#if ( NUM_DIR_LIGHTS > 0 ) && defined( RE_Direct )\n\tDirectionalLight directionalLight;\n\t#pragma unroll_loop\n\tfor ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {\n\t\tdirectionalLight = directionalLights[ i ];\n\t\tgetDirectionalDirectLightIrradiance( directionalLight, geometry, directLight );\n\t\t#ifdef USE_SHADOWMAP\n\t\tdirectLight.color *= all( bvec2( directionalLight.shadow, directLight.visible ) ) ? getShadow( directionalShadowMap[ i ], directionalLight.shadowMapSize, directionalLight.shadowBias, directionalLight.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;\n\t\t#endif\n\t\tRE_Direct( directLight, geometry, material, reflectedLight );\n\t}\n#endif\n#if ( NUM_RECT_AREA_LIGHTS > 0 ) && defined( RE_Direct_RectArea )\n\tRectAreaLight rectAreaLight;\n\t#pragma unroll_loop\n\tfor ( int i = 0; i < NUM_RECT_AREA_LIGHTS; i ++ ) {\n\t\trectAreaLight = rectAreaLights[ i ];\n\t\tRE_Direct_RectArea( rectAreaLight, geometry, material, reflectedLight );\n\t}\n#endif\n#if defined( RE_IndirectDiffuse )\n\tvec3 irradiance = getAmbientLightIrradiance( ambientLightColor );\n\t#if ( NUM_HEMI_LIGHTS > 0 )\n\t\t#pragma unroll_loop\n\t\tfor ( int i = 0; i < NUM_HEMI_LIGHTS; i ++ ) {\n\t\t\tirradiance += getHemisphereLightIrradiance( hemisphereLights[ i ], geometry );\n\t\t}\n\t#endif\n#endif\n#if defined( RE_IndirectSpecular )\n\tvec3 radiance = vec3( 0.0 );\n\tvec3 clearCoatRadiance = vec3( 0.0 );\n#endif";
  3664. var lights_fragment_maps = "#if defined( RE_IndirectDiffuse )\n\t#ifdef USE_LIGHTMAP\n\t\tvec3 lightMapIrradiance = texture2D( lightMap, vUv2 ).xyz * lightMapIntensity;\n\t\t#ifndef PHYSICALLY_CORRECT_LIGHTS\n\t\t\tlightMapIrradiance *= PI;\n\t\t#endif\n\t\tirradiance += lightMapIrradiance;\n\t#endif\n\t#if defined( USE_ENVMAP ) && defined( PHYSICAL ) && defined( ENVMAP_TYPE_CUBE_UV )\n\t\tirradiance += getLightProbeIndirectIrradiance( geometry, maxMipLevel );\n\t#endif\n#endif\n#if defined( USE_ENVMAP ) && defined( RE_IndirectSpecular )\n\tradiance += getLightProbeIndirectRadiance( geometry, Material_BlinnShininessExponent( material ), maxMipLevel );\n\t#ifndef STANDARD\n\t\tclearCoatRadiance += getLightProbeIndirectRadiance( geometry, Material_ClearCoat_BlinnShininessExponent( material ), maxMipLevel );\n\t#endif\n#endif";
  3665. var lights_fragment_end = "#if defined( RE_IndirectDiffuse )\n\tRE_IndirectDiffuse( irradiance, geometry, material, reflectedLight );\n#endif\n#if defined( RE_IndirectSpecular )\n\tRE_IndirectSpecular( radiance, irradiance, clearCoatRadiance, geometry, material, reflectedLight );\n#endif";
  3666. var logdepthbuf_fragment = "#if defined( USE_LOGDEPTHBUF ) && defined( USE_LOGDEPTHBUF_EXT )\n\tgl_FragDepthEXT = log2( vFragDepth ) * logDepthBufFC * 0.5;\n#endif";
  3667. var logdepthbuf_pars_fragment = "#if defined( USE_LOGDEPTHBUF ) && defined( USE_LOGDEPTHBUF_EXT )\n\tuniform float logDepthBufFC;\n\tvarying float vFragDepth;\n#endif";
  3668. var logdepthbuf_pars_vertex = "#ifdef USE_LOGDEPTHBUF\n\t#ifdef USE_LOGDEPTHBUF_EXT\n\t\tvarying float vFragDepth;\n\t#else\n\t\tuniform float logDepthBufFC;\n\t#endif\n#endif";
  3669. var logdepthbuf_vertex = "#ifdef USE_LOGDEPTHBUF\n\t#ifdef USE_LOGDEPTHBUF_EXT\n\t\tvFragDepth = 1.0 + gl_Position.w;\n\t#else\n\t\tgl_Position.z = log2( max( EPSILON, gl_Position.w + 1.0 ) ) * logDepthBufFC - 1.0;\n\t\tgl_Position.z *= gl_Position.w;\n\t#endif\n#endif";
  3670. var map_fragment = "#ifdef USE_MAP\n\tvec4 texelColor = texture2D( map, vUv );\n\ttexelColor = mapTexelToLinear( texelColor );\n\tdiffuseColor *= texelColor;\n#endif";
  3671. var map_pars_fragment = "#ifdef USE_MAP\n\tuniform sampler2D map;\n#endif";
  3672. var map_particle_fragment = "#ifdef USE_MAP\n\tvec2 uv = ( uvTransform * vec3( gl_PointCoord.x, 1.0 - gl_PointCoord.y, 1 ) ).xy;\n\tvec4 mapTexel = texture2D( map, uv );\n\tdiffuseColor *= mapTexelToLinear( mapTexel );\n#endif";
  3673. var map_particle_pars_fragment = "#ifdef USE_MAP\n\tuniform mat3 uvTransform;\n\tuniform sampler2D map;\n#endif";
  3674. var metalnessmap_fragment = "float metalnessFactor = metalness;\n#ifdef USE_METALNESSMAP\n\tvec4 texelMetalness = texture2D( metalnessMap, vUv );\n\tmetalnessFactor *= texelMetalness.b;\n#endif";
  3675. var metalnessmap_pars_fragment = "#ifdef USE_METALNESSMAP\n\tuniform sampler2D metalnessMap;\n#endif";
  3676. var morphnormal_vertex = "#ifdef USE_MORPHNORMALS\n\tobjectNormal += ( morphNormal0 - normal ) * morphTargetInfluences[ 0 ];\n\tobjectNormal += ( morphNormal1 - normal ) * morphTargetInfluences[ 1 ];\n\tobjectNormal += ( morphNormal2 - normal ) * morphTargetInfluences[ 2 ];\n\tobjectNormal += ( morphNormal3 - normal ) * morphTargetInfluences[ 3 ];\n#endif";
  3677. var morphtarget_pars_vertex = "#ifdef USE_MORPHTARGETS\n\t#ifndef USE_MORPHNORMALS\n\tuniform float morphTargetInfluences[ 8 ];\n\t#else\n\tuniform float morphTargetInfluences[ 4 ];\n\t#endif\n#endif";
  3678. var morphtarget_vertex = "#ifdef USE_MORPHTARGETS\n\ttransformed += ( morphTarget0 - position ) * morphTargetInfluences[ 0 ];\n\ttransformed += ( morphTarget1 - position ) * morphTargetInfluences[ 1 ];\n\ttransformed += ( morphTarget2 - position ) * morphTargetInfluences[ 2 ];\n\ttransformed += ( morphTarget3 - position ) * morphTargetInfluences[ 3 ];\n\t#ifndef USE_MORPHNORMALS\n\ttransformed += ( morphTarget4 - position ) * morphTargetInfluences[ 4 ];\n\ttransformed += ( morphTarget5 - position ) * morphTargetInfluences[ 5 ];\n\ttransformed += ( morphTarget6 - position ) * morphTargetInfluences[ 6 ];\n\ttransformed += ( morphTarget7 - position ) * morphTargetInfluences[ 7 ];\n\t#endif\n#endif";
  3679. var normal_fragment_begin = "#ifdef FLAT_SHADED\n\tvec3 fdx = vec3( dFdx( vViewPosition.x ), dFdx( vViewPosition.y ), dFdx( vViewPosition.z ) );\n\tvec3 fdy = vec3( dFdy( vViewPosition.x ), dFdy( vViewPosition.y ), dFdy( vViewPosition.z ) );\n\tvec3 normal = normalize( cross( fdx, fdy ) );\n#else\n\tvec3 normal = normalize( vNormal );\n\t#ifdef DOUBLE_SIDED\n\t\tnormal = normal * ( float( gl_FrontFacing ) * 2.0 - 1.0 );\n\t#endif\n\t#ifdef USE_TANGENT\n\t\tvec3 tangent = normalize( vTangent );\n\t\tvec3 bitangent = normalize( vBitangent );\n\t\t#ifdef DOUBLE_SIDED\n\t\t\ttangent = tangent * ( float( gl_FrontFacing ) * 2.0 - 1.0 );\n\t\t\tbitangent = bitangent * ( float( gl_FrontFacing ) * 2.0 - 1.0 );\n\t\t#endif\n\t#endif\n#endif";
  3680. var normal_fragment_maps = "#ifdef USE_NORMALMAP\n\t#ifdef OBJECTSPACE_NORMALMAP\n\t\tnormal = texture2D( normalMap, vUv ).xyz * 2.0 - 1.0;\n\t\t#ifdef FLIP_SIDED\n\t\t\tnormal = - normal;\n\t\t#endif\n\t\t#ifdef DOUBLE_SIDED\n\t\t\tnormal = normal * ( float( gl_FrontFacing ) * 2.0 - 1.0 );\n\t\t#endif\n\t\tnormal = normalize( normalMatrix * normal );\n\t#else\n\t\t#ifdef USE_TANGENT\n\t\t\tmat3 vTBN = mat3( tangent, bitangent, normal );\n\t\t\tvec3 mapN = texture2D( normalMap, vUv ).xyz * 2.0 - 1.0;\n\t\t\tmapN.xy = normalScale * mapN.xy;\n\t\t\tnormal = normalize( vTBN * mapN );\n\t\t#else\n\t\t\tnormal = perturbNormal2Arb( -vViewPosition, normal );\n\t\t#endif\n\t#endif\n#elif defined( USE_BUMPMAP )\n\tnormal = perturbNormalArb( -vViewPosition, normal, dHdxy_fwd() );\n#endif";
  3681. var normalmap_pars_fragment = "#ifdef USE_NORMALMAP\n\tuniform sampler2D normalMap;\n\tuniform vec2 normalScale;\n\t#ifdef OBJECTSPACE_NORMALMAP\n\t\tuniform mat3 normalMatrix;\n\t#else\n\t\tvec3 perturbNormal2Arb( vec3 eye_pos, vec3 surf_norm ) {\n\t\t\tvec3 q0 = vec3( dFdx( eye_pos.x ), dFdx( eye_pos.y ), dFdx( eye_pos.z ) );\n\t\t\tvec3 q1 = vec3( dFdy( eye_pos.x ), dFdy( eye_pos.y ), dFdy( eye_pos.z ) );\n\t\t\tvec2 st0 = dFdx( vUv.st );\n\t\t\tvec2 st1 = dFdy( vUv.st );\n\t\t\tfloat scale = sign( st1.t * st0.s - st0.t * st1.s );\n\t\t\tvec3 S = normalize( ( q0 * st1.t - q1 * st0.t ) * scale );\n\t\t\tvec3 T = normalize( ( - q0 * st1.s + q1 * st0.s ) * scale );\n\t\t\tvec3 N = normalize( surf_norm );\n\t\t\tmat3 tsn = mat3( S, T, N );\n\t\t\tvec3 mapN = texture2D( normalMap, vUv ).xyz * 2.0 - 1.0;\n\t\t\tmapN.xy *= normalScale;\n\t\t\tmapN.xy *= ( float( gl_FrontFacing ) * 2.0 - 1.0 );\n\t\t\treturn normalize( tsn * mapN );\n\t\t}\n\t#endif\n#endif";
  3682. var packing = "vec3 packNormalToRGB( const in vec3 normal ) {\n\treturn normalize( normal ) * 0.5 + 0.5;\n}\nvec3 unpackRGBToNormal( const in vec3 rgb ) {\n\treturn 2.0 * rgb.xyz - 1.0;\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\tvec4 r = vec4( fract( v * PackFactors ), v );\n\tr.yzw -= r.xyz * ShiftRight8;\treturn r * PackUpscale;\n}\nfloat unpackRGBAToDepth( const in vec4 v ) {\n\treturn dot( v, UnpackFactors );\n}\nfloat viewZToOrthographicDepth( const in float viewZ, const in float near, const in float far ) {\n\treturn ( viewZ + near ) / ( near - far );\n}\nfloat orthographicDepthToViewZ( const in float linearClipZ, const in float near, const in float far ) {\n\treturn linearClipZ * ( near - far ) - near;\n}\nfloat viewZToPerspectiveDepth( const in float viewZ, const in float near, const in float far ) {\n\treturn (( near + viewZ ) * far ) / (( far - near ) * viewZ );\n}\nfloat perspectiveDepthToViewZ( const in float invClipZ, const in float near, const in float far ) {\n\treturn ( near * far ) / ( ( far - near ) * invClipZ - far );\n}";
  3683. var premultiplied_alpha_fragment = "#ifdef PREMULTIPLIED_ALPHA\n\tgl_FragColor.rgb *= gl_FragColor.a;\n#endif";
  3684. var project_vertex = "vec4 mvPosition = modelViewMatrix * vec4( transformed, 1.0 );\ngl_Position = projectionMatrix * mvPosition;";
  3685. var dithering_fragment = "#if defined( DITHERING )\n\tgl_FragColor.rgb = dithering( gl_FragColor.rgb );\n#endif";
  3686. var dithering_pars_fragment = "#if defined( DITHERING )\n\tvec3 dithering( vec3 color ) {\n\t\tfloat grid_position = rand( gl_FragCoord.xy );\n\t\tvec3 dither_shift_RGB = vec3( 0.25 / 255.0, -0.25 / 255.0, 0.25 / 255.0 );\n\t\tdither_shift_RGB = mix( 2.0 * dither_shift_RGB, -2.0 * dither_shift_RGB, grid_position );\n\t\treturn color + dither_shift_RGB;\n\t}\n#endif";
  3687. var roughnessmap_fragment = "float roughnessFactor = roughness;\n#ifdef USE_ROUGHNESSMAP\n\tvec4 texelRoughness = texture2D( roughnessMap, vUv );\n\troughnessFactor *= texelRoughness.g;\n#endif";
  3688. var roughnessmap_pars_fragment = "#ifdef USE_ROUGHNESSMAP\n\tuniform sampler2D roughnessMap;\n#endif";
  3689. var shadowmap_pars_fragment = "#ifdef USE_SHADOWMAP\n\t#if NUM_DIR_LIGHTS > 0\n\t\tuniform sampler2D directionalShadowMap[ NUM_DIR_LIGHTS ];\n\t\tvarying vec4 vDirectionalShadowCoord[ NUM_DIR_LIGHTS ];\n\t#endif\n\t#if NUM_SPOT_LIGHTS > 0\n\t\tuniform sampler2D spotShadowMap[ NUM_SPOT_LIGHTS ];\n\t\tvarying vec4 vSpotShadowCoord[ NUM_SPOT_LIGHTS ];\n\t#endif\n\t#if NUM_POINT_LIGHTS > 0\n\t\tuniform sampler2D pointShadowMap[ NUM_POINT_LIGHTS ];\n\t\tvarying vec4 vPointShadowCoord[ NUM_POINT_LIGHTS ];\n\t#endif\n\tfloat texture2DCompare( sampler2D depths, vec2 uv, float compare ) {\n\t\treturn step( compare, unpackRGBAToDepth( texture2D( depths, uv ) ) );\n\t}\n\tfloat texture2DShadowLerp( sampler2D depths, vec2 size, vec2 uv, float compare ) {\n\t\tconst vec2 offset = vec2( 0.0, 1.0 );\n\t\tvec2 texelSize = vec2( 1.0 ) / size;\n\t\tvec2 centroidUV = floor( uv * size + 0.5 ) / size;\n\t\tfloat lb = texture2DCompare( depths, centroidUV + texelSize * offset.xx, compare );\n\t\tfloat lt = texture2DCompare( depths, centroidUV + texelSize * offset.xy, compare );\n\t\tfloat rb = texture2DCompare( depths, centroidUV + texelSize * offset.yx, compare );\n\t\tfloat rt = texture2DCompare( depths, centroidUV + texelSize * offset.yy, compare );\n\t\tvec2 f = fract( uv * size + 0.5 );\n\t\tfloat a = mix( lb, lt, f.y );\n\t\tfloat b = mix( rb, rt, f.y );\n\t\tfloat c = mix( a, b, f.x );\n\t\treturn c;\n\t}\n\tfloat getShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowBias, float shadowRadius, vec4 shadowCoord ) {\n\t\tfloat shadow = 1.0;\n\t\tshadowCoord.xyz /= shadowCoord.w;\n\t\tshadowCoord.z += shadowBias;\n\t\tbvec4 inFrustumVec = bvec4 ( shadowCoord.x >= 0.0, shadowCoord.x <= 1.0, shadowCoord.y >= 0.0, shadowCoord.y <= 1.0 );\n\t\tbool inFrustum = all( inFrustumVec );\n\t\tbvec2 frustumTestVec = bvec2( inFrustum, shadowCoord.z <= 1.0 );\n\t\tbool frustumTest = all( frustumTestVec );\n\t\tif ( frustumTest ) {\n\t\t#if defined( SHADOWMAP_TYPE_PCF )\n\t\t\tvec2 texelSize = vec2( 1.0 ) / shadowMapSize;\n\t\t\tfloat dx0 = - texelSize.x * shadowRadius;\n\t\t\tfloat dy0 = - texelSize.y * shadowRadius;\n\t\t\tfloat dx1 = + texelSize.x * shadowRadius;\n\t\t\tfloat dy1 = + texelSize.y * shadowRadius;\n\t\t\tshadow = (\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, dy0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, dy0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, 0.0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy, shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, 0.0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, dy1 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy1 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, dy1 ), shadowCoord.z )\n\t\t\t) * ( 1.0 / 9.0 );\n\t\t#elif defined( SHADOWMAP_TYPE_PCF_SOFT )\n\t\t\tvec2 texelSize = vec2( 1.0 ) / shadowMapSize;\n\t\t\tfloat dx0 = - texelSize.x * shadowRadius;\n\t\t\tfloat dy0 = - texelSize.y * shadowRadius;\n\t\t\tfloat dx1 = + texelSize.x * shadowRadius;\n\t\t\tfloat dy1 = + texelSize.y * shadowRadius;\n\t\t\tshadow = (\n\t\t\t\ttexture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( dx0, dy0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( 0.0, dy0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( dx1, dy0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( dx0, 0.0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy, shadowCoord.z ) +\n\t\t\t\ttexture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( dx1, 0.0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( dx0, dy1 ), shadowCoord.z ) +\n\t\t\t\ttexture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( 0.0, dy1 ), shadowCoord.z ) +\n\t\t\t\ttexture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( dx1, dy1 ), shadowCoord.z )\n\t\t\t) * ( 1.0 / 9.0 );\n\t\t#else\n\t\t\tshadow = texture2DCompare( shadowMap, shadowCoord.xy, shadowCoord.z );\n\t\t#endif\n\t\t}\n\t\treturn shadow;\n\t}\n\tvec2 cubeToUV( vec3 v, float texelSizeY ) {\n\t\tvec3 absV = abs( v );\n\t\tfloat scaleToCube = 1.0 / max( absV.x, max( absV.y, absV.z ) );\n\t\tabsV *= scaleToCube;\n\t\tv *= scaleToCube * ( 1.0 - 2.0 * texelSizeY );\n\t\tvec2 planar = v.xy;\n\t\tfloat almostATexel = 1.5 * texelSizeY;\n\t\tfloat almostOne = 1.0 - almostATexel;\n\t\tif ( absV.z >= almostOne ) {\n\t\t\tif ( v.z > 0.0 )\n\t\t\t\tplanar.x = 4.0 - v.x;\n\t\t} else if ( absV.x >= almostOne ) {\n\t\t\tfloat signX = sign( v.x );\n\t\t\tplanar.x = v.z * signX + 2.0 * signX;\n\t\t} else if ( absV.y >= almostOne ) {\n\t\t\tfloat signY = sign( v.y );\n\t\t\tplanar.x = v.x + 2.0 * signY + 2.0;\n\t\t\tplanar.y = v.z * signY - 2.0;\n\t\t}\n\t\treturn vec2( 0.125, 0.25 ) * planar + vec2( 0.375, 0.75 );\n\t}\n\tfloat getPointShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowBias, float shadowRadius, vec4 shadowCoord, float shadowCameraNear, float shadowCameraFar ) {\n\t\tvec2 texelSize = vec2( 1.0 ) / ( shadowMapSize * vec2( 4.0, 2.0 ) );\n\t\tvec3 lightToPosition = shadowCoord.xyz;\n\t\tfloat dp = ( length( lightToPosition ) - shadowCameraNear ) / ( shadowCameraFar - shadowCameraNear );\t\tdp += shadowBias;\n\t\tvec3 bd3D = normalize( lightToPosition );\n\t\t#if defined( SHADOWMAP_TYPE_PCF ) || defined( SHADOWMAP_TYPE_PCF_SOFT )\n\t\t\tvec2 offset = vec2( - 1, 1 ) * shadowRadius * texelSize.y;\n\t\t\treturn (\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.xyy, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.yyy, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.xyx, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.yyx, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.xxy, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.yxy, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.xxx, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.yxx, texelSize.y ), dp )\n\t\t\t) * ( 1.0 / 9.0 );\n\t\t#else\n\t\t\treturn texture2DCompare( shadowMap, cubeToUV( bd3D, texelSize.y ), dp );\n\t\t#endif\n\t}\n#endif";
  3690. var shadowmap_pars_vertex = "#ifdef USE_SHADOWMAP\n\t#if NUM_DIR_LIGHTS > 0\n\t\tuniform mat4 directionalShadowMatrix[ NUM_DIR_LIGHTS ];\n\t\tvarying vec4 vDirectionalShadowCoord[ NUM_DIR_LIGHTS ];\n\t#endif\n\t#if NUM_SPOT_LIGHTS > 0\n\t\tuniform mat4 spotShadowMatrix[ NUM_SPOT_LIGHTS ];\n\t\tvarying vec4 vSpotShadowCoord[ NUM_SPOT_LIGHTS ];\n\t#endif\n\t#if NUM_POINT_LIGHTS > 0\n\t\tuniform mat4 pointShadowMatrix[ NUM_POINT_LIGHTS ];\n\t\tvarying vec4 vPointShadowCoord[ NUM_POINT_LIGHTS ];\n\t#endif\n#endif";
  3691. var shadowmap_vertex = "#ifdef USE_SHADOWMAP\n\t#if NUM_DIR_LIGHTS > 0\n\t#pragma unroll_loop\n\tfor ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {\n\t\tvDirectionalShadowCoord[ i ] = directionalShadowMatrix[ i ] * worldPosition;\n\t}\n\t#endif\n\t#if NUM_SPOT_LIGHTS > 0\n\t#pragma unroll_loop\n\tfor ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) {\n\t\tvSpotShadowCoord[ i ] = spotShadowMatrix[ i ] * worldPosition;\n\t}\n\t#endif\n\t#if NUM_POINT_LIGHTS > 0\n\t#pragma unroll_loop\n\tfor ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) {\n\t\tvPointShadowCoord[ i ] = pointShadowMatrix[ i ] * worldPosition;\n\t}\n\t#endif\n#endif";
  3692. var shadowmask_pars_fragment = "float getShadowMask() {\n\tfloat shadow = 1.0;\n\t#ifdef USE_SHADOWMAP\n\t#if NUM_DIR_LIGHTS > 0\n\tDirectionalLight directionalLight;\n\t#pragma unroll_loop\n\tfor ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {\n\t\tdirectionalLight = directionalLights[ i ];\n\t\tshadow *= bool( directionalLight.shadow ) ? getShadow( directionalShadowMap[ i ], directionalLight.shadowMapSize, directionalLight.shadowBias, directionalLight.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;\n\t}\n\t#endif\n\t#if NUM_SPOT_LIGHTS > 0\n\tSpotLight spotLight;\n\t#pragma unroll_loop\n\tfor ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) {\n\t\tspotLight = spotLights[ i ];\n\t\tshadow *= bool( spotLight.shadow ) ? getShadow( spotShadowMap[ i ], spotLight.shadowMapSize, spotLight.shadowBias, spotLight.shadowRadius, vSpotShadowCoord[ i ] ) : 1.0;\n\t}\n\t#endif\n\t#if NUM_POINT_LIGHTS > 0\n\tPointLight pointLight;\n\t#pragma unroll_loop\n\tfor ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) {\n\t\tpointLight = pointLights[ i ];\n\t\tshadow *= bool( pointLight.shadow ) ? getPointShadow( pointShadowMap[ i ], pointLight.shadowMapSize, pointLight.shadowBias, pointLight.shadowRadius, vPointShadowCoord[ i ], pointLight.shadowCameraNear, pointLight.shadowCameraFar ) : 1.0;\n\t}\n\t#endif\n\t#endif\n\treturn shadow;\n}";
  3693. var skinbase_vertex = "#ifdef USE_SKINNING\n\tmat4 boneMatX = getBoneMatrix( skinIndex.x );\n\tmat4 boneMatY = getBoneMatrix( skinIndex.y );\n\tmat4 boneMatZ = getBoneMatrix( skinIndex.z );\n\tmat4 boneMatW = getBoneMatrix( skinIndex.w );\n#endif";
  3694. var skinning_pars_vertex = "#ifdef USE_SKINNING\n\tuniform mat4 bindMatrix;\n\tuniform mat4 bindMatrixInverse;\n\t#ifdef BONE_TEXTURE\n\t\tuniform sampler2D boneTexture;\n\t\tuniform int boneTextureSize;\n\t\tmat4 getBoneMatrix( const in float i ) {\n\t\t\tfloat j = i * 4.0;\n\t\t\tfloat x = mod( j, float( boneTextureSize ) );\n\t\t\tfloat y = floor( j / float( boneTextureSize ) );\n\t\t\tfloat dx = 1.0 / float( boneTextureSize );\n\t\t\tfloat dy = 1.0 / float( boneTextureSize );\n\t\t\ty = dy * ( y + 0.5 );\n\t\t\tvec4 v1 = texture2D( boneTexture, vec2( dx * ( x + 0.5 ), y ) );\n\t\t\tvec4 v2 = texture2D( boneTexture, vec2( dx * ( x + 1.5 ), y ) );\n\t\t\tvec4 v3 = texture2D( boneTexture, vec2( dx * ( x + 2.5 ), y ) );\n\t\t\tvec4 v4 = texture2D( boneTexture, vec2( dx * ( x + 3.5 ), y ) );\n\t\t\tmat4 bone = mat4( v1, v2, v3, v4 );\n\t\t\treturn bone;\n\t\t}\n\t#else\n\t\tuniform mat4 boneMatrices[ MAX_BONES ];\n\t\tmat4 getBoneMatrix( const in float i ) {\n\t\t\tmat4 bone = boneMatrices[ int(i) ];\n\t\t\treturn bone;\n\t\t}\n\t#endif\n#endif";
  3695. var skinning_vertex = "#ifdef USE_SKINNING\n\tvec4 skinVertex = bindMatrix * vec4( transformed, 1.0 );\n\tvec4 skinned = vec4( 0.0 );\n\tskinned += boneMatX * skinVertex * skinWeight.x;\n\tskinned += boneMatY * skinVertex * skinWeight.y;\n\tskinned += boneMatZ * skinVertex * skinWeight.z;\n\tskinned += boneMatW * skinVertex * skinWeight.w;\n\ttransformed = ( bindMatrixInverse * skinned ).xyz;\n#endif";
  3696. var skinnormal_vertex = "#ifdef USE_SKINNING\n\tmat4 skinMatrix = mat4( 0.0 );\n\tskinMatrix += skinWeight.x * boneMatX;\n\tskinMatrix += skinWeight.y * boneMatY;\n\tskinMatrix += skinWeight.z * boneMatZ;\n\tskinMatrix += skinWeight.w * boneMatW;\n\tskinMatrix = bindMatrixInverse * skinMatrix * bindMatrix;\n\tobjectNormal = vec4( skinMatrix * vec4( objectNormal, 0.0 ) ).xyz;\n\t#ifdef USE_TANGENT\n\t\tobjectTangent = vec4( skinMatrix * vec4( objectTangent, 0.0 ) ).xyz;\n\t#endif\n#endif";
  3697. var specularmap_fragment = "float specularStrength;\n#ifdef USE_SPECULARMAP\n\tvec4 texelSpecular = texture2D( specularMap, vUv );\n\tspecularStrength = texelSpecular.r;\n#else\n\tspecularStrength = 1.0;\n#endif";
  3698. var specularmap_pars_fragment = "#ifdef USE_SPECULARMAP\n\tuniform sampler2D specularMap;\n#endif";
  3699. var tonemapping_fragment = "#if defined( TONE_MAPPING )\n\tgl_FragColor.rgb = toneMapping( gl_FragColor.rgb );\n#endif";
  3700. var tonemapping_pars_fragment = "#ifndef saturate\n\t#define saturate(a) clamp( a, 0.0, 1.0 )\n#endif\nuniform float toneMappingExposure;\nuniform float toneMappingWhitePoint;\nvec3 LinearToneMapping( vec3 color ) {\n\treturn toneMappingExposure * color;\n}\nvec3 ReinhardToneMapping( vec3 color ) {\n\tcolor *= toneMappingExposure;\n\treturn 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\tcolor *= toneMappingExposure;\n\treturn saturate( Uncharted2Helper( color ) / Uncharted2Helper( vec3( toneMappingWhitePoint ) ) );\n}\nvec3 OptimizedCineonToneMapping( vec3 color ) {\n\tcolor *= toneMappingExposure;\n\tcolor = max( vec3( 0.0 ), color - 0.004 );\n\treturn pow( ( color * ( 6.2 * color + 0.5 ) ) / ( color * ( 6.2 * color + 1.7 ) + 0.06 ), vec3( 2.2 ) );\n}\nvec3 ACESFilmicToneMapping( vec3 color ) {\n\tcolor *= toneMappingExposure;\n\treturn saturate( ( color * ( 2.51 * color + 0.03 ) ) / ( color * ( 2.43 * color + 0.59 ) + 0.14 ) );\n}";
  3701. var 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\tvarying vec2 vUv;\n#endif";
  3702. var 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\tvarying vec2 vUv;\n\tuniform mat3 uvTransform;\n#endif";
  3703. var 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\tvUv = ( uvTransform * vec3( uv, 1 ) ).xy;\n#endif";
  3704. var uv2_pars_fragment = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tvarying vec2 vUv2;\n#endif";
  3705. var uv2_pars_vertex = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tattribute vec2 uv2;\n\tvarying vec2 vUv2;\n#endif";
  3706. var uv2_vertex = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tvUv2 = uv2;\n#endif";
  3707. var worldpos_vertex = "#if defined( USE_ENVMAP ) || defined( DISTANCE ) || defined ( USE_SHADOWMAP )\n\tvec4 worldPosition = modelMatrix * vec4( transformed, 1.0 );\n#endif";
  3708. var background_frag = "uniform sampler2D t2D;\nvarying vec2 vUv;\nvoid main() {\n\tvec4 texColor = texture2D( t2D, vUv );\n\tgl_FragColor = mapTexelToLinear( texColor );\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n}";
  3709. var background_vert = "varying vec2 vUv;\nuniform mat3 uvTransform;\nvoid main() {\n\tvUv = ( uvTransform * vec3( uv, 1 ) ).xy;\n\tgl_Position = vec4( position.xy, 1.0, 1.0 );\n}";
  3710. var cube_frag = "uniform samplerCube tCube;\nuniform float tFlip;\nuniform float opacity;\nvarying vec3 vWorldDirection;\nvoid main() {\n\tvec4 texColor = textureCube( tCube, vec3( tFlip * vWorldDirection.x, vWorldDirection.yz ) );\n\tgl_FragColor = mapTexelToLinear( texColor );\n\tgl_FragColor.a *= opacity;\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n}";
  3711. var cube_vert = "varying vec3 vWorldDirection;\n#include <common>\nvoid main() {\n\tvWorldDirection = transformDirection( position, modelMatrix );\n\t#include <begin_vertex>\n\t#include <project_vertex>\n\tgl_Position.z = gl_Position.w;\n}";
  3712. var depth_frag = "#if DEPTH_PACKING == 3200\n\tuniform 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\t#include <clipping_planes_fragment>\n\tvec4 diffuseColor = vec4( 1.0 );\n\t#if DEPTH_PACKING == 3200\n\t\tdiffuseColor.a = opacity;\n\t#endif\n\t#include <map_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <logdepthbuf_fragment>\n\t#if DEPTH_PACKING == 3200\n\t\tgl_FragColor = vec4( vec3( 1.0 - gl_FragCoord.z ), opacity );\n\t#elif DEPTH_PACKING == 3201\n\t\tgl_FragColor = packDepthToRGBA( gl_FragCoord.z );\n\t#endif\n}";
  3713. var 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\t#include <uv_vertex>\n\t#include <skinbase_vertex>\n\t#ifdef USE_DISPLACEMENTMAP\n\t\t#include <beginnormal_vertex>\n\t\t#include <morphnormal_vertex>\n\t\t#include <skinnormal_vertex>\n\t#endif\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n}";
  3714. var distanceRGBA_frag = "#define DISTANCE\nuniform vec3 referencePosition;\nuniform float nearDistance;\nuniform float farDistance;\nvarying vec3 vWorldPosition;\n#include <common>\n#include <packing>\n#include <uv_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main () {\n\t#include <clipping_planes_fragment>\n\tvec4 diffuseColor = vec4( 1.0 );\n\t#include <map_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\tfloat dist = length( vWorldPosition - referencePosition );\n\tdist = ( dist - nearDistance ) / ( farDistance - nearDistance );\n\tdist = saturate( dist );\n\tgl_FragColor = packDepthToRGBA( dist );\n}";
  3715. var distanceRGBA_vert = "#define DISTANCE\nvarying vec3 vWorldPosition;\n#include <common>\n#include <uv_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <skinbase_vertex>\n\t#ifdef USE_DISPLACEMENTMAP\n\t\t#include <beginnormal_vertex>\n\t\t#include <morphnormal_vertex>\n\t\t#include <skinnormal_vertex>\n\t#endif\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <worldpos_vertex>\n\t#include <clipping_planes_vertex>\n\tvWorldPosition = worldPosition.xyz;\n}";
  3716. var equirect_frag = "uniform sampler2D tEquirect;\nvarying vec3 vWorldDirection;\n#include <common>\nvoid main() {\n\tvec3 direction = normalize( vWorldDirection );\n\tvec2 sampleUV;\n\tsampleUV.y = asin( clamp( direction.y, - 1.0, 1.0 ) ) * RECIPROCAL_PI + 0.5;\n\tsampleUV.x = atan( direction.z, direction.x ) * RECIPROCAL_PI2 + 0.5;\n\tvec4 texColor = texture2D( tEquirect, sampleUV );\n\tgl_FragColor = mapTexelToLinear( texColor );\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n}";
  3717. var equirect_vert = "varying vec3 vWorldDirection;\n#include <common>\nvoid main() {\n\tvWorldDirection = transformDirection( position, modelMatrix );\n\t#include <begin_vertex>\n\t#include <project_vertex>\n}";
  3718. var 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\t#include <clipping_planes_fragment>\n\tif ( mod( vLineDistance, totalSize ) > dashSize ) {\n\t\tdiscard;\n\t}\n\tvec3 outgoingLight = vec3( 0.0 );\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include <logdepthbuf_fragment>\n\t#include <color_fragment>\n\toutgoingLight = diffuseColor.rgb;\n\tgl_FragColor = vec4( outgoingLight, diffuseColor.a );\n\t#include <premultiplied_alpha_fragment>\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n}";
  3719. var linedashed_vert = "uniform float scale;\nattribute float lineDistance;\nvarying float vLineDistance;\n#include <common>\n#include <color_pars_vertex>\n#include <fog_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <color_vertex>\n\tvLineDistance = scale * lineDistance;\n\tvec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );\n\tgl_Position = projectionMatrix * mvPosition;\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\t#include <fog_vertex>\n}";
  3720. var meshbasic_frag = "uniform vec3 diffuse;\nuniform float opacity;\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n#endif\n#include <common>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <uv2_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <aomap_pars_fragment>\n#include <lightmap_pars_fragment>\n#include <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\t#include <clipping_planes_fragment>\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <color_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <specularmap_fragment>\n\tReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n\t#ifdef USE_LIGHTMAP\n\t\treflectedLight.indirectDiffuse += texture2D( lightMap, vUv2 ).xyz * lightMapIntensity;\n\t#else\n\t\treflectedLight.indirectDiffuse += vec3( 1.0 );\n\t#endif\n\t#include <aomap_fragment>\n\treflectedLight.indirectDiffuse *= diffuseColor.rgb;\n\tvec3 outgoingLight = reflectedLight.indirectDiffuse;\n\t#include <envmap_fragment>\n\tgl_FragColor = vec4( outgoingLight, diffuseColor.a );\n\t#include <premultiplied_alpha_fragment>\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n}";
  3721. var 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 <fog_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\t#include <uv_vertex>\n\t#include <uv2_vertex>\n\t#include <color_vertex>\n\t#include <skinbase_vertex>\n\t#ifdef USE_ENVMAP\n\t#include <beginnormal_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n\t#endif\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <worldpos_vertex>\n\t#include <clipping_planes_vertex>\n\t#include <envmap_vertex>\n\t#include <fog_vertex>\n}";
  3722. var meshlambert_frag = "uniform vec3 diffuse;\nuniform vec3 emissive;\nuniform float opacity;\nvarying vec3 vLightFront;\nvarying vec3 vIndirectFront;\n#ifdef DOUBLE_SIDED\n\tvarying vec3 vLightBack;\n\tvarying vec3 vIndirectBack;\n#endif\n#include <common>\n#include <packing>\n#include <dithering_pars_fragment>\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_begin>\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\t#include <clipping_planes_fragment>\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\tReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n\tvec3 totalEmissiveRadiance = emissive;\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <color_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <specularmap_fragment>\n\t#include <emissivemap_fragment>\n\treflectedLight.indirectDiffuse = getAmbientLightIrradiance( ambientLightColor );\n\t#ifdef DOUBLE_SIDED\n\t\treflectedLight.indirectDiffuse += ( gl_FrontFacing ) ? vIndirectFront : vIndirectBack;\n\t#else\n\t\treflectedLight.indirectDiffuse += vIndirectFront;\n\t#endif\n\t#include <lightmap_fragment>\n\treflectedLight.indirectDiffuse *= BRDF_Diffuse_Lambert( diffuseColor.rgb );\n\t#ifdef DOUBLE_SIDED\n\t\treflectedLight.directDiffuse = ( gl_FrontFacing ) ? vLightFront : vLightBack;\n\t#else\n\t\treflectedLight.directDiffuse = vLightFront;\n\t#endif\n\treflectedLight.directDiffuse *= BRDF_Diffuse_Lambert( diffuseColor.rgb ) * getShadowMask();\n\t#include <aomap_fragment>\n\tvec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + totalEmissiveRadiance;\n\t#include <envmap_fragment>\n\tgl_FragColor = vec4( outgoingLight, diffuseColor.a );\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n\t#include <dithering_fragment>\n}";
  3723. var meshlambert_vert = "#define LAMBERT\nvarying vec3 vLightFront;\nvarying vec3 vIndirectFront;\n#ifdef DOUBLE_SIDED\n\tvarying vec3 vLightBack;\n\tvarying vec3 vIndirectBack;\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_begin>\n#include <color_pars_vertex>\n#include <fog_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\t#include <uv_vertex>\n\t#include <uv2_vertex>\n\t#include <color_vertex>\n\t#include <beginnormal_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinbase_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\t#include <worldpos_vertex>\n\t#include <envmap_vertex>\n\t#include <lights_lambert_vertex>\n\t#include <shadowmap_vertex>\n\t#include <fog_vertex>\n}";
  3724. var meshmatcap_frag = "#define MATCAP\nuniform vec3 diffuse;\nuniform float opacity;\nuniform sampler2D matcap;\nvarying vec3 vViewPosition;\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n#endif\n#include <common>\n#include <uv_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <fog_pars_fragment>\n#include <bumpmap_pars_fragment>\n#include <normalmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\t#include <clipping_planes_fragment>\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <normal_fragment_begin>\n\t#include <normal_fragment_maps>\n\tvec3 viewDir = normalize( vViewPosition );\n\tvec3 x = normalize( vec3( viewDir.z, 0.0, - viewDir.x ) );\n\tvec3 y = cross( viewDir, x );\n\tvec2 uv = vec2( dot( x, normal ), dot( y, normal ) ) * 0.495 + 0.5;\n\t#ifdef USE_MATCAP\n\t\tvec4 matcapColor = texture2D( matcap, uv );\n\t\tmatcapColor = matcapTexelToLinear( matcapColor );\n\t#else\n\t\tvec4 matcapColor = vec4( 1.0 );\n\t#endif\n\tvec3 outgoingLight = diffuseColor.rgb * matcapColor.rgb;\n\tgl_FragColor = vec4( outgoingLight, diffuseColor.a );\n\t#include <premultiplied_alpha_fragment>\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n}";
  3725. var meshmatcap_vert = "#define MATCAP\nvarying vec3 vViewPosition;\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n#endif\n#include <common>\n#include <uv_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <fog_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\t#include <uv_vertex>\n\t#include <beginnormal_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinbase_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n\t#ifndef FLAT_SHADED\n\t\tvNormal = normalize( transformedNormal );\n\t#endif\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\t#include <fog_vertex>\n\tvViewPosition = - mvPosition.xyz;\n}";
  3726. var 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 <dithering_pars_fragment>\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 <gradientmap_pars_fragment>\n#include <fog_pars_fragment>\n#include <bsdfs>\n#include <lights_pars_begin>\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\t#include <clipping_planes_fragment>\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\tReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n\tvec3 totalEmissiveRadiance = emissive;\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <color_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <specularmap_fragment>\n\t#include <normal_fragment_begin>\n\t#include <normal_fragment_maps>\n\t#include <emissivemap_fragment>\n\t#include <lights_phong_fragment>\n\t#include <lights_fragment_begin>\n\t#include <lights_fragment_maps>\n\t#include <lights_fragment_end>\n\t#include <aomap_fragment>\n\tvec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + reflectedLight.directSpecular + reflectedLight.indirectSpecular + totalEmissiveRadiance;\n\t#include <envmap_fragment>\n\tgl_FragColor = vec4( outgoingLight, diffuseColor.a );\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n\t#include <dithering_fragment>\n}";
  3727. var meshphong_vert = "#define PHONG\nvarying vec3 vViewPosition;\n#ifndef FLAT_SHADED\n\tvarying 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 <fog_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\t#include <uv_vertex>\n\t#include <uv2_vertex>\n\t#include <color_vertex>\n\t#include <beginnormal_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinbase_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n#ifndef FLAT_SHADED\n\tvNormal = normalize( transformedNormal );\n#endif\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\tvViewPosition = - mvPosition.xyz;\n\t#include <worldpos_vertex>\n\t#include <envmap_vertex>\n\t#include <shadowmap_vertex>\n\t#include <fog_vertex>\n}";
  3728. var meshphysical_frag = "#define PHYSICAL\nuniform vec3 diffuse;\nuniform vec3 emissive;\nuniform float roughness;\nuniform float metalness;\nuniform float opacity;\n#ifndef STANDARD\n\tuniform float clearCoat;\n\tuniform float clearCoatRoughness;\n#endif\nvarying vec3 vViewPosition;\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n\t#ifdef USE_TANGENT\n\t\tvarying vec3 vTangent;\n\t\tvarying vec3 vBitangent;\n\t#endif\n#endif\n#include <common>\n#include <packing>\n#include <dithering_pars_fragment>\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 <bsdfs>\n#include <cube_uv_reflection_fragment>\n#include <envmap_pars_fragment>\n#include <envmap_physical_pars_fragment>\n#include <fog_pars_fragment>\n#include <lights_pars_begin>\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\t#include <clipping_planes_fragment>\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\tReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n\tvec3 totalEmissiveRadiance = emissive;\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <color_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <roughnessmap_fragment>\n\t#include <metalnessmap_fragment>\n\t#include <normal_fragment_begin>\n\t#include <normal_fragment_maps>\n\t#include <emissivemap_fragment>\n\t#include <lights_physical_fragment>\n\t#include <lights_fragment_begin>\n\t#include <lights_fragment_maps>\n\t#include <lights_fragment_end>\n\t#include <aomap_fragment>\n\tvec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + reflectedLight.directSpecular + reflectedLight.indirectSpecular + totalEmissiveRadiance;\n\tgl_FragColor = vec4( outgoingLight, diffuseColor.a );\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n\t#include <dithering_fragment>\n}";
  3729. var meshphysical_vert = "#define PHYSICAL\nvarying vec3 vViewPosition;\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n\t#ifdef USE_TANGENT\n\t\tvarying vec3 vTangent;\n\t\tvarying vec3 vBitangent;\n\t#endif\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 <fog_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\t#include <uv_vertex>\n\t#include <uv2_vertex>\n\t#include <color_vertex>\n\t#include <beginnormal_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinbase_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n#ifndef FLAT_SHADED\n\tvNormal = normalize( transformedNormal );\n\t#ifdef USE_TANGENT\n\t\tvTangent = normalize( transformedTangent );\n\t\tvBitangent = normalize( cross( vNormal, vTangent ) * tangent.w );\n\t#endif\n#endif\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\tvViewPosition = - mvPosition.xyz;\n\t#include <worldpos_vertex>\n\t#include <shadowmap_vertex>\n\t#include <fog_vertex>\n}";
  3730. var normal_frag = "#define NORMAL\nuniform float opacity;\n#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || ( defined( USE_NORMALMAP ) && ! defined( OBJECTSPACE_NORMALMAP ) )\n\tvarying vec3 vViewPosition;\n#endif\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n\t#ifdef USE_TANGENT\n\t\tvarying vec3 vTangent;\n\t\tvarying vec3 vBitangent;\n\t#endif\n#endif\n#include <packing>\n#include <uv_pars_fragment>\n#include <bumpmap_pars_fragment>\n#include <normalmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\nvoid main() {\n\t#include <logdepthbuf_fragment>\n\t#include <normal_fragment_begin>\n\t#include <normal_fragment_maps>\n\tgl_FragColor = vec4( packNormalToRGB( normal ), opacity );\n}";
  3731. var normal_vert = "#define NORMAL\n#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || ( defined( USE_NORMALMAP ) && ! defined( OBJECTSPACE_NORMALMAP ) )\n\tvarying vec3 vViewPosition;\n#endif\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n\t#ifdef USE_TANGENT\n\t\tvarying vec3 vTangent;\n\t\tvarying vec3 vBitangent;\n\t#endif\n#endif\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>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <beginnormal_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinbase_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n#ifndef FLAT_SHADED\n\tvNormal = normalize( transformedNormal );\n\t#ifdef USE_TANGENT\n\t\tvTangent = normalize( transformedTangent );\n\t\tvBitangent = normalize( cross( vNormal, vTangent ) * tangent.w );\n\t#endif\n#endif\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || ( defined( USE_NORMALMAP ) && ! defined( OBJECTSPACE_NORMALMAP ) )\n\tvViewPosition = - mvPosition.xyz;\n#endif\n}";
  3732. var 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 <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\t#include <clipping_planes_fragment>\n\tvec3 outgoingLight = vec3( 0.0 );\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include <logdepthbuf_fragment>\n\t#include <map_particle_fragment>\n\t#include <color_fragment>\n\t#include <alphatest_fragment>\n\toutgoingLight = diffuseColor.rgb;\n\tgl_FragColor = vec4( outgoingLight, diffuseColor.a );\n\t#include <premultiplied_alpha_fragment>\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n}";
  3733. var points_vert = "uniform float size;\nuniform float scale;\n#include <common>\n#include <color_pars_vertex>\n#include <fog_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <color_vertex>\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <project_vertex>\n\tgl_PointSize = size;\n\t#ifdef USE_SIZEATTENUATION\n\t\tbool isPerspective = ( projectionMatrix[ 2 ][ 3 ] == - 1.0 );\n\t\tif ( isPerspective ) gl_PointSize *= ( scale / - mvPosition.z );\n\t#endif\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\t#include <worldpos_vertex>\n\t#include <fog_vertex>\n}";
  3734. var shadow_frag = "uniform vec3 color;\nuniform float opacity;\n#include <common>\n#include <packing>\n#include <fog_pars_fragment>\n#include <bsdfs>\n#include <lights_pars_begin>\n#include <shadowmap_pars_fragment>\n#include <shadowmask_pars_fragment>\nvoid main() {\n\tgl_FragColor = vec4( color, opacity * ( 1.0 - getShadowMask() ) );\n\t#include <fog_fragment>\n}";
  3735. var shadow_vert = "#include <fog_pars_vertex>\n#include <shadowmap_pars_vertex>\nvoid main() {\n\t#include <begin_vertex>\n\t#include <project_vertex>\n\t#include <worldpos_vertex>\n\t#include <shadowmap_vertex>\n\t#include <fog_vertex>\n}";
  3736. var sprite_frag = "uniform vec3 diffuse;\nuniform float opacity;\n#include <common>\n#include <uv_pars_fragment>\n#include <map_pars_fragment>\n#include <fog_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\t#include <clipping_planes_fragment>\n\tvec3 outgoingLight = vec3( 0.0 );\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <alphatest_fragment>\n\toutgoingLight = diffuseColor.rgb;\n\tgl_FragColor = vec4( outgoingLight, diffuseColor.a );\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n}";
  3737. var sprite_vert = "uniform float rotation;\nuniform vec2 center;\n#include <common>\n#include <uv_pars_vertex>\n#include <fog_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\tvec4 mvPosition = modelViewMatrix * vec4( 0.0, 0.0, 0.0, 1.0 );\n\tvec2 scale;\n\tscale.x = length( vec3( modelMatrix[ 0 ].x, modelMatrix[ 0 ].y, modelMatrix[ 0 ].z ) );\n\tscale.y = length( vec3( modelMatrix[ 1 ].x, modelMatrix[ 1 ].y, modelMatrix[ 1 ].z ) );\n\t#ifndef USE_SIZEATTENUATION\n\t\tbool isPerspective = ( projectionMatrix[ 2 ][ 3 ] == - 1.0 );\n\t\tif ( isPerspective ) scale *= - mvPosition.z;\n\t#endif\n\tvec2 alignedPosition = ( position.xy - ( center - vec2( 0.5 ) ) ) * scale;\n\tvec2 rotatedPosition;\n\trotatedPosition.x = cos( rotation ) * alignedPosition.x - sin( rotation ) * alignedPosition.y;\n\trotatedPosition.y = sin( rotation ) * alignedPosition.x + cos( rotation ) * alignedPosition.y;\n\tmvPosition.xy += rotatedPosition;\n\tgl_Position = projectionMatrix * mvPosition;\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\t#include <fog_vertex>\n}";
  3738. var ShaderChunk = {
  3739. alphamap_fragment: alphamap_fragment,
  3740. alphamap_pars_fragment: alphamap_pars_fragment,
  3741. alphatest_fragment: alphatest_fragment,
  3742. aomap_fragment: aomap_fragment,
  3743. aomap_pars_fragment: aomap_pars_fragment,
  3744. begin_vertex: begin_vertex,
  3745. beginnormal_vertex: beginnormal_vertex,
  3746. bsdfs: bsdfs,
  3747. bumpmap_pars_fragment: bumpmap_pars_fragment,
  3748. clipping_planes_fragment: clipping_planes_fragment,
  3749. clipping_planes_pars_fragment: clipping_planes_pars_fragment,
  3750. clipping_planes_pars_vertex: clipping_planes_pars_vertex,
  3751. clipping_planes_vertex: clipping_planes_vertex,
  3752. color_fragment: color_fragment,
  3753. color_pars_fragment: color_pars_fragment,
  3754. color_pars_vertex: color_pars_vertex,
  3755. color_vertex: color_vertex,
  3756. common: common,
  3757. cube_uv_reflection_fragment: cube_uv_reflection_fragment,
  3758. defaultnormal_vertex: defaultnormal_vertex,
  3759. displacementmap_pars_vertex: displacementmap_pars_vertex,
  3760. displacementmap_vertex: displacementmap_vertex,
  3761. emissivemap_fragment: emissivemap_fragment,
  3762. emissivemap_pars_fragment: emissivemap_pars_fragment,
  3763. encodings_fragment: encodings_fragment,
  3764. encodings_pars_fragment: encodings_pars_fragment,
  3765. envmap_fragment: envmap_fragment,
  3766. envmap_pars_fragment: envmap_pars_fragment,
  3767. envmap_pars_vertex: envmap_pars_vertex,
  3768. envmap_physical_pars_fragment: envmap_physical_pars_fragment,
  3769. envmap_vertex: envmap_vertex,
  3770. fog_vertex: fog_vertex,
  3771. fog_pars_vertex: fog_pars_vertex,
  3772. fog_fragment: fog_fragment,
  3773. fog_pars_fragment: fog_pars_fragment,
  3774. gradientmap_pars_fragment: gradientmap_pars_fragment,
  3775. lightmap_fragment: lightmap_fragment,
  3776. lightmap_pars_fragment: lightmap_pars_fragment,
  3777. lights_lambert_vertex: lights_lambert_vertex,
  3778. lights_pars_begin: lights_pars_begin,
  3779. lights_phong_fragment: lights_phong_fragment,
  3780. lights_phong_pars_fragment: lights_phong_pars_fragment,
  3781. lights_physical_fragment: lights_physical_fragment,
  3782. lights_physical_pars_fragment: lights_physical_pars_fragment,
  3783. lights_fragment_begin: lights_fragment_begin,
  3784. lights_fragment_maps: lights_fragment_maps,
  3785. lights_fragment_end: lights_fragment_end,
  3786. logdepthbuf_fragment: logdepthbuf_fragment,
  3787. logdepthbuf_pars_fragment: logdepthbuf_pars_fragment,
  3788. logdepthbuf_pars_vertex: logdepthbuf_pars_vertex,
  3789. logdepthbuf_vertex: logdepthbuf_vertex,
  3790. map_fragment: map_fragment,
  3791. map_pars_fragment: map_pars_fragment,
  3792. map_particle_fragment: map_particle_fragment,
  3793. map_particle_pars_fragment: map_particle_pars_fragment,
  3794. metalnessmap_fragment: metalnessmap_fragment,
  3795. metalnessmap_pars_fragment: metalnessmap_pars_fragment,
  3796. morphnormal_vertex: morphnormal_vertex,
  3797. morphtarget_pars_vertex: morphtarget_pars_vertex,
  3798. morphtarget_vertex: morphtarget_vertex,
  3799. normal_fragment_begin: normal_fragment_begin,
  3800. normal_fragment_maps: normal_fragment_maps,
  3801. normalmap_pars_fragment: normalmap_pars_fragment,
  3802. packing: packing,
  3803. premultiplied_alpha_fragment: premultiplied_alpha_fragment,
  3804. project_vertex: project_vertex,
  3805. dithering_fragment: dithering_fragment,
  3806. dithering_pars_fragment: dithering_pars_fragment,
  3807. roughnessmap_fragment: roughnessmap_fragment,
  3808. roughnessmap_pars_fragment: roughnessmap_pars_fragment,
  3809. shadowmap_pars_fragment: shadowmap_pars_fragment,
  3810. shadowmap_pars_vertex: shadowmap_pars_vertex,
  3811. shadowmap_vertex: shadowmap_vertex,
  3812. shadowmask_pars_fragment: shadowmask_pars_fragment,
  3813. skinbase_vertex: skinbase_vertex,
  3814. skinning_pars_vertex: skinning_pars_vertex,
  3815. skinning_vertex: skinning_vertex,
  3816. skinnormal_vertex: skinnormal_vertex,
  3817. specularmap_fragment: specularmap_fragment,
  3818. specularmap_pars_fragment: specularmap_pars_fragment,
  3819. tonemapping_fragment: tonemapping_fragment,
  3820. tonemapping_pars_fragment: tonemapping_pars_fragment,
  3821. uv_pars_fragment: uv_pars_fragment,
  3822. uv_pars_vertex: uv_pars_vertex,
  3823. uv_vertex: uv_vertex,
  3824. uv2_pars_fragment: uv2_pars_fragment,
  3825. uv2_pars_vertex: uv2_pars_vertex,
  3826. uv2_vertex: uv2_vertex,
  3827. worldpos_vertex: worldpos_vertex,
  3828. background_frag: background_frag,
  3829. background_vert: background_vert,
  3830. cube_frag: cube_frag,
  3831. cube_vert: cube_vert,
  3832. depth_frag: depth_frag,
  3833. depth_vert: depth_vert,
  3834. distanceRGBA_frag: distanceRGBA_frag,
  3835. distanceRGBA_vert: distanceRGBA_vert,
  3836. equirect_frag: equirect_frag,
  3837. equirect_vert: equirect_vert,
  3838. linedashed_frag: linedashed_frag,
  3839. linedashed_vert: linedashed_vert,
  3840. meshbasic_frag: meshbasic_frag,
  3841. meshbasic_vert: meshbasic_vert,
  3842. meshlambert_frag: meshlambert_frag,
  3843. meshlambert_vert: meshlambert_vert,
  3844. meshmatcap_frag: meshmatcap_frag,
  3845. meshmatcap_vert: meshmatcap_vert,
  3846. meshphong_frag: meshphong_frag,
  3847. meshphong_vert: meshphong_vert,
  3848. meshphysical_frag: meshphysical_frag,
  3849. meshphysical_vert: meshphysical_vert,
  3850. normal_frag: normal_frag,
  3851. normal_vert: normal_vert,
  3852. points_frag: points_frag,
  3853. points_vert: points_vert,
  3854. shadow_frag: shadow_frag,
  3855. shadow_vert: shadow_vert,
  3856. sprite_frag: sprite_frag,
  3857. sprite_vert: sprite_vert
  3858. };
  3859. /**
  3860. * Uniform Utilities
  3861. */
  3862. function cloneUniforms( src ) {
  3863. var dst = {};
  3864. for ( var u in src ) {
  3865. dst[ u ] = {};
  3866. for ( var p in src[ u ] ) {
  3867. var property = src[ u ][ p ];
  3868. if ( property && ( property.isColor ||
  3869. property.isMatrix3 || property.isMatrix4 ||
  3870. property.isVector2 || property.isVector3 || property.isVector4 ||
  3871. property.isTexture ) ) {
  3872. dst[ u ][ p ] = property.clone();
  3873. } else if ( Array.isArray( property ) ) {
  3874. dst[ u ][ p ] = property.slice();
  3875. } else {
  3876. dst[ u ][ p ] = property;
  3877. }
  3878. }
  3879. }
  3880. return dst;
  3881. }
  3882. function mergeUniforms( uniforms ) {
  3883. var merged = {};
  3884. for ( var u = 0; u < uniforms.length; u ++ ) {
  3885. var tmp = cloneUniforms( uniforms[ u ] );
  3886. for ( var p in tmp ) {
  3887. merged[ p ] = tmp[ p ];
  3888. }
  3889. }
  3890. return merged;
  3891. }
  3892. // Legacy
  3893. var UniformsUtils = { clone: cloneUniforms, merge: mergeUniforms };
  3894. /**
  3895. * @author mrdoob / http://mrdoob.com/
  3896. */
  3897. var ColorKeywords = { 'aliceblue': 0xF0F8FF, 'antiquewhite': 0xFAEBD7, 'aqua': 0x00FFFF, 'aquamarine': 0x7FFFD4, 'azure': 0xF0FFFF,
  3898. 'beige': 0xF5F5DC, 'bisque': 0xFFE4C4, 'black': 0x000000, 'blanchedalmond': 0xFFEBCD, 'blue': 0x0000FF, 'blueviolet': 0x8A2BE2,
  3899. 'brown': 0xA52A2A, 'burlywood': 0xDEB887, 'cadetblue': 0x5F9EA0, 'chartreuse': 0x7FFF00, 'chocolate': 0xD2691E, 'coral': 0xFF7F50,
  3900. 'cornflowerblue': 0x6495ED, 'cornsilk': 0xFFF8DC, 'crimson': 0xDC143C, 'cyan': 0x00FFFF, 'darkblue': 0x00008B, 'darkcyan': 0x008B8B,
  3901. 'darkgoldenrod': 0xB8860B, 'darkgray': 0xA9A9A9, 'darkgreen': 0x006400, 'darkgrey': 0xA9A9A9, 'darkkhaki': 0xBDB76B, 'darkmagenta': 0x8B008B,
  3902. 'darkolivegreen': 0x556B2F, 'darkorange': 0xFF8C00, 'darkorchid': 0x9932CC, 'darkred': 0x8B0000, 'darksalmon': 0xE9967A, 'darkseagreen': 0x8FBC8F,
  3903. 'darkslateblue': 0x483D8B, 'darkslategray': 0x2F4F4F, 'darkslategrey': 0x2F4F4F, 'darkturquoise': 0x00CED1, 'darkviolet': 0x9400D3,
  3904. 'deeppink': 0xFF1493, 'deepskyblue': 0x00BFFF, 'dimgray': 0x696969, 'dimgrey': 0x696969, 'dodgerblue': 0x1E90FF, 'firebrick': 0xB22222,
  3905. 'floralwhite': 0xFFFAF0, 'forestgreen': 0x228B22, 'fuchsia': 0xFF00FF, 'gainsboro': 0xDCDCDC, 'ghostwhite': 0xF8F8FF, 'gold': 0xFFD700,
  3906. 'goldenrod': 0xDAA520, 'gray': 0x808080, 'green': 0x008000, 'greenyellow': 0xADFF2F, 'grey': 0x808080, 'honeydew': 0xF0FFF0, 'hotpink': 0xFF69B4,
  3907. 'indianred': 0xCD5C5C, 'indigo': 0x4B0082, 'ivory': 0xFFFFF0, 'khaki': 0xF0E68C, 'lavender': 0xE6E6FA, 'lavenderblush': 0xFFF0F5, 'lawngreen': 0x7CFC00,
  3908. 'lemonchiffon': 0xFFFACD, 'lightblue': 0xADD8E6, 'lightcoral': 0xF08080, 'lightcyan': 0xE0FFFF, 'lightgoldenrodyellow': 0xFAFAD2, 'lightgray': 0xD3D3D3,
  3909. 'lightgreen': 0x90EE90, 'lightgrey': 0xD3D3D3, 'lightpink': 0xFFB6C1, 'lightsalmon': 0xFFA07A, 'lightseagreen': 0x20B2AA, 'lightskyblue': 0x87CEFA,
  3910. 'lightslategray': 0x778899, 'lightslategrey': 0x778899, 'lightsteelblue': 0xB0C4DE, 'lightyellow': 0xFFFFE0, 'lime': 0x00FF00, 'limegreen': 0x32CD32,
  3911. 'linen': 0xFAF0E6, 'magenta': 0xFF00FF, 'maroon': 0x800000, 'mediumaquamarine': 0x66CDAA, 'mediumblue': 0x0000CD, 'mediumorchid': 0xBA55D3,
  3912. 'mediumpurple': 0x9370DB, 'mediumseagreen': 0x3CB371, 'mediumslateblue': 0x7B68EE, 'mediumspringgreen': 0x00FA9A, 'mediumturquoise': 0x48D1CC,
  3913. 'mediumvioletred': 0xC71585, 'midnightblue': 0x191970, 'mintcream': 0xF5FFFA, 'mistyrose': 0xFFE4E1, 'moccasin': 0xFFE4B5, 'navajowhite': 0xFFDEAD,
  3914. 'navy': 0x000080, 'oldlace': 0xFDF5E6, 'olive': 0x808000, 'olivedrab': 0x6B8E23, 'orange': 0xFFA500, 'orangered': 0xFF4500, 'orchid': 0xDA70D6,
  3915. 'palegoldenrod': 0xEEE8AA, 'palegreen': 0x98FB98, 'paleturquoise': 0xAFEEEE, 'palevioletred': 0xDB7093, 'papayawhip': 0xFFEFD5, 'peachpuff': 0xFFDAB9,
  3916. 'peru': 0xCD853F, 'pink': 0xFFC0CB, 'plum': 0xDDA0DD, 'powderblue': 0xB0E0E6, 'purple': 0x800080, 'rebeccapurple': 0x663399, 'red': 0xFF0000, 'rosybrown': 0xBC8F8F,
  3917. 'royalblue': 0x4169E1, 'saddlebrown': 0x8B4513, 'salmon': 0xFA8072, 'sandybrown': 0xF4A460, 'seagreen': 0x2E8B57, 'seashell': 0xFFF5EE,
  3918. 'sienna': 0xA0522D, 'silver': 0xC0C0C0, 'skyblue': 0x87CEEB, 'slateblue': 0x6A5ACD, 'slategray': 0x708090, 'slategrey': 0x708090, 'snow': 0xFFFAFA,
  3919. 'springgreen': 0x00FF7F, 'steelblue': 0x4682B4, 'tan': 0xD2B48C, 'teal': 0x008080, 'thistle': 0xD8BFD8, 'tomato': 0xFF6347, 'turquoise': 0x40E0D0,
  3920. 'violet': 0xEE82EE, 'wheat': 0xF5DEB3, 'white': 0xFFFFFF, 'whitesmoke': 0xF5F5F5, 'yellow': 0xFFFF00, 'yellowgreen': 0x9ACD32 };
  3921. function Color( r, g, b ) {
  3922. if ( g === undefined && b === undefined ) {
  3923. // r is THREE.Color, hex or string
  3924. return this.set( r );
  3925. }
  3926. return this.setRGB( r, g, b );
  3927. }
  3928. Object.assign( Color.prototype, {
  3929. isColor: true,
  3930. r: 1, g: 1, b: 1,
  3931. set: function ( value ) {
  3932. if ( value && value.isColor ) {
  3933. this.copy( value );
  3934. } else if ( typeof value === 'number' ) {
  3935. this.setHex( value );
  3936. } else if ( typeof value === 'string' ) {
  3937. this.setStyle( value );
  3938. }
  3939. return this;
  3940. },
  3941. setScalar: function ( scalar ) {
  3942. this.r = scalar;
  3943. this.g = scalar;
  3944. this.b = scalar;
  3945. return this;
  3946. },
  3947. setHex: function ( hex ) {
  3948. hex = Math.floor( hex );
  3949. this.r = ( hex >> 16 & 255 ) / 255;
  3950. this.g = ( hex >> 8 & 255 ) / 255;
  3951. this.b = ( hex & 255 ) / 255;
  3952. return this;
  3953. },
  3954. setRGB: function ( r, g, b ) {
  3955. this.r = r;
  3956. this.g = g;
  3957. this.b = b;
  3958. return this;
  3959. },
  3960. setHSL: function () {
  3961. function hue2rgb( p, q, t ) {
  3962. if ( t < 0 ) t += 1;
  3963. if ( t > 1 ) t -= 1;
  3964. if ( t < 1 / 6 ) return p + ( q - p ) * 6 * t;
  3965. if ( t < 1 / 2 ) return q;
  3966. if ( t < 2 / 3 ) return p + ( q - p ) * 6 * ( 2 / 3 - t );
  3967. return p;
  3968. }
  3969. return function setHSL( h, s, l ) {
  3970. // h,s,l ranges are in 0.0 - 1.0
  3971. h = _Math.euclideanModulo( h, 1 );
  3972. s = _Math.clamp( s, 0, 1 );
  3973. l = _Math.clamp( l, 0, 1 );
  3974. if ( s === 0 ) {
  3975. this.r = this.g = this.b = l;
  3976. } else {
  3977. var p = l <= 0.5 ? l * ( 1 + s ) : l + s - ( l * s );
  3978. var q = ( 2 * l ) - p;
  3979. this.r = hue2rgb( q, p, h + 1 / 3 );
  3980. this.g = hue2rgb( q, p, h );
  3981. this.b = hue2rgb( q, p, h - 1 / 3 );
  3982. }
  3983. return this;
  3984. };
  3985. }(),
  3986. setStyle: function ( style ) {
  3987. function handleAlpha( string ) {
  3988. if ( string === undefined ) return;
  3989. if ( parseFloat( string ) < 1 ) {
  3990. console.warn( 'THREE.Color: Alpha component of ' + style + ' will be ignored.' );
  3991. }
  3992. }
  3993. var m;
  3994. if ( m = /^((?:rgb|hsl)a?)\(\s*([^\)]*)\)/.exec( style ) ) {
  3995. // rgb / hsl
  3996. var color;
  3997. var name = m[ 1 ];
  3998. var components = m[ 2 ];
  3999. switch ( name ) {
  4000. case 'rgb':
  4001. case 'rgba':
  4002. if ( color = /^(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec( components ) ) {
  4003. // rgb(255,0,0) rgba(255,0,0,0.5)
  4004. this.r = Math.min( 255, parseInt( color[ 1 ], 10 ) ) / 255;
  4005. this.g = Math.min( 255, parseInt( color[ 2 ], 10 ) ) / 255;
  4006. this.b = Math.min( 255, parseInt( color[ 3 ], 10 ) ) / 255;
  4007. handleAlpha( color[ 5 ] );
  4008. return this;
  4009. }
  4010. if ( color = /^(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec( components ) ) {
  4011. // rgb(100%,0%,0%) rgba(100%,0%,0%,0.5)
  4012. this.r = Math.min( 100, parseInt( color[ 1 ], 10 ) ) / 100;
  4013. this.g = Math.min( 100, parseInt( color[ 2 ], 10 ) ) / 100;
  4014. this.b = Math.min( 100, parseInt( color[ 3 ], 10 ) ) / 100;
  4015. handleAlpha( color[ 5 ] );
  4016. return this;
  4017. }
  4018. break;
  4019. case 'hsl':
  4020. case 'hsla':
  4021. if ( color = /^([0-9]*\.?[0-9]+)\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec( components ) ) {
  4022. // hsl(120,50%,50%) hsla(120,50%,50%,0.5)
  4023. var h = parseFloat( color[ 1 ] ) / 360;
  4024. var s = parseInt( color[ 2 ], 10 ) / 100;
  4025. var l = parseInt( color[ 3 ], 10 ) / 100;
  4026. handleAlpha( color[ 5 ] );
  4027. return this.setHSL( h, s, l );
  4028. }
  4029. break;
  4030. }
  4031. } else if ( m = /^\#([A-Fa-f0-9]+)$/.exec( style ) ) {
  4032. // hex color
  4033. var hex = m[ 1 ];
  4034. var size = hex.length;
  4035. if ( size === 3 ) {
  4036. // #ff0
  4037. this.r = parseInt( hex.charAt( 0 ) + hex.charAt( 0 ), 16 ) / 255;
  4038. this.g = parseInt( hex.charAt( 1 ) + hex.charAt( 1 ), 16 ) / 255;
  4039. this.b = parseInt( hex.charAt( 2 ) + hex.charAt( 2 ), 16 ) / 255;
  4040. return this;
  4041. } else if ( size === 6 ) {
  4042. // #ff0000
  4043. this.r = parseInt( hex.charAt( 0 ) + hex.charAt( 1 ), 16 ) / 255;
  4044. this.g = parseInt( hex.charAt( 2 ) + hex.charAt( 3 ), 16 ) / 255;
  4045. this.b = parseInt( hex.charAt( 4 ) + hex.charAt( 5 ), 16 ) / 255;
  4046. return this;
  4047. }
  4048. }
  4049. if ( style && style.length > 0 ) {
  4050. // color keywords
  4051. var hex = ColorKeywords[ style ];
  4052. if ( hex !== undefined ) {
  4053. // red
  4054. this.setHex( hex );
  4055. } else {
  4056. // unknown color
  4057. console.warn( 'THREE.Color: Unknown color ' + style );
  4058. }
  4059. }
  4060. return this;
  4061. },
  4062. clone: function () {
  4063. return new this.constructor( this.r, this.g, this.b );
  4064. },
  4065. copy: function ( color ) {
  4066. this.r = color.r;
  4067. this.g = color.g;
  4068. this.b = color.b;
  4069. return this;
  4070. },
  4071. copyGammaToLinear: function ( color, gammaFactor ) {
  4072. if ( gammaFactor === undefined ) gammaFactor = 2.0;
  4073. this.r = Math.pow( color.r, gammaFactor );
  4074. this.g = Math.pow( color.g, gammaFactor );
  4075. this.b = Math.pow( color.b, gammaFactor );
  4076. return this;
  4077. },
  4078. copyLinearToGamma: function ( color, gammaFactor ) {
  4079. if ( gammaFactor === undefined ) gammaFactor = 2.0;
  4080. var safeInverse = ( gammaFactor > 0 ) ? ( 1.0 / gammaFactor ) : 1.0;
  4081. this.r = Math.pow( color.r, safeInverse );
  4082. this.g = Math.pow( color.g, safeInverse );
  4083. this.b = Math.pow( color.b, safeInverse );
  4084. return this;
  4085. },
  4086. convertGammaToLinear: function ( gammaFactor ) {
  4087. this.copyGammaToLinear( this, gammaFactor );
  4088. return this;
  4089. },
  4090. convertLinearToGamma: function ( gammaFactor ) {
  4091. this.copyLinearToGamma( this, gammaFactor );
  4092. return this;
  4093. },
  4094. copySRGBToLinear: function () {
  4095. function SRGBToLinear( c ) {
  4096. return ( c < 0.04045 ) ? c * 0.0773993808 : Math.pow( c * 0.9478672986 + 0.0521327014, 2.4 );
  4097. }
  4098. return function copySRGBToLinear( color ) {
  4099. this.r = SRGBToLinear( color.r );
  4100. this.g = SRGBToLinear( color.g );
  4101. this.b = SRGBToLinear( color.b );
  4102. return this;
  4103. };
  4104. }(),
  4105. copyLinearToSRGB: function () {
  4106. function LinearToSRGB( c ) {
  4107. return ( c < 0.0031308 ) ? c * 12.92 : 1.055 * ( Math.pow( c, 0.41666 ) ) - 0.055;
  4108. }
  4109. return function copyLinearToSRGB( color ) {
  4110. this.r = LinearToSRGB( color.r );
  4111. this.g = LinearToSRGB( color.g );
  4112. this.b = LinearToSRGB( color.b );
  4113. return this;
  4114. };
  4115. }(),
  4116. convertSRGBToLinear: function () {
  4117. this.copySRGBToLinear( this );
  4118. return this;
  4119. },
  4120. convertLinearToSRGB: function () {
  4121. this.copyLinearToSRGB( this );
  4122. return this;
  4123. },
  4124. getHex: function () {
  4125. return ( this.r * 255 ) << 16 ^ ( this.g * 255 ) << 8 ^ ( this.b * 255 ) << 0;
  4126. },
  4127. getHexString: function () {
  4128. return ( '000000' + this.getHex().toString( 16 ) ).slice( - 6 );
  4129. },
  4130. getHSL: function ( target ) {
  4131. // h,s,l ranges are in 0.0 - 1.0
  4132. if ( target === undefined ) {
  4133. console.warn( 'THREE.Color: .getHSL() target is now required' );
  4134. target = { h: 0, s: 0, l: 0 };
  4135. }
  4136. var r = this.r, g = this.g, b = this.b;
  4137. var max = Math.max( r, g, b );
  4138. var min = Math.min( r, g, b );
  4139. var hue, saturation;
  4140. var lightness = ( min + max ) / 2.0;
  4141. if ( min === max ) {
  4142. hue = 0;
  4143. saturation = 0;
  4144. } else {
  4145. var delta = max - min;
  4146. saturation = lightness <= 0.5 ? delta / ( max + min ) : delta / ( 2 - max - min );
  4147. switch ( max ) {
  4148. case r: hue = ( g - b ) / delta + ( g < b ? 6 : 0 ); break;
  4149. case g: hue = ( b - r ) / delta + 2; break;
  4150. case b: hue = ( r - g ) / delta + 4; break;
  4151. }
  4152. hue /= 6;
  4153. }
  4154. target.h = hue;
  4155. target.s = saturation;
  4156. target.l = lightness;
  4157. return target;
  4158. },
  4159. getStyle: function () {
  4160. return 'rgb(' + ( ( this.r * 255 ) | 0 ) + ',' + ( ( this.g * 255 ) | 0 ) + ',' + ( ( this.b * 255 ) | 0 ) + ')';
  4161. },
  4162. offsetHSL: function () {
  4163. var hsl = {};
  4164. return function ( h, s, l ) {
  4165. this.getHSL( hsl );
  4166. hsl.h += h; hsl.s += s; hsl.l += l;
  4167. this.setHSL( hsl.h, hsl.s, hsl.l );
  4168. return this;
  4169. };
  4170. }(),
  4171. add: function ( color ) {
  4172. this.r += color.r;
  4173. this.g += color.g;
  4174. this.b += color.b;
  4175. return this;
  4176. },
  4177. addColors: function ( color1, color2 ) {
  4178. this.r = color1.r + color2.r;
  4179. this.g = color1.g + color2.g;
  4180. this.b = color1.b + color2.b;
  4181. return this;
  4182. },
  4183. addScalar: function ( s ) {
  4184. this.r += s;
  4185. this.g += s;
  4186. this.b += s;
  4187. return this;
  4188. },
  4189. sub: function ( color ) {
  4190. this.r = Math.max( 0, this.r - color.r );
  4191. this.g = Math.max( 0, this.g - color.g );
  4192. this.b = Math.max( 0, this.b - color.b );
  4193. return this;
  4194. },
  4195. multiply: function ( color ) {
  4196. this.r *= color.r;
  4197. this.g *= color.g;
  4198. this.b *= color.b;
  4199. return this;
  4200. },
  4201. multiplyScalar: function ( s ) {
  4202. this.r *= s;
  4203. this.g *= s;
  4204. this.b *= s;
  4205. return this;
  4206. },
  4207. lerp: function ( color, alpha ) {
  4208. this.r += ( color.r - this.r ) * alpha;
  4209. this.g += ( color.g - this.g ) * alpha;
  4210. this.b += ( color.b - this.b ) * alpha;
  4211. return this;
  4212. },
  4213. lerpHSL: function () {
  4214. var hslA = { h: 0, s: 0, l: 0 };
  4215. var hslB = { h: 0, s: 0, l: 0 };
  4216. return function lerpHSL( color, alpha ) {
  4217. this.getHSL( hslA );
  4218. color.getHSL( hslB );
  4219. var h = _Math.lerp( hslA.h, hslB.h, alpha );
  4220. var s = _Math.lerp( hslA.s, hslB.s, alpha );
  4221. var l = _Math.lerp( hslA.l, hslB.l, alpha );
  4222. this.setHSL( h, s, l );
  4223. return this;
  4224. };
  4225. }(),
  4226. equals: function ( c ) {
  4227. return ( c.r === this.r ) && ( c.g === this.g ) && ( c.b === this.b );
  4228. },
  4229. fromArray: function ( array, offset ) {
  4230. if ( offset === undefined ) offset = 0;
  4231. this.r = array[ offset ];
  4232. this.g = array[ offset + 1 ];
  4233. this.b = array[ offset + 2 ];
  4234. return this;
  4235. },
  4236. toArray: function ( array, offset ) {
  4237. if ( array === undefined ) array = [];
  4238. if ( offset === undefined ) offset = 0;
  4239. array[ offset ] = this.r;
  4240. array[ offset + 1 ] = this.g;
  4241. array[ offset + 2 ] = this.b;
  4242. return array;
  4243. },
  4244. toJSON: function () {
  4245. return this.getHex();
  4246. }
  4247. } );
  4248. /**
  4249. * Uniforms library for shared webgl shaders
  4250. */
  4251. var UniformsLib = {
  4252. common: {
  4253. diffuse: { value: new Color( 0xeeeeee ) },
  4254. opacity: { value: 1.0 },
  4255. map: { value: null },
  4256. uvTransform: { value: new Matrix3() },
  4257. alphaMap: { value: null },
  4258. },
  4259. specularmap: {
  4260. specularMap: { value: null },
  4261. },
  4262. envmap: {
  4263. envMap: { value: null },
  4264. flipEnvMap: { value: - 1 },
  4265. reflectivity: { value: 1.0 },
  4266. refractionRatio: { value: 0.98 },
  4267. maxMipLevel: { value: 0 }
  4268. },
  4269. aomap: {
  4270. aoMap: { value: null },
  4271. aoMapIntensity: { value: 1 }
  4272. },
  4273. lightmap: {
  4274. lightMap: { value: null },
  4275. lightMapIntensity: { value: 1 }
  4276. },
  4277. emissivemap: {
  4278. emissiveMap: { value: null }
  4279. },
  4280. bumpmap: {
  4281. bumpMap: { value: null },
  4282. bumpScale: { value: 1 }
  4283. },
  4284. normalmap: {
  4285. normalMap: { value: null },
  4286. normalScale: { value: new Vector2( 1, 1 ) }
  4287. },
  4288. displacementmap: {
  4289. displacementMap: { value: null },
  4290. displacementScale: { value: 1 },
  4291. displacementBias: { value: 0 }
  4292. },
  4293. roughnessmap: {
  4294. roughnessMap: { value: null }
  4295. },
  4296. metalnessmap: {
  4297. metalnessMap: { value: null }
  4298. },
  4299. gradientmap: {
  4300. gradientMap: { value: null }
  4301. },
  4302. fog: {
  4303. fogDensity: { value: 0.00025 },
  4304. fogNear: { value: 1 },
  4305. fogFar: { value: 2000 },
  4306. fogColor: { value: new Color( 0xffffff ) }
  4307. },
  4308. lights: {
  4309. ambientLightColor: { value: [] },
  4310. directionalLights: { value: [], properties: {
  4311. direction: {},
  4312. color: {},
  4313. shadow: {},
  4314. shadowBias: {},
  4315. shadowRadius: {},
  4316. shadowMapSize: {}
  4317. } },
  4318. directionalShadowMap: { value: [] },
  4319. directionalShadowMatrix: { value: [] },
  4320. spotLights: { value: [], properties: {
  4321. color: {},
  4322. position: {},
  4323. direction: {},
  4324. distance: {},
  4325. coneCos: {},
  4326. penumbraCos: {},
  4327. decay: {},
  4328. shadow: {},
  4329. shadowBias: {},
  4330. shadowRadius: {},
  4331. shadowMapSize: {}
  4332. } },
  4333. spotShadowMap: { value: [] },
  4334. spotShadowMatrix: { value: [] },
  4335. pointLights: { value: [], properties: {
  4336. color: {},
  4337. position: {},
  4338. decay: {},
  4339. distance: {},
  4340. shadow: {},
  4341. shadowBias: {},
  4342. shadowRadius: {},
  4343. shadowMapSize: {},
  4344. shadowCameraNear: {},
  4345. shadowCameraFar: {}
  4346. } },
  4347. pointShadowMap: { value: [] },
  4348. pointShadowMatrix: { value: [] },
  4349. hemisphereLights: { value: [], properties: {
  4350. direction: {},
  4351. skyColor: {},
  4352. groundColor: {}
  4353. } },
  4354. // TODO (abelnation): RectAreaLight BRDF data needs to be moved from example to main src
  4355. rectAreaLights: { value: [], properties: {
  4356. color: {},
  4357. position: {},
  4358. width: {},
  4359. height: {}
  4360. } }
  4361. },
  4362. points: {
  4363. diffuse: { value: new Color( 0xeeeeee ) },
  4364. opacity: { value: 1.0 },
  4365. size: { value: 1.0 },
  4366. scale: { value: 1.0 },
  4367. map: { value: null },
  4368. uvTransform: { value: new Matrix3() }
  4369. },
  4370. sprite: {
  4371. diffuse: { value: new Color( 0xeeeeee ) },
  4372. opacity: { value: 1.0 },
  4373. center: { value: new Vector2( 0.5, 0.5 ) },
  4374. rotation: { value: 0.0 },
  4375. map: { value: null },
  4376. uvTransform: { value: new Matrix3() }
  4377. }
  4378. };
  4379. /**
  4380. * @author alteredq / http://alteredqualia.com/
  4381. * @author mrdoob / http://mrdoob.com/
  4382. * @author mikael emtinger / http://gomo.se/
  4383. */
  4384. var ShaderLib = {
  4385. basic: {
  4386. uniforms: mergeUniforms( [
  4387. UniformsLib.common,
  4388. UniformsLib.specularmap,
  4389. UniformsLib.envmap,
  4390. UniformsLib.aomap,
  4391. UniformsLib.lightmap,
  4392. UniformsLib.fog
  4393. ] ),
  4394. vertexShader: ShaderChunk.meshbasic_vert,
  4395. fragmentShader: ShaderChunk.meshbasic_frag
  4396. },
  4397. lambert: {
  4398. uniforms: mergeUniforms( [
  4399. UniformsLib.common,
  4400. UniformsLib.specularmap,
  4401. UniformsLib.envmap,
  4402. UniformsLib.aomap,
  4403. UniformsLib.lightmap,
  4404. UniformsLib.emissivemap,
  4405. UniformsLib.fog,
  4406. UniformsLib.lights,
  4407. {
  4408. emissive: { value: new Color( 0x000000 ) }
  4409. }
  4410. ] ),
  4411. vertexShader: ShaderChunk.meshlambert_vert,
  4412. fragmentShader: ShaderChunk.meshlambert_frag
  4413. },
  4414. phong: {
  4415. uniforms: mergeUniforms( [
  4416. UniformsLib.common,
  4417. UniformsLib.specularmap,
  4418. UniformsLib.envmap,
  4419. UniformsLib.aomap,
  4420. UniformsLib.lightmap,
  4421. UniformsLib.emissivemap,
  4422. UniformsLib.bumpmap,
  4423. UniformsLib.normalmap,
  4424. UniformsLib.displacementmap,
  4425. UniformsLib.gradientmap,
  4426. UniformsLib.fog,
  4427. UniformsLib.lights,
  4428. {
  4429. emissive: { value: new Color( 0x000000 ) },
  4430. specular: { value: new Color( 0x111111 ) },
  4431. shininess: { value: 30 }
  4432. }
  4433. ] ),
  4434. vertexShader: ShaderChunk.meshphong_vert,
  4435. fragmentShader: ShaderChunk.meshphong_frag
  4436. },
  4437. standard: {
  4438. uniforms: mergeUniforms( [
  4439. UniformsLib.common,
  4440. UniformsLib.envmap,
  4441. UniformsLib.aomap,
  4442. UniformsLib.lightmap,
  4443. UniformsLib.emissivemap,
  4444. UniformsLib.bumpmap,
  4445. UniformsLib.normalmap,
  4446. UniformsLib.displacementmap,
  4447. UniformsLib.roughnessmap,
  4448. UniformsLib.metalnessmap,
  4449. UniformsLib.fog,
  4450. UniformsLib.lights,
  4451. {
  4452. emissive: { value: new Color( 0x000000 ) },
  4453. roughness: { value: 0.5 },
  4454. metalness: { value: 0.5 },
  4455. envMapIntensity: { value: 1 } // temporary
  4456. }
  4457. ] ),
  4458. vertexShader: ShaderChunk.meshphysical_vert,
  4459. fragmentShader: ShaderChunk.meshphysical_frag
  4460. },
  4461. matcap: {
  4462. uniforms: mergeUniforms( [
  4463. UniformsLib.common,
  4464. UniformsLib.bumpmap,
  4465. UniformsLib.normalmap,
  4466. UniformsLib.displacementmap,
  4467. UniformsLib.fog,
  4468. {
  4469. matcap: { value: null }
  4470. }
  4471. ] ),
  4472. vertexShader: ShaderChunk.meshmatcap_vert,
  4473. fragmentShader: ShaderChunk.meshmatcap_frag
  4474. },
  4475. points: {
  4476. uniforms: mergeUniforms( [
  4477. UniformsLib.points,
  4478. UniformsLib.fog
  4479. ] ),
  4480. vertexShader: ShaderChunk.points_vert,
  4481. fragmentShader: ShaderChunk.points_frag
  4482. },
  4483. dashed: {
  4484. uniforms: mergeUniforms( [
  4485. UniformsLib.common,
  4486. UniformsLib.fog,
  4487. {
  4488. scale: { value: 1 },
  4489. dashSize: { value: 1 },
  4490. totalSize: { value: 2 }
  4491. }
  4492. ] ),
  4493. vertexShader: ShaderChunk.linedashed_vert,
  4494. fragmentShader: ShaderChunk.linedashed_frag
  4495. },
  4496. depth: {
  4497. uniforms: mergeUniforms( [
  4498. UniformsLib.common,
  4499. UniformsLib.displacementmap
  4500. ] ),
  4501. vertexShader: ShaderChunk.depth_vert,
  4502. fragmentShader: ShaderChunk.depth_frag
  4503. },
  4504. normal: {
  4505. uniforms: mergeUniforms( [
  4506. UniformsLib.common,
  4507. UniformsLib.bumpmap,
  4508. UniformsLib.normalmap,
  4509. UniformsLib.displacementmap,
  4510. {
  4511. opacity: { value: 1.0 }
  4512. }
  4513. ] ),
  4514. vertexShader: ShaderChunk.normal_vert,
  4515. fragmentShader: ShaderChunk.normal_frag
  4516. },
  4517. sprite: {
  4518. uniforms: mergeUniforms( [
  4519. UniformsLib.sprite,
  4520. UniformsLib.fog
  4521. ] ),
  4522. vertexShader: ShaderChunk.sprite_vert,
  4523. fragmentShader: ShaderChunk.sprite_frag
  4524. },
  4525. background: {
  4526. uniforms: {
  4527. uvTransform: { value: new Matrix3() },
  4528. t2D: { value: null },
  4529. },
  4530. vertexShader: ShaderChunk.background_vert,
  4531. fragmentShader: ShaderChunk.background_frag
  4532. },
  4533. /* -------------------------------------------------------------------------
  4534. // Cube map shader
  4535. ------------------------------------------------------------------------- */
  4536. cube: {
  4537. uniforms: {
  4538. tCube: { value: null },
  4539. tFlip: { value: - 1 },
  4540. opacity: { value: 1.0 }
  4541. },
  4542. vertexShader: ShaderChunk.cube_vert,
  4543. fragmentShader: ShaderChunk.cube_frag
  4544. },
  4545. equirect: {
  4546. uniforms: {
  4547. tEquirect: { value: null },
  4548. },
  4549. vertexShader: ShaderChunk.equirect_vert,
  4550. fragmentShader: ShaderChunk.equirect_frag
  4551. },
  4552. distanceRGBA: {
  4553. uniforms: mergeUniforms( [
  4554. UniformsLib.common,
  4555. UniformsLib.displacementmap,
  4556. {
  4557. referencePosition: { value: new Vector3() },
  4558. nearDistance: { value: 1 },
  4559. farDistance: { value: 1000 }
  4560. }
  4561. ] ),
  4562. vertexShader: ShaderChunk.distanceRGBA_vert,
  4563. fragmentShader: ShaderChunk.distanceRGBA_frag
  4564. },
  4565. shadow: {
  4566. uniforms: mergeUniforms( [
  4567. UniformsLib.lights,
  4568. UniformsLib.fog,
  4569. {
  4570. color: { value: new Color( 0x00000 ) },
  4571. opacity: { value: 1.0 }
  4572. },
  4573. ] ),
  4574. vertexShader: ShaderChunk.shadow_vert,
  4575. fragmentShader: ShaderChunk.shadow_frag
  4576. }
  4577. };
  4578. ShaderLib.physical = {
  4579. uniforms: mergeUniforms( [
  4580. ShaderLib.standard.uniforms,
  4581. {
  4582. clearCoat: { value: 0 },
  4583. clearCoatRoughness: { value: 0 }
  4584. }
  4585. ] ),
  4586. vertexShader: ShaderChunk.meshphysical_vert,
  4587. fragmentShader: ShaderChunk.meshphysical_frag
  4588. };
  4589. /**
  4590. * @author mrdoob / http://mrdoob.com/
  4591. */
  4592. function WebGLAnimation() {
  4593. var context = null;
  4594. var isAnimating = false;
  4595. var animationLoop = null;
  4596. function onAnimationFrame( time, frame ) {
  4597. if ( isAnimating === false ) return;
  4598. animationLoop( time, frame );
  4599. context.requestAnimationFrame( onAnimationFrame );
  4600. }
  4601. return {
  4602. start: function () {
  4603. if ( isAnimating === true ) return;
  4604. if ( animationLoop === null ) return;
  4605. context.requestAnimationFrame( onAnimationFrame );
  4606. isAnimating = true;
  4607. },
  4608. stop: function () {
  4609. isAnimating = false;
  4610. },
  4611. setAnimationLoop: function ( callback ) {
  4612. animationLoop = callback;
  4613. },
  4614. setContext: function ( value ) {
  4615. context = value;
  4616. }
  4617. };
  4618. }
  4619. /**
  4620. * @author mrdoob / http://mrdoob.com/
  4621. */
  4622. function WebGLAttributes( gl ) {
  4623. var buffers = new WeakMap();
  4624. function createBuffer( attribute, bufferType ) {
  4625. var array = attribute.array;
  4626. var usage = attribute.dynamic ? 35048 : 35044;
  4627. var buffer = gl.createBuffer();
  4628. gl.bindBuffer( bufferType, buffer );
  4629. gl.bufferData( bufferType, array, usage );
  4630. attribute.onUploadCallback();
  4631. var type = 5126;
  4632. if ( array instanceof Float32Array ) {
  4633. type = 5126;
  4634. } else if ( array instanceof Float64Array ) {
  4635. console.warn( 'THREE.WebGLAttributes: Unsupported data buffer format: Float64Array.' );
  4636. } else if ( array instanceof Uint16Array ) {
  4637. type = 5123;
  4638. } else if ( array instanceof Int16Array ) {
  4639. type = 5122;
  4640. } else if ( array instanceof Uint32Array ) {
  4641. type = 5125;
  4642. } else if ( array instanceof Int32Array ) {
  4643. type = 5124;
  4644. } else if ( array instanceof Int8Array ) {
  4645. type = 5120;
  4646. } else if ( array instanceof Uint8Array ) {
  4647. type = 5121;
  4648. }
  4649. return {
  4650. buffer: buffer,
  4651. type: type,
  4652. bytesPerElement: array.BYTES_PER_ELEMENT,
  4653. version: attribute.version
  4654. };
  4655. }
  4656. function updateBuffer( buffer, attribute, bufferType ) {
  4657. var array = attribute.array;
  4658. var updateRange = attribute.updateRange;
  4659. gl.bindBuffer( bufferType, buffer );
  4660. if ( attribute.dynamic === false ) {
  4661. gl.bufferData( bufferType, array, 35044 );
  4662. } else if ( updateRange.count === - 1 ) {
  4663. // Not using update ranges
  4664. gl.bufferSubData( bufferType, 0, array );
  4665. } else if ( updateRange.count === 0 ) {
  4666. 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.' );
  4667. } else {
  4668. gl.bufferSubData( bufferType, updateRange.offset * array.BYTES_PER_ELEMENT,
  4669. array.subarray( updateRange.offset, updateRange.offset + updateRange.count ) );
  4670. updateRange.count = - 1; // reset range
  4671. }
  4672. }
  4673. //
  4674. function get( attribute ) {
  4675. if ( attribute.isInterleavedBufferAttribute ) attribute = attribute.data;
  4676. return buffers.get( attribute );
  4677. }
  4678. function remove( attribute ) {
  4679. if ( attribute.isInterleavedBufferAttribute ) attribute = attribute.data;
  4680. var data = buffers.get( attribute );
  4681. if ( data ) {
  4682. gl.deleteBuffer( data.buffer );
  4683. buffers.delete( attribute );
  4684. }
  4685. }
  4686. function update( attribute, bufferType ) {
  4687. if ( attribute.isInterleavedBufferAttribute ) attribute = attribute.data;
  4688. var data = buffers.get( attribute );
  4689. if ( data === undefined ) {
  4690. buffers.set( attribute, createBuffer( attribute, bufferType ) );
  4691. } else if ( data.version < attribute.version ) {
  4692. updateBuffer( data.buffer, attribute, bufferType );
  4693. data.version = attribute.version;
  4694. }
  4695. }
  4696. return {
  4697. get: get,
  4698. remove: remove,
  4699. update: update
  4700. };
  4701. }
  4702. /**
  4703. * @author mrdoob / http://mrdoob.com/
  4704. * @author alteredq / http://alteredqualia.com/
  4705. */
  4706. function Face3( a, b, c, normal, color, materialIndex ) {
  4707. this.a = a;
  4708. this.b = b;
  4709. this.c = c;
  4710. this.normal = ( normal && normal.isVector3 ) ? normal : new Vector3();
  4711. this.vertexNormals = Array.isArray( normal ) ? normal : [];
  4712. this.color = ( color && color.isColor ) ? color : new Color();
  4713. this.vertexColors = Array.isArray( color ) ? color : [];
  4714. this.materialIndex = materialIndex !== undefined ? materialIndex : 0;
  4715. }
  4716. Object.assign( Face3.prototype, {
  4717. clone: function () {
  4718. return new this.constructor().copy( this );
  4719. },
  4720. copy: function ( source ) {
  4721. this.a = source.a;
  4722. this.b = source.b;
  4723. this.c = source.c;
  4724. this.normal.copy( source.normal );
  4725. this.color.copy( source.color );
  4726. this.materialIndex = source.materialIndex;
  4727. for ( var i = 0, il = source.vertexNormals.length; i < il; i ++ ) {
  4728. this.vertexNormals[ i ] = source.vertexNormals[ i ].clone();
  4729. }
  4730. for ( var i = 0, il = source.vertexColors.length; i < il; i ++ ) {
  4731. this.vertexColors[ i ] = source.vertexColors[ i ].clone();
  4732. }
  4733. return this;
  4734. }
  4735. } );
  4736. /**
  4737. * @author mrdoob / http://mrdoob.com/
  4738. * @author WestLangley / http://github.com/WestLangley
  4739. * @author bhouston / http://clara.io
  4740. */
  4741. function Euler( x, y, z, order ) {
  4742. this._x = x || 0;
  4743. this._y = y || 0;
  4744. this._z = z || 0;
  4745. this._order = order || Euler.DefaultOrder;
  4746. }
  4747. Euler.RotationOrders = [ 'XYZ', 'YZX', 'ZXY', 'XZY', 'YXZ', 'ZYX' ];
  4748. Euler.DefaultOrder = 'XYZ';
  4749. Object.defineProperties( Euler.prototype, {
  4750. x: {
  4751. get: function () {
  4752. return this._x;
  4753. },
  4754. set: function ( value ) {
  4755. this._x = value;
  4756. this.onChangeCallback();
  4757. }
  4758. },
  4759. y: {
  4760. get: function () {
  4761. return this._y;
  4762. },
  4763. set: function ( value ) {
  4764. this._y = value;
  4765. this.onChangeCallback();
  4766. }
  4767. },
  4768. z: {
  4769. get: function () {
  4770. return this._z;
  4771. },
  4772. set: function ( value ) {
  4773. this._z = value;
  4774. this.onChangeCallback();
  4775. }
  4776. },
  4777. order: {
  4778. get: function () {
  4779. return this._order;
  4780. },
  4781. set: function ( value ) {
  4782. this._order = value;
  4783. this.onChangeCallback();
  4784. }
  4785. }
  4786. } );
  4787. Object.assign( Euler.prototype, {
  4788. isEuler: true,
  4789. set: function ( x, y, z, order ) {
  4790. this._x = x;
  4791. this._y = y;
  4792. this._z = z;
  4793. this._order = order || this._order;
  4794. this.onChangeCallback();
  4795. return this;
  4796. },
  4797. clone: function () {
  4798. return new this.constructor( this._x, this._y, this._z, this._order );
  4799. },
  4800. copy: function ( euler ) {
  4801. this._x = euler._x;
  4802. this._y = euler._y;
  4803. this._z = euler._z;
  4804. this._order = euler._order;
  4805. this.onChangeCallback();
  4806. return this;
  4807. },
  4808. setFromRotationMatrix: function ( m, order, update ) {
  4809. var clamp = _Math.clamp;
  4810. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  4811. var te = m.elements;
  4812. var m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ];
  4813. var m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ];
  4814. var m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ];
  4815. order = order || this._order;
  4816. if ( order === 'XYZ' ) {
  4817. this._y = Math.asin( clamp( m13, - 1, 1 ) );
  4818. if ( Math.abs( m13 ) < 0.99999 ) {
  4819. this._x = Math.atan2( - m23, m33 );
  4820. this._z = Math.atan2( - m12, m11 );
  4821. } else {
  4822. this._x = Math.atan2( m32, m22 );
  4823. this._z = 0;
  4824. }
  4825. } else if ( order === 'YXZ' ) {
  4826. this._x = Math.asin( - clamp( m23, - 1, 1 ) );
  4827. if ( Math.abs( m23 ) < 0.99999 ) {
  4828. this._y = Math.atan2( m13, m33 );
  4829. this._z = Math.atan2( m21, m22 );
  4830. } else {
  4831. this._y = Math.atan2( - m31, m11 );
  4832. this._z = 0;
  4833. }
  4834. } else if ( order === 'ZXY' ) {
  4835. this._x = Math.asin( clamp( m32, - 1, 1 ) );
  4836. if ( Math.abs( m32 ) < 0.99999 ) {
  4837. this._y = Math.atan2( - m31, m33 );
  4838. this._z = Math.atan2( - m12, m22 );
  4839. } else {
  4840. this._y = 0;
  4841. this._z = Math.atan2( m21, m11 );
  4842. }
  4843. } else if ( order === 'ZYX' ) {
  4844. this._y = Math.asin( - clamp( m31, - 1, 1 ) );
  4845. if ( Math.abs( m31 ) < 0.99999 ) {
  4846. this._x = Math.atan2( m32, m33 );
  4847. this._z = Math.atan2( m21, m11 );
  4848. } else {
  4849. this._x = 0;
  4850. this._z = Math.atan2( - m12, m22 );
  4851. }
  4852. } else if ( order === 'YZX' ) {
  4853. this._z = Math.asin( clamp( m21, - 1, 1 ) );
  4854. if ( Math.abs( m21 ) < 0.99999 ) {
  4855. this._x = Math.atan2( - m23, m22 );
  4856. this._y = Math.atan2( - m31, m11 );
  4857. } else {
  4858. this._x = 0;
  4859. this._y = Math.atan2( m13, m33 );
  4860. }
  4861. } else if ( order === 'XZY' ) {
  4862. this._z = Math.asin( - clamp( m12, - 1, 1 ) );
  4863. if ( Math.abs( m12 ) < 0.99999 ) {
  4864. this._x = Math.atan2( m32, m22 );
  4865. this._y = Math.atan2( m13, m11 );
  4866. } else {
  4867. this._x = Math.atan2( - m23, m33 );
  4868. this._y = 0;
  4869. }
  4870. } else {
  4871. console.warn( 'THREE.Euler: .setFromRotationMatrix() given unsupported order: ' + order );
  4872. }
  4873. this._order = order;
  4874. if ( update !== false ) this.onChangeCallback();
  4875. return this;
  4876. },
  4877. setFromQuaternion: function () {
  4878. var matrix = new Matrix4();
  4879. return function setFromQuaternion( q, order, update ) {
  4880. matrix.makeRotationFromQuaternion( q );
  4881. return this.setFromRotationMatrix( matrix, order, update );
  4882. };
  4883. }(),
  4884. setFromVector3: function ( v, order ) {
  4885. return this.set( v.x, v.y, v.z, order || this._order );
  4886. },
  4887. reorder: function () {
  4888. // WARNING: this discards revolution information -bhouston
  4889. var q = new Quaternion();
  4890. return function reorder( newOrder ) {
  4891. q.setFromEuler( this );
  4892. return this.setFromQuaternion( q, newOrder );
  4893. };
  4894. }(),
  4895. equals: function ( euler ) {
  4896. return ( euler._x === this._x ) && ( euler._y === this._y ) && ( euler._z === this._z ) && ( euler._order === this._order );
  4897. },
  4898. fromArray: function ( array ) {
  4899. this._x = array[ 0 ];
  4900. this._y = array[ 1 ];
  4901. this._z = array[ 2 ];
  4902. if ( array[ 3 ] !== undefined ) this._order = array[ 3 ];
  4903. this.onChangeCallback();
  4904. return this;
  4905. },
  4906. toArray: function ( array, offset ) {
  4907. if ( array === undefined ) array = [];
  4908. if ( offset === undefined ) offset = 0;
  4909. array[ offset ] = this._x;
  4910. array[ offset + 1 ] = this._y;
  4911. array[ offset + 2 ] = this._z;
  4912. array[ offset + 3 ] = this._order;
  4913. return array;
  4914. },
  4915. toVector3: function ( optionalResult ) {
  4916. if ( optionalResult ) {
  4917. return optionalResult.set( this._x, this._y, this._z );
  4918. } else {
  4919. return new Vector3( this._x, this._y, this._z );
  4920. }
  4921. },
  4922. onChange: function ( callback ) {
  4923. this.onChangeCallback = callback;
  4924. return this;
  4925. },
  4926. onChangeCallback: function () {}
  4927. } );
  4928. /**
  4929. * @author mrdoob / http://mrdoob.com/
  4930. */
  4931. function Layers() {
  4932. this.mask = 1 | 0;
  4933. }
  4934. Object.assign( Layers.prototype, {
  4935. set: function ( channel ) {
  4936. this.mask = 1 << channel | 0;
  4937. },
  4938. enable: function ( channel ) {
  4939. this.mask |= 1 << channel | 0;
  4940. },
  4941. toggle: function ( channel ) {
  4942. this.mask ^= 1 << channel | 0;
  4943. },
  4944. disable: function ( channel ) {
  4945. this.mask &= ~ ( 1 << channel | 0 );
  4946. },
  4947. test: function ( layers ) {
  4948. return ( this.mask & layers.mask ) !== 0;
  4949. }
  4950. } );
  4951. /**
  4952. * @author mrdoob / http://mrdoob.com/
  4953. * @author mikael emtinger / http://gomo.se/
  4954. * @author alteredq / http://alteredqualia.com/
  4955. * @author WestLangley / http://github.com/WestLangley
  4956. * @author elephantatwork / www.elephantatwork.ch
  4957. */
  4958. var object3DId = 0;
  4959. function Object3D() {
  4960. Object.defineProperty( this, 'id', { value: object3DId ++ } );
  4961. this.uuid = _Math.generateUUID();
  4962. this.name = '';
  4963. this.type = 'Object3D';
  4964. this.parent = null;
  4965. this.children = [];
  4966. this.up = Object3D.DefaultUp.clone();
  4967. var position = new Vector3();
  4968. var rotation = new Euler();
  4969. var quaternion = new Quaternion();
  4970. var scale = new Vector3( 1, 1, 1 );
  4971. function onRotationChange() {
  4972. quaternion.setFromEuler( rotation, false );
  4973. }
  4974. function onQuaternionChange() {
  4975. rotation.setFromQuaternion( quaternion, undefined, false );
  4976. }
  4977. rotation.onChange( onRotationChange );
  4978. quaternion.onChange( onQuaternionChange );
  4979. Object.defineProperties( this, {
  4980. position: {
  4981. configurable: true,
  4982. enumerable: true,
  4983. value: position
  4984. },
  4985. rotation: {
  4986. configurable: true,
  4987. enumerable: true,
  4988. value: rotation
  4989. },
  4990. quaternion: {
  4991. configurable: true,
  4992. enumerable: true,
  4993. value: quaternion
  4994. },
  4995. scale: {
  4996. configurable: true,
  4997. enumerable: true,
  4998. value: scale
  4999. },
  5000. modelViewMatrix: {
  5001. value: new Matrix4()
  5002. },
  5003. normalMatrix: {
  5004. value: new Matrix3()
  5005. }
  5006. } );
  5007. this.matrix = new Matrix4();
  5008. this.matrixWorld = new Matrix4();
  5009. this.matrixAutoUpdate = Object3D.DefaultMatrixAutoUpdate;
  5010. this.matrixWorldNeedsUpdate = false;
  5011. this.layers = new Layers();
  5012. this.visible = true;
  5013. this.castShadow = false;
  5014. this.receiveShadow = false;
  5015. this.frustumCulled = true;
  5016. this.renderOrder = 0;
  5017. this.userData = {};
  5018. }
  5019. Object3D.DefaultUp = new Vector3( 0, 1, 0 );
  5020. Object3D.DefaultMatrixAutoUpdate = true;
  5021. Object3D.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  5022. constructor: Object3D,
  5023. isObject3D: true,
  5024. onBeforeRender: function () {},
  5025. onAfterRender: function () {},
  5026. applyMatrix: function ( matrix ) {
  5027. this.matrix.multiplyMatrices( matrix, this.matrix );
  5028. this.matrix.decompose( this.position, this.quaternion, this.scale );
  5029. },
  5030. applyQuaternion: function ( q ) {
  5031. this.quaternion.premultiply( q );
  5032. return this;
  5033. },
  5034. setRotationFromAxisAngle: function ( axis, angle ) {
  5035. // assumes axis is normalized
  5036. this.quaternion.setFromAxisAngle( axis, angle );
  5037. },
  5038. setRotationFromEuler: function ( euler ) {
  5039. this.quaternion.setFromEuler( euler, true );
  5040. },
  5041. setRotationFromMatrix: function ( m ) {
  5042. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  5043. this.quaternion.setFromRotationMatrix( m );
  5044. },
  5045. setRotationFromQuaternion: function ( q ) {
  5046. // assumes q is normalized
  5047. this.quaternion.copy( q );
  5048. },
  5049. rotateOnAxis: function () {
  5050. // rotate object on axis in object space
  5051. // axis is assumed to be normalized
  5052. var q1 = new Quaternion();
  5053. return function rotateOnAxis( axis, angle ) {
  5054. q1.setFromAxisAngle( axis, angle );
  5055. this.quaternion.multiply( q1 );
  5056. return this;
  5057. };
  5058. }(),
  5059. rotateOnWorldAxis: function () {
  5060. // rotate object on axis in world space
  5061. // axis is assumed to be normalized
  5062. // method assumes no rotated parent
  5063. var q1 = new Quaternion();
  5064. return function rotateOnWorldAxis( axis, angle ) {
  5065. q1.setFromAxisAngle( axis, angle );
  5066. this.quaternion.premultiply( q1 );
  5067. return this;
  5068. };
  5069. }(),
  5070. rotateX: function () {
  5071. var v1 = new Vector3( 1, 0, 0 );
  5072. return function rotateX( angle ) {
  5073. return this.rotateOnAxis( v1, angle );
  5074. };
  5075. }(),
  5076. rotateY: function () {
  5077. var v1 = new Vector3( 0, 1, 0 );
  5078. return function rotateY( angle ) {
  5079. return this.rotateOnAxis( v1, angle );
  5080. };
  5081. }(),
  5082. rotateZ: function () {
  5083. var v1 = new Vector3( 0, 0, 1 );
  5084. return function rotateZ( angle ) {
  5085. return this.rotateOnAxis( v1, angle );
  5086. };
  5087. }(),
  5088. translateOnAxis: function () {
  5089. // translate object by distance along axis in object space
  5090. // axis is assumed to be normalized
  5091. var v1 = new Vector3();
  5092. return function translateOnAxis( axis, distance ) {
  5093. v1.copy( axis ).applyQuaternion( this.quaternion );
  5094. this.position.add( v1.multiplyScalar( distance ) );
  5095. return this;
  5096. };
  5097. }(),
  5098. translateX: function () {
  5099. var v1 = new Vector3( 1, 0, 0 );
  5100. return function translateX( distance ) {
  5101. return this.translateOnAxis( v1, distance );
  5102. };
  5103. }(),
  5104. translateY: function () {
  5105. var v1 = new Vector3( 0, 1, 0 );
  5106. return function translateY( distance ) {
  5107. return this.translateOnAxis( v1, distance );
  5108. };
  5109. }(),
  5110. translateZ: function () {
  5111. var v1 = new Vector3( 0, 0, 1 );
  5112. return function translateZ( distance ) {
  5113. return this.translateOnAxis( v1, distance );
  5114. };
  5115. }(),
  5116. localToWorld: function ( vector ) {
  5117. return vector.applyMatrix4( this.matrixWorld );
  5118. },
  5119. worldToLocal: function () {
  5120. var m1 = new Matrix4();
  5121. return function worldToLocal( vector ) {
  5122. return vector.applyMatrix4( m1.getInverse( this.matrixWorld ) );
  5123. };
  5124. }(),
  5125. lookAt: function () {
  5126. // This method does not support objects having non-uniformly-scaled parent(s)
  5127. var q1 = new Quaternion();
  5128. var m1 = new Matrix4();
  5129. var target = new Vector3();
  5130. var position = new Vector3();
  5131. return function lookAt( x, y, z ) {
  5132. if ( x.isVector3 ) {
  5133. target.copy( x );
  5134. } else {
  5135. target.set( x, y, z );
  5136. }
  5137. var parent = this.parent;
  5138. this.updateWorldMatrix( true, false );
  5139. position.setFromMatrixPosition( this.matrixWorld );
  5140. if ( this.isCamera || this.isLight ) {
  5141. m1.lookAt( position, target, this.up );
  5142. } else {
  5143. m1.lookAt( target, position, this.up );
  5144. }
  5145. this.quaternion.setFromRotationMatrix( m1 );
  5146. if ( parent ) {
  5147. m1.extractRotation( parent.matrixWorld );
  5148. q1.setFromRotationMatrix( m1 );
  5149. this.quaternion.premultiply( q1.inverse() );
  5150. }
  5151. };
  5152. }(),
  5153. add: function ( object ) {
  5154. if ( arguments.length > 1 ) {
  5155. for ( var i = 0; i < arguments.length; i ++ ) {
  5156. this.add( arguments[ i ] );
  5157. }
  5158. return this;
  5159. }
  5160. if ( object === this ) {
  5161. console.error( "THREE.Object3D.add: object can't be added as a child of itself.", object );
  5162. return this;
  5163. }
  5164. if ( ( object && object.isObject3D ) ) {
  5165. if ( object.parent !== null ) {
  5166. object.parent.remove( object );
  5167. }
  5168. object.parent = this;
  5169. object.dispatchEvent( { type: 'added' } );
  5170. this.children.push( object );
  5171. } else {
  5172. console.error( "THREE.Object3D.add: object not an instance of THREE.Object3D.", object );
  5173. }
  5174. return this;
  5175. },
  5176. remove: function ( object ) {
  5177. if ( arguments.length > 1 ) {
  5178. for ( var i = 0; i < arguments.length; i ++ ) {
  5179. this.remove( arguments[ i ] );
  5180. }
  5181. return this;
  5182. }
  5183. var index = this.children.indexOf( object );
  5184. if ( index !== - 1 ) {
  5185. object.parent = null;
  5186. object.dispatchEvent( { type: 'removed' } );
  5187. this.children.splice( index, 1 );
  5188. }
  5189. return this;
  5190. },
  5191. getObjectById: function ( id ) {
  5192. return this.getObjectByProperty( 'id', id );
  5193. },
  5194. getObjectByName: function ( name ) {
  5195. return this.getObjectByProperty( 'name', name );
  5196. },
  5197. getObjectByProperty: function ( name, value ) {
  5198. if ( this[ name ] === value ) return this;
  5199. for ( var i = 0, l = this.children.length; i < l; i ++ ) {
  5200. var child = this.children[ i ];
  5201. var object = child.getObjectByProperty( name, value );
  5202. if ( object !== undefined ) {
  5203. return object;
  5204. }
  5205. }
  5206. return undefined;
  5207. },
  5208. getWorldPosition: function ( target ) {
  5209. if ( target === undefined ) {
  5210. console.warn( 'THREE.Object3D: .getWorldPosition() target is now required' );
  5211. target = new Vector3();
  5212. }
  5213. this.updateMatrixWorld( true );
  5214. return target.setFromMatrixPosition( this.matrixWorld );
  5215. },
  5216. getWorldQuaternion: function () {
  5217. var position = new Vector3();
  5218. var scale = new Vector3();
  5219. return function getWorldQuaternion( target ) {
  5220. if ( target === undefined ) {
  5221. console.warn( 'THREE.Object3D: .getWorldQuaternion() target is now required' );
  5222. target = new Quaternion();
  5223. }
  5224. this.updateMatrixWorld( true );
  5225. this.matrixWorld.decompose( position, target, scale );
  5226. return target;
  5227. };
  5228. }(),
  5229. getWorldScale: function () {
  5230. var position = new Vector3();
  5231. var quaternion = new Quaternion();
  5232. return function getWorldScale( target ) {
  5233. if ( target === undefined ) {
  5234. console.warn( 'THREE.Object3D: .getWorldScale() target is now required' );
  5235. target = new Vector3();
  5236. }
  5237. this.updateMatrixWorld( true );
  5238. this.matrixWorld.decompose( position, quaternion, target );
  5239. return target;
  5240. };
  5241. }(),
  5242. getWorldDirection: function ( target ) {
  5243. if ( target === undefined ) {
  5244. console.warn( 'THREE.Object3D: .getWorldDirection() target is now required' );
  5245. target = new Vector3();
  5246. }
  5247. this.updateMatrixWorld( true );
  5248. var e = this.matrixWorld.elements;
  5249. return target.set( e[ 8 ], e[ 9 ], e[ 10 ] ).normalize();
  5250. },
  5251. raycast: function () {},
  5252. traverse: function ( callback ) {
  5253. callback( this );
  5254. var children = this.children;
  5255. for ( var i = 0, l = children.length; i < l; i ++ ) {
  5256. children[ i ].traverse( callback );
  5257. }
  5258. },
  5259. traverseVisible: function ( callback ) {
  5260. if ( this.visible === false ) return;
  5261. callback( this );
  5262. var children = this.children;
  5263. for ( var i = 0, l = children.length; i < l; i ++ ) {
  5264. children[ i ].traverseVisible( callback );
  5265. }
  5266. },
  5267. traverseAncestors: function ( callback ) {
  5268. var parent = this.parent;
  5269. if ( parent !== null ) {
  5270. callback( parent );
  5271. parent.traverseAncestors( callback );
  5272. }
  5273. },
  5274. updateMatrix: function () {
  5275. this.matrix.compose( this.position, this.quaternion, this.scale );
  5276. this.matrixWorldNeedsUpdate = true;
  5277. },
  5278. updateMatrixWorld: function ( force ) {
  5279. if ( this.matrixAutoUpdate ) this.updateMatrix();
  5280. if ( this.matrixWorldNeedsUpdate || force ) {
  5281. if ( this.parent === null ) {
  5282. this.matrixWorld.copy( this.matrix );
  5283. } else {
  5284. this.matrixWorld.multiplyMatrices( this.parent.matrixWorld, this.matrix );
  5285. }
  5286. this.matrixWorldNeedsUpdate = false;
  5287. force = true;
  5288. }
  5289. // update children
  5290. var children = this.children;
  5291. for ( var i = 0, l = children.length; i < l; i ++ ) {
  5292. children[ i ].updateMatrixWorld( force );
  5293. }
  5294. },
  5295. updateWorldMatrix: function ( updateParents, updateChildren ) {
  5296. var parent = this.parent;
  5297. if ( updateParents === true && parent !== null ) {
  5298. parent.updateWorldMatrix( true, false );
  5299. }
  5300. if ( this.matrixAutoUpdate ) this.updateMatrix();
  5301. if ( this.parent === null ) {
  5302. this.matrixWorld.copy( this.matrix );
  5303. } else {
  5304. this.matrixWorld.multiplyMatrices( this.parent.matrixWorld, this.matrix );
  5305. }
  5306. // update children
  5307. if ( updateChildren === true ) {
  5308. var children = this.children;
  5309. for ( var i = 0, l = children.length; i < l; i ++ ) {
  5310. children[ i ].updateWorldMatrix( false, true );
  5311. }
  5312. }
  5313. },
  5314. toJSON: function ( meta ) {
  5315. // meta is a string when called from JSON.stringify
  5316. var isRootObject = ( meta === undefined || typeof meta === 'string' );
  5317. var output = {};
  5318. // meta is a hash used to collect geometries, materials.
  5319. // not providing it implies that this is the root object
  5320. // being serialized.
  5321. if ( isRootObject ) {
  5322. // initialize meta obj
  5323. meta = {
  5324. geometries: {},
  5325. materials: {},
  5326. textures: {},
  5327. images: {},
  5328. shapes: {}
  5329. };
  5330. output.metadata = {
  5331. version: 4.5,
  5332. type: 'Object',
  5333. generator: 'Object3D.toJSON'
  5334. };
  5335. }
  5336. // standard Object3D serialization
  5337. var object = {};
  5338. object.uuid = this.uuid;
  5339. object.type = this.type;
  5340. if ( this.name !== '' ) object.name = this.name;
  5341. if ( this.castShadow === true ) object.castShadow = true;
  5342. if ( this.receiveShadow === true ) object.receiveShadow = true;
  5343. if ( this.visible === false ) object.visible = false;
  5344. if ( this.frustumCulled === false ) object.frustumCulled = false;
  5345. if ( this.renderOrder !== 0 ) object.renderOrder = this.renderOrder;
  5346. if ( JSON.stringify( this.userData ) !== '{}' ) object.userData = this.userData;
  5347. object.layers = this.layers.mask;
  5348. object.matrix = this.matrix.toArray();
  5349. if ( this.matrixAutoUpdate === false ) object.matrixAutoUpdate = false;
  5350. // object specific properties
  5351. if ( this.isMesh && this.drawMode !== TrianglesDrawMode ) object.drawMode = this.drawMode;
  5352. //
  5353. function serialize( library, element ) {
  5354. if ( library[ element.uuid ] === undefined ) {
  5355. library[ element.uuid ] = element.toJSON( meta );
  5356. }
  5357. return element.uuid;
  5358. }
  5359. if ( this.isMesh || this.isLine || this.isPoints ) {
  5360. object.geometry = serialize( meta.geometries, this.geometry );
  5361. var parameters = this.geometry.parameters;
  5362. if ( parameters !== undefined && parameters.shapes !== undefined ) {
  5363. var shapes = parameters.shapes;
  5364. if ( Array.isArray( shapes ) ) {
  5365. for ( var i = 0, l = shapes.length; i < l; i ++ ) {
  5366. var shape = shapes[ i ];
  5367. serialize( meta.shapes, shape );
  5368. }
  5369. } else {
  5370. serialize( meta.shapes, shapes );
  5371. }
  5372. }
  5373. }
  5374. if ( this.material !== undefined ) {
  5375. if ( Array.isArray( this.material ) ) {
  5376. var uuids = [];
  5377. for ( var i = 0, l = this.material.length; i < l; i ++ ) {
  5378. uuids.push( serialize( meta.materials, this.material[ i ] ) );
  5379. }
  5380. object.material = uuids;
  5381. } else {
  5382. object.material = serialize( meta.materials, this.material );
  5383. }
  5384. }
  5385. //
  5386. if ( this.children.length > 0 ) {
  5387. object.children = [];
  5388. for ( var i = 0; i < this.children.length; i ++ ) {
  5389. object.children.push( this.children[ i ].toJSON( meta ).object );
  5390. }
  5391. }
  5392. if ( isRootObject ) {
  5393. var geometries = extractFromCache( meta.geometries );
  5394. var materials = extractFromCache( meta.materials );
  5395. var textures = extractFromCache( meta.textures );
  5396. var images = extractFromCache( meta.images );
  5397. var shapes = extractFromCache( meta.shapes );
  5398. if ( geometries.length > 0 ) output.geometries = geometries;
  5399. if ( materials.length > 0 ) output.materials = materials;
  5400. if ( textures.length > 0 ) output.textures = textures;
  5401. if ( images.length > 0 ) output.images = images;
  5402. if ( shapes.length > 0 ) output.shapes = shapes;
  5403. }
  5404. output.object = object;
  5405. return output;
  5406. // extract data from the cache hash
  5407. // remove metadata on each item
  5408. // and return as array
  5409. function extractFromCache( cache ) {
  5410. var values = [];
  5411. for ( var key in cache ) {
  5412. var data = cache[ key ];
  5413. delete data.metadata;
  5414. values.push( data );
  5415. }
  5416. return values;
  5417. }
  5418. },
  5419. clone: function ( recursive ) {
  5420. return new this.constructor().copy( this, recursive );
  5421. },
  5422. copy: function ( source, recursive ) {
  5423. if ( recursive === undefined ) recursive = true;
  5424. this.name = source.name;
  5425. this.up.copy( source.up );
  5426. this.position.copy( source.position );
  5427. this.quaternion.copy( source.quaternion );
  5428. this.scale.copy( source.scale );
  5429. this.matrix.copy( source.matrix );
  5430. this.matrixWorld.copy( source.matrixWorld );
  5431. this.matrixAutoUpdate = source.matrixAutoUpdate;
  5432. this.matrixWorldNeedsUpdate = source.matrixWorldNeedsUpdate;
  5433. this.layers.mask = source.layers.mask;
  5434. this.visible = source.visible;
  5435. this.castShadow = source.castShadow;
  5436. this.receiveShadow = source.receiveShadow;
  5437. this.frustumCulled = source.frustumCulled;
  5438. this.renderOrder = source.renderOrder;
  5439. this.userData = JSON.parse( JSON.stringify( source.userData ) );
  5440. if ( recursive === true ) {
  5441. for ( var i = 0; i < source.children.length; i ++ ) {
  5442. var child = source.children[ i ];
  5443. this.add( child.clone() );
  5444. }
  5445. }
  5446. return this;
  5447. }
  5448. } );
  5449. /**
  5450. * @author mrdoob / http://mrdoob.com/
  5451. * @author kile / http://kile.stravaganza.org/
  5452. * @author alteredq / http://alteredqualia.com/
  5453. * @author mikael emtinger / http://gomo.se/
  5454. * @author zz85 / http://www.lab4games.net/zz85/blog
  5455. * @author bhouston / http://clara.io
  5456. */
  5457. var geometryId = 0; // Geometry uses even numbers as Id
  5458. function Geometry() {
  5459. Object.defineProperty( this, 'id', { value: geometryId += 2 } );
  5460. this.uuid = _Math.generateUUID();
  5461. this.name = '';
  5462. this.type = 'Geometry';
  5463. this.vertices = [];
  5464. this.colors = [];
  5465. this.faces = [];
  5466. this.faceVertexUvs = [[]];
  5467. this.morphTargets = [];
  5468. this.morphNormals = [];
  5469. this.skinWeights = [];
  5470. this.skinIndices = [];
  5471. this.lineDistances = [];
  5472. this.boundingBox = null;
  5473. this.boundingSphere = null;
  5474. // update flags
  5475. this.elementsNeedUpdate = false;
  5476. this.verticesNeedUpdate = false;
  5477. this.uvsNeedUpdate = false;
  5478. this.normalsNeedUpdate = false;
  5479. this.colorsNeedUpdate = false;
  5480. this.lineDistancesNeedUpdate = false;
  5481. this.groupsNeedUpdate = false;
  5482. }
  5483. Geometry.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  5484. constructor: Geometry,
  5485. isGeometry: true,
  5486. applyMatrix: function ( matrix ) {
  5487. var normalMatrix = new Matrix3().getNormalMatrix( matrix );
  5488. for ( var i = 0, il = this.vertices.length; i < il; i ++ ) {
  5489. var vertex = this.vertices[ i ];
  5490. vertex.applyMatrix4( matrix );
  5491. }
  5492. for ( var i = 0, il = this.faces.length; i < il; i ++ ) {
  5493. var face = this.faces[ i ];
  5494. face.normal.applyMatrix3( normalMatrix ).normalize();
  5495. for ( var j = 0, jl = face.vertexNormals.length; j < jl; j ++ ) {
  5496. face.vertexNormals[ j ].applyMatrix3( normalMatrix ).normalize();
  5497. }
  5498. }
  5499. if ( this.boundingBox !== null ) {
  5500. this.computeBoundingBox();
  5501. }
  5502. if ( this.boundingSphere !== null ) {
  5503. this.computeBoundingSphere();
  5504. }
  5505. this.verticesNeedUpdate = true;
  5506. this.normalsNeedUpdate = true;
  5507. return this;
  5508. },
  5509. rotateX: function () {
  5510. // rotate geometry around world x-axis
  5511. var m1 = new Matrix4();
  5512. return function rotateX( angle ) {
  5513. m1.makeRotationX( angle );
  5514. this.applyMatrix( m1 );
  5515. return this;
  5516. };
  5517. }(),
  5518. rotateY: function () {
  5519. // rotate geometry around world y-axis
  5520. var m1 = new Matrix4();
  5521. return function rotateY( angle ) {
  5522. m1.makeRotationY( angle );
  5523. this.applyMatrix( m1 );
  5524. return this;
  5525. };
  5526. }(),
  5527. rotateZ: function () {
  5528. // rotate geometry around world z-axis
  5529. var m1 = new Matrix4();
  5530. return function rotateZ( angle ) {
  5531. m1.makeRotationZ( angle );
  5532. this.applyMatrix( m1 );
  5533. return this;
  5534. };
  5535. }(),
  5536. translate: function () {
  5537. // translate geometry
  5538. var m1 = new Matrix4();
  5539. return function translate( x, y, z ) {
  5540. m1.makeTranslation( x, y, z );
  5541. this.applyMatrix( m1 );
  5542. return this;
  5543. };
  5544. }(),
  5545. scale: function () {
  5546. // scale geometry
  5547. var m1 = new Matrix4();
  5548. return function scale( x, y, z ) {
  5549. m1.makeScale( x, y, z );
  5550. this.applyMatrix( m1 );
  5551. return this;
  5552. };
  5553. }(),
  5554. lookAt: function () {
  5555. var obj = new Object3D();
  5556. return function lookAt( vector ) {
  5557. obj.lookAt( vector );
  5558. obj.updateMatrix();
  5559. this.applyMatrix( obj.matrix );
  5560. };
  5561. }(),
  5562. fromBufferGeometry: function ( geometry ) {
  5563. var scope = this;
  5564. var indices = geometry.index !== null ? geometry.index.array : undefined;
  5565. var attributes = geometry.attributes;
  5566. var positions = attributes.position.array;
  5567. var normals = attributes.normal !== undefined ? attributes.normal.array : undefined;
  5568. var colors = attributes.color !== undefined ? attributes.color.array : undefined;
  5569. var uvs = attributes.uv !== undefined ? attributes.uv.array : undefined;
  5570. var uvs2 = attributes.uv2 !== undefined ? attributes.uv2.array : undefined;
  5571. if ( uvs2 !== undefined ) this.faceVertexUvs[ 1 ] = [];
  5572. for ( var i = 0, j = 0; i < positions.length; i += 3, j += 2 ) {
  5573. scope.vertices.push( new Vector3().fromArray( positions, i ) );
  5574. if ( colors !== undefined ) {
  5575. scope.colors.push( new Color().fromArray( colors, i ) );
  5576. }
  5577. }
  5578. function addFace( a, b, c, materialIndex ) {
  5579. var vertexColors = ( colors === undefined ) ? [] : [
  5580. scope.colors[ a ].clone(),
  5581. scope.colors[ b ].clone(),
  5582. scope.colors[ c ].clone() ];
  5583. var vertexNormals = ( normals === undefined ) ? [] : [
  5584. new Vector3().fromArray( normals, a * 3 ),
  5585. new Vector3().fromArray( normals, b * 3 ),
  5586. new Vector3().fromArray( normals, c * 3 )
  5587. ];
  5588. var face = new Face3( a, b, c, vertexNormals, vertexColors, materialIndex );
  5589. scope.faces.push( face );
  5590. if ( uvs !== undefined ) {
  5591. scope.faceVertexUvs[ 0 ].push( [
  5592. new Vector2().fromArray( uvs, a * 2 ),
  5593. new Vector2().fromArray( uvs, b * 2 ),
  5594. new Vector2().fromArray( uvs, c * 2 )
  5595. ] );
  5596. }
  5597. if ( uvs2 !== undefined ) {
  5598. scope.faceVertexUvs[ 1 ].push( [
  5599. new Vector2().fromArray( uvs2, a * 2 ),
  5600. new Vector2().fromArray( uvs2, b * 2 ),
  5601. new Vector2().fromArray( uvs2, c * 2 )
  5602. ] );
  5603. }
  5604. }
  5605. var groups = geometry.groups;
  5606. if ( groups.length > 0 ) {
  5607. for ( var i = 0; i < groups.length; i ++ ) {
  5608. var group = groups[ i ];
  5609. var start = group.start;
  5610. var count = group.count;
  5611. for ( var j = start, jl = start + count; j < jl; j += 3 ) {
  5612. if ( indices !== undefined ) {
  5613. addFace( indices[ j ], indices[ j + 1 ], indices[ j + 2 ], group.materialIndex );
  5614. } else {
  5615. addFace( j, j + 1, j + 2, group.materialIndex );
  5616. }
  5617. }
  5618. }
  5619. } else {
  5620. if ( indices !== undefined ) {
  5621. for ( var i = 0; i < indices.length; i += 3 ) {
  5622. addFace( indices[ i ], indices[ i + 1 ], indices[ i + 2 ] );
  5623. }
  5624. } else {
  5625. for ( var i = 0; i < positions.length / 3; i += 3 ) {
  5626. addFace( i, i + 1, i + 2 );
  5627. }
  5628. }
  5629. }
  5630. this.computeFaceNormals();
  5631. if ( geometry.boundingBox !== null ) {
  5632. this.boundingBox = geometry.boundingBox.clone();
  5633. }
  5634. if ( geometry.boundingSphere !== null ) {
  5635. this.boundingSphere = geometry.boundingSphere.clone();
  5636. }
  5637. return this;
  5638. },
  5639. center: function () {
  5640. var offset = new Vector3();
  5641. return function center() {
  5642. this.computeBoundingBox();
  5643. this.boundingBox.getCenter( offset ).negate();
  5644. this.translate( offset.x, offset.y, offset.z );
  5645. return this;
  5646. };
  5647. }(),
  5648. normalize: function () {
  5649. this.computeBoundingSphere();
  5650. var center = this.boundingSphere.center;
  5651. var radius = this.boundingSphere.radius;
  5652. var s = radius === 0 ? 1 : 1.0 / radius;
  5653. var matrix = new Matrix4();
  5654. matrix.set(
  5655. s, 0, 0, - s * center.x,
  5656. 0, s, 0, - s * center.y,
  5657. 0, 0, s, - s * center.z,
  5658. 0, 0, 0, 1
  5659. );
  5660. this.applyMatrix( matrix );
  5661. return this;
  5662. },
  5663. computeFaceNormals: function () {
  5664. var cb = new Vector3(), ab = new Vector3();
  5665. for ( var f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5666. var face = this.faces[ f ];
  5667. var vA = this.vertices[ face.a ];
  5668. var vB = this.vertices[ face.b ];
  5669. var vC = this.vertices[ face.c ];
  5670. cb.subVectors( vC, vB );
  5671. ab.subVectors( vA, vB );
  5672. cb.cross( ab );
  5673. cb.normalize();
  5674. face.normal.copy( cb );
  5675. }
  5676. },
  5677. computeVertexNormals: function ( areaWeighted ) {
  5678. if ( areaWeighted === undefined ) areaWeighted = true;
  5679. var v, vl, f, fl, face, vertices;
  5680. vertices = new Array( this.vertices.length );
  5681. for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) {
  5682. vertices[ v ] = new Vector3();
  5683. }
  5684. if ( areaWeighted ) {
  5685. // vertex normals weighted by triangle areas
  5686. // http://www.iquilezles.org/www/articles/normals/normals.htm
  5687. var vA, vB, vC;
  5688. var cb = new Vector3(), ab = new Vector3();
  5689. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5690. face = this.faces[ f ];
  5691. vA = this.vertices[ face.a ];
  5692. vB = this.vertices[ face.b ];
  5693. vC = this.vertices[ face.c ];
  5694. cb.subVectors( vC, vB );
  5695. ab.subVectors( vA, vB );
  5696. cb.cross( ab );
  5697. vertices[ face.a ].add( cb );
  5698. vertices[ face.b ].add( cb );
  5699. vertices[ face.c ].add( cb );
  5700. }
  5701. } else {
  5702. this.computeFaceNormals();
  5703. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5704. face = this.faces[ f ];
  5705. vertices[ face.a ].add( face.normal );
  5706. vertices[ face.b ].add( face.normal );
  5707. vertices[ face.c ].add( face.normal );
  5708. }
  5709. }
  5710. for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) {
  5711. vertices[ v ].normalize();
  5712. }
  5713. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5714. face = this.faces[ f ];
  5715. var vertexNormals = face.vertexNormals;
  5716. if ( vertexNormals.length === 3 ) {
  5717. vertexNormals[ 0 ].copy( vertices[ face.a ] );
  5718. vertexNormals[ 1 ].copy( vertices[ face.b ] );
  5719. vertexNormals[ 2 ].copy( vertices[ face.c ] );
  5720. } else {
  5721. vertexNormals[ 0 ] = vertices[ face.a ].clone();
  5722. vertexNormals[ 1 ] = vertices[ face.b ].clone();
  5723. vertexNormals[ 2 ] = vertices[ face.c ].clone();
  5724. }
  5725. }
  5726. if ( this.faces.length > 0 ) {
  5727. this.normalsNeedUpdate = true;
  5728. }
  5729. },
  5730. computeFlatVertexNormals: function () {
  5731. var f, fl, face;
  5732. this.computeFaceNormals();
  5733. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5734. face = this.faces[ f ];
  5735. var vertexNormals = face.vertexNormals;
  5736. if ( vertexNormals.length === 3 ) {
  5737. vertexNormals[ 0 ].copy( face.normal );
  5738. vertexNormals[ 1 ].copy( face.normal );
  5739. vertexNormals[ 2 ].copy( face.normal );
  5740. } else {
  5741. vertexNormals[ 0 ] = face.normal.clone();
  5742. vertexNormals[ 1 ] = face.normal.clone();
  5743. vertexNormals[ 2 ] = face.normal.clone();
  5744. }
  5745. }
  5746. if ( this.faces.length > 0 ) {
  5747. this.normalsNeedUpdate = true;
  5748. }
  5749. },
  5750. computeMorphNormals: function () {
  5751. var i, il, f, fl, face;
  5752. // save original normals
  5753. // - create temp variables on first access
  5754. // otherwise just copy (for faster repeated calls)
  5755. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5756. face = this.faces[ f ];
  5757. if ( ! face.__originalFaceNormal ) {
  5758. face.__originalFaceNormal = face.normal.clone();
  5759. } else {
  5760. face.__originalFaceNormal.copy( face.normal );
  5761. }
  5762. if ( ! face.__originalVertexNormals ) face.__originalVertexNormals = [];
  5763. for ( i = 0, il = face.vertexNormals.length; i < il; i ++ ) {
  5764. if ( ! face.__originalVertexNormals[ i ] ) {
  5765. face.__originalVertexNormals[ i ] = face.vertexNormals[ i ].clone();
  5766. } else {
  5767. face.__originalVertexNormals[ i ].copy( face.vertexNormals[ i ] );
  5768. }
  5769. }
  5770. }
  5771. // use temp geometry to compute face and vertex normals for each morph
  5772. var tmpGeo = new Geometry();
  5773. tmpGeo.faces = this.faces;
  5774. for ( i = 0, il = this.morphTargets.length; i < il; i ++ ) {
  5775. // create on first access
  5776. if ( ! this.morphNormals[ i ] ) {
  5777. this.morphNormals[ i ] = {};
  5778. this.morphNormals[ i ].faceNormals = [];
  5779. this.morphNormals[ i ].vertexNormals = [];
  5780. var dstNormalsFace = this.morphNormals[ i ].faceNormals;
  5781. var dstNormalsVertex = this.morphNormals[ i ].vertexNormals;
  5782. var faceNormal, vertexNormals;
  5783. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5784. faceNormal = new Vector3();
  5785. vertexNormals = { a: new Vector3(), b: new Vector3(), c: new Vector3() };
  5786. dstNormalsFace.push( faceNormal );
  5787. dstNormalsVertex.push( vertexNormals );
  5788. }
  5789. }
  5790. var morphNormals = this.morphNormals[ i ];
  5791. // set vertices to morph target
  5792. tmpGeo.vertices = this.morphTargets[ i ].vertices;
  5793. // compute morph normals
  5794. tmpGeo.computeFaceNormals();
  5795. tmpGeo.computeVertexNormals();
  5796. // store morph normals
  5797. var faceNormal, vertexNormals;
  5798. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5799. face = this.faces[ f ];
  5800. faceNormal = morphNormals.faceNormals[ f ];
  5801. vertexNormals = morphNormals.vertexNormals[ f ];
  5802. faceNormal.copy( face.normal );
  5803. vertexNormals.a.copy( face.vertexNormals[ 0 ] );
  5804. vertexNormals.b.copy( face.vertexNormals[ 1 ] );
  5805. vertexNormals.c.copy( face.vertexNormals[ 2 ] );
  5806. }
  5807. }
  5808. // restore original normals
  5809. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5810. face = this.faces[ f ];
  5811. face.normal = face.__originalFaceNormal;
  5812. face.vertexNormals = face.__originalVertexNormals;
  5813. }
  5814. },
  5815. computeBoundingBox: function () {
  5816. if ( this.boundingBox === null ) {
  5817. this.boundingBox = new Box3();
  5818. }
  5819. this.boundingBox.setFromPoints( this.vertices );
  5820. },
  5821. computeBoundingSphere: function () {
  5822. if ( this.boundingSphere === null ) {
  5823. this.boundingSphere = new Sphere();
  5824. }
  5825. this.boundingSphere.setFromPoints( this.vertices );
  5826. },
  5827. merge: function ( geometry, matrix, materialIndexOffset ) {
  5828. if ( ! ( geometry && geometry.isGeometry ) ) {
  5829. console.error( 'THREE.Geometry.merge(): geometry not an instance of THREE.Geometry.', geometry );
  5830. return;
  5831. }
  5832. var normalMatrix,
  5833. vertexOffset = this.vertices.length,
  5834. vertices1 = this.vertices,
  5835. vertices2 = geometry.vertices,
  5836. faces1 = this.faces,
  5837. faces2 = geometry.faces,
  5838. uvs1 = this.faceVertexUvs[ 0 ],
  5839. uvs2 = geometry.faceVertexUvs[ 0 ],
  5840. colors1 = this.colors,
  5841. colors2 = geometry.colors;
  5842. if ( materialIndexOffset === undefined ) materialIndexOffset = 0;
  5843. if ( matrix !== undefined ) {
  5844. normalMatrix = new Matrix3().getNormalMatrix( matrix );
  5845. }
  5846. // vertices
  5847. for ( var i = 0, il = vertices2.length; i < il; i ++ ) {
  5848. var vertex = vertices2[ i ];
  5849. var vertexCopy = vertex.clone();
  5850. if ( matrix !== undefined ) vertexCopy.applyMatrix4( matrix );
  5851. vertices1.push( vertexCopy );
  5852. }
  5853. // colors
  5854. for ( var i = 0, il = colors2.length; i < il; i ++ ) {
  5855. colors1.push( colors2[ i ].clone() );
  5856. }
  5857. // faces
  5858. for ( i = 0, il = faces2.length; i < il; i ++ ) {
  5859. var face = faces2[ i ], faceCopy, normal, color,
  5860. faceVertexNormals = face.vertexNormals,
  5861. faceVertexColors = face.vertexColors;
  5862. faceCopy = new Face3( face.a + vertexOffset, face.b + vertexOffset, face.c + vertexOffset );
  5863. faceCopy.normal.copy( face.normal );
  5864. if ( normalMatrix !== undefined ) {
  5865. faceCopy.normal.applyMatrix3( normalMatrix ).normalize();
  5866. }
  5867. for ( var j = 0, jl = faceVertexNormals.length; j < jl; j ++ ) {
  5868. normal = faceVertexNormals[ j ].clone();
  5869. if ( normalMatrix !== undefined ) {
  5870. normal.applyMatrix3( normalMatrix ).normalize();
  5871. }
  5872. faceCopy.vertexNormals.push( normal );
  5873. }
  5874. faceCopy.color.copy( face.color );
  5875. for ( var j = 0, jl = faceVertexColors.length; j < jl; j ++ ) {
  5876. color = faceVertexColors[ j ];
  5877. faceCopy.vertexColors.push( color.clone() );
  5878. }
  5879. faceCopy.materialIndex = face.materialIndex + materialIndexOffset;
  5880. faces1.push( faceCopy );
  5881. }
  5882. // uvs
  5883. for ( i = 0, il = uvs2.length; i < il; i ++ ) {
  5884. var uv = uvs2[ i ], uvCopy = [];
  5885. if ( uv === undefined ) {
  5886. continue;
  5887. }
  5888. for ( var j = 0, jl = uv.length; j < jl; j ++ ) {
  5889. uvCopy.push( uv[ j ].clone() );
  5890. }
  5891. uvs1.push( uvCopy );
  5892. }
  5893. },
  5894. mergeMesh: function ( mesh ) {
  5895. if ( ! ( mesh && mesh.isMesh ) ) {
  5896. console.error( 'THREE.Geometry.mergeMesh(): mesh not an instance of THREE.Mesh.', mesh );
  5897. return;
  5898. }
  5899. if ( mesh.matrixAutoUpdate ) mesh.updateMatrix();
  5900. this.merge( mesh.geometry, mesh.matrix );
  5901. },
  5902. /*
  5903. * Checks for duplicate vertices with hashmap.
  5904. * Duplicated vertices are removed
  5905. * and faces' vertices are updated.
  5906. */
  5907. mergeVertices: function () {
  5908. var verticesMap = {}; // Hashmap for looking up vertices by position coordinates (and making sure they are unique)
  5909. var unique = [], changes = [];
  5910. var v, key;
  5911. var precisionPoints = 4; // number of decimal points, e.g. 4 for epsilon of 0.0001
  5912. var precision = Math.pow( 10, precisionPoints );
  5913. var i, il, face;
  5914. var indices, j, jl;
  5915. for ( i = 0, il = this.vertices.length; i < il; i ++ ) {
  5916. v = this.vertices[ i ];
  5917. key = Math.round( v.x * precision ) + '_' + Math.round( v.y * precision ) + '_' + Math.round( v.z * precision );
  5918. if ( verticesMap[ key ] === undefined ) {
  5919. verticesMap[ key ] = i;
  5920. unique.push( this.vertices[ i ] );
  5921. changes[ i ] = unique.length - 1;
  5922. } else {
  5923. //console.log('Duplicate vertex found. ', i, ' could be using ', verticesMap[key]);
  5924. changes[ i ] = changes[ verticesMap[ key ] ];
  5925. }
  5926. }
  5927. // if faces are completely degenerate after merging vertices, we
  5928. // have to remove them from the geometry.
  5929. var faceIndicesToRemove = [];
  5930. for ( i = 0, il = this.faces.length; i < il; i ++ ) {
  5931. face = this.faces[ i ];
  5932. face.a = changes[ face.a ];
  5933. face.b = changes[ face.b ];
  5934. face.c = changes[ face.c ];
  5935. indices = [ face.a, face.b, face.c ];
  5936. // if any duplicate vertices are found in a Face3
  5937. // we have to remove the face as nothing can be saved
  5938. for ( var n = 0; n < 3; n ++ ) {
  5939. if ( indices[ n ] === indices[ ( n + 1 ) % 3 ] ) {
  5940. faceIndicesToRemove.push( i );
  5941. break;
  5942. }
  5943. }
  5944. }
  5945. for ( i = faceIndicesToRemove.length - 1; i >= 0; i -- ) {
  5946. var idx = faceIndicesToRemove[ i ];
  5947. this.faces.splice( idx, 1 );
  5948. for ( j = 0, jl = this.faceVertexUvs.length; j < jl; j ++ ) {
  5949. this.faceVertexUvs[ j ].splice( idx, 1 );
  5950. }
  5951. }
  5952. // Use unique set of vertices
  5953. var diff = this.vertices.length - unique.length;
  5954. this.vertices = unique;
  5955. return diff;
  5956. },
  5957. setFromPoints: function ( points ) {
  5958. this.vertices = [];
  5959. for ( var i = 0, l = points.length; i < l; i ++ ) {
  5960. var point = points[ i ];
  5961. this.vertices.push( new Vector3( point.x, point.y, point.z || 0 ) );
  5962. }
  5963. return this;
  5964. },
  5965. sortFacesByMaterialIndex: function () {
  5966. var faces = this.faces;
  5967. var length = faces.length;
  5968. // tag faces
  5969. for ( var i = 0; i < length; i ++ ) {
  5970. faces[ i ]._id = i;
  5971. }
  5972. // sort faces
  5973. function materialIndexSort( a, b ) {
  5974. return a.materialIndex - b.materialIndex;
  5975. }
  5976. faces.sort( materialIndexSort );
  5977. // sort uvs
  5978. var uvs1 = this.faceVertexUvs[ 0 ];
  5979. var uvs2 = this.faceVertexUvs[ 1 ];
  5980. var newUvs1, newUvs2;
  5981. if ( uvs1 && uvs1.length === length ) newUvs1 = [];
  5982. if ( uvs2 && uvs2.length === length ) newUvs2 = [];
  5983. for ( var i = 0; i < length; i ++ ) {
  5984. var id = faces[ i ]._id;
  5985. if ( newUvs1 ) newUvs1.push( uvs1[ id ] );
  5986. if ( newUvs2 ) newUvs2.push( uvs2[ id ] );
  5987. }
  5988. if ( newUvs1 ) this.faceVertexUvs[ 0 ] = newUvs1;
  5989. if ( newUvs2 ) this.faceVertexUvs[ 1 ] = newUvs2;
  5990. },
  5991. toJSON: function () {
  5992. var data = {
  5993. metadata: {
  5994. version: 4.5,
  5995. type: 'Geometry',
  5996. generator: 'Geometry.toJSON'
  5997. }
  5998. };
  5999. // standard Geometry serialization
  6000. data.uuid = this.uuid;
  6001. data.type = this.type;
  6002. if ( this.name !== '' ) data.name = this.name;
  6003. if ( this.parameters !== undefined ) {
  6004. var parameters = this.parameters;
  6005. for ( var key in parameters ) {
  6006. if ( parameters[ key ] !== undefined ) data[ key ] = parameters[ key ];
  6007. }
  6008. return data;
  6009. }
  6010. var vertices = [];
  6011. for ( var i = 0; i < this.vertices.length; i ++ ) {
  6012. var vertex = this.vertices[ i ];
  6013. vertices.push( vertex.x, vertex.y, vertex.z );
  6014. }
  6015. var faces = [];
  6016. var normals = [];
  6017. var normalsHash = {};
  6018. var colors = [];
  6019. var colorsHash = {};
  6020. var uvs = [];
  6021. var uvsHash = {};
  6022. for ( var i = 0; i < this.faces.length; i ++ ) {
  6023. var face = this.faces[ i ];
  6024. var hasMaterial = true;
  6025. var hasFaceUv = false; // deprecated
  6026. var hasFaceVertexUv = this.faceVertexUvs[ 0 ][ i ] !== undefined;
  6027. var hasFaceNormal = face.normal.length() > 0;
  6028. var hasFaceVertexNormal = face.vertexNormals.length > 0;
  6029. var hasFaceColor = face.color.r !== 1 || face.color.g !== 1 || face.color.b !== 1;
  6030. var hasFaceVertexColor = face.vertexColors.length > 0;
  6031. var faceType = 0;
  6032. faceType = setBit( faceType, 0, 0 ); // isQuad
  6033. faceType = setBit( faceType, 1, hasMaterial );
  6034. faceType = setBit( faceType, 2, hasFaceUv );
  6035. faceType = setBit( faceType, 3, hasFaceVertexUv );
  6036. faceType = setBit( faceType, 4, hasFaceNormal );
  6037. faceType = setBit( faceType, 5, hasFaceVertexNormal );
  6038. faceType = setBit( faceType, 6, hasFaceColor );
  6039. faceType = setBit( faceType, 7, hasFaceVertexColor );
  6040. faces.push( faceType );
  6041. faces.push( face.a, face.b, face.c );
  6042. faces.push( face.materialIndex );
  6043. if ( hasFaceVertexUv ) {
  6044. var faceVertexUvs = this.faceVertexUvs[ 0 ][ i ];
  6045. faces.push(
  6046. getUvIndex( faceVertexUvs[ 0 ] ),
  6047. getUvIndex( faceVertexUvs[ 1 ] ),
  6048. getUvIndex( faceVertexUvs[ 2 ] )
  6049. );
  6050. }
  6051. if ( hasFaceNormal ) {
  6052. faces.push( getNormalIndex( face.normal ) );
  6053. }
  6054. if ( hasFaceVertexNormal ) {
  6055. var vertexNormals = face.vertexNormals;
  6056. faces.push(
  6057. getNormalIndex( vertexNormals[ 0 ] ),
  6058. getNormalIndex( vertexNormals[ 1 ] ),
  6059. getNormalIndex( vertexNormals[ 2 ] )
  6060. );
  6061. }
  6062. if ( hasFaceColor ) {
  6063. faces.push( getColorIndex( face.color ) );
  6064. }
  6065. if ( hasFaceVertexColor ) {
  6066. var vertexColors = face.vertexColors;
  6067. faces.push(
  6068. getColorIndex( vertexColors[ 0 ] ),
  6069. getColorIndex( vertexColors[ 1 ] ),
  6070. getColorIndex( vertexColors[ 2 ] )
  6071. );
  6072. }
  6073. }
  6074. function setBit( value, position, enabled ) {
  6075. return enabled ? value | ( 1 << position ) : value & ( ~ ( 1 << position ) );
  6076. }
  6077. function getNormalIndex( normal ) {
  6078. var hash = normal.x.toString() + normal.y.toString() + normal.z.toString();
  6079. if ( normalsHash[ hash ] !== undefined ) {
  6080. return normalsHash[ hash ];
  6081. }
  6082. normalsHash[ hash ] = normals.length / 3;
  6083. normals.push( normal.x, normal.y, normal.z );
  6084. return normalsHash[ hash ];
  6085. }
  6086. function getColorIndex( color ) {
  6087. var hash = color.r.toString() + color.g.toString() + color.b.toString();
  6088. if ( colorsHash[ hash ] !== undefined ) {
  6089. return colorsHash[ hash ];
  6090. }
  6091. colorsHash[ hash ] = colors.length;
  6092. colors.push( color.getHex() );
  6093. return colorsHash[ hash ];
  6094. }
  6095. function getUvIndex( uv ) {
  6096. var hash = uv.x.toString() + uv.y.toString();
  6097. if ( uvsHash[ hash ] !== undefined ) {
  6098. return uvsHash[ hash ];
  6099. }
  6100. uvsHash[ hash ] = uvs.length / 2;
  6101. uvs.push( uv.x, uv.y );
  6102. return uvsHash[ hash ];
  6103. }
  6104. data.data = {};
  6105. data.data.vertices = vertices;
  6106. data.data.normals = normals;
  6107. if ( colors.length > 0 ) data.data.colors = colors;
  6108. if ( uvs.length > 0 ) data.data.uvs = [ uvs ]; // temporal backward compatibility
  6109. data.data.faces = faces;
  6110. return data;
  6111. },
  6112. clone: function () {
  6113. /*
  6114. // Handle primitives
  6115. var parameters = this.parameters;
  6116. if ( parameters !== undefined ) {
  6117. var values = [];
  6118. for ( var key in parameters ) {
  6119. values.push( parameters[ key ] );
  6120. }
  6121. var geometry = Object.create( this.constructor.prototype );
  6122. this.constructor.apply( geometry, values );
  6123. return geometry;
  6124. }
  6125. return new this.constructor().copy( this );
  6126. */
  6127. return new Geometry().copy( this );
  6128. },
  6129. copy: function ( source ) {
  6130. var i, il, j, jl, k, kl;
  6131. // reset
  6132. this.vertices = [];
  6133. this.colors = [];
  6134. this.faces = [];
  6135. this.faceVertexUvs = [[]];
  6136. this.morphTargets = [];
  6137. this.morphNormals = [];
  6138. this.skinWeights = [];
  6139. this.skinIndices = [];
  6140. this.lineDistances = [];
  6141. this.boundingBox = null;
  6142. this.boundingSphere = null;
  6143. // name
  6144. this.name = source.name;
  6145. // vertices
  6146. var vertices = source.vertices;
  6147. for ( i = 0, il = vertices.length; i < il; i ++ ) {
  6148. this.vertices.push( vertices[ i ].clone() );
  6149. }
  6150. // colors
  6151. var colors = source.colors;
  6152. for ( i = 0, il = colors.length; i < il; i ++ ) {
  6153. this.colors.push( colors[ i ].clone() );
  6154. }
  6155. // faces
  6156. var faces = source.faces;
  6157. for ( i = 0, il = faces.length; i < il; i ++ ) {
  6158. this.faces.push( faces[ i ].clone() );
  6159. }
  6160. // face vertex uvs
  6161. for ( i = 0, il = source.faceVertexUvs.length; i < il; i ++ ) {
  6162. var faceVertexUvs = source.faceVertexUvs[ i ];
  6163. if ( this.faceVertexUvs[ i ] === undefined ) {
  6164. this.faceVertexUvs[ i ] = [];
  6165. }
  6166. for ( j = 0, jl = faceVertexUvs.length; j < jl; j ++ ) {
  6167. var uvs = faceVertexUvs[ j ], uvsCopy = [];
  6168. for ( k = 0, kl = uvs.length; k < kl; k ++ ) {
  6169. var uv = uvs[ k ];
  6170. uvsCopy.push( uv.clone() );
  6171. }
  6172. this.faceVertexUvs[ i ].push( uvsCopy );
  6173. }
  6174. }
  6175. // morph targets
  6176. var morphTargets = source.morphTargets;
  6177. for ( i = 0, il = morphTargets.length; i < il; i ++ ) {
  6178. var morphTarget = {};
  6179. morphTarget.name = morphTargets[ i ].name;
  6180. // vertices
  6181. if ( morphTargets[ i ].vertices !== undefined ) {
  6182. morphTarget.vertices = [];
  6183. for ( j = 0, jl = morphTargets[ i ].vertices.length; j < jl; j ++ ) {
  6184. morphTarget.vertices.push( morphTargets[ i ].vertices[ j ].clone() );
  6185. }
  6186. }
  6187. // normals
  6188. if ( morphTargets[ i ].normals !== undefined ) {
  6189. morphTarget.normals = [];
  6190. for ( j = 0, jl = morphTargets[ i ].normals.length; j < jl; j ++ ) {
  6191. morphTarget.normals.push( morphTargets[ i ].normals[ j ].clone() );
  6192. }
  6193. }
  6194. this.morphTargets.push( morphTarget );
  6195. }
  6196. // morph normals
  6197. var morphNormals = source.morphNormals;
  6198. for ( i = 0, il = morphNormals.length; i < il; i ++ ) {
  6199. var morphNormal = {};
  6200. // vertex normals
  6201. if ( morphNormals[ i ].vertexNormals !== undefined ) {
  6202. morphNormal.vertexNormals = [];
  6203. for ( j = 0, jl = morphNormals[ i ].vertexNormals.length; j < jl; j ++ ) {
  6204. var srcVertexNormal = morphNormals[ i ].vertexNormals[ j ];
  6205. var destVertexNormal = {};
  6206. destVertexNormal.a = srcVertexNormal.a.clone();
  6207. destVertexNormal.b = srcVertexNormal.b.clone();
  6208. destVertexNormal.c = srcVertexNormal.c.clone();
  6209. morphNormal.vertexNormals.push( destVertexNormal );
  6210. }
  6211. }
  6212. // face normals
  6213. if ( morphNormals[ i ].faceNormals !== undefined ) {
  6214. morphNormal.faceNormals = [];
  6215. for ( j = 0, jl = morphNormals[ i ].faceNormals.length; j < jl; j ++ ) {
  6216. morphNormal.faceNormals.push( morphNormals[ i ].faceNormals[ j ].clone() );
  6217. }
  6218. }
  6219. this.morphNormals.push( morphNormal );
  6220. }
  6221. // skin weights
  6222. var skinWeights = source.skinWeights;
  6223. for ( i = 0, il = skinWeights.length; i < il; i ++ ) {
  6224. this.skinWeights.push( skinWeights[ i ].clone() );
  6225. }
  6226. // skin indices
  6227. var skinIndices = source.skinIndices;
  6228. for ( i = 0, il = skinIndices.length; i < il; i ++ ) {
  6229. this.skinIndices.push( skinIndices[ i ].clone() );
  6230. }
  6231. // line distances
  6232. var lineDistances = source.lineDistances;
  6233. for ( i = 0, il = lineDistances.length; i < il; i ++ ) {
  6234. this.lineDistances.push( lineDistances[ i ] );
  6235. }
  6236. // bounding box
  6237. var boundingBox = source.boundingBox;
  6238. if ( boundingBox !== null ) {
  6239. this.boundingBox = boundingBox.clone();
  6240. }
  6241. // bounding sphere
  6242. var boundingSphere = source.boundingSphere;
  6243. if ( boundingSphere !== null ) {
  6244. this.boundingSphere = boundingSphere.clone();
  6245. }
  6246. // update flags
  6247. this.elementsNeedUpdate = source.elementsNeedUpdate;
  6248. this.verticesNeedUpdate = source.verticesNeedUpdate;
  6249. this.uvsNeedUpdate = source.uvsNeedUpdate;
  6250. this.normalsNeedUpdate = source.normalsNeedUpdate;
  6251. this.colorsNeedUpdate = source.colorsNeedUpdate;
  6252. this.lineDistancesNeedUpdate = source.lineDistancesNeedUpdate;
  6253. this.groupsNeedUpdate = source.groupsNeedUpdate;
  6254. return this;
  6255. },
  6256. dispose: function () {
  6257. this.dispatchEvent( { type: 'dispose' } );
  6258. }
  6259. } );
  6260. /**
  6261. * @author mrdoob / http://mrdoob.com/
  6262. */
  6263. function BufferAttribute( array, itemSize, normalized ) {
  6264. if ( Array.isArray( array ) ) {
  6265. throw new TypeError( 'THREE.BufferAttribute: array should be a Typed Array.' );
  6266. }
  6267. this.name = '';
  6268. this.array = array;
  6269. this.itemSize = itemSize;
  6270. this.count = array !== undefined ? array.length / itemSize : 0;
  6271. this.normalized = normalized === true;
  6272. this.dynamic = false;
  6273. this.updateRange = { offset: 0, count: - 1 };
  6274. this.version = 0;
  6275. }
  6276. Object.defineProperty( BufferAttribute.prototype, 'needsUpdate', {
  6277. set: function ( value ) {
  6278. if ( value === true ) this.version ++;
  6279. }
  6280. } );
  6281. Object.assign( BufferAttribute.prototype, {
  6282. isBufferAttribute: true,
  6283. onUploadCallback: function () {},
  6284. setArray: function ( array ) {
  6285. if ( Array.isArray( array ) ) {
  6286. throw new TypeError( 'THREE.BufferAttribute: array should be a Typed Array.' );
  6287. }
  6288. this.count = array !== undefined ? array.length / this.itemSize : 0;
  6289. this.array = array;
  6290. return this;
  6291. },
  6292. setDynamic: function ( value ) {
  6293. this.dynamic = value;
  6294. return this;
  6295. },
  6296. copy: function ( source ) {
  6297. this.name = source.name;
  6298. this.array = new source.array.constructor( source.array );
  6299. this.itemSize = source.itemSize;
  6300. this.count = source.count;
  6301. this.normalized = source.normalized;
  6302. this.dynamic = source.dynamic;
  6303. return this;
  6304. },
  6305. copyAt: function ( index1, attribute, index2 ) {
  6306. index1 *= this.itemSize;
  6307. index2 *= attribute.itemSize;
  6308. for ( var i = 0, l = this.itemSize; i < l; i ++ ) {
  6309. this.array[ index1 + i ] = attribute.array[ index2 + i ];
  6310. }
  6311. return this;
  6312. },
  6313. copyArray: function ( array ) {
  6314. this.array.set( array );
  6315. return this;
  6316. },
  6317. copyColorsArray: function ( colors ) {
  6318. var array = this.array, offset = 0;
  6319. for ( var i = 0, l = colors.length; i < l; i ++ ) {
  6320. var color = colors[ i ];
  6321. if ( color === undefined ) {
  6322. console.warn( 'THREE.BufferAttribute.copyColorsArray(): color is undefined', i );
  6323. color = new Color();
  6324. }
  6325. array[ offset ++ ] = color.r;
  6326. array[ offset ++ ] = color.g;
  6327. array[ offset ++ ] = color.b;
  6328. }
  6329. return this;
  6330. },
  6331. copyVector2sArray: function ( vectors ) {
  6332. var array = this.array, offset = 0;
  6333. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  6334. var vector = vectors[ i ];
  6335. if ( vector === undefined ) {
  6336. console.warn( 'THREE.BufferAttribute.copyVector2sArray(): vector is undefined', i );
  6337. vector = new Vector2();
  6338. }
  6339. array[ offset ++ ] = vector.x;
  6340. array[ offset ++ ] = vector.y;
  6341. }
  6342. return this;
  6343. },
  6344. copyVector3sArray: function ( vectors ) {
  6345. var array = this.array, offset = 0;
  6346. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  6347. var vector = vectors[ i ];
  6348. if ( vector === undefined ) {
  6349. console.warn( 'THREE.BufferAttribute.copyVector3sArray(): vector is undefined', i );
  6350. vector = new Vector3();
  6351. }
  6352. array[ offset ++ ] = vector.x;
  6353. array[ offset ++ ] = vector.y;
  6354. array[ offset ++ ] = vector.z;
  6355. }
  6356. return this;
  6357. },
  6358. copyVector4sArray: function ( vectors ) {
  6359. var array = this.array, offset = 0;
  6360. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  6361. var vector = vectors[ i ];
  6362. if ( vector === undefined ) {
  6363. console.warn( 'THREE.BufferAttribute.copyVector4sArray(): vector is undefined', i );
  6364. vector = new Vector4();
  6365. }
  6366. array[ offset ++ ] = vector.x;
  6367. array[ offset ++ ] = vector.y;
  6368. array[ offset ++ ] = vector.z;
  6369. array[ offset ++ ] = vector.w;
  6370. }
  6371. return this;
  6372. },
  6373. set: function ( value, offset ) {
  6374. if ( offset === undefined ) offset = 0;
  6375. this.array.set( value, offset );
  6376. return this;
  6377. },
  6378. getX: function ( index ) {
  6379. return this.array[ index * this.itemSize ];
  6380. },
  6381. setX: function ( index, x ) {
  6382. this.array[ index * this.itemSize ] = x;
  6383. return this;
  6384. },
  6385. getY: function ( index ) {
  6386. return this.array[ index * this.itemSize + 1 ];
  6387. },
  6388. setY: function ( index, y ) {
  6389. this.array[ index * this.itemSize + 1 ] = y;
  6390. return this;
  6391. },
  6392. getZ: function ( index ) {
  6393. return this.array[ index * this.itemSize + 2 ];
  6394. },
  6395. setZ: function ( index, z ) {
  6396. this.array[ index * this.itemSize + 2 ] = z;
  6397. return this;
  6398. },
  6399. getW: function ( index ) {
  6400. return this.array[ index * this.itemSize + 3 ];
  6401. },
  6402. setW: function ( index, w ) {
  6403. this.array[ index * this.itemSize + 3 ] = w;
  6404. return this;
  6405. },
  6406. setXY: function ( index, x, y ) {
  6407. index *= this.itemSize;
  6408. this.array[ index + 0 ] = x;
  6409. this.array[ index + 1 ] = y;
  6410. return this;
  6411. },
  6412. setXYZ: function ( index, x, y, z ) {
  6413. index *= this.itemSize;
  6414. this.array[ index + 0 ] = x;
  6415. this.array[ index + 1 ] = y;
  6416. this.array[ index + 2 ] = z;
  6417. return this;
  6418. },
  6419. setXYZW: function ( index, x, y, z, w ) {
  6420. index *= this.itemSize;
  6421. this.array[ index + 0 ] = x;
  6422. this.array[ index + 1 ] = y;
  6423. this.array[ index + 2 ] = z;
  6424. this.array[ index + 3 ] = w;
  6425. return this;
  6426. },
  6427. onUpload: function ( callback ) {
  6428. this.onUploadCallback = callback;
  6429. return this;
  6430. },
  6431. clone: function () {
  6432. return new this.constructor( this.array, this.itemSize ).copy( this );
  6433. }
  6434. } );
  6435. //
  6436. function Int8BufferAttribute( array, itemSize, normalized ) {
  6437. BufferAttribute.call( this, new Int8Array( array ), itemSize, normalized );
  6438. }
  6439. Int8BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  6440. Int8BufferAttribute.prototype.constructor = Int8BufferAttribute;
  6441. function Uint8BufferAttribute( array, itemSize, normalized ) {
  6442. BufferAttribute.call( this, new Uint8Array( array ), itemSize, normalized );
  6443. }
  6444. Uint8BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  6445. Uint8BufferAttribute.prototype.constructor = Uint8BufferAttribute;
  6446. function Uint8ClampedBufferAttribute( array, itemSize, normalized ) {
  6447. BufferAttribute.call( this, new Uint8ClampedArray( array ), itemSize, normalized );
  6448. }
  6449. Uint8ClampedBufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  6450. Uint8ClampedBufferAttribute.prototype.constructor = Uint8ClampedBufferAttribute;
  6451. function Int16BufferAttribute( array, itemSize, normalized ) {
  6452. BufferAttribute.call( this, new Int16Array( array ), itemSize, normalized );
  6453. }
  6454. Int16BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  6455. Int16BufferAttribute.prototype.constructor = Int16BufferAttribute;
  6456. function Uint16BufferAttribute( array, itemSize, normalized ) {
  6457. BufferAttribute.call( this, new Uint16Array( array ), itemSize, normalized );
  6458. }
  6459. Uint16BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  6460. Uint16BufferAttribute.prototype.constructor = Uint16BufferAttribute;
  6461. function Int32BufferAttribute( array, itemSize, normalized ) {
  6462. BufferAttribute.call( this, new Int32Array( array ), itemSize, normalized );
  6463. }
  6464. Int32BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  6465. Int32BufferAttribute.prototype.constructor = Int32BufferAttribute;
  6466. function Uint32BufferAttribute( array, itemSize, normalized ) {
  6467. BufferAttribute.call( this, new Uint32Array( array ), itemSize, normalized );
  6468. }
  6469. Uint32BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  6470. Uint32BufferAttribute.prototype.constructor = Uint32BufferAttribute;
  6471. function Float32BufferAttribute( array, itemSize, normalized ) {
  6472. BufferAttribute.call( this, new Float32Array( array ), itemSize, normalized );
  6473. }
  6474. Float32BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  6475. Float32BufferAttribute.prototype.constructor = Float32BufferAttribute;
  6476. function Float64BufferAttribute( array, itemSize, normalized ) {
  6477. BufferAttribute.call( this, new Float64Array( array ), itemSize, normalized );
  6478. }
  6479. Float64BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  6480. Float64BufferAttribute.prototype.constructor = Float64BufferAttribute;
  6481. /**
  6482. * @author mrdoob / http://mrdoob.com/
  6483. */
  6484. function DirectGeometry() {
  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( DirectGeometry.prototype, {
  6505. computeGroups: function ( geometry ) {
  6506. var group;
  6507. var groups = [];
  6508. var materialIndex = undefined;
  6509. var faces = geometry.faces;
  6510. for ( var i = 0; i < faces.length; i ++ ) {
  6511. var face = faces[ i ];
  6512. // materials
  6513. if ( face.materialIndex !== materialIndex ) {
  6514. materialIndex = face.materialIndex;
  6515. if ( group !== undefined ) {
  6516. group.count = ( i * 3 ) - group.start;
  6517. groups.push( group );
  6518. }
  6519. group = {
  6520. start: i * 3,
  6521. materialIndex: materialIndex
  6522. };
  6523. }
  6524. }
  6525. if ( group !== undefined ) {
  6526. group.count = ( i * 3 ) - group.start;
  6527. groups.push( group );
  6528. }
  6529. this.groups = groups;
  6530. },
  6531. fromGeometry: function ( geometry ) {
  6532. var faces = geometry.faces;
  6533. var vertices = geometry.vertices;
  6534. var faceVertexUvs = geometry.faceVertexUvs;
  6535. var hasFaceVertexUv = faceVertexUvs[ 0 ] && faceVertexUvs[ 0 ].length > 0;
  6536. var hasFaceVertexUv2 = faceVertexUvs[ 1 ] && faceVertexUvs[ 1 ].length > 0;
  6537. // morphs
  6538. var morphTargets = geometry.morphTargets;
  6539. var morphTargetsLength = morphTargets.length;
  6540. var morphTargetsPosition;
  6541. if ( morphTargetsLength > 0 ) {
  6542. morphTargetsPosition = [];
  6543. for ( var i = 0; i < morphTargetsLength; i ++ ) {
  6544. morphTargetsPosition[ i ] = {
  6545. name: morphTargets[ i ].name,
  6546. data: []
  6547. };
  6548. }
  6549. this.morphTargets.position = morphTargetsPosition;
  6550. }
  6551. var morphNormals = geometry.morphNormals;
  6552. var morphNormalsLength = morphNormals.length;
  6553. var morphTargetsNormal;
  6554. if ( morphNormalsLength > 0 ) {
  6555. morphTargetsNormal = [];
  6556. for ( var i = 0; i < morphNormalsLength; i ++ ) {
  6557. morphTargetsNormal[ i ] = {
  6558. name: morphNormals[ i ].name,
  6559. data: []
  6560. };
  6561. }
  6562. this.morphTargets.normal = morphTargetsNormal;
  6563. }
  6564. // skins
  6565. var skinIndices = geometry.skinIndices;
  6566. var skinWeights = geometry.skinWeights;
  6567. var hasSkinIndices = skinIndices.length === vertices.length;
  6568. var hasSkinWeights = skinWeights.length === vertices.length;
  6569. //
  6570. if ( vertices.length > 0 && faces.length === 0 ) {
  6571. console.error( 'THREE.DirectGeometry: Faceless geometries are not supported.' );
  6572. }
  6573. for ( var i = 0; i < faces.length; i ++ ) {
  6574. var face = faces[ i ];
  6575. this.vertices.push( vertices[ face.a ], vertices[ face.b ], vertices[ face.c ] );
  6576. var vertexNormals = face.vertexNormals;
  6577. if ( vertexNormals.length === 3 ) {
  6578. this.normals.push( vertexNormals[ 0 ], vertexNormals[ 1 ], vertexNormals[ 2 ] );
  6579. } else {
  6580. var normal = face.normal;
  6581. this.normals.push( normal, normal, normal );
  6582. }
  6583. var vertexColors = face.vertexColors;
  6584. if ( vertexColors.length === 3 ) {
  6585. this.colors.push( vertexColors[ 0 ], vertexColors[ 1 ], vertexColors[ 2 ] );
  6586. } else {
  6587. var color = face.color;
  6588. this.colors.push( color, color, color );
  6589. }
  6590. if ( hasFaceVertexUv === true ) {
  6591. var vertexUvs = faceVertexUvs[ 0 ][ i ];
  6592. if ( vertexUvs !== undefined ) {
  6593. this.uvs.push( vertexUvs[ 0 ], vertexUvs[ 1 ], vertexUvs[ 2 ] );
  6594. } else {
  6595. console.warn( 'THREE.DirectGeometry.fromGeometry(): Undefined vertexUv ', i );
  6596. this.uvs.push( new Vector2(), new Vector2(), new Vector2() );
  6597. }
  6598. }
  6599. if ( hasFaceVertexUv2 === true ) {
  6600. var vertexUvs = faceVertexUvs[ 1 ][ i ];
  6601. if ( vertexUvs !== undefined ) {
  6602. this.uvs2.push( vertexUvs[ 0 ], vertexUvs[ 1 ], vertexUvs[ 2 ] );
  6603. } else {
  6604. console.warn( 'THREE.DirectGeometry.fromGeometry(): Undefined vertexUv2 ', i );
  6605. this.uvs2.push( new Vector2(), new Vector2(), new Vector2() );
  6606. }
  6607. }
  6608. // morphs
  6609. for ( var j = 0; j < morphTargetsLength; j ++ ) {
  6610. var morphTarget = morphTargets[ j ].vertices;
  6611. morphTargetsPosition[ j ].data.push( morphTarget[ face.a ], morphTarget[ face.b ], morphTarget[ face.c ] );
  6612. }
  6613. for ( var j = 0; j < morphNormalsLength; j ++ ) {
  6614. var morphNormal = morphNormals[ j ].vertexNormals[ i ];
  6615. morphTargetsNormal[ j ].data.push( morphNormal.a, morphNormal.b, morphNormal.c );
  6616. }
  6617. // skins
  6618. if ( hasSkinIndices ) {
  6619. this.skinIndices.push( skinIndices[ face.a ], skinIndices[ face.b ], skinIndices[ face.c ] );
  6620. }
  6621. if ( hasSkinWeights ) {
  6622. this.skinWeights.push( skinWeights[ face.a ], skinWeights[ face.b ], skinWeights[ face.c ] );
  6623. }
  6624. }
  6625. this.computeGroups( geometry );
  6626. this.verticesNeedUpdate = geometry.verticesNeedUpdate;
  6627. this.normalsNeedUpdate = geometry.normalsNeedUpdate;
  6628. this.colorsNeedUpdate = geometry.colorsNeedUpdate;
  6629. this.uvsNeedUpdate = geometry.uvsNeedUpdate;
  6630. this.groupsNeedUpdate = geometry.groupsNeedUpdate;
  6631. return this;
  6632. }
  6633. } );
  6634. /**
  6635. * @author mrdoob / http://mrdoob.com/
  6636. */
  6637. function arrayMax( array ) {
  6638. if ( array.length === 0 ) return - Infinity;
  6639. var max = array[ 0 ];
  6640. for ( var i = 1, l = array.length; i < l; ++ i ) {
  6641. if ( array[ i ] > max ) max = array[ i ];
  6642. }
  6643. return max;
  6644. }
  6645. /**
  6646. * @author alteredq / http://alteredqualia.com/
  6647. * @author mrdoob / http://mrdoob.com/
  6648. */
  6649. var bufferGeometryId = 1; // BufferGeometry uses odd numbers as Id
  6650. function BufferGeometry() {
  6651. Object.defineProperty( this, 'id', { value: bufferGeometryId += 2 } );
  6652. this.uuid = _Math.generateUUID();
  6653. this.name = '';
  6654. this.type = 'BufferGeometry';
  6655. this.index = null;
  6656. this.attributes = {};
  6657. this.morphAttributes = {};
  6658. this.groups = [];
  6659. this.boundingBox = null;
  6660. this.boundingSphere = null;
  6661. this.drawRange = { start: 0, count: Infinity };
  6662. this.userData = {};
  6663. }
  6664. BufferGeometry.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  6665. constructor: BufferGeometry,
  6666. isBufferGeometry: true,
  6667. getIndex: function () {
  6668. return this.index;
  6669. },
  6670. setIndex: function ( index ) {
  6671. if ( Array.isArray( index ) ) {
  6672. this.index = new ( arrayMax( index ) > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute )( index, 1 );
  6673. } else {
  6674. this.index = index;
  6675. }
  6676. },
  6677. addAttribute: function ( name, attribute ) {
  6678. if ( ! ( attribute && attribute.isBufferAttribute ) && ! ( attribute && attribute.isInterleavedBufferAttribute ) ) {
  6679. console.warn( 'THREE.BufferGeometry: .addAttribute() now expects ( name, attribute ).' );
  6680. return this.addAttribute( name, new BufferAttribute( arguments[ 1 ], arguments[ 2 ] ) );
  6681. }
  6682. if ( name === 'index' ) {
  6683. console.warn( 'THREE.BufferGeometry.addAttribute: Use .setIndex() for index attribute.' );
  6684. this.setIndex( attribute );
  6685. return this;
  6686. }
  6687. this.attributes[ name ] = attribute;
  6688. return this;
  6689. },
  6690. getAttribute: function ( name ) {
  6691. return this.attributes[ name ];
  6692. },
  6693. removeAttribute: function ( name ) {
  6694. delete this.attributes[ name ];
  6695. return this;
  6696. },
  6697. addGroup: function ( start, count, materialIndex ) {
  6698. this.groups.push( {
  6699. start: start,
  6700. count: count,
  6701. materialIndex: materialIndex !== undefined ? materialIndex : 0
  6702. } );
  6703. },
  6704. clearGroups: function () {
  6705. this.groups = [];
  6706. },
  6707. setDrawRange: function ( start, count ) {
  6708. this.drawRange.start = start;
  6709. this.drawRange.count = count;
  6710. },
  6711. applyMatrix: function ( matrix ) {
  6712. var position = this.attributes.position;
  6713. if ( position !== undefined ) {
  6714. matrix.applyToBufferAttribute( position );
  6715. position.needsUpdate = true;
  6716. }
  6717. var normal = this.attributes.normal;
  6718. if ( normal !== undefined ) {
  6719. var normalMatrix = new Matrix3().getNormalMatrix( matrix );
  6720. normalMatrix.applyToBufferAttribute( normal );
  6721. normal.needsUpdate = true;
  6722. }
  6723. var tangent = this.attributes.tangent;
  6724. if ( tangent !== undefined ) {
  6725. var normalMatrix = new Matrix3().getNormalMatrix( matrix );
  6726. // Tangent is vec4, but the '.w' component is a sign value (+1/-1).
  6727. normalMatrix.applyToBufferAttribute( tangent );
  6728. tangent.needsUpdate = true;
  6729. }
  6730. if ( this.boundingBox !== null ) {
  6731. this.computeBoundingBox();
  6732. }
  6733. if ( this.boundingSphere !== null ) {
  6734. this.computeBoundingSphere();
  6735. }
  6736. return this;
  6737. },
  6738. rotateX: function () {
  6739. // rotate geometry around world x-axis
  6740. var m1 = new Matrix4();
  6741. return function rotateX( angle ) {
  6742. m1.makeRotationX( angle );
  6743. this.applyMatrix( m1 );
  6744. return this;
  6745. };
  6746. }(),
  6747. rotateY: function () {
  6748. // rotate geometry around world y-axis
  6749. var m1 = new Matrix4();
  6750. return function rotateY( angle ) {
  6751. m1.makeRotationY( angle );
  6752. this.applyMatrix( m1 );
  6753. return this;
  6754. };
  6755. }(),
  6756. rotateZ: function () {
  6757. // rotate geometry around world z-axis
  6758. var m1 = new Matrix4();
  6759. return function rotateZ( angle ) {
  6760. m1.makeRotationZ( angle );
  6761. this.applyMatrix( m1 );
  6762. return this;
  6763. };
  6764. }(),
  6765. translate: function () {
  6766. // translate geometry
  6767. var m1 = new Matrix4();
  6768. return function translate( x, y, z ) {
  6769. m1.makeTranslation( x, y, z );
  6770. this.applyMatrix( m1 );
  6771. return this;
  6772. };
  6773. }(),
  6774. scale: function () {
  6775. // scale geometry
  6776. var m1 = new Matrix4();
  6777. return function scale( x, y, z ) {
  6778. m1.makeScale( x, y, z );
  6779. this.applyMatrix( m1 );
  6780. return this;
  6781. };
  6782. }(),
  6783. lookAt: function () {
  6784. var obj = new Object3D();
  6785. return function lookAt( vector ) {
  6786. obj.lookAt( vector );
  6787. obj.updateMatrix();
  6788. this.applyMatrix( obj.matrix );
  6789. };
  6790. }(),
  6791. center: function () {
  6792. var offset = new Vector3();
  6793. return function center() {
  6794. this.computeBoundingBox();
  6795. this.boundingBox.getCenter( offset ).negate();
  6796. this.translate( offset.x, offset.y, offset.z );
  6797. return this;
  6798. };
  6799. }(),
  6800. setFromObject: function ( object ) {
  6801. // console.log( 'THREE.BufferGeometry.setFromObject(). Converting', object, this );
  6802. var geometry = object.geometry;
  6803. if ( object.isPoints || object.isLine ) {
  6804. var positions = new Float32BufferAttribute( geometry.vertices.length * 3, 3 );
  6805. var colors = new Float32BufferAttribute( geometry.colors.length * 3, 3 );
  6806. this.addAttribute( 'position', positions.copyVector3sArray( geometry.vertices ) );
  6807. this.addAttribute( 'color', colors.copyColorsArray( geometry.colors ) );
  6808. if ( geometry.lineDistances && geometry.lineDistances.length === geometry.vertices.length ) {
  6809. var lineDistances = new Float32BufferAttribute( geometry.lineDistances.length, 1 );
  6810. this.addAttribute( 'lineDistance', lineDistances.copyArray( geometry.lineDistances ) );
  6811. }
  6812. if ( geometry.boundingSphere !== null ) {
  6813. this.boundingSphere = geometry.boundingSphere.clone();
  6814. }
  6815. if ( geometry.boundingBox !== null ) {
  6816. this.boundingBox = geometry.boundingBox.clone();
  6817. }
  6818. } else if ( object.isMesh ) {
  6819. if ( geometry && geometry.isGeometry ) {
  6820. this.fromGeometry( geometry );
  6821. }
  6822. }
  6823. return this;
  6824. },
  6825. setFromPoints: function ( points ) {
  6826. var position = [];
  6827. for ( var i = 0, l = points.length; i < l; i ++ ) {
  6828. var point = points[ i ];
  6829. position.push( point.x, point.y, point.z || 0 );
  6830. }
  6831. this.addAttribute( 'position', new Float32BufferAttribute( position, 3 ) );
  6832. return this;
  6833. },
  6834. updateFromObject: function ( object ) {
  6835. var geometry = object.geometry;
  6836. if ( object.isMesh ) {
  6837. var direct = geometry.__directGeometry;
  6838. if ( geometry.elementsNeedUpdate === true ) {
  6839. direct = undefined;
  6840. geometry.elementsNeedUpdate = false;
  6841. }
  6842. if ( direct === undefined ) {
  6843. return this.fromGeometry( geometry );
  6844. }
  6845. direct.verticesNeedUpdate = geometry.verticesNeedUpdate;
  6846. direct.normalsNeedUpdate = geometry.normalsNeedUpdate;
  6847. direct.colorsNeedUpdate = geometry.colorsNeedUpdate;
  6848. direct.uvsNeedUpdate = geometry.uvsNeedUpdate;
  6849. direct.groupsNeedUpdate = geometry.groupsNeedUpdate;
  6850. geometry.verticesNeedUpdate = false;
  6851. geometry.normalsNeedUpdate = false;
  6852. geometry.colorsNeedUpdate = false;
  6853. geometry.uvsNeedUpdate = false;
  6854. geometry.groupsNeedUpdate = false;
  6855. geometry = direct;
  6856. }
  6857. var attribute;
  6858. if ( geometry.verticesNeedUpdate === true ) {
  6859. attribute = this.attributes.position;
  6860. if ( attribute !== undefined ) {
  6861. attribute.copyVector3sArray( geometry.vertices );
  6862. attribute.needsUpdate = true;
  6863. }
  6864. geometry.verticesNeedUpdate = false;
  6865. }
  6866. if ( geometry.normalsNeedUpdate === true ) {
  6867. attribute = this.attributes.normal;
  6868. if ( attribute !== undefined ) {
  6869. attribute.copyVector3sArray( geometry.normals );
  6870. attribute.needsUpdate = true;
  6871. }
  6872. geometry.normalsNeedUpdate = false;
  6873. }
  6874. if ( geometry.colorsNeedUpdate === true ) {
  6875. attribute = this.attributes.color;
  6876. if ( attribute !== undefined ) {
  6877. attribute.copyColorsArray( geometry.colors );
  6878. attribute.needsUpdate = true;
  6879. }
  6880. geometry.colorsNeedUpdate = false;
  6881. }
  6882. if ( geometry.uvsNeedUpdate ) {
  6883. attribute = this.attributes.uv;
  6884. if ( attribute !== undefined ) {
  6885. attribute.copyVector2sArray( geometry.uvs );
  6886. attribute.needsUpdate = true;
  6887. }
  6888. geometry.uvsNeedUpdate = false;
  6889. }
  6890. if ( geometry.lineDistancesNeedUpdate ) {
  6891. attribute = this.attributes.lineDistance;
  6892. if ( attribute !== undefined ) {
  6893. attribute.copyArray( geometry.lineDistances );
  6894. attribute.needsUpdate = true;
  6895. }
  6896. geometry.lineDistancesNeedUpdate = false;
  6897. }
  6898. if ( geometry.groupsNeedUpdate ) {
  6899. geometry.computeGroups( object.geometry );
  6900. this.groups = geometry.groups;
  6901. geometry.groupsNeedUpdate = false;
  6902. }
  6903. return this;
  6904. },
  6905. fromGeometry: function ( geometry ) {
  6906. geometry.__directGeometry = new DirectGeometry().fromGeometry( geometry );
  6907. return this.fromDirectGeometry( geometry.__directGeometry );
  6908. },
  6909. fromDirectGeometry: function ( geometry ) {
  6910. var positions = new Float32Array( geometry.vertices.length * 3 );
  6911. this.addAttribute( 'position', new BufferAttribute( positions, 3 ).copyVector3sArray( geometry.vertices ) );
  6912. if ( geometry.normals.length > 0 ) {
  6913. var normals = new Float32Array( geometry.normals.length * 3 );
  6914. this.addAttribute( 'normal', new BufferAttribute( normals, 3 ).copyVector3sArray( geometry.normals ) );
  6915. }
  6916. if ( geometry.colors.length > 0 ) {
  6917. var colors = new Float32Array( geometry.colors.length * 3 );
  6918. this.addAttribute( 'color', new BufferAttribute( colors, 3 ).copyColorsArray( geometry.colors ) );
  6919. }
  6920. if ( geometry.uvs.length > 0 ) {
  6921. var uvs = new Float32Array( geometry.uvs.length * 2 );
  6922. this.addAttribute( 'uv', new BufferAttribute( uvs, 2 ).copyVector2sArray( geometry.uvs ) );
  6923. }
  6924. if ( geometry.uvs2.length > 0 ) {
  6925. var uvs2 = new Float32Array( geometry.uvs2.length * 2 );
  6926. this.addAttribute( 'uv2', new BufferAttribute( uvs2, 2 ).copyVector2sArray( geometry.uvs2 ) );
  6927. }
  6928. // groups
  6929. this.groups = geometry.groups;
  6930. // morphs
  6931. for ( var name in geometry.morphTargets ) {
  6932. var array = [];
  6933. var morphTargets = geometry.morphTargets[ name ];
  6934. for ( var i = 0, l = morphTargets.length; i < l; i ++ ) {
  6935. var morphTarget = morphTargets[ i ];
  6936. var attribute = new Float32BufferAttribute( morphTarget.data.length * 3, 3 );
  6937. attribute.name = morphTarget.name;
  6938. array.push( attribute.copyVector3sArray( morphTarget.data ) );
  6939. }
  6940. this.morphAttributes[ name ] = array;
  6941. }
  6942. // skinning
  6943. if ( geometry.skinIndices.length > 0 ) {
  6944. var skinIndices = new Float32BufferAttribute( geometry.skinIndices.length * 4, 4 );
  6945. this.addAttribute( 'skinIndex', skinIndices.copyVector4sArray( geometry.skinIndices ) );
  6946. }
  6947. if ( geometry.skinWeights.length > 0 ) {
  6948. var skinWeights = new Float32BufferAttribute( geometry.skinWeights.length * 4, 4 );
  6949. this.addAttribute( 'skinWeight', skinWeights.copyVector4sArray( geometry.skinWeights ) );
  6950. }
  6951. //
  6952. if ( geometry.boundingSphere !== null ) {
  6953. this.boundingSphere = geometry.boundingSphere.clone();
  6954. }
  6955. if ( geometry.boundingBox !== null ) {
  6956. this.boundingBox = geometry.boundingBox.clone();
  6957. }
  6958. return this;
  6959. },
  6960. computeBoundingBox: function () {
  6961. if ( this.boundingBox === null ) {
  6962. this.boundingBox = new Box3();
  6963. }
  6964. var position = this.attributes.position;
  6965. if ( position !== undefined ) {
  6966. this.boundingBox.setFromBufferAttribute( position );
  6967. } else {
  6968. this.boundingBox.makeEmpty();
  6969. }
  6970. if ( isNaN( this.boundingBox.min.x ) || isNaN( this.boundingBox.min.y ) || isNaN( this.boundingBox.min.z ) ) {
  6971. console.error( 'THREE.BufferGeometry.computeBoundingBox: Computed min/max have NaN values. The "position" attribute is likely to have NaN values.', this );
  6972. }
  6973. },
  6974. computeBoundingSphere: function () {
  6975. var box = new Box3();
  6976. var vector = new Vector3();
  6977. return function computeBoundingSphere() {
  6978. if ( this.boundingSphere === null ) {
  6979. this.boundingSphere = new Sphere();
  6980. }
  6981. var position = this.attributes.position;
  6982. if ( position ) {
  6983. var center = this.boundingSphere.center;
  6984. box.setFromBufferAttribute( position );
  6985. box.getCenter( center );
  6986. // hoping to find a boundingSphere with a radius smaller than the
  6987. // boundingSphere of the boundingBox: sqrt(3) smaller in the best case
  6988. var maxRadiusSq = 0;
  6989. for ( var i = 0, il = position.count; i < il; i ++ ) {
  6990. vector.x = position.getX( i );
  6991. vector.y = position.getY( i );
  6992. vector.z = position.getZ( i );
  6993. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( vector ) );
  6994. }
  6995. this.boundingSphere.radius = Math.sqrt( maxRadiusSq );
  6996. if ( isNaN( this.boundingSphere.radius ) ) {
  6997. console.error( 'THREE.BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.', this );
  6998. }
  6999. }
  7000. };
  7001. }(),
  7002. computeFaceNormals: function () {
  7003. // backwards compatibility
  7004. },
  7005. computeVertexNormals: function () {
  7006. var index = this.index;
  7007. var attributes = this.attributes;
  7008. if ( attributes.position ) {
  7009. var positions = attributes.position.array;
  7010. if ( attributes.normal === undefined ) {
  7011. this.addAttribute( 'normal', new BufferAttribute( new Float32Array( positions.length ), 3 ) );
  7012. } else {
  7013. // reset existing normals to zero
  7014. var array = attributes.normal.array;
  7015. for ( var i = 0, il = array.length; i < il; i ++ ) {
  7016. array[ i ] = 0;
  7017. }
  7018. }
  7019. var normals = attributes.normal.array;
  7020. var vA, vB, vC;
  7021. var pA = new Vector3(), pB = new Vector3(), pC = new Vector3();
  7022. var cb = new Vector3(), ab = new Vector3();
  7023. // indexed elements
  7024. if ( index ) {
  7025. var indices = index.array;
  7026. for ( var i = 0, il = index.count; i < il; i += 3 ) {
  7027. vA = indices[ i + 0 ] * 3;
  7028. vB = indices[ i + 1 ] * 3;
  7029. vC = indices[ i + 2 ] * 3;
  7030. pA.fromArray( positions, vA );
  7031. pB.fromArray( positions, vB );
  7032. pC.fromArray( positions, vC );
  7033. cb.subVectors( pC, pB );
  7034. ab.subVectors( pA, pB );
  7035. cb.cross( ab );
  7036. normals[ vA ] += cb.x;
  7037. normals[ vA + 1 ] += cb.y;
  7038. normals[ vA + 2 ] += cb.z;
  7039. normals[ vB ] += cb.x;
  7040. normals[ vB + 1 ] += cb.y;
  7041. normals[ vB + 2 ] += cb.z;
  7042. normals[ vC ] += cb.x;
  7043. normals[ vC + 1 ] += cb.y;
  7044. normals[ vC + 2 ] += cb.z;
  7045. }
  7046. } else {
  7047. // non-indexed elements (unconnected triangle soup)
  7048. for ( var i = 0, il = positions.length; i < il; i += 9 ) {
  7049. pA.fromArray( positions, i );
  7050. pB.fromArray( positions, i + 3 );
  7051. pC.fromArray( positions, i + 6 );
  7052. cb.subVectors( pC, pB );
  7053. ab.subVectors( pA, pB );
  7054. cb.cross( ab );
  7055. normals[ i ] = cb.x;
  7056. normals[ i + 1 ] = cb.y;
  7057. normals[ i + 2 ] = cb.z;
  7058. normals[ i + 3 ] = cb.x;
  7059. normals[ i + 4 ] = cb.y;
  7060. normals[ i + 5 ] = cb.z;
  7061. normals[ i + 6 ] = cb.x;
  7062. normals[ i + 7 ] = cb.y;
  7063. normals[ i + 8 ] = cb.z;
  7064. }
  7065. }
  7066. this.normalizeNormals();
  7067. attributes.normal.needsUpdate = true;
  7068. }
  7069. },
  7070. merge: function ( geometry, offset ) {
  7071. if ( ! ( geometry && geometry.isBufferGeometry ) ) {
  7072. console.error( 'THREE.BufferGeometry.merge(): geometry not an instance of THREE.BufferGeometry.', geometry );
  7073. return;
  7074. }
  7075. if ( offset === undefined ) {
  7076. offset = 0;
  7077. console.warn(
  7078. 'THREE.BufferGeometry.merge(): Overwriting original geometry, starting at offset=0. '
  7079. + 'Use BufferGeometryUtils.mergeBufferGeometries() for lossless merge.'
  7080. );
  7081. }
  7082. var attributes = this.attributes;
  7083. for ( var key in attributes ) {
  7084. if ( geometry.attributes[ key ] === undefined ) continue;
  7085. var attribute1 = attributes[ key ];
  7086. var attributeArray1 = attribute1.array;
  7087. var attribute2 = geometry.attributes[ key ];
  7088. var attributeArray2 = attribute2.array;
  7089. var attributeSize = attribute2.itemSize;
  7090. for ( var i = 0, j = attributeSize * offset; i < attributeArray2.length; i ++, j ++ ) {
  7091. attributeArray1[ j ] = attributeArray2[ i ];
  7092. }
  7093. }
  7094. return this;
  7095. },
  7096. normalizeNormals: function () {
  7097. var vector = new Vector3();
  7098. return function normalizeNormals() {
  7099. var normals = this.attributes.normal;
  7100. for ( var i = 0, il = normals.count; i < il; i ++ ) {
  7101. vector.x = normals.getX( i );
  7102. vector.y = normals.getY( i );
  7103. vector.z = normals.getZ( i );
  7104. vector.normalize();
  7105. normals.setXYZ( i, vector.x, vector.y, vector.z );
  7106. }
  7107. };
  7108. }(),
  7109. toNonIndexed: function () {
  7110. function convertBufferAttribute( attribute, indices ) {
  7111. var array = attribute.array;
  7112. var itemSize = attribute.itemSize;
  7113. var array2 = new array.constructor( indices.length * itemSize );
  7114. var index = 0, index2 = 0;
  7115. for ( var i = 0, l = indices.length; i < l; i ++ ) {
  7116. index = indices[ i ] * itemSize;
  7117. for ( var j = 0; j < itemSize; j ++ ) {
  7118. array2[ index2 ++ ] = array[ index ++ ];
  7119. }
  7120. }
  7121. return new BufferAttribute( array2, itemSize );
  7122. }
  7123. //
  7124. if ( this.index === null ) {
  7125. console.warn( 'THREE.BufferGeometry.toNonIndexed(): Geometry is already non-indexed.' );
  7126. return this;
  7127. }
  7128. var geometry2 = new BufferGeometry();
  7129. var indices = this.index.array;
  7130. var attributes = this.attributes;
  7131. // attributes
  7132. for ( var name in attributes ) {
  7133. var attribute = attributes[ name ];
  7134. var newAttribute = convertBufferAttribute( attribute, indices );
  7135. geometry2.addAttribute( name, newAttribute );
  7136. }
  7137. // morph attributes
  7138. var morphAttributes = this.morphAttributes;
  7139. for ( name in morphAttributes ) {
  7140. var morphArray = [];
  7141. var morphAttribute = morphAttributes[ name ]; // morphAttribute: array of Float32BufferAttributes
  7142. for ( var i = 0, il = morphAttribute.length; i < il; i ++ ) {
  7143. var attribute = morphAttribute[ i ];
  7144. var newAttribute = convertBufferAttribute( attribute, indices );
  7145. morphArray.push( newAttribute );
  7146. }
  7147. geometry2.morphAttributes[ name ] = morphArray;
  7148. }
  7149. // groups
  7150. var groups = this.groups;
  7151. for ( var i = 0, l = groups.length; i < l; i ++ ) {
  7152. var group = groups[ i ];
  7153. geometry2.addGroup( group.start, group.count, group.materialIndex );
  7154. }
  7155. return geometry2;
  7156. },
  7157. toJSON: function () {
  7158. var data = {
  7159. metadata: {
  7160. version: 4.5,
  7161. type: 'BufferGeometry',
  7162. generator: 'BufferGeometry.toJSON'
  7163. }
  7164. };
  7165. // standard BufferGeometry serialization
  7166. data.uuid = this.uuid;
  7167. data.type = this.type;
  7168. if ( this.name !== '' ) data.name = this.name;
  7169. if ( Object.keys( this.userData ).length > 0 ) data.userData = this.userData;
  7170. if ( this.parameters !== undefined ) {
  7171. var parameters = this.parameters;
  7172. for ( var key in parameters ) {
  7173. if ( parameters[ key ] !== undefined ) data[ key ] = parameters[ key ];
  7174. }
  7175. return data;
  7176. }
  7177. data.data = { attributes: {} };
  7178. var index = this.index;
  7179. if ( index !== null ) {
  7180. data.data.index = {
  7181. type: index.array.constructor.name,
  7182. array: Array.prototype.slice.call( index.array )
  7183. };
  7184. }
  7185. var attributes = this.attributes;
  7186. for ( var key in attributes ) {
  7187. var attribute = attributes[ key ];
  7188. var attributeData = {
  7189. itemSize: attribute.itemSize,
  7190. type: attribute.array.constructor.name,
  7191. array: Array.prototype.slice.call( attribute.array ),
  7192. normalized: attribute.normalized
  7193. };
  7194. if ( attribute.name !== '' ) attributeData.name = attribute.name;
  7195. data.data.attributes[ key ] = attributeData;
  7196. }
  7197. var morphAttributes = {};
  7198. var hasMorphAttributes = false;
  7199. for ( var key in this.morphAttributes ) {
  7200. var attributeArray = this.morphAttributes[ key ];
  7201. var array = [];
  7202. for ( var i = 0, il = attributeArray.length; i < il; i ++ ) {
  7203. var attribute = attributeArray[ i ];
  7204. var attributeData = {
  7205. itemSize: attribute.itemSize,
  7206. type: attribute.array.constructor.name,
  7207. array: Array.prototype.slice.call( attribute.array ),
  7208. normalized: attribute.normalized
  7209. };
  7210. if ( attribute.name !== '' ) attributeData.name = attribute.name;
  7211. array.push( attributeData );
  7212. }
  7213. if ( array.length > 0 ) {
  7214. morphAttributes[ key ] = array;
  7215. hasMorphAttributes = true;
  7216. }
  7217. }
  7218. if ( hasMorphAttributes ) data.data.morphAttributes = morphAttributes;
  7219. var groups = this.groups;
  7220. if ( groups.length > 0 ) {
  7221. data.data.groups = JSON.parse( JSON.stringify( groups ) );
  7222. }
  7223. var boundingSphere = this.boundingSphere;
  7224. if ( boundingSphere !== null ) {
  7225. data.data.boundingSphere = {
  7226. center: boundingSphere.center.toArray(),
  7227. radius: boundingSphere.radius
  7228. };
  7229. }
  7230. return data;
  7231. },
  7232. clone: function () {
  7233. /*
  7234. // Handle primitives
  7235. var parameters = this.parameters;
  7236. if ( parameters !== undefined ) {
  7237. var values = [];
  7238. for ( var key in parameters ) {
  7239. values.push( parameters[ key ] );
  7240. }
  7241. var geometry = Object.create( this.constructor.prototype );
  7242. this.constructor.apply( geometry, values );
  7243. return geometry;
  7244. }
  7245. return new this.constructor().copy( this );
  7246. */
  7247. return new BufferGeometry().copy( this );
  7248. },
  7249. copy: function ( source ) {
  7250. var name, i, l;
  7251. // reset
  7252. this.index = null;
  7253. this.attributes = {};
  7254. this.morphAttributes = {};
  7255. this.groups = [];
  7256. this.boundingBox = null;
  7257. this.boundingSphere = null;
  7258. // name
  7259. this.name = source.name;
  7260. // index
  7261. var index = source.index;
  7262. if ( index !== null ) {
  7263. this.setIndex( index.clone() );
  7264. }
  7265. // attributes
  7266. var attributes = source.attributes;
  7267. for ( name in attributes ) {
  7268. var attribute = attributes[ name ];
  7269. this.addAttribute( name, attribute.clone() );
  7270. }
  7271. // morph attributes
  7272. var morphAttributes = source.morphAttributes;
  7273. for ( name in morphAttributes ) {
  7274. var array = [];
  7275. var morphAttribute = morphAttributes[ name ]; // morphAttribute: array of Float32BufferAttributes
  7276. for ( i = 0, l = morphAttribute.length; i < l; i ++ ) {
  7277. array.push( morphAttribute[ i ].clone() );
  7278. }
  7279. this.morphAttributes[ name ] = array;
  7280. }
  7281. // groups
  7282. var groups = source.groups;
  7283. for ( i = 0, l = groups.length; i < l; i ++ ) {
  7284. var group = groups[ i ];
  7285. this.addGroup( group.start, group.count, group.materialIndex );
  7286. }
  7287. // bounding box
  7288. var boundingBox = source.boundingBox;
  7289. if ( boundingBox !== null ) {
  7290. this.boundingBox = boundingBox.clone();
  7291. }
  7292. // bounding sphere
  7293. var boundingSphere = source.boundingSphere;
  7294. if ( boundingSphere !== null ) {
  7295. this.boundingSphere = boundingSphere.clone();
  7296. }
  7297. // draw range
  7298. this.drawRange.start = source.drawRange.start;
  7299. this.drawRange.count = source.drawRange.count;
  7300. // user data
  7301. this.userData = source.userData;
  7302. return this;
  7303. },
  7304. dispose: function () {
  7305. this.dispatchEvent( { type: 'dispose' } );
  7306. }
  7307. } );
  7308. /**
  7309. * @author mrdoob / http://mrdoob.com/
  7310. * @author Mugen87 / https://github.com/Mugen87
  7311. */
  7312. // BoxGeometry
  7313. function BoxGeometry( width, height, depth, widthSegments, heightSegments, depthSegments ) {
  7314. Geometry.call( this );
  7315. this.type = 'BoxGeometry';
  7316. this.parameters = {
  7317. width: width,
  7318. height: height,
  7319. depth: depth,
  7320. widthSegments: widthSegments,
  7321. heightSegments: heightSegments,
  7322. depthSegments: depthSegments
  7323. };
  7324. this.fromBufferGeometry( new BoxBufferGeometry( width, height, depth, widthSegments, heightSegments, depthSegments ) );
  7325. this.mergeVertices();
  7326. }
  7327. BoxGeometry.prototype = Object.create( Geometry.prototype );
  7328. BoxGeometry.prototype.constructor = BoxGeometry;
  7329. // BoxBufferGeometry
  7330. function BoxBufferGeometry( width, height, depth, widthSegments, heightSegments, depthSegments ) {
  7331. BufferGeometry.call( this );
  7332. this.type = 'BoxBufferGeometry';
  7333. this.parameters = {
  7334. width: width,
  7335. height: height,
  7336. depth: depth,
  7337. widthSegments: widthSegments,
  7338. heightSegments: heightSegments,
  7339. depthSegments: depthSegments
  7340. };
  7341. var scope = this;
  7342. width = width || 1;
  7343. height = height || 1;
  7344. depth = depth || 1;
  7345. // segments
  7346. widthSegments = Math.floor( widthSegments ) || 1;
  7347. heightSegments = Math.floor( heightSegments ) || 1;
  7348. depthSegments = Math.floor( depthSegments ) || 1;
  7349. // buffers
  7350. var indices = [];
  7351. var vertices = [];
  7352. var normals = [];
  7353. var uvs = [];
  7354. // helper variables
  7355. var numberOfVertices = 0;
  7356. var groupStart = 0;
  7357. // build each side of the box geometry
  7358. buildPlane( 'z', 'y', 'x', - 1, - 1, depth, height, width, depthSegments, heightSegments, 0 ); // px
  7359. buildPlane( 'z', 'y', 'x', 1, - 1, depth, height, - width, depthSegments, heightSegments, 1 ); // nx
  7360. buildPlane( 'x', 'z', 'y', 1, 1, width, depth, height, widthSegments, depthSegments, 2 ); // py
  7361. buildPlane( 'x', 'z', 'y', 1, - 1, width, depth, - height, widthSegments, depthSegments, 3 ); // ny
  7362. buildPlane( 'x', 'y', 'z', 1, - 1, width, height, depth, widthSegments, heightSegments, 4 ); // pz
  7363. buildPlane( 'x', 'y', 'z', - 1, - 1, width, height, - depth, widthSegments, heightSegments, 5 ); // nz
  7364. // build geometry
  7365. this.setIndex( indices );
  7366. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  7367. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  7368. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  7369. function buildPlane( u, v, w, udir, vdir, width, height, depth, gridX, gridY, materialIndex ) {
  7370. var segmentWidth = width / gridX;
  7371. var segmentHeight = height / gridY;
  7372. var widthHalf = width / 2;
  7373. var heightHalf = height / 2;
  7374. var depthHalf = depth / 2;
  7375. var gridX1 = gridX + 1;
  7376. var gridY1 = gridY + 1;
  7377. var vertexCounter = 0;
  7378. var groupCount = 0;
  7379. var ix, iy;
  7380. var vector = new Vector3();
  7381. // generate vertices, normals and uvs
  7382. for ( iy = 0; iy < gridY1; iy ++ ) {
  7383. var y = iy * segmentHeight - heightHalf;
  7384. for ( ix = 0; ix < gridX1; ix ++ ) {
  7385. var x = ix * segmentWidth - widthHalf;
  7386. // set values to correct vector component
  7387. vector[ u ] = x * udir;
  7388. vector[ v ] = y * vdir;
  7389. vector[ w ] = depthHalf;
  7390. // now apply vector to vertex buffer
  7391. vertices.push( vector.x, vector.y, vector.z );
  7392. // set values to correct vector component
  7393. vector[ u ] = 0;
  7394. vector[ v ] = 0;
  7395. vector[ w ] = depth > 0 ? 1 : - 1;
  7396. // now apply vector to normal buffer
  7397. normals.push( vector.x, vector.y, vector.z );
  7398. // uvs
  7399. uvs.push( ix / gridX );
  7400. uvs.push( 1 - ( iy / gridY ) );
  7401. // counters
  7402. vertexCounter += 1;
  7403. }
  7404. }
  7405. // indices
  7406. // 1. you need three indices to draw a single face
  7407. // 2. a single segment consists of two faces
  7408. // 3. so we need to generate six (2*3) indices per segment
  7409. for ( iy = 0; iy < gridY; iy ++ ) {
  7410. for ( ix = 0; ix < gridX; ix ++ ) {
  7411. var a = numberOfVertices + ix + gridX1 * iy;
  7412. var b = numberOfVertices + ix + gridX1 * ( iy + 1 );
  7413. var c = numberOfVertices + ( ix + 1 ) + gridX1 * ( iy + 1 );
  7414. var d = numberOfVertices + ( ix + 1 ) + gridX1 * iy;
  7415. // faces
  7416. indices.push( a, b, d );
  7417. indices.push( b, c, d );
  7418. // increase counter
  7419. groupCount += 6;
  7420. }
  7421. }
  7422. // add a group to the geometry. this will ensure multi material support
  7423. scope.addGroup( groupStart, groupCount, materialIndex );
  7424. // calculate new start value for groups
  7425. groupStart += groupCount;
  7426. // update total number of vertices
  7427. numberOfVertices += vertexCounter;
  7428. }
  7429. }
  7430. BoxBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  7431. BoxBufferGeometry.prototype.constructor = BoxBufferGeometry;
  7432. /**
  7433. * @author mrdoob / http://mrdoob.com/
  7434. * @author Mugen87 / https://github.com/Mugen87
  7435. */
  7436. // PlaneGeometry
  7437. function PlaneGeometry( width, height, widthSegments, heightSegments ) {
  7438. Geometry.call( this );
  7439. this.type = 'PlaneGeometry';
  7440. this.parameters = {
  7441. width: width,
  7442. height: height,
  7443. widthSegments: widthSegments,
  7444. heightSegments: heightSegments
  7445. };
  7446. this.fromBufferGeometry( new PlaneBufferGeometry( width, height, widthSegments, heightSegments ) );
  7447. this.mergeVertices();
  7448. }
  7449. PlaneGeometry.prototype = Object.create( Geometry.prototype );
  7450. PlaneGeometry.prototype.constructor = PlaneGeometry;
  7451. // PlaneBufferGeometry
  7452. function PlaneBufferGeometry( width, height, widthSegments, heightSegments ) {
  7453. BufferGeometry.call( this );
  7454. this.type = 'PlaneBufferGeometry';
  7455. this.parameters = {
  7456. width: width,
  7457. height: height,
  7458. widthSegments: widthSegments,
  7459. heightSegments: heightSegments
  7460. };
  7461. width = width || 1;
  7462. height = height || 1;
  7463. var width_half = width / 2;
  7464. var height_half = height / 2;
  7465. var gridX = Math.floor( widthSegments ) || 1;
  7466. var gridY = Math.floor( heightSegments ) || 1;
  7467. var gridX1 = gridX + 1;
  7468. var gridY1 = gridY + 1;
  7469. var segment_width = width / gridX;
  7470. var segment_height = height / gridY;
  7471. var ix, iy;
  7472. // buffers
  7473. var indices = [];
  7474. var vertices = [];
  7475. var normals = [];
  7476. var uvs = [];
  7477. // generate vertices, normals and uvs
  7478. for ( iy = 0; iy < gridY1; iy ++ ) {
  7479. var y = iy * segment_height - height_half;
  7480. for ( ix = 0; ix < gridX1; ix ++ ) {
  7481. var x = ix * segment_width - width_half;
  7482. vertices.push( x, - y, 0 );
  7483. normals.push( 0, 0, 1 );
  7484. uvs.push( ix / gridX );
  7485. uvs.push( 1 - ( iy / gridY ) );
  7486. }
  7487. }
  7488. // indices
  7489. for ( iy = 0; iy < gridY; iy ++ ) {
  7490. for ( ix = 0; ix < gridX; ix ++ ) {
  7491. var a = ix + gridX1 * iy;
  7492. var b = ix + gridX1 * ( iy + 1 );
  7493. var c = ( ix + 1 ) + gridX1 * ( iy + 1 );
  7494. var d = ( ix + 1 ) + gridX1 * iy;
  7495. // faces
  7496. indices.push( a, b, d );
  7497. indices.push( b, c, d );
  7498. }
  7499. }
  7500. // build geometry
  7501. this.setIndex( indices );
  7502. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  7503. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  7504. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  7505. }
  7506. PlaneBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  7507. PlaneBufferGeometry.prototype.constructor = PlaneBufferGeometry;
  7508. /**
  7509. * @author mrdoob / http://mrdoob.com/
  7510. * @author alteredq / http://alteredqualia.com/
  7511. */
  7512. var materialId = 0;
  7513. function Material() {
  7514. Object.defineProperty( this, 'id', { value: materialId ++ } );
  7515. this.uuid = _Math.generateUUID();
  7516. this.name = '';
  7517. this.type = 'Material';
  7518. this.fog = true;
  7519. this.lights = true;
  7520. this.blending = NormalBlending;
  7521. this.side = FrontSide;
  7522. this.flatShading = false;
  7523. this.vertexTangents = false;
  7524. this.vertexColors = NoColors; // THREE.NoColors, THREE.VertexColors, THREE.FaceColors
  7525. this.opacity = 1;
  7526. this.transparent = false;
  7527. this.blendSrc = SrcAlphaFactor;
  7528. this.blendDst = OneMinusSrcAlphaFactor;
  7529. this.blendEquation = AddEquation;
  7530. this.blendSrcAlpha = null;
  7531. this.blendDstAlpha = null;
  7532. this.blendEquationAlpha = null;
  7533. this.depthFunc = LessEqualDepth;
  7534. this.depthTest = true;
  7535. this.depthWrite = true;
  7536. this.clippingPlanes = null;
  7537. this.clipIntersection = false;
  7538. this.clipShadows = false;
  7539. this.shadowSide = null;
  7540. this.colorWrite = true;
  7541. this.precision = null; // override the renderer's default precision for this material
  7542. this.polygonOffset = false;
  7543. this.polygonOffsetFactor = 0;
  7544. this.polygonOffsetUnits = 0;
  7545. this.dithering = false;
  7546. this.alphaTest = 0;
  7547. this.premultipliedAlpha = false;
  7548. this.visible = true;
  7549. this.userData = {};
  7550. this.needsUpdate = true;
  7551. }
  7552. Material.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  7553. constructor: Material,
  7554. isMaterial: true,
  7555. onBeforeCompile: function () {},
  7556. setValues: function ( values ) {
  7557. if ( values === undefined ) return;
  7558. for ( var key in values ) {
  7559. var newValue = values[ key ];
  7560. if ( newValue === undefined ) {
  7561. console.warn( "THREE.Material: '" + key + "' parameter is undefined." );
  7562. continue;
  7563. }
  7564. // for backward compatability if shading is set in the constructor
  7565. if ( key === 'shading' ) {
  7566. console.warn( 'THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.' );
  7567. this.flatShading = ( newValue === FlatShading ) ? true : false;
  7568. continue;
  7569. }
  7570. var currentValue = this[ key ];
  7571. if ( currentValue === undefined ) {
  7572. console.warn( "THREE." + this.type + ": '" + key + "' is not a property of this material." );
  7573. continue;
  7574. }
  7575. if ( currentValue && currentValue.isColor ) {
  7576. currentValue.set( newValue );
  7577. } else if ( ( currentValue && currentValue.isVector3 ) && ( newValue && newValue.isVector3 ) ) {
  7578. currentValue.copy( newValue );
  7579. } else {
  7580. this[ key ] = newValue;
  7581. }
  7582. }
  7583. },
  7584. toJSON: function ( meta ) {
  7585. var isRoot = ( meta === undefined || typeof meta === 'string' );
  7586. if ( isRoot ) {
  7587. meta = {
  7588. textures: {},
  7589. images: {}
  7590. };
  7591. }
  7592. var data = {
  7593. metadata: {
  7594. version: 4.5,
  7595. type: 'Material',
  7596. generator: 'Material.toJSON'
  7597. }
  7598. };
  7599. // standard Material serialization
  7600. data.uuid = this.uuid;
  7601. data.type = this.type;
  7602. if ( this.name !== '' ) data.name = this.name;
  7603. if ( this.color && this.color.isColor ) data.color = this.color.getHex();
  7604. if ( this.roughness !== undefined ) data.roughness = this.roughness;
  7605. if ( this.metalness !== undefined ) data.metalness = this.metalness;
  7606. if ( this.emissive && this.emissive.isColor ) data.emissive = this.emissive.getHex();
  7607. if ( this.emissiveIntensity !== 1 ) data.emissiveIntensity = this.emissiveIntensity;
  7608. if ( this.specular && this.specular.isColor ) data.specular = this.specular.getHex();
  7609. if ( this.shininess !== undefined ) data.shininess = this.shininess;
  7610. if ( this.clearCoat !== undefined ) data.clearCoat = this.clearCoat;
  7611. if ( this.clearCoatRoughness !== undefined ) data.clearCoatRoughness = this.clearCoatRoughness;
  7612. if ( this.map && this.map.isTexture ) data.map = this.map.toJSON( meta ).uuid;
  7613. if ( this.alphaMap && this.alphaMap.isTexture ) data.alphaMap = this.alphaMap.toJSON( meta ).uuid;
  7614. if ( this.lightMap && this.lightMap.isTexture ) data.lightMap = this.lightMap.toJSON( meta ).uuid;
  7615. if ( this.aoMap && this.aoMap.isTexture ) {
  7616. data.aoMap = this.aoMap.toJSON( meta ).uuid;
  7617. data.aoMapIntensity = this.aoMapIntensity;
  7618. }
  7619. if ( this.bumpMap && this.bumpMap.isTexture ) {
  7620. data.bumpMap = this.bumpMap.toJSON( meta ).uuid;
  7621. data.bumpScale = this.bumpScale;
  7622. }
  7623. if ( this.normalMap && this.normalMap.isTexture ) {
  7624. data.normalMap = this.normalMap.toJSON( meta ).uuid;
  7625. data.normalMapType = this.normalMapType;
  7626. data.normalScale = this.normalScale.toArray();
  7627. }
  7628. if ( this.displacementMap && this.displacementMap.isTexture ) {
  7629. data.displacementMap = this.displacementMap.toJSON( meta ).uuid;
  7630. data.displacementScale = this.displacementScale;
  7631. data.displacementBias = this.displacementBias;
  7632. }
  7633. if ( this.roughnessMap && this.roughnessMap.isTexture ) data.roughnessMap = this.roughnessMap.toJSON( meta ).uuid;
  7634. if ( this.metalnessMap && this.metalnessMap.isTexture ) data.metalnessMap = this.metalnessMap.toJSON( meta ).uuid;
  7635. if ( this.emissiveMap && this.emissiveMap.isTexture ) data.emissiveMap = this.emissiveMap.toJSON( meta ).uuid;
  7636. if ( this.specularMap && this.specularMap.isTexture ) data.specularMap = this.specularMap.toJSON( meta ).uuid;
  7637. if ( this.envMap && this.envMap.isTexture ) {
  7638. data.envMap = this.envMap.toJSON( meta ).uuid;
  7639. data.reflectivity = this.reflectivity; // Scale behind envMap
  7640. if ( this.combine !== undefined ) data.combine = this.combine;
  7641. if ( this.envMapIntensity !== undefined ) data.envMapIntensity = this.envMapIntensity;
  7642. }
  7643. if ( this.gradientMap && this.gradientMap.isTexture ) {
  7644. data.gradientMap = this.gradientMap.toJSON( meta ).uuid;
  7645. }
  7646. if ( this.size !== undefined ) data.size = this.size;
  7647. if ( this.sizeAttenuation !== undefined ) data.sizeAttenuation = this.sizeAttenuation;
  7648. if ( this.blending !== NormalBlending ) data.blending = this.blending;
  7649. if ( this.flatShading === true ) data.flatShading = this.flatShading;
  7650. if ( this.side !== FrontSide ) data.side = this.side;
  7651. if ( this.vertexColors !== NoColors ) data.vertexColors = this.vertexColors;
  7652. if ( this.opacity < 1 ) data.opacity = this.opacity;
  7653. if ( this.transparent === true ) data.transparent = this.transparent;
  7654. data.depthFunc = this.depthFunc;
  7655. data.depthTest = this.depthTest;
  7656. data.depthWrite = this.depthWrite;
  7657. // rotation (SpriteMaterial)
  7658. if ( this.rotation !== 0 ) data.rotation = this.rotation;
  7659. if ( this.polygonOffset === true ) data.polygonOffset = true;
  7660. if ( this.polygonOffsetFactor !== 0 ) data.polygonOffsetFactor = this.polygonOffsetFactor;
  7661. if ( this.polygonOffsetUnits !== 0 ) data.polygonOffsetUnits = this.polygonOffsetUnits;
  7662. if ( this.linewidth !== 1 ) data.linewidth = this.linewidth;
  7663. if ( this.dashSize !== undefined ) data.dashSize = this.dashSize;
  7664. if ( this.gapSize !== undefined ) data.gapSize = this.gapSize;
  7665. if ( this.scale !== undefined ) data.scale = this.scale;
  7666. if ( this.dithering === true ) data.dithering = true;
  7667. if ( this.alphaTest > 0 ) data.alphaTest = this.alphaTest;
  7668. if ( this.premultipliedAlpha === true ) data.premultipliedAlpha = this.premultipliedAlpha;
  7669. if ( this.wireframe === true ) data.wireframe = this.wireframe;
  7670. if ( this.wireframeLinewidth > 1 ) data.wireframeLinewidth = this.wireframeLinewidth;
  7671. if ( this.wireframeLinecap !== 'round' ) data.wireframeLinecap = this.wireframeLinecap;
  7672. if ( this.wireframeLinejoin !== 'round' ) data.wireframeLinejoin = this.wireframeLinejoin;
  7673. if ( this.morphTargets === true ) data.morphTargets = true;
  7674. if ( this.skinning === true ) data.skinning = true;
  7675. if ( this.visible === false ) data.visible = false;
  7676. if ( JSON.stringify( this.userData ) !== '{}' ) data.userData = this.userData;
  7677. // TODO: Copied from Object3D.toJSON
  7678. function extractFromCache( cache ) {
  7679. var values = [];
  7680. for ( var key in cache ) {
  7681. var data = cache[ key ];
  7682. delete data.metadata;
  7683. values.push( data );
  7684. }
  7685. return values;
  7686. }
  7687. if ( isRoot ) {
  7688. var textures = extractFromCache( meta.textures );
  7689. var images = extractFromCache( meta.images );
  7690. if ( textures.length > 0 ) data.textures = textures;
  7691. if ( images.length > 0 ) data.images = images;
  7692. }
  7693. return data;
  7694. },
  7695. clone: function () {
  7696. return new this.constructor().copy( this );
  7697. },
  7698. copy: function ( source ) {
  7699. this.name = source.name;
  7700. this.fog = source.fog;
  7701. this.lights = source.lights;
  7702. this.blending = source.blending;
  7703. this.side = source.side;
  7704. this.flatShading = source.flatShading;
  7705. this.vertexColors = source.vertexColors;
  7706. this.opacity = source.opacity;
  7707. this.transparent = source.transparent;
  7708. this.blendSrc = source.blendSrc;
  7709. this.blendDst = source.blendDst;
  7710. this.blendEquation = source.blendEquation;
  7711. this.blendSrcAlpha = source.blendSrcAlpha;
  7712. this.blendDstAlpha = source.blendDstAlpha;
  7713. this.blendEquationAlpha = source.blendEquationAlpha;
  7714. this.depthFunc = source.depthFunc;
  7715. this.depthTest = source.depthTest;
  7716. this.depthWrite = source.depthWrite;
  7717. this.colorWrite = source.colorWrite;
  7718. this.precision = source.precision;
  7719. this.polygonOffset = source.polygonOffset;
  7720. this.polygonOffsetFactor = source.polygonOffsetFactor;
  7721. this.polygonOffsetUnits = source.polygonOffsetUnits;
  7722. this.dithering = source.dithering;
  7723. this.alphaTest = source.alphaTest;
  7724. this.premultipliedAlpha = source.premultipliedAlpha;
  7725. this.visible = source.visible;
  7726. this.userData = JSON.parse( JSON.stringify( source.userData ) );
  7727. this.clipShadows = source.clipShadows;
  7728. this.clipIntersection = source.clipIntersection;
  7729. var srcPlanes = source.clippingPlanes,
  7730. dstPlanes = null;
  7731. if ( srcPlanes !== null ) {
  7732. var n = srcPlanes.length;
  7733. dstPlanes = new Array( n );
  7734. for ( var i = 0; i !== n; ++ i )
  7735. dstPlanes[ i ] = srcPlanes[ i ].clone();
  7736. }
  7737. this.clippingPlanes = dstPlanes;
  7738. this.shadowSide = source.shadowSide;
  7739. return this;
  7740. },
  7741. dispose: function () {
  7742. this.dispatchEvent( { type: 'dispose' } );
  7743. }
  7744. } );
  7745. var default_vertex = "void main() {\n\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}";
  7746. var default_fragment = "void main() {\n\tgl_FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );\n}";
  7747. /**
  7748. * @author alteredq / http://alteredqualia.com/
  7749. *
  7750. * parameters = {
  7751. * defines: { "label" : "value" },
  7752. * uniforms: { "parameter1": { value: 1.0 }, "parameter2": { value2: 2 } },
  7753. *
  7754. * fragmentShader: <string>,
  7755. * vertexShader: <string>,
  7756. *
  7757. * wireframe: <boolean>,
  7758. * wireframeLinewidth: <float>,
  7759. *
  7760. * lights: <bool>,
  7761. *
  7762. * skinning: <bool>,
  7763. * morphTargets: <bool>,
  7764. * morphNormals: <bool>
  7765. * }
  7766. */
  7767. function ShaderMaterial( parameters ) {
  7768. Material.call( this );
  7769. this.type = 'ShaderMaterial';
  7770. this.defines = {};
  7771. this.uniforms = {};
  7772. this.vertexShader = default_vertex;
  7773. this.fragmentShader = default_fragment;
  7774. this.linewidth = 1;
  7775. this.wireframe = false;
  7776. this.wireframeLinewidth = 1;
  7777. this.fog = false; // set to use scene fog
  7778. this.lights = false; // set to use scene lights
  7779. this.clipping = false; // set to use user-defined clipping planes
  7780. this.skinning = false; // set to use skinning attribute streams
  7781. this.morphTargets = false; // set to use morph targets
  7782. this.morphNormals = false; // set to use morph normals
  7783. this.extensions = {
  7784. derivatives: false, // set to use derivatives
  7785. fragDepth: false, // set to use fragment depth values
  7786. drawBuffers: false, // set to use draw buffers
  7787. shaderTextureLOD: false // set to use shader texture LOD
  7788. };
  7789. // When rendered geometry doesn't include these attributes but the material does,
  7790. // use these default values in WebGL. This avoids errors when buffer data is missing.
  7791. this.defaultAttributeValues = {
  7792. 'color': [ 1, 1, 1 ],
  7793. 'uv': [ 0, 0 ],
  7794. 'uv2': [ 0, 0 ]
  7795. };
  7796. this.index0AttributeName = undefined;
  7797. this.uniformsNeedUpdate = false;
  7798. if ( parameters !== undefined ) {
  7799. if ( parameters.attributes !== undefined ) {
  7800. console.error( 'THREE.ShaderMaterial: attributes should now be defined in THREE.BufferGeometry instead.' );
  7801. }
  7802. this.setValues( parameters );
  7803. }
  7804. }
  7805. ShaderMaterial.prototype = Object.create( Material.prototype );
  7806. ShaderMaterial.prototype.constructor = ShaderMaterial;
  7807. ShaderMaterial.prototype.isShaderMaterial = true;
  7808. ShaderMaterial.prototype.copy = function ( source ) {
  7809. Material.prototype.copy.call( this, source );
  7810. this.fragmentShader = source.fragmentShader;
  7811. this.vertexShader = source.vertexShader;
  7812. this.uniforms = cloneUniforms( source.uniforms );
  7813. this.defines = Object.assign( {}, source.defines );
  7814. this.wireframe = source.wireframe;
  7815. this.wireframeLinewidth = source.wireframeLinewidth;
  7816. this.lights = source.lights;
  7817. this.clipping = source.clipping;
  7818. this.skinning = source.skinning;
  7819. this.morphTargets = source.morphTargets;
  7820. this.morphNormals = source.morphNormals;
  7821. this.extensions = source.extensions;
  7822. return this;
  7823. };
  7824. ShaderMaterial.prototype.toJSON = function ( meta ) {
  7825. var data = Material.prototype.toJSON.call( this, meta );
  7826. data.uniforms = {};
  7827. for ( var name in this.uniforms ) {
  7828. var uniform = this.uniforms[ name ];
  7829. var value = uniform.value;
  7830. if ( value && value.isTexture ) {
  7831. data.uniforms[ name ] = {
  7832. type: 't',
  7833. value: value.toJSON( meta ).uuid
  7834. };
  7835. } else if ( value && value.isColor ) {
  7836. data.uniforms[ name ] = {
  7837. type: 'c',
  7838. value: value.getHex()
  7839. };
  7840. } else if ( value && value.isVector2 ) {
  7841. data.uniforms[ name ] = {
  7842. type: 'v2',
  7843. value: value.toArray()
  7844. };
  7845. } else if ( value && value.isVector3 ) {
  7846. data.uniforms[ name ] = {
  7847. type: 'v3',
  7848. value: value.toArray()
  7849. };
  7850. } else if ( value && value.isVector4 ) {
  7851. data.uniforms[ name ] = {
  7852. type: 'v4',
  7853. value: value.toArray()
  7854. };
  7855. } else if ( value && value.isMatrix3 ) {
  7856. data.uniforms[ name ] = {
  7857. type: 'm3',
  7858. value: value.toArray()
  7859. };
  7860. } else if ( value && value.isMatrix4 ) {
  7861. data.uniforms[ name ] = {
  7862. type: 'm4',
  7863. value: value.toArray()
  7864. };
  7865. } else {
  7866. data.uniforms[ name ] = {
  7867. value: value
  7868. };
  7869. // note: the array variants v2v, v3v, v4v, m4v and tv are not supported so far
  7870. }
  7871. }
  7872. if ( Object.keys( this.defines ).length > 0 ) data.defines = this.defines;
  7873. data.vertexShader = this.vertexShader;
  7874. data.fragmentShader = this.fragmentShader;
  7875. var extensions = {};
  7876. for ( var key in this.extensions ) {
  7877. if ( this.extensions[ key ] === true ) extensions[ key ] = true;
  7878. }
  7879. if ( Object.keys( extensions ).length > 0 ) data.extensions = extensions;
  7880. return data;
  7881. };
  7882. /**
  7883. * @author bhouston / http://clara.io
  7884. */
  7885. function Ray( origin, direction ) {
  7886. this.origin = ( origin !== undefined ) ? origin : new Vector3();
  7887. this.direction = ( direction !== undefined ) ? direction : new Vector3();
  7888. }
  7889. Object.assign( Ray.prototype, {
  7890. set: function ( origin, direction ) {
  7891. this.origin.copy( origin );
  7892. this.direction.copy( direction );
  7893. return this;
  7894. },
  7895. clone: function () {
  7896. return new this.constructor().copy( this );
  7897. },
  7898. copy: function ( ray ) {
  7899. this.origin.copy( ray.origin );
  7900. this.direction.copy( ray.direction );
  7901. return this;
  7902. },
  7903. at: function ( t, target ) {
  7904. if ( target === undefined ) {
  7905. console.warn( 'THREE.Ray: .at() target is now required' );
  7906. target = new Vector3();
  7907. }
  7908. return target.copy( this.direction ).multiplyScalar( t ).add( this.origin );
  7909. },
  7910. lookAt: function ( v ) {
  7911. this.direction.copy( v ).sub( this.origin ).normalize();
  7912. return this;
  7913. },
  7914. recast: function () {
  7915. var v1 = new Vector3();
  7916. return function recast( t ) {
  7917. this.origin.copy( this.at( t, v1 ) );
  7918. return this;
  7919. };
  7920. }(),
  7921. closestPointToPoint: function ( point, target ) {
  7922. if ( target === undefined ) {
  7923. console.warn( 'THREE.Ray: .closestPointToPoint() target is now required' );
  7924. target = new Vector3();
  7925. }
  7926. target.subVectors( point, this.origin );
  7927. var directionDistance = target.dot( this.direction );
  7928. if ( directionDistance < 0 ) {
  7929. return target.copy( this.origin );
  7930. }
  7931. return target.copy( this.direction ).multiplyScalar( directionDistance ).add( this.origin );
  7932. },
  7933. distanceToPoint: function ( point ) {
  7934. return Math.sqrt( this.distanceSqToPoint( point ) );
  7935. },
  7936. distanceSqToPoint: function () {
  7937. var v1 = new Vector3();
  7938. return function distanceSqToPoint( point ) {
  7939. var directionDistance = v1.subVectors( point, this.origin ).dot( this.direction );
  7940. // point behind the ray
  7941. if ( directionDistance < 0 ) {
  7942. return this.origin.distanceToSquared( point );
  7943. }
  7944. v1.copy( this.direction ).multiplyScalar( directionDistance ).add( this.origin );
  7945. return v1.distanceToSquared( point );
  7946. };
  7947. }(),
  7948. distanceSqToSegment: function () {
  7949. var segCenter = new Vector3();
  7950. var segDir = new Vector3();
  7951. var diff = new Vector3();
  7952. return function distanceSqToSegment( v0, v1, optionalPointOnRay, optionalPointOnSegment ) {
  7953. // from http://www.geometrictools.com/GTEngine/Include/Mathematics/GteDistRaySegment.h
  7954. // It returns the min distance between the ray and the segment
  7955. // defined by v0 and v1
  7956. // It can also set two optional targets :
  7957. // - The closest point on the ray
  7958. // - The closest point on the segment
  7959. segCenter.copy( v0 ).add( v1 ).multiplyScalar( 0.5 );
  7960. segDir.copy( v1 ).sub( v0 ).normalize();
  7961. diff.copy( this.origin ).sub( segCenter );
  7962. var segExtent = v0.distanceTo( v1 ) * 0.5;
  7963. var a01 = - this.direction.dot( segDir );
  7964. var b0 = diff.dot( this.direction );
  7965. var b1 = - diff.dot( segDir );
  7966. var c = diff.lengthSq();
  7967. var det = Math.abs( 1 - a01 * a01 );
  7968. var s0, s1, sqrDist, extDet;
  7969. if ( det > 0 ) {
  7970. // The ray and segment are not parallel.
  7971. s0 = a01 * b1 - b0;
  7972. s1 = a01 * b0 - b1;
  7973. extDet = segExtent * det;
  7974. if ( s0 >= 0 ) {
  7975. if ( s1 >= - extDet ) {
  7976. if ( s1 <= extDet ) {
  7977. // region 0
  7978. // Minimum at interior points of ray and segment.
  7979. var invDet = 1 / det;
  7980. s0 *= invDet;
  7981. s1 *= invDet;
  7982. sqrDist = s0 * ( s0 + a01 * s1 + 2 * b0 ) + s1 * ( a01 * s0 + s1 + 2 * b1 ) + c;
  7983. } else {
  7984. // region 1
  7985. s1 = segExtent;
  7986. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  7987. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  7988. }
  7989. } else {
  7990. // region 5
  7991. s1 = - segExtent;
  7992. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  7993. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  7994. }
  7995. } else {
  7996. if ( s1 <= - extDet ) {
  7997. // region 4
  7998. s0 = Math.max( 0, - ( - a01 * segExtent + b0 ) );
  7999. s1 = ( s0 > 0 ) ? - segExtent : Math.min( Math.max( - segExtent, - b1 ), segExtent );
  8000. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  8001. } else if ( s1 <= extDet ) {
  8002. // region 3
  8003. s0 = 0;
  8004. s1 = Math.min( Math.max( - segExtent, - b1 ), segExtent );
  8005. sqrDist = s1 * ( s1 + 2 * b1 ) + c;
  8006. } else {
  8007. // region 2
  8008. s0 = Math.max( 0, - ( a01 * segExtent + b0 ) );
  8009. s1 = ( s0 > 0 ) ? segExtent : Math.min( Math.max( - segExtent, - b1 ), segExtent );
  8010. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  8011. }
  8012. }
  8013. } else {
  8014. // Ray and segment are parallel.
  8015. s1 = ( a01 > 0 ) ? - segExtent : segExtent;
  8016. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  8017. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  8018. }
  8019. if ( optionalPointOnRay ) {
  8020. optionalPointOnRay.copy( this.direction ).multiplyScalar( s0 ).add( this.origin );
  8021. }
  8022. if ( optionalPointOnSegment ) {
  8023. optionalPointOnSegment.copy( segDir ).multiplyScalar( s1 ).add( segCenter );
  8024. }
  8025. return sqrDist;
  8026. };
  8027. }(),
  8028. intersectSphere: function () {
  8029. var v1 = new Vector3();
  8030. return function intersectSphere( sphere, target ) {
  8031. v1.subVectors( sphere.center, this.origin );
  8032. var tca = v1.dot( this.direction );
  8033. var d2 = v1.dot( v1 ) - tca * tca;
  8034. var radius2 = sphere.radius * sphere.radius;
  8035. if ( d2 > radius2 ) return null;
  8036. var thc = Math.sqrt( radius2 - d2 );
  8037. // t0 = first intersect point - entrance on front of sphere
  8038. var t0 = tca - thc;
  8039. // t1 = second intersect point - exit point on back of sphere
  8040. var t1 = tca + thc;
  8041. // test to see if both t0 and t1 are behind the ray - if so, return null
  8042. if ( t0 < 0 && t1 < 0 ) return null;
  8043. // test to see if t0 is behind the ray:
  8044. // if it is, the ray is inside the sphere, so return the second exit point scaled by t1,
  8045. // in order to always return an intersect point that is in front of the ray.
  8046. if ( t0 < 0 ) return this.at( t1, target );
  8047. // else t0 is in front of the ray, so return the first collision point scaled by t0
  8048. return this.at( t0, target );
  8049. };
  8050. }(),
  8051. intersectsSphere: function ( sphere ) {
  8052. return this.distanceSqToPoint( sphere.center ) <= ( sphere.radius * sphere.radius );
  8053. },
  8054. distanceToPlane: function ( plane ) {
  8055. var denominator = plane.normal.dot( this.direction );
  8056. if ( denominator === 0 ) {
  8057. // line is coplanar, return origin
  8058. if ( plane.distanceToPoint( this.origin ) === 0 ) {
  8059. return 0;
  8060. }
  8061. // Null is preferable to undefined since undefined means.... it is undefined
  8062. return null;
  8063. }
  8064. var t = - ( this.origin.dot( plane.normal ) + plane.constant ) / denominator;
  8065. // Return if the ray never intersects the plane
  8066. return t >= 0 ? t : null;
  8067. },
  8068. intersectPlane: function ( plane, target ) {
  8069. var t = this.distanceToPlane( plane );
  8070. if ( t === null ) {
  8071. return null;
  8072. }
  8073. return this.at( t, target );
  8074. },
  8075. intersectsPlane: function ( plane ) {
  8076. // check if the ray lies on the plane first
  8077. var distToPoint = plane.distanceToPoint( this.origin );
  8078. if ( distToPoint === 0 ) {
  8079. return true;
  8080. }
  8081. var denominator = plane.normal.dot( this.direction );
  8082. if ( denominator * distToPoint < 0 ) {
  8083. return true;
  8084. }
  8085. // ray origin is behind the plane (and is pointing behind it)
  8086. return false;
  8087. },
  8088. intersectBox: function ( box, target ) {
  8089. var tmin, tmax, tymin, tymax, tzmin, tzmax;
  8090. var invdirx = 1 / this.direction.x,
  8091. invdiry = 1 / this.direction.y,
  8092. invdirz = 1 / this.direction.z;
  8093. var origin = this.origin;
  8094. if ( invdirx >= 0 ) {
  8095. tmin = ( box.min.x - origin.x ) * invdirx;
  8096. tmax = ( box.max.x - origin.x ) * invdirx;
  8097. } else {
  8098. tmin = ( box.max.x - origin.x ) * invdirx;
  8099. tmax = ( box.min.x - origin.x ) * invdirx;
  8100. }
  8101. if ( invdiry >= 0 ) {
  8102. tymin = ( box.min.y - origin.y ) * invdiry;
  8103. tymax = ( box.max.y - origin.y ) * invdiry;
  8104. } else {
  8105. tymin = ( box.max.y - origin.y ) * invdiry;
  8106. tymax = ( box.min.y - origin.y ) * invdiry;
  8107. }
  8108. if ( ( tmin > tymax ) || ( tymin > tmax ) ) return null;
  8109. // These lines also handle the case where tmin or tmax is NaN
  8110. // (result of 0 * Infinity). x !== x returns true if x is NaN
  8111. if ( tymin > tmin || tmin !== tmin ) tmin = tymin;
  8112. if ( tymax < tmax || tmax !== tmax ) tmax = tymax;
  8113. if ( invdirz >= 0 ) {
  8114. tzmin = ( box.min.z - origin.z ) * invdirz;
  8115. tzmax = ( box.max.z - origin.z ) * invdirz;
  8116. } else {
  8117. tzmin = ( box.max.z - origin.z ) * invdirz;
  8118. tzmax = ( box.min.z - origin.z ) * invdirz;
  8119. }
  8120. if ( ( tmin > tzmax ) || ( tzmin > tmax ) ) return null;
  8121. if ( tzmin > tmin || tmin !== tmin ) tmin = tzmin;
  8122. if ( tzmax < tmax || tmax !== tmax ) tmax = tzmax;
  8123. //return point closest to the ray (positive side)
  8124. if ( tmax < 0 ) return null;
  8125. return this.at( tmin >= 0 ? tmin : tmax, target );
  8126. },
  8127. intersectsBox: ( function () {
  8128. var v = new Vector3();
  8129. return function intersectsBox( box ) {
  8130. return this.intersectBox( box, v ) !== null;
  8131. };
  8132. } )(),
  8133. intersectTriangle: function () {
  8134. // Compute the offset origin, edges, and normal.
  8135. var diff = new Vector3();
  8136. var edge1 = new Vector3();
  8137. var edge2 = new Vector3();
  8138. var normal = new Vector3();
  8139. return function intersectTriangle( a, b, c, backfaceCulling, target ) {
  8140. // from http://www.geometrictools.com/GTEngine/Include/Mathematics/GteIntrRay3Triangle3.h
  8141. edge1.subVectors( b, a );
  8142. edge2.subVectors( c, a );
  8143. normal.crossVectors( edge1, edge2 );
  8144. // Solve Q + t*D = b1*E1 + b2*E2 (Q = kDiff, D = ray direction,
  8145. // E1 = kEdge1, E2 = kEdge2, N = Cross(E1,E2)) by
  8146. // |Dot(D,N)|*b1 = sign(Dot(D,N))*Dot(D,Cross(Q,E2))
  8147. // |Dot(D,N)|*b2 = sign(Dot(D,N))*Dot(D,Cross(E1,Q))
  8148. // |Dot(D,N)|*t = -sign(Dot(D,N))*Dot(Q,N)
  8149. var DdN = this.direction.dot( normal );
  8150. var sign;
  8151. if ( DdN > 0 ) {
  8152. if ( backfaceCulling ) return null;
  8153. sign = 1;
  8154. } else if ( DdN < 0 ) {
  8155. sign = - 1;
  8156. DdN = - DdN;
  8157. } else {
  8158. return null;
  8159. }
  8160. diff.subVectors( this.origin, a );
  8161. var DdQxE2 = sign * this.direction.dot( edge2.crossVectors( diff, edge2 ) );
  8162. // b1 < 0, no intersection
  8163. if ( DdQxE2 < 0 ) {
  8164. return null;
  8165. }
  8166. var DdE1xQ = sign * this.direction.dot( edge1.cross( diff ) );
  8167. // b2 < 0, no intersection
  8168. if ( DdE1xQ < 0 ) {
  8169. return null;
  8170. }
  8171. // b1+b2 > 1, no intersection
  8172. if ( DdQxE2 + DdE1xQ > DdN ) {
  8173. return null;
  8174. }
  8175. // Line intersects triangle, check if ray does.
  8176. var QdN = - sign * diff.dot( normal );
  8177. // t < 0, no intersection
  8178. if ( QdN < 0 ) {
  8179. return null;
  8180. }
  8181. // Ray intersects triangle.
  8182. return this.at( QdN / DdN, target );
  8183. };
  8184. }(),
  8185. applyMatrix4: function ( matrix4 ) {
  8186. this.origin.applyMatrix4( matrix4 );
  8187. this.direction.transformDirection( matrix4 );
  8188. return this;
  8189. },
  8190. equals: function ( ray ) {
  8191. return ray.origin.equals( this.origin ) && ray.direction.equals( this.direction );
  8192. }
  8193. } );
  8194. /**
  8195. * @author bhouston / http://clara.io
  8196. * @author mrdoob / http://mrdoob.com/
  8197. */
  8198. function Triangle( a, b, c ) {
  8199. this.a = ( a !== undefined ) ? a : new Vector3();
  8200. this.b = ( b !== undefined ) ? b : new Vector3();
  8201. this.c = ( c !== undefined ) ? c : new Vector3();
  8202. }
  8203. Object.assign( Triangle, {
  8204. getNormal: function () {
  8205. var v0 = new Vector3();
  8206. return function getNormal( a, b, c, target ) {
  8207. if ( target === undefined ) {
  8208. console.warn( 'THREE.Triangle: .getNormal() target is now required' );
  8209. target = new Vector3();
  8210. }
  8211. target.subVectors( c, b );
  8212. v0.subVectors( a, b );
  8213. target.cross( v0 );
  8214. var targetLengthSq = target.lengthSq();
  8215. if ( targetLengthSq > 0 ) {
  8216. return target.multiplyScalar( 1 / Math.sqrt( targetLengthSq ) );
  8217. }
  8218. return target.set( 0, 0, 0 );
  8219. };
  8220. }(),
  8221. // static/instance method to calculate barycentric coordinates
  8222. // based on: http://www.blackpawn.com/texts/pointinpoly/default.html
  8223. getBarycoord: function () {
  8224. var v0 = new Vector3();
  8225. var v1 = new Vector3();
  8226. var v2 = new Vector3();
  8227. return function getBarycoord( point, a, b, c, target ) {
  8228. v0.subVectors( c, a );
  8229. v1.subVectors( b, a );
  8230. v2.subVectors( point, a );
  8231. var dot00 = v0.dot( v0 );
  8232. var dot01 = v0.dot( v1 );
  8233. var dot02 = v0.dot( v2 );
  8234. var dot11 = v1.dot( v1 );
  8235. var dot12 = v1.dot( v2 );
  8236. var denom = ( dot00 * dot11 - dot01 * dot01 );
  8237. if ( target === undefined ) {
  8238. console.warn( 'THREE.Triangle: .getBarycoord() target is now required' );
  8239. target = new Vector3();
  8240. }
  8241. // collinear or singular triangle
  8242. if ( denom === 0 ) {
  8243. // arbitrary location outside of triangle?
  8244. // not sure if this is the best idea, maybe should be returning undefined
  8245. return target.set( - 2, - 1, - 1 );
  8246. }
  8247. var invDenom = 1 / denom;
  8248. var u = ( dot11 * dot02 - dot01 * dot12 ) * invDenom;
  8249. var v = ( dot00 * dot12 - dot01 * dot02 ) * invDenom;
  8250. // barycentric coordinates must always sum to 1
  8251. return target.set( 1 - u - v, v, u );
  8252. };
  8253. }(),
  8254. containsPoint: function () {
  8255. var v1 = new Vector3();
  8256. return function containsPoint( point, a, b, c ) {
  8257. Triangle.getBarycoord( point, a, b, c, v1 );
  8258. return ( v1.x >= 0 ) && ( v1.y >= 0 ) && ( ( v1.x + v1.y ) <= 1 );
  8259. };
  8260. }(),
  8261. getUV: function () {
  8262. var barycoord = new Vector3();
  8263. return function getUV( point, p1, p2, p3, uv1, uv2, uv3, target ) {
  8264. this.getBarycoord( point, p1, p2, p3, barycoord );
  8265. target.set( 0, 0 );
  8266. target.addScaledVector( uv1, barycoord.x );
  8267. target.addScaledVector( uv2, barycoord.y );
  8268. target.addScaledVector( uv3, barycoord.z );
  8269. return target;
  8270. };
  8271. }()
  8272. } );
  8273. Object.assign( Triangle.prototype, {
  8274. set: function ( a, b, c ) {
  8275. this.a.copy( a );
  8276. this.b.copy( b );
  8277. this.c.copy( c );
  8278. return this;
  8279. },
  8280. setFromPointsAndIndices: function ( points, i0, i1, i2 ) {
  8281. this.a.copy( points[ i0 ] );
  8282. this.b.copy( points[ i1 ] );
  8283. this.c.copy( points[ i2 ] );
  8284. return this;
  8285. },
  8286. clone: function () {
  8287. return new this.constructor().copy( this );
  8288. },
  8289. copy: function ( triangle ) {
  8290. this.a.copy( triangle.a );
  8291. this.b.copy( triangle.b );
  8292. this.c.copy( triangle.c );
  8293. return this;
  8294. },
  8295. getArea: function () {
  8296. var v0 = new Vector3();
  8297. var v1 = new Vector3();
  8298. return function getArea() {
  8299. v0.subVectors( this.c, this.b );
  8300. v1.subVectors( this.a, this.b );
  8301. return v0.cross( v1 ).length() * 0.5;
  8302. };
  8303. }(),
  8304. getMidpoint: function ( target ) {
  8305. if ( target === undefined ) {
  8306. console.warn( 'THREE.Triangle: .getMidpoint() target is now required' );
  8307. target = new Vector3();
  8308. }
  8309. return target.addVectors( this.a, this.b ).add( this.c ).multiplyScalar( 1 / 3 );
  8310. },
  8311. getNormal: function ( target ) {
  8312. return Triangle.getNormal( this.a, this.b, this.c, target );
  8313. },
  8314. getPlane: function ( target ) {
  8315. if ( target === undefined ) {
  8316. console.warn( 'THREE.Triangle: .getPlane() target is now required' );
  8317. target = new Vector3();
  8318. }
  8319. return target.setFromCoplanarPoints( this.a, this.b, this.c );
  8320. },
  8321. getBarycoord: function ( point, target ) {
  8322. return Triangle.getBarycoord( point, this.a, this.b, this.c, target );
  8323. },
  8324. containsPoint: function ( point ) {
  8325. return Triangle.containsPoint( point, this.a, this.b, this.c );
  8326. },
  8327. getUV: function ( point, uv1, uv2, uv3, result ) {
  8328. return Triangle.getUV( point, this.a, this.b, this.c, uv1, uv2, uv3, result );
  8329. },
  8330. intersectsBox: function ( box ) {
  8331. return box.intersectsTriangle( this );
  8332. },
  8333. closestPointToPoint: function () {
  8334. var vab = new Vector3();
  8335. var vac = new Vector3();
  8336. var vbc = new Vector3();
  8337. var vap = new Vector3();
  8338. var vbp = new Vector3();
  8339. var vcp = new Vector3();
  8340. return function closestPointToPoint( p, target ) {
  8341. if ( target === undefined ) {
  8342. console.warn( 'THREE.Triangle: .closestPointToPoint() target is now required' );
  8343. target = new Vector3();
  8344. }
  8345. var a = this.a, b = this.b, c = this.c;
  8346. var v, w;
  8347. // algorithm thanks to Real-Time Collision Detection by Christer Ericson,
  8348. // published by Morgan Kaufmann Publishers, (c) 2005 Elsevier Inc.,
  8349. // under the accompanying license; see chapter 5.1.5 for detailed explanation.
  8350. // basically, we're distinguishing which of the voronoi regions of the triangle
  8351. // the point lies in with the minimum amount of redundant computation.
  8352. vab.subVectors( b, a );
  8353. vac.subVectors( c, a );
  8354. vap.subVectors( p, a );
  8355. var d1 = vab.dot( vap );
  8356. var d2 = vac.dot( vap );
  8357. if ( d1 <= 0 && d2 <= 0 ) {
  8358. // vertex region of A; barycentric coords (1, 0, 0)
  8359. return target.copy( a );
  8360. }
  8361. vbp.subVectors( p, b );
  8362. var d3 = vab.dot( vbp );
  8363. var d4 = vac.dot( vbp );
  8364. if ( d3 >= 0 && d4 <= d3 ) {
  8365. // vertex region of B; barycentric coords (0, 1, 0)
  8366. return target.copy( b );
  8367. }
  8368. var vc = d1 * d4 - d3 * d2;
  8369. if ( vc <= 0 && d1 >= 0 && d3 <= 0 ) {
  8370. v = d1 / ( d1 - d3 );
  8371. // edge region of AB; barycentric coords (1-v, v, 0)
  8372. return target.copy( a ).addScaledVector( vab, v );
  8373. }
  8374. vcp.subVectors( p, c );
  8375. var d5 = vab.dot( vcp );
  8376. var d6 = vac.dot( vcp );
  8377. if ( d6 >= 0 && d5 <= d6 ) {
  8378. // vertex region of C; barycentric coords (0, 0, 1)
  8379. return target.copy( c );
  8380. }
  8381. var vb = d5 * d2 - d1 * d6;
  8382. if ( vb <= 0 && d2 >= 0 && d6 <= 0 ) {
  8383. w = d2 / ( d2 - d6 );
  8384. // edge region of AC; barycentric coords (1-w, 0, w)
  8385. return target.copy( a ).addScaledVector( vac, w );
  8386. }
  8387. var va = d3 * d6 - d5 * d4;
  8388. if ( va <= 0 && ( d4 - d3 ) >= 0 && ( d5 - d6 ) >= 0 ) {
  8389. vbc.subVectors( c, b );
  8390. w = ( d4 - d3 ) / ( ( d4 - d3 ) + ( d5 - d6 ) );
  8391. // edge region of BC; barycentric coords (0, 1-w, w)
  8392. return target.copy( b ).addScaledVector( vbc, w ); // edge region of BC
  8393. }
  8394. // face region
  8395. var denom = 1 / ( va + vb + vc );
  8396. // u = va * denom
  8397. v = vb * denom;
  8398. w = vc * denom;
  8399. return target.copy( a ).addScaledVector( vab, v ).addScaledVector( vac, w );
  8400. };
  8401. }(),
  8402. equals: function ( triangle ) {
  8403. return triangle.a.equals( this.a ) && triangle.b.equals( this.b ) && triangle.c.equals( this.c );
  8404. }
  8405. } );
  8406. /**
  8407. * @author mrdoob / http://mrdoob.com/
  8408. * @author alteredq / http://alteredqualia.com/
  8409. *
  8410. * parameters = {
  8411. * color: <hex>,
  8412. * opacity: <float>,
  8413. * map: new THREE.Texture( <Image> ),
  8414. *
  8415. * lightMap: new THREE.Texture( <Image> ),
  8416. * lightMapIntensity: <float>
  8417. *
  8418. * aoMap: new THREE.Texture( <Image> ),
  8419. * aoMapIntensity: <float>
  8420. *
  8421. * specularMap: new THREE.Texture( <Image> ),
  8422. *
  8423. * alphaMap: new THREE.Texture( <Image> ),
  8424. *
  8425. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  8426. * combine: THREE.Multiply,
  8427. * reflectivity: <float>,
  8428. * refractionRatio: <float>,
  8429. *
  8430. * depthTest: <bool>,
  8431. * depthWrite: <bool>,
  8432. *
  8433. * wireframe: <boolean>,
  8434. * wireframeLinewidth: <float>,
  8435. *
  8436. * skinning: <bool>,
  8437. * morphTargets: <bool>
  8438. * }
  8439. */
  8440. function MeshBasicMaterial( parameters ) {
  8441. Material.call( this );
  8442. this.type = 'MeshBasicMaterial';
  8443. this.color = new Color( 0xffffff ); // emissive
  8444. this.map = null;
  8445. this.lightMap = null;
  8446. this.lightMapIntensity = 1.0;
  8447. this.aoMap = null;
  8448. this.aoMapIntensity = 1.0;
  8449. this.specularMap = null;
  8450. this.alphaMap = null;
  8451. this.envMap = null;
  8452. this.combine = MultiplyOperation;
  8453. this.reflectivity = 1;
  8454. this.refractionRatio = 0.98;
  8455. this.wireframe = false;
  8456. this.wireframeLinewidth = 1;
  8457. this.wireframeLinecap = 'round';
  8458. this.wireframeLinejoin = 'round';
  8459. this.skinning = false;
  8460. this.morphTargets = false;
  8461. this.lights = false;
  8462. this.setValues( parameters );
  8463. }
  8464. MeshBasicMaterial.prototype = Object.create( Material.prototype );
  8465. MeshBasicMaterial.prototype.constructor = MeshBasicMaterial;
  8466. MeshBasicMaterial.prototype.isMeshBasicMaterial = true;
  8467. MeshBasicMaterial.prototype.copy = function ( source ) {
  8468. Material.prototype.copy.call( this, source );
  8469. this.color.copy( source.color );
  8470. this.map = source.map;
  8471. this.lightMap = source.lightMap;
  8472. this.lightMapIntensity = source.lightMapIntensity;
  8473. this.aoMap = source.aoMap;
  8474. this.aoMapIntensity = source.aoMapIntensity;
  8475. this.specularMap = source.specularMap;
  8476. this.alphaMap = source.alphaMap;
  8477. this.envMap = source.envMap;
  8478. this.combine = source.combine;
  8479. this.reflectivity = source.reflectivity;
  8480. this.refractionRatio = source.refractionRatio;
  8481. this.wireframe = source.wireframe;
  8482. this.wireframeLinewidth = source.wireframeLinewidth;
  8483. this.wireframeLinecap = source.wireframeLinecap;
  8484. this.wireframeLinejoin = source.wireframeLinejoin;
  8485. this.skinning = source.skinning;
  8486. this.morphTargets = source.morphTargets;
  8487. return this;
  8488. };
  8489. /**
  8490. * @author mrdoob / http://mrdoob.com/
  8491. * @author alteredq / http://alteredqualia.com/
  8492. * @author mikael emtinger / http://gomo.se/
  8493. * @author jonobr1 / http://jonobr1.com/
  8494. */
  8495. function Mesh( geometry, material ) {
  8496. Object3D.call( this );
  8497. this.type = 'Mesh';
  8498. this.geometry = geometry !== undefined ? geometry : new BufferGeometry();
  8499. this.material = material !== undefined ? material : new MeshBasicMaterial( { color: Math.random() * 0xffffff } );
  8500. this.drawMode = TrianglesDrawMode;
  8501. this.updateMorphTargets();
  8502. }
  8503. Mesh.prototype = Object.assign( Object.create( Object3D.prototype ), {
  8504. constructor: Mesh,
  8505. isMesh: true,
  8506. setDrawMode: function ( value ) {
  8507. this.drawMode = value;
  8508. },
  8509. copy: function ( source ) {
  8510. Object3D.prototype.copy.call( this, source );
  8511. this.drawMode = source.drawMode;
  8512. if ( source.morphTargetInfluences !== undefined ) {
  8513. this.morphTargetInfluences = source.morphTargetInfluences.slice();
  8514. }
  8515. if ( source.morphTargetDictionary !== undefined ) {
  8516. this.morphTargetDictionary = Object.assign( {}, source.morphTargetDictionary );
  8517. }
  8518. return this;
  8519. },
  8520. updateMorphTargets: function () {
  8521. var geometry = this.geometry;
  8522. var m, ml, name;
  8523. if ( geometry.isBufferGeometry ) {
  8524. var morphAttributes = geometry.morphAttributes;
  8525. var keys = Object.keys( morphAttributes );
  8526. if ( keys.length > 0 ) {
  8527. var morphAttribute = morphAttributes[ keys[ 0 ] ];
  8528. if ( morphAttribute !== undefined ) {
  8529. this.morphTargetInfluences = [];
  8530. this.morphTargetDictionary = {};
  8531. for ( m = 0, ml = morphAttribute.length; m < ml; m ++ ) {
  8532. name = morphAttribute[ m ].name || String( m );
  8533. this.morphTargetInfluences.push( 0 );
  8534. this.morphTargetDictionary[ name ] = m;
  8535. }
  8536. }
  8537. }
  8538. } else {
  8539. var morphTargets = geometry.morphTargets;
  8540. if ( morphTargets !== undefined && morphTargets.length > 0 ) {
  8541. console.error( 'THREE.Mesh.updateMorphTargets() no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.' );
  8542. }
  8543. }
  8544. },
  8545. raycast: ( function () {
  8546. var inverseMatrix = new Matrix4();
  8547. var ray = new Ray();
  8548. var sphere = new Sphere();
  8549. var vA = new Vector3();
  8550. var vB = new Vector3();
  8551. var vC = new Vector3();
  8552. var tempA = new Vector3();
  8553. var tempB = new Vector3();
  8554. var tempC = new Vector3();
  8555. var uvA = new Vector2();
  8556. var uvB = new Vector2();
  8557. var uvC = new Vector2();
  8558. var intersectionPoint = new Vector3();
  8559. var intersectionPointWorld = new Vector3();
  8560. function checkIntersection( object, material, raycaster, ray, pA, pB, pC, point ) {
  8561. var intersect;
  8562. if ( material.side === BackSide ) {
  8563. intersect = ray.intersectTriangle( pC, pB, pA, true, point );
  8564. } else {
  8565. intersect = ray.intersectTriangle( pA, pB, pC, material.side !== DoubleSide, point );
  8566. }
  8567. if ( intersect === null ) return null;
  8568. intersectionPointWorld.copy( point );
  8569. intersectionPointWorld.applyMatrix4( object.matrixWorld );
  8570. var distance = raycaster.ray.origin.distanceTo( intersectionPointWorld );
  8571. if ( distance < raycaster.near || distance > raycaster.far ) return null;
  8572. return {
  8573. distance: distance,
  8574. point: intersectionPointWorld.clone(),
  8575. object: object
  8576. };
  8577. }
  8578. function checkBufferGeometryIntersection( object, material, raycaster, ray, position, uv, a, b, c ) {
  8579. vA.fromBufferAttribute( position, a );
  8580. vB.fromBufferAttribute( position, b );
  8581. vC.fromBufferAttribute( position, c );
  8582. var intersection = checkIntersection( object, material, raycaster, ray, vA, vB, vC, intersectionPoint );
  8583. if ( intersection ) {
  8584. if ( uv ) {
  8585. uvA.fromBufferAttribute( uv, a );
  8586. uvB.fromBufferAttribute( uv, b );
  8587. uvC.fromBufferAttribute( uv, c );
  8588. intersection.uv = Triangle.getUV( intersectionPoint, vA, vB, vC, uvA, uvB, uvC, new Vector2() );
  8589. }
  8590. var face = new Face3( a, b, c );
  8591. Triangle.getNormal( vA, vB, vC, face.normal );
  8592. intersection.face = face;
  8593. }
  8594. return intersection;
  8595. }
  8596. return function raycast( raycaster, intersects ) {
  8597. var geometry = this.geometry;
  8598. var material = this.material;
  8599. var matrixWorld = this.matrixWorld;
  8600. if ( material === undefined ) return;
  8601. // Checking boundingSphere distance to ray
  8602. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  8603. sphere.copy( geometry.boundingSphere );
  8604. sphere.applyMatrix4( matrixWorld );
  8605. if ( raycaster.ray.intersectsSphere( sphere ) === false ) return;
  8606. //
  8607. inverseMatrix.getInverse( matrixWorld );
  8608. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  8609. // Check boundingBox before continuing
  8610. if ( geometry.boundingBox !== null ) {
  8611. if ( ray.intersectsBox( geometry.boundingBox ) === false ) return;
  8612. }
  8613. var intersection;
  8614. if ( geometry.isBufferGeometry ) {
  8615. var a, b, c;
  8616. var index = geometry.index;
  8617. var position = geometry.attributes.position;
  8618. var uv = geometry.attributes.uv;
  8619. var groups = geometry.groups;
  8620. var drawRange = geometry.drawRange;
  8621. var i, j, il, jl;
  8622. var group, groupMaterial;
  8623. var start, end;
  8624. if ( index !== null ) {
  8625. // indexed buffer geometry
  8626. if ( Array.isArray( material ) ) {
  8627. for ( i = 0, il = groups.length; i < il; i ++ ) {
  8628. group = groups[ i ];
  8629. groupMaterial = material[ group.materialIndex ];
  8630. start = Math.max( group.start, drawRange.start );
  8631. end = Math.min( ( group.start + group.count ), ( drawRange.start + drawRange.count ) );
  8632. for ( j = start, jl = end; j < jl; j += 3 ) {
  8633. a = index.getX( j );
  8634. b = index.getX( j + 1 );
  8635. c = index.getX( j + 2 );
  8636. intersection = checkBufferGeometryIntersection( this, groupMaterial, raycaster, ray, position, uv, a, b, c );
  8637. if ( intersection ) {
  8638. intersection.faceIndex = Math.floor( j / 3 ); // triangle number in indexed buffer semantics
  8639. intersection.face.materialIndex = group.materialIndex;
  8640. intersects.push( intersection );
  8641. }
  8642. }
  8643. }
  8644. } else {
  8645. start = Math.max( 0, drawRange.start );
  8646. end = Math.min( index.count, ( drawRange.start + drawRange.count ) );
  8647. for ( i = start, il = end; i < il; i += 3 ) {
  8648. a = index.getX( i );
  8649. b = index.getX( i + 1 );
  8650. c = index.getX( i + 2 );
  8651. intersection = checkBufferGeometryIntersection( this, material, raycaster, ray, position, uv, a, b, c );
  8652. if ( intersection ) {
  8653. intersection.faceIndex = Math.floor( i / 3 ); // triangle number in indexed buffer semantics
  8654. intersects.push( intersection );
  8655. }
  8656. }
  8657. }
  8658. } else if ( position !== undefined ) {
  8659. // non-indexed buffer geometry
  8660. if ( Array.isArray( material ) ) {
  8661. for ( i = 0, il = groups.length; i < il; i ++ ) {
  8662. group = groups[ i ];
  8663. groupMaterial = material[ group.materialIndex ];
  8664. start = Math.max( group.start, drawRange.start );
  8665. end = Math.min( ( group.start + group.count ), ( drawRange.start + drawRange.count ) );
  8666. for ( j = start, jl = end; j < jl; j += 3 ) {
  8667. a = j;
  8668. b = j + 1;
  8669. c = j + 2;
  8670. intersection = checkBufferGeometryIntersection( this, groupMaterial, raycaster, ray, position, uv, a, b, c );
  8671. if ( intersection ) {
  8672. intersection.faceIndex = Math.floor( j / 3 ); // triangle number in non-indexed buffer semantics
  8673. intersection.face.materialIndex = group.materialIndex;
  8674. intersects.push( intersection );
  8675. }
  8676. }
  8677. }
  8678. } else {
  8679. start = Math.max( 0, drawRange.start );
  8680. end = Math.min( position.count, ( drawRange.start + drawRange.count ) );
  8681. for ( i = start, il = end; i < il; i += 3 ) {
  8682. a = i;
  8683. b = i + 1;
  8684. c = i + 2;
  8685. intersection = checkBufferGeometryIntersection( this, material, raycaster, ray, position, uv, a, b, c );
  8686. if ( intersection ) {
  8687. intersection.faceIndex = Math.floor( i / 3 ); // triangle number in non-indexed buffer semantics
  8688. intersects.push( intersection );
  8689. }
  8690. }
  8691. }
  8692. }
  8693. } else if ( geometry.isGeometry ) {
  8694. var fvA, fvB, fvC;
  8695. var isMultiMaterial = Array.isArray( material );
  8696. var vertices = geometry.vertices;
  8697. var faces = geometry.faces;
  8698. var uvs;
  8699. var faceVertexUvs = geometry.faceVertexUvs[ 0 ];
  8700. if ( faceVertexUvs.length > 0 ) uvs = faceVertexUvs;
  8701. for ( var f = 0, fl = faces.length; f < fl; f ++ ) {
  8702. var face = faces[ f ];
  8703. var faceMaterial = isMultiMaterial ? material[ face.materialIndex ] : material;
  8704. if ( faceMaterial === undefined ) continue;
  8705. fvA = vertices[ face.a ];
  8706. fvB = vertices[ face.b ];
  8707. fvC = vertices[ face.c ];
  8708. if ( faceMaterial.morphTargets === true ) {
  8709. var morphTargets = geometry.morphTargets;
  8710. var morphInfluences = this.morphTargetInfluences;
  8711. vA.set( 0, 0, 0 );
  8712. vB.set( 0, 0, 0 );
  8713. vC.set( 0, 0, 0 );
  8714. for ( var t = 0, tl = morphTargets.length; t < tl; t ++ ) {
  8715. var influence = morphInfluences[ t ];
  8716. if ( influence === 0 ) continue;
  8717. var targets = morphTargets[ t ].vertices;
  8718. vA.addScaledVector( tempA.subVectors( targets[ face.a ], fvA ), influence );
  8719. vB.addScaledVector( tempB.subVectors( targets[ face.b ], fvB ), influence );
  8720. vC.addScaledVector( tempC.subVectors( targets[ face.c ], fvC ), influence );
  8721. }
  8722. vA.add( fvA );
  8723. vB.add( fvB );
  8724. vC.add( fvC );
  8725. fvA = vA;
  8726. fvB = vB;
  8727. fvC = vC;
  8728. }
  8729. intersection = checkIntersection( this, faceMaterial, raycaster, ray, fvA, fvB, fvC, intersectionPoint );
  8730. if ( intersection ) {
  8731. if ( uvs && uvs[ f ] ) {
  8732. var uvs_f = uvs[ f ];
  8733. uvA.copy( uvs_f[ 0 ] );
  8734. uvB.copy( uvs_f[ 1 ] );
  8735. uvC.copy( uvs_f[ 2 ] );
  8736. intersection.uv = Triangle.getUV( intersectionPoint, fvA, fvB, fvC, uvA, uvB, uvC, new Vector2() );
  8737. }
  8738. intersection.face = face;
  8739. intersection.faceIndex = f;
  8740. intersects.push( intersection );
  8741. }
  8742. }
  8743. }
  8744. };
  8745. }() ),
  8746. clone: function () {
  8747. return new this.constructor( this.geometry, this.material ).copy( this );
  8748. }
  8749. } );
  8750. /**
  8751. * @author mrdoob / http://mrdoob.com/
  8752. */
  8753. function WebGLBackground( renderer, state, objects, premultipliedAlpha ) {
  8754. var clearColor = new Color( 0x000000 );
  8755. var clearAlpha = 0;
  8756. var planeMesh;
  8757. var boxMesh;
  8758. // Store the current background texture and its `version`
  8759. // so we can recompile the material accordingly.
  8760. var currentBackground = null;
  8761. var currentBackgroundVersion = 0;
  8762. function render( renderList, scene, camera, forceClear ) {
  8763. var background = scene.background;
  8764. if ( background === null ) {
  8765. setClear( clearColor, clearAlpha );
  8766. currentBackground = null;
  8767. currentBackgroundVersion = 0;
  8768. } else if ( background && background.isColor ) {
  8769. setClear( background, 1 );
  8770. forceClear = true;
  8771. currentBackground = null;
  8772. currentBackgroundVersion = 0;
  8773. }
  8774. if ( renderer.autoClear || forceClear ) {
  8775. renderer.clear( renderer.autoClearColor, renderer.autoClearDepth, renderer.autoClearStencil );
  8776. }
  8777. if ( background && ( background.isCubeTexture || background.isWebGLRenderTargetCube ) ) {
  8778. if ( boxMesh === undefined ) {
  8779. boxMesh = new Mesh(
  8780. new BoxBufferGeometry( 1, 1, 1 ),
  8781. new ShaderMaterial( {
  8782. type: 'BackgroundCubeMaterial',
  8783. uniforms: cloneUniforms( ShaderLib.cube.uniforms ),
  8784. vertexShader: ShaderLib.cube.vertexShader,
  8785. fragmentShader: ShaderLib.cube.fragmentShader,
  8786. side: BackSide,
  8787. depthTest: false,
  8788. depthWrite: false,
  8789. fog: false
  8790. } )
  8791. );
  8792. boxMesh.geometry.removeAttribute( 'normal' );
  8793. boxMesh.geometry.removeAttribute( 'uv' );
  8794. boxMesh.onBeforeRender = function ( renderer, scene, camera ) {
  8795. this.matrixWorld.copyPosition( camera.matrixWorld );
  8796. };
  8797. // enable code injection for non-built-in material
  8798. Object.defineProperty( boxMesh.material, 'map', {
  8799. get: function () {
  8800. return this.uniforms.tCube.value;
  8801. }
  8802. } );
  8803. objects.update( boxMesh );
  8804. }
  8805. var texture = background.isWebGLRenderTargetCube ? background.texture : background;
  8806. boxMesh.material.uniforms.tCube.value = texture;
  8807. boxMesh.material.uniforms.tFlip.value = ( background.isWebGLRenderTargetCube ) ? 1 : - 1;
  8808. if ( currentBackground !== background ||
  8809. currentBackgroundVersion !== texture.version ) {
  8810. boxMesh.material.needsUpdate = true;
  8811. currentBackground = background;
  8812. currentBackgroundVersion = texture.version;
  8813. }
  8814. // push to the pre-sorted opaque render list
  8815. renderList.unshift( boxMesh, boxMesh.geometry, boxMesh.material, 0, 0, null );
  8816. } else if ( background && background.isTexture ) {
  8817. if ( planeMesh === undefined ) {
  8818. planeMesh = new Mesh(
  8819. new PlaneBufferGeometry( 2, 2 ),
  8820. new ShaderMaterial( {
  8821. type: 'BackgroundMaterial',
  8822. uniforms: cloneUniforms( ShaderLib.background.uniforms ),
  8823. vertexShader: ShaderLib.background.vertexShader,
  8824. fragmentShader: ShaderLib.background.fragmentShader,
  8825. side: FrontSide,
  8826. depthTest: false,
  8827. depthWrite: false,
  8828. fog: false
  8829. } )
  8830. );
  8831. planeMesh.geometry.removeAttribute( 'normal' );
  8832. // enable code injection for non-built-in material
  8833. Object.defineProperty( planeMesh.material, 'map', {
  8834. get: function () {
  8835. return this.uniforms.t2D.value;
  8836. }
  8837. } );
  8838. objects.update( planeMesh );
  8839. }
  8840. planeMesh.material.uniforms.t2D.value = background;
  8841. if ( background.matrixAutoUpdate === true ) {
  8842. background.updateMatrix();
  8843. }
  8844. planeMesh.material.uniforms.uvTransform.value.copy( background.matrix );
  8845. if ( currentBackground !== background ||
  8846. currentBackgroundVersion !== background.version ) {
  8847. planeMesh.material.needsUpdate = true;
  8848. currentBackground = background;
  8849. currentBackgroundVersion = background.version;
  8850. }
  8851. // push to the pre-sorted opaque render list
  8852. renderList.unshift( planeMesh, planeMesh.geometry, planeMesh.material, 0, 0, null );
  8853. }
  8854. }
  8855. function setClear( color, alpha ) {
  8856. state.buffers.color.setClear( color.r, color.g, color.b, alpha, premultipliedAlpha );
  8857. }
  8858. return {
  8859. getClearColor: function () {
  8860. return clearColor;
  8861. },
  8862. setClearColor: function ( color, alpha ) {
  8863. clearColor.set( color );
  8864. clearAlpha = alpha !== undefined ? alpha : 1;
  8865. setClear( clearColor, clearAlpha );
  8866. },
  8867. getClearAlpha: function () {
  8868. return clearAlpha;
  8869. },
  8870. setClearAlpha: function ( alpha ) {
  8871. clearAlpha = alpha;
  8872. setClear( clearColor, clearAlpha );
  8873. },
  8874. render: render
  8875. };
  8876. }
  8877. /**
  8878. * @author mrdoob / http://mrdoob.com/
  8879. */
  8880. function WebGLBufferRenderer( gl, extensions, info, capabilities ) {
  8881. var mode;
  8882. function setMode( value ) {
  8883. mode = value;
  8884. }
  8885. function render( start, count ) {
  8886. gl.drawArrays( mode, start, count );
  8887. info.update( count, mode );
  8888. }
  8889. function renderInstances( geometry, start, count ) {
  8890. var extension;
  8891. if ( capabilities.isWebGL2 ) {
  8892. extension = gl;
  8893. } else {
  8894. extension = extensions.get( 'ANGLE_instanced_arrays' );
  8895. if ( extension === null ) {
  8896. console.error( 'THREE.WebGLBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  8897. return;
  8898. }
  8899. }
  8900. extension[ capabilities.isWebGL2 ? 'drawArraysInstanced' : 'drawArraysInstancedANGLE' ]( mode, start, count, geometry.maxInstancedCount );
  8901. info.update( count, mode, geometry.maxInstancedCount );
  8902. }
  8903. //
  8904. this.setMode = setMode;
  8905. this.render = render;
  8906. this.renderInstances = renderInstances;
  8907. }
  8908. /**
  8909. * @author mrdoob / http://mrdoob.com/
  8910. */
  8911. function WebGLCapabilities( gl, extensions, parameters ) {
  8912. var maxAnisotropy;
  8913. function getMaxAnisotropy() {
  8914. if ( maxAnisotropy !== undefined ) return maxAnisotropy;
  8915. var extension = extensions.get( 'EXT_texture_filter_anisotropic' );
  8916. if ( extension !== null ) {
  8917. maxAnisotropy = gl.getParameter( extension.MAX_TEXTURE_MAX_ANISOTROPY_EXT );
  8918. } else {
  8919. maxAnisotropy = 0;
  8920. }
  8921. return maxAnisotropy;
  8922. }
  8923. function getMaxPrecision( precision ) {
  8924. if ( precision === 'highp' ) {
  8925. if ( gl.getShaderPrecisionFormat( 35633, 36338 ).precision > 0 &&
  8926. gl.getShaderPrecisionFormat( 35632, 36338 ).precision > 0 ) {
  8927. return 'highp';
  8928. }
  8929. precision = 'mediump';
  8930. }
  8931. if ( precision === 'mediump' ) {
  8932. if ( gl.getShaderPrecisionFormat( 35633, 36337 ).precision > 0 &&
  8933. gl.getShaderPrecisionFormat( 35632, 36337 ).precision > 0 ) {
  8934. return 'mediump';
  8935. }
  8936. }
  8937. return 'lowp';
  8938. }
  8939. var isWebGL2 = typeof WebGL2RenderingContext !== 'undefined' && gl instanceof WebGL2RenderingContext;
  8940. var precision = parameters.precision !== undefined ? parameters.precision : 'highp';
  8941. var maxPrecision = getMaxPrecision( precision );
  8942. if ( maxPrecision !== precision ) {
  8943. console.warn( 'THREE.WebGLRenderer:', precision, 'not supported, using', maxPrecision, 'instead.' );
  8944. precision = maxPrecision;
  8945. }
  8946. var logarithmicDepthBuffer = parameters.logarithmicDepthBuffer === true;
  8947. var maxTextures = gl.getParameter( 34930 );
  8948. var maxVertexTextures = gl.getParameter( 35660 );
  8949. var maxTextureSize = gl.getParameter( 3379 );
  8950. var maxCubemapSize = gl.getParameter( 34076 );
  8951. var maxAttributes = gl.getParameter( 34921 );
  8952. var maxVertexUniforms = gl.getParameter( 36347 );
  8953. var maxVaryings = gl.getParameter( 36348 );
  8954. var maxFragmentUniforms = gl.getParameter( 36349 );
  8955. var vertexTextures = maxVertexTextures > 0;
  8956. var floatFragmentTextures = isWebGL2 || !! extensions.get( 'OES_texture_float' );
  8957. var floatVertexTextures = vertexTextures && floatFragmentTextures;
  8958. var maxSamples = isWebGL2 ? gl.getParameter( 36183 ) : 0;
  8959. return {
  8960. isWebGL2: isWebGL2,
  8961. getMaxAnisotropy: getMaxAnisotropy,
  8962. getMaxPrecision: getMaxPrecision,
  8963. precision: precision,
  8964. logarithmicDepthBuffer: logarithmicDepthBuffer,
  8965. maxTextures: maxTextures,
  8966. maxVertexTextures: maxVertexTextures,
  8967. maxTextureSize: maxTextureSize,
  8968. maxCubemapSize: maxCubemapSize,
  8969. maxAttributes: maxAttributes,
  8970. maxVertexUniforms: maxVertexUniforms,
  8971. maxVaryings: maxVaryings,
  8972. maxFragmentUniforms: maxFragmentUniforms,
  8973. vertexTextures: vertexTextures,
  8974. floatFragmentTextures: floatFragmentTextures,
  8975. floatVertexTextures: floatVertexTextures,
  8976. maxSamples: maxSamples
  8977. };
  8978. }
  8979. /**
  8980. * @author tschw
  8981. */
  8982. function WebGLClipping() {
  8983. var scope = this,
  8984. globalState = null,
  8985. numGlobalPlanes = 0,
  8986. localClippingEnabled = false,
  8987. renderingShadows = false,
  8988. plane = new Plane(),
  8989. viewNormalMatrix = new Matrix3(),
  8990. uniform = { value: null, needsUpdate: false };
  8991. this.uniform = uniform;
  8992. this.numPlanes = 0;
  8993. this.numIntersection = 0;
  8994. this.init = function ( planes, enableLocalClipping, camera ) {
  8995. var enabled =
  8996. planes.length !== 0 ||
  8997. enableLocalClipping ||
  8998. // enable state of previous frame - the clipping code has to
  8999. // run another frame in order to reset the state:
  9000. numGlobalPlanes !== 0 ||
  9001. localClippingEnabled;
  9002. localClippingEnabled = enableLocalClipping;
  9003. globalState = projectPlanes( planes, camera, 0 );
  9004. numGlobalPlanes = planes.length;
  9005. return enabled;
  9006. };
  9007. this.beginShadows = function () {
  9008. renderingShadows = true;
  9009. projectPlanes( null );
  9010. };
  9011. this.endShadows = function () {
  9012. renderingShadows = false;
  9013. resetGlobalState();
  9014. };
  9015. this.setState = function ( planes, clipIntersection, clipShadows, camera, cache, fromCache ) {
  9016. if ( ! localClippingEnabled || planes === null || planes.length === 0 || renderingShadows && ! clipShadows ) {
  9017. // there's no local clipping
  9018. if ( renderingShadows ) {
  9019. // there's no global clipping
  9020. projectPlanes( null );
  9021. } else {
  9022. resetGlobalState();
  9023. }
  9024. } else {
  9025. var nGlobal = renderingShadows ? 0 : numGlobalPlanes,
  9026. lGlobal = nGlobal * 4,
  9027. dstArray = cache.clippingState || null;
  9028. uniform.value = dstArray; // ensure unique state
  9029. dstArray = projectPlanes( planes, camera, lGlobal, fromCache );
  9030. for ( var i = 0; i !== lGlobal; ++ i ) {
  9031. dstArray[ i ] = globalState[ i ];
  9032. }
  9033. cache.clippingState = dstArray;
  9034. this.numIntersection = clipIntersection ? this.numPlanes : 0;
  9035. this.numPlanes += nGlobal;
  9036. }
  9037. };
  9038. function resetGlobalState() {
  9039. if ( uniform.value !== globalState ) {
  9040. uniform.value = globalState;
  9041. uniform.needsUpdate = numGlobalPlanes > 0;
  9042. }
  9043. scope.numPlanes = numGlobalPlanes;
  9044. scope.numIntersection = 0;
  9045. }
  9046. function projectPlanes( planes, camera, dstOffset, skipTransform ) {
  9047. var nPlanes = planes !== null ? planes.length : 0,
  9048. dstArray = null;
  9049. if ( nPlanes !== 0 ) {
  9050. dstArray = uniform.value;
  9051. if ( skipTransform !== true || dstArray === null ) {
  9052. var flatSize = dstOffset + nPlanes * 4,
  9053. viewMatrix = camera.matrixWorldInverse;
  9054. viewNormalMatrix.getNormalMatrix( viewMatrix );
  9055. if ( dstArray === null || dstArray.length < flatSize ) {
  9056. dstArray = new Float32Array( flatSize );
  9057. }
  9058. for ( var i = 0, i4 = dstOffset; i !== nPlanes; ++ i, i4 += 4 ) {
  9059. plane.copy( planes[ i ] ).applyMatrix4( viewMatrix, viewNormalMatrix );
  9060. plane.normal.toArray( dstArray, i4 );
  9061. dstArray[ i4 + 3 ] = plane.constant;
  9062. }
  9063. }
  9064. uniform.value = dstArray;
  9065. uniform.needsUpdate = true;
  9066. }
  9067. scope.numPlanes = nPlanes;
  9068. return dstArray;
  9069. }
  9070. }
  9071. /**
  9072. * @author mrdoob / http://mrdoob.com/
  9073. */
  9074. function WebGLExtensions( gl ) {
  9075. var extensions = {};
  9076. return {
  9077. get: function ( name ) {
  9078. if ( extensions[ name ] !== undefined ) {
  9079. return extensions[ name ];
  9080. }
  9081. var extension;
  9082. switch ( name ) {
  9083. case 'WEBGL_depth_texture':
  9084. extension = gl.getExtension( 'WEBGL_depth_texture' ) || gl.getExtension( 'MOZ_WEBGL_depth_texture' ) || gl.getExtension( 'WEBKIT_WEBGL_depth_texture' );
  9085. break;
  9086. case 'EXT_texture_filter_anisotropic':
  9087. extension = gl.getExtension( 'EXT_texture_filter_anisotropic' ) || gl.getExtension( 'MOZ_EXT_texture_filter_anisotropic' ) || gl.getExtension( 'WEBKIT_EXT_texture_filter_anisotropic' );
  9088. break;
  9089. case 'WEBGL_compressed_texture_s3tc':
  9090. extension = gl.getExtension( 'WEBGL_compressed_texture_s3tc' ) || gl.getExtension( 'MOZ_WEBGL_compressed_texture_s3tc' ) || gl.getExtension( 'WEBKIT_WEBGL_compressed_texture_s3tc' );
  9091. break;
  9092. case 'WEBGL_compressed_texture_pvrtc':
  9093. extension = gl.getExtension( 'WEBGL_compressed_texture_pvrtc' ) || gl.getExtension( 'WEBKIT_WEBGL_compressed_texture_pvrtc' );
  9094. break;
  9095. default:
  9096. extension = gl.getExtension( name );
  9097. }
  9098. if ( extension === null ) {
  9099. console.warn( 'THREE.WebGLRenderer: ' + name + ' extension not supported.' );
  9100. }
  9101. extensions[ name ] = extension;
  9102. return extension;
  9103. }
  9104. };
  9105. }
  9106. /**
  9107. * @author mrdoob / http://mrdoob.com/
  9108. */
  9109. function WebGLGeometries( gl, attributes, info ) {
  9110. var geometries = {};
  9111. var wireframeAttributes = {};
  9112. function onGeometryDispose( event ) {
  9113. var geometry = event.target;
  9114. var buffergeometry = geometries[ geometry.id ];
  9115. if ( buffergeometry.index !== null ) {
  9116. attributes.remove( buffergeometry.index );
  9117. }
  9118. for ( var name in buffergeometry.attributes ) {
  9119. attributes.remove( buffergeometry.attributes[ name ] );
  9120. }
  9121. geometry.removeEventListener( 'dispose', onGeometryDispose );
  9122. delete geometries[ geometry.id ];
  9123. var attribute = wireframeAttributes[ buffergeometry.id ];
  9124. if ( attribute ) {
  9125. attributes.remove( attribute );
  9126. delete wireframeAttributes[ buffergeometry.id ];
  9127. }
  9128. //
  9129. info.memory.geometries --;
  9130. }
  9131. function get( object, geometry ) {
  9132. var buffergeometry = geometries[ geometry.id ];
  9133. if ( buffergeometry ) return buffergeometry;
  9134. geometry.addEventListener( 'dispose', onGeometryDispose );
  9135. if ( geometry.isBufferGeometry ) {
  9136. buffergeometry = geometry;
  9137. } else if ( geometry.isGeometry ) {
  9138. if ( geometry._bufferGeometry === undefined ) {
  9139. geometry._bufferGeometry = new BufferGeometry().setFromObject( object );
  9140. }
  9141. buffergeometry = geometry._bufferGeometry;
  9142. }
  9143. geometries[ geometry.id ] = buffergeometry;
  9144. info.memory.geometries ++;
  9145. return buffergeometry;
  9146. }
  9147. function update( geometry ) {
  9148. var index = geometry.index;
  9149. var geometryAttributes = geometry.attributes;
  9150. if ( index !== null ) {
  9151. attributes.update( index, 34963 );
  9152. }
  9153. for ( var name in geometryAttributes ) {
  9154. attributes.update( geometryAttributes[ name ], 34962 );
  9155. }
  9156. // morph targets
  9157. var morphAttributes = geometry.morphAttributes;
  9158. for ( var name in morphAttributes ) {
  9159. var array = morphAttributes[ name ];
  9160. for ( var i = 0, l = array.length; i < l; i ++ ) {
  9161. attributes.update( array[ i ], 34962 );
  9162. }
  9163. }
  9164. }
  9165. function getWireframeAttribute( geometry ) {
  9166. var attribute = wireframeAttributes[ geometry.id ];
  9167. if ( attribute ) return attribute;
  9168. var indices = [];
  9169. var geometryIndex = geometry.index;
  9170. var geometryAttributes = geometry.attributes;
  9171. // console.time( 'wireframe' );
  9172. if ( geometryIndex !== null ) {
  9173. var array = geometryIndex.array;
  9174. for ( var i = 0, l = array.length; i < l; i += 3 ) {
  9175. var a = array[ i + 0 ];
  9176. var b = array[ i + 1 ];
  9177. var c = array[ i + 2 ];
  9178. indices.push( a, b, b, c, c, a );
  9179. }
  9180. } else {
  9181. var array = geometryAttributes.position.array;
  9182. for ( var i = 0, l = ( array.length / 3 ) - 1; i < l; i += 3 ) {
  9183. var a = i + 0;
  9184. var b = i + 1;
  9185. var c = i + 2;
  9186. indices.push( a, b, b, c, c, a );
  9187. }
  9188. }
  9189. // console.timeEnd( 'wireframe' );
  9190. attribute = new ( arrayMax( indices ) > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute )( indices, 1 );
  9191. attributes.update( attribute, 34963 );
  9192. wireframeAttributes[ geometry.id ] = attribute;
  9193. return attribute;
  9194. }
  9195. return {
  9196. get: get,
  9197. update: update,
  9198. getWireframeAttribute: getWireframeAttribute
  9199. };
  9200. }
  9201. /**
  9202. * @author mrdoob / http://mrdoob.com/
  9203. */
  9204. function WebGLIndexedBufferRenderer( gl, extensions, info, capabilities ) {
  9205. var mode;
  9206. function setMode( value ) {
  9207. mode = value;
  9208. }
  9209. var type, bytesPerElement;
  9210. function setIndex( value ) {
  9211. type = value.type;
  9212. bytesPerElement = value.bytesPerElement;
  9213. }
  9214. function render( start, count ) {
  9215. gl.drawElements( mode, count, type, start * bytesPerElement );
  9216. info.update( count, mode );
  9217. }
  9218. function renderInstances( geometry, start, count ) {
  9219. var extension;
  9220. if ( capabilities.isWebGL2 ) {
  9221. extension = gl;
  9222. } else {
  9223. var extension = extensions.get( 'ANGLE_instanced_arrays' );
  9224. if ( extension === null ) {
  9225. console.error( 'THREE.WebGLIndexedBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  9226. return;
  9227. }
  9228. }
  9229. extension[ capabilities.isWebGL2 ? 'drawElementsInstanced' : 'drawElementsInstancedANGLE' ]( mode, count, type, start * bytesPerElement, geometry.maxInstancedCount );
  9230. info.update( count, mode, geometry.maxInstancedCount );
  9231. }
  9232. //
  9233. this.setMode = setMode;
  9234. this.setIndex = setIndex;
  9235. this.render = render;
  9236. this.renderInstances = renderInstances;
  9237. }
  9238. /**
  9239. * @author Mugen87 / https://github.com/Mugen87
  9240. */
  9241. function WebGLInfo( gl ) {
  9242. var memory = {
  9243. geometries: 0,
  9244. textures: 0
  9245. };
  9246. var render = {
  9247. frame: 0,
  9248. calls: 0,
  9249. triangles: 0,
  9250. points: 0,
  9251. lines: 0
  9252. };
  9253. function update( count, mode, instanceCount ) {
  9254. instanceCount = instanceCount || 1;
  9255. render.calls ++;
  9256. switch ( mode ) {
  9257. case 4:
  9258. render.triangles += instanceCount * ( count / 3 );
  9259. break;
  9260. case 5:
  9261. case 6:
  9262. render.triangles += instanceCount * ( count - 2 );
  9263. break;
  9264. case 1:
  9265. render.lines += instanceCount * ( count / 2 );
  9266. break;
  9267. case 3:
  9268. render.lines += instanceCount * ( count - 1 );
  9269. break;
  9270. case 2:
  9271. render.lines += instanceCount * count;
  9272. break;
  9273. case 0:
  9274. render.points += instanceCount * count;
  9275. break;
  9276. default:
  9277. console.error( 'THREE.WebGLInfo: Unknown draw mode:', mode );
  9278. break;
  9279. }
  9280. }
  9281. function reset() {
  9282. render.frame ++;
  9283. render.calls = 0;
  9284. render.triangles = 0;
  9285. render.points = 0;
  9286. render.lines = 0;
  9287. }
  9288. return {
  9289. memory: memory,
  9290. render: render,
  9291. programs: null,
  9292. autoReset: true,
  9293. reset: reset,
  9294. update: update
  9295. };
  9296. }
  9297. /**
  9298. * @author mrdoob / http://mrdoob.com/
  9299. */
  9300. function absNumericalSort( a, b ) {
  9301. return Math.abs( b[ 1 ] ) - Math.abs( a[ 1 ] );
  9302. }
  9303. function WebGLMorphtargets( gl ) {
  9304. var influencesList = {};
  9305. var morphInfluences = new Float32Array( 8 );
  9306. function update( object, geometry, material, program ) {
  9307. var objectInfluences = object.morphTargetInfluences;
  9308. var length = objectInfluences.length;
  9309. var influences = influencesList[ geometry.id ];
  9310. if ( influences === undefined ) {
  9311. // initialise list
  9312. influences = [];
  9313. for ( var i = 0; i < length; i ++ ) {
  9314. influences[ i ] = [ i, 0 ];
  9315. }
  9316. influencesList[ geometry.id ] = influences;
  9317. }
  9318. var morphTargets = material.morphTargets && geometry.morphAttributes.position;
  9319. var morphNormals = material.morphNormals && geometry.morphAttributes.normal;
  9320. // Remove current morphAttributes
  9321. for ( var i = 0; i < length; i ++ ) {
  9322. var influence = influences[ i ];
  9323. if ( influence[ 1 ] !== 0 ) {
  9324. if ( morphTargets ) geometry.removeAttribute( 'morphTarget' + i );
  9325. if ( morphNormals ) geometry.removeAttribute( 'morphNormal' + i );
  9326. }
  9327. }
  9328. // Collect influences
  9329. for ( var i = 0; i < length; i ++ ) {
  9330. var influence = influences[ i ];
  9331. influence[ 0 ] = i;
  9332. influence[ 1 ] = objectInfluences[ i ];
  9333. }
  9334. influences.sort( absNumericalSort );
  9335. // Add morphAttributes
  9336. for ( var i = 0; i < 8; i ++ ) {
  9337. var influence = influences[ i ];
  9338. if ( influence ) {
  9339. var index = influence[ 0 ];
  9340. var value = influence[ 1 ];
  9341. if ( value ) {
  9342. if ( morphTargets ) geometry.addAttribute( 'morphTarget' + i, morphTargets[ index ] );
  9343. if ( morphNormals ) geometry.addAttribute( 'morphNormal' + i, morphNormals[ index ] );
  9344. morphInfluences[ i ] = value;
  9345. continue;
  9346. }
  9347. }
  9348. morphInfluences[ i ] = 0;
  9349. }
  9350. program.getUniforms().setValue( gl, 'morphTargetInfluences', morphInfluences );
  9351. }
  9352. return {
  9353. update: update
  9354. };
  9355. }
  9356. /**
  9357. * @author mrdoob / http://mrdoob.com/
  9358. */
  9359. function WebGLObjects( geometries, info ) {
  9360. var updateList = {};
  9361. function update( object ) {
  9362. var frame = info.render.frame;
  9363. var geometry = object.geometry;
  9364. var buffergeometry = geometries.get( object, geometry );
  9365. // Update once per frame
  9366. if ( updateList[ buffergeometry.id ] !== frame ) {
  9367. if ( geometry.isGeometry ) {
  9368. buffergeometry.updateFromObject( object );
  9369. }
  9370. geometries.update( buffergeometry );
  9371. updateList[ buffergeometry.id ] = frame;
  9372. }
  9373. return buffergeometry;
  9374. }
  9375. function dispose() {
  9376. updateList = {};
  9377. }
  9378. return {
  9379. update: update,
  9380. dispose: dispose
  9381. };
  9382. }
  9383. /**
  9384. * @author mrdoob / http://mrdoob.com/
  9385. */
  9386. function CubeTexture( images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding ) {
  9387. images = images !== undefined ? images : [];
  9388. mapping = mapping !== undefined ? mapping : CubeReflectionMapping;
  9389. format = format !== undefined ? format : RGBFormat;
  9390. Texture.call( this, images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding );
  9391. this.flipY = false;
  9392. }
  9393. CubeTexture.prototype = Object.create( Texture.prototype );
  9394. CubeTexture.prototype.constructor = CubeTexture;
  9395. CubeTexture.prototype.isCubeTexture = true;
  9396. Object.defineProperty( CubeTexture.prototype, 'images', {
  9397. get: function () {
  9398. return this.image;
  9399. },
  9400. set: function ( value ) {
  9401. this.image = value;
  9402. }
  9403. } );
  9404. /**
  9405. * @author Artur Trzesiok
  9406. */
  9407. function DataTexture3D( data, width, height, depth ) {
  9408. // We're going to add .setXXX() methods for setting properties later.
  9409. // Users can still set in DataTexture3D directly.
  9410. //
  9411. // var texture = new THREE.DataTexture3D( data, width, height, depth );
  9412. // texture.anisotropy = 16;
  9413. //
  9414. // See #14839
  9415. Texture.call( this, null );
  9416. this.image = { data: data, width: width, height: height, depth: depth };
  9417. this.magFilter = NearestFilter;
  9418. this.minFilter = NearestFilter;
  9419. this.wrapR = ClampToEdgeWrapping;
  9420. this.generateMipmaps = false;
  9421. this.flipY = false;
  9422. }
  9423. DataTexture3D.prototype = Object.create( Texture.prototype );
  9424. DataTexture3D.prototype.constructor = DataTexture3D;
  9425. DataTexture3D.prototype.isDataTexture3D = true;
  9426. /**
  9427. * @author tschw
  9428. * @author Mugen87 / https://github.com/Mugen87
  9429. * @author mrdoob / http://mrdoob.com/
  9430. *
  9431. * Uniforms of a program.
  9432. * Those form a tree structure with a special top-level container for the root,
  9433. * which you get by calling 'new WebGLUniforms( gl, program, renderer )'.
  9434. *
  9435. *
  9436. * Properties of inner nodes including the top-level container:
  9437. *
  9438. * .seq - array of nested uniforms
  9439. * .map - nested uniforms by name
  9440. *
  9441. *
  9442. * Methods of all nodes except the top-level container:
  9443. *
  9444. * .setValue( gl, value, [renderer] )
  9445. *
  9446. * uploads a uniform value(s)
  9447. * the 'renderer' parameter is needed for sampler uniforms
  9448. *
  9449. *
  9450. * Static methods of the top-level container (renderer factorizations):
  9451. *
  9452. * .upload( gl, seq, values, renderer )
  9453. *
  9454. * sets uniforms in 'seq' to 'values[id].value'
  9455. *
  9456. * .seqWithValue( seq, values ) : filteredSeq
  9457. *
  9458. * filters 'seq' entries with corresponding entry in values
  9459. *
  9460. *
  9461. * Methods of the top-level container (renderer factorizations):
  9462. *
  9463. * .setValue( gl, name, value )
  9464. *
  9465. * sets uniform with name 'name' to 'value'
  9466. *
  9467. * .set( gl, obj, prop )
  9468. *
  9469. * sets uniform from object and property with same name than uniform
  9470. *
  9471. * .setOptional( gl, obj, prop )
  9472. *
  9473. * like .set for an optional property of the object
  9474. *
  9475. */
  9476. var emptyTexture = new Texture();
  9477. var emptyTexture3d = new DataTexture3D();
  9478. var emptyCubeTexture = new CubeTexture();
  9479. // --- Base for inner nodes (including the root) ---
  9480. function UniformContainer() {
  9481. this.seq = [];
  9482. this.map = {};
  9483. }
  9484. // --- Utilities ---
  9485. // Array Caches (provide typed arrays for temporary by size)
  9486. var arrayCacheF32 = [];
  9487. var arrayCacheI32 = [];
  9488. // Float32Array caches used for uploading Matrix uniforms
  9489. var mat4array = new Float32Array( 16 );
  9490. var mat3array = new Float32Array( 9 );
  9491. var mat2array = new Float32Array( 4 );
  9492. // Flattening for arrays of vectors and matrices
  9493. function flatten( array, nBlocks, blockSize ) {
  9494. var firstElem = array[ 0 ];
  9495. if ( firstElem <= 0 || firstElem > 0 ) return array;
  9496. // unoptimized: ! isNaN( firstElem )
  9497. // see http://jacksondunstan.com/articles/983
  9498. var n = nBlocks * blockSize,
  9499. r = arrayCacheF32[ n ];
  9500. if ( r === undefined ) {
  9501. r = new Float32Array( n );
  9502. arrayCacheF32[ n ] = r;
  9503. }
  9504. if ( nBlocks !== 0 ) {
  9505. firstElem.toArray( r, 0 );
  9506. for ( var i = 1, offset = 0; i !== nBlocks; ++ i ) {
  9507. offset += blockSize;
  9508. array[ i ].toArray( r, offset );
  9509. }
  9510. }
  9511. return r;
  9512. }
  9513. function arraysEqual( a, b ) {
  9514. if ( a.length !== b.length ) return false;
  9515. for ( var i = 0, l = a.length; i < l; i ++ ) {
  9516. if ( a[ i ] !== b[ i ] ) return false;
  9517. }
  9518. return true;
  9519. }
  9520. function copyArray( a, b ) {
  9521. for ( var i = 0, l = b.length; i < l; i ++ ) {
  9522. a[ i ] = b[ i ];
  9523. }
  9524. }
  9525. // Texture unit allocation
  9526. function allocTexUnits( renderer, n ) {
  9527. var r = arrayCacheI32[ n ];
  9528. if ( r === undefined ) {
  9529. r = new Int32Array( n );
  9530. arrayCacheI32[ n ] = r;
  9531. }
  9532. for ( var i = 0; i !== n; ++ i )
  9533. r[ i ] = renderer.allocTextureUnit();
  9534. return r;
  9535. }
  9536. // --- Setters ---
  9537. // Note: Defining these methods externally, because they come in a bunch
  9538. // and this way their names minify.
  9539. // Single scalar
  9540. function setValue1f( gl, v ) {
  9541. var cache = this.cache;
  9542. if ( cache[ 0 ] === v ) return;
  9543. gl.uniform1f( this.addr, v );
  9544. cache[ 0 ] = v;
  9545. }
  9546. function setValue1i( gl, v ) {
  9547. var cache = this.cache;
  9548. if ( cache[ 0 ] === v ) return;
  9549. gl.uniform1i( this.addr, v );
  9550. cache[ 0 ] = v;
  9551. }
  9552. // Single float vector (from flat array or THREE.VectorN)
  9553. function setValue2fv( gl, v ) {
  9554. var cache = this.cache;
  9555. if ( v.x !== undefined ) {
  9556. if ( cache[ 0 ] !== v.x || cache[ 1 ] !== v.y ) {
  9557. gl.uniform2f( this.addr, v.x, v.y );
  9558. cache[ 0 ] = v.x;
  9559. cache[ 1 ] = v.y;
  9560. }
  9561. } else {
  9562. if ( arraysEqual( cache, v ) ) return;
  9563. gl.uniform2fv( this.addr, v );
  9564. copyArray( cache, v );
  9565. }
  9566. }
  9567. function setValue3fv( gl, v ) {
  9568. var cache = this.cache;
  9569. if ( v.x !== undefined ) {
  9570. if ( cache[ 0 ] !== v.x || cache[ 1 ] !== v.y || cache[ 2 ] !== v.z ) {
  9571. gl.uniform3f( this.addr, v.x, v.y, v.z );
  9572. cache[ 0 ] = v.x;
  9573. cache[ 1 ] = v.y;
  9574. cache[ 2 ] = v.z;
  9575. }
  9576. } else if ( v.r !== undefined ) {
  9577. if ( cache[ 0 ] !== v.r || cache[ 1 ] !== v.g || cache[ 2 ] !== v.b ) {
  9578. gl.uniform3f( this.addr, v.r, v.g, v.b );
  9579. cache[ 0 ] = v.r;
  9580. cache[ 1 ] = v.g;
  9581. cache[ 2 ] = v.b;
  9582. }
  9583. } else {
  9584. if ( arraysEqual( cache, v ) ) return;
  9585. gl.uniform3fv( this.addr, v );
  9586. copyArray( cache, v );
  9587. }
  9588. }
  9589. function setValue4fv( gl, v ) {
  9590. var cache = this.cache;
  9591. if ( v.x !== undefined ) {
  9592. if ( cache[ 0 ] !== v.x || cache[ 1 ] !== v.y || cache[ 2 ] !== v.z || cache[ 3 ] !== v.w ) {
  9593. gl.uniform4f( this.addr, v.x, v.y, v.z, v.w );
  9594. cache[ 0 ] = v.x;
  9595. cache[ 1 ] = v.y;
  9596. cache[ 2 ] = v.z;
  9597. cache[ 3 ] = v.w;
  9598. }
  9599. } else {
  9600. if ( arraysEqual( cache, v ) ) return;
  9601. gl.uniform4fv( this.addr, v );
  9602. copyArray( cache, v );
  9603. }
  9604. }
  9605. // Single matrix (from flat array or MatrixN)
  9606. function setValue2fm( gl, v ) {
  9607. var cache = this.cache;
  9608. var elements = v.elements;
  9609. if ( elements === undefined ) {
  9610. if ( arraysEqual( cache, v ) ) return;
  9611. gl.uniformMatrix2fv( this.addr, false, v );
  9612. copyArray( cache, v );
  9613. } else {
  9614. if ( arraysEqual( cache, elements ) ) return;
  9615. mat2array.set( elements );
  9616. gl.uniformMatrix2fv( this.addr, false, mat2array );
  9617. copyArray( cache, elements );
  9618. }
  9619. }
  9620. function setValue3fm( gl, v ) {
  9621. var cache = this.cache;
  9622. var elements = v.elements;
  9623. if ( elements === undefined ) {
  9624. if ( arraysEqual( cache, v ) ) return;
  9625. gl.uniformMatrix3fv( this.addr, false, v );
  9626. copyArray( cache, v );
  9627. } else {
  9628. if ( arraysEqual( cache, elements ) ) return;
  9629. mat3array.set( elements );
  9630. gl.uniformMatrix3fv( this.addr, false, mat3array );
  9631. copyArray( cache, elements );
  9632. }
  9633. }
  9634. function setValue4fm( gl, v ) {
  9635. var cache = this.cache;
  9636. var elements = v.elements;
  9637. if ( elements === undefined ) {
  9638. if ( arraysEqual( cache, v ) ) return;
  9639. gl.uniformMatrix4fv( this.addr, false, v );
  9640. copyArray( cache, v );
  9641. } else {
  9642. if ( arraysEqual( cache, elements ) ) return;
  9643. mat4array.set( elements );
  9644. gl.uniformMatrix4fv( this.addr, false, mat4array );
  9645. copyArray( cache, elements );
  9646. }
  9647. }
  9648. // Single texture (2D / Cube)
  9649. function setValueT1( gl, v, renderer ) {
  9650. var cache = this.cache;
  9651. var unit = renderer.allocTextureUnit();
  9652. if ( cache[ 0 ] !== unit ) {
  9653. gl.uniform1i( this.addr, unit );
  9654. cache[ 0 ] = unit;
  9655. }
  9656. renderer.setTexture2D( v || emptyTexture, unit );
  9657. }
  9658. function setValueT3D1( gl, v, renderer ) {
  9659. var cache = this.cache;
  9660. var unit = renderer.allocTextureUnit();
  9661. if ( cache[ 0 ] !== unit ) {
  9662. gl.uniform1i( this.addr, unit );
  9663. cache[ 0 ] = unit;
  9664. }
  9665. renderer.setTexture3D( v || emptyTexture3d, unit );
  9666. }
  9667. function setValueT6( gl, v, renderer ) {
  9668. var cache = this.cache;
  9669. var unit = renderer.allocTextureUnit();
  9670. if ( cache[ 0 ] !== unit ) {
  9671. gl.uniform1i( this.addr, unit );
  9672. cache[ 0 ] = unit;
  9673. }
  9674. renderer.setTextureCube( v || emptyCubeTexture, unit );
  9675. }
  9676. // Integer / Boolean vectors or arrays thereof (always flat arrays)
  9677. function setValue2iv( gl, v ) {
  9678. var cache = this.cache;
  9679. if ( arraysEqual( cache, v ) ) return;
  9680. gl.uniform2iv( this.addr, v );
  9681. copyArray( cache, v );
  9682. }
  9683. function setValue3iv( gl, v ) {
  9684. var cache = this.cache;
  9685. if ( arraysEqual( cache, v ) ) return;
  9686. gl.uniform3iv( this.addr, v );
  9687. copyArray( cache, v );
  9688. }
  9689. function setValue4iv( gl, v ) {
  9690. var cache = this.cache;
  9691. if ( arraysEqual( cache, v ) ) return;
  9692. gl.uniform4iv( this.addr, v );
  9693. copyArray( cache, v );
  9694. }
  9695. // Helper to pick the right setter for the singular case
  9696. function getSingularSetter( type ) {
  9697. switch ( type ) {
  9698. case 0x1406: return setValue1f; // FLOAT
  9699. case 0x8b50: return setValue2fv; // _VEC2
  9700. case 0x8b51: return setValue3fv; // _VEC3
  9701. case 0x8b52: return setValue4fv; // _VEC4
  9702. case 0x8b5a: return setValue2fm; // _MAT2
  9703. case 0x8b5b: return setValue3fm; // _MAT3
  9704. case 0x8b5c: return setValue4fm; // _MAT4
  9705. case 0x8b5e: case 0x8d66: return setValueT1; // SAMPLER_2D, SAMPLER_EXTERNAL_OES
  9706. case 0x8B5F: return setValueT3D1; // SAMPLER_3D
  9707. case 0x8b60: return setValueT6; // SAMPLER_CUBE
  9708. case 0x1404: case 0x8b56: return setValue1i; // INT, BOOL
  9709. case 0x8b53: case 0x8b57: return setValue2iv; // _VEC2
  9710. case 0x8b54: case 0x8b58: return setValue3iv; // _VEC3
  9711. case 0x8b55: case 0x8b59: return setValue4iv; // _VEC4
  9712. }
  9713. }
  9714. // Array of scalars
  9715. function setValue1fv( gl, v ) {
  9716. var cache = this.cache;
  9717. if ( arraysEqual( cache, v ) ) return;
  9718. gl.uniform1fv( this.addr, v );
  9719. copyArray( cache, v );
  9720. }
  9721. function setValue1iv( gl, v ) {
  9722. var cache = this.cache;
  9723. if ( arraysEqual( cache, v ) ) return;
  9724. gl.uniform1iv( this.addr, v );
  9725. copyArray( cache, v );
  9726. }
  9727. // Array of vectors (flat or from THREE classes)
  9728. function setValueV2a( gl, v ) {
  9729. var cache = this.cache;
  9730. var data = flatten( v, this.size, 2 );
  9731. if ( arraysEqual( cache, data ) ) return;
  9732. gl.uniform2fv( this.addr, data );
  9733. this.updateCache( data );
  9734. }
  9735. function setValueV3a( gl, v ) {
  9736. var cache = this.cache;
  9737. var data = flatten( v, this.size, 3 );
  9738. if ( arraysEqual( cache, data ) ) return;
  9739. gl.uniform3fv( this.addr, data );
  9740. this.updateCache( data );
  9741. }
  9742. function setValueV4a( gl, v ) {
  9743. var cache = this.cache;
  9744. var data = flatten( v, this.size, 4 );
  9745. if ( arraysEqual( cache, data ) ) return;
  9746. gl.uniform4fv( this.addr, data );
  9747. this.updateCache( data );
  9748. }
  9749. // Array of matrices (flat or from THREE clases)
  9750. function setValueM2a( gl, v ) {
  9751. var cache = this.cache;
  9752. var data = flatten( v, this.size, 4 );
  9753. if ( arraysEqual( cache, data ) ) return;
  9754. gl.uniformMatrix2fv( this.addr, false, data );
  9755. this.updateCache( data );
  9756. }
  9757. function setValueM3a( gl, v ) {
  9758. var cache = this.cache;
  9759. var data = flatten( v, this.size, 9 );
  9760. if ( arraysEqual( cache, data ) ) return;
  9761. gl.uniformMatrix3fv( this.addr, false, data );
  9762. this.updateCache( data );
  9763. }
  9764. function setValueM4a( gl, v ) {
  9765. var cache = this.cache;
  9766. var data = flatten( v, this.size, 16 );
  9767. if ( arraysEqual( cache, data ) ) return;
  9768. gl.uniformMatrix4fv( this.addr, false, data );
  9769. this.updateCache( data );
  9770. }
  9771. // Array of textures (2D / Cube)
  9772. function setValueT1a( gl, v, renderer ) {
  9773. var cache = this.cache;
  9774. var n = v.length;
  9775. var units = allocTexUnits( renderer, n );
  9776. if ( arraysEqual( cache, units ) === false ) {
  9777. gl.uniform1iv( this.addr, units );
  9778. copyArray( cache, units );
  9779. }
  9780. for ( var i = 0; i !== n; ++ i ) {
  9781. renderer.setTexture2D( v[ i ] || emptyTexture, units[ i ] );
  9782. }
  9783. }
  9784. function setValueT6a( gl, v, renderer ) {
  9785. var cache = this.cache;
  9786. var n = v.length;
  9787. var units = allocTexUnits( renderer, n );
  9788. if ( arraysEqual( cache, units ) === false ) {
  9789. gl.uniform1iv( this.addr, units );
  9790. copyArray( cache, units );
  9791. }
  9792. for ( var i = 0; i !== n; ++ i ) {
  9793. renderer.setTextureCube( v[ i ] || emptyCubeTexture, units[ i ] );
  9794. }
  9795. }
  9796. // Helper to pick the right setter for a pure (bottom-level) array
  9797. function getPureArraySetter( type ) {
  9798. switch ( type ) {
  9799. case 0x1406: return setValue1fv; // FLOAT
  9800. case 0x8b50: return setValueV2a; // _VEC2
  9801. case 0x8b51: return setValueV3a; // _VEC3
  9802. case 0x8b52: return setValueV4a; // _VEC4
  9803. case 0x8b5a: return setValueM2a; // _MAT2
  9804. case 0x8b5b: return setValueM3a; // _MAT3
  9805. case 0x8b5c: return setValueM4a; // _MAT4
  9806. case 0x8b5e: return setValueT1a; // SAMPLER_2D
  9807. case 0x8b60: return setValueT6a; // SAMPLER_CUBE
  9808. case 0x1404: case 0x8b56: return setValue1iv; // INT, BOOL
  9809. case 0x8b53: case 0x8b57: return setValue2iv; // _VEC2
  9810. case 0x8b54: case 0x8b58: return setValue3iv; // _VEC3
  9811. case 0x8b55: case 0x8b59: return setValue4iv; // _VEC4
  9812. }
  9813. }
  9814. // --- Uniform Classes ---
  9815. function SingleUniform( id, activeInfo, addr ) {
  9816. this.id = id;
  9817. this.addr = addr;
  9818. this.cache = [];
  9819. this.setValue = getSingularSetter( activeInfo.type );
  9820. // this.path = activeInfo.name; // DEBUG
  9821. }
  9822. function PureArrayUniform( id, activeInfo, addr ) {
  9823. this.id = id;
  9824. this.addr = addr;
  9825. this.cache = [];
  9826. this.size = activeInfo.size;
  9827. this.setValue = getPureArraySetter( activeInfo.type );
  9828. // this.path = activeInfo.name; // DEBUG
  9829. }
  9830. PureArrayUniform.prototype.updateCache = function ( data ) {
  9831. var cache = this.cache;
  9832. if ( data instanceof Float32Array && cache.length !== data.length ) {
  9833. this.cache = new Float32Array( data.length );
  9834. }
  9835. copyArray( cache, data );
  9836. };
  9837. function StructuredUniform( id ) {
  9838. this.id = id;
  9839. UniformContainer.call( this ); // mix-in
  9840. }
  9841. StructuredUniform.prototype.setValue = function ( gl, value, renderer ) {
  9842. var seq = this.seq;
  9843. for ( var i = 0, n = seq.length; i !== n; ++ i ) {
  9844. var u = seq[ i ];
  9845. u.setValue( gl, value[ u.id ], renderer );
  9846. }
  9847. };
  9848. // --- Top-level ---
  9849. // Parser - builds up the property tree from the path strings
  9850. var RePathPart = /([\w\d_]+)(\])?(\[|\.)?/g;
  9851. // extracts
  9852. // - the identifier (member name or array index)
  9853. // - followed by an optional right bracket (found when array index)
  9854. // - followed by an optional left bracket or dot (type of subscript)
  9855. //
  9856. // Note: These portions can be read in a non-overlapping fashion and
  9857. // allow straightforward parsing of the hierarchy that WebGL encodes
  9858. // in the uniform names.
  9859. function addUniform( container, uniformObject ) {
  9860. container.seq.push( uniformObject );
  9861. container.map[ uniformObject.id ] = uniformObject;
  9862. }
  9863. function parseUniform( activeInfo, addr, container ) {
  9864. var path = activeInfo.name,
  9865. pathLength = path.length;
  9866. // reset RegExp object, because of the early exit of a previous run
  9867. RePathPart.lastIndex = 0;
  9868. while ( true ) {
  9869. var match = RePathPart.exec( path ),
  9870. matchEnd = RePathPart.lastIndex,
  9871. id = match[ 1 ],
  9872. idIsIndex = match[ 2 ] === ']',
  9873. subscript = match[ 3 ];
  9874. if ( idIsIndex ) id = id | 0; // convert to integer
  9875. if ( subscript === undefined || subscript === '[' && matchEnd + 2 === pathLength ) {
  9876. // bare name or "pure" bottom-level array "[0]" suffix
  9877. addUniform( container, subscript === undefined ?
  9878. new SingleUniform( id, activeInfo, addr ) :
  9879. new PureArrayUniform( id, activeInfo, addr ) );
  9880. break;
  9881. } else {
  9882. // step into inner node / create it in case it doesn't exist
  9883. var map = container.map, next = map[ id ];
  9884. if ( next === undefined ) {
  9885. next = new StructuredUniform( id );
  9886. addUniform( container, next );
  9887. }
  9888. container = next;
  9889. }
  9890. }
  9891. }
  9892. // Root Container
  9893. function WebGLUniforms( gl, program, renderer ) {
  9894. UniformContainer.call( this );
  9895. this.renderer = renderer;
  9896. var n = gl.getProgramParameter( program, 35718 );
  9897. for ( var i = 0; i < n; ++ i ) {
  9898. var info = gl.getActiveUniform( program, i ),
  9899. addr = gl.getUniformLocation( program, info.name );
  9900. parseUniform( info, addr, this );
  9901. }
  9902. }
  9903. WebGLUniforms.prototype.setValue = function ( gl, name, value ) {
  9904. var u = this.map[ name ];
  9905. if ( u !== undefined ) u.setValue( gl, value, this.renderer );
  9906. };
  9907. WebGLUniforms.prototype.setOptional = function ( gl, object, name ) {
  9908. var v = object[ name ];
  9909. if ( v !== undefined ) this.setValue( gl, name, v );
  9910. };
  9911. // Static interface
  9912. WebGLUniforms.upload = function ( gl, seq, values, renderer ) {
  9913. for ( var i = 0, n = seq.length; i !== n; ++ i ) {
  9914. var u = seq[ i ],
  9915. v = values[ u.id ];
  9916. if ( v.needsUpdate !== false ) {
  9917. // note: always updating when .needsUpdate is undefined
  9918. u.setValue( gl, v.value, renderer );
  9919. }
  9920. }
  9921. };
  9922. WebGLUniforms.seqWithValue = function ( seq, values ) {
  9923. var r = [];
  9924. for ( var i = 0, n = seq.length; i !== n; ++ i ) {
  9925. var u = seq[ i ];
  9926. if ( u.id in values ) r.push( u );
  9927. }
  9928. return r;
  9929. };
  9930. /**
  9931. * @author mrdoob / http://mrdoob.com/
  9932. */
  9933. function addLineNumbers( string ) {
  9934. var lines = string.split( '\n' );
  9935. for ( var i = 0; i < lines.length; i ++ ) {
  9936. lines[ i ] = ( i + 1 ) + ': ' + lines[ i ];
  9937. }
  9938. return lines.join( '\n' );
  9939. }
  9940. function WebGLShader( gl, type, string ) {
  9941. var shader = gl.createShader( type );
  9942. gl.shaderSource( shader, string );
  9943. gl.compileShader( shader );
  9944. if ( gl.getShaderParameter( shader, 35713 ) === false ) {
  9945. console.error( 'THREE.WebGLShader: Shader couldn\'t compile.' );
  9946. }
  9947. if ( gl.getShaderInfoLog( shader ) !== '' ) {
  9948. console.warn( 'THREE.WebGLShader: gl.getShaderInfoLog()', type === 35633 ? 'vertex' : 'fragment', gl.getShaderInfoLog( shader ), addLineNumbers( string ) );
  9949. }
  9950. // --enable-privileged-webgl-extension
  9951. // console.log( type, gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( shader ) );
  9952. return shader;
  9953. }
  9954. /**
  9955. * @author mrdoob / http://mrdoob.com/
  9956. */
  9957. var programIdCount = 0;
  9958. function getEncodingComponents( encoding ) {
  9959. switch ( encoding ) {
  9960. case LinearEncoding:
  9961. return [ 'Linear', '( value )' ];
  9962. case sRGBEncoding:
  9963. return [ 'sRGB', '( value )' ];
  9964. case RGBEEncoding:
  9965. return [ 'RGBE', '( value )' ];
  9966. case RGBM7Encoding:
  9967. return [ 'RGBM', '( value, 7.0 )' ];
  9968. case RGBM16Encoding:
  9969. return [ 'RGBM', '( value, 16.0 )' ];
  9970. case RGBDEncoding:
  9971. return [ 'RGBD', '( value, 256.0 )' ];
  9972. case GammaEncoding:
  9973. return [ 'Gamma', '( value, float( GAMMA_FACTOR ) )' ];
  9974. default:
  9975. throw new Error( 'unsupported encoding: ' + encoding );
  9976. }
  9977. }
  9978. function getTexelDecodingFunction( functionName, encoding ) {
  9979. var components = getEncodingComponents( encoding );
  9980. return 'vec4 ' + functionName + '( vec4 value ) { return ' + components[ 0 ] + 'ToLinear' + components[ 1 ] + '; }';
  9981. }
  9982. function getTexelEncodingFunction( functionName, encoding ) {
  9983. var components = getEncodingComponents( encoding );
  9984. return 'vec4 ' + functionName + '( vec4 value ) { return LinearTo' + components[ 0 ] + components[ 1 ] + '; }';
  9985. }
  9986. function getToneMappingFunction( functionName, toneMapping ) {
  9987. var toneMappingName;
  9988. switch ( toneMapping ) {
  9989. case LinearToneMapping:
  9990. toneMappingName = 'Linear';
  9991. break;
  9992. case ReinhardToneMapping:
  9993. toneMappingName = 'Reinhard';
  9994. break;
  9995. case Uncharted2ToneMapping:
  9996. toneMappingName = 'Uncharted2';
  9997. break;
  9998. case CineonToneMapping:
  9999. toneMappingName = 'OptimizedCineon';
  10000. break;
  10001. case ACESFilmicToneMapping:
  10002. toneMappingName = 'ACESFilmic';
  10003. break;
  10004. default:
  10005. throw new Error( 'unsupported toneMapping: ' + toneMapping );
  10006. }
  10007. return 'vec3 ' + functionName + '( vec3 color ) { return ' + toneMappingName + 'ToneMapping( color ); }';
  10008. }
  10009. function generateExtensions( extensions, parameters, rendererExtensions ) {
  10010. extensions = extensions || {};
  10011. var chunks = [
  10012. ( extensions.derivatives || parameters.envMapCubeUV || parameters.bumpMap || ( parameters.normalMap && ! parameters.objectSpaceNormalMap ) || parameters.flatShading ) ? '#extension GL_OES_standard_derivatives : enable' : '',
  10013. ( extensions.fragDepth || parameters.logarithmicDepthBuffer ) && rendererExtensions.get( 'EXT_frag_depth' ) ? '#extension GL_EXT_frag_depth : enable' : '',
  10014. ( extensions.drawBuffers ) && rendererExtensions.get( 'WEBGL_draw_buffers' ) ? '#extension GL_EXT_draw_buffers : require' : '',
  10015. ( extensions.shaderTextureLOD || parameters.envMap ) && rendererExtensions.get( 'EXT_shader_texture_lod' ) ? '#extension GL_EXT_shader_texture_lod : enable' : ''
  10016. ];
  10017. return chunks.filter( filterEmptyLine ).join( '\n' );
  10018. }
  10019. function generateDefines( defines ) {
  10020. var chunks = [];
  10021. for ( var name in defines ) {
  10022. var value = defines[ name ];
  10023. if ( value === false ) continue;
  10024. chunks.push( '#define ' + name + ' ' + value );
  10025. }
  10026. return chunks.join( '\n' );
  10027. }
  10028. function fetchAttributeLocations( gl, program ) {
  10029. var attributes = {};
  10030. var n = gl.getProgramParameter( program, 35721 );
  10031. for ( var i = 0; i < n; i ++ ) {
  10032. var info = gl.getActiveAttrib( program, i );
  10033. var name = info.name;
  10034. // console.log( 'THREE.WebGLProgram: ACTIVE VERTEX ATTRIBUTE:', name, i );
  10035. attributes[ name ] = gl.getAttribLocation( program, name );
  10036. }
  10037. return attributes;
  10038. }
  10039. function filterEmptyLine( string ) {
  10040. return string !== '';
  10041. }
  10042. function replaceLightNums( string, parameters ) {
  10043. return string
  10044. .replace( /NUM_DIR_LIGHTS/g, parameters.numDirLights )
  10045. .replace( /NUM_SPOT_LIGHTS/g, parameters.numSpotLights )
  10046. .replace( /NUM_RECT_AREA_LIGHTS/g, parameters.numRectAreaLights )
  10047. .replace( /NUM_POINT_LIGHTS/g, parameters.numPointLights )
  10048. .replace( /NUM_HEMI_LIGHTS/g, parameters.numHemiLights );
  10049. }
  10050. function replaceClippingPlaneNums( string, parameters ) {
  10051. return string
  10052. .replace( /NUM_CLIPPING_PLANES/g, parameters.numClippingPlanes )
  10053. .replace( /UNION_CLIPPING_PLANES/g, ( parameters.numClippingPlanes - parameters.numClipIntersection ) );
  10054. }
  10055. function parseIncludes( string ) {
  10056. var pattern = /^[ \t]*#include +<([\w\d./]+)>/gm;
  10057. function replace( match, include ) {
  10058. var replace = ShaderChunk[ include ];
  10059. if ( replace === undefined ) {
  10060. throw new Error( 'Can not resolve #include <' + include + '>' );
  10061. }
  10062. return parseIncludes( replace );
  10063. }
  10064. return string.replace( pattern, replace );
  10065. }
  10066. function unrollLoops( string ) {
  10067. var pattern = /#pragma unroll_loop[\s]+?for \( int i \= (\d+)\; i < (\d+)\; i \+\+ \) \{([\s\S]+?)(?=\})\}/g;
  10068. function replace( match, start, end, snippet ) {
  10069. var unroll = '';
  10070. for ( var i = parseInt( start ); i < parseInt( end ); i ++ ) {
  10071. unroll += snippet.replace( /\[ i \]/g, '[ ' + i + ' ]' );
  10072. }
  10073. return unroll;
  10074. }
  10075. return string.replace( pattern, replace );
  10076. }
  10077. function WebGLProgram( renderer, extensions, code, material, shader, parameters, capabilities ) {
  10078. var gl = renderer.context;
  10079. var defines = material.defines;
  10080. var vertexShader = shader.vertexShader;
  10081. var fragmentShader = shader.fragmentShader;
  10082. var shadowMapTypeDefine = 'SHADOWMAP_TYPE_BASIC';
  10083. if ( parameters.shadowMapType === PCFShadowMap ) {
  10084. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF';
  10085. } else if ( parameters.shadowMapType === PCFSoftShadowMap ) {
  10086. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF_SOFT';
  10087. }
  10088. var envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  10089. var envMapModeDefine = 'ENVMAP_MODE_REFLECTION';
  10090. var envMapBlendingDefine = 'ENVMAP_BLENDING_MULTIPLY';
  10091. if ( parameters.envMap ) {
  10092. switch ( material.envMap.mapping ) {
  10093. case CubeReflectionMapping:
  10094. case CubeRefractionMapping:
  10095. envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  10096. break;
  10097. case CubeUVReflectionMapping:
  10098. case CubeUVRefractionMapping:
  10099. envMapTypeDefine = 'ENVMAP_TYPE_CUBE_UV';
  10100. break;
  10101. case EquirectangularReflectionMapping:
  10102. case EquirectangularRefractionMapping:
  10103. envMapTypeDefine = 'ENVMAP_TYPE_EQUIREC';
  10104. break;
  10105. case SphericalReflectionMapping:
  10106. envMapTypeDefine = 'ENVMAP_TYPE_SPHERE';
  10107. break;
  10108. }
  10109. switch ( material.envMap.mapping ) {
  10110. case CubeRefractionMapping:
  10111. case EquirectangularRefractionMapping:
  10112. envMapModeDefine = 'ENVMAP_MODE_REFRACTION';
  10113. break;
  10114. }
  10115. switch ( material.combine ) {
  10116. case MultiplyOperation:
  10117. envMapBlendingDefine = 'ENVMAP_BLENDING_MULTIPLY';
  10118. break;
  10119. case MixOperation:
  10120. envMapBlendingDefine = 'ENVMAP_BLENDING_MIX';
  10121. break;
  10122. case AddOperation:
  10123. envMapBlendingDefine = 'ENVMAP_BLENDING_ADD';
  10124. break;
  10125. }
  10126. }
  10127. var gammaFactorDefine = ( renderer.gammaFactor > 0 ) ? renderer.gammaFactor : 1.0;
  10128. // console.log( 'building new program ' );
  10129. //
  10130. var customExtensions = capabilities.isWebGL2 ? '' : generateExtensions( material.extensions, parameters, extensions );
  10131. var customDefines = generateDefines( defines );
  10132. //
  10133. var program = gl.createProgram();
  10134. var prefixVertex, prefixFragment;
  10135. if ( material.isRawShaderMaterial ) {
  10136. prefixVertex = [
  10137. customDefines
  10138. ].filter( filterEmptyLine ).join( '\n' );
  10139. if ( prefixVertex.length > 0 ) {
  10140. prefixVertex += '\n';
  10141. }
  10142. prefixFragment = [
  10143. customExtensions,
  10144. customDefines
  10145. ].filter( filterEmptyLine ).join( '\n' );
  10146. if ( prefixFragment.length > 0 ) {
  10147. prefixFragment += '\n';
  10148. }
  10149. } else {
  10150. prefixVertex = [
  10151. 'precision ' + parameters.precision + ' float;',
  10152. 'precision ' + parameters.precision + ' int;',
  10153. '#define SHADER_NAME ' + shader.name,
  10154. customDefines,
  10155. parameters.supportsVertexTextures ? '#define VERTEX_TEXTURES' : '',
  10156. '#define GAMMA_FACTOR ' + gammaFactorDefine,
  10157. '#define MAX_BONES ' + parameters.maxBones,
  10158. ( parameters.useFog && parameters.fog ) ? '#define USE_FOG' : '',
  10159. ( parameters.useFog && parameters.fogExp ) ? '#define FOG_EXP2' : '',
  10160. parameters.map ? '#define USE_MAP' : '',
  10161. parameters.envMap ? '#define USE_ENVMAP' : '',
  10162. parameters.envMap ? '#define ' + envMapModeDefine : '',
  10163. parameters.lightMap ? '#define USE_LIGHTMAP' : '',
  10164. parameters.aoMap ? '#define USE_AOMAP' : '',
  10165. parameters.emissiveMap ? '#define USE_EMISSIVEMAP' : '',
  10166. parameters.bumpMap ? '#define USE_BUMPMAP' : '',
  10167. parameters.normalMap ? '#define USE_NORMALMAP' : '',
  10168. ( parameters.normalMap && parameters.objectSpaceNormalMap ) ? '#define OBJECTSPACE_NORMALMAP' : '',
  10169. parameters.displacementMap && parameters.supportsVertexTextures ? '#define USE_DISPLACEMENTMAP' : '',
  10170. parameters.specularMap ? '#define USE_SPECULARMAP' : '',
  10171. parameters.roughnessMap ? '#define USE_ROUGHNESSMAP' : '',
  10172. parameters.metalnessMap ? '#define USE_METALNESSMAP' : '',
  10173. parameters.alphaMap ? '#define USE_ALPHAMAP' : '',
  10174. parameters.vertexTangents ? '#define USE_TANGENT' : '',
  10175. parameters.vertexColors ? '#define USE_COLOR' : '',
  10176. parameters.flatShading ? '#define FLAT_SHADED' : '',
  10177. parameters.skinning ? '#define USE_SKINNING' : '',
  10178. parameters.useVertexTexture ? '#define BONE_TEXTURE' : '',
  10179. parameters.morphTargets ? '#define USE_MORPHTARGETS' : '',
  10180. parameters.morphNormals && parameters.flatShading === false ? '#define USE_MORPHNORMALS' : '',
  10181. parameters.doubleSided ? '#define DOUBLE_SIDED' : '',
  10182. parameters.flipSided ? '#define FLIP_SIDED' : '',
  10183. parameters.shadowMapEnabled ? '#define USE_SHADOWMAP' : '',
  10184. parameters.shadowMapEnabled ? '#define ' + shadowMapTypeDefine : '',
  10185. parameters.sizeAttenuation ? '#define USE_SIZEATTENUATION' : '',
  10186. parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
  10187. parameters.logarithmicDepthBuffer && ( capabilities.isWebGL2 || extensions.get( 'EXT_frag_depth' ) ) ? '#define USE_LOGDEPTHBUF_EXT' : '',
  10188. 'uniform mat4 modelMatrix;',
  10189. 'uniform mat4 modelViewMatrix;',
  10190. 'uniform mat4 projectionMatrix;',
  10191. 'uniform mat4 viewMatrix;',
  10192. 'uniform mat3 normalMatrix;',
  10193. 'uniform vec3 cameraPosition;',
  10194. 'attribute vec3 position;',
  10195. 'attribute vec3 normal;',
  10196. 'attribute vec2 uv;',
  10197. '#ifdef USE_TANGENT',
  10198. ' attribute vec4 tangent;',
  10199. '#endif',
  10200. '#ifdef USE_COLOR',
  10201. ' attribute vec3 color;',
  10202. '#endif',
  10203. '#ifdef USE_MORPHTARGETS',
  10204. ' attribute vec3 morphTarget0;',
  10205. ' attribute vec3 morphTarget1;',
  10206. ' attribute vec3 morphTarget2;',
  10207. ' attribute vec3 morphTarget3;',
  10208. ' #ifdef USE_MORPHNORMALS',
  10209. ' attribute vec3 morphNormal0;',
  10210. ' attribute vec3 morphNormal1;',
  10211. ' attribute vec3 morphNormal2;',
  10212. ' attribute vec3 morphNormal3;',
  10213. ' #else',
  10214. ' attribute vec3 morphTarget4;',
  10215. ' attribute vec3 morphTarget5;',
  10216. ' attribute vec3 morphTarget6;',
  10217. ' attribute vec3 morphTarget7;',
  10218. ' #endif',
  10219. '#endif',
  10220. '#ifdef USE_SKINNING',
  10221. ' attribute vec4 skinIndex;',
  10222. ' attribute vec4 skinWeight;',
  10223. '#endif',
  10224. '\n'
  10225. ].filter( filterEmptyLine ).join( '\n' );
  10226. prefixFragment = [
  10227. customExtensions,
  10228. 'precision ' + parameters.precision + ' float;',
  10229. 'precision ' + parameters.precision + ' int;',
  10230. '#define SHADER_NAME ' + shader.name,
  10231. customDefines,
  10232. parameters.alphaTest ? '#define ALPHATEST ' + parameters.alphaTest + ( parameters.alphaTest % 1 ? '' : '.0' ) : '', // add '.0' if integer
  10233. '#define GAMMA_FACTOR ' + gammaFactorDefine,
  10234. ( parameters.useFog && parameters.fog ) ? '#define USE_FOG' : '',
  10235. ( parameters.useFog && parameters.fogExp ) ? '#define FOG_EXP2' : '',
  10236. parameters.map ? '#define USE_MAP' : '',
  10237. parameters.matcap ? '#define USE_MATCAP' : '',
  10238. parameters.envMap ? '#define USE_ENVMAP' : '',
  10239. parameters.envMap ? '#define ' + envMapTypeDefine : '',
  10240. parameters.envMap ? '#define ' + envMapModeDefine : '',
  10241. parameters.envMap ? '#define ' + envMapBlendingDefine : '',
  10242. parameters.lightMap ? '#define USE_LIGHTMAP' : '',
  10243. parameters.aoMap ? '#define USE_AOMAP' : '',
  10244. parameters.emissiveMap ? '#define USE_EMISSIVEMAP' : '',
  10245. parameters.bumpMap ? '#define USE_BUMPMAP' : '',
  10246. parameters.normalMap ? '#define USE_NORMALMAP' : '',
  10247. ( parameters.normalMap && parameters.objectSpaceNormalMap ) ? '#define OBJECTSPACE_NORMALMAP' : '',
  10248. parameters.specularMap ? '#define USE_SPECULARMAP' : '',
  10249. parameters.roughnessMap ? '#define USE_ROUGHNESSMAP' : '',
  10250. parameters.metalnessMap ? '#define USE_METALNESSMAP' : '',
  10251. parameters.alphaMap ? '#define USE_ALPHAMAP' : '',
  10252. parameters.vertexTangents ? '#define USE_TANGENT' : '',
  10253. parameters.vertexColors ? '#define USE_COLOR' : '',
  10254. parameters.gradientMap ? '#define USE_GRADIENTMAP' : '',
  10255. parameters.flatShading ? '#define FLAT_SHADED' : '',
  10256. parameters.doubleSided ? '#define DOUBLE_SIDED' : '',
  10257. parameters.flipSided ? '#define FLIP_SIDED' : '',
  10258. parameters.shadowMapEnabled ? '#define USE_SHADOWMAP' : '',
  10259. parameters.shadowMapEnabled ? '#define ' + shadowMapTypeDefine : '',
  10260. parameters.premultipliedAlpha ? '#define PREMULTIPLIED_ALPHA' : '',
  10261. parameters.physicallyCorrectLights ? '#define PHYSICALLY_CORRECT_LIGHTS' : '',
  10262. parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
  10263. parameters.logarithmicDepthBuffer && ( capabilities.isWebGL2 || extensions.get( 'EXT_frag_depth' ) ) ? '#define USE_LOGDEPTHBUF_EXT' : '',
  10264. parameters.envMap && ( capabilities.isWebGL2 || extensions.get( 'EXT_shader_texture_lod' ) ) ? '#define TEXTURE_LOD_EXT' : '',
  10265. 'uniform mat4 viewMatrix;',
  10266. 'uniform vec3 cameraPosition;',
  10267. ( parameters.toneMapping !== NoToneMapping ) ? '#define TONE_MAPPING' : '',
  10268. ( parameters.toneMapping !== NoToneMapping ) ? ShaderChunk[ 'tonemapping_pars_fragment' ] : '', // this code is required here because it is used by the toneMapping() function defined below
  10269. ( parameters.toneMapping !== NoToneMapping ) ? getToneMappingFunction( 'toneMapping', parameters.toneMapping ) : '',
  10270. parameters.dithering ? '#define DITHERING' : '',
  10271. ( parameters.outputEncoding || parameters.mapEncoding || parameters.matcapEncoding || parameters.envMapEncoding || parameters.emissiveMapEncoding ) ?
  10272. ShaderChunk[ 'encodings_pars_fragment' ] : '', // this code is required here because it is used by the various encoding/decoding function defined below
  10273. parameters.mapEncoding ? getTexelDecodingFunction( 'mapTexelToLinear', parameters.mapEncoding ) : '',
  10274. parameters.matcapEncoding ? getTexelDecodingFunction( 'matcapTexelToLinear', parameters.matcapEncoding ) : '',
  10275. parameters.envMapEncoding ? getTexelDecodingFunction( 'envMapTexelToLinear', parameters.envMapEncoding ) : '',
  10276. parameters.emissiveMapEncoding ? getTexelDecodingFunction( 'emissiveMapTexelToLinear', parameters.emissiveMapEncoding ) : '',
  10277. parameters.outputEncoding ? getTexelEncodingFunction( 'linearToOutputTexel', parameters.outputEncoding ) : '',
  10278. parameters.depthPacking ? '#define DEPTH_PACKING ' + material.depthPacking : '',
  10279. '\n'
  10280. ].filter( filterEmptyLine ).join( '\n' );
  10281. }
  10282. vertexShader = parseIncludes( vertexShader );
  10283. vertexShader = replaceLightNums( vertexShader, parameters );
  10284. vertexShader = replaceClippingPlaneNums( vertexShader, parameters );
  10285. fragmentShader = parseIncludes( fragmentShader );
  10286. fragmentShader = replaceLightNums( fragmentShader, parameters );
  10287. fragmentShader = replaceClippingPlaneNums( fragmentShader, parameters );
  10288. vertexShader = unrollLoops( vertexShader );
  10289. fragmentShader = unrollLoops( fragmentShader );
  10290. if ( capabilities.isWebGL2 && ! material.isRawShaderMaterial ) {
  10291. var isGLSL3ShaderMaterial = false;
  10292. var versionRegex = /^\s*#version\s+300\s+es\s*\n/;
  10293. if ( material.isShaderMaterial &&
  10294. vertexShader.match( versionRegex ) !== null &&
  10295. fragmentShader.match( versionRegex ) !== null ) {
  10296. isGLSL3ShaderMaterial = true;
  10297. vertexShader = vertexShader.replace( versionRegex, '' );
  10298. fragmentShader = fragmentShader.replace( versionRegex, '' );
  10299. }
  10300. // GLSL 3.0 conversion
  10301. prefixVertex = [
  10302. '#version 300 es\n',
  10303. '#define attribute in',
  10304. '#define varying out',
  10305. '#define texture2D texture'
  10306. ].join( '\n' ) + '\n' + prefixVertex;
  10307. prefixFragment = [
  10308. '#version 300 es\n',
  10309. '#define varying in',
  10310. isGLSL3ShaderMaterial ? '' : 'out highp vec4 pc_fragColor;',
  10311. isGLSL3ShaderMaterial ? '' : '#define gl_FragColor pc_fragColor',
  10312. '#define gl_FragDepthEXT gl_FragDepth',
  10313. '#define texture2D texture',
  10314. '#define textureCube texture',
  10315. '#define texture2DProj textureProj',
  10316. '#define texture2DLodEXT textureLod',
  10317. '#define texture2DProjLodEXT textureProjLod',
  10318. '#define textureCubeLodEXT textureLod',
  10319. '#define texture2DGradEXT textureGrad',
  10320. '#define texture2DProjGradEXT textureProjGrad',
  10321. '#define textureCubeGradEXT textureGrad'
  10322. ].join( '\n' ) + '\n' + prefixFragment;
  10323. }
  10324. var vertexGlsl = prefixVertex + vertexShader;
  10325. var fragmentGlsl = prefixFragment + fragmentShader;
  10326. // console.log( '*VERTEX*', vertexGlsl );
  10327. // console.log( '*FRAGMENT*', fragmentGlsl );
  10328. var glVertexShader = WebGLShader( gl, 35633, vertexGlsl );
  10329. var glFragmentShader = WebGLShader( gl, 35632, fragmentGlsl );
  10330. gl.attachShader( program, glVertexShader );
  10331. gl.attachShader( program, glFragmentShader );
  10332. // Force a particular attribute to index 0.
  10333. if ( material.index0AttributeName !== undefined ) {
  10334. gl.bindAttribLocation( program, 0, material.index0AttributeName );
  10335. } else if ( parameters.morphTargets === true ) {
  10336. // programs with morphTargets displace position out of attribute 0
  10337. gl.bindAttribLocation( program, 0, 'position' );
  10338. }
  10339. gl.linkProgram( program );
  10340. var programLog = gl.getProgramInfoLog( program ).trim();
  10341. var vertexLog = gl.getShaderInfoLog( glVertexShader ).trim();
  10342. var fragmentLog = gl.getShaderInfoLog( glFragmentShader ).trim();
  10343. var runnable = true;
  10344. var haveDiagnostics = true;
  10345. // console.log( '**VERTEX**', gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( glVertexShader ) );
  10346. // console.log( '**FRAGMENT**', gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( glFragmentShader ) );
  10347. if ( gl.getProgramParameter( program, 35714 ) === false ) {
  10348. runnable = false;
  10349. console.error( 'THREE.WebGLProgram: shader error: ', gl.getError(), '35715', gl.getProgramParameter( program, 35715 ), 'gl.getProgramInfoLog', programLog, vertexLog, fragmentLog );
  10350. } else if ( programLog !== '' ) {
  10351. console.warn( 'THREE.WebGLProgram: gl.getProgramInfoLog()', programLog );
  10352. } else if ( vertexLog === '' || fragmentLog === '' ) {
  10353. haveDiagnostics = false;
  10354. }
  10355. if ( haveDiagnostics ) {
  10356. this.diagnostics = {
  10357. runnable: runnable,
  10358. material: material,
  10359. programLog: programLog,
  10360. vertexShader: {
  10361. log: vertexLog,
  10362. prefix: prefixVertex
  10363. },
  10364. fragmentShader: {
  10365. log: fragmentLog,
  10366. prefix: prefixFragment
  10367. }
  10368. };
  10369. }
  10370. // clean up
  10371. gl.deleteShader( glVertexShader );
  10372. gl.deleteShader( glFragmentShader );
  10373. // set up caching for uniform locations
  10374. var cachedUniforms;
  10375. this.getUniforms = function () {
  10376. if ( cachedUniforms === undefined ) {
  10377. cachedUniforms = new WebGLUniforms( gl, program, renderer );
  10378. }
  10379. return cachedUniforms;
  10380. };
  10381. // set up caching for attribute locations
  10382. var cachedAttributes;
  10383. this.getAttributes = function () {
  10384. if ( cachedAttributes === undefined ) {
  10385. cachedAttributes = fetchAttributeLocations( gl, program );
  10386. }
  10387. return cachedAttributes;
  10388. };
  10389. // free resource
  10390. this.destroy = function () {
  10391. gl.deleteProgram( program );
  10392. this.program = undefined;
  10393. };
  10394. // DEPRECATED
  10395. Object.defineProperties( this, {
  10396. uniforms: {
  10397. get: function () {
  10398. console.warn( 'THREE.WebGLProgram: .uniforms is now .getUniforms().' );
  10399. return this.getUniforms();
  10400. }
  10401. },
  10402. attributes: {
  10403. get: function () {
  10404. console.warn( 'THREE.WebGLProgram: .attributes is now .getAttributes().' );
  10405. return this.getAttributes();
  10406. }
  10407. }
  10408. } );
  10409. //
  10410. this.name = shader.name;
  10411. this.id = programIdCount ++;
  10412. this.code = code;
  10413. this.usedTimes = 1;
  10414. this.program = program;
  10415. this.vertexShader = glVertexShader;
  10416. this.fragmentShader = glFragmentShader;
  10417. return this;
  10418. }
  10419. /**
  10420. * @author mrdoob / http://mrdoob.com/
  10421. */
  10422. function WebGLPrograms( renderer, extensions, capabilities ) {
  10423. var programs = [];
  10424. var shaderIDs = {
  10425. MeshDepthMaterial: 'depth',
  10426. MeshDistanceMaterial: 'distanceRGBA',
  10427. MeshNormalMaterial: 'normal',
  10428. MeshBasicMaterial: 'basic',
  10429. MeshLambertMaterial: 'lambert',
  10430. MeshPhongMaterial: 'phong',
  10431. MeshToonMaterial: 'phong',
  10432. MeshStandardMaterial: 'physical',
  10433. MeshPhysicalMaterial: 'physical',
  10434. MeshMatcapMaterial: 'matcap',
  10435. LineBasicMaterial: 'basic',
  10436. LineDashedMaterial: 'dashed',
  10437. PointsMaterial: 'points',
  10438. ShadowMaterial: 'shadow',
  10439. SpriteMaterial: 'sprite'
  10440. };
  10441. var parameterNames = [
  10442. "precision", "supportsVertexTextures", "map", "mapEncoding", "matcap", "matcapEncoding", "envMap", "envMapMode", "envMapEncoding",
  10443. "lightMap", "aoMap", "emissiveMap", "emissiveMapEncoding", "bumpMap", "normalMap", "objectSpaceNormalMap", "displacementMap", "specularMap",
  10444. "roughnessMap", "metalnessMap", "gradientMap",
  10445. "alphaMap", "combine", "vertexColors", "vertexTangents", "fog", "useFog", "fogExp",
  10446. "flatShading", "sizeAttenuation", "logarithmicDepthBuffer", "skinning",
  10447. "maxBones", "useVertexTexture", "morphTargets", "morphNormals",
  10448. "maxMorphTargets", "maxMorphNormals", "premultipliedAlpha",
  10449. "numDirLights", "numPointLights", "numSpotLights", "numHemiLights", "numRectAreaLights",
  10450. "shadowMapEnabled", "shadowMapType", "toneMapping", 'physicallyCorrectLights',
  10451. "alphaTest", "doubleSided", "flipSided", "numClippingPlanes", "numClipIntersection", "depthPacking", "dithering"
  10452. ];
  10453. function allocateBones( object ) {
  10454. var skeleton = object.skeleton;
  10455. var bones = skeleton.bones;
  10456. if ( capabilities.floatVertexTextures ) {
  10457. return 1024;
  10458. } else {
  10459. // default for when object is not specified
  10460. // ( for example when prebuilding shader to be used with multiple objects )
  10461. //
  10462. // - leave some extra space for other uniforms
  10463. // - limit here is ANGLE's 254 max uniform vectors
  10464. // (up to 54 should be safe)
  10465. var nVertexUniforms = capabilities.maxVertexUniforms;
  10466. var nVertexMatrices = Math.floor( ( nVertexUniforms - 20 ) / 4 );
  10467. var maxBones = Math.min( nVertexMatrices, bones.length );
  10468. if ( maxBones < bones.length ) {
  10469. console.warn( 'THREE.WebGLRenderer: Skeleton has ' + bones.length + ' bones. This GPU supports ' + maxBones + '.' );
  10470. return 0;
  10471. }
  10472. return maxBones;
  10473. }
  10474. }
  10475. function getTextureEncodingFromMap( map, gammaOverrideLinear ) {
  10476. var encoding;
  10477. if ( ! map ) {
  10478. encoding = LinearEncoding;
  10479. } else if ( map.isTexture ) {
  10480. encoding = map.encoding;
  10481. } else if ( map.isWebGLRenderTarget ) {
  10482. console.warn( "THREE.WebGLPrograms.getTextureEncodingFromMap: don't use render targets as textures. Use their .texture property instead." );
  10483. encoding = map.texture.encoding;
  10484. }
  10485. // add backwards compatibility for WebGLRenderer.gammaInput/gammaOutput parameter, should probably be removed at some point.
  10486. if ( encoding === LinearEncoding && gammaOverrideLinear ) {
  10487. encoding = GammaEncoding;
  10488. }
  10489. return encoding;
  10490. }
  10491. this.getParameters = function ( material, lights, shadows, fog, nClipPlanes, nClipIntersection, object ) {
  10492. var shaderID = shaderIDs[ material.type ];
  10493. // heuristics to create shader parameters according to lights in the scene
  10494. // (not to blow over maxLights budget)
  10495. var maxBones = object.isSkinnedMesh ? allocateBones( object ) : 0;
  10496. var precision = capabilities.precision;
  10497. if ( material.precision !== null ) {
  10498. precision = capabilities.getMaxPrecision( material.precision );
  10499. if ( precision !== material.precision ) {
  10500. console.warn( 'THREE.WebGLProgram.getParameters:', material.precision, 'not supported, using', precision, 'instead.' );
  10501. }
  10502. }
  10503. var currentRenderTarget = renderer.getRenderTarget();
  10504. var parameters = {
  10505. shaderID: shaderID,
  10506. precision: precision,
  10507. supportsVertexTextures: capabilities.vertexTextures,
  10508. outputEncoding: getTextureEncodingFromMap( ( ! currentRenderTarget ) ? null : currentRenderTarget.texture, renderer.gammaOutput ),
  10509. map: !! material.map,
  10510. mapEncoding: getTextureEncodingFromMap( material.map, renderer.gammaInput ),
  10511. matcap: !! material.matcap,
  10512. matcapEncoding: getTextureEncodingFromMap( material.matcap, renderer.gammaInput ),
  10513. envMap: !! material.envMap,
  10514. envMapMode: material.envMap && material.envMap.mapping,
  10515. envMapEncoding: getTextureEncodingFromMap( material.envMap, renderer.gammaInput ),
  10516. envMapCubeUV: ( !! material.envMap ) && ( ( material.envMap.mapping === CubeUVReflectionMapping ) || ( material.envMap.mapping === CubeUVRefractionMapping ) ),
  10517. lightMap: !! material.lightMap,
  10518. aoMap: !! material.aoMap,
  10519. emissiveMap: !! material.emissiveMap,
  10520. emissiveMapEncoding: getTextureEncodingFromMap( material.emissiveMap, renderer.gammaInput ),
  10521. bumpMap: !! material.bumpMap,
  10522. normalMap: !! material.normalMap,
  10523. objectSpaceNormalMap: material.normalMapType === ObjectSpaceNormalMap,
  10524. displacementMap: !! material.displacementMap,
  10525. roughnessMap: !! material.roughnessMap,
  10526. metalnessMap: !! material.metalnessMap,
  10527. specularMap: !! material.specularMap,
  10528. alphaMap: !! material.alphaMap,
  10529. gradientMap: !! material.gradientMap,
  10530. combine: material.combine,
  10531. vertexTangents: ( material.normalMap && material.vertexTangents ),
  10532. vertexColors: material.vertexColors,
  10533. fog: !! fog,
  10534. useFog: material.fog,
  10535. fogExp: ( fog && fog.isFogExp2 ),
  10536. flatShading: material.flatShading,
  10537. sizeAttenuation: material.sizeAttenuation,
  10538. logarithmicDepthBuffer: capabilities.logarithmicDepthBuffer,
  10539. skinning: material.skinning && maxBones > 0,
  10540. maxBones: maxBones,
  10541. useVertexTexture: capabilities.floatVertexTextures,
  10542. morphTargets: material.morphTargets,
  10543. morphNormals: material.morphNormals,
  10544. maxMorphTargets: renderer.maxMorphTargets,
  10545. maxMorphNormals: renderer.maxMorphNormals,
  10546. numDirLights: lights.directional.length,
  10547. numPointLights: lights.point.length,
  10548. numSpotLights: lights.spot.length,
  10549. numRectAreaLights: lights.rectArea.length,
  10550. numHemiLights: lights.hemi.length,
  10551. numClippingPlanes: nClipPlanes,
  10552. numClipIntersection: nClipIntersection,
  10553. dithering: material.dithering,
  10554. shadowMapEnabled: renderer.shadowMap.enabled && object.receiveShadow && shadows.length > 0,
  10555. shadowMapType: renderer.shadowMap.type,
  10556. toneMapping: renderer.toneMapping,
  10557. physicallyCorrectLights: renderer.physicallyCorrectLights,
  10558. premultipliedAlpha: material.premultipliedAlpha,
  10559. alphaTest: material.alphaTest,
  10560. doubleSided: material.side === DoubleSide,
  10561. flipSided: material.side === BackSide,
  10562. depthPacking: ( material.depthPacking !== undefined ) ? material.depthPacking : false
  10563. };
  10564. return parameters;
  10565. };
  10566. this.getProgramCode = function ( material, parameters ) {
  10567. var array = [];
  10568. if ( parameters.shaderID ) {
  10569. array.push( parameters.shaderID );
  10570. } else {
  10571. array.push( material.fragmentShader );
  10572. array.push( material.vertexShader );
  10573. }
  10574. if ( material.defines !== undefined ) {
  10575. for ( var name in material.defines ) {
  10576. array.push( name );
  10577. array.push( material.defines[ name ] );
  10578. }
  10579. }
  10580. for ( var i = 0; i < parameterNames.length; i ++ ) {
  10581. array.push( parameters[ parameterNames[ i ] ] );
  10582. }
  10583. array.push( material.onBeforeCompile.toString() );
  10584. array.push( renderer.gammaOutput );
  10585. array.push( renderer.gammaFactor );
  10586. return array.join();
  10587. };
  10588. this.acquireProgram = function ( material, shader, parameters, code ) {
  10589. var program;
  10590. // Check if code has been already compiled
  10591. for ( var p = 0, pl = programs.length; p < pl; p ++ ) {
  10592. var programInfo = programs[ p ];
  10593. if ( programInfo.code === code ) {
  10594. program = programInfo;
  10595. ++ program.usedTimes;
  10596. break;
  10597. }
  10598. }
  10599. if ( program === undefined ) {
  10600. program = new WebGLProgram( renderer, extensions, code, material, shader, parameters, capabilities );
  10601. programs.push( program );
  10602. }
  10603. return program;
  10604. };
  10605. this.releaseProgram = function ( program ) {
  10606. if ( -- program.usedTimes === 0 ) {
  10607. // Remove from unordered set
  10608. var i = programs.indexOf( program );
  10609. programs[ i ] = programs[ programs.length - 1 ];
  10610. programs.pop();
  10611. // Free WebGL resources
  10612. program.destroy();
  10613. }
  10614. };
  10615. // Exposed for resource monitoring & error feedback via renderer.info:
  10616. this.programs = programs;
  10617. }
  10618. /**
  10619. * @author fordacious / fordacious.github.io
  10620. */
  10621. function WebGLProperties() {
  10622. var properties = new WeakMap();
  10623. function get( object ) {
  10624. var map = properties.get( object );
  10625. if ( map === undefined ) {
  10626. map = {};
  10627. properties.set( object, map );
  10628. }
  10629. return map;
  10630. }
  10631. function remove( object ) {
  10632. properties.delete( object );
  10633. }
  10634. function update( object, key, value ) {
  10635. properties.get( object )[ key ] = value;
  10636. }
  10637. function dispose() {
  10638. properties = new WeakMap();
  10639. }
  10640. return {
  10641. get: get,
  10642. remove: remove,
  10643. update: update,
  10644. dispose: dispose
  10645. };
  10646. }
  10647. /**
  10648. * @author mrdoob / http://mrdoob.com/
  10649. */
  10650. function painterSortStable( a, b ) {
  10651. if ( a.groupOrder !== b.groupOrder ) {
  10652. return a.groupOrder - b.groupOrder;
  10653. } else if ( a.renderOrder !== b.renderOrder ) {
  10654. return a.renderOrder - b.renderOrder;
  10655. } else if ( a.program && b.program && a.program !== b.program ) {
  10656. return a.program.id - b.program.id;
  10657. } else if ( a.material.id !== b.material.id ) {
  10658. return a.material.id - b.material.id;
  10659. } else if ( a.z !== b.z ) {
  10660. return a.z - b.z;
  10661. } else {
  10662. return a.id - b.id;
  10663. }
  10664. }
  10665. function reversePainterSortStable( a, b ) {
  10666. if ( a.groupOrder !== b.groupOrder ) {
  10667. return a.groupOrder - b.groupOrder;
  10668. } else if ( a.renderOrder !== b.renderOrder ) {
  10669. return a.renderOrder - b.renderOrder;
  10670. } else if ( a.z !== b.z ) {
  10671. return b.z - a.z;
  10672. } else {
  10673. return a.id - b.id;
  10674. }
  10675. }
  10676. function WebGLRenderList() {
  10677. var renderItems = [];
  10678. var renderItemsIndex = 0;
  10679. var opaque = [];
  10680. var transparent = [];
  10681. function init() {
  10682. renderItemsIndex = 0;
  10683. opaque.length = 0;
  10684. transparent.length = 0;
  10685. }
  10686. function getNextRenderItem( object, geometry, material, groupOrder, z, group ) {
  10687. var renderItem = renderItems[ renderItemsIndex ];
  10688. if ( renderItem === undefined ) {
  10689. renderItem = {
  10690. id: object.id,
  10691. object: object,
  10692. geometry: geometry,
  10693. material: material,
  10694. program: material.program,
  10695. groupOrder: groupOrder,
  10696. renderOrder: object.renderOrder,
  10697. z: z,
  10698. group: group
  10699. };
  10700. renderItems[ renderItemsIndex ] = renderItem;
  10701. } else {
  10702. renderItem.id = object.id;
  10703. renderItem.object = object;
  10704. renderItem.geometry = geometry;
  10705. renderItem.material = material;
  10706. renderItem.program = material.program;
  10707. renderItem.groupOrder = groupOrder;
  10708. renderItem.renderOrder = object.renderOrder;
  10709. renderItem.z = z;
  10710. renderItem.group = group;
  10711. }
  10712. renderItemsIndex ++;
  10713. return renderItem;
  10714. }
  10715. function push( object, geometry, material, groupOrder, z, group ) {
  10716. var renderItem = getNextRenderItem( object, geometry, material, groupOrder, z, group );
  10717. ( material.transparent === true ? transparent : opaque ).push( renderItem );
  10718. }
  10719. function unshift( object, geometry, material, groupOrder, z, group ) {
  10720. var renderItem = getNextRenderItem( object, geometry, material, groupOrder, z, group );
  10721. ( material.transparent === true ? transparent : opaque ).unshift( renderItem );
  10722. }
  10723. function sort() {
  10724. if ( opaque.length > 1 ) opaque.sort( painterSortStable );
  10725. if ( transparent.length > 1 ) transparent.sort( reversePainterSortStable );
  10726. }
  10727. return {
  10728. opaque: opaque,
  10729. transparent: transparent,
  10730. init: init,
  10731. push: push,
  10732. unshift: unshift,
  10733. sort: sort
  10734. };
  10735. }
  10736. function WebGLRenderLists() {
  10737. var lists = {};
  10738. function onSceneDispose( event ) {
  10739. var scene = event.target;
  10740. scene.removeEventListener( 'dispose', onSceneDispose );
  10741. delete lists[ scene.id ];
  10742. }
  10743. function get( scene, camera ) {
  10744. var cameras = lists[ scene.id ];
  10745. var list;
  10746. if ( cameras === undefined ) {
  10747. list = new WebGLRenderList();
  10748. lists[ scene.id ] = {};
  10749. lists[ scene.id ][ camera.id ] = list;
  10750. scene.addEventListener( 'dispose', onSceneDispose );
  10751. } else {
  10752. list = cameras[ camera.id ];
  10753. if ( list === undefined ) {
  10754. list = new WebGLRenderList();
  10755. cameras[ camera.id ] = list;
  10756. }
  10757. }
  10758. return list;
  10759. }
  10760. function dispose() {
  10761. lists = {};
  10762. }
  10763. return {
  10764. get: get,
  10765. dispose: dispose
  10766. };
  10767. }
  10768. /**
  10769. * @author mrdoob / http://mrdoob.com/
  10770. */
  10771. function UniformsCache() {
  10772. var lights = {};
  10773. return {
  10774. get: function ( light ) {
  10775. if ( lights[ light.id ] !== undefined ) {
  10776. return lights[ light.id ];
  10777. }
  10778. var uniforms;
  10779. switch ( light.type ) {
  10780. case 'DirectionalLight':
  10781. uniforms = {
  10782. direction: new Vector3(),
  10783. color: new Color(),
  10784. shadow: false,
  10785. shadowBias: 0,
  10786. shadowRadius: 1,
  10787. shadowMapSize: new Vector2()
  10788. };
  10789. break;
  10790. case 'SpotLight':
  10791. uniforms = {
  10792. position: new Vector3(),
  10793. direction: new Vector3(),
  10794. color: new Color(),
  10795. distance: 0,
  10796. coneCos: 0,
  10797. penumbraCos: 0,
  10798. decay: 0,
  10799. shadow: false,
  10800. shadowBias: 0,
  10801. shadowRadius: 1,
  10802. shadowMapSize: new Vector2()
  10803. };
  10804. break;
  10805. case 'PointLight':
  10806. uniforms = {
  10807. position: new Vector3(),
  10808. color: new Color(),
  10809. distance: 0,
  10810. decay: 0,
  10811. shadow: false,
  10812. shadowBias: 0,
  10813. shadowRadius: 1,
  10814. shadowMapSize: new Vector2(),
  10815. shadowCameraNear: 1,
  10816. shadowCameraFar: 1000
  10817. };
  10818. break;
  10819. case 'HemisphereLight':
  10820. uniforms = {
  10821. direction: new Vector3(),
  10822. skyColor: new Color(),
  10823. groundColor: new Color()
  10824. };
  10825. break;
  10826. case 'RectAreaLight':
  10827. uniforms = {
  10828. color: new Color(),
  10829. position: new Vector3(),
  10830. halfWidth: new Vector3(),
  10831. halfHeight: new Vector3()
  10832. // TODO (abelnation): set RectAreaLight shadow uniforms
  10833. };
  10834. break;
  10835. }
  10836. lights[ light.id ] = uniforms;
  10837. return uniforms;
  10838. }
  10839. };
  10840. }
  10841. var count = 0;
  10842. function WebGLLights() {
  10843. var cache = new UniformsCache();
  10844. var state = {
  10845. id: count ++,
  10846. hash: {
  10847. stateID: - 1,
  10848. directionalLength: - 1,
  10849. pointLength: - 1,
  10850. spotLength: - 1,
  10851. rectAreaLength: - 1,
  10852. hemiLength: - 1,
  10853. shadowsLength: - 1
  10854. },
  10855. ambient: [ 0, 0, 0 ],
  10856. directional: [],
  10857. directionalShadowMap: [],
  10858. directionalShadowMatrix: [],
  10859. spot: [],
  10860. spotShadowMap: [],
  10861. spotShadowMatrix: [],
  10862. rectArea: [],
  10863. point: [],
  10864. pointShadowMap: [],
  10865. pointShadowMatrix: [],
  10866. hemi: []
  10867. };
  10868. var vector3 = new Vector3();
  10869. var matrix4 = new Matrix4();
  10870. var matrix42 = new Matrix4();
  10871. function setup( lights, shadows, camera ) {
  10872. var r = 0, g = 0, b = 0;
  10873. var directionalLength = 0;
  10874. var pointLength = 0;
  10875. var spotLength = 0;
  10876. var rectAreaLength = 0;
  10877. var hemiLength = 0;
  10878. var viewMatrix = camera.matrixWorldInverse;
  10879. for ( var i = 0, l = lights.length; i < l; i ++ ) {
  10880. var light = lights[ i ];
  10881. var color = light.color;
  10882. var intensity = light.intensity;
  10883. var distance = light.distance;
  10884. var shadowMap = ( light.shadow && light.shadow.map ) ? light.shadow.map.texture : null;
  10885. if ( light.isAmbientLight ) {
  10886. r += color.r * intensity;
  10887. g += color.g * intensity;
  10888. b += color.b * intensity;
  10889. } else if ( light.isDirectionalLight ) {
  10890. var uniforms = cache.get( light );
  10891. uniforms.color.copy( light.color ).multiplyScalar( light.intensity );
  10892. uniforms.direction.setFromMatrixPosition( light.matrixWorld );
  10893. vector3.setFromMatrixPosition( light.target.matrixWorld );
  10894. uniforms.direction.sub( vector3 );
  10895. uniforms.direction.transformDirection( viewMatrix );
  10896. uniforms.shadow = light.castShadow;
  10897. if ( light.castShadow ) {
  10898. var shadow = light.shadow;
  10899. uniforms.shadowBias = shadow.bias;
  10900. uniforms.shadowRadius = shadow.radius;
  10901. uniforms.shadowMapSize = shadow.mapSize;
  10902. }
  10903. state.directionalShadowMap[ directionalLength ] = shadowMap;
  10904. state.directionalShadowMatrix[ directionalLength ] = light.shadow.matrix;
  10905. state.directional[ directionalLength ] = uniforms;
  10906. directionalLength ++;
  10907. } else if ( light.isSpotLight ) {
  10908. var uniforms = cache.get( light );
  10909. uniforms.position.setFromMatrixPosition( light.matrixWorld );
  10910. uniforms.position.applyMatrix4( viewMatrix );
  10911. uniforms.color.copy( color ).multiplyScalar( intensity );
  10912. uniforms.distance = distance;
  10913. uniforms.direction.setFromMatrixPosition( light.matrixWorld );
  10914. vector3.setFromMatrixPosition( light.target.matrixWorld );
  10915. uniforms.direction.sub( vector3 );
  10916. uniforms.direction.transformDirection( viewMatrix );
  10917. uniforms.coneCos = Math.cos( light.angle );
  10918. uniforms.penumbraCos = Math.cos( light.angle * ( 1 - light.penumbra ) );
  10919. uniforms.decay = light.decay;
  10920. uniforms.shadow = light.castShadow;
  10921. if ( light.castShadow ) {
  10922. var shadow = light.shadow;
  10923. uniforms.shadowBias = shadow.bias;
  10924. uniforms.shadowRadius = shadow.radius;
  10925. uniforms.shadowMapSize = shadow.mapSize;
  10926. }
  10927. state.spotShadowMap[ spotLength ] = shadowMap;
  10928. state.spotShadowMatrix[ spotLength ] = light.shadow.matrix;
  10929. state.spot[ spotLength ] = uniforms;
  10930. spotLength ++;
  10931. } else if ( light.isRectAreaLight ) {
  10932. var uniforms = cache.get( light );
  10933. // (a) intensity is the total visible light emitted
  10934. //uniforms.color.copy( color ).multiplyScalar( intensity / ( light.width * light.height * Math.PI ) );
  10935. // (b) intensity is the brightness of the light
  10936. uniforms.color.copy( color ).multiplyScalar( intensity );
  10937. uniforms.position.setFromMatrixPosition( light.matrixWorld );
  10938. uniforms.position.applyMatrix4( viewMatrix );
  10939. // extract local rotation of light to derive width/height half vectors
  10940. matrix42.identity();
  10941. matrix4.copy( light.matrixWorld );
  10942. matrix4.premultiply( viewMatrix );
  10943. matrix42.extractRotation( matrix4 );
  10944. uniforms.halfWidth.set( light.width * 0.5, 0.0, 0.0 );
  10945. uniforms.halfHeight.set( 0.0, light.height * 0.5, 0.0 );
  10946. uniforms.halfWidth.applyMatrix4( matrix42 );
  10947. uniforms.halfHeight.applyMatrix4( matrix42 );
  10948. // TODO (abelnation): RectAreaLight distance?
  10949. // uniforms.distance = distance;
  10950. state.rectArea[ rectAreaLength ] = uniforms;
  10951. rectAreaLength ++;
  10952. } else if ( light.isPointLight ) {
  10953. var uniforms = cache.get( light );
  10954. uniforms.position.setFromMatrixPosition( light.matrixWorld );
  10955. uniforms.position.applyMatrix4( viewMatrix );
  10956. uniforms.color.copy( light.color ).multiplyScalar( light.intensity );
  10957. uniforms.distance = light.distance;
  10958. uniforms.decay = light.decay;
  10959. uniforms.shadow = light.castShadow;
  10960. if ( light.castShadow ) {
  10961. var shadow = light.shadow;
  10962. uniforms.shadowBias = shadow.bias;
  10963. uniforms.shadowRadius = shadow.radius;
  10964. uniforms.shadowMapSize = shadow.mapSize;
  10965. uniforms.shadowCameraNear = shadow.camera.near;
  10966. uniforms.shadowCameraFar = shadow.camera.far;
  10967. }
  10968. state.pointShadowMap[ pointLength ] = shadowMap;
  10969. state.pointShadowMatrix[ pointLength ] = light.shadow.matrix;
  10970. state.point[ pointLength ] = uniforms;
  10971. pointLength ++;
  10972. } else if ( light.isHemisphereLight ) {
  10973. var uniforms = cache.get( light );
  10974. uniforms.direction.setFromMatrixPosition( light.matrixWorld );
  10975. uniforms.direction.transformDirection( viewMatrix );
  10976. uniforms.direction.normalize();
  10977. uniforms.skyColor.copy( light.color ).multiplyScalar( intensity );
  10978. uniforms.groundColor.copy( light.groundColor ).multiplyScalar( intensity );
  10979. state.hemi[ hemiLength ] = uniforms;
  10980. hemiLength ++;
  10981. }
  10982. }
  10983. state.ambient[ 0 ] = r;
  10984. state.ambient[ 1 ] = g;
  10985. state.ambient[ 2 ] = b;
  10986. state.directional.length = directionalLength;
  10987. state.spot.length = spotLength;
  10988. state.rectArea.length = rectAreaLength;
  10989. state.point.length = pointLength;
  10990. state.hemi.length = hemiLength;
  10991. state.hash.stateID = state.id;
  10992. state.hash.directionalLength = directionalLength;
  10993. state.hash.pointLength = pointLength;
  10994. state.hash.spotLength = spotLength;
  10995. state.hash.rectAreaLength = rectAreaLength;
  10996. state.hash.hemiLength = hemiLength;
  10997. state.hash.shadowsLength = shadows.length;
  10998. }
  10999. return {
  11000. setup: setup,
  11001. state: state
  11002. };
  11003. }
  11004. /**
  11005. * @author Mugen87 / https://github.com/Mugen87
  11006. */
  11007. function WebGLRenderState() {
  11008. var lights = new WebGLLights();
  11009. var lightsArray = [];
  11010. var shadowsArray = [];
  11011. function init() {
  11012. lightsArray.length = 0;
  11013. shadowsArray.length = 0;
  11014. }
  11015. function pushLight( light ) {
  11016. lightsArray.push( light );
  11017. }
  11018. function pushShadow( shadowLight ) {
  11019. shadowsArray.push( shadowLight );
  11020. }
  11021. function setupLights( camera ) {
  11022. lights.setup( lightsArray, shadowsArray, camera );
  11023. }
  11024. var state = {
  11025. lightsArray: lightsArray,
  11026. shadowsArray: shadowsArray,
  11027. lights: lights
  11028. };
  11029. return {
  11030. init: init,
  11031. state: state,
  11032. setupLights: setupLights,
  11033. pushLight: pushLight,
  11034. pushShadow: pushShadow
  11035. };
  11036. }
  11037. function WebGLRenderStates() {
  11038. var renderStates = {};
  11039. function onSceneDispose( event ) {
  11040. var scene = event.target;
  11041. scene.removeEventListener( 'dispose', onSceneDispose );
  11042. delete renderStates[ scene.id ];
  11043. }
  11044. function get( scene, camera ) {
  11045. var renderState;
  11046. if ( renderStates[ scene.id ] === undefined ) {
  11047. renderState = new WebGLRenderState();
  11048. renderStates[ scene.id ] = {};
  11049. renderStates[ scene.id ][ camera.id ] = renderState;
  11050. scene.addEventListener( 'dispose', onSceneDispose );
  11051. } else {
  11052. if ( renderStates[ scene.id ][ camera.id ] === undefined ) {
  11053. renderState = new WebGLRenderState();
  11054. renderStates[ scene.id ][ camera.id ] = renderState;
  11055. } else {
  11056. renderState = renderStates[ scene.id ][ camera.id ];
  11057. }
  11058. }
  11059. return renderState;
  11060. }
  11061. function dispose() {
  11062. renderStates = {};
  11063. }
  11064. return {
  11065. get: get,
  11066. dispose: dispose
  11067. };
  11068. }
  11069. /**
  11070. * @author mrdoob / http://mrdoob.com/
  11071. * @author alteredq / http://alteredqualia.com/
  11072. * @author bhouston / https://clara.io
  11073. * @author WestLangley / http://github.com/WestLangley
  11074. *
  11075. * parameters = {
  11076. *
  11077. * opacity: <float>,
  11078. *
  11079. * map: new THREE.Texture( <Image> ),
  11080. *
  11081. * alphaMap: new THREE.Texture( <Image> ),
  11082. *
  11083. * displacementMap: new THREE.Texture( <Image> ),
  11084. * displacementScale: <float>,
  11085. * displacementBias: <float>,
  11086. *
  11087. * wireframe: <boolean>,
  11088. * wireframeLinewidth: <float>
  11089. * }
  11090. */
  11091. function MeshDepthMaterial( parameters ) {
  11092. Material.call( this );
  11093. this.type = 'MeshDepthMaterial';
  11094. this.depthPacking = BasicDepthPacking;
  11095. this.skinning = false;
  11096. this.morphTargets = false;
  11097. this.map = null;
  11098. this.alphaMap = null;
  11099. this.displacementMap = null;
  11100. this.displacementScale = 1;
  11101. this.displacementBias = 0;
  11102. this.wireframe = false;
  11103. this.wireframeLinewidth = 1;
  11104. this.fog = false;
  11105. this.lights = false;
  11106. this.setValues( parameters );
  11107. }
  11108. MeshDepthMaterial.prototype = Object.create( Material.prototype );
  11109. MeshDepthMaterial.prototype.constructor = MeshDepthMaterial;
  11110. MeshDepthMaterial.prototype.isMeshDepthMaterial = true;
  11111. MeshDepthMaterial.prototype.copy = function ( source ) {
  11112. Material.prototype.copy.call( this, source );
  11113. this.depthPacking = source.depthPacking;
  11114. this.skinning = source.skinning;
  11115. this.morphTargets = source.morphTargets;
  11116. this.map = source.map;
  11117. this.alphaMap = source.alphaMap;
  11118. this.displacementMap = source.displacementMap;
  11119. this.displacementScale = source.displacementScale;
  11120. this.displacementBias = source.displacementBias;
  11121. this.wireframe = source.wireframe;
  11122. this.wireframeLinewidth = source.wireframeLinewidth;
  11123. return this;
  11124. };
  11125. /**
  11126. * @author WestLangley / http://github.com/WestLangley
  11127. *
  11128. * parameters = {
  11129. *
  11130. * referencePosition: <float>,
  11131. * nearDistance: <float>,
  11132. * farDistance: <float>,
  11133. *
  11134. * skinning: <bool>,
  11135. * morphTargets: <bool>,
  11136. *
  11137. * map: new THREE.Texture( <Image> ),
  11138. *
  11139. * alphaMap: new THREE.Texture( <Image> ),
  11140. *
  11141. * displacementMap: new THREE.Texture( <Image> ),
  11142. * displacementScale: <float>,
  11143. * displacementBias: <float>
  11144. *
  11145. * }
  11146. */
  11147. function MeshDistanceMaterial( parameters ) {
  11148. Material.call( this );
  11149. this.type = 'MeshDistanceMaterial';
  11150. this.referencePosition = new Vector3();
  11151. this.nearDistance = 1;
  11152. this.farDistance = 1000;
  11153. this.skinning = false;
  11154. this.morphTargets = false;
  11155. this.map = null;
  11156. this.alphaMap = null;
  11157. this.displacementMap = null;
  11158. this.displacementScale = 1;
  11159. this.displacementBias = 0;
  11160. this.fog = false;
  11161. this.lights = false;
  11162. this.setValues( parameters );
  11163. }
  11164. MeshDistanceMaterial.prototype = Object.create( Material.prototype );
  11165. MeshDistanceMaterial.prototype.constructor = MeshDistanceMaterial;
  11166. MeshDistanceMaterial.prototype.isMeshDistanceMaterial = true;
  11167. MeshDistanceMaterial.prototype.copy = function ( source ) {
  11168. Material.prototype.copy.call( this, source );
  11169. this.referencePosition.copy( source.referencePosition );
  11170. this.nearDistance = source.nearDistance;
  11171. this.farDistance = source.farDistance;
  11172. this.skinning = source.skinning;
  11173. this.morphTargets = source.morphTargets;
  11174. this.map = source.map;
  11175. this.alphaMap = source.alphaMap;
  11176. this.displacementMap = source.displacementMap;
  11177. this.displacementScale = source.displacementScale;
  11178. this.displacementBias = source.displacementBias;
  11179. return this;
  11180. };
  11181. /**
  11182. * @author alteredq / http://alteredqualia.com/
  11183. * @author mrdoob / http://mrdoob.com/
  11184. */
  11185. function WebGLShadowMap( _renderer, _objects, maxTextureSize ) {
  11186. var _frustum = new Frustum(),
  11187. _projScreenMatrix = new Matrix4(),
  11188. _shadowMapSize = new Vector2(),
  11189. _maxShadowMapSize = new Vector2( maxTextureSize, maxTextureSize ),
  11190. _lookTarget = new Vector3(),
  11191. _lightPositionWorld = new Vector3(),
  11192. _MorphingFlag = 1,
  11193. _SkinningFlag = 2,
  11194. _NumberOfMaterialVariants = ( _MorphingFlag | _SkinningFlag ) + 1,
  11195. _depthMaterials = new Array( _NumberOfMaterialVariants ),
  11196. _distanceMaterials = new Array( _NumberOfMaterialVariants ),
  11197. _materialCache = {};
  11198. var shadowSide = { 0: BackSide, 1: FrontSide, 2: DoubleSide };
  11199. var cubeDirections = [
  11200. new Vector3( 1, 0, 0 ), new Vector3( - 1, 0, 0 ), new Vector3( 0, 0, 1 ),
  11201. new Vector3( 0, 0, - 1 ), new Vector3( 0, 1, 0 ), new Vector3( 0, - 1, 0 )
  11202. ];
  11203. var cubeUps = [
  11204. new Vector3( 0, 1, 0 ), new Vector3( 0, 1, 0 ), new Vector3( 0, 1, 0 ),
  11205. new Vector3( 0, 1, 0 ), new Vector3( 0, 0, 1 ), new Vector3( 0, 0, - 1 )
  11206. ];
  11207. var cube2DViewPorts = [
  11208. new Vector4(), new Vector4(), new Vector4(),
  11209. new Vector4(), new Vector4(), new Vector4()
  11210. ];
  11211. // init
  11212. for ( var i = 0; i !== _NumberOfMaterialVariants; ++ i ) {
  11213. var useMorphing = ( i & _MorphingFlag ) !== 0;
  11214. var useSkinning = ( i & _SkinningFlag ) !== 0;
  11215. var depthMaterial = new MeshDepthMaterial( {
  11216. depthPacking: RGBADepthPacking,
  11217. morphTargets: useMorphing,
  11218. skinning: useSkinning
  11219. } );
  11220. _depthMaterials[ i ] = depthMaterial;
  11221. //
  11222. var distanceMaterial = new MeshDistanceMaterial( {
  11223. morphTargets: useMorphing,
  11224. skinning: useSkinning
  11225. } );
  11226. _distanceMaterials[ i ] = distanceMaterial;
  11227. }
  11228. //
  11229. var scope = this;
  11230. this.enabled = false;
  11231. this.autoUpdate = true;
  11232. this.needsUpdate = false;
  11233. this.type = PCFShadowMap;
  11234. this.render = function ( lights, scene, camera ) {
  11235. if ( scope.enabled === false ) return;
  11236. if ( scope.autoUpdate === false && scope.needsUpdate === false ) return;
  11237. if ( lights.length === 0 ) return;
  11238. var currentRenderTarget = _renderer.getRenderTarget();
  11239. var _state = _renderer.state;
  11240. // Set GL state for depth map.
  11241. _state.setBlending( NoBlending );
  11242. _state.buffers.color.setClear( 1, 1, 1, 1 );
  11243. _state.buffers.depth.setTest( true );
  11244. _state.setScissorTest( false );
  11245. // render depth map
  11246. var faceCount;
  11247. for ( var i = 0, il = lights.length; i < il; i ++ ) {
  11248. var light = lights[ i ];
  11249. var shadow = light.shadow;
  11250. var isPointLight = light && light.isPointLight;
  11251. if ( shadow === undefined ) {
  11252. console.warn( 'THREE.WebGLShadowMap:', light, 'has no shadow.' );
  11253. continue;
  11254. }
  11255. var shadowCamera = shadow.camera;
  11256. _shadowMapSize.copy( shadow.mapSize );
  11257. _shadowMapSize.min( _maxShadowMapSize );
  11258. if ( isPointLight ) {
  11259. var vpWidth = _shadowMapSize.x;
  11260. var vpHeight = _shadowMapSize.y;
  11261. // These viewports map a cube-map onto a 2D texture with the
  11262. // following orientation:
  11263. //
  11264. // xzXZ
  11265. // y Y
  11266. //
  11267. // X - Positive x direction
  11268. // x - Negative x direction
  11269. // Y - Positive y direction
  11270. // y - Negative y direction
  11271. // Z - Positive z direction
  11272. // z - Negative z direction
  11273. // positive X
  11274. cube2DViewPorts[ 0 ].set( vpWidth * 2, vpHeight, vpWidth, vpHeight );
  11275. // negative X
  11276. cube2DViewPorts[ 1 ].set( 0, vpHeight, vpWidth, vpHeight );
  11277. // positive Z
  11278. cube2DViewPorts[ 2 ].set( vpWidth * 3, vpHeight, vpWidth, vpHeight );
  11279. // negative Z
  11280. cube2DViewPorts[ 3 ].set( vpWidth, vpHeight, vpWidth, vpHeight );
  11281. // positive Y
  11282. cube2DViewPorts[ 4 ].set( vpWidth * 3, 0, vpWidth, vpHeight );
  11283. // negative Y
  11284. cube2DViewPorts[ 5 ].set( vpWidth, 0, vpWidth, vpHeight );
  11285. _shadowMapSize.x *= 4.0;
  11286. _shadowMapSize.y *= 2.0;
  11287. }
  11288. if ( shadow.map === null ) {
  11289. var pars = { minFilter: NearestFilter, magFilter: NearestFilter, format: RGBAFormat };
  11290. shadow.map = new WebGLRenderTarget( _shadowMapSize.x, _shadowMapSize.y, pars );
  11291. shadow.map.texture.name = light.name + ".shadowMap";
  11292. shadowCamera.updateProjectionMatrix();
  11293. }
  11294. if ( shadow.isSpotLightShadow ) {
  11295. shadow.update( light );
  11296. }
  11297. var shadowMap = shadow.map;
  11298. var shadowMatrix = shadow.matrix;
  11299. _lightPositionWorld.setFromMatrixPosition( light.matrixWorld );
  11300. shadowCamera.position.copy( _lightPositionWorld );
  11301. if ( isPointLight ) {
  11302. faceCount = 6;
  11303. // for point lights we set the shadow matrix to be a translation-only matrix
  11304. // equal to inverse of the light's position
  11305. shadowMatrix.makeTranslation( - _lightPositionWorld.x, - _lightPositionWorld.y, - _lightPositionWorld.z );
  11306. } else {
  11307. faceCount = 1;
  11308. _lookTarget.setFromMatrixPosition( light.target.matrixWorld );
  11309. shadowCamera.lookAt( _lookTarget );
  11310. shadowCamera.updateMatrixWorld();
  11311. // compute shadow matrix
  11312. shadowMatrix.set(
  11313. 0.5, 0.0, 0.0, 0.5,
  11314. 0.0, 0.5, 0.0, 0.5,
  11315. 0.0, 0.0, 0.5, 0.5,
  11316. 0.0, 0.0, 0.0, 1.0
  11317. );
  11318. shadowMatrix.multiply( shadowCamera.projectionMatrix );
  11319. shadowMatrix.multiply( shadowCamera.matrixWorldInverse );
  11320. }
  11321. _renderer.setRenderTarget( shadowMap );
  11322. _renderer.clear();
  11323. // render shadow map for each cube face (if omni-directional) or
  11324. // run a single pass if not
  11325. for ( var face = 0; face < faceCount; face ++ ) {
  11326. if ( isPointLight ) {
  11327. _lookTarget.copy( shadowCamera.position );
  11328. _lookTarget.add( cubeDirections[ face ] );
  11329. shadowCamera.up.copy( cubeUps[ face ] );
  11330. shadowCamera.lookAt( _lookTarget );
  11331. shadowCamera.updateMatrixWorld();
  11332. var vpDimensions = cube2DViewPorts[ face ];
  11333. _state.viewport( vpDimensions );
  11334. }
  11335. // update camera matrices and frustum
  11336. _projScreenMatrix.multiplyMatrices( shadowCamera.projectionMatrix, shadowCamera.matrixWorldInverse );
  11337. _frustum.setFromMatrix( _projScreenMatrix );
  11338. // set object matrices & frustum culling
  11339. renderObject( scene, camera, shadowCamera, isPointLight );
  11340. }
  11341. }
  11342. scope.needsUpdate = false;
  11343. _renderer.setRenderTarget( currentRenderTarget );
  11344. };
  11345. function getDepthMaterial( object, material, isPointLight, lightPositionWorld, shadowCameraNear, shadowCameraFar ) {
  11346. var geometry = object.geometry;
  11347. var result = null;
  11348. var materialVariants = _depthMaterials;
  11349. var customMaterial = object.customDepthMaterial;
  11350. if ( isPointLight ) {
  11351. materialVariants = _distanceMaterials;
  11352. customMaterial = object.customDistanceMaterial;
  11353. }
  11354. if ( ! customMaterial ) {
  11355. var useMorphing = false;
  11356. if ( material.morphTargets ) {
  11357. if ( geometry && geometry.isBufferGeometry ) {
  11358. useMorphing = geometry.morphAttributes && geometry.morphAttributes.position && geometry.morphAttributes.position.length > 0;
  11359. } else if ( geometry && geometry.isGeometry ) {
  11360. useMorphing = geometry.morphTargets && geometry.morphTargets.length > 0;
  11361. }
  11362. }
  11363. if ( object.isSkinnedMesh && material.skinning === false ) {
  11364. console.warn( 'THREE.WebGLShadowMap: THREE.SkinnedMesh with material.skinning set to false:', object );
  11365. }
  11366. var useSkinning = object.isSkinnedMesh && material.skinning;
  11367. var variantIndex = 0;
  11368. if ( useMorphing ) variantIndex |= _MorphingFlag;
  11369. if ( useSkinning ) variantIndex |= _SkinningFlag;
  11370. result = materialVariants[ variantIndex ];
  11371. } else {
  11372. result = customMaterial;
  11373. }
  11374. if ( _renderer.localClippingEnabled &&
  11375. material.clipShadows === true &&
  11376. material.clippingPlanes.length !== 0 ) {
  11377. // in this case we need a unique material instance reflecting the
  11378. // appropriate state
  11379. var keyA = result.uuid, keyB = material.uuid;
  11380. var materialsForVariant = _materialCache[ keyA ];
  11381. if ( materialsForVariant === undefined ) {
  11382. materialsForVariant = {};
  11383. _materialCache[ keyA ] = materialsForVariant;
  11384. }
  11385. var cachedMaterial = materialsForVariant[ keyB ];
  11386. if ( cachedMaterial === undefined ) {
  11387. cachedMaterial = result.clone();
  11388. materialsForVariant[ keyB ] = cachedMaterial;
  11389. }
  11390. result = cachedMaterial;
  11391. }
  11392. result.visible = material.visible;
  11393. result.wireframe = material.wireframe;
  11394. result.side = ( material.shadowSide != null ) ? material.shadowSide : shadowSide[ material.side ];
  11395. result.clipShadows = material.clipShadows;
  11396. result.clippingPlanes = material.clippingPlanes;
  11397. result.clipIntersection = material.clipIntersection;
  11398. result.wireframeLinewidth = material.wireframeLinewidth;
  11399. result.linewidth = material.linewidth;
  11400. if ( isPointLight && result.isMeshDistanceMaterial ) {
  11401. result.referencePosition.copy( lightPositionWorld );
  11402. result.nearDistance = shadowCameraNear;
  11403. result.farDistance = shadowCameraFar;
  11404. }
  11405. return result;
  11406. }
  11407. function renderObject( object, camera, shadowCamera, isPointLight ) {
  11408. if ( object.visible === false ) return;
  11409. var visible = object.layers.test( camera.layers );
  11410. if ( visible && ( object.isMesh || object.isLine || object.isPoints ) ) {
  11411. if ( object.castShadow && ( ! object.frustumCulled || _frustum.intersectsObject( object ) ) ) {
  11412. object.modelViewMatrix.multiplyMatrices( shadowCamera.matrixWorldInverse, object.matrixWorld );
  11413. var geometry = _objects.update( object );
  11414. var material = object.material;
  11415. if ( Array.isArray( material ) ) {
  11416. var groups = geometry.groups;
  11417. for ( var k = 0, kl = groups.length; k < kl; k ++ ) {
  11418. var group = groups[ k ];
  11419. var groupMaterial = material[ group.materialIndex ];
  11420. if ( groupMaterial && groupMaterial.visible ) {
  11421. var depthMaterial = getDepthMaterial( object, groupMaterial, isPointLight, _lightPositionWorld, shadowCamera.near, shadowCamera.far );
  11422. _renderer.renderBufferDirect( shadowCamera, null, geometry, depthMaterial, object, group );
  11423. }
  11424. }
  11425. } else if ( material.visible ) {
  11426. var depthMaterial = getDepthMaterial( object, material, isPointLight, _lightPositionWorld, shadowCamera.near, shadowCamera.far );
  11427. _renderer.renderBufferDirect( shadowCamera, null, geometry, depthMaterial, object, null );
  11428. }
  11429. }
  11430. }
  11431. var children = object.children;
  11432. for ( var i = 0, l = children.length; i < l; i ++ ) {
  11433. renderObject( children[ i ], camera, shadowCamera, isPointLight );
  11434. }
  11435. }
  11436. }
  11437. /**
  11438. * @author mrdoob / http://mrdoob.com/
  11439. */
  11440. function WebGLState( gl, extensions, utils, capabilities ) {
  11441. function ColorBuffer() {
  11442. var locked = false;
  11443. var color = new Vector4();
  11444. var currentColorMask = null;
  11445. var currentColorClear = new Vector4( 0, 0, 0, 0 );
  11446. return {
  11447. setMask: function ( colorMask ) {
  11448. if ( currentColorMask !== colorMask && ! locked ) {
  11449. gl.colorMask( colorMask, colorMask, colorMask, colorMask );
  11450. currentColorMask = colorMask;
  11451. }
  11452. },
  11453. setLocked: function ( lock ) {
  11454. locked = lock;
  11455. },
  11456. setClear: function ( r, g, b, a, premultipliedAlpha ) {
  11457. if ( premultipliedAlpha === true ) {
  11458. r *= a; g *= a; b *= a;
  11459. }
  11460. color.set( r, g, b, a );
  11461. if ( currentColorClear.equals( color ) === false ) {
  11462. gl.clearColor( r, g, b, a );
  11463. currentColorClear.copy( color );
  11464. }
  11465. },
  11466. reset: function () {
  11467. locked = false;
  11468. currentColorMask = null;
  11469. currentColorClear.set( - 1, 0, 0, 0 ); // set to invalid state
  11470. }
  11471. };
  11472. }
  11473. function DepthBuffer() {
  11474. var locked = false;
  11475. var currentDepthMask = null;
  11476. var currentDepthFunc = null;
  11477. var currentDepthClear = null;
  11478. return {
  11479. setTest: function ( depthTest ) {
  11480. if ( depthTest ) {
  11481. enable( 2929 );
  11482. } else {
  11483. disable( 2929 );
  11484. }
  11485. },
  11486. setMask: function ( depthMask ) {
  11487. if ( currentDepthMask !== depthMask && ! locked ) {
  11488. gl.depthMask( depthMask );
  11489. currentDepthMask = depthMask;
  11490. }
  11491. },
  11492. setFunc: function ( depthFunc ) {
  11493. if ( currentDepthFunc !== depthFunc ) {
  11494. if ( depthFunc ) {
  11495. switch ( depthFunc ) {
  11496. case NeverDepth:
  11497. gl.depthFunc( 512 );
  11498. break;
  11499. case AlwaysDepth:
  11500. gl.depthFunc( 519 );
  11501. break;
  11502. case LessDepth:
  11503. gl.depthFunc( 513 );
  11504. break;
  11505. case LessEqualDepth:
  11506. gl.depthFunc( 515 );
  11507. break;
  11508. case EqualDepth:
  11509. gl.depthFunc( 514 );
  11510. break;
  11511. case GreaterEqualDepth:
  11512. gl.depthFunc( 518 );
  11513. break;
  11514. case GreaterDepth:
  11515. gl.depthFunc( 516 );
  11516. break;
  11517. case NotEqualDepth:
  11518. gl.depthFunc( 517 );
  11519. break;
  11520. default:
  11521. gl.depthFunc( 515 );
  11522. }
  11523. } else {
  11524. gl.depthFunc( 515 );
  11525. }
  11526. currentDepthFunc = depthFunc;
  11527. }
  11528. },
  11529. setLocked: function ( lock ) {
  11530. locked = lock;
  11531. },
  11532. setClear: function ( depth ) {
  11533. if ( currentDepthClear !== depth ) {
  11534. gl.clearDepth( depth );
  11535. currentDepthClear = depth;
  11536. }
  11537. },
  11538. reset: function () {
  11539. locked = false;
  11540. currentDepthMask = null;
  11541. currentDepthFunc = null;
  11542. currentDepthClear = null;
  11543. }
  11544. };
  11545. }
  11546. function StencilBuffer() {
  11547. var locked = false;
  11548. var currentStencilMask = null;
  11549. var currentStencilFunc = null;
  11550. var currentStencilRef = null;
  11551. var currentStencilFuncMask = null;
  11552. var currentStencilFail = null;
  11553. var currentStencilZFail = null;
  11554. var currentStencilZPass = null;
  11555. var currentStencilClear = null;
  11556. return {
  11557. setTest: function ( stencilTest ) {
  11558. if ( stencilTest ) {
  11559. enable( 2960 );
  11560. } else {
  11561. disable( 2960 );
  11562. }
  11563. },
  11564. setMask: function ( stencilMask ) {
  11565. if ( currentStencilMask !== stencilMask && ! locked ) {
  11566. gl.stencilMask( stencilMask );
  11567. currentStencilMask = stencilMask;
  11568. }
  11569. },
  11570. setFunc: function ( stencilFunc, stencilRef, stencilMask ) {
  11571. if ( currentStencilFunc !== stencilFunc ||
  11572. currentStencilRef !== stencilRef ||
  11573. currentStencilFuncMask !== stencilMask ) {
  11574. gl.stencilFunc( stencilFunc, stencilRef, stencilMask );
  11575. currentStencilFunc = stencilFunc;
  11576. currentStencilRef = stencilRef;
  11577. currentStencilFuncMask = stencilMask;
  11578. }
  11579. },
  11580. setOp: function ( stencilFail, stencilZFail, stencilZPass ) {
  11581. if ( currentStencilFail !== stencilFail ||
  11582. currentStencilZFail !== stencilZFail ||
  11583. currentStencilZPass !== stencilZPass ) {
  11584. gl.stencilOp( stencilFail, stencilZFail, stencilZPass );
  11585. currentStencilFail = stencilFail;
  11586. currentStencilZFail = stencilZFail;
  11587. currentStencilZPass = stencilZPass;
  11588. }
  11589. },
  11590. setLocked: function ( lock ) {
  11591. locked = lock;
  11592. },
  11593. setClear: function ( stencil ) {
  11594. if ( currentStencilClear !== stencil ) {
  11595. gl.clearStencil( stencil );
  11596. currentStencilClear = stencil;
  11597. }
  11598. },
  11599. reset: function () {
  11600. locked = false;
  11601. currentStencilMask = null;
  11602. currentStencilFunc = null;
  11603. currentStencilRef = null;
  11604. currentStencilFuncMask = null;
  11605. currentStencilFail = null;
  11606. currentStencilZFail = null;
  11607. currentStencilZPass = null;
  11608. currentStencilClear = null;
  11609. }
  11610. };
  11611. }
  11612. //
  11613. var colorBuffer = new ColorBuffer();
  11614. var depthBuffer = new DepthBuffer();
  11615. var stencilBuffer = new StencilBuffer();
  11616. var maxVertexAttributes = gl.getParameter( 34921 );
  11617. var newAttributes = new Uint8Array( maxVertexAttributes );
  11618. var enabledAttributes = new Uint8Array( maxVertexAttributes );
  11619. var attributeDivisors = new Uint8Array( maxVertexAttributes );
  11620. var enabledCapabilities = {};
  11621. var compressedTextureFormats = null;
  11622. var currentProgram = null;
  11623. var currentBlendingEnabled = null;
  11624. var currentBlending = null;
  11625. var currentBlendEquation = null;
  11626. var currentBlendSrc = null;
  11627. var currentBlendDst = null;
  11628. var currentBlendEquationAlpha = null;
  11629. var currentBlendSrcAlpha = null;
  11630. var currentBlendDstAlpha = null;
  11631. var currentPremultipledAlpha = false;
  11632. var currentFlipSided = null;
  11633. var currentCullFace = null;
  11634. var currentLineWidth = null;
  11635. var currentPolygonOffsetFactor = null;
  11636. var currentPolygonOffsetUnits = null;
  11637. var maxTextures = gl.getParameter( 35661 );
  11638. var lineWidthAvailable = false;
  11639. var version = 0;
  11640. var glVersion = gl.getParameter( 7938 );
  11641. if ( glVersion.indexOf( 'WebGL' ) !== - 1 ) {
  11642. version = parseFloat( /^WebGL\ ([0-9])/.exec( glVersion )[ 1 ] );
  11643. lineWidthAvailable = ( version >= 1.0 );
  11644. } else if ( glVersion.indexOf( 'OpenGL ES' ) !== - 1 ) {
  11645. version = parseFloat( /^OpenGL\ ES\ ([0-9])/.exec( glVersion )[ 1 ] );
  11646. lineWidthAvailable = ( version >= 2.0 );
  11647. }
  11648. var currentTextureSlot = null;
  11649. var currentBoundTextures = {};
  11650. var currentScissor = new Vector4();
  11651. var currentViewport = new Vector4();
  11652. function createTexture( type, target, count ) {
  11653. var data = new Uint8Array( 4 ); // 4 is required to match default unpack alignment of 4.
  11654. var texture = gl.createTexture();
  11655. gl.bindTexture( type, texture );
  11656. gl.texParameteri( type, 10241, 9728 );
  11657. gl.texParameteri( type, 10240, 9728 );
  11658. for ( var i = 0; i < count; i ++ ) {
  11659. gl.texImage2D( target + i, 0, 6408, 1, 1, 0, 6408, 5121, data );
  11660. }
  11661. return texture;
  11662. }
  11663. var emptyTextures = {};
  11664. emptyTextures[ 3553 ] = createTexture( 3553, 3553, 1 );
  11665. emptyTextures[ 34067 ] = createTexture( 34067, 34069, 6 );
  11666. // init
  11667. colorBuffer.setClear( 0, 0, 0, 1 );
  11668. depthBuffer.setClear( 1 );
  11669. stencilBuffer.setClear( 0 );
  11670. enable( 2929 );
  11671. depthBuffer.setFunc( LessEqualDepth );
  11672. setFlipSided( false );
  11673. setCullFace( CullFaceBack );
  11674. enable( 2884 );
  11675. setBlending( NoBlending );
  11676. //
  11677. function initAttributes() {
  11678. for ( var i = 0, l = newAttributes.length; i < l; i ++ ) {
  11679. newAttributes[ i ] = 0;
  11680. }
  11681. }
  11682. function enableAttribute( attribute ) {
  11683. enableAttributeAndDivisor( attribute, 0 );
  11684. }
  11685. function enableAttributeAndDivisor( attribute, meshPerAttribute ) {
  11686. newAttributes[ attribute ] = 1;
  11687. if ( enabledAttributes[ attribute ] === 0 ) {
  11688. gl.enableVertexAttribArray( attribute );
  11689. enabledAttributes[ attribute ] = 1;
  11690. }
  11691. if ( attributeDivisors[ attribute ] !== meshPerAttribute ) {
  11692. var extension = capabilities.isWebGL2 ? gl : extensions.get( 'ANGLE_instanced_arrays' );
  11693. extension[ capabilities.isWebGL2 ? 'vertexAttribDivisor' : 'vertexAttribDivisorANGLE' ]( attribute, meshPerAttribute );
  11694. attributeDivisors[ attribute ] = meshPerAttribute;
  11695. }
  11696. }
  11697. function disableUnusedAttributes() {
  11698. for ( var i = 0, l = enabledAttributes.length; i !== l; ++ i ) {
  11699. if ( enabledAttributes[ i ] !== newAttributes[ i ] ) {
  11700. gl.disableVertexAttribArray( i );
  11701. enabledAttributes[ i ] = 0;
  11702. }
  11703. }
  11704. }
  11705. function enable( id ) {
  11706. if ( enabledCapabilities[ id ] !== true ) {
  11707. gl.enable( id );
  11708. enabledCapabilities[ id ] = true;
  11709. }
  11710. }
  11711. function disable( id ) {
  11712. if ( enabledCapabilities[ id ] !== false ) {
  11713. gl.disable( id );
  11714. enabledCapabilities[ id ] = false;
  11715. }
  11716. }
  11717. function getCompressedTextureFormats() {
  11718. if ( compressedTextureFormats === null ) {
  11719. compressedTextureFormats = [];
  11720. if ( extensions.get( 'WEBGL_compressed_texture_pvrtc' ) ||
  11721. extensions.get( 'WEBGL_compressed_texture_s3tc' ) ||
  11722. extensions.get( 'WEBGL_compressed_texture_etc1' ) ||
  11723. extensions.get( 'WEBGL_compressed_texture_astc' ) ) {
  11724. var formats = gl.getParameter( 34467 );
  11725. for ( var i = 0; i < formats.length; i ++ ) {
  11726. compressedTextureFormats.push( formats[ i ] );
  11727. }
  11728. }
  11729. }
  11730. return compressedTextureFormats;
  11731. }
  11732. function useProgram( program ) {
  11733. if ( currentProgram !== program ) {
  11734. gl.useProgram( program );
  11735. currentProgram = program;
  11736. return true;
  11737. }
  11738. return false;
  11739. }
  11740. function setBlending( blending, blendEquation, blendSrc, blendDst, blendEquationAlpha, blendSrcAlpha, blendDstAlpha, premultipliedAlpha ) {
  11741. if ( blending === NoBlending ) {
  11742. if ( currentBlendingEnabled ) {
  11743. disable( 3042 );
  11744. currentBlendingEnabled = false;
  11745. }
  11746. return;
  11747. }
  11748. if ( ! currentBlendingEnabled ) {
  11749. enable( 3042 );
  11750. currentBlendingEnabled = true;
  11751. }
  11752. if ( blending !== CustomBlending ) {
  11753. if ( blending !== currentBlending || premultipliedAlpha !== currentPremultipledAlpha ) {
  11754. if ( currentBlendEquation !== AddEquation || currentBlendEquationAlpha !== AddEquation ) {
  11755. gl.blendEquation( 32774 );
  11756. currentBlendEquation = AddEquation;
  11757. currentBlendEquationAlpha = AddEquation;
  11758. }
  11759. if ( premultipliedAlpha ) {
  11760. switch ( blending ) {
  11761. case NormalBlending:
  11762. gl.blendFuncSeparate( 1, 771, 1, 771 );
  11763. break;
  11764. case AdditiveBlending:
  11765. gl.blendFunc( 1, 1 );
  11766. break;
  11767. case SubtractiveBlending:
  11768. gl.blendFuncSeparate( 0, 0, 769, 771 );
  11769. break;
  11770. case MultiplyBlending:
  11771. gl.blendFuncSeparate( 0, 768, 0, 770 );
  11772. break;
  11773. default:
  11774. console.error( 'THREE.WebGLState: Invalid blending: ', blending );
  11775. break;
  11776. }
  11777. } else {
  11778. switch ( blending ) {
  11779. case NormalBlending:
  11780. gl.blendFuncSeparate( 770, 771, 1, 771 );
  11781. break;
  11782. case AdditiveBlending:
  11783. gl.blendFunc( 770, 1 );
  11784. break;
  11785. case SubtractiveBlending:
  11786. gl.blendFunc( 0, 769 );
  11787. break;
  11788. case MultiplyBlending:
  11789. gl.blendFunc( 0, 768 );
  11790. break;
  11791. default:
  11792. console.error( 'THREE.WebGLState: Invalid blending: ', blending );
  11793. break;
  11794. }
  11795. }
  11796. currentBlendSrc = null;
  11797. currentBlendDst = null;
  11798. currentBlendSrcAlpha = null;
  11799. currentBlendDstAlpha = null;
  11800. currentBlending = blending;
  11801. currentPremultipledAlpha = premultipliedAlpha;
  11802. }
  11803. return;
  11804. }
  11805. // custom blending
  11806. blendEquationAlpha = blendEquationAlpha || blendEquation;
  11807. blendSrcAlpha = blendSrcAlpha || blendSrc;
  11808. blendDstAlpha = blendDstAlpha || blendDst;
  11809. if ( blendEquation !== currentBlendEquation || blendEquationAlpha !== currentBlendEquationAlpha ) {
  11810. gl.blendEquationSeparate( utils.convert( blendEquation ), utils.convert( blendEquationAlpha ) );
  11811. currentBlendEquation = blendEquation;
  11812. currentBlendEquationAlpha = blendEquationAlpha;
  11813. }
  11814. if ( blendSrc !== currentBlendSrc || blendDst !== currentBlendDst || blendSrcAlpha !== currentBlendSrcAlpha || blendDstAlpha !== currentBlendDstAlpha ) {
  11815. gl.blendFuncSeparate( utils.convert( blendSrc ), utils.convert( blendDst ), utils.convert( blendSrcAlpha ), utils.convert( blendDstAlpha ) );
  11816. currentBlendSrc = blendSrc;
  11817. currentBlendDst = blendDst;
  11818. currentBlendSrcAlpha = blendSrcAlpha;
  11819. currentBlendDstAlpha = blendDstAlpha;
  11820. }
  11821. currentBlending = blending;
  11822. currentPremultipledAlpha = null;
  11823. }
  11824. function setMaterial( material, frontFaceCW ) {
  11825. material.side === DoubleSide
  11826. ? disable( 2884 )
  11827. : enable( 2884 );
  11828. var flipSided = ( material.side === BackSide );
  11829. if ( frontFaceCW ) flipSided = ! flipSided;
  11830. setFlipSided( flipSided );
  11831. ( material.blending === NormalBlending && material.transparent === false )
  11832. ? setBlending( NoBlending )
  11833. : setBlending( material.blending, material.blendEquation, material.blendSrc, material.blendDst, material.blendEquationAlpha, material.blendSrcAlpha, material.blendDstAlpha, material.premultipliedAlpha );
  11834. depthBuffer.setFunc( material.depthFunc );
  11835. depthBuffer.setTest( material.depthTest );
  11836. depthBuffer.setMask( material.depthWrite );
  11837. colorBuffer.setMask( material.colorWrite );
  11838. setPolygonOffset( material.polygonOffset, material.polygonOffsetFactor, material.polygonOffsetUnits );
  11839. }
  11840. //
  11841. function setFlipSided( flipSided ) {
  11842. if ( currentFlipSided !== flipSided ) {
  11843. if ( flipSided ) {
  11844. gl.frontFace( 2304 );
  11845. } else {
  11846. gl.frontFace( 2305 );
  11847. }
  11848. currentFlipSided = flipSided;
  11849. }
  11850. }
  11851. function setCullFace( cullFace ) {
  11852. if ( cullFace !== CullFaceNone ) {
  11853. enable( 2884 );
  11854. if ( cullFace !== currentCullFace ) {
  11855. if ( cullFace === CullFaceBack ) {
  11856. gl.cullFace( 1029 );
  11857. } else if ( cullFace === CullFaceFront ) {
  11858. gl.cullFace( 1028 );
  11859. } else {
  11860. gl.cullFace( 1032 );
  11861. }
  11862. }
  11863. } else {
  11864. disable( 2884 );
  11865. }
  11866. currentCullFace = cullFace;
  11867. }
  11868. function setLineWidth( width ) {
  11869. if ( width !== currentLineWidth ) {
  11870. if ( lineWidthAvailable ) gl.lineWidth( width );
  11871. currentLineWidth = width;
  11872. }
  11873. }
  11874. function setPolygonOffset( polygonOffset, factor, units ) {
  11875. if ( polygonOffset ) {
  11876. enable( 32823 );
  11877. if ( currentPolygonOffsetFactor !== factor || currentPolygonOffsetUnits !== units ) {
  11878. gl.polygonOffset( factor, units );
  11879. currentPolygonOffsetFactor = factor;
  11880. currentPolygonOffsetUnits = units;
  11881. }
  11882. } else {
  11883. disable( 32823 );
  11884. }
  11885. }
  11886. function setScissorTest( scissorTest ) {
  11887. if ( scissorTest ) {
  11888. enable( 3089 );
  11889. } else {
  11890. disable( 3089 );
  11891. }
  11892. }
  11893. // texture
  11894. function activeTexture( webglSlot ) {
  11895. if ( webglSlot === undefined ) webglSlot = 33984 + maxTextures - 1;
  11896. if ( currentTextureSlot !== webglSlot ) {
  11897. gl.activeTexture( webglSlot );
  11898. currentTextureSlot = webglSlot;
  11899. }
  11900. }
  11901. function bindTexture( webglType, webglTexture ) {
  11902. if ( currentTextureSlot === null ) {
  11903. activeTexture();
  11904. }
  11905. var boundTexture = currentBoundTextures[ currentTextureSlot ];
  11906. if ( boundTexture === undefined ) {
  11907. boundTexture = { type: undefined, texture: undefined };
  11908. currentBoundTextures[ currentTextureSlot ] = boundTexture;
  11909. }
  11910. if ( boundTexture.type !== webglType || boundTexture.texture !== webglTexture ) {
  11911. gl.bindTexture( webglType, webglTexture || emptyTextures[ webglType ] );
  11912. boundTexture.type = webglType;
  11913. boundTexture.texture = webglTexture;
  11914. }
  11915. }
  11916. function compressedTexImage2D() {
  11917. try {
  11918. gl.compressedTexImage2D.apply( gl, arguments );
  11919. } catch ( error ) {
  11920. console.error( 'THREE.WebGLState:', error );
  11921. }
  11922. }
  11923. function texImage2D() {
  11924. try {
  11925. gl.texImage2D.apply( gl, arguments );
  11926. } catch ( error ) {
  11927. console.error( 'THREE.WebGLState:', error );
  11928. }
  11929. }
  11930. function texImage3D() {
  11931. try {
  11932. gl.texImage3D.apply( gl, arguments );
  11933. } catch ( error ) {
  11934. console.error( 'THREE.WebGLState:', error );
  11935. }
  11936. }
  11937. //
  11938. function scissor( scissor ) {
  11939. if ( currentScissor.equals( scissor ) === false ) {
  11940. gl.scissor( scissor.x, scissor.y, scissor.z, scissor.w );
  11941. currentScissor.copy( scissor );
  11942. }
  11943. }
  11944. function viewport( viewport ) {
  11945. if ( currentViewport.equals( viewport ) === false ) {
  11946. gl.viewport( viewport.x, viewport.y, viewport.z, viewport.w );
  11947. currentViewport.copy( viewport );
  11948. }
  11949. }
  11950. //
  11951. function reset() {
  11952. for ( var i = 0; i < enabledAttributes.length; i ++ ) {
  11953. if ( enabledAttributes[ i ] === 1 ) {
  11954. gl.disableVertexAttribArray( i );
  11955. enabledAttributes[ i ] = 0;
  11956. }
  11957. }
  11958. enabledCapabilities = {};
  11959. compressedTextureFormats = null;
  11960. currentTextureSlot = null;
  11961. currentBoundTextures = {};
  11962. currentProgram = null;
  11963. currentBlending = null;
  11964. currentFlipSided = null;
  11965. currentCullFace = null;
  11966. colorBuffer.reset();
  11967. depthBuffer.reset();
  11968. stencilBuffer.reset();
  11969. }
  11970. return {
  11971. buffers: {
  11972. color: colorBuffer,
  11973. depth: depthBuffer,
  11974. stencil: stencilBuffer
  11975. },
  11976. initAttributes: initAttributes,
  11977. enableAttribute: enableAttribute,
  11978. enableAttributeAndDivisor: enableAttributeAndDivisor,
  11979. disableUnusedAttributes: disableUnusedAttributes,
  11980. enable: enable,
  11981. disable: disable,
  11982. getCompressedTextureFormats: getCompressedTextureFormats,
  11983. useProgram: useProgram,
  11984. setBlending: setBlending,
  11985. setMaterial: setMaterial,
  11986. setFlipSided: setFlipSided,
  11987. setCullFace: setCullFace,
  11988. setLineWidth: setLineWidth,
  11989. setPolygonOffset: setPolygonOffset,
  11990. setScissorTest: setScissorTest,
  11991. activeTexture: activeTexture,
  11992. bindTexture: bindTexture,
  11993. compressedTexImage2D: compressedTexImage2D,
  11994. texImage2D: texImage2D,
  11995. texImage3D: texImage3D,
  11996. scissor: scissor,
  11997. viewport: viewport,
  11998. reset: reset
  11999. };
  12000. }
  12001. /**
  12002. * @author mrdoob / http://mrdoob.com/
  12003. */
  12004. function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, info ) {
  12005. var _videoTextures = {};
  12006. var _canvas;
  12007. //
  12008. var useOffscreenCanvas = typeof OffscreenCanvas !== 'undefined';
  12009. function createCanvas( width, height ) {
  12010. // Use OffscreenCanvas when available. Specially needed in web workers
  12011. return useOffscreenCanvas ?
  12012. new OffscreenCanvas( width, height ) :
  12013. document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' );
  12014. }
  12015. function resizeImage( image, needsPowerOfTwo, needsNewCanvas, maxSize ) {
  12016. var scale = 1;
  12017. // handle case if texture exceeds max size
  12018. if ( image.width > maxSize || image.height > maxSize ) {
  12019. scale = maxSize / Math.max( image.width, image.height );
  12020. }
  12021. // only perform resize if necessary
  12022. if ( scale < 1 || needsPowerOfTwo === true ) {
  12023. // only perform resize for certain image types
  12024. if ( image instanceof ImageBitmap || image instanceof HTMLImageElement || image instanceof HTMLCanvasElement ) {
  12025. var floor = needsPowerOfTwo ? _Math.floorPowerOfTwo : Math.floor;
  12026. var width = floor( scale * image.width );
  12027. var height = floor( scale * image.height );
  12028. if ( _canvas === undefined ) _canvas = createCanvas( width, height );
  12029. // cube textures can't reuse the same canvas
  12030. var canvas = needsNewCanvas ? createCanvas( width, height ) : _canvas;
  12031. canvas.width = width;
  12032. canvas.height = height;
  12033. var context = canvas.getContext( '2d' );
  12034. context.drawImage( image, 0, 0, width, height );
  12035. console.warn( 'THREE.WebGLRenderer: Texture has been resized from (' + image.width + 'x' + image.height + ') to (' + width + 'x' + height + ').' );
  12036. return useOffscreenCanvas ? canvas.transferToImageBitmap() : canvas;
  12037. } else {
  12038. if ( 'data' in image ) {
  12039. console.warn( 'THREE.WebGLRenderer: Image in DataTexture is too big (' + image.width + 'x' + image.height + ').' );
  12040. }
  12041. return image;
  12042. }
  12043. }
  12044. return image;
  12045. }
  12046. function isPowerOfTwo( image ) {
  12047. return _Math.isPowerOfTwo( image.width ) && _Math.isPowerOfTwo( image.height );
  12048. }
  12049. function textureNeedsPowerOfTwo( texture ) {
  12050. if ( capabilities.isWebGL2 ) return false;
  12051. return ( texture.wrapS !== ClampToEdgeWrapping || texture.wrapT !== ClampToEdgeWrapping ) ||
  12052. ( texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter );
  12053. }
  12054. function textureNeedsGenerateMipmaps( texture, supportsMips ) {
  12055. return texture.generateMipmaps && supportsMips &&
  12056. texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter;
  12057. }
  12058. function generateMipmap( target, texture, width, height ) {
  12059. _gl.generateMipmap( target );
  12060. var textureProperties = properties.get( texture );
  12061. // Note: Math.log( x ) * Math.LOG2E used instead of Math.log2( x ) which is not supported by IE11
  12062. textureProperties.__maxMipLevel = Math.log( Math.max( width, height ) ) * Math.LOG2E;
  12063. }
  12064. function getInternalFormat( glFormat, glType ) {
  12065. if ( ! capabilities.isWebGL2 ) return glFormat;
  12066. var internalFormat = glFormat;
  12067. if ( glFormat === 6403 ) {
  12068. if ( glType === 5126 ) internalFormat = 33326;
  12069. if ( glType === 5131 ) internalFormat = 33325;
  12070. if ( glType === 5121 ) internalFormat = 33321;
  12071. }
  12072. if ( glFormat === 6407 ) {
  12073. if ( glType === 5126 ) internalFormat = 34837;
  12074. if ( glType === 5131 ) internalFormat = 34843;
  12075. if ( glType === 5121 ) internalFormat = 32849;
  12076. }
  12077. if ( glFormat === 6408 ) {
  12078. if ( glType === 5126 ) internalFormat = 34836;
  12079. if ( glType === 5131 ) internalFormat = 34842;
  12080. if ( glType === 5121 ) internalFormat = 32856;
  12081. }
  12082. if ( internalFormat === 33325 || internalFormat === 33326 ||
  12083. internalFormat === 34842 || internalFormat === 34836 ) {
  12084. extensions.get( 'EXT_color_buffer_float' );
  12085. } else if ( internalFormat === 34843 || internalFormat === 34837 ) {
  12086. console.warn( 'THREE.WebGLRenderer: Floating point textures with RGB format not supported. Please use RGBA instead.' );
  12087. }
  12088. return internalFormat;
  12089. }
  12090. // Fallback filters for non-power-of-2 textures
  12091. function filterFallback( f ) {
  12092. if ( f === NearestFilter || f === NearestMipMapNearestFilter || f === NearestMipMapLinearFilter ) {
  12093. return 9728;
  12094. }
  12095. return 9729;
  12096. }
  12097. //
  12098. function onTextureDispose( event ) {
  12099. var texture = event.target;
  12100. texture.removeEventListener( 'dispose', onTextureDispose );
  12101. deallocateTexture( texture );
  12102. if ( texture.isVideoTexture ) {
  12103. delete _videoTextures[ texture.id ];
  12104. }
  12105. info.memory.textures --;
  12106. }
  12107. function onRenderTargetDispose( event ) {
  12108. var renderTarget = event.target;
  12109. renderTarget.removeEventListener( 'dispose', onRenderTargetDispose );
  12110. deallocateRenderTarget( renderTarget );
  12111. info.memory.textures --;
  12112. }
  12113. //
  12114. function deallocateTexture( texture ) {
  12115. var textureProperties = properties.get( texture );
  12116. if ( textureProperties.__webglInit === undefined ) return;
  12117. _gl.deleteTexture( textureProperties.__webglTexture );
  12118. properties.remove( texture );
  12119. }
  12120. function deallocateRenderTarget( renderTarget ) {
  12121. var renderTargetProperties = properties.get( renderTarget );
  12122. var textureProperties = properties.get( renderTarget.texture );
  12123. if ( ! renderTarget ) return;
  12124. if ( textureProperties.__webglTexture !== undefined ) {
  12125. _gl.deleteTexture( textureProperties.__webglTexture );
  12126. }
  12127. if ( renderTarget.depthTexture ) {
  12128. renderTarget.depthTexture.dispose();
  12129. }
  12130. if ( renderTarget.isWebGLRenderTargetCube ) {
  12131. for ( var i = 0; i < 6; i ++ ) {
  12132. _gl.deleteFramebuffer( renderTargetProperties.__webglFramebuffer[ i ] );
  12133. if ( renderTargetProperties.__webglDepthbuffer ) _gl.deleteRenderbuffer( renderTargetProperties.__webglDepthbuffer[ i ] );
  12134. }
  12135. } else {
  12136. _gl.deleteFramebuffer( renderTargetProperties.__webglFramebuffer );
  12137. if ( renderTargetProperties.__webglDepthbuffer ) _gl.deleteRenderbuffer( renderTargetProperties.__webglDepthbuffer );
  12138. }
  12139. properties.remove( renderTarget.texture );
  12140. properties.remove( renderTarget );
  12141. }
  12142. //
  12143. function setTexture2D( texture, slot ) {
  12144. var textureProperties = properties.get( texture );
  12145. if ( texture.isVideoTexture ) updateVideoTexture( texture );
  12146. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  12147. var image = texture.image;
  12148. if ( image === undefined ) {
  12149. console.warn( 'THREE.WebGLRenderer: Texture marked for update but image is undefined' );
  12150. } else if ( image.complete === false ) {
  12151. console.warn( 'THREE.WebGLRenderer: Texture marked for update but image is incomplete' );
  12152. } else {
  12153. uploadTexture( textureProperties, texture, slot );
  12154. return;
  12155. }
  12156. }
  12157. state.activeTexture( 33984 + slot );
  12158. state.bindTexture( 3553, textureProperties.__webglTexture );
  12159. }
  12160. function setTexture3D( texture, slot ) {
  12161. var textureProperties = properties.get( texture );
  12162. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  12163. uploadTexture( textureProperties, texture, slot );
  12164. return;
  12165. }
  12166. state.activeTexture( 33984 + slot );
  12167. state.bindTexture( 32879, textureProperties.__webglTexture );
  12168. }
  12169. function setTextureCube( texture, slot ) {
  12170. var textureProperties = properties.get( texture );
  12171. if ( texture.image.length === 6 ) {
  12172. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  12173. initTexture( textureProperties, texture );
  12174. state.activeTexture( 33984 + slot );
  12175. state.bindTexture( 34067, textureProperties.__webglTexture );
  12176. _gl.pixelStorei( 37440, texture.flipY );
  12177. var isCompressed = ( texture && texture.isCompressedTexture );
  12178. var isDataTexture = ( texture.image[ 0 ] && texture.image[ 0 ].isDataTexture );
  12179. var cubeImage = [];
  12180. for ( var i = 0; i < 6; i ++ ) {
  12181. if ( ! isCompressed && ! isDataTexture ) {
  12182. cubeImage[ i ] = resizeImage( texture.image[ i ], false, true, capabilities.maxCubemapSize );
  12183. } else {
  12184. cubeImage[ i ] = isDataTexture ? texture.image[ i ].image : texture.image[ i ];
  12185. }
  12186. }
  12187. var image = cubeImage[ 0 ],
  12188. supportsMips = isPowerOfTwo( image ) || capabilities.isWebGL2,
  12189. glFormat = utils.convert( texture.format ),
  12190. glType = utils.convert( texture.type ),
  12191. glInternalFormat = getInternalFormat( glFormat, glType );
  12192. setTextureParameters( 34067, texture, supportsMips );
  12193. for ( var i = 0; i < 6; i ++ ) {
  12194. if ( ! isCompressed ) {
  12195. if ( isDataTexture ) {
  12196. state.texImage2D( 34069 + i, 0, glInternalFormat, cubeImage[ i ].width, cubeImage[ i ].height, 0, glFormat, glType, cubeImage[ i ].data );
  12197. } else {
  12198. state.texImage2D( 34069 + i, 0, glInternalFormat, glFormat, glType, cubeImage[ i ] );
  12199. }
  12200. } else {
  12201. var mipmap, mipmaps = cubeImage[ i ].mipmaps;
  12202. for ( var j = 0, jl = mipmaps.length; j < jl; j ++ ) {
  12203. mipmap = mipmaps[ j ];
  12204. if ( texture.format !== RGBAFormat && texture.format !== RGBFormat ) {
  12205. if ( state.getCompressedTextureFormats().indexOf( glFormat ) > - 1 ) {
  12206. state.compressedTexImage2D( 34069 + i, j, glInternalFormat, mipmap.width, mipmap.height, 0, mipmap.data );
  12207. } else {
  12208. console.warn( 'THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .setTextureCube()' );
  12209. }
  12210. } else {
  12211. state.texImage2D( 34069 + i, j, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  12212. }
  12213. }
  12214. }
  12215. }
  12216. if ( ! isCompressed ) {
  12217. textureProperties.__maxMipLevel = 0;
  12218. } else {
  12219. textureProperties.__maxMipLevel = mipmaps.length - 1;
  12220. }
  12221. if ( textureNeedsGenerateMipmaps( texture, supportsMips ) ) {
  12222. // We assume images for cube map have the same size.
  12223. generateMipmap( 34067, texture, image.width, image.height );
  12224. }
  12225. textureProperties.__version = texture.version;
  12226. if ( texture.onUpdate ) texture.onUpdate( texture );
  12227. } else {
  12228. state.activeTexture( 33984 + slot );
  12229. state.bindTexture( 34067, textureProperties.__webglTexture );
  12230. }
  12231. }
  12232. }
  12233. function setTextureCubeDynamic( texture, slot ) {
  12234. state.activeTexture( 33984 + slot );
  12235. state.bindTexture( 34067, properties.get( texture ).__webglTexture );
  12236. }
  12237. function setTextureParameters( textureType, texture, supportsMips ) {
  12238. var extension;
  12239. if ( supportsMips ) {
  12240. _gl.texParameteri( textureType, 10242, utils.convert( texture.wrapS ) );
  12241. _gl.texParameteri( textureType, 10243, utils.convert( texture.wrapT ) );
  12242. if ( textureType === 32879 ) {
  12243. _gl.texParameteri( textureType, 32882, utils.convert( texture.wrapR ) );
  12244. }
  12245. _gl.texParameteri( textureType, 10240, utils.convert( texture.magFilter ) );
  12246. _gl.texParameteri( textureType, 10241, utils.convert( texture.minFilter ) );
  12247. } else {
  12248. _gl.texParameteri( textureType, 10242, 33071 );
  12249. _gl.texParameteri( textureType, 10243, 33071 );
  12250. if ( textureType === 32879 ) {
  12251. _gl.texParameteri( textureType, 32882, 33071 );
  12252. }
  12253. if ( texture.wrapS !== ClampToEdgeWrapping || texture.wrapT !== ClampToEdgeWrapping ) {
  12254. console.warn( 'THREE.WebGLRenderer: Texture is not power of two. Texture.wrapS and Texture.wrapT should be set to THREE.ClampToEdgeWrapping.' );
  12255. }
  12256. _gl.texParameteri( textureType, 10240, filterFallback( texture.magFilter ) );
  12257. _gl.texParameteri( textureType, 10241, filterFallback( texture.minFilter ) );
  12258. if ( texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter ) {
  12259. console.warn( 'THREE.WebGLRenderer: Texture is not power of two. Texture.minFilter should be set to THREE.NearestFilter or THREE.LinearFilter.' );
  12260. }
  12261. }
  12262. extension = extensions.get( 'EXT_texture_filter_anisotropic' );
  12263. if ( extension ) {
  12264. if ( texture.type === FloatType && extensions.get( 'OES_texture_float_linear' ) === null ) return;
  12265. if ( texture.type === HalfFloatType && ( capabilities.isWebGL2 || extensions.get( 'OES_texture_half_float_linear' ) ) === null ) return;
  12266. if ( texture.anisotropy > 1 || properties.get( texture ).__currentAnisotropy ) {
  12267. _gl.texParameterf( textureType, extension.TEXTURE_MAX_ANISOTROPY_EXT, Math.min( texture.anisotropy, capabilities.getMaxAnisotropy() ) );
  12268. properties.get( texture ).__currentAnisotropy = texture.anisotropy;
  12269. }
  12270. }
  12271. }
  12272. function initTexture( textureProperties, texture ) {
  12273. if ( textureProperties.__webglInit === undefined ) {
  12274. textureProperties.__webglInit = true;
  12275. texture.addEventListener( 'dispose', onTextureDispose );
  12276. textureProperties.__webglTexture = _gl.createTexture();
  12277. info.memory.textures ++;
  12278. }
  12279. }
  12280. function uploadTexture( textureProperties, texture, slot ) {
  12281. var textureType = ( texture.isDataTexture3D ) ? 32879 : 3553;
  12282. initTexture( textureProperties, texture );
  12283. state.activeTexture( 33984 + slot );
  12284. state.bindTexture( textureType, textureProperties.__webglTexture );
  12285. _gl.pixelStorei( 37440, texture.flipY );
  12286. _gl.pixelStorei( 37441, texture.premultiplyAlpha );
  12287. _gl.pixelStorei( 3317, texture.unpackAlignment );
  12288. var needsPowerOfTwo = textureNeedsPowerOfTwo( texture ) && isPowerOfTwo( texture.image ) === false;
  12289. var image = resizeImage( texture.image, needsPowerOfTwo, false, capabilities.maxTextureSize );
  12290. var supportsMips = isPowerOfTwo( image ) || capabilities.isWebGL2,
  12291. glFormat = utils.convert( texture.format ),
  12292. glType = utils.convert( texture.type ),
  12293. glInternalFormat = getInternalFormat( glFormat, glType );
  12294. setTextureParameters( textureType, texture, supportsMips );
  12295. var mipmap, mipmaps = texture.mipmaps;
  12296. if ( texture.isDepthTexture ) {
  12297. // populate depth texture with dummy data
  12298. glInternalFormat = 6402;
  12299. if ( texture.type === FloatType ) {
  12300. if ( ! capabilities.isWebGL2 ) throw new Error( 'Float Depth Texture only supported in WebGL2.0' );
  12301. glInternalFormat = 36012;
  12302. } else if ( capabilities.isWebGL2 ) {
  12303. // WebGL 2.0 requires signed internalformat for glTexImage2D
  12304. glInternalFormat = 33189;
  12305. }
  12306. if ( texture.format === DepthFormat && glInternalFormat === 6402 ) {
  12307. // The error INVALID_OPERATION is generated by texImage2D if format and internalformat are
  12308. // DEPTH_COMPONENT and type is not UNSIGNED_SHORT or UNSIGNED_INT
  12309. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  12310. if ( texture.type !== UnsignedShortType && texture.type !== UnsignedIntType ) {
  12311. console.warn( 'THREE.WebGLRenderer: Use UnsignedShortType or UnsignedIntType for DepthFormat DepthTexture.' );
  12312. texture.type = UnsignedShortType;
  12313. glType = utils.convert( texture.type );
  12314. }
  12315. }
  12316. // Depth stencil textures need the DEPTH_STENCIL internal format
  12317. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  12318. if ( texture.format === DepthStencilFormat ) {
  12319. glInternalFormat = 34041;
  12320. // The error INVALID_OPERATION is generated by texImage2D if format and internalformat are
  12321. // DEPTH_STENCIL and type is not UNSIGNED_INT_24_8_WEBGL.
  12322. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  12323. if ( texture.type !== UnsignedInt248Type ) {
  12324. console.warn( 'THREE.WebGLRenderer: Use UnsignedInt248Type for DepthStencilFormat DepthTexture.' );
  12325. texture.type = UnsignedInt248Type;
  12326. glType = utils.convert( texture.type );
  12327. }
  12328. }
  12329. state.texImage2D( 3553, 0, glInternalFormat, image.width, image.height, 0, glFormat, glType, null );
  12330. } else if ( texture.isDataTexture ) {
  12331. // use manually created mipmaps if available
  12332. // if there are no manual mipmaps
  12333. // set 0 level mipmap and then use GL to generate other mipmap levels
  12334. if ( mipmaps.length > 0 && supportsMips ) {
  12335. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  12336. mipmap = mipmaps[ i ];
  12337. state.texImage2D( 3553, i, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  12338. }
  12339. texture.generateMipmaps = false;
  12340. textureProperties.__maxMipLevel = mipmaps.length - 1;
  12341. } else {
  12342. state.texImage2D( 3553, 0, glInternalFormat, image.width, image.height, 0, glFormat, glType, image.data );
  12343. textureProperties.__maxMipLevel = 0;
  12344. }
  12345. } else if ( texture.isCompressedTexture ) {
  12346. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  12347. mipmap = mipmaps[ i ];
  12348. if ( texture.format !== RGBAFormat && texture.format !== RGBFormat ) {
  12349. if ( state.getCompressedTextureFormats().indexOf( glFormat ) > - 1 ) {
  12350. state.compressedTexImage2D( 3553, i, glInternalFormat, mipmap.width, mipmap.height, 0, mipmap.data );
  12351. } else {
  12352. console.warn( 'THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()' );
  12353. }
  12354. } else {
  12355. state.texImage2D( 3553, i, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  12356. }
  12357. }
  12358. textureProperties.__maxMipLevel = mipmaps.length - 1;
  12359. } else if ( texture.isDataTexture3D ) {
  12360. state.texImage3D( 32879, 0, glInternalFormat, image.width, image.height, image.depth, 0, glFormat, glType, image.data );
  12361. textureProperties.__maxMipLevel = 0;
  12362. } else {
  12363. // regular Texture (image, video, canvas)
  12364. // use manually created mipmaps if available
  12365. // if there are no manual mipmaps
  12366. // set 0 level mipmap and then use GL to generate other mipmap levels
  12367. if ( mipmaps.length > 0 && supportsMips ) {
  12368. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  12369. mipmap = mipmaps[ i ];
  12370. state.texImage2D( 3553, i, glInternalFormat, glFormat, glType, mipmap );
  12371. }
  12372. texture.generateMipmaps = false;
  12373. textureProperties.__maxMipLevel = mipmaps.length - 1;
  12374. } else {
  12375. state.texImage2D( 3553, 0, glInternalFormat, glFormat, glType, image );
  12376. textureProperties.__maxMipLevel = 0;
  12377. }
  12378. }
  12379. if ( textureNeedsGenerateMipmaps( texture, supportsMips ) ) {
  12380. generateMipmap( 3553, texture, image.width, image.height );
  12381. }
  12382. textureProperties.__version = texture.version;
  12383. if ( texture.onUpdate ) texture.onUpdate( texture );
  12384. }
  12385. // Render targets
  12386. // Setup storage for target texture and bind it to correct framebuffer
  12387. function setupFrameBufferTexture( framebuffer, renderTarget, attachment, textureTarget ) {
  12388. var glFormat = utils.convert( renderTarget.texture.format );
  12389. var glType = utils.convert( renderTarget.texture.type );
  12390. var glInternalFormat = getInternalFormat( glFormat, glType );
  12391. state.texImage2D( textureTarget, 0, glInternalFormat, renderTarget.width, renderTarget.height, 0, glFormat, glType, null );
  12392. _gl.bindFramebuffer( 36160, framebuffer );
  12393. _gl.framebufferTexture2D( 36160, attachment, textureTarget, properties.get( renderTarget.texture ).__webglTexture, 0 );
  12394. _gl.bindFramebuffer( 36160, null );
  12395. }
  12396. // Setup storage for internal depth/stencil buffers and bind to correct framebuffer
  12397. function setupRenderBufferStorage( renderbuffer, renderTarget, isMultisample ) {
  12398. _gl.bindRenderbuffer( 36161, renderbuffer );
  12399. if ( renderTarget.depthBuffer && ! renderTarget.stencilBuffer ) {
  12400. if ( isMultisample ) {
  12401. var samples = getRenderTargetSamples( renderTarget );
  12402. _gl.renderbufferStorageMultisample( 36161, samples, 33189, renderTarget.width, renderTarget.height );
  12403. } else {
  12404. _gl.renderbufferStorage( 36161, 33189, renderTarget.width, renderTarget.height );
  12405. }
  12406. _gl.framebufferRenderbuffer( 36160, 36096, 36161, renderbuffer );
  12407. } else if ( renderTarget.depthBuffer && renderTarget.stencilBuffer ) {
  12408. if ( isMultisample ) {
  12409. var samples = getRenderTargetSamples( renderTarget );
  12410. _gl.renderbufferStorageMultisample( 36161, samples, 34041, renderTarget.width, renderTarget.height );
  12411. } else {
  12412. _gl.renderbufferStorage( 36161, 34041, renderTarget.width, renderTarget.height );
  12413. }
  12414. _gl.framebufferRenderbuffer( 36160, 33306, 36161, renderbuffer );
  12415. } else {
  12416. var glFormat = utils.convert( renderTarget.texture.format );
  12417. var glType = utils.convert( renderTarget.texture.type );
  12418. var glInternalFormat = getInternalFormat( glFormat, glType );
  12419. if ( isMultisample ) {
  12420. var samples = getRenderTargetSamples( renderTarget );
  12421. _gl.renderbufferStorageMultisample( 36161, samples, glInternalFormat, renderTarget.width, renderTarget.height );
  12422. } else {
  12423. _gl.renderbufferStorage( 36161, glInternalFormat, renderTarget.width, renderTarget.height );
  12424. }
  12425. }
  12426. _gl.bindRenderbuffer( 36161, null );
  12427. }
  12428. // Setup resources for a Depth Texture for a FBO (needs an extension)
  12429. function setupDepthTexture( framebuffer, renderTarget ) {
  12430. var isCube = ( renderTarget && renderTarget.isWebGLRenderTargetCube );
  12431. if ( isCube ) throw new Error( 'Depth Texture with cube render targets is not supported' );
  12432. _gl.bindFramebuffer( 36160, framebuffer );
  12433. if ( ! ( renderTarget.depthTexture && renderTarget.depthTexture.isDepthTexture ) ) {
  12434. throw new Error( 'renderTarget.depthTexture must be an instance of THREE.DepthTexture' );
  12435. }
  12436. // upload an empty depth texture with framebuffer size
  12437. if ( ! properties.get( renderTarget.depthTexture ).__webglTexture ||
  12438. renderTarget.depthTexture.image.width !== renderTarget.width ||
  12439. renderTarget.depthTexture.image.height !== renderTarget.height ) {
  12440. renderTarget.depthTexture.image.width = renderTarget.width;
  12441. renderTarget.depthTexture.image.height = renderTarget.height;
  12442. renderTarget.depthTexture.needsUpdate = true;
  12443. }
  12444. setTexture2D( renderTarget.depthTexture, 0 );
  12445. var webglDepthTexture = properties.get( renderTarget.depthTexture ).__webglTexture;
  12446. if ( renderTarget.depthTexture.format === DepthFormat ) {
  12447. _gl.framebufferTexture2D( 36160, 36096, 3553, webglDepthTexture, 0 );
  12448. } else if ( renderTarget.depthTexture.format === DepthStencilFormat ) {
  12449. _gl.framebufferTexture2D( 36160, 33306, 3553, webglDepthTexture, 0 );
  12450. } else {
  12451. throw new Error( 'Unknown depthTexture format' );
  12452. }
  12453. }
  12454. // Setup GL resources for a non-texture depth buffer
  12455. function setupDepthRenderbuffer( renderTarget ) {
  12456. var renderTargetProperties = properties.get( renderTarget );
  12457. var isCube = ( renderTarget.isWebGLRenderTargetCube === true );
  12458. if ( renderTarget.depthTexture ) {
  12459. if ( isCube ) throw new Error( 'target.depthTexture not supported in Cube render targets' );
  12460. setupDepthTexture( renderTargetProperties.__webglFramebuffer, renderTarget );
  12461. } else {
  12462. if ( isCube ) {
  12463. renderTargetProperties.__webglDepthbuffer = [];
  12464. for ( var i = 0; i < 6; i ++ ) {
  12465. _gl.bindFramebuffer( 36160, renderTargetProperties.__webglFramebuffer[ i ] );
  12466. renderTargetProperties.__webglDepthbuffer[ i ] = _gl.createRenderbuffer();
  12467. setupRenderBufferStorage( renderTargetProperties.__webglDepthbuffer[ i ], renderTarget );
  12468. }
  12469. } else {
  12470. _gl.bindFramebuffer( 36160, renderTargetProperties.__webglFramebuffer );
  12471. renderTargetProperties.__webglDepthbuffer = _gl.createRenderbuffer();
  12472. setupRenderBufferStorage( renderTargetProperties.__webglDepthbuffer, renderTarget );
  12473. }
  12474. }
  12475. _gl.bindFramebuffer( 36160, null );
  12476. }
  12477. // Set up GL resources for the render target
  12478. function setupRenderTarget( renderTarget ) {
  12479. var renderTargetProperties = properties.get( renderTarget );
  12480. var textureProperties = properties.get( renderTarget.texture );
  12481. renderTarget.addEventListener( 'dispose', onRenderTargetDispose );
  12482. textureProperties.__webglTexture = _gl.createTexture();
  12483. info.memory.textures ++;
  12484. var isCube = ( renderTarget.isWebGLRenderTargetCube === true );
  12485. var isMultisample = ( renderTarget.isWebGLMultisampleRenderTarget === true );
  12486. var supportsMips = isPowerOfTwo( renderTarget ) || capabilities.isWebGL2;
  12487. // Setup framebuffer
  12488. if ( isCube ) {
  12489. renderTargetProperties.__webglFramebuffer = [];
  12490. for ( var i = 0; i < 6; i ++ ) {
  12491. renderTargetProperties.__webglFramebuffer[ i ] = _gl.createFramebuffer();
  12492. }
  12493. } else {
  12494. renderTargetProperties.__webglFramebuffer = _gl.createFramebuffer();
  12495. if ( isMultisample ) {
  12496. if ( capabilities.isWebGL2 ) {
  12497. renderTargetProperties.__webglMultisampledFramebuffer = _gl.createFramebuffer();
  12498. renderTargetProperties.__webglColorRenderbuffer = _gl.createRenderbuffer();
  12499. _gl.bindRenderbuffer( 36161, renderTargetProperties.__webglColorRenderbuffer );
  12500. var glFormat = utils.convert( renderTarget.texture.format );
  12501. var glType = utils.convert( renderTarget.texture.type );
  12502. var glInternalFormat = getInternalFormat( glFormat, glType );
  12503. var samples = getRenderTargetSamples( renderTarget );
  12504. _gl.renderbufferStorageMultisample( 36161, samples, glInternalFormat, renderTarget.width, renderTarget.height );
  12505. _gl.bindFramebuffer( 36160, renderTargetProperties.__webglMultisampledFramebuffer );
  12506. _gl.framebufferRenderbuffer( 36160, 36064, 36161, renderTargetProperties.__webglColorRenderbuffer );
  12507. _gl.bindRenderbuffer( 36161, null );
  12508. if ( renderTarget.depthBuffer ) {
  12509. renderTargetProperties.__webglDepthRenderbuffer = _gl.createRenderbuffer();
  12510. setupRenderBufferStorage( renderTargetProperties.__webglDepthRenderbuffer, renderTarget, true );
  12511. }
  12512. _gl.bindFramebuffer( 36160, null );
  12513. } else {
  12514. console.warn( 'THREE.WebGLRenderer: WebGLMultisampleRenderTarget can only be used with WebGL2.' );
  12515. }
  12516. }
  12517. }
  12518. // Setup color buffer
  12519. if ( isCube ) {
  12520. state.bindTexture( 34067, textureProperties.__webglTexture );
  12521. setTextureParameters( 34067, renderTarget.texture, supportsMips );
  12522. for ( var i = 0; i < 6; i ++ ) {
  12523. setupFrameBufferTexture( renderTargetProperties.__webglFramebuffer[ i ], renderTarget, 36064, 34069 + i );
  12524. }
  12525. if ( textureNeedsGenerateMipmaps( renderTarget.texture, supportsMips ) ) {
  12526. generateMipmap( 34067, renderTarget.texture, renderTarget.width, renderTarget.height );
  12527. }
  12528. state.bindTexture( 34067, null );
  12529. } else {
  12530. state.bindTexture( 3553, textureProperties.__webglTexture );
  12531. setTextureParameters( 3553, renderTarget.texture, supportsMips );
  12532. setupFrameBufferTexture( renderTargetProperties.__webglFramebuffer, renderTarget, 36064, 3553 );
  12533. if ( textureNeedsGenerateMipmaps( renderTarget.texture, supportsMips ) ) {
  12534. generateMipmap( 3553, renderTarget.texture, renderTarget.width, renderTarget.height );
  12535. }
  12536. state.bindTexture( 3553, null );
  12537. }
  12538. // Setup depth and stencil buffers
  12539. if ( renderTarget.depthBuffer ) {
  12540. setupDepthRenderbuffer( renderTarget );
  12541. }
  12542. }
  12543. function updateRenderTargetMipmap( renderTarget ) {
  12544. var texture = renderTarget.texture;
  12545. var supportsMips = isPowerOfTwo( renderTarget ) || capabilities.isWebGL2;
  12546. if ( textureNeedsGenerateMipmaps( texture, supportsMips ) ) {
  12547. var target = renderTarget.isWebGLRenderTargetCube ? 34067 : 3553;
  12548. var webglTexture = properties.get( texture ).__webglTexture;
  12549. state.bindTexture( target, webglTexture );
  12550. generateMipmap( target, texture, renderTarget.width, renderTarget.height );
  12551. state.bindTexture( target, null );
  12552. }
  12553. }
  12554. function updateMultisampleRenderTarget( renderTarget ) {
  12555. if ( renderTarget.isWebGLMultisampleRenderTarget ) {
  12556. if ( capabilities.isWebGL2 ) {
  12557. var renderTargetProperties = properties.get( renderTarget );
  12558. _gl.bindFramebuffer( 36008, renderTargetProperties.__webglMultisampledFramebuffer );
  12559. _gl.bindFramebuffer( 36009, renderTargetProperties.__webglFramebuffer );
  12560. var width = renderTarget.width;
  12561. var height = renderTarget.height;
  12562. var mask = 16384;
  12563. if ( renderTarget.depthBuffer ) mask |= 256;
  12564. if ( renderTarget.stencilBuffer ) mask |= 1024;
  12565. _gl.blitFramebuffer( 0, 0, width, height, 0, 0, width, height, mask, 9728 );
  12566. } else {
  12567. console.warn( 'THREE.WebGLRenderer: WebGLMultisampleRenderTarget can only be used with WebGL2.' );
  12568. }
  12569. }
  12570. }
  12571. function getRenderTargetSamples( renderTarget ) {
  12572. return ( capabilities.isWebGL2 && renderTarget.isWebGLMultisampleRenderTarget ) ?
  12573. Math.min( capabilities.maxSamples, renderTarget.samples ) : 0;
  12574. }
  12575. function updateVideoTexture( texture ) {
  12576. var id = texture.id;
  12577. var frame = info.render.frame;
  12578. // Check the last frame we updated the VideoTexture
  12579. if ( _videoTextures[ id ] !== frame ) {
  12580. _videoTextures[ id ] = frame;
  12581. texture.update();
  12582. }
  12583. }
  12584. this.setTexture2D = setTexture2D;
  12585. this.setTexture3D = setTexture3D;
  12586. this.setTextureCube = setTextureCube;
  12587. this.setTextureCubeDynamic = setTextureCubeDynamic;
  12588. this.setupRenderTarget = setupRenderTarget;
  12589. this.updateRenderTargetMipmap = updateRenderTargetMipmap;
  12590. this.updateMultisampleRenderTarget = updateMultisampleRenderTarget;
  12591. }
  12592. /**
  12593. * @author thespite / http://www.twitter.com/thespite
  12594. */
  12595. function WebGLUtils( gl, extensions, capabilities ) {
  12596. function convert( p ) {
  12597. var extension;
  12598. if ( p === RepeatWrapping ) return 10497;
  12599. if ( p === ClampToEdgeWrapping ) return 33071;
  12600. if ( p === MirroredRepeatWrapping ) return 33648;
  12601. if ( p === NearestFilter ) return 9728;
  12602. if ( p === NearestMipMapNearestFilter ) return 9984;
  12603. if ( p === NearestMipMapLinearFilter ) return 9986;
  12604. if ( p === LinearFilter ) return 9729;
  12605. if ( p === LinearMipMapNearestFilter ) return 9985;
  12606. if ( p === LinearMipMapLinearFilter ) return 9987;
  12607. if ( p === UnsignedByteType ) return 5121;
  12608. if ( p === UnsignedShort4444Type ) return 32819;
  12609. if ( p === UnsignedShort5551Type ) return 32820;
  12610. if ( p === UnsignedShort565Type ) return 33635;
  12611. if ( p === ByteType ) return 5120;
  12612. if ( p === ShortType ) return 5122;
  12613. if ( p === UnsignedShortType ) return 5123;
  12614. if ( p === IntType ) return 5124;
  12615. if ( p === UnsignedIntType ) return 5125;
  12616. if ( p === FloatType ) return 5126;
  12617. if ( p === HalfFloatType ) {
  12618. if ( capabilities.isWebGL2 ) return 5131;
  12619. extension = extensions.get( 'OES_texture_half_float' );
  12620. if ( extension !== null ) return extension.HALF_FLOAT_OES;
  12621. }
  12622. if ( p === AlphaFormat ) return 6406;
  12623. if ( p === RGBFormat ) return 6407;
  12624. if ( p === RGBAFormat ) return 6408;
  12625. if ( p === LuminanceFormat ) return 6409;
  12626. if ( p === LuminanceAlphaFormat ) return 6410;
  12627. if ( p === DepthFormat ) return 6402;
  12628. if ( p === DepthStencilFormat ) return 34041;
  12629. if ( p === RedFormat ) return 6403;
  12630. if ( p === AddEquation ) return 32774;
  12631. if ( p === SubtractEquation ) return 32778;
  12632. if ( p === ReverseSubtractEquation ) return 32779;
  12633. if ( p === ZeroFactor ) return 0;
  12634. if ( p === OneFactor ) return 1;
  12635. if ( p === SrcColorFactor ) return 768;
  12636. if ( p === OneMinusSrcColorFactor ) return 769;
  12637. if ( p === SrcAlphaFactor ) return 770;
  12638. if ( p === OneMinusSrcAlphaFactor ) return 771;
  12639. if ( p === DstAlphaFactor ) return 772;
  12640. if ( p === OneMinusDstAlphaFactor ) return 773;
  12641. if ( p === DstColorFactor ) return 774;
  12642. if ( p === OneMinusDstColorFactor ) return 775;
  12643. if ( p === SrcAlphaSaturateFactor ) return 776;
  12644. if ( p === RGB_S3TC_DXT1_Format || p === RGBA_S3TC_DXT1_Format ||
  12645. p === RGBA_S3TC_DXT3_Format || p === RGBA_S3TC_DXT5_Format ) {
  12646. extension = extensions.get( 'WEBGL_compressed_texture_s3tc' );
  12647. if ( extension !== null ) {
  12648. if ( p === RGB_S3TC_DXT1_Format ) return extension.COMPRESSED_RGB_S3TC_DXT1_EXT;
  12649. if ( p === RGBA_S3TC_DXT1_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT1_EXT;
  12650. if ( p === RGBA_S3TC_DXT3_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT3_EXT;
  12651. if ( p === RGBA_S3TC_DXT5_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT5_EXT;
  12652. }
  12653. }
  12654. if ( p === RGB_PVRTC_4BPPV1_Format || p === RGB_PVRTC_2BPPV1_Format ||
  12655. p === RGBA_PVRTC_4BPPV1_Format || p === RGBA_PVRTC_2BPPV1_Format ) {
  12656. extension = extensions.get( 'WEBGL_compressed_texture_pvrtc' );
  12657. if ( extension !== null ) {
  12658. if ( p === RGB_PVRTC_4BPPV1_Format ) return extension.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;
  12659. if ( p === RGB_PVRTC_2BPPV1_Format ) return extension.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;
  12660. if ( p === RGBA_PVRTC_4BPPV1_Format ) return extension.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;
  12661. if ( p === RGBA_PVRTC_2BPPV1_Format ) return extension.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG;
  12662. }
  12663. }
  12664. if ( p === RGB_ETC1_Format ) {
  12665. extension = extensions.get( 'WEBGL_compressed_texture_etc1' );
  12666. if ( extension !== null ) return extension.COMPRESSED_RGB_ETC1_WEBGL;
  12667. }
  12668. if ( p === RGBA_ASTC_4x4_Format || p === RGBA_ASTC_5x4_Format || p === RGBA_ASTC_5x5_Format ||
  12669. p === RGBA_ASTC_6x5_Format || p === RGBA_ASTC_6x6_Format || p === RGBA_ASTC_8x5_Format ||
  12670. p === RGBA_ASTC_8x6_Format || p === RGBA_ASTC_8x8_Format || p === RGBA_ASTC_10x5_Format ||
  12671. p === RGBA_ASTC_10x6_Format || p === RGBA_ASTC_10x8_Format || p === RGBA_ASTC_10x10_Format ||
  12672. p === RGBA_ASTC_12x10_Format || p === RGBA_ASTC_12x12_Format ) {
  12673. extension = extensions.get( 'WEBGL_compressed_texture_astc' );
  12674. if ( extension !== null ) {
  12675. return p;
  12676. }
  12677. }
  12678. if ( p === MinEquation || p === MaxEquation ) {
  12679. if ( capabilities.isWebGL2 ) {
  12680. if ( p === MinEquation ) return 32775;
  12681. if ( p === MaxEquation ) return 32776;
  12682. }
  12683. extension = extensions.get( 'EXT_blend_minmax' );
  12684. if ( extension !== null ) {
  12685. if ( p === MinEquation ) return extension.MIN_EXT;
  12686. if ( p === MaxEquation ) return extension.MAX_EXT;
  12687. }
  12688. }
  12689. if ( p === UnsignedInt248Type ) {
  12690. if ( capabilities.isWebGL2 ) return 34042;
  12691. extension = extensions.get( 'WEBGL_depth_texture' );
  12692. if ( extension !== null ) return extension.UNSIGNED_INT_24_8_WEBGL;
  12693. }
  12694. return 0;
  12695. }
  12696. return { convert: convert };
  12697. }
  12698. /**
  12699. * @author mrdoob / http://mrdoob.com/
  12700. */
  12701. function Group() {
  12702. Object3D.call( this );
  12703. this.type = 'Group';
  12704. }
  12705. Group.prototype = Object.assign( Object.create( Object3D.prototype ), {
  12706. constructor: Group,
  12707. isGroup: true
  12708. } );
  12709. /**
  12710. * @author mrdoob / http://mrdoob.com/
  12711. * @author mikael emtinger / http://gomo.se/
  12712. * @author WestLangley / http://github.com/WestLangley
  12713. */
  12714. function Camera() {
  12715. Object3D.call( this );
  12716. this.type = 'Camera';
  12717. this.matrixWorldInverse = new Matrix4();
  12718. this.projectionMatrix = new Matrix4();
  12719. this.projectionMatrixInverse = new Matrix4();
  12720. }
  12721. Camera.prototype = Object.assign( Object.create( Object3D.prototype ), {
  12722. constructor: Camera,
  12723. isCamera: true,
  12724. copy: function ( source, recursive ) {
  12725. Object3D.prototype.copy.call( this, source, recursive );
  12726. this.matrixWorldInverse.copy( source.matrixWorldInverse );
  12727. this.projectionMatrix.copy( source.projectionMatrix );
  12728. this.projectionMatrixInverse.copy( source.projectionMatrixInverse );
  12729. return this;
  12730. },
  12731. getWorldDirection: function ( target ) {
  12732. if ( target === undefined ) {
  12733. console.warn( 'THREE.Camera: .getWorldDirection() target is now required' );
  12734. target = new Vector3();
  12735. }
  12736. this.updateMatrixWorld( true );
  12737. var e = this.matrixWorld.elements;
  12738. return target.set( - e[ 8 ], - e[ 9 ], - e[ 10 ] ).normalize();
  12739. },
  12740. updateMatrixWorld: function ( force ) {
  12741. Object3D.prototype.updateMatrixWorld.call( this, force );
  12742. this.matrixWorldInverse.getInverse( this.matrixWorld );
  12743. },
  12744. clone: function () {
  12745. return new this.constructor().copy( this );
  12746. }
  12747. } );
  12748. /**
  12749. * @author mrdoob / http://mrdoob.com/
  12750. * @author greggman / http://games.greggman.com/
  12751. * @author zz85 / http://www.lab4games.net/zz85/blog
  12752. * @author tschw
  12753. */
  12754. function PerspectiveCamera( fov, aspect, near, far ) {
  12755. Camera.call( this );
  12756. this.type = 'PerspectiveCamera';
  12757. this.fov = fov !== undefined ? fov : 50;
  12758. this.zoom = 1;
  12759. this.near = near !== undefined ? near : 0.1;
  12760. this.far = far !== undefined ? far : 2000;
  12761. this.focus = 10;
  12762. this.aspect = aspect !== undefined ? aspect : 1;
  12763. this.view = null;
  12764. this.filmGauge = 35; // width of the film (default in millimeters)
  12765. this.filmOffset = 0; // horizontal film offset (same unit as gauge)
  12766. this.updateProjectionMatrix();
  12767. }
  12768. PerspectiveCamera.prototype = Object.assign( Object.create( Camera.prototype ), {
  12769. constructor: PerspectiveCamera,
  12770. isPerspectiveCamera: true,
  12771. copy: function ( source, recursive ) {
  12772. Camera.prototype.copy.call( this, source, recursive );
  12773. this.fov = source.fov;
  12774. this.zoom = source.zoom;
  12775. this.near = source.near;
  12776. this.far = source.far;
  12777. this.focus = source.focus;
  12778. this.aspect = source.aspect;
  12779. this.view = source.view === null ? null : Object.assign( {}, source.view );
  12780. this.filmGauge = source.filmGauge;
  12781. this.filmOffset = source.filmOffset;
  12782. return this;
  12783. },
  12784. /**
  12785. * Sets the FOV by focal length in respect to the current .filmGauge.
  12786. *
  12787. * The default film gauge is 35, so that the focal length can be specified for
  12788. * a 35mm (full frame) camera.
  12789. *
  12790. * Values for focal length and film gauge must have the same unit.
  12791. */
  12792. setFocalLength: function ( focalLength ) {
  12793. // see http://www.bobatkins.com/photography/technical/field_of_view.html
  12794. var vExtentSlope = 0.5 * this.getFilmHeight() / focalLength;
  12795. this.fov = _Math.RAD2DEG * 2 * Math.atan( vExtentSlope );
  12796. this.updateProjectionMatrix();
  12797. },
  12798. /**
  12799. * Calculates the focal length from the current .fov and .filmGauge.
  12800. */
  12801. getFocalLength: function () {
  12802. var vExtentSlope = Math.tan( _Math.DEG2RAD * 0.5 * this.fov );
  12803. return 0.5 * this.getFilmHeight() / vExtentSlope;
  12804. },
  12805. getEffectiveFOV: function () {
  12806. return _Math.RAD2DEG * 2 * Math.atan(
  12807. Math.tan( _Math.DEG2RAD * 0.5 * this.fov ) / this.zoom );
  12808. },
  12809. getFilmWidth: function () {
  12810. // film not completely covered in portrait format (aspect < 1)
  12811. return this.filmGauge * Math.min( this.aspect, 1 );
  12812. },
  12813. getFilmHeight: function () {
  12814. // film not completely covered in landscape format (aspect > 1)
  12815. return this.filmGauge / Math.max( this.aspect, 1 );
  12816. },
  12817. /**
  12818. * Sets an offset in a larger frustum. This is useful for multi-window or
  12819. * multi-monitor/multi-machine setups.
  12820. *
  12821. * For example, if you have 3x2 monitors and each monitor is 1920x1080 and
  12822. * the monitors are in grid like this
  12823. *
  12824. * +---+---+---+
  12825. * | A | B | C |
  12826. * +---+---+---+
  12827. * | D | E | F |
  12828. * +---+---+---+
  12829. *
  12830. * then for each monitor you would call it like this
  12831. *
  12832. * var w = 1920;
  12833. * var h = 1080;
  12834. * var fullWidth = w * 3;
  12835. * var fullHeight = h * 2;
  12836. *
  12837. * --A--
  12838. * camera.setViewOffset( fullWidth, fullHeight, w * 0, h * 0, w, h );
  12839. * --B--
  12840. * camera.setViewOffset( fullWidth, fullHeight, w * 1, h * 0, w, h );
  12841. * --C--
  12842. * camera.setViewOffset( fullWidth, fullHeight, w * 2, h * 0, w, h );
  12843. * --D--
  12844. * camera.setViewOffset( fullWidth, fullHeight, w * 0, h * 1, w, h );
  12845. * --E--
  12846. * camera.setViewOffset( fullWidth, fullHeight, w * 1, h * 1, w, h );
  12847. * --F--
  12848. * camera.setViewOffset( fullWidth, fullHeight, w * 2, h * 1, w, h );
  12849. *
  12850. * Note there is no reason monitors have to be the same size or in a grid.
  12851. */
  12852. setViewOffset: function ( fullWidth, fullHeight, x, y, width, height ) {
  12853. this.aspect = fullWidth / fullHeight;
  12854. if ( this.view === null ) {
  12855. this.view = {
  12856. enabled: true,
  12857. fullWidth: 1,
  12858. fullHeight: 1,
  12859. offsetX: 0,
  12860. offsetY: 0,
  12861. width: 1,
  12862. height: 1
  12863. };
  12864. }
  12865. this.view.enabled = true;
  12866. this.view.fullWidth = fullWidth;
  12867. this.view.fullHeight = fullHeight;
  12868. this.view.offsetX = x;
  12869. this.view.offsetY = y;
  12870. this.view.width = width;
  12871. this.view.height = height;
  12872. this.updateProjectionMatrix();
  12873. },
  12874. clearViewOffset: function () {
  12875. if ( this.view !== null ) {
  12876. this.view.enabled = false;
  12877. }
  12878. this.updateProjectionMatrix();
  12879. },
  12880. updateProjectionMatrix: function () {
  12881. var near = this.near,
  12882. top = near * Math.tan( _Math.DEG2RAD * 0.5 * this.fov ) / this.zoom,
  12883. height = 2 * top,
  12884. width = this.aspect * height,
  12885. left = - 0.5 * width,
  12886. view = this.view;
  12887. if ( this.view !== null && this.view.enabled ) {
  12888. var fullWidth = view.fullWidth,
  12889. fullHeight = view.fullHeight;
  12890. left += view.offsetX * width / fullWidth;
  12891. top -= view.offsetY * height / fullHeight;
  12892. width *= view.width / fullWidth;
  12893. height *= view.height / fullHeight;
  12894. }
  12895. var skew = this.filmOffset;
  12896. if ( skew !== 0 ) left += near * skew / this.getFilmWidth();
  12897. this.projectionMatrix.makePerspective( left, left + width, top, top - height, near, this.far );
  12898. this.projectionMatrixInverse.getInverse( this.projectionMatrix );
  12899. },
  12900. toJSON: function ( meta ) {
  12901. var data = Object3D.prototype.toJSON.call( this, meta );
  12902. data.object.fov = this.fov;
  12903. data.object.zoom = this.zoom;
  12904. data.object.near = this.near;
  12905. data.object.far = this.far;
  12906. data.object.focus = this.focus;
  12907. data.object.aspect = this.aspect;
  12908. if ( this.view !== null ) data.object.view = Object.assign( {}, this.view );
  12909. data.object.filmGauge = this.filmGauge;
  12910. data.object.filmOffset = this.filmOffset;
  12911. return data;
  12912. }
  12913. } );
  12914. /**
  12915. * @author mrdoob / http://mrdoob.com/
  12916. */
  12917. function ArrayCamera( array ) {
  12918. PerspectiveCamera.call( this );
  12919. this.cameras = array || [];
  12920. }
  12921. ArrayCamera.prototype = Object.assign( Object.create( PerspectiveCamera.prototype ), {
  12922. constructor: ArrayCamera,
  12923. isArrayCamera: true
  12924. } );
  12925. /**
  12926. * @author jsantell / https://www.jsantell.com/
  12927. * @author mrdoob / http://mrdoob.com/
  12928. */
  12929. var cameraLPos = new Vector3();
  12930. var cameraRPos = new Vector3();
  12931. /**
  12932. * Assumes 2 cameras that are parallel and share an X-axis, and that
  12933. * the cameras' projection and world matrices have already been set.
  12934. * And that near and far planes are identical for both cameras.
  12935. * Visualization of this technique: https://computergraphics.stackexchange.com/a/4765
  12936. */
  12937. function setProjectionFromUnion( camera, cameraL, cameraR ) {
  12938. cameraLPos.setFromMatrixPosition( cameraL.matrixWorld );
  12939. cameraRPos.setFromMatrixPosition( cameraR.matrixWorld );
  12940. var ipd = cameraLPos.distanceTo( cameraRPos );
  12941. var projL = cameraL.projectionMatrix.elements;
  12942. var projR = cameraR.projectionMatrix.elements;
  12943. // VR systems will have identical far and near planes, and
  12944. // most likely identical top and bottom frustum extents.
  12945. // Use the left camera for these values.
  12946. var near = projL[ 14 ] / ( projL[ 10 ] - 1 );
  12947. var far = projL[ 14 ] / ( projL[ 10 ] + 1 );
  12948. var topFov = ( projL[ 9 ] + 1 ) / projL[ 5 ];
  12949. var bottomFov = ( projL[ 9 ] - 1 ) / projL[ 5 ];
  12950. var leftFov = ( projL[ 8 ] - 1 ) / projL[ 0 ];
  12951. var rightFov = ( projR[ 8 ] + 1 ) / projR[ 0 ];
  12952. var left = near * leftFov;
  12953. var right = near * rightFov;
  12954. // Calculate the new camera's position offset from the
  12955. // left camera. xOffset should be roughly half `ipd`.
  12956. var zOffset = ipd / ( - leftFov + rightFov );
  12957. var xOffset = zOffset * - leftFov;
  12958. // TODO: Better way to apply this offset?
  12959. cameraL.matrixWorld.decompose( camera.position, camera.quaternion, camera.scale );
  12960. camera.translateX( xOffset );
  12961. camera.translateZ( zOffset );
  12962. camera.matrixWorld.compose( camera.position, camera.quaternion, camera.scale );
  12963. camera.matrixWorldInverse.getInverse( camera.matrixWorld );
  12964. // Find the union of the frustum values of the cameras and scale
  12965. // the values so that the near plane's position does not change in world space,
  12966. // although must now be relative to the new union camera.
  12967. var near2 = near + zOffset;
  12968. var far2 = far + zOffset;
  12969. var left2 = left - xOffset;
  12970. var right2 = right + ( ipd - xOffset );
  12971. var top2 = topFov * far / far2 * near2;
  12972. var bottom2 = bottomFov * far / far2 * near2;
  12973. camera.projectionMatrix.makePerspective( left2, right2, top2, bottom2, near2, far2 );
  12974. }
  12975. /**
  12976. * @author mrdoob / http://mrdoob.com/
  12977. */
  12978. function WebVRManager( renderer ) {
  12979. var scope = this;
  12980. var device = null;
  12981. var frameData = null;
  12982. var poseTarget = null;
  12983. var controllers = [];
  12984. var standingMatrix = new Matrix4();
  12985. var standingMatrixInverse = new Matrix4();
  12986. var framebufferScaleFactor = 1.0;
  12987. var frameOfReferenceType = 'stage';
  12988. if ( typeof window !== 'undefined' && 'VRFrameData' in window ) {
  12989. frameData = new window.VRFrameData();
  12990. window.addEventListener( 'vrdisplaypresentchange', onVRDisplayPresentChange, false );
  12991. }
  12992. var matrixWorldInverse = new Matrix4();
  12993. var tempQuaternion = new Quaternion();
  12994. var tempPosition = new Vector3();
  12995. var cameraL = new PerspectiveCamera();
  12996. cameraL.bounds = new Vector4( 0.0, 0.0, 0.5, 1.0 );
  12997. cameraL.layers.enable( 1 );
  12998. var cameraR = new PerspectiveCamera();
  12999. cameraR.bounds = new Vector4( 0.5, 0.0, 0.5, 1.0 );
  13000. cameraR.layers.enable( 2 );
  13001. var cameraVR = new ArrayCamera( [ cameraL, cameraR ] );
  13002. cameraVR.layers.enable( 1 );
  13003. cameraVR.layers.enable( 2 );
  13004. //
  13005. function isPresenting() {
  13006. return device !== null && device.isPresenting === true;
  13007. }
  13008. var currentSize = new Vector2(), currentPixelRatio;
  13009. function onVRDisplayPresentChange() {
  13010. if ( isPresenting() ) {
  13011. var eyeParameters = device.getEyeParameters( 'left' );
  13012. var renderWidth = eyeParameters.renderWidth * framebufferScaleFactor;
  13013. var renderHeight = eyeParameters.renderHeight * framebufferScaleFactor;
  13014. currentPixelRatio = renderer.getPixelRatio();
  13015. renderer.getSize( currentSize );
  13016. renderer.setDrawingBufferSize( renderWidth * 2, renderHeight, 1 );
  13017. animation.start();
  13018. } else {
  13019. if ( scope.enabled ) {
  13020. renderer.setDrawingBufferSize( currentSize.width, currentSize.height, currentPixelRatio );
  13021. }
  13022. animation.stop();
  13023. }
  13024. }
  13025. //
  13026. var triggers = [];
  13027. function findGamepad( id ) {
  13028. var gamepads = navigator.getGamepads && navigator.getGamepads();
  13029. for ( var i = 0, j = 0, l = gamepads.length; i < l; i ++ ) {
  13030. var gamepad = gamepads[ i ];
  13031. if ( gamepad && ( gamepad.id === 'Daydream Controller' ||
  13032. gamepad.id === 'Gear VR Controller' || gamepad.id === 'Oculus Go Controller' ||
  13033. gamepad.id === 'OpenVR Gamepad' || gamepad.id.startsWith( 'Oculus Touch' ) ||
  13034. gamepad.id.startsWith( 'Spatial Controller' ) ) ) {
  13035. if ( j === id ) return gamepad;
  13036. j ++;
  13037. }
  13038. }
  13039. }
  13040. function updateControllers() {
  13041. for ( var i = 0; i < controllers.length; i ++ ) {
  13042. var controller = controllers[ i ];
  13043. var gamepad = findGamepad( i );
  13044. if ( gamepad !== undefined && gamepad.pose !== undefined ) {
  13045. if ( gamepad.pose === null ) return;
  13046. // Pose
  13047. var pose = gamepad.pose;
  13048. if ( pose.hasPosition === false ) controller.position.set( 0.2, - 0.6, - 0.05 );
  13049. if ( pose.position !== null ) controller.position.fromArray( pose.position );
  13050. if ( pose.orientation !== null ) controller.quaternion.fromArray( pose.orientation );
  13051. controller.matrix.compose( controller.position, controller.quaternion, controller.scale );
  13052. controller.matrix.premultiply( standingMatrix );
  13053. controller.matrix.decompose( controller.position, controller.quaternion, controller.scale );
  13054. controller.matrixWorldNeedsUpdate = true;
  13055. controller.visible = true;
  13056. // Trigger
  13057. var buttonId = gamepad.id === 'Daydream Controller' ? 0 : 1;
  13058. if ( triggers[ i ] !== gamepad.buttons[ buttonId ].pressed ) {
  13059. triggers[ i ] = gamepad.buttons[ buttonId ].pressed;
  13060. if ( triggers[ i ] === true ) {
  13061. controller.dispatchEvent( { type: 'selectstart' } );
  13062. } else {
  13063. controller.dispatchEvent( { type: 'selectend' } );
  13064. controller.dispatchEvent( { type: 'select' } );
  13065. }
  13066. }
  13067. } else {
  13068. controller.visible = false;
  13069. }
  13070. }
  13071. }
  13072. //
  13073. this.enabled = false;
  13074. this.getController = function ( id ) {
  13075. var controller = controllers[ id ];
  13076. if ( controller === undefined ) {
  13077. controller = new Group();
  13078. controller.matrixAutoUpdate = false;
  13079. controller.visible = false;
  13080. controllers[ id ] = controller;
  13081. }
  13082. return controller;
  13083. };
  13084. this.getDevice = function () {
  13085. return device;
  13086. };
  13087. this.setDevice = function ( value ) {
  13088. if ( value !== undefined ) device = value;
  13089. animation.setContext( value );
  13090. };
  13091. this.setFramebufferScaleFactor = function ( value ) {
  13092. framebufferScaleFactor = value;
  13093. };
  13094. this.setFrameOfReferenceType = function ( value ) {
  13095. frameOfReferenceType = value;
  13096. };
  13097. this.setPoseTarget = function ( object ) {
  13098. if ( object !== undefined ) poseTarget = object;
  13099. };
  13100. this.getCamera = function ( camera ) {
  13101. var userHeight = frameOfReferenceType === 'stage' ? 1.6 : 0;
  13102. if ( isPresenting() === false ) {
  13103. camera.position.set( 0, userHeight, 0 );
  13104. camera.rotation.set( 0, 0, 0 );
  13105. return camera;
  13106. }
  13107. device.depthNear = camera.near;
  13108. device.depthFar = camera.far;
  13109. device.getFrameData( frameData );
  13110. //
  13111. if ( frameOfReferenceType === 'stage' ) {
  13112. var stageParameters = device.stageParameters;
  13113. if ( stageParameters ) {
  13114. standingMatrix.fromArray( stageParameters.sittingToStandingTransform );
  13115. } else {
  13116. standingMatrix.makeTranslation( 0, userHeight, 0 );
  13117. }
  13118. }
  13119. var pose = frameData.pose;
  13120. var poseObject = poseTarget !== null ? poseTarget : camera;
  13121. // We want to manipulate poseObject by its position and quaternion components since users may rely on them.
  13122. poseObject.matrix.copy( standingMatrix );
  13123. poseObject.matrix.decompose( poseObject.position, poseObject.quaternion, poseObject.scale );
  13124. if ( pose.orientation !== null ) {
  13125. tempQuaternion.fromArray( pose.orientation );
  13126. poseObject.quaternion.multiply( tempQuaternion );
  13127. }
  13128. if ( pose.position !== null ) {
  13129. tempQuaternion.setFromRotationMatrix( standingMatrix );
  13130. tempPosition.fromArray( pose.position );
  13131. tempPosition.applyQuaternion( tempQuaternion );
  13132. poseObject.position.add( tempPosition );
  13133. }
  13134. poseObject.updateMatrixWorld();
  13135. //
  13136. cameraL.near = camera.near;
  13137. cameraR.near = camera.near;
  13138. cameraL.far = camera.far;
  13139. cameraR.far = camera.far;
  13140. cameraL.matrixWorldInverse.fromArray( frameData.leftViewMatrix );
  13141. cameraR.matrixWorldInverse.fromArray( frameData.rightViewMatrix );
  13142. // TODO (mrdoob) Double check this code
  13143. standingMatrixInverse.getInverse( standingMatrix );
  13144. if ( frameOfReferenceType === 'stage' ) {
  13145. cameraL.matrixWorldInverse.multiply( standingMatrixInverse );
  13146. cameraR.matrixWorldInverse.multiply( standingMatrixInverse );
  13147. }
  13148. var parent = poseObject.parent;
  13149. if ( parent !== null ) {
  13150. matrixWorldInverse.getInverse( parent.matrixWorld );
  13151. cameraL.matrixWorldInverse.multiply( matrixWorldInverse );
  13152. cameraR.matrixWorldInverse.multiply( matrixWorldInverse );
  13153. }
  13154. // envMap and Mirror needs camera.matrixWorld
  13155. cameraL.matrixWorld.getInverse( cameraL.matrixWorldInverse );
  13156. cameraR.matrixWorld.getInverse( cameraR.matrixWorldInverse );
  13157. cameraL.projectionMatrix.fromArray( frameData.leftProjectionMatrix );
  13158. cameraR.projectionMatrix.fromArray( frameData.rightProjectionMatrix );
  13159. setProjectionFromUnion( cameraVR, cameraL, cameraR );
  13160. //
  13161. var layers = device.getLayers();
  13162. if ( layers.length ) {
  13163. var layer = layers[ 0 ];
  13164. if ( layer.leftBounds !== null && layer.leftBounds.length === 4 ) {
  13165. cameraL.bounds.fromArray( layer.leftBounds );
  13166. }
  13167. if ( layer.rightBounds !== null && layer.rightBounds.length === 4 ) {
  13168. cameraR.bounds.fromArray( layer.rightBounds );
  13169. }
  13170. }
  13171. updateControllers();
  13172. return cameraVR;
  13173. };
  13174. this.getStandingMatrix = function () {
  13175. return standingMatrix;
  13176. };
  13177. this.isPresenting = isPresenting;
  13178. // Animation Loop
  13179. var animation = new WebGLAnimation();
  13180. this.setAnimationLoop = function ( callback ) {
  13181. animation.setAnimationLoop( callback );
  13182. };
  13183. this.submitFrame = function () {
  13184. if ( isPresenting() ) device.submitFrame();
  13185. };
  13186. this.dispose = function () {
  13187. if ( typeof window !== 'undefined' ) {
  13188. window.removeEventListener( 'vrdisplaypresentchange', onVRDisplayPresentChange );
  13189. }
  13190. };
  13191. }
  13192. /**
  13193. * @author mrdoob / http://mrdoob.com/
  13194. */
  13195. function WebXRManager( renderer ) {
  13196. var gl = renderer.context;
  13197. var device = null;
  13198. var session = null;
  13199. var framebufferScaleFactor = 1.0;
  13200. var frameOfReference = null;
  13201. var frameOfReferenceType = 'stage';
  13202. var pose = null;
  13203. var controllers = [];
  13204. var inputSources = [];
  13205. function isPresenting() {
  13206. return session !== null && frameOfReference !== null;
  13207. }
  13208. //
  13209. var cameraL = new PerspectiveCamera();
  13210. cameraL.layers.enable( 1 );
  13211. cameraL.viewport = new Vector4();
  13212. var cameraR = new PerspectiveCamera();
  13213. cameraR.layers.enable( 2 );
  13214. cameraR.viewport = new Vector4();
  13215. var cameraVR = new ArrayCamera( [ cameraL, cameraR ] );
  13216. cameraVR.layers.enable( 1 );
  13217. cameraVR.layers.enable( 2 );
  13218. //
  13219. this.enabled = false;
  13220. this.getController = function ( id ) {
  13221. var controller = controllers[ id ];
  13222. if ( controller === undefined ) {
  13223. controller = new Group();
  13224. controller.matrixAutoUpdate = false;
  13225. controller.visible = false;
  13226. controllers[ id ] = controller;
  13227. }
  13228. return controller;
  13229. };
  13230. this.getDevice = function () {
  13231. return device;
  13232. };
  13233. this.setDevice = function ( value ) {
  13234. if ( value !== undefined ) device = value;
  13235. if ( value instanceof XRDevice ) gl.setCompatibleXRDevice( value );
  13236. };
  13237. //
  13238. function onSessionEvent( event ) {
  13239. var controller = controllers[ inputSources.indexOf( event.inputSource ) ];
  13240. if ( controller ) controller.dispatchEvent( { type: event.type } );
  13241. }
  13242. function onSessionEnd() {
  13243. renderer.setFramebuffer( null );
  13244. renderer.setRenderTarget( renderer.getRenderTarget() ); // Hack #15830
  13245. animation.stop();
  13246. }
  13247. this.setFramebufferScaleFactor = function ( value ) {
  13248. framebufferScaleFactor = value;
  13249. };
  13250. this.setFrameOfReferenceType = function ( value ) {
  13251. frameOfReferenceType = value;
  13252. };
  13253. this.setSession = function ( value ) {
  13254. session = value;
  13255. if ( session !== null ) {
  13256. session.addEventListener( 'select', onSessionEvent );
  13257. session.addEventListener( 'selectstart', onSessionEvent );
  13258. session.addEventListener( 'selectend', onSessionEvent );
  13259. session.addEventListener( 'end', onSessionEnd );
  13260. session.baseLayer = new XRWebGLLayer( session, gl, { framebufferScaleFactor: framebufferScaleFactor } );
  13261. session.requestFrameOfReference( frameOfReferenceType ).then( function ( value ) {
  13262. frameOfReference = value;
  13263. renderer.setFramebuffer( session.baseLayer.framebuffer );
  13264. animation.setContext( session );
  13265. animation.start();
  13266. } );
  13267. //
  13268. inputSources = session.getInputSources();
  13269. session.addEventListener( 'inputsourceschange', function () {
  13270. inputSources = session.getInputSources();
  13271. console.log( inputSources );
  13272. for ( var i = 0; i < controllers.length; i ++ ) {
  13273. var controller = controllers[ i ];
  13274. controller.userData.inputSource = inputSources[ i ];
  13275. }
  13276. } );
  13277. }
  13278. };
  13279. function updateCamera( camera, parent ) {
  13280. if ( parent === null ) {
  13281. camera.matrixWorld.copy( camera.matrix );
  13282. } else {
  13283. camera.matrixWorld.multiplyMatrices( parent.matrixWorld, camera.matrix );
  13284. }
  13285. camera.matrixWorldInverse.getInverse( camera.matrixWorld );
  13286. }
  13287. this.getCamera = function ( camera ) {
  13288. if ( isPresenting() ) {
  13289. var parent = camera.parent;
  13290. var cameras = cameraVR.cameras;
  13291. updateCamera( cameraVR, parent );
  13292. for ( var i = 0; i < cameras.length; i ++ ) {
  13293. updateCamera( cameras[ i ], parent );
  13294. }
  13295. // update camera and its children
  13296. camera.matrixWorld.copy( cameraVR.matrixWorld );
  13297. var children = camera.children;
  13298. for ( var i = 0, l = children.length; i < l; i ++ ) {
  13299. children[ i ].updateMatrixWorld( true );
  13300. }
  13301. setProjectionFromUnion( cameraVR, cameraL, cameraR );
  13302. return cameraVR;
  13303. }
  13304. return camera;
  13305. };
  13306. this.isPresenting = isPresenting;
  13307. // Animation Loop
  13308. var onAnimationFrameCallback = null;
  13309. function onAnimationFrame( time, frame ) {
  13310. pose = frame.getDevicePose( frameOfReference );
  13311. if ( pose !== null ) {
  13312. var layer = session.baseLayer;
  13313. var views = frame.views;
  13314. for ( var i = 0; i < views.length; i ++ ) {
  13315. var view = views[ i ];
  13316. var viewport = layer.getViewport( view );
  13317. var viewMatrix = pose.getViewMatrix( view );
  13318. var camera = cameraVR.cameras[ i ];
  13319. camera.matrix.fromArray( viewMatrix ).getInverse( camera.matrix );
  13320. camera.projectionMatrix.fromArray( view.projectionMatrix );
  13321. camera.viewport.set( viewport.x, viewport.y, viewport.width, viewport.height );
  13322. if ( i === 0 ) {
  13323. cameraVR.matrix.copy( camera.matrix );
  13324. }
  13325. }
  13326. }
  13327. //
  13328. for ( var i = 0; i < controllers.length; i ++ ) {
  13329. var controller = controllers[ i ];
  13330. var inputSource = inputSources[ i ];
  13331. if ( inputSource ) {
  13332. var inputPose = frame.getInputPose( inputSource, frameOfReference );
  13333. if ( inputPose !== null ) {
  13334. if ( 'targetRay' in inputPose ) {
  13335. controller.matrix.elements = inputPose.targetRay.transformMatrix;
  13336. } else if ( 'pointerMatrix' in inputPose ) {
  13337. // DEPRECATED
  13338. controller.matrix.elements = inputPose.pointerMatrix;
  13339. }
  13340. controller.matrix.decompose( controller.position, controller.rotation, controller.scale );
  13341. controller.visible = true;
  13342. continue;
  13343. }
  13344. }
  13345. controller.visible = false;
  13346. }
  13347. if ( onAnimationFrameCallback ) onAnimationFrameCallback( time );
  13348. }
  13349. var animation = new WebGLAnimation();
  13350. animation.setAnimationLoop( onAnimationFrame );
  13351. this.setAnimationLoop = function ( callback ) {
  13352. onAnimationFrameCallback = callback;
  13353. };
  13354. this.dispose = function () {};
  13355. // DEPRECATED
  13356. this.getStandingMatrix = function () {
  13357. console.warn( 'THREE.WebXRManager: getStandingMatrix() is no longer needed.' );
  13358. return new THREE.Matrix4();
  13359. };
  13360. this.submitFrame = function () {};
  13361. }
  13362. /**
  13363. * @author supereggbert / http://www.paulbrunt.co.uk/
  13364. * @author mrdoob / http://mrdoob.com/
  13365. * @author alteredq / http://alteredqualia.com/
  13366. * @author szimek / https://github.com/szimek/
  13367. * @author tschw
  13368. */
  13369. function WebGLRenderer( parameters ) {
  13370. console.log( 'THREE.WebGLRenderer', REVISION );
  13371. parameters = parameters || {};
  13372. var _canvas = parameters.canvas !== undefined ? parameters.canvas : document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' ),
  13373. _context = parameters.context !== undefined ? parameters.context : null,
  13374. _alpha = parameters.alpha !== undefined ? parameters.alpha : false,
  13375. _depth = parameters.depth !== undefined ? parameters.depth : true,
  13376. _stencil = parameters.stencil !== undefined ? parameters.stencil : true,
  13377. _antialias = parameters.antialias !== undefined ? parameters.antialias : false,
  13378. _premultipliedAlpha = parameters.premultipliedAlpha !== undefined ? parameters.premultipliedAlpha : true,
  13379. _preserveDrawingBuffer = parameters.preserveDrawingBuffer !== undefined ? parameters.preserveDrawingBuffer : false,
  13380. _powerPreference = parameters.powerPreference !== undefined ? parameters.powerPreference : 'default';
  13381. var currentRenderList = null;
  13382. var currentRenderState = null;
  13383. // public properties
  13384. this.domElement = _canvas;
  13385. this.context = null;
  13386. // clearing
  13387. this.autoClear = true;
  13388. this.autoClearColor = true;
  13389. this.autoClearDepth = true;
  13390. this.autoClearStencil = true;
  13391. // scene graph
  13392. this.sortObjects = true;
  13393. // user-defined clipping
  13394. this.clippingPlanes = [];
  13395. this.localClippingEnabled = false;
  13396. // physically based shading
  13397. this.gammaFactor = 2.0; // for backwards compatibility
  13398. this.gammaInput = false;
  13399. this.gammaOutput = false;
  13400. // physical lights
  13401. this.physicallyCorrectLights = false;
  13402. // tone mapping
  13403. this.toneMapping = LinearToneMapping;
  13404. this.toneMappingExposure = 1.0;
  13405. this.toneMappingWhitePoint = 1.0;
  13406. // morphs
  13407. this.maxMorphTargets = 8;
  13408. this.maxMorphNormals = 4;
  13409. // internal properties
  13410. var _this = this,
  13411. _isContextLost = false,
  13412. // internal state cache
  13413. _framebuffer = null,
  13414. _currentRenderTarget = null,
  13415. _currentFramebuffer = null,
  13416. _currentMaterialId = - 1,
  13417. // geometry and program caching
  13418. _currentGeometryProgram = {
  13419. geometry: null,
  13420. program: null,
  13421. wireframe: false
  13422. },
  13423. _currentCamera = null,
  13424. _currentArrayCamera = null,
  13425. _currentViewport = new Vector4(),
  13426. _currentScissor = new Vector4(),
  13427. _currentScissorTest = null,
  13428. //
  13429. _usedTextureUnits = 0,
  13430. //
  13431. _width = _canvas.width,
  13432. _height = _canvas.height,
  13433. _pixelRatio = 1,
  13434. _viewport = new Vector4( 0, 0, _width, _height ),
  13435. _scissor = new Vector4( 0, 0, _width, _height ),
  13436. _scissorTest = false,
  13437. // frustum
  13438. _frustum = new Frustum(),
  13439. // clipping
  13440. _clipping = new WebGLClipping(),
  13441. _clippingEnabled = false,
  13442. _localClippingEnabled = false,
  13443. // camera matrices cache
  13444. _projScreenMatrix = new Matrix4(),
  13445. _vector3 = new Vector3();
  13446. function getTargetPixelRatio() {
  13447. return _currentRenderTarget === null ? _pixelRatio : 1;
  13448. }
  13449. // initialize
  13450. var _gl;
  13451. try {
  13452. var contextAttributes = {
  13453. alpha: _alpha,
  13454. depth: _depth,
  13455. stencil: _stencil,
  13456. antialias: _antialias,
  13457. premultipliedAlpha: _premultipliedAlpha,
  13458. preserveDrawingBuffer: _preserveDrawingBuffer,
  13459. powerPreference: _powerPreference
  13460. };
  13461. // event listeners must be registered before WebGL context is created, see #12753
  13462. _canvas.addEventListener( 'webglcontextlost', onContextLost, false );
  13463. _canvas.addEventListener( 'webglcontextrestored', onContextRestore, false );
  13464. _gl = _context || _canvas.getContext( 'webgl', contextAttributes ) || _canvas.getContext( 'experimental-webgl', contextAttributes );
  13465. if ( _gl === null ) {
  13466. if ( _canvas.getContext( 'webgl' ) !== null ) {
  13467. throw new Error( 'Error creating WebGL context with your selected attributes.' );
  13468. } else {
  13469. throw new Error( 'Error creating WebGL context.' );
  13470. }
  13471. }
  13472. // Some experimental-webgl implementations do not have getShaderPrecisionFormat
  13473. if ( _gl.getShaderPrecisionFormat === undefined ) {
  13474. _gl.getShaderPrecisionFormat = function () {
  13475. return { 'rangeMin': 1, 'rangeMax': 1, 'precision': 1 };
  13476. };
  13477. }
  13478. } catch ( error ) {
  13479. console.error( 'THREE.WebGLRenderer: ' + error.message );
  13480. throw error;
  13481. }
  13482. var extensions, capabilities, state, info;
  13483. var properties, textures, attributes, geometries, objects;
  13484. var programCache, renderLists, renderStates;
  13485. var background, morphtargets, bufferRenderer, indexedBufferRenderer;
  13486. var utils;
  13487. function initGLContext() {
  13488. extensions = new WebGLExtensions( _gl );
  13489. capabilities = new WebGLCapabilities( _gl, extensions, parameters );
  13490. if ( ! capabilities.isWebGL2 ) {
  13491. extensions.get( 'WEBGL_depth_texture' );
  13492. extensions.get( 'OES_texture_float' );
  13493. extensions.get( 'OES_texture_half_float' );
  13494. extensions.get( 'OES_texture_half_float_linear' );
  13495. extensions.get( 'OES_standard_derivatives' );
  13496. extensions.get( 'OES_element_index_uint' );
  13497. extensions.get( 'ANGLE_instanced_arrays' );
  13498. }
  13499. extensions.get( 'OES_texture_float_linear' );
  13500. utils = new WebGLUtils( _gl, extensions, capabilities );
  13501. state = new WebGLState( _gl, extensions, utils, capabilities );
  13502. state.scissor( _currentScissor.copy( _scissor ).multiplyScalar( _pixelRatio ) );
  13503. state.viewport( _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio ) );
  13504. info = new WebGLInfo( _gl );
  13505. properties = new WebGLProperties();
  13506. textures = new WebGLTextures( _gl, extensions, state, properties, capabilities, utils, info );
  13507. attributes = new WebGLAttributes( _gl );
  13508. geometries = new WebGLGeometries( _gl, attributes, info );
  13509. objects = new WebGLObjects( geometries, info );
  13510. morphtargets = new WebGLMorphtargets( _gl );
  13511. programCache = new WebGLPrograms( _this, extensions, capabilities );
  13512. renderLists = new WebGLRenderLists();
  13513. renderStates = new WebGLRenderStates();
  13514. background = new WebGLBackground( _this, state, objects, _premultipliedAlpha );
  13515. bufferRenderer = new WebGLBufferRenderer( _gl, extensions, info, capabilities );
  13516. indexedBufferRenderer = new WebGLIndexedBufferRenderer( _gl, extensions, info, capabilities );
  13517. info.programs = programCache.programs;
  13518. _this.context = _gl;
  13519. _this.capabilities = capabilities;
  13520. _this.extensions = extensions;
  13521. _this.properties = properties;
  13522. _this.renderLists = renderLists;
  13523. _this.state = state;
  13524. _this.info = info;
  13525. }
  13526. initGLContext();
  13527. // vr
  13528. var vr = null;
  13529. if ( typeof navigator !== 'undefined' ) {
  13530. vr = ( 'xr' in navigator ) ? new WebXRManager( _this ) : new WebVRManager( _this );
  13531. }
  13532. this.vr = vr;
  13533. // shadow map
  13534. var shadowMap = new WebGLShadowMap( _this, objects, capabilities.maxTextureSize );
  13535. this.shadowMap = shadowMap;
  13536. // API
  13537. this.getContext = function () {
  13538. return _gl;
  13539. };
  13540. this.getContextAttributes = function () {
  13541. return _gl.getContextAttributes();
  13542. };
  13543. this.forceContextLoss = function () {
  13544. var extension = extensions.get( 'WEBGL_lose_context' );
  13545. if ( extension ) extension.loseContext();
  13546. };
  13547. this.forceContextRestore = function () {
  13548. var extension = extensions.get( 'WEBGL_lose_context' );
  13549. if ( extension ) extension.restoreContext();
  13550. };
  13551. this.getPixelRatio = function () {
  13552. return _pixelRatio;
  13553. };
  13554. this.setPixelRatio = function ( value ) {
  13555. if ( value === undefined ) return;
  13556. _pixelRatio = value;
  13557. this.setSize( _width, _height, false );
  13558. };
  13559. this.getSize = function ( target ) {
  13560. if ( target === undefined ) {
  13561. console.warn( 'WebGLRenderer: .getsize() now requires a Vector2 as an argument' );
  13562. target = new Vector2();
  13563. }
  13564. return target.set( _width, _height );
  13565. };
  13566. this.setSize = function ( width, height, updateStyle ) {
  13567. if ( vr.isPresenting() ) {
  13568. console.warn( 'THREE.WebGLRenderer: Can\'t change size while VR device is presenting.' );
  13569. return;
  13570. }
  13571. _width = width;
  13572. _height = height;
  13573. _canvas.width = width * _pixelRatio;
  13574. _canvas.height = height * _pixelRatio;
  13575. if ( updateStyle !== false ) {
  13576. _canvas.style.width = width + 'px';
  13577. _canvas.style.height = height + 'px';
  13578. }
  13579. this.setViewport( 0, 0, width, height );
  13580. };
  13581. this.getDrawingBufferSize = function ( target ) {
  13582. if ( target === undefined ) {
  13583. console.warn( 'WebGLRenderer: .getdrawingBufferSize() now requires a Vector2 as an argument' );
  13584. target = new Vector2();
  13585. }
  13586. return target.set( _width * _pixelRatio, _height * _pixelRatio );
  13587. };
  13588. this.setDrawingBufferSize = function ( width, height, pixelRatio ) {
  13589. _width = width;
  13590. _height = height;
  13591. _pixelRatio = pixelRatio;
  13592. _canvas.width = width * pixelRatio;
  13593. _canvas.height = height * pixelRatio;
  13594. this.setViewport( 0, 0, width, height );
  13595. };
  13596. this.getCurrentViewport = function ( target ) {
  13597. if ( target === undefined ) {
  13598. console.warn( 'WebGLRenderer: .getCurrentViewport() now requires a Vector4 as an argument' );
  13599. target = new Vector4();
  13600. }
  13601. return target.copy( _currentViewport );
  13602. };
  13603. this.getViewport = function ( target ) {
  13604. return target.copy( _viewport );
  13605. };
  13606. this.setViewport = function ( x, y, width, height ) {
  13607. if ( x.isVector4 ) {
  13608. _viewport.set( x.x, x.y, x.z, x.w );
  13609. } else {
  13610. _viewport.set( x, y, width, height );
  13611. }
  13612. state.viewport( _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio ) );
  13613. };
  13614. this.getScissor = function ( target ) {
  13615. return target.copy( _scissor );
  13616. };
  13617. this.setScissor = function ( x, y, width, height ) {
  13618. if ( x.isVector4 ) {
  13619. _scissor.set( x.x, x.y, x.z, x.w );
  13620. } else {
  13621. _scissor.set( x, y, width, height );
  13622. }
  13623. state.scissor( _currentScissor.copy( _scissor ).multiplyScalar( _pixelRatio ) );
  13624. };
  13625. this.getScissorTest = function () {
  13626. return _scissorTest;
  13627. };
  13628. this.setScissorTest = function ( boolean ) {
  13629. state.setScissorTest( _scissorTest = boolean );
  13630. };
  13631. // Clearing
  13632. this.getClearColor = function () {
  13633. return background.getClearColor();
  13634. };
  13635. this.setClearColor = function () {
  13636. background.setClearColor.apply( background, arguments );
  13637. };
  13638. this.getClearAlpha = function () {
  13639. return background.getClearAlpha();
  13640. };
  13641. this.setClearAlpha = function () {
  13642. background.setClearAlpha.apply( background, arguments );
  13643. };
  13644. this.clear = function ( color, depth, stencil ) {
  13645. var bits = 0;
  13646. if ( color === undefined || color ) bits |= 16384;
  13647. if ( depth === undefined || depth ) bits |= 256;
  13648. if ( stencil === undefined || stencil ) bits |= 1024;
  13649. _gl.clear( bits );
  13650. };
  13651. this.clearColor = function () {
  13652. this.clear( true, false, false );
  13653. };
  13654. this.clearDepth = function () {
  13655. this.clear( false, true, false );
  13656. };
  13657. this.clearStencil = function () {
  13658. this.clear( false, false, true );
  13659. };
  13660. //
  13661. this.dispose = function () {
  13662. _canvas.removeEventListener( 'webglcontextlost', onContextLost, false );
  13663. _canvas.removeEventListener( 'webglcontextrestored', onContextRestore, false );
  13664. renderLists.dispose();
  13665. renderStates.dispose();
  13666. properties.dispose();
  13667. objects.dispose();
  13668. vr.dispose();
  13669. animation.stop();
  13670. };
  13671. // Events
  13672. function onContextLost( event ) {
  13673. event.preventDefault();
  13674. console.log( 'THREE.WebGLRenderer: Context Lost.' );
  13675. _isContextLost = true;
  13676. }
  13677. function onContextRestore( /* event */ ) {
  13678. console.log( 'THREE.WebGLRenderer: Context Restored.' );
  13679. _isContextLost = false;
  13680. initGLContext();
  13681. }
  13682. function onMaterialDispose( event ) {
  13683. var material = event.target;
  13684. material.removeEventListener( 'dispose', onMaterialDispose );
  13685. deallocateMaterial( material );
  13686. }
  13687. // Buffer deallocation
  13688. function deallocateMaterial( material ) {
  13689. releaseMaterialProgramReference( material );
  13690. properties.remove( material );
  13691. }
  13692. function releaseMaterialProgramReference( material ) {
  13693. var programInfo = properties.get( material ).program;
  13694. material.program = undefined;
  13695. if ( programInfo !== undefined ) {
  13696. programCache.releaseProgram( programInfo );
  13697. }
  13698. }
  13699. // Buffer rendering
  13700. function renderObjectImmediate( object, program ) {
  13701. object.render( function ( object ) {
  13702. _this.renderBufferImmediate( object, program );
  13703. } );
  13704. }
  13705. this.renderBufferImmediate = function ( object, program ) {
  13706. state.initAttributes();
  13707. var buffers = properties.get( object );
  13708. if ( object.hasPositions && ! buffers.position ) buffers.position = _gl.createBuffer();
  13709. if ( object.hasNormals && ! buffers.normal ) buffers.normal = _gl.createBuffer();
  13710. if ( object.hasUvs && ! buffers.uv ) buffers.uv = _gl.createBuffer();
  13711. if ( object.hasColors && ! buffers.color ) buffers.color = _gl.createBuffer();
  13712. var programAttributes = program.getAttributes();
  13713. if ( object.hasPositions ) {
  13714. _gl.bindBuffer( 34962, buffers.position );
  13715. _gl.bufferData( 34962, object.positionArray, 35048 );
  13716. state.enableAttribute( programAttributes.position );
  13717. _gl.vertexAttribPointer( programAttributes.position, 3, 5126, false, 0, 0 );
  13718. }
  13719. if ( object.hasNormals ) {
  13720. _gl.bindBuffer( 34962, buffers.normal );
  13721. _gl.bufferData( 34962, object.normalArray, 35048 );
  13722. state.enableAttribute( programAttributes.normal );
  13723. _gl.vertexAttribPointer( programAttributes.normal, 3, 5126, false, 0, 0 );
  13724. }
  13725. if ( object.hasUvs ) {
  13726. _gl.bindBuffer( 34962, buffers.uv );
  13727. _gl.bufferData( 34962, object.uvArray, 35048 );
  13728. state.enableAttribute( programAttributes.uv );
  13729. _gl.vertexAttribPointer( programAttributes.uv, 2, 5126, false, 0, 0 );
  13730. }
  13731. if ( object.hasColors ) {
  13732. _gl.bindBuffer( 34962, buffers.color );
  13733. _gl.bufferData( 34962, object.colorArray, 35048 );
  13734. state.enableAttribute( programAttributes.color );
  13735. _gl.vertexAttribPointer( programAttributes.color, 3, 5126, false, 0, 0 );
  13736. }
  13737. state.disableUnusedAttributes();
  13738. _gl.drawArrays( 4, 0, object.count );
  13739. object.count = 0;
  13740. };
  13741. this.renderBufferDirect = function ( camera, fog, geometry, material, object, group ) {
  13742. var frontFaceCW = ( object.isMesh && object.matrixWorld.determinant() < 0 );
  13743. state.setMaterial( material, frontFaceCW );
  13744. var program = setProgram( camera, fog, material, object );
  13745. var updateBuffers = false;
  13746. if ( _currentGeometryProgram.geometry !== geometry.id ||
  13747. _currentGeometryProgram.program !== program.id ||
  13748. _currentGeometryProgram.wireframe !== ( material.wireframe === true ) ) {
  13749. _currentGeometryProgram.geometry = geometry.id;
  13750. _currentGeometryProgram.program = program.id;
  13751. _currentGeometryProgram.wireframe = material.wireframe === true;
  13752. updateBuffers = true;
  13753. }
  13754. if ( object.morphTargetInfluences ) {
  13755. morphtargets.update( object, geometry, material, program );
  13756. updateBuffers = true;
  13757. }
  13758. //
  13759. var index = geometry.index;
  13760. var position = geometry.attributes.position;
  13761. var rangeFactor = 1;
  13762. if ( material.wireframe === true ) {
  13763. index = geometries.getWireframeAttribute( geometry );
  13764. rangeFactor = 2;
  13765. }
  13766. var attribute;
  13767. var renderer = bufferRenderer;
  13768. if ( index !== null ) {
  13769. attribute = attributes.get( index );
  13770. renderer = indexedBufferRenderer;
  13771. renderer.setIndex( attribute );
  13772. }
  13773. if ( updateBuffers ) {
  13774. setupVertexAttributes( material, program, geometry );
  13775. if ( index !== null ) {
  13776. _gl.bindBuffer( 34963, attribute.buffer );
  13777. }
  13778. }
  13779. //
  13780. var dataCount = Infinity;
  13781. if ( index !== null ) {
  13782. dataCount = index.count;
  13783. } else if ( position !== undefined ) {
  13784. dataCount = position.count;
  13785. }
  13786. var rangeStart = geometry.drawRange.start * rangeFactor;
  13787. var rangeCount = geometry.drawRange.count * rangeFactor;
  13788. var groupStart = group !== null ? group.start * rangeFactor : 0;
  13789. var groupCount = group !== null ? group.count * rangeFactor : Infinity;
  13790. var drawStart = Math.max( rangeStart, groupStart );
  13791. var drawEnd = Math.min( dataCount, rangeStart + rangeCount, groupStart + groupCount ) - 1;
  13792. var drawCount = Math.max( 0, drawEnd - drawStart + 1 );
  13793. if ( drawCount === 0 ) return;
  13794. //
  13795. if ( object.isMesh ) {
  13796. if ( material.wireframe === true ) {
  13797. state.setLineWidth( material.wireframeLinewidth * getTargetPixelRatio() );
  13798. renderer.setMode( 1 );
  13799. } else {
  13800. switch ( object.drawMode ) {
  13801. case TrianglesDrawMode:
  13802. renderer.setMode( 4 );
  13803. break;
  13804. case TriangleStripDrawMode:
  13805. renderer.setMode( 5 );
  13806. break;
  13807. case TriangleFanDrawMode:
  13808. renderer.setMode( 6 );
  13809. break;
  13810. }
  13811. }
  13812. } else if ( object.isLine ) {
  13813. var lineWidth = material.linewidth;
  13814. if ( lineWidth === undefined ) lineWidth = 1; // Not using Line*Material
  13815. state.setLineWidth( lineWidth * getTargetPixelRatio() );
  13816. if ( object.isLineSegments ) {
  13817. renderer.setMode( 1 );
  13818. } else if ( object.isLineLoop ) {
  13819. renderer.setMode( 2 );
  13820. } else {
  13821. renderer.setMode( 3 );
  13822. }
  13823. } else if ( object.isPoints ) {
  13824. renderer.setMode( 0 );
  13825. } else if ( object.isSprite ) {
  13826. renderer.setMode( 4 );
  13827. }
  13828. if ( geometry && geometry.isInstancedBufferGeometry ) {
  13829. if ( geometry.maxInstancedCount > 0 ) {
  13830. renderer.renderInstances( geometry, drawStart, drawCount );
  13831. }
  13832. } else {
  13833. renderer.render( drawStart, drawCount );
  13834. }
  13835. };
  13836. function setupVertexAttributes( material, program, geometry ) {
  13837. if ( geometry && geometry.isInstancedBufferGeometry && ! capabilities.isWebGL2 ) {
  13838. if ( extensions.get( 'ANGLE_instanced_arrays' ) === null ) {
  13839. console.error( 'THREE.WebGLRenderer.setupVertexAttributes: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  13840. return;
  13841. }
  13842. }
  13843. state.initAttributes();
  13844. var geometryAttributes = geometry.attributes;
  13845. var programAttributes = program.getAttributes();
  13846. var materialDefaultAttributeValues = material.defaultAttributeValues;
  13847. for ( var name in programAttributes ) {
  13848. var programAttribute = programAttributes[ name ];
  13849. if ( programAttribute >= 0 ) {
  13850. var geometryAttribute = geometryAttributes[ name ];
  13851. if ( geometryAttribute !== undefined ) {
  13852. var normalized = geometryAttribute.normalized;
  13853. var size = geometryAttribute.itemSize;
  13854. var attribute = attributes.get( geometryAttribute );
  13855. // TODO Attribute may not be available on context restore
  13856. if ( attribute === undefined ) continue;
  13857. var buffer = attribute.buffer;
  13858. var type = attribute.type;
  13859. var bytesPerElement = attribute.bytesPerElement;
  13860. if ( geometryAttribute.isInterleavedBufferAttribute ) {
  13861. var data = geometryAttribute.data;
  13862. var stride = data.stride;
  13863. var offset = geometryAttribute.offset;
  13864. if ( data && data.isInstancedInterleavedBuffer ) {
  13865. state.enableAttributeAndDivisor( programAttribute, data.meshPerAttribute );
  13866. if ( geometry.maxInstancedCount === undefined ) {
  13867. geometry.maxInstancedCount = data.meshPerAttribute * data.count;
  13868. }
  13869. } else {
  13870. state.enableAttribute( programAttribute );
  13871. }
  13872. _gl.bindBuffer( 34962, buffer );
  13873. _gl.vertexAttribPointer( programAttribute, size, type, normalized, stride * bytesPerElement, offset * bytesPerElement );
  13874. } else {
  13875. if ( geometryAttribute.isInstancedBufferAttribute ) {
  13876. state.enableAttributeAndDivisor( programAttribute, geometryAttribute.meshPerAttribute );
  13877. if ( geometry.maxInstancedCount === undefined ) {
  13878. geometry.maxInstancedCount = geometryAttribute.meshPerAttribute * geometryAttribute.count;
  13879. }
  13880. } else {
  13881. state.enableAttribute( programAttribute );
  13882. }
  13883. _gl.bindBuffer( 34962, buffer );
  13884. _gl.vertexAttribPointer( programAttribute, size, type, normalized, 0, 0 );
  13885. }
  13886. } else if ( materialDefaultAttributeValues !== undefined ) {
  13887. var value = materialDefaultAttributeValues[ name ];
  13888. if ( value !== undefined ) {
  13889. switch ( value.length ) {
  13890. case 2:
  13891. _gl.vertexAttrib2fv( programAttribute, value );
  13892. break;
  13893. case 3:
  13894. _gl.vertexAttrib3fv( programAttribute, value );
  13895. break;
  13896. case 4:
  13897. _gl.vertexAttrib4fv( programAttribute, value );
  13898. break;
  13899. default:
  13900. _gl.vertexAttrib1fv( programAttribute, value );
  13901. }
  13902. }
  13903. }
  13904. }
  13905. }
  13906. state.disableUnusedAttributes();
  13907. }
  13908. // Compile
  13909. this.compile = function ( scene, camera ) {
  13910. currentRenderState = renderStates.get( scene, camera );
  13911. currentRenderState.init();
  13912. scene.traverse( function ( object ) {
  13913. if ( object.isLight ) {
  13914. currentRenderState.pushLight( object );
  13915. if ( object.castShadow ) {
  13916. currentRenderState.pushShadow( object );
  13917. }
  13918. }
  13919. } );
  13920. currentRenderState.setupLights( camera );
  13921. scene.traverse( function ( object ) {
  13922. if ( object.material ) {
  13923. if ( Array.isArray( object.material ) ) {
  13924. for ( var i = 0; i < object.material.length; i ++ ) {
  13925. initMaterial( object.material[ i ], scene.fog, object );
  13926. }
  13927. } else {
  13928. initMaterial( object.material, scene.fog, object );
  13929. }
  13930. }
  13931. } );
  13932. };
  13933. // Animation Loop
  13934. var onAnimationFrameCallback = null;
  13935. function onAnimationFrame( time ) {
  13936. if ( vr.isPresenting() ) return;
  13937. if ( onAnimationFrameCallback ) onAnimationFrameCallback( time );
  13938. }
  13939. var animation = new WebGLAnimation();
  13940. animation.setAnimationLoop( onAnimationFrame );
  13941. if ( typeof window !== 'undefined' ) animation.setContext( window );
  13942. this.setAnimationLoop = function ( callback ) {
  13943. onAnimationFrameCallback = callback;
  13944. vr.setAnimationLoop( callback );
  13945. animation.start();
  13946. };
  13947. // Rendering
  13948. this.render = function ( scene, camera ) {
  13949. var renderTarget, forceClear;
  13950. if ( arguments[ 2 ] !== undefined ) {
  13951. console.warn( 'THREE.WebGLRenderer.render(): the renderTarget argument has been removed. Use .setRenderTarget() instead.' );
  13952. renderTarget = arguments[ 2 ];
  13953. }
  13954. if ( arguments[ 3 ] !== undefined ) {
  13955. console.warn( 'THREE.WebGLRenderer.render(): the forceClear argument has been removed. Use .clear() instead.' );
  13956. forceClear = arguments[ 3 ];
  13957. }
  13958. if ( ! ( camera && camera.isCamera ) ) {
  13959. console.error( 'THREE.WebGLRenderer.render: camera is not an instance of THREE.Camera.' );
  13960. return;
  13961. }
  13962. if ( _isContextLost ) return;
  13963. // reset caching for this frame
  13964. _currentGeometryProgram.geometry = null;
  13965. _currentGeometryProgram.program = null;
  13966. _currentGeometryProgram.wireframe = false;
  13967. _currentMaterialId = - 1;
  13968. _currentCamera = null;
  13969. // update scene graph
  13970. if ( scene.autoUpdate === true ) scene.updateMatrixWorld();
  13971. // update camera matrices and frustum
  13972. if ( camera.parent === null ) camera.updateMatrixWorld();
  13973. if ( vr.enabled ) {
  13974. camera = vr.getCamera( camera );
  13975. }
  13976. //
  13977. currentRenderState = renderStates.get( scene, camera );
  13978. currentRenderState.init();
  13979. scene.onBeforeRender( _this, scene, camera, renderTarget || _currentRenderTarget );
  13980. _projScreenMatrix.multiplyMatrices( camera.projectionMatrix, camera.matrixWorldInverse );
  13981. _frustum.setFromMatrix( _projScreenMatrix );
  13982. _localClippingEnabled = this.localClippingEnabled;
  13983. _clippingEnabled = _clipping.init( this.clippingPlanes, _localClippingEnabled, camera );
  13984. currentRenderList = renderLists.get( scene, camera );
  13985. currentRenderList.init();
  13986. projectObject( scene, camera, 0, _this.sortObjects );
  13987. if ( _this.sortObjects === true ) {
  13988. currentRenderList.sort();
  13989. }
  13990. //
  13991. if ( _clippingEnabled ) _clipping.beginShadows();
  13992. var shadowsArray = currentRenderState.state.shadowsArray;
  13993. shadowMap.render( shadowsArray, scene, camera );
  13994. currentRenderState.setupLights( camera );
  13995. if ( _clippingEnabled ) _clipping.endShadows();
  13996. //
  13997. if ( this.info.autoReset ) this.info.reset();
  13998. if ( renderTarget !== undefined ) {
  13999. this.setRenderTarget( renderTarget );
  14000. }
  14001. //
  14002. background.render( currentRenderList, scene, camera, forceClear );
  14003. // render scene
  14004. var opaqueObjects = currentRenderList.opaque;
  14005. var transparentObjects = currentRenderList.transparent;
  14006. if ( scene.overrideMaterial ) {
  14007. var overrideMaterial = scene.overrideMaterial;
  14008. if ( opaqueObjects.length ) renderObjects( opaqueObjects, scene, camera, overrideMaterial );
  14009. if ( transparentObjects.length ) renderObjects( transparentObjects, scene, camera, overrideMaterial );
  14010. } else {
  14011. // opaque pass (front-to-back order)
  14012. if ( opaqueObjects.length ) renderObjects( opaqueObjects, scene, camera );
  14013. // transparent pass (back-to-front order)
  14014. if ( transparentObjects.length ) renderObjects( transparentObjects, scene, camera );
  14015. }
  14016. //
  14017. if ( _currentRenderTarget !== null ) {
  14018. // Generate mipmap if we're using any kind of mipmap filtering
  14019. textures.updateRenderTargetMipmap( _currentRenderTarget );
  14020. // resolve multisample renderbuffers to a single-sample texture if necessary
  14021. textures.updateMultisampleRenderTarget( _currentRenderTarget );
  14022. }
  14023. // Ensure depth buffer writing is enabled so it can be cleared on next render
  14024. state.buffers.depth.setTest( true );
  14025. state.buffers.depth.setMask( true );
  14026. state.buffers.color.setMask( true );
  14027. state.setPolygonOffset( false );
  14028. scene.onAfterRender( _this, scene, camera );
  14029. if ( vr.enabled ) {
  14030. vr.submitFrame();
  14031. }
  14032. // _gl.finish();
  14033. currentRenderList = null;
  14034. currentRenderState = null;
  14035. };
  14036. function projectObject( object, camera, groupOrder, sortObjects ) {
  14037. if ( object.visible === false ) return;
  14038. var visible = object.layers.test( camera.layers );
  14039. if ( visible ) {
  14040. if ( object.isGroup ) {
  14041. groupOrder = object.renderOrder;
  14042. } else if ( object.isLight ) {
  14043. currentRenderState.pushLight( object );
  14044. if ( object.castShadow ) {
  14045. currentRenderState.pushShadow( object );
  14046. }
  14047. } else if ( object.isSprite ) {
  14048. if ( ! object.frustumCulled || _frustum.intersectsSprite( object ) ) {
  14049. if ( sortObjects ) {
  14050. _vector3.setFromMatrixPosition( object.matrixWorld )
  14051. .applyMatrix4( _projScreenMatrix );
  14052. }
  14053. var geometry = objects.update( object );
  14054. var material = object.material;
  14055. currentRenderList.push( object, geometry, material, groupOrder, _vector3.z, null );
  14056. }
  14057. } else if ( object.isImmediateRenderObject ) {
  14058. if ( sortObjects ) {
  14059. _vector3.setFromMatrixPosition( object.matrixWorld )
  14060. .applyMatrix4( _projScreenMatrix );
  14061. }
  14062. currentRenderList.push( object, null, object.material, groupOrder, _vector3.z, null );
  14063. } else if ( object.isMesh || object.isLine || object.isPoints ) {
  14064. if ( object.isSkinnedMesh ) {
  14065. object.skeleton.update();
  14066. }
  14067. if ( ! object.frustumCulled || _frustum.intersectsObject( object ) ) {
  14068. if ( sortObjects ) {
  14069. _vector3.setFromMatrixPosition( object.matrixWorld )
  14070. .applyMatrix4( _projScreenMatrix );
  14071. }
  14072. var geometry = objects.update( object );
  14073. var material = object.material;
  14074. if ( Array.isArray( material ) ) {
  14075. var groups = geometry.groups;
  14076. for ( var i = 0, l = groups.length; i < l; i ++ ) {
  14077. var group = groups[ i ];
  14078. var groupMaterial = material[ group.materialIndex ];
  14079. if ( groupMaterial && groupMaterial.visible ) {
  14080. currentRenderList.push( object, geometry, groupMaterial, groupOrder, _vector3.z, group );
  14081. }
  14082. }
  14083. } else if ( material.visible ) {
  14084. currentRenderList.push( object, geometry, material, groupOrder, _vector3.z, null );
  14085. }
  14086. }
  14087. }
  14088. }
  14089. var children = object.children;
  14090. for ( var i = 0, l = children.length; i < l; i ++ ) {
  14091. projectObject( children[ i ], camera, groupOrder, sortObjects );
  14092. }
  14093. }
  14094. function renderObjects( renderList, scene, camera, overrideMaterial ) {
  14095. for ( var i = 0, l = renderList.length; i < l; i ++ ) {
  14096. var renderItem = renderList[ i ];
  14097. var object = renderItem.object;
  14098. var geometry = renderItem.geometry;
  14099. var material = overrideMaterial === undefined ? renderItem.material : overrideMaterial;
  14100. var group = renderItem.group;
  14101. if ( camera.isArrayCamera ) {
  14102. _currentArrayCamera = camera;
  14103. var cameras = camera.cameras;
  14104. for ( var j = 0, jl = cameras.length; j < jl; j ++ ) {
  14105. var camera2 = cameras[ j ];
  14106. if ( object.layers.test( camera2.layers ) ) {
  14107. if ( 'viewport' in camera2 ) { // XR
  14108. state.viewport( _currentViewport.copy( camera2.viewport ) );
  14109. } else {
  14110. var bounds = camera2.bounds;
  14111. var x = bounds.x * _width;
  14112. var y = bounds.y * _height;
  14113. var width = bounds.z * _width;
  14114. var height = bounds.w * _height;
  14115. state.viewport( _currentViewport.set( x, y, width, height ).multiplyScalar( _pixelRatio ) );
  14116. }
  14117. currentRenderState.setupLights( camera2 );
  14118. renderObject( object, scene, camera2, geometry, material, group );
  14119. }
  14120. }
  14121. } else {
  14122. _currentArrayCamera = null;
  14123. renderObject( object, scene, camera, geometry, material, group );
  14124. }
  14125. }
  14126. }
  14127. function renderObject( object, scene, camera, geometry, material, group ) {
  14128. object.onBeforeRender( _this, scene, camera, geometry, material, group );
  14129. currentRenderState = renderStates.get( scene, _currentArrayCamera || camera );
  14130. object.modelViewMatrix.multiplyMatrices( camera.matrixWorldInverse, object.matrixWorld );
  14131. object.normalMatrix.getNormalMatrix( object.modelViewMatrix );
  14132. if ( object.isImmediateRenderObject ) {
  14133. state.setMaterial( material );
  14134. var program = setProgram( camera, scene.fog, material, object );
  14135. _currentGeometryProgram.geometry = null;
  14136. _currentGeometryProgram.program = null;
  14137. _currentGeometryProgram.wireframe = false;
  14138. renderObjectImmediate( object, program );
  14139. } else {
  14140. _this.renderBufferDirect( camera, scene.fog, geometry, material, object, group );
  14141. }
  14142. object.onAfterRender( _this, scene, camera, geometry, material, group );
  14143. currentRenderState = renderStates.get( scene, _currentArrayCamera || camera );
  14144. }
  14145. function initMaterial( material, fog, object ) {
  14146. var materialProperties = properties.get( material );
  14147. var lights = currentRenderState.state.lights;
  14148. var shadowsArray = currentRenderState.state.shadowsArray;
  14149. var lightsHash = materialProperties.lightsHash;
  14150. var lightsStateHash = lights.state.hash;
  14151. var parameters = programCache.getParameters(
  14152. material, lights.state, shadowsArray, fog, _clipping.numPlanes, _clipping.numIntersection, object );
  14153. var code = programCache.getProgramCode( material, parameters );
  14154. var program = materialProperties.program;
  14155. var programChange = true;
  14156. if ( program === undefined ) {
  14157. // new material
  14158. material.addEventListener( 'dispose', onMaterialDispose );
  14159. } else if ( program.code !== code ) {
  14160. // changed glsl or parameters
  14161. releaseMaterialProgramReference( material );
  14162. } else if ( lightsHash.stateID !== lightsStateHash.stateID ||
  14163. lightsHash.directionalLength !== lightsStateHash.directionalLength ||
  14164. lightsHash.pointLength !== lightsStateHash.pointLength ||
  14165. lightsHash.spotLength !== lightsStateHash.spotLength ||
  14166. lightsHash.rectAreaLength !== lightsStateHash.rectAreaLength ||
  14167. lightsHash.hemiLength !== lightsStateHash.hemiLength ||
  14168. lightsHash.shadowsLength !== lightsStateHash.shadowsLength ) {
  14169. lightsHash.stateID = lightsStateHash.stateID;
  14170. lightsHash.directionalLength = lightsStateHash.directionalLength;
  14171. lightsHash.pointLength = lightsStateHash.pointLength;
  14172. lightsHash.spotLength = lightsStateHash.spotLength;
  14173. lightsHash.rectAreaLength = lightsStateHash.rectAreaLength;
  14174. lightsHash.hemiLength = lightsStateHash.hemiLength;
  14175. lightsHash.shadowsLength = lightsStateHash.shadowsLength;
  14176. programChange = false;
  14177. } else if ( parameters.shaderID !== undefined ) {
  14178. // same glsl and uniform list
  14179. return;
  14180. } else {
  14181. // only rebuild uniform list
  14182. programChange = false;
  14183. }
  14184. if ( programChange ) {
  14185. if ( parameters.shaderID ) {
  14186. var shader = ShaderLib[ parameters.shaderID ];
  14187. materialProperties.shader = {
  14188. name: material.type,
  14189. uniforms: cloneUniforms( shader.uniforms ),
  14190. vertexShader: shader.vertexShader,
  14191. fragmentShader: shader.fragmentShader
  14192. };
  14193. } else {
  14194. materialProperties.shader = {
  14195. name: material.type,
  14196. uniforms: material.uniforms,
  14197. vertexShader: material.vertexShader,
  14198. fragmentShader: material.fragmentShader
  14199. };
  14200. }
  14201. material.onBeforeCompile( materialProperties.shader, _this );
  14202. // Computing code again as onBeforeCompile may have changed the shaders
  14203. code = programCache.getProgramCode( material, parameters );
  14204. program = programCache.acquireProgram( material, materialProperties.shader, parameters, code );
  14205. materialProperties.program = program;
  14206. material.program = program;
  14207. }
  14208. var programAttributes = program.getAttributes();
  14209. if ( material.morphTargets ) {
  14210. material.numSupportedMorphTargets = 0;
  14211. for ( var i = 0; i < _this.maxMorphTargets; i ++ ) {
  14212. if ( programAttributes[ 'morphTarget' + i ] >= 0 ) {
  14213. material.numSupportedMorphTargets ++;
  14214. }
  14215. }
  14216. }
  14217. if ( material.morphNormals ) {
  14218. material.numSupportedMorphNormals = 0;
  14219. for ( var i = 0; i < _this.maxMorphNormals; i ++ ) {
  14220. if ( programAttributes[ 'morphNormal' + i ] >= 0 ) {
  14221. material.numSupportedMorphNormals ++;
  14222. }
  14223. }
  14224. }
  14225. var uniforms = materialProperties.shader.uniforms;
  14226. if ( ! material.isShaderMaterial &&
  14227. ! material.isRawShaderMaterial ||
  14228. material.clipping === true ) {
  14229. materialProperties.numClippingPlanes = _clipping.numPlanes;
  14230. materialProperties.numIntersection = _clipping.numIntersection;
  14231. uniforms.clippingPlanes = _clipping.uniform;
  14232. }
  14233. materialProperties.fog = fog;
  14234. // store the light setup it was created for
  14235. if ( lightsHash === undefined ) {
  14236. materialProperties.lightsHash = lightsHash = {};
  14237. }
  14238. lightsHash.stateID = lightsStateHash.stateID;
  14239. lightsHash.directionalLength = lightsStateHash.directionalLength;
  14240. lightsHash.pointLength = lightsStateHash.pointLength;
  14241. lightsHash.spotLength = lightsStateHash.spotLength;
  14242. lightsHash.rectAreaLength = lightsStateHash.rectAreaLength;
  14243. lightsHash.hemiLength = lightsStateHash.hemiLength;
  14244. lightsHash.shadowsLength = lightsStateHash.shadowsLength;
  14245. if ( material.lights ) {
  14246. // wire up the material to this renderer's lighting state
  14247. uniforms.ambientLightColor.value = lights.state.ambient;
  14248. uniforms.directionalLights.value = lights.state.directional;
  14249. uniforms.spotLights.value = lights.state.spot;
  14250. uniforms.rectAreaLights.value = lights.state.rectArea;
  14251. uniforms.pointLights.value = lights.state.point;
  14252. uniforms.hemisphereLights.value = lights.state.hemi;
  14253. uniforms.directionalShadowMap.value = lights.state.directionalShadowMap;
  14254. uniforms.directionalShadowMatrix.value = lights.state.directionalShadowMatrix;
  14255. uniforms.spotShadowMap.value = lights.state.spotShadowMap;
  14256. uniforms.spotShadowMatrix.value = lights.state.spotShadowMatrix;
  14257. uniforms.pointShadowMap.value = lights.state.pointShadowMap;
  14258. uniforms.pointShadowMatrix.value = lights.state.pointShadowMatrix;
  14259. // TODO (abelnation): add area lights shadow info to uniforms
  14260. }
  14261. var progUniforms = materialProperties.program.getUniforms(),
  14262. uniformsList =
  14263. WebGLUniforms.seqWithValue( progUniforms.seq, uniforms );
  14264. materialProperties.uniformsList = uniformsList;
  14265. }
  14266. function setProgram( camera, fog, material, object ) {
  14267. _usedTextureUnits = 0;
  14268. var materialProperties = properties.get( material );
  14269. var lights = currentRenderState.state.lights;
  14270. var lightsHash = materialProperties.lightsHash;
  14271. var lightsStateHash = lights.state.hash;
  14272. if ( _clippingEnabled ) {
  14273. if ( _localClippingEnabled || camera !== _currentCamera ) {
  14274. var useCache =
  14275. camera === _currentCamera &&
  14276. material.id === _currentMaterialId;
  14277. // we might want to call this function with some ClippingGroup
  14278. // object instead of the material, once it becomes feasible
  14279. // (#8465, #8379)
  14280. _clipping.setState(
  14281. material.clippingPlanes, material.clipIntersection, material.clipShadows,
  14282. camera, materialProperties, useCache );
  14283. }
  14284. }
  14285. if ( material.needsUpdate === false ) {
  14286. if ( materialProperties.program === undefined ) {
  14287. material.needsUpdate = true;
  14288. } else if ( material.fog && materialProperties.fog !== fog ) {
  14289. material.needsUpdate = true;
  14290. } else if ( material.lights && ( lightsHash.stateID !== lightsStateHash.stateID ||
  14291. lightsHash.directionalLength !== lightsStateHash.directionalLength ||
  14292. lightsHash.pointLength !== lightsStateHash.pointLength ||
  14293. lightsHash.spotLength !== lightsStateHash.spotLength ||
  14294. lightsHash.rectAreaLength !== lightsStateHash.rectAreaLength ||
  14295. lightsHash.hemiLength !== lightsStateHash.hemiLength ||
  14296. lightsHash.shadowsLength !== lightsStateHash.shadowsLength ) ) {
  14297. material.needsUpdate = true;
  14298. } else if ( materialProperties.numClippingPlanes !== undefined &&
  14299. ( materialProperties.numClippingPlanes !== _clipping.numPlanes ||
  14300. materialProperties.numIntersection !== _clipping.numIntersection ) ) {
  14301. material.needsUpdate = true;
  14302. }
  14303. }
  14304. if ( material.needsUpdate ) {
  14305. initMaterial( material, fog, object );
  14306. material.needsUpdate = false;
  14307. }
  14308. var refreshProgram = false;
  14309. var refreshMaterial = false;
  14310. var refreshLights = false;
  14311. var program = materialProperties.program,
  14312. p_uniforms = program.getUniforms(),
  14313. m_uniforms = materialProperties.shader.uniforms;
  14314. if ( state.useProgram( program.program ) ) {
  14315. refreshProgram = true;
  14316. refreshMaterial = true;
  14317. refreshLights = true;
  14318. }
  14319. if ( material.id !== _currentMaterialId ) {
  14320. _currentMaterialId = material.id;
  14321. refreshMaterial = true;
  14322. }
  14323. if ( refreshProgram || _currentCamera !== camera ) {
  14324. p_uniforms.setValue( _gl, 'projectionMatrix', camera.projectionMatrix );
  14325. if ( capabilities.logarithmicDepthBuffer ) {
  14326. p_uniforms.setValue( _gl, 'logDepthBufFC',
  14327. 2.0 / ( Math.log( camera.far + 1.0 ) / Math.LN2 ) );
  14328. }
  14329. if ( _currentCamera !== camera ) {
  14330. _currentCamera = camera;
  14331. // lighting uniforms depend on the camera so enforce an update
  14332. // now, in case this material supports lights - or later, when
  14333. // the next material that does gets activated:
  14334. refreshMaterial = true; // set to true on material change
  14335. refreshLights = true; // remains set until update done
  14336. }
  14337. // load material specific uniforms
  14338. // (shader material also gets them for the sake of genericity)
  14339. if ( material.isShaderMaterial ||
  14340. material.isMeshPhongMaterial ||
  14341. material.isMeshStandardMaterial ||
  14342. material.envMap ) {
  14343. var uCamPos = p_uniforms.map.cameraPosition;
  14344. if ( uCamPos !== undefined ) {
  14345. uCamPos.setValue( _gl,
  14346. _vector3.setFromMatrixPosition( camera.matrixWorld ) );
  14347. }
  14348. }
  14349. if ( material.isMeshPhongMaterial ||
  14350. material.isMeshLambertMaterial ||
  14351. material.isMeshBasicMaterial ||
  14352. material.isMeshStandardMaterial ||
  14353. material.isShaderMaterial ||
  14354. material.skinning ) {
  14355. p_uniforms.setValue( _gl, 'viewMatrix', camera.matrixWorldInverse );
  14356. }
  14357. }
  14358. // skinning uniforms must be set even if material didn't change
  14359. // auto-setting of texture unit for bone texture must go before other textures
  14360. // not sure why, but otherwise weird things happen
  14361. if ( material.skinning ) {
  14362. p_uniforms.setOptional( _gl, object, 'bindMatrix' );
  14363. p_uniforms.setOptional( _gl, object, 'bindMatrixInverse' );
  14364. var skeleton = object.skeleton;
  14365. if ( skeleton ) {
  14366. var bones = skeleton.bones;
  14367. if ( capabilities.floatVertexTextures ) {
  14368. if ( skeleton.boneTexture === undefined ) {
  14369. // layout (1 matrix = 4 pixels)
  14370. // RGBA RGBA RGBA RGBA (=> column1, column2, column3, column4)
  14371. // with 8x8 pixel texture max 16 bones * 4 pixels = (8 * 8)
  14372. // 16x16 pixel texture max 64 bones * 4 pixels = (16 * 16)
  14373. // 32x32 pixel texture max 256 bones * 4 pixels = (32 * 32)
  14374. // 64x64 pixel texture max 1024 bones * 4 pixels = (64 * 64)
  14375. var size = Math.sqrt( bones.length * 4 ); // 4 pixels needed for 1 matrix
  14376. size = _Math.ceilPowerOfTwo( size );
  14377. size = Math.max( size, 4 );
  14378. var boneMatrices = new Float32Array( size * size * 4 ); // 4 floats per RGBA pixel
  14379. boneMatrices.set( skeleton.boneMatrices ); // copy current values
  14380. var boneTexture = new DataTexture( boneMatrices, size, size, RGBAFormat, FloatType );
  14381. boneTexture.needsUpdate = true;
  14382. skeleton.boneMatrices = boneMatrices;
  14383. skeleton.boneTexture = boneTexture;
  14384. skeleton.boneTextureSize = size;
  14385. }
  14386. p_uniforms.setValue( _gl, 'boneTexture', skeleton.boneTexture );
  14387. p_uniforms.setValue( _gl, 'boneTextureSize', skeleton.boneTextureSize );
  14388. } else {
  14389. p_uniforms.setOptional( _gl, skeleton, 'boneMatrices' );
  14390. }
  14391. }
  14392. }
  14393. if ( refreshMaterial ) {
  14394. p_uniforms.setValue( _gl, 'toneMappingExposure', _this.toneMappingExposure );
  14395. p_uniforms.setValue( _gl, 'toneMappingWhitePoint', _this.toneMappingWhitePoint );
  14396. if ( material.lights ) {
  14397. // the current material requires lighting info
  14398. // note: all lighting uniforms are always set correctly
  14399. // they simply reference the renderer's state for their
  14400. // values
  14401. //
  14402. // use the current material's .needsUpdate flags to set
  14403. // the GL state when required
  14404. markUniformsLightsNeedsUpdate( m_uniforms, refreshLights );
  14405. }
  14406. // refresh uniforms common to several materials
  14407. if ( fog && material.fog ) {
  14408. refreshUniformsFog( m_uniforms, fog );
  14409. }
  14410. if ( material.isMeshBasicMaterial ) {
  14411. refreshUniformsCommon( m_uniforms, material );
  14412. } else if ( material.isMeshLambertMaterial ) {
  14413. refreshUniformsCommon( m_uniforms, material );
  14414. refreshUniformsLambert( m_uniforms, material );
  14415. } else if ( material.isMeshPhongMaterial ) {
  14416. refreshUniformsCommon( m_uniforms, material );
  14417. if ( material.isMeshToonMaterial ) {
  14418. refreshUniformsToon( m_uniforms, material );
  14419. } else {
  14420. refreshUniformsPhong( m_uniforms, material );
  14421. }
  14422. } else if ( material.isMeshStandardMaterial ) {
  14423. refreshUniformsCommon( m_uniforms, material );
  14424. if ( material.isMeshPhysicalMaterial ) {
  14425. refreshUniformsPhysical( m_uniforms, material );
  14426. } else {
  14427. refreshUniformsStandard( m_uniforms, material );
  14428. }
  14429. } else if ( material.isMeshMatcapMaterial ) {
  14430. refreshUniformsCommon( m_uniforms, material );
  14431. refreshUniformsMatcap( m_uniforms, material );
  14432. } else if ( material.isMeshDepthMaterial ) {
  14433. refreshUniformsCommon( m_uniforms, material );
  14434. refreshUniformsDepth( m_uniforms, material );
  14435. } else if ( material.isMeshDistanceMaterial ) {
  14436. refreshUniformsCommon( m_uniforms, material );
  14437. refreshUniformsDistance( m_uniforms, material );
  14438. } else if ( material.isMeshNormalMaterial ) {
  14439. refreshUniformsCommon( m_uniforms, material );
  14440. refreshUniformsNormal( m_uniforms, material );
  14441. } else if ( material.isLineBasicMaterial ) {
  14442. refreshUniformsLine( m_uniforms, material );
  14443. if ( material.isLineDashedMaterial ) {
  14444. refreshUniformsDash( m_uniforms, material );
  14445. }
  14446. } else if ( material.isPointsMaterial ) {
  14447. refreshUniformsPoints( m_uniforms, material );
  14448. } else if ( material.isSpriteMaterial ) {
  14449. refreshUniformsSprites( m_uniforms, material );
  14450. } else if ( material.isShadowMaterial ) {
  14451. m_uniforms.color.value = material.color;
  14452. m_uniforms.opacity.value = material.opacity;
  14453. }
  14454. // RectAreaLight Texture
  14455. // TODO (mrdoob): Find a nicer implementation
  14456. if ( m_uniforms.ltc_1 !== undefined ) m_uniforms.ltc_1.value = UniformsLib.LTC_1;
  14457. if ( m_uniforms.ltc_2 !== undefined ) m_uniforms.ltc_2.value = UniformsLib.LTC_2;
  14458. WebGLUniforms.upload( _gl, materialProperties.uniformsList, m_uniforms, _this );
  14459. }
  14460. if ( material.isShaderMaterial && material.uniformsNeedUpdate === true ) {
  14461. WebGLUniforms.upload( _gl, materialProperties.uniformsList, m_uniforms, _this );
  14462. material.uniformsNeedUpdate = false;
  14463. }
  14464. if ( material.isSpriteMaterial ) {
  14465. p_uniforms.setValue( _gl, 'center', object.center );
  14466. }
  14467. // common matrices
  14468. p_uniforms.setValue( _gl, 'modelViewMatrix', object.modelViewMatrix );
  14469. p_uniforms.setValue( _gl, 'normalMatrix', object.normalMatrix );
  14470. p_uniforms.setValue( _gl, 'modelMatrix', object.matrixWorld );
  14471. return program;
  14472. }
  14473. // Uniforms (refresh uniforms objects)
  14474. function refreshUniformsCommon( uniforms, material ) {
  14475. uniforms.opacity.value = material.opacity;
  14476. if ( material.color ) {
  14477. uniforms.diffuse.value = material.color;
  14478. }
  14479. if ( material.emissive ) {
  14480. uniforms.emissive.value.copy( material.emissive ).multiplyScalar( material.emissiveIntensity );
  14481. }
  14482. if ( material.map ) {
  14483. uniforms.map.value = material.map;
  14484. }
  14485. if ( material.alphaMap ) {
  14486. uniforms.alphaMap.value = material.alphaMap;
  14487. }
  14488. if ( material.specularMap ) {
  14489. uniforms.specularMap.value = material.specularMap;
  14490. }
  14491. if ( material.envMap ) {
  14492. uniforms.envMap.value = material.envMap;
  14493. // don't flip CubeTexture envMaps, flip everything else:
  14494. // WebGLRenderTargetCube will be flipped for backwards compatibility
  14495. // WebGLRenderTargetCube.texture will be flipped because it's a Texture and NOT a CubeTexture
  14496. // this check must be handled differently, or removed entirely, if WebGLRenderTargetCube uses a CubeTexture in the future
  14497. uniforms.flipEnvMap.value = material.envMap.isCubeTexture ? - 1 : 1;
  14498. uniforms.reflectivity.value = material.reflectivity;
  14499. uniforms.refractionRatio.value = material.refractionRatio;
  14500. uniforms.maxMipLevel.value = properties.get( material.envMap ).__maxMipLevel;
  14501. }
  14502. if ( material.lightMap ) {
  14503. uniforms.lightMap.value = material.lightMap;
  14504. uniforms.lightMapIntensity.value = material.lightMapIntensity;
  14505. }
  14506. if ( material.aoMap ) {
  14507. uniforms.aoMap.value = material.aoMap;
  14508. uniforms.aoMapIntensity.value = material.aoMapIntensity;
  14509. }
  14510. // uv repeat and offset setting priorities
  14511. // 1. color map
  14512. // 2. specular map
  14513. // 3. normal map
  14514. // 4. bump map
  14515. // 5. alpha map
  14516. // 6. emissive map
  14517. var uvScaleMap;
  14518. if ( material.map ) {
  14519. uvScaleMap = material.map;
  14520. } else if ( material.specularMap ) {
  14521. uvScaleMap = material.specularMap;
  14522. } else if ( material.displacementMap ) {
  14523. uvScaleMap = material.displacementMap;
  14524. } else if ( material.normalMap ) {
  14525. uvScaleMap = material.normalMap;
  14526. } else if ( material.bumpMap ) {
  14527. uvScaleMap = material.bumpMap;
  14528. } else if ( material.roughnessMap ) {
  14529. uvScaleMap = material.roughnessMap;
  14530. } else if ( material.metalnessMap ) {
  14531. uvScaleMap = material.metalnessMap;
  14532. } else if ( material.alphaMap ) {
  14533. uvScaleMap = material.alphaMap;
  14534. } else if ( material.emissiveMap ) {
  14535. uvScaleMap = material.emissiveMap;
  14536. }
  14537. if ( uvScaleMap !== undefined ) {
  14538. // backwards compatibility
  14539. if ( uvScaleMap.isWebGLRenderTarget ) {
  14540. uvScaleMap = uvScaleMap.texture;
  14541. }
  14542. if ( uvScaleMap.matrixAutoUpdate === true ) {
  14543. uvScaleMap.updateMatrix();
  14544. }
  14545. uniforms.uvTransform.value.copy( uvScaleMap.matrix );
  14546. }
  14547. }
  14548. function refreshUniformsLine( uniforms, material ) {
  14549. uniforms.diffuse.value = material.color;
  14550. uniforms.opacity.value = material.opacity;
  14551. }
  14552. function refreshUniformsDash( uniforms, material ) {
  14553. uniforms.dashSize.value = material.dashSize;
  14554. uniforms.totalSize.value = material.dashSize + material.gapSize;
  14555. uniforms.scale.value = material.scale;
  14556. }
  14557. function refreshUniformsPoints( uniforms, material ) {
  14558. uniforms.diffuse.value = material.color;
  14559. uniforms.opacity.value = material.opacity;
  14560. uniforms.size.value = material.size * _pixelRatio;
  14561. uniforms.scale.value = _height * 0.5;
  14562. uniforms.map.value = material.map;
  14563. if ( material.map !== null ) {
  14564. if ( material.map.matrixAutoUpdate === true ) {
  14565. material.map.updateMatrix();
  14566. }
  14567. uniforms.uvTransform.value.copy( material.map.matrix );
  14568. }
  14569. }
  14570. function refreshUniformsSprites( uniforms, material ) {
  14571. uniforms.diffuse.value = material.color;
  14572. uniforms.opacity.value = material.opacity;
  14573. uniforms.rotation.value = material.rotation;
  14574. uniforms.map.value = material.map;
  14575. if ( material.map !== null ) {
  14576. if ( material.map.matrixAutoUpdate === true ) {
  14577. material.map.updateMatrix();
  14578. }
  14579. uniforms.uvTransform.value.copy( material.map.matrix );
  14580. }
  14581. }
  14582. function refreshUniformsFog( uniforms, fog ) {
  14583. uniforms.fogColor.value = fog.color;
  14584. if ( fog.isFog ) {
  14585. uniforms.fogNear.value = fog.near;
  14586. uniforms.fogFar.value = fog.far;
  14587. } else if ( fog.isFogExp2 ) {
  14588. uniforms.fogDensity.value = fog.density;
  14589. }
  14590. }
  14591. function refreshUniformsLambert( uniforms, material ) {
  14592. if ( material.emissiveMap ) {
  14593. uniforms.emissiveMap.value = material.emissiveMap;
  14594. }
  14595. }
  14596. function refreshUniformsPhong( uniforms, material ) {
  14597. uniforms.specular.value = material.specular;
  14598. uniforms.shininess.value = Math.max( material.shininess, 1e-4 ); // to prevent pow( 0.0, 0.0 )
  14599. if ( material.emissiveMap ) {
  14600. uniforms.emissiveMap.value = material.emissiveMap;
  14601. }
  14602. if ( material.bumpMap ) {
  14603. uniforms.bumpMap.value = material.bumpMap;
  14604. uniforms.bumpScale.value = material.bumpScale;
  14605. if ( material.side === BackSide ) uniforms.bumpScale.value *= - 1;
  14606. }
  14607. if ( material.normalMap ) {
  14608. uniforms.normalMap.value = material.normalMap;
  14609. uniforms.normalScale.value.copy( material.normalScale );
  14610. if ( material.side === BackSide ) uniforms.normalScale.value.negate();
  14611. }
  14612. if ( material.displacementMap ) {
  14613. uniforms.displacementMap.value = material.displacementMap;
  14614. uniforms.displacementScale.value = material.displacementScale;
  14615. uniforms.displacementBias.value = material.displacementBias;
  14616. }
  14617. }
  14618. function refreshUniformsToon( uniforms, material ) {
  14619. refreshUniformsPhong( uniforms, material );
  14620. if ( material.gradientMap ) {
  14621. uniforms.gradientMap.value = material.gradientMap;
  14622. }
  14623. }
  14624. function refreshUniformsStandard( uniforms, material ) {
  14625. uniforms.roughness.value = material.roughness;
  14626. uniforms.metalness.value = material.metalness;
  14627. if ( material.roughnessMap ) {
  14628. uniforms.roughnessMap.value = material.roughnessMap;
  14629. }
  14630. if ( material.metalnessMap ) {
  14631. uniforms.metalnessMap.value = material.metalnessMap;
  14632. }
  14633. if ( material.emissiveMap ) {
  14634. uniforms.emissiveMap.value = material.emissiveMap;
  14635. }
  14636. if ( material.bumpMap ) {
  14637. uniforms.bumpMap.value = material.bumpMap;
  14638. uniforms.bumpScale.value = material.bumpScale;
  14639. if ( material.side === BackSide ) uniforms.bumpScale.value *= - 1;
  14640. }
  14641. if ( material.normalMap ) {
  14642. uniforms.normalMap.value = material.normalMap;
  14643. uniforms.normalScale.value.copy( material.normalScale );
  14644. if ( material.side === BackSide ) uniforms.normalScale.value.negate();
  14645. }
  14646. if ( material.displacementMap ) {
  14647. uniforms.displacementMap.value = material.displacementMap;
  14648. uniforms.displacementScale.value = material.displacementScale;
  14649. uniforms.displacementBias.value = material.displacementBias;
  14650. }
  14651. if ( material.envMap ) {
  14652. //uniforms.envMap.value = material.envMap; // part of uniforms common
  14653. uniforms.envMapIntensity.value = material.envMapIntensity;
  14654. }
  14655. }
  14656. function refreshUniformsPhysical( uniforms, material ) {
  14657. refreshUniformsStandard( uniforms, material );
  14658. uniforms.reflectivity.value = material.reflectivity; // also part of uniforms common
  14659. uniforms.clearCoat.value = material.clearCoat;
  14660. uniforms.clearCoatRoughness.value = material.clearCoatRoughness;
  14661. }
  14662. function refreshUniformsMatcap( uniforms, material ) {
  14663. if ( material.matcap ) {
  14664. uniforms.matcap.value = material.matcap;
  14665. }
  14666. if ( material.bumpMap ) {
  14667. uniforms.bumpMap.value = material.bumpMap;
  14668. uniforms.bumpScale.value = material.bumpScale;
  14669. if ( material.side === BackSide ) uniforms.bumpScale.value *= - 1;
  14670. }
  14671. if ( material.normalMap ) {
  14672. uniforms.normalMap.value = material.normalMap;
  14673. uniforms.normalScale.value.copy( material.normalScale );
  14674. if ( material.side === BackSide ) uniforms.normalScale.value.negate();
  14675. }
  14676. if ( material.displacementMap ) {
  14677. uniforms.displacementMap.value = material.displacementMap;
  14678. uniforms.displacementScale.value = material.displacementScale;
  14679. uniforms.displacementBias.value = material.displacementBias;
  14680. }
  14681. }
  14682. function refreshUniformsDepth( uniforms, material ) {
  14683. if ( material.displacementMap ) {
  14684. uniforms.displacementMap.value = material.displacementMap;
  14685. uniforms.displacementScale.value = material.displacementScale;
  14686. uniforms.displacementBias.value = material.displacementBias;
  14687. }
  14688. }
  14689. function refreshUniformsDistance( uniforms, material ) {
  14690. if ( material.displacementMap ) {
  14691. uniforms.displacementMap.value = material.displacementMap;
  14692. uniforms.displacementScale.value = material.displacementScale;
  14693. uniforms.displacementBias.value = material.displacementBias;
  14694. }
  14695. uniforms.referencePosition.value.copy( material.referencePosition );
  14696. uniforms.nearDistance.value = material.nearDistance;
  14697. uniforms.farDistance.value = material.farDistance;
  14698. }
  14699. function refreshUniformsNormal( uniforms, material ) {
  14700. if ( material.bumpMap ) {
  14701. uniforms.bumpMap.value = material.bumpMap;
  14702. uniforms.bumpScale.value = material.bumpScale;
  14703. if ( material.side === BackSide ) uniforms.bumpScale.value *= - 1;
  14704. }
  14705. if ( material.normalMap ) {
  14706. uniforms.normalMap.value = material.normalMap;
  14707. uniforms.normalScale.value.copy( material.normalScale );
  14708. if ( material.side === BackSide ) uniforms.normalScale.value.negate();
  14709. }
  14710. if ( material.displacementMap ) {
  14711. uniforms.displacementMap.value = material.displacementMap;
  14712. uniforms.displacementScale.value = material.displacementScale;
  14713. uniforms.displacementBias.value = material.displacementBias;
  14714. }
  14715. }
  14716. // If uniforms are marked as clean, they don't need to be loaded to the GPU.
  14717. function markUniformsLightsNeedsUpdate( uniforms, value ) {
  14718. uniforms.ambientLightColor.needsUpdate = value;
  14719. uniforms.directionalLights.needsUpdate = value;
  14720. uniforms.pointLights.needsUpdate = value;
  14721. uniforms.spotLights.needsUpdate = value;
  14722. uniforms.rectAreaLights.needsUpdate = value;
  14723. uniforms.hemisphereLights.needsUpdate = value;
  14724. }
  14725. // Textures
  14726. function allocTextureUnit() {
  14727. var textureUnit = _usedTextureUnits;
  14728. if ( textureUnit >= capabilities.maxTextures ) {
  14729. console.warn( 'THREE.WebGLRenderer: Trying to use ' + textureUnit + ' texture units while this GPU supports only ' + capabilities.maxTextures );
  14730. }
  14731. _usedTextureUnits += 1;
  14732. return textureUnit;
  14733. }
  14734. this.allocTextureUnit = allocTextureUnit;
  14735. // this.setTexture2D = setTexture2D;
  14736. this.setTexture2D = ( function () {
  14737. var warned = false;
  14738. // backwards compatibility: peel texture.texture
  14739. return function setTexture2D( texture, slot ) {
  14740. if ( texture && texture.isWebGLRenderTarget ) {
  14741. if ( ! warned ) {
  14742. console.warn( "THREE.WebGLRenderer.setTexture2D: don't use render targets as textures. Use their .texture property instead." );
  14743. warned = true;
  14744. }
  14745. texture = texture.texture;
  14746. }
  14747. textures.setTexture2D( texture, slot );
  14748. };
  14749. }() );
  14750. this.setTexture3D = ( function () {
  14751. // backwards compatibility: peel texture.texture
  14752. return function setTexture3D( texture, slot ) {
  14753. textures.setTexture3D( texture, slot );
  14754. };
  14755. }() );
  14756. this.setTexture = ( function () {
  14757. var warned = false;
  14758. return function setTexture( texture, slot ) {
  14759. if ( ! warned ) {
  14760. console.warn( "THREE.WebGLRenderer: .setTexture is deprecated, use setTexture2D instead." );
  14761. warned = true;
  14762. }
  14763. textures.setTexture2D( texture, slot );
  14764. };
  14765. }() );
  14766. this.setTextureCube = ( function () {
  14767. var warned = false;
  14768. return function setTextureCube( texture, slot ) {
  14769. // backwards compatibility: peel texture.texture
  14770. if ( texture && texture.isWebGLRenderTargetCube ) {
  14771. if ( ! warned ) {
  14772. console.warn( "THREE.WebGLRenderer.setTextureCube: don't use cube render targets as textures. Use their .texture property instead." );
  14773. warned = true;
  14774. }
  14775. texture = texture.texture;
  14776. }
  14777. // currently relying on the fact that WebGLRenderTargetCube.texture is a Texture and NOT a CubeTexture
  14778. // TODO: unify these code paths
  14779. if ( ( texture && texture.isCubeTexture ) ||
  14780. ( Array.isArray( texture.image ) && texture.image.length === 6 ) ) {
  14781. // CompressedTexture can have Array in image :/
  14782. // this function alone should take care of cube textures
  14783. textures.setTextureCube( texture, slot );
  14784. } else {
  14785. // assumed: texture property of THREE.WebGLRenderTargetCube
  14786. textures.setTextureCubeDynamic( texture, slot );
  14787. }
  14788. };
  14789. }() );
  14790. //
  14791. this.setFramebuffer = function ( value ) {
  14792. _framebuffer = value;
  14793. };
  14794. this.getRenderTarget = function () {
  14795. return _currentRenderTarget;
  14796. };
  14797. this.setRenderTarget = function ( renderTarget, activeCubeFace, activeMipMapLevel ) {
  14798. _currentRenderTarget = renderTarget;
  14799. if ( renderTarget && properties.get( renderTarget ).__webglFramebuffer === undefined ) {
  14800. textures.setupRenderTarget( renderTarget );
  14801. }
  14802. var framebuffer = _framebuffer;
  14803. var isCube = false;
  14804. if ( renderTarget ) {
  14805. var __webglFramebuffer = properties.get( renderTarget ).__webglFramebuffer;
  14806. if ( renderTarget.isWebGLRenderTargetCube ) {
  14807. framebuffer = __webglFramebuffer[ activeCubeFace || 0 ];
  14808. isCube = true;
  14809. } else if ( renderTarget.isWebGLMultisampleRenderTarget ) {
  14810. framebuffer = properties.get( renderTarget ).__webglMultisampledFramebuffer;
  14811. } else {
  14812. framebuffer = __webglFramebuffer;
  14813. }
  14814. _currentViewport.copy( renderTarget.viewport );
  14815. _currentScissor.copy( renderTarget.scissor );
  14816. _currentScissorTest = renderTarget.scissorTest;
  14817. } else {
  14818. _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio );
  14819. _currentScissor.copy( _scissor ).multiplyScalar( _pixelRatio );
  14820. _currentScissorTest = _scissorTest;
  14821. }
  14822. if ( _currentFramebuffer !== framebuffer ) {
  14823. _gl.bindFramebuffer( 36160, framebuffer );
  14824. _currentFramebuffer = framebuffer;
  14825. }
  14826. state.viewport( _currentViewport );
  14827. state.scissor( _currentScissor );
  14828. state.setScissorTest( _currentScissorTest );
  14829. if ( isCube ) {
  14830. var textureProperties = properties.get( renderTarget.texture );
  14831. _gl.framebufferTexture2D( 36160, 36064, 34069 + activeCubeFace || 0, textureProperties.__webglTexture, activeMipMapLevel || 0 );
  14832. }
  14833. };
  14834. this.readRenderTargetPixels = function ( renderTarget, x, y, width, height, buffer ) {
  14835. if ( ! ( renderTarget && renderTarget.isWebGLRenderTarget ) ) {
  14836. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.' );
  14837. return;
  14838. }
  14839. var framebuffer = properties.get( renderTarget ).__webglFramebuffer;
  14840. if ( framebuffer ) {
  14841. var restore = false;
  14842. if ( framebuffer !== _currentFramebuffer ) {
  14843. _gl.bindFramebuffer( 36160, framebuffer );
  14844. restore = true;
  14845. }
  14846. try {
  14847. var texture = renderTarget.texture;
  14848. var textureFormat = texture.format;
  14849. var textureType = texture.type;
  14850. if ( textureFormat !== RGBAFormat && utils.convert( textureFormat ) !== _gl.getParameter( 35739 ) ) {
  14851. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA or implementation defined format.' );
  14852. return;
  14853. }
  14854. if ( textureType !== UnsignedByteType && utils.convert( textureType ) !== _gl.getParameter( 35738 ) && // IE11, Edge and Chrome Mac < 52 (#9513)
  14855. ! ( textureType === FloatType && ( capabilities.isWebGL2 || extensions.get( 'OES_texture_float' ) || extensions.get( 'WEBGL_color_buffer_float' ) ) ) && // Chrome Mac >= 52 and Firefox
  14856. ! ( textureType === HalfFloatType && ( capabilities.isWebGL2 ? extensions.get( 'EXT_color_buffer_float' ) : extensions.get( 'EXT_color_buffer_half_float' ) ) ) ) {
  14857. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in UnsignedByteType or implementation defined type.' );
  14858. return;
  14859. }
  14860. if ( _gl.checkFramebufferStatus( 36160 ) === 36053 ) {
  14861. // the following if statement ensures valid read requests (no out-of-bounds pixels, see #8604)
  14862. if ( ( x >= 0 && x <= ( renderTarget.width - width ) ) && ( y >= 0 && y <= ( renderTarget.height - height ) ) ) {
  14863. _gl.readPixels( x, y, width, height, utils.convert( textureFormat ), utils.convert( textureType ), buffer );
  14864. }
  14865. } else {
  14866. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: readPixels from renderTarget failed. Framebuffer not complete.' );
  14867. }
  14868. } finally {
  14869. if ( restore ) {
  14870. _gl.bindFramebuffer( 36160, _currentFramebuffer );
  14871. }
  14872. }
  14873. }
  14874. };
  14875. this.copyFramebufferToTexture = function ( position, texture, level ) {
  14876. var width = texture.image.width;
  14877. var height = texture.image.height;
  14878. var glFormat = utils.convert( texture.format );
  14879. this.setTexture2D( texture, 0 );
  14880. _gl.copyTexImage2D( 3553, level || 0, glFormat, position.x, position.y, width, height, 0 );
  14881. };
  14882. this.copyTextureToTexture = function ( position, srcTexture, dstTexture, level ) {
  14883. var width = srcTexture.image.width;
  14884. var height = srcTexture.image.height;
  14885. var glFormat = utils.convert( dstTexture.format );
  14886. var glType = utils.convert( dstTexture.type );
  14887. this.setTexture2D( dstTexture, 0 );
  14888. if ( srcTexture.isDataTexture ) {
  14889. _gl.texSubImage2D( 3553, level || 0, position.x, position.y, width, height, glFormat, glType, srcTexture.image.data );
  14890. } else {
  14891. _gl.texSubImage2D( 3553, level || 0, position.x, position.y, glFormat, glType, srcTexture.image );
  14892. }
  14893. };
  14894. }
  14895. /**
  14896. * @author mrdoob / http://mrdoob.com/
  14897. * @author alteredq / http://alteredqualia.com/
  14898. */
  14899. function FogExp2( color, density ) {
  14900. this.name = '';
  14901. this.color = new Color( color );
  14902. this.density = ( density !== undefined ) ? density : 0.00025;
  14903. }
  14904. Object.assign( FogExp2.prototype, {
  14905. isFogExp2: true,
  14906. clone: function () {
  14907. return new FogExp2( this.color, this.density );
  14908. },
  14909. toJSON: function ( /* meta */ ) {
  14910. return {
  14911. type: 'FogExp2',
  14912. color: this.color.getHex(),
  14913. density: this.density
  14914. };
  14915. }
  14916. } );
  14917. /**
  14918. * @author mrdoob / http://mrdoob.com/
  14919. * @author alteredq / http://alteredqualia.com/
  14920. */
  14921. function Fog( color, near, far ) {
  14922. this.name = '';
  14923. this.color = new Color( color );
  14924. this.near = ( near !== undefined ) ? near : 1;
  14925. this.far = ( far !== undefined ) ? far : 1000;
  14926. }
  14927. Object.assign( Fog.prototype, {
  14928. isFog: true,
  14929. clone: function () {
  14930. return new Fog( this.color, this.near, this.far );
  14931. },
  14932. toJSON: function ( /* meta */ ) {
  14933. return {
  14934. type: 'Fog',
  14935. color: this.color.getHex(),
  14936. near: this.near,
  14937. far: this.far
  14938. };
  14939. }
  14940. } );
  14941. /**
  14942. * @author mrdoob / http://mrdoob.com/
  14943. */
  14944. function Scene() {
  14945. Object3D.call( this );
  14946. this.type = 'Scene';
  14947. this.background = null;
  14948. this.fog = null;
  14949. this.overrideMaterial = null;
  14950. this.autoUpdate = true; // checked by the renderer
  14951. }
  14952. Scene.prototype = Object.assign( Object.create( Object3D.prototype ), {
  14953. constructor: Scene,
  14954. isScene: true,
  14955. copy: function ( source, recursive ) {
  14956. Object3D.prototype.copy.call( this, source, recursive );
  14957. if ( source.background !== null ) this.background = source.background.clone();
  14958. if ( source.fog !== null ) this.fog = source.fog.clone();
  14959. if ( source.overrideMaterial !== null ) this.overrideMaterial = source.overrideMaterial.clone();
  14960. this.autoUpdate = source.autoUpdate;
  14961. this.matrixAutoUpdate = source.matrixAutoUpdate;
  14962. return this;
  14963. },
  14964. toJSON: function ( meta ) {
  14965. var data = Object3D.prototype.toJSON.call( this, meta );
  14966. if ( this.background !== null ) data.object.background = this.background.toJSON( meta );
  14967. if ( this.fog !== null ) data.object.fog = this.fog.toJSON();
  14968. return data;
  14969. },
  14970. dispose: function () {
  14971. this.dispatchEvent( { type: 'dispose' } );
  14972. }
  14973. } );
  14974. /**
  14975. * @author benaadams / https://twitter.com/ben_a_adams
  14976. */
  14977. function InterleavedBuffer( array, stride ) {
  14978. this.array = array;
  14979. this.stride = stride;
  14980. this.count = array !== undefined ? array.length / stride : 0;
  14981. this.dynamic = false;
  14982. this.updateRange = { offset: 0, count: - 1 };
  14983. this.version = 0;
  14984. }
  14985. Object.defineProperty( InterleavedBuffer.prototype, 'needsUpdate', {
  14986. set: function ( value ) {
  14987. if ( value === true ) this.version ++;
  14988. }
  14989. } );
  14990. Object.assign( InterleavedBuffer.prototype, {
  14991. isInterleavedBuffer: true,
  14992. onUploadCallback: function () {},
  14993. setArray: function ( array ) {
  14994. if ( Array.isArray( array ) ) {
  14995. throw new TypeError( 'THREE.BufferAttribute: array should be a Typed Array.' );
  14996. }
  14997. this.count = array !== undefined ? array.length / this.stride : 0;
  14998. this.array = array;
  14999. return this;
  15000. },
  15001. setDynamic: function ( value ) {
  15002. this.dynamic = value;
  15003. return this;
  15004. },
  15005. copy: function ( source ) {
  15006. this.array = new source.array.constructor( source.array );
  15007. this.count = source.count;
  15008. this.stride = source.stride;
  15009. this.dynamic = source.dynamic;
  15010. return this;
  15011. },
  15012. copyAt: function ( index1, attribute, index2 ) {
  15013. index1 *= this.stride;
  15014. index2 *= attribute.stride;
  15015. for ( var i = 0, l = this.stride; i < l; i ++ ) {
  15016. this.array[ index1 + i ] = attribute.array[ index2 + i ];
  15017. }
  15018. return this;
  15019. },
  15020. set: function ( value, offset ) {
  15021. if ( offset === undefined ) offset = 0;
  15022. this.array.set( value, offset );
  15023. return this;
  15024. },
  15025. clone: function () {
  15026. return new this.constructor().copy( this );
  15027. },
  15028. onUpload: function ( callback ) {
  15029. this.onUploadCallback = callback;
  15030. return this;
  15031. }
  15032. } );
  15033. /**
  15034. * @author benaadams / https://twitter.com/ben_a_adams
  15035. */
  15036. function InterleavedBufferAttribute( interleavedBuffer, itemSize, offset, normalized ) {
  15037. this.data = interleavedBuffer;
  15038. this.itemSize = itemSize;
  15039. this.offset = offset;
  15040. this.normalized = normalized === true;
  15041. }
  15042. Object.defineProperties( InterleavedBufferAttribute.prototype, {
  15043. count: {
  15044. get: function () {
  15045. return this.data.count;
  15046. }
  15047. },
  15048. array: {
  15049. get: function () {
  15050. return this.data.array;
  15051. }
  15052. }
  15053. } );
  15054. Object.assign( InterleavedBufferAttribute.prototype, {
  15055. isInterleavedBufferAttribute: true,
  15056. setX: function ( index, x ) {
  15057. this.data.array[ index * this.data.stride + this.offset ] = x;
  15058. return this;
  15059. },
  15060. setY: function ( index, y ) {
  15061. this.data.array[ index * this.data.stride + this.offset + 1 ] = y;
  15062. return this;
  15063. },
  15064. setZ: function ( index, z ) {
  15065. this.data.array[ index * this.data.stride + this.offset + 2 ] = z;
  15066. return this;
  15067. },
  15068. setW: function ( index, w ) {
  15069. this.data.array[ index * this.data.stride + this.offset + 3 ] = w;
  15070. return this;
  15071. },
  15072. getX: function ( index ) {
  15073. return this.data.array[ index * this.data.stride + this.offset ];
  15074. },
  15075. getY: function ( index ) {
  15076. return this.data.array[ index * this.data.stride + this.offset + 1 ];
  15077. },
  15078. getZ: function ( index ) {
  15079. return this.data.array[ index * this.data.stride + this.offset + 2 ];
  15080. },
  15081. getW: function ( index ) {
  15082. return this.data.array[ index * this.data.stride + this.offset + 3 ];
  15083. },
  15084. setXY: function ( index, x, y ) {
  15085. index = index * this.data.stride + this.offset;
  15086. this.data.array[ index + 0 ] = x;
  15087. this.data.array[ index + 1 ] = y;
  15088. return this;
  15089. },
  15090. setXYZ: function ( index, x, y, z ) {
  15091. index = index * this.data.stride + this.offset;
  15092. this.data.array[ index + 0 ] = x;
  15093. this.data.array[ index + 1 ] = y;
  15094. this.data.array[ index + 2 ] = z;
  15095. return this;
  15096. },
  15097. setXYZW: function ( index, x, y, z, w ) {
  15098. index = index * this.data.stride + this.offset;
  15099. this.data.array[ index + 0 ] = x;
  15100. this.data.array[ index + 1 ] = y;
  15101. this.data.array[ index + 2 ] = z;
  15102. this.data.array[ index + 3 ] = w;
  15103. return this;
  15104. }
  15105. } );
  15106. /**
  15107. * @author alteredq / http://alteredqualia.com/
  15108. *
  15109. * parameters = {
  15110. * color: <hex>,
  15111. * map: new THREE.Texture( <Image> ),
  15112. * rotation: <float>,
  15113. * sizeAttenuation: <bool>
  15114. * }
  15115. */
  15116. function SpriteMaterial( parameters ) {
  15117. Material.call( this );
  15118. this.type = 'SpriteMaterial';
  15119. this.color = new Color( 0xffffff );
  15120. this.map = null;
  15121. this.rotation = 0;
  15122. this.sizeAttenuation = true;
  15123. this.lights = false;
  15124. this.transparent = true;
  15125. this.setValues( parameters );
  15126. }
  15127. SpriteMaterial.prototype = Object.create( Material.prototype );
  15128. SpriteMaterial.prototype.constructor = SpriteMaterial;
  15129. SpriteMaterial.prototype.isSpriteMaterial = true;
  15130. SpriteMaterial.prototype.copy = function ( source ) {
  15131. Material.prototype.copy.call( this, source );
  15132. this.color.copy( source.color );
  15133. this.map = source.map;
  15134. this.rotation = source.rotation;
  15135. this.sizeAttenuation = source.sizeAttenuation;
  15136. return this;
  15137. };
  15138. /**
  15139. * @author mikael emtinger / http://gomo.se/
  15140. * @author alteredq / http://alteredqualia.com/
  15141. */
  15142. var geometry;
  15143. function Sprite( material ) {
  15144. Object3D.call( this );
  15145. this.type = 'Sprite';
  15146. if ( geometry === undefined ) {
  15147. geometry = new BufferGeometry();
  15148. var float32Array = new Float32Array( [
  15149. - 0.5, - 0.5, 0, 0, 0,
  15150. 0.5, - 0.5, 0, 1, 0,
  15151. 0.5, 0.5, 0, 1, 1,
  15152. - 0.5, 0.5, 0, 0, 1
  15153. ] );
  15154. var interleavedBuffer = new InterleavedBuffer( float32Array, 5 );
  15155. geometry.setIndex( [ 0, 1, 2, 0, 2, 3 ] );
  15156. geometry.addAttribute( 'position', new InterleavedBufferAttribute( interleavedBuffer, 3, 0, false ) );
  15157. geometry.addAttribute( 'uv', new InterleavedBufferAttribute( interleavedBuffer, 2, 3, false ) );
  15158. }
  15159. this.geometry = geometry;
  15160. this.material = ( material !== undefined ) ? material : new SpriteMaterial();
  15161. this.center = new Vector2( 0.5, 0.5 );
  15162. }
  15163. Sprite.prototype = Object.assign( Object.create( Object3D.prototype ), {
  15164. constructor: Sprite,
  15165. isSprite: true,
  15166. raycast: ( function () {
  15167. var intersectPoint = new Vector3();
  15168. var worldScale = new Vector3();
  15169. var mvPosition = new Vector3();
  15170. var alignedPosition = new Vector2();
  15171. var rotatedPosition = new Vector2();
  15172. var viewWorldMatrix = new Matrix4();
  15173. var vA = new Vector3();
  15174. var vB = new Vector3();
  15175. var vC = new Vector3();
  15176. var uvA = new Vector2();
  15177. var uvB = new Vector2();
  15178. var uvC = new Vector2();
  15179. function transformVertex( vertexPosition, mvPosition, center, scale, sin, cos ) {
  15180. // compute position in camera space
  15181. alignedPosition.subVectors( vertexPosition, center ).addScalar( 0.5 ).multiply( scale );
  15182. // to check if rotation is not zero
  15183. if ( sin !== undefined ) {
  15184. rotatedPosition.x = ( cos * alignedPosition.x ) - ( sin * alignedPosition.y );
  15185. rotatedPosition.y = ( sin * alignedPosition.x ) + ( cos * alignedPosition.y );
  15186. } else {
  15187. rotatedPosition.copy( alignedPosition );
  15188. }
  15189. vertexPosition.copy( mvPosition );
  15190. vertexPosition.x += rotatedPosition.x;
  15191. vertexPosition.y += rotatedPosition.y;
  15192. // transform to world space
  15193. vertexPosition.applyMatrix4( viewWorldMatrix );
  15194. }
  15195. return function raycast( raycaster, intersects ) {
  15196. worldScale.setFromMatrixScale( this.matrixWorld );
  15197. viewWorldMatrix.getInverse( this.modelViewMatrix ).premultiply( this.matrixWorld );
  15198. mvPosition.setFromMatrixPosition( this.modelViewMatrix );
  15199. var rotation = this.material.rotation;
  15200. var sin, cos;
  15201. if ( rotation !== 0 ) {
  15202. cos = Math.cos( rotation );
  15203. sin = Math.sin( rotation );
  15204. }
  15205. var center = this.center;
  15206. transformVertex( vA.set( - 0.5, - 0.5, 0 ), mvPosition, center, worldScale, sin, cos );
  15207. transformVertex( vB.set( 0.5, - 0.5, 0 ), mvPosition, center, worldScale, sin, cos );
  15208. transformVertex( vC.set( 0.5, 0.5, 0 ), mvPosition, center, worldScale, sin, cos );
  15209. uvA.set( 0, 0 );
  15210. uvB.set( 1, 0 );
  15211. uvC.set( 1, 1 );
  15212. // check first triangle
  15213. var intersect = raycaster.ray.intersectTriangle( vA, vB, vC, false, intersectPoint );
  15214. if ( intersect === null ) {
  15215. // check second triangle
  15216. transformVertex( vB.set( - 0.5, 0.5, 0 ), mvPosition, center, worldScale, sin, cos );
  15217. uvB.set( 0, 1 );
  15218. intersect = raycaster.ray.intersectTriangle( vA, vC, vB, false, intersectPoint );
  15219. if ( intersect === null ) {
  15220. return;
  15221. }
  15222. }
  15223. var distance = raycaster.ray.origin.distanceTo( intersectPoint );
  15224. if ( distance < raycaster.near || distance > raycaster.far ) return;
  15225. intersects.push( {
  15226. distance: distance,
  15227. point: intersectPoint.clone(),
  15228. uv: Triangle.getUV( intersectPoint, vA, vB, vC, uvA, uvB, uvC, new Vector2() ),
  15229. face: null,
  15230. object: this
  15231. } );
  15232. };
  15233. }() ),
  15234. clone: function () {
  15235. return new this.constructor( this.material ).copy( this );
  15236. },
  15237. copy: function ( source ) {
  15238. Object3D.prototype.copy.call( this, source );
  15239. if ( source.center !== undefined ) this.center.copy( source.center );
  15240. return this;
  15241. }
  15242. } );
  15243. /**
  15244. * @author mikael emtinger / http://gomo.se/
  15245. * @author alteredq / http://alteredqualia.com/
  15246. * @author mrdoob / http://mrdoob.com/
  15247. */
  15248. function LOD() {
  15249. Object3D.call( this );
  15250. this.type = 'LOD';
  15251. Object.defineProperties( this, {
  15252. levels: {
  15253. enumerable: true,
  15254. value: []
  15255. }
  15256. } );
  15257. }
  15258. LOD.prototype = Object.assign( Object.create( Object3D.prototype ), {
  15259. constructor: LOD,
  15260. copy: function ( source ) {
  15261. Object3D.prototype.copy.call( this, source, false );
  15262. var levels = source.levels;
  15263. for ( var i = 0, l = levels.length; i < l; i ++ ) {
  15264. var level = levels[ i ];
  15265. this.addLevel( level.object.clone(), level.distance );
  15266. }
  15267. return this;
  15268. },
  15269. addLevel: function ( object, distance ) {
  15270. if ( distance === undefined ) distance = 0;
  15271. distance = Math.abs( distance );
  15272. var levels = this.levels;
  15273. for ( var l = 0; l < levels.length; l ++ ) {
  15274. if ( distance < levels[ l ].distance ) {
  15275. break;
  15276. }
  15277. }
  15278. levels.splice( l, 0, { distance: distance, object: object } );
  15279. this.add( object );
  15280. },
  15281. getObjectForDistance: function ( distance ) {
  15282. var levels = this.levels;
  15283. for ( var i = 1, l = levels.length; i < l; i ++ ) {
  15284. if ( distance < levels[ i ].distance ) {
  15285. break;
  15286. }
  15287. }
  15288. return levels[ i - 1 ].object;
  15289. },
  15290. raycast: ( function () {
  15291. var matrixPosition = new Vector3();
  15292. return function raycast( raycaster, intersects ) {
  15293. matrixPosition.setFromMatrixPosition( this.matrixWorld );
  15294. var distance = raycaster.ray.origin.distanceTo( matrixPosition );
  15295. this.getObjectForDistance( distance ).raycast( raycaster, intersects );
  15296. };
  15297. }() ),
  15298. update: function () {
  15299. var v1 = new Vector3();
  15300. var v2 = new Vector3();
  15301. return function update( camera ) {
  15302. var levels = this.levels;
  15303. if ( levels.length > 1 ) {
  15304. v1.setFromMatrixPosition( camera.matrixWorld );
  15305. v2.setFromMatrixPosition( this.matrixWorld );
  15306. var distance = v1.distanceTo( v2 );
  15307. levels[ 0 ].object.visible = true;
  15308. for ( var i = 1, l = levels.length; i < l; i ++ ) {
  15309. if ( distance >= levels[ i ].distance ) {
  15310. levels[ i - 1 ].object.visible = false;
  15311. levels[ i ].object.visible = true;
  15312. } else {
  15313. break;
  15314. }
  15315. }
  15316. for ( ; i < l; i ++ ) {
  15317. levels[ i ].object.visible = false;
  15318. }
  15319. }
  15320. };
  15321. }(),
  15322. toJSON: function ( meta ) {
  15323. var data = Object3D.prototype.toJSON.call( this, meta );
  15324. data.object.levels = [];
  15325. var levels = this.levels;
  15326. for ( var i = 0, l = levels.length; i < l; i ++ ) {
  15327. var level = levels[ i ];
  15328. data.object.levels.push( {
  15329. object: level.object.uuid,
  15330. distance: level.distance
  15331. } );
  15332. }
  15333. return data;
  15334. }
  15335. } );
  15336. /**
  15337. * @author mikael emtinger / http://gomo.se/
  15338. * @author alteredq / http://alteredqualia.com/
  15339. * @author ikerr / http://verold.com
  15340. */
  15341. function SkinnedMesh( geometry, material ) {
  15342. if ( geometry && geometry.isGeometry ) {
  15343. console.error( 'THREE.SkinnedMesh no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.' );
  15344. }
  15345. Mesh.call( this, geometry, material );
  15346. this.type = 'SkinnedMesh';
  15347. this.bindMode = 'attached';
  15348. this.bindMatrix = new Matrix4();
  15349. this.bindMatrixInverse = new Matrix4();
  15350. }
  15351. SkinnedMesh.prototype = Object.assign( Object.create( Mesh.prototype ), {
  15352. constructor: SkinnedMesh,
  15353. isSkinnedMesh: true,
  15354. bind: function ( skeleton, bindMatrix ) {
  15355. this.skeleton = skeleton;
  15356. if ( bindMatrix === undefined ) {
  15357. this.updateMatrixWorld( true );
  15358. this.skeleton.calculateInverses();
  15359. bindMatrix = this.matrixWorld;
  15360. }
  15361. this.bindMatrix.copy( bindMatrix );
  15362. this.bindMatrixInverse.getInverse( bindMatrix );
  15363. },
  15364. pose: function () {
  15365. this.skeleton.pose();
  15366. },
  15367. normalizeSkinWeights: function () {
  15368. var vector = new Vector4();
  15369. var skinWeight = this.geometry.attributes.skinWeight;
  15370. for ( var i = 0, l = skinWeight.count; i < l; i ++ ) {
  15371. vector.x = skinWeight.getX( i );
  15372. vector.y = skinWeight.getY( i );
  15373. vector.z = skinWeight.getZ( i );
  15374. vector.w = skinWeight.getW( i );
  15375. var scale = 1.0 / vector.manhattanLength();
  15376. if ( scale !== Infinity ) {
  15377. vector.multiplyScalar( scale );
  15378. } else {
  15379. vector.set( 1, 0, 0, 0 ); // do something reasonable
  15380. }
  15381. skinWeight.setXYZW( i, vector.x, vector.y, vector.z, vector.w );
  15382. }
  15383. },
  15384. updateMatrixWorld: function ( force ) {
  15385. Mesh.prototype.updateMatrixWorld.call( this, force );
  15386. if ( this.bindMode === 'attached' ) {
  15387. this.bindMatrixInverse.getInverse( this.matrixWorld );
  15388. } else if ( this.bindMode === 'detached' ) {
  15389. this.bindMatrixInverse.getInverse( this.bindMatrix );
  15390. } else {
  15391. console.warn( 'THREE.SkinnedMesh: Unrecognized bindMode: ' + this.bindMode );
  15392. }
  15393. },
  15394. clone: function () {
  15395. return new this.constructor( this.geometry, this.material ).copy( this );
  15396. }
  15397. } );
  15398. /**
  15399. * @author mikael emtinger / http://gomo.se/
  15400. * @author alteredq / http://alteredqualia.com/
  15401. * @author michael guerrero / http://realitymeltdown.com
  15402. * @author ikerr / http://verold.com
  15403. */
  15404. function Skeleton( bones, boneInverses ) {
  15405. // copy the bone array
  15406. bones = bones || [];
  15407. this.bones = bones.slice( 0 );
  15408. this.boneMatrices = new Float32Array( this.bones.length * 16 );
  15409. // use the supplied bone inverses or calculate the inverses
  15410. if ( boneInverses === undefined ) {
  15411. this.calculateInverses();
  15412. } else {
  15413. if ( this.bones.length === boneInverses.length ) {
  15414. this.boneInverses = boneInverses.slice( 0 );
  15415. } else {
  15416. console.warn( 'THREE.Skeleton boneInverses is the wrong length.' );
  15417. this.boneInverses = [];
  15418. for ( var i = 0, il = this.bones.length; i < il; i ++ ) {
  15419. this.boneInverses.push( new Matrix4() );
  15420. }
  15421. }
  15422. }
  15423. }
  15424. Object.assign( Skeleton.prototype, {
  15425. calculateInverses: function () {
  15426. this.boneInverses = [];
  15427. for ( var i = 0, il = this.bones.length; i < il; i ++ ) {
  15428. var inverse = new Matrix4();
  15429. if ( this.bones[ i ] ) {
  15430. inverse.getInverse( this.bones[ i ].matrixWorld );
  15431. }
  15432. this.boneInverses.push( inverse );
  15433. }
  15434. },
  15435. pose: function () {
  15436. var bone, i, il;
  15437. // recover the bind-time world matrices
  15438. for ( i = 0, il = this.bones.length; i < il; i ++ ) {
  15439. bone = this.bones[ i ];
  15440. if ( bone ) {
  15441. bone.matrixWorld.getInverse( this.boneInverses[ i ] );
  15442. }
  15443. }
  15444. // compute the local matrices, positions, rotations and scales
  15445. for ( i = 0, il = this.bones.length; i < il; i ++ ) {
  15446. bone = this.bones[ i ];
  15447. if ( bone ) {
  15448. if ( bone.parent && bone.parent.isBone ) {
  15449. bone.matrix.getInverse( bone.parent.matrixWorld );
  15450. bone.matrix.multiply( bone.matrixWorld );
  15451. } else {
  15452. bone.matrix.copy( bone.matrixWorld );
  15453. }
  15454. bone.matrix.decompose( bone.position, bone.quaternion, bone.scale );
  15455. }
  15456. }
  15457. },
  15458. update: ( function () {
  15459. var offsetMatrix = new Matrix4();
  15460. var identityMatrix = new Matrix4();
  15461. return function update() {
  15462. var bones = this.bones;
  15463. var boneInverses = this.boneInverses;
  15464. var boneMatrices = this.boneMatrices;
  15465. var boneTexture = this.boneTexture;
  15466. // flatten bone matrices to array
  15467. for ( var i = 0, il = bones.length; i < il; i ++ ) {
  15468. // compute the offset between the current and the original transform
  15469. var matrix = bones[ i ] ? bones[ i ].matrixWorld : identityMatrix;
  15470. offsetMatrix.multiplyMatrices( matrix, boneInverses[ i ] );
  15471. offsetMatrix.toArray( boneMatrices, i * 16 );
  15472. }
  15473. if ( boneTexture !== undefined ) {
  15474. boneTexture.needsUpdate = true;
  15475. }
  15476. };
  15477. } )(),
  15478. clone: function () {
  15479. return new Skeleton( this.bones, this.boneInverses );
  15480. },
  15481. getBoneByName: function ( name ) {
  15482. for ( var i = 0, il = this.bones.length; i < il; i ++ ) {
  15483. var bone = this.bones[ i ];
  15484. if ( bone.name === name ) {
  15485. return bone;
  15486. }
  15487. }
  15488. return undefined;
  15489. }
  15490. } );
  15491. /**
  15492. * @author mikael emtinger / http://gomo.se/
  15493. * @author alteredq / http://alteredqualia.com/
  15494. * @author ikerr / http://verold.com
  15495. */
  15496. function Bone() {
  15497. Object3D.call( this );
  15498. this.type = 'Bone';
  15499. }
  15500. Bone.prototype = Object.assign( Object.create( Object3D.prototype ), {
  15501. constructor: Bone,
  15502. isBone: true
  15503. } );
  15504. /**
  15505. * @author mrdoob / http://mrdoob.com/
  15506. * @author alteredq / http://alteredqualia.com/
  15507. *
  15508. * parameters = {
  15509. * color: <hex>,
  15510. * opacity: <float>,
  15511. *
  15512. * linewidth: <float>,
  15513. * linecap: "round",
  15514. * linejoin: "round"
  15515. * }
  15516. */
  15517. function LineBasicMaterial( parameters ) {
  15518. Material.call( this );
  15519. this.type = 'LineBasicMaterial';
  15520. this.color = new Color( 0xffffff );
  15521. this.linewidth = 1;
  15522. this.linecap = 'round';
  15523. this.linejoin = 'round';
  15524. this.lights = false;
  15525. this.setValues( parameters );
  15526. }
  15527. LineBasicMaterial.prototype = Object.create( Material.prototype );
  15528. LineBasicMaterial.prototype.constructor = LineBasicMaterial;
  15529. LineBasicMaterial.prototype.isLineBasicMaterial = true;
  15530. LineBasicMaterial.prototype.copy = function ( source ) {
  15531. Material.prototype.copy.call( this, source );
  15532. this.color.copy( source.color );
  15533. this.linewidth = source.linewidth;
  15534. this.linecap = source.linecap;
  15535. this.linejoin = source.linejoin;
  15536. return this;
  15537. };
  15538. /**
  15539. * @author mrdoob / http://mrdoob.com/
  15540. */
  15541. function Line( geometry, material, mode ) {
  15542. if ( mode === 1 ) {
  15543. console.error( 'THREE.Line: parameter THREE.LinePieces no longer supported. Use THREE.LineSegments instead.' );
  15544. }
  15545. Object3D.call( this );
  15546. this.type = 'Line';
  15547. this.geometry = geometry !== undefined ? geometry : new BufferGeometry();
  15548. this.material = material !== undefined ? material : new LineBasicMaterial( { color: Math.random() * 0xffffff } );
  15549. }
  15550. Line.prototype = Object.assign( Object.create( Object3D.prototype ), {
  15551. constructor: Line,
  15552. isLine: true,
  15553. computeLineDistances: ( function () {
  15554. var start = new Vector3();
  15555. var end = new Vector3();
  15556. return function computeLineDistances() {
  15557. var geometry = this.geometry;
  15558. if ( geometry.isBufferGeometry ) {
  15559. // we assume non-indexed geometry
  15560. if ( geometry.index === null ) {
  15561. var positionAttribute = geometry.attributes.position;
  15562. var lineDistances = [ 0 ];
  15563. for ( var i = 1, l = positionAttribute.count; i < l; i ++ ) {
  15564. start.fromBufferAttribute( positionAttribute, i - 1 );
  15565. end.fromBufferAttribute( positionAttribute, i );
  15566. lineDistances[ i ] = lineDistances[ i - 1 ];
  15567. lineDistances[ i ] += start.distanceTo( end );
  15568. }
  15569. geometry.addAttribute( 'lineDistance', new Float32BufferAttribute( lineDistances, 1 ) );
  15570. } else {
  15571. console.warn( 'THREE.Line.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.' );
  15572. }
  15573. } else if ( geometry.isGeometry ) {
  15574. var vertices = geometry.vertices;
  15575. var lineDistances = geometry.lineDistances;
  15576. lineDistances[ 0 ] = 0;
  15577. for ( var i = 1, l = vertices.length; i < l; i ++ ) {
  15578. lineDistances[ i ] = lineDistances[ i - 1 ];
  15579. lineDistances[ i ] += vertices[ i - 1 ].distanceTo( vertices[ i ] );
  15580. }
  15581. }
  15582. return this;
  15583. };
  15584. }() ),
  15585. raycast: ( function () {
  15586. var inverseMatrix = new Matrix4();
  15587. var ray = new Ray();
  15588. var sphere = new Sphere();
  15589. return function raycast( raycaster, intersects ) {
  15590. var precision = raycaster.linePrecision;
  15591. var geometry = this.geometry;
  15592. var matrixWorld = this.matrixWorld;
  15593. // Checking boundingSphere distance to ray
  15594. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  15595. sphere.copy( geometry.boundingSphere );
  15596. sphere.applyMatrix4( matrixWorld );
  15597. sphere.radius += precision;
  15598. if ( raycaster.ray.intersectsSphere( sphere ) === false ) return;
  15599. //
  15600. inverseMatrix.getInverse( matrixWorld );
  15601. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  15602. var localPrecision = precision / ( ( this.scale.x + this.scale.y + this.scale.z ) / 3 );
  15603. var localPrecisionSq = localPrecision * localPrecision;
  15604. var vStart = new Vector3();
  15605. var vEnd = new Vector3();
  15606. var interSegment = new Vector3();
  15607. var interRay = new Vector3();
  15608. var step = ( this && this.isLineSegments ) ? 2 : 1;
  15609. if ( geometry.isBufferGeometry ) {
  15610. var index = geometry.index;
  15611. var attributes = geometry.attributes;
  15612. var positions = attributes.position.array;
  15613. if ( index !== null ) {
  15614. var indices = index.array;
  15615. for ( var i = 0, l = indices.length - 1; i < l; i += step ) {
  15616. var a = indices[ i ];
  15617. var b = indices[ i + 1 ];
  15618. vStart.fromArray( positions, a * 3 );
  15619. vEnd.fromArray( positions, b * 3 );
  15620. var distSq = ray.distanceSqToSegment( vStart, vEnd, interRay, interSegment );
  15621. if ( distSq > localPrecisionSq ) continue;
  15622. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  15623. var distance = raycaster.ray.origin.distanceTo( interRay );
  15624. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  15625. intersects.push( {
  15626. distance: distance,
  15627. // What do we want? intersection point on the ray or on the segment??
  15628. // point: raycaster.ray.at( distance ),
  15629. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  15630. index: i,
  15631. face: null,
  15632. faceIndex: null,
  15633. object: this
  15634. } );
  15635. }
  15636. } else {
  15637. for ( var i = 0, l = positions.length / 3 - 1; i < l; i += step ) {
  15638. vStart.fromArray( positions, 3 * i );
  15639. vEnd.fromArray( positions, 3 * i + 3 );
  15640. var distSq = ray.distanceSqToSegment( vStart, vEnd, interRay, interSegment );
  15641. if ( distSq > localPrecisionSq ) continue;
  15642. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  15643. var distance = raycaster.ray.origin.distanceTo( interRay );
  15644. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  15645. intersects.push( {
  15646. distance: distance,
  15647. // What do we want? intersection point on the ray or on the segment??
  15648. // point: raycaster.ray.at( distance ),
  15649. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  15650. index: i,
  15651. face: null,
  15652. faceIndex: null,
  15653. object: this
  15654. } );
  15655. }
  15656. }
  15657. } else if ( geometry.isGeometry ) {
  15658. var vertices = geometry.vertices;
  15659. var nbVertices = vertices.length;
  15660. for ( var i = 0; i < nbVertices - 1; i += step ) {
  15661. var distSq = ray.distanceSqToSegment( vertices[ i ], vertices[ i + 1 ], interRay, interSegment );
  15662. if ( distSq > localPrecisionSq ) continue;
  15663. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  15664. var distance = raycaster.ray.origin.distanceTo( interRay );
  15665. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  15666. intersects.push( {
  15667. distance: distance,
  15668. // What do we want? intersection point on the ray or on the segment??
  15669. // point: raycaster.ray.at( distance ),
  15670. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  15671. index: i,
  15672. face: null,
  15673. faceIndex: null,
  15674. object: this
  15675. } );
  15676. }
  15677. }
  15678. };
  15679. }() ),
  15680. copy: function ( source ) {
  15681. Object3D.prototype.copy.call( this, source );
  15682. this.geometry.copy( source.geometry );
  15683. this.material.copy( source.material );
  15684. return this;
  15685. },
  15686. clone: function () {
  15687. return new this.constructor().copy( this );
  15688. }
  15689. } );
  15690. /**
  15691. * @author mrdoob / http://mrdoob.com/
  15692. */
  15693. function LineSegments( geometry, material ) {
  15694. Line.call( this, geometry, material );
  15695. this.type = 'LineSegments';
  15696. }
  15697. LineSegments.prototype = Object.assign( Object.create( Line.prototype ), {
  15698. constructor: LineSegments,
  15699. isLineSegments: true,
  15700. computeLineDistances: ( function () {
  15701. var start = new Vector3();
  15702. var end = new Vector3();
  15703. return function computeLineDistances() {
  15704. var geometry = this.geometry;
  15705. if ( geometry.isBufferGeometry ) {
  15706. // we assume non-indexed geometry
  15707. if ( geometry.index === null ) {
  15708. var positionAttribute = geometry.attributes.position;
  15709. var lineDistances = [];
  15710. for ( var i = 0, l = positionAttribute.count; i < l; i += 2 ) {
  15711. start.fromBufferAttribute( positionAttribute, i );
  15712. end.fromBufferAttribute( positionAttribute, i + 1 );
  15713. lineDistances[ i ] = ( i === 0 ) ? 0 : lineDistances[ i - 1 ];
  15714. lineDistances[ i + 1 ] = lineDistances[ i ] + start.distanceTo( end );
  15715. }
  15716. geometry.addAttribute( 'lineDistance', new Float32BufferAttribute( lineDistances, 1 ) );
  15717. } else {
  15718. console.warn( 'THREE.LineSegments.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.' );
  15719. }
  15720. } else if ( geometry.isGeometry ) {
  15721. var vertices = geometry.vertices;
  15722. var lineDistances = geometry.lineDistances;
  15723. for ( var i = 0, l = vertices.length; i < l; i += 2 ) {
  15724. start.copy( vertices[ i ] );
  15725. end.copy( vertices[ i + 1 ] );
  15726. lineDistances[ i ] = ( i === 0 ) ? 0 : lineDistances[ i - 1 ];
  15727. lineDistances[ i + 1 ] = lineDistances[ i ] + start.distanceTo( end );
  15728. }
  15729. }
  15730. return this;
  15731. };
  15732. }() )
  15733. } );
  15734. /**
  15735. * @author mgreter / http://github.com/mgreter
  15736. */
  15737. function LineLoop( geometry, material ) {
  15738. Line.call( this, geometry, material );
  15739. this.type = 'LineLoop';
  15740. }
  15741. LineLoop.prototype = Object.assign( Object.create( Line.prototype ), {
  15742. constructor: LineLoop,
  15743. isLineLoop: true,
  15744. } );
  15745. /**
  15746. * @author mrdoob / http://mrdoob.com/
  15747. * @author alteredq / http://alteredqualia.com/
  15748. *
  15749. * parameters = {
  15750. * color: <hex>,
  15751. * opacity: <float>,
  15752. * map: new THREE.Texture( <Image> ),
  15753. *
  15754. * size: <float>,
  15755. * sizeAttenuation: <bool>
  15756. *
  15757. * morphTargets: <bool>
  15758. * }
  15759. */
  15760. function PointsMaterial( parameters ) {
  15761. Material.call( this );
  15762. this.type = 'PointsMaterial';
  15763. this.color = new Color( 0xffffff );
  15764. this.map = null;
  15765. this.size = 1;
  15766. this.sizeAttenuation = true;
  15767. this.morphTargets = false;
  15768. this.lights = false;
  15769. this.setValues( parameters );
  15770. }
  15771. PointsMaterial.prototype = Object.create( Material.prototype );
  15772. PointsMaterial.prototype.constructor = PointsMaterial;
  15773. PointsMaterial.prototype.isPointsMaterial = true;
  15774. PointsMaterial.prototype.copy = function ( source ) {
  15775. Material.prototype.copy.call( this, source );
  15776. this.color.copy( source.color );
  15777. this.map = source.map;
  15778. this.size = source.size;
  15779. this.sizeAttenuation = source.sizeAttenuation;
  15780. this.morphTargets = source.morphTargets;
  15781. return this;
  15782. };
  15783. /**
  15784. * @author alteredq / http://alteredqualia.com/
  15785. */
  15786. function Points( geometry, material ) {
  15787. Object3D.call( this );
  15788. this.type = 'Points';
  15789. this.geometry = geometry !== undefined ? geometry : new BufferGeometry();
  15790. this.material = material !== undefined ? material : new PointsMaterial( { color: Math.random() * 0xffffff } );
  15791. }
  15792. Points.prototype = Object.assign( Object.create( Object3D.prototype ), {
  15793. constructor: Points,
  15794. isPoints: true,
  15795. raycast: ( function () {
  15796. var inverseMatrix = new Matrix4();
  15797. var ray = new Ray();
  15798. var sphere = new Sphere();
  15799. return function raycast( raycaster, intersects ) {
  15800. var object = this;
  15801. var geometry = this.geometry;
  15802. var matrixWorld = this.matrixWorld;
  15803. var threshold = raycaster.params.Points.threshold;
  15804. // Checking boundingSphere distance to ray
  15805. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  15806. sphere.copy( geometry.boundingSphere );
  15807. sphere.applyMatrix4( matrixWorld );
  15808. sphere.radius += threshold;
  15809. if ( raycaster.ray.intersectsSphere( sphere ) === false ) return;
  15810. //
  15811. inverseMatrix.getInverse( matrixWorld );
  15812. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  15813. var localThreshold = threshold / ( ( this.scale.x + this.scale.y + this.scale.z ) / 3 );
  15814. var localThresholdSq = localThreshold * localThreshold;
  15815. var position = new Vector3();
  15816. var intersectPoint = new Vector3();
  15817. function testPoint( point, index ) {
  15818. var rayPointDistanceSq = ray.distanceSqToPoint( point );
  15819. if ( rayPointDistanceSq < localThresholdSq ) {
  15820. ray.closestPointToPoint( point, intersectPoint );
  15821. intersectPoint.applyMatrix4( matrixWorld );
  15822. var distance = raycaster.ray.origin.distanceTo( intersectPoint );
  15823. if ( distance < raycaster.near || distance > raycaster.far ) return;
  15824. intersects.push( {
  15825. distance: distance,
  15826. distanceToRay: Math.sqrt( rayPointDistanceSq ),
  15827. point: intersectPoint.clone(),
  15828. index: index,
  15829. face: null,
  15830. object: object
  15831. } );
  15832. }
  15833. }
  15834. if ( geometry.isBufferGeometry ) {
  15835. var index = geometry.index;
  15836. var attributes = geometry.attributes;
  15837. var positions = attributes.position.array;
  15838. if ( index !== null ) {
  15839. var indices = index.array;
  15840. for ( var i = 0, il = indices.length; i < il; i ++ ) {
  15841. var a = indices[ i ];
  15842. position.fromArray( positions, a * 3 );
  15843. testPoint( position, a );
  15844. }
  15845. } else {
  15846. for ( var i = 0, l = positions.length / 3; i < l; i ++ ) {
  15847. position.fromArray( positions, i * 3 );
  15848. testPoint( position, i );
  15849. }
  15850. }
  15851. } else {
  15852. var vertices = geometry.vertices;
  15853. for ( var i = 0, l = vertices.length; i < l; i ++ ) {
  15854. testPoint( vertices[ i ], i );
  15855. }
  15856. }
  15857. };
  15858. }() ),
  15859. clone: function () {
  15860. return new this.constructor( this.geometry, this.material ).copy( this );
  15861. }
  15862. } );
  15863. /**
  15864. * @author mrdoob / http://mrdoob.com/
  15865. */
  15866. function VideoTexture( video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  15867. Texture.call( this, video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  15868. this.format = format !== undefined ? format : RGBFormat;
  15869. this.minFilter = minFilter !== undefined ? minFilter : LinearFilter;
  15870. this.magFilter = magFilter !== undefined ? magFilter : LinearFilter;
  15871. this.generateMipmaps = false;
  15872. }
  15873. VideoTexture.prototype = Object.assign( Object.create( Texture.prototype ), {
  15874. constructor: VideoTexture,
  15875. isVideoTexture: true,
  15876. update: function () {
  15877. var video = this.image;
  15878. if ( video.readyState >= video.HAVE_CURRENT_DATA ) {
  15879. this.needsUpdate = true;
  15880. }
  15881. }
  15882. } );
  15883. /**
  15884. * @author alteredq / http://alteredqualia.com/
  15885. */
  15886. function CompressedTexture( mipmaps, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, encoding ) {
  15887. Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding );
  15888. this.image = { width: width, height: height };
  15889. this.mipmaps = mipmaps;
  15890. // no flipping for cube textures
  15891. // (also flipping doesn't work for compressed textures )
  15892. this.flipY = false;
  15893. // can't generate mipmaps for compressed textures
  15894. // mips must be embedded in DDS files
  15895. this.generateMipmaps = false;
  15896. }
  15897. CompressedTexture.prototype = Object.create( Texture.prototype );
  15898. CompressedTexture.prototype.constructor = CompressedTexture;
  15899. CompressedTexture.prototype.isCompressedTexture = true;
  15900. /**
  15901. * @author mrdoob / http://mrdoob.com/
  15902. */
  15903. function CanvasTexture( canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  15904. Texture.call( this, canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  15905. this.needsUpdate = true;
  15906. }
  15907. CanvasTexture.prototype = Object.create( Texture.prototype );
  15908. CanvasTexture.prototype.constructor = CanvasTexture;
  15909. CanvasTexture.prototype.isCanvasTexture = true;
  15910. /**
  15911. * @author Matt DesLauriers / @mattdesl
  15912. * @author atix / arthursilber.de
  15913. */
  15914. function DepthTexture( width, height, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, format ) {
  15915. format = format !== undefined ? format : DepthFormat;
  15916. if ( format !== DepthFormat && format !== DepthStencilFormat ) {
  15917. throw new Error( 'DepthTexture format must be either THREE.DepthFormat or THREE.DepthStencilFormat' );
  15918. }
  15919. if ( type === undefined && format === DepthFormat ) type = UnsignedShortType;
  15920. if ( type === undefined && format === DepthStencilFormat ) type = UnsignedInt248Type;
  15921. Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  15922. this.image = { width: width, height: height };
  15923. this.magFilter = magFilter !== undefined ? magFilter : NearestFilter;
  15924. this.minFilter = minFilter !== undefined ? minFilter : NearestFilter;
  15925. this.flipY = false;
  15926. this.generateMipmaps = false;
  15927. }
  15928. DepthTexture.prototype = Object.create( Texture.prototype );
  15929. DepthTexture.prototype.constructor = DepthTexture;
  15930. DepthTexture.prototype.isDepthTexture = true;
  15931. /**
  15932. * @author mrdoob / http://mrdoob.com/
  15933. * @author Mugen87 / https://github.com/Mugen87
  15934. */
  15935. function WireframeGeometry( geometry ) {
  15936. BufferGeometry.call( this );
  15937. this.type = 'WireframeGeometry';
  15938. // buffer
  15939. var vertices = [];
  15940. // helper variables
  15941. var i, j, l, o, ol;
  15942. var edge = [ 0, 0 ], edges = {}, e, edge1, edge2;
  15943. var key, keys = [ 'a', 'b', 'c' ];
  15944. var vertex;
  15945. // different logic for Geometry and BufferGeometry
  15946. if ( geometry && geometry.isGeometry ) {
  15947. // create a data structure that contains all edges without duplicates
  15948. var faces = geometry.faces;
  15949. for ( i = 0, l = faces.length; i < l; i ++ ) {
  15950. var face = faces[ i ];
  15951. for ( j = 0; j < 3; j ++ ) {
  15952. edge1 = face[ keys[ j ] ];
  15953. edge2 = face[ keys[ ( j + 1 ) % 3 ] ];
  15954. edge[ 0 ] = Math.min( edge1, edge2 ); // sorting prevents duplicates
  15955. edge[ 1 ] = Math.max( edge1, edge2 );
  15956. key = edge[ 0 ] + ',' + edge[ 1 ];
  15957. if ( edges[ key ] === undefined ) {
  15958. edges[ key ] = { index1: edge[ 0 ], index2: edge[ 1 ] };
  15959. }
  15960. }
  15961. }
  15962. // generate vertices
  15963. for ( key in edges ) {
  15964. e = edges[ key ];
  15965. vertex = geometry.vertices[ e.index1 ];
  15966. vertices.push( vertex.x, vertex.y, vertex.z );
  15967. vertex = geometry.vertices[ e.index2 ];
  15968. vertices.push( vertex.x, vertex.y, vertex.z );
  15969. }
  15970. } else if ( geometry && geometry.isBufferGeometry ) {
  15971. var position, indices, groups;
  15972. var group, start, count;
  15973. var index1, index2;
  15974. vertex = new Vector3();
  15975. if ( geometry.index !== null ) {
  15976. // indexed BufferGeometry
  15977. position = geometry.attributes.position;
  15978. indices = geometry.index;
  15979. groups = geometry.groups;
  15980. if ( groups.length === 0 ) {
  15981. groups = [ { start: 0, count: indices.count, materialIndex: 0 } ];
  15982. }
  15983. // create a data structure that contains all eges without duplicates
  15984. for ( o = 0, ol = groups.length; o < ol; ++ o ) {
  15985. group = groups[ o ];
  15986. start = group.start;
  15987. count = group.count;
  15988. for ( i = start, l = ( start + count ); i < l; i += 3 ) {
  15989. for ( j = 0; j < 3; j ++ ) {
  15990. edge1 = indices.getX( i + j );
  15991. edge2 = indices.getX( i + ( j + 1 ) % 3 );
  15992. edge[ 0 ] = Math.min( edge1, edge2 ); // sorting prevents duplicates
  15993. edge[ 1 ] = Math.max( edge1, edge2 );
  15994. key = edge[ 0 ] + ',' + edge[ 1 ];
  15995. if ( edges[ key ] === undefined ) {
  15996. edges[ key ] = { index1: edge[ 0 ], index2: edge[ 1 ] };
  15997. }
  15998. }
  15999. }
  16000. }
  16001. // generate vertices
  16002. for ( key in edges ) {
  16003. e = edges[ key ];
  16004. vertex.fromBufferAttribute( position, e.index1 );
  16005. vertices.push( vertex.x, vertex.y, vertex.z );
  16006. vertex.fromBufferAttribute( position, e.index2 );
  16007. vertices.push( vertex.x, vertex.y, vertex.z );
  16008. }
  16009. } else {
  16010. // non-indexed BufferGeometry
  16011. position = geometry.attributes.position;
  16012. for ( i = 0, l = ( position.count / 3 ); i < l; i ++ ) {
  16013. for ( j = 0; j < 3; j ++ ) {
  16014. // three edges per triangle, an edge is represented as (index1, index2)
  16015. // e.g. the first triangle has the following edges: (0,1),(1,2),(2,0)
  16016. index1 = 3 * i + j;
  16017. vertex.fromBufferAttribute( position, index1 );
  16018. vertices.push( vertex.x, vertex.y, vertex.z );
  16019. index2 = 3 * i + ( ( j + 1 ) % 3 );
  16020. vertex.fromBufferAttribute( position, index2 );
  16021. vertices.push( vertex.x, vertex.y, vertex.z );
  16022. }
  16023. }
  16024. }
  16025. }
  16026. // build geometry
  16027. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  16028. }
  16029. WireframeGeometry.prototype = Object.create( BufferGeometry.prototype );
  16030. WireframeGeometry.prototype.constructor = WireframeGeometry;
  16031. /**
  16032. * @author zz85 / https://github.com/zz85
  16033. * @author Mugen87 / https://github.com/Mugen87
  16034. *
  16035. * Parametric Surfaces Geometry
  16036. * based on the brilliant article by @prideout http://prideout.net/blog/?p=44
  16037. */
  16038. // ParametricGeometry
  16039. function ParametricGeometry( func, slices, stacks ) {
  16040. Geometry.call( this );
  16041. this.type = 'ParametricGeometry';
  16042. this.parameters = {
  16043. func: func,
  16044. slices: slices,
  16045. stacks: stacks
  16046. };
  16047. this.fromBufferGeometry( new ParametricBufferGeometry( func, slices, stacks ) );
  16048. this.mergeVertices();
  16049. }
  16050. ParametricGeometry.prototype = Object.create( Geometry.prototype );
  16051. ParametricGeometry.prototype.constructor = ParametricGeometry;
  16052. // ParametricBufferGeometry
  16053. function ParametricBufferGeometry( func, slices, stacks ) {
  16054. BufferGeometry.call( this );
  16055. this.type = 'ParametricBufferGeometry';
  16056. this.parameters = {
  16057. func: func,
  16058. slices: slices,
  16059. stacks: stacks
  16060. };
  16061. // buffers
  16062. var indices = [];
  16063. var vertices = [];
  16064. var normals = [];
  16065. var uvs = [];
  16066. var EPS = 0.00001;
  16067. var normal = new Vector3();
  16068. var p0 = new Vector3(), p1 = new Vector3();
  16069. var pu = new Vector3(), pv = new Vector3();
  16070. var i, j;
  16071. if ( func.length < 3 ) {
  16072. console.error( 'THREE.ParametricGeometry: Function must now modify a Vector3 as third parameter.' );
  16073. }
  16074. // generate vertices, normals and uvs
  16075. var sliceCount = slices + 1;
  16076. for ( i = 0; i <= stacks; i ++ ) {
  16077. var v = i / stacks;
  16078. for ( j = 0; j <= slices; j ++ ) {
  16079. var u = j / slices;
  16080. // vertex
  16081. func( u, v, p0 );
  16082. vertices.push( p0.x, p0.y, p0.z );
  16083. // normal
  16084. // approximate tangent vectors via finite differences
  16085. if ( u - EPS >= 0 ) {
  16086. func( u - EPS, v, p1 );
  16087. pu.subVectors( p0, p1 );
  16088. } else {
  16089. func( u + EPS, v, p1 );
  16090. pu.subVectors( p1, p0 );
  16091. }
  16092. if ( v - EPS >= 0 ) {
  16093. func( u, v - EPS, p1 );
  16094. pv.subVectors( p0, p1 );
  16095. } else {
  16096. func( u, v + EPS, p1 );
  16097. pv.subVectors( p1, p0 );
  16098. }
  16099. // cross product of tangent vectors returns surface normal
  16100. normal.crossVectors( pu, pv ).normalize();
  16101. normals.push( normal.x, normal.y, normal.z );
  16102. // uv
  16103. uvs.push( u, v );
  16104. }
  16105. }
  16106. // generate indices
  16107. for ( i = 0; i < stacks; i ++ ) {
  16108. for ( j = 0; j < slices; j ++ ) {
  16109. var a = i * sliceCount + j;
  16110. var b = i * sliceCount + j + 1;
  16111. var c = ( i + 1 ) * sliceCount + j + 1;
  16112. var d = ( i + 1 ) * sliceCount + j;
  16113. // faces one and two
  16114. indices.push( a, b, d );
  16115. indices.push( b, c, d );
  16116. }
  16117. }
  16118. // build geometry
  16119. this.setIndex( indices );
  16120. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  16121. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  16122. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  16123. }
  16124. ParametricBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  16125. ParametricBufferGeometry.prototype.constructor = ParametricBufferGeometry;
  16126. /**
  16127. * @author clockworkgeek / https://github.com/clockworkgeek
  16128. * @author timothypratley / https://github.com/timothypratley
  16129. * @author WestLangley / http://github.com/WestLangley
  16130. * @author Mugen87 / https://github.com/Mugen87
  16131. */
  16132. // PolyhedronGeometry
  16133. function PolyhedronGeometry( vertices, indices, radius, detail ) {
  16134. Geometry.call( this );
  16135. this.type = 'PolyhedronGeometry';
  16136. this.parameters = {
  16137. vertices: vertices,
  16138. indices: indices,
  16139. radius: radius,
  16140. detail: detail
  16141. };
  16142. this.fromBufferGeometry( new PolyhedronBufferGeometry( vertices, indices, radius, detail ) );
  16143. this.mergeVertices();
  16144. }
  16145. PolyhedronGeometry.prototype = Object.create( Geometry.prototype );
  16146. PolyhedronGeometry.prototype.constructor = PolyhedronGeometry;
  16147. // PolyhedronBufferGeometry
  16148. function PolyhedronBufferGeometry( vertices, indices, radius, detail ) {
  16149. BufferGeometry.call( this );
  16150. this.type = 'PolyhedronBufferGeometry';
  16151. this.parameters = {
  16152. vertices: vertices,
  16153. indices: indices,
  16154. radius: radius,
  16155. detail: detail
  16156. };
  16157. radius = radius || 1;
  16158. detail = detail || 0;
  16159. // default buffer data
  16160. var vertexBuffer = [];
  16161. var uvBuffer = [];
  16162. // the subdivision creates the vertex buffer data
  16163. subdivide( detail );
  16164. // all vertices should lie on a conceptual sphere with a given radius
  16165. appplyRadius( radius );
  16166. // finally, create the uv data
  16167. generateUVs();
  16168. // build non-indexed geometry
  16169. this.addAttribute( 'position', new Float32BufferAttribute( vertexBuffer, 3 ) );
  16170. this.addAttribute( 'normal', new Float32BufferAttribute( vertexBuffer.slice(), 3 ) );
  16171. this.addAttribute( 'uv', new Float32BufferAttribute( uvBuffer, 2 ) );
  16172. if ( detail === 0 ) {
  16173. this.computeVertexNormals(); // flat normals
  16174. } else {
  16175. this.normalizeNormals(); // smooth normals
  16176. }
  16177. // helper functions
  16178. function subdivide( detail ) {
  16179. var a = new Vector3();
  16180. var b = new Vector3();
  16181. var c = new Vector3();
  16182. // iterate over all faces and apply a subdivison with the given detail value
  16183. for ( var i = 0; i < indices.length; i += 3 ) {
  16184. // get the vertices of the face
  16185. getVertexByIndex( indices[ i + 0 ], a );
  16186. getVertexByIndex( indices[ i + 1 ], b );
  16187. getVertexByIndex( indices[ i + 2 ], c );
  16188. // perform subdivision
  16189. subdivideFace( a, b, c, detail );
  16190. }
  16191. }
  16192. function subdivideFace( a, b, c, detail ) {
  16193. var cols = Math.pow( 2, detail );
  16194. // we use this multidimensional array as a data structure for creating the subdivision
  16195. var v = [];
  16196. var i, j;
  16197. // construct all of the vertices for this subdivision
  16198. for ( i = 0; i <= cols; i ++ ) {
  16199. v[ i ] = [];
  16200. var aj = a.clone().lerp( c, i / cols );
  16201. var bj = b.clone().lerp( c, i / cols );
  16202. var rows = cols - i;
  16203. for ( j = 0; j <= rows; j ++ ) {
  16204. if ( j === 0 && i === cols ) {
  16205. v[ i ][ j ] = aj;
  16206. } else {
  16207. v[ i ][ j ] = aj.clone().lerp( bj, j / rows );
  16208. }
  16209. }
  16210. }
  16211. // construct all of the faces
  16212. for ( i = 0; i < cols; i ++ ) {
  16213. for ( j = 0; j < 2 * ( cols - i ) - 1; j ++ ) {
  16214. var k = Math.floor( j / 2 );
  16215. if ( j % 2 === 0 ) {
  16216. pushVertex( v[ i ][ k + 1 ] );
  16217. pushVertex( v[ i + 1 ][ k ] );
  16218. pushVertex( v[ i ][ k ] );
  16219. } else {
  16220. pushVertex( v[ i ][ k + 1 ] );
  16221. pushVertex( v[ i + 1 ][ k + 1 ] );
  16222. pushVertex( v[ i + 1 ][ k ] );
  16223. }
  16224. }
  16225. }
  16226. }
  16227. function appplyRadius( radius ) {
  16228. var vertex = new Vector3();
  16229. // iterate over the entire buffer and apply the radius to each vertex
  16230. for ( var i = 0; i < vertexBuffer.length; i += 3 ) {
  16231. vertex.x = vertexBuffer[ i + 0 ];
  16232. vertex.y = vertexBuffer[ i + 1 ];
  16233. vertex.z = vertexBuffer[ i + 2 ];
  16234. vertex.normalize().multiplyScalar( radius );
  16235. vertexBuffer[ i + 0 ] = vertex.x;
  16236. vertexBuffer[ i + 1 ] = vertex.y;
  16237. vertexBuffer[ i + 2 ] = vertex.z;
  16238. }
  16239. }
  16240. function generateUVs() {
  16241. var vertex = new Vector3();
  16242. for ( var i = 0; i < vertexBuffer.length; i += 3 ) {
  16243. vertex.x = vertexBuffer[ i + 0 ];
  16244. vertex.y = vertexBuffer[ i + 1 ];
  16245. vertex.z = vertexBuffer[ i + 2 ];
  16246. var u = azimuth( vertex ) / 2 / Math.PI + 0.5;
  16247. var v = inclination( vertex ) / Math.PI + 0.5;
  16248. uvBuffer.push( u, 1 - v );
  16249. }
  16250. correctUVs();
  16251. correctSeam();
  16252. }
  16253. function correctSeam() {
  16254. // handle case when face straddles the seam, see #3269
  16255. for ( var i = 0; i < uvBuffer.length; i += 6 ) {
  16256. // uv data of a single face
  16257. var x0 = uvBuffer[ i + 0 ];
  16258. var x1 = uvBuffer[ i + 2 ];
  16259. var x2 = uvBuffer[ i + 4 ];
  16260. var max = Math.max( x0, x1, x2 );
  16261. var min = Math.min( x0, x1, x2 );
  16262. // 0.9 is somewhat arbitrary
  16263. if ( max > 0.9 && min < 0.1 ) {
  16264. if ( x0 < 0.2 ) uvBuffer[ i + 0 ] += 1;
  16265. if ( x1 < 0.2 ) uvBuffer[ i + 2 ] += 1;
  16266. if ( x2 < 0.2 ) uvBuffer[ i + 4 ] += 1;
  16267. }
  16268. }
  16269. }
  16270. function pushVertex( vertex ) {
  16271. vertexBuffer.push( vertex.x, vertex.y, vertex.z );
  16272. }
  16273. function getVertexByIndex( index, vertex ) {
  16274. var stride = index * 3;
  16275. vertex.x = vertices[ stride + 0 ];
  16276. vertex.y = vertices[ stride + 1 ];
  16277. vertex.z = vertices[ stride + 2 ];
  16278. }
  16279. function correctUVs() {
  16280. var a = new Vector3();
  16281. var b = new Vector3();
  16282. var c = new Vector3();
  16283. var centroid = new Vector3();
  16284. var uvA = new Vector2();
  16285. var uvB = new Vector2();
  16286. var uvC = new Vector2();
  16287. for ( var i = 0, j = 0; i < vertexBuffer.length; i += 9, j += 6 ) {
  16288. a.set( vertexBuffer[ i + 0 ], vertexBuffer[ i + 1 ], vertexBuffer[ i + 2 ] );
  16289. b.set( vertexBuffer[ i + 3 ], vertexBuffer[ i + 4 ], vertexBuffer[ i + 5 ] );
  16290. c.set( vertexBuffer[ i + 6 ], vertexBuffer[ i + 7 ], vertexBuffer[ i + 8 ] );
  16291. uvA.set( uvBuffer[ j + 0 ], uvBuffer[ j + 1 ] );
  16292. uvB.set( uvBuffer[ j + 2 ], uvBuffer[ j + 3 ] );
  16293. uvC.set( uvBuffer[ j + 4 ], uvBuffer[ j + 5 ] );
  16294. centroid.copy( a ).add( b ).add( c ).divideScalar( 3 );
  16295. var azi = azimuth( centroid );
  16296. correctUV( uvA, j + 0, a, azi );
  16297. correctUV( uvB, j + 2, b, azi );
  16298. correctUV( uvC, j + 4, c, azi );
  16299. }
  16300. }
  16301. function correctUV( uv, stride, vector, azimuth ) {
  16302. if ( ( azimuth < 0 ) && ( uv.x === 1 ) ) {
  16303. uvBuffer[ stride ] = uv.x - 1;
  16304. }
  16305. if ( ( vector.x === 0 ) && ( vector.z === 0 ) ) {
  16306. uvBuffer[ stride ] = azimuth / 2 / Math.PI + 0.5;
  16307. }
  16308. }
  16309. // Angle around the Y axis, counter-clockwise when looking from above.
  16310. function azimuth( vector ) {
  16311. return Math.atan2( vector.z, - vector.x );
  16312. }
  16313. // Angle above the XZ plane.
  16314. function inclination( vector ) {
  16315. return Math.atan2( - vector.y, Math.sqrt( ( vector.x * vector.x ) + ( vector.z * vector.z ) ) );
  16316. }
  16317. }
  16318. PolyhedronBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  16319. PolyhedronBufferGeometry.prototype.constructor = PolyhedronBufferGeometry;
  16320. /**
  16321. * @author timothypratley / https://github.com/timothypratley
  16322. * @author Mugen87 / https://github.com/Mugen87
  16323. */
  16324. // TetrahedronGeometry
  16325. function TetrahedronGeometry( radius, detail ) {
  16326. Geometry.call( this );
  16327. this.type = 'TetrahedronGeometry';
  16328. this.parameters = {
  16329. radius: radius,
  16330. detail: detail
  16331. };
  16332. this.fromBufferGeometry( new TetrahedronBufferGeometry( radius, detail ) );
  16333. this.mergeVertices();
  16334. }
  16335. TetrahedronGeometry.prototype = Object.create( Geometry.prototype );
  16336. TetrahedronGeometry.prototype.constructor = TetrahedronGeometry;
  16337. // TetrahedronBufferGeometry
  16338. function TetrahedronBufferGeometry( radius, detail ) {
  16339. var vertices = [
  16340. 1, 1, 1, - 1, - 1, 1, - 1, 1, - 1, 1, - 1, - 1
  16341. ];
  16342. var indices = [
  16343. 2, 1, 0, 0, 3, 2, 1, 3, 0, 2, 3, 1
  16344. ];
  16345. PolyhedronBufferGeometry.call( this, vertices, indices, radius, detail );
  16346. this.type = 'TetrahedronBufferGeometry';
  16347. this.parameters = {
  16348. radius: radius,
  16349. detail: detail
  16350. };
  16351. }
  16352. TetrahedronBufferGeometry.prototype = Object.create( PolyhedronBufferGeometry.prototype );
  16353. TetrahedronBufferGeometry.prototype.constructor = TetrahedronBufferGeometry;
  16354. /**
  16355. * @author timothypratley / https://github.com/timothypratley
  16356. * @author Mugen87 / https://github.com/Mugen87
  16357. */
  16358. // OctahedronGeometry
  16359. function OctahedronGeometry( radius, detail ) {
  16360. Geometry.call( this );
  16361. this.type = 'OctahedronGeometry';
  16362. this.parameters = {
  16363. radius: radius,
  16364. detail: detail
  16365. };
  16366. this.fromBufferGeometry( new OctahedronBufferGeometry( radius, detail ) );
  16367. this.mergeVertices();
  16368. }
  16369. OctahedronGeometry.prototype = Object.create( Geometry.prototype );
  16370. OctahedronGeometry.prototype.constructor = OctahedronGeometry;
  16371. // OctahedronBufferGeometry
  16372. function OctahedronBufferGeometry( radius, detail ) {
  16373. var vertices = [
  16374. 1, 0, 0, - 1, 0, 0, 0, 1, 0,
  16375. 0, - 1, 0, 0, 0, 1, 0, 0, - 1
  16376. ];
  16377. var indices = [
  16378. 0, 2, 4, 0, 4, 3, 0, 3, 5,
  16379. 0, 5, 2, 1, 2, 5, 1, 5, 3,
  16380. 1, 3, 4, 1, 4, 2
  16381. ];
  16382. PolyhedronBufferGeometry.call( this, vertices, indices, radius, detail );
  16383. this.type = 'OctahedronBufferGeometry';
  16384. this.parameters = {
  16385. radius: radius,
  16386. detail: detail
  16387. };
  16388. }
  16389. OctahedronBufferGeometry.prototype = Object.create( PolyhedronBufferGeometry.prototype );
  16390. OctahedronBufferGeometry.prototype.constructor = OctahedronBufferGeometry;
  16391. /**
  16392. * @author timothypratley / https://github.com/timothypratley
  16393. * @author Mugen87 / https://github.com/Mugen87
  16394. */
  16395. // IcosahedronGeometry
  16396. function IcosahedronGeometry( radius, detail ) {
  16397. Geometry.call( this );
  16398. this.type = 'IcosahedronGeometry';
  16399. this.parameters = {
  16400. radius: radius,
  16401. detail: detail
  16402. };
  16403. this.fromBufferGeometry( new IcosahedronBufferGeometry( radius, detail ) );
  16404. this.mergeVertices();
  16405. }
  16406. IcosahedronGeometry.prototype = Object.create( Geometry.prototype );
  16407. IcosahedronGeometry.prototype.constructor = IcosahedronGeometry;
  16408. // IcosahedronBufferGeometry
  16409. function IcosahedronBufferGeometry( radius, detail ) {
  16410. var t = ( 1 + Math.sqrt( 5 ) ) / 2;
  16411. var vertices = [
  16412. - 1, t, 0, 1, t, 0, - 1, - t, 0, 1, - t, 0,
  16413. 0, - 1, t, 0, 1, t, 0, - 1, - t, 0, 1, - t,
  16414. t, 0, - 1, t, 0, 1, - t, 0, - 1, - t, 0, 1
  16415. ];
  16416. var indices = [
  16417. 0, 11, 5, 0, 5, 1, 0, 1, 7, 0, 7, 10, 0, 10, 11,
  16418. 1, 5, 9, 5, 11, 4, 11, 10, 2, 10, 7, 6, 7, 1, 8,
  16419. 3, 9, 4, 3, 4, 2, 3, 2, 6, 3, 6, 8, 3, 8, 9,
  16420. 4, 9, 5, 2, 4, 11, 6, 2, 10, 8, 6, 7, 9, 8, 1
  16421. ];
  16422. PolyhedronBufferGeometry.call( this, vertices, indices, radius, detail );
  16423. this.type = 'IcosahedronBufferGeometry';
  16424. this.parameters = {
  16425. radius: radius,
  16426. detail: detail
  16427. };
  16428. }
  16429. IcosahedronBufferGeometry.prototype = Object.create( PolyhedronBufferGeometry.prototype );
  16430. IcosahedronBufferGeometry.prototype.constructor = IcosahedronBufferGeometry;
  16431. /**
  16432. * @author Abe Pazos / https://hamoid.com
  16433. * @author Mugen87 / https://github.com/Mugen87
  16434. */
  16435. // DodecahedronGeometry
  16436. function DodecahedronGeometry( radius, detail ) {
  16437. Geometry.call( this );
  16438. this.type = 'DodecahedronGeometry';
  16439. this.parameters = {
  16440. radius: radius,
  16441. detail: detail
  16442. };
  16443. this.fromBufferGeometry( new DodecahedronBufferGeometry( radius, detail ) );
  16444. this.mergeVertices();
  16445. }
  16446. DodecahedronGeometry.prototype = Object.create( Geometry.prototype );
  16447. DodecahedronGeometry.prototype.constructor = DodecahedronGeometry;
  16448. // DodecahedronBufferGeometry
  16449. function DodecahedronBufferGeometry( radius, detail ) {
  16450. var t = ( 1 + Math.sqrt( 5 ) ) / 2;
  16451. var r = 1 / t;
  16452. var vertices = [
  16453. // (±1, ±1, ±1)
  16454. - 1, - 1, - 1, - 1, - 1, 1,
  16455. - 1, 1, - 1, - 1, 1, 1,
  16456. 1, - 1, - 1, 1, - 1, 1,
  16457. 1, 1, - 1, 1, 1, 1,
  16458. // (0, ±1/φ, ±φ)
  16459. 0, - r, - t, 0, - r, t,
  16460. 0, r, - t, 0, r, t,
  16461. // (±1/φ, ±φ, 0)
  16462. - r, - t, 0, - r, t, 0,
  16463. r, - t, 0, r, t, 0,
  16464. // (±φ, 0, ±1/φ)
  16465. - t, 0, - r, t, 0, - r,
  16466. - t, 0, r, t, 0, r
  16467. ];
  16468. var indices = [
  16469. 3, 11, 7, 3, 7, 15, 3, 15, 13,
  16470. 7, 19, 17, 7, 17, 6, 7, 6, 15,
  16471. 17, 4, 8, 17, 8, 10, 17, 10, 6,
  16472. 8, 0, 16, 8, 16, 2, 8, 2, 10,
  16473. 0, 12, 1, 0, 1, 18, 0, 18, 16,
  16474. 6, 10, 2, 6, 2, 13, 6, 13, 15,
  16475. 2, 16, 18, 2, 18, 3, 2, 3, 13,
  16476. 18, 1, 9, 18, 9, 11, 18, 11, 3,
  16477. 4, 14, 12, 4, 12, 0, 4, 0, 8,
  16478. 11, 9, 5, 11, 5, 19, 11, 19, 7,
  16479. 19, 5, 14, 19, 14, 4, 19, 4, 17,
  16480. 1, 12, 14, 1, 14, 5, 1, 5, 9
  16481. ];
  16482. PolyhedronBufferGeometry.call( this, vertices, indices, radius, detail );
  16483. this.type = 'DodecahedronBufferGeometry';
  16484. this.parameters = {
  16485. radius: radius,
  16486. detail: detail
  16487. };
  16488. }
  16489. DodecahedronBufferGeometry.prototype = Object.create( PolyhedronBufferGeometry.prototype );
  16490. DodecahedronBufferGeometry.prototype.constructor = DodecahedronBufferGeometry;
  16491. /**
  16492. * @author oosmoxiecode / https://github.com/oosmoxiecode
  16493. * @author WestLangley / https://github.com/WestLangley
  16494. * @author zz85 / https://github.com/zz85
  16495. * @author miningold / https://github.com/miningold
  16496. * @author jonobr1 / https://github.com/jonobr1
  16497. * @author Mugen87 / https://github.com/Mugen87
  16498. *
  16499. */
  16500. // TubeGeometry
  16501. function TubeGeometry( path, tubularSegments, radius, radialSegments, closed, taper ) {
  16502. Geometry.call( this );
  16503. this.type = 'TubeGeometry';
  16504. this.parameters = {
  16505. path: path,
  16506. tubularSegments: tubularSegments,
  16507. radius: radius,
  16508. radialSegments: radialSegments,
  16509. closed: closed
  16510. };
  16511. if ( taper !== undefined ) console.warn( 'THREE.TubeGeometry: taper has been removed.' );
  16512. var bufferGeometry = new TubeBufferGeometry( path, tubularSegments, radius, radialSegments, closed );
  16513. // expose internals
  16514. this.tangents = bufferGeometry.tangents;
  16515. this.normals = bufferGeometry.normals;
  16516. this.binormals = bufferGeometry.binormals;
  16517. // create geometry
  16518. this.fromBufferGeometry( bufferGeometry );
  16519. this.mergeVertices();
  16520. }
  16521. TubeGeometry.prototype = Object.create( Geometry.prototype );
  16522. TubeGeometry.prototype.constructor = TubeGeometry;
  16523. // TubeBufferGeometry
  16524. function TubeBufferGeometry( path, tubularSegments, radius, radialSegments, closed ) {
  16525. BufferGeometry.call( this );
  16526. this.type = 'TubeBufferGeometry';
  16527. this.parameters = {
  16528. path: path,
  16529. tubularSegments: tubularSegments,
  16530. radius: radius,
  16531. radialSegments: radialSegments,
  16532. closed: closed
  16533. };
  16534. tubularSegments = tubularSegments || 64;
  16535. radius = radius || 1;
  16536. radialSegments = radialSegments || 8;
  16537. closed = closed || false;
  16538. var frames = path.computeFrenetFrames( tubularSegments, closed );
  16539. // expose internals
  16540. this.tangents = frames.tangents;
  16541. this.normals = frames.normals;
  16542. this.binormals = frames.binormals;
  16543. // helper variables
  16544. var vertex = new Vector3();
  16545. var normal = new Vector3();
  16546. var uv = new Vector2();
  16547. var P = new Vector3();
  16548. var i, j;
  16549. // buffer
  16550. var vertices = [];
  16551. var normals = [];
  16552. var uvs = [];
  16553. var indices = [];
  16554. // create buffer data
  16555. generateBufferData();
  16556. // build geometry
  16557. this.setIndex( indices );
  16558. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  16559. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  16560. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  16561. // functions
  16562. function generateBufferData() {
  16563. for ( i = 0; i < tubularSegments; i ++ ) {
  16564. generateSegment( i );
  16565. }
  16566. // if the geometry is not closed, generate the last row of vertices and normals
  16567. // at the regular position on the given path
  16568. //
  16569. // if the geometry is closed, duplicate the first row of vertices and normals (uvs will differ)
  16570. generateSegment( ( closed === false ) ? tubularSegments : 0 );
  16571. // uvs are generated in a separate function.
  16572. // this makes it easy compute correct values for closed geometries
  16573. generateUVs();
  16574. // finally create faces
  16575. generateIndices();
  16576. }
  16577. function generateSegment( i ) {
  16578. // we use getPointAt to sample evenly distributed points from the given path
  16579. P = path.getPointAt( i / tubularSegments, P );
  16580. // retrieve corresponding normal and binormal
  16581. var N = frames.normals[ i ];
  16582. var B = frames.binormals[ i ];
  16583. // generate normals and vertices for the current segment
  16584. for ( j = 0; j <= radialSegments; j ++ ) {
  16585. var v = j / radialSegments * Math.PI * 2;
  16586. var sin = Math.sin( v );
  16587. var cos = - Math.cos( v );
  16588. // normal
  16589. normal.x = ( cos * N.x + sin * B.x );
  16590. normal.y = ( cos * N.y + sin * B.y );
  16591. normal.z = ( cos * N.z + sin * B.z );
  16592. normal.normalize();
  16593. normals.push( normal.x, normal.y, normal.z );
  16594. // vertex
  16595. vertex.x = P.x + radius * normal.x;
  16596. vertex.y = P.y + radius * normal.y;
  16597. vertex.z = P.z + radius * normal.z;
  16598. vertices.push( vertex.x, vertex.y, vertex.z );
  16599. }
  16600. }
  16601. function generateIndices() {
  16602. for ( j = 1; j <= tubularSegments; j ++ ) {
  16603. for ( i = 1; i <= radialSegments; i ++ ) {
  16604. var a = ( radialSegments + 1 ) * ( j - 1 ) + ( i - 1 );
  16605. var b = ( radialSegments + 1 ) * j + ( i - 1 );
  16606. var c = ( radialSegments + 1 ) * j + i;
  16607. var d = ( radialSegments + 1 ) * ( j - 1 ) + i;
  16608. // faces
  16609. indices.push( a, b, d );
  16610. indices.push( b, c, d );
  16611. }
  16612. }
  16613. }
  16614. function generateUVs() {
  16615. for ( i = 0; i <= tubularSegments; i ++ ) {
  16616. for ( j = 0; j <= radialSegments; j ++ ) {
  16617. uv.x = i / tubularSegments;
  16618. uv.y = j / radialSegments;
  16619. uvs.push( uv.x, uv.y );
  16620. }
  16621. }
  16622. }
  16623. }
  16624. TubeBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  16625. TubeBufferGeometry.prototype.constructor = TubeBufferGeometry;
  16626. TubeBufferGeometry.prototype.toJSON = function () {
  16627. var data = BufferGeometry.prototype.toJSON.call( this );
  16628. data.path = this.parameters.path.toJSON();
  16629. return data;
  16630. };
  16631. /**
  16632. * @author oosmoxiecode
  16633. * @author Mugen87 / https://github.com/Mugen87
  16634. *
  16635. * based on http://www.blackpawn.com/texts/pqtorus/
  16636. */
  16637. // TorusKnotGeometry
  16638. function TorusKnotGeometry( radius, tube, tubularSegments, radialSegments, p, q, heightScale ) {
  16639. Geometry.call( this );
  16640. this.type = 'TorusKnotGeometry';
  16641. this.parameters = {
  16642. radius: radius,
  16643. tube: tube,
  16644. tubularSegments: tubularSegments,
  16645. radialSegments: radialSegments,
  16646. p: p,
  16647. q: q
  16648. };
  16649. if ( heightScale !== undefined ) console.warn( 'THREE.TorusKnotGeometry: heightScale has been deprecated. Use .scale( x, y, z ) instead.' );
  16650. this.fromBufferGeometry( new TorusKnotBufferGeometry( radius, tube, tubularSegments, radialSegments, p, q ) );
  16651. this.mergeVertices();
  16652. }
  16653. TorusKnotGeometry.prototype = Object.create( Geometry.prototype );
  16654. TorusKnotGeometry.prototype.constructor = TorusKnotGeometry;
  16655. // TorusKnotBufferGeometry
  16656. function TorusKnotBufferGeometry( radius, tube, tubularSegments, radialSegments, p, q ) {
  16657. BufferGeometry.call( this );
  16658. this.type = 'TorusKnotBufferGeometry';
  16659. this.parameters = {
  16660. radius: radius,
  16661. tube: tube,
  16662. tubularSegments: tubularSegments,
  16663. radialSegments: radialSegments,
  16664. p: p,
  16665. q: q
  16666. };
  16667. radius = radius || 1;
  16668. tube = tube || 0.4;
  16669. tubularSegments = Math.floor( tubularSegments ) || 64;
  16670. radialSegments = Math.floor( radialSegments ) || 8;
  16671. p = p || 2;
  16672. q = q || 3;
  16673. // buffers
  16674. var indices = [];
  16675. var vertices = [];
  16676. var normals = [];
  16677. var uvs = [];
  16678. // helper variables
  16679. var i, j;
  16680. var vertex = new Vector3();
  16681. var normal = new Vector3();
  16682. var P1 = new Vector3();
  16683. var P2 = new Vector3();
  16684. var B = new Vector3();
  16685. var T = new Vector3();
  16686. var N = new Vector3();
  16687. // generate vertices, normals and uvs
  16688. for ( i = 0; i <= tubularSegments; ++ i ) {
  16689. // the radian "u" is used to calculate the position on the torus curve of the current tubular segement
  16690. var u = i / tubularSegments * p * Math.PI * 2;
  16691. // now we calculate two points. P1 is our current position on the curve, P2 is a little farther ahead.
  16692. // these points are used to create a special "coordinate space", which is necessary to calculate the correct vertex positions
  16693. calculatePositionOnCurve( u, p, q, radius, P1 );
  16694. calculatePositionOnCurve( u + 0.01, p, q, radius, P2 );
  16695. // calculate orthonormal basis
  16696. T.subVectors( P2, P1 );
  16697. N.addVectors( P2, P1 );
  16698. B.crossVectors( T, N );
  16699. N.crossVectors( B, T );
  16700. // normalize B, N. T can be ignored, we don't use it
  16701. B.normalize();
  16702. N.normalize();
  16703. for ( j = 0; j <= radialSegments; ++ j ) {
  16704. // now calculate the vertices. they are nothing more than an extrusion of the torus curve.
  16705. // because we extrude a shape in the xy-plane, there is no need to calculate a z-value.
  16706. var v = j / radialSegments * Math.PI * 2;
  16707. var cx = - tube * Math.cos( v );
  16708. var cy = tube * Math.sin( v );
  16709. // now calculate the final vertex position.
  16710. // first we orient the extrusion with our basis vectos, then we add it to the current position on the curve
  16711. vertex.x = P1.x + ( cx * N.x + cy * B.x );
  16712. vertex.y = P1.y + ( cx * N.y + cy * B.y );
  16713. vertex.z = P1.z + ( cx * N.z + cy * B.z );
  16714. vertices.push( vertex.x, vertex.y, vertex.z );
  16715. // normal (P1 is always the center/origin of the extrusion, thus we can use it to calculate the normal)
  16716. normal.subVectors( vertex, P1 ).normalize();
  16717. normals.push( normal.x, normal.y, normal.z );
  16718. // uv
  16719. uvs.push( i / tubularSegments );
  16720. uvs.push( j / radialSegments );
  16721. }
  16722. }
  16723. // generate indices
  16724. for ( j = 1; j <= tubularSegments; j ++ ) {
  16725. for ( i = 1; i <= radialSegments; i ++ ) {
  16726. // indices
  16727. var a = ( radialSegments + 1 ) * ( j - 1 ) + ( i - 1 );
  16728. var b = ( radialSegments + 1 ) * j + ( i - 1 );
  16729. var c = ( radialSegments + 1 ) * j + i;
  16730. var d = ( radialSegments + 1 ) * ( j - 1 ) + i;
  16731. // faces
  16732. indices.push( a, b, d );
  16733. indices.push( b, c, d );
  16734. }
  16735. }
  16736. // build geometry
  16737. this.setIndex( indices );
  16738. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  16739. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  16740. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  16741. // this function calculates the current position on the torus curve
  16742. function calculatePositionOnCurve( u, p, q, radius, position ) {
  16743. var cu = Math.cos( u );
  16744. var su = Math.sin( u );
  16745. var quOverP = q / p * u;
  16746. var cs = Math.cos( quOverP );
  16747. position.x = radius * ( 2 + cs ) * 0.5 * cu;
  16748. position.y = radius * ( 2 + cs ) * su * 0.5;
  16749. position.z = radius * Math.sin( quOverP ) * 0.5;
  16750. }
  16751. }
  16752. TorusKnotBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  16753. TorusKnotBufferGeometry.prototype.constructor = TorusKnotBufferGeometry;
  16754. /**
  16755. * @author oosmoxiecode
  16756. * @author mrdoob / http://mrdoob.com/
  16757. * @author Mugen87 / https://github.com/Mugen87
  16758. */
  16759. // TorusGeometry
  16760. function TorusGeometry( radius, tube, radialSegments, tubularSegments, arc ) {
  16761. Geometry.call( this );
  16762. this.type = 'TorusGeometry';
  16763. this.parameters = {
  16764. radius: radius,
  16765. tube: tube,
  16766. radialSegments: radialSegments,
  16767. tubularSegments: tubularSegments,
  16768. arc: arc
  16769. };
  16770. this.fromBufferGeometry( new TorusBufferGeometry( radius, tube, radialSegments, tubularSegments, arc ) );
  16771. this.mergeVertices();
  16772. }
  16773. TorusGeometry.prototype = Object.create( Geometry.prototype );
  16774. TorusGeometry.prototype.constructor = TorusGeometry;
  16775. // TorusBufferGeometry
  16776. function TorusBufferGeometry( radius, tube, radialSegments, tubularSegments, arc ) {
  16777. BufferGeometry.call( this );
  16778. this.type = 'TorusBufferGeometry';
  16779. this.parameters = {
  16780. radius: radius,
  16781. tube: tube,
  16782. radialSegments: radialSegments,
  16783. tubularSegments: tubularSegments,
  16784. arc: arc
  16785. };
  16786. radius = radius || 1;
  16787. tube = tube || 0.4;
  16788. radialSegments = Math.floor( radialSegments ) || 8;
  16789. tubularSegments = Math.floor( tubularSegments ) || 6;
  16790. arc = arc || Math.PI * 2;
  16791. // buffers
  16792. var indices = [];
  16793. var vertices = [];
  16794. var normals = [];
  16795. var uvs = [];
  16796. // helper variables
  16797. var center = new Vector3();
  16798. var vertex = new Vector3();
  16799. var normal = new Vector3();
  16800. var j, i;
  16801. // generate vertices, normals and uvs
  16802. for ( j = 0; j <= radialSegments; j ++ ) {
  16803. for ( i = 0; i <= tubularSegments; i ++ ) {
  16804. var u = i / tubularSegments * arc;
  16805. var v = j / radialSegments * Math.PI * 2;
  16806. // vertex
  16807. vertex.x = ( radius + tube * Math.cos( v ) ) * Math.cos( u );
  16808. vertex.y = ( radius + tube * Math.cos( v ) ) * Math.sin( u );
  16809. vertex.z = tube * Math.sin( v );
  16810. vertices.push( vertex.x, vertex.y, vertex.z );
  16811. // normal
  16812. center.x = radius * Math.cos( u );
  16813. center.y = radius * Math.sin( u );
  16814. normal.subVectors( vertex, center ).normalize();
  16815. normals.push( normal.x, normal.y, normal.z );
  16816. // uv
  16817. uvs.push( i / tubularSegments );
  16818. uvs.push( j / radialSegments );
  16819. }
  16820. }
  16821. // generate indices
  16822. for ( j = 1; j <= radialSegments; j ++ ) {
  16823. for ( i = 1; i <= tubularSegments; i ++ ) {
  16824. // indices
  16825. var a = ( tubularSegments + 1 ) * j + i - 1;
  16826. var b = ( tubularSegments + 1 ) * ( j - 1 ) + i - 1;
  16827. var c = ( tubularSegments + 1 ) * ( j - 1 ) + i;
  16828. var d = ( tubularSegments + 1 ) * j + i;
  16829. // faces
  16830. indices.push( a, b, d );
  16831. indices.push( b, c, d );
  16832. }
  16833. }
  16834. // build geometry
  16835. this.setIndex( indices );
  16836. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  16837. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  16838. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  16839. }
  16840. TorusBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  16841. TorusBufferGeometry.prototype.constructor = TorusBufferGeometry;
  16842. /**
  16843. * @author Mugen87 / https://github.com/Mugen87
  16844. * Port from https://github.com/mapbox/earcut (v2.1.2)
  16845. */
  16846. var Earcut = {
  16847. triangulate: function ( data, holeIndices, dim ) {
  16848. dim = dim || 2;
  16849. var hasHoles = holeIndices && holeIndices.length,
  16850. outerLen = hasHoles ? holeIndices[ 0 ] * dim : data.length,
  16851. outerNode = linkedList( data, 0, outerLen, dim, true ),
  16852. triangles = [];
  16853. if ( ! outerNode ) return triangles;
  16854. var minX, minY, maxX, maxY, x, y, invSize;
  16855. if ( hasHoles ) outerNode = eliminateHoles( data, holeIndices, outerNode, dim );
  16856. // if the shape is not too simple, we'll use z-order curve hash later; calculate polygon bbox
  16857. if ( data.length > 80 * dim ) {
  16858. minX = maxX = data[ 0 ];
  16859. minY = maxY = data[ 1 ];
  16860. for ( var i = dim; i < outerLen; i += dim ) {
  16861. x = data[ i ];
  16862. y = data[ i + 1 ];
  16863. if ( x < minX ) minX = x;
  16864. if ( y < minY ) minY = y;
  16865. if ( x > maxX ) maxX = x;
  16866. if ( y > maxY ) maxY = y;
  16867. }
  16868. // minX, minY and invSize are later used to transform coords into integers for z-order calculation
  16869. invSize = Math.max( maxX - minX, maxY - minY );
  16870. invSize = invSize !== 0 ? 1 / invSize : 0;
  16871. }
  16872. earcutLinked( outerNode, triangles, dim, minX, minY, invSize );
  16873. return triangles;
  16874. }
  16875. };
  16876. // create a circular doubly linked list from polygon points in the specified winding order
  16877. function linkedList( data, start, end, dim, clockwise ) {
  16878. var i, last;
  16879. if ( clockwise === ( signedArea( data, start, end, dim ) > 0 ) ) {
  16880. for ( i = start; i < end; i += dim ) last = insertNode( i, data[ i ], data[ i + 1 ], last );
  16881. } else {
  16882. for ( i = end - dim; i >= start; i -= dim ) last = insertNode( i, data[ i ], data[ i + 1 ], last );
  16883. }
  16884. if ( last && equals( last, last.next ) ) {
  16885. removeNode( last );
  16886. last = last.next;
  16887. }
  16888. return last;
  16889. }
  16890. // eliminate colinear or duplicate points
  16891. function filterPoints( start, end ) {
  16892. if ( ! start ) return start;
  16893. if ( ! end ) end = start;
  16894. var p = start, again;
  16895. do {
  16896. again = false;
  16897. if ( ! p.steiner && ( equals( p, p.next ) || area( p.prev, p, p.next ) === 0 ) ) {
  16898. removeNode( p );
  16899. p = end = p.prev;
  16900. if ( p === p.next ) break;
  16901. again = true;
  16902. } else {
  16903. p = p.next;
  16904. }
  16905. } while ( again || p !== end );
  16906. return end;
  16907. }
  16908. // main ear slicing loop which triangulates a polygon (given as a linked list)
  16909. function earcutLinked( ear, triangles, dim, minX, minY, invSize, pass ) {
  16910. if ( ! ear ) return;
  16911. // interlink polygon nodes in z-order
  16912. if ( ! pass && invSize ) indexCurve( ear, minX, minY, invSize );
  16913. var stop = ear, prev, next;
  16914. // iterate through ears, slicing them one by one
  16915. while ( ear.prev !== ear.next ) {
  16916. prev = ear.prev;
  16917. next = ear.next;
  16918. if ( invSize ? isEarHashed( ear, minX, minY, invSize ) : isEar( ear ) ) {
  16919. // cut off the triangle
  16920. triangles.push( prev.i / dim );
  16921. triangles.push( ear.i / dim );
  16922. triangles.push( next.i / dim );
  16923. removeNode( ear );
  16924. // skipping the next vertice leads to less sliver triangles
  16925. ear = next.next;
  16926. stop = next.next;
  16927. continue;
  16928. }
  16929. ear = next;
  16930. // if we looped through the whole remaining polygon and can't find any more ears
  16931. if ( ear === stop ) {
  16932. // try filtering points and slicing again
  16933. if ( ! pass ) {
  16934. earcutLinked( filterPoints( ear ), triangles, dim, minX, minY, invSize, 1 );
  16935. // if this didn't work, try curing all small self-intersections locally
  16936. } else if ( pass === 1 ) {
  16937. ear = cureLocalIntersections( ear, triangles, dim );
  16938. earcutLinked( ear, triangles, dim, minX, minY, invSize, 2 );
  16939. // as a last resort, try splitting the remaining polygon into two
  16940. } else if ( pass === 2 ) {
  16941. splitEarcut( ear, triangles, dim, minX, minY, invSize );
  16942. }
  16943. break;
  16944. }
  16945. }
  16946. }
  16947. // check whether a polygon node forms a valid ear with adjacent nodes
  16948. function isEar( ear ) {
  16949. var a = ear.prev,
  16950. b = ear,
  16951. c = ear.next;
  16952. if ( area( a, b, c ) >= 0 ) return false; // reflex, can't be an ear
  16953. // now make sure we don't have other points inside the potential ear
  16954. var p = ear.next.next;
  16955. while ( p !== ear.prev ) {
  16956. if ( pointInTriangle( a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y ) && area( p.prev, p, p.next ) >= 0 ) {
  16957. return false;
  16958. }
  16959. p = p.next;
  16960. }
  16961. return true;
  16962. }
  16963. function isEarHashed( ear, minX, minY, invSize ) {
  16964. var a = ear.prev,
  16965. b = ear,
  16966. c = ear.next;
  16967. if ( area( a, b, c ) >= 0 ) return false; // reflex, can't be an ear
  16968. // triangle bbox; min & max are calculated like this for speed
  16969. var minTX = a.x < b.x ? ( a.x < c.x ? a.x : c.x ) : ( b.x < c.x ? b.x : c.x ),
  16970. minTY = a.y < b.y ? ( a.y < c.y ? a.y : c.y ) : ( b.y < c.y ? b.y : c.y ),
  16971. maxTX = a.x > b.x ? ( a.x > c.x ? a.x : c.x ) : ( b.x > c.x ? b.x : c.x ),
  16972. maxTY = a.y > b.y ? ( a.y > c.y ? a.y : c.y ) : ( b.y > c.y ? b.y : c.y );
  16973. // z-order range for the current triangle bbox;
  16974. var minZ = zOrder( minTX, minTY, minX, minY, invSize ),
  16975. maxZ = zOrder( maxTX, maxTY, minX, minY, invSize );
  16976. // first look for points inside the triangle in increasing z-order
  16977. var p = ear.nextZ;
  16978. while ( p && p.z <= maxZ ) {
  16979. if ( p !== ear.prev && p !== ear.next &&
  16980. pointInTriangle( a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y ) &&
  16981. area( p.prev, p, p.next ) >= 0 ) return false;
  16982. p = p.nextZ;
  16983. }
  16984. // then look for points in decreasing z-order
  16985. p = ear.prevZ;
  16986. while ( p && p.z >= minZ ) {
  16987. if ( p !== ear.prev && p !== ear.next &&
  16988. pointInTriangle( a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y ) &&
  16989. area( p.prev, p, p.next ) >= 0 ) return false;
  16990. p = p.prevZ;
  16991. }
  16992. return true;
  16993. }
  16994. // go through all polygon nodes and cure small local self-intersections
  16995. function cureLocalIntersections( start, triangles, dim ) {
  16996. var p = start;
  16997. do {
  16998. var a = p.prev, b = p.next.next;
  16999. if ( ! equals( a, b ) && intersects( a, p, p.next, b ) && locallyInside( a, b ) && locallyInside( b, a ) ) {
  17000. triangles.push( a.i / dim );
  17001. triangles.push( p.i / dim );
  17002. triangles.push( b.i / dim );
  17003. // remove two nodes involved
  17004. removeNode( p );
  17005. removeNode( p.next );
  17006. p = start = b;
  17007. }
  17008. p = p.next;
  17009. } while ( p !== start );
  17010. return p;
  17011. }
  17012. // try splitting polygon into two and triangulate them independently
  17013. function splitEarcut( start, triangles, dim, minX, minY, invSize ) {
  17014. // look for a valid diagonal that divides the polygon into two
  17015. var a = start;
  17016. do {
  17017. var b = a.next.next;
  17018. while ( b !== a.prev ) {
  17019. if ( a.i !== b.i && isValidDiagonal( a, b ) ) {
  17020. // split the polygon in two by the diagonal
  17021. var c = splitPolygon( a, b );
  17022. // filter colinear points around the cuts
  17023. a = filterPoints( a, a.next );
  17024. c = filterPoints( c, c.next );
  17025. // run earcut on each half
  17026. earcutLinked( a, triangles, dim, minX, minY, invSize );
  17027. earcutLinked( c, triangles, dim, minX, minY, invSize );
  17028. return;
  17029. }
  17030. b = b.next;
  17031. }
  17032. a = a.next;
  17033. } while ( a !== start );
  17034. }
  17035. // link every hole into the outer loop, producing a single-ring polygon without holes
  17036. function eliminateHoles( data, holeIndices, outerNode, dim ) {
  17037. var queue = [], i, len, start, end, list;
  17038. for ( i = 0, len = holeIndices.length; i < len; i ++ ) {
  17039. start = holeIndices[ i ] * dim;
  17040. end = i < len - 1 ? holeIndices[ i + 1 ] * dim : data.length;
  17041. list = linkedList( data, start, end, dim, false );
  17042. if ( list === list.next ) list.steiner = true;
  17043. queue.push( getLeftmost( list ) );
  17044. }
  17045. queue.sort( compareX );
  17046. // process holes from left to right
  17047. for ( i = 0; i < queue.length; i ++ ) {
  17048. eliminateHole( queue[ i ], outerNode );
  17049. outerNode = filterPoints( outerNode, outerNode.next );
  17050. }
  17051. return outerNode;
  17052. }
  17053. function compareX( a, b ) {
  17054. return a.x - b.x;
  17055. }
  17056. // find a bridge between vertices that connects hole with an outer ring and and link it
  17057. function eliminateHole( hole, outerNode ) {
  17058. outerNode = findHoleBridge( hole, outerNode );
  17059. if ( outerNode ) {
  17060. var b = splitPolygon( outerNode, hole );
  17061. filterPoints( b, b.next );
  17062. }
  17063. }
  17064. // David Eberly's algorithm for finding a bridge between hole and outer polygon
  17065. function findHoleBridge( hole, outerNode ) {
  17066. var p = outerNode,
  17067. hx = hole.x,
  17068. hy = hole.y,
  17069. qx = - Infinity,
  17070. m;
  17071. // find a segment intersected by a ray from the hole's leftmost point to the left;
  17072. // segment's endpoint with lesser x will be potential connection point
  17073. do {
  17074. if ( hy <= p.y && hy >= p.next.y && p.next.y !== p.y ) {
  17075. var x = p.x + ( hy - p.y ) * ( p.next.x - p.x ) / ( p.next.y - p.y );
  17076. if ( x <= hx && x > qx ) {
  17077. qx = x;
  17078. if ( x === hx ) {
  17079. if ( hy === p.y ) return p;
  17080. if ( hy === p.next.y ) return p.next;
  17081. }
  17082. m = p.x < p.next.x ? p : p.next;
  17083. }
  17084. }
  17085. p = p.next;
  17086. } while ( p !== outerNode );
  17087. if ( ! m ) return null;
  17088. if ( hx === qx ) return m.prev; // hole touches outer segment; pick lower endpoint
  17089. // look for points inside the triangle of hole point, segment intersection and endpoint;
  17090. // if there are no points found, we have a valid connection;
  17091. // otherwise choose the point of the minimum angle with the ray as connection point
  17092. var stop = m,
  17093. mx = m.x,
  17094. my = m.y,
  17095. tanMin = Infinity,
  17096. tan;
  17097. p = m.next;
  17098. while ( p !== stop ) {
  17099. if ( hx >= p.x && p.x >= mx && hx !== p.x &&
  17100. pointInTriangle( hy < my ? hx : qx, hy, mx, my, hy < my ? qx : hx, hy, p.x, p.y ) ) {
  17101. tan = Math.abs( hy - p.y ) / ( hx - p.x ); // tangential
  17102. if ( ( tan < tanMin || ( tan === tanMin && p.x > m.x ) ) && locallyInside( p, hole ) ) {
  17103. m = p;
  17104. tanMin = tan;
  17105. }
  17106. }
  17107. p = p.next;
  17108. }
  17109. return m;
  17110. }
  17111. // interlink polygon nodes in z-order
  17112. function indexCurve( start, minX, minY, invSize ) {
  17113. var p = start;
  17114. do {
  17115. if ( p.z === null ) p.z = zOrder( p.x, p.y, minX, minY, invSize );
  17116. p.prevZ = p.prev;
  17117. p.nextZ = p.next;
  17118. p = p.next;
  17119. } while ( p !== start );
  17120. p.prevZ.nextZ = null;
  17121. p.prevZ = null;
  17122. sortLinked( p );
  17123. }
  17124. // Simon Tatham's linked list merge sort algorithm
  17125. // http://www.chiark.greenend.org.uk/~sgtatham/algorithms/listsort.html
  17126. function sortLinked( list ) {
  17127. var i, p, q, e, tail, numMerges, pSize, qSize, inSize = 1;
  17128. do {
  17129. p = list;
  17130. list = null;
  17131. tail = null;
  17132. numMerges = 0;
  17133. while ( p ) {
  17134. numMerges ++;
  17135. q = p;
  17136. pSize = 0;
  17137. for ( i = 0; i < inSize; i ++ ) {
  17138. pSize ++;
  17139. q = q.nextZ;
  17140. if ( ! q ) break;
  17141. }
  17142. qSize = inSize;
  17143. while ( pSize > 0 || ( qSize > 0 && q ) ) {
  17144. if ( pSize !== 0 && ( qSize === 0 || ! q || p.z <= q.z ) ) {
  17145. e = p;
  17146. p = p.nextZ;
  17147. pSize --;
  17148. } else {
  17149. e = q;
  17150. q = q.nextZ;
  17151. qSize --;
  17152. }
  17153. if ( tail ) tail.nextZ = e;
  17154. else list = e;
  17155. e.prevZ = tail;
  17156. tail = e;
  17157. }
  17158. p = q;
  17159. }
  17160. tail.nextZ = null;
  17161. inSize *= 2;
  17162. } while ( numMerges > 1 );
  17163. return list;
  17164. }
  17165. // z-order of a point given coords and inverse of the longer side of data bbox
  17166. function zOrder( x, y, minX, minY, invSize ) {
  17167. // coords are transformed into non-negative 15-bit integer range
  17168. x = 32767 * ( x - minX ) * invSize;
  17169. y = 32767 * ( y - minY ) * invSize;
  17170. x = ( x | ( x << 8 ) ) & 0x00FF00FF;
  17171. x = ( x | ( x << 4 ) ) & 0x0F0F0F0F;
  17172. x = ( x | ( x << 2 ) ) & 0x33333333;
  17173. x = ( x | ( x << 1 ) ) & 0x55555555;
  17174. y = ( y | ( y << 8 ) ) & 0x00FF00FF;
  17175. y = ( y | ( y << 4 ) ) & 0x0F0F0F0F;
  17176. y = ( y | ( y << 2 ) ) & 0x33333333;
  17177. y = ( y | ( y << 1 ) ) & 0x55555555;
  17178. return x | ( y << 1 );
  17179. }
  17180. // find the leftmost node of a polygon ring
  17181. function getLeftmost( start ) {
  17182. var p = start, leftmost = start;
  17183. do {
  17184. if ( p.x < leftmost.x ) leftmost = p;
  17185. p = p.next;
  17186. } while ( p !== start );
  17187. return leftmost;
  17188. }
  17189. // check if a point lies within a convex triangle
  17190. function pointInTriangle( ax, ay, bx, by, cx, cy, px, py ) {
  17191. return ( cx - px ) * ( ay - py ) - ( ax - px ) * ( cy - py ) >= 0 &&
  17192. ( ax - px ) * ( by - py ) - ( bx - px ) * ( ay - py ) >= 0 &&
  17193. ( bx - px ) * ( cy - py ) - ( cx - px ) * ( by - py ) >= 0;
  17194. }
  17195. // check if a diagonal between two polygon nodes is valid (lies in polygon interior)
  17196. function isValidDiagonal( a, b ) {
  17197. return a.next.i !== b.i && a.prev.i !== b.i && ! intersectsPolygon( a, b ) &&
  17198. locallyInside( a, b ) && locallyInside( b, a ) && middleInside( a, b );
  17199. }
  17200. // signed area of a triangle
  17201. function area( p, q, r ) {
  17202. return ( q.y - p.y ) * ( r.x - q.x ) - ( q.x - p.x ) * ( r.y - q.y );
  17203. }
  17204. // check if two points are equal
  17205. function equals( p1, p2 ) {
  17206. return p1.x === p2.x && p1.y === p2.y;
  17207. }
  17208. // check if two segments intersect
  17209. function intersects( p1, q1, p2, q2 ) {
  17210. if ( ( equals( p1, q1 ) && equals( p2, q2 ) ) ||
  17211. ( equals( p1, q2 ) && equals( p2, q1 ) ) ) return true;
  17212. return area( p1, q1, p2 ) > 0 !== area( p1, q1, q2 ) > 0 &&
  17213. area( p2, q2, p1 ) > 0 !== area( p2, q2, q1 ) > 0;
  17214. }
  17215. // check if a polygon diagonal intersects any polygon segments
  17216. function intersectsPolygon( a, b ) {
  17217. var p = a;
  17218. do {
  17219. if ( p.i !== a.i && p.next.i !== a.i && p.i !== b.i && p.next.i !== b.i &&
  17220. intersects( p, p.next, a, b ) ) {
  17221. return true;
  17222. }
  17223. p = p.next;
  17224. } while ( p !== a );
  17225. return false;
  17226. }
  17227. // check if a polygon diagonal is locally inside the polygon
  17228. function locallyInside( a, b ) {
  17229. return area( a.prev, a, a.next ) < 0 ?
  17230. area( a, b, a.next ) >= 0 && area( a, a.prev, b ) >= 0 :
  17231. area( a, b, a.prev ) < 0 || area( a, a.next, b ) < 0;
  17232. }
  17233. // check if the middle point of a polygon diagonal is inside the polygon
  17234. function middleInside( a, b ) {
  17235. var p = a,
  17236. inside = false,
  17237. px = ( a.x + b.x ) / 2,
  17238. py = ( a.y + b.y ) / 2;
  17239. do {
  17240. if ( ( ( p.y > py ) !== ( p.next.y > py ) ) && p.next.y !== p.y &&
  17241. ( px < ( p.next.x - p.x ) * ( py - p.y ) / ( p.next.y - p.y ) + p.x ) ) {
  17242. inside = ! inside;
  17243. }
  17244. p = p.next;
  17245. } while ( p !== a );
  17246. return inside;
  17247. }
  17248. // link two polygon vertices with a bridge; if the vertices belong to the same ring, it splits polygon into two;
  17249. // if one belongs to the outer ring and another to a hole, it merges it into a single ring
  17250. function splitPolygon( a, b ) {
  17251. var a2 = new Node( a.i, a.x, a.y ),
  17252. b2 = new Node( b.i, b.x, b.y ),
  17253. an = a.next,
  17254. bp = b.prev;
  17255. a.next = b;
  17256. b.prev = a;
  17257. a2.next = an;
  17258. an.prev = a2;
  17259. b2.next = a2;
  17260. a2.prev = b2;
  17261. bp.next = b2;
  17262. b2.prev = bp;
  17263. return b2;
  17264. }
  17265. // create a node and optionally link it with previous one (in a circular doubly linked list)
  17266. function insertNode( i, x, y, last ) {
  17267. var p = new Node( i, x, y );
  17268. if ( ! last ) {
  17269. p.prev = p;
  17270. p.next = p;
  17271. } else {
  17272. p.next = last.next;
  17273. p.prev = last;
  17274. last.next.prev = p;
  17275. last.next = p;
  17276. }
  17277. return p;
  17278. }
  17279. function removeNode( p ) {
  17280. p.next.prev = p.prev;
  17281. p.prev.next = p.next;
  17282. if ( p.prevZ ) p.prevZ.nextZ = p.nextZ;
  17283. if ( p.nextZ ) p.nextZ.prevZ = p.prevZ;
  17284. }
  17285. function Node( i, x, y ) {
  17286. // vertice index in coordinates array
  17287. this.i = i;
  17288. // vertex coordinates
  17289. this.x = x;
  17290. this.y = y;
  17291. // previous and next vertice nodes in a polygon ring
  17292. this.prev = null;
  17293. this.next = null;
  17294. // z-order curve value
  17295. this.z = null;
  17296. // previous and next nodes in z-order
  17297. this.prevZ = null;
  17298. this.nextZ = null;
  17299. // indicates whether this is a steiner point
  17300. this.steiner = false;
  17301. }
  17302. function signedArea( data, start, end, dim ) {
  17303. var sum = 0;
  17304. for ( var i = start, j = end - dim; i < end; i += dim ) {
  17305. sum += ( data[ j ] - data[ i ] ) * ( data[ i + 1 ] + data[ j + 1 ] );
  17306. j = i;
  17307. }
  17308. return sum;
  17309. }
  17310. /**
  17311. * @author zz85 / http://www.lab4games.net/zz85/blog
  17312. */
  17313. var ShapeUtils = {
  17314. // calculate area of the contour polygon
  17315. area: function ( contour ) {
  17316. var n = contour.length;
  17317. var a = 0.0;
  17318. for ( var p = n - 1, q = 0; q < n; p = q ++ ) {
  17319. a += contour[ p ].x * contour[ q ].y - contour[ q ].x * contour[ p ].y;
  17320. }
  17321. return a * 0.5;
  17322. },
  17323. isClockWise: function ( pts ) {
  17324. return ShapeUtils.area( pts ) < 0;
  17325. },
  17326. triangulateShape: function ( contour, holes ) {
  17327. var vertices = []; // flat array of vertices like [ x0,y0, x1,y1, x2,y2, ... ]
  17328. var holeIndices = []; // array of hole indices
  17329. var faces = []; // final array of vertex indices like [ [ a,b,d ], [ b,c,d ] ]
  17330. removeDupEndPts( contour );
  17331. addContour( vertices, contour );
  17332. //
  17333. var holeIndex = contour.length;
  17334. holes.forEach( removeDupEndPts );
  17335. for ( var i = 0; i < holes.length; i ++ ) {
  17336. holeIndices.push( holeIndex );
  17337. holeIndex += holes[ i ].length;
  17338. addContour( vertices, holes[ i ] );
  17339. }
  17340. //
  17341. var triangles = Earcut.triangulate( vertices, holeIndices );
  17342. //
  17343. for ( var i = 0; i < triangles.length; i += 3 ) {
  17344. faces.push( triangles.slice( i, i + 3 ) );
  17345. }
  17346. return faces;
  17347. }
  17348. };
  17349. function removeDupEndPts( points ) {
  17350. var l = points.length;
  17351. if ( l > 2 && points[ l - 1 ].equals( points[ 0 ] ) ) {
  17352. points.pop();
  17353. }
  17354. }
  17355. function addContour( vertices, contour ) {
  17356. for ( var i = 0; i < contour.length; i ++ ) {
  17357. vertices.push( contour[ i ].x );
  17358. vertices.push( contour[ i ].y );
  17359. }
  17360. }
  17361. /**
  17362. * @author zz85 / http://www.lab4games.net/zz85/blog
  17363. *
  17364. * Creates extruded geometry from a path shape.
  17365. *
  17366. * parameters = {
  17367. *
  17368. * curveSegments: <int>, // number of points on the curves
  17369. * steps: <int>, // number of points for z-side extrusions / used for subdividing segments of extrude spline too
  17370. * depth: <float>, // Depth to extrude the shape
  17371. *
  17372. * bevelEnabled: <bool>, // turn on bevel
  17373. * bevelThickness: <float>, // how deep into the original shape bevel goes
  17374. * bevelSize: <float>, // how far from shape outline is bevel
  17375. * bevelSegments: <int>, // number of bevel layers
  17376. *
  17377. * extrudePath: <THREE.Curve> // curve to extrude shape along
  17378. *
  17379. * UVGenerator: <Object> // object that provides UV generator functions
  17380. *
  17381. * }
  17382. */
  17383. // ExtrudeGeometry
  17384. function ExtrudeGeometry( shapes, options ) {
  17385. Geometry.call( this );
  17386. this.type = 'ExtrudeGeometry';
  17387. this.parameters = {
  17388. shapes: shapes,
  17389. options: options
  17390. };
  17391. this.fromBufferGeometry( new ExtrudeBufferGeometry( shapes, options ) );
  17392. this.mergeVertices();
  17393. }
  17394. ExtrudeGeometry.prototype = Object.create( Geometry.prototype );
  17395. ExtrudeGeometry.prototype.constructor = ExtrudeGeometry;
  17396. ExtrudeGeometry.prototype.toJSON = function () {
  17397. var data = Geometry.prototype.toJSON.call( this );
  17398. var shapes = this.parameters.shapes;
  17399. var options = this.parameters.options;
  17400. return toJSON( shapes, options, data );
  17401. };
  17402. // ExtrudeBufferGeometry
  17403. function ExtrudeBufferGeometry( shapes, options ) {
  17404. BufferGeometry.call( this );
  17405. this.type = 'ExtrudeBufferGeometry';
  17406. this.parameters = {
  17407. shapes: shapes,
  17408. options: options
  17409. };
  17410. shapes = Array.isArray( shapes ) ? shapes : [ shapes ];
  17411. var scope = this;
  17412. var verticesArray = [];
  17413. var uvArray = [];
  17414. for ( var i = 0, l = shapes.length; i < l; i ++ ) {
  17415. var shape = shapes[ i ];
  17416. addShape( shape );
  17417. }
  17418. // build geometry
  17419. this.addAttribute( 'position', new Float32BufferAttribute( verticesArray, 3 ) );
  17420. this.addAttribute( 'uv', new Float32BufferAttribute( uvArray, 2 ) );
  17421. this.computeVertexNormals();
  17422. // functions
  17423. function addShape( shape ) {
  17424. var placeholder = [];
  17425. // options
  17426. var curveSegments = options.curveSegments !== undefined ? options.curveSegments : 12;
  17427. var steps = options.steps !== undefined ? options.steps : 1;
  17428. var depth = options.depth !== undefined ? options.depth : 100;
  17429. var bevelEnabled = options.bevelEnabled !== undefined ? options.bevelEnabled : true;
  17430. var bevelThickness = options.bevelThickness !== undefined ? options.bevelThickness : 6;
  17431. var bevelSize = options.bevelSize !== undefined ? options.bevelSize : bevelThickness - 2;
  17432. var bevelSegments = options.bevelSegments !== undefined ? options.bevelSegments : 3;
  17433. var extrudePath = options.extrudePath;
  17434. var uvgen = options.UVGenerator !== undefined ? options.UVGenerator : WorldUVGenerator;
  17435. // deprecated options
  17436. if ( options.amount !== undefined ) {
  17437. console.warn( 'THREE.ExtrudeBufferGeometry: amount has been renamed to depth.' );
  17438. depth = options.amount;
  17439. }
  17440. //
  17441. var extrudePts, extrudeByPath = false;
  17442. var splineTube, binormal, normal, position2;
  17443. if ( extrudePath ) {
  17444. extrudePts = extrudePath.getSpacedPoints( steps );
  17445. extrudeByPath = true;
  17446. bevelEnabled = false; // bevels not supported for path extrusion
  17447. // SETUP TNB variables
  17448. // TODO1 - have a .isClosed in spline?
  17449. splineTube = extrudePath.computeFrenetFrames( steps, false );
  17450. // console.log(splineTube, 'splineTube', splineTube.normals.length, 'steps', steps, 'extrudePts', extrudePts.length);
  17451. binormal = new Vector3();
  17452. normal = new Vector3();
  17453. position2 = new Vector3();
  17454. }
  17455. // Safeguards if bevels are not enabled
  17456. if ( ! bevelEnabled ) {
  17457. bevelSegments = 0;
  17458. bevelThickness = 0;
  17459. bevelSize = 0;
  17460. }
  17461. // Variables initialization
  17462. var ahole, h, hl; // looping of holes
  17463. var shapePoints = shape.extractPoints( curveSegments );
  17464. var vertices = shapePoints.shape;
  17465. var holes = shapePoints.holes;
  17466. var reverse = ! ShapeUtils.isClockWise( vertices );
  17467. if ( reverse ) {
  17468. vertices = vertices.reverse();
  17469. // Maybe we should also check if holes are in the opposite direction, just to be safe ...
  17470. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  17471. ahole = holes[ h ];
  17472. if ( ShapeUtils.isClockWise( ahole ) ) {
  17473. holes[ h ] = ahole.reverse();
  17474. }
  17475. }
  17476. }
  17477. var faces = ShapeUtils.triangulateShape( vertices, holes );
  17478. /* Vertices */
  17479. var contour = vertices; // vertices has all points but contour has only points of circumference
  17480. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  17481. ahole = holes[ h ];
  17482. vertices = vertices.concat( ahole );
  17483. }
  17484. function scalePt2( pt, vec, size ) {
  17485. if ( ! vec ) console.error( "THREE.ExtrudeGeometry: vec does not exist" );
  17486. return vec.clone().multiplyScalar( size ).add( pt );
  17487. }
  17488. var b, bs, t, z,
  17489. vert, vlen = vertices.length,
  17490. face, flen = faces.length;
  17491. // Find directions for point movement
  17492. function getBevelVec( inPt, inPrev, inNext ) {
  17493. // computes for inPt the corresponding point inPt' on a new contour
  17494. // shifted by 1 unit (length of normalized vector) to the left
  17495. // if we walk along contour clockwise, this new contour is outside the old one
  17496. //
  17497. // inPt' is the intersection of the two lines parallel to the two
  17498. // adjacent edges of inPt at a distance of 1 unit on the left side.
  17499. var v_trans_x, v_trans_y, shrink_by; // resulting translation vector for inPt
  17500. // good reading for geometry algorithms (here: line-line intersection)
  17501. // http://geomalgorithms.com/a05-_intersect-1.html
  17502. var v_prev_x = inPt.x - inPrev.x,
  17503. v_prev_y = inPt.y - inPrev.y;
  17504. var v_next_x = inNext.x - inPt.x,
  17505. v_next_y = inNext.y - inPt.y;
  17506. var v_prev_lensq = ( v_prev_x * v_prev_x + v_prev_y * v_prev_y );
  17507. // check for collinear edges
  17508. var collinear0 = ( v_prev_x * v_next_y - v_prev_y * v_next_x );
  17509. if ( Math.abs( collinear0 ) > Number.EPSILON ) {
  17510. // not collinear
  17511. // length of vectors for normalizing
  17512. var v_prev_len = Math.sqrt( v_prev_lensq );
  17513. var v_next_len = Math.sqrt( v_next_x * v_next_x + v_next_y * v_next_y );
  17514. // shift adjacent points by unit vectors to the left
  17515. var ptPrevShift_x = ( inPrev.x - v_prev_y / v_prev_len );
  17516. var ptPrevShift_y = ( inPrev.y + v_prev_x / v_prev_len );
  17517. var ptNextShift_x = ( inNext.x - v_next_y / v_next_len );
  17518. var ptNextShift_y = ( inNext.y + v_next_x / v_next_len );
  17519. // scaling factor for v_prev to intersection point
  17520. var sf = ( ( ptNextShift_x - ptPrevShift_x ) * v_next_y -
  17521. ( ptNextShift_y - ptPrevShift_y ) * v_next_x ) /
  17522. ( v_prev_x * v_next_y - v_prev_y * v_next_x );
  17523. // vector from inPt to intersection point
  17524. v_trans_x = ( ptPrevShift_x + v_prev_x * sf - inPt.x );
  17525. v_trans_y = ( ptPrevShift_y + v_prev_y * sf - inPt.y );
  17526. // Don't normalize!, otherwise sharp corners become ugly
  17527. // but prevent crazy spikes
  17528. var v_trans_lensq = ( v_trans_x * v_trans_x + v_trans_y * v_trans_y );
  17529. if ( v_trans_lensq <= 2 ) {
  17530. return new Vector2( v_trans_x, v_trans_y );
  17531. } else {
  17532. shrink_by = Math.sqrt( v_trans_lensq / 2 );
  17533. }
  17534. } else {
  17535. // handle special case of collinear edges
  17536. var direction_eq = false; // assumes: opposite
  17537. if ( v_prev_x > Number.EPSILON ) {
  17538. if ( v_next_x > Number.EPSILON ) {
  17539. direction_eq = true;
  17540. }
  17541. } else {
  17542. if ( v_prev_x < - Number.EPSILON ) {
  17543. if ( v_next_x < - Number.EPSILON ) {
  17544. direction_eq = true;
  17545. }
  17546. } else {
  17547. if ( Math.sign( v_prev_y ) === Math.sign( v_next_y ) ) {
  17548. direction_eq = true;
  17549. }
  17550. }
  17551. }
  17552. if ( direction_eq ) {
  17553. // console.log("Warning: lines are a straight sequence");
  17554. v_trans_x = - v_prev_y;
  17555. v_trans_y = v_prev_x;
  17556. shrink_by = Math.sqrt( v_prev_lensq );
  17557. } else {
  17558. // console.log("Warning: lines are a straight spike");
  17559. v_trans_x = v_prev_x;
  17560. v_trans_y = v_prev_y;
  17561. shrink_by = Math.sqrt( v_prev_lensq / 2 );
  17562. }
  17563. }
  17564. return new Vector2( v_trans_x / shrink_by, v_trans_y / shrink_by );
  17565. }
  17566. var contourMovements = [];
  17567. for ( var i = 0, il = contour.length, j = il - 1, k = i + 1; i < il; i ++, j ++, k ++ ) {
  17568. if ( j === il ) j = 0;
  17569. if ( k === il ) k = 0;
  17570. // (j)---(i)---(k)
  17571. // console.log('i,j,k', i, j , k)
  17572. contourMovements[ i ] = getBevelVec( contour[ i ], contour[ j ], contour[ k ] );
  17573. }
  17574. var holesMovements = [],
  17575. oneHoleMovements, verticesMovements = contourMovements.concat();
  17576. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  17577. ahole = holes[ h ];
  17578. oneHoleMovements = [];
  17579. for ( i = 0, il = ahole.length, j = il - 1, k = i + 1; i < il; i ++, j ++, k ++ ) {
  17580. if ( j === il ) j = 0;
  17581. if ( k === il ) k = 0;
  17582. // (j)---(i)---(k)
  17583. oneHoleMovements[ i ] = getBevelVec( ahole[ i ], ahole[ j ], ahole[ k ] );
  17584. }
  17585. holesMovements.push( oneHoleMovements );
  17586. verticesMovements = verticesMovements.concat( oneHoleMovements );
  17587. }
  17588. // Loop bevelSegments, 1 for the front, 1 for the back
  17589. for ( b = 0; b < bevelSegments; b ++ ) {
  17590. //for ( b = bevelSegments; b > 0; b -- ) {
  17591. t = b / bevelSegments;
  17592. z = bevelThickness * Math.cos( t * Math.PI / 2 );
  17593. bs = bevelSize * Math.sin( t * Math.PI / 2 );
  17594. // contract shape
  17595. for ( i = 0, il = contour.length; i < il; i ++ ) {
  17596. vert = scalePt2( contour[ i ], contourMovements[ i ], bs );
  17597. v( vert.x, vert.y, - z );
  17598. }
  17599. // expand holes
  17600. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  17601. ahole = holes[ h ];
  17602. oneHoleMovements = holesMovements[ h ];
  17603. for ( i = 0, il = ahole.length; i < il; i ++ ) {
  17604. vert = scalePt2( ahole[ i ], oneHoleMovements[ i ], bs );
  17605. v( vert.x, vert.y, - z );
  17606. }
  17607. }
  17608. }
  17609. bs = bevelSize;
  17610. // Back facing vertices
  17611. for ( i = 0; i < vlen; i ++ ) {
  17612. vert = bevelEnabled ? scalePt2( vertices[ i ], verticesMovements[ i ], bs ) : vertices[ i ];
  17613. if ( ! extrudeByPath ) {
  17614. v( vert.x, vert.y, 0 );
  17615. } else {
  17616. // v( vert.x, vert.y + extrudePts[ 0 ].y, extrudePts[ 0 ].x );
  17617. normal.copy( splineTube.normals[ 0 ] ).multiplyScalar( vert.x );
  17618. binormal.copy( splineTube.binormals[ 0 ] ).multiplyScalar( vert.y );
  17619. position2.copy( extrudePts[ 0 ] ).add( normal ).add( binormal );
  17620. v( position2.x, position2.y, position2.z );
  17621. }
  17622. }
  17623. // Add stepped vertices...
  17624. // Including front facing vertices
  17625. var s;
  17626. for ( s = 1; s <= steps; s ++ ) {
  17627. for ( i = 0; i < vlen; i ++ ) {
  17628. vert = bevelEnabled ? scalePt2( vertices[ i ], verticesMovements[ i ], bs ) : vertices[ i ];
  17629. if ( ! extrudeByPath ) {
  17630. v( vert.x, vert.y, depth / steps * s );
  17631. } else {
  17632. // v( vert.x, vert.y + extrudePts[ s - 1 ].y, extrudePts[ s - 1 ].x );
  17633. normal.copy( splineTube.normals[ s ] ).multiplyScalar( vert.x );
  17634. binormal.copy( splineTube.binormals[ s ] ).multiplyScalar( vert.y );
  17635. position2.copy( extrudePts[ s ] ).add( normal ).add( binormal );
  17636. v( position2.x, position2.y, position2.z );
  17637. }
  17638. }
  17639. }
  17640. // Add bevel segments planes
  17641. //for ( b = 1; b <= bevelSegments; b ++ ) {
  17642. for ( b = bevelSegments - 1; b >= 0; b -- ) {
  17643. t = b / bevelSegments;
  17644. z = bevelThickness * Math.cos( t * Math.PI / 2 );
  17645. bs = bevelSize * Math.sin( t * Math.PI / 2 );
  17646. // contract shape
  17647. for ( i = 0, il = contour.length; i < il; i ++ ) {
  17648. vert = scalePt2( contour[ i ], contourMovements[ i ], bs );
  17649. v( vert.x, vert.y, depth + z );
  17650. }
  17651. // expand holes
  17652. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  17653. ahole = holes[ h ];
  17654. oneHoleMovements = holesMovements[ h ];
  17655. for ( i = 0, il = ahole.length; i < il; i ++ ) {
  17656. vert = scalePt2( ahole[ i ], oneHoleMovements[ i ], bs );
  17657. if ( ! extrudeByPath ) {
  17658. v( vert.x, vert.y, depth + z );
  17659. } else {
  17660. v( vert.x, vert.y + extrudePts[ steps - 1 ].y, extrudePts[ steps - 1 ].x + z );
  17661. }
  17662. }
  17663. }
  17664. }
  17665. /* Faces */
  17666. // Top and bottom faces
  17667. buildLidFaces();
  17668. // Sides faces
  17669. buildSideFaces();
  17670. ///// Internal functions
  17671. function buildLidFaces() {
  17672. var start = verticesArray.length / 3;
  17673. if ( bevelEnabled ) {
  17674. var layer = 0; // steps + 1
  17675. var offset = vlen * layer;
  17676. // Bottom faces
  17677. for ( i = 0; i < flen; i ++ ) {
  17678. face = faces[ i ];
  17679. f3( face[ 2 ] + offset, face[ 1 ] + offset, face[ 0 ] + offset );
  17680. }
  17681. layer = steps + bevelSegments * 2;
  17682. offset = vlen * layer;
  17683. // Top faces
  17684. for ( i = 0; i < flen; i ++ ) {
  17685. face = faces[ i ];
  17686. f3( face[ 0 ] + offset, face[ 1 ] + offset, face[ 2 ] + offset );
  17687. }
  17688. } else {
  17689. // Bottom faces
  17690. for ( i = 0; i < flen; i ++ ) {
  17691. face = faces[ i ];
  17692. f3( face[ 2 ], face[ 1 ], face[ 0 ] );
  17693. }
  17694. // Top faces
  17695. for ( i = 0; i < flen; i ++ ) {
  17696. face = faces[ i ];
  17697. f3( face[ 0 ] + vlen * steps, face[ 1 ] + vlen * steps, face[ 2 ] + vlen * steps );
  17698. }
  17699. }
  17700. scope.addGroup( start, verticesArray.length / 3 - start, 0 );
  17701. }
  17702. // Create faces for the z-sides of the shape
  17703. function buildSideFaces() {
  17704. var start = verticesArray.length / 3;
  17705. var layeroffset = 0;
  17706. sidewalls( contour, layeroffset );
  17707. layeroffset += contour.length;
  17708. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  17709. ahole = holes[ h ];
  17710. sidewalls( ahole, layeroffset );
  17711. //, true
  17712. layeroffset += ahole.length;
  17713. }
  17714. scope.addGroup( start, verticesArray.length / 3 - start, 1 );
  17715. }
  17716. function sidewalls( contour, layeroffset ) {
  17717. var j, k;
  17718. i = contour.length;
  17719. while ( -- i >= 0 ) {
  17720. j = i;
  17721. k = i - 1;
  17722. if ( k < 0 ) k = contour.length - 1;
  17723. //console.log('b', i,j, i-1, k,vertices.length);
  17724. var s = 0,
  17725. sl = steps + bevelSegments * 2;
  17726. for ( s = 0; s < sl; s ++ ) {
  17727. var slen1 = vlen * s;
  17728. var slen2 = vlen * ( s + 1 );
  17729. var a = layeroffset + j + slen1,
  17730. b = layeroffset + k + slen1,
  17731. c = layeroffset + k + slen2,
  17732. d = layeroffset + j + slen2;
  17733. f4( a, b, c, d );
  17734. }
  17735. }
  17736. }
  17737. function v( x, y, z ) {
  17738. placeholder.push( x );
  17739. placeholder.push( y );
  17740. placeholder.push( z );
  17741. }
  17742. function f3( a, b, c ) {
  17743. addVertex( a );
  17744. addVertex( b );
  17745. addVertex( c );
  17746. var nextIndex = verticesArray.length / 3;
  17747. var uvs = uvgen.generateTopUV( scope, verticesArray, nextIndex - 3, nextIndex - 2, nextIndex - 1 );
  17748. addUV( uvs[ 0 ] );
  17749. addUV( uvs[ 1 ] );
  17750. addUV( uvs[ 2 ] );
  17751. }
  17752. function f4( a, b, c, d ) {
  17753. addVertex( a );
  17754. addVertex( b );
  17755. addVertex( d );
  17756. addVertex( b );
  17757. addVertex( c );
  17758. addVertex( d );
  17759. var nextIndex = verticesArray.length / 3;
  17760. var uvs = uvgen.generateSideWallUV( scope, verticesArray, nextIndex - 6, nextIndex - 3, nextIndex - 2, nextIndex - 1 );
  17761. addUV( uvs[ 0 ] );
  17762. addUV( uvs[ 1 ] );
  17763. addUV( uvs[ 3 ] );
  17764. addUV( uvs[ 1 ] );
  17765. addUV( uvs[ 2 ] );
  17766. addUV( uvs[ 3 ] );
  17767. }
  17768. function addVertex( index ) {
  17769. verticesArray.push( placeholder[ index * 3 + 0 ] );
  17770. verticesArray.push( placeholder[ index * 3 + 1 ] );
  17771. verticesArray.push( placeholder[ index * 3 + 2 ] );
  17772. }
  17773. function addUV( vector2 ) {
  17774. uvArray.push( vector2.x );
  17775. uvArray.push( vector2.y );
  17776. }
  17777. }
  17778. }
  17779. ExtrudeBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  17780. ExtrudeBufferGeometry.prototype.constructor = ExtrudeBufferGeometry;
  17781. ExtrudeBufferGeometry.prototype.toJSON = function () {
  17782. var data = BufferGeometry.prototype.toJSON.call( this );
  17783. var shapes = this.parameters.shapes;
  17784. var options = this.parameters.options;
  17785. return toJSON( shapes, options, data );
  17786. };
  17787. //
  17788. var WorldUVGenerator = {
  17789. generateTopUV: function ( geometry, vertices, indexA, indexB, indexC ) {
  17790. var a_x = vertices[ indexA * 3 ];
  17791. var a_y = vertices[ indexA * 3 + 1 ];
  17792. var b_x = vertices[ indexB * 3 ];
  17793. var b_y = vertices[ indexB * 3 + 1 ];
  17794. var c_x = vertices[ indexC * 3 ];
  17795. var c_y = vertices[ indexC * 3 + 1 ];
  17796. return [
  17797. new Vector2( a_x, a_y ),
  17798. new Vector2( b_x, b_y ),
  17799. new Vector2( c_x, c_y )
  17800. ];
  17801. },
  17802. generateSideWallUV: function ( geometry, vertices, indexA, indexB, indexC, indexD ) {
  17803. var a_x = vertices[ indexA * 3 ];
  17804. var a_y = vertices[ indexA * 3 + 1 ];
  17805. var a_z = vertices[ indexA * 3 + 2 ];
  17806. var b_x = vertices[ indexB * 3 ];
  17807. var b_y = vertices[ indexB * 3 + 1 ];
  17808. var b_z = vertices[ indexB * 3 + 2 ];
  17809. var c_x = vertices[ indexC * 3 ];
  17810. var c_y = vertices[ indexC * 3 + 1 ];
  17811. var c_z = vertices[ indexC * 3 + 2 ];
  17812. var d_x = vertices[ indexD * 3 ];
  17813. var d_y = vertices[ indexD * 3 + 1 ];
  17814. var d_z = vertices[ indexD * 3 + 2 ];
  17815. if ( Math.abs( a_y - b_y ) < 0.01 ) {
  17816. return [
  17817. new Vector2( a_x, 1 - a_z ),
  17818. new Vector2( b_x, 1 - b_z ),
  17819. new Vector2( c_x, 1 - c_z ),
  17820. new Vector2( d_x, 1 - d_z )
  17821. ];
  17822. } else {
  17823. return [
  17824. new Vector2( a_y, 1 - a_z ),
  17825. new Vector2( b_y, 1 - b_z ),
  17826. new Vector2( c_y, 1 - c_z ),
  17827. new Vector2( d_y, 1 - d_z )
  17828. ];
  17829. }
  17830. }
  17831. };
  17832. function toJSON( shapes, options, data ) {
  17833. //
  17834. data.shapes = [];
  17835. if ( Array.isArray( shapes ) ) {
  17836. for ( var i = 0, l = shapes.length; i < l; i ++ ) {
  17837. var shape = shapes[ i ];
  17838. data.shapes.push( shape.uuid );
  17839. }
  17840. } else {
  17841. data.shapes.push( shapes.uuid );
  17842. }
  17843. //
  17844. if ( options.extrudePath !== undefined ) data.options.extrudePath = options.extrudePath.toJSON();
  17845. return data;
  17846. }
  17847. /**
  17848. * @author zz85 / http://www.lab4games.net/zz85/blog
  17849. * @author alteredq / http://alteredqualia.com/
  17850. *
  17851. * Text = 3D Text
  17852. *
  17853. * parameters = {
  17854. * font: <THREE.Font>, // font
  17855. *
  17856. * size: <float>, // size of the text
  17857. * height: <float>, // thickness to extrude text
  17858. * curveSegments: <int>, // number of points on the curves
  17859. *
  17860. * bevelEnabled: <bool>, // turn on bevel
  17861. * bevelThickness: <float>, // how deep into text bevel goes
  17862. * bevelSize: <float> // how far from text outline is bevel
  17863. * }
  17864. */
  17865. // TextGeometry
  17866. function TextGeometry( text, parameters ) {
  17867. Geometry.call( this );
  17868. this.type = 'TextGeometry';
  17869. this.parameters = {
  17870. text: text,
  17871. parameters: parameters
  17872. };
  17873. this.fromBufferGeometry( new TextBufferGeometry( text, parameters ) );
  17874. this.mergeVertices();
  17875. }
  17876. TextGeometry.prototype = Object.create( Geometry.prototype );
  17877. TextGeometry.prototype.constructor = TextGeometry;
  17878. // TextBufferGeometry
  17879. function TextBufferGeometry( text, parameters ) {
  17880. parameters = parameters || {};
  17881. var font = parameters.font;
  17882. if ( ! ( font && font.isFont ) ) {
  17883. console.error( 'THREE.TextGeometry: font parameter is not an instance of THREE.Font.' );
  17884. return new Geometry();
  17885. }
  17886. var shapes = font.generateShapes( text, parameters.size );
  17887. // translate parameters to ExtrudeGeometry API
  17888. parameters.depth = parameters.height !== undefined ? parameters.height : 50;
  17889. // defaults
  17890. if ( parameters.bevelThickness === undefined ) parameters.bevelThickness = 10;
  17891. if ( parameters.bevelSize === undefined ) parameters.bevelSize = 8;
  17892. if ( parameters.bevelEnabled === undefined ) parameters.bevelEnabled = false;
  17893. ExtrudeBufferGeometry.call( this, shapes, parameters );
  17894. this.type = 'TextBufferGeometry';
  17895. }
  17896. TextBufferGeometry.prototype = Object.create( ExtrudeBufferGeometry.prototype );
  17897. TextBufferGeometry.prototype.constructor = TextBufferGeometry;
  17898. /**
  17899. * @author mrdoob / http://mrdoob.com/
  17900. * @author benaadams / https://twitter.com/ben_a_adams
  17901. * @author Mugen87 / https://github.com/Mugen87
  17902. */
  17903. // SphereGeometry
  17904. function SphereGeometry( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) {
  17905. Geometry.call( this );
  17906. this.type = 'SphereGeometry';
  17907. this.parameters = {
  17908. radius: radius,
  17909. widthSegments: widthSegments,
  17910. heightSegments: heightSegments,
  17911. phiStart: phiStart,
  17912. phiLength: phiLength,
  17913. thetaStart: thetaStart,
  17914. thetaLength: thetaLength
  17915. };
  17916. this.fromBufferGeometry( new SphereBufferGeometry( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) );
  17917. this.mergeVertices();
  17918. }
  17919. SphereGeometry.prototype = Object.create( Geometry.prototype );
  17920. SphereGeometry.prototype.constructor = SphereGeometry;
  17921. // SphereBufferGeometry
  17922. function SphereBufferGeometry( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) {
  17923. BufferGeometry.call( this );
  17924. this.type = 'SphereBufferGeometry';
  17925. this.parameters = {
  17926. radius: radius,
  17927. widthSegments: widthSegments,
  17928. heightSegments: heightSegments,
  17929. phiStart: phiStart,
  17930. phiLength: phiLength,
  17931. thetaStart: thetaStart,
  17932. thetaLength: thetaLength
  17933. };
  17934. radius = radius || 1;
  17935. widthSegments = Math.max( 3, Math.floor( widthSegments ) || 8 );
  17936. heightSegments = Math.max( 2, Math.floor( heightSegments ) || 6 );
  17937. phiStart = phiStart !== undefined ? phiStart : 0;
  17938. phiLength = phiLength !== undefined ? phiLength : Math.PI * 2;
  17939. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  17940. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI;
  17941. var thetaEnd = thetaStart + thetaLength;
  17942. var ix, iy;
  17943. var index = 0;
  17944. var grid = [];
  17945. var vertex = new Vector3();
  17946. var normal = new Vector3();
  17947. // buffers
  17948. var indices = [];
  17949. var vertices = [];
  17950. var normals = [];
  17951. var uvs = [];
  17952. // generate vertices, normals and uvs
  17953. for ( iy = 0; iy <= heightSegments; iy ++ ) {
  17954. var verticesRow = [];
  17955. var v = iy / heightSegments;
  17956. for ( ix = 0; ix <= widthSegments; ix ++ ) {
  17957. var u = ix / widthSegments;
  17958. // vertex
  17959. vertex.x = - radius * Math.cos( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  17960. vertex.y = radius * Math.cos( thetaStart + v * thetaLength );
  17961. vertex.z = radius * Math.sin( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  17962. vertices.push( vertex.x, vertex.y, vertex.z );
  17963. // normal
  17964. normal.set( vertex.x, vertex.y, vertex.z ).normalize();
  17965. normals.push( normal.x, normal.y, normal.z );
  17966. // uv
  17967. uvs.push( u, 1 - v );
  17968. verticesRow.push( index ++ );
  17969. }
  17970. grid.push( verticesRow );
  17971. }
  17972. // indices
  17973. for ( iy = 0; iy < heightSegments; iy ++ ) {
  17974. for ( ix = 0; ix < widthSegments; ix ++ ) {
  17975. var a = grid[ iy ][ ix + 1 ];
  17976. var b = grid[ iy ][ ix ];
  17977. var c = grid[ iy + 1 ][ ix ];
  17978. var d = grid[ iy + 1 ][ ix + 1 ];
  17979. if ( iy !== 0 || thetaStart > 0 ) indices.push( a, b, d );
  17980. if ( iy !== heightSegments - 1 || thetaEnd < Math.PI ) indices.push( b, c, d );
  17981. }
  17982. }
  17983. // build geometry
  17984. this.setIndex( indices );
  17985. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  17986. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  17987. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  17988. }
  17989. SphereBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  17990. SphereBufferGeometry.prototype.constructor = SphereBufferGeometry;
  17991. /**
  17992. * @author Kaleb Murphy
  17993. * @author Mugen87 / https://github.com/Mugen87
  17994. */
  17995. // RingGeometry
  17996. function RingGeometry( innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength ) {
  17997. Geometry.call( this );
  17998. this.type = 'RingGeometry';
  17999. this.parameters = {
  18000. innerRadius: innerRadius,
  18001. outerRadius: outerRadius,
  18002. thetaSegments: thetaSegments,
  18003. phiSegments: phiSegments,
  18004. thetaStart: thetaStart,
  18005. thetaLength: thetaLength
  18006. };
  18007. this.fromBufferGeometry( new RingBufferGeometry( innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength ) );
  18008. this.mergeVertices();
  18009. }
  18010. RingGeometry.prototype = Object.create( Geometry.prototype );
  18011. RingGeometry.prototype.constructor = RingGeometry;
  18012. // RingBufferGeometry
  18013. function RingBufferGeometry( innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength ) {
  18014. BufferGeometry.call( this );
  18015. this.type = 'RingBufferGeometry';
  18016. this.parameters = {
  18017. innerRadius: innerRadius,
  18018. outerRadius: outerRadius,
  18019. thetaSegments: thetaSegments,
  18020. phiSegments: phiSegments,
  18021. thetaStart: thetaStart,
  18022. thetaLength: thetaLength
  18023. };
  18024. innerRadius = innerRadius || 0.5;
  18025. outerRadius = outerRadius || 1;
  18026. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  18027. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  18028. thetaSegments = thetaSegments !== undefined ? Math.max( 3, thetaSegments ) : 8;
  18029. phiSegments = phiSegments !== undefined ? Math.max( 1, phiSegments ) : 1;
  18030. // buffers
  18031. var indices = [];
  18032. var vertices = [];
  18033. var normals = [];
  18034. var uvs = [];
  18035. // some helper variables
  18036. var segment;
  18037. var radius = innerRadius;
  18038. var radiusStep = ( ( outerRadius - innerRadius ) / phiSegments );
  18039. var vertex = new Vector3();
  18040. var uv = new Vector2();
  18041. var j, i;
  18042. // generate vertices, normals and uvs
  18043. for ( j = 0; j <= phiSegments; j ++ ) {
  18044. for ( i = 0; i <= thetaSegments; i ++ ) {
  18045. // values are generate from the inside of the ring to the outside
  18046. segment = thetaStart + i / thetaSegments * thetaLength;
  18047. // vertex
  18048. vertex.x = radius * Math.cos( segment );
  18049. vertex.y = radius * Math.sin( segment );
  18050. vertices.push( vertex.x, vertex.y, vertex.z );
  18051. // normal
  18052. normals.push( 0, 0, 1 );
  18053. // uv
  18054. uv.x = ( vertex.x / outerRadius + 1 ) / 2;
  18055. uv.y = ( vertex.y / outerRadius + 1 ) / 2;
  18056. uvs.push( uv.x, uv.y );
  18057. }
  18058. // increase the radius for next row of vertices
  18059. radius += radiusStep;
  18060. }
  18061. // indices
  18062. for ( j = 0; j < phiSegments; j ++ ) {
  18063. var thetaSegmentLevel = j * ( thetaSegments + 1 );
  18064. for ( i = 0; i < thetaSegments; i ++ ) {
  18065. segment = i + thetaSegmentLevel;
  18066. var a = segment;
  18067. var b = segment + thetaSegments + 1;
  18068. var c = segment + thetaSegments + 2;
  18069. var d = segment + 1;
  18070. // faces
  18071. indices.push( a, b, d );
  18072. indices.push( b, c, d );
  18073. }
  18074. }
  18075. // build geometry
  18076. this.setIndex( indices );
  18077. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  18078. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  18079. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  18080. }
  18081. RingBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  18082. RingBufferGeometry.prototype.constructor = RingBufferGeometry;
  18083. /**
  18084. * @author zz85 / https://github.com/zz85
  18085. * @author bhouston / http://clara.io
  18086. * @author Mugen87 / https://github.com/Mugen87
  18087. */
  18088. // LatheGeometry
  18089. function LatheGeometry( points, segments, phiStart, phiLength ) {
  18090. Geometry.call( this );
  18091. this.type = 'LatheGeometry';
  18092. this.parameters = {
  18093. points: points,
  18094. segments: segments,
  18095. phiStart: phiStart,
  18096. phiLength: phiLength
  18097. };
  18098. this.fromBufferGeometry( new LatheBufferGeometry( points, segments, phiStart, phiLength ) );
  18099. this.mergeVertices();
  18100. }
  18101. LatheGeometry.prototype = Object.create( Geometry.prototype );
  18102. LatheGeometry.prototype.constructor = LatheGeometry;
  18103. // LatheBufferGeometry
  18104. function LatheBufferGeometry( points, segments, phiStart, phiLength ) {
  18105. BufferGeometry.call( this );
  18106. this.type = 'LatheBufferGeometry';
  18107. this.parameters = {
  18108. points: points,
  18109. segments: segments,
  18110. phiStart: phiStart,
  18111. phiLength: phiLength
  18112. };
  18113. segments = Math.floor( segments ) || 12;
  18114. phiStart = phiStart || 0;
  18115. phiLength = phiLength || Math.PI * 2;
  18116. // clamp phiLength so it's in range of [ 0, 2PI ]
  18117. phiLength = _Math.clamp( phiLength, 0, Math.PI * 2 );
  18118. // buffers
  18119. var indices = [];
  18120. var vertices = [];
  18121. var uvs = [];
  18122. // helper variables
  18123. var base;
  18124. var inverseSegments = 1.0 / segments;
  18125. var vertex = new Vector3();
  18126. var uv = new Vector2();
  18127. var i, j;
  18128. // generate vertices and uvs
  18129. for ( i = 0; i <= segments; i ++ ) {
  18130. var phi = phiStart + i * inverseSegments * phiLength;
  18131. var sin = Math.sin( phi );
  18132. var cos = Math.cos( phi );
  18133. for ( j = 0; j <= ( points.length - 1 ); j ++ ) {
  18134. // vertex
  18135. vertex.x = points[ j ].x * sin;
  18136. vertex.y = points[ j ].y;
  18137. vertex.z = points[ j ].x * cos;
  18138. vertices.push( vertex.x, vertex.y, vertex.z );
  18139. // uv
  18140. uv.x = i / segments;
  18141. uv.y = j / ( points.length - 1 );
  18142. uvs.push( uv.x, uv.y );
  18143. }
  18144. }
  18145. // indices
  18146. for ( i = 0; i < segments; i ++ ) {
  18147. for ( j = 0; j < ( points.length - 1 ); j ++ ) {
  18148. base = j + i * points.length;
  18149. var a = base;
  18150. var b = base + points.length;
  18151. var c = base + points.length + 1;
  18152. var d = base + 1;
  18153. // faces
  18154. indices.push( a, b, d );
  18155. indices.push( b, c, d );
  18156. }
  18157. }
  18158. // build geometry
  18159. this.setIndex( indices );
  18160. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  18161. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  18162. // generate normals
  18163. this.computeVertexNormals();
  18164. // if the geometry is closed, we need to average the normals along the seam.
  18165. // because the corresponding vertices are identical (but still have different UVs).
  18166. if ( phiLength === Math.PI * 2 ) {
  18167. var normals = this.attributes.normal.array;
  18168. var n1 = new Vector3();
  18169. var n2 = new Vector3();
  18170. var n = new Vector3();
  18171. // this is the buffer offset for the last line of vertices
  18172. base = segments * points.length * 3;
  18173. for ( i = 0, j = 0; i < points.length; i ++, j += 3 ) {
  18174. // select the normal of the vertex in the first line
  18175. n1.x = normals[ j + 0 ];
  18176. n1.y = normals[ j + 1 ];
  18177. n1.z = normals[ j + 2 ];
  18178. // select the normal of the vertex in the last line
  18179. n2.x = normals[ base + j + 0 ];
  18180. n2.y = normals[ base + j + 1 ];
  18181. n2.z = normals[ base + j + 2 ];
  18182. // average normals
  18183. n.addVectors( n1, n2 ).normalize();
  18184. // assign the new values to both normals
  18185. normals[ j + 0 ] = normals[ base + j + 0 ] = n.x;
  18186. normals[ j + 1 ] = normals[ base + j + 1 ] = n.y;
  18187. normals[ j + 2 ] = normals[ base + j + 2 ] = n.z;
  18188. }
  18189. }
  18190. }
  18191. LatheBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  18192. LatheBufferGeometry.prototype.constructor = LatheBufferGeometry;
  18193. /**
  18194. * @author jonobr1 / http://jonobr1.com
  18195. * @author Mugen87 / https://github.com/Mugen87
  18196. */
  18197. // ShapeGeometry
  18198. function ShapeGeometry( shapes, curveSegments ) {
  18199. Geometry.call( this );
  18200. this.type = 'ShapeGeometry';
  18201. if ( typeof curveSegments === 'object' ) {
  18202. console.warn( 'THREE.ShapeGeometry: Options parameter has been removed.' );
  18203. curveSegments = curveSegments.curveSegments;
  18204. }
  18205. this.parameters = {
  18206. shapes: shapes,
  18207. curveSegments: curveSegments
  18208. };
  18209. this.fromBufferGeometry( new ShapeBufferGeometry( shapes, curveSegments ) );
  18210. this.mergeVertices();
  18211. }
  18212. ShapeGeometry.prototype = Object.create( Geometry.prototype );
  18213. ShapeGeometry.prototype.constructor = ShapeGeometry;
  18214. ShapeGeometry.prototype.toJSON = function () {
  18215. var data = Geometry.prototype.toJSON.call( this );
  18216. var shapes = this.parameters.shapes;
  18217. return toJSON$1( shapes, data );
  18218. };
  18219. // ShapeBufferGeometry
  18220. function ShapeBufferGeometry( shapes, curveSegments ) {
  18221. BufferGeometry.call( this );
  18222. this.type = 'ShapeBufferGeometry';
  18223. this.parameters = {
  18224. shapes: shapes,
  18225. curveSegments: curveSegments
  18226. };
  18227. curveSegments = curveSegments || 12;
  18228. // buffers
  18229. var indices = [];
  18230. var vertices = [];
  18231. var normals = [];
  18232. var uvs = [];
  18233. // helper variables
  18234. var groupStart = 0;
  18235. var groupCount = 0;
  18236. // allow single and array values for "shapes" parameter
  18237. if ( Array.isArray( shapes ) === false ) {
  18238. addShape( shapes );
  18239. } else {
  18240. for ( var i = 0; i < shapes.length; i ++ ) {
  18241. addShape( shapes[ i ] );
  18242. this.addGroup( groupStart, groupCount, i ); // enables MultiMaterial support
  18243. groupStart += groupCount;
  18244. groupCount = 0;
  18245. }
  18246. }
  18247. // build geometry
  18248. this.setIndex( indices );
  18249. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  18250. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  18251. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  18252. // helper functions
  18253. function addShape( shape ) {
  18254. var i, l, shapeHole;
  18255. var indexOffset = vertices.length / 3;
  18256. var points = shape.extractPoints( curveSegments );
  18257. var shapeVertices = points.shape;
  18258. var shapeHoles = points.holes;
  18259. // check direction of vertices
  18260. if ( ShapeUtils.isClockWise( shapeVertices ) === false ) {
  18261. shapeVertices = shapeVertices.reverse();
  18262. }
  18263. for ( i = 0, l = shapeHoles.length; i < l; i ++ ) {
  18264. shapeHole = shapeHoles[ i ];
  18265. if ( ShapeUtils.isClockWise( shapeHole ) === true ) {
  18266. shapeHoles[ i ] = shapeHole.reverse();
  18267. }
  18268. }
  18269. var faces = ShapeUtils.triangulateShape( shapeVertices, shapeHoles );
  18270. // join vertices of inner and outer paths to a single array
  18271. for ( i = 0, l = shapeHoles.length; i < l; i ++ ) {
  18272. shapeHole = shapeHoles[ i ];
  18273. shapeVertices = shapeVertices.concat( shapeHole );
  18274. }
  18275. // vertices, normals, uvs
  18276. for ( i = 0, l = shapeVertices.length; i < l; i ++ ) {
  18277. var vertex = shapeVertices[ i ];
  18278. vertices.push( vertex.x, vertex.y, 0 );
  18279. normals.push( 0, 0, 1 );
  18280. uvs.push( vertex.x, vertex.y ); // world uvs
  18281. }
  18282. // incides
  18283. for ( i = 0, l = faces.length; i < l; i ++ ) {
  18284. var face = faces[ i ];
  18285. var a = face[ 0 ] + indexOffset;
  18286. var b = face[ 1 ] + indexOffset;
  18287. var c = face[ 2 ] + indexOffset;
  18288. indices.push( a, b, c );
  18289. groupCount += 3;
  18290. }
  18291. }
  18292. }
  18293. ShapeBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  18294. ShapeBufferGeometry.prototype.constructor = ShapeBufferGeometry;
  18295. ShapeBufferGeometry.prototype.toJSON = function () {
  18296. var data = BufferGeometry.prototype.toJSON.call( this );
  18297. var shapes = this.parameters.shapes;
  18298. return toJSON$1( shapes, data );
  18299. };
  18300. //
  18301. function toJSON$1( shapes, data ) {
  18302. data.shapes = [];
  18303. if ( Array.isArray( shapes ) ) {
  18304. for ( var i = 0, l = shapes.length; i < l; i ++ ) {
  18305. var shape = shapes[ i ];
  18306. data.shapes.push( shape.uuid );
  18307. }
  18308. } else {
  18309. data.shapes.push( shapes.uuid );
  18310. }
  18311. return data;
  18312. }
  18313. /**
  18314. * @author WestLangley / http://github.com/WestLangley
  18315. * @author Mugen87 / https://github.com/Mugen87
  18316. */
  18317. function EdgesGeometry( geometry, thresholdAngle ) {
  18318. BufferGeometry.call( this );
  18319. this.type = 'EdgesGeometry';
  18320. this.parameters = {
  18321. thresholdAngle: thresholdAngle
  18322. };
  18323. thresholdAngle = ( thresholdAngle !== undefined ) ? thresholdAngle : 1;
  18324. // buffer
  18325. var vertices = [];
  18326. // helper variables
  18327. var thresholdDot = Math.cos( _Math.DEG2RAD * thresholdAngle );
  18328. var edge = [ 0, 0 ], edges = {}, edge1, edge2;
  18329. var key, keys = [ 'a', 'b', 'c' ];
  18330. // prepare source geometry
  18331. var geometry2;
  18332. if ( geometry.isBufferGeometry ) {
  18333. geometry2 = new Geometry();
  18334. geometry2.fromBufferGeometry( geometry );
  18335. } else {
  18336. geometry2 = geometry.clone();
  18337. }
  18338. geometry2.mergeVertices();
  18339. geometry2.computeFaceNormals();
  18340. var sourceVertices = geometry2.vertices;
  18341. var faces = geometry2.faces;
  18342. // now create a data structure where each entry represents an edge with its adjoining faces
  18343. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  18344. var face = faces[ i ];
  18345. for ( var j = 0; j < 3; j ++ ) {
  18346. edge1 = face[ keys[ j ] ];
  18347. edge2 = face[ keys[ ( j + 1 ) % 3 ] ];
  18348. edge[ 0 ] = Math.min( edge1, edge2 );
  18349. edge[ 1 ] = Math.max( edge1, edge2 );
  18350. key = edge[ 0 ] + ',' + edge[ 1 ];
  18351. if ( edges[ key ] === undefined ) {
  18352. edges[ key ] = { index1: edge[ 0 ], index2: edge[ 1 ], face1: i, face2: undefined };
  18353. } else {
  18354. edges[ key ].face2 = i;
  18355. }
  18356. }
  18357. }
  18358. // generate vertices
  18359. for ( key in edges ) {
  18360. var e = edges[ key ];
  18361. // an edge is only rendered if the angle (in degrees) between the face normals of the adjoining faces exceeds this value. default = 1 degree.
  18362. if ( e.face2 === undefined || faces[ e.face1 ].normal.dot( faces[ e.face2 ].normal ) <= thresholdDot ) {
  18363. var vertex = sourceVertices[ e.index1 ];
  18364. vertices.push( vertex.x, vertex.y, vertex.z );
  18365. vertex = sourceVertices[ e.index2 ];
  18366. vertices.push( vertex.x, vertex.y, vertex.z );
  18367. }
  18368. }
  18369. // build geometry
  18370. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  18371. }
  18372. EdgesGeometry.prototype = Object.create( BufferGeometry.prototype );
  18373. EdgesGeometry.prototype.constructor = EdgesGeometry;
  18374. /**
  18375. * @author mrdoob / http://mrdoob.com/
  18376. * @author Mugen87 / https://github.com/Mugen87
  18377. */
  18378. // CylinderGeometry
  18379. function CylinderGeometry( radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  18380. Geometry.call( this );
  18381. this.type = 'CylinderGeometry';
  18382. this.parameters = {
  18383. radiusTop: radiusTop,
  18384. radiusBottom: radiusBottom,
  18385. height: height,
  18386. radialSegments: radialSegments,
  18387. heightSegments: heightSegments,
  18388. openEnded: openEnded,
  18389. thetaStart: thetaStart,
  18390. thetaLength: thetaLength
  18391. };
  18392. this.fromBufferGeometry( new CylinderBufferGeometry( radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) );
  18393. this.mergeVertices();
  18394. }
  18395. CylinderGeometry.prototype = Object.create( Geometry.prototype );
  18396. CylinderGeometry.prototype.constructor = CylinderGeometry;
  18397. // CylinderBufferGeometry
  18398. function CylinderBufferGeometry( radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  18399. BufferGeometry.call( this );
  18400. this.type = 'CylinderBufferGeometry';
  18401. this.parameters = {
  18402. radiusTop: radiusTop,
  18403. radiusBottom: radiusBottom,
  18404. height: height,
  18405. radialSegments: radialSegments,
  18406. heightSegments: heightSegments,
  18407. openEnded: openEnded,
  18408. thetaStart: thetaStart,
  18409. thetaLength: thetaLength
  18410. };
  18411. var scope = this;
  18412. radiusTop = radiusTop !== undefined ? radiusTop : 1;
  18413. radiusBottom = radiusBottom !== undefined ? radiusBottom : 1;
  18414. height = height || 1;
  18415. radialSegments = Math.floor( radialSegments ) || 8;
  18416. heightSegments = Math.floor( heightSegments ) || 1;
  18417. openEnded = openEnded !== undefined ? openEnded : false;
  18418. thetaStart = thetaStart !== undefined ? thetaStart : 0.0;
  18419. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  18420. // buffers
  18421. var indices = [];
  18422. var vertices = [];
  18423. var normals = [];
  18424. var uvs = [];
  18425. // helper variables
  18426. var index = 0;
  18427. var indexArray = [];
  18428. var halfHeight = height / 2;
  18429. var groupStart = 0;
  18430. // generate geometry
  18431. generateTorso();
  18432. if ( openEnded === false ) {
  18433. if ( radiusTop > 0 ) generateCap( true );
  18434. if ( radiusBottom > 0 ) generateCap( false );
  18435. }
  18436. // build geometry
  18437. this.setIndex( indices );
  18438. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  18439. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  18440. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  18441. function generateTorso() {
  18442. var x, y;
  18443. var normal = new Vector3();
  18444. var vertex = new Vector3();
  18445. var groupCount = 0;
  18446. // this will be used to calculate the normal
  18447. var slope = ( radiusBottom - radiusTop ) / height;
  18448. // generate vertices, normals and uvs
  18449. for ( y = 0; y <= heightSegments; y ++ ) {
  18450. var indexRow = [];
  18451. var v = y / heightSegments;
  18452. // calculate the radius of the current row
  18453. var radius = v * ( radiusBottom - radiusTop ) + radiusTop;
  18454. for ( x = 0; x <= radialSegments; x ++ ) {
  18455. var u = x / radialSegments;
  18456. var theta = u * thetaLength + thetaStart;
  18457. var sinTheta = Math.sin( theta );
  18458. var cosTheta = Math.cos( theta );
  18459. // vertex
  18460. vertex.x = radius * sinTheta;
  18461. vertex.y = - v * height + halfHeight;
  18462. vertex.z = radius * cosTheta;
  18463. vertices.push( vertex.x, vertex.y, vertex.z );
  18464. // normal
  18465. normal.set( sinTheta, slope, cosTheta ).normalize();
  18466. normals.push( normal.x, normal.y, normal.z );
  18467. // uv
  18468. uvs.push( u, 1 - v );
  18469. // save index of vertex in respective row
  18470. indexRow.push( index ++ );
  18471. }
  18472. // now save vertices of the row in our index array
  18473. indexArray.push( indexRow );
  18474. }
  18475. // generate indices
  18476. for ( x = 0; x < radialSegments; x ++ ) {
  18477. for ( y = 0; y < heightSegments; y ++ ) {
  18478. // we use the index array to access the correct indices
  18479. var a = indexArray[ y ][ x ];
  18480. var b = indexArray[ y + 1 ][ x ];
  18481. var c = indexArray[ y + 1 ][ x + 1 ];
  18482. var d = indexArray[ y ][ x + 1 ];
  18483. // faces
  18484. indices.push( a, b, d );
  18485. indices.push( b, c, d );
  18486. // update group counter
  18487. groupCount += 6;
  18488. }
  18489. }
  18490. // add a group to the geometry. this will ensure multi material support
  18491. scope.addGroup( groupStart, groupCount, 0 );
  18492. // calculate new start value for groups
  18493. groupStart += groupCount;
  18494. }
  18495. function generateCap( top ) {
  18496. var x, centerIndexStart, centerIndexEnd;
  18497. var uv = new Vector2();
  18498. var vertex = new Vector3();
  18499. var groupCount = 0;
  18500. var radius = ( top === true ) ? radiusTop : radiusBottom;
  18501. var sign = ( top === true ) ? 1 : - 1;
  18502. // save the index of the first center vertex
  18503. centerIndexStart = index;
  18504. // first we generate the center vertex data of the cap.
  18505. // because the geometry needs one set of uvs per face,
  18506. // we must generate a center vertex per face/segment
  18507. for ( x = 1; x <= radialSegments; x ++ ) {
  18508. // vertex
  18509. vertices.push( 0, halfHeight * sign, 0 );
  18510. // normal
  18511. normals.push( 0, sign, 0 );
  18512. // uv
  18513. uvs.push( 0.5, 0.5 );
  18514. // increase index
  18515. index ++;
  18516. }
  18517. // save the index of the last center vertex
  18518. centerIndexEnd = index;
  18519. // now we generate the surrounding vertices, normals and uvs
  18520. for ( x = 0; x <= radialSegments; x ++ ) {
  18521. var u = x / radialSegments;
  18522. var theta = u * thetaLength + thetaStart;
  18523. var cosTheta = Math.cos( theta );
  18524. var sinTheta = Math.sin( theta );
  18525. // vertex
  18526. vertex.x = radius * sinTheta;
  18527. vertex.y = halfHeight * sign;
  18528. vertex.z = radius * cosTheta;
  18529. vertices.push( vertex.x, vertex.y, vertex.z );
  18530. // normal
  18531. normals.push( 0, sign, 0 );
  18532. // uv
  18533. uv.x = ( cosTheta * 0.5 ) + 0.5;
  18534. uv.y = ( sinTheta * 0.5 * sign ) + 0.5;
  18535. uvs.push( uv.x, uv.y );
  18536. // increase index
  18537. index ++;
  18538. }
  18539. // generate indices
  18540. for ( x = 0; x < radialSegments; x ++ ) {
  18541. var c = centerIndexStart + x;
  18542. var i = centerIndexEnd + x;
  18543. if ( top === true ) {
  18544. // face top
  18545. indices.push( i, i + 1, c );
  18546. } else {
  18547. // face bottom
  18548. indices.push( i + 1, i, c );
  18549. }
  18550. groupCount += 3;
  18551. }
  18552. // add a group to the geometry. this will ensure multi material support
  18553. scope.addGroup( groupStart, groupCount, top === true ? 1 : 2 );
  18554. // calculate new start value for groups
  18555. groupStart += groupCount;
  18556. }
  18557. }
  18558. CylinderBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  18559. CylinderBufferGeometry.prototype.constructor = CylinderBufferGeometry;
  18560. /**
  18561. * @author abelnation / http://github.com/abelnation
  18562. */
  18563. // ConeGeometry
  18564. function ConeGeometry( radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  18565. CylinderGeometry.call( this, 0, radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength );
  18566. this.type = 'ConeGeometry';
  18567. this.parameters = {
  18568. radius: radius,
  18569. height: height,
  18570. radialSegments: radialSegments,
  18571. heightSegments: heightSegments,
  18572. openEnded: openEnded,
  18573. thetaStart: thetaStart,
  18574. thetaLength: thetaLength
  18575. };
  18576. }
  18577. ConeGeometry.prototype = Object.create( CylinderGeometry.prototype );
  18578. ConeGeometry.prototype.constructor = ConeGeometry;
  18579. // ConeBufferGeometry
  18580. function ConeBufferGeometry( radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  18581. CylinderBufferGeometry.call( this, 0, radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength );
  18582. this.type = 'ConeBufferGeometry';
  18583. this.parameters = {
  18584. radius: radius,
  18585. height: height,
  18586. radialSegments: radialSegments,
  18587. heightSegments: heightSegments,
  18588. openEnded: openEnded,
  18589. thetaStart: thetaStart,
  18590. thetaLength: thetaLength
  18591. };
  18592. }
  18593. ConeBufferGeometry.prototype = Object.create( CylinderBufferGeometry.prototype );
  18594. ConeBufferGeometry.prototype.constructor = ConeBufferGeometry;
  18595. /**
  18596. * @author benaadams / https://twitter.com/ben_a_adams
  18597. * @author Mugen87 / https://github.com/Mugen87
  18598. * @author hughes
  18599. */
  18600. // CircleGeometry
  18601. function CircleGeometry( radius, segments, thetaStart, thetaLength ) {
  18602. Geometry.call( this );
  18603. this.type = 'CircleGeometry';
  18604. this.parameters = {
  18605. radius: radius,
  18606. segments: segments,
  18607. thetaStart: thetaStart,
  18608. thetaLength: thetaLength
  18609. };
  18610. this.fromBufferGeometry( new CircleBufferGeometry( radius, segments, thetaStart, thetaLength ) );
  18611. this.mergeVertices();
  18612. }
  18613. CircleGeometry.prototype = Object.create( Geometry.prototype );
  18614. CircleGeometry.prototype.constructor = CircleGeometry;
  18615. // CircleBufferGeometry
  18616. function CircleBufferGeometry( radius, segments, thetaStart, thetaLength ) {
  18617. BufferGeometry.call( this );
  18618. this.type = 'CircleBufferGeometry';
  18619. this.parameters = {
  18620. radius: radius,
  18621. segments: segments,
  18622. thetaStart: thetaStart,
  18623. thetaLength: thetaLength
  18624. };
  18625. radius = radius || 1;
  18626. segments = segments !== undefined ? Math.max( 3, segments ) : 8;
  18627. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  18628. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  18629. // buffers
  18630. var indices = [];
  18631. var vertices = [];
  18632. var normals = [];
  18633. var uvs = [];
  18634. // helper variables
  18635. var i, s;
  18636. var vertex = new Vector3();
  18637. var uv = new Vector2();
  18638. // center point
  18639. vertices.push( 0, 0, 0 );
  18640. normals.push( 0, 0, 1 );
  18641. uvs.push( 0.5, 0.5 );
  18642. for ( s = 0, i = 3; s <= segments; s ++, i += 3 ) {
  18643. var segment = thetaStart + s / segments * thetaLength;
  18644. // vertex
  18645. vertex.x = radius * Math.cos( segment );
  18646. vertex.y = radius * Math.sin( segment );
  18647. vertices.push( vertex.x, vertex.y, vertex.z );
  18648. // normal
  18649. normals.push( 0, 0, 1 );
  18650. // uvs
  18651. uv.x = ( vertices[ i ] / radius + 1 ) / 2;
  18652. uv.y = ( vertices[ i + 1 ] / radius + 1 ) / 2;
  18653. uvs.push( uv.x, uv.y );
  18654. }
  18655. // indices
  18656. for ( i = 1; i <= segments; i ++ ) {
  18657. indices.push( i, i + 1, 0 );
  18658. }
  18659. // build geometry
  18660. this.setIndex( indices );
  18661. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  18662. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  18663. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  18664. }
  18665. CircleBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  18666. CircleBufferGeometry.prototype.constructor = CircleBufferGeometry;
  18667. var Geometries = /*#__PURE__*/Object.freeze({
  18668. WireframeGeometry: WireframeGeometry,
  18669. ParametricGeometry: ParametricGeometry,
  18670. ParametricBufferGeometry: ParametricBufferGeometry,
  18671. TetrahedronGeometry: TetrahedronGeometry,
  18672. TetrahedronBufferGeometry: TetrahedronBufferGeometry,
  18673. OctahedronGeometry: OctahedronGeometry,
  18674. OctahedronBufferGeometry: OctahedronBufferGeometry,
  18675. IcosahedronGeometry: IcosahedronGeometry,
  18676. IcosahedronBufferGeometry: IcosahedronBufferGeometry,
  18677. DodecahedronGeometry: DodecahedronGeometry,
  18678. DodecahedronBufferGeometry: DodecahedronBufferGeometry,
  18679. PolyhedronGeometry: PolyhedronGeometry,
  18680. PolyhedronBufferGeometry: PolyhedronBufferGeometry,
  18681. TubeGeometry: TubeGeometry,
  18682. TubeBufferGeometry: TubeBufferGeometry,
  18683. TorusKnotGeometry: TorusKnotGeometry,
  18684. TorusKnotBufferGeometry: TorusKnotBufferGeometry,
  18685. TorusGeometry: TorusGeometry,
  18686. TorusBufferGeometry: TorusBufferGeometry,
  18687. TextGeometry: TextGeometry,
  18688. TextBufferGeometry: TextBufferGeometry,
  18689. SphereGeometry: SphereGeometry,
  18690. SphereBufferGeometry: SphereBufferGeometry,
  18691. RingGeometry: RingGeometry,
  18692. RingBufferGeometry: RingBufferGeometry,
  18693. PlaneGeometry: PlaneGeometry,
  18694. PlaneBufferGeometry: PlaneBufferGeometry,
  18695. LatheGeometry: LatheGeometry,
  18696. LatheBufferGeometry: LatheBufferGeometry,
  18697. ShapeGeometry: ShapeGeometry,
  18698. ShapeBufferGeometry: ShapeBufferGeometry,
  18699. ExtrudeGeometry: ExtrudeGeometry,
  18700. ExtrudeBufferGeometry: ExtrudeBufferGeometry,
  18701. EdgesGeometry: EdgesGeometry,
  18702. ConeGeometry: ConeGeometry,
  18703. ConeBufferGeometry: ConeBufferGeometry,
  18704. CylinderGeometry: CylinderGeometry,
  18705. CylinderBufferGeometry: CylinderBufferGeometry,
  18706. CircleGeometry: CircleGeometry,
  18707. CircleBufferGeometry: CircleBufferGeometry,
  18708. BoxGeometry: BoxGeometry,
  18709. BoxBufferGeometry: BoxBufferGeometry
  18710. });
  18711. /**
  18712. * @author mrdoob / http://mrdoob.com/
  18713. *
  18714. * parameters = {
  18715. * color: <THREE.Color>
  18716. * }
  18717. */
  18718. function ShadowMaterial( parameters ) {
  18719. Material.call( this );
  18720. this.type = 'ShadowMaterial';
  18721. this.color = new Color( 0x000000 );
  18722. this.transparent = true;
  18723. this.setValues( parameters );
  18724. }
  18725. ShadowMaterial.prototype = Object.create( Material.prototype );
  18726. ShadowMaterial.prototype.constructor = ShadowMaterial;
  18727. ShadowMaterial.prototype.isShadowMaterial = true;
  18728. ShadowMaterial.prototype.copy = function ( source ) {
  18729. Material.prototype.copy.call( this, source );
  18730. this.color.copy( source.color );
  18731. return this;
  18732. };
  18733. /**
  18734. * @author mrdoob / http://mrdoob.com/
  18735. */
  18736. function RawShaderMaterial( parameters ) {
  18737. ShaderMaterial.call( this, parameters );
  18738. this.type = 'RawShaderMaterial';
  18739. }
  18740. RawShaderMaterial.prototype = Object.create( ShaderMaterial.prototype );
  18741. RawShaderMaterial.prototype.constructor = RawShaderMaterial;
  18742. RawShaderMaterial.prototype.isRawShaderMaterial = true;
  18743. /**
  18744. * @author WestLangley / http://github.com/WestLangley
  18745. *
  18746. * parameters = {
  18747. * color: <hex>,
  18748. * roughness: <float>,
  18749. * metalness: <float>,
  18750. * opacity: <float>,
  18751. *
  18752. * map: new THREE.Texture( <Image> ),
  18753. *
  18754. * lightMap: new THREE.Texture( <Image> ),
  18755. * lightMapIntensity: <float>
  18756. *
  18757. * aoMap: new THREE.Texture( <Image> ),
  18758. * aoMapIntensity: <float>
  18759. *
  18760. * emissive: <hex>,
  18761. * emissiveIntensity: <float>
  18762. * emissiveMap: new THREE.Texture( <Image> ),
  18763. *
  18764. * bumpMap: new THREE.Texture( <Image> ),
  18765. * bumpScale: <float>,
  18766. *
  18767. * normalMap: new THREE.Texture( <Image> ),
  18768. * normalMapType: THREE.TangentSpaceNormalMap,
  18769. * normalScale: <Vector2>,
  18770. *
  18771. * displacementMap: new THREE.Texture( <Image> ),
  18772. * displacementScale: <float>,
  18773. * displacementBias: <float>,
  18774. *
  18775. * roughnessMap: new THREE.Texture( <Image> ),
  18776. *
  18777. * metalnessMap: new THREE.Texture( <Image> ),
  18778. *
  18779. * alphaMap: new THREE.Texture( <Image> ),
  18780. *
  18781. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  18782. * envMapIntensity: <float>
  18783. *
  18784. * refractionRatio: <float>,
  18785. *
  18786. * wireframe: <boolean>,
  18787. * wireframeLinewidth: <float>,
  18788. *
  18789. * skinning: <bool>,
  18790. * morphTargets: <bool>,
  18791. * morphNormals: <bool>
  18792. * }
  18793. */
  18794. function MeshStandardMaterial( parameters ) {
  18795. Material.call( this );
  18796. this.defines = { 'STANDARD': '' };
  18797. this.type = 'MeshStandardMaterial';
  18798. this.color = new Color( 0xffffff ); // diffuse
  18799. this.roughness = 0.5;
  18800. this.metalness = 0.5;
  18801. this.map = null;
  18802. this.lightMap = null;
  18803. this.lightMapIntensity = 1.0;
  18804. this.aoMap = null;
  18805. this.aoMapIntensity = 1.0;
  18806. this.emissive = new Color( 0x000000 );
  18807. this.emissiveIntensity = 1.0;
  18808. this.emissiveMap = null;
  18809. this.bumpMap = null;
  18810. this.bumpScale = 1;
  18811. this.normalMap = null;
  18812. this.normalMapType = TangentSpaceNormalMap;
  18813. this.normalScale = new Vector2( 1, 1 );
  18814. this.displacementMap = null;
  18815. this.displacementScale = 1;
  18816. this.displacementBias = 0;
  18817. this.roughnessMap = null;
  18818. this.metalnessMap = null;
  18819. this.alphaMap = null;
  18820. this.envMap = null;
  18821. this.envMapIntensity = 1.0;
  18822. this.refractionRatio = 0.98;
  18823. this.wireframe = false;
  18824. this.wireframeLinewidth = 1;
  18825. this.wireframeLinecap = 'round';
  18826. this.wireframeLinejoin = 'round';
  18827. this.skinning = false;
  18828. this.morphTargets = false;
  18829. this.morphNormals = false;
  18830. this.setValues( parameters );
  18831. }
  18832. MeshStandardMaterial.prototype = Object.create( Material.prototype );
  18833. MeshStandardMaterial.prototype.constructor = MeshStandardMaterial;
  18834. MeshStandardMaterial.prototype.isMeshStandardMaterial = true;
  18835. MeshStandardMaterial.prototype.copy = function ( source ) {
  18836. Material.prototype.copy.call( this, source );
  18837. this.defines = { 'STANDARD': '' };
  18838. this.color.copy( source.color );
  18839. this.roughness = source.roughness;
  18840. this.metalness = source.metalness;
  18841. this.map = source.map;
  18842. this.lightMap = source.lightMap;
  18843. this.lightMapIntensity = source.lightMapIntensity;
  18844. this.aoMap = source.aoMap;
  18845. this.aoMapIntensity = source.aoMapIntensity;
  18846. this.emissive.copy( source.emissive );
  18847. this.emissiveMap = source.emissiveMap;
  18848. this.emissiveIntensity = source.emissiveIntensity;
  18849. this.bumpMap = source.bumpMap;
  18850. this.bumpScale = source.bumpScale;
  18851. this.normalMap = source.normalMap;
  18852. this.normalMapType = source.normalMapType;
  18853. this.normalScale.copy( source.normalScale );
  18854. this.displacementMap = source.displacementMap;
  18855. this.displacementScale = source.displacementScale;
  18856. this.displacementBias = source.displacementBias;
  18857. this.roughnessMap = source.roughnessMap;
  18858. this.metalnessMap = source.metalnessMap;
  18859. this.alphaMap = source.alphaMap;
  18860. this.envMap = source.envMap;
  18861. this.envMapIntensity = source.envMapIntensity;
  18862. this.refractionRatio = source.refractionRatio;
  18863. this.wireframe = source.wireframe;
  18864. this.wireframeLinewidth = source.wireframeLinewidth;
  18865. this.wireframeLinecap = source.wireframeLinecap;
  18866. this.wireframeLinejoin = source.wireframeLinejoin;
  18867. this.skinning = source.skinning;
  18868. this.morphTargets = source.morphTargets;
  18869. this.morphNormals = source.morphNormals;
  18870. return this;
  18871. };
  18872. /**
  18873. * @author WestLangley / http://github.com/WestLangley
  18874. *
  18875. * parameters = {
  18876. * reflectivity: <float>
  18877. * clearCoat: <float>
  18878. * clearCoatRoughness: <float>
  18879. * }
  18880. */
  18881. function MeshPhysicalMaterial( parameters ) {
  18882. MeshStandardMaterial.call( this );
  18883. this.defines = { 'PHYSICAL': '' };
  18884. this.type = 'MeshPhysicalMaterial';
  18885. this.reflectivity = 0.5; // maps to F0 = 0.04
  18886. this.clearCoat = 0.0;
  18887. this.clearCoatRoughness = 0.0;
  18888. this.setValues( parameters );
  18889. }
  18890. MeshPhysicalMaterial.prototype = Object.create( MeshStandardMaterial.prototype );
  18891. MeshPhysicalMaterial.prototype.constructor = MeshPhysicalMaterial;
  18892. MeshPhysicalMaterial.prototype.isMeshPhysicalMaterial = true;
  18893. MeshPhysicalMaterial.prototype.copy = function ( source ) {
  18894. MeshStandardMaterial.prototype.copy.call( this, source );
  18895. this.defines = { 'PHYSICAL': '' };
  18896. this.reflectivity = source.reflectivity;
  18897. this.clearCoat = source.clearCoat;
  18898. this.clearCoatRoughness = source.clearCoatRoughness;
  18899. return this;
  18900. };
  18901. /**
  18902. * @author mrdoob / http://mrdoob.com/
  18903. * @author alteredq / http://alteredqualia.com/
  18904. *
  18905. * parameters = {
  18906. * color: <hex>,
  18907. * specular: <hex>,
  18908. * shininess: <float>,
  18909. * opacity: <float>,
  18910. *
  18911. * map: new THREE.Texture( <Image> ),
  18912. *
  18913. * lightMap: new THREE.Texture( <Image> ),
  18914. * lightMapIntensity: <float>
  18915. *
  18916. * aoMap: new THREE.Texture( <Image> ),
  18917. * aoMapIntensity: <float>
  18918. *
  18919. * emissive: <hex>,
  18920. * emissiveIntensity: <float>
  18921. * emissiveMap: new THREE.Texture( <Image> ),
  18922. *
  18923. * bumpMap: new THREE.Texture( <Image> ),
  18924. * bumpScale: <float>,
  18925. *
  18926. * normalMap: new THREE.Texture( <Image> ),
  18927. * normalMapType: THREE.TangentSpaceNormalMap,
  18928. * normalScale: <Vector2>,
  18929. *
  18930. * displacementMap: new THREE.Texture( <Image> ),
  18931. * displacementScale: <float>,
  18932. * displacementBias: <float>,
  18933. *
  18934. * specularMap: new THREE.Texture( <Image> ),
  18935. *
  18936. * alphaMap: new THREE.Texture( <Image> ),
  18937. *
  18938. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  18939. * combine: THREE.Multiply,
  18940. * reflectivity: <float>,
  18941. * refractionRatio: <float>,
  18942. *
  18943. * wireframe: <boolean>,
  18944. * wireframeLinewidth: <float>,
  18945. *
  18946. * skinning: <bool>,
  18947. * morphTargets: <bool>,
  18948. * morphNormals: <bool>
  18949. * }
  18950. */
  18951. function MeshPhongMaterial( parameters ) {
  18952. Material.call( this );
  18953. this.type = 'MeshPhongMaterial';
  18954. this.color = new Color( 0xffffff ); // diffuse
  18955. this.specular = new Color( 0x111111 );
  18956. this.shininess = 30;
  18957. this.map = null;
  18958. this.lightMap = null;
  18959. this.lightMapIntensity = 1.0;
  18960. this.aoMap = null;
  18961. this.aoMapIntensity = 1.0;
  18962. this.emissive = new Color( 0x000000 );
  18963. this.emissiveIntensity = 1.0;
  18964. this.emissiveMap = null;
  18965. this.bumpMap = null;
  18966. this.bumpScale = 1;
  18967. this.normalMap = null;
  18968. this.normalMapType = TangentSpaceNormalMap;
  18969. this.normalScale = new Vector2( 1, 1 );
  18970. this.displacementMap = null;
  18971. this.displacementScale = 1;
  18972. this.displacementBias = 0;
  18973. this.specularMap = null;
  18974. this.alphaMap = null;
  18975. this.envMap = null;
  18976. this.combine = MultiplyOperation;
  18977. this.reflectivity = 1;
  18978. this.refractionRatio = 0.98;
  18979. this.wireframe = false;
  18980. this.wireframeLinewidth = 1;
  18981. this.wireframeLinecap = 'round';
  18982. this.wireframeLinejoin = 'round';
  18983. this.skinning = false;
  18984. this.morphTargets = false;
  18985. this.morphNormals = false;
  18986. this.setValues( parameters );
  18987. }
  18988. MeshPhongMaterial.prototype = Object.create( Material.prototype );
  18989. MeshPhongMaterial.prototype.constructor = MeshPhongMaterial;
  18990. MeshPhongMaterial.prototype.isMeshPhongMaterial = true;
  18991. MeshPhongMaterial.prototype.copy = function ( source ) {
  18992. Material.prototype.copy.call( this, source );
  18993. this.color.copy( source.color );
  18994. this.specular.copy( source.specular );
  18995. this.shininess = source.shininess;
  18996. this.map = source.map;
  18997. this.lightMap = source.lightMap;
  18998. this.lightMapIntensity = source.lightMapIntensity;
  18999. this.aoMap = source.aoMap;
  19000. this.aoMapIntensity = source.aoMapIntensity;
  19001. this.emissive.copy( source.emissive );
  19002. this.emissiveMap = source.emissiveMap;
  19003. this.emissiveIntensity = source.emissiveIntensity;
  19004. this.bumpMap = source.bumpMap;
  19005. this.bumpScale = source.bumpScale;
  19006. this.normalMap = source.normalMap;
  19007. this.normalMapType = source.normalMapType;
  19008. this.normalScale.copy( source.normalScale );
  19009. this.displacementMap = source.displacementMap;
  19010. this.displacementScale = source.displacementScale;
  19011. this.displacementBias = source.displacementBias;
  19012. this.specularMap = source.specularMap;
  19013. this.alphaMap = source.alphaMap;
  19014. this.envMap = source.envMap;
  19015. this.combine = source.combine;
  19016. this.reflectivity = source.reflectivity;
  19017. this.refractionRatio = source.refractionRatio;
  19018. this.wireframe = source.wireframe;
  19019. this.wireframeLinewidth = source.wireframeLinewidth;
  19020. this.wireframeLinecap = source.wireframeLinecap;
  19021. this.wireframeLinejoin = source.wireframeLinejoin;
  19022. this.skinning = source.skinning;
  19023. this.morphTargets = source.morphTargets;
  19024. this.morphNormals = source.morphNormals;
  19025. return this;
  19026. };
  19027. /**
  19028. * @author takahirox / http://github.com/takahirox
  19029. *
  19030. * parameters = {
  19031. * gradientMap: new THREE.Texture( <Image> )
  19032. * }
  19033. */
  19034. function MeshToonMaterial( parameters ) {
  19035. MeshPhongMaterial.call( this );
  19036. this.defines = { 'TOON': '' };
  19037. this.type = 'MeshToonMaterial';
  19038. this.gradientMap = null;
  19039. this.setValues( parameters );
  19040. }
  19041. MeshToonMaterial.prototype = Object.create( MeshPhongMaterial.prototype );
  19042. MeshToonMaterial.prototype.constructor = MeshToonMaterial;
  19043. MeshToonMaterial.prototype.isMeshToonMaterial = true;
  19044. MeshToonMaterial.prototype.copy = function ( source ) {
  19045. MeshPhongMaterial.prototype.copy.call( this, source );
  19046. this.gradientMap = source.gradientMap;
  19047. return this;
  19048. };
  19049. /**
  19050. * @author mrdoob / http://mrdoob.com/
  19051. * @author WestLangley / http://github.com/WestLangley
  19052. *
  19053. * parameters = {
  19054. * opacity: <float>,
  19055. *
  19056. * bumpMap: new THREE.Texture( <Image> ),
  19057. * bumpScale: <float>,
  19058. *
  19059. * normalMap: new THREE.Texture( <Image> ),
  19060. * normalMapType: THREE.TangentSpaceNormalMap,
  19061. * normalScale: <Vector2>,
  19062. *
  19063. * displacementMap: new THREE.Texture( <Image> ),
  19064. * displacementScale: <float>,
  19065. * displacementBias: <float>,
  19066. *
  19067. * wireframe: <boolean>,
  19068. * wireframeLinewidth: <float>
  19069. *
  19070. * skinning: <bool>,
  19071. * morphTargets: <bool>,
  19072. * morphNormals: <bool>
  19073. * }
  19074. */
  19075. function MeshNormalMaterial( parameters ) {
  19076. Material.call( this );
  19077. this.type = 'MeshNormalMaterial';
  19078. this.bumpMap = null;
  19079. this.bumpScale = 1;
  19080. this.normalMap = null;
  19081. this.normalMapType = TangentSpaceNormalMap;
  19082. this.normalScale = new Vector2( 1, 1 );
  19083. this.displacementMap = null;
  19084. this.displacementScale = 1;
  19085. this.displacementBias = 0;
  19086. this.wireframe = false;
  19087. this.wireframeLinewidth = 1;
  19088. this.fog = false;
  19089. this.lights = false;
  19090. this.skinning = false;
  19091. this.morphTargets = false;
  19092. this.morphNormals = false;
  19093. this.setValues( parameters );
  19094. }
  19095. MeshNormalMaterial.prototype = Object.create( Material.prototype );
  19096. MeshNormalMaterial.prototype.constructor = MeshNormalMaterial;
  19097. MeshNormalMaterial.prototype.isMeshNormalMaterial = true;
  19098. MeshNormalMaterial.prototype.copy = function ( source ) {
  19099. Material.prototype.copy.call( this, source );
  19100. this.bumpMap = source.bumpMap;
  19101. this.bumpScale = source.bumpScale;
  19102. this.normalMap = source.normalMap;
  19103. this.normalMapType = source.normalMapType;
  19104. this.normalScale.copy( source.normalScale );
  19105. this.displacementMap = source.displacementMap;
  19106. this.displacementScale = source.displacementScale;
  19107. this.displacementBias = source.displacementBias;
  19108. this.wireframe = source.wireframe;
  19109. this.wireframeLinewidth = source.wireframeLinewidth;
  19110. this.skinning = source.skinning;
  19111. this.morphTargets = source.morphTargets;
  19112. this.morphNormals = source.morphNormals;
  19113. return this;
  19114. };
  19115. /**
  19116. * @author mrdoob / http://mrdoob.com/
  19117. * @author alteredq / http://alteredqualia.com/
  19118. *
  19119. * parameters = {
  19120. * color: <hex>,
  19121. * opacity: <float>,
  19122. *
  19123. * map: new THREE.Texture( <Image> ),
  19124. *
  19125. * lightMap: new THREE.Texture( <Image> ),
  19126. * lightMapIntensity: <float>
  19127. *
  19128. * aoMap: new THREE.Texture( <Image> ),
  19129. * aoMapIntensity: <float>
  19130. *
  19131. * emissive: <hex>,
  19132. * emissiveIntensity: <float>
  19133. * emissiveMap: new THREE.Texture( <Image> ),
  19134. *
  19135. * specularMap: new THREE.Texture( <Image> ),
  19136. *
  19137. * alphaMap: new THREE.Texture( <Image> ),
  19138. *
  19139. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  19140. * combine: THREE.Multiply,
  19141. * reflectivity: <float>,
  19142. * refractionRatio: <float>,
  19143. *
  19144. * wireframe: <boolean>,
  19145. * wireframeLinewidth: <float>,
  19146. *
  19147. * skinning: <bool>,
  19148. * morphTargets: <bool>,
  19149. * morphNormals: <bool>
  19150. * }
  19151. */
  19152. function MeshLambertMaterial( parameters ) {
  19153. Material.call( this );
  19154. this.type = 'MeshLambertMaterial';
  19155. this.color = new Color( 0xffffff ); // diffuse
  19156. this.map = null;
  19157. this.lightMap = null;
  19158. this.lightMapIntensity = 1.0;
  19159. this.aoMap = null;
  19160. this.aoMapIntensity = 1.0;
  19161. this.emissive = new Color( 0x000000 );
  19162. this.emissiveIntensity = 1.0;
  19163. this.emissiveMap = null;
  19164. this.specularMap = null;
  19165. this.alphaMap = null;
  19166. this.envMap = null;
  19167. this.combine = MultiplyOperation;
  19168. this.reflectivity = 1;
  19169. this.refractionRatio = 0.98;
  19170. this.wireframe = false;
  19171. this.wireframeLinewidth = 1;
  19172. this.wireframeLinecap = 'round';
  19173. this.wireframeLinejoin = 'round';
  19174. this.skinning = false;
  19175. this.morphTargets = false;
  19176. this.morphNormals = false;
  19177. this.setValues( parameters );
  19178. }
  19179. MeshLambertMaterial.prototype = Object.create( Material.prototype );
  19180. MeshLambertMaterial.prototype.constructor = MeshLambertMaterial;
  19181. MeshLambertMaterial.prototype.isMeshLambertMaterial = true;
  19182. MeshLambertMaterial.prototype.copy = function ( source ) {
  19183. Material.prototype.copy.call( this, source );
  19184. this.color.copy( source.color );
  19185. this.map = source.map;
  19186. this.lightMap = source.lightMap;
  19187. this.lightMapIntensity = source.lightMapIntensity;
  19188. this.aoMap = source.aoMap;
  19189. this.aoMapIntensity = source.aoMapIntensity;
  19190. this.emissive.copy( source.emissive );
  19191. this.emissiveMap = source.emissiveMap;
  19192. this.emissiveIntensity = source.emissiveIntensity;
  19193. this.specularMap = source.specularMap;
  19194. this.alphaMap = source.alphaMap;
  19195. this.envMap = source.envMap;
  19196. this.combine = source.combine;
  19197. this.reflectivity = source.reflectivity;
  19198. this.refractionRatio = source.refractionRatio;
  19199. this.wireframe = source.wireframe;
  19200. this.wireframeLinewidth = source.wireframeLinewidth;
  19201. this.wireframeLinecap = source.wireframeLinecap;
  19202. this.wireframeLinejoin = source.wireframeLinejoin;
  19203. this.skinning = source.skinning;
  19204. this.morphTargets = source.morphTargets;
  19205. this.morphNormals = source.morphNormals;
  19206. return this;
  19207. };
  19208. /**
  19209. * @author WestLangley / http://github.com/WestLangley
  19210. *
  19211. * parameters = {
  19212. * color: <hex>,
  19213. * opacity: <float>,
  19214. *
  19215. * matcap: new THREE.Texture( <Image> ),
  19216. *
  19217. * map: new THREE.Texture( <Image> ),
  19218. *
  19219. * bumpMap: new THREE.Texture( <Image> ),
  19220. * bumpScale: <float>,
  19221. *
  19222. * normalMap: new THREE.Texture( <Image> ),
  19223. * normalMapType: THREE.TangentSpaceNormalMap,
  19224. * normalScale: <Vector2>,
  19225. *
  19226. * displacementMap: new THREE.Texture( <Image> ),
  19227. * displacementScale: <float>,
  19228. * displacementBias: <float>,
  19229. *
  19230. * alphaMap: new THREE.Texture( <Image> ),
  19231. *
  19232. * skinning: <bool>,
  19233. * morphTargets: <bool>,
  19234. * morphNormals: <bool>
  19235. * }
  19236. */
  19237. function MeshMatcapMaterial( parameters ) {
  19238. Material.call( this );
  19239. this.defines = { 'MATCAP': '' };
  19240. this.type = 'MeshMatcapMaterial';
  19241. this.color = new Color( 0xffffff ); // diffuse
  19242. this.matcap = null;
  19243. this.map = null;
  19244. this.bumpMap = null;
  19245. this.bumpScale = 1;
  19246. this.normalMap = null;
  19247. this.normalMapType = TangentSpaceNormalMap;
  19248. this.normalScale = new Vector2( 1, 1 );
  19249. this.displacementMap = null;
  19250. this.displacementScale = 1;
  19251. this.displacementBias = 0;
  19252. this.alphaMap = null;
  19253. this.skinning = false;
  19254. this.morphTargets = false;
  19255. this.morphNormals = false;
  19256. this.lights = false;
  19257. this.setValues( parameters );
  19258. }
  19259. MeshMatcapMaterial.prototype = Object.create( Material.prototype );
  19260. MeshMatcapMaterial.prototype.constructor = MeshMatcapMaterial;
  19261. MeshMatcapMaterial.prototype.isMeshMatcapMaterial = true;
  19262. MeshMatcapMaterial.prototype.copy = function ( source ) {
  19263. Material.prototype.copy.call( this, source );
  19264. this.defines = { 'MATCAP': '' };
  19265. this.color.copy( source.color );
  19266. this.matcap = source.matcap;
  19267. this.map = source.map;
  19268. this.bumpMap = source.bumpMap;
  19269. this.bumpScale = source.bumpScale;
  19270. this.normalMap = source.normalMap;
  19271. this.normalMapType = source.normalMapType;
  19272. this.normalScale.copy( source.normalScale );
  19273. this.displacementMap = source.displacementMap;
  19274. this.displacementScale = source.displacementScale;
  19275. this.displacementBias = source.displacementBias;
  19276. this.alphaMap = source.alphaMap;
  19277. this.skinning = source.skinning;
  19278. this.morphTargets = source.morphTargets;
  19279. this.morphNormals = source.morphNormals;
  19280. return this;
  19281. };
  19282. /**
  19283. * @author alteredq / http://alteredqualia.com/
  19284. *
  19285. * parameters = {
  19286. * color: <hex>,
  19287. * opacity: <float>,
  19288. *
  19289. * linewidth: <float>,
  19290. *
  19291. * scale: <float>,
  19292. * dashSize: <float>,
  19293. * gapSize: <float>
  19294. * }
  19295. */
  19296. function LineDashedMaterial( parameters ) {
  19297. LineBasicMaterial.call( this );
  19298. this.type = 'LineDashedMaterial';
  19299. this.scale = 1;
  19300. this.dashSize = 3;
  19301. this.gapSize = 1;
  19302. this.setValues( parameters );
  19303. }
  19304. LineDashedMaterial.prototype = Object.create( LineBasicMaterial.prototype );
  19305. LineDashedMaterial.prototype.constructor = LineDashedMaterial;
  19306. LineDashedMaterial.prototype.isLineDashedMaterial = true;
  19307. LineDashedMaterial.prototype.copy = function ( source ) {
  19308. LineBasicMaterial.prototype.copy.call( this, source );
  19309. this.scale = source.scale;
  19310. this.dashSize = source.dashSize;
  19311. this.gapSize = source.gapSize;
  19312. return this;
  19313. };
  19314. var Materials = /*#__PURE__*/Object.freeze({
  19315. ShadowMaterial: ShadowMaterial,
  19316. SpriteMaterial: SpriteMaterial,
  19317. RawShaderMaterial: RawShaderMaterial,
  19318. ShaderMaterial: ShaderMaterial,
  19319. PointsMaterial: PointsMaterial,
  19320. MeshPhysicalMaterial: MeshPhysicalMaterial,
  19321. MeshStandardMaterial: MeshStandardMaterial,
  19322. MeshPhongMaterial: MeshPhongMaterial,
  19323. MeshToonMaterial: MeshToonMaterial,
  19324. MeshNormalMaterial: MeshNormalMaterial,
  19325. MeshLambertMaterial: MeshLambertMaterial,
  19326. MeshDepthMaterial: MeshDepthMaterial,
  19327. MeshDistanceMaterial: MeshDistanceMaterial,
  19328. MeshBasicMaterial: MeshBasicMaterial,
  19329. MeshMatcapMaterial: MeshMatcapMaterial,
  19330. LineDashedMaterial: LineDashedMaterial,
  19331. LineBasicMaterial: LineBasicMaterial,
  19332. Material: Material
  19333. });
  19334. /**
  19335. * @author tschw
  19336. * @author Ben Houston / http://clara.io/
  19337. * @author David Sarno / http://lighthaus.us/
  19338. */
  19339. var AnimationUtils = {
  19340. // same as Array.prototype.slice, but also works on typed arrays
  19341. arraySlice: function ( array, from, to ) {
  19342. if ( AnimationUtils.isTypedArray( array ) ) {
  19343. // in ios9 array.subarray(from, undefined) will return empty array
  19344. // but array.subarray(from) or array.subarray(from, len) is correct
  19345. return new array.constructor( array.subarray( from, to !== undefined ? to : array.length ) );
  19346. }
  19347. return array.slice( from, to );
  19348. },
  19349. // converts an array to a specific type
  19350. convertArray: function ( array, type, forceClone ) {
  19351. if ( ! array || // let 'undefined' and 'null' pass
  19352. ! forceClone && array.constructor === type ) return array;
  19353. if ( typeof type.BYTES_PER_ELEMENT === 'number' ) {
  19354. return new type( array ); // create typed array
  19355. }
  19356. return Array.prototype.slice.call( array ); // create Array
  19357. },
  19358. isTypedArray: function ( object ) {
  19359. return ArrayBuffer.isView( object ) &&
  19360. ! ( object instanceof DataView );
  19361. },
  19362. // returns an array by which times and values can be sorted
  19363. getKeyframeOrder: function ( times ) {
  19364. function compareTime( i, j ) {
  19365. return times[ i ] - times[ j ];
  19366. }
  19367. var n = times.length;
  19368. var result = new Array( n );
  19369. for ( var i = 0; i !== n; ++ i ) result[ i ] = i;
  19370. result.sort( compareTime );
  19371. return result;
  19372. },
  19373. // uses the array previously returned by 'getKeyframeOrder' to sort data
  19374. sortedArray: function ( values, stride, order ) {
  19375. var nValues = values.length;
  19376. var result = new values.constructor( nValues );
  19377. for ( var i = 0, dstOffset = 0; dstOffset !== nValues; ++ i ) {
  19378. var srcOffset = order[ i ] * stride;
  19379. for ( var j = 0; j !== stride; ++ j ) {
  19380. result[ dstOffset ++ ] = values[ srcOffset + j ];
  19381. }
  19382. }
  19383. return result;
  19384. },
  19385. // function for parsing AOS keyframe formats
  19386. flattenJSON: function ( jsonKeys, times, values, valuePropertyName ) {
  19387. var i = 1, key = jsonKeys[ 0 ];
  19388. while ( key !== undefined && key[ valuePropertyName ] === undefined ) {
  19389. key = jsonKeys[ i ++ ];
  19390. }
  19391. if ( key === undefined ) return; // no data
  19392. var value = key[ valuePropertyName ];
  19393. if ( value === undefined ) return; // no data
  19394. if ( Array.isArray( value ) ) {
  19395. do {
  19396. value = key[ valuePropertyName ];
  19397. if ( value !== undefined ) {
  19398. times.push( key.time );
  19399. values.push.apply( values, value ); // push all elements
  19400. }
  19401. key = jsonKeys[ i ++ ];
  19402. } while ( key !== undefined );
  19403. } else if ( value.toArray !== undefined ) {
  19404. // ...assume THREE.Math-ish
  19405. do {
  19406. value = key[ valuePropertyName ];
  19407. if ( value !== undefined ) {
  19408. times.push( key.time );
  19409. value.toArray( values, values.length );
  19410. }
  19411. key = jsonKeys[ i ++ ];
  19412. } while ( key !== undefined );
  19413. } else {
  19414. // otherwise push as-is
  19415. do {
  19416. value = key[ valuePropertyName ];
  19417. if ( value !== undefined ) {
  19418. times.push( key.time );
  19419. values.push( value );
  19420. }
  19421. key = jsonKeys[ i ++ ];
  19422. } while ( key !== undefined );
  19423. }
  19424. }
  19425. };
  19426. /**
  19427. * Abstract base class of interpolants over parametric samples.
  19428. *
  19429. * The parameter domain is one dimensional, typically the time or a path
  19430. * along a curve defined by the data.
  19431. *
  19432. * The sample values can have any dimensionality and derived classes may
  19433. * apply special interpretations to the data.
  19434. *
  19435. * This class provides the interval seek in a Template Method, deferring
  19436. * the actual interpolation to derived classes.
  19437. *
  19438. * Time complexity is O(1) for linear access crossing at most two points
  19439. * and O(log N) for random access, where N is the number of positions.
  19440. *
  19441. * References:
  19442. *
  19443. * http://www.oodesign.com/template-method-pattern.html
  19444. *
  19445. * @author tschw
  19446. */
  19447. function Interpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  19448. this.parameterPositions = parameterPositions;
  19449. this._cachedIndex = 0;
  19450. this.resultBuffer = resultBuffer !== undefined ?
  19451. resultBuffer : new sampleValues.constructor( sampleSize );
  19452. this.sampleValues = sampleValues;
  19453. this.valueSize = sampleSize;
  19454. }
  19455. Object.assign( Interpolant.prototype, {
  19456. evaluate: function ( t ) {
  19457. var pp = this.parameterPositions,
  19458. i1 = this._cachedIndex,
  19459. t1 = pp[ i1 ],
  19460. t0 = pp[ i1 - 1 ];
  19461. validate_interval: {
  19462. seek: {
  19463. var right;
  19464. linear_scan: {
  19465. //- See http://jsperf.com/comparison-to-undefined/3
  19466. //- slower code:
  19467. //-
  19468. //- if ( t >= t1 || t1 === undefined ) {
  19469. forward_scan: if ( ! ( t < t1 ) ) {
  19470. for ( var giveUpAt = i1 + 2; ; ) {
  19471. if ( t1 === undefined ) {
  19472. if ( t < t0 ) break forward_scan;
  19473. // after end
  19474. i1 = pp.length;
  19475. this._cachedIndex = i1;
  19476. return this.afterEnd_( i1 - 1, t, t0 );
  19477. }
  19478. if ( i1 === giveUpAt ) break; // this loop
  19479. t0 = t1;
  19480. t1 = pp[ ++ i1 ];
  19481. if ( t < t1 ) {
  19482. // we have arrived at the sought interval
  19483. break seek;
  19484. }
  19485. }
  19486. // prepare binary search on the right side of the index
  19487. right = pp.length;
  19488. break linear_scan;
  19489. }
  19490. //- slower code:
  19491. //- if ( t < t0 || t0 === undefined ) {
  19492. if ( ! ( t >= t0 ) ) {
  19493. // looping?
  19494. var t1global = pp[ 1 ];
  19495. if ( t < t1global ) {
  19496. i1 = 2; // + 1, using the scan for the details
  19497. t0 = t1global;
  19498. }
  19499. // linear reverse scan
  19500. for ( var giveUpAt = i1 - 2; ; ) {
  19501. if ( t0 === undefined ) {
  19502. // before start
  19503. this._cachedIndex = 0;
  19504. return this.beforeStart_( 0, t, t1 );
  19505. }
  19506. if ( i1 === giveUpAt ) break; // this loop
  19507. t1 = t0;
  19508. t0 = pp[ -- i1 - 1 ];
  19509. if ( t >= t0 ) {
  19510. // we have arrived at the sought interval
  19511. break seek;
  19512. }
  19513. }
  19514. // prepare binary search on the left side of the index
  19515. right = i1;
  19516. i1 = 0;
  19517. break linear_scan;
  19518. }
  19519. // the interval is valid
  19520. break validate_interval;
  19521. } // linear scan
  19522. // binary search
  19523. while ( i1 < right ) {
  19524. var mid = ( i1 + right ) >>> 1;
  19525. if ( t < pp[ mid ] ) {
  19526. right = mid;
  19527. } else {
  19528. i1 = mid + 1;
  19529. }
  19530. }
  19531. t1 = pp[ i1 ];
  19532. t0 = pp[ i1 - 1 ];
  19533. // check boundary cases, again
  19534. if ( t0 === undefined ) {
  19535. this._cachedIndex = 0;
  19536. return this.beforeStart_( 0, t, t1 );
  19537. }
  19538. if ( t1 === undefined ) {
  19539. i1 = pp.length;
  19540. this._cachedIndex = i1;
  19541. return this.afterEnd_( i1 - 1, t0, t );
  19542. }
  19543. } // seek
  19544. this._cachedIndex = i1;
  19545. this.intervalChanged_( i1, t0, t1 );
  19546. } // validate_interval
  19547. return this.interpolate_( i1, t0, t, t1 );
  19548. },
  19549. settings: null, // optional, subclass-specific settings structure
  19550. // Note: The indirection allows central control of many interpolants.
  19551. // --- Protected interface
  19552. DefaultSettings_: {},
  19553. getSettings_: function () {
  19554. return this.settings || this.DefaultSettings_;
  19555. },
  19556. copySampleValue_: function ( index ) {
  19557. // copies a sample value to the result buffer
  19558. var result = this.resultBuffer,
  19559. values = this.sampleValues,
  19560. stride = this.valueSize,
  19561. offset = index * stride;
  19562. for ( var i = 0; i !== stride; ++ i ) {
  19563. result[ i ] = values[ offset + i ];
  19564. }
  19565. return result;
  19566. },
  19567. // Template methods for derived classes:
  19568. interpolate_: function ( /* i1, t0, t, t1 */ ) {
  19569. throw new Error( 'call to abstract method' );
  19570. // implementations shall return this.resultBuffer
  19571. },
  19572. intervalChanged_: function ( /* i1, t0, t1 */ ) {
  19573. // empty
  19574. }
  19575. } );
  19576. //!\ DECLARE ALIAS AFTER assign prototype !
  19577. Object.assign( Interpolant.prototype, {
  19578. //( 0, t, t0 ), returns this.resultBuffer
  19579. beforeStart_: Interpolant.prototype.copySampleValue_,
  19580. //( N-1, tN-1, t ), returns this.resultBuffer
  19581. afterEnd_: Interpolant.prototype.copySampleValue_,
  19582. } );
  19583. /**
  19584. * Fast and simple cubic spline interpolant.
  19585. *
  19586. * It was derived from a Hermitian construction setting the first derivative
  19587. * at each sample position to the linear slope between neighboring positions
  19588. * over their parameter interval.
  19589. *
  19590. * @author tschw
  19591. */
  19592. function CubicInterpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  19593. Interpolant.call( this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  19594. this._weightPrev = - 0;
  19595. this._offsetPrev = - 0;
  19596. this._weightNext = - 0;
  19597. this._offsetNext = - 0;
  19598. }
  19599. CubicInterpolant.prototype = Object.assign( Object.create( Interpolant.prototype ), {
  19600. constructor: CubicInterpolant,
  19601. DefaultSettings_: {
  19602. endingStart: ZeroCurvatureEnding,
  19603. endingEnd: ZeroCurvatureEnding
  19604. },
  19605. intervalChanged_: function ( i1, t0, t1 ) {
  19606. var pp = this.parameterPositions,
  19607. iPrev = i1 - 2,
  19608. iNext = i1 + 1,
  19609. tPrev = pp[ iPrev ],
  19610. tNext = pp[ iNext ];
  19611. if ( tPrev === undefined ) {
  19612. switch ( this.getSettings_().endingStart ) {
  19613. case ZeroSlopeEnding:
  19614. // f'(t0) = 0
  19615. iPrev = i1;
  19616. tPrev = 2 * t0 - t1;
  19617. break;
  19618. case WrapAroundEnding:
  19619. // use the other end of the curve
  19620. iPrev = pp.length - 2;
  19621. tPrev = t0 + pp[ iPrev ] - pp[ iPrev + 1 ];
  19622. break;
  19623. default: // ZeroCurvatureEnding
  19624. // f''(t0) = 0 a.k.a. Natural Spline
  19625. iPrev = i1;
  19626. tPrev = t1;
  19627. }
  19628. }
  19629. if ( tNext === undefined ) {
  19630. switch ( this.getSettings_().endingEnd ) {
  19631. case ZeroSlopeEnding:
  19632. // f'(tN) = 0
  19633. iNext = i1;
  19634. tNext = 2 * t1 - t0;
  19635. break;
  19636. case WrapAroundEnding:
  19637. // use the other end of the curve
  19638. iNext = 1;
  19639. tNext = t1 + pp[ 1 ] - pp[ 0 ];
  19640. break;
  19641. default: // ZeroCurvatureEnding
  19642. // f''(tN) = 0, a.k.a. Natural Spline
  19643. iNext = i1 - 1;
  19644. tNext = t0;
  19645. }
  19646. }
  19647. var halfDt = ( t1 - t0 ) * 0.5,
  19648. stride = this.valueSize;
  19649. this._weightPrev = halfDt / ( t0 - tPrev );
  19650. this._weightNext = halfDt / ( tNext - t1 );
  19651. this._offsetPrev = iPrev * stride;
  19652. this._offsetNext = iNext * stride;
  19653. },
  19654. interpolate_: function ( i1, t0, t, t1 ) {
  19655. var result = this.resultBuffer,
  19656. values = this.sampleValues,
  19657. stride = this.valueSize,
  19658. o1 = i1 * stride, o0 = o1 - stride,
  19659. oP = this._offsetPrev, oN = this._offsetNext,
  19660. wP = this._weightPrev, wN = this._weightNext,
  19661. p = ( t - t0 ) / ( t1 - t0 ),
  19662. pp = p * p,
  19663. ppp = pp * p;
  19664. // evaluate polynomials
  19665. var sP = - wP * ppp + 2 * wP * pp - wP * p;
  19666. var s0 = ( 1 + wP ) * ppp + ( - 1.5 - 2 * wP ) * pp + ( - 0.5 + wP ) * p + 1;
  19667. var s1 = ( - 1 - wN ) * ppp + ( 1.5 + wN ) * pp + 0.5 * p;
  19668. var sN = wN * ppp - wN * pp;
  19669. // combine data linearly
  19670. for ( var i = 0; i !== stride; ++ i ) {
  19671. result[ i ] =
  19672. sP * values[ oP + i ] +
  19673. s0 * values[ o0 + i ] +
  19674. s1 * values[ o1 + i ] +
  19675. sN * values[ oN + i ];
  19676. }
  19677. return result;
  19678. }
  19679. } );
  19680. /**
  19681. * @author tschw
  19682. */
  19683. function LinearInterpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  19684. Interpolant.call( this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  19685. }
  19686. LinearInterpolant.prototype = Object.assign( Object.create( Interpolant.prototype ), {
  19687. constructor: LinearInterpolant,
  19688. interpolate_: function ( i1, t0, t, t1 ) {
  19689. var result = this.resultBuffer,
  19690. values = this.sampleValues,
  19691. stride = this.valueSize,
  19692. offset1 = i1 * stride,
  19693. offset0 = offset1 - stride,
  19694. weight1 = ( t - t0 ) / ( t1 - t0 ),
  19695. weight0 = 1 - weight1;
  19696. for ( var i = 0; i !== stride; ++ i ) {
  19697. result[ i ] =
  19698. values[ offset0 + i ] * weight0 +
  19699. values[ offset1 + i ] * weight1;
  19700. }
  19701. return result;
  19702. }
  19703. } );
  19704. /**
  19705. *
  19706. * Interpolant that evaluates to the sample value at the position preceeding
  19707. * the parameter.
  19708. *
  19709. * @author tschw
  19710. */
  19711. function DiscreteInterpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  19712. Interpolant.call( this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  19713. }
  19714. DiscreteInterpolant.prototype = Object.assign( Object.create( Interpolant.prototype ), {
  19715. constructor: DiscreteInterpolant,
  19716. interpolate_: function ( i1 /*, t0, t, t1 */ ) {
  19717. return this.copySampleValue_( i1 - 1 );
  19718. }
  19719. } );
  19720. /**
  19721. *
  19722. * A timed sequence of keyframes for a specific property.
  19723. *
  19724. *
  19725. * @author Ben Houston / http://clara.io/
  19726. * @author David Sarno / http://lighthaus.us/
  19727. * @author tschw
  19728. */
  19729. function KeyframeTrack( name, times, values, interpolation ) {
  19730. if ( name === undefined ) throw new Error( 'THREE.KeyframeTrack: track name is undefined' );
  19731. if ( times === undefined || times.length === 0 ) throw new Error( 'THREE.KeyframeTrack: no keyframes in track named ' + name );
  19732. this.name = name;
  19733. this.times = AnimationUtils.convertArray( times, this.TimeBufferType );
  19734. this.values = AnimationUtils.convertArray( values, this.ValueBufferType );
  19735. this.setInterpolation( interpolation || this.DefaultInterpolation );
  19736. }
  19737. // Static methods
  19738. Object.assign( KeyframeTrack, {
  19739. // Serialization (in static context, because of constructor invocation
  19740. // and automatic invocation of .toJSON):
  19741. toJSON: function ( track ) {
  19742. var trackType = track.constructor;
  19743. var json;
  19744. // derived classes can define a static toJSON method
  19745. if ( trackType.toJSON !== undefined ) {
  19746. json = trackType.toJSON( track );
  19747. } else {
  19748. // by default, we assume the data can be serialized as-is
  19749. json = {
  19750. 'name': track.name,
  19751. 'times': AnimationUtils.convertArray( track.times, Array ),
  19752. 'values': AnimationUtils.convertArray( track.values, Array )
  19753. };
  19754. var interpolation = track.getInterpolation();
  19755. if ( interpolation !== track.DefaultInterpolation ) {
  19756. json.interpolation = interpolation;
  19757. }
  19758. }
  19759. json.type = track.ValueTypeName; // mandatory
  19760. return json;
  19761. }
  19762. } );
  19763. Object.assign( KeyframeTrack.prototype, {
  19764. constructor: KeyframeTrack,
  19765. TimeBufferType: Float32Array,
  19766. ValueBufferType: Float32Array,
  19767. DefaultInterpolation: InterpolateLinear,
  19768. InterpolantFactoryMethodDiscrete: function ( result ) {
  19769. return new DiscreteInterpolant( this.times, this.values, this.getValueSize(), result );
  19770. },
  19771. InterpolantFactoryMethodLinear: function ( result ) {
  19772. return new LinearInterpolant( this.times, this.values, this.getValueSize(), result );
  19773. },
  19774. InterpolantFactoryMethodSmooth: function ( result ) {
  19775. return new CubicInterpolant( this.times, this.values, this.getValueSize(), result );
  19776. },
  19777. setInterpolation: function ( interpolation ) {
  19778. var factoryMethod;
  19779. switch ( interpolation ) {
  19780. case InterpolateDiscrete:
  19781. factoryMethod = this.InterpolantFactoryMethodDiscrete;
  19782. break;
  19783. case InterpolateLinear:
  19784. factoryMethod = this.InterpolantFactoryMethodLinear;
  19785. break;
  19786. case InterpolateSmooth:
  19787. factoryMethod = this.InterpolantFactoryMethodSmooth;
  19788. break;
  19789. }
  19790. if ( factoryMethod === undefined ) {
  19791. var message = "unsupported interpolation for " +
  19792. this.ValueTypeName + " keyframe track named " + this.name;
  19793. if ( this.createInterpolant === undefined ) {
  19794. // fall back to default, unless the default itself is messed up
  19795. if ( interpolation !== this.DefaultInterpolation ) {
  19796. this.setInterpolation( this.DefaultInterpolation );
  19797. } else {
  19798. throw new Error( message ); // fatal, in this case
  19799. }
  19800. }
  19801. console.warn( 'THREE.KeyframeTrack:', message );
  19802. return this;
  19803. }
  19804. this.createInterpolant = factoryMethod;
  19805. return this;
  19806. },
  19807. getInterpolation: function () {
  19808. switch ( this.createInterpolant ) {
  19809. case this.InterpolantFactoryMethodDiscrete:
  19810. return InterpolateDiscrete;
  19811. case this.InterpolantFactoryMethodLinear:
  19812. return InterpolateLinear;
  19813. case this.InterpolantFactoryMethodSmooth:
  19814. return InterpolateSmooth;
  19815. }
  19816. },
  19817. getValueSize: function () {
  19818. return this.values.length / this.times.length;
  19819. },
  19820. // move all keyframes either forwards or backwards in time
  19821. shift: function ( timeOffset ) {
  19822. if ( timeOffset !== 0.0 ) {
  19823. var times = this.times;
  19824. for ( var i = 0, n = times.length; i !== n; ++ i ) {
  19825. times[ i ] += timeOffset;
  19826. }
  19827. }
  19828. return this;
  19829. },
  19830. // scale all keyframe times by a factor (useful for frame <-> seconds conversions)
  19831. scale: function ( timeScale ) {
  19832. if ( timeScale !== 1.0 ) {
  19833. var times = this.times;
  19834. for ( var i = 0, n = times.length; i !== n; ++ i ) {
  19835. times[ i ] *= timeScale;
  19836. }
  19837. }
  19838. return this;
  19839. },
  19840. // removes keyframes before and after animation without changing any values within the range [startTime, endTime].
  19841. // IMPORTANT: We do not shift around keys to the start of the track time, because for interpolated keys this will change their values
  19842. trim: function ( startTime, endTime ) {
  19843. var times = this.times,
  19844. nKeys = times.length,
  19845. from = 0,
  19846. to = nKeys - 1;
  19847. while ( from !== nKeys && times[ from ] < startTime ) {
  19848. ++ from;
  19849. }
  19850. while ( to !== - 1 && times[ to ] > endTime ) {
  19851. -- to;
  19852. }
  19853. ++ to; // inclusive -> exclusive bound
  19854. if ( from !== 0 || to !== nKeys ) {
  19855. // empty tracks are forbidden, so keep at least one keyframe
  19856. if ( from >= to ) to = Math.max( to, 1 ), from = to - 1;
  19857. var stride = this.getValueSize();
  19858. this.times = AnimationUtils.arraySlice( times, from, to );
  19859. this.values = AnimationUtils.arraySlice( this.values, from * stride, to * stride );
  19860. }
  19861. return this;
  19862. },
  19863. // ensure we do not get a GarbageInGarbageOut situation, make sure tracks are at least minimally viable
  19864. validate: function () {
  19865. var valid = true;
  19866. var valueSize = this.getValueSize();
  19867. if ( valueSize - Math.floor( valueSize ) !== 0 ) {
  19868. console.error( 'THREE.KeyframeTrack: Invalid value size in track.', this );
  19869. valid = false;
  19870. }
  19871. var times = this.times,
  19872. values = this.values,
  19873. nKeys = times.length;
  19874. if ( nKeys === 0 ) {
  19875. console.error( 'THREE.KeyframeTrack: Track is empty.', this );
  19876. valid = false;
  19877. }
  19878. var prevTime = null;
  19879. for ( var i = 0; i !== nKeys; i ++ ) {
  19880. var currTime = times[ i ];
  19881. if ( typeof currTime === 'number' && isNaN( currTime ) ) {
  19882. console.error( 'THREE.KeyframeTrack: Time is not a valid number.', this, i, currTime );
  19883. valid = false;
  19884. break;
  19885. }
  19886. if ( prevTime !== null && prevTime > currTime ) {
  19887. console.error( 'THREE.KeyframeTrack: Out of order keys.', this, i, currTime, prevTime );
  19888. valid = false;
  19889. break;
  19890. }
  19891. prevTime = currTime;
  19892. }
  19893. if ( values !== undefined ) {
  19894. if ( AnimationUtils.isTypedArray( values ) ) {
  19895. for ( var i = 0, n = values.length; i !== n; ++ i ) {
  19896. var value = values[ i ];
  19897. if ( isNaN( value ) ) {
  19898. console.error( 'THREE.KeyframeTrack: Value is not a valid number.', this, i, value );
  19899. valid = false;
  19900. break;
  19901. }
  19902. }
  19903. }
  19904. }
  19905. return valid;
  19906. },
  19907. // removes equivalent sequential keys as common in morph target sequences
  19908. // (0,0,0,0,1,1,1,0,0,0,0,0,0,0) --> (0,0,1,1,0,0)
  19909. optimize: function () {
  19910. var times = this.times,
  19911. values = this.values,
  19912. stride = this.getValueSize(),
  19913. smoothInterpolation = this.getInterpolation() === InterpolateSmooth,
  19914. writeIndex = 1,
  19915. lastIndex = times.length - 1;
  19916. for ( var i = 1; i < lastIndex; ++ i ) {
  19917. var keep = false;
  19918. var time = times[ i ];
  19919. var timeNext = times[ i + 1 ];
  19920. // remove adjacent keyframes scheduled at the same time
  19921. if ( time !== timeNext && ( i !== 1 || time !== time[ 0 ] ) ) {
  19922. if ( ! smoothInterpolation ) {
  19923. // remove unnecessary keyframes same as their neighbors
  19924. var offset = i * stride,
  19925. offsetP = offset - stride,
  19926. offsetN = offset + stride;
  19927. for ( var j = 0; j !== stride; ++ j ) {
  19928. var value = values[ offset + j ];
  19929. if ( value !== values[ offsetP + j ] ||
  19930. value !== values[ offsetN + j ] ) {
  19931. keep = true;
  19932. break;
  19933. }
  19934. }
  19935. } else {
  19936. keep = true;
  19937. }
  19938. }
  19939. // in-place compaction
  19940. if ( keep ) {
  19941. if ( i !== writeIndex ) {
  19942. times[ writeIndex ] = times[ i ];
  19943. var readOffset = i * stride,
  19944. writeOffset = writeIndex * stride;
  19945. for ( var j = 0; j !== stride; ++ j ) {
  19946. values[ writeOffset + j ] = values[ readOffset + j ];
  19947. }
  19948. }
  19949. ++ writeIndex;
  19950. }
  19951. }
  19952. // flush last keyframe (compaction looks ahead)
  19953. if ( lastIndex > 0 ) {
  19954. times[ writeIndex ] = times[ lastIndex ];
  19955. for ( var readOffset = lastIndex * stride, writeOffset = writeIndex * stride, j = 0; j !== stride; ++ j ) {
  19956. values[ writeOffset + j ] = values[ readOffset + j ];
  19957. }
  19958. ++ writeIndex;
  19959. }
  19960. if ( writeIndex !== times.length ) {
  19961. this.times = AnimationUtils.arraySlice( times, 0, writeIndex );
  19962. this.values = AnimationUtils.arraySlice( values, 0, writeIndex * stride );
  19963. }
  19964. return this;
  19965. },
  19966. clone: function () {
  19967. var times = AnimationUtils.arraySlice( this.times, 0 );
  19968. var values = AnimationUtils.arraySlice( this.values, 0 );
  19969. var TypedKeyframeTrack = this.constructor;
  19970. var track = new TypedKeyframeTrack( this.name, times, values );
  19971. // Interpolant argument to constructor is not saved, so copy the factory method directly.
  19972. track.createInterpolant = this.createInterpolant;
  19973. return track;
  19974. }
  19975. } );
  19976. /**
  19977. *
  19978. * A Track of Boolean keyframe values.
  19979. *
  19980. *
  19981. * @author Ben Houston / http://clara.io/
  19982. * @author David Sarno / http://lighthaus.us/
  19983. * @author tschw
  19984. */
  19985. function BooleanKeyframeTrack( name, times, values ) {
  19986. KeyframeTrack.call( this, name, times, values );
  19987. }
  19988. BooleanKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), {
  19989. constructor: BooleanKeyframeTrack,
  19990. ValueTypeName: 'bool',
  19991. ValueBufferType: Array,
  19992. DefaultInterpolation: InterpolateDiscrete,
  19993. InterpolantFactoryMethodLinear: undefined,
  19994. InterpolantFactoryMethodSmooth: undefined
  19995. // Note: Actually this track could have a optimized / compressed
  19996. // representation of a single value and a custom interpolant that
  19997. // computes "firstValue ^ isOdd( index )".
  19998. } );
  19999. /**
  20000. *
  20001. * A Track of keyframe values that represent color.
  20002. *
  20003. *
  20004. * @author Ben Houston / http://clara.io/
  20005. * @author David Sarno / http://lighthaus.us/
  20006. * @author tschw
  20007. */
  20008. function ColorKeyframeTrack( name, times, values, interpolation ) {
  20009. KeyframeTrack.call( this, name, times, values, interpolation );
  20010. }
  20011. ColorKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), {
  20012. constructor: ColorKeyframeTrack,
  20013. ValueTypeName: 'color'
  20014. // ValueBufferType is inherited
  20015. // DefaultInterpolation is inherited
  20016. // Note: Very basic implementation and nothing special yet.
  20017. // However, this is the place for color space parameterization.
  20018. } );
  20019. /**
  20020. *
  20021. * A Track of numeric keyframe values.
  20022. *
  20023. * @author Ben Houston / http://clara.io/
  20024. * @author David Sarno / http://lighthaus.us/
  20025. * @author tschw
  20026. */
  20027. function NumberKeyframeTrack( name, times, values, interpolation ) {
  20028. KeyframeTrack.call( this, name, times, values, interpolation );
  20029. }
  20030. NumberKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), {
  20031. constructor: NumberKeyframeTrack,
  20032. ValueTypeName: 'number'
  20033. // ValueBufferType is inherited
  20034. // DefaultInterpolation is inherited
  20035. } );
  20036. /**
  20037. * Spherical linear unit quaternion interpolant.
  20038. *
  20039. * @author tschw
  20040. */
  20041. function QuaternionLinearInterpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  20042. Interpolant.call( this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  20043. }
  20044. QuaternionLinearInterpolant.prototype = Object.assign( Object.create( Interpolant.prototype ), {
  20045. constructor: QuaternionLinearInterpolant,
  20046. interpolate_: function ( i1, t0, t, t1 ) {
  20047. var result = this.resultBuffer,
  20048. values = this.sampleValues,
  20049. stride = this.valueSize,
  20050. offset = i1 * stride,
  20051. alpha = ( t - t0 ) / ( t1 - t0 );
  20052. for ( var end = offset + stride; offset !== end; offset += 4 ) {
  20053. Quaternion.slerpFlat( result, 0, values, offset - stride, values, offset, alpha );
  20054. }
  20055. return result;
  20056. }
  20057. } );
  20058. /**
  20059. *
  20060. * A Track of quaternion keyframe values.
  20061. *
  20062. * @author Ben Houston / http://clara.io/
  20063. * @author David Sarno / http://lighthaus.us/
  20064. * @author tschw
  20065. */
  20066. function QuaternionKeyframeTrack( name, times, values, interpolation ) {
  20067. KeyframeTrack.call( this, name, times, values, interpolation );
  20068. }
  20069. QuaternionKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), {
  20070. constructor: QuaternionKeyframeTrack,
  20071. ValueTypeName: 'quaternion',
  20072. // ValueBufferType is inherited
  20073. DefaultInterpolation: InterpolateLinear,
  20074. InterpolantFactoryMethodLinear: function ( result ) {
  20075. return new QuaternionLinearInterpolant( this.times, this.values, this.getValueSize(), result );
  20076. },
  20077. InterpolantFactoryMethodSmooth: undefined // not yet implemented
  20078. } );
  20079. /**
  20080. *
  20081. * A Track that interpolates Strings
  20082. *
  20083. *
  20084. * @author Ben Houston / http://clara.io/
  20085. * @author David Sarno / http://lighthaus.us/
  20086. * @author tschw
  20087. */
  20088. function StringKeyframeTrack( name, times, values, interpolation ) {
  20089. KeyframeTrack.call( this, name, times, values, interpolation );
  20090. }
  20091. StringKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), {
  20092. constructor: StringKeyframeTrack,
  20093. ValueTypeName: 'string',
  20094. ValueBufferType: Array,
  20095. DefaultInterpolation: InterpolateDiscrete,
  20096. InterpolantFactoryMethodLinear: undefined,
  20097. InterpolantFactoryMethodSmooth: undefined
  20098. } );
  20099. /**
  20100. *
  20101. * A Track of vectored keyframe values.
  20102. *
  20103. *
  20104. * @author Ben Houston / http://clara.io/
  20105. * @author David Sarno / http://lighthaus.us/
  20106. * @author tschw
  20107. */
  20108. function VectorKeyframeTrack( name, times, values, interpolation ) {
  20109. KeyframeTrack.call( this, name, times, values, interpolation );
  20110. }
  20111. VectorKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), {
  20112. constructor: VectorKeyframeTrack,
  20113. ValueTypeName: 'vector'
  20114. // ValueBufferType is inherited
  20115. // DefaultInterpolation is inherited
  20116. } );
  20117. /**
  20118. *
  20119. * Reusable set of Tracks that represent an animation.
  20120. *
  20121. * @author Ben Houston / http://clara.io/
  20122. * @author David Sarno / http://lighthaus.us/
  20123. */
  20124. function AnimationClip( name, duration, tracks ) {
  20125. this.name = name;
  20126. this.tracks = tracks;
  20127. this.duration = ( duration !== undefined ) ? duration : - 1;
  20128. this.uuid = _Math.generateUUID();
  20129. // this means it should figure out its duration by scanning the tracks
  20130. if ( this.duration < 0 ) {
  20131. this.resetDuration();
  20132. }
  20133. }
  20134. function getTrackTypeForValueTypeName( typeName ) {
  20135. switch ( typeName.toLowerCase() ) {
  20136. case 'scalar':
  20137. case 'double':
  20138. case 'float':
  20139. case 'number':
  20140. case 'integer':
  20141. return NumberKeyframeTrack;
  20142. case 'vector':
  20143. case 'vector2':
  20144. case 'vector3':
  20145. case 'vector4':
  20146. return VectorKeyframeTrack;
  20147. case 'color':
  20148. return ColorKeyframeTrack;
  20149. case 'quaternion':
  20150. return QuaternionKeyframeTrack;
  20151. case 'bool':
  20152. case 'boolean':
  20153. return BooleanKeyframeTrack;
  20154. case 'string':
  20155. return StringKeyframeTrack;
  20156. }
  20157. throw new Error( 'THREE.KeyframeTrack: Unsupported typeName: ' + typeName );
  20158. }
  20159. function parseKeyframeTrack( json ) {
  20160. if ( json.type === undefined ) {
  20161. throw new Error( 'THREE.KeyframeTrack: track type undefined, can not parse' );
  20162. }
  20163. var trackType = getTrackTypeForValueTypeName( json.type );
  20164. if ( json.times === undefined ) {
  20165. var times = [], values = [];
  20166. AnimationUtils.flattenJSON( json.keys, times, values, 'value' );
  20167. json.times = times;
  20168. json.values = values;
  20169. }
  20170. // derived classes can define a static parse method
  20171. if ( trackType.parse !== undefined ) {
  20172. return trackType.parse( json );
  20173. } else {
  20174. // by default, we assume a constructor compatible with the base
  20175. return new trackType( json.name, json.times, json.values, json.interpolation );
  20176. }
  20177. }
  20178. Object.assign( AnimationClip, {
  20179. parse: function ( json ) {
  20180. var tracks = [],
  20181. jsonTracks = json.tracks,
  20182. frameTime = 1.0 / ( json.fps || 1.0 );
  20183. for ( var i = 0, n = jsonTracks.length; i !== n; ++ i ) {
  20184. tracks.push( parseKeyframeTrack( jsonTracks[ i ] ).scale( frameTime ) );
  20185. }
  20186. return new AnimationClip( json.name, json.duration, tracks );
  20187. },
  20188. toJSON: function ( clip ) {
  20189. var tracks = [],
  20190. clipTracks = clip.tracks;
  20191. var json = {
  20192. 'name': clip.name,
  20193. 'duration': clip.duration,
  20194. 'tracks': tracks,
  20195. 'uuid': clip.uuid
  20196. };
  20197. for ( var i = 0, n = clipTracks.length; i !== n; ++ i ) {
  20198. tracks.push( KeyframeTrack.toJSON( clipTracks[ i ] ) );
  20199. }
  20200. return json;
  20201. },
  20202. CreateFromMorphTargetSequence: function ( name, morphTargetSequence, fps, noLoop ) {
  20203. var numMorphTargets = morphTargetSequence.length;
  20204. var tracks = [];
  20205. for ( var i = 0; i < numMorphTargets; i ++ ) {
  20206. var times = [];
  20207. var values = [];
  20208. times.push(
  20209. ( i + numMorphTargets - 1 ) % numMorphTargets,
  20210. i,
  20211. ( i + 1 ) % numMorphTargets );
  20212. values.push( 0, 1, 0 );
  20213. var order = AnimationUtils.getKeyframeOrder( times );
  20214. times = AnimationUtils.sortedArray( times, 1, order );
  20215. values = AnimationUtils.sortedArray( values, 1, order );
  20216. // if there is a key at the first frame, duplicate it as the
  20217. // last frame as well for perfect loop.
  20218. if ( ! noLoop && times[ 0 ] === 0 ) {
  20219. times.push( numMorphTargets );
  20220. values.push( values[ 0 ] );
  20221. }
  20222. tracks.push(
  20223. new NumberKeyframeTrack(
  20224. '.morphTargetInfluences[' + morphTargetSequence[ i ].name + ']',
  20225. times, values
  20226. ).scale( 1.0 / fps ) );
  20227. }
  20228. return new AnimationClip( name, - 1, tracks );
  20229. },
  20230. findByName: function ( objectOrClipArray, name ) {
  20231. var clipArray = objectOrClipArray;
  20232. if ( ! Array.isArray( objectOrClipArray ) ) {
  20233. var o = objectOrClipArray;
  20234. clipArray = o.geometry && o.geometry.animations || o.animations;
  20235. }
  20236. for ( var i = 0; i < clipArray.length; i ++ ) {
  20237. if ( clipArray[ i ].name === name ) {
  20238. return clipArray[ i ];
  20239. }
  20240. }
  20241. return null;
  20242. },
  20243. CreateClipsFromMorphTargetSequences: function ( morphTargets, fps, noLoop ) {
  20244. var animationToMorphTargets = {};
  20245. // tested with https://regex101.com/ on trick sequences
  20246. // such flamingo_flyA_003, flamingo_run1_003, crdeath0059
  20247. var pattern = /^([\w-]*?)([\d]+)$/;
  20248. // sort morph target names into animation groups based
  20249. // patterns like Walk_001, Walk_002, Run_001, Run_002
  20250. for ( var i = 0, il = morphTargets.length; i < il; i ++ ) {
  20251. var morphTarget = morphTargets[ i ];
  20252. var parts = morphTarget.name.match( pattern );
  20253. if ( parts && parts.length > 1 ) {
  20254. var name = parts[ 1 ];
  20255. var animationMorphTargets = animationToMorphTargets[ name ];
  20256. if ( ! animationMorphTargets ) {
  20257. animationToMorphTargets[ name ] = animationMorphTargets = [];
  20258. }
  20259. animationMorphTargets.push( morphTarget );
  20260. }
  20261. }
  20262. var clips = [];
  20263. for ( var name in animationToMorphTargets ) {
  20264. clips.push( AnimationClip.CreateFromMorphTargetSequence( name, animationToMorphTargets[ name ], fps, noLoop ) );
  20265. }
  20266. return clips;
  20267. },
  20268. // parse the animation.hierarchy format
  20269. parseAnimation: function ( animation, bones ) {
  20270. if ( ! animation ) {
  20271. console.error( 'THREE.AnimationClip: No animation in JSONLoader data.' );
  20272. return null;
  20273. }
  20274. var addNonemptyTrack = function ( trackType, trackName, animationKeys, propertyName, destTracks ) {
  20275. // only return track if there are actually keys.
  20276. if ( animationKeys.length !== 0 ) {
  20277. var times = [];
  20278. var values = [];
  20279. AnimationUtils.flattenJSON( animationKeys, times, values, propertyName );
  20280. // empty keys are filtered out, so check again
  20281. if ( times.length !== 0 ) {
  20282. destTracks.push( new trackType( trackName, times, values ) );
  20283. }
  20284. }
  20285. };
  20286. var tracks = [];
  20287. var clipName = animation.name || 'default';
  20288. // automatic length determination in AnimationClip.
  20289. var duration = animation.length || - 1;
  20290. var fps = animation.fps || 30;
  20291. var hierarchyTracks = animation.hierarchy || [];
  20292. for ( var h = 0; h < hierarchyTracks.length; h ++ ) {
  20293. var animationKeys = hierarchyTracks[ h ].keys;
  20294. // skip empty tracks
  20295. if ( ! animationKeys || animationKeys.length === 0 ) continue;
  20296. // process morph targets
  20297. if ( animationKeys[ 0 ].morphTargets ) {
  20298. // figure out all morph targets used in this track
  20299. var morphTargetNames = {};
  20300. for ( var k = 0; k < animationKeys.length; k ++ ) {
  20301. if ( animationKeys[ k ].morphTargets ) {
  20302. for ( var m = 0; m < animationKeys[ k ].morphTargets.length; m ++ ) {
  20303. morphTargetNames[ animationKeys[ k ].morphTargets[ m ] ] = - 1;
  20304. }
  20305. }
  20306. }
  20307. // create a track for each morph target with all zero
  20308. // morphTargetInfluences except for the keys in which
  20309. // the morphTarget is named.
  20310. for ( var morphTargetName in morphTargetNames ) {
  20311. var times = [];
  20312. var values = [];
  20313. for ( var m = 0; m !== animationKeys[ k ].morphTargets.length; ++ m ) {
  20314. var animationKey = animationKeys[ k ];
  20315. times.push( animationKey.time );
  20316. values.push( ( animationKey.morphTarget === morphTargetName ) ? 1 : 0 );
  20317. }
  20318. tracks.push( new NumberKeyframeTrack( '.morphTargetInfluence[' + morphTargetName + ']', times, values ) );
  20319. }
  20320. duration = morphTargetNames.length * ( fps || 1.0 );
  20321. } else {
  20322. // ...assume skeletal animation
  20323. var boneName = '.bones[' + bones[ h ].name + ']';
  20324. addNonemptyTrack(
  20325. VectorKeyframeTrack, boneName + '.position',
  20326. animationKeys, 'pos', tracks );
  20327. addNonemptyTrack(
  20328. QuaternionKeyframeTrack, boneName + '.quaternion',
  20329. animationKeys, 'rot', tracks );
  20330. addNonemptyTrack(
  20331. VectorKeyframeTrack, boneName + '.scale',
  20332. animationKeys, 'scl', tracks );
  20333. }
  20334. }
  20335. if ( tracks.length === 0 ) {
  20336. return null;
  20337. }
  20338. var clip = new AnimationClip( clipName, duration, tracks );
  20339. return clip;
  20340. }
  20341. } );
  20342. Object.assign( AnimationClip.prototype, {
  20343. resetDuration: function () {
  20344. var tracks = this.tracks, duration = 0;
  20345. for ( var i = 0, n = tracks.length; i !== n; ++ i ) {
  20346. var track = this.tracks[ i ];
  20347. duration = Math.max( duration, track.times[ track.times.length - 1 ] );
  20348. }
  20349. this.duration = duration;
  20350. return this;
  20351. },
  20352. trim: function () {
  20353. for ( var i = 0; i < this.tracks.length; i ++ ) {
  20354. this.tracks[ i ].trim( 0, this.duration );
  20355. }
  20356. return this;
  20357. },
  20358. validate: function () {
  20359. var valid = true;
  20360. for ( var i = 0; i < this.tracks.length; i ++ ) {
  20361. valid = valid && this.tracks[ i ].validate();
  20362. }
  20363. return valid;
  20364. },
  20365. optimize: function () {
  20366. for ( var i = 0; i < this.tracks.length; i ++ ) {
  20367. this.tracks[ i ].optimize();
  20368. }
  20369. return this;
  20370. },
  20371. clone: function () {
  20372. var tracks = [];
  20373. for ( var i = 0; i < this.tracks.length; i ++ ) {
  20374. tracks.push( this.tracks[ i ].clone() );
  20375. }
  20376. return new AnimationClip( this.name, this.duration, tracks );
  20377. }
  20378. } );
  20379. /**
  20380. * @author mrdoob / http://mrdoob.com/
  20381. */
  20382. var Cache = {
  20383. enabled: false,
  20384. files: {},
  20385. add: function ( key, file ) {
  20386. if ( this.enabled === false ) return;
  20387. // console.log( 'THREE.Cache', 'Adding key:', key );
  20388. this.files[ key ] = file;
  20389. },
  20390. get: function ( key ) {
  20391. if ( this.enabled === false ) return;
  20392. // console.log( 'THREE.Cache', 'Checking key:', key );
  20393. return this.files[ key ];
  20394. },
  20395. remove: function ( key ) {
  20396. delete this.files[ key ];
  20397. },
  20398. clear: function () {
  20399. this.files = {};
  20400. }
  20401. };
  20402. /**
  20403. * @author mrdoob / http://mrdoob.com/
  20404. */
  20405. function LoadingManager( onLoad, onProgress, onError ) {
  20406. var scope = this;
  20407. var isLoading = false;
  20408. var itemsLoaded = 0;
  20409. var itemsTotal = 0;
  20410. var urlModifier = undefined;
  20411. // Refer to #5689 for the reason why we don't set .onStart
  20412. // in the constructor
  20413. this.onStart = undefined;
  20414. this.onLoad = onLoad;
  20415. this.onProgress = onProgress;
  20416. this.onError = onError;
  20417. this.itemStart = function ( url ) {
  20418. itemsTotal ++;
  20419. if ( isLoading === false ) {
  20420. if ( scope.onStart !== undefined ) {
  20421. scope.onStart( url, itemsLoaded, itemsTotal );
  20422. }
  20423. }
  20424. isLoading = true;
  20425. };
  20426. this.itemEnd = function ( url ) {
  20427. itemsLoaded ++;
  20428. if ( scope.onProgress !== undefined ) {
  20429. scope.onProgress( url, itemsLoaded, itemsTotal );
  20430. }
  20431. if ( itemsLoaded === itemsTotal ) {
  20432. isLoading = false;
  20433. if ( scope.onLoad !== undefined ) {
  20434. scope.onLoad();
  20435. }
  20436. }
  20437. };
  20438. this.itemError = function ( url ) {
  20439. if ( scope.onError !== undefined ) {
  20440. scope.onError( url );
  20441. }
  20442. };
  20443. this.resolveURL = function ( url ) {
  20444. if ( urlModifier ) {
  20445. return urlModifier( url );
  20446. }
  20447. return url;
  20448. };
  20449. this.setURLModifier = function ( transform ) {
  20450. urlModifier = transform;
  20451. return this;
  20452. };
  20453. }
  20454. var DefaultLoadingManager = new LoadingManager();
  20455. /**
  20456. * @author mrdoob / http://mrdoob.com/
  20457. */
  20458. var loading = {};
  20459. function FileLoader( manager ) {
  20460. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  20461. }
  20462. Object.assign( FileLoader.prototype, {
  20463. load: function ( url, onLoad, onProgress, onError ) {
  20464. if ( url === undefined ) url = '';
  20465. if ( this.path !== undefined ) url = this.path + url;
  20466. url = this.manager.resolveURL( url );
  20467. var scope = this;
  20468. var cached = Cache.get( url );
  20469. if ( cached !== undefined ) {
  20470. scope.manager.itemStart( url );
  20471. setTimeout( function () {
  20472. if ( onLoad ) onLoad( cached );
  20473. scope.manager.itemEnd( url );
  20474. }, 0 );
  20475. return cached;
  20476. }
  20477. // Check if request is duplicate
  20478. if ( loading[ url ] !== undefined ) {
  20479. loading[ url ].push( {
  20480. onLoad: onLoad,
  20481. onProgress: onProgress,
  20482. onError: onError
  20483. } );
  20484. return;
  20485. }
  20486. // Check for data: URI
  20487. var dataUriRegex = /^data:(.*?)(;base64)?,(.*)$/;
  20488. var dataUriRegexResult = url.match( dataUriRegex );
  20489. // Safari can not handle Data URIs through XMLHttpRequest so process manually
  20490. if ( dataUriRegexResult ) {
  20491. var mimeType = dataUriRegexResult[ 1 ];
  20492. var isBase64 = !! dataUriRegexResult[ 2 ];
  20493. var data = dataUriRegexResult[ 3 ];
  20494. data = decodeURIComponent( data );
  20495. if ( isBase64 ) data = atob( data );
  20496. try {
  20497. var response;
  20498. var responseType = ( this.responseType || '' ).toLowerCase();
  20499. switch ( responseType ) {
  20500. case 'arraybuffer':
  20501. case 'blob':
  20502. var view = new Uint8Array( data.length );
  20503. for ( var i = 0; i < data.length; i ++ ) {
  20504. view[ i ] = data.charCodeAt( i );
  20505. }
  20506. if ( responseType === 'blob' ) {
  20507. response = new Blob( [ view.buffer ], { type: mimeType } );
  20508. } else {
  20509. response = view.buffer;
  20510. }
  20511. break;
  20512. case 'document':
  20513. var parser = new DOMParser();
  20514. response = parser.parseFromString( data, mimeType );
  20515. break;
  20516. case 'json':
  20517. response = JSON.parse( data );
  20518. break;
  20519. default: // 'text' or other
  20520. response = data;
  20521. break;
  20522. }
  20523. // Wait for next browser tick like standard XMLHttpRequest event dispatching does
  20524. setTimeout( function () {
  20525. if ( onLoad ) onLoad( response );
  20526. scope.manager.itemEnd( url );
  20527. }, 0 );
  20528. } catch ( error ) {
  20529. // Wait for next browser tick like standard XMLHttpRequest event dispatching does
  20530. setTimeout( function () {
  20531. if ( onError ) onError( error );
  20532. scope.manager.itemError( url );
  20533. scope.manager.itemEnd( url );
  20534. }, 0 );
  20535. }
  20536. } else {
  20537. // Initialise array for duplicate requests
  20538. loading[ url ] = [];
  20539. loading[ url ].push( {
  20540. onLoad: onLoad,
  20541. onProgress: onProgress,
  20542. onError: onError
  20543. } );
  20544. var request = new XMLHttpRequest();
  20545. request.open( 'GET', url, true );
  20546. request.addEventListener( 'load', function ( event ) {
  20547. var response = this.response;
  20548. Cache.add( url, response );
  20549. var callbacks = loading[ url ];
  20550. delete loading[ url ];
  20551. if ( this.status === 200 || this.status === 0 ) {
  20552. // Some browsers return HTTP Status 0 when using non-http protocol
  20553. // e.g. 'file://' or 'data://'. Handle as success.
  20554. if ( this.status === 0 ) console.warn( 'THREE.FileLoader: HTTP Status 0 received.' );
  20555. for ( var i = 0, il = callbacks.length; i < il; i ++ ) {
  20556. var callback = callbacks[ i ];
  20557. if ( callback.onLoad ) callback.onLoad( response );
  20558. }
  20559. scope.manager.itemEnd( url );
  20560. } else {
  20561. for ( var i = 0, il = callbacks.length; i < il; i ++ ) {
  20562. var callback = callbacks[ i ];
  20563. if ( callback.onError ) callback.onError( event );
  20564. }
  20565. scope.manager.itemError( url );
  20566. scope.manager.itemEnd( url );
  20567. }
  20568. }, false );
  20569. request.addEventListener( 'progress', function ( event ) {
  20570. var callbacks = loading[ url ];
  20571. for ( var i = 0, il = callbacks.length; i < il; i ++ ) {
  20572. var callback = callbacks[ i ];
  20573. if ( callback.onProgress ) callback.onProgress( event );
  20574. }
  20575. }, false );
  20576. request.addEventListener( 'error', function ( event ) {
  20577. var callbacks = loading[ url ];
  20578. delete loading[ url ];
  20579. for ( var i = 0, il = callbacks.length; i < il; i ++ ) {
  20580. var callback = callbacks[ i ];
  20581. if ( callback.onError ) callback.onError( event );
  20582. }
  20583. scope.manager.itemError( url );
  20584. scope.manager.itemEnd( url );
  20585. }, false );
  20586. request.addEventListener( 'abort', function ( event ) {
  20587. var callbacks = loading[ url ];
  20588. delete loading[ url ];
  20589. for ( var i = 0, il = callbacks.length; i < il; i ++ ) {
  20590. var callback = callbacks[ i ];
  20591. if ( callback.onError ) callback.onError( event );
  20592. }
  20593. scope.manager.itemError( url );
  20594. scope.manager.itemEnd( url );
  20595. }, false );
  20596. if ( this.responseType !== undefined ) request.responseType = this.responseType;
  20597. if ( this.withCredentials !== undefined ) request.withCredentials = this.withCredentials;
  20598. if ( request.overrideMimeType ) request.overrideMimeType( this.mimeType !== undefined ? this.mimeType : 'text/plain' );
  20599. for ( var header in this.requestHeader ) {
  20600. request.setRequestHeader( header, this.requestHeader[ header ] );
  20601. }
  20602. request.send( null );
  20603. }
  20604. scope.manager.itemStart( url );
  20605. return request;
  20606. },
  20607. setPath: function ( value ) {
  20608. this.path = value;
  20609. return this;
  20610. },
  20611. setResponseType: function ( value ) {
  20612. this.responseType = value;
  20613. return this;
  20614. },
  20615. setWithCredentials: function ( value ) {
  20616. this.withCredentials = value;
  20617. return this;
  20618. },
  20619. setMimeType: function ( value ) {
  20620. this.mimeType = value;
  20621. return this;
  20622. },
  20623. setRequestHeader: function ( value ) {
  20624. this.requestHeader = value;
  20625. return this;
  20626. }
  20627. } );
  20628. /**
  20629. * @author bhouston / http://clara.io/
  20630. */
  20631. function AnimationLoader( manager ) {
  20632. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  20633. }
  20634. Object.assign( AnimationLoader.prototype, {
  20635. load: function ( url, onLoad, onProgress, onError ) {
  20636. var scope = this;
  20637. var loader = new FileLoader( scope.manager );
  20638. loader.setPath( scope.path );
  20639. loader.load( url, function ( text ) {
  20640. onLoad( scope.parse( JSON.parse( text ) ) );
  20641. }, onProgress, onError );
  20642. },
  20643. parse: function ( json, onLoad ) {
  20644. var animations = [];
  20645. for ( var i = 0; i < json.length; i ++ ) {
  20646. var clip = AnimationClip.parse( json[ i ] );
  20647. animations.push( clip );
  20648. }
  20649. onLoad( animations );
  20650. },
  20651. setPath: function ( value ) {
  20652. this.path = value;
  20653. return this;
  20654. }
  20655. } );
  20656. /**
  20657. * @author mrdoob / http://mrdoob.com/
  20658. *
  20659. * Abstract Base class to block based textures loader (dds, pvr, ...)
  20660. */
  20661. function CompressedTextureLoader( manager ) {
  20662. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  20663. // override in sub classes
  20664. this._parser = null;
  20665. }
  20666. Object.assign( CompressedTextureLoader.prototype, {
  20667. load: function ( url, onLoad, onProgress, onError ) {
  20668. var scope = this;
  20669. var images = [];
  20670. var texture = new CompressedTexture();
  20671. texture.image = images;
  20672. var loader = new FileLoader( this.manager );
  20673. loader.setPath( this.path );
  20674. loader.setResponseType( 'arraybuffer' );
  20675. function loadTexture( i ) {
  20676. loader.load( url[ i ], function ( buffer ) {
  20677. var texDatas = scope._parser( buffer, true );
  20678. images[ i ] = {
  20679. width: texDatas.width,
  20680. height: texDatas.height,
  20681. format: texDatas.format,
  20682. mipmaps: texDatas.mipmaps
  20683. };
  20684. loaded += 1;
  20685. if ( loaded === 6 ) {
  20686. if ( texDatas.mipmapCount === 1 )
  20687. texture.minFilter = LinearFilter;
  20688. texture.format = texDatas.format;
  20689. texture.needsUpdate = true;
  20690. if ( onLoad ) onLoad( texture );
  20691. }
  20692. }, onProgress, onError );
  20693. }
  20694. if ( Array.isArray( url ) ) {
  20695. var loaded = 0;
  20696. for ( var i = 0, il = url.length; i < il; ++ i ) {
  20697. loadTexture( i );
  20698. }
  20699. } else {
  20700. // compressed cubemap texture stored in a single DDS file
  20701. loader.load( url, function ( buffer ) {
  20702. var texDatas = scope._parser( buffer, true );
  20703. if ( texDatas.isCubemap ) {
  20704. var faces = texDatas.mipmaps.length / texDatas.mipmapCount;
  20705. for ( var f = 0; f < faces; f ++ ) {
  20706. images[ f ] = { mipmaps: [] };
  20707. for ( var i = 0; i < texDatas.mipmapCount; i ++ ) {
  20708. images[ f ].mipmaps.push( texDatas.mipmaps[ f * texDatas.mipmapCount + i ] );
  20709. images[ f ].format = texDatas.format;
  20710. images[ f ].width = texDatas.width;
  20711. images[ f ].height = texDatas.height;
  20712. }
  20713. }
  20714. } else {
  20715. texture.image.width = texDatas.width;
  20716. texture.image.height = texDatas.height;
  20717. texture.mipmaps = texDatas.mipmaps;
  20718. }
  20719. if ( texDatas.mipmapCount === 1 ) {
  20720. texture.minFilter = LinearFilter;
  20721. }
  20722. texture.format = texDatas.format;
  20723. texture.needsUpdate = true;
  20724. if ( onLoad ) onLoad( texture );
  20725. }, onProgress, onError );
  20726. }
  20727. return texture;
  20728. },
  20729. setPath: function ( value ) {
  20730. this.path = value;
  20731. return this;
  20732. }
  20733. } );
  20734. /**
  20735. * @author Nikos M. / https://github.com/foo123/
  20736. *
  20737. * Abstract Base class to load generic binary textures formats (rgbe, hdr, ...)
  20738. */
  20739. function DataTextureLoader( manager ) {
  20740. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  20741. // override in sub classes
  20742. this._parser = null;
  20743. }
  20744. Object.assign( DataTextureLoader.prototype, {
  20745. load: function ( url, onLoad, onProgress, onError ) {
  20746. var scope = this;
  20747. var texture = new DataTexture();
  20748. var loader = new FileLoader( this.manager );
  20749. loader.setResponseType( 'arraybuffer' );
  20750. loader.setPath( this.path );
  20751. loader.load( url, function ( buffer ) {
  20752. var texData = scope._parser( buffer );
  20753. if ( ! texData ) return;
  20754. if ( texData.image !== undefined ) {
  20755. texture.image = texData.image;
  20756. } else if ( texData.data !== undefined ) {
  20757. texture.image.width = texData.width;
  20758. texture.image.height = texData.height;
  20759. texture.image.data = texData.data;
  20760. }
  20761. texture.wrapS = texData.wrapS !== undefined ? texData.wrapS : ClampToEdgeWrapping;
  20762. texture.wrapT = texData.wrapT !== undefined ? texData.wrapT : ClampToEdgeWrapping;
  20763. texture.magFilter = texData.magFilter !== undefined ? texData.magFilter : LinearFilter;
  20764. texture.minFilter = texData.minFilter !== undefined ? texData.minFilter : LinearMipMapLinearFilter;
  20765. texture.anisotropy = texData.anisotropy !== undefined ? texData.anisotropy : 1;
  20766. if ( texData.format !== undefined ) {
  20767. texture.format = texData.format;
  20768. }
  20769. if ( texData.type !== undefined ) {
  20770. texture.type = texData.type;
  20771. }
  20772. if ( texData.mipmaps !== undefined ) {
  20773. texture.mipmaps = texData.mipmaps;
  20774. }
  20775. if ( texData.mipmapCount === 1 ) {
  20776. texture.minFilter = LinearFilter;
  20777. }
  20778. texture.needsUpdate = true;
  20779. if ( onLoad ) onLoad( texture, texData );
  20780. }, onProgress, onError );
  20781. return texture;
  20782. },
  20783. setPath: function ( value ) {
  20784. this.path = value;
  20785. return this;
  20786. }
  20787. } );
  20788. /**
  20789. * @author mrdoob / http://mrdoob.com/
  20790. */
  20791. function ImageLoader( manager ) {
  20792. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  20793. }
  20794. Object.assign( ImageLoader.prototype, {
  20795. crossOrigin: 'anonymous',
  20796. load: function ( url, onLoad, onProgress, onError ) {
  20797. if ( url === undefined ) url = '';
  20798. if ( this.path !== undefined ) url = this.path + url;
  20799. url = this.manager.resolveURL( url );
  20800. var scope = this;
  20801. var cached = Cache.get( url );
  20802. if ( cached !== undefined ) {
  20803. scope.manager.itemStart( url );
  20804. setTimeout( function () {
  20805. if ( onLoad ) onLoad( cached );
  20806. scope.manager.itemEnd( url );
  20807. }, 0 );
  20808. return cached;
  20809. }
  20810. var image = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'img' );
  20811. function onImageLoad() {
  20812. image.removeEventListener( 'load', onImageLoad, false );
  20813. image.removeEventListener( 'error', onImageError, false );
  20814. Cache.add( url, this );
  20815. if ( onLoad ) onLoad( this );
  20816. scope.manager.itemEnd( url );
  20817. }
  20818. function onImageError( event ) {
  20819. image.removeEventListener( 'load', onImageLoad, false );
  20820. image.removeEventListener( 'error', onImageError, false );
  20821. if ( onError ) onError( event );
  20822. scope.manager.itemError( url );
  20823. scope.manager.itemEnd( url );
  20824. }
  20825. image.addEventListener( 'load', onImageLoad, false );
  20826. image.addEventListener( 'error', onImageError, false );
  20827. if ( url.substr( 0, 5 ) !== 'data:' ) {
  20828. if ( this.crossOrigin !== undefined ) image.crossOrigin = this.crossOrigin;
  20829. }
  20830. scope.manager.itemStart( url );
  20831. image.src = url;
  20832. return image;
  20833. },
  20834. setCrossOrigin: function ( value ) {
  20835. this.crossOrigin = value;
  20836. return this;
  20837. },
  20838. setPath: function ( value ) {
  20839. this.path = value;
  20840. return this;
  20841. }
  20842. } );
  20843. /**
  20844. * @author mrdoob / http://mrdoob.com/
  20845. */
  20846. function CubeTextureLoader( manager ) {
  20847. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  20848. }
  20849. Object.assign( CubeTextureLoader.prototype, {
  20850. crossOrigin: 'anonymous',
  20851. load: function ( urls, onLoad, onProgress, onError ) {
  20852. var texture = new CubeTexture();
  20853. var loader = new ImageLoader( this.manager );
  20854. loader.setCrossOrigin( this.crossOrigin );
  20855. loader.setPath( this.path );
  20856. var loaded = 0;
  20857. function loadTexture( i ) {
  20858. loader.load( urls[ i ], function ( image ) {
  20859. texture.images[ i ] = image;
  20860. loaded ++;
  20861. if ( loaded === 6 ) {
  20862. texture.needsUpdate = true;
  20863. if ( onLoad ) onLoad( texture );
  20864. }
  20865. }, undefined, onError );
  20866. }
  20867. for ( var i = 0; i < urls.length; ++ i ) {
  20868. loadTexture( i );
  20869. }
  20870. return texture;
  20871. },
  20872. setCrossOrigin: function ( value ) {
  20873. this.crossOrigin = value;
  20874. return this;
  20875. },
  20876. setPath: function ( value ) {
  20877. this.path = value;
  20878. return this;
  20879. }
  20880. } );
  20881. /**
  20882. * @author mrdoob / http://mrdoob.com/
  20883. */
  20884. function TextureLoader( manager ) {
  20885. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  20886. }
  20887. Object.assign( TextureLoader.prototype, {
  20888. crossOrigin: 'anonymous',
  20889. load: function ( url, onLoad, onProgress, onError ) {
  20890. var texture = new Texture();
  20891. var loader = new ImageLoader( this.manager );
  20892. loader.setCrossOrigin( this.crossOrigin );
  20893. loader.setPath( this.path );
  20894. loader.load( url, function ( image ) {
  20895. texture.image = image;
  20896. // JPEGs can't have an alpha channel, so memory can be saved by storing them as RGB.
  20897. var isJPEG = url.search( /\.jpe?g($|\?)/i ) > 0 || url.search( /^data\:image\/jpeg/ ) === 0;
  20898. texture.format = isJPEG ? RGBFormat : RGBAFormat;
  20899. texture.needsUpdate = true;
  20900. if ( onLoad !== undefined ) {
  20901. onLoad( texture );
  20902. }
  20903. }, onProgress, onError );
  20904. return texture;
  20905. },
  20906. setCrossOrigin: function ( value ) {
  20907. this.crossOrigin = value;
  20908. return this;
  20909. },
  20910. setPath: function ( value ) {
  20911. this.path = value;
  20912. return this;
  20913. }
  20914. } );
  20915. /**
  20916. * @author zz85 / http://www.lab4games.net/zz85/blog
  20917. * Extensible curve object
  20918. *
  20919. * Some common of curve methods:
  20920. * .getPoint( t, optionalTarget ), .getTangent( t )
  20921. * .getPointAt( u, optionalTarget ), .getTangentAt( u )
  20922. * .getPoints(), .getSpacedPoints()
  20923. * .getLength()
  20924. * .updateArcLengths()
  20925. *
  20926. * This following curves inherit from THREE.Curve:
  20927. *
  20928. * -- 2D curves --
  20929. * THREE.ArcCurve
  20930. * THREE.CubicBezierCurve
  20931. * THREE.EllipseCurve
  20932. * THREE.LineCurve
  20933. * THREE.QuadraticBezierCurve
  20934. * THREE.SplineCurve
  20935. *
  20936. * -- 3D curves --
  20937. * THREE.CatmullRomCurve3
  20938. * THREE.CubicBezierCurve3
  20939. * THREE.LineCurve3
  20940. * THREE.QuadraticBezierCurve3
  20941. *
  20942. * A series of curves can be represented as a THREE.CurvePath.
  20943. *
  20944. **/
  20945. /**************************************************************
  20946. * Abstract Curve base class
  20947. **************************************************************/
  20948. function Curve() {
  20949. this.type = 'Curve';
  20950. this.arcLengthDivisions = 200;
  20951. }
  20952. Object.assign( Curve.prototype, {
  20953. // Virtual base class method to overwrite and implement in subclasses
  20954. // - t [0 .. 1]
  20955. getPoint: function ( /* t, optionalTarget */ ) {
  20956. console.warn( 'THREE.Curve: .getPoint() not implemented.' );
  20957. return null;
  20958. },
  20959. // Get point at relative position in curve according to arc length
  20960. // - u [0 .. 1]
  20961. getPointAt: function ( u, optionalTarget ) {
  20962. var t = this.getUtoTmapping( u );
  20963. return this.getPoint( t, optionalTarget );
  20964. },
  20965. // Get sequence of points using getPoint( t )
  20966. getPoints: function ( divisions ) {
  20967. if ( divisions === undefined ) divisions = 5;
  20968. var points = [];
  20969. for ( var d = 0; d <= divisions; d ++ ) {
  20970. points.push( this.getPoint( d / divisions ) );
  20971. }
  20972. return points;
  20973. },
  20974. // Get sequence of points using getPointAt( u )
  20975. getSpacedPoints: function ( divisions ) {
  20976. if ( divisions === undefined ) divisions = 5;
  20977. var points = [];
  20978. for ( var d = 0; d <= divisions; d ++ ) {
  20979. points.push( this.getPointAt( d / divisions ) );
  20980. }
  20981. return points;
  20982. },
  20983. // Get total curve arc length
  20984. getLength: function () {
  20985. var lengths = this.getLengths();
  20986. return lengths[ lengths.length - 1 ];
  20987. },
  20988. // Get list of cumulative segment lengths
  20989. getLengths: function ( divisions ) {
  20990. if ( divisions === undefined ) divisions = this.arcLengthDivisions;
  20991. if ( this.cacheArcLengths &&
  20992. ( this.cacheArcLengths.length === divisions + 1 ) &&
  20993. ! this.needsUpdate ) {
  20994. return this.cacheArcLengths;
  20995. }
  20996. this.needsUpdate = false;
  20997. var cache = [];
  20998. var current, last = this.getPoint( 0 );
  20999. var p, sum = 0;
  21000. cache.push( 0 );
  21001. for ( p = 1; p <= divisions; p ++ ) {
  21002. current = this.getPoint( p / divisions );
  21003. sum += current.distanceTo( last );
  21004. cache.push( sum );
  21005. last = current;
  21006. }
  21007. this.cacheArcLengths = cache;
  21008. return cache; // { sums: cache, sum: sum }; Sum is in the last element.
  21009. },
  21010. updateArcLengths: function () {
  21011. this.needsUpdate = true;
  21012. this.getLengths();
  21013. },
  21014. // Given u ( 0 .. 1 ), get a t to find p. This gives you points which are equidistant
  21015. getUtoTmapping: function ( u, distance ) {
  21016. var arcLengths = this.getLengths();
  21017. var i = 0, il = arcLengths.length;
  21018. var targetArcLength; // The targeted u distance value to get
  21019. if ( distance ) {
  21020. targetArcLength = distance;
  21021. } else {
  21022. targetArcLength = u * arcLengths[ il - 1 ];
  21023. }
  21024. // binary search for the index with largest value smaller than target u distance
  21025. var low = 0, high = il - 1, comparison;
  21026. while ( low <= high ) {
  21027. 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
  21028. comparison = arcLengths[ i ] - targetArcLength;
  21029. if ( comparison < 0 ) {
  21030. low = i + 1;
  21031. } else if ( comparison > 0 ) {
  21032. high = i - 1;
  21033. } else {
  21034. high = i;
  21035. break;
  21036. // DONE
  21037. }
  21038. }
  21039. i = high;
  21040. if ( arcLengths[ i ] === targetArcLength ) {
  21041. return i / ( il - 1 );
  21042. }
  21043. // we could get finer grain at lengths, or use simple interpolation between two points
  21044. var lengthBefore = arcLengths[ i ];
  21045. var lengthAfter = arcLengths[ i + 1 ];
  21046. var segmentLength = lengthAfter - lengthBefore;
  21047. // determine where we are between the 'before' and 'after' points
  21048. var segmentFraction = ( targetArcLength - lengthBefore ) / segmentLength;
  21049. // add that fractional amount to t
  21050. var t = ( i + segmentFraction ) / ( il - 1 );
  21051. return t;
  21052. },
  21053. // Returns a unit vector tangent at t
  21054. // In case any sub curve does not implement its tangent derivation,
  21055. // 2 points a small delta apart will be used to find its gradient
  21056. // which seems to give a reasonable approximation
  21057. getTangent: function ( t ) {
  21058. var delta = 0.0001;
  21059. var t1 = t - delta;
  21060. var t2 = t + delta;
  21061. // Capping in case of danger
  21062. if ( t1 < 0 ) t1 = 0;
  21063. if ( t2 > 1 ) t2 = 1;
  21064. var pt1 = this.getPoint( t1 );
  21065. var pt2 = this.getPoint( t2 );
  21066. var vec = pt2.clone().sub( pt1 );
  21067. return vec.normalize();
  21068. },
  21069. getTangentAt: function ( u ) {
  21070. var t = this.getUtoTmapping( u );
  21071. return this.getTangent( t );
  21072. },
  21073. computeFrenetFrames: function ( segments, closed ) {
  21074. // see http://www.cs.indiana.edu/pub/techreports/TR425.pdf
  21075. var normal = new Vector3();
  21076. var tangents = [];
  21077. var normals = [];
  21078. var binormals = [];
  21079. var vec = new Vector3();
  21080. var mat = new Matrix4();
  21081. var i, u, theta;
  21082. // compute the tangent vectors for each segment on the curve
  21083. for ( i = 0; i <= segments; i ++ ) {
  21084. u = i / segments;
  21085. tangents[ i ] = this.getTangentAt( u );
  21086. tangents[ i ].normalize();
  21087. }
  21088. // select an initial normal vector perpendicular to the first tangent vector,
  21089. // and in the direction of the minimum tangent xyz component
  21090. normals[ 0 ] = new Vector3();
  21091. binormals[ 0 ] = new Vector3();
  21092. var min = Number.MAX_VALUE;
  21093. var tx = Math.abs( tangents[ 0 ].x );
  21094. var ty = Math.abs( tangents[ 0 ].y );
  21095. var tz = Math.abs( tangents[ 0 ].z );
  21096. if ( tx <= min ) {
  21097. min = tx;
  21098. normal.set( 1, 0, 0 );
  21099. }
  21100. if ( ty <= min ) {
  21101. min = ty;
  21102. normal.set( 0, 1, 0 );
  21103. }
  21104. if ( tz <= min ) {
  21105. normal.set( 0, 0, 1 );
  21106. }
  21107. vec.crossVectors( tangents[ 0 ], normal ).normalize();
  21108. normals[ 0 ].crossVectors( tangents[ 0 ], vec );
  21109. binormals[ 0 ].crossVectors( tangents[ 0 ], normals[ 0 ] );
  21110. // compute the slowly-varying normal and binormal vectors for each segment on the curve
  21111. for ( i = 1; i <= segments; i ++ ) {
  21112. normals[ i ] = normals[ i - 1 ].clone();
  21113. binormals[ i ] = binormals[ i - 1 ].clone();
  21114. vec.crossVectors( tangents[ i - 1 ], tangents[ i ] );
  21115. if ( vec.length() > Number.EPSILON ) {
  21116. vec.normalize();
  21117. theta = Math.acos( _Math.clamp( tangents[ i - 1 ].dot( tangents[ i ] ), - 1, 1 ) ); // clamp for floating pt errors
  21118. normals[ i ].applyMatrix4( mat.makeRotationAxis( vec, theta ) );
  21119. }
  21120. binormals[ i ].crossVectors( tangents[ i ], normals[ i ] );
  21121. }
  21122. // if the curve is closed, postprocess the vectors so the first and last normal vectors are the same
  21123. if ( closed === true ) {
  21124. theta = Math.acos( _Math.clamp( normals[ 0 ].dot( normals[ segments ] ), - 1, 1 ) );
  21125. theta /= segments;
  21126. if ( tangents[ 0 ].dot( vec.crossVectors( normals[ 0 ], normals[ segments ] ) ) > 0 ) {
  21127. theta = - theta;
  21128. }
  21129. for ( i = 1; i <= segments; i ++ ) {
  21130. // twist a little...
  21131. normals[ i ].applyMatrix4( mat.makeRotationAxis( tangents[ i ], theta * i ) );
  21132. binormals[ i ].crossVectors( tangents[ i ], normals[ i ] );
  21133. }
  21134. }
  21135. return {
  21136. tangents: tangents,
  21137. normals: normals,
  21138. binormals: binormals
  21139. };
  21140. },
  21141. clone: function () {
  21142. return new this.constructor().copy( this );
  21143. },
  21144. copy: function ( source ) {
  21145. this.arcLengthDivisions = source.arcLengthDivisions;
  21146. return this;
  21147. },
  21148. toJSON: function () {
  21149. var data = {
  21150. metadata: {
  21151. version: 4.5,
  21152. type: 'Curve',
  21153. generator: 'Curve.toJSON'
  21154. }
  21155. };
  21156. data.arcLengthDivisions = this.arcLengthDivisions;
  21157. data.type = this.type;
  21158. return data;
  21159. },
  21160. fromJSON: function ( json ) {
  21161. this.arcLengthDivisions = json.arcLengthDivisions;
  21162. return this;
  21163. }
  21164. } );
  21165. function EllipseCurve( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  21166. Curve.call( this );
  21167. this.type = 'EllipseCurve';
  21168. this.aX = aX || 0;
  21169. this.aY = aY || 0;
  21170. this.xRadius = xRadius || 1;
  21171. this.yRadius = yRadius || 1;
  21172. this.aStartAngle = aStartAngle || 0;
  21173. this.aEndAngle = aEndAngle || 2 * Math.PI;
  21174. this.aClockwise = aClockwise || false;
  21175. this.aRotation = aRotation || 0;
  21176. }
  21177. EllipseCurve.prototype = Object.create( Curve.prototype );
  21178. EllipseCurve.prototype.constructor = EllipseCurve;
  21179. EllipseCurve.prototype.isEllipseCurve = true;
  21180. EllipseCurve.prototype.getPoint = function ( t, optionalTarget ) {
  21181. var point = optionalTarget || new Vector2();
  21182. var twoPi = Math.PI * 2;
  21183. var deltaAngle = this.aEndAngle - this.aStartAngle;
  21184. var samePoints = Math.abs( deltaAngle ) < Number.EPSILON;
  21185. // ensures that deltaAngle is 0 .. 2 PI
  21186. while ( deltaAngle < 0 ) deltaAngle += twoPi;
  21187. while ( deltaAngle > twoPi ) deltaAngle -= twoPi;
  21188. if ( deltaAngle < Number.EPSILON ) {
  21189. if ( samePoints ) {
  21190. deltaAngle = 0;
  21191. } else {
  21192. deltaAngle = twoPi;
  21193. }
  21194. }
  21195. if ( this.aClockwise === true && ! samePoints ) {
  21196. if ( deltaAngle === twoPi ) {
  21197. deltaAngle = - twoPi;
  21198. } else {
  21199. deltaAngle = deltaAngle - twoPi;
  21200. }
  21201. }
  21202. var angle = this.aStartAngle + t * deltaAngle;
  21203. var x = this.aX + this.xRadius * Math.cos( angle );
  21204. var y = this.aY + this.yRadius * Math.sin( angle );
  21205. if ( this.aRotation !== 0 ) {
  21206. var cos = Math.cos( this.aRotation );
  21207. var sin = Math.sin( this.aRotation );
  21208. var tx = x - this.aX;
  21209. var ty = y - this.aY;
  21210. // Rotate the point about the center of the ellipse.
  21211. x = tx * cos - ty * sin + this.aX;
  21212. y = tx * sin + ty * cos + this.aY;
  21213. }
  21214. return point.set( x, y );
  21215. };
  21216. EllipseCurve.prototype.copy = function ( source ) {
  21217. Curve.prototype.copy.call( this, source );
  21218. this.aX = source.aX;
  21219. this.aY = source.aY;
  21220. this.xRadius = source.xRadius;
  21221. this.yRadius = source.yRadius;
  21222. this.aStartAngle = source.aStartAngle;
  21223. this.aEndAngle = source.aEndAngle;
  21224. this.aClockwise = source.aClockwise;
  21225. this.aRotation = source.aRotation;
  21226. return this;
  21227. };
  21228. EllipseCurve.prototype.toJSON = function () {
  21229. var data = Curve.prototype.toJSON.call( this );
  21230. data.aX = this.aX;
  21231. data.aY = this.aY;
  21232. data.xRadius = this.xRadius;
  21233. data.yRadius = this.yRadius;
  21234. data.aStartAngle = this.aStartAngle;
  21235. data.aEndAngle = this.aEndAngle;
  21236. data.aClockwise = this.aClockwise;
  21237. data.aRotation = this.aRotation;
  21238. return data;
  21239. };
  21240. EllipseCurve.prototype.fromJSON = function ( json ) {
  21241. Curve.prototype.fromJSON.call( this, json );
  21242. this.aX = json.aX;
  21243. this.aY = json.aY;
  21244. this.xRadius = json.xRadius;
  21245. this.yRadius = json.yRadius;
  21246. this.aStartAngle = json.aStartAngle;
  21247. this.aEndAngle = json.aEndAngle;
  21248. this.aClockwise = json.aClockwise;
  21249. this.aRotation = json.aRotation;
  21250. return this;
  21251. };
  21252. function ArcCurve( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  21253. EllipseCurve.call( this, aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise );
  21254. this.type = 'ArcCurve';
  21255. }
  21256. ArcCurve.prototype = Object.create( EllipseCurve.prototype );
  21257. ArcCurve.prototype.constructor = ArcCurve;
  21258. ArcCurve.prototype.isArcCurve = true;
  21259. /**
  21260. * @author zz85 https://github.com/zz85
  21261. *
  21262. * Centripetal CatmullRom Curve - which is useful for avoiding
  21263. * cusps and self-intersections in non-uniform catmull rom curves.
  21264. * http://www.cemyuksel.com/research/catmullrom_param/catmullrom.pdf
  21265. *
  21266. * curve.type accepts centripetal(default), chordal and catmullrom
  21267. * curve.tension is used for catmullrom which defaults to 0.5
  21268. */
  21269. /*
  21270. Based on an optimized c++ solution in
  21271. - http://stackoverflow.com/questions/9489736/catmull-rom-curve-with-no-cusps-and-no-self-intersections/
  21272. - http://ideone.com/NoEbVM
  21273. This CubicPoly class could be used for reusing some variables and calculations,
  21274. but for three.js curve use, it could be possible inlined and flatten into a single function call
  21275. which can be placed in CurveUtils.
  21276. */
  21277. function CubicPoly() {
  21278. var c0 = 0, c1 = 0, c2 = 0, c3 = 0;
  21279. /*
  21280. * Compute coefficients for a cubic polynomial
  21281. * p(s) = c0 + c1*s + c2*s^2 + c3*s^3
  21282. * such that
  21283. * p(0) = x0, p(1) = x1
  21284. * and
  21285. * p'(0) = t0, p'(1) = t1.
  21286. */
  21287. function init( x0, x1, t0, t1 ) {
  21288. c0 = x0;
  21289. c1 = t0;
  21290. c2 = - 3 * x0 + 3 * x1 - 2 * t0 - t1;
  21291. c3 = 2 * x0 - 2 * x1 + t0 + t1;
  21292. }
  21293. return {
  21294. initCatmullRom: function ( x0, x1, x2, x3, tension ) {
  21295. init( x1, x2, tension * ( x2 - x0 ), tension * ( x3 - x1 ) );
  21296. },
  21297. initNonuniformCatmullRom: function ( x0, x1, x2, x3, dt0, dt1, dt2 ) {
  21298. // compute tangents when parameterized in [t1,t2]
  21299. var t1 = ( x1 - x0 ) / dt0 - ( x2 - x0 ) / ( dt0 + dt1 ) + ( x2 - x1 ) / dt1;
  21300. var t2 = ( x2 - x1 ) / dt1 - ( x3 - x1 ) / ( dt1 + dt2 ) + ( x3 - x2 ) / dt2;
  21301. // rescale tangents for parametrization in [0,1]
  21302. t1 *= dt1;
  21303. t2 *= dt1;
  21304. init( x1, x2, t1, t2 );
  21305. },
  21306. calc: function ( t ) {
  21307. var t2 = t * t;
  21308. var t3 = t2 * t;
  21309. return c0 + c1 * t + c2 * t2 + c3 * t3;
  21310. }
  21311. };
  21312. }
  21313. //
  21314. var tmp = new Vector3();
  21315. var px = new CubicPoly(), py = new CubicPoly(), pz = new CubicPoly();
  21316. function CatmullRomCurve3( points, closed, curveType, tension ) {
  21317. Curve.call( this );
  21318. this.type = 'CatmullRomCurve3';
  21319. this.points = points || [];
  21320. this.closed = closed || false;
  21321. this.curveType = curveType || 'centripetal';
  21322. this.tension = tension || 0.5;
  21323. }
  21324. CatmullRomCurve3.prototype = Object.create( Curve.prototype );
  21325. CatmullRomCurve3.prototype.constructor = CatmullRomCurve3;
  21326. CatmullRomCurve3.prototype.isCatmullRomCurve3 = true;
  21327. CatmullRomCurve3.prototype.getPoint = function ( t, optionalTarget ) {
  21328. var point = optionalTarget || new Vector3();
  21329. var points = this.points;
  21330. var l = points.length;
  21331. var p = ( l - ( this.closed ? 0 : 1 ) ) * t;
  21332. var intPoint = Math.floor( p );
  21333. var weight = p - intPoint;
  21334. if ( this.closed ) {
  21335. intPoint += intPoint > 0 ? 0 : ( Math.floor( Math.abs( intPoint ) / l ) + 1 ) * l;
  21336. } else if ( weight === 0 && intPoint === l - 1 ) {
  21337. intPoint = l - 2;
  21338. weight = 1;
  21339. }
  21340. var p0, p1, p2, p3; // 4 points
  21341. if ( this.closed || intPoint > 0 ) {
  21342. p0 = points[ ( intPoint - 1 ) % l ];
  21343. } else {
  21344. // extrapolate first point
  21345. tmp.subVectors( points[ 0 ], points[ 1 ] ).add( points[ 0 ] );
  21346. p0 = tmp;
  21347. }
  21348. p1 = points[ intPoint % l ];
  21349. p2 = points[ ( intPoint + 1 ) % l ];
  21350. if ( this.closed || intPoint + 2 < l ) {
  21351. p3 = points[ ( intPoint + 2 ) % l ];
  21352. } else {
  21353. // extrapolate last point
  21354. tmp.subVectors( points[ l - 1 ], points[ l - 2 ] ).add( points[ l - 1 ] );
  21355. p3 = tmp;
  21356. }
  21357. if ( this.curveType === 'centripetal' || this.curveType === 'chordal' ) {
  21358. // init Centripetal / Chordal Catmull-Rom
  21359. var pow = this.curveType === 'chordal' ? 0.5 : 0.25;
  21360. var dt0 = Math.pow( p0.distanceToSquared( p1 ), pow );
  21361. var dt1 = Math.pow( p1.distanceToSquared( p2 ), pow );
  21362. var dt2 = Math.pow( p2.distanceToSquared( p3 ), pow );
  21363. // safety check for repeated points
  21364. if ( dt1 < 1e-4 ) dt1 = 1.0;
  21365. if ( dt0 < 1e-4 ) dt0 = dt1;
  21366. if ( dt2 < 1e-4 ) dt2 = dt1;
  21367. px.initNonuniformCatmullRom( p0.x, p1.x, p2.x, p3.x, dt0, dt1, dt2 );
  21368. py.initNonuniformCatmullRom( p0.y, p1.y, p2.y, p3.y, dt0, dt1, dt2 );
  21369. pz.initNonuniformCatmullRom( p0.z, p1.z, p2.z, p3.z, dt0, dt1, dt2 );
  21370. } else if ( this.curveType === 'catmullrom' ) {
  21371. px.initCatmullRom( p0.x, p1.x, p2.x, p3.x, this.tension );
  21372. py.initCatmullRom( p0.y, p1.y, p2.y, p3.y, this.tension );
  21373. pz.initCatmullRom( p0.z, p1.z, p2.z, p3.z, this.tension );
  21374. }
  21375. point.set(
  21376. px.calc( weight ),
  21377. py.calc( weight ),
  21378. pz.calc( weight )
  21379. );
  21380. return point;
  21381. };
  21382. CatmullRomCurve3.prototype.copy = function ( source ) {
  21383. Curve.prototype.copy.call( this, source );
  21384. this.points = [];
  21385. for ( var i = 0, l = source.points.length; i < l; i ++ ) {
  21386. var point = source.points[ i ];
  21387. this.points.push( point.clone() );
  21388. }
  21389. this.closed = source.closed;
  21390. this.curveType = source.curveType;
  21391. this.tension = source.tension;
  21392. return this;
  21393. };
  21394. CatmullRomCurve3.prototype.toJSON = function () {
  21395. var data = Curve.prototype.toJSON.call( this );
  21396. data.points = [];
  21397. for ( var i = 0, l = this.points.length; i < l; i ++ ) {
  21398. var point = this.points[ i ];
  21399. data.points.push( point.toArray() );
  21400. }
  21401. data.closed = this.closed;
  21402. data.curveType = this.curveType;
  21403. data.tension = this.tension;
  21404. return data;
  21405. };
  21406. CatmullRomCurve3.prototype.fromJSON = function ( json ) {
  21407. Curve.prototype.fromJSON.call( this, json );
  21408. this.points = [];
  21409. for ( var i = 0, l = json.points.length; i < l; i ++ ) {
  21410. var point = json.points[ i ];
  21411. this.points.push( new Vector3().fromArray( point ) );
  21412. }
  21413. this.closed = json.closed;
  21414. this.curveType = json.curveType;
  21415. this.tension = json.tension;
  21416. return this;
  21417. };
  21418. /**
  21419. * @author zz85 / http://www.lab4games.net/zz85/blog
  21420. *
  21421. * Bezier Curves formulas obtained from
  21422. * http://en.wikipedia.org/wiki/Bézier_curve
  21423. */
  21424. function CatmullRom( t, p0, p1, p2, p3 ) {
  21425. var v0 = ( p2 - p0 ) * 0.5;
  21426. var v1 = ( p3 - p1 ) * 0.5;
  21427. var t2 = t * t;
  21428. var t3 = t * t2;
  21429. return ( 2 * p1 - 2 * p2 + v0 + v1 ) * t3 + ( - 3 * p1 + 3 * p2 - 2 * v0 - v1 ) * t2 + v0 * t + p1;
  21430. }
  21431. //
  21432. function QuadraticBezierP0( t, p ) {
  21433. var k = 1 - t;
  21434. return k * k * p;
  21435. }
  21436. function QuadraticBezierP1( t, p ) {
  21437. return 2 * ( 1 - t ) * t * p;
  21438. }
  21439. function QuadraticBezierP2( t, p ) {
  21440. return t * t * p;
  21441. }
  21442. function QuadraticBezier( t, p0, p1, p2 ) {
  21443. return QuadraticBezierP0( t, p0 ) + QuadraticBezierP1( t, p1 ) +
  21444. QuadraticBezierP2( t, p2 );
  21445. }
  21446. //
  21447. function CubicBezierP0( t, p ) {
  21448. var k = 1 - t;
  21449. return k * k * k * p;
  21450. }
  21451. function CubicBezierP1( t, p ) {
  21452. var k = 1 - t;
  21453. return 3 * k * k * t * p;
  21454. }
  21455. function CubicBezierP2( t, p ) {
  21456. return 3 * ( 1 - t ) * t * t * p;
  21457. }
  21458. function CubicBezierP3( t, p ) {
  21459. return t * t * t * p;
  21460. }
  21461. function CubicBezier( t, p0, p1, p2, p3 ) {
  21462. return CubicBezierP0( t, p0 ) + CubicBezierP1( t, p1 ) + CubicBezierP2( t, p2 ) +
  21463. CubicBezierP3( t, p3 );
  21464. }
  21465. function CubicBezierCurve( v0, v1, v2, v3 ) {
  21466. Curve.call( this );
  21467. this.type = 'CubicBezierCurve';
  21468. this.v0 = v0 || new Vector2();
  21469. this.v1 = v1 || new Vector2();
  21470. this.v2 = v2 || new Vector2();
  21471. this.v3 = v3 || new Vector2();
  21472. }
  21473. CubicBezierCurve.prototype = Object.create( Curve.prototype );
  21474. CubicBezierCurve.prototype.constructor = CubicBezierCurve;
  21475. CubicBezierCurve.prototype.isCubicBezierCurve = true;
  21476. CubicBezierCurve.prototype.getPoint = function ( t, optionalTarget ) {
  21477. var point = optionalTarget || new Vector2();
  21478. var v0 = this.v0, v1 = this.v1, v2 = this.v2, v3 = this.v3;
  21479. point.set(
  21480. CubicBezier( t, v0.x, v1.x, v2.x, v3.x ),
  21481. CubicBezier( t, v0.y, v1.y, v2.y, v3.y )
  21482. );
  21483. return point;
  21484. };
  21485. CubicBezierCurve.prototype.copy = function ( source ) {
  21486. Curve.prototype.copy.call( this, source );
  21487. this.v0.copy( source.v0 );
  21488. this.v1.copy( source.v1 );
  21489. this.v2.copy( source.v2 );
  21490. this.v3.copy( source.v3 );
  21491. return this;
  21492. };
  21493. CubicBezierCurve.prototype.toJSON = function () {
  21494. var data = Curve.prototype.toJSON.call( this );
  21495. data.v0 = this.v0.toArray();
  21496. data.v1 = this.v1.toArray();
  21497. data.v2 = this.v2.toArray();
  21498. data.v3 = this.v3.toArray();
  21499. return data;
  21500. };
  21501. CubicBezierCurve.prototype.fromJSON = function ( json ) {
  21502. Curve.prototype.fromJSON.call( this, json );
  21503. this.v0.fromArray( json.v0 );
  21504. this.v1.fromArray( json.v1 );
  21505. this.v2.fromArray( json.v2 );
  21506. this.v3.fromArray( json.v3 );
  21507. return this;
  21508. };
  21509. function CubicBezierCurve3( v0, v1, v2, v3 ) {
  21510. Curve.call( this );
  21511. this.type = 'CubicBezierCurve3';
  21512. this.v0 = v0 || new Vector3();
  21513. this.v1 = v1 || new Vector3();
  21514. this.v2 = v2 || new Vector3();
  21515. this.v3 = v3 || new Vector3();
  21516. }
  21517. CubicBezierCurve3.prototype = Object.create( Curve.prototype );
  21518. CubicBezierCurve3.prototype.constructor = CubicBezierCurve3;
  21519. CubicBezierCurve3.prototype.isCubicBezierCurve3 = true;
  21520. CubicBezierCurve3.prototype.getPoint = function ( t, optionalTarget ) {
  21521. var point = optionalTarget || new Vector3();
  21522. var v0 = this.v0, v1 = this.v1, v2 = this.v2, v3 = this.v3;
  21523. point.set(
  21524. CubicBezier( t, v0.x, v1.x, v2.x, v3.x ),
  21525. CubicBezier( t, v0.y, v1.y, v2.y, v3.y ),
  21526. CubicBezier( t, v0.z, v1.z, v2.z, v3.z )
  21527. );
  21528. return point;
  21529. };
  21530. CubicBezierCurve3.prototype.copy = function ( source ) {
  21531. Curve.prototype.copy.call( this, source );
  21532. this.v0.copy( source.v0 );
  21533. this.v1.copy( source.v1 );
  21534. this.v2.copy( source.v2 );
  21535. this.v3.copy( source.v3 );
  21536. return this;
  21537. };
  21538. CubicBezierCurve3.prototype.toJSON = function () {
  21539. var data = Curve.prototype.toJSON.call( this );
  21540. data.v0 = this.v0.toArray();
  21541. data.v1 = this.v1.toArray();
  21542. data.v2 = this.v2.toArray();
  21543. data.v3 = this.v3.toArray();
  21544. return data;
  21545. };
  21546. CubicBezierCurve3.prototype.fromJSON = function ( json ) {
  21547. Curve.prototype.fromJSON.call( this, json );
  21548. this.v0.fromArray( json.v0 );
  21549. this.v1.fromArray( json.v1 );
  21550. this.v2.fromArray( json.v2 );
  21551. this.v3.fromArray( json.v3 );
  21552. return this;
  21553. };
  21554. function LineCurve( v1, v2 ) {
  21555. Curve.call( this );
  21556. this.type = 'LineCurve';
  21557. this.v1 = v1 || new Vector2();
  21558. this.v2 = v2 || new Vector2();
  21559. }
  21560. LineCurve.prototype = Object.create( Curve.prototype );
  21561. LineCurve.prototype.constructor = LineCurve;
  21562. LineCurve.prototype.isLineCurve = true;
  21563. LineCurve.prototype.getPoint = function ( t, optionalTarget ) {
  21564. var point = optionalTarget || new Vector2();
  21565. if ( t === 1 ) {
  21566. point.copy( this.v2 );
  21567. } else {
  21568. point.copy( this.v2 ).sub( this.v1 );
  21569. point.multiplyScalar( t ).add( this.v1 );
  21570. }
  21571. return point;
  21572. };
  21573. // Line curve is linear, so we can overwrite default getPointAt
  21574. LineCurve.prototype.getPointAt = function ( u, optionalTarget ) {
  21575. return this.getPoint( u, optionalTarget );
  21576. };
  21577. LineCurve.prototype.getTangent = function ( /* t */ ) {
  21578. var tangent = this.v2.clone().sub( this.v1 );
  21579. return tangent.normalize();
  21580. };
  21581. LineCurve.prototype.copy = function ( source ) {
  21582. Curve.prototype.copy.call( this, source );
  21583. this.v1.copy( source.v1 );
  21584. this.v2.copy( source.v2 );
  21585. return this;
  21586. };
  21587. LineCurve.prototype.toJSON = function () {
  21588. var data = Curve.prototype.toJSON.call( this );
  21589. data.v1 = this.v1.toArray();
  21590. data.v2 = this.v2.toArray();
  21591. return data;
  21592. };
  21593. LineCurve.prototype.fromJSON = function ( json ) {
  21594. Curve.prototype.fromJSON.call( this, json );
  21595. this.v1.fromArray( json.v1 );
  21596. this.v2.fromArray( json.v2 );
  21597. return this;
  21598. };
  21599. function LineCurve3( v1, v2 ) {
  21600. Curve.call( this );
  21601. this.type = 'LineCurve3';
  21602. this.v1 = v1 || new Vector3();
  21603. this.v2 = v2 || new Vector3();
  21604. }
  21605. LineCurve3.prototype = Object.create( Curve.prototype );
  21606. LineCurve3.prototype.constructor = LineCurve3;
  21607. LineCurve3.prototype.isLineCurve3 = true;
  21608. LineCurve3.prototype.getPoint = function ( t, optionalTarget ) {
  21609. var point = optionalTarget || new Vector3();
  21610. if ( t === 1 ) {
  21611. point.copy( this.v2 );
  21612. } else {
  21613. point.copy( this.v2 ).sub( this.v1 );
  21614. point.multiplyScalar( t ).add( this.v1 );
  21615. }
  21616. return point;
  21617. };
  21618. // Line curve is linear, so we can overwrite default getPointAt
  21619. LineCurve3.prototype.getPointAt = function ( u, optionalTarget ) {
  21620. return this.getPoint( u, optionalTarget );
  21621. };
  21622. LineCurve3.prototype.copy = function ( source ) {
  21623. Curve.prototype.copy.call( this, source );
  21624. this.v1.copy( source.v1 );
  21625. this.v2.copy( source.v2 );
  21626. return this;
  21627. };
  21628. LineCurve3.prototype.toJSON = function () {
  21629. var data = Curve.prototype.toJSON.call( this );
  21630. data.v1 = this.v1.toArray();
  21631. data.v2 = this.v2.toArray();
  21632. return data;
  21633. };
  21634. LineCurve3.prototype.fromJSON = function ( json ) {
  21635. Curve.prototype.fromJSON.call( this, json );
  21636. this.v1.fromArray( json.v1 );
  21637. this.v2.fromArray( json.v2 );
  21638. return this;
  21639. };
  21640. function QuadraticBezierCurve( v0, v1, v2 ) {
  21641. Curve.call( this );
  21642. this.type = 'QuadraticBezierCurve';
  21643. this.v0 = v0 || new Vector2();
  21644. this.v1 = v1 || new Vector2();
  21645. this.v2 = v2 || new Vector2();
  21646. }
  21647. QuadraticBezierCurve.prototype = Object.create( Curve.prototype );
  21648. QuadraticBezierCurve.prototype.constructor = QuadraticBezierCurve;
  21649. QuadraticBezierCurve.prototype.isQuadraticBezierCurve = true;
  21650. QuadraticBezierCurve.prototype.getPoint = function ( t, optionalTarget ) {
  21651. var point = optionalTarget || new Vector2();
  21652. var v0 = this.v0, v1 = this.v1, v2 = this.v2;
  21653. point.set(
  21654. QuadraticBezier( t, v0.x, v1.x, v2.x ),
  21655. QuadraticBezier( t, v0.y, v1.y, v2.y )
  21656. );
  21657. return point;
  21658. };
  21659. QuadraticBezierCurve.prototype.copy = function ( source ) {
  21660. Curve.prototype.copy.call( this, source );
  21661. this.v0.copy( source.v0 );
  21662. this.v1.copy( source.v1 );
  21663. this.v2.copy( source.v2 );
  21664. return this;
  21665. };
  21666. QuadraticBezierCurve.prototype.toJSON = function () {
  21667. var data = Curve.prototype.toJSON.call( this );
  21668. data.v0 = this.v0.toArray();
  21669. data.v1 = this.v1.toArray();
  21670. data.v2 = this.v2.toArray();
  21671. return data;
  21672. };
  21673. QuadraticBezierCurve.prototype.fromJSON = function ( json ) {
  21674. Curve.prototype.fromJSON.call( this, json );
  21675. this.v0.fromArray( json.v0 );
  21676. this.v1.fromArray( json.v1 );
  21677. this.v2.fromArray( json.v2 );
  21678. return this;
  21679. };
  21680. function QuadraticBezierCurve3( v0, v1, v2 ) {
  21681. Curve.call( this );
  21682. this.type = 'QuadraticBezierCurve3';
  21683. this.v0 = v0 || new Vector3();
  21684. this.v1 = v1 || new Vector3();
  21685. this.v2 = v2 || new Vector3();
  21686. }
  21687. QuadraticBezierCurve3.prototype = Object.create( Curve.prototype );
  21688. QuadraticBezierCurve3.prototype.constructor = QuadraticBezierCurve3;
  21689. QuadraticBezierCurve3.prototype.isQuadraticBezierCurve3 = true;
  21690. QuadraticBezierCurve3.prototype.getPoint = function ( t, optionalTarget ) {
  21691. var point = optionalTarget || new Vector3();
  21692. var v0 = this.v0, v1 = this.v1, v2 = this.v2;
  21693. point.set(
  21694. QuadraticBezier( t, v0.x, v1.x, v2.x ),
  21695. QuadraticBezier( t, v0.y, v1.y, v2.y ),
  21696. QuadraticBezier( t, v0.z, v1.z, v2.z )
  21697. );
  21698. return point;
  21699. };
  21700. QuadraticBezierCurve3.prototype.copy = function ( source ) {
  21701. Curve.prototype.copy.call( this, source );
  21702. this.v0.copy( source.v0 );
  21703. this.v1.copy( source.v1 );
  21704. this.v2.copy( source.v2 );
  21705. return this;
  21706. };
  21707. QuadraticBezierCurve3.prototype.toJSON = function () {
  21708. var data = Curve.prototype.toJSON.call( this );
  21709. data.v0 = this.v0.toArray();
  21710. data.v1 = this.v1.toArray();
  21711. data.v2 = this.v2.toArray();
  21712. return data;
  21713. };
  21714. QuadraticBezierCurve3.prototype.fromJSON = function ( json ) {
  21715. Curve.prototype.fromJSON.call( this, json );
  21716. this.v0.fromArray( json.v0 );
  21717. this.v1.fromArray( json.v1 );
  21718. this.v2.fromArray( json.v2 );
  21719. return this;
  21720. };
  21721. function SplineCurve( points /* array of Vector2 */ ) {
  21722. Curve.call( this );
  21723. this.type = 'SplineCurve';
  21724. this.points = points || [];
  21725. }
  21726. SplineCurve.prototype = Object.create( Curve.prototype );
  21727. SplineCurve.prototype.constructor = SplineCurve;
  21728. SplineCurve.prototype.isSplineCurve = true;
  21729. SplineCurve.prototype.getPoint = function ( t, optionalTarget ) {
  21730. var point = optionalTarget || new Vector2();
  21731. var points = this.points;
  21732. var p = ( points.length - 1 ) * t;
  21733. var intPoint = Math.floor( p );
  21734. var weight = p - intPoint;
  21735. var p0 = points[ intPoint === 0 ? intPoint : intPoint - 1 ];
  21736. var p1 = points[ intPoint ];
  21737. var p2 = points[ intPoint > points.length - 2 ? points.length - 1 : intPoint + 1 ];
  21738. var p3 = points[ intPoint > points.length - 3 ? points.length - 1 : intPoint + 2 ];
  21739. point.set(
  21740. CatmullRom( weight, p0.x, p1.x, p2.x, p3.x ),
  21741. CatmullRom( weight, p0.y, p1.y, p2.y, p3.y )
  21742. );
  21743. return point;
  21744. };
  21745. SplineCurve.prototype.copy = function ( source ) {
  21746. Curve.prototype.copy.call( this, source );
  21747. this.points = [];
  21748. for ( var i = 0, l = source.points.length; i < l; i ++ ) {
  21749. var point = source.points[ i ];
  21750. this.points.push( point.clone() );
  21751. }
  21752. return this;
  21753. };
  21754. SplineCurve.prototype.toJSON = function () {
  21755. var data = Curve.prototype.toJSON.call( this );
  21756. data.points = [];
  21757. for ( var i = 0, l = this.points.length; i < l; i ++ ) {
  21758. var point = this.points[ i ];
  21759. data.points.push( point.toArray() );
  21760. }
  21761. return data;
  21762. };
  21763. SplineCurve.prototype.fromJSON = function ( json ) {
  21764. Curve.prototype.fromJSON.call( this, json );
  21765. this.points = [];
  21766. for ( var i = 0, l = json.points.length; i < l; i ++ ) {
  21767. var point = json.points[ i ];
  21768. this.points.push( new Vector2().fromArray( point ) );
  21769. }
  21770. return this;
  21771. };
  21772. var Curves = /*#__PURE__*/Object.freeze({
  21773. ArcCurve: ArcCurve,
  21774. CatmullRomCurve3: CatmullRomCurve3,
  21775. CubicBezierCurve: CubicBezierCurve,
  21776. CubicBezierCurve3: CubicBezierCurve3,
  21777. EllipseCurve: EllipseCurve,
  21778. LineCurve: LineCurve,
  21779. LineCurve3: LineCurve3,
  21780. QuadraticBezierCurve: QuadraticBezierCurve,
  21781. QuadraticBezierCurve3: QuadraticBezierCurve3,
  21782. SplineCurve: SplineCurve
  21783. });
  21784. /**
  21785. * @author zz85 / http://www.lab4games.net/zz85/blog
  21786. *
  21787. **/
  21788. /**************************************************************
  21789. * Curved Path - a curve path is simply a array of connected
  21790. * curves, but retains the api of a curve
  21791. **************************************************************/
  21792. function CurvePath() {
  21793. Curve.call( this );
  21794. this.type = 'CurvePath';
  21795. this.curves = [];
  21796. this.autoClose = false; // Automatically closes the path
  21797. }
  21798. CurvePath.prototype = Object.assign( Object.create( Curve.prototype ), {
  21799. constructor: CurvePath,
  21800. add: function ( curve ) {
  21801. this.curves.push( curve );
  21802. },
  21803. closePath: function () {
  21804. // Add a line curve if start and end of lines are not connected
  21805. var startPoint = this.curves[ 0 ].getPoint( 0 );
  21806. var endPoint = this.curves[ this.curves.length - 1 ].getPoint( 1 );
  21807. if ( ! startPoint.equals( endPoint ) ) {
  21808. this.curves.push( new LineCurve( endPoint, startPoint ) );
  21809. }
  21810. },
  21811. // To get accurate point with reference to
  21812. // entire path distance at time t,
  21813. // following has to be done:
  21814. // 1. Length of each sub path have to be known
  21815. // 2. Locate and identify type of curve
  21816. // 3. Get t for the curve
  21817. // 4. Return curve.getPointAt(t')
  21818. getPoint: function ( t ) {
  21819. var d = t * this.getLength();
  21820. var curveLengths = this.getCurveLengths();
  21821. var i = 0;
  21822. // To think about boundaries points.
  21823. while ( i < curveLengths.length ) {
  21824. if ( curveLengths[ i ] >= d ) {
  21825. var diff = curveLengths[ i ] - d;
  21826. var curve = this.curves[ i ];
  21827. var segmentLength = curve.getLength();
  21828. var u = segmentLength === 0 ? 0 : 1 - diff / segmentLength;
  21829. return curve.getPointAt( u );
  21830. }
  21831. i ++;
  21832. }
  21833. return null;
  21834. // loop where sum != 0, sum > d , sum+1 <d
  21835. },
  21836. // We cannot use the default THREE.Curve getPoint() with getLength() because in
  21837. // THREE.Curve, getLength() depends on getPoint() but in THREE.CurvePath
  21838. // getPoint() depends on getLength
  21839. getLength: function () {
  21840. var lens = this.getCurveLengths();
  21841. return lens[ lens.length - 1 ];
  21842. },
  21843. // cacheLengths must be recalculated.
  21844. updateArcLengths: function () {
  21845. this.needsUpdate = true;
  21846. this.cacheLengths = null;
  21847. this.getCurveLengths();
  21848. },
  21849. // Compute lengths and cache them
  21850. // We cannot overwrite getLengths() because UtoT mapping uses it.
  21851. getCurveLengths: function () {
  21852. // We use cache values if curves and cache array are same length
  21853. if ( this.cacheLengths && this.cacheLengths.length === this.curves.length ) {
  21854. return this.cacheLengths;
  21855. }
  21856. // Get length of sub-curve
  21857. // Push sums into cached array
  21858. var lengths = [], sums = 0;
  21859. for ( var i = 0, l = this.curves.length; i < l; i ++ ) {
  21860. sums += this.curves[ i ].getLength();
  21861. lengths.push( sums );
  21862. }
  21863. this.cacheLengths = lengths;
  21864. return lengths;
  21865. },
  21866. getSpacedPoints: function ( divisions ) {
  21867. if ( divisions === undefined ) divisions = 40;
  21868. var points = [];
  21869. for ( var i = 0; i <= divisions; i ++ ) {
  21870. points.push( this.getPoint( i / divisions ) );
  21871. }
  21872. if ( this.autoClose ) {
  21873. points.push( points[ 0 ] );
  21874. }
  21875. return points;
  21876. },
  21877. getPoints: function ( divisions ) {
  21878. divisions = divisions || 12;
  21879. var points = [], last;
  21880. for ( var i = 0, curves = this.curves; i < curves.length; i ++ ) {
  21881. var curve = curves[ i ];
  21882. var resolution = ( curve && curve.isEllipseCurve ) ? divisions * 2
  21883. : ( curve && ( curve.isLineCurve || curve.isLineCurve3 ) ) ? 1
  21884. : ( curve && curve.isSplineCurve ) ? divisions * curve.points.length
  21885. : divisions;
  21886. var pts = curve.getPoints( resolution );
  21887. for ( var j = 0; j < pts.length; j ++ ) {
  21888. var point = pts[ j ];
  21889. if ( last && last.equals( point ) ) continue; // ensures no consecutive points are duplicates
  21890. points.push( point );
  21891. last = point;
  21892. }
  21893. }
  21894. if ( this.autoClose && points.length > 1 && ! points[ points.length - 1 ].equals( points[ 0 ] ) ) {
  21895. points.push( points[ 0 ] );
  21896. }
  21897. return points;
  21898. },
  21899. copy: function ( source ) {
  21900. Curve.prototype.copy.call( this, source );
  21901. this.curves = [];
  21902. for ( var i = 0, l = source.curves.length; i < l; i ++ ) {
  21903. var curve = source.curves[ i ];
  21904. this.curves.push( curve.clone() );
  21905. }
  21906. this.autoClose = source.autoClose;
  21907. return this;
  21908. },
  21909. toJSON: function () {
  21910. var data = Curve.prototype.toJSON.call( this );
  21911. data.autoClose = this.autoClose;
  21912. data.curves = [];
  21913. for ( var i = 0, l = this.curves.length; i < l; i ++ ) {
  21914. var curve = this.curves[ i ];
  21915. data.curves.push( curve.toJSON() );
  21916. }
  21917. return data;
  21918. },
  21919. fromJSON: function ( json ) {
  21920. Curve.prototype.fromJSON.call( this, json );
  21921. this.autoClose = json.autoClose;
  21922. this.curves = [];
  21923. for ( var i = 0, l = json.curves.length; i < l; i ++ ) {
  21924. var curve = json.curves[ i ];
  21925. this.curves.push( new Curves[ curve.type ]().fromJSON( curve ) );
  21926. }
  21927. return this;
  21928. }
  21929. } );
  21930. /**
  21931. * @author zz85 / http://www.lab4games.net/zz85/blog
  21932. * Creates free form 2d path using series of points, lines or curves.
  21933. **/
  21934. function Path( points ) {
  21935. CurvePath.call( this );
  21936. this.type = 'Path';
  21937. this.currentPoint = new Vector2();
  21938. if ( points ) {
  21939. this.setFromPoints( points );
  21940. }
  21941. }
  21942. Path.prototype = Object.assign( Object.create( CurvePath.prototype ), {
  21943. constructor: Path,
  21944. setFromPoints: function ( points ) {
  21945. this.moveTo( points[ 0 ].x, points[ 0 ].y );
  21946. for ( var i = 1, l = points.length; i < l; i ++ ) {
  21947. this.lineTo( points[ i ].x, points[ i ].y );
  21948. }
  21949. },
  21950. moveTo: function ( x, y ) {
  21951. this.currentPoint.set( x, y ); // TODO consider referencing vectors instead of copying?
  21952. },
  21953. lineTo: function ( x, y ) {
  21954. var curve = new LineCurve( this.currentPoint.clone(), new Vector2( x, y ) );
  21955. this.curves.push( curve );
  21956. this.currentPoint.set( x, y );
  21957. },
  21958. quadraticCurveTo: function ( aCPx, aCPy, aX, aY ) {
  21959. var curve = new QuadraticBezierCurve(
  21960. this.currentPoint.clone(),
  21961. new Vector2( aCPx, aCPy ),
  21962. new Vector2( aX, aY )
  21963. );
  21964. this.curves.push( curve );
  21965. this.currentPoint.set( aX, aY );
  21966. },
  21967. bezierCurveTo: function ( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY ) {
  21968. var curve = new CubicBezierCurve(
  21969. this.currentPoint.clone(),
  21970. new Vector2( aCP1x, aCP1y ),
  21971. new Vector2( aCP2x, aCP2y ),
  21972. new Vector2( aX, aY )
  21973. );
  21974. this.curves.push( curve );
  21975. this.currentPoint.set( aX, aY );
  21976. },
  21977. splineThru: function ( pts /*Array of Vector*/ ) {
  21978. var npts = [ this.currentPoint.clone() ].concat( pts );
  21979. var curve = new SplineCurve( npts );
  21980. this.curves.push( curve );
  21981. this.currentPoint.copy( pts[ pts.length - 1 ] );
  21982. },
  21983. arc: function ( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  21984. var x0 = this.currentPoint.x;
  21985. var y0 = this.currentPoint.y;
  21986. this.absarc( aX + x0, aY + y0, aRadius,
  21987. aStartAngle, aEndAngle, aClockwise );
  21988. },
  21989. absarc: function ( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  21990. this.absellipse( aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise );
  21991. },
  21992. ellipse: function ( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  21993. var x0 = this.currentPoint.x;
  21994. var y0 = this.currentPoint.y;
  21995. this.absellipse( aX + x0, aY + y0, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation );
  21996. },
  21997. absellipse: function ( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  21998. var curve = new EllipseCurve( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation );
  21999. if ( this.curves.length > 0 ) {
  22000. // if a previous curve is present, attempt to join
  22001. var firstPoint = curve.getPoint( 0 );
  22002. if ( ! firstPoint.equals( this.currentPoint ) ) {
  22003. this.lineTo( firstPoint.x, firstPoint.y );
  22004. }
  22005. }
  22006. this.curves.push( curve );
  22007. var lastPoint = curve.getPoint( 1 );
  22008. this.currentPoint.copy( lastPoint );
  22009. },
  22010. copy: function ( source ) {
  22011. CurvePath.prototype.copy.call( this, source );
  22012. this.currentPoint.copy( source.currentPoint );
  22013. return this;
  22014. },
  22015. toJSON: function () {
  22016. var data = CurvePath.prototype.toJSON.call( this );
  22017. data.currentPoint = this.currentPoint.toArray();
  22018. return data;
  22019. },
  22020. fromJSON: function ( json ) {
  22021. CurvePath.prototype.fromJSON.call( this, json );
  22022. this.currentPoint.fromArray( json.currentPoint );
  22023. return this;
  22024. }
  22025. } );
  22026. /**
  22027. * @author zz85 / http://www.lab4games.net/zz85/blog
  22028. * Defines a 2d shape plane using paths.
  22029. **/
  22030. // STEP 1 Create a path.
  22031. // STEP 2 Turn path into shape.
  22032. // STEP 3 ExtrudeGeometry takes in Shape/Shapes
  22033. // STEP 3a - Extract points from each shape, turn to vertices
  22034. // STEP 3b - Triangulate each shape, add faces.
  22035. function Shape( points ) {
  22036. Path.call( this, points );
  22037. this.uuid = _Math.generateUUID();
  22038. this.type = 'Shape';
  22039. this.holes = [];
  22040. }
  22041. Shape.prototype = Object.assign( Object.create( Path.prototype ), {
  22042. constructor: Shape,
  22043. getPointsHoles: function ( divisions ) {
  22044. var holesPts = [];
  22045. for ( var i = 0, l = this.holes.length; i < l; i ++ ) {
  22046. holesPts[ i ] = this.holes[ i ].getPoints( divisions );
  22047. }
  22048. return holesPts;
  22049. },
  22050. // get points of shape and holes (keypoints based on segments parameter)
  22051. extractPoints: function ( divisions ) {
  22052. return {
  22053. shape: this.getPoints( divisions ),
  22054. holes: this.getPointsHoles( divisions )
  22055. };
  22056. },
  22057. copy: function ( source ) {
  22058. Path.prototype.copy.call( this, source );
  22059. this.holes = [];
  22060. for ( var i = 0, l = source.holes.length; i < l; i ++ ) {
  22061. var hole = source.holes[ i ];
  22062. this.holes.push( hole.clone() );
  22063. }
  22064. return this;
  22065. },
  22066. toJSON: function () {
  22067. var data = Path.prototype.toJSON.call( this );
  22068. data.uuid = this.uuid;
  22069. data.holes = [];
  22070. for ( var i = 0, l = this.holes.length; i < l; i ++ ) {
  22071. var hole = this.holes[ i ];
  22072. data.holes.push( hole.toJSON() );
  22073. }
  22074. return data;
  22075. },
  22076. fromJSON: function ( json ) {
  22077. Path.prototype.fromJSON.call( this, json );
  22078. this.uuid = json.uuid;
  22079. this.holes = [];
  22080. for ( var i = 0, l = json.holes.length; i < l; i ++ ) {
  22081. var hole = json.holes[ i ];
  22082. this.holes.push( new Path().fromJSON( hole ) );
  22083. }
  22084. return this;
  22085. }
  22086. } );
  22087. /**
  22088. * @author mrdoob / http://mrdoob.com/
  22089. * @author alteredq / http://alteredqualia.com/
  22090. */
  22091. function Light( color, intensity ) {
  22092. Object3D.call( this );
  22093. this.type = 'Light';
  22094. this.color = new Color( color );
  22095. this.intensity = intensity !== undefined ? intensity : 1;
  22096. this.receiveShadow = undefined;
  22097. }
  22098. Light.prototype = Object.assign( Object.create( Object3D.prototype ), {
  22099. constructor: Light,
  22100. isLight: true,
  22101. copy: function ( source ) {
  22102. Object3D.prototype.copy.call( this, source );
  22103. this.color.copy( source.color );
  22104. this.intensity = source.intensity;
  22105. return this;
  22106. },
  22107. toJSON: function ( meta ) {
  22108. var data = Object3D.prototype.toJSON.call( this, meta );
  22109. data.object.color = this.color.getHex();
  22110. data.object.intensity = this.intensity;
  22111. if ( this.groundColor !== undefined ) data.object.groundColor = this.groundColor.getHex();
  22112. if ( this.distance !== undefined ) data.object.distance = this.distance;
  22113. if ( this.angle !== undefined ) data.object.angle = this.angle;
  22114. if ( this.decay !== undefined ) data.object.decay = this.decay;
  22115. if ( this.penumbra !== undefined ) data.object.penumbra = this.penumbra;
  22116. if ( this.shadow !== undefined ) data.object.shadow = this.shadow.toJSON();
  22117. return data;
  22118. }
  22119. } );
  22120. /**
  22121. * @author alteredq / http://alteredqualia.com/
  22122. */
  22123. function HemisphereLight( skyColor, groundColor, intensity ) {
  22124. Light.call( this, skyColor, intensity );
  22125. this.type = 'HemisphereLight';
  22126. this.castShadow = undefined;
  22127. this.position.copy( Object3D.DefaultUp );
  22128. this.updateMatrix();
  22129. this.groundColor = new Color( groundColor );
  22130. }
  22131. HemisphereLight.prototype = Object.assign( Object.create( Light.prototype ), {
  22132. constructor: HemisphereLight,
  22133. isHemisphereLight: true,
  22134. copy: function ( source ) {
  22135. Light.prototype.copy.call( this, source );
  22136. this.groundColor.copy( source.groundColor );
  22137. return this;
  22138. }
  22139. } );
  22140. /**
  22141. * @author mrdoob / http://mrdoob.com/
  22142. */
  22143. function LightShadow( camera ) {
  22144. this.camera = camera;
  22145. this.bias = 0;
  22146. this.radius = 1;
  22147. this.mapSize = new Vector2( 512, 512 );
  22148. this.map = null;
  22149. this.matrix = new Matrix4();
  22150. }
  22151. Object.assign( LightShadow.prototype, {
  22152. copy: function ( source ) {
  22153. this.camera = source.camera.clone();
  22154. this.bias = source.bias;
  22155. this.radius = source.radius;
  22156. this.mapSize.copy( source.mapSize );
  22157. return this;
  22158. },
  22159. clone: function () {
  22160. return new this.constructor().copy( this );
  22161. },
  22162. toJSON: function () {
  22163. var object = {};
  22164. if ( this.bias !== 0 ) object.bias = this.bias;
  22165. if ( this.radius !== 1 ) object.radius = this.radius;
  22166. if ( this.mapSize.x !== 512 || this.mapSize.y !== 512 ) object.mapSize = this.mapSize.toArray();
  22167. object.camera = this.camera.toJSON( false ).object;
  22168. delete object.camera.matrix;
  22169. return object;
  22170. }
  22171. } );
  22172. /**
  22173. * @author mrdoob / http://mrdoob.com/
  22174. */
  22175. function SpotLightShadow() {
  22176. LightShadow.call( this, new PerspectiveCamera( 50, 1, 0.5, 500 ) );
  22177. }
  22178. SpotLightShadow.prototype = Object.assign( Object.create( LightShadow.prototype ), {
  22179. constructor: SpotLightShadow,
  22180. isSpotLightShadow: true,
  22181. update: function ( light ) {
  22182. var camera = this.camera;
  22183. var fov = _Math.RAD2DEG * 2 * light.angle;
  22184. var aspect = this.mapSize.width / this.mapSize.height;
  22185. var far = light.distance || camera.far;
  22186. if ( fov !== camera.fov || aspect !== camera.aspect || far !== camera.far ) {
  22187. camera.fov = fov;
  22188. camera.aspect = aspect;
  22189. camera.far = far;
  22190. camera.updateProjectionMatrix();
  22191. }
  22192. }
  22193. } );
  22194. /**
  22195. * @author alteredq / http://alteredqualia.com/
  22196. */
  22197. function SpotLight( color, intensity, distance, angle, penumbra, decay ) {
  22198. Light.call( this, color, intensity );
  22199. this.type = 'SpotLight';
  22200. this.position.copy( Object3D.DefaultUp );
  22201. this.updateMatrix();
  22202. this.target = new Object3D();
  22203. Object.defineProperty( this, 'power', {
  22204. get: function () {
  22205. // intensity = power per solid angle.
  22206. // ref: equation (17) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  22207. return this.intensity * Math.PI;
  22208. },
  22209. set: function ( power ) {
  22210. // intensity = power per solid angle.
  22211. // ref: equation (17) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  22212. this.intensity = power / Math.PI;
  22213. }
  22214. } );
  22215. this.distance = ( distance !== undefined ) ? distance : 0;
  22216. this.angle = ( angle !== undefined ) ? angle : Math.PI / 3;
  22217. this.penumbra = ( penumbra !== undefined ) ? penumbra : 0;
  22218. this.decay = ( decay !== undefined ) ? decay : 1; // for physically correct lights, should be 2.
  22219. this.shadow = new SpotLightShadow();
  22220. }
  22221. SpotLight.prototype = Object.assign( Object.create( Light.prototype ), {
  22222. constructor: SpotLight,
  22223. isSpotLight: true,
  22224. copy: function ( source ) {
  22225. Light.prototype.copy.call( this, source );
  22226. this.distance = source.distance;
  22227. this.angle = source.angle;
  22228. this.penumbra = source.penumbra;
  22229. this.decay = source.decay;
  22230. this.target = source.target.clone();
  22231. this.shadow = source.shadow.clone();
  22232. return this;
  22233. }
  22234. } );
  22235. /**
  22236. * @author mrdoob / http://mrdoob.com/
  22237. */
  22238. function PointLight( color, intensity, distance, decay ) {
  22239. Light.call( this, color, intensity );
  22240. this.type = 'PointLight';
  22241. Object.defineProperty( this, 'power', {
  22242. get: function () {
  22243. // intensity = power per solid angle.
  22244. // ref: equation (15) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  22245. return this.intensity * 4 * Math.PI;
  22246. },
  22247. set: function ( power ) {
  22248. // intensity = power per solid angle.
  22249. // ref: equation (15) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  22250. this.intensity = power / ( 4 * Math.PI );
  22251. }
  22252. } );
  22253. this.distance = ( distance !== undefined ) ? distance : 0;
  22254. this.decay = ( decay !== undefined ) ? decay : 1; // for physically correct lights, should be 2.
  22255. this.shadow = new LightShadow( new PerspectiveCamera( 90, 1, 0.5, 500 ) );
  22256. }
  22257. PointLight.prototype = Object.assign( Object.create( Light.prototype ), {
  22258. constructor: PointLight,
  22259. isPointLight: true,
  22260. copy: function ( source ) {
  22261. Light.prototype.copy.call( this, source );
  22262. this.distance = source.distance;
  22263. this.decay = source.decay;
  22264. this.shadow = source.shadow.clone();
  22265. return this;
  22266. }
  22267. } );
  22268. /**
  22269. * @author alteredq / http://alteredqualia.com/
  22270. * @author arose / http://github.com/arose
  22271. */
  22272. function OrthographicCamera( left, right, top, bottom, near, far ) {
  22273. Camera.call( this );
  22274. this.type = 'OrthographicCamera';
  22275. this.zoom = 1;
  22276. this.view = null;
  22277. this.left = ( left !== undefined ) ? left : - 1;
  22278. this.right = ( right !== undefined ) ? right : 1;
  22279. this.top = ( top !== undefined ) ? top : 1;
  22280. this.bottom = ( bottom !== undefined ) ? bottom : - 1;
  22281. this.near = ( near !== undefined ) ? near : 0.1;
  22282. this.far = ( far !== undefined ) ? far : 2000;
  22283. this.updateProjectionMatrix();
  22284. }
  22285. OrthographicCamera.prototype = Object.assign( Object.create( Camera.prototype ), {
  22286. constructor: OrthographicCamera,
  22287. isOrthographicCamera: true,
  22288. copy: function ( source, recursive ) {
  22289. Camera.prototype.copy.call( this, source, recursive );
  22290. this.left = source.left;
  22291. this.right = source.right;
  22292. this.top = source.top;
  22293. this.bottom = source.bottom;
  22294. this.near = source.near;
  22295. this.far = source.far;
  22296. this.zoom = source.zoom;
  22297. this.view = source.view === null ? null : Object.assign( {}, source.view );
  22298. return this;
  22299. },
  22300. setViewOffset: function ( fullWidth, fullHeight, x, y, width, height ) {
  22301. if ( this.view === null ) {
  22302. this.view = {
  22303. enabled: true,
  22304. fullWidth: 1,
  22305. fullHeight: 1,
  22306. offsetX: 0,
  22307. offsetY: 0,
  22308. width: 1,
  22309. height: 1
  22310. };
  22311. }
  22312. this.view.enabled = true;
  22313. this.view.fullWidth = fullWidth;
  22314. this.view.fullHeight = fullHeight;
  22315. this.view.offsetX = x;
  22316. this.view.offsetY = y;
  22317. this.view.width = width;
  22318. this.view.height = height;
  22319. this.updateProjectionMatrix();
  22320. },
  22321. clearViewOffset: function () {
  22322. if ( this.view !== null ) {
  22323. this.view.enabled = false;
  22324. }
  22325. this.updateProjectionMatrix();
  22326. },
  22327. updateProjectionMatrix: function () {
  22328. var dx = ( this.right - this.left ) / ( 2 * this.zoom );
  22329. var dy = ( this.top - this.bottom ) / ( 2 * this.zoom );
  22330. var cx = ( this.right + this.left ) / 2;
  22331. var cy = ( this.top + this.bottom ) / 2;
  22332. var left = cx - dx;
  22333. var right = cx + dx;
  22334. var top = cy + dy;
  22335. var bottom = cy - dy;
  22336. if ( this.view !== null && this.view.enabled ) {
  22337. var zoomW = this.zoom / ( this.view.width / this.view.fullWidth );
  22338. var zoomH = this.zoom / ( this.view.height / this.view.fullHeight );
  22339. var scaleW = ( this.right - this.left ) / this.view.width;
  22340. var scaleH = ( this.top - this.bottom ) / this.view.height;
  22341. left += scaleW * ( this.view.offsetX / zoomW );
  22342. right = left + scaleW * ( this.view.width / zoomW );
  22343. top -= scaleH * ( this.view.offsetY / zoomH );
  22344. bottom = top - scaleH * ( this.view.height / zoomH );
  22345. }
  22346. this.projectionMatrix.makeOrthographic( left, right, top, bottom, this.near, this.far );
  22347. this.projectionMatrixInverse.getInverse( this.projectionMatrix );
  22348. },
  22349. toJSON: function ( meta ) {
  22350. var data = Object3D.prototype.toJSON.call( this, meta );
  22351. data.object.zoom = this.zoom;
  22352. data.object.left = this.left;
  22353. data.object.right = this.right;
  22354. data.object.top = this.top;
  22355. data.object.bottom = this.bottom;
  22356. data.object.near = this.near;
  22357. data.object.far = this.far;
  22358. if ( this.view !== null ) data.object.view = Object.assign( {}, this.view );
  22359. return data;
  22360. }
  22361. } );
  22362. /**
  22363. * @author mrdoob / http://mrdoob.com/
  22364. */
  22365. function DirectionalLightShadow( ) {
  22366. LightShadow.call( this, new OrthographicCamera( - 5, 5, 5, - 5, 0.5, 500 ) );
  22367. }
  22368. DirectionalLightShadow.prototype = Object.assign( Object.create( LightShadow.prototype ), {
  22369. constructor: DirectionalLightShadow
  22370. } );
  22371. /**
  22372. * @author mrdoob / http://mrdoob.com/
  22373. * @author alteredq / http://alteredqualia.com/
  22374. */
  22375. function DirectionalLight( color, intensity ) {
  22376. Light.call( this, color, intensity );
  22377. this.type = 'DirectionalLight';
  22378. this.position.copy( Object3D.DefaultUp );
  22379. this.updateMatrix();
  22380. this.target = new Object3D();
  22381. this.shadow = new DirectionalLightShadow();
  22382. }
  22383. DirectionalLight.prototype = Object.assign( Object.create( Light.prototype ), {
  22384. constructor: DirectionalLight,
  22385. isDirectionalLight: true,
  22386. copy: function ( source ) {
  22387. Light.prototype.copy.call( this, source );
  22388. this.target = source.target.clone();
  22389. this.shadow = source.shadow.clone();
  22390. return this;
  22391. }
  22392. } );
  22393. /**
  22394. * @author mrdoob / http://mrdoob.com/
  22395. */
  22396. function AmbientLight( color, intensity ) {
  22397. Light.call( this, color, intensity );
  22398. this.type = 'AmbientLight';
  22399. this.castShadow = undefined;
  22400. }
  22401. AmbientLight.prototype = Object.assign( Object.create( Light.prototype ), {
  22402. constructor: AmbientLight,
  22403. isAmbientLight: true
  22404. } );
  22405. /**
  22406. * @author abelnation / http://github.com/abelnation
  22407. */
  22408. function RectAreaLight( color, intensity, width, height ) {
  22409. Light.call( this, color, intensity );
  22410. this.type = 'RectAreaLight';
  22411. this.width = ( width !== undefined ) ? width : 10;
  22412. this.height = ( height !== undefined ) ? height : 10;
  22413. }
  22414. RectAreaLight.prototype = Object.assign( Object.create( Light.prototype ), {
  22415. constructor: RectAreaLight,
  22416. isRectAreaLight: true,
  22417. copy: function ( source ) {
  22418. Light.prototype.copy.call( this, source );
  22419. this.width = source.width;
  22420. this.height = source.height;
  22421. return this;
  22422. },
  22423. toJSON: function ( meta ) {
  22424. var data = Light.prototype.toJSON.call( this, meta );
  22425. data.object.width = this.width;
  22426. data.object.height = this.height;
  22427. return data;
  22428. }
  22429. } );
  22430. /**
  22431. * @author mrdoob / http://mrdoob.com/
  22432. */
  22433. function MaterialLoader( manager ) {
  22434. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  22435. this.textures = {};
  22436. }
  22437. Object.assign( MaterialLoader.prototype, {
  22438. load: function ( url, onLoad, onProgress, onError ) {
  22439. var scope = this;
  22440. var loader = new FileLoader( scope.manager );
  22441. loader.setPath( scope.path );
  22442. loader.load( url, function ( text ) {
  22443. onLoad( scope.parse( JSON.parse( text ) ) );
  22444. }, onProgress, onError );
  22445. },
  22446. parse: function ( json ) {
  22447. var textures = this.textures;
  22448. function getTexture( name ) {
  22449. if ( textures[ name ] === undefined ) {
  22450. console.warn( 'THREE.MaterialLoader: Undefined texture', name );
  22451. }
  22452. return textures[ name ];
  22453. }
  22454. var material = new Materials[ json.type ]();
  22455. if ( json.uuid !== undefined ) material.uuid = json.uuid;
  22456. if ( json.name !== undefined ) material.name = json.name;
  22457. if ( json.color !== undefined ) material.color.setHex( json.color );
  22458. if ( json.roughness !== undefined ) material.roughness = json.roughness;
  22459. if ( json.metalness !== undefined ) material.metalness = json.metalness;
  22460. if ( json.emissive !== undefined ) material.emissive.setHex( json.emissive );
  22461. if ( json.specular !== undefined ) material.specular.setHex( json.specular );
  22462. if ( json.shininess !== undefined ) material.shininess = json.shininess;
  22463. if ( json.clearCoat !== undefined ) material.clearCoat = json.clearCoat;
  22464. if ( json.clearCoatRoughness !== undefined ) material.clearCoatRoughness = json.clearCoatRoughness;
  22465. if ( json.vertexColors !== undefined ) material.vertexColors = json.vertexColors;
  22466. if ( json.fog !== undefined ) material.fog = json.fog;
  22467. if ( json.flatShading !== undefined ) material.flatShading = json.flatShading;
  22468. if ( json.blending !== undefined ) material.blending = json.blending;
  22469. if ( json.combine !== undefined ) material.combine = json.combine;
  22470. if ( json.side !== undefined ) material.side = json.side;
  22471. if ( json.opacity !== undefined ) material.opacity = json.opacity;
  22472. if ( json.transparent !== undefined ) material.transparent = json.transparent;
  22473. if ( json.alphaTest !== undefined ) material.alphaTest = json.alphaTest;
  22474. if ( json.depthTest !== undefined ) material.depthTest = json.depthTest;
  22475. if ( json.depthWrite !== undefined ) material.depthWrite = json.depthWrite;
  22476. if ( json.colorWrite !== undefined ) material.colorWrite = json.colorWrite;
  22477. if ( json.wireframe !== undefined ) material.wireframe = json.wireframe;
  22478. if ( json.wireframeLinewidth !== undefined ) material.wireframeLinewidth = json.wireframeLinewidth;
  22479. if ( json.wireframeLinecap !== undefined ) material.wireframeLinecap = json.wireframeLinecap;
  22480. if ( json.wireframeLinejoin !== undefined ) material.wireframeLinejoin = json.wireframeLinejoin;
  22481. if ( json.rotation !== undefined ) material.rotation = json.rotation;
  22482. if ( json.linewidth !== 1 ) material.linewidth = json.linewidth;
  22483. if ( json.dashSize !== undefined ) material.dashSize = json.dashSize;
  22484. if ( json.gapSize !== undefined ) material.gapSize = json.gapSize;
  22485. if ( json.scale !== undefined ) material.scale = json.scale;
  22486. if ( json.polygonOffset !== undefined ) material.polygonOffset = json.polygonOffset;
  22487. if ( json.polygonOffsetFactor !== undefined ) material.polygonOffsetFactor = json.polygonOffsetFactor;
  22488. if ( json.polygonOffsetUnits !== undefined ) material.polygonOffsetUnits = json.polygonOffsetUnits;
  22489. if ( json.skinning !== undefined ) material.skinning = json.skinning;
  22490. if ( json.morphTargets !== undefined ) material.morphTargets = json.morphTargets;
  22491. if ( json.dithering !== undefined ) material.dithering = json.dithering;
  22492. if ( json.visible !== undefined ) material.visible = json.visible;
  22493. if ( json.userData !== undefined ) material.userData = json.userData;
  22494. // Shader Material
  22495. if ( json.uniforms !== undefined ) {
  22496. for ( var name in json.uniforms ) {
  22497. var uniform = json.uniforms[ name ];
  22498. material.uniforms[ name ] = {};
  22499. switch ( uniform.type ) {
  22500. case 't':
  22501. material.uniforms[ name ].value = getTexture( uniform.value );
  22502. break;
  22503. case 'c':
  22504. material.uniforms[ name ].value = new Color().setHex( uniform.value );
  22505. break;
  22506. case 'v2':
  22507. material.uniforms[ name ].value = new Vector2().fromArray( uniform.value );
  22508. break;
  22509. case 'v3':
  22510. material.uniforms[ name ].value = new Vector3().fromArray( uniform.value );
  22511. break;
  22512. case 'v4':
  22513. material.uniforms[ name ].value = new Vector4().fromArray( uniform.value );
  22514. break;
  22515. case 'm3':
  22516. material.uniforms[ name ].value = new Matrix3().fromArray( uniform.value );
  22517. case 'm4':
  22518. material.uniforms[ name ].value = new Matrix4().fromArray( uniform.value );
  22519. break;
  22520. default:
  22521. material.uniforms[ name ].value = uniform.value;
  22522. }
  22523. }
  22524. }
  22525. if ( json.defines !== undefined ) material.defines = json.defines;
  22526. if ( json.vertexShader !== undefined ) material.vertexShader = json.vertexShader;
  22527. if ( json.fragmentShader !== undefined ) material.fragmentShader = json.fragmentShader;
  22528. if ( json.extensions !== undefined ) {
  22529. for ( var key in json.extensions ) {
  22530. material.extensions[ key ] = json.extensions[ key ];
  22531. }
  22532. }
  22533. // Deprecated
  22534. if ( json.shading !== undefined ) material.flatShading = json.shading === 1; // THREE.FlatShading
  22535. // for PointsMaterial
  22536. if ( json.size !== undefined ) material.size = json.size;
  22537. if ( json.sizeAttenuation !== undefined ) material.sizeAttenuation = json.sizeAttenuation;
  22538. // maps
  22539. if ( json.map !== undefined ) material.map = getTexture( json.map );
  22540. if ( json.alphaMap !== undefined ) {
  22541. material.alphaMap = getTexture( json.alphaMap );
  22542. material.transparent = true;
  22543. }
  22544. if ( json.bumpMap !== undefined ) material.bumpMap = getTexture( json.bumpMap );
  22545. if ( json.bumpScale !== undefined ) material.bumpScale = json.bumpScale;
  22546. if ( json.normalMap !== undefined ) material.normalMap = getTexture( json.normalMap );
  22547. if ( json.normalMapType !== undefined ) material.normalMapType = json.normalMapType;
  22548. if ( json.normalScale !== undefined ) {
  22549. var normalScale = json.normalScale;
  22550. if ( Array.isArray( normalScale ) === false ) {
  22551. // Blender exporter used to export a scalar. See #7459
  22552. normalScale = [ normalScale, normalScale ];
  22553. }
  22554. material.normalScale = new Vector2().fromArray( normalScale );
  22555. }
  22556. if ( json.displacementMap !== undefined ) material.displacementMap = getTexture( json.displacementMap );
  22557. if ( json.displacementScale !== undefined ) material.displacementScale = json.displacementScale;
  22558. if ( json.displacementBias !== undefined ) material.displacementBias = json.displacementBias;
  22559. if ( json.roughnessMap !== undefined ) material.roughnessMap = getTexture( json.roughnessMap );
  22560. if ( json.metalnessMap !== undefined ) material.metalnessMap = getTexture( json.metalnessMap );
  22561. if ( json.emissiveMap !== undefined ) material.emissiveMap = getTexture( json.emissiveMap );
  22562. if ( json.emissiveIntensity !== undefined ) material.emissiveIntensity = json.emissiveIntensity;
  22563. if ( json.specularMap !== undefined ) material.specularMap = getTexture( json.specularMap );
  22564. if ( json.envMap !== undefined ) material.envMap = getTexture( json.envMap );
  22565. if ( json.envMapIntensity !== undefined ) material.envMapIntensity = json.envMapIntensity;
  22566. if ( json.reflectivity !== undefined ) material.reflectivity = json.reflectivity;
  22567. if ( json.lightMap !== undefined ) material.lightMap = getTexture( json.lightMap );
  22568. if ( json.lightMapIntensity !== undefined ) material.lightMapIntensity = json.lightMapIntensity;
  22569. if ( json.aoMap !== undefined ) material.aoMap = getTexture( json.aoMap );
  22570. if ( json.aoMapIntensity !== undefined ) material.aoMapIntensity = json.aoMapIntensity;
  22571. if ( json.gradientMap !== undefined ) material.gradientMap = getTexture( json.gradientMap );
  22572. return material;
  22573. },
  22574. setPath: function ( value ) {
  22575. this.path = value;
  22576. return this;
  22577. },
  22578. setTextures: function ( value ) {
  22579. this.textures = value;
  22580. return this;
  22581. }
  22582. } );
  22583. /**
  22584. * @author Don McCurdy / https://www.donmccurdy.com
  22585. */
  22586. var LoaderUtils = {
  22587. decodeText: function ( array ) {
  22588. if ( typeof TextDecoder !== 'undefined' ) {
  22589. return new TextDecoder().decode( array );
  22590. }
  22591. // Avoid the String.fromCharCode.apply(null, array) shortcut, which
  22592. // throws a "maximum call stack size exceeded" error for large arrays.
  22593. var s = '';
  22594. for ( var i = 0, il = array.length; i < il; i ++ ) {
  22595. // Implicitly assumes little-endian.
  22596. s += String.fromCharCode( array[ i ] );
  22597. }
  22598. // Merges multi-byte utf-8 characters.
  22599. return decodeURIComponent( escape( s ) );
  22600. },
  22601. extractUrlBase: function ( url ) {
  22602. var index = url.lastIndexOf( '/' );
  22603. if ( index === - 1 ) return './';
  22604. return url.substr( 0, index + 1 );
  22605. }
  22606. };
  22607. /**
  22608. * @author mrdoob / http://mrdoob.com/
  22609. */
  22610. function BufferGeometryLoader( manager ) {
  22611. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  22612. }
  22613. Object.assign( BufferGeometryLoader.prototype, {
  22614. load: function ( url, onLoad, onProgress, onError ) {
  22615. var scope = this;
  22616. var loader = new FileLoader( scope.manager );
  22617. loader.setPath( scope.path );
  22618. loader.load( url, function ( text ) {
  22619. onLoad( scope.parse( JSON.parse( text ) ) );
  22620. }, onProgress, onError );
  22621. },
  22622. parse: function ( json ) {
  22623. var geometry = new BufferGeometry();
  22624. var index = json.data.index;
  22625. if ( index !== undefined ) {
  22626. var typedArray = new TYPED_ARRAYS[ index.type ]( index.array );
  22627. geometry.setIndex( new BufferAttribute( typedArray, 1 ) );
  22628. }
  22629. var attributes = json.data.attributes;
  22630. for ( var key in attributes ) {
  22631. var attribute = attributes[ key ];
  22632. var typedArray = new TYPED_ARRAYS[ attribute.type ]( attribute.array );
  22633. var bufferAttribute = new BufferAttribute( typedArray, attribute.itemSize, attribute.normalized );
  22634. if ( attribute.name !== undefined ) bufferAttribute.name = attribute.name;
  22635. geometry.addAttribute( key, bufferAttribute );
  22636. }
  22637. var morphAttributes = json.data.morphAttributes;
  22638. if ( morphAttributes ) {
  22639. for ( var key in morphAttributes ) {
  22640. var attributeArray = morphAttributes[ key ];
  22641. var array = [];
  22642. for ( var i = 0, il = attributeArray.length; i < il; i ++ ) {
  22643. var attribute = attributeArray[ i ];
  22644. var typedArray = new TYPED_ARRAYS[ attribute.type ]( attribute.array );
  22645. var bufferAttribute = new BufferAttribute( typedArray, attribute.itemSize, attribute.normalized );
  22646. if ( attribute.name !== undefined ) bufferAttribute.name = attribute.name;
  22647. array.push( bufferAttribute );
  22648. }
  22649. geometry.morphAttributes[ key ] = array;
  22650. }
  22651. }
  22652. var groups = json.data.groups || json.data.drawcalls || json.data.offsets;
  22653. if ( groups !== undefined ) {
  22654. for ( var i = 0, n = groups.length; i !== n; ++ i ) {
  22655. var group = groups[ i ];
  22656. geometry.addGroup( group.start, group.count, group.materialIndex );
  22657. }
  22658. }
  22659. var boundingSphere = json.data.boundingSphere;
  22660. if ( boundingSphere !== undefined ) {
  22661. var center = new Vector3();
  22662. if ( boundingSphere.center !== undefined ) {
  22663. center.fromArray( boundingSphere.center );
  22664. }
  22665. geometry.boundingSphere = new Sphere( center, boundingSphere.radius );
  22666. }
  22667. if ( json.name ) geometry.name = json.name;
  22668. if ( json.userData ) geometry.userData = json.userData;
  22669. return geometry;
  22670. },
  22671. setPath: function ( value ) {
  22672. this.path = value;
  22673. return this;
  22674. }
  22675. } );
  22676. var TYPED_ARRAYS = {
  22677. Int8Array: Int8Array,
  22678. Uint8Array: Uint8Array,
  22679. // Workaround for IE11 pre KB2929437. See #11440
  22680. Uint8ClampedArray: typeof Uint8ClampedArray !== 'undefined' ? Uint8ClampedArray : Uint8Array,
  22681. Int16Array: Int16Array,
  22682. Uint16Array: Uint16Array,
  22683. Int32Array: Int32Array,
  22684. Uint32Array: Uint32Array,
  22685. Float32Array: Float32Array,
  22686. Float64Array: Float64Array
  22687. };
  22688. /**
  22689. * @author mrdoob / http://mrdoob.com/
  22690. */
  22691. function ObjectLoader( manager ) {
  22692. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  22693. this.resourcePath = '';
  22694. }
  22695. Object.assign( ObjectLoader.prototype, {
  22696. crossOrigin: 'anonymous',
  22697. load: function ( url, onLoad, onProgress, onError ) {
  22698. var scope = this;
  22699. var path = ( this.path === undefined ) ? LoaderUtils.extractUrlBase( url ) : this.path;
  22700. this.resourcePath = this.resourcePath || path;
  22701. var loader = new FileLoader( scope.manager );
  22702. loader.setPath( this.path );
  22703. loader.load( url, function ( text ) {
  22704. var json = null;
  22705. try {
  22706. json = JSON.parse( text );
  22707. } catch ( error ) {
  22708. if ( onError !== undefined ) onError( error );
  22709. console.error( 'THREE:ObjectLoader: Can\'t parse ' + url + '.', error.message );
  22710. return;
  22711. }
  22712. var metadata = json.metadata;
  22713. if ( metadata === undefined || metadata.type === undefined || metadata.type.toLowerCase() === 'geometry' ) {
  22714. console.error( 'THREE.ObjectLoader: Can\'t load ' + url );
  22715. return;
  22716. }
  22717. scope.parse( json, onLoad );
  22718. }, onProgress, onError );
  22719. },
  22720. setPath: function ( value ) {
  22721. this.path = value;
  22722. return this;
  22723. },
  22724. setResourcePath: function ( value ) {
  22725. this.resourcePath = value;
  22726. return this;
  22727. },
  22728. setCrossOrigin: function ( value ) {
  22729. this.crossOrigin = value;
  22730. return this;
  22731. },
  22732. parse: function ( json, onLoad ) {
  22733. var shapes = this.parseShape( json.shapes );
  22734. var geometries = this.parseGeometries( json.geometries, shapes );
  22735. var images = this.parseImages( json.images, function () {
  22736. if ( onLoad !== undefined ) onLoad( object );
  22737. } );
  22738. var textures = this.parseTextures( json.textures, images );
  22739. var materials = this.parseMaterials( json.materials, textures );
  22740. var object = this.parseObject( json.object, geometries, materials );
  22741. if ( json.animations ) {
  22742. object.animations = this.parseAnimations( json.animations );
  22743. }
  22744. if ( json.images === undefined || json.images.length === 0 ) {
  22745. if ( onLoad !== undefined ) onLoad( object );
  22746. }
  22747. return object;
  22748. },
  22749. parseShape: function ( json ) {
  22750. var shapes = {};
  22751. if ( json !== undefined ) {
  22752. for ( var i = 0, l = json.length; i < l; i ++ ) {
  22753. var shape = new Shape().fromJSON( json[ i ] );
  22754. shapes[ shape.uuid ] = shape;
  22755. }
  22756. }
  22757. return shapes;
  22758. },
  22759. parseGeometries: function ( json, shapes ) {
  22760. var geometries = {};
  22761. if ( json !== undefined ) {
  22762. var bufferGeometryLoader = new BufferGeometryLoader();
  22763. for ( var i = 0, l = json.length; i < l; i ++ ) {
  22764. var geometry;
  22765. var data = json[ i ];
  22766. switch ( data.type ) {
  22767. case 'PlaneGeometry':
  22768. case 'PlaneBufferGeometry':
  22769. geometry = new Geometries[ data.type ](
  22770. data.width,
  22771. data.height,
  22772. data.widthSegments,
  22773. data.heightSegments
  22774. );
  22775. break;
  22776. case 'BoxGeometry':
  22777. case 'BoxBufferGeometry':
  22778. case 'CubeGeometry': // backwards compatible
  22779. geometry = new Geometries[ data.type ](
  22780. data.width,
  22781. data.height,
  22782. data.depth,
  22783. data.widthSegments,
  22784. data.heightSegments,
  22785. data.depthSegments
  22786. );
  22787. break;
  22788. case 'CircleGeometry':
  22789. case 'CircleBufferGeometry':
  22790. geometry = new Geometries[ data.type ](
  22791. data.radius,
  22792. data.segments,
  22793. data.thetaStart,
  22794. data.thetaLength
  22795. );
  22796. break;
  22797. case 'CylinderGeometry':
  22798. case 'CylinderBufferGeometry':
  22799. geometry = new Geometries[ data.type ](
  22800. data.radiusTop,
  22801. data.radiusBottom,
  22802. data.height,
  22803. data.radialSegments,
  22804. data.heightSegments,
  22805. data.openEnded,
  22806. data.thetaStart,
  22807. data.thetaLength
  22808. );
  22809. break;
  22810. case 'ConeGeometry':
  22811. case 'ConeBufferGeometry':
  22812. geometry = new Geometries[ data.type ](
  22813. data.radius,
  22814. data.height,
  22815. data.radialSegments,
  22816. data.heightSegments,
  22817. data.openEnded,
  22818. data.thetaStart,
  22819. data.thetaLength
  22820. );
  22821. break;
  22822. case 'SphereGeometry':
  22823. case 'SphereBufferGeometry':
  22824. geometry = new Geometries[ data.type ](
  22825. data.radius,
  22826. data.widthSegments,
  22827. data.heightSegments,
  22828. data.phiStart,
  22829. data.phiLength,
  22830. data.thetaStart,
  22831. data.thetaLength
  22832. );
  22833. break;
  22834. case 'DodecahedronGeometry':
  22835. case 'DodecahedronBufferGeometry':
  22836. case 'IcosahedronGeometry':
  22837. case 'IcosahedronBufferGeometry':
  22838. case 'OctahedronGeometry':
  22839. case 'OctahedronBufferGeometry':
  22840. case 'TetrahedronGeometry':
  22841. case 'TetrahedronBufferGeometry':
  22842. geometry = new Geometries[ data.type ](
  22843. data.radius,
  22844. data.detail
  22845. );
  22846. break;
  22847. case 'RingGeometry':
  22848. case 'RingBufferGeometry':
  22849. geometry = new Geometries[ data.type ](
  22850. data.innerRadius,
  22851. data.outerRadius,
  22852. data.thetaSegments,
  22853. data.phiSegments,
  22854. data.thetaStart,
  22855. data.thetaLength
  22856. );
  22857. break;
  22858. case 'TorusGeometry':
  22859. case 'TorusBufferGeometry':
  22860. geometry = new Geometries[ data.type ](
  22861. data.radius,
  22862. data.tube,
  22863. data.radialSegments,
  22864. data.tubularSegments,
  22865. data.arc
  22866. );
  22867. break;
  22868. case 'TorusKnotGeometry':
  22869. case 'TorusKnotBufferGeometry':
  22870. geometry = new Geometries[ data.type ](
  22871. data.radius,
  22872. data.tube,
  22873. data.tubularSegments,
  22874. data.radialSegments,
  22875. data.p,
  22876. data.q
  22877. );
  22878. break;
  22879. case 'TubeGeometry':
  22880. case 'TubeBufferGeometry':
  22881. // This only works for built-in curves (e.g. CatmullRomCurve3).
  22882. // User defined curves or instances of CurvePath will not be deserialized.
  22883. geometry = new Geometries[ data.type ](
  22884. new Curves[ data.path.type ]().fromJSON( data.path ),
  22885. data.tubularSegments,
  22886. data.radius,
  22887. data.radialSegments,
  22888. data.closed
  22889. );
  22890. break;
  22891. case 'LatheGeometry':
  22892. case 'LatheBufferGeometry':
  22893. geometry = new Geometries[ data.type ](
  22894. data.points,
  22895. data.segments,
  22896. data.phiStart,
  22897. data.phiLength
  22898. );
  22899. break;
  22900. case 'PolyhedronGeometry':
  22901. case 'PolyhedronBufferGeometry':
  22902. geometry = new Geometries[ data.type ](
  22903. data.vertices,
  22904. data.indices,
  22905. data.radius,
  22906. data.details
  22907. );
  22908. break;
  22909. case 'ShapeGeometry':
  22910. case 'ShapeBufferGeometry':
  22911. var geometryShapes = [];
  22912. for ( var j = 0, jl = data.shapes.length; j < jl; j ++ ) {
  22913. var shape = shapes[ data.shapes[ j ] ];
  22914. geometryShapes.push( shape );
  22915. }
  22916. geometry = new Geometries[ data.type ](
  22917. geometryShapes,
  22918. data.curveSegments
  22919. );
  22920. break;
  22921. case 'ExtrudeGeometry':
  22922. case 'ExtrudeBufferGeometry':
  22923. var geometryShapes = [];
  22924. for ( var j = 0, jl = data.shapes.length; j < jl; j ++ ) {
  22925. var shape = shapes[ data.shapes[ j ] ];
  22926. geometryShapes.push( shape );
  22927. }
  22928. var extrudePath = data.options.extrudePath;
  22929. if ( extrudePath !== undefined ) {
  22930. data.options.extrudePath = new Curves[ extrudePath.type ]().fromJSON( extrudePath );
  22931. }
  22932. geometry = new Geometries[ data.type ](
  22933. geometryShapes,
  22934. data.options
  22935. );
  22936. break;
  22937. case 'BufferGeometry':
  22938. geometry = bufferGeometryLoader.parse( data );
  22939. break;
  22940. case 'Geometry':
  22941. if ( 'THREE' in window && 'LegacyJSONLoader' in THREE ) {
  22942. var geometryLoader = new THREE.LegacyJSONLoader();
  22943. geometry = geometryLoader.parse( data, this.resourcePath ).geometry;
  22944. } else {
  22945. console.error( 'THREE.ObjectLoader: You have to import LegacyJSONLoader in order load geometry data of type "Geometry".' );
  22946. }
  22947. break;
  22948. default:
  22949. console.warn( 'THREE.ObjectLoader: Unsupported geometry type "' + data.type + '"' );
  22950. continue;
  22951. }
  22952. geometry.uuid = data.uuid;
  22953. if ( data.name !== undefined ) geometry.name = data.name;
  22954. if ( geometry.isBufferGeometry === true && data.userData !== undefined ) geometry.userData = data.userData;
  22955. geometries[ data.uuid ] = geometry;
  22956. }
  22957. }
  22958. return geometries;
  22959. },
  22960. parseMaterials: function ( json, textures ) {
  22961. var cache = {}; // MultiMaterial
  22962. var materials = {};
  22963. if ( json !== undefined ) {
  22964. var loader = new MaterialLoader();
  22965. loader.setTextures( textures );
  22966. for ( var i = 0, l = json.length; i < l; i ++ ) {
  22967. var data = json[ i ];
  22968. if ( data.type === 'MultiMaterial' ) {
  22969. // Deprecated
  22970. var array = [];
  22971. for ( var j = 0; j < data.materials.length; j ++ ) {
  22972. var material = data.materials[ j ];
  22973. if ( cache[ material.uuid ] === undefined ) {
  22974. cache[ material.uuid ] = loader.parse( material );
  22975. }
  22976. array.push( cache[ material.uuid ] );
  22977. }
  22978. materials[ data.uuid ] = array;
  22979. } else {
  22980. if ( cache[ data.uuid ] === undefined ) {
  22981. cache[ data.uuid ] = loader.parse( data );
  22982. }
  22983. materials[ data.uuid ] = cache[ data.uuid ];
  22984. }
  22985. }
  22986. }
  22987. return materials;
  22988. },
  22989. parseAnimations: function ( json ) {
  22990. var animations = [];
  22991. for ( var i = 0; i < json.length; i ++ ) {
  22992. var data = json[ i ];
  22993. var clip = AnimationClip.parse( data );
  22994. if ( data.uuid !== undefined ) clip.uuid = data.uuid;
  22995. animations.push( clip );
  22996. }
  22997. return animations;
  22998. },
  22999. parseImages: function ( json, onLoad ) {
  23000. var scope = this;
  23001. var images = {};
  23002. function loadImage( url ) {
  23003. scope.manager.itemStart( url );
  23004. return loader.load( url, function () {
  23005. scope.manager.itemEnd( url );
  23006. }, undefined, function () {
  23007. scope.manager.itemError( url );
  23008. scope.manager.itemEnd( url );
  23009. } );
  23010. }
  23011. if ( json !== undefined && json.length > 0 ) {
  23012. var manager = new LoadingManager( onLoad );
  23013. var loader = new ImageLoader( manager );
  23014. loader.setCrossOrigin( this.crossOrigin );
  23015. for ( var i = 0, il = json.length; i < il; i ++ ) {
  23016. var image = json[ i ];
  23017. var url = image.url;
  23018. if ( Array.isArray( url ) ) {
  23019. // load array of images e.g CubeTexture
  23020. images[ image.uuid ] = [];
  23021. for ( var j = 0, jl = url.length; j < jl; j ++ ) {
  23022. var currentUrl = url[ j ];
  23023. var path = /^(\/\/)|([a-z]+:(\/\/)?)/i.test( currentUrl ) ? currentUrl : scope.resourcePath + currentUrl;
  23024. images[ image.uuid ].push( loadImage( path ) );
  23025. }
  23026. } else {
  23027. // load single image
  23028. var path = /^(\/\/)|([a-z]+:(\/\/)?)/i.test( image.url ) ? image.url : scope.resourcePath + image.url;
  23029. images[ image.uuid ] = loadImage( path );
  23030. }
  23031. }
  23032. }
  23033. return images;
  23034. },
  23035. parseTextures: function ( json, images ) {
  23036. function parseConstant( value, type ) {
  23037. if ( typeof value === 'number' ) return value;
  23038. console.warn( 'THREE.ObjectLoader.parseTexture: Constant should be in numeric form.', value );
  23039. return type[ value ];
  23040. }
  23041. var textures = {};
  23042. if ( json !== undefined ) {
  23043. for ( var i = 0, l = json.length; i < l; i ++ ) {
  23044. var data = json[ i ];
  23045. if ( data.image === undefined ) {
  23046. console.warn( 'THREE.ObjectLoader: No "image" specified for', data.uuid );
  23047. }
  23048. if ( images[ data.image ] === undefined ) {
  23049. console.warn( 'THREE.ObjectLoader: Undefined image', data.image );
  23050. }
  23051. var texture;
  23052. if ( Array.isArray( images[ data.image ] ) ) {
  23053. texture = new CubeTexture( images[ data.image ] );
  23054. } else {
  23055. texture = new Texture( images[ data.image ] );
  23056. }
  23057. texture.needsUpdate = true;
  23058. texture.uuid = data.uuid;
  23059. if ( data.name !== undefined ) texture.name = data.name;
  23060. if ( data.mapping !== undefined ) texture.mapping = parseConstant( data.mapping, TEXTURE_MAPPING );
  23061. if ( data.offset !== undefined ) texture.offset.fromArray( data.offset );
  23062. if ( data.repeat !== undefined ) texture.repeat.fromArray( data.repeat );
  23063. if ( data.center !== undefined ) texture.center.fromArray( data.center );
  23064. if ( data.rotation !== undefined ) texture.rotation = data.rotation;
  23065. if ( data.wrap !== undefined ) {
  23066. texture.wrapS = parseConstant( data.wrap[ 0 ], TEXTURE_WRAPPING );
  23067. texture.wrapT = parseConstant( data.wrap[ 1 ], TEXTURE_WRAPPING );
  23068. }
  23069. if ( data.format !== undefined ) texture.format = data.format;
  23070. if ( data.type !== undefined ) texture.type = data.type;
  23071. if ( data.encoding !== undefined ) texture.encoding = data.encoding;
  23072. if ( data.minFilter !== undefined ) texture.minFilter = parseConstant( data.minFilter, TEXTURE_FILTER );
  23073. if ( data.magFilter !== undefined ) texture.magFilter = parseConstant( data.magFilter, TEXTURE_FILTER );
  23074. if ( data.anisotropy !== undefined ) texture.anisotropy = data.anisotropy;
  23075. if ( data.flipY !== undefined ) texture.flipY = data.flipY;
  23076. if ( data.premultiplyAlpha !== undefined ) texture.premultiplyAlpha = data.premultiplyAlpha;
  23077. if ( data.unpackAlignment !== undefined ) texture.unpackAlignment = data.unpackAlignment;
  23078. textures[ data.uuid ] = texture;
  23079. }
  23080. }
  23081. return textures;
  23082. },
  23083. parseObject: function ( data, geometries, materials ) {
  23084. var object;
  23085. function getGeometry( name ) {
  23086. if ( geometries[ name ] === undefined ) {
  23087. console.warn( 'THREE.ObjectLoader: Undefined geometry', name );
  23088. }
  23089. return geometries[ name ];
  23090. }
  23091. function getMaterial( name ) {
  23092. if ( name === undefined ) return undefined;
  23093. if ( Array.isArray( name ) ) {
  23094. var array = [];
  23095. for ( var i = 0, l = name.length; i < l; i ++ ) {
  23096. var uuid = name[ i ];
  23097. if ( materials[ uuid ] === undefined ) {
  23098. console.warn( 'THREE.ObjectLoader: Undefined material', uuid );
  23099. }
  23100. array.push( materials[ uuid ] );
  23101. }
  23102. return array;
  23103. }
  23104. if ( materials[ name ] === undefined ) {
  23105. console.warn( 'THREE.ObjectLoader: Undefined material', name );
  23106. }
  23107. return materials[ name ];
  23108. }
  23109. switch ( data.type ) {
  23110. case 'Scene':
  23111. object = new Scene();
  23112. if ( data.background !== undefined ) {
  23113. if ( Number.isInteger( data.background ) ) {
  23114. object.background = new Color( data.background );
  23115. }
  23116. }
  23117. if ( data.fog !== undefined ) {
  23118. if ( data.fog.type === 'Fog' ) {
  23119. object.fog = new Fog( data.fog.color, data.fog.near, data.fog.far );
  23120. } else if ( data.fog.type === 'FogExp2' ) {
  23121. object.fog = new FogExp2( data.fog.color, data.fog.density );
  23122. }
  23123. }
  23124. break;
  23125. case 'PerspectiveCamera':
  23126. object = new PerspectiveCamera( data.fov, data.aspect, data.near, data.far );
  23127. if ( data.focus !== undefined ) object.focus = data.focus;
  23128. if ( data.zoom !== undefined ) object.zoom = data.zoom;
  23129. if ( data.filmGauge !== undefined ) object.filmGauge = data.filmGauge;
  23130. if ( data.filmOffset !== undefined ) object.filmOffset = data.filmOffset;
  23131. if ( data.view !== undefined ) object.view = Object.assign( {}, data.view );
  23132. break;
  23133. case 'OrthographicCamera':
  23134. object = new OrthographicCamera( data.left, data.right, data.top, data.bottom, data.near, data.far );
  23135. if ( data.zoom !== undefined ) object.zoom = data.zoom;
  23136. if ( data.view !== undefined ) object.view = Object.assign( {}, data.view );
  23137. break;
  23138. case 'AmbientLight':
  23139. object = new AmbientLight( data.color, data.intensity );
  23140. break;
  23141. case 'DirectionalLight':
  23142. object = new DirectionalLight( data.color, data.intensity );
  23143. break;
  23144. case 'PointLight':
  23145. object = new PointLight( data.color, data.intensity, data.distance, data.decay );
  23146. break;
  23147. case 'RectAreaLight':
  23148. object = new RectAreaLight( data.color, data.intensity, data.width, data.height );
  23149. break;
  23150. case 'SpotLight':
  23151. object = new SpotLight( data.color, data.intensity, data.distance, data.angle, data.penumbra, data.decay );
  23152. break;
  23153. case 'HemisphereLight':
  23154. object = new HemisphereLight( data.color, data.groundColor, data.intensity );
  23155. break;
  23156. case 'SkinnedMesh':
  23157. console.warn( 'THREE.ObjectLoader.parseObject() does not support SkinnedMesh yet.' );
  23158. case 'Mesh':
  23159. var geometry = getGeometry( data.geometry );
  23160. var material = getMaterial( data.material );
  23161. if ( geometry.bones && geometry.bones.length > 0 ) {
  23162. object = new SkinnedMesh( geometry, material );
  23163. } else {
  23164. object = new Mesh( geometry, material );
  23165. }
  23166. if ( data.drawMode !== undefined ) object.setDrawMode( data.drawMode );
  23167. break;
  23168. case 'LOD':
  23169. object = new LOD();
  23170. break;
  23171. case 'Line':
  23172. object = new Line( getGeometry( data.geometry ), getMaterial( data.material ), data.mode );
  23173. break;
  23174. case 'LineLoop':
  23175. object = new LineLoop( getGeometry( data.geometry ), getMaterial( data.material ) );
  23176. break;
  23177. case 'LineSegments':
  23178. object = new LineSegments( getGeometry( data.geometry ), getMaterial( data.material ) );
  23179. break;
  23180. case 'PointCloud':
  23181. case 'Points':
  23182. object = new Points( getGeometry( data.geometry ), getMaterial( data.material ) );
  23183. break;
  23184. case 'Sprite':
  23185. object = new Sprite( getMaterial( data.material ) );
  23186. break;
  23187. case 'Group':
  23188. object = new Group();
  23189. break;
  23190. default:
  23191. object = new Object3D();
  23192. }
  23193. object.uuid = data.uuid;
  23194. if ( data.name !== undefined ) object.name = data.name;
  23195. if ( data.matrix !== undefined ) {
  23196. object.matrix.fromArray( data.matrix );
  23197. if ( data.matrixAutoUpdate !== undefined ) object.matrixAutoUpdate = data.matrixAutoUpdate;
  23198. if ( object.matrixAutoUpdate ) object.matrix.decompose( object.position, object.quaternion, object.scale );
  23199. } else {
  23200. if ( data.position !== undefined ) object.position.fromArray( data.position );
  23201. if ( data.rotation !== undefined ) object.rotation.fromArray( data.rotation );
  23202. if ( data.quaternion !== undefined ) object.quaternion.fromArray( data.quaternion );
  23203. if ( data.scale !== undefined ) object.scale.fromArray( data.scale );
  23204. }
  23205. if ( data.castShadow !== undefined ) object.castShadow = data.castShadow;
  23206. if ( data.receiveShadow !== undefined ) object.receiveShadow = data.receiveShadow;
  23207. if ( data.shadow ) {
  23208. if ( data.shadow.bias !== undefined ) object.shadow.bias = data.shadow.bias;
  23209. if ( data.shadow.radius !== undefined ) object.shadow.radius = data.shadow.radius;
  23210. if ( data.shadow.mapSize !== undefined ) object.shadow.mapSize.fromArray( data.shadow.mapSize );
  23211. if ( data.shadow.camera !== undefined ) object.shadow.camera = this.parseObject( data.shadow.camera );
  23212. }
  23213. if ( data.visible !== undefined ) object.visible = data.visible;
  23214. if ( data.frustumCulled !== undefined ) object.frustumCulled = data.frustumCulled;
  23215. if ( data.renderOrder !== undefined ) object.renderOrder = data.renderOrder;
  23216. if ( data.userData !== undefined ) object.userData = data.userData;
  23217. if ( data.layers !== undefined ) object.layers.mask = data.layers;
  23218. if ( data.children !== undefined ) {
  23219. var children = data.children;
  23220. for ( var i = 0; i < children.length; i ++ ) {
  23221. object.add( this.parseObject( children[ i ], geometries, materials ) );
  23222. }
  23223. }
  23224. if ( data.type === 'LOD' ) {
  23225. var levels = data.levels;
  23226. for ( var l = 0; l < levels.length; l ++ ) {
  23227. var level = levels[ l ];
  23228. var child = object.getObjectByProperty( 'uuid', level.object );
  23229. if ( child !== undefined ) {
  23230. object.addLevel( child, level.distance );
  23231. }
  23232. }
  23233. }
  23234. return object;
  23235. }
  23236. } );
  23237. var TEXTURE_MAPPING = {
  23238. UVMapping: UVMapping,
  23239. CubeReflectionMapping: CubeReflectionMapping,
  23240. CubeRefractionMapping: CubeRefractionMapping,
  23241. EquirectangularReflectionMapping: EquirectangularReflectionMapping,
  23242. EquirectangularRefractionMapping: EquirectangularRefractionMapping,
  23243. SphericalReflectionMapping: SphericalReflectionMapping,
  23244. CubeUVReflectionMapping: CubeUVReflectionMapping,
  23245. CubeUVRefractionMapping: CubeUVRefractionMapping
  23246. };
  23247. var TEXTURE_WRAPPING = {
  23248. RepeatWrapping: RepeatWrapping,
  23249. ClampToEdgeWrapping: ClampToEdgeWrapping,
  23250. MirroredRepeatWrapping: MirroredRepeatWrapping
  23251. };
  23252. var TEXTURE_FILTER = {
  23253. NearestFilter: NearestFilter,
  23254. NearestMipMapNearestFilter: NearestMipMapNearestFilter,
  23255. NearestMipMapLinearFilter: NearestMipMapLinearFilter,
  23256. LinearFilter: LinearFilter,
  23257. LinearMipMapNearestFilter: LinearMipMapNearestFilter,
  23258. LinearMipMapLinearFilter: LinearMipMapLinearFilter
  23259. };
  23260. /**
  23261. * @author thespite / http://clicktorelease.com/
  23262. */
  23263. function ImageBitmapLoader( manager ) {
  23264. if ( typeof createImageBitmap === 'undefined' ) {
  23265. console.warn( 'THREE.ImageBitmapLoader: createImageBitmap() not supported.' );
  23266. }
  23267. if ( typeof fetch === 'undefined' ) {
  23268. console.warn( 'THREE.ImageBitmapLoader: fetch() not supported.' );
  23269. }
  23270. this.manager = manager !== undefined ? manager : DefaultLoadingManager;
  23271. this.options = undefined;
  23272. }
  23273. ImageBitmapLoader.prototype = {
  23274. constructor: ImageBitmapLoader,
  23275. setOptions: function setOptions( options ) {
  23276. this.options = options;
  23277. return this;
  23278. },
  23279. load: function ( url, onLoad, onProgress, onError ) {
  23280. if ( url === undefined ) url = '';
  23281. if ( this.path !== undefined ) url = this.path + url;
  23282. url = this.manager.resolveURL( url );
  23283. var scope = this;
  23284. var cached = Cache.get( url );
  23285. if ( cached !== undefined ) {
  23286. scope.manager.itemStart( url );
  23287. setTimeout( function () {
  23288. if ( onLoad ) onLoad( cached );
  23289. scope.manager.itemEnd( url );
  23290. }, 0 );
  23291. return cached;
  23292. }
  23293. fetch( url ).then( function ( res ) {
  23294. return res.blob();
  23295. } ).then( function ( blob ) {
  23296. return createImageBitmap( blob, scope.options );
  23297. } ).then( function ( imageBitmap ) {
  23298. Cache.add( url, imageBitmap );
  23299. if ( onLoad ) onLoad( imageBitmap );
  23300. scope.manager.itemEnd( url );
  23301. } ).catch( function ( e ) {
  23302. if ( onError ) onError( e );
  23303. scope.manager.itemError( url );
  23304. scope.manager.itemEnd( url );
  23305. } );
  23306. scope.manager.itemStart( url );
  23307. },
  23308. setCrossOrigin: function ( /* value */ ) {
  23309. return this;
  23310. },
  23311. setPath: function ( value ) {
  23312. this.path = value;
  23313. return this;
  23314. }
  23315. };
  23316. /**
  23317. * @author zz85 / http://www.lab4games.net/zz85/blog
  23318. * minimal class for proxing functions to Path. Replaces old "extractSubpaths()"
  23319. **/
  23320. function ShapePath() {
  23321. this.type = 'ShapePath';
  23322. this.color = new Color();
  23323. this.subPaths = [];
  23324. this.currentPath = null;
  23325. }
  23326. Object.assign( ShapePath.prototype, {
  23327. moveTo: function ( x, y ) {
  23328. this.currentPath = new Path();
  23329. this.subPaths.push( this.currentPath );
  23330. this.currentPath.moveTo( x, y );
  23331. },
  23332. lineTo: function ( x, y ) {
  23333. this.currentPath.lineTo( x, y );
  23334. },
  23335. quadraticCurveTo: function ( aCPx, aCPy, aX, aY ) {
  23336. this.currentPath.quadraticCurveTo( aCPx, aCPy, aX, aY );
  23337. },
  23338. bezierCurveTo: function ( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY ) {
  23339. this.currentPath.bezierCurveTo( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY );
  23340. },
  23341. splineThru: function ( pts ) {
  23342. this.currentPath.splineThru( pts );
  23343. },
  23344. toShapes: function ( isCCW, noHoles ) {
  23345. function toShapesNoHoles( inSubpaths ) {
  23346. var shapes = [];
  23347. for ( var i = 0, l = inSubpaths.length; i < l; i ++ ) {
  23348. var tmpPath = inSubpaths[ i ];
  23349. var tmpShape = new Shape();
  23350. tmpShape.curves = tmpPath.curves;
  23351. shapes.push( tmpShape );
  23352. }
  23353. return shapes;
  23354. }
  23355. function isPointInsidePolygon( inPt, inPolygon ) {
  23356. var polyLen = inPolygon.length;
  23357. // inPt on polygon contour => immediate success or
  23358. // toggling of inside/outside at every single! intersection point of an edge
  23359. // with the horizontal line through inPt, left of inPt
  23360. // not counting lowerY endpoints of edges and whole edges on that line
  23361. var inside = false;
  23362. for ( var p = polyLen - 1, q = 0; q < polyLen; p = q ++ ) {
  23363. var edgeLowPt = inPolygon[ p ];
  23364. var edgeHighPt = inPolygon[ q ];
  23365. var edgeDx = edgeHighPt.x - edgeLowPt.x;
  23366. var edgeDy = edgeHighPt.y - edgeLowPt.y;
  23367. if ( Math.abs( edgeDy ) > Number.EPSILON ) {
  23368. // not parallel
  23369. if ( edgeDy < 0 ) {
  23370. edgeLowPt = inPolygon[ q ]; edgeDx = - edgeDx;
  23371. edgeHighPt = inPolygon[ p ]; edgeDy = - edgeDy;
  23372. }
  23373. if ( ( inPt.y < edgeLowPt.y ) || ( inPt.y > edgeHighPt.y ) ) continue;
  23374. if ( inPt.y === edgeLowPt.y ) {
  23375. if ( inPt.x === edgeLowPt.x ) return true; // inPt is on contour ?
  23376. // continue; // no intersection or edgeLowPt => doesn't count !!!
  23377. } else {
  23378. var perpEdge = edgeDy * ( inPt.x - edgeLowPt.x ) - edgeDx * ( inPt.y - edgeLowPt.y );
  23379. if ( perpEdge === 0 ) return true; // inPt is on contour ?
  23380. if ( perpEdge < 0 ) continue;
  23381. inside = ! inside; // true intersection left of inPt
  23382. }
  23383. } else {
  23384. // parallel or collinear
  23385. if ( inPt.y !== edgeLowPt.y ) continue; // parallel
  23386. // edge lies on the same horizontal line as inPt
  23387. if ( ( ( edgeHighPt.x <= inPt.x ) && ( inPt.x <= edgeLowPt.x ) ) ||
  23388. ( ( edgeLowPt.x <= inPt.x ) && ( inPt.x <= edgeHighPt.x ) ) ) return true; // inPt: Point on contour !
  23389. // continue;
  23390. }
  23391. }
  23392. return inside;
  23393. }
  23394. var isClockWise = ShapeUtils.isClockWise;
  23395. var subPaths = this.subPaths;
  23396. if ( subPaths.length === 0 ) return [];
  23397. if ( noHoles === true ) return toShapesNoHoles( subPaths );
  23398. var solid, tmpPath, tmpShape, shapes = [];
  23399. if ( subPaths.length === 1 ) {
  23400. tmpPath = subPaths[ 0 ];
  23401. tmpShape = new Shape();
  23402. tmpShape.curves = tmpPath.curves;
  23403. shapes.push( tmpShape );
  23404. return shapes;
  23405. }
  23406. var holesFirst = ! isClockWise( subPaths[ 0 ].getPoints() );
  23407. holesFirst = isCCW ? ! holesFirst : holesFirst;
  23408. // console.log("Holes first", holesFirst);
  23409. var betterShapeHoles = [];
  23410. var newShapes = [];
  23411. var newShapeHoles = [];
  23412. var mainIdx = 0;
  23413. var tmpPoints;
  23414. newShapes[ mainIdx ] = undefined;
  23415. newShapeHoles[ mainIdx ] = [];
  23416. for ( var i = 0, l = subPaths.length; i < l; i ++ ) {
  23417. tmpPath = subPaths[ i ];
  23418. tmpPoints = tmpPath.getPoints();
  23419. solid = isClockWise( tmpPoints );
  23420. solid = isCCW ? ! solid : solid;
  23421. if ( solid ) {
  23422. if ( ( ! holesFirst ) && ( newShapes[ mainIdx ] ) ) mainIdx ++;
  23423. newShapes[ mainIdx ] = { s: new Shape(), p: tmpPoints };
  23424. newShapes[ mainIdx ].s.curves = tmpPath.curves;
  23425. if ( holesFirst ) mainIdx ++;
  23426. newShapeHoles[ mainIdx ] = [];
  23427. //console.log('cw', i);
  23428. } else {
  23429. newShapeHoles[ mainIdx ].push( { h: tmpPath, p: tmpPoints[ 0 ] } );
  23430. //console.log('ccw', i);
  23431. }
  23432. }
  23433. // only Holes? -> probably all Shapes with wrong orientation
  23434. if ( ! newShapes[ 0 ] ) return toShapesNoHoles( subPaths );
  23435. if ( newShapes.length > 1 ) {
  23436. var ambiguous = false;
  23437. var toChange = [];
  23438. for ( var sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx ++ ) {
  23439. betterShapeHoles[ sIdx ] = [];
  23440. }
  23441. for ( var sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx ++ ) {
  23442. var sho = newShapeHoles[ sIdx ];
  23443. for ( var hIdx = 0; hIdx < sho.length; hIdx ++ ) {
  23444. var ho = sho[ hIdx ];
  23445. var hole_unassigned = true;
  23446. for ( var s2Idx = 0; s2Idx < newShapes.length; s2Idx ++ ) {
  23447. if ( isPointInsidePolygon( ho.p, newShapes[ s2Idx ].p ) ) {
  23448. if ( sIdx !== s2Idx ) toChange.push( { froms: sIdx, tos: s2Idx, hole: hIdx } );
  23449. if ( hole_unassigned ) {
  23450. hole_unassigned = false;
  23451. betterShapeHoles[ s2Idx ].push( ho );
  23452. } else {
  23453. ambiguous = true;
  23454. }
  23455. }
  23456. }
  23457. if ( hole_unassigned ) {
  23458. betterShapeHoles[ sIdx ].push( ho );
  23459. }
  23460. }
  23461. }
  23462. // console.log("ambiguous: ", ambiguous);
  23463. if ( toChange.length > 0 ) {
  23464. // console.log("to change: ", toChange);
  23465. if ( ! ambiguous ) newShapeHoles = betterShapeHoles;
  23466. }
  23467. }
  23468. var tmpHoles;
  23469. for ( var i = 0, il = newShapes.length; i < il; i ++ ) {
  23470. tmpShape = newShapes[ i ].s;
  23471. shapes.push( tmpShape );
  23472. tmpHoles = newShapeHoles[ i ];
  23473. for ( var j = 0, jl = tmpHoles.length; j < jl; j ++ ) {
  23474. tmpShape.holes.push( tmpHoles[ j ].h );
  23475. }
  23476. }
  23477. //console.log("shape", shapes);
  23478. return shapes;
  23479. }
  23480. } );
  23481. /**
  23482. * @author zz85 / http://www.lab4games.net/zz85/blog
  23483. * @author mrdoob / http://mrdoob.com/
  23484. */
  23485. function Font( data ) {
  23486. this.type = 'Font';
  23487. this.data = data;
  23488. }
  23489. Object.assign( Font.prototype, {
  23490. isFont: true,
  23491. generateShapes: function ( text, size ) {
  23492. if ( size === undefined ) size = 100;
  23493. var shapes = [];
  23494. var paths = createPaths( text, size, this.data );
  23495. for ( var p = 0, pl = paths.length; p < pl; p ++ ) {
  23496. Array.prototype.push.apply( shapes, paths[ p ].toShapes() );
  23497. }
  23498. return shapes;
  23499. }
  23500. } );
  23501. function createPaths( text, size, data ) {
  23502. var chars = Array.from ? Array.from( text ) : String( text ).split( '' ); // see #13988
  23503. var scale = size / data.resolution;
  23504. var line_height = ( data.boundingBox.yMax - data.boundingBox.yMin + data.underlineThickness ) * scale;
  23505. var paths = [];
  23506. var offsetX = 0, offsetY = 0;
  23507. for ( var i = 0; i < chars.length; i ++ ) {
  23508. var char = chars[ i ];
  23509. if ( char === '\n' ) {
  23510. offsetX = 0;
  23511. offsetY -= line_height;
  23512. } else {
  23513. var ret = createPath( char, scale, offsetX, offsetY, data );
  23514. offsetX += ret.offsetX;
  23515. paths.push( ret.path );
  23516. }
  23517. }
  23518. return paths;
  23519. }
  23520. function createPath( char, scale, offsetX, offsetY, data ) {
  23521. var glyph = data.glyphs[ char ] || data.glyphs[ '?' ];
  23522. if ( ! glyph ) return;
  23523. var path = new ShapePath();
  23524. var x, y, cpx, cpy, cpx1, cpy1, cpx2, cpy2;
  23525. if ( glyph.o ) {
  23526. var outline = glyph._cachedOutline || ( glyph._cachedOutline = glyph.o.split( ' ' ) );
  23527. for ( var i = 0, l = outline.length; i < l; ) {
  23528. var action = outline[ i ++ ];
  23529. switch ( action ) {
  23530. case 'm': // moveTo
  23531. x = outline[ i ++ ] * scale + offsetX;
  23532. y = outline[ i ++ ] * scale + offsetY;
  23533. path.moveTo( x, y );
  23534. break;
  23535. case 'l': // lineTo
  23536. x = outline[ i ++ ] * scale + offsetX;
  23537. y = outline[ i ++ ] * scale + offsetY;
  23538. path.lineTo( x, y );
  23539. break;
  23540. case 'q': // quadraticCurveTo
  23541. cpx = outline[ i ++ ] * scale + offsetX;
  23542. cpy = outline[ i ++ ] * scale + offsetY;
  23543. cpx1 = outline[ i ++ ] * scale + offsetX;
  23544. cpy1 = outline[ i ++ ] * scale + offsetY;
  23545. path.quadraticCurveTo( cpx1, cpy1, cpx, cpy );
  23546. break;
  23547. case 'b': // bezierCurveTo
  23548. cpx = outline[ i ++ ] * scale + offsetX;
  23549. cpy = outline[ i ++ ] * scale + offsetY;
  23550. cpx1 = outline[ i ++ ] * scale + offsetX;
  23551. cpy1 = outline[ i ++ ] * scale + offsetY;
  23552. cpx2 = outline[ i ++ ] * scale + offsetX;
  23553. cpy2 = outline[ i ++ ] * scale + offsetY;
  23554. path.bezierCurveTo( cpx1, cpy1, cpx2, cpy2, cpx, cpy );
  23555. break;
  23556. }
  23557. }
  23558. }
  23559. return { offsetX: glyph.ha * scale, path: path };
  23560. }
  23561. /**
  23562. * @author mrdoob / http://mrdoob.com/
  23563. */
  23564. function FontLoader( manager ) {
  23565. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  23566. }
  23567. Object.assign( FontLoader.prototype, {
  23568. load: function ( url, onLoad, onProgress, onError ) {
  23569. var scope = this;
  23570. var loader = new FileLoader( this.manager );
  23571. loader.setPath( this.path );
  23572. loader.load( url, function ( text ) {
  23573. var json;
  23574. try {
  23575. json = JSON.parse( text );
  23576. } catch ( e ) {
  23577. console.warn( 'THREE.FontLoader: typeface.js support is being deprecated. Use typeface.json instead.' );
  23578. json = JSON.parse( text.substring( 65, text.length - 2 ) );
  23579. }
  23580. var font = scope.parse( json );
  23581. if ( onLoad ) onLoad( font );
  23582. }, onProgress, onError );
  23583. },
  23584. parse: function ( json ) {
  23585. return new Font( json );
  23586. },
  23587. setPath: function ( value ) {
  23588. this.path = value;
  23589. return this;
  23590. }
  23591. } );
  23592. /**
  23593. * @author alteredq / http://alteredqualia.com/
  23594. */
  23595. function Loader() {}
  23596. Loader.Handlers = {
  23597. handlers: [],
  23598. add: function ( regex, loader ) {
  23599. this.handlers.push( regex, loader );
  23600. },
  23601. get: function ( file ) {
  23602. var handlers = this.handlers;
  23603. for ( var i = 0, l = handlers.length; i < l; i += 2 ) {
  23604. var regex = handlers[ i ];
  23605. var loader = handlers[ i + 1 ];
  23606. if ( regex.test( file ) ) {
  23607. return loader;
  23608. }
  23609. }
  23610. return null;
  23611. }
  23612. };
  23613. Object.assign( Loader.prototype, {
  23614. crossOrigin: 'anonymous',
  23615. onLoadStart: function () {},
  23616. onLoadProgress: function () {},
  23617. onLoadComplete: function () {},
  23618. initMaterials: function ( materials, texturePath, crossOrigin ) {
  23619. var array = [];
  23620. for ( var i = 0; i < materials.length; ++ i ) {
  23621. array[ i ] = this.createMaterial( materials[ i ], texturePath, crossOrigin );
  23622. }
  23623. return array;
  23624. },
  23625. createMaterial: ( function () {
  23626. var BlendingMode = {
  23627. NoBlending: NoBlending,
  23628. NormalBlending: NormalBlending,
  23629. AdditiveBlending: AdditiveBlending,
  23630. SubtractiveBlending: SubtractiveBlending,
  23631. MultiplyBlending: MultiplyBlending,
  23632. CustomBlending: CustomBlending
  23633. };
  23634. var color = new Color();
  23635. var textureLoader = new TextureLoader();
  23636. var materialLoader = new MaterialLoader();
  23637. return function createMaterial( m, texturePath, crossOrigin ) {
  23638. // convert from old material format
  23639. var textures = {};
  23640. function loadTexture( path, repeat, offset, wrap, anisotropy ) {
  23641. var fullPath = texturePath + path;
  23642. var loader = Loader.Handlers.get( fullPath );
  23643. var texture;
  23644. if ( loader !== null ) {
  23645. texture = loader.load( fullPath );
  23646. } else {
  23647. textureLoader.setCrossOrigin( crossOrigin );
  23648. texture = textureLoader.load( fullPath );
  23649. }
  23650. if ( repeat !== undefined ) {
  23651. texture.repeat.fromArray( repeat );
  23652. if ( repeat[ 0 ] !== 1 ) texture.wrapS = RepeatWrapping;
  23653. if ( repeat[ 1 ] !== 1 ) texture.wrapT = RepeatWrapping;
  23654. }
  23655. if ( offset !== undefined ) {
  23656. texture.offset.fromArray( offset );
  23657. }
  23658. if ( wrap !== undefined ) {
  23659. if ( wrap[ 0 ] === 'repeat' ) texture.wrapS = RepeatWrapping;
  23660. if ( wrap[ 0 ] === 'mirror' ) texture.wrapS = MirroredRepeatWrapping;
  23661. if ( wrap[ 1 ] === 'repeat' ) texture.wrapT = RepeatWrapping;
  23662. if ( wrap[ 1 ] === 'mirror' ) texture.wrapT = MirroredRepeatWrapping;
  23663. }
  23664. if ( anisotropy !== undefined ) {
  23665. texture.anisotropy = anisotropy;
  23666. }
  23667. var uuid = _Math.generateUUID();
  23668. textures[ uuid ] = texture;
  23669. return uuid;
  23670. }
  23671. //
  23672. var json = {
  23673. uuid: _Math.generateUUID(),
  23674. type: 'MeshLambertMaterial'
  23675. };
  23676. for ( var name in m ) {
  23677. var value = m[ name ];
  23678. switch ( name ) {
  23679. case 'DbgColor':
  23680. case 'DbgIndex':
  23681. case 'opticalDensity':
  23682. case 'illumination':
  23683. break;
  23684. case 'DbgName':
  23685. json.name = value;
  23686. break;
  23687. case 'blending':
  23688. json.blending = BlendingMode[ value ];
  23689. break;
  23690. case 'colorAmbient':
  23691. case 'mapAmbient':
  23692. console.warn( 'THREE.Loader.createMaterial:', name, 'is no longer supported.' );
  23693. break;
  23694. case 'colorDiffuse':
  23695. json.color = color.fromArray( value ).getHex();
  23696. break;
  23697. case 'colorSpecular':
  23698. json.specular = color.fromArray( value ).getHex();
  23699. break;
  23700. case 'colorEmissive':
  23701. json.emissive = color.fromArray( value ).getHex();
  23702. break;
  23703. case 'specularCoef':
  23704. json.shininess = value;
  23705. break;
  23706. case 'shading':
  23707. if ( value.toLowerCase() === 'basic' ) json.type = 'MeshBasicMaterial';
  23708. if ( value.toLowerCase() === 'phong' ) json.type = 'MeshPhongMaterial';
  23709. if ( value.toLowerCase() === 'standard' ) json.type = 'MeshStandardMaterial';
  23710. break;
  23711. case 'mapDiffuse':
  23712. json.map = loadTexture( value, m.mapDiffuseRepeat, m.mapDiffuseOffset, m.mapDiffuseWrap, m.mapDiffuseAnisotropy );
  23713. break;
  23714. case 'mapDiffuseRepeat':
  23715. case 'mapDiffuseOffset':
  23716. case 'mapDiffuseWrap':
  23717. case 'mapDiffuseAnisotropy':
  23718. break;
  23719. case 'mapEmissive':
  23720. json.emissiveMap = loadTexture( value, m.mapEmissiveRepeat, m.mapEmissiveOffset, m.mapEmissiveWrap, m.mapEmissiveAnisotropy );
  23721. break;
  23722. case 'mapEmissiveRepeat':
  23723. case 'mapEmissiveOffset':
  23724. case 'mapEmissiveWrap':
  23725. case 'mapEmissiveAnisotropy':
  23726. break;
  23727. case 'mapLight':
  23728. json.lightMap = loadTexture( value, m.mapLightRepeat, m.mapLightOffset, m.mapLightWrap, m.mapLightAnisotropy );
  23729. break;
  23730. case 'mapLightRepeat':
  23731. case 'mapLightOffset':
  23732. case 'mapLightWrap':
  23733. case 'mapLightAnisotropy':
  23734. break;
  23735. case 'mapAO':
  23736. json.aoMap = loadTexture( value, m.mapAORepeat, m.mapAOOffset, m.mapAOWrap, m.mapAOAnisotropy );
  23737. break;
  23738. case 'mapAORepeat':
  23739. case 'mapAOOffset':
  23740. case 'mapAOWrap':
  23741. case 'mapAOAnisotropy':
  23742. break;
  23743. case 'mapBump':
  23744. json.bumpMap = loadTexture( value, m.mapBumpRepeat, m.mapBumpOffset, m.mapBumpWrap, m.mapBumpAnisotropy );
  23745. break;
  23746. case 'mapBumpScale':
  23747. json.bumpScale = value;
  23748. break;
  23749. case 'mapBumpRepeat':
  23750. case 'mapBumpOffset':
  23751. case 'mapBumpWrap':
  23752. case 'mapBumpAnisotropy':
  23753. break;
  23754. case 'mapNormal':
  23755. json.normalMap = loadTexture( value, m.mapNormalRepeat, m.mapNormalOffset, m.mapNormalWrap, m.mapNormalAnisotropy );
  23756. break;
  23757. case 'mapNormalFactor':
  23758. json.normalScale = value;
  23759. break;
  23760. case 'mapNormalRepeat':
  23761. case 'mapNormalOffset':
  23762. case 'mapNormalWrap':
  23763. case 'mapNormalAnisotropy':
  23764. break;
  23765. case 'mapSpecular':
  23766. json.specularMap = loadTexture( value, m.mapSpecularRepeat, m.mapSpecularOffset, m.mapSpecularWrap, m.mapSpecularAnisotropy );
  23767. break;
  23768. case 'mapSpecularRepeat':
  23769. case 'mapSpecularOffset':
  23770. case 'mapSpecularWrap':
  23771. case 'mapSpecularAnisotropy':
  23772. break;
  23773. case 'mapMetalness':
  23774. json.metalnessMap = loadTexture( value, m.mapMetalnessRepeat, m.mapMetalnessOffset, m.mapMetalnessWrap, m.mapMetalnessAnisotropy );
  23775. break;
  23776. case 'mapMetalnessRepeat':
  23777. case 'mapMetalnessOffset':
  23778. case 'mapMetalnessWrap':
  23779. case 'mapMetalnessAnisotropy':
  23780. break;
  23781. case 'mapRoughness':
  23782. json.roughnessMap = loadTexture( value, m.mapRoughnessRepeat, m.mapRoughnessOffset, m.mapRoughnessWrap, m.mapRoughnessAnisotropy );
  23783. break;
  23784. case 'mapRoughnessRepeat':
  23785. case 'mapRoughnessOffset':
  23786. case 'mapRoughnessWrap':
  23787. case 'mapRoughnessAnisotropy':
  23788. break;
  23789. case 'mapAlpha':
  23790. json.alphaMap = loadTexture( value, m.mapAlphaRepeat, m.mapAlphaOffset, m.mapAlphaWrap, m.mapAlphaAnisotropy );
  23791. break;
  23792. case 'mapAlphaRepeat':
  23793. case 'mapAlphaOffset':
  23794. case 'mapAlphaWrap':
  23795. case 'mapAlphaAnisotropy':
  23796. break;
  23797. case 'flipSided':
  23798. json.side = BackSide;
  23799. break;
  23800. case 'doubleSided':
  23801. json.side = DoubleSide;
  23802. break;
  23803. case 'transparency':
  23804. console.warn( 'THREE.Loader.createMaterial: transparency has been renamed to opacity' );
  23805. json.opacity = value;
  23806. break;
  23807. case 'depthTest':
  23808. case 'depthWrite':
  23809. case 'colorWrite':
  23810. case 'opacity':
  23811. case 'reflectivity':
  23812. case 'transparent':
  23813. case 'visible':
  23814. case 'wireframe':
  23815. json[ name ] = value;
  23816. break;
  23817. case 'vertexColors':
  23818. if ( value === true ) json.vertexColors = VertexColors;
  23819. if ( value === 'face' ) json.vertexColors = FaceColors;
  23820. break;
  23821. default:
  23822. console.error( 'THREE.Loader.createMaterial: Unsupported', name, value );
  23823. break;
  23824. }
  23825. }
  23826. if ( json.type === 'MeshBasicMaterial' ) delete json.emissive;
  23827. if ( json.type !== 'MeshPhongMaterial' ) delete json.specular;
  23828. if ( json.opacity < 1 ) json.transparent = true;
  23829. materialLoader.setTextures( textures );
  23830. return materialLoader.parse( json );
  23831. };
  23832. } )()
  23833. } );
  23834. /**
  23835. * @author mrdoob / http://mrdoob.com/
  23836. */
  23837. var context;
  23838. var AudioContext = {
  23839. getContext: function () {
  23840. if ( context === undefined ) {
  23841. context = new ( window.AudioContext || window.webkitAudioContext )();
  23842. }
  23843. return context;
  23844. },
  23845. setContext: function ( value ) {
  23846. context = value;
  23847. }
  23848. };
  23849. /**
  23850. * @author Reece Aaron Lecrivain / http://reecenotes.com/
  23851. */
  23852. function AudioLoader( manager ) {
  23853. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  23854. }
  23855. Object.assign( AudioLoader.prototype, {
  23856. load: function ( url, onLoad, onProgress, onError ) {
  23857. var loader = new FileLoader( this.manager );
  23858. loader.setResponseType( 'arraybuffer' );
  23859. loader.setPath( this.path );
  23860. loader.load( url, function ( buffer ) {
  23861. // Create a copy of the buffer. The `decodeAudioData` method
  23862. // detaches the buffer when complete, preventing reuse.
  23863. var bufferCopy = buffer.slice( 0 );
  23864. var context = AudioContext.getContext();
  23865. context.decodeAudioData( bufferCopy, function ( audioBuffer ) {
  23866. onLoad( audioBuffer );
  23867. } );
  23868. }, onProgress, onError );
  23869. },
  23870. setPath: function ( value ) {
  23871. this.path = value;
  23872. return this;
  23873. }
  23874. } );
  23875. /**
  23876. * @author mrdoob / http://mrdoob.com/
  23877. */
  23878. function StereoCamera() {
  23879. this.type = 'StereoCamera';
  23880. this.aspect = 1;
  23881. this.eyeSep = 0.064;
  23882. this.cameraL = new PerspectiveCamera();
  23883. this.cameraL.layers.enable( 1 );
  23884. this.cameraL.matrixAutoUpdate = false;
  23885. this.cameraR = new PerspectiveCamera();
  23886. this.cameraR.layers.enable( 2 );
  23887. this.cameraR.matrixAutoUpdate = false;
  23888. }
  23889. Object.assign( StereoCamera.prototype, {
  23890. update: ( function () {
  23891. var instance, focus, fov, aspect, near, far, zoom, eyeSep;
  23892. var eyeRight = new Matrix4();
  23893. var eyeLeft = new Matrix4();
  23894. return function update( camera ) {
  23895. var needsUpdate = instance !== this || focus !== camera.focus || fov !== camera.fov ||
  23896. aspect !== camera.aspect * this.aspect || near !== camera.near ||
  23897. far !== camera.far || zoom !== camera.zoom || eyeSep !== this.eyeSep;
  23898. if ( needsUpdate ) {
  23899. instance = this;
  23900. focus = camera.focus;
  23901. fov = camera.fov;
  23902. aspect = camera.aspect * this.aspect;
  23903. near = camera.near;
  23904. far = camera.far;
  23905. zoom = camera.zoom;
  23906. // Off-axis stereoscopic effect based on
  23907. // http://paulbourke.net/stereographics/stereorender/
  23908. var projectionMatrix = camera.projectionMatrix.clone();
  23909. eyeSep = this.eyeSep / 2;
  23910. var eyeSepOnProjection = eyeSep * near / focus;
  23911. var ymax = ( near * Math.tan( _Math.DEG2RAD * fov * 0.5 ) ) / zoom;
  23912. var xmin, xmax;
  23913. // translate xOffset
  23914. eyeLeft.elements[ 12 ] = - eyeSep;
  23915. eyeRight.elements[ 12 ] = eyeSep;
  23916. // for left eye
  23917. xmin = - ymax * aspect + eyeSepOnProjection;
  23918. xmax = ymax * aspect + eyeSepOnProjection;
  23919. projectionMatrix.elements[ 0 ] = 2 * near / ( xmax - xmin );
  23920. projectionMatrix.elements[ 8 ] = ( xmax + xmin ) / ( xmax - xmin );
  23921. this.cameraL.projectionMatrix.copy( projectionMatrix );
  23922. // for right eye
  23923. xmin = - ymax * aspect - eyeSepOnProjection;
  23924. xmax = ymax * aspect - eyeSepOnProjection;
  23925. projectionMatrix.elements[ 0 ] = 2 * near / ( xmax - xmin );
  23926. projectionMatrix.elements[ 8 ] = ( xmax + xmin ) / ( xmax - xmin );
  23927. this.cameraR.projectionMatrix.copy( projectionMatrix );
  23928. }
  23929. this.cameraL.matrixWorld.copy( camera.matrixWorld ).multiply( eyeLeft );
  23930. this.cameraR.matrixWorld.copy( camera.matrixWorld ).multiply( eyeRight );
  23931. };
  23932. } )()
  23933. } );
  23934. /**
  23935. * Camera for rendering cube maps
  23936. * - renders scene into axis-aligned cube
  23937. *
  23938. * @author alteredq / http://alteredqualia.com/
  23939. */
  23940. function CubeCamera( near, far, cubeResolution, options ) {
  23941. Object3D.call( this );
  23942. this.type = 'CubeCamera';
  23943. var fov = 90, aspect = 1;
  23944. var cameraPX = new PerspectiveCamera( fov, aspect, near, far );
  23945. cameraPX.up.set( 0, - 1, 0 );
  23946. cameraPX.lookAt( new Vector3( 1, 0, 0 ) );
  23947. this.add( cameraPX );
  23948. var cameraNX = new PerspectiveCamera( fov, aspect, near, far );
  23949. cameraNX.up.set( 0, - 1, 0 );
  23950. cameraNX.lookAt( new Vector3( - 1, 0, 0 ) );
  23951. this.add( cameraNX );
  23952. var cameraPY = new PerspectiveCamera( fov, aspect, near, far );
  23953. cameraPY.up.set( 0, 0, 1 );
  23954. cameraPY.lookAt( new Vector3( 0, 1, 0 ) );
  23955. this.add( cameraPY );
  23956. var cameraNY = new PerspectiveCamera( fov, aspect, near, far );
  23957. cameraNY.up.set( 0, 0, - 1 );
  23958. cameraNY.lookAt( new Vector3( 0, - 1, 0 ) );
  23959. this.add( cameraNY );
  23960. var cameraPZ = new PerspectiveCamera( fov, aspect, near, far );
  23961. cameraPZ.up.set( 0, - 1, 0 );
  23962. cameraPZ.lookAt( new Vector3( 0, 0, 1 ) );
  23963. this.add( cameraPZ );
  23964. var cameraNZ = new PerspectiveCamera( fov, aspect, near, far );
  23965. cameraNZ.up.set( 0, - 1, 0 );
  23966. cameraNZ.lookAt( new Vector3( 0, 0, - 1 ) );
  23967. this.add( cameraNZ );
  23968. options = options || { format: RGBFormat, magFilter: LinearFilter, minFilter: LinearFilter };
  23969. this.renderTarget = new WebGLRenderTargetCube( cubeResolution, cubeResolution, options );
  23970. this.renderTarget.texture.name = "CubeCamera";
  23971. this.update = function ( renderer, scene ) {
  23972. if ( this.parent === null ) this.updateMatrixWorld();
  23973. var currentRenderTarget = renderer.getRenderTarget();
  23974. var renderTarget = this.renderTarget;
  23975. var generateMipmaps = renderTarget.texture.generateMipmaps;
  23976. renderTarget.texture.generateMipmaps = false;
  23977. renderer.setRenderTarget( renderTarget, 0 );
  23978. renderer.render( scene, cameraPX );
  23979. renderer.setRenderTarget( renderTarget, 1 );
  23980. renderer.render( scene, cameraNX );
  23981. renderer.setRenderTarget( renderTarget, 2 );
  23982. renderer.render( scene, cameraPY );
  23983. renderer.setRenderTarget( renderTarget, 3 );
  23984. renderer.render( scene, cameraNY );
  23985. renderer.setRenderTarget( renderTarget, 4 );
  23986. renderer.render( scene, cameraPZ );
  23987. renderTarget.texture.generateMipmaps = generateMipmaps;
  23988. renderer.setRenderTarget( renderTarget, 5 );
  23989. renderer.render( scene, cameraNZ );
  23990. renderer.setRenderTarget( currentRenderTarget );
  23991. };
  23992. this.clear = function ( renderer, color, depth, stencil ) {
  23993. var currentRenderTarget = renderer.getRenderTarget();
  23994. var renderTarget = this.renderTarget;
  23995. for ( var i = 0; i < 6; i ++ ) {
  23996. renderTarget.activeCubeFace = i;
  23997. renderer.setRenderTarget( renderTarget );
  23998. renderer.clear( color, depth, stencil );
  23999. }
  24000. renderer.setRenderTarget( currentRenderTarget );
  24001. };
  24002. }
  24003. CubeCamera.prototype = Object.create( Object3D.prototype );
  24004. CubeCamera.prototype.constructor = CubeCamera;
  24005. /**
  24006. * @author alteredq / http://alteredqualia.com/
  24007. */
  24008. function Clock( autoStart ) {
  24009. this.autoStart = ( autoStart !== undefined ) ? autoStart : true;
  24010. this.startTime = 0;
  24011. this.oldTime = 0;
  24012. this.elapsedTime = 0;
  24013. this.running = false;
  24014. }
  24015. Object.assign( Clock.prototype, {
  24016. start: function () {
  24017. this.startTime = ( typeof performance === 'undefined' ? Date : performance ).now(); // see #10732
  24018. this.oldTime = this.startTime;
  24019. this.elapsedTime = 0;
  24020. this.running = true;
  24021. },
  24022. stop: function () {
  24023. this.getElapsedTime();
  24024. this.running = false;
  24025. this.autoStart = false;
  24026. },
  24027. getElapsedTime: function () {
  24028. this.getDelta();
  24029. return this.elapsedTime;
  24030. },
  24031. getDelta: function () {
  24032. var diff = 0;
  24033. if ( this.autoStart && ! this.running ) {
  24034. this.start();
  24035. return 0;
  24036. }
  24037. if ( this.running ) {
  24038. var newTime = ( typeof performance === 'undefined' ? Date : performance ).now();
  24039. diff = ( newTime - this.oldTime ) / 1000;
  24040. this.oldTime = newTime;
  24041. this.elapsedTime += diff;
  24042. }
  24043. return diff;
  24044. }
  24045. } );
  24046. /**
  24047. * @author mrdoob / http://mrdoob.com/
  24048. */
  24049. function AudioListener() {
  24050. Object3D.call( this );
  24051. this.type = 'AudioListener';
  24052. this.context = AudioContext.getContext();
  24053. this.gain = this.context.createGain();
  24054. this.gain.connect( this.context.destination );
  24055. this.filter = null;
  24056. this.timeDelta = 0;
  24057. }
  24058. AudioListener.prototype = Object.assign( Object.create( Object3D.prototype ), {
  24059. constructor: AudioListener,
  24060. getInput: function () {
  24061. return this.gain;
  24062. },
  24063. removeFilter: function ( ) {
  24064. if ( this.filter !== null ) {
  24065. this.gain.disconnect( this.filter );
  24066. this.filter.disconnect( this.context.destination );
  24067. this.gain.connect( this.context.destination );
  24068. this.filter = null;
  24069. }
  24070. return this;
  24071. },
  24072. getFilter: function () {
  24073. return this.filter;
  24074. },
  24075. setFilter: function ( value ) {
  24076. if ( this.filter !== null ) {
  24077. this.gain.disconnect( this.filter );
  24078. this.filter.disconnect( this.context.destination );
  24079. } else {
  24080. this.gain.disconnect( this.context.destination );
  24081. }
  24082. this.filter = value;
  24083. this.gain.connect( this.filter );
  24084. this.filter.connect( this.context.destination );
  24085. return this;
  24086. },
  24087. getMasterVolume: function () {
  24088. return this.gain.gain.value;
  24089. },
  24090. setMasterVolume: function ( value ) {
  24091. this.gain.gain.setTargetAtTime( value, this.context.currentTime, 0.01 );
  24092. return this;
  24093. },
  24094. updateMatrixWorld: ( function () {
  24095. var position = new Vector3();
  24096. var quaternion = new Quaternion();
  24097. var scale = new Vector3();
  24098. var orientation = new Vector3();
  24099. var clock = new Clock();
  24100. return function updateMatrixWorld( force ) {
  24101. Object3D.prototype.updateMatrixWorld.call( this, force );
  24102. var listener = this.context.listener;
  24103. var up = this.up;
  24104. this.timeDelta = clock.getDelta();
  24105. this.matrixWorld.decompose( position, quaternion, scale );
  24106. orientation.set( 0, 0, - 1 ).applyQuaternion( quaternion );
  24107. if ( listener.positionX ) {
  24108. // code path for Chrome (see #14393)
  24109. var endTime = this.context.currentTime + this.timeDelta;
  24110. listener.positionX.linearRampToValueAtTime( position.x, endTime );
  24111. listener.positionY.linearRampToValueAtTime( position.y, endTime );
  24112. listener.positionZ.linearRampToValueAtTime( position.z, endTime );
  24113. listener.forwardX.linearRampToValueAtTime( orientation.x, endTime );
  24114. listener.forwardY.linearRampToValueAtTime( orientation.y, endTime );
  24115. listener.forwardZ.linearRampToValueAtTime( orientation.z, endTime );
  24116. listener.upX.linearRampToValueAtTime( up.x, endTime );
  24117. listener.upY.linearRampToValueAtTime( up.y, endTime );
  24118. listener.upZ.linearRampToValueAtTime( up.z, endTime );
  24119. } else {
  24120. listener.setPosition( position.x, position.y, position.z );
  24121. listener.setOrientation( orientation.x, orientation.y, orientation.z, up.x, up.y, up.z );
  24122. }
  24123. };
  24124. } )()
  24125. } );
  24126. /**
  24127. * @author mrdoob / http://mrdoob.com/
  24128. * @author Reece Aaron Lecrivain / http://reecenotes.com/
  24129. */
  24130. function Audio( listener ) {
  24131. Object3D.call( this );
  24132. this.type = 'Audio';
  24133. this.listener = listener;
  24134. this.context = listener.context;
  24135. this.gain = this.context.createGain();
  24136. this.gain.connect( listener.getInput() );
  24137. this.autoplay = false;
  24138. this.buffer = null;
  24139. this.detune = 0;
  24140. this.loop = false;
  24141. this.startTime = 0;
  24142. this.offset = 0;
  24143. this.playbackRate = 1;
  24144. this.isPlaying = false;
  24145. this.hasPlaybackControl = true;
  24146. this.sourceType = 'empty';
  24147. this.filters = [];
  24148. }
  24149. Audio.prototype = Object.assign( Object.create( Object3D.prototype ), {
  24150. constructor: Audio,
  24151. getOutput: function () {
  24152. return this.gain;
  24153. },
  24154. setNodeSource: function ( audioNode ) {
  24155. this.hasPlaybackControl = false;
  24156. this.sourceType = 'audioNode';
  24157. this.source = audioNode;
  24158. this.connect();
  24159. return this;
  24160. },
  24161. setMediaElementSource: function ( mediaElement ) {
  24162. this.hasPlaybackControl = false;
  24163. this.sourceType = 'mediaNode';
  24164. this.source = this.context.createMediaElementSource( mediaElement );
  24165. this.connect();
  24166. return this;
  24167. },
  24168. setBuffer: function ( audioBuffer ) {
  24169. this.buffer = audioBuffer;
  24170. this.sourceType = 'buffer';
  24171. if ( this.autoplay ) this.play();
  24172. return this;
  24173. },
  24174. play: function () {
  24175. if ( this.isPlaying === true ) {
  24176. console.warn( 'THREE.Audio: Audio is already playing.' );
  24177. return;
  24178. }
  24179. if ( this.hasPlaybackControl === false ) {
  24180. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  24181. return;
  24182. }
  24183. var source = this.context.createBufferSource();
  24184. source.buffer = this.buffer;
  24185. source.loop = this.loop;
  24186. source.onended = this.onEnded.bind( this );
  24187. this.startTime = this.context.currentTime;
  24188. source.start( this.startTime, this.offset );
  24189. this.isPlaying = true;
  24190. this.source = source;
  24191. this.setDetune( this.detune );
  24192. this.setPlaybackRate( this.playbackRate );
  24193. return this.connect();
  24194. },
  24195. pause: function () {
  24196. if ( this.hasPlaybackControl === false ) {
  24197. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  24198. return;
  24199. }
  24200. if ( this.isPlaying === true ) {
  24201. this.source.stop();
  24202. this.source.onended = null;
  24203. this.offset += ( this.context.currentTime - this.startTime ) * this.playbackRate;
  24204. this.isPlaying = false;
  24205. }
  24206. return this;
  24207. },
  24208. stop: function () {
  24209. if ( this.hasPlaybackControl === false ) {
  24210. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  24211. return;
  24212. }
  24213. this.source.stop();
  24214. this.source.onended = null;
  24215. this.offset = 0;
  24216. this.isPlaying = false;
  24217. return this;
  24218. },
  24219. connect: function () {
  24220. if ( this.filters.length > 0 ) {
  24221. this.source.connect( this.filters[ 0 ] );
  24222. for ( var i = 1, l = this.filters.length; i < l; i ++ ) {
  24223. this.filters[ i - 1 ].connect( this.filters[ i ] );
  24224. }
  24225. this.filters[ this.filters.length - 1 ].connect( this.getOutput() );
  24226. } else {
  24227. this.source.connect( this.getOutput() );
  24228. }
  24229. return this;
  24230. },
  24231. disconnect: function () {
  24232. if ( this.filters.length > 0 ) {
  24233. this.source.disconnect( this.filters[ 0 ] );
  24234. for ( var i = 1, l = this.filters.length; i < l; i ++ ) {
  24235. this.filters[ i - 1 ].disconnect( this.filters[ i ] );
  24236. }
  24237. this.filters[ this.filters.length - 1 ].disconnect( this.getOutput() );
  24238. } else {
  24239. this.source.disconnect( this.getOutput() );
  24240. }
  24241. return this;
  24242. },
  24243. getFilters: function () {
  24244. return this.filters;
  24245. },
  24246. setFilters: function ( value ) {
  24247. if ( ! value ) value = [];
  24248. if ( this.isPlaying === true ) {
  24249. this.disconnect();
  24250. this.filters = value;
  24251. this.connect();
  24252. } else {
  24253. this.filters = value;
  24254. }
  24255. return this;
  24256. },
  24257. setDetune: function ( value ) {
  24258. this.detune = value;
  24259. if ( this.source.detune === undefined ) return; // only set detune when available
  24260. if ( this.isPlaying === true ) {
  24261. this.source.detune.setTargetAtTime( this.detune, this.context.currentTime, 0.01 );
  24262. }
  24263. return this;
  24264. },
  24265. getDetune: function () {
  24266. return this.detune;
  24267. },
  24268. getFilter: function () {
  24269. return this.getFilters()[ 0 ];
  24270. },
  24271. setFilter: function ( filter ) {
  24272. return this.setFilters( filter ? [ filter ] : [] );
  24273. },
  24274. setPlaybackRate: function ( value ) {
  24275. if ( this.hasPlaybackControl === false ) {
  24276. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  24277. return;
  24278. }
  24279. this.playbackRate = value;
  24280. if ( this.isPlaying === true ) {
  24281. this.source.playbackRate.setTargetAtTime( this.playbackRate, this.context.currentTime, 0.01 );
  24282. }
  24283. return this;
  24284. },
  24285. getPlaybackRate: function () {
  24286. return this.playbackRate;
  24287. },
  24288. onEnded: function () {
  24289. this.isPlaying = false;
  24290. },
  24291. getLoop: function () {
  24292. if ( this.hasPlaybackControl === false ) {
  24293. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  24294. return false;
  24295. }
  24296. return this.loop;
  24297. },
  24298. setLoop: function ( value ) {
  24299. if ( this.hasPlaybackControl === false ) {
  24300. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  24301. return;
  24302. }
  24303. this.loop = value;
  24304. if ( this.isPlaying === true ) {
  24305. this.source.loop = this.loop;
  24306. }
  24307. return this;
  24308. },
  24309. getVolume: function () {
  24310. return this.gain.gain.value;
  24311. },
  24312. setVolume: function ( value ) {
  24313. this.gain.gain.setTargetAtTime( value, this.context.currentTime, 0.01 );
  24314. return this;
  24315. }
  24316. } );
  24317. /**
  24318. * @author mrdoob / http://mrdoob.com/
  24319. */
  24320. function PositionalAudio( listener ) {
  24321. Audio.call( this, listener );
  24322. this.panner = this.context.createPanner();
  24323. this.panner.connect( this.gain );
  24324. }
  24325. PositionalAudio.prototype = Object.assign( Object.create( Audio.prototype ), {
  24326. constructor: PositionalAudio,
  24327. getOutput: function () {
  24328. return this.panner;
  24329. },
  24330. getRefDistance: function () {
  24331. return this.panner.refDistance;
  24332. },
  24333. setRefDistance: function ( value ) {
  24334. this.panner.refDistance = value;
  24335. return this;
  24336. },
  24337. getRolloffFactor: function () {
  24338. return this.panner.rolloffFactor;
  24339. },
  24340. setRolloffFactor: function ( value ) {
  24341. this.panner.rolloffFactor = value;
  24342. return this;
  24343. },
  24344. getDistanceModel: function () {
  24345. return this.panner.distanceModel;
  24346. },
  24347. setDistanceModel: function ( value ) {
  24348. this.panner.distanceModel = value;
  24349. return this;
  24350. },
  24351. getMaxDistance: function () {
  24352. return this.panner.maxDistance;
  24353. },
  24354. setMaxDistance: function ( value ) {
  24355. this.panner.maxDistance = value;
  24356. return this;
  24357. },
  24358. setDirectionalCone: function ( coneInnerAngle, coneOuterAngle, coneOuterGain ) {
  24359. this.panner.coneInnerAngle = coneInnerAngle;
  24360. this.panner.coneOuterAngle = coneOuterAngle;
  24361. this.panner.coneOuterGain = coneOuterGain;
  24362. return this;
  24363. },
  24364. updateMatrixWorld: ( function () {
  24365. var position = new Vector3();
  24366. var quaternion = new Quaternion();
  24367. var scale = new Vector3();
  24368. var orientation = new Vector3();
  24369. return function updateMatrixWorld( force ) {
  24370. Object3D.prototype.updateMatrixWorld.call( this, force );
  24371. if ( this.hasPlaybackControl === true && this.isPlaying === false ) return;
  24372. this.matrixWorld.decompose( position, quaternion, scale );
  24373. orientation.set( 0, 0, 1 ).applyQuaternion( quaternion );
  24374. var panner = this.panner;
  24375. if ( panner.positionX ) {
  24376. // code path for Chrome and Firefox (see #14393)
  24377. var endTime = this.context.currentTime + this.listener.timeDelta;
  24378. panner.positionX.linearRampToValueAtTime( position.x, endTime );
  24379. panner.positionY.linearRampToValueAtTime( position.y, endTime );
  24380. panner.positionZ.linearRampToValueAtTime( position.z, endTime );
  24381. panner.orientationX.linearRampToValueAtTime( orientation.x, endTime );
  24382. panner.orientationY.linearRampToValueAtTime( orientation.y, endTime );
  24383. panner.orientationZ.linearRampToValueAtTime( orientation.z, endTime );
  24384. } else {
  24385. panner.setPosition( position.x, position.y, position.z );
  24386. panner.setOrientation( orientation.x, orientation.y, orientation.z );
  24387. }
  24388. };
  24389. } )()
  24390. } );
  24391. /**
  24392. * @author mrdoob / http://mrdoob.com/
  24393. */
  24394. function AudioAnalyser( audio, fftSize ) {
  24395. this.analyser = audio.context.createAnalyser();
  24396. this.analyser.fftSize = fftSize !== undefined ? fftSize : 2048;
  24397. this.data = new Uint8Array( this.analyser.frequencyBinCount );
  24398. audio.getOutput().connect( this.analyser );
  24399. }
  24400. Object.assign( AudioAnalyser.prototype, {
  24401. getFrequencyData: function () {
  24402. this.analyser.getByteFrequencyData( this.data );
  24403. return this.data;
  24404. },
  24405. getAverageFrequency: function () {
  24406. var value = 0, data = this.getFrequencyData();
  24407. for ( var i = 0; i < data.length; i ++ ) {
  24408. value += data[ i ];
  24409. }
  24410. return value / data.length;
  24411. }
  24412. } );
  24413. /**
  24414. *
  24415. * Buffered scene graph property that allows weighted accumulation.
  24416. *
  24417. *
  24418. * @author Ben Houston / http://clara.io/
  24419. * @author David Sarno / http://lighthaus.us/
  24420. * @author tschw
  24421. */
  24422. function PropertyMixer( binding, typeName, valueSize ) {
  24423. this.binding = binding;
  24424. this.valueSize = valueSize;
  24425. var bufferType = Float64Array,
  24426. mixFunction;
  24427. switch ( typeName ) {
  24428. case 'quaternion':
  24429. mixFunction = this._slerp;
  24430. break;
  24431. case 'string':
  24432. case 'bool':
  24433. bufferType = Array;
  24434. mixFunction = this._select;
  24435. break;
  24436. default:
  24437. mixFunction = this._lerp;
  24438. }
  24439. this.buffer = new bufferType( valueSize * 4 );
  24440. // layout: [ incoming | accu0 | accu1 | orig ]
  24441. //
  24442. // interpolators can use .buffer as their .result
  24443. // the data then goes to 'incoming'
  24444. //
  24445. // 'accu0' and 'accu1' are used frame-interleaved for
  24446. // the cumulative result and are compared to detect
  24447. // changes
  24448. //
  24449. // 'orig' stores the original state of the property
  24450. this._mixBufferRegion = mixFunction;
  24451. this.cumulativeWeight = 0;
  24452. this.useCount = 0;
  24453. this.referenceCount = 0;
  24454. }
  24455. Object.assign( PropertyMixer.prototype, {
  24456. // accumulate data in the 'incoming' region into 'accu<i>'
  24457. accumulate: function ( accuIndex, weight ) {
  24458. // note: happily accumulating nothing when weight = 0, the caller knows
  24459. // the weight and shouldn't have made the call in the first place
  24460. var buffer = this.buffer,
  24461. stride = this.valueSize,
  24462. offset = accuIndex * stride + stride,
  24463. currentWeight = this.cumulativeWeight;
  24464. if ( currentWeight === 0 ) {
  24465. // accuN := incoming * weight
  24466. for ( var i = 0; i !== stride; ++ i ) {
  24467. buffer[ offset + i ] = buffer[ i ];
  24468. }
  24469. currentWeight = weight;
  24470. } else {
  24471. // accuN := accuN + incoming * weight
  24472. currentWeight += weight;
  24473. var mix = weight / currentWeight;
  24474. this._mixBufferRegion( buffer, offset, 0, mix, stride );
  24475. }
  24476. this.cumulativeWeight = currentWeight;
  24477. },
  24478. // apply the state of 'accu<i>' to the binding when accus differ
  24479. apply: function ( accuIndex ) {
  24480. var stride = this.valueSize,
  24481. buffer = this.buffer,
  24482. offset = accuIndex * stride + stride,
  24483. weight = this.cumulativeWeight,
  24484. binding = this.binding;
  24485. this.cumulativeWeight = 0;
  24486. if ( weight < 1 ) {
  24487. // accuN := accuN + original * ( 1 - cumulativeWeight )
  24488. var originalValueOffset = stride * 3;
  24489. this._mixBufferRegion(
  24490. buffer, offset, originalValueOffset, 1 - weight, stride );
  24491. }
  24492. for ( var i = stride, e = stride + stride; i !== e; ++ i ) {
  24493. if ( buffer[ i ] !== buffer[ i + stride ] ) {
  24494. // value has changed -> update scene graph
  24495. binding.setValue( buffer, offset );
  24496. break;
  24497. }
  24498. }
  24499. },
  24500. // remember the state of the bound property and copy it to both accus
  24501. saveOriginalState: function () {
  24502. var binding = this.binding;
  24503. var buffer = this.buffer,
  24504. stride = this.valueSize,
  24505. originalValueOffset = stride * 3;
  24506. binding.getValue( buffer, originalValueOffset );
  24507. // accu[0..1] := orig -- initially detect changes against the original
  24508. for ( var i = stride, e = originalValueOffset; i !== e; ++ i ) {
  24509. buffer[ i ] = buffer[ originalValueOffset + ( i % stride ) ];
  24510. }
  24511. this.cumulativeWeight = 0;
  24512. },
  24513. // apply the state previously taken via 'saveOriginalState' to the binding
  24514. restoreOriginalState: function () {
  24515. var originalValueOffset = this.valueSize * 3;
  24516. this.binding.setValue( this.buffer, originalValueOffset );
  24517. },
  24518. // mix functions
  24519. _select: function ( buffer, dstOffset, srcOffset, t, stride ) {
  24520. if ( t >= 0.5 ) {
  24521. for ( var i = 0; i !== stride; ++ i ) {
  24522. buffer[ dstOffset + i ] = buffer[ srcOffset + i ];
  24523. }
  24524. }
  24525. },
  24526. _slerp: function ( buffer, dstOffset, srcOffset, t ) {
  24527. Quaternion.slerpFlat( buffer, dstOffset, buffer, dstOffset, buffer, srcOffset, t );
  24528. },
  24529. _lerp: function ( buffer, dstOffset, srcOffset, t, stride ) {
  24530. var s = 1 - t;
  24531. for ( var i = 0; i !== stride; ++ i ) {
  24532. var j = dstOffset + i;
  24533. buffer[ j ] = buffer[ j ] * s + buffer[ srcOffset + i ] * t;
  24534. }
  24535. }
  24536. } );
  24537. /**
  24538. *
  24539. * A reference to a real property in the scene graph.
  24540. *
  24541. *
  24542. * @author Ben Houston / http://clara.io/
  24543. * @author David Sarno / http://lighthaus.us/
  24544. * @author tschw
  24545. */
  24546. // Characters [].:/ are reserved for track binding syntax.
  24547. var RESERVED_CHARS_RE = '\\[\\]\\.:\\/';
  24548. function Composite( targetGroup, path, optionalParsedPath ) {
  24549. var parsedPath = optionalParsedPath || PropertyBinding.parseTrackName( path );
  24550. this._targetGroup = targetGroup;
  24551. this._bindings = targetGroup.subscribe_( path, parsedPath );
  24552. }
  24553. Object.assign( Composite.prototype, {
  24554. getValue: function ( array, offset ) {
  24555. this.bind(); // bind all binding
  24556. var firstValidIndex = this._targetGroup.nCachedObjects_,
  24557. binding = this._bindings[ firstValidIndex ];
  24558. // and only call .getValue on the first
  24559. if ( binding !== undefined ) binding.getValue( array, offset );
  24560. },
  24561. setValue: function ( array, offset ) {
  24562. var bindings = this._bindings;
  24563. for ( var i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++ i ) {
  24564. bindings[ i ].setValue( array, offset );
  24565. }
  24566. },
  24567. bind: function () {
  24568. var bindings = this._bindings;
  24569. for ( var i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++ i ) {
  24570. bindings[ i ].bind();
  24571. }
  24572. },
  24573. unbind: function () {
  24574. var bindings = this._bindings;
  24575. for ( var i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++ i ) {
  24576. bindings[ i ].unbind();
  24577. }
  24578. }
  24579. } );
  24580. function PropertyBinding( rootNode, path, parsedPath ) {
  24581. this.path = path;
  24582. this.parsedPath = parsedPath || PropertyBinding.parseTrackName( path );
  24583. this.node = PropertyBinding.findNode( rootNode, this.parsedPath.nodeName ) || rootNode;
  24584. this.rootNode = rootNode;
  24585. }
  24586. Object.assign( PropertyBinding, {
  24587. Composite: Composite,
  24588. create: function ( root, path, parsedPath ) {
  24589. if ( ! ( root && root.isAnimationObjectGroup ) ) {
  24590. return new PropertyBinding( root, path, parsedPath );
  24591. } else {
  24592. return new PropertyBinding.Composite( root, path, parsedPath );
  24593. }
  24594. },
  24595. /**
  24596. * Replaces spaces with underscores and removes unsupported characters from
  24597. * node names, to ensure compatibility with parseTrackName().
  24598. *
  24599. * @param {string} name Node name to be sanitized.
  24600. * @return {string}
  24601. */
  24602. sanitizeNodeName: ( function () {
  24603. var reservedRe = new RegExp( '[' + RESERVED_CHARS_RE + ']', 'g' );
  24604. return function sanitizeNodeName( name ) {
  24605. return name.replace( /\s/g, '_' ).replace( reservedRe, '' );
  24606. };
  24607. }() ),
  24608. parseTrackName: function () {
  24609. // Attempts to allow node names from any language. ES5's `\w` regexp matches
  24610. // only latin characters, and the unicode \p{L} is not yet supported. So
  24611. // instead, we exclude reserved characters and match everything else.
  24612. var wordChar = '[^' + RESERVED_CHARS_RE + ']';
  24613. var wordCharOrDot = '[^' + RESERVED_CHARS_RE.replace( '\\.', '' ) + ']';
  24614. // Parent directories, delimited by '/' or ':'. Currently unused, but must
  24615. // be matched to parse the rest of the track name.
  24616. var directoryRe = /((?:WC+[\/:])*)/.source.replace( 'WC', wordChar );
  24617. // Target node. May contain word characters (a-zA-Z0-9_) and '.' or '-'.
  24618. var nodeRe = /(WCOD+)?/.source.replace( 'WCOD', wordCharOrDot );
  24619. // Object on target node, and accessor. May not contain reserved
  24620. // characters. Accessor may contain any character except closing bracket.
  24621. var objectRe = /(?:\.(WC+)(?:\[(.+)\])?)?/.source.replace( 'WC', wordChar );
  24622. // Property and accessor. May not contain reserved characters. Accessor may
  24623. // contain any non-bracket characters.
  24624. var propertyRe = /\.(WC+)(?:\[(.+)\])?/.source.replace( 'WC', wordChar );
  24625. var trackRe = new RegExp( ''
  24626. + '^'
  24627. + directoryRe
  24628. + nodeRe
  24629. + objectRe
  24630. + propertyRe
  24631. + '$'
  24632. );
  24633. var supportedObjectNames = [ 'material', 'materials', 'bones' ];
  24634. return function parseTrackName( trackName ) {
  24635. var matches = trackRe.exec( trackName );
  24636. if ( ! matches ) {
  24637. throw new Error( 'PropertyBinding: Cannot parse trackName: ' + trackName );
  24638. }
  24639. var results = {
  24640. // directoryName: matches[ 1 ], // (tschw) currently unused
  24641. nodeName: matches[ 2 ],
  24642. objectName: matches[ 3 ],
  24643. objectIndex: matches[ 4 ],
  24644. propertyName: matches[ 5 ], // required
  24645. propertyIndex: matches[ 6 ]
  24646. };
  24647. var lastDot = results.nodeName && results.nodeName.lastIndexOf( '.' );
  24648. if ( lastDot !== undefined && lastDot !== - 1 ) {
  24649. var objectName = results.nodeName.substring( lastDot + 1 );
  24650. // Object names must be checked against a whitelist. Otherwise, there
  24651. // is no way to parse 'foo.bar.baz': 'baz' must be a property, but
  24652. // 'bar' could be the objectName, or part of a nodeName (which can
  24653. // include '.' characters).
  24654. if ( supportedObjectNames.indexOf( objectName ) !== - 1 ) {
  24655. results.nodeName = results.nodeName.substring( 0, lastDot );
  24656. results.objectName = objectName;
  24657. }
  24658. }
  24659. if ( results.propertyName === null || results.propertyName.length === 0 ) {
  24660. throw new Error( 'PropertyBinding: can not parse propertyName from trackName: ' + trackName );
  24661. }
  24662. return results;
  24663. };
  24664. }(),
  24665. findNode: function ( root, nodeName ) {
  24666. if ( ! nodeName || nodeName === "" || nodeName === "root" || nodeName === "." || nodeName === - 1 || nodeName === root.name || nodeName === root.uuid ) {
  24667. return root;
  24668. }
  24669. // search into skeleton bones.
  24670. if ( root.skeleton ) {
  24671. var bone = root.skeleton.getBoneByName( nodeName );
  24672. if ( bone !== undefined ) {
  24673. return bone;
  24674. }
  24675. }
  24676. // search into node subtree.
  24677. if ( root.children ) {
  24678. var searchNodeSubtree = function ( children ) {
  24679. for ( var i = 0; i < children.length; i ++ ) {
  24680. var childNode = children[ i ];
  24681. if ( childNode.name === nodeName || childNode.uuid === nodeName ) {
  24682. return childNode;
  24683. }
  24684. var result = searchNodeSubtree( childNode.children );
  24685. if ( result ) return result;
  24686. }
  24687. return null;
  24688. };
  24689. var subTreeNode = searchNodeSubtree( root.children );
  24690. if ( subTreeNode ) {
  24691. return subTreeNode;
  24692. }
  24693. }
  24694. return null;
  24695. }
  24696. } );
  24697. Object.assign( PropertyBinding.prototype, { // prototype, continued
  24698. // these are used to "bind" a nonexistent property
  24699. _getValue_unavailable: function () {},
  24700. _setValue_unavailable: function () {},
  24701. BindingType: {
  24702. Direct: 0,
  24703. EntireArray: 1,
  24704. ArrayElement: 2,
  24705. HasFromToArray: 3
  24706. },
  24707. Versioning: {
  24708. None: 0,
  24709. NeedsUpdate: 1,
  24710. MatrixWorldNeedsUpdate: 2
  24711. },
  24712. GetterByBindingType: [
  24713. function getValue_direct( buffer, offset ) {
  24714. buffer[ offset ] = this.node[ this.propertyName ];
  24715. },
  24716. function getValue_array( buffer, offset ) {
  24717. var source = this.resolvedProperty;
  24718. for ( var i = 0, n = source.length; i !== n; ++ i ) {
  24719. buffer[ offset ++ ] = source[ i ];
  24720. }
  24721. },
  24722. function getValue_arrayElement( buffer, offset ) {
  24723. buffer[ offset ] = this.resolvedProperty[ this.propertyIndex ];
  24724. },
  24725. function getValue_toArray( buffer, offset ) {
  24726. this.resolvedProperty.toArray( buffer, offset );
  24727. }
  24728. ],
  24729. SetterByBindingTypeAndVersioning: [
  24730. [
  24731. // Direct
  24732. function setValue_direct( buffer, offset ) {
  24733. this.targetObject[ this.propertyName ] = buffer[ offset ];
  24734. },
  24735. function setValue_direct_setNeedsUpdate( buffer, offset ) {
  24736. this.targetObject[ this.propertyName ] = buffer[ offset ];
  24737. this.targetObject.needsUpdate = true;
  24738. },
  24739. function setValue_direct_setMatrixWorldNeedsUpdate( buffer, offset ) {
  24740. this.targetObject[ this.propertyName ] = buffer[ offset ];
  24741. this.targetObject.matrixWorldNeedsUpdate = true;
  24742. }
  24743. ], [
  24744. // EntireArray
  24745. function setValue_array( buffer, offset ) {
  24746. var dest = this.resolvedProperty;
  24747. for ( var i = 0, n = dest.length; i !== n; ++ i ) {
  24748. dest[ i ] = buffer[ offset ++ ];
  24749. }
  24750. },
  24751. function setValue_array_setNeedsUpdate( buffer, offset ) {
  24752. var dest = this.resolvedProperty;
  24753. for ( var i = 0, n = dest.length; i !== n; ++ i ) {
  24754. dest[ i ] = buffer[ offset ++ ];
  24755. }
  24756. this.targetObject.needsUpdate = true;
  24757. },
  24758. function setValue_array_setMatrixWorldNeedsUpdate( buffer, offset ) {
  24759. var dest = this.resolvedProperty;
  24760. for ( var i = 0, n = dest.length; i !== n; ++ i ) {
  24761. dest[ i ] = buffer[ offset ++ ];
  24762. }
  24763. this.targetObject.matrixWorldNeedsUpdate = true;
  24764. }
  24765. ], [
  24766. // ArrayElement
  24767. function setValue_arrayElement( buffer, offset ) {
  24768. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  24769. },
  24770. function setValue_arrayElement_setNeedsUpdate( buffer, offset ) {
  24771. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  24772. this.targetObject.needsUpdate = true;
  24773. },
  24774. function setValue_arrayElement_setMatrixWorldNeedsUpdate( buffer, offset ) {
  24775. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  24776. this.targetObject.matrixWorldNeedsUpdate = true;
  24777. }
  24778. ], [
  24779. // HasToFromArray
  24780. function setValue_fromArray( buffer, offset ) {
  24781. this.resolvedProperty.fromArray( buffer, offset );
  24782. },
  24783. function setValue_fromArray_setNeedsUpdate( buffer, offset ) {
  24784. this.resolvedProperty.fromArray( buffer, offset );
  24785. this.targetObject.needsUpdate = true;
  24786. },
  24787. function setValue_fromArray_setMatrixWorldNeedsUpdate( buffer, offset ) {
  24788. this.resolvedProperty.fromArray( buffer, offset );
  24789. this.targetObject.matrixWorldNeedsUpdate = true;
  24790. }
  24791. ]
  24792. ],
  24793. getValue: function getValue_unbound( targetArray, offset ) {
  24794. this.bind();
  24795. this.getValue( targetArray, offset );
  24796. // Note: This class uses a State pattern on a per-method basis:
  24797. // 'bind' sets 'this.getValue' / 'setValue' and shadows the
  24798. // prototype version of these methods with one that represents
  24799. // the bound state. When the property is not found, the methods
  24800. // become no-ops.
  24801. },
  24802. setValue: function getValue_unbound( sourceArray, offset ) {
  24803. this.bind();
  24804. this.setValue( sourceArray, offset );
  24805. },
  24806. // create getter / setter pair for a property in the scene graph
  24807. bind: function () {
  24808. var targetObject = this.node,
  24809. parsedPath = this.parsedPath,
  24810. objectName = parsedPath.objectName,
  24811. propertyName = parsedPath.propertyName,
  24812. propertyIndex = parsedPath.propertyIndex;
  24813. if ( ! targetObject ) {
  24814. targetObject = PropertyBinding.findNode( this.rootNode, parsedPath.nodeName ) || this.rootNode;
  24815. this.node = targetObject;
  24816. }
  24817. // set fail state so we can just 'return' on error
  24818. this.getValue = this._getValue_unavailable;
  24819. this.setValue = this._setValue_unavailable;
  24820. // ensure there is a value node
  24821. if ( ! targetObject ) {
  24822. console.error( 'THREE.PropertyBinding: Trying to update node for track: ' + this.path + ' but it wasn\'t found.' );
  24823. return;
  24824. }
  24825. if ( objectName ) {
  24826. var objectIndex = parsedPath.objectIndex;
  24827. // special cases were we need to reach deeper into the hierarchy to get the face materials....
  24828. switch ( objectName ) {
  24829. case 'materials':
  24830. if ( ! targetObject.material ) {
  24831. console.error( 'THREE.PropertyBinding: Can not bind to material as node does not have a material.', this );
  24832. return;
  24833. }
  24834. if ( ! targetObject.material.materials ) {
  24835. console.error( 'THREE.PropertyBinding: Can not bind to material.materials as node.material does not have a materials array.', this );
  24836. return;
  24837. }
  24838. targetObject = targetObject.material.materials;
  24839. break;
  24840. case 'bones':
  24841. if ( ! targetObject.skeleton ) {
  24842. console.error( 'THREE.PropertyBinding: Can not bind to bones as node does not have a skeleton.', this );
  24843. return;
  24844. }
  24845. // potential future optimization: skip this if propertyIndex is already an integer
  24846. // and convert the integer string to a true integer.
  24847. targetObject = targetObject.skeleton.bones;
  24848. // support resolving morphTarget names into indices.
  24849. for ( var i = 0; i < targetObject.length; i ++ ) {
  24850. if ( targetObject[ i ].name === objectIndex ) {
  24851. objectIndex = i;
  24852. break;
  24853. }
  24854. }
  24855. break;
  24856. default:
  24857. if ( targetObject[ objectName ] === undefined ) {
  24858. console.error( 'THREE.PropertyBinding: Can not bind to objectName of node undefined.', this );
  24859. return;
  24860. }
  24861. targetObject = targetObject[ objectName ];
  24862. }
  24863. if ( objectIndex !== undefined ) {
  24864. if ( targetObject[ objectIndex ] === undefined ) {
  24865. console.error( 'THREE.PropertyBinding: Trying to bind to objectIndex of objectName, but is undefined.', this, targetObject );
  24866. return;
  24867. }
  24868. targetObject = targetObject[ objectIndex ];
  24869. }
  24870. }
  24871. // resolve property
  24872. var nodeProperty = targetObject[ propertyName ];
  24873. if ( nodeProperty === undefined ) {
  24874. var nodeName = parsedPath.nodeName;
  24875. console.error( 'THREE.PropertyBinding: Trying to update property for track: ' + nodeName +
  24876. '.' + propertyName + ' but it wasn\'t found.', targetObject );
  24877. return;
  24878. }
  24879. // determine versioning scheme
  24880. var versioning = this.Versioning.None;
  24881. this.targetObject = targetObject;
  24882. if ( targetObject.needsUpdate !== undefined ) { // material
  24883. versioning = this.Versioning.NeedsUpdate;
  24884. } else if ( targetObject.matrixWorldNeedsUpdate !== undefined ) { // node transform
  24885. versioning = this.Versioning.MatrixWorldNeedsUpdate;
  24886. }
  24887. // determine how the property gets bound
  24888. var bindingType = this.BindingType.Direct;
  24889. if ( propertyIndex !== undefined ) {
  24890. // access a sub element of the property array (only primitives are supported right now)
  24891. if ( propertyName === "morphTargetInfluences" ) {
  24892. // potential optimization, skip this if propertyIndex is already an integer, and convert the integer string to a true integer.
  24893. // support resolving morphTarget names into indices.
  24894. if ( ! targetObject.geometry ) {
  24895. console.error( 'THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.', this );
  24896. return;
  24897. }
  24898. if ( targetObject.geometry.isBufferGeometry ) {
  24899. if ( ! targetObject.geometry.morphAttributes ) {
  24900. console.error( 'THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.morphAttributes.', this );
  24901. return;
  24902. }
  24903. for ( var i = 0; i < this.node.geometry.morphAttributes.position.length; i ++ ) {
  24904. if ( targetObject.geometry.morphAttributes.position[ i ].name === propertyIndex ) {
  24905. propertyIndex = i;
  24906. break;
  24907. }
  24908. }
  24909. } else {
  24910. if ( ! targetObject.geometry.morphTargets ) {
  24911. console.error( 'THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.morphTargets.', this );
  24912. return;
  24913. }
  24914. for ( var i = 0; i < this.node.geometry.morphTargets.length; i ++ ) {
  24915. if ( targetObject.geometry.morphTargets[ i ].name === propertyIndex ) {
  24916. propertyIndex = i;
  24917. break;
  24918. }
  24919. }
  24920. }
  24921. }
  24922. bindingType = this.BindingType.ArrayElement;
  24923. this.resolvedProperty = nodeProperty;
  24924. this.propertyIndex = propertyIndex;
  24925. } else if ( nodeProperty.fromArray !== undefined && nodeProperty.toArray !== undefined ) {
  24926. // must use copy for Object3D.Euler/Quaternion
  24927. bindingType = this.BindingType.HasFromToArray;
  24928. this.resolvedProperty = nodeProperty;
  24929. } else if ( Array.isArray( nodeProperty ) ) {
  24930. bindingType = this.BindingType.EntireArray;
  24931. this.resolvedProperty = nodeProperty;
  24932. } else {
  24933. this.propertyName = propertyName;
  24934. }
  24935. // select getter / setter
  24936. this.getValue = this.GetterByBindingType[ bindingType ];
  24937. this.setValue = this.SetterByBindingTypeAndVersioning[ bindingType ][ versioning ];
  24938. },
  24939. unbind: function () {
  24940. this.node = null;
  24941. // back to the prototype version of getValue / setValue
  24942. // note: avoiding to mutate the shape of 'this' via 'delete'
  24943. this.getValue = this._getValue_unbound;
  24944. this.setValue = this._setValue_unbound;
  24945. }
  24946. } );
  24947. //!\ DECLARE ALIAS AFTER assign prototype !
  24948. Object.assign( PropertyBinding.prototype, {
  24949. // initial state of these methods that calls 'bind'
  24950. _getValue_unbound: PropertyBinding.prototype.getValue,
  24951. _setValue_unbound: PropertyBinding.prototype.setValue,
  24952. } );
  24953. /**
  24954. *
  24955. * A group of objects that receives a shared animation state.
  24956. *
  24957. * Usage:
  24958. *
  24959. * - Add objects you would otherwise pass as 'root' to the
  24960. * constructor or the .clipAction method of AnimationMixer.
  24961. *
  24962. * - Instead pass this object as 'root'.
  24963. *
  24964. * - You can also add and remove objects later when the mixer
  24965. * is running.
  24966. *
  24967. * Note:
  24968. *
  24969. * Objects of this class appear as one object to the mixer,
  24970. * so cache control of the individual objects must be done
  24971. * on the group.
  24972. *
  24973. * Limitation:
  24974. *
  24975. * - The animated properties must be compatible among the
  24976. * all objects in the group.
  24977. *
  24978. * - A single property can either be controlled through a
  24979. * target group or directly, but not both.
  24980. *
  24981. * @author tschw
  24982. */
  24983. function AnimationObjectGroup() {
  24984. this.uuid = _Math.generateUUID();
  24985. // cached objects followed by the active ones
  24986. this._objects = Array.prototype.slice.call( arguments );
  24987. this.nCachedObjects_ = 0; // threshold
  24988. // note: read by PropertyBinding.Composite
  24989. var indices = {};
  24990. this._indicesByUUID = indices; // for bookkeeping
  24991. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  24992. indices[ arguments[ i ].uuid ] = i;
  24993. }
  24994. this._paths = []; // inside: string
  24995. this._parsedPaths = []; // inside: { we don't care, here }
  24996. this._bindings = []; // inside: Array< PropertyBinding >
  24997. this._bindingsIndicesByPath = {}; // inside: indices in these arrays
  24998. var scope = this;
  24999. this.stats = {
  25000. objects: {
  25001. get total() {
  25002. return scope._objects.length;
  25003. },
  25004. get inUse() {
  25005. return this.total - scope.nCachedObjects_;
  25006. }
  25007. },
  25008. get bindingsPerObject() {
  25009. return scope._bindings.length;
  25010. }
  25011. };
  25012. }
  25013. Object.assign( AnimationObjectGroup.prototype, {
  25014. isAnimationObjectGroup: true,
  25015. add: function () {
  25016. var objects = this._objects,
  25017. nObjects = objects.length,
  25018. nCachedObjects = this.nCachedObjects_,
  25019. indicesByUUID = this._indicesByUUID,
  25020. paths = this._paths,
  25021. parsedPaths = this._parsedPaths,
  25022. bindings = this._bindings,
  25023. nBindings = bindings.length,
  25024. knownObject = undefined;
  25025. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  25026. var object = arguments[ i ],
  25027. uuid = object.uuid,
  25028. index = indicesByUUID[ uuid ];
  25029. if ( index === undefined ) {
  25030. // unknown object -> add it to the ACTIVE region
  25031. index = nObjects ++;
  25032. indicesByUUID[ uuid ] = index;
  25033. objects.push( object );
  25034. // accounting is done, now do the same for all bindings
  25035. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  25036. bindings[ j ].push( new PropertyBinding( object, paths[ j ], parsedPaths[ j ] ) );
  25037. }
  25038. } else if ( index < nCachedObjects ) {
  25039. knownObject = objects[ index ];
  25040. // move existing object to the ACTIVE region
  25041. var firstActiveIndex = -- nCachedObjects,
  25042. lastCachedObject = objects[ firstActiveIndex ];
  25043. indicesByUUID[ lastCachedObject.uuid ] = index;
  25044. objects[ index ] = lastCachedObject;
  25045. indicesByUUID[ uuid ] = firstActiveIndex;
  25046. objects[ firstActiveIndex ] = object;
  25047. // accounting is done, now do the same for all bindings
  25048. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  25049. var bindingsForPath = bindings[ j ],
  25050. lastCached = bindingsForPath[ firstActiveIndex ],
  25051. binding = bindingsForPath[ index ];
  25052. bindingsForPath[ index ] = lastCached;
  25053. if ( binding === undefined ) {
  25054. // since we do not bother to create new bindings
  25055. // for objects that are cached, the binding may
  25056. // or may not exist
  25057. binding = new PropertyBinding( object, paths[ j ], parsedPaths[ j ] );
  25058. }
  25059. bindingsForPath[ firstActiveIndex ] = binding;
  25060. }
  25061. } else if ( objects[ index ] !== knownObject ) {
  25062. console.error( 'THREE.AnimationObjectGroup: Different objects with the same UUID ' +
  25063. 'detected. Clean the caches or recreate your infrastructure when reloading scenes.' );
  25064. } // else the object is already where we want it to be
  25065. } // for arguments
  25066. this.nCachedObjects_ = nCachedObjects;
  25067. },
  25068. remove: function () {
  25069. var objects = this._objects,
  25070. nCachedObjects = this.nCachedObjects_,
  25071. indicesByUUID = this._indicesByUUID,
  25072. bindings = this._bindings,
  25073. nBindings = bindings.length;
  25074. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  25075. var object = arguments[ i ],
  25076. uuid = object.uuid,
  25077. index = indicesByUUID[ uuid ];
  25078. if ( index !== undefined && index >= nCachedObjects ) {
  25079. // move existing object into the CACHED region
  25080. var lastCachedIndex = nCachedObjects ++,
  25081. firstActiveObject = objects[ lastCachedIndex ];
  25082. indicesByUUID[ firstActiveObject.uuid ] = index;
  25083. objects[ index ] = firstActiveObject;
  25084. indicesByUUID[ uuid ] = lastCachedIndex;
  25085. objects[ lastCachedIndex ] = object;
  25086. // accounting is done, now do the same for all bindings
  25087. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  25088. var bindingsForPath = bindings[ j ],
  25089. firstActive = bindingsForPath[ lastCachedIndex ],
  25090. binding = bindingsForPath[ index ];
  25091. bindingsForPath[ index ] = firstActive;
  25092. bindingsForPath[ lastCachedIndex ] = binding;
  25093. }
  25094. }
  25095. } // for arguments
  25096. this.nCachedObjects_ = nCachedObjects;
  25097. },
  25098. // remove & forget
  25099. uncache: function () {
  25100. var objects = this._objects,
  25101. nObjects = objects.length,
  25102. nCachedObjects = this.nCachedObjects_,
  25103. indicesByUUID = this._indicesByUUID,
  25104. bindings = this._bindings,
  25105. nBindings = bindings.length;
  25106. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  25107. var object = arguments[ i ],
  25108. uuid = object.uuid,
  25109. index = indicesByUUID[ uuid ];
  25110. if ( index !== undefined ) {
  25111. delete indicesByUUID[ uuid ];
  25112. if ( index < nCachedObjects ) {
  25113. // object is cached, shrink the CACHED region
  25114. var firstActiveIndex = -- nCachedObjects,
  25115. lastCachedObject = objects[ firstActiveIndex ],
  25116. lastIndex = -- nObjects,
  25117. lastObject = objects[ lastIndex ];
  25118. // last cached object takes this object's place
  25119. indicesByUUID[ lastCachedObject.uuid ] = index;
  25120. objects[ index ] = lastCachedObject;
  25121. // last object goes to the activated slot and pop
  25122. indicesByUUID[ lastObject.uuid ] = firstActiveIndex;
  25123. objects[ firstActiveIndex ] = lastObject;
  25124. objects.pop();
  25125. // accounting is done, now do the same for all bindings
  25126. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  25127. var bindingsForPath = bindings[ j ],
  25128. lastCached = bindingsForPath[ firstActiveIndex ],
  25129. last = bindingsForPath[ lastIndex ];
  25130. bindingsForPath[ index ] = lastCached;
  25131. bindingsForPath[ firstActiveIndex ] = last;
  25132. bindingsForPath.pop();
  25133. }
  25134. } else {
  25135. // object is active, just swap with the last and pop
  25136. var lastIndex = -- nObjects,
  25137. lastObject = objects[ lastIndex ];
  25138. indicesByUUID[ lastObject.uuid ] = index;
  25139. objects[ index ] = lastObject;
  25140. objects.pop();
  25141. // accounting is done, now do the same for all bindings
  25142. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  25143. var bindingsForPath = bindings[ j ];
  25144. bindingsForPath[ index ] = bindingsForPath[ lastIndex ];
  25145. bindingsForPath.pop();
  25146. }
  25147. } // cached or active
  25148. } // if object is known
  25149. } // for arguments
  25150. this.nCachedObjects_ = nCachedObjects;
  25151. },
  25152. // Internal interface used by befriended PropertyBinding.Composite:
  25153. subscribe_: function ( path, parsedPath ) {
  25154. // returns an array of bindings for the given path that is changed
  25155. // according to the contained objects in the group
  25156. var indicesByPath = this._bindingsIndicesByPath,
  25157. index = indicesByPath[ path ],
  25158. bindings = this._bindings;
  25159. if ( index !== undefined ) return bindings[ index ];
  25160. var paths = this._paths,
  25161. parsedPaths = this._parsedPaths,
  25162. objects = this._objects,
  25163. nObjects = objects.length,
  25164. nCachedObjects = this.nCachedObjects_,
  25165. bindingsForPath = new Array( nObjects );
  25166. index = bindings.length;
  25167. indicesByPath[ path ] = index;
  25168. paths.push( path );
  25169. parsedPaths.push( parsedPath );
  25170. bindings.push( bindingsForPath );
  25171. for ( var i = nCachedObjects, n = objects.length; i !== n; ++ i ) {
  25172. var object = objects[ i ];
  25173. bindingsForPath[ i ] = new PropertyBinding( object, path, parsedPath );
  25174. }
  25175. return bindingsForPath;
  25176. },
  25177. unsubscribe_: function ( path ) {
  25178. // tells the group to forget about a property path and no longer
  25179. // update the array previously obtained with 'subscribe_'
  25180. var indicesByPath = this._bindingsIndicesByPath,
  25181. index = indicesByPath[ path ];
  25182. if ( index !== undefined ) {
  25183. var paths = this._paths,
  25184. parsedPaths = this._parsedPaths,
  25185. bindings = this._bindings,
  25186. lastBindingsIndex = bindings.length - 1,
  25187. lastBindings = bindings[ lastBindingsIndex ],
  25188. lastBindingsPath = path[ lastBindingsIndex ];
  25189. indicesByPath[ lastBindingsPath ] = index;
  25190. bindings[ index ] = lastBindings;
  25191. bindings.pop();
  25192. parsedPaths[ index ] = parsedPaths[ lastBindingsIndex ];
  25193. parsedPaths.pop();
  25194. paths[ index ] = paths[ lastBindingsIndex ];
  25195. paths.pop();
  25196. }
  25197. }
  25198. } );
  25199. /**
  25200. *
  25201. * Action provided by AnimationMixer for scheduling clip playback on specific
  25202. * objects.
  25203. *
  25204. * @author Ben Houston / http://clara.io/
  25205. * @author David Sarno / http://lighthaus.us/
  25206. * @author tschw
  25207. *
  25208. */
  25209. function AnimationAction( mixer, clip, localRoot ) {
  25210. this._mixer = mixer;
  25211. this._clip = clip;
  25212. this._localRoot = localRoot || null;
  25213. var tracks = clip.tracks,
  25214. nTracks = tracks.length,
  25215. interpolants = new Array( nTracks );
  25216. var interpolantSettings = {
  25217. endingStart: ZeroCurvatureEnding,
  25218. endingEnd: ZeroCurvatureEnding
  25219. };
  25220. for ( var i = 0; i !== nTracks; ++ i ) {
  25221. var interpolant = tracks[ i ].createInterpolant( null );
  25222. interpolants[ i ] = interpolant;
  25223. interpolant.settings = interpolantSettings;
  25224. }
  25225. this._interpolantSettings = interpolantSettings;
  25226. this._interpolants = interpolants; // bound by the mixer
  25227. // inside: PropertyMixer (managed by the mixer)
  25228. this._propertyBindings = new Array( nTracks );
  25229. this._cacheIndex = null; // for the memory manager
  25230. this._byClipCacheIndex = null; // for the memory manager
  25231. this._timeScaleInterpolant = null;
  25232. this._weightInterpolant = null;
  25233. this.loop = LoopRepeat;
  25234. this._loopCount = - 1;
  25235. // global mixer time when the action is to be started
  25236. // it's set back to 'null' upon start of the action
  25237. this._startTime = null;
  25238. // scaled local time of the action
  25239. // gets clamped or wrapped to 0..clip.duration according to loop
  25240. this.time = 0;
  25241. this.timeScale = 1;
  25242. this._effectiveTimeScale = 1;
  25243. this.weight = 1;
  25244. this._effectiveWeight = 1;
  25245. this.repetitions = Infinity; // no. of repetitions when looping
  25246. this.paused = false; // true -> zero effective time scale
  25247. this.enabled = true; // false -> zero effective weight
  25248. this.clampWhenFinished = false;// keep feeding the last frame?
  25249. this.zeroSlopeAtStart = true;// for smooth interpolation w/o separate
  25250. this.zeroSlopeAtEnd = true;// clips for start, loop and end
  25251. }
  25252. Object.assign( AnimationAction.prototype, {
  25253. // State & Scheduling
  25254. play: function () {
  25255. this._mixer._activateAction( this );
  25256. return this;
  25257. },
  25258. stop: function () {
  25259. this._mixer._deactivateAction( this );
  25260. return this.reset();
  25261. },
  25262. reset: function () {
  25263. this.paused = false;
  25264. this.enabled = true;
  25265. this.time = 0; // restart clip
  25266. this._loopCount = - 1;// forget previous loops
  25267. this._startTime = null;// forget scheduling
  25268. return this.stopFading().stopWarping();
  25269. },
  25270. isRunning: function () {
  25271. return this.enabled && ! this.paused && this.timeScale !== 0 &&
  25272. this._startTime === null && this._mixer._isActiveAction( this );
  25273. },
  25274. // return true when play has been called
  25275. isScheduled: function () {
  25276. return this._mixer._isActiveAction( this );
  25277. },
  25278. startAt: function ( time ) {
  25279. this._startTime = time;
  25280. return this;
  25281. },
  25282. setLoop: function ( mode, repetitions ) {
  25283. this.loop = mode;
  25284. this.repetitions = repetitions;
  25285. return this;
  25286. },
  25287. // Weight
  25288. // set the weight stopping any scheduled fading
  25289. // although .enabled = false yields an effective weight of zero, this
  25290. // method does *not* change .enabled, because it would be confusing
  25291. setEffectiveWeight: function ( weight ) {
  25292. this.weight = weight;
  25293. // note: same logic as when updated at runtime
  25294. this._effectiveWeight = this.enabled ? weight : 0;
  25295. return this.stopFading();
  25296. },
  25297. // return the weight considering fading and .enabled
  25298. getEffectiveWeight: function () {
  25299. return this._effectiveWeight;
  25300. },
  25301. fadeIn: function ( duration ) {
  25302. return this._scheduleFading( duration, 0, 1 );
  25303. },
  25304. fadeOut: function ( duration ) {
  25305. return this._scheduleFading( duration, 1, 0 );
  25306. },
  25307. crossFadeFrom: function ( fadeOutAction, duration, warp ) {
  25308. fadeOutAction.fadeOut( duration );
  25309. this.fadeIn( duration );
  25310. if ( warp ) {
  25311. var fadeInDuration = this._clip.duration,
  25312. fadeOutDuration = fadeOutAction._clip.duration,
  25313. startEndRatio = fadeOutDuration / fadeInDuration,
  25314. endStartRatio = fadeInDuration / fadeOutDuration;
  25315. fadeOutAction.warp( 1.0, startEndRatio, duration );
  25316. this.warp( endStartRatio, 1.0, duration );
  25317. }
  25318. return this;
  25319. },
  25320. crossFadeTo: function ( fadeInAction, duration, warp ) {
  25321. return fadeInAction.crossFadeFrom( this, duration, warp );
  25322. },
  25323. stopFading: function () {
  25324. var weightInterpolant = this._weightInterpolant;
  25325. if ( weightInterpolant !== null ) {
  25326. this._weightInterpolant = null;
  25327. this._mixer._takeBackControlInterpolant( weightInterpolant );
  25328. }
  25329. return this;
  25330. },
  25331. // Time Scale Control
  25332. // set the time scale stopping any scheduled warping
  25333. // although .paused = true yields an effective time scale of zero, this
  25334. // method does *not* change .paused, because it would be confusing
  25335. setEffectiveTimeScale: function ( timeScale ) {
  25336. this.timeScale = timeScale;
  25337. this._effectiveTimeScale = this.paused ? 0 : timeScale;
  25338. return this.stopWarping();
  25339. },
  25340. // return the time scale considering warping and .paused
  25341. getEffectiveTimeScale: function () {
  25342. return this._effectiveTimeScale;
  25343. },
  25344. setDuration: function ( duration ) {
  25345. this.timeScale = this._clip.duration / duration;
  25346. return this.stopWarping();
  25347. },
  25348. syncWith: function ( action ) {
  25349. this.time = action.time;
  25350. this.timeScale = action.timeScale;
  25351. return this.stopWarping();
  25352. },
  25353. halt: function ( duration ) {
  25354. return this.warp( this._effectiveTimeScale, 0, duration );
  25355. },
  25356. warp: function ( startTimeScale, endTimeScale, duration ) {
  25357. var mixer = this._mixer, now = mixer.time,
  25358. interpolant = this._timeScaleInterpolant,
  25359. timeScale = this.timeScale;
  25360. if ( interpolant === null ) {
  25361. interpolant = mixer._lendControlInterpolant();
  25362. this._timeScaleInterpolant = interpolant;
  25363. }
  25364. var times = interpolant.parameterPositions,
  25365. values = interpolant.sampleValues;
  25366. times[ 0 ] = now;
  25367. times[ 1 ] = now + duration;
  25368. values[ 0 ] = startTimeScale / timeScale;
  25369. values[ 1 ] = endTimeScale / timeScale;
  25370. return this;
  25371. },
  25372. stopWarping: function () {
  25373. var timeScaleInterpolant = this._timeScaleInterpolant;
  25374. if ( timeScaleInterpolant !== null ) {
  25375. this._timeScaleInterpolant = null;
  25376. this._mixer._takeBackControlInterpolant( timeScaleInterpolant );
  25377. }
  25378. return this;
  25379. },
  25380. // Object Accessors
  25381. getMixer: function () {
  25382. return this._mixer;
  25383. },
  25384. getClip: function () {
  25385. return this._clip;
  25386. },
  25387. getRoot: function () {
  25388. return this._localRoot || this._mixer._root;
  25389. },
  25390. // Interna
  25391. _update: function ( time, deltaTime, timeDirection, accuIndex ) {
  25392. // called by the mixer
  25393. if ( ! this.enabled ) {
  25394. // call ._updateWeight() to update ._effectiveWeight
  25395. this._updateWeight( time );
  25396. return;
  25397. }
  25398. var startTime = this._startTime;
  25399. if ( startTime !== null ) {
  25400. // check for scheduled start of action
  25401. var timeRunning = ( time - startTime ) * timeDirection;
  25402. if ( timeRunning < 0 || timeDirection === 0 ) {
  25403. return; // yet to come / don't decide when delta = 0
  25404. }
  25405. // start
  25406. this._startTime = null; // unschedule
  25407. deltaTime = timeDirection * timeRunning;
  25408. }
  25409. // apply time scale and advance time
  25410. deltaTime *= this._updateTimeScale( time );
  25411. var clipTime = this._updateTime( deltaTime );
  25412. // note: _updateTime may disable the action resulting in
  25413. // an effective weight of 0
  25414. var weight = this._updateWeight( time );
  25415. if ( weight > 0 ) {
  25416. var interpolants = this._interpolants;
  25417. var propertyMixers = this._propertyBindings;
  25418. for ( var j = 0, m = interpolants.length; j !== m; ++ j ) {
  25419. interpolants[ j ].evaluate( clipTime );
  25420. propertyMixers[ j ].accumulate( accuIndex, weight );
  25421. }
  25422. }
  25423. },
  25424. _updateWeight: function ( time ) {
  25425. var weight = 0;
  25426. if ( this.enabled ) {
  25427. weight = this.weight;
  25428. var interpolant = this._weightInterpolant;
  25429. if ( interpolant !== null ) {
  25430. var interpolantValue = interpolant.evaluate( time )[ 0 ];
  25431. weight *= interpolantValue;
  25432. if ( time > interpolant.parameterPositions[ 1 ] ) {
  25433. this.stopFading();
  25434. if ( interpolantValue === 0 ) {
  25435. // faded out, disable
  25436. this.enabled = false;
  25437. }
  25438. }
  25439. }
  25440. }
  25441. this._effectiveWeight = weight;
  25442. return weight;
  25443. },
  25444. _updateTimeScale: function ( time ) {
  25445. var timeScale = 0;
  25446. if ( ! this.paused ) {
  25447. timeScale = this.timeScale;
  25448. var interpolant = this._timeScaleInterpolant;
  25449. if ( interpolant !== null ) {
  25450. var interpolantValue = interpolant.evaluate( time )[ 0 ];
  25451. timeScale *= interpolantValue;
  25452. if ( time > interpolant.parameterPositions[ 1 ] ) {
  25453. this.stopWarping();
  25454. if ( timeScale === 0 ) {
  25455. // motion has halted, pause
  25456. this.paused = true;
  25457. } else {
  25458. // warp done - apply final time scale
  25459. this.timeScale = timeScale;
  25460. }
  25461. }
  25462. }
  25463. }
  25464. this._effectiveTimeScale = timeScale;
  25465. return timeScale;
  25466. },
  25467. _updateTime: function ( deltaTime ) {
  25468. var time = this.time + deltaTime;
  25469. var duration = this._clip.duration;
  25470. var loop = this.loop;
  25471. var loopCount = this._loopCount;
  25472. var pingPong = ( loop === LoopPingPong );
  25473. if ( deltaTime === 0 ) {
  25474. if ( loopCount === - 1 ) return time;
  25475. return ( pingPong && ( loopCount & 1 ) === 1 ) ? duration - time : time;
  25476. }
  25477. if ( loop === LoopOnce ) {
  25478. if ( loopCount === - 1 ) {
  25479. // just started
  25480. this._loopCount = 0;
  25481. this._setEndings( true, true, false );
  25482. }
  25483. handle_stop: {
  25484. if ( time >= duration ) {
  25485. time = duration;
  25486. } else if ( time < 0 ) {
  25487. time = 0;
  25488. } else break handle_stop;
  25489. if ( this.clampWhenFinished ) this.paused = true;
  25490. else this.enabled = false;
  25491. this._mixer.dispatchEvent( {
  25492. type: 'finished', action: this,
  25493. direction: deltaTime < 0 ? - 1 : 1
  25494. } );
  25495. }
  25496. } else { // repetitive Repeat or PingPong
  25497. if ( loopCount === - 1 ) {
  25498. // just started
  25499. if ( deltaTime >= 0 ) {
  25500. loopCount = 0;
  25501. this._setEndings( true, this.repetitions === 0, pingPong );
  25502. } else {
  25503. // when looping in reverse direction, the initial
  25504. // transition through zero counts as a repetition,
  25505. // so leave loopCount at -1
  25506. this._setEndings( this.repetitions === 0, true, pingPong );
  25507. }
  25508. }
  25509. if ( time >= duration || time < 0 ) {
  25510. // wrap around
  25511. var loopDelta = Math.floor( time / duration ); // signed
  25512. time -= duration * loopDelta;
  25513. loopCount += Math.abs( loopDelta );
  25514. var pending = this.repetitions - loopCount;
  25515. if ( pending <= 0 ) {
  25516. // have to stop (switch state, clamp time, fire event)
  25517. if ( this.clampWhenFinished ) this.paused = true;
  25518. else this.enabled = false;
  25519. time = deltaTime > 0 ? duration : 0;
  25520. this._mixer.dispatchEvent( {
  25521. type: 'finished', action: this,
  25522. direction: deltaTime > 0 ? 1 : - 1
  25523. } );
  25524. } else {
  25525. // keep running
  25526. if ( pending === 1 ) {
  25527. // entering the last round
  25528. var atStart = deltaTime < 0;
  25529. this._setEndings( atStart, ! atStart, pingPong );
  25530. } else {
  25531. this._setEndings( false, false, pingPong );
  25532. }
  25533. this._loopCount = loopCount;
  25534. this._mixer.dispatchEvent( {
  25535. type: 'loop', action: this, loopDelta: loopDelta
  25536. } );
  25537. }
  25538. }
  25539. if ( pingPong && ( loopCount & 1 ) === 1 ) {
  25540. // invert time for the "pong round"
  25541. this.time = time;
  25542. return duration - time;
  25543. }
  25544. }
  25545. this.time = time;
  25546. return time;
  25547. },
  25548. _setEndings: function ( atStart, atEnd, pingPong ) {
  25549. var settings = this._interpolantSettings;
  25550. if ( pingPong ) {
  25551. settings.endingStart = ZeroSlopeEnding;
  25552. settings.endingEnd = ZeroSlopeEnding;
  25553. } else {
  25554. // assuming for LoopOnce atStart == atEnd == true
  25555. if ( atStart ) {
  25556. settings.endingStart = this.zeroSlopeAtStart ? ZeroSlopeEnding : ZeroCurvatureEnding;
  25557. } else {
  25558. settings.endingStart = WrapAroundEnding;
  25559. }
  25560. if ( atEnd ) {
  25561. settings.endingEnd = this.zeroSlopeAtEnd ? ZeroSlopeEnding : ZeroCurvatureEnding;
  25562. } else {
  25563. settings.endingEnd = WrapAroundEnding;
  25564. }
  25565. }
  25566. },
  25567. _scheduleFading: function ( duration, weightNow, weightThen ) {
  25568. var mixer = this._mixer, now = mixer.time,
  25569. interpolant = this._weightInterpolant;
  25570. if ( interpolant === null ) {
  25571. interpolant = mixer._lendControlInterpolant();
  25572. this._weightInterpolant = interpolant;
  25573. }
  25574. var times = interpolant.parameterPositions,
  25575. values = interpolant.sampleValues;
  25576. times[ 0 ] = now;
  25577. values[ 0 ] = weightNow;
  25578. times[ 1 ] = now + duration;
  25579. values[ 1 ] = weightThen;
  25580. return this;
  25581. }
  25582. } );
  25583. /**
  25584. *
  25585. * Player for AnimationClips.
  25586. *
  25587. *
  25588. * @author Ben Houston / http://clara.io/
  25589. * @author David Sarno / http://lighthaus.us/
  25590. * @author tschw
  25591. */
  25592. function AnimationMixer( root ) {
  25593. this._root = root;
  25594. this._initMemoryManager();
  25595. this._accuIndex = 0;
  25596. this.time = 0;
  25597. this.timeScale = 1.0;
  25598. }
  25599. AnimationMixer.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  25600. constructor: AnimationMixer,
  25601. _bindAction: function ( action, prototypeAction ) {
  25602. var root = action._localRoot || this._root,
  25603. tracks = action._clip.tracks,
  25604. nTracks = tracks.length,
  25605. bindings = action._propertyBindings,
  25606. interpolants = action._interpolants,
  25607. rootUuid = root.uuid,
  25608. bindingsByRoot = this._bindingsByRootAndName,
  25609. bindingsByName = bindingsByRoot[ rootUuid ];
  25610. if ( bindingsByName === undefined ) {
  25611. bindingsByName = {};
  25612. bindingsByRoot[ rootUuid ] = bindingsByName;
  25613. }
  25614. for ( var i = 0; i !== nTracks; ++ i ) {
  25615. var track = tracks[ i ],
  25616. trackName = track.name,
  25617. binding = bindingsByName[ trackName ];
  25618. if ( binding !== undefined ) {
  25619. bindings[ i ] = binding;
  25620. } else {
  25621. binding = bindings[ i ];
  25622. if ( binding !== undefined ) {
  25623. // existing binding, make sure the cache knows
  25624. if ( binding._cacheIndex === null ) {
  25625. ++ binding.referenceCount;
  25626. this._addInactiveBinding( binding, rootUuid, trackName );
  25627. }
  25628. continue;
  25629. }
  25630. var path = prototypeAction && prototypeAction.
  25631. _propertyBindings[ i ].binding.parsedPath;
  25632. binding = new PropertyMixer(
  25633. PropertyBinding.create( root, trackName, path ),
  25634. track.ValueTypeName, track.getValueSize() );
  25635. ++ binding.referenceCount;
  25636. this._addInactiveBinding( binding, rootUuid, trackName );
  25637. bindings[ i ] = binding;
  25638. }
  25639. interpolants[ i ].resultBuffer = binding.buffer;
  25640. }
  25641. },
  25642. _activateAction: function ( action ) {
  25643. if ( ! this._isActiveAction( action ) ) {
  25644. if ( action._cacheIndex === null ) {
  25645. // this action has been forgotten by the cache, but the user
  25646. // appears to be still using it -> rebind
  25647. var rootUuid = ( action._localRoot || this._root ).uuid,
  25648. clipUuid = action._clip.uuid,
  25649. actionsForClip = this._actionsByClip[ clipUuid ];
  25650. this._bindAction( action,
  25651. actionsForClip && actionsForClip.knownActions[ 0 ] );
  25652. this._addInactiveAction( action, clipUuid, rootUuid );
  25653. }
  25654. var bindings = action._propertyBindings;
  25655. // increment reference counts / sort out state
  25656. for ( var i = 0, n = bindings.length; i !== n; ++ i ) {
  25657. var binding = bindings[ i ];
  25658. if ( binding.useCount ++ === 0 ) {
  25659. this._lendBinding( binding );
  25660. binding.saveOriginalState();
  25661. }
  25662. }
  25663. this._lendAction( action );
  25664. }
  25665. },
  25666. _deactivateAction: function ( action ) {
  25667. if ( this._isActiveAction( action ) ) {
  25668. var bindings = action._propertyBindings;
  25669. // decrement reference counts / sort out state
  25670. for ( var i = 0, n = bindings.length; i !== n; ++ i ) {
  25671. var binding = bindings[ i ];
  25672. if ( -- binding.useCount === 0 ) {
  25673. binding.restoreOriginalState();
  25674. this._takeBackBinding( binding );
  25675. }
  25676. }
  25677. this._takeBackAction( action );
  25678. }
  25679. },
  25680. // Memory manager
  25681. _initMemoryManager: function () {
  25682. this._actions = []; // 'nActiveActions' followed by inactive ones
  25683. this._nActiveActions = 0;
  25684. this._actionsByClip = {};
  25685. // inside:
  25686. // {
  25687. // knownActions: Array< AnimationAction > - used as prototypes
  25688. // actionByRoot: AnimationAction - lookup
  25689. // }
  25690. this._bindings = []; // 'nActiveBindings' followed by inactive ones
  25691. this._nActiveBindings = 0;
  25692. this._bindingsByRootAndName = {}; // inside: Map< name, PropertyMixer >
  25693. this._controlInterpolants = []; // same game as above
  25694. this._nActiveControlInterpolants = 0;
  25695. var scope = this;
  25696. this.stats = {
  25697. actions: {
  25698. get total() {
  25699. return scope._actions.length;
  25700. },
  25701. get inUse() {
  25702. return scope._nActiveActions;
  25703. }
  25704. },
  25705. bindings: {
  25706. get total() {
  25707. return scope._bindings.length;
  25708. },
  25709. get inUse() {
  25710. return scope._nActiveBindings;
  25711. }
  25712. },
  25713. controlInterpolants: {
  25714. get total() {
  25715. return scope._controlInterpolants.length;
  25716. },
  25717. get inUse() {
  25718. return scope._nActiveControlInterpolants;
  25719. }
  25720. }
  25721. };
  25722. },
  25723. // Memory management for AnimationAction objects
  25724. _isActiveAction: function ( action ) {
  25725. var index = action._cacheIndex;
  25726. return index !== null && index < this._nActiveActions;
  25727. },
  25728. _addInactiveAction: function ( action, clipUuid, rootUuid ) {
  25729. var actions = this._actions,
  25730. actionsByClip = this._actionsByClip,
  25731. actionsForClip = actionsByClip[ clipUuid ];
  25732. if ( actionsForClip === undefined ) {
  25733. actionsForClip = {
  25734. knownActions: [ action ],
  25735. actionByRoot: {}
  25736. };
  25737. action._byClipCacheIndex = 0;
  25738. actionsByClip[ clipUuid ] = actionsForClip;
  25739. } else {
  25740. var knownActions = actionsForClip.knownActions;
  25741. action._byClipCacheIndex = knownActions.length;
  25742. knownActions.push( action );
  25743. }
  25744. action._cacheIndex = actions.length;
  25745. actions.push( action );
  25746. actionsForClip.actionByRoot[ rootUuid ] = action;
  25747. },
  25748. _removeInactiveAction: function ( action ) {
  25749. var actions = this._actions,
  25750. lastInactiveAction = actions[ actions.length - 1 ],
  25751. cacheIndex = action._cacheIndex;
  25752. lastInactiveAction._cacheIndex = cacheIndex;
  25753. actions[ cacheIndex ] = lastInactiveAction;
  25754. actions.pop();
  25755. action._cacheIndex = null;
  25756. var clipUuid = action._clip.uuid,
  25757. actionsByClip = this._actionsByClip,
  25758. actionsForClip = actionsByClip[ clipUuid ],
  25759. knownActionsForClip = actionsForClip.knownActions,
  25760. lastKnownAction =
  25761. knownActionsForClip[ knownActionsForClip.length - 1 ],
  25762. byClipCacheIndex = action._byClipCacheIndex;
  25763. lastKnownAction._byClipCacheIndex = byClipCacheIndex;
  25764. knownActionsForClip[ byClipCacheIndex ] = lastKnownAction;
  25765. knownActionsForClip.pop();
  25766. action._byClipCacheIndex = null;
  25767. var actionByRoot = actionsForClip.actionByRoot,
  25768. rootUuid = ( action._localRoot || this._root ).uuid;
  25769. delete actionByRoot[ rootUuid ];
  25770. if ( knownActionsForClip.length === 0 ) {
  25771. delete actionsByClip[ clipUuid ];
  25772. }
  25773. this._removeInactiveBindingsForAction( action );
  25774. },
  25775. _removeInactiveBindingsForAction: function ( action ) {
  25776. var bindings = action._propertyBindings;
  25777. for ( var i = 0, n = bindings.length; i !== n; ++ i ) {
  25778. var binding = bindings[ i ];
  25779. if ( -- binding.referenceCount === 0 ) {
  25780. this._removeInactiveBinding( binding );
  25781. }
  25782. }
  25783. },
  25784. _lendAction: function ( action ) {
  25785. // [ active actions | inactive actions ]
  25786. // [ active actions >| inactive actions ]
  25787. // s a
  25788. // <-swap->
  25789. // a s
  25790. var actions = this._actions,
  25791. prevIndex = action._cacheIndex,
  25792. lastActiveIndex = this._nActiveActions ++,
  25793. firstInactiveAction = actions[ lastActiveIndex ];
  25794. action._cacheIndex = lastActiveIndex;
  25795. actions[ lastActiveIndex ] = action;
  25796. firstInactiveAction._cacheIndex = prevIndex;
  25797. actions[ prevIndex ] = firstInactiveAction;
  25798. },
  25799. _takeBackAction: function ( action ) {
  25800. // [ active actions | inactive actions ]
  25801. // [ active actions |< inactive actions ]
  25802. // a s
  25803. // <-swap->
  25804. // s a
  25805. var actions = this._actions,
  25806. prevIndex = action._cacheIndex,
  25807. firstInactiveIndex = -- this._nActiveActions,
  25808. lastActiveAction = actions[ firstInactiveIndex ];
  25809. action._cacheIndex = firstInactiveIndex;
  25810. actions[ firstInactiveIndex ] = action;
  25811. lastActiveAction._cacheIndex = prevIndex;
  25812. actions[ prevIndex ] = lastActiveAction;
  25813. },
  25814. // Memory management for PropertyMixer objects
  25815. _addInactiveBinding: function ( binding, rootUuid, trackName ) {
  25816. var bindingsByRoot = this._bindingsByRootAndName,
  25817. bindingByName = bindingsByRoot[ rootUuid ],
  25818. bindings = this._bindings;
  25819. if ( bindingByName === undefined ) {
  25820. bindingByName = {};
  25821. bindingsByRoot[ rootUuid ] = bindingByName;
  25822. }
  25823. bindingByName[ trackName ] = binding;
  25824. binding._cacheIndex = bindings.length;
  25825. bindings.push( binding );
  25826. },
  25827. _removeInactiveBinding: function ( binding ) {
  25828. var bindings = this._bindings,
  25829. propBinding = binding.binding,
  25830. rootUuid = propBinding.rootNode.uuid,
  25831. trackName = propBinding.path,
  25832. bindingsByRoot = this._bindingsByRootAndName,
  25833. bindingByName = bindingsByRoot[ rootUuid ],
  25834. lastInactiveBinding = bindings[ bindings.length - 1 ],
  25835. cacheIndex = binding._cacheIndex;
  25836. lastInactiveBinding._cacheIndex = cacheIndex;
  25837. bindings[ cacheIndex ] = lastInactiveBinding;
  25838. bindings.pop();
  25839. delete bindingByName[ trackName ];
  25840. remove_empty_map: {
  25841. for ( var _ in bindingByName ) break remove_empty_map; // eslint-disable-line no-unused-vars
  25842. delete bindingsByRoot[ rootUuid ];
  25843. }
  25844. },
  25845. _lendBinding: function ( binding ) {
  25846. var bindings = this._bindings,
  25847. prevIndex = binding._cacheIndex,
  25848. lastActiveIndex = this._nActiveBindings ++,
  25849. firstInactiveBinding = bindings[ lastActiveIndex ];
  25850. binding._cacheIndex = lastActiveIndex;
  25851. bindings[ lastActiveIndex ] = binding;
  25852. firstInactiveBinding._cacheIndex = prevIndex;
  25853. bindings[ prevIndex ] = firstInactiveBinding;
  25854. },
  25855. _takeBackBinding: function ( binding ) {
  25856. var bindings = this._bindings,
  25857. prevIndex = binding._cacheIndex,
  25858. firstInactiveIndex = -- this._nActiveBindings,
  25859. lastActiveBinding = bindings[ firstInactiveIndex ];
  25860. binding._cacheIndex = firstInactiveIndex;
  25861. bindings[ firstInactiveIndex ] = binding;
  25862. lastActiveBinding._cacheIndex = prevIndex;
  25863. bindings[ prevIndex ] = lastActiveBinding;
  25864. },
  25865. // Memory management of Interpolants for weight and time scale
  25866. _lendControlInterpolant: function () {
  25867. var interpolants = this._controlInterpolants,
  25868. lastActiveIndex = this._nActiveControlInterpolants ++,
  25869. interpolant = interpolants[ lastActiveIndex ];
  25870. if ( interpolant === undefined ) {
  25871. interpolant = new LinearInterpolant(
  25872. new Float32Array( 2 ), new Float32Array( 2 ),
  25873. 1, this._controlInterpolantsResultBuffer );
  25874. interpolant.__cacheIndex = lastActiveIndex;
  25875. interpolants[ lastActiveIndex ] = interpolant;
  25876. }
  25877. return interpolant;
  25878. },
  25879. _takeBackControlInterpolant: function ( interpolant ) {
  25880. var interpolants = this._controlInterpolants,
  25881. prevIndex = interpolant.__cacheIndex,
  25882. firstInactiveIndex = -- this._nActiveControlInterpolants,
  25883. lastActiveInterpolant = interpolants[ firstInactiveIndex ];
  25884. interpolant.__cacheIndex = firstInactiveIndex;
  25885. interpolants[ firstInactiveIndex ] = interpolant;
  25886. lastActiveInterpolant.__cacheIndex = prevIndex;
  25887. interpolants[ prevIndex ] = lastActiveInterpolant;
  25888. },
  25889. _controlInterpolantsResultBuffer: new Float32Array( 1 ),
  25890. // return an action for a clip optionally using a custom root target
  25891. // object (this method allocates a lot of dynamic memory in case a
  25892. // previously unknown clip/root combination is specified)
  25893. clipAction: function ( clip, optionalRoot ) {
  25894. var root = optionalRoot || this._root,
  25895. rootUuid = root.uuid,
  25896. clipObject = typeof clip === 'string' ?
  25897. AnimationClip.findByName( root, clip ) : clip,
  25898. clipUuid = clipObject !== null ? clipObject.uuid : clip,
  25899. actionsForClip = this._actionsByClip[ clipUuid ],
  25900. prototypeAction = null;
  25901. if ( actionsForClip !== undefined ) {
  25902. var existingAction =
  25903. actionsForClip.actionByRoot[ rootUuid ];
  25904. if ( existingAction !== undefined ) {
  25905. return existingAction;
  25906. }
  25907. // we know the clip, so we don't have to parse all
  25908. // the bindings again but can just copy
  25909. prototypeAction = actionsForClip.knownActions[ 0 ];
  25910. // also, take the clip from the prototype action
  25911. if ( clipObject === null )
  25912. clipObject = prototypeAction._clip;
  25913. }
  25914. // clip must be known when specified via string
  25915. if ( clipObject === null ) return null;
  25916. // allocate all resources required to run it
  25917. var newAction = new AnimationAction( this, clipObject, optionalRoot );
  25918. this._bindAction( newAction, prototypeAction );
  25919. // and make the action known to the memory manager
  25920. this._addInactiveAction( newAction, clipUuid, rootUuid );
  25921. return newAction;
  25922. },
  25923. // get an existing action
  25924. existingAction: function ( clip, optionalRoot ) {
  25925. var root = optionalRoot || this._root,
  25926. rootUuid = root.uuid,
  25927. clipObject = typeof clip === 'string' ?
  25928. AnimationClip.findByName( root, clip ) : clip,
  25929. clipUuid = clipObject ? clipObject.uuid : clip,
  25930. actionsForClip = this._actionsByClip[ clipUuid ];
  25931. if ( actionsForClip !== undefined ) {
  25932. return actionsForClip.actionByRoot[ rootUuid ] || null;
  25933. }
  25934. return null;
  25935. },
  25936. // deactivates all previously scheduled actions
  25937. stopAllAction: function () {
  25938. var actions = this._actions,
  25939. nActions = this._nActiveActions,
  25940. bindings = this._bindings,
  25941. nBindings = this._nActiveBindings;
  25942. this._nActiveActions = 0;
  25943. this._nActiveBindings = 0;
  25944. for ( var i = 0; i !== nActions; ++ i ) {
  25945. actions[ i ].reset();
  25946. }
  25947. for ( var i = 0; i !== nBindings; ++ i ) {
  25948. bindings[ i ].useCount = 0;
  25949. }
  25950. return this;
  25951. },
  25952. // advance the time and update apply the animation
  25953. update: function ( deltaTime ) {
  25954. deltaTime *= this.timeScale;
  25955. var actions = this._actions,
  25956. nActions = this._nActiveActions,
  25957. time = this.time += deltaTime,
  25958. timeDirection = Math.sign( deltaTime ),
  25959. accuIndex = this._accuIndex ^= 1;
  25960. // run active actions
  25961. for ( var i = 0; i !== nActions; ++ i ) {
  25962. var action = actions[ i ];
  25963. action._update( time, deltaTime, timeDirection, accuIndex );
  25964. }
  25965. // update scene graph
  25966. var bindings = this._bindings,
  25967. nBindings = this._nActiveBindings;
  25968. for ( var i = 0; i !== nBindings; ++ i ) {
  25969. bindings[ i ].apply( accuIndex );
  25970. }
  25971. return this;
  25972. },
  25973. // return this mixer's root target object
  25974. getRoot: function () {
  25975. return this._root;
  25976. },
  25977. // free all resources specific to a particular clip
  25978. uncacheClip: function ( clip ) {
  25979. var actions = this._actions,
  25980. clipUuid = clip.uuid,
  25981. actionsByClip = this._actionsByClip,
  25982. actionsForClip = actionsByClip[ clipUuid ];
  25983. if ( actionsForClip !== undefined ) {
  25984. // note: just calling _removeInactiveAction would mess up the
  25985. // iteration state and also require updating the state we can
  25986. // just throw away
  25987. var actionsToRemove = actionsForClip.knownActions;
  25988. for ( var i = 0, n = actionsToRemove.length; i !== n; ++ i ) {
  25989. var action = actionsToRemove[ i ];
  25990. this._deactivateAction( action );
  25991. var cacheIndex = action._cacheIndex,
  25992. lastInactiveAction = actions[ actions.length - 1 ];
  25993. action._cacheIndex = null;
  25994. action._byClipCacheIndex = null;
  25995. lastInactiveAction._cacheIndex = cacheIndex;
  25996. actions[ cacheIndex ] = lastInactiveAction;
  25997. actions.pop();
  25998. this._removeInactiveBindingsForAction( action );
  25999. }
  26000. delete actionsByClip[ clipUuid ];
  26001. }
  26002. },
  26003. // free all resources specific to a particular root target object
  26004. uncacheRoot: function ( root ) {
  26005. var rootUuid = root.uuid,
  26006. actionsByClip = this._actionsByClip;
  26007. for ( var clipUuid in actionsByClip ) {
  26008. var actionByRoot = actionsByClip[ clipUuid ].actionByRoot,
  26009. action = actionByRoot[ rootUuid ];
  26010. if ( action !== undefined ) {
  26011. this._deactivateAction( action );
  26012. this._removeInactiveAction( action );
  26013. }
  26014. }
  26015. var bindingsByRoot = this._bindingsByRootAndName,
  26016. bindingByName = bindingsByRoot[ rootUuid ];
  26017. if ( bindingByName !== undefined ) {
  26018. for ( var trackName in bindingByName ) {
  26019. var binding = bindingByName[ trackName ];
  26020. binding.restoreOriginalState();
  26021. this._removeInactiveBinding( binding );
  26022. }
  26023. }
  26024. },
  26025. // remove a targeted clip from the cache
  26026. uncacheAction: function ( clip, optionalRoot ) {
  26027. var action = this.existingAction( clip, optionalRoot );
  26028. if ( action !== null ) {
  26029. this._deactivateAction( action );
  26030. this._removeInactiveAction( action );
  26031. }
  26032. }
  26033. } );
  26034. /**
  26035. * @author mrdoob / http://mrdoob.com/
  26036. */
  26037. function Uniform( value ) {
  26038. if ( typeof value === 'string' ) {
  26039. console.warn( 'THREE.Uniform: Type parameter is no longer needed.' );
  26040. value = arguments[ 1 ];
  26041. }
  26042. this.value = value;
  26043. }
  26044. Uniform.prototype.clone = function () {
  26045. return new Uniform( this.value.clone === undefined ? this.value : this.value.clone() );
  26046. };
  26047. /**
  26048. * @author benaadams / https://twitter.com/ben_a_adams
  26049. */
  26050. function InstancedBufferGeometry() {
  26051. BufferGeometry.call( this );
  26052. this.type = 'InstancedBufferGeometry';
  26053. this.maxInstancedCount = undefined;
  26054. }
  26055. InstancedBufferGeometry.prototype = Object.assign( Object.create( BufferGeometry.prototype ), {
  26056. constructor: InstancedBufferGeometry,
  26057. isInstancedBufferGeometry: true,
  26058. copy: function ( source ) {
  26059. BufferGeometry.prototype.copy.call( this, source );
  26060. this.maxInstancedCount = source.maxInstancedCount;
  26061. return this;
  26062. },
  26063. clone: function () {
  26064. return new this.constructor().copy( this );
  26065. }
  26066. } );
  26067. /**
  26068. * @author benaadams / https://twitter.com/ben_a_adams
  26069. */
  26070. function InstancedInterleavedBuffer( array, stride, meshPerAttribute ) {
  26071. InterleavedBuffer.call( this, array, stride );
  26072. this.meshPerAttribute = meshPerAttribute || 1;
  26073. }
  26074. InstancedInterleavedBuffer.prototype = Object.assign( Object.create( InterleavedBuffer.prototype ), {
  26075. constructor: InstancedInterleavedBuffer,
  26076. isInstancedInterleavedBuffer: true,
  26077. copy: function ( source ) {
  26078. InterleavedBuffer.prototype.copy.call( this, source );
  26079. this.meshPerAttribute = source.meshPerAttribute;
  26080. return this;
  26081. }
  26082. } );
  26083. /**
  26084. * @author benaadams / https://twitter.com/ben_a_adams
  26085. */
  26086. function InstancedBufferAttribute( array, itemSize, normalized, meshPerAttribute ) {
  26087. if ( typeof ( normalized ) === 'number' ) {
  26088. meshPerAttribute = normalized;
  26089. normalized = false;
  26090. console.error( 'THREE.InstancedBufferAttribute: The constructor now expects normalized as the third argument.' );
  26091. }
  26092. BufferAttribute.call( this, array, itemSize, normalized );
  26093. this.meshPerAttribute = meshPerAttribute || 1;
  26094. }
  26095. InstancedBufferAttribute.prototype = Object.assign( Object.create( BufferAttribute.prototype ), {
  26096. constructor: InstancedBufferAttribute,
  26097. isInstancedBufferAttribute: true,
  26098. copy: function ( source ) {
  26099. BufferAttribute.prototype.copy.call( this, source );
  26100. this.meshPerAttribute = source.meshPerAttribute;
  26101. return this;
  26102. }
  26103. } );
  26104. /**
  26105. * @author mrdoob / http://mrdoob.com/
  26106. * @author bhouston / http://clara.io/
  26107. * @author stephomi / http://stephaneginier.com/
  26108. */
  26109. function Raycaster( origin, direction, near, far ) {
  26110. this.ray = new Ray( origin, direction );
  26111. // direction is assumed to be normalized (for accurate distance calculations)
  26112. this.near = near || 0;
  26113. this.far = far || Infinity;
  26114. this.params = {
  26115. Mesh: {},
  26116. Line: {},
  26117. LOD: {},
  26118. Points: { threshold: 1 },
  26119. Sprite: {}
  26120. };
  26121. Object.defineProperties( this.params, {
  26122. PointCloud: {
  26123. get: function () {
  26124. console.warn( 'THREE.Raycaster: params.PointCloud has been renamed to params.Points.' );
  26125. return this.Points;
  26126. }
  26127. }
  26128. } );
  26129. }
  26130. function ascSort( a, b ) {
  26131. return a.distance - b.distance;
  26132. }
  26133. function intersectObject( object, raycaster, intersects, recursive ) {
  26134. if ( object.visible === false ) return;
  26135. object.raycast( raycaster, intersects );
  26136. if ( recursive === true ) {
  26137. var children = object.children;
  26138. for ( var i = 0, l = children.length; i < l; i ++ ) {
  26139. intersectObject( children[ i ], raycaster, intersects, true );
  26140. }
  26141. }
  26142. }
  26143. Object.assign( Raycaster.prototype, {
  26144. linePrecision: 1,
  26145. set: function ( origin, direction ) {
  26146. // direction is assumed to be normalized (for accurate distance calculations)
  26147. this.ray.set( origin, direction );
  26148. },
  26149. setFromCamera: function ( coords, camera ) {
  26150. if ( ( camera && camera.isPerspectiveCamera ) ) {
  26151. this.ray.origin.setFromMatrixPosition( camera.matrixWorld );
  26152. this.ray.direction.set( coords.x, coords.y, 0.5 ).unproject( camera ).sub( this.ray.origin ).normalize();
  26153. } else if ( ( camera && camera.isOrthographicCamera ) ) {
  26154. this.ray.origin.set( coords.x, coords.y, ( camera.near + camera.far ) / ( camera.near - camera.far ) ).unproject( camera ); // set origin in plane of camera
  26155. this.ray.direction.set( 0, 0, - 1 ).transformDirection( camera.matrixWorld );
  26156. } else {
  26157. console.error( 'THREE.Raycaster: Unsupported camera type.' );
  26158. }
  26159. },
  26160. intersectObject: function ( object, recursive, optionalTarget ) {
  26161. var intersects = optionalTarget || [];
  26162. intersectObject( object, this, intersects, recursive );
  26163. intersects.sort( ascSort );
  26164. return intersects;
  26165. },
  26166. intersectObjects: function ( objects, recursive, optionalTarget ) {
  26167. var intersects = optionalTarget || [];
  26168. if ( Array.isArray( objects ) === false ) {
  26169. console.warn( 'THREE.Raycaster.intersectObjects: objects is not an Array.' );
  26170. return intersects;
  26171. }
  26172. for ( var i = 0, l = objects.length; i < l; i ++ ) {
  26173. intersectObject( objects[ i ], this, intersects, recursive );
  26174. }
  26175. intersects.sort( ascSort );
  26176. return intersects;
  26177. }
  26178. } );
  26179. /**
  26180. * @author bhouston / http://clara.io
  26181. * @author WestLangley / http://github.com/WestLangley
  26182. *
  26183. * Ref: https://en.wikipedia.org/wiki/Spherical_coordinate_system
  26184. *
  26185. * The polar angle (phi) is measured from the positive y-axis. The positive y-axis is up.
  26186. * The azimuthal angle (theta) is measured from the positive z-axiz.
  26187. */
  26188. function Spherical( radius, phi, theta ) {
  26189. this.radius = ( radius !== undefined ) ? radius : 1.0;
  26190. this.phi = ( phi !== undefined ) ? phi : 0; // polar angle
  26191. this.theta = ( theta !== undefined ) ? theta : 0; // azimuthal angle
  26192. return this;
  26193. }
  26194. Object.assign( Spherical.prototype, {
  26195. set: function ( radius, phi, theta ) {
  26196. this.radius = radius;
  26197. this.phi = phi;
  26198. this.theta = theta;
  26199. return this;
  26200. },
  26201. clone: function () {
  26202. return new this.constructor().copy( this );
  26203. },
  26204. copy: function ( other ) {
  26205. this.radius = other.radius;
  26206. this.phi = other.phi;
  26207. this.theta = other.theta;
  26208. return this;
  26209. },
  26210. // restrict phi to be betwee EPS and PI-EPS
  26211. makeSafe: function () {
  26212. var EPS = 0.000001;
  26213. this.phi = Math.max( EPS, Math.min( Math.PI - EPS, this.phi ) );
  26214. return this;
  26215. },
  26216. setFromVector3: function ( v ) {
  26217. return this.setFromCartesianCoords( v.x, v.y, v.z );
  26218. },
  26219. setFromCartesianCoords: function ( x, y, z ) {
  26220. this.radius = Math.sqrt( x * x + y * y + z * z );
  26221. if ( this.radius === 0 ) {
  26222. this.theta = 0;
  26223. this.phi = 0;
  26224. } else {
  26225. this.theta = Math.atan2( x, z );
  26226. this.phi = Math.acos( _Math.clamp( y / this.radius, - 1, 1 ) );
  26227. }
  26228. return this;
  26229. }
  26230. } );
  26231. /**
  26232. * @author Mugen87 / https://github.com/Mugen87
  26233. *
  26234. * Ref: https://en.wikipedia.org/wiki/Cylindrical_coordinate_system
  26235. *
  26236. */
  26237. function Cylindrical( radius, theta, y ) {
  26238. this.radius = ( radius !== undefined ) ? radius : 1.0; // distance from the origin to a point in the x-z plane
  26239. this.theta = ( theta !== undefined ) ? theta : 0; // counterclockwise angle in the x-z plane measured in radians from the positive z-axis
  26240. this.y = ( y !== undefined ) ? y : 0; // height above the x-z plane
  26241. return this;
  26242. }
  26243. Object.assign( Cylindrical.prototype, {
  26244. set: function ( radius, theta, y ) {
  26245. this.radius = radius;
  26246. this.theta = theta;
  26247. this.y = y;
  26248. return this;
  26249. },
  26250. clone: function () {
  26251. return new this.constructor().copy( this );
  26252. },
  26253. copy: function ( other ) {
  26254. this.radius = other.radius;
  26255. this.theta = other.theta;
  26256. this.y = other.y;
  26257. return this;
  26258. },
  26259. setFromVector3: function ( v ) {
  26260. return this.setFromCartesianCoords( v.x, v.y, v.z );
  26261. },
  26262. setFromCartesianCoords: function ( x, y, z ) {
  26263. this.radius = Math.sqrt( x * x + z * z );
  26264. this.theta = Math.atan2( x, z );
  26265. this.y = y;
  26266. return this;
  26267. }
  26268. } );
  26269. /**
  26270. * @author bhouston / http://clara.io
  26271. */
  26272. function Box2( min, max ) {
  26273. this.min = ( min !== undefined ) ? min : new Vector2( + Infinity, + Infinity );
  26274. this.max = ( max !== undefined ) ? max : new Vector2( - Infinity, - Infinity );
  26275. }
  26276. Object.assign( Box2.prototype, {
  26277. set: function ( min, max ) {
  26278. this.min.copy( min );
  26279. this.max.copy( max );
  26280. return this;
  26281. },
  26282. setFromPoints: function ( points ) {
  26283. this.makeEmpty();
  26284. for ( var i = 0, il = points.length; i < il; i ++ ) {
  26285. this.expandByPoint( points[ i ] );
  26286. }
  26287. return this;
  26288. },
  26289. setFromCenterAndSize: function () {
  26290. var v1 = new Vector2();
  26291. return function setFromCenterAndSize( center, size ) {
  26292. var halfSize = v1.copy( size ).multiplyScalar( 0.5 );
  26293. this.min.copy( center ).sub( halfSize );
  26294. this.max.copy( center ).add( halfSize );
  26295. return this;
  26296. };
  26297. }(),
  26298. clone: function () {
  26299. return new this.constructor().copy( this );
  26300. },
  26301. copy: function ( box ) {
  26302. this.min.copy( box.min );
  26303. this.max.copy( box.max );
  26304. return this;
  26305. },
  26306. makeEmpty: function () {
  26307. this.min.x = this.min.y = + Infinity;
  26308. this.max.x = this.max.y = - Infinity;
  26309. return this;
  26310. },
  26311. isEmpty: function () {
  26312. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  26313. return ( this.max.x < this.min.x ) || ( this.max.y < this.min.y );
  26314. },
  26315. getCenter: function ( target ) {
  26316. if ( target === undefined ) {
  26317. console.warn( 'THREE.Box2: .getCenter() target is now required' );
  26318. target = new Vector2();
  26319. }
  26320. return this.isEmpty() ? target.set( 0, 0 ) : target.addVectors( this.min, this.max ).multiplyScalar( 0.5 );
  26321. },
  26322. getSize: function ( target ) {
  26323. if ( target === undefined ) {
  26324. console.warn( 'THREE.Box2: .getSize() target is now required' );
  26325. target = new Vector2();
  26326. }
  26327. return this.isEmpty() ? target.set( 0, 0 ) : target.subVectors( this.max, this.min );
  26328. },
  26329. expandByPoint: function ( point ) {
  26330. this.min.min( point );
  26331. this.max.max( point );
  26332. return this;
  26333. },
  26334. expandByVector: function ( vector ) {
  26335. this.min.sub( vector );
  26336. this.max.add( vector );
  26337. return this;
  26338. },
  26339. expandByScalar: function ( scalar ) {
  26340. this.min.addScalar( - scalar );
  26341. this.max.addScalar( scalar );
  26342. return this;
  26343. },
  26344. containsPoint: function ( point ) {
  26345. return point.x < this.min.x || point.x > this.max.x ||
  26346. point.y < this.min.y || point.y > this.max.y ? false : true;
  26347. },
  26348. containsBox: function ( box ) {
  26349. return this.min.x <= box.min.x && box.max.x <= this.max.x &&
  26350. this.min.y <= box.min.y && box.max.y <= this.max.y;
  26351. },
  26352. getParameter: function ( point, target ) {
  26353. // This can potentially have a divide by zero if the box
  26354. // has a size dimension of 0.
  26355. if ( target === undefined ) {
  26356. console.warn( 'THREE.Box2: .getParameter() target is now required' );
  26357. target = new Vector2();
  26358. }
  26359. return target.set(
  26360. ( point.x - this.min.x ) / ( this.max.x - this.min.x ),
  26361. ( point.y - this.min.y ) / ( this.max.y - this.min.y )
  26362. );
  26363. },
  26364. intersectsBox: function ( box ) {
  26365. // using 4 splitting planes to rule out intersections
  26366. return box.max.x < this.min.x || box.min.x > this.max.x ||
  26367. box.max.y < this.min.y || box.min.y > this.max.y ? false : true;
  26368. },
  26369. clampPoint: function ( point, target ) {
  26370. if ( target === undefined ) {
  26371. console.warn( 'THREE.Box2: .clampPoint() target is now required' );
  26372. target = new Vector2();
  26373. }
  26374. return target.copy( point ).clamp( this.min, this.max );
  26375. },
  26376. distanceToPoint: function () {
  26377. var v1 = new Vector2();
  26378. return function distanceToPoint( point ) {
  26379. var clampedPoint = v1.copy( point ).clamp( this.min, this.max );
  26380. return clampedPoint.sub( point ).length();
  26381. };
  26382. }(),
  26383. intersect: function ( box ) {
  26384. this.min.max( box.min );
  26385. this.max.min( box.max );
  26386. return this;
  26387. },
  26388. union: function ( box ) {
  26389. this.min.min( box.min );
  26390. this.max.max( box.max );
  26391. return this;
  26392. },
  26393. translate: function ( offset ) {
  26394. this.min.add( offset );
  26395. this.max.add( offset );
  26396. return this;
  26397. },
  26398. equals: function ( box ) {
  26399. return box.min.equals( this.min ) && box.max.equals( this.max );
  26400. }
  26401. } );
  26402. /**
  26403. * @author bhouston / http://clara.io
  26404. */
  26405. function Line3( start, end ) {
  26406. this.start = ( start !== undefined ) ? start : new Vector3();
  26407. this.end = ( end !== undefined ) ? end : new Vector3();
  26408. }
  26409. Object.assign( Line3.prototype, {
  26410. set: function ( start, end ) {
  26411. this.start.copy( start );
  26412. this.end.copy( end );
  26413. return this;
  26414. },
  26415. clone: function () {
  26416. return new this.constructor().copy( this );
  26417. },
  26418. copy: function ( line ) {
  26419. this.start.copy( line.start );
  26420. this.end.copy( line.end );
  26421. return this;
  26422. },
  26423. getCenter: function ( target ) {
  26424. if ( target === undefined ) {
  26425. console.warn( 'THREE.Line3: .getCenter() target is now required' );
  26426. target = new Vector3();
  26427. }
  26428. return target.addVectors( this.start, this.end ).multiplyScalar( 0.5 );
  26429. },
  26430. delta: function ( target ) {
  26431. if ( target === undefined ) {
  26432. console.warn( 'THREE.Line3: .delta() target is now required' );
  26433. target = new Vector3();
  26434. }
  26435. return target.subVectors( this.end, this.start );
  26436. },
  26437. distanceSq: function () {
  26438. return this.start.distanceToSquared( this.end );
  26439. },
  26440. distance: function () {
  26441. return this.start.distanceTo( this.end );
  26442. },
  26443. at: function ( t, target ) {
  26444. if ( target === undefined ) {
  26445. console.warn( 'THREE.Line3: .at() target is now required' );
  26446. target = new Vector3();
  26447. }
  26448. return this.delta( target ).multiplyScalar( t ).add( this.start );
  26449. },
  26450. closestPointToPointParameter: function () {
  26451. var startP = new Vector3();
  26452. var startEnd = new Vector3();
  26453. return function closestPointToPointParameter( point, clampToLine ) {
  26454. startP.subVectors( point, this.start );
  26455. startEnd.subVectors( this.end, this.start );
  26456. var startEnd2 = startEnd.dot( startEnd );
  26457. var startEnd_startP = startEnd.dot( startP );
  26458. var t = startEnd_startP / startEnd2;
  26459. if ( clampToLine ) {
  26460. t = _Math.clamp( t, 0, 1 );
  26461. }
  26462. return t;
  26463. };
  26464. }(),
  26465. closestPointToPoint: function ( point, clampToLine, target ) {
  26466. var t = this.closestPointToPointParameter( point, clampToLine );
  26467. if ( target === undefined ) {
  26468. console.warn( 'THREE.Line3: .closestPointToPoint() target is now required' );
  26469. target = new Vector3();
  26470. }
  26471. return this.delta( target ).multiplyScalar( t ).add( this.start );
  26472. },
  26473. applyMatrix4: function ( matrix ) {
  26474. this.start.applyMatrix4( matrix );
  26475. this.end.applyMatrix4( matrix );
  26476. return this;
  26477. },
  26478. equals: function ( line ) {
  26479. return line.start.equals( this.start ) && line.end.equals( this.end );
  26480. }
  26481. } );
  26482. /**
  26483. * @author alteredq / http://alteredqualia.com/
  26484. */
  26485. function ImmediateRenderObject( material ) {
  26486. Object3D.call( this );
  26487. this.material = material;
  26488. this.render = function ( /* renderCallback */ ) {};
  26489. }
  26490. ImmediateRenderObject.prototype = Object.create( Object3D.prototype );
  26491. ImmediateRenderObject.prototype.constructor = ImmediateRenderObject;
  26492. ImmediateRenderObject.prototype.isImmediateRenderObject = true;
  26493. /**
  26494. * @author mrdoob / http://mrdoob.com/
  26495. * @author WestLangley / http://github.com/WestLangley
  26496. */
  26497. function VertexNormalsHelper( object, size, hex, linewidth ) {
  26498. this.object = object;
  26499. this.size = ( size !== undefined ) ? size : 1;
  26500. var color = ( hex !== undefined ) ? hex : 0xff0000;
  26501. var width = ( linewidth !== undefined ) ? linewidth : 1;
  26502. //
  26503. var nNormals = 0;
  26504. var objGeometry = this.object.geometry;
  26505. if ( objGeometry && objGeometry.isGeometry ) {
  26506. nNormals = objGeometry.faces.length * 3;
  26507. } else if ( objGeometry && objGeometry.isBufferGeometry ) {
  26508. nNormals = objGeometry.attributes.normal.count;
  26509. }
  26510. //
  26511. var geometry = new BufferGeometry();
  26512. var positions = new Float32BufferAttribute( nNormals * 2 * 3, 3 );
  26513. geometry.addAttribute( 'position', positions );
  26514. LineSegments.call( this, geometry, new LineBasicMaterial( { color: color, linewidth: width } ) );
  26515. //
  26516. this.matrixAutoUpdate = false;
  26517. this.update();
  26518. }
  26519. VertexNormalsHelper.prototype = Object.create( LineSegments.prototype );
  26520. VertexNormalsHelper.prototype.constructor = VertexNormalsHelper;
  26521. VertexNormalsHelper.prototype.update = ( function () {
  26522. var v1 = new Vector3();
  26523. var v2 = new Vector3();
  26524. var normalMatrix = new Matrix3();
  26525. return function update() {
  26526. var keys = [ 'a', 'b', 'c' ];
  26527. this.object.updateMatrixWorld( true );
  26528. normalMatrix.getNormalMatrix( this.object.matrixWorld );
  26529. var matrixWorld = this.object.matrixWorld;
  26530. var position = this.geometry.attributes.position;
  26531. //
  26532. var objGeometry = this.object.geometry;
  26533. if ( objGeometry && objGeometry.isGeometry ) {
  26534. var vertices = objGeometry.vertices;
  26535. var faces = objGeometry.faces;
  26536. var idx = 0;
  26537. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  26538. var face = faces[ i ];
  26539. for ( var j = 0, jl = face.vertexNormals.length; j < jl; j ++ ) {
  26540. var vertex = vertices[ face[ keys[ j ] ] ];
  26541. var normal = face.vertexNormals[ j ];
  26542. v1.copy( vertex ).applyMatrix4( matrixWorld );
  26543. v2.copy( normal ).applyMatrix3( normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
  26544. position.setXYZ( idx, v1.x, v1.y, v1.z );
  26545. idx = idx + 1;
  26546. position.setXYZ( idx, v2.x, v2.y, v2.z );
  26547. idx = idx + 1;
  26548. }
  26549. }
  26550. } else if ( objGeometry && objGeometry.isBufferGeometry ) {
  26551. var objPos = objGeometry.attributes.position;
  26552. var objNorm = objGeometry.attributes.normal;
  26553. var idx = 0;
  26554. // for simplicity, ignore index and drawcalls, and render every normal
  26555. for ( var j = 0, jl = objPos.count; j < jl; j ++ ) {
  26556. v1.set( objPos.getX( j ), objPos.getY( j ), objPos.getZ( j ) ).applyMatrix4( matrixWorld );
  26557. v2.set( objNorm.getX( j ), objNorm.getY( j ), objNorm.getZ( j ) );
  26558. v2.applyMatrix3( normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
  26559. position.setXYZ( idx, v1.x, v1.y, v1.z );
  26560. idx = idx + 1;
  26561. position.setXYZ( idx, v2.x, v2.y, v2.z );
  26562. idx = idx + 1;
  26563. }
  26564. }
  26565. position.needsUpdate = true;
  26566. };
  26567. }() );
  26568. /**
  26569. * @author alteredq / http://alteredqualia.com/
  26570. * @author mrdoob / http://mrdoob.com/
  26571. * @author WestLangley / http://github.com/WestLangley
  26572. */
  26573. function SpotLightHelper( light, color ) {
  26574. Object3D.call( this );
  26575. this.light = light;
  26576. this.light.updateMatrixWorld();
  26577. this.matrix = light.matrixWorld;
  26578. this.matrixAutoUpdate = false;
  26579. this.color = color;
  26580. var geometry = new BufferGeometry();
  26581. var positions = [
  26582. 0, 0, 0, 0, 0, 1,
  26583. 0, 0, 0, 1, 0, 1,
  26584. 0, 0, 0, - 1, 0, 1,
  26585. 0, 0, 0, 0, 1, 1,
  26586. 0, 0, 0, 0, - 1, 1
  26587. ];
  26588. for ( var i = 0, j = 1, l = 32; i < l; i ++, j ++ ) {
  26589. var p1 = ( i / l ) * Math.PI * 2;
  26590. var p2 = ( j / l ) * Math.PI * 2;
  26591. positions.push(
  26592. Math.cos( p1 ), Math.sin( p1 ), 1,
  26593. Math.cos( p2 ), Math.sin( p2 ), 1
  26594. );
  26595. }
  26596. geometry.addAttribute( 'position', new Float32BufferAttribute( positions, 3 ) );
  26597. var material = new LineBasicMaterial( { fog: false } );
  26598. this.cone = new LineSegments( geometry, material );
  26599. this.add( this.cone );
  26600. this.update();
  26601. }
  26602. SpotLightHelper.prototype = Object.create( Object3D.prototype );
  26603. SpotLightHelper.prototype.constructor = SpotLightHelper;
  26604. SpotLightHelper.prototype.dispose = function () {
  26605. this.cone.geometry.dispose();
  26606. this.cone.material.dispose();
  26607. };
  26608. SpotLightHelper.prototype.update = function () {
  26609. var vector = new Vector3();
  26610. return function update() {
  26611. this.light.updateMatrixWorld();
  26612. var coneLength = this.light.distance ? this.light.distance : 1000;
  26613. var coneWidth = coneLength * Math.tan( this.light.angle );
  26614. this.cone.scale.set( coneWidth, coneWidth, coneLength );
  26615. vector.setFromMatrixPosition( this.light.target.matrixWorld );
  26616. this.cone.lookAt( vector );
  26617. if ( this.color !== undefined ) {
  26618. this.cone.material.color.set( this.color );
  26619. } else {
  26620. this.cone.material.color.copy( this.light.color );
  26621. }
  26622. };
  26623. }();
  26624. /**
  26625. * @author Sean Griffin / http://twitter.com/sgrif
  26626. * @author Michael Guerrero / http://realitymeltdown.com
  26627. * @author mrdoob / http://mrdoob.com/
  26628. * @author ikerr / http://verold.com
  26629. * @author Mugen87 / https://github.com/Mugen87
  26630. */
  26631. function getBoneList( object ) {
  26632. var boneList = [];
  26633. if ( object && object.isBone ) {
  26634. boneList.push( object );
  26635. }
  26636. for ( var i = 0; i < object.children.length; i ++ ) {
  26637. boneList.push.apply( boneList, getBoneList( object.children[ i ] ) );
  26638. }
  26639. return boneList;
  26640. }
  26641. function SkeletonHelper( object ) {
  26642. var bones = getBoneList( object );
  26643. var geometry = new BufferGeometry();
  26644. var vertices = [];
  26645. var colors = [];
  26646. var color1 = new Color( 0, 0, 1 );
  26647. var color2 = new Color( 0, 1, 0 );
  26648. for ( var i = 0; i < bones.length; i ++ ) {
  26649. var bone = bones[ i ];
  26650. if ( bone.parent && bone.parent.isBone ) {
  26651. vertices.push( 0, 0, 0 );
  26652. vertices.push( 0, 0, 0 );
  26653. colors.push( color1.r, color1.g, color1.b );
  26654. colors.push( color2.r, color2.g, color2.b );
  26655. }
  26656. }
  26657. geometry.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  26658. geometry.addAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  26659. var material = new LineBasicMaterial( { vertexColors: VertexColors, depthTest: false, depthWrite: false, transparent: true } );
  26660. LineSegments.call( this, geometry, material );
  26661. this.root = object;
  26662. this.bones = bones;
  26663. this.matrix = object.matrixWorld;
  26664. this.matrixAutoUpdate = false;
  26665. }
  26666. SkeletonHelper.prototype = Object.create( LineSegments.prototype );
  26667. SkeletonHelper.prototype.constructor = SkeletonHelper;
  26668. SkeletonHelper.prototype.updateMatrixWorld = function () {
  26669. var vector = new Vector3();
  26670. var boneMatrix = new Matrix4();
  26671. var matrixWorldInv = new Matrix4();
  26672. return function updateMatrixWorld( force ) {
  26673. var bones = this.bones;
  26674. var geometry = this.geometry;
  26675. var position = geometry.getAttribute( 'position' );
  26676. matrixWorldInv.getInverse( this.root.matrixWorld );
  26677. for ( var i = 0, j = 0; i < bones.length; i ++ ) {
  26678. var bone = bones[ i ];
  26679. if ( bone.parent && bone.parent.isBone ) {
  26680. boneMatrix.multiplyMatrices( matrixWorldInv, bone.matrixWorld );
  26681. vector.setFromMatrixPosition( boneMatrix );
  26682. position.setXYZ( j, vector.x, vector.y, vector.z );
  26683. boneMatrix.multiplyMatrices( matrixWorldInv, bone.parent.matrixWorld );
  26684. vector.setFromMatrixPosition( boneMatrix );
  26685. position.setXYZ( j + 1, vector.x, vector.y, vector.z );
  26686. j += 2;
  26687. }
  26688. }
  26689. geometry.getAttribute( 'position' ).needsUpdate = true;
  26690. Object3D.prototype.updateMatrixWorld.call( this, force );
  26691. };
  26692. }();
  26693. /**
  26694. * @author alteredq / http://alteredqualia.com/
  26695. * @author mrdoob / http://mrdoob.com/
  26696. */
  26697. function PointLightHelper( light, sphereSize, color ) {
  26698. this.light = light;
  26699. this.light.updateMatrixWorld();
  26700. this.color = color;
  26701. var geometry = new SphereBufferGeometry( sphereSize, 4, 2 );
  26702. var material = new MeshBasicMaterial( { wireframe: true, fog: false } );
  26703. Mesh.call( this, geometry, material );
  26704. this.matrix = this.light.matrixWorld;
  26705. this.matrixAutoUpdate = false;
  26706. this.update();
  26707. /*
  26708. var distanceGeometry = new THREE.IcosahedronBufferGeometry( 1, 2 );
  26709. var distanceMaterial = new THREE.MeshBasicMaterial( { color: hexColor, fog: false, wireframe: true, opacity: 0.1, transparent: true } );
  26710. this.lightSphere = new THREE.Mesh( bulbGeometry, bulbMaterial );
  26711. this.lightDistance = new THREE.Mesh( distanceGeometry, distanceMaterial );
  26712. var d = light.distance;
  26713. if ( d === 0.0 ) {
  26714. this.lightDistance.visible = false;
  26715. } else {
  26716. this.lightDistance.scale.set( d, d, d );
  26717. }
  26718. this.add( this.lightDistance );
  26719. */
  26720. }
  26721. PointLightHelper.prototype = Object.create( Mesh.prototype );
  26722. PointLightHelper.prototype.constructor = PointLightHelper;
  26723. PointLightHelper.prototype.dispose = function () {
  26724. this.geometry.dispose();
  26725. this.material.dispose();
  26726. };
  26727. PointLightHelper.prototype.update = function () {
  26728. if ( this.color !== undefined ) {
  26729. this.material.color.set( this.color );
  26730. } else {
  26731. this.material.color.copy( this.light.color );
  26732. }
  26733. /*
  26734. var d = this.light.distance;
  26735. if ( d === 0.0 ) {
  26736. this.lightDistance.visible = false;
  26737. } else {
  26738. this.lightDistance.visible = true;
  26739. this.lightDistance.scale.set( d, d, d );
  26740. }
  26741. */
  26742. };
  26743. /**
  26744. * @author abelnation / http://github.com/abelnation
  26745. * @author Mugen87 / http://github.com/Mugen87
  26746. * @author WestLangley / http://github.com/WestLangley
  26747. *
  26748. * This helper must be added as a child of the light
  26749. */
  26750. function RectAreaLightHelper( light, color ) {
  26751. this.type = 'RectAreaLightHelper';
  26752. this.light = light;
  26753. this.color = color; // optional hardwired color for the helper
  26754. var positions = [ 1, 1, 0, - 1, 1, 0, - 1, - 1, 0, 1, - 1, 0, 1, 1, 0 ];
  26755. var geometry = new BufferGeometry();
  26756. geometry.addAttribute( 'position', new Float32BufferAttribute( positions, 3 ) );
  26757. geometry.computeBoundingSphere();
  26758. var material = new LineBasicMaterial( { fog: false } );
  26759. Line.call( this, geometry, material );
  26760. //
  26761. var positions2 = [ 1, 1, 0, - 1, 1, 0, - 1, - 1, 0, 1, 1, 0, - 1, - 1, 0, 1, - 1, 0 ];
  26762. var geometry2 = new BufferGeometry();
  26763. geometry2.addAttribute( 'position', new Float32BufferAttribute( positions2, 3 ) );
  26764. geometry2.computeBoundingSphere();
  26765. this.add( new Mesh( geometry2, new MeshBasicMaterial( { side: BackSide, fog: false } ) ) );
  26766. this.update();
  26767. }
  26768. RectAreaLightHelper.prototype = Object.create( Line.prototype );
  26769. RectAreaLightHelper.prototype.constructor = RectAreaLightHelper;
  26770. RectAreaLightHelper.prototype.update = function () {
  26771. this.scale.set( 0.5 * this.light.width, 0.5 * this.light.height, 1 );
  26772. if ( this.color !== undefined ) {
  26773. this.material.color.set( this.color );
  26774. this.children[ 0 ].material.color.set( this.color );
  26775. } else {
  26776. this.material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  26777. // prevent hue shift
  26778. var c = this.material.color;
  26779. var max = Math.max( c.r, c.g, c.b );
  26780. if ( max > 1 ) c.multiplyScalar( 1 / max );
  26781. this.children[ 0 ].material.color.copy( this.material.color );
  26782. }
  26783. };
  26784. RectAreaLightHelper.prototype.dispose = function () {
  26785. this.geometry.dispose();
  26786. this.material.dispose();
  26787. this.children[ 0 ].geometry.dispose();
  26788. this.children[ 0 ].material.dispose();
  26789. };
  26790. /**
  26791. * @author alteredq / http://alteredqualia.com/
  26792. * @author mrdoob / http://mrdoob.com/
  26793. * @author Mugen87 / https://github.com/Mugen87
  26794. */
  26795. function HemisphereLightHelper( light, size, color ) {
  26796. Object3D.call( this );
  26797. this.light = light;
  26798. this.light.updateMatrixWorld();
  26799. this.matrix = light.matrixWorld;
  26800. this.matrixAutoUpdate = false;
  26801. this.color = color;
  26802. var geometry = new OctahedronBufferGeometry( size );
  26803. geometry.rotateY( Math.PI * 0.5 );
  26804. this.material = new MeshBasicMaterial( { wireframe: true, fog: false } );
  26805. if ( this.color === undefined ) this.material.vertexColors = VertexColors;
  26806. var position = geometry.getAttribute( 'position' );
  26807. var colors = new Float32Array( position.count * 3 );
  26808. geometry.addAttribute( 'color', new BufferAttribute( colors, 3 ) );
  26809. this.add( new Mesh( geometry, this.material ) );
  26810. this.update();
  26811. }
  26812. HemisphereLightHelper.prototype = Object.create( Object3D.prototype );
  26813. HemisphereLightHelper.prototype.constructor = HemisphereLightHelper;
  26814. HemisphereLightHelper.prototype.dispose = function () {
  26815. this.children[ 0 ].geometry.dispose();
  26816. this.children[ 0 ].material.dispose();
  26817. };
  26818. HemisphereLightHelper.prototype.update = function () {
  26819. var vector = new Vector3();
  26820. var color1 = new Color();
  26821. var color2 = new Color();
  26822. return function update() {
  26823. var mesh = this.children[ 0 ];
  26824. if ( this.color !== undefined ) {
  26825. this.material.color.set( this.color );
  26826. } else {
  26827. var colors = mesh.geometry.getAttribute( 'color' );
  26828. color1.copy( this.light.color );
  26829. color2.copy( this.light.groundColor );
  26830. for ( var i = 0, l = colors.count; i < l; i ++ ) {
  26831. var color = ( i < ( l / 2 ) ) ? color1 : color2;
  26832. colors.setXYZ( i, color.r, color.g, color.b );
  26833. }
  26834. colors.needsUpdate = true;
  26835. }
  26836. mesh.lookAt( vector.setFromMatrixPosition( this.light.matrixWorld ).negate() );
  26837. };
  26838. }();
  26839. /**
  26840. * @author mrdoob / http://mrdoob.com/
  26841. */
  26842. function GridHelper( size, divisions, color1, color2 ) {
  26843. size = size || 10;
  26844. divisions = divisions || 10;
  26845. color1 = new Color( color1 !== undefined ? color1 : 0x444444 );
  26846. color2 = new Color( color2 !== undefined ? color2 : 0x888888 );
  26847. var center = divisions / 2;
  26848. var step = size / divisions;
  26849. var halfSize = size / 2;
  26850. var vertices = [], colors = [];
  26851. for ( var i = 0, j = 0, k = - halfSize; i <= divisions; i ++, k += step ) {
  26852. vertices.push( - halfSize, 0, k, halfSize, 0, k );
  26853. vertices.push( k, 0, - halfSize, k, 0, halfSize );
  26854. var color = i === center ? color1 : color2;
  26855. color.toArray( colors, j ); j += 3;
  26856. color.toArray( colors, j ); j += 3;
  26857. color.toArray( colors, j ); j += 3;
  26858. color.toArray( colors, j ); j += 3;
  26859. }
  26860. var geometry = new BufferGeometry();
  26861. geometry.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  26862. geometry.addAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  26863. var material = new LineBasicMaterial( { vertexColors: VertexColors } );
  26864. LineSegments.call( this, geometry, material );
  26865. }
  26866. GridHelper.prototype = Object.create( LineSegments.prototype );
  26867. GridHelper.prototype.constructor = GridHelper;
  26868. /**
  26869. * @author mrdoob / http://mrdoob.com/
  26870. * @author Mugen87 / http://github.com/Mugen87
  26871. * @author Hectate / http://www.github.com/Hectate
  26872. */
  26873. function PolarGridHelper( radius, radials, circles, divisions, color1, color2 ) {
  26874. radius = radius || 10;
  26875. radials = radials || 16;
  26876. circles = circles || 8;
  26877. divisions = divisions || 64;
  26878. color1 = new Color( color1 !== undefined ? color1 : 0x444444 );
  26879. color2 = new Color( color2 !== undefined ? color2 : 0x888888 );
  26880. var vertices = [];
  26881. var colors = [];
  26882. var x, z;
  26883. var v, i, j, r, color;
  26884. // create the radials
  26885. for ( i = 0; i <= radials; i ++ ) {
  26886. v = ( i / radials ) * ( Math.PI * 2 );
  26887. x = Math.sin( v ) * radius;
  26888. z = Math.cos( v ) * radius;
  26889. vertices.push( 0, 0, 0 );
  26890. vertices.push( x, 0, z );
  26891. color = ( i & 1 ) ? color1 : color2;
  26892. colors.push( color.r, color.g, color.b );
  26893. colors.push( color.r, color.g, color.b );
  26894. }
  26895. // create the circles
  26896. for ( i = 0; i <= circles; i ++ ) {
  26897. color = ( i & 1 ) ? color1 : color2;
  26898. r = radius - ( radius / circles * i );
  26899. for ( j = 0; j < divisions; j ++ ) {
  26900. // first vertex
  26901. v = ( j / divisions ) * ( Math.PI * 2 );
  26902. x = Math.sin( v ) * r;
  26903. z = Math.cos( v ) * r;
  26904. vertices.push( x, 0, z );
  26905. colors.push( color.r, color.g, color.b );
  26906. // second vertex
  26907. v = ( ( j + 1 ) / divisions ) * ( Math.PI * 2 );
  26908. x = Math.sin( v ) * r;
  26909. z = Math.cos( v ) * r;
  26910. vertices.push( x, 0, z );
  26911. colors.push( color.r, color.g, color.b );
  26912. }
  26913. }
  26914. var geometry = new BufferGeometry();
  26915. geometry.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  26916. geometry.addAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  26917. var material = new LineBasicMaterial( { vertexColors: VertexColors } );
  26918. LineSegments.call( this, geometry, material );
  26919. }
  26920. PolarGridHelper.prototype = Object.create( LineSegments.prototype );
  26921. PolarGridHelper.prototype.constructor = PolarGridHelper;
  26922. /**
  26923. * @author Mugen87 / http://github.com/Mugen87
  26924. */
  26925. function PositionalAudioHelper( audio, range, divisionsInnerAngle, divisionsOuterAngle ) {
  26926. this.audio = audio;
  26927. this.range = range || 1;
  26928. this.divisionsInnerAngle = divisionsInnerAngle || 16;
  26929. this.divisionsOuterAngle = divisionsOuterAngle || 2;
  26930. var geometry = new BufferGeometry();
  26931. var divisions = this.divisionsInnerAngle + this.divisionsOuterAngle * 2;
  26932. var positions = new Float32Array( ( divisions * 3 + 3 ) * 3 );
  26933. geometry.addAttribute( 'position', new BufferAttribute( positions, 3 ) );
  26934. var materialInnerAngle = new LineBasicMaterial( { color: 0x00ff00 } );
  26935. var materialOuterAngle = new LineBasicMaterial( { color: 0xffff00 } );
  26936. Line.call( this, geometry, [ materialOuterAngle, materialInnerAngle ] );
  26937. this.update();
  26938. }
  26939. PositionalAudioHelper.prototype = Object.create( Line.prototype );
  26940. PositionalAudioHelper.prototype.constructor = PositionalAudioHelper;
  26941. PositionalAudioHelper.prototype.update = function () {
  26942. var audio = this.audio;
  26943. var range = this.range;
  26944. var divisionsInnerAngle = this.divisionsInnerAngle;
  26945. var divisionsOuterAngle = this.divisionsOuterAngle;
  26946. var coneInnerAngle = _Math.degToRad( audio.panner.coneInnerAngle );
  26947. var coneOuterAngle = _Math.degToRad( audio.panner.coneOuterAngle );
  26948. var halfConeInnerAngle = coneInnerAngle / 2;
  26949. var halfConeOuterAngle = coneOuterAngle / 2;
  26950. var start = 0;
  26951. var count = 0;
  26952. var i, stride;
  26953. var geometry = this.geometry;
  26954. var positionAttribute = geometry.attributes.position;
  26955. geometry.clearGroups();
  26956. //
  26957. function generateSegment( from, to, divisions, materialIndex ) {
  26958. var step = ( to - from ) / divisions;
  26959. positionAttribute.setXYZ( start, 0, 0, 0 );
  26960. count ++;
  26961. for ( i = from; i < to; i += step ) {
  26962. stride = start + count;
  26963. positionAttribute.setXYZ( stride, Math.sin( i ) * range, 0, Math.cos( i ) * range );
  26964. positionAttribute.setXYZ( stride + 1, Math.sin( Math.min( i + step, to ) ) * range, 0, Math.cos( Math.min( i + step, to ) ) * range );
  26965. positionAttribute.setXYZ( stride + 2, 0, 0, 0 );
  26966. count += 3;
  26967. }
  26968. geometry.addGroup( start, count, materialIndex );
  26969. start += count;
  26970. count = 0;
  26971. }
  26972. //
  26973. generateSegment( - halfConeOuterAngle, - halfConeInnerAngle, divisionsOuterAngle, 0 );
  26974. generateSegment( - halfConeInnerAngle, halfConeInnerAngle, divisionsInnerAngle, 1 );
  26975. generateSegment( halfConeInnerAngle, halfConeOuterAngle, divisionsOuterAngle, 0 );
  26976. //
  26977. positionAttribute.needsUpdate = true;
  26978. if ( coneInnerAngle === coneOuterAngle ) this.material[ 0 ].visible = false;
  26979. };
  26980. PositionalAudioHelper.prototype.dispose = function () {
  26981. this.geometry.dispose();
  26982. this.material[ 0 ].dispose();
  26983. this.material[ 1 ].dispose();
  26984. };
  26985. /**
  26986. * @author mrdoob / http://mrdoob.com/
  26987. * @author WestLangley / http://github.com/WestLangley
  26988. */
  26989. function FaceNormalsHelper( object, size, hex, linewidth ) {
  26990. // FaceNormalsHelper only supports THREE.Geometry
  26991. this.object = object;
  26992. this.size = ( size !== undefined ) ? size : 1;
  26993. var color = ( hex !== undefined ) ? hex : 0xffff00;
  26994. var width = ( linewidth !== undefined ) ? linewidth : 1;
  26995. //
  26996. var nNormals = 0;
  26997. var objGeometry = this.object.geometry;
  26998. if ( objGeometry && objGeometry.isGeometry ) {
  26999. nNormals = objGeometry.faces.length;
  27000. } else {
  27001. console.warn( 'THREE.FaceNormalsHelper: only THREE.Geometry is supported. Use THREE.VertexNormalsHelper, instead.' );
  27002. }
  27003. //
  27004. var geometry = new BufferGeometry();
  27005. var positions = new Float32BufferAttribute( nNormals * 2 * 3, 3 );
  27006. geometry.addAttribute( 'position', positions );
  27007. LineSegments.call( this, geometry, new LineBasicMaterial( { color: color, linewidth: width } ) );
  27008. //
  27009. this.matrixAutoUpdate = false;
  27010. this.update();
  27011. }
  27012. FaceNormalsHelper.prototype = Object.create( LineSegments.prototype );
  27013. FaceNormalsHelper.prototype.constructor = FaceNormalsHelper;
  27014. FaceNormalsHelper.prototype.update = ( function () {
  27015. var v1 = new Vector3();
  27016. var v2 = new Vector3();
  27017. var normalMatrix = new Matrix3();
  27018. return function update() {
  27019. this.object.updateMatrixWorld( true );
  27020. normalMatrix.getNormalMatrix( this.object.matrixWorld );
  27021. var matrixWorld = this.object.matrixWorld;
  27022. var position = this.geometry.attributes.position;
  27023. //
  27024. var objGeometry = this.object.geometry;
  27025. var vertices = objGeometry.vertices;
  27026. var faces = objGeometry.faces;
  27027. var idx = 0;
  27028. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  27029. var face = faces[ i ];
  27030. var normal = face.normal;
  27031. v1.copy( vertices[ face.a ] )
  27032. .add( vertices[ face.b ] )
  27033. .add( vertices[ face.c ] )
  27034. .divideScalar( 3 )
  27035. .applyMatrix4( matrixWorld );
  27036. v2.copy( normal ).applyMatrix3( normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
  27037. position.setXYZ( idx, v1.x, v1.y, v1.z );
  27038. idx = idx + 1;
  27039. position.setXYZ( idx, v2.x, v2.y, v2.z );
  27040. idx = idx + 1;
  27041. }
  27042. position.needsUpdate = true;
  27043. };
  27044. }() );
  27045. /**
  27046. * @author alteredq / http://alteredqualia.com/
  27047. * @author mrdoob / http://mrdoob.com/
  27048. * @author WestLangley / http://github.com/WestLangley
  27049. */
  27050. function DirectionalLightHelper( light, size, color ) {
  27051. Object3D.call( this );
  27052. this.light = light;
  27053. this.light.updateMatrixWorld();
  27054. this.matrix = light.matrixWorld;
  27055. this.matrixAutoUpdate = false;
  27056. this.color = color;
  27057. if ( size === undefined ) size = 1;
  27058. var geometry = new BufferGeometry();
  27059. geometry.addAttribute( 'position', new Float32BufferAttribute( [
  27060. - size, size, 0,
  27061. size, size, 0,
  27062. size, - size, 0,
  27063. - size, - size, 0,
  27064. - size, size, 0
  27065. ], 3 ) );
  27066. var material = new LineBasicMaterial( { fog: false } );
  27067. this.lightPlane = new Line( geometry, material );
  27068. this.add( this.lightPlane );
  27069. geometry = new BufferGeometry();
  27070. geometry.addAttribute( 'position', new Float32BufferAttribute( [ 0, 0, 0, 0, 0, 1 ], 3 ) );
  27071. this.targetLine = new Line( geometry, material );
  27072. this.add( this.targetLine );
  27073. this.update();
  27074. }
  27075. DirectionalLightHelper.prototype = Object.create( Object3D.prototype );
  27076. DirectionalLightHelper.prototype.constructor = DirectionalLightHelper;
  27077. DirectionalLightHelper.prototype.dispose = function () {
  27078. this.lightPlane.geometry.dispose();
  27079. this.lightPlane.material.dispose();
  27080. this.targetLine.geometry.dispose();
  27081. this.targetLine.material.dispose();
  27082. };
  27083. DirectionalLightHelper.prototype.update = function () {
  27084. var v1 = new Vector3();
  27085. var v2 = new Vector3();
  27086. var v3 = new Vector3();
  27087. return function update() {
  27088. v1.setFromMatrixPosition( this.light.matrixWorld );
  27089. v2.setFromMatrixPosition( this.light.target.matrixWorld );
  27090. v3.subVectors( v2, v1 );
  27091. this.lightPlane.lookAt( v2 );
  27092. if ( this.color !== undefined ) {
  27093. this.lightPlane.material.color.set( this.color );
  27094. this.targetLine.material.color.set( this.color );
  27095. } else {
  27096. this.lightPlane.material.color.copy( this.light.color );
  27097. this.targetLine.material.color.copy( this.light.color );
  27098. }
  27099. this.targetLine.lookAt( v2 );
  27100. this.targetLine.scale.z = v3.length();
  27101. };
  27102. }();
  27103. /**
  27104. * @author alteredq / http://alteredqualia.com/
  27105. * @author Mugen87 / https://github.com/Mugen87
  27106. *
  27107. * - shows frustum, line of sight and up of the camera
  27108. * - suitable for fast updates
  27109. * - based on frustum visualization in lightgl.js shadowmap example
  27110. * http://evanw.github.com/lightgl.js/tests/shadowmap.html
  27111. */
  27112. function CameraHelper( camera ) {
  27113. var geometry = new BufferGeometry();
  27114. var material = new LineBasicMaterial( { color: 0xffffff, vertexColors: FaceColors } );
  27115. var vertices = [];
  27116. var colors = [];
  27117. var pointMap = {};
  27118. // colors
  27119. var colorFrustum = new Color( 0xffaa00 );
  27120. var colorCone = new Color( 0xff0000 );
  27121. var colorUp = new Color( 0x00aaff );
  27122. var colorTarget = new Color( 0xffffff );
  27123. var colorCross = new Color( 0x333333 );
  27124. // near
  27125. addLine( 'n1', 'n2', colorFrustum );
  27126. addLine( 'n2', 'n4', colorFrustum );
  27127. addLine( 'n4', 'n3', colorFrustum );
  27128. addLine( 'n3', 'n1', colorFrustum );
  27129. // far
  27130. addLine( 'f1', 'f2', colorFrustum );
  27131. addLine( 'f2', 'f4', colorFrustum );
  27132. addLine( 'f4', 'f3', colorFrustum );
  27133. addLine( 'f3', 'f1', colorFrustum );
  27134. // sides
  27135. addLine( 'n1', 'f1', colorFrustum );
  27136. addLine( 'n2', 'f2', colorFrustum );
  27137. addLine( 'n3', 'f3', colorFrustum );
  27138. addLine( 'n4', 'f4', colorFrustum );
  27139. // cone
  27140. addLine( 'p', 'n1', colorCone );
  27141. addLine( 'p', 'n2', colorCone );
  27142. addLine( 'p', 'n3', colorCone );
  27143. addLine( 'p', 'n4', colorCone );
  27144. // up
  27145. addLine( 'u1', 'u2', colorUp );
  27146. addLine( 'u2', 'u3', colorUp );
  27147. addLine( 'u3', 'u1', colorUp );
  27148. // target
  27149. addLine( 'c', 't', colorTarget );
  27150. addLine( 'p', 'c', colorCross );
  27151. // cross
  27152. addLine( 'cn1', 'cn2', colorCross );
  27153. addLine( 'cn3', 'cn4', colorCross );
  27154. addLine( 'cf1', 'cf2', colorCross );
  27155. addLine( 'cf3', 'cf4', colorCross );
  27156. function addLine( a, b, color ) {
  27157. addPoint( a, color );
  27158. addPoint( b, color );
  27159. }
  27160. function addPoint( id, color ) {
  27161. vertices.push( 0, 0, 0 );
  27162. colors.push( color.r, color.g, color.b );
  27163. if ( pointMap[ id ] === undefined ) {
  27164. pointMap[ id ] = [];
  27165. }
  27166. pointMap[ id ].push( ( vertices.length / 3 ) - 1 );
  27167. }
  27168. geometry.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  27169. geometry.addAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  27170. LineSegments.call( this, geometry, material );
  27171. this.camera = camera;
  27172. if ( this.camera.updateProjectionMatrix ) this.camera.updateProjectionMatrix();
  27173. this.matrix = camera.matrixWorld;
  27174. this.matrixAutoUpdate = false;
  27175. this.pointMap = pointMap;
  27176. this.update();
  27177. }
  27178. CameraHelper.prototype = Object.create( LineSegments.prototype );
  27179. CameraHelper.prototype.constructor = CameraHelper;
  27180. CameraHelper.prototype.update = function () {
  27181. var geometry, pointMap;
  27182. var vector = new Vector3();
  27183. var camera = new Camera();
  27184. function setPoint( point, x, y, z ) {
  27185. vector.set( x, y, z ).unproject( camera );
  27186. var points = pointMap[ point ];
  27187. if ( points !== undefined ) {
  27188. var position = geometry.getAttribute( 'position' );
  27189. for ( var i = 0, l = points.length; i < l; i ++ ) {
  27190. position.setXYZ( points[ i ], vector.x, vector.y, vector.z );
  27191. }
  27192. }
  27193. }
  27194. return function update() {
  27195. geometry = this.geometry;
  27196. pointMap = this.pointMap;
  27197. var w = 1, h = 1;
  27198. // we need just camera projection matrix
  27199. // world matrix must be identity
  27200. camera.projectionMatrix.copy( this.camera.projectionMatrix );
  27201. // center / target
  27202. setPoint( 'c', 0, 0, - 1 );
  27203. setPoint( 't', 0, 0, 1 );
  27204. // near
  27205. setPoint( 'n1', - w, - h, - 1 );
  27206. setPoint( 'n2', w, - h, - 1 );
  27207. setPoint( 'n3', - w, h, - 1 );
  27208. setPoint( 'n4', w, h, - 1 );
  27209. // far
  27210. setPoint( 'f1', - w, - h, 1 );
  27211. setPoint( 'f2', w, - h, 1 );
  27212. setPoint( 'f3', - w, h, 1 );
  27213. setPoint( 'f4', w, h, 1 );
  27214. // up
  27215. setPoint( 'u1', w * 0.7, h * 1.1, - 1 );
  27216. setPoint( 'u2', - w * 0.7, h * 1.1, - 1 );
  27217. setPoint( 'u3', 0, h * 2, - 1 );
  27218. // cross
  27219. setPoint( 'cf1', - w, 0, 1 );
  27220. setPoint( 'cf2', w, 0, 1 );
  27221. setPoint( 'cf3', 0, - h, 1 );
  27222. setPoint( 'cf4', 0, h, 1 );
  27223. setPoint( 'cn1', - w, 0, - 1 );
  27224. setPoint( 'cn2', w, 0, - 1 );
  27225. setPoint( 'cn3', 0, - h, - 1 );
  27226. setPoint( 'cn4', 0, h, - 1 );
  27227. geometry.getAttribute( 'position' ).needsUpdate = true;
  27228. };
  27229. }();
  27230. /**
  27231. * @author mrdoob / http://mrdoob.com/
  27232. * @author Mugen87 / http://github.com/Mugen87
  27233. */
  27234. function BoxHelper( object, color ) {
  27235. this.object = object;
  27236. if ( color === undefined ) color = 0xffff00;
  27237. 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 ] );
  27238. var positions = new Float32Array( 8 * 3 );
  27239. var geometry = new BufferGeometry();
  27240. geometry.setIndex( new BufferAttribute( indices, 1 ) );
  27241. geometry.addAttribute( 'position', new BufferAttribute( positions, 3 ) );
  27242. LineSegments.call( this, geometry, new LineBasicMaterial( { color: color } ) );
  27243. this.matrixAutoUpdate = false;
  27244. this.update();
  27245. }
  27246. BoxHelper.prototype = Object.create( LineSegments.prototype );
  27247. BoxHelper.prototype.constructor = BoxHelper;
  27248. BoxHelper.prototype.update = ( function () {
  27249. var box = new Box3();
  27250. return function update( object ) {
  27251. if ( object !== undefined ) {
  27252. console.warn( 'THREE.BoxHelper: .update() has no longer arguments.' );
  27253. }
  27254. if ( this.object !== undefined ) {
  27255. box.setFromObject( this.object );
  27256. }
  27257. if ( box.isEmpty() ) return;
  27258. var min = box.min;
  27259. var max = box.max;
  27260. /*
  27261. 5____4
  27262. 1/___0/|
  27263. | 6__|_7
  27264. 2/___3/
  27265. 0: max.x, max.y, max.z
  27266. 1: min.x, max.y, max.z
  27267. 2: min.x, min.y, max.z
  27268. 3: max.x, min.y, max.z
  27269. 4: max.x, max.y, min.z
  27270. 5: min.x, max.y, min.z
  27271. 6: min.x, min.y, min.z
  27272. 7: max.x, min.y, min.z
  27273. */
  27274. var position = this.geometry.attributes.position;
  27275. var array = position.array;
  27276. array[ 0 ] = max.x; array[ 1 ] = max.y; array[ 2 ] = max.z;
  27277. array[ 3 ] = min.x; array[ 4 ] = max.y; array[ 5 ] = max.z;
  27278. array[ 6 ] = min.x; array[ 7 ] = min.y; array[ 8 ] = max.z;
  27279. array[ 9 ] = max.x; array[ 10 ] = min.y; array[ 11 ] = max.z;
  27280. array[ 12 ] = max.x; array[ 13 ] = max.y; array[ 14 ] = min.z;
  27281. array[ 15 ] = min.x; array[ 16 ] = max.y; array[ 17 ] = min.z;
  27282. array[ 18 ] = min.x; array[ 19 ] = min.y; array[ 20 ] = min.z;
  27283. array[ 21 ] = max.x; array[ 22 ] = min.y; array[ 23 ] = min.z;
  27284. position.needsUpdate = true;
  27285. this.geometry.computeBoundingSphere();
  27286. };
  27287. } )();
  27288. BoxHelper.prototype.setFromObject = function ( object ) {
  27289. this.object = object;
  27290. this.update();
  27291. return this;
  27292. };
  27293. BoxHelper.prototype.copy = function ( source ) {
  27294. LineSegments.prototype.copy.call( this, source );
  27295. this.object = source.object;
  27296. return this;
  27297. };
  27298. BoxHelper.prototype.clone = function () {
  27299. return new this.constructor().copy( this );
  27300. };
  27301. /**
  27302. * @author WestLangley / http://github.com/WestLangley
  27303. */
  27304. function Box3Helper( box, hex ) {
  27305. this.type = 'Box3Helper';
  27306. this.box = box;
  27307. var color = ( hex !== undefined ) ? hex : 0xffff00;
  27308. 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 ] );
  27309. var positions = [ 1, 1, 1, - 1, 1, 1, - 1, - 1, 1, 1, - 1, 1, 1, 1, - 1, - 1, 1, - 1, - 1, - 1, - 1, 1, - 1, - 1 ];
  27310. var geometry = new BufferGeometry();
  27311. geometry.setIndex( new BufferAttribute( indices, 1 ) );
  27312. geometry.addAttribute( 'position', new Float32BufferAttribute( positions, 3 ) );
  27313. LineSegments.call( this, geometry, new LineBasicMaterial( { color: color } ) );
  27314. this.geometry.computeBoundingSphere();
  27315. }
  27316. Box3Helper.prototype = Object.create( LineSegments.prototype );
  27317. Box3Helper.prototype.constructor = Box3Helper;
  27318. Box3Helper.prototype.updateMatrixWorld = function ( force ) {
  27319. var box = this.box;
  27320. if ( box.isEmpty() ) return;
  27321. box.getCenter( this.position );
  27322. box.getSize( this.scale );
  27323. this.scale.multiplyScalar( 0.5 );
  27324. Object3D.prototype.updateMatrixWorld.call( this, force );
  27325. };
  27326. /**
  27327. * @author WestLangley / http://github.com/WestLangley
  27328. */
  27329. function PlaneHelper( plane, size, hex ) {
  27330. this.type = 'PlaneHelper';
  27331. this.plane = plane;
  27332. this.size = ( size === undefined ) ? 1 : size;
  27333. var color = ( hex !== undefined ) ? hex : 0xffff00;
  27334. var positions = [ 1, - 1, 1, - 1, 1, 1, - 1, - 1, 1, 1, 1, 1, - 1, 1, 1, - 1, - 1, 1, 1, - 1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 0 ];
  27335. var geometry = new BufferGeometry();
  27336. geometry.addAttribute( 'position', new Float32BufferAttribute( positions, 3 ) );
  27337. geometry.computeBoundingSphere();
  27338. Line.call( this, geometry, new LineBasicMaterial( { color: color } ) );
  27339. //
  27340. var positions2 = [ 1, 1, 1, - 1, 1, 1, - 1, - 1, 1, 1, 1, 1, - 1, - 1, 1, 1, - 1, 1 ];
  27341. var geometry2 = new BufferGeometry();
  27342. geometry2.addAttribute( 'position', new Float32BufferAttribute( positions2, 3 ) );
  27343. geometry2.computeBoundingSphere();
  27344. this.add( new Mesh( geometry2, new MeshBasicMaterial( { color: color, opacity: 0.2, transparent: true, depthWrite: false } ) ) );
  27345. }
  27346. PlaneHelper.prototype = Object.create( Line.prototype );
  27347. PlaneHelper.prototype.constructor = PlaneHelper;
  27348. PlaneHelper.prototype.updateMatrixWorld = function ( force ) {
  27349. var scale = - this.plane.constant;
  27350. if ( Math.abs( scale ) < 1e-8 ) scale = 1e-8; // sign does not matter
  27351. this.scale.set( 0.5 * this.size, 0.5 * this.size, scale );
  27352. this.children[ 0 ].material.side = ( scale < 0 ) ? BackSide : FrontSide; // renderer flips side when determinant < 0; flipping not wanted here
  27353. this.lookAt( this.plane.normal );
  27354. Object3D.prototype.updateMatrixWorld.call( this, force );
  27355. };
  27356. /**
  27357. * @author WestLangley / http://github.com/WestLangley
  27358. * @author zz85 / http://github.com/zz85
  27359. * @author bhouston / http://clara.io
  27360. *
  27361. * Creates an arrow for visualizing directions
  27362. *
  27363. * Parameters:
  27364. * dir - Vector3
  27365. * origin - Vector3
  27366. * length - Number
  27367. * color - color in hex value
  27368. * headLength - Number
  27369. * headWidth - Number
  27370. */
  27371. var lineGeometry, coneGeometry;
  27372. function ArrowHelper( dir, origin, length, color, headLength, headWidth ) {
  27373. // dir is assumed to be normalized
  27374. Object3D.call( this );
  27375. if ( dir === undefined ) dir = new Vector3( 0, 0, 1 );
  27376. if ( origin === undefined ) origin = new Vector3( 0, 0, 0 );
  27377. if ( length === undefined ) length = 1;
  27378. if ( color === undefined ) color = 0xffff00;
  27379. if ( headLength === undefined ) headLength = 0.2 * length;
  27380. if ( headWidth === undefined ) headWidth = 0.2 * headLength;
  27381. if ( lineGeometry === undefined ) {
  27382. lineGeometry = new BufferGeometry();
  27383. lineGeometry.addAttribute( 'position', new Float32BufferAttribute( [ 0, 0, 0, 0, 1, 0 ], 3 ) );
  27384. coneGeometry = new CylinderBufferGeometry( 0, 0.5, 1, 5, 1 );
  27385. coneGeometry.translate( 0, - 0.5, 0 );
  27386. }
  27387. this.position.copy( origin );
  27388. this.line = new Line( lineGeometry, new LineBasicMaterial( { color: color } ) );
  27389. this.line.matrixAutoUpdate = false;
  27390. this.add( this.line );
  27391. this.cone = new Mesh( coneGeometry, new MeshBasicMaterial( { color: color } ) );
  27392. this.cone.matrixAutoUpdate = false;
  27393. this.add( this.cone );
  27394. this.setDirection( dir );
  27395. this.setLength( length, headLength, headWidth );
  27396. }
  27397. ArrowHelper.prototype = Object.create( Object3D.prototype );
  27398. ArrowHelper.prototype.constructor = ArrowHelper;
  27399. ArrowHelper.prototype.setDirection = ( function () {
  27400. var axis = new Vector3();
  27401. var radians;
  27402. return function setDirection( dir ) {
  27403. // dir is assumed to be normalized
  27404. if ( dir.y > 0.99999 ) {
  27405. this.quaternion.set( 0, 0, 0, 1 );
  27406. } else if ( dir.y < - 0.99999 ) {
  27407. this.quaternion.set( 1, 0, 0, 0 );
  27408. } else {
  27409. axis.set( dir.z, 0, - dir.x ).normalize();
  27410. radians = Math.acos( dir.y );
  27411. this.quaternion.setFromAxisAngle( axis, radians );
  27412. }
  27413. };
  27414. }() );
  27415. ArrowHelper.prototype.setLength = function ( length, headLength, headWidth ) {
  27416. if ( headLength === undefined ) headLength = 0.2 * length;
  27417. if ( headWidth === undefined ) headWidth = 0.2 * headLength;
  27418. this.line.scale.set( 1, Math.max( 0, length - headLength ), 1 );
  27419. this.line.updateMatrix();
  27420. this.cone.scale.set( headWidth, headLength, headWidth );
  27421. this.cone.position.y = length;
  27422. this.cone.updateMatrix();
  27423. };
  27424. ArrowHelper.prototype.setColor = function ( color ) {
  27425. this.line.material.color.copy( color );
  27426. this.cone.material.color.copy( color );
  27427. };
  27428. ArrowHelper.prototype.copy = function ( source ) {
  27429. Object3D.prototype.copy.call( this, source, false );
  27430. this.line.copy( source.line );
  27431. this.cone.copy( source.cone );
  27432. return this;
  27433. };
  27434. ArrowHelper.prototype.clone = function () {
  27435. return new this.constructor().copy( this );
  27436. };
  27437. /**
  27438. * @author sroucheray / http://sroucheray.org/
  27439. * @author mrdoob / http://mrdoob.com/
  27440. */
  27441. function AxesHelper( size ) {
  27442. size = size || 1;
  27443. var vertices = [
  27444. 0, 0, 0, size, 0, 0,
  27445. 0, 0, 0, 0, size, 0,
  27446. 0, 0, 0, 0, 0, size
  27447. ];
  27448. var colors = [
  27449. 1, 0, 0, 1, 0.6, 0,
  27450. 0, 1, 0, 0.6, 1, 0,
  27451. 0, 0, 1, 0, 0.6, 1
  27452. ];
  27453. var geometry = new BufferGeometry();
  27454. geometry.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  27455. geometry.addAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  27456. var material = new LineBasicMaterial( { vertexColors: VertexColors } );
  27457. LineSegments.call( this, geometry, material );
  27458. }
  27459. AxesHelper.prototype = Object.create( LineSegments.prototype );
  27460. AxesHelper.prototype.constructor = AxesHelper;
  27461. /**
  27462. * @author mrdoob / http://mrdoob.com/
  27463. */
  27464. function Face4( a, b, c, d, normal, color, materialIndex ) {
  27465. console.warn( 'THREE.Face4 has been removed. A THREE.Face3 will be created instead.' );
  27466. return new Face3( a, b, c, normal, color, materialIndex );
  27467. }
  27468. var LineStrip = 0;
  27469. var LinePieces = 1;
  27470. function MeshFaceMaterial( materials ) {
  27471. console.warn( 'THREE.MeshFaceMaterial has been removed. Use an Array instead.' );
  27472. return materials;
  27473. }
  27474. function MultiMaterial( materials ) {
  27475. if ( materials === undefined ) materials = [];
  27476. console.warn( 'THREE.MultiMaterial has been removed. Use an Array instead.' );
  27477. materials.isMultiMaterial = true;
  27478. materials.materials = materials;
  27479. materials.clone = function () {
  27480. return materials.slice();
  27481. };
  27482. return materials;
  27483. }
  27484. function PointCloud( geometry, material ) {
  27485. console.warn( 'THREE.PointCloud has been renamed to THREE.Points.' );
  27486. return new Points( geometry, material );
  27487. }
  27488. function Particle( material ) {
  27489. console.warn( 'THREE.Particle has been renamed to THREE.Sprite.' );
  27490. return new Sprite( material );
  27491. }
  27492. function ParticleSystem( geometry, material ) {
  27493. console.warn( 'THREE.ParticleSystem has been renamed to THREE.Points.' );
  27494. return new Points( geometry, material );
  27495. }
  27496. function PointCloudMaterial( parameters ) {
  27497. console.warn( 'THREE.PointCloudMaterial has been renamed to THREE.PointsMaterial.' );
  27498. return new PointsMaterial( parameters );
  27499. }
  27500. function ParticleBasicMaterial( parameters ) {
  27501. console.warn( 'THREE.ParticleBasicMaterial has been renamed to THREE.PointsMaterial.' );
  27502. return new PointsMaterial( parameters );
  27503. }
  27504. function ParticleSystemMaterial( parameters ) {
  27505. console.warn( 'THREE.ParticleSystemMaterial has been renamed to THREE.PointsMaterial.' );
  27506. return new PointsMaterial( parameters );
  27507. }
  27508. function Vertex( x, y, z ) {
  27509. console.warn( 'THREE.Vertex has been removed. Use THREE.Vector3 instead.' );
  27510. return new Vector3( x, y, z );
  27511. }
  27512. //
  27513. function DynamicBufferAttribute( array, itemSize ) {
  27514. console.warn( 'THREE.DynamicBufferAttribute has been removed. Use new THREE.BufferAttribute().setDynamic( true ) instead.' );
  27515. return new BufferAttribute( array, itemSize ).setDynamic( true );
  27516. }
  27517. function Int8Attribute( array, itemSize ) {
  27518. console.warn( 'THREE.Int8Attribute has been removed. Use new THREE.Int8BufferAttribute() instead.' );
  27519. return new Int8BufferAttribute( array, itemSize );
  27520. }
  27521. function Uint8Attribute( array, itemSize ) {
  27522. console.warn( 'THREE.Uint8Attribute has been removed. Use new THREE.Uint8BufferAttribute() instead.' );
  27523. return new Uint8BufferAttribute( array, itemSize );
  27524. }
  27525. function Uint8ClampedAttribute( array, itemSize ) {
  27526. console.warn( 'THREE.Uint8ClampedAttribute has been removed. Use new THREE.Uint8ClampedBufferAttribute() instead.' );
  27527. return new Uint8ClampedBufferAttribute( array, itemSize );
  27528. }
  27529. function Int16Attribute( array, itemSize ) {
  27530. console.warn( 'THREE.Int16Attribute has been removed. Use new THREE.Int16BufferAttribute() instead.' );
  27531. return new Int16BufferAttribute( array, itemSize );
  27532. }
  27533. function Uint16Attribute( array, itemSize ) {
  27534. console.warn( 'THREE.Uint16Attribute has been removed. Use new THREE.Uint16BufferAttribute() instead.' );
  27535. return new Uint16BufferAttribute( array, itemSize );
  27536. }
  27537. function Int32Attribute( array, itemSize ) {
  27538. console.warn( 'THREE.Int32Attribute has been removed. Use new THREE.Int32BufferAttribute() instead.' );
  27539. return new Int32BufferAttribute( array, itemSize );
  27540. }
  27541. function Uint32Attribute( array, itemSize ) {
  27542. console.warn( 'THREE.Uint32Attribute has been removed. Use new THREE.Uint32BufferAttribute() instead.' );
  27543. return new Uint32BufferAttribute( array, itemSize );
  27544. }
  27545. function Float32Attribute( array, itemSize ) {
  27546. console.warn( 'THREE.Float32Attribute has been removed. Use new THREE.Float32BufferAttribute() instead.' );
  27547. return new Float32BufferAttribute( array, itemSize );
  27548. }
  27549. function Float64Attribute( array, itemSize ) {
  27550. console.warn( 'THREE.Float64Attribute has been removed. Use new THREE.Float64BufferAttribute() instead.' );
  27551. return new Float64BufferAttribute( array, itemSize );
  27552. }
  27553. //
  27554. Curve.create = function ( construct, getPoint ) {
  27555. console.log( 'THREE.Curve.create() has been deprecated' );
  27556. construct.prototype = Object.create( Curve.prototype );
  27557. construct.prototype.constructor = construct;
  27558. construct.prototype.getPoint = getPoint;
  27559. return construct;
  27560. };
  27561. //
  27562. Object.assign( CurvePath.prototype, {
  27563. createPointsGeometry: function ( divisions ) {
  27564. console.warn( 'THREE.CurvePath: .createPointsGeometry() has been removed. Use new THREE.Geometry().setFromPoints( points ) instead.' );
  27565. // generate geometry from path points (for Line or Points objects)
  27566. var pts = this.getPoints( divisions );
  27567. return this.createGeometry( pts );
  27568. },
  27569. createSpacedPointsGeometry: function ( divisions ) {
  27570. console.warn( 'THREE.CurvePath: .createSpacedPointsGeometry() has been removed. Use new THREE.Geometry().setFromPoints( points ) instead.' );
  27571. // generate geometry from equidistant sampling along the path
  27572. var pts = this.getSpacedPoints( divisions );
  27573. return this.createGeometry( pts );
  27574. },
  27575. createGeometry: function ( points ) {
  27576. console.warn( 'THREE.CurvePath: .createGeometry() has been removed. Use new THREE.Geometry().setFromPoints( points ) instead.' );
  27577. var geometry = new Geometry();
  27578. for ( var i = 0, l = points.length; i < l; i ++ ) {
  27579. var point = points[ i ];
  27580. geometry.vertices.push( new Vector3( point.x, point.y, point.z || 0 ) );
  27581. }
  27582. return geometry;
  27583. }
  27584. } );
  27585. //
  27586. Object.assign( Path.prototype, {
  27587. fromPoints: function ( points ) {
  27588. console.warn( 'THREE.Path: .fromPoints() has been renamed to .setFromPoints().' );
  27589. this.setFromPoints( points );
  27590. }
  27591. } );
  27592. //
  27593. function ClosedSplineCurve3( points ) {
  27594. console.warn( 'THREE.ClosedSplineCurve3 has been deprecated. Use THREE.CatmullRomCurve3 instead.' );
  27595. CatmullRomCurve3.call( this, points );
  27596. this.type = 'catmullrom';
  27597. this.closed = true;
  27598. }
  27599. ClosedSplineCurve3.prototype = Object.create( CatmullRomCurve3.prototype );
  27600. //
  27601. function SplineCurve3( points ) {
  27602. console.warn( 'THREE.SplineCurve3 has been deprecated. Use THREE.CatmullRomCurve3 instead.' );
  27603. CatmullRomCurve3.call( this, points );
  27604. this.type = 'catmullrom';
  27605. }
  27606. SplineCurve3.prototype = Object.create( CatmullRomCurve3.prototype );
  27607. //
  27608. function Spline( points ) {
  27609. console.warn( 'THREE.Spline has been removed. Use THREE.CatmullRomCurve3 instead.' );
  27610. CatmullRomCurve3.call( this, points );
  27611. this.type = 'catmullrom';
  27612. }
  27613. Spline.prototype = Object.create( CatmullRomCurve3.prototype );
  27614. Object.assign( Spline.prototype, {
  27615. initFromArray: function ( /* a */ ) {
  27616. console.error( 'THREE.Spline: .initFromArray() has been removed.' );
  27617. },
  27618. getControlPointsArray: function ( /* optionalTarget */ ) {
  27619. console.error( 'THREE.Spline: .getControlPointsArray() has been removed.' );
  27620. },
  27621. reparametrizeByArcLength: function ( /* samplingCoef */ ) {
  27622. console.error( 'THREE.Spline: .reparametrizeByArcLength() has been removed.' );
  27623. }
  27624. } );
  27625. //
  27626. function AxisHelper( size ) {
  27627. console.warn( 'THREE.AxisHelper has been renamed to THREE.AxesHelper.' );
  27628. return new AxesHelper( size );
  27629. }
  27630. function BoundingBoxHelper( object, color ) {
  27631. console.warn( 'THREE.BoundingBoxHelper has been deprecated. Creating a THREE.BoxHelper instead.' );
  27632. return new BoxHelper( object, color );
  27633. }
  27634. function EdgesHelper( object, hex ) {
  27635. console.warn( 'THREE.EdgesHelper has been removed. Use THREE.EdgesGeometry instead.' );
  27636. return new LineSegments( new EdgesGeometry( object.geometry ), new LineBasicMaterial( { color: hex !== undefined ? hex : 0xffffff } ) );
  27637. }
  27638. GridHelper.prototype.setColors = function () {
  27639. console.error( 'THREE.GridHelper: setColors() has been deprecated, pass them in the constructor instead.' );
  27640. };
  27641. SkeletonHelper.prototype.update = function () {
  27642. console.error( 'THREE.SkeletonHelper: update() no longer needs to be called.' );
  27643. };
  27644. function WireframeHelper( object, hex ) {
  27645. console.warn( 'THREE.WireframeHelper has been removed. Use THREE.WireframeGeometry instead.' );
  27646. return new LineSegments( new WireframeGeometry( object.geometry ), new LineBasicMaterial( { color: hex !== undefined ? hex : 0xffffff } ) );
  27647. }
  27648. //
  27649. Object.assign( Loader.prototype, {
  27650. extractUrlBase: function ( url ) {
  27651. console.warn( 'THREE.Loader: .extractUrlBase() has been deprecated. Use THREE.LoaderUtils.extractUrlBase() instead.' );
  27652. return LoaderUtils.extractUrlBase( url );
  27653. }
  27654. } );
  27655. function XHRLoader( manager ) {
  27656. console.warn( 'THREE.XHRLoader has been renamed to THREE.FileLoader.' );
  27657. return new FileLoader( manager );
  27658. }
  27659. function BinaryTextureLoader( manager ) {
  27660. console.warn( 'THREE.BinaryTextureLoader has been renamed to THREE.DataTextureLoader.' );
  27661. return new DataTextureLoader( manager );
  27662. }
  27663. Object.assign( ObjectLoader.prototype, {
  27664. setTexturePath: function ( value ) {
  27665. console.warn( 'THREE.ObjectLoader: .setTexturePath() has been renamed to .setResourcePath().' );
  27666. return this.setResourcePath( value );
  27667. }
  27668. } );
  27669. //
  27670. Object.assign( Box2.prototype, {
  27671. center: function ( optionalTarget ) {
  27672. console.warn( 'THREE.Box2: .center() has been renamed to .getCenter().' );
  27673. return this.getCenter( optionalTarget );
  27674. },
  27675. empty: function () {
  27676. console.warn( 'THREE.Box2: .empty() has been renamed to .isEmpty().' );
  27677. return this.isEmpty();
  27678. },
  27679. isIntersectionBox: function ( box ) {
  27680. console.warn( 'THREE.Box2: .isIntersectionBox() has been renamed to .intersectsBox().' );
  27681. return this.intersectsBox( box );
  27682. },
  27683. size: function ( optionalTarget ) {
  27684. console.warn( 'THREE.Box2: .size() has been renamed to .getSize().' );
  27685. return this.getSize( optionalTarget );
  27686. }
  27687. } );
  27688. Object.assign( Box3.prototype, {
  27689. center: function ( optionalTarget ) {
  27690. console.warn( 'THREE.Box3: .center() has been renamed to .getCenter().' );
  27691. return this.getCenter( optionalTarget );
  27692. },
  27693. empty: function () {
  27694. console.warn( 'THREE.Box3: .empty() has been renamed to .isEmpty().' );
  27695. return this.isEmpty();
  27696. },
  27697. isIntersectionBox: function ( box ) {
  27698. console.warn( 'THREE.Box3: .isIntersectionBox() has been renamed to .intersectsBox().' );
  27699. return this.intersectsBox( box );
  27700. },
  27701. isIntersectionSphere: function ( sphere ) {
  27702. console.warn( 'THREE.Box3: .isIntersectionSphere() has been renamed to .intersectsSphere().' );
  27703. return this.intersectsSphere( sphere );
  27704. },
  27705. size: function ( optionalTarget ) {
  27706. console.warn( 'THREE.Box3: .size() has been renamed to .getSize().' );
  27707. return this.getSize( optionalTarget );
  27708. }
  27709. } );
  27710. Line3.prototype.center = function ( optionalTarget ) {
  27711. console.warn( 'THREE.Line3: .center() has been renamed to .getCenter().' );
  27712. return this.getCenter( optionalTarget );
  27713. };
  27714. Object.assign( _Math, {
  27715. random16: function () {
  27716. console.warn( 'THREE.Math: .random16() has been deprecated. Use Math.random() instead.' );
  27717. return Math.random();
  27718. },
  27719. nearestPowerOfTwo: function ( value ) {
  27720. console.warn( 'THREE.Math: .nearestPowerOfTwo() has been renamed to .floorPowerOfTwo().' );
  27721. return _Math.floorPowerOfTwo( value );
  27722. },
  27723. nextPowerOfTwo: function ( value ) {
  27724. console.warn( 'THREE.Math: .nextPowerOfTwo() has been renamed to .ceilPowerOfTwo().' );
  27725. return _Math.ceilPowerOfTwo( value );
  27726. }
  27727. } );
  27728. Object.assign( Matrix3.prototype, {
  27729. flattenToArrayOffset: function ( array, offset ) {
  27730. console.warn( "THREE.Matrix3: .flattenToArrayOffset() has been deprecated. Use .toArray() instead." );
  27731. return this.toArray( array, offset );
  27732. },
  27733. multiplyVector3: function ( vector ) {
  27734. console.warn( 'THREE.Matrix3: .multiplyVector3() has been removed. Use vector.applyMatrix3( matrix ) instead.' );
  27735. return vector.applyMatrix3( this );
  27736. },
  27737. multiplyVector3Array: function ( /* a */ ) {
  27738. console.error( 'THREE.Matrix3: .multiplyVector3Array() has been removed.' );
  27739. },
  27740. applyToBuffer: function ( buffer /*, offset, length */ ) {
  27741. console.warn( 'THREE.Matrix3: .applyToBuffer() has been removed. Use matrix.applyToBufferAttribute( attribute ) instead.' );
  27742. return this.applyToBufferAttribute( buffer );
  27743. },
  27744. applyToVector3Array: function ( /* array, offset, length */ ) {
  27745. console.error( 'THREE.Matrix3: .applyToVector3Array() has been removed.' );
  27746. }
  27747. } );
  27748. Object.assign( Matrix4.prototype, {
  27749. extractPosition: function ( m ) {
  27750. console.warn( 'THREE.Matrix4: .extractPosition() has been renamed to .copyPosition().' );
  27751. return this.copyPosition( m );
  27752. },
  27753. flattenToArrayOffset: function ( array, offset ) {
  27754. console.warn( "THREE.Matrix4: .flattenToArrayOffset() has been deprecated. Use .toArray() instead." );
  27755. return this.toArray( array, offset );
  27756. },
  27757. getPosition: function () {
  27758. var v1;
  27759. return function getPosition() {
  27760. if ( v1 === undefined ) v1 = new Vector3();
  27761. console.warn( 'THREE.Matrix4: .getPosition() has been removed. Use Vector3.setFromMatrixPosition( matrix ) instead.' );
  27762. return v1.setFromMatrixColumn( this, 3 );
  27763. };
  27764. }(),
  27765. setRotationFromQuaternion: function ( q ) {
  27766. console.warn( 'THREE.Matrix4: .setRotationFromQuaternion() has been renamed to .makeRotationFromQuaternion().' );
  27767. return this.makeRotationFromQuaternion( q );
  27768. },
  27769. multiplyToArray: function () {
  27770. console.warn( 'THREE.Matrix4: .multiplyToArray() has been removed.' );
  27771. },
  27772. multiplyVector3: function ( vector ) {
  27773. console.warn( 'THREE.Matrix4: .multiplyVector3() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
  27774. return vector.applyMatrix4( this );
  27775. },
  27776. multiplyVector4: function ( vector ) {
  27777. console.warn( 'THREE.Matrix4: .multiplyVector4() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
  27778. return vector.applyMatrix4( this );
  27779. },
  27780. multiplyVector3Array: function ( /* a */ ) {
  27781. console.error( 'THREE.Matrix4: .multiplyVector3Array() has been removed.' );
  27782. },
  27783. rotateAxis: function ( v ) {
  27784. console.warn( 'THREE.Matrix4: .rotateAxis() has been removed. Use Vector3.transformDirection( matrix ) instead.' );
  27785. v.transformDirection( this );
  27786. },
  27787. crossVector: function ( vector ) {
  27788. console.warn( 'THREE.Matrix4: .crossVector() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
  27789. return vector.applyMatrix4( this );
  27790. },
  27791. translate: function () {
  27792. console.error( 'THREE.Matrix4: .translate() has been removed.' );
  27793. },
  27794. rotateX: function () {
  27795. console.error( 'THREE.Matrix4: .rotateX() has been removed.' );
  27796. },
  27797. rotateY: function () {
  27798. console.error( 'THREE.Matrix4: .rotateY() has been removed.' );
  27799. },
  27800. rotateZ: function () {
  27801. console.error( 'THREE.Matrix4: .rotateZ() has been removed.' );
  27802. },
  27803. rotateByAxis: function () {
  27804. console.error( 'THREE.Matrix4: .rotateByAxis() has been removed.' );
  27805. },
  27806. applyToBuffer: function ( buffer /*, offset, length */ ) {
  27807. console.warn( 'THREE.Matrix4: .applyToBuffer() has been removed. Use matrix.applyToBufferAttribute( attribute ) instead.' );
  27808. return this.applyToBufferAttribute( buffer );
  27809. },
  27810. applyToVector3Array: function ( /* array, offset, length */ ) {
  27811. console.error( 'THREE.Matrix4: .applyToVector3Array() has been removed.' );
  27812. },
  27813. makeFrustum: function ( left, right, bottom, top, near, far ) {
  27814. console.warn( 'THREE.Matrix4: .makeFrustum() has been removed. Use .makePerspective( left, right, top, bottom, near, far ) instead.' );
  27815. return this.makePerspective( left, right, top, bottom, near, far );
  27816. }
  27817. } );
  27818. Plane.prototype.isIntersectionLine = function ( line ) {
  27819. console.warn( 'THREE.Plane: .isIntersectionLine() has been renamed to .intersectsLine().' );
  27820. return this.intersectsLine( line );
  27821. };
  27822. Quaternion.prototype.multiplyVector3 = function ( vector ) {
  27823. console.warn( 'THREE.Quaternion: .multiplyVector3() has been removed. Use is now vector.applyQuaternion( quaternion ) instead.' );
  27824. return vector.applyQuaternion( this );
  27825. };
  27826. Object.assign( Ray.prototype, {
  27827. isIntersectionBox: function ( box ) {
  27828. console.warn( 'THREE.Ray: .isIntersectionBox() has been renamed to .intersectsBox().' );
  27829. return this.intersectsBox( box );
  27830. },
  27831. isIntersectionPlane: function ( plane ) {
  27832. console.warn( 'THREE.Ray: .isIntersectionPlane() has been renamed to .intersectsPlane().' );
  27833. return this.intersectsPlane( plane );
  27834. },
  27835. isIntersectionSphere: function ( sphere ) {
  27836. console.warn( 'THREE.Ray: .isIntersectionSphere() has been renamed to .intersectsSphere().' );
  27837. return this.intersectsSphere( sphere );
  27838. }
  27839. } );
  27840. Object.assign( Triangle.prototype, {
  27841. area: function () {
  27842. console.warn( 'THREE.Triangle: .area() has been renamed to .getArea().' );
  27843. return this.getArea();
  27844. },
  27845. barycoordFromPoint: function ( point, target ) {
  27846. console.warn( 'THREE.Triangle: .barycoordFromPoint() has been renamed to .getBarycoord().' );
  27847. return this.getBarycoord( point, target );
  27848. },
  27849. midpoint: function ( target ) {
  27850. console.warn( 'THREE.Triangle: .midpoint() has been renamed to .getMidpoint().' );
  27851. return this.getMidpoint( target );
  27852. },
  27853. normal: function ( target ) {
  27854. console.warn( 'THREE.Triangle: .normal() has been renamed to .getNormal().' );
  27855. return this.getNormal( target );
  27856. },
  27857. plane: function ( target ) {
  27858. console.warn( 'THREE.Triangle: .plane() has been renamed to .getPlane().' );
  27859. return this.getPlane( target );
  27860. }
  27861. } );
  27862. Object.assign( Triangle, {
  27863. barycoordFromPoint: function ( point, a, b, c, target ) {
  27864. console.warn( 'THREE.Triangle: .barycoordFromPoint() has been renamed to .getBarycoord().' );
  27865. return Triangle.getBarycoord( point, a, b, c, target );
  27866. },
  27867. normal: function ( a, b, c, target ) {
  27868. console.warn( 'THREE.Triangle: .normal() has been renamed to .getNormal().' );
  27869. return Triangle.getNormal( a, b, c, target );
  27870. }
  27871. } );
  27872. Object.assign( Shape.prototype, {
  27873. extractAllPoints: function ( divisions ) {
  27874. console.warn( 'THREE.Shape: .extractAllPoints() has been removed. Use .extractPoints() instead.' );
  27875. return this.extractPoints( divisions );
  27876. },
  27877. extrude: function ( options ) {
  27878. console.warn( 'THREE.Shape: .extrude() has been removed. Use ExtrudeGeometry() instead.' );
  27879. return new ExtrudeGeometry( this, options );
  27880. },
  27881. makeGeometry: function ( options ) {
  27882. console.warn( 'THREE.Shape: .makeGeometry() has been removed. Use ShapeGeometry() instead.' );
  27883. return new ShapeGeometry( this, options );
  27884. }
  27885. } );
  27886. Object.assign( Vector2.prototype, {
  27887. fromAttribute: function ( attribute, index, offset ) {
  27888. console.warn( 'THREE.Vector2: .fromAttribute() has been renamed to .fromBufferAttribute().' );
  27889. return this.fromBufferAttribute( attribute, index, offset );
  27890. },
  27891. distanceToManhattan: function ( v ) {
  27892. console.warn( 'THREE.Vector2: .distanceToManhattan() has been renamed to .manhattanDistanceTo().' );
  27893. return this.manhattanDistanceTo( v );
  27894. },
  27895. lengthManhattan: function () {
  27896. console.warn( 'THREE.Vector2: .lengthManhattan() has been renamed to .manhattanLength().' );
  27897. return this.manhattanLength();
  27898. }
  27899. } );
  27900. Object.assign( Vector3.prototype, {
  27901. setEulerFromRotationMatrix: function () {
  27902. console.error( 'THREE.Vector3: .setEulerFromRotationMatrix() has been removed. Use Euler.setFromRotationMatrix() instead.' );
  27903. },
  27904. setEulerFromQuaternion: function () {
  27905. console.error( 'THREE.Vector3: .setEulerFromQuaternion() has been removed. Use Euler.setFromQuaternion() instead.' );
  27906. },
  27907. getPositionFromMatrix: function ( m ) {
  27908. console.warn( 'THREE.Vector3: .getPositionFromMatrix() has been renamed to .setFromMatrixPosition().' );
  27909. return this.setFromMatrixPosition( m );
  27910. },
  27911. getScaleFromMatrix: function ( m ) {
  27912. console.warn( 'THREE.Vector3: .getScaleFromMatrix() has been renamed to .setFromMatrixScale().' );
  27913. return this.setFromMatrixScale( m );
  27914. },
  27915. getColumnFromMatrix: function ( index, matrix ) {
  27916. console.warn( 'THREE.Vector3: .getColumnFromMatrix() has been renamed to .setFromMatrixColumn().' );
  27917. return this.setFromMatrixColumn( matrix, index );
  27918. },
  27919. applyProjection: function ( m ) {
  27920. console.warn( 'THREE.Vector3: .applyProjection() has been removed. Use .applyMatrix4( m ) instead.' );
  27921. return this.applyMatrix4( m );
  27922. },
  27923. fromAttribute: function ( attribute, index, offset ) {
  27924. console.warn( 'THREE.Vector3: .fromAttribute() has been renamed to .fromBufferAttribute().' );
  27925. return this.fromBufferAttribute( attribute, index, offset );
  27926. },
  27927. distanceToManhattan: function ( v ) {
  27928. console.warn( 'THREE.Vector3: .distanceToManhattan() has been renamed to .manhattanDistanceTo().' );
  27929. return this.manhattanDistanceTo( v );
  27930. },
  27931. lengthManhattan: function () {
  27932. console.warn( 'THREE.Vector3: .lengthManhattan() has been renamed to .manhattanLength().' );
  27933. return this.manhattanLength();
  27934. }
  27935. } );
  27936. Object.assign( Vector4.prototype, {
  27937. fromAttribute: function ( attribute, index, offset ) {
  27938. console.warn( 'THREE.Vector4: .fromAttribute() has been renamed to .fromBufferAttribute().' );
  27939. return this.fromBufferAttribute( attribute, index, offset );
  27940. },
  27941. lengthManhattan: function () {
  27942. console.warn( 'THREE.Vector4: .lengthManhattan() has been renamed to .manhattanLength().' );
  27943. return this.manhattanLength();
  27944. }
  27945. } );
  27946. //
  27947. Object.assign( Geometry.prototype, {
  27948. computeTangents: function () {
  27949. console.error( 'THREE.Geometry: .computeTangents() has been removed.' );
  27950. },
  27951. computeLineDistances: function () {
  27952. console.error( 'THREE.Geometry: .computeLineDistances() has been removed. Use THREE.Line.computeLineDistances() instead.' );
  27953. }
  27954. } );
  27955. Object.assign( Object3D.prototype, {
  27956. getChildByName: function ( name ) {
  27957. console.warn( 'THREE.Object3D: .getChildByName() has been renamed to .getObjectByName().' );
  27958. return this.getObjectByName( name );
  27959. },
  27960. renderDepth: function () {
  27961. console.warn( 'THREE.Object3D: .renderDepth has been removed. Use .renderOrder, instead.' );
  27962. },
  27963. translate: function ( distance, axis ) {
  27964. console.warn( 'THREE.Object3D: .translate() has been removed. Use .translateOnAxis( axis, distance ) instead.' );
  27965. return this.translateOnAxis( axis, distance );
  27966. },
  27967. getWorldRotation: function () {
  27968. console.error( 'THREE.Object3D: .getWorldRotation() has been removed. Use THREE.Object3D.getWorldQuaternion( target ) instead.' );
  27969. }
  27970. } );
  27971. Object.defineProperties( Object3D.prototype, {
  27972. eulerOrder: {
  27973. get: function () {
  27974. console.warn( 'THREE.Object3D: .eulerOrder is now .rotation.order.' );
  27975. return this.rotation.order;
  27976. },
  27977. set: function ( value ) {
  27978. console.warn( 'THREE.Object3D: .eulerOrder is now .rotation.order.' );
  27979. this.rotation.order = value;
  27980. }
  27981. },
  27982. useQuaternion: {
  27983. get: function () {
  27984. console.warn( 'THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.' );
  27985. },
  27986. set: function () {
  27987. console.warn( 'THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.' );
  27988. }
  27989. }
  27990. } );
  27991. Object.defineProperties( LOD.prototype, {
  27992. objects: {
  27993. get: function () {
  27994. console.warn( 'THREE.LOD: .objects has been renamed to .levels.' );
  27995. return this.levels;
  27996. }
  27997. }
  27998. } );
  27999. Object.defineProperty( Skeleton.prototype, 'useVertexTexture', {
  28000. get: function () {
  28001. console.warn( 'THREE.Skeleton: useVertexTexture has been removed.' );
  28002. },
  28003. set: function () {
  28004. console.warn( 'THREE.Skeleton: useVertexTexture has been removed.' );
  28005. }
  28006. } );
  28007. SkinnedMesh.prototype.initBones = function () {
  28008. console.error( 'THREE.SkinnedMesh: initBones() has been removed.' );
  28009. };
  28010. Object.defineProperty( Curve.prototype, '__arcLengthDivisions', {
  28011. get: function () {
  28012. console.warn( 'THREE.Curve: .__arcLengthDivisions is now .arcLengthDivisions.' );
  28013. return this.arcLengthDivisions;
  28014. },
  28015. set: function ( value ) {
  28016. console.warn( 'THREE.Curve: .__arcLengthDivisions is now .arcLengthDivisions.' );
  28017. this.arcLengthDivisions = value;
  28018. }
  28019. } );
  28020. //
  28021. PerspectiveCamera.prototype.setLens = function ( focalLength, filmGauge ) {
  28022. console.warn( "THREE.PerspectiveCamera.setLens is deprecated. " +
  28023. "Use .setFocalLength and .filmGauge for a photographic setup." );
  28024. if ( filmGauge !== undefined ) this.filmGauge = filmGauge;
  28025. this.setFocalLength( focalLength );
  28026. };
  28027. //
  28028. Object.defineProperties( Light.prototype, {
  28029. onlyShadow: {
  28030. set: function () {
  28031. console.warn( 'THREE.Light: .onlyShadow has been removed.' );
  28032. }
  28033. },
  28034. shadowCameraFov: {
  28035. set: function ( value ) {
  28036. console.warn( 'THREE.Light: .shadowCameraFov is now .shadow.camera.fov.' );
  28037. this.shadow.camera.fov = value;
  28038. }
  28039. },
  28040. shadowCameraLeft: {
  28041. set: function ( value ) {
  28042. console.warn( 'THREE.Light: .shadowCameraLeft is now .shadow.camera.left.' );
  28043. this.shadow.camera.left = value;
  28044. }
  28045. },
  28046. shadowCameraRight: {
  28047. set: function ( value ) {
  28048. console.warn( 'THREE.Light: .shadowCameraRight is now .shadow.camera.right.' );
  28049. this.shadow.camera.right = value;
  28050. }
  28051. },
  28052. shadowCameraTop: {
  28053. set: function ( value ) {
  28054. console.warn( 'THREE.Light: .shadowCameraTop is now .shadow.camera.top.' );
  28055. this.shadow.camera.top = value;
  28056. }
  28057. },
  28058. shadowCameraBottom: {
  28059. set: function ( value ) {
  28060. console.warn( 'THREE.Light: .shadowCameraBottom is now .shadow.camera.bottom.' );
  28061. this.shadow.camera.bottom = value;
  28062. }
  28063. },
  28064. shadowCameraNear: {
  28065. set: function ( value ) {
  28066. console.warn( 'THREE.Light: .shadowCameraNear is now .shadow.camera.near.' );
  28067. this.shadow.camera.near = value;
  28068. }
  28069. },
  28070. shadowCameraFar: {
  28071. set: function ( value ) {
  28072. console.warn( 'THREE.Light: .shadowCameraFar is now .shadow.camera.far.' );
  28073. this.shadow.camera.far = value;
  28074. }
  28075. },
  28076. shadowCameraVisible: {
  28077. set: function () {
  28078. console.warn( 'THREE.Light: .shadowCameraVisible has been removed. Use new THREE.CameraHelper( light.shadow.camera ) instead.' );
  28079. }
  28080. },
  28081. shadowBias: {
  28082. set: function ( value ) {
  28083. console.warn( 'THREE.Light: .shadowBias is now .shadow.bias.' );
  28084. this.shadow.bias = value;
  28085. }
  28086. },
  28087. shadowDarkness: {
  28088. set: function () {
  28089. console.warn( 'THREE.Light: .shadowDarkness has been removed.' );
  28090. }
  28091. },
  28092. shadowMapWidth: {
  28093. set: function ( value ) {
  28094. console.warn( 'THREE.Light: .shadowMapWidth is now .shadow.mapSize.width.' );
  28095. this.shadow.mapSize.width = value;
  28096. }
  28097. },
  28098. shadowMapHeight: {
  28099. set: function ( value ) {
  28100. console.warn( 'THREE.Light: .shadowMapHeight is now .shadow.mapSize.height.' );
  28101. this.shadow.mapSize.height = value;
  28102. }
  28103. }
  28104. } );
  28105. //
  28106. Object.defineProperties( BufferAttribute.prototype, {
  28107. length: {
  28108. get: function () {
  28109. console.warn( 'THREE.BufferAttribute: .length has been deprecated. Use .count instead.' );
  28110. return this.array.length;
  28111. }
  28112. },
  28113. copyIndicesArray: function ( /* indices */ ) {
  28114. console.error( 'THREE.BufferAttribute: .copyIndicesArray() has been removed.' );
  28115. }
  28116. } );
  28117. Object.assign( BufferGeometry.prototype, {
  28118. addIndex: function ( index ) {
  28119. console.warn( 'THREE.BufferGeometry: .addIndex() has been renamed to .setIndex().' );
  28120. this.setIndex( index );
  28121. },
  28122. addDrawCall: function ( start, count, indexOffset ) {
  28123. if ( indexOffset !== undefined ) {
  28124. console.warn( 'THREE.BufferGeometry: .addDrawCall() no longer supports indexOffset.' );
  28125. }
  28126. console.warn( 'THREE.BufferGeometry: .addDrawCall() is now .addGroup().' );
  28127. this.addGroup( start, count );
  28128. },
  28129. clearDrawCalls: function () {
  28130. console.warn( 'THREE.BufferGeometry: .clearDrawCalls() is now .clearGroups().' );
  28131. this.clearGroups();
  28132. },
  28133. computeTangents: function () {
  28134. console.warn( 'THREE.BufferGeometry: .computeTangents() has been removed.' );
  28135. },
  28136. computeOffsets: function () {
  28137. console.warn( 'THREE.BufferGeometry: .computeOffsets() has been removed.' );
  28138. }
  28139. } );
  28140. Object.defineProperties( BufferGeometry.prototype, {
  28141. drawcalls: {
  28142. get: function () {
  28143. console.error( 'THREE.BufferGeometry: .drawcalls has been renamed to .groups.' );
  28144. return this.groups;
  28145. }
  28146. },
  28147. offsets: {
  28148. get: function () {
  28149. console.warn( 'THREE.BufferGeometry: .offsets has been renamed to .groups.' );
  28150. return this.groups;
  28151. }
  28152. }
  28153. } );
  28154. //
  28155. Object.assign( ExtrudeBufferGeometry.prototype, {
  28156. getArrays: function () {
  28157. console.error( 'THREE.ExtrudeBufferGeometry: .getArrays() has been removed.' );
  28158. },
  28159. addShapeList: function () {
  28160. console.error( 'THREE.ExtrudeBufferGeometry: .addShapeList() has been removed.' );
  28161. },
  28162. addShape: function () {
  28163. console.error( 'THREE.ExtrudeBufferGeometry: .addShape() has been removed.' );
  28164. }
  28165. } );
  28166. //
  28167. Object.defineProperties( Uniform.prototype, {
  28168. dynamic: {
  28169. set: function () {
  28170. console.warn( 'THREE.Uniform: .dynamic has been removed. Use object.onBeforeRender() instead.' );
  28171. }
  28172. },
  28173. onUpdate: {
  28174. value: function () {
  28175. console.warn( 'THREE.Uniform: .onUpdate() has been removed. Use object.onBeforeRender() instead.' );
  28176. return this;
  28177. }
  28178. }
  28179. } );
  28180. //
  28181. Object.defineProperties( Material.prototype, {
  28182. wrapAround: {
  28183. get: function () {
  28184. console.warn( 'THREE.Material: .wrapAround has been removed.' );
  28185. },
  28186. set: function () {
  28187. console.warn( 'THREE.Material: .wrapAround has been removed.' );
  28188. }
  28189. },
  28190. overdraw: {
  28191. get: function () {
  28192. console.warn( 'THREE.Material: .overdraw has been removed.' );
  28193. },
  28194. set: function () {
  28195. console.warn( 'THREE.Material: .overdraw has been removed.' );
  28196. }
  28197. },
  28198. wrapRGB: {
  28199. get: function () {
  28200. console.warn( 'THREE.Material: .wrapRGB has been removed.' );
  28201. return new Color();
  28202. }
  28203. },
  28204. shading: {
  28205. get: function () {
  28206. console.error( 'THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.' );
  28207. },
  28208. set: function ( value ) {
  28209. console.warn( 'THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.' );
  28210. this.flatShading = ( value === FlatShading );
  28211. }
  28212. }
  28213. } );
  28214. Object.defineProperties( MeshPhongMaterial.prototype, {
  28215. metal: {
  28216. get: function () {
  28217. console.warn( 'THREE.MeshPhongMaterial: .metal has been removed. Use THREE.MeshStandardMaterial instead.' );
  28218. return false;
  28219. },
  28220. set: function () {
  28221. console.warn( 'THREE.MeshPhongMaterial: .metal has been removed. Use THREE.MeshStandardMaterial instead' );
  28222. }
  28223. }
  28224. } );
  28225. Object.defineProperties( ShaderMaterial.prototype, {
  28226. derivatives: {
  28227. get: function () {
  28228. console.warn( 'THREE.ShaderMaterial: .derivatives has been moved to .extensions.derivatives.' );
  28229. return this.extensions.derivatives;
  28230. },
  28231. set: function ( value ) {
  28232. console.warn( 'THREE. ShaderMaterial: .derivatives has been moved to .extensions.derivatives.' );
  28233. this.extensions.derivatives = value;
  28234. }
  28235. }
  28236. } );
  28237. //
  28238. Object.assign( WebGLRenderer.prototype, {
  28239. clearTarget: function ( renderTarget, color, depth, stencil ) {
  28240. console.warn( 'THREE.WebGLRenderer: .clearTarget() has been deprecated. Use .setRenderTarget() and .clear() instead.' );
  28241. this.setRenderTarget( renderTarget );
  28242. this.clear( color, depth, stencil );
  28243. },
  28244. animate: function ( callback ) {
  28245. console.warn( 'THREE.WebGLRenderer: .animate() is now .setAnimationLoop().' );
  28246. this.setAnimationLoop( callback );
  28247. },
  28248. getCurrentRenderTarget: function () {
  28249. console.warn( 'THREE.WebGLRenderer: .getCurrentRenderTarget() is now .getRenderTarget().' );
  28250. return this.getRenderTarget();
  28251. },
  28252. getMaxAnisotropy: function () {
  28253. console.warn( 'THREE.WebGLRenderer: .getMaxAnisotropy() is now .capabilities.getMaxAnisotropy().' );
  28254. return this.capabilities.getMaxAnisotropy();
  28255. },
  28256. getPrecision: function () {
  28257. console.warn( 'THREE.WebGLRenderer: .getPrecision() is now .capabilities.precision.' );
  28258. return this.capabilities.precision;
  28259. },
  28260. resetGLState: function () {
  28261. console.warn( 'THREE.WebGLRenderer: .resetGLState() is now .state.reset().' );
  28262. return this.state.reset();
  28263. },
  28264. supportsFloatTextures: function () {
  28265. console.warn( 'THREE.WebGLRenderer: .supportsFloatTextures() is now .extensions.get( \'OES_texture_float\' ).' );
  28266. return this.extensions.get( 'OES_texture_float' );
  28267. },
  28268. supportsHalfFloatTextures: function () {
  28269. console.warn( 'THREE.WebGLRenderer: .supportsHalfFloatTextures() is now .extensions.get( \'OES_texture_half_float\' ).' );
  28270. return this.extensions.get( 'OES_texture_half_float' );
  28271. },
  28272. supportsStandardDerivatives: function () {
  28273. console.warn( 'THREE.WebGLRenderer: .supportsStandardDerivatives() is now .extensions.get( \'OES_standard_derivatives\' ).' );
  28274. return this.extensions.get( 'OES_standard_derivatives' );
  28275. },
  28276. supportsCompressedTextureS3TC: function () {
  28277. console.warn( 'THREE.WebGLRenderer: .supportsCompressedTextureS3TC() is now .extensions.get( \'WEBGL_compressed_texture_s3tc\' ).' );
  28278. return this.extensions.get( 'WEBGL_compressed_texture_s3tc' );
  28279. },
  28280. supportsCompressedTexturePVRTC: function () {
  28281. console.warn( 'THREE.WebGLRenderer: .supportsCompressedTexturePVRTC() is now .extensions.get( \'WEBGL_compressed_texture_pvrtc\' ).' );
  28282. return this.extensions.get( 'WEBGL_compressed_texture_pvrtc' );
  28283. },
  28284. supportsBlendMinMax: function () {
  28285. console.warn( 'THREE.WebGLRenderer: .supportsBlendMinMax() is now .extensions.get( \'EXT_blend_minmax\' ).' );
  28286. return this.extensions.get( 'EXT_blend_minmax' );
  28287. },
  28288. supportsVertexTextures: function () {
  28289. console.warn( 'THREE.WebGLRenderer: .supportsVertexTextures() is now .capabilities.vertexTextures.' );
  28290. return this.capabilities.vertexTextures;
  28291. },
  28292. supportsInstancedArrays: function () {
  28293. console.warn( 'THREE.WebGLRenderer: .supportsInstancedArrays() is now .extensions.get( \'ANGLE_instanced_arrays\' ).' );
  28294. return this.extensions.get( 'ANGLE_instanced_arrays' );
  28295. },
  28296. enableScissorTest: function ( boolean ) {
  28297. console.warn( 'THREE.WebGLRenderer: .enableScissorTest() is now .setScissorTest().' );
  28298. this.setScissorTest( boolean );
  28299. },
  28300. initMaterial: function () {
  28301. console.warn( 'THREE.WebGLRenderer: .initMaterial() has been removed.' );
  28302. },
  28303. addPrePlugin: function () {
  28304. console.warn( 'THREE.WebGLRenderer: .addPrePlugin() has been removed.' );
  28305. },
  28306. addPostPlugin: function () {
  28307. console.warn( 'THREE.WebGLRenderer: .addPostPlugin() has been removed.' );
  28308. },
  28309. updateShadowMap: function () {
  28310. console.warn( 'THREE.WebGLRenderer: .updateShadowMap() has been removed.' );
  28311. },
  28312. setFaceCulling: function () {
  28313. console.warn( 'THREE.WebGLRenderer: .setFaceCulling() has been removed.' );
  28314. }
  28315. } );
  28316. Object.defineProperties( WebGLRenderer.prototype, {
  28317. shadowMapEnabled: {
  28318. get: function () {
  28319. return this.shadowMap.enabled;
  28320. },
  28321. set: function ( value ) {
  28322. console.warn( 'THREE.WebGLRenderer: .shadowMapEnabled is now .shadowMap.enabled.' );
  28323. this.shadowMap.enabled = value;
  28324. }
  28325. },
  28326. shadowMapType: {
  28327. get: function () {
  28328. return this.shadowMap.type;
  28329. },
  28330. set: function ( value ) {
  28331. console.warn( 'THREE.WebGLRenderer: .shadowMapType is now .shadowMap.type.' );
  28332. this.shadowMap.type = value;
  28333. }
  28334. },
  28335. shadowMapCullFace: {
  28336. get: function () {
  28337. console.warn( 'THREE.WebGLRenderer: .shadowMapCullFace has been removed. Set Material.shadowSide instead.' );
  28338. return undefined;
  28339. },
  28340. set: function ( /* value */ ) {
  28341. console.warn( 'THREE.WebGLRenderer: .shadowMapCullFace has been removed. Set Material.shadowSide instead.' );
  28342. }
  28343. }
  28344. } );
  28345. Object.defineProperties( WebGLShadowMap.prototype, {
  28346. cullFace: {
  28347. get: function () {
  28348. console.warn( 'THREE.WebGLRenderer: .shadowMap.cullFace has been removed. Set Material.shadowSide instead.' );
  28349. return undefined;
  28350. },
  28351. set: function ( /* cullFace */ ) {
  28352. console.warn( 'THREE.WebGLRenderer: .shadowMap.cullFace has been removed. Set Material.shadowSide instead.' );
  28353. }
  28354. },
  28355. renderReverseSided: {
  28356. get: function () {
  28357. console.warn( 'THREE.WebGLRenderer: .shadowMap.renderReverseSided has been removed. Set Material.shadowSide instead.' );
  28358. return undefined;
  28359. },
  28360. set: function () {
  28361. console.warn( 'THREE.WebGLRenderer: .shadowMap.renderReverseSided has been removed. Set Material.shadowSide instead.' );
  28362. }
  28363. },
  28364. renderSingleSided: {
  28365. get: function () {
  28366. console.warn( 'THREE.WebGLRenderer: .shadowMap.renderSingleSided has been removed. Set Material.shadowSide instead.' );
  28367. return undefined;
  28368. },
  28369. set: function () {
  28370. console.warn( 'THREE.WebGLRenderer: .shadowMap.renderSingleSided has been removed. Set Material.shadowSide instead.' );
  28371. }
  28372. }
  28373. } );
  28374. //
  28375. Object.defineProperties( WebGLRenderTargetCube.prototype, {
  28376. activeCubeFace: {
  28377. set: function ( /* value */ ) {
  28378. console.warn( 'THREE.WebGLRenderTargetCube: .activeCubeFace has been removed. It is now the second parameter of WebGLRenderer.setRenderTarget().' );
  28379. }
  28380. },
  28381. activeMipMapLevel: {
  28382. set: function ( /* value */ ) {
  28383. console.warn( 'THREE.WebGLRenderTargetCube: .activeMipMapLevel has been removed. It is now the third parameter of WebGLRenderer.setRenderTarget().' );
  28384. }
  28385. }
  28386. } );
  28387. //
  28388. Object.defineProperties( WebGLRenderTarget.prototype, {
  28389. wrapS: {
  28390. get: function () {
  28391. console.warn( 'THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.' );
  28392. return this.texture.wrapS;
  28393. },
  28394. set: function ( value ) {
  28395. console.warn( 'THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.' );
  28396. this.texture.wrapS = value;
  28397. }
  28398. },
  28399. wrapT: {
  28400. get: function () {
  28401. console.warn( 'THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.' );
  28402. return this.texture.wrapT;
  28403. },
  28404. set: function ( value ) {
  28405. console.warn( 'THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.' );
  28406. this.texture.wrapT = value;
  28407. }
  28408. },
  28409. magFilter: {
  28410. get: function () {
  28411. console.warn( 'THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.' );
  28412. return this.texture.magFilter;
  28413. },
  28414. set: function ( value ) {
  28415. console.warn( 'THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.' );
  28416. this.texture.magFilter = value;
  28417. }
  28418. },
  28419. minFilter: {
  28420. get: function () {
  28421. console.warn( 'THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.' );
  28422. return this.texture.minFilter;
  28423. },
  28424. set: function ( value ) {
  28425. console.warn( 'THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.' );
  28426. this.texture.minFilter = value;
  28427. }
  28428. },
  28429. anisotropy: {
  28430. get: function () {
  28431. console.warn( 'THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy.' );
  28432. return this.texture.anisotropy;
  28433. },
  28434. set: function ( value ) {
  28435. console.warn( 'THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy.' );
  28436. this.texture.anisotropy = value;
  28437. }
  28438. },
  28439. offset: {
  28440. get: function () {
  28441. console.warn( 'THREE.WebGLRenderTarget: .offset is now .texture.offset.' );
  28442. return this.texture.offset;
  28443. },
  28444. set: function ( value ) {
  28445. console.warn( 'THREE.WebGLRenderTarget: .offset is now .texture.offset.' );
  28446. this.texture.offset = value;
  28447. }
  28448. },
  28449. repeat: {
  28450. get: function () {
  28451. console.warn( 'THREE.WebGLRenderTarget: .repeat is now .texture.repeat.' );
  28452. return this.texture.repeat;
  28453. },
  28454. set: function ( value ) {
  28455. console.warn( 'THREE.WebGLRenderTarget: .repeat is now .texture.repeat.' );
  28456. this.texture.repeat = value;
  28457. }
  28458. },
  28459. format: {
  28460. get: function () {
  28461. console.warn( 'THREE.WebGLRenderTarget: .format is now .texture.format.' );
  28462. return this.texture.format;
  28463. },
  28464. set: function ( value ) {
  28465. console.warn( 'THREE.WebGLRenderTarget: .format is now .texture.format.' );
  28466. this.texture.format = value;
  28467. }
  28468. },
  28469. type: {
  28470. get: function () {
  28471. console.warn( 'THREE.WebGLRenderTarget: .type is now .texture.type.' );
  28472. return this.texture.type;
  28473. },
  28474. set: function ( value ) {
  28475. console.warn( 'THREE.WebGLRenderTarget: .type is now .texture.type.' );
  28476. this.texture.type = value;
  28477. }
  28478. },
  28479. generateMipmaps: {
  28480. get: function () {
  28481. console.warn( 'THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps.' );
  28482. return this.texture.generateMipmaps;
  28483. },
  28484. set: function ( value ) {
  28485. console.warn( 'THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps.' );
  28486. this.texture.generateMipmaps = value;
  28487. }
  28488. }
  28489. } );
  28490. //
  28491. Object.defineProperties( WebVRManager.prototype, {
  28492. standing: {
  28493. set: function ( /* value */ ) {
  28494. console.warn( 'THREE.WebVRManager: .standing has been removed.' );
  28495. }
  28496. },
  28497. userHeight: {
  28498. set: function ( /* value */ ) {
  28499. console.warn( 'THREE.WebVRManager: .userHeight has been removed.' );
  28500. }
  28501. }
  28502. } );
  28503. //
  28504. Audio.prototype.load = function ( file ) {
  28505. console.warn( 'THREE.Audio: .load has been deprecated. Use THREE.AudioLoader instead.' );
  28506. var scope = this;
  28507. var audioLoader = new AudioLoader();
  28508. audioLoader.load( file, function ( buffer ) {
  28509. scope.setBuffer( buffer );
  28510. } );
  28511. return this;
  28512. };
  28513. AudioAnalyser.prototype.getData = function () {
  28514. console.warn( 'THREE.AudioAnalyser: .getData() is now .getFrequencyData().' );
  28515. return this.getFrequencyData();
  28516. };
  28517. //
  28518. CubeCamera.prototype.updateCubeMap = function ( renderer, scene ) {
  28519. console.warn( 'THREE.CubeCamera: .updateCubeMap() is now .update().' );
  28520. return this.update( renderer, scene );
  28521. };
  28522. //
  28523. var GeometryUtils = {
  28524. merge: function ( geometry1, geometry2, materialIndexOffset ) {
  28525. console.warn( 'THREE.GeometryUtils: .merge() has been moved to Geometry. Use geometry.merge( geometry2, matrix, materialIndexOffset ) instead.' );
  28526. var matrix;
  28527. if ( geometry2.isMesh ) {
  28528. geometry2.matrixAutoUpdate && geometry2.updateMatrix();
  28529. matrix = geometry2.matrix;
  28530. geometry2 = geometry2.geometry;
  28531. }
  28532. geometry1.merge( geometry2, matrix, materialIndexOffset );
  28533. },
  28534. center: function ( geometry ) {
  28535. console.warn( 'THREE.GeometryUtils: .center() has been moved to Geometry. Use geometry.center() instead.' );
  28536. return geometry.center();
  28537. }
  28538. };
  28539. ImageUtils.crossOrigin = undefined;
  28540. ImageUtils.loadTexture = function ( url, mapping, onLoad, onError ) {
  28541. console.warn( 'THREE.ImageUtils.loadTexture has been deprecated. Use THREE.TextureLoader() instead.' );
  28542. var loader = new TextureLoader();
  28543. loader.setCrossOrigin( this.crossOrigin );
  28544. var texture = loader.load( url, onLoad, undefined, onError );
  28545. if ( mapping ) texture.mapping = mapping;
  28546. return texture;
  28547. };
  28548. ImageUtils.loadTextureCube = function ( urls, mapping, onLoad, onError ) {
  28549. console.warn( 'THREE.ImageUtils.loadTextureCube has been deprecated. Use THREE.CubeTextureLoader() instead.' );
  28550. var loader = new CubeTextureLoader();
  28551. loader.setCrossOrigin( this.crossOrigin );
  28552. var texture = loader.load( urls, onLoad, undefined, onError );
  28553. if ( mapping ) texture.mapping = mapping;
  28554. return texture;
  28555. };
  28556. ImageUtils.loadCompressedTexture = function () {
  28557. console.error( 'THREE.ImageUtils.loadCompressedTexture has been removed. Use THREE.DDSLoader instead.' );
  28558. };
  28559. ImageUtils.loadCompressedTextureCube = function () {
  28560. console.error( 'THREE.ImageUtils.loadCompressedTextureCube has been removed. Use THREE.DDSLoader instead.' );
  28561. };
  28562. //
  28563. function Projector() {
  28564. console.error( 'THREE.Projector has been moved to /examples/js/renderers/Projector.js.' );
  28565. this.projectVector = function ( vector, camera ) {
  28566. console.warn( 'THREE.Projector: .projectVector() is now vector.project().' );
  28567. vector.project( camera );
  28568. };
  28569. this.unprojectVector = function ( vector, camera ) {
  28570. console.warn( 'THREE.Projector: .unprojectVector() is now vector.unproject().' );
  28571. vector.unproject( camera );
  28572. };
  28573. this.pickingRay = function () {
  28574. console.error( 'THREE.Projector: .pickingRay() is now raycaster.setFromCamera().' );
  28575. };
  28576. }
  28577. //
  28578. function CanvasRenderer() {
  28579. console.error( 'THREE.CanvasRenderer has been removed' );
  28580. }
  28581. //
  28582. function JSONLoader() {
  28583. console.error( 'THREE.JSONLoader has been removed.' );
  28584. }
  28585. //
  28586. var SceneUtils = {
  28587. createMultiMaterialObject: function ( /* geometry, materials */ ) {
  28588. console.error( 'THREE.SceneUtils has been moved to /examples/js/utils/SceneUtils.js' );
  28589. },
  28590. detach: function ( /* child, parent, scene */ ) {
  28591. console.error( 'THREE.SceneUtils has been moved to /examples/js/utils/SceneUtils.js' );
  28592. },
  28593. attach: function ( /* child, scene, parent */ ) {
  28594. console.error( 'THREE.SceneUtils has been moved to /examples/js/utils/SceneUtils.js' );
  28595. }
  28596. };
  28597. //
  28598. function LensFlare() {
  28599. console.error( 'THREE.LensFlare has been moved to /examples/js/objects/Lensflare.js' );
  28600. }
  28601. exports.WebGLMultisampleRenderTarget = WebGLMultisampleRenderTarget;
  28602. exports.WebGLRenderTargetCube = WebGLRenderTargetCube;
  28603. exports.WebGLRenderTarget = WebGLRenderTarget;
  28604. exports.WebGLRenderer = WebGLRenderer;
  28605. exports.ShaderLib = ShaderLib;
  28606. exports.UniformsLib = UniformsLib;
  28607. exports.UniformsUtils = UniformsUtils;
  28608. exports.ShaderChunk = ShaderChunk;
  28609. exports.FogExp2 = FogExp2;
  28610. exports.Fog = Fog;
  28611. exports.Scene = Scene;
  28612. exports.Sprite = Sprite;
  28613. exports.LOD = LOD;
  28614. exports.SkinnedMesh = SkinnedMesh;
  28615. exports.Skeleton = Skeleton;
  28616. exports.Bone = Bone;
  28617. exports.Mesh = Mesh;
  28618. exports.LineSegments = LineSegments;
  28619. exports.LineLoop = LineLoop;
  28620. exports.Line = Line;
  28621. exports.Points = Points;
  28622. exports.Group = Group;
  28623. exports.VideoTexture = VideoTexture;
  28624. exports.DataTexture = DataTexture;
  28625. exports.DataTexture3D = DataTexture3D;
  28626. exports.CompressedTexture = CompressedTexture;
  28627. exports.CubeTexture = CubeTexture;
  28628. exports.CanvasTexture = CanvasTexture;
  28629. exports.DepthTexture = DepthTexture;
  28630. exports.Texture = Texture;
  28631. exports.AnimationLoader = AnimationLoader;
  28632. exports.CompressedTextureLoader = CompressedTextureLoader;
  28633. exports.DataTextureLoader = DataTextureLoader;
  28634. exports.CubeTextureLoader = CubeTextureLoader;
  28635. exports.TextureLoader = TextureLoader;
  28636. exports.ObjectLoader = ObjectLoader;
  28637. exports.MaterialLoader = MaterialLoader;
  28638. exports.BufferGeometryLoader = BufferGeometryLoader;
  28639. exports.DefaultLoadingManager = DefaultLoadingManager;
  28640. exports.LoadingManager = LoadingManager;
  28641. exports.ImageLoader = ImageLoader;
  28642. exports.ImageBitmapLoader = ImageBitmapLoader;
  28643. exports.FontLoader = FontLoader;
  28644. exports.FileLoader = FileLoader;
  28645. exports.Loader = Loader;
  28646. exports.LoaderUtils = LoaderUtils;
  28647. exports.Cache = Cache;
  28648. exports.AudioLoader = AudioLoader;
  28649. exports.SpotLightShadow = SpotLightShadow;
  28650. exports.SpotLight = SpotLight;
  28651. exports.PointLight = PointLight;
  28652. exports.RectAreaLight = RectAreaLight;
  28653. exports.HemisphereLight = HemisphereLight;
  28654. exports.DirectionalLightShadow = DirectionalLightShadow;
  28655. exports.DirectionalLight = DirectionalLight;
  28656. exports.AmbientLight = AmbientLight;
  28657. exports.LightShadow = LightShadow;
  28658. exports.Light = Light;
  28659. exports.StereoCamera = StereoCamera;
  28660. exports.PerspectiveCamera = PerspectiveCamera;
  28661. exports.OrthographicCamera = OrthographicCamera;
  28662. exports.CubeCamera = CubeCamera;
  28663. exports.ArrayCamera = ArrayCamera;
  28664. exports.Camera = Camera;
  28665. exports.AudioListener = AudioListener;
  28666. exports.PositionalAudio = PositionalAudio;
  28667. exports.AudioContext = AudioContext;
  28668. exports.AudioAnalyser = AudioAnalyser;
  28669. exports.Audio = Audio;
  28670. exports.VectorKeyframeTrack = VectorKeyframeTrack;
  28671. exports.StringKeyframeTrack = StringKeyframeTrack;
  28672. exports.QuaternionKeyframeTrack = QuaternionKeyframeTrack;
  28673. exports.NumberKeyframeTrack = NumberKeyframeTrack;
  28674. exports.ColorKeyframeTrack = ColorKeyframeTrack;
  28675. exports.BooleanKeyframeTrack = BooleanKeyframeTrack;
  28676. exports.PropertyMixer = PropertyMixer;
  28677. exports.PropertyBinding = PropertyBinding;
  28678. exports.KeyframeTrack = KeyframeTrack;
  28679. exports.AnimationUtils = AnimationUtils;
  28680. exports.AnimationObjectGroup = AnimationObjectGroup;
  28681. exports.AnimationMixer = AnimationMixer;
  28682. exports.AnimationClip = AnimationClip;
  28683. exports.Uniform = Uniform;
  28684. exports.InstancedBufferGeometry = InstancedBufferGeometry;
  28685. exports.BufferGeometry = BufferGeometry;
  28686. exports.Geometry = Geometry;
  28687. exports.InterleavedBufferAttribute = InterleavedBufferAttribute;
  28688. exports.InstancedInterleavedBuffer = InstancedInterleavedBuffer;
  28689. exports.InterleavedBuffer = InterleavedBuffer;
  28690. exports.InstancedBufferAttribute = InstancedBufferAttribute;
  28691. exports.Face3 = Face3;
  28692. exports.Object3D = Object3D;
  28693. exports.Raycaster = Raycaster;
  28694. exports.Layers = Layers;
  28695. exports.EventDispatcher = EventDispatcher;
  28696. exports.Clock = Clock;
  28697. exports.QuaternionLinearInterpolant = QuaternionLinearInterpolant;
  28698. exports.LinearInterpolant = LinearInterpolant;
  28699. exports.DiscreteInterpolant = DiscreteInterpolant;
  28700. exports.CubicInterpolant = CubicInterpolant;
  28701. exports.Interpolant = Interpolant;
  28702. exports.Triangle = Triangle;
  28703. exports.Math = _Math;
  28704. exports.Spherical = Spherical;
  28705. exports.Cylindrical = Cylindrical;
  28706. exports.Plane = Plane;
  28707. exports.Frustum = Frustum;
  28708. exports.Sphere = Sphere;
  28709. exports.Ray = Ray;
  28710. exports.Matrix4 = Matrix4;
  28711. exports.Matrix3 = Matrix3;
  28712. exports.Box3 = Box3;
  28713. exports.Box2 = Box2;
  28714. exports.Line3 = Line3;
  28715. exports.Euler = Euler;
  28716. exports.Vector4 = Vector4;
  28717. exports.Vector3 = Vector3;
  28718. exports.Vector2 = Vector2;
  28719. exports.Quaternion = Quaternion;
  28720. exports.Color = Color;
  28721. exports.ImmediateRenderObject = ImmediateRenderObject;
  28722. exports.VertexNormalsHelper = VertexNormalsHelper;
  28723. exports.SpotLightHelper = SpotLightHelper;
  28724. exports.SkeletonHelper = SkeletonHelper;
  28725. exports.PointLightHelper = PointLightHelper;
  28726. exports.RectAreaLightHelper = RectAreaLightHelper;
  28727. exports.HemisphereLightHelper = HemisphereLightHelper;
  28728. exports.GridHelper = GridHelper;
  28729. exports.PolarGridHelper = PolarGridHelper;
  28730. exports.PositionalAudioHelper = PositionalAudioHelper;
  28731. exports.FaceNormalsHelper = FaceNormalsHelper;
  28732. exports.DirectionalLightHelper = DirectionalLightHelper;
  28733. exports.CameraHelper = CameraHelper;
  28734. exports.BoxHelper = BoxHelper;
  28735. exports.Box3Helper = Box3Helper;
  28736. exports.PlaneHelper = PlaneHelper;
  28737. exports.ArrowHelper = ArrowHelper;
  28738. exports.AxesHelper = AxesHelper;
  28739. exports.Shape = Shape;
  28740. exports.Path = Path;
  28741. exports.ShapePath = ShapePath;
  28742. exports.Font = Font;
  28743. exports.CurvePath = CurvePath;
  28744. exports.Curve = Curve;
  28745. exports.ImageUtils = ImageUtils;
  28746. exports.ShapeUtils = ShapeUtils;
  28747. exports.WebGLUtils = WebGLUtils;
  28748. exports.WireframeGeometry = WireframeGeometry;
  28749. exports.ParametricGeometry = ParametricGeometry;
  28750. exports.ParametricBufferGeometry = ParametricBufferGeometry;
  28751. exports.TetrahedronGeometry = TetrahedronGeometry;
  28752. exports.TetrahedronBufferGeometry = TetrahedronBufferGeometry;
  28753. exports.OctahedronGeometry = OctahedronGeometry;
  28754. exports.OctahedronBufferGeometry = OctahedronBufferGeometry;
  28755. exports.IcosahedronGeometry = IcosahedronGeometry;
  28756. exports.IcosahedronBufferGeometry = IcosahedronBufferGeometry;
  28757. exports.DodecahedronGeometry = DodecahedronGeometry;
  28758. exports.DodecahedronBufferGeometry = DodecahedronBufferGeometry;
  28759. exports.PolyhedronGeometry = PolyhedronGeometry;
  28760. exports.PolyhedronBufferGeometry = PolyhedronBufferGeometry;
  28761. exports.TubeGeometry = TubeGeometry;
  28762. exports.TubeBufferGeometry = TubeBufferGeometry;
  28763. exports.TorusKnotGeometry = TorusKnotGeometry;
  28764. exports.TorusKnotBufferGeometry = TorusKnotBufferGeometry;
  28765. exports.TorusGeometry = TorusGeometry;
  28766. exports.TorusBufferGeometry = TorusBufferGeometry;
  28767. exports.TextGeometry = TextGeometry;
  28768. exports.TextBufferGeometry = TextBufferGeometry;
  28769. exports.SphereGeometry = SphereGeometry;
  28770. exports.SphereBufferGeometry = SphereBufferGeometry;
  28771. exports.RingGeometry = RingGeometry;
  28772. exports.RingBufferGeometry = RingBufferGeometry;
  28773. exports.PlaneGeometry = PlaneGeometry;
  28774. exports.PlaneBufferGeometry = PlaneBufferGeometry;
  28775. exports.LatheGeometry = LatheGeometry;
  28776. exports.LatheBufferGeometry = LatheBufferGeometry;
  28777. exports.ShapeGeometry = ShapeGeometry;
  28778. exports.ShapeBufferGeometry = ShapeBufferGeometry;
  28779. exports.ExtrudeGeometry = ExtrudeGeometry;
  28780. exports.ExtrudeBufferGeometry = ExtrudeBufferGeometry;
  28781. exports.EdgesGeometry = EdgesGeometry;
  28782. exports.ConeGeometry = ConeGeometry;
  28783. exports.ConeBufferGeometry = ConeBufferGeometry;
  28784. exports.CylinderGeometry = CylinderGeometry;
  28785. exports.CylinderBufferGeometry = CylinderBufferGeometry;
  28786. exports.CircleGeometry = CircleGeometry;
  28787. exports.CircleBufferGeometry = CircleBufferGeometry;
  28788. exports.BoxGeometry = BoxGeometry;
  28789. exports.CubeGeometry = BoxGeometry;
  28790. exports.BoxBufferGeometry = BoxBufferGeometry;
  28791. exports.ShadowMaterial = ShadowMaterial;
  28792. exports.SpriteMaterial = SpriteMaterial;
  28793. exports.RawShaderMaterial = RawShaderMaterial;
  28794. exports.ShaderMaterial = ShaderMaterial;
  28795. exports.PointsMaterial = PointsMaterial;
  28796. exports.MeshPhysicalMaterial = MeshPhysicalMaterial;
  28797. exports.MeshStandardMaterial = MeshStandardMaterial;
  28798. exports.MeshPhongMaterial = MeshPhongMaterial;
  28799. exports.MeshToonMaterial = MeshToonMaterial;
  28800. exports.MeshNormalMaterial = MeshNormalMaterial;
  28801. exports.MeshLambertMaterial = MeshLambertMaterial;
  28802. exports.MeshDepthMaterial = MeshDepthMaterial;
  28803. exports.MeshDistanceMaterial = MeshDistanceMaterial;
  28804. exports.MeshBasicMaterial = MeshBasicMaterial;
  28805. exports.MeshMatcapMaterial = MeshMatcapMaterial;
  28806. exports.LineDashedMaterial = LineDashedMaterial;
  28807. exports.LineBasicMaterial = LineBasicMaterial;
  28808. exports.Material = Material;
  28809. exports.Float64BufferAttribute = Float64BufferAttribute;
  28810. exports.Float32BufferAttribute = Float32BufferAttribute;
  28811. exports.Uint32BufferAttribute = Uint32BufferAttribute;
  28812. exports.Int32BufferAttribute = Int32BufferAttribute;
  28813. exports.Uint16BufferAttribute = Uint16BufferAttribute;
  28814. exports.Int16BufferAttribute = Int16BufferAttribute;
  28815. exports.Uint8ClampedBufferAttribute = Uint8ClampedBufferAttribute;
  28816. exports.Uint8BufferAttribute = Uint8BufferAttribute;
  28817. exports.Int8BufferAttribute = Int8BufferAttribute;
  28818. exports.BufferAttribute = BufferAttribute;
  28819. exports.ArcCurve = ArcCurve;
  28820. exports.CatmullRomCurve3 = CatmullRomCurve3;
  28821. exports.CubicBezierCurve = CubicBezierCurve;
  28822. exports.CubicBezierCurve3 = CubicBezierCurve3;
  28823. exports.EllipseCurve = EllipseCurve;
  28824. exports.LineCurve = LineCurve;
  28825. exports.LineCurve3 = LineCurve3;
  28826. exports.QuadraticBezierCurve = QuadraticBezierCurve;
  28827. exports.QuadraticBezierCurve3 = QuadraticBezierCurve3;
  28828. exports.SplineCurve = SplineCurve;
  28829. exports.REVISION = REVISION;
  28830. exports.MOUSE = MOUSE;
  28831. exports.CullFaceNone = CullFaceNone;
  28832. exports.CullFaceBack = CullFaceBack;
  28833. exports.CullFaceFront = CullFaceFront;
  28834. exports.CullFaceFrontBack = CullFaceFrontBack;
  28835. exports.FrontFaceDirectionCW = FrontFaceDirectionCW;
  28836. exports.FrontFaceDirectionCCW = FrontFaceDirectionCCW;
  28837. exports.BasicShadowMap = BasicShadowMap;
  28838. exports.PCFShadowMap = PCFShadowMap;
  28839. exports.PCFSoftShadowMap = PCFSoftShadowMap;
  28840. exports.FrontSide = FrontSide;
  28841. exports.BackSide = BackSide;
  28842. exports.DoubleSide = DoubleSide;
  28843. exports.FlatShading = FlatShading;
  28844. exports.SmoothShading = SmoothShading;
  28845. exports.NoColors = NoColors;
  28846. exports.FaceColors = FaceColors;
  28847. exports.VertexColors = VertexColors;
  28848. exports.NoBlending = NoBlending;
  28849. exports.NormalBlending = NormalBlending;
  28850. exports.AdditiveBlending = AdditiveBlending;
  28851. exports.SubtractiveBlending = SubtractiveBlending;
  28852. exports.MultiplyBlending = MultiplyBlending;
  28853. exports.CustomBlending = CustomBlending;
  28854. exports.AddEquation = AddEquation;
  28855. exports.SubtractEquation = SubtractEquation;
  28856. exports.ReverseSubtractEquation = ReverseSubtractEquation;
  28857. exports.MinEquation = MinEquation;
  28858. exports.MaxEquation = MaxEquation;
  28859. exports.ZeroFactor = ZeroFactor;
  28860. exports.OneFactor = OneFactor;
  28861. exports.SrcColorFactor = SrcColorFactor;
  28862. exports.OneMinusSrcColorFactor = OneMinusSrcColorFactor;
  28863. exports.SrcAlphaFactor = SrcAlphaFactor;
  28864. exports.OneMinusSrcAlphaFactor = OneMinusSrcAlphaFactor;
  28865. exports.DstAlphaFactor = DstAlphaFactor;
  28866. exports.OneMinusDstAlphaFactor = OneMinusDstAlphaFactor;
  28867. exports.DstColorFactor = DstColorFactor;
  28868. exports.OneMinusDstColorFactor = OneMinusDstColorFactor;
  28869. exports.SrcAlphaSaturateFactor = SrcAlphaSaturateFactor;
  28870. exports.NeverDepth = NeverDepth;
  28871. exports.AlwaysDepth = AlwaysDepth;
  28872. exports.LessDepth = LessDepth;
  28873. exports.LessEqualDepth = LessEqualDepth;
  28874. exports.EqualDepth = EqualDepth;
  28875. exports.GreaterEqualDepth = GreaterEqualDepth;
  28876. exports.GreaterDepth = GreaterDepth;
  28877. exports.NotEqualDepth = NotEqualDepth;
  28878. exports.MultiplyOperation = MultiplyOperation;
  28879. exports.MixOperation = MixOperation;
  28880. exports.AddOperation = AddOperation;
  28881. exports.NoToneMapping = NoToneMapping;
  28882. exports.LinearToneMapping = LinearToneMapping;
  28883. exports.ReinhardToneMapping = ReinhardToneMapping;
  28884. exports.Uncharted2ToneMapping = Uncharted2ToneMapping;
  28885. exports.CineonToneMapping = CineonToneMapping;
  28886. exports.ACESFilmicToneMapping = ACESFilmicToneMapping;
  28887. exports.UVMapping = UVMapping;
  28888. exports.CubeReflectionMapping = CubeReflectionMapping;
  28889. exports.CubeRefractionMapping = CubeRefractionMapping;
  28890. exports.EquirectangularReflectionMapping = EquirectangularReflectionMapping;
  28891. exports.EquirectangularRefractionMapping = EquirectangularRefractionMapping;
  28892. exports.SphericalReflectionMapping = SphericalReflectionMapping;
  28893. exports.CubeUVReflectionMapping = CubeUVReflectionMapping;
  28894. exports.CubeUVRefractionMapping = CubeUVRefractionMapping;
  28895. exports.RepeatWrapping = RepeatWrapping;
  28896. exports.ClampToEdgeWrapping = ClampToEdgeWrapping;
  28897. exports.MirroredRepeatWrapping = MirroredRepeatWrapping;
  28898. exports.NearestFilter = NearestFilter;
  28899. exports.NearestMipMapNearestFilter = NearestMipMapNearestFilter;
  28900. exports.NearestMipMapLinearFilter = NearestMipMapLinearFilter;
  28901. exports.LinearFilter = LinearFilter;
  28902. exports.LinearMipMapNearestFilter = LinearMipMapNearestFilter;
  28903. exports.LinearMipMapLinearFilter = LinearMipMapLinearFilter;
  28904. exports.UnsignedByteType = UnsignedByteType;
  28905. exports.ByteType = ByteType;
  28906. exports.ShortType = ShortType;
  28907. exports.UnsignedShortType = UnsignedShortType;
  28908. exports.IntType = IntType;
  28909. exports.UnsignedIntType = UnsignedIntType;
  28910. exports.FloatType = FloatType;
  28911. exports.HalfFloatType = HalfFloatType;
  28912. exports.UnsignedShort4444Type = UnsignedShort4444Type;
  28913. exports.UnsignedShort5551Type = UnsignedShort5551Type;
  28914. exports.UnsignedShort565Type = UnsignedShort565Type;
  28915. exports.UnsignedInt248Type = UnsignedInt248Type;
  28916. exports.AlphaFormat = AlphaFormat;
  28917. exports.RGBFormat = RGBFormat;
  28918. exports.RGBAFormat = RGBAFormat;
  28919. exports.LuminanceFormat = LuminanceFormat;
  28920. exports.LuminanceAlphaFormat = LuminanceAlphaFormat;
  28921. exports.RGBEFormat = RGBEFormat;
  28922. exports.DepthFormat = DepthFormat;
  28923. exports.DepthStencilFormat = DepthStencilFormat;
  28924. exports.RedFormat = RedFormat;
  28925. exports.RGB_S3TC_DXT1_Format = RGB_S3TC_DXT1_Format;
  28926. exports.RGBA_S3TC_DXT1_Format = RGBA_S3TC_DXT1_Format;
  28927. exports.RGBA_S3TC_DXT3_Format = RGBA_S3TC_DXT3_Format;
  28928. exports.RGBA_S3TC_DXT5_Format = RGBA_S3TC_DXT5_Format;
  28929. exports.RGB_PVRTC_4BPPV1_Format = RGB_PVRTC_4BPPV1_Format;
  28930. exports.RGB_PVRTC_2BPPV1_Format = RGB_PVRTC_2BPPV1_Format;
  28931. exports.RGBA_PVRTC_4BPPV1_Format = RGBA_PVRTC_4BPPV1_Format;
  28932. exports.RGBA_PVRTC_2BPPV1_Format = RGBA_PVRTC_2BPPV1_Format;
  28933. exports.RGB_ETC1_Format = RGB_ETC1_Format;
  28934. exports.RGBA_ASTC_4x4_Format = RGBA_ASTC_4x4_Format;
  28935. exports.RGBA_ASTC_5x4_Format = RGBA_ASTC_5x4_Format;
  28936. exports.RGBA_ASTC_5x5_Format = RGBA_ASTC_5x5_Format;
  28937. exports.RGBA_ASTC_6x5_Format = RGBA_ASTC_6x5_Format;
  28938. exports.RGBA_ASTC_6x6_Format = RGBA_ASTC_6x6_Format;
  28939. exports.RGBA_ASTC_8x5_Format = RGBA_ASTC_8x5_Format;
  28940. exports.RGBA_ASTC_8x6_Format = RGBA_ASTC_8x6_Format;
  28941. exports.RGBA_ASTC_8x8_Format = RGBA_ASTC_8x8_Format;
  28942. exports.RGBA_ASTC_10x5_Format = RGBA_ASTC_10x5_Format;
  28943. exports.RGBA_ASTC_10x6_Format = RGBA_ASTC_10x6_Format;
  28944. exports.RGBA_ASTC_10x8_Format = RGBA_ASTC_10x8_Format;
  28945. exports.RGBA_ASTC_10x10_Format = RGBA_ASTC_10x10_Format;
  28946. exports.RGBA_ASTC_12x10_Format = RGBA_ASTC_12x10_Format;
  28947. exports.RGBA_ASTC_12x12_Format = RGBA_ASTC_12x12_Format;
  28948. exports.LoopOnce = LoopOnce;
  28949. exports.LoopRepeat = LoopRepeat;
  28950. exports.LoopPingPong = LoopPingPong;
  28951. exports.InterpolateDiscrete = InterpolateDiscrete;
  28952. exports.InterpolateLinear = InterpolateLinear;
  28953. exports.InterpolateSmooth = InterpolateSmooth;
  28954. exports.ZeroCurvatureEnding = ZeroCurvatureEnding;
  28955. exports.ZeroSlopeEnding = ZeroSlopeEnding;
  28956. exports.WrapAroundEnding = WrapAroundEnding;
  28957. exports.TrianglesDrawMode = TrianglesDrawMode;
  28958. exports.TriangleStripDrawMode = TriangleStripDrawMode;
  28959. exports.TriangleFanDrawMode = TriangleFanDrawMode;
  28960. exports.LinearEncoding = LinearEncoding;
  28961. exports.sRGBEncoding = sRGBEncoding;
  28962. exports.GammaEncoding = GammaEncoding;
  28963. exports.RGBEEncoding = RGBEEncoding;
  28964. exports.LogLuvEncoding = LogLuvEncoding;
  28965. exports.RGBM7Encoding = RGBM7Encoding;
  28966. exports.RGBM16Encoding = RGBM16Encoding;
  28967. exports.RGBDEncoding = RGBDEncoding;
  28968. exports.BasicDepthPacking = BasicDepthPacking;
  28969. exports.RGBADepthPacking = RGBADepthPacking;
  28970. exports.TangentSpaceNormalMap = TangentSpaceNormalMap;
  28971. exports.ObjectSpaceNormalMap = ObjectSpaceNormalMap;
  28972. exports.Face4 = Face4;
  28973. exports.LineStrip = LineStrip;
  28974. exports.LinePieces = LinePieces;
  28975. exports.MeshFaceMaterial = MeshFaceMaterial;
  28976. exports.MultiMaterial = MultiMaterial;
  28977. exports.PointCloud = PointCloud;
  28978. exports.Particle = Particle;
  28979. exports.ParticleSystem = ParticleSystem;
  28980. exports.PointCloudMaterial = PointCloudMaterial;
  28981. exports.ParticleBasicMaterial = ParticleBasicMaterial;
  28982. exports.ParticleSystemMaterial = ParticleSystemMaterial;
  28983. exports.Vertex = Vertex;
  28984. exports.DynamicBufferAttribute = DynamicBufferAttribute;
  28985. exports.Int8Attribute = Int8Attribute;
  28986. exports.Uint8Attribute = Uint8Attribute;
  28987. exports.Uint8ClampedAttribute = Uint8ClampedAttribute;
  28988. exports.Int16Attribute = Int16Attribute;
  28989. exports.Uint16Attribute = Uint16Attribute;
  28990. exports.Int32Attribute = Int32Attribute;
  28991. exports.Uint32Attribute = Uint32Attribute;
  28992. exports.Float32Attribute = Float32Attribute;
  28993. exports.Float64Attribute = Float64Attribute;
  28994. exports.ClosedSplineCurve3 = ClosedSplineCurve3;
  28995. exports.SplineCurve3 = SplineCurve3;
  28996. exports.Spline = Spline;
  28997. exports.AxisHelper = AxisHelper;
  28998. exports.BoundingBoxHelper = BoundingBoxHelper;
  28999. exports.EdgesHelper = EdgesHelper;
  29000. exports.WireframeHelper = WireframeHelper;
  29001. exports.XHRLoader = XHRLoader;
  29002. exports.BinaryTextureLoader = BinaryTextureLoader;
  29003. exports.GeometryUtils = GeometryUtils;
  29004. exports.Projector = Projector;
  29005. exports.CanvasRenderer = CanvasRenderer;
  29006. exports.JSONLoader = JSONLoader;
  29007. exports.SceneUtils = SceneUtils;
  29008. exports.LensFlare = LensFlare;
  29009. Object.defineProperty(exports, '__esModule', { value: true });
  29010. }));