three.js 1.1 MB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520225212252222523225242252522526225272252822529225302253122532225332253422535225362253722538225392254022541225422254322544225452254622547225482254922550225512255222553225542255522556225572255822559225602256122562225632256422565225662256722568225692257022571225722257322574225752257622577225782257922580225812258222583225842258522586225872258822589225902259122592225932259422595225962259722598225992260022601226022260322604226052260622607226082260922610226112261222613226142261522616226172261822619226202262122622226232262422625226262262722628226292263022631226322263322634226352263622637226382263922640226412264222643226442264522646226472264822649226502265122652226532265422655226562265722658226592266022661226622266322664226652266622667226682266922670226712267222673226742267522676226772267822679226802268122682226832268422685226862268722688226892269022691226922269322694226952269622697226982269922700227012270222703227042270522706227072270822709227102271122712227132271422715227162271722718227192272022721227222272322724227252272622727227282272922730227312273222733227342273522736227372273822739227402274122742227432274422745227462274722748227492275022751227522275322754227552275622757227582275922760227612276222763227642276522766227672276822769227702277122772227732277422775227762277722778227792278022781227822278322784227852278622787227882278922790227912279222793227942279522796227972279822799228002280122802228032280422805228062280722808228092281022811228122281322814228152281622817228182281922820228212282222823228242282522826228272282822829228302283122832228332283422835228362283722838228392284022841228422284322844228452284622847228482284922850228512285222853228542285522856228572285822859228602286122862228632286422865228662286722868228692287022871228722287322874228752287622877228782287922880228812288222883228842288522886228872288822889228902289122892228932289422895228962289722898228992290022901229022290322904229052290622907229082290922910229112291222913229142291522916229172291822919229202292122922229232292422925229262292722928229292293022931229322293322934229352293622937229382293922940229412294222943229442294522946229472294822949229502295122952229532295422955229562295722958229592296022961229622296322964229652296622967229682296922970229712297222973229742297522976229772297822979229802298122982229832298422985229862298722988229892299022991229922299322994229952299622997229982299923000230012300223003230042300523006230072300823009230102301123012230132301423015230162301723018230192302023021230222302323024230252302623027230282302923030230312303223033230342303523036230372303823039230402304123042230432304423045230462304723048230492305023051230522305323054230552305623057230582305923060230612306223063230642306523066230672306823069230702307123072230732307423075230762307723078230792308023081230822308323084230852308623087230882308923090230912309223093230942309523096230972309823099231002310123102231032310423105231062310723108231092311023111231122311323114231152311623117231182311923120231212312223123231242312523126231272312823129231302313123132231332313423135231362313723138231392314023141231422314323144231452314623147231482314923150231512315223153231542315523156231572315823159231602316123162231632316423165231662316723168231692317023171231722317323174231752317623177231782317923180231812318223183231842318523186231872318823189231902319123192231932319423195231962319723198231992320023201232022320323204232052320623207232082320923210232112321223213232142321523216232172321823219232202322123222232232322423225232262322723228232292323023231232322323323234232352323623237232382323923240232412324223243232442324523246232472324823249232502325123252232532325423255232562325723258232592326023261232622326323264232652326623267232682326923270232712327223273232742327523276232772327823279232802328123282232832328423285232862328723288232892329023291232922329323294232952329623297232982329923300233012330223303233042330523306233072330823309233102331123312233132331423315233162331723318233192332023321233222332323324233252332623327233282332923330233312333223333233342333523336233372333823339233402334123342233432334423345233462334723348233492335023351233522335323354233552335623357233582335923360233612336223363233642336523366233672336823369233702337123372233732337423375233762337723378233792338023381233822338323384233852338623387233882338923390233912339223393233942339523396233972339823399234002340123402234032340423405234062340723408234092341023411234122341323414234152341623417234182341923420234212342223423234242342523426234272342823429234302343123432234332343423435234362343723438234392344023441234422344323444234452344623447234482344923450234512345223453234542345523456234572345823459234602346123462234632346423465234662346723468234692347023471234722347323474234752347623477234782347923480234812348223483234842348523486234872348823489234902349123492234932349423495234962349723498234992350023501235022350323504235052350623507235082350923510235112351223513235142351523516235172351823519235202352123522235232352423525235262352723528235292353023531235322353323534235352353623537235382353923540235412354223543235442354523546235472354823549235502355123552235532355423555235562355723558235592356023561235622356323564235652356623567235682356923570235712357223573235742357523576235772357823579235802358123582235832358423585235862358723588235892359023591235922359323594235952359623597235982359923600236012360223603236042360523606236072360823609236102361123612236132361423615236162361723618236192362023621236222362323624236252362623627236282362923630236312363223633236342363523636236372363823639236402364123642236432364423645236462364723648236492365023651236522365323654236552365623657236582365923660236612366223663236642366523666236672366823669236702367123672236732367423675236762367723678236792368023681236822368323684236852368623687236882368923690236912369223693236942369523696236972369823699237002370123702237032370423705237062370723708237092371023711237122371323714237152371623717237182371923720237212372223723237242372523726237272372823729237302373123732237332373423735237362373723738237392374023741237422374323744237452374623747237482374923750237512375223753237542375523756237572375823759237602376123762237632376423765237662376723768237692377023771237722377323774237752377623777237782377923780237812378223783237842378523786237872378823789237902379123792237932379423795237962379723798237992380023801238022380323804238052380623807238082380923810238112381223813238142381523816238172381823819238202382123822238232382423825238262382723828238292383023831238322383323834238352383623837238382383923840238412384223843238442384523846238472384823849238502385123852238532385423855238562385723858238592386023861238622386323864238652386623867238682386923870238712387223873238742387523876238772387823879238802388123882238832388423885238862388723888238892389023891238922389323894238952389623897238982389923900239012390223903239042390523906239072390823909239102391123912239132391423915239162391723918239192392023921239222392323924239252392623927239282392923930239312393223933239342393523936239372393823939239402394123942239432394423945239462394723948239492395023951239522395323954239552395623957239582395923960239612396223963239642396523966239672396823969239702397123972239732397423975239762397723978239792398023981239822398323984239852398623987239882398923990239912399223993239942399523996239972399823999240002400124002240032400424005240062400724008240092401024011240122401324014240152401624017240182401924020240212402224023240242402524026240272402824029240302403124032240332403424035240362403724038240392404024041240422404324044240452404624047240482404924050240512405224053240542405524056240572405824059240602406124062240632406424065240662406724068240692407024071240722407324074240752407624077240782407924080240812408224083240842408524086240872408824089240902409124092240932409424095240962409724098240992410024101241022410324104241052410624107241082410924110241112411224113241142411524116241172411824119241202412124122241232412424125241262412724128241292413024131241322413324134241352413624137241382413924140241412414224143241442414524146241472414824149241502415124152241532415424155241562415724158241592416024161241622416324164241652416624167241682416924170241712417224173241742417524176241772417824179241802418124182241832418424185241862418724188241892419024191241922419324194241952419624197241982419924200242012420224203242042420524206242072420824209242102421124212242132421424215242162421724218242192422024221242222422324224242252422624227242282422924230242312423224233242342423524236242372423824239242402424124242242432424424245242462424724248242492425024251242522425324254242552425624257242582425924260242612426224263242642426524266242672426824269242702427124272242732427424275242762427724278242792428024281242822428324284242852428624287242882428924290242912429224293242942429524296242972429824299243002430124302243032430424305243062430724308243092431024311243122431324314243152431624317243182431924320243212432224323243242432524326243272432824329243302433124332243332433424335243362433724338243392434024341243422434324344243452434624347243482434924350243512435224353243542435524356243572435824359243602436124362243632436424365243662436724368243692437024371243722437324374243752437624377243782437924380243812438224383243842438524386243872438824389243902439124392243932439424395243962439724398243992440024401244022440324404244052440624407244082440924410244112441224413244142441524416244172441824419244202442124422244232442424425244262442724428244292443024431244322443324434244352443624437244382443924440244412444224443244442444524446244472444824449244502445124452244532445424455244562445724458244592446024461244622446324464244652446624467244682446924470244712447224473244742447524476244772447824479244802448124482244832448424485244862448724488244892449024491244922449324494244952449624497244982449924500245012450224503245042450524506245072450824509245102451124512245132451424515245162451724518245192452024521245222452324524245252452624527245282452924530245312453224533245342453524536245372453824539245402454124542245432454424545245462454724548245492455024551245522455324554245552455624557245582455924560245612456224563245642456524566245672456824569245702457124572245732457424575245762457724578245792458024581245822458324584245852458624587245882458924590245912459224593245942459524596245972459824599246002460124602246032460424605246062460724608246092461024611246122461324614246152461624617246182461924620246212462224623246242462524626246272462824629246302463124632246332463424635246362463724638246392464024641246422464324644246452464624647246482464924650246512465224653246542465524656246572465824659246602466124662246632466424665246662466724668246692467024671246722467324674246752467624677246782467924680246812468224683246842468524686246872468824689246902469124692246932469424695246962469724698246992470024701247022470324704247052470624707247082470924710247112471224713247142471524716247172471824719247202472124722247232472424725247262472724728247292473024731247322473324734247352473624737247382473924740247412474224743247442474524746247472474824749247502475124752247532475424755247562475724758247592476024761247622476324764247652476624767247682476924770247712477224773247742477524776247772477824779247802478124782247832478424785247862478724788247892479024791247922479324794247952479624797247982479924800248012480224803248042480524806248072480824809248102481124812248132481424815248162481724818248192482024821248222482324824248252482624827248282482924830248312483224833248342483524836248372483824839248402484124842248432484424845248462484724848248492485024851248522485324854248552485624857248582485924860248612486224863248642486524866248672486824869248702487124872248732487424875248762487724878248792488024881248822488324884248852488624887248882488924890248912489224893248942489524896248972489824899249002490124902249032490424905249062490724908249092491024911249122491324914249152491624917249182491924920249212492224923249242492524926249272492824929249302493124932249332493424935249362493724938249392494024941249422494324944249452494624947249482494924950249512495224953249542495524956249572495824959249602496124962249632496424965249662496724968249692497024971249722497324974249752497624977249782497924980249812498224983249842498524986249872498824989249902499124992249932499424995249962499724998249992500025001250022500325004250052500625007250082500925010250112501225013250142501525016250172501825019250202502125022250232502425025250262502725028250292503025031250322503325034250352503625037250382503925040250412504225043250442504525046250472504825049250502505125052250532505425055250562505725058250592506025061250622506325064250652506625067250682506925070250712507225073250742507525076250772507825079250802508125082250832508425085250862508725088250892509025091250922509325094250952509625097250982509925100251012510225103251042510525106251072510825109251102511125112251132511425115251162511725118251192512025121251222512325124251252512625127251282512925130251312513225133251342513525136251372513825139251402514125142251432514425145251462514725148251492515025151251522515325154251552515625157251582515925160251612516225163251642516525166251672516825169251702517125172251732517425175251762517725178251792518025181251822518325184251852518625187251882518925190251912519225193251942519525196251972519825199252002520125202252032520425205252062520725208252092521025211252122521325214252152521625217252182521925220252212522225223252242522525226252272522825229252302523125232252332523425235252362523725238252392524025241252422524325244252452524625247252482524925250252512525225253252542525525256252572525825259252602526125262252632526425265252662526725268252692527025271252722527325274252752527625277252782527925280252812528225283252842528525286252872528825289252902529125292252932529425295252962529725298252992530025301253022530325304253052530625307253082530925310253112531225313253142531525316253172531825319253202532125322253232532425325253262532725328253292533025331253322533325334253352533625337253382533925340253412534225343253442534525346253472534825349253502535125352253532535425355253562535725358253592536025361253622536325364253652536625367253682536925370253712537225373253742537525376253772537825379253802538125382253832538425385253862538725388253892539025391253922539325394253952539625397253982539925400254012540225403254042540525406254072540825409254102541125412254132541425415254162541725418254192542025421254222542325424254252542625427254282542925430254312543225433254342543525436254372543825439254402544125442254432544425445254462544725448254492545025451254522545325454254552545625457254582545925460254612546225463254642546525466254672546825469254702547125472254732547425475254762547725478254792548025481254822548325484254852548625487254882548925490254912549225493254942549525496254972549825499255002550125502255032550425505255062550725508255092551025511255122551325514255152551625517255182551925520255212552225523255242552525526255272552825529255302553125532255332553425535255362553725538255392554025541255422554325544255452554625547255482554925550255512555225553255542555525556255572555825559255602556125562255632556425565255662556725568255692557025571255722557325574255752557625577255782557925580255812558225583255842558525586255872558825589255902559125592255932559425595255962559725598255992560025601256022560325604256052560625607256082560925610256112561225613256142561525616256172561825619256202562125622256232562425625256262562725628256292563025631256322563325634256352563625637256382563925640256412564225643256442564525646256472564825649256502565125652256532565425655256562565725658256592566025661256622566325664256652566625667256682566925670256712567225673256742567525676256772567825679256802568125682256832568425685256862568725688256892569025691256922569325694256952569625697256982569925700257012570225703257042570525706257072570825709257102571125712257132571425715257162571725718257192572025721257222572325724257252572625727257282572925730257312573225733257342573525736257372573825739257402574125742257432574425745257462574725748257492575025751257522575325754257552575625757257582575925760257612576225763257642576525766257672576825769257702577125772257732577425775257762577725778257792578025781257822578325784257852578625787257882578925790257912579225793257942579525796257972579825799258002580125802258032580425805258062580725808258092581025811258122581325814258152581625817258182581925820258212582225823258242582525826258272582825829258302583125832258332583425835258362583725838258392584025841258422584325844258452584625847258482584925850258512585225853258542585525856258572585825859258602586125862258632586425865258662586725868258692587025871258722587325874258752587625877258782587925880258812588225883258842588525886258872588825889258902589125892258932589425895258962589725898258992590025901259022590325904259052590625907259082590925910259112591225913259142591525916259172591825919259202592125922259232592425925259262592725928259292593025931259322593325934259352593625937259382593925940259412594225943259442594525946259472594825949259502595125952259532595425955259562595725958259592596025961259622596325964259652596625967259682596925970259712597225973259742597525976259772597825979259802598125982259832598425985259862598725988259892599025991259922599325994259952599625997259982599926000260012600226003260042600526006260072600826009260102601126012260132601426015260162601726018260192602026021260222602326024260252602626027260282602926030260312603226033260342603526036260372603826039260402604126042260432604426045260462604726048260492605026051260522605326054260552605626057260582605926060260612606226063260642606526066260672606826069260702607126072260732607426075260762607726078260792608026081260822608326084260852608626087260882608926090260912609226093260942609526096260972609826099261002610126102261032610426105261062610726108261092611026111261122611326114261152611626117261182611926120261212612226123261242612526126261272612826129261302613126132261332613426135261362613726138261392614026141261422614326144261452614626147261482614926150261512615226153261542615526156261572615826159261602616126162261632616426165261662616726168261692617026171261722617326174261752617626177261782617926180261812618226183261842618526186261872618826189261902619126192261932619426195261962619726198261992620026201262022620326204262052620626207262082620926210262112621226213262142621526216262172621826219262202622126222262232622426225262262622726228262292623026231262322623326234262352623626237262382623926240262412624226243262442624526246262472624826249262502625126252262532625426255262562625726258262592626026261262622626326264262652626626267262682626926270262712627226273262742627526276262772627826279262802628126282262832628426285262862628726288262892629026291262922629326294262952629626297262982629926300263012630226303263042630526306263072630826309263102631126312263132631426315263162631726318263192632026321263222632326324263252632626327263282632926330263312633226333263342633526336263372633826339263402634126342263432634426345263462634726348263492635026351263522635326354263552635626357263582635926360263612636226363263642636526366263672636826369263702637126372263732637426375263762637726378263792638026381263822638326384263852638626387263882638926390263912639226393263942639526396263972639826399264002640126402264032640426405264062640726408264092641026411264122641326414264152641626417264182641926420264212642226423264242642526426264272642826429264302643126432264332643426435264362643726438264392644026441264422644326444264452644626447264482644926450264512645226453264542645526456264572645826459264602646126462264632646426465264662646726468264692647026471264722647326474264752647626477264782647926480264812648226483264842648526486264872648826489264902649126492264932649426495264962649726498264992650026501265022650326504265052650626507265082650926510265112651226513265142651526516265172651826519265202652126522265232652426525265262652726528265292653026531265322653326534265352653626537265382653926540265412654226543265442654526546265472654826549265502655126552265532655426555265562655726558265592656026561265622656326564265652656626567265682656926570265712657226573265742657526576265772657826579265802658126582265832658426585265862658726588265892659026591265922659326594265952659626597265982659926600266012660226603266042660526606266072660826609266102661126612266132661426615266162661726618266192662026621266222662326624266252662626627266282662926630266312663226633266342663526636266372663826639266402664126642266432664426645266462664726648266492665026651266522665326654266552665626657266582665926660266612666226663266642666526666266672666826669266702667126672266732667426675266762667726678266792668026681266822668326684266852668626687266882668926690266912669226693266942669526696266972669826699267002670126702267032670426705267062670726708267092671026711267122671326714267152671626717267182671926720267212672226723267242672526726267272672826729267302673126732267332673426735267362673726738267392674026741267422674326744267452674626747267482674926750267512675226753267542675526756267572675826759267602676126762267632676426765267662676726768267692677026771267722677326774267752677626777267782677926780267812678226783267842678526786267872678826789267902679126792267932679426795267962679726798267992680026801268022680326804268052680626807268082680926810268112681226813268142681526816268172681826819268202682126822268232682426825268262682726828268292683026831268322683326834268352683626837268382683926840268412684226843268442684526846268472684826849268502685126852268532685426855268562685726858268592686026861268622686326864268652686626867268682686926870268712687226873268742687526876268772687826879268802688126882268832688426885268862688726888268892689026891268922689326894268952689626897268982689926900269012690226903269042690526906269072690826909269102691126912269132691426915269162691726918269192692026921269222692326924269252692626927269282692926930269312693226933269342693526936269372693826939269402694126942269432694426945269462694726948269492695026951269522695326954269552695626957269582695926960269612696226963269642696526966269672696826969269702697126972269732697426975269762697726978269792698026981269822698326984269852698626987269882698926990269912699226993269942699526996269972699826999270002700127002270032700427005270062700727008270092701027011270122701327014270152701627017270182701927020270212702227023270242702527026270272702827029270302703127032270332703427035270362703727038270392704027041270422704327044270452704627047270482704927050270512705227053270542705527056270572705827059270602706127062270632706427065270662706727068270692707027071270722707327074270752707627077270782707927080270812708227083270842708527086270872708827089270902709127092270932709427095270962709727098270992710027101271022710327104271052710627107271082710927110271112711227113271142711527116271172711827119271202712127122271232712427125271262712727128271292713027131271322713327134271352713627137271382713927140271412714227143271442714527146271472714827149271502715127152271532715427155271562715727158271592716027161271622716327164271652716627167271682716927170271712717227173271742717527176271772717827179271802718127182271832718427185271862718727188271892719027191271922719327194271952719627197271982719927200272012720227203272042720527206272072720827209272102721127212272132721427215272162721727218272192722027221272222722327224272252722627227272282722927230272312723227233272342723527236272372723827239272402724127242272432724427245272462724727248272492725027251272522725327254272552725627257272582725927260272612726227263272642726527266272672726827269272702727127272272732727427275272762727727278272792728027281272822728327284272852728627287272882728927290272912729227293272942729527296272972729827299273002730127302273032730427305273062730727308273092731027311273122731327314273152731627317273182731927320273212732227323273242732527326273272732827329273302733127332273332733427335273362733727338273392734027341273422734327344273452734627347273482734927350273512735227353273542735527356273572735827359273602736127362273632736427365273662736727368273692737027371273722737327374273752737627377273782737927380273812738227383273842738527386273872738827389273902739127392273932739427395273962739727398273992740027401274022740327404274052740627407274082740927410274112741227413274142741527416274172741827419274202742127422274232742427425274262742727428274292743027431274322743327434274352743627437274382743927440274412744227443274442744527446274472744827449274502745127452274532745427455274562745727458274592746027461274622746327464274652746627467274682746927470274712747227473274742747527476274772747827479274802748127482274832748427485274862748727488274892749027491274922749327494274952749627497274982749927500275012750227503275042750527506275072750827509275102751127512275132751427515275162751727518275192752027521275222752327524275252752627527275282752927530275312753227533275342753527536275372753827539275402754127542275432754427545275462754727548275492755027551275522755327554275552755627557275582755927560275612756227563275642756527566275672756827569275702757127572275732757427575275762757727578275792758027581275822758327584275852758627587275882758927590275912759227593275942759527596275972759827599276002760127602276032760427605276062760727608276092761027611276122761327614276152761627617276182761927620276212762227623276242762527626276272762827629276302763127632276332763427635276362763727638276392764027641276422764327644276452764627647276482764927650276512765227653276542765527656276572765827659276602766127662276632766427665276662766727668276692767027671276722767327674276752767627677276782767927680276812768227683276842768527686276872768827689276902769127692276932769427695276962769727698276992770027701277022770327704277052770627707277082770927710277112771227713277142771527716277172771827719277202772127722277232772427725277262772727728277292773027731277322773327734277352773627737277382773927740277412774227743277442774527746277472774827749277502775127752277532775427755277562775727758277592776027761277622776327764277652776627767277682776927770277712777227773277742777527776277772777827779277802778127782277832778427785277862778727788277892779027791277922779327794277952779627797277982779927800278012780227803278042780527806278072780827809278102781127812278132781427815278162781727818278192782027821278222782327824278252782627827278282782927830278312783227833278342783527836278372783827839278402784127842278432784427845278462784727848278492785027851278522785327854278552785627857278582785927860278612786227863278642786527866278672786827869278702787127872278732787427875278762787727878278792788027881278822788327884278852788627887278882788927890278912789227893278942789527896278972789827899279002790127902279032790427905279062790727908279092791027911279122791327914279152791627917279182791927920279212792227923279242792527926279272792827929279302793127932279332793427935279362793727938279392794027941279422794327944279452794627947279482794927950279512795227953279542795527956279572795827959279602796127962279632796427965279662796727968279692797027971279722797327974279752797627977279782797927980279812798227983279842798527986279872798827989279902799127992279932799427995279962799727998279992800028001280022800328004280052800628007280082800928010280112801228013280142801528016280172801828019280202802128022280232802428025280262802728028280292803028031280322803328034280352803628037280382803928040280412804228043280442804528046280472804828049280502805128052280532805428055280562805728058280592806028061280622806328064280652806628067280682806928070280712807228073280742807528076280772807828079280802808128082280832808428085280862808728088280892809028091280922809328094280952809628097280982809928100281012810228103281042810528106281072810828109281102811128112281132811428115281162811728118281192812028121281222812328124281252812628127281282812928130281312813228133281342813528136281372813828139281402814128142281432814428145281462814728148281492815028151281522815328154281552815628157281582815928160281612816228163281642816528166281672816828169281702817128172281732817428175281762817728178281792818028181281822818328184281852818628187281882818928190281912819228193281942819528196281972819828199282002820128202282032820428205282062820728208282092821028211282122821328214282152821628217282182821928220282212822228223282242822528226282272822828229282302823128232282332823428235282362823728238282392824028241282422824328244282452824628247282482824928250282512825228253282542825528256282572825828259282602826128262282632826428265282662826728268282692827028271282722827328274282752827628277282782827928280282812828228283282842828528286282872828828289282902829128292282932829428295282962829728298282992830028301283022830328304283052830628307283082830928310283112831228313283142831528316283172831828319283202832128322283232832428325283262832728328283292833028331283322833328334283352833628337283382833928340283412834228343283442834528346283472834828349283502835128352283532835428355283562835728358283592836028361283622836328364283652836628367283682836928370283712837228373283742837528376283772837828379283802838128382283832838428385283862838728388283892839028391283922839328394283952839628397283982839928400284012840228403284042840528406284072840828409284102841128412284132841428415284162841728418284192842028421284222842328424284252842628427284282842928430284312843228433284342843528436284372843828439284402844128442284432844428445284462844728448284492845028451284522845328454284552845628457284582845928460284612846228463284642846528466284672846828469284702847128472284732847428475284762847728478284792848028481284822848328484284852848628487284882848928490284912849228493284942849528496284972849828499285002850128502285032850428505285062850728508285092851028511285122851328514285152851628517285182851928520285212852228523285242852528526285272852828529285302853128532285332853428535285362853728538285392854028541285422854328544285452854628547285482854928550285512855228553285542855528556285572855828559285602856128562285632856428565285662856728568285692857028571285722857328574285752857628577285782857928580285812858228583285842858528586285872858828589285902859128592285932859428595285962859728598285992860028601286022860328604286052860628607286082860928610286112861228613286142861528616286172861828619286202862128622286232862428625286262862728628286292863028631286322863328634286352863628637286382863928640286412864228643286442864528646286472864828649286502865128652286532865428655286562865728658286592866028661286622866328664286652866628667286682866928670286712867228673286742867528676286772867828679286802868128682286832868428685286862868728688286892869028691286922869328694286952869628697286982869928700287012870228703287042870528706287072870828709287102871128712287132871428715287162871728718287192872028721287222872328724287252872628727287282872928730287312873228733287342873528736287372873828739287402874128742287432874428745287462874728748287492875028751287522875328754287552875628757287582875928760287612876228763287642876528766287672876828769287702877128772287732877428775287762877728778287792878028781287822878328784287852878628787287882878928790287912879228793287942879528796287972879828799288002880128802288032880428805288062880728808288092881028811288122881328814288152881628817288182881928820288212882228823288242882528826288272882828829288302883128832288332883428835288362883728838288392884028841288422884328844288452884628847288482884928850288512885228853288542885528856288572885828859288602886128862288632886428865288662886728868288692887028871288722887328874288752887628877288782887928880288812888228883288842888528886288872888828889288902889128892288932889428895288962889728898288992890028901289022890328904289052890628907289082890928910289112891228913289142891528916289172891828919289202892128922289232892428925289262892728928289292893028931289322893328934289352893628937289382893928940289412894228943289442894528946289472894828949289502895128952289532895428955289562895728958289592896028961289622896328964289652896628967289682896928970289712897228973289742897528976289772897828979289802898128982289832898428985289862898728988289892899028991289922899328994289952899628997289982899929000290012900229003290042900529006290072900829009290102901129012290132901429015290162901729018290192902029021290222902329024290252902629027290282902929030290312903229033290342903529036290372903829039290402904129042290432904429045290462904729048290492905029051290522905329054290552905629057290582905929060290612906229063290642906529066290672906829069290702907129072290732907429075290762907729078290792908029081290822908329084290852908629087290882908929090290912909229093290942909529096290972909829099291002910129102291032910429105291062910729108291092911029111291122911329114291152911629117291182911929120291212912229123291242912529126291272912829129291302913129132291332913429135291362913729138291392914029141291422914329144291452914629147291482914929150291512915229153291542915529156291572915829159291602916129162291632916429165291662916729168291692917029171291722917329174291752917629177291782917929180291812918229183291842918529186291872918829189291902919129192291932919429195291962919729198291992920029201292022920329204292052920629207292082920929210292112921229213292142921529216292172921829219292202922129222292232922429225292262922729228292292923029231292322923329234292352923629237292382923929240292412924229243292442924529246292472924829249292502925129252292532925429255292562925729258292592926029261292622926329264292652926629267292682926929270292712927229273292742927529276292772927829279292802928129282292832928429285292862928729288292892929029291292922929329294292952929629297292982929929300293012930229303293042930529306293072930829309293102931129312293132931429315293162931729318293192932029321293222932329324293252932629327293282932929330293312933229333293342933529336293372933829339293402934129342293432934429345293462934729348293492935029351293522935329354293552935629357293582935929360293612936229363293642936529366293672936829369293702937129372293732937429375293762937729378293792938029381293822938329384293852938629387293882938929390293912939229393293942939529396293972939829399294002940129402294032940429405294062940729408294092941029411294122941329414294152941629417294182941929420294212942229423294242942529426294272942829429294302943129432294332943429435294362943729438294392944029441294422944329444294452944629447294482944929450294512945229453294542945529456294572945829459294602946129462294632946429465294662946729468294692947029471294722947329474294752947629477294782947929480294812948229483294842948529486294872948829489294902949129492294932949429495294962949729498294992950029501295022950329504295052950629507295082950929510295112951229513295142951529516295172951829519295202952129522295232952429525295262952729528295292953029531295322953329534295352953629537295382953929540295412954229543295442954529546295472954829549295502955129552295532955429555295562955729558295592956029561295622956329564295652956629567295682956929570295712957229573295742957529576295772957829579295802958129582295832958429585295862958729588295892959029591295922959329594295952959629597295982959929600296012960229603296042960529606296072960829609296102961129612296132961429615296162961729618296192962029621296222962329624296252962629627296282962929630296312963229633296342963529636296372963829639296402964129642296432964429645296462964729648296492965029651296522965329654296552965629657296582965929660296612966229663296642966529666296672966829669296702967129672296732967429675296762967729678296792968029681296822968329684296852968629687296882968929690296912969229693296942969529696296972969829699297002970129702297032970429705297062970729708297092971029711297122971329714297152971629717297182971929720297212972229723297242972529726297272972829729297302973129732297332973429735297362973729738297392974029741297422974329744297452974629747297482974929750297512975229753297542975529756297572975829759297602976129762297632976429765297662976729768297692977029771297722977329774297752977629777297782977929780297812978229783297842978529786297872978829789297902979129792297932979429795297962979729798297992980029801298022980329804298052980629807298082980929810298112981229813298142981529816298172981829819298202982129822298232982429825298262982729828298292983029831298322983329834298352983629837298382983929840298412984229843298442984529846298472984829849298502985129852298532985429855298562985729858298592986029861298622986329864298652986629867298682986929870298712987229873298742987529876298772987829879298802988129882298832988429885298862988729888298892989029891298922989329894298952989629897298982989929900299012990229903299042990529906299072990829909299102991129912299132991429915299162991729918299192992029921299222992329924299252992629927299282992929930299312993229933299342993529936299372993829939299402994129942299432994429945299462994729948299492995029951299522995329954299552995629957299582995929960299612996229963299642996529966299672996829969299702997129972299732997429975299762997729978299792998029981299822998329984299852998629987299882998929990299912999229993299942999529996299972999829999300003000130002300033000430005300063000730008300093001030011300123001330014300153001630017300183001930020300213002230023300243002530026300273002830029300303003130032300333003430035300363003730038300393004030041300423004330044300453004630047300483004930050300513005230053300543005530056300573005830059300603006130062300633006430065300663006730068300693007030071300723007330074300753007630077300783007930080300813008230083300843008530086300873008830089300903009130092300933009430095300963009730098300993010030101301023010330104301053010630107301083010930110301113011230113301143011530116301173011830119301203012130122301233012430125301263012730128301293013030131301323013330134301353013630137301383013930140301413014230143301443014530146301473014830149301503015130152301533015430155301563015730158301593016030161301623016330164301653016630167301683016930170301713017230173301743017530176301773017830179301803018130182301833018430185301863018730188301893019030191301923019330194301953019630197301983019930200302013020230203302043020530206302073020830209302103021130212302133021430215302163021730218302193022030221302223022330224302253022630227302283022930230302313023230233302343023530236302373023830239302403024130242302433024430245302463024730248302493025030251302523025330254302553025630257302583025930260302613026230263302643026530266302673026830269302703027130272302733027430275302763027730278302793028030281302823028330284302853028630287302883028930290302913029230293302943029530296302973029830299303003030130302303033030430305303063030730308303093031030311303123031330314303153031630317303183031930320303213032230323303243032530326303273032830329303303033130332303333033430335303363033730338303393034030341303423034330344303453034630347303483034930350303513035230353303543035530356303573035830359303603036130362303633036430365303663036730368303693037030371303723037330374303753037630377303783037930380303813038230383303843038530386303873038830389303903039130392303933039430395303963039730398303993040030401304023040330404304053040630407304083040930410304113041230413304143041530416304173041830419304203042130422304233042430425304263042730428304293043030431304323043330434304353043630437304383043930440304413044230443304443044530446304473044830449304503045130452304533045430455304563045730458304593046030461304623046330464304653046630467304683046930470304713047230473304743047530476304773047830479304803048130482304833048430485304863048730488304893049030491304923049330494304953049630497304983049930500305013050230503305043050530506305073050830509305103051130512305133051430515305163051730518305193052030521305223052330524305253052630527305283052930530305313053230533305343053530536305373053830539305403054130542305433054430545305463054730548305493055030551305523055330554305553055630557305583055930560305613056230563305643056530566305673056830569305703057130572305733057430575305763057730578305793058030581305823058330584305853058630587305883058930590305913059230593305943059530596305973059830599306003060130602306033060430605306063060730608306093061030611306123061330614306153061630617306183061930620306213062230623306243062530626306273062830629306303063130632306333063430635306363063730638306393064030641306423064330644306453064630647306483064930650306513065230653306543065530656306573065830659306603066130662306633066430665306663066730668306693067030671306723067330674306753067630677306783067930680306813068230683306843068530686306873068830689306903069130692306933069430695306963069730698306993070030701307023070330704307053070630707307083070930710307113071230713307143071530716307173071830719307203072130722307233072430725307263072730728307293073030731307323073330734307353073630737307383073930740307413074230743307443074530746307473074830749307503075130752307533075430755307563075730758307593076030761307623076330764307653076630767307683076930770307713077230773307743077530776307773077830779307803078130782307833078430785307863078730788307893079030791307923079330794307953079630797307983079930800308013080230803308043080530806308073080830809308103081130812308133081430815308163081730818308193082030821308223082330824308253082630827308283082930830308313083230833308343083530836308373083830839308403084130842308433084430845308463084730848308493085030851308523085330854308553085630857308583085930860308613086230863308643086530866308673086830869308703087130872308733087430875308763087730878308793088030881308823088330884308853088630887308883088930890308913089230893308943089530896308973089830899309003090130902309033090430905309063090730908309093091030911309123091330914309153091630917309183091930920309213092230923309243092530926309273092830929309303093130932309333093430935309363093730938309393094030941309423094330944309453094630947309483094930950309513095230953309543095530956309573095830959309603096130962309633096430965309663096730968309693097030971309723097330974309753097630977309783097930980309813098230983309843098530986309873098830989309903099130992309933099430995309963099730998309993100031001310023100331004310053100631007310083100931010310113101231013310143101531016310173101831019310203102131022310233102431025310263102731028310293103031031310323103331034310353103631037310383103931040310413104231043310443104531046310473104831049310503105131052310533105431055310563105731058310593106031061310623106331064310653106631067310683106931070310713107231073310743107531076310773107831079310803108131082310833108431085310863108731088310893109031091310923109331094310953109631097310983109931100311013110231103311043110531106311073110831109311103111131112311133111431115311163111731118311193112031121311223112331124311253112631127311283112931130311313113231133311343113531136311373113831139311403114131142311433114431145311463114731148311493115031151311523115331154311553115631157311583115931160311613116231163311643116531166311673116831169311703117131172311733117431175311763117731178311793118031181311823118331184311853118631187311883118931190311913119231193311943119531196311973119831199312003120131202312033120431205312063120731208312093121031211312123121331214312153121631217312183121931220312213122231223312243122531226312273122831229312303123131232312333123431235312363123731238312393124031241312423124331244312453124631247312483124931250312513125231253312543125531256312573125831259312603126131262312633126431265312663126731268312693127031271312723127331274312753127631277312783127931280312813128231283312843128531286312873128831289312903129131292312933129431295312963129731298312993130031301313023130331304313053130631307313083130931310313113131231313313143131531316313173131831319313203132131322313233132431325313263132731328313293133031331313323133331334313353133631337313383133931340313413134231343313443134531346313473134831349313503135131352313533135431355313563135731358313593136031361313623136331364313653136631367313683136931370313713137231373313743137531376313773137831379313803138131382313833138431385313863138731388313893139031391313923139331394313953139631397313983139931400314013140231403314043140531406314073140831409314103141131412314133141431415314163141731418314193142031421314223142331424314253142631427314283142931430314313143231433314343143531436314373143831439314403144131442314433144431445314463144731448314493145031451314523145331454314553145631457314583145931460314613146231463314643146531466314673146831469314703147131472314733147431475314763147731478314793148031481314823148331484314853148631487314883148931490314913149231493314943149531496314973149831499315003150131502315033150431505315063150731508315093151031511315123151331514315153151631517315183151931520315213152231523315243152531526315273152831529315303153131532315333153431535315363153731538315393154031541315423154331544315453154631547315483154931550315513155231553315543155531556315573155831559315603156131562315633156431565315663156731568315693157031571315723157331574315753157631577315783157931580315813158231583315843158531586315873158831589315903159131592315933159431595315963159731598315993160031601316023160331604316053160631607316083160931610316113161231613316143161531616316173161831619316203162131622316233162431625316263162731628316293163031631316323163331634316353163631637316383163931640316413164231643316443164531646316473164831649316503165131652316533165431655316563165731658316593166031661316623166331664316653166631667316683166931670316713167231673316743167531676316773167831679316803168131682316833168431685316863168731688316893169031691316923169331694316953169631697316983169931700317013170231703317043170531706317073170831709317103171131712317133171431715317163171731718317193172031721317223172331724317253172631727317283172931730317313173231733317343173531736317373173831739317403174131742317433174431745317463174731748317493175031751317523175331754317553175631757317583175931760317613176231763317643176531766317673176831769317703177131772317733177431775317763177731778317793178031781317823178331784317853178631787317883178931790317913179231793317943179531796317973179831799318003180131802318033180431805318063180731808318093181031811318123181331814318153181631817318183181931820318213182231823318243182531826318273182831829318303183131832318333183431835318363183731838318393184031841318423184331844318453184631847318483184931850318513185231853318543185531856318573185831859318603186131862318633186431865318663186731868318693187031871318723187331874318753187631877318783187931880318813188231883318843188531886318873188831889318903189131892318933189431895318963189731898318993190031901319023190331904319053190631907319083190931910319113191231913319143191531916319173191831919319203192131922319233192431925319263192731928319293193031931319323193331934319353193631937319383193931940319413194231943319443194531946319473194831949319503195131952319533195431955319563195731958319593196031961319623196331964319653196631967319683196931970319713197231973319743197531976319773197831979319803198131982319833198431985319863198731988319893199031991319923199331994319953199631997319983199932000320013200232003320043200532006320073200832009320103201132012320133201432015320163201732018320193202032021320223202332024320253202632027320283202932030320313203232033320343203532036320373203832039320403204132042320433204432045320463204732048320493205032051320523205332054320553205632057320583205932060320613206232063320643206532066320673206832069320703207132072320733207432075320763207732078320793208032081320823208332084320853208632087320883208932090320913209232093320943209532096320973209832099321003210132102321033210432105321063210732108321093211032111321123211332114321153211632117321183211932120321213212232123321243212532126321273212832129321303213132132321333213432135321363213732138321393214032141321423214332144321453214632147321483214932150321513215232153321543215532156321573215832159321603216132162321633216432165321663216732168321693217032171321723217332174321753217632177321783217932180321813218232183321843218532186321873218832189321903219132192321933219432195321963219732198321993220032201322023220332204322053220632207322083220932210322113221232213322143221532216322173221832219322203222132222322233222432225322263222732228322293223032231322323223332234322353223632237322383223932240322413224232243322443224532246322473224832249322503225132252322533225432255322563225732258322593226032261322623226332264322653226632267322683226932270322713227232273322743227532276322773227832279322803228132282322833228432285322863228732288322893229032291322923229332294322953229632297322983229932300323013230232303323043230532306323073230832309323103231132312323133231432315323163231732318323193232032321323223232332324323253232632327323283232932330323313233232333323343233532336323373233832339323403234132342323433234432345323463234732348323493235032351323523235332354323553235632357323583235932360323613236232363323643236532366323673236832369323703237132372323733237432375323763237732378323793238032381323823238332384323853238632387323883238932390323913239232393323943239532396323973239832399324003240132402324033240432405324063240732408324093241032411324123241332414324153241632417324183241932420324213242232423324243242532426324273242832429324303243132432324333243432435324363243732438324393244032441324423244332444324453244632447324483244932450324513245232453324543245532456324573245832459324603246132462324633246432465324663246732468324693247032471324723247332474324753247632477324783247932480324813248232483324843248532486324873248832489324903249132492324933249432495324963249732498324993250032501325023250332504325053250632507325083250932510325113251232513325143251532516325173251832519325203252132522325233252432525325263252732528325293253032531325323253332534325353253632537325383253932540325413254232543325443254532546325473254832549325503255132552325533255432555325563255732558325593256032561325623256332564325653256632567325683256932570325713257232573325743257532576325773257832579325803258132582325833258432585325863258732588325893259032591325923259332594325953259632597325983259932600326013260232603326043260532606326073260832609326103261132612326133261432615326163261732618326193262032621326223262332624326253262632627326283262932630326313263232633326343263532636326373263832639326403264132642326433264432645326463264732648326493265032651326523265332654326553265632657326583265932660326613266232663326643266532666326673266832669326703267132672326733267432675326763267732678326793268032681326823268332684326853268632687326883268932690326913269232693326943269532696326973269832699327003270132702327033270432705327063270732708327093271032711327123271332714327153271632717327183271932720327213272232723327243272532726327273272832729327303273132732327333273432735327363273732738327393274032741327423274332744327453274632747327483274932750327513275232753327543275532756327573275832759327603276132762327633276432765327663276732768327693277032771327723277332774327753277632777327783277932780327813278232783327843278532786327873278832789327903279132792327933279432795327963279732798327993280032801328023280332804328053280632807328083280932810328113281232813328143281532816328173281832819328203282132822328233282432825328263282732828328293283032831328323283332834328353283632837328383283932840328413284232843328443284532846328473284832849328503285132852328533285432855328563285732858328593286032861328623286332864328653286632867328683286932870328713287232873328743287532876328773287832879328803288132882328833288432885328863288732888328893289032891328923289332894328953289632897328983289932900329013290232903329043290532906329073290832909329103291132912329133291432915329163291732918329193292032921329223292332924329253292632927329283292932930329313293232933329343293532936329373293832939329403294132942329433294432945329463294732948329493295032951329523295332954329553295632957329583295932960329613296232963329643296532966329673296832969329703297132972329733297432975329763297732978329793298032981329823298332984329853298632987329883298932990329913299232993329943299532996329973299832999330003300133002330033300433005330063300733008330093301033011330123301333014330153301633017330183301933020330213302233023330243302533026330273302833029330303303133032330333303433035330363303733038330393304033041330423304333044330453304633047330483304933050330513305233053330543305533056330573305833059330603306133062330633306433065330663306733068330693307033071330723307333074330753307633077330783307933080330813308233083330843308533086330873308833089330903309133092330933309433095330963309733098330993310033101331023310333104331053310633107331083310933110331113311233113331143311533116331173311833119331203312133122331233312433125331263312733128331293313033131331323313333134331353313633137331383313933140331413314233143331443314533146331473314833149331503315133152331533315433155331563315733158331593316033161331623316333164331653316633167331683316933170331713317233173331743317533176331773317833179331803318133182331833318433185331863318733188331893319033191331923319333194331953319633197331983319933200332013320233203332043320533206332073320833209332103321133212332133321433215332163321733218332193322033221332223322333224332253322633227332283322933230332313323233233332343323533236332373323833239332403324133242332433324433245332463324733248332493325033251332523325333254332553325633257332583325933260332613326233263332643326533266332673326833269332703327133272332733327433275332763327733278332793328033281332823328333284332853328633287332883328933290332913329233293332943329533296332973329833299333003330133302333033330433305333063330733308333093331033311333123331333314333153331633317333183331933320333213332233323333243332533326333273332833329333303333133332333333333433335333363333733338333393334033341333423334333344333453334633347333483334933350333513335233353333543335533356333573335833359333603336133362333633336433365333663336733368333693337033371333723337333374333753337633377333783337933380333813338233383333843338533386333873338833389333903339133392333933339433395333963339733398333993340033401334023340333404334053340633407334083340933410334113341233413334143341533416334173341833419334203342133422334233342433425334263342733428334293343033431334323343333434334353343633437334383343933440334413344233443334443344533446334473344833449334503345133452334533345433455334563345733458334593346033461334623346333464334653346633467334683346933470334713347233473334743347533476334773347833479334803348133482334833348433485334863348733488334893349033491334923349333494334953349633497334983349933500335013350233503335043350533506335073350833509335103351133512335133351433515335163351733518335193352033521335223352333524335253352633527335283352933530335313353233533335343353533536335373353833539335403354133542335433354433545335463354733548335493355033551335523355333554335553355633557335583355933560335613356233563335643356533566335673356833569335703357133572335733357433575335763357733578335793358033581335823358333584335853358633587335883358933590335913359233593335943359533596335973359833599336003360133602336033360433605336063360733608336093361033611336123361333614336153361633617336183361933620336213362233623336243362533626336273362833629336303363133632336333363433635336363363733638336393364033641336423364333644336453364633647336483364933650336513365233653336543365533656336573365833659336603366133662336633366433665336663366733668336693367033671336723367333674336753367633677336783367933680336813368233683336843368533686336873368833689336903369133692336933369433695336963369733698336993370033701337023370333704337053370633707337083370933710337113371233713337143371533716337173371833719337203372133722337233372433725337263372733728337293373033731337323373333734337353373633737337383373933740337413374233743337443374533746337473374833749337503375133752337533375433755337563375733758337593376033761337623376333764337653376633767337683376933770337713377233773337743377533776337773377833779337803378133782337833378433785337863378733788337893379033791337923379333794337953379633797337983379933800338013380233803338043380533806338073380833809338103381133812338133381433815338163381733818338193382033821338223382333824338253382633827338283382933830338313383233833338343383533836338373383833839338403384133842338433384433845338463384733848338493385033851338523385333854338553385633857338583385933860338613386233863338643386533866338673386833869338703387133872338733387433875338763387733878338793388033881338823388333884338853388633887338883388933890338913389233893338943389533896338973389833899339003390133902339033390433905339063390733908339093391033911339123391333914339153391633917339183391933920339213392233923339243392533926339273392833929339303393133932339333393433935339363393733938339393394033941339423394333944339453394633947339483394933950339513395233953339543395533956339573395833959339603396133962339633396433965339663396733968339693397033971339723397333974339753397633977339783397933980339813398233983339843398533986339873398833989339903399133992339933399433995339963399733998339993400034001340023400334004340053400634007340083400934010340113401234013340143401534016340173401834019340203402134022340233402434025340263402734028340293403034031340323403334034340353403634037340383403934040340413404234043340443404534046340473404834049340503405134052340533405434055340563405734058340593406034061340623406334064340653406634067340683406934070340713407234073340743407534076340773407834079340803408134082340833408434085340863408734088340893409034091340923409334094340953409634097340983409934100341013410234103341043410534106341073410834109341103411134112341133411434115341163411734118341193412034121341223412334124341253412634127341283412934130341313413234133341343413534136341373413834139341403414134142341433414434145341463414734148341493415034151341523415334154341553415634157341583415934160341613416234163341643416534166341673416834169341703417134172341733417434175341763417734178341793418034181341823418334184341853418634187341883418934190341913419234193341943419534196341973419834199342003420134202342033420434205342063420734208342093421034211342123421334214342153421634217342183421934220342213422234223342243422534226342273422834229342303423134232342333423434235342363423734238342393424034241342423424334244342453424634247342483424934250342513425234253342543425534256342573425834259342603426134262342633426434265342663426734268342693427034271342723427334274342753427634277342783427934280342813428234283342843428534286342873428834289342903429134292342933429434295342963429734298342993430034301343023430334304343053430634307343083430934310343113431234313343143431534316343173431834319343203432134322343233432434325343263432734328343293433034331343323433334334343353433634337343383433934340343413434234343343443434534346343473434834349343503435134352343533435434355343563435734358343593436034361343623436334364343653436634367343683436934370343713437234373343743437534376343773437834379343803438134382343833438434385343863438734388343893439034391343923439334394343953439634397343983439934400344013440234403344043440534406344073440834409344103441134412344133441434415344163441734418344193442034421344223442334424344253442634427344283442934430344313443234433344343443534436344373443834439344403444134442344433444434445344463444734448344493445034451344523445334454344553445634457344583445934460344613446234463344643446534466344673446834469344703447134472344733447434475344763447734478344793448034481344823448334484344853448634487344883448934490344913449234493344943449534496344973449834499345003450134502345033450434505345063450734508345093451034511345123451334514345153451634517345183451934520345213452234523345243452534526345273452834529345303453134532345333453434535345363453734538345393454034541345423454334544345453454634547345483454934550345513455234553345543455534556345573455834559345603456134562345633456434565345663456734568345693457034571345723457334574345753457634577345783457934580345813458234583345843458534586345873458834589345903459134592345933459434595345963459734598345993460034601346023460334604346053460634607346083460934610346113461234613346143461534616346173461834619346203462134622346233462434625346263462734628346293463034631346323463334634346353463634637346383463934640346413464234643346443464534646346473464834649346503465134652346533465434655346563465734658346593466034661346623466334664346653466634667346683466934670346713467234673346743467534676346773467834679346803468134682346833468434685346863468734688346893469034691346923469334694346953469634697346983469934700347013470234703347043470534706347073470834709347103471134712347133471434715347163471734718347193472034721347223472334724347253472634727347283472934730347313473234733347343473534736347373473834739347403474134742347433474434745347463474734748347493475034751347523475334754347553475634757347583475934760347613476234763347643476534766347673476834769347703477134772347733477434775347763477734778347793478034781347823478334784347853478634787347883478934790347913479234793347943479534796347973479834799348003480134802348033480434805348063480734808348093481034811348123481334814348153481634817348183481934820348213482234823348243482534826348273482834829348303483134832348333483434835348363483734838348393484034841348423484334844348453484634847348483484934850348513485234853348543485534856348573485834859348603486134862348633486434865348663486734868348693487034871348723487334874348753487634877348783487934880348813488234883348843488534886348873488834889348903489134892348933489434895348963489734898348993490034901349023490334904349053490634907349083490934910349113491234913349143491534916349173491834919349203492134922349233492434925349263492734928349293493034931349323493334934349353493634937349383493934940349413494234943349443494534946349473494834949349503495134952349533495434955349563495734958349593496034961349623496334964349653496634967349683496934970349713497234973349743497534976349773497834979349803498134982349833498434985349863498734988349893499034991349923499334994349953499634997349983499935000350013500235003350043500535006350073500835009350103501135012350133501435015350163501735018350193502035021350223502335024350253502635027350283502935030350313503235033350343503535036350373503835039350403504135042350433504435045350463504735048350493505035051350523505335054350553505635057350583505935060350613506235063350643506535066350673506835069350703507135072350733507435075350763507735078350793508035081350823508335084350853508635087350883508935090350913509235093350943509535096350973509835099351003510135102351033510435105351063510735108351093511035111351123511335114351153511635117351183511935120351213512235123351243512535126351273512835129351303513135132351333513435135351363513735138351393514035141351423514335144351453514635147351483514935150351513515235153351543515535156351573515835159351603516135162351633516435165351663516735168351693517035171351723517335174351753517635177351783517935180351813518235183351843518535186351873518835189351903519135192351933519435195351963519735198351993520035201352023520335204352053520635207352083520935210352113521235213352143521535216352173521835219352203522135222352233522435225352263522735228352293523035231352323523335234352353523635237352383523935240352413524235243352443524535246352473524835249352503525135252352533525435255352563525735258352593526035261352623526335264352653526635267352683526935270352713527235273352743527535276352773527835279352803528135282352833528435285352863528735288352893529035291352923529335294352953529635297352983529935300353013530235303353043530535306353073530835309353103531135312353133531435315353163531735318353193532035321353223532335324353253532635327353283532935330353313533235333353343533535336353373533835339353403534135342353433534435345353463534735348353493535035351353523535335354353553535635357353583535935360353613536235363353643536535366353673536835369353703537135372353733537435375353763537735378353793538035381353823538335384353853538635387353883538935390353913539235393353943539535396353973539835399354003540135402354033540435405354063540735408354093541035411354123541335414354153541635417354183541935420354213542235423354243542535426354273542835429354303543135432354333543435435354363543735438354393544035441354423544335444354453544635447354483544935450354513545235453354543545535456354573545835459354603546135462354633546435465354663546735468354693547035471354723547335474354753547635477354783547935480354813548235483354843548535486354873548835489354903549135492354933549435495354963549735498354993550035501355023550335504355053550635507355083550935510355113551235513355143551535516355173551835519355203552135522355233552435525355263552735528355293553035531355323553335534355353553635537355383553935540355413554235543355443554535546355473554835549355503555135552355533555435555355563555735558355593556035561355623556335564355653556635567355683556935570355713557235573355743557535576355773557835579355803558135582355833558435585355863558735588355893559035591355923559335594355953559635597355983559935600356013560235603356043560535606356073560835609356103561135612356133561435615356163561735618356193562035621356223562335624356253562635627356283562935630356313563235633356343563535636356373563835639356403564135642356433564435645356463564735648356493565035651356523565335654356553565635657356583565935660356613566235663356643566535666356673566835669356703567135672356733567435675356763567735678356793568035681356823568335684356853568635687356883568935690356913569235693356943569535696356973569835699357003570135702357033570435705357063570735708357093571035711357123571335714357153571635717357183571935720357213572235723357243572535726357273572835729357303573135732357333573435735357363573735738357393574035741357423574335744357453574635747357483574935750357513575235753357543575535756357573575835759357603576135762357633576435765357663576735768357693577035771357723577335774357753577635777357783577935780357813578235783357843578535786357873578835789357903579135792357933579435795357963579735798357993580035801358023580335804358053580635807358083580935810358113581235813358143581535816358173581835819358203582135822358233582435825358263582735828358293583035831358323583335834358353583635837358383583935840358413584235843358443584535846358473584835849358503585135852358533585435855358563585735858358593586035861358623586335864358653586635867358683586935870358713587235873358743587535876358773587835879358803588135882358833588435885358863588735888358893589035891358923589335894358953589635897358983589935900359013590235903359043590535906359073590835909359103591135912359133591435915359163591735918359193592035921359223592335924359253592635927359283592935930359313593235933359343593535936359373593835939359403594135942359433594435945359463594735948359493595035951359523595335954359553595635957359583595935960359613596235963359643596535966359673596835969359703597135972359733597435975359763597735978359793598035981359823598335984359853598635987359883598935990359913599235993359943599535996359973599835999360003600136002360033600436005360063600736008360093601036011360123601336014360153601636017360183601936020360213602236023360243602536026360273602836029360303603136032360333603436035360363603736038360393604036041360423604336044360453604636047360483604936050360513605236053360543605536056360573605836059360603606136062360633606436065360663606736068360693607036071360723607336074360753607636077360783607936080360813608236083360843608536086360873608836089360903609136092360933609436095360963609736098360993610036101361023610336104361053610636107361083610936110361113611236113361143611536116361173611836119361203612136122361233612436125361263612736128361293613036131361323613336134361353613636137361383613936140361413614236143361443614536146361473614836149361503615136152361533615436155361563615736158361593616036161361623616336164361653616636167361683616936170361713617236173361743617536176361773617836179361803618136182361833618436185361863618736188361893619036191361923619336194361953619636197361983619936200362013620236203362043620536206362073620836209362103621136212362133621436215362163621736218362193622036221362223622336224362253622636227362283622936230362313623236233362343623536236362373623836239362403624136242362433624436245362463624736248362493625036251362523625336254362553625636257362583625936260362613626236263362643626536266362673626836269362703627136272362733627436275362763627736278362793628036281362823628336284362853628636287362883628936290362913629236293362943629536296362973629836299363003630136302363033630436305363063630736308363093631036311363123631336314363153631636317363183631936320363213632236323363243632536326363273632836329363303633136332363333633436335363363633736338363393634036341363423634336344363453634636347363483634936350363513635236353363543635536356363573635836359363603636136362363633636436365363663636736368363693637036371363723637336374363753637636377363783637936380363813638236383363843638536386363873638836389363903639136392363933639436395363963639736398363993640036401364023640336404364053640636407364083640936410364113641236413364143641536416364173641836419364203642136422364233642436425364263642736428364293643036431364323643336434364353643636437364383643936440364413644236443364443644536446364473644836449364503645136452364533645436455364563645736458364593646036461364623646336464364653646636467364683646936470364713647236473364743647536476364773647836479364803648136482364833648436485364863648736488364893649036491364923649336494364953649636497364983649936500365013650236503365043650536506365073650836509365103651136512365133651436515365163651736518365193652036521365223652336524365253652636527365283652936530365313653236533365343653536536365373653836539365403654136542365433654436545365463654736548365493655036551365523655336554365553655636557365583655936560365613656236563365643656536566365673656836569365703657136572365733657436575365763657736578365793658036581365823658336584365853658636587365883658936590365913659236593365943659536596365973659836599366003660136602366033660436605366063660736608366093661036611366123661336614366153661636617366183661936620366213662236623366243662536626366273662836629366303663136632366333663436635366363663736638366393664036641366423664336644366453664636647366483664936650366513665236653366543665536656366573665836659366603666136662366633666436665366663666736668366693667036671366723667336674366753667636677366783667936680366813668236683366843668536686366873668836689366903669136692366933669436695366963669736698366993670036701367023670336704367053670636707367083670936710367113671236713367143671536716367173671836719367203672136722367233672436725367263672736728367293673036731367323673336734367353673636737367383673936740367413674236743367443674536746367473674836749367503675136752367533675436755367563675736758367593676036761367623676336764367653676636767367683676936770367713677236773367743677536776367773677836779367803678136782367833678436785367863678736788367893679036791367923679336794367953679636797367983679936800368013680236803368043680536806368073680836809368103681136812368133681436815368163681736818368193682036821368223682336824368253682636827368283682936830368313683236833368343683536836368373683836839368403684136842368433684436845368463684736848368493685036851368523685336854368553685636857368583685936860368613686236863368643686536866368673686836869368703687136872368733687436875368763687736878368793688036881368823688336884368853688636887368883688936890368913689236893368943689536896368973689836899369003690136902369033690436905369063690736908369093691036911369123691336914369153691636917369183691936920369213692236923369243692536926369273692836929369303693136932369333693436935369363693736938369393694036941369423694336944369453694636947369483694936950369513695236953369543695536956369573695836959369603696136962369633696436965369663696736968369693697036971369723697336974369753697636977369783697936980369813698236983369843698536986369873698836989369903699136992369933699436995369963699736998369993700037001370023700337004370053700637007370083700937010370113701237013370143701537016370173701837019370203702137022370233702437025370263702737028370293703037031370323703337034370353703637037370383703937040370413704237043370443704537046370473704837049370503705137052370533705437055370563705737058370593706037061370623706337064370653706637067370683706937070370713707237073370743707537076370773707837079370803708137082370833708437085370863708737088370893709037091370923709337094370953709637097370983709937100371013710237103371043710537106371073710837109371103711137112371133711437115371163711737118371193712037121371223712337124371253712637127371283712937130371313713237133371343713537136371373713837139371403714137142371433714437145371463714737148371493715037151371523715337154371553715637157371583715937160371613716237163371643716537166371673716837169371703717137172371733717437175371763717737178371793718037181371823718337184371853718637187371883718937190371913719237193371943719537196371973719837199372003720137202372033720437205372063720737208372093721037211372123721337214372153721637217372183721937220372213722237223372243722537226372273722837229372303723137232372333723437235372363723737238372393724037241372423724337244372453724637247372483724937250372513725237253372543725537256372573725837259372603726137262372633726437265372663726737268372693727037271372723727337274372753727637277372783727937280372813728237283372843728537286372873728837289372903729137292372933729437295372963729737298372993730037301373023730337304373053730637307373083730937310373113731237313373143731537316373173731837319373203732137322373233732437325373263732737328373293733037331373323733337334373353733637337373383733937340373413734237343373443734537346373473734837349373503735137352373533735437355373563735737358373593736037361373623736337364373653736637367373683736937370373713737237373373743737537376373773737837379373803738137382373833738437385373863738737388373893739037391373923739337394373953739637397373983739937400374013740237403374043740537406374073740837409374103741137412374133741437415374163741737418374193742037421374223742337424374253742637427374283742937430374313743237433374343743537436374373743837439374403744137442374433744437445374463744737448374493745037451374523745337454374553745637457374583745937460374613746237463374643746537466374673746837469374703747137472374733747437475374763747737478374793748037481374823748337484374853748637487374883748937490374913749237493374943749537496374973749837499375003750137502375033750437505375063750737508375093751037511375123751337514375153751637517375183751937520375213752237523375243752537526375273752837529375303753137532375333753437535375363753737538375393754037541375423754337544375453754637547375483754937550375513755237553375543755537556375573755837559375603756137562375633756437565375663756737568375693757037571375723757337574375753757637577375783757937580375813758237583375843758537586375873758837589375903759137592375933759437595375963759737598375993760037601376023760337604376053760637607376083760937610376113761237613376143761537616376173761837619376203762137622376233762437625376263762737628376293763037631376323763337634376353763637637376383763937640376413764237643376443764537646376473764837649376503765137652376533765437655376563765737658376593766037661376623766337664376653766637667376683766937670376713767237673376743767537676376773767837679376803768137682376833768437685376863768737688376893769037691376923769337694376953769637697376983769937700377013770237703377043770537706377073770837709377103771137712377133771437715377163771737718377193772037721377223772337724377253772637727377283772937730377313773237733377343773537736377373773837739377403774137742377433774437745377463774737748377493775037751377523775337754377553775637757377583775937760377613776237763377643776537766377673776837769377703777137772377733777437775377763777737778377793778037781377823778337784377853778637787377883778937790377913779237793377943779537796377973779837799378003780137802378033780437805378063780737808378093781037811378123781337814378153781637817378183781937820378213782237823378243782537826378273782837829378303783137832378333783437835378363783737838378393784037841378423784337844378453784637847378483784937850378513785237853378543785537856378573785837859378603786137862378633786437865378663786737868378693787037871378723787337874378753787637877378783787937880378813788237883378843788537886378873788837889378903789137892378933789437895378963789737898378993790037901379023790337904379053790637907379083790937910379113791237913379143791537916379173791837919379203792137922379233792437925379263792737928379293793037931379323793337934379353793637937379383793937940379413794237943379443794537946379473794837949379503795137952379533795437955379563795737958379593796037961379623796337964379653796637967379683796937970379713797237973379743797537976379773797837979379803798137982379833798437985379863798737988379893799037991379923799337994379953799637997379983799938000380013800238003380043800538006380073800838009380103801138012380133801438015380163801738018380193802038021380223802338024380253802638027380283802938030380313803238033380343803538036380373803838039380403804138042380433804438045380463804738048380493805038051380523805338054380553805638057380583805938060380613806238063380643806538066380673806838069380703807138072380733807438075380763807738078380793808038081380823808338084380853808638087380883808938090380913809238093380943809538096380973809838099381003810138102381033810438105381063810738108381093811038111381123811338114381153811638117381183811938120381213812238123381243812538126381273812838129381303813138132381333813438135381363813738138381393814038141381423814338144381453814638147381483814938150381513815238153381543815538156381573815838159381603816138162381633816438165381663816738168381693817038171381723817338174381753817638177381783817938180381813818238183381843818538186381873818838189381903819138192381933819438195381963819738198381993820038201382023820338204382053820638207382083820938210382113821238213382143821538216382173821838219382203822138222382233822438225382263822738228382293823038231382323823338234382353823638237382383823938240382413824238243382443824538246382473824838249382503825138252382533825438255382563825738258382593826038261382623826338264382653826638267382683826938270382713827238273382743827538276382773827838279382803828138282382833828438285382863828738288382893829038291382923829338294382953829638297382983829938300383013830238303383043830538306383073830838309383103831138312383133831438315383163831738318383193832038321383223832338324383253832638327383283832938330383313833238333383343833538336383373833838339383403834138342383433834438345383463834738348383493835038351383523835338354383553835638357383583835938360383613836238363383643836538366383673836838369383703837138372383733837438375383763837738378383793838038381383823838338384383853838638387383883838938390383913839238393383943839538396383973839838399384003840138402384033840438405384063840738408384093841038411384123841338414384153841638417384183841938420384213842238423384243842538426384273842838429384303843138432384333843438435384363843738438384393844038441384423844338444384453844638447384483844938450384513845238453384543845538456384573845838459384603846138462384633846438465384663846738468384693847038471384723847338474384753847638477384783847938480384813848238483384843848538486384873848838489384903849138492384933849438495384963849738498384993850038501385023850338504385053850638507385083850938510385113851238513385143851538516385173851838519385203852138522385233852438525385263852738528385293853038531385323853338534385353853638537385383853938540385413854238543385443854538546385473854838549385503855138552385533855438555385563855738558385593856038561385623856338564385653856638567385683856938570385713857238573385743857538576385773857838579385803858138582385833858438585385863858738588385893859038591385923859338594385953859638597385983859938600386013860238603386043860538606386073860838609386103861138612386133861438615386163861738618386193862038621386223862338624386253862638627386283862938630386313863238633386343863538636386373863838639386403864138642386433864438645386463864738648386493865038651386523865338654386553865638657386583865938660386613866238663386643866538666386673866838669386703867138672386733867438675386763867738678386793868038681386823868338684386853868638687386883868938690386913869238693386943869538696386973869838699387003870138702387033870438705387063870738708387093871038711387123871338714387153871638717387183871938720387213872238723387243872538726387273872838729387303873138732387333873438735387363873738738387393874038741387423874338744387453874638747387483874938750387513875238753387543875538756387573875838759387603876138762387633876438765387663876738768387693877038771387723877338774387753877638777387783877938780387813878238783387843878538786387873878838789387903879138792387933879438795387963879738798387993880038801388023880338804388053880638807388083880938810388113881238813388143881538816388173881838819388203882138822388233882438825388263882738828388293883038831388323883338834388353883638837388383883938840388413884238843388443884538846388473884838849388503885138852388533885438855388563885738858388593886038861388623886338864388653886638867388683886938870388713887238873388743887538876388773887838879388803888138882388833888438885388863888738888388893889038891388923889338894388953889638897388983889938900389013890238903389043890538906389073890838909389103891138912389133891438915389163891738918389193892038921389223892338924389253892638927389283892938930389313893238933389343893538936389373893838939389403894138942389433894438945389463894738948389493895038951389523895338954389553895638957389583895938960389613896238963389643896538966389673896838969389703897138972389733897438975389763897738978389793898038981389823898338984389853898638987389883898938990389913899238993389943899538996389973899838999390003900139002390033900439005390063900739008390093901039011390123901339014390153901639017390183901939020390213902239023390243902539026390273902839029390303903139032390333903439035390363903739038390393904039041390423904339044390453904639047390483904939050390513905239053390543905539056390573905839059390603906139062390633906439065390663906739068390693907039071390723907339074390753907639077390783907939080390813908239083390843908539086390873908839089390903909139092390933909439095390963909739098390993910039101391023910339104391053910639107391083910939110391113911239113391143911539116391173911839119391203912139122391233912439125391263912739128391293913039131391323913339134391353913639137391383913939140391413914239143391443914539146391473914839149391503915139152391533915439155391563915739158391593916039161391623916339164391653916639167391683916939170391713917239173391743917539176391773917839179391803918139182391833918439185391863918739188391893919039191391923919339194391953919639197391983919939200392013920239203392043920539206392073920839209392103921139212392133921439215392163921739218392193922039221392223922339224392253922639227392283922939230392313923239233392343923539236392373923839239392403924139242392433924439245392463924739248392493925039251392523925339254392553925639257392583925939260392613926239263392643926539266392673926839269392703927139272392733927439275392763927739278392793928039281392823928339284392853928639287392883928939290392913929239293392943929539296392973929839299393003930139302393033930439305393063930739308393093931039311393123931339314393153931639317393183931939320393213932239323393243932539326393273932839329393303933139332393333933439335393363933739338393393934039341393423934339344393453934639347393483934939350393513935239353393543935539356393573935839359393603936139362393633936439365393663936739368393693937039371393723937339374393753937639377393783937939380393813938239383393843938539386393873938839389393903939139392393933939439395393963939739398393993940039401394023940339404394053940639407394083940939410394113941239413394143941539416394173941839419394203942139422394233942439425394263942739428394293943039431394323943339434394353943639437394383943939440394413944239443394443944539446394473944839449394503945139452394533945439455394563945739458394593946039461394623946339464394653946639467394683946939470394713947239473394743947539476394773947839479394803948139482394833948439485394863948739488394893949039491394923949339494394953949639497394983949939500395013950239503395043950539506395073950839509395103951139512395133951439515395163951739518395193952039521395223952339524395253952639527395283952939530395313953239533395343953539536395373953839539395403954139542395433954439545395463954739548395493955039551395523955339554395553955639557395583955939560395613956239563395643956539566395673956839569395703957139572395733957439575395763957739578395793958039581395823958339584395853958639587395883958939590395913959239593395943959539596395973959839599396003960139602396033960439605396063960739608396093961039611396123961339614396153961639617396183961939620396213962239623396243962539626396273962839629396303963139632396333963439635396363963739638396393964039641396423964339644396453964639647396483964939650396513965239653396543965539656396573965839659396603966139662396633966439665396663966739668396693967039671396723967339674396753967639677396783967939680396813968239683396843968539686396873968839689396903969139692396933969439695396963969739698396993970039701397023970339704397053970639707397083970939710397113971239713397143971539716397173971839719397203972139722397233972439725397263972739728397293973039731397323973339734397353973639737397383973939740397413974239743397443974539746397473974839749397503975139752397533975439755397563975739758397593976039761397623976339764397653976639767397683976939770397713977239773397743977539776397773977839779397803978139782397833978439785397863978739788397893979039791397923979339794397953979639797397983979939800398013980239803398043980539806398073980839809398103981139812398133981439815398163981739818398193982039821398223982339824398253982639827398283982939830398313983239833398343983539836398373983839839398403984139842398433984439845398463984739848398493985039851398523985339854398553985639857398583985939860398613986239863398643986539866398673986839869398703987139872398733987439875398763987739878398793988039881398823988339884398853988639887398883988939890398913989239893398943989539896398973989839899399003990139902399033990439905399063990739908399093991039911399123991339914399153991639917399183991939920399213992239923399243992539926399273992839929399303993139932399333993439935399363993739938399393994039941399423994339944399453994639947399483994939950399513995239953399543995539956399573995839959399603996139962399633996439965399663996739968399693997039971399723997339974399753997639977399783997939980399813998239983399843998539986399873998839989399903999139992399933999439995399963999739998399994000040001400024000340004400054000640007400084000940010400114001240013400144001540016400174001840019400204002140022400234002440025400264002740028400294003040031400324003340034400354003640037400384003940040400414004240043400444004540046400474004840049400504005140052400534005440055400564005740058400594006040061400624006340064400654006640067400684006940070400714007240073400744007540076400774007840079400804008140082400834008440085400864008740088400894009040091400924009340094400954009640097400984009940100401014010240103401044010540106401074010840109401104011140112401134011440115401164011740118401194012040121401224012340124401254012640127401284012940130401314013240133401344013540136401374013840139401404014140142401434014440145401464014740148401494015040151401524015340154401554015640157401584015940160401614016240163401644016540166401674016840169401704017140172401734017440175401764017740178401794018040181401824018340184401854018640187401884018940190401914019240193401944019540196401974019840199402004020140202402034020440205402064020740208402094021040211402124021340214402154021640217402184021940220402214022240223402244022540226402274022840229402304023140232402334023440235402364023740238402394024040241402424024340244402454024640247402484024940250402514025240253402544025540256402574025840259402604026140262402634026440265402664026740268402694027040271402724027340274402754027640277402784027940280402814028240283402844028540286402874028840289402904029140292402934029440295402964029740298402994030040301403024030340304403054030640307403084030940310403114031240313403144031540316403174031840319403204032140322403234032440325403264032740328403294033040331403324033340334403354033640337403384033940340403414034240343403444034540346403474034840349403504035140352403534035440355403564035740358403594036040361403624036340364403654036640367403684036940370403714037240373403744037540376403774037840379403804038140382403834038440385403864038740388403894039040391403924039340394403954039640397403984039940400404014040240403404044040540406404074040840409404104041140412404134041440415404164041740418404194042040421404224042340424404254042640427404284042940430404314043240433404344043540436404374043840439404404044140442404434044440445404464044740448404494045040451404524045340454404554045640457404584045940460404614046240463404644046540466404674046840469404704047140472404734047440475404764047740478404794048040481404824048340484404854048640487404884048940490404914049240493404944049540496404974049840499405004050140502405034050440505405064050740508405094051040511405124051340514405154051640517405184051940520405214052240523405244052540526405274052840529405304053140532405334053440535405364053740538405394054040541405424054340544405454054640547405484054940550405514055240553405544055540556405574055840559405604056140562405634056440565405664056740568405694057040571405724057340574405754057640577405784057940580405814058240583405844058540586405874058840589405904059140592405934059440595405964059740598405994060040601406024060340604406054060640607406084060940610406114061240613406144061540616406174061840619406204062140622406234062440625406264062740628406294063040631406324063340634406354063640637406384063940640406414064240643406444064540646406474064840649406504065140652406534065440655406564065740658406594066040661406624066340664406654066640667406684066940670406714067240673406744067540676406774067840679406804068140682406834068440685406864068740688406894069040691406924069340694406954069640697406984069940700407014070240703407044070540706407074070840709407104071140712407134071440715407164071740718407194072040721407224072340724407254072640727407284072940730407314073240733407344073540736407374073840739407404074140742407434074440745407464074740748407494075040751407524075340754407554075640757407584075940760407614076240763407644076540766407674076840769407704077140772407734077440775407764077740778407794078040781407824078340784407854078640787407884078940790407914079240793407944079540796407974079840799408004080140802408034080440805408064080740808408094081040811408124081340814408154081640817408184081940820408214082240823408244082540826408274082840829408304083140832408334083440835408364083740838408394084040841408424084340844408454084640847408484084940850408514085240853408544085540856408574085840859408604086140862408634086440865408664086740868408694087040871408724087340874408754087640877408784087940880408814088240883408844088540886408874088840889408904089140892408934089440895408964089740898408994090040901409024090340904409054090640907409084090940910409114091240913409144091540916409174091840919409204092140922409234092440925409264092740928409294093040931409324093340934409354093640937409384093940940409414094240943409444094540946409474094840949409504095140952409534095440955409564095740958409594096040961409624096340964409654096640967409684096940970409714097240973409744097540976409774097840979409804098140982409834098440985409864098740988409894099040991409924099340994409954099640997409984099941000410014100241003410044100541006410074100841009410104101141012410134101441015410164101741018410194102041021410224102341024410254102641027410284102941030410314103241033410344103541036410374103841039410404104141042410434104441045410464104741048410494105041051410524105341054410554105641057410584105941060410614106241063410644106541066410674106841069410704107141072410734107441075410764107741078410794108041081410824108341084410854108641087410884108941090410914109241093410944109541096410974109841099411004110141102411034110441105411064110741108411094111041111411124111341114411154111641117411184111941120411214112241123411244112541126411274112841129411304113141132411334113441135411364113741138411394114041141411424114341144411454114641147411484114941150411514115241153411544115541156411574115841159411604116141162411634116441165411664116741168411694117041171411724117341174411754117641177411784117941180411814118241183411844118541186411874118841189411904119141192411934119441195411964119741198411994120041201412024120341204412054120641207412084120941210412114121241213412144121541216412174121841219412204122141222412234122441225412264122741228412294123041231412324123341234412354123641237412384123941240412414124241243412444124541246412474124841249412504125141252412534125441255412564125741258412594126041261412624126341264412654126641267412684126941270412714127241273412744127541276412774127841279412804128141282412834128441285412864128741288412894129041291412924129341294412954129641297412984129941300413014130241303413044130541306413074130841309413104131141312413134131441315413164131741318413194132041321413224132341324413254132641327413284132941330413314133241333413344133541336413374133841339413404134141342413434134441345413464134741348413494135041351413524135341354413554135641357413584135941360413614136241363413644136541366413674136841369413704137141372413734137441375413764137741378413794138041381413824138341384413854138641387413884138941390413914139241393413944139541396413974139841399414004140141402414034140441405414064140741408414094141041411414124141341414414154141641417414184141941420414214142241423414244142541426414274142841429414304143141432414334143441435414364143741438414394144041441414424144341444414454144641447414484144941450414514145241453414544145541456414574145841459414604146141462414634146441465414664146741468414694147041471414724147341474414754147641477414784147941480414814148241483414844148541486414874148841489414904149141492414934149441495414964149741498414994150041501415024150341504415054150641507415084150941510415114151241513415144151541516415174151841519415204152141522415234152441525415264152741528415294153041531415324153341534415354153641537415384153941540415414154241543415444154541546415474154841549415504155141552415534155441555415564155741558415594156041561415624156341564415654156641567415684156941570415714157241573415744157541576415774157841579415804158141582415834158441585415864158741588415894159041591415924159341594415954159641597415984159941600416014160241603416044160541606416074160841609416104161141612416134161441615416164161741618416194162041621416224162341624416254162641627416284162941630416314163241633416344163541636416374163841639416404164141642416434164441645416464164741648416494165041651416524165341654416554165641657416584165941660416614166241663416644166541666416674166841669416704167141672416734167441675416764167741678416794168041681416824168341684416854168641687416884168941690416914169241693416944169541696416974169841699417004170141702417034170441705417064170741708417094171041711417124171341714417154171641717417184171941720417214172241723417244172541726417274172841729417304173141732417334173441735417364173741738417394174041741417424174341744417454174641747417484174941750417514175241753417544175541756417574175841759417604176141762417634176441765417664176741768417694177041771417724177341774417754177641777417784177941780417814178241783417844178541786417874178841789417904179141792417934179441795417964179741798417994180041801418024180341804418054180641807418084180941810418114181241813418144181541816418174181841819418204182141822418234182441825418264182741828418294183041831418324183341834418354183641837418384183941840418414184241843418444184541846418474184841849418504185141852418534185441855418564185741858418594186041861418624186341864418654186641867418684186941870418714187241873418744187541876418774187841879418804188141882418834188441885418864188741888418894189041891418924189341894418954189641897418984189941900419014190241903419044190541906419074190841909419104191141912419134191441915419164191741918419194192041921419224192341924419254192641927419284192941930419314193241933419344193541936419374193841939419404194141942419434194441945419464194741948419494195041951419524195341954419554195641957419584195941960419614196241963419644196541966419674196841969419704197141972419734197441975419764197741978419794198041981419824198341984419854198641987419884198941990419914199241993419944199541996419974199841999420004200142002420034200442005420064200742008420094201042011420124201342014420154201642017420184201942020420214202242023420244202542026420274202842029420304203142032420334203442035420364203742038420394204042041420424204342044420454204642047420484204942050420514205242053420544205542056420574205842059420604206142062420634206442065420664206742068420694207042071420724207342074420754207642077420784207942080420814208242083420844208542086420874208842089420904209142092420934209442095420964209742098420994210042101421024210342104421054210642107421084210942110421114211242113421144211542116421174211842119421204212142122421234212442125421264212742128421294213042131421324213342134421354213642137421384213942140421414214242143421444214542146421474214842149421504215142152421534215442155421564215742158421594216042161421624216342164421654216642167421684216942170421714217242173421744217542176421774217842179421804218142182421834218442185421864218742188421894219042191421924219342194421954219642197421984219942200422014220242203422044220542206422074220842209422104221142212422134221442215422164221742218422194222042221422224222342224422254222642227422284222942230422314223242233422344223542236422374223842239422404224142242422434224442245422464224742248422494225042251422524225342254422554225642257422584225942260422614226242263422644226542266422674226842269422704227142272422734227442275422764227742278422794228042281422824228342284422854228642287422884228942290422914229242293422944229542296422974229842299423004230142302423034230442305423064230742308423094231042311423124231342314423154231642317423184231942320423214232242323423244232542326423274232842329423304233142332423334233442335423364233742338423394234042341423424234342344423454234642347423484234942350423514235242353423544235542356423574235842359423604236142362423634236442365423664236742368423694237042371423724237342374423754237642377423784237942380423814238242383423844238542386423874238842389423904239142392423934239442395423964239742398423994240042401424024240342404424054240642407424084240942410424114241242413424144241542416424174241842419424204242142422424234242442425424264242742428424294243042431424324243342434424354243642437424384243942440424414244242443424444244542446424474244842449424504245142452424534245442455424564245742458424594246042461424624246342464424654246642467424684246942470424714247242473424744247542476424774247842479424804248142482424834248442485424864248742488424894249042491424924249342494424954249642497424984249942500425014250242503425044250542506425074250842509425104251142512425134251442515425164251742518425194252042521425224252342524425254252642527425284252942530425314253242533425344253542536425374253842539425404254142542425434254442545425464254742548425494255042551425524255342554425554255642557425584255942560425614256242563425644256542566425674256842569425704257142572425734257442575425764257742578425794258042581425824258342584425854258642587425884258942590425914259242593425944259542596425974259842599426004260142602426034260442605426064260742608426094261042611426124261342614426154261642617426184261942620426214262242623426244262542626426274262842629426304263142632426334263442635426364263742638426394264042641426424264342644426454264642647426484264942650426514265242653426544265542656426574265842659426604266142662426634266442665426664266742668426694267042671426724267342674426754267642677426784267942680426814268242683426844268542686426874268842689426904269142692426934269442695426964269742698426994270042701427024270342704427054270642707427084270942710427114271242713427144271542716427174271842719427204272142722427234272442725427264272742728427294273042731427324273342734427354273642737427384273942740427414274242743427444274542746427474274842749427504275142752427534275442755427564275742758427594276042761427624276342764427654276642767427684276942770427714277242773427744277542776427774277842779427804278142782427834278442785427864278742788427894279042791427924279342794427954279642797427984279942800428014280242803428044280542806428074280842809428104281142812428134281442815428164281742818428194282042821428224282342824428254282642827428284282942830428314283242833428344283542836428374283842839428404284142842428434284442845428464284742848428494285042851428524285342854428554285642857428584285942860428614286242863428644286542866428674286842869428704287142872428734287442875428764287742878428794288042881428824288342884428854288642887428884288942890428914289242893428944289542896428974289842899429004290142902429034290442905429064290742908429094291042911429124291342914429154291642917429184291942920429214292242923429244292542926429274292842929429304293142932429334293442935429364293742938429394294042941429424294342944429454294642947429484294942950429514295242953429544295542956429574295842959429604296142962429634296442965429664296742968429694297042971429724297342974429754297642977429784297942980429814298242983429844298542986429874298842989429904299142992429934299442995429964299742998429994300043001430024300343004430054300643007430084300943010430114301243013430144301543016430174301843019430204302143022430234302443025430264302743028430294303043031430324303343034430354303643037430384303943040430414304243043430444304543046430474304843049430504305143052430534305443055430564305743058430594306043061430624306343064430654306643067430684306943070430714307243073430744307543076430774307843079430804308143082430834308443085430864308743088430894309043091430924309343094430954309643097430984309943100431014310243103431044310543106431074310843109431104311143112431134311443115431164311743118431194312043121431224312343124431254312643127431284312943130431314313243133431344313543136431374313843139431404314143142431434314443145431464314743148431494315043151431524315343154431554315643157431584315943160431614316243163431644316543166431674316843169431704317143172431734317443175431764317743178431794318043181431824318343184431854318643187431884318943190431914319243193431944319543196431974319843199432004320143202432034320443205432064320743208432094321043211432124321343214432154321643217432184321943220432214322243223432244322543226432274322843229432304323143232432334323443235432364323743238432394324043241432424324343244432454324643247432484324943250432514325243253432544325543256432574325843259432604326143262432634326443265432664326743268432694327043271432724327343274432754327643277432784327943280432814328243283432844328543286432874328843289432904329143292432934329443295432964329743298432994330043301433024330343304433054330643307433084330943310433114331243313433144331543316433174331843319433204332143322433234332443325433264332743328433294333043331433324333343334433354333643337433384333943340433414334243343433444334543346433474334843349433504335143352433534335443355433564335743358433594336043361433624336343364433654336643367433684336943370433714337243373433744337543376433774337843379433804338143382433834338443385433864338743388433894339043391433924339343394433954339643397433984339943400434014340243403434044340543406434074340843409434104341143412434134341443415434164341743418434194342043421434224342343424434254342643427434284342943430434314343243433434344343543436434374343843439434404344143442434434344443445434464344743448434494345043451434524345343454434554345643457434584345943460434614346243463434644346543466434674346843469434704347143472434734347443475434764347743478434794348043481434824348343484434854348643487434884348943490434914349243493434944349543496434974349843499435004350143502435034350443505435064350743508435094351043511435124351343514435154351643517435184351943520435214352243523435244352543526435274352843529435304353143532435334353443535435364353743538435394354043541435424354343544435454354643547435484354943550435514355243553435544355543556435574355843559435604356143562435634356443565435664356743568435694357043571435724357343574435754357643577435784357943580435814358243583435844358543586435874358843589435904359143592435934359443595435964359743598435994360043601436024360343604436054360643607436084360943610436114361243613436144361543616436174361843619436204362143622436234362443625436264362743628436294363043631436324363343634436354363643637436384363943640436414364243643436444364543646436474364843649436504365143652436534365443655436564365743658436594366043661436624366343664436654366643667436684366943670436714367243673436744367543676436774367843679436804368143682436834368443685436864368743688436894369043691436924369343694436954369643697436984369943700437014370243703437044370543706437074370843709437104371143712437134371443715437164371743718437194372043721437224372343724437254372643727437284372943730437314373243733437344373543736437374373843739437404374143742437434374443745437464374743748437494375043751437524375343754437554375643757437584375943760437614376243763437644376543766437674376843769437704377143772437734377443775437764377743778437794378043781437824378343784437854378643787437884378943790437914379243793437944379543796437974379843799438004380143802438034380443805438064380743808438094381043811438124381343814438154381643817438184381943820438214382243823438244382543826438274382843829438304383143832438334383443835438364383743838438394384043841438424384343844438454384643847438484384943850438514385243853438544385543856438574385843859438604386143862438634386443865438664386743868438694387043871438724387343874438754387643877438784387943880438814388243883438844388543886438874388843889438904389143892438934389443895438964389743898438994390043901439024390343904439054390643907439084390943910439114391243913439144391543916439174391843919439204392143922439234392443925439264392743928439294393043931439324393343934439354393643937439384393943940439414394243943439444394543946439474394843949439504395143952439534395443955439564395743958439594396043961439624396343964439654396643967439684396943970439714397243973439744397543976439774397843979439804398143982439834398443985439864398743988439894399043991439924399343994439954399643997439984399944000440014400244003440044400544006440074400844009440104401144012440134401444015440164401744018440194402044021440224402344024440254402644027440284402944030440314403244033440344403544036440374403844039440404404144042440434404444045440464404744048440494405044051440524405344054440554405644057440584405944060440614406244063440644406544066440674406844069440704407144072440734407444075440764407744078440794408044081440824408344084440854408644087440884408944090440914409244093440944409544096440974409844099441004410144102441034410444105441064410744108441094411044111441124411344114441154411644117441184411944120441214412244123441244412544126441274412844129441304413144132441334413444135441364413744138441394414044141441424414344144441454414644147441484414944150441514415244153441544415544156441574415844159441604416144162441634416444165441664416744168441694417044171441724417344174441754417644177441784417944180441814418244183441844418544186441874418844189441904419144192441934419444195441964419744198441994420044201442024420344204442054420644207442084420944210442114421244213442144421544216442174421844219442204422144222442234422444225442264422744228442294423044231442324423344234442354423644237442384423944240442414424244243442444424544246442474424844249442504425144252442534425444255442564425744258442594426044261442624426344264442654426644267442684426944270442714427244273442744427544276442774427844279442804428144282442834428444285442864428744288442894429044291442924429344294442954429644297442984429944300443014430244303443044430544306443074430844309443104431144312443134431444315443164431744318443194432044321443224432344324443254432644327443284432944330443314433244333443344433544336443374433844339443404434144342443434434444345443464434744348443494435044351443524435344354443554435644357443584435944360443614436244363443644436544366443674436844369443704437144372443734437444375443764437744378443794438044381443824438344384443854438644387443884438944390443914439244393443944439544396443974439844399444004440144402444034440444405444064440744408444094441044411444124441344414444154441644417444184441944420444214442244423444244442544426444274442844429444304443144432444334443444435444364443744438444394444044441444424444344444444454444644447444484444944450444514445244453444544445544456444574445844459444604446144462444634446444465444664446744468444694447044471444724447344474444754447644477444784447944480444814448244483444844448544486444874448844489444904449144492444934449444495444964449744498444994450044501445024450344504445054450644507445084450944510445114451244513445144451544516445174451844519445204452144522445234452444525445264452744528445294453044531445324453344534445354453644537445384453944540445414454244543445444454544546445474454844549445504455144552445534455444555445564455744558445594456044561445624456344564445654456644567445684456944570445714457244573445744457544576445774457844579445804458144582445834458444585445864458744588445894459044591445924459344594445954459644597445984459944600446014460244603446044460544606446074460844609446104461144612446134461444615446164461744618446194462044621446224462344624446254462644627446284462944630446314463244633446344463544636446374463844639446404464144642446434464444645446464464744648446494465044651446524465344654446554465644657446584465944660446614466244663446644466544666446674466844669446704467144672446734467444675446764467744678446794468044681446824468344684446854468644687446884468944690446914469244693446944469544696446974469844699447004470144702447034470444705447064470744708447094471044711447124471344714447154471644717447184471944720447214472244723447244472544726447274472844729447304473144732447334473444735447364473744738447394474044741447424474344744447454474644747447484474944750447514475244753447544475544756447574475844759447604476144762447634476444765447664476744768447694477044771447724477344774447754477644777447784477944780447814478244783447844478544786447874478844789447904479144792447934479444795447964479744798447994480044801448024480344804448054480644807448084480944810448114481244813448144481544816448174481844819448204482144822448234482444825448264482744828448294483044831448324483344834448354483644837448384483944840448414484244843448444484544846448474484844849448504485144852448534485444855448564485744858448594486044861448624486344864448654486644867448684486944870448714487244873448744487544876448774487844879448804488144882448834488444885448864488744888448894489044891448924489344894448954489644897448984489944900449014490244903449044490544906449074490844909449104491144912449134491444915449164491744918449194492044921449224492344924449254492644927449284492944930449314493244933449344493544936449374493844939449404494144942449434494444945449464494744948449494495044951449524495344954449554495644957449584495944960449614496244963449644496544966449674496844969449704497144972449734497444975449764497744978449794498044981449824498344984449854498644987449884498944990449914499244993449944499544996449974499844999450004500145002450034500445005450064500745008450094501045011450124501345014450154501645017450184501945020450214502245023450244502545026450274502845029450304503145032450334503445035450364503745038450394504045041450424504345044450454504645047450484504945050450514505245053450544505545056450574505845059450604506145062450634506445065450664506745068450694507045071450724507345074450754507645077450784507945080450814508245083450844508545086450874508845089450904509145092450934509445095450964509745098450994510045101451024510345104451054510645107451084510945110451114511245113451144511545116451174511845119451204512145122451234512445125451264512745128451294513045131451324513345134451354513645137451384513945140451414514245143451444514545146451474514845149451504515145152451534515445155451564515745158451594516045161451624516345164451654516645167451684516945170451714517245173451744517545176451774517845179451804518145182451834518445185451864518745188451894519045191451924519345194451954519645197451984519945200452014520245203452044520545206452074520845209452104521145212452134521445215452164521745218452194522045221452224522345224452254522645227452284522945230452314523245233452344523545236452374523845239452404524145242452434524445245452464524745248452494525045251452524525345254452554525645257452584525945260452614526245263452644526545266452674526845269452704527145272452734527445275452764527745278452794528045281452824528345284452854528645287452884528945290452914529245293452944529545296452974529845299453004530145302453034530445305453064530745308453094531045311453124531345314453154531645317453184531945320453214532245323453244532545326453274532845329453304533145332453334533445335453364533745338453394534045341453424534345344453454534645347453484534945350453514535245353453544535545356453574535845359453604536145362453634536445365453664536745368453694537045371453724537345374453754537645377453784537945380453814538245383453844538545386453874538845389453904539145392453934539445395453964539745398453994540045401454024540345404454054540645407454084540945410454114541245413454144541545416454174541845419454204542145422454234542445425454264542745428454294543045431454324543345434454354543645437454384543945440454414544245443454444544545446454474544845449454504545145452454534545445455454564545745458454594546045461454624546345464454654546645467454684546945470454714547245473454744547545476454774547845479454804548145482454834548445485454864548745488454894549045491454924549345494454954549645497454984549945500455014550245503455044550545506455074550845509455104551145512455134551445515455164551745518455194552045521455224552345524455254552645527455284552945530455314553245533455344553545536455374553845539455404554145542455434554445545455464554745548455494555045551455524555345554455554555645557455584555945560455614556245563455644556545566455674556845569455704557145572455734557445575455764557745578455794558045581455824558345584455854558645587455884558945590455914559245593455944559545596455974559845599456004560145602456034560445605456064560745608456094561045611456124561345614456154561645617456184561945620456214562245623456244562545626456274562845629456304563145632456334563445635456364563745638456394564045641456424564345644456454564645647456484564945650456514565245653456544565545656456574565845659456604566145662456634566445665456664566745668456694567045671456724567345674456754567645677456784567945680456814568245683456844568545686456874568845689456904569145692456934569445695456964569745698456994570045701457024570345704457054570645707457084570945710457114571245713457144571545716457174571845719457204572145722457234572445725457264572745728457294573045731457324573345734457354573645737457384573945740457414574245743457444574545746457474574845749457504575145752457534575445755457564575745758457594576045761457624576345764457654576645767457684576945770457714577245773457744577545776457774577845779457804578145782457834578445785457864578745788457894579045791457924579345794457954579645797457984579945800458014580245803458044580545806458074580845809458104581145812458134581445815458164581745818458194582045821458224582345824458254582645827458284582945830458314583245833458344583545836458374583845839458404584145842458434584445845458464584745848458494585045851458524585345854458554585645857458584585945860458614586245863458644586545866458674586845869458704587145872458734587445875458764587745878458794588045881458824588345884458854588645887458884588945890458914589245893458944589545896458974589845899459004590145902459034590445905459064590745908459094591045911459124591345914459154591645917459184591945920459214592245923459244592545926459274592845929459304593145932459334593445935459364593745938459394594045941459424594345944459454594645947459484594945950459514595245953459544595545956459574595845959459604596145962459634596445965459664596745968459694597045971459724597345974459754597645977459784597945980459814598245983459844598545986459874598845989459904599145992459934599445995459964599745998459994600046001460024600346004460054600646007460084600946010460114601246013460144601546016460174601846019460204602146022460234602446025460264602746028460294603046031460324603346034460354603646037460384603946040460414604246043460444604546046460474604846049460504605146052460534605446055460564605746058460594606046061460624606346064460654606646067460684606946070460714607246073460744607546076460774607846079460804608146082460834608446085460864608746088460894609046091460924609346094460954609646097460984609946100461014610246103461044610546106461074610846109461104611146112461134611446115461164611746118461194612046121461224612346124461254612646127461284612946130461314613246133461344613546136461374613846139461404614146142461434614446145461464614746148461494615046151461524615346154461554615646157461584615946160461614616246163461644616546166461674616846169461704617146172461734617446175461764617746178461794618046181461824618346184461854618646187461884618946190461914619246193461944619546196461974619846199462004620146202462034620446205462064620746208462094621046211462124621346214462154621646217462184621946220462214622246223462244622546226462274622846229462304623146232462334623446235462364623746238462394624046241462424624346244462454624646247462484624946250462514625246253462544625546256462574625846259462604626146262462634626446265462664626746268462694627046271462724627346274462754627646277462784627946280462814628246283462844628546286462874628846289462904629146292462934629446295462964629746298462994630046301463024630346304463054630646307463084630946310463114631246313463144631546316463174631846319463204632146322463234632446325463264632746328463294633046331463324633346334463354633646337463384633946340463414634246343463444634546346463474634846349463504635146352463534635446355463564635746358463594636046361463624636346364463654636646367463684636946370463714637246373463744637546376463774637846379463804638146382463834638446385463864638746388463894639046391463924639346394463954639646397463984639946400464014640246403464044640546406464074640846409464104641146412464134641446415464164641746418464194642046421464224642346424464254642646427464284642946430464314643246433464344643546436464374643846439464404644146442464434644446445464464644746448464494645046451464524645346454464554645646457464584645946460464614646246463464644646546466464674646846469464704647146472464734647446475464764647746478464794648046481464824648346484464854648646487464884648946490464914649246493464944649546496464974649846499465004650146502465034650446505465064650746508465094651046511465124651346514465154651646517465184651946520465214652246523465244652546526465274652846529465304653146532465334653446535465364653746538465394654046541465424654346544465454654646547465484654946550465514655246553465544655546556465574655846559465604656146562465634656446565465664656746568465694657046571465724657346574465754657646577465784657946580465814658246583465844658546586465874658846589465904659146592465934659446595465964659746598465994660046601466024660346604466054660646607466084660946610466114661246613466144661546616466174661846619466204662146622466234662446625466264662746628466294663046631466324663346634466354663646637466384663946640466414664246643466444664546646466474664846649466504665146652466534665446655466564665746658466594666046661466624666346664466654666646667466684666946670466714667246673466744667546676466774667846679466804668146682466834668446685466864668746688466894669046691466924669346694466954669646697466984669946700467014670246703467044670546706467074670846709467104671146712467134671446715467164671746718467194672046721467224672346724467254672646727467284672946730467314673246733467344673546736467374673846739467404674146742467434674446745467464674746748467494675046751467524675346754467554675646757467584675946760467614676246763467644676546766467674676846769467704677146772467734677446775467764677746778467794678046781467824678346784467854678646787467884678946790467914679246793467944679546796467974679846799468004680146802468034680446805468064680746808468094681046811468124681346814468154681646817468184681946820468214682246823468244682546826468274682846829468304683146832468334683446835468364683746838468394684046841468424684346844468454684646847468484684946850468514685246853468544685546856468574685846859468604686146862468634686446865468664686746868468694687046871468724687346874468754687646877468784687946880468814688246883468844688546886468874688846889468904689146892468934689446895468964689746898468994690046901469024690346904469054690646907469084690946910469114691246913469144691546916469174691846919469204692146922469234692446925469264692746928469294693046931469324693346934469354693646937469384693946940469414694246943469444694546946469474694846949469504695146952469534695446955469564695746958469594696046961469624696346964469654696646967469684696946970469714697246973469744697546976469774697846979469804698146982469834698446985469864698746988469894699046991469924699346994469954699646997469984699947000470014700247003470044700547006470074700847009470104701147012470134701447015470164701747018470194702047021470224702347024470254702647027470284702947030470314703247033470344703547036470374703847039470404704147042470434704447045470464704747048470494705047051470524705347054470554705647057470584705947060470614706247063470644706547066470674706847069470704707147072470734707447075470764707747078470794708047081470824708347084470854708647087470884708947090470914709247093470944709547096470974709847099471004710147102471034710447105471064710747108471094711047111471124711347114471154711647117471184711947120471214712247123471244712547126471274712847129471304713147132471334713447135471364713747138471394714047141471424714347144471454714647147471484714947150471514715247153471544715547156471574715847159471604716147162471634716447165471664716747168471694717047171471724717347174471754717647177471784717947180471814718247183471844718547186471874718847189471904719147192471934719447195471964719747198471994720047201472024720347204472054720647207472084720947210472114721247213472144721547216472174721847219472204722147222472234722447225472264722747228472294723047231472324723347234472354723647237472384723947240472414724247243472444724547246472474724847249472504725147252472534725447255472564725747258472594726047261472624726347264472654726647267472684726947270472714727247273472744727547276472774727847279472804728147282472834728447285472864728747288472894729047291472924729347294472954729647297472984729947300473014730247303473044730547306473074730847309473104731147312473134731447315473164731747318473194732047321473224732347324473254732647327473284732947330473314733247333473344733547336473374733847339473404734147342473434734447345473464734747348473494735047351473524735347354473554735647357473584735947360473614736247363473644736547366473674736847369473704737147372473734737447375473764737747378473794738047381473824738347384473854738647387473884738947390473914739247393473944739547396473974739847399474004740147402474034740447405474064740747408474094741047411474124741347414474154741647417474184741947420474214742247423474244742547426474274742847429474304743147432474334743447435474364743747438474394744047441474424744347444474454744647447474484744947450474514745247453474544745547456474574745847459474604746147462474634746447465474664746747468474694747047471474724747347474474754747647477474784747947480474814748247483474844748547486474874748847489474904749147492474934749447495474964749747498474994750047501475024750347504475054750647507475084750947510475114751247513475144751547516475174751847519475204752147522475234752447525475264752747528475294753047531475324753347534475354753647537475384753947540475414754247543475444754547546475474754847549475504755147552475534755447555475564755747558475594756047561475624756347564475654756647567475684756947570475714757247573475744757547576475774757847579475804758147582475834758447585475864758747588475894759047591475924759347594475954759647597475984759947600476014760247603476044760547606476074760847609476104761147612476134761447615476164761747618476194762047621476224762347624476254762647627476284762947630476314763247633476344763547636476374763847639476404764147642476434764447645476464764747648476494765047651476524765347654476554765647657476584765947660476614766247663476644766547666476674766847669476704767147672476734767447675476764767747678476794768047681476824768347684476854768647687476884768947690476914769247693476944769547696476974769847699477004770147702477034770447705477064770747708477094771047711477124771347714477154771647717477184771947720477214772247723477244772547726477274772847729477304773147732477334773447735477364773747738477394774047741477424774347744477454774647747477484774947750477514775247753477544775547756477574775847759477604776147762477634776447765477664776747768477694777047771477724777347774477754777647777477784777947780477814778247783477844778547786477874778847789477904779147792477934779447795477964779747798477994780047801478024780347804478054780647807478084780947810478114781247813478144781547816478174781847819478204782147822478234782447825478264782747828478294783047831478324783347834478354783647837478384783947840478414784247843478444784547846478474784847849478504785147852478534785447855478564785747858478594786047861478624786347864478654786647867478684786947870478714787247873478744787547876478774787847879478804788147882478834788447885478864788747888478894789047891478924789347894478954789647897478984789947900479014790247903479044790547906479074790847909479104791147912479134791447915479164791747918479194792047921479224792347924479254792647927479284792947930479314793247933479344793547936479374793847939479404794147942479434794447945479464794747948479494795047951479524795347954479554795647957479584795947960479614796247963479644796547966479674796847969479704797147972479734797447975479764797747978479794798047981479824798347984479854798647987479884798947990479914799247993479944799547996479974799847999480004800148002480034800448005480064800748008480094801048011480124801348014480154801648017480184801948020480214802248023480244802548026480274802848029480304803148032480334803448035480364803748038480394804048041480424804348044480454804648047480484804948050480514805248053480544805548056480574805848059480604806148062480634806448065480664806748068480694807048071480724807348074480754807648077480784807948080480814808248083480844808548086480874808848089480904809148092480934809448095480964809748098480994810048101481024810348104481054810648107481084810948110481114811248113481144811548116481174811848119481204812148122481234812448125481264812748128481294813048131481324813348134481354813648137481384813948140481414814248143481444814548146481474814848149481504815148152481534815448155481564815748158481594816048161481624816348164481654816648167481684816948170481714817248173481744817548176481774817848179481804818148182481834818448185481864818748188481894819048191481924819348194481954819648197481984819948200482014820248203482044820548206482074820848209482104821148212482134821448215482164821748218482194822048221482224822348224482254822648227482284822948230482314823248233482344823548236482374823848239482404824148242482434824448245482464824748248482494825048251482524825348254482554825648257482584825948260482614826248263482644826548266482674826848269482704827148272482734827448275482764827748278482794828048281482824828348284482854828648287482884828948290482914829248293482944829548296482974829848299483004830148302483034830448305483064830748308483094831048311483124831348314483154831648317483184831948320483214832248323483244832548326483274832848329483304833148332483334833448335483364833748338483394834048341483424834348344483454834648347483484834948350483514835248353483544835548356483574835848359483604836148362483634836448365483664836748368483694837048371483724837348374483754837648377483784837948380483814838248383483844838548386483874838848389483904839148392483934839448395483964839748398483994840048401484024840348404484054840648407484084840948410484114841248413484144841548416484174841848419484204842148422484234842448425484264842748428484294843048431484324843348434484354843648437484384843948440484414844248443484444844548446484474844848449484504845148452484534845448455484564845748458484594846048461484624846348464484654846648467484684846948470484714847248473484744847548476484774847848479484804848148482484834848448485484864848748488484894849048491484924849348494484954849648497484984849948500485014850248503485044850548506485074850848509485104851148512485134851448515485164851748518485194852048521485224852348524485254852648527485284852948530485314853248533485344853548536485374853848539485404854148542485434854448545485464854748548485494855048551485524855348554485554855648557485584855948560485614856248563485644856548566485674856848569485704857148572485734857448575485764857748578485794858048581485824858348584485854858648587485884858948590485914859248593485944859548596485974859848599486004860148602486034860448605486064860748608486094861048611486124861348614486154861648617486184861948620486214862248623486244862548626486274862848629486304863148632486334863448635486364863748638486394864048641486424864348644486454864648647486484864948650486514865248653486544865548656486574865848659486604866148662486634866448665486664866748668486694867048671486724867348674486754867648677486784867948680486814868248683486844868548686486874868848689486904869148692486934869448695486964869748698486994870048701487024870348704487054870648707487084870948710487114871248713487144871548716487174871848719487204872148722487234872448725487264872748728487294873048731487324873348734487354873648737487384873948740487414874248743487444874548746487474874848749487504875148752487534875448755487564875748758487594876048761487624876348764487654876648767487684876948770487714877248773487744877548776487774877848779487804878148782487834878448785487864878748788487894879048791487924879348794487954879648797487984879948800488014880248803488044880548806488074880848809488104881148812488134881448815488164881748818488194882048821488224882348824488254882648827488284882948830488314883248833488344883548836488374883848839488404884148842488434884448845488464884748848488494885048851488524885348854488554885648857488584885948860488614886248863488644886548866488674886848869488704887148872488734887448875488764887748878488794888048881488824888348884488854888648887488884888948890488914889248893488944889548896488974889848899489004890148902489034890448905489064890748908489094891048911489124891348914489154891648917489184891948920489214892248923489244892548926489274892848929489304893148932489334893448935489364893748938489394894048941489424894348944489454894648947489484894948950489514895248953489544895548956489574895848959489604896148962489634896448965489664896748968489694897048971489724897348974489754897648977489784897948980489814898248983489844898548986489874898848989489904899148992489934899448995489964899748998489994900049001490024900349004490054900649007490084900949010490114901249013490144901549016490174901849019490204902149022490234902449025490264902749028490294903049031490324903349034490354903649037490384903949040490414904249043490444904549046490474904849049490504905149052490534905449055490564905749058490594906049061490624906349064490654906649067490684906949070490714907249073490744907549076490774907849079490804908149082490834908449085490864908749088490894909049091490924909349094490954909649097490984909949100491014910249103491044910549106491074910849109491104911149112491134911449115491164911749118491194912049121491224912349124491254912649127491284912949130491314913249133491344913549136491374913849139491404914149142491434914449145491464914749148491494915049151491524915349154
  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 = '105';
  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 ( minVal, maxVal ) {
  482. this.x = Math.max( minVal, Math.min( maxVal, this.x ) );
  483. this.y = Math.max( minVal, Math.min( maxVal, this.y ) );
  484. return this;
  485. },
  486. clampLength: function ( min, max ) {
  487. var length = this.length();
  488. return this.divideScalar( length || 1 ).multiplyScalar( Math.max( min, Math.min( max, length ) ) );
  489. },
  490. floor: function () {
  491. this.x = Math.floor( this.x );
  492. this.y = Math.floor( this.y );
  493. return this;
  494. },
  495. ceil: function () {
  496. this.x = Math.ceil( this.x );
  497. this.y = Math.ceil( this.y );
  498. return this;
  499. },
  500. round: function () {
  501. this.x = Math.round( this.x );
  502. this.y = Math.round( this.y );
  503. return this;
  504. },
  505. roundToZero: function () {
  506. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  507. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  508. return this;
  509. },
  510. negate: function () {
  511. this.x = - this.x;
  512. this.y = - this.y;
  513. return this;
  514. },
  515. dot: function ( v ) {
  516. return this.x * v.x + this.y * v.y;
  517. },
  518. cross: function ( v ) {
  519. return this.x * v.y - this.y * v.x;
  520. },
  521. lengthSq: function () {
  522. return this.x * this.x + this.y * this.y;
  523. },
  524. length: function () {
  525. return Math.sqrt( this.x * this.x + this.y * this.y );
  526. },
  527. manhattanLength: function () {
  528. return Math.abs( this.x ) + Math.abs( this.y );
  529. },
  530. normalize: function () {
  531. return this.divideScalar( this.length() || 1 );
  532. },
  533. angle: function () {
  534. // computes the angle in radians with respect to the positive x-axis
  535. var angle = Math.atan2( this.y, this.x );
  536. if ( angle < 0 ) angle += 2 * Math.PI;
  537. return angle;
  538. },
  539. distanceTo: function ( v ) {
  540. return Math.sqrt( this.distanceToSquared( v ) );
  541. },
  542. distanceToSquared: function ( v ) {
  543. var dx = this.x - v.x, dy = this.y - v.y;
  544. return dx * dx + dy * dy;
  545. },
  546. manhattanDistanceTo: function ( v ) {
  547. return Math.abs( this.x - v.x ) + Math.abs( this.y - v.y );
  548. },
  549. setLength: function ( length ) {
  550. return this.normalize().multiplyScalar( length );
  551. },
  552. lerp: function ( v, alpha ) {
  553. this.x += ( v.x - this.x ) * alpha;
  554. this.y += ( v.y - this.y ) * alpha;
  555. return this;
  556. },
  557. lerpVectors: function ( v1, v2, alpha ) {
  558. return this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  559. },
  560. equals: function ( v ) {
  561. return ( ( v.x === this.x ) && ( v.y === this.y ) );
  562. },
  563. fromArray: function ( array, offset ) {
  564. if ( offset === undefined ) offset = 0;
  565. this.x = array[ offset ];
  566. this.y = array[ offset + 1 ];
  567. return this;
  568. },
  569. toArray: function ( array, offset ) {
  570. if ( array === undefined ) array = [];
  571. if ( offset === undefined ) offset = 0;
  572. array[ offset ] = this.x;
  573. array[ offset + 1 ] = this.y;
  574. return array;
  575. },
  576. fromBufferAttribute: function ( attribute, index, offset ) {
  577. if ( offset !== undefined ) {
  578. console.warn( 'THREE.Vector2: offset has been removed from .fromBufferAttribute().' );
  579. }
  580. this.x = attribute.getX( index );
  581. this.y = attribute.getY( index );
  582. return this;
  583. },
  584. rotateAround: function ( center, angle ) {
  585. var c = Math.cos( angle ), s = Math.sin( angle );
  586. var x = this.x - center.x;
  587. var y = this.y - center.y;
  588. this.x = x * c - y * s + center.x;
  589. this.y = x * s + y * c + center.y;
  590. return this;
  591. }
  592. } );
  593. /**
  594. * @author mikael emtinger / http://gomo.se/
  595. * @author alteredq / http://alteredqualia.com/
  596. * @author WestLangley / http://github.com/WestLangley
  597. * @author bhouston / http://clara.io
  598. */
  599. function Quaternion( x, y, z, w ) {
  600. this._x = x || 0;
  601. this._y = y || 0;
  602. this._z = z || 0;
  603. this._w = ( w !== undefined ) ? w : 1;
  604. }
  605. Object.assign( Quaternion, {
  606. slerp: function ( qa, qb, qm, t ) {
  607. return qm.copy( qa ).slerp( qb, t );
  608. },
  609. slerpFlat: function ( dst, dstOffset, src0, srcOffset0, src1, srcOffset1, t ) {
  610. // fuzz-free, array-based Quaternion SLERP operation
  611. var x0 = src0[ srcOffset0 + 0 ],
  612. y0 = src0[ srcOffset0 + 1 ],
  613. z0 = src0[ srcOffset0 + 2 ],
  614. w0 = src0[ srcOffset0 + 3 ],
  615. x1 = src1[ srcOffset1 + 0 ],
  616. y1 = src1[ srcOffset1 + 1 ],
  617. z1 = src1[ srcOffset1 + 2 ],
  618. w1 = src1[ srcOffset1 + 3 ];
  619. if ( w0 !== w1 || x0 !== x1 || y0 !== y1 || z0 !== z1 ) {
  620. var s = 1 - t,
  621. cos = x0 * x1 + y0 * y1 + z0 * z1 + w0 * w1,
  622. dir = ( cos >= 0 ? 1 : - 1 ),
  623. sqrSin = 1 - cos * cos;
  624. // Skip the Slerp for tiny steps to avoid numeric problems:
  625. if ( sqrSin > Number.EPSILON ) {
  626. var sin = Math.sqrt( sqrSin ),
  627. len = Math.atan2( sin, cos * dir );
  628. s = Math.sin( s * len ) / sin;
  629. t = Math.sin( t * len ) / sin;
  630. }
  631. var tDir = t * dir;
  632. x0 = x0 * s + x1 * tDir;
  633. y0 = y0 * s + y1 * tDir;
  634. z0 = z0 * s + z1 * tDir;
  635. w0 = w0 * s + w1 * tDir;
  636. // Normalize in case we just did a lerp:
  637. if ( s === 1 - t ) {
  638. var f = 1 / Math.sqrt( x0 * x0 + y0 * y0 + z0 * z0 + w0 * w0 );
  639. x0 *= f;
  640. y0 *= f;
  641. z0 *= f;
  642. w0 *= f;
  643. }
  644. }
  645. dst[ dstOffset ] = x0;
  646. dst[ dstOffset + 1 ] = y0;
  647. dst[ dstOffset + 2 ] = z0;
  648. dst[ dstOffset + 3 ] = w0;
  649. }
  650. } );
  651. Object.defineProperties( Quaternion.prototype, {
  652. x: {
  653. get: function () {
  654. return this._x;
  655. },
  656. set: function ( value ) {
  657. this._x = value;
  658. this.onChangeCallback();
  659. }
  660. },
  661. y: {
  662. get: function () {
  663. return this._y;
  664. },
  665. set: function ( value ) {
  666. this._y = value;
  667. this.onChangeCallback();
  668. }
  669. },
  670. z: {
  671. get: function () {
  672. return this._z;
  673. },
  674. set: function ( value ) {
  675. this._z = value;
  676. this.onChangeCallback();
  677. }
  678. },
  679. w: {
  680. get: function () {
  681. return this._w;
  682. },
  683. set: function ( value ) {
  684. this._w = value;
  685. this.onChangeCallback();
  686. }
  687. }
  688. } );
  689. Object.assign( Quaternion.prototype, {
  690. isQuaternion: true,
  691. set: function ( x, y, z, w ) {
  692. this._x = x;
  693. this._y = y;
  694. this._z = z;
  695. this._w = w;
  696. this.onChangeCallback();
  697. return this;
  698. },
  699. clone: function () {
  700. return new this.constructor( this._x, this._y, this._z, this._w );
  701. },
  702. copy: function ( quaternion ) {
  703. this._x = quaternion.x;
  704. this._y = quaternion.y;
  705. this._z = quaternion.z;
  706. this._w = quaternion.w;
  707. this.onChangeCallback();
  708. return this;
  709. },
  710. setFromEuler: function ( euler, update ) {
  711. if ( ! ( euler && euler.isEuler ) ) {
  712. throw new Error( 'THREE.Quaternion: .setFromEuler() now expects an Euler rotation rather than a Vector3 and order.' );
  713. }
  714. var x = euler._x, y = euler._y, z = euler._z, order = euler.order;
  715. // http://www.mathworks.com/matlabcentral/fileexchange/
  716. // 20696-function-to-convert-between-dcm-euler-angles-quaternions-and-euler-vectors/
  717. // content/SpinCalc.m
  718. var cos = Math.cos;
  719. var sin = Math.sin;
  720. var c1 = cos( x / 2 );
  721. var c2 = cos( y / 2 );
  722. var c3 = cos( z / 2 );
  723. var s1 = sin( x / 2 );
  724. var s2 = sin( y / 2 );
  725. var s3 = sin( z / 2 );
  726. if ( order === 'XYZ' ) {
  727. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  728. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  729. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  730. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  731. } else if ( order === 'YXZ' ) {
  732. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  733. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  734. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  735. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  736. } else if ( order === 'ZXY' ) {
  737. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  738. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  739. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  740. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  741. } else if ( order === 'ZYX' ) {
  742. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  743. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  744. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  745. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  746. } else if ( order === 'YZX' ) {
  747. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  748. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  749. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  750. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  751. } else if ( order === 'XZY' ) {
  752. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  753. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  754. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  755. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  756. }
  757. if ( update !== false ) this.onChangeCallback();
  758. return this;
  759. },
  760. setFromAxisAngle: function ( axis, angle ) {
  761. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToQuaternion/index.htm
  762. // assumes axis is normalized
  763. var halfAngle = angle / 2, s = Math.sin( halfAngle );
  764. this._x = axis.x * s;
  765. this._y = axis.y * s;
  766. this._z = axis.z * s;
  767. this._w = Math.cos( halfAngle );
  768. this.onChangeCallback();
  769. return this;
  770. },
  771. setFromRotationMatrix: function ( m ) {
  772. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm
  773. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  774. var te = m.elements,
  775. m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ],
  776. m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ],
  777. m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ],
  778. trace = m11 + m22 + m33,
  779. s;
  780. if ( trace > 0 ) {
  781. s = 0.5 / Math.sqrt( trace + 1.0 );
  782. this._w = 0.25 / s;
  783. this._x = ( m32 - m23 ) * s;
  784. this._y = ( m13 - m31 ) * s;
  785. this._z = ( m21 - m12 ) * s;
  786. } else if ( m11 > m22 && m11 > m33 ) {
  787. s = 2.0 * Math.sqrt( 1.0 + m11 - m22 - m33 );
  788. this._w = ( m32 - m23 ) / s;
  789. this._x = 0.25 * s;
  790. this._y = ( m12 + m21 ) / s;
  791. this._z = ( m13 + m31 ) / s;
  792. } else if ( m22 > m33 ) {
  793. s = 2.0 * Math.sqrt( 1.0 + m22 - m11 - m33 );
  794. this._w = ( m13 - m31 ) / s;
  795. this._x = ( m12 + m21 ) / s;
  796. this._y = 0.25 * s;
  797. this._z = ( m23 + m32 ) / s;
  798. } else {
  799. s = 2.0 * Math.sqrt( 1.0 + m33 - m11 - m22 );
  800. this._w = ( m21 - m12 ) / s;
  801. this._x = ( m13 + m31 ) / s;
  802. this._y = ( m23 + m32 ) / s;
  803. this._z = 0.25 * s;
  804. }
  805. this.onChangeCallback();
  806. return this;
  807. },
  808. setFromUnitVectors: function ( vFrom, vTo ) {
  809. // assumes direction vectors vFrom and vTo are normalized
  810. var EPS = 0.000001;
  811. var r = vFrom.dot( vTo ) + 1;
  812. if ( r < EPS ) {
  813. r = 0;
  814. if ( Math.abs( vFrom.x ) > Math.abs( vFrom.z ) ) {
  815. this._x = - vFrom.y;
  816. this._y = vFrom.x;
  817. this._z = 0;
  818. this._w = r;
  819. } else {
  820. this._x = 0;
  821. this._y = - vFrom.z;
  822. this._z = vFrom.y;
  823. this._w = r;
  824. }
  825. } else {
  826. // crossVectors( vFrom, vTo ); // inlined to avoid cyclic dependency on Vector3
  827. this._x = vFrom.y * vTo.z - vFrom.z * vTo.y;
  828. this._y = vFrom.z * vTo.x - vFrom.x * vTo.z;
  829. this._z = vFrom.x * vTo.y - vFrom.y * vTo.x;
  830. this._w = r;
  831. }
  832. return this.normalize();
  833. },
  834. angleTo: function ( q ) {
  835. return 2 * Math.acos( Math.abs( _Math.clamp( this.dot( q ), - 1, 1 ) ) );
  836. },
  837. rotateTowards: function ( q, step ) {
  838. var angle = this.angleTo( q );
  839. if ( angle === 0 ) return this;
  840. var t = Math.min( 1, step / angle );
  841. this.slerp( q, t );
  842. return this;
  843. },
  844. inverse: function () {
  845. // quaternion is assumed to have unit length
  846. return this.conjugate();
  847. },
  848. conjugate: function () {
  849. this._x *= - 1;
  850. this._y *= - 1;
  851. this._z *= - 1;
  852. this.onChangeCallback();
  853. return this;
  854. },
  855. dot: function ( v ) {
  856. return this._x * v._x + this._y * v._y + this._z * v._z + this._w * v._w;
  857. },
  858. lengthSq: function () {
  859. return this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w;
  860. },
  861. length: function () {
  862. return Math.sqrt( this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w );
  863. },
  864. normalize: function () {
  865. var l = this.length();
  866. if ( l === 0 ) {
  867. this._x = 0;
  868. this._y = 0;
  869. this._z = 0;
  870. this._w = 1;
  871. } else {
  872. l = 1 / l;
  873. this._x = this._x * l;
  874. this._y = this._y * l;
  875. this._z = this._z * l;
  876. this._w = this._w * l;
  877. }
  878. this.onChangeCallback();
  879. return this;
  880. },
  881. multiply: function ( q, p ) {
  882. if ( p !== undefined ) {
  883. console.warn( 'THREE.Quaternion: .multiply() now only accepts one argument. Use .multiplyQuaternions( a, b ) instead.' );
  884. return this.multiplyQuaternions( q, p );
  885. }
  886. return this.multiplyQuaternions( this, q );
  887. },
  888. premultiply: function ( q ) {
  889. return this.multiplyQuaternions( q, this );
  890. },
  891. multiplyQuaternions: function ( a, b ) {
  892. // from http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/code/index.htm
  893. var qax = a._x, qay = a._y, qaz = a._z, qaw = a._w;
  894. var qbx = b._x, qby = b._y, qbz = b._z, qbw = b._w;
  895. this._x = qax * qbw + qaw * qbx + qay * qbz - qaz * qby;
  896. this._y = qay * qbw + qaw * qby + qaz * qbx - qax * qbz;
  897. this._z = qaz * qbw + qaw * qbz + qax * qby - qay * qbx;
  898. this._w = qaw * qbw - qax * qbx - qay * qby - qaz * qbz;
  899. this.onChangeCallback();
  900. return this;
  901. },
  902. slerp: function ( qb, t ) {
  903. if ( t === 0 ) return this;
  904. if ( t === 1 ) return this.copy( qb );
  905. var x = this._x, y = this._y, z = this._z, w = this._w;
  906. // http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/slerp/
  907. var cosHalfTheta = w * qb._w + x * qb._x + y * qb._y + z * qb._z;
  908. if ( cosHalfTheta < 0 ) {
  909. this._w = - qb._w;
  910. this._x = - qb._x;
  911. this._y = - qb._y;
  912. this._z = - qb._z;
  913. cosHalfTheta = - cosHalfTheta;
  914. } else {
  915. this.copy( qb );
  916. }
  917. if ( cosHalfTheta >= 1.0 ) {
  918. this._w = w;
  919. this._x = x;
  920. this._y = y;
  921. this._z = z;
  922. return this;
  923. }
  924. var sqrSinHalfTheta = 1.0 - cosHalfTheta * cosHalfTheta;
  925. if ( sqrSinHalfTheta <= Number.EPSILON ) {
  926. var s = 1 - t;
  927. this._w = s * w + t * this._w;
  928. this._x = s * x + t * this._x;
  929. this._y = s * y + t * this._y;
  930. this._z = s * z + t * this._z;
  931. return this.normalize();
  932. }
  933. var sinHalfTheta = Math.sqrt( sqrSinHalfTheta );
  934. var halfTheta = Math.atan2( sinHalfTheta, cosHalfTheta );
  935. var ratioA = Math.sin( ( 1 - t ) * halfTheta ) / sinHalfTheta,
  936. ratioB = Math.sin( t * halfTheta ) / sinHalfTheta;
  937. this._w = ( w * ratioA + this._w * ratioB );
  938. this._x = ( x * ratioA + this._x * ratioB );
  939. this._y = ( y * ratioA + this._y * ratioB );
  940. this._z = ( z * ratioA + this._z * ratioB );
  941. this.onChangeCallback();
  942. return this;
  943. },
  944. equals: function ( quaternion ) {
  945. return ( quaternion._x === this._x ) && ( quaternion._y === this._y ) && ( quaternion._z === this._z ) && ( quaternion._w === this._w );
  946. },
  947. fromArray: function ( array, offset ) {
  948. if ( offset === undefined ) offset = 0;
  949. this._x = array[ offset ];
  950. this._y = array[ offset + 1 ];
  951. this._z = array[ offset + 2 ];
  952. this._w = array[ offset + 3 ];
  953. this.onChangeCallback();
  954. return this;
  955. },
  956. toArray: function ( array, offset ) {
  957. if ( array === undefined ) array = [];
  958. if ( offset === undefined ) offset = 0;
  959. array[ offset ] = this._x;
  960. array[ offset + 1 ] = this._y;
  961. array[ offset + 2 ] = this._z;
  962. array[ offset + 3 ] = this._w;
  963. return array;
  964. },
  965. onChange: function ( callback ) {
  966. this.onChangeCallback = callback;
  967. return this;
  968. },
  969. onChangeCallback: function () {}
  970. } );
  971. /**
  972. * @author mrdoob / http://mrdoob.com/
  973. * @author kile / http://kile.stravaganza.org/
  974. * @author philogb / http://blog.thejit.org/
  975. * @author mikael emtinger / http://gomo.se/
  976. * @author egraether / http://egraether.com/
  977. * @author WestLangley / http://github.com/WestLangley
  978. */
  979. function Vector3( x, y, z ) {
  980. this.x = x || 0;
  981. this.y = y || 0;
  982. this.z = z || 0;
  983. }
  984. Object.assign( Vector3.prototype, {
  985. isVector3: true,
  986. set: function ( x, y, z ) {
  987. this.x = x;
  988. this.y = y;
  989. this.z = z;
  990. return this;
  991. },
  992. setScalar: function ( scalar ) {
  993. this.x = scalar;
  994. this.y = scalar;
  995. this.z = scalar;
  996. return this;
  997. },
  998. setX: function ( x ) {
  999. this.x = x;
  1000. return this;
  1001. },
  1002. setY: function ( y ) {
  1003. this.y = y;
  1004. return this;
  1005. },
  1006. setZ: function ( z ) {
  1007. this.z = z;
  1008. return this;
  1009. },
  1010. setComponent: function ( index, value ) {
  1011. switch ( index ) {
  1012. case 0: this.x = value; break;
  1013. case 1: this.y = value; break;
  1014. case 2: this.z = value; break;
  1015. default: throw new Error( 'index is out of range: ' + index );
  1016. }
  1017. return this;
  1018. },
  1019. getComponent: function ( index ) {
  1020. switch ( index ) {
  1021. case 0: return this.x;
  1022. case 1: return this.y;
  1023. case 2: return this.z;
  1024. default: throw new Error( 'index is out of range: ' + index );
  1025. }
  1026. },
  1027. clone: function () {
  1028. return new this.constructor( this.x, this.y, this.z );
  1029. },
  1030. copy: function ( v ) {
  1031. this.x = v.x;
  1032. this.y = v.y;
  1033. this.z = v.z;
  1034. return this;
  1035. },
  1036. add: function ( v, w ) {
  1037. if ( w !== undefined ) {
  1038. console.warn( 'THREE.Vector3: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  1039. return this.addVectors( v, w );
  1040. }
  1041. this.x += v.x;
  1042. this.y += v.y;
  1043. this.z += v.z;
  1044. return this;
  1045. },
  1046. addScalar: function ( s ) {
  1047. this.x += s;
  1048. this.y += s;
  1049. this.z += s;
  1050. return this;
  1051. },
  1052. addVectors: function ( a, b ) {
  1053. this.x = a.x + b.x;
  1054. this.y = a.y + b.y;
  1055. this.z = a.z + b.z;
  1056. return this;
  1057. },
  1058. addScaledVector: function ( v, s ) {
  1059. this.x += v.x * s;
  1060. this.y += v.y * s;
  1061. this.z += v.z * s;
  1062. return this;
  1063. },
  1064. sub: function ( v, w ) {
  1065. if ( w !== undefined ) {
  1066. console.warn( 'THREE.Vector3: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  1067. return this.subVectors( v, w );
  1068. }
  1069. this.x -= v.x;
  1070. this.y -= v.y;
  1071. this.z -= v.z;
  1072. return this;
  1073. },
  1074. subScalar: function ( s ) {
  1075. this.x -= s;
  1076. this.y -= s;
  1077. this.z -= s;
  1078. return this;
  1079. },
  1080. subVectors: function ( a, b ) {
  1081. this.x = a.x - b.x;
  1082. this.y = a.y - b.y;
  1083. this.z = a.z - b.z;
  1084. return this;
  1085. },
  1086. multiply: function ( v, w ) {
  1087. if ( w !== undefined ) {
  1088. console.warn( 'THREE.Vector3: .multiply() now only accepts one argument. Use .multiplyVectors( a, b ) instead.' );
  1089. return this.multiplyVectors( v, w );
  1090. }
  1091. this.x *= v.x;
  1092. this.y *= v.y;
  1093. this.z *= v.z;
  1094. return this;
  1095. },
  1096. multiplyScalar: function ( scalar ) {
  1097. this.x *= scalar;
  1098. this.y *= scalar;
  1099. this.z *= scalar;
  1100. return this;
  1101. },
  1102. multiplyVectors: function ( a, b ) {
  1103. this.x = a.x * b.x;
  1104. this.y = a.y * b.y;
  1105. this.z = a.z * b.z;
  1106. return this;
  1107. },
  1108. applyEuler: function () {
  1109. var quaternion = new Quaternion();
  1110. return function applyEuler( euler ) {
  1111. if ( ! ( euler && euler.isEuler ) ) {
  1112. console.error( 'THREE.Vector3: .applyEuler() now expects an Euler rotation rather than a Vector3 and order.' );
  1113. }
  1114. return this.applyQuaternion( quaternion.setFromEuler( euler ) );
  1115. };
  1116. }(),
  1117. applyAxisAngle: function () {
  1118. var quaternion = new Quaternion();
  1119. return function applyAxisAngle( axis, angle ) {
  1120. return this.applyQuaternion( quaternion.setFromAxisAngle( axis, angle ) );
  1121. };
  1122. }(),
  1123. applyMatrix3: function ( m ) {
  1124. var x = this.x, y = this.y, z = this.z;
  1125. var e = m.elements;
  1126. this.x = e[ 0 ] * x + e[ 3 ] * y + e[ 6 ] * z;
  1127. this.y = e[ 1 ] * x + e[ 4 ] * y + e[ 7 ] * z;
  1128. this.z = e[ 2 ] * x + e[ 5 ] * y + e[ 8 ] * z;
  1129. return this;
  1130. },
  1131. applyMatrix4: function ( m ) {
  1132. var x = this.x, y = this.y, z = this.z;
  1133. var e = m.elements;
  1134. var w = 1 / ( e[ 3 ] * x + e[ 7 ] * y + e[ 11 ] * z + e[ 15 ] );
  1135. this.x = ( e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ] ) * w;
  1136. this.y = ( e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ] ) * w;
  1137. this.z = ( e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ] ) * w;
  1138. return this;
  1139. },
  1140. applyQuaternion: function ( q ) {
  1141. var x = this.x, y = this.y, z = this.z;
  1142. var qx = q.x, qy = q.y, qz = q.z, qw = q.w;
  1143. // calculate quat * vector
  1144. var ix = qw * x + qy * z - qz * y;
  1145. var iy = qw * y + qz * x - qx * z;
  1146. var iz = qw * z + qx * y - qy * x;
  1147. var iw = - qx * x - qy * y - qz * z;
  1148. // calculate result * inverse quat
  1149. this.x = ix * qw + iw * - qx + iy * - qz - iz * - qy;
  1150. this.y = iy * qw + iw * - qy + iz * - qx - ix * - qz;
  1151. this.z = iz * qw + iw * - qz + ix * - qy - iy * - qx;
  1152. return this;
  1153. },
  1154. project: function ( camera ) {
  1155. return this.applyMatrix4( camera.matrixWorldInverse ).applyMatrix4( camera.projectionMatrix );
  1156. },
  1157. unproject: function ( camera ) {
  1158. return this.applyMatrix4( camera.projectionMatrixInverse ).applyMatrix4( camera.matrixWorld );
  1159. },
  1160. transformDirection: function ( m ) {
  1161. // input: THREE.Matrix4 affine matrix
  1162. // vector interpreted as a direction
  1163. var x = this.x, y = this.y, z = this.z;
  1164. var e = m.elements;
  1165. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z;
  1166. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z;
  1167. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z;
  1168. return this.normalize();
  1169. },
  1170. divide: function ( v ) {
  1171. this.x /= v.x;
  1172. this.y /= v.y;
  1173. this.z /= v.z;
  1174. return this;
  1175. },
  1176. divideScalar: function ( scalar ) {
  1177. return this.multiplyScalar( 1 / scalar );
  1178. },
  1179. min: function ( v ) {
  1180. this.x = Math.min( this.x, v.x );
  1181. this.y = Math.min( this.y, v.y );
  1182. this.z = Math.min( this.z, v.z );
  1183. return this;
  1184. },
  1185. max: function ( v ) {
  1186. this.x = Math.max( this.x, v.x );
  1187. this.y = Math.max( this.y, v.y );
  1188. this.z = Math.max( this.z, v.z );
  1189. return this;
  1190. },
  1191. clamp: function ( min, max ) {
  1192. // assumes min < max, componentwise
  1193. this.x = Math.max( min.x, Math.min( max.x, this.x ) );
  1194. this.y = Math.max( min.y, Math.min( max.y, this.y ) );
  1195. this.z = Math.max( min.z, Math.min( max.z, this.z ) );
  1196. return this;
  1197. },
  1198. clampScalar: function ( minVal, maxVal ) {
  1199. this.x = Math.max( minVal, Math.min( maxVal, this.x ) );
  1200. this.y = Math.max( minVal, Math.min( maxVal, this.y ) );
  1201. this.z = Math.max( minVal, Math.min( maxVal, this.z ) );
  1202. return this;
  1203. },
  1204. clampLength: function ( min, max ) {
  1205. var length = this.length();
  1206. return this.divideScalar( length || 1 ).multiplyScalar( Math.max( min, Math.min( max, length ) ) );
  1207. },
  1208. floor: function () {
  1209. this.x = Math.floor( this.x );
  1210. this.y = Math.floor( this.y );
  1211. this.z = Math.floor( this.z );
  1212. return this;
  1213. },
  1214. ceil: function () {
  1215. this.x = Math.ceil( this.x );
  1216. this.y = Math.ceil( this.y );
  1217. this.z = Math.ceil( this.z );
  1218. return this;
  1219. },
  1220. round: function () {
  1221. this.x = Math.round( this.x );
  1222. this.y = Math.round( this.y );
  1223. this.z = Math.round( this.z );
  1224. return this;
  1225. },
  1226. roundToZero: function () {
  1227. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  1228. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  1229. this.z = ( this.z < 0 ) ? Math.ceil( this.z ) : Math.floor( this.z );
  1230. return this;
  1231. },
  1232. negate: function () {
  1233. this.x = - this.x;
  1234. this.y = - this.y;
  1235. this.z = - this.z;
  1236. return this;
  1237. },
  1238. dot: function ( v ) {
  1239. return this.x * v.x + this.y * v.y + this.z * v.z;
  1240. },
  1241. // TODO lengthSquared?
  1242. lengthSq: function () {
  1243. return this.x * this.x + this.y * this.y + this.z * this.z;
  1244. },
  1245. length: function () {
  1246. return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z );
  1247. },
  1248. manhattanLength: function () {
  1249. return Math.abs( this.x ) + Math.abs( this.y ) + Math.abs( this.z );
  1250. },
  1251. normalize: function () {
  1252. return this.divideScalar( this.length() || 1 );
  1253. },
  1254. setLength: function ( length ) {
  1255. return this.normalize().multiplyScalar( length );
  1256. },
  1257. lerp: function ( v, alpha ) {
  1258. this.x += ( v.x - this.x ) * alpha;
  1259. this.y += ( v.y - this.y ) * alpha;
  1260. this.z += ( v.z - this.z ) * alpha;
  1261. return this;
  1262. },
  1263. lerpVectors: function ( v1, v2, alpha ) {
  1264. return this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  1265. },
  1266. cross: function ( v, w ) {
  1267. if ( w !== undefined ) {
  1268. console.warn( 'THREE.Vector3: .cross() now only accepts one argument. Use .crossVectors( a, b ) instead.' );
  1269. return this.crossVectors( v, w );
  1270. }
  1271. return this.crossVectors( this, v );
  1272. },
  1273. crossVectors: function ( a, b ) {
  1274. var ax = a.x, ay = a.y, az = a.z;
  1275. var bx = b.x, by = b.y, bz = b.z;
  1276. this.x = ay * bz - az * by;
  1277. this.y = az * bx - ax * bz;
  1278. this.z = ax * by - ay * bx;
  1279. return this;
  1280. },
  1281. projectOnVector: function ( vector ) {
  1282. var scalar = vector.dot( this ) / vector.lengthSq();
  1283. return this.copy( vector ).multiplyScalar( scalar );
  1284. },
  1285. projectOnPlane: function () {
  1286. var v1 = new Vector3();
  1287. return function projectOnPlane( planeNormal ) {
  1288. v1.copy( this ).projectOnVector( planeNormal );
  1289. return this.sub( v1 );
  1290. };
  1291. }(),
  1292. reflect: function () {
  1293. // reflect incident vector off plane orthogonal to normal
  1294. // normal is assumed to have unit length
  1295. var v1 = new Vector3();
  1296. return function reflect( normal ) {
  1297. return this.sub( v1.copy( normal ).multiplyScalar( 2 * this.dot( normal ) ) );
  1298. };
  1299. }(),
  1300. angleTo: function ( v ) {
  1301. var theta = this.dot( v ) / ( Math.sqrt( this.lengthSq() * v.lengthSq() ) );
  1302. // clamp, to handle numerical problems
  1303. return Math.acos( _Math.clamp( theta, - 1, 1 ) );
  1304. },
  1305. distanceTo: function ( v ) {
  1306. return Math.sqrt( this.distanceToSquared( v ) );
  1307. },
  1308. distanceToSquared: function ( v ) {
  1309. var dx = this.x - v.x, dy = this.y - v.y, dz = this.z - v.z;
  1310. return dx * dx + dy * dy + dz * dz;
  1311. },
  1312. manhattanDistanceTo: function ( v ) {
  1313. return Math.abs( this.x - v.x ) + Math.abs( this.y - v.y ) + Math.abs( this.z - v.z );
  1314. },
  1315. setFromSpherical: function ( s ) {
  1316. return this.setFromSphericalCoords( s.radius, s.phi, s.theta );
  1317. },
  1318. setFromSphericalCoords: function ( radius, phi, theta ) {
  1319. var sinPhiRadius = Math.sin( phi ) * radius;
  1320. this.x = sinPhiRadius * Math.sin( theta );
  1321. this.y = Math.cos( phi ) * radius;
  1322. this.z = sinPhiRadius * Math.cos( theta );
  1323. return this;
  1324. },
  1325. setFromCylindrical: function ( c ) {
  1326. return this.setFromCylindricalCoords( c.radius, c.theta, c.y );
  1327. },
  1328. setFromCylindricalCoords: function ( radius, theta, y ) {
  1329. this.x = radius * Math.sin( theta );
  1330. this.y = y;
  1331. this.z = radius * Math.cos( theta );
  1332. return this;
  1333. },
  1334. setFromMatrixPosition: function ( m ) {
  1335. var e = m.elements;
  1336. this.x = e[ 12 ];
  1337. this.y = e[ 13 ];
  1338. this.z = e[ 14 ];
  1339. return this;
  1340. },
  1341. setFromMatrixScale: function ( m ) {
  1342. var sx = this.setFromMatrixColumn( m, 0 ).length();
  1343. var sy = this.setFromMatrixColumn( m, 1 ).length();
  1344. var sz = this.setFromMatrixColumn( m, 2 ).length();
  1345. this.x = sx;
  1346. this.y = sy;
  1347. this.z = sz;
  1348. return this;
  1349. },
  1350. setFromMatrixColumn: function ( m, index ) {
  1351. return this.fromArray( m.elements, index * 4 );
  1352. },
  1353. equals: function ( v ) {
  1354. return ( ( v.x === this.x ) && ( v.y === this.y ) && ( v.z === this.z ) );
  1355. },
  1356. fromArray: function ( array, offset ) {
  1357. if ( offset === undefined ) offset = 0;
  1358. this.x = array[ offset ];
  1359. this.y = array[ offset + 1 ];
  1360. this.z = array[ offset + 2 ];
  1361. return this;
  1362. },
  1363. toArray: function ( array, offset ) {
  1364. if ( array === undefined ) array = [];
  1365. if ( offset === undefined ) offset = 0;
  1366. array[ offset ] = this.x;
  1367. array[ offset + 1 ] = this.y;
  1368. array[ offset + 2 ] = this.z;
  1369. return array;
  1370. },
  1371. fromBufferAttribute: function ( attribute, index, offset ) {
  1372. if ( offset !== undefined ) {
  1373. console.warn( 'THREE.Vector3: offset has been removed from .fromBufferAttribute().' );
  1374. }
  1375. this.x = attribute.getX( index );
  1376. this.y = attribute.getY( index );
  1377. this.z = attribute.getZ( index );
  1378. return this;
  1379. }
  1380. } );
  1381. /**
  1382. * @author alteredq / http://alteredqualia.com/
  1383. * @author WestLangley / http://github.com/WestLangley
  1384. * @author bhouston / http://clara.io
  1385. * @author tschw
  1386. */
  1387. function Matrix3() {
  1388. this.elements = [
  1389. 1, 0, 0,
  1390. 0, 1, 0,
  1391. 0, 0, 1
  1392. ];
  1393. if ( arguments.length > 0 ) {
  1394. console.error( 'THREE.Matrix3: the constructor no longer reads arguments. use .set() instead.' );
  1395. }
  1396. }
  1397. Object.assign( Matrix3.prototype, {
  1398. isMatrix3: true,
  1399. set: function ( n11, n12, n13, n21, n22, n23, n31, n32, n33 ) {
  1400. var te = this.elements;
  1401. te[ 0 ] = n11; te[ 1 ] = n21; te[ 2 ] = n31;
  1402. te[ 3 ] = n12; te[ 4 ] = n22; te[ 5 ] = n32;
  1403. te[ 6 ] = n13; te[ 7 ] = n23; te[ 8 ] = n33;
  1404. return this;
  1405. },
  1406. identity: function () {
  1407. this.set(
  1408. 1, 0, 0,
  1409. 0, 1, 0,
  1410. 0, 0, 1
  1411. );
  1412. return this;
  1413. },
  1414. clone: function () {
  1415. return new this.constructor().fromArray( this.elements );
  1416. },
  1417. copy: function ( m ) {
  1418. var te = this.elements;
  1419. var me = m.elements;
  1420. te[ 0 ] = me[ 0 ]; te[ 1 ] = me[ 1 ]; te[ 2 ] = me[ 2 ];
  1421. te[ 3 ] = me[ 3 ]; te[ 4 ] = me[ 4 ]; te[ 5 ] = me[ 5 ];
  1422. te[ 6 ] = me[ 6 ]; te[ 7 ] = me[ 7 ]; te[ 8 ] = me[ 8 ];
  1423. return this;
  1424. },
  1425. setFromMatrix4: function ( m ) {
  1426. var me = m.elements;
  1427. this.set(
  1428. me[ 0 ], me[ 4 ], me[ 8 ],
  1429. me[ 1 ], me[ 5 ], me[ 9 ],
  1430. me[ 2 ], me[ 6 ], me[ 10 ]
  1431. );
  1432. return this;
  1433. },
  1434. applyToBufferAttribute: function () {
  1435. var v1 = new Vector3();
  1436. return function applyToBufferAttribute( attribute ) {
  1437. for ( var i = 0, l = attribute.count; i < l; i ++ ) {
  1438. v1.x = attribute.getX( i );
  1439. v1.y = attribute.getY( i );
  1440. v1.z = attribute.getZ( i );
  1441. v1.applyMatrix3( this );
  1442. attribute.setXYZ( i, v1.x, v1.y, v1.z );
  1443. }
  1444. return attribute;
  1445. };
  1446. }(),
  1447. multiply: function ( m ) {
  1448. return this.multiplyMatrices( this, m );
  1449. },
  1450. premultiply: function ( m ) {
  1451. return this.multiplyMatrices( m, this );
  1452. },
  1453. multiplyMatrices: function ( a, b ) {
  1454. var ae = a.elements;
  1455. var be = b.elements;
  1456. var te = this.elements;
  1457. var a11 = ae[ 0 ], a12 = ae[ 3 ], a13 = ae[ 6 ];
  1458. var a21 = ae[ 1 ], a22 = ae[ 4 ], a23 = ae[ 7 ];
  1459. var a31 = ae[ 2 ], a32 = ae[ 5 ], a33 = ae[ 8 ];
  1460. var b11 = be[ 0 ], b12 = be[ 3 ], b13 = be[ 6 ];
  1461. var b21 = be[ 1 ], b22 = be[ 4 ], b23 = be[ 7 ];
  1462. var b31 = be[ 2 ], b32 = be[ 5 ], b33 = be[ 8 ];
  1463. te[ 0 ] = a11 * b11 + a12 * b21 + a13 * b31;
  1464. te[ 3 ] = a11 * b12 + a12 * b22 + a13 * b32;
  1465. te[ 6 ] = a11 * b13 + a12 * b23 + a13 * b33;
  1466. te[ 1 ] = a21 * b11 + a22 * b21 + a23 * b31;
  1467. te[ 4 ] = a21 * b12 + a22 * b22 + a23 * b32;
  1468. te[ 7 ] = a21 * b13 + a22 * b23 + a23 * b33;
  1469. te[ 2 ] = a31 * b11 + a32 * b21 + a33 * b31;
  1470. te[ 5 ] = a31 * b12 + a32 * b22 + a33 * b32;
  1471. te[ 8 ] = a31 * b13 + a32 * b23 + a33 * b33;
  1472. return this;
  1473. },
  1474. multiplyScalar: function ( s ) {
  1475. var te = this.elements;
  1476. te[ 0 ] *= s; te[ 3 ] *= s; te[ 6 ] *= s;
  1477. te[ 1 ] *= s; te[ 4 ] *= s; te[ 7 ] *= s;
  1478. te[ 2 ] *= s; te[ 5 ] *= s; te[ 8 ] *= s;
  1479. return this;
  1480. },
  1481. determinant: function () {
  1482. var te = this.elements;
  1483. var a = te[ 0 ], b = te[ 1 ], c = te[ 2 ],
  1484. d = te[ 3 ], e = te[ 4 ], f = te[ 5 ],
  1485. g = te[ 6 ], h = te[ 7 ], i = te[ 8 ];
  1486. return a * e * i - a * f * h - b * d * i + b * f * g + c * d * h - c * e * g;
  1487. },
  1488. getInverse: function ( matrix, throwOnDegenerate ) {
  1489. if ( matrix && matrix.isMatrix4 ) {
  1490. console.error( "THREE.Matrix3: .getInverse() no longer takes a Matrix4 argument." );
  1491. }
  1492. var me = matrix.elements,
  1493. te = this.elements,
  1494. n11 = me[ 0 ], n21 = me[ 1 ], n31 = me[ 2 ],
  1495. n12 = me[ 3 ], n22 = me[ 4 ], n32 = me[ 5 ],
  1496. n13 = me[ 6 ], n23 = me[ 7 ], n33 = me[ 8 ],
  1497. t11 = n33 * n22 - n32 * n23,
  1498. t12 = n32 * n13 - n33 * n12,
  1499. t13 = n23 * n12 - n22 * n13,
  1500. det = n11 * t11 + n21 * t12 + n31 * t13;
  1501. if ( det === 0 ) {
  1502. var msg = "THREE.Matrix3: .getInverse() can't invert matrix, determinant is 0";
  1503. if ( throwOnDegenerate === true ) {
  1504. throw new Error( msg );
  1505. } else {
  1506. console.warn( msg );
  1507. }
  1508. return this.identity();
  1509. }
  1510. var detInv = 1 / det;
  1511. te[ 0 ] = t11 * detInv;
  1512. te[ 1 ] = ( n31 * n23 - n33 * n21 ) * detInv;
  1513. te[ 2 ] = ( n32 * n21 - n31 * n22 ) * detInv;
  1514. te[ 3 ] = t12 * detInv;
  1515. te[ 4 ] = ( n33 * n11 - n31 * n13 ) * detInv;
  1516. te[ 5 ] = ( n31 * n12 - n32 * n11 ) * detInv;
  1517. te[ 6 ] = t13 * detInv;
  1518. te[ 7 ] = ( n21 * n13 - n23 * n11 ) * detInv;
  1519. te[ 8 ] = ( n22 * n11 - n21 * n12 ) * detInv;
  1520. return this;
  1521. },
  1522. transpose: function () {
  1523. var tmp, m = this.elements;
  1524. tmp = m[ 1 ]; m[ 1 ] = m[ 3 ]; m[ 3 ] = tmp;
  1525. tmp = m[ 2 ]; m[ 2 ] = m[ 6 ]; m[ 6 ] = tmp;
  1526. tmp = m[ 5 ]; m[ 5 ] = m[ 7 ]; m[ 7 ] = tmp;
  1527. return this;
  1528. },
  1529. getNormalMatrix: function ( matrix4 ) {
  1530. return this.setFromMatrix4( matrix4 ).getInverse( this ).transpose();
  1531. },
  1532. transposeIntoArray: function ( r ) {
  1533. var m = this.elements;
  1534. r[ 0 ] = m[ 0 ];
  1535. r[ 1 ] = m[ 3 ];
  1536. r[ 2 ] = m[ 6 ];
  1537. r[ 3 ] = m[ 1 ];
  1538. r[ 4 ] = m[ 4 ];
  1539. r[ 5 ] = m[ 7 ];
  1540. r[ 6 ] = m[ 2 ];
  1541. r[ 7 ] = m[ 5 ];
  1542. r[ 8 ] = m[ 8 ];
  1543. return this;
  1544. },
  1545. setUvTransform: function ( tx, ty, sx, sy, rotation, cx, cy ) {
  1546. var c = Math.cos( rotation );
  1547. var s = Math.sin( rotation );
  1548. this.set(
  1549. sx * c, sx * s, - sx * ( c * cx + s * cy ) + cx + tx,
  1550. - sy * s, sy * c, - sy * ( - s * cx + c * cy ) + cy + ty,
  1551. 0, 0, 1
  1552. );
  1553. },
  1554. scale: function ( sx, sy ) {
  1555. var te = this.elements;
  1556. te[ 0 ] *= sx; te[ 3 ] *= sx; te[ 6 ] *= sx;
  1557. te[ 1 ] *= sy; te[ 4 ] *= sy; te[ 7 ] *= sy;
  1558. return this;
  1559. },
  1560. rotate: function ( theta ) {
  1561. var c = Math.cos( theta );
  1562. var s = Math.sin( theta );
  1563. var te = this.elements;
  1564. var a11 = te[ 0 ], a12 = te[ 3 ], a13 = te[ 6 ];
  1565. var a21 = te[ 1 ], a22 = te[ 4 ], a23 = te[ 7 ];
  1566. te[ 0 ] = c * a11 + s * a21;
  1567. te[ 3 ] = c * a12 + s * a22;
  1568. te[ 6 ] = c * a13 + s * a23;
  1569. te[ 1 ] = - s * a11 + c * a21;
  1570. te[ 4 ] = - s * a12 + c * a22;
  1571. te[ 7 ] = - s * a13 + c * a23;
  1572. return this;
  1573. },
  1574. translate: function ( tx, ty ) {
  1575. var te = this.elements;
  1576. te[ 0 ] += tx * te[ 2 ]; te[ 3 ] += tx * te[ 5 ]; te[ 6 ] += tx * te[ 8 ];
  1577. te[ 1 ] += ty * te[ 2 ]; te[ 4 ] += ty * te[ 5 ]; te[ 7 ] += ty * te[ 8 ];
  1578. return this;
  1579. },
  1580. equals: function ( matrix ) {
  1581. var te = this.elements;
  1582. var me = matrix.elements;
  1583. for ( var i = 0; i < 9; i ++ ) {
  1584. if ( te[ i ] !== me[ i ] ) return false;
  1585. }
  1586. return true;
  1587. },
  1588. fromArray: function ( array, offset ) {
  1589. if ( offset === undefined ) offset = 0;
  1590. for ( var i = 0; i < 9; i ++ ) {
  1591. this.elements[ i ] = array[ i + offset ];
  1592. }
  1593. return this;
  1594. },
  1595. toArray: function ( array, offset ) {
  1596. if ( array === undefined ) array = [];
  1597. if ( offset === undefined ) offset = 0;
  1598. var te = this.elements;
  1599. array[ offset ] = te[ 0 ];
  1600. array[ offset + 1 ] = te[ 1 ];
  1601. array[ offset + 2 ] = te[ 2 ];
  1602. array[ offset + 3 ] = te[ 3 ];
  1603. array[ offset + 4 ] = te[ 4 ];
  1604. array[ offset + 5 ] = te[ 5 ];
  1605. array[ offset + 6 ] = te[ 6 ];
  1606. array[ offset + 7 ] = te[ 7 ];
  1607. array[ offset + 8 ] = te[ 8 ];
  1608. return array;
  1609. }
  1610. } );
  1611. /**
  1612. * @author mrdoob / http://mrdoob.com/
  1613. * @author alteredq / http://alteredqualia.com/
  1614. * @author szimek / https://github.com/szimek/
  1615. */
  1616. var _canvas;
  1617. var ImageUtils = {
  1618. getDataURL: function ( image ) {
  1619. var canvas;
  1620. if ( typeof HTMLCanvasElement == 'undefined' ) {
  1621. return image.src;
  1622. } else if ( image instanceof HTMLCanvasElement ) {
  1623. canvas = image;
  1624. } else {
  1625. if ( _canvas === undefined ) _canvas = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' );
  1626. _canvas.width = image.width;
  1627. _canvas.height = image.height;
  1628. var context = _canvas.getContext( '2d' );
  1629. if ( image instanceof ImageData ) {
  1630. context.putImageData( image, 0, 0 );
  1631. } else {
  1632. context.drawImage( image, 0, 0, image.width, image.height );
  1633. }
  1634. canvas = _canvas;
  1635. }
  1636. if ( canvas.width > 2048 || canvas.height > 2048 ) {
  1637. return canvas.toDataURL( 'image/jpeg', 0.6 );
  1638. } else {
  1639. return canvas.toDataURL( 'image/png' );
  1640. }
  1641. }
  1642. };
  1643. /**
  1644. * @author mrdoob / http://mrdoob.com/
  1645. * @author alteredq / http://alteredqualia.com/
  1646. * @author szimek / https://github.com/szimek/
  1647. */
  1648. var textureId = 0;
  1649. function Texture( image, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding ) {
  1650. Object.defineProperty( this, 'id', { value: textureId ++ } );
  1651. this.uuid = _Math.generateUUID();
  1652. this.name = '';
  1653. this.image = image !== undefined ? image : Texture.DEFAULT_IMAGE;
  1654. this.mipmaps = [];
  1655. this.mapping = mapping !== undefined ? mapping : Texture.DEFAULT_MAPPING;
  1656. this.wrapS = wrapS !== undefined ? wrapS : ClampToEdgeWrapping;
  1657. this.wrapT = wrapT !== undefined ? wrapT : ClampToEdgeWrapping;
  1658. this.magFilter = magFilter !== undefined ? magFilter : LinearFilter;
  1659. this.minFilter = minFilter !== undefined ? minFilter : LinearMipMapLinearFilter;
  1660. this.anisotropy = anisotropy !== undefined ? anisotropy : 1;
  1661. this.format = format !== undefined ? format : RGBAFormat;
  1662. this.type = type !== undefined ? type : UnsignedByteType;
  1663. this.offset = new Vector2( 0, 0 );
  1664. this.repeat = new Vector2( 1, 1 );
  1665. this.center = new Vector2( 0, 0 );
  1666. this.rotation = 0;
  1667. this.matrixAutoUpdate = true;
  1668. this.matrix = new Matrix3();
  1669. this.generateMipmaps = true;
  1670. this.premultiplyAlpha = false;
  1671. this.flipY = true;
  1672. this.unpackAlignment = 4; // valid values: 1, 2, 4, 8 (see http://www.khronos.org/opengles/sdk/docs/man/xhtml/glPixelStorei.xml)
  1673. // Values of encoding !== THREE.LinearEncoding only supported on map, envMap and emissiveMap.
  1674. //
  1675. // Also changing the encoding after already used by a Material will not automatically make the Material
  1676. // update. You need to explicitly call Material.needsUpdate to trigger it to recompile.
  1677. this.encoding = encoding !== undefined ? encoding : LinearEncoding;
  1678. this.version = 0;
  1679. this.onUpdate = null;
  1680. }
  1681. Texture.DEFAULT_IMAGE = undefined;
  1682. Texture.DEFAULT_MAPPING = UVMapping;
  1683. Texture.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  1684. constructor: Texture,
  1685. isTexture: true,
  1686. updateMatrix: function () {
  1687. this.matrix.setUvTransform( this.offset.x, this.offset.y, this.repeat.x, this.repeat.y, this.rotation, this.center.x, this.center.y );
  1688. },
  1689. clone: function () {
  1690. return new this.constructor().copy( this );
  1691. },
  1692. copy: function ( source ) {
  1693. this.name = source.name;
  1694. this.image = source.image;
  1695. this.mipmaps = source.mipmaps.slice( 0 );
  1696. this.mapping = source.mapping;
  1697. this.wrapS = source.wrapS;
  1698. this.wrapT = source.wrapT;
  1699. this.magFilter = source.magFilter;
  1700. this.minFilter = source.minFilter;
  1701. this.anisotropy = source.anisotropy;
  1702. this.format = source.format;
  1703. this.type = source.type;
  1704. this.offset.copy( source.offset );
  1705. this.repeat.copy( source.repeat );
  1706. this.center.copy( source.center );
  1707. this.rotation = source.rotation;
  1708. this.matrixAutoUpdate = source.matrixAutoUpdate;
  1709. this.matrix.copy( source.matrix );
  1710. this.generateMipmaps = source.generateMipmaps;
  1711. this.premultiplyAlpha = source.premultiplyAlpha;
  1712. this.flipY = source.flipY;
  1713. this.unpackAlignment = source.unpackAlignment;
  1714. this.encoding = source.encoding;
  1715. return this;
  1716. },
  1717. toJSON: function ( meta ) {
  1718. var isRootObject = ( meta === undefined || typeof meta === 'string' );
  1719. if ( ! isRootObject && meta.textures[ this.uuid ] !== undefined ) {
  1720. return meta.textures[ this.uuid ];
  1721. }
  1722. var output = {
  1723. metadata: {
  1724. version: 4.5,
  1725. type: 'Texture',
  1726. generator: 'Texture.toJSON'
  1727. },
  1728. uuid: this.uuid,
  1729. name: this.name,
  1730. mapping: this.mapping,
  1731. repeat: [ this.repeat.x, this.repeat.y ],
  1732. offset: [ this.offset.x, this.offset.y ],
  1733. center: [ this.center.x, this.center.y ],
  1734. rotation: this.rotation,
  1735. wrap: [ this.wrapS, this.wrapT ],
  1736. format: this.format,
  1737. type: this.type,
  1738. encoding: this.encoding,
  1739. minFilter: this.minFilter,
  1740. magFilter: this.magFilter,
  1741. anisotropy: this.anisotropy,
  1742. flipY: this.flipY,
  1743. premultiplyAlpha: this.premultiplyAlpha,
  1744. unpackAlignment: this.unpackAlignment
  1745. };
  1746. if ( this.image !== undefined ) {
  1747. // TODO: Move to THREE.Image
  1748. var image = this.image;
  1749. if ( image.uuid === undefined ) {
  1750. image.uuid = _Math.generateUUID(); // UGH
  1751. }
  1752. if ( ! isRootObject && meta.images[ image.uuid ] === undefined ) {
  1753. var url;
  1754. if ( Array.isArray( image ) ) {
  1755. // process array of images e.g. CubeTexture
  1756. url = [];
  1757. for ( var i = 0, l = image.length; i < l; i ++ ) {
  1758. url.push( ImageUtils.getDataURL( image[ i ] ) );
  1759. }
  1760. } else {
  1761. // process single image
  1762. url = ImageUtils.getDataURL( image );
  1763. }
  1764. meta.images[ image.uuid ] = {
  1765. uuid: image.uuid,
  1766. url: url
  1767. };
  1768. }
  1769. output.image = image.uuid;
  1770. }
  1771. if ( ! isRootObject ) {
  1772. meta.textures[ this.uuid ] = output;
  1773. }
  1774. return output;
  1775. },
  1776. dispose: function () {
  1777. this.dispatchEvent( { type: 'dispose' } );
  1778. },
  1779. transformUv: function ( uv ) {
  1780. if ( this.mapping !== UVMapping ) return uv;
  1781. uv.applyMatrix3( this.matrix );
  1782. if ( uv.x < 0 || uv.x > 1 ) {
  1783. switch ( this.wrapS ) {
  1784. case RepeatWrapping:
  1785. uv.x = uv.x - Math.floor( uv.x );
  1786. break;
  1787. case ClampToEdgeWrapping:
  1788. uv.x = uv.x < 0 ? 0 : 1;
  1789. break;
  1790. case MirroredRepeatWrapping:
  1791. if ( Math.abs( Math.floor( uv.x ) % 2 ) === 1 ) {
  1792. uv.x = Math.ceil( uv.x ) - uv.x;
  1793. } else {
  1794. uv.x = uv.x - Math.floor( uv.x );
  1795. }
  1796. break;
  1797. }
  1798. }
  1799. if ( uv.y < 0 || uv.y > 1 ) {
  1800. switch ( this.wrapT ) {
  1801. case RepeatWrapping:
  1802. uv.y = uv.y - Math.floor( uv.y );
  1803. break;
  1804. case ClampToEdgeWrapping:
  1805. uv.y = uv.y < 0 ? 0 : 1;
  1806. break;
  1807. case MirroredRepeatWrapping:
  1808. if ( Math.abs( Math.floor( uv.y ) % 2 ) === 1 ) {
  1809. uv.y = Math.ceil( uv.y ) - uv.y;
  1810. } else {
  1811. uv.y = uv.y - Math.floor( uv.y );
  1812. }
  1813. break;
  1814. }
  1815. }
  1816. if ( this.flipY ) {
  1817. uv.y = 1 - uv.y;
  1818. }
  1819. return uv;
  1820. }
  1821. } );
  1822. Object.defineProperty( Texture.prototype, "needsUpdate", {
  1823. set: function ( value ) {
  1824. if ( value === true ) this.version ++;
  1825. }
  1826. } );
  1827. /**
  1828. * @author supereggbert / http://www.paulbrunt.co.uk/
  1829. * @author philogb / http://blog.thejit.org/
  1830. * @author mikael emtinger / http://gomo.se/
  1831. * @author egraether / http://egraether.com/
  1832. * @author WestLangley / http://github.com/WestLangley
  1833. */
  1834. function Vector4( x, y, z, w ) {
  1835. this.x = x || 0;
  1836. this.y = y || 0;
  1837. this.z = z || 0;
  1838. this.w = ( w !== undefined ) ? w : 1;
  1839. }
  1840. Object.assign( Vector4.prototype, {
  1841. isVector4: true,
  1842. set: function ( x, y, z, w ) {
  1843. this.x = x;
  1844. this.y = y;
  1845. this.z = z;
  1846. this.w = w;
  1847. return this;
  1848. },
  1849. setScalar: function ( scalar ) {
  1850. this.x = scalar;
  1851. this.y = scalar;
  1852. this.z = scalar;
  1853. this.w = scalar;
  1854. return this;
  1855. },
  1856. setX: function ( x ) {
  1857. this.x = x;
  1858. return this;
  1859. },
  1860. setY: function ( y ) {
  1861. this.y = y;
  1862. return this;
  1863. },
  1864. setZ: function ( z ) {
  1865. this.z = z;
  1866. return this;
  1867. },
  1868. setW: function ( w ) {
  1869. this.w = w;
  1870. return this;
  1871. },
  1872. setComponent: function ( index, value ) {
  1873. switch ( index ) {
  1874. case 0: this.x = value; break;
  1875. case 1: this.y = value; break;
  1876. case 2: this.z = value; break;
  1877. case 3: this.w = value; break;
  1878. default: throw new Error( 'index is out of range: ' + index );
  1879. }
  1880. return this;
  1881. },
  1882. getComponent: function ( index ) {
  1883. switch ( index ) {
  1884. case 0: return this.x;
  1885. case 1: return this.y;
  1886. case 2: return this.z;
  1887. case 3: return this.w;
  1888. default: throw new Error( 'index is out of range: ' + index );
  1889. }
  1890. },
  1891. clone: function () {
  1892. return new this.constructor( this.x, this.y, this.z, this.w );
  1893. },
  1894. copy: function ( v ) {
  1895. this.x = v.x;
  1896. this.y = v.y;
  1897. this.z = v.z;
  1898. this.w = ( v.w !== undefined ) ? v.w : 1;
  1899. return this;
  1900. },
  1901. add: function ( v, w ) {
  1902. if ( w !== undefined ) {
  1903. console.warn( 'THREE.Vector4: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  1904. return this.addVectors( v, w );
  1905. }
  1906. this.x += v.x;
  1907. this.y += v.y;
  1908. this.z += v.z;
  1909. this.w += v.w;
  1910. return this;
  1911. },
  1912. addScalar: function ( s ) {
  1913. this.x += s;
  1914. this.y += s;
  1915. this.z += s;
  1916. this.w += s;
  1917. return this;
  1918. },
  1919. addVectors: function ( a, b ) {
  1920. this.x = a.x + b.x;
  1921. this.y = a.y + b.y;
  1922. this.z = a.z + b.z;
  1923. this.w = a.w + b.w;
  1924. return this;
  1925. },
  1926. addScaledVector: function ( v, s ) {
  1927. this.x += v.x * s;
  1928. this.y += v.y * s;
  1929. this.z += v.z * s;
  1930. this.w += v.w * s;
  1931. return this;
  1932. },
  1933. sub: function ( v, w ) {
  1934. if ( w !== undefined ) {
  1935. console.warn( 'THREE.Vector4: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  1936. return this.subVectors( v, w );
  1937. }
  1938. this.x -= v.x;
  1939. this.y -= v.y;
  1940. this.z -= v.z;
  1941. this.w -= v.w;
  1942. return this;
  1943. },
  1944. subScalar: function ( s ) {
  1945. this.x -= s;
  1946. this.y -= s;
  1947. this.z -= s;
  1948. this.w -= s;
  1949. return this;
  1950. },
  1951. subVectors: function ( a, b ) {
  1952. this.x = a.x - b.x;
  1953. this.y = a.y - b.y;
  1954. this.z = a.z - b.z;
  1955. this.w = a.w - b.w;
  1956. return this;
  1957. },
  1958. multiplyScalar: function ( scalar ) {
  1959. this.x *= scalar;
  1960. this.y *= scalar;
  1961. this.z *= scalar;
  1962. this.w *= scalar;
  1963. return this;
  1964. },
  1965. applyMatrix4: function ( m ) {
  1966. var x = this.x, y = this.y, z = this.z, w = this.w;
  1967. var e = m.elements;
  1968. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ] * w;
  1969. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ] * w;
  1970. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ] * w;
  1971. this.w = e[ 3 ] * x + e[ 7 ] * y + e[ 11 ] * z + e[ 15 ] * w;
  1972. return this;
  1973. },
  1974. divideScalar: function ( scalar ) {
  1975. return this.multiplyScalar( 1 / scalar );
  1976. },
  1977. setAxisAngleFromQuaternion: function ( q ) {
  1978. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToAngle/index.htm
  1979. // q is assumed to be normalized
  1980. this.w = 2 * Math.acos( q.w );
  1981. var s = Math.sqrt( 1 - q.w * q.w );
  1982. if ( s < 0.0001 ) {
  1983. this.x = 1;
  1984. this.y = 0;
  1985. this.z = 0;
  1986. } else {
  1987. this.x = q.x / s;
  1988. this.y = q.y / s;
  1989. this.z = q.z / s;
  1990. }
  1991. return this;
  1992. },
  1993. setAxisAngleFromRotationMatrix: function ( m ) {
  1994. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToAngle/index.htm
  1995. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  1996. var angle, x, y, z, // variables for result
  1997. epsilon = 0.01, // margin to allow for rounding errors
  1998. epsilon2 = 0.1, // margin to distinguish between 0 and 180 degrees
  1999. te = m.elements,
  2000. m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ],
  2001. m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ],
  2002. m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ];
  2003. if ( ( Math.abs( m12 - m21 ) < epsilon ) &&
  2004. ( Math.abs( m13 - m31 ) < epsilon ) &&
  2005. ( Math.abs( m23 - m32 ) < epsilon ) ) {
  2006. // singularity found
  2007. // first check for identity matrix which must have +1 for all terms
  2008. // in leading diagonal and zero in other terms
  2009. if ( ( Math.abs( m12 + m21 ) < epsilon2 ) &&
  2010. ( Math.abs( m13 + m31 ) < epsilon2 ) &&
  2011. ( Math.abs( m23 + m32 ) < epsilon2 ) &&
  2012. ( Math.abs( m11 + m22 + m33 - 3 ) < epsilon2 ) ) {
  2013. // this singularity is identity matrix so angle = 0
  2014. this.set( 1, 0, 0, 0 );
  2015. return this; // zero angle, arbitrary axis
  2016. }
  2017. // otherwise this singularity is angle = 180
  2018. angle = Math.PI;
  2019. var xx = ( m11 + 1 ) / 2;
  2020. var yy = ( m22 + 1 ) / 2;
  2021. var zz = ( m33 + 1 ) / 2;
  2022. var xy = ( m12 + m21 ) / 4;
  2023. var xz = ( m13 + m31 ) / 4;
  2024. var yz = ( m23 + m32 ) / 4;
  2025. if ( ( xx > yy ) && ( xx > zz ) ) {
  2026. // m11 is the largest diagonal term
  2027. if ( xx < epsilon ) {
  2028. x = 0;
  2029. y = 0.707106781;
  2030. z = 0.707106781;
  2031. } else {
  2032. x = Math.sqrt( xx );
  2033. y = xy / x;
  2034. z = xz / x;
  2035. }
  2036. } else if ( yy > zz ) {
  2037. // m22 is the largest diagonal term
  2038. if ( yy < epsilon ) {
  2039. x = 0.707106781;
  2040. y = 0;
  2041. z = 0.707106781;
  2042. } else {
  2043. y = Math.sqrt( yy );
  2044. x = xy / y;
  2045. z = yz / y;
  2046. }
  2047. } else {
  2048. // m33 is the largest diagonal term so base result on this
  2049. if ( zz < epsilon ) {
  2050. x = 0.707106781;
  2051. y = 0.707106781;
  2052. z = 0;
  2053. } else {
  2054. z = Math.sqrt( zz );
  2055. x = xz / z;
  2056. y = yz / z;
  2057. }
  2058. }
  2059. this.set( x, y, z, angle );
  2060. return this; // return 180 deg rotation
  2061. }
  2062. // as we have reached here there are no singularities so we can handle normally
  2063. var s = Math.sqrt( ( m32 - m23 ) * ( m32 - m23 ) +
  2064. ( m13 - m31 ) * ( m13 - m31 ) +
  2065. ( m21 - m12 ) * ( m21 - m12 ) ); // used to normalize
  2066. if ( Math.abs( s ) < 0.001 ) s = 1;
  2067. // prevent divide by zero, should not happen if matrix is orthogonal and should be
  2068. // caught by singularity test above, but I've left it in just in case
  2069. this.x = ( m32 - m23 ) / s;
  2070. this.y = ( m13 - m31 ) / s;
  2071. this.z = ( m21 - m12 ) / s;
  2072. this.w = Math.acos( ( m11 + m22 + m33 - 1 ) / 2 );
  2073. return this;
  2074. },
  2075. min: function ( v ) {
  2076. this.x = Math.min( this.x, v.x );
  2077. this.y = Math.min( this.y, v.y );
  2078. this.z = Math.min( this.z, v.z );
  2079. this.w = Math.min( this.w, v.w );
  2080. return this;
  2081. },
  2082. max: function ( v ) {
  2083. this.x = Math.max( this.x, v.x );
  2084. this.y = Math.max( this.y, v.y );
  2085. this.z = Math.max( this.z, v.z );
  2086. this.w = Math.max( this.w, v.w );
  2087. return this;
  2088. },
  2089. clamp: function ( min, max ) {
  2090. // assumes min < max, componentwise
  2091. this.x = Math.max( min.x, Math.min( max.x, this.x ) );
  2092. this.y = Math.max( min.y, Math.min( max.y, this.y ) );
  2093. this.z = Math.max( min.z, Math.min( max.z, this.z ) );
  2094. this.w = Math.max( min.w, Math.min( max.w, this.w ) );
  2095. return this;
  2096. },
  2097. clampScalar: function () {
  2098. var min, max;
  2099. return function clampScalar( minVal, maxVal ) {
  2100. if ( min === undefined ) {
  2101. min = new Vector4();
  2102. max = new Vector4();
  2103. }
  2104. min.set( minVal, minVal, minVal, minVal );
  2105. max.set( maxVal, maxVal, maxVal, maxVal );
  2106. return this.clamp( min, max );
  2107. };
  2108. }(),
  2109. clampLength: function ( min, max ) {
  2110. var length = this.length();
  2111. return this.divideScalar( length || 1 ).multiplyScalar( Math.max( min, Math.min( max, length ) ) );
  2112. },
  2113. floor: function () {
  2114. this.x = Math.floor( this.x );
  2115. this.y = Math.floor( this.y );
  2116. this.z = Math.floor( this.z );
  2117. this.w = Math.floor( this.w );
  2118. return this;
  2119. },
  2120. ceil: function () {
  2121. this.x = Math.ceil( this.x );
  2122. this.y = Math.ceil( this.y );
  2123. this.z = Math.ceil( this.z );
  2124. this.w = Math.ceil( this.w );
  2125. return this;
  2126. },
  2127. round: function () {
  2128. this.x = Math.round( this.x );
  2129. this.y = Math.round( this.y );
  2130. this.z = Math.round( this.z );
  2131. this.w = Math.round( this.w );
  2132. return this;
  2133. },
  2134. roundToZero: function () {
  2135. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  2136. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  2137. this.z = ( this.z < 0 ) ? Math.ceil( this.z ) : Math.floor( this.z );
  2138. this.w = ( this.w < 0 ) ? Math.ceil( this.w ) : Math.floor( this.w );
  2139. return this;
  2140. },
  2141. negate: function () {
  2142. this.x = - this.x;
  2143. this.y = - this.y;
  2144. this.z = - this.z;
  2145. this.w = - this.w;
  2146. return this;
  2147. },
  2148. dot: function ( v ) {
  2149. return this.x * v.x + this.y * v.y + this.z * v.z + this.w * v.w;
  2150. },
  2151. lengthSq: function () {
  2152. return this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w;
  2153. },
  2154. length: function () {
  2155. return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w );
  2156. },
  2157. manhattanLength: function () {
  2158. return Math.abs( this.x ) + Math.abs( this.y ) + Math.abs( this.z ) + Math.abs( this.w );
  2159. },
  2160. normalize: function () {
  2161. return this.divideScalar( this.length() || 1 );
  2162. },
  2163. setLength: function ( length ) {
  2164. return this.normalize().multiplyScalar( length );
  2165. },
  2166. lerp: function ( v, alpha ) {
  2167. this.x += ( v.x - this.x ) * alpha;
  2168. this.y += ( v.y - this.y ) * alpha;
  2169. this.z += ( v.z - this.z ) * alpha;
  2170. this.w += ( v.w - this.w ) * alpha;
  2171. return this;
  2172. },
  2173. lerpVectors: function ( v1, v2, alpha ) {
  2174. return this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  2175. },
  2176. equals: function ( v ) {
  2177. return ( ( v.x === this.x ) && ( v.y === this.y ) && ( v.z === this.z ) && ( v.w === this.w ) );
  2178. },
  2179. fromArray: function ( array, offset ) {
  2180. if ( offset === undefined ) offset = 0;
  2181. this.x = array[ offset ];
  2182. this.y = array[ offset + 1 ];
  2183. this.z = array[ offset + 2 ];
  2184. this.w = array[ offset + 3 ];
  2185. return this;
  2186. },
  2187. toArray: function ( array, offset ) {
  2188. if ( array === undefined ) array = [];
  2189. if ( offset === undefined ) offset = 0;
  2190. array[ offset ] = this.x;
  2191. array[ offset + 1 ] = this.y;
  2192. array[ offset + 2 ] = this.z;
  2193. array[ offset + 3 ] = this.w;
  2194. return array;
  2195. },
  2196. fromBufferAttribute: function ( attribute, index, offset ) {
  2197. if ( offset !== undefined ) {
  2198. console.warn( 'THREE.Vector4: offset has been removed from .fromBufferAttribute().' );
  2199. }
  2200. this.x = attribute.getX( index );
  2201. this.y = attribute.getY( index );
  2202. this.z = attribute.getZ( index );
  2203. this.w = attribute.getW( index );
  2204. return this;
  2205. }
  2206. } );
  2207. /**
  2208. * @author szimek / https://github.com/szimek/
  2209. * @author alteredq / http://alteredqualia.com/
  2210. * @author Marius Kintel / https://github.com/kintel
  2211. */
  2212. /*
  2213. In options, we can specify:
  2214. * Texture parameters for an auto-generated target texture
  2215. * depthBuffer/stencilBuffer: Booleans to indicate if we should generate these buffers
  2216. */
  2217. function WebGLRenderTarget( width, height, options ) {
  2218. this.width = width;
  2219. this.height = height;
  2220. this.scissor = new Vector4( 0, 0, width, height );
  2221. this.scissorTest = false;
  2222. this.viewport = new Vector4( 0, 0, width, height );
  2223. options = options || {};
  2224. this.texture = new Texture( undefined, undefined, options.wrapS, options.wrapT, options.magFilter, options.minFilter, options.format, options.type, options.anisotropy, options.encoding );
  2225. this.texture.generateMipmaps = options.generateMipmaps !== undefined ? options.generateMipmaps : false;
  2226. this.texture.minFilter = options.minFilter !== undefined ? options.minFilter : LinearFilter;
  2227. this.depthBuffer = options.depthBuffer !== undefined ? options.depthBuffer : true;
  2228. this.stencilBuffer = options.stencilBuffer !== undefined ? options.stencilBuffer : true;
  2229. this.depthTexture = options.depthTexture !== undefined ? options.depthTexture : null;
  2230. }
  2231. WebGLRenderTarget.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  2232. constructor: WebGLRenderTarget,
  2233. isWebGLRenderTarget: true,
  2234. setSize: function ( width, height ) {
  2235. if ( this.width !== width || this.height !== height ) {
  2236. this.width = width;
  2237. this.height = height;
  2238. this.dispose();
  2239. }
  2240. this.viewport.set( 0, 0, width, height );
  2241. this.scissor.set( 0, 0, width, height );
  2242. },
  2243. clone: function () {
  2244. return new this.constructor().copy( this );
  2245. },
  2246. copy: function ( source ) {
  2247. this.width = source.width;
  2248. this.height = source.height;
  2249. this.viewport.copy( source.viewport );
  2250. this.texture = source.texture.clone();
  2251. this.depthBuffer = source.depthBuffer;
  2252. this.stencilBuffer = source.stencilBuffer;
  2253. this.depthTexture = source.depthTexture;
  2254. return this;
  2255. },
  2256. dispose: function () {
  2257. this.dispatchEvent( { type: 'dispose' } );
  2258. }
  2259. } );
  2260. /**
  2261. * @author Mugen87 / https://github.com/Mugen87
  2262. * @author Matt DesLauriers / @mattdesl
  2263. */
  2264. function WebGLMultisampleRenderTarget( width, height, options ) {
  2265. WebGLRenderTarget.call( this, width, height, options );
  2266. this.samples = 4;
  2267. }
  2268. WebGLMultisampleRenderTarget.prototype = Object.assign( Object.create( WebGLRenderTarget.prototype ), {
  2269. constructor: WebGLMultisampleRenderTarget,
  2270. isWebGLMultisampleRenderTarget: true,
  2271. copy: function ( source ) {
  2272. WebGLRenderTarget.prototype.copy.call( this, source );
  2273. this.samples = source.samples;
  2274. return this;
  2275. }
  2276. } );
  2277. /**
  2278. * @author alteredq / http://alteredqualia.com
  2279. */
  2280. function WebGLRenderTargetCube( width, height, options ) {
  2281. WebGLRenderTarget.call( this, width, height, options );
  2282. }
  2283. WebGLRenderTargetCube.prototype = Object.create( WebGLRenderTarget.prototype );
  2284. WebGLRenderTargetCube.prototype.constructor = WebGLRenderTargetCube;
  2285. WebGLRenderTargetCube.prototype.isWebGLRenderTargetCube = true;
  2286. /**
  2287. * @author alteredq / http://alteredqualia.com/
  2288. */
  2289. function DataTexture( data, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, encoding ) {
  2290. Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding );
  2291. this.image = { data: data, width: width, height: height };
  2292. this.magFilter = magFilter !== undefined ? magFilter : NearestFilter;
  2293. this.minFilter = minFilter !== undefined ? minFilter : NearestFilter;
  2294. this.generateMipmaps = false;
  2295. this.flipY = false;
  2296. this.unpackAlignment = 1;
  2297. }
  2298. DataTexture.prototype = Object.create( Texture.prototype );
  2299. DataTexture.prototype.constructor = DataTexture;
  2300. DataTexture.prototype.isDataTexture = true;
  2301. /**
  2302. * @author bhouston / http://clara.io
  2303. * @author WestLangley / http://github.com/WestLangley
  2304. */
  2305. function Box3( min, max ) {
  2306. this.min = ( min !== undefined ) ? min : new Vector3( + Infinity, + Infinity, + Infinity );
  2307. this.max = ( max !== undefined ) ? max : new Vector3( - Infinity, - Infinity, - Infinity );
  2308. }
  2309. Object.assign( Box3.prototype, {
  2310. isBox3: true,
  2311. set: function ( min, max ) {
  2312. this.min.copy( min );
  2313. this.max.copy( max );
  2314. return this;
  2315. },
  2316. setFromArray: function ( array ) {
  2317. var minX = + Infinity;
  2318. var minY = + Infinity;
  2319. var minZ = + Infinity;
  2320. var maxX = - Infinity;
  2321. var maxY = - Infinity;
  2322. var maxZ = - Infinity;
  2323. for ( var i = 0, l = array.length; i < l; i += 3 ) {
  2324. var x = array[ i ];
  2325. var y = array[ i + 1 ];
  2326. var z = array[ i + 2 ];
  2327. if ( x < minX ) minX = x;
  2328. if ( y < minY ) minY = y;
  2329. if ( z < minZ ) minZ = z;
  2330. if ( x > maxX ) maxX = x;
  2331. if ( y > maxY ) maxY = y;
  2332. if ( z > maxZ ) maxZ = z;
  2333. }
  2334. this.min.set( minX, minY, minZ );
  2335. this.max.set( maxX, maxY, maxZ );
  2336. return this;
  2337. },
  2338. setFromBufferAttribute: function ( attribute ) {
  2339. var minX = + Infinity;
  2340. var minY = + Infinity;
  2341. var minZ = + Infinity;
  2342. var maxX = - Infinity;
  2343. var maxY = - Infinity;
  2344. var maxZ = - Infinity;
  2345. for ( var i = 0, l = attribute.count; i < l; i ++ ) {
  2346. var x = attribute.getX( i );
  2347. var y = attribute.getY( i );
  2348. var z = attribute.getZ( i );
  2349. if ( x < minX ) minX = x;
  2350. if ( y < minY ) minY = y;
  2351. if ( z < minZ ) minZ = z;
  2352. if ( x > maxX ) maxX = x;
  2353. if ( y > maxY ) maxY = y;
  2354. if ( z > maxZ ) maxZ = z;
  2355. }
  2356. this.min.set( minX, minY, minZ );
  2357. this.max.set( maxX, maxY, maxZ );
  2358. return this;
  2359. },
  2360. setFromPoints: function ( points ) {
  2361. this.makeEmpty();
  2362. for ( var i = 0, il = points.length; i < il; i ++ ) {
  2363. this.expandByPoint( points[ i ] );
  2364. }
  2365. return this;
  2366. },
  2367. setFromCenterAndSize: function () {
  2368. var v1 = new Vector3();
  2369. return function setFromCenterAndSize( center, size ) {
  2370. var halfSize = v1.copy( size ).multiplyScalar( 0.5 );
  2371. this.min.copy( center ).sub( halfSize );
  2372. this.max.copy( center ).add( halfSize );
  2373. return this;
  2374. };
  2375. }(),
  2376. setFromObject: function ( object ) {
  2377. this.makeEmpty();
  2378. return this.expandByObject( object );
  2379. },
  2380. clone: function () {
  2381. return new this.constructor().copy( this );
  2382. },
  2383. copy: function ( box ) {
  2384. this.min.copy( box.min );
  2385. this.max.copy( box.max );
  2386. return this;
  2387. },
  2388. makeEmpty: function () {
  2389. this.min.x = this.min.y = this.min.z = + Infinity;
  2390. this.max.x = this.max.y = this.max.z = - Infinity;
  2391. return this;
  2392. },
  2393. isEmpty: function () {
  2394. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  2395. return ( this.max.x < this.min.x ) || ( this.max.y < this.min.y ) || ( this.max.z < this.min.z );
  2396. },
  2397. getCenter: function ( target ) {
  2398. if ( target === undefined ) {
  2399. console.warn( 'THREE.Box3: .getCenter() target is now required' );
  2400. target = new Vector3();
  2401. }
  2402. return this.isEmpty() ? target.set( 0, 0, 0 ) : target.addVectors( this.min, this.max ).multiplyScalar( 0.5 );
  2403. },
  2404. getSize: function ( target ) {
  2405. if ( target === undefined ) {
  2406. console.warn( 'THREE.Box3: .getSize() target is now required' );
  2407. target = new Vector3();
  2408. }
  2409. return this.isEmpty() ? target.set( 0, 0, 0 ) : target.subVectors( this.max, this.min );
  2410. },
  2411. expandByPoint: function ( point ) {
  2412. this.min.min( point );
  2413. this.max.max( point );
  2414. return this;
  2415. },
  2416. expandByVector: function ( vector ) {
  2417. this.min.sub( vector );
  2418. this.max.add( vector );
  2419. return this;
  2420. },
  2421. expandByScalar: function ( scalar ) {
  2422. this.min.addScalar( - scalar );
  2423. this.max.addScalar( scalar );
  2424. return this;
  2425. },
  2426. expandByObject: function () {
  2427. // Computes the world-axis-aligned bounding box of an object (including its children),
  2428. // accounting for both the object's, and children's, world transforms
  2429. var scope, i, l;
  2430. var v1 = new Vector3();
  2431. function traverse( node ) {
  2432. var geometry = node.geometry;
  2433. if ( geometry !== undefined ) {
  2434. if ( geometry.isGeometry ) {
  2435. var vertices = geometry.vertices;
  2436. for ( i = 0, l = vertices.length; i < l; i ++ ) {
  2437. v1.copy( vertices[ i ] );
  2438. v1.applyMatrix4( node.matrixWorld );
  2439. scope.expandByPoint( v1 );
  2440. }
  2441. } else if ( geometry.isBufferGeometry ) {
  2442. var attribute = geometry.attributes.position;
  2443. if ( attribute !== undefined ) {
  2444. for ( i = 0, l = attribute.count; i < l; i ++ ) {
  2445. v1.fromBufferAttribute( attribute, i ).applyMatrix4( node.matrixWorld );
  2446. scope.expandByPoint( v1 );
  2447. }
  2448. }
  2449. }
  2450. }
  2451. }
  2452. return function expandByObject( object ) {
  2453. scope = this;
  2454. object.updateMatrixWorld( true );
  2455. object.traverse( traverse );
  2456. return this;
  2457. };
  2458. }(),
  2459. containsPoint: function ( point ) {
  2460. return point.x < this.min.x || point.x > this.max.x ||
  2461. point.y < this.min.y || point.y > this.max.y ||
  2462. point.z < this.min.z || point.z > this.max.z ? false : true;
  2463. },
  2464. containsBox: function ( box ) {
  2465. return this.min.x <= box.min.x && box.max.x <= this.max.x &&
  2466. this.min.y <= box.min.y && box.max.y <= this.max.y &&
  2467. this.min.z <= box.min.z && box.max.z <= this.max.z;
  2468. },
  2469. getParameter: function ( point, target ) {
  2470. // This can potentially have a divide by zero if the box
  2471. // has a size dimension of 0.
  2472. if ( target === undefined ) {
  2473. console.warn( 'THREE.Box3: .getParameter() target is now required' );
  2474. target = new Vector3();
  2475. }
  2476. return target.set(
  2477. ( point.x - this.min.x ) / ( this.max.x - this.min.x ),
  2478. ( point.y - this.min.y ) / ( this.max.y - this.min.y ),
  2479. ( point.z - this.min.z ) / ( this.max.z - this.min.z )
  2480. );
  2481. },
  2482. intersectsBox: function ( box ) {
  2483. // using 6 splitting planes to rule out intersections.
  2484. return box.max.x < this.min.x || box.min.x > this.max.x ||
  2485. box.max.y < this.min.y || box.min.y > this.max.y ||
  2486. box.max.z < this.min.z || box.min.z > this.max.z ? false : true;
  2487. },
  2488. intersectsSphere: ( function () {
  2489. var closestPoint = new Vector3();
  2490. return function intersectsSphere( sphere ) {
  2491. // Find the point on the AABB closest to the sphere center.
  2492. this.clampPoint( sphere.center, closestPoint );
  2493. // If that point is inside the sphere, the AABB and sphere intersect.
  2494. return closestPoint.distanceToSquared( sphere.center ) <= ( sphere.radius * sphere.radius );
  2495. };
  2496. } )(),
  2497. intersectsPlane: function ( plane ) {
  2498. // We compute the minimum and maximum dot product values. If those values
  2499. // are on the same side (back or front) of the plane, then there is no intersection.
  2500. var min, max;
  2501. if ( plane.normal.x > 0 ) {
  2502. min = plane.normal.x * this.min.x;
  2503. max = plane.normal.x * this.max.x;
  2504. } else {
  2505. min = plane.normal.x * this.max.x;
  2506. max = plane.normal.x * this.min.x;
  2507. }
  2508. if ( plane.normal.y > 0 ) {
  2509. min += plane.normal.y * this.min.y;
  2510. max += plane.normal.y * this.max.y;
  2511. } else {
  2512. min += plane.normal.y * this.max.y;
  2513. max += plane.normal.y * this.min.y;
  2514. }
  2515. if ( plane.normal.z > 0 ) {
  2516. min += plane.normal.z * this.min.z;
  2517. max += plane.normal.z * this.max.z;
  2518. } else {
  2519. min += plane.normal.z * this.max.z;
  2520. max += plane.normal.z * this.min.z;
  2521. }
  2522. return ( min <= - plane.constant && max >= - plane.constant );
  2523. },
  2524. intersectsTriangle: ( function () {
  2525. // triangle centered vertices
  2526. var v0 = new Vector3();
  2527. var v1 = new Vector3();
  2528. var v2 = new Vector3();
  2529. // triangle edge vectors
  2530. var f0 = new Vector3();
  2531. var f1 = new Vector3();
  2532. var f2 = new Vector3();
  2533. var testAxis = new Vector3();
  2534. var center = new Vector3();
  2535. var extents = new Vector3();
  2536. var triangleNormal = new Vector3();
  2537. function satForAxes( axes ) {
  2538. var i, j;
  2539. for ( i = 0, j = axes.length - 3; i <= j; i += 3 ) {
  2540. testAxis.fromArray( axes, i );
  2541. // project the aabb onto the seperating axis
  2542. var r = extents.x * Math.abs( testAxis.x ) + extents.y * Math.abs( testAxis.y ) + extents.z * Math.abs( testAxis.z );
  2543. // project all 3 vertices of the triangle onto the seperating axis
  2544. var p0 = v0.dot( testAxis );
  2545. var p1 = v1.dot( testAxis );
  2546. var p2 = v2.dot( testAxis );
  2547. // actual test, basically see if either of the most extreme of the triangle points intersects r
  2548. if ( Math.max( - Math.max( p0, p1, p2 ), Math.min( p0, p1, p2 ) ) > r ) {
  2549. // points of the projected triangle are outside the projected half-length of the aabb
  2550. // the axis is seperating and we can exit
  2551. return false;
  2552. }
  2553. }
  2554. return true;
  2555. }
  2556. return function intersectsTriangle( triangle ) {
  2557. if ( this.isEmpty() ) {
  2558. return false;
  2559. }
  2560. // compute box center and extents
  2561. this.getCenter( center );
  2562. extents.subVectors( this.max, center );
  2563. // translate triangle to aabb origin
  2564. v0.subVectors( triangle.a, center );
  2565. v1.subVectors( triangle.b, center );
  2566. v2.subVectors( triangle.c, center );
  2567. // compute edge vectors for triangle
  2568. f0.subVectors( v1, v0 );
  2569. f1.subVectors( v2, v1 );
  2570. f2.subVectors( v0, v2 );
  2571. // test against axes that are given by cross product combinations of the edges of the triangle and the edges of the aabb
  2572. // 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
  2573. // axis_ij = u_i x f_j (u0, u1, u2 = face normals of aabb = x,y,z axes vectors since aabb is axis aligned)
  2574. var axes = [
  2575. 0, - f0.z, f0.y, 0, - f1.z, f1.y, 0, - f2.z, f2.y,
  2576. f0.z, 0, - f0.x, f1.z, 0, - f1.x, f2.z, 0, - f2.x,
  2577. - f0.y, f0.x, 0, - f1.y, f1.x, 0, - f2.y, f2.x, 0
  2578. ];
  2579. if ( ! satForAxes( axes ) ) {
  2580. return false;
  2581. }
  2582. // test 3 face normals from the aabb
  2583. axes = [ 1, 0, 0, 0, 1, 0, 0, 0, 1 ];
  2584. if ( ! satForAxes( axes ) ) {
  2585. return false;
  2586. }
  2587. // finally testing the face normal of the triangle
  2588. // use already existing triangle edge vectors here
  2589. triangleNormal.crossVectors( f0, f1 );
  2590. axes = [ triangleNormal.x, triangleNormal.y, triangleNormal.z ];
  2591. return satForAxes( axes );
  2592. };
  2593. } )(),
  2594. clampPoint: function ( point, target ) {
  2595. if ( target === undefined ) {
  2596. console.warn( 'THREE.Box3: .clampPoint() target is now required' );
  2597. target = new Vector3();
  2598. }
  2599. return target.copy( point ).clamp( this.min, this.max );
  2600. },
  2601. distanceToPoint: function () {
  2602. var v1 = new Vector3();
  2603. return function distanceToPoint( point ) {
  2604. var clampedPoint = v1.copy( point ).clamp( this.min, this.max );
  2605. return clampedPoint.sub( point ).length();
  2606. };
  2607. }(),
  2608. getBoundingSphere: function () {
  2609. var v1 = new Vector3();
  2610. return function getBoundingSphere( target ) {
  2611. if ( target === undefined ) {
  2612. console.error( 'THREE.Box3: .getBoundingSphere() target is now required' );
  2613. //target = new Sphere(); // removed to avoid cyclic dependency
  2614. }
  2615. this.getCenter( target.center );
  2616. target.radius = this.getSize( v1 ).length() * 0.5;
  2617. return target;
  2618. };
  2619. }(),
  2620. intersect: function ( box ) {
  2621. this.min.max( box.min );
  2622. this.max.min( box.max );
  2623. // 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.
  2624. if ( this.isEmpty() ) this.makeEmpty();
  2625. return this;
  2626. },
  2627. union: function ( box ) {
  2628. this.min.min( box.min );
  2629. this.max.max( box.max );
  2630. return this;
  2631. },
  2632. applyMatrix4: function () {
  2633. var points = [
  2634. new Vector3(),
  2635. new Vector3(),
  2636. new Vector3(),
  2637. new Vector3(),
  2638. new Vector3(),
  2639. new Vector3(),
  2640. new Vector3(),
  2641. new Vector3()
  2642. ];
  2643. return function applyMatrix4( matrix ) {
  2644. // transform of empty box is an empty box.
  2645. if ( this.isEmpty() ) return this;
  2646. // NOTE: I am using a binary pattern to specify all 2^3 combinations below
  2647. points[ 0 ].set( this.min.x, this.min.y, this.min.z ).applyMatrix4( matrix ); // 000
  2648. points[ 1 ].set( this.min.x, this.min.y, this.max.z ).applyMatrix4( matrix ); // 001
  2649. points[ 2 ].set( this.min.x, this.max.y, this.min.z ).applyMatrix4( matrix ); // 010
  2650. points[ 3 ].set( this.min.x, this.max.y, this.max.z ).applyMatrix4( matrix ); // 011
  2651. points[ 4 ].set( this.max.x, this.min.y, this.min.z ).applyMatrix4( matrix ); // 100
  2652. points[ 5 ].set( this.max.x, this.min.y, this.max.z ).applyMatrix4( matrix ); // 101
  2653. points[ 6 ].set( this.max.x, this.max.y, this.min.z ).applyMatrix4( matrix ); // 110
  2654. points[ 7 ].set( this.max.x, this.max.y, this.max.z ).applyMatrix4( matrix ); // 111
  2655. this.setFromPoints( points );
  2656. return this;
  2657. };
  2658. }(),
  2659. translate: function ( offset ) {
  2660. this.min.add( offset );
  2661. this.max.add( offset );
  2662. return this;
  2663. },
  2664. equals: function ( box ) {
  2665. return box.min.equals( this.min ) && box.max.equals( this.max );
  2666. }
  2667. } );
  2668. /**
  2669. * @author bhouston / http://clara.io
  2670. * @author mrdoob / http://mrdoob.com/
  2671. */
  2672. function Sphere( center, radius ) {
  2673. this.center = ( center !== undefined ) ? center : new Vector3();
  2674. this.radius = ( radius !== undefined ) ? radius : 0;
  2675. }
  2676. Object.assign( Sphere.prototype, {
  2677. set: function ( center, radius ) {
  2678. this.center.copy( center );
  2679. this.radius = radius;
  2680. return this;
  2681. },
  2682. setFromPoints: function () {
  2683. var box = new Box3();
  2684. return function setFromPoints( points, optionalCenter ) {
  2685. var center = this.center;
  2686. if ( optionalCenter !== undefined ) {
  2687. center.copy( optionalCenter );
  2688. } else {
  2689. box.setFromPoints( points ).getCenter( center );
  2690. }
  2691. var maxRadiusSq = 0;
  2692. for ( var i = 0, il = points.length; i < il; i ++ ) {
  2693. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( points[ i ] ) );
  2694. }
  2695. this.radius = Math.sqrt( maxRadiusSq );
  2696. return this;
  2697. };
  2698. }(),
  2699. clone: function () {
  2700. return new this.constructor().copy( this );
  2701. },
  2702. copy: function ( sphere ) {
  2703. this.center.copy( sphere.center );
  2704. this.radius = sphere.radius;
  2705. return this;
  2706. },
  2707. empty: function () {
  2708. return ( this.radius <= 0 );
  2709. },
  2710. containsPoint: function ( point ) {
  2711. return ( point.distanceToSquared( this.center ) <= ( this.radius * this.radius ) );
  2712. },
  2713. distanceToPoint: function ( point ) {
  2714. return ( point.distanceTo( this.center ) - this.radius );
  2715. },
  2716. intersectsSphere: function ( sphere ) {
  2717. var radiusSum = this.radius + sphere.radius;
  2718. return sphere.center.distanceToSquared( this.center ) <= ( radiusSum * radiusSum );
  2719. },
  2720. intersectsBox: function ( box ) {
  2721. return box.intersectsSphere( this );
  2722. },
  2723. intersectsPlane: function ( plane ) {
  2724. return Math.abs( plane.distanceToPoint( this.center ) ) <= this.radius;
  2725. },
  2726. clampPoint: function ( point, target ) {
  2727. var deltaLengthSq = this.center.distanceToSquared( point );
  2728. if ( target === undefined ) {
  2729. console.warn( 'THREE.Sphere: .clampPoint() target is now required' );
  2730. target = new Vector3();
  2731. }
  2732. target.copy( point );
  2733. if ( deltaLengthSq > ( this.radius * this.radius ) ) {
  2734. target.sub( this.center ).normalize();
  2735. target.multiplyScalar( this.radius ).add( this.center );
  2736. }
  2737. return target;
  2738. },
  2739. getBoundingBox: function ( target ) {
  2740. if ( target === undefined ) {
  2741. console.warn( 'THREE.Sphere: .getBoundingBox() target is now required' );
  2742. target = new Box3();
  2743. }
  2744. target.set( this.center, this.center );
  2745. target.expandByScalar( this.radius );
  2746. return target;
  2747. },
  2748. applyMatrix4: function ( matrix ) {
  2749. this.center.applyMatrix4( matrix );
  2750. this.radius = this.radius * matrix.getMaxScaleOnAxis();
  2751. return this;
  2752. },
  2753. translate: function ( offset ) {
  2754. this.center.add( offset );
  2755. return this;
  2756. },
  2757. equals: function ( sphere ) {
  2758. return sphere.center.equals( this.center ) && ( sphere.radius === this.radius );
  2759. }
  2760. } );
  2761. /**
  2762. * @author bhouston / http://clara.io
  2763. */
  2764. function Plane( normal, constant ) {
  2765. // normal is assumed to be normalized
  2766. this.normal = ( normal !== undefined ) ? normal : new Vector3( 1, 0, 0 );
  2767. this.constant = ( constant !== undefined ) ? constant : 0;
  2768. }
  2769. Object.assign( Plane.prototype, {
  2770. set: function ( normal, constant ) {
  2771. this.normal.copy( normal );
  2772. this.constant = constant;
  2773. return this;
  2774. },
  2775. setComponents: function ( x, y, z, w ) {
  2776. this.normal.set( x, y, z );
  2777. this.constant = w;
  2778. return this;
  2779. },
  2780. setFromNormalAndCoplanarPoint: function ( normal, point ) {
  2781. this.normal.copy( normal );
  2782. this.constant = - point.dot( this.normal );
  2783. return this;
  2784. },
  2785. setFromCoplanarPoints: function () {
  2786. var v1 = new Vector3();
  2787. var v2 = new Vector3();
  2788. return function setFromCoplanarPoints( a, b, c ) {
  2789. var normal = v1.subVectors( c, b ).cross( v2.subVectors( a, b ) ).normalize();
  2790. // Q: should an error be thrown if normal is zero (e.g. degenerate plane)?
  2791. this.setFromNormalAndCoplanarPoint( normal, a );
  2792. return this;
  2793. };
  2794. }(),
  2795. clone: function () {
  2796. return new this.constructor().copy( this );
  2797. },
  2798. copy: function ( plane ) {
  2799. this.normal.copy( plane.normal );
  2800. this.constant = plane.constant;
  2801. return this;
  2802. },
  2803. normalize: function () {
  2804. // Note: will lead to a divide by zero if the plane is invalid.
  2805. var inverseNormalLength = 1.0 / this.normal.length();
  2806. this.normal.multiplyScalar( inverseNormalLength );
  2807. this.constant *= inverseNormalLength;
  2808. return this;
  2809. },
  2810. negate: function () {
  2811. this.constant *= - 1;
  2812. this.normal.negate();
  2813. return this;
  2814. },
  2815. distanceToPoint: function ( point ) {
  2816. return this.normal.dot( point ) + this.constant;
  2817. },
  2818. distanceToSphere: function ( sphere ) {
  2819. return this.distanceToPoint( sphere.center ) - sphere.radius;
  2820. },
  2821. projectPoint: function ( point, target ) {
  2822. if ( target === undefined ) {
  2823. console.warn( 'THREE.Plane: .projectPoint() target is now required' );
  2824. target = new Vector3();
  2825. }
  2826. return target.copy( this.normal ).multiplyScalar( - this.distanceToPoint( point ) ).add( point );
  2827. },
  2828. intersectLine: function () {
  2829. var v1 = new Vector3();
  2830. return function intersectLine( line, target ) {
  2831. if ( target === undefined ) {
  2832. console.warn( 'THREE.Plane: .intersectLine() target is now required' );
  2833. target = new Vector3();
  2834. }
  2835. var direction = line.delta( v1 );
  2836. var denominator = this.normal.dot( direction );
  2837. if ( denominator === 0 ) {
  2838. // line is coplanar, return origin
  2839. if ( this.distanceToPoint( line.start ) === 0 ) {
  2840. return target.copy( line.start );
  2841. }
  2842. // Unsure if this is the correct method to handle this case.
  2843. return undefined;
  2844. }
  2845. var t = - ( line.start.dot( this.normal ) + this.constant ) / denominator;
  2846. if ( t < 0 || t > 1 ) {
  2847. return undefined;
  2848. }
  2849. return target.copy( direction ).multiplyScalar( t ).add( line.start );
  2850. };
  2851. }(),
  2852. intersectsLine: function ( line ) {
  2853. // Note: this tests if a line intersects the plane, not whether it (or its end-points) are coplanar with it.
  2854. var startSign = this.distanceToPoint( line.start );
  2855. var endSign = this.distanceToPoint( line.end );
  2856. return ( startSign < 0 && endSign > 0 ) || ( endSign < 0 && startSign > 0 );
  2857. },
  2858. intersectsBox: function ( box ) {
  2859. return box.intersectsPlane( this );
  2860. },
  2861. intersectsSphere: function ( sphere ) {
  2862. return sphere.intersectsPlane( this );
  2863. },
  2864. coplanarPoint: function ( target ) {
  2865. if ( target === undefined ) {
  2866. console.warn( 'THREE.Plane: .coplanarPoint() target is now required' );
  2867. target = new Vector3();
  2868. }
  2869. return target.copy( this.normal ).multiplyScalar( - this.constant );
  2870. },
  2871. applyMatrix4: function () {
  2872. var v1 = new Vector3();
  2873. var m1 = new Matrix3();
  2874. return function applyMatrix4( matrix, optionalNormalMatrix ) {
  2875. var normalMatrix = optionalNormalMatrix || m1.getNormalMatrix( matrix );
  2876. var referencePoint = this.coplanarPoint( v1 ).applyMatrix4( matrix );
  2877. var normal = this.normal.applyMatrix3( normalMatrix ).normalize();
  2878. this.constant = - referencePoint.dot( normal );
  2879. return this;
  2880. };
  2881. }(),
  2882. translate: function ( offset ) {
  2883. this.constant -= offset.dot( this.normal );
  2884. return this;
  2885. },
  2886. equals: function ( plane ) {
  2887. return plane.normal.equals( this.normal ) && ( plane.constant === this.constant );
  2888. }
  2889. } );
  2890. /**
  2891. * @author mrdoob / http://mrdoob.com/
  2892. * @author alteredq / http://alteredqualia.com/
  2893. * @author bhouston / http://clara.io
  2894. */
  2895. function Frustum( p0, p1, p2, p3, p4, p5 ) {
  2896. this.planes = [
  2897. ( p0 !== undefined ) ? p0 : new Plane(),
  2898. ( p1 !== undefined ) ? p1 : new Plane(),
  2899. ( p2 !== undefined ) ? p2 : new Plane(),
  2900. ( p3 !== undefined ) ? p3 : new Plane(),
  2901. ( p4 !== undefined ) ? p4 : new Plane(),
  2902. ( p5 !== undefined ) ? p5 : new Plane()
  2903. ];
  2904. }
  2905. Object.assign( Frustum.prototype, {
  2906. set: function ( p0, p1, p2, p3, p4, p5 ) {
  2907. var planes = this.planes;
  2908. planes[ 0 ].copy( p0 );
  2909. planes[ 1 ].copy( p1 );
  2910. planes[ 2 ].copy( p2 );
  2911. planes[ 3 ].copy( p3 );
  2912. planes[ 4 ].copy( p4 );
  2913. planes[ 5 ].copy( p5 );
  2914. return this;
  2915. },
  2916. clone: function () {
  2917. return new this.constructor().copy( this );
  2918. },
  2919. copy: function ( frustum ) {
  2920. var planes = this.planes;
  2921. for ( var i = 0; i < 6; i ++ ) {
  2922. planes[ i ].copy( frustum.planes[ i ] );
  2923. }
  2924. return this;
  2925. },
  2926. setFromMatrix: function ( m ) {
  2927. var planes = this.planes;
  2928. var me = m.elements;
  2929. var me0 = me[ 0 ], me1 = me[ 1 ], me2 = me[ 2 ], me3 = me[ 3 ];
  2930. var me4 = me[ 4 ], me5 = me[ 5 ], me6 = me[ 6 ], me7 = me[ 7 ];
  2931. var me8 = me[ 8 ], me9 = me[ 9 ], me10 = me[ 10 ], me11 = me[ 11 ];
  2932. var me12 = me[ 12 ], me13 = me[ 13 ], me14 = me[ 14 ], me15 = me[ 15 ];
  2933. planes[ 0 ].setComponents( me3 - me0, me7 - me4, me11 - me8, me15 - me12 ).normalize();
  2934. planes[ 1 ].setComponents( me3 + me0, me7 + me4, me11 + me8, me15 + me12 ).normalize();
  2935. planes[ 2 ].setComponents( me3 + me1, me7 + me5, me11 + me9, me15 + me13 ).normalize();
  2936. planes[ 3 ].setComponents( me3 - me1, me7 - me5, me11 - me9, me15 - me13 ).normalize();
  2937. planes[ 4 ].setComponents( me3 - me2, me7 - me6, me11 - me10, me15 - me14 ).normalize();
  2938. planes[ 5 ].setComponents( me3 + me2, me7 + me6, me11 + me10, me15 + me14 ).normalize();
  2939. return this;
  2940. },
  2941. intersectsObject: function () {
  2942. var sphere = new Sphere();
  2943. return function intersectsObject( object ) {
  2944. var geometry = object.geometry;
  2945. if ( geometry.boundingSphere === null )
  2946. geometry.computeBoundingSphere();
  2947. sphere.copy( geometry.boundingSphere )
  2948. .applyMatrix4( object.matrixWorld );
  2949. return this.intersectsSphere( sphere );
  2950. };
  2951. }(),
  2952. intersectsSprite: function () {
  2953. var sphere = new Sphere();
  2954. return function intersectsSprite( sprite ) {
  2955. sphere.center.set( 0, 0, 0 );
  2956. sphere.radius = 0.7071067811865476;
  2957. sphere.applyMatrix4( sprite.matrixWorld );
  2958. return this.intersectsSphere( sphere );
  2959. };
  2960. }(),
  2961. intersectsSphere: function ( sphere ) {
  2962. var planes = this.planes;
  2963. var center = sphere.center;
  2964. var negRadius = - sphere.radius;
  2965. for ( var i = 0; i < 6; i ++ ) {
  2966. var distance = planes[ i ].distanceToPoint( center );
  2967. if ( distance < negRadius ) {
  2968. return false;
  2969. }
  2970. }
  2971. return true;
  2972. },
  2973. intersectsBox: function () {
  2974. var p = new Vector3();
  2975. return function intersectsBox( box ) {
  2976. var planes = this.planes;
  2977. for ( var i = 0; i < 6; i ++ ) {
  2978. var plane = planes[ i ];
  2979. // corner at max distance
  2980. p.x = plane.normal.x > 0 ? box.max.x : box.min.x;
  2981. p.y = plane.normal.y > 0 ? box.max.y : box.min.y;
  2982. p.z = plane.normal.z > 0 ? box.max.z : box.min.z;
  2983. if ( plane.distanceToPoint( p ) < 0 ) {
  2984. return false;
  2985. }
  2986. }
  2987. return true;
  2988. };
  2989. }(),
  2990. containsPoint: function ( point ) {
  2991. var planes = this.planes;
  2992. for ( var i = 0; i < 6; i ++ ) {
  2993. if ( planes[ i ].distanceToPoint( point ) < 0 ) {
  2994. return false;
  2995. }
  2996. }
  2997. return true;
  2998. }
  2999. } );
  3000. /**
  3001. * @author mrdoob / http://mrdoob.com/
  3002. * @author supereggbert / http://www.paulbrunt.co.uk/
  3003. * @author philogb / http://blog.thejit.org/
  3004. * @author jordi_ros / http://plattsoft.com
  3005. * @author D1plo1d / http://github.com/D1plo1d
  3006. * @author alteredq / http://alteredqualia.com/
  3007. * @author mikael emtinger / http://gomo.se/
  3008. * @author timknip / http://www.floorplanner.com/
  3009. * @author bhouston / http://clara.io
  3010. * @author WestLangley / http://github.com/WestLangley
  3011. */
  3012. function Matrix4() {
  3013. this.elements = [
  3014. 1, 0, 0, 0,
  3015. 0, 1, 0, 0,
  3016. 0, 0, 1, 0,
  3017. 0, 0, 0, 1
  3018. ];
  3019. if ( arguments.length > 0 ) {
  3020. console.error( 'THREE.Matrix4: the constructor no longer reads arguments. use .set() instead.' );
  3021. }
  3022. }
  3023. Object.assign( Matrix4.prototype, {
  3024. isMatrix4: true,
  3025. set: function ( n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44 ) {
  3026. var te = this.elements;
  3027. te[ 0 ] = n11; te[ 4 ] = n12; te[ 8 ] = n13; te[ 12 ] = n14;
  3028. te[ 1 ] = n21; te[ 5 ] = n22; te[ 9 ] = n23; te[ 13 ] = n24;
  3029. te[ 2 ] = n31; te[ 6 ] = n32; te[ 10 ] = n33; te[ 14 ] = n34;
  3030. te[ 3 ] = n41; te[ 7 ] = n42; te[ 11 ] = n43; te[ 15 ] = n44;
  3031. return this;
  3032. },
  3033. identity: function () {
  3034. this.set(
  3035. 1, 0, 0, 0,
  3036. 0, 1, 0, 0,
  3037. 0, 0, 1, 0,
  3038. 0, 0, 0, 1
  3039. );
  3040. return this;
  3041. },
  3042. clone: function () {
  3043. return new Matrix4().fromArray( this.elements );
  3044. },
  3045. copy: function ( m ) {
  3046. var te = this.elements;
  3047. var me = m.elements;
  3048. te[ 0 ] = me[ 0 ]; te[ 1 ] = me[ 1 ]; te[ 2 ] = me[ 2 ]; te[ 3 ] = me[ 3 ];
  3049. te[ 4 ] = me[ 4 ]; te[ 5 ] = me[ 5 ]; te[ 6 ] = me[ 6 ]; te[ 7 ] = me[ 7 ];
  3050. te[ 8 ] = me[ 8 ]; te[ 9 ] = me[ 9 ]; te[ 10 ] = me[ 10 ]; te[ 11 ] = me[ 11 ];
  3051. te[ 12 ] = me[ 12 ]; te[ 13 ] = me[ 13 ]; te[ 14 ] = me[ 14 ]; te[ 15 ] = me[ 15 ];
  3052. return this;
  3053. },
  3054. copyPosition: function ( m ) {
  3055. var te = this.elements, me = m.elements;
  3056. te[ 12 ] = me[ 12 ];
  3057. te[ 13 ] = me[ 13 ];
  3058. te[ 14 ] = me[ 14 ];
  3059. return this;
  3060. },
  3061. extractBasis: function ( xAxis, yAxis, zAxis ) {
  3062. xAxis.setFromMatrixColumn( this, 0 );
  3063. yAxis.setFromMatrixColumn( this, 1 );
  3064. zAxis.setFromMatrixColumn( this, 2 );
  3065. return this;
  3066. },
  3067. makeBasis: function ( xAxis, yAxis, zAxis ) {
  3068. this.set(
  3069. xAxis.x, yAxis.x, zAxis.x, 0,
  3070. xAxis.y, yAxis.y, zAxis.y, 0,
  3071. xAxis.z, yAxis.z, zAxis.z, 0,
  3072. 0, 0, 0, 1
  3073. );
  3074. return this;
  3075. },
  3076. extractRotation: function () {
  3077. var v1 = new Vector3();
  3078. return function extractRotation( m ) {
  3079. // this method does not support reflection matrices
  3080. var te = this.elements;
  3081. var me = m.elements;
  3082. var scaleX = 1 / v1.setFromMatrixColumn( m, 0 ).length();
  3083. var scaleY = 1 / v1.setFromMatrixColumn( m, 1 ).length();
  3084. var scaleZ = 1 / v1.setFromMatrixColumn( m, 2 ).length();
  3085. te[ 0 ] = me[ 0 ] * scaleX;
  3086. te[ 1 ] = me[ 1 ] * scaleX;
  3087. te[ 2 ] = me[ 2 ] * scaleX;
  3088. te[ 3 ] = 0;
  3089. te[ 4 ] = me[ 4 ] * scaleY;
  3090. te[ 5 ] = me[ 5 ] * scaleY;
  3091. te[ 6 ] = me[ 6 ] * scaleY;
  3092. te[ 7 ] = 0;
  3093. te[ 8 ] = me[ 8 ] * scaleZ;
  3094. te[ 9 ] = me[ 9 ] * scaleZ;
  3095. te[ 10 ] = me[ 10 ] * scaleZ;
  3096. te[ 11 ] = 0;
  3097. te[ 12 ] = 0;
  3098. te[ 13 ] = 0;
  3099. te[ 14 ] = 0;
  3100. te[ 15 ] = 1;
  3101. return this;
  3102. };
  3103. }(),
  3104. makeRotationFromEuler: function ( euler ) {
  3105. if ( ! ( euler && euler.isEuler ) ) {
  3106. console.error( 'THREE.Matrix4: .makeRotationFromEuler() now expects a Euler rotation rather than a Vector3 and order.' );
  3107. }
  3108. var te = this.elements;
  3109. var x = euler.x, y = euler.y, z = euler.z;
  3110. var a = Math.cos( x ), b = Math.sin( x );
  3111. var c = Math.cos( y ), d = Math.sin( y );
  3112. var e = Math.cos( z ), f = Math.sin( z );
  3113. if ( euler.order === 'XYZ' ) {
  3114. var ae = a * e, af = a * f, be = b * e, bf = b * f;
  3115. te[ 0 ] = c * e;
  3116. te[ 4 ] = - c * f;
  3117. te[ 8 ] = d;
  3118. te[ 1 ] = af + be * d;
  3119. te[ 5 ] = ae - bf * d;
  3120. te[ 9 ] = - b * c;
  3121. te[ 2 ] = bf - ae * d;
  3122. te[ 6 ] = be + af * d;
  3123. te[ 10 ] = a * c;
  3124. } else if ( euler.order === 'YXZ' ) {
  3125. var ce = c * e, cf = c * f, de = d * e, df = d * f;
  3126. te[ 0 ] = ce + df * b;
  3127. te[ 4 ] = de * b - cf;
  3128. te[ 8 ] = a * d;
  3129. te[ 1 ] = a * f;
  3130. te[ 5 ] = a * e;
  3131. te[ 9 ] = - b;
  3132. te[ 2 ] = cf * b - de;
  3133. te[ 6 ] = df + ce * b;
  3134. te[ 10 ] = a * c;
  3135. } else if ( euler.order === 'ZXY' ) {
  3136. var ce = c * e, cf = c * f, de = d * e, df = d * f;
  3137. te[ 0 ] = ce - df * b;
  3138. te[ 4 ] = - a * f;
  3139. te[ 8 ] = de + cf * b;
  3140. te[ 1 ] = cf + de * b;
  3141. te[ 5 ] = a * e;
  3142. te[ 9 ] = df - ce * b;
  3143. te[ 2 ] = - a * d;
  3144. te[ 6 ] = b;
  3145. te[ 10 ] = a * c;
  3146. } else if ( euler.order === 'ZYX' ) {
  3147. var ae = a * e, af = a * f, be = b * e, bf = b * f;
  3148. te[ 0 ] = c * e;
  3149. te[ 4 ] = be * d - af;
  3150. te[ 8 ] = ae * d + bf;
  3151. te[ 1 ] = c * f;
  3152. te[ 5 ] = bf * d + ae;
  3153. te[ 9 ] = af * d - be;
  3154. te[ 2 ] = - d;
  3155. te[ 6 ] = b * c;
  3156. te[ 10 ] = a * c;
  3157. } else if ( euler.order === 'YZX' ) {
  3158. var ac = a * c, ad = a * d, bc = b * c, bd = b * d;
  3159. te[ 0 ] = c * e;
  3160. te[ 4 ] = bd - ac * f;
  3161. te[ 8 ] = bc * f + ad;
  3162. te[ 1 ] = f;
  3163. te[ 5 ] = a * e;
  3164. te[ 9 ] = - b * e;
  3165. te[ 2 ] = - d * e;
  3166. te[ 6 ] = ad * f + bc;
  3167. te[ 10 ] = ac - bd * f;
  3168. } else if ( euler.order === 'XZY' ) {
  3169. var ac = a * c, ad = a * d, bc = b * c, bd = b * d;
  3170. te[ 0 ] = c * e;
  3171. te[ 4 ] = - f;
  3172. te[ 8 ] = d * e;
  3173. te[ 1 ] = ac * f + bd;
  3174. te[ 5 ] = a * e;
  3175. te[ 9 ] = ad * f - bc;
  3176. te[ 2 ] = bc * f - ad;
  3177. te[ 6 ] = b * e;
  3178. te[ 10 ] = bd * f + ac;
  3179. }
  3180. // bottom row
  3181. te[ 3 ] = 0;
  3182. te[ 7 ] = 0;
  3183. te[ 11 ] = 0;
  3184. // last column
  3185. te[ 12 ] = 0;
  3186. te[ 13 ] = 0;
  3187. te[ 14 ] = 0;
  3188. te[ 15 ] = 1;
  3189. return this;
  3190. },
  3191. makeRotationFromQuaternion: function () {
  3192. var zero = new Vector3( 0, 0, 0 );
  3193. var one = new Vector3( 1, 1, 1 );
  3194. return function makeRotationFromQuaternion( q ) {
  3195. return this.compose( zero, q, one );
  3196. };
  3197. }(),
  3198. lookAt: function () {
  3199. var x = new Vector3();
  3200. var y = new Vector3();
  3201. var z = new Vector3();
  3202. return function lookAt( eye, target, up ) {
  3203. var te = this.elements;
  3204. z.subVectors( eye, target );
  3205. if ( z.lengthSq() === 0 ) {
  3206. // eye and target are in the same position
  3207. z.z = 1;
  3208. }
  3209. z.normalize();
  3210. x.crossVectors( up, z );
  3211. if ( x.lengthSq() === 0 ) {
  3212. // up and z are parallel
  3213. if ( Math.abs( up.z ) === 1 ) {
  3214. z.x += 0.0001;
  3215. } else {
  3216. z.z += 0.0001;
  3217. }
  3218. z.normalize();
  3219. x.crossVectors( up, z );
  3220. }
  3221. x.normalize();
  3222. y.crossVectors( z, x );
  3223. te[ 0 ] = x.x; te[ 4 ] = y.x; te[ 8 ] = z.x;
  3224. te[ 1 ] = x.y; te[ 5 ] = y.y; te[ 9 ] = z.y;
  3225. te[ 2 ] = x.z; te[ 6 ] = y.z; te[ 10 ] = z.z;
  3226. return this;
  3227. };
  3228. }(),
  3229. multiply: function ( m, n ) {
  3230. if ( n !== undefined ) {
  3231. console.warn( 'THREE.Matrix4: .multiply() now only accepts one argument. Use .multiplyMatrices( a, b ) instead.' );
  3232. return this.multiplyMatrices( m, n );
  3233. }
  3234. return this.multiplyMatrices( this, m );
  3235. },
  3236. premultiply: function ( m ) {
  3237. return this.multiplyMatrices( m, this );
  3238. },
  3239. multiplyMatrices: function ( a, b ) {
  3240. var ae = a.elements;
  3241. var be = b.elements;
  3242. var te = this.elements;
  3243. var a11 = ae[ 0 ], a12 = ae[ 4 ], a13 = ae[ 8 ], a14 = ae[ 12 ];
  3244. var a21 = ae[ 1 ], a22 = ae[ 5 ], a23 = ae[ 9 ], a24 = ae[ 13 ];
  3245. var a31 = ae[ 2 ], a32 = ae[ 6 ], a33 = ae[ 10 ], a34 = ae[ 14 ];
  3246. var a41 = ae[ 3 ], a42 = ae[ 7 ], a43 = ae[ 11 ], a44 = ae[ 15 ];
  3247. var b11 = be[ 0 ], b12 = be[ 4 ], b13 = be[ 8 ], b14 = be[ 12 ];
  3248. var b21 = be[ 1 ], b22 = be[ 5 ], b23 = be[ 9 ], b24 = be[ 13 ];
  3249. var b31 = be[ 2 ], b32 = be[ 6 ], b33 = be[ 10 ], b34 = be[ 14 ];
  3250. var b41 = be[ 3 ], b42 = be[ 7 ], b43 = be[ 11 ], b44 = be[ 15 ];
  3251. te[ 0 ] = a11 * b11 + a12 * b21 + a13 * b31 + a14 * b41;
  3252. te[ 4 ] = a11 * b12 + a12 * b22 + a13 * b32 + a14 * b42;
  3253. te[ 8 ] = a11 * b13 + a12 * b23 + a13 * b33 + a14 * b43;
  3254. te[ 12 ] = a11 * b14 + a12 * b24 + a13 * b34 + a14 * b44;
  3255. te[ 1 ] = a21 * b11 + a22 * b21 + a23 * b31 + a24 * b41;
  3256. te[ 5 ] = a21 * b12 + a22 * b22 + a23 * b32 + a24 * b42;
  3257. te[ 9 ] = a21 * b13 + a22 * b23 + a23 * b33 + a24 * b43;
  3258. te[ 13 ] = a21 * b14 + a22 * b24 + a23 * b34 + a24 * b44;
  3259. te[ 2 ] = a31 * b11 + a32 * b21 + a33 * b31 + a34 * b41;
  3260. te[ 6 ] = a31 * b12 + a32 * b22 + a33 * b32 + a34 * b42;
  3261. te[ 10 ] = a31 * b13 + a32 * b23 + a33 * b33 + a34 * b43;
  3262. te[ 14 ] = a31 * b14 + a32 * b24 + a33 * b34 + a34 * b44;
  3263. te[ 3 ] = a41 * b11 + a42 * b21 + a43 * b31 + a44 * b41;
  3264. te[ 7 ] = a41 * b12 + a42 * b22 + a43 * b32 + a44 * b42;
  3265. te[ 11 ] = a41 * b13 + a42 * b23 + a43 * b33 + a44 * b43;
  3266. te[ 15 ] = a41 * b14 + a42 * b24 + a43 * b34 + a44 * b44;
  3267. return this;
  3268. },
  3269. multiplyScalar: function ( s ) {
  3270. var te = this.elements;
  3271. te[ 0 ] *= s; te[ 4 ] *= s; te[ 8 ] *= s; te[ 12 ] *= s;
  3272. te[ 1 ] *= s; te[ 5 ] *= s; te[ 9 ] *= s; te[ 13 ] *= s;
  3273. te[ 2 ] *= s; te[ 6 ] *= s; te[ 10 ] *= s; te[ 14 ] *= s;
  3274. te[ 3 ] *= s; te[ 7 ] *= s; te[ 11 ] *= s; te[ 15 ] *= s;
  3275. return this;
  3276. },
  3277. applyToBufferAttribute: function () {
  3278. var v1 = new Vector3();
  3279. return function applyToBufferAttribute( attribute ) {
  3280. for ( var i = 0, l = attribute.count; i < l; i ++ ) {
  3281. v1.x = attribute.getX( i );
  3282. v1.y = attribute.getY( i );
  3283. v1.z = attribute.getZ( i );
  3284. v1.applyMatrix4( this );
  3285. attribute.setXYZ( i, v1.x, v1.y, v1.z );
  3286. }
  3287. return attribute;
  3288. };
  3289. }(),
  3290. determinant: function () {
  3291. var te = this.elements;
  3292. var n11 = te[ 0 ], n12 = te[ 4 ], n13 = te[ 8 ], n14 = te[ 12 ];
  3293. var n21 = te[ 1 ], n22 = te[ 5 ], n23 = te[ 9 ], n24 = te[ 13 ];
  3294. var n31 = te[ 2 ], n32 = te[ 6 ], n33 = te[ 10 ], n34 = te[ 14 ];
  3295. var n41 = te[ 3 ], n42 = te[ 7 ], n43 = te[ 11 ], n44 = te[ 15 ];
  3296. //TODO: make this more efficient
  3297. //( based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm )
  3298. return (
  3299. n41 * (
  3300. + n14 * n23 * n32
  3301. - n13 * n24 * n32
  3302. - n14 * n22 * n33
  3303. + n12 * n24 * n33
  3304. + n13 * n22 * n34
  3305. - n12 * n23 * n34
  3306. ) +
  3307. n42 * (
  3308. + n11 * n23 * n34
  3309. - n11 * n24 * n33
  3310. + n14 * n21 * n33
  3311. - n13 * n21 * n34
  3312. + n13 * n24 * n31
  3313. - n14 * n23 * n31
  3314. ) +
  3315. n43 * (
  3316. + n11 * n24 * n32
  3317. - n11 * n22 * n34
  3318. - n14 * n21 * n32
  3319. + n12 * n21 * n34
  3320. + n14 * n22 * n31
  3321. - n12 * n24 * n31
  3322. ) +
  3323. n44 * (
  3324. - n13 * n22 * n31
  3325. - n11 * n23 * n32
  3326. + n11 * n22 * n33
  3327. + n13 * n21 * n32
  3328. - n12 * n21 * n33
  3329. + n12 * n23 * n31
  3330. )
  3331. );
  3332. },
  3333. transpose: function () {
  3334. var te = this.elements;
  3335. var tmp;
  3336. tmp = te[ 1 ]; te[ 1 ] = te[ 4 ]; te[ 4 ] = tmp;
  3337. tmp = te[ 2 ]; te[ 2 ] = te[ 8 ]; te[ 8 ] = tmp;
  3338. tmp = te[ 6 ]; te[ 6 ] = te[ 9 ]; te[ 9 ] = tmp;
  3339. tmp = te[ 3 ]; te[ 3 ] = te[ 12 ]; te[ 12 ] = tmp;
  3340. tmp = te[ 7 ]; te[ 7 ] = te[ 13 ]; te[ 13 ] = tmp;
  3341. tmp = te[ 11 ]; te[ 11 ] = te[ 14 ]; te[ 14 ] = tmp;
  3342. return this;
  3343. },
  3344. setPosition: function ( x, y, z ) {
  3345. var te = this.elements;
  3346. if ( x.isVector3 ) {
  3347. te[ 12 ] = x.x;
  3348. te[ 13 ] = x.y;
  3349. te[ 14 ] = x.z;
  3350. } else {
  3351. te[ 12 ] = x;
  3352. te[ 13 ] = y;
  3353. te[ 14 ] = z;
  3354. }
  3355. return this;
  3356. },
  3357. getInverse: function ( m, throwOnDegenerate ) {
  3358. // based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm
  3359. var te = this.elements,
  3360. me = m.elements,
  3361. n11 = me[ 0 ], n21 = me[ 1 ], n31 = me[ 2 ], n41 = me[ 3 ],
  3362. n12 = me[ 4 ], n22 = me[ 5 ], n32 = me[ 6 ], n42 = me[ 7 ],
  3363. n13 = me[ 8 ], n23 = me[ 9 ], n33 = me[ 10 ], n43 = me[ 11 ],
  3364. n14 = me[ 12 ], n24 = me[ 13 ], n34 = me[ 14 ], n44 = me[ 15 ],
  3365. t11 = n23 * n34 * n42 - n24 * n33 * n42 + n24 * n32 * n43 - n22 * n34 * n43 - n23 * n32 * n44 + n22 * n33 * n44,
  3366. t12 = n14 * n33 * n42 - n13 * n34 * n42 - n14 * n32 * n43 + n12 * n34 * n43 + n13 * n32 * n44 - n12 * n33 * n44,
  3367. t13 = n13 * n24 * n42 - n14 * n23 * n42 + n14 * n22 * n43 - n12 * n24 * n43 - n13 * n22 * n44 + n12 * n23 * n44,
  3368. t14 = n14 * n23 * n32 - n13 * n24 * n32 - n14 * n22 * n33 + n12 * n24 * n33 + n13 * n22 * n34 - n12 * n23 * n34;
  3369. var det = n11 * t11 + n21 * t12 + n31 * t13 + n41 * t14;
  3370. if ( det === 0 ) {
  3371. var msg = "THREE.Matrix4: .getInverse() can't invert matrix, determinant is 0";
  3372. if ( throwOnDegenerate === true ) {
  3373. throw new Error( msg );
  3374. } else {
  3375. console.warn( msg );
  3376. }
  3377. return this.identity();
  3378. }
  3379. var detInv = 1 / det;
  3380. te[ 0 ] = t11 * detInv;
  3381. te[ 1 ] = ( n24 * n33 * n41 - n23 * n34 * n41 - n24 * n31 * n43 + n21 * n34 * n43 + n23 * n31 * n44 - n21 * n33 * n44 ) * detInv;
  3382. te[ 2 ] = ( n22 * n34 * n41 - n24 * n32 * n41 + n24 * n31 * n42 - n21 * n34 * n42 - n22 * n31 * n44 + n21 * n32 * n44 ) * detInv;
  3383. te[ 3 ] = ( n23 * n32 * n41 - n22 * n33 * n41 - n23 * n31 * n42 + n21 * n33 * n42 + n22 * n31 * n43 - n21 * n32 * n43 ) * detInv;
  3384. te[ 4 ] = t12 * detInv;
  3385. te[ 5 ] = ( n13 * n34 * n41 - n14 * n33 * n41 + n14 * n31 * n43 - n11 * n34 * n43 - n13 * n31 * n44 + n11 * n33 * n44 ) * detInv;
  3386. te[ 6 ] = ( n14 * n32 * n41 - n12 * n34 * n41 - n14 * n31 * n42 + n11 * n34 * n42 + n12 * n31 * n44 - n11 * n32 * n44 ) * detInv;
  3387. te[ 7 ] = ( n12 * n33 * n41 - n13 * n32 * n41 + n13 * n31 * n42 - n11 * n33 * n42 - n12 * n31 * n43 + n11 * n32 * n43 ) * detInv;
  3388. te[ 8 ] = t13 * detInv;
  3389. te[ 9 ] = ( n14 * n23 * n41 - n13 * n24 * n41 - n14 * n21 * n43 + n11 * n24 * n43 + n13 * n21 * n44 - n11 * n23 * n44 ) * detInv;
  3390. te[ 10 ] = ( n12 * n24 * n41 - n14 * n22 * n41 + n14 * n21 * n42 - n11 * n24 * n42 - n12 * n21 * n44 + n11 * n22 * n44 ) * detInv;
  3391. te[ 11 ] = ( n13 * n22 * n41 - n12 * n23 * n41 - n13 * n21 * n42 + n11 * n23 * n42 + n12 * n21 * n43 - n11 * n22 * n43 ) * detInv;
  3392. te[ 12 ] = t14 * detInv;
  3393. te[ 13 ] = ( n13 * n24 * n31 - n14 * n23 * n31 + n14 * n21 * n33 - n11 * n24 * n33 - n13 * n21 * n34 + n11 * n23 * n34 ) * detInv;
  3394. te[ 14 ] = ( n14 * n22 * n31 - n12 * n24 * n31 - n14 * n21 * n32 + n11 * n24 * n32 + n12 * n21 * n34 - n11 * n22 * n34 ) * detInv;
  3395. te[ 15 ] = ( n12 * n23 * n31 - n13 * n22 * n31 + n13 * n21 * n32 - n11 * n23 * n32 - n12 * n21 * n33 + n11 * n22 * n33 ) * detInv;
  3396. return this;
  3397. },
  3398. scale: function ( v ) {
  3399. var te = this.elements;
  3400. var x = v.x, y = v.y, z = v.z;
  3401. te[ 0 ] *= x; te[ 4 ] *= y; te[ 8 ] *= z;
  3402. te[ 1 ] *= x; te[ 5 ] *= y; te[ 9 ] *= z;
  3403. te[ 2 ] *= x; te[ 6 ] *= y; te[ 10 ] *= z;
  3404. te[ 3 ] *= x; te[ 7 ] *= y; te[ 11 ] *= z;
  3405. return this;
  3406. },
  3407. getMaxScaleOnAxis: function () {
  3408. var te = this.elements;
  3409. var scaleXSq = te[ 0 ] * te[ 0 ] + te[ 1 ] * te[ 1 ] + te[ 2 ] * te[ 2 ];
  3410. var scaleYSq = te[ 4 ] * te[ 4 ] + te[ 5 ] * te[ 5 ] + te[ 6 ] * te[ 6 ];
  3411. var scaleZSq = te[ 8 ] * te[ 8 ] + te[ 9 ] * te[ 9 ] + te[ 10 ] * te[ 10 ];
  3412. return Math.sqrt( Math.max( scaleXSq, scaleYSq, scaleZSq ) );
  3413. },
  3414. makeTranslation: function ( x, y, z ) {
  3415. this.set(
  3416. 1, 0, 0, x,
  3417. 0, 1, 0, y,
  3418. 0, 0, 1, z,
  3419. 0, 0, 0, 1
  3420. );
  3421. return this;
  3422. },
  3423. makeRotationX: function ( theta ) {
  3424. var c = Math.cos( theta ), s = Math.sin( theta );
  3425. this.set(
  3426. 1, 0, 0, 0,
  3427. 0, c, - s, 0,
  3428. 0, s, c, 0,
  3429. 0, 0, 0, 1
  3430. );
  3431. return this;
  3432. },
  3433. makeRotationY: function ( theta ) {
  3434. var c = Math.cos( theta ), s = Math.sin( theta );
  3435. this.set(
  3436. c, 0, s, 0,
  3437. 0, 1, 0, 0,
  3438. - s, 0, c, 0,
  3439. 0, 0, 0, 1
  3440. );
  3441. return this;
  3442. },
  3443. makeRotationZ: function ( theta ) {
  3444. var c = Math.cos( theta ), s = Math.sin( theta );
  3445. this.set(
  3446. c, - s, 0, 0,
  3447. s, c, 0, 0,
  3448. 0, 0, 1, 0,
  3449. 0, 0, 0, 1
  3450. );
  3451. return this;
  3452. },
  3453. makeRotationAxis: function ( axis, angle ) {
  3454. // Based on http://www.gamedev.net/reference/articles/article1199.asp
  3455. var c = Math.cos( angle );
  3456. var s = Math.sin( angle );
  3457. var t = 1 - c;
  3458. var x = axis.x, y = axis.y, z = axis.z;
  3459. var tx = t * x, ty = t * y;
  3460. this.set(
  3461. tx * x + c, tx * y - s * z, tx * z + s * y, 0,
  3462. tx * y + s * z, ty * y + c, ty * z - s * x, 0,
  3463. tx * z - s * y, ty * z + s * x, t * z * z + c, 0,
  3464. 0, 0, 0, 1
  3465. );
  3466. return this;
  3467. },
  3468. makeScale: function ( x, y, z ) {
  3469. this.set(
  3470. x, 0, 0, 0,
  3471. 0, y, 0, 0,
  3472. 0, 0, z, 0,
  3473. 0, 0, 0, 1
  3474. );
  3475. return this;
  3476. },
  3477. makeShear: function ( x, y, z ) {
  3478. this.set(
  3479. 1, y, z, 0,
  3480. x, 1, z, 0,
  3481. x, y, 1, 0,
  3482. 0, 0, 0, 1
  3483. );
  3484. return this;
  3485. },
  3486. compose: function ( position, quaternion, scale ) {
  3487. var te = this.elements;
  3488. var x = quaternion._x, y = quaternion._y, z = quaternion._z, w = quaternion._w;
  3489. var x2 = x + x, y2 = y + y, z2 = z + z;
  3490. var xx = x * x2, xy = x * y2, xz = x * z2;
  3491. var yy = y * y2, yz = y * z2, zz = z * z2;
  3492. var wx = w * x2, wy = w * y2, wz = w * z2;
  3493. var sx = scale.x, sy = scale.y, sz = scale.z;
  3494. te[ 0 ] = ( 1 - ( yy + zz ) ) * sx;
  3495. te[ 1 ] = ( xy + wz ) * sx;
  3496. te[ 2 ] = ( xz - wy ) * sx;
  3497. te[ 3 ] = 0;
  3498. te[ 4 ] = ( xy - wz ) * sy;
  3499. te[ 5 ] = ( 1 - ( xx + zz ) ) * sy;
  3500. te[ 6 ] = ( yz + wx ) * sy;
  3501. te[ 7 ] = 0;
  3502. te[ 8 ] = ( xz + wy ) * sz;
  3503. te[ 9 ] = ( yz - wx ) * sz;
  3504. te[ 10 ] = ( 1 - ( xx + yy ) ) * sz;
  3505. te[ 11 ] = 0;
  3506. te[ 12 ] = position.x;
  3507. te[ 13 ] = position.y;
  3508. te[ 14 ] = position.z;
  3509. te[ 15 ] = 1;
  3510. return this;
  3511. },
  3512. decompose: function () {
  3513. var vector = new Vector3();
  3514. var matrix = new Matrix4();
  3515. return function decompose( position, quaternion, scale ) {
  3516. var te = this.elements;
  3517. var sx = vector.set( te[ 0 ], te[ 1 ], te[ 2 ] ).length();
  3518. var sy = vector.set( te[ 4 ], te[ 5 ], te[ 6 ] ).length();
  3519. var sz = vector.set( te[ 8 ], te[ 9 ], te[ 10 ] ).length();
  3520. // if determine is negative, we need to invert one scale
  3521. var det = this.determinant();
  3522. if ( det < 0 ) sx = - sx;
  3523. position.x = te[ 12 ];
  3524. position.y = te[ 13 ];
  3525. position.z = te[ 14 ];
  3526. // scale the rotation part
  3527. matrix.copy( this );
  3528. var invSX = 1 / sx;
  3529. var invSY = 1 / sy;
  3530. var invSZ = 1 / sz;
  3531. matrix.elements[ 0 ] *= invSX;
  3532. matrix.elements[ 1 ] *= invSX;
  3533. matrix.elements[ 2 ] *= invSX;
  3534. matrix.elements[ 4 ] *= invSY;
  3535. matrix.elements[ 5 ] *= invSY;
  3536. matrix.elements[ 6 ] *= invSY;
  3537. matrix.elements[ 8 ] *= invSZ;
  3538. matrix.elements[ 9 ] *= invSZ;
  3539. matrix.elements[ 10 ] *= invSZ;
  3540. quaternion.setFromRotationMatrix( matrix );
  3541. scale.x = sx;
  3542. scale.y = sy;
  3543. scale.z = sz;
  3544. return this;
  3545. };
  3546. }(),
  3547. makePerspective: function ( left, right, top, bottom, near, far ) {
  3548. if ( far === undefined ) {
  3549. console.warn( 'THREE.Matrix4: .makePerspective() has been redefined and has a new signature. Please check the docs.' );
  3550. }
  3551. var te = this.elements;
  3552. var x = 2 * near / ( right - left );
  3553. var y = 2 * near / ( top - bottom );
  3554. var a = ( right + left ) / ( right - left );
  3555. var b = ( top + bottom ) / ( top - bottom );
  3556. var c = - ( far + near ) / ( far - near );
  3557. var d = - 2 * far * near / ( far - near );
  3558. te[ 0 ] = x; te[ 4 ] = 0; te[ 8 ] = a; te[ 12 ] = 0;
  3559. te[ 1 ] = 0; te[ 5 ] = y; te[ 9 ] = b; te[ 13 ] = 0;
  3560. te[ 2 ] = 0; te[ 6 ] = 0; te[ 10 ] = c; te[ 14 ] = d;
  3561. te[ 3 ] = 0; te[ 7 ] = 0; te[ 11 ] = - 1; te[ 15 ] = 0;
  3562. return this;
  3563. },
  3564. makeOrthographic: function ( left, right, top, bottom, near, far ) {
  3565. var te = this.elements;
  3566. var w = 1.0 / ( right - left );
  3567. var h = 1.0 / ( top - bottom );
  3568. var p = 1.0 / ( far - near );
  3569. var x = ( right + left ) * w;
  3570. var y = ( top + bottom ) * h;
  3571. var z = ( far + near ) * p;
  3572. te[ 0 ] = 2 * w; te[ 4 ] = 0; te[ 8 ] = 0; te[ 12 ] = - x;
  3573. te[ 1 ] = 0; te[ 5 ] = 2 * h; te[ 9 ] = 0; te[ 13 ] = - y;
  3574. te[ 2 ] = 0; te[ 6 ] = 0; te[ 10 ] = - 2 * p; te[ 14 ] = - z;
  3575. te[ 3 ] = 0; te[ 7 ] = 0; te[ 11 ] = 0; te[ 15 ] = 1;
  3576. return this;
  3577. },
  3578. equals: function ( matrix ) {
  3579. var te = this.elements;
  3580. var me = matrix.elements;
  3581. for ( var i = 0; i < 16; i ++ ) {
  3582. if ( te[ i ] !== me[ i ] ) return false;
  3583. }
  3584. return true;
  3585. },
  3586. fromArray: function ( array, offset ) {
  3587. if ( offset === undefined ) offset = 0;
  3588. for ( var i = 0; i < 16; i ++ ) {
  3589. this.elements[ i ] = array[ i + offset ];
  3590. }
  3591. return this;
  3592. },
  3593. toArray: function ( array, offset ) {
  3594. if ( array === undefined ) array = [];
  3595. if ( offset === undefined ) offset = 0;
  3596. var te = this.elements;
  3597. array[ offset ] = te[ 0 ];
  3598. array[ offset + 1 ] = te[ 1 ];
  3599. array[ offset + 2 ] = te[ 2 ];
  3600. array[ offset + 3 ] = te[ 3 ];
  3601. array[ offset + 4 ] = te[ 4 ];
  3602. array[ offset + 5 ] = te[ 5 ];
  3603. array[ offset + 6 ] = te[ 6 ];
  3604. array[ offset + 7 ] = te[ 7 ];
  3605. array[ offset + 8 ] = te[ 8 ];
  3606. array[ offset + 9 ] = te[ 9 ];
  3607. array[ offset + 10 ] = te[ 10 ];
  3608. array[ offset + 11 ] = te[ 11 ];
  3609. array[ offset + 12 ] = te[ 12 ];
  3610. array[ offset + 13 ] = te[ 13 ];
  3611. array[ offset + 14 ] = te[ 14 ];
  3612. array[ offset + 15 ] = te[ 15 ];
  3613. return array;
  3614. }
  3615. } );
  3616. var alphamap_fragment = "#ifdef USE_ALPHAMAP\n\tdiffuseColor.a *= texture2D( alphaMap, vUv ).g;\n#endif";
  3617. var alphamap_pars_fragment = "#ifdef USE_ALPHAMAP\n\tuniform sampler2D alphaMap;\n#endif";
  3618. var alphatest_fragment = "#ifdef ALPHATEST\n\tif ( diffuseColor.a < ALPHATEST ) discard;\n#endif";
  3619. 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";
  3620. var aomap_pars_fragment = "#ifdef USE_AOMAP\n\tuniform sampler2D aoMap;\n\tuniform float aoMapIntensity;\n#endif";
  3621. var begin_vertex = "vec3 transformed = vec3( position );";
  3622. var beginnormal_vertex = "vec3 objectNormal = vec3( normal );\n#ifdef USE_TANGENT\n\tvec3 objectTangent = vec3( tangent.xyz );\n#endif";
  3623. 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}\nvec3 F_Schlick_RoughnessDependent( const in vec3 F0, const in float dotNV, const in float roughness ) {\n\tfloat fresnel = exp2( ( -5.55473 * dotNV - 6.98316 ) * dotNV );\n\tvec3 Fr = max( vec3( 1.0 - roughness ), F0 ) - F0;\n\treturn Fr * fresnel + F0;\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_RoughnessDependent( specularColor, dotNV, roughness );\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}";
  3624. 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";
  3625. 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";
  3626. 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";
  3627. var clipping_planes_pars_vertex = "#if NUM_CLIPPING_PLANES > 0 && ! defined( PHYSICAL ) && ! defined( PHONG ) && ! defined( MATCAP )\n\tvarying vec3 vViewPosition;\n#endif";
  3628. var clipping_planes_vertex = "#if NUM_CLIPPING_PLANES > 0 && ! defined( PHYSICAL ) && ! defined( PHONG ) && ! defined( MATCAP )\n\tvViewPosition = - mvPosition.xyz;\n#endif";
  3629. var color_fragment = "#ifdef USE_COLOR\n\tdiffuseColor.rgb *= vColor;\n#endif";
  3630. var color_pars_fragment = "#ifdef USE_COLOR\n\tvarying vec3 vColor;\n#endif";
  3631. var color_pars_vertex = "#ifdef USE_COLOR\n\tvarying vec3 vColor;\n#endif";
  3632. var color_vertex = "#ifdef USE_COLOR\n\tvColor.xyz = color.xyz;\n#endif";
  3633. 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}";
  3634. 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";
  3635. 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";
  3636. var displacementmap_pars_vertex = "#ifdef USE_DISPLACEMENTMAP\n\tuniform sampler2D displacementMap;\n\tuniform float displacementScale;\n\tuniform float displacementBias;\n#endif";
  3637. var displacementmap_vertex = "#ifdef USE_DISPLACEMENTMAP\n\ttransformed += normalize( objectNormal ) * ( texture2D( displacementMap, uv ).x * displacementScale + displacementBias );\n#endif";
  3638. var emissivemap_fragment = "#ifdef USE_EMISSIVEMAP\n\tvec4 emissiveColor = texture2D( emissiveMap, vUv );\n\temissiveColor.rgb = emissiveMapTexelToLinear( emissiveColor ).rgb;\n\ttotalEmissiveRadiance *= emissiveColor.rgb;\n#endif";
  3639. var emissivemap_pars_fragment = "#ifdef USE_EMISSIVEMAP\n\tuniform sampler2D emissiveMap;\n#endif";
  3640. var encodings_fragment = "gl_FragColor = linearToOutputTexel( gl_FragColor );";
  3641. 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}";
  3642. 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";
  3643. 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";
  3644. 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";
  3645. 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";
  3646. var fog_vertex = "#ifdef USE_FOG\n\tfogDepth = -mvPosition.z;\n#endif";
  3647. var fog_pars_vertex = "#ifdef USE_FOG\n\tvarying float fogDepth;\n#endif";
  3648. 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";
  3649. 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";
  3650. 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";
  3651. var lightmap_fragment = "#ifdef USE_LIGHTMAP\n\treflectedLight.indirectDiffuse += PI * texture2D( lightMap, vUv2 ).xyz * lightMapIntensity;\n#endif";
  3652. var lightmap_pars_fragment = "#ifdef USE_LIGHTMAP\n\tuniform sampler2D lightMap;\n\tuniform float lightMapIntensity;\n#endif";
  3653. 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";
  3654. var lights_pars_begin = "uniform vec3 ambientLightColor;\nuniform vec3 lightProbe[ 9 ];\nvec3 shGetIrradianceAt( in vec3 normal, in vec3 shCoefficients[ 9 ] ) {\n\tfloat x = normal.x, y = normal.y, z = normal.z;\n\tvec3 result = shCoefficients[ 0 ] * 0.886227;\n\tresult += shCoefficients[ 1 ] * 2.0 * 0.511664 * y;\n\tresult += shCoefficients[ 2 ] * 2.0 * 0.511664 * z;\n\tresult += shCoefficients[ 3 ] * 2.0 * 0.511664 * x;\n\tresult += shCoefficients[ 4 ] * 2.0 * 0.429043 * x * y;\n\tresult += shCoefficients[ 5 ] * 2.0 * 0.429043 * y * z;\n\tresult += shCoefficients[ 6 ] * ( 0.743125 * z * z - 0.247708 );\n\tresult += shCoefficients[ 7 ] * 2.0 * 0.429043 * x * z;\n\tresult += shCoefficients[ 8 ] * 0.429043 * ( x * x - y * y );\n\treturn result;\n}\nvec3 getLightProbeIrradiance( const in vec3 lightProbe[ 9 ], const in GeometricContext geometry ) {\n\tvec3 worldNormal = inverseTransformDirection( geometry.normal, viewMatrix );\n\tvec3 irradiance = shGetIrradianceAt( worldNormal, lightProbe );\n\treturn irradiance;\n}\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";
  3655. 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";
  3656. var lights_phong_fragment = "BlinnPhongMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;\nmaterial.specularColor = specular;\nmaterial.specularShininess = shininess;\nmaterial.specularStrength = specularStrength;";
  3657. 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)";
  3658. 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";
  3659. 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 * ( 1.0 - ( singleScattering + multiScattering ) );\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}";
  3660. 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\tirradiance += getLightProbeIrradiance( lightProbe, geometry );\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";
  3661. 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";
  3662. 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";
  3663. var logdepthbuf_fragment = "#if defined( USE_LOGDEPTHBUF ) && defined( USE_LOGDEPTHBUF_EXT )\n\tgl_FragDepthEXT = log2( vFragDepth ) * logDepthBufFC * 0.5;\n#endif";
  3664. var logdepthbuf_pars_fragment = "#if defined( USE_LOGDEPTHBUF ) && defined( USE_LOGDEPTHBUF_EXT )\n\tuniform float logDepthBufFC;\n\tvarying float vFragDepth;\n#endif";
  3665. 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";
  3666. 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";
  3667. var map_fragment = "#ifdef USE_MAP\n\tvec4 texelColor = texture2D( map, vUv );\n\ttexelColor = mapTexelToLinear( texelColor );\n\tdiffuseColor *= texelColor;\n#endif";
  3668. var map_pars_fragment = "#ifdef USE_MAP\n\tuniform sampler2D map;\n#endif";
  3669. 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";
  3670. var map_particle_pars_fragment = "#ifdef USE_MAP\n\tuniform mat3 uvTransform;\n\tuniform sampler2D map;\n#endif";
  3671. var metalnessmap_fragment = "float metalnessFactor = metalness;\n#ifdef USE_METALNESSMAP\n\tvec4 texelMetalness = texture2D( metalnessMap, vUv );\n\tmetalnessFactor *= texelMetalness.b;\n#endif";
  3672. var metalnessmap_pars_fragment = "#ifdef USE_METALNESSMAP\n\tuniform sampler2D metalnessMap;\n#endif";
  3673. 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";
  3674. 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";
  3675. 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";
  3676. 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";
  3677. 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";
  3678. 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";
  3679. 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}";
  3680. var premultiplied_alpha_fragment = "#ifdef PREMULTIPLIED_ALPHA\n\tgl_FragColor.rgb *= gl_FragColor.a;\n#endif";
  3681. var project_vertex = "vec4 mvPosition = modelViewMatrix * vec4( transformed, 1.0 );\ngl_Position = projectionMatrix * mvPosition;";
  3682. var dithering_fragment = "#if defined( DITHERING )\n\tgl_FragColor.rgb = dithering( gl_FragColor.rgb );\n#endif";
  3683. 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";
  3684. var roughnessmap_fragment = "float roughnessFactor = roughness;\n#ifdef USE_ROUGHNESSMAP\n\tvec4 texelRoughness = texture2D( roughnessMap, vUv );\n\troughnessFactor *= texelRoughness.g;\n#endif";
  3685. var roughnessmap_pars_fragment = "#ifdef USE_ROUGHNESSMAP\n\tuniform sampler2D roughnessMap;\n#endif";
  3686. 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";
  3687. 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";
  3688. 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";
  3689. 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}";
  3690. 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";
  3691. 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";
  3692. 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";
  3693. 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";
  3694. 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";
  3695. var specularmap_pars_fragment = "#ifdef USE_SPECULARMAP\n\tuniform sampler2D specularMap;\n#endif";
  3696. var tonemapping_fragment = "#if defined( TONE_MAPPING )\n\tgl_FragColor.rgb = toneMapping( gl_FragColor.rgb );\n#endif";
  3697. 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}";
  3698. 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";
  3699. 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";
  3700. 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";
  3701. var uv2_pars_fragment = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tvarying vec2 vUv2;\n#endif";
  3702. var uv2_pars_vertex = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tattribute vec2 uv2;\n\tvarying vec2 vUv2;\n#endif";
  3703. var uv2_vertex = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tvUv2 = uv2;\n#endif";
  3704. var worldpos_vertex = "#if defined( USE_ENVMAP ) || defined( DISTANCE ) || defined ( USE_SHADOWMAP )\n\tvec4 worldPosition = modelMatrix * vec4( transformed, 1.0 );\n#endif";
  3705. 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}";
  3706. 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}";
  3707. 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}";
  3708. 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}";
  3709. 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}";
  3710. 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}";
  3711. 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}";
  3712. 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}";
  3713. 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}";
  3714. 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}";
  3715. 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}";
  3716. 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}";
  3717. 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}";
  3718. 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}";
  3719. 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}";
  3720. 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}";
  3721. 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}";
  3722. 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}";
  3723. 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}";
  3724. 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}";
  3725. 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}";
  3726. 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}";
  3727. 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}";
  3728. 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}";
  3729. 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}";
  3730. 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}";
  3731. 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}";
  3732. 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}";
  3733. 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}";
  3734. 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}";
  3735. var ShaderChunk = {
  3736. alphamap_fragment: alphamap_fragment,
  3737. alphamap_pars_fragment: alphamap_pars_fragment,
  3738. alphatest_fragment: alphatest_fragment,
  3739. aomap_fragment: aomap_fragment,
  3740. aomap_pars_fragment: aomap_pars_fragment,
  3741. begin_vertex: begin_vertex,
  3742. beginnormal_vertex: beginnormal_vertex,
  3743. bsdfs: bsdfs,
  3744. bumpmap_pars_fragment: bumpmap_pars_fragment,
  3745. clipping_planes_fragment: clipping_planes_fragment,
  3746. clipping_planes_pars_fragment: clipping_planes_pars_fragment,
  3747. clipping_planes_pars_vertex: clipping_planes_pars_vertex,
  3748. clipping_planes_vertex: clipping_planes_vertex,
  3749. color_fragment: color_fragment,
  3750. color_pars_fragment: color_pars_fragment,
  3751. color_pars_vertex: color_pars_vertex,
  3752. color_vertex: color_vertex,
  3753. common: common,
  3754. cube_uv_reflection_fragment: cube_uv_reflection_fragment,
  3755. defaultnormal_vertex: defaultnormal_vertex,
  3756. displacementmap_pars_vertex: displacementmap_pars_vertex,
  3757. displacementmap_vertex: displacementmap_vertex,
  3758. emissivemap_fragment: emissivemap_fragment,
  3759. emissivemap_pars_fragment: emissivemap_pars_fragment,
  3760. encodings_fragment: encodings_fragment,
  3761. encodings_pars_fragment: encodings_pars_fragment,
  3762. envmap_fragment: envmap_fragment,
  3763. envmap_pars_fragment: envmap_pars_fragment,
  3764. envmap_pars_vertex: envmap_pars_vertex,
  3765. envmap_physical_pars_fragment: envmap_physical_pars_fragment,
  3766. envmap_vertex: envmap_vertex,
  3767. fog_vertex: fog_vertex,
  3768. fog_pars_vertex: fog_pars_vertex,
  3769. fog_fragment: fog_fragment,
  3770. fog_pars_fragment: fog_pars_fragment,
  3771. gradientmap_pars_fragment: gradientmap_pars_fragment,
  3772. lightmap_fragment: lightmap_fragment,
  3773. lightmap_pars_fragment: lightmap_pars_fragment,
  3774. lights_lambert_vertex: lights_lambert_vertex,
  3775. lights_pars_begin: lights_pars_begin,
  3776. lights_phong_fragment: lights_phong_fragment,
  3777. lights_phong_pars_fragment: lights_phong_pars_fragment,
  3778. lights_physical_fragment: lights_physical_fragment,
  3779. lights_physical_pars_fragment: lights_physical_pars_fragment,
  3780. lights_fragment_begin: lights_fragment_begin,
  3781. lights_fragment_maps: lights_fragment_maps,
  3782. lights_fragment_end: lights_fragment_end,
  3783. logdepthbuf_fragment: logdepthbuf_fragment,
  3784. logdepthbuf_pars_fragment: logdepthbuf_pars_fragment,
  3785. logdepthbuf_pars_vertex: logdepthbuf_pars_vertex,
  3786. logdepthbuf_vertex: logdepthbuf_vertex,
  3787. map_fragment: map_fragment,
  3788. map_pars_fragment: map_pars_fragment,
  3789. map_particle_fragment: map_particle_fragment,
  3790. map_particle_pars_fragment: map_particle_pars_fragment,
  3791. metalnessmap_fragment: metalnessmap_fragment,
  3792. metalnessmap_pars_fragment: metalnessmap_pars_fragment,
  3793. morphnormal_vertex: morphnormal_vertex,
  3794. morphtarget_pars_vertex: morphtarget_pars_vertex,
  3795. morphtarget_vertex: morphtarget_vertex,
  3796. normal_fragment_begin: normal_fragment_begin,
  3797. normal_fragment_maps: normal_fragment_maps,
  3798. normalmap_pars_fragment: normalmap_pars_fragment,
  3799. packing: packing,
  3800. premultiplied_alpha_fragment: premultiplied_alpha_fragment,
  3801. project_vertex: project_vertex,
  3802. dithering_fragment: dithering_fragment,
  3803. dithering_pars_fragment: dithering_pars_fragment,
  3804. roughnessmap_fragment: roughnessmap_fragment,
  3805. roughnessmap_pars_fragment: roughnessmap_pars_fragment,
  3806. shadowmap_pars_fragment: shadowmap_pars_fragment,
  3807. shadowmap_pars_vertex: shadowmap_pars_vertex,
  3808. shadowmap_vertex: shadowmap_vertex,
  3809. shadowmask_pars_fragment: shadowmask_pars_fragment,
  3810. skinbase_vertex: skinbase_vertex,
  3811. skinning_pars_vertex: skinning_pars_vertex,
  3812. skinning_vertex: skinning_vertex,
  3813. skinnormal_vertex: skinnormal_vertex,
  3814. specularmap_fragment: specularmap_fragment,
  3815. specularmap_pars_fragment: specularmap_pars_fragment,
  3816. tonemapping_fragment: tonemapping_fragment,
  3817. tonemapping_pars_fragment: tonemapping_pars_fragment,
  3818. uv_pars_fragment: uv_pars_fragment,
  3819. uv_pars_vertex: uv_pars_vertex,
  3820. uv_vertex: uv_vertex,
  3821. uv2_pars_fragment: uv2_pars_fragment,
  3822. uv2_pars_vertex: uv2_pars_vertex,
  3823. uv2_vertex: uv2_vertex,
  3824. worldpos_vertex: worldpos_vertex,
  3825. background_frag: background_frag,
  3826. background_vert: background_vert,
  3827. cube_frag: cube_frag,
  3828. cube_vert: cube_vert,
  3829. depth_frag: depth_frag,
  3830. depth_vert: depth_vert,
  3831. distanceRGBA_frag: distanceRGBA_frag,
  3832. distanceRGBA_vert: distanceRGBA_vert,
  3833. equirect_frag: equirect_frag,
  3834. equirect_vert: equirect_vert,
  3835. linedashed_frag: linedashed_frag,
  3836. linedashed_vert: linedashed_vert,
  3837. meshbasic_frag: meshbasic_frag,
  3838. meshbasic_vert: meshbasic_vert,
  3839. meshlambert_frag: meshlambert_frag,
  3840. meshlambert_vert: meshlambert_vert,
  3841. meshmatcap_frag: meshmatcap_frag,
  3842. meshmatcap_vert: meshmatcap_vert,
  3843. meshphong_frag: meshphong_frag,
  3844. meshphong_vert: meshphong_vert,
  3845. meshphysical_frag: meshphysical_frag,
  3846. meshphysical_vert: meshphysical_vert,
  3847. normal_frag: normal_frag,
  3848. normal_vert: normal_vert,
  3849. points_frag: points_frag,
  3850. points_vert: points_vert,
  3851. shadow_frag: shadow_frag,
  3852. shadow_vert: shadow_vert,
  3853. sprite_frag: sprite_frag,
  3854. sprite_vert: sprite_vert
  3855. };
  3856. /**
  3857. * Uniform Utilities
  3858. */
  3859. function cloneUniforms( src ) {
  3860. var dst = {};
  3861. for ( var u in src ) {
  3862. dst[ u ] = {};
  3863. for ( var p in src[ u ] ) {
  3864. var property = src[ u ][ p ];
  3865. if ( property && ( property.isColor ||
  3866. property.isMatrix3 || property.isMatrix4 ||
  3867. property.isVector2 || property.isVector3 || property.isVector4 ||
  3868. property.isTexture ) ) {
  3869. dst[ u ][ p ] = property.clone();
  3870. } else if ( Array.isArray( property ) ) {
  3871. dst[ u ][ p ] = property.slice();
  3872. } else {
  3873. dst[ u ][ p ] = property;
  3874. }
  3875. }
  3876. }
  3877. return dst;
  3878. }
  3879. function mergeUniforms( uniforms ) {
  3880. var merged = {};
  3881. for ( var u = 0; u < uniforms.length; u ++ ) {
  3882. var tmp = cloneUniforms( uniforms[ u ] );
  3883. for ( var p in tmp ) {
  3884. merged[ p ] = tmp[ p ];
  3885. }
  3886. }
  3887. return merged;
  3888. }
  3889. // Legacy
  3890. var UniformsUtils = { clone: cloneUniforms, merge: mergeUniforms };
  3891. /**
  3892. * @author mrdoob / http://mrdoob.com/
  3893. */
  3894. var ColorKeywords = { 'aliceblue': 0xF0F8FF, 'antiquewhite': 0xFAEBD7, 'aqua': 0x00FFFF, 'aquamarine': 0x7FFFD4, 'azure': 0xF0FFFF,
  3895. 'beige': 0xF5F5DC, 'bisque': 0xFFE4C4, 'black': 0x000000, 'blanchedalmond': 0xFFEBCD, 'blue': 0x0000FF, 'blueviolet': 0x8A2BE2,
  3896. 'brown': 0xA52A2A, 'burlywood': 0xDEB887, 'cadetblue': 0x5F9EA0, 'chartreuse': 0x7FFF00, 'chocolate': 0xD2691E, 'coral': 0xFF7F50,
  3897. 'cornflowerblue': 0x6495ED, 'cornsilk': 0xFFF8DC, 'crimson': 0xDC143C, 'cyan': 0x00FFFF, 'darkblue': 0x00008B, 'darkcyan': 0x008B8B,
  3898. 'darkgoldenrod': 0xB8860B, 'darkgray': 0xA9A9A9, 'darkgreen': 0x006400, 'darkgrey': 0xA9A9A9, 'darkkhaki': 0xBDB76B, 'darkmagenta': 0x8B008B,
  3899. 'darkolivegreen': 0x556B2F, 'darkorange': 0xFF8C00, 'darkorchid': 0x9932CC, 'darkred': 0x8B0000, 'darksalmon': 0xE9967A, 'darkseagreen': 0x8FBC8F,
  3900. 'darkslateblue': 0x483D8B, 'darkslategray': 0x2F4F4F, 'darkslategrey': 0x2F4F4F, 'darkturquoise': 0x00CED1, 'darkviolet': 0x9400D3,
  3901. 'deeppink': 0xFF1493, 'deepskyblue': 0x00BFFF, 'dimgray': 0x696969, 'dimgrey': 0x696969, 'dodgerblue': 0x1E90FF, 'firebrick': 0xB22222,
  3902. 'floralwhite': 0xFFFAF0, 'forestgreen': 0x228B22, 'fuchsia': 0xFF00FF, 'gainsboro': 0xDCDCDC, 'ghostwhite': 0xF8F8FF, 'gold': 0xFFD700,
  3903. 'goldenrod': 0xDAA520, 'gray': 0x808080, 'green': 0x008000, 'greenyellow': 0xADFF2F, 'grey': 0x808080, 'honeydew': 0xF0FFF0, 'hotpink': 0xFF69B4,
  3904. 'indianred': 0xCD5C5C, 'indigo': 0x4B0082, 'ivory': 0xFFFFF0, 'khaki': 0xF0E68C, 'lavender': 0xE6E6FA, 'lavenderblush': 0xFFF0F5, 'lawngreen': 0x7CFC00,
  3905. 'lemonchiffon': 0xFFFACD, 'lightblue': 0xADD8E6, 'lightcoral': 0xF08080, 'lightcyan': 0xE0FFFF, 'lightgoldenrodyellow': 0xFAFAD2, 'lightgray': 0xD3D3D3,
  3906. 'lightgreen': 0x90EE90, 'lightgrey': 0xD3D3D3, 'lightpink': 0xFFB6C1, 'lightsalmon': 0xFFA07A, 'lightseagreen': 0x20B2AA, 'lightskyblue': 0x87CEFA,
  3907. 'lightslategray': 0x778899, 'lightslategrey': 0x778899, 'lightsteelblue': 0xB0C4DE, 'lightyellow': 0xFFFFE0, 'lime': 0x00FF00, 'limegreen': 0x32CD32,
  3908. 'linen': 0xFAF0E6, 'magenta': 0xFF00FF, 'maroon': 0x800000, 'mediumaquamarine': 0x66CDAA, 'mediumblue': 0x0000CD, 'mediumorchid': 0xBA55D3,
  3909. 'mediumpurple': 0x9370DB, 'mediumseagreen': 0x3CB371, 'mediumslateblue': 0x7B68EE, 'mediumspringgreen': 0x00FA9A, 'mediumturquoise': 0x48D1CC,
  3910. 'mediumvioletred': 0xC71585, 'midnightblue': 0x191970, 'mintcream': 0xF5FFFA, 'mistyrose': 0xFFE4E1, 'moccasin': 0xFFE4B5, 'navajowhite': 0xFFDEAD,
  3911. 'navy': 0x000080, 'oldlace': 0xFDF5E6, 'olive': 0x808000, 'olivedrab': 0x6B8E23, 'orange': 0xFFA500, 'orangered': 0xFF4500, 'orchid': 0xDA70D6,
  3912. 'palegoldenrod': 0xEEE8AA, 'palegreen': 0x98FB98, 'paleturquoise': 0xAFEEEE, 'palevioletred': 0xDB7093, 'papayawhip': 0xFFEFD5, 'peachpuff': 0xFFDAB9,
  3913. 'peru': 0xCD853F, 'pink': 0xFFC0CB, 'plum': 0xDDA0DD, 'powderblue': 0xB0E0E6, 'purple': 0x800080, 'rebeccapurple': 0x663399, 'red': 0xFF0000, 'rosybrown': 0xBC8F8F,
  3914. 'royalblue': 0x4169E1, 'saddlebrown': 0x8B4513, 'salmon': 0xFA8072, 'sandybrown': 0xF4A460, 'seagreen': 0x2E8B57, 'seashell': 0xFFF5EE,
  3915. 'sienna': 0xA0522D, 'silver': 0xC0C0C0, 'skyblue': 0x87CEEB, 'slateblue': 0x6A5ACD, 'slategray': 0x708090, 'slategrey': 0x708090, 'snow': 0xFFFAFA,
  3916. 'springgreen': 0x00FF7F, 'steelblue': 0x4682B4, 'tan': 0xD2B48C, 'teal': 0x008080, 'thistle': 0xD8BFD8, 'tomato': 0xFF6347, 'turquoise': 0x40E0D0,
  3917. 'violet': 0xEE82EE, 'wheat': 0xF5DEB3, 'white': 0xFFFFFF, 'whitesmoke': 0xF5F5F5, 'yellow': 0xFFFF00, 'yellowgreen': 0x9ACD32 };
  3918. function Color( r, g, b ) {
  3919. if ( g === undefined && b === undefined ) {
  3920. // r is THREE.Color, hex or string
  3921. return this.set( r );
  3922. }
  3923. return this.setRGB( r, g, b );
  3924. }
  3925. Object.assign( Color.prototype, {
  3926. isColor: true,
  3927. r: 1, g: 1, b: 1,
  3928. set: function ( value ) {
  3929. if ( value && value.isColor ) {
  3930. this.copy( value );
  3931. } else if ( typeof value === 'number' ) {
  3932. this.setHex( value );
  3933. } else if ( typeof value === 'string' ) {
  3934. this.setStyle( value );
  3935. }
  3936. return this;
  3937. },
  3938. setScalar: function ( scalar ) {
  3939. this.r = scalar;
  3940. this.g = scalar;
  3941. this.b = scalar;
  3942. return this;
  3943. },
  3944. setHex: function ( hex ) {
  3945. hex = Math.floor( hex );
  3946. this.r = ( hex >> 16 & 255 ) / 255;
  3947. this.g = ( hex >> 8 & 255 ) / 255;
  3948. this.b = ( hex & 255 ) / 255;
  3949. return this;
  3950. },
  3951. setRGB: function ( r, g, b ) {
  3952. this.r = r;
  3953. this.g = g;
  3954. this.b = b;
  3955. return this;
  3956. },
  3957. setHSL: function () {
  3958. function hue2rgb( p, q, t ) {
  3959. if ( t < 0 ) t += 1;
  3960. if ( t > 1 ) t -= 1;
  3961. if ( t < 1 / 6 ) return p + ( q - p ) * 6 * t;
  3962. if ( t < 1 / 2 ) return q;
  3963. if ( t < 2 / 3 ) return p + ( q - p ) * 6 * ( 2 / 3 - t );
  3964. return p;
  3965. }
  3966. return function setHSL( h, s, l ) {
  3967. // h,s,l ranges are in 0.0 - 1.0
  3968. h = _Math.euclideanModulo( h, 1 );
  3969. s = _Math.clamp( s, 0, 1 );
  3970. l = _Math.clamp( l, 0, 1 );
  3971. if ( s === 0 ) {
  3972. this.r = this.g = this.b = l;
  3973. } else {
  3974. var p = l <= 0.5 ? l * ( 1 + s ) : l + s - ( l * s );
  3975. var q = ( 2 * l ) - p;
  3976. this.r = hue2rgb( q, p, h + 1 / 3 );
  3977. this.g = hue2rgb( q, p, h );
  3978. this.b = hue2rgb( q, p, h - 1 / 3 );
  3979. }
  3980. return this;
  3981. };
  3982. }(),
  3983. setStyle: function ( style ) {
  3984. function handleAlpha( string ) {
  3985. if ( string === undefined ) return;
  3986. if ( parseFloat( string ) < 1 ) {
  3987. console.warn( 'THREE.Color: Alpha component of ' + style + ' will be ignored.' );
  3988. }
  3989. }
  3990. var m;
  3991. if ( m = /^((?:rgb|hsl)a?)\(\s*([^\)]*)\)/.exec( style ) ) {
  3992. // rgb / hsl
  3993. var color;
  3994. var name = m[ 1 ];
  3995. var components = m[ 2 ];
  3996. switch ( name ) {
  3997. case 'rgb':
  3998. case 'rgba':
  3999. if ( color = /^(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec( components ) ) {
  4000. // rgb(255,0,0) rgba(255,0,0,0.5)
  4001. this.r = Math.min( 255, parseInt( color[ 1 ], 10 ) ) / 255;
  4002. this.g = Math.min( 255, parseInt( color[ 2 ], 10 ) ) / 255;
  4003. this.b = Math.min( 255, parseInt( color[ 3 ], 10 ) ) / 255;
  4004. handleAlpha( color[ 5 ] );
  4005. return this;
  4006. }
  4007. if ( color = /^(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec( components ) ) {
  4008. // rgb(100%,0%,0%) rgba(100%,0%,0%,0.5)
  4009. this.r = Math.min( 100, parseInt( color[ 1 ], 10 ) ) / 100;
  4010. this.g = Math.min( 100, parseInt( color[ 2 ], 10 ) ) / 100;
  4011. this.b = Math.min( 100, parseInt( color[ 3 ], 10 ) ) / 100;
  4012. handleAlpha( color[ 5 ] );
  4013. return this;
  4014. }
  4015. break;
  4016. case 'hsl':
  4017. case 'hsla':
  4018. if ( color = /^([0-9]*\.?[0-9]+)\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec( components ) ) {
  4019. // hsl(120,50%,50%) hsla(120,50%,50%,0.5)
  4020. var h = parseFloat( color[ 1 ] ) / 360;
  4021. var s = parseInt( color[ 2 ], 10 ) / 100;
  4022. var l = parseInt( color[ 3 ], 10 ) / 100;
  4023. handleAlpha( color[ 5 ] );
  4024. return this.setHSL( h, s, l );
  4025. }
  4026. break;
  4027. }
  4028. } else if ( m = /^\#([A-Fa-f0-9]+)$/.exec( style ) ) {
  4029. // hex color
  4030. var hex = m[ 1 ];
  4031. var size = hex.length;
  4032. if ( size === 3 ) {
  4033. // #ff0
  4034. this.r = parseInt( hex.charAt( 0 ) + hex.charAt( 0 ), 16 ) / 255;
  4035. this.g = parseInt( hex.charAt( 1 ) + hex.charAt( 1 ), 16 ) / 255;
  4036. this.b = parseInt( hex.charAt( 2 ) + hex.charAt( 2 ), 16 ) / 255;
  4037. return this;
  4038. } else if ( size === 6 ) {
  4039. // #ff0000
  4040. this.r = parseInt( hex.charAt( 0 ) + hex.charAt( 1 ), 16 ) / 255;
  4041. this.g = parseInt( hex.charAt( 2 ) + hex.charAt( 3 ), 16 ) / 255;
  4042. this.b = parseInt( hex.charAt( 4 ) + hex.charAt( 5 ), 16 ) / 255;
  4043. return this;
  4044. }
  4045. }
  4046. if ( style && style.length > 0 ) {
  4047. // color keywords
  4048. var hex = ColorKeywords[ style ];
  4049. if ( hex !== undefined ) {
  4050. // red
  4051. this.setHex( hex );
  4052. } else {
  4053. // unknown color
  4054. console.warn( 'THREE.Color: Unknown color ' + style );
  4055. }
  4056. }
  4057. return this;
  4058. },
  4059. clone: function () {
  4060. return new this.constructor( this.r, this.g, this.b );
  4061. },
  4062. copy: function ( color ) {
  4063. this.r = color.r;
  4064. this.g = color.g;
  4065. this.b = color.b;
  4066. return this;
  4067. },
  4068. copyGammaToLinear: function ( color, gammaFactor ) {
  4069. if ( gammaFactor === undefined ) gammaFactor = 2.0;
  4070. this.r = Math.pow( color.r, gammaFactor );
  4071. this.g = Math.pow( color.g, gammaFactor );
  4072. this.b = Math.pow( color.b, gammaFactor );
  4073. return this;
  4074. },
  4075. copyLinearToGamma: function ( color, gammaFactor ) {
  4076. if ( gammaFactor === undefined ) gammaFactor = 2.0;
  4077. var safeInverse = ( gammaFactor > 0 ) ? ( 1.0 / gammaFactor ) : 1.0;
  4078. this.r = Math.pow( color.r, safeInverse );
  4079. this.g = Math.pow( color.g, safeInverse );
  4080. this.b = Math.pow( color.b, safeInverse );
  4081. return this;
  4082. },
  4083. convertGammaToLinear: function ( gammaFactor ) {
  4084. this.copyGammaToLinear( this, gammaFactor );
  4085. return this;
  4086. },
  4087. convertLinearToGamma: function ( gammaFactor ) {
  4088. this.copyLinearToGamma( this, gammaFactor );
  4089. return this;
  4090. },
  4091. copySRGBToLinear: function () {
  4092. function SRGBToLinear( c ) {
  4093. return ( c < 0.04045 ) ? c * 0.0773993808 : Math.pow( c * 0.9478672986 + 0.0521327014, 2.4 );
  4094. }
  4095. return function copySRGBToLinear( color ) {
  4096. this.r = SRGBToLinear( color.r );
  4097. this.g = SRGBToLinear( color.g );
  4098. this.b = SRGBToLinear( color.b );
  4099. return this;
  4100. };
  4101. }(),
  4102. copyLinearToSRGB: function () {
  4103. function LinearToSRGB( c ) {
  4104. return ( c < 0.0031308 ) ? c * 12.92 : 1.055 * ( Math.pow( c, 0.41666 ) ) - 0.055;
  4105. }
  4106. return function copyLinearToSRGB( color ) {
  4107. this.r = LinearToSRGB( color.r );
  4108. this.g = LinearToSRGB( color.g );
  4109. this.b = LinearToSRGB( color.b );
  4110. return this;
  4111. };
  4112. }(),
  4113. convertSRGBToLinear: function () {
  4114. this.copySRGBToLinear( this );
  4115. return this;
  4116. },
  4117. convertLinearToSRGB: function () {
  4118. this.copyLinearToSRGB( this );
  4119. return this;
  4120. },
  4121. getHex: function () {
  4122. return ( this.r * 255 ) << 16 ^ ( this.g * 255 ) << 8 ^ ( this.b * 255 ) << 0;
  4123. },
  4124. getHexString: function () {
  4125. return ( '000000' + this.getHex().toString( 16 ) ).slice( - 6 );
  4126. },
  4127. getHSL: function ( target ) {
  4128. // h,s,l ranges are in 0.0 - 1.0
  4129. if ( target === undefined ) {
  4130. console.warn( 'THREE.Color: .getHSL() target is now required' );
  4131. target = { h: 0, s: 0, l: 0 };
  4132. }
  4133. var r = this.r, g = this.g, b = this.b;
  4134. var max = Math.max( r, g, b );
  4135. var min = Math.min( r, g, b );
  4136. var hue, saturation;
  4137. var lightness = ( min + max ) / 2.0;
  4138. if ( min === max ) {
  4139. hue = 0;
  4140. saturation = 0;
  4141. } else {
  4142. var delta = max - min;
  4143. saturation = lightness <= 0.5 ? delta / ( max + min ) : delta / ( 2 - max - min );
  4144. switch ( max ) {
  4145. case r: hue = ( g - b ) / delta + ( g < b ? 6 : 0 ); break;
  4146. case g: hue = ( b - r ) / delta + 2; break;
  4147. case b: hue = ( r - g ) / delta + 4; break;
  4148. }
  4149. hue /= 6;
  4150. }
  4151. target.h = hue;
  4152. target.s = saturation;
  4153. target.l = lightness;
  4154. return target;
  4155. },
  4156. getStyle: function () {
  4157. return 'rgb(' + ( ( this.r * 255 ) | 0 ) + ',' + ( ( this.g * 255 ) | 0 ) + ',' + ( ( this.b * 255 ) | 0 ) + ')';
  4158. },
  4159. offsetHSL: function () {
  4160. var hsl = {};
  4161. return function ( h, s, l ) {
  4162. this.getHSL( hsl );
  4163. hsl.h += h; hsl.s += s; hsl.l += l;
  4164. this.setHSL( hsl.h, hsl.s, hsl.l );
  4165. return this;
  4166. };
  4167. }(),
  4168. add: function ( color ) {
  4169. this.r += color.r;
  4170. this.g += color.g;
  4171. this.b += color.b;
  4172. return this;
  4173. },
  4174. addColors: function ( color1, color2 ) {
  4175. this.r = color1.r + color2.r;
  4176. this.g = color1.g + color2.g;
  4177. this.b = color1.b + color2.b;
  4178. return this;
  4179. },
  4180. addScalar: function ( s ) {
  4181. this.r += s;
  4182. this.g += s;
  4183. this.b += s;
  4184. return this;
  4185. },
  4186. sub: function ( color ) {
  4187. this.r = Math.max( 0, this.r - color.r );
  4188. this.g = Math.max( 0, this.g - color.g );
  4189. this.b = Math.max( 0, this.b - color.b );
  4190. return this;
  4191. },
  4192. multiply: function ( color ) {
  4193. this.r *= color.r;
  4194. this.g *= color.g;
  4195. this.b *= color.b;
  4196. return this;
  4197. },
  4198. multiplyScalar: function ( s ) {
  4199. this.r *= s;
  4200. this.g *= s;
  4201. this.b *= s;
  4202. return this;
  4203. },
  4204. lerp: function ( color, alpha ) {
  4205. this.r += ( color.r - this.r ) * alpha;
  4206. this.g += ( color.g - this.g ) * alpha;
  4207. this.b += ( color.b - this.b ) * alpha;
  4208. return this;
  4209. },
  4210. lerpHSL: function () {
  4211. var hslA = { h: 0, s: 0, l: 0 };
  4212. var hslB = { h: 0, s: 0, l: 0 };
  4213. return function lerpHSL( color, alpha ) {
  4214. this.getHSL( hslA );
  4215. color.getHSL( hslB );
  4216. var h = _Math.lerp( hslA.h, hslB.h, alpha );
  4217. var s = _Math.lerp( hslA.s, hslB.s, alpha );
  4218. var l = _Math.lerp( hslA.l, hslB.l, alpha );
  4219. this.setHSL( h, s, l );
  4220. return this;
  4221. };
  4222. }(),
  4223. equals: function ( c ) {
  4224. return ( c.r === this.r ) && ( c.g === this.g ) && ( c.b === this.b );
  4225. },
  4226. fromArray: function ( array, offset ) {
  4227. if ( offset === undefined ) offset = 0;
  4228. this.r = array[ offset ];
  4229. this.g = array[ offset + 1 ];
  4230. this.b = array[ offset + 2 ];
  4231. return this;
  4232. },
  4233. toArray: function ( array, offset ) {
  4234. if ( array === undefined ) array = [];
  4235. if ( offset === undefined ) offset = 0;
  4236. array[ offset ] = this.r;
  4237. array[ offset + 1 ] = this.g;
  4238. array[ offset + 2 ] = this.b;
  4239. return array;
  4240. },
  4241. toJSON: function () {
  4242. return this.getHex();
  4243. }
  4244. } );
  4245. /**
  4246. * Uniforms library for shared webgl shaders
  4247. */
  4248. var UniformsLib = {
  4249. common: {
  4250. diffuse: { value: new Color( 0xeeeeee ) },
  4251. opacity: { value: 1.0 },
  4252. map: { value: null },
  4253. uvTransform: { value: new Matrix3() },
  4254. alphaMap: { value: null },
  4255. },
  4256. specularmap: {
  4257. specularMap: { value: null },
  4258. },
  4259. envmap: {
  4260. envMap: { value: null },
  4261. flipEnvMap: { value: - 1 },
  4262. reflectivity: { value: 1.0 },
  4263. refractionRatio: { value: 0.98 },
  4264. maxMipLevel: { value: 0 }
  4265. },
  4266. aomap: {
  4267. aoMap: { value: null },
  4268. aoMapIntensity: { value: 1 }
  4269. },
  4270. lightmap: {
  4271. lightMap: { value: null },
  4272. lightMapIntensity: { value: 1 }
  4273. },
  4274. emissivemap: {
  4275. emissiveMap: { value: null }
  4276. },
  4277. bumpmap: {
  4278. bumpMap: { value: null },
  4279. bumpScale: { value: 1 }
  4280. },
  4281. normalmap: {
  4282. normalMap: { value: null },
  4283. normalScale: { value: new Vector2( 1, 1 ) }
  4284. },
  4285. displacementmap: {
  4286. displacementMap: { value: null },
  4287. displacementScale: { value: 1 },
  4288. displacementBias: { value: 0 }
  4289. },
  4290. roughnessmap: {
  4291. roughnessMap: { value: null }
  4292. },
  4293. metalnessmap: {
  4294. metalnessMap: { value: null }
  4295. },
  4296. gradientmap: {
  4297. gradientMap: { value: null }
  4298. },
  4299. fog: {
  4300. fogDensity: { value: 0.00025 },
  4301. fogNear: { value: 1 },
  4302. fogFar: { value: 2000 },
  4303. fogColor: { value: new Color( 0xffffff ) }
  4304. },
  4305. lights: {
  4306. ambientLightColor: { value: [] },
  4307. lightProbe: { value: [] },
  4308. directionalLights: { value: [], properties: {
  4309. direction: {},
  4310. color: {},
  4311. shadow: {},
  4312. shadowBias: {},
  4313. shadowRadius: {},
  4314. shadowMapSize: {}
  4315. } },
  4316. directionalShadowMap: { value: [] },
  4317. directionalShadowMatrix: { value: [] },
  4318. spotLights: { value: [], properties: {
  4319. color: {},
  4320. position: {},
  4321. direction: {},
  4322. distance: {},
  4323. coneCos: {},
  4324. penumbraCos: {},
  4325. decay: {},
  4326. shadow: {},
  4327. shadowBias: {},
  4328. shadowRadius: {},
  4329. shadowMapSize: {}
  4330. } },
  4331. spotShadowMap: { value: [] },
  4332. spotShadowMatrix: { value: [] },
  4333. pointLights: { value: [], properties: {
  4334. color: {},
  4335. position: {},
  4336. decay: {},
  4337. distance: {},
  4338. shadow: {},
  4339. shadowBias: {},
  4340. shadowRadius: {},
  4341. shadowMapSize: {},
  4342. shadowCameraNear: {},
  4343. shadowCameraFar: {}
  4344. } },
  4345. pointShadowMap: { value: [] },
  4346. pointShadowMatrix: { value: [] },
  4347. hemisphereLights: { value: [], properties: {
  4348. direction: {},
  4349. skyColor: {},
  4350. groundColor: {}
  4351. } },
  4352. // TODO (abelnation): RectAreaLight BRDF data needs to be moved from example to main src
  4353. rectAreaLights: { value: [], properties: {
  4354. color: {},
  4355. position: {},
  4356. width: {},
  4357. height: {}
  4358. } }
  4359. },
  4360. points: {
  4361. diffuse: { value: new Color( 0xeeeeee ) },
  4362. opacity: { value: 1.0 },
  4363. size: { value: 1.0 },
  4364. scale: { value: 1.0 },
  4365. map: { value: null },
  4366. uvTransform: { value: new Matrix3() }
  4367. },
  4368. sprite: {
  4369. diffuse: { value: new Color( 0xeeeeee ) },
  4370. opacity: { value: 1.0 },
  4371. center: { value: new Vector2( 0.5, 0.5 ) },
  4372. rotation: { value: 0.0 },
  4373. map: { value: null },
  4374. uvTransform: { value: new Matrix3() }
  4375. }
  4376. };
  4377. /**
  4378. * @author alteredq / http://alteredqualia.com/
  4379. * @author mrdoob / http://mrdoob.com/
  4380. * @author mikael emtinger / http://gomo.se/
  4381. */
  4382. var ShaderLib = {
  4383. basic: {
  4384. uniforms: mergeUniforms( [
  4385. UniformsLib.common,
  4386. UniformsLib.specularmap,
  4387. UniformsLib.envmap,
  4388. UniformsLib.aomap,
  4389. UniformsLib.lightmap,
  4390. UniformsLib.fog
  4391. ] ),
  4392. vertexShader: ShaderChunk.meshbasic_vert,
  4393. fragmentShader: ShaderChunk.meshbasic_frag
  4394. },
  4395. lambert: {
  4396. uniforms: mergeUniforms( [
  4397. UniformsLib.common,
  4398. UniformsLib.specularmap,
  4399. UniformsLib.envmap,
  4400. UniformsLib.aomap,
  4401. UniformsLib.lightmap,
  4402. UniformsLib.emissivemap,
  4403. UniformsLib.fog,
  4404. UniformsLib.lights,
  4405. {
  4406. emissive: { value: new Color( 0x000000 ) }
  4407. }
  4408. ] ),
  4409. vertexShader: ShaderChunk.meshlambert_vert,
  4410. fragmentShader: ShaderChunk.meshlambert_frag
  4411. },
  4412. phong: {
  4413. uniforms: mergeUniforms( [
  4414. UniformsLib.common,
  4415. UniformsLib.specularmap,
  4416. UniformsLib.envmap,
  4417. UniformsLib.aomap,
  4418. UniformsLib.lightmap,
  4419. UniformsLib.emissivemap,
  4420. UniformsLib.bumpmap,
  4421. UniformsLib.normalmap,
  4422. UniformsLib.displacementmap,
  4423. UniformsLib.gradientmap,
  4424. UniformsLib.fog,
  4425. UniformsLib.lights,
  4426. {
  4427. emissive: { value: new Color( 0x000000 ) },
  4428. specular: { value: new Color( 0x111111 ) },
  4429. shininess: { value: 30 }
  4430. }
  4431. ] ),
  4432. vertexShader: ShaderChunk.meshphong_vert,
  4433. fragmentShader: ShaderChunk.meshphong_frag
  4434. },
  4435. standard: {
  4436. uniforms: mergeUniforms( [
  4437. UniformsLib.common,
  4438. UniformsLib.envmap,
  4439. UniformsLib.aomap,
  4440. UniformsLib.lightmap,
  4441. UniformsLib.emissivemap,
  4442. UniformsLib.bumpmap,
  4443. UniformsLib.normalmap,
  4444. UniformsLib.displacementmap,
  4445. UniformsLib.roughnessmap,
  4446. UniformsLib.metalnessmap,
  4447. UniformsLib.fog,
  4448. UniformsLib.lights,
  4449. {
  4450. emissive: { value: new Color( 0x000000 ) },
  4451. roughness: { value: 0.5 },
  4452. metalness: { value: 0.5 },
  4453. envMapIntensity: { value: 1 } // temporary
  4454. }
  4455. ] ),
  4456. vertexShader: ShaderChunk.meshphysical_vert,
  4457. fragmentShader: ShaderChunk.meshphysical_frag
  4458. },
  4459. matcap: {
  4460. uniforms: mergeUniforms( [
  4461. UniformsLib.common,
  4462. UniformsLib.bumpmap,
  4463. UniformsLib.normalmap,
  4464. UniformsLib.displacementmap,
  4465. UniformsLib.fog,
  4466. {
  4467. matcap: { value: null }
  4468. }
  4469. ] ),
  4470. vertexShader: ShaderChunk.meshmatcap_vert,
  4471. fragmentShader: ShaderChunk.meshmatcap_frag
  4472. },
  4473. points: {
  4474. uniforms: mergeUniforms( [
  4475. UniformsLib.points,
  4476. UniformsLib.fog
  4477. ] ),
  4478. vertexShader: ShaderChunk.points_vert,
  4479. fragmentShader: ShaderChunk.points_frag
  4480. },
  4481. dashed: {
  4482. uniforms: mergeUniforms( [
  4483. UniformsLib.common,
  4484. UniformsLib.fog,
  4485. {
  4486. scale: { value: 1 },
  4487. dashSize: { value: 1 },
  4488. totalSize: { value: 2 }
  4489. }
  4490. ] ),
  4491. vertexShader: ShaderChunk.linedashed_vert,
  4492. fragmentShader: ShaderChunk.linedashed_frag
  4493. },
  4494. depth: {
  4495. uniforms: mergeUniforms( [
  4496. UniformsLib.common,
  4497. UniformsLib.displacementmap
  4498. ] ),
  4499. vertexShader: ShaderChunk.depth_vert,
  4500. fragmentShader: ShaderChunk.depth_frag
  4501. },
  4502. normal: {
  4503. uniforms: mergeUniforms( [
  4504. UniformsLib.common,
  4505. UniformsLib.bumpmap,
  4506. UniformsLib.normalmap,
  4507. UniformsLib.displacementmap,
  4508. {
  4509. opacity: { value: 1.0 }
  4510. }
  4511. ] ),
  4512. vertexShader: ShaderChunk.normal_vert,
  4513. fragmentShader: ShaderChunk.normal_frag
  4514. },
  4515. sprite: {
  4516. uniforms: mergeUniforms( [
  4517. UniformsLib.sprite,
  4518. UniformsLib.fog
  4519. ] ),
  4520. vertexShader: ShaderChunk.sprite_vert,
  4521. fragmentShader: ShaderChunk.sprite_frag
  4522. },
  4523. background: {
  4524. uniforms: {
  4525. uvTransform: { value: new Matrix3() },
  4526. t2D: { value: null },
  4527. },
  4528. vertexShader: ShaderChunk.background_vert,
  4529. fragmentShader: ShaderChunk.background_frag
  4530. },
  4531. /* -------------------------------------------------------------------------
  4532. // Cube map shader
  4533. ------------------------------------------------------------------------- */
  4534. cube: {
  4535. uniforms: {
  4536. tCube: { value: null },
  4537. tFlip: { value: - 1 },
  4538. opacity: { value: 1.0 }
  4539. },
  4540. vertexShader: ShaderChunk.cube_vert,
  4541. fragmentShader: ShaderChunk.cube_frag
  4542. },
  4543. equirect: {
  4544. uniforms: {
  4545. tEquirect: { value: null },
  4546. },
  4547. vertexShader: ShaderChunk.equirect_vert,
  4548. fragmentShader: ShaderChunk.equirect_frag
  4549. },
  4550. distanceRGBA: {
  4551. uniforms: mergeUniforms( [
  4552. UniformsLib.common,
  4553. UniformsLib.displacementmap,
  4554. {
  4555. referencePosition: { value: new Vector3() },
  4556. nearDistance: { value: 1 },
  4557. farDistance: { value: 1000 }
  4558. }
  4559. ] ),
  4560. vertexShader: ShaderChunk.distanceRGBA_vert,
  4561. fragmentShader: ShaderChunk.distanceRGBA_frag
  4562. },
  4563. shadow: {
  4564. uniforms: mergeUniforms( [
  4565. UniformsLib.lights,
  4566. UniformsLib.fog,
  4567. {
  4568. color: { value: new Color( 0x00000 ) },
  4569. opacity: { value: 1.0 }
  4570. },
  4571. ] ),
  4572. vertexShader: ShaderChunk.shadow_vert,
  4573. fragmentShader: ShaderChunk.shadow_frag
  4574. }
  4575. };
  4576. ShaderLib.physical = {
  4577. uniforms: mergeUniforms( [
  4578. ShaderLib.standard.uniforms,
  4579. {
  4580. clearCoat: { value: 0 },
  4581. clearCoatRoughness: { value: 0 }
  4582. }
  4583. ] ),
  4584. vertexShader: ShaderChunk.meshphysical_vert,
  4585. fragmentShader: ShaderChunk.meshphysical_frag
  4586. };
  4587. /**
  4588. * @author mrdoob / http://mrdoob.com/
  4589. */
  4590. function WebGLAnimation() {
  4591. var context = null;
  4592. var isAnimating = false;
  4593. var animationLoop = null;
  4594. function onAnimationFrame( time, frame ) {
  4595. if ( isAnimating === false ) return;
  4596. animationLoop( time, frame );
  4597. context.requestAnimationFrame( onAnimationFrame );
  4598. }
  4599. return {
  4600. start: function () {
  4601. if ( isAnimating === true ) return;
  4602. if ( animationLoop === null ) return;
  4603. context.requestAnimationFrame( onAnimationFrame );
  4604. isAnimating = true;
  4605. },
  4606. stop: function () {
  4607. isAnimating = false;
  4608. },
  4609. setAnimationLoop: function ( callback ) {
  4610. animationLoop = callback;
  4611. },
  4612. setContext: function ( value ) {
  4613. context = value;
  4614. }
  4615. };
  4616. }
  4617. /**
  4618. * @author mrdoob / http://mrdoob.com/
  4619. */
  4620. function WebGLAttributes( gl ) {
  4621. var buffers = new WeakMap();
  4622. function createBuffer( attribute, bufferType ) {
  4623. var array = attribute.array;
  4624. var usage = attribute.dynamic ? 35048 : 35044;
  4625. var buffer = gl.createBuffer();
  4626. gl.bindBuffer( bufferType, buffer );
  4627. gl.bufferData( bufferType, array, usage );
  4628. attribute.onUploadCallback();
  4629. var type = 5126;
  4630. if ( array instanceof Float32Array ) {
  4631. type = 5126;
  4632. } else if ( array instanceof Float64Array ) {
  4633. console.warn( 'THREE.WebGLAttributes: Unsupported data buffer format: Float64Array.' );
  4634. } else if ( array instanceof Uint16Array ) {
  4635. type = 5123;
  4636. } else if ( array instanceof Int16Array ) {
  4637. type = 5122;
  4638. } else if ( array instanceof Uint32Array ) {
  4639. type = 5125;
  4640. } else if ( array instanceof Int32Array ) {
  4641. type = 5124;
  4642. } else if ( array instanceof Int8Array ) {
  4643. type = 5120;
  4644. } else if ( array instanceof Uint8Array ) {
  4645. type = 5121;
  4646. }
  4647. return {
  4648. buffer: buffer,
  4649. type: type,
  4650. bytesPerElement: array.BYTES_PER_ELEMENT,
  4651. version: attribute.version
  4652. };
  4653. }
  4654. function updateBuffer( buffer, attribute, bufferType ) {
  4655. var array = attribute.array;
  4656. var updateRange = attribute.updateRange;
  4657. gl.bindBuffer( bufferType, buffer );
  4658. if ( attribute.dynamic === false ) {
  4659. gl.bufferData( bufferType, array, 35044 );
  4660. } else if ( updateRange.count === - 1 ) {
  4661. // Not using update ranges
  4662. gl.bufferSubData( bufferType, 0, array );
  4663. } else if ( updateRange.count === 0 ) {
  4664. 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.' );
  4665. } else {
  4666. gl.bufferSubData( bufferType, updateRange.offset * array.BYTES_PER_ELEMENT,
  4667. array.subarray( updateRange.offset, updateRange.offset + updateRange.count ) );
  4668. updateRange.count = - 1; // reset range
  4669. }
  4670. }
  4671. //
  4672. function get( attribute ) {
  4673. if ( attribute.isInterleavedBufferAttribute ) attribute = attribute.data;
  4674. return buffers.get( attribute );
  4675. }
  4676. function remove( attribute ) {
  4677. if ( attribute.isInterleavedBufferAttribute ) attribute = attribute.data;
  4678. var data = buffers.get( attribute );
  4679. if ( data ) {
  4680. gl.deleteBuffer( data.buffer );
  4681. buffers.delete( attribute );
  4682. }
  4683. }
  4684. function update( attribute, bufferType ) {
  4685. if ( attribute.isInterleavedBufferAttribute ) attribute = attribute.data;
  4686. var data = buffers.get( attribute );
  4687. if ( data === undefined ) {
  4688. buffers.set( attribute, createBuffer( attribute, bufferType ) );
  4689. } else if ( data.version < attribute.version ) {
  4690. updateBuffer( data.buffer, attribute, bufferType );
  4691. data.version = attribute.version;
  4692. }
  4693. }
  4694. return {
  4695. get: get,
  4696. remove: remove,
  4697. update: update
  4698. };
  4699. }
  4700. /**
  4701. * @author mrdoob / http://mrdoob.com/
  4702. * @author alteredq / http://alteredqualia.com/
  4703. */
  4704. function Face3( a, b, c, normal, color, materialIndex ) {
  4705. this.a = a;
  4706. this.b = b;
  4707. this.c = c;
  4708. this.normal = ( normal && normal.isVector3 ) ? normal : new Vector3();
  4709. this.vertexNormals = Array.isArray( normal ) ? normal : [];
  4710. this.color = ( color && color.isColor ) ? color : new Color();
  4711. this.vertexColors = Array.isArray( color ) ? color : [];
  4712. this.materialIndex = materialIndex !== undefined ? materialIndex : 0;
  4713. }
  4714. Object.assign( Face3.prototype, {
  4715. clone: function () {
  4716. return new this.constructor().copy( this );
  4717. },
  4718. copy: function ( source ) {
  4719. this.a = source.a;
  4720. this.b = source.b;
  4721. this.c = source.c;
  4722. this.normal.copy( source.normal );
  4723. this.color.copy( source.color );
  4724. this.materialIndex = source.materialIndex;
  4725. for ( var i = 0, il = source.vertexNormals.length; i < il; i ++ ) {
  4726. this.vertexNormals[ i ] = source.vertexNormals[ i ].clone();
  4727. }
  4728. for ( var i = 0, il = source.vertexColors.length; i < il; i ++ ) {
  4729. this.vertexColors[ i ] = source.vertexColors[ i ].clone();
  4730. }
  4731. return this;
  4732. }
  4733. } );
  4734. /**
  4735. * @author mrdoob / http://mrdoob.com/
  4736. * @author WestLangley / http://github.com/WestLangley
  4737. * @author bhouston / http://clara.io
  4738. */
  4739. function Euler( x, y, z, order ) {
  4740. this._x = x || 0;
  4741. this._y = y || 0;
  4742. this._z = z || 0;
  4743. this._order = order || Euler.DefaultOrder;
  4744. }
  4745. Euler.RotationOrders = [ 'XYZ', 'YZX', 'ZXY', 'XZY', 'YXZ', 'ZYX' ];
  4746. Euler.DefaultOrder = 'XYZ';
  4747. Object.defineProperties( Euler.prototype, {
  4748. x: {
  4749. get: function () {
  4750. return this._x;
  4751. },
  4752. set: function ( value ) {
  4753. this._x = value;
  4754. this.onChangeCallback();
  4755. }
  4756. },
  4757. y: {
  4758. get: function () {
  4759. return this._y;
  4760. },
  4761. set: function ( value ) {
  4762. this._y = value;
  4763. this.onChangeCallback();
  4764. }
  4765. },
  4766. z: {
  4767. get: function () {
  4768. return this._z;
  4769. },
  4770. set: function ( value ) {
  4771. this._z = value;
  4772. this.onChangeCallback();
  4773. }
  4774. },
  4775. order: {
  4776. get: function () {
  4777. return this._order;
  4778. },
  4779. set: function ( value ) {
  4780. this._order = value;
  4781. this.onChangeCallback();
  4782. }
  4783. }
  4784. } );
  4785. Object.assign( Euler.prototype, {
  4786. isEuler: true,
  4787. set: function ( x, y, z, order ) {
  4788. this._x = x;
  4789. this._y = y;
  4790. this._z = z;
  4791. this._order = order || this._order;
  4792. this.onChangeCallback();
  4793. return this;
  4794. },
  4795. clone: function () {
  4796. return new this.constructor( this._x, this._y, this._z, this._order );
  4797. },
  4798. copy: function ( euler ) {
  4799. this._x = euler._x;
  4800. this._y = euler._y;
  4801. this._z = euler._z;
  4802. this._order = euler._order;
  4803. this.onChangeCallback();
  4804. return this;
  4805. },
  4806. setFromRotationMatrix: function ( m, order, update ) {
  4807. var clamp = _Math.clamp;
  4808. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  4809. var te = m.elements;
  4810. var m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ];
  4811. var m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ];
  4812. var m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ];
  4813. order = order || this._order;
  4814. if ( order === 'XYZ' ) {
  4815. this._y = Math.asin( clamp( m13, - 1, 1 ) );
  4816. if ( Math.abs( m13 ) < 0.99999 ) {
  4817. this._x = Math.atan2( - m23, m33 );
  4818. this._z = Math.atan2( - m12, m11 );
  4819. } else {
  4820. this._x = Math.atan2( m32, m22 );
  4821. this._z = 0;
  4822. }
  4823. } else if ( order === 'YXZ' ) {
  4824. this._x = Math.asin( - clamp( m23, - 1, 1 ) );
  4825. if ( Math.abs( m23 ) < 0.99999 ) {
  4826. this._y = Math.atan2( m13, m33 );
  4827. this._z = Math.atan2( m21, m22 );
  4828. } else {
  4829. this._y = Math.atan2( - m31, m11 );
  4830. this._z = 0;
  4831. }
  4832. } else if ( order === 'ZXY' ) {
  4833. this._x = Math.asin( clamp( m32, - 1, 1 ) );
  4834. if ( Math.abs( m32 ) < 0.99999 ) {
  4835. this._y = Math.atan2( - m31, m33 );
  4836. this._z = Math.atan2( - m12, m22 );
  4837. } else {
  4838. this._y = 0;
  4839. this._z = Math.atan2( m21, m11 );
  4840. }
  4841. } else if ( order === 'ZYX' ) {
  4842. this._y = Math.asin( - clamp( m31, - 1, 1 ) );
  4843. if ( Math.abs( m31 ) < 0.99999 ) {
  4844. this._x = Math.atan2( m32, m33 );
  4845. this._z = Math.atan2( m21, m11 );
  4846. } else {
  4847. this._x = 0;
  4848. this._z = Math.atan2( - m12, m22 );
  4849. }
  4850. } else if ( order === 'YZX' ) {
  4851. this._z = Math.asin( clamp( m21, - 1, 1 ) );
  4852. if ( Math.abs( m21 ) < 0.99999 ) {
  4853. this._x = Math.atan2( - m23, m22 );
  4854. this._y = Math.atan2( - m31, m11 );
  4855. } else {
  4856. this._x = 0;
  4857. this._y = Math.atan2( m13, m33 );
  4858. }
  4859. } else if ( order === 'XZY' ) {
  4860. this._z = Math.asin( - clamp( m12, - 1, 1 ) );
  4861. if ( Math.abs( m12 ) < 0.99999 ) {
  4862. this._x = Math.atan2( m32, m22 );
  4863. this._y = Math.atan2( m13, m11 );
  4864. } else {
  4865. this._x = Math.atan2( - m23, m33 );
  4866. this._y = 0;
  4867. }
  4868. } else {
  4869. console.warn( 'THREE.Euler: .setFromRotationMatrix() given unsupported order: ' + order );
  4870. }
  4871. this._order = order;
  4872. if ( update !== false ) this.onChangeCallback();
  4873. return this;
  4874. },
  4875. setFromQuaternion: function () {
  4876. var matrix = new Matrix4();
  4877. return function setFromQuaternion( q, order, update ) {
  4878. matrix.makeRotationFromQuaternion( q );
  4879. return this.setFromRotationMatrix( matrix, order, update );
  4880. };
  4881. }(),
  4882. setFromVector3: function ( v, order ) {
  4883. return this.set( v.x, v.y, v.z, order || this._order );
  4884. },
  4885. reorder: function () {
  4886. // WARNING: this discards revolution information -bhouston
  4887. var q = new Quaternion();
  4888. return function reorder( newOrder ) {
  4889. q.setFromEuler( this );
  4890. return this.setFromQuaternion( q, newOrder );
  4891. };
  4892. }(),
  4893. equals: function ( euler ) {
  4894. return ( euler._x === this._x ) && ( euler._y === this._y ) && ( euler._z === this._z ) && ( euler._order === this._order );
  4895. },
  4896. fromArray: function ( array ) {
  4897. this._x = array[ 0 ];
  4898. this._y = array[ 1 ];
  4899. this._z = array[ 2 ];
  4900. if ( array[ 3 ] !== undefined ) this._order = array[ 3 ];
  4901. this.onChangeCallback();
  4902. return this;
  4903. },
  4904. toArray: function ( array, offset ) {
  4905. if ( array === undefined ) array = [];
  4906. if ( offset === undefined ) offset = 0;
  4907. array[ offset ] = this._x;
  4908. array[ offset + 1 ] = this._y;
  4909. array[ offset + 2 ] = this._z;
  4910. array[ offset + 3 ] = this._order;
  4911. return array;
  4912. },
  4913. toVector3: function ( optionalResult ) {
  4914. if ( optionalResult ) {
  4915. return optionalResult.set( this._x, this._y, this._z );
  4916. } else {
  4917. return new Vector3( this._x, this._y, this._z );
  4918. }
  4919. },
  4920. onChange: function ( callback ) {
  4921. this.onChangeCallback = callback;
  4922. return this;
  4923. },
  4924. onChangeCallback: function () {}
  4925. } );
  4926. /**
  4927. * @author mrdoob / http://mrdoob.com/
  4928. */
  4929. function Layers() {
  4930. this.mask = 1 | 0;
  4931. }
  4932. Object.assign( Layers.prototype, {
  4933. set: function ( channel ) {
  4934. this.mask = 1 << channel | 0;
  4935. },
  4936. enable: function ( channel ) {
  4937. this.mask |= 1 << channel | 0;
  4938. },
  4939. toggle: function ( channel ) {
  4940. this.mask ^= 1 << channel | 0;
  4941. },
  4942. disable: function ( channel ) {
  4943. this.mask &= ~ ( 1 << channel | 0 );
  4944. },
  4945. test: function ( layers ) {
  4946. return ( this.mask & layers.mask ) !== 0;
  4947. }
  4948. } );
  4949. /**
  4950. * @author mrdoob / http://mrdoob.com/
  4951. * @author mikael emtinger / http://gomo.se/
  4952. * @author alteredq / http://alteredqualia.com/
  4953. * @author WestLangley / http://github.com/WestLangley
  4954. * @author elephantatwork / www.elephantatwork.ch
  4955. */
  4956. var object3DId = 0;
  4957. function Object3D() {
  4958. Object.defineProperty( this, 'id', { value: object3DId ++ } );
  4959. this.uuid = _Math.generateUUID();
  4960. this.name = '';
  4961. this.type = 'Object3D';
  4962. this.parent = null;
  4963. this.children = [];
  4964. this.up = Object3D.DefaultUp.clone();
  4965. var position = new Vector3();
  4966. var rotation = new Euler();
  4967. var quaternion = new Quaternion();
  4968. var scale = new Vector3( 1, 1, 1 );
  4969. function onRotationChange() {
  4970. quaternion.setFromEuler( rotation, false );
  4971. }
  4972. function onQuaternionChange() {
  4973. rotation.setFromQuaternion( quaternion, undefined, false );
  4974. }
  4975. rotation.onChange( onRotationChange );
  4976. quaternion.onChange( onQuaternionChange );
  4977. Object.defineProperties( this, {
  4978. position: {
  4979. configurable: true,
  4980. enumerable: true,
  4981. value: position
  4982. },
  4983. rotation: {
  4984. configurable: true,
  4985. enumerable: true,
  4986. value: rotation
  4987. },
  4988. quaternion: {
  4989. configurable: true,
  4990. enumerable: true,
  4991. value: quaternion
  4992. },
  4993. scale: {
  4994. configurable: true,
  4995. enumerable: true,
  4996. value: scale
  4997. },
  4998. modelViewMatrix: {
  4999. value: new Matrix4()
  5000. },
  5001. normalMatrix: {
  5002. value: new Matrix3()
  5003. }
  5004. } );
  5005. this.matrix = new Matrix4();
  5006. this.matrixWorld = new Matrix4();
  5007. this.matrixAutoUpdate = Object3D.DefaultMatrixAutoUpdate;
  5008. this.matrixWorldNeedsUpdate = false;
  5009. this.layers = new Layers();
  5010. this.visible = true;
  5011. this.castShadow = false;
  5012. this.receiveShadow = false;
  5013. this.frustumCulled = true;
  5014. this.renderOrder = 0;
  5015. this.userData = {};
  5016. }
  5017. Object3D.DefaultUp = new Vector3( 0, 1, 0 );
  5018. Object3D.DefaultMatrixAutoUpdate = true;
  5019. Object3D.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  5020. constructor: Object3D,
  5021. isObject3D: true,
  5022. onBeforeRender: function () {},
  5023. onAfterRender: function () {},
  5024. applyMatrix: function ( matrix ) {
  5025. if ( this.matrixAutoUpdate ) this.updateMatrix();
  5026. this.matrix.premultiply( matrix );
  5027. this.matrix.decompose( this.position, this.quaternion, this.scale );
  5028. },
  5029. applyQuaternion: function ( q ) {
  5030. this.quaternion.premultiply( q );
  5031. return this;
  5032. },
  5033. setRotationFromAxisAngle: function ( axis, angle ) {
  5034. // assumes axis is normalized
  5035. this.quaternion.setFromAxisAngle( axis, angle );
  5036. },
  5037. setRotationFromEuler: function ( euler ) {
  5038. this.quaternion.setFromEuler( euler, true );
  5039. },
  5040. setRotationFromMatrix: function ( m ) {
  5041. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  5042. this.quaternion.setFromRotationMatrix( m );
  5043. },
  5044. setRotationFromQuaternion: function ( q ) {
  5045. // assumes q is normalized
  5046. this.quaternion.copy( q );
  5047. },
  5048. rotateOnAxis: function () {
  5049. // rotate object on axis in object space
  5050. // axis is assumed to be normalized
  5051. var q1 = new Quaternion();
  5052. return function rotateOnAxis( axis, angle ) {
  5053. q1.setFromAxisAngle( axis, angle );
  5054. this.quaternion.multiply( q1 );
  5055. return this;
  5056. };
  5057. }(),
  5058. rotateOnWorldAxis: function () {
  5059. // rotate object on axis in world space
  5060. // axis is assumed to be normalized
  5061. // method assumes no rotated parent
  5062. var q1 = new Quaternion();
  5063. return function rotateOnWorldAxis( axis, angle ) {
  5064. q1.setFromAxisAngle( axis, angle );
  5065. this.quaternion.premultiply( q1 );
  5066. return this;
  5067. };
  5068. }(),
  5069. rotateX: function () {
  5070. var v1 = new Vector3( 1, 0, 0 );
  5071. return function rotateX( angle ) {
  5072. return this.rotateOnAxis( v1, angle );
  5073. };
  5074. }(),
  5075. rotateY: function () {
  5076. var v1 = new Vector3( 0, 1, 0 );
  5077. return function rotateY( angle ) {
  5078. return this.rotateOnAxis( v1, angle );
  5079. };
  5080. }(),
  5081. rotateZ: function () {
  5082. var v1 = new Vector3( 0, 0, 1 );
  5083. return function rotateZ( angle ) {
  5084. return this.rotateOnAxis( v1, angle );
  5085. };
  5086. }(),
  5087. translateOnAxis: function () {
  5088. // translate object by distance along axis in object space
  5089. // axis is assumed to be normalized
  5090. var v1 = new Vector3();
  5091. return function translateOnAxis( axis, distance ) {
  5092. v1.copy( axis ).applyQuaternion( this.quaternion );
  5093. this.position.add( v1.multiplyScalar( distance ) );
  5094. return this;
  5095. };
  5096. }(),
  5097. translateX: function () {
  5098. var v1 = new Vector3( 1, 0, 0 );
  5099. return function translateX( distance ) {
  5100. return this.translateOnAxis( v1, distance );
  5101. };
  5102. }(),
  5103. translateY: function () {
  5104. var v1 = new Vector3( 0, 1, 0 );
  5105. return function translateY( distance ) {
  5106. return this.translateOnAxis( v1, distance );
  5107. };
  5108. }(),
  5109. translateZ: function () {
  5110. var v1 = new Vector3( 0, 0, 1 );
  5111. return function translateZ( distance ) {
  5112. return this.translateOnAxis( v1, distance );
  5113. };
  5114. }(),
  5115. localToWorld: function ( vector ) {
  5116. return vector.applyMatrix4( this.matrixWorld );
  5117. },
  5118. worldToLocal: function () {
  5119. var m1 = new Matrix4();
  5120. return function worldToLocal( vector ) {
  5121. return vector.applyMatrix4( m1.getInverse( this.matrixWorld ) );
  5122. };
  5123. }(),
  5124. lookAt: function () {
  5125. // This method does not support objects having non-uniformly-scaled parent(s)
  5126. var q1 = new Quaternion();
  5127. var m1 = new Matrix4();
  5128. var target = new Vector3();
  5129. var position = new Vector3();
  5130. return function lookAt( x, y, z ) {
  5131. if ( x.isVector3 ) {
  5132. target.copy( x );
  5133. } else {
  5134. target.set( x, y, z );
  5135. }
  5136. var parent = this.parent;
  5137. this.updateWorldMatrix( true, false );
  5138. position.setFromMatrixPosition( this.matrixWorld );
  5139. if ( this.isCamera || this.isLight ) {
  5140. m1.lookAt( position, target, this.up );
  5141. } else {
  5142. m1.lookAt( target, position, this.up );
  5143. }
  5144. this.quaternion.setFromRotationMatrix( m1 );
  5145. if ( parent ) {
  5146. m1.extractRotation( parent.matrixWorld );
  5147. q1.setFromRotationMatrix( m1 );
  5148. this.quaternion.premultiply( q1.inverse() );
  5149. }
  5150. };
  5151. }(),
  5152. add: function ( object ) {
  5153. if ( arguments.length > 1 ) {
  5154. for ( var i = 0; i < arguments.length; i ++ ) {
  5155. this.add( arguments[ i ] );
  5156. }
  5157. return this;
  5158. }
  5159. if ( object === this ) {
  5160. console.error( "THREE.Object3D.add: object can't be added as a child of itself.", object );
  5161. return this;
  5162. }
  5163. if ( ( object && object.isObject3D ) ) {
  5164. if ( object.parent !== null ) {
  5165. object.parent.remove( object );
  5166. }
  5167. object.parent = this;
  5168. object.dispatchEvent( { type: 'added' } );
  5169. this.children.push( object );
  5170. } else {
  5171. console.error( "THREE.Object3D.add: object not an instance of THREE.Object3D.", object );
  5172. }
  5173. return this;
  5174. },
  5175. remove: function ( object ) {
  5176. if ( arguments.length > 1 ) {
  5177. for ( var i = 0; i < arguments.length; i ++ ) {
  5178. this.remove( arguments[ i ] );
  5179. }
  5180. return this;
  5181. }
  5182. var index = this.children.indexOf( object );
  5183. if ( index !== - 1 ) {
  5184. object.parent = null;
  5185. object.dispatchEvent( { type: 'removed' } );
  5186. this.children.splice( index, 1 );
  5187. }
  5188. return this;
  5189. },
  5190. attach: function () {
  5191. // adds object as a child of this, while maintaining the object's world transform
  5192. var m = new Matrix4();
  5193. return function attach( object ) {
  5194. this.updateWorldMatrix( true, false );
  5195. m.getInverse( this.matrixWorld );
  5196. if ( object.parent !== null ) {
  5197. object.parent.updateWorldMatrix( true, false );
  5198. m.multiply( object.parent.matrixWorld );
  5199. }
  5200. object.applyMatrix( m );
  5201. object.updateWorldMatrix( false, false );
  5202. this.add( object );
  5203. return this;
  5204. };
  5205. }(),
  5206. getObjectById: function ( id ) {
  5207. return this.getObjectByProperty( 'id', id );
  5208. },
  5209. getObjectByName: function ( name ) {
  5210. return this.getObjectByProperty( 'name', name );
  5211. },
  5212. getObjectByProperty: function ( name, value ) {
  5213. if ( this[ name ] === value ) return this;
  5214. for ( var i = 0, l = this.children.length; i < l; i ++ ) {
  5215. var child = this.children[ i ];
  5216. var object = child.getObjectByProperty( name, value );
  5217. if ( object !== undefined ) {
  5218. return object;
  5219. }
  5220. }
  5221. return undefined;
  5222. },
  5223. getWorldPosition: function ( target ) {
  5224. if ( target === undefined ) {
  5225. console.warn( 'THREE.Object3D: .getWorldPosition() target is now required' );
  5226. target = new Vector3();
  5227. }
  5228. this.updateMatrixWorld( true );
  5229. return target.setFromMatrixPosition( this.matrixWorld );
  5230. },
  5231. getWorldQuaternion: function () {
  5232. var position = new Vector3();
  5233. var scale = new Vector3();
  5234. return function getWorldQuaternion( target ) {
  5235. if ( target === undefined ) {
  5236. console.warn( 'THREE.Object3D: .getWorldQuaternion() target is now required' );
  5237. target = new Quaternion();
  5238. }
  5239. this.updateMatrixWorld( true );
  5240. this.matrixWorld.decompose( position, target, scale );
  5241. return target;
  5242. };
  5243. }(),
  5244. getWorldScale: function () {
  5245. var position = new Vector3();
  5246. var quaternion = new Quaternion();
  5247. return function getWorldScale( target ) {
  5248. if ( target === undefined ) {
  5249. console.warn( 'THREE.Object3D: .getWorldScale() target is now required' );
  5250. target = new Vector3();
  5251. }
  5252. this.updateMatrixWorld( true );
  5253. this.matrixWorld.decompose( position, quaternion, target );
  5254. return target;
  5255. };
  5256. }(),
  5257. getWorldDirection: function ( target ) {
  5258. if ( target === undefined ) {
  5259. console.warn( 'THREE.Object3D: .getWorldDirection() target is now required' );
  5260. target = new Vector3();
  5261. }
  5262. this.updateMatrixWorld( true );
  5263. var e = this.matrixWorld.elements;
  5264. return target.set( e[ 8 ], e[ 9 ], e[ 10 ] ).normalize();
  5265. },
  5266. raycast: function () {},
  5267. traverse: function ( callback ) {
  5268. callback( this );
  5269. var children = this.children;
  5270. for ( var i = 0, l = children.length; i < l; i ++ ) {
  5271. children[ i ].traverse( callback );
  5272. }
  5273. },
  5274. traverseVisible: function ( callback ) {
  5275. if ( this.visible === false ) return;
  5276. callback( this );
  5277. var children = this.children;
  5278. for ( var i = 0, l = children.length; i < l; i ++ ) {
  5279. children[ i ].traverseVisible( callback );
  5280. }
  5281. },
  5282. traverseAncestors: function ( callback ) {
  5283. var parent = this.parent;
  5284. if ( parent !== null ) {
  5285. callback( parent );
  5286. parent.traverseAncestors( callback );
  5287. }
  5288. },
  5289. updateMatrix: function () {
  5290. this.matrix.compose( this.position, this.quaternion, this.scale );
  5291. this.matrixWorldNeedsUpdate = true;
  5292. },
  5293. updateMatrixWorld: function ( force ) {
  5294. if ( this.matrixAutoUpdate ) this.updateMatrix();
  5295. if ( this.matrixWorldNeedsUpdate || force ) {
  5296. if ( this.parent === null ) {
  5297. this.matrixWorld.copy( this.matrix );
  5298. } else {
  5299. this.matrixWorld.multiplyMatrices( this.parent.matrixWorld, this.matrix );
  5300. }
  5301. this.matrixWorldNeedsUpdate = false;
  5302. force = true;
  5303. }
  5304. // update children
  5305. var children = this.children;
  5306. for ( var i = 0, l = children.length; i < l; i ++ ) {
  5307. children[ i ].updateMatrixWorld( force );
  5308. }
  5309. },
  5310. updateWorldMatrix: function ( updateParents, updateChildren ) {
  5311. var parent = this.parent;
  5312. if ( updateParents === true && parent !== null ) {
  5313. parent.updateWorldMatrix( true, false );
  5314. }
  5315. if ( this.matrixAutoUpdate ) this.updateMatrix();
  5316. if ( this.parent === null ) {
  5317. this.matrixWorld.copy( this.matrix );
  5318. } else {
  5319. this.matrixWorld.multiplyMatrices( this.parent.matrixWorld, this.matrix );
  5320. }
  5321. // update children
  5322. if ( updateChildren === true ) {
  5323. var children = this.children;
  5324. for ( var i = 0, l = children.length; i < l; i ++ ) {
  5325. children[ i ].updateWorldMatrix( false, true );
  5326. }
  5327. }
  5328. },
  5329. toJSON: function ( meta ) {
  5330. // meta is a string when called from JSON.stringify
  5331. var isRootObject = ( meta === undefined || typeof meta === 'string' );
  5332. var output = {};
  5333. // meta is a hash used to collect geometries, materials.
  5334. // not providing it implies that this is the root object
  5335. // being serialized.
  5336. if ( isRootObject ) {
  5337. // initialize meta obj
  5338. meta = {
  5339. geometries: {},
  5340. materials: {},
  5341. textures: {},
  5342. images: {},
  5343. shapes: {}
  5344. };
  5345. output.metadata = {
  5346. version: 4.5,
  5347. type: 'Object',
  5348. generator: 'Object3D.toJSON'
  5349. };
  5350. }
  5351. // standard Object3D serialization
  5352. var object = {};
  5353. object.uuid = this.uuid;
  5354. object.type = this.type;
  5355. if ( this.name !== '' ) object.name = this.name;
  5356. if ( this.castShadow === true ) object.castShadow = true;
  5357. if ( this.receiveShadow === true ) object.receiveShadow = true;
  5358. if ( this.visible === false ) object.visible = false;
  5359. if ( this.frustumCulled === false ) object.frustumCulled = false;
  5360. if ( this.renderOrder !== 0 ) object.renderOrder = this.renderOrder;
  5361. if ( JSON.stringify( this.userData ) !== '{}' ) object.userData = this.userData;
  5362. object.layers = this.layers.mask;
  5363. object.matrix = this.matrix.toArray();
  5364. if ( this.matrixAutoUpdate === false ) object.matrixAutoUpdate = false;
  5365. // object specific properties
  5366. if ( this.isMesh && this.drawMode !== TrianglesDrawMode ) object.drawMode = this.drawMode;
  5367. //
  5368. function serialize( library, element ) {
  5369. if ( library[ element.uuid ] === undefined ) {
  5370. library[ element.uuid ] = element.toJSON( meta );
  5371. }
  5372. return element.uuid;
  5373. }
  5374. if ( this.isMesh || this.isLine || this.isPoints ) {
  5375. object.geometry = serialize( meta.geometries, this.geometry );
  5376. var parameters = this.geometry.parameters;
  5377. if ( parameters !== undefined && parameters.shapes !== undefined ) {
  5378. var shapes = parameters.shapes;
  5379. if ( Array.isArray( shapes ) ) {
  5380. for ( var i = 0, l = shapes.length; i < l; i ++ ) {
  5381. var shape = shapes[ i ];
  5382. serialize( meta.shapes, shape );
  5383. }
  5384. } else {
  5385. serialize( meta.shapes, shapes );
  5386. }
  5387. }
  5388. }
  5389. if ( this.material !== undefined ) {
  5390. if ( Array.isArray( this.material ) ) {
  5391. var uuids = [];
  5392. for ( var i = 0, l = this.material.length; i < l; i ++ ) {
  5393. uuids.push( serialize( meta.materials, this.material[ i ] ) );
  5394. }
  5395. object.material = uuids;
  5396. } else {
  5397. object.material = serialize( meta.materials, this.material );
  5398. }
  5399. }
  5400. //
  5401. if ( this.children.length > 0 ) {
  5402. object.children = [];
  5403. for ( var i = 0; i < this.children.length; i ++ ) {
  5404. object.children.push( this.children[ i ].toJSON( meta ).object );
  5405. }
  5406. }
  5407. if ( isRootObject ) {
  5408. var geometries = extractFromCache( meta.geometries );
  5409. var materials = extractFromCache( meta.materials );
  5410. var textures = extractFromCache( meta.textures );
  5411. var images = extractFromCache( meta.images );
  5412. var shapes = extractFromCache( meta.shapes );
  5413. if ( geometries.length > 0 ) output.geometries = geometries;
  5414. if ( materials.length > 0 ) output.materials = materials;
  5415. if ( textures.length > 0 ) output.textures = textures;
  5416. if ( images.length > 0 ) output.images = images;
  5417. if ( shapes.length > 0 ) output.shapes = shapes;
  5418. }
  5419. output.object = object;
  5420. return output;
  5421. // extract data from the cache hash
  5422. // remove metadata on each item
  5423. // and return as array
  5424. function extractFromCache( cache ) {
  5425. var values = [];
  5426. for ( var key in cache ) {
  5427. var data = cache[ key ];
  5428. delete data.metadata;
  5429. values.push( data );
  5430. }
  5431. return values;
  5432. }
  5433. },
  5434. clone: function ( recursive ) {
  5435. return new this.constructor().copy( this, recursive );
  5436. },
  5437. copy: function ( source, recursive ) {
  5438. if ( recursive === undefined ) recursive = true;
  5439. this.name = source.name;
  5440. this.up.copy( source.up );
  5441. this.position.copy( source.position );
  5442. this.quaternion.copy( source.quaternion );
  5443. this.scale.copy( source.scale );
  5444. this.matrix.copy( source.matrix );
  5445. this.matrixWorld.copy( source.matrixWorld );
  5446. this.matrixAutoUpdate = source.matrixAutoUpdate;
  5447. this.matrixWorldNeedsUpdate = source.matrixWorldNeedsUpdate;
  5448. this.layers.mask = source.layers.mask;
  5449. this.visible = source.visible;
  5450. this.castShadow = source.castShadow;
  5451. this.receiveShadow = source.receiveShadow;
  5452. this.frustumCulled = source.frustumCulled;
  5453. this.renderOrder = source.renderOrder;
  5454. this.userData = JSON.parse( JSON.stringify( source.userData ) );
  5455. if ( recursive === true ) {
  5456. for ( var i = 0; i < source.children.length; i ++ ) {
  5457. var child = source.children[ i ];
  5458. this.add( child.clone() );
  5459. }
  5460. }
  5461. return this;
  5462. }
  5463. } );
  5464. /**
  5465. * @author mrdoob / http://mrdoob.com/
  5466. * @author kile / http://kile.stravaganza.org/
  5467. * @author alteredq / http://alteredqualia.com/
  5468. * @author mikael emtinger / http://gomo.se/
  5469. * @author zz85 / http://www.lab4games.net/zz85/blog
  5470. * @author bhouston / http://clara.io
  5471. */
  5472. var geometryId = 0; // Geometry uses even numbers as Id
  5473. function Geometry() {
  5474. Object.defineProperty( this, 'id', { value: geometryId += 2 } );
  5475. this.uuid = _Math.generateUUID();
  5476. this.name = '';
  5477. this.type = 'Geometry';
  5478. this.vertices = [];
  5479. this.colors = [];
  5480. this.faces = [];
  5481. this.faceVertexUvs = [[]];
  5482. this.morphTargets = [];
  5483. this.morphNormals = [];
  5484. this.skinWeights = [];
  5485. this.skinIndices = [];
  5486. this.lineDistances = [];
  5487. this.boundingBox = null;
  5488. this.boundingSphere = null;
  5489. // update flags
  5490. this.elementsNeedUpdate = false;
  5491. this.verticesNeedUpdate = false;
  5492. this.uvsNeedUpdate = false;
  5493. this.normalsNeedUpdate = false;
  5494. this.colorsNeedUpdate = false;
  5495. this.lineDistancesNeedUpdate = false;
  5496. this.groupsNeedUpdate = false;
  5497. }
  5498. Geometry.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  5499. constructor: Geometry,
  5500. isGeometry: true,
  5501. applyMatrix: function ( matrix ) {
  5502. var normalMatrix = new Matrix3().getNormalMatrix( matrix );
  5503. for ( var i = 0, il = this.vertices.length; i < il; i ++ ) {
  5504. var vertex = this.vertices[ i ];
  5505. vertex.applyMatrix4( matrix );
  5506. }
  5507. for ( var i = 0, il = this.faces.length; i < il; i ++ ) {
  5508. var face = this.faces[ i ];
  5509. face.normal.applyMatrix3( normalMatrix ).normalize();
  5510. for ( var j = 0, jl = face.vertexNormals.length; j < jl; j ++ ) {
  5511. face.vertexNormals[ j ].applyMatrix3( normalMatrix ).normalize();
  5512. }
  5513. }
  5514. if ( this.boundingBox !== null ) {
  5515. this.computeBoundingBox();
  5516. }
  5517. if ( this.boundingSphere !== null ) {
  5518. this.computeBoundingSphere();
  5519. }
  5520. this.verticesNeedUpdate = true;
  5521. this.normalsNeedUpdate = true;
  5522. return this;
  5523. },
  5524. rotateX: function () {
  5525. // rotate geometry around world x-axis
  5526. var m1 = new Matrix4();
  5527. return function rotateX( angle ) {
  5528. m1.makeRotationX( angle );
  5529. this.applyMatrix( m1 );
  5530. return this;
  5531. };
  5532. }(),
  5533. rotateY: function () {
  5534. // rotate geometry around world y-axis
  5535. var m1 = new Matrix4();
  5536. return function rotateY( angle ) {
  5537. m1.makeRotationY( angle );
  5538. this.applyMatrix( m1 );
  5539. return this;
  5540. };
  5541. }(),
  5542. rotateZ: function () {
  5543. // rotate geometry around world z-axis
  5544. var m1 = new Matrix4();
  5545. return function rotateZ( angle ) {
  5546. m1.makeRotationZ( angle );
  5547. this.applyMatrix( m1 );
  5548. return this;
  5549. };
  5550. }(),
  5551. translate: function () {
  5552. // translate geometry
  5553. var m1 = new Matrix4();
  5554. return function translate( x, y, z ) {
  5555. m1.makeTranslation( x, y, z );
  5556. this.applyMatrix( m1 );
  5557. return this;
  5558. };
  5559. }(),
  5560. scale: function () {
  5561. // scale geometry
  5562. var m1 = new Matrix4();
  5563. return function scale( x, y, z ) {
  5564. m1.makeScale( x, y, z );
  5565. this.applyMatrix( m1 );
  5566. return this;
  5567. };
  5568. }(),
  5569. lookAt: function () {
  5570. var obj = new Object3D();
  5571. return function lookAt( vector ) {
  5572. obj.lookAt( vector );
  5573. obj.updateMatrix();
  5574. this.applyMatrix( obj.matrix );
  5575. };
  5576. }(),
  5577. fromBufferGeometry: function ( geometry ) {
  5578. var scope = this;
  5579. var indices = geometry.index !== null ? geometry.index.array : undefined;
  5580. var attributes = geometry.attributes;
  5581. var positions = attributes.position.array;
  5582. var normals = attributes.normal !== undefined ? attributes.normal.array : undefined;
  5583. var colors = attributes.color !== undefined ? attributes.color.array : undefined;
  5584. var uvs = attributes.uv !== undefined ? attributes.uv.array : undefined;
  5585. var uvs2 = attributes.uv2 !== undefined ? attributes.uv2.array : undefined;
  5586. if ( uvs2 !== undefined ) this.faceVertexUvs[ 1 ] = [];
  5587. for ( var i = 0; i < positions.length; i += 3 ) {
  5588. scope.vertices.push( new Vector3().fromArray( positions, i ) );
  5589. if ( colors !== undefined ) {
  5590. scope.colors.push( new Color().fromArray( colors, i ) );
  5591. }
  5592. }
  5593. function addFace( a, b, c, materialIndex ) {
  5594. var vertexColors = ( colors === undefined ) ? [] : [
  5595. scope.colors[ a ].clone(),
  5596. scope.colors[ b ].clone(),
  5597. scope.colors[ c ].clone() ];
  5598. var vertexNormals = ( normals === undefined ) ? [] : [
  5599. new Vector3().fromArray( normals, a * 3 ),
  5600. new Vector3().fromArray( normals, b * 3 ),
  5601. new Vector3().fromArray( normals, c * 3 )
  5602. ];
  5603. var face = new Face3( a, b, c, vertexNormals, vertexColors, materialIndex );
  5604. scope.faces.push( face );
  5605. if ( uvs !== undefined ) {
  5606. scope.faceVertexUvs[ 0 ].push( [
  5607. new Vector2().fromArray( uvs, a * 2 ),
  5608. new Vector2().fromArray( uvs, b * 2 ),
  5609. new Vector2().fromArray( uvs, c * 2 )
  5610. ] );
  5611. }
  5612. if ( uvs2 !== undefined ) {
  5613. scope.faceVertexUvs[ 1 ].push( [
  5614. new Vector2().fromArray( uvs2, a * 2 ),
  5615. new Vector2().fromArray( uvs2, b * 2 ),
  5616. new Vector2().fromArray( uvs2, c * 2 )
  5617. ] );
  5618. }
  5619. }
  5620. var groups = geometry.groups;
  5621. if ( groups.length > 0 ) {
  5622. for ( var i = 0; i < groups.length; i ++ ) {
  5623. var group = groups[ i ];
  5624. var start = group.start;
  5625. var count = group.count;
  5626. for ( var j = start, jl = start + count; j < jl; j += 3 ) {
  5627. if ( indices !== undefined ) {
  5628. addFace( indices[ j ], indices[ j + 1 ], indices[ j + 2 ], group.materialIndex );
  5629. } else {
  5630. addFace( j, j + 1, j + 2, group.materialIndex );
  5631. }
  5632. }
  5633. }
  5634. } else {
  5635. if ( indices !== undefined ) {
  5636. for ( var i = 0; i < indices.length; i += 3 ) {
  5637. addFace( indices[ i ], indices[ i + 1 ], indices[ i + 2 ] );
  5638. }
  5639. } else {
  5640. for ( var i = 0; i < positions.length / 3; i += 3 ) {
  5641. addFace( i, i + 1, i + 2 );
  5642. }
  5643. }
  5644. }
  5645. this.computeFaceNormals();
  5646. if ( geometry.boundingBox !== null ) {
  5647. this.boundingBox = geometry.boundingBox.clone();
  5648. }
  5649. if ( geometry.boundingSphere !== null ) {
  5650. this.boundingSphere = geometry.boundingSphere.clone();
  5651. }
  5652. return this;
  5653. },
  5654. center: function () {
  5655. var offset = new Vector3();
  5656. return function center() {
  5657. this.computeBoundingBox();
  5658. this.boundingBox.getCenter( offset ).negate();
  5659. this.translate( offset.x, offset.y, offset.z );
  5660. return this;
  5661. };
  5662. }(),
  5663. normalize: function () {
  5664. this.computeBoundingSphere();
  5665. var center = this.boundingSphere.center;
  5666. var radius = this.boundingSphere.radius;
  5667. var s = radius === 0 ? 1 : 1.0 / radius;
  5668. var matrix = new Matrix4();
  5669. matrix.set(
  5670. s, 0, 0, - s * center.x,
  5671. 0, s, 0, - s * center.y,
  5672. 0, 0, s, - s * center.z,
  5673. 0, 0, 0, 1
  5674. );
  5675. this.applyMatrix( matrix );
  5676. return this;
  5677. },
  5678. computeFaceNormals: function () {
  5679. var cb = new Vector3(), ab = new Vector3();
  5680. for ( var f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5681. var face = this.faces[ f ];
  5682. var vA = this.vertices[ face.a ];
  5683. var vB = this.vertices[ face.b ];
  5684. var vC = this.vertices[ face.c ];
  5685. cb.subVectors( vC, vB );
  5686. ab.subVectors( vA, vB );
  5687. cb.cross( ab );
  5688. cb.normalize();
  5689. face.normal.copy( cb );
  5690. }
  5691. },
  5692. computeVertexNormals: function ( areaWeighted ) {
  5693. if ( areaWeighted === undefined ) areaWeighted = true;
  5694. var v, vl, f, fl, face, vertices;
  5695. vertices = new Array( this.vertices.length );
  5696. for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) {
  5697. vertices[ v ] = new Vector3();
  5698. }
  5699. if ( areaWeighted ) {
  5700. // vertex normals weighted by triangle areas
  5701. // http://www.iquilezles.org/www/articles/normals/normals.htm
  5702. var vA, vB, vC;
  5703. var cb = new Vector3(), ab = new Vector3();
  5704. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5705. face = this.faces[ f ];
  5706. vA = this.vertices[ face.a ];
  5707. vB = this.vertices[ face.b ];
  5708. vC = this.vertices[ face.c ];
  5709. cb.subVectors( vC, vB );
  5710. ab.subVectors( vA, vB );
  5711. cb.cross( ab );
  5712. vertices[ face.a ].add( cb );
  5713. vertices[ face.b ].add( cb );
  5714. vertices[ face.c ].add( cb );
  5715. }
  5716. } else {
  5717. this.computeFaceNormals();
  5718. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5719. face = this.faces[ f ];
  5720. vertices[ face.a ].add( face.normal );
  5721. vertices[ face.b ].add( face.normal );
  5722. vertices[ face.c ].add( face.normal );
  5723. }
  5724. }
  5725. for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) {
  5726. vertices[ v ].normalize();
  5727. }
  5728. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5729. face = this.faces[ f ];
  5730. var vertexNormals = face.vertexNormals;
  5731. if ( vertexNormals.length === 3 ) {
  5732. vertexNormals[ 0 ].copy( vertices[ face.a ] );
  5733. vertexNormals[ 1 ].copy( vertices[ face.b ] );
  5734. vertexNormals[ 2 ].copy( vertices[ face.c ] );
  5735. } else {
  5736. vertexNormals[ 0 ] = vertices[ face.a ].clone();
  5737. vertexNormals[ 1 ] = vertices[ face.b ].clone();
  5738. vertexNormals[ 2 ] = vertices[ face.c ].clone();
  5739. }
  5740. }
  5741. if ( this.faces.length > 0 ) {
  5742. this.normalsNeedUpdate = true;
  5743. }
  5744. },
  5745. computeFlatVertexNormals: function () {
  5746. var f, fl, face;
  5747. this.computeFaceNormals();
  5748. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5749. face = this.faces[ f ];
  5750. var vertexNormals = face.vertexNormals;
  5751. if ( vertexNormals.length === 3 ) {
  5752. vertexNormals[ 0 ].copy( face.normal );
  5753. vertexNormals[ 1 ].copy( face.normal );
  5754. vertexNormals[ 2 ].copy( face.normal );
  5755. } else {
  5756. vertexNormals[ 0 ] = face.normal.clone();
  5757. vertexNormals[ 1 ] = face.normal.clone();
  5758. vertexNormals[ 2 ] = face.normal.clone();
  5759. }
  5760. }
  5761. if ( this.faces.length > 0 ) {
  5762. this.normalsNeedUpdate = true;
  5763. }
  5764. },
  5765. computeMorphNormals: function () {
  5766. var i, il, f, fl, face;
  5767. // save original normals
  5768. // - create temp variables on first access
  5769. // otherwise just copy (for faster repeated calls)
  5770. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5771. face = this.faces[ f ];
  5772. if ( ! face.__originalFaceNormal ) {
  5773. face.__originalFaceNormal = face.normal.clone();
  5774. } else {
  5775. face.__originalFaceNormal.copy( face.normal );
  5776. }
  5777. if ( ! face.__originalVertexNormals ) face.__originalVertexNormals = [];
  5778. for ( i = 0, il = face.vertexNormals.length; i < il; i ++ ) {
  5779. if ( ! face.__originalVertexNormals[ i ] ) {
  5780. face.__originalVertexNormals[ i ] = face.vertexNormals[ i ].clone();
  5781. } else {
  5782. face.__originalVertexNormals[ i ].copy( face.vertexNormals[ i ] );
  5783. }
  5784. }
  5785. }
  5786. // use temp geometry to compute face and vertex normals for each morph
  5787. var tmpGeo = new Geometry();
  5788. tmpGeo.faces = this.faces;
  5789. for ( i = 0, il = this.morphTargets.length; i < il; i ++ ) {
  5790. // create on first access
  5791. if ( ! this.morphNormals[ i ] ) {
  5792. this.morphNormals[ i ] = {};
  5793. this.morphNormals[ i ].faceNormals = [];
  5794. this.morphNormals[ i ].vertexNormals = [];
  5795. var dstNormalsFace = this.morphNormals[ i ].faceNormals;
  5796. var dstNormalsVertex = this.morphNormals[ i ].vertexNormals;
  5797. var faceNormal, vertexNormals;
  5798. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5799. faceNormal = new Vector3();
  5800. vertexNormals = { a: new Vector3(), b: new Vector3(), c: new Vector3() };
  5801. dstNormalsFace.push( faceNormal );
  5802. dstNormalsVertex.push( vertexNormals );
  5803. }
  5804. }
  5805. var morphNormals = this.morphNormals[ i ];
  5806. // set vertices to morph target
  5807. tmpGeo.vertices = this.morphTargets[ i ].vertices;
  5808. // compute morph normals
  5809. tmpGeo.computeFaceNormals();
  5810. tmpGeo.computeVertexNormals();
  5811. // store morph normals
  5812. var faceNormal, vertexNormals;
  5813. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5814. face = this.faces[ f ];
  5815. faceNormal = morphNormals.faceNormals[ f ];
  5816. vertexNormals = morphNormals.vertexNormals[ f ];
  5817. faceNormal.copy( face.normal );
  5818. vertexNormals.a.copy( face.vertexNormals[ 0 ] );
  5819. vertexNormals.b.copy( face.vertexNormals[ 1 ] );
  5820. vertexNormals.c.copy( face.vertexNormals[ 2 ] );
  5821. }
  5822. }
  5823. // restore original normals
  5824. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5825. face = this.faces[ f ];
  5826. face.normal = face.__originalFaceNormal;
  5827. face.vertexNormals = face.__originalVertexNormals;
  5828. }
  5829. },
  5830. computeBoundingBox: function () {
  5831. if ( this.boundingBox === null ) {
  5832. this.boundingBox = new Box3();
  5833. }
  5834. this.boundingBox.setFromPoints( this.vertices );
  5835. },
  5836. computeBoundingSphere: function () {
  5837. if ( this.boundingSphere === null ) {
  5838. this.boundingSphere = new Sphere();
  5839. }
  5840. this.boundingSphere.setFromPoints( this.vertices );
  5841. },
  5842. merge: function ( geometry, matrix, materialIndexOffset ) {
  5843. if ( ! ( geometry && geometry.isGeometry ) ) {
  5844. console.error( 'THREE.Geometry.merge(): geometry not an instance of THREE.Geometry.', geometry );
  5845. return;
  5846. }
  5847. var normalMatrix,
  5848. vertexOffset = this.vertices.length,
  5849. vertices1 = this.vertices,
  5850. vertices2 = geometry.vertices,
  5851. faces1 = this.faces,
  5852. faces2 = geometry.faces,
  5853. uvs1 = this.faceVertexUvs[ 0 ],
  5854. uvs2 = geometry.faceVertexUvs[ 0 ],
  5855. colors1 = this.colors,
  5856. colors2 = geometry.colors;
  5857. if ( materialIndexOffset === undefined ) materialIndexOffset = 0;
  5858. if ( matrix !== undefined ) {
  5859. normalMatrix = new Matrix3().getNormalMatrix( matrix );
  5860. }
  5861. // vertices
  5862. for ( var i = 0, il = vertices2.length; i < il; i ++ ) {
  5863. var vertex = vertices2[ i ];
  5864. var vertexCopy = vertex.clone();
  5865. if ( matrix !== undefined ) vertexCopy.applyMatrix4( matrix );
  5866. vertices1.push( vertexCopy );
  5867. }
  5868. // colors
  5869. for ( var i = 0, il = colors2.length; i < il; i ++ ) {
  5870. colors1.push( colors2[ i ].clone() );
  5871. }
  5872. // faces
  5873. for ( i = 0, il = faces2.length; i < il; i ++ ) {
  5874. var face = faces2[ i ], faceCopy, normal, color,
  5875. faceVertexNormals = face.vertexNormals,
  5876. faceVertexColors = face.vertexColors;
  5877. faceCopy = new Face3( face.a + vertexOffset, face.b + vertexOffset, face.c + vertexOffset );
  5878. faceCopy.normal.copy( face.normal );
  5879. if ( normalMatrix !== undefined ) {
  5880. faceCopy.normal.applyMatrix3( normalMatrix ).normalize();
  5881. }
  5882. for ( var j = 0, jl = faceVertexNormals.length; j < jl; j ++ ) {
  5883. normal = faceVertexNormals[ j ].clone();
  5884. if ( normalMatrix !== undefined ) {
  5885. normal.applyMatrix3( normalMatrix ).normalize();
  5886. }
  5887. faceCopy.vertexNormals.push( normal );
  5888. }
  5889. faceCopy.color.copy( face.color );
  5890. for ( var j = 0, jl = faceVertexColors.length; j < jl; j ++ ) {
  5891. color = faceVertexColors[ j ];
  5892. faceCopy.vertexColors.push( color.clone() );
  5893. }
  5894. faceCopy.materialIndex = face.materialIndex + materialIndexOffset;
  5895. faces1.push( faceCopy );
  5896. }
  5897. // uvs
  5898. for ( i = 0, il = uvs2.length; i < il; i ++ ) {
  5899. var uv = uvs2[ i ], uvCopy = [];
  5900. if ( uv === undefined ) {
  5901. continue;
  5902. }
  5903. for ( var j = 0, jl = uv.length; j < jl; j ++ ) {
  5904. uvCopy.push( uv[ j ].clone() );
  5905. }
  5906. uvs1.push( uvCopy );
  5907. }
  5908. },
  5909. mergeMesh: function ( mesh ) {
  5910. if ( ! ( mesh && mesh.isMesh ) ) {
  5911. console.error( 'THREE.Geometry.mergeMesh(): mesh not an instance of THREE.Mesh.', mesh );
  5912. return;
  5913. }
  5914. if ( mesh.matrixAutoUpdate ) mesh.updateMatrix();
  5915. this.merge( mesh.geometry, mesh.matrix );
  5916. },
  5917. /*
  5918. * Checks for duplicate vertices with hashmap.
  5919. * Duplicated vertices are removed
  5920. * and faces' vertices are updated.
  5921. */
  5922. mergeVertices: function () {
  5923. var verticesMap = {}; // Hashmap for looking up vertices by position coordinates (and making sure they are unique)
  5924. var unique = [], changes = [];
  5925. var v, key;
  5926. var precisionPoints = 4; // number of decimal points, e.g. 4 for epsilon of 0.0001
  5927. var precision = Math.pow( 10, precisionPoints );
  5928. var i, il, face;
  5929. var indices, j, jl;
  5930. for ( i = 0, il = this.vertices.length; i < il; i ++ ) {
  5931. v = this.vertices[ i ];
  5932. key = Math.round( v.x * precision ) + '_' + Math.round( v.y * precision ) + '_' + Math.round( v.z * precision );
  5933. if ( verticesMap[ key ] === undefined ) {
  5934. verticesMap[ key ] = i;
  5935. unique.push( this.vertices[ i ] );
  5936. changes[ i ] = unique.length - 1;
  5937. } else {
  5938. //console.log('Duplicate vertex found. ', i, ' could be using ', verticesMap[key]);
  5939. changes[ i ] = changes[ verticesMap[ key ] ];
  5940. }
  5941. }
  5942. // if faces are completely degenerate after merging vertices, we
  5943. // have to remove them from the geometry.
  5944. var faceIndicesToRemove = [];
  5945. for ( i = 0, il = this.faces.length; i < il; i ++ ) {
  5946. face = this.faces[ i ];
  5947. face.a = changes[ face.a ];
  5948. face.b = changes[ face.b ];
  5949. face.c = changes[ face.c ];
  5950. indices = [ face.a, face.b, face.c ];
  5951. // if any duplicate vertices are found in a Face3
  5952. // we have to remove the face as nothing can be saved
  5953. for ( var n = 0; n < 3; n ++ ) {
  5954. if ( indices[ n ] === indices[ ( n + 1 ) % 3 ] ) {
  5955. faceIndicesToRemove.push( i );
  5956. break;
  5957. }
  5958. }
  5959. }
  5960. for ( i = faceIndicesToRemove.length - 1; i >= 0; i -- ) {
  5961. var idx = faceIndicesToRemove[ i ];
  5962. this.faces.splice( idx, 1 );
  5963. for ( j = 0, jl = this.faceVertexUvs.length; j < jl; j ++ ) {
  5964. this.faceVertexUvs[ j ].splice( idx, 1 );
  5965. }
  5966. }
  5967. // Use unique set of vertices
  5968. var diff = this.vertices.length - unique.length;
  5969. this.vertices = unique;
  5970. return diff;
  5971. },
  5972. setFromPoints: function ( points ) {
  5973. this.vertices = [];
  5974. for ( var i = 0, l = points.length; i < l; i ++ ) {
  5975. var point = points[ i ];
  5976. this.vertices.push( new Vector3( point.x, point.y, point.z || 0 ) );
  5977. }
  5978. return this;
  5979. },
  5980. sortFacesByMaterialIndex: function () {
  5981. var faces = this.faces;
  5982. var length = faces.length;
  5983. // tag faces
  5984. for ( var i = 0; i < length; i ++ ) {
  5985. faces[ i ]._id = i;
  5986. }
  5987. // sort faces
  5988. function materialIndexSort( a, b ) {
  5989. return a.materialIndex - b.materialIndex;
  5990. }
  5991. faces.sort( materialIndexSort );
  5992. // sort uvs
  5993. var uvs1 = this.faceVertexUvs[ 0 ];
  5994. var uvs2 = this.faceVertexUvs[ 1 ];
  5995. var newUvs1, newUvs2;
  5996. if ( uvs1 && uvs1.length === length ) newUvs1 = [];
  5997. if ( uvs2 && uvs2.length === length ) newUvs2 = [];
  5998. for ( var i = 0; i < length; i ++ ) {
  5999. var id = faces[ i ]._id;
  6000. if ( newUvs1 ) newUvs1.push( uvs1[ id ] );
  6001. if ( newUvs2 ) newUvs2.push( uvs2[ id ] );
  6002. }
  6003. if ( newUvs1 ) this.faceVertexUvs[ 0 ] = newUvs1;
  6004. if ( newUvs2 ) this.faceVertexUvs[ 1 ] = newUvs2;
  6005. },
  6006. toJSON: function () {
  6007. var data = {
  6008. metadata: {
  6009. version: 4.5,
  6010. type: 'Geometry',
  6011. generator: 'Geometry.toJSON'
  6012. }
  6013. };
  6014. // standard Geometry serialization
  6015. data.uuid = this.uuid;
  6016. data.type = this.type;
  6017. if ( this.name !== '' ) data.name = this.name;
  6018. if ( this.parameters !== undefined ) {
  6019. var parameters = this.parameters;
  6020. for ( var key in parameters ) {
  6021. if ( parameters[ key ] !== undefined ) data[ key ] = parameters[ key ];
  6022. }
  6023. return data;
  6024. }
  6025. var vertices = [];
  6026. for ( var i = 0; i < this.vertices.length; i ++ ) {
  6027. var vertex = this.vertices[ i ];
  6028. vertices.push( vertex.x, vertex.y, vertex.z );
  6029. }
  6030. var faces = [];
  6031. var normals = [];
  6032. var normalsHash = {};
  6033. var colors = [];
  6034. var colorsHash = {};
  6035. var uvs = [];
  6036. var uvsHash = {};
  6037. for ( var i = 0; i < this.faces.length; i ++ ) {
  6038. var face = this.faces[ i ];
  6039. var hasMaterial = true;
  6040. var hasFaceUv = false; // deprecated
  6041. var hasFaceVertexUv = this.faceVertexUvs[ 0 ][ i ] !== undefined;
  6042. var hasFaceNormal = face.normal.length() > 0;
  6043. var hasFaceVertexNormal = face.vertexNormals.length > 0;
  6044. var hasFaceColor = face.color.r !== 1 || face.color.g !== 1 || face.color.b !== 1;
  6045. var hasFaceVertexColor = face.vertexColors.length > 0;
  6046. var faceType = 0;
  6047. faceType = setBit( faceType, 0, 0 ); // isQuad
  6048. faceType = setBit( faceType, 1, hasMaterial );
  6049. faceType = setBit( faceType, 2, hasFaceUv );
  6050. faceType = setBit( faceType, 3, hasFaceVertexUv );
  6051. faceType = setBit( faceType, 4, hasFaceNormal );
  6052. faceType = setBit( faceType, 5, hasFaceVertexNormal );
  6053. faceType = setBit( faceType, 6, hasFaceColor );
  6054. faceType = setBit( faceType, 7, hasFaceVertexColor );
  6055. faces.push( faceType );
  6056. faces.push( face.a, face.b, face.c );
  6057. faces.push( face.materialIndex );
  6058. if ( hasFaceVertexUv ) {
  6059. var faceVertexUvs = this.faceVertexUvs[ 0 ][ i ];
  6060. faces.push(
  6061. getUvIndex( faceVertexUvs[ 0 ] ),
  6062. getUvIndex( faceVertexUvs[ 1 ] ),
  6063. getUvIndex( faceVertexUvs[ 2 ] )
  6064. );
  6065. }
  6066. if ( hasFaceNormal ) {
  6067. faces.push( getNormalIndex( face.normal ) );
  6068. }
  6069. if ( hasFaceVertexNormal ) {
  6070. var vertexNormals = face.vertexNormals;
  6071. faces.push(
  6072. getNormalIndex( vertexNormals[ 0 ] ),
  6073. getNormalIndex( vertexNormals[ 1 ] ),
  6074. getNormalIndex( vertexNormals[ 2 ] )
  6075. );
  6076. }
  6077. if ( hasFaceColor ) {
  6078. faces.push( getColorIndex( face.color ) );
  6079. }
  6080. if ( hasFaceVertexColor ) {
  6081. var vertexColors = face.vertexColors;
  6082. faces.push(
  6083. getColorIndex( vertexColors[ 0 ] ),
  6084. getColorIndex( vertexColors[ 1 ] ),
  6085. getColorIndex( vertexColors[ 2 ] )
  6086. );
  6087. }
  6088. }
  6089. function setBit( value, position, enabled ) {
  6090. return enabled ? value | ( 1 << position ) : value & ( ~ ( 1 << position ) );
  6091. }
  6092. function getNormalIndex( normal ) {
  6093. var hash = normal.x.toString() + normal.y.toString() + normal.z.toString();
  6094. if ( normalsHash[ hash ] !== undefined ) {
  6095. return normalsHash[ hash ];
  6096. }
  6097. normalsHash[ hash ] = normals.length / 3;
  6098. normals.push( normal.x, normal.y, normal.z );
  6099. return normalsHash[ hash ];
  6100. }
  6101. function getColorIndex( color ) {
  6102. var hash = color.r.toString() + color.g.toString() + color.b.toString();
  6103. if ( colorsHash[ hash ] !== undefined ) {
  6104. return colorsHash[ hash ];
  6105. }
  6106. colorsHash[ hash ] = colors.length;
  6107. colors.push( color.getHex() );
  6108. return colorsHash[ hash ];
  6109. }
  6110. function getUvIndex( uv ) {
  6111. var hash = uv.x.toString() + uv.y.toString();
  6112. if ( uvsHash[ hash ] !== undefined ) {
  6113. return uvsHash[ hash ];
  6114. }
  6115. uvsHash[ hash ] = uvs.length / 2;
  6116. uvs.push( uv.x, uv.y );
  6117. return uvsHash[ hash ];
  6118. }
  6119. data.data = {};
  6120. data.data.vertices = vertices;
  6121. data.data.normals = normals;
  6122. if ( colors.length > 0 ) data.data.colors = colors;
  6123. if ( uvs.length > 0 ) data.data.uvs = [ uvs ]; // temporal backward compatibility
  6124. data.data.faces = faces;
  6125. return data;
  6126. },
  6127. clone: function () {
  6128. /*
  6129. // Handle primitives
  6130. var parameters = this.parameters;
  6131. if ( parameters !== undefined ) {
  6132. var values = [];
  6133. for ( var key in parameters ) {
  6134. values.push( parameters[ key ] );
  6135. }
  6136. var geometry = Object.create( this.constructor.prototype );
  6137. this.constructor.apply( geometry, values );
  6138. return geometry;
  6139. }
  6140. return new this.constructor().copy( this );
  6141. */
  6142. return new Geometry().copy( this );
  6143. },
  6144. copy: function ( source ) {
  6145. var i, il, j, jl, k, kl;
  6146. // reset
  6147. this.vertices = [];
  6148. this.colors = [];
  6149. this.faces = [];
  6150. this.faceVertexUvs = [[]];
  6151. this.morphTargets = [];
  6152. this.morphNormals = [];
  6153. this.skinWeights = [];
  6154. this.skinIndices = [];
  6155. this.lineDistances = [];
  6156. this.boundingBox = null;
  6157. this.boundingSphere = null;
  6158. // name
  6159. this.name = source.name;
  6160. // vertices
  6161. var vertices = source.vertices;
  6162. for ( i = 0, il = vertices.length; i < il; i ++ ) {
  6163. this.vertices.push( vertices[ i ].clone() );
  6164. }
  6165. // colors
  6166. var colors = source.colors;
  6167. for ( i = 0, il = colors.length; i < il; i ++ ) {
  6168. this.colors.push( colors[ i ].clone() );
  6169. }
  6170. // faces
  6171. var faces = source.faces;
  6172. for ( i = 0, il = faces.length; i < il; i ++ ) {
  6173. this.faces.push( faces[ i ].clone() );
  6174. }
  6175. // face vertex uvs
  6176. for ( i = 0, il = source.faceVertexUvs.length; i < il; i ++ ) {
  6177. var faceVertexUvs = source.faceVertexUvs[ i ];
  6178. if ( this.faceVertexUvs[ i ] === undefined ) {
  6179. this.faceVertexUvs[ i ] = [];
  6180. }
  6181. for ( j = 0, jl = faceVertexUvs.length; j < jl; j ++ ) {
  6182. var uvs = faceVertexUvs[ j ], uvsCopy = [];
  6183. for ( k = 0, kl = uvs.length; k < kl; k ++ ) {
  6184. var uv = uvs[ k ];
  6185. uvsCopy.push( uv.clone() );
  6186. }
  6187. this.faceVertexUvs[ i ].push( uvsCopy );
  6188. }
  6189. }
  6190. // morph targets
  6191. var morphTargets = source.morphTargets;
  6192. for ( i = 0, il = morphTargets.length; i < il; i ++ ) {
  6193. var morphTarget = {};
  6194. morphTarget.name = morphTargets[ i ].name;
  6195. // vertices
  6196. if ( morphTargets[ i ].vertices !== undefined ) {
  6197. morphTarget.vertices = [];
  6198. for ( j = 0, jl = morphTargets[ i ].vertices.length; j < jl; j ++ ) {
  6199. morphTarget.vertices.push( morphTargets[ i ].vertices[ j ].clone() );
  6200. }
  6201. }
  6202. // normals
  6203. if ( morphTargets[ i ].normals !== undefined ) {
  6204. morphTarget.normals = [];
  6205. for ( j = 0, jl = morphTargets[ i ].normals.length; j < jl; j ++ ) {
  6206. morphTarget.normals.push( morphTargets[ i ].normals[ j ].clone() );
  6207. }
  6208. }
  6209. this.morphTargets.push( morphTarget );
  6210. }
  6211. // morph normals
  6212. var morphNormals = source.morphNormals;
  6213. for ( i = 0, il = morphNormals.length; i < il; i ++ ) {
  6214. var morphNormal = {};
  6215. // vertex normals
  6216. if ( morphNormals[ i ].vertexNormals !== undefined ) {
  6217. morphNormal.vertexNormals = [];
  6218. for ( j = 0, jl = morphNormals[ i ].vertexNormals.length; j < jl; j ++ ) {
  6219. var srcVertexNormal = morphNormals[ i ].vertexNormals[ j ];
  6220. var destVertexNormal = {};
  6221. destVertexNormal.a = srcVertexNormal.a.clone();
  6222. destVertexNormal.b = srcVertexNormal.b.clone();
  6223. destVertexNormal.c = srcVertexNormal.c.clone();
  6224. morphNormal.vertexNormals.push( destVertexNormal );
  6225. }
  6226. }
  6227. // face normals
  6228. if ( morphNormals[ i ].faceNormals !== undefined ) {
  6229. morphNormal.faceNormals = [];
  6230. for ( j = 0, jl = morphNormals[ i ].faceNormals.length; j < jl; j ++ ) {
  6231. morphNormal.faceNormals.push( morphNormals[ i ].faceNormals[ j ].clone() );
  6232. }
  6233. }
  6234. this.morphNormals.push( morphNormal );
  6235. }
  6236. // skin weights
  6237. var skinWeights = source.skinWeights;
  6238. for ( i = 0, il = skinWeights.length; i < il; i ++ ) {
  6239. this.skinWeights.push( skinWeights[ i ].clone() );
  6240. }
  6241. // skin indices
  6242. var skinIndices = source.skinIndices;
  6243. for ( i = 0, il = skinIndices.length; i < il; i ++ ) {
  6244. this.skinIndices.push( skinIndices[ i ].clone() );
  6245. }
  6246. // line distances
  6247. var lineDistances = source.lineDistances;
  6248. for ( i = 0, il = lineDistances.length; i < il; i ++ ) {
  6249. this.lineDistances.push( lineDistances[ i ] );
  6250. }
  6251. // bounding box
  6252. var boundingBox = source.boundingBox;
  6253. if ( boundingBox !== null ) {
  6254. this.boundingBox = boundingBox.clone();
  6255. }
  6256. // bounding sphere
  6257. var boundingSphere = source.boundingSphere;
  6258. if ( boundingSphere !== null ) {
  6259. this.boundingSphere = boundingSphere.clone();
  6260. }
  6261. // update flags
  6262. this.elementsNeedUpdate = source.elementsNeedUpdate;
  6263. this.verticesNeedUpdate = source.verticesNeedUpdate;
  6264. this.uvsNeedUpdate = source.uvsNeedUpdate;
  6265. this.normalsNeedUpdate = source.normalsNeedUpdate;
  6266. this.colorsNeedUpdate = source.colorsNeedUpdate;
  6267. this.lineDistancesNeedUpdate = source.lineDistancesNeedUpdate;
  6268. this.groupsNeedUpdate = source.groupsNeedUpdate;
  6269. return this;
  6270. },
  6271. dispose: function () {
  6272. this.dispatchEvent( { type: 'dispose' } );
  6273. }
  6274. } );
  6275. /**
  6276. * @author mrdoob / http://mrdoob.com/
  6277. */
  6278. function BufferAttribute( array, itemSize, normalized ) {
  6279. if ( Array.isArray( array ) ) {
  6280. throw new TypeError( 'THREE.BufferAttribute: array should be a Typed Array.' );
  6281. }
  6282. this.name = '';
  6283. this.array = array;
  6284. this.itemSize = itemSize;
  6285. this.count = array !== undefined ? array.length / itemSize : 0;
  6286. this.normalized = normalized === true;
  6287. this.dynamic = false;
  6288. this.updateRange = { offset: 0, count: - 1 };
  6289. this.version = 0;
  6290. }
  6291. Object.defineProperty( BufferAttribute.prototype, 'needsUpdate', {
  6292. set: function ( value ) {
  6293. if ( value === true ) this.version ++;
  6294. }
  6295. } );
  6296. Object.assign( BufferAttribute.prototype, {
  6297. isBufferAttribute: true,
  6298. onUploadCallback: function () {},
  6299. setArray: function ( array ) {
  6300. if ( Array.isArray( array ) ) {
  6301. throw new TypeError( 'THREE.BufferAttribute: array should be a Typed Array.' );
  6302. }
  6303. this.count = array !== undefined ? array.length / this.itemSize : 0;
  6304. this.array = array;
  6305. return this;
  6306. },
  6307. setDynamic: function ( value ) {
  6308. this.dynamic = value;
  6309. return this;
  6310. },
  6311. copy: function ( source ) {
  6312. this.name = source.name;
  6313. this.array = new source.array.constructor( source.array );
  6314. this.itemSize = source.itemSize;
  6315. this.count = source.count;
  6316. this.normalized = source.normalized;
  6317. this.dynamic = source.dynamic;
  6318. return this;
  6319. },
  6320. copyAt: function ( index1, attribute, index2 ) {
  6321. index1 *= this.itemSize;
  6322. index2 *= attribute.itemSize;
  6323. for ( var i = 0, l = this.itemSize; i < l; i ++ ) {
  6324. this.array[ index1 + i ] = attribute.array[ index2 + i ];
  6325. }
  6326. return this;
  6327. },
  6328. copyArray: function ( array ) {
  6329. this.array.set( array );
  6330. return this;
  6331. },
  6332. copyColorsArray: function ( colors ) {
  6333. var array = this.array, offset = 0;
  6334. for ( var i = 0, l = colors.length; i < l; i ++ ) {
  6335. var color = colors[ i ];
  6336. if ( color === undefined ) {
  6337. console.warn( 'THREE.BufferAttribute.copyColorsArray(): color is undefined', i );
  6338. color = new Color();
  6339. }
  6340. array[ offset ++ ] = color.r;
  6341. array[ offset ++ ] = color.g;
  6342. array[ offset ++ ] = color.b;
  6343. }
  6344. return this;
  6345. },
  6346. copyVector2sArray: function ( vectors ) {
  6347. var array = this.array, offset = 0;
  6348. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  6349. var vector = vectors[ i ];
  6350. if ( vector === undefined ) {
  6351. console.warn( 'THREE.BufferAttribute.copyVector2sArray(): vector is undefined', i );
  6352. vector = new Vector2();
  6353. }
  6354. array[ offset ++ ] = vector.x;
  6355. array[ offset ++ ] = vector.y;
  6356. }
  6357. return this;
  6358. },
  6359. copyVector3sArray: function ( vectors ) {
  6360. var array = this.array, offset = 0;
  6361. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  6362. var vector = vectors[ i ];
  6363. if ( vector === undefined ) {
  6364. console.warn( 'THREE.BufferAttribute.copyVector3sArray(): vector is undefined', i );
  6365. vector = new Vector3();
  6366. }
  6367. array[ offset ++ ] = vector.x;
  6368. array[ offset ++ ] = vector.y;
  6369. array[ offset ++ ] = vector.z;
  6370. }
  6371. return this;
  6372. },
  6373. copyVector4sArray: function ( vectors ) {
  6374. var array = this.array, offset = 0;
  6375. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  6376. var vector = vectors[ i ];
  6377. if ( vector === undefined ) {
  6378. console.warn( 'THREE.BufferAttribute.copyVector4sArray(): vector is undefined', i );
  6379. vector = new Vector4();
  6380. }
  6381. array[ offset ++ ] = vector.x;
  6382. array[ offset ++ ] = vector.y;
  6383. array[ offset ++ ] = vector.z;
  6384. array[ offset ++ ] = vector.w;
  6385. }
  6386. return this;
  6387. },
  6388. set: function ( value, offset ) {
  6389. if ( offset === undefined ) offset = 0;
  6390. this.array.set( value, offset );
  6391. return this;
  6392. },
  6393. getX: function ( index ) {
  6394. return this.array[ index * this.itemSize ];
  6395. },
  6396. setX: function ( index, x ) {
  6397. this.array[ index * this.itemSize ] = x;
  6398. return this;
  6399. },
  6400. getY: function ( index ) {
  6401. return this.array[ index * this.itemSize + 1 ];
  6402. },
  6403. setY: function ( index, y ) {
  6404. this.array[ index * this.itemSize + 1 ] = y;
  6405. return this;
  6406. },
  6407. getZ: function ( index ) {
  6408. return this.array[ index * this.itemSize + 2 ];
  6409. },
  6410. setZ: function ( index, z ) {
  6411. this.array[ index * this.itemSize + 2 ] = z;
  6412. return this;
  6413. },
  6414. getW: function ( index ) {
  6415. return this.array[ index * this.itemSize + 3 ];
  6416. },
  6417. setW: function ( index, w ) {
  6418. this.array[ index * this.itemSize + 3 ] = w;
  6419. return this;
  6420. },
  6421. setXY: function ( index, x, y ) {
  6422. index *= this.itemSize;
  6423. this.array[ index + 0 ] = x;
  6424. this.array[ index + 1 ] = y;
  6425. return this;
  6426. },
  6427. setXYZ: function ( index, x, y, z ) {
  6428. index *= this.itemSize;
  6429. this.array[ index + 0 ] = x;
  6430. this.array[ index + 1 ] = y;
  6431. this.array[ index + 2 ] = z;
  6432. return this;
  6433. },
  6434. setXYZW: function ( index, x, y, z, w ) {
  6435. index *= this.itemSize;
  6436. this.array[ index + 0 ] = x;
  6437. this.array[ index + 1 ] = y;
  6438. this.array[ index + 2 ] = z;
  6439. this.array[ index + 3 ] = w;
  6440. return this;
  6441. },
  6442. onUpload: function ( callback ) {
  6443. this.onUploadCallback = callback;
  6444. return this;
  6445. },
  6446. clone: function () {
  6447. return new this.constructor( this.array, this.itemSize ).copy( this );
  6448. },
  6449. toJSON: function () {
  6450. return {
  6451. itemSize: this.itemSize,
  6452. type: this.array.constructor.name,
  6453. array: Array.prototype.slice.call( this.array ),
  6454. normalized: this.normalized
  6455. };
  6456. }
  6457. } );
  6458. //
  6459. function Int8BufferAttribute( array, itemSize, normalized ) {
  6460. BufferAttribute.call( this, new Int8Array( array ), itemSize, normalized );
  6461. }
  6462. Int8BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  6463. Int8BufferAttribute.prototype.constructor = Int8BufferAttribute;
  6464. function Uint8BufferAttribute( array, itemSize, normalized ) {
  6465. BufferAttribute.call( this, new Uint8Array( array ), itemSize, normalized );
  6466. }
  6467. Uint8BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  6468. Uint8BufferAttribute.prototype.constructor = Uint8BufferAttribute;
  6469. function Uint8ClampedBufferAttribute( array, itemSize, normalized ) {
  6470. BufferAttribute.call( this, new Uint8ClampedArray( array ), itemSize, normalized );
  6471. }
  6472. Uint8ClampedBufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  6473. Uint8ClampedBufferAttribute.prototype.constructor = Uint8ClampedBufferAttribute;
  6474. function Int16BufferAttribute( array, itemSize, normalized ) {
  6475. BufferAttribute.call( this, new Int16Array( array ), itemSize, normalized );
  6476. }
  6477. Int16BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  6478. Int16BufferAttribute.prototype.constructor = Int16BufferAttribute;
  6479. function Uint16BufferAttribute( array, itemSize, normalized ) {
  6480. BufferAttribute.call( this, new Uint16Array( array ), itemSize, normalized );
  6481. }
  6482. Uint16BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  6483. Uint16BufferAttribute.prototype.constructor = Uint16BufferAttribute;
  6484. function Int32BufferAttribute( array, itemSize, normalized ) {
  6485. BufferAttribute.call( this, new Int32Array( array ), itemSize, normalized );
  6486. }
  6487. Int32BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  6488. Int32BufferAttribute.prototype.constructor = Int32BufferAttribute;
  6489. function Uint32BufferAttribute( array, itemSize, normalized ) {
  6490. BufferAttribute.call( this, new Uint32Array( array ), itemSize, normalized );
  6491. }
  6492. Uint32BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  6493. Uint32BufferAttribute.prototype.constructor = Uint32BufferAttribute;
  6494. function Float32BufferAttribute( array, itemSize, normalized ) {
  6495. BufferAttribute.call( this, new Float32Array( array ), itemSize, normalized );
  6496. }
  6497. Float32BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  6498. Float32BufferAttribute.prototype.constructor = Float32BufferAttribute;
  6499. function Float64BufferAttribute( array, itemSize, normalized ) {
  6500. BufferAttribute.call( this, new Float64Array( array ), itemSize, normalized );
  6501. }
  6502. Float64BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  6503. Float64BufferAttribute.prototype.constructor = Float64BufferAttribute;
  6504. /**
  6505. * @author mrdoob / http://mrdoob.com/
  6506. */
  6507. function DirectGeometry() {
  6508. this.vertices = [];
  6509. this.normals = [];
  6510. this.colors = [];
  6511. this.uvs = [];
  6512. this.uvs2 = [];
  6513. this.groups = [];
  6514. this.morphTargets = {};
  6515. this.skinWeights = [];
  6516. this.skinIndices = [];
  6517. // this.lineDistances = [];
  6518. this.boundingBox = null;
  6519. this.boundingSphere = null;
  6520. // update flags
  6521. this.verticesNeedUpdate = false;
  6522. this.normalsNeedUpdate = false;
  6523. this.colorsNeedUpdate = false;
  6524. this.uvsNeedUpdate = false;
  6525. this.groupsNeedUpdate = false;
  6526. }
  6527. Object.assign( DirectGeometry.prototype, {
  6528. computeGroups: function ( geometry ) {
  6529. var group;
  6530. var groups = [];
  6531. var materialIndex = undefined;
  6532. var faces = geometry.faces;
  6533. for ( var i = 0; i < faces.length; i ++ ) {
  6534. var face = faces[ i ];
  6535. // materials
  6536. if ( face.materialIndex !== materialIndex ) {
  6537. materialIndex = face.materialIndex;
  6538. if ( group !== undefined ) {
  6539. group.count = ( i * 3 ) - group.start;
  6540. groups.push( group );
  6541. }
  6542. group = {
  6543. start: i * 3,
  6544. materialIndex: materialIndex
  6545. };
  6546. }
  6547. }
  6548. if ( group !== undefined ) {
  6549. group.count = ( i * 3 ) - group.start;
  6550. groups.push( group );
  6551. }
  6552. this.groups = groups;
  6553. },
  6554. fromGeometry: function ( geometry ) {
  6555. var faces = geometry.faces;
  6556. var vertices = geometry.vertices;
  6557. var faceVertexUvs = geometry.faceVertexUvs;
  6558. var hasFaceVertexUv = faceVertexUvs[ 0 ] && faceVertexUvs[ 0 ].length > 0;
  6559. var hasFaceVertexUv2 = faceVertexUvs[ 1 ] && faceVertexUvs[ 1 ].length > 0;
  6560. // morphs
  6561. var morphTargets = geometry.morphTargets;
  6562. var morphTargetsLength = morphTargets.length;
  6563. var morphTargetsPosition;
  6564. if ( morphTargetsLength > 0 ) {
  6565. morphTargetsPosition = [];
  6566. for ( var i = 0; i < morphTargetsLength; i ++ ) {
  6567. morphTargetsPosition[ i ] = {
  6568. name: morphTargets[ i ].name,
  6569. data: []
  6570. };
  6571. }
  6572. this.morphTargets.position = morphTargetsPosition;
  6573. }
  6574. var morphNormals = geometry.morphNormals;
  6575. var morphNormalsLength = morphNormals.length;
  6576. var morphTargetsNormal;
  6577. if ( morphNormalsLength > 0 ) {
  6578. morphTargetsNormal = [];
  6579. for ( var i = 0; i < morphNormalsLength; i ++ ) {
  6580. morphTargetsNormal[ i ] = {
  6581. name: morphNormals[ i ].name,
  6582. data: []
  6583. };
  6584. }
  6585. this.morphTargets.normal = morphTargetsNormal;
  6586. }
  6587. // skins
  6588. var skinIndices = geometry.skinIndices;
  6589. var skinWeights = geometry.skinWeights;
  6590. var hasSkinIndices = skinIndices.length === vertices.length;
  6591. var hasSkinWeights = skinWeights.length === vertices.length;
  6592. //
  6593. if ( vertices.length > 0 && faces.length === 0 ) {
  6594. console.error( 'THREE.DirectGeometry: Faceless geometries are not supported.' );
  6595. }
  6596. for ( var i = 0; i < faces.length; i ++ ) {
  6597. var face = faces[ i ];
  6598. this.vertices.push( vertices[ face.a ], vertices[ face.b ], vertices[ face.c ] );
  6599. var vertexNormals = face.vertexNormals;
  6600. if ( vertexNormals.length === 3 ) {
  6601. this.normals.push( vertexNormals[ 0 ], vertexNormals[ 1 ], vertexNormals[ 2 ] );
  6602. } else {
  6603. var normal = face.normal;
  6604. this.normals.push( normal, normal, normal );
  6605. }
  6606. var vertexColors = face.vertexColors;
  6607. if ( vertexColors.length === 3 ) {
  6608. this.colors.push( vertexColors[ 0 ], vertexColors[ 1 ], vertexColors[ 2 ] );
  6609. } else {
  6610. var color = face.color;
  6611. this.colors.push( color, color, color );
  6612. }
  6613. if ( hasFaceVertexUv === true ) {
  6614. var vertexUvs = faceVertexUvs[ 0 ][ i ];
  6615. if ( vertexUvs !== undefined ) {
  6616. this.uvs.push( vertexUvs[ 0 ], vertexUvs[ 1 ], vertexUvs[ 2 ] );
  6617. } else {
  6618. console.warn( 'THREE.DirectGeometry.fromGeometry(): Undefined vertexUv ', i );
  6619. this.uvs.push( new Vector2(), new Vector2(), new Vector2() );
  6620. }
  6621. }
  6622. if ( hasFaceVertexUv2 === true ) {
  6623. var vertexUvs = faceVertexUvs[ 1 ][ i ];
  6624. if ( vertexUvs !== undefined ) {
  6625. this.uvs2.push( vertexUvs[ 0 ], vertexUvs[ 1 ], vertexUvs[ 2 ] );
  6626. } else {
  6627. console.warn( 'THREE.DirectGeometry.fromGeometry(): Undefined vertexUv2 ', i );
  6628. this.uvs2.push( new Vector2(), new Vector2(), new Vector2() );
  6629. }
  6630. }
  6631. // morphs
  6632. for ( var j = 0; j < morphTargetsLength; j ++ ) {
  6633. var morphTarget = morphTargets[ j ].vertices;
  6634. morphTargetsPosition[ j ].data.push( morphTarget[ face.a ], morphTarget[ face.b ], morphTarget[ face.c ] );
  6635. }
  6636. for ( var j = 0; j < morphNormalsLength; j ++ ) {
  6637. var morphNormal = morphNormals[ j ].vertexNormals[ i ];
  6638. morphTargetsNormal[ j ].data.push( morphNormal.a, morphNormal.b, morphNormal.c );
  6639. }
  6640. // skins
  6641. if ( hasSkinIndices ) {
  6642. this.skinIndices.push( skinIndices[ face.a ], skinIndices[ face.b ], skinIndices[ face.c ] );
  6643. }
  6644. if ( hasSkinWeights ) {
  6645. this.skinWeights.push( skinWeights[ face.a ], skinWeights[ face.b ], skinWeights[ face.c ] );
  6646. }
  6647. }
  6648. this.computeGroups( geometry );
  6649. this.verticesNeedUpdate = geometry.verticesNeedUpdate;
  6650. this.normalsNeedUpdate = geometry.normalsNeedUpdate;
  6651. this.colorsNeedUpdate = geometry.colorsNeedUpdate;
  6652. this.uvsNeedUpdate = geometry.uvsNeedUpdate;
  6653. this.groupsNeedUpdate = geometry.groupsNeedUpdate;
  6654. return this;
  6655. }
  6656. } );
  6657. /**
  6658. * @author mrdoob / http://mrdoob.com/
  6659. */
  6660. function arrayMax( array ) {
  6661. if ( array.length === 0 ) return - Infinity;
  6662. var max = array[ 0 ];
  6663. for ( var i = 1, l = array.length; i < l; ++ i ) {
  6664. if ( array[ i ] > max ) max = array[ i ];
  6665. }
  6666. return max;
  6667. }
  6668. /**
  6669. * @author alteredq / http://alteredqualia.com/
  6670. * @author mrdoob / http://mrdoob.com/
  6671. */
  6672. var bufferGeometryId = 1; // BufferGeometry uses odd numbers as Id
  6673. function BufferGeometry() {
  6674. Object.defineProperty( this, 'id', { value: bufferGeometryId += 2 } );
  6675. this.uuid = _Math.generateUUID();
  6676. this.name = '';
  6677. this.type = 'BufferGeometry';
  6678. this.index = null;
  6679. this.attributes = {};
  6680. this.morphAttributes = {};
  6681. this.groups = [];
  6682. this.boundingBox = null;
  6683. this.boundingSphere = null;
  6684. this.drawRange = { start: 0, count: Infinity };
  6685. this.userData = {};
  6686. }
  6687. BufferGeometry.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  6688. constructor: BufferGeometry,
  6689. isBufferGeometry: true,
  6690. getIndex: function () {
  6691. return this.index;
  6692. },
  6693. setIndex: function ( index ) {
  6694. if ( Array.isArray( index ) ) {
  6695. this.index = new ( arrayMax( index ) > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute )( index, 1 );
  6696. } else {
  6697. this.index = index;
  6698. }
  6699. },
  6700. addAttribute: function ( name, attribute ) {
  6701. if ( ! ( attribute && attribute.isBufferAttribute ) && ! ( attribute && attribute.isInterleavedBufferAttribute ) ) {
  6702. console.warn( 'THREE.BufferGeometry: .addAttribute() now expects ( name, attribute ).' );
  6703. return this.addAttribute( name, new BufferAttribute( arguments[ 1 ], arguments[ 2 ] ) );
  6704. }
  6705. if ( name === 'index' ) {
  6706. console.warn( 'THREE.BufferGeometry.addAttribute: Use .setIndex() for index attribute.' );
  6707. this.setIndex( attribute );
  6708. return this;
  6709. }
  6710. this.attributes[ name ] = attribute;
  6711. return this;
  6712. },
  6713. getAttribute: function ( name ) {
  6714. return this.attributes[ name ];
  6715. },
  6716. removeAttribute: function ( name ) {
  6717. delete this.attributes[ name ];
  6718. return this;
  6719. },
  6720. addGroup: function ( start, count, materialIndex ) {
  6721. this.groups.push( {
  6722. start: start,
  6723. count: count,
  6724. materialIndex: materialIndex !== undefined ? materialIndex : 0
  6725. } );
  6726. },
  6727. clearGroups: function () {
  6728. this.groups = [];
  6729. },
  6730. setDrawRange: function ( start, count ) {
  6731. this.drawRange.start = start;
  6732. this.drawRange.count = count;
  6733. },
  6734. applyMatrix: function ( matrix ) {
  6735. var position = this.attributes.position;
  6736. if ( position !== undefined ) {
  6737. matrix.applyToBufferAttribute( position );
  6738. position.needsUpdate = true;
  6739. }
  6740. var normal = this.attributes.normal;
  6741. if ( normal !== undefined ) {
  6742. var normalMatrix = new Matrix3().getNormalMatrix( matrix );
  6743. normalMatrix.applyToBufferAttribute( normal );
  6744. normal.needsUpdate = true;
  6745. }
  6746. var tangent = this.attributes.tangent;
  6747. if ( tangent !== undefined ) {
  6748. var normalMatrix = new Matrix3().getNormalMatrix( matrix );
  6749. // Tangent is vec4, but the '.w' component is a sign value (+1/-1).
  6750. normalMatrix.applyToBufferAttribute( tangent );
  6751. tangent.needsUpdate = true;
  6752. }
  6753. if ( this.boundingBox !== null ) {
  6754. this.computeBoundingBox();
  6755. }
  6756. if ( this.boundingSphere !== null ) {
  6757. this.computeBoundingSphere();
  6758. }
  6759. return this;
  6760. },
  6761. rotateX: function () {
  6762. // rotate geometry around world x-axis
  6763. var m1 = new Matrix4();
  6764. return function rotateX( angle ) {
  6765. m1.makeRotationX( angle );
  6766. this.applyMatrix( m1 );
  6767. return this;
  6768. };
  6769. }(),
  6770. rotateY: function () {
  6771. // rotate geometry around world y-axis
  6772. var m1 = new Matrix4();
  6773. return function rotateY( angle ) {
  6774. m1.makeRotationY( angle );
  6775. this.applyMatrix( m1 );
  6776. return this;
  6777. };
  6778. }(),
  6779. rotateZ: function () {
  6780. // rotate geometry around world z-axis
  6781. var m1 = new Matrix4();
  6782. return function rotateZ( angle ) {
  6783. m1.makeRotationZ( angle );
  6784. this.applyMatrix( m1 );
  6785. return this;
  6786. };
  6787. }(),
  6788. translate: function () {
  6789. // translate geometry
  6790. var m1 = new Matrix4();
  6791. return function translate( x, y, z ) {
  6792. m1.makeTranslation( x, y, z );
  6793. this.applyMatrix( m1 );
  6794. return this;
  6795. };
  6796. }(),
  6797. scale: function () {
  6798. // scale geometry
  6799. var m1 = new Matrix4();
  6800. return function scale( x, y, z ) {
  6801. m1.makeScale( x, y, z );
  6802. this.applyMatrix( m1 );
  6803. return this;
  6804. };
  6805. }(),
  6806. lookAt: function () {
  6807. var obj = new Object3D();
  6808. return function lookAt( vector ) {
  6809. obj.lookAt( vector );
  6810. obj.updateMatrix();
  6811. this.applyMatrix( obj.matrix );
  6812. };
  6813. }(),
  6814. center: function () {
  6815. var offset = new Vector3();
  6816. return function center() {
  6817. this.computeBoundingBox();
  6818. this.boundingBox.getCenter( offset ).negate();
  6819. this.translate( offset.x, offset.y, offset.z );
  6820. return this;
  6821. };
  6822. }(),
  6823. setFromObject: function ( object ) {
  6824. // console.log( 'THREE.BufferGeometry.setFromObject(). Converting', object, this );
  6825. var geometry = object.geometry;
  6826. if ( object.isPoints || object.isLine ) {
  6827. var positions = new Float32BufferAttribute( geometry.vertices.length * 3, 3 );
  6828. var colors = new Float32BufferAttribute( geometry.colors.length * 3, 3 );
  6829. this.addAttribute( 'position', positions.copyVector3sArray( geometry.vertices ) );
  6830. this.addAttribute( 'color', colors.copyColorsArray( geometry.colors ) );
  6831. if ( geometry.lineDistances && geometry.lineDistances.length === geometry.vertices.length ) {
  6832. var lineDistances = new Float32BufferAttribute( geometry.lineDistances.length, 1 );
  6833. this.addAttribute( 'lineDistance', lineDistances.copyArray( geometry.lineDistances ) );
  6834. }
  6835. if ( geometry.boundingSphere !== null ) {
  6836. this.boundingSphere = geometry.boundingSphere.clone();
  6837. }
  6838. if ( geometry.boundingBox !== null ) {
  6839. this.boundingBox = geometry.boundingBox.clone();
  6840. }
  6841. } else if ( object.isMesh ) {
  6842. if ( geometry && geometry.isGeometry ) {
  6843. this.fromGeometry( geometry );
  6844. }
  6845. }
  6846. return this;
  6847. },
  6848. setFromPoints: function ( points ) {
  6849. var position = [];
  6850. for ( var i = 0, l = points.length; i < l; i ++ ) {
  6851. var point = points[ i ];
  6852. position.push( point.x, point.y, point.z || 0 );
  6853. }
  6854. this.addAttribute( 'position', new Float32BufferAttribute( position, 3 ) );
  6855. return this;
  6856. },
  6857. updateFromObject: function ( object ) {
  6858. var geometry = object.geometry;
  6859. if ( object.isMesh ) {
  6860. var direct = geometry.__directGeometry;
  6861. if ( geometry.elementsNeedUpdate === true ) {
  6862. direct = undefined;
  6863. geometry.elementsNeedUpdate = false;
  6864. }
  6865. if ( direct === undefined ) {
  6866. return this.fromGeometry( geometry );
  6867. }
  6868. direct.verticesNeedUpdate = geometry.verticesNeedUpdate;
  6869. direct.normalsNeedUpdate = geometry.normalsNeedUpdate;
  6870. direct.colorsNeedUpdate = geometry.colorsNeedUpdate;
  6871. direct.uvsNeedUpdate = geometry.uvsNeedUpdate;
  6872. direct.groupsNeedUpdate = geometry.groupsNeedUpdate;
  6873. geometry.verticesNeedUpdate = false;
  6874. geometry.normalsNeedUpdate = false;
  6875. geometry.colorsNeedUpdate = false;
  6876. geometry.uvsNeedUpdate = false;
  6877. geometry.groupsNeedUpdate = false;
  6878. geometry = direct;
  6879. }
  6880. var attribute;
  6881. if ( geometry.verticesNeedUpdate === true ) {
  6882. attribute = this.attributes.position;
  6883. if ( attribute !== undefined ) {
  6884. attribute.copyVector3sArray( geometry.vertices );
  6885. attribute.needsUpdate = true;
  6886. }
  6887. geometry.verticesNeedUpdate = false;
  6888. }
  6889. if ( geometry.normalsNeedUpdate === true ) {
  6890. attribute = this.attributes.normal;
  6891. if ( attribute !== undefined ) {
  6892. attribute.copyVector3sArray( geometry.normals );
  6893. attribute.needsUpdate = true;
  6894. }
  6895. geometry.normalsNeedUpdate = false;
  6896. }
  6897. if ( geometry.colorsNeedUpdate === true ) {
  6898. attribute = this.attributes.color;
  6899. if ( attribute !== undefined ) {
  6900. attribute.copyColorsArray( geometry.colors );
  6901. attribute.needsUpdate = true;
  6902. }
  6903. geometry.colorsNeedUpdate = false;
  6904. }
  6905. if ( geometry.uvsNeedUpdate ) {
  6906. attribute = this.attributes.uv;
  6907. if ( attribute !== undefined ) {
  6908. attribute.copyVector2sArray( geometry.uvs );
  6909. attribute.needsUpdate = true;
  6910. }
  6911. geometry.uvsNeedUpdate = false;
  6912. }
  6913. if ( geometry.lineDistancesNeedUpdate ) {
  6914. attribute = this.attributes.lineDistance;
  6915. if ( attribute !== undefined ) {
  6916. attribute.copyArray( geometry.lineDistances );
  6917. attribute.needsUpdate = true;
  6918. }
  6919. geometry.lineDistancesNeedUpdate = false;
  6920. }
  6921. if ( geometry.groupsNeedUpdate ) {
  6922. geometry.computeGroups( object.geometry );
  6923. this.groups = geometry.groups;
  6924. geometry.groupsNeedUpdate = false;
  6925. }
  6926. return this;
  6927. },
  6928. fromGeometry: function ( geometry ) {
  6929. geometry.__directGeometry = new DirectGeometry().fromGeometry( geometry );
  6930. return this.fromDirectGeometry( geometry.__directGeometry );
  6931. },
  6932. fromDirectGeometry: function ( geometry ) {
  6933. var positions = new Float32Array( geometry.vertices.length * 3 );
  6934. this.addAttribute( 'position', new BufferAttribute( positions, 3 ).copyVector3sArray( geometry.vertices ) );
  6935. if ( geometry.normals.length > 0 ) {
  6936. var normals = new Float32Array( geometry.normals.length * 3 );
  6937. this.addAttribute( 'normal', new BufferAttribute( normals, 3 ).copyVector3sArray( geometry.normals ) );
  6938. }
  6939. if ( geometry.colors.length > 0 ) {
  6940. var colors = new Float32Array( geometry.colors.length * 3 );
  6941. this.addAttribute( 'color', new BufferAttribute( colors, 3 ).copyColorsArray( geometry.colors ) );
  6942. }
  6943. if ( geometry.uvs.length > 0 ) {
  6944. var uvs = new Float32Array( geometry.uvs.length * 2 );
  6945. this.addAttribute( 'uv', new BufferAttribute( uvs, 2 ).copyVector2sArray( geometry.uvs ) );
  6946. }
  6947. if ( geometry.uvs2.length > 0 ) {
  6948. var uvs2 = new Float32Array( geometry.uvs2.length * 2 );
  6949. this.addAttribute( 'uv2', new BufferAttribute( uvs2, 2 ).copyVector2sArray( geometry.uvs2 ) );
  6950. }
  6951. // groups
  6952. this.groups = geometry.groups;
  6953. // morphs
  6954. for ( var name in geometry.morphTargets ) {
  6955. var array = [];
  6956. var morphTargets = geometry.morphTargets[ name ];
  6957. for ( var i = 0, l = morphTargets.length; i < l; i ++ ) {
  6958. var morphTarget = morphTargets[ i ];
  6959. var attribute = new Float32BufferAttribute( morphTarget.data.length * 3, 3 );
  6960. attribute.name = morphTarget.name;
  6961. array.push( attribute.copyVector3sArray( morphTarget.data ) );
  6962. }
  6963. this.morphAttributes[ name ] = array;
  6964. }
  6965. // skinning
  6966. if ( geometry.skinIndices.length > 0 ) {
  6967. var skinIndices = new Float32BufferAttribute( geometry.skinIndices.length * 4, 4 );
  6968. this.addAttribute( 'skinIndex', skinIndices.copyVector4sArray( geometry.skinIndices ) );
  6969. }
  6970. if ( geometry.skinWeights.length > 0 ) {
  6971. var skinWeights = new Float32BufferAttribute( geometry.skinWeights.length * 4, 4 );
  6972. this.addAttribute( 'skinWeight', skinWeights.copyVector4sArray( geometry.skinWeights ) );
  6973. }
  6974. //
  6975. if ( geometry.boundingSphere !== null ) {
  6976. this.boundingSphere = geometry.boundingSphere.clone();
  6977. }
  6978. if ( geometry.boundingBox !== null ) {
  6979. this.boundingBox = geometry.boundingBox.clone();
  6980. }
  6981. return this;
  6982. },
  6983. computeBoundingBox: function () {
  6984. var box = new Box3();
  6985. return function computeBoundingBox() {
  6986. if ( this.boundingBox === null ) {
  6987. this.boundingBox = new Box3();
  6988. }
  6989. var position = this.attributes.position;
  6990. var morphAttributesPosition = this.morphAttributes.position;
  6991. if ( position !== undefined ) {
  6992. this.boundingBox.setFromBufferAttribute( position );
  6993. // process morph attributes if present
  6994. if ( morphAttributesPosition ) {
  6995. for ( var i = 0, il = morphAttributesPosition.length; i < il; i ++ ) {
  6996. var morphAttribute = morphAttributesPosition[ i ];
  6997. box.setFromBufferAttribute( morphAttribute );
  6998. this.boundingBox.expandByPoint( box.min );
  6999. this.boundingBox.expandByPoint( box.max );
  7000. }
  7001. }
  7002. } else {
  7003. this.boundingBox.makeEmpty();
  7004. }
  7005. if ( isNaN( this.boundingBox.min.x ) || isNaN( this.boundingBox.min.y ) || isNaN( this.boundingBox.min.z ) ) {
  7006. console.error( 'THREE.BufferGeometry.computeBoundingBox: Computed min/max have NaN values. The "position" attribute is likely to have NaN values.', this );
  7007. }
  7008. };
  7009. }(),
  7010. computeBoundingSphere: function () {
  7011. var box = new Box3();
  7012. var boxMorphTargets = new Box3();
  7013. var vector = new Vector3();
  7014. return function computeBoundingSphere() {
  7015. if ( this.boundingSphere === null ) {
  7016. this.boundingSphere = new Sphere();
  7017. }
  7018. var position = this.attributes.position;
  7019. var morphAttributesPosition = this.morphAttributes.position;
  7020. if ( position ) {
  7021. // first, find the center of the bounding sphere
  7022. var center = this.boundingSphere.center;
  7023. box.setFromBufferAttribute( position );
  7024. // process morph attributes if present
  7025. if ( morphAttributesPosition ) {
  7026. for ( var i = 0, il = morphAttributesPosition.length; i < il; i ++ ) {
  7027. var morphAttribute = morphAttributesPosition[ i ];
  7028. boxMorphTargets.setFromBufferAttribute( morphAttribute );
  7029. box.expandByPoint( boxMorphTargets.min );
  7030. box.expandByPoint( boxMorphTargets.max );
  7031. }
  7032. }
  7033. box.getCenter( center );
  7034. // second, try to find a boundingSphere with a radius smaller than the
  7035. // boundingSphere of the boundingBox: sqrt(3) smaller in the best case
  7036. var maxRadiusSq = 0;
  7037. for ( var i = 0, il = position.count; i < il; i ++ ) {
  7038. vector.fromBufferAttribute( position, i );
  7039. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( vector ) );
  7040. }
  7041. // process morph attributes if present
  7042. if ( morphAttributesPosition ) {
  7043. for ( var i = 0, il = morphAttributesPosition.length; i < il; i ++ ) {
  7044. var morphAttribute = morphAttributesPosition[ i ];
  7045. for ( var j = 0, jl = morphAttribute.count; j < jl; j ++ ) {
  7046. vector.fromBufferAttribute( morphAttribute, j );
  7047. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( vector ) );
  7048. }
  7049. }
  7050. }
  7051. this.boundingSphere.radius = Math.sqrt( maxRadiusSq );
  7052. if ( isNaN( this.boundingSphere.radius ) ) {
  7053. console.error( 'THREE.BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.', this );
  7054. }
  7055. }
  7056. };
  7057. }(),
  7058. computeFaceNormals: function () {
  7059. // backwards compatibility
  7060. },
  7061. computeVertexNormals: function () {
  7062. var index = this.index;
  7063. var attributes = this.attributes;
  7064. if ( attributes.position ) {
  7065. var positions = attributes.position.array;
  7066. if ( attributes.normal === undefined ) {
  7067. this.addAttribute( 'normal', new BufferAttribute( new Float32Array( positions.length ), 3 ) );
  7068. } else {
  7069. // reset existing normals to zero
  7070. var array = attributes.normal.array;
  7071. for ( var i = 0, il = array.length; i < il; i ++ ) {
  7072. array[ i ] = 0;
  7073. }
  7074. }
  7075. var normals = attributes.normal.array;
  7076. var vA, vB, vC;
  7077. var pA = new Vector3(), pB = new Vector3(), pC = new Vector3();
  7078. var cb = new Vector3(), ab = new Vector3();
  7079. // indexed elements
  7080. if ( index ) {
  7081. var indices = index.array;
  7082. for ( var i = 0, il = index.count; i < il; i += 3 ) {
  7083. vA = indices[ i + 0 ] * 3;
  7084. vB = indices[ i + 1 ] * 3;
  7085. vC = indices[ i + 2 ] * 3;
  7086. pA.fromArray( positions, vA );
  7087. pB.fromArray( positions, vB );
  7088. pC.fromArray( positions, vC );
  7089. cb.subVectors( pC, pB );
  7090. ab.subVectors( pA, pB );
  7091. cb.cross( ab );
  7092. normals[ vA ] += cb.x;
  7093. normals[ vA + 1 ] += cb.y;
  7094. normals[ vA + 2 ] += cb.z;
  7095. normals[ vB ] += cb.x;
  7096. normals[ vB + 1 ] += cb.y;
  7097. normals[ vB + 2 ] += cb.z;
  7098. normals[ vC ] += cb.x;
  7099. normals[ vC + 1 ] += cb.y;
  7100. normals[ vC + 2 ] += cb.z;
  7101. }
  7102. } else {
  7103. // non-indexed elements (unconnected triangle soup)
  7104. for ( var i = 0, il = positions.length; i < il; i += 9 ) {
  7105. pA.fromArray( positions, i );
  7106. pB.fromArray( positions, i + 3 );
  7107. pC.fromArray( positions, i + 6 );
  7108. cb.subVectors( pC, pB );
  7109. ab.subVectors( pA, pB );
  7110. cb.cross( ab );
  7111. normals[ i ] = cb.x;
  7112. normals[ i + 1 ] = cb.y;
  7113. normals[ i + 2 ] = cb.z;
  7114. normals[ i + 3 ] = cb.x;
  7115. normals[ i + 4 ] = cb.y;
  7116. normals[ i + 5 ] = cb.z;
  7117. normals[ i + 6 ] = cb.x;
  7118. normals[ i + 7 ] = cb.y;
  7119. normals[ i + 8 ] = cb.z;
  7120. }
  7121. }
  7122. this.normalizeNormals();
  7123. attributes.normal.needsUpdate = true;
  7124. }
  7125. },
  7126. merge: function ( geometry, offset ) {
  7127. if ( ! ( geometry && geometry.isBufferGeometry ) ) {
  7128. console.error( 'THREE.BufferGeometry.merge(): geometry not an instance of THREE.BufferGeometry.', geometry );
  7129. return;
  7130. }
  7131. if ( offset === undefined ) {
  7132. offset = 0;
  7133. console.warn(
  7134. 'THREE.BufferGeometry.merge(): Overwriting original geometry, starting at offset=0. '
  7135. + 'Use BufferGeometryUtils.mergeBufferGeometries() for lossless merge.'
  7136. );
  7137. }
  7138. var attributes = this.attributes;
  7139. for ( var key in attributes ) {
  7140. if ( geometry.attributes[ key ] === undefined ) continue;
  7141. var attribute1 = attributes[ key ];
  7142. var attributeArray1 = attribute1.array;
  7143. var attribute2 = geometry.attributes[ key ];
  7144. var attributeArray2 = attribute2.array;
  7145. var attributeOffset = attribute2.itemSize * offset;
  7146. var length = Math.min( attributeArray2.length, attributeArray1.length - attributeOffset );
  7147. for ( var i = 0, j = attributeOffset; i < length; i ++, j ++ ) {
  7148. attributeArray1[ j ] = attributeArray2[ i ];
  7149. }
  7150. }
  7151. return this;
  7152. },
  7153. normalizeNormals: function () {
  7154. var vector = new Vector3();
  7155. return function normalizeNormals() {
  7156. var normals = this.attributes.normal;
  7157. for ( var i = 0, il = normals.count; i < il; i ++ ) {
  7158. vector.x = normals.getX( i );
  7159. vector.y = normals.getY( i );
  7160. vector.z = normals.getZ( i );
  7161. vector.normalize();
  7162. normals.setXYZ( i, vector.x, vector.y, vector.z );
  7163. }
  7164. };
  7165. }(),
  7166. toNonIndexed: function () {
  7167. function convertBufferAttribute( attribute, indices ) {
  7168. var array = attribute.array;
  7169. var itemSize = attribute.itemSize;
  7170. var array2 = new array.constructor( indices.length * itemSize );
  7171. var index = 0, index2 = 0;
  7172. for ( var i = 0, l = indices.length; i < l; i ++ ) {
  7173. index = indices[ i ] * itemSize;
  7174. for ( var j = 0; j < itemSize; j ++ ) {
  7175. array2[ index2 ++ ] = array[ index ++ ];
  7176. }
  7177. }
  7178. return new BufferAttribute( array2, itemSize );
  7179. }
  7180. //
  7181. if ( this.index === null ) {
  7182. console.warn( 'THREE.BufferGeometry.toNonIndexed(): Geometry is already non-indexed.' );
  7183. return this;
  7184. }
  7185. var geometry2 = new BufferGeometry();
  7186. var indices = this.index.array;
  7187. var attributes = this.attributes;
  7188. // attributes
  7189. for ( var name in attributes ) {
  7190. var attribute = attributes[ name ];
  7191. var newAttribute = convertBufferAttribute( attribute, indices );
  7192. geometry2.addAttribute( name, newAttribute );
  7193. }
  7194. // morph attributes
  7195. var morphAttributes = this.morphAttributes;
  7196. for ( name in morphAttributes ) {
  7197. var morphArray = [];
  7198. var morphAttribute = morphAttributes[ name ]; // morphAttribute: array of Float32BufferAttributes
  7199. for ( var i = 0, il = morphAttribute.length; i < il; i ++ ) {
  7200. var attribute = morphAttribute[ i ];
  7201. var newAttribute = convertBufferAttribute( attribute, indices );
  7202. morphArray.push( newAttribute );
  7203. }
  7204. geometry2.morphAttributes[ name ] = morphArray;
  7205. }
  7206. // groups
  7207. var groups = this.groups;
  7208. for ( var i = 0, l = groups.length; i < l; i ++ ) {
  7209. var group = groups[ i ];
  7210. geometry2.addGroup( group.start, group.count, group.materialIndex );
  7211. }
  7212. return geometry2;
  7213. },
  7214. toJSON: function () {
  7215. var data = {
  7216. metadata: {
  7217. version: 4.5,
  7218. type: 'BufferGeometry',
  7219. generator: 'BufferGeometry.toJSON'
  7220. }
  7221. };
  7222. // standard BufferGeometry serialization
  7223. data.uuid = this.uuid;
  7224. data.type = this.type;
  7225. if ( this.name !== '' ) data.name = this.name;
  7226. if ( Object.keys( this.userData ).length > 0 ) data.userData = this.userData;
  7227. if ( this.parameters !== undefined ) {
  7228. var parameters = this.parameters;
  7229. for ( var key in parameters ) {
  7230. if ( parameters[ key ] !== undefined ) data[ key ] = parameters[ key ];
  7231. }
  7232. return data;
  7233. }
  7234. data.data = { attributes: {} };
  7235. var index = this.index;
  7236. if ( index !== null ) {
  7237. data.data.index = {
  7238. type: index.array.constructor.name,
  7239. array: Array.prototype.slice.call( index.array )
  7240. };
  7241. }
  7242. var attributes = this.attributes;
  7243. for ( var key in attributes ) {
  7244. var attribute = attributes[ key ];
  7245. var attributeData = attribute.toJSON();
  7246. if ( attribute.name !== '' ) attributeData.name = attribute.name;
  7247. data.data.attributes[ key ] = attributeData;
  7248. }
  7249. var morphAttributes = {};
  7250. var hasMorphAttributes = false;
  7251. for ( var key in this.morphAttributes ) {
  7252. var attributeArray = this.morphAttributes[ key ];
  7253. var array = [];
  7254. for ( var i = 0, il = attributeArray.length; i < il; i ++ ) {
  7255. var attribute = attributeArray[ i ];
  7256. var attributeData = attribute.toJSON();
  7257. if ( attribute.name !== '' ) attributeData.name = attribute.name;
  7258. array.push( attributeData );
  7259. }
  7260. if ( array.length > 0 ) {
  7261. morphAttributes[ key ] = array;
  7262. hasMorphAttributes = true;
  7263. }
  7264. }
  7265. if ( hasMorphAttributes ) data.data.morphAttributes = morphAttributes;
  7266. var groups = this.groups;
  7267. if ( groups.length > 0 ) {
  7268. data.data.groups = JSON.parse( JSON.stringify( groups ) );
  7269. }
  7270. var boundingSphere = this.boundingSphere;
  7271. if ( boundingSphere !== null ) {
  7272. data.data.boundingSphere = {
  7273. center: boundingSphere.center.toArray(),
  7274. radius: boundingSphere.radius
  7275. };
  7276. }
  7277. return data;
  7278. },
  7279. clone: function () {
  7280. /*
  7281. // Handle primitives
  7282. var parameters = this.parameters;
  7283. if ( parameters !== undefined ) {
  7284. var values = [];
  7285. for ( var key in parameters ) {
  7286. values.push( parameters[ key ] );
  7287. }
  7288. var geometry = Object.create( this.constructor.prototype );
  7289. this.constructor.apply( geometry, values );
  7290. return geometry;
  7291. }
  7292. return new this.constructor().copy( this );
  7293. */
  7294. return new BufferGeometry().copy( this );
  7295. },
  7296. copy: function ( source ) {
  7297. var name, i, l;
  7298. // reset
  7299. this.index = null;
  7300. this.attributes = {};
  7301. this.morphAttributes = {};
  7302. this.groups = [];
  7303. this.boundingBox = null;
  7304. this.boundingSphere = null;
  7305. // name
  7306. this.name = source.name;
  7307. // index
  7308. var index = source.index;
  7309. if ( index !== null ) {
  7310. this.setIndex( index.clone() );
  7311. }
  7312. // attributes
  7313. var attributes = source.attributes;
  7314. for ( name in attributes ) {
  7315. var attribute = attributes[ name ];
  7316. this.addAttribute( name, attribute.clone() );
  7317. }
  7318. // morph attributes
  7319. var morphAttributes = source.morphAttributes;
  7320. for ( name in morphAttributes ) {
  7321. var array = [];
  7322. var morphAttribute = morphAttributes[ name ]; // morphAttribute: array of Float32BufferAttributes
  7323. for ( i = 0, l = morphAttribute.length; i < l; i ++ ) {
  7324. array.push( morphAttribute[ i ].clone() );
  7325. }
  7326. this.morphAttributes[ name ] = array;
  7327. }
  7328. // groups
  7329. var groups = source.groups;
  7330. for ( i = 0, l = groups.length; i < l; i ++ ) {
  7331. var group = groups[ i ];
  7332. this.addGroup( group.start, group.count, group.materialIndex );
  7333. }
  7334. // bounding box
  7335. var boundingBox = source.boundingBox;
  7336. if ( boundingBox !== null ) {
  7337. this.boundingBox = boundingBox.clone();
  7338. }
  7339. // bounding sphere
  7340. var boundingSphere = source.boundingSphere;
  7341. if ( boundingSphere !== null ) {
  7342. this.boundingSphere = boundingSphere.clone();
  7343. }
  7344. // draw range
  7345. this.drawRange.start = source.drawRange.start;
  7346. this.drawRange.count = source.drawRange.count;
  7347. // user data
  7348. this.userData = source.userData;
  7349. return this;
  7350. },
  7351. dispose: function () {
  7352. this.dispatchEvent( { type: 'dispose' } );
  7353. }
  7354. } );
  7355. /**
  7356. * @author mrdoob / http://mrdoob.com/
  7357. * @author Mugen87 / https://github.com/Mugen87
  7358. */
  7359. // BoxGeometry
  7360. function BoxGeometry( width, height, depth, widthSegments, heightSegments, depthSegments ) {
  7361. Geometry.call( this );
  7362. this.type = 'BoxGeometry';
  7363. this.parameters = {
  7364. width: width,
  7365. height: height,
  7366. depth: depth,
  7367. widthSegments: widthSegments,
  7368. heightSegments: heightSegments,
  7369. depthSegments: depthSegments
  7370. };
  7371. this.fromBufferGeometry( new BoxBufferGeometry( width, height, depth, widthSegments, heightSegments, depthSegments ) );
  7372. this.mergeVertices();
  7373. }
  7374. BoxGeometry.prototype = Object.create( Geometry.prototype );
  7375. BoxGeometry.prototype.constructor = BoxGeometry;
  7376. // BoxBufferGeometry
  7377. function BoxBufferGeometry( width, height, depth, widthSegments, heightSegments, depthSegments ) {
  7378. BufferGeometry.call( this );
  7379. this.type = 'BoxBufferGeometry';
  7380. this.parameters = {
  7381. width: width,
  7382. height: height,
  7383. depth: depth,
  7384. widthSegments: widthSegments,
  7385. heightSegments: heightSegments,
  7386. depthSegments: depthSegments
  7387. };
  7388. var scope = this;
  7389. width = width || 1;
  7390. height = height || 1;
  7391. depth = depth || 1;
  7392. // segments
  7393. widthSegments = Math.floor( widthSegments ) || 1;
  7394. heightSegments = Math.floor( heightSegments ) || 1;
  7395. depthSegments = Math.floor( depthSegments ) || 1;
  7396. // buffers
  7397. var indices = [];
  7398. var vertices = [];
  7399. var normals = [];
  7400. var uvs = [];
  7401. // helper variables
  7402. var numberOfVertices = 0;
  7403. var groupStart = 0;
  7404. // build each side of the box geometry
  7405. buildPlane( 'z', 'y', 'x', - 1, - 1, depth, height, width, depthSegments, heightSegments, 0 ); // px
  7406. buildPlane( 'z', 'y', 'x', 1, - 1, depth, height, - width, depthSegments, heightSegments, 1 ); // nx
  7407. buildPlane( 'x', 'z', 'y', 1, 1, width, depth, height, widthSegments, depthSegments, 2 ); // py
  7408. buildPlane( 'x', 'z', 'y', 1, - 1, width, depth, - height, widthSegments, depthSegments, 3 ); // ny
  7409. buildPlane( 'x', 'y', 'z', 1, - 1, width, height, depth, widthSegments, heightSegments, 4 ); // pz
  7410. buildPlane( 'x', 'y', 'z', - 1, - 1, width, height, - depth, widthSegments, heightSegments, 5 ); // nz
  7411. // build geometry
  7412. this.setIndex( indices );
  7413. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  7414. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  7415. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  7416. function buildPlane( u, v, w, udir, vdir, width, height, depth, gridX, gridY, materialIndex ) {
  7417. var segmentWidth = width / gridX;
  7418. var segmentHeight = height / gridY;
  7419. var widthHalf = width / 2;
  7420. var heightHalf = height / 2;
  7421. var depthHalf = depth / 2;
  7422. var gridX1 = gridX + 1;
  7423. var gridY1 = gridY + 1;
  7424. var vertexCounter = 0;
  7425. var groupCount = 0;
  7426. var ix, iy;
  7427. var vector = new Vector3();
  7428. // generate vertices, normals and uvs
  7429. for ( iy = 0; iy < gridY1; iy ++ ) {
  7430. var y = iy * segmentHeight - heightHalf;
  7431. for ( ix = 0; ix < gridX1; ix ++ ) {
  7432. var x = ix * segmentWidth - widthHalf;
  7433. // set values to correct vector component
  7434. vector[ u ] = x * udir;
  7435. vector[ v ] = y * vdir;
  7436. vector[ w ] = depthHalf;
  7437. // now apply vector to vertex buffer
  7438. vertices.push( vector.x, vector.y, vector.z );
  7439. // set values to correct vector component
  7440. vector[ u ] = 0;
  7441. vector[ v ] = 0;
  7442. vector[ w ] = depth > 0 ? 1 : - 1;
  7443. // now apply vector to normal buffer
  7444. normals.push( vector.x, vector.y, vector.z );
  7445. // uvs
  7446. uvs.push( ix / gridX );
  7447. uvs.push( 1 - ( iy / gridY ) );
  7448. // counters
  7449. vertexCounter += 1;
  7450. }
  7451. }
  7452. // indices
  7453. // 1. you need three indices to draw a single face
  7454. // 2. a single segment consists of two faces
  7455. // 3. so we need to generate six (2*3) indices per segment
  7456. for ( iy = 0; iy < gridY; iy ++ ) {
  7457. for ( ix = 0; ix < gridX; ix ++ ) {
  7458. var a = numberOfVertices + ix + gridX1 * iy;
  7459. var b = numberOfVertices + ix + gridX1 * ( iy + 1 );
  7460. var c = numberOfVertices + ( ix + 1 ) + gridX1 * ( iy + 1 );
  7461. var d = numberOfVertices + ( ix + 1 ) + gridX1 * iy;
  7462. // faces
  7463. indices.push( a, b, d );
  7464. indices.push( b, c, d );
  7465. // increase counter
  7466. groupCount += 6;
  7467. }
  7468. }
  7469. // add a group to the geometry. this will ensure multi material support
  7470. scope.addGroup( groupStart, groupCount, materialIndex );
  7471. // calculate new start value for groups
  7472. groupStart += groupCount;
  7473. // update total number of vertices
  7474. numberOfVertices += vertexCounter;
  7475. }
  7476. }
  7477. BoxBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  7478. BoxBufferGeometry.prototype.constructor = BoxBufferGeometry;
  7479. /**
  7480. * @author mrdoob / http://mrdoob.com/
  7481. * @author Mugen87 / https://github.com/Mugen87
  7482. */
  7483. // PlaneGeometry
  7484. function PlaneGeometry( width, height, widthSegments, heightSegments ) {
  7485. Geometry.call( this );
  7486. this.type = 'PlaneGeometry';
  7487. this.parameters = {
  7488. width: width,
  7489. height: height,
  7490. widthSegments: widthSegments,
  7491. heightSegments: heightSegments
  7492. };
  7493. this.fromBufferGeometry( new PlaneBufferGeometry( width, height, widthSegments, heightSegments ) );
  7494. this.mergeVertices();
  7495. }
  7496. PlaneGeometry.prototype = Object.create( Geometry.prototype );
  7497. PlaneGeometry.prototype.constructor = PlaneGeometry;
  7498. // PlaneBufferGeometry
  7499. function PlaneBufferGeometry( width, height, widthSegments, heightSegments ) {
  7500. BufferGeometry.call( this );
  7501. this.type = 'PlaneBufferGeometry';
  7502. this.parameters = {
  7503. width: width,
  7504. height: height,
  7505. widthSegments: widthSegments,
  7506. heightSegments: heightSegments
  7507. };
  7508. width = width || 1;
  7509. height = height || 1;
  7510. var width_half = width / 2;
  7511. var height_half = height / 2;
  7512. var gridX = Math.floor( widthSegments ) || 1;
  7513. var gridY = Math.floor( heightSegments ) || 1;
  7514. var gridX1 = gridX + 1;
  7515. var gridY1 = gridY + 1;
  7516. var segment_width = width / gridX;
  7517. var segment_height = height / gridY;
  7518. var ix, iy;
  7519. // buffers
  7520. var indices = [];
  7521. var vertices = [];
  7522. var normals = [];
  7523. var uvs = [];
  7524. // generate vertices, normals and uvs
  7525. for ( iy = 0; iy < gridY1; iy ++ ) {
  7526. var y = iy * segment_height - height_half;
  7527. for ( ix = 0; ix < gridX1; ix ++ ) {
  7528. var x = ix * segment_width - width_half;
  7529. vertices.push( x, - y, 0 );
  7530. normals.push( 0, 0, 1 );
  7531. uvs.push( ix / gridX );
  7532. uvs.push( 1 - ( iy / gridY ) );
  7533. }
  7534. }
  7535. // indices
  7536. for ( iy = 0; iy < gridY; iy ++ ) {
  7537. for ( ix = 0; ix < gridX; ix ++ ) {
  7538. var a = ix + gridX1 * iy;
  7539. var b = ix + gridX1 * ( iy + 1 );
  7540. var c = ( ix + 1 ) + gridX1 * ( iy + 1 );
  7541. var d = ( ix + 1 ) + gridX1 * iy;
  7542. // faces
  7543. indices.push( a, b, d );
  7544. indices.push( b, c, d );
  7545. }
  7546. }
  7547. // build geometry
  7548. this.setIndex( indices );
  7549. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  7550. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  7551. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  7552. }
  7553. PlaneBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  7554. PlaneBufferGeometry.prototype.constructor = PlaneBufferGeometry;
  7555. /**
  7556. * @author mrdoob / http://mrdoob.com/
  7557. * @author alteredq / http://alteredqualia.com/
  7558. */
  7559. var materialId = 0;
  7560. function Material() {
  7561. Object.defineProperty( this, 'id', { value: materialId ++ } );
  7562. this.uuid = _Math.generateUUID();
  7563. this.name = '';
  7564. this.type = 'Material';
  7565. this.fog = true;
  7566. this.lights = true;
  7567. this.blending = NormalBlending;
  7568. this.side = FrontSide;
  7569. this.flatShading = false;
  7570. this.vertexTangents = false;
  7571. this.vertexColors = NoColors; // THREE.NoColors, THREE.VertexColors, THREE.FaceColors
  7572. this.opacity = 1;
  7573. this.transparent = false;
  7574. this.blendSrc = SrcAlphaFactor;
  7575. this.blendDst = OneMinusSrcAlphaFactor;
  7576. this.blendEquation = AddEquation;
  7577. this.blendSrcAlpha = null;
  7578. this.blendDstAlpha = null;
  7579. this.blendEquationAlpha = null;
  7580. this.depthFunc = LessEqualDepth;
  7581. this.depthTest = true;
  7582. this.depthWrite = true;
  7583. this.clippingPlanes = null;
  7584. this.clipIntersection = false;
  7585. this.clipShadows = false;
  7586. this.shadowSide = null;
  7587. this.colorWrite = true;
  7588. this.precision = null; // override the renderer's default precision for this material
  7589. this.polygonOffset = false;
  7590. this.polygonOffsetFactor = 0;
  7591. this.polygonOffsetUnits = 0;
  7592. this.dithering = false;
  7593. this.alphaTest = 0;
  7594. this.premultipliedAlpha = false;
  7595. this.visible = true;
  7596. this.userData = {};
  7597. this.needsUpdate = true;
  7598. }
  7599. Material.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  7600. constructor: Material,
  7601. isMaterial: true,
  7602. onBeforeCompile: function () {},
  7603. setValues: function ( values ) {
  7604. if ( values === undefined ) return;
  7605. for ( var key in values ) {
  7606. var newValue = values[ key ];
  7607. if ( newValue === undefined ) {
  7608. console.warn( "THREE.Material: '" + key + "' parameter is undefined." );
  7609. continue;
  7610. }
  7611. // for backward compatability if shading is set in the constructor
  7612. if ( key === 'shading' ) {
  7613. console.warn( 'THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.' );
  7614. this.flatShading = ( newValue === FlatShading ) ? true : false;
  7615. continue;
  7616. }
  7617. var currentValue = this[ key ];
  7618. if ( currentValue === undefined ) {
  7619. console.warn( "THREE." + this.type + ": '" + key + "' is not a property of this material." );
  7620. continue;
  7621. }
  7622. if ( currentValue && currentValue.isColor ) {
  7623. currentValue.set( newValue );
  7624. } else if ( ( currentValue && currentValue.isVector3 ) && ( newValue && newValue.isVector3 ) ) {
  7625. currentValue.copy( newValue );
  7626. } else {
  7627. this[ key ] = newValue;
  7628. }
  7629. }
  7630. },
  7631. toJSON: function ( meta ) {
  7632. var isRoot = ( meta === undefined || typeof meta === 'string' );
  7633. if ( isRoot ) {
  7634. meta = {
  7635. textures: {},
  7636. images: {}
  7637. };
  7638. }
  7639. var data = {
  7640. metadata: {
  7641. version: 4.5,
  7642. type: 'Material',
  7643. generator: 'Material.toJSON'
  7644. }
  7645. };
  7646. // standard Material serialization
  7647. data.uuid = this.uuid;
  7648. data.type = this.type;
  7649. if ( this.name !== '' ) data.name = this.name;
  7650. if ( this.color && this.color.isColor ) data.color = this.color.getHex();
  7651. if ( this.roughness !== undefined ) data.roughness = this.roughness;
  7652. if ( this.metalness !== undefined ) data.metalness = this.metalness;
  7653. if ( this.emissive && this.emissive.isColor ) data.emissive = this.emissive.getHex();
  7654. if ( this.emissiveIntensity !== 1 ) data.emissiveIntensity = this.emissiveIntensity;
  7655. if ( this.specular && this.specular.isColor ) data.specular = this.specular.getHex();
  7656. if ( this.shininess !== undefined ) data.shininess = this.shininess;
  7657. if ( this.clearCoat !== undefined ) data.clearCoat = this.clearCoat;
  7658. if ( this.clearCoatRoughness !== undefined ) data.clearCoatRoughness = this.clearCoatRoughness;
  7659. if ( this.map && this.map.isTexture ) data.map = this.map.toJSON( meta ).uuid;
  7660. if ( this.matcap && this.matcap.isTexture ) data.matcap = this.matcap.toJSON( meta ).uuid;
  7661. if ( this.alphaMap && this.alphaMap.isTexture ) data.alphaMap = this.alphaMap.toJSON( meta ).uuid;
  7662. if ( this.lightMap && this.lightMap.isTexture ) data.lightMap = this.lightMap.toJSON( meta ).uuid;
  7663. if ( this.aoMap && this.aoMap.isTexture ) {
  7664. data.aoMap = this.aoMap.toJSON( meta ).uuid;
  7665. data.aoMapIntensity = this.aoMapIntensity;
  7666. }
  7667. if ( this.bumpMap && this.bumpMap.isTexture ) {
  7668. data.bumpMap = this.bumpMap.toJSON( meta ).uuid;
  7669. data.bumpScale = this.bumpScale;
  7670. }
  7671. if ( this.normalMap && this.normalMap.isTexture ) {
  7672. data.normalMap = this.normalMap.toJSON( meta ).uuid;
  7673. data.normalMapType = this.normalMapType;
  7674. data.normalScale = this.normalScale.toArray();
  7675. }
  7676. if ( this.displacementMap && this.displacementMap.isTexture ) {
  7677. data.displacementMap = this.displacementMap.toJSON( meta ).uuid;
  7678. data.displacementScale = this.displacementScale;
  7679. data.displacementBias = this.displacementBias;
  7680. }
  7681. if ( this.roughnessMap && this.roughnessMap.isTexture ) data.roughnessMap = this.roughnessMap.toJSON( meta ).uuid;
  7682. if ( this.metalnessMap && this.metalnessMap.isTexture ) data.metalnessMap = this.metalnessMap.toJSON( meta ).uuid;
  7683. if ( this.emissiveMap && this.emissiveMap.isTexture ) data.emissiveMap = this.emissiveMap.toJSON( meta ).uuid;
  7684. if ( this.specularMap && this.specularMap.isTexture ) data.specularMap = this.specularMap.toJSON( meta ).uuid;
  7685. if ( this.envMap && this.envMap.isTexture ) {
  7686. data.envMap = this.envMap.toJSON( meta ).uuid;
  7687. data.reflectivity = this.reflectivity; // Scale behind envMap
  7688. if ( this.combine !== undefined ) data.combine = this.combine;
  7689. if ( this.envMapIntensity !== undefined ) data.envMapIntensity = this.envMapIntensity;
  7690. }
  7691. if ( this.gradientMap && this.gradientMap.isTexture ) {
  7692. data.gradientMap = this.gradientMap.toJSON( meta ).uuid;
  7693. }
  7694. if ( this.size !== undefined ) data.size = this.size;
  7695. if ( this.sizeAttenuation !== undefined ) data.sizeAttenuation = this.sizeAttenuation;
  7696. if ( this.blending !== NormalBlending ) data.blending = this.blending;
  7697. if ( this.flatShading === true ) data.flatShading = this.flatShading;
  7698. if ( this.side !== FrontSide ) data.side = this.side;
  7699. if ( this.vertexColors !== NoColors ) data.vertexColors = this.vertexColors;
  7700. if ( this.opacity < 1 ) data.opacity = this.opacity;
  7701. if ( this.transparent === true ) data.transparent = this.transparent;
  7702. data.depthFunc = this.depthFunc;
  7703. data.depthTest = this.depthTest;
  7704. data.depthWrite = this.depthWrite;
  7705. // rotation (SpriteMaterial)
  7706. if ( this.rotation !== 0 ) data.rotation = this.rotation;
  7707. if ( this.polygonOffset === true ) data.polygonOffset = true;
  7708. if ( this.polygonOffsetFactor !== 0 ) data.polygonOffsetFactor = this.polygonOffsetFactor;
  7709. if ( this.polygonOffsetUnits !== 0 ) data.polygonOffsetUnits = this.polygonOffsetUnits;
  7710. if ( this.linewidth !== 1 ) data.linewidth = this.linewidth;
  7711. if ( this.dashSize !== undefined ) data.dashSize = this.dashSize;
  7712. if ( this.gapSize !== undefined ) data.gapSize = this.gapSize;
  7713. if ( this.scale !== undefined ) data.scale = this.scale;
  7714. if ( this.dithering === true ) data.dithering = true;
  7715. if ( this.alphaTest > 0 ) data.alphaTest = this.alphaTest;
  7716. if ( this.premultipliedAlpha === true ) data.premultipliedAlpha = this.premultipliedAlpha;
  7717. if ( this.wireframe === true ) data.wireframe = this.wireframe;
  7718. if ( this.wireframeLinewidth > 1 ) data.wireframeLinewidth = this.wireframeLinewidth;
  7719. if ( this.wireframeLinecap !== 'round' ) data.wireframeLinecap = this.wireframeLinecap;
  7720. if ( this.wireframeLinejoin !== 'round' ) data.wireframeLinejoin = this.wireframeLinejoin;
  7721. if ( this.morphTargets === true ) data.morphTargets = true;
  7722. if ( this.skinning === true ) data.skinning = true;
  7723. if ( this.visible === false ) data.visible = false;
  7724. if ( JSON.stringify( this.userData ) !== '{}' ) data.userData = this.userData;
  7725. // TODO: Copied from Object3D.toJSON
  7726. function extractFromCache( cache ) {
  7727. var values = [];
  7728. for ( var key in cache ) {
  7729. var data = cache[ key ];
  7730. delete data.metadata;
  7731. values.push( data );
  7732. }
  7733. return values;
  7734. }
  7735. if ( isRoot ) {
  7736. var textures = extractFromCache( meta.textures );
  7737. var images = extractFromCache( meta.images );
  7738. if ( textures.length > 0 ) data.textures = textures;
  7739. if ( images.length > 0 ) data.images = images;
  7740. }
  7741. return data;
  7742. },
  7743. clone: function () {
  7744. return new this.constructor().copy( this );
  7745. },
  7746. copy: function ( source ) {
  7747. this.name = source.name;
  7748. this.fog = source.fog;
  7749. this.lights = source.lights;
  7750. this.blending = source.blending;
  7751. this.side = source.side;
  7752. this.flatShading = source.flatShading;
  7753. this.vertexColors = source.vertexColors;
  7754. this.opacity = source.opacity;
  7755. this.transparent = source.transparent;
  7756. this.blendSrc = source.blendSrc;
  7757. this.blendDst = source.blendDst;
  7758. this.blendEquation = source.blendEquation;
  7759. this.blendSrcAlpha = source.blendSrcAlpha;
  7760. this.blendDstAlpha = source.blendDstAlpha;
  7761. this.blendEquationAlpha = source.blendEquationAlpha;
  7762. this.depthFunc = source.depthFunc;
  7763. this.depthTest = source.depthTest;
  7764. this.depthWrite = source.depthWrite;
  7765. this.colorWrite = source.colorWrite;
  7766. this.precision = source.precision;
  7767. this.polygonOffset = source.polygonOffset;
  7768. this.polygonOffsetFactor = source.polygonOffsetFactor;
  7769. this.polygonOffsetUnits = source.polygonOffsetUnits;
  7770. this.dithering = source.dithering;
  7771. this.alphaTest = source.alphaTest;
  7772. this.premultipliedAlpha = source.premultipliedAlpha;
  7773. this.visible = source.visible;
  7774. this.userData = JSON.parse( JSON.stringify( source.userData ) );
  7775. this.clipShadows = source.clipShadows;
  7776. this.clipIntersection = source.clipIntersection;
  7777. var srcPlanes = source.clippingPlanes,
  7778. dstPlanes = null;
  7779. if ( srcPlanes !== null ) {
  7780. var n = srcPlanes.length;
  7781. dstPlanes = new Array( n );
  7782. for ( var i = 0; i !== n; ++ i )
  7783. dstPlanes[ i ] = srcPlanes[ i ].clone();
  7784. }
  7785. this.clippingPlanes = dstPlanes;
  7786. this.shadowSide = source.shadowSide;
  7787. return this;
  7788. },
  7789. dispose: function () {
  7790. this.dispatchEvent( { type: 'dispose' } );
  7791. }
  7792. } );
  7793. var default_vertex = "void main() {\n\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}";
  7794. var default_fragment = "void main() {\n\tgl_FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );\n}";
  7795. /**
  7796. * @author alteredq / http://alteredqualia.com/
  7797. *
  7798. * parameters = {
  7799. * defines: { "label" : "value" },
  7800. * uniforms: { "parameter1": { value: 1.0 }, "parameter2": { value2: 2 } },
  7801. *
  7802. * fragmentShader: <string>,
  7803. * vertexShader: <string>,
  7804. *
  7805. * wireframe: <boolean>,
  7806. * wireframeLinewidth: <float>,
  7807. *
  7808. * lights: <bool>,
  7809. *
  7810. * skinning: <bool>,
  7811. * morphTargets: <bool>,
  7812. * morphNormals: <bool>
  7813. * }
  7814. */
  7815. function ShaderMaterial( parameters ) {
  7816. Material.call( this );
  7817. this.type = 'ShaderMaterial';
  7818. this.defines = {};
  7819. this.uniforms = {};
  7820. this.vertexShader = default_vertex;
  7821. this.fragmentShader = default_fragment;
  7822. this.linewidth = 1;
  7823. this.wireframe = false;
  7824. this.wireframeLinewidth = 1;
  7825. this.fog = false; // set to use scene fog
  7826. this.lights = false; // set to use scene lights
  7827. this.clipping = false; // set to use user-defined clipping planes
  7828. this.skinning = false; // set to use skinning attribute streams
  7829. this.morphTargets = false; // set to use morph targets
  7830. this.morphNormals = false; // set to use morph normals
  7831. this.extensions = {
  7832. derivatives: false, // set to use derivatives
  7833. fragDepth: false, // set to use fragment depth values
  7834. drawBuffers: false, // set to use draw buffers
  7835. shaderTextureLOD: false // set to use shader texture LOD
  7836. };
  7837. // When rendered geometry doesn't include these attributes but the material does,
  7838. // use these default values in WebGL. This avoids errors when buffer data is missing.
  7839. this.defaultAttributeValues = {
  7840. 'color': [ 1, 1, 1 ],
  7841. 'uv': [ 0, 0 ],
  7842. 'uv2': [ 0, 0 ]
  7843. };
  7844. this.index0AttributeName = undefined;
  7845. this.uniformsNeedUpdate = false;
  7846. if ( parameters !== undefined ) {
  7847. if ( parameters.attributes !== undefined ) {
  7848. console.error( 'THREE.ShaderMaterial: attributes should now be defined in THREE.BufferGeometry instead.' );
  7849. }
  7850. this.setValues( parameters );
  7851. }
  7852. }
  7853. ShaderMaterial.prototype = Object.create( Material.prototype );
  7854. ShaderMaterial.prototype.constructor = ShaderMaterial;
  7855. ShaderMaterial.prototype.isShaderMaterial = true;
  7856. ShaderMaterial.prototype.copy = function ( source ) {
  7857. Material.prototype.copy.call( this, source );
  7858. this.fragmentShader = source.fragmentShader;
  7859. this.vertexShader = source.vertexShader;
  7860. this.uniforms = cloneUniforms( source.uniforms );
  7861. this.defines = Object.assign( {}, source.defines );
  7862. this.wireframe = source.wireframe;
  7863. this.wireframeLinewidth = source.wireframeLinewidth;
  7864. this.lights = source.lights;
  7865. this.clipping = source.clipping;
  7866. this.skinning = source.skinning;
  7867. this.morphTargets = source.morphTargets;
  7868. this.morphNormals = source.morphNormals;
  7869. this.extensions = source.extensions;
  7870. return this;
  7871. };
  7872. ShaderMaterial.prototype.toJSON = function ( meta ) {
  7873. var data = Material.prototype.toJSON.call( this, meta );
  7874. data.uniforms = {};
  7875. for ( var name in this.uniforms ) {
  7876. var uniform = this.uniforms[ name ];
  7877. var value = uniform.value;
  7878. if ( value && value.isTexture ) {
  7879. data.uniforms[ name ] = {
  7880. type: 't',
  7881. value: value.toJSON( meta ).uuid
  7882. };
  7883. } else if ( value && value.isColor ) {
  7884. data.uniforms[ name ] = {
  7885. type: 'c',
  7886. value: value.getHex()
  7887. };
  7888. } else if ( value && value.isVector2 ) {
  7889. data.uniforms[ name ] = {
  7890. type: 'v2',
  7891. value: value.toArray()
  7892. };
  7893. } else if ( value && value.isVector3 ) {
  7894. data.uniforms[ name ] = {
  7895. type: 'v3',
  7896. value: value.toArray()
  7897. };
  7898. } else if ( value && value.isVector4 ) {
  7899. data.uniforms[ name ] = {
  7900. type: 'v4',
  7901. value: value.toArray()
  7902. };
  7903. } else if ( value && value.isMatrix3 ) {
  7904. data.uniforms[ name ] = {
  7905. type: 'm3',
  7906. value: value.toArray()
  7907. };
  7908. } else if ( value && value.isMatrix4 ) {
  7909. data.uniforms[ name ] = {
  7910. type: 'm4',
  7911. value: value.toArray()
  7912. };
  7913. } else {
  7914. data.uniforms[ name ] = {
  7915. value: value
  7916. };
  7917. // note: the array variants v2v, v3v, v4v, m4v and tv are not supported so far
  7918. }
  7919. }
  7920. if ( Object.keys( this.defines ).length > 0 ) data.defines = this.defines;
  7921. data.vertexShader = this.vertexShader;
  7922. data.fragmentShader = this.fragmentShader;
  7923. var extensions = {};
  7924. for ( var key in this.extensions ) {
  7925. if ( this.extensions[ key ] === true ) extensions[ key ] = true;
  7926. }
  7927. if ( Object.keys( extensions ).length > 0 ) data.extensions = extensions;
  7928. return data;
  7929. };
  7930. /**
  7931. * @author bhouston / http://clara.io
  7932. */
  7933. function Ray( origin, direction ) {
  7934. this.origin = ( origin !== undefined ) ? origin : new Vector3();
  7935. this.direction = ( direction !== undefined ) ? direction : new Vector3();
  7936. }
  7937. Object.assign( Ray.prototype, {
  7938. set: function ( origin, direction ) {
  7939. this.origin.copy( origin );
  7940. this.direction.copy( direction );
  7941. return this;
  7942. },
  7943. clone: function () {
  7944. return new this.constructor().copy( this );
  7945. },
  7946. copy: function ( ray ) {
  7947. this.origin.copy( ray.origin );
  7948. this.direction.copy( ray.direction );
  7949. return this;
  7950. },
  7951. at: function ( t, target ) {
  7952. if ( target === undefined ) {
  7953. console.warn( 'THREE.Ray: .at() target is now required' );
  7954. target = new Vector3();
  7955. }
  7956. return target.copy( this.direction ).multiplyScalar( t ).add( this.origin );
  7957. },
  7958. lookAt: function ( v ) {
  7959. this.direction.copy( v ).sub( this.origin ).normalize();
  7960. return this;
  7961. },
  7962. recast: function () {
  7963. var v1 = new Vector3();
  7964. return function recast( t ) {
  7965. this.origin.copy( this.at( t, v1 ) );
  7966. return this;
  7967. };
  7968. }(),
  7969. closestPointToPoint: function ( point, target ) {
  7970. if ( target === undefined ) {
  7971. console.warn( 'THREE.Ray: .closestPointToPoint() target is now required' );
  7972. target = new Vector3();
  7973. }
  7974. target.subVectors( point, this.origin );
  7975. var directionDistance = target.dot( this.direction );
  7976. if ( directionDistance < 0 ) {
  7977. return target.copy( this.origin );
  7978. }
  7979. return target.copy( this.direction ).multiplyScalar( directionDistance ).add( this.origin );
  7980. },
  7981. distanceToPoint: function ( point ) {
  7982. return Math.sqrt( this.distanceSqToPoint( point ) );
  7983. },
  7984. distanceSqToPoint: function () {
  7985. var v1 = new Vector3();
  7986. return function distanceSqToPoint( point ) {
  7987. var directionDistance = v1.subVectors( point, this.origin ).dot( this.direction );
  7988. // point behind the ray
  7989. if ( directionDistance < 0 ) {
  7990. return this.origin.distanceToSquared( point );
  7991. }
  7992. v1.copy( this.direction ).multiplyScalar( directionDistance ).add( this.origin );
  7993. return v1.distanceToSquared( point );
  7994. };
  7995. }(),
  7996. distanceSqToSegment: function () {
  7997. var segCenter = new Vector3();
  7998. var segDir = new Vector3();
  7999. var diff = new Vector3();
  8000. return function distanceSqToSegment( v0, v1, optionalPointOnRay, optionalPointOnSegment ) {
  8001. // from http://www.geometrictools.com/GTEngine/Include/Mathematics/GteDistRaySegment.h
  8002. // It returns the min distance between the ray and the segment
  8003. // defined by v0 and v1
  8004. // It can also set two optional targets :
  8005. // - The closest point on the ray
  8006. // - The closest point on the segment
  8007. segCenter.copy( v0 ).add( v1 ).multiplyScalar( 0.5 );
  8008. segDir.copy( v1 ).sub( v0 ).normalize();
  8009. diff.copy( this.origin ).sub( segCenter );
  8010. var segExtent = v0.distanceTo( v1 ) * 0.5;
  8011. var a01 = - this.direction.dot( segDir );
  8012. var b0 = diff.dot( this.direction );
  8013. var b1 = - diff.dot( segDir );
  8014. var c = diff.lengthSq();
  8015. var det = Math.abs( 1 - a01 * a01 );
  8016. var s0, s1, sqrDist, extDet;
  8017. if ( det > 0 ) {
  8018. // The ray and segment are not parallel.
  8019. s0 = a01 * b1 - b0;
  8020. s1 = a01 * b0 - b1;
  8021. extDet = segExtent * det;
  8022. if ( s0 >= 0 ) {
  8023. if ( s1 >= - extDet ) {
  8024. if ( s1 <= extDet ) {
  8025. // region 0
  8026. // Minimum at interior points of ray and segment.
  8027. var invDet = 1 / det;
  8028. s0 *= invDet;
  8029. s1 *= invDet;
  8030. sqrDist = s0 * ( s0 + a01 * s1 + 2 * b0 ) + s1 * ( a01 * s0 + s1 + 2 * b1 ) + c;
  8031. } else {
  8032. // region 1
  8033. s1 = segExtent;
  8034. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  8035. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  8036. }
  8037. } else {
  8038. // region 5
  8039. s1 = - segExtent;
  8040. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  8041. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  8042. }
  8043. } else {
  8044. if ( s1 <= - extDet ) {
  8045. // region 4
  8046. s0 = Math.max( 0, - ( - a01 * segExtent + b0 ) );
  8047. s1 = ( s0 > 0 ) ? - segExtent : Math.min( Math.max( - segExtent, - b1 ), segExtent );
  8048. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  8049. } else if ( s1 <= extDet ) {
  8050. // region 3
  8051. s0 = 0;
  8052. s1 = Math.min( Math.max( - segExtent, - b1 ), segExtent );
  8053. sqrDist = s1 * ( s1 + 2 * b1 ) + c;
  8054. } else {
  8055. // region 2
  8056. s0 = Math.max( 0, - ( a01 * segExtent + b0 ) );
  8057. s1 = ( s0 > 0 ) ? segExtent : Math.min( Math.max( - segExtent, - b1 ), segExtent );
  8058. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  8059. }
  8060. }
  8061. } else {
  8062. // Ray and segment are parallel.
  8063. s1 = ( a01 > 0 ) ? - segExtent : segExtent;
  8064. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  8065. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  8066. }
  8067. if ( optionalPointOnRay ) {
  8068. optionalPointOnRay.copy( this.direction ).multiplyScalar( s0 ).add( this.origin );
  8069. }
  8070. if ( optionalPointOnSegment ) {
  8071. optionalPointOnSegment.copy( segDir ).multiplyScalar( s1 ).add( segCenter );
  8072. }
  8073. return sqrDist;
  8074. };
  8075. }(),
  8076. intersectSphere: function () {
  8077. var v1 = new Vector3();
  8078. return function intersectSphere( sphere, target ) {
  8079. v1.subVectors( sphere.center, this.origin );
  8080. var tca = v1.dot( this.direction );
  8081. var d2 = v1.dot( v1 ) - tca * tca;
  8082. var radius2 = sphere.radius * sphere.radius;
  8083. if ( d2 > radius2 ) return null;
  8084. var thc = Math.sqrt( radius2 - d2 );
  8085. // t0 = first intersect point - entrance on front of sphere
  8086. var t0 = tca - thc;
  8087. // t1 = second intersect point - exit point on back of sphere
  8088. var t1 = tca + thc;
  8089. // test to see if both t0 and t1 are behind the ray - if so, return null
  8090. if ( t0 < 0 && t1 < 0 ) return null;
  8091. // test to see if t0 is behind the ray:
  8092. // if it is, the ray is inside the sphere, so return the second exit point scaled by t1,
  8093. // in order to always return an intersect point that is in front of the ray.
  8094. if ( t0 < 0 ) return this.at( t1, target );
  8095. // else t0 is in front of the ray, so return the first collision point scaled by t0
  8096. return this.at( t0, target );
  8097. };
  8098. }(),
  8099. intersectsSphere: function ( sphere ) {
  8100. return this.distanceSqToPoint( sphere.center ) <= ( sphere.radius * sphere.radius );
  8101. },
  8102. distanceToPlane: function ( plane ) {
  8103. var denominator = plane.normal.dot( this.direction );
  8104. if ( denominator === 0 ) {
  8105. // line is coplanar, return origin
  8106. if ( plane.distanceToPoint( this.origin ) === 0 ) {
  8107. return 0;
  8108. }
  8109. // Null is preferable to undefined since undefined means.... it is undefined
  8110. return null;
  8111. }
  8112. var t = - ( this.origin.dot( plane.normal ) + plane.constant ) / denominator;
  8113. // Return if the ray never intersects the plane
  8114. return t >= 0 ? t : null;
  8115. },
  8116. intersectPlane: function ( plane, target ) {
  8117. var t = this.distanceToPlane( plane );
  8118. if ( t === null ) {
  8119. return null;
  8120. }
  8121. return this.at( t, target );
  8122. },
  8123. intersectsPlane: function ( plane ) {
  8124. // check if the ray lies on the plane first
  8125. var distToPoint = plane.distanceToPoint( this.origin );
  8126. if ( distToPoint === 0 ) {
  8127. return true;
  8128. }
  8129. var denominator = plane.normal.dot( this.direction );
  8130. if ( denominator * distToPoint < 0 ) {
  8131. return true;
  8132. }
  8133. // ray origin is behind the plane (and is pointing behind it)
  8134. return false;
  8135. },
  8136. intersectBox: function ( box, target ) {
  8137. var tmin, tmax, tymin, tymax, tzmin, tzmax;
  8138. var invdirx = 1 / this.direction.x,
  8139. invdiry = 1 / this.direction.y,
  8140. invdirz = 1 / this.direction.z;
  8141. var origin = this.origin;
  8142. if ( invdirx >= 0 ) {
  8143. tmin = ( box.min.x - origin.x ) * invdirx;
  8144. tmax = ( box.max.x - origin.x ) * invdirx;
  8145. } else {
  8146. tmin = ( box.max.x - origin.x ) * invdirx;
  8147. tmax = ( box.min.x - origin.x ) * invdirx;
  8148. }
  8149. if ( invdiry >= 0 ) {
  8150. tymin = ( box.min.y - origin.y ) * invdiry;
  8151. tymax = ( box.max.y - origin.y ) * invdiry;
  8152. } else {
  8153. tymin = ( box.max.y - origin.y ) * invdiry;
  8154. tymax = ( box.min.y - origin.y ) * invdiry;
  8155. }
  8156. if ( ( tmin > tymax ) || ( tymin > tmax ) ) return null;
  8157. // These lines also handle the case where tmin or tmax is NaN
  8158. // (result of 0 * Infinity). x !== x returns true if x is NaN
  8159. if ( tymin > tmin || tmin !== tmin ) tmin = tymin;
  8160. if ( tymax < tmax || tmax !== tmax ) tmax = tymax;
  8161. if ( invdirz >= 0 ) {
  8162. tzmin = ( box.min.z - origin.z ) * invdirz;
  8163. tzmax = ( box.max.z - origin.z ) * invdirz;
  8164. } else {
  8165. tzmin = ( box.max.z - origin.z ) * invdirz;
  8166. tzmax = ( box.min.z - origin.z ) * invdirz;
  8167. }
  8168. if ( ( tmin > tzmax ) || ( tzmin > tmax ) ) return null;
  8169. if ( tzmin > tmin || tmin !== tmin ) tmin = tzmin;
  8170. if ( tzmax < tmax || tmax !== tmax ) tmax = tzmax;
  8171. //return point closest to the ray (positive side)
  8172. if ( tmax < 0 ) return null;
  8173. return this.at( tmin >= 0 ? tmin : tmax, target );
  8174. },
  8175. intersectsBox: ( function () {
  8176. var v = new Vector3();
  8177. return function intersectsBox( box ) {
  8178. return this.intersectBox( box, v ) !== null;
  8179. };
  8180. } )(),
  8181. intersectTriangle: function () {
  8182. // Compute the offset origin, edges, and normal.
  8183. var diff = new Vector3();
  8184. var edge1 = new Vector3();
  8185. var edge2 = new Vector3();
  8186. var normal = new Vector3();
  8187. return function intersectTriangle( a, b, c, backfaceCulling, target ) {
  8188. // from http://www.geometrictools.com/GTEngine/Include/Mathematics/GteIntrRay3Triangle3.h
  8189. edge1.subVectors( b, a );
  8190. edge2.subVectors( c, a );
  8191. normal.crossVectors( edge1, edge2 );
  8192. // Solve Q + t*D = b1*E1 + b2*E2 (Q = kDiff, D = ray direction,
  8193. // E1 = kEdge1, E2 = kEdge2, N = Cross(E1,E2)) by
  8194. // |Dot(D,N)|*b1 = sign(Dot(D,N))*Dot(D,Cross(Q,E2))
  8195. // |Dot(D,N)|*b2 = sign(Dot(D,N))*Dot(D,Cross(E1,Q))
  8196. // |Dot(D,N)|*t = -sign(Dot(D,N))*Dot(Q,N)
  8197. var DdN = this.direction.dot( normal );
  8198. var sign;
  8199. if ( DdN > 0 ) {
  8200. if ( backfaceCulling ) return null;
  8201. sign = 1;
  8202. } else if ( DdN < 0 ) {
  8203. sign = - 1;
  8204. DdN = - DdN;
  8205. } else {
  8206. return null;
  8207. }
  8208. diff.subVectors( this.origin, a );
  8209. var DdQxE2 = sign * this.direction.dot( edge2.crossVectors( diff, edge2 ) );
  8210. // b1 < 0, no intersection
  8211. if ( DdQxE2 < 0 ) {
  8212. return null;
  8213. }
  8214. var DdE1xQ = sign * this.direction.dot( edge1.cross( diff ) );
  8215. // b2 < 0, no intersection
  8216. if ( DdE1xQ < 0 ) {
  8217. return null;
  8218. }
  8219. // b1+b2 > 1, no intersection
  8220. if ( DdQxE2 + DdE1xQ > DdN ) {
  8221. return null;
  8222. }
  8223. // Line intersects triangle, check if ray does.
  8224. var QdN = - sign * diff.dot( normal );
  8225. // t < 0, no intersection
  8226. if ( QdN < 0 ) {
  8227. return null;
  8228. }
  8229. // Ray intersects triangle.
  8230. return this.at( QdN / DdN, target );
  8231. };
  8232. }(),
  8233. applyMatrix4: function ( matrix4 ) {
  8234. this.origin.applyMatrix4( matrix4 );
  8235. this.direction.transformDirection( matrix4 );
  8236. return this;
  8237. },
  8238. equals: function ( ray ) {
  8239. return ray.origin.equals( this.origin ) && ray.direction.equals( this.direction );
  8240. }
  8241. } );
  8242. /**
  8243. * @author bhouston / http://clara.io
  8244. * @author mrdoob / http://mrdoob.com/
  8245. */
  8246. function Triangle( a, b, c ) {
  8247. this.a = ( a !== undefined ) ? a : new Vector3();
  8248. this.b = ( b !== undefined ) ? b : new Vector3();
  8249. this.c = ( c !== undefined ) ? c : new Vector3();
  8250. }
  8251. Object.assign( Triangle, {
  8252. getNormal: function () {
  8253. var v0 = new Vector3();
  8254. return function getNormal( a, b, c, target ) {
  8255. if ( target === undefined ) {
  8256. console.warn( 'THREE.Triangle: .getNormal() target is now required' );
  8257. target = new Vector3();
  8258. }
  8259. target.subVectors( c, b );
  8260. v0.subVectors( a, b );
  8261. target.cross( v0 );
  8262. var targetLengthSq = target.lengthSq();
  8263. if ( targetLengthSq > 0 ) {
  8264. return target.multiplyScalar( 1 / Math.sqrt( targetLengthSq ) );
  8265. }
  8266. return target.set( 0, 0, 0 );
  8267. };
  8268. }(),
  8269. // static/instance method to calculate barycentric coordinates
  8270. // based on: http://www.blackpawn.com/texts/pointinpoly/default.html
  8271. getBarycoord: function () {
  8272. var v0 = new Vector3();
  8273. var v1 = new Vector3();
  8274. var v2 = new Vector3();
  8275. return function getBarycoord( point, a, b, c, target ) {
  8276. v0.subVectors( c, a );
  8277. v1.subVectors( b, a );
  8278. v2.subVectors( point, a );
  8279. var dot00 = v0.dot( v0 );
  8280. var dot01 = v0.dot( v1 );
  8281. var dot02 = v0.dot( v2 );
  8282. var dot11 = v1.dot( v1 );
  8283. var dot12 = v1.dot( v2 );
  8284. var denom = ( dot00 * dot11 - dot01 * dot01 );
  8285. if ( target === undefined ) {
  8286. console.warn( 'THREE.Triangle: .getBarycoord() target is now required' );
  8287. target = new Vector3();
  8288. }
  8289. // collinear or singular triangle
  8290. if ( denom === 0 ) {
  8291. // arbitrary location outside of triangle?
  8292. // not sure if this is the best idea, maybe should be returning undefined
  8293. return target.set( - 2, - 1, - 1 );
  8294. }
  8295. var invDenom = 1 / denom;
  8296. var u = ( dot11 * dot02 - dot01 * dot12 ) * invDenom;
  8297. var v = ( dot00 * dot12 - dot01 * dot02 ) * invDenom;
  8298. // barycentric coordinates must always sum to 1
  8299. return target.set( 1 - u - v, v, u );
  8300. };
  8301. }(),
  8302. containsPoint: function () {
  8303. var v1 = new Vector3();
  8304. return function containsPoint( point, a, b, c ) {
  8305. Triangle.getBarycoord( point, a, b, c, v1 );
  8306. return ( v1.x >= 0 ) && ( v1.y >= 0 ) && ( ( v1.x + v1.y ) <= 1 );
  8307. };
  8308. }(),
  8309. getUV: function () {
  8310. var barycoord = new Vector3();
  8311. return function getUV( point, p1, p2, p3, uv1, uv2, uv3, target ) {
  8312. this.getBarycoord( point, p1, p2, p3, barycoord );
  8313. target.set( 0, 0 );
  8314. target.addScaledVector( uv1, barycoord.x );
  8315. target.addScaledVector( uv2, barycoord.y );
  8316. target.addScaledVector( uv3, barycoord.z );
  8317. return target;
  8318. };
  8319. }(),
  8320. isFrontFacing: function () {
  8321. var v0 = new Vector3();
  8322. var v1 = new Vector3();
  8323. return function isFrontFacing( a, b, c, direction ) {
  8324. v0.subVectors( c, b );
  8325. v1.subVectors( a, b );
  8326. // strictly front facing
  8327. return ( v0.cross( v1 ).dot( direction ) < 0 ) ? true : false;
  8328. };
  8329. }()
  8330. } );
  8331. Object.assign( Triangle.prototype, {
  8332. set: function ( a, b, c ) {
  8333. this.a.copy( a );
  8334. this.b.copy( b );
  8335. this.c.copy( c );
  8336. return this;
  8337. },
  8338. setFromPointsAndIndices: function ( points, i0, i1, i2 ) {
  8339. this.a.copy( points[ i0 ] );
  8340. this.b.copy( points[ i1 ] );
  8341. this.c.copy( points[ i2 ] );
  8342. return this;
  8343. },
  8344. clone: function () {
  8345. return new this.constructor().copy( this );
  8346. },
  8347. copy: function ( triangle ) {
  8348. this.a.copy( triangle.a );
  8349. this.b.copy( triangle.b );
  8350. this.c.copy( triangle.c );
  8351. return this;
  8352. },
  8353. getArea: function () {
  8354. var v0 = new Vector3();
  8355. var v1 = new Vector3();
  8356. return function getArea() {
  8357. v0.subVectors( this.c, this.b );
  8358. v1.subVectors( this.a, this.b );
  8359. return v0.cross( v1 ).length() * 0.5;
  8360. };
  8361. }(),
  8362. getMidpoint: function ( target ) {
  8363. if ( target === undefined ) {
  8364. console.warn( 'THREE.Triangle: .getMidpoint() target is now required' );
  8365. target = new Vector3();
  8366. }
  8367. return target.addVectors( this.a, this.b ).add( this.c ).multiplyScalar( 1 / 3 );
  8368. },
  8369. getNormal: function ( target ) {
  8370. return Triangle.getNormal( this.a, this.b, this.c, target );
  8371. },
  8372. getPlane: function ( target ) {
  8373. if ( target === undefined ) {
  8374. console.warn( 'THREE.Triangle: .getPlane() target is now required' );
  8375. target = new Vector3();
  8376. }
  8377. return target.setFromCoplanarPoints( this.a, this.b, this.c );
  8378. },
  8379. getBarycoord: function ( point, target ) {
  8380. return Triangle.getBarycoord( point, this.a, this.b, this.c, target );
  8381. },
  8382. getUV: function ( point, uv1, uv2, uv3, target ) {
  8383. return Triangle.getUV( point, this.a, this.b, this.c, uv1, uv2, uv3, target );
  8384. },
  8385. containsPoint: function ( point ) {
  8386. return Triangle.containsPoint( point, this.a, this.b, this.c );
  8387. },
  8388. isFrontFacing: function ( direction ) {
  8389. return Triangle.isFrontFacing( this.a, this.b, this.c, direction );
  8390. },
  8391. intersectsBox: function ( box ) {
  8392. return box.intersectsTriangle( this );
  8393. },
  8394. closestPointToPoint: function () {
  8395. var vab = new Vector3();
  8396. var vac = new Vector3();
  8397. var vbc = new Vector3();
  8398. var vap = new Vector3();
  8399. var vbp = new Vector3();
  8400. var vcp = new Vector3();
  8401. return function closestPointToPoint( p, target ) {
  8402. if ( target === undefined ) {
  8403. console.warn( 'THREE.Triangle: .closestPointToPoint() target is now required' );
  8404. target = new Vector3();
  8405. }
  8406. var a = this.a, b = this.b, c = this.c;
  8407. var v, w;
  8408. // algorithm thanks to Real-Time Collision Detection by Christer Ericson,
  8409. // published by Morgan Kaufmann Publishers, (c) 2005 Elsevier Inc.,
  8410. // under the accompanying license; see chapter 5.1.5 for detailed explanation.
  8411. // basically, we're distinguishing which of the voronoi regions of the triangle
  8412. // the point lies in with the minimum amount of redundant computation.
  8413. vab.subVectors( b, a );
  8414. vac.subVectors( c, a );
  8415. vap.subVectors( p, a );
  8416. var d1 = vab.dot( vap );
  8417. var d2 = vac.dot( vap );
  8418. if ( d1 <= 0 && d2 <= 0 ) {
  8419. // vertex region of A; barycentric coords (1, 0, 0)
  8420. return target.copy( a );
  8421. }
  8422. vbp.subVectors( p, b );
  8423. var d3 = vab.dot( vbp );
  8424. var d4 = vac.dot( vbp );
  8425. if ( d3 >= 0 && d4 <= d3 ) {
  8426. // vertex region of B; barycentric coords (0, 1, 0)
  8427. return target.copy( b );
  8428. }
  8429. var vc = d1 * d4 - d3 * d2;
  8430. if ( vc <= 0 && d1 >= 0 && d3 <= 0 ) {
  8431. v = d1 / ( d1 - d3 );
  8432. // edge region of AB; barycentric coords (1-v, v, 0)
  8433. return target.copy( a ).addScaledVector( vab, v );
  8434. }
  8435. vcp.subVectors( p, c );
  8436. var d5 = vab.dot( vcp );
  8437. var d6 = vac.dot( vcp );
  8438. if ( d6 >= 0 && d5 <= d6 ) {
  8439. // vertex region of C; barycentric coords (0, 0, 1)
  8440. return target.copy( c );
  8441. }
  8442. var vb = d5 * d2 - d1 * d6;
  8443. if ( vb <= 0 && d2 >= 0 && d6 <= 0 ) {
  8444. w = d2 / ( d2 - d6 );
  8445. // edge region of AC; barycentric coords (1-w, 0, w)
  8446. return target.copy( a ).addScaledVector( vac, w );
  8447. }
  8448. var va = d3 * d6 - d5 * d4;
  8449. if ( va <= 0 && ( d4 - d3 ) >= 0 && ( d5 - d6 ) >= 0 ) {
  8450. vbc.subVectors( c, b );
  8451. w = ( d4 - d3 ) / ( ( d4 - d3 ) + ( d5 - d6 ) );
  8452. // edge region of BC; barycentric coords (0, 1-w, w)
  8453. return target.copy( b ).addScaledVector( vbc, w ); // edge region of BC
  8454. }
  8455. // face region
  8456. var denom = 1 / ( va + vb + vc );
  8457. // u = va * denom
  8458. v = vb * denom;
  8459. w = vc * denom;
  8460. return target.copy( a ).addScaledVector( vab, v ).addScaledVector( vac, w );
  8461. };
  8462. }(),
  8463. equals: function ( triangle ) {
  8464. return triangle.a.equals( this.a ) && triangle.b.equals( this.b ) && triangle.c.equals( this.c );
  8465. }
  8466. } );
  8467. /**
  8468. * @author mrdoob / http://mrdoob.com/
  8469. * @author alteredq / http://alteredqualia.com/
  8470. *
  8471. * parameters = {
  8472. * color: <hex>,
  8473. * opacity: <float>,
  8474. * map: new THREE.Texture( <Image> ),
  8475. *
  8476. * lightMap: new THREE.Texture( <Image> ),
  8477. * lightMapIntensity: <float>
  8478. *
  8479. * aoMap: new THREE.Texture( <Image> ),
  8480. * aoMapIntensity: <float>
  8481. *
  8482. * specularMap: new THREE.Texture( <Image> ),
  8483. *
  8484. * alphaMap: new THREE.Texture( <Image> ),
  8485. *
  8486. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  8487. * combine: THREE.Multiply,
  8488. * reflectivity: <float>,
  8489. * refractionRatio: <float>,
  8490. *
  8491. * depthTest: <bool>,
  8492. * depthWrite: <bool>,
  8493. *
  8494. * wireframe: <boolean>,
  8495. * wireframeLinewidth: <float>,
  8496. *
  8497. * skinning: <bool>,
  8498. * morphTargets: <bool>
  8499. * }
  8500. */
  8501. function MeshBasicMaterial( parameters ) {
  8502. Material.call( this );
  8503. this.type = 'MeshBasicMaterial';
  8504. this.color = new Color( 0xffffff ); // emissive
  8505. this.map = null;
  8506. this.lightMap = null;
  8507. this.lightMapIntensity = 1.0;
  8508. this.aoMap = null;
  8509. this.aoMapIntensity = 1.0;
  8510. this.specularMap = null;
  8511. this.alphaMap = null;
  8512. this.envMap = null;
  8513. this.combine = MultiplyOperation;
  8514. this.reflectivity = 1;
  8515. this.refractionRatio = 0.98;
  8516. this.wireframe = false;
  8517. this.wireframeLinewidth = 1;
  8518. this.wireframeLinecap = 'round';
  8519. this.wireframeLinejoin = 'round';
  8520. this.skinning = false;
  8521. this.morphTargets = false;
  8522. this.lights = false;
  8523. this.setValues( parameters );
  8524. }
  8525. MeshBasicMaterial.prototype = Object.create( Material.prototype );
  8526. MeshBasicMaterial.prototype.constructor = MeshBasicMaterial;
  8527. MeshBasicMaterial.prototype.isMeshBasicMaterial = true;
  8528. MeshBasicMaterial.prototype.copy = function ( source ) {
  8529. Material.prototype.copy.call( this, source );
  8530. this.color.copy( source.color );
  8531. this.map = source.map;
  8532. this.lightMap = source.lightMap;
  8533. this.lightMapIntensity = source.lightMapIntensity;
  8534. this.aoMap = source.aoMap;
  8535. this.aoMapIntensity = source.aoMapIntensity;
  8536. this.specularMap = source.specularMap;
  8537. this.alphaMap = source.alphaMap;
  8538. this.envMap = source.envMap;
  8539. this.combine = source.combine;
  8540. this.reflectivity = source.reflectivity;
  8541. this.refractionRatio = source.refractionRatio;
  8542. this.wireframe = source.wireframe;
  8543. this.wireframeLinewidth = source.wireframeLinewidth;
  8544. this.wireframeLinecap = source.wireframeLinecap;
  8545. this.wireframeLinejoin = source.wireframeLinejoin;
  8546. this.skinning = source.skinning;
  8547. this.morphTargets = source.morphTargets;
  8548. return this;
  8549. };
  8550. /**
  8551. * @author mrdoob / http://mrdoob.com/
  8552. * @author alteredq / http://alteredqualia.com/
  8553. * @author mikael emtinger / http://gomo.se/
  8554. * @author jonobr1 / http://jonobr1.com/
  8555. */
  8556. function Mesh( geometry, material ) {
  8557. Object3D.call( this );
  8558. this.type = 'Mesh';
  8559. this.geometry = geometry !== undefined ? geometry : new BufferGeometry();
  8560. this.material = material !== undefined ? material : new MeshBasicMaterial( { color: Math.random() * 0xffffff } );
  8561. this.drawMode = TrianglesDrawMode;
  8562. this.updateMorphTargets();
  8563. }
  8564. Mesh.prototype = Object.assign( Object.create( Object3D.prototype ), {
  8565. constructor: Mesh,
  8566. isMesh: true,
  8567. setDrawMode: function ( value ) {
  8568. this.drawMode = value;
  8569. },
  8570. copy: function ( source ) {
  8571. Object3D.prototype.copy.call( this, source );
  8572. this.drawMode = source.drawMode;
  8573. if ( source.morphTargetInfluences !== undefined ) {
  8574. this.morphTargetInfluences = source.morphTargetInfluences.slice();
  8575. }
  8576. if ( source.morphTargetDictionary !== undefined ) {
  8577. this.morphTargetDictionary = Object.assign( {}, source.morphTargetDictionary );
  8578. }
  8579. return this;
  8580. },
  8581. updateMorphTargets: function () {
  8582. var geometry = this.geometry;
  8583. var m, ml, name;
  8584. if ( geometry.isBufferGeometry ) {
  8585. var morphAttributes = geometry.morphAttributes;
  8586. var keys = Object.keys( morphAttributes );
  8587. if ( keys.length > 0 ) {
  8588. var morphAttribute = morphAttributes[ keys[ 0 ] ];
  8589. if ( morphAttribute !== undefined ) {
  8590. this.morphTargetInfluences = [];
  8591. this.morphTargetDictionary = {};
  8592. for ( m = 0, ml = morphAttribute.length; m < ml; m ++ ) {
  8593. name = morphAttribute[ m ].name || String( m );
  8594. this.morphTargetInfluences.push( 0 );
  8595. this.morphTargetDictionary[ name ] = m;
  8596. }
  8597. }
  8598. }
  8599. } else {
  8600. var morphTargets = geometry.morphTargets;
  8601. if ( morphTargets !== undefined && morphTargets.length > 0 ) {
  8602. console.error( 'THREE.Mesh.updateMorphTargets() no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.' );
  8603. }
  8604. }
  8605. },
  8606. raycast: ( function () {
  8607. var inverseMatrix = new Matrix4();
  8608. var ray = new Ray();
  8609. var sphere = new Sphere();
  8610. var vA = new Vector3();
  8611. var vB = new Vector3();
  8612. var vC = new Vector3();
  8613. var tempA = new Vector3();
  8614. var tempB = new Vector3();
  8615. var tempC = new Vector3();
  8616. var morphA = new Vector3();
  8617. var morphB = new Vector3();
  8618. var morphC = new Vector3();
  8619. var uvA = new Vector2();
  8620. var uvB = new Vector2();
  8621. var uvC = new Vector2();
  8622. var intersectionPoint = new Vector3();
  8623. var intersectionPointWorld = new Vector3();
  8624. function checkIntersection( object, material, raycaster, ray, pA, pB, pC, point ) {
  8625. var intersect;
  8626. if ( material.side === BackSide ) {
  8627. intersect = ray.intersectTriangle( pC, pB, pA, true, point );
  8628. } else {
  8629. intersect = ray.intersectTriangle( pA, pB, pC, material.side !== DoubleSide, point );
  8630. }
  8631. if ( intersect === null ) return null;
  8632. intersectionPointWorld.copy( point );
  8633. intersectionPointWorld.applyMatrix4( object.matrixWorld );
  8634. var distance = raycaster.ray.origin.distanceTo( intersectionPointWorld );
  8635. if ( distance < raycaster.near || distance > raycaster.far ) return null;
  8636. return {
  8637. distance: distance,
  8638. point: intersectionPointWorld.clone(),
  8639. object: object
  8640. };
  8641. }
  8642. function checkBufferGeometryIntersection( object, material, raycaster, ray, position, morphPosition, uv, a, b, c ) {
  8643. vA.fromBufferAttribute( position, a );
  8644. vB.fromBufferAttribute( position, b );
  8645. vC.fromBufferAttribute( position, c );
  8646. var morphInfluences = object.morphTargetInfluences;
  8647. if ( material.morphTargets && morphPosition && morphInfluences ) {
  8648. morphA.set( 0, 0, 0 );
  8649. morphB.set( 0, 0, 0 );
  8650. morphC.set( 0, 0, 0 );
  8651. for ( var i = 0, il = morphPosition.length; i < il; i ++ ) {
  8652. var influence = morphInfluences[ i ];
  8653. var morphAttribute = morphPosition[ i ];
  8654. if ( influence === 0 ) continue;
  8655. tempA.fromBufferAttribute( morphAttribute, a );
  8656. tempB.fromBufferAttribute( morphAttribute, b );
  8657. tempC.fromBufferAttribute( morphAttribute, c );
  8658. morphA.addScaledVector( tempA.sub( vA ), influence );
  8659. morphB.addScaledVector( tempB.sub( vB ), influence );
  8660. morphC.addScaledVector( tempC.sub( vC ), influence );
  8661. }
  8662. vA.add( morphA );
  8663. vB.add( morphB );
  8664. vC.add( morphC );
  8665. }
  8666. var intersection = checkIntersection( object, material, raycaster, ray, vA, vB, vC, intersectionPoint );
  8667. if ( intersection ) {
  8668. if ( uv ) {
  8669. uvA.fromBufferAttribute( uv, a );
  8670. uvB.fromBufferAttribute( uv, b );
  8671. uvC.fromBufferAttribute( uv, c );
  8672. intersection.uv = Triangle.getUV( intersectionPoint, vA, vB, vC, uvA, uvB, uvC, new Vector2() );
  8673. }
  8674. var face = new Face3( a, b, c );
  8675. Triangle.getNormal( vA, vB, vC, face.normal );
  8676. intersection.face = face;
  8677. }
  8678. return intersection;
  8679. }
  8680. return function raycast( raycaster, intersects ) {
  8681. var geometry = this.geometry;
  8682. var material = this.material;
  8683. var matrixWorld = this.matrixWorld;
  8684. if ( material === undefined ) return;
  8685. // Checking boundingSphere distance to ray
  8686. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  8687. sphere.copy( geometry.boundingSphere );
  8688. sphere.applyMatrix4( matrixWorld );
  8689. if ( raycaster.ray.intersectsSphere( sphere ) === false ) return;
  8690. //
  8691. inverseMatrix.getInverse( matrixWorld );
  8692. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  8693. // Check boundingBox before continuing
  8694. if ( geometry.boundingBox !== null ) {
  8695. if ( ray.intersectsBox( geometry.boundingBox ) === false ) return;
  8696. }
  8697. var intersection;
  8698. if ( geometry.isBufferGeometry ) {
  8699. var a, b, c;
  8700. var index = geometry.index;
  8701. var position = geometry.attributes.position;
  8702. var morphPosition = geometry.morphAttributes.position;
  8703. var uv = geometry.attributes.uv;
  8704. var groups = geometry.groups;
  8705. var drawRange = geometry.drawRange;
  8706. var i, j, il, jl;
  8707. var group, groupMaterial;
  8708. var start, end;
  8709. if ( index !== null ) {
  8710. // indexed buffer geometry
  8711. if ( Array.isArray( material ) ) {
  8712. for ( i = 0, il = groups.length; i < il; i ++ ) {
  8713. group = groups[ i ];
  8714. groupMaterial = material[ group.materialIndex ];
  8715. start = Math.max( group.start, drawRange.start );
  8716. end = Math.min( ( group.start + group.count ), ( drawRange.start + drawRange.count ) );
  8717. for ( j = start, jl = end; j < jl; j += 3 ) {
  8718. a = index.getX( j );
  8719. b = index.getX( j + 1 );
  8720. c = index.getX( j + 2 );
  8721. intersection = checkBufferGeometryIntersection( this, groupMaterial, raycaster, ray, position, morphPosition, uv, a, b, c );
  8722. if ( intersection ) {
  8723. intersection.faceIndex = Math.floor( j / 3 ); // triangle number in indexed buffer semantics
  8724. intersection.face.materialIndex = group.materialIndex;
  8725. intersects.push( intersection );
  8726. }
  8727. }
  8728. }
  8729. } else {
  8730. start = Math.max( 0, drawRange.start );
  8731. end = Math.min( index.count, ( drawRange.start + drawRange.count ) );
  8732. for ( i = start, il = end; i < il; i += 3 ) {
  8733. a = index.getX( i );
  8734. b = index.getX( i + 1 );
  8735. c = index.getX( i + 2 );
  8736. intersection = checkBufferGeometryIntersection( this, material, raycaster, ray, position, morphPosition, uv, a, b, c );
  8737. if ( intersection ) {
  8738. intersection.faceIndex = Math.floor( i / 3 ); // triangle number in indexed buffer semantics
  8739. intersects.push( intersection );
  8740. }
  8741. }
  8742. }
  8743. } else if ( position !== undefined ) {
  8744. // non-indexed buffer geometry
  8745. if ( Array.isArray( material ) ) {
  8746. for ( i = 0, il = groups.length; i < il; i ++ ) {
  8747. group = groups[ i ];
  8748. groupMaterial = material[ group.materialIndex ];
  8749. start = Math.max( group.start, drawRange.start );
  8750. end = Math.min( ( group.start + group.count ), ( drawRange.start + drawRange.count ) );
  8751. for ( j = start, jl = end; j < jl; j += 3 ) {
  8752. a = j;
  8753. b = j + 1;
  8754. c = j + 2;
  8755. intersection = checkBufferGeometryIntersection( this, groupMaterial, raycaster, ray, position, morphPosition, uv, a, b, c );
  8756. if ( intersection ) {
  8757. intersection.faceIndex = Math.floor( j / 3 ); // triangle number in non-indexed buffer semantics
  8758. intersection.face.materialIndex = group.materialIndex;
  8759. intersects.push( intersection );
  8760. }
  8761. }
  8762. }
  8763. } else {
  8764. start = Math.max( 0, drawRange.start );
  8765. end = Math.min( position.count, ( drawRange.start + drawRange.count ) );
  8766. for ( i = start, il = end; i < il; i += 3 ) {
  8767. a = i;
  8768. b = i + 1;
  8769. c = i + 2;
  8770. intersection = checkBufferGeometryIntersection( this, material, raycaster, ray, position, morphPosition, uv, a, b, c );
  8771. if ( intersection ) {
  8772. intersection.faceIndex = Math.floor( i / 3 ); // triangle number in non-indexed buffer semantics
  8773. intersects.push( intersection );
  8774. }
  8775. }
  8776. }
  8777. }
  8778. } else if ( geometry.isGeometry ) {
  8779. var fvA, fvB, fvC;
  8780. var isMultiMaterial = Array.isArray( material );
  8781. var vertices = geometry.vertices;
  8782. var faces = geometry.faces;
  8783. var uvs;
  8784. var faceVertexUvs = geometry.faceVertexUvs[ 0 ];
  8785. if ( faceVertexUvs.length > 0 ) uvs = faceVertexUvs;
  8786. for ( var f = 0, fl = faces.length; f < fl; f ++ ) {
  8787. var face = faces[ f ];
  8788. var faceMaterial = isMultiMaterial ? material[ face.materialIndex ] : material;
  8789. if ( faceMaterial === undefined ) continue;
  8790. fvA = vertices[ face.a ];
  8791. fvB = vertices[ face.b ];
  8792. fvC = vertices[ face.c ];
  8793. intersection = checkIntersection( this, faceMaterial, raycaster, ray, fvA, fvB, fvC, intersectionPoint );
  8794. if ( intersection ) {
  8795. if ( uvs && uvs[ f ] ) {
  8796. var uvs_f = uvs[ f ];
  8797. uvA.copy( uvs_f[ 0 ] );
  8798. uvB.copy( uvs_f[ 1 ] );
  8799. uvC.copy( uvs_f[ 2 ] );
  8800. intersection.uv = Triangle.getUV( intersectionPoint, fvA, fvB, fvC, uvA, uvB, uvC, new Vector2() );
  8801. }
  8802. intersection.face = face;
  8803. intersection.faceIndex = f;
  8804. intersects.push( intersection );
  8805. }
  8806. }
  8807. }
  8808. };
  8809. }() ),
  8810. clone: function () {
  8811. return new this.constructor( this.geometry, this.material ).copy( this );
  8812. }
  8813. } );
  8814. /**
  8815. * @author mrdoob / http://mrdoob.com/
  8816. */
  8817. function WebGLBackground( renderer, state, objects, premultipliedAlpha ) {
  8818. var clearColor = new Color( 0x000000 );
  8819. var clearAlpha = 0;
  8820. var planeMesh;
  8821. var boxMesh;
  8822. // Store the current background texture and its `version`
  8823. // so we can recompile the material accordingly.
  8824. var currentBackground = null;
  8825. var currentBackgroundVersion = 0;
  8826. function render( renderList, scene, camera, forceClear ) {
  8827. var background = scene.background;
  8828. // Ignore background in AR
  8829. // TODO: Reconsider this.
  8830. var vr = renderer.vr;
  8831. var session = vr.getSession && vr.getSession();
  8832. if ( session && session.environmentBlendMode === 'additive' ) {
  8833. background = null;
  8834. }
  8835. if ( background === null ) {
  8836. setClear( clearColor, clearAlpha );
  8837. currentBackground = null;
  8838. currentBackgroundVersion = 0;
  8839. } else if ( background && background.isColor ) {
  8840. setClear( background, 1 );
  8841. forceClear = true;
  8842. currentBackground = null;
  8843. currentBackgroundVersion = 0;
  8844. }
  8845. if ( renderer.autoClear || forceClear ) {
  8846. renderer.clear( renderer.autoClearColor, renderer.autoClearDepth, renderer.autoClearStencil );
  8847. }
  8848. if ( background && ( background.isCubeTexture || background.isWebGLRenderTargetCube ) ) {
  8849. if ( boxMesh === undefined ) {
  8850. boxMesh = new Mesh(
  8851. new BoxBufferGeometry( 1, 1, 1 ),
  8852. new ShaderMaterial( {
  8853. type: 'BackgroundCubeMaterial',
  8854. uniforms: cloneUniforms( ShaderLib.cube.uniforms ),
  8855. vertexShader: ShaderLib.cube.vertexShader,
  8856. fragmentShader: ShaderLib.cube.fragmentShader,
  8857. side: BackSide,
  8858. depthTest: false,
  8859. depthWrite: false,
  8860. fog: false
  8861. } )
  8862. );
  8863. boxMesh.geometry.removeAttribute( 'normal' );
  8864. boxMesh.geometry.removeAttribute( 'uv' );
  8865. boxMesh.onBeforeRender = function ( renderer, scene, camera ) {
  8866. this.matrixWorld.copyPosition( camera.matrixWorld );
  8867. };
  8868. // enable code injection for non-built-in material
  8869. Object.defineProperty( boxMesh.material, 'map', {
  8870. get: function () {
  8871. return this.uniforms.tCube.value;
  8872. }
  8873. } );
  8874. objects.update( boxMesh );
  8875. }
  8876. var texture = background.isWebGLRenderTargetCube ? background.texture : background;
  8877. boxMesh.material.uniforms.tCube.value = texture;
  8878. boxMesh.material.uniforms.tFlip.value = ( background.isWebGLRenderTargetCube ) ? 1 : - 1;
  8879. if ( currentBackground !== background ||
  8880. currentBackgroundVersion !== texture.version ) {
  8881. boxMesh.material.needsUpdate = true;
  8882. currentBackground = background;
  8883. currentBackgroundVersion = texture.version;
  8884. }
  8885. // push to the pre-sorted opaque render list
  8886. renderList.unshift( boxMesh, boxMesh.geometry, boxMesh.material, 0, 0, null );
  8887. } else if ( background && background.isTexture ) {
  8888. if ( planeMesh === undefined ) {
  8889. planeMesh = new Mesh(
  8890. new PlaneBufferGeometry( 2, 2 ),
  8891. new ShaderMaterial( {
  8892. type: 'BackgroundMaterial',
  8893. uniforms: cloneUniforms( ShaderLib.background.uniforms ),
  8894. vertexShader: ShaderLib.background.vertexShader,
  8895. fragmentShader: ShaderLib.background.fragmentShader,
  8896. side: FrontSide,
  8897. depthTest: false,
  8898. depthWrite: false,
  8899. fog: false
  8900. } )
  8901. );
  8902. planeMesh.geometry.removeAttribute( 'normal' );
  8903. // enable code injection for non-built-in material
  8904. Object.defineProperty( planeMesh.material, 'map', {
  8905. get: function () {
  8906. return this.uniforms.t2D.value;
  8907. }
  8908. } );
  8909. objects.update( planeMesh );
  8910. }
  8911. planeMesh.material.uniforms.t2D.value = background;
  8912. if ( background.matrixAutoUpdate === true ) {
  8913. background.updateMatrix();
  8914. }
  8915. planeMesh.material.uniforms.uvTransform.value.copy( background.matrix );
  8916. if ( currentBackground !== background ||
  8917. currentBackgroundVersion !== background.version ) {
  8918. planeMesh.material.needsUpdate = true;
  8919. currentBackground = background;
  8920. currentBackgroundVersion = background.version;
  8921. }
  8922. // push to the pre-sorted opaque render list
  8923. renderList.unshift( planeMesh, planeMesh.geometry, planeMesh.material, 0, 0, null );
  8924. }
  8925. }
  8926. function setClear( color, alpha ) {
  8927. state.buffers.color.setClear( color.r, color.g, color.b, alpha, premultipliedAlpha );
  8928. }
  8929. return {
  8930. getClearColor: function () {
  8931. return clearColor;
  8932. },
  8933. setClearColor: function ( color, alpha ) {
  8934. clearColor.set( color );
  8935. clearAlpha = alpha !== undefined ? alpha : 1;
  8936. setClear( clearColor, clearAlpha );
  8937. },
  8938. getClearAlpha: function () {
  8939. return clearAlpha;
  8940. },
  8941. setClearAlpha: function ( alpha ) {
  8942. clearAlpha = alpha;
  8943. setClear( clearColor, clearAlpha );
  8944. },
  8945. render: render
  8946. };
  8947. }
  8948. /**
  8949. * @author mrdoob / http://mrdoob.com/
  8950. */
  8951. function WebGLBufferRenderer( gl, extensions, info, capabilities ) {
  8952. var mode;
  8953. function setMode( value ) {
  8954. mode = value;
  8955. }
  8956. function render( start, count ) {
  8957. gl.drawArrays( mode, start, count );
  8958. info.update( count, mode );
  8959. }
  8960. function renderInstances( geometry, start, count ) {
  8961. var extension;
  8962. if ( capabilities.isWebGL2 ) {
  8963. extension = gl;
  8964. } else {
  8965. extension = extensions.get( 'ANGLE_instanced_arrays' );
  8966. if ( extension === null ) {
  8967. console.error( 'THREE.WebGLBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  8968. return;
  8969. }
  8970. }
  8971. extension[ capabilities.isWebGL2 ? 'drawArraysInstanced' : 'drawArraysInstancedANGLE' ]( mode, start, count, geometry.maxInstancedCount );
  8972. info.update( count, mode, geometry.maxInstancedCount );
  8973. }
  8974. //
  8975. this.setMode = setMode;
  8976. this.render = render;
  8977. this.renderInstances = renderInstances;
  8978. }
  8979. /**
  8980. * @author mrdoob / http://mrdoob.com/
  8981. */
  8982. function WebGLCapabilities( gl, extensions, parameters ) {
  8983. var maxAnisotropy;
  8984. function getMaxAnisotropy() {
  8985. if ( maxAnisotropy !== undefined ) return maxAnisotropy;
  8986. var extension = extensions.get( 'EXT_texture_filter_anisotropic' );
  8987. if ( extension !== null ) {
  8988. maxAnisotropy = gl.getParameter( extension.MAX_TEXTURE_MAX_ANISOTROPY_EXT );
  8989. } else {
  8990. maxAnisotropy = 0;
  8991. }
  8992. return maxAnisotropy;
  8993. }
  8994. function getMaxPrecision( precision ) {
  8995. if ( precision === 'highp' ) {
  8996. if ( gl.getShaderPrecisionFormat( 35633, 36338 ).precision > 0 &&
  8997. gl.getShaderPrecisionFormat( 35632, 36338 ).precision > 0 ) {
  8998. return 'highp';
  8999. }
  9000. precision = 'mediump';
  9001. }
  9002. if ( precision === 'mediump' ) {
  9003. if ( gl.getShaderPrecisionFormat( 35633, 36337 ).precision > 0 &&
  9004. gl.getShaderPrecisionFormat( 35632, 36337 ).precision > 0 ) {
  9005. return 'mediump';
  9006. }
  9007. }
  9008. return 'lowp';
  9009. }
  9010. var isWebGL2 = typeof WebGL2RenderingContext !== 'undefined' && gl instanceof WebGL2RenderingContext;
  9011. var precision = parameters.precision !== undefined ? parameters.precision : 'highp';
  9012. var maxPrecision = getMaxPrecision( precision );
  9013. if ( maxPrecision !== precision ) {
  9014. console.warn( 'THREE.WebGLRenderer:', precision, 'not supported, using', maxPrecision, 'instead.' );
  9015. precision = maxPrecision;
  9016. }
  9017. var logarithmicDepthBuffer = parameters.logarithmicDepthBuffer === true;
  9018. var maxTextures = gl.getParameter( 34930 );
  9019. var maxVertexTextures = gl.getParameter( 35660 );
  9020. var maxTextureSize = gl.getParameter( 3379 );
  9021. var maxCubemapSize = gl.getParameter( 34076 );
  9022. var maxAttributes = gl.getParameter( 34921 );
  9023. var maxVertexUniforms = gl.getParameter( 36347 );
  9024. var maxVaryings = gl.getParameter( 36348 );
  9025. var maxFragmentUniforms = gl.getParameter( 36349 );
  9026. var vertexTextures = maxVertexTextures > 0;
  9027. var floatFragmentTextures = isWebGL2 || !! extensions.get( 'OES_texture_float' );
  9028. var floatVertexTextures = vertexTextures && floatFragmentTextures;
  9029. var maxSamples = isWebGL2 ? gl.getParameter( 36183 ) : 0;
  9030. return {
  9031. isWebGL2: isWebGL2,
  9032. getMaxAnisotropy: getMaxAnisotropy,
  9033. getMaxPrecision: getMaxPrecision,
  9034. precision: precision,
  9035. logarithmicDepthBuffer: logarithmicDepthBuffer,
  9036. maxTextures: maxTextures,
  9037. maxVertexTextures: maxVertexTextures,
  9038. maxTextureSize: maxTextureSize,
  9039. maxCubemapSize: maxCubemapSize,
  9040. maxAttributes: maxAttributes,
  9041. maxVertexUniforms: maxVertexUniforms,
  9042. maxVaryings: maxVaryings,
  9043. maxFragmentUniforms: maxFragmentUniforms,
  9044. vertexTextures: vertexTextures,
  9045. floatFragmentTextures: floatFragmentTextures,
  9046. floatVertexTextures: floatVertexTextures,
  9047. maxSamples: maxSamples
  9048. };
  9049. }
  9050. /**
  9051. * @author tschw
  9052. */
  9053. function WebGLClipping() {
  9054. var scope = this,
  9055. globalState = null,
  9056. numGlobalPlanes = 0,
  9057. localClippingEnabled = false,
  9058. renderingShadows = false,
  9059. plane = new Plane(),
  9060. viewNormalMatrix = new Matrix3(),
  9061. uniform = { value: null, needsUpdate: false };
  9062. this.uniform = uniform;
  9063. this.numPlanes = 0;
  9064. this.numIntersection = 0;
  9065. this.init = function ( planes, enableLocalClipping, camera ) {
  9066. var enabled =
  9067. planes.length !== 0 ||
  9068. enableLocalClipping ||
  9069. // enable state of previous frame - the clipping code has to
  9070. // run another frame in order to reset the state:
  9071. numGlobalPlanes !== 0 ||
  9072. localClippingEnabled;
  9073. localClippingEnabled = enableLocalClipping;
  9074. globalState = projectPlanes( planes, camera, 0 );
  9075. numGlobalPlanes = planes.length;
  9076. return enabled;
  9077. };
  9078. this.beginShadows = function () {
  9079. renderingShadows = true;
  9080. projectPlanes( null );
  9081. };
  9082. this.endShadows = function () {
  9083. renderingShadows = false;
  9084. resetGlobalState();
  9085. };
  9086. this.setState = function ( planes, clipIntersection, clipShadows, camera, cache, fromCache ) {
  9087. if ( ! localClippingEnabled || planes === null || planes.length === 0 || renderingShadows && ! clipShadows ) {
  9088. // there's no local clipping
  9089. if ( renderingShadows ) {
  9090. // there's no global clipping
  9091. projectPlanes( null );
  9092. } else {
  9093. resetGlobalState();
  9094. }
  9095. } else {
  9096. var nGlobal = renderingShadows ? 0 : numGlobalPlanes,
  9097. lGlobal = nGlobal * 4,
  9098. dstArray = cache.clippingState || null;
  9099. uniform.value = dstArray; // ensure unique state
  9100. dstArray = projectPlanes( planes, camera, lGlobal, fromCache );
  9101. for ( var i = 0; i !== lGlobal; ++ i ) {
  9102. dstArray[ i ] = globalState[ i ];
  9103. }
  9104. cache.clippingState = dstArray;
  9105. this.numIntersection = clipIntersection ? this.numPlanes : 0;
  9106. this.numPlanes += nGlobal;
  9107. }
  9108. };
  9109. function resetGlobalState() {
  9110. if ( uniform.value !== globalState ) {
  9111. uniform.value = globalState;
  9112. uniform.needsUpdate = numGlobalPlanes > 0;
  9113. }
  9114. scope.numPlanes = numGlobalPlanes;
  9115. scope.numIntersection = 0;
  9116. }
  9117. function projectPlanes( planes, camera, dstOffset, skipTransform ) {
  9118. var nPlanes = planes !== null ? planes.length : 0,
  9119. dstArray = null;
  9120. if ( nPlanes !== 0 ) {
  9121. dstArray = uniform.value;
  9122. if ( skipTransform !== true || dstArray === null ) {
  9123. var flatSize = dstOffset + nPlanes * 4,
  9124. viewMatrix = camera.matrixWorldInverse;
  9125. viewNormalMatrix.getNormalMatrix( viewMatrix );
  9126. if ( dstArray === null || dstArray.length < flatSize ) {
  9127. dstArray = new Float32Array( flatSize );
  9128. }
  9129. for ( var i = 0, i4 = dstOffset; i !== nPlanes; ++ i, i4 += 4 ) {
  9130. plane.copy( planes[ i ] ).applyMatrix4( viewMatrix, viewNormalMatrix );
  9131. plane.normal.toArray( dstArray, i4 );
  9132. dstArray[ i4 + 3 ] = plane.constant;
  9133. }
  9134. }
  9135. uniform.value = dstArray;
  9136. uniform.needsUpdate = true;
  9137. }
  9138. scope.numPlanes = nPlanes;
  9139. return dstArray;
  9140. }
  9141. }
  9142. /**
  9143. * @author mrdoob / http://mrdoob.com/
  9144. */
  9145. function WebGLExtensions( gl ) {
  9146. var extensions = {};
  9147. return {
  9148. get: function ( name ) {
  9149. if ( extensions[ name ] !== undefined ) {
  9150. return extensions[ name ];
  9151. }
  9152. var extension;
  9153. switch ( name ) {
  9154. case 'WEBGL_depth_texture':
  9155. extension = gl.getExtension( 'WEBGL_depth_texture' ) || gl.getExtension( 'MOZ_WEBGL_depth_texture' ) || gl.getExtension( 'WEBKIT_WEBGL_depth_texture' );
  9156. break;
  9157. case 'EXT_texture_filter_anisotropic':
  9158. extension = gl.getExtension( 'EXT_texture_filter_anisotropic' ) || gl.getExtension( 'MOZ_EXT_texture_filter_anisotropic' ) || gl.getExtension( 'WEBKIT_EXT_texture_filter_anisotropic' );
  9159. break;
  9160. case 'WEBGL_compressed_texture_s3tc':
  9161. extension = gl.getExtension( 'WEBGL_compressed_texture_s3tc' ) || gl.getExtension( 'MOZ_WEBGL_compressed_texture_s3tc' ) || gl.getExtension( 'WEBKIT_WEBGL_compressed_texture_s3tc' );
  9162. break;
  9163. case 'WEBGL_compressed_texture_pvrtc':
  9164. extension = gl.getExtension( 'WEBGL_compressed_texture_pvrtc' ) || gl.getExtension( 'WEBKIT_WEBGL_compressed_texture_pvrtc' );
  9165. break;
  9166. default:
  9167. extension = gl.getExtension( name );
  9168. }
  9169. if ( extension === null ) {
  9170. console.warn( 'THREE.WebGLRenderer: ' + name + ' extension not supported.' );
  9171. }
  9172. extensions[ name ] = extension;
  9173. return extension;
  9174. }
  9175. };
  9176. }
  9177. /**
  9178. * @author mrdoob / http://mrdoob.com/
  9179. */
  9180. function WebGLGeometries( gl, attributes, info ) {
  9181. var geometries = {};
  9182. var wireframeAttributes = {};
  9183. function onGeometryDispose( event ) {
  9184. var geometry = event.target;
  9185. var buffergeometry = geometries[ geometry.id ];
  9186. if ( buffergeometry.index !== null ) {
  9187. attributes.remove( buffergeometry.index );
  9188. }
  9189. for ( var name in buffergeometry.attributes ) {
  9190. attributes.remove( buffergeometry.attributes[ name ] );
  9191. }
  9192. geometry.removeEventListener( 'dispose', onGeometryDispose );
  9193. delete geometries[ geometry.id ];
  9194. var attribute = wireframeAttributes[ buffergeometry.id ];
  9195. if ( attribute ) {
  9196. attributes.remove( attribute );
  9197. delete wireframeAttributes[ buffergeometry.id ];
  9198. }
  9199. //
  9200. info.memory.geometries --;
  9201. }
  9202. function get( object, geometry ) {
  9203. var buffergeometry = geometries[ geometry.id ];
  9204. if ( buffergeometry ) return buffergeometry;
  9205. geometry.addEventListener( 'dispose', onGeometryDispose );
  9206. if ( geometry.isBufferGeometry ) {
  9207. buffergeometry = geometry;
  9208. } else if ( geometry.isGeometry ) {
  9209. if ( geometry._bufferGeometry === undefined ) {
  9210. geometry._bufferGeometry = new BufferGeometry().setFromObject( object );
  9211. }
  9212. buffergeometry = geometry._bufferGeometry;
  9213. }
  9214. geometries[ geometry.id ] = buffergeometry;
  9215. info.memory.geometries ++;
  9216. return buffergeometry;
  9217. }
  9218. function update( geometry ) {
  9219. var index = geometry.index;
  9220. var geometryAttributes = geometry.attributes;
  9221. if ( index !== null ) {
  9222. attributes.update( index, 34963 );
  9223. }
  9224. for ( var name in geometryAttributes ) {
  9225. attributes.update( geometryAttributes[ name ], 34962 );
  9226. }
  9227. // morph targets
  9228. var morphAttributes = geometry.morphAttributes;
  9229. for ( var name in morphAttributes ) {
  9230. var array = morphAttributes[ name ];
  9231. for ( var i = 0, l = array.length; i < l; i ++ ) {
  9232. attributes.update( array[ i ], 34962 );
  9233. }
  9234. }
  9235. }
  9236. function getWireframeAttribute( geometry ) {
  9237. var attribute = wireframeAttributes[ geometry.id ];
  9238. if ( attribute ) return attribute;
  9239. var indices = [];
  9240. var geometryIndex = geometry.index;
  9241. var geometryAttributes = geometry.attributes;
  9242. // console.time( 'wireframe' );
  9243. if ( geometryIndex !== null ) {
  9244. var array = geometryIndex.array;
  9245. for ( var i = 0, l = array.length; i < l; i += 3 ) {
  9246. var a = array[ i + 0 ];
  9247. var b = array[ i + 1 ];
  9248. var c = array[ i + 2 ];
  9249. indices.push( a, b, b, c, c, a );
  9250. }
  9251. } else {
  9252. var array = geometryAttributes.position.array;
  9253. for ( var i = 0, l = ( array.length / 3 ) - 1; i < l; i += 3 ) {
  9254. var a = i + 0;
  9255. var b = i + 1;
  9256. var c = i + 2;
  9257. indices.push( a, b, b, c, c, a );
  9258. }
  9259. }
  9260. // console.timeEnd( 'wireframe' );
  9261. attribute = new ( arrayMax( indices ) > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute )( indices, 1 );
  9262. attributes.update( attribute, 34963 );
  9263. wireframeAttributes[ geometry.id ] = attribute;
  9264. return attribute;
  9265. }
  9266. return {
  9267. get: get,
  9268. update: update,
  9269. getWireframeAttribute: getWireframeAttribute
  9270. };
  9271. }
  9272. /**
  9273. * @author mrdoob / http://mrdoob.com/
  9274. */
  9275. function WebGLIndexedBufferRenderer( gl, extensions, info, capabilities ) {
  9276. var mode;
  9277. function setMode( value ) {
  9278. mode = value;
  9279. }
  9280. var type, bytesPerElement;
  9281. function setIndex( value ) {
  9282. type = value.type;
  9283. bytesPerElement = value.bytesPerElement;
  9284. }
  9285. function render( start, count ) {
  9286. gl.drawElements( mode, count, type, start * bytesPerElement );
  9287. info.update( count, mode );
  9288. }
  9289. function renderInstances( geometry, start, count ) {
  9290. var extension;
  9291. if ( capabilities.isWebGL2 ) {
  9292. extension = gl;
  9293. } else {
  9294. var extension = extensions.get( 'ANGLE_instanced_arrays' );
  9295. if ( extension === null ) {
  9296. console.error( 'THREE.WebGLIndexedBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  9297. return;
  9298. }
  9299. }
  9300. extension[ capabilities.isWebGL2 ? 'drawElementsInstanced' : 'drawElementsInstancedANGLE' ]( mode, count, type, start * bytesPerElement, geometry.maxInstancedCount );
  9301. info.update( count, mode, geometry.maxInstancedCount );
  9302. }
  9303. //
  9304. this.setMode = setMode;
  9305. this.setIndex = setIndex;
  9306. this.render = render;
  9307. this.renderInstances = renderInstances;
  9308. }
  9309. /**
  9310. * @author Mugen87 / https://github.com/Mugen87
  9311. */
  9312. function WebGLInfo( gl ) {
  9313. var memory = {
  9314. geometries: 0,
  9315. textures: 0
  9316. };
  9317. var render = {
  9318. frame: 0,
  9319. calls: 0,
  9320. triangles: 0,
  9321. points: 0,
  9322. lines: 0
  9323. };
  9324. function update( count, mode, instanceCount ) {
  9325. instanceCount = instanceCount || 1;
  9326. render.calls ++;
  9327. switch ( mode ) {
  9328. case 4:
  9329. render.triangles += instanceCount * ( count / 3 );
  9330. break;
  9331. case 5:
  9332. case 6:
  9333. render.triangles += instanceCount * ( count - 2 );
  9334. break;
  9335. case 1:
  9336. render.lines += instanceCount * ( count / 2 );
  9337. break;
  9338. case 3:
  9339. render.lines += instanceCount * ( count - 1 );
  9340. break;
  9341. case 2:
  9342. render.lines += instanceCount * count;
  9343. break;
  9344. case 0:
  9345. render.points += instanceCount * count;
  9346. break;
  9347. default:
  9348. console.error( 'THREE.WebGLInfo: Unknown draw mode:', mode );
  9349. break;
  9350. }
  9351. }
  9352. function reset() {
  9353. render.frame ++;
  9354. render.calls = 0;
  9355. render.triangles = 0;
  9356. render.points = 0;
  9357. render.lines = 0;
  9358. }
  9359. return {
  9360. memory: memory,
  9361. render: render,
  9362. programs: null,
  9363. autoReset: true,
  9364. reset: reset,
  9365. update: update
  9366. };
  9367. }
  9368. /**
  9369. * @author mrdoob / http://mrdoob.com/
  9370. */
  9371. function absNumericalSort( a, b ) {
  9372. return Math.abs( b[ 1 ] ) - Math.abs( a[ 1 ] );
  9373. }
  9374. function WebGLMorphtargets( gl ) {
  9375. var influencesList = {};
  9376. var morphInfluences = new Float32Array( 8 );
  9377. function update( object, geometry, material, program ) {
  9378. var objectInfluences = object.morphTargetInfluences;
  9379. var length = objectInfluences.length;
  9380. var influences = influencesList[ geometry.id ];
  9381. if ( influences === undefined ) {
  9382. // initialise list
  9383. influences = [];
  9384. for ( var i = 0; i < length; i ++ ) {
  9385. influences[ i ] = [ i, 0 ];
  9386. }
  9387. influencesList[ geometry.id ] = influences;
  9388. }
  9389. var morphTargets = material.morphTargets && geometry.morphAttributes.position;
  9390. var morphNormals = material.morphNormals && geometry.morphAttributes.normal;
  9391. // Remove current morphAttributes
  9392. for ( var i = 0; i < length; i ++ ) {
  9393. var influence = influences[ i ];
  9394. if ( influence[ 1 ] !== 0 ) {
  9395. if ( morphTargets ) geometry.removeAttribute( 'morphTarget' + i );
  9396. if ( morphNormals ) geometry.removeAttribute( 'morphNormal' + i );
  9397. }
  9398. }
  9399. // Collect influences
  9400. for ( var i = 0; i < length; i ++ ) {
  9401. var influence = influences[ i ];
  9402. influence[ 0 ] = i;
  9403. influence[ 1 ] = objectInfluences[ i ];
  9404. }
  9405. influences.sort( absNumericalSort );
  9406. // Add morphAttributes
  9407. for ( var i = 0; i < 8; i ++ ) {
  9408. var influence = influences[ i ];
  9409. if ( influence ) {
  9410. var index = influence[ 0 ];
  9411. var value = influence[ 1 ];
  9412. if ( value ) {
  9413. if ( morphTargets ) geometry.addAttribute( 'morphTarget' + i, morphTargets[ index ] );
  9414. if ( morphNormals ) geometry.addAttribute( 'morphNormal' + i, morphNormals[ index ] );
  9415. morphInfluences[ i ] = value;
  9416. continue;
  9417. }
  9418. }
  9419. morphInfluences[ i ] = 0;
  9420. }
  9421. program.getUniforms().setValue( gl, 'morphTargetInfluences', morphInfluences );
  9422. }
  9423. return {
  9424. update: update
  9425. };
  9426. }
  9427. /**
  9428. * @author mrdoob / http://mrdoob.com/
  9429. */
  9430. function WebGLObjects( geometries, info ) {
  9431. var updateList = {};
  9432. function update( object ) {
  9433. var frame = info.render.frame;
  9434. var geometry = object.geometry;
  9435. var buffergeometry = geometries.get( object, geometry );
  9436. // Update once per frame
  9437. if ( updateList[ buffergeometry.id ] !== frame ) {
  9438. if ( geometry.isGeometry ) {
  9439. buffergeometry.updateFromObject( object );
  9440. }
  9441. geometries.update( buffergeometry );
  9442. updateList[ buffergeometry.id ] = frame;
  9443. }
  9444. return buffergeometry;
  9445. }
  9446. function dispose() {
  9447. updateList = {};
  9448. }
  9449. return {
  9450. update: update,
  9451. dispose: dispose
  9452. };
  9453. }
  9454. /**
  9455. * @author mrdoob / http://mrdoob.com/
  9456. */
  9457. function CubeTexture( images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding ) {
  9458. images = images !== undefined ? images : [];
  9459. mapping = mapping !== undefined ? mapping : CubeReflectionMapping;
  9460. format = format !== undefined ? format : RGBFormat;
  9461. Texture.call( this, images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding );
  9462. this.flipY = false;
  9463. }
  9464. CubeTexture.prototype = Object.create( Texture.prototype );
  9465. CubeTexture.prototype.constructor = CubeTexture;
  9466. CubeTexture.prototype.isCubeTexture = true;
  9467. Object.defineProperty( CubeTexture.prototype, 'images', {
  9468. get: function () {
  9469. return this.image;
  9470. },
  9471. set: function ( value ) {
  9472. this.image = value;
  9473. }
  9474. } );
  9475. /**
  9476. * @author Takahiro https://github.com/takahirox
  9477. */
  9478. function DataTexture2DArray( data, width, height, depth ) {
  9479. Texture.call( this, null );
  9480. this.image = { data: data, width: width, height: height, depth: depth };
  9481. this.magFilter = NearestFilter;
  9482. this.minFilter = NearestFilter;
  9483. this.wrapR = ClampToEdgeWrapping;
  9484. this.generateMipmaps = false;
  9485. this.flipY = false;
  9486. }
  9487. DataTexture2DArray.prototype = Object.create( Texture.prototype );
  9488. DataTexture2DArray.prototype.constructor = DataTexture2DArray;
  9489. DataTexture2DArray.prototype.isDataTexture2DArray = true;
  9490. /**
  9491. * @author Artur Trzesiok
  9492. */
  9493. function DataTexture3D( data, width, height, depth ) {
  9494. // We're going to add .setXXX() methods for setting properties later.
  9495. // Users can still set in DataTexture3D directly.
  9496. //
  9497. // var texture = new THREE.DataTexture3D( data, width, height, depth );
  9498. // texture.anisotropy = 16;
  9499. //
  9500. // See #14839
  9501. Texture.call( this, null );
  9502. this.image = { data: data, width: width, height: height, depth: depth };
  9503. this.magFilter = NearestFilter;
  9504. this.minFilter = NearestFilter;
  9505. this.wrapR = ClampToEdgeWrapping;
  9506. this.generateMipmaps = false;
  9507. this.flipY = false;
  9508. }
  9509. DataTexture3D.prototype = Object.create( Texture.prototype );
  9510. DataTexture3D.prototype.constructor = DataTexture3D;
  9511. DataTexture3D.prototype.isDataTexture3D = true;
  9512. /**
  9513. * @author tschw
  9514. * @author Mugen87 / https://github.com/Mugen87
  9515. * @author mrdoob / http://mrdoob.com/
  9516. *
  9517. * Uniforms of a program.
  9518. * Those form a tree structure with a special top-level container for the root,
  9519. * which you get by calling 'new WebGLUniforms( gl, program )'.
  9520. *
  9521. *
  9522. * Properties of inner nodes including the top-level container:
  9523. *
  9524. * .seq - array of nested uniforms
  9525. * .map - nested uniforms by name
  9526. *
  9527. *
  9528. * Methods of all nodes except the top-level container:
  9529. *
  9530. * .setValue( gl, value, [textures] )
  9531. *
  9532. * uploads a uniform value(s)
  9533. * the 'textures' parameter is needed for sampler uniforms
  9534. *
  9535. *
  9536. * Static methods of the top-level container (textures factorizations):
  9537. *
  9538. * .upload( gl, seq, values, textures )
  9539. *
  9540. * sets uniforms in 'seq' to 'values[id].value'
  9541. *
  9542. * .seqWithValue( seq, values ) : filteredSeq
  9543. *
  9544. * filters 'seq' entries with corresponding entry in values
  9545. *
  9546. *
  9547. * Methods of the top-level container (textures factorizations):
  9548. *
  9549. * .setValue( gl, name, value, textures )
  9550. *
  9551. * sets uniform with name 'name' to 'value'
  9552. *
  9553. * .setOptional( gl, obj, prop )
  9554. *
  9555. * like .set for an optional property of the object
  9556. *
  9557. */
  9558. var emptyTexture = new Texture();
  9559. var emptyTexture2dArray = new DataTexture2DArray();
  9560. var emptyTexture3d = new DataTexture3D();
  9561. var emptyCubeTexture = new CubeTexture();
  9562. // --- Utilities ---
  9563. // Array Caches (provide typed arrays for temporary by size)
  9564. var arrayCacheF32 = [];
  9565. var arrayCacheI32 = [];
  9566. // Float32Array caches used for uploading Matrix uniforms
  9567. var mat4array = new Float32Array( 16 );
  9568. var mat3array = new Float32Array( 9 );
  9569. var mat2array = new Float32Array( 4 );
  9570. // Flattening for arrays of vectors and matrices
  9571. function flatten( array, nBlocks, blockSize ) {
  9572. var firstElem = array[ 0 ];
  9573. if ( firstElem <= 0 || firstElem > 0 ) return array;
  9574. // unoptimized: ! isNaN( firstElem )
  9575. // see http://jacksondunstan.com/articles/983
  9576. var n = nBlocks * blockSize,
  9577. r = arrayCacheF32[ n ];
  9578. if ( r === undefined ) {
  9579. r = new Float32Array( n );
  9580. arrayCacheF32[ n ] = r;
  9581. }
  9582. if ( nBlocks !== 0 ) {
  9583. firstElem.toArray( r, 0 );
  9584. for ( var i = 1, offset = 0; i !== nBlocks; ++ i ) {
  9585. offset += blockSize;
  9586. array[ i ].toArray( r, offset );
  9587. }
  9588. }
  9589. return r;
  9590. }
  9591. function arraysEqual( a, b ) {
  9592. if ( a.length !== b.length ) return false;
  9593. for ( var i = 0, l = a.length; i < l; i ++ ) {
  9594. if ( a[ i ] !== b[ i ] ) return false;
  9595. }
  9596. return true;
  9597. }
  9598. function copyArray( a, b ) {
  9599. for ( var i = 0, l = b.length; i < l; i ++ ) {
  9600. a[ i ] = b[ i ];
  9601. }
  9602. }
  9603. // Texture unit allocation
  9604. function allocTexUnits( textures, n ) {
  9605. var r = arrayCacheI32[ n ];
  9606. if ( r === undefined ) {
  9607. r = new Int32Array( n );
  9608. arrayCacheI32[ n ] = r;
  9609. }
  9610. for ( var i = 0; i !== n; ++ i )
  9611. r[ i ] = textures.allocateTextureUnit();
  9612. return r;
  9613. }
  9614. // --- Setters ---
  9615. // Note: Defining these methods externally, because they come in a bunch
  9616. // and this way their names minify.
  9617. // Single scalar
  9618. function setValueV1f( gl, v ) {
  9619. var cache = this.cache;
  9620. if ( cache[ 0 ] === v ) return;
  9621. gl.uniform1f( this.addr, v );
  9622. cache[ 0 ] = v;
  9623. }
  9624. // Single float vector (from flat array or THREE.VectorN)
  9625. function setValueV2f( gl, v ) {
  9626. var cache = this.cache;
  9627. if ( v.x !== undefined ) {
  9628. if ( cache[ 0 ] !== v.x || cache[ 1 ] !== v.y ) {
  9629. gl.uniform2f( this.addr, v.x, v.y );
  9630. cache[ 0 ] = v.x;
  9631. cache[ 1 ] = v.y;
  9632. }
  9633. } else {
  9634. if ( arraysEqual( cache, v ) ) return;
  9635. gl.uniform2fv( this.addr, v );
  9636. copyArray( cache, v );
  9637. }
  9638. }
  9639. function setValueV3f( gl, v ) {
  9640. var cache = this.cache;
  9641. if ( v.x !== undefined ) {
  9642. if ( cache[ 0 ] !== v.x || cache[ 1 ] !== v.y || cache[ 2 ] !== v.z ) {
  9643. gl.uniform3f( this.addr, v.x, v.y, v.z );
  9644. cache[ 0 ] = v.x;
  9645. cache[ 1 ] = v.y;
  9646. cache[ 2 ] = v.z;
  9647. }
  9648. } else if ( v.r !== undefined ) {
  9649. if ( cache[ 0 ] !== v.r || cache[ 1 ] !== v.g || cache[ 2 ] !== v.b ) {
  9650. gl.uniform3f( this.addr, v.r, v.g, v.b );
  9651. cache[ 0 ] = v.r;
  9652. cache[ 1 ] = v.g;
  9653. cache[ 2 ] = v.b;
  9654. }
  9655. } else {
  9656. if ( arraysEqual( cache, v ) ) return;
  9657. gl.uniform3fv( this.addr, v );
  9658. copyArray( cache, v );
  9659. }
  9660. }
  9661. function setValueV4f( gl, v ) {
  9662. var cache = this.cache;
  9663. if ( v.x !== undefined ) {
  9664. if ( cache[ 0 ] !== v.x || cache[ 1 ] !== v.y || cache[ 2 ] !== v.z || cache[ 3 ] !== v.w ) {
  9665. gl.uniform4f( this.addr, v.x, v.y, v.z, v.w );
  9666. cache[ 0 ] = v.x;
  9667. cache[ 1 ] = v.y;
  9668. cache[ 2 ] = v.z;
  9669. cache[ 3 ] = v.w;
  9670. }
  9671. } else {
  9672. if ( arraysEqual( cache, v ) ) return;
  9673. gl.uniform4fv( this.addr, v );
  9674. copyArray( cache, v );
  9675. }
  9676. }
  9677. // Single matrix (from flat array or MatrixN)
  9678. function setValueM2( gl, v ) {
  9679. var cache = this.cache;
  9680. var elements = v.elements;
  9681. if ( elements === undefined ) {
  9682. if ( arraysEqual( cache, v ) ) return;
  9683. gl.uniformMatrix2fv( this.addr, false, v );
  9684. copyArray( cache, v );
  9685. } else {
  9686. if ( arraysEqual( cache, elements ) ) return;
  9687. mat2array.set( elements );
  9688. gl.uniformMatrix2fv( this.addr, false, mat2array );
  9689. copyArray( cache, elements );
  9690. }
  9691. }
  9692. function setValueM3( gl, v ) {
  9693. var cache = this.cache;
  9694. var elements = v.elements;
  9695. if ( elements === undefined ) {
  9696. if ( arraysEqual( cache, v ) ) return;
  9697. gl.uniformMatrix3fv( this.addr, false, v );
  9698. copyArray( cache, v );
  9699. } else {
  9700. if ( arraysEqual( cache, elements ) ) return;
  9701. mat3array.set( elements );
  9702. gl.uniformMatrix3fv( this.addr, false, mat3array );
  9703. copyArray( cache, elements );
  9704. }
  9705. }
  9706. function setValueM4( gl, v ) {
  9707. var cache = this.cache;
  9708. var elements = v.elements;
  9709. if ( elements === undefined ) {
  9710. if ( arraysEqual( cache, v ) ) return;
  9711. gl.uniformMatrix4fv( this.addr, false, v );
  9712. copyArray( cache, v );
  9713. } else {
  9714. if ( arraysEqual( cache, elements ) ) return;
  9715. mat4array.set( elements );
  9716. gl.uniformMatrix4fv( this.addr, false, mat4array );
  9717. copyArray( cache, elements );
  9718. }
  9719. }
  9720. // Single texture (2D / Cube)
  9721. function setValueT1( gl, v, textures ) {
  9722. var cache = this.cache;
  9723. var unit = textures.allocateTextureUnit();
  9724. if ( cache[ 0 ] !== unit ) {
  9725. gl.uniform1i( this.addr, unit );
  9726. cache[ 0 ] = unit;
  9727. }
  9728. textures.safeSetTexture2D( v || emptyTexture, unit );
  9729. }
  9730. function setValueT2DArray1( gl, v, textures ) {
  9731. var cache = this.cache;
  9732. var unit = textures.allocateTextureUnit();
  9733. if ( cache[ 0 ] !== unit ) {
  9734. gl.uniform1i( this.addr, unit );
  9735. cache[ 0 ] = unit;
  9736. }
  9737. textures.setTexture2DArray( v || emptyTexture2dArray, unit );
  9738. }
  9739. function setValueT3D1( gl, v, textures ) {
  9740. var cache = this.cache;
  9741. var unit = textures.allocateTextureUnit();
  9742. if ( cache[ 0 ] !== unit ) {
  9743. gl.uniform1i( this.addr, unit );
  9744. cache[ 0 ] = unit;
  9745. }
  9746. textures.setTexture3D( v || emptyTexture3d, unit );
  9747. }
  9748. function setValueT6( gl, v, textures ) {
  9749. var cache = this.cache;
  9750. var unit = textures.allocateTextureUnit();
  9751. if ( cache[ 0 ] !== unit ) {
  9752. gl.uniform1i( this.addr, unit );
  9753. cache[ 0 ] = unit;
  9754. }
  9755. textures.safeSetTextureCube( v || emptyCubeTexture, unit );
  9756. }
  9757. // Integer / Boolean vectors or arrays thereof (always flat arrays)
  9758. function setValueV1i( gl, v ) {
  9759. var cache = this.cache;
  9760. if ( cache[ 0 ] === v ) return;
  9761. gl.uniform1i( this.addr, v );
  9762. cache[ 0 ] = v;
  9763. }
  9764. function setValueV2i( gl, v ) {
  9765. var cache = this.cache;
  9766. if ( arraysEqual( cache, v ) ) return;
  9767. gl.uniform2iv( this.addr, v );
  9768. copyArray( cache, v );
  9769. }
  9770. function setValueV3i( gl, v ) {
  9771. var cache = this.cache;
  9772. if ( arraysEqual( cache, v ) ) return;
  9773. gl.uniform3iv( this.addr, v );
  9774. copyArray( cache, v );
  9775. }
  9776. function setValueV4i( gl, v ) {
  9777. var cache = this.cache;
  9778. if ( arraysEqual( cache, v ) ) return;
  9779. gl.uniform4iv( this.addr, v );
  9780. copyArray( cache, v );
  9781. }
  9782. // Helper to pick the right setter for the singular case
  9783. function getSingularSetter( type ) {
  9784. switch ( type ) {
  9785. case 0x1406: return setValueV1f; // FLOAT
  9786. case 0x8b50: return setValueV2f; // _VEC2
  9787. case 0x8b51: return setValueV3f; // _VEC3
  9788. case 0x8b52: return setValueV4f; // _VEC4
  9789. case 0x8b5a: return setValueM2; // _MAT2
  9790. case 0x8b5b: return setValueM3; // _MAT3
  9791. case 0x8b5c: return setValueM4; // _MAT4
  9792. case 0x8b5e: case 0x8d66: return setValueT1; // SAMPLER_2D, SAMPLER_EXTERNAL_OES
  9793. case 0x8b5f: return setValueT3D1; // SAMPLER_3D
  9794. case 0x8b60: return setValueT6; // SAMPLER_CUBE
  9795. case 0x8DC1: return setValueT2DArray1; // SAMPLER_2D_ARRAY
  9796. case 0x1404: case 0x8b56: return setValueV1i; // INT, BOOL
  9797. case 0x8b53: case 0x8b57: return setValueV2i; // _VEC2
  9798. case 0x8b54: case 0x8b58: return setValueV3i; // _VEC3
  9799. case 0x8b55: case 0x8b59: return setValueV4i; // _VEC4
  9800. }
  9801. }
  9802. // Array of scalars
  9803. function setValueV1fArray( gl, v ) {
  9804. gl.uniform1fv( this.addr, v );
  9805. }
  9806. // Integer / Boolean vectors or arrays thereof (always flat arrays)
  9807. function setValueV1iArray( gl, v ) {
  9808. gl.uniform1iv( this.addr, v );
  9809. }
  9810. function setValueV2iArray( gl, v ) {
  9811. gl.uniform2iv( this.addr, v );
  9812. }
  9813. function setValueV3iArray( gl, v ) {
  9814. gl.uniform3iv( this.addr, v );
  9815. }
  9816. function setValueV4iArray( gl, v ) {
  9817. gl.uniform4iv( this.addr, v );
  9818. }
  9819. // Array of vectors (flat or from THREE classes)
  9820. function setValueV2fArray( gl, v ) {
  9821. var data = flatten( v, this.size, 2 );
  9822. gl.uniform2fv( this.addr, data );
  9823. }
  9824. function setValueV3fArray( gl, v ) {
  9825. var data = flatten( v, this.size, 3 );
  9826. gl.uniform3fv( this.addr, data );
  9827. }
  9828. function setValueV4fArray( gl, v ) {
  9829. var data = flatten( v, this.size, 4 );
  9830. gl.uniform4fv( this.addr, data );
  9831. }
  9832. // Array of matrices (flat or from THREE clases)
  9833. function setValueM2Array( gl, v ) {
  9834. var data = flatten( v, this.size, 4 );
  9835. gl.uniformMatrix2fv( this.addr, false, data );
  9836. }
  9837. function setValueM3Array( gl, v ) {
  9838. var data = flatten( v, this.size, 9 );
  9839. gl.uniformMatrix3fv( this.addr, false, data );
  9840. }
  9841. function setValueM4Array( gl, v ) {
  9842. var data = flatten( v, this.size, 16 );
  9843. gl.uniformMatrix4fv( this.addr, false, data );
  9844. }
  9845. // Array of textures (2D / Cube)
  9846. function setValueT1Array( gl, v, textures ) {
  9847. var n = v.length;
  9848. var units = allocTexUnits( textures, n );
  9849. gl.uniform1iv( this.addr, units );
  9850. for ( var i = 0; i !== n; ++ i ) {
  9851. textures.safeSetTexture2D( v[ i ] || emptyTexture, units[ i ] );
  9852. }
  9853. }
  9854. function setValueT6Array( gl, v, textures ) {
  9855. var n = v.length;
  9856. var units = allocTexUnits( textures, n );
  9857. gl.uniform1iv( this.addr, units );
  9858. for ( var i = 0; i !== n; ++ i ) {
  9859. textures.safeSetTextureCube( v[ i ] || emptyCubeTexture, units[ i ] );
  9860. }
  9861. }
  9862. // Helper to pick the right setter for a pure (bottom-level) array
  9863. function getPureArraySetter( type ) {
  9864. switch ( type ) {
  9865. case 0x1406: return setValueV1fArray; // FLOAT
  9866. case 0x8b50: return setValueV2fArray; // _VEC2
  9867. case 0x8b51: return setValueV3fArray; // _VEC3
  9868. case 0x8b52: return setValueV4fArray; // _VEC4
  9869. case 0x8b5a: return setValueM2Array; // _MAT2
  9870. case 0x8b5b: return setValueM3Array; // _MAT3
  9871. case 0x8b5c: return setValueM4Array; // _MAT4
  9872. case 0x8b5e: return setValueT1Array; // SAMPLER_2D
  9873. case 0x8b60: return setValueT6Array; // SAMPLER_CUBE
  9874. case 0x1404: case 0x8b56: return setValueV1iArray; // INT, BOOL
  9875. case 0x8b53: case 0x8b57: return setValueV2iArray; // _VEC2
  9876. case 0x8b54: case 0x8b58: return setValueV3iArray; // _VEC3
  9877. case 0x8b55: case 0x8b59: return setValueV4iArray; // _VEC4
  9878. }
  9879. }
  9880. // --- Uniform Classes ---
  9881. function SingleUniform( id, activeInfo, addr ) {
  9882. this.id = id;
  9883. this.addr = addr;
  9884. this.cache = [];
  9885. this.setValue = getSingularSetter( activeInfo.type );
  9886. // this.path = activeInfo.name; // DEBUG
  9887. }
  9888. function PureArrayUniform( id, activeInfo, addr ) {
  9889. this.id = id;
  9890. this.addr = addr;
  9891. this.cache = [];
  9892. this.size = activeInfo.size;
  9893. this.setValue = getPureArraySetter( activeInfo.type );
  9894. // this.path = activeInfo.name; // DEBUG
  9895. }
  9896. PureArrayUniform.prototype.updateCache = function ( data ) {
  9897. var cache = this.cache;
  9898. if ( data instanceof Float32Array && cache.length !== data.length ) {
  9899. this.cache = new Float32Array( data.length );
  9900. }
  9901. copyArray( cache, data );
  9902. };
  9903. function StructuredUniform( id ) {
  9904. this.id = id;
  9905. this.seq = [];
  9906. this.map = {};
  9907. }
  9908. StructuredUniform.prototype.setValue = function ( gl, value, textures ) {
  9909. var seq = this.seq;
  9910. for ( var i = 0, n = seq.length; i !== n; ++ i ) {
  9911. var u = seq[ i ];
  9912. u.setValue( gl, value[ u.id ], textures );
  9913. }
  9914. };
  9915. // --- Top-level ---
  9916. // Parser - builds up the property tree from the path strings
  9917. var RePathPart = /([\w\d_]+)(\])?(\[|\.)?/g;
  9918. // extracts
  9919. // - the identifier (member name or array index)
  9920. // - followed by an optional right bracket (found when array index)
  9921. // - followed by an optional left bracket or dot (type of subscript)
  9922. //
  9923. // Note: These portions can be read in a non-overlapping fashion and
  9924. // allow straightforward parsing of the hierarchy that WebGL encodes
  9925. // in the uniform names.
  9926. function addUniform( container, uniformObject ) {
  9927. container.seq.push( uniformObject );
  9928. container.map[ uniformObject.id ] = uniformObject;
  9929. }
  9930. function parseUniform( activeInfo, addr, container ) {
  9931. var path = activeInfo.name,
  9932. pathLength = path.length;
  9933. // reset RegExp object, because of the early exit of a previous run
  9934. RePathPart.lastIndex = 0;
  9935. while ( true ) {
  9936. var match = RePathPart.exec( path ),
  9937. matchEnd = RePathPart.lastIndex,
  9938. id = match[ 1 ],
  9939. idIsIndex = match[ 2 ] === ']',
  9940. subscript = match[ 3 ];
  9941. if ( idIsIndex ) id = id | 0; // convert to integer
  9942. if ( subscript === undefined || subscript === '[' && matchEnd + 2 === pathLength ) {
  9943. // bare name or "pure" bottom-level array "[0]" suffix
  9944. addUniform( container, subscript === undefined ?
  9945. new SingleUniform( id, activeInfo, addr ) :
  9946. new PureArrayUniform( id, activeInfo, addr ) );
  9947. break;
  9948. } else {
  9949. // step into inner node / create it in case it doesn't exist
  9950. var map = container.map, next = map[ id ];
  9951. if ( next === undefined ) {
  9952. next = new StructuredUniform( id );
  9953. addUniform( container, next );
  9954. }
  9955. container = next;
  9956. }
  9957. }
  9958. }
  9959. // Root Container
  9960. function WebGLUniforms( gl, program ) {
  9961. this.seq = [];
  9962. this.map = {};
  9963. var n = gl.getProgramParameter( program, 35718 );
  9964. for ( var i = 0; i < n; ++ i ) {
  9965. var info = gl.getActiveUniform( program, i ),
  9966. addr = gl.getUniformLocation( program, info.name );
  9967. parseUniform( info, addr, this );
  9968. }
  9969. }
  9970. WebGLUniforms.prototype.setValue = function ( gl, name, value, textures ) {
  9971. var u = this.map[ name ];
  9972. if ( u !== undefined ) u.setValue( gl, value, textures );
  9973. };
  9974. WebGLUniforms.prototype.setOptional = function ( gl, object, name ) {
  9975. var v = object[ name ];
  9976. if ( v !== undefined ) this.setValue( gl, name, v );
  9977. };
  9978. // Static interface
  9979. WebGLUniforms.upload = function ( gl, seq, values, textures ) {
  9980. for ( var i = 0, n = seq.length; i !== n; ++ i ) {
  9981. var u = seq[ i ],
  9982. v = values[ u.id ];
  9983. if ( v.needsUpdate !== false ) {
  9984. // note: always updating when .needsUpdate is undefined
  9985. u.setValue( gl, v.value, textures );
  9986. }
  9987. }
  9988. };
  9989. WebGLUniforms.seqWithValue = function ( seq, values ) {
  9990. var r = [];
  9991. for ( var i = 0, n = seq.length; i !== n; ++ i ) {
  9992. var u = seq[ i ];
  9993. if ( u.id in values ) r.push( u );
  9994. }
  9995. return r;
  9996. };
  9997. /**
  9998. * @author mrdoob / http://mrdoob.com/
  9999. */
  10000. function addLineNumbers( string ) {
  10001. var lines = string.split( '\n' );
  10002. for ( var i = 0; i < lines.length; i ++ ) {
  10003. lines[ i ] = ( i + 1 ) + ': ' + lines[ i ];
  10004. }
  10005. return lines.join( '\n' );
  10006. }
  10007. function WebGLShader( gl, type, string, debug ) {
  10008. var shader = gl.createShader( type );
  10009. gl.shaderSource( shader, string );
  10010. gl.compileShader( shader );
  10011. if ( debug === true ) {
  10012. if ( gl.getShaderParameter( shader, 35713 ) === false ) {
  10013. console.error( 'THREE.WebGLShader: Shader couldn\'t compile.' );
  10014. }
  10015. if ( gl.getShaderInfoLog( shader ) !== '' ) {
  10016. console.warn( 'THREE.WebGLShader: gl.getShaderInfoLog()', type === 35633 ? 'vertex' : 'fragment', gl.getShaderInfoLog( shader ), addLineNumbers( string ) );
  10017. }
  10018. }
  10019. // --enable-privileged-webgl-extension
  10020. // console.log( type, gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( shader ) );
  10021. return shader;
  10022. }
  10023. /**
  10024. * @author mrdoob / http://mrdoob.com/
  10025. */
  10026. var programIdCount = 0;
  10027. function getEncodingComponents( encoding ) {
  10028. switch ( encoding ) {
  10029. case LinearEncoding:
  10030. return [ 'Linear', '( value )' ];
  10031. case sRGBEncoding:
  10032. return [ 'sRGB', '( value )' ];
  10033. case RGBEEncoding:
  10034. return [ 'RGBE', '( value )' ];
  10035. case RGBM7Encoding:
  10036. return [ 'RGBM', '( value, 7.0 )' ];
  10037. case RGBM16Encoding:
  10038. return [ 'RGBM', '( value, 16.0 )' ];
  10039. case RGBDEncoding:
  10040. return [ 'RGBD', '( value, 256.0 )' ];
  10041. case GammaEncoding:
  10042. return [ 'Gamma', '( value, float( GAMMA_FACTOR ) )' ];
  10043. default:
  10044. throw new Error( 'unsupported encoding: ' + encoding );
  10045. }
  10046. }
  10047. function getTexelDecodingFunction( functionName, encoding ) {
  10048. var components = getEncodingComponents( encoding );
  10049. return 'vec4 ' + functionName + '( vec4 value ) { return ' + components[ 0 ] + 'ToLinear' + components[ 1 ] + '; }';
  10050. }
  10051. function getTexelEncodingFunction( functionName, encoding ) {
  10052. var components = getEncodingComponents( encoding );
  10053. return 'vec4 ' + functionName + '( vec4 value ) { return LinearTo' + components[ 0 ] + components[ 1 ] + '; }';
  10054. }
  10055. function getToneMappingFunction( functionName, toneMapping ) {
  10056. var toneMappingName;
  10057. switch ( toneMapping ) {
  10058. case LinearToneMapping:
  10059. toneMappingName = 'Linear';
  10060. break;
  10061. case ReinhardToneMapping:
  10062. toneMappingName = 'Reinhard';
  10063. break;
  10064. case Uncharted2ToneMapping:
  10065. toneMappingName = 'Uncharted2';
  10066. break;
  10067. case CineonToneMapping:
  10068. toneMappingName = 'OptimizedCineon';
  10069. break;
  10070. case ACESFilmicToneMapping:
  10071. toneMappingName = 'ACESFilmic';
  10072. break;
  10073. default:
  10074. throw new Error( 'unsupported toneMapping: ' + toneMapping );
  10075. }
  10076. return 'vec3 ' + functionName + '( vec3 color ) { return ' + toneMappingName + 'ToneMapping( color ); }';
  10077. }
  10078. function generateExtensions( extensions, parameters, rendererExtensions ) {
  10079. extensions = extensions || {};
  10080. var chunks = [
  10081. ( extensions.derivatives || parameters.envMapCubeUV || parameters.bumpMap || ( parameters.normalMap && ! parameters.objectSpaceNormalMap ) || parameters.flatShading ) ? '#extension GL_OES_standard_derivatives : enable' : '',
  10082. ( extensions.fragDepth || parameters.logarithmicDepthBuffer ) && rendererExtensions.get( 'EXT_frag_depth' ) ? '#extension GL_EXT_frag_depth : enable' : '',
  10083. ( extensions.drawBuffers ) && rendererExtensions.get( 'WEBGL_draw_buffers' ) ? '#extension GL_EXT_draw_buffers : require' : '',
  10084. ( extensions.shaderTextureLOD || parameters.envMap ) && rendererExtensions.get( 'EXT_shader_texture_lod' ) ? '#extension GL_EXT_shader_texture_lod : enable' : ''
  10085. ];
  10086. return chunks.filter( filterEmptyLine ).join( '\n' );
  10087. }
  10088. function generateDefines( defines ) {
  10089. var chunks = [];
  10090. for ( var name in defines ) {
  10091. var value = defines[ name ];
  10092. if ( value === false ) continue;
  10093. chunks.push( '#define ' + name + ' ' + value );
  10094. }
  10095. return chunks.join( '\n' );
  10096. }
  10097. function fetchAttributeLocations( gl, program ) {
  10098. var attributes = {};
  10099. var n = gl.getProgramParameter( program, 35721 );
  10100. for ( var i = 0; i < n; i ++ ) {
  10101. var info = gl.getActiveAttrib( program, i );
  10102. var name = info.name;
  10103. // console.log( 'THREE.WebGLProgram: ACTIVE VERTEX ATTRIBUTE:', name, i );
  10104. attributes[ name ] = gl.getAttribLocation( program, name );
  10105. }
  10106. return attributes;
  10107. }
  10108. function filterEmptyLine( string ) {
  10109. return string !== '';
  10110. }
  10111. function replaceLightNums( string, parameters ) {
  10112. return string
  10113. .replace( /NUM_DIR_LIGHTS/g, parameters.numDirLights )
  10114. .replace( /NUM_SPOT_LIGHTS/g, parameters.numSpotLights )
  10115. .replace( /NUM_RECT_AREA_LIGHTS/g, parameters.numRectAreaLights )
  10116. .replace( /NUM_POINT_LIGHTS/g, parameters.numPointLights )
  10117. .replace( /NUM_HEMI_LIGHTS/g, parameters.numHemiLights );
  10118. }
  10119. function replaceClippingPlaneNums( string, parameters ) {
  10120. return string
  10121. .replace( /NUM_CLIPPING_PLANES/g, parameters.numClippingPlanes )
  10122. .replace( /UNION_CLIPPING_PLANES/g, ( parameters.numClippingPlanes - parameters.numClipIntersection ) );
  10123. }
  10124. function parseIncludes( string ) {
  10125. var pattern = /^[ \t]*#include +<([\w\d./]+)>/gm;
  10126. function replace( match, include ) {
  10127. var replace = ShaderChunk[ include ];
  10128. if ( replace === undefined ) {
  10129. throw new Error( 'Can not resolve #include <' + include + '>' );
  10130. }
  10131. return parseIncludes( replace );
  10132. }
  10133. return string.replace( pattern, replace );
  10134. }
  10135. function unrollLoops( string ) {
  10136. var pattern = /#pragma unroll_loop[\s]+?for \( int i \= (\d+)\; i < (\d+)\; i \+\+ \) \{([\s\S]+?)(?=\})\}/g;
  10137. function replace( match, start, end, snippet ) {
  10138. var unroll = '';
  10139. for ( var i = parseInt( start ); i < parseInt( end ); i ++ ) {
  10140. unroll += snippet.replace( /\[ i \]/g, '[ ' + i + ' ]' );
  10141. }
  10142. return unroll;
  10143. }
  10144. return string.replace( pattern, replace );
  10145. }
  10146. function WebGLProgram( renderer, extensions, code, material, shader, parameters, capabilities, textures ) {
  10147. var gl = renderer.context;
  10148. var defines = material.defines;
  10149. var vertexShader = shader.vertexShader;
  10150. var fragmentShader = shader.fragmentShader;
  10151. var shadowMapTypeDefine = 'SHADOWMAP_TYPE_BASIC';
  10152. if ( parameters.shadowMapType === PCFShadowMap ) {
  10153. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF';
  10154. } else if ( parameters.shadowMapType === PCFSoftShadowMap ) {
  10155. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF_SOFT';
  10156. }
  10157. var envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  10158. var envMapModeDefine = 'ENVMAP_MODE_REFLECTION';
  10159. var envMapBlendingDefine = 'ENVMAP_BLENDING_MULTIPLY';
  10160. if ( parameters.envMap ) {
  10161. switch ( material.envMap.mapping ) {
  10162. case CubeReflectionMapping:
  10163. case CubeRefractionMapping:
  10164. envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  10165. break;
  10166. case CubeUVReflectionMapping:
  10167. case CubeUVRefractionMapping:
  10168. envMapTypeDefine = 'ENVMAP_TYPE_CUBE_UV';
  10169. break;
  10170. case EquirectangularReflectionMapping:
  10171. case EquirectangularRefractionMapping:
  10172. envMapTypeDefine = 'ENVMAP_TYPE_EQUIREC';
  10173. break;
  10174. case SphericalReflectionMapping:
  10175. envMapTypeDefine = 'ENVMAP_TYPE_SPHERE';
  10176. break;
  10177. }
  10178. switch ( material.envMap.mapping ) {
  10179. case CubeRefractionMapping:
  10180. case EquirectangularRefractionMapping:
  10181. envMapModeDefine = 'ENVMAP_MODE_REFRACTION';
  10182. break;
  10183. }
  10184. switch ( material.combine ) {
  10185. case MultiplyOperation:
  10186. envMapBlendingDefine = 'ENVMAP_BLENDING_MULTIPLY';
  10187. break;
  10188. case MixOperation:
  10189. envMapBlendingDefine = 'ENVMAP_BLENDING_MIX';
  10190. break;
  10191. case AddOperation:
  10192. envMapBlendingDefine = 'ENVMAP_BLENDING_ADD';
  10193. break;
  10194. }
  10195. }
  10196. var gammaFactorDefine = ( renderer.gammaFactor > 0 ) ? renderer.gammaFactor : 1.0;
  10197. // console.log( 'building new program ' );
  10198. //
  10199. var customExtensions = capabilities.isWebGL2 ? '' : generateExtensions( material.extensions, parameters, extensions );
  10200. var customDefines = generateDefines( defines );
  10201. //
  10202. var program = gl.createProgram();
  10203. var prefixVertex, prefixFragment;
  10204. if ( material.isRawShaderMaterial ) {
  10205. prefixVertex = [
  10206. customDefines
  10207. ].filter( filterEmptyLine ).join( '\n' );
  10208. if ( prefixVertex.length > 0 ) {
  10209. prefixVertex += '\n';
  10210. }
  10211. prefixFragment = [
  10212. customExtensions,
  10213. customDefines
  10214. ].filter( filterEmptyLine ).join( '\n' );
  10215. if ( prefixFragment.length > 0 ) {
  10216. prefixFragment += '\n';
  10217. }
  10218. } else {
  10219. prefixVertex = [
  10220. 'precision ' + parameters.precision + ' float;',
  10221. 'precision ' + parameters.precision + ' int;',
  10222. '#define SHADER_NAME ' + shader.name,
  10223. customDefines,
  10224. parameters.supportsVertexTextures ? '#define VERTEX_TEXTURES' : '',
  10225. '#define GAMMA_FACTOR ' + gammaFactorDefine,
  10226. '#define MAX_BONES ' + parameters.maxBones,
  10227. ( parameters.useFog && parameters.fog ) ? '#define USE_FOG' : '',
  10228. ( parameters.useFog && parameters.fogExp ) ? '#define FOG_EXP2' : '',
  10229. parameters.map ? '#define USE_MAP' : '',
  10230. parameters.envMap ? '#define USE_ENVMAP' : '',
  10231. parameters.envMap ? '#define ' + envMapModeDefine : '',
  10232. parameters.lightMap ? '#define USE_LIGHTMAP' : '',
  10233. parameters.aoMap ? '#define USE_AOMAP' : '',
  10234. parameters.emissiveMap ? '#define USE_EMISSIVEMAP' : '',
  10235. parameters.bumpMap ? '#define USE_BUMPMAP' : '',
  10236. parameters.normalMap ? '#define USE_NORMALMAP' : '',
  10237. ( parameters.normalMap && parameters.objectSpaceNormalMap ) ? '#define OBJECTSPACE_NORMALMAP' : '',
  10238. parameters.displacementMap && parameters.supportsVertexTextures ? '#define USE_DISPLACEMENTMAP' : '',
  10239. parameters.specularMap ? '#define USE_SPECULARMAP' : '',
  10240. parameters.roughnessMap ? '#define USE_ROUGHNESSMAP' : '',
  10241. parameters.metalnessMap ? '#define USE_METALNESSMAP' : '',
  10242. parameters.alphaMap ? '#define USE_ALPHAMAP' : '',
  10243. parameters.vertexTangents ? '#define USE_TANGENT' : '',
  10244. parameters.vertexColors ? '#define USE_COLOR' : '',
  10245. parameters.flatShading ? '#define FLAT_SHADED' : '',
  10246. parameters.skinning ? '#define USE_SKINNING' : '',
  10247. parameters.useVertexTexture ? '#define BONE_TEXTURE' : '',
  10248. parameters.morphTargets ? '#define USE_MORPHTARGETS' : '',
  10249. parameters.morphNormals && parameters.flatShading === false ? '#define USE_MORPHNORMALS' : '',
  10250. parameters.doubleSided ? '#define DOUBLE_SIDED' : '',
  10251. parameters.flipSided ? '#define FLIP_SIDED' : '',
  10252. parameters.shadowMapEnabled ? '#define USE_SHADOWMAP' : '',
  10253. parameters.shadowMapEnabled ? '#define ' + shadowMapTypeDefine : '',
  10254. parameters.sizeAttenuation ? '#define USE_SIZEATTENUATION' : '',
  10255. parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
  10256. parameters.logarithmicDepthBuffer && ( capabilities.isWebGL2 || extensions.get( 'EXT_frag_depth' ) ) ? '#define USE_LOGDEPTHBUF_EXT' : '',
  10257. 'uniform mat4 modelMatrix;',
  10258. 'uniform mat4 modelViewMatrix;',
  10259. 'uniform mat4 projectionMatrix;',
  10260. 'uniform mat4 viewMatrix;',
  10261. 'uniform mat3 normalMatrix;',
  10262. 'uniform vec3 cameraPosition;',
  10263. 'attribute vec3 position;',
  10264. 'attribute vec3 normal;',
  10265. 'attribute vec2 uv;',
  10266. '#ifdef USE_TANGENT',
  10267. ' attribute vec4 tangent;',
  10268. '#endif',
  10269. '#ifdef USE_COLOR',
  10270. ' attribute vec3 color;',
  10271. '#endif',
  10272. '#ifdef USE_MORPHTARGETS',
  10273. ' attribute vec3 morphTarget0;',
  10274. ' attribute vec3 morphTarget1;',
  10275. ' attribute vec3 morphTarget2;',
  10276. ' attribute vec3 morphTarget3;',
  10277. ' #ifdef USE_MORPHNORMALS',
  10278. ' attribute vec3 morphNormal0;',
  10279. ' attribute vec3 morphNormal1;',
  10280. ' attribute vec3 morphNormal2;',
  10281. ' attribute vec3 morphNormal3;',
  10282. ' #else',
  10283. ' attribute vec3 morphTarget4;',
  10284. ' attribute vec3 morphTarget5;',
  10285. ' attribute vec3 morphTarget6;',
  10286. ' attribute vec3 morphTarget7;',
  10287. ' #endif',
  10288. '#endif',
  10289. '#ifdef USE_SKINNING',
  10290. ' attribute vec4 skinIndex;',
  10291. ' attribute vec4 skinWeight;',
  10292. '#endif',
  10293. '\n'
  10294. ].filter( filterEmptyLine ).join( '\n' );
  10295. prefixFragment = [
  10296. customExtensions,
  10297. 'precision ' + parameters.precision + ' float;',
  10298. 'precision ' + parameters.precision + ' int;',
  10299. '#define SHADER_NAME ' + shader.name,
  10300. customDefines,
  10301. parameters.alphaTest ? '#define ALPHATEST ' + parameters.alphaTest + ( parameters.alphaTest % 1 ? '' : '.0' ) : '', // add '.0' if integer
  10302. '#define GAMMA_FACTOR ' + gammaFactorDefine,
  10303. ( parameters.useFog && parameters.fog ) ? '#define USE_FOG' : '',
  10304. ( parameters.useFog && parameters.fogExp ) ? '#define FOG_EXP2' : '',
  10305. parameters.map ? '#define USE_MAP' : '',
  10306. parameters.matcap ? '#define USE_MATCAP' : '',
  10307. parameters.envMap ? '#define USE_ENVMAP' : '',
  10308. parameters.envMap ? '#define ' + envMapTypeDefine : '',
  10309. parameters.envMap ? '#define ' + envMapModeDefine : '',
  10310. parameters.envMap ? '#define ' + envMapBlendingDefine : '',
  10311. parameters.lightMap ? '#define USE_LIGHTMAP' : '',
  10312. parameters.aoMap ? '#define USE_AOMAP' : '',
  10313. parameters.emissiveMap ? '#define USE_EMISSIVEMAP' : '',
  10314. parameters.bumpMap ? '#define USE_BUMPMAP' : '',
  10315. parameters.normalMap ? '#define USE_NORMALMAP' : '',
  10316. ( parameters.normalMap && parameters.objectSpaceNormalMap ) ? '#define OBJECTSPACE_NORMALMAP' : '',
  10317. parameters.specularMap ? '#define USE_SPECULARMAP' : '',
  10318. parameters.roughnessMap ? '#define USE_ROUGHNESSMAP' : '',
  10319. parameters.metalnessMap ? '#define USE_METALNESSMAP' : '',
  10320. parameters.alphaMap ? '#define USE_ALPHAMAP' : '',
  10321. parameters.vertexTangents ? '#define USE_TANGENT' : '',
  10322. parameters.vertexColors ? '#define USE_COLOR' : '',
  10323. parameters.gradientMap ? '#define USE_GRADIENTMAP' : '',
  10324. parameters.flatShading ? '#define FLAT_SHADED' : '',
  10325. parameters.doubleSided ? '#define DOUBLE_SIDED' : '',
  10326. parameters.flipSided ? '#define FLIP_SIDED' : '',
  10327. parameters.shadowMapEnabled ? '#define USE_SHADOWMAP' : '',
  10328. parameters.shadowMapEnabled ? '#define ' + shadowMapTypeDefine : '',
  10329. parameters.premultipliedAlpha ? '#define PREMULTIPLIED_ALPHA' : '',
  10330. parameters.physicallyCorrectLights ? '#define PHYSICALLY_CORRECT_LIGHTS' : '',
  10331. parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
  10332. parameters.logarithmicDepthBuffer && ( capabilities.isWebGL2 || extensions.get( 'EXT_frag_depth' ) ) ? '#define USE_LOGDEPTHBUF_EXT' : '',
  10333. parameters.envMap && ( capabilities.isWebGL2 || extensions.get( 'EXT_shader_texture_lod' ) ) ? '#define TEXTURE_LOD_EXT' : '',
  10334. 'uniform mat4 viewMatrix;',
  10335. 'uniform vec3 cameraPosition;',
  10336. ( parameters.toneMapping !== NoToneMapping ) ? '#define TONE_MAPPING' : '',
  10337. ( parameters.toneMapping !== NoToneMapping ) ? ShaderChunk[ 'tonemapping_pars_fragment' ] : '', // this code is required here because it is used by the toneMapping() function defined below
  10338. ( parameters.toneMapping !== NoToneMapping ) ? getToneMappingFunction( 'toneMapping', parameters.toneMapping ) : '',
  10339. parameters.dithering ? '#define DITHERING' : '',
  10340. ( parameters.outputEncoding || parameters.mapEncoding || parameters.matcapEncoding || parameters.envMapEncoding || parameters.emissiveMapEncoding ) ?
  10341. ShaderChunk[ 'encodings_pars_fragment' ] : '', // this code is required here because it is used by the various encoding/decoding function defined below
  10342. parameters.mapEncoding ? getTexelDecodingFunction( 'mapTexelToLinear', parameters.mapEncoding ) : '',
  10343. parameters.matcapEncoding ? getTexelDecodingFunction( 'matcapTexelToLinear', parameters.matcapEncoding ) : '',
  10344. parameters.envMapEncoding ? getTexelDecodingFunction( 'envMapTexelToLinear', parameters.envMapEncoding ) : '',
  10345. parameters.emissiveMapEncoding ? getTexelDecodingFunction( 'emissiveMapTexelToLinear', parameters.emissiveMapEncoding ) : '',
  10346. parameters.outputEncoding ? getTexelEncodingFunction( 'linearToOutputTexel', parameters.outputEncoding ) : '',
  10347. parameters.depthPacking ? '#define DEPTH_PACKING ' + material.depthPacking : '',
  10348. '\n'
  10349. ].filter( filterEmptyLine ).join( '\n' );
  10350. }
  10351. vertexShader = parseIncludes( vertexShader );
  10352. vertexShader = replaceLightNums( vertexShader, parameters );
  10353. vertexShader = replaceClippingPlaneNums( vertexShader, parameters );
  10354. fragmentShader = parseIncludes( fragmentShader );
  10355. fragmentShader = replaceLightNums( fragmentShader, parameters );
  10356. fragmentShader = replaceClippingPlaneNums( fragmentShader, parameters );
  10357. vertexShader = unrollLoops( vertexShader );
  10358. fragmentShader = unrollLoops( fragmentShader );
  10359. if ( capabilities.isWebGL2 && ! material.isRawShaderMaterial ) {
  10360. var isGLSL3ShaderMaterial = false;
  10361. var versionRegex = /^\s*#version\s+300\s+es\s*\n/;
  10362. if ( material.isShaderMaterial &&
  10363. vertexShader.match( versionRegex ) !== null &&
  10364. fragmentShader.match( versionRegex ) !== null ) {
  10365. isGLSL3ShaderMaterial = true;
  10366. vertexShader = vertexShader.replace( versionRegex, '' );
  10367. fragmentShader = fragmentShader.replace( versionRegex, '' );
  10368. }
  10369. // GLSL 3.0 conversion
  10370. prefixVertex = [
  10371. '#version 300 es\n',
  10372. '#define attribute in',
  10373. '#define varying out',
  10374. '#define texture2D texture'
  10375. ].join( '\n' ) + '\n' + prefixVertex;
  10376. prefixFragment = [
  10377. '#version 300 es\n',
  10378. '#define varying in',
  10379. isGLSL3ShaderMaterial ? '' : 'out highp vec4 pc_fragColor;',
  10380. isGLSL3ShaderMaterial ? '' : '#define gl_FragColor pc_fragColor',
  10381. '#define gl_FragDepthEXT gl_FragDepth',
  10382. '#define texture2D texture',
  10383. '#define textureCube texture',
  10384. '#define texture2DProj textureProj',
  10385. '#define texture2DLodEXT textureLod',
  10386. '#define texture2DProjLodEXT textureProjLod',
  10387. '#define textureCubeLodEXT textureLod',
  10388. '#define texture2DGradEXT textureGrad',
  10389. '#define texture2DProjGradEXT textureProjGrad',
  10390. '#define textureCubeGradEXT textureGrad'
  10391. ].join( '\n' ) + '\n' + prefixFragment;
  10392. }
  10393. var vertexGlsl = prefixVertex + vertexShader;
  10394. var fragmentGlsl = prefixFragment + fragmentShader;
  10395. // console.log( '*VERTEX*', vertexGlsl );
  10396. // console.log( '*FRAGMENT*', fragmentGlsl );
  10397. var glVertexShader = WebGLShader( gl, 35633, vertexGlsl, renderer.debug.checkShaderErrors );
  10398. var glFragmentShader = WebGLShader( gl, 35632, fragmentGlsl, renderer.debug.checkShaderErrors );
  10399. gl.attachShader( program, glVertexShader );
  10400. gl.attachShader( program, glFragmentShader );
  10401. // Force a particular attribute to index 0.
  10402. if ( material.index0AttributeName !== undefined ) {
  10403. gl.bindAttribLocation( program, 0, material.index0AttributeName );
  10404. } else if ( parameters.morphTargets === true ) {
  10405. // programs with morphTargets displace position out of attribute 0
  10406. gl.bindAttribLocation( program, 0, 'position' );
  10407. }
  10408. gl.linkProgram( program );
  10409. // check for link errors
  10410. if ( renderer.debug.checkShaderErrors ) {
  10411. var programLog = gl.getProgramInfoLog( program ).trim();
  10412. var vertexLog = gl.getShaderInfoLog( glVertexShader ).trim();
  10413. var fragmentLog = gl.getShaderInfoLog( glFragmentShader ).trim();
  10414. var runnable = true;
  10415. var haveDiagnostics = true;
  10416. // console.log( '**VERTEX**', gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( glVertexShader ) );
  10417. // console.log( '**FRAGMENT**', gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( glFragmentShader ) );
  10418. if ( gl.getProgramParameter( program, 35714 ) === false ) {
  10419. runnable = false;
  10420. console.error( 'THREE.WebGLProgram: shader error: ', gl.getError(), '35715', gl.getProgramParameter( program, 35715 ), 'gl.getProgramInfoLog', programLog, vertexLog, fragmentLog );
  10421. } else if ( programLog !== '' ) {
  10422. console.warn( 'THREE.WebGLProgram: gl.getProgramInfoLog()', programLog );
  10423. } else if ( vertexLog === '' || fragmentLog === '' ) {
  10424. haveDiagnostics = false;
  10425. }
  10426. if ( haveDiagnostics ) {
  10427. this.diagnostics = {
  10428. runnable: runnable,
  10429. material: material,
  10430. programLog: programLog,
  10431. vertexShader: {
  10432. log: vertexLog,
  10433. prefix: prefixVertex
  10434. },
  10435. fragmentShader: {
  10436. log: fragmentLog,
  10437. prefix: prefixFragment
  10438. }
  10439. };
  10440. }
  10441. }
  10442. // clean up
  10443. gl.deleteShader( glVertexShader );
  10444. gl.deleteShader( glFragmentShader );
  10445. // set up caching for uniform locations
  10446. var cachedUniforms;
  10447. this.getUniforms = function () {
  10448. if ( cachedUniforms === undefined ) {
  10449. cachedUniforms = new WebGLUniforms( gl, program, textures );
  10450. }
  10451. return cachedUniforms;
  10452. };
  10453. // set up caching for attribute locations
  10454. var cachedAttributes;
  10455. this.getAttributes = function () {
  10456. if ( cachedAttributes === undefined ) {
  10457. cachedAttributes = fetchAttributeLocations( gl, program );
  10458. }
  10459. return cachedAttributes;
  10460. };
  10461. // free resource
  10462. this.destroy = function () {
  10463. gl.deleteProgram( program );
  10464. this.program = undefined;
  10465. };
  10466. // DEPRECATED
  10467. Object.defineProperties( this, {
  10468. uniforms: {
  10469. get: function () {
  10470. console.warn( 'THREE.WebGLProgram: .uniforms is now .getUniforms().' );
  10471. return this.getUniforms();
  10472. }
  10473. },
  10474. attributes: {
  10475. get: function () {
  10476. console.warn( 'THREE.WebGLProgram: .attributes is now .getAttributes().' );
  10477. return this.getAttributes();
  10478. }
  10479. }
  10480. } );
  10481. //
  10482. this.name = shader.name;
  10483. this.id = programIdCount ++;
  10484. this.code = code;
  10485. this.usedTimes = 1;
  10486. this.program = program;
  10487. this.vertexShader = glVertexShader;
  10488. this.fragmentShader = glFragmentShader;
  10489. return this;
  10490. }
  10491. /**
  10492. * @author mrdoob / http://mrdoob.com/
  10493. */
  10494. function WebGLPrograms( renderer, extensions, capabilities, textures ) {
  10495. var programs = [];
  10496. var shaderIDs = {
  10497. MeshDepthMaterial: 'depth',
  10498. MeshDistanceMaterial: 'distanceRGBA',
  10499. MeshNormalMaterial: 'normal',
  10500. MeshBasicMaterial: 'basic',
  10501. MeshLambertMaterial: 'lambert',
  10502. MeshPhongMaterial: 'phong',
  10503. MeshToonMaterial: 'phong',
  10504. MeshStandardMaterial: 'physical',
  10505. MeshPhysicalMaterial: 'physical',
  10506. MeshMatcapMaterial: 'matcap',
  10507. LineBasicMaterial: 'basic',
  10508. LineDashedMaterial: 'dashed',
  10509. PointsMaterial: 'points',
  10510. ShadowMaterial: 'shadow',
  10511. SpriteMaterial: 'sprite'
  10512. };
  10513. var parameterNames = [
  10514. "precision", "supportsVertexTextures", "map", "mapEncoding", "matcap", "matcapEncoding", "envMap", "envMapMode", "envMapEncoding",
  10515. "lightMap", "aoMap", "emissiveMap", "emissiveMapEncoding", "bumpMap", "normalMap", "objectSpaceNormalMap", "displacementMap", "specularMap",
  10516. "roughnessMap", "metalnessMap", "gradientMap",
  10517. "alphaMap", "combine", "vertexColors", "vertexTangents", "fog", "useFog", "fogExp",
  10518. "flatShading", "sizeAttenuation", "logarithmicDepthBuffer", "skinning",
  10519. "maxBones", "useVertexTexture", "morphTargets", "morphNormals",
  10520. "maxMorphTargets", "maxMorphNormals", "premultipliedAlpha",
  10521. "numDirLights", "numPointLights", "numSpotLights", "numHemiLights", "numRectAreaLights",
  10522. "shadowMapEnabled", "shadowMapType", "toneMapping", 'physicallyCorrectLights',
  10523. "alphaTest", "doubleSided", "flipSided", "numClippingPlanes", "numClipIntersection", "depthPacking", "dithering"
  10524. ];
  10525. function allocateBones( object ) {
  10526. var skeleton = object.skeleton;
  10527. var bones = skeleton.bones;
  10528. if ( capabilities.floatVertexTextures ) {
  10529. return 1024;
  10530. } else {
  10531. // default for when object is not specified
  10532. // ( for example when prebuilding shader to be used with multiple objects )
  10533. //
  10534. // - leave some extra space for other uniforms
  10535. // - limit here is ANGLE's 254 max uniform vectors
  10536. // (up to 54 should be safe)
  10537. var nVertexUniforms = capabilities.maxVertexUniforms;
  10538. var nVertexMatrices = Math.floor( ( nVertexUniforms - 20 ) / 4 );
  10539. var maxBones = Math.min( nVertexMatrices, bones.length );
  10540. if ( maxBones < bones.length ) {
  10541. console.warn( 'THREE.WebGLRenderer: Skeleton has ' + bones.length + ' bones. This GPU supports ' + maxBones + '.' );
  10542. return 0;
  10543. }
  10544. return maxBones;
  10545. }
  10546. }
  10547. function getTextureEncodingFromMap( map, gammaOverrideLinear ) {
  10548. var encoding;
  10549. if ( ! map ) {
  10550. encoding = LinearEncoding;
  10551. } else if ( map.isTexture ) {
  10552. encoding = map.encoding;
  10553. } else if ( map.isWebGLRenderTarget ) {
  10554. console.warn( "THREE.WebGLPrograms.getTextureEncodingFromMap: don't use render targets as textures. Use their .texture property instead." );
  10555. encoding = map.texture.encoding;
  10556. }
  10557. // add backwards compatibility for WebGLRenderer.gammaInput/gammaOutput parameter, should probably be removed at some point.
  10558. if ( encoding === LinearEncoding && gammaOverrideLinear ) {
  10559. encoding = GammaEncoding;
  10560. }
  10561. return encoding;
  10562. }
  10563. this.getParameters = function ( material, lights, shadows, fog, nClipPlanes, nClipIntersection, object ) {
  10564. var shaderID = shaderIDs[ material.type ];
  10565. // heuristics to create shader parameters according to lights in the scene
  10566. // (not to blow over maxLights budget)
  10567. var maxBones = object.isSkinnedMesh ? allocateBones( object ) : 0;
  10568. var precision = capabilities.precision;
  10569. if ( material.precision !== null ) {
  10570. precision = capabilities.getMaxPrecision( material.precision );
  10571. if ( precision !== material.precision ) {
  10572. console.warn( 'THREE.WebGLProgram.getParameters:', material.precision, 'not supported, using', precision, 'instead.' );
  10573. }
  10574. }
  10575. var currentRenderTarget = renderer.getRenderTarget();
  10576. var parameters = {
  10577. shaderID: shaderID,
  10578. precision: precision,
  10579. supportsVertexTextures: capabilities.vertexTextures,
  10580. outputEncoding: getTextureEncodingFromMap( ( ! currentRenderTarget ) ? null : currentRenderTarget.texture, renderer.gammaOutput ),
  10581. map: !! material.map,
  10582. mapEncoding: getTextureEncodingFromMap( material.map, renderer.gammaInput ),
  10583. matcap: !! material.matcap,
  10584. matcapEncoding: getTextureEncodingFromMap( material.matcap, renderer.gammaInput ),
  10585. envMap: !! material.envMap,
  10586. envMapMode: material.envMap && material.envMap.mapping,
  10587. envMapEncoding: getTextureEncodingFromMap( material.envMap, renderer.gammaInput ),
  10588. envMapCubeUV: ( !! material.envMap ) && ( ( material.envMap.mapping === CubeUVReflectionMapping ) || ( material.envMap.mapping === CubeUVRefractionMapping ) ),
  10589. lightMap: !! material.lightMap,
  10590. aoMap: !! material.aoMap,
  10591. emissiveMap: !! material.emissiveMap,
  10592. emissiveMapEncoding: getTextureEncodingFromMap( material.emissiveMap, renderer.gammaInput ),
  10593. bumpMap: !! material.bumpMap,
  10594. normalMap: !! material.normalMap,
  10595. objectSpaceNormalMap: material.normalMapType === ObjectSpaceNormalMap,
  10596. displacementMap: !! material.displacementMap,
  10597. roughnessMap: !! material.roughnessMap,
  10598. metalnessMap: !! material.metalnessMap,
  10599. specularMap: !! material.specularMap,
  10600. alphaMap: !! material.alphaMap,
  10601. gradientMap: !! material.gradientMap,
  10602. combine: material.combine,
  10603. vertexTangents: ( material.normalMap && material.vertexTangents ),
  10604. vertexColors: material.vertexColors,
  10605. fog: !! fog,
  10606. useFog: material.fog,
  10607. fogExp: ( fog && fog.isFogExp2 ),
  10608. flatShading: material.flatShading,
  10609. sizeAttenuation: material.sizeAttenuation,
  10610. logarithmicDepthBuffer: capabilities.logarithmicDepthBuffer,
  10611. skinning: material.skinning && maxBones > 0,
  10612. maxBones: maxBones,
  10613. useVertexTexture: capabilities.floatVertexTextures,
  10614. morphTargets: material.morphTargets,
  10615. morphNormals: material.morphNormals,
  10616. maxMorphTargets: renderer.maxMorphTargets,
  10617. maxMorphNormals: renderer.maxMorphNormals,
  10618. numDirLights: lights.directional.length,
  10619. numPointLights: lights.point.length,
  10620. numSpotLights: lights.spot.length,
  10621. numRectAreaLights: lights.rectArea.length,
  10622. numHemiLights: lights.hemi.length,
  10623. numClippingPlanes: nClipPlanes,
  10624. numClipIntersection: nClipIntersection,
  10625. dithering: material.dithering,
  10626. shadowMapEnabled: renderer.shadowMap.enabled && object.receiveShadow && shadows.length > 0,
  10627. shadowMapType: renderer.shadowMap.type,
  10628. toneMapping: renderer.toneMapping,
  10629. physicallyCorrectLights: renderer.physicallyCorrectLights,
  10630. premultipliedAlpha: material.premultipliedAlpha,
  10631. alphaTest: material.alphaTest,
  10632. doubleSided: material.side === DoubleSide,
  10633. flipSided: material.side === BackSide,
  10634. depthPacking: ( material.depthPacking !== undefined ) ? material.depthPacking : false
  10635. };
  10636. return parameters;
  10637. };
  10638. this.getProgramCode = function ( material, parameters ) {
  10639. var array = [];
  10640. if ( parameters.shaderID ) {
  10641. array.push( parameters.shaderID );
  10642. } else {
  10643. array.push( material.fragmentShader );
  10644. array.push( material.vertexShader );
  10645. }
  10646. if ( material.defines !== undefined ) {
  10647. for ( var name in material.defines ) {
  10648. array.push( name );
  10649. array.push( material.defines[ name ] );
  10650. }
  10651. }
  10652. for ( var i = 0; i < parameterNames.length; i ++ ) {
  10653. array.push( parameters[ parameterNames[ i ] ] );
  10654. }
  10655. array.push( material.onBeforeCompile.toString() );
  10656. array.push( renderer.gammaOutput );
  10657. array.push( renderer.gammaFactor );
  10658. return array.join();
  10659. };
  10660. this.acquireProgram = function ( material, shader, parameters, code ) {
  10661. var program;
  10662. // Check if code has been already compiled
  10663. for ( var p = 0, pl = programs.length; p < pl; p ++ ) {
  10664. var programInfo = programs[ p ];
  10665. if ( programInfo.code === code ) {
  10666. program = programInfo;
  10667. ++ program.usedTimes;
  10668. break;
  10669. }
  10670. }
  10671. if ( program === undefined ) {
  10672. program = new WebGLProgram( renderer, extensions, code, material, shader, parameters, capabilities, textures );
  10673. programs.push( program );
  10674. }
  10675. return program;
  10676. };
  10677. this.releaseProgram = function ( program ) {
  10678. if ( -- program.usedTimes === 0 ) {
  10679. // Remove from unordered set
  10680. var i = programs.indexOf( program );
  10681. programs[ i ] = programs[ programs.length - 1 ];
  10682. programs.pop();
  10683. // Free WebGL resources
  10684. program.destroy();
  10685. }
  10686. };
  10687. // Exposed for resource monitoring & error feedback via renderer.info:
  10688. this.programs = programs;
  10689. }
  10690. /**
  10691. * @author fordacious / fordacious.github.io
  10692. */
  10693. function WebGLProperties() {
  10694. var properties = new WeakMap();
  10695. function get( object ) {
  10696. var map = properties.get( object );
  10697. if ( map === undefined ) {
  10698. map = {};
  10699. properties.set( object, map );
  10700. }
  10701. return map;
  10702. }
  10703. function remove( object ) {
  10704. properties.delete( object );
  10705. }
  10706. function update( object, key, value ) {
  10707. properties.get( object )[ key ] = value;
  10708. }
  10709. function dispose() {
  10710. properties = new WeakMap();
  10711. }
  10712. return {
  10713. get: get,
  10714. remove: remove,
  10715. update: update,
  10716. dispose: dispose
  10717. };
  10718. }
  10719. /**
  10720. * @author mrdoob / http://mrdoob.com/
  10721. */
  10722. function painterSortStable( a, b ) {
  10723. if ( a.groupOrder !== b.groupOrder ) {
  10724. return a.groupOrder - b.groupOrder;
  10725. } else if ( a.renderOrder !== b.renderOrder ) {
  10726. return a.renderOrder - b.renderOrder;
  10727. } else if ( a.program !== b.program ) {
  10728. return a.program.id - b.program.id;
  10729. } else if ( a.material.id !== b.material.id ) {
  10730. return a.material.id - b.material.id;
  10731. } else if ( a.z !== b.z ) {
  10732. return a.z - b.z;
  10733. } else {
  10734. return a.id - b.id;
  10735. }
  10736. }
  10737. function reversePainterSortStable( a, b ) {
  10738. if ( a.groupOrder !== b.groupOrder ) {
  10739. return a.groupOrder - b.groupOrder;
  10740. } else if ( a.renderOrder !== b.renderOrder ) {
  10741. return a.renderOrder - b.renderOrder;
  10742. } else if ( a.z !== b.z ) {
  10743. return b.z - a.z;
  10744. } else {
  10745. return a.id - b.id;
  10746. }
  10747. }
  10748. function WebGLRenderList() {
  10749. var renderItems = [];
  10750. var renderItemsIndex = 0;
  10751. var opaque = [];
  10752. var transparent = [];
  10753. var defaultProgram = { id: - 1 };
  10754. function init() {
  10755. renderItemsIndex = 0;
  10756. opaque.length = 0;
  10757. transparent.length = 0;
  10758. }
  10759. function getNextRenderItem( object, geometry, material, groupOrder, z, group ) {
  10760. var renderItem = renderItems[ renderItemsIndex ];
  10761. if ( renderItem === undefined ) {
  10762. renderItem = {
  10763. id: object.id,
  10764. object: object,
  10765. geometry: geometry,
  10766. material: material,
  10767. program: material.program || defaultProgram,
  10768. groupOrder: groupOrder,
  10769. renderOrder: object.renderOrder,
  10770. z: z,
  10771. group: group
  10772. };
  10773. renderItems[ renderItemsIndex ] = renderItem;
  10774. } else {
  10775. renderItem.id = object.id;
  10776. renderItem.object = object;
  10777. renderItem.geometry = geometry;
  10778. renderItem.material = material;
  10779. renderItem.program = material.program || defaultProgram;
  10780. renderItem.groupOrder = groupOrder;
  10781. renderItem.renderOrder = object.renderOrder;
  10782. renderItem.z = z;
  10783. renderItem.group = group;
  10784. }
  10785. renderItemsIndex ++;
  10786. return renderItem;
  10787. }
  10788. function push( object, geometry, material, groupOrder, z, group ) {
  10789. var renderItem = getNextRenderItem( object, geometry, material, groupOrder, z, group );
  10790. ( material.transparent === true ? transparent : opaque ).push( renderItem );
  10791. }
  10792. function unshift( object, geometry, material, groupOrder, z, group ) {
  10793. var renderItem = getNextRenderItem( object, geometry, material, groupOrder, z, group );
  10794. ( material.transparent === true ? transparent : opaque ).unshift( renderItem );
  10795. }
  10796. function sort() {
  10797. if ( opaque.length > 1 ) opaque.sort( painterSortStable );
  10798. if ( transparent.length > 1 ) transparent.sort( reversePainterSortStable );
  10799. }
  10800. return {
  10801. opaque: opaque,
  10802. transparent: transparent,
  10803. init: init,
  10804. push: push,
  10805. unshift: unshift,
  10806. sort: sort
  10807. };
  10808. }
  10809. function WebGLRenderLists() {
  10810. var lists = {};
  10811. function onSceneDispose( event ) {
  10812. var scene = event.target;
  10813. scene.removeEventListener( 'dispose', onSceneDispose );
  10814. delete lists[ scene.id ];
  10815. }
  10816. function get( scene, camera ) {
  10817. var cameras = lists[ scene.id ];
  10818. var list;
  10819. if ( cameras === undefined ) {
  10820. list = new WebGLRenderList();
  10821. lists[ scene.id ] = {};
  10822. lists[ scene.id ][ camera.id ] = list;
  10823. scene.addEventListener( 'dispose', onSceneDispose );
  10824. } else {
  10825. list = cameras[ camera.id ];
  10826. if ( list === undefined ) {
  10827. list = new WebGLRenderList();
  10828. cameras[ camera.id ] = list;
  10829. }
  10830. }
  10831. return list;
  10832. }
  10833. function dispose() {
  10834. lists = {};
  10835. }
  10836. return {
  10837. get: get,
  10838. dispose: dispose
  10839. };
  10840. }
  10841. /**
  10842. * @author mrdoob / http://mrdoob.com/
  10843. */
  10844. function UniformsCache() {
  10845. var lights = {};
  10846. return {
  10847. get: function ( light ) {
  10848. if ( lights[ light.id ] !== undefined ) {
  10849. return lights[ light.id ];
  10850. }
  10851. var uniforms;
  10852. switch ( light.type ) {
  10853. case 'DirectionalLight':
  10854. uniforms = {
  10855. direction: new Vector3(),
  10856. color: new Color(),
  10857. shadow: false,
  10858. shadowBias: 0,
  10859. shadowRadius: 1,
  10860. shadowMapSize: new Vector2()
  10861. };
  10862. break;
  10863. case 'SpotLight':
  10864. uniforms = {
  10865. position: new Vector3(),
  10866. direction: new Vector3(),
  10867. color: new Color(),
  10868. distance: 0,
  10869. coneCos: 0,
  10870. penumbraCos: 0,
  10871. decay: 0,
  10872. shadow: false,
  10873. shadowBias: 0,
  10874. shadowRadius: 1,
  10875. shadowMapSize: new Vector2()
  10876. };
  10877. break;
  10878. case 'PointLight':
  10879. uniforms = {
  10880. position: new Vector3(),
  10881. color: new Color(),
  10882. distance: 0,
  10883. decay: 0,
  10884. shadow: false,
  10885. shadowBias: 0,
  10886. shadowRadius: 1,
  10887. shadowMapSize: new Vector2(),
  10888. shadowCameraNear: 1,
  10889. shadowCameraFar: 1000
  10890. };
  10891. break;
  10892. case 'HemisphereLight':
  10893. uniforms = {
  10894. direction: new Vector3(),
  10895. skyColor: new Color(),
  10896. groundColor: new Color()
  10897. };
  10898. break;
  10899. case 'RectAreaLight':
  10900. uniforms = {
  10901. color: new Color(),
  10902. position: new Vector3(),
  10903. halfWidth: new Vector3(),
  10904. halfHeight: new Vector3()
  10905. // TODO (abelnation): set RectAreaLight shadow uniforms
  10906. };
  10907. break;
  10908. }
  10909. lights[ light.id ] = uniforms;
  10910. return uniforms;
  10911. }
  10912. };
  10913. }
  10914. var count = 0;
  10915. function WebGLLights() {
  10916. var cache = new UniformsCache();
  10917. var state = {
  10918. id: count ++,
  10919. hash: {
  10920. stateID: - 1,
  10921. directionalLength: - 1,
  10922. pointLength: - 1,
  10923. spotLength: - 1,
  10924. rectAreaLength: - 1,
  10925. hemiLength: - 1,
  10926. shadowsLength: - 1
  10927. },
  10928. ambient: [ 0, 0, 0 ],
  10929. probe: [],
  10930. directional: [],
  10931. directionalShadowMap: [],
  10932. directionalShadowMatrix: [],
  10933. spot: [],
  10934. spotShadowMap: [],
  10935. spotShadowMatrix: [],
  10936. rectArea: [],
  10937. point: [],
  10938. pointShadowMap: [],
  10939. pointShadowMatrix: [],
  10940. hemi: []
  10941. };
  10942. for ( var i = 0; i < 9; i ++ ) state.probe.push( new Vector3() );
  10943. var vector3 = new Vector3();
  10944. var matrix4 = new Matrix4();
  10945. var matrix42 = new Matrix4();
  10946. function setup( lights, shadows, camera ) {
  10947. var r = 0, g = 0, b = 0;
  10948. for ( var i = 0; i < 9; i ++ ) state.probe[ i ].set( 0, 0, 0 );
  10949. var directionalLength = 0;
  10950. var pointLength = 0;
  10951. var spotLength = 0;
  10952. var rectAreaLength = 0;
  10953. var hemiLength = 0;
  10954. var viewMatrix = camera.matrixWorldInverse;
  10955. for ( var i = 0, l = lights.length; i < l; i ++ ) {
  10956. var light = lights[ i ];
  10957. var color = light.color;
  10958. var intensity = light.intensity;
  10959. var distance = light.distance;
  10960. var shadowMap = ( light.shadow && light.shadow.map ) ? light.shadow.map.texture : null;
  10961. if ( light.isAmbientLight ) {
  10962. r += color.r * intensity;
  10963. g += color.g * intensity;
  10964. b += color.b * intensity;
  10965. } else if ( light.isLightProbe ) {
  10966. for ( var j = 0; j < 9; j ++ ) {
  10967. state.probe[ j ].addScaledVector( light.sh.coefficients[ j ], intensity );
  10968. }
  10969. } else if ( light.isDirectionalLight ) {
  10970. var uniforms = cache.get( light );
  10971. uniforms.color.copy( light.color ).multiplyScalar( light.intensity );
  10972. uniforms.direction.setFromMatrixPosition( light.matrixWorld );
  10973. vector3.setFromMatrixPosition( light.target.matrixWorld );
  10974. uniforms.direction.sub( vector3 );
  10975. uniforms.direction.transformDirection( viewMatrix );
  10976. uniforms.shadow = light.castShadow;
  10977. if ( light.castShadow ) {
  10978. var shadow = light.shadow;
  10979. uniforms.shadowBias = shadow.bias;
  10980. uniforms.shadowRadius = shadow.radius;
  10981. uniforms.shadowMapSize = shadow.mapSize;
  10982. }
  10983. state.directionalShadowMap[ directionalLength ] = shadowMap;
  10984. state.directionalShadowMatrix[ directionalLength ] = light.shadow.matrix;
  10985. state.directional[ directionalLength ] = uniforms;
  10986. directionalLength ++;
  10987. } else if ( light.isSpotLight ) {
  10988. var uniforms = cache.get( light );
  10989. uniforms.position.setFromMatrixPosition( light.matrixWorld );
  10990. uniforms.position.applyMatrix4( viewMatrix );
  10991. uniforms.color.copy( color ).multiplyScalar( intensity );
  10992. uniforms.distance = distance;
  10993. uniforms.direction.setFromMatrixPosition( light.matrixWorld );
  10994. vector3.setFromMatrixPosition( light.target.matrixWorld );
  10995. uniforms.direction.sub( vector3 );
  10996. uniforms.direction.transformDirection( viewMatrix );
  10997. uniforms.coneCos = Math.cos( light.angle );
  10998. uniforms.penumbraCos = Math.cos( light.angle * ( 1 - light.penumbra ) );
  10999. uniforms.decay = light.decay;
  11000. uniforms.shadow = light.castShadow;
  11001. if ( light.castShadow ) {
  11002. var shadow = light.shadow;
  11003. uniforms.shadowBias = shadow.bias;
  11004. uniforms.shadowRadius = shadow.radius;
  11005. uniforms.shadowMapSize = shadow.mapSize;
  11006. }
  11007. state.spotShadowMap[ spotLength ] = shadowMap;
  11008. state.spotShadowMatrix[ spotLength ] = light.shadow.matrix;
  11009. state.spot[ spotLength ] = uniforms;
  11010. spotLength ++;
  11011. } else if ( light.isRectAreaLight ) {
  11012. var uniforms = cache.get( light );
  11013. // (a) intensity is the total visible light emitted
  11014. //uniforms.color.copy( color ).multiplyScalar( intensity / ( light.width * light.height * Math.PI ) );
  11015. // (b) intensity is the brightness of the light
  11016. uniforms.color.copy( color ).multiplyScalar( intensity );
  11017. uniforms.position.setFromMatrixPosition( light.matrixWorld );
  11018. uniforms.position.applyMatrix4( viewMatrix );
  11019. // extract local rotation of light to derive width/height half vectors
  11020. matrix42.identity();
  11021. matrix4.copy( light.matrixWorld );
  11022. matrix4.premultiply( viewMatrix );
  11023. matrix42.extractRotation( matrix4 );
  11024. uniforms.halfWidth.set( light.width * 0.5, 0.0, 0.0 );
  11025. uniforms.halfHeight.set( 0.0, light.height * 0.5, 0.0 );
  11026. uniforms.halfWidth.applyMatrix4( matrix42 );
  11027. uniforms.halfHeight.applyMatrix4( matrix42 );
  11028. // TODO (abelnation): RectAreaLight distance?
  11029. // uniforms.distance = distance;
  11030. state.rectArea[ rectAreaLength ] = uniforms;
  11031. rectAreaLength ++;
  11032. } else if ( light.isPointLight ) {
  11033. var uniforms = cache.get( light );
  11034. uniforms.position.setFromMatrixPosition( light.matrixWorld );
  11035. uniforms.position.applyMatrix4( viewMatrix );
  11036. uniforms.color.copy( light.color ).multiplyScalar( light.intensity );
  11037. uniforms.distance = light.distance;
  11038. uniforms.decay = light.decay;
  11039. uniforms.shadow = light.castShadow;
  11040. if ( light.castShadow ) {
  11041. var shadow = light.shadow;
  11042. uniforms.shadowBias = shadow.bias;
  11043. uniforms.shadowRadius = shadow.radius;
  11044. uniforms.shadowMapSize = shadow.mapSize;
  11045. uniforms.shadowCameraNear = shadow.camera.near;
  11046. uniforms.shadowCameraFar = shadow.camera.far;
  11047. }
  11048. state.pointShadowMap[ pointLength ] = shadowMap;
  11049. state.pointShadowMatrix[ pointLength ] = light.shadow.matrix;
  11050. state.point[ pointLength ] = uniforms;
  11051. pointLength ++;
  11052. } else if ( light.isHemisphereLight ) {
  11053. var uniforms = cache.get( light );
  11054. uniforms.direction.setFromMatrixPosition( light.matrixWorld );
  11055. uniforms.direction.transformDirection( viewMatrix );
  11056. uniforms.direction.normalize();
  11057. uniforms.skyColor.copy( light.color ).multiplyScalar( intensity );
  11058. uniforms.groundColor.copy( light.groundColor ).multiplyScalar( intensity );
  11059. state.hemi[ hemiLength ] = uniforms;
  11060. hemiLength ++;
  11061. }
  11062. }
  11063. state.ambient[ 0 ] = r;
  11064. state.ambient[ 1 ] = g;
  11065. state.ambient[ 2 ] = b;
  11066. state.directional.length = directionalLength;
  11067. state.spot.length = spotLength;
  11068. state.rectArea.length = rectAreaLength;
  11069. state.point.length = pointLength;
  11070. state.hemi.length = hemiLength;
  11071. state.hash.stateID = state.id;
  11072. state.hash.directionalLength = directionalLength;
  11073. state.hash.pointLength = pointLength;
  11074. state.hash.spotLength = spotLength;
  11075. state.hash.rectAreaLength = rectAreaLength;
  11076. state.hash.hemiLength = hemiLength;
  11077. state.hash.shadowsLength = shadows.length;
  11078. }
  11079. return {
  11080. setup: setup,
  11081. state: state
  11082. };
  11083. }
  11084. /**
  11085. * @author Mugen87 / https://github.com/Mugen87
  11086. */
  11087. function WebGLRenderState() {
  11088. var lights = new WebGLLights();
  11089. var lightsArray = [];
  11090. var shadowsArray = [];
  11091. function init() {
  11092. lightsArray.length = 0;
  11093. shadowsArray.length = 0;
  11094. }
  11095. function pushLight( light ) {
  11096. lightsArray.push( light );
  11097. }
  11098. function pushShadow( shadowLight ) {
  11099. shadowsArray.push( shadowLight );
  11100. }
  11101. function setupLights( camera ) {
  11102. lights.setup( lightsArray, shadowsArray, camera );
  11103. }
  11104. var state = {
  11105. lightsArray: lightsArray,
  11106. shadowsArray: shadowsArray,
  11107. lights: lights
  11108. };
  11109. return {
  11110. init: init,
  11111. state: state,
  11112. setupLights: setupLights,
  11113. pushLight: pushLight,
  11114. pushShadow: pushShadow
  11115. };
  11116. }
  11117. function WebGLRenderStates() {
  11118. var renderStates = {};
  11119. function onSceneDispose( event ) {
  11120. var scene = event.target;
  11121. scene.removeEventListener( 'dispose', onSceneDispose );
  11122. delete renderStates[ scene.id ];
  11123. }
  11124. function get( scene, camera ) {
  11125. var renderState;
  11126. if ( renderStates[ scene.id ] === undefined ) {
  11127. renderState = new WebGLRenderState();
  11128. renderStates[ scene.id ] = {};
  11129. renderStates[ scene.id ][ camera.id ] = renderState;
  11130. scene.addEventListener( 'dispose', onSceneDispose );
  11131. } else {
  11132. if ( renderStates[ scene.id ][ camera.id ] === undefined ) {
  11133. renderState = new WebGLRenderState();
  11134. renderStates[ scene.id ][ camera.id ] = renderState;
  11135. } else {
  11136. renderState = renderStates[ scene.id ][ camera.id ];
  11137. }
  11138. }
  11139. return renderState;
  11140. }
  11141. function dispose() {
  11142. renderStates = {};
  11143. }
  11144. return {
  11145. get: get,
  11146. dispose: dispose
  11147. };
  11148. }
  11149. /**
  11150. * @author mrdoob / http://mrdoob.com/
  11151. * @author alteredq / http://alteredqualia.com/
  11152. * @author bhouston / https://clara.io
  11153. * @author WestLangley / http://github.com/WestLangley
  11154. *
  11155. * parameters = {
  11156. *
  11157. * opacity: <float>,
  11158. *
  11159. * map: new THREE.Texture( <Image> ),
  11160. *
  11161. * alphaMap: new THREE.Texture( <Image> ),
  11162. *
  11163. * displacementMap: new THREE.Texture( <Image> ),
  11164. * displacementScale: <float>,
  11165. * displacementBias: <float>,
  11166. *
  11167. * wireframe: <boolean>,
  11168. * wireframeLinewidth: <float>
  11169. * }
  11170. */
  11171. function MeshDepthMaterial( parameters ) {
  11172. Material.call( this );
  11173. this.type = 'MeshDepthMaterial';
  11174. this.depthPacking = BasicDepthPacking;
  11175. this.skinning = false;
  11176. this.morphTargets = false;
  11177. this.map = null;
  11178. this.alphaMap = null;
  11179. this.displacementMap = null;
  11180. this.displacementScale = 1;
  11181. this.displacementBias = 0;
  11182. this.wireframe = false;
  11183. this.wireframeLinewidth = 1;
  11184. this.fog = false;
  11185. this.lights = false;
  11186. this.setValues( parameters );
  11187. }
  11188. MeshDepthMaterial.prototype = Object.create( Material.prototype );
  11189. MeshDepthMaterial.prototype.constructor = MeshDepthMaterial;
  11190. MeshDepthMaterial.prototype.isMeshDepthMaterial = true;
  11191. MeshDepthMaterial.prototype.copy = function ( source ) {
  11192. Material.prototype.copy.call( this, source );
  11193. this.depthPacking = source.depthPacking;
  11194. this.skinning = source.skinning;
  11195. this.morphTargets = source.morphTargets;
  11196. this.map = source.map;
  11197. this.alphaMap = source.alphaMap;
  11198. this.displacementMap = source.displacementMap;
  11199. this.displacementScale = source.displacementScale;
  11200. this.displacementBias = source.displacementBias;
  11201. this.wireframe = source.wireframe;
  11202. this.wireframeLinewidth = source.wireframeLinewidth;
  11203. return this;
  11204. };
  11205. /**
  11206. * @author WestLangley / http://github.com/WestLangley
  11207. *
  11208. * parameters = {
  11209. *
  11210. * referencePosition: <float>,
  11211. * nearDistance: <float>,
  11212. * farDistance: <float>,
  11213. *
  11214. * skinning: <bool>,
  11215. * morphTargets: <bool>,
  11216. *
  11217. * map: new THREE.Texture( <Image> ),
  11218. *
  11219. * alphaMap: new THREE.Texture( <Image> ),
  11220. *
  11221. * displacementMap: new THREE.Texture( <Image> ),
  11222. * displacementScale: <float>,
  11223. * displacementBias: <float>
  11224. *
  11225. * }
  11226. */
  11227. function MeshDistanceMaterial( parameters ) {
  11228. Material.call( this );
  11229. this.type = 'MeshDistanceMaterial';
  11230. this.referencePosition = new Vector3();
  11231. this.nearDistance = 1;
  11232. this.farDistance = 1000;
  11233. this.skinning = false;
  11234. this.morphTargets = false;
  11235. this.map = null;
  11236. this.alphaMap = null;
  11237. this.displacementMap = null;
  11238. this.displacementScale = 1;
  11239. this.displacementBias = 0;
  11240. this.fog = false;
  11241. this.lights = false;
  11242. this.setValues( parameters );
  11243. }
  11244. MeshDistanceMaterial.prototype = Object.create( Material.prototype );
  11245. MeshDistanceMaterial.prototype.constructor = MeshDistanceMaterial;
  11246. MeshDistanceMaterial.prototype.isMeshDistanceMaterial = true;
  11247. MeshDistanceMaterial.prototype.copy = function ( source ) {
  11248. Material.prototype.copy.call( this, source );
  11249. this.referencePosition.copy( source.referencePosition );
  11250. this.nearDistance = source.nearDistance;
  11251. this.farDistance = source.farDistance;
  11252. this.skinning = source.skinning;
  11253. this.morphTargets = source.morphTargets;
  11254. this.map = source.map;
  11255. this.alphaMap = source.alphaMap;
  11256. this.displacementMap = source.displacementMap;
  11257. this.displacementScale = source.displacementScale;
  11258. this.displacementBias = source.displacementBias;
  11259. return this;
  11260. };
  11261. /**
  11262. * @author alteredq / http://alteredqualia.com/
  11263. * @author mrdoob / http://mrdoob.com/
  11264. */
  11265. function WebGLShadowMap( _renderer, _objects, maxTextureSize ) {
  11266. var _frustum = new Frustum(),
  11267. _projScreenMatrix = new Matrix4(),
  11268. _shadowMapSize = new Vector2(),
  11269. _maxShadowMapSize = new Vector2( maxTextureSize, maxTextureSize ),
  11270. _lookTarget = new Vector3(),
  11271. _lightPositionWorld = new Vector3(),
  11272. _MorphingFlag = 1,
  11273. _SkinningFlag = 2,
  11274. _NumberOfMaterialVariants = ( _MorphingFlag | _SkinningFlag ) + 1,
  11275. _depthMaterials = new Array( _NumberOfMaterialVariants ),
  11276. _distanceMaterials = new Array( _NumberOfMaterialVariants ),
  11277. _materialCache = {};
  11278. var shadowSide = { 0: BackSide, 1: FrontSide, 2: DoubleSide };
  11279. var cubeDirections = [
  11280. new Vector3( 1, 0, 0 ), new Vector3( - 1, 0, 0 ), new Vector3( 0, 0, 1 ),
  11281. new Vector3( 0, 0, - 1 ), new Vector3( 0, 1, 0 ), new Vector3( 0, - 1, 0 )
  11282. ];
  11283. var cubeUps = [
  11284. new Vector3( 0, 1, 0 ), new Vector3( 0, 1, 0 ), new Vector3( 0, 1, 0 ),
  11285. new Vector3( 0, 1, 0 ), new Vector3( 0, 0, 1 ), new Vector3( 0, 0, - 1 )
  11286. ];
  11287. var cube2DViewPorts = [
  11288. new Vector4(), new Vector4(), new Vector4(),
  11289. new Vector4(), new Vector4(), new Vector4()
  11290. ];
  11291. // init
  11292. for ( var i = 0; i !== _NumberOfMaterialVariants; ++ i ) {
  11293. var useMorphing = ( i & _MorphingFlag ) !== 0;
  11294. var useSkinning = ( i & _SkinningFlag ) !== 0;
  11295. var depthMaterial = new MeshDepthMaterial( {
  11296. depthPacking: RGBADepthPacking,
  11297. morphTargets: useMorphing,
  11298. skinning: useSkinning
  11299. } );
  11300. _depthMaterials[ i ] = depthMaterial;
  11301. //
  11302. var distanceMaterial = new MeshDistanceMaterial( {
  11303. morphTargets: useMorphing,
  11304. skinning: useSkinning
  11305. } );
  11306. _distanceMaterials[ i ] = distanceMaterial;
  11307. }
  11308. //
  11309. var scope = this;
  11310. this.enabled = false;
  11311. this.autoUpdate = true;
  11312. this.needsUpdate = false;
  11313. this.type = PCFShadowMap;
  11314. this.render = function ( lights, scene, camera ) {
  11315. if ( scope.enabled === false ) return;
  11316. if ( scope.autoUpdate === false && scope.needsUpdate === false ) return;
  11317. if ( lights.length === 0 ) return;
  11318. var currentRenderTarget = _renderer.getRenderTarget();
  11319. var activeCubeFace = _renderer.getActiveCubeFace();
  11320. var activeMipMapLevel = _renderer.getActiveMipMapLevel();
  11321. var _state = _renderer.state;
  11322. // Set GL state for depth map.
  11323. _state.setBlending( NoBlending );
  11324. _state.buffers.color.setClear( 1, 1, 1, 1 );
  11325. _state.buffers.depth.setTest( true );
  11326. _state.setScissorTest( false );
  11327. // render depth map
  11328. var faceCount;
  11329. for ( var i = 0, il = lights.length; i < il; i ++ ) {
  11330. var light = lights[ i ];
  11331. var shadow = light.shadow;
  11332. var isPointLight = light && light.isPointLight;
  11333. if ( shadow === undefined ) {
  11334. console.warn( 'THREE.WebGLShadowMap:', light, 'has no shadow.' );
  11335. continue;
  11336. }
  11337. var shadowCamera = shadow.camera;
  11338. _shadowMapSize.copy( shadow.mapSize );
  11339. _shadowMapSize.min( _maxShadowMapSize );
  11340. if ( isPointLight ) {
  11341. var vpWidth = _shadowMapSize.x;
  11342. var vpHeight = _shadowMapSize.y;
  11343. // These viewports map a cube-map onto a 2D texture with the
  11344. // following orientation:
  11345. //
  11346. // xzXZ
  11347. // y Y
  11348. //
  11349. // X - Positive x direction
  11350. // x - Negative x direction
  11351. // Y - Positive y direction
  11352. // y - Negative y direction
  11353. // Z - Positive z direction
  11354. // z - Negative z direction
  11355. // positive X
  11356. cube2DViewPorts[ 0 ].set( vpWidth * 2, vpHeight, vpWidth, vpHeight );
  11357. // negative X
  11358. cube2DViewPorts[ 1 ].set( 0, vpHeight, vpWidth, vpHeight );
  11359. // positive Z
  11360. cube2DViewPorts[ 2 ].set( vpWidth * 3, vpHeight, vpWidth, vpHeight );
  11361. // negative Z
  11362. cube2DViewPorts[ 3 ].set( vpWidth, vpHeight, vpWidth, vpHeight );
  11363. // positive Y
  11364. cube2DViewPorts[ 4 ].set( vpWidth * 3, 0, vpWidth, vpHeight );
  11365. // negative Y
  11366. cube2DViewPorts[ 5 ].set( vpWidth, 0, vpWidth, vpHeight );
  11367. _shadowMapSize.x *= 4.0;
  11368. _shadowMapSize.y *= 2.0;
  11369. }
  11370. if ( shadow.map === null ) {
  11371. var pars = { minFilter: NearestFilter, magFilter: NearestFilter, format: RGBAFormat };
  11372. shadow.map = new WebGLRenderTarget( _shadowMapSize.x, _shadowMapSize.y, pars );
  11373. shadow.map.texture.name = light.name + ".shadowMap";
  11374. shadowCamera.updateProjectionMatrix();
  11375. }
  11376. if ( shadow.isSpotLightShadow ) {
  11377. shadow.update( light );
  11378. }
  11379. var shadowMap = shadow.map;
  11380. var shadowMatrix = shadow.matrix;
  11381. _lightPositionWorld.setFromMatrixPosition( light.matrixWorld );
  11382. shadowCamera.position.copy( _lightPositionWorld );
  11383. if ( isPointLight ) {
  11384. faceCount = 6;
  11385. // for point lights we set the shadow matrix to be a translation-only matrix
  11386. // equal to inverse of the light's position
  11387. shadowMatrix.makeTranslation( - _lightPositionWorld.x, - _lightPositionWorld.y, - _lightPositionWorld.z );
  11388. } else {
  11389. faceCount = 1;
  11390. _lookTarget.setFromMatrixPosition( light.target.matrixWorld );
  11391. shadowCamera.lookAt( _lookTarget );
  11392. shadowCamera.updateMatrixWorld();
  11393. // compute shadow matrix
  11394. shadowMatrix.set(
  11395. 0.5, 0.0, 0.0, 0.5,
  11396. 0.0, 0.5, 0.0, 0.5,
  11397. 0.0, 0.0, 0.5, 0.5,
  11398. 0.0, 0.0, 0.0, 1.0
  11399. );
  11400. shadowMatrix.multiply( shadowCamera.projectionMatrix );
  11401. shadowMatrix.multiply( shadowCamera.matrixWorldInverse );
  11402. }
  11403. _renderer.setRenderTarget( shadowMap );
  11404. _renderer.clear();
  11405. // render shadow map for each cube face (if omni-directional) or
  11406. // run a single pass if not
  11407. for ( var face = 0; face < faceCount; face ++ ) {
  11408. if ( isPointLight ) {
  11409. _lookTarget.copy( shadowCamera.position );
  11410. _lookTarget.add( cubeDirections[ face ] );
  11411. shadowCamera.up.copy( cubeUps[ face ] );
  11412. shadowCamera.lookAt( _lookTarget );
  11413. shadowCamera.updateMatrixWorld();
  11414. var vpDimensions = cube2DViewPorts[ face ];
  11415. _state.viewport( vpDimensions );
  11416. }
  11417. // update camera matrices and frustum
  11418. _projScreenMatrix.multiplyMatrices( shadowCamera.projectionMatrix, shadowCamera.matrixWorldInverse );
  11419. _frustum.setFromMatrix( _projScreenMatrix );
  11420. // set object matrices & frustum culling
  11421. renderObject( scene, camera, shadowCamera, isPointLight );
  11422. }
  11423. }
  11424. scope.needsUpdate = false;
  11425. _renderer.setRenderTarget( currentRenderTarget, activeCubeFace, activeMipMapLevel );
  11426. };
  11427. function getDepthMaterial( object, material, isPointLight, lightPositionWorld, shadowCameraNear, shadowCameraFar ) {
  11428. var geometry = object.geometry;
  11429. var result = null;
  11430. var materialVariants = _depthMaterials;
  11431. var customMaterial = object.customDepthMaterial;
  11432. if ( isPointLight ) {
  11433. materialVariants = _distanceMaterials;
  11434. customMaterial = object.customDistanceMaterial;
  11435. }
  11436. if ( ! customMaterial ) {
  11437. var useMorphing = false;
  11438. if ( material.morphTargets ) {
  11439. if ( geometry && geometry.isBufferGeometry ) {
  11440. useMorphing = geometry.morphAttributes && geometry.morphAttributes.position && geometry.morphAttributes.position.length > 0;
  11441. } else if ( geometry && geometry.isGeometry ) {
  11442. useMorphing = geometry.morphTargets && geometry.morphTargets.length > 0;
  11443. }
  11444. }
  11445. if ( object.isSkinnedMesh && material.skinning === false ) {
  11446. console.warn( 'THREE.WebGLShadowMap: THREE.SkinnedMesh with material.skinning set to false:', object );
  11447. }
  11448. var useSkinning = object.isSkinnedMesh && material.skinning;
  11449. var variantIndex = 0;
  11450. if ( useMorphing ) variantIndex |= _MorphingFlag;
  11451. if ( useSkinning ) variantIndex |= _SkinningFlag;
  11452. result = materialVariants[ variantIndex ];
  11453. } else {
  11454. result = customMaterial;
  11455. }
  11456. if ( _renderer.localClippingEnabled &&
  11457. material.clipShadows === true &&
  11458. material.clippingPlanes.length !== 0 ) {
  11459. // in this case we need a unique material instance reflecting the
  11460. // appropriate state
  11461. var keyA = result.uuid, keyB = material.uuid;
  11462. var materialsForVariant = _materialCache[ keyA ];
  11463. if ( materialsForVariant === undefined ) {
  11464. materialsForVariant = {};
  11465. _materialCache[ keyA ] = materialsForVariant;
  11466. }
  11467. var cachedMaterial = materialsForVariant[ keyB ];
  11468. if ( cachedMaterial === undefined ) {
  11469. cachedMaterial = result.clone();
  11470. materialsForVariant[ keyB ] = cachedMaterial;
  11471. }
  11472. result = cachedMaterial;
  11473. }
  11474. result.visible = material.visible;
  11475. result.wireframe = material.wireframe;
  11476. result.side = ( material.shadowSide != null ) ? material.shadowSide : shadowSide[ material.side ];
  11477. result.clipShadows = material.clipShadows;
  11478. result.clippingPlanes = material.clippingPlanes;
  11479. result.clipIntersection = material.clipIntersection;
  11480. result.wireframeLinewidth = material.wireframeLinewidth;
  11481. result.linewidth = material.linewidth;
  11482. if ( isPointLight && result.isMeshDistanceMaterial ) {
  11483. result.referencePosition.copy( lightPositionWorld );
  11484. result.nearDistance = shadowCameraNear;
  11485. result.farDistance = shadowCameraFar;
  11486. }
  11487. return result;
  11488. }
  11489. function renderObject( object, camera, shadowCamera, isPointLight ) {
  11490. if ( object.visible === false ) return;
  11491. var visible = object.layers.test( camera.layers );
  11492. if ( visible && ( object.isMesh || object.isLine || object.isPoints ) ) {
  11493. if ( object.castShadow && ( ! object.frustumCulled || _frustum.intersectsObject( object ) ) ) {
  11494. object.modelViewMatrix.multiplyMatrices( shadowCamera.matrixWorldInverse, object.matrixWorld );
  11495. var geometry = _objects.update( object );
  11496. var material = object.material;
  11497. if ( Array.isArray( material ) ) {
  11498. var groups = geometry.groups;
  11499. for ( var k = 0, kl = groups.length; k < kl; k ++ ) {
  11500. var group = groups[ k ];
  11501. var groupMaterial = material[ group.materialIndex ];
  11502. if ( groupMaterial && groupMaterial.visible ) {
  11503. var depthMaterial = getDepthMaterial( object, groupMaterial, isPointLight, _lightPositionWorld, shadowCamera.near, shadowCamera.far );
  11504. _renderer.renderBufferDirect( shadowCamera, null, geometry, depthMaterial, object, group );
  11505. }
  11506. }
  11507. } else if ( material.visible ) {
  11508. var depthMaterial = getDepthMaterial( object, material, isPointLight, _lightPositionWorld, shadowCamera.near, shadowCamera.far );
  11509. _renderer.renderBufferDirect( shadowCamera, null, geometry, depthMaterial, object, null );
  11510. }
  11511. }
  11512. }
  11513. var children = object.children;
  11514. for ( var i = 0, l = children.length; i < l; i ++ ) {
  11515. renderObject( children[ i ], camera, shadowCamera, isPointLight );
  11516. }
  11517. }
  11518. }
  11519. /**
  11520. * @author mrdoob / http://mrdoob.com/
  11521. */
  11522. function WebGLState( gl, extensions, utils, capabilities ) {
  11523. function ColorBuffer() {
  11524. var locked = false;
  11525. var color = new Vector4();
  11526. var currentColorMask = null;
  11527. var currentColorClear = new Vector4( 0, 0, 0, 0 );
  11528. return {
  11529. setMask: function ( colorMask ) {
  11530. if ( currentColorMask !== colorMask && ! locked ) {
  11531. gl.colorMask( colorMask, colorMask, colorMask, colorMask );
  11532. currentColorMask = colorMask;
  11533. }
  11534. },
  11535. setLocked: function ( lock ) {
  11536. locked = lock;
  11537. },
  11538. setClear: function ( r, g, b, a, premultipliedAlpha ) {
  11539. if ( premultipliedAlpha === true ) {
  11540. r *= a; g *= a; b *= a;
  11541. }
  11542. color.set( r, g, b, a );
  11543. if ( currentColorClear.equals( color ) === false ) {
  11544. gl.clearColor( r, g, b, a );
  11545. currentColorClear.copy( color );
  11546. }
  11547. },
  11548. reset: function () {
  11549. locked = false;
  11550. currentColorMask = null;
  11551. currentColorClear.set( - 1, 0, 0, 0 ); // set to invalid state
  11552. }
  11553. };
  11554. }
  11555. function DepthBuffer() {
  11556. var locked = false;
  11557. var currentDepthMask = null;
  11558. var currentDepthFunc = null;
  11559. var currentDepthClear = null;
  11560. return {
  11561. setTest: function ( depthTest ) {
  11562. if ( depthTest ) {
  11563. enable( 2929 );
  11564. } else {
  11565. disable( 2929 );
  11566. }
  11567. },
  11568. setMask: function ( depthMask ) {
  11569. if ( currentDepthMask !== depthMask && ! locked ) {
  11570. gl.depthMask( depthMask );
  11571. currentDepthMask = depthMask;
  11572. }
  11573. },
  11574. setFunc: function ( depthFunc ) {
  11575. if ( currentDepthFunc !== depthFunc ) {
  11576. if ( depthFunc ) {
  11577. switch ( depthFunc ) {
  11578. case NeverDepth:
  11579. gl.depthFunc( 512 );
  11580. break;
  11581. case AlwaysDepth:
  11582. gl.depthFunc( 519 );
  11583. break;
  11584. case LessDepth:
  11585. gl.depthFunc( 513 );
  11586. break;
  11587. case LessEqualDepth:
  11588. gl.depthFunc( 515 );
  11589. break;
  11590. case EqualDepth:
  11591. gl.depthFunc( 514 );
  11592. break;
  11593. case GreaterEqualDepth:
  11594. gl.depthFunc( 518 );
  11595. break;
  11596. case GreaterDepth:
  11597. gl.depthFunc( 516 );
  11598. break;
  11599. case NotEqualDepth:
  11600. gl.depthFunc( 517 );
  11601. break;
  11602. default:
  11603. gl.depthFunc( 515 );
  11604. }
  11605. } else {
  11606. gl.depthFunc( 515 );
  11607. }
  11608. currentDepthFunc = depthFunc;
  11609. }
  11610. },
  11611. setLocked: function ( lock ) {
  11612. locked = lock;
  11613. },
  11614. setClear: function ( depth ) {
  11615. if ( currentDepthClear !== depth ) {
  11616. gl.clearDepth( depth );
  11617. currentDepthClear = depth;
  11618. }
  11619. },
  11620. reset: function () {
  11621. locked = false;
  11622. currentDepthMask = null;
  11623. currentDepthFunc = null;
  11624. currentDepthClear = null;
  11625. }
  11626. };
  11627. }
  11628. function StencilBuffer() {
  11629. var locked = false;
  11630. var currentStencilMask = null;
  11631. var currentStencilFunc = null;
  11632. var currentStencilRef = null;
  11633. var currentStencilFuncMask = null;
  11634. var currentStencilFail = null;
  11635. var currentStencilZFail = null;
  11636. var currentStencilZPass = null;
  11637. var currentStencilClear = null;
  11638. return {
  11639. setTest: function ( stencilTest ) {
  11640. if ( stencilTest ) {
  11641. enable( 2960 );
  11642. } else {
  11643. disable( 2960 );
  11644. }
  11645. },
  11646. setMask: function ( stencilMask ) {
  11647. if ( currentStencilMask !== stencilMask && ! locked ) {
  11648. gl.stencilMask( stencilMask );
  11649. currentStencilMask = stencilMask;
  11650. }
  11651. },
  11652. setFunc: function ( stencilFunc, stencilRef, stencilMask ) {
  11653. if ( currentStencilFunc !== stencilFunc ||
  11654. currentStencilRef !== stencilRef ||
  11655. currentStencilFuncMask !== stencilMask ) {
  11656. gl.stencilFunc( stencilFunc, stencilRef, stencilMask );
  11657. currentStencilFunc = stencilFunc;
  11658. currentStencilRef = stencilRef;
  11659. currentStencilFuncMask = stencilMask;
  11660. }
  11661. },
  11662. setOp: function ( stencilFail, stencilZFail, stencilZPass ) {
  11663. if ( currentStencilFail !== stencilFail ||
  11664. currentStencilZFail !== stencilZFail ||
  11665. currentStencilZPass !== stencilZPass ) {
  11666. gl.stencilOp( stencilFail, stencilZFail, stencilZPass );
  11667. currentStencilFail = stencilFail;
  11668. currentStencilZFail = stencilZFail;
  11669. currentStencilZPass = stencilZPass;
  11670. }
  11671. },
  11672. setLocked: function ( lock ) {
  11673. locked = lock;
  11674. },
  11675. setClear: function ( stencil ) {
  11676. if ( currentStencilClear !== stencil ) {
  11677. gl.clearStencil( stencil );
  11678. currentStencilClear = stencil;
  11679. }
  11680. },
  11681. reset: function () {
  11682. locked = false;
  11683. currentStencilMask = null;
  11684. currentStencilFunc = null;
  11685. currentStencilRef = null;
  11686. currentStencilFuncMask = null;
  11687. currentStencilFail = null;
  11688. currentStencilZFail = null;
  11689. currentStencilZPass = null;
  11690. currentStencilClear = null;
  11691. }
  11692. };
  11693. }
  11694. //
  11695. var colorBuffer = new ColorBuffer();
  11696. var depthBuffer = new DepthBuffer();
  11697. var stencilBuffer = new StencilBuffer();
  11698. var maxVertexAttributes = gl.getParameter( 34921 );
  11699. var newAttributes = new Uint8Array( maxVertexAttributes );
  11700. var enabledAttributes = new Uint8Array( maxVertexAttributes );
  11701. var attributeDivisors = new Uint8Array( maxVertexAttributes );
  11702. var enabledCapabilities = {};
  11703. var compressedTextureFormats = null;
  11704. var currentProgram = null;
  11705. var currentBlendingEnabled = null;
  11706. var currentBlending = null;
  11707. var currentBlendEquation = null;
  11708. var currentBlendSrc = null;
  11709. var currentBlendDst = null;
  11710. var currentBlendEquationAlpha = null;
  11711. var currentBlendSrcAlpha = null;
  11712. var currentBlendDstAlpha = null;
  11713. var currentPremultipledAlpha = false;
  11714. var currentFlipSided = null;
  11715. var currentCullFace = null;
  11716. var currentLineWidth = null;
  11717. var currentPolygonOffsetFactor = null;
  11718. var currentPolygonOffsetUnits = null;
  11719. var maxTextures = gl.getParameter( 35661 );
  11720. var lineWidthAvailable = false;
  11721. var version = 0;
  11722. var glVersion = gl.getParameter( 7938 );
  11723. if ( glVersion.indexOf( 'WebGL' ) !== - 1 ) {
  11724. version = parseFloat( /^WebGL\ ([0-9])/.exec( glVersion )[ 1 ] );
  11725. lineWidthAvailable = ( version >= 1.0 );
  11726. } else if ( glVersion.indexOf( 'OpenGL ES' ) !== - 1 ) {
  11727. version = parseFloat( /^OpenGL\ ES\ ([0-9])/.exec( glVersion )[ 1 ] );
  11728. lineWidthAvailable = ( version >= 2.0 );
  11729. }
  11730. var currentTextureSlot = null;
  11731. var currentBoundTextures = {};
  11732. var currentScissor = new Vector4();
  11733. var currentViewport = new Vector4();
  11734. function createTexture( type, target, count ) {
  11735. var data = new Uint8Array( 4 ); // 4 is required to match default unpack alignment of 4.
  11736. var texture = gl.createTexture();
  11737. gl.bindTexture( type, texture );
  11738. gl.texParameteri( type, 10241, 9728 );
  11739. gl.texParameteri( type, 10240, 9728 );
  11740. for ( var i = 0; i < count; i ++ ) {
  11741. gl.texImage2D( target + i, 0, 6408, 1, 1, 0, 6408, 5121, data );
  11742. }
  11743. return texture;
  11744. }
  11745. var emptyTextures = {};
  11746. emptyTextures[ 3553 ] = createTexture( 3553, 3553, 1 );
  11747. emptyTextures[ 34067 ] = createTexture( 34067, 34069, 6 );
  11748. // init
  11749. colorBuffer.setClear( 0, 0, 0, 1 );
  11750. depthBuffer.setClear( 1 );
  11751. stencilBuffer.setClear( 0 );
  11752. enable( 2929 );
  11753. depthBuffer.setFunc( LessEqualDepth );
  11754. setFlipSided( false );
  11755. setCullFace( CullFaceBack );
  11756. enable( 2884 );
  11757. setBlending( NoBlending );
  11758. //
  11759. function initAttributes() {
  11760. for ( var i = 0, l = newAttributes.length; i < l; i ++ ) {
  11761. newAttributes[ i ] = 0;
  11762. }
  11763. }
  11764. function enableAttribute( attribute ) {
  11765. enableAttributeAndDivisor( attribute, 0 );
  11766. }
  11767. function enableAttributeAndDivisor( attribute, meshPerAttribute ) {
  11768. newAttributes[ attribute ] = 1;
  11769. if ( enabledAttributes[ attribute ] === 0 ) {
  11770. gl.enableVertexAttribArray( attribute );
  11771. enabledAttributes[ attribute ] = 1;
  11772. }
  11773. if ( attributeDivisors[ attribute ] !== meshPerAttribute ) {
  11774. var extension = capabilities.isWebGL2 ? gl : extensions.get( 'ANGLE_instanced_arrays' );
  11775. extension[ capabilities.isWebGL2 ? 'vertexAttribDivisor' : 'vertexAttribDivisorANGLE' ]( attribute, meshPerAttribute );
  11776. attributeDivisors[ attribute ] = meshPerAttribute;
  11777. }
  11778. }
  11779. function disableUnusedAttributes() {
  11780. for ( var i = 0, l = enabledAttributes.length; i !== l; ++ i ) {
  11781. if ( enabledAttributes[ i ] !== newAttributes[ i ] ) {
  11782. gl.disableVertexAttribArray( i );
  11783. enabledAttributes[ i ] = 0;
  11784. }
  11785. }
  11786. }
  11787. function enable( id ) {
  11788. if ( enabledCapabilities[ id ] !== true ) {
  11789. gl.enable( id );
  11790. enabledCapabilities[ id ] = true;
  11791. }
  11792. }
  11793. function disable( id ) {
  11794. if ( enabledCapabilities[ id ] !== false ) {
  11795. gl.disable( id );
  11796. enabledCapabilities[ id ] = false;
  11797. }
  11798. }
  11799. function getCompressedTextureFormats() {
  11800. if ( compressedTextureFormats === null ) {
  11801. compressedTextureFormats = [];
  11802. if ( extensions.get( 'WEBGL_compressed_texture_pvrtc' ) ||
  11803. extensions.get( 'WEBGL_compressed_texture_s3tc' ) ||
  11804. extensions.get( 'WEBGL_compressed_texture_etc1' ) ||
  11805. extensions.get( 'WEBGL_compressed_texture_astc' ) ) {
  11806. var formats = gl.getParameter( 34467 );
  11807. for ( var i = 0; i < formats.length; i ++ ) {
  11808. compressedTextureFormats.push( formats[ i ] );
  11809. }
  11810. }
  11811. }
  11812. return compressedTextureFormats;
  11813. }
  11814. function useProgram( program ) {
  11815. if ( currentProgram !== program ) {
  11816. gl.useProgram( program );
  11817. currentProgram = program;
  11818. return true;
  11819. }
  11820. return false;
  11821. }
  11822. function setBlending( blending, blendEquation, blendSrc, blendDst, blendEquationAlpha, blendSrcAlpha, blendDstAlpha, premultipliedAlpha ) {
  11823. if ( blending === NoBlending ) {
  11824. if ( currentBlendingEnabled ) {
  11825. disable( 3042 );
  11826. currentBlendingEnabled = false;
  11827. }
  11828. return;
  11829. }
  11830. if ( ! currentBlendingEnabled ) {
  11831. enable( 3042 );
  11832. currentBlendingEnabled = true;
  11833. }
  11834. if ( blending !== CustomBlending ) {
  11835. if ( blending !== currentBlending || premultipliedAlpha !== currentPremultipledAlpha ) {
  11836. if ( currentBlendEquation !== AddEquation || currentBlendEquationAlpha !== AddEquation ) {
  11837. gl.blendEquation( 32774 );
  11838. currentBlendEquation = AddEquation;
  11839. currentBlendEquationAlpha = AddEquation;
  11840. }
  11841. if ( premultipliedAlpha ) {
  11842. switch ( blending ) {
  11843. case NormalBlending:
  11844. gl.blendFuncSeparate( 1, 771, 1, 771 );
  11845. break;
  11846. case AdditiveBlending:
  11847. gl.blendFunc( 1, 1 );
  11848. break;
  11849. case SubtractiveBlending:
  11850. gl.blendFuncSeparate( 0, 0, 769, 771 );
  11851. break;
  11852. case MultiplyBlending:
  11853. gl.blendFuncSeparate( 0, 768, 0, 770 );
  11854. break;
  11855. default:
  11856. console.error( 'THREE.WebGLState: Invalid blending: ', blending );
  11857. break;
  11858. }
  11859. } else {
  11860. switch ( blending ) {
  11861. case NormalBlending:
  11862. gl.blendFuncSeparate( 770, 771, 1, 771 );
  11863. break;
  11864. case AdditiveBlending:
  11865. gl.blendFunc( 770, 1 );
  11866. break;
  11867. case SubtractiveBlending:
  11868. gl.blendFunc( 0, 769 );
  11869. break;
  11870. case MultiplyBlending:
  11871. gl.blendFunc( 0, 768 );
  11872. break;
  11873. default:
  11874. console.error( 'THREE.WebGLState: Invalid blending: ', blending );
  11875. break;
  11876. }
  11877. }
  11878. currentBlendSrc = null;
  11879. currentBlendDst = null;
  11880. currentBlendSrcAlpha = null;
  11881. currentBlendDstAlpha = null;
  11882. currentBlending = blending;
  11883. currentPremultipledAlpha = premultipliedAlpha;
  11884. }
  11885. return;
  11886. }
  11887. // custom blending
  11888. blendEquationAlpha = blendEquationAlpha || blendEquation;
  11889. blendSrcAlpha = blendSrcAlpha || blendSrc;
  11890. blendDstAlpha = blendDstAlpha || blendDst;
  11891. if ( blendEquation !== currentBlendEquation || blendEquationAlpha !== currentBlendEquationAlpha ) {
  11892. gl.blendEquationSeparate( utils.convert( blendEquation ), utils.convert( blendEquationAlpha ) );
  11893. currentBlendEquation = blendEquation;
  11894. currentBlendEquationAlpha = blendEquationAlpha;
  11895. }
  11896. if ( blendSrc !== currentBlendSrc || blendDst !== currentBlendDst || blendSrcAlpha !== currentBlendSrcAlpha || blendDstAlpha !== currentBlendDstAlpha ) {
  11897. gl.blendFuncSeparate( utils.convert( blendSrc ), utils.convert( blendDst ), utils.convert( blendSrcAlpha ), utils.convert( blendDstAlpha ) );
  11898. currentBlendSrc = blendSrc;
  11899. currentBlendDst = blendDst;
  11900. currentBlendSrcAlpha = blendSrcAlpha;
  11901. currentBlendDstAlpha = blendDstAlpha;
  11902. }
  11903. currentBlending = blending;
  11904. currentPremultipledAlpha = null;
  11905. }
  11906. function setMaterial( material, frontFaceCW ) {
  11907. material.side === DoubleSide
  11908. ? disable( 2884 )
  11909. : enable( 2884 );
  11910. var flipSided = ( material.side === BackSide );
  11911. if ( frontFaceCW ) flipSided = ! flipSided;
  11912. setFlipSided( flipSided );
  11913. ( material.blending === NormalBlending && material.transparent === false )
  11914. ? setBlending( NoBlending )
  11915. : setBlending( material.blending, material.blendEquation, material.blendSrc, material.blendDst, material.blendEquationAlpha, material.blendSrcAlpha, material.blendDstAlpha, material.premultipliedAlpha );
  11916. depthBuffer.setFunc( material.depthFunc );
  11917. depthBuffer.setTest( material.depthTest );
  11918. depthBuffer.setMask( material.depthWrite );
  11919. colorBuffer.setMask( material.colorWrite );
  11920. setPolygonOffset( material.polygonOffset, material.polygonOffsetFactor, material.polygonOffsetUnits );
  11921. }
  11922. //
  11923. function setFlipSided( flipSided ) {
  11924. if ( currentFlipSided !== flipSided ) {
  11925. if ( flipSided ) {
  11926. gl.frontFace( 2304 );
  11927. } else {
  11928. gl.frontFace( 2305 );
  11929. }
  11930. currentFlipSided = flipSided;
  11931. }
  11932. }
  11933. function setCullFace( cullFace ) {
  11934. if ( cullFace !== CullFaceNone ) {
  11935. enable( 2884 );
  11936. if ( cullFace !== currentCullFace ) {
  11937. if ( cullFace === CullFaceBack ) {
  11938. gl.cullFace( 1029 );
  11939. } else if ( cullFace === CullFaceFront ) {
  11940. gl.cullFace( 1028 );
  11941. } else {
  11942. gl.cullFace( 1032 );
  11943. }
  11944. }
  11945. } else {
  11946. disable( 2884 );
  11947. }
  11948. currentCullFace = cullFace;
  11949. }
  11950. function setLineWidth( width ) {
  11951. if ( width !== currentLineWidth ) {
  11952. if ( lineWidthAvailable ) gl.lineWidth( width );
  11953. currentLineWidth = width;
  11954. }
  11955. }
  11956. function setPolygonOffset( polygonOffset, factor, units ) {
  11957. if ( polygonOffset ) {
  11958. enable( 32823 );
  11959. if ( currentPolygonOffsetFactor !== factor || currentPolygonOffsetUnits !== units ) {
  11960. gl.polygonOffset( factor, units );
  11961. currentPolygonOffsetFactor = factor;
  11962. currentPolygonOffsetUnits = units;
  11963. }
  11964. } else {
  11965. disable( 32823 );
  11966. }
  11967. }
  11968. function setScissorTest( scissorTest ) {
  11969. if ( scissorTest ) {
  11970. enable( 3089 );
  11971. } else {
  11972. disable( 3089 );
  11973. }
  11974. }
  11975. // texture
  11976. function activeTexture( webglSlot ) {
  11977. if ( webglSlot === undefined ) webglSlot = 33984 + maxTextures - 1;
  11978. if ( currentTextureSlot !== webglSlot ) {
  11979. gl.activeTexture( webglSlot );
  11980. currentTextureSlot = webglSlot;
  11981. }
  11982. }
  11983. function bindTexture( webglType, webglTexture ) {
  11984. if ( currentTextureSlot === null ) {
  11985. activeTexture();
  11986. }
  11987. var boundTexture = currentBoundTextures[ currentTextureSlot ];
  11988. if ( boundTexture === undefined ) {
  11989. boundTexture = { type: undefined, texture: undefined };
  11990. currentBoundTextures[ currentTextureSlot ] = boundTexture;
  11991. }
  11992. if ( boundTexture.type !== webglType || boundTexture.texture !== webglTexture ) {
  11993. gl.bindTexture( webglType, webglTexture || emptyTextures[ webglType ] );
  11994. boundTexture.type = webglType;
  11995. boundTexture.texture = webglTexture;
  11996. }
  11997. }
  11998. function compressedTexImage2D() {
  11999. try {
  12000. gl.compressedTexImage2D.apply( gl, arguments );
  12001. } catch ( error ) {
  12002. console.error( 'THREE.WebGLState:', error );
  12003. }
  12004. }
  12005. function texImage2D() {
  12006. try {
  12007. gl.texImage2D.apply( gl, arguments );
  12008. } catch ( error ) {
  12009. console.error( 'THREE.WebGLState:', error );
  12010. }
  12011. }
  12012. function texImage3D() {
  12013. try {
  12014. gl.texImage3D.apply( gl, arguments );
  12015. } catch ( error ) {
  12016. console.error( 'THREE.WebGLState:', error );
  12017. }
  12018. }
  12019. //
  12020. function scissor( scissor ) {
  12021. if ( currentScissor.equals( scissor ) === false ) {
  12022. gl.scissor( scissor.x, scissor.y, scissor.z, scissor.w );
  12023. currentScissor.copy( scissor );
  12024. }
  12025. }
  12026. function viewport( viewport ) {
  12027. if ( currentViewport.equals( viewport ) === false ) {
  12028. gl.viewport( viewport.x, viewport.y, viewport.z, viewport.w );
  12029. currentViewport.copy( viewport );
  12030. }
  12031. }
  12032. //
  12033. function reset() {
  12034. for ( var i = 0; i < enabledAttributes.length; i ++ ) {
  12035. if ( enabledAttributes[ i ] === 1 ) {
  12036. gl.disableVertexAttribArray( i );
  12037. enabledAttributes[ i ] = 0;
  12038. }
  12039. }
  12040. enabledCapabilities = {};
  12041. compressedTextureFormats = null;
  12042. currentTextureSlot = null;
  12043. currentBoundTextures = {};
  12044. currentProgram = null;
  12045. currentBlending = null;
  12046. currentFlipSided = null;
  12047. currentCullFace = null;
  12048. colorBuffer.reset();
  12049. depthBuffer.reset();
  12050. stencilBuffer.reset();
  12051. }
  12052. return {
  12053. buffers: {
  12054. color: colorBuffer,
  12055. depth: depthBuffer,
  12056. stencil: stencilBuffer
  12057. },
  12058. initAttributes: initAttributes,
  12059. enableAttribute: enableAttribute,
  12060. enableAttributeAndDivisor: enableAttributeAndDivisor,
  12061. disableUnusedAttributes: disableUnusedAttributes,
  12062. enable: enable,
  12063. disable: disable,
  12064. getCompressedTextureFormats: getCompressedTextureFormats,
  12065. useProgram: useProgram,
  12066. setBlending: setBlending,
  12067. setMaterial: setMaterial,
  12068. setFlipSided: setFlipSided,
  12069. setCullFace: setCullFace,
  12070. setLineWidth: setLineWidth,
  12071. setPolygonOffset: setPolygonOffset,
  12072. setScissorTest: setScissorTest,
  12073. activeTexture: activeTexture,
  12074. bindTexture: bindTexture,
  12075. compressedTexImage2D: compressedTexImage2D,
  12076. texImage2D: texImage2D,
  12077. texImage3D: texImage3D,
  12078. scissor: scissor,
  12079. viewport: viewport,
  12080. reset: reset
  12081. };
  12082. }
  12083. /**
  12084. * @author mrdoob / http://mrdoob.com/
  12085. */
  12086. function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, info ) {
  12087. var _videoTextures = {};
  12088. var _canvas;
  12089. //
  12090. var useOffscreenCanvas = typeof OffscreenCanvas !== 'undefined';
  12091. function createCanvas( width, height ) {
  12092. // Use OffscreenCanvas when available. Specially needed in web workers
  12093. return useOffscreenCanvas ?
  12094. new OffscreenCanvas( width, height ) :
  12095. document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' );
  12096. }
  12097. function resizeImage( image, needsPowerOfTwo, needsNewCanvas, maxSize ) {
  12098. var scale = 1;
  12099. // handle case if texture exceeds max size
  12100. if ( image.width > maxSize || image.height > maxSize ) {
  12101. scale = maxSize / Math.max( image.width, image.height );
  12102. }
  12103. // only perform resize if necessary
  12104. if ( scale < 1 || needsPowerOfTwo === true ) {
  12105. // only perform resize for certain image types
  12106. if ( ( typeof HTMLImageElement !== 'undefined' && image instanceof HTMLImageElement ) ||
  12107. ( typeof HTMLCanvasElement !== 'undefined' && image instanceof HTMLCanvasElement ) ||
  12108. ( typeof ImageBitmap !== 'undefined' && image instanceof ImageBitmap ) ) {
  12109. var floor = needsPowerOfTwo ? _Math.floorPowerOfTwo : Math.floor;
  12110. var width = floor( scale * image.width );
  12111. var height = floor( scale * image.height );
  12112. if ( _canvas === undefined ) _canvas = createCanvas( width, height );
  12113. // cube textures can't reuse the same canvas
  12114. var canvas = needsNewCanvas ? createCanvas( width, height ) : _canvas;
  12115. canvas.width = width;
  12116. canvas.height = height;
  12117. var context = canvas.getContext( '2d' );
  12118. context.drawImage( image, 0, 0, width, height );
  12119. console.warn( 'THREE.WebGLRenderer: Texture has been resized from (' + image.width + 'x' + image.height + ') to (' + width + 'x' + height + ').' );
  12120. return canvas;
  12121. } else {
  12122. if ( 'data' in image ) {
  12123. console.warn( 'THREE.WebGLRenderer: Image in DataTexture is too big (' + image.width + 'x' + image.height + ').' );
  12124. }
  12125. return image;
  12126. }
  12127. }
  12128. return image;
  12129. }
  12130. function isPowerOfTwo( image ) {
  12131. return _Math.isPowerOfTwo( image.width ) && _Math.isPowerOfTwo( image.height );
  12132. }
  12133. function textureNeedsPowerOfTwo( texture ) {
  12134. if ( capabilities.isWebGL2 ) return false;
  12135. return ( texture.wrapS !== ClampToEdgeWrapping || texture.wrapT !== ClampToEdgeWrapping ) ||
  12136. ( texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter );
  12137. }
  12138. function textureNeedsGenerateMipmaps( texture, supportsMips ) {
  12139. return texture.generateMipmaps && supportsMips &&
  12140. texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter;
  12141. }
  12142. function generateMipmap( target, texture, width, height ) {
  12143. _gl.generateMipmap( target );
  12144. var textureProperties = properties.get( texture );
  12145. // Note: Math.log( x ) * Math.LOG2E used instead of Math.log2( x ) which is not supported by IE11
  12146. textureProperties.__maxMipLevel = Math.log( Math.max( width, height ) ) * Math.LOG2E;
  12147. }
  12148. function getInternalFormat( glFormat, glType ) {
  12149. if ( ! capabilities.isWebGL2 ) return glFormat;
  12150. var internalFormat = glFormat;
  12151. if ( glFormat === 6403 ) {
  12152. if ( glType === 5126 ) internalFormat = 33326;
  12153. if ( glType === 5131 ) internalFormat = 33325;
  12154. if ( glType === 5121 ) internalFormat = 33321;
  12155. }
  12156. if ( glFormat === 6407 ) {
  12157. if ( glType === 5126 ) internalFormat = 34837;
  12158. if ( glType === 5131 ) internalFormat = 34843;
  12159. if ( glType === 5121 ) internalFormat = 32849;
  12160. }
  12161. if ( glFormat === 6408 ) {
  12162. if ( glType === 5126 ) internalFormat = 34836;
  12163. if ( glType === 5131 ) internalFormat = 34842;
  12164. if ( glType === 5121 ) internalFormat = 32856;
  12165. }
  12166. if ( internalFormat === 33325 || internalFormat === 33326 ||
  12167. internalFormat === 34842 || internalFormat === 34836 ) {
  12168. extensions.get( 'EXT_color_buffer_float' );
  12169. } else if ( internalFormat === 34843 || internalFormat === 34837 ) {
  12170. console.warn( 'THREE.WebGLRenderer: Floating point textures with RGB format not supported. Please use RGBA instead.' );
  12171. }
  12172. return internalFormat;
  12173. }
  12174. // Fallback filters for non-power-of-2 textures
  12175. function filterFallback( f ) {
  12176. if ( f === NearestFilter || f === NearestMipMapNearestFilter || f === NearestMipMapLinearFilter ) {
  12177. return 9728;
  12178. }
  12179. return 9729;
  12180. }
  12181. //
  12182. function onTextureDispose( event ) {
  12183. var texture = event.target;
  12184. texture.removeEventListener( 'dispose', onTextureDispose );
  12185. deallocateTexture( texture );
  12186. if ( texture.isVideoTexture ) {
  12187. delete _videoTextures[ texture.id ];
  12188. }
  12189. info.memory.textures --;
  12190. }
  12191. function onRenderTargetDispose( event ) {
  12192. var renderTarget = event.target;
  12193. renderTarget.removeEventListener( 'dispose', onRenderTargetDispose );
  12194. deallocateRenderTarget( renderTarget );
  12195. info.memory.textures --;
  12196. }
  12197. //
  12198. function deallocateTexture( texture ) {
  12199. var textureProperties = properties.get( texture );
  12200. if ( textureProperties.__webglInit === undefined ) return;
  12201. _gl.deleteTexture( textureProperties.__webglTexture );
  12202. properties.remove( texture );
  12203. }
  12204. function deallocateRenderTarget( renderTarget ) {
  12205. var renderTargetProperties = properties.get( renderTarget );
  12206. var textureProperties = properties.get( renderTarget.texture );
  12207. if ( ! renderTarget ) return;
  12208. if ( textureProperties.__webglTexture !== undefined ) {
  12209. _gl.deleteTexture( textureProperties.__webglTexture );
  12210. }
  12211. if ( renderTarget.depthTexture ) {
  12212. renderTarget.depthTexture.dispose();
  12213. }
  12214. if ( renderTarget.isWebGLRenderTargetCube ) {
  12215. for ( var i = 0; i < 6; i ++ ) {
  12216. _gl.deleteFramebuffer( renderTargetProperties.__webglFramebuffer[ i ] );
  12217. if ( renderTargetProperties.__webglDepthbuffer ) _gl.deleteRenderbuffer( renderTargetProperties.__webglDepthbuffer[ i ] );
  12218. }
  12219. } else {
  12220. _gl.deleteFramebuffer( renderTargetProperties.__webglFramebuffer );
  12221. if ( renderTargetProperties.__webglDepthbuffer ) _gl.deleteRenderbuffer( renderTargetProperties.__webglDepthbuffer );
  12222. }
  12223. properties.remove( renderTarget.texture );
  12224. properties.remove( renderTarget );
  12225. }
  12226. //
  12227. var textureUnits = 0;
  12228. function resetTextureUnits() {
  12229. textureUnits = 0;
  12230. }
  12231. function allocateTextureUnit() {
  12232. var textureUnit = textureUnits;
  12233. if ( textureUnit >= capabilities.maxTextures ) {
  12234. console.warn( 'THREE.WebGLTextures: Trying to use ' + textureUnit + ' texture units while this GPU supports only ' + capabilities.maxTextures );
  12235. }
  12236. textureUnits += 1;
  12237. return textureUnit;
  12238. }
  12239. //
  12240. function setTexture2D( texture, slot ) {
  12241. var textureProperties = properties.get( texture );
  12242. if ( texture.isVideoTexture ) updateVideoTexture( texture );
  12243. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  12244. var image = texture.image;
  12245. if ( image === undefined ) {
  12246. console.warn( 'THREE.WebGLRenderer: Texture marked for update but image is undefined' );
  12247. } else if ( image.complete === false ) {
  12248. console.warn( 'THREE.WebGLRenderer: Texture marked for update but image is incomplete' );
  12249. } else {
  12250. uploadTexture( textureProperties, texture, slot );
  12251. return;
  12252. }
  12253. }
  12254. state.activeTexture( 33984 + slot );
  12255. state.bindTexture( 3553, textureProperties.__webglTexture );
  12256. }
  12257. function setTexture2DArray( texture, slot ) {
  12258. var textureProperties = properties.get( texture );
  12259. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  12260. uploadTexture( textureProperties, texture, slot );
  12261. return;
  12262. }
  12263. state.activeTexture( 33984 + slot );
  12264. state.bindTexture( 35866, textureProperties.__webglTexture );
  12265. }
  12266. function setTexture3D( texture, slot ) {
  12267. var textureProperties = properties.get( texture );
  12268. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  12269. uploadTexture( textureProperties, texture, slot );
  12270. return;
  12271. }
  12272. state.activeTexture( 33984 + slot );
  12273. state.bindTexture( 32879, textureProperties.__webglTexture );
  12274. }
  12275. function setTextureCube( texture, slot ) {
  12276. var textureProperties = properties.get( texture );
  12277. if ( texture.image.length === 6 ) {
  12278. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  12279. initTexture( textureProperties, texture );
  12280. state.activeTexture( 33984 + slot );
  12281. state.bindTexture( 34067, textureProperties.__webglTexture );
  12282. _gl.pixelStorei( 37440, texture.flipY );
  12283. var isCompressed = ( texture && texture.isCompressedTexture );
  12284. var isDataTexture = ( texture.image[ 0 ] && texture.image[ 0 ].isDataTexture );
  12285. var cubeImage = [];
  12286. for ( var i = 0; i < 6; i ++ ) {
  12287. if ( ! isCompressed && ! isDataTexture ) {
  12288. cubeImage[ i ] = resizeImage( texture.image[ i ], false, true, capabilities.maxCubemapSize );
  12289. } else {
  12290. cubeImage[ i ] = isDataTexture ? texture.image[ i ].image : texture.image[ i ];
  12291. }
  12292. }
  12293. var image = cubeImage[ 0 ],
  12294. supportsMips = isPowerOfTwo( image ) || capabilities.isWebGL2,
  12295. glFormat = utils.convert( texture.format ),
  12296. glType = utils.convert( texture.type ),
  12297. glInternalFormat = getInternalFormat( glFormat, glType );
  12298. setTextureParameters( 34067, texture, supportsMips );
  12299. for ( var i = 0; i < 6; i ++ ) {
  12300. if ( ! isCompressed ) {
  12301. if ( isDataTexture ) {
  12302. state.texImage2D( 34069 + i, 0, glInternalFormat, cubeImage[ i ].width, cubeImage[ i ].height, 0, glFormat, glType, cubeImage[ i ].data );
  12303. } else {
  12304. state.texImage2D( 34069 + i, 0, glInternalFormat, glFormat, glType, cubeImage[ i ] );
  12305. }
  12306. } else {
  12307. var mipmap, mipmaps = cubeImage[ i ].mipmaps;
  12308. for ( var j = 0, jl = mipmaps.length; j < jl; j ++ ) {
  12309. mipmap = mipmaps[ j ];
  12310. if ( texture.format !== RGBAFormat && texture.format !== RGBFormat ) {
  12311. if ( state.getCompressedTextureFormats().indexOf( glFormat ) > - 1 ) {
  12312. state.compressedTexImage2D( 34069 + i, j, glInternalFormat, mipmap.width, mipmap.height, 0, mipmap.data );
  12313. } else {
  12314. console.warn( 'THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .setTextureCube()' );
  12315. }
  12316. } else {
  12317. state.texImage2D( 34069 + i, j, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  12318. }
  12319. }
  12320. }
  12321. }
  12322. if ( ! isCompressed ) {
  12323. textureProperties.__maxMipLevel = 0;
  12324. } else {
  12325. textureProperties.__maxMipLevel = mipmaps.length - 1;
  12326. }
  12327. if ( textureNeedsGenerateMipmaps( texture, supportsMips ) ) {
  12328. // We assume images for cube map have the same size.
  12329. generateMipmap( 34067, texture, image.width, image.height );
  12330. }
  12331. textureProperties.__version = texture.version;
  12332. if ( texture.onUpdate ) texture.onUpdate( texture );
  12333. } else {
  12334. state.activeTexture( 33984 + slot );
  12335. state.bindTexture( 34067, textureProperties.__webglTexture );
  12336. }
  12337. }
  12338. }
  12339. function setTextureCubeDynamic( texture, slot ) {
  12340. state.activeTexture( 33984 + slot );
  12341. state.bindTexture( 34067, properties.get( texture ).__webglTexture );
  12342. }
  12343. function setTextureParameters( textureType, texture, supportsMips ) {
  12344. var extension;
  12345. if ( supportsMips ) {
  12346. _gl.texParameteri( textureType, 10242, utils.convert( texture.wrapS ) );
  12347. _gl.texParameteri( textureType, 10243, utils.convert( texture.wrapT ) );
  12348. if ( textureType === 32879 || textureType === 35866 ) {
  12349. _gl.texParameteri( textureType, 32882, utils.convert( texture.wrapR ) );
  12350. }
  12351. _gl.texParameteri( textureType, 10240, utils.convert( texture.magFilter ) );
  12352. _gl.texParameteri( textureType, 10241, utils.convert( texture.minFilter ) );
  12353. } else {
  12354. _gl.texParameteri( textureType, 10242, 33071 );
  12355. _gl.texParameteri( textureType, 10243, 33071 );
  12356. if ( textureType === 32879 || textureType === 35866 ) {
  12357. _gl.texParameteri( textureType, 32882, 33071 );
  12358. }
  12359. if ( texture.wrapS !== ClampToEdgeWrapping || texture.wrapT !== ClampToEdgeWrapping ) {
  12360. console.warn( 'THREE.WebGLRenderer: Texture is not power of two. Texture.wrapS and Texture.wrapT should be set to THREE.ClampToEdgeWrapping.' );
  12361. }
  12362. _gl.texParameteri( textureType, 10240, filterFallback( texture.magFilter ) );
  12363. _gl.texParameteri( textureType, 10241, filterFallback( texture.minFilter ) );
  12364. if ( texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter ) {
  12365. console.warn( 'THREE.WebGLRenderer: Texture is not power of two. Texture.minFilter should be set to THREE.NearestFilter or THREE.LinearFilter.' );
  12366. }
  12367. }
  12368. extension = extensions.get( 'EXT_texture_filter_anisotropic' );
  12369. if ( extension ) {
  12370. if ( texture.type === FloatType && extensions.get( 'OES_texture_float_linear' ) === null ) return;
  12371. if ( texture.type === HalfFloatType && ( capabilities.isWebGL2 || extensions.get( 'OES_texture_half_float_linear' ) ) === null ) return;
  12372. if ( texture.anisotropy > 1 || properties.get( texture ).__currentAnisotropy ) {
  12373. _gl.texParameterf( textureType, extension.TEXTURE_MAX_ANISOTROPY_EXT, Math.min( texture.anisotropy, capabilities.getMaxAnisotropy() ) );
  12374. properties.get( texture ).__currentAnisotropy = texture.anisotropy;
  12375. }
  12376. }
  12377. }
  12378. function initTexture( textureProperties, texture ) {
  12379. if ( textureProperties.__webglInit === undefined ) {
  12380. textureProperties.__webglInit = true;
  12381. texture.addEventListener( 'dispose', onTextureDispose );
  12382. textureProperties.__webglTexture = _gl.createTexture();
  12383. info.memory.textures ++;
  12384. }
  12385. }
  12386. function uploadTexture( textureProperties, texture, slot ) {
  12387. var textureType = 3553;
  12388. if ( texture.isDataTexture2DArray ) textureType = 35866;
  12389. if ( texture.isDataTexture3D ) textureType = 32879;
  12390. initTexture( textureProperties, texture );
  12391. state.activeTexture( 33984 + slot );
  12392. state.bindTexture( textureType, textureProperties.__webglTexture );
  12393. _gl.pixelStorei( 37440, texture.flipY );
  12394. _gl.pixelStorei( 37441, texture.premultiplyAlpha );
  12395. _gl.pixelStorei( 3317, texture.unpackAlignment );
  12396. var needsPowerOfTwo = textureNeedsPowerOfTwo( texture ) && isPowerOfTwo( texture.image ) === false;
  12397. var image = resizeImage( texture.image, needsPowerOfTwo, false, capabilities.maxTextureSize );
  12398. var supportsMips = isPowerOfTwo( image ) || capabilities.isWebGL2,
  12399. glFormat = utils.convert( texture.format ),
  12400. glType = utils.convert( texture.type ),
  12401. glInternalFormat = getInternalFormat( glFormat, glType );
  12402. setTextureParameters( textureType, texture, supportsMips );
  12403. var mipmap, mipmaps = texture.mipmaps;
  12404. if ( texture.isDepthTexture ) {
  12405. // populate depth texture with dummy data
  12406. glInternalFormat = 6402;
  12407. if ( texture.type === FloatType ) {
  12408. if ( ! capabilities.isWebGL2 ) throw new Error( 'Float Depth Texture only supported in WebGL2.0' );
  12409. glInternalFormat = 36012;
  12410. } else if ( capabilities.isWebGL2 ) {
  12411. // WebGL 2.0 requires signed internalformat for glTexImage2D
  12412. glInternalFormat = 33189;
  12413. }
  12414. if ( texture.format === DepthFormat && glInternalFormat === 6402 ) {
  12415. // The error INVALID_OPERATION is generated by texImage2D if format and internalformat are
  12416. // DEPTH_COMPONENT and type is not UNSIGNED_SHORT or UNSIGNED_INT
  12417. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  12418. if ( texture.type !== UnsignedShortType && texture.type !== UnsignedIntType ) {
  12419. console.warn( 'THREE.WebGLRenderer: Use UnsignedShortType or UnsignedIntType for DepthFormat DepthTexture.' );
  12420. texture.type = UnsignedShortType;
  12421. glType = utils.convert( texture.type );
  12422. }
  12423. }
  12424. // Depth stencil textures need the DEPTH_STENCIL internal format
  12425. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  12426. if ( texture.format === DepthStencilFormat ) {
  12427. glInternalFormat = 34041;
  12428. // The error INVALID_OPERATION is generated by texImage2D if format and internalformat are
  12429. // DEPTH_STENCIL and type is not UNSIGNED_INT_24_8_WEBGL.
  12430. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  12431. if ( texture.type !== UnsignedInt248Type ) {
  12432. console.warn( 'THREE.WebGLRenderer: Use UnsignedInt248Type for DepthStencilFormat DepthTexture.' );
  12433. texture.type = UnsignedInt248Type;
  12434. glType = utils.convert( texture.type );
  12435. }
  12436. }
  12437. state.texImage2D( 3553, 0, glInternalFormat, image.width, image.height, 0, glFormat, glType, null );
  12438. } else if ( texture.isDataTexture ) {
  12439. // use manually created mipmaps if available
  12440. // if there are no manual mipmaps
  12441. // set 0 level mipmap and then use GL to generate other mipmap levels
  12442. if ( mipmaps.length > 0 && supportsMips ) {
  12443. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  12444. mipmap = mipmaps[ i ];
  12445. state.texImage2D( 3553, i, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  12446. }
  12447. texture.generateMipmaps = false;
  12448. textureProperties.__maxMipLevel = mipmaps.length - 1;
  12449. } else {
  12450. state.texImage2D( 3553, 0, glInternalFormat, image.width, image.height, 0, glFormat, glType, image.data );
  12451. textureProperties.__maxMipLevel = 0;
  12452. }
  12453. } else if ( texture.isCompressedTexture ) {
  12454. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  12455. mipmap = mipmaps[ i ];
  12456. if ( texture.format !== RGBAFormat && texture.format !== RGBFormat ) {
  12457. if ( state.getCompressedTextureFormats().indexOf( glFormat ) > - 1 ) {
  12458. state.compressedTexImage2D( 3553, i, glInternalFormat, mipmap.width, mipmap.height, 0, mipmap.data );
  12459. } else {
  12460. console.warn( 'THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()' );
  12461. }
  12462. } else {
  12463. state.texImage2D( 3553, i, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  12464. }
  12465. }
  12466. textureProperties.__maxMipLevel = mipmaps.length - 1;
  12467. } else if ( texture.isDataTexture2DArray ) {
  12468. state.texImage3D( 35866, 0, glInternalFormat, image.width, image.height, image.depth, 0, glFormat, glType, image.data );
  12469. textureProperties.__maxMipLevel = 0;
  12470. } else if ( texture.isDataTexture3D ) {
  12471. state.texImage3D( 32879, 0, glInternalFormat, image.width, image.height, image.depth, 0, glFormat, glType, image.data );
  12472. textureProperties.__maxMipLevel = 0;
  12473. } else {
  12474. // regular Texture (image, video, canvas)
  12475. // use manually created mipmaps if available
  12476. // if there are no manual mipmaps
  12477. // set 0 level mipmap and then use GL to generate other mipmap levels
  12478. if ( mipmaps.length > 0 && supportsMips ) {
  12479. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  12480. mipmap = mipmaps[ i ];
  12481. state.texImage2D( 3553, i, glInternalFormat, glFormat, glType, mipmap );
  12482. }
  12483. texture.generateMipmaps = false;
  12484. textureProperties.__maxMipLevel = mipmaps.length - 1;
  12485. } else {
  12486. state.texImage2D( 3553, 0, glInternalFormat, glFormat, glType, image );
  12487. textureProperties.__maxMipLevel = 0;
  12488. }
  12489. }
  12490. if ( textureNeedsGenerateMipmaps( texture, supportsMips ) ) {
  12491. generateMipmap( 3553, texture, image.width, image.height );
  12492. }
  12493. textureProperties.__version = texture.version;
  12494. if ( texture.onUpdate ) texture.onUpdate( texture );
  12495. }
  12496. // Render targets
  12497. // Setup storage for target texture and bind it to correct framebuffer
  12498. function setupFrameBufferTexture( framebuffer, renderTarget, attachment, textureTarget ) {
  12499. var glFormat = utils.convert( renderTarget.texture.format );
  12500. var glType = utils.convert( renderTarget.texture.type );
  12501. var glInternalFormat = getInternalFormat( glFormat, glType );
  12502. state.texImage2D( textureTarget, 0, glInternalFormat, renderTarget.width, renderTarget.height, 0, glFormat, glType, null );
  12503. _gl.bindFramebuffer( 36160, framebuffer );
  12504. _gl.framebufferTexture2D( 36160, attachment, textureTarget, properties.get( renderTarget.texture ).__webglTexture, 0 );
  12505. _gl.bindFramebuffer( 36160, null );
  12506. }
  12507. // Setup storage for internal depth/stencil buffers and bind to correct framebuffer
  12508. function setupRenderBufferStorage( renderbuffer, renderTarget, isMultisample ) {
  12509. _gl.bindRenderbuffer( 36161, renderbuffer );
  12510. if ( renderTarget.depthBuffer && ! renderTarget.stencilBuffer ) {
  12511. if ( isMultisample ) {
  12512. var samples = getRenderTargetSamples( renderTarget );
  12513. _gl.renderbufferStorageMultisample( 36161, samples, 33189, renderTarget.width, renderTarget.height );
  12514. } else {
  12515. _gl.renderbufferStorage( 36161, 33189, renderTarget.width, renderTarget.height );
  12516. }
  12517. _gl.framebufferRenderbuffer( 36160, 36096, 36161, renderbuffer );
  12518. } else if ( renderTarget.depthBuffer && renderTarget.stencilBuffer ) {
  12519. if ( isMultisample ) {
  12520. var samples = getRenderTargetSamples( renderTarget );
  12521. _gl.renderbufferStorageMultisample( 36161, samples, 34041, renderTarget.width, renderTarget.height );
  12522. } else {
  12523. _gl.renderbufferStorage( 36161, 34041, renderTarget.width, renderTarget.height );
  12524. }
  12525. _gl.framebufferRenderbuffer( 36160, 33306, 36161, renderbuffer );
  12526. } else {
  12527. var glFormat = utils.convert( renderTarget.texture.format );
  12528. var glType = utils.convert( renderTarget.texture.type );
  12529. var glInternalFormat = getInternalFormat( glFormat, glType );
  12530. if ( isMultisample ) {
  12531. var samples = getRenderTargetSamples( renderTarget );
  12532. _gl.renderbufferStorageMultisample( 36161, samples, glInternalFormat, renderTarget.width, renderTarget.height );
  12533. } else {
  12534. _gl.renderbufferStorage( 36161, glInternalFormat, renderTarget.width, renderTarget.height );
  12535. }
  12536. }
  12537. _gl.bindRenderbuffer( 36161, null );
  12538. }
  12539. // Setup resources for a Depth Texture for a FBO (needs an extension)
  12540. function setupDepthTexture( framebuffer, renderTarget ) {
  12541. var isCube = ( renderTarget && renderTarget.isWebGLRenderTargetCube );
  12542. if ( isCube ) throw new Error( 'Depth Texture with cube render targets is not supported' );
  12543. _gl.bindFramebuffer( 36160, framebuffer );
  12544. if ( ! ( renderTarget.depthTexture && renderTarget.depthTexture.isDepthTexture ) ) {
  12545. throw new Error( 'renderTarget.depthTexture must be an instance of THREE.DepthTexture' );
  12546. }
  12547. // upload an empty depth texture with framebuffer size
  12548. if ( ! properties.get( renderTarget.depthTexture ).__webglTexture ||
  12549. renderTarget.depthTexture.image.width !== renderTarget.width ||
  12550. renderTarget.depthTexture.image.height !== renderTarget.height ) {
  12551. renderTarget.depthTexture.image.width = renderTarget.width;
  12552. renderTarget.depthTexture.image.height = renderTarget.height;
  12553. renderTarget.depthTexture.needsUpdate = true;
  12554. }
  12555. setTexture2D( renderTarget.depthTexture, 0 );
  12556. var webglDepthTexture = properties.get( renderTarget.depthTexture ).__webglTexture;
  12557. if ( renderTarget.depthTexture.format === DepthFormat ) {
  12558. _gl.framebufferTexture2D( 36160, 36096, 3553, webglDepthTexture, 0 );
  12559. } else if ( renderTarget.depthTexture.format === DepthStencilFormat ) {
  12560. _gl.framebufferTexture2D( 36160, 33306, 3553, webglDepthTexture, 0 );
  12561. } else {
  12562. throw new Error( 'Unknown depthTexture format' );
  12563. }
  12564. }
  12565. // Setup GL resources for a non-texture depth buffer
  12566. function setupDepthRenderbuffer( renderTarget ) {
  12567. var renderTargetProperties = properties.get( renderTarget );
  12568. var isCube = ( renderTarget.isWebGLRenderTargetCube === true );
  12569. if ( renderTarget.depthTexture ) {
  12570. if ( isCube ) throw new Error( 'target.depthTexture not supported in Cube render targets' );
  12571. setupDepthTexture( renderTargetProperties.__webglFramebuffer, renderTarget );
  12572. } else {
  12573. if ( isCube ) {
  12574. renderTargetProperties.__webglDepthbuffer = [];
  12575. for ( var i = 0; i < 6; i ++ ) {
  12576. _gl.bindFramebuffer( 36160, renderTargetProperties.__webglFramebuffer[ i ] );
  12577. renderTargetProperties.__webglDepthbuffer[ i ] = _gl.createRenderbuffer();
  12578. setupRenderBufferStorage( renderTargetProperties.__webglDepthbuffer[ i ], renderTarget );
  12579. }
  12580. } else {
  12581. _gl.bindFramebuffer( 36160, renderTargetProperties.__webglFramebuffer );
  12582. renderTargetProperties.__webglDepthbuffer = _gl.createRenderbuffer();
  12583. setupRenderBufferStorage( renderTargetProperties.__webglDepthbuffer, renderTarget );
  12584. }
  12585. }
  12586. _gl.bindFramebuffer( 36160, null );
  12587. }
  12588. // Set up GL resources for the render target
  12589. function setupRenderTarget( renderTarget ) {
  12590. var renderTargetProperties = properties.get( renderTarget );
  12591. var textureProperties = properties.get( renderTarget.texture );
  12592. renderTarget.addEventListener( 'dispose', onRenderTargetDispose );
  12593. textureProperties.__webglTexture = _gl.createTexture();
  12594. info.memory.textures ++;
  12595. var isCube = ( renderTarget.isWebGLRenderTargetCube === true );
  12596. var isMultisample = ( renderTarget.isWebGLMultisampleRenderTarget === true );
  12597. var supportsMips = isPowerOfTwo( renderTarget ) || capabilities.isWebGL2;
  12598. // Setup framebuffer
  12599. if ( isCube ) {
  12600. renderTargetProperties.__webglFramebuffer = [];
  12601. for ( var i = 0; i < 6; i ++ ) {
  12602. renderTargetProperties.__webglFramebuffer[ i ] = _gl.createFramebuffer();
  12603. }
  12604. } else {
  12605. renderTargetProperties.__webglFramebuffer = _gl.createFramebuffer();
  12606. if ( isMultisample ) {
  12607. if ( capabilities.isWebGL2 ) {
  12608. renderTargetProperties.__webglMultisampledFramebuffer = _gl.createFramebuffer();
  12609. renderTargetProperties.__webglColorRenderbuffer = _gl.createRenderbuffer();
  12610. _gl.bindRenderbuffer( 36161, renderTargetProperties.__webglColorRenderbuffer );
  12611. var glFormat = utils.convert( renderTarget.texture.format );
  12612. var glType = utils.convert( renderTarget.texture.type );
  12613. var glInternalFormat = getInternalFormat( glFormat, glType );
  12614. var samples = getRenderTargetSamples( renderTarget );
  12615. _gl.renderbufferStorageMultisample( 36161, samples, glInternalFormat, renderTarget.width, renderTarget.height );
  12616. _gl.bindFramebuffer( 36160, renderTargetProperties.__webglMultisampledFramebuffer );
  12617. _gl.framebufferRenderbuffer( 36160, 36064, 36161, renderTargetProperties.__webglColorRenderbuffer );
  12618. _gl.bindRenderbuffer( 36161, null );
  12619. if ( renderTarget.depthBuffer ) {
  12620. renderTargetProperties.__webglDepthRenderbuffer = _gl.createRenderbuffer();
  12621. setupRenderBufferStorage( renderTargetProperties.__webglDepthRenderbuffer, renderTarget, true );
  12622. }
  12623. _gl.bindFramebuffer( 36160, null );
  12624. } else {
  12625. console.warn( 'THREE.WebGLRenderer: WebGLMultisampleRenderTarget can only be used with WebGL2.' );
  12626. }
  12627. }
  12628. }
  12629. // Setup color buffer
  12630. if ( isCube ) {
  12631. state.bindTexture( 34067, textureProperties.__webglTexture );
  12632. setTextureParameters( 34067, renderTarget.texture, supportsMips );
  12633. for ( var i = 0; i < 6; i ++ ) {
  12634. setupFrameBufferTexture( renderTargetProperties.__webglFramebuffer[ i ], renderTarget, 36064, 34069 + i );
  12635. }
  12636. if ( textureNeedsGenerateMipmaps( renderTarget.texture, supportsMips ) ) {
  12637. generateMipmap( 34067, renderTarget.texture, renderTarget.width, renderTarget.height );
  12638. }
  12639. state.bindTexture( 34067, null );
  12640. } else {
  12641. state.bindTexture( 3553, textureProperties.__webglTexture );
  12642. setTextureParameters( 3553, renderTarget.texture, supportsMips );
  12643. setupFrameBufferTexture( renderTargetProperties.__webglFramebuffer, renderTarget, 36064, 3553 );
  12644. if ( textureNeedsGenerateMipmaps( renderTarget.texture, supportsMips ) ) {
  12645. generateMipmap( 3553, renderTarget.texture, renderTarget.width, renderTarget.height );
  12646. }
  12647. state.bindTexture( 3553, null );
  12648. }
  12649. // Setup depth and stencil buffers
  12650. if ( renderTarget.depthBuffer ) {
  12651. setupDepthRenderbuffer( renderTarget );
  12652. }
  12653. }
  12654. function updateRenderTargetMipmap( renderTarget ) {
  12655. var texture = renderTarget.texture;
  12656. var supportsMips = isPowerOfTwo( renderTarget ) || capabilities.isWebGL2;
  12657. if ( textureNeedsGenerateMipmaps( texture, supportsMips ) ) {
  12658. var target = renderTarget.isWebGLRenderTargetCube ? 34067 : 3553;
  12659. var webglTexture = properties.get( texture ).__webglTexture;
  12660. state.bindTexture( target, webglTexture );
  12661. generateMipmap( target, texture, renderTarget.width, renderTarget.height );
  12662. state.bindTexture( target, null );
  12663. }
  12664. }
  12665. function updateMultisampleRenderTarget( renderTarget ) {
  12666. if ( renderTarget.isWebGLMultisampleRenderTarget ) {
  12667. if ( capabilities.isWebGL2 ) {
  12668. var renderTargetProperties = properties.get( renderTarget );
  12669. _gl.bindFramebuffer( 36008, renderTargetProperties.__webglMultisampledFramebuffer );
  12670. _gl.bindFramebuffer( 36009, renderTargetProperties.__webglFramebuffer );
  12671. var width = renderTarget.width;
  12672. var height = renderTarget.height;
  12673. var mask = 16384;
  12674. if ( renderTarget.depthBuffer ) mask |= 256;
  12675. if ( renderTarget.stencilBuffer ) mask |= 1024;
  12676. _gl.blitFramebuffer( 0, 0, width, height, 0, 0, width, height, mask, 9728 );
  12677. } else {
  12678. console.warn( 'THREE.WebGLRenderer: WebGLMultisampleRenderTarget can only be used with WebGL2.' );
  12679. }
  12680. }
  12681. }
  12682. function getRenderTargetSamples( renderTarget ) {
  12683. return ( capabilities.isWebGL2 && renderTarget.isWebGLMultisampleRenderTarget ) ?
  12684. Math.min( capabilities.maxSamples, renderTarget.samples ) : 0;
  12685. }
  12686. function updateVideoTexture( texture ) {
  12687. var id = texture.id;
  12688. var frame = info.render.frame;
  12689. // Check the last frame we updated the VideoTexture
  12690. if ( _videoTextures[ id ] !== frame ) {
  12691. _videoTextures[ id ] = frame;
  12692. texture.update();
  12693. }
  12694. }
  12695. // backwards compatibility
  12696. var warnedTexture2D = false;
  12697. var warnedTextureCube = false;
  12698. function safeSetTexture2D( texture, slot ) {
  12699. if ( texture && texture.isWebGLRenderTarget ) {
  12700. if ( warnedTexture2D === false ) {
  12701. console.warn( "THREE.WebGLTextures.safeSetTexture2D: don't use render targets as textures. Use their .texture property instead." );
  12702. warnedTexture2D = true;
  12703. }
  12704. texture = texture.texture;
  12705. }
  12706. setTexture2D( texture, slot );
  12707. }
  12708. function safeSetTextureCube( texture, slot ) {
  12709. if ( texture && texture.isWebGLRenderTargetCube ) {
  12710. if ( warnedTextureCube === false ) {
  12711. console.warn( "THREE.WebGLTextures.safeSetTextureCube: don't use cube render targets as textures. Use their .texture property instead." );
  12712. warnedTextureCube = true;
  12713. }
  12714. texture = texture.texture;
  12715. }
  12716. // currently relying on the fact that WebGLRenderTargetCube.texture is a Texture and NOT a CubeTexture
  12717. // TODO: unify these code paths
  12718. if ( ( texture && texture.isCubeTexture ) ||
  12719. ( Array.isArray( texture.image ) && texture.image.length === 6 ) ) {
  12720. // CompressedTexture can have Array in image :/
  12721. // this function alone should take care of cube textures
  12722. setTextureCube( texture, slot );
  12723. } else {
  12724. // assumed: texture property of THREE.WebGLRenderTargetCube
  12725. setTextureCubeDynamic( texture, slot );
  12726. }
  12727. }
  12728. //
  12729. this.allocateTextureUnit = allocateTextureUnit;
  12730. this.resetTextureUnits = resetTextureUnits;
  12731. this.setTexture2D = setTexture2D;
  12732. this.setTexture2DArray = setTexture2DArray;
  12733. this.setTexture3D = setTexture3D;
  12734. this.setTextureCube = setTextureCube;
  12735. this.setTextureCubeDynamic = setTextureCubeDynamic;
  12736. this.setupRenderTarget = setupRenderTarget;
  12737. this.updateRenderTargetMipmap = updateRenderTargetMipmap;
  12738. this.updateMultisampleRenderTarget = updateMultisampleRenderTarget;
  12739. this.safeSetTexture2D = safeSetTexture2D;
  12740. this.safeSetTextureCube = safeSetTextureCube;
  12741. }
  12742. /**
  12743. * @author thespite / http://www.twitter.com/thespite
  12744. */
  12745. function WebGLUtils( gl, extensions, capabilities ) {
  12746. function convert( p ) {
  12747. var extension;
  12748. if ( p === RepeatWrapping ) return 10497;
  12749. if ( p === ClampToEdgeWrapping ) return 33071;
  12750. if ( p === MirroredRepeatWrapping ) return 33648;
  12751. if ( p === NearestFilter ) return 9728;
  12752. if ( p === NearestMipMapNearestFilter ) return 9984;
  12753. if ( p === NearestMipMapLinearFilter ) return 9986;
  12754. if ( p === LinearFilter ) return 9729;
  12755. if ( p === LinearMipMapNearestFilter ) return 9985;
  12756. if ( p === LinearMipMapLinearFilter ) return 9987;
  12757. if ( p === UnsignedByteType ) return 5121;
  12758. if ( p === UnsignedShort4444Type ) return 32819;
  12759. if ( p === UnsignedShort5551Type ) return 32820;
  12760. if ( p === UnsignedShort565Type ) return 33635;
  12761. if ( p === ByteType ) return 5120;
  12762. if ( p === ShortType ) return 5122;
  12763. if ( p === UnsignedShortType ) return 5123;
  12764. if ( p === IntType ) return 5124;
  12765. if ( p === UnsignedIntType ) return 5125;
  12766. if ( p === FloatType ) return 5126;
  12767. if ( p === HalfFloatType ) {
  12768. if ( capabilities.isWebGL2 ) return 5131;
  12769. extension = extensions.get( 'OES_texture_half_float' );
  12770. if ( extension !== null ) return extension.HALF_FLOAT_OES;
  12771. }
  12772. if ( p === AlphaFormat ) return 6406;
  12773. if ( p === RGBFormat ) return 6407;
  12774. if ( p === RGBAFormat ) return 6408;
  12775. if ( p === LuminanceFormat ) return 6409;
  12776. if ( p === LuminanceAlphaFormat ) return 6410;
  12777. if ( p === DepthFormat ) return 6402;
  12778. if ( p === DepthStencilFormat ) return 34041;
  12779. if ( p === RedFormat ) return 6403;
  12780. if ( p === AddEquation ) return 32774;
  12781. if ( p === SubtractEquation ) return 32778;
  12782. if ( p === ReverseSubtractEquation ) return 32779;
  12783. if ( p === ZeroFactor ) return 0;
  12784. if ( p === OneFactor ) return 1;
  12785. if ( p === SrcColorFactor ) return 768;
  12786. if ( p === OneMinusSrcColorFactor ) return 769;
  12787. if ( p === SrcAlphaFactor ) return 770;
  12788. if ( p === OneMinusSrcAlphaFactor ) return 771;
  12789. if ( p === DstAlphaFactor ) return 772;
  12790. if ( p === OneMinusDstAlphaFactor ) return 773;
  12791. if ( p === DstColorFactor ) return 774;
  12792. if ( p === OneMinusDstColorFactor ) return 775;
  12793. if ( p === SrcAlphaSaturateFactor ) return 776;
  12794. if ( p === RGB_S3TC_DXT1_Format || p === RGBA_S3TC_DXT1_Format ||
  12795. p === RGBA_S3TC_DXT3_Format || p === RGBA_S3TC_DXT5_Format ) {
  12796. extension = extensions.get( 'WEBGL_compressed_texture_s3tc' );
  12797. if ( extension !== null ) {
  12798. if ( p === RGB_S3TC_DXT1_Format ) return extension.COMPRESSED_RGB_S3TC_DXT1_EXT;
  12799. if ( p === RGBA_S3TC_DXT1_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT1_EXT;
  12800. if ( p === RGBA_S3TC_DXT3_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT3_EXT;
  12801. if ( p === RGBA_S3TC_DXT5_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT5_EXT;
  12802. }
  12803. }
  12804. if ( p === RGB_PVRTC_4BPPV1_Format || p === RGB_PVRTC_2BPPV1_Format ||
  12805. p === RGBA_PVRTC_4BPPV1_Format || p === RGBA_PVRTC_2BPPV1_Format ) {
  12806. extension = extensions.get( 'WEBGL_compressed_texture_pvrtc' );
  12807. if ( extension !== null ) {
  12808. if ( p === RGB_PVRTC_4BPPV1_Format ) return extension.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;
  12809. if ( p === RGB_PVRTC_2BPPV1_Format ) return extension.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;
  12810. if ( p === RGBA_PVRTC_4BPPV1_Format ) return extension.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;
  12811. if ( p === RGBA_PVRTC_2BPPV1_Format ) return extension.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG;
  12812. }
  12813. }
  12814. if ( p === RGB_ETC1_Format ) {
  12815. extension = extensions.get( 'WEBGL_compressed_texture_etc1' );
  12816. if ( extension !== null ) return extension.COMPRESSED_RGB_ETC1_WEBGL;
  12817. }
  12818. if ( p === RGBA_ASTC_4x4_Format || p === RGBA_ASTC_5x4_Format || p === RGBA_ASTC_5x5_Format ||
  12819. p === RGBA_ASTC_6x5_Format || p === RGBA_ASTC_6x6_Format || p === RGBA_ASTC_8x5_Format ||
  12820. p === RGBA_ASTC_8x6_Format || p === RGBA_ASTC_8x8_Format || p === RGBA_ASTC_10x5_Format ||
  12821. p === RGBA_ASTC_10x6_Format || p === RGBA_ASTC_10x8_Format || p === RGBA_ASTC_10x10_Format ||
  12822. p === RGBA_ASTC_12x10_Format || p === RGBA_ASTC_12x12_Format ) {
  12823. extension = extensions.get( 'WEBGL_compressed_texture_astc' );
  12824. if ( extension !== null ) {
  12825. return p;
  12826. }
  12827. }
  12828. if ( p === MinEquation || p === MaxEquation ) {
  12829. if ( capabilities.isWebGL2 ) {
  12830. if ( p === MinEquation ) return 32775;
  12831. if ( p === MaxEquation ) return 32776;
  12832. }
  12833. extension = extensions.get( 'EXT_blend_minmax' );
  12834. if ( extension !== null ) {
  12835. if ( p === MinEquation ) return extension.MIN_EXT;
  12836. if ( p === MaxEquation ) return extension.MAX_EXT;
  12837. }
  12838. }
  12839. if ( p === UnsignedInt248Type ) {
  12840. if ( capabilities.isWebGL2 ) return 34042;
  12841. extension = extensions.get( 'WEBGL_depth_texture' );
  12842. if ( extension !== null ) return extension.UNSIGNED_INT_24_8_WEBGL;
  12843. }
  12844. return 0;
  12845. }
  12846. return { convert: convert };
  12847. }
  12848. /**
  12849. * @author mrdoob / http://mrdoob.com/
  12850. */
  12851. function Group() {
  12852. Object3D.call( this );
  12853. this.type = 'Group';
  12854. }
  12855. Group.prototype = Object.assign( Object.create( Object3D.prototype ), {
  12856. constructor: Group,
  12857. isGroup: true
  12858. } );
  12859. /**
  12860. * @author mrdoob / http://mrdoob.com/
  12861. * @author mikael emtinger / http://gomo.se/
  12862. * @author WestLangley / http://github.com/WestLangley
  12863. */
  12864. function Camera() {
  12865. Object3D.call( this );
  12866. this.type = 'Camera';
  12867. this.matrixWorldInverse = new Matrix4();
  12868. this.projectionMatrix = new Matrix4();
  12869. this.projectionMatrixInverse = new Matrix4();
  12870. }
  12871. Camera.prototype = Object.assign( Object.create( Object3D.prototype ), {
  12872. constructor: Camera,
  12873. isCamera: true,
  12874. copy: function ( source, recursive ) {
  12875. Object3D.prototype.copy.call( this, source, recursive );
  12876. this.matrixWorldInverse.copy( source.matrixWorldInverse );
  12877. this.projectionMatrix.copy( source.projectionMatrix );
  12878. this.projectionMatrixInverse.copy( source.projectionMatrixInverse );
  12879. return this;
  12880. },
  12881. getWorldDirection: function ( target ) {
  12882. if ( target === undefined ) {
  12883. console.warn( 'THREE.Camera: .getWorldDirection() target is now required' );
  12884. target = new Vector3();
  12885. }
  12886. this.updateMatrixWorld( true );
  12887. var e = this.matrixWorld.elements;
  12888. return target.set( - e[ 8 ], - e[ 9 ], - e[ 10 ] ).normalize();
  12889. },
  12890. updateMatrixWorld: function ( force ) {
  12891. Object3D.prototype.updateMatrixWorld.call( this, force );
  12892. this.matrixWorldInverse.getInverse( this.matrixWorld );
  12893. },
  12894. clone: function () {
  12895. return new this.constructor().copy( this );
  12896. }
  12897. } );
  12898. /**
  12899. * @author mrdoob / http://mrdoob.com/
  12900. * @author greggman / http://games.greggman.com/
  12901. * @author zz85 / http://www.lab4games.net/zz85/blog
  12902. * @author tschw
  12903. */
  12904. function PerspectiveCamera( fov, aspect, near, far ) {
  12905. Camera.call( this );
  12906. this.type = 'PerspectiveCamera';
  12907. this.fov = fov !== undefined ? fov : 50;
  12908. this.zoom = 1;
  12909. this.near = near !== undefined ? near : 0.1;
  12910. this.far = far !== undefined ? far : 2000;
  12911. this.focus = 10;
  12912. this.aspect = aspect !== undefined ? aspect : 1;
  12913. this.view = null;
  12914. this.filmGauge = 35; // width of the film (default in millimeters)
  12915. this.filmOffset = 0; // horizontal film offset (same unit as gauge)
  12916. this.updateProjectionMatrix();
  12917. }
  12918. PerspectiveCamera.prototype = Object.assign( Object.create( Camera.prototype ), {
  12919. constructor: PerspectiveCamera,
  12920. isPerspectiveCamera: true,
  12921. copy: function ( source, recursive ) {
  12922. Camera.prototype.copy.call( this, source, recursive );
  12923. this.fov = source.fov;
  12924. this.zoom = source.zoom;
  12925. this.near = source.near;
  12926. this.far = source.far;
  12927. this.focus = source.focus;
  12928. this.aspect = source.aspect;
  12929. this.view = source.view === null ? null : Object.assign( {}, source.view );
  12930. this.filmGauge = source.filmGauge;
  12931. this.filmOffset = source.filmOffset;
  12932. return this;
  12933. },
  12934. /**
  12935. * Sets the FOV by focal length in respect to the current .filmGauge.
  12936. *
  12937. * The default film gauge is 35, so that the focal length can be specified for
  12938. * a 35mm (full frame) camera.
  12939. *
  12940. * Values for focal length and film gauge must have the same unit.
  12941. */
  12942. setFocalLength: function ( focalLength ) {
  12943. // see http://www.bobatkins.com/photography/technical/field_of_view.html
  12944. var vExtentSlope = 0.5 * this.getFilmHeight() / focalLength;
  12945. this.fov = _Math.RAD2DEG * 2 * Math.atan( vExtentSlope );
  12946. this.updateProjectionMatrix();
  12947. },
  12948. /**
  12949. * Calculates the focal length from the current .fov and .filmGauge.
  12950. */
  12951. getFocalLength: function () {
  12952. var vExtentSlope = Math.tan( _Math.DEG2RAD * 0.5 * this.fov );
  12953. return 0.5 * this.getFilmHeight() / vExtentSlope;
  12954. },
  12955. getEffectiveFOV: function () {
  12956. return _Math.RAD2DEG * 2 * Math.atan(
  12957. Math.tan( _Math.DEG2RAD * 0.5 * this.fov ) / this.zoom );
  12958. },
  12959. getFilmWidth: function () {
  12960. // film not completely covered in portrait format (aspect < 1)
  12961. return this.filmGauge * Math.min( this.aspect, 1 );
  12962. },
  12963. getFilmHeight: function () {
  12964. // film not completely covered in landscape format (aspect > 1)
  12965. return this.filmGauge / Math.max( this.aspect, 1 );
  12966. },
  12967. /**
  12968. * Sets an offset in a larger frustum. This is useful for multi-window or
  12969. * multi-monitor/multi-machine setups.
  12970. *
  12971. * For example, if you have 3x2 monitors and each monitor is 1920x1080 and
  12972. * the monitors are in grid like this
  12973. *
  12974. * +---+---+---+
  12975. * | A | B | C |
  12976. * +---+---+---+
  12977. * | D | E | F |
  12978. * +---+---+---+
  12979. *
  12980. * then for each monitor you would call it like this
  12981. *
  12982. * var w = 1920;
  12983. * var h = 1080;
  12984. * var fullWidth = w * 3;
  12985. * var fullHeight = h * 2;
  12986. *
  12987. * --A--
  12988. * camera.setViewOffset( fullWidth, fullHeight, w * 0, h * 0, w, h );
  12989. * --B--
  12990. * camera.setViewOffset( fullWidth, fullHeight, w * 1, h * 0, w, h );
  12991. * --C--
  12992. * camera.setViewOffset( fullWidth, fullHeight, w * 2, h * 0, w, h );
  12993. * --D--
  12994. * camera.setViewOffset( fullWidth, fullHeight, w * 0, h * 1, w, h );
  12995. * --E--
  12996. * camera.setViewOffset( fullWidth, fullHeight, w * 1, h * 1, w, h );
  12997. * --F--
  12998. * camera.setViewOffset( fullWidth, fullHeight, w * 2, h * 1, w, h );
  12999. *
  13000. * Note there is no reason monitors have to be the same size or in a grid.
  13001. */
  13002. setViewOffset: function ( fullWidth, fullHeight, x, y, width, height ) {
  13003. this.aspect = fullWidth / fullHeight;
  13004. if ( this.view === null ) {
  13005. this.view = {
  13006. enabled: true,
  13007. fullWidth: 1,
  13008. fullHeight: 1,
  13009. offsetX: 0,
  13010. offsetY: 0,
  13011. width: 1,
  13012. height: 1
  13013. };
  13014. }
  13015. this.view.enabled = true;
  13016. this.view.fullWidth = fullWidth;
  13017. this.view.fullHeight = fullHeight;
  13018. this.view.offsetX = x;
  13019. this.view.offsetY = y;
  13020. this.view.width = width;
  13021. this.view.height = height;
  13022. this.updateProjectionMatrix();
  13023. },
  13024. clearViewOffset: function () {
  13025. if ( this.view !== null ) {
  13026. this.view.enabled = false;
  13027. }
  13028. this.updateProjectionMatrix();
  13029. },
  13030. updateProjectionMatrix: function () {
  13031. var near = this.near,
  13032. top = near * Math.tan( _Math.DEG2RAD * 0.5 * this.fov ) / this.zoom,
  13033. height = 2 * top,
  13034. width = this.aspect * height,
  13035. left = - 0.5 * width,
  13036. view = this.view;
  13037. if ( this.view !== null && this.view.enabled ) {
  13038. var fullWidth = view.fullWidth,
  13039. fullHeight = view.fullHeight;
  13040. left += view.offsetX * width / fullWidth;
  13041. top -= view.offsetY * height / fullHeight;
  13042. width *= view.width / fullWidth;
  13043. height *= view.height / fullHeight;
  13044. }
  13045. var skew = this.filmOffset;
  13046. if ( skew !== 0 ) left += near * skew / this.getFilmWidth();
  13047. this.projectionMatrix.makePerspective( left, left + width, top, top - height, near, this.far );
  13048. this.projectionMatrixInverse.getInverse( this.projectionMatrix );
  13049. },
  13050. toJSON: function ( meta ) {
  13051. var data = Object3D.prototype.toJSON.call( this, meta );
  13052. data.object.fov = this.fov;
  13053. data.object.zoom = this.zoom;
  13054. data.object.near = this.near;
  13055. data.object.far = this.far;
  13056. data.object.focus = this.focus;
  13057. data.object.aspect = this.aspect;
  13058. if ( this.view !== null ) data.object.view = Object.assign( {}, this.view );
  13059. data.object.filmGauge = this.filmGauge;
  13060. data.object.filmOffset = this.filmOffset;
  13061. return data;
  13062. }
  13063. } );
  13064. /**
  13065. * @author mrdoob / http://mrdoob.com/
  13066. */
  13067. function ArrayCamera( array ) {
  13068. PerspectiveCamera.call( this );
  13069. this.cameras = array || [];
  13070. }
  13071. ArrayCamera.prototype = Object.assign( Object.create( PerspectiveCamera.prototype ), {
  13072. constructor: ArrayCamera,
  13073. isArrayCamera: true
  13074. } );
  13075. /**
  13076. * @author jsantell / https://www.jsantell.com/
  13077. * @author mrdoob / http://mrdoob.com/
  13078. */
  13079. var cameraLPos = new Vector3();
  13080. var cameraRPos = new Vector3();
  13081. /**
  13082. * Assumes 2 cameras that are parallel and share an X-axis, and that
  13083. * the cameras' projection and world matrices have already been set.
  13084. * And that near and far planes are identical for both cameras.
  13085. * Visualization of this technique: https://computergraphics.stackexchange.com/a/4765
  13086. */
  13087. function setProjectionFromUnion( camera, cameraL, cameraR ) {
  13088. cameraLPos.setFromMatrixPosition( cameraL.matrixWorld );
  13089. cameraRPos.setFromMatrixPosition( cameraR.matrixWorld );
  13090. var ipd = cameraLPos.distanceTo( cameraRPos );
  13091. var projL = cameraL.projectionMatrix.elements;
  13092. var projR = cameraR.projectionMatrix.elements;
  13093. // VR systems will have identical far and near planes, and
  13094. // most likely identical top and bottom frustum extents.
  13095. // Use the left camera for these values.
  13096. var near = projL[ 14 ] / ( projL[ 10 ] - 1 );
  13097. var far = projL[ 14 ] / ( projL[ 10 ] + 1 );
  13098. var topFov = ( projL[ 9 ] + 1 ) / projL[ 5 ];
  13099. var bottomFov = ( projL[ 9 ] - 1 ) / projL[ 5 ];
  13100. var leftFov = ( projL[ 8 ] - 1 ) / projL[ 0 ];
  13101. var rightFov = ( projR[ 8 ] + 1 ) / projR[ 0 ];
  13102. var left = near * leftFov;
  13103. var right = near * rightFov;
  13104. // Calculate the new camera's position offset from the
  13105. // left camera. xOffset should be roughly half `ipd`.
  13106. var zOffset = ipd / ( - leftFov + rightFov );
  13107. var xOffset = zOffset * - leftFov;
  13108. // TODO: Better way to apply this offset?
  13109. cameraL.matrixWorld.decompose( camera.position, camera.quaternion, camera.scale );
  13110. camera.translateX( xOffset );
  13111. camera.translateZ( zOffset );
  13112. camera.matrixWorld.compose( camera.position, camera.quaternion, camera.scale );
  13113. camera.matrixWorldInverse.getInverse( camera.matrixWorld );
  13114. // Find the union of the frustum values of the cameras and scale
  13115. // the values so that the near plane's position does not change in world space,
  13116. // although must now be relative to the new union camera.
  13117. var near2 = near + zOffset;
  13118. var far2 = far + zOffset;
  13119. var left2 = left - xOffset;
  13120. var right2 = right + ( ipd - xOffset );
  13121. var top2 = topFov * far / far2 * near2;
  13122. var bottom2 = bottomFov * far / far2 * near2;
  13123. camera.projectionMatrix.makePerspective( left2, right2, top2, bottom2, near2, far2 );
  13124. }
  13125. /**
  13126. * @author mrdoob / http://mrdoob.com/
  13127. */
  13128. function WebVRManager( renderer ) {
  13129. var renderWidth, renderHeight;
  13130. var scope = this;
  13131. var device = null;
  13132. var frameData = null;
  13133. var poseTarget = null;
  13134. var controllers = [];
  13135. var standingMatrix = new Matrix4();
  13136. var standingMatrixInverse = new Matrix4();
  13137. var framebufferScaleFactor = 1.0;
  13138. var referenceSpaceType = 'local-floor';
  13139. if ( typeof window !== 'undefined' && 'VRFrameData' in window ) {
  13140. frameData = new window.VRFrameData();
  13141. window.addEventListener( 'vrdisplaypresentchange', onVRDisplayPresentChange, false );
  13142. }
  13143. var matrixWorldInverse = new Matrix4();
  13144. var tempQuaternion = new Quaternion();
  13145. var tempPosition = new Vector3();
  13146. var cameraL = new PerspectiveCamera();
  13147. cameraL.viewport = new Vector4();
  13148. cameraL.layers.enable( 1 );
  13149. var cameraR = new PerspectiveCamera();
  13150. cameraR.viewport = new Vector4();
  13151. cameraR.layers.enable( 2 );
  13152. var cameraVR = new ArrayCamera( [ cameraL, cameraR ] );
  13153. cameraVR.layers.enable( 1 );
  13154. cameraVR.layers.enable( 2 );
  13155. //
  13156. function isPresenting() {
  13157. return device !== null && device.isPresenting === true;
  13158. }
  13159. var currentSize = new Vector2(), currentPixelRatio;
  13160. function onVRDisplayPresentChange() {
  13161. if ( isPresenting() ) {
  13162. var eyeParameters = device.getEyeParameters( 'left' );
  13163. renderWidth = 2 * eyeParameters.renderWidth * framebufferScaleFactor;
  13164. renderHeight = eyeParameters.renderHeight * framebufferScaleFactor;
  13165. currentPixelRatio = renderer.getPixelRatio();
  13166. renderer.getSize( currentSize );
  13167. renderer.setDrawingBufferSize( renderWidth, renderHeight, 1 );
  13168. cameraL.viewport.set( 0, 0, renderWidth / 2, renderHeight );
  13169. cameraR.viewport.set( renderWidth / 2, 0, renderWidth / 2, renderHeight );
  13170. animation.start();
  13171. } else {
  13172. if ( scope.enabled ) {
  13173. renderer.setDrawingBufferSize( currentSize.width, currentSize.height, currentPixelRatio );
  13174. }
  13175. animation.stop();
  13176. }
  13177. }
  13178. //
  13179. var triggers = [];
  13180. function findGamepad( id ) {
  13181. var gamepads = navigator.getGamepads && navigator.getGamepads();
  13182. for ( var i = 0, j = 0, l = gamepads.length; i < l; i ++ ) {
  13183. var gamepad = gamepads[ i ];
  13184. if ( gamepad && ( gamepad.id === 'Daydream Controller' ||
  13185. gamepad.id === 'Gear VR Controller' || gamepad.id === 'Oculus Go Controller' ||
  13186. gamepad.id === 'OpenVR Gamepad' || gamepad.id.startsWith( 'Oculus Touch' ) ||
  13187. gamepad.id.startsWith( 'Spatial Controller' ) ) ) {
  13188. if ( j === id ) return gamepad;
  13189. j ++;
  13190. }
  13191. }
  13192. }
  13193. function updateControllers() {
  13194. for ( var i = 0; i < controllers.length; i ++ ) {
  13195. var controller = controllers[ i ];
  13196. var gamepad = findGamepad( i );
  13197. if ( gamepad !== undefined && gamepad.pose !== undefined ) {
  13198. if ( gamepad.pose === null ) return;
  13199. // Pose
  13200. var pose = gamepad.pose;
  13201. if ( pose.hasPosition === false ) controller.position.set( 0.2, - 0.6, - 0.05 );
  13202. if ( pose.position !== null ) controller.position.fromArray( pose.position );
  13203. if ( pose.orientation !== null ) controller.quaternion.fromArray( pose.orientation );
  13204. controller.matrix.compose( controller.position, controller.quaternion, controller.scale );
  13205. controller.matrix.premultiply( standingMatrix );
  13206. controller.matrix.decompose( controller.position, controller.quaternion, controller.scale );
  13207. controller.matrixWorldNeedsUpdate = true;
  13208. controller.visible = true;
  13209. // Trigger
  13210. var buttonId = gamepad.id === 'Daydream Controller' ? 0 : 1;
  13211. if ( triggers[ i ] === undefined ) triggers[ i ] = false;
  13212. if ( triggers[ i ] !== gamepad.buttons[ buttonId ].pressed ) {
  13213. triggers[ i ] = gamepad.buttons[ buttonId ].pressed;
  13214. if ( triggers[ i ] === true ) {
  13215. controller.dispatchEvent( { type: 'selectstart' } );
  13216. } else {
  13217. controller.dispatchEvent( { type: 'selectend' } );
  13218. controller.dispatchEvent( { type: 'select' } );
  13219. }
  13220. }
  13221. } else {
  13222. controller.visible = false;
  13223. }
  13224. }
  13225. }
  13226. function updateViewportFromBounds( viewport, bounds ) {
  13227. if ( bounds !== null && bounds.length === 4 ) {
  13228. viewport.set( bounds[ 0 ] * renderWidth, bounds[ 1 ] * renderHeight, bounds[ 2 ] * renderWidth, bounds[ 3 ] * renderHeight );
  13229. }
  13230. }
  13231. //
  13232. this.enabled = false;
  13233. this.getController = function ( id ) {
  13234. var controller = controllers[ id ];
  13235. if ( controller === undefined ) {
  13236. controller = new Group();
  13237. controller.matrixAutoUpdate = false;
  13238. controller.visible = false;
  13239. controllers[ id ] = controller;
  13240. }
  13241. return controller;
  13242. };
  13243. this.getDevice = function () {
  13244. return device;
  13245. };
  13246. this.setDevice = function ( value ) {
  13247. if ( value !== undefined ) device = value;
  13248. animation.setContext( value );
  13249. };
  13250. this.setFramebufferScaleFactor = function ( value ) {
  13251. framebufferScaleFactor = value;
  13252. };
  13253. this.setReferenceSpaceType = function ( value ) {
  13254. referenceSpaceType = value;
  13255. };
  13256. this.setPoseTarget = function ( object ) {
  13257. if ( object !== undefined ) poseTarget = object;
  13258. };
  13259. this.getCamera = function ( camera ) {
  13260. var userHeight = referenceSpaceType === 'local-floor' ? 1.6 : 0;
  13261. if ( isPresenting() === false ) {
  13262. camera.position.set( 0, userHeight, 0 );
  13263. camera.rotation.set( 0, 0, 0 );
  13264. return camera;
  13265. }
  13266. device.depthNear = camera.near;
  13267. device.depthFar = camera.far;
  13268. device.getFrameData( frameData );
  13269. //
  13270. if ( referenceSpaceType === 'local-floor' ) {
  13271. var stageParameters = device.stageParameters;
  13272. if ( stageParameters ) {
  13273. standingMatrix.fromArray( stageParameters.sittingToStandingTransform );
  13274. } else {
  13275. standingMatrix.makeTranslation( 0, userHeight, 0 );
  13276. }
  13277. }
  13278. var pose = frameData.pose;
  13279. var poseObject = poseTarget !== null ? poseTarget : camera;
  13280. // We want to manipulate poseObject by its position and quaternion components since users may rely on them.
  13281. poseObject.matrix.copy( standingMatrix );
  13282. poseObject.matrix.decompose( poseObject.position, poseObject.quaternion, poseObject.scale );
  13283. if ( pose.orientation !== null ) {
  13284. tempQuaternion.fromArray( pose.orientation );
  13285. poseObject.quaternion.multiply( tempQuaternion );
  13286. }
  13287. if ( pose.position !== null ) {
  13288. tempQuaternion.setFromRotationMatrix( standingMatrix );
  13289. tempPosition.fromArray( pose.position );
  13290. tempPosition.applyQuaternion( tempQuaternion );
  13291. poseObject.position.add( tempPosition );
  13292. }
  13293. poseObject.updateMatrixWorld();
  13294. //
  13295. cameraL.near = camera.near;
  13296. cameraR.near = camera.near;
  13297. cameraL.far = camera.far;
  13298. cameraR.far = camera.far;
  13299. cameraL.matrixWorldInverse.fromArray( frameData.leftViewMatrix );
  13300. cameraR.matrixWorldInverse.fromArray( frameData.rightViewMatrix );
  13301. // TODO (mrdoob) Double check this code
  13302. standingMatrixInverse.getInverse( standingMatrix );
  13303. if ( referenceSpaceType === 'local-floor' ) {
  13304. cameraL.matrixWorldInverse.multiply( standingMatrixInverse );
  13305. cameraR.matrixWorldInverse.multiply( standingMatrixInverse );
  13306. }
  13307. var parent = poseObject.parent;
  13308. if ( parent !== null ) {
  13309. matrixWorldInverse.getInverse( parent.matrixWorld );
  13310. cameraL.matrixWorldInverse.multiply( matrixWorldInverse );
  13311. cameraR.matrixWorldInverse.multiply( matrixWorldInverse );
  13312. }
  13313. // envMap and Mirror needs camera.matrixWorld
  13314. cameraL.matrixWorld.getInverse( cameraL.matrixWorldInverse );
  13315. cameraR.matrixWorld.getInverse( cameraR.matrixWorldInverse );
  13316. cameraL.projectionMatrix.fromArray( frameData.leftProjectionMatrix );
  13317. cameraR.projectionMatrix.fromArray( frameData.rightProjectionMatrix );
  13318. setProjectionFromUnion( cameraVR, cameraL, cameraR );
  13319. //
  13320. var layers = device.getLayers();
  13321. if ( layers.length ) {
  13322. var layer = layers[ 0 ];
  13323. updateViewportFromBounds( cameraL.viewport, layer.leftBounds );
  13324. updateViewportFromBounds( cameraR.viewport, layer.rightBounds );
  13325. }
  13326. updateControllers();
  13327. return cameraVR;
  13328. };
  13329. this.getStandingMatrix = function () {
  13330. return standingMatrix;
  13331. };
  13332. this.isPresenting = isPresenting;
  13333. // Animation Loop
  13334. var animation = new WebGLAnimation();
  13335. this.setAnimationLoop = function ( callback ) {
  13336. animation.setAnimationLoop( callback );
  13337. if ( isPresenting() ) animation.start();
  13338. };
  13339. this.submitFrame = function () {
  13340. if ( isPresenting() ) device.submitFrame();
  13341. };
  13342. this.dispose = function () {
  13343. if ( typeof window !== 'undefined' ) {
  13344. window.removeEventListener( 'vrdisplaypresentchange', onVRDisplayPresentChange );
  13345. }
  13346. };
  13347. // DEPRECATED
  13348. this.setFrameOfReferenceType = function () {
  13349. console.warn( 'THREE.WebVRManager: setFrameOfReferenceType() has been deprecated.' );
  13350. };
  13351. }
  13352. /**
  13353. * @author mrdoob / http://mrdoob.com/
  13354. */
  13355. function WebXRManager( renderer ) {
  13356. var gl = renderer.context;
  13357. var session = null;
  13358. var referenceSpace = null;
  13359. var referenceSpaceType = 'local-floor';
  13360. var pose = null;
  13361. var controllers = [];
  13362. var inputSources = [];
  13363. function isPresenting() {
  13364. return session !== null && referenceSpace !== null;
  13365. }
  13366. //
  13367. var cameraL = new PerspectiveCamera();
  13368. cameraL.layers.enable( 1 );
  13369. cameraL.viewport = new Vector4();
  13370. var cameraR = new PerspectiveCamera();
  13371. cameraR.layers.enable( 2 );
  13372. cameraR.viewport = new Vector4();
  13373. var cameraVR = new ArrayCamera( [ cameraL, cameraR ] );
  13374. cameraVR.layers.enable( 1 );
  13375. cameraVR.layers.enable( 2 );
  13376. //
  13377. this.enabled = false;
  13378. this.getController = function ( id ) {
  13379. var controller = controllers[ id ];
  13380. if ( controller === undefined ) {
  13381. controller = new Group();
  13382. controller.matrixAutoUpdate = false;
  13383. controller.visible = false;
  13384. controllers[ id ] = controller;
  13385. }
  13386. return controller;
  13387. };
  13388. //
  13389. function onSessionEvent( event ) {
  13390. for ( var i = 0; i < controllers.length; i ++ ) {
  13391. if ( inputSources[ i ] === event.inputSource ) {
  13392. controllers[ i ].dispatchEvent( { type: event.type } );
  13393. }
  13394. }
  13395. }
  13396. function onSessionEnd() {
  13397. renderer.setFramebuffer( null );
  13398. renderer.setRenderTarget( renderer.getRenderTarget() ); // Hack #15830
  13399. animation.stop();
  13400. }
  13401. function onRequestReferenceSpace( value ) {
  13402. referenceSpace = value;
  13403. animation.setContext( session );
  13404. animation.start();
  13405. }
  13406. this.setFramebufferScaleFactor = function ( value ) {
  13407. };
  13408. this.setReferenceSpaceType = function ( value ) {
  13409. referenceSpaceType = value;
  13410. };
  13411. this.setSession = function ( value ) {
  13412. session = value;
  13413. if ( session !== null ) {
  13414. session.addEventListener( 'select', onSessionEvent );
  13415. session.addEventListener( 'selectstart', onSessionEvent );
  13416. session.addEventListener( 'selectend', onSessionEvent );
  13417. session.addEventListener( 'end', onSessionEnd );
  13418. session.updateRenderState( { baseLayer: new XRWebGLLayer( session, gl ) } );
  13419. session.requestReferenceSpace( referenceSpaceType ).then( onRequestReferenceSpace );
  13420. //
  13421. inputSources = session.inputSources;
  13422. session.addEventListener( 'inputsourceschange', function () {
  13423. inputSources = session.inputSources;
  13424. console.log( inputSources );
  13425. for ( var i = 0; i < controllers.length; i ++ ) {
  13426. var controller = controllers[ i ];
  13427. controller.userData.inputSource = inputSources[ i ];
  13428. }
  13429. } );
  13430. }
  13431. };
  13432. function updateCamera( camera, parent ) {
  13433. if ( parent === null ) {
  13434. camera.matrixWorld.copy( camera.matrix );
  13435. } else {
  13436. camera.matrixWorld.multiplyMatrices( parent.matrixWorld, camera.matrix );
  13437. }
  13438. camera.matrixWorldInverse.getInverse( camera.matrixWorld );
  13439. }
  13440. this.getCamera = function ( camera ) {
  13441. if ( isPresenting() ) {
  13442. var parent = camera.parent;
  13443. var cameras = cameraVR.cameras;
  13444. updateCamera( cameraVR, parent );
  13445. for ( var i = 0; i < cameras.length; i ++ ) {
  13446. updateCamera( cameras[ i ], parent );
  13447. }
  13448. // update camera and its children
  13449. camera.matrixWorld.copy( cameraVR.matrixWorld );
  13450. var children = camera.children;
  13451. for ( var i = 0, l = children.length; i < l; i ++ ) {
  13452. children[ i ].updateMatrixWorld( true );
  13453. }
  13454. setProjectionFromUnion( cameraVR, cameraL, cameraR );
  13455. return cameraVR;
  13456. }
  13457. return camera;
  13458. };
  13459. this.isPresenting = isPresenting;
  13460. // Animation Loop
  13461. var onAnimationFrameCallback = null;
  13462. function onAnimationFrame( time, frame ) {
  13463. pose = frame.getViewerPose( referenceSpace );
  13464. if ( pose !== null ) {
  13465. var views = pose.views;
  13466. var baseLayer = session.renderState.baseLayer;
  13467. renderer.setFramebuffer( baseLayer.framebuffer );
  13468. for ( var i = 0; i < views.length; i ++ ) {
  13469. var view = views[ i ];
  13470. var viewport = baseLayer.getViewport( view );
  13471. var viewMatrix = view.transform.inverse.matrix;
  13472. var camera = cameraVR.cameras[ i ];
  13473. camera.matrix.fromArray( viewMatrix ).getInverse( camera.matrix );
  13474. camera.projectionMatrix.fromArray( view.projectionMatrix );
  13475. camera.viewport.set( viewport.x, viewport.y, viewport.width, viewport.height );
  13476. if ( i === 0 ) {
  13477. cameraVR.matrix.copy( camera.matrix );
  13478. }
  13479. }
  13480. }
  13481. //
  13482. for ( var i = 0; i < controllers.length; i ++ ) {
  13483. var controller = controllers[ i ];
  13484. var inputSource = inputSources[ i ];
  13485. if ( inputSource ) {
  13486. var inputPose = frame.getPose( inputSource.targetRaySpace, referenceSpace );
  13487. if ( inputPose !== null ) {
  13488. controller.matrix.fromArray( inputPose.transform.matrix );
  13489. controller.matrix.decompose( controller.position, controller.rotation, controller.scale );
  13490. controller.visible = true;
  13491. continue;
  13492. }
  13493. }
  13494. controller.visible = false;
  13495. }
  13496. if ( onAnimationFrameCallback ) onAnimationFrameCallback( time );
  13497. }
  13498. var animation = new WebGLAnimation();
  13499. animation.setAnimationLoop( onAnimationFrame );
  13500. this.setAnimationLoop = function ( callback ) {
  13501. onAnimationFrameCallback = callback;
  13502. };
  13503. this.dispose = function () {};
  13504. // DEPRECATED
  13505. this.getStandingMatrix = function () {
  13506. console.warn( 'THREE.WebXRManager: getStandingMatrix() is no longer needed.' );
  13507. return new Matrix4();
  13508. };
  13509. this.getDevice = function () {
  13510. console.warn( 'THREE.WebXRManager: getDevice() has been deprecated.' );
  13511. };
  13512. this.setDevice = function () {
  13513. console.warn( 'THREE.WebXRManager: setDevice() has been deprecated.' );
  13514. };
  13515. this.setFrameOfReferenceType = function () {
  13516. console.warn( 'THREE.WebXRManager: setFrameOfReferenceType() has been deprecated.' );
  13517. };
  13518. this.submitFrame = function () {};
  13519. }
  13520. /**
  13521. * @author supereggbert / http://www.paulbrunt.co.uk/
  13522. * @author mrdoob / http://mrdoob.com/
  13523. * @author alteredq / http://alteredqualia.com/
  13524. * @author szimek / https://github.com/szimek/
  13525. * @author tschw
  13526. */
  13527. function WebGLRenderer( parameters ) {
  13528. console.log( 'THREE.WebGLRenderer', REVISION );
  13529. parameters = parameters || {};
  13530. var _canvas = parameters.canvas !== undefined ? parameters.canvas : document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' ),
  13531. _context = parameters.context !== undefined ? parameters.context : null,
  13532. _alpha = parameters.alpha !== undefined ? parameters.alpha : false,
  13533. _depth = parameters.depth !== undefined ? parameters.depth : true,
  13534. _stencil = parameters.stencil !== undefined ? parameters.stencil : true,
  13535. _antialias = parameters.antialias !== undefined ? parameters.antialias : false,
  13536. _premultipliedAlpha = parameters.premultipliedAlpha !== undefined ? parameters.premultipliedAlpha : true,
  13537. _preserveDrawingBuffer = parameters.preserveDrawingBuffer !== undefined ? parameters.preserveDrawingBuffer : false,
  13538. _powerPreference = parameters.powerPreference !== undefined ? parameters.powerPreference : 'default',
  13539. _failIfMajorPerformanceCaveat = parameters.failIfMajorPerformanceCaveat !== undefined ? parameters.failIfMajorPerformanceCaveat : false;
  13540. var currentRenderList = null;
  13541. var currentRenderState = null;
  13542. // public properties
  13543. this.domElement = _canvas;
  13544. this.context = null;
  13545. // Debug configuration container
  13546. this.debug = {
  13547. /**
  13548. * Enables error checking and reporting when shader programs are being compiled
  13549. * @type {boolean}
  13550. */
  13551. checkShaderErrors: true
  13552. };
  13553. // clearing
  13554. this.autoClear = true;
  13555. this.autoClearColor = true;
  13556. this.autoClearDepth = true;
  13557. this.autoClearStencil = true;
  13558. // scene graph
  13559. this.sortObjects = true;
  13560. // user-defined clipping
  13561. this.clippingPlanes = [];
  13562. this.localClippingEnabled = false;
  13563. // physically based shading
  13564. this.gammaFactor = 2.0; // for backwards compatibility
  13565. this.gammaInput = false;
  13566. this.gammaOutput = false;
  13567. // physical lights
  13568. this.physicallyCorrectLights = false;
  13569. // tone mapping
  13570. this.toneMapping = LinearToneMapping;
  13571. this.toneMappingExposure = 1.0;
  13572. this.toneMappingWhitePoint = 1.0;
  13573. // morphs
  13574. this.maxMorphTargets = 8;
  13575. this.maxMorphNormals = 4;
  13576. // internal properties
  13577. var _this = this,
  13578. _isContextLost = false,
  13579. // internal state cache
  13580. _framebuffer = null,
  13581. _currentActiveCubeFace = 0,
  13582. _currentActiveMipmapLevel = 0,
  13583. _currentRenderTarget = null,
  13584. _currentFramebuffer = null,
  13585. _currentMaterialId = - 1,
  13586. // geometry and program caching
  13587. _currentGeometryProgram = {
  13588. geometry: null,
  13589. program: null,
  13590. wireframe: false
  13591. },
  13592. _currentCamera = null,
  13593. _currentArrayCamera = null,
  13594. _currentViewport = new Vector4(),
  13595. _currentScissor = new Vector4(),
  13596. _currentScissorTest = null,
  13597. //
  13598. _width = _canvas.width,
  13599. _height = _canvas.height,
  13600. _pixelRatio = 1,
  13601. _viewport = new Vector4( 0, 0, _width, _height ),
  13602. _scissor = new Vector4( 0, 0, _width, _height ),
  13603. _scissorTest = false,
  13604. // frustum
  13605. _frustum = new Frustum(),
  13606. // clipping
  13607. _clipping = new WebGLClipping(),
  13608. _clippingEnabled = false,
  13609. _localClippingEnabled = false,
  13610. // camera matrices cache
  13611. _projScreenMatrix = new Matrix4(),
  13612. _vector3 = new Vector3();
  13613. function getTargetPixelRatio() {
  13614. return _currentRenderTarget === null ? _pixelRatio : 1;
  13615. }
  13616. // initialize
  13617. var _gl;
  13618. try {
  13619. var contextAttributes = {
  13620. alpha: _alpha,
  13621. depth: _depth,
  13622. stencil: _stencil,
  13623. antialias: _antialias,
  13624. premultipliedAlpha: _premultipliedAlpha,
  13625. preserveDrawingBuffer: _preserveDrawingBuffer,
  13626. powerPreference: _powerPreference,
  13627. failIfMajorPerformanceCaveat: _failIfMajorPerformanceCaveat,
  13628. xrCompatible: true
  13629. };
  13630. // event listeners must be registered before WebGL context is created, see #12753
  13631. _canvas.addEventListener( 'webglcontextlost', onContextLost, false );
  13632. _canvas.addEventListener( 'webglcontextrestored', onContextRestore, false );
  13633. _gl = _context || _canvas.getContext( 'webgl', contextAttributes ) || _canvas.getContext( 'experimental-webgl', contextAttributes );
  13634. if ( _gl === null ) {
  13635. if ( _canvas.getContext( 'webgl' ) !== null ) {
  13636. throw new Error( 'Error creating WebGL context with your selected attributes.' );
  13637. } else {
  13638. throw new Error( 'Error creating WebGL context.' );
  13639. }
  13640. }
  13641. // Some experimental-webgl implementations do not have getShaderPrecisionFormat
  13642. if ( _gl.getShaderPrecisionFormat === undefined ) {
  13643. _gl.getShaderPrecisionFormat = function () {
  13644. return { 'rangeMin': 1, 'rangeMax': 1, 'precision': 1 };
  13645. };
  13646. }
  13647. } catch ( error ) {
  13648. console.error( 'THREE.WebGLRenderer: ' + error.message );
  13649. throw error;
  13650. }
  13651. var extensions, capabilities, state, info;
  13652. var properties, textures, attributes, geometries, objects;
  13653. var programCache, renderLists, renderStates;
  13654. var background, morphtargets, bufferRenderer, indexedBufferRenderer;
  13655. var utils;
  13656. function initGLContext() {
  13657. extensions = new WebGLExtensions( _gl );
  13658. capabilities = new WebGLCapabilities( _gl, extensions, parameters );
  13659. if ( ! capabilities.isWebGL2 ) {
  13660. extensions.get( 'WEBGL_depth_texture' );
  13661. extensions.get( 'OES_texture_float' );
  13662. extensions.get( 'OES_texture_half_float' );
  13663. extensions.get( 'OES_texture_half_float_linear' );
  13664. extensions.get( 'OES_standard_derivatives' );
  13665. extensions.get( 'OES_element_index_uint' );
  13666. extensions.get( 'ANGLE_instanced_arrays' );
  13667. }
  13668. extensions.get( 'OES_texture_float_linear' );
  13669. utils = new WebGLUtils( _gl, extensions, capabilities );
  13670. state = new WebGLState( _gl, extensions, utils, capabilities );
  13671. state.scissor( _currentScissor.copy( _scissor ).multiplyScalar( _pixelRatio ) );
  13672. state.viewport( _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio ) );
  13673. info = new WebGLInfo( _gl );
  13674. properties = new WebGLProperties();
  13675. textures = new WebGLTextures( _gl, extensions, state, properties, capabilities, utils, info );
  13676. attributes = new WebGLAttributes( _gl );
  13677. geometries = new WebGLGeometries( _gl, attributes, info );
  13678. objects = new WebGLObjects( geometries, info );
  13679. morphtargets = new WebGLMorphtargets( _gl );
  13680. programCache = new WebGLPrograms( _this, extensions, capabilities, textures );
  13681. renderLists = new WebGLRenderLists();
  13682. renderStates = new WebGLRenderStates();
  13683. background = new WebGLBackground( _this, state, objects, _premultipliedAlpha );
  13684. bufferRenderer = new WebGLBufferRenderer( _gl, extensions, info, capabilities );
  13685. indexedBufferRenderer = new WebGLIndexedBufferRenderer( _gl, extensions, info, capabilities );
  13686. info.programs = programCache.programs;
  13687. _this.context = _gl;
  13688. _this.capabilities = capabilities;
  13689. _this.extensions = extensions;
  13690. _this.properties = properties;
  13691. _this.renderLists = renderLists;
  13692. _this.state = state;
  13693. _this.info = info;
  13694. }
  13695. initGLContext();
  13696. // vr
  13697. var vr = ( typeof navigator !== 'undefined' && 'xr' in navigator && 'supportsSession' in navigator.xr ) ? new WebXRManager( _this ) : new WebVRManager( _this );
  13698. this.vr = vr;
  13699. // shadow map
  13700. var shadowMap = new WebGLShadowMap( _this, objects, capabilities.maxTextureSize );
  13701. this.shadowMap = shadowMap;
  13702. // API
  13703. this.getContext = function () {
  13704. return _gl;
  13705. };
  13706. this.getContextAttributes = function () {
  13707. return _gl.getContextAttributes();
  13708. };
  13709. this.forceContextLoss = function () {
  13710. var extension = extensions.get( 'WEBGL_lose_context' );
  13711. if ( extension ) extension.loseContext();
  13712. };
  13713. this.forceContextRestore = function () {
  13714. var extension = extensions.get( 'WEBGL_lose_context' );
  13715. if ( extension ) extension.restoreContext();
  13716. };
  13717. this.getPixelRatio = function () {
  13718. return _pixelRatio;
  13719. };
  13720. this.setPixelRatio = function ( value ) {
  13721. if ( value === undefined ) return;
  13722. _pixelRatio = value;
  13723. this.setSize( _width, _height, false );
  13724. };
  13725. this.getSize = function ( target ) {
  13726. if ( target === undefined ) {
  13727. console.warn( 'WebGLRenderer: .getsize() now requires a Vector2 as an argument' );
  13728. target = new Vector2();
  13729. }
  13730. return target.set( _width, _height );
  13731. };
  13732. this.setSize = function ( width, height, updateStyle ) {
  13733. if ( vr.isPresenting() ) {
  13734. console.warn( 'THREE.WebGLRenderer: Can\'t change size while VR device is presenting.' );
  13735. return;
  13736. }
  13737. _width = width;
  13738. _height = height;
  13739. _canvas.width = width * _pixelRatio;
  13740. _canvas.height = height * _pixelRatio;
  13741. if ( updateStyle !== false ) {
  13742. _canvas.style.width = width + 'px';
  13743. _canvas.style.height = height + 'px';
  13744. }
  13745. this.setViewport( 0, 0, width, height );
  13746. };
  13747. this.getDrawingBufferSize = function ( target ) {
  13748. if ( target === undefined ) {
  13749. console.warn( 'WebGLRenderer: .getdrawingBufferSize() now requires a Vector2 as an argument' );
  13750. target = new Vector2();
  13751. }
  13752. return target.set( _width * _pixelRatio, _height * _pixelRatio );
  13753. };
  13754. this.setDrawingBufferSize = function ( width, height, pixelRatio ) {
  13755. _width = width;
  13756. _height = height;
  13757. _pixelRatio = pixelRatio;
  13758. _canvas.width = width * pixelRatio;
  13759. _canvas.height = height * pixelRatio;
  13760. this.setViewport( 0, 0, width, height );
  13761. };
  13762. this.getCurrentViewport = function ( target ) {
  13763. if ( target === undefined ) {
  13764. console.warn( 'WebGLRenderer: .getCurrentViewport() now requires a Vector4 as an argument' );
  13765. target = new Vector4();
  13766. }
  13767. return target.copy( _currentViewport );
  13768. };
  13769. this.getViewport = function ( target ) {
  13770. return target.copy( _viewport );
  13771. };
  13772. this.setViewport = function ( x, y, width, height ) {
  13773. if ( x.isVector4 ) {
  13774. _viewport.set( x.x, x.y, x.z, x.w );
  13775. } else {
  13776. _viewport.set( x, y, width, height );
  13777. }
  13778. state.viewport( _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio ) );
  13779. };
  13780. this.getScissor = function ( target ) {
  13781. return target.copy( _scissor );
  13782. };
  13783. this.setScissor = function ( x, y, width, height ) {
  13784. if ( x.isVector4 ) {
  13785. _scissor.set( x.x, x.y, x.z, x.w );
  13786. } else {
  13787. _scissor.set( x, y, width, height );
  13788. }
  13789. state.scissor( _currentScissor.copy( _scissor ).multiplyScalar( _pixelRatio ) );
  13790. };
  13791. this.getScissorTest = function () {
  13792. return _scissorTest;
  13793. };
  13794. this.setScissorTest = function ( boolean ) {
  13795. state.setScissorTest( _scissorTest = boolean );
  13796. };
  13797. // Clearing
  13798. this.getClearColor = function () {
  13799. return background.getClearColor();
  13800. };
  13801. this.setClearColor = function () {
  13802. background.setClearColor.apply( background, arguments );
  13803. };
  13804. this.getClearAlpha = function () {
  13805. return background.getClearAlpha();
  13806. };
  13807. this.setClearAlpha = function () {
  13808. background.setClearAlpha.apply( background, arguments );
  13809. };
  13810. this.clear = function ( color, depth, stencil ) {
  13811. var bits = 0;
  13812. if ( color === undefined || color ) bits |= 16384;
  13813. if ( depth === undefined || depth ) bits |= 256;
  13814. if ( stencil === undefined || stencil ) bits |= 1024;
  13815. _gl.clear( bits );
  13816. };
  13817. this.clearColor = function () {
  13818. this.clear( true, false, false );
  13819. };
  13820. this.clearDepth = function () {
  13821. this.clear( false, true, false );
  13822. };
  13823. this.clearStencil = function () {
  13824. this.clear( false, false, true );
  13825. };
  13826. //
  13827. this.dispose = function () {
  13828. _canvas.removeEventListener( 'webglcontextlost', onContextLost, false );
  13829. _canvas.removeEventListener( 'webglcontextrestored', onContextRestore, false );
  13830. renderLists.dispose();
  13831. renderStates.dispose();
  13832. properties.dispose();
  13833. objects.dispose();
  13834. vr.dispose();
  13835. animation.stop();
  13836. };
  13837. // Events
  13838. function onContextLost( event ) {
  13839. event.preventDefault();
  13840. console.log( 'THREE.WebGLRenderer: Context Lost.' );
  13841. _isContextLost = true;
  13842. }
  13843. function onContextRestore( /* event */ ) {
  13844. console.log( 'THREE.WebGLRenderer: Context Restored.' );
  13845. _isContextLost = false;
  13846. initGLContext();
  13847. }
  13848. function onMaterialDispose( event ) {
  13849. var material = event.target;
  13850. material.removeEventListener( 'dispose', onMaterialDispose );
  13851. deallocateMaterial( material );
  13852. }
  13853. // Buffer deallocation
  13854. function deallocateMaterial( material ) {
  13855. releaseMaterialProgramReference( material );
  13856. properties.remove( material );
  13857. }
  13858. function releaseMaterialProgramReference( material ) {
  13859. var programInfo = properties.get( material ).program;
  13860. material.program = undefined;
  13861. if ( programInfo !== undefined ) {
  13862. programCache.releaseProgram( programInfo );
  13863. }
  13864. }
  13865. // Buffer rendering
  13866. function renderObjectImmediate( object, program ) {
  13867. object.render( function ( object ) {
  13868. _this.renderBufferImmediate( object, program );
  13869. } );
  13870. }
  13871. this.renderBufferImmediate = function ( object, program ) {
  13872. state.initAttributes();
  13873. var buffers = properties.get( object );
  13874. if ( object.hasPositions && ! buffers.position ) buffers.position = _gl.createBuffer();
  13875. if ( object.hasNormals && ! buffers.normal ) buffers.normal = _gl.createBuffer();
  13876. if ( object.hasUvs && ! buffers.uv ) buffers.uv = _gl.createBuffer();
  13877. if ( object.hasColors && ! buffers.color ) buffers.color = _gl.createBuffer();
  13878. var programAttributes = program.getAttributes();
  13879. if ( object.hasPositions ) {
  13880. _gl.bindBuffer( 34962, buffers.position );
  13881. _gl.bufferData( 34962, object.positionArray, 35048 );
  13882. state.enableAttribute( programAttributes.position );
  13883. _gl.vertexAttribPointer( programAttributes.position, 3, 5126, false, 0, 0 );
  13884. }
  13885. if ( object.hasNormals ) {
  13886. _gl.bindBuffer( 34962, buffers.normal );
  13887. _gl.bufferData( 34962, object.normalArray, 35048 );
  13888. state.enableAttribute( programAttributes.normal );
  13889. _gl.vertexAttribPointer( programAttributes.normal, 3, 5126, false, 0, 0 );
  13890. }
  13891. if ( object.hasUvs ) {
  13892. _gl.bindBuffer( 34962, buffers.uv );
  13893. _gl.bufferData( 34962, object.uvArray, 35048 );
  13894. state.enableAttribute( programAttributes.uv );
  13895. _gl.vertexAttribPointer( programAttributes.uv, 2, 5126, false, 0, 0 );
  13896. }
  13897. if ( object.hasColors ) {
  13898. _gl.bindBuffer( 34962, buffers.color );
  13899. _gl.bufferData( 34962, object.colorArray, 35048 );
  13900. state.enableAttribute( programAttributes.color );
  13901. _gl.vertexAttribPointer( programAttributes.color, 3, 5126, false, 0, 0 );
  13902. }
  13903. state.disableUnusedAttributes();
  13904. _gl.drawArrays( 4, 0, object.count );
  13905. object.count = 0;
  13906. };
  13907. this.renderBufferDirect = function ( camera, fog, geometry, material, object, group ) {
  13908. var frontFaceCW = ( object.isMesh && object.matrixWorld.determinant() < 0 );
  13909. state.setMaterial( material, frontFaceCW );
  13910. var program = setProgram( camera, fog, material, object );
  13911. var updateBuffers = false;
  13912. if ( _currentGeometryProgram.geometry !== geometry.id ||
  13913. _currentGeometryProgram.program !== program.id ||
  13914. _currentGeometryProgram.wireframe !== ( material.wireframe === true ) ) {
  13915. _currentGeometryProgram.geometry = geometry.id;
  13916. _currentGeometryProgram.program = program.id;
  13917. _currentGeometryProgram.wireframe = material.wireframe === true;
  13918. updateBuffers = true;
  13919. }
  13920. if ( object.morphTargetInfluences ) {
  13921. morphtargets.update( object, geometry, material, program );
  13922. updateBuffers = true;
  13923. }
  13924. //
  13925. var index = geometry.index;
  13926. var position = geometry.attributes.position;
  13927. var rangeFactor = 1;
  13928. if ( material.wireframe === true ) {
  13929. index = geometries.getWireframeAttribute( geometry );
  13930. rangeFactor = 2;
  13931. }
  13932. var attribute;
  13933. var renderer = bufferRenderer;
  13934. if ( index !== null ) {
  13935. attribute = attributes.get( index );
  13936. renderer = indexedBufferRenderer;
  13937. renderer.setIndex( attribute );
  13938. }
  13939. if ( updateBuffers ) {
  13940. setupVertexAttributes( material, program, geometry );
  13941. if ( index !== null ) {
  13942. _gl.bindBuffer( 34963, attribute.buffer );
  13943. }
  13944. }
  13945. //
  13946. var dataCount = Infinity;
  13947. if ( index !== null ) {
  13948. dataCount = index.count;
  13949. } else if ( position !== undefined ) {
  13950. dataCount = position.count;
  13951. }
  13952. var rangeStart = geometry.drawRange.start * rangeFactor;
  13953. var rangeCount = geometry.drawRange.count * rangeFactor;
  13954. var groupStart = group !== null ? group.start * rangeFactor : 0;
  13955. var groupCount = group !== null ? group.count * rangeFactor : Infinity;
  13956. var drawStart = Math.max( rangeStart, groupStart );
  13957. var drawEnd = Math.min( dataCount, rangeStart + rangeCount, groupStart + groupCount ) - 1;
  13958. var drawCount = Math.max( 0, drawEnd - drawStart + 1 );
  13959. if ( drawCount === 0 ) return;
  13960. //
  13961. if ( object.isMesh ) {
  13962. if ( material.wireframe === true ) {
  13963. state.setLineWidth( material.wireframeLinewidth * getTargetPixelRatio() );
  13964. renderer.setMode( 1 );
  13965. } else {
  13966. switch ( object.drawMode ) {
  13967. case TrianglesDrawMode:
  13968. renderer.setMode( 4 );
  13969. break;
  13970. case TriangleStripDrawMode:
  13971. renderer.setMode( 5 );
  13972. break;
  13973. case TriangleFanDrawMode:
  13974. renderer.setMode( 6 );
  13975. break;
  13976. }
  13977. }
  13978. } else if ( object.isLine ) {
  13979. var lineWidth = material.linewidth;
  13980. if ( lineWidth === undefined ) lineWidth = 1; // Not using Line*Material
  13981. state.setLineWidth( lineWidth * getTargetPixelRatio() );
  13982. if ( object.isLineSegments ) {
  13983. renderer.setMode( 1 );
  13984. } else if ( object.isLineLoop ) {
  13985. renderer.setMode( 2 );
  13986. } else {
  13987. renderer.setMode( 3 );
  13988. }
  13989. } else if ( object.isPoints ) {
  13990. renderer.setMode( 0 );
  13991. } else if ( object.isSprite ) {
  13992. renderer.setMode( 4 );
  13993. }
  13994. if ( geometry && geometry.isInstancedBufferGeometry ) {
  13995. if ( geometry.maxInstancedCount > 0 ) {
  13996. renderer.renderInstances( geometry, drawStart, drawCount );
  13997. }
  13998. } else {
  13999. renderer.render( drawStart, drawCount );
  14000. }
  14001. };
  14002. function setupVertexAttributes( material, program, geometry ) {
  14003. if ( geometry && geometry.isInstancedBufferGeometry && ! capabilities.isWebGL2 ) {
  14004. if ( extensions.get( 'ANGLE_instanced_arrays' ) === null ) {
  14005. console.error( 'THREE.WebGLRenderer.setupVertexAttributes: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  14006. return;
  14007. }
  14008. }
  14009. state.initAttributes();
  14010. var geometryAttributes = geometry.attributes;
  14011. var programAttributes = program.getAttributes();
  14012. var materialDefaultAttributeValues = material.defaultAttributeValues;
  14013. for ( var name in programAttributes ) {
  14014. var programAttribute = programAttributes[ name ];
  14015. if ( programAttribute >= 0 ) {
  14016. var geometryAttribute = geometryAttributes[ name ];
  14017. if ( geometryAttribute !== undefined ) {
  14018. var normalized = geometryAttribute.normalized;
  14019. var size = geometryAttribute.itemSize;
  14020. var attribute = attributes.get( geometryAttribute );
  14021. // TODO Attribute may not be available on context restore
  14022. if ( attribute === undefined ) continue;
  14023. var buffer = attribute.buffer;
  14024. var type = attribute.type;
  14025. var bytesPerElement = attribute.bytesPerElement;
  14026. if ( geometryAttribute.isInterleavedBufferAttribute ) {
  14027. var data = geometryAttribute.data;
  14028. var stride = data.stride;
  14029. var offset = geometryAttribute.offset;
  14030. if ( data && data.isInstancedInterleavedBuffer ) {
  14031. state.enableAttributeAndDivisor( programAttribute, data.meshPerAttribute );
  14032. if ( geometry.maxInstancedCount === undefined ) {
  14033. geometry.maxInstancedCount = data.meshPerAttribute * data.count;
  14034. }
  14035. } else {
  14036. state.enableAttribute( programAttribute );
  14037. }
  14038. _gl.bindBuffer( 34962, buffer );
  14039. _gl.vertexAttribPointer( programAttribute, size, type, normalized, stride * bytesPerElement, offset * bytesPerElement );
  14040. } else {
  14041. if ( geometryAttribute.isInstancedBufferAttribute ) {
  14042. state.enableAttributeAndDivisor( programAttribute, geometryAttribute.meshPerAttribute );
  14043. if ( geometry.maxInstancedCount === undefined ) {
  14044. geometry.maxInstancedCount = geometryAttribute.meshPerAttribute * geometryAttribute.count;
  14045. }
  14046. } else {
  14047. state.enableAttribute( programAttribute );
  14048. }
  14049. _gl.bindBuffer( 34962, buffer );
  14050. _gl.vertexAttribPointer( programAttribute, size, type, normalized, 0, 0 );
  14051. }
  14052. } else if ( materialDefaultAttributeValues !== undefined ) {
  14053. var value = materialDefaultAttributeValues[ name ];
  14054. if ( value !== undefined ) {
  14055. switch ( value.length ) {
  14056. case 2:
  14057. _gl.vertexAttrib2fv( programAttribute, value );
  14058. break;
  14059. case 3:
  14060. _gl.vertexAttrib3fv( programAttribute, value );
  14061. break;
  14062. case 4:
  14063. _gl.vertexAttrib4fv( programAttribute, value );
  14064. break;
  14065. default:
  14066. _gl.vertexAttrib1fv( programAttribute, value );
  14067. }
  14068. }
  14069. }
  14070. }
  14071. }
  14072. state.disableUnusedAttributes();
  14073. }
  14074. // Compile
  14075. this.compile = function ( scene, camera ) {
  14076. currentRenderState = renderStates.get( scene, camera );
  14077. currentRenderState.init();
  14078. scene.traverse( function ( object ) {
  14079. if ( object.isLight ) {
  14080. currentRenderState.pushLight( object );
  14081. if ( object.castShadow ) {
  14082. currentRenderState.pushShadow( object );
  14083. }
  14084. }
  14085. } );
  14086. currentRenderState.setupLights( camera );
  14087. scene.traverse( function ( object ) {
  14088. if ( object.material ) {
  14089. if ( Array.isArray( object.material ) ) {
  14090. for ( var i = 0; i < object.material.length; i ++ ) {
  14091. initMaterial( object.material[ i ], scene.fog, object );
  14092. }
  14093. } else {
  14094. initMaterial( object.material, scene.fog, object );
  14095. }
  14096. }
  14097. } );
  14098. };
  14099. // Animation Loop
  14100. var onAnimationFrameCallback = null;
  14101. function onAnimationFrame( time ) {
  14102. if ( vr.isPresenting() ) return;
  14103. if ( onAnimationFrameCallback ) onAnimationFrameCallback( time );
  14104. }
  14105. var animation = new WebGLAnimation();
  14106. animation.setAnimationLoop( onAnimationFrame );
  14107. if ( typeof window !== 'undefined' ) animation.setContext( window );
  14108. this.setAnimationLoop = function ( callback ) {
  14109. onAnimationFrameCallback = callback;
  14110. vr.setAnimationLoop( callback );
  14111. animation.start();
  14112. };
  14113. // Rendering
  14114. this.render = function ( scene, camera ) {
  14115. var renderTarget, forceClear;
  14116. if ( arguments[ 2 ] !== undefined ) {
  14117. console.warn( 'THREE.WebGLRenderer.render(): the renderTarget argument has been removed. Use .setRenderTarget() instead.' );
  14118. renderTarget = arguments[ 2 ];
  14119. }
  14120. if ( arguments[ 3 ] !== undefined ) {
  14121. console.warn( 'THREE.WebGLRenderer.render(): the forceClear argument has been removed. Use .clear() instead.' );
  14122. forceClear = arguments[ 3 ];
  14123. }
  14124. if ( ! ( camera && camera.isCamera ) ) {
  14125. console.error( 'THREE.WebGLRenderer.render: camera is not an instance of THREE.Camera.' );
  14126. return;
  14127. }
  14128. if ( _isContextLost ) return;
  14129. // reset caching for this frame
  14130. _currentGeometryProgram.geometry = null;
  14131. _currentGeometryProgram.program = null;
  14132. _currentGeometryProgram.wireframe = false;
  14133. _currentMaterialId = - 1;
  14134. _currentCamera = null;
  14135. // update scene graph
  14136. if ( scene.autoUpdate === true ) scene.updateMatrixWorld();
  14137. // update camera matrices and frustum
  14138. if ( camera.parent === null ) camera.updateMatrixWorld();
  14139. if ( vr.enabled ) {
  14140. camera = vr.getCamera( camera );
  14141. }
  14142. //
  14143. currentRenderState = renderStates.get( scene, camera );
  14144. currentRenderState.init();
  14145. scene.onBeforeRender( _this, scene, camera, renderTarget || _currentRenderTarget );
  14146. _projScreenMatrix.multiplyMatrices( camera.projectionMatrix, camera.matrixWorldInverse );
  14147. _frustum.setFromMatrix( _projScreenMatrix );
  14148. _localClippingEnabled = this.localClippingEnabled;
  14149. _clippingEnabled = _clipping.init( this.clippingPlanes, _localClippingEnabled, camera );
  14150. currentRenderList = renderLists.get( scene, camera );
  14151. currentRenderList.init();
  14152. projectObject( scene, camera, 0, _this.sortObjects );
  14153. if ( _this.sortObjects === true ) {
  14154. currentRenderList.sort();
  14155. }
  14156. //
  14157. if ( _clippingEnabled ) _clipping.beginShadows();
  14158. var shadowsArray = currentRenderState.state.shadowsArray;
  14159. shadowMap.render( shadowsArray, scene, camera );
  14160. currentRenderState.setupLights( camera );
  14161. if ( _clippingEnabled ) _clipping.endShadows();
  14162. //
  14163. if ( this.info.autoReset ) this.info.reset();
  14164. if ( renderTarget !== undefined ) {
  14165. this.setRenderTarget( renderTarget );
  14166. }
  14167. //
  14168. background.render( currentRenderList, scene, camera, forceClear );
  14169. // render scene
  14170. var opaqueObjects = currentRenderList.opaque;
  14171. var transparentObjects = currentRenderList.transparent;
  14172. if ( scene.overrideMaterial ) {
  14173. var overrideMaterial = scene.overrideMaterial;
  14174. if ( opaqueObjects.length ) renderObjects( opaqueObjects, scene, camera, overrideMaterial );
  14175. if ( transparentObjects.length ) renderObjects( transparentObjects, scene, camera, overrideMaterial );
  14176. } else {
  14177. // opaque pass (front-to-back order)
  14178. if ( opaqueObjects.length ) renderObjects( opaqueObjects, scene, camera );
  14179. // transparent pass (back-to-front order)
  14180. if ( transparentObjects.length ) renderObjects( transparentObjects, scene, camera );
  14181. }
  14182. //
  14183. scene.onAfterRender( _this, scene, camera );
  14184. //
  14185. if ( _currentRenderTarget !== null ) {
  14186. // Generate mipmap if we're using any kind of mipmap filtering
  14187. textures.updateRenderTargetMipmap( _currentRenderTarget );
  14188. // resolve multisample renderbuffers to a single-sample texture if necessary
  14189. textures.updateMultisampleRenderTarget( _currentRenderTarget );
  14190. }
  14191. // Ensure depth buffer writing is enabled so it can be cleared on next render
  14192. state.buffers.depth.setTest( true );
  14193. state.buffers.depth.setMask( true );
  14194. state.buffers.color.setMask( true );
  14195. state.setPolygonOffset( false );
  14196. if ( vr.enabled ) {
  14197. vr.submitFrame();
  14198. }
  14199. // _gl.finish();
  14200. currentRenderList = null;
  14201. currentRenderState = null;
  14202. };
  14203. function projectObject( object, camera, groupOrder, sortObjects ) {
  14204. if ( object.visible === false ) return;
  14205. var visible = object.layers.test( camera.layers );
  14206. if ( visible ) {
  14207. if ( object.isGroup ) {
  14208. groupOrder = object.renderOrder;
  14209. } else if ( object.isLight ) {
  14210. currentRenderState.pushLight( object );
  14211. if ( object.castShadow ) {
  14212. currentRenderState.pushShadow( object );
  14213. }
  14214. } else if ( object.isSprite ) {
  14215. if ( ! object.frustumCulled || _frustum.intersectsSprite( object ) ) {
  14216. if ( sortObjects ) {
  14217. _vector3.setFromMatrixPosition( object.matrixWorld )
  14218. .applyMatrix4( _projScreenMatrix );
  14219. }
  14220. var geometry = objects.update( object );
  14221. var material = object.material;
  14222. if ( material.visible ) {
  14223. currentRenderList.push( object, geometry, material, groupOrder, _vector3.z, null );
  14224. }
  14225. }
  14226. } else if ( object.isImmediateRenderObject ) {
  14227. if ( sortObjects ) {
  14228. _vector3.setFromMatrixPosition( object.matrixWorld )
  14229. .applyMatrix4( _projScreenMatrix );
  14230. }
  14231. currentRenderList.push( object, null, object.material, groupOrder, _vector3.z, null );
  14232. } else if ( object.isMesh || object.isLine || object.isPoints ) {
  14233. if ( object.isSkinnedMesh ) {
  14234. object.skeleton.update();
  14235. }
  14236. if ( ! object.frustumCulled || _frustum.intersectsObject( object ) ) {
  14237. if ( sortObjects ) {
  14238. _vector3.setFromMatrixPosition( object.matrixWorld )
  14239. .applyMatrix4( _projScreenMatrix );
  14240. }
  14241. var geometry = objects.update( object );
  14242. var material = object.material;
  14243. if ( Array.isArray( material ) ) {
  14244. var groups = geometry.groups;
  14245. for ( var i = 0, l = groups.length; i < l; i ++ ) {
  14246. var group = groups[ i ];
  14247. var groupMaterial = material[ group.materialIndex ];
  14248. if ( groupMaterial && groupMaterial.visible ) {
  14249. currentRenderList.push( object, geometry, groupMaterial, groupOrder, _vector3.z, group );
  14250. }
  14251. }
  14252. } else if ( material.visible ) {
  14253. currentRenderList.push( object, geometry, material, groupOrder, _vector3.z, null );
  14254. }
  14255. }
  14256. }
  14257. }
  14258. var children = object.children;
  14259. for ( var i = 0, l = children.length; i < l; i ++ ) {
  14260. projectObject( children[ i ], camera, groupOrder, sortObjects );
  14261. }
  14262. }
  14263. function renderObjects( renderList, scene, camera, overrideMaterial ) {
  14264. for ( var i = 0, l = renderList.length; i < l; i ++ ) {
  14265. var renderItem = renderList[ i ];
  14266. var object = renderItem.object;
  14267. var geometry = renderItem.geometry;
  14268. var material = overrideMaterial === undefined ? renderItem.material : overrideMaterial;
  14269. var group = renderItem.group;
  14270. if ( camera.isArrayCamera ) {
  14271. _currentArrayCamera = camera;
  14272. var cameras = camera.cameras;
  14273. for ( var j = 0, jl = cameras.length; j < jl; j ++ ) {
  14274. var camera2 = cameras[ j ];
  14275. if ( object.layers.test( camera2.layers ) ) {
  14276. state.viewport( _currentViewport.copy( camera2.viewport ) );
  14277. currentRenderState.setupLights( camera2 );
  14278. renderObject( object, scene, camera2, geometry, material, group );
  14279. }
  14280. }
  14281. } else {
  14282. _currentArrayCamera = null;
  14283. renderObject( object, scene, camera, geometry, material, group );
  14284. }
  14285. }
  14286. }
  14287. function renderObject( object, scene, camera, geometry, material, group ) {
  14288. object.onBeforeRender( _this, scene, camera, geometry, material, group );
  14289. currentRenderState = renderStates.get( scene, _currentArrayCamera || camera );
  14290. object.modelViewMatrix.multiplyMatrices( camera.matrixWorldInverse, object.matrixWorld );
  14291. object.normalMatrix.getNormalMatrix( object.modelViewMatrix );
  14292. if ( object.isImmediateRenderObject ) {
  14293. state.setMaterial( material );
  14294. var program = setProgram( camera, scene.fog, material, object );
  14295. _currentGeometryProgram.geometry = null;
  14296. _currentGeometryProgram.program = null;
  14297. _currentGeometryProgram.wireframe = false;
  14298. renderObjectImmediate( object, program );
  14299. } else {
  14300. _this.renderBufferDirect( camera, scene.fog, geometry, material, object, group );
  14301. }
  14302. object.onAfterRender( _this, scene, camera, geometry, material, group );
  14303. currentRenderState = renderStates.get( scene, _currentArrayCamera || camera );
  14304. }
  14305. function initMaterial( material, fog, object ) {
  14306. var materialProperties = properties.get( material );
  14307. var lights = currentRenderState.state.lights;
  14308. var shadowsArray = currentRenderState.state.shadowsArray;
  14309. var lightsHash = materialProperties.lightsHash;
  14310. var lightsStateHash = lights.state.hash;
  14311. var parameters = programCache.getParameters(
  14312. material, lights.state, shadowsArray, fog, _clipping.numPlanes, _clipping.numIntersection, object );
  14313. var code = programCache.getProgramCode( material, parameters );
  14314. var program = materialProperties.program;
  14315. var programChange = true;
  14316. if ( program === undefined ) {
  14317. // new material
  14318. material.addEventListener( 'dispose', onMaterialDispose );
  14319. } else if ( program.code !== code ) {
  14320. // changed glsl or parameters
  14321. releaseMaterialProgramReference( material );
  14322. } else if ( lightsHash.stateID !== lightsStateHash.stateID ||
  14323. lightsHash.directionalLength !== lightsStateHash.directionalLength ||
  14324. lightsHash.pointLength !== lightsStateHash.pointLength ||
  14325. lightsHash.spotLength !== lightsStateHash.spotLength ||
  14326. lightsHash.rectAreaLength !== lightsStateHash.rectAreaLength ||
  14327. lightsHash.hemiLength !== lightsStateHash.hemiLength ||
  14328. lightsHash.shadowsLength !== lightsStateHash.shadowsLength ) {
  14329. lightsHash.stateID = lightsStateHash.stateID;
  14330. lightsHash.directionalLength = lightsStateHash.directionalLength;
  14331. lightsHash.pointLength = lightsStateHash.pointLength;
  14332. lightsHash.spotLength = lightsStateHash.spotLength;
  14333. lightsHash.rectAreaLength = lightsStateHash.rectAreaLength;
  14334. lightsHash.hemiLength = lightsStateHash.hemiLength;
  14335. lightsHash.shadowsLength = lightsStateHash.shadowsLength;
  14336. programChange = false;
  14337. } else if ( parameters.shaderID !== undefined ) {
  14338. // same glsl and uniform list
  14339. return;
  14340. } else {
  14341. // only rebuild uniform list
  14342. programChange = false;
  14343. }
  14344. if ( programChange ) {
  14345. if ( parameters.shaderID ) {
  14346. var shader = ShaderLib[ parameters.shaderID ];
  14347. materialProperties.shader = {
  14348. name: material.type,
  14349. uniforms: cloneUniforms( shader.uniforms ),
  14350. vertexShader: shader.vertexShader,
  14351. fragmentShader: shader.fragmentShader
  14352. };
  14353. } else {
  14354. materialProperties.shader = {
  14355. name: material.type,
  14356. uniforms: material.uniforms,
  14357. vertexShader: material.vertexShader,
  14358. fragmentShader: material.fragmentShader
  14359. };
  14360. }
  14361. material.onBeforeCompile( materialProperties.shader, _this );
  14362. // Computing code again as onBeforeCompile may have changed the shaders
  14363. code = programCache.getProgramCode( material, parameters );
  14364. program = programCache.acquireProgram( material, materialProperties.shader, parameters, code );
  14365. materialProperties.program = program;
  14366. material.program = program;
  14367. }
  14368. var programAttributes = program.getAttributes();
  14369. if ( material.morphTargets ) {
  14370. material.numSupportedMorphTargets = 0;
  14371. for ( var i = 0; i < _this.maxMorphTargets; i ++ ) {
  14372. if ( programAttributes[ 'morphTarget' + i ] >= 0 ) {
  14373. material.numSupportedMorphTargets ++;
  14374. }
  14375. }
  14376. }
  14377. if ( material.morphNormals ) {
  14378. material.numSupportedMorphNormals = 0;
  14379. for ( var i = 0; i < _this.maxMorphNormals; i ++ ) {
  14380. if ( programAttributes[ 'morphNormal' + i ] >= 0 ) {
  14381. material.numSupportedMorphNormals ++;
  14382. }
  14383. }
  14384. }
  14385. var uniforms = materialProperties.shader.uniforms;
  14386. if ( ! material.isShaderMaterial &&
  14387. ! material.isRawShaderMaterial ||
  14388. material.clipping === true ) {
  14389. materialProperties.numClippingPlanes = _clipping.numPlanes;
  14390. materialProperties.numIntersection = _clipping.numIntersection;
  14391. uniforms.clippingPlanes = _clipping.uniform;
  14392. }
  14393. materialProperties.fog = fog;
  14394. // store the light setup it was created for
  14395. if ( lightsHash === undefined ) {
  14396. materialProperties.lightsHash = lightsHash = {};
  14397. }
  14398. lightsHash.stateID = lightsStateHash.stateID;
  14399. lightsHash.directionalLength = lightsStateHash.directionalLength;
  14400. lightsHash.pointLength = lightsStateHash.pointLength;
  14401. lightsHash.spotLength = lightsStateHash.spotLength;
  14402. lightsHash.rectAreaLength = lightsStateHash.rectAreaLength;
  14403. lightsHash.hemiLength = lightsStateHash.hemiLength;
  14404. lightsHash.shadowsLength = lightsStateHash.shadowsLength;
  14405. if ( material.lights ) {
  14406. // wire up the material to this renderer's lighting state
  14407. uniforms.ambientLightColor.value = lights.state.ambient;
  14408. uniforms.lightProbe.value = lights.state.probe;
  14409. uniforms.directionalLights.value = lights.state.directional;
  14410. uniforms.spotLights.value = lights.state.spot;
  14411. uniforms.rectAreaLights.value = lights.state.rectArea;
  14412. uniforms.pointLights.value = lights.state.point;
  14413. uniforms.hemisphereLights.value = lights.state.hemi;
  14414. uniforms.directionalShadowMap.value = lights.state.directionalShadowMap;
  14415. uniforms.directionalShadowMatrix.value = lights.state.directionalShadowMatrix;
  14416. uniforms.spotShadowMap.value = lights.state.spotShadowMap;
  14417. uniforms.spotShadowMatrix.value = lights.state.spotShadowMatrix;
  14418. uniforms.pointShadowMap.value = lights.state.pointShadowMap;
  14419. uniforms.pointShadowMatrix.value = lights.state.pointShadowMatrix;
  14420. // TODO (abelnation): add area lights shadow info to uniforms
  14421. }
  14422. var progUniforms = materialProperties.program.getUniforms(),
  14423. uniformsList =
  14424. WebGLUniforms.seqWithValue( progUniforms.seq, uniforms );
  14425. materialProperties.uniformsList = uniformsList;
  14426. }
  14427. function setProgram( camera, fog, material, object ) {
  14428. textures.resetTextureUnits();
  14429. var materialProperties = properties.get( material );
  14430. var lights = currentRenderState.state.lights;
  14431. var lightsHash = materialProperties.lightsHash;
  14432. var lightsStateHash = lights.state.hash;
  14433. if ( _clippingEnabled ) {
  14434. if ( _localClippingEnabled || camera !== _currentCamera ) {
  14435. var useCache =
  14436. camera === _currentCamera &&
  14437. material.id === _currentMaterialId;
  14438. // we might want to call this function with some ClippingGroup
  14439. // object instead of the material, once it becomes feasible
  14440. // (#8465, #8379)
  14441. _clipping.setState(
  14442. material.clippingPlanes, material.clipIntersection, material.clipShadows,
  14443. camera, materialProperties, useCache );
  14444. }
  14445. }
  14446. if ( material.needsUpdate === false ) {
  14447. if ( materialProperties.program === undefined ) {
  14448. material.needsUpdate = true;
  14449. } else if ( material.fog && materialProperties.fog !== fog ) {
  14450. material.needsUpdate = true;
  14451. } else if ( material.lights && ( lightsHash.stateID !== lightsStateHash.stateID ||
  14452. lightsHash.directionalLength !== lightsStateHash.directionalLength ||
  14453. lightsHash.pointLength !== lightsStateHash.pointLength ||
  14454. lightsHash.spotLength !== lightsStateHash.spotLength ||
  14455. lightsHash.rectAreaLength !== lightsStateHash.rectAreaLength ||
  14456. lightsHash.hemiLength !== lightsStateHash.hemiLength ||
  14457. lightsHash.shadowsLength !== lightsStateHash.shadowsLength ) ) {
  14458. material.needsUpdate = true;
  14459. } else if ( materialProperties.numClippingPlanes !== undefined &&
  14460. ( materialProperties.numClippingPlanes !== _clipping.numPlanes ||
  14461. materialProperties.numIntersection !== _clipping.numIntersection ) ) {
  14462. material.needsUpdate = true;
  14463. }
  14464. }
  14465. if ( material.needsUpdate ) {
  14466. initMaterial( material, fog, object );
  14467. material.needsUpdate = false;
  14468. }
  14469. var refreshProgram = false;
  14470. var refreshMaterial = false;
  14471. var refreshLights = false;
  14472. var program = materialProperties.program,
  14473. p_uniforms = program.getUniforms(),
  14474. m_uniforms = materialProperties.shader.uniforms;
  14475. if ( state.useProgram( program.program ) ) {
  14476. refreshProgram = true;
  14477. refreshMaterial = true;
  14478. refreshLights = true;
  14479. }
  14480. if ( material.id !== _currentMaterialId ) {
  14481. _currentMaterialId = material.id;
  14482. refreshMaterial = true;
  14483. }
  14484. if ( refreshProgram || _currentCamera !== camera ) {
  14485. p_uniforms.setValue( _gl, 'projectionMatrix', camera.projectionMatrix );
  14486. if ( capabilities.logarithmicDepthBuffer ) {
  14487. p_uniforms.setValue( _gl, 'logDepthBufFC',
  14488. 2.0 / ( Math.log( camera.far + 1.0 ) / Math.LN2 ) );
  14489. }
  14490. if ( _currentCamera !== camera ) {
  14491. _currentCamera = camera;
  14492. // lighting uniforms depend on the camera so enforce an update
  14493. // now, in case this material supports lights - or later, when
  14494. // the next material that does gets activated:
  14495. refreshMaterial = true; // set to true on material change
  14496. refreshLights = true; // remains set until update done
  14497. }
  14498. // load material specific uniforms
  14499. // (shader material also gets them for the sake of genericity)
  14500. if ( material.isShaderMaterial ||
  14501. material.isMeshPhongMaterial ||
  14502. material.isMeshStandardMaterial ||
  14503. material.envMap ) {
  14504. var uCamPos = p_uniforms.map.cameraPosition;
  14505. if ( uCamPos !== undefined ) {
  14506. uCamPos.setValue( _gl,
  14507. _vector3.setFromMatrixPosition( camera.matrixWorld ) );
  14508. }
  14509. }
  14510. if ( material.isMeshPhongMaterial ||
  14511. material.isMeshLambertMaterial ||
  14512. material.isMeshBasicMaterial ||
  14513. material.isMeshStandardMaterial ||
  14514. material.isShaderMaterial ||
  14515. material.skinning ) {
  14516. p_uniforms.setValue( _gl, 'viewMatrix', camera.matrixWorldInverse );
  14517. }
  14518. }
  14519. // skinning uniforms must be set even if material didn't change
  14520. // auto-setting of texture unit for bone texture must go before other textures
  14521. // not sure why, but otherwise weird things happen
  14522. if ( material.skinning ) {
  14523. p_uniforms.setOptional( _gl, object, 'bindMatrix' );
  14524. p_uniforms.setOptional( _gl, object, 'bindMatrixInverse' );
  14525. var skeleton = object.skeleton;
  14526. if ( skeleton ) {
  14527. var bones = skeleton.bones;
  14528. if ( capabilities.floatVertexTextures ) {
  14529. if ( skeleton.boneTexture === undefined ) {
  14530. // layout (1 matrix = 4 pixels)
  14531. // RGBA RGBA RGBA RGBA (=> column1, column2, column3, column4)
  14532. // with 8x8 pixel texture max 16 bones * 4 pixels = (8 * 8)
  14533. // 16x16 pixel texture max 64 bones * 4 pixels = (16 * 16)
  14534. // 32x32 pixel texture max 256 bones * 4 pixels = (32 * 32)
  14535. // 64x64 pixel texture max 1024 bones * 4 pixels = (64 * 64)
  14536. var size = Math.sqrt( bones.length * 4 ); // 4 pixels needed for 1 matrix
  14537. size = _Math.ceilPowerOfTwo( size );
  14538. size = Math.max( size, 4 );
  14539. var boneMatrices = new Float32Array( size * size * 4 ); // 4 floats per RGBA pixel
  14540. boneMatrices.set( skeleton.boneMatrices ); // copy current values
  14541. var boneTexture = new DataTexture( boneMatrices, size, size, RGBAFormat, FloatType );
  14542. boneTexture.needsUpdate = true;
  14543. skeleton.boneMatrices = boneMatrices;
  14544. skeleton.boneTexture = boneTexture;
  14545. skeleton.boneTextureSize = size;
  14546. }
  14547. p_uniforms.setValue( _gl, 'boneTexture', skeleton.boneTexture, textures );
  14548. p_uniforms.setValue( _gl, 'boneTextureSize', skeleton.boneTextureSize );
  14549. } else {
  14550. p_uniforms.setOptional( _gl, skeleton, 'boneMatrices' );
  14551. }
  14552. }
  14553. }
  14554. if ( refreshMaterial ) {
  14555. p_uniforms.setValue( _gl, 'toneMappingExposure', _this.toneMappingExposure );
  14556. p_uniforms.setValue( _gl, 'toneMappingWhitePoint', _this.toneMappingWhitePoint );
  14557. if ( material.lights ) {
  14558. // the current material requires lighting info
  14559. // note: all lighting uniforms are always set correctly
  14560. // they simply reference the renderer's state for their
  14561. // values
  14562. //
  14563. // use the current material's .needsUpdate flags to set
  14564. // the GL state when required
  14565. markUniformsLightsNeedsUpdate( m_uniforms, refreshLights );
  14566. }
  14567. // refresh uniforms common to several materials
  14568. if ( fog && material.fog ) {
  14569. refreshUniformsFog( m_uniforms, fog );
  14570. }
  14571. if ( material.isMeshBasicMaterial ) {
  14572. refreshUniformsCommon( m_uniforms, material );
  14573. } else if ( material.isMeshLambertMaterial ) {
  14574. refreshUniformsCommon( m_uniforms, material );
  14575. refreshUniformsLambert( m_uniforms, material );
  14576. } else if ( material.isMeshPhongMaterial ) {
  14577. refreshUniformsCommon( m_uniforms, material );
  14578. if ( material.isMeshToonMaterial ) {
  14579. refreshUniformsToon( m_uniforms, material );
  14580. } else {
  14581. refreshUniformsPhong( m_uniforms, material );
  14582. }
  14583. } else if ( material.isMeshStandardMaterial ) {
  14584. refreshUniformsCommon( m_uniforms, material );
  14585. if ( material.isMeshPhysicalMaterial ) {
  14586. refreshUniformsPhysical( m_uniforms, material );
  14587. } else {
  14588. refreshUniformsStandard( m_uniforms, material );
  14589. }
  14590. } else if ( material.isMeshMatcapMaterial ) {
  14591. refreshUniformsCommon( m_uniforms, material );
  14592. refreshUniformsMatcap( m_uniforms, material );
  14593. } else if ( material.isMeshDepthMaterial ) {
  14594. refreshUniformsCommon( m_uniforms, material );
  14595. refreshUniformsDepth( m_uniforms, material );
  14596. } else if ( material.isMeshDistanceMaterial ) {
  14597. refreshUniformsCommon( m_uniforms, material );
  14598. refreshUniformsDistance( m_uniforms, material );
  14599. } else if ( material.isMeshNormalMaterial ) {
  14600. refreshUniformsCommon( m_uniforms, material );
  14601. refreshUniformsNormal( m_uniforms, material );
  14602. } else if ( material.isLineBasicMaterial ) {
  14603. refreshUniformsLine( m_uniforms, material );
  14604. if ( material.isLineDashedMaterial ) {
  14605. refreshUniformsDash( m_uniforms, material );
  14606. }
  14607. } else if ( material.isPointsMaterial ) {
  14608. refreshUniformsPoints( m_uniforms, material );
  14609. } else if ( material.isSpriteMaterial ) {
  14610. refreshUniformsSprites( m_uniforms, material );
  14611. } else if ( material.isShadowMaterial ) {
  14612. m_uniforms.color.value.copy( material.color );
  14613. m_uniforms.opacity.value = material.opacity;
  14614. }
  14615. // RectAreaLight Texture
  14616. // TODO (mrdoob): Find a nicer implementation
  14617. if ( m_uniforms.ltc_1 !== undefined ) m_uniforms.ltc_1.value = UniformsLib.LTC_1;
  14618. if ( m_uniforms.ltc_2 !== undefined ) m_uniforms.ltc_2.value = UniformsLib.LTC_2;
  14619. WebGLUniforms.upload( _gl, materialProperties.uniformsList, m_uniforms, textures );
  14620. }
  14621. if ( material.isShaderMaterial && material.uniformsNeedUpdate === true ) {
  14622. WebGLUniforms.upload( _gl, materialProperties.uniformsList, m_uniforms, textures );
  14623. material.uniformsNeedUpdate = false;
  14624. }
  14625. if ( material.isSpriteMaterial ) {
  14626. p_uniforms.setValue( _gl, 'center', object.center );
  14627. }
  14628. // common matrices
  14629. p_uniforms.setValue( _gl, 'modelViewMatrix', object.modelViewMatrix );
  14630. p_uniforms.setValue( _gl, 'normalMatrix', object.normalMatrix );
  14631. p_uniforms.setValue( _gl, 'modelMatrix', object.matrixWorld );
  14632. return program;
  14633. }
  14634. // Uniforms (refresh uniforms objects)
  14635. function refreshUniformsCommon( uniforms, material ) {
  14636. uniforms.opacity.value = material.opacity;
  14637. if ( material.color ) {
  14638. uniforms.diffuse.value.copy( material.color );
  14639. }
  14640. if ( material.emissive ) {
  14641. uniforms.emissive.value.copy( material.emissive ).multiplyScalar( material.emissiveIntensity );
  14642. }
  14643. if ( material.map ) {
  14644. uniforms.map.value = material.map;
  14645. }
  14646. if ( material.alphaMap ) {
  14647. uniforms.alphaMap.value = material.alphaMap;
  14648. }
  14649. if ( material.specularMap ) {
  14650. uniforms.specularMap.value = material.specularMap;
  14651. }
  14652. if ( material.envMap ) {
  14653. uniforms.envMap.value = material.envMap;
  14654. // don't flip CubeTexture envMaps, flip everything else:
  14655. // WebGLRenderTargetCube will be flipped for backwards compatibility
  14656. // WebGLRenderTargetCube.texture will be flipped because it's a Texture and NOT a CubeTexture
  14657. // this check must be handled differently, or removed entirely, if WebGLRenderTargetCube uses a CubeTexture in the future
  14658. uniforms.flipEnvMap.value = material.envMap.isCubeTexture ? - 1 : 1;
  14659. uniforms.reflectivity.value = material.reflectivity;
  14660. uniforms.refractionRatio.value = material.refractionRatio;
  14661. uniforms.maxMipLevel.value = properties.get( material.envMap ).__maxMipLevel;
  14662. }
  14663. if ( material.lightMap ) {
  14664. uniforms.lightMap.value = material.lightMap;
  14665. uniforms.lightMapIntensity.value = material.lightMapIntensity;
  14666. }
  14667. if ( material.aoMap ) {
  14668. uniforms.aoMap.value = material.aoMap;
  14669. uniforms.aoMapIntensity.value = material.aoMapIntensity;
  14670. }
  14671. // uv repeat and offset setting priorities
  14672. // 1. color map
  14673. // 2. specular map
  14674. // 3. normal map
  14675. // 4. bump map
  14676. // 5. alpha map
  14677. // 6. emissive map
  14678. var uvScaleMap;
  14679. if ( material.map ) {
  14680. uvScaleMap = material.map;
  14681. } else if ( material.specularMap ) {
  14682. uvScaleMap = material.specularMap;
  14683. } else if ( material.displacementMap ) {
  14684. uvScaleMap = material.displacementMap;
  14685. } else if ( material.normalMap ) {
  14686. uvScaleMap = material.normalMap;
  14687. } else if ( material.bumpMap ) {
  14688. uvScaleMap = material.bumpMap;
  14689. } else if ( material.roughnessMap ) {
  14690. uvScaleMap = material.roughnessMap;
  14691. } else if ( material.metalnessMap ) {
  14692. uvScaleMap = material.metalnessMap;
  14693. } else if ( material.alphaMap ) {
  14694. uvScaleMap = material.alphaMap;
  14695. } else if ( material.emissiveMap ) {
  14696. uvScaleMap = material.emissiveMap;
  14697. }
  14698. if ( uvScaleMap !== undefined ) {
  14699. // backwards compatibility
  14700. if ( uvScaleMap.isWebGLRenderTarget ) {
  14701. uvScaleMap = uvScaleMap.texture;
  14702. }
  14703. if ( uvScaleMap.matrixAutoUpdate === true ) {
  14704. uvScaleMap.updateMatrix();
  14705. }
  14706. uniforms.uvTransform.value.copy( uvScaleMap.matrix );
  14707. }
  14708. }
  14709. function refreshUniformsLine( uniforms, material ) {
  14710. uniforms.diffuse.value.copy( material.color );
  14711. uniforms.opacity.value = material.opacity;
  14712. }
  14713. function refreshUniformsDash( uniforms, material ) {
  14714. uniforms.dashSize.value = material.dashSize;
  14715. uniforms.totalSize.value = material.dashSize + material.gapSize;
  14716. uniforms.scale.value = material.scale;
  14717. }
  14718. function refreshUniformsPoints( uniforms, material ) {
  14719. uniforms.diffuse.value.copy( material.color );
  14720. uniforms.opacity.value = material.opacity;
  14721. uniforms.size.value = material.size * _pixelRatio;
  14722. uniforms.scale.value = _height * 0.5;
  14723. uniforms.map.value = material.map;
  14724. if ( material.map !== null ) {
  14725. if ( material.map.matrixAutoUpdate === true ) {
  14726. material.map.updateMatrix();
  14727. }
  14728. uniforms.uvTransform.value.copy( material.map.matrix );
  14729. }
  14730. }
  14731. function refreshUniformsSprites( uniforms, material ) {
  14732. uniforms.diffuse.value.copy( material.color );
  14733. uniforms.opacity.value = material.opacity;
  14734. uniforms.rotation.value = material.rotation;
  14735. uniforms.map.value = material.map;
  14736. if ( material.map !== null ) {
  14737. if ( material.map.matrixAutoUpdate === true ) {
  14738. material.map.updateMatrix();
  14739. }
  14740. uniforms.uvTransform.value.copy( material.map.matrix );
  14741. }
  14742. }
  14743. function refreshUniformsFog( uniforms, fog ) {
  14744. uniforms.fogColor.value.copy( fog.color );
  14745. if ( fog.isFog ) {
  14746. uniforms.fogNear.value = fog.near;
  14747. uniforms.fogFar.value = fog.far;
  14748. } else if ( fog.isFogExp2 ) {
  14749. uniforms.fogDensity.value = fog.density;
  14750. }
  14751. }
  14752. function refreshUniformsLambert( uniforms, material ) {
  14753. if ( material.emissiveMap ) {
  14754. uniforms.emissiveMap.value = material.emissiveMap;
  14755. }
  14756. }
  14757. function refreshUniformsPhong( uniforms, material ) {
  14758. uniforms.specular.value.copy( material.specular );
  14759. uniforms.shininess.value = Math.max( material.shininess, 1e-4 ); // to prevent pow( 0.0, 0.0 )
  14760. if ( material.emissiveMap ) {
  14761. uniforms.emissiveMap.value = material.emissiveMap;
  14762. }
  14763. if ( material.bumpMap ) {
  14764. uniforms.bumpMap.value = material.bumpMap;
  14765. uniforms.bumpScale.value = material.bumpScale;
  14766. if ( material.side === BackSide ) uniforms.bumpScale.value *= - 1;
  14767. }
  14768. if ( material.normalMap ) {
  14769. uniforms.normalMap.value = material.normalMap;
  14770. uniforms.normalScale.value.copy( material.normalScale );
  14771. if ( material.side === BackSide ) uniforms.normalScale.value.negate();
  14772. }
  14773. if ( material.displacementMap ) {
  14774. uniforms.displacementMap.value = material.displacementMap;
  14775. uniforms.displacementScale.value = material.displacementScale;
  14776. uniforms.displacementBias.value = material.displacementBias;
  14777. }
  14778. }
  14779. function refreshUniformsToon( uniforms, material ) {
  14780. refreshUniformsPhong( uniforms, material );
  14781. if ( material.gradientMap ) {
  14782. uniforms.gradientMap.value = material.gradientMap;
  14783. }
  14784. }
  14785. function refreshUniformsStandard( uniforms, material ) {
  14786. uniforms.roughness.value = material.roughness;
  14787. uniforms.metalness.value = material.metalness;
  14788. if ( material.roughnessMap ) {
  14789. uniforms.roughnessMap.value = material.roughnessMap;
  14790. }
  14791. if ( material.metalnessMap ) {
  14792. uniforms.metalnessMap.value = material.metalnessMap;
  14793. }
  14794. if ( material.emissiveMap ) {
  14795. uniforms.emissiveMap.value = material.emissiveMap;
  14796. }
  14797. if ( material.bumpMap ) {
  14798. uniforms.bumpMap.value = material.bumpMap;
  14799. uniforms.bumpScale.value = material.bumpScale;
  14800. if ( material.side === BackSide ) uniforms.bumpScale.value *= - 1;
  14801. }
  14802. if ( material.normalMap ) {
  14803. uniforms.normalMap.value = material.normalMap;
  14804. uniforms.normalScale.value.copy( material.normalScale );
  14805. if ( material.side === BackSide ) uniforms.normalScale.value.negate();
  14806. }
  14807. if ( material.displacementMap ) {
  14808. uniforms.displacementMap.value = material.displacementMap;
  14809. uniforms.displacementScale.value = material.displacementScale;
  14810. uniforms.displacementBias.value = material.displacementBias;
  14811. }
  14812. if ( material.envMap ) {
  14813. //uniforms.envMap.value = material.envMap; // part of uniforms common
  14814. uniforms.envMapIntensity.value = material.envMapIntensity;
  14815. }
  14816. }
  14817. function refreshUniformsPhysical( uniforms, material ) {
  14818. refreshUniformsStandard( uniforms, material );
  14819. uniforms.reflectivity.value = material.reflectivity; // also part of uniforms common
  14820. uniforms.clearCoat.value = material.clearCoat;
  14821. uniforms.clearCoatRoughness.value = material.clearCoatRoughness;
  14822. }
  14823. function refreshUniformsMatcap( uniforms, material ) {
  14824. if ( material.matcap ) {
  14825. uniforms.matcap.value = material.matcap;
  14826. }
  14827. if ( material.bumpMap ) {
  14828. uniforms.bumpMap.value = material.bumpMap;
  14829. uniforms.bumpScale.value = material.bumpScale;
  14830. if ( material.side === BackSide ) uniforms.bumpScale.value *= - 1;
  14831. }
  14832. if ( material.normalMap ) {
  14833. uniforms.normalMap.value = material.normalMap;
  14834. uniforms.normalScale.value.copy( material.normalScale );
  14835. if ( material.side === BackSide ) uniforms.normalScale.value.negate();
  14836. }
  14837. if ( material.displacementMap ) {
  14838. uniforms.displacementMap.value = material.displacementMap;
  14839. uniforms.displacementScale.value = material.displacementScale;
  14840. uniforms.displacementBias.value = material.displacementBias;
  14841. }
  14842. }
  14843. function refreshUniformsDepth( uniforms, material ) {
  14844. if ( material.displacementMap ) {
  14845. uniforms.displacementMap.value = material.displacementMap;
  14846. uniforms.displacementScale.value = material.displacementScale;
  14847. uniforms.displacementBias.value = material.displacementBias;
  14848. }
  14849. }
  14850. function refreshUniformsDistance( uniforms, material ) {
  14851. if ( material.displacementMap ) {
  14852. uniforms.displacementMap.value = material.displacementMap;
  14853. uniforms.displacementScale.value = material.displacementScale;
  14854. uniforms.displacementBias.value = material.displacementBias;
  14855. }
  14856. uniforms.referencePosition.value.copy( material.referencePosition );
  14857. uniforms.nearDistance.value = material.nearDistance;
  14858. uniforms.farDistance.value = material.farDistance;
  14859. }
  14860. function refreshUniformsNormal( uniforms, material ) {
  14861. if ( material.bumpMap ) {
  14862. uniforms.bumpMap.value = material.bumpMap;
  14863. uniforms.bumpScale.value = material.bumpScale;
  14864. if ( material.side === BackSide ) uniforms.bumpScale.value *= - 1;
  14865. }
  14866. if ( material.normalMap ) {
  14867. uniforms.normalMap.value = material.normalMap;
  14868. uniforms.normalScale.value.copy( material.normalScale );
  14869. if ( material.side === BackSide ) uniforms.normalScale.value.negate();
  14870. }
  14871. if ( material.displacementMap ) {
  14872. uniforms.displacementMap.value = material.displacementMap;
  14873. uniforms.displacementScale.value = material.displacementScale;
  14874. uniforms.displacementBias.value = material.displacementBias;
  14875. }
  14876. }
  14877. // If uniforms are marked as clean, they don't need to be loaded to the GPU.
  14878. function markUniformsLightsNeedsUpdate( uniforms, value ) {
  14879. uniforms.ambientLightColor.needsUpdate = value;
  14880. uniforms.lightProbe.needsUpdate = value;
  14881. uniforms.directionalLights.needsUpdate = value;
  14882. uniforms.pointLights.needsUpdate = value;
  14883. uniforms.spotLights.needsUpdate = value;
  14884. uniforms.rectAreaLights.needsUpdate = value;
  14885. uniforms.hemisphereLights.needsUpdate = value;
  14886. }
  14887. //
  14888. this.setFramebuffer = function ( value ) {
  14889. if ( _framebuffer !== value ) _gl.bindFramebuffer( 36160, value );
  14890. _framebuffer = value;
  14891. };
  14892. this.getActiveCubeFace = function () {
  14893. return _currentActiveCubeFace;
  14894. };
  14895. this.getActiveMipMapLevel = function () {
  14896. return _currentActiveMipmapLevel;
  14897. };
  14898. this.getRenderTarget = function () {
  14899. return _currentRenderTarget;
  14900. };
  14901. this.setRenderTarget = function ( renderTarget, activeCubeFace, activeMipMapLevel ) {
  14902. _currentRenderTarget = renderTarget;
  14903. _currentActiveCubeFace = activeCubeFace;
  14904. _currentActiveMipmapLevel = activeMipMapLevel;
  14905. if ( renderTarget && properties.get( renderTarget ).__webglFramebuffer === undefined ) {
  14906. textures.setupRenderTarget( renderTarget );
  14907. }
  14908. var framebuffer = _framebuffer;
  14909. var isCube = false;
  14910. if ( renderTarget ) {
  14911. var __webglFramebuffer = properties.get( renderTarget ).__webglFramebuffer;
  14912. if ( renderTarget.isWebGLRenderTargetCube ) {
  14913. framebuffer = __webglFramebuffer[ activeCubeFace || 0 ];
  14914. isCube = true;
  14915. } else if ( renderTarget.isWebGLMultisampleRenderTarget ) {
  14916. framebuffer = properties.get( renderTarget ).__webglMultisampledFramebuffer;
  14917. } else {
  14918. framebuffer = __webglFramebuffer;
  14919. }
  14920. _currentViewport.copy( renderTarget.viewport );
  14921. _currentScissor.copy( renderTarget.scissor );
  14922. _currentScissorTest = renderTarget.scissorTest;
  14923. } else {
  14924. _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio );
  14925. _currentScissor.copy( _scissor ).multiplyScalar( _pixelRatio );
  14926. _currentScissorTest = _scissorTest;
  14927. }
  14928. if ( _currentFramebuffer !== framebuffer ) {
  14929. _gl.bindFramebuffer( 36160, framebuffer );
  14930. _currentFramebuffer = framebuffer;
  14931. }
  14932. state.viewport( _currentViewport );
  14933. state.scissor( _currentScissor );
  14934. state.setScissorTest( _currentScissorTest );
  14935. if ( isCube ) {
  14936. var textureProperties = properties.get( renderTarget.texture );
  14937. _gl.framebufferTexture2D( 36160, 36064, 34069 + ( activeCubeFace || 0 ), textureProperties.__webglTexture, activeMipMapLevel || 0 );
  14938. }
  14939. };
  14940. this.readRenderTargetPixels = function ( renderTarget, x, y, width, height, buffer, activeCubeFaceIndex ) {
  14941. if ( ! ( renderTarget && renderTarget.isWebGLRenderTarget ) ) {
  14942. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.' );
  14943. return;
  14944. }
  14945. var framebuffer = properties.get( renderTarget ).__webglFramebuffer;
  14946. if ( renderTarget.isWebGLRenderTargetCube && activeCubeFaceIndex !== undefined ) {
  14947. framebuffer = framebuffer[ activeCubeFaceIndex ];
  14948. }
  14949. if ( framebuffer ) {
  14950. var restore = false;
  14951. if ( framebuffer !== _currentFramebuffer ) {
  14952. _gl.bindFramebuffer( 36160, framebuffer );
  14953. restore = true;
  14954. }
  14955. try {
  14956. var texture = renderTarget.texture;
  14957. var textureFormat = texture.format;
  14958. var textureType = texture.type;
  14959. if ( textureFormat !== RGBAFormat && utils.convert( textureFormat ) !== _gl.getParameter( 35739 ) ) {
  14960. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA or implementation defined format.' );
  14961. return;
  14962. }
  14963. if ( textureType !== UnsignedByteType && utils.convert( textureType ) !== _gl.getParameter( 35738 ) && // IE11, Edge and Chrome Mac < 52 (#9513)
  14964. ! ( textureType === FloatType && ( capabilities.isWebGL2 || extensions.get( 'OES_texture_float' ) || extensions.get( 'WEBGL_color_buffer_float' ) ) ) && // Chrome Mac >= 52 and Firefox
  14965. ! ( textureType === HalfFloatType && ( capabilities.isWebGL2 ? extensions.get( 'EXT_color_buffer_float' ) : extensions.get( 'EXT_color_buffer_half_float' ) ) ) ) {
  14966. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in UnsignedByteType or implementation defined type.' );
  14967. return;
  14968. }
  14969. if ( _gl.checkFramebufferStatus( 36160 ) === 36053 ) {
  14970. // the following if statement ensures valid read requests (no out-of-bounds pixels, see #8604)
  14971. if ( ( x >= 0 && x <= ( renderTarget.width - width ) ) && ( y >= 0 && y <= ( renderTarget.height - height ) ) ) {
  14972. _gl.readPixels( x, y, width, height, utils.convert( textureFormat ), utils.convert( textureType ), buffer );
  14973. }
  14974. } else {
  14975. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: readPixels from renderTarget failed. Framebuffer not complete.' );
  14976. }
  14977. } finally {
  14978. if ( restore ) {
  14979. _gl.bindFramebuffer( 36160, _currentFramebuffer );
  14980. }
  14981. }
  14982. }
  14983. };
  14984. this.copyFramebufferToTexture = function ( position, texture, level ) {
  14985. var width = texture.image.width;
  14986. var height = texture.image.height;
  14987. var glFormat = utils.convert( texture.format );
  14988. textures.setTexture2D( texture, 0 );
  14989. _gl.copyTexImage2D( 3553, level || 0, glFormat, position.x, position.y, width, height, 0 );
  14990. };
  14991. this.copyTextureToTexture = function ( position, srcTexture, dstTexture, level ) {
  14992. var width = srcTexture.image.width;
  14993. var height = srcTexture.image.height;
  14994. var glFormat = utils.convert( dstTexture.format );
  14995. var glType = utils.convert( dstTexture.type );
  14996. textures.setTexture2D( dstTexture, 0 );
  14997. if ( srcTexture.isDataTexture ) {
  14998. _gl.texSubImage2D( 3553, level || 0, position.x, position.y, width, height, glFormat, glType, srcTexture.image.data );
  14999. } else {
  15000. _gl.texSubImage2D( 3553, level || 0, position.x, position.y, glFormat, glType, srcTexture.image );
  15001. }
  15002. };
  15003. /*
  15004. if ( typeof __THREE_DEVTOOLS__ !== undefined ) {
  15005. __THREE_DEVTOOLS__.dispatchEvent( { type: 'renderer', value: this } );
  15006. }
  15007. */
  15008. }
  15009. /**
  15010. * @author mrdoob / http://mrdoob.com/
  15011. * @author alteredq / http://alteredqualia.com/
  15012. */
  15013. function FogExp2( color, density ) {
  15014. this.name = '';
  15015. this.color = new Color( color );
  15016. this.density = ( density !== undefined ) ? density : 0.00025;
  15017. }
  15018. Object.assign( FogExp2.prototype, {
  15019. isFogExp2: true,
  15020. clone: function () {
  15021. return new FogExp2( this.color, this.density );
  15022. },
  15023. toJSON: function ( /* meta */ ) {
  15024. return {
  15025. type: 'FogExp2',
  15026. color: this.color.getHex(),
  15027. density: this.density
  15028. };
  15029. }
  15030. } );
  15031. /**
  15032. * @author mrdoob / http://mrdoob.com/
  15033. * @author alteredq / http://alteredqualia.com/
  15034. */
  15035. function Fog( color, near, far ) {
  15036. this.name = '';
  15037. this.color = new Color( color );
  15038. this.near = ( near !== undefined ) ? near : 1;
  15039. this.far = ( far !== undefined ) ? far : 1000;
  15040. }
  15041. Object.assign( Fog.prototype, {
  15042. isFog: true,
  15043. clone: function () {
  15044. return new Fog( this.color, this.near, this.far );
  15045. },
  15046. toJSON: function ( /* meta */ ) {
  15047. return {
  15048. type: 'Fog',
  15049. color: this.color.getHex(),
  15050. near: this.near,
  15051. far: this.far
  15052. };
  15053. }
  15054. } );
  15055. /**
  15056. * @author mrdoob / http://mrdoob.com/
  15057. */
  15058. function Scene() {
  15059. Object3D.call( this );
  15060. this.type = 'Scene';
  15061. this.background = null;
  15062. this.fog = null;
  15063. this.overrideMaterial = null;
  15064. this.autoUpdate = true; // checked by the renderer
  15065. /*
  15066. if ( typeof __THREE_DEVTOOLS__ !== undefined ) {
  15067. __THREE_DEVTOOLS__.dispatchEvent( { type: 'scene', value: this } );
  15068. }
  15069. */
  15070. }
  15071. Scene.prototype = Object.assign( Object.create( Object3D.prototype ), {
  15072. constructor: Scene,
  15073. isScene: true,
  15074. copy: function ( source, recursive ) {
  15075. Object3D.prototype.copy.call( this, source, recursive );
  15076. if ( source.background !== null ) this.background = source.background.clone();
  15077. if ( source.fog !== null ) this.fog = source.fog.clone();
  15078. if ( source.overrideMaterial !== null ) this.overrideMaterial = source.overrideMaterial.clone();
  15079. this.autoUpdate = source.autoUpdate;
  15080. this.matrixAutoUpdate = source.matrixAutoUpdate;
  15081. return this;
  15082. },
  15083. toJSON: function ( meta ) {
  15084. var data = Object3D.prototype.toJSON.call( this, meta );
  15085. if ( this.background !== null ) data.object.background = this.background.toJSON( meta );
  15086. if ( this.fog !== null ) data.object.fog = this.fog.toJSON();
  15087. return data;
  15088. },
  15089. dispose: function () {
  15090. this.dispatchEvent( { type: 'dispose' } );
  15091. }
  15092. } );
  15093. /**
  15094. * @author benaadams / https://twitter.com/ben_a_adams
  15095. */
  15096. function InterleavedBuffer( array, stride ) {
  15097. this.array = array;
  15098. this.stride = stride;
  15099. this.count = array !== undefined ? array.length / stride : 0;
  15100. this.dynamic = false;
  15101. this.updateRange = { offset: 0, count: - 1 };
  15102. this.version = 0;
  15103. }
  15104. Object.defineProperty( InterleavedBuffer.prototype, 'needsUpdate', {
  15105. set: function ( value ) {
  15106. if ( value === true ) this.version ++;
  15107. }
  15108. } );
  15109. Object.assign( InterleavedBuffer.prototype, {
  15110. isInterleavedBuffer: true,
  15111. onUploadCallback: function () {},
  15112. setArray: function ( array ) {
  15113. if ( Array.isArray( array ) ) {
  15114. throw new TypeError( 'THREE.BufferAttribute: array should be a Typed Array.' );
  15115. }
  15116. this.count = array !== undefined ? array.length / this.stride : 0;
  15117. this.array = array;
  15118. return this;
  15119. },
  15120. setDynamic: function ( value ) {
  15121. this.dynamic = value;
  15122. return this;
  15123. },
  15124. copy: function ( source ) {
  15125. this.array = new source.array.constructor( source.array );
  15126. this.count = source.count;
  15127. this.stride = source.stride;
  15128. this.dynamic = source.dynamic;
  15129. return this;
  15130. },
  15131. copyAt: function ( index1, attribute, index2 ) {
  15132. index1 *= this.stride;
  15133. index2 *= attribute.stride;
  15134. for ( var i = 0, l = this.stride; i < l; i ++ ) {
  15135. this.array[ index1 + i ] = attribute.array[ index2 + i ];
  15136. }
  15137. return this;
  15138. },
  15139. set: function ( value, offset ) {
  15140. if ( offset === undefined ) offset = 0;
  15141. this.array.set( value, offset );
  15142. return this;
  15143. },
  15144. clone: function () {
  15145. return new this.constructor().copy( this );
  15146. },
  15147. onUpload: function ( callback ) {
  15148. this.onUploadCallback = callback;
  15149. return this;
  15150. }
  15151. } );
  15152. /**
  15153. * @author benaadams / https://twitter.com/ben_a_adams
  15154. */
  15155. function InterleavedBufferAttribute( interleavedBuffer, itemSize, offset, normalized ) {
  15156. this.data = interleavedBuffer;
  15157. this.itemSize = itemSize;
  15158. this.offset = offset;
  15159. this.normalized = normalized === true;
  15160. }
  15161. Object.defineProperties( InterleavedBufferAttribute.prototype, {
  15162. count: {
  15163. get: function () {
  15164. return this.data.count;
  15165. }
  15166. },
  15167. array: {
  15168. get: function () {
  15169. return this.data.array;
  15170. }
  15171. }
  15172. } );
  15173. Object.assign( InterleavedBufferAttribute.prototype, {
  15174. isInterleavedBufferAttribute: true,
  15175. setX: function ( index, x ) {
  15176. this.data.array[ index * this.data.stride + this.offset ] = x;
  15177. return this;
  15178. },
  15179. setY: function ( index, y ) {
  15180. this.data.array[ index * this.data.stride + this.offset + 1 ] = y;
  15181. return this;
  15182. },
  15183. setZ: function ( index, z ) {
  15184. this.data.array[ index * this.data.stride + this.offset + 2 ] = z;
  15185. return this;
  15186. },
  15187. setW: function ( index, w ) {
  15188. this.data.array[ index * this.data.stride + this.offset + 3 ] = w;
  15189. return this;
  15190. },
  15191. getX: function ( index ) {
  15192. return this.data.array[ index * this.data.stride + this.offset ];
  15193. },
  15194. getY: function ( index ) {
  15195. return this.data.array[ index * this.data.stride + this.offset + 1 ];
  15196. },
  15197. getZ: function ( index ) {
  15198. return this.data.array[ index * this.data.stride + this.offset + 2 ];
  15199. },
  15200. getW: function ( index ) {
  15201. return this.data.array[ index * this.data.stride + this.offset + 3 ];
  15202. },
  15203. setXY: function ( index, x, y ) {
  15204. index = index * this.data.stride + this.offset;
  15205. this.data.array[ index + 0 ] = x;
  15206. this.data.array[ index + 1 ] = y;
  15207. return this;
  15208. },
  15209. setXYZ: function ( index, x, y, z ) {
  15210. index = index * this.data.stride + this.offset;
  15211. this.data.array[ index + 0 ] = x;
  15212. this.data.array[ index + 1 ] = y;
  15213. this.data.array[ index + 2 ] = z;
  15214. return this;
  15215. },
  15216. setXYZW: function ( index, x, y, z, w ) {
  15217. index = index * this.data.stride + this.offset;
  15218. this.data.array[ index + 0 ] = x;
  15219. this.data.array[ index + 1 ] = y;
  15220. this.data.array[ index + 2 ] = z;
  15221. this.data.array[ index + 3 ] = w;
  15222. return this;
  15223. }
  15224. } );
  15225. /**
  15226. * @author alteredq / http://alteredqualia.com/
  15227. *
  15228. * parameters = {
  15229. * color: <hex>,
  15230. * map: new THREE.Texture( <Image> ),
  15231. * rotation: <float>,
  15232. * sizeAttenuation: <bool>
  15233. * }
  15234. */
  15235. function SpriteMaterial( parameters ) {
  15236. Material.call( this );
  15237. this.type = 'SpriteMaterial';
  15238. this.color = new Color( 0xffffff );
  15239. this.map = null;
  15240. this.rotation = 0;
  15241. this.sizeAttenuation = true;
  15242. this.lights = false;
  15243. this.transparent = true;
  15244. this.setValues( parameters );
  15245. }
  15246. SpriteMaterial.prototype = Object.create( Material.prototype );
  15247. SpriteMaterial.prototype.constructor = SpriteMaterial;
  15248. SpriteMaterial.prototype.isSpriteMaterial = true;
  15249. SpriteMaterial.prototype.copy = function ( source ) {
  15250. Material.prototype.copy.call( this, source );
  15251. this.color.copy( source.color );
  15252. this.map = source.map;
  15253. this.rotation = source.rotation;
  15254. this.sizeAttenuation = source.sizeAttenuation;
  15255. return this;
  15256. };
  15257. /**
  15258. * @author mikael emtinger / http://gomo.se/
  15259. * @author alteredq / http://alteredqualia.com/
  15260. */
  15261. var geometry;
  15262. function Sprite( material ) {
  15263. Object3D.call( this );
  15264. this.type = 'Sprite';
  15265. if ( geometry === undefined ) {
  15266. geometry = new BufferGeometry();
  15267. var float32Array = new Float32Array( [
  15268. - 0.5, - 0.5, 0, 0, 0,
  15269. 0.5, - 0.5, 0, 1, 0,
  15270. 0.5, 0.5, 0, 1, 1,
  15271. - 0.5, 0.5, 0, 0, 1
  15272. ] );
  15273. var interleavedBuffer = new InterleavedBuffer( float32Array, 5 );
  15274. geometry.setIndex( [ 0, 1, 2, 0, 2, 3 ] );
  15275. geometry.addAttribute( 'position', new InterleavedBufferAttribute( interleavedBuffer, 3, 0, false ) );
  15276. geometry.addAttribute( 'uv', new InterleavedBufferAttribute( interleavedBuffer, 2, 3, false ) );
  15277. }
  15278. this.geometry = geometry;
  15279. this.material = ( material !== undefined ) ? material : new SpriteMaterial();
  15280. this.center = new Vector2( 0.5, 0.5 );
  15281. }
  15282. Sprite.prototype = Object.assign( Object.create( Object3D.prototype ), {
  15283. constructor: Sprite,
  15284. isSprite: true,
  15285. raycast: ( function () {
  15286. var intersectPoint = new Vector3();
  15287. var worldScale = new Vector3();
  15288. var mvPosition = new Vector3();
  15289. var alignedPosition = new Vector2();
  15290. var rotatedPosition = new Vector2();
  15291. var viewWorldMatrix = new Matrix4();
  15292. var vA = new Vector3();
  15293. var vB = new Vector3();
  15294. var vC = new Vector3();
  15295. var uvA = new Vector2();
  15296. var uvB = new Vector2();
  15297. var uvC = new Vector2();
  15298. function transformVertex( vertexPosition, mvPosition, center, scale, sin, cos ) {
  15299. // compute position in camera space
  15300. alignedPosition.subVectors( vertexPosition, center ).addScalar( 0.5 ).multiply( scale );
  15301. // to check if rotation is not zero
  15302. if ( sin !== undefined ) {
  15303. rotatedPosition.x = ( cos * alignedPosition.x ) - ( sin * alignedPosition.y );
  15304. rotatedPosition.y = ( sin * alignedPosition.x ) + ( cos * alignedPosition.y );
  15305. } else {
  15306. rotatedPosition.copy( alignedPosition );
  15307. }
  15308. vertexPosition.copy( mvPosition );
  15309. vertexPosition.x += rotatedPosition.x;
  15310. vertexPosition.y += rotatedPosition.y;
  15311. // transform to world space
  15312. vertexPosition.applyMatrix4( viewWorldMatrix );
  15313. }
  15314. return function raycast( raycaster, intersects ) {
  15315. worldScale.setFromMatrixScale( this.matrixWorld );
  15316. viewWorldMatrix.getInverse( this.modelViewMatrix ).premultiply( this.matrixWorld );
  15317. mvPosition.setFromMatrixPosition( this.modelViewMatrix );
  15318. var rotation = this.material.rotation;
  15319. var sin, cos;
  15320. if ( rotation !== 0 ) {
  15321. cos = Math.cos( rotation );
  15322. sin = Math.sin( rotation );
  15323. }
  15324. var center = this.center;
  15325. transformVertex( vA.set( - 0.5, - 0.5, 0 ), mvPosition, center, worldScale, sin, cos );
  15326. transformVertex( vB.set( 0.5, - 0.5, 0 ), mvPosition, center, worldScale, sin, cos );
  15327. transformVertex( vC.set( 0.5, 0.5, 0 ), mvPosition, center, worldScale, sin, cos );
  15328. uvA.set( 0, 0 );
  15329. uvB.set( 1, 0 );
  15330. uvC.set( 1, 1 );
  15331. // check first triangle
  15332. var intersect = raycaster.ray.intersectTriangle( vA, vB, vC, false, intersectPoint );
  15333. if ( intersect === null ) {
  15334. // check second triangle
  15335. transformVertex( vB.set( - 0.5, 0.5, 0 ), mvPosition, center, worldScale, sin, cos );
  15336. uvB.set( 0, 1 );
  15337. intersect = raycaster.ray.intersectTriangle( vA, vC, vB, false, intersectPoint );
  15338. if ( intersect === null ) {
  15339. return;
  15340. }
  15341. }
  15342. var distance = raycaster.ray.origin.distanceTo( intersectPoint );
  15343. if ( distance < raycaster.near || distance > raycaster.far ) return;
  15344. intersects.push( {
  15345. distance: distance,
  15346. point: intersectPoint.clone(),
  15347. uv: Triangle.getUV( intersectPoint, vA, vB, vC, uvA, uvB, uvC, new Vector2() ),
  15348. face: null,
  15349. object: this
  15350. } );
  15351. };
  15352. }() ),
  15353. clone: function () {
  15354. return new this.constructor( this.material ).copy( this );
  15355. },
  15356. copy: function ( source ) {
  15357. Object3D.prototype.copy.call( this, source );
  15358. if ( source.center !== undefined ) this.center.copy( source.center );
  15359. return this;
  15360. }
  15361. } );
  15362. /**
  15363. * @author mikael emtinger / http://gomo.se/
  15364. * @author alteredq / http://alteredqualia.com/
  15365. * @author mrdoob / http://mrdoob.com/
  15366. */
  15367. function LOD() {
  15368. Object3D.call( this );
  15369. this.type = 'LOD';
  15370. Object.defineProperties( this, {
  15371. levels: {
  15372. enumerable: true,
  15373. value: []
  15374. }
  15375. } );
  15376. }
  15377. LOD.prototype = Object.assign( Object.create( Object3D.prototype ), {
  15378. constructor: LOD,
  15379. isLOD: true,
  15380. copy: function ( source ) {
  15381. Object3D.prototype.copy.call( this, source, false );
  15382. var levels = source.levels;
  15383. for ( var i = 0, l = levels.length; i < l; i ++ ) {
  15384. var level = levels[ i ];
  15385. this.addLevel( level.object.clone(), level.distance );
  15386. }
  15387. return this;
  15388. },
  15389. addLevel: function ( object, distance ) {
  15390. if ( distance === undefined ) distance = 0;
  15391. distance = Math.abs( distance );
  15392. var levels = this.levels;
  15393. for ( var l = 0; l < levels.length; l ++ ) {
  15394. if ( distance < levels[ l ].distance ) {
  15395. break;
  15396. }
  15397. }
  15398. levels.splice( l, 0, { distance: distance, object: object } );
  15399. this.add( object );
  15400. return this;
  15401. },
  15402. getObjectForDistance: function ( distance ) {
  15403. var levels = this.levels;
  15404. for ( var i = 1, l = levels.length; i < l; i ++ ) {
  15405. if ( distance < levels[ i ].distance ) {
  15406. break;
  15407. }
  15408. }
  15409. return levels[ i - 1 ].object;
  15410. },
  15411. raycast: ( function () {
  15412. var matrixPosition = new Vector3();
  15413. return function raycast( raycaster, intersects ) {
  15414. matrixPosition.setFromMatrixPosition( this.matrixWorld );
  15415. var distance = raycaster.ray.origin.distanceTo( matrixPosition );
  15416. this.getObjectForDistance( distance ).raycast( raycaster, intersects );
  15417. };
  15418. }() ),
  15419. update: function () {
  15420. var v1 = new Vector3();
  15421. var v2 = new Vector3();
  15422. return function update( camera ) {
  15423. var levels = this.levels;
  15424. if ( levels.length > 1 ) {
  15425. v1.setFromMatrixPosition( camera.matrixWorld );
  15426. v2.setFromMatrixPosition( this.matrixWorld );
  15427. var distance = v1.distanceTo( v2 );
  15428. levels[ 0 ].object.visible = true;
  15429. for ( var i = 1, l = levels.length; i < l; i ++ ) {
  15430. if ( distance >= levels[ i ].distance ) {
  15431. levels[ i - 1 ].object.visible = false;
  15432. levels[ i ].object.visible = true;
  15433. } else {
  15434. break;
  15435. }
  15436. }
  15437. for ( ; i < l; i ++ ) {
  15438. levels[ i ].object.visible = false;
  15439. }
  15440. }
  15441. };
  15442. }(),
  15443. toJSON: function ( meta ) {
  15444. var data = Object3D.prototype.toJSON.call( this, meta );
  15445. data.object.levels = [];
  15446. var levels = this.levels;
  15447. for ( var i = 0, l = levels.length; i < l; i ++ ) {
  15448. var level = levels[ i ];
  15449. data.object.levels.push( {
  15450. object: level.object.uuid,
  15451. distance: level.distance
  15452. } );
  15453. }
  15454. return data;
  15455. }
  15456. } );
  15457. /**
  15458. * @author mikael emtinger / http://gomo.se/
  15459. * @author alteredq / http://alteredqualia.com/
  15460. * @author ikerr / http://verold.com
  15461. */
  15462. function SkinnedMesh( geometry, material ) {
  15463. if ( geometry && geometry.isGeometry ) {
  15464. console.error( 'THREE.SkinnedMesh no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.' );
  15465. }
  15466. Mesh.call( this, geometry, material );
  15467. this.type = 'SkinnedMesh';
  15468. this.bindMode = 'attached';
  15469. this.bindMatrix = new Matrix4();
  15470. this.bindMatrixInverse = new Matrix4();
  15471. }
  15472. SkinnedMesh.prototype = Object.assign( Object.create( Mesh.prototype ), {
  15473. constructor: SkinnedMesh,
  15474. isSkinnedMesh: true,
  15475. bind: function ( skeleton, bindMatrix ) {
  15476. this.skeleton = skeleton;
  15477. if ( bindMatrix === undefined ) {
  15478. this.updateMatrixWorld( true );
  15479. this.skeleton.calculateInverses();
  15480. bindMatrix = this.matrixWorld;
  15481. }
  15482. this.bindMatrix.copy( bindMatrix );
  15483. this.bindMatrixInverse.getInverse( bindMatrix );
  15484. },
  15485. pose: function () {
  15486. this.skeleton.pose();
  15487. },
  15488. normalizeSkinWeights: function () {
  15489. var vector = new Vector4();
  15490. var skinWeight = this.geometry.attributes.skinWeight;
  15491. for ( var i = 0, l = skinWeight.count; i < l; i ++ ) {
  15492. vector.x = skinWeight.getX( i );
  15493. vector.y = skinWeight.getY( i );
  15494. vector.z = skinWeight.getZ( i );
  15495. vector.w = skinWeight.getW( i );
  15496. var scale = 1.0 / vector.manhattanLength();
  15497. if ( scale !== Infinity ) {
  15498. vector.multiplyScalar( scale );
  15499. } else {
  15500. vector.set( 1, 0, 0, 0 ); // do something reasonable
  15501. }
  15502. skinWeight.setXYZW( i, vector.x, vector.y, vector.z, vector.w );
  15503. }
  15504. },
  15505. updateMatrixWorld: function ( force ) {
  15506. Mesh.prototype.updateMatrixWorld.call( this, force );
  15507. if ( this.bindMode === 'attached' ) {
  15508. this.bindMatrixInverse.getInverse( this.matrixWorld );
  15509. } else if ( this.bindMode === 'detached' ) {
  15510. this.bindMatrixInverse.getInverse( this.bindMatrix );
  15511. } else {
  15512. console.warn( 'THREE.SkinnedMesh: Unrecognized bindMode: ' + this.bindMode );
  15513. }
  15514. },
  15515. clone: function () {
  15516. return new this.constructor( this.geometry, this.material ).copy( this );
  15517. }
  15518. } );
  15519. /**
  15520. * @author mikael emtinger / http://gomo.se/
  15521. * @author alteredq / http://alteredqualia.com/
  15522. * @author michael guerrero / http://realitymeltdown.com
  15523. * @author ikerr / http://verold.com
  15524. */
  15525. function Skeleton( bones, boneInverses ) {
  15526. // copy the bone array
  15527. bones = bones || [];
  15528. this.bones = bones.slice( 0 );
  15529. this.boneMatrices = new Float32Array( this.bones.length * 16 );
  15530. // use the supplied bone inverses or calculate the inverses
  15531. if ( boneInverses === undefined ) {
  15532. this.calculateInverses();
  15533. } else {
  15534. if ( this.bones.length === boneInverses.length ) {
  15535. this.boneInverses = boneInverses.slice( 0 );
  15536. } else {
  15537. console.warn( 'THREE.Skeleton boneInverses is the wrong length.' );
  15538. this.boneInverses = [];
  15539. for ( var i = 0, il = this.bones.length; i < il; i ++ ) {
  15540. this.boneInverses.push( new Matrix4() );
  15541. }
  15542. }
  15543. }
  15544. }
  15545. Object.assign( Skeleton.prototype, {
  15546. calculateInverses: function () {
  15547. this.boneInverses = [];
  15548. for ( var i = 0, il = this.bones.length; i < il; i ++ ) {
  15549. var inverse = new Matrix4();
  15550. if ( this.bones[ i ] ) {
  15551. inverse.getInverse( this.bones[ i ].matrixWorld );
  15552. }
  15553. this.boneInverses.push( inverse );
  15554. }
  15555. },
  15556. pose: function () {
  15557. var bone, i, il;
  15558. // recover the bind-time world matrices
  15559. for ( i = 0, il = this.bones.length; i < il; i ++ ) {
  15560. bone = this.bones[ i ];
  15561. if ( bone ) {
  15562. bone.matrixWorld.getInverse( this.boneInverses[ i ] );
  15563. }
  15564. }
  15565. // compute the local matrices, positions, rotations and scales
  15566. for ( i = 0, il = this.bones.length; i < il; i ++ ) {
  15567. bone = this.bones[ i ];
  15568. if ( bone ) {
  15569. if ( bone.parent && bone.parent.isBone ) {
  15570. bone.matrix.getInverse( bone.parent.matrixWorld );
  15571. bone.matrix.multiply( bone.matrixWorld );
  15572. } else {
  15573. bone.matrix.copy( bone.matrixWorld );
  15574. }
  15575. bone.matrix.decompose( bone.position, bone.quaternion, bone.scale );
  15576. }
  15577. }
  15578. },
  15579. update: ( function () {
  15580. var offsetMatrix = new Matrix4();
  15581. var identityMatrix = new Matrix4();
  15582. return function update() {
  15583. var bones = this.bones;
  15584. var boneInverses = this.boneInverses;
  15585. var boneMatrices = this.boneMatrices;
  15586. var boneTexture = this.boneTexture;
  15587. // flatten bone matrices to array
  15588. for ( var i = 0, il = bones.length; i < il; i ++ ) {
  15589. // compute the offset between the current and the original transform
  15590. var matrix = bones[ i ] ? bones[ i ].matrixWorld : identityMatrix;
  15591. offsetMatrix.multiplyMatrices( matrix, boneInverses[ i ] );
  15592. offsetMatrix.toArray( boneMatrices, i * 16 );
  15593. }
  15594. if ( boneTexture !== undefined ) {
  15595. boneTexture.needsUpdate = true;
  15596. }
  15597. };
  15598. } )(),
  15599. clone: function () {
  15600. return new Skeleton( this.bones, this.boneInverses );
  15601. },
  15602. getBoneByName: function ( name ) {
  15603. for ( var i = 0, il = this.bones.length; i < il; i ++ ) {
  15604. var bone = this.bones[ i ];
  15605. if ( bone.name === name ) {
  15606. return bone;
  15607. }
  15608. }
  15609. return undefined;
  15610. }
  15611. } );
  15612. /**
  15613. * @author mikael emtinger / http://gomo.se/
  15614. * @author alteredq / http://alteredqualia.com/
  15615. * @author ikerr / http://verold.com
  15616. */
  15617. function Bone() {
  15618. Object3D.call( this );
  15619. this.type = 'Bone';
  15620. }
  15621. Bone.prototype = Object.assign( Object.create( Object3D.prototype ), {
  15622. constructor: Bone,
  15623. isBone: true
  15624. } );
  15625. /**
  15626. * @author mrdoob / http://mrdoob.com/
  15627. * @author alteredq / http://alteredqualia.com/
  15628. *
  15629. * parameters = {
  15630. * color: <hex>,
  15631. * opacity: <float>,
  15632. *
  15633. * linewidth: <float>,
  15634. * linecap: "round",
  15635. * linejoin: "round"
  15636. * }
  15637. */
  15638. function LineBasicMaterial( parameters ) {
  15639. Material.call( this );
  15640. this.type = 'LineBasicMaterial';
  15641. this.color = new Color( 0xffffff );
  15642. this.linewidth = 1;
  15643. this.linecap = 'round';
  15644. this.linejoin = 'round';
  15645. this.lights = false;
  15646. this.setValues( parameters );
  15647. }
  15648. LineBasicMaterial.prototype = Object.create( Material.prototype );
  15649. LineBasicMaterial.prototype.constructor = LineBasicMaterial;
  15650. LineBasicMaterial.prototype.isLineBasicMaterial = true;
  15651. LineBasicMaterial.prototype.copy = function ( source ) {
  15652. Material.prototype.copy.call( this, source );
  15653. this.color.copy( source.color );
  15654. this.linewidth = source.linewidth;
  15655. this.linecap = source.linecap;
  15656. this.linejoin = source.linejoin;
  15657. return this;
  15658. };
  15659. /**
  15660. * @author mrdoob / http://mrdoob.com/
  15661. */
  15662. function Line( geometry, material, mode ) {
  15663. if ( mode === 1 ) {
  15664. console.error( 'THREE.Line: parameter THREE.LinePieces no longer supported. Use THREE.LineSegments instead.' );
  15665. }
  15666. Object3D.call( this );
  15667. this.type = 'Line';
  15668. this.geometry = geometry !== undefined ? geometry : new BufferGeometry();
  15669. this.material = material !== undefined ? material : new LineBasicMaterial( { color: Math.random() * 0xffffff } );
  15670. }
  15671. Line.prototype = Object.assign( Object.create( Object3D.prototype ), {
  15672. constructor: Line,
  15673. isLine: true,
  15674. computeLineDistances: ( function () {
  15675. var start = new Vector3();
  15676. var end = new Vector3();
  15677. return function computeLineDistances() {
  15678. var geometry = this.geometry;
  15679. if ( geometry.isBufferGeometry ) {
  15680. // we assume non-indexed geometry
  15681. if ( geometry.index === null ) {
  15682. var positionAttribute = geometry.attributes.position;
  15683. var lineDistances = [ 0 ];
  15684. for ( var i = 1, l = positionAttribute.count; i < l; i ++ ) {
  15685. start.fromBufferAttribute( positionAttribute, i - 1 );
  15686. end.fromBufferAttribute( positionAttribute, i );
  15687. lineDistances[ i ] = lineDistances[ i - 1 ];
  15688. lineDistances[ i ] += start.distanceTo( end );
  15689. }
  15690. geometry.addAttribute( 'lineDistance', new Float32BufferAttribute( lineDistances, 1 ) );
  15691. } else {
  15692. console.warn( 'THREE.Line.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.' );
  15693. }
  15694. } else if ( geometry.isGeometry ) {
  15695. var vertices = geometry.vertices;
  15696. var lineDistances = geometry.lineDistances;
  15697. lineDistances[ 0 ] = 0;
  15698. for ( var i = 1, l = vertices.length; i < l; i ++ ) {
  15699. lineDistances[ i ] = lineDistances[ i - 1 ];
  15700. lineDistances[ i ] += vertices[ i - 1 ].distanceTo( vertices[ i ] );
  15701. }
  15702. }
  15703. return this;
  15704. };
  15705. }() ),
  15706. raycast: ( function () {
  15707. var inverseMatrix = new Matrix4();
  15708. var ray = new Ray();
  15709. var sphere = new Sphere();
  15710. return function raycast( raycaster, intersects ) {
  15711. var precision = raycaster.linePrecision;
  15712. var geometry = this.geometry;
  15713. var matrixWorld = this.matrixWorld;
  15714. // Checking boundingSphere distance to ray
  15715. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  15716. sphere.copy( geometry.boundingSphere );
  15717. sphere.applyMatrix4( matrixWorld );
  15718. sphere.radius += precision;
  15719. if ( raycaster.ray.intersectsSphere( sphere ) === false ) return;
  15720. //
  15721. inverseMatrix.getInverse( matrixWorld );
  15722. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  15723. var localPrecision = precision / ( ( this.scale.x + this.scale.y + this.scale.z ) / 3 );
  15724. var localPrecisionSq = localPrecision * localPrecision;
  15725. var vStart = new Vector3();
  15726. var vEnd = new Vector3();
  15727. var interSegment = new Vector3();
  15728. var interRay = new Vector3();
  15729. var step = ( this && this.isLineSegments ) ? 2 : 1;
  15730. if ( geometry.isBufferGeometry ) {
  15731. var index = geometry.index;
  15732. var attributes = geometry.attributes;
  15733. var positions = attributes.position.array;
  15734. if ( index !== null ) {
  15735. var indices = index.array;
  15736. for ( var i = 0, l = indices.length - 1; i < l; i += step ) {
  15737. var a = indices[ i ];
  15738. var b = indices[ i + 1 ];
  15739. vStart.fromArray( positions, a * 3 );
  15740. vEnd.fromArray( positions, b * 3 );
  15741. var distSq = ray.distanceSqToSegment( vStart, vEnd, interRay, interSegment );
  15742. if ( distSq > localPrecisionSq ) continue;
  15743. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  15744. var distance = raycaster.ray.origin.distanceTo( interRay );
  15745. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  15746. intersects.push( {
  15747. distance: distance,
  15748. // What do we want? intersection point on the ray or on the segment??
  15749. // point: raycaster.ray.at( distance ),
  15750. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  15751. index: i,
  15752. face: null,
  15753. faceIndex: null,
  15754. object: this
  15755. } );
  15756. }
  15757. } else {
  15758. for ( var i = 0, l = positions.length / 3 - 1; i < l; i += step ) {
  15759. vStart.fromArray( positions, 3 * i );
  15760. vEnd.fromArray( positions, 3 * i + 3 );
  15761. var distSq = ray.distanceSqToSegment( vStart, vEnd, interRay, interSegment );
  15762. if ( distSq > localPrecisionSq ) continue;
  15763. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  15764. var distance = raycaster.ray.origin.distanceTo( interRay );
  15765. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  15766. intersects.push( {
  15767. distance: distance,
  15768. // What do we want? intersection point on the ray or on the segment??
  15769. // point: raycaster.ray.at( distance ),
  15770. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  15771. index: i,
  15772. face: null,
  15773. faceIndex: null,
  15774. object: this
  15775. } );
  15776. }
  15777. }
  15778. } else if ( geometry.isGeometry ) {
  15779. var vertices = geometry.vertices;
  15780. var nbVertices = vertices.length;
  15781. for ( var i = 0; i < nbVertices - 1; i += step ) {
  15782. var distSq = ray.distanceSqToSegment( vertices[ i ], vertices[ i + 1 ], interRay, interSegment );
  15783. if ( distSq > localPrecisionSq ) continue;
  15784. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  15785. var distance = raycaster.ray.origin.distanceTo( interRay );
  15786. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  15787. intersects.push( {
  15788. distance: distance,
  15789. // What do we want? intersection point on the ray or on the segment??
  15790. // point: raycaster.ray.at( distance ),
  15791. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  15792. index: i,
  15793. face: null,
  15794. faceIndex: null,
  15795. object: this
  15796. } );
  15797. }
  15798. }
  15799. };
  15800. }() ),
  15801. clone: function () {
  15802. return new this.constructor( this.geometry, this.material ).copy( this );
  15803. }
  15804. } );
  15805. /**
  15806. * @author mrdoob / http://mrdoob.com/
  15807. */
  15808. function LineSegments( geometry, material ) {
  15809. Line.call( this, geometry, material );
  15810. this.type = 'LineSegments';
  15811. }
  15812. LineSegments.prototype = Object.assign( Object.create( Line.prototype ), {
  15813. constructor: LineSegments,
  15814. isLineSegments: true,
  15815. computeLineDistances: ( function () {
  15816. var start = new Vector3();
  15817. var end = new Vector3();
  15818. return function computeLineDistances() {
  15819. var geometry = this.geometry;
  15820. if ( geometry.isBufferGeometry ) {
  15821. // we assume non-indexed geometry
  15822. if ( geometry.index === null ) {
  15823. var positionAttribute = geometry.attributes.position;
  15824. var lineDistances = [];
  15825. for ( var i = 0, l = positionAttribute.count; i < l; i += 2 ) {
  15826. start.fromBufferAttribute( positionAttribute, i );
  15827. end.fromBufferAttribute( positionAttribute, i + 1 );
  15828. lineDistances[ i ] = ( i === 0 ) ? 0 : lineDistances[ i - 1 ];
  15829. lineDistances[ i + 1 ] = lineDistances[ i ] + start.distanceTo( end );
  15830. }
  15831. geometry.addAttribute( 'lineDistance', new Float32BufferAttribute( lineDistances, 1 ) );
  15832. } else {
  15833. console.warn( 'THREE.LineSegments.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.' );
  15834. }
  15835. } else if ( geometry.isGeometry ) {
  15836. var vertices = geometry.vertices;
  15837. var lineDistances = geometry.lineDistances;
  15838. for ( var i = 0, l = vertices.length; i < l; i += 2 ) {
  15839. start.copy( vertices[ i ] );
  15840. end.copy( vertices[ i + 1 ] );
  15841. lineDistances[ i ] = ( i === 0 ) ? 0 : lineDistances[ i - 1 ];
  15842. lineDistances[ i + 1 ] = lineDistances[ i ] + start.distanceTo( end );
  15843. }
  15844. }
  15845. return this;
  15846. };
  15847. }() )
  15848. } );
  15849. /**
  15850. * @author mgreter / http://github.com/mgreter
  15851. */
  15852. function LineLoop( geometry, material ) {
  15853. Line.call( this, geometry, material );
  15854. this.type = 'LineLoop';
  15855. }
  15856. LineLoop.prototype = Object.assign( Object.create( Line.prototype ), {
  15857. constructor: LineLoop,
  15858. isLineLoop: true,
  15859. } );
  15860. /**
  15861. * @author mrdoob / http://mrdoob.com/
  15862. * @author alteredq / http://alteredqualia.com/
  15863. *
  15864. * parameters = {
  15865. * color: <hex>,
  15866. * opacity: <float>,
  15867. * map: new THREE.Texture( <Image> ),
  15868. *
  15869. * size: <float>,
  15870. * sizeAttenuation: <bool>
  15871. *
  15872. * morphTargets: <bool>
  15873. * }
  15874. */
  15875. function PointsMaterial( parameters ) {
  15876. Material.call( this );
  15877. this.type = 'PointsMaterial';
  15878. this.color = new Color( 0xffffff );
  15879. this.map = null;
  15880. this.size = 1;
  15881. this.sizeAttenuation = true;
  15882. this.morphTargets = false;
  15883. this.lights = false;
  15884. this.setValues( parameters );
  15885. }
  15886. PointsMaterial.prototype = Object.create( Material.prototype );
  15887. PointsMaterial.prototype.constructor = PointsMaterial;
  15888. PointsMaterial.prototype.isPointsMaterial = true;
  15889. PointsMaterial.prototype.copy = function ( source ) {
  15890. Material.prototype.copy.call( this, source );
  15891. this.color.copy( source.color );
  15892. this.map = source.map;
  15893. this.size = source.size;
  15894. this.sizeAttenuation = source.sizeAttenuation;
  15895. this.morphTargets = source.morphTargets;
  15896. return this;
  15897. };
  15898. /**
  15899. * @author alteredq / http://alteredqualia.com/
  15900. */
  15901. function Points( geometry, material ) {
  15902. Object3D.call( this );
  15903. this.type = 'Points';
  15904. this.geometry = geometry !== undefined ? geometry : new BufferGeometry();
  15905. this.material = material !== undefined ? material : new PointsMaterial( { color: Math.random() * 0xffffff } );
  15906. }
  15907. Points.prototype = Object.assign( Object.create( Object3D.prototype ), {
  15908. constructor: Points,
  15909. isPoints: true,
  15910. raycast: ( function () {
  15911. var inverseMatrix = new Matrix4();
  15912. var ray = new Ray();
  15913. var sphere = new Sphere();
  15914. return function raycast( raycaster, intersects ) {
  15915. var object = this;
  15916. var geometry = this.geometry;
  15917. var matrixWorld = this.matrixWorld;
  15918. var threshold = raycaster.params.Points.threshold;
  15919. // Checking boundingSphere distance to ray
  15920. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  15921. sphere.copy( geometry.boundingSphere );
  15922. sphere.applyMatrix4( matrixWorld );
  15923. sphere.radius += threshold;
  15924. if ( raycaster.ray.intersectsSphere( sphere ) === false ) return;
  15925. //
  15926. inverseMatrix.getInverse( matrixWorld );
  15927. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  15928. var localThreshold = threshold / ( ( this.scale.x + this.scale.y + this.scale.z ) / 3 );
  15929. var localThresholdSq = localThreshold * localThreshold;
  15930. var position = new Vector3();
  15931. var intersectPoint = new Vector3();
  15932. function testPoint( point, index ) {
  15933. var rayPointDistanceSq = ray.distanceSqToPoint( point );
  15934. if ( rayPointDistanceSq < localThresholdSq ) {
  15935. ray.closestPointToPoint( point, intersectPoint );
  15936. intersectPoint.applyMatrix4( matrixWorld );
  15937. var distance = raycaster.ray.origin.distanceTo( intersectPoint );
  15938. if ( distance < raycaster.near || distance > raycaster.far ) return;
  15939. intersects.push( {
  15940. distance: distance,
  15941. distanceToRay: Math.sqrt( rayPointDistanceSq ),
  15942. point: intersectPoint.clone(),
  15943. index: index,
  15944. face: null,
  15945. object: object
  15946. } );
  15947. }
  15948. }
  15949. if ( geometry.isBufferGeometry ) {
  15950. var index = geometry.index;
  15951. var attributes = geometry.attributes;
  15952. var positions = attributes.position.array;
  15953. if ( index !== null ) {
  15954. var indices = index.array;
  15955. for ( var i = 0, il = indices.length; i < il; i ++ ) {
  15956. var a = indices[ i ];
  15957. position.fromArray( positions, a * 3 );
  15958. testPoint( position, a );
  15959. }
  15960. } else {
  15961. for ( var i = 0, l = positions.length / 3; i < l; i ++ ) {
  15962. position.fromArray( positions, i * 3 );
  15963. testPoint( position, i );
  15964. }
  15965. }
  15966. } else {
  15967. var vertices = geometry.vertices;
  15968. for ( var i = 0, l = vertices.length; i < l; i ++ ) {
  15969. testPoint( vertices[ i ], i );
  15970. }
  15971. }
  15972. };
  15973. }() ),
  15974. clone: function () {
  15975. return new this.constructor( this.geometry, this.material ).copy( this );
  15976. }
  15977. } );
  15978. /**
  15979. * @author mrdoob / http://mrdoob.com/
  15980. */
  15981. function VideoTexture( video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  15982. Texture.call( this, video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  15983. this.format = format !== undefined ? format : RGBFormat;
  15984. this.minFilter = minFilter !== undefined ? minFilter : LinearFilter;
  15985. this.magFilter = magFilter !== undefined ? magFilter : LinearFilter;
  15986. this.generateMipmaps = false;
  15987. }
  15988. VideoTexture.prototype = Object.assign( Object.create( Texture.prototype ), {
  15989. constructor: VideoTexture,
  15990. isVideoTexture: true,
  15991. update: function () {
  15992. var video = this.image;
  15993. if ( video.readyState >= video.HAVE_CURRENT_DATA ) {
  15994. this.needsUpdate = true;
  15995. }
  15996. }
  15997. } );
  15998. /**
  15999. * @author alteredq / http://alteredqualia.com/
  16000. */
  16001. function CompressedTexture( mipmaps, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, encoding ) {
  16002. Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding );
  16003. this.image = { width: width, height: height };
  16004. this.mipmaps = mipmaps;
  16005. // no flipping for cube textures
  16006. // (also flipping doesn't work for compressed textures )
  16007. this.flipY = false;
  16008. // can't generate mipmaps for compressed textures
  16009. // mips must be embedded in DDS files
  16010. this.generateMipmaps = false;
  16011. }
  16012. CompressedTexture.prototype = Object.create( Texture.prototype );
  16013. CompressedTexture.prototype.constructor = CompressedTexture;
  16014. CompressedTexture.prototype.isCompressedTexture = true;
  16015. /**
  16016. * @author mrdoob / http://mrdoob.com/
  16017. */
  16018. function CanvasTexture( canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  16019. Texture.call( this, canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  16020. this.needsUpdate = true;
  16021. }
  16022. CanvasTexture.prototype = Object.create( Texture.prototype );
  16023. CanvasTexture.prototype.constructor = CanvasTexture;
  16024. CanvasTexture.prototype.isCanvasTexture = true;
  16025. /**
  16026. * @author Matt DesLauriers / @mattdesl
  16027. * @author atix / arthursilber.de
  16028. */
  16029. function DepthTexture( width, height, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, format ) {
  16030. format = format !== undefined ? format : DepthFormat;
  16031. if ( format !== DepthFormat && format !== DepthStencilFormat ) {
  16032. throw new Error( 'DepthTexture format must be either THREE.DepthFormat or THREE.DepthStencilFormat' );
  16033. }
  16034. if ( type === undefined && format === DepthFormat ) type = UnsignedShortType;
  16035. if ( type === undefined && format === DepthStencilFormat ) type = UnsignedInt248Type;
  16036. Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  16037. this.image = { width: width, height: height };
  16038. this.magFilter = magFilter !== undefined ? magFilter : NearestFilter;
  16039. this.minFilter = minFilter !== undefined ? minFilter : NearestFilter;
  16040. this.flipY = false;
  16041. this.generateMipmaps = false;
  16042. }
  16043. DepthTexture.prototype = Object.create( Texture.prototype );
  16044. DepthTexture.prototype.constructor = DepthTexture;
  16045. DepthTexture.prototype.isDepthTexture = true;
  16046. /**
  16047. * @author mrdoob / http://mrdoob.com/
  16048. * @author Mugen87 / https://github.com/Mugen87
  16049. */
  16050. function WireframeGeometry( geometry ) {
  16051. BufferGeometry.call( this );
  16052. this.type = 'WireframeGeometry';
  16053. // buffer
  16054. var vertices = [];
  16055. // helper variables
  16056. var i, j, l, o, ol;
  16057. var edge = [ 0, 0 ], edges = {}, e, edge1, edge2;
  16058. var key, keys = [ 'a', 'b', 'c' ];
  16059. var vertex;
  16060. // different logic for Geometry and BufferGeometry
  16061. if ( geometry && geometry.isGeometry ) {
  16062. // create a data structure that contains all edges without duplicates
  16063. var faces = geometry.faces;
  16064. for ( i = 0, l = faces.length; i < l; i ++ ) {
  16065. var face = faces[ i ];
  16066. for ( j = 0; j < 3; j ++ ) {
  16067. edge1 = face[ keys[ j ] ];
  16068. edge2 = face[ keys[ ( j + 1 ) % 3 ] ];
  16069. edge[ 0 ] = Math.min( edge1, edge2 ); // sorting prevents duplicates
  16070. edge[ 1 ] = Math.max( edge1, edge2 );
  16071. key = edge[ 0 ] + ',' + edge[ 1 ];
  16072. if ( edges[ key ] === undefined ) {
  16073. edges[ key ] = { index1: edge[ 0 ], index2: edge[ 1 ] };
  16074. }
  16075. }
  16076. }
  16077. // generate vertices
  16078. for ( key in edges ) {
  16079. e = edges[ key ];
  16080. vertex = geometry.vertices[ e.index1 ];
  16081. vertices.push( vertex.x, vertex.y, vertex.z );
  16082. vertex = geometry.vertices[ e.index2 ];
  16083. vertices.push( vertex.x, vertex.y, vertex.z );
  16084. }
  16085. } else if ( geometry && geometry.isBufferGeometry ) {
  16086. var position, indices, groups;
  16087. var group, start, count;
  16088. var index1, index2;
  16089. vertex = new Vector3();
  16090. if ( geometry.index !== null ) {
  16091. // indexed BufferGeometry
  16092. position = geometry.attributes.position;
  16093. indices = geometry.index;
  16094. groups = geometry.groups;
  16095. if ( groups.length === 0 ) {
  16096. groups = [ { start: 0, count: indices.count, materialIndex: 0 } ];
  16097. }
  16098. // create a data structure that contains all eges without duplicates
  16099. for ( o = 0, ol = groups.length; o < ol; ++ o ) {
  16100. group = groups[ o ];
  16101. start = group.start;
  16102. count = group.count;
  16103. for ( i = start, l = ( start + count ); i < l; i += 3 ) {
  16104. for ( j = 0; j < 3; j ++ ) {
  16105. edge1 = indices.getX( i + j );
  16106. edge2 = indices.getX( i + ( j + 1 ) % 3 );
  16107. edge[ 0 ] = Math.min( edge1, edge2 ); // sorting prevents duplicates
  16108. edge[ 1 ] = Math.max( edge1, edge2 );
  16109. key = edge[ 0 ] + ',' + edge[ 1 ];
  16110. if ( edges[ key ] === undefined ) {
  16111. edges[ key ] = { index1: edge[ 0 ], index2: edge[ 1 ] };
  16112. }
  16113. }
  16114. }
  16115. }
  16116. // generate vertices
  16117. for ( key in edges ) {
  16118. e = edges[ key ];
  16119. vertex.fromBufferAttribute( position, e.index1 );
  16120. vertices.push( vertex.x, vertex.y, vertex.z );
  16121. vertex.fromBufferAttribute( position, e.index2 );
  16122. vertices.push( vertex.x, vertex.y, vertex.z );
  16123. }
  16124. } else {
  16125. // non-indexed BufferGeometry
  16126. position = geometry.attributes.position;
  16127. for ( i = 0, l = ( position.count / 3 ); i < l; i ++ ) {
  16128. for ( j = 0; j < 3; j ++ ) {
  16129. // three edges per triangle, an edge is represented as (index1, index2)
  16130. // e.g. the first triangle has the following edges: (0,1),(1,2),(2,0)
  16131. index1 = 3 * i + j;
  16132. vertex.fromBufferAttribute( position, index1 );
  16133. vertices.push( vertex.x, vertex.y, vertex.z );
  16134. index2 = 3 * i + ( ( j + 1 ) % 3 );
  16135. vertex.fromBufferAttribute( position, index2 );
  16136. vertices.push( vertex.x, vertex.y, vertex.z );
  16137. }
  16138. }
  16139. }
  16140. }
  16141. // build geometry
  16142. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  16143. }
  16144. WireframeGeometry.prototype = Object.create( BufferGeometry.prototype );
  16145. WireframeGeometry.prototype.constructor = WireframeGeometry;
  16146. /**
  16147. * @author zz85 / https://github.com/zz85
  16148. * @author Mugen87 / https://github.com/Mugen87
  16149. *
  16150. * Parametric Surfaces Geometry
  16151. * based on the brilliant article by @prideout http://prideout.net/blog/?p=44
  16152. */
  16153. // ParametricGeometry
  16154. function ParametricGeometry( func, slices, stacks ) {
  16155. Geometry.call( this );
  16156. this.type = 'ParametricGeometry';
  16157. this.parameters = {
  16158. func: func,
  16159. slices: slices,
  16160. stacks: stacks
  16161. };
  16162. this.fromBufferGeometry( new ParametricBufferGeometry( func, slices, stacks ) );
  16163. this.mergeVertices();
  16164. }
  16165. ParametricGeometry.prototype = Object.create( Geometry.prototype );
  16166. ParametricGeometry.prototype.constructor = ParametricGeometry;
  16167. // ParametricBufferGeometry
  16168. function ParametricBufferGeometry( func, slices, stacks ) {
  16169. BufferGeometry.call( this );
  16170. this.type = 'ParametricBufferGeometry';
  16171. this.parameters = {
  16172. func: func,
  16173. slices: slices,
  16174. stacks: stacks
  16175. };
  16176. // buffers
  16177. var indices = [];
  16178. var vertices = [];
  16179. var normals = [];
  16180. var uvs = [];
  16181. var EPS = 0.00001;
  16182. var normal = new Vector3();
  16183. var p0 = new Vector3(), p1 = new Vector3();
  16184. var pu = new Vector3(), pv = new Vector3();
  16185. var i, j;
  16186. if ( func.length < 3 ) {
  16187. console.error( 'THREE.ParametricGeometry: Function must now modify a Vector3 as third parameter.' );
  16188. }
  16189. // generate vertices, normals and uvs
  16190. var sliceCount = slices + 1;
  16191. for ( i = 0; i <= stacks; i ++ ) {
  16192. var v = i / stacks;
  16193. for ( j = 0; j <= slices; j ++ ) {
  16194. var u = j / slices;
  16195. // vertex
  16196. func( u, v, p0 );
  16197. vertices.push( p0.x, p0.y, p0.z );
  16198. // normal
  16199. // approximate tangent vectors via finite differences
  16200. if ( u - EPS >= 0 ) {
  16201. func( u - EPS, v, p1 );
  16202. pu.subVectors( p0, p1 );
  16203. } else {
  16204. func( u + EPS, v, p1 );
  16205. pu.subVectors( p1, p0 );
  16206. }
  16207. if ( v - EPS >= 0 ) {
  16208. func( u, v - EPS, p1 );
  16209. pv.subVectors( p0, p1 );
  16210. } else {
  16211. func( u, v + EPS, p1 );
  16212. pv.subVectors( p1, p0 );
  16213. }
  16214. // cross product of tangent vectors returns surface normal
  16215. normal.crossVectors( pu, pv ).normalize();
  16216. normals.push( normal.x, normal.y, normal.z );
  16217. // uv
  16218. uvs.push( u, v );
  16219. }
  16220. }
  16221. // generate indices
  16222. for ( i = 0; i < stacks; i ++ ) {
  16223. for ( j = 0; j < slices; j ++ ) {
  16224. var a = i * sliceCount + j;
  16225. var b = i * sliceCount + j + 1;
  16226. var c = ( i + 1 ) * sliceCount + j + 1;
  16227. var d = ( i + 1 ) * sliceCount + j;
  16228. // faces one and two
  16229. indices.push( a, b, d );
  16230. indices.push( b, c, d );
  16231. }
  16232. }
  16233. // build geometry
  16234. this.setIndex( indices );
  16235. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  16236. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  16237. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  16238. }
  16239. ParametricBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  16240. ParametricBufferGeometry.prototype.constructor = ParametricBufferGeometry;
  16241. /**
  16242. * @author clockworkgeek / https://github.com/clockworkgeek
  16243. * @author timothypratley / https://github.com/timothypratley
  16244. * @author WestLangley / http://github.com/WestLangley
  16245. * @author Mugen87 / https://github.com/Mugen87
  16246. */
  16247. // PolyhedronGeometry
  16248. function PolyhedronGeometry( vertices, indices, radius, detail ) {
  16249. Geometry.call( this );
  16250. this.type = 'PolyhedronGeometry';
  16251. this.parameters = {
  16252. vertices: vertices,
  16253. indices: indices,
  16254. radius: radius,
  16255. detail: detail
  16256. };
  16257. this.fromBufferGeometry( new PolyhedronBufferGeometry( vertices, indices, radius, detail ) );
  16258. this.mergeVertices();
  16259. }
  16260. PolyhedronGeometry.prototype = Object.create( Geometry.prototype );
  16261. PolyhedronGeometry.prototype.constructor = PolyhedronGeometry;
  16262. // PolyhedronBufferGeometry
  16263. function PolyhedronBufferGeometry( vertices, indices, radius, detail ) {
  16264. BufferGeometry.call( this );
  16265. this.type = 'PolyhedronBufferGeometry';
  16266. this.parameters = {
  16267. vertices: vertices,
  16268. indices: indices,
  16269. radius: radius,
  16270. detail: detail
  16271. };
  16272. radius = radius || 1;
  16273. detail = detail || 0;
  16274. // default buffer data
  16275. var vertexBuffer = [];
  16276. var uvBuffer = [];
  16277. // the subdivision creates the vertex buffer data
  16278. subdivide( detail );
  16279. // all vertices should lie on a conceptual sphere with a given radius
  16280. appplyRadius( radius );
  16281. // finally, create the uv data
  16282. generateUVs();
  16283. // build non-indexed geometry
  16284. this.addAttribute( 'position', new Float32BufferAttribute( vertexBuffer, 3 ) );
  16285. this.addAttribute( 'normal', new Float32BufferAttribute( vertexBuffer.slice(), 3 ) );
  16286. this.addAttribute( 'uv', new Float32BufferAttribute( uvBuffer, 2 ) );
  16287. if ( detail === 0 ) {
  16288. this.computeVertexNormals(); // flat normals
  16289. } else {
  16290. this.normalizeNormals(); // smooth normals
  16291. }
  16292. // helper functions
  16293. function subdivide( detail ) {
  16294. var a = new Vector3();
  16295. var b = new Vector3();
  16296. var c = new Vector3();
  16297. // iterate over all faces and apply a subdivison with the given detail value
  16298. for ( var i = 0; i < indices.length; i += 3 ) {
  16299. // get the vertices of the face
  16300. getVertexByIndex( indices[ i + 0 ], a );
  16301. getVertexByIndex( indices[ i + 1 ], b );
  16302. getVertexByIndex( indices[ i + 2 ], c );
  16303. // perform subdivision
  16304. subdivideFace( a, b, c, detail );
  16305. }
  16306. }
  16307. function subdivideFace( a, b, c, detail ) {
  16308. var cols = Math.pow( 2, detail );
  16309. // we use this multidimensional array as a data structure for creating the subdivision
  16310. var v = [];
  16311. var i, j;
  16312. // construct all of the vertices for this subdivision
  16313. for ( i = 0; i <= cols; i ++ ) {
  16314. v[ i ] = [];
  16315. var aj = a.clone().lerp( c, i / cols );
  16316. var bj = b.clone().lerp( c, i / cols );
  16317. var rows = cols - i;
  16318. for ( j = 0; j <= rows; j ++ ) {
  16319. if ( j === 0 && i === cols ) {
  16320. v[ i ][ j ] = aj;
  16321. } else {
  16322. v[ i ][ j ] = aj.clone().lerp( bj, j / rows );
  16323. }
  16324. }
  16325. }
  16326. // construct all of the faces
  16327. for ( i = 0; i < cols; i ++ ) {
  16328. for ( j = 0; j < 2 * ( cols - i ) - 1; j ++ ) {
  16329. var k = Math.floor( j / 2 );
  16330. if ( j % 2 === 0 ) {
  16331. pushVertex( v[ i ][ k + 1 ] );
  16332. pushVertex( v[ i + 1 ][ k ] );
  16333. pushVertex( v[ i ][ k ] );
  16334. } else {
  16335. pushVertex( v[ i ][ k + 1 ] );
  16336. pushVertex( v[ i + 1 ][ k + 1 ] );
  16337. pushVertex( v[ i + 1 ][ k ] );
  16338. }
  16339. }
  16340. }
  16341. }
  16342. function appplyRadius( radius ) {
  16343. var vertex = new Vector3();
  16344. // iterate over the entire buffer and apply the radius to each vertex
  16345. for ( var i = 0; i < vertexBuffer.length; i += 3 ) {
  16346. vertex.x = vertexBuffer[ i + 0 ];
  16347. vertex.y = vertexBuffer[ i + 1 ];
  16348. vertex.z = vertexBuffer[ i + 2 ];
  16349. vertex.normalize().multiplyScalar( radius );
  16350. vertexBuffer[ i + 0 ] = vertex.x;
  16351. vertexBuffer[ i + 1 ] = vertex.y;
  16352. vertexBuffer[ i + 2 ] = vertex.z;
  16353. }
  16354. }
  16355. function generateUVs() {
  16356. var vertex = new Vector3();
  16357. for ( var i = 0; i < vertexBuffer.length; i += 3 ) {
  16358. vertex.x = vertexBuffer[ i + 0 ];
  16359. vertex.y = vertexBuffer[ i + 1 ];
  16360. vertex.z = vertexBuffer[ i + 2 ];
  16361. var u = azimuth( vertex ) / 2 / Math.PI + 0.5;
  16362. var v = inclination( vertex ) / Math.PI + 0.5;
  16363. uvBuffer.push( u, 1 - v );
  16364. }
  16365. correctUVs();
  16366. correctSeam();
  16367. }
  16368. function correctSeam() {
  16369. // handle case when face straddles the seam, see #3269
  16370. for ( var i = 0; i < uvBuffer.length; i += 6 ) {
  16371. // uv data of a single face
  16372. var x0 = uvBuffer[ i + 0 ];
  16373. var x1 = uvBuffer[ i + 2 ];
  16374. var x2 = uvBuffer[ i + 4 ];
  16375. var max = Math.max( x0, x1, x2 );
  16376. var min = Math.min( x0, x1, x2 );
  16377. // 0.9 is somewhat arbitrary
  16378. if ( max > 0.9 && min < 0.1 ) {
  16379. if ( x0 < 0.2 ) uvBuffer[ i + 0 ] += 1;
  16380. if ( x1 < 0.2 ) uvBuffer[ i + 2 ] += 1;
  16381. if ( x2 < 0.2 ) uvBuffer[ i + 4 ] += 1;
  16382. }
  16383. }
  16384. }
  16385. function pushVertex( vertex ) {
  16386. vertexBuffer.push( vertex.x, vertex.y, vertex.z );
  16387. }
  16388. function getVertexByIndex( index, vertex ) {
  16389. var stride = index * 3;
  16390. vertex.x = vertices[ stride + 0 ];
  16391. vertex.y = vertices[ stride + 1 ];
  16392. vertex.z = vertices[ stride + 2 ];
  16393. }
  16394. function correctUVs() {
  16395. var a = new Vector3();
  16396. var b = new Vector3();
  16397. var c = new Vector3();
  16398. var centroid = new Vector3();
  16399. var uvA = new Vector2();
  16400. var uvB = new Vector2();
  16401. var uvC = new Vector2();
  16402. for ( var i = 0, j = 0; i < vertexBuffer.length; i += 9, j += 6 ) {
  16403. a.set( vertexBuffer[ i + 0 ], vertexBuffer[ i + 1 ], vertexBuffer[ i + 2 ] );
  16404. b.set( vertexBuffer[ i + 3 ], vertexBuffer[ i + 4 ], vertexBuffer[ i + 5 ] );
  16405. c.set( vertexBuffer[ i + 6 ], vertexBuffer[ i + 7 ], vertexBuffer[ i + 8 ] );
  16406. uvA.set( uvBuffer[ j + 0 ], uvBuffer[ j + 1 ] );
  16407. uvB.set( uvBuffer[ j + 2 ], uvBuffer[ j + 3 ] );
  16408. uvC.set( uvBuffer[ j + 4 ], uvBuffer[ j + 5 ] );
  16409. centroid.copy( a ).add( b ).add( c ).divideScalar( 3 );
  16410. var azi = azimuth( centroid );
  16411. correctUV( uvA, j + 0, a, azi );
  16412. correctUV( uvB, j + 2, b, azi );
  16413. correctUV( uvC, j + 4, c, azi );
  16414. }
  16415. }
  16416. function correctUV( uv, stride, vector, azimuth ) {
  16417. if ( ( azimuth < 0 ) && ( uv.x === 1 ) ) {
  16418. uvBuffer[ stride ] = uv.x - 1;
  16419. }
  16420. if ( ( vector.x === 0 ) && ( vector.z === 0 ) ) {
  16421. uvBuffer[ stride ] = azimuth / 2 / Math.PI + 0.5;
  16422. }
  16423. }
  16424. // Angle around the Y axis, counter-clockwise when looking from above.
  16425. function azimuth( vector ) {
  16426. return Math.atan2( vector.z, - vector.x );
  16427. }
  16428. // Angle above the XZ plane.
  16429. function inclination( vector ) {
  16430. return Math.atan2( - vector.y, Math.sqrt( ( vector.x * vector.x ) + ( vector.z * vector.z ) ) );
  16431. }
  16432. }
  16433. PolyhedronBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  16434. PolyhedronBufferGeometry.prototype.constructor = PolyhedronBufferGeometry;
  16435. /**
  16436. * @author timothypratley / https://github.com/timothypratley
  16437. * @author Mugen87 / https://github.com/Mugen87
  16438. */
  16439. // TetrahedronGeometry
  16440. function TetrahedronGeometry( radius, detail ) {
  16441. Geometry.call( this );
  16442. this.type = 'TetrahedronGeometry';
  16443. this.parameters = {
  16444. radius: radius,
  16445. detail: detail
  16446. };
  16447. this.fromBufferGeometry( new TetrahedronBufferGeometry( radius, detail ) );
  16448. this.mergeVertices();
  16449. }
  16450. TetrahedronGeometry.prototype = Object.create( Geometry.prototype );
  16451. TetrahedronGeometry.prototype.constructor = TetrahedronGeometry;
  16452. // TetrahedronBufferGeometry
  16453. function TetrahedronBufferGeometry( radius, detail ) {
  16454. var vertices = [
  16455. 1, 1, 1, - 1, - 1, 1, - 1, 1, - 1, 1, - 1, - 1
  16456. ];
  16457. var indices = [
  16458. 2, 1, 0, 0, 3, 2, 1, 3, 0, 2, 3, 1
  16459. ];
  16460. PolyhedronBufferGeometry.call( this, vertices, indices, radius, detail );
  16461. this.type = 'TetrahedronBufferGeometry';
  16462. this.parameters = {
  16463. radius: radius,
  16464. detail: detail
  16465. };
  16466. }
  16467. TetrahedronBufferGeometry.prototype = Object.create( PolyhedronBufferGeometry.prototype );
  16468. TetrahedronBufferGeometry.prototype.constructor = TetrahedronBufferGeometry;
  16469. /**
  16470. * @author timothypratley / https://github.com/timothypratley
  16471. * @author Mugen87 / https://github.com/Mugen87
  16472. */
  16473. // OctahedronGeometry
  16474. function OctahedronGeometry( radius, detail ) {
  16475. Geometry.call( this );
  16476. this.type = 'OctahedronGeometry';
  16477. this.parameters = {
  16478. radius: radius,
  16479. detail: detail
  16480. };
  16481. this.fromBufferGeometry( new OctahedronBufferGeometry( radius, detail ) );
  16482. this.mergeVertices();
  16483. }
  16484. OctahedronGeometry.prototype = Object.create( Geometry.prototype );
  16485. OctahedronGeometry.prototype.constructor = OctahedronGeometry;
  16486. // OctahedronBufferGeometry
  16487. function OctahedronBufferGeometry( radius, detail ) {
  16488. var vertices = [
  16489. 1, 0, 0, - 1, 0, 0, 0, 1, 0,
  16490. 0, - 1, 0, 0, 0, 1, 0, 0, - 1
  16491. ];
  16492. var indices = [
  16493. 0, 2, 4, 0, 4, 3, 0, 3, 5,
  16494. 0, 5, 2, 1, 2, 5, 1, 5, 3,
  16495. 1, 3, 4, 1, 4, 2
  16496. ];
  16497. PolyhedronBufferGeometry.call( this, vertices, indices, radius, detail );
  16498. this.type = 'OctahedronBufferGeometry';
  16499. this.parameters = {
  16500. radius: radius,
  16501. detail: detail
  16502. };
  16503. }
  16504. OctahedronBufferGeometry.prototype = Object.create( PolyhedronBufferGeometry.prototype );
  16505. OctahedronBufferGeometry.prototype.constructor = OctahedronBufferGeometry;
  16506. /**
  16507. * @author timothypratley / https://github.com/timothypratley
  16508. * @author Mugen87 / https://github.com/Mugen87
  16509. */
  16510. // IcosahedronGeometry
  16511. function IcosahedronGeometry( radius, detail ) {
  16512. Geometry.call( this );
  16513. this.type = 'IcosahedronGeometry';
  16514. this.parameters = {
  16515. radius: radius,
  16516. detail: detail
  16517. };
  16518. this.fromBufferGeometry( new IcosahedronBufferGeometry( radius, detail ) );
  16519. this.mergeVertices();
  16520. }
  16521. IcosahedronGeometry.prototype = Object.create( Geometry.prototype );
  16522. IcosahedronGeometry.prototype.constructor = IcosahedronGeometry;
  16523. // IcosahedronBufferGeometry
  16524. function IcosahedronBufferGeometry( radius, detail ) {
  16525. var t = ( 1 + Math.sqrt( 5 ) ) / 2;
  16526. var vertices = [
  16527. - 1, t, 0, 1, t, 0, - 1, - t, 0, 1, - t, 0,
  16528. 0, - 1, t, 0, 1, t, 0, - 1, - t, 0, 1, - t,
  16529. t, 0, - 1, t, 0, 1, - t, 0, - 1, - t, 0, 1
  16530. ];
  16531. var indices = [
  16532. 0, 11, 5, 0, 5, 1, 0, 1, 7, 0, 7, 10, 0, 10, 11,
  16533. 1, 5, 9, 5, 11, 4, 11, 10, 2, 10, 7, 6, 7, 1, 8,
  16534. 3, 9, 4, 3, 4, 2, 3, 2, 6, 3, 6, 8, 3, 8, 9,
  16535. 4, 9, 5, 2, 4, 11, 6, 2, 10, 8, 6, 7, 9, 8, 1
  16536. ];
  16537. PolyhedronBufferGeometry.call( this, vertices, indices, radius, detail );
  16538. this.type = 'IcosahedronBufferGeometry';
  16539. this.parameters = {
  16540. radius: radius,
  16541. detail: detail
  16542. };
  16543. }
  16544. IcosahedronBufferGeometry.prototype = Object.create( PolyhedronBufferGeometry.prototype );
  16545. IcosahedronBufferGeometry.prototype.constructor = IcosahedronBufferGeometry;
  16546. /**
  16547. * @author Abe Pazos / https://hamoid.com
  16548. * @author Mugen87 / https://github.com/Mugen87
  16549. */
  16550. // DodecahedronGeometry
  16551. function DodecahedronGeometry( radius, detail ) {
  16552. Geometry.call( this );
  16553. this.type = 'DodecahedronGeometry';
  16554. this.parameters = {
  16555. radius: radius,
  16556. detail: detail
  16557. };
  16558. this.fromBufferGeometry( new DodecahedronBufferGeometry( radius, detail ) );
  16559. this.mergeVertices();
  16560. }
  16561. DodecahedronGeometry.prototype = Object.create( Geometry.prototype );
  16562. DodecahedronGeometry.prototype.constructor = DodecahedronGeometry;
  16563. // DodecahedronBufferGeometry
  16564. function DodecahedronBufferGeometry( radius, detail ) {
  16565. var t = ( 1 + Math.sqrt( 5 ) ) / 2;
  16566. var r = 1 / t;
  16567. var vertices = [
  16568. // (±1, ±1, ±1)
  16569. - 1, - 1, - 1, - 1, - 1, 1,
  16570. - 1, 1, - 1, - 1, 1, 1,
  16571. 1, - 1, - 1, 1, - 1, 1,
  16572. 1, 1, - 1, 1, 1, 1,
  16573. // (0, ±1/φ, ±φ)
  16574. 0, - r, - t, 0, - r, t,
  16575. 0, r, - t, 0, r, t,
  16576. // (±1/φ, ±φ, 0)
  16577. - r, - t, 0, - r, t, 0,
  16578. r, - t, 0, r, t, 0,
  16579. // (±φ, 0, ±1/φ)
  16580. - t, 0, - r, t, 0, - r,
  16581. - t, 0, r, t, 0, r
  16582. ];
  16583. var indices = [
  16584. 3, 11, 7, 3, 7, 15, 3, 15, 13,
  16585. 7, 19, 17, 7, 17, 6, 7, 6, 15,
  16586. 17, 4, 8, 17, 8, 10, 17, 10, 6,
  16587. 8, 0, 16, 8, 16, 2, 8, 2, 10,
  16588. 0, 12, 1, 0, 1, 18, 0, 18, 16,
  16589. 6, 10, 2, 6, 2, 13, 6, 13, 15,
  16590. 2, 16, 18, 2, 18, 3, 2, 3, 13,
  16591. 18, 1, 9, 18, 9, 11, 18, 11, 3,
  16592. 4, 14, 12, 4, 12, 0, 4, 0, 8,
  16593. 11, 9, 5, 11, 5, 19, 11, 19, 7,
  16594. 19, 5, 14, 19, 14, 4, 19, 4, 17,
  16595. 1, 12, 14, 1, 14, 5, 1, 5, 9
  16596. ];
  16597. PolyhedronBufferGeometry.call( this, vertices, indices, radius, detail );
  16598. this.type = 'DodecahedronBufferGeometry';
  16599. this.parameters = {
  16600. radius: radius,
  16601. detail: detail
  16602. };
  16603. }
  16604. DodecahedronBufferGeometry.prototype = Object.create( PolyhedronBufferGeometry.prototype );
  16605. DodecahedronBufferGeometry.prototype.constructor = DodecahedronBufferGeometry;
  16606. /**
  16607. * @author oosmoxiecode / https://github.com/oosmoxiecode
  16608. * @author WestLangley / https://github.com/WestLangley
  16609. * @author zz85 / https://github.com/zz85
  16610. * @author miningold / https://github.com/miningold
  16611. * @author jonobr1 / https://github.com/jonobr1
  16612. * @author Mugen87 / https://github.com/Mugen87
  16613. *
  16614. */
  16615. // TubeGeometry
  16616. function TubeGeometry( path, tubularSegments, radius, radialSegments, closed, taper ) {
  16617. Geometry.call( this );
  16618. this.type = 'TubeGeometry';
  16619. this.parameters = {
  16620. path: path,
  16621. tubularSegments: tubularSegments,
  16622. radius: radius,
  16623. radialSegments: radialSegments,
  16624. closed: closed
  16625. };
  16626. if ( taper !== undefined ) console.warn( 'THREE.TubeGeometry: taper has been removed.' );
  16627. var bufferGeometry = new TubeBufferGeometry( path, tubularSegments, radius, radialSegments, closed );
  16628. // expose internals
  16629. this.tangents = bufferGeometry.tangents;
  16630. this.normals = bufferGeometry.normals;
  16631. this.binormals = bufferGeometry.binormals;
  16632. // create geometry
  16633. this.fromBufferGeometry( bufferGeometry );
  16634. this.mergeVertices();
  16635. }
  16636. TubeGeometry.prototype = Object.create( Geometry.prototype );
  16637. TubeGeometry.prototype.constructor = TubeGeometry;
  16638. // TubeBufferGeometry
  16639. function TubeBufferGeometry( path, tubularSegments, radius, radialSegments, closed ) {
  16640. BufferGeometry.call( this );
  16641. this.type = 'TubeBufferGeometry';
  16642. this.parameters = {
  16643. path: path,
  16644. tubularSegments: tubularSegments,
  16645. radius: radius,
  16646. radialSegments: radialSegments,
  16647. closed: closed
  16648. };
  16649. tubularSegments = tubularSegments || 64;
  16650. radius = radius || 1;
  16651. radialSegments = radialSegments || 8;
  16652. closed = closed || false;
  16653. var frames = path.computeFrenetFrames( tubularSegments, closed );
  16654. // expose internals
  16655. this.tangents = frames.tangents;
  16656. this.normals = frames.normals;
  16657. this.binormals = frames.binormals;
  16658. // helper variables
  16659. var vertex = new Vector3();
  16660. var normal = new Vector3();
  16661. var uv = new Vector2();
  16662. var P = new Vector3();
  16663. var i, j;
  16664. // buffer
  16665. var vertices = [];
  16666. var normals = [];
  16667. var uvs = [];
  16668. var indices = [];
  16669. // create buffer data
  16670. generateBufferData();
  16671. // build geometry
  16672. this.setIndex( indices );
  16673. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  16674. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  16675. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  16676. // functions
  16677. function generateBufferData() {
  16678. for ( i = 0; i < tubularSegments; i ++ ) {
  16679. generateSegment( i );
  16680. }
  16681. // if the geometry is not closed, generate the last row of vertices and normals
  16682. // at the regular position on the given path
  16683. //
  16684. // if the geometry is closed, duplicate the first row of vertices and normals (uvs will differ)
  16685. generateSegment( ( closed === false ) ? tubularSegments : 0 );
  16686. // uvs are generated in a separate function.
  16687. // this makes it easy compute correct values for closed geometries
  16688. generateUVs();
  16689. // finally create faces
  16690. generateIndices();
  16691. }
  16692. function generateSegment( i ) {
  16693. // we use getPointAt to sample evenly distributed points from the given path
  16694. P = path.getPointAt( i / tubularSegments, P );
  16695. // retrieve corresponding normal and binormal
  16696. var N = frames.normals[ i ];
  16697. var B = frames.binormals[ i ];
  16698. // generate normals and vertices for the current segment
  16699. for ( j = 0; j <= radialSegments; j ++ ) {
  16700. var v = j / radialSegments * Math.PI * 2;
  16701. var sin = Math.sin( v );
  16702. var cos = - Math.cos( v );
  16703. // normal
  16704. normal.x = ( cos * N.x + sin * B.x );
  16705. normal.y = ( cos * N.y + sin * B.y );
  16706. normal.z = ( cos * N.z + sin * B.z );
  16707. normal.normalize();
  16708. normals.push( normal.x, normal.y, normal.z );
  16709. // vertex
  16710. vertex.x = P.x + radius * normal.x;
  16711. vertex.y = P.y + radius * normal.y;
  16712. vertex.z = P.z + radius * normal.z;
  16713. vertices.push( vertex.x, vertex.y, vertex.z );
  16714. }
  16715. }
  16716. function generateIndices() {
  16717. for ( j = 1; j <= tubularSegments; j ++ ) {
  16718. for ( i = 1; i <= radialSegments; i ++ ) {
  16719. var a = ( radialSegments + 1 ) * ( j - 1 ) + ( i - 1 );
  16720. var b = ( radialSegments + 1 ) * j + ( i - 1 );
  16721. var c = ( radialSegments + 1 ) * j + i;
  16722. var d = ( radialSegments + 1 ) * ( j - 1 ) + i;
  16723. // faces
  16724. indices.push( a, b, d );
  16725. indices.push( b, c, d );
  16726. }
  16727. }
  16728. }
  16729. function generateUVs() {
  16730. for ( i = 0; i <= tubularSegments; i ++ ) {
  16731. for ( j = 0; j <= radialSegments; j ++ ) {
  16732. uv.x = i / tubularSegments;
  16733. uv.y = j / radialSegments;
  16734. uvs.push( uv.x, uv.y );
  16735. }
  16736. }
  16737. }
  16738. }
  16739. TubeBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  16740. TubeBufferGeometry.prototype.constructor = TubeBufferGeometry;
  16741. TubeBufferGeometry.prototype.toJSON = function () {
  16742. var data = BufferGeometry.prototype.toJSON.call( this );
  16743. data.path = this.parameters.path.toJSON();
  16744. return data;
  16745. };
  16746. /**
  16747. * @author oosmoxiecode
  16748. * @author Mugen87 / https://github.com/Mugen87
  16749. *
  16750. * based on http://www.blackpawn.com/texts/pqtorus/
  16751. */
  16752. // TorusKnotGeometry
  16753. function TorusKnotGeometry( radius, tube, tubularSegments, radialSegments, p, q, heightScale ) {
  16754. Geometry.call( this );
  16755. this.type = 'TorusKnotGeometry';
  16756. this.parameters = {
  16757. radius: radius,
  16758. tube: tube,
  16759. tubularSegments: tubularSegments,
  16760. radialSegments: radialSegments,
  16761. p: p,
  16762. q: q
  16763. };
  16764. if ( heightScale !== undefined ) console.warn( 'THREE.TorusKnotGeometry: heightScale has been deprecated. Use .scale( x, y, z ) instead.' );
  16765. this.fromBufferGeometry( new TorusKnotBufferGeometry( radius, tube, tubularSegments, radialSegments, p, q ) );
  16766. this.mergeVertices();
  16767. }
  16768. TorusKnotGeometry.prototype = Object.create( Geometry.prototype );
  16769. TorusKnotGeometry.prototype.constructor = TorusKnotGeometry;
  16770. // TorusKnotBufferGeometry
  16771. function TorusKnotBufferGeometry( radius, tube, tubularSegments, radialSegments, p, q ) {
  16772. BufferGeometry.call( this );
  16773. this.type = 'TorusKnotBufferGeometry';
  16774. this.parameters = {
  16775. radius: radius,
  16776. tube: tube,
  16777. tubularSegments: tubularSegments,
  16778. radialSegments: radialSegments,
  16779. p: p,
  16780. q: q
  16781. };
  16782. radius = radius || 1;
  16783. tube = tube || 0.4;
  16784. tubularSegments = Math.floor( tubularSegments ) || 64;
  16785. radialSegments = Math.floor( radialSegments ) || 8;
  16786. p = p || 2;
  16787. q = q || 3;
  16788. // buffers
  16789. var indices = [];
  16790. var vertices = [];
  16791. var normals = [];
  16792. var uvs = [];
  16793. // helper variables
  16794. var i, j;
  16795. var vertex = new Vector3();
  16796. var normal = new Vector3();
  16797. var P1 = new Vector3();
  16798. var P2 = new Vector3();
  16799. var B = new Vector3();
  16800. var T = new Vector3();
  16801. var N = new Vector3();
  16802. // generate vertices, normals and uvs
  16803. for ( i = 0; i <= tubularSegments; ++ i ) {
  16804. // the radian "u" is used to calculate the position on the torus curve of the current tubular segement
  16805. var u = i / tubularSegments * p * Math.PI * 2;
  16806. // now we calculate two points. P1 is our current position on the curve, P2 is a little farther ahead.
  16807. // these points are used to create a special "coordinate space", which is necessary to calculate the correct vertex positions
  16808. calculatePositionOnCurve( u, p, q, radius, P1 );
  16809. calculatePositionOnCurve( u + 0.01, p, q, radius, P2 );
  16810. // calculate orthonormal basis
  16811. T.subVectors( P2, P1 );
  16812. N.addVectors( P2, P1 );
  16813. B.crossVectors( T, N );
  16814. N.crossVectors( B, T );
  16815. // normalize B, N. T can be ignored, we don't use it
  16816. B.normalize();
  16817. N.normalize();
  16818. for ( j = 0; j <= radialSegments; ++ j ) {
  16819. // now calculate the vertices. they are nothing more than an extrusion of the torus curve.
  16820. // because we extrude a shape in the xy-plane, there is no need to calculate a z-value.
  16821. var v = j / radialSegments * Math.PI * 2;
  16822. var cx = - tube * Math.cos( v );
  16823. var cy = tube * Math.sin( v );
  16824. // now calculate the final vertex position.
  16825. // first we orient the extrusion with our basis vectos, then we add it to the current position on the curve
  16826. vertex.x = P1.x + ( cx * N.x + cy * B.x );
  16827. vertex.y = P1.y + ( cx * N.y + cy * B.y );
  16828. vertex.z = P1.z + ( cx * N.z + cy * B.z );
  16829. vertices.push( vertex.x, vertex.y, vertex.z );
  16830. // normal (P1 is always the center/origin of the extrusion, thus we can use it to calculate the normal)
  16831. normal.subVectors( vertex, P1 ).normalize();
  16832. normals.push( normal.x, normal.y, normal.z );
  16833. // uv
  16834. uvs.push( i / tubularSegments );
  16835. uvs.push( j / radialSegments );
  16836. }
  16837. }
  16838. // generate indices
  16839. for ( j = 1; j <= tubularSegments; j ++ ) {
  16840. for ( i = 1; i <= radialSegments; i ++ ) {
  16841. // indices
  16842. var a = ( radialSegments + 1 ) * ( j - 1 ) + ( i - 1 );
  16843. var b = ( radialSegments + 1 ) * j + ( i - 1 );
  16844. var c = ( radialSegments + 1 ) * j + i;
  16845. var d = ( radialSegments + 1 ) * ( j - 1 ) + i;
  16846. // faces
  16847. indices.push( a, b, d );
  16848. indices.push( b, c, d );
  16849. }
  16850. }
  16851. // build geometry
  16852. this.setIndex( indices );
  16853. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  16854. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  16855. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  16856. // this function calculates the current position on the torus curve
  16857. function calculatePositionOnCurve( u, p, q, radius, position ) {
  16858. var cu = Math.cos( u );
  16859. var su = Math.sin( u );
  16860. var quOverP = q / p * u;
  16861. var cs = Math.cos( quOverP );
  16862. position.x = radius * ( 2 + cs ) * 0.5 * cu;
  16863. position.y = radius * ( 2 + cs ) * su * 0.5;
  16864. position.z = radius * Math.sin( quOverP ) * 0.5;
  16865. }
  16866. }
  16867. TorusKnotBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  16868. TorusKnotBufferGeometry.prototype.constructor = TorusKnotBufferGeometry;
  16869. /**
  16870. * @author oosmoxiecode
  16871. * @author mrdoob / http://mrdoob.com/
  16872. * @author Mugen87 / https://github.com/Mugen87
  16873. */
  16874. // TorusGeometry
  16875. function TorusGeometry( radius, tube, radialSegments, tubularSegments, arc ) {
  16876. Geometry.call( this );
  16877. this.type = 'TorusGeometry';
  16878. this.parameters = {
  16879. radius: radius,
  16880. tube: tube,
  16881. radialSegments: radialSegments,
  16882. tubularSegments: tubularSegments,
  16883. arc: arc
  16884. };
  16885. this.fromBufferGeometry( new TorusBufferGeometry( radius, tube, radialSegments, tubularSegments, arc ) );
  16886. this.mergeVertices();
  16887. }
  16888. TorusGeometry.prototype = Object.create( Geometry.prototype );
  16889. TorusGeometry.prototype.constructor = TorusGeometry;
  16890. // TorusBufferGeometry
  16891. function TorusBufferGeometry( radius, tube, radialSegments, tubularSegments, arc ) {
  16892. BufferGeometry.call( this );
  16893. this.type = 'TorusBufferGeometry';
  16894. this.parameters = {
  16895. radius: radius,
  16896. tube: tube,
  16897. radialSegments: radialSegments,
  16898. tubularSegments: tubularSegments,
  16899. arc: arc
  16900. };
  16901. radius = radius || 1;
  16902. tube = tube || 0.4;
  16903. radialSegments = Math.floor( radialSegments ) || 8;
  16904. tubularSegments = Math.floor( tubularSegments ) || 6;
  16905. arc = arc || Math.PI * 2;
  16906. // buffers
  16907. var indices = [];
  16908. var vertices = [];
  16909. var normals = [];
  16910. var uvs = [];
  16911. // helper variables
  16912. var center = new Vector3();
  16913. var vertex = new Vector3();
  16914. var normal = new Vector3();
  16915. var j, i;
  16916. // generate vertices, normals and uvs
  16917. for ( j = 0; j <= radialSegments; j ++ ) {
  16918. for ( i = 0; i <= tubularSegments; i ++ ) {
  16919. var u = i / tubularSegments * arc;
  16920. var v = j / radialSegments * Math.PI * 2;
  16921. // vertex
  16922. vertex.x = ( radius + tube * Math.cos( v ) ) * Math.cos( u );
  16923. vertex.y = ( radius + tube * Math.cos( v ) ) * Math.sin( u );
  16924. vertex.z = tube * Math.sin( v );
  16925. vertices.push( vertex.x, vertex.y, vertex.z );
  16926. // normal
  16927. center.x = radius * Math.cos( u );
  16928. center.y = radius * Math.sin( u );
  16929. normal.subVectors( vertex, center ).normalize();
  16930. normals.push( normal.x, normal.y, normal.z );
  16931. // uv
  16932. uvs.push( i / tubularSegments );
  16933. uvs.push( j / radialSegments );
  16934. }
  16935. }
  16936. // generate indices
  16937. for ( j = 1; j <= radialSegments; j ++ ) {
  16938. for ( i = 1; i <= tubularSegments; i ++ ) {
  16939. // indices
  16940. var a = ( tubularSegments + 1 ) * j + i - 1;
  16941. var b = ( tubularSegments + 1 ) * ( j - 1 ) + i - 1;
  16942. var c = ( tubularSegments + 1 ) * ( j - 1 ) + i;
  16943. var d = ( tubularSegments + 1 ) * j + i;
  16944. // faces
  16945. indices.push( a, b, d );
  16946. indices.push( b, c, d );
  16947. }
  16948. }
  16949. // build geometry
  16950. this.setIndex( indices );
  16951. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  16952. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  16953. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  16954. }
  16955. TorusBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  16956. TorusBufferGeometry.prototype.constructor = TorusBufferGeometry;
  16957. /**
  16958. * @author Mugen87 / https://github.com/Mugen87
  16959. * Port from https://github.com/mapbox/earcut (v2.1.2)
  16960. */
  16961. var Earcut = {
  16962. triangulate: function ( data, holeIndices, dim ) {
  16963. dim = dim || 2;
  16964. var hasHoles = holeIndices && holeIndices.length,
  16965. outerLen = hasHoles ? holeIndices[ 0 ] * dim : data.length,
  16966. outerNode = linkedList( data, 0, outerLen, dim, true ),
  16967. triangles = [];
  16968. if ( ! outerNode ) return triangles;
  16969. var minX, minY, maxX, maxY, x, y, invSize;
  16970. if ( hasHoles ) outerNode = eliminateHoles( data, holeIndices, outerNode, dim );
  16971. // if the shape is not too simple, we'll use z-order curve hash later; calculate polygon bbox
  16972. if ( data.length > 80 * dim ) {
  16973. minX = maxX = data[ 0 ];
  16974. minY = maxY = data[ 1 ];
  16975. for ( var i = dim; i < outerLen; i += dim ) {
  16976. x = data[ i ];
  16977. y = data[ i + 1 ];
  16978. if ( x < minX ) minX = x;
  16979. if ( y < minY ) minY = y;
  16980. if ( x > maxX ) maxX = x;
  16981. if ( y > maxY ) maxY = y;
  16982. }
  16983. // minX, minY and invSize are later used to transform coords into integers for z-order calculation
  16984. invSize = Math.max( maxX - minX, maxY - minY );
  16985. invSize = invSize !== 0 ? 1 / invSize : 0;
  16986. }
  16987. earcutLinked( outerNode, triangles, dim, minX, minY, invSize );
  16988. return triangles;
  16989. }
  16990. };
  16991. // create a circular doubly linked list from polygon points in the specified winding order
  16992. function linkedList( data, start, end, dim, clockwise ) {
  16993. var i, last;
  16994. if ( clockwise === ( signedArea( data, start, end, dim ) > 0 ) ) {
  16995. for ( i = start; i < end; i += dim ) last = insertNode( i, data[ i ], data[ i + 1 ], last );
  16996. } else {
  16997. for ( i = end - dim; i >= start; i -= dim ) last = insertNode( i, data[ i ], data[ i + 1 ], last );
  16998. }
  16999. if ( last && equals( last, last.next ) ) {
  17000. removeNode( last );
  17001. last = last.next;
  17002. }
  17003. return last;
  17004. }
  17005. // eliminate colinear or duplicate points
  17006. function filterPoints( start, end ) {
  17007. if ( ! start ) return start;
  17008. if ( ! end ) end = start;
  17009. var p = start, again;
  17010. do {
  17011. again = false;
  17012. if ( ! p.steiner && ( equals( p, p.next ) || area( p.prev, p, p.next ) === 0 ) ) {
  17013. removeNode( p );
  17014. p = end = p.prev;
  17015. if ( p === p.next ) break;
  17016. again = true;
  17017. } else {
  17018. p = p.next;
  17019. }
  17020. } while ( again || p !== end );
  17021. return end;
  17022. }
  17023. // main ear slicing loop which triangulates a polygon (given as a linked list)
  17024. function earcutLinked( ear, triangles, dim, minX, minY, invSize, pass ) {
  17025. if ( ! ear ) return;
  17026. // interlink polygon nodes in z-order
  17027. if ( ! pass && invSize ) indexCurve( ear, minX, minY, invSize );
  17028. var stop = ear, prev, next;
  17029. // iterate through ears, slicing them one by one
  17030. while ( ear.prev !== ear.next ) {
  17031. prev = ear.prev;
  17032. next = ear.next;
  17033. if ( invSize ? isEarHashed( ear, minX, minY, invSize ) : isEar( ear ) ) {
  17034. // cut off the triangle
  17035. triangles.push( prev.i / dim );
  17036. triangles.push( ear.i / dim );
  17037. triangles.push( next.i / dim );
  17038. removeNode( ear );
  17039. // skipping the next vertice leads to less sliver triangles
  17040. ear = next.next;
  17041. stop = next.next;
  17042. continue;
  17043. }
  17044. ear = next;
  17045. // if we looped through the whole remaining polygon and can't find any more ears
  17046. if ( ear === stop ) {
  17047. // try filtering points and slicing again
  17048. if ( ! pass ) {
  17049. earcutLinked( filterPoints( ear ), triangles, dim, minX, minY, invSize, 1 );
  17050. // if this didn't work, try curing all small self-intersections locally
  17051. } else if ( pass === 1 ) {
  17052. ear = cureLocalIntersections( ear, triangles, dim );
  17053. earcutLinked( ear, triangles, dim, minX, minY, invSize, 2 );
  17054. // as a last resort, try splitting the remaining polygon into two
  17055. } else if ( pass === 2 ) {
  17056. splitEarcut( ear, triangles, dim, minX, minY, invSize );
  17057. }
  17058. break;
  17059. }
  17060. }
  17061. }
  17062. // check whether a polygon node forms a valid ear with adjacent nodes
  17063. function isEar( ear ) {
  17064. var a = ear.prev,
  17065. b = ear,
  17066. c = ear.next;
  17067. if ( area( a, b, c ) >= 0 ) return false; // reflex, can't be an ear
  17068. // now make sure we don't have other points inside the potential ear
  17069. var p = ear.next.next;
  17070. while ( p !== ear.prev ) {
  17071. 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 ) {
  17072. return false;
  17073. }
  17074. p = p.next;
  17075. }
  17076. return true;
  17077. }
  17078. function isEarHashed( ear, minX, minY, invSize ) {
  17079. var a = ear.prev,
  17080. b = ear,
  17081. c = ear.next;
  17082. if ( area( a, b, c ) >= 0 ) return false; // reflex, can't be an ear
  17083. // triangle bbox; min & max are calculated like this for speed
  17084. var minTX = a.x < b.x ? ( a.x < c.x ? a.x : c.x ) : ( b.x < c.x ? b.x : c.x ),
  17085. minTY = a.y < b.y ? ( a.y < c.y ? a.y : c.y ) : ( b.y < c.y ? b.y : c.y ),
  17086. maxTX = a.x > b.x ? ( a.x > c.x ? a.x : c.x ) : ( b.x > c.x ? b.x : c.x ),
  17087. maxTY = a.y > b.y ? ( a.y > c.y ? a.y : c.y ) : ( b.y > c.y ? b.y : c.y );
  17088. // z-order range for the current triangle bbox;
  17089. var minZ = zOrder( minTX, minTY, minX, minY, invSize ),
  17090. maxZ = zOrder( maxTX, maxTY, minX, minY, invSize );
  17091. // first look for points inside the triangle in increasing z-order
  17092. var p = ear.nextZ;
  17093. while ( p && p.z <= maxZ ) {
  17094. if ( p !== ear.prev && p !== ear.next &&
  17095. pointInTriangle( a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y ) &&
  17096. area( p.prev, p, p.next ) >= 0 ) return false;
  17097. p = p.nextZ;
  17098. }
  17099. // then look for points in decreasing z-order
  17100. p = ear.prevZ;
  17101. while ( p && p.z >= minZ ) {
  17102. if ( p !== ear.prev && p !== ear.next &&
  17103. pointInTriangle( a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y ) &&
  17104. area( p.prev, p, p.next ) >= 0 ) return false;
  17105. p = p.prevZ;
  17106. }
  17107. return true;
  17108. }
  17109. // go through all polygon nodes and cure small local self-intersections
  17110. function cureLocalIntersections( start, triangles, dim ) {
  17111. var p = start;
  17112. do {
  17113. var a = p.prev, b = p.next.next;
  17114. if ( ! equals( a, b ) && intersects( a, p, p.next, b ) && locallyInside( a, b ) && locallyInside( b, a ) ) {
  17115. triangles.push( a.i / dim );
  17116. triangles.push( p.i / dim );
  17117. triangles.push( b.i / dim );
  17118. // remove two nodes involved
  17119. removeNode( p );
  17120. removeNode( p.next );
  17121. p = start = b;
  17122. }
  17123. p = p.next;
  17124. } while ( p !== start );
  17125. return p;
  17126. }
  17127. // try splitting polygon into two and triangulate them independently
  17128. function splitEarcut( start, triangles, dim, minX, minY, invSize ) {
  17129. // look for a valid diagonal that divides the polygon into two
  17130. var a = start;
  17131. do {
  17132. var b = a.next.next;
  17133. while ( b !== a.prev ) {
  17134. if ( a.i !== b.i && isValidDiagonal( a, b ) ) {
  17135. // split the polygon in two by the diagonal
  17136. var c = splitPolygon( a, b );
  17137. // filter colinear points around the cuts
  17138. a = filterPoints( a, a.next );
  17139. c = filterPoints( c, c.next );
  17140. // run earcut on each half
  17141. earcutLinked( a, triangles, dim, minX, minY, invSize );
  17142. earcutLinked( c, triangles, dim, minX, minY, invSize );
  17143. return;
  17144. }
  17145. b = b.next;
  17146. }
  17147. a = a.next;
  17148. } while ( a !== start );
  17149. }
  17150. // link every hole into the outer loop, producing a single-ring polygon without holes
  17151. function eliminateHoles( data, holeIndices, outerNode, dim ) {
  17152. var queue = [], i, len, start, end, list;
  17153. for ( i = 0, len = holeIndices.length; i < len; i ++ ) {
  17154. start = holeIndices[ i ] * dim;
  17155. end = i < len - 1 ? holeIndices[ i + 1 ] * dim : data.length;
  17156. list = linkedList( data, start, end, dim, false );
  17157. if ( list === list.next ) list.steiner = true;
  17158. queue.push( getLeftmost( list ) );
  17159. }
  17160. queue.sort( compareX );
  17161. // process holes from left to right
  17162. for ( i = 0; i < queue.length; i ++ ) {
  17163. eliminateHole( queue[ i ], outerNode );
  17164. outerNode = filterPoints( outerNode, outerNode.next );
  17165. }
  17166. return outerNode;
  17167. }
  17168. function compareX( a, b ) {
  17169. return a.x - b.x;
  17170. }
  17171. // find a bridge between vertices that connects hole with an outer ring and and link it
  17172. function eliminateHole( hole, outerNode ) {
  17173. outerNode = findHoleBridge( hole, outerNode );
  17174. if ( outerNode ) {
  17175. var b = splitPolygon( outerNode, hole );
  17176. filterPoints( b, b.next );
  17177. }
  17178. }
  17179. // David Eberly's algorithm for finding a bridge between hole and outer polygon
  17180. function findHoleBridge( hole, outerNode ) {
  17181. var p = outerNode,
  17182. hx = hole.x,
  17183. hy = hole.y,
  17184. qx = - Infinity,
  17185. m;
  17186. // find a segment intersected by a ray from the hole's leftmost point to the left;
  17187. // segment's endpoint with lesser x will be potential connection point
  17188. do {
  17189. if ( hy <= p.y && hy >= p.next.y && p.next.y !== p.y ) {
  17190. var x = p.x + ( hy - p.y ) * ( p.next.x - p.x ) / ( p.next.y - p.y );
  17191. if ( x <= hx && x > qx ) {
  17192. qx = x;
  17193. if ( x === hx ) {
  17194. if ( hy === p.y ) return p;
  17195. if ( hy === p.next.y ) return p.next;
  17196. }
  17197. m = p.x < p.next.x ? p : p.next;
  17198. }
  17199. }
  17200. p = p.next;
  17201. } while ( p !== outerNode );
  17202. if ( ! m ) return null;
  17203. if ( hx === qx ) return m.prev; // hole touches outer segment; pick lower endpoint
  17204. // look for points inside the triangle of hole point, segment intersection and endpoint;
  17205. // if there are no points found, we have a valid connection;
  17206. // otherwise choose the point of the minimum angle with the ray as connection point
  17207. var stop = m,
  17208. mx = m.x,
  17209. my = m.y,
  17210. tanMin = Infinity,
  17211. tan;
  17212. p = m.next;
  17213. while ( p !== stop ) {
  17214. if ( hx >= p.x && p.x >= mx && hx !== p.x &&
  17215. pointInTriangle( hy < my ? hx : qx, hy, mx, my, hy < my ? qx : hx, hy, p.x, p.y ) ) {
  17216. tan = Math.abs( hy - p.y ) / ( hx - p.x ); // tangential
  17217. if ( ( tan < tanMin || ( tan === tanMin && p.x > m.x ) ) && locallyInside( p, hole ) ) {
  17218. m = p;
  17219. tanMin = tan;
  17220. }
  17221. }
  17222. p = p.next;
  17223. }
  17224. return m;
  17225. }
  17226. // interlink polygon nodes in z-order
  17227. function indexCurve( start, minX, minY, invSize ) {
  17228. var p = start;
  17229. do {
  17230. if ( p.z === null ) p.z = zOrder( p.x, p.y, minX, minY, invSize );
  17231. p.prevZ = p.prev;
  17232. p.nextZ = p.next;
  17233. p = p.next;
  17234. } while ( p !== start );
  17235. p.prevZ.nextZ = null;
  17236. p.prevZ = null;
  17237. sortLinked( p );
  17238. }
  17239. // Simon Tatham's linked list merge sort algorithm
  17240. // http://www.chiark.greenend.org.uk/~sgtatham/algorithms/listsort.html
  17241. function sortLinked( list ) {
  17242. var i, p, q, e, tail, numMerges, pSize, qSize, inSize = 1;
  17243. do {
  17244. p = list;
  17245. list = null;
  17246. tail = null;
  17247. numMerges = 0;
  17248. while ( p ) {
  17249. numMerges ++;
  17250. q = p;
  17251. pSize = 0;
  17252. for ( i = 0; i < inSize; i ++ ) {
  17253. pSize ++;
  17254. q = q.nextZ;
  17255. if ( ! q ) break;
  17256. }
  17257. qSize = inSize;
  17258. while ( pSize > 0 || ( qSize > 0 && q ) ) {
  17259. if ( pSize !== 0 && ( qSize === 0 || ! q || p.z <= q.z ) ) {
  17260. e = p;
  17261. p = p.nextZ;
  17262. pSize --;
  17263. } else {
  17264. e = q;
  17265. q = q.nextZ;
  17266. qSize --;
  17267. }
  17268. if ( tail ) tail.nextZ = e;
  17269. else list = e;
  17270. e.prevZ = tail;
  17271. tail = e;
  17272. }
  17273. p = q;
  17274. }
  17275. tail.nextZ = null;
  17276. inSize *= 2;
  17277. } while ( numMerges > 1 );
  17278. return list;
  17279. }
  17280. // z-order of a point given coords and inverse of the longer side of data bbox
  17281. function zOrder( x, y, minX, minY, invSize ) {
  17282. // coords are transformed into non-negative 15-bit integer range
  17283. x = 32767 * ( x - minX ) * invSize;
  17284. y = 32767 * ( y - minY ) * invSize;
  17285. x = ( x | ( x << 8 ) ) & 0x00FF00FF;
  17286. x = ( x | ( x << 4 ) ) & 0x0F0F0F0F;
  17287. x = ( x | ( x << 2 ) ) & 0x33333333;
  17288. x = ( x | ( x << 1 ) ) & 0x55555555;
  17289. y = ( y | ( y << 8 ) ) & 0x00FF00FF;
  17290. y = ( y | ( y << 4 ) ) & 0x0F0F0F0F;
  17291. y = ( y | ( y << 2 ) ) & 0x33333333;
  17292. y = ( y | ( y << 1 ) ) & 0x55555555;
  17293. return x | ( y << 1 );
  17294. }
  17295. // find the leftmost node of a polygon ring
  17296. function getLeftmost( start ) {
  17297. var p = start, leftmost = start;
  17298. do {
  17299. if ( p.x < leftmost.x ) leftmost = p;
  17300. p = p.next;
  17301. } while ( p !== start );
  17302. return leftmost;
  17303. }
  17304. // check if a point lies within a convex triangle
  17305. function pointInTriangle( ax, ay, bx, by, cx, cy, px, py ) {
  17306. return ( cx - px ) * ( ay - py ) - ( ax - px ) * ( cy - py ) >= 0 &&
  17307. ( ax - px ) * ( by - py ) - ( bx - px ) * ( ay - py ) >= 0 &&
  17308. ( bx - px ) * ( cy - py ) - ( cx - px ) * ( by - py ) >= 0;
  17309. }
  17310. // check if a diagonal between two polygon nodes is valid (lies in polygon interior)
  17311. function isValidDiagonal( a, b ) {
  17312. return a.next.i !== b.i && a.prev.i !== b.i && ! intersectsPolygon( a, b ) &&
  17313. locallyInside( a, b ) && locallyInside( b, a ) && middleInside( a, b );
  17314. }
  17315. // signed area of a triangle
  17316. function area( p, q, r ) {
  17317. return ( q.y - p.y ) * ( r.x - q.x ) - ( q.x - p.x ) * ( r.y - q.y );
  17318. }
  17319. // check if two points are equal
  17320. function equals( p1, p2 ) {
  17321. return p1.x === p2.x && p1.y === p2.y;
  17322. }
  17323. // check if two segments intersect
  17324. function intersects( p1, q1, p2, q2 ) {
  17325. if ( ( equals( p1, q1 ) && equals( p2, q2 ) ) ||
  17326. ( equals( p1, q2 ) && equals( p2, q1 ) ) ) return true;
  17327. return area( p1, q1, p2 ) > 0 !== area( p1, q1, q2 ) > 0 &&
  17328. area( p2, q2, p1 ) > 0 !== area( p2, q2, q1 ) > 0;
  17329. }
  17330. // check if a polygon diagonal intersects any polygon segments
  17331. function intersectsPolygon( a, b ) {
  17332. var p = a;
  17333. do {
  17334. if ( p.i !== a.i && p.next.i !== a.i && p.i !== b.i && p.next.i !== b.i &&
  17335. intersects( p, p.next, a, b ) ) {
  17336. return true;
  17337. }
  17338. p = p.next;
  17339. } while ( p !== a );
  17340. return false;
  17341. }
  17342. // check if a polygon diagonal is locally inside the polygon
  17343. function locallyInside( a, b ) {
  17344. return area( a.prev, a, a.next ) < 0 ?
  17345. area( a, b, a.next ) >= 0 && area( a, a.prev, b ) >= 0 :
  17346. area( a, b, a.prev ) < 0 || area( a, a.next, b ) < 0;
  17347. }
  17348. // check if the middle point of a polygon diagonal is inside the polygon
  17349. function middleInside( a, b ) {
  17350. var p = a,
  17351. inside = false,
  17352. px = ( a.x + b.x ) / 2,
  17353. py = ( a.y + b.y ) / 2;
  17354. do {
  17355. if ( ( ( p.y > py ) !== ( p.next.y > py ) ) && p.next.y !== p.y &&
  17356. ( px < ( p.next.x - p.x ) * ( py - p.y ) / ( p.next.y - p.y ) + p.x ) ) {
  17357. inside = ! inside;
  17358. }
  17359. p = p.next;
  17360. } while ( p !== a );
  17361. return inside;
  17362. }
  17363. // link two polygon vertices with a bridge; if the vertices belong to the same ring, it splits polygon into two;
  17364. // if one belongs to the outer ring and another to a hole, it merges it into a single ring
  17365. function splitPolygon( a, b ) {
  17366. var a2 = new Node( a.i, a.x, a.y ),
  17367. b2 = new Node( b.i, b.x, b.y ),
  17368. an = a.next,
  17369. bp = b.prev;
  17370. a.next = b;
  17371. b.prev = a;
  17372. a2.next = an;
  17373. an.prev = a2;
  17374. b2.next = a2;
  17375. a2.prev = b2;
  17376. bp.next = b2;
  17377. b2.prev = bp;
  17378. return b2;
  17379. }
  17380. // create a node and optionally link it with previous one (in a circular doubly linked list)
  17381. function insertNode( i, x, y, last ) {
  17382. var p = new Node( i, x, y );
  17383. if ( ! last ) {
  17384. p.prev = p;
  17385. p.next = p;
  17386. } else {
  17387. p.next = last.next;
  17388. p.prev = last;
  17389. last.next.prev = p;
  17390. last.next = p;
  17391. }
  17392. return p;
  17393. }
  17394. function removeNode( p ) {
  17395. p.next.prev = p.prev;
  17396. p.prev.next = p.next;
  17397. if ( p.prevZ ) p.prevZ.nextZ = p.nextZ;
  17398. if ( p.nextZ ) p.nextZ.prevZ = p.prevZ;
  17399. }
  17400. function Node( i, x, y ) {
  17401. // vertice index in coordinates array
  17402. this.i = i;
  17403. // vertex coordinates
  17404. this.x = x;
  17405. this.y = y;
  17406. // previous and next vertice nodes in a polygon ring
  17407. this.prev = null;
  17408. this.next = null;
  17409. // z-order curve value
  17410. this.z = null;
  17411. // previous and next nodes in z-order
  17412. this.prevZ = null;
  17413. this.nextZ = null;
  17414. // indicates whether this is a steiner point
  17415. this.steiner = false;
  17416. }
  17417. function signedArea( data, start, end, dim ) {
  17418. var sum = 0;
  17419. for ( var i = start, j = end - dim; i < end; i += dim ) {
  17420. sum += ( data[ j ] - data[ i ] ) * ( data[ i + 1 ] + data[ j + 1 ] );
  17421. j = i;
  17422. }
  17423. return sum;
  17424. }
  17425. /**
  17426. * @author zz85 / http://www.lab4games.net/zz85/blog
  17427. */
  17428. var ShapeUtils = {
  17429. // calculate area of the contour polygon
  17430. area: function ( contour ) {
  17431. var n = contour.length;
  17432. var a = 0.0;
  17433. for ( var p = n - 1, q = 0; q < n; p = q ++ ) {
  17434. a += contour[ p ].x * contour[ q ].y - contour[ q ].x * contour[ p ].y;
  17435. }
  17436. return a * 0.5;
  17437. },
  17438. isClockWise: function ( pts ) {
  17439. return ShapeUtils.area( pts ) < 0;
  17440. },
  17441. triangulateShape: function ( contour, holes ) {
  17442. var vertices = []; // flat array of vertices like [ x0,y0, x1,y1, x2,y2, ... ]
  17443. var holeIndices = []; // array of hole indices
  17444. var faces = []; // final array of vertex indices like [ [ a,b,d ], [ b,c,d ] ]
  17445. removeDupEndPts( contour );
  17446. addContour( vertices, contour );
  17447. //
  17448. var holeIndex = contour.length;
  17449. holes.forEach( removeDupEndPts );
  17450. for ( var i = 0; i < holes.length; i ++ ) {
  17451. holeIndices.push( holeIndex );
  17452. holeIndex += holes[ i ].length;
  17453. addContour( vertices, holes[ i ] );
  17454. }
  17455. //
  17456. var triangles = Earcut.triangulate( vertices, holeIndices );
  17457. //
  17458. for ( var i = 0; i < triangles.length; i += 3 ) {
  17459. faces.push( triangles.slice( i, i + 3 ) );
  17460. }
  17461. return faces;
  17462. }
  17463. };
  17464. function removeDupEndPts( points ) {
  17465. var l = points.length;
  17466. if ( l > 2 && points[ l - 1 ].equals( points[ 0 ] ) ) {
  17467. points.pop();
  17468. }
  17469. }
  17470. function addContour( vertices, contour ) {
  17471. for ( var i = 0; i < contour.length; i ++ ) {
  17472. vertices.push( contour[ i ].x );
  17473. vertices.push( contour[ i ].y );
  17474. }
  17475. }
  17476. /**
  17477. * @author zz85 / http://www.lab4games.net/zz85/blog
  17478. *
  17479. * Creates extruded geometry from a path shape.
  17480. *
  17481. * parameters = {
  17482. *
  17483. * curveSegments: <int>, // number of points on the curves
  17484. * steps: <int>, // number of points for z-side extrusions / used for subdividing segments of extrude spline too
  17485. * depth: <float>, // Depth to extrude the shape
  17486. *
  17487. * bevelEnabled: <bool>, // turn on bevel
  17488. * bevelThickness: <float>, // how deep into the original shape bevel goes
  17489. * bevelSize: <float>, // how far from shape outline (including bevelOffset) is bevel
  17490. * bevelOffset: <float>, // how far from shape outline does bevel start
  17491. * bevelSegments: <int>, // number of bevel layers
  17492. *
  17493. * extrudePath: <THREE.Curve> // curve to extrude shape along
  17494. *
  17495. * UVGenerator: <Object> // object that provides UV generator functions
  17496. *
  17497. * }
  17498. */
  17499. // ExtrudeGeometry
  17500. function ExtrudeGeometry( shapes, options ) {
  17501. Geometry.call( this );
  17502. this.type = 'ExtrudeGeometry';
  17503. this.parameters = {
  17504. shapes: shapes,
  17505. options: options
  17506. };
  17507. this.fromBufferGeometry( new ExtrudeBufferGeometry( shapes, options ) );
  17508. this.mergeVertices();
  17509. }
  17510. ExtrudeGeometry.prototype = Object.create( Geometry.prototype );
  17511. ExtrudeGeometry.prototype.constructor = ExtrudeGeometry;
  17512. ExtrudeGeometry.prototype.toJSON = function () {
  17513. var data = Geometry.prototype.toJSON.call( this );
  17514. var shapes = this.parameters.shapes;
  17515. var options = this.parameters.options;
  17516. return toJSON( shapes, options, data );
  17517. };
  17518. // ExtrudeBufferGeometry
  17519. function ExtrudeBufferGeometry( shapes, options ) {
  17520. BufferGeometry.call( this );
  17521. this.type = 'ExtrudeBufferGeometry';
  17522. this.parameters = {
  17523. shapes: shapes,
  17524. options: options
  17525. };
  17526. shapes = Array.isArray( shapes ) ? shapes : [ shapes ];
  17527. var scope = this;
  17528. var verticesArray = [];
  17529. var uvArray = [];
  17530. for ( var i = 0, l = shapes.length; i < l; i ++ ) {
  17531. var shape = shapes[ i ];
  17532. addShape( shape );
  17533. }
  17534. // build geometry
  17535. this.addAttribute( 'position', new Float32BufferAttribute( verticesArray, 3 ) );
  17536. this.addAttribute( 'uv', new Float32BufferAttribute( uvArray, 2 ) );
  17537. this.computeVertexNormals();
  17538. // functions
  17539. function addShape( shape ) {
  17540. var placeholder = [];
  17541. // options
  17542. var curveSegments = options.curveSegments !== undefined ? options.curveSegments : 12;
  17543. var steps = options.steps !== undefined ? options.steps : 1;
  17544. var depth = options.depth !== undefined ? options.depth : 100;
  17545. var bevelEnabled = options.bevelEnabled !== undefined ? options.bevelEnabled : true;
  17546. var bevelThickness = options.bevelThickness !== undefined ? options.bevelThickness : 6;
  17547. var bevelSize = options.bevelSize !== undefined ? options.bevelSize : bevelThickness - 2;
  17548. var bevelOffset = options.bevelOffset !== undefined ? options.bevelOffset : 0;
  17549. var bevelSegments = options.bevelSegments !== undefined ? options.bevelSegments : 3;
  17550. var extrudePath = options.extrudePath;
  17551. var uvgen = options.UVGenerator !== undefined ? options.UVGenerator : WorldUVGenerator;
  17552. // deprecated options
  17553. if ( options.amount !== undefined ) {
  17554. console.warn( 'THREE.ExtrudeBufferGeometry: amount has been renamed to depth.' );
  17555. depth = options.amount;
  17556. }
  17557. //
  17558. var extrudePts, extrudeByPath = false;
  17559. var splineTube, binormal, normal, position2;
  17560. if ( extrudePath ) {
  17561. extrudePts = extrudePath.getSpacedPoints( steps );
  17562. extrudeByPath = true;
  17563. bevelEnabled = false; // bevels not supported for path extrusion
  17564. // SETUP TNB variables
  17565. // TODO1 - have a .isClosed in spline?
  17566. splineTube = extrudePath.computeFrenetFrames( steps, false );
  17567. // console.log(splineTube, 'splineTube', splineTube.normals.length, 'steps', steps, 'extrudePts', extrudePts.length);
  17568. binormal = new Vector3();
  17569. normal = new Vector3();
  17570. position2 = new Vector3();
  17571. }
  17572. // Safeguards if bevels are not enabled
  17573. if ( ! bevelEnabled ) {
  17574. bevelSegments = 0;
  17575. bevelThickness = 0;
  17576. bevelSize = 0;
  17577. bevelOffset = 0;
  17578. }
  17579. // Variables initialization
  17580. var ahole, h, hl; // looping of holes
  17581. var shapePoints = shape.extractPoints( curveSegments );
  17582. var vertices = shapePoints.shape;
  17583. var holes = shapePoints.holes;
  17584. var reverse = ! ShapeUtils.isClockWise( vertices );
  17585. if ( reverse ) {
  17586. vertices = vertices.reverse();
  17587. // Maybe we should also check if holes are in the opposite direction, just to be safe ...
  17588. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  17589. ahole = holes[ h ];
  17590. if ( ShapeUtils.isClockWise( ahole ) ) {
  17591. holes[ h ] = ahole.reverse();
  17592. }
  17593. }
  17594. }
  17595. var faces = ShapeUtils.triangulateShape( vertices, holes );
  17596. /* Vertices */
  17597. var contour = vertices; // vertices has all points but contour has only points of circumference
  17598. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  17599. ahole = holes[ h ];
  17600. vertices = vertices.concat( ahole );
  17601. }
  17602. function scalePt2( pt, vec, size ) {
  17603. if ( ! vec ) console.error( "THREE.ExtrudeGeometry: vec does not exist" );
  17604. return vec.clone().multiplyScalar( size ).add( pt );
  17605. }
  17606. var b, bs, t, z,
  17607. vert, vlen = vertices.length,
  17608. face, flen = faces.length;
  17609. // Find directions for point movement
  17610. function getBevelVec( inPt, inPrev, inNext ) {
  17611. // computes for inPt the corresponding point inPt' on a new contour
  17612. // shifted by 1 unit (length of normalized vector) to the left
  17613. // if we walk along contour clockwise, this new contour is outside the old one
  17614. //
  17615. // inPt' is the intersection of the two lines parallel to the two
  17616. // adjacent edges of inPt at a distance of 1 unit on the left side.
  17617. var v_trans_x, v_trans_y, shrink_by; // resulting translation vector for inPt
  17618. // good reading for geometry algorithms (here: line-line intersection)
  17619. // http://geomalgorithms.com/a05-_intersect-1.html
  17620. var v_prev_x = inPt.x - inPrev.x,
  17621. v_prev_y = inPt.y - inPrev.y;
  17622. var v_next_x = inNext.x - inPt.x,
  17623. v_next_y = inNext.y - inPt.y;
  17624. var v_prev_lensq = ( v_prev_x * v_prev_x + v_prev_y * v_prev_y );
  17625. // check for collinear edges
  17626. var collinear0 = ( v_prev_x * v_next_y - v_prev_y * v_next_x );
  17627. if ( Math.abs( collinear0 ) > Number.EPSILON ) {
  17628. // not collinear
  17629. // length of vectors for normalizing
  17630. var v_prev_len = Math.sqrt( v_prev_lensq );
  17631. var v_next_len = Math.sqrt( v_next_x * v_next_x + v_next_y * v_next_y );
  17632. // shift adjacent points by unit vectors to the left
  17633. var ptPrevShift_x = ( inPrev.x - v_prev_y / v_prev_len );
  17634. var ptPrevShift_y = ( inPrev.y + v_prev_x / v_prev_len );
  17635. var ptNextShift_x = ( inNext.x - v_next_y / v_next_len );
  17636. var ptNextShift_y = ( inNext.y + v_next_x / v_next_len );
  17637. // scaling factor for v_prev to intersection point
  17638. var sf = ( ( ptNextShift_x - ptPrevShift_x ) * v_next_y -
  17639. ( ptNextShift_y - ptPrevShift_y ) * v_next_x ) /
  17640. ( v_prev_x * v_next_y - v_prev_y * v_next_x );
  17641. // vector from inPt to intersection point
  17642. v_trans_x = ( ptPrevShift_x + v_prev_x * sf - inPt.x );
  17643. v_trans_y = ( ptPrevShift_y + v_prev_y * sf - inPt.y );
  17644. // Don't normalize!, otherwise sharp corners become ugly
  17645. // but prevent crazy spikes
  17646. var v_trans_lensq = ( v_trans_x * v_trans_x + v_trans_y * v_trans_y );
  17647. if ( v_trans_lensq <= 2 ) {
  17648. return new Vector2( v_trans_x, v_trans_y );
  17649. } else {
  17650. shrink_by = Math.sqrt( v_trans_lensq / 2 );
  17651. }
  17652. } else {
  17653. // handle special case of collinear edges
  17654. var direction_eq = false; // assumes: opposite
  17655. if ( v_prev_x > Number.EPSILON ) {
  17656. if ( v_next_x > Number.EPSILON ) {
  17657. direction_eq = true;
  17658. }
  17659. } else {
  17660. if ( v_prev_x < - Number.EPSILON ) {
  17661. if ( v_next_x < - Number.EPSILON ) {
  17662. direction_eq = true;
  17663. }
  17664. } else {
  17665. if ( Math.sign( v_prev_y ) === Math.sign( v_next_y ) ) {
  17666. direction_eq = true;
  17667. }
  17668. }
  17669. }
  17670. if ( direction_eq ) {
  17671. // console.log("Warning: lines are a straight sequence");
  17672. v_trans_x = - v_prev_y;
  17673. v_trans_y = v_prev_x;
  17674. shrink_by = Math.sqrt( v_prev_lensq );
  17675. } else {
  17676. // console.log("Warning: lines are a straight spike");
  17677. v_trans_x = v_prev_x;
  17678. v_trans_y = v_prev_y;
  17679. shrink_by = Math.sqrt( v_prev_lensq / 2 );
  17680. }
  17681. }
  17682. return new Vector2( v_trans_x / shrink_by, v_trans_y / shrink_by );
  17683. }
  17684. var contourMovements = [];
  17685. for ( var i = 0, il = contour.length, j = il - 1, k = i + 1; i < il; i ++, j ++, k ++ ) {
  17686. if ( j === il ) j = 0;
  17687. if ( k === il ) k = 0;
  17688. // (j)---(i)---(k)
  17689. // console.log('i,j,k', i, j , k)
  17690. contourMovements[ i ] = getBevelVec( contour[ i ], contour[ j ], contour[ k ] );
  17691. }
  17692. var holesMovements = [],
  17693. oneHoleMovements, verticesMovements = contourMovements.concat();
  17694. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  17695. ahole = holes[ h ];
  17696. oneHoleMovements = [];
  17697. for ( i = 0, il = ahole.length, j = il - 1, k = i + 1; i < il; i ++, j ++, k ++ ) {
  17698. if ( j === il ) j = 0;
  17699. if ( k === il ) k = 0;
  17700. // (j)---(i)---(k)
  17701. oneHoleMovements[ i ] = getBevelVec( ahole[ i ], ahole[ j ], ahole[ k ] );
  17702. }
  17703. holesMovements.push( oneHoleMovements );
  17704. verticesMovements = verticesMovements.concat( oneHoleMovements );
  17705. }
  17706. // Loop bevelSegments, 1 for the front, 1 for the back
  17707. for ( b = 0; b < bevelSegments; b ++ ) {
  17708. //for ( b = bevelSegments; b > 0; b -- ) {
  17709. t = b / bevelSegments;
  17710. z = bevelThickness * Math.cos( t * Math.PI / 2 );
  17711. bs = bevelSize * Math.sin( t * Math.PI / 2 ) + bevelOffset;
  17712. // contract shape
  17713. for ( i = 0, il = contour.length; i < il; i ++ ) {
  17714. vert = scalePt2( contour[ i ], contourMovements[ i ], bs );
  17715. v( vert.x, vert.y, - z );
  17716. }
  17717. // expand holes
  17718. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  17719. ahole = holes[ h ];
  17720. oneHoleMovements = holesMovements[ h ];
  17721. for ( i = 0, il = ahole.length; i < il; i ++ ) {
  17722. vert = scalePt2( ahole[ i ], oneHoleMovements[ i ], bs );
  17723. v( vert.x, vert.y, - z );
  17724. }
  17725. }
  17726. }
  17727. bs = bevelSize + bevelOffset;
  17728. // Back facing vertices
  17729. for ( i = 0; i < vlen; i ++ ) {
  17730. vert = bevelEnabled ? scalePt2( vertices[ i ], verticesMovements[ i ], bs ) : vertices[ i ];
  17731. if ( ! extrudeByPath ) {
  17732. v( vert.x, vert.y, 0 );
  17733. } else {
  17734. // v( vert.x, vert.y + extrudePts[ 0 ].y, extrudePts[ 0 ].x );
  17735. normal.copy( splineTube.normals[ 0 ] ).multiplyScalar( vert.x );
  17736. binormal.copy( splineTube.binormals[ 0 ] ).multiplyScalar( vert.y );
  17737. position2.copy( extrudePts[ 0 ] ).add( normal ).add( binormal );
  17738. v( position2.x, position2.y, position2.z );
  17739. }
  17740. }
  17741. // Add stepped vertices...
  17742. // Including front facing vertices
  17743. var s;
  17744. for ( s = 1; s <= steps; s ++ ) {
  17745. for ( i = 0; i < vlen; i ++ ) {
  17746. vert = bevelEnabled ? scalePt2( vertices[ i ], verticesMovements[ i ], bs ) : vertices[ i ];
  17747. if ( ! extrudeByPath ) {
  17748. v( vert.x, vert.y, depth / steps * s );
  17749. } else {
  17750. // v( vert.x, vert.y + extrudePts[ s - 1 ].y, extrudePts[ s - 1 ].x );
  17751. normal.copy( splineTube.normals[ s ] ).multiplyScalar( vert.x );
  17752. binormal.copy( splineTube.binormals[ s ] ).multiplyScalar( vert.y );
  17753. position2.copy( extrudePts[ s ] ).add( normal ).add( binormal );
  17754. v( position2.x, position2.y, position2.z );
  17755. }
  17756. }
  17757. }
  17758. // Add bevel segments planes
  17759. //for ( b = 1; b <= bevelSegments; b ++ ) {
  17760. for ( b = bevelSegments - 1; b >= 0; b -- ) {
  17761. t = b / bevelSegments;
  17762. z = bevelThickness * Math.cos( t * Math.PI / 2 );
  17763. bs = bevelSize * Math.sin( t * Math.PI / 2 ) + bevelOffset;
  17764. // contract shape
  17765. for ( i = 0, il = contour.length; i < il; i ++ ) {
  17766. vert = scalePt2( contour[ i ], contourMovements[ i ], bs );
  17767. v( vert.x, vert.y, depth + z );
  17768. }
  17769. // expand holes
  17770. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  17771. ahole = holes[ h ];
  17772. oneHoleMovements = holesMovements[ h ];
  17773. for ( i = 0, il = ahole.length; i < il; i ++ ) {
  17774. vert = scalePt2( ahole[ i ], oneHoleMovements[ i ], bs );
  17775. if ( ! extrudeByPath ) {
  17776. v( vert.x, vert.y, depth + z );
  17777. } else {
  17778. v( vert.x, vert.y + extrudePts[ steps - 1 ].y, extrudePts[ steps - 1 ].x + z );
  17779. }
  17780. }
  17781. }
  17782. }
  17783. /* Faces */
  17784. // Top and bottom faces
  17785. buildLidFaces();
  17786. // Sides faces
  17787. buildSideFaces();
  17788. ///// Internal functions
  17789. function buildLidFaces() {
  17790. var start = verticesArray.length / 3;
  17791. if ( bevelEnabled ) {
  17792. var layer = 0; // steps + 1
  17793. var offset = vlen * layer;
  17794. // Bottom faces
  17795. for ( i = 0; i < flen; i ++ ) {
  17796. face = faces[ i ];
  17797. f3( face[ 2 ] + offset, face[ 1 ] + offset, face[ 0 ] + offset );
  17798. }
  17799. layer = steps + bevelSegments * 2;
  17800. offset = vlen * layer;
  17801. // Top faces
  17802. for ( i = 0; i < flen; i ++ ) {
  17803. face = faces[ i ];
  17804. f3( face[ 0 ] + offset, face[ 1 ] + offset, face[ 2 ] + offset );
  17805. }
  17806. } else {
  17807. // Bottom faces
  17808. for ( i = 0; i < flen; i ++ ) {
  17809. face = faces[ i ];
  17810. f3( face[ 2 ], face[ 1 ], face[ 0 ] );
  17811. }
  17812. // Top faces
  17813. for ( i = 0; i < flen; i ++ ) {
  17814. face = faces[ i ];
  17815. f3( face[ 0 ] + vlen * steps, face[ 1 ] + vlen * steps, face[ 2 ] + vlen * steps );
  17816. }
  17817. }
  17818. scope.addGroup( start, verticesArray.length / 3 - start, 0 );
  17819. }
  17820. // Create faces for the z-sides of the shape
  17821. function buildSideFaces() {
  17822. var start = verticesArray.length / 3;
  17823. var layeroffset = 0;
  17824. sidewalls( contour, layeroffset );
  17825. layeroffset += contour.length;
  17826. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  17827. ahole = holes[ h ];
  17828. sidewalls( ahole, layeroffset );
  17829. //, true
  17830. layeroffset += ahole.length;
  17831. }
  17832. scope.addGroup( start, verticesArray.length / 3 - start, 1 );
  17833. }
  17834. function sidewalls( contour, layeroffset ) {
  17835. var j, k;
  17836. i = contour.length;
  17837. while ( -- i >= 0 ) {
  17838. j = i;
  17839. k = i - 1;
  17840. if ( k < 0 ) k = contour.length - 1;
  17841. //console.log('b', i,j, i-1, k,vertices.length);
  17842. var s = 0,
  17843. sl = steps + bevelSegments * 2;
  17844. for ( s = 0; s < sl; s ++ ) {
  17845. var slen1 = vlen * s;
  17846. var slen2 = vlen * ( s + 1 );
  17847. var a = layeroffset + j + slen1,
  17848. b = layeroffset + k + slen1,
  17849. c = layeroffset + k + slen2,
  17850. d = layeroffset + j + slen2;
  17851. f4( a, b, c, d );
  17852. }
  17853. }
  17854. }
  17855. function v( x, y, z ) {
  17856. placeholder.push( x );
  17857. placeholder.push( y );
  17858. placeholder.push( z );
  17859. }
  17860. function f3( a, b, c ) {
  17861. addVertex( a );
  17862. addVertex( b );
  17863. addVertex( c );
  17864. var nextIndex = verticesArray.length / 3;
  17865. var uvs = uvgen.generateTopUV( scope, verticesArray, nextIndex - 3, nextIndex - 2, nextIndex - 1 );
  17866. addUV( uvs[ 0 ] );
  17867. addUV( uvs[ 1 ] );
  17868. addUV( uvs[ 2 ] );
  17869. }
  17870. function f4( a, b, c, d ) {
  17871. addVertex( a );
  17872. addVertex( b );
  17873. addVertex( d );
  17874. addVertex( b );
  17875. addVertex( c );
  17876. addVertex( d );
  17877. var nextIndex = verticesArray.length / 3;
  17878. var uvs = uvgen.generateSideWallUV( scope, verticesArray, nextIndex - 6, nextIndex - 3, nextIndex - 2, nextIndex - 1 );
  17879. addUV( uvs[ 0 ] );
  17880. addUV( uvs[ 1 ] );
  17881. addUV( uvs[ 3 ] );
  17882. addUV( uvs[ 1 ] );
  17883. addUV( uvs[ 2 ] );
  17884. addUV( uvs[ 3 ] );
  17885. }
  17886. function addVertex( index ) {
  17887. verticesArray.push( placeholder[ index * 3 + 0 ] );
  17888. verticesArray.push( placeholder[ index * 3 + 1 ] );
  17889. verticesArray.push( placeholder[ index * 3 + 2 ] );
  17890. }
  17891. function addUV( vector2 ) {
  17892. uvArray.push( vector2.x );
  17893. uvArray.push( vector2.y );
  17894. }
  17895. }
  17896. }
  17897. ExtrudeBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  17898. ExtrudeBufferGeometry.prototype.constructor = ExtrudeBufferGeometry;
  17899. ExtrudeBufferGeometry.prototype.toJSON = function () {
  17900. var data = BufferGeometry.prototype.toJSON.call( this );
  17901. var shapes = this.parameters.shapes;
  17902. var options = this.parameters.options;
  17903. return toJSON( shapes, options, data );
  17904. };
  17905. //
  17906. var WorldUVGenerator = {
  17907. generateTopUV: function ( geometry, vertices, indexA, indexB, indexC ) {
  17908. var a_x = vertices[ indexA * 3 ];
  17909. var a_y = vertices[ indexA * 3 + 1 ];
  17910. var b_x = vertices[ indexB * 3 ];
  17911. var b_y = vertices[ indexB * 3 + 1 ];
  17912. var c_x = vertices[ indexC * 3 ];
  17913. var c_y = vertices[ indexC * 3 + 1 ];
  17914. return [
  17915. new Vector2( a_x, a_y ),
  17916. new Vector2( b_x, b_y ),
  17917. new Vector2( c_x, c_y )
  17918. ];
  17919. },
  17920. generateSideWallUV: function ( geometry, vertices, indexA, indexB, indexC, indexD ) {
  17921. var a_x = vertices[ indexA * 3 ];
  17922. var a_y = vertices[ indexA * 3 + 1 ];
  17923. var a_z = vertices[ indexA * 3 + 2 ];
  17924. var b_x = vertices[ indexB * 3 ];
  17925. var b_y = vertices[ indexB * 3 + 1 ];
  17926. var b_z = vertices[ indexB * 3 + 2 ];
  17927. var c_x = vertices[ indexC * 3 ];
  17928. var c_y = vertices[ indexC * 3 + 1 ];
  17929. var c_z = vertices[ indexC * 3 + 2 ];
  17930. var d_x = vertices[ indexD * 3 ];
  17931. var d_y = vertices[ indexD * 3 + 1 ];
  17932. var d_z = vertices[ indexD * 3 + 2 ];
  17933. if ( Math.abs( a_y - b_y ) < 0.01 ) {
  17934. return [
  17935. new Vector2( a_x, 1 - a_z ),
  17936. new Vector2( b_x, 1 - b_z ),
  17937. new Vector2( c_x, 1 - c_z ),
  17938. new Vector2( d_x, 1 - d_z )
  17939. ];
  17940. } else {
  17941. return [
  17942. new Vector2( a_y, 1 - a_z ),
  17943. new Vector2( b_y, 1 - b_z ),
  17944. new Vector2( c_y, 1 - c_z ),
  17945. new Vector2( d_y, 1 - d_z )
  17946. ];
  17947. }
  17948. }
  17949. };
  17950. function toJSON( shapes, options, data ) {
  17951. //
  17952. data.shapes = [];
  17953. if ( Array.isArray( shapes ) ) {
  17954. for ( var i = 0, l = shapes.length; i < l; i ++ ) {
  17955. var shape = shapes[ i ];
  17956. data.shapes.push( shape.uuid );
  17957. }
  17958. } else {
  17959. data.shapes.push( shapes.uuid );
  17960. }
  17961. //
  17962. if ( options.extrudePath !== undefined ) data.options.extrudePath = options.extrudePath.toJSON();
  17963. return data;
  17964. }
  17965. /**
  17966. * @author zz85 / http://www.lab4games.net/zz85/blog
  17967. * @author alteredq / http://alteredqualia.com/
  17968. *
  17969. * Text = 3D Text
  17970. *
  17971. * parameters = {
  17972. * font: <THREE.Font>, // font
  17973. *
  17974. * size: <float>, // size of the text
  17975. * height: <float>, // thickness to extrude text
  17976. * curveSegments: <int>, // number of points on the curves
  17977. *
  17978. * bevelEnabled: <bool>, // turn on bevel
  17979. * bevelThickness: <float>, // how deep into text bevel goes
  17980. * bevelSize: <float>, // how far from text outline (including bevelOffset) is bevel
  17981. * bevelOffset: <float> // how far from text outline does bevel start
  17982. * }
  17983. */
  17984. // TextGeometry
  17985. function TextGeometry( text, parameters ) {
  17986. Geometry.call( this );
  17987. this.type = 'TextGeometry';
  17988. this.parameters = {
  17989. text: text,
  17990. parameters: parameters
  17991. };
  17992. this.fromBufferGeometry( new TextBufferGeometry( text, parameters ) );
  17993. this.mergeVertices();
  17994. }
  17995. TextGeometry.prototype = Object.create( Geometry.prototype );
  17996. TextGeometry.prototype.constructor = TextGeometry;
  17997. // TextBufferGeometry
  17998. function TextBufferGeometry( text, parameters ) {
  17999. parameters = parameters || {};
  18000. var font = parameters.font;
  18001. if ( ! ( font && font.isFont ) ) {
  18002. console.error( 'THREE.TextGeometry: font parameter is not an instance of THREE.Font.' );
  18003. return new Geometry();
  18004. }
  18005. var shapes = font.generateShapes( text, parameters.size );
  18006. // translate parameters to ExtrudeGeometry API
  18007. parameters.depth = parameters.height !== undefined ? parameters.height : 50;
  18008. // defaults
  18009. if ( parameters.bevelThickness === undefined ) parameters.bevelThickness = 10;
  18010. if ( parameters.bevelSize === undefined ) parameters.bevelSize = 8;
  18011. if ( parameters.bevelEnabled === undefined ) parameters.bevelEnabled = false;
  18012. ExtrudeBufferGeometry.call( this, shapes, parameters );
  18013. this.type = 'TextBufferGeometry';
  18014. }
  18015. TextBufferGeometry.prototype = Object.create( ExtrudeBufferGeometry.prototype );
  18016. TextBufferGeometry.prototype.constructor = TextBufferGeometry;
  18017. /**
  18018. * @author mrdoob / http://mrdoob.com/
  18019. * @author benaadams / https://twitter.com/ben_a_adams
  18020. * @author Mugen87 / https://github.com/Mugen87
  18021. */
  18022. // SphereGeometry
  18023. function SphereGeometry( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) {
  18024. Geometry.call( this );
  18025. this.type = 'SphereGeometry';
  18026. this.parameters = {
  18027. radius: radius,
  18028. widthSegments: widthSegments,
  18029. heightSegments: heightSegments,
  18030. phiStart: phiStart,
  18031. phiLength: phiLength,
  18032. thetaStart: thetaStart,
  18033. thetaLength: thetaLength
  18034. };
  18035. this.fromBufferGeometry( new SphereBufferGeometry( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) );
  18036. this.mergeVertices();
  18037. }
  18038. SphereGeometry.prototype = Object.create( Geometry.prototype );
  18039. SphereGeometry.prototype.constructor = SphereGeometry;
  18040. // SphereBufferGeometry
  18041. function SphereBufferGeometry( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) {
  18042. BufferGeometry.call( this );
  18043. this.type = 'SphereBufferGeometry';
  18044. this.parameters = {
  18045. radius: radius,
  18046. widthSegments: widthSegments,
  18047. heightSegments: heightSegments,
  18048. phiStart: phiStart,
  18049. phiLength: phiLength,
  18050. thetaStart: thetaStart,
  18051. thetaLength: thetaLength
  18052. };
  18053. radius = radius || 1;
  18054. widthSegments = Math.max( 3, Math.floor( widthSegments ) || 8 );
  18055. heightSegments = Math.max( 2, Math.floor( heightSegments ) || 6 );
  18056. phiStart = phiStart !== undefined ? phiStart : 0;
  18057. phiLength = phiLength !== undefined ? phiLength : Math.PI * 2;
  18058. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  18059. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI;
  18060. var thetaEnd = Math.min( thetaStart + thetaLength, Math.PI );
  18061. var ix, iy;
  18062. var index = 0;
  18063. var grid = [];
  18064. var vertex = new Vector3();
  18065. var normal = new Vector3();
  18066. // buffers
  18067. var indices = [];
  18068. var vertices = [];
  18069. var normals = [];
  18070. var uvs = [];
  18071. // generate vertices, normals and uvs
  18072. for ( iy = 0; iy <= heightSegments; iy ++ ) {
  18073. var verticesRow = [];
  18074. var v = iy / heightSegments;
  18075. // special case for the poles
  18076. var uOffset = 0;
  18077. if ( iy == 0 && thetaStart == 0 ) {
  18078. uOffset = 0.5 / widthSegments;
  18079. } else if ( iy == heightSegments && thetaEnd == Math.PI ) {
  18080. uOffset = - 0.5 / widthSegments;
  18081. }
  18082. for ( ix = 0; ix <= widthSegments; ix ++ ) {
  18083. var u = ix / widthSegments;
  18084. // vertex
  18085. vertex.x = - radius * Math.cos( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  18086. vertex.y = radius * Math.cos( thetaStart + v * thetaLength );
  18087. vertex.z = radius * Math.sin( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  18088. vertices.push( vertex.x, vertex.y, vertex.z );
  18089. // normal
  18090. normal.copy( vertex ).normalize();
  18091. normals.push( normal.x, normal.y, normal.z );
  18092. // uv
  18093. uvs.push( u + uOffset, 1 - v );
  18094. verticesRow.push( index ++ );
  18095. }
  18096. grid.push( verticesRow );
  18097. }
  18098. // indices
  18099. for ( iy = 0; iy < heightSegments; iy ++ ) {
  18100. for ( ix = 0; ix < widthSegments; ix ++ ) {
  18101. var a = grid[ iy ][ ix + 1 ];
  18102. var b = grid[ iy ][ ix ];
  18103. var c = grid[ iy + 1 ][ ix ];
  18104. var d = grid[ iy + 1 ][ ix + 1 ];
  18105. if ( iy !== 0 || thetaStart > 0 ) indices.push( a, b, d );
  18106. if ( iy !== heightSegments - 1 || thetaEnd < Math.PI ) indices.push( b, c, d );
  18107. }
  18108. }
  18109. // build geometry
  18110. this.setIndex( indices );
  18111. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  18112. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  18113. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  18114. }
  18115. SphereBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  18116. SphereBufferGeometry.prototype.constructor = SphereBufferGeometry;
  18117. /**
  18118. * @author Kaleb Murphy
  18119. * @author Mugen87 / https://github.com/Mugen87
  18120. */
  18121. // RingGeometry
  18122. function RingGeometry( innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength ) {
  18123. Geometry.call( this );
  18124. this.type = 'RingGeometry';
  18125. this.parameters = {
  18126. innerRadius: innerRadius,
  18127. outerRadius: outerRadius,
  18128. thetaSegments: thetaSegments,
  18129. phiSegments: phiSegments,
  18130. thetaStart: thetaStart,
  18131. thetaLength: thetaLength
  18132. };
  18133. this.fromBufferGeometry( new RingBufferGeometry( innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength ) );
  18134. this.mergeVertices();
  18135. }
  18136. RingGeometry.prototype = Object.create( Geometry.prototype );
  18137. RingGeometry.prototype.constructor = RingGeometry;
  18138. // RingBufferGeometry
  18139. function RingBufferGeometry( innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength ) {
  18140. BufferGeometry.call( this );
  18141. this.type = 'RingBufferGeometry';
  18142. this.parameters = {
  18143. innerRadius: innerRadius,
  18144. outerRadius: outerRadius,
  18145. thetaSegments: thetaSegments,
  18146. phiSegments: phiSegments,
  18147. thetaStart: thetaStart,
  18148. thetaLength: thetaLength
  18149. };
  18150. innerRadius = innerRadius || 0.5;
  18151. outerRadius = outerRadius || 1;
  18152. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  18153. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  18154. thetaSegments = thetaSegments !== undefined ? Math.max( 3, thetaSegments ) : 8;
  18155. phiSegments = phiSegments !== undefined ? Math.max( 1, phiSegments ) : 1;
  18156. // buffers
  18157. var indices = [];
  18158. var vertices = [];
  18159. var normals = [];
  18160. var uvs = [];
  18161. // some helper variables
  18162. var segment;
  18163. var radius = innerRadius;
  18164. var radiusStep = ( ( outerRadius - innerRadius ) / phiSegments );
  18165. var vertex = new Vector3();
  18166. var uv = new Vector2();
  18167. var j, i;
  18168. // generate vertices, normals and uvs
  18169. for ( j = 0; j <= phiSegments; j ++ ) {
  18170. for ( i = 0; i <= thetaSegments; i ++ ) {
  18171. // values are generate from the inside of the ring to the outside
  18172. segment = thetaStart + i / thetaSegments * thetaLength;
  18173. // vertex
  18174. vertex.x = radius * Math.cos( segment );
  18175. vertex.y = radius * Math.sin( segment );
  18176. vertices.push( vertex.x, vertex.y, vertex.z );
  18177. // normal
  18178. normals.push( 0, 0, 1 );
  18179. // uv
  18180. uv.x = ( vertex.x / outerRadius + 1 ) / 2;
  18181. uv.y = ( vertex.y / outerRadius + 1 ) / 2;
  18182. uvs.push( uv.x, uv.y );
  18183. }
  18184. // increase the radius for next row of vertices
  18185. radius += radiusStep;
  18186. }
  18187. // indices
  18188. for ( j = 0; j < phiSegments; j ++ ) {
  18189. var thetaSegmentLevel = j * ( thetaSegments + 1 );
  18190. for ( i = 0; i < thetaSegments; i ++ ) {
  18191. segment = i + thetaSegmentLevel;
  18192. var a = segment;
  18193. var b = segment + thetaSegments + 1;
  18194. var c = segment + thetaSegments + 2;
  18195. var d = segment + 1;
  18196. // faces
  18197. indices.push( a, b, d );
  18198. indices.push( b, c, d );
  18199. }
  18200. }
  18201. // build geometry
  18202. this.setIndex( indices );
  18203. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  18204. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  18205. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  18206. }
  18207. RingBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  18208. RingBufferGeometry.prototype.constructor = RingBufferGeometry;
  18209. /**
  18210. * @author zz85 / https://github.com/zz85
  18211. * @author bhouston / http://clara.io
  18212. * @author Mugen87 / https://github.com/Mugen87
  18213. */
  18214. // LatheGeometry
  18215. function LatheGeometry( points, segments, phiStart, phiLength ) {
  18216. Geometry.call( this );
  18217. this.type = 'LatheGeometry';
  18218. this.parameters = {
  18219. points: points,
  18220. segments: segments,
  18221. phiStart: phiStart,
  18222. phiLength: phiLength
  18223. };
  18224. this.fromBufferGeometry( new LatheBufferGeometry( points, segments, phiStart, phiLength ) );
  18225. this.mergeVertices();
  18226. }
  18227. LatheGeometry.prototype = Object.create( Geometry.prototype );
  18228. LatheGeometry.prototype.constructor = LatheGeometry;
  18229. // LatheBufferGeometry
  18230. function LatheBufferGeometry( points, segments, phiStart, phiLength ) {
  18231. BufferGeometry.call( this );
  18232. this.type = 'LatheBufferGeometry';
  18233. this.parameters = {
  18234. points: points,
  18235. segments: segments,
  18236. phiStart: phiStart,
  18237. phiLength: phiLength
  18238. };
  18239. segments = Math.floor( segments ) || 12;
  18240. phiStart = phiStart || 0;
  18241. phiLength = phiLength || Math.PI * 2;
  18242. // clamp phiLength so it's in range of [ 0, 2PI ]
  18243. phiLength = _Math.clamp( phiLength, 0, Math.PI * 2 );
  18244. // buffers
  18245. var indices = [];
  18246. var vertices = [];
  18247. var uvs = [];
  18248. // helper variables
  18249. var base;
  18250. var inverseSegments = 1.0 / segments;
  18251. var vertex = new Vector3();
  18252. var uv = new Vector2();
  18253. var i, j;
  18254. // generate vertices and uvs
  18255. for ( i = 0; i <= segments; i ++ ) {
  18256. var phi = phiStart + i * inverseSegments * phiLength;
  18257. var sin = Math.sin( phi );
  18258. var cos = Math.cos( phi );
  18259. for ( j = 0; j <= ( points.length - 1 ); j ++ ) {
  18260. // vertex
  18261. vertex.x = points[ j ].x * sin;
  18262. vertex.y = points[ j ].y;
  18263. vertex.z = points[ j ].x * cos;
  18264. vertices.push( vertex.x, vertex.y, vertex.z );
  18265. // uv
  18266. uv.x = i / segments;
  18267. uv.y = j / ( points.length - 1 );
  18268. uvs.push( uv.x, uv.y );
  18269. }
  18270. }
  18271. // indices
  18272. for ( i = 0; i < segments; i ++ ) {
  18273. for ( j = 0; j < ( points.length - 1 ); j ++ ) {
  18274. base = j + i * points.length;
  18275. var a = base;
  18276. var b = base + points.length;
  18277. var c = base + points.length + 1;
  18278. var d = base + 1;
  18279. // faces
  18280. indices.push( a, b, d );
  18281. indices.push( b, c, d );
  18282. }
  18283. }
  18284. // build geometry
  18285. this.setIndex( indices );
  18286. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  18287. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  18288. // generate normals
  18289. this.computeVertexNormals();
  18290. // if the geometry is closed, we need to average the normals along the seam.
  18291. // because the corresponding vertices are identical (but still have different UVs).
  18292. if ( phiLength === Math.PI * 2 ) {
  18293. var normals = this.attributes.normal.array;
  18294. var n1 = new Vector3();
  18295. var n2 = new Vector3();
  18296. var n = new Vector3();
  18297. // this is the buffer offset for the last line of vertices
  18298. base = segments * points.length * 3;
  18299. for ( i = 0, j = 0; i < points.length; i ++, j += 3 ) {
  18300. // select the normal of the vertex in the first line
  18301. n1.x = normals[ j + 0 ];
  18302. n1.y = normals[ j + 1 ];
  18303. n1.z = normals[ j + 2 ];
  18304. // select the normal of the vertex in the last line
  18305. n2.x = normals[ base + j + 0 ];
  18306. n2.y = normals[ base + j + 1 ];
  18307. n2.z = normals[ base + j + 2 ];
  18308. // average normals
  18309. n.addVectors( n1, n2 ).normalize();
  18310. // assign the new values to both normals
  18311. normals[ j + 0 ] = normals[ base + j + 0 ] = n.x;
  18312. normals[ j + 1 ] = normals[ base + j + 1 ] = n.y;
  18313. normals[ j + 2 ] = normals[ base + j + 2 ] = n.z;
  18314. }
  18315. }
  18316. }
  18317. LatheBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  18318. LatheBufferGeometry.prototype.constructor = LatheBufferGeometry;
  18319. /**
  18320. * @author jonobr1 / http://jonobr1.com
  18321. * @author Mugen87 / https://github.com/Mugen87
  18322. */
  18323. // ShapeGeometry
  18324. function ShapeGeometry( shapes, curveSegments ) {
  18325. Geometry.call( this );
  18326. this.type = 'ShapeGeometry';
  18327. if ( typeof curveSegments === 'object' ) {
  18328. console.warn( 'THREE.ShapeGeometry: Options parameter has been removed.' );
  18329. curveSegments = curveSegments.curveSegments;
  18330. }
  18331. this.parameters = {
  18332. shapes: shapes,
  18333. curveSegments: curveSegments
  18334. };
  18335. this.fromBufferGeometry( new ShapeBufferGeometry( shapes, curveSegments ) );
  18336. this.mergeVertices();
  18337. }
  18338. ShapeGeometry.prototype = Object.create( Geometry.prototype );
  18339. ShapeGeometry.prototype.constructor = ShapeGeometry;
  18340. ShapeGeometry.prototype.toJSON = function () {
  18341. var data = Geometry.prototype.toJSON.call( this );
  18342. var shapes = this.parameters.shapes;
  18343. return toJSON$1( shapes, data );
  18344. };
  18345. // ShapeBufferGeometry
  18346. function ShapeBufferGeometry( shapes, curveSegments ) {
  18347. BufferGeometry.call( this );
  18348. this.type = 'ShapeBufferGeometry';
  18349. this.parameters = {
  18350. shapes: shapes,
  18351. curveSegments: curveSegments
  18352. };
  18353. curveSegments = curveSegments || 12;
  18354. // buffers
  18355. var indices = [];
  18356. var vertices = [];
  18357. var normals = [];
  18358. var uvs = [];
  18359. // helper variables
  18360. var groupStart = 0;
  18361. var groupCount = 0;
  18362. // allow single and array values for "shapes" parameter
  18363. if ( Array.isArray( shapes ) === false ) {
  18364. addShape( shapes );
  18365. } else {
  18366. for ( var i = 0; i < shapes.length; i ++ ) {
  18367. addShape( shapes[ i ] );
  18368. this.addGroup( groupStart, groupCount, i ); // enables MultiMaterial support
  18369. groupStart += groupCount;
  18370. groupCount = 0;
  18371. }
  18372. }
  18373. // build geometry
  18374. this.setIndex( indices );
  18375. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  18376. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  18377. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  18378. // helper functions
  18379. function addShape( shape ) {
  18380. var i, l, shapeHole;
  18381. var indexOffset = vertices.length / 3;
  18382. var points = shape.extractPoints( curveSegments );
  18383. var shapeVertices = points.shape;
  18384. var shapeHoles = points.holes;
  18385. // check direction of vertices
  18386. if ( ShapeUtils.isClockWise( shapeVertices ) === false ) {
  18387. shapeVertices = shapeVertices.reverse();
  18388. }
  18389. for ( i = 0, l = shapeHoles.length; i < l; i ++ ) {
  18390. shapeHole = shapeHoles[ i ];
  18391. if ( ShapeUtils.isClockWise( shapeHole ) === true ) {
  18392. shapeHoles[ i ] = shapeHole.reverse();
  18393. }
  18394. }
  18395. var faces = ShapeUtils.triangulateShape( shapeVertices, shapeHoles );
  18396. // join vertices of inner and outer paths to a single array
  18397. for ( i = 0, l = shapeHoles.length; i < l; i ++ ) {
  18398. shapeHole = shapeHoles[ i ];
  18399. shapeVertices = shapeVertices.concat( shapeHole );
  18400. }
  18401. // vertices, normals, uvs
  18402. for ( i = 0, l = shapeVertices.length; i < l; i ++ ) {
  18403. var vertex = shapeVertices[ i ];
  18404. vertices.push( vertex.x, vertex.y, 0 );
  18405. normals.push( 0, 0, 1 );
  18406. uvs.push( vertex.x, vertex.y ); // world uvs
  18407. }
  18408. // incides
  18409. for ( i = 0, l = faces.length; i < l; i ++ ) {
  18410. var face = faces[ i ];
  18411. var a = face[ 0 ] + indexOffset;
  18412. var b = face[ 1 ] + indexOffset;
  18413. var c = face[ 2 ] + indexOffset;
  18414. indices.push( a, b, c );
  18415. groupCount += 3;
  18416. }
  18417. }
  18418. }
  18419. ShapeBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  18420. ShapeBufferGeometry.prototype.constructor = ShapeBufferGeometry;
  18421. ShapeBufferGeometry.prototype.toJSON = function () {
  18422. var data = BufferGeometry.prototype.toJSON.call( this );
  18423. var shapes = this.parameters.shapes;
  18424. return toJSON$1( shapes, data );
  18425. };
  18426. //
  18427. function toJSON$1( shapes, data ) {
  18428. data.shapes = [];
  18429. if ( Array.isArray( shapes ) ) {
  18430. for ( var i = 0, l = shapes.length; i < l; i ++ ) {
  18431. var shape = shapes[ i ];
  18432. data.shapes.push( shape.uuid );
  18433. }
  18434. } else {
  18435. data.shapes.push( shapes.uuid );
  18436. }
  18437. return data;
  18438. }
  18439. /**
  18440. * @author WestLangley / http://github.com/WestLangley
  18441. * @author Mugen87 / https://github.com/Mugen87
  18442. */
  18443. function EdgesGeometry( geometry, thresholdAngle ) {
  18444. BufferGeometry.call( this );
  18445. this.type = 'EdgesGeometry';
  18446. this.parameters = {
  18447. thresholdAngle: thresholdAngle
  18448. };
  18449. thresholdAngle = ( thresholdAngle !== undefined ) ? thresholdAngle : 1;
  18450. // buffer
  18451. var vertices = [];
  18452. // helper variables
  18453. var thresholdDot = Math.cos( _Math.DEG2RAD * thresholdAngle );
  18454. var edge = [ 0, 0 ], edges = {}, edge1, edge2;
  18455. var key, keys = [ 'a', 'b', 'c' ];
  18456. // prepare source geometry
  18457. var geometry2;
  18458. if ( geometry.isBufferGeometry ) {
  18459. geometry2 = new Geometry();
  18460. geometry2.fromBufferGeometry( geometry );
  18461. } else {
  18462. geometry2 = geometry.clone();
  18463. }
  18464. geometry2.mergeVertices();
  18465. geometry2.computeFaceNormals();
  18466. var sourceVertices = geometry2.vertices;
  18467. var faces = geometry2.faces;
  18468. // now create a data structure where each entry represents an edge with its adjoining faces
  18469. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  18470. var face = faces[ i ];
  18471. for ( var j = 0; j < 3; j ++ ) {
  18472. edge1 = face[ keys[ j ] ];
  18473. edge2 = face[ keys[ ( j + 1 ) % 3 ] ];
  18474. edge[ 0 ] = Math.min( edge1, edge2 );
  18475. edge[ 1 ] = Math.max( edge1, edge2 );
  18476. key = edge[ 0 ] + ',' + edge[ 1 ];
  18477. if ( edges[ key ] === undefined ) {
  18478. edges[ key ] = { index1: edge[ 0 ], index2: edge[ 1 ], face1: i, face2: undefined };
  18479. } else {
  18480. edges[ key ].face2 = i;
  18481. }
  18482. }
  18483. }
  18484. // generate vertices
  18485. for ( key in edges ) {
  18486. var e = edges[ key ];
  18487. // an edge is only rendered if the angle (in degrees) between the face normals of the adjoining faces exceeds this value. default = 1 degree.
  18488. if ( e.face2 === undefined || faces[ e.face1 ].normal.dot( faces[ e.face2 ].normal ) <= thresholdDot ) {
  18489. var vertex = sourceVertices[ e.index1 ];
  18490. vertices.push( vertex.x, vertex.y, vertex.z );
  18491. vertex = sourceVertices[ e.index2 ];
  18492. vertices.push( vertex.x, vertex.y, vertex.z );
  18493. }
  18494. }
  18495. // build geometry
  18496. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  18497. }
  18498. EdgesGeometry.prototype = Object.create( BufferGeometry.prototype );
  18499. EdgesGeometry.prototype.constructor = EdgesGeometry;
  18500. /**
  18501. * @author mrdoob / http://mrdoob.com/
  18502. * @author Mugen87 / https://github.com/Mugen87
  18503. */
  18504. // CylinderGeometry
  18505. function CylinderGeometry( radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  18506. Geometry.call( this );
  18507. this.type = 'CylinderGeometry';
  18508. this.parameters = {
  18509. radiusTop: radiusTop,
  18510. radiusBottom: radiusBottom,
  18511. height: height,
  18512. radialSegments: radialSegments,
  18513. heightSegments: heightSegments,
  18514. openEnded: openEnded,
  18515. thetaStart: thetaStart,
  18516. thetaLength: thetaLength
  18517. };
  18518. this.fromBufferGeometry( new CylinderBufferGeometry( radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) );
  18519. this.mergeVertices();
  18520. }
  18521. CylinderGeometry.prototype = Object.create( Geometry.prototype );
  18522. CylinderGeometry.prototype.constructor = CylinderGeometry;
  18523. // CylinderBufferGeometry
  18524. function CylinderBufferGeometry( radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  18525. BufferGeometry.call( this );
  18526. this.type = 'CylinderBufferGeometry';
  18527. this.parameters = {
  18528. radiusTop: radiusTop,
  18529. radiusBottom: radiusBottom,
  18530. height: height,
  18531. radialSegments: radialSegments,
  18532. heightSegments: heightSegments,
  18533. openEnded: openEnded,
  18534. thetaStart: thetaStart,
  18535. thetaLength: thetaLength
  18536. };
  18537. var scope = this;
  18538. radiusTop = radiusTop !== undefined ? radiusTop : 1;
  18539. radiusBottom = radiusBottom !== undefined ? radiusBottom : 1;
  18540. height = height || 1;
  18541. radialSegments = Math.floor( radialSegments ) || 8;
  18542. heightSegments = Math.floor( heightSegments ) || 1;
  18543. openEnded = openEnded !== undefined ? openEnded : false;
  18544. thetaStart = thetaStart !== undefined ? thetaStart : 0.0;
  18545. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  18546. // buffers
  18547. var indices = [];
  18548. var vertices = [];
  18549. var normals = [];
  18550. var uvs = [];
  18551. // helper variables
  18552. var index = 0;
  18553. var indexArray = [];
  18554. var halfHeight = height / 2;
  18555. var groupStart = 0;
  18556. // generate geometry
  18557. generateTorso();
  18558. if ( openEnded === false ) {
  18559. if ( radiusTop > 0 ) generateCap( true );
  18560. if ( radiusBottom > 0 ) generateCap( false );
  18561. }
  18562. // build geometry
  18563. this.setIndex( indices );
  18564. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  18565. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  18566. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  18567. function generateTorso() {
  18568. var x, y;
  18569. var normal = new Vector3();
  18570. var vertex = new Vector3();
  18571. var groupCount = 0;
  18572. // this will be used to calculate the normal
  18573. var slope = ( radiusBottom - radiusTop ) / height;
  18574. // generate vertices, normals and uvs
  18575. for ( y = 0; y <= heightSegments; y ++ ) {
  18576. var indexRow = [];
  18577. var v = y / heightSegments;
  18578. // calculate the radius of the current row
  18579. var radius = v * ( radiusBottom - radiusTop ) + radiusTop;
  18580. for ( x = 0; x <= radialSegments; x ++ ) {
  18581. var u = x / radialSegments;
  18582. var theta = u * thetaLength + thetaStart;
  18583. var sinTheta = Math.sin( theta );
  18584. var cosTheta = Math.cos( theta );
  18585. // vertex
  18586. vertex.x = radius * sinTheta;
  18587. vertex.y = - v * height + halfHeight;
  18588. vertex.z = radius * cosTheta;
  18589. vertices.push( vertex.x, vertex.y, vertex.z );
  18590. // normal
  18591. normal.set( sinTheta, slope, cosTheta ).normalize();
  18592. normals.push( normal.x, normal.y, normal.z );
  18593. // uv
  18594. uvs.push( u, 1 - v );
  18595. // save index of vertex in respective row
  18596. indexRow.push( index ++ );
  18597. }
  18598. // now save vertices of the row in our index array
  18599. indexArray.push( indexRow );
  18600. }
  18601. // generate indices
  18602. for ( x = 0; x < radialSegments; x ++ ) {
  18603. for ( y = 0; y < heightSegments; y ++ ) {
  18604. // we use the index array to access the correct indices
  18605. var a = indexArray[ y ][ x ];
  18606. var b = indexArray[ y + 1 ][ x ];
  18607. var c = indexArray[ y + 1 ][ x + 1 ];
  18608. var d = indexArray[ y ][ x + 1 ];
  18609. // faces
  18610. indices.push( a, b, d );
  18611. indices.push( b, c, d );
  18612. // update group counter
  18613. groupCount += 6;
  18614. }
  18615. }
  18616. // add a group to the geometry. this will ensure multi material support
  18617. scope.addGroup( groupStart, groupCount, 0 );
  18618. // calculate new start value for groups
  18619. groupStart += groupCount;
  18620. }
  18621. function generateCap( top ) {
  18622. var x, centerIndexStart, centerIndexEnd;
  18623. var uv = new Vector2();
  18624. var vertex = new Vector3();
  18625. var groupCount = 0;
  18626. var radius = ( top === true ) ? radiusTop : radiusBottom;
  18627. var sign = ( top === true ) ? 1 : - 1;
  18628. // save the index of the first center vertex
  18629. centerIndexStart = index;
  18630. // first we generate the center vertex data of the cap.
  18631. // because the geometry needs one set of uvs per face,
  18632. // we must generate a center vertex per face/segment
  18633. for ( x = 1; x <= radialSegments; x ++ ) {
  18634. // vertex
  18635. vertices.push( 0, halfHeight * sign, 0 );
  18636. // normal
  18637. normals.push( 0, sign, 0 );
  18638. // uv
  18639. uvs.push( 0.5, 0.5 );
  18640. // increase index
  18641. index ++;
  18642. }
  18643. // save the index of the last center vertex
  18644. centerIndexEnd = index;
  18645. // now we generate the surrounding vertices, normals and uvs
  18646. for ( x = 0; x <= radialSegments; x ++ ) {
  18647. var u = x / radialSegments;
  18648. var theta = u * thetaLength + thetaStart;
  18649. var cosTheta = Math.cos( theta );
  18650. var sinTheta = Math.sin( theta );
  18651. // vertex
  18652. vertex.x = radius * sinTheta;
  18653. vertex.y = halfHeight * sign;
  18654. vertex.z = radius * cosTheta;
  18655. vertices.push( vertex.x, vertex.y, vertex.z );
  18656. // normal
  18657. normals.push( 0, sign, 0 );
  18658. // uv
  18659. uv.x = ( cosTheta * 0.5 ) + 0.5;
  18660. uv.y = ( sinTheta * 0.5 * sign ) + 0.5;
  18661. uvs.push( uv.x, uv.y );
  18662. // increase index
  18663. index ++;
  18664. }
  18665. // generate indices
  18666. for ( x = 0; x < radialSegments; x ++ ) {
  18667. var c = centerIndexStart + x;
  18668. var i = centerIndexEnd + x;
  18669. if ( top === true ) {
  18670. // face top
  18671. indices.push( i, i + 1, c );
  18672. } else {
  18673. // face bottom
  18674. indices.push( i + 1, i, c );
  18675. }
  18676. groupCount += 3;
  18677. }
  18678. // add a group to the geometry. this will ensure multi material support
  18679. scope.addGroup( groupStart, groupCount, top === true ? 1 : 2 );
  18680. // calculate new start value for groups
  18681. groupStart += groupCount;
  18682. }
  18683. }
  18684. CylinderBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  18685. CylinderBufferGeometry.prototype.constructor = CylinderBufferGeometry;
  18686. /**
  18687. * @author abelnation / http://github.com/abelnation
  18688. */
  18689. // ConeGeometry
  18690. function ConeGeometry( radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  18691. CylinderGeometry.call( this, 0, radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength );
  18692. this.type = 'ConeGeometry';
  18693. this.parameters = {
  18694. radius: radius,
  18695. height: height,
  18696. radialSegments: radialSegments,
  18697. heightSegments: heightSegments,
  18698. openEnded: openEnded,
  18699. thetaStart: thetaStart,
  18700. thetaLength: thetaLength
  18701. };
  18702. }
  18703. ConeGeometry.prototype = Object.create( CylinderGeometry.prototype );
  18704. ConeGeometry.prototype.constructor = ConeGeometry;
  18705. // ConeBufferGeometry
  18706. function ConeBufferGeometry( radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  18707. CylinderBufferGeometry.call( this, 0, radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength );
  18708. this.type = 'ConeBufferGeometry';
  18709. this.parameters = {
  18710. radius: radius,
  18711. height: height,
  18712. radialSegments: radialSegments,
  18713. heightSegments: heightSegments,
  18714. openEnded: openEnded,
  18715. thetaStart: thetaStart,
  18716. thetaLength: thetaLength
  18717. };
  18718. }
  18719. ConeBufferGeometry.prototype = Object.create( CylinderBufferGeometry.prototype );
  18720. ConeBufferGeometry.prototype.constructor = ConeBufferGeometry;
  18721. /**
  18722. * @author benaadams / https://twitter.com/ben_a_adams
  18723. * @author Mugen87 / https://github.com/Mugen87
  18724. * @author hughes
  18725. */
  18726. // CircleGeometry
  18727. function CircleGeometry( radius, segments, thetaStart, thetaLength ) {
  18728. Geometry.call( this );
  18729. this.type = 'CircleGeometry';
  18730. this.parameters = {
  18731. radius: radius,
  18732. segments: segments,
  18733. thetaStart: thetaStart,
  18734. thetaLength: thetaLength
  18735. };
  18736. this.fromBufferGeometry( new CircleBufferGeometry( radius, segments, thetaStart, thetaLength ) );
  18737. this.mergeVertices();
  18738. }
  18739. CircleGeometry.prototype = Object.create( Geometry.prototype );
  18740. CircleGeometry.prototype.constructor = CircleGeometry;
  18741. // CircleBufferGeometry
  18742. function CircleBufferGeometry( radius, segments, thetaStart, thetaLength ) {
  18743. BufferGeometry.call( this );
  18744. this.type = 'CircleBufferGeometry';
  18745. this.parameters = {
  18746. radius: radius,
  18747. segments: segments,
  18748. thetaStart: thetaStart,
  18749. thetaLength: thetaLength
  18750. };
  18751. radius = radius || 1;
  18752. segments = segments !== undefined ? Math.max( 3, segments ) : 8;
  18753. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  18754. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  18755. // buffers
  18756. var indices = [];
  18757. var vertices = [];
  18758. var normals = [];
  18759. var uvs = [];
  18760. // helper variables
  18761. var i, s;
  18762. var vertex = new Vector3();
  18763. var uv = new Vector2();
  18764. // center point
  18765. vertices.push( 0, 0, 0 );
  18766. normals.push( 0, 0, 1 );
  18767. uvs.push( 0.5, 0.5 );
  18768. for ( s = 0, i = 3; s <= segments; s ++, i += 3 ) {
  18769. var segment = thetaStart + s / segments * thetaLength;
  18770. // vertex
  18771. vertex.x = radius * Math.cos( segment );
  18772. vertex.y = radius * Math.sin( segment );
  18773. vertices.push( vertex.x, vertex.y, vertex.z );
  18774. // normal
  18775. normals.push( 0, 0, 1 );
  18776. // uvs
  18777. uv.x = ( vertices[ i ] / radius + 1 ) / 2;
  18778. uv.y = ( vertices[ i + 1 ] / radius + 1 ) / 2;
  18779. uvs.push( uv.x, uv.y );
  18780. }
  18781. // indices
  18782. for ( i = 1; i <= segments; i ++ ) {
  18783. indices.push( i, i + 1, 0 );
  18784. }
  18785. // build geometry
  18786. this.setIndex( indices );
  18787. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  18788. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  18789. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  18790. }
  18791. CircleBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  18792. CircleBufferGeometry.prototype.constructor = CircleBufferGeometry;
  18793. var Geometries = /*#__PURE__*/Object.freeze({
  18794. WireframeGeometry: WireframeGeometry,
  18795. ParametricGeometry: ParametricGeometry,
  18796. ParametricBufferGeometry: ParametricBufferGeometry,
  18797. TetrahedronGeometry: TetrahedronGeometry,
  18798. TetrahedronBufferGeometry: TetrahedronBufferGeometry,
  18799. OctahedronGeometry: OctahedronGeometry,
  18800. OctahedronBufferGeometry: OctahedronBufferGeometry,
  18801. IcosahedronGeometry: IcosahedronGeometry,
  18802. IcosahedronBufferGeometry: IcosahedronBufferGeometry,
  18803. DodecahedronGeometry: DodecahedronGeometry,
  18804. DodecahedronBufferGeometry: DodecahedronBufferGeometry,
  18805. PolyhedronGeometry: PolyhedronGeometry,
  18806. PolyhedronBufferGeometry: PolyhedronBufferGeometry,
  18807. TubeGeometry: TubeGeometry,
  18808. TubeBufferGeometry: TubeBufferGeometry,
  18809. TorusKnotGeometry: TorusKnotGeometry,
  18810. TorusKnotBufferGeometry: TorusKnotBufferGeometry,
  18811. TorusGeometry: TorusGeometry,
  18812. TorusBufferGeometry: TorusBufferGeometry,
  18813. TextGeometry: TextGeometry,
  18814. TextBufferGeometry: TextBufferGeometry,
  18815. SphereGeometry: SphereGeometry,
  18816. SphereBufferGeometry: SphereBufferGeometry,
  18817. RingGeometry: RingGeometry,
  18818. RingBufferGeometry: RingBufferGeometry,
  18819. PlaneGeometry: PlaneGeometry,
  18820. PlaneBufferGeometry: PlaneBufferGeometry,
  18821. LatheGeometry: LatheGeometry,
  18822. LatheBufferGeometry: LatheBufferGeometry,
  18823. ShapeGeometry: ShapeGeometry,
  18824. ShapeBufferGeometry: ShapeBufferGeometry,
  18825. ExtrudeGeometry: ExtrudeGeometry,
  18826. ExtrudeBufferGeometry: ExtrudeBufferGeometry,
  18827. EdgesGeometry: EdgesGeometry,
  18828. ConeGeometry: ConeGeometry,
  18829. ConeBufferGeometry: ConeBufferGeometry,
  18830. CylinderGeometry: CylinderGeometry,
  18831. CylinderBufferGeometry: CylinderBufferGeometry,
  18832. CircleGeometry: CircleGeometry,
  18833. CircleBufferGeometry: CircleBufferGeometry,
  18834. BoxGeometry: BoxGeometry,
  18835. BoxBufferGeometry: BoxBufferGeometry
  18836. });
  18837. /**
  18838. * @author mrdoob / http://mrdoob.com/
  18839. *
  18840. * parameters = {
  18841. * color: <THREE.Color>
  18842. * }
  18843. */
  18844. function ShadowMaterial( parameters ) {
  18845. Material.call( this );
  18846. this.type = 'ShadowMaterial';
  18847. this.color = new Color( 0x000000 );
  18848. this.transparent = true;
  18849. this.setValues( parameters );
  18850. }
  18851. ShadowMaterial.prototype = Object.create( Material.prototype );
  18852. ShadowMaterial.prototype.constructor = ShadowMaterial;
  18853. ShadowMaterial.prototype.isShadowMaterial = true;
  18854. ShadowMaterial.prototype.copy = function ( source ) {
  18855. Material.prototype.copy.call( this, source );
  18856. this.color.copy( source.color );
  18857. return this;
  18858. };
  18859. /**
  18860. * @author mrdoob / http://mrdoob.com/
  18861. */
  18862. function RawShaderMaterial( parameters ) {
  18863. ShaderMaterial.call( this, parameters );
  18864. this.type = 'RawShaderMaterial';
  18865. }
  18866. RawShaderMaterial.prototype = Object.create( ShaderMaterial.prototype );
  18867. RawShaderMaterial.prototype.constructor = RawShaderMaterial;
  18868. RawShaderMaterial.prototype.isRawShaderMaterial = true;
  18869. /**
  18870. * @author WestLangley / http://github.com/WestLangley
  18871. *
  18872. * parameters = {
  18873. * color: <hex>,
  18874. * roughness: <float>,
  18875. * metalness: <float>,
  18876. * opacity: <float>,
  18877. *
  18878. * map: new THREE.Texture( <Image> ),
  18879. *
  18880. * lightMap: new THREE.Texture( <Image> ),
  18881. * lightMapIntensity: <float>
  18882. *
  18883. * aoMap: new THREE.Texture( <Image> ),
  18884. * aoMapIntensity: <float>
  18885. *
  18886. * emissive: <hex>,
  18887. * emissiveIntensity: <float>
  18888. * emissiveMap: new THREE.Texture( <Image> ),
  18889. *
  18890. * bumpMap: new THREE.Texture( <Image> ),
  18891. * bumpScale: <float>,
  18892. *
  18893. * normalMap: new THREE.Texture( <Image> ),
  18894. * normalMapType: THREE.TangentSpaceNormalMap,
  18895. * normalScale: <Vector2>,
  18896. *
  18897. * displacementMap: new THREE.Texture( <Image> ),
  18898. * displacementScale: <float>,
  18899. * displacementBias: <float>,
  18900. *
  18901. * roughnessMap: new THREE.Texture( <Image> ),
  18902. *
  18903. * metalnessMap: new THREE.Texture( <Image> ),
  18904. *
  18905. * alphaMap: new THREE.Texture( <Image> ),
  18906. *
  18907. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  18908. * envMapIntensity: <float>
  18909. *
  18910. * refractionRatio: <float>,
  18911. *
  18912. * wireframe: <boolean>,
  18913. * wireframeLinewidth: <float>,
  18914. *
  18915. * skinning: <bool>,
  18916. * morphTargets: <bool>,
  18917. * morphNormals: <bool>
  18918. * }
  18919. */
  18920. function MeshStandardMaterial( parameters ) {
  18921. Material.call( this );
  18922. this.defines = { 'STANDARD': '' };
  18923. this.type = 'MeshStandardMaterial';
  18924. this.color = new Color( 0xffffff ); // diffuse
  18925. this.roughness = 0.5;
  18926. this.metalness = 0.5;
  18927. this.map = null;
  18928. this.lightMap = null;
  18929. this.lightMapIntensity = 1.0;
  18930. this.aoMap = null;
  18931. this.aoMapIntensity = 1.0;
  18932. this.emissive = new Color( 0x000000 );
  18933. this.emissiveIntensity = 1.0;
  18934. this.emissiveMap = null;
  18935. this.bumpMap = null;
  18936. this.bumpScale = 1;
  18937. this.normalMap = null;
  18938. this.normalMapType = TangentSpaceNormalMap;
  18939. this.normalScale = new Vector2( 1, 1 );
  18940. this.displacementMap = null;
  18941. this.displacementScale = 1;
  18942. this.displacementBias = 0;
  18943. this.roughnessMap = null;
  18944. this.metalnessMap = null;
  18945. this.alphaMap = null;
  18946. this.envMap = null;
  18947. this.envMapIntensity = 1.0;
  18948. this.refractionRatio = 0.98;
  18949. this.wireframe = false;
  18950. this.wireframeLinewidth = 1;
  18951. this.wireframeLinecap = 'round';
  18952. this.wireframeLinejoin = 'round';
  18953. this.skinning = false;
  18954. this.morphTargets = false;
  18955. this.morphNormals = false;
  18956. this.setValues( parameters );
  18957. }
  18958. MeshStandardMaterial.prototype = Object.create( Material.prototype );
  18959. MeshStandardMaterial.prototype.constructor = MeshStandardMaterial;
  18960. MeshStandardMaterial.prototype.isMeshStandardMaterial = true;
  18961. MeshStandardMaterial.prototype.copy = function ( source ) {
  18962. Material.prototype.copy.call( this, source );
  18963. this.defines = { 'STANDARD': '' };
  18964. this.color.copy( source.color );
  18965. this.roughness = source.roughness;
  18966. this.metalness = source.metalness;
  18967. this.map = source.map;
  18968. this.lightMap = source.lightMap;
  18969. this.lightMapIntensity = source.lightMapIntensity;
  18970. this.aoMap = source.aoMap;
  18971. this.aoMapIntensity = source.aoMapIntensity;
  18972. this.emissive.copy( source.emissive );
  18973. this.emissiveMap = source.emissiveMap;
  18974. this.emissiveIntensity = source.emissiveIntensity;
  18975. this.bumpMap = source.bumpMap;
  18976. this.bumpScale = source.bumpScale;
  18977. this.normalMap = source.normalMap;
  18978. this.normalMapType = source.normalMapType;
  18979. this.normalScale.copy( source.normalScale );
  18980. this.displacementMap = source.displacementMap;
  18981. this.displacementScale = source.displacementScale;
  18982. this.displacementBias = source.displacementBias;
  18983. this.roughnessMap = source.roughnessMap;
  18984. this.metalnessMap = source.metalnessMap;
  18985. this.alphaMap = source.alphaMap;
  18986. this.envMap = source.envMap;
  18987. this.envMapIntensity = source.envMapIntensity;
  18988. this.refractionRatio = source.refractionRatio;
  18989. this.wireframe = source.wireframe;
  18990. this.wireframeLinewidth = source.wireframeLinewidth;
  18991. this.wireframeLinecap = source.wireframeLinecap;
  18992. this.wireframeLinejoin = source.wireframeLinejoin;
  18993. this.skinning = source.skinning;
  18994. this.morphTargets = source.morphTargets;
  18995. this.morphNormals = source.morphNormals;
  18996. return this;
  18997. };
  18998. /**
  18999. * @author WestLangley / http://github.com/WestLangley
  19000. *
  19001. * parameters = {
  19002. * reflectivity: <float>
  19003. * clearCoat: <float>
  19004. * clearCoatRoughness: <float>
  19005. * }
  19006. */
  19007. function MeshPhysicalMaterial( parameters ) {
  19008. MeshStandardMaterial.call( this );
  19009. this.defines = { 'PHYSICAL': '' };
  19010. this.type = 'MeshPhysicalMaterial';
  19011. this.reflectivity = 0.5; // maps to F0 = 0.04
  19012. this.clearCoat = 0.0;
  19013. this.clearCoatRoughness = 0.0;
  19014. this.setValues( parameters );
  19015. }
  19016. MeshPhysicalMaterial.prototype = Object.create( MeshStandardMaterial.prototype );
  19017. MeshPhysicalMaterial.prototype.constructor = MeshPhysicalMaterial;
  19018. MeshPhysicalMaterial.prototype.isMeshPhysicalMaterial = true;
  19019. MeshPhysicalMaterial.prototype.copy = function ( source ) {
  19020. MeshStandardMaterial.prototype.copy.call( this, source );
  19021. this.defines = { 'PHYSICAL': '' };
  19022. this.reflectivity = source.reflectivity;
  19023. this.clearCoat = source.clearCoat;
  19024. this.clearCoatRoughness = source.clearCoatRoughness;
  19025. return this;
  19026. };
  19027. /**
  19028. * @author mrdoob / http://mrdoob.com/
  19029. * @author alteredq / http://alteredqualia.com/
  19030. *
  19031. * parameters = {
  19032. * color: <hex>,
  19033. * specular: <hex>,
  19034. * shininess: <float>,
  19035. * opacity: <float>,
  19036. *
  19037. * map: new THREE.Texture( <Image> ),
  19038. *
  19039. * lightMap: new THREE.Texture( <Image> ),
  19040. * lightMapIntensity: <float>
  19041. *
  19042. * aoMap: new THREE.Texture( <Image> ),
  19043. * aoMapIntensity: <float>
  19044. *
  19045. * emissive: <hex>,
  19046. * emissiveIntensity: <float>
  19047. * emissiveMap: new THREE.Texture( <Image> ),
  19048. *
  19049. * bumpMap: new THREE.Texture( <Image> ),
  19050. * bumpScale: <float>,
  19051. *
  19052. * normalMap: new THREE.Texture( <Image> ),
  19053. * normalMapType: THREE.TangentSpaceNormalMap,
  19054. * normalScale: <Vector2>,
  19055. *
  19056. * displacementMap: new THREE.Texture( <Image> ),
  19057. * displacementScale: <float>,
  19058. * displacementBias: <float>,
  19059. *
  19060. * specularMap: new THREE.Texture( <Image> ),
  19061. *
  19062. * alphaMap: new THREE.Texture( <Image> ),
  19063. *
  19064. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  19065. * combine: THREE.Multiply,
  19066. * reflectivity: <float>,
  19067. * refractionRatio: <float>,
  19068. *
  19069. * wireframe: <boolean>,
  19070. * wireframeLinewidth: <float>,
  19071. *
  19072. * skinning: <bool>,
  19073. * morphTargets: <bool>,
  19074. * morphNormals: <bool>
  19075. * }
  19076. */
  19077. function MeshPhongMaterial( parameters ) {
  19078. Material.call( this );
  19079. this.type = 'MeshPhongMaterial';
  19080. this.color = new Color( 0xffffff ); // diffuse
  19081. this.specular = new Color( 0x111111 );
  19082. this.shininess = 30;
  19083. this.map = null;
  19084. this.lightMap = null;
  19085. this.lightMapIntensity = 1.0;
  19086. this.aoMap = null;
  19087. this.aoMapIntensity = 1.0;
  19088. this.emissive = new Color( 0x000000 );
  19089. this.emissiveIntensity = 1.0;
  19090. this.emissiveMap = null;
  19091. this.bumpMap = null;
  19092. this.bumpScale = 1;
  19093. this.normalMap = null;
  19094. this.normalMapType = TangentSpaceNormalMap;
  19095. this.normalScale = new Vector2( 1, 1 );
  19096. this.displacementMap = null;
  19097. this.displacementScale = 1;
  19098. this.displacementBias = 0;
  19099. this.specularMap = null;
  19100. this.alphaMap = null;
  19101. this.envMap = null;
  19102. this.combine = MultiplyOperation;
  19103. this.reflectivity = 1;
  19104. this.refractionRatio = 0.98;
  19105. this.wireframe = false;
  19106. this.wireframeLinewidth = 1;
  19107. this.wireframeLinecap = 'round';
  19108. this.wireframeLinejoin = 'round';
  19109. this.skinning = false;
  19110. this.morphTargets = false;
  19111. this.morphNormals = false;
  19112. this.setValues( parameters );
  19113. }
  19114. MeshPhongMaterial.prototype = Object.create( Material.prototype );
  19115. MeshPhongMaterial.prototype.constructor = MeshPhongMaterial;
  19116. MeshPhongMaterial.prototype.isMeshPhongMaterial = true;
  19117. MeshPhongMaterial.prototype.copy = function ( source ) {
  19118. Material.prototype.copy.call( this, source );
  19119. this.color.copy( source.color );
  19120. this.specular.copy( source.specular );
  19121. this.shininess = source.shininess;
  19122. this.map = source.map;
  19123. this.lightMap = source.lightMap;
  19124. this.lightMapIntensity = source.lightMapIntensity;
  19125. this.aoMap = source.aoMap;
  19126. this.aoMapIntensity = source.aoMapIntensity;
  19127. this.emissive.copy( source.emissive );
  19128. this.emissiveMap = source.emissiveMap;
  19129. this.emissiveIntensity = source.emissiveIntensity;
  19130. this.bumpMap = source.bumpMap;
  19131. this.bumpScale = source.bumpScale;
  19132. this.normalMap = source.normalMap;
  19133. this.normalMapType = source.normalMapType;
  19134. this.normalScale.copy( source.normalScale );
  19135. this.displacementMap = source.displacementMap;
  19136. this.displacementScale = source.displacementScale;
  19137. this.displacementBias = source.displacementBias;
  19138. this.specularMap = source.specularMap;
  19139. this.alphaMap = source.alphaMap;
  19140. this.envMap = source.envMap;
  19141. this.combine = source.combine;
  19142. this.reflectivity = source.reflectivity;
  19143. this.refractionRatio = source.refractionRatio;
  19144. this.wireframe = source.wireframe;
  19145. this.wireframeLinewidth = source.wireframeLinewidth;
  19146. this.wireframeLinecap = source.wireframeLinecap;
  19147. this.wireframeLinejoin = source.wireframeLinejoin;
  19148. this.skinning = source.skinning;
  19149. this.morphTargets = source.morphTargets;
  19150. this.morphNormals = source.morphNormals;
  19151. return this;
  19152. };
  19153. /**
  19154. * @author takahirox / http://github.com/takahirox
  19155. *
  19156. * parameters = {
  19157. * gradientMap: new THREE.Texture( <Image> )
  19158. * }
  19159. */
  19160. function MeshToonMaterial( parameters ) {
  19161. MeshPhongMaterial.call( this );
  19162. this.defines = { 'TOON': '' };
  19163. this.type = 'MeshToonMaterial';
  19164. this.gradientMap = null;
  19165. this.setValues( parameters );
  19166. }
  19167. MeshToonMaterial.prototype = Object.create( MeshPhongMaterial.prototype );
  19168. MeshToonMaterial.prototype.constructor = MeshToonMaterial;
  19169. MeshToonMaterial.prototype.isMeshToonMaterial = true;
  19170. MeshToonMaterial.prototype.copy = function ( source ) {
  19171. MeshPhongMaterial.prototype.copy.call( this, source );
  19172. this.gradientMap = source.gradientMap;
  19173. return this;
  19174. };
  19175. /**
  19176. * @author mrdoob / http://mrdoob.com/
  19177. * @author WestLangley / http://github.com/WestLangley
  19178. *
  19179. * parameters = {
  19180. * opacity: <float>,
  19181. *
  19182. * bumpMap: new THREE.Texture( <Image> ),
  19183. * bumpScale: <float>,
  19184. *
  19185. * normalMap: new THREE.Texture( <Image> ),
  19186. * normalMapType: THREE.TangentSpaceNormalMap,
  19187. * normalScale: <Vector2>,
  19188. *
  19189. * displacementMap: new THREE.Texture( <Image> ),
  19190. * displacementScale: <float>,
  19191. * displacementBias: <float>,
  19192. *
  19193. * wireframe: <boolean>,
  19194. * wireframeLinewidth: <float>
  19195. *
  19196. * skinning: <bool>,
  19197. * morphTargets: <bool>,
  19198. * morphNormals: <bool>
  19199. * }
  19200. */
  19201. function MeshNormalMaterial( parameters ) {
  19202. Material.call( this );
  19203. this.type = 'MeshNormalMaterial';
  19204. this.bumpMap = null;
  19205. this.bumpScale = 1;
  19206. this.normalMap = null;
  19207. this.normalMapType = TangentSpaceNormalMap;
  19208. this.normalScale = new Vector2( 1, 1 );
  19209. this.displacementMap = null;
  19210. this.displacementScale = 1;
  19211. this.displacementBias = 0;
  19212. this.wireframe = false;
  19213. this.wireframeLinewidth = 1;
  19214. this.fog = false;
  19215. this.lights = false;
  19216. this.skinning = false;
  19217. this.morphTargets = false;
  19218. this.morphNormals = false;
  19219. this.setValues( parameters );
  19220. }
  19221. MeshNormalMaterial.prototype = Object.create( Material.prototype );
  19222. MeshNormalMaterial.prototype.constructor = MeshNormalMaterial;
  19223. MeshNormalMaterial.prototype.isMeshNormalMaterial = true;
  19224. MeshNormalMaterial.prototype.copy = function ( source ) {
  19225. Material.prototype.copy.call( this, source );
  19226. this.bumpMap = source.bumpMap;
  19227. this.bumpScale = source.bumpScale;
  19228. this.normalMap = source.normalMap;
  19229. this.normalMapType = source.normalMapType;
  19230. this.normalScale.copy( source.normalScale );
  19231. this.displacementMap = source.displacementMap;
  19232. this.displacementScale = source.displacementScale;
  19233. this.displacementBias = source.displacementBias;
  19234. this.wireframe = source.wireframe;
  19235. this.wireframeLinewidth = source.wireframeLinewidth;
  19236. this.skinning = source.skinning;
  19237. this.morphTargets = source.morphTargets;
  19238. this.morphNormals = source.morphNormals;
  19239. return this;
  19240. };
  19241. /**
  19242. * @author mrdoob / http://mrdoob.com/
  19243. * @author alteredq / http://alteredqualia.com/
  19244. *
  19245. * parameters = {
  19246. * color: <hex>,
  19247. * opacity: <float>,
  19248. *
  19249. * map: new THREE.Texture( <Image> ),
  19250. *
  19251. * lightMap: new THREE.Texture( <Image> ),
  19252. * lightMapIntensity: <float>
  19253. *
  19254. * aoMap: new THREE.Texture( <Image> ),
  19255. * aoMapIntensity: <float>
  19256. *
  19257. * emissive: <hex>,
  19258. * emissiveIntensity: <float>
  19259. * emissiveMap: new THREE.Texture( <Image> ),
  19260. *
  19261. * specularMap: new THREE.Texture( <Image> ),
  19262. *
  19263. * alphaMap: new THREE.Texture( <Image> ),
  19264. *
  19265. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  19266. * combine: THREE.Multiply,
  19267. * reflectivity: <float>,
  19268. * refractionRatio: <float>,
  19269. *
  19270. * wireframe: <boolean>,
  19271. * wireframeLinewidth: <float>,
  19272. *
  19273. * skinning: <bool>,
  19274. * morphTargets: <bool>,
  19275. * morphNormals: <bool>
  19276. * }
  19277. */
  19278. function MeshLambertMaterial( parameters ) {
  19279. Material.call( this );
  19280. this.type = 'MeshLambertMaterial';
  19281. this.color = new Color( 0xffffff ); // diffuse
  19282. this.map = null;
  19283. this.lightMap = null;
  19284. this.lightMapIntensity = 1.0;
  19285. this.aoMap = null;
  19286. this.aoMapIntensity = 1.0;
  19287. this.emissive = new Color( 0x000000 );
  19288. this.emissiveIntensity = 1.0;
  19289. this.emissiveMap = null;
  19290. this.specularMap = null;
  19291. this.alphaMap = null;
  19292. this.envMap = null;
  19293. this.combine = MultiplyOperation;
  19294. this.reflectivity = 1;
  19295. this.refractionRatio = 0.98;
  19296. this.wireframe = false;
  19297. this.wireframeLinewidth = 1;
  19298. this.wireframeLinecap = 'round';
  19299. this.wireframeLinejoin = 'round';
  19300. this.skinning = false;
  19301. this.morphTargets = false;
  19302. this.morphNormals = false;
  19303. this.setValues( parameters );
  19304. }
  19305. MeshLambertMaterial.prototype = Object.create( Material.prototype );
  19306. MeshLambertMaterial.prototype.constructor = MeshLambertMaterial;
  19307. MeshLambertMaterial.prototype.isMeshLambertMaterial = true;
  19308. MeshLambertMaterial.prototype.copy = function ( source ) {
  19309. Material.prototype.copy.call( this, source );
  19310. this.color.copy( source.color );
  19311. this.map = source.map;
  19312. this.lightMap = source.lightMap;
  19313. this.lightMapIntensity = source.lightMapIntensity;
  19314. this.aoMap = source.aoMap;
  19315. this.aoMapIntensity = source.aoMapIntensity;
  19316. this.emissive.copy( source.emissive );
  19317. this.emissiveMap = source.emissiveMap;
  19318. this.emissiveIntensity = source.emissiveIntensity;
  19319. this.specularMap = source.specularMap;
  19320. this.alphaMap = source.alphaMap;
  19321. this.envMap = source.envMap;
  19322. this.combine = source.combine;
  19323. this.reflectivity = source.reflectivity;
  19324. this.refractionRatio = source.refractionRatio;
  19325. this.wireframe = source.wireframe;
  19326. this.wireframeLinewidth = source.wireframeLinewidth;
  19327. this.wireframeLinecap = source.wireframeLinecap;
  19328. this.wireframeLinejoin = source.wireframeLinejoin;
  19329. this.skinning = source.skinning;
  19330. this.morphTargets = source.morphTargets;
  19331. this.morphNormals = source.morphNormals;
  19332. return this;
  19333. };
  19334. /**
  19335. * @author WestLangley / http://github.com/WestLangley
  19336. *
  19337. * parameters = {
  19338. * color: <hex>,
  19339. * opacity: <float>,
  19340. *
  19341. * matcap: new THREE.Texture( <Image> ),
  19342. *
  19343. * map: new THREE.Texture( <Image> ),
  19344. *
  19345. * bumpMap: new THREE.Texture( <Image> ),
  19346. * bumpScale: <float>,
  19347. *
  19348. * normalMap: new THREE.Texture( <Image> ),
  19349. * normalMapType: THREE.TangentSpaceNormalMap,
  19350. * normalScale: <Vector2>,
  19351. *
  19352. * displacementMap: new THREE.Texture( <Image> ),
  19353. * displacementScale: <float>,
  19354. * displacementBias: <float>,
  19355. *
  19356. * alphaMap: new THREE.Texture( <Image> ),
  19357. *
  19358. * skinning: <bool>,
  19359. * morphTargets: <bool>,
  19360. * morphNormals: <bool>
  19361. * }
  19362. */
  19363. function MeshMatcapMaterial( parameters ) {
  19364. Material.call( this );
  19365. this.defines = { 'MATCAP': '' };
  19366. this.type = 'MeshMatcapMaterial';
  19367. this.color = new Color( 0xffffff ); // diffuse
  19368. this.matcap = null;
  19369. this.map = null;
  19370. this.bumpMap = null;
  19371. this.bumpScale = 1;
  19372. this.normalMap = null;
  19373. this.normalMapType = TangentSpaceNormalMap;
  19374. this.normalScale = new Vector2( 1, 1 );
  19375. this.displacementMap = null;
  19376. this.displacementScale = 1;
  19377. this.displacementBias = 0;
  19378. this.alphaMap = null;
  19379. this.skinning = false;
  19380. this.morphTargets = false;
  19381. this.morphNormals = false;
  19382. this.lights = false;
  19383. this.setValues( parameters );
  19384. }
  19385. MeshMatcapMaterial.prototype = Object.create( Material.prototype );
  19386. MeshMatcapMaterial.prototype.constructor = MeshMatcapMaterial;
  19387. MeshMatcapMaterial.prototype.isMeshMatcapMaterial = true;
  19388. MeshMatcapMaterial.prototype.copy = function ( source ) {
  19389. Material.prototype.copy.call( this, source );
  19390. this.defines = { 'MATCAP': '' };
  19391. this.color.copy( source.color );
  19392. this.matcap = source.matcap;
  19393. this.map = source.map;
  19394. this.bumpMap = source.bumpMap;
  19395. this.bumpScale = source.bumpScale;
  19396. this.normalMap = source.normalMap;
  19397. this.normalMapType = source.normalMapType;
  19398. this.normalScale.copy( source.normalScale );
  19399. this.displacementMap = source.displacementMap;
  19400. this.displacementScale = source.displacementScale;
  19401. this.displacementBias = source.displacementBias;
  19402. this.alphaMap = source.alphaMap;
  19403. this.skinning = source.skinning;
  19404. this.morphTargets = source.morphTargets;
  19405. this.morphNormals = source.morphNormals;
  19406. return this;
  19407. };
  19408. /**
  19409. * @author alteredq / http://alteredqualia.com/
  19410. *
  19411. * parameters = {
  19412. * color: <hex>,
  19413. * opacity: <float>,
  19414. *
  19415. * linewidth: <float>,
  19416. *
  19417. * scale: <float>,
  19418. * dashSize: <float>,
  19419. * gapSize: <float>
  19420. * }
  19421. */
  19422. function LineDashedMaterial( parameters ) {
  19423. LineBasicMaterial.call( this );
  19424. this.type = 'LineDashedMaterial';
  19425. this.scale = 1;
  19426. this.dashSize = 3;
  19427. this.gapSize = 1;
  19428. this.setValues( parameters );
  19429. }
  19430. LineDashedMaterial.prototype = Object.create( LineBasicMaterial.prototype );
  19431. LineDashedMaterial.prototype.constructor = LineDashedMaterial;
  19432. LineDashedMaterial.prototype.isLineDashedMaterial = true;
  19433. LineDashedMaterial.prototype.copy = function ( source ) {
  19434. LineBasicMaterial.prototype.copy.call( this, source );
  19435. this.scale = source.scale;
  19436. this.dashSize = source.dashSize;
  19437. this.gapSize = source.gapSize;
  19438. return this;
  19439. };
  19440. var Materials = /*#__PURE__*/Object.freeze({
  19441. ShadowMaterial: ShadowMaterial,
  19442. SpriteMaterial: SpriteMaterial,
  19443. RawShaderMaterial: RawShaderMaterial,
  19444. ShaderMaterial: ShaderMaterial,
  19445. PointsMaterial: PointsMaterial,
  19446. MeshPhysicalMaterial: MeshPhysicalMaterial,
  19447. MeshStandardMaterial: MeshStandardMaterial,
  19448. MeshPhongMaterial: MeshPhongMaterial,
  19449. MeshToonMaterial: MeshToonMaterial,
  19450. MeshNormalMaterial: MeshNormalMaterial,
  19451. MeshLambertMaterial: MeshLambertMaterial,
  19452. MeshDepthMaterial: MeshDepthMaterial,
  19453. MeshDistanceMaterial: MeshDistanceMaterial,
  19454. MeshBasicMaterial: MeshBasicMaterial,
  19455. MeshMatcapMaterial: MeshMatcapMaterial,
  19456. LineDashedMaterial: LineDashedMaterial,
  19457. LineBasicMaterial: LineBasicMaterial,
  19458. Material: Material
  19459. });
  19460. /**
  19461. * @author tschw
  19462. * @author Ben Houston / http://clara.io/
  19463. * @author David Sarno / http://lighthaus.us/
  19464. */
  19465. var AnimationUtils = {
  19466. // same as Array.prototype.slice, but also works on typed arrays
  19467. arraySlice: function ( array, from, to ) {
  19468. if ( AnimationUtils.isTypedArray( array ) ) {
  19469. // in ios9 array.subarray(from, undefined) will return empty array
  19470. // but array.subarray(from) or array.subarray(from, len) is correct
  19471. return new array.constructor( array.subarray( from, to !== undefined ? to : array.length ) );
  19472. }
  19473. return array.slice( from, to );
  19474. },
  19475. // converts an array to a specific type
  19476. convertArray: function ( array, type, forceClone ) {
  19477. if ( ! array || // let 'undefined' and 'null' pass
  19478. ! forceClone && array.constructor === type ) return array;
  19479. if ( typeof type.BYTES_PER_ELEMENT === 'number' ) {
  19480. return new type( array ); // create typed array
  19481. }
  19482. return Array.prototype.slice.call( array ); // create Array
  19483. },
  19484. isTypedArray: function ( object ) {
  19485. return ArrayBuffer.isView( object ) &&
  19486. ! ( object instanceof DataView );
  19487. },
  19488. // returns an array by which times and values can be sorted
  19489. getKeyframeOrder: function ( times ) {
  19490. function compareTime( i, j ) {
  19491. return times[ i ] - times[ j ];
  19492. }
  19493. var n = times.length;
  19494. var result = new Array( n );
  19495. for ( var i = 0; i !== n; ++ i ) result[ i ] = i;
  19496. result.sort( compareTime );
  19497. return result;
  19498. },
  19499. // uses the array previously returned by 'getKeyframeOrder' to sort data
  19500. sortedArray: function ( values, stride, order ) {
  19501. var nValues = values.length;
  19502. var result = new values.constructor( nValues );
  19503. for ( var i = 0, dstOffset = 0; dstOffset !== nValues; ++ i ) {
  19504. var srcOffset = order[ i ] * stride;
  19505. for ( var j = 0; j !== stride; ++ j ) {
  19506. result[ dstOffset ++ ] = values[ srcOffset + j ];
  19507. }
  19508. }
  19509. return result;
  19510. },
  19511. // function for parsing AOS keyframe formats
  19512. flattenJSON: function ( jsonKeys, times, values, valuePropertyName ) {
  19513. var i = 1, key = jsonKeys[ 0 ];
  19514. while ( key !== undefined && key[ valuePropertyName ] === undefined ) {
  19515. key = jsonKeys[ i ++ ];
  19516. }
  19517. if ( key === undefined ) return; // no data
  19518. var value = key[ valuePropertyName ];
  19519. if ( value === undefined ) return; // no data
  19520. if ( Array.isArray( value ) ) {
  19521. do {
  19522. value = key[ valuePropertyName ];
  19523. if ( value !== undefined ) {
  19524. times.push( key.time );
  19525. values.push.apply( values, value ); // push all elements
  19526. }
  19527. key = jsonKeys[ i ++ ];
  19528. } while ( key !== undefined );
  19529. } else if ( value.toArray !== undefined ) {
  19530. // ...assume THREE.Math-ish
  19531. do {
  19532. value = key[ valuePropertyName ];
  19533. if ( value !== undefined ) {
  19534. times.push( key.time );
  19535. value.toArray( values, values.length );
  19536. }
  19537. key = jsonKeys[ i ++ ];
  19538. } while ( key !== undefined );
  19539. } else {
  19540. // otherwise push as-is
  19541. do {
  19542. value = key[ valuePropertyName ];
  19543. if ( value !== undefined ) {
  19544. times.push( key.time );
  19545. values.push( value );
  19546. }
  19547. key = jsonKeys[ i ++ ];
  19548. } while ( key !== undefined );
  19549. }
  19550. }
  19551. };
  19552. /**
  19553. * Abstract base class of interpolants over parametric samples.
  19554. *
  19555. * The parameter domain is one dimensional, typically the time or a path
  19556. * along a curve defined by the data.
  19557. *
  19558. * The sample values can have any dimensionality and derived classes may
  19559. * apply special interpretations to the data.
  19560. *
  19561. * This class provides the interval seek in a Template Method, deferring
  19562. * the actual interpolation to derived classes.
  19563. *
  19564. * Time complexity is O(1) for linear access crossing at most two points
  19565. * and O(log N) for random access, where N is the number of positions.
  19566. *
  19567. * References:
  19568. *
  19569. * http://www.oodesign.com/template-method-pattern.html
  19570. *
  19571. * @author tschw
  19572. */
  19573. function Interpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  19574. this.parameterPositions = parameterPositions;
  19575. this._cachedIndex = 0;
  19576. this.resultBuffer = resultBuffer !== undefined ?
  19577. resultBuffer : new sampleValues.constructor( sampleSize );
  19578. this.sampleValues = sampleValues;
  19579. this.valueSize = sampleSize;
  19580. }
  19581. Object.assign( Interpolant.prototype, {
  19582. evaluate: function ( t ) {
  19583. var pp = this.parameterPositions,
  19584. i1 = this._cachedIndex,
  19585. t1 = pp[ i1 ],
  19586. t0 = pp[ i1 - 1 ];
  19587. validate_interval: {
  19588. seek: {
  19589. var right;
  19590. linear_scan: {
  19591. //- See http://jsperf.com/comparison-to-undefined/3
  19592. //- slower code:
  19593. //-
  19594. //- if ( t >= t1 || t1 === undefined ) {
  19595. forward_scan: if ( ! ( t < t1 ) ) {
  19596. for ( var giveUpAt = i1 + 2; ; ) {
  19597. if ( t1 === undefined ) {
  19598. if ( t < t0 ) break forward_scan;
  19599. // after end
  19600. i1 = pp.length;
  19601. this._cachedIndex = i1;
  19602. return this.afterEnd_( i1 - 1, t, t0 );
  19603. }
  19604. if ( i1 === giveUpAt ) break; // this loop
  19605. t0 = t1;
  19606. t1 = pp[ ++ i1 ];
  19607. if ( t < t1 ) {
  19608. // we have arrived at the sought interval
  19609. break seek;
  19610. }
  19611. }
  19612. // prepare binary search on the right side of the index
  19613. right = pp.length;
  19614. break linear_scan;
  19615. }
  19616. //- slower code:
  19617. //- if ( t < t0 || t0 === undefined ) {
  19618. if ( ! ( t >= t0 ) ) {
  19619. // looping?
  19620. var t1global = pp[ 1 ];
  19621. if ( t < t1global ) {
  19622. i1 = 2; // + 1, using the scan for the details
  19623. t0 = t1global;
  19624. }
  19625. // linear reverse scan
  19626. for ( var giveUpAt = i1 - 2; ; ) {
  19627. if ( t0 === undefined ) {
  19628. // before start
  19629. this._cachedIndex = 0;
  19630. return this.beforeStart_( 0, t, t1 );
  19631. }
  19632. if ( i1 === giveUpAt ) break; // this loop
  19633. t1 = t0;
  19634. t0 = pp[ -- i1 - 1 ];
  19635. if ( t >= t0 ) {
  19636. // we have arrived at the sought interval
  19637. break seek;
  19638. }
  19639. }
  19640. // prepare binary search on the left side of the index
  19641. right = i1;
  19642. i1 = 0;
  19643. break linear_scan;
  19644. }
  19645. // the interval is valid
  19646. break validate_interval;
  19647. } // linear scan
  19648. // binary search
  19649. while ( i1 < right ) {
  19650. var mid = ( i1 + right ) >>> 1;
  19651. if ( t < pp[ mid ] ) {
  19652. right = mid;
  19653. } else {
  19654. i1 = mid + 1;
  19655. }
  19656. }
  19657. t1 = pp[ i1 ];
  19658. t0 = pp[ i1 - 1 ];
  19659. // check boundary cases, again
  19660. if ( t0 === undefined ) {
  19661. this._cachedIndex = 0;
  19662. return this.beforeStart_( 0, t, t1 );
  19663. }
  19664. if ( t1 === undefined ) {
  19665. i1 = pp.length;
  19666. this._cachedIndex = i1;
  19667. return this.afterEnd_( i1 - 1, t0, t );
  19668. }
  19669. } // seek
  19670. this._cachedIndex = i1;
  19671. this.intervalChanged_( i1, t0, t1 );
  19672. } // validate_interval
  19673. return this.interpolate_( i1, t0, t, t1 );
  19674. },
  19675. settings: null, // optional, subclass-specific settings structure
  19676. // Note: The indirection allows central control of many interpolants.
  19677. // --- Protected interface
  19678. DefaultSettings_: {},
  19679. getSettings_: function () {
  19680. return this.settings || this.DefaultSettings_;
  19681. },
  19682. copySampleValue_: function ( index ) {
  19683. // copies a sample value to the result buffer
  19684. var result = this.resultBuffer,
  19685. values = this.sampleValues,
  19686. stride = this.valueSize,
  19687. offset = index * stride;
  19688. for ( var i = 0; i !== stride; ++ i ) {
  19689. result[ i ] = values[ offset + i ];
  19690. }
  19691. return result;
  19692. },
  19693. // Template methods for derived classes:
  19694. interpolate_: function ( /* i1, t0, t, t1 */ ) {
  19695. throw new Error( 'call to abstract method' );
  19696. // implementations shall return this.resultBuffer
  19697. },
  19698. intervalChanged_: function ( /* i1, t0, t1 */ ) {
  19699. // empty
  19700. }
  19701. } );
  19702. //!\ DECLARE ALIAS AFTER assign prototype !
  19703. Object.assign( Interpolant.prototype, {
  19704. //( 0, t, t0 ), returns this.resultBuffer
  19705. beforeStart_: Interpolant.prototype.copySampleValue_,
  19706. //( N-1, tN-1, t ), returns this.resultBuffer
  19707. afterEnd_: Interpolant.prototype.copySampleValue_,
  19708. } );
  19709. /**
  19710. * Fast and simple cubic spline interpolant.
  19711. *
  19712. * It was derived from a Hermitian construction setting the first derivative
  19713. * at each sample position to the linear slope between neighboring positions
  19714. * over their parameter interval.
  19715. *
  19716. * @author tschw
  19717. */
  19718. function CubicInterpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  19719. Interpolant.call( this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  19720. this._weightPrev = - 0;
  19721. this._offsetPrev = - 0;
  19722. this._weightNext = - 0;
  19723. this._offsetNext = - 0;
  19724. }
  19725. CubicInterpolant.prototype = Object.assign( Object.create( Interpolant.prototype ), {
  19726. constructor: CubicInterpolant,
  19727. DefaultSettings_: {
  19728. endingStart: ZeroCurvatureEnding,
  19729. endingEnd: ZeroCurvatureEnding
  19730. },
  19731. intervalChanged_: function ( i1, t0, t1 ) {
  19732. var pp = this.parameterPositions,
  19733. iPrev = i1 - 2,
  19734. iNext = i1 + 1,
  19735. tPrev = pp[ iPrev ],
  19736. tNext = pp[ iNext ];
  19737. if ( tPrev === undefined ) {
  19738. switch ( this.getSettings_().endingStart ) {
  19739. case ZeroSlopeEnding:
  19740. // f'(t0) = 0
  19741. iPrev = i1;
  19742. tPrev = 2 * t0 - t1;
  19743. break;
  19744. case WrapAroundEnding:
  19745. // use the other end of the curve
  19746. iPrev = pp.length - 2;
  19747. tPrev = t0 + pp[ iPrev ] - pp[ iPrev + 1 ];
  19748. break;
  19749. default: // ZeroCurvatureEnding
  19750. // f''(t0) = 0 a.k.a. Natural Spline
  19751. iPrev = i1;
  19752. tPrev = t1;
  19753. }
  19754. }
  19755. if ( tNext === undefined ) {
  19756. switch ( this.getSettings_().endingEnd ) {
  19757. case ZeroSlopeEnding:
  19758. // f'(tN) = 0
  19759. iNext = i1;
  19760. tNext = 2 * t1 - t0;
  19761. break;
  19762. case WrapAroundEnding:
  19763. // use the other end of the curve
  19764. iNext = 1;
  19765. tNext = t1 + pp[ 1 ] - pp[ 0 ];
  19766. break;
  19767. default: // ZeroCurvatureEnding
  19768. // f''(tN) = 0, a.k.a. Natural Spline
  19769. iNext = i1 - 1;
  19770. tNext = t0;
  19771. }
  19772. }
  19773. var halfDt = ( t1 - t0 ) * 0.5,
  19774. stride = this.valueSize;
  19775. this._weightPrev = halfDt / ( t0 - tPrev );
  19776. this._weightNext = halfDt / ( tNext - t1 );
  19777. this._offsetPrev = iPrev * stride;
  19778. this._offsetNext = iNext * stride;
  19779. },
  19780. interpolate_: function ( i1, t0, t, t1 ) {
  19781. var result = this.resultBuffer,
  19782. values = this.sampleValues,
  19783. stride = this.valueSize,
  19784. o1 = i1 * stride, o0 = o1 - stride,
  19785. oP = this._offsetPrev, oN = this._offsetNext,
  19786. wP = this._weightPrev, wN = this._weightNext,
  19787. p = ( t - t0 ) / ( t1 - t0 ),
  19788. pp = p * p,
  19789. ppp = pp * p;
  19790. // evaluate polynomials
  19791. var sP = - wP * ppp + 2 * wP * pp - wP * p;
  19792. var s0 = ( 1 + wP ) * ppp + ( - 1.5 - 2 * wP ) * pp + ( - 0.5 + wP ) * p + 1;
  19793. var s1 = ( - 1 - wN ) * ppp + ( 1.5 + wN ) * pp + 0.5 * p;
  19794. var sN = wN * ppp - wN * pp;
  19795. // combine data linearly
  19796. for ( var i = 0; i !== stride; ++ i ) {
  19797. result[ i ] =
  19798. sP * values[ oP + i ] +
  19799. s0 * values[ o0 + i ] +
  19800. s1 * values[ o1 + i ] +
  19801. sN * values[ oN + i ];
  19802. }
  19803. return result;
  19804. }
  19805. } );
  19806. /**
  19807. * @author tschw
  19808. */
  19809. function LinearInterpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  19810. Interpolant.call( this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  19811. }
  19812. LinearInterpolant.prototype = Object.assign( Object.create( Interpolant.prototype ), {
  19813. constructor: LinearInterpolant,
  19814. interpolate_: function ( i1, t0, t, t1 ) {
  19815. var result = this.resultBuffer,
  19816. values = this.sampleValues,
  19817. stride = this.valueSize,
  19818. offset1 = i1 * stride,
  19819. offset0 = offset1 - stride,
  19820. weight1 = ( t - t0 ) / ( t1 - t0 ),
  19821. weight0 = 1 - weight1;
  19822. for ( var i = 0; i !== stride; ++ i ) {
  19823. result[ i ] =
  19824. values[ offset0 + i ] * weight0 +
  19825. values[ offset1 + i ] * weight1;
  19826. }
  19827. return result;
  19828. }
  19829. } );
  19830. /**
  19831. *
  19832. * Interpolant that evaluates to the sample value at the position preceeding
  19833. * the parameter.
  19834. *
  19835. * @author tschw
  19836. */
  19837. function DiscreteInterpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  19838. Interpolant.call( this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  19839. }
  19840. DiscreteInterpolant.prototype = Object.assign( Object.create( Interpolant.prototype ), {
  19841. constructor: DiscreteInterpolant,
  19842. interpolate_: function ( i1 /*, t0, t, t1 */ ) {
  19843. return this.copySampleValue_( i1 - 1 );
  19844. }
  19845. } );
  19846. /**
  19847. *
  19848. * A timed sequence of keyframes for a specific property.
  19849. *
  19850. *
  19851. * @author Ben Houston / http://clara.io/
  19852. * @author David Sarno / http://lighthaus.us/
  19853. * @author tschw
  19854. */
  19855. function KeyframeTrack( name, times, values, interpolation ) {
  19856. if ( name === undefined ) throw new Error( 'THREE.KeyframeTrack: track name is undefined' );
  19857. if ( times === undefined || times.length === 0 ) throw new Error( 'THREE.KeyframeTrack: no keyframes in track named ' + name );
  19858. this.name = name;
  19859. this.times = AnimationUtils.convertArray( times, this.TimeBufferType );
  19860. this.values = AnimationUtils.convertArray( values, this.ValueBufferType );
  19861. this.setInterpolation( interpolation || this.DefaultInterpolation );
  19862. }
  19863. // Static methods
  19864. Object.assign( KeyframeTrack, {
  19865. // Serialization (in static context, because of constructor invocation
  19866. // and automatic invocation of .toJSON):
  19867. toJSON: function ( track ) {
  19868. var trackType = track.constructor;
  19869. var json;
  19870. // derived classes can define a static toJSON method
  19871. if ( trackType.toJSON !== undefined ) {
  19872. json = trackType.toJSON( track );
  19873. } else {
  19874. // by default, we assume the data can be serialized as-is
  19875. json = {
  19876. 'name': track.name,
  19877. 'times': AnimationUtils.convertArray( track.times, Array ),
  19878. 'values': AnimationUtils.convertArray( track.values, Array )
  19879. };
  19880. var interpolation = track.getInterpolation();
  19881. if ( interpolation !== track.DefaultInterpolation ) {
  19882. json.interpolation = interpolation;
  19883. }
  19884. }
  19885. json.type = track.ValueTypeName; // mandatory
  19886. return json;
  19887. }
  19888. } );
  19889. Object.assign( KeyframeTrack.prototype, {
  19890. constructor: KeyframeTrack,
  19891. TimeBufferType: Float32Array,
  19892. ValueBufferType: Float32Array,
  19893. DefaultInterpolation: InterpolateLinear,
  19894. InterpolantFactoryMethodDiscrete: function ( result ) {
  19895. return new DiscreteInterpolant( this.times, this.values, this.getValueSize(), result );
  19896. },
  19897. InterpolantFactoryMethodLinear: function ( result ) {
  19898. return new LinearInterpolant( this.times, this.values, this.getValueSize(), result );
  19899. },
  19900. InterpolantFactoryMethodSmooth: function ( result ) {
  19901. return new CubicInterpolant( this.times, this.values, this.getValueSize(), result );
  19902. },
  19903. setInterpolation: function ( interpolation ) {
  19904. var factoryMethod;
  19905. switch ( interpolation ) {
  19906. case InterpolateDiscrete:
  19907. factoryMethod = this.InterpolantFactoryMethodDiscrete;
  19908. break;
  19909. case InterpolateLinear:
  19910. factoryMethod = this.InterpolantFactoryMethodLinear;
  19911. break;
  19912. case InterpolateSmooth:
  19913. factoryMethod = this.InterpolantFactoryMethodSmooth;
  19914. break;
  19915. }
  19916. if ( factoryMethod === undefined ) {
  19917. var message = "unsupported interpolation for " +
  19918. this.ValueTypeName + " keyframe track named " + this.name;
  19919. if ( this.createInterpolant === undefined ) {
  19920. // fall back to default, unless the default itself is messed up
  19921. if ( interpolation !== this.DefaultInterpolation ) {
  19922. this.setInterpolation( this.DefaultInterpolation );
  19923. } else {
  19924. throw new Error( message ); // fatal, in this case
  19925. }
  19926. }
  19927. console.warn( 'THREE.KeyframeTrack:', message );
  19928. return this;
  19929. }
  19930. this.createInterpolant = factoryMethod;
  19931. return this;
  19932. },
  19933. getInterpolation: function () {
  19934. switch ( this.createInterpolant ) {
  19935. case this.InterpolantFactoryMethodDiscrete:
  19936. return InterpolateDiscrete;
  19937. case this.InterpolantFactoryMethodLinear:
  19938. return InterpolateLinear;
  19939. case this.InterpolantFactoryMethodSmooth:
  19940. return InterpolateSmooth;
  19941. }
  19942. },
  19943. getValueSize: function () {
  19944. return this.values.length / this.times.length;
  19945. },
  19946. // move all keyframes either forwards or backwards in time
  19947. shift: function ( timeOffset ) {
  19948. if ( timeOffset !== 0.0 ) {
  19949. var times = this.times;
  19950. for ( var i = 0, n = times.length; i !== n; ++ i ) {
  19951. times[ i ] += timeOffset;
  19952. }
  19953. }
  19954. return this;
  19955. },
  19956. // scale all keyframe times by a factor (useful for frame <-> seconds conversions)
  19957. scale: function ( timeScale ) {
  19958. if ( timeScale !== 1.0 ) {
  19959. var times = this.times;
  19960. for ( var i = 0, n = times.length; i !== n; ++ i ) {
  19961. times[ i ] *= timeScale;
  19962. }
  19963. }
  19964. return this;
  19965. },
  19966. // removes keyframes before and after animation without changing any values within the range [startTime, endTime].
  19967. // IMPORTANT: We do not shift around keys to the start of the track time, because for interpolated keys this will change their values
  19968. trim: function ( startTime, endTime ) {
  19969. var times = this.times,
  19970. nKeys = times.length,
  19971. from = 0,
  19972. to = nKeys - 1;
  19973. while ( from !== nKeys && times[ from ] < startTime ) {
  19974. ++ from;
  19975. }
  19976. while ( to !== - 1 && times[ to ] > endTime ) {
  19977. -- to;
  19978. }
  19979. ++ to; // inclusive -> exclusive bound
  19980. if ( from !== 0 || to !== nKeys ) {
  19981. // empty tracks are forbidden, so keep at least one keyframe
  19982. if ( from >= to ) to = Math.max( to, 1 ), from = to - 1;
  19983. var stride = this.getValueSize();
  19984. this.times = AnimationUtils.arraySlice( times, from, to );
  19985. this.values = AnimationUtils.arraySlice( this.values, from * stride, to * stride );
  19986. }
  19987. return this;
  19988. },
  19989. // ensure we do not get a GarbageInGarbageOut situation, make sure tracks are at least minimally viable
  19990. validate: function () {
  19991. var valid = true;
  19992. var valueSize = this.getValueSize();
  19993. if ( valueSize - Math.floor( valueSize ) !== 0 ) {
  19994. console.error( 'THREE.KeyframeTrack: Invalid value size in track.', this );
  19995. valid = false;
  19996. }
  19997. var times = this.times,
  19998. values = this.values,
  19999. nKeys = times.length;
  20000. if ( nKeys === 0 ) {
  20001. console.error( 'THREE.KeyframeTrack: Track is empty.', this );
  20002. valid = false;
  20003. }
  20004. var prevTime = null;
  20005. for ( var i = 0; i !== nKeys; i ++ ) {
  20006. var currTime = times[ i ];
  20007. if ( typeof currTime === 'number' && isNaN( currTime ) ) {
  20008. console.error( 'THREE.KeyframeTrack: Time is not a valid number.', this, i, currTime );
  20009. valid = false;
  20010. break;
  20011. }
  20012. if ( prevTime !== null && prevTime > currTime ) {
  20013. console.error( 'THREE.KeyframeTrack: Out of order keys.', this, i, currTime, prevTime );
  20014. valid = false;
  20015. break;
  20016. }
  20017. prevTime = currTime;
  20018. }
  20019. if ( values !== undefined ) {
  20020. if ( AnimationUtils.isTypedArray( values ) ) {
  20021. for ( var i = 0, n = values.length; i !== n; ++ i ) {
  20022. var value = values[ i ];
  20023. if ( isNaN( value ) ) {
  20024. console.error( 'THREE.KeyframeTrack: Value is not a valid number.', this, i, value );
  20025. valid = false;
  20026. break;
  20027. }
  20028. }
  20029. }
  20030. }
  20031. return valid;
  20032. },
  20033. // removes equivalent sequential keys as common in morph target sequences
  20034. // (0,0,0,0,1,1,1,0,0,0,0,0,0,0) --> (0,0,1,1,0,0)
  20035. optimize: function () {
  20036. var times = this.times,
  20037. values = this.values,
  20038. stride = this.getValueSize(),
  20039. smoothInterpolation = this.getInterpolation() === InterpolateSmooth,
  20040. writeIndex = 1,
  20041. lastIndex = times.length - 1;
  20042. for ( var i = 1; i < lastIndex; ++ i ) {
  20043. var keep = false;
  20044. var time = times[ i ];
  20045. var timeNext = times[ i + 1 ];
  20046. // remove adjacent keyframes scheduled at the same time
  20047. if ( time !== timeNext && ( i !== 1 || time !== time[ 0 ] ) ) {
  20048. if ( ! smoothInterpolation ) {
  20049. // remove unnecessary keyframes same as their neighbors
  20050. var offset = i * stride,
  20051. offsetP = offset - stride,
  20052. offsetN = offset + stride;
  20053. for ( var j = 0; j !== stride; ++ j ) {
  20054. var value = values[ offset + j ];
  20055. if ( value !== values[ offsetP + j ] ||
  20056. value !== values[ offsetN + j ] ) {
  20057. keep = true;
  20058. break;
  20059. }
  20060. }
  20061. } else {
  20062. keep = true;
  20063. }
  20064. }
  20065. // in-place compaction
  20066. if ( keep ) {
  20067. if ( i !== writeIndex ) {
  20068. times[ writeIndex ] = times[ i ];
  20069. var readOffset = i * stride,
  20070. writeOffset = writeIndex * stride;
  20071. for ( var j = 0; j !== stride; ++ j ) {
  20072. values[ writeOffset + j ] = values[ readOffset + j ];
  20073. }
  20074. }
  20075. ++ writeIndex;
  20076. }
  20077. }
  20078. // flush last keyframe (compaction looks ahead)
  20079. if ( lastIndex > 0 ) {
  20080. times[ writeIndex ] = times[ lastIndex ];
  20081. for ( var readOffset = lastIndex * stride, writeOffset = writeIndex * stride, j = 0; j !== stride; ++ j ) {
  20082. values[ writeOffset + j ] = values[ readOffset + j ];
  20083. }
  20084. ++ writeIndex;
  20085. }
  20086. if ( writeIndex !== times.length ) {
  20087. this.times = AnimationUtils.arraySlice( times, 0, writeIndex );
  20088. this.values = AnimationUtils.arraySlice( values, 0, writeIndex * stride );
  20089. }
  20090. return this;
  20091. },
  20092. clone: function () {
  20093. var times = AnimationUtils.arraySlice( this.times, 0 );
  20094. var values = AnimationUtils.arraySlice( this.values, 0 );
  20095. var TypedKeyframeTrack = this.constructor;
  20096. var track = new TypedKeyframeTrack( this.name, times, values );
  20097. // Interpolant argument to constructor is not saved, so copy the factory method directly.
  20098. track.createInterpolant = this.createInterpolant;
  20099. return track;
  20100. }
  20101. } );
  20102. /**
  20103. *
  20104. * A Track of Boolean keyframe values.
  20105. *
  20106. *
  20107. * @author Ben Houston / http://clara.io/
  20108. * @author David Sarno / http://lighthaus.us/
  20109. * @author tschw
  20110. */
  20111. function BooleanKeyframeTrack( name, times, values ) {
  20112. KeyframeTrack.call( this, name, times, values );
  20113. }
  20114. BooleanKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), {
  20115. constructor: BooleanKeyframeTrack,
  20116. ValueTypeName: 'bool',
  20117. ValueBufferType: Array,
  20118. DefaultInterpolation: InterpolateDiscrete,
  20119. InterpolantFactoryMethodLinear: undefined,
  20120. InterpolantFactoryMethodSmooth: undefined
  20121. // Note: Actually this track could have a optimized / compressed
  20122. // representation of a single value and a custom interpolant that
  20123. // computes "firstValue ^ isOdd( index )".
  20124. } );
  20125. /**
  20126. *
  20127. * A Track of keyframe values that represent color.
  20128. *
  20129. *
  20130. * @author Ben Houston / http://clara.io/
  20131. * @author David Sarno / http://lighthaus.us/
  20132. * @author tschw
  20133. */
  20134. function ColorKeyframeTrack( name, times, values, interpolation ) {
  20135. KeyframeTrack.call( this, name, times, values, interpolation );
  20136. }
  20137. ColorKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), {
  20138. constructor: ColorKeyframeTrack,
  20139. ValueTypeName: 'color'
  20140. // ValueBufferType is inherited
  20141. // DefaultInterpolation is inherited
  20142. // Note: Very basic implementation and nothing special yet.
  20143. // However, this is the place for color space parameterization.
  20144. } );
  20145. /**
  20146. *
  20147. * A Track of numeric keyframe values.
  20148. *
  20149. * @author Ben Houston / http://clara.io/
  20150. * @author David Sarno / http://lighthaus.us/
  20151. * @author tschw
  20152. */
  20153. function NumberKeyframeTrack( name, times, values, interpolation ) {
  20154. KeyframeTrack.call( this, name, times, values, interpolation );
  20155. }
  20156. NumberKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), {
  20157. constructor: NumberKeyframeTrack,
  20158. ValueTypeName: 'number'
  20159. // ValueBufferType is inherited
  20160. // DefaultInterpolation is inherited
  20161. } );
  20162. /**
  20163. * Spherical linear unit quaternion interpolant.
  20164. *
  20165. * @author tschw
  20166. */
  20167. function QuaternionLinearInterpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  20168. Interpolant.call( this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  20169. }
  20170. QuaternionLinearInterpolant.prototype = Object.assign( Object.create( Interpolant.prototype ), {
  20171. constructor: QuaternionLinearInterpolant,
  20172. interpolate_: function ( i1, t0, t, t1 ) {
  20173. var result = this.resultBuffer,
  20174. values = this.sampleValues,
  20175. stride = this.valueSize,
  20176. offset = i1 * stride,
  20177. alpha = ( t - t0 ) / ( t1 - t0 );
  20178. for ( var end = offset + stride; offset !== end; offset += 4 ) {
  20179. Quaternion.slerpFlat( result, 0, values, offset - stride, values, offset, alpha );
  20180. }
  20181. return result;
  20182. }
  20183. } );
  20184. /**
  20185. *
  20186. * A Track of quaternion keyframe values.
  20187. *
  20188. * @author Ben Houston / http://clara.io/
  20189. * @author David Sarno / http://lighthaus.us/
  20190. * @author tschw
  20191. */
  20192. function QuaternionKeyframeTrack( name, times, values, interpolation ) {
  20193. KeyframeTrack.call( this, name, times, values, interpolation );
  20194. }
  20195. QuaternionKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), {
  20196. constructor: QuaternionKeyframeTrack,
  20197. ValueTypeName: 'quaternion',
  20198. // ValueBufferType is inherited
  20199. DefaultInterpolation: InterpolateLinear,
  20200. InterpolantFactoryMethodLinear: function ( result ) {
  20201. return new QuaternionLinearInterpolant( this.times, this.values, this.getValueSize(), result );
  20202. },
  20203. InterpolantFactoryMethodSmooth: undefined // not yet implemented
  20204. } );
  20205. /**
  20206. *
  20207. * A Track that interpolates Strings
  20208. *
  20209. *
  20210. * @author Ben Houston / http://clara.io/
  20211. * @author David Sarno / http://lighthaus.us/
  20212. * @author tschw
  20213. */
  20214. function StringKeyframeTrack( name, times, values, interpolation ) {
  20215. KeyframeTrack.call( this, name, times, values, interpolation );
  20216. }
  20217. StringKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), {
  20218. constructor: StringKeyframeTrack,
  20219. ValueTypeName: 'string',
  20220. ValueBufferType: Array,
  20221. DefaultInterpolation: InterpolateDiscrete,
  20222. InterpolantFactoryMethodLinear: undefined,
  20223. InterpolantFactoryMethodSmooth: undefined
  20224. } );
  20225. /**
  20226. *
  20227. * A Track of vectored keyframe values.
  20228. *
  20229. *
  20230. * @author Ben Houston / http://clara.io/
  20231. * @author David Sarno / http://lighthaus.us/
  20232. * @author tschw
  20233. */
  20234. function VectorKeyframeTrack( name, times, values, interpolation ) {
  20235. KeyframeTrack.call( this, name, times, values, interpolation );
  20236. }
  20237. VectorKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), {
  20238. constructor: VectorKeyframeTrack,
  20239. ValueTypeName: 'vector'
  20240. // ValueBufferType is inherited
  20241. // DefaultInterpolation is inherited
  20242. } );
  20243. /**
  20244. *
  20245. * Reusable set of Tracks that represent an animation.
  20246. *
  20247. * @author Ben Houston / http://clara.io/
  20248. * @author David Sarno / http://lighthaus.us/
  20249. */
  20250. function AnimationClip( name, duration, tracks ) {
  20251. this.name = name;
  20252. this.tracks = tracks;
  20253. this.duration = ( duration !== undefined ) ? duration : - 1;
  20254. this.uuid = _Math.generateUUID();
  20255. // this means it should figure out its duration by scanning the tracks
  20256. if ( this.duration < 0 ) {
  20257. this.resetDuration();
  20258. }
  20259. }
  20260. function getTrackTypeForValueTypeName( typeName ) {
  20261. switch ( typeName.toLowerCase() ) {
  20262. case 'scalar':
  20263. case 'double':
  20264. case 'float':
  20265. case 'number':
  20266. case 'integer':
  20267. return NumberKeyframeTrack;
  20268. case 'vector':
  20269. case 'vector2':
  20270. case 'vector3':
  20271. case 'vector4':
  20272. return VectorKeyframeTrack;
  20273. case 'color':
  20274. return ColorKeyframeTrack;
  20275. case 'quaternion':
  20276. return QuaternionKeyframeTrack;
  20277. case 'bool':
  20278. case 'boolean':
  20279. return BooleanKeyframeTrack;
  20280. case 'string':
  20281. return StringKeyframeTrack;
  20282. }
  20283. throw new Error( 'THREE.KeyframeTrack: Unsupported typeName: ' + typeName );
  20284. }
  20285. function parseKeyframeTrack( json ) {
  20286. if ( json.type === undefined ) {
  20287. throw new Error( 'THREE.KeyframeTrack: track type undefined, can not parse' );
  20288. }
  20289. var trackType = getTrackTypeForValueTypeName( json.type );
  20290. if ( json.times === undefined ) {
  20291. var times = [], values = [];
  20292. AnimationUtils.flattenJSON( json.keys, times, values, 'value' );
  20293. json.times = times;
  20294. json.values = values;
  20295. }
  20296. // derived classes can define a static parse method
  20297. if ( trackType.parse !== undefined ) {
  20298. return trackType.parse( json );
  20299. } else {
  20300. // by default, we assume a constructor compatible with the base
  20301. return new trackType( json.name, json.times, json.values, json.interpolation );
  20302. }
  20303. }
  20304. Object.assign( AnimationClip, {
  20305. parse: function ( json ) {
  20306. var tracks = [],
  20307. jsonTracks = json.tracks,
  20308. frameTime = 1.0 / ( json.fps || 1.0 );
  20309. for ( var i = 0, n = jsonTracks.length; i !== n; ++ i ) {
  20310. tracks.push( parseKeyframeTrack( jsonTracks[ i ] ).scale( frameTime ) );
  20311. }
  20312. return new AnimationClip( json.name, json.duration, tracks );
  20313. },
  20314. toJSON: function ( clip ) {
  20315. var tracks = [],
  20316. clipTracks = clip.tracks;
  20317. var json = {
  20318. 'name': clip.name,
  20319. 'duration': clip.duration,
  20320. 'tracks': tracks,
  20321. 'uuid': clip.uuid
  20322. };
  20323. for ( var i = 0, n = clipTracks.length; i !== n; ++ i ) {
  20324. tracks.push( KeyframeTrack.toJSON( clipTracks[ i ] ) );
  20325. }
  20326. return json;
  20327. },
  20328. CreateFromMorphTargetSequence: function ( name, morphTargetSequence, fps, noLoop ) {
  20329. var numMorphTargets = morphTargetSequence.length;
  20330. var tracks = [];
  20331. for ( var i = 0; i < numMorphTargets; i ++ ) {
  20332. var times = [];
  20333. var values = [];
  20334. times.push(
  20335. ( i + numMorphTargets - 1 ) % numMorphTargets,
  20336. i,
  20337. ( i + 1 ) % numMorphTargets );
  20338. values.push( 0, 1, 0 );
  20339. var order = AnimationUtils.getKeyframeOrder( times );
  20340. times = AnimationUtils.sortedArray( times, 1, order );
  20341. values = AnimationUtils.sortedArray( values, 1, order );
  20342. // if there is a key at the first frame, duplicate it as the
  20343. // last frame as well for perfect loop.
  20344. if ( ! noLoop && times[ 0 ] === 0 ) {
  20345. times.push( numMorphTargets );
  20346. values.push( values[ 0 ] );
  20347. }
  20348. tracks.push(
  20349. new NumberKeyframeTrack(
  20350. '.morphTargetInfluences[' + morphTargetSequence[ i ].name + ']',
  20351. times, values
  20352. ).scale( 1.0 / fps ) );
  20353. }
  20354. return new AnimationClip( name, - 1, tracks );
  20355. },
  20356. findByName: function ( objectOrClipArray, name ) {
  20357. var clipArray = objectOrClipArray;
  20358. if ( ! Array.isArray( objectOrClipArray ) ) {
  20359. var o = objectOrClipArray;
  20360. clipArray = o.geometry && o.geometry.animations || o.animations;
  20361. }
  20362. for ( var i = 0; i < clipArray.length; i ++ ) {
  20363. if ( clipArray[ i ].name === name ) {
  20364. return clipArray[ i ];
  20365. }
  20366. }
  20367. return null;
  20368. },
  20369. CreateClipsFromMorphTargetSequences: function ( morphTargets, fps, noLoop ) {
  20370. var animationToMorphTargets = {};
  20371. // tested with https://regex101.com/ on trick sequences
  20372. // such flamingo_flyA_003, flamingo_run1_003, crdeath0059
  20373. var pattern = /^([\w-]*?)([\d]+)$/;
  20374. // sort morph target names into animation groups based
  20375. // patterns like Walk_001, Walk_002, Run_001, Run_002
  20376. for ( var i = 0, il = morphTargets.length; i < il; i ++ ) {
  20377. var morphTarget = morphTargets[ i ];
  20378. var parts = morphTarget.name.match( pattern );
  20379. if ( parts && parts.length > 1 ) {
  20380. var name = parts[ 1 ];
  20381. var animationMorphTargets = animationToMorphTargets[ name ];
  20382. if ( ! animationMorphTargets ) {
  20383. animationToMorphTargets[ name ] = animationMorphTargets = [];
  20384. }
  20385. animationMorphTargets.push( morphTarget );
  20386. }
  20387. }
  20388. var clips = [];
  20389. for ( var name in animationToMorphTargets ) {
  20390. clips.push( AnimationClip.CreateFromMorphTargetSequence( name, animationToMorphTargets[ name ], fps, noLoop ) );
  20391. }
  20392. return clips;
  20393. },
  20394. // parse the animation.hierarchy format
  20395. parseAnimation: function ( animation, bones ) {
  20396. if ( ! animation ) {
  20397. console.error( 'THREE.AnimationClip: No animation in JSONLoader data.' );
  20398. return null;
  20399. }
  20400. var addNonemptyTrack = function ( trackType, trackName, animationKeys, propertyName, destTracks ) {
  20401. // only return track if there are actually keys.
  20402. if ( animationKeys.length !== 0 ) {
  20403. var times = [];
  20404. var values = [];
  20405. AnimationUtils.flattenJSON( animationKeys, times, values, propertyName );
  20406. // empty keys are filtered out, so check again
  20407. if ( times.length !== 0 ) {
  20408. destTracks.push( new trackType( trackName, times, values ) );
  20409. }
  20410. }
  20411. };
  20412. var tracks = [];
  20413. var clipName = animation.name || 'default';
  20414. // automatic length determination in AnimationClip.
  20415. var duration = animation.length || - 1;
  20416. var fps = animation.fps || 30;
  20417. var hierarchyTracks = animation.hierarchy || [];
  20418. for ( var h = 0; h < hierarchyTracks.length; h ++ ) {
  20419. var animationKeys = hierarchyTracks[ h ].keys;
  20420. // skip empty tracks
  20421. if ( ! animationKeys || animationKeys.length === 0 ) continue;
  20422. // process morph targets
  20423. if ( animationKeys[ 0 ].morphTargets ) {
  20424. // figure out all morph targets used in this track
  20425. var morphTargetNames = {};
  20426. for ( var k = 0; k < animationKeys.length; k ++ ) {
  20427. if ( animationKeys[ k ].morphTargets ) {
  20428. for ( var m = 0; m < animationKeys[ k ].morphTargets.length; m ++ ) {
  20429. morphTargetNames[ animationKeys[ k ].morphTargets[ m ] ] = - 1;
  20430. }
  20431. }
  20432. }
  20433. // create a track for each morph target with all zero
  20434. // morphTargetInfluences except for the keys in which
  20435. // the morphTarget is named.
  20436. for ( var morphTargetName in morphTargetNames ) {
  20437. var times = [];
  20438. var values = [];
  20439. for ( var m = 0; m !== animationKeys[ k ].morphTargets.length; ++ m ) {
  20440. var animationKey = animationKeys[ k ];
  20441. times.push( animationKey.time );
  20442. values.push( ( animationKey.morphTarget === morphTargetName ) ? 1 : 0 );
  20443. }
  20444. tracks.push( new NumberKeyframeTrack( '.morphTargetInfluence[' + morphTargetName + ']', times, values ) );
  20445. }
  20446. duration = morphTargetNames.length * ( fps || 1.0 );
  20447. } else {
  20448. // ...assume skeletal animation
  20449. var boneName = '.bones[' + bones[ h ].name + ']';
  20450. addNonemptyTrack(
  20451. VectorKeyframeTrack, boneName + '.position',
  20452. animationKeys, 'pos', tracks );
  20453. addNonemptyTrack(
  20454. QuaternionKeyframeTrack, boneName + '.quaternion',
  20455. animationKeys, 'rot', tracks );
  20456. addNonemptyTrack(
  20457. VectorKeyframeTrack, boneName + '.scale',
  20458. animationKeys, 'scl', tracks );
  20459. }
  20460. }
  20461. if ( tracks.length === 0 ) {
  20462. return null;
  20463. }
  20464. var clip = new AnimationClip( clipName, duration, tracks );
  20465. return clip;
  20466. }
  20467. } );
  20468. Object.assign( AnimationClip.prototype, {
  20469. resetDuration: function () {
  20470. var tracks = this.tracks, duration = 0;
  20471. for ( var i = 0, n = tracks.length; i !== n; ++ i ) {
  20472. var track = this.tracks[ i ];
  20473. duration = Math.max( duration, track.times[ track.times.length - 1 ] );
  20474. }
  20475. this.duration = duration;
  20476. return this;
  20477. },
  20478. trim: function () {
  20479. for ( var i = 0; i < this.tracks.length; i ++ ) {
  20480. this.tracks[ i ].trim( 0, this.duration );
  20481. }
  20482. return this;
  20483. },
  20484. validate: function () {
  20485. var valid = true;
  20486. for ( var i = 0; i < this.tracks.length; i ++ ) {
  20487. valid = valid && this.tracks[ i ].validate();
  20488. }
  20489. return valid;
  20490. },
  20491. optimize: function () {
  20492. for ( var i = 0; i < this.tracks.length; i ++ ) {
  20493. this.tracks[ i ].optimize();
  20494. }
  20495. return this;
  20496. },
  20497. clone: function () {
  20498. var tracks = [];
  20499. for ( var i = 0; i < this.tracks.length; i ++ ) {
  20500. tracks.push( this.tracks[ i ].clone() );
  20501. }
  20502. return new AnimationClip( this.name, this.duration, tracks );
  20503. }
  20504. } );
  20505. /**
  20506. * @author mrdoob / http://mrdoob.com/
  20507. */
  20508. var Cache = {
  20509. enabled: false,
  20510. files: {},
  20511. add: function ( key, file ) {
  20512. if ( this.enabled === false ) return;
  20513. // console.log( 'THREE.Cache', 'Adding key:', key );
  20514. this.files[ key ] = file;
  20515. },
  20516. get: function ( key ) {
  20517. if ( this.enabled === false ) return;
  20518. // console.log( 'THREE.Cache', 'Checking key:', key );
  20519. return this.files[ key ];
  20520. },
  20521. remove: function ( key ) {
  20522. delete this.files[ key ];
  20523. },
  20524. clear: function () {
  20525. this.files = {};
  20526. }
  20527. };
  20528. /**
  20529. * @author mrdoob / http://mrdoob.com/
  20530. */
  20531. function LoadingManager( onLoad, onProgress, onError ) {
  20532. var scope = this;
  20533. var isLoading = false;
  20534. var itemsLoaded = 0;
  20535. var itemsTotal = 0;
  20536. var urlModifier = undefined;
  20537. // Refer to #5689 for the reason why we don't set .onStart
  20538. // in the constructor
  20539. this.onStart = undefined;
  20540. this.onLoad = onLoad;
  20541. this.onProgress = onProgress;
  20542. this.onError = onError;
  20543. this.itemStart = function ( url ) {
  20544. itemsTotal ++;
  20545. if ( isLoading === false ) {
  20546. if ( scope.onStart !== undefined ) {
  20547. scope.onStart( url, itemsLoaded, itemsTotal );
  20548. }
  20549. }
  20550. isLoading = true;
  20551. };
  20552. this.itemEnd = function ( url ) {
  20553. itemsLoaded ++;
  20554. if ( scope.onProgress !== undefined ) {
  20555. scope.onProgress( url, itemsLoaded, itemsTotal );
  20556. }
  20557. if ( itemsLoaded === itemsTotal ) {
  20558. isLoading = false;
  20559. if ( scope.onLoad !== undefined ) {
  20560. scope.onLoad();
  20561. }
  20562. }
  20563. };
  20564. this.itemError = function ( url ) {
  20565. if ( scope.onError !== undefined ) {
  20566. scope.onError( url );
  20567. }
  20568. };
  20569. this.resolveURL = function ( url ) {
  20570. if ( urlModifier ) {
  20571. return urlModifier( url );
  20572. }
  20573. return url;
  20574. };
  20575. this.setURLModifier = function ( transform ) {
  20576. urlModifier = transform;
  20577. return this;
  20578. };
  20579. }
  20580. var DefaultLoadingManager = new LoadingManager();
  20581. /**
  20582. * @author mrdoob / http://mrdoob.com/
  20583. */
  20584. var loading = {};
  20585. function FileLoader( manager ) {
  20586. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  20587. }
  20588. Object.assign( FileLoader.prototype, {
  20589. load: function ( url, onLoad, onProgress, onError ) {
  20590. if ( url === undefined ) url = '';
  20591. if ( this.path !== undefined ) url = this.path + url;
  20592. url = this.manager.resolveURL( url );
  20593. var scope = this;
  20594. var cached = Cache.get( url );
  20595. if ( cached !== undefined ) {
  20596. scope.manager.itemStart( url );
  20597. setTimeout( function () {
  20598. if ( onLoad ) onLoad( cached );
  20599. scope.manager.itemEnd( url );
  20600. }, 0 );
  20601. return cached;
  20602. }
  20603. // Check if request is duplicate
  20604. if ( loading[ url ] !== undefined ) {
  20605. loading[ url ].push( {
  20606. onLoad: onLoad,
  20607. onProgress: onProgress,
  20608. onError: onError
  20609. } );
  20610. return;
  20611. }
  20612. // Check for data: URI
  20613. var dataUriRegex = /^data:(.*?)(;base64)?,(.*)$/;
  20614. var dataUriRegexResult = url.match( dataUriRegex );
  20615. // Safari can not handle Data URIs through XMLHttpRequest so process manually
  20616. if ( dataUriRegexResult ) {
  20617. var mimeType = dataUriRegexResult[ 1 ];
  20618. var isBase64 = !! dataUriRegexResult[ 2 ];
  20619. var data = dataUriRegexResult[ 3 ];
  20620. data = decodeURIComponent( data );
  20621. if ( isBase64 ) data = atob( data );
  20622. try {
  20623. var response;
  20624. var responseType = ( this.responseType || '' ).toLowerCase();
  20625. switch ( responseType ) {
  20626. case 'arraybuffer':
  20627. case 'blob':
  20628. var view = new Uint8Array( data.length );
  20629. for ( var i = 0; i < data.length; i ++ ) {
  20630. view[ i ] = data.charCodeAt( i );
  20631. }
  20632. if ( responseType === 'blob' ) {
  20633. response = new Blob( [ view.buffer ], { type: mimeType } );
  20634. } else {
  20635. response = view.buffer;
  20636. }
  20637. break;
  20638. case 'document':
  20639. var parser = new DOMParser();
  20640. response = parser.parseFromString( data, mimeType );
  20641. break;
  20642. case 'json':
  20643. response = JSON.parse( data );
  20644. break;
  20645. default: // 'text' or other
  20646. response = data;
  20647. break;
  20648. }
  20649. // Wait for next browser tick like standard XMLHttpRequest event dispatching does
  20650. setTimeout( function () {
  20651. if ( onLoad ) onLoad( response );
  20652. scope.manager.itemEnd( url );
  20653. }, 0 );
  20654. } catch ( error ) {
  20655. // Wait for next browser tick like standard XMLHttpRequest event dispatching does
  20656. setTimeout( function () {
  20657. if ( onError ) onError( error );
  20658. scope.manager.itemError( url );
  20659. scope.manager.itemEnd( url );
  20660. }, 0 );
  20661. }
  20662. } else {
  20663. // Initialise array for duplicate requests
  20664. loading[ url ] = [];
  20665. loading[ url ].push( {
  20666. onLoad: onLoad,
  20667. onProgress: onProgress,
  20668. onError: onError
  20669. } );
  20670. var request = new XMLHttpRequest();
  20671. request.open( 'GET', url, true );
  20672. request.addEventListener( 'load', function ( event ) {
  20673. var response = this.response;
  20674. Cache.add( url, response );
  20675. var callbacks = loading[ url ];
  20676. delete loading[ url ];
  20677. if ( this.status === 200 || this.status === 0 ) {
  20678. // Some browsers return HTTP Status 0 when using non-http protocol
  20679. // e.g. 'file://' or 'data://'. Handle as success.
  20680. if ( this.status === 0 ) console.warn( 'THREE.FileLoader: HTTP Status 0 received.' );
  20681. for ( var i = 0, il = callbacks.length; i < il; i ++ ) {
  20682. var callback = callbacks[ i ];
  20683. if ( callback.onLoad ) callback.onLoad( response );
  20684. }
  20685. scope.manager.itemEnd( url );
  20686. } else {
  20687. for ( var i = 0, il = callbacks.length; i < il; i ++ ) {
  20688. var callback = callbacks[ i ];
  20689. if ( callback.onError ) callback.onError( event );
  20690. }
  20691. scope.manager.itemError( url );
  20692. scope.manager.itemEnd( url );
  20693. }
  20694. }, false );
  20695. request.addEventListener( 'progress', function ( event ) {
  20696. var callbacks = loading[ url ];
  20697. for ( var i = 0, il = callbacks.length; i < il; i ++ ) {
  20698. var callback = callbacks[ i ];
  20699. if ( callback.onProgress ) callback.onProgress( event );
  20700. }
  20701. }, false );
  20702. request.addEventListener( 'error', function ( event ) {
  20703. var callbacks = loading[ url ];
  20704. delete loading[ url ];
  20705. for ( var i = 0, il = callbacks.length; i < il; i ++ ) {
  20706. var callback = callbacks[ i ];
  20707. if ( callback.onError ) callback.onError( event );
  20708. }
  20709. scope.manager.itemError( url );
  20710. scope.manager.itemEnd( url );
  20711. }, false );
  20712. request.addEventListener( 'abort', function ( event ) {
  20713. var callbacks = loading[ url ];
  20714. delete loading[ url ];
  20715. for ( var i = 0, il = callbacks.length; i < il; i ++ ) {
  20716. var callback = callbacks[ i ];
  20717. if ( callback.onError ) callback.onError( event );
  20718. }
  20719. scope.manager.itemError( url );
  20720. scope.manager.itemEnd( url );
  20721. }, false );
  20722. if ( this.responseType !== undefined ) request.responseType = this.responseType;
  20723. if ( this.withCredentials !== undefined ) request.withCredentials = this.withCredentials;
  20724. if ( request.overrideMimeType ) request.overrideMimeType( this.mimeType !== undefined ? this.mimeType : 'text/plain' );
  20725. for ( var header in this.requestHeader ) {
  20726. request.setRequestHeader( header, this.requestHeader[ header ] );
  20727. }
  20728. request.send( null );
  20729. }
  20730. scope.manager.itemStart( url );
  20731. return request;
  20732. },
  20733. setPath: function ( value ) {
  20734. this.path = value;
  20735. return this;
  20736. },
  20737. setResponseType: function ( value ) {
  20738. this.responseType = value;
  20739. return this;
  20740. },
  20741. setWithCredentials: function ( value ) {
  20742. this.withCredentials = value;
  20743. return this;
  20744. },
  20745. setMimeType: function ( value ) {
  20746. this.mimeType = value;
  20747. return this;
  20748. },
  20749. setRequestHeader: function ( value ) {
  20750. this.requestHeader = value;
  20751. return this;
  20752. }
  20753. } );
  20754. /**
  20755. * @author bhouston / http://clara.io/
  20756. */
  20757. function AnimationLoader( manager ) {
  20758. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  20759. }
  20760. Object.assign( AnimationLoader.prototype, {
  20761. load: function ( url, onLoad, onProgress, onError ) {
  20762. var scope = this;
  20763. var loader = new FileLoader( scope.manager );
  20764. loader.setPath( scope.path );
  20765. loader.load( url, function ( text ) {
  20766. onLoad( scope.parse( JSON.parse( text ) ) );
  20767. }, onProgress, onError );
  20768. },
  20769. parse: function ( json ) {
  20770. var animations = [];
  20771. for ( var i = 0; i < json.length; i ++ ) {
  20772. var clip = AnimationClip.parse( json[ i ] );
  20773. animations.push( clip );
  20774. }
  20775. return animations;
  20776. },
  20777. setPath: function ( value ) {
  20778. this.path = value;
  20779. return this;
  20780. }
  20781. } );
  20782. /**
  20783. * @author mrdoob / http://mrdoob.com/
  20784. *
  20785. * Abstract Base class to block based textures loader (dds, pvr, ...)
  20786. */
  20787. function CompressedTextureLoader( manager ) {
  20788. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  20789. // override in sub classes
  20790. this._parser = null;
  20791. }
  20792. Object.assign( CompressedTextureLoader.prototype, {
  20793. load: function ( url, onLoad, onProgress, onError ) {
  20794. var scope = this;
  20795. var images = [];
  20796. var texture = new CompressedTexture();
  20797. texture.image = images;
  20798. var loader = new FileLoader( this.manager );
  20799. loader.setPath( this.path );
  20800. loader.setResponseType( 'arraybuffer' );
  20801. function loadTexture( i ) {
  20802. loader.load( url[ i ], function ( buffer ) {
  20803. var texDatas = scope._parser( buffer, true );
  20804. images[ i ] = {
  20805. width: texDatas.width,
  20806. height: texDatas.height,
  20807. format: texDatas.format,
  20808. mipmaps: texDatas.mipmaps
  20809. };
  20810. loaded += 1;
  20811. if ( loaded === 6 ) {
  20812. if ( texDatas.mipmapCount === 1 )
  20813. texture.minFilter = LinearFilter;
  20814. texture.format = texDatas.format;
  20815. texture.needsUpdate = true;
  20816. if ( onLoad ) onLoad( texture );
  20817. }
  20818. }, onProgress, onError );
  20819. }
  20820. if ( Array.isArray( url ) ) {
  20821. var loaded = 0;
  20822. for ( var i = 0, il = url.length; i < il; ++ i ) {
  20823. loadTexture( i );
  20824. }
  20825. } else {
  20826. // compressed cubemap texture stored in a single DDS file
  20827. loader.load( url, function ( buffer ) {
  20828. var texDatas = scope._parser( buffer, true );
  20829. if ( texDatas.isCubemap ) {
  20830. var faces = texDatas.mipmaps.length / texDatas.mipmapCount;
  20831. for ( var f = 0; f < faces; f ++ ) {
  20832. images[ f ] = { mipmaps: [] };
  20833. for ( var i = 0; i < texDatas.mipmapCount; i ++ ) {
  20834. images[ f ].mipmaps.push( texDatas.mipmaps[ f * texDatas.mipmapCount + i ] );
  20835. images[ f ].format = texDatas.format;
  20836. images[ f ].width = texDatas.width;
  20837. images[ f ].height = texDatas.height;
  20838. }
  20839. }
  20840. } else {
  20841. texture.image.width = texDatas.width;
  20842. texture.image.height = texDatas.height;
  20843. texture.mipmaps = texDatas.mipmaps;
  20844. }
  20845. if ( texDatas.mipmapCount === 1 ) {
  20846. texture.minFilter = LinearFilter;
  20847. }
  20848. texture.format = texDatas.format;
  20849. texture.needsUpdate = true;
  20850. if ( onLoad ) onLoad( texture );
  20851. }, onProgress, onError );
  20852. }
  20853. return texture;
  20854. },
  20855. setPath: function ( value ) {
  20856. this.path = value;
  20857. return this;
  20858. }
  20859. } );
  20860. /**
  20861. * @author Nikos M. / https://github.com/foo123/
  20862. *
  20863. * Abstract Base class to load generic binary textures formats (rgbe, hdr, ...)
  20864. */
  20865. function DataTextureLoader( manager ) {
  20866. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  20867. // override in sub classes
  20868. this._parser = null;
  20869. }
  20870. Object.assign( DataTextureLoader.prototype, {
  20871. load: function ( url, onLoad, onProgress, onError ) {
  20872. var scope = this;
  20873. var texture = new DataTexture();
  20874. var loader = new FileLoader( this.manager );
  20875. loader.setResponseType( 'arraybuffer' );
  20876. loader.setPath( this.path );
  20877. loader.load( url, function ( buffer ) {
  20878. var texData = scope._parser( buffer );
  20879. if ( ! texData ) return;
  20880. if ( texData.image !== undefined ) {
  20881. texture.image = texData.image;
  20882. } else if ( texData.data !== undefined ) {
  20883. texture.image.width = texData.width;
  20884. texture.image.height = texData.height;
  20885. texture.image.data = texData.data;
  20886. }
  20887. texture.wrapS = texData.wrapS !== undefined ? texData.wrapS : ClampToEdgeWrapping;
  20888. texture.wrapT = texData.wrapT !== undefined ? texData.wrapT : ClampToEdgeWrapping;
  20889. texture.magFilter = texData.magFilter !== undefined ? texData.magFilter : LinearFilter;
  20890. texture.minFilter = texData.minFilter !== undefined ? texData.minFilter : LinearMipMapLinearFilter;
  20891. texture.anisotropy = texData.anisotropy !== undefined ? texData.anisotropy : 1;
  20892. if ( texData.format !== undefined ) {
  20893. texture.format = texData.format;
  20894. }
  20895. if ( texData.type !== undefined ) {
  20896. texture.type = texData.type;
  20897. }
  20898. if ( texData.mipmaps !== undefined ) {
  20899. texture.mipmaps = texData.mipmaps;
  20900. }
  20901. if ( texData.mipmapCount === 1 ) {
  20902. texture.minFilter = LinearFilter;
  20903. }
  20904. texture.needsUpdate = true;
  20905. if ( onLoad ) onLoad( texture, texData );
  20906. }, onProgress, onError );
  20907. return texture;
  20908. },
  20909. setPath: function ( value ) {
  20910. this.path = value;
  20911. return this;
  20912. }
  20913. } );
  20914. /**
  20915. * @author mrdoob / http://mrdoob.com/
  20916. */
  20917. function ImageLoader( manager ) {
  20918. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  20919. }
  20920. Object.assign( ImageLoader.prototype, {
  20921. crossOrigin: 'anonymous',
  20922. load: function ( url, onLoad, onProgress, onError ) {
  20923. if ( url === undefined ) url = '';
  20924. if ( this.path !== undefined ) url = this.path + url;
  20925. url = this.manager.resolveURL( url );
  20926. var scope = this;
  20927. var cached = Cache.get( url );
  20928. if ( cached !== undefined ) {
  20929. scope.manager.itemStart( url );
  20930. setTimeout( function () {
  20931. if ( onLoad ) onLoad( cached );
  20932. scope.manager.itemEnd( url );
  20933. }, 0 );
  20934. return cached;
  20935. }
  20936. var image = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'img' );
  20937. function onImageLoad() {
  20938. image.removeEventListener( 'load', onImageLoad, false );
  20939. image.removeEventListener( 'error', onImageError, false );
  20940. Cache.add( url, this );
  20941. if ( onLoad ) onLoad( this );
  20942. scope.manager.itemEnd( url );
  20943. }
  20944. function onImageError( event ) {
  20945. image.removeEventListener( 'load', onImageLoad, false );
  20946. image.removeEventListener( 'error', onImageError, false );
  20947. if ( onError ) onError( event );
  20948. scope.manager.itemError( url );
  20949. scope.manager.itemEnd( url );
  20950. }
  20951. image.addEventListener( 'load', onImageLoad, false );
  20952. image.addEventListener( 'error', onImageError, false );
  20953. if ( url.substr( 0, 5 ) !== 'data:' ) {
  20954. if ( this.crossOrigin !== undefined ) image.crossOrigin = this.crossOrigin;
  20955. }
  20956. scope.manager.itemStart( url );
  20957. image.src = url;
  20958. return image;
  20959. },
  20960. setCrossOrigin: function ( value ) {
  20961. this.crossOrigin = value;
  20962. return this;
  20963. },
  20964. setPath: function ( value ) {
  20965. this.path = value;
  20966. return this;
  20967. }
  20968. } );
  20969. /**
  20970. * @author mrdoob / http://mrdoob.com/
  20971. */
  20972. function CubeTextureLoader( manager ) {
  20973. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  20974. }
  20975. Object.assign( CubeTextureLoader.prototype, {
  20976. crossOrigin: 'anonymous',
  20977. load: function ( urls, onLoad, onProgress, onError ) {
  20978. var texture = new CubeTexture();
  20979. var loader = new ImageLoader( this.manager );
  20980. loader.setCrossOrigin( this.crossOrigin );
  20981. loader.setPath( this.path );
  20982. var loaded = 0;
  20983. function loadTexture( i ) {
  20984. loader.load( urls[ i ], function ( image ) {
  20985. texture.images[ i ] = image;
  20986. loaded ++;
  20987. if ( loaded === 6 ) {
  20988. texture.needsUpdate = true;
  20989. if ( onLoad ) onLoad( texture );
  20990. }
  20991. }, undefined, onError );
  20992. }
  20993. for ( var i = 0; i < urls.length; ++ i ) {
  20994. loadTexture( i );
  20995. }
  20996. return texture;
  20997. },
  20998. setCrossOrigin: function ( value ) {
  20999. this.crossOrigin = value;
  21000. return this;
  21001. },
  21002. setPath: function ( value ) {
  21003. this.path = value;
  21004. return this;
  21005. }
  21006. } );
  21007. /**
  21008. * @author mrdoob / http://mrdoob.com/
  21009. */
  21010. function TextureLoader( manager ) {
  21011. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  21012. }
  21013. Object.assign( TextureLoader.prototype, {
  21014. crossOrigin: 'anonymous',
  21015. load: function ( url, onLoad, onProgress, onError ) {
  21016. var texture = new Texture();
  21017. var loader = new ImageLoader( this.manager );
  21018. loader.setCrossOrigin( this.crossOrigin );
  21019. loader.setPath( this.path );
  21020. loader.load( url, function ( image ) {
  21021. texture.image = image;
  21022. // JPEGs can't have an alpha channel, so memory can be saved by storing them as RGB.
  21023. var isJPEG = url.search( /\.jpe?g($|\?)/i ) > 0 || url.search( /^data\:image\/jpeg/ ) === 0;
  21024. texture.format = isJPEG ? RGBFormat : RGBAFormat;
  21025. texture.needsUpdate = true;
  21026. if ( onLoad !== undefined ) {
  21027. onLoad( texture );
  21028. }
  21029. }, onProgress, onError );
  21030. return texture;
  21031. },
  21032. setCrossOrigin: function ( value ) {
  21033. this.crossOrigin = value;
  21034. return this;
  21035. },
  21036. setPath: function ( value ) {
  21037. this.path = value;
  21038. return this;
  21039. }
  21040. } );
  21041. /**
  21042. * @author zz85 / http://www.lab4games.net/zz85/blog
  21043. * Extensible curve object
  21044. *
  21045. * Some common of curve methods:
  21046. * .getPoint( t, optionalTarget ), .getTangent( t )
  21047. * .getPointAt( u, optionalTarget ), .getTangentAt( u )
  21048. * .getPoints(), .getSpacedPoints()
  21049. * .getLength()
  21050. * .updateArcLengths()
  21051. *
  21052. * This following curves inherit from THREE.Curve:
  21053. *
  21054. * -- 2D curves --
  21055. * THREE.ArcCurve
  21056. * THREE.CubicBezierCurve
  21057. * THREE.EllipseCurve
  21058. * THREE.LineCurve
  21059. * THREE.QuadraticBezierCurve
  21060. * THREE.SplineCurve
  21061. *
  21062. * -- 3D curves --
  21063. * THREE.CatmullRomCurve3
  21064. * THREE.CubicBezierCurve3
  21065. * THREE.LineCurve3
  21066. * THREE.QuadraticBezierCurve3
  21067. *
  21068. * A series of curves can be represented as a THREE.CurvePath.
  21069. *
  21070. **/
  21071. /**************************************************************
  21072. * Abstract Curve base class
  21073. **************************************************************/
  21074. function Curve() {
  21075. this.type = 'Curve';
  21076. this.arcLengthDivisions = 200;
  21077. }
  21078. Object.assign( Curve.prototype, {
  21079. // Virtual base class method to overwrite and implement in subclasses
  21080. // - t [0 .. 1]
  21081. getPoint: function ( /* t, optionalTarget */ ) {
  21082. console.warn( 'THREE.Curve: .getPoint() not implemented.' );
  21083. return null;
  21084. },
  21085. // Get point at relative position in curve according to arc length
  21086. // - u [0 .. 1]
  21087. getPointAt: function ( u, optionalTarget ) {
  21088. var t = this.getUtoTmapping( u );
  21089. return this.getPoint( t, optionalTarget );
  21090. },
  21091. // Get sequence of points using getPoint( t )
  21092. getPoints: function ( divisions ) {
  21093. if ( divisions === undefined ) divisions = 5;
  21094. var points = [];
  21095. for ( var d = 0; d <= divisions; d ++ ) {
  21096. points.push( this.getPoint( d / divisions ) );
  21097. }
  21098. return points;
  21099. },
  21100. // Get sequence of points using getPointAt( u )
  21101. getSpacedPoints: function ( divisions ) {
  21102. if ( divisions === undefined ) divisions = 5;
  21103. var points = [];
  21104. for ( var d = 0; d <= divisions; d ++ ) {
  21105. points.push( this.getPointAt( d / divisions ) );
  21106. }
  21107. return points;
  21108. },
  21109. // Get total curve arc length
  21110. getLength: function () {
  21111. var lengths = this.getLengths();
  21112. return lengths[ lengths.length - 1 ];
  21113. },
  21114. // Get list of cumulative segment lengths
  21115. getLengths: function ( divisions ) {
  21116. if ( divisions === undefined ) divisions = this.arcLengthDivisions;
  21117. if ( this.cacheArcLengths &&
  21118. ( this.cacheArcLengths.length === divisions + 1 ) &&
  21119. ! this.needsUpdate ) {
  21120. return this.cacheArcLengths;
  21121. }
  21122. this.needsUpdate = false;
  21123. var cache = [];
  21124. var current, last = this.getPoint( 0 );
  21125. var p, sum = 0;
  21126. cache.push( 0 );
  21127. for ( p = 1; p <= divisions; p ++ ) {
  21128. current = this.getPoint( p / divisions );
  21129. sum += current.distanceTo( last );
  21130. cache.push( sum );
  21131. last = current;
  21132. }
  21133. this.cacheArcLengths = cache;
  21134. return cache; // { sums: cache, sum: sum }; Sum is in the last element.
  21135. },
  21136. updateArcLengths: function () {
  21137. this.needsUpdate = true;
  21138. this.getLengths();
  21139. },
  21140. // Given u ( 0 .. 1 ), get a t to find p. This gives you points which are equidistant
  21141. getUtoTmapping: function ( u, distance ) {
  21142. var arcLengths = this.getLengths();
  21143. var i = 0, il = arcLengths.length;
  21144. var targetArcLength; // The targeted u distance value to get
  21145. if ( distance ) {
  21146. targetArcLength = distance;
  21147. } else {
  21148. targetArcLength = u * arcLengths[ il - 1 ];
  21149. }
  21150. // binary search for the index with largest value smaller than target u distance
  21151. var low = 0, high = il - 1, comparison;
  21152. while ( low <= high ) {
  21153. 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
  21154. comparison = arcLengths[ i ] - targetArcLength;
  21155. if ( comparison < 0 ) {
  21156. low = i + 1;
  21157. } else if ( comparison > 0 ) {
  21158. high = i - 1;
  21159. } else {
  21160. high = i;
  21161. break;
  21162. // DONE
  21163. }
  21164. }
  21165. i = high;
  21166. if ( arcLengths[ i ] === targetArcLength ) {
  21167. return i / ( il - 1 );
  21168. }
  21169. // we could get finer grain at lengths, or use simple interpolation between two points
  21170. var lengthBefore = arcLengths[ i ];
  21171. var lengthAfter = arcLengths[ i + 1 ];
  21172. var segmentLength = lengthAfter - lengthBefore;
  21173. // determine where we are between the 'before' and 'after' points
  21174. var segmentFraction = ( targetArcLength - lengthBefore ) / segmentLength;
  21175. // add that fractional amount to t
  21176. var t = ( i + segmentFraction ) / ( il - 1 );
  21177. return t;
  21178. },
  21179. // Returns a unit vector tangent at t
  21180. // In case any sub curve does not implement its tangent derivation,
  21181. // 2 points a small delta apart will be used to find its gradient
  21182. // which seems to give a reasonable approximation
  21183. getTangent: function ( t ) {
  21184. var delta = 0.0001;
  21185. var t1 = t - delta;
  21186. var t2 = t + delta;
  21187. // Capping in case of danger
  21188. if ( t1 < 0 ) t1 = 0;
  21189. if ( t2 > 1 ) t2 = 1;
  21190. var pt1 = this.getPoint( t1 );
  21191. var pt2 = this.getPoint( t2 );
  21192. var vec = pt2.clone().sub( pt1 );
  21193. return vec.normalize();
  21194. },
  21195. getTangentAt: function ( u ) {
  21196. var t = this.getUtoTmapping( u );
  21197. return this.getTangent( t );
  21198. },
  21199. computeFrenetFrames: function ( segments, closed ) {
  21200. // see http://www.cs.indiana.edu/pub/techreports/TR425.pdf
  21201. var normal = new Vector3();
  21202. var tangents = [];
  21203. var normals = [];
  21204. var binormals = [];
  21205. var vec = new Vector3();
  21206. var mat = new Matrix4();
  21207. var i, u, theta;
  21208. // compute the tangent vectors for each segment on the curve
  21209. for ( i = 0; i <= segments; i ++ ) {
  21210. u = i / segments;
  21211. tangents[ i ] = this.getTangentAt( u );
  21212. tangents[ i ].normalize();
  21213. }
  21214. // select an initial normal vector perpendicular to the first tangent vector,
  21215. // and in the direction of the minimum tangent xyz component
  21216. normals[ 0 ] = new Vector3();
  21217. binormals[ 0 ] = new Vector3();
  21218. var min = Number.MAX_VALUE;
  21219. var tx = Math.abs( tangents[ 0 ].x );
  21220. var ty = Math.abs( tangents[ 0 ].y );
  21221. var tz = Math.abs( tangents[ 0 ].z );
  21222. if ( tx <= min ) {
  21223. min = tx;
  21224. normal.set( 1, 0, 0 );
  21225. }
  21226. if ( ty <= min ) {
  21227. min = ty;
  21228. normal.set( 0, 1, 0 );
  21229. }
  21230. if ( tz <= min ) {
  21231. normal.set( 0, 0, 1 );
  21232. }
  21233. vec.crossVectors( tangents[ 0 ], normal ).normalize();
  21234. normals[ 0 ].crossVectors( tangents[ 0 ], vec );
  21235. binormals[ 0 ].crossVectors( tangents[ 0 ], normals[ 0 ] );
  21236. // compute the slowly-varying normal and binormal vectors for each segment on the curve
  21237. for ( i = 1; i <= segments; i ++ ) {
  21238. normals[ i ] = normals[ i - 1 ].clone();
  21239. binormals[ i ] = binormals[ i - 1 ].clone();
  21240. vec.crossVectors( tangents[ i - 1 ], tangents[ i ] );
  21241. if ( vec.length() > Number.EPSILON ) {
  21242. vec.normalize();
  21243. theta = Math.acos( _Math.clamp( tangents[ i - 1 ].dot( tangents[ i ] ), - 1, 1 ) ); // clamp for floating pt errors
  21244. normals[ i ].applyMatrix4( mat.makeRotationAxis( vec, theta ) );
  21245. }
  21246. binormals[ i ].crossVectors( tangents[ i ], normals[ i ] );
  21247. }
  21248. // if the curve is closed, postprocess the vectors so the first and last normal vectors are the same
  21249. if ( closed === true ) {
  21250. theta = Math.acos( _Math.clamp( normals[ 0 ].dot( normals[ segments ] ), - 1, 1 ) );
  21251. theta /= segments;
  21252. if ( tangents[ 0 ].dot( vec.crossVectors( normals[ 0 ], normals[ segments ] ) ) > 0 ) {
  21253. theta = - theta;
  21254. }
  21255. for ( i = 1; i <= segments; i ++ ) {
  21256. // twist a little...
  21257. normals[ i ].applyMatrix4( mat.makeRotationAxis( tangents[ i ], theta * i ) );
  21258. binormals[ i ].crossVectors( tangents[ i ], normals[ i ] );
  21259. }
  21260. }
  21261. return {
  21262. tangents: tangents,
  21263. normals: normals,
  21264. binormals: binormals
  21265. };
  21266. },
  21267. clone: function () {
  21268. return new this.constructor().copy( this );
  21269. },
  21270. copy: function ( source ) {
  21271. this.arcLengthDivisions = source.arcLengthDivisions;
  21272. return this;
  21273. },
  21274. toJSON: function () {
  21275. var data = {
  21276. metadata: {
  21277. version: 4.5,
  21278. type: 'Curve',
  21279. generator: 'Curve.toJSON'
  21280. }
  21281. };
  21282. data.arcLengthDivisions = this.arcLengthDivisions;
  21283. data.type = this.type;
  21284. return data;
  21285. },
  21286. fromJSON: function ( json ) {
  21287. this.arcLengthDivisions = json.arcLengthDivisions;
  21288. return this;
  21289. }
  21290. } );
  21291. function EllipseCurve( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  21292. Curve.call( this );
  21293. this.type = 'EllipseCurve';
  21294. this.aX = aX || 0;
  21295. this.aY = aY || 0;
  21296. this.xRadius = xRadius || 1;
  21297. this.yRadius = yRadius || 1;
  21298. this.aStartAngle = aStartAngle || 0;
  21299. this.aEndAngle = aEndAngle || 2 * Math.PI;
  21300. this.aClockwise = aClockwise || false;
  21301. this.aRotation = aRotation || 0;
  21302. }
  21303. EllipseCurve.prototype = Object.create( Curve.prototype );
  21304. EllipseCurve.prototype.constructor = EllipseCurve;
  21305. EllipseCurve.prototype.isEllipseCurve = true;
  21306. EllipseCurve.prototype.getPoint = function ( t, optionalTarget ) {
  21307. var point = optionalTarget || new Vector2();
  21308. var twoPi = Math.PI * 2;
  21309. var deltaAngle = this.aEndAngle - this.aStartAngle;
  21310. var samePoints = Math.abs( deltaAngle ) < Number.EPSILON;
  21311. // ensures that deltaAngle is 0 .. 2 PI
  21312. while ( deltaAngle < 0 ) deltaAngle += twoPi;
  21313. while ( deltaAngle > twoPi ) deltaAngle -= twoPi;
  21314. if ( deltaAngle < Number.EPSILON ) {
  21315. if ( samePoints ) {
  21316. deltaAngle = 0;
  21317. } else {
  21318. deltaAngle = twoPi;
  21319. }
  21320. }
  21321. if ( this.aClockwise === true && ! samePoints ) {
  21322. if ( deltaAngle === twoPi ) {
  21323. deltaAngle = - twoPi;
  21324. } else {
  21325. deltaAngle = deltaAngle - twoPi;
  21326. }
  21327. }
  21328. var angle = this.aStartAngle + t * deltaAngle;
  21329. var x = this.aX + this.xRadius * Math.cos( angle );
  21330. var y = this.aY + this.yRadius * Math.sin( angle );
  21331. if ( this.aRotation !== 0 ) {
  21332. var cos = Math.cos( this.aRotation );
  21333. var sin = Math.sin( this.aRotation );
  21334. var tx = x - this.aX;
  21335. var ty = y - this.aY;
  21336. // Rotate the point about the center of the ellipse.
  21337. x = tx * cos - ty * sin + this.aX;
  21338. y = tx * sin + ty * cos + this.aY;
  21339. }
  21340. return point.set( x, y );
  21341. };
  21342. EllipseCurve.prototype.copy = function ( source ) {
  21343. Curve.prototype.copy.call( this, source );
  21344. this.aX = source.aX;
  21345. this.aY = source.aY;
  21346. this.xRadius = source.xRadius;
  21347. this.yRadius = source.yRadius;
  21348. this.aStartAngle = source.aStartAngle;
  21349. this.aEndAngle = source.aEndAngle;
  21350. this.aClockwise = source.aClockwise;
  21351. this.aRotation = source.aRotation;
  21352. return this;
  21353. };
  21354. EllipseCurve.prototype.toJSON = function () {
  21355. var data = Curve.prototype.toJSON.call( this );
  21356. data.aX = this.aX;
  21357. data.aY = this.aY;
  21358. data.xRadius = this.xRadius;
  21359. data.yRadius = this.yRadius;
  21360. data.aStartAngle = this.aStartAngle;
  21361. data.aEndAngle = this.aEndAngle;
  21362. data.aClockwise = this.aClockwise;
  21363. data.aRotation = this.aRotation;
  21364. return data;
  21365. };
  21366. EllipseCurve.prototype.fromJSON = function ( json ) {
  21367. Curve.prototype.fromJSON.call( this, json );
  21368. this.aX = json.aX;
  21369. this.aY = json.aY;
  21370. this.xRadius = json.xRadius;
  21371. this.yRadius = json.yRadius;
  21372. this.aStartAngle = json.aStartAngle;
  21373. this.aEndAngle = json.aEndAngle;
  21374. this.aClockwise = json.aClockwise;
  21375. this.aRotation = json.aRotation;
  21376. return this;
  21377. };
  21378. function ArcCurve( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  21379. EllipseCurve.call( this, aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise );
  21380. this.type = 'ArcCurve';
  21381. }
  21382. ArcCurve.prototype = Object.create( EllipseCurve.prototype );
  21383. ArcCurve.prototype.constructor = ArcCurve;
  21384. ArcCurve.prototype.isArcCurve = true;
  21385. /**
  21386. * @author zz85 https://github.com/zz85
  21387. *
  21388. * Centripetal CatmullRom Curve - which is useful for avoiding
  21389. * cusps and self-intersections in non-uniform catmull rom curves.
  21390. * http://www.cemyuksel.com/research/catmullrom_param/catmullrom.pdf
  21391. *
  21392. * curve.type accepts centripetal(default), chordal and catmullrom
  21393. * curve.tension is used for catmullrom which defaults to 0.5
  21394. */
  21395. /*
  21396. Based on an optimized c++ solution in
  21397. - http://stackoverflow.com/questions/9489736/catmull-rom-curve-with-no-cusps-and-no-self-intersections/
  21398. - http://ideone.com/NoEbVM
  21399. This CubicPoly class could be used for reusing some variables and calculations,
  21400. but for three.js curve use, it could be possible inlined and flatten into a single function call
  21401. which can be placed in CurveUtils.
  21402. */
  21403. function CubicPoly() {
  21404. var c0 = 0, c1 = 0, c2 = 0, c3 = 0;
  21405. /*
  21406. * Compute coefficients for a cubic polynomial
  21407. * p(s) = c0 + c1*s + c2*s^2 + c3*s^3
  21408. * such that
  21409. * p(0) = x0, p(1) = x1
  21410. * and
  21411. * p'(0) = t0, p'(1) = t1.
  21412. */
  21413. function init( x0, x1, t0, t1 ) {
  21414. c0 = x0;
  21415. c1 = t0;
  21416. c2 = - 3 * x0 + 3 * x1 - 2 * t0 - t1;
  21417. c3 = 2 * x0 - 2 * x1 + t0 + t1;
  21418. }
  21419. return {
  21420. initCatmullRom: function ( x0, x1, x2, x3, tension ) {
  21421. init( x1, x2, tension * ( x2 - x0 ), tension * ( x3 - x1 ) );
  21422. },
  21423. initNonuniformCatmullRom: function ( x0, x1, x2, x3, dt0, dt1, dt2 ) {
  21424. // compute tangents when parameterized in [t1,t2]
  21425. var t1 = ( x1 - x0 ) / dt0 - ( x2 - x0 ) / ( dt0 + dt1 ) + ( x2 - x1 ) / dt1;
  21426. var t2 = ( x2 - x1 ) / dt1 - ( x3 - x1 ) / ( dt1 + dt2 ) + ( x3 - x2 ) / dt2;
  21427. // rescale tangents for parametrization in [0,1]
  21428. t1 *= dt1;
  21429. t2 *= dt1;
  21430. init( x1, x2, t1, t2 );
  21431. },
  21432. calc: function ( t ) {
  21433. var t2 = t * t;
  21434. var t3 = t2 * t;
  21435. return c0 + c1 * t + c2 * t2 + c3 * t3;
  21436. }
  21437. };
  21438. }
  21439. //
  21440. var tmp = new Vector3();
  21441. var px = new CubicPoly(), py = new CubicPoly(), pz = new CubicPoly();
  21442. function CatmullRomCurve3( points, closed, curveType, tension ) {
  21443. Curve.call( this );
  21444. this.type = 'CatmullRomCurve3';
  21445. this.points = points || [];
  21446. this.closed = closed || false;
  21447. this.curveType = curveType || 'centripetal';
  21448. this.tension = tension || 0.5;
  21449. }
  21450. CatmullRomCurve3.prototype = Object.create( Curve.prototype );
  21451. CatmullRomCurve3.prototype.constructor = CatmullRomCurve3;
  21452. CatmullRomCurve3.prototype.isCatmullRomCurve3 = true;
  21453. CatmullRomCurve3.prototype.getPoint = function ( t, optionalTarget ) {
  21454. var point = optionalTarget || new Vector3();
  21455. var points = this.points;
  21456. var l = points.length;
  21457. var p = ( l - ( this.closed ? 0 : 1 ) ) * t;
  21458. var intPoint = Math.floor( p );
  21459. var weight = p - intPoint;
  21460. if ( this.closed ) {
  21461. intPoint += intPoint > 0 ? 0 : ( Math.floor( Math.abs( intPoint ) / l ) + 1 ) * l;
  21462. } else if ( weight === 0 && intPoint === l - 1 ) {
  21463. intPoint = l - 2;
  21464. weight = 1;
  21465. }
  21466. var p0, p1, p2, p3; // 4 points
  21467. if ( this.closed || intPoint > 0 ) {
  21468. p0 = points[ ( intPoint - 1 ) % l ];
  21469. } else {
  21470. // extrapolate first point
  21471. tmp.subVectors( points[ 0 ], points[ 1 ] ).add( points[ 0 ] );
  21472. p0 = tmp;
  21473. }
  21474. p1 = points[ intPoint % l ];
  21475. p2 = points[ ( intPoint + 1 ) % l ];
  21476. if ( this.closed || intPoint + 2 < l ) {
  21477. p3 = points[ ( intPoint + 2 ) % l ];
  21478. } else {
  21479. // extrapolate last point
  21480. tmp.subVectors( points[ l - 1 ], points[ l - 2 ] ).add( points[ l - 1 ] );
  21481. p3 = tmp;
  21482. }
  21483. if ( this.curveType === 'centripetal' || this.curveType === 'chordal' ) {
  21484. // init Centripetal / Chordal Catmull-Rom
  21485. var pow = this.curveType === 'chordal' ? 0.5 : 0.25;
  21486. var dt0 = Math.pow( p0.distanceToSquared( p1 ), pow );
  21487. var dt1 = Math.pow( p1.distanceToSquared( p2 ), pow );
  21488. var dt2 = Math.pow( p2.distanceToSquared( p3 ), pow );
  21489. // safety check for repeated points
  21490. if ( dt1 < 1e-4 ) dt1 = 1.0;
  21491. if ( dt0 < 1e-4 ) dt0 = dt1;
  21492. if ( dt2 < 1e-4 ) dt2 = dt1;
  21493. px.initNonuniformCatmullRom( p0.x, p1.x, p2.x, p3.x, dt0, dt1, dt2 );
  21494. py.initNonuniformCatmullRom( p0.y, p1.y, p2.y, p3.y, dt0, dt1, dt2 );
  21495. pz.initNonuniformCatmullRom( p0.z, p1.z, p2.z, p3.z, dt0, dt1, dt2 );
  21496. } else if ( this.curveType === 'catmullrom' ) {
  21497. px.initCatmullRom( p0.x, p1.x, p2.x, p3.x, this.tension );
  21498. py.initCatmullRom( p0.y, p1.y, p2.y, p3.y, this.tension );
  21499. pz.initCatmullRom( p0.z, p1.z, p2.z, p3.z, this.tension );
  21500. }
  21501. point.set(
  21502. px.calc( weight ),
  21503. py.calc( weight ),
  21504. pz.calc( weight )
  21505. );
  21506. return point;
  21507. };
  21508. CatmullRomCurve3.prototype.copy = function ( source ) {
  21509. Curve.prototype.copy.call( this, source );
  21510. this.points = [];
  21511. for ( var i = 0, l = source.points.length; i < l; i ++ ) {
  21512. var point = source.points[ i ];
  21513. this.points.push( point.clone() );
  21514. }
  21515. this.closed = source.closed;
  21516. this.curveType = source.curveType;
  21517. this.tension = source.tension;
  21518. return this;
  21519. };
  21520. CatmullRomCurve3.prototype.toJSON = function () {
  21521. var data = Curve.prototype.toJSON.call( this );
  21522. data.points = [];
  21523. for ( var i = 0, l = this.points.length; i < l; i ++ ) {
  21524. var point = this.points[ i ];
  21525. data.points.push( point.toArray() );
  21526. }
  21527. data.closed = this.closed;
  21528. data.curveType = this.curveType;
  21529. data.tension = this.tension;
  21530. return data;
  21531. };
  21532. CatmullRomCurve3.prototype.fromJSON = function ( json ) {
  21533. Curve.prototype.fromJSON.call( this, json );
  21534. this.points = [];
  21535. for ( var i = 0, l = json.points.length; i < l; i ++ ) {
  21536. var point = json.points[ i ];
  21537. this.points.push( new Vector3().fromArray( point ) );
  21538. }
  21539. this.closed = json.closed;
  21540. this.curveType = json.curveType;
  21541. this.tension = json.tension;
  21542. return this;
  21543. };
  21544. /**
  21545. * @author zz85 / http://www.lab4games.net/zz85/blog
  21546. *
  21547. * Bezier Curves formulas obtained from
  21548. * http://en.wikipedia.org/wiki/Bézier_curve
  21549. */
  21550. function CatmullRom( t, p0, p1, p2, p3 ) {
  21551. var v0 = ( p2 - p0 ) * 0.5;
  21552. var v1 = ( p3 - p1 ) * 0.5;
  21553. var t2 = t * t;
  21554. var t3 = t * t2;
  21555. return ( 2 * p1 - 2 * p2 + v0 + v1 ) * t3 + ( - 3 * p1 + 3 * p2 - 2 * v0 - v1 ) * t2 + v0 * t + p1;
  21556. }
  21557. //
  21558. function QuadraticBezierP0( t, p ) {
  21559. var k = 1 - t;
  21560. return k * k * p;
  21561. }
  21562. function QuadraticBezierP1( t, p ) {
  21563. return 2 * ( 1 - t ) * t * p;
  21564. }
  21565. function QuadraticBezierP2( t, p ) {
  21566. return t * t * p;
  21567. }
  21568. function QuadraticBezier( t, p0, p1, p2 ) {
  21569. return QuadraticBezierP0( t, p0 ) + QuadraticBezierP1( t, p1 ) +
  21570. QuadraticBezierP2( t, p2 );
  21571. }
  21572. //
  21573. function CubicBezierP0( t, p ) {
  21574. var k = 1 - t;
  21575. return k * k * k * p;
  21576. }
  21577. function CubicBezierP1( t, p ) {
  21578. var k = 1 - t;
  21579. return 3 * k * k * t * p;
  21580. }
  21581. function CubicBezierP2( t, p ) {
  21582. return 3 * ( 1 - t ) * t * t * p;
  21583. }
  21584. function CubicBezierP3( t, p ) {
  21585. return t * t * t * p;
  21586. }
  21587. function CubicBezier( t, p0, p1, p2, p3 ) {
  21588. return CubicBezierP0( t, p0 ) + CubicBezierP1( t, p1 ) + CubicBezierP2( t, p2 ) +
  21589. CubicBezierP3( t, p3 );
  21590. }
  21591. function CubicBezierCurve( v0, v1, v2, v3 ) {
  21592. Curve.call( this );
  21593. this.type = 'CubicBezierCurve';
  21594. this.v0 = v0 || new Vector2();
  21595. this.v1 = v1 || new Vector2();
  21596. this.v2 = v2 || new Vector2();
  21597. this.v3 = v3 || new Vector2();
  21598. }
  21599. CubicBezierCurve.prototype = Object.create( Curve.prototype );
  21600. CubicBezierCurve.prototype.constructor = CubicBezierCurve;
  21601. CubicBezierCurve.prototype.isCubicBezierCurve = true;
  21602. CubicBezierCurve.prototype.getPoint = function ( t, optionalTarget ) {
  21603. var point = optionalTarget || new Vector2();
  21604. var v0 = this.v0, v1 = this.v1, v2 = this.v2, v3 = this.v3;
  21605. point.set(
  21606. CubicBezier( t, v0.x, v1.x, v2.x, v3.x ),
  21607. CubicBezier( t, v0.y, v1.y, v2.y, v3.y )
  21608. );
  21609. return point;
  21610. };
  21611. CubicBezierCurve.prototype.copy = function ( source ) {
  21612. Curve.prototype.copy.call( this, source );
  21613. this.v0.copy( source.v0 );
  21614. this.v1.copy( source.v1 );
  21615. this.v2.copy( source.v2 );
  21616. this.v3.copy( source.v3 );
  21617. return this;
  21618. };
  21619. CubicBezierCurve.prototype.toJSON = function () {
  21620. var data = Curve.prototype.toJSON.call( this );
  21621. data.v0 = this.v0.toArray();
  21622. data.v1 = this.v1.toArray();
  21623. data.v2 = this.v2.toArray();
  21624. data.v3 = this.v3.toArray();
  21625. return data;
  21626. };
  21627. CubicBezierCurve.prototype.fromJSON = function ( json ) {
  21628. Curve.prototype.fromJSON.call( this, json );
  21629. this.v0.fromArray( json.v0 );
  21630. this.v1.fromArray( json.v1 );
  21631. this.v2.fromArray( json.v2 );
  21632. this.v3.fromArray( json.v3 );
  21633. return this;
  21634. };
  21635. function CubicBezierCurve3( v0, v1, v2, v3 ) {
  21636. Curve.call( this );
  21637. this.type = 'CubicBezierCurve3';
  21638. this.v0 = v0 || new Vector3();
  21639. this.v1 = v1 || new Vector3();
  21640. this.v2 = v2 || new Vector3();
  21641. this.v3 = v3 || new Vector3();
  21642. }
  21643. CubicBezierCurve3.prototype = Object.create( Curve.prototype );
  21644. CubicBezierCurve3.prototype.constructor = CubicBezierCurve3;
  21645. CubicBezierCurve3.prototype.isCubicBezierCurve3 = true;
  21646. CubicBezierCurve3.prototype.getPoint = function ( t, optionalTarget ) {
  21647. var point = optionalTarget || new Vector3();
  21648. var v0 = this.v0, v1 = this.v1, v2 = this.v2, v3 = this.v3;
  21649. point.set(
  21650. CubicBezier( t, v0.x, v1.x, v2.x, v3.x ),
  21651. CubicBezier( t, v0.y, v1.y, v2.y, v3.y ),
  21652. CubicBezier( t, v0.z, v1.z, v2.z, v3.z )
  21653. );
  21654. return point;
  21655. };
  21656. CubicBezierCurve3.prototype.copy = function ( source ) {
  21657. Curve.prototype.copy.call( this, source );
  21658. this.v0.copy( source.v0 );
  21659. this.v1.copy( source.v1 );
  21660. this.v2.copy( source.v2 );
  21661. this.v3.copy( source.v3 );
  21662. return this;
  21663. };
  21664. CubicBezierCurve3.prototype.toJSON = function () {
  21665. var data = Curve.prototype.toJSON.call( this );
  21666. data.v0 = this.v0.toArray();
  21667. data.v1 = this.v1.toArray();
  21668. data.v2 = this.v2.toArray();
  21669. data.v3 = this.v3.toArray();
  21670. return data;
  21671. };
  21672. CubicBezierCurve3.prototype.fromJSON = function ( json ) {
  21673. Curve.prototype.fromJSON.call( this, json );
  21674. this.v0.fromArray( json.v0 );
  21675. this.v1.fromArray( json.v1 );
  21676. this.v2.fromArray( json.v2 );
  21677. this.v3.fromArray( json.v3 );
  21678. return this;
  21679. };
  21680. function LineCurve( v1, v2 ) {
  21681. Curve.call( this );
  21682. this.type = 'LineCurve';
  21683. this.v1 = v1 || new Vector2();
  21684. this.v2 = v2 || new Vector2();
  21685. }
  21686. LineCurve.prototype = Object.create( Curve.prototype );
  21687. LineCurve.prototype.constructor = LineCurve;
  21688. LineCurve.prototype.isLineCurve = true;
  21689. LineCurve.prototype.getPoint = function ( t, optionalTarget ) {
  21690. var point = optionalTarget || new Vector2();
  21691. if ( t === 1 ) {
  21692. point.copy( this.v2 );
  21693. } else {
  21694. point.copy( this.v2 ).sub( this.v1 );
  21695. point.multiplyScalar( t ).add( this.v1 );
  21696. }
  21697. return point;
  21698. };
  21699. // Line curve is linear, so we can overwrite default getPointAt
  21700. LineCurve.prototype.getPointAt = function ( u, optionalTarget ) {
  21701. return this.getPoint( u, optionalTarget );
  21702. };
  21703. LineCurve.prototype.getTangent = function ( /* t */ ) {
  21704. var tangent = this.v2.clone().sub( this.v1 );
  21705. return tangent.normalize();
  21706. };
  21707. LineCurve.prototype.copy = function ( source ) {
  21708. Curve.prototype.copy.call( this, source );
  21709. this.v1.copy( source.v1 );
  21710. this.v2.copy( source.v2 );
  21711. return this;
  21712. };
  21713. LineCurve.prototype.toJSON = function () {
  21714. var data = Curve.prototype.toJSON.call( this );
  21715. data.v1 = this.v1.toArray();
  21716. data.v2 = this.v2.toArray();
  21717. return data;
  21718. };
  21719. LineCurve.prototype.fromJSON = function ( json ) {
  21720. Curve.prototype.fromJSON.call( this, json );
  21721. this.v1.fromArray( json.v1 );
  21722. this.v2.fromArray( json.v2 );
  21723. return this;
  21724. };
  21725. function LineCurve3( v1, v2 ) {
  21726. Curve.call( this );
  21727. this.type = 'LineCurve3';
  21728. this.v1 = v1 || new Vector3();
  21729. this.v2 = v2 || new Vector3();
  21730. }
  21731. LineCurve3.prototype = Object.create( Curve.prototype );
  21732. LineCurve3.prototype.constructor = LineCurve3;
  21733. LineCurve3.prototype.isLineCurve3 = true;
  21734. LineCurve3.prototype.getPoint = function ( t, optionalTarget ) {
  21735. var point = optionalTarget || new Vector3();
  21736. if ( t === 1 ) {
  21737. point.copy( this.v2 );
  21738. } else {
  21739. point.copy( this.v2 ).sub( this.v1 );
  21740. point.multiplyScalar( t ).add( this.v1 );
  21741. }
  21742. return point;
  21743. };
  21744. // Line curve is linear, so we can overwrite default getPointAt
  21745. LineCurve3.prototype.getPointAt = function ( u, optionalTarget ) {
  21746. return this.getPoint( u, optionalTarget );
  21747. };
  21748. LineCurve3.prototype.copy = function ( source ) {
  21749. Curve.prototype.copy.call( this, source );
  21750. this.v1.copy( source.v1 );
  21751. this.v2.copy( source.v2 );
  21752. return this;
  21753. };
  21754. LineCurve3.prototype.toJSON = function () {
  21755. var data = Curve.prototype.toJSON.call( this );
  21756. data.v1 = this.v1.toArray();
  21757. data.v2 = this.v2.toArray();
  21758. return data;
  21759. };
  21760. LineCurve3.prototype.fromJSON = function ( json ) {
  21761. Curve.prototype.fromJSON.call( this, json );
  21762. this.v1.fromArray( json.v1 );
  21763. this.v2.fromArray( json.v2 );
  21764. return this;
  21765. };
  21766. function QuadraticBezierCurve( v0, v1, v2 ) {
  21767. Curve.call( this );
  21768. this.type = 'QuadraticBezierCurve';
  21769. this.v0 = v0 || new Vector2();
  21770. this.v1 = v1 || new Vector2();
  21771. this.v2 = v2 || new Vector2();
  21772. }
  21773. QuadraticBezierCurve.prototype = Object.create( Curve.prototype );
  21774. QuadraticBezierCurve.prototype.constructor = QuadraticBezierCurve;
  21775. QuadraticBezierCurve.prototype.isQuadraticBezierCurve = true;
  21776. QuadraticBezierCurve.prototype.getPoint = function ( t, optionalTarget ) {
  21777. var point = optionalTarget || new Vector2();
  21778. var v0 = this.v0, v1 = this.v1, v2 = this.v2;
  21779. point.set(
  21780. QuadraticBezier( t, v0.x, v1.x, v2.x ),
  21781. QuadraticBezier( t, v0.y, v1.y, v2.y )
  21782. );
  21783. return point;
  21784. };
  21785. QuadraticBezierCurve.prototype.copy = function ( source ) {
  21786. Curve.prototype.copy.call( this, source );
  21787. this.v0.copy( source.v0 );
  21788. this.v1.copy( source.v1 );
  21789. this.v2.copy( source.v2 );
  21790. return this;
  21791. };
  21792. QuadraticBezierCurve.prototype.toJSON = function () {
  21793. var data = Curve.prototype.toJSON.call( this );
  21794. data.v0 = this.v0.toArray();
  21795. data.v1 = this.v1.toArray();
  21796. data.v2 = this.v2.toArray();
  21797. return data;
  21798. };
  21799. QuadraticBezierCurve.prototype.fromJSON = function ( json ) {
  21800. Curve.prototype.fromJSON.call( this, json );
  21801. this.v0.fromArray( json.v0 );
  21802. this.v1.fromArray( json.v1 );
  21803. this.v2.fromArray( json.v2 );
  21804. return this;
  21805. };
  21806. function QuadraticBezierCurve3( v0, v1, v2 ) {
  21807. Curve.call( this );
  21808. this.type = 'QuadraticBezierCurve3';
  21809. this.v0 = v0 || new Vector3();
  21810. this.v1 = v1 || new Vector3();
  21811. this.v2 = v2 || new Vector3();
  21812. }
  21813. QuadraticBezierCurve3.prototype = Object.create( Curve.prototype );
  21814. QuadraticBezierCurve3.prototype.constructor = QuadraticBezierCurve3;
  21815. QuadraticBezierCurve3.prototype.isQuadraticBezierCurve3 = true;
  21816. QuadraticBezierCurve3.prototype.getPoint = function ( t, optionalTarget ) {
  21817. var point = optionalTarget || new Vector3();
  21818. var v0 = this.v0, v1 = this.v1, v2 = this.v2;
  21819. point.set(
  21820. QuadraticBezier( t, v0.x, v1.x, v2.x ),
  21821. QuadraticBezier( t, v0.y, v1.y, v2.y ),
  21822. QuadraticBezier( t, v0.z, v1.z, v2.z )
  21823. );
  21824. return point;
  21825. };
  21826. QuadraticBezierCurve3.prototype.copy = function ( source ) {
  21827. Curve.prototype.copy.call( this, source );
  21828. this.v0.copy( source.v0 );
  21829. this.v1.copy( source.v1 );
  21830. this.v2.copy( source.v2 );
  21831. return this;
  21832. };
  21833. QuadraticBezierCurve3.prototype.toJSON = function () {
  21834. var data = Curve.prototype.toJSON.call( this );
  21835. data.v0 = this.v0.toArray();
  21836. data.v1 = this.v1.toArray();
  21837. data.v2 = this.v2.toArray();
  21838. return data;
  21839. };
  21840. QuadraticBezierCurve3.prototype.fromJSON = function ( json ) {
  21841. Curve.prototype.fromJSON.call( this, json );
  21842. this.v0.fromArray( json.v0 );
  21843. this.v1.fromArray( json.v1 );
  21844. this.v2.fromArray( json.v2 );
  21845. return this;
  21846. };
  21847. function SplineCurve( points /* array of Vector2 */ ) {
  21848. Curve.call( this );
  21849. this.type = 'SplineCurve';
  21850. this.points = points || [];
  21851. }
  21852. SplineCurve.prototype = Object.create( Curve.prototype );
  21853. SplineCurve.prototype.constructor = SplineCurve;
  21854. SplineCurve.prototype.isSplineCurve = true;
  21855. SplineCurve.prototype.getPoint = function ( t, optionalTarget ) {
  21856. var point = optionalTarget || new Vector2();
  21857. var points = this.points;
  21858. var p = ( points.length - 1 ) * t;
  21859. var intPoint = Math.floor( p );
  21860. var weight = p - intPoint;
  21861. var p0 = points[ intPoint === 0 ? intPoint : intPoint - 1 ];
  21862. var p1 = points[ intPoint ];
  21863. var p2 = points[ intPoint > points.length - 2 ? points.length - 1 : intPoint + 1 ];
  21864. var p3 = points[ intPoint > points.length - 3 ? points.length - 1 : intPoint + 2 ];
  21865. point.set(
  21866. CatmullRom( weight, p0.x, p1.x, p2.x, p3.x ),
  21867. CatmullRom( weight, p0.y, p1.y, p2.y, p3.y )
  21868. );
  21869. return point;
  21870. };
  21871. SplineCurve.prototype.copy = function ( source ) {
  21872. Curve.prototype.copy.call( this, source );
  21873. this.points = [];
  21874. for ( var i = 0, l = source.points.length; i < l; i ++ ) {
  21875. var point = source.points[ i ];
  21876. this.points.push( point.clone() );
  21877. }
  21878. return this;
  21879. };
  21880. SplineCurve.prototype.toJSON = function () {
  21881. var data = Curve.prototype.toJSON.call( this );
  21882. data.points = [];
  21883. for ( var i = 0, l = this.points.length; i < l; i ++ ) {
  21884. var point = this.points[ i ];
  21885. data.points.push( point.toArray() );
  21886. }
  21887. return data;
  21888. };
  21889. SplineCurve.prototype.fromJSON = function ( json ) {
  21890. Curve.prototype.fromJSON.call( this, json );
  21891. this.points = [];
  21892. for ( var i = 0, l = json.points.length; i < l; i ++ ) {
  21893. var point = json.points[ i ];
  21894. this.points.push( new Vector2().fromArray( point ) );
  21895. }
  21896. return this;
  21897. };
  21898. var Curves = /*#__PURE__*/Object.freeze({
  21899. ArcCurve: ArcCurve,
  21900. CatmullRomCurve3: CatmullRomCurve3,
  21901. CubicBezierCurve: CubicBezierCurve,
  21902. CubicBezierCurve3: CubicBezierCurve3,
  21903. EllipseCurve: EllipseCurve,
  21904. LineCurve: LineCurve,
  21905. LineCurve3: LineCurve3,
  21906. QuadraticBezierCurve: QuadraticBezierCurve,
  21907. QuadraticBezierCurve3: QuadraticBezierCurve3,
  21908. SplineCurve: SplineCurve
  21909. });
  21910. /**
  21911. * @author zz85 / http://www.lab4games.net/zz85/blog
  21912. *
  21913. **/
  21914. /**************************************************************
  21915. * Curved Path - a curve path is simply a array of connected
  21916. * curves, but retains the api of a curve
  21917. **************************************************************/
  21918. function CurvePath() {
  21919. Curve.call( this );
  21920. this.type = 'CurvePath';
  21921. this.curves = [];
  21922. this.autoClose = false; // Automatically closes the path
  21923. }
  21924. CurvePath.prototype = Object.assign( Object.create( Curve.prototype ), {
  21925. constructor: CurvePath,
  21926. add: function ( curve ) {
  21927. this.curves.push( curve );
  21928. },
  21929. closePath: function () {
  21930. // Add a line curve if start and end of lines are not connected
  21931. var startPoint = this.curves[ 0 ].getPoint( 0 );
  21932. var endPoint = this.curves[ this.curves.length - 1 ].getPoint( 1 );
  21933. if ( ! startPoint.equals( endPoint ) ) {
  21934. this.curves.push( new LineCurve( endPoint, startPoint ) );
  21935. }
  21936. },
  21937. // To get accurate point with reference to
  21938. // entire path distance at time t,
  21939. // following has to be done:
  21940. // 1. Length of each sub path have to be known
  21941. // 2. Locate and identify type of curve
  21942. // 3. Get t for the curve
  21943. // 4. Return curve.getPointAt(t')
  21944. getPoint: function ( t ) {
  21945. var d = t * this.getLength();
  21946. var curveLengths = this.getCurveLengths();
  21947. var i = 0;
  21948. // To think about boundaries points.
  21949. while ( i < curveLengths.length ) {
  21950. if ( curveLengths[ i ] >= d ) {
  21951. var diff = curveLengths[ i ] - d;
  21952. var curve = this.curves[ i ];
  21953. var segmentLength = curve.getLength();
  21954. var u = segmentLength === 0 ? 0 : 1 - diff / segmentLength;
  21955. return curve.getPointAt( u );
  21956. }
  21957. i ++;
  21958. }
  21959. return null;
  21960. // loop where sum != 0, sum > d , sum+1 <d
  21961. },
  21962. // We cannot use the default THREE.Curve getPoint() with getLength() because in
  21963. // THREE.Curve, getLength() depends on getPoint() but in THREE.CurvePath
  21964. // getPoint() depends on getLength
  21965. getLength: function () {
  21966. var lens = this.getCurveLengths();
  21967. return lens[ lens.length - 1 ];
  21968. },
  21969. // cacheLengths must be recalculated.
  21970. updateArcLengths: function () {
  21971. this.needsUpdate = true;
  21972. this.cacheLengths = null;
  21973. this.getCurveLengths();
  21974. },
  21975. // Compute lengths and cache them
  21976. // We cannot overwrite getLengths() because UtoT mapping uses it.
  21977. getCurveLengths: function () {
  21978. // We use cache values if curves and cache array are same length
  21979. if ( this.cacheLengths && this.cacheLengths.length === this.curves.length ) {
  21980. return this.cacheLengths;
  21981. }
  21982. // Get length of sub-curve
  21983. // Push sums into cached array
  21984. var lengths = [], sums = 0;
  21985. for ( var i = 0, l = this.curves.length; i < l; i ++ ) {
  21986. sums += this.curves[ i ].getLength();
  21987. lengths.push( sums );
  21988. }
  21989. this.cacheLengths = lengths;
  21990. return lengths;
  21991. },
  21992. getSpacedPoints: function ( divisions ) {
  21993. if ( divisions === undefined ) divisions = 40;
  21994. var points = [];
  21995. for ( var i = 0; i <= divisions; i ++ ) {
  21996. points.push( this.getPoint( i / divisions ) );
  21997. }
  21998. if ( this.autoClose ) {
  21999. points.push( points[ 0 ] );
  22000. }
  22001. return points;
  22002. },
  22003. getPoints: function ( divisions ) {
  22004. divisions = divisions || 12;
  22005. var points = [], last;
  22006. for ( var i = 0, curves = this.curves; i < curves.length; i ++ ) {
  22007. var curve = curves[ i ];
  22008. var resolution = ( curve && curve.isEllipseCurve ) ? divisions * 2
  22009. : ( curve && ( curve.isLineCurve || curve.isLineCurve3 ) ) ? 1
  22010. : ( curve && curve.isSplineCurve ) ? divisions * curve.points.length
  22011. : divisions;
  22012. var pts = curve.getPoints( resolution );
  22013. for ( var j = 0; j < pts.length; j ++ ) {
  22014. var point = pts[ j ];
  22015. if ( last && last.equals( point ) ) continue; // ensures no consecutive points are duplicates
  22016. points.push( point );
  22017. last = point;
  22018. }
  22019. }
  22020. if ( this.autoClose && points.length > 1 && ! points[ points.length - 1 ].equals( points[ 0 ] ) ) {
  22021. points.push( points[ 0 ] );
  22022. }
  22023. return points;
  22024. },
  22025. copy: function ( source ) {
  22026. Curve.prototype.copy.call( this, source );
  22027. this.curves = [];
  22028. for ( var i = 0, l = source.curves.length; i < l; i ++ ) {
  22029. var curve = source.curves[ i ];
  22030. this.curves.push( curve.clone() );
  22031. }
  22032. this.autoClose = source.autoClose;
  22033. return this;
  22034. },
  22035. toJSON: function () {
  22036. var data = Curve.prototype.toJSON.call( this );
  22037. data.autoClose = this.autoClose;
  22038. data.curves = [];
  22039. for ( var i = 0, l = this.curves.length; i < l; i ++ ) {
  22040. var curve = this.curves[ i ];
  22041. data.curves.push( curve.toJSON() );
  22042. }
  22043. return data;
  22044. },
  22045. fromJSON: function ( json ) {
  22046. Curve.prototype.fromJSON.call( this, json );
  22047. this.autoClose = json.autoClose;
  22048. this.curves = [];
  22049. for ( var i = 0, l = json.curves.length; i < l; i ++ ) {
  22050. var curve = json.curves[ i ];
  22051. this.curves.push( new Curves[ curve.type ]().fromJSON( curve ) );
  22052. }
  22053. return this;
  22054. }
  22055. } );
  22056. /**
  22057. * @author zz85 / http://www.lab4games.net/zz85/blog
  22058. * Creates free form 2d path using series of points, lines or curves.
  22059. **/
  22060. function Path( points ) {
  22061. CurvePath.call( this );
  22062. this.type = 'Path';
  22063. this.currentPoint = new Vector2();
  22064. if ( points ) {
  22065. this.setFromPoints( points );
  22066. }
  22067. }
  22068. Path.prototype = Object.assign( Object.create( CurvePath.prototype ), {
  22069. constructor: Path,
  22070. setFromPoints: function ( points ) {
  22071. this.moveTo( points[ 0 ].x, points[ 0 ].y );
  22072. for ( var i = 1, l = points.length; i < l; i ++ ) {
  22073. this.lineTo( points[ i ].x, points[ i ].y );
  22074. }
  22075. },
  22076. moveTo: function ( x, y ) {
  22077. this.currentPoint.set( x, y ); // TODO consider referencing vectors instead of copying?
  22078. },
  22079. lineTo: function ( x, y ) {
  22080. var curve = new LineCurve( this.currentPoint.clone(), new Vector2( x, y ) );
  22081. this.curves.push( curve );
  22082. this.currentPoint.set( x, y );
  22083. },
  22084. quadraticCurveTo: function ( aCPx, aCPy, aX, aY ) {
  22085. var curve = new QuadraticBezierCurve(
  22086. this.currentPoint.clone(),
  22087. new Vector2( aCPx, aCPy ),
  22088. new Vector2( aX, aY )
  22089. );
  22090. this.curves.push( curve );
  22091. this.currentPoint.set( aX, aY );
  22092. },
  22093. bezierCurveTo: function ( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY ) {
  22094. var curve = new CubicBezierCurve(
  22095. this.currentPoint.clone(),
  22096. new Vector2( aCP1x, aCP1y ),
  22097. new Vector2( aCP2x, aCP2y ),
  22098. new Vector2( aX, aY )
  22099. );
  22100. this.curves.push( curve );
  22101. this.currentPoint.set( aX, aY );
  22102. },
  22103. splineThru: function ( pts /*Array of Vector*/ ) {
  22104. var npts = [ this.currentPoint.clone() ].concat( pts );
  22105. var curve = new SplineCurve( npts );
  22106. this.curves.push( curve );
  22107. this.currentPoint.copy( pts[ pts.length - 1 ] );
  22108. },
  22109. arc: function ( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  22110. var x0 = this.currentPoint.x;
  22111. var y0 = this.currentPoint.y;
  22112. this.absarc( aX + x0, aY + y0, aRadius,
  22113. aStartAngle, aEndAngle, aClockwise );
  22114. },
  22115. absarc: function ( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  22116. this.absellipse( aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise );
  22117. },
  22118. ellipse: function ( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  22119. var x0 = this.currentPoint.x;
  22120. var y0 = this.currentPoint.y;
  22121. this.absellipse( aX + x0, aY + y0, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation );
  22122. },
  22123. absellipse: function ( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  22124. var curve = new EllipseCurve( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation );
  22125. if ( this.curves.length > 0 ) {
  22126. // if a previous curve is present, attempt to join
  22127. var firstPoint = curve.getPoint( 0 );
  22128. if ( ! firstPoint.equals( this.currentPoint ) ) {
  22129. this.lineTo( firstPoint.x, firstPoint.y );
  22130. }
  22131. }
  22132. this.curves.push( curve );
  22133. var lastPoint = curve.getPoint( 1 );
  22134. this.currentPoint.copy( lastPoint );
  22135. },
  22136. copy: function ( source ) {
  22137. CurvePath.prototype.copy.call( this, source );
  22138. this.currentPoint.copy( source.currentPoint );
  22139. return this;
  22140. },
  22141. toJSON: function () {
  22142. var data = CurvePath.prototype.toJSON.call( this );
  22143. data.currentPoint = this.currentPoint.toArray();
  22144. return data;
  22145. },
  22146. fromJSON: function ( json ) {
  22147. CurvePath.prototype.fromJSON.call( this, json );
  22148. this.currentPoint.fromArray( json.currentPoint );
  22149. return this;
  22150. }
  22151. } );
  22152. /**
  22153. * @author zz85 / http://www.lab4games.net/zz85/blog
  22154. * Defines a 2d shape plane using paths.
  22155. **/
  22156. // STEP 1 Create a path.
  22157. // STEP 2 Turn path into shape.
  22158. // STEP 3 ExtrudeGeometry takes in Shape/Shapes
  22159. // STEP 3a - Extract points from each shape, turn to vertices
  22160. // STEP 3b - Triangulate each shape, add faces.
  22161. function Shape( points ) {
  22162. Path.call( this, points );
  22163. this.uuid = _Math.generateUUID();
  22164. this.type = 'Shape';
  22165. this.holes = [];
  22166. }
  22167. Shape.prototype = Object.assign( Object.create( Path.prototype ), {
  22168. constructor: Shape,
  22169. getPointsHoles: function ( divisions ) {
  22170. var holesPts = [];
  22171. for ( var i = 0, l = this.holes.length; i < l; i ++ ) {
  22172. holesPts[ i ] = this.holes[ i ].getPoints( divisions );
  22173. }
  22174. return holesPts;
  22175. },
  22176. // get points of shape and holes (keypoints based on segments parameter)
  22177. extractPoints: function ( divisions ) {
  22178. return {
  22179. shape: this.getPoints( divisions ),
  22180. holes: this.getPointsHoles( divisions )
  22181. };
  22182. },
  22183. copy: function ( source ) {
  22184. Path.prototype.copy.call( this, source );
  22185. this.holes = [];
  22186. for ( var i = 0, l = source.holes.length; i < l; i ++ ) {
  22187. var hole = source.holes[ i ];
  22188. this.holes.push( hole.clone() );
  22189. }
  22190. return this;
  22191. },
  22192. toJSON: function () {
  22193. var data = Path.prototype.toJSON.call( this );
  22194. data.uuid = this.uuid;
  22195. data.holes = [];
  22196. for ( var i = 0, l = this.holes.length; i < l; i ++ ) {
  22197. var hole = this.holes[ i ];
  22198. data.holes.push( hole.toJSON() );
  22199. }
  22200. return data;
  22201. },
  22202. fromJSON: function ( json ) {
  22203. Path.prototype.fromJSON.call( this, json );
  22204. this.uuid = json.uuid;
  22205. this.holes = [];
  22206. for ( var i = 0, l = json.holes.length; i < l; i ++ ) {
  22207. var hole = json.holes[ i ];
  22208. this.holes.push( new Path().fromJSON( hole ) );
  22209. }
  22210. return this;
  22211. }
  22212. } );
  22213. /**
  22214. * @author mrdoob / http://mrdoob.com/
  22215. * @author alteredq / http://alteredqualia.com/
  22216. */
  22217. function Light( color, intensity ) {
  22218. Object3D.call( this );
  22219. this.type = 'Light';
  22220. this.color = new Color( color );
  22221. this.intensity = intensity !== undefined ? intensity : 1;
  22222. this.receiveShadow = undefined;
  22223. }
  22224. Light.prototype = Object.assign( Object.create( Object3D.prototype ), {
  22225. constructor: Light,
  22226. isLight: true,
  22227. copy: function ( source ) {
  22228. Object3D.prototype.copy.call( this, source );
  22229. this.color.copy( source.color );
  22230. this.intensity = source.intensity;
  22231. return this;
  22232. },
  22233. toJSON: function ( meta ) {
  22234. var data = Object3D.prototype.toJSON.call( this, meta );
  22235. data.object.color = this.color.getHex();
  22236. data.object.intensity = this.intensity;
  22237. if ( this.groundColor !== undefined ) data.object.groundColor = this.groundColor.getHex();
  22238. if ( this.distance !== undefined ) data.object.distance = this.distance;
  22239. if ( this.angle !== undefined ) data.object.angle = this.angle;
  22240. if ( this.decay !== undefined ) data.object.decay = this.decay;
  22241. if ( this.penumbra !== undefined ) data.object.penumbra = this.penumbra;
  22242. if ( this.shadow !== undefined ) data.object.shadow = this.shadow.toJSON();
  22243. return data;
  22244. }
  22245. } );
  22246. /**
  22247. * @author alteredq / http://alteredqualia.com/
  22248. */
  22249. function HemisphereLight( skyColor, groundColor, intensity ) {
  22250. Light.call( this, skyColor, intensity );
  22251. this.type = 'HemisphereLight';
  22252. this.castShadow = undefined;
  22253. this.position.copy( Object3D.DefaultUp );
  22254. this.updateMatrix();
  22255. this.groundColor = new Color( groundColor );
  22256. }
  22257. HemisphereLight.prototype = Object.assign( Object.create( Light.prototype ), {
  22258. constructor: HemisphereLight,
  22259. isHemisphereLight: true,
  22260. copy: function ( source ) {
  22261. Light.prototype.copy.call( this, source );
  22262. this.groundColor.copy( source.groundColor );
  22263. return this;
  22264. }
  22265. } );
  22266. /**
  22267. * @author mrdoob / http://mrdoob.com/
  22268. */
  22269. function LightShadow( camera ) {
  22270. this.camera = camera;
  22271. this.bias = 0;
  22272. this.radius = 1;
  22273. this.mapSize = new Vector2( 512, 512 );
  22274. this.map = null;
  22275. this.matrix = new Matrix4();
  22276. }
  22277. Object.assign( LightShadow.prototype, {
  22278. copy: function ( source ) {
  22279. this.camera = source.camera.clone();
  22280. this.bias = source.bias;
  22281. this.radius = source.radius;
  22282. this.mapSize.copy( source.mapSize );
  22283. return this;
  22284. },
  22285. clone: function () {
  22286. return new this.constructor().copy( this );
  22287. },
  22288. toJSON: function () {
  22289. var object = {};
  22290. if ( this.bias !== 0 ) object.bias = this.bias;
  22291. if ( this.radius !== 1 ) object.radius = this.radius;
  22292. if ( this.mapSize.x !== 512 || this.mapSize.y !== 512 ) object.mapSize = this.mapSize.toArray();
  22293. object.camera = this.camera.toJSON( false ).object;
  22294. delete object.camera.matrix;
  22295. return object;
  22296. }
  22297. } );
  22298. /**
  22299. * @author mrdoob / http://mrdoob.com/
  22300. */
  22301. function SpotLightShadow() {
  22302. LightShadow.call( this, new PerspectiveCamera( 50, 1, 0.5, 500 ) );
  22303. }
  22304. SpotLightShadow.prototype = Object.assign( Object.create( LightShadow.prototype ), {
  22305. constructor: SpotLightShadow,
  22306. isSpotLightShadow: true,
  22307. update: function ( light ) {
  22308. var camera = this.camera;
  22309. var fov = _Math.RAD2DEG * 2 * light.angle;
  22310. var aspect = this.mapSize.width / this.mapSize.height;
  22311. var far = light.distance || camera.far;
  22312. if ( fov !== camera.fov || aspect !== camera.aspect || far !== camera.far ) {
  22313. camera.fov = fov;
  22314. camera.aspect = aspect;
  22315. camera.far = far;
  22316. camera.updateProjectionMatrix();
  22317. }
  22318. }
  22319. } );
  22320. /**
  22321. * @author alteredq / http://alteredqualia.com/
  22322. */
  22323. function SpotLight( color, intensity, distance, angle, penumbra, decay ) {
  22324. Light.call( this, color, intensity );
  22325. this.type = 'SpotLight';
  22326. this.position.copy( Object3D.DefaultUp );
  22327. this.updateMatrix();
  22328. this.target = new Object3D();
  22329. Object.defineProperty( this, 'power', {
  22330. get: function () {
  22331. // intensity = power per solid angle.
  22332. // ref: equation (17) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  22333. return this.intensity * Math.PI;
  22334. },
  22335. set: function ( power ) {
  22336. // intensity = power per solid angle.
  22337. // ref: equation (17) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  22338. this.intensity = power / Math.PI;
  22339. }
  22340. } );
  22341. this.distance = ( distance !== undefined ) ? distance : 0;
  22342. this.angle = ( angle !== undefined ) ? angle : Math.PI / 3;
  22343. this.penumbra = ( penumbra !== undefined ) ? penumbra : 0;
  22344. this.decay = ( decay !== undefined ) ? decay : 1; // for physically correct lights, should be 2.
  22345. this.shadow = new SpotLightShadow();
  22346. }
  22347. SpotLight.prototype = Object.assign( Object.create( Light.prototype ), {
  22348. constructor: SpotLight,
  22349. isSpotLight: true,
  22350. copy: function ( source ) {
  22351. Light.prototype.copy.call( this, source );
  22352. this.distance = source.distance;
  22353. this.angle = source.angle;
  22354. this.penumbra = source.penumbra;
  22355. this.decay = source.decay;
  22356. this.target = source.target.clone();
  22357. this.shadow = source.shadow.clone();
  22358. return this;
  22359. }
  22360. } );
  22361. /**
  22362. * @author mrdoob / http://mrdoob.com/
  22363. */
  22364. function PointLight( color, intensity, distance, decay ) {
  22365. Light.call( this, color, intensity );
  22366. this.type = 'PointLight';
  22367. Object.defineProperty( this, 'power', {
  22368. get: function () {
  22369. // intensity = power per solid angle.
  22370. // ref: equation (15) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  22371. return this.intensity * 4 * Math.PI;
  22372. },
  22373. set: function ( power ) {
  22374. // intensity = power per solid angle.
  22375. // ref: equation (15) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  22376. this.intensity = power / ( 4 * Math.PI );
  22377. }
  22378. } );
  22379. this.distance = ( distance !== undefined ) ? distance : 0;
  22380. this.decay = ( decay !== undefined ) ? decay : 1; // for physically correct lights, should be 2.
  22381. this.shadow = new LightShadow( new PerspectiveCamera( 90, 1, 0.5, 500 ) );
  22382. }
  22383. PointLight.prototype = Object.assign( Object.create( Light.prototype ), {
  22384. constructor: PointLight,
  22385. isPointLight: true,
  22386. copy: function ( source ) {
  22387. Light.prototype.copy.call( this, source );
  22388. this.distance = source.distance;
  22389. this.decay = source.decay;
  22390. this.shadow = source.shadow.clone();
  22391. return this;
  22392. }
  22393. } );
  22394. /**
  22395. * @author alteredq / http://alteredqualia.com/
  22396. * @author arose / http://github.com/arose
  22397. */
  22398. function OrthographicCamera( left, right, top, bottom, near, far ) {
  22399. Camera.call( this );
  22400. this.type = 'OrthographicCamera';
  22401. this.zoom = 1;
  22402. this.view = null;
  22403. this.left = ( left !== undefined ) ? left : - 1;
  22404. this.right = ( right !== undefined ) ? right : 1;
  22405. this.top = ( top !== undefined ) ? top : 1;
  22406. this.bottom = ( bottom !== undefined ) ? bottom : - 1;
  22407. this.near = ( near !== undefined ) ? near : 0.1;
  22408. this.far = ( far !== undefined ) ? far : 2000;
  22409. this.updateProjectionMatrix();
  22410. }
  22411. OrthographicCamera.prototype = Object.assign( Object.create( Camera.prototype ), {
  22412. constructor: OrthographicCamera,
  22413. isOrthographicCamera: true,
  22414. copy: function ( source, recursive ) {
  22415. Camera.prototype.copy.call( this, source, recursive );
  22416. this.left = source.left;
  22417. this.right = source.right;
  22418. this.top = source.top;
  22419. this.bottom = source.bottom;
  22420. this.near = source.near;
  22421. this.far = source.far;
  22422. this.zoom = source.zoom;
  22423. this.view = source.view === null ? null : Object.assign( {}, source.view );
  22424. return this;
  22425. },
  22426. setViewOffset: function ( fullWidth, fullHeight, x, y, width, height ) {
  22427. if ( this.view === null ) {
  22428. this.view = {
  22429. enabled: true,
  22430. fullWidth: 1,
  22431. fullHeight: 1,
  22432. offsetX: 0,
  22433. offsetY: 0,
  22434. width: 1,
  22435. height: 1
  22436. };
  22437. }
  22438. this.view.enabled = true;
  22439. this.view.fullWidth = fullWidth;
  22440. this.view.fullHeight = fullHeight;
  22441. this.view.offsetX = x;
  22442. this.view.offsetY = y;
  22443. this.view.width = width;
  22444. this.view.height = height;
  22445. this.updateProjectionMatrix();
  22446. },
  22447. clearViewOffset: function () {
  22448. if ( this.view !== null ) {
  22449. this.view.enabled = false;
  22450. }
  22451. this.updateProjectionMatrix();
  22452. },
  22453. updateProjectionMatrix: function () {
  22454. var dx = ( this.right - this.left ) / ( 2 * this.zoom );
  22455. var dy = ( this.top - this.bottom ) / ( 2 * this.zoom );
  22456. var cx = ( this.right + this.left ) / 2;
  22457. var cy = ( this.top + this.bottom ) / 2;
  22458. var left = cx - dx;
  22459. var right = cx + dx;
  22460. var top = cy + dy;
  22461. var bottom = cy - dy;
  22462. if ( this.view !== null && this.view.enabled ) {
  22463. var zoomW = this.zoom / ( this.view.width / this.view.fullWidth );
  22464. var zoomH = this.zoom / ( this.view.height / this.view.fullHeight );
  22465. var scaleW = ( this.right - this.left ) / this.view.width;
  22466. var scaleH = ( this.top - this.bottom ) / this.view.height;
  22467. left += scaleW * ( this.view.offsetX / zoomW );
  22468. right = left + scaleW * ( this.view.width / zoomW );
  22469. top -= scaleH * ( this.view.offsetY / zoomH );
  22470. bottom = top - scaleH * ( this.view.height / zoomH );
  22471. }
  22472. this.projectionMatrix.makeOrthographic( left, right, top, bottom, this.near, this.far );
  22473. this.projectionMatrixInverse.getInverse( this.projectionMatrix );
  22474. },
  22475. toJSON: function ( meta ) {
  22476. var data = Object3D.prototype.toJSON.call( this, meta );
  22477. data.object.zoom = this.zoom;
  22478. data.object.left = this.left;
  22479. data.object.right = this.right;
  22480. data.object.top = this.top;
  22481. data.object.bottom = this.bottom;
  22482. data.object.near = this.near;
  22483. data.object.far = this.far;
  22484. if ( this.view !== null ) data.object.view = Object.assign( {}, this.view );
  22485. return data;
  22486. }
  22487. } );
  22488. /**
  22489. * @author mrdoob / http://mrdoob.com/
  22490. */
  22491. function DirectionalLightShadow( ) {
  22492. LightShadow.call( this, new OrthographicCamera( - 5, 5, 5, - 5, 0.5, 500 ) );
  22493. }
  22494. DirectionalLightShadow.prototype = Object.assign( Object.create( LightShadow.prototype ), {
  22495. constructor: DirectionalLightShadow
  22496. } );
  22497. /**
  22498. * @author mrdoob / http://mrdoob.com/
  22499. * @author alteredq / http://alteredqualia.com/
  22500. */
  22501. function DirectionalLight( color, intensity ) {
  22502. Light.call( this, color, intensity );
  22503. this.type = 'DirectionalLight';
  22504. this.position.copy( Object3D.DefaultUp );
  22505. this.updateMatrix();
  22506. this.target = new Object3D();
  22507. this.shadow = new DirectionalLightShadow();
  22508. }
  22509. DirectionalLight.prototype = Object.assign( Object.create( Light.prototype ), {
  22510. constructor: DirectionalLight,
  22511. isDirectionalLight: true,
  22512. copy: function ( source ) {
  22513. Light.prototype.copy.call( this, source );
  22514. this.target = source.target.clone();
  22515. this.shadow = source.shadow.clone();
  22516. return this;
  22517. }
  22518. } );
  22519. /**
  22520. * @author mrdoob / http://mrdoob.com/
  22521. */
  22522. function AmbientLight( color, intensity ) {
  22523. Light.call( this, color, intensity );
  22524. this.type = 'AmbientLight';
  22525. this.castShadow = undefined;
  22526. }
  22527. AmbientLight.prototype = Object.assign( Object.create( Light.prototype ), {
  22528. constructor: AmbientLight,
  22529. isAmbientLight: true
  22530. } );
  22531. /**
  22532. * @author abelnation / http://github.com/abelnation
  22533. */
  22534. function RectAreaLight( color, intensity, width, height ) {
  22535. Light.call( this, color, intensity );
  22536. this.type = 'RectAreaLight';
  22537. this.width = ( width !== undefined ) ? width : 10;
  22538. this.height = ( height !== undefined ) ? height : 10;
  22539. }
  22540. RectAreaLight.prototype = Object.assign( Object.create( Light.prototype ), {
  22541. constructor: RectAreaLight,
  22542. isRectAreaLight: true,
  22543. copy: function ( source ) {
  22544. Light.prototype.copy.call( this, source );
  22545. this.width = source.width;
  22546. this.height = source.height;
  22547. return this;
  22548. },
  22549. toJSON: function ( meta ) {
  22550. var data = Light.prototype.toJSON.call( this, meta );
  22551. data.object.width = this.width;
  22552. data.object.height = this.height;
  22553. return data;
  22554. }
  22555. } );
  22556. /**
  22557. * @author mrdoob / http://mrdoob.com/
  22558. */
  22559. function MaterialLoader( manager ) {
  22560. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  22561. this.textures = {};
  22562. }
  22563. Object.assign( MaterialLoader.prototype, {
  22564. load: function ( url, onLoad, onProgress, onError ) {
  22565. var scope = this;
  22566. var loader = new FileLoader( scope.manager );
  22567. loader.setPath( scope.path );
  22568. loader.load( url, function ( text ) {
  22569. onLoad( scope.parse( JSON.parse( text ) ) );
  22570. }, onProgress, onError );
  22571. },
  22572. parse: function ( json ) {
  22573. var textures = this.textures;
  22574. function getTexture( name ) {
  22575. if ( textures[ name ] === undefined ) {
  22576. console.warn( 'THREE.MaterialLoader: Undefined texture', name );
  22577. }
  22578. return textures[ name ];
  22579. }
  22580. var material = new Materials[ json.type ]();
  22581. if ( json.uuid !== undefined ) material.uuid = json.uuid;
  22582. if ( json.name !== undefined ) material.name = json.name;
  22583. if ( json.color !== undefined ) material.color.setHex( json.color );
  22584. if ( json.roughness !== undefined ) material.roughness = json.roughness;
  22585. if ( json.metalness !== undefined ) material.metalness = json.metalness;
  22586. if ( json.emissive !== undefined ) material.emissive.setHex( json.emissive );
  22587. if ( json.specular !== undefined ) material.specular.setHex( json.specular );
  22588. if ( json.shininess !== undefined ) material.shininess = json.shininess;
  22589. if ( json.clearCoat !== undefined ) material.clearCoat = json.clearCoat;
  22590. if ( json.clearCoatRoughness !== undefined ) material.clearCoatRoughness = json.clearCoatRoughness;
  22591. if ( json.vertexColors !== undefined ) material.vertexColors = json.vertexColors;
  22592. if ( json.fog !== undefined ) material.fog = json.fog;
  22593. if ( json.flatShading !== undefined ) material.flatShading = json.flatShading;
  22594. if ( json.blending !== undefined ) material.blending = json.blending;
  22595. if ( json.combine !== undefined ) material.combine = json.combine;
  22596. if ( json.side !== undefined ) material.side = json.side;
  22597. if ( json.opacity !== undefined ) material.opacity = json.opacity;
  22598. if ( json.transparent !== undefined ) material.transparent = json.transparent;
  22599. if ( json.alphaTest !== undefined ) material.alphaTest = json.alphaTest;
  22600. if ( json.depthTest !== undefined ) material.depthTest = json.depthTest;
  22601. if ( json.depthWrite !== undefined ) material.depthWrite = json.depthWrite;
  22602. if ( json.colorWrite !== undefined ) material.colorWrite = json.colorWrite;
  22603. if ( json.wireframe !== undefined ) material.wireframe = json.wireframe;
  22604. if ( json.wireframeLinewidth !== undefined ) material.wireframeLinewidth = json.wireframeLinewidth;
  22605. if ( json.wireframeLinecap !== undefined ) material.wireframeLinecap = json.wireframeLinecap;
  22606. if ( json.wireframeLinejoin !== undefined ) material.wireframeLinejoin = json.wireframeLinejoin;
  22607. if ( json.rotation !== undefined ) material.rotation = json.rotation;
  22608. if ( json.linewidth !== 1 ) material.linewidth = json.linewidth;
  22609. if ( json.dashSize !== undefined ) material.dashSize = json.dashSize;
  22610. if ( json.gapSize !== undefined ) material.gapSize = json.gapSize;
  22611. if ( json.scale !== undefined ) material.scale = json.scale;
  22612. if ( json.polygonOffset !== undefined ) material.polygonOffset = json.polygonOffset;
  22613. if ( json.polygonOffsetFactor !== undefined ) material.polygonOffsetFactor = json.polygonOffsetFactor;
  22614. if ( json.polygonOffsetUnits !== undefined ) material.polygonOffsetUnits = json.polygonOffsetUnits;
  22615. if ( json.skinning !== undefined ) material.skinning = json.skinning;
  22616. if ( json.morphTargets !== undefined ) material.morphTargets = json.morphTargets;
  22617. if ( json.dithering !== undefined ) material.dithering = json.dithering;
  22618. if ( json.visible !== undefined ) material.visible = json.visible;
  22619. if ( json.userData !== undefined ) material.userData = json.userData;
  22620. // Shader Material
  22621. if ( json.uniforms !== undefined ) {
  22622. for ( var name in json.uniforms ) {
  22623. var uniform = json.uniforms[ name ];
  22624. material.uniforms[ name ] = {};
  22625. switch ( uniform.type ) {
  22626. case 't':
  22627. material.uniforms[ name ].value = getTexture( uniform.value );
  22628. break;
  22629. case 'c':
  22630. material.uniforms[ name ].value = new Color().setHex( uniform.value );
  22631. break;
  22632. case 'v2':
  22633. material.uniforms[ name ].value = new Vector2().fromArray( uniform.value );
  22634. break;
  22635. case 'v3':
  22636. material.uniforms[ name ].value = new Vector3().fromArray( uniform.value );
  22637. break;
  22638. case 'v4':
  22639. material.uniforms[ name ].value = new Vector4().fromArray( uniform.value );
  22640. break;
  22641. case 'm3':
  22642. material.uniforms[ name ].value = new Matrix3().fromArray( uniform.value );
  22643. case 'm4':
  22644. material.uniforms[ name ].value = new Matrix4().fromArray( uniform.value );
  22645. break;
  22646. default:
  22647. material.uniforms[ name ].value = uniform.value;
  22648. }
  22649. }
  22650. }
  22651. if ( json.defines !== undefined ) material.defines = json.defines;
  22652. if ( json.vertexShader !== undefined ) material.vertexShader = json.vertexShader;
  22653. if ( json.fragmentShader !== undefined ) material.fragmentShader = json.fragmentShader;
  22654. if ( json.extensions !== undefined ) {
  22655. for ( var key in json.extensions ) {
  22656. material.extensions[ key ] = json.extensions[ key ];
  22657. }
  22658. }
  22659. // Deprecated
  22660. if ( json.shading !== undefined ) material.flatShading = json.shading === 1; // THREE.FlatShading
  22661. // for PointsMaterial
  22662. if ( json.size !== undefined ) material.size = json.size;
  22663. if ( json.sizeAttenuation !== undefined ) material.sizeAttenuation = json.sizeAttenuation;
  22664. // maps
  22665. if ( json.map !== undefined ) material.map = getTexture( json.map );
  22666. if ( json.matcap !== undefined ) material.matcap = getTexture( json.matcap );
  22667. if ( json.alphaMap !== undefined ) {
  22668. material.alphaMap = getTexture( json.alphaMap );
  22669. material.transparent = true;
  22670. }
  22671. if ( json.bumpMap !== undefined ) material.bumpMap = getTexture( json.bumpMap );
  22672. if ( json.bumpScale !== undefined ) material.bumpScale = json.bumpScale;
  22673. if ( json.normalMap !== undefined ) material.normalMap = getTexture( json.normalMap );
  22674. if ( json.normalMapType !== undefined ) material.normalMapType = json.normalMapType;
  22675. if ( json.normalScale !== undefined ) {
  22676. var normalScale = json.normalScale;
  22677. if ( Array.isArray( normalScale ) === false ) {
  22678. // Blender exporter used to export a scalar. See #7459
  22679. normalScale = [ normalScale, normalScale ];
  22680. }
  22681. material.normalScale = new Vector2().fromArray( normalScale );
  22682. }
  22683. if ( json.displacementMap !== undefined ) material.displacementMap = getTexture( json.displacementMap );
  22684. if ( json.displacementScale !== undefined ) material.displacementScale = json.displacementScale;
  22685. if ( json.displacementBias !== undefined ) material.displacementBias = json.displacementBias;
  22686. if ( json.roughnessMap !== undefined ) material.roughnessMap = getTexture( json.roughnessMap );
  22687. if ( json.metalnessMap !== undefined ) material.metalnessMap = getTexture( json.metalnessMap );
  22688. if ( json.emissiveMap !== undefined ) material.emissiveMap = getTexture( json.emissiveMap );
  22689. if ( json.emissiveIntensity !== undefined ) material.emissiveIntensity = json.emissiveIntensity;
  22690. if ( json.specularMap !== undefined ) material.specularMap = getTexture( json.specularMap );
  22691. if ( json.envMap !== undefined ) material.envMap = getTexture( json.envMap );
  22692. if ( json.envMapIntensity !== undefined ) material.envMapIntensity = json.envMapIntensity;
  22693. if ( json.reflectivity !== undefined ) material.reflectivity = json.reflectivity;
  22694. if ( json.lightMap !== undefined ) material.lightMap = getTexture( json.lightMap );
  22695. if ( json.lightMapIntensity !== undefined ) material.lightMapIntensity = json.lightMapIntensity;
  22696. if ( json.aoMap !== undefined ) material.aoMap = getTexture( json.aoMap );
  22697. if ( json.aoMapIntensity !== undefined ) material.aoMapIntensity = json.aoMapIntensity;
  22698. if ( json.gradientMap !== undefined ) material.gradientMap = getTexture( json.gradientMap );
  22699. return material;
  22700. },
  22701. setPath: function ( value ) {
  22702. this.path = value;
  22703. return this;
  22704. },
  22705. setTextures: function ( value ) {
  22706. this.textures = value;
  22707. return this;
  22708. }
  22709. } );
  22710. /**
  22711. * @author Don McCurdy / https://www.donmccurdy.com
  22712. */
  22713. var LoaderUtils = {
  22714. decodeText: function ( array ) {
  22715. if ( typeof TextDecoder !== 'undefined' ) {
  22716. return new TextDecoder().decode( array );
  22717. }
  22718. // Avoid the String.fromCharCode.apply(null, array) shortcut, which
  22719. // throws a "maximum call stack size exceeded" error for large arrays.
  22720. var s = '';
  22721. for ( var i = 0, il = array.length; i < il; i ++ ) {
  22722. // Implicitly assumes little-endian.
  22723. s += String.fromCharCode( array[ i ] );
  22724. }
  22725. try {
  22726. // merges multi-byte utf-8 characters.
  22727. return decodeURIComponent( escape( s ) );
  22728. } catch ( e ) { // see #16358
  22729. return s;
  22730. }
  22731. },
  22732. extractUrlBase: function ( url ) {
  22733. var index = url.lastIndexOf( '/' );
  22734. if ( index === - 1 ) return './';
  22735. return url.substr( 0, index + 1 );
  22736. }
  22737. };
  22738. /**
  22739. * @author benaadams / https://twitter.com/ben_a_adams
  22740. */
  22741. function InstancedBufferGeometry() {
  22742. BufferGeometry.call( this );
  22743. this.type = 'InstancedBufferGeometry';
  22744. this.maxInstancedCount = undefined;
  22745. }
  22746. InstancedBufferGeometry.prototype = Object.assign( Object.create( BufferGeometry.prototype ), {
  22747. constructor: InstancedBufferGeometry,
  22748. isInstancedBufferGeometry: true,
  22749. copy: function ( source ) {
  22750. BufferGeometry.prototype.copy.call( this, source );
  22751. this.maxInstancedCount = source.maxInstancedCount;
  22752. return this;
  22753. },
  22754. clone: function () {
  22755. return new this.constructor().copy( this );
  22756. },
  22757. toJSON: function () {
  22758. var data = BufferGeometry.prototype.toJSON.call( this );
  22759. data.maxInstancedCount = this.maxInstancedCount;
  22760. data.isInstancedBufferGeometry = true;
  22761. return data;
  22762. }
  22763. } );
  22764. /**
  22765. * @author benaadams / https://twitter.com/ben_a_adams
  22766. */
  22767. function InstancedBufferAttribute( array, itemSize, normalized, meshPerAttribute ) {
  22768. if ( typeof ( normalized ) === 'number' ) {
  22769. meshPerAttribute = normalized;
  22770. normalized = false;
  22771. console.error( 'THREE.InstancedBufferAttribute: The constructor now expects normalized as the third argument.' );
  22772. }
  22773. BufferAttribute.call( this, array, itemSize, normalized );
  22774. this.meshPerAttribute = meshPerAttribute || 1;
  22775. }
  22776. InstancedBufferAttribute.prototype = Object.assign( Object.create( BufferAttribute.prototype ), {
  22777. constructor: InstancedBufferAttribute,
  22778. isInstancedBufferAttribute: true,
  22779. copy: function ( source ) {
  22780. BufferAttribute.prototype.copy.call( this, source );
  22781. this.meshPerAttribute = source.meshPerAttribute;
  22782. return this;
  22783. },
  22784. toJSON: function () {
  22785. var data = BufferAttribute.prototype.toJSON.call( this );
  22786. data.meshPerAttribute = this.meshPerAttribute;
  22787. data.isInstancedBufferAttribute = true;
  22788. return data;
  22789. }
  22790. } );
  22791. /**
  22792. * @author mrdoob / http://mrdoob.com/
  22793. */
  22794. function BufferGeometryLoader( manager ) {
  22795. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  22796. }
  22797. Object.assign( BufferGeometryLoader.prototype, {
  22798. load: function ( url, onLoad, onProgress, onError ) {
  22799. var scope = this;
  22800. var loader = new FileLoader( scope.manager );
  22801. loader.setPath( scope.path );
  22802. loader.load( url, function ( text ) {
  22803. onLoad( scope.parse( JSON.parse( text ) ) );
  22804. }, onProgress, onError );
  22805. },
  22806. parse: function ( json ) {
  22807. var geometry = json.isInstancedBufferGeometry ? new InstancedBufferGeometry() : new BufferGeometry();
  22808. var index = json.data.index;
  22809. if ( index !== undefined ) {
  22810. var typedArray = new TYPED_ARRAYS[ index.type ]( index.array );
  22811. geometry.setIndex( new BufferAttribute( typedArray, 1 ) );
  22812. }
  22813. var attributes = json.data.attributes;
  22814. for ( var key in attributes ) {
  22815. var attribute = attributes[ key ];
  22816. var typedArray = new TYPED_ARRAYS[ attribute.type ]( attribute.array );
  22817. var bufferAttributeConstr = attribute.isInstancedBufferAttribute ? InstancedBufferAttribute : BufferAttribute;
  22818. var bufferAttribute = new bufferAttributeConstr( typedArray, attribute.itemSize, attribute.normalized );
  22819. if ( attribute.name !== undefined ) bufferAttribute.name = attribute.name;
  22820. geometry.addAttribute( key, bufferAttribute );
  22821. }
  22822. var morphAttributes = json.data.morphAttributes;
  22823. if ( morphAttributes ) {
  22824. for ( var key in morphAttributes ) {
  22825. var attributeArray = morphAttributes[ key ];
  22826. var array = [];
  22827. for ( var i = 0, il = attributeArray.length; i < il; i ++ ) {
  22828. var attribute = attributeArray[ i ];
  22829. var typedArray = new TYPED_ARRAYS[ attribute.type ]( attribute.array );
  22830. var bufferAttribute = new BufferAttribute( typedArray, attribute.itemSize, attribute.normalized );
  22831. if ( attribute.name !== undefined ) bufferAttribute.name = attribute.name;
  22832. array.push( bufferAttribute );
  22833. }
  22834. geometry.morphAttributes[ key ] = array;
  22835. }
  22836. }
  22837. var groups = json.data.groups || json.data.drawcalls || json.data.offsets;
  22838. if ( groups !== undefined ) {
  22839. for ( var i = 0, n = groups.length; i !== n; ++ i ) {
  22840. var group = groups[ i ];
  22841. geometry.addGroup( group.start, group.count, group.materialIndex );
  22842. }
  22843. }
  22844. var boundingSphere = json.data.boundingSphere;
  22845. if ( boundingSphere !== undefined ) {
  22846. var center = new Vector3();
  22847. if ( boundingSphere.center !== undefined ) {
  22848. center.fromArray( boundingSphere.center );
  22849. }
  22850. geometry.boundingSphere = new Sphere( center, boundingSphere.radius );
  22851. }
  22852. if ( json.name ) geometry.name = json.name;
  22853. if ( json.userData ) geometry.userData = json.userData;
  22854. return geometry;
  22855. },
  22856. setPath: function ( value ) {
  22857. this.path = value;
  22858. return this;
  22859. }
  22860. } );
  22861. var TYPED_ARRAYS = {
  22862. Int8Array: Int8Array,
  22863. Uint8Array: Uint8Array,
  22864. // Workaround for IE11 pre KB2929437. See #11440
  22865. Uint8ClampedArray: typeof Uint8ClampedArray !== 'undefined' ? Uint8ClampedArray : Uint8Array,
  22866. Int16Array: Int16Array,
  22867. Uint16Array: Uint16Array,
  22868. Int32Array: Int32Array,
  22869. Uint32Array: Uint32Array,
  22870. Float32Array: Float32Array,
  22871. Float64Array: Float64Array
  22872. };
  22873. /**
  22874. * @author mrdoob / http://mrdoob.com/
  22875. */
  22876. function ObjectLoader( manager ) {
  22877. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  22878. this.resourcePath = '';
  22879. }
  22880. Object.assign( ObjectLoader.prototype, {
  22881. crossOrigin: 'anonymous',
  22882. load: function ( url, onLoad, onProgress, onError ) {
  22883. var scope = this;
  22884. var path = ( this.path === undefined ) ? LoaderUtils.extractUrlBase( url ) : this.path;
  22885. this.resourcePath = this.resourcePath || path;
  22886. var loader = new FileLoader( scope.manager );
  22887. loader.setPath( this.path );
  22888. loader.load( url, function ( text ) {
  22889. var json = null;
  22890. try {
  22891. json = JSON.parse( text );
  22892. } catch ( error ) {
  22893. if ( onError !== undefined ) onError( error );
  22894. console.error( 'THREE:ObjectLoader: Can\'t parse ' + url + '.', error.message );
  22895. return;
  22896. }
  22897. var metadata = json.metadata;
  22898. if ( metadata === undefined || metadata.type === undefined || metadata.type.toLowerCase() === 'geometry' ) {
  22899. console.error( 'THREE.ObjectLoader: Can\'t load ' + url );
  22900. return;
  22901. }
  22902. scope.parse( json, onLoad );
  22903. }, onProgress, onError );
  22904. },
  22905. setPath: function ( value ) {
  22906. this.path = value;
  22907. return this;
  22908. },
  22909. setResourcePath: function ( value ) {
  22910. this.resourcePath = value;
  22911. return this;
  22912. },
  22913. setCrossOrigin: function ( value ) {
  22914. this.crossOrigin = value;
  22915. return this;
  22916. },
  22917. parse: function ( json, onLoad ) {
  22918. var shapes = this.parseShape( json.shapes );
  22919. var geometries = this.parseGeometries( json.geometries, shapes );
  22920. var images = this.parseImages( json.images, function () {
  22921. if ( onLoad !== undefined ) onLoad( object );
  22922. } );
  22923. var textures = this.parseTextures( json.textures, images );
  22924. var materials = this.parseMaterials( json.materials, textures );
  22925. var object = this.parseObject( json.object, geometries, materials );
  22926. if ( json.animations ) {
  22927. object.animations = this.parseAnimations( json.animations );
  22928. }
  22929. if ( json.images === undefined || json.images.length === 0 ) {
  22930. if ( onLoad !== undefined ) onLoad( object );
  22931. }
  22932. return object;
  22933. },
  22934. parseShape: function ( json ) {
  22935. var shapes = {};
  22936. if ( json !== undefined ) {
  22937. for ( var i = 0, l = json.length; i < l; i ++ ) {
  22938. var shape = new Shape().fromJSON( json[ i ] );
  22939. shapes[ shape.uuid ] = shape;
  22940. }
  22941. }
  22942. return shapes;
  22943. },
  22944. parseGeometries: function ( json, shapes ) {
  22945. var geometries = {};
  22946. if ( json !== undefined ) {
  22947. var bufferGeometryLoader = new BufferGeometryLoader();
  22948. for ( var i = 0, l = json.length; i < l; i ++ ) {
  22949. var geometry;
  22950. var data = json[ i ];
  22951. switch ( data.type ) {
  22952. case 'PlaneGeometry':
  22953. case 'PlaneBufferGeometry':
  22954. geometry = new Geometries[ data.type ](
  22955. data.width,
  22956. data.height,
  22957. data.widthSegments,
  22958. data.heightSegments
  22959. );
  22960. break;
  22961. case 'BoxGeometry':
  22962. case 'BoxBufferGeometry':
  22963. case 'CubeGeometry': // backwards compatible
  22964. geometry = new Geometries[ data.type ](
  22965. data.width,
  22966. data.height,
  22967. data.depth,
  22968. data.widthSegments,
  22969. data.heightSegments,
  22970. data.depthSegments
  22971. );
  22972. break;
  22973. case 'CircleGeometry':
  22974. case 'CircleBufferGeometry':
  22975. geometry = new Geometries[ data.type ](
  22976. data.radius,
  22977. data.segments,
  22978. data.thetaStart,
  22979. data.thetaLength
  22980. );
  22981. break;
  22982. case 'CylinderGeometry':
  22983. case 'CylinderBufferGeometry':
  22984. geometry = new Geometries[ data.type ](
  22985. data.radiusTop,
  22986. data.radiusBottom,
  22987. data.height,
  22988. data.radialSegments,
  22989. data.heightSegments,
  22990. data.openEnded,
  22991. data.thetaStart,
  22992. data.thetaLength
  22993. );
  22994. break;
  22995. case 'ConeGeometry':
  22996. case 'ConeBufferGeometry':
  22997. geometry = new Geometries[ data.type ](
  22998. data.radius,
  22999. data.height,
  23000. data.radialSegments,
  23001. data.heightSegments,
  23002. data.openEnded,
  23003. data.thetaStart,
  23004. data.thetaLength
  23005. );
  23006. break;
  23007. case 'SphereGeometry':
  23008. case 'SphereBufferGeometry':
  23009. geometry = new Geometries[ data.type ](
  23010. data.radius,
  23011. data.widthSegments,
  23012. data.heightSegments,
  23013. data.phiStart,
  23014. data.phiLength,
  23015. data.thetaStart,
  23016. data.thetaLength
  23017. );
  23018. break;
  23019. case 'DodecahedronGeometry':
  23020. case 'DodecahedronBufferGeometry':
  23021. case 'IcosahedronGeometry':
  23022. case 'IcosahedronBufferGeometry':
  23023. case 'OctahedronGeometry':
  23024. case 'OctahedronBufferGeometry':
  23025. case 'TetrahedronGeometry':
  23026. case 'TetrahedronBufferGeometry':
  23027. geometry = new Geometries[ data.type ](
  23028. data.radius,
  23029. data.detail
  23030. );
  23031. break;
  23032. case 'RingGeometry':
  23033. case 'RingBufferGeometry':
  23034. geometry = new Geometries[ data.type ](
  23035. data.innerRadius,
  23036. data.outerRadius,
  23037. data.thetaSegments,
  23038. data.phiSegments,
  23039. data.thetaStart,
  23040. data.thetaLength
  23041. );
  23042. break;
  23043. case 'TorusGeometry':
  23044. case 'TorusBufferGeometry':
  23045. geometry = new Geometries[ data.type ](
  23046. data.radius,
  23047. data.tube,
  23048. data.radialSegments,
  23049. data.tubularSegments,
  23050. data.arc
  23051. );
  23052. break;
  23053. case 'TorusKnotGeometry':
  23054. case 'TorusKnotBufferGeometry':
  23055. geometry = new Geometries[ data.type ](
  23056. data.radius,
  23057. data.tube,
  23058. data.tubularSegments,
  23059. data.radialSegments,
  23060. data.p,
  23061. data.q
  23062. );
  23063. break;
  23064. case 'TubeGeometry':
  23065. case 'TubeBufferGeometry':
  23066. // This only works for built-in curves (e.g. CatmullRomCurve3).
  23067. // User defined curves or instances of CurvePath will not be deserialized.
  23068. geometry = new Geometries[ data.type ](
  23069. new Curves[ data.path.type ]().fromJSON( data.path ),
  23070. data.tubularSegments,
  23071. data.radius,
  23072. data.radialSegments,
  23073. data.closed
  23074. );
  23075. break;
  23076. case 'LatheGeometry':
  23077. case 'LatheBufferGeometry':
  23078. geometry = new Geometries[ data.type ](
  23079. data.points,
  23080. data.segments,
  23081. data.phiStart,
  23082. data.phiLength
  23083. );
  23084. break;
  23085. case 'PolyhedronGeometry':
  23086. case 'PolyhedronBufferGeometry':
  23087. geometry = new Geometries[ data.type ](
  23088. data.vertices,
  23089. data.indices,
  23090. data.radius,
  23091. data.details
  23092. );
  23093. break;
  23094. case 'ShapeGeometry':
  23095. case 'ShapeBufferGeometry':
  23096. var geometryShapes = [];
  23097. for ( var j = 0, jl = data.shapes.length; j < jl; j ++ ) {
  23098. var shape = shapes[ data.shapes[ j ] ];
  23099. geometryShapes.push( shape );
  23100. }
  23101. geometry = new Geometries[ data.type ](
  23102. geometryShapes,
  23103. data.curveSegments
  23104. );
  23105. break;
  23106. case 'ExtrudeGeometry':
  23107. case 'ExtrudeBufferGeometry':
  23108. var geometryShapes = [];
  23109. for ( var j = 0, jl = data.shapes.length; j < jl; j ++ ) {
  23110. var shape = shapes[ data.shapes[ j ] ];
  23111. geometryShapes.push( shape );
  23112. }
  23113. var extrudePath = data.options.extrudePath;
  23114. if ( extrudePath !== undefined ) {
  23115. data.options.extrudePath = new Curves[ extrudePath.type ]().fromJSON( extrudePath );
  23116. }
  23117. geometry = new Geometries[ data.type ](
  23118. geometryShapes,
  23119. data.options
  23120. );
  23121. break;
  23122. case 'BufferGeometry':
  23123. case 'InstancedBufferGeometry':
  23124. geometry = bufferGeometryLoader.parse( data );
  23125. break;
  23126. case 'Geometry':
  23127. if ( 'THREE' in window && 'LegacyJSONLoader' in THREE ) {
  23128. var geometryLoader = new THREE.LegacyJSONLoader();
  23129. geometry = geometryLoader.parse( data, this.resourcePath ).geometry;
  23130. } else {
  23131. console.error( 'THREE.ObjectLoader: You have to import LegacyJSONLoader in order load geometry data of type "Geometry".' );
  23132. }
  23133. break;
  23134. default:
  23135. console.warn( 'THREE.ObjectLoader: Unsupported geometry type "' + data.type + '"' );
  23136. continue;
  23137. }
  23138. geometry.uuid = data.uuid;
  23139. if ( data.name !== undefined ) geometry.name = data.name;
  23140. if ( geometry.isBufferGeometry === true && data.userData !== undefined ) geometry.userData = data.userData;
  23141. geometries[ data.uuid ] = geometry;
  23142. }
  23143. }
  23144. return geometries;
  23145. },
  23146. parseMaterials: function ( json, textures ) {
  23147. var cache = {}; // MultiMaterial
  23148. var materials = {};
  23149. if ( json !== undefined ) {
  23150. var loader = new MaterialLoader();
  23151. loader.setTextures( textures );
  23152. for ( var i = 0, l = json.length; i < l; i ++ ) {
  23153. var data = json[ i ];
  23154. if ( data.type === 'MultiMaterial' ) {
  23155. // Deprecated
  23156. var array = [];
  23157. for ( var j = 0; j < data.materials.length; j ++ ) {
  23158. var material = data.materials[ j ];
  23159. if ( cache[ material.uuid ] === undefined ) {
  23160. cache[ material.uuid ] = loader.parse( material );
  23161. }
  23162. array.push( cache[ material.uuid ] );
  23163. }
  23164. materials[ data.uuid ] = array;
  23165. } else {
  23166. if ( cache[ data.uuid ] === undefined ) {
  23167. cache[ data.uuid ] = loader.parse( data );
  23168. }
  23169. materials[ data.uuid ] = cache[ data.uuid ];
  23170. }
  23171. }
  23172. }
  23173. return materials;
  23174. },
  23175. parseAnimations: function ( json ) {
  23176. var animations = [];
  23177. for ( var i = 0; i < json.length; i ++ ) {
  23178. var data = json[ i ];
  23179. var clip = AnimationClip.parse( data );
  23180. if ( data.uuid !== undefined ) clip.uuid = data.uuid;
  23181. animations.push( clip );
  23182. }
  23183. return animations;
  23184. },
  23185. parseImages: function ( json, onLoad ) {
  23186. var scope = this;
  23187. var images = {};
  23188. function loadImage( url ) {
  23189. scope.manager.itemStart( url );
  23190. return loader.load( url, function () {
  23191. scope.manager.itemEnd( url );
  23192. }, undefined, function () {
  23193. scope.manager.itemError( url );
  23194. scope.manager.itemEnd( url );
  23195. } );
  23196. }
  23197. if ( json !== undefined && json.length > 0 ) {
  23198. var manager = new LoadingManager( onLoad );
  23199. var loader = new ImageLoader( manager );
  23200. loader.setCrossOrigin( this.crossOrigin );
  23201. for ( var i = 0, il = json.length; i < il; i ++ ) {
  23202. var image = json[ i ];
  23203. var url = image.url;
  23204. if ( Array.isArray( url ) ) {
  23205. // load array of images e.g CubeTexture
  23206. images[ image.uuid ] = [];
  23207. for ( var j = 0, jl = url.length; j < jl; j ++ ) {
  23208. var currentUrl = url[ j ];
  23209. var path = /^(\/\/)|([a-z]+:(\/\/)?)/i.test( currentUrl ) ? currentUrl : scope.resourcePath + currentUrl;
  23210. images[ image.uuid ].push( loadImage( path ) );
  23211. }
  23212. } else {
  23213. // load single image
  23214. var path = /^(\/\/)|([a-z]+:(\/\/)?)/i.test( image.url ) ? image.url : scope.resourcePath + image.url;
  23215. images[ image.uuid ] = loadImage( path );
  23216. }
  23217. }
  23218. }
  23219. return images;
  23220. },
  23221. parseTextures: function ( json, images ) {
  23222. function parseConstant( value, type ) {
  23223. if ( typeof value === 'number' ) return value;
  23224. console.warn( 'THREE.ObjectLoader.parseTexture: Constant should be in numeric form.', value );
  23225. return type[ value ];
  23226. }
  23227. var textures = {};
  23228. if ( json !== undefined ) {
  23229. for ( var i = 0, l = json.length; i < l; i ++ ) {
  23230. var data = json[ i ];
  23231. if ( data.image === undefined ) {
  23232. console.warn( 'THREE.ObjectLoader: No "image" specified for', data.uuid );
  23233. }
  23234. if ( images[ data.image ] === undefined ) {
  23235. console.warn( 'THREE.ObjectLoader: Undefined image', data.image );
  23236. }
  23237. var texture;
  23238. if ( Array.isArray( images[ data.image ] ) ) {
  23239. texture = new CubeTexture( images[ data.image ] );
  23240. } else {
  23241. texture = new Texture( images[ data.image ] );
  23242. }
  23243. texture.needsUpdate = true;
  23244. texture.uuid = data.uuid;
  23245. if ( data.name !== undefined ) texture.name = data.name;
  23246. if ( data.mapping !== undefined ) texture.mapping = parseConstant( data.mapping, TEXTURE_MAPPING );
  23247. if ( data.offset !== undefined ) texture.offset.fromArray( data.offset );
  23248. if ( data.repeat !== undefined ) texture.repeat.fromArray( data.repeat );
  23249. if ( data.center !== undefined ) texture.center.fromArray( data.center );
  23250. if ( data.rotation !== undefined ) texture.rotation = data.rotation;
  23251. if ( data.wrap !== undefined ) {
  23252. texture.wrapS = parseConstant( data.wrap[ 0 ], TEXTURE_WRAPPING );
  23253. texture.wrapT = parseConstant( data.wrap[ 1 ], TEXTURE_WRAPPING );
  23254. }
  23255. if ( data.format !== undefined ) texture.format = data.format;
  23256. if ( data.type !== undefined ) texture.type = data.type;
  23257. if ( data.encoding !== undefined ) texture.encoding = data.encoding;
  23258. if ( data.minFilter !== undefined ) texture.minFilter = parseConstant( data.minFilter, TEXTURE_FILTER );
  23259. if ( data.magFilter !== undefined ) texture.magFilter = parseConstant( data.magFilter, TEXTURE_FILTER );
  23260. if ( data.anisotropy !== undefined ) texture.anisotropy = data.anisotropy;
  23261. if ( data.flipY !== undefined ) texture.flipY = data.flipY;
  23262. if ( data.premultiplyAlpha !== undefined ) texture.premultiplyAlpha = data.premultiplyAlpha;
  23263. if ( data.unpackAlignment !== undefined ) texture.unpackAlignment = data.unpackAlignment;
  23264. textures[ data.uuid ] = texture;
  23265. }
  23266. }
  23267. return textures;
  23268. },
  23269. parseObject: function ( data, geometries, materials ) {
  23270. var object;
  23271. function getGeometry( name ) {
  23272. if ( geometries[ name ] === undefined ) {
  23273. console.warn( 'THREE.ObjectLoader: Undefined geometry', name );
  23274. }
  23275. return geometries[ name ];
  23276. }
  23277. function getMaterial( name ) {
  23278. if ( name === undefined ) return undefined;
  23279. if ( Array.isArray( name ) ) {
  23280. var array = [];
  23281. for ( var i = 0, l = name.length; i < l; i ++ ) {
  23282. var uuid = name[ i ];
  23283. if ( materials[ uuid ] === undefined ) {
  23284. console.warn( 'THREE.ObjectLoader: Undefined material', uuid );
  23285. }
  23286. array.push( materials[ uuid ] );
  23287. }
  23288. return array;
  23289. }
  23290. if ( materials[ name ] === undefined ) {
  23291. console.warn( 'THREE.ObjectLoader: Undefined material', name );
  23292. }
  23293. return materials[ name ];
  23294. }
  23295. switch ( data.type ) {
  23296. case 'Scene':
  23297. object = new Scene();
  23298. if ( data.background !== undefined ) {
  23299. if ( Number.isInteger( data.background ) ) {
  23300. object.background = new Color( data.background );
  23301. }
  23302. }
  23303. if ( data.fog !== undefined ) {
  23304. if ( data.fog.type === 'Fog' ) {
  23305. object.fog = new Fog( data.fog.color, data.fog.near, data.fog.far );
  23306. } else if ( data.fog.type === 'FogExp2' ) {
  23307. object.fog = new FogExp2( data.fog.color, data.fog.density );
  23308. }
  23309. }
  23310. break;
  23311. case 'PerspectiveCamera':
  23312. object = new PerspectiveCamera( data.fov, data.aspect, data.near, data.far );
  23313. if ( data.focus !== undefined ) object.focus = data.focus;
  23314. if ( data.zoom !== undefined ) object.zoom = data.zoom;
  23315. if ( data.filmGauge !== undefined ) object.filmGauge = data.filmGauge;
  23316. if ( data.filmOffset !== undefined ) object.filmOffset = data.filmOffset;
  23317. if ( data.view !== undefined ) object.view = Object.assign( {}, data.view );
  23318. break;
  23319. case 'OrthographicCamera':
  23320. object = new OrthographicCamera( data.left, data.right, data.top, data.bottom, data.near, data.far );
  23321. if ( data.zoom !== undefined ) object.zoom = data.zoom;
  23322. if ( data.view !== undefined ) object.view = Object.assign( {}, data.view );
  23323. break;
  23324. case 'AmbientLight':
  23325. object = new AmbientLight( data.color, data.intensity );
  23326. break;
  23327. case 'DirectionalLight':
  23328. object = new DirectionalLight( data.color, data.intensity );
  23329. break;
  23330. case 'PointLight':
  23331. object = new PointLight( data.color, data.intensity, data.distance, data.decay );
  23332. break;
  23333. case 'RectAreaLight':
  23334. object = new RectAreaLight( data.color, data.intensity, data.width, data.height );
  23335. break;
  23336. case 'SpotLight':
  23337. object = new SpotLight( data.color, data.intensity, data.distance, data.angle, data.penumbra, data.decay );
  23338. break;
  23339. case 'HemisphereLight':
  23340. object = new HemisphereLight( data.color, data.groundColor, data.intensity );
  23341. break;
  23342. case 'SkinnedMesh':
  23343. console.warn( 'THREE.ObjectLoader.parseObject() does not support SkinnedMesh yet.' );
  23344. case 'Mesh':
  23345. var geometry = getGeometry( data.geometry );
  23346. var material = getMaterial( data.material );
  23347. if ( geometry.bones && geometry.bones.length > 0 ) {
  23348. object = new SkinnedMesh( geometry, material );
  23349. } else {
  23350. object = new Mesh( geometry, material );
  23351. }
  23352. if ( data.drawMode !== undefined ) object.setDrawMode( data.drawMode );
  23353. break;
  23354. case 'LOD':
  23355. object = new LOD();
  23356. break;
  23357. case 'Line':
  23358. object = new Line( getGeometry( data.geometry ), getMaterial( data.material ), data.mode );
  23359. break;
  23360. case 'LineLoop':
  23361. object = new LineLoop( getGeometry( data.geometry ), getMaterial( data.material ) );
  23362. break;
  23363. case 'LineSegments':
  23364. object = new LineSegments( getGeometry( data.geometry ), getMaterial( data.material ) );
  23365. break;
  23366. case 'PointCloud':
  23367. case 'Points':
  23368. object = new Points( getGeometry( data.geometry ), getMaterial( data.material ) );
  23369. break;
  23370. case 'Sprite':
  23371. object = new Sprite( getMaterial( data.material ) );
  23372. break;
  23373. case 'Group':
  23374. object = new Group();
  23375. break;
  23376. default:
  23377. object = new Object3D();
  23378. }
  23379. object.uuid = data.uuid;
  23380. if ( data.name !== undefined ) object.name = data.name;
  23381. if ( data.matrix !== undefined ) {
  23382. object.matrix.fromArray( data.matrix );
  23383. if ( data.matrixAutoUpdate !== undefined ) object.matrixAutoUpdate = data.matrixAutoUpdate;
  23384. if ( object.matrixAutoUpdate ) object.matrix.decompose( object.position, object.quaternion, object.scale );
  23385. } else {
  23386. if ( data.position !== undefined ) object.position.fromArray( data.position );
  23387. if ( data.rotation !== undefined ) object.rotation.fromArray( data.rotation );
  23388. if ( data.quaternion !== undefined ) object.quaternion.fromArray( data.quaternion );
  23389. if ( data.scale !== undefined ) object.scale.fromArray( data.scale );
  23390. }
  23391. if ( data.castShadow !== undefined ) object.castShadow = data.castShadow;
  23392. if ( data.receiveShadow !== undefined ) object.receiveShadow = data.receiveShadow;
  23393. if ( data.shadow ) {
  23394. if ( data.shadow.bias !== undefined ) object.shadow.bias = data.shadow.bias;
  23395. if ( data.shadow.radius !== undefined ) object.shadow.radius = data.shadow.radius;
  23396. if ( data.shadow.mapSize !== undefined ) object.shadow.mapSize.fromArray( data.shadow.mapSize );
  23397. if ( data.shadow.camera !== undefined ) object.shadow.camera = this.parseObject( data.shadow.camera );
  23398. }
  23399. if ( data.visible !== undefined ) object.visible = data.visible;
  23400. if ( data.frustumCulled !== undefined ) object.frustumCulled = data.frustumCulled;
  23401. if ( data.renderOrder !== undefined ) object.renderOrder = data.renderOrder;
  23402. if ( data.userData !== undefined ) object.userData = data.userData;
  23403. if ( data.layers !== undefined ) object.layers.mask = data.layers;
  23404. if ( data.children !== undefined ) {
  23405. var children = data.children;
  23406. for ( var i = 0; i < children.length; i ++ ) {
  23407. object.add( this.parseObject( children[ i ], geometries, materials ) );
  23408. }
  23409. }
  23410. if ( data.type === 'LOD' ) {
  23411. var levels = data.levels;
  23412. for ( var l = 0; l < levels.length; l ++ ) {
  23413. var level = levels[ l ];
  23414. var child = object.getObjectByProperty( 'uuid', level.object );
  23415. if ( child !== undefined ) {
  23416. object.addLevel( child, level.distance );
  23417. }
  23418. }
  23419. }
  23420. return object;
  23421. }
  23422. } );
  23423. var TEXTURE_MAPPING = {
  23424. UVMapping: UVMapping,
  23425. CubeReflectionMapping: CubeReflectionMapping,
  23426. CubeRefractionMapping: CubeRefractionMapping,
  23427. EquirectangularReflectionMapping: EquirectangularReflectionMapping,
  23428. EquirectangularRefractionMapping: EquirectangularRefractionMapping,
  23429. SphericalReflectionMapping: SphericalReflectionMapping,
  23430. CubeUVReflectionMapping: CubeUVReflectionMapping,
  23431. CubeUVRefractionMapping: CubeUVRefractionMapping
  23432. };
  23433. var TEXTURE_WRAPPING = {
  23434. RepeatWrapping: RepeatWrapping,
  23435. ClampToEdgeWrapping: ClampToEdgeWrapping,
  23436. MirroredRepeatWrapping: MirroredRepeatWrapping
  23437. };
  23438. var TEXTURE_FILTER = {
  23439. NearestFilter: NearestFilter,
  23440. NearestMipMapNearestFilter: NearestMipMapNearestFilter,
  23441. NearestMipMapLinearFilter: NearestMipMapLinearFilter,
  23442. LinearFilter: LinearFilter,
  23443. LinearMipMapNearestFilter: LinearMipMapNearestFilter,
  23444. LinearMipMapLinearFilter: LinearMipMapLinearFilter
  23445. };
  23446. /**
  23447. * @author thespite / http://clicktorelease.com/
  23448. */
  23449. function ImageBitmapLoader( manager ) {
  23450. if ( typeof createImageBitmap === 'undefined' ) {
  23451. console.warn( 'THREE.ImageBitmapLoader: createImageBitmap() not supported.' );
  23452. }
  23453. if ( typeof fetch === 'undefined' ) {
  23454. console.warn( 'THREE.ImageBitmapLoader: fetch() not supported.' );
  23455. }
  23456. this.manager = manager !== undefined ? manager : DefaultLoadingManager;
  23457. this.options = undefined;
  23458. }
  23459. ImageBitmapLoader.prototype = {
  23460. constructor: ImageBitmapLoader,
  23461. setOptions: function setOptions( options ) {
  23462. this.options = options;
  23463. return this;
  23464. },
  23465. load: function ( url, onLoad, onProgress, onError ) {
  23466. if ( url === undefined ) url = '';
  23467. if ( this.path !== undefined ) url = this.path + url;
  23468. url = this.manager.resolveURL( url );
  23469. var scope = this;
  23470. var cached = Cache.get( url );
  23471. if ( cached !== undefined ) {
  23472. scope.manager.itemStart( url );
  23473. setTimeout( function () {
  23474. if ( onLoad ) onLoad( cached );
  23475. scope.manager.itemEnd( url );
  23476. }, 0 );
  23477. return cached;
  23478. }
  23479. fetch( url ).then( function ( res ) {
  23480. return res.blob();
  23481. } ).then( function ( blob ) {
  23482. if ( scope.options === undefined ) {
  23483. // Workaround for FireFox. It causes an error if you pass options.
  23484. return createImageBitmap( blob );
  23485. } else {
  23486. return createImageBitmap( blob, scope.options );
  23487. }
  23488. } ).then( function ( imageBitmap ) {
  23489. Cache.add( url, imageBitmap );
  23490. if ( onLoad ) onLoad( imageBitmap );
  23491. scope.manager.itemEnd( url );
  23492. } ).catch( function ( e ) {
  23493. if ( onError ) onError( e );
  23494. scope.manager.itemError( url );
  23495. scope.manager.itemEnd( url );
  23496. } );
  23497. scope.manager.itemStart( url );
  23498. },
  23499. setCrossOrigin: function ( /* value */ ) {
  23500. return this;
  23501. },
  23502. setPath: function ( value ) {
  23503. this.path = value;
  23504. return this;
  23505. }
  23506. };
  23507. /**
  23508. * @author zz85 / http://www.lab4games.net/zz85/blog
  23509. * minimal class for proxing functions to Path. Replaces old "extractSubpaths()"
  23510. **/
  23511. function ShapePath() {
  23512. this.type = 'ShapePath';
  23513. this.color = new Color();
  23514. this.subPaths = [];
  23515. this.currentPath = null;
  23516. }
  23517. Object.assign( ShapePath.prototype, {
  23518. moveTo: function ( x, y ) {
  23519. this.currentPath = new Path();
  23520. this.subPaths.push( this.currentPath );
  23521. this.currentPath.moveTo( x, y );
  23522. },
  23523. lineTo: function ( x, y ) {
  23524. this.currentPath.lineTo( x, y );
  23525. },
  23526. quadraticCurveTo: function ( aCPx, aCPy, aX, aY ) {
  23527. this.currentPath.quadraticCurveTo( aCPx, aCPy, aX, aY );
  23528. },
  23529. bezierCurveTo: function ( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY ) {
  23530. this.currentPath.bezierCurveTo( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY );
  23531. },
  23532. splineThru: function ( pts ) {
  23533. this.currentPath.splineThru( pts );
  23534. },
  23535. toShapes: function ( isCCW, noHoles ) {
  23536. function toShapesNoHoles( inSubpaths ) {
  23537. var shapes = [];
  23538. for ( var i = 0, l = inSubpaths.length; i < l; i ++ ) {
  23539. var tmpPath = inSubpaths[ i ];
  23540. var tmpShape = new Shape();
  23541. tmpShape.curves = tmpPath.curves;
  23542. shapes.push( tmpShape );
  23543. }
  23544. return shapes;
  23545. }
  23546. function isPointInsidePolygon( inPt, inPolygon ) {
  23547. var polyLen = inPolygon.length;
  23548. // inPt on polygon contour => immediate success or
  23549. // toggling of inside/outside at every single! intersection point of an edge
  23550. // with the horizontal line through inPt, left of inPt
  23551. // not counting lowerY endpoints of edges and whole edges on that line
  23552. var inside = false;
  23553. for ( var p = polyLen - 1, q = 0; q < polyLen; p = q ++ ) {
  23554. var edgeLowPt = inPolygon[ p ];
  23555. var edgeHighPt = inPolygon[ q ];
  23556. var edgeDx = edgeHighPt.x - edgeLowPt.x;
  23557. var edgeDy = edgeHighPt.y - edgeLowPt.y;
  23558. if ( Math.abs( edgeDy ) > Number.EPSILON ) {
  23559. // not parallel
  23560. if ( edgeDy < 0 ) {
  23561. edgeLowPt = inPolygon[ q ]; edgeDx = - edgeDx;
  23562. edgeHighPt = inPolygon[ p ]; edgeDy = - edgeDy;
  23563. }
  23564. if ( ( inPt.y < edgeLowPt.y ) || ( inPt.y > edgeHighPt.y ) ) continue;
  23565. if ( inPt.y === edgeLowPt.y ) {
  23566. if ( inPt.x === edgeLowPt.x ) return true; // inPt is on contour ?
  23567. // continue; // no intersection or edgeLowPt => doesn't count !!!
  23568. } else {
  23569. var perpEdge = edgeDy * ( inPt.x - edgeLowPt.x ) - edgeDx * ( inPt.y - edgeLowPt.y );
  23570. if ( perpEdge === 0 ) return true; // inPt is on contour ?
  23571. if ( perpEdge < 0 ) continue;
  23572. inside = ! inside; // true intersection left of inPt
  23573. }
  23574. } else {
  23575. // parallel or collinear
  23576. if ( inPt.y !== edgeLowPt.y ) continue; // parallel
  23577. // edge lies on the same horizontal line as inPt
  23578. if ( ( ( edgeHighPt.x <= inPt.x ) && ( inPt.x <= edgeLowPt.x ) ) ||
  23579. ( ( edgeLowPt.x <= inPt.x ) && ( inPt.x <= edgeHighPt.x ) ) ) return true; // inPt: Point on contour !
  23580. // continue;
  23581. }
  23582. }
  23583. return inside;
  23584. }
  23585. var isClockWise = ShapeUtils.isClockWise;
  23586. var subPaths = this.subPaths;
  23587. if ( subPaths.length === 0 ) return [];
  23588. if ( noHoles === true ) return toShapesNoHoles( subPaths );
  23589. var solid, tmpPath, tmpShape, shapes = [];
  23590. if ( subPaths.length === 1 ) {
  23591. tmpPath = subPaths[ 0 ];
  23592. tmpShape = new Shape();
  23593. tmpShape.curves = tmpPath.curves;
  23594. shapes.push( tmpShape );
  23595. return shapes;
  23596. }
  23597. var holesFirst = ! isClockWise( subPaths[ 0 ].getPoints() );
  23598. holesFirst = isCCW ? ! holesFirst : holesFirst;
  23599. // console.log("Holes first", holesFirst);
  23600. var betterShapeHoles = [];
  23601. var newShapes = [];
  23602. var newShapeHoles = [];
  23603. var mainIdx = 0;
  23604. var tmpPoints;
  23605. newShapes[ mainIdx ] = undefined;
  23606. newShapeHoles[ mainIdx ] = [];
  23607. for ( var i = 0, l = subPaths.length; i < l; i ++ ) {
  23608. tmpPath = subPaths[ i ];
  23609. tmpPoints = tmpPath.getPoints();
  23610. solid = isClockWise( tmpPoints );
  23611. solid = isCCW ? ! solid : solid;
  23612. if ( solid ) {
  23613. if ( ( ! holesFirst ) && ( newShapes[ mainIdx ] ) ) mainIdx ++;
  23614. newShapes[ mainIdx ] = { s: new Shape(), p: tmpPoints };
  23615. newShapes[ mainIdx ].s.curves = tmpPath.curves;
  23616. if ( holesFirst ) mainIdx ++;
  23617. newShapeHoles[ mainIdx ] = [];
  23618. //console.log('cw', i);
  23619. } else {
  23620. newShapeHoles[ mainIdx ].push( { h: tmpPath, p: tmpPoints[ 0 ] } );
  23621. //console.log('ccw', i);
  23622. }
  23623. }
  23624. // only Holes? -> probably all Shapes with wrong orientation
  23625. if ( ! newShapes[ 0 ] ) return toShapesNoHoles( subPaths );
  23626. if ( newShapes.length > 1 ) {
  23627. var ambiguous = false;
  23628. var toChange = [];
  23629. for ( var sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx ++ ) {
  23630. betterShapeHoles[ sIdx ] = [];
  23631. }
  23632. for ( var sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx ++ ) {
  23633. var sho = newShapeHoles[ sIdx ];
  23634. for ( var hIdx = 0; hIdx < sho.length; hIdx ++ ) {
  23635. var ho = sho[ hIdx ];
  23636. var hole_unassigned = true;
  23637. for ( var s2Idx = 0; s2Idx < newShapes.length; s2Idx ++ ) {
  23638. if ( isPointInsidePolygon( ho.p, newShapes[ s2Idx ].p ) ) {
  23639. if ( sIdx !== s2Idx ) toChange.push( { froms: sIdx, tos: s2Idx, hole: hIdx } );
  23640. if ( hole_unassigned ) {
  23641. hole_unassigned = false;
  23642. betterShapeHoles[ s2Idx ].push( ho );
  23643. } else {
  23644. ambiguous = true;
  23645. }
  23646. }
  23647. }
  23648. if ( hole_unassigned ) {
  23649. betterShapeHoles[ sIdx ].push( ho );
  23650. }
  23651. }
  23652. }
  23653. // console.log("ambiguous: ", ambiguous);
  23654. if ( toChange.length > 0 ) {
  23655. // console.log("to change: ", toChange);
  23656. if ( ! ambiguous ) newShapeHoles = betterShapeHoles;
  23657. }
  23658. }
  23659. var tmpHoles;
  23660. for ( var i = 0, il = newShapes.length; i < il; i ++ ) {
  23661. tmpShape = newShapes[ i ].s;
  23662. shapes.push( tmpShape );
  23663. tmpHoles = newShapeHoles[ i ];
  23664. for ( var j = 0, jl = tmpHoles.length; j < jl; j ++ ) {
  23665. tmpShape.holes.push( tmpHoles[ j ].h );
  23666. }
  23667. }
  23668. //console.log("shape", shapes);
  23669. return shapes;
  23670. }
  23671. } );
  23672. /**
  23673. * @author zz85 / http://www.lab4games.net/zz85/blog
  23674. * @author mrdoob / http://mrdoob.com/
  23675. */
  23676. function Font( data ) {
  23677. this.type = 'Font';
  23678. this.data = data;
  23679. }
  23680. Object.assign( Font.prototype, {
  23681. isFont: true,
  23682. generateShapes: function ( text, size ) {
  23683. if ( size === undefined ) size = 100;
  23684. var shapes = [];
  23685. var paths = createPaths( text, size, this.data );
  23686. for ( var p = 0, pl = paths.length; p < pl; p ++ ) {
  23687. Array.prototype.push.apply( shapes, paths[ p ].toShapes() );
  23688. }
  23689. return shapes;
  23690. }
  23691. } );
  23692. function createPaths( text, size, data ) {
  23693. var chars = Array.from ? Array.from( text ) : String( text ).split( '' ); // see #13988
  23694. var scale = size / data.resolution;
  23695. var line_height = ( data.boundingBox.yMax - data.boundingBox.yMin + data.underlineThickness ) * scale;
  23696. var paths = [];
  23697. var offsetX = 0, offsetY = 0;
  23698. for ( var i = 0; i < chars.length; i ++ ) {
  23699. var char = chars[ i ];
  23700. if ( char === '\n' ) {
  23701. offsetX = 0;
  23702. offsetY -= line_height;
  23703. } else {
  23704. var ret = createPath( char, scale, offsetX, offsetY, data );
  23705. offsetX += ret.offsetX;
  23706. paths.push( ret.path );
  23707. }
  23708. }
  23709. return paths;
  23710. }
  23711. function createPath( char, scale, offsetX, offsetY, data ) {
  23712. var glyph = data.glyphs[ char ] || data.glyphs[ '?' ];
  23713. if ( ! glyph ) return;
  23714. var path = new ShapePath();
  23715. var x, y, cpx, cpy, cpx1, cpy1, cpx2, cpy2;
  23716. if ( glyph.o ) {
  23717. var outline = glyph._cachedOutline || ( glyph._cachedOutline = glyph.o.split( ' ' ) );
  23718. for ( var i = 0, l = outline.length; i < l; ) {
  23719. var action = outline[ i ++ ];
  23720. switch ( action ) {
  23721. case 'm': // moveTo
  23722. x = outline[ i ++ ] * scale + offsetX;
  23723. y = outline[ i ++ ] * scale + offsetY;
  23724. path.moveTo( x, y );
  23725. break;
  23726. case 'l': // lineTo
  23727. x = outline[ i ++ ] * scale + offsetX;
  23728. y = outline[ i ++ ] * scale + offsetY;
  23729. path.lineTo( x, y );
  23730. break;
  23731. case 'q': // quadraticCurveTo
  23732. cpx = outline[ i ++ ] * scale + offsetX;
  23733. cpy = outline[ i ++ ] * scale + offsetY;
  23734. cpx1 = outline[ i ++ ] * scale + offsetX;
  23735. cpy1 = outline[ i ++ ] * scale + offsetY;
  23736. path.quadraticCurveTo( cpx1, cpy1, cpx, cpy );
  23737. break;
  23738. case 'b': // bezierCurveTo
  23739. cpx = outline[ i ++ ] * scale + offsetX;
  23740. cpy = outline[ i ++ ] * scale + offsetY;
  23741. cpx1 = outline[ i ++ ] * scale + offsetX;
  23742. cpy1 = outline[ i ++ ] * scale + offsetY;
  23743. cpx2 = outline[ i ++ ] * scale + offsetX;
  23744. cpy2 = outline[ i ++ ] * scale + offsetY;
  23745. path.bezierCurveTo( cpx1, cpy1, cpx2, cpy2, cpx, cpy );
  23746. break;
  23747. }
  23748. }
  23749. }
  23750. return { offsetX: glyph.ha * scale, path: path };
  23751. }
  23752. /**
  23753. * @author mrdoob / http://mrdoob.com/
  23754. */
  23755. function FontLoader( manager ) {
  23756. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  23757. }
  23758. Object.assign( FontLoader.prototype, {
  23759. load: function ( url, onLoad, onProgress, onError ) {
  23760. var scope = this;
  23761. var loader = new FileLoader( this.manager );
  23762. loader.setPath( this.path );
  23763. loader.load( url, function ( text ) {
  23764. var json;
  23765. try {
  23766. json = JSON.parse( text );
  23767. } catch ( e ) {
  23768. console.warn( 'THREE.FontLoader: typeface.js support is being deprecated. Use typeface.json instead.' );
  23769. json = JSON.parse( text.substring( 65, text.length - 2 ) );
  23770. }
  23771. var font = scope.parse( json );
  23772. if ( onLoad ) onLoad( font );
  23773. }, onProgress, onError );
  23774. },
  23775. parse: function ( json ) {
  23776. return new Font( json );
  23777. },
  23778. setPath: function ( value ) {
  23779. this.path = value;
  23780. return this;
  23781. }
  23782. } );
  23783. /**
  23784. * @author alteredq / http://alteredqualia.com/
  23785. */
  23786. function Loader() {}
  23787. Loader.Handlers = {
  23788. handlers: [],
  23789. add: function ( regex, loader ) {
  23790. this.handlers.push( regex, loader );
  23791. },
  23792. get: function ( file ) {
  23793. var handlers = this.handlers;
  23794. for ( var i = 0, l = handlers.length; i < l; i += 2 ) {
  23795. var regex = handlers[ i ];
  23796. var loader = handlers[ i + 1 ];
  23797. if ( regex.test( file ) ) {
  23798. return loader;
  23799. }
  23800. }
  23801. return null;
  23802. }
  23803. };
  23804. Object.assign( Loader.prototype, {
  23805. crossOrigin: 'anonymous',
  23806. onLoadStart: function () {},
  23807. onLoadProgress: function () {},
  23808. onLoadComplete: function () {},
  23809. initMaterials: function ( materials, texturePath, crossOrigin ) {
  23810. var array = [];
  23811. for ( var i = 0; i < materials.length; ++ i ) {
  23812. array[ i ] = this.createMaterial( materials[ i ], texturePath, crossOrigin );
  23813. }
  23814. return array;
  23815. },
  23816. createMaterial: ( function () {
  23817. var BlendingMode = {
  23818. NoBlending: NoBlending,
  23819. NormalBlending: NormalBlending,
  23820. AdditiveBlending: AdditiveBlending,
  23821. SubtractiveBlending: SubtractiveBlending,
  23822. MultiplyBlending: MultiplyBlending,
  23823. CustomBlending: CustomBlending
  23824. };
  23825. var color = new Color();
  23826. var textureLoader = new TextureLoader();
  23827. var materialLoader = new MaterialLoader();
  23828. return function createMaterial( m, texturePath, crossOrigin ) {
  23829. // convert from old material format
  23830. var textures = {};
  23831. function loadTexture( path, repeat, offset, wrap, anisotropy ) {
  23832. var fullPath = texturePath + path;
  23833. var loader = Loader.Handlers.get( fullPath );
  23834. var texture;
  23835. if ( loader !== null ) {
  23836. texture = loader.load( fullPath );
  23837. } else {
  23838. textureLoader.setCrossOrigin( crossOrigin );
  23839. texture = textureLoader.load( fullPath );
  23840. }
  23841. if ( repeat !== undefined ) {
  23842. texture.repeat.fromArray( repeat );
  23843. if ( repeat[ 0 ] !== 1 ) texture.wrapS = RepeatWrapping;
  23844. if ( repeat[ 1 ] !== 1 ) texture.wrapT = RepeatWrapping;
  23845. }
  23846. if ( offset !== undefined ) {
  23847. texture.offset.fromArray( offset );
  23848. }
  23849. if ( wrap !== undefined ) {
  23850. if ( wrap[ 0 ] === 'repeat' ) texture.wrapS = RepeatWrapping;
  23851. if ( wrap[ 0 ] === 'mirror' ) texture.wrapS = MirroredRepeatWrapping;
  23852. if ( wrap[ 1 ] === 'repeat' ) texture.wrapT = RepeatWrapping;
  23853. if ( wrap[ 1 ] === 'mirror' ) texture.wrapT = MirroredRepeatWrapping;
  23854. }
  23855. if ( anisotropy !== undefined ) {
  23856. texture.anisotropy = anisotropy;
  23857. }
  23858. var uuid = _Math.generateUUID();
  23859. textures[ uuid ] = texture;
  23860. return uuid;
  23861. }
  23862. //
  23863. var json = {
  23864. uuid: _Math.generateUUID(),
  23865. type: 'MeshLambertMaterial'
  23866. };
  23867. for ( var name in m ) {
  23868. var value = m[ name ];
  23869. switch ( name ) {
  23870. case 'DbgColor':
  23871. case 'DbgIndex':
  23872. case 'opticalDensity':
  23873. case 'illumination':
  23874. break;
  23875. case 'DbgName':
  23876. json.name = value;
  23877. break;
  23878. case 'blending':
  23879. json.blending = BlendingMode[ value ];
  23880. break;
  23881. case 'colorAmbient':
  23882. case 'mapAmbient':
  23883. console.warn( 'THREE.Loader.createMaterial:', name, 'is no longer supported.' );
  23884. break;
  23885. case 'colorDiffuse':
  23886. json.color = color.fromArray( value ).getHex();
  23887. break;
  23888. case 'colorSpecular':
  23889. json.specular = color.fromArray( value ).getHex();
  23890. break;
  23891. case 'colorEmissive':
  23892. json.emissive = color.fromArray( value ).getHex();
  23893. break;
  23894. case 'specularCoef':
  23895. json.shininess = value;
  23896. break;
  23897. case 'shading':
  23898. if ( value.toLowerCase() === 'basic' ) json.type = 'MeshBasicMaterial';
  23899. if ( value.toLowerCase() === 'phong' ) json.type = 'MeshPhongMaterial';
  23900. if ( value.toLowerCase() === 'standard' ) json.type = 'MeshStandardMaterial';
  23901. break;
  23902. case 'mapDiffuse':
  23903. json.map = loadTexture( value, m.mapDiffuseRepeat, m.mapDiffuseOffset, m.mapDiffuseWrap, m.mapDiffuseAnisotropy );
  23904. break;
  23905. case 'mapDiffuseRepeat':
  23906. case 'mapDiffuseOffset':
  23907. case 'mapDiffuseWrap':
  23908. case 'mapDiffuseAnisotropy':
  23909. break;
  23910. case 'mapEmissive':
  23911. json.emissiveMap = loadTexture( value, m.mapEmissiveRepeat, m.mapEmissiveOffset, m.mapEmissiveWrap, m.mapEmissiveAnisotropy );
  23912. break;
  23913. case 'mapEmissiveRepeat':
  23914. case 'mapEmissiveOffset':
  23915. case 'mapEmissiveWrap':
  23916. case 'mapEmissiveAnisotropy':
  23917. break;
  23918. case 'mapLight':
  23919. json.lightMap = loadTexture( value, m.mapLightRepeat, m.mapLightOffset, m.mapLightWrap, m.mapLightAnisotropy );
  23920. break;
  23921. case 'mapLightRepeat':
  23922. case 'mapLightOffset':
  23923. case 'mapLightWrap':
  23924. case 'mapLightAnisotropy':
  23925. break;
  23926. case 'mapAO':
  23927. json.aoMap = loadTexture( value, m.mapAORepeat, m.mapAOOffset, m.mapAOWrap, m.mapAOAnisotropy );
  23928. break;
  23929. case 'mapAORepeat':
  23930. case 'mapAOOffset':
  23931. case 'mapAOWrap':
  23932. case 'mapAOAnisotropy':
  23933. break;
  23934. case 'mapBump':
  23935. json.bumpMap = loadTexture( value, m.mapBumpRepeat, m.mapBumpOffset, m.mapBumpWrap, m.mapBumpAnisotropy );
  23936. break;
  23937. case 'mapBumpScale':
  23938. json.bumpScale = value;
  23939. break;
  23940. case 'mapBumpRepeat':
  23941. case 'mapBumpOffset':
  23942. case 'mapBumpWrap':
  23943. case 'mapBumpAnisotropy':
  23944. break;
  23945. case 'mapNormal':
  23946. json.normalMap = loadTexture( value, m.mapNormalRepeat, m.mapNormalOffset, m.mapNormalWrap, m.mapNormalAnisotropy );
  23947. break;
  23948. case 'mapNormalFactor':
  23949. json.normalScale = value;
  23950. break;
  23951. case 'mapNormalRepeat':
  23952. case 'mapNormalOffset':
  23953. case 'mapNormalWrap':
  23954. case 'mapNormalAnisotropy':
  23955. break;
  23956. case 'mapSpecular':
  23957. json.specularMap = loadTexture( value, m.mapSpecularRepeat, m.mapSpecularOffset, m.mapSpecularWrap, m.mapSpecularAnisotropy );
  23958. break;
  23959. case 'mapSpecularRepeat':
  23960. case 'mapSpecularOffset':
  23961. case 'mapSpecularWrap':
  23962. case 'mapSpecularAnisotropy':
  23963. break;
  23964. case 'mapMetalness':
  23965. json.metalnessMap = loadTexture( value, m.mapMetalnessRepeat, m.mapMetalnessOffset, m.mapMetalnessWrap, m.mapMetalnessAnisotropy );
  23966. break;
  23967. case 'mapMetalnessRepeat':
  23968. case 'mapMetalnessOffset':
  23969. case 'mapMetalnessWrap':
  23970. case 'mapMetalnessAnisotropy':
  23971. break;
  23972. case 'mapRoughness':
  23973. json.roughnessMap = loadTexture( value, m.mapRoughnessRepeat, m.mapRoughnessOffset, m.mapRoughnessWrap, m.mapRoughnessAnisotropy );
  23974. break;
  23975. case 'mapRoughnessRepeat':
  23976. case 'mapRoughnessOffset':
  23977. case 'mapRoughnessWrap':
  23978. case 'mapRoughnessAnisotropy':
  23979. break;
  23980. case 'mapAlpha':
  23981. json.alphaMap = loadTexture( value, m.mapAlphaRepeat, m.mapAlphaOffset, m.mapAlphaWrap, m.mapAlphaAnisotropy );
  23982. break;
  23983. case 'mapAlphaRepeat':
  23984. case 'mapAlphaOffset':
  23985. case 'mapAlphaWrap':
  23986. case 'mapAlphaAnisotropy':
  23987. break;
  23988. case 'flipSided':
  23989. json.side = BackSide;
  23990. break;
  23991. case 'doubleSided':
  23992. json.side = DoubleSide;
  23993. break;
  23994. case 'transparency':
  23995. console.warn( 'THREE.Loader.createMaterial: transparency has been renamed to opacity' );
  23996. json.opacity = value;
  23997. break;
  23998. case 'depthTest':
  23999. case 'depthWrite':
  24000. case 'colorWrite':
  24001. case 'opacity':
  24002. case 'reflectivity':
  24003. case 'transparent':
  24004. case 'visible':
  24005. case 'wireframe':
  24006. json[ name ] = value;
  24007. break;
  24008. case 'vertexColors':
  24009. if ( value === true ) json.vertexColors = VertexColors;
  24010. if ( value === 'face' ) json.vertexColors = FaceColors;
  24011. break;
  24012. default:
  24013. console.error( 'THREE.Loader.createMaterial: Unsupported', name, value );
  24014. break;
  24015. }
  24016. }
  24017. if ( json.type === 'MeshBasicMaterial' ) delete json.emissive;
  24018. if ( json.type !== 'MeshPhongMaterial' ) delete json.specular;
  24019. if ( json.opacity < 1 ) json.transparent = true;
  24020. materialLoader.setTextures( textures );
  24021. return materialLoader.parse( json );
  24022. };
  24023. } )()
  24024. } );
  24025. /**
  24026. * @author mrdoob / http://mrdoob.com/
  24027. */
  24028. var context;
  24029. var AudioContext = {
  24030. getContext: function () {
  24031. if ( context === undefined ) {
  24032. context = new ( window.AudioContext || window.webkitAudioContext )();
  24033. }
  24034. return context;
  24035. },
  24036. setContext: function ( value ) {
  24037. context = value;
  24038. }
  24039. };
  24040. /**
  24041. * @author Reece Aaron Lecrivain / http://reecenotes.com/
  24042. */
  24043. function AudioLoader( manager ) {
  24044. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  24045. }
  24046. Object.assign( AudioLoader.prototype, {
  24047. load: function ( url, onLoad, onProgress, onError ) {
  24048. var loader = new FileLoader( this.manager );
  24049. loader.setResponseType( 'arraybuffer' );
  24050. loader.setPath( this.path );
  24051. loader.load( url, function ( buffer ) {
  24052. // Create a copy of the buffer. The `decodeAudioData` method
  24053. // detaches the buffer when complete, preventing reuse.
  24054. var bufferCopy = buffer.slice( 0 );
  24055. var context = AudioContext.getContext();
  24056. context.decodeAudioData( bufferCopy, function ( audioBuffer ) {
  24057. onLoad( audioBuffer );
  24058. } );
  24059. }, onProgress, onError );
  24060. },
  24061. setPath: function ( value ) {
  24062. this.path = value;
  24063. return this;
  24064. }
  24065. } );
  24066. /**
  24067. * @author bhouston / http://clara.io
  24068. * @author WestLangley / http://github.com/WestLangley
  24069. *
  24070. * Primary reference:
  24071. * https://graphics.stanford.edu/papers/envmap/envmap.pdf
  24072. *
  24073. * Secondary reference:
  24074. * https://www.ppsloan.org/publications/StupidSH36.pdf
  24075. */
  24076. // 3-band SH defined by 9 coefficients
  24077. function SphericalHarmonics3() {
  24078. this.coefficients = [];
  24079. for ( var i = 0; i < 9; i ++ ) {
  24080. this.coefficients.push( new Vector3() );
  24081. }
  24082. }
  24083. Object.assign( SphericalHarmonics3.prototype, {
  24084. isSphericalHarmonics3: true,
  24085. set: function ( coefficients ) {
  24086. for ( var i = 0; i < 9; i ++ ) {
  24087. this.coefficients[ i ].copy( coefficients[ i ] );
  24088. }
  24089. return this;
  24090. },
  24091. zero: function () {
  24092. for ( var i = 0; i < 9; i ++ ) {
  24093. this.coefficients[ i ].set( 0, 0, 0 );
  24094. }
  24095. return this;
  24096. },
  24097. // get the radiance in the direction of the normal
  24098. // target is a Vector3
  24099. getAt: function ( normal, target ) {
  24100. // normal is assumed to be unit length
  24101. var x = normal.x, y = normal.y, z = normal.z;
  24102. var coeff = this.coefficients;
  24103. // band 0
  24104. target = coeff[ 0 ] * 0.282095;
  24105. // band 1
  24106. target += coeff[ 1 ] * 0.488603 * y;
  24107. target += coeff[ 2 ] * 0.488603 * z;
  24108. target += coeff[ 3 ] * 0.488603 * x;
  24109. // band 2
  24110. target += coeff[ 4 ] * 1.092548 * ( x * y );
  24111. target += coeff[ 5 ] * 1.092548 * ( y * z );
  24112. target += coeff[ 6 ] * 0.315392 * ( 3.0 * z * z - 1.0 );
  24113. target += coeff[ 7 ] * 1.092548 * ( x * z );
  24114. target += coeff[ 8 ] * 0.546274 * ( x * x - y * y );
  24115. return target;
  24116. },
  24117. // get the irradiance (radiance convolved with cosine lobe) in the direction of the normal
  24118. // target is a Vector3
  24119. // https://graphics.stanford.edu/papers/envmap/envmap.pdf
  24120. getIrradianceAt: function ( normal, target ) {
  24121. // normal is assumed to be unit length
  24122. var x = normal.x, y = normal.y, z = normal.z;
  24123. var coeff = this.coefficients;
  24124. // band 0
  24125. target = coeff[ 0 ] * 0.886227; // π * 0.282095
  24126. // band 1
  24127. target += coeff[ 1 ] * 2.0 * 0.511664 * y; // ( 2 * π / 3 ) * 0.488603
  24128. target += coeff[ 2 ] * 2.0 * 0.511664 * z;
  24129. target += coeff[ 3 ] * 2.0 * 0.511664 * x;
  24130. // band 2
  24131. target += coeff[ 4 ] * 2.0 * 0.429043 * x * y; // ( π / 4 ) * 1.092548
  24132. target += coeff[ 5 ] * 2.0 * 0.429043 * y * z;
  24133. target += coeff[ 6 ] * ( 0.743125 * z * z - 0.247708 ); // ( π / 4 ) * 0.315392 * 3
  24134. target += coeff[ 7 ] * 2.0 * 0.429043 * x * z;
  24135. target += coeff[ 8 ] * 0.429043 * ( x * x - y * y ); // ( π / 4 ) * 0.546274
  24136. return target;
  24137. },
  24138. add: function ( sh ) {
  24139. for ( var i = 0; i < 9; i ++ ) {
  24140. this.coefficients[ i ].add( sh.coefficients[ i ] );
  24141. }
  24142. return this;
  24143. },
  24144. scale: function ( s ) {
  24145. for ( var i = 0; i < 9; i ++ ) {
  24146. this.coefficients[ i ].multiplyScalar( s );
  24147. }
  24148. return this;
  24149. },
  24150. lerp: function ( sh, alpha ) {
  24151. for ( var i = 0; i < 9; i ++ ) {
  24152. this.coefficients[ i ].lerp( sh.coefficients[ i ], alpha );
  24153. }
  24154. return this;
  24155. },
  24156. equals: function ( sh ) {
  24157. for ( var i = 0; i < 9; i ++ ) {
  24158. if ( ! this.coefficients[ i ].equals( sh.coefficients[ i ] ) ) {
  24159. return false;
  24160. }
  24161. }
  24162. return true;
  24163. },
  24164. copy: function ( sh ) {
  24165. return this.set( sh.coefficients );
  24166. },
  24167. clone: function () {
  24168. return new this.constructor().copy( this );
  24169. },
  24170. fromArray: function ( array ) {
  24171. var coefficients = this.coefficients;
  24172. for ( var i = 0; i < 9; i ++ ) {
  24173. coefficients[ i ].fromArray( array, i * 3 );
  24174. }
  24175. return this;
  24176. },
  24177. toArray: function () {
  24178. var array = [];
  24179. var coefficients = this.coefficients;
  24180. for ( var i = 0; i < 9; i ++ ) {
  24181. coefficients[ i ].toArray( array, i * 3 );
  24182. }
  24183. return array;
  24184. }
  24185. } );
  24186. Object.assign( SphericalHarmonics3, {
  24187. // evaluate the basis functions
  24188. // shBasis is an Array[ 9 ]
  24189. getBasisAt: function ( normal, shBasis ) {
  24190. // normal is assumed to be unit length
  24191. var x = normal.x, y = normal.y, z = normal.z;
  24192. // band 0
  24193. shBasis[ 0 ] = 0.282095;
  24194. // band 1
  24195. shBasis[ 1 ] = 0.488603 * y;
  24196. shBasis[ 2 ] = 0.488603 * z;
  24197. shBasis[ 3 ] = 0.488603 * x;
  24198. // band 2
  24199. shBasis[ 4 ] = 1.092548 * x * y;
  24200. shBasis[ 5 ] = 1.092548 * y * z;
  24201. shBasis[ 6 ] = 0.315392 * ( 3 * z * z - 1 );
  24202. shBasis[ 7 ] = 1.092548 * x * z;
  24203. shBasis[ 8 ] = 0.546274 * ( x * x - y * y );
  24204. }
  24205. } );
  24206. /**
  24207. * @author WestLangley / http://github.com/WestLangley
  24208. *
  24209. * A LightProbe is a source of indirect-diffuse light
  24210. */
  24211. function LightProbe( sh, intensity ) {
  24212. Light.call( this, undefined, intensity );
  24213. this.sh = ( sh !== undefined ) ? sh : new SphericalHarmonics3();
  24214. }
  24215. LightProbe.prototype = Object.assign( Object.create( Light.prototype ), {
  24216. constructor: LightProbe,
  24217. isLightProbe: true,
  24218. copy: function ( source ) {
  24219. Light.prototype.copy.call( this, source );
  24220. this.sh.copy( source.sh );
  24221. this.intensity = source.intensity;
  24222. return this;
  24223. },
  24224. toJSON: function ( meta ) {
  24225. var data = Light.prototype.toJSON.call( this, meta );
  24226. // data.sh = this.sh.toArray(); // todo
  24227. return data;
  24228. }
  24229. } );
  24230. /**
  24231. * @author WestLangley / http://github.com/WestLangley
  24232. */
  24233. function HemisphereLightProbe( skyColor, groundColor, intensity ) {
  24234. LightProbe.call( this, undefined, intensity );
  24235. var color1 = new Color().set( skyColor );
  24236. var color2 = new Color().set( groundColor );
  24237. var sky = new Vector3( color1.r, color1.g, color1.b );
  24238. var ground = new Vector3( color2.r, color2.g, color2.b );
  24239. // without extra factor of PI in the shader, should = 1 / Math.sqrt( Math.PI );
  24240. var c0 = Math.sqrt( Math.PI );
  24241. var c1 = c0 * Math.sqrt( 0.75 );
  24242. this.sh.coefficients[ 0 ].copy( sky ).add( ground ).multiplyScalar( c0 );
  24243. this.sh.coefficients[ 1 ].copy( sky ).sub( ground ).multiplyScalar( c1 );
  24244. }
  24245. HemisphereLightProbe.prototype = Object.assign( Object.create( LightProbe.prototype ), {
  24246. constructor: HemisphereLightProbe,
  24247. isHemisphereLightProbe: true,
  24248. copy: function ( source ) { // modifying colors not currently supported
  24249. LightProbe.prototype.copy.call( this, source );
  24250. return this;
  24251. },
  24252. toJSON: function ( meta ) {
  24253. var data = LightProbe.prototype.toJSON.call( this, meta );
  24254. // data.sh = this.sh.toArray(); // todo
  24255. return data;
  24256. }
  24257. } );
  24258. /**
  24259. * @author WestLangley / http://github.com/WestLangley
  24260. */
  24261. function AmbientLightProbe( color, intensity ) {
  24262. LightProbe.call( this, undefined, intensity );
  24263. var color1 = new Color().set( color );
  24264. // without extra factor of PI in the shader, would be 2 / Math.sqrt( Math.PI );
  24265. this.sh.coefficients[ 0 ].set( color1.r, color1.g, color1.b ).multiplyScalar( 2 * Math.sqrt( Math.PI ) );
  24266. }
  24267. AmbientLightProbe.prototype = Object.assign( Object.create( LightProbe.prototype ), {
  24268. constructor: AmbientLightProbe,
  24269. isAmbientLightProbe: true,
  24270. copy: function ( source ) { // modifying color not currently supported
  24271. LightProbe.prototype.copy.call( this, source );
  24272. return this;
  24273. },
  24274. toJSON: function ( meta ) {
  24275. var data = LightProbe.prototype.toJSON.call( this, meta );
  24276. // data.sh = this.sh.toArray(); // todo
  24277. return data;
  24278. }
  24279. } );
  24280. /**
  24281. * @author mrdoob / http://mrdoob.com/
  24282. */
  24283. function StereoCamera() {
  24284. this.type = 'StereoCamera';
  24285. this.aspect = 1;
  24286. this.eyeSep = 0.064;
  24287. this.cameraL = new PerspectiveCamera();
  24288. this.cameraL.layers.enable( 1 );
  24289. this.cameraL.matrixAutoUpdate = false;
  24290. this.cameraR = new PerspectiveCamera();
  24291. this.cameraR.layers.enable( 2 );
  24292. this.cameraR.matrixAutoUpdate = false;
  24293. }
  24294. Object.assign( StereoCamera.prototype, {
  24295. update: ( function () {
  24296. var instance, focus, fov, aspect, near, far, zoom, eyeSep;
  24297. var eyeRight = new Matrix4();
  24298. var eyeLeft = new Matrix4();
  24299. return function update( camera ) {
  24300. var needsUpdate = instance !== this || focus !== camera.focus || fov !== camera.fov ||
  24301. aspect !== camera.aspect * this.aspect || near !== camera.near ||
  24302. far !== camera.far || zoom !== camera.zoom || eyeSep !== this.eyeSep;
  24303. if ( needsUpdate ) {
  24304. instance = this;
  24305. focus = camera.focus;
  24306. fov = camera.fov;
  24307. aspect = camera.aspect * this.aspect;
  24308. near = camera.near;
  24309. far = camera.far;
  24310. zoom = camera.zoom;
  24311. // Off-axis stereoscopic effect based on
  24312. // http://paulbourke.net/stereographics/stereorender/
  24313. var projectionMatrix = camera.projectionMatrix.clone();
  24314. eyeSep = this.eyeSep / 2;
  24315. var eyeSepOnProjection = eyeSep * near / focus;
  24316. var ymax = ( near * Math.tan( _Math.DEG2RAD * fov * 0.5 ) ) / zoom;
  24317. var xmin, xmax;
  24318. // translate xOffset
  24319. eyeLeft.elements[ 12 ] = - eyeSep;
  24320. eyeRight.elements[ 12 ] = eyeSep;
  24321. // for left eye
  24322. xmin = - ymax * aspect + eyeSepOnProjection;
  24323. xmax = ymax * aspect + eyeSepOnProjection;
  24324. projectionMatrix.elements[ 0 ] = 2 * near / ( xmax - xmin );
  24325. projectionMatrix.elements[ 8 ] = ( xmax + xmin ) / ( xmax - xmin );
  24326. this.cameraL.projectionMatrix.copy( projectionMatrix );
  24327. // for right eye
  24328. xmin = - ymax * aspect - eyeSepOnProjection;
  24329. xmax = ymax * aspect - eyeSepOnProjection;
  24330. projectionMatrix.elements[ 0 ] = 2 * near / ( xmax - xmin );
  24331. projectionMatrix.elements[ 8 ] = ( xmax + xmin ) / ( xmax - xmin );
  24332. this.cameraR.projectionMatrix.copy( projectionMatrix );
  24333. }
  24334. this.cameraL.matrixWorld.copy( camera.matrixWorld ).multiply( eyeLeft );
  24335. this.cameraR.matrixWorld.copy( camera.matrixWorld ).multiply( eyeRight );
  24336. };
  24337. } )()
  24338. } );
  24339. /**
  24340. * Camera for rendering cube maps
  24341. * - renders scene into axis-aligned cube
  24342. *
  24343. * @author alteredq / http://alteredqualia.com/
  24344. */
  24345. var fov = 90, aspect = 1;
  24346. function CubeCamera( near, far, cubeResolution, options ) {
  24347. Object3D.call( this );
  24348. this.type = 'CubeCamera';
  24349. var cameraPX = new PerspectiveCamera( fov, aspect, near, far );
  24350. cameraPX.up.set( 0, - 1, 0 );
  24351. cameraPX.lookAt( new Vector3( 1, 0, 0 ) );
  24352. this.add( cameraPX );
  24353. var cameraNX = new PerspectiveCamera( fov, aspect, near, far );
  24354. cameraNX.up.set( 0, - 1, 0 );
  24355. cameraNX.lookAt( new Vector3( - 1, 0, 0 ) );
  24356. this.add( cameraNX );
  24357. var cameraPY = new PerspectiveCamera( fov, aspect, near, far );
  24358. cameraPY.up.set( 0, 0, 1 );
  24359. cameraPY.lookAt( new Vector3( 0, 1, 0 ) );
  24360. this.add( cameraPY );
  24361. var cameraNY = new PerspectiveCamera( fov, aspect, near, far );
  24362. cameraNY.up.set( 0, 0, - 1 );
  24363. cameraNY.lookAt( new Vector3( 0, - 1, 0 ) );
  24364. this.add( cameraNY );
  24365. var cameraPZ = new PerspectiveCamera( fov, aspect, near, far );
  24366. cameraPZ.up.set( 0, - 1, 0 );
  24367. cameraPZ.lookAt( new Vector3( 0, 0, 1 ) );
  24368. this.add( cameraPZ );
  24369. var cameraNZ = new PerspectiveCamera( fov, aspect, near, far );
  24370. cameraNZ.up.set( 0, - 1, 0 );
  24371. cameraNZ.lookAt( new Vector3( 0, 0, - 1 ) );
  24372. this.add( cameraNZ );
  24373. options = options || { format: RGBFormat, magFilter: LinearFilter, minFilter: LinearFilter };
  24374. this.renderTarget = new WebGLRenderTargetCube( cubeResolution, cubeResolution, options );
  24375. this.renderTarget.texture.name = "CubeCamera";
  24376. this.update = function ( renderer, scene ) {
  24377. if ( this.parent === null ) this.updateMatrixWorld();
  24378. var currentRenderTarget = renderer.getRenderTarget();
  24379. var renderTarget = this.renderTarget;
  24380. var generateMipmaps = renderTarget.texture.generateMipmaps;
  24381. renderTarget.texture.generateMipmaps = false;
  24382. renderer.setRenderTarget( renderTarget, 0 );
  24383. renderer.render( scene, cameraPX );
  24384. renderer.setRenderTarget( renderTarget, 1 );
  24385. renderer.render( scene, cameraNX );
  24386. renderer.setRenderTarget( renderTarget, 2 );
  24387. renderer.render( scene, cameraPY );
  24388. renderer.setRenderTarget( renderTarget, 3 );
  24389. renderer.render( scene, cameraNY );
  24390. renderer.setRenderTarget( renderTarget, 4 );
  24391. renderer.render( scene, cameraPZ );
  24392. renderTarget.texture.generateMipmaps = generateMipmaps;
  24393. renderer.setRenderTarget( renderTarget, 5 );
  24394. renderer.render( scene, cameraNZ );
  24395. renderer.setRenderTarget( currentRenderTarget );
  24396. };
  24397. this.clear = function ( renderer, color, depth, stencil ) {
  24398. var currentRenderTarget = renderer.getRenderTarget();
  24399. var renderTarget = this.renderTarget;
  24400. for ( var i = 0; i < 6; i ++ ) {
  24401. renderer.setRenderTarget( renderTarget, i );
  24402. renderer.clear( color, depth, stencil );
  24403. }
  24404. renderer.setRenderTarget( currentRenderTarget );
  24405. };
  24406. }
  24407. CubeCamera.prototype = Object.create( Object3D.prototype );
  24408. CubeCamera.prototype.constructor = CubeCamera;
  24409. /**
  24410. * @author alteredq / http://alteredqualia.com/
  24411. */
  24412. function Clock( autoStart ) {
  24413. this.autoStart = ( autoStart !== undefined ) ? autoStart : true;
  24414. this.startTime = 0;
  24415. this.oldTime = 0;
  24416. this.elapsedTime = 0;
  24417. this.running = false;
  24418. }
  24419. Object.assign( Clock.prototype, {
  24420. start: function () {
  24421. this.startTime = ( typeof performance === 'undefined' ? Date : performance ).now(); // see #10732
  24422. this.oldTime = this.startTime;
  24423. this.elapsedTime = 0;
  24424. this.running = true;
  24425. },
  24426. stop: function () {
  24427. this.getElapsedTime();
  24428. this.running = false;
  24429. this.autoStart = false;
  24430. },
  24431. getElapsedTime: function () {
  24432. this.getDelta();
  24433. return this.elapsedTime;
  24434. },
  24435. getDelta: function () {
  24436. var diff = 0;
  24437. if ( this.autoStart && ! this.running ) {
  24438. this.start();
  24439. return 0;
  24440. }
  24441. if ( this.running ) {
  24442. var newTime = ( typeof performance === 'undefined' ? Date : performance ).now();
  24443. diff = ( newTime - this.oldTime ) / 1000;
  24444. this.oldTime = newTime;
  24445. this.elapsedTime += diff;
  24446. }
  24447. return diff;
  24448. }
  24449. } );
  24450. /**
  24451. * @author mrdoob / http://mrdoob.com/
  24452. */
  24453. function AudioListener() {
  24454. Object3D.call( this );
  24455. this.type = 'AudioListener';
  24456. this.context = AudioContext.getContext();
  24457. this.gain = this.context.createGain();
  24458. this.gain.connect( this.context.destination );
  24459. this.filter = null;
  24460. this.timeDelta = 0;
  24461. }
  24462. AudioListener.prototype = Object.assign( Object.create( Object3D.prototype ), {
  24463. constructor: AudioListener,
  24464. getInput: function () {
  24465. return this.gain;
  24466. },
  24467. removeFilter: function ( ) {
  24468. if ( this.filter !== null ) {
  24469. this.gain.disconnect( this.filter );
  24470. this.filter.disconnect( this.context.destination );
  24471. this.gain.connect( this.context.destination );
  24472. this.filter = null;
  24473. }
  24474. return this;
  24475. },
  24476. getFilter: function () {
  24477. return this.filter;
  24478. },
  24479. setFilter: function ( value ) {
  24480. if ( this.filter !== null ) {
  24481. this.gain.disconnect( this.filter );
  24482. this.filter.disconnect( this.context.destination );
  24483. } else {
  24484. this.gain.disconnect( this.context.destination );
  24485. }
  24486. this.filter = value;
  24487. this.gain.connect( this.filter );
  24488. this.filter.connect( this.context.destination );
  24489. return this;
  24490. },
  24491. getMasterVolume: function () {
  24492. return this.gain.gain.value;
  24493. },
  24494. setMasterVolume: function ( value ) {
  24495. this.gain.gain.setTargetAtTime( value, this.context.currentTime, 0.01 );
  24496. return this;
  24497. },
  24498. updateMatrixWorld: ( function () {
  24499. var position = new Vector3();
  24500. var quaternion = new Quaternion();
  24501. var scale = new Vector3();
  24502. var orientation = new Vector3();
  24503. var clock = new Clock();
  24504. return function updateMatrixWorld( force ) {
  24505. Object3D.prototype.updateMatrixWorld.call( this, force );
  24506. var listener = this.context.listener;
  24507. var up = this.up;
  24508. this.timeDelta = clock.getDelta();
  24509. this.matrixWorld.decompose( position, quaternion, scale );
  24510. orientation.set( 0, 0, - 1 ).applyQuaternion( quaternion );
  24511. if ( listener.positionX ) {
  24512. // code path for Chrome (see #14393)
  24513. var endTime = this.context.currentTime + this.timeDelta;
  24514. listener.positionX.linearRampToValueAtTime( position.x, endTime );
  24515. listener.positionY.linearRampToValueAtTime( position.y, endTime );
  24516. listener.positionZ.linearRampToValueAtTime( position.z, endTime );
  24517. listener.forwardX.linearRampToValueAtTime( orientation.x, endTime );
  24518. listener.forwardY.linearRampToValueAtTime( orientation.y, endTime );
  24519. listener.forwardZ.linearRampToValueAtTime( orientation.z, endTime );
  24520. listener.upX.linearRampToValueAtTime( up.x, endTime );
  24521. listener.upY.linearRampToValueAtTime( up.y, endTime );
  24522. listener.upZ.linearRampToValueAtTime( up.z, endTime );
  24523. } else {
  24524. listener.setPosition( position.x, position.y, position.z );
  24525. listener.setOrientation( orientation.x, orientation.y, orientation.z, up.x, up.y, up.z );
  24526. }
  24527. };
  24528. } )()
  24529. } );
  24530. /**
  24531. * @author mrdoob / http://mrdoob.com/
  24532. * @author Reece Aaron Lecrivain / http://reecenotes.com/
  24533. */
  24534. function Audio( listener ) {
  24535. Object3D.call( this );
  24536. this.type = 'Audio';
  24537. this.listener = listener;
  24538. this.context = listener.context;
  24539. this.gain = this.context.createGain();
  24540. this.gain.connect( listener.getInput() );
  24541. this.autoplay = false;
  24542. this.buffer = null;
  24543. this.detune = 0;
  24544. this.loop = false;
  24545. this.startTime = 0;
  24546. this.offset = 0;
  24547. this.playbackRate = 1;
  24548. this.isPlaying = false;
  24549. this.hasPlaybackControl = true;
  24550. this.sourceType = 'empty';
  24551. this.filters = [];
  24552. }
  24553. Audio.prototype = Object.assign( Object.create( Object3D.prototype ), {
  24554. constructor: Audio,
  24555. getOutput: function () {
  24556. return this.gain;
  24557. },
  24558. setNodeSource: function ( audioNode ) {
  24559. this.hasPlaybackControl = false;
  24560. this.sourceType = 'audioNode';
  24561. this.source = audioNode;
  24562. this.connect();
  24563. return this;
  24564. },
  24565. setMediaElementSource: function ( mediaElement ) {
  24566. this.hasPlaybackControl = false;
  24567. this.sourceType = 'mediaNode';
  24568. this.source = this.context.createMediaElementSource( mediaElement );
  24569. this.connect();
  24570. return this;
  24571. },
  24572. setBuffer: function ( audioBuffer ) {
  24573. this.buffer = audioBuffer;
  24574. this.sourceType = 'buffer';
  24575. if ( this.autoplay ) this.play();
  24576. return this;
  24577. },
  24578. play: function () {
  24579. if ( this.isPlaying === true ) {
  24580. console.warn( 'THREE.Audio: Audio is already playing.' );
  24581. return;
  24582. }
  24583. if ( this.hasPlaybackControl === false ) {
  24584. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  24585. return;
  24586. }
  24587. var source = this.context.createBufferSource();
  24588. source.buffer = this.buffer;
  24589. source.loop = this.loop;
  24590. source.onended = this.onEnded.bind( this );
  24591. this.startTime = this.context.currentTime;
  24592. source.start( this.startTime, this.offset );
  24593. this.isPlaying = true;
  24594. this.source = source;
  24595. this.setDetune( this.detune );
  24596. this.setPlaybackRate( this.playbackRate );
  24597. return this.connect();
  24598. },
  24599. pause: function () {
  24600. if ( this.hasPlaybackControl === false ) {
  24601. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  24602. return;
  24603. }
  24604. if ( this.isPlaying === true ) {
  24605. this.source.stop();
  24606. this.source.onended = null;
  24607. this.offset += ( this.context.currentTime - this.startTime ) * this.playbackRate;
  24608. this.isPlaying = false;
  24609. }
  24610. return this;
  24611. },
  24612. stop: function () {
  24613. if ( this.hasPlaybackControl === false ) {
  24614. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  24615. return;
  24616. }
  24617. this.source.stop();
  24618. this.source.onended = null;
  24619. this.offset = 0;
  24620. this.isPlaying = false;
  24621. return this;
  24622. },
  24623. connect: function () {
  24624. if ( this.filters.length > 0 ) {
  24625. this.source.connect( this.filters[ 0 ] );
  24626. for ( var i = 1, l = this.filters.length; i < l; i ++ ) {
  24627. this.filters[ i - 1 ].connect( this.filters[ i ] );
  24628. }
  24629. this.filters[ this.filters.length - 1 ].connect( this.getOutput() );
  24630. } else {
  24631. this.source.connect( this.getOutput() );
  24632. }
  24633. return this;
  24634. },
  24635. disconnect: function () {
  24636. if ( this.filters.length > 0 ) {
  24637. this.source.disconnect( this.filters[ 0 ] );
  24638. for ( var i = 1, l = this.filters.length; i < l; i ++ ) {
  24639. this.filters[ i - 1 ].disconnect( this.filters[ i ] );
  24640. }
  24641. this.filters[ this.filters.length - 1 ].disconnect( this.getOutput() );
  24642. } else {
  24643. this.source.disconnect( this.getOutput() );
  24644. }
  24645. return this;
  24646. },
  24647. getFilters: function () {
  24648. return this.filters;
  24649. },
  24650. setFilters: function ( value ) {
  24651. if ( ! value ) value = [];
  24652. if ( this.isPlaying === true ) {
  24653. this.disconnect();
  24654. this.filters = value;
  24655. this.connect();
  24656. } else {
  24657. this.filters = value;
  24658. }
  24659. return this;
  24660. },
  24661. setDetune: function ( value ) {
  24662. this.detune = value;
  24663. if ( this.source.detune === undefined ) return; // only set detune when available
  24664. if ( this.isPlaying === true ) {
  24665. this.source.detune.setTargetAtTime( this.detune, this.context.currentTime, 0.01 );
  24666. }
  24667. return this;
  24668. },
  24669. getDetune: function () {
  24670. return this.detune;
  24671. },
  24672. getFilter: function () {
  24673. return this.getFilters()[ 0 ];
  24674. },
  24675. setFilter: function ( filter ) {
  24676. return this.setFilters( filter ? [ filter ] : [] );
  24677. },
  24678. setPlaybackRate: function ( value ) {
  24679. if ( this.hasPlaybackControl === false ) {
  24680. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  24681. return;
  24682. }
  24683. this.playbackRate = value;
  24684. if ( this.isPlaying === true ) {
  24685. this.source.playbackRate.setTargetAtTime( this.playbackRate, this.context.currentTime, 0.01 );
  24686. }
  24687. return this;
  24688. },
  24689. getPlaybackRate: function () {
  24690. return this.playbackRate;
  24691. },
  24692. onEnded: function () {
  24693. this.isPlaying = false;
  24694. },
  24695. getLoop: function () {
  24696. if ( this.hasPlaybackControl === false ) {
  24697. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  24698. return false;
  24699. }
  24700. return this.loop;
  24701. },
  24702. setLoop: function ( value ) {
  24703. if ( this.hasPlaybackControl === false ) {
  24704. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  24705. return;
  24706. }
  24707. this.loop = value;
  24708. if ( this.isPlaying === true ) {
  24709. this.source.loop = this.loop;
  24710. }
  24711. return this;
  24712. },
  24713. getVolume: function () {
  24714. return this.gain.gain.value;
  24715. },
  24716. setVolume: function ( value ) {
  24717. this.gain.gain.setTargetAtTime( value, this.context.currentTime, 0.01 );
  24718. return this;
  24719. }
  24720. } );
  24721. /**
  24722. * @author mrdoob / http://mrdoob.com/
  24723. */
  24724. function PositionalAudio( listener ) {
  24725. Audio.call( this, listener );
  24726. this.panner = this.context.createPanner();
  24727. this.panner.panningModel = 'HRTF';
  24728. this.panner.connect( this.gain );
  24729. }
  24730. PositionalAudio.prototype = Object.assign( Object.create( Audio.prototype ), {
  24731. constructor: PositionalAudio,
  24732. getOutput: function () {
  24733. return this.panner;
  24734. },
  24735. getRefDistance: function () {
  24736. return this.panner.refDistance;
  24737. },
  24738. setRefDistance: function ( value ) {
  24739. this.panner.refDistance = value;
  24740. return this;
  24741. },
  24742. getRolloffFactor: function () {
  24743. return this.panner.rolloffFactor;
  24744. },
  24745. setRolloffFactor: function ( value ) {
  24746. this.panner.rolloffFactor = value;
  24747. return this;
  24748. },
  24749. getDistanceModel: function () {
  24750. return this.panner.distanceModel;
  24751. },
  24752. setDistanceModel: function ( value ) {
  24753. this.panner.distanceModel = value;
  24754. return this;
  24755. },
  24756. getMaxDistance: function () {
  24757. return this.panner.maxDistance;
  24758. },
  24759. setMaxDistance: function ( value ) {
  24760. this.panner.maxDistance = value;
  24761. return this;
  24762. },
  24763. setDirectionalCone: function ( coneInnerAngle, coneOuterAngle, coneOuterGain ) {
  24764. this.panner.coneInnerAngle = coneInnerAngle;
  24765. this.panner.coneOuterAngle = coneOuterAngle;
  24766. this.panner.coneOuterGain = coneOuterGain;
  24767. return this;
  24768. },
  24769. updateMatrixWorld: ( function () {
  24770. var position = new Vector3();
  24771. var quaternion = new Quaternion();
  24772. var scale = new Vector3();
  24773. var orientation = new Vector3();
  24774. return function updateMatrixWorld( force ) {
  24775. Object3D.prototype.updateMatrixWorld.call( this, force );
  24776. if ( this.hasPlaybackControl === true && this.isPlaying === false ) return;
  24777. this.matrixWorld.decompose( position, quaternion, scale );
  24778. orientation.set( 0, 0, 1 ).applyQuaternion( quaternion );
  24779. var panner = this.panner;
  24780. if ( panner.positionX ) {
  24781. // code path for Chrome and Firefox (see #14393)
  24782. var endTime = this.context.currentTime + this.listener.timeDelta;
  24783. panner.positionX.linearRampToValueAtTime( position.x, endTime );
  24784. panner.positionY.linearRampToValueAtTime( position.y, endTime );
  24785. panner.positionZ.linearRampToValueAtTime( position.z, endTime );
  24786. panner.orientationX.linearRampToValueAtTime( orientation.x, endTime );
  24787. panner.orientationY.linearRampToValueAtTime( orientation.y, endTime );
  24788. panner.orientationZ.linearRampToValueAtTime( orientation.z, endTime );
  24789. } else {
  24790. panner.setPosition( position.x, position.y, position.z );
  24791. panner.setOrientation( orientation.x, orientation.y, orientation.z );
  24792. }
  24793. };
  24794. } )()
  24795. } );
  24796. /**
  24797. * @author mrdoob / http://mrdoob.com/
  24798. */
  24799. function AudioAnalyser( audio, fftSize ) {
  24800. this.analyser = audio.context.createAnalyser();
  24801. this.analyser.fftSize = fftSize !== undefined ? fftSize : 2048;
  24802. this.data = new Uint8Array( this.analyser.frequencyBinCount );
  24803. audio.getOutput().connect( this.analyser );
  24804. }
  24805. Object.assign( AudioAnalyser.prototype, {
  24806. getFrequencyData: function () {
  24807. this.analyser.getByteFrequencyData( this.data );
  24808. return this.data;
  24809. },
  24810. getAverageFrequency: function () {
  24811. var value = 0, data = this.getFrequencyData();
  24812. for ( var i = 0; i < data.length; i ++ ) {
  24813. value += data[ i ];
  24814. }
  24815. return value / data.length;
  24816. }
  24817. } );
  24818. /**
  24819. *
  24820. * Buffered scene graph property that allows weighted accumulation.
  24821. *
  24822. *
  24823. * @author Ben Houston / http://clara.io/
  24824. * @author David Sarno / http://lighthaus.us/
  24825. * @author tschw
  24826. */
  24827. function PropertyMixer( binding, typeName, valueSize ) {
  24828. this.binding = binding;
  24829. this.valueSize = valueSize;
  24830. var bufferType = Float64Array,
  24831. mixFunction;
  24832. switch ( typeName ) {
  24833. case 'quaternion':
  24834. mixFunction = this._slerp;
  24835. break;
  24836. case 'string':
  24837. case 'bool':
  24838. bufferType = Array;
  24839. mixFunction = this._select;
  24840. break;
  24841. default:
  24842. mixFunction = this._lerp;
  24843. }
  24844. this.buffer = new bufferType( valueSize * 4 );
  24845. // layout: [ incoming | accu0 | accu1 | orig ]
  24846. //
  24847. // interpolators can use .buffer as their .result
  24848. // the data then goes to 'incoming'
  24849. //
  24850. // 'accu0' and 'accu1' are used frame-interleaved for
  24851. // the cumulative result and are compared to detect
  24852. // changes
  24853. //
  24854. // 'orig' stores the original state of the property
  24855. this._mixBufferRegion = mixFunction;
  24856. this.cumulativeWeight = 0;
  24857. this.useCount = 0;
  24858. this.referenceCount = 0;
  24859. }
  24860. Object.assign( PropertyMixer.prototype, {
  24861. // accumulate data in the 'incoming' region into 'accu<i>'
  24862. accumulate: function ( accuIndex, weight ) {
  24863. // note: happily accumulating nothing when weight = 0, the caller knows
  24864. // the weight and shouldn't have made the call in the first place
  24865. var buffer = this.buffer,
  24866. stride = this.valueSize,
  24867. offset = accuIndex * stride + stride,
  24868. currentWeight = this.cumulativeWeight;
  24869. if ( currentWeight === 0 ) {
  24870. // accuN := incoming * weight
  24871. for ( var i = 0; i !== stride; ++ i ) {
  24872. buffer[ offset + i ] = buffer[ i ];
  24873. }
  24874. currentWeight = weight;
  24875. } else {
  24876. // accuN := accuN + incoming * weight
  24877. currentWeight += weight;
  24878. var mix = weight / currentWeight;
  24879. this._mixBufferRegion( buffer, offset, 0, mix, stride );
  24880. }
  24881. this.cumulativeWeight = currentWeight;
  24882. },
  24883. // apply the state of 'accu<i>' to the binding when accus differ
  24884. apply: function ( accuIndex ) {
  24885. var stride = this.valueSize,
  24886. buffer = this.buffer,
  24887. offset = accuIndex * stride + stride,
  24888. weight = this.cumulativeWeight,
  24889. binding = this.binding;
  24890. this.cumulativeWeight = 0;
  24891. if ( weight < 1 ) {
  24892. // accuN := accuN + original * ( 1 - cumulativeWeight )
  24893. var originalValueOffset = stride * 3;
  24894. this._mixBufferRegion(
  24895. buffer, offset, originalValueOffset, 1 - weight, stride );
  24896. }
  24897. for ( var i = stride, e = stride + stride; i !== e; ++ i ) {
  24898. if ( buffer[ i ] !== buffer[ i + stride ] ) {
  24899. // value has changed -> update scene graph
  24900. binding.setValue( buffer, offset );
  24901. break;
  24902. }
  24903. }
  24904. },
  24905. // remember the state of the bound property and copy it to both accus
  24906. saveOriginalState: function () {
  24907. var binding = this.binding;
  24908. var buffer = this.buffer,
  24909. stride = this.valueSize,
  24910. originalValueOffset = stride * 3;
  24911. binding.getValue( buffer, originalValueOffset );
  24912. // accu[0..1] := orig -- initially detect changes against the original
  24913. for ( var i = stride, e = originalValueOffset; i !== e; ++ i ) {
  24914. buffer[ i ] = buffer[ originalValueOffset + ( i % stride ) ];
  24915. }
  24916. this.cumulativeWeight = 0;
  24917. },
  24918. // apply the state previously taken via 'saveOriginalState' to the binding
  24919. restoreOriginalState: function () {
  24920. var originalValueOffset = this.valueSize * 3;
  24921. this.binding.setValue( this.buffer, originalValueOffset );
  24922. },
  24923. // mix functions
  24924. _select: function ( buffer, dstOffset, srcOffset, t, stride ) {
  24925. if ( t >= 0.5 ) {
  24926. for ( var i = 0; i !== stride; ++ i ) {
  24927. buffer[ dstOffset + i ] = buffer[ srcOffset + i ];
  24928. }
  24929. }
  24930. },
  24931. _slerp: function ( buffer, dstOffset, srcOffset, t ) {
  24932. Quaternion.slerpFlat( buffer, dstOffset, buffer, dstOffset, buffer, srcOffset, t );
  24933. },
  24934. _lerp: function ( buffer, dstOffset, srcOffset, t, stride ) {
  24935. var s = 1 - t;
  24936. for ( var i = 0; i !== stride; ++ i ) {
  24937. var j = dstOffset + i;
  24938. buffer[ j ] = buffer[ j ] * s + buffer[ srcOffset + i ] * t;
  24939. }
  24940. }
  24941. } );
  24942. /**
  24943. *
  24944. * A reference to a real property in the scene graph.
  24945. *
  24946. *
  24947. * @author Ben Houston / http://clara.io/
  24948. * @author David Sarno / http://lighthaus.us/
  24949. * @author tschw
  24950. */
  24951. // Characters [].:/ are reserved for track binding syntax.
  24952. var RESERVED_CHARS_RE = '\\[\\]\\.:\\/';
  24953. function Composite( targetGroup, path, optionalParsedPath ) {
  24954. var parsedPath = optionalParsedPath || PropertyBinding.parseTrackName( path );
  24955. this._targetGroup = targetGroup;
  24956. this._bindings = targetGroup.subscribe_( path, parsedPath );
  24957. }
  24958. Object.assign( Composite.prototype, {
  24959. getValue: function ( array, offset ) {
  24960. this.bind(); // bind all binding
  24961. var firstValidIndex = this._targetGroup.nCachedObjects_,
  24962. binding = this._bindings[ firstValidIndex ];
  24963. // and only call .getValue on the first
  24964. if ( binding !== undefined ) binding.getValue( array, offset );
  24965. },
  24966. setValue: function ( array, offset ) {
  24967. var bindings = this._bindings;
  24968. for ( var i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++ i ) {
  24969. bindings[ i ].setValue( array, offset );
  24970. }
  24971. },
  24972. bind: function () {
  24973. var bindings = this._bindings;
  24974. for ( var i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++ i ) {
  24975. bindings[ i ].bind();
  24976. }
  24977. },
  24978. unbind: function () {
  24979. var bindings = this._bindings;
  24980. for ( var i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++ i ) {
  24981. bindings[ i ].unbind();
  24982. }
  24983. }
  24984. } );
  24985. function PropertyBinding( rootNode, path, parsedPath ) {
  24986. this.path = path;
  24987. this.parsedPath = parsedPath || PropertyBinding.parseTrackName( path );
  24988. this.node = PropertyBinding.findNode( rootNode, this.parsedPath.nodeName ) || rootNode;
  24989. this.rootNode = rootNode;
  24990. }
  24991. Object.assign( PropertyBinding, {
  24992. Composite: Composite,
  24993. create: function ( root, path, parsedPath ) {
  24994. if ( ! ( root && root.isAnimationObjectGroup ) ) {
  24995. return new PropertyBinding( root, path, parsedPath );
  24996. } else {
  24997. return new PropertyBinding.Composite( root, path, parsedPath );
  24998. }
  24999. },
  25000. /**
  25001. * Replaces spaces with underscores and removes unsupported characters from
  25002. * node names, to ensure compatibility with parseTrackName().
  25003. *
  25004. * @param {string} name Node name to be sanitized.
  25005. * @return {string}
  25006. */
  25007. sanitizeNodeName: ( function () {
  25008. var reservedRe = new RegExp( '[' + RESERVED_CHARS_RE + ']', 'g' );
  25009. return function sanitizeNodeName( name ) {
  25010. return name.replace( /\s/g, '_' ).replace( reservedRe, '' );
  25011. };
  25012. }() ),
  25013. parseTrackName: function () {
  25014. // Attempts to allow node names from any language. ES5's `\w` regexp matches
  25015. // only latin characters, and the unicode \p{L} is not yet supported. So
  25016. // instead, we exclude reserved characters and match everything else.
  25017. var wordChar = '[^' + RESERVED_CHARS_RE + ']';
  25018. var wordCharOrDot = '[^' + RESERVED_CHARS_RE.replace( '\\.', '' ) + ']';
  25019. // Parent directories, delimited by '/' or ':'. Currently unused, but must
  25020. // be matched to parse the rest of the track name.
  25021. var directoryRe = /((?:WC+[\/:])*)/.source.replace( 'WC', wordChar );
  25022. // Target node. May contain word characters (a-zA-Z0-9_) and '.' or '-'.
  25023. var nodeRe = /(WCOD+)?/.source.replace( 'WCOD', wordCharOrDot );
  25024. // Object on target node, and accessor. May not contain reserved
  25025. // characters. Accessor may contain any character except closing bracket.
  25026. var objectRe = /(?:\.(WC+)(?:\[(.+)\])?)?/.source.replace( 'WC', wordChar );
  25027. // Property and accessor. May not contain reserved characters. Accessor may
  25028. // contain any non-bracket characters.
  25029. var propertyRe = /\.(WC+)(?:\[(.+)\])?/.source.replace( 'WC', wordChar );
  25030. var trackRe = new RegExp( ''
  25031. + '^'
  25032. + directoryRe
  25033. + nodeRe
  25034. + objectRe
  25035. + propertyRe
  25036. + '$'
  25037. );
  25038. var supportedObjectNames = [ 'material', 'materials', 'bones' ];
  25039. return function parseTrackName( trackName ) {
  25040. var matches = trackRe.exec( trackName );
  25041. if ( ! matches ) {
  25042. throw new Error( 'PropertyBinding: Cannot parse trackName: ' + trackName );
  25043. }
  25044. var results = {
  25045. // directoryName: matches[ 1 ], // (tschw) currently unused
  25046. nodeName: matches[ 2 ],
  25047. objectName: matches[ 3 ],
  25048. objectIndex: matches[ 4 ],
  25049. propertyName: matches[ 5 ], // required
  25050. propertyIndex: matches[ 6 ]
  25051. };
  25052. var lastDot = results.nodeName && results.nodeName.lastIndexOf( '.' );
  25053. if ( lastDot !== undefined && lastDot !== - 1 ) {
  25054. var objectName = results.nodeName.substring( lastDot + 1 );
  25055. // Object names must be checked against a whitelist. Otherwise, there
  25056. // is no way to parse 'foo.bar.baz': 'baz' must be a property, but
  25057. // 'bar' could be the objectName, or part of a nodeName (which can
  25058. // include '.' characters).
  25059. if ( supportedObjectNames.indexOf( objectName ) !== - 1 ) {
  25060. results.nodeName = results.nodeName.substring( 0, lastDot );
  25061. results.objectName = objectName;
  25062. }
  25063. }
  25064. if ( results.propertyName === null || results.propertyName.length === 0 ) {
  25065. throw new Error( 'PropertyBinding: can not parse propertyName from trackName: ' + trackName );
  25066. }
  25067. return results;
  25068. };
  25069. }(),
  25070. findNode: function ( root, nodeName ) {
  25071. if ( ! nodeName || nodeName === "" || nodeName === "root" || nodeName === "." || nodeName === - 1 || nodeName === root.name || nodeName === root.uuid ) {
  25072. return root;
  25073. }
  25074. // search into skeleton bones.
  25075. if ( root.skeleton ) {
  25076. var bone = root.skeleton.getBoneByName( nodeName );
  25077. if ( bone !== undefined ) {
  25078. return bone;
  25079. }
  25080. }
  25081. // search into node subtree.
  25082. if ( root.children ) {
  25083. var searchNodeSubtree = function ( children ) {
  25084. for ( var i = 0; i < children.length; i ++ ) {
  25085. var childNode = children[ i ];
  25086. if ( childNode.name === nodeName || childNode.uuid === nodeName ) {
  25087. return childNode;
  25088. }
  25089. var result = searchNodeSubtree( childNode.children );
  25090. if ( result ) return result;
  25091. }
  25092. return null;
  25093. };
  25094. var subTreeNode = searchNodeSubtree( root.children );
  25095. if ( subTreeNode ) {
  25096. return subTreeNode;
  25097. }
  25098. }
  25099. return null;
  25100. }
  25101. } );
  25102. Object.assign( PropertyBinding.prototype, { // prototype, continued
  25103. // these are used to "bind" a nonexistent property
  25104. _getValue_unavailable: function () {},
  25105. _setValue_unavailable: function () {},
  25106. BindingType: {
  25107. Direct: 0,
  25108. EntireArray: 1,
  25109. ArrayElement: 2,
  25110. HasFromToArray: 3
  25111. },
  25112. Versioning: {
  25113. None: 0,
  25114. NeedsUpdate: 1,
  25115. MatrixWorldNeedsUpdate: 2
  25116. },
  25117. GetterByBindingType: [
  25118. function getValue_direct( buffer, offset ) {
  25119. buffer[ offset ] = this.node[ this.propertyName ];
  25120. },
  25121. function getValue_array( buffer, offset ) {
  25122. var source = this.resolvedProperty;
  25123. for ( var i = 0, n = source.length; i !== n; ++ i ) {
  25124. buffer[ offset ++ ] = source[ i ];
  25125. }
  25126. },
  25127. function getValue_arrayElement( buffer, offset ) {
  25128. buffer[ offset ] = this.resolvedProperty[ this.propertyIndex ];
  25129. },
  25130. function getValue_toArray( buffer, offset ) {
  25131. this.resolvedProperty.toArray( buffer, offset );
  25132. }
  25133. ],
  25134. SetterByBindingTypeAndVersioning: [
  25135. [
  25136. // Direct
  25137. function setValue_direct( buffer, offset ) {
  25138. this.targetObject[ this.propertyName ] = buffer[ offset ];
  25139. },
  25140. function setValue_direct_setNeedsUpdate( buffer, offset ) {
  25141. this.targetObject[ this.propertyName ] = buffer[ offset ];
  25142. this.targetObject.needsUpdate = true;
  25143. },
  25144. function setValue_direct_setMatrixWorldNeedsUpdate( buffer, offset ) {
  25145. this.targetObject[ this.propertyName ] = buffer[ offset ];
  25146. this.targetObject.matrixWorldNeedsUpdate = true;
  25147. }
  25148. ], [
  25149. // EntireArray
  25150. function setValue_array( buffer, offset ) {
  25151. var dest = this.resolvedProperty;
  25152. for ( var i = 0, n = dest.length; i !== n; ++ i ) {
  25153. dest[ i ] = buffer[ offset ++ ];
  25154. }
  25155. },
  25156. function setValue_array_setNeedsUpdate( buffer, offset ) {
  25157. var dest = this.resolvedProperty;
  25158. for ( var i = 0, n = dest.length; i !== n; ++ i ) {
  25159. dest[ i ] = buffer[ offset ++ ];
  25160. }
  25161. this.targetObject.needsUpdate = true;
  25162. },
  25163. function setValue_array_setMatrixWorldNeedsUpdate( buffer, offset ) {
  25164. var dest = this.resolvedProperty;
  25165. for ( var i = 0, n = dest.length; i !== n; ++ i ) {
  25166. dest[ i ] = buffer[ offset ++ ];
  25167. }
  25168. this.targetObject.matrixWorldNeedsUpdate = true;
  25169. }
  25170. ], [
  25171. // ArrayElement
  25172. function setValue_arrayElement( buffer, offset ) {
  25173. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  25174. },
  25175. function setValue_arrayElement_setNeedsUpdate( buffer, offset ) {
  25176. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  25177. this.targetObject.needsUpdate = true;
  25178. },
  25179. function setValue_arrayElement_setMatrixWorldNeedsUpdate( buffer, offset ) {
  25180. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  25181. this.targetObject.matrixWorldNeedsUpdate = true;
  25182. }
  25183. ], [
  25184. // HasToFromArray
  25185. function setValue_fromArray( buffer, offset ) {
  25186. this.resolvedProperty.fromArray( buffer, offset );
  25187. },
  25188. function setValue_fromArray_setNeedsUpdate( buffer, offset ) {
  25189. this.resolvedProperty.fromArray( buffer, offset );
  25190. this.targetObject.needsUpdate = true;
  25191. },
  25192. function setValue_fromArray_setMatrixWorldNeedsUpdate( buffer, offset ) {
  25193. this.resolvedProperty.fromArray( buffer, offset );
  25194. this.targetObject.matrixWorldNeedsUpdate = true;
  25195. }
  25196. ]
  25197. ],
  25198. getValue: function getValue_unbound( targetArray, offset ) {
  25199. this.bind();
  25200. this.getValue( targetArray, offset );
  25201. // Note: This class uses a State pattern on a per-method basis:
  25202. // 'bind' sets 'this.getValue' / 'setValue' and shadows the
  25203. // prototype version of these methods with one that represents
  25204. // the bound state. When the property is not found, the methods
  25205. // become no-ops.
  25206. },
  25207. setValue: function getValue_unbound( sourceArray, offset ) {
  25208. this.bind();
  25209. this.setValue( sourceArray, offset );
  25210. },
  25211. // create getter / setter pair for a property in the scene graph
  25212. bind: function () {
  25213. var targetObject = this.node,
  25214. parsedPath = this.parsedPath,
  25215. objectName = parsedPath.objectName,
  25216. propertyName = parsedPath.propertyName,
  25217. propertyIndex = parsedPath.propertyIndex;
  25218. if ( ! targetObject ) {
  25219. targetObject = PropertyBinding.findNode( this.rootNode, parsedPath.nodeName ) || this.rootNode;
  25220. this.node = targetObject;
  25221. }
  25222. // set fail state so we can just 'return' on error
  25223. this.getValue = this._getValue_unavailable;
  25224. this.setValue = this._setValue_unavailable;
  25225. // ensure there is a value node
  25226. if ( ! targetObject ) {
  25227. console.error( 'THREE.PropertyBinding: Trying to update node for track: ' + this.path + ' but it wasn\'t found.' );
  25228. return;
  25229. }
  25230. if ( objectName ) {
  25231. var objectIndex = parsedPath.objectIndex;
  25232. // special cases were we need to reach deeper into the hierarchy to get the face materials....
  25233. switch ( objectName ) {
  25234. case 'materials':
  25235. if ( ! targetObject.material ) {
  25236. console.error( 'THREE.PropertyBinding: Can not bind to material as node does not have a material.', this );
  25237. return;
  25238. }
  25239. if ( ! targetObject.material.materials ) {
  25240. console.error( 'THREE.PropertyBinding: Can not bind to material.materials as node.material does not have a materials array.', this );
  25241. return;
  25242. }
  25243. targetObject = targetObject.material.materials;
  25244. break;
  25245. case 'bones':
  25246. if ( ! targetObject.skeleton ) {
  25247. console.error( 'THREE.PropertyBinding: Can not bind to bones as node does not have a skeleton.', this );
  25248. return;
  25249. }
  25250. // potential future optimization: skip this if propertyIndex is already an integer
  25251. // and convert the integer string to a true integer.
  25252. targetObject = targetObject.skeleton.bones;
  25253. // support resolving morphTarget names into indices.
  25254. for ( var i = 0; i < targetObject.length; i ++ ) {
  25255. if ( targetObject[ i ].name === objectIndex ) {
  25256. objectIndex = i;
  25257. break;
  25258. }
  25259. }
  25260. break;
  25261. default:
  25262. if ( targetObject[ objectName ] === undefined ) {
  25263. console.error( 'THREE.PropertyBinding: Can not bind to objectName of node undefined.', this );
  25264. return;
  25265. }
  25266. targetObject = targetObject[ objectName ];
  25267. }
  25268. if ( objectIndex !== undefined ) {
  25269. if ( targetObject[ objectIndex ] === undefined ) {
  25270. console.error( 'THREE.PropertyBinding: Trying to bind to objectIndex of objectName, but is undefined.', this, targetObject );
  25271. return;
  25272. }
  25273. targetObject = targetObject[ objectIndex ];
  25274. }
  25275. }
  25276. // resolve property
  25277. var nodeProperty = targetObject[ propertyName ];
  25278. if ( nodeProperty === undefined ) {
  25279. var nodeName = parsedPath.nodeName;
  25280. console.error( 'THREE.PropertyBinding: Trying to update property for track: ' + nodeName +
  25281. '.' + propertyName + ' but it wasn\'t found.', targetObject );
  25282. return;
  25283. }
  25284. // determine versioning scheme
  25285. var versioning = this.Versioning.None;
  25286. this.targetObject = targetObject;
  25287. if ( targetObject.needsUpdate !== undefined ) { // material
  25288. versioning = this.Versioning.NeedsUpdate;
  25289. } else if ( targetObject.matrixWorldNeedsUpdate !== undefined ) { // node transform
  25290. versioning = this.Versioning.MatrixWorldNeedsUpdate;
  25291. }
  25292. // determine how the property gets bound
  25293. var bindingType = this.BindingType.Direct;
  25294. if ( propertyIndex !== undefined ) {
  25295. // access a sub element of the property array (only primitives are supported right now)
  25296. if ( propertyName === "morphTargetInfluences" ) {
  25297. // potential optimization, skip this if propertyIndex is already an integer, and convert the integer string to a true integer.
  25298. // support resolving morphTarget names into indices.
  25299. if ( ! targetObject.geometry ) {
  25300. console.error( 'THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.', this );
  25301. return;
  25302. }
  25303. if ( targetObject.geometry.isBufferGeometry ) {
  25304. if ( ! targetObject.geometry.morphAttributes ) {
  25305. console.error( 'THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.morphAttributes.', this );
  25306. return;
  25307. }
  25308. for ( var i = 0; i < this.node.geometry.morphAttributes.position.length; i ++ ) {
  25309. if ( targetObject.geometry.morphAttributes.position[ i ].name === propertyIndex ) {
  25310. propertyIndex = i;
  25311. break;
  25312. }
  25313. }
  25314. } else {
  25315. if ( ! targetObject.geometry.morphTargets ) {
  25316. console.error( 'THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.morphTargets.', this );
  25317. return;
  25318. }
  25319. for ( var i = 0; i < this.node.geometry.morphTargets.length; i ++ ) {
  25320. if ( targetObject.geometry.morphTargets[ i ].name === propertyIndex ) {
  25321. propertyIndex = i;
  25322. break;
  25323. }
  25324. }
  25325. }
  25326. }
  25327. bindingType = this.BindingType.ArrayElement;
  25328. this.resolvedProperty = nodeProperty;
  25329. this.propertyIndex = propertyIndex;
  25330. } else if ( nodeProperty.fromArray !== undefined && nodeProperty.toArray !== undefined ) {
  25331. // must use copy for Object3D.Euler/Quaternion
  25332. bindingType = this.BindingType.HasFromToArray;
  25333. this.resolvedProperty = nodeProperty;
  25334. } else if ( Array.isArray( nodeProperty ) ) {
  25335. bindingType = this.BindingType.EntireArray;
  25336. this.resolvedProperty = nodeProperty;
  25337. } else {
  25338. this.propertyName = propertyName;
  25339. }
  25340. // select getter / setter
  25341. this.getValue = this.GetterByBindingType[ bindingType ];
  25342. this.setValue = this.SetterByBindingTypeAndVersioning[ bindingType ][ versioning ];
  25343. },
  25344. unbind: function () {
  25345. this.node = null;
  25346. // back to the prototype version of getValue / setValue
  25347. // note: avoiding to mutate the shape of 'this' via 'delete'
  25348. this.getValue = this._getValue_unbound;
  25349. this.setValue = this._setValue_unbound;
  25350. }
  25351. } );
  25352. //!\ DECLARE ALIAS AFTER assign prototype !
  25353. Object.assign( PropertyBinding.prototype, {
  25354. // initial state of these methods that calls 'bind'
  25355. _getValue_unbound: PropertyBinding.prototype.getValue,
  25356. _setValue_unbound: PropertyBinding.prototype.setValue,
  25357. } );
  25358. /**
  25359. *
  25360. * A group of objects that receives a shared animation state.
  25361. *
  25362. * Usage:
  25363. *
  25364. * - Add objects you would otherwise pass as 'root' to the
  25365. * constructor or the .clipAction method of AnimationMixer.
  25366. *
  25367. * - Instead pass this object as 'root'.
  25368. *
  25369. * - You can also add and remove objects later when the mixer
  25370. * is running.
  25371. *
  25372. * Note:
  25373. *
  25374. * Objects of this class appear as one object to the mixer,
  25375. * so cache control of the individual objects must be done
  25376. * on the group.
  25377. *
  25378. * Limitation:
  25379. *
  25380. * - The animated properties must be compatible among the
  25381. * all objects in the group.
  25382. *
  25383. * - A single property can either be controlled through a
  25384. * target group or directly, but not both.
  25385. *
  25386. * @author tschw
  25387. */
  25388. function AnimationObjectGroup() {
  25389. this.uuid = _Math.generateUUID();
  25390. // cached objects followed by the active ones
  25391. this._objects = Array.prototype.slice.call( arguments );
  25392. this.nCachedObjects_ = 0; // threshold
  25393. // note: read by PropertyBinding.Composite
  25394. var indices = {};
  25395. this._indicesByUUID = indices; // for bookkeeping
  25396. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  25397. indices[ arguments[ i ].uuid ] = i;
  25398. }
  25399. this._paths = []; // inside: string
  25400. this._parsedPaths = []; // inside: { we don't care, here }
  25401. this._bindings = []; // inside: Array< PropertyBinding >
  25402. this._bindingsIndicesByPath = {}; // inside: indices in these arrays
  25403. var scope = this;
  25404. this.stats = {
  25405. objects: {
  25406. get total() {
  25407. return scope._objects.length;
  25408. },
  25409. get inUse() {
  25410. return this.total - scope.nCachedObjects_;
  25411. }
  25412. },
  25413. get bindingsPerObject() {
  25414. return scope._bindings.length;
  25415. }
  25416. };
  25417. }
  25418. Object.assign( AnimationObjectGroup.prototype, {
  25419. isAnimationObjectGroup: true,
  25420. add: function () {
  25421. var objects = this._objects,
  25422. nObjects = objects.length,
  25423. nCachedObjects = this.nCachedObjects_,
  25424. indicesByUUID = this._indicesByUUID,
  25425. paths = this._paths,
  25426. parsedPaths = this._parsedPaths,
  25427. bindings = this._bindings,
  25428. nBindings = bindings.length,
  25429. knownObject = undefined;
  25430. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  25431. var object = arguments[ i ],
  25432. uuid = object.uuid,
  25433. index = indicesByUUID[ uuid ];
  25434. if ( index === undefined ) {
  25435. // unknown object -> add it to the ACTIVE region
  25436. index = nObjects ++;
  25437. indicesByUUID[ uuid ] = index;
  25438. objects.push( object );
  25439. // accounting is done, now do the same for all bindings
  25440. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  25441. bindings[ j ].push( new PropertyBinding( object, paths[ j ], parsedPaths[ j ] ) );
  25442. }
  25443. } else if ( index < nCachedObjects ) {
  25444. knownObject = objects[ index ];
  25445. // move existing object to the ACTIVE region
  25446. var firstActiveIndex = -- nCachedObjects,
  25447. lastCachedObject = objects[ firstActiveIndex ];
  25448. indicesByUUID[ lastCachedObject.uuid ] = index;
  25449. objects[ index ] = lastCachedObject;
  25450. indicesByUUID[ uuid ] = firstActiveIndex;
  25451. objects[ firstActiveIndex ] = object;
  25452. // accounting is done, now do the same for all bindings
  25453. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  25454. var bindingsForPath = bindings[ j ],
  25455. lastCached = bindingsForPath[ firstActiveIndex ],
  25456. binding = bindingsForPath[ index ];
  25457. bindingsForPath[ index ] = lastCached;
  25458. if ( binding === undefined ) {
  25459. // since we do not bother to create new bindings
  25460. // for objects that are cached, the binding may
  25461. // or may not exist
  25462. binding = new PropertyBinding( object, paths[ j ], parsedPaths[ j ] );
  25463. }
  25464. bindingsForPath[ firstActiveIndex ] = binding;
  25465. }
  25466. } else if ( objects[ index ] !== knownObject ) {
  25467. console.error( 'THREE.AnimationObjectGroup: Different objects with the same UUID ' +
  25468. 'detected. Clean the caches or recreate your infrastructure when reloading scenes.' );
  25469. } // else the object is already where we want it to be
  25470. } // for arguments
  25471. this.nCachedObjects_ = nCachedObjects;
  25472. },
  25473. remove: function () {
  25474. var objects = this._objects,
  25475. nCachedObjects = this.nCachedObjects_,
  25476. indicesByUUID = this._indicesByUUID,
  25477. bindings = this._bindings,
  25478. nBindings = bindings.length;
  25479. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  25480. var object = arguments[ i ],
  25481. uuid = object.uuid,
  25482. index = indicesByUUID[ uuid ];
  25483. if ( index !== undefined && index >= nCachedObjects ) {
  25484. // move existing object into the CACHED region
  25485. var lastCachedIndex = nCachedObjects ++,
  25486. firstActiveObject = objects[ lastCachedIndex ];
  25487. indicesByUUID[ firstActiveObject.uuid ] = index;
  25488. objects[ index ] = firstActiveObject;
  25489. indicesByUUID[ uuid ] = lastCachedIndex;
  25490. objects[ lastCachedIndex ] = object;
  25491. // accounting is done, now do the same for all bindings
  25492. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  25493. var bindingsForPath = bindings[ j ],
  25494. firstActive = bindingsForPath[ lastCachedIndex ],
  25495. binding = bindingsForPath[ index ];
  25496. bindingsForPath[ index ] = firstActive;
  25497. bindingsForPath[ lastCachedIndex ] = binding;
  25498. }
  25499. }
  25500. } // for arguments
  25501. this.nCachedObjects_ = nCachedObjects;
  25502. },
  25503. // remove & forget
  25504. uncache: function () {
  25505. var objects = this._objects,
  25506. nObjects = objects.length,
  25507. nCachedObjects = this.nCachedObjects_,
  25508. indicesByUUID = this._indicesByUUID,
  25509. bindings = this._bindings,
  25510. nBindings = bindings.length;
  25511. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  25512. var object = arguments[ i ],
  25513. uuid = object.uuid,
  25514. index = indicesByUUID[ uuid ];
  25515. if ( index !== undefined ) {
  25516. delete indicesByUUID[ uuid ];
  25517. if ( index < nCachedObjects ) {
  25518. // object is cached, shrink the CACHED region
  25519. var firstActiveIndex = -- nCachedObjects,
  25520. lastCachedObject = objects[ firstActiveIndex ],
  25521. lastIndex = -- nObjects,
  25522. lastObject = objects[ lastIndex ];
  25523. // last cached object takes this object's place
  25524. indicesByUUID[ lastCachedObject.uuid ] = index;
  25525. objects[ index ] = lastCachedObject;
  25526. // last object goes to the activated slot and pop
  25527. indicesByUUID[ lastObject.uuid ] = firstActiveIndex;
  25528. objects[ firstActiveIndex ] = lastObject;
  25529. objects.pop();
  25530. // accounting is done, now do the same for all bindings
  25531. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  25532. var bindingsForPath = bindings[ j ],
  25533. lastCached = bindingsForPath[ firstActiveIndex ],
  25534. last = bindingsForPath[ lastIndex ];
  25535. bindingsForPath[ index ] = lastCached;
  25536. bindingsForPath[ firstActiveIndex ] = last;
  25537. bindingsForPath.pop();
  25538. }
  25539. } else {
  25540. // object is active, just swap with the last and pop
  25541. var lastIndex = -- nObjects,
  25542. lastObject = objects[ lastIndex ];
  25543. indicesByUUID[ lastObject.uuid ] = index;
  25544. objects[ index ] = lastObject;
  25545. objects.pop();
  25546. // accounting is done, now do the same for all bindings
  25547. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  25548. var bindingsForPath = bindings[ j ];
  25549. bindingsForPath[ index ] = bindingsForPath[ lastIndex ];
  25550. bindingsForPath.pop();
  25551. }
  25552. } // cached or active
  25553. } // if object is known
  25554. } // for arguments
  25555. this.nCachedObjects_ = nCachedObjects;
  25556. },
  25557. // Internal interface used by befriended PropertyBinding.Composite:
  25558. subscribe_: function ( path, parsedPath ) {
  25559. // returns an array of bindings for the given path that is changed
  25560. // according to the contained objects in the group
  25561. var indicesByPath = this._bindingsIndicesByPath,
  25562. index = indicesByPath[ path ],
  25563. bindings = this._bindings;
  25564. if ( index !== undefined ) return bindings[ index ];
  25565. var paths = this._paths,
  25566. parsedPaths = this._parsedPaths,
  25567. objects = this._objects,
  25568. nObjects = objects.length,
  25569. nCachedObjects = this.nCachedObjects_,
  25570. bindingsForPath = new Array( nObjects );
  25571. index = bindings.length;
  25572. indicesByPath[ path ] = index;
  25573. paths.push( path );
  25574. parsedPaths.push( parsedPath );
  25575. bindings.push( bindingsForPath );
  25576. for ( var i = nCachedObjects, n = objects.length; i !== n; ++ i ) {
  25577. var object = objects[ i ];
  25578. bindingsForPath[ i ] = new PropertyBinding( object, path, parsedPath );
  25579. }
  25580. return bindingsForPath;
  25581. },
  25582. unsubscribe_: function ( path ) {
  25583. // tells the group to forget about a property path and no longer
  25584. // update the array previously obtained with 'subscribe_'
  25585. var indicesByPath = this._bindingsIndicesByPath,
  25586. index = indicesByPath[ path ];
  25587. if ( index !== undefined ) {
  25588. var paths = this._paths,
  25589. parsedPaths = this._parsedPaths,
  25590. bindings = this._bindings,
  25591. lastBindingsIndex = bindings.length - 1,
  25592. lastBindings = bindings[ lastBindingsIndex ],
  25593. lastBindingsPath = path[ lastBindingsIndex ];
  25594. indicesByPath[ lastBindingsPath ] = index;
  25595. bindings[ index ] = lastBindings;
  25596. bindings.pop();
  25597. parsedPaths[ index ] = parsedPaths[ lastBindingsIndex ];
  25598. parsedPaths.pop();
  25599. paths[ index ] = paths[ lastBindingsIndex ];
  25600. paths.pop();
  25601. }
  25602. }
  25603. } );
  25604. /**
  25605. *
  25606. * Action provided by AnimationMixer for scheduling clip playback on specific
  25607. * objects.
  25608. *
  25609. * @author Ben Houston / http://clara.io/
  25610. * @author David Sarno / http://lighthaus.us/
  25611. * @author tschw
  25612. *
  25613. */
  25614. function AnimationAction( mixer, clip, localRoot ) {
  25615. this._mixer = mixer;
  25616. this._clip = clip;
  25617. this._localRoot = localRoot || null;
  25618. var tracks = clip.tracks,
  25619. nTracks = tracks.length,
  25620. interpolants = new Array( nTracks );
  25621. var interpolantSettings = {
  25622. endingStart: ZeroCurvatureEnding,
  25623. endingEnd: ZeroCurvatureEnding
  25624. };
  25625. for ( var i = 0; i !== nTracks; ++ i ) {
  25626. var interpolant = tracks[ i ].createInterpolant( null );
  25627. interpolants[ i ] = interpolant;
  25628. interpolant.settings = interpolantSettings;
  25629. }
  25630. this._interpolantSettings = interpolantSettings;
  25631. this._interpolants = interpolants; // bound by the mixer
  25632. // inside: PropertyMixer (managed by the mixer)
  25633. this._propertyBindings = new Array( nTracks );
  25634. this._cacheIndex = null; // for the memory manager
  25635. this._byClipCacheIndex = null; // for the memory manager
  25636. this._timeScaleInterpolant = null;
  25637. this._weightInterpolant = null;
  25638. this.loop = LoopRepeat;
  25639. this._loopCount = - 1;
  25640. // global mixer time when the action is to be started
  25641. // it's set back to 'null' upon start of the action
  25642. this._startTime = null;
  25643. // scaled local time of the action
  25644. // gets clamped or wrapped to 0..clip.duration according to loop
  25645. this.time = 0;
  25646. this.timeScale = 1;
  25647. this._effectiveTimeScale = 1;
  25648. this.weight = 1;
  25649. this._effectiveWeight = 1;
  25650. this.repetitions = Infinity; // no. of repetitions when looping
  25651. this.paused = false; // true -> zero effective time scale
  25652. this.enabled = true; // false -> zero effective weight
  25653. this.clampWhenFinished = false;// keep feeding the last frame?
  25654. this.zeroSlopeAtStart = true;// for smooth interpolation w/o separate
  25655. this.zeroSlopeAtEnd = true;// clips for start, loop and end
  25656. }
  25657. Object.assign( AnimationAction.prototype, {
  25658. // State & Scheduling
  25659. play: function () {
  25660. this._mixer._activateAction( this );
  25661. return this;
  25662. },
  25663. stop: function () {
  25664. this._mixer._deactivateAction( this );
  25665. return this.reset();
  25666. },
  25667. reset: function () {
  25668. this.paused = false;
  25669. this.enabled = true;
  25670. this.time = 0; // restart clip
  25671. this._loopCount = - 1;// forget previous loops
  25672. this._startTime = null;// forget scheduling
  25673. return this.stopFading().stopWarping();
  25674. },
  25675. isRunning: function () {
  25676. return this.enabled && ! this.paused && this.timeScale !== 0 &&
  25677. this._startTime === null && this._mixer._isActiveAction( this );
  25678. },
  25679. // return true when play has been called
  25680. isScheduled: function () {
  25681. return this._mixer._isActiveAction( this );
  25682. },
  25683. startAt: function ( time ) {
  25684. this._startTime = time;
  25685. return this;
  25686. },
  25687. setLoop: function ( mode, repetitions ) {
  25688. this.loop = mode;
  25689. this.repetitions = repetitions;
  25690. return this;
  25691. },
  25692. // Weight
  25693. // set the weight stopping any scheduled fading
  25694. // although .enabled = false yields an effective weight of zero, this
  25695. // method does *not* change .enabled, because it would be confusing
  25696. setEffectiveWeight: function ( weight ) {
  25697. this.weight = weight;
  25698. // note: same logic as when updated at runtime
  25699. this._effectiveWeight = this.enabled ? weight : 0;
  25700. return this.stopFading();
  25701. },
  25702. // return the weight considering fading and .enabled
  25703. getEffectiveWeight: function () {
  25704. return this._effectiveWeight;
  25705. },
  25706. fadeIn: function ( duration ) {
  25707. return this._scheduleFading( duration, 0, 1 );
  25708. },
  25709. fadeOut: function ( duration ) {
  25710. return this._scheduleFading( duration, 1, 0 );
  25711. },
  25712. crossFadeFrom: function ( fadeOutAction, duration, warp ) {
  25713. fadeOutAction.fadeOut( duration );
  25714. this.fadeIn( duration );
  25715. if ( warp ) {
  25716. var fadeInDuration = this._clip.duration,
  25717. fadeOutDuration = fadeOutAction._clip.duration,
  25718. startEndRatio = fadeOutDuration / fadeInDuration,
  25719. endStartRatio = fadeInDuration / fadeOutDuration;
  25720. fadeOutAction.warp( 1.0, startEndRatio, duration );
  25721. this.warp( endStartRatio, 1.0, duration );
  25722. }
  25723. return this;
  25724. },
  25725. crossFadeTo: function ( fadeInAction, duration, warp ) {
  25726. return fadeInAction.crossFadeFrom( this, duration, warp );
  25727. },
  25728. stopFading: function () {
  25729. var weightInterpolant = this._weightInterpolant;
  25730. if ( weightInterpolant !== null ) {
  25731. this._weightInterpolant = null;
  25732. this._mixer._takeBackControlInterpolant( weightInterpolant );
  25733. }
  25734. return this;
  25735. },
  25736. // Time Scale Control
  25737. // set the time scale stopping any scheduled warping
  25738. // although .paused = true yields an effective time scale of zero, this
  25739. // method does *not* change .paused, because it would be confusing
  25740. setEffectiveTimeScale: function ( timeScale ) {
  25741. this.timeScale = timeScale;
  25742. this._effectiveTimeScale = this.paused ? 0 : timeScale;
  25743. return this.stopWarping();
  25744. },
  25745. // return the time scale considering warping and .paused
  25746. getEffectiveTimeScale: function () {
  25747. return this._effectiveTimeScale;
  25748. },
  25749. setDuration: function ( duration ) {
  25750. this.timeScale = this._clip.duration / duration;
  25751. return this.stopWarping();
  25752. },
  25753. syncWith: function ( action ) {
  25754. this.time = action.time;
  25755. this.timeScale = action.timeScale;
  25756. return this.stopWarping();
  25757. },
  25758. halt: function ( duration ) {
  25759. return this.warp( this._effectiveTimeScale, 0, duration );
  25760. },
  25761. warp: function ( startTimeScale, endTimeScale, duration ) {
  25762. var mixer = this._mixer, now = mixer.time,
  25763. interpolant = this._timeScaleInterpolant,
  25764. timeScale = this.timeScale;
  25765. if ( interpolant === null ) {
  25766. interpolant = mixer._lendControlInterpolant();
  25767. this._timeScaleInterpolant = interpolant;
  25768. }
  25769. var times = interpolant.parameterPositions,
  25770. values = interpolant.sampleValues;
  25771. times[ 0 ] = now;
  25772. times[ 1 ] = now + duration;
  25773. values[ 0 ] = startTimeScale / timeScale;
  25774. values[ 1 ] = endTimeScale / timeScale;
  25775. return this;
  25776. },
  25777. stopWarping: function () {
  25778. var timeScaleInterpolant = this._timeScaleInterpolant;
  25779. if ( timeScaleInterpolant !== null ) {
  25780. this._timeScaleInterpolant = null;
  25781. this._mixer._takeBackControlInterpolant( timeScaleInterpolant );
  25782. }
  25783. return this;
  25784. },
  25785. // Object Accessors
  25786. getMixer: function () {
  25787. return this._mixer;
  25788. },
  25789. getClip: function () {
  25790. return this._clip;
  25791. },
  25792. getRoot: function () {
  25793. return this._localRoot || this._mixer._root;
  25794. },
  25795. // Interna
  25796. _update: function ( time, deltaTime, timeDirection, accuIndex ) {
  25797. // called by the mixer
  25798. if ( ! this.enabled ) {
  25799. // call ._updateWeight() to update ._effectiveWeight
  25800. this._updateWeight( time );
  25801. return;
  25802. }
  25803. var startTime = this._startTime;
  25804. if ( startTime !== null ) {
  25805. // check for scheduled start of action
  25806. var timeRunning = ( time - startTime ) * timeDirection;
  25807. if ( timeRunning < 0 || timeDirection === 0 ) {
  25808. return; // yet to come / don't decide when delta = 0
  25809. }
  25810. // start
  25811. this._startTime = null; // unschedule
  25812. deltaTime = timeDirection * timeRunning;
  25813. }
  25814. // apply time scale and advance time
  25815. deltaTime *= this._updateTimeScale( time );
  25816. var clipTime = this._updateTime( deltaTime );
  25817. // note: _updateTime may disable the action resulting in
  25818. // an effective weight of 0
  25819. var weight = this._updateWeight( time );
  25820. if ( weight > 0 ) {
  25821. var interpolants = this._interpolants;
  25822. var propertyMixers = this._propertyBindings;
  25823. for ( var j = 0, m = interpolants.length; j !== m; ++ j ) {
  25824. interpolants[ j ].evaluate( clipTime );
  25825. propertyMixers[ j ].accumulate( accuIndex, weight );
  25826. }
  25827. }
  25828. },
  25829. _updateWeight: function ( time ) {
  25830. var weight = 0;
  25831. if ( this.enabled ) {
  25832. weight = this.weight;
  25833. var interpolant = this._weightInterpolant;
  25834. if ( interpolant !== null ) {
  25835. var interpolantValue = interpolant.evaluate( time )[ 0 ];
  25836. weight *= interpolantValue;
  25837. if ( time > interpolant.parameterPositions[ 1 ] ) {
  25838. this.stopFading();
  25839. if ( interpolantValue === 0 ) {
  25840. // faded out, disable
  25841. this.enabled = false;
  25842. }
  25843. }
  25844. }
  25845. }
  25846. this._effectiveWeight = weight;
  25847. return weight;
  25848. },
  25849. _updateTimeScale: function ( time ) {
  25850. var timeScale = 0;
  25851. if ( ! this.paused ) {
  25852. timeScale = this.timeScale;
  25853. var interpolant = this._timeScaleInterpolant;
  25854. if ( interpolant !== null ) {
  25855. var interpolantValue = interpolant.evaluate( time )[ 0 ];
  25856. timeScale *= interpolantValue;
  25857. if ( time > interpolant.parameterPositions[ 1 ] ) {
  25858. this.stopWarping();
  25859. if ( timeScale === 0 ) {
  25860. // motion has halted, pause
  25861. this.paused = true;
  25862. } else {
  25863. // warp done - apply final time scale
  25864. this.timeScale = timeScale;
  25865. }
  25866. }
  25867. }
  25868. }
  25869. this._effectiveTimeScale = timeScale;
  25870. return timeScale;
  25871. },
  25872. _updateTime: function ( deltaTime ) {
  25873. var time = this.time + deltaTime;
  25874. var duration = this._clip.duration;
  25875. var loop = this.loop;
  25876. var loopCount = this._loopCount;
  25877. var pingPong = ( loop === LoopPingPong );
  25878. if ( deltaTime === 0 ) {
  25879. if ( loopCount === - 1 ) return time;
  25880. return ( pingPong && ( loopCount & 1 ) === 1 ) ? duration - time : time;
  25881. }
  25882. if ( loop === LoopOnce ) {
  25883. if ( loopCount === - 1 ) {
  25884. // just started
  25885. this._loopCount = 0;
  25886. this._setEndings( true, true, false );
  25887. }
  25888. handle_stop: {
  25889. if ( time >= duration ) {
  25890. time = duration;
  25891. } else if ( time < 0 ) {
  25892. time = 0;
  25893. } else {
  25894. this.time = time;
  25895. break handle_stop;
  25896. }
  25897. if ( this.clampWhenFinished ) this.paused = true;
  25898. else this.enabled = false;
  25899. this.time = time;
  25900. this._mixer.dispatchEvent( {
  25901. type: 'finished', action: this,
  25902. direction: deltaTime < 0 ? - 1 : 1
  25903. } );
  25904. }
  25905. } else { // repetitive Repeat or PingPong
  25906. if ( loopCount === - 1 ) {
  25907. // just started
  25908. if ( deltaTime >= 0 ) {
  25909. loopCount = 0;
  25910. this._setEndings( true, this.repetitions === 0, pingPong );
  25911. } else {
  25912. // when looping in reverse direction, the initial
  25913. // transition through zero counts as a repetition,
  25914. // so leave loopCount at -1
  25915. this._setEndings( this.repetitions === 0, true, pingPong );
  25916. }
  25917. }
  25918. if ( time >= duration || time < 0 ) {
  25919. // wrap around
  25920. var loopDelta = Math.floor( time / duration ); // signed
  25921. time -= duration * loopDelta;
  25922. loopCount += Math.abs( loopDelta );
  25923. var pending = this.repetitions - loopCount;
  25924. if ( pending <= 0 ) {
  25925. // have to stop (switch state, clamp time, fire event)
  25926. if ( this.clampWhenFinished ) this.paused = true;
  25927. else this.enabled = false;
  25928. time = deltaTime > 0 ? duration : 0;
  25929. this.time = time;
  25930. this._mixer.dispatchEvent( {
  25931. type: 'finished', action: this,
  25932. direction: deltaTime > 0 ? 1 : - 1
  25933. } );
  25934. } else {
  25935. // keep running
  25936. if ( pending === 1 ) {
  25937. // entering the last round
  25938. var atStart = deltaTime < 0;
  25939. this._setEndings( atStart, ! atStart, pingPong );
  25940. } else {
  25941. this._setEndings( false, false, pingPong );
  25942. }
  25943. this._loopCount = loopCount;
  25944. this.time = time;
  25945. this._mixer.dispatchEvent( {
  25946. type: 'loop', action: this, loopDelta: loopDelta
  25947. } );
  25948. }
  25949. } else {
  25950. this.time = time;
  25951. }
  25952. if ( pingPong && ( loopCount & 1 ) === 1 ) {
  25953. // invert time for the "pong round"
  25954. return duration - time;
  25955. }
  25956. }
  25957. return time;
  25958. },
  25959. _setEndings: function ( atStart, atEnd, pingPong ) {
  25960. var settings = this._interpolantSettings;
  25961. if ( pingPong ) {
  25962. settings.endingStart = ZeroSlopeEnding;
  25963. settings.endingEnd = ZeroSlopeEnding;
  25964. } else {
  25965. // assuming for LoopOnce atStart == atEnd == true
  25966. if ( atStart ) {
  25967. settings.endingStart = this.zeroSlopeAtStart ? ZeroSlopeEnding : ZeroCurvatureEnding;
  25968. } else {
  25969. settings.endingStart = WrapAroundEnding;
  25970. }
  25971. if ( atEnd ) {
  25972. settings.endingEnd = this.zeroSlopeAtEnd ? ZeroSlopeEnding : ZeroCurvatureEnding;
  25973. } else {
  25974. settings.endingEnd = WrapAroundEnding;
  25975. }
  25976. }
  25977. },
  25978. _scheduleFading: function ( duration, weightNow, weightThen ) {
  25979. var mixer = this._mixer, now = mixer.time,
  25980. interpolant = this._weightInterpolant;
  25981. if ( interpolant === null ) {
  25982. interpolant = mixer._lendControlInterpolant();
  25983. this._weightInterpolant = interpolant;
  25984. }
  25985. var times = interpolant.parameterPositions,
  25986. values = interpolant.sampleValues;
  25987. times[ 0 ] = now;
  25988. values[ 0 ] = weightNow;
  25989. times[ 1 ] = now + duration;
  25990. values[ 1 ] = weightThen;
  25991. return this;
  25992. }
  25993. } );
  25994. /**
  25995. *
  25996. * Player for AnimationClips.
  25997. *
  25998. *
  25999. * @author Ben Houston / http://clara.io/
  26000. * @author David Sarno / http://lighthaus.us/
  26001. * @author tschw
  26002. */
  26003. function AnimationMixer( root ) {
  26004. this._root = root;
  26005. this._initMemoryManager();
  26006. this._accuIndex = 0;
  26007. this.time = 0;
  26008. this.timeScale = 1.0;
  26009. }
  26010. AnimationMixer.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  26011. constructor: AnimationMixer,
  26012. _bindAction: function ( action, prototypeAction ) {
  26013. var root = action._localRoot || this._root,
  26014. tracks = action._clip.tracks,
  26015. nTracks = tracks.length,
  26016. bindings = action._propertyBindings,
  26017. interpolants = action._interpolants,
  26018. rootUuid = root.uuid,
  26019. bindingsByRoot = this._bindingsByRootAndName,
  26020. bindingsByName = bindingsByRoot[ rootUuid ];
  26021. if ( bindingsByName === undefined ) {
  26022. bindingsByName = {};
  26023. bindingsByRoot[ rootUuid ] = bindingsByName;
  26024. }
  26025. for ( var i = 0; i !== nTracks; ++ i ) {
  26026. var track = tracks[ i ],
  26027. trackName = track.name,
  26028. binding = bindingsByName[ trackName ];
  26029. if ( binding !== undefined ) {
  26030. bindings[ i ] = binding;
  26031. } else {
  26032. binding = bindings[ i ];
  26033. if ( binding !== undefined ) {
  26034. // existing binding, make sure the cache knows
  26035. if ( binding._cacheIndex === null ) {
  26036. ++ binding.referenceCount;
  26037. this._addInactiveBinding( binding, rootUuid, trackName );
  26038. }
  26039. continue;
  26040. }
  26041. var path = prototypeAction && prototypeAction.
  26042. _propertyBindings[ i ].binding.parsedPath;
  26043. binding = new PropertyMixer(
  26044. PropertyBinding.create( root, trackName, path ),
  26045. track.ValueTypeName, track.getValueSize() );
  26046. ++ binding.referenceCount;
  26047. this._addInactiveBinding( binding, rootUuid, trackName );
  26048. bindings[ i ] = binding;
  26049. }
  26050. interpolants[ i ].resultBuffer = binding.buffer;
  26051. }
  26052. },
  26053. _activateAction: function ( action ) {
  26054. if ( ! this._isActiveAction( action ) ) {
  26055. if ( action._cacheIndex === null ) {
  26056. // this action has been forgotten by the cache, but the user
  26057. // appears to be still using it -> rebind
  26058. var rootUuid = ( action._localRoot || this._root ).uuid,
  26059. clipUuid = action._clip.uuid,
  26060. actionsForClip = this._actionsByClip[ clipUuid ];
  26061. this._bindAction( action,
  26062. actionsForClip && actionsForClip.knownActions[ 0 ] );
  26063. this._addInactiveAction( action, clipUuid, rootUuid );
  26064. }
  26065. var bindings = action._propertyBindings;
  26066. // increment reference counts / sort out state
  26067. for ( var i = 0, n = bindings.length; i !== n; ++ i ) {
  26068. var binding = bindings[ i ];
  26069. if ( binding.useCount ++ === 0 ) {
  26070. this._lendBinding( binding );
  26071. binding.saveOriginalState();
  26072. }
  26073. }
  26074. this._lendAction( action );
  26075. }
  26076. },
  26077. _deactivateAction: function ( action ) {
  26078. if ( this._isActiveAction( action ) ) {
  26079. var bindings = action._propertyBindings;
  26080. // decrement reference counts / sort out state
  26081. for ( var i = 0, n = bindings.length; i !== n; ++ i ) {
  26082. var binding = bindings[ i ];
  26083. if ( -- binding.useCount === 0 ) {
  26084. binding.restoreOriginalState();
  26085. this._takeBackBinding( binding );
  26086. }
  26087. }
  26088. this._takeBackAction( action );
  26089. }
  26090. },
  26091. // Memory manager
  26092. _initMemoryManager: function () {
  26093. this._actions = []; // 'nActiveActions' followed by inactive ones
  26094. this._nActiveActions = 0;
  26095. this._actionsByClip = {};
  26096. // inside:
  26097. // {
  26098. // knownActions: Array< AnimationAction > - used as prototypes
  26099. // actionByRoot: AnimationAction - lookup
  26100. // }
  26101. this._bindings = []; // 'nActiveBindings' followed by inactive ones
  26102. this._nActiveBindings = 0;
  26103. this._bindingsByRootAndName = {}; // inside: Map< name, PropertyMixer >
  26104. this._controlInterpolants = []; // same game as above
  26105. this._nActiveControlInterpolants = 0;
  26106. var scope = this;
  26107. this.stats = {
  26108. actions: {
  26109. get total() {
  26110. return scope._actions.length;
  26111. },
  26112. get inUse() {
  26113. return scope._nActiveActions;
  26114. }
  26115. },
  26116. bindings: {
  26117. get total() {
  26118. return scope._bindings.length;
  26119. },
  26120. get inUse() {
  26121. return scope._nActiveBindings;
  26122. }
  26123. },
  26124. controlInterpolants: {
  26125. get total() {
  26126. return scope._controlInterpolants.length;
  26127. },
  26128. get inUse() {
  26129. return scope._nActiveControlInterpolants;
  26130. }
  26131. }
  26132. };
  26133. },
  26134. // Memory management for AnimationAction objects
  26135. _isActiveAction: function ( action ) {
  26136. var index = action._cacheIndex;
  26137. return index !== null && index < this._nActiveActions;
  26138. },
  26139. _addInactiveAction: function ( action, clipUuid, rootUuid ) {
  26140. var actions = this._actions,
  26141. actionsByClip = this._actionsByClip,
  26142. actionsForClip = actionsByClip[ clipUuid ];
  26143. if ( actionsForClip === undefined ) {
  26144. actionsForClip = {
  26145. knownActions: [ action ],
  26146. actionByRoot: {}
  26147. };
  26148. action._byClipCacheIndex = 0;
  26149. actionsByClip[ clipUuid ] = actionsForClip;
  26150. } else {
  26151. var knownActions = actionsForClip.knownActions;
  26152. action._byClipCacheIndex = knownActions.length;
  26153. knownActions.push( action );
  26154. }
  26155. action._cacheIndex = actions.length;
  26156. actions.push( action );
  26157. actionsForClip.actionByRoot[ rootUuid ] = action;
  26158. },
  26159. _removeInactiveAction: function ( action ) {
  26160. var actions = this._actions,
  26161. lastInactiveAction = actions[ actions.length - 1 ],
  26162. cacheIndex = action._cacheIndex;
  26163. lastInactiveAction._cacheIndex = cacheIndex;
  26164. actions[ cacheIndex ] = lastInactiveAction;
  26165. actions.pop();
  26166. action._cacheIndex = null;
  26167. var clipUuid = action._clip.uuid,
  26168. actionsByClip = this._actionsByClip,
  26169. actionsForClip = actionsByClip[ clipUuid ],
  26170. knownActionsForClip = actionsForClip.knownActions,
  26171. lastKnownAction =
  26172. knownActionsForClip[ knownActionsForClip.length - 1 ],
  26173. byClipCacheIndex = action._byClipCacheIndex;
  26174. lastKnownAction._byClipCacheIndex = byClipCacheIndex;
  26175. knownActionsForClip[ byClipCacheIndex ] = lastKnownAction;
  26176. knownActionsForClip.pop();
  26177. action._byClipCacheIndex = null;
  26178. var actionByRoot = actionsForClip.actionByRoot,
  26179. rootUuid = ( action._localRoot || this._root ).uuid;
  26180. delete actionByRoot[ rootUuid ];
  26181. if ( knownActionsForClip.length === 0 ) {
  26182. delete actionsByClip[ clipUuid ];
  26183. }
  26184. this._removeInactiveBindingsForAction( action );
  26185. },
  26186. _removeInactiveBindingsForAction: function ( action ) {
  26187. var bindings = action._propertyBindings;
  26188. for ( var i = 0, n = bindings.length; i !== n; ++ i ) {
  26189. var binding = bindings[ i ];
  26190. if ( -- binding.referenceCount === 0 ) {
  26191. this._removeInactiveBinding( binding );
  26192. }
  26193. }
  26194. },
  26195. _lendAction: function ( action ) {
  26196. // [ active actions | inactive actions ]
  26197. // [ active actions >| inactive actions ]
  26198. // s a
  26199. // <-swap->
  26200. // a s
  26201. var actions = this._actions,
  26202. prevIndex = action._cacheIndex,
  26203. lastActiveIndex = this._nActiveActions ++,
  26204. firstInactiveAction = actions[ lastActiveIndex ];
  26205. action._cacheIndex = lastActiveIndex;
  26206. actions[ lastActiveIndex ] = action;
  26207. firstInactiveAction._cacheIndex = prevIndex;
  26208. actions[ prevIndex ] = firstInactiveAction;
  26209. },
  26210. _takeBackAction: function ( action ) {
  26211. // [ active actions | inactive actions ]
  26212. // [ active actions |< inactive actions ]
  26213. // a s
  26214. // <-swap->
  26215. // s a
  26216. var actions = this._actions,
  26217. prevIndex = action._cacheIndex,
  26218. firstInactiveIndex = -- this._nActiveActions,
  26219. lastActiveAction = actions[ firstInactiveIndex ];
  26220. action._cacheIndex = firstInactiveIndex;
  26221. actions[ firstInactiveIndex ] = action;
  26222. lastActiveAction._cacheIndex = prevIndex;
  26223. actions[ prevIndex ] = lastActiveAction;
  26224. },
  26225. // Memory management for PropertyMixer objects
  26226. _addInactiveBinding: function ( binding, rootUuid, trackName ) {
  26227. var bindingsByRoot = this._bindingsByRootAndName,
  26228. bindingByName = bindingsByRoot[ rootUuid ],
  26229. bindings = this._bindings;
  26230. if ( bindingByName === undefined ) {
  26231. bindingByName = {};
  26232. bindingsByRoot[ rootUuid ] = bindingByName;
  26233. }
  26234. bindingByName[ trackName ] = binding;
  26235. binding._cacheIndex = bindings.length;
  26236. bindings.push( binding );
  26237. },
  26238. _removeInactiveBinding: function ( binding ) {
  26239. var bindings = this._bindings,
  26240. propBinding = binding.binding,
  26241. rootUuid = propBinding.rootNode.uuid,
  26242. trackName = propBinding.path,
  26243. bindingsByRoot = this._bindingsByRootAndName,
  26244. bindingByName = bindingsByRoot[ rootUuid ],
  26245. lastInactiveBinding = bindings[ bindings.length - 1 ],
  26246. cacheIndex = binding._cacheIndex;
  26247. lastInactiveBinding._cacheIndex = cacheIndex;
  26248. bindings[ cacheIndex ] = lastInactiveBinding;
  26249. bindings.pop();
  26250. delete bindingByName[ trackName ];
  26251. remove_empty_map: {
  26252. for ( var _ in bindingByName ) break remove_empty_map; // eslint-disable-line no-unused-vars
  26253. delete bindingsByRoot[ rootUuid ];
  26254. }
  26255. },
  26256. _lendBinding: function ( binding ) {
  26257. var bindings = this._bindings,
  26258. prevIndex = binding._cacheIndex,
  26259. lastActiveIndex = this._nActiveBindings ++,
  26260. firstInactiveBinding = bindings[ lastActiveIndex ];
  26261. binding._cacheIndex = lastActiveIndex;
  26262. bindings[ lastActiveIndex ] = binding;
  26263. firstInactiveBinding._cacheIndex = prevIndex;
  26264. bindings[ prevIndex ] = firstInactiveBinding;
  26265. },
  26266. _takeBackBinding: function ( binding ) {
  26267. var bindings = this._bindings,
  26268. prevIndex = binding._cacheIndex,
  26269. firstInactiveIndex = -- this._nActiveBindings,
  26270. lastActiveBinding = bindings[ firstInactiveIndex ];
  26271. binding._cacheIndex = firstInactiveIndex;
  26272. bindings[ firstInactiveIndex ] = binding;
  26273. lastActiveBinding._cacheIndex = prevIndex;
  26274. bindings[ prevIndex ] = lastActiveBinding;
  26275. },
  26276. // Memory management of Interpolants for weight and time scale
  26277. _lendControlInterpolant: function () {
  26278. var interpolants = this._controlInterpolants,
  26279. lastActiveIndex = this._nActiveControlInterpolants ++,
  26280. interpolant = interpolants[ lastActiveIndex ];
  26281. if ( interpolant === undefined ) {
  26282. interpolant = new LinearInterpolant(
  26283. new Float32Array( 2 ), new Float32Array( 2 ),
  26284. 1, this._controlInterpolantsResultBuffer );
  26285. interpolant.__cacheIndex = lastActiveIndex;
  26286. interpolants[ lastActiveIndex ] = interpolant;
  26287. }
  26288. return interpolant;
  26289. },
  26290. _takeBackControlInterpolant: function ( interpolant ) {
  26291. var interpolants = this._controlInterpolants,
  26292. prevIndex = interpolant.__cacheIndex,
  26293. firstInactiveIndex = -- this._nActiveControlInterpolants,
  26294. lastActiveInterpolant = interpolants[ firstInactiveIndex ];
  26295. interpolant.__cacheIndex = firstInactiveIndex;
  26296. interpolants[ firstInactiveIndex ] = interpolant;
  26297. lastActiveInterpolant.__cacheIndex = prevIndex;
  26298. interpolants[ prevIndex ] = lastActiveInterpolant;
  26299. },
  26300. _controlInterpolantsResultBuffer: new Float32Array( 1 ),
  26301. // return an action for a clip optionally using a custom root target
  26302. // object (this method allocates a lot of dynamic memory in case a
  26303. // previously unknown clip/root combination is specified)
  26304. clipAction: function ( clip, optionalRoot ) {
  26305. var root = optionalRoot || this._root,
  26306. rootUuid = root.uuid,
  26307. clipObject = typeof clip === 'string' ?
  26308. AnimationClip.findByName( root, clip ) : clip,
  26309. clipUuid = clipObject !== null ? clipObject.uuid : clip,
  26310. actionsForClip = this._actionsByClip[ clipUuid ],
  26311. prototypeAction = null;
  26312. if ( actionsForClip !== undefined ) {
  26313. var existingAction =
  26314. actionsForClip.actionByRoot[ rootUuid ];
  26315. if ( existingAction !== undefined ) {
  26316. return existingAction;
  26317. }
  26318. // we know the clip, so we don't have to parse all
  26319. // the bindings again but can just copy
  26320. prototypeAction = actionsForClip.knownActions[ 0 ];
  26321. // also, take the clip from the prototype action
  26322. if ( clipObject === null )
  26323. clipObject = prototypeAction._clip;
  26324. }
  26325. // clip must be known when specified via string
  26326. if ( clipObject === null ) return null;
  26327. // allocate all resources required to run it
  26328. var newAction = new AnimationAction( this, clipObject, optionalRoot );
  26329. this._bindAction( newAction, prototypeAction );
  26330. // and make the action known to the memory manager
  26331. this._addInactiveAction( newAction, clipUuid, rootUuid );
  26332. return newAction;
  26333. },
  26334. // get an existing action
  26335. existingAction: function ( clip, optionalRoot ) {
  26336. var root = optionalRoot || this._root,
  26337. rootUuid = root.uuid,
  26338. clipObject = typeof clip === 'string' ?
  26339. AnimationClip.findByName( root, clip ) : clip,
  26340. clipUuid = clipObject ? clipObject.uuid : clip,
  26341. actionsForClip = this._actionsByClip[ clipUuid ];
  26342. if ( actionsForClip !== undefined ) {
  26343. return actionsForClip.actionByRoot[ rootUuid ] || null;
  26344. }
  26345. return null;
  26346. },
  26347. // deactivates all previously scheduled actions
  26348. stopAllAction: function () {
  26349. var actions = this._actions,
  26350. nActions = this._nActiveActions,
  26351. bindings = this._bindings,
  26352. nBindings = this._nActiveBindings;
  26353. this._nActiveActions = 0;
  26354. this._nActiveBindings = 0;
  26355. for ( var i = 0; i !== nActions; ++ i ) {
  26356. actions[ i ].reset();
  26357. }
  26358. for ( var i = 0; i !== nBindings; ++ i ) {
  26359. bindings[ i ].useCount = 0;
  26360. }
  26361. return this;
  26362. },
  26363. // advance the time and update apply the animation
  26364. update: function ( deltaTime ) {
  26365. deltaTime *= this.timeScale;
  26366. var actions = this._actions,
  26367. nActions = this._nActiveActions,
  26368. time = this.time += deltaTime,
  26369. timeDirection = Math.sign( deltaTime ),
  26370. accuIndex = this._accuIndex ^= 1;
  26371. // run active actions
  26372. for ( var i = 0; i !== nActions; ++ i ) {
  26373. var action = actions[ i ];
  26374. action._update( time, deltaTime, timeDirection, accuIndex );
  26375. }
  26376. // update scene graph
  26377. var bindings = this._bindings,
  26378. nBindings = this._nActiveBindings;
  26379. for ( var i = 0; i !== nBindings; ++ i ) {
  26380. bindings[ i ].apply( accuIndex );
  26381. }
  26382. return this;
  26383. },
  26384. // return this mixer's root target object
  26385. getRoot: function () {
  26386. return this._root;
  26387. },
  26388. // free all resources specific to a particular clip
  26389. uncacheClip: function ( clip ) {
  26390. var actions = this._actions,
  26391. clipUuid = clip.uuid,
  26392. actionsByClip = this._actionsByClip,
  26393. actionsForClip = actionsByClip[ clipUuid ];
  26394. if ( actionsForClip !== undefined ) {
  26395. // note: just calling _removeInactiveAction would mess up the
  26396. // iteration state and also require updating the state we can
  26397. // just throw away
  26398. var actionsToRemove = actionsForClip.knownActions;
  26399. for ( var i = 0, n = actionsToRemove.length; i !== n; ++ i ) {
  26400. var action = actionsToRemove[ i ];
  26401. this._deactivateAction( action );
  26402. var cacheIndex = action._cacheIndex,
  26403. lastInactiveAction = actions[ actions.length - 1 ];
  26404. action._cacheIndex = null;
  26405. action._byClipCacheIndex = null;
  26406. lastInactiveAction._cacheIndex = cacheIndex;
  26407. actions[ cacheIndex ] = lastInactiveAction;
  26408. actions.pop();
  26409. this._removeInactiveBindingsForAction( action );
  26410. }
  26411. delete actionsByClip[ clipUuid ];
  26412. }
  26413. },
  26414. // free all resources specific to a particular root target object
  26415. uncacheRoot: function ( root ) {
  26416. var rootUuid = root.uuid,
  26417. actionsByClip = this._actionsByClip;
  26418. for ( var clipUuid in actionsByClip ) {
  26419. var actionByRoot = actionsByClip[ clipUuid ].actionByRoot,
  26420. action = actionByRoot[ rootUuid ];
  26421. if ( action !== undefined ) {
  26422. this._deactivateAction( action );
  26423. this._removeInactiveAction( action );
  26424. }
  26425. }
  26426. var bindingsByRoot = this._bindingsByRootAndName,
  26427. bindingByName = bindingsByRoot[ rootUuid ];
  26428. if ( bindingByName !== undefined ) {
  26429. for ( var trackName in bindingByName ) {
  26430. var binding = bindingByName[ trackName ];
  26431. binding.restoreOriginalState();
  26432. this._removeInactiveBinding( binding );
  26433. }
  26434. }
  26435. },
  26436. // remove a targeted clip from the cache
  26437. uncacheAction: function ( clip, optionalRoot ) {
  26438. var action = this.existingAction( clip, optionalRoot );
  26439. if ( action !== null ) {
  26440. this._deactivateAction( action );
  26441. this._removeInactiveAction( action );
  26442. }
  26443. }
  26444. } );
  26445. /**
  26446. * @author mrdoob / http://mrdoob.com/
  26447. */
  26448. function Uniform( value ) {
  26449. if ( typeof value === 'string' ) {
  26450. console.warn( 'THREE.Uniform: Type parameter is no longer needed.' );
  26451. value = arguments[ 1 ];
  26452. }
  26453. this.value = value;
  26454. }
  26455. Uniform.prototype.clone = function () {
  26456. return new Uniform( this.value.clone === undefined ? this.value : this.value.clone() );
  26457. };
  26458. /**
  26459. * @author benaadams / https://twitter.com/ben_a_adams
  26460. */
  26461. function InstancedInterleavedBuffer( array, stride, meshPerAttribute ) {
  26462. InterleavedBuffer.call( this, array, stride );
  26463. this.meshPerAttribute = meshPerAttribute || 1;
  26464. }
  26465. InstancedInterleavedBuffer.prototype = Object.assign( Object.create( InterleavedBuffer.prototype ), {
  26466. constructor: InstancedInterleavedBuffer,
  26467. isInstancedInterleavedBuffer: true,
  26468. copy: function ( source ) {
  26469. InterleavedBuffer.prototype.copy.call( this, source );
  26470. this.meshPerAttribute = source.meshPerAttribute;
  26471. return this;
  26472. }
  26473. } );
  26474. /**
  26475. * @author mrdoob / http://mrdoob.com/
  26476. * @author bhouston / http://clara.io/
  26477. * @author stephomi / http://stephaneginier.com/
  26478. */
  26479. function Raycaster( origin, direction, near, far ) {
  26480. this.ray = new Ray( origin, direction );
  26481. // direction is assumed to be normalized (for accurate distance calculations)
  26482. this.near = near || 0;
  26483. this.far = far || Infinity;
  26484. this.params = {
  26485. Mesh: {},
  26486. Line: {},
  26487. LOD: {},
  26488. Points: { threshold: 1 },
  26489. Sprite: {}
  26490. };
  26491. Object.defineProperties( this.params, {
  26492. PointCloud: {
  26493. get: function () {
  26494. console.warn( 'THREE.Raycaster: params.PointCloud has been renamed to params.Points.' );
  26495. return this.Points;
  26496. }
  26497. }
  26498. } );
  26499. }
  26500. function ascSort( a, b ) {
  26501. return a.distance - b.distance;
  26502. }
  26503. function intersectObject( object, raycaster, intersects, recursive ) {
  26504. if ( object.visible === false ) return;
  26505. object.raycast( raycaster, intersects );
  26506. if ( recursive === true ) {
  26507. var children = object.children;
  26508. for ( var i = 0, l = children.length; i < l; i ++ ) {
  26509. intersectObject( children[ i ], raycaster, intersects, true );
  26510. }
  26511. }
  26512. }
  26513. Object.assign( Raycaster.prototype, {
  26514. linePrecision: 1,
  26515. set: function ( origin, direction ) {
  26516. // direction is assumed to be normalized (for accurate distance calculations)
  26517. this.ray.set( origin, direction );
  26518. },
  26519. setFromCamera: function ( coords, camera ) {
  26520. if ( ( camera && camera.isPerspectiveCamera ) ) {
  26521. this.ray.origin.setFromMatrixPosition( camera.matrixWorld );
  26522. this.ray.direction.set( coords.x, coords.y, 0.5 ).unproject( camera ).sub( this.ray.origin ).normalize();
  26523. } else if ( ( camera && camera.isOrthographicCamera ) ) {
  26524. this.ray.origin.set( coords.x, coords.y, ( camera.near + camera.far ) / ( camera.near - camera.far ) ).unproject( camera ); // set origin in plane of camera
  26525. this.ray.direction.set( 0, 0, - 1 ).transformDirection( camera.matrixWorld );
  26526. } else {
  26527. console.error( 'THREE.Raycaster: Unsupported camera type.' );
  26528. }
  26529. },
  26530. intersectObject: function ( object, recursive, optionalTarget ) {
  26531. var intersects = optionalTarget || [];
  26532. intersectObject( object, this, intersects, recursive );
  26533. intersects.sort( ascSort );
  26534. return intersects;
  26535. },
  26536. intersectObjects: function ( objects, recursive, optionalTarget ) {
  26537. var intersects = optionalTarget || [];
  26538. if ( Array.isArray( objects ) === false ) {
  26539. console.warn( 'THREE.Raycaster.intersectObjects: objects is not an Array.' );
  26540. return intersects;
  26541. }
  26542. for ( var i = 0, l = objects.length; i < l; i ++ ) {
  26543. intersectObject( objects[ i ], this, intersects, recursive );
  26544. }
  26545. intersects.sort( ascSort );
  26546. return intersects;
  26547. }
  26548. } );
  26549. /**
  26550. * @author bhouston / http://clara.io
  26551. * @author WestLangley / http://github.com/WestLangley
  26552. *
  26553. * Ref: https://en.wikipedia.org/wiki/Spherical_coordinate_system
  26554. *
  26555. * The polar angle (phi) is measured from the positive y-axis. The positive y-axis is up.
  26556. * The azimuthal angle (theta) is measured from the positive z-axiz.
  26557. */
  26558. function Spherical( radius, phi, theta ) {
  26559. this.radius = ( radius !== undefined ) ? radius : 1.0;
  26560. this.phi = ( phi !== undefined ) ? phi : 0; // polar angle
  26561. this.theta = ( theta !== undefined ) ? theta : 0; // azimuthal angle
  26562. return this;
  26563. }
  26564. Object.assign( Spherical.prototype, {
  26565. set: function ( radius, phi, theta ) {
  26566. this.radius = radius;
  26567. this.phi = phi;
  26568. this.theta = theta;
  26569. return this;
  26570. },
  26571. clone: function () {
  26572. return new this.constructor().copy( this );
  26573. },
  26574. copy: function ( other ) {
  26575. this.radius = other.radius;
  26576. this.phi = other.phi;
  26577. this.theta = other.theta;
  26578. return this;
  26579. },
  26580. // restrict phi to be betwee EPS and PI-EPS
  26581. makeSafe: function () {
  26582. var EPS = 0.000001;
  26583. this.phi = Math.max( EPS, Math.min( Math.PI - EPS, this.phi ) );
  26584. return this;
  26585. },
  26586. setFromVector3: function ( v ) {
  26587. return this.setFromCartesianCoords( v.x, v.y, v.z );
  26588. },
  26589. setFromCartesianCoords: function ( x, y, z ) {
  26590. this.radius = Math.sqrt( x * x + y * y + z * z );
  26591. if ( this.radius === 0 ) {
  26592. this.theta = 0;
  26593. this.phi = 0;
  26594. } else {
  26595. this.theta = Math.atan2( x, z );
  26596. this.phi = Math.acos( _Math.clamp( y / this.radius, - 1, 1 ) );
  26597. }
  26598. return this;
  26599. }
  26600. } );
  26601. /**
  26602. * @author Mugen87 / https://github.com/Mugen87
  26603. *
  26604. * Ref: https://en.wikipedia.org/wiki/Cylindrical_coordinate_system
  26605. *
  26606. */
  26607. function Cylindrical( radius, theta, y ) {
  26608. this.radius = ( radius !== undefined ) ? radius : 1.0; // distance from the origin to a point in the x-z plane
  26609. this.theta = ( theta !== undefined ) ? theta : 0; // counterclockwise angle in the x-z plane measured in radians from the positive z-axis
  26610. this.y = ( y !== undefined ) ? y : 0; // height above the x-z plane
  26611. return this;
  26612. }
  26613. Object.assign( Cylindrical.prototype, {
  26614. set: function ( radius, theta, y ) {
  26615. this.radius = radius;
  26616. this.theta = theta;
  26617. this.y = y;
  26618. return this;
  26619. },
  26620. clone: function () {
  26621. return new this.constructor().copy( this );
  26622. },
  26623. copy: function ( other ) {
  26624. this.radius = other.radius;
  26625. this.theta = other.theta;
  26626. this.y = other.y;
  26627. return this;
  26628. },
  26629. setFromVector3: function ( v ) {
  26630. return this.setFromCartesianCoords( v.x, v.y, v.z );
  26631. },
  26632. setFromCartesianCoords: function ( x, y, z ) {
  26633. this.radius = Math.sqrt( x * x + z * z );
  26634. this.theta = Math.atan2( x, z );
  26635. this.y = y;
  26636. return this;
  26637. }
  26638. } );
  26639. /**
  26640. * @author bhouston / http://clara.io
  26641. */
  26642. function Box2( min, max ) {
  26643. this.min = ( min !== undefined ) ? min : new Vector2( + Infinity, + Infinity );
  26644. this.max = ( max !== undefined ) ? max : new Vector2( - Infinity, - Infinity );
  26645. }
  26646. Object.assign( Box2.prototype, {
  26647. set: function ( min, max ) {
  26648. this.min.copy( min );
  26649. this.max.copy( max );
  26650. return this;
  26651. },
  26652. setFromPoints: function ( points ) {
  26653. this.makeEmpty();
  26654. for ( var i = 0, il = points.length; i < il; i ++ ) {
  26655. this.expandByPoint( points[ i ] );
  26656. }
  26657. return this;
  26658. },
  26659. setFromCenterAndSize: function () {
  26660. var v1 = new Vector2();
  26661. return function setFromCenterAndSize( center, size ) {
  26662. var halfSize = v1.copy( size ).multiplyScalar( 0.5 );
  26663. this.min.copy( center ).sub( halfSize );
  26664. this.max.copy( center ).add( halfSize );
  26665. return this;
  26666. };
  26667. }(),
  26668. clone: function () {
  26669. return new this.constructor().copy( this );
  26670. },
  26671. copy: function ( box ) {
  26672. this.min.copy( box.min );
  26673. this.max.copy( box.max );
  26674. return this;
  26675. },
  26676. makeEmpty: function () {
  26677. this.min.x = this.min.y = + Infinity;
  26678. this.max.x = this.max.y = - Infinity;
  26679. return this;
  26680. },
  26681. isEmpty: function () {
  26682. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  26683. return ( this.max.x < this.min.x ) || ( this.max.y < this.min.y );
  26684. },
  26685. getCenter: function ( target ) {
  26686. if ( target === undefined ) {
  26687. console.warn( 'THREE.Box2: .getCenter() target is now required' );
  26688. target = new Vector2();
  26689. }
  26690. return this.isEmpty() ? target.set( 0, 0 ) : target.addVectors( this.min, this.max ).multiplyScalar( 0.5 );
  26691. },
  26692. getSize: function ( target ) {
  26693. if ( target === undefined ) {
  26694. console.warn( 'THREE.Box2: .getSize() target is now required' );
  26695. target = new Vector2();
  26696. }
  26697. return this.isEmpty() ? target.set( 0, 0 ) : target.subVectors( this.max, this.min );
  26698. },
  26699. expandByPoint: function ( point ) {
  26700. this.min.min( point );
  26701. this.max.max( point );
  26702. return this;
  26703. },
  26704. expandByVector: function ( vector ) {
  26705. this.min.sub( vector );
  26706. this.max.add( vector );
  26707. return this;
  26708. },
  26709. expandByScalar: function ( scalar ) {
  26710. this.min.addScalar( - scalar );
  26711. this.max.addScalar( scalar );
  26712. return this;
  26713. },
  26714. containsPoint: function ( point ) {
  26715. return point.x < this.min.x || point.x > this.max.x ||
  26716. point.y < this.min.y || point.y > this.max.y ? false : true;
  26717. },
  26718. containsBox: function ( box ) {
  26719. return this.min.x <= box.min.x && box.max.x <= this.max.x &&
  26720. this.min.y <= box.min.y && box.max.y <= this.max.y;
  26721. },
  26722. getParameter: function ( point, target ) {
  26723. // This can potentially have a divide by zero if the box
  26724. // has a size dimension of 0.
  26725. if ( target === undefined ) {
  26726. console.warn( 'THREE.Box2: .getParameter() target is now required' );
  26727. target = new Vector2();
  26728. }
  26729. return target.set(
  26730. ( point.x - this.min.x ) / ( this.max.x - this.min.x ),
  26731. ( point.y - this.min.y ) / ( this.max.y - this.min.y )
  26732. );
  26733. },
  26734. intersectsBox: function ( box ) {
  26735. // using 4 splitting planes to rule out intersections
  26736. return box.max.x < this.min.x || box.min.x > this.max.x ||
  26737. box.max.y < this.min.y || box.min.y > this.max.y ? false : true;
  26738. },
  26739. clampPoint: function ( point, target ) {
  26740. if ( target === undefined ) {
  26741. console.warn( 'THREE.Box2: .clampPoint() target is now required' );
  26742. target = new Vector2();
  26743. }
  26744. return target.copy( point ).clamp( this.min, this.max );
  26745. },
  26746. distanceToPoint: function () {
  26747. var v1 = new Vector2();
  26748. return function distanceToPoint( point ) {
  26749. var clampedPoint = v1.copy( point ).clamp( this.min, this.max );
  26750. return clampedPoint.sub( point ).length();
  26751. };
  26752. }(),
  26753. intersect: function ( box ) {
  26754. this.min.max( box.min );
  26755. this.max.min( box.max );
  26756. return this;
  26757. },
  26758. union: function ( box ) {
  26759. this.min.min( box.min );
  26760. this.max.max( box.max );
  26761. return this;
  26762. },
  26763. translate: function ( offset ) {
  26764. this.min.add( offset );
  26765. this.max.add( offset );
  26766. return this;
  26767. },
  26768. equals: function ( box ) {
  26769. return box.min.equals( this.min ) && box.max.equals( this.max );
  26770. }
  26771. } );
  26772. /**
  26773. * @author bhouston / http://clara.io
  26774. */
  26775. function Line3( start, end ) {
  26776. this.start = ( start !== undefined ) ? start : new Vector3();
  26777. this.end = ( end !== undefined ) ? end : new Vector3();
  26778. }
  26779. Object.assign( Line3.prototype, {
  26780. set: function ( start, end ) {
  26781. this.start.copy( start );
  26782. this.end.copy( end );
  26783. return this;
  26784. },
  26785. clone: function () {
  26786. return new this.constructor().copy( this );
  26787. },
  26788. copy: function ( line ) {
  26789. this.start.copy( line.start );
  26790. this.end.copy( line.end );
  26791. return this;
  26792. },
  26793. getCenter: function ( target ) {
  26794. if ( target === undefined ) {
  26795. console.warn( 'THREE.Line3: .getCenter() target is now required' );
  26796. target = new Vector3();
  26797. }
  26798. return target.addVectors( this.start, this.end ).multiplyScalar( 0.5 );
  26799. },
  26800. delta: function ( target ) {
  26801. if ( target === undefined ) {
  26802. console.warn( 'THREE.Line3: .delta() target is now required' );
  26803. target = new Vector3();
  26804. }
  26805. return target.subVectors( this.end, this.start );
  26806. },
  26807. distanceSq: function () {
  26808. return this.start.distanceToSquared( this.end );
  26809. },
  26810. distance: function () {
  26811. return this.start.distanceTo( this.end );
  26812. },
  26813. at: function ( t, target ) {
  26814. if ( target === undefined ) {
  26815. console.warn( 'THREE.Line3: .at() target is now required' );
  26816. target = new Vector3();
  26817. }
  26818. return this.delta( target ).multiplyScalar( t ).add( this.start );
  26819. },
  26820. closestPointToPointParameter: function () {
  26821. var startP = new Vector3();
  26822. var startEnd = new Vector3();
  26823. return function closestPointToPointParameter( point, clampToLine ) {
  26824. startP.subVectors( point, this.start );
  26825. startEnd.subVectors( this.end, this.start );
  26826. var startEnd2 = startEnd.dot( startEnd );
  26827. var startEnd_startP = startEnd.dot( startP );
  26828. var t = startEnd_startP / startEnd2;
  26829. if ( clampToLine ) {
  26830. t = _Math.clamp( t, 0, 1 );
  26831. }
  26832. return t;
  26833. };
  26834. }(),
  26835. closestPointToPoint: function ( point, clampToLine, target ) {
  26836. var t = this.closestPointToPointParameter( point, clampToLine );
  26837. if ( target === undefined ) {
  26838. console.warn( 'THREE.Line3: .closestPointToPoint() target is now required' );
  26839. target = new Vector3();
  26840. }
  26841. return this.delta( target ).multiplyScalar( t ).add( this.start );
  26842. },
  26843. applyMatrix4: function ( matrix ) {
  26844. this.start.applyMatrix4( matrix );
  26845. this.end.applyMatrix4( matrix );
  26846. return this;
  26847. },
  26848. equals: function ( line ) {
  26849. return line.start.equals( this.start ) && line.end.equals( this.end );
  26850. }
  26851. } );
  26852. /**
  26853. * @author alteredq / http://alteredqualia.com/
  26854. */
  26855. function ImmediateRenderObject( material ) {
  26856. Object3D.call( this );
  26857. this.material = material;
  26858. this.render = function ( /* renderCallback */ ) {};
  26859. }
  26860. ImmediateRenderObject.prototype = Object.create( Object3D.prototype );
  26861. ImmediateRenderObject.prototype.constructor = ImmediateRenderObject;
  26862. ImmediateRenderObject.prototype.isImmediateRenderObject = true;
  26863. /**
  26864. * @author mrdoob / http://mrdoob.com/
  26865. * @author WestLangley / http://github.com/WestLangley
  26866. */
  26867. function VertexNormalsHelper( object, size, hex, linewidth ) {
  26868. this.object = object;
  26869. this.size = ( size !== undefined ) ? size : 1;
  26870. var color = ( hex !== undefined ) ? hex : 0xff0000;
  26871. var width = ( linewidth !== undefined ) ? linewidth : 1;
  26872. //
  26873. var nNormals = 0;
  26874. var objGeometry = this.object.geometry;
  26875. if ( objGeometry && objGeometry.isGeometry ) {
  26876. nNormals = objGeometry.faces.length * 3;
  26877. } else if ( objGeometry && objGeometry.isBufferGeometry ) {
  26878. nNormals = objGeometry.attributes.normal.count;
  26879. }
  26880. //
  26881. var geometry = new BufferGeometry();
  26882. var positions = new Float32BufferAttribute( nNormals * 2 * 3, 3 );
  26883. geometry.addAttribute( 'position', positions );
  26884. LineSegments.call( this, geometry, new LineBasicMaterial( { color: color, linewidth: width } ) );
  26885. //
  26886. this.matrixAutoUpdate = false;
  26887. this.update();
  26888. }
  26889. VertexNormalsHelper.prototype = Object.create( LineSegments.prototype );
  26890. VertexNormalsHelper.prototype.constructor = VertexNormalsHelper;
  26891. VertexNormalsHelper.prototype.update = ( function () {
  26892. var v1 = new Vector3();
  26893. var v2 = new Vector3();
  26894. var normalMatrix = new Matrix3();
  26895. return function update() {
  26896. var keys = [ 'a', 'b', 'c' ];
  26897. this.object.updateMatrixWorld( true );
  26898. normalMatrix.getNormalMatrix( this.object.matrixWorld );
  26899. var matrixWorld = this.object.matrixWorld;
  26900. var position = this.geometry.attributes.position;
  26901. //
  26902. var objGeometry = this.object.geometry;
  26903. if ( objGeometry && objGeometry.isGeometry ) {
  26904. var vertices = objGeometry.vertices;
  26905. var faces = objGeometry.faces;
  26906. var idx = 0;
  26907. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  26908. var face = faces[ i ];
  26909. for ( var j = 0, jl = face.vertexNormals.length; j < jl; j ++ ) {
  26910. var vertex = vertices[ face[ keys[ j ] ] ];
  26911. var normal = face.vertexNormals[ j ];
  26912. v1.copy( vertex ).applyMatrix4( matrixWorld );
  26913. v2.copy( normal ).applyMatrix3( normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
  26914. position.setXYZ( idx, v1.x, v1.y, v1.z );
  26915. idx = idx + 1;
  26916. position.setXYZ( idx, v2.x, v2.y, v2.z );
  26917. idx = idx + 1;
  26918. }
  26919. }
  26920. } else if ( objGeometry && objGeometry.isBufferGeometry ) {
  26921. var objPos = objGeometry.attributes.position;
  26922. var objNorm = objGeometry.attributes.normal;
  26923. var idx = 0;
  26924. // for simplicity, ignore index and drawcalls, and render every normal
  26925. for ( var j = 0, jl = objPos.count; j < jl; j ++ ) {
  26926. v1.set( objPos.getX( j ), objPos.getY( j ), objPos.getZ( j ) ).applyMatrix4( matrixWorld );
  26927. v2.set( objNorm.getX( j ), objNorm.getY( j ), objNorm.getZ( j ) );
  26928. v2.applyMatrix3( normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
  26929. position.setXYZ( idx, v1.x, v1.y, v1.z );
  26930. idx = idx + 1;
  26931. position.setXYZ( idx, v2.x, v2.y, v2.z );
  26932. idx = idx + 1;
  26933. }
  26934. }
  26935. position.needsUpdate = true;
  26936. };
  26937. }() );
  26938. /**
  26939. * @author alteredq / http://alteredqualia.com/
  26940. * @author mrdoob / http://mrdoob.com/
  26941. * @author WestLangley / http://github.com/WestLangley
  26942. */
  26943. function SpotLightHelper( light, color ) {
  26944. Object3D.call( this );
  26945. this.light = light;
  26946. this.light.updateMatrixWorld();
  26947. this.matrix = light.matrixWorld;
  26948. this.matrixAutoUpdate = false;
  26949. this.color = color;
  26950. var geometry = new BufferGeometry();
  26951. var positions = [
  26952. 0, 0, 0, 0, 0, 1,
  26953. 0, 0, 0, 1, 0, 1,
  26954. 0, 0, 0, - 1, 0, 1,
  26955. 0, 0, 0, 0, 1, 1,
  26956. 0, 0, 0, 0, - 1, 1
  26957. ];
  26958. for ( var i = 0, j = 1, l = 32; i < l; i ++, j ++ ) {
  26959. var p1 = ( i / l ) * Math.PI * 2;
  26960. var p2 = ( j / l ) * Math.PI * 2;
  26961. positions.push(
  26962. Math.cos( p1 ), Math.sin( p1 ), 1,
  26963. Math.cos( p2 ), Math.sin( p2 ), 1
  26964. );
  26965. }
  26966. geometry.addAttribute( 'position', new Float32BufferAttribute( positions, 3 ) );
  26967. var material = new LineBasicMaterial( { fog: false } );
  26968. this.cone = new LineSegments( geometry, material );
  26969. this.add( this.cone );
  26970. this.update();
  26971. }
  26972. SpotLightHelper.prototype = Object.create( Object3D.prototype );
  26973. SpotLightHelper.prototype.constructor = SpotLightHelper;
  26974. SpotLightHelper.prototype.dispose = function () {
  26975. this.cone.geometry.dispose();
  26976. this.cone.material.dispose();
  26977. };
  26978. SpotLightHelper.prototype.update = function () {
  26979. var vector = new Vector3();
  26980. return function update() {
  26981. this.light.updateMatrixWorld();
  26982. var coneLength = this.light.distance ? this.light.distance : 1000;
  26983. var coneWidth = coneLength * Math.tan( this.light.angle );
  26984. this.cone.scale.set( coneWidth, coneWidth, coneLength );
  26985. vector.setFromMatrixPosition( this.light.target.matrixWorld );
  26986. this.cone.lookAt( vector );
  26987. if ( this.color !== undefined ) {
  26988. this.cone.material.color.set( this.color );
  26989. } else {
  26990. this.cone.material.color.copy( this.light.color );
  26991. }
  26992. };
  26993. }();
  26994. /**
  26995. * @author Sean Griffin / http://twitter.com/sgrif
  26996. * @author Michael Guerrero / http://realitymeltdown.com
  26997. * @author mrdoob / http://mrdoob.com/
  26998. * @author ikerr / http://verold.com
  26999. * @author Mugen87 / https://github.com/Mugen87
  27000. */
  27001. function getBoneList( object ) {
  27002. var boneList = [];
  27003. if ( object && object.isBone ) {
  27004. boneList.push( object );
  27005. }
  27006. for ( var i = 0; i < object.children.length; i ++ ) {
  27007. boneList.push.apply( boneList, getBoneList( object.children[ i ] ) );
  27008. }
  27009. return boneList;
  27010. }
  27011. function SkeletonHelper( object ) {
  27012. var bones = getBoneList( object );
  27013. var geometry = new BufferGeometry();
  27014. var vertices = [];
  27015. var colors = [];
  27016. var color1 = new Color( 0, 0, 1 );
  27017. var color2 = new Color( 0, 1, 0 );
  27018. for ( var i = 0; i < bones.length; i ++ ) {
  27019. var bone = bones[ i ];
  27020. if ( bone.parent && bone.parent.isBone ) {
  27021. vertices.push( 0, 0, 0 );
  27022. vertices.push( 0, 0, 0 );
  27023. colors.push( color1.r, color1.g, color1.b );
  27024. colors.push( color2.r, color2.g, color2.b );
  27025. }
  27026. }
  27027. geometry.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  27028. geometry.addAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  27029. var material = new LineBasicMaterial( { vertexColors: VertexColors, depthTest: false, depthWrite: false, transparent: true } );
  27030. LineSegments.call( this, geometry, material );
  27031. this.root = object;
  27032. this.bones = bones;
  27033. this.matrix = object.matrixWorld;
  27034. this.matrixAutoUpdate = false;
  27035. }
  27036. SkeletonHelper.prototype = Object.create( LineSegments.prototype );
  27037. SkeletonHelper.prototype.constructor = SkeletonHelper;
  27038. SkeletonHelper.prototype.updateMatrixWorld = function () {
  27039. var vector = new Vector3();
  27040. var boneMatrix = new Matrix4();
  27041. var matrixWorldInv = new Matrix4();
  27042. return function updateMatrixWorld( force ) {
  27043. var bones = this.bones;
  27044. var geometry = this.geometry;
  27045. var position = geometry.getAttribute( 'position' );
  27046. matrixWorldInv.getInverse( this.root.matrixWorld );
  27047. for ( var i = 0, j = 0; i < bones.length; i ++ ) {
  27048. var bone = bones[ i ];
  27049. if ( bone.parent && bone.parent.isBone ) {
  27050. boneMatrix.multiplyMatrices( matrixWorldInv, bone.matrixWorld );
  27051. vector.setFromMatrixPosition( boneMatrix );
  27052. position.setXYZ( j, vector.x, vector.y, vector.z );
  27053. boneMatrix.multiplyMatrices( matrixWorldInv, bone.parent.matrixWorld );
  27054. vector.setFromMatrixPosition( boneMatrix );
  27055. position.setXYZ( j + 1, vector.x, vector.y, vector.z );
  27056. j += 2;
  27057. }
  27058. }
  27059. geometry.getAttribute( 'position' ).needsUpdate = true;
  27060. Object3D.prototype.updateMatrixWorld.call( this, force );
  27061. };
  27062. }();
  27063. /**
  27064. * @author alteredq / http://alteredqualia.com/
  27065. * @author mrdoob / http://mrdoob.com/
  27066. */
  27067. function PointLightHelper( light, sphereSize, color ) {
  27068. this.light = light;
  27069. this.light.updateMatrixWorld();
  27070. this.color = color;
  27071. var geometry = new SphereBufferGeometry( sphereSize, 4, 2 );
  27072. var material = new MeshBasicMaterial( { wireframe: true, fog: false } );
  27073. Mesh.call( this, geometry, material );
  27074. this.matrix = this.light.matrixWorld;
  27075. this.matrixAutoUpdate = false;
  27076. this.update();
  27077. /*
  27078. var distanceGeometry = new THREE.IcosahedronBufferGeometry( 1, 2 );
  27079. var distanceMaterial = new THREE.MeshBasicMaterial( { color: hexColor, fog: false, wireframe: true, opacity: 0.1, transparent: true } );
  27080. this.lightSphere = new THREE.Mesh( bulbGeometry, bulbMaterial );
  27081. this.lightDistance = new THREE.Mesh( distanceGeometry, distanceMaterial );
  27082. var d = light.distance;
  27083. if ( d === 0.0 ) {
  27084. this.lightDistance.visible = false;
  27085. } else {
  27086. this.lightDistance.scale.set( d, d, d );
  27087. }
  27088. this.add( this.lightDistance );
  27089. */
  27090. }
  27091. PointLightHelper.prototype = Object.create( Mesh.prototype );
  27092. PointLightHelper.prototype.constructor = PointLightHelper;
  27093. PointLightHelper.prototype.dispose = function () {
  27094. this.geometry.dispose();
  27095. this.material.dispose();
  27096. };
  27097. PointLightHelper.prototype.update = function () {
  27098. if ( this.color !== undefined ) {
  27099. this.material.color.set( this.color );
  27100. } else {
  27101. this.material.color.copy( this.light.color );
  27102. }
  27103. /*
  27104. var d = this.light.distance;
  27105. if ( d === 0.0 ) {
  27106. this.lightDistance.visible = false;
  27107. } else {
  27108. this.lightDistance.visible = true;
  27109. this.lightDistance.scale.set( d, d, d );
  27110. }
  27111. */
  27112. };
  27113. /**
  27114. * @author abelnation / http://github.com/abelnation
  27115. * @author Mugen87 / http://github.com/Mugen87
  27116. * @author WestLangley / http://github.com/WestLangley
  27117. *
  27118. * This helper must be added as a child of the light
  27119. */
  27120. function RectAreaLightHelper( light, color ) {
  27121. this.type = 'RectAreaLightHelper';
  27122. this.light = light;
  27123. this.color = color; // optional hardwired color for the helper
  27124. var positions = [ 1, 1, 0, - 1, 1, 0, - 1, - 1, 0, 1, - 1, 0, 1, 1, 0 ];
  27125. var geometry = new BufferGeometry();
  27126. geometry.addAttribute( 'position', new Float32BufferAttribute( positions, 3 ) );
  27127. geometry.computeBoundingSphere();
  27128. var material = new LineBasicMaterial( { fog: false } );
  27129. Line.call( this, geometry, material );
  27130. //
  27131. var positions2 = [ 1, 1, 0, - 1, 1, 0, - 1, - 1, 0, 1, 1, 0, - 1, - 1, 0, 1, - 1, 0 ];
  27132. var geometry2 = new BufferGeometry();
  27133. geometry2.addAttribute( 'position', new Float32BufferAttribute( positions2, 3 ) );
  27134. geometry2.computeBoundingSphere();
  27135. this.add( new Mesh( geometry2, new MeshBasicMaterial( { side: BackSide, fog: false } ) ) );
  27136. this.update();
  27137. }
  27138. RectAreaLightHelper.prototype = Object.create( Line.prototype );
  27139. RectAreaLightHelper.prototype.constructor = RectAreaLightHelper;
  27140. RectAreaLightHelper.prototype.update = function () {
  27141. this.scale.set( 0.5 * this.light.width, 0.5 * this.light.height, 1 );
  27142. if ( this.color !== undefined ) {
  27143. this.material.color.set( this.color );
  27144. this.children[ 0 ].material.color.set( this.color );
  27145. } else {
  27146. this.material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  27147. // prevent hue shift
  27148. var c = this.material.color;
  27149. var max = Math.max( c.r, c.g, c.b );
  27150. if ( max > 1 ) c.multiplyScalar( 1 / max );
  27151. this.children[ 0 ].material.color.copy( this.material.color );
  27152. }
  27153. };
  27154. RectAreaLightHelper.prototype.dispose = function () {
  27155. this.geometry.dispose();
  27156. this.material.dispose();
  27157. this.children[ 0 ].geometry.dispose();
  27158. this.children[ 0 ].material.dispose();
  27159. };
  27160. /**
  27161. * @author alteredq / http://alteredqualia.com/
  27162. * @author mrdoob / http://mrdoob.com/
  27163. * @author Mugen87 / https://github.com/Mugen87
  27164. */
  27165. function HemisphereLightHelper( light, size, color ) {
  27166. Object3D.call( this );
  27167. this.light = light;
  27168. this.light.updateMatrixWorld();
  27169. this.matrix = light.matrixWorld;
  27170. this.matrixAutoUpdate = false;
  27171. this.color = color;
  27172. var geometry = new OctahedronBufferGeometry( size );
  27173. geometry.rotateY( Math.PI * 0.5 );
  27174. this.material = new MeshBasicMaterial( { wireframe: true, fog: false } );
  27175. if ( this.color === undefined ) this.material.vertexColors = VertexColors;
  27176. var position = geometry.getAttribute( 'position' );
  27177. var colors = new Float32Array( position.count * 3 );
  27178. geometry.addAttribute( 'color', new BufferAttribute( colors, 3 ) );
  27179. this.add( new Mesh( geometry, this.material ) );
  27180. this.update();
  27181. }
  27182. HemisphereLightHelper.prototype = Object.create( Object3D.prototype );
  27183. HemisphereLightHelper.prototype.constructor = HemisphereLightHelper;
  27184. HemisphereLightHelper.prototype.dispose = function () {
  27185. this.children[ 0 ].geometry.dispose();
  27186. this.children[ 0 ].material.dispose();
  27187. };
  27188. HemisphereLightHelper.prototype.update = function () {
  27189. var vector = new Vector3();
  27190. var color1 = new Color();
  27191. var color2 = new Color();
  27192. return function update() {
  27193. var mesh = this.children[ 0 ];
  27194. if ( this.color !== undefined ) {
  27195. this.material.color.set( this.color );
  27196. } else {
  27197. var colors = mesh.geometry.getAttribute( 'color' );
  27198. color1.copy( this.light.color );
  27199. color2.copy( this.light.groundColor );
  27200. for ( var i = 0, l = colors.count; i < l; i ++ ) {
  27201. var color = ( i < ( l / 2 ) ) ? color1 : color2;
  27202. colors.setXYZ( i, color.r, color.g, color.b );
  27203. }
  27204. colors.needsUpdate = true;
  27205. }
  27206. mesh.lookAt( vector.setFromMatrixPosition( this.light.matrixWorld ).negate() );
  27207. };
  27208. }();
  27209. /**
  27210. * @author WestLangley / http://github.com/WestLangley
  27211. */
  27212. function LightProbeHelper( lightProbe, size ) {
  27213. this.lightProbe = lightProbe;
  27214. this.size = size;
  27215. var defines = {};
  27216. defines[ 'GAMMA_OUTPUT' ] = "";
  27217. // material
  27218. var material = new ShaderMaterial( {
  27219. defines: defines,
  27220. uniforms: {
  27221. sh: { value: this.lightProbe.sh.coefficients }, // by reference
  27222. intensity: { value: this.lightProbe.intensity }
  27223. },
  27224. vertexShader: [
  27225. 'varying vec3 vNormal;',
  27226. 'void main() {',
  27227. ' vNormal = normalize( normalMatrix * normal );',
  27228. ' gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );',
  27229. '}',
  27230. ].join( '\n' ),
  27231. fragmentShader: [
  27232. '#define RECIPROCAL_PI 0.318309886',
  27233. 'vec3 inverseTransformDirection( in vec3 normal, in mat4 matrix ) {',
  27234. ' // matrix is assumed to be orthogonal',
  27235. ' return normalize( ( vec4( normal, 0.0 ) * matrix ).xyz );',
  27236. '}',
  27237. 'vec3 linearToOutput( in vec3 a ) {',
  27238. ' #ifdef GAMMA_OUTPUT',
  27239. ' return pow( a, vec3( 1.0 / float( GAMMA_FACTOR ) ) );',
  27240. ' #else',
  27241. ' return a;',
  27242. ' #endif',
  27243. '}',
  27244. '// source: https://graphics.stanford.edu/papers/envmap/envmap.pdf',
  27245. 'vec3 shGetIrradianceAt( in vec3 normal, in vec3 shCoefficients[ 9 ] ) {',
  27246. ' // normal is assumed to have unit length',
  27247. ' float x = normal.x, y = normal.y, z = normal.z;',
  27248. ' // band 0',
  27249. ' vec3 result = shCoefficients[ 0 ] * 0.886227;',
  27250. ' // band 1',
  27251. ' result += shCoefficients[ 1 ] * 2.0 * 0.511664 * y;',
  27252. ' result += shCoefficients[ 2 ] * 2.0 * 0.511664 * z;',
  27253. ' result += shCoefficients[ 3 ] * 2.0 * 0.511664 * x;',
  27254. ' // band 2',
  27255. ' result += shCoefficients[ 4 ] * 2.0 * 0.429043 * x * y;',
  27256. ' result += shCoefficients[ 5 ] * 2.0 * 0.429043 * y * z;',
  27257. ' result += shCoefficients[ 6 ] * ( 0.743125 * z * z - 0.247708 );',
  27258. ' result += shCoefficients[ 7 ] * 2.0 * 0.429043 * x * z;',
  27259. ' result += shCoefficients[ 8 ] * 0.429043 * ( x * x - y * y );',
  27260. ' return result;',
  27261. '}',
  27262. 'uniform vec3 sh[ 9 ]; // sh coefficients',
  27263. 'uniform float intensity; // light probe intensity',
  27264. 'varying vec3 vNormal;',
  27265. 'void main() {',
  27266. ' vec3 normal = normalize( vNormal );',
  27267. ' vec3 worldNormal = inverseTransformDirection( normal, viewMatrix );',
  27268. ' vec3 irradiance = shGetIrradianceAt( worldNormal, sh );',
  27269. ' vec3 outgoingLight = RECIPROCAL_PI * irradiance * intensity;',
  27270. ' outgoingLight = linearToOutput( outgoingLight );',
  27271. ' gl_FragColor = vec4( outgoingLight, 1.0 );',
  27272. '}'
  27273. ].join( '\n' )
  27274. } );
  27275. var geometry = new SphereBufferGeometry( 1, 32, 16 );
  27276. Mesh.call( this, geometry, material );
  27277. this.onBeforeRender();
  27278. }
  27279. LightProbeHelper.prototype = Object.create( Mesh.prototype );
  27280. LightProbeHelper.prototype.constructor = LightProbeHelper;
  27281. LightProbeHelper.prototype.dispose = function () {
  27282. this.geometry.dispose();
  27283. this.material.dispose();
  27284. };
  27285. LightProbeHelper.prototype.onBeforeRender = function () {
  27286. return function update() {
  27287. this.position.copy( this.lightProbe.position );
  27288. this.scale.set( 1, 1, 1 ).multiplyScalar( this.size );
  27289. this.material.uniforms.intensity.value = this.lightProbe.intensity;
  27290. };
  27291. }();
  27292. /**
  27293. * @author mrdoob / http://mrdoob.com/
  27294. */
  27295. function GridHelper( size, divisions, color1, color2 ) {
  27296. size = size || 10;
  27297. divisions = divisions || 10;
  27298. color1 = new Color( color1 !== undefined ? color1 : 0x444444 );
  27299. color2 = new Color( color2 !== undefined ? color2 : 0x888888 );
  27300. var center = divisions / 2;
  27301. var step = size / divisions;
  27302. var halfSize = size / 2;
  27303. var vertices = [], colors = [];
  27304. for ( var i = 0, j = 0, k = - halfSize; i <= divisions; i ++, k += step ) {
  27305. vertices.push( - halfSize, 0, k, halfSize, 0, k );
  27306. vertices.push( k, 0, - halfSize, k, 0, halfSize );
  27307. var color = i === center ? color1 : color2;
  27308. color.toArray( colors, j ); j += 3;
  27309. color.toArray( colors, j ); j += 3;
  27310. color.toArray( colors, j ); j += 3;
  27311. color.toArray( colors, j ); j += 3;
  27312. }
  27313. var geometry = new BufferGeometry();
  27314. geometry.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  27315. geometry.addAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  27316. var material = new LineBasicMaterial( { vertexColors: VertexColors } );
  27317. LineSegments.call( this, geometry, material );
  27318. }
  27319. GridHelper.prototype = Object.assign( Object.create( LineSegments.prototype ), {
  27320. constructor: GridHelper,
  27321. copy: function ( source ) {
  27322. LineSegments.prototype.copy.call( this, source );
  27323. this.geometry.copy( source.geometry );
  27324. this.material.copy( source.material );
  27325. return this;
  27326. },
  27327. clone: function () {
  27328. return new this.constructor().copy( this );
  27329. }
  27330. } );
  27331. /**
  27332. * @author mrdoob / http://mrdoob.com/
  27333. * @author Mugen87 / http://github.com/Mugen87
  27334. * @author Hectate / http://www.github.com/Hectate
  27335. */
  27336. function PolarGridHelper( radius, radials, circles, divisions, color1, color2 ) {
  27337. radius = radius || 10;
  27338. radials = radials || 16;
  27339. circles = circles || 8;
  27340. divisions = divisions || 64;
  27341. color1 = new Color( color1 !== undefined ? color1 : 0x444444 );
  27342. color2 = new Color( color2 !== undefined ? color2 : 0x888888 );
  27343. var vertices = [];
  27344. var colors = [];
  27345. var x, z;
  27346. var v, i, j, r, color;
  27347. // create the radials
  27348. for ( i = 0; i <= radials; i ++ ) {
  27349. v = ( i / radials ) * ( Math.PI * 2 );
  27350. x = Math.sin( v ) * radius;
  27351. z = Math.cos( v ) * radius;
  27352. vertices.push( 0, 0, 0 );
  27353. vertices.push( x, 0, z );
  27354. color = ( i & 1 ) ? color1 : color2;
  27355. colors.push( color.r, color.g, color.b );
  27356. colors.push( color.r, color.g, color.b );
  27357. }
  27358. // create the circles
  27359. for ( i = 0; i <= circles; i ++ ) {
  27360. color = ( i & 1 ) ? color1 : color2;
  27361. r = radius - ( radius / circles * i );
  27362. for ( j = 0; j < divisions; j ++ ) {
  27363. // first vertex
  27364. v = ( j / divisions ) * ( Math.PI * 2 );
  27365. x = Math.sin( v ) * r;
  27366. z = Math.cos( v ) * r;
  27367. vertices.push( x, 0, z );
  27368. colors.push( color.r, color.g, color.b );
  27369. // second vertex
  27370. v = ( ( j + 1 ) / divisions ) * ( Math.PI * 2 );
  27371. x = Math.sin( v ) * r;
  27372. z = Math.cos( v ) * r;
  27373. vertices.push( x, 0, z );
  27374. colors.push( color.r, color.g, color.b );
  27375. }
  27376. }
  27377. var geometry = new BufferGeometry();
  27378. geometry.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  27379. geometry.addAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  27380. var material = new LineBasicMaterial( { vertexColors: VertexColors } );
  27381. LineSegments.call( this, geometry, material );
  27382. }
  27383. PolarGridHelper.prototype = Object.create( LineSegments.prototype );
  27384. PolarGridHelper.prototype.constructor = PolarGridHelper;
  27385. /**
  27386. * @author Mugen87 / http://github.com/Mugen87
  27387. */
  27388. function PositionalAudioHelper( audio, range, divisionsInnerAngle, divisionsOuterAngle ) {
  27389. this.audio = audio;
  27390. this.range = range || 1;
  27391. this.divisionsInnerAngle = divisionsInnerAngle || 16;
  27392. this.divisionsOuterAngle = divisionsOuterAngle || 2;
  27393. var geometry = new BufferGeometry();
  27394. var divisions = this.divisionsInnerAngle + this.divisionsOuterAngle * 2;
  27395. var positions = new Float32Array( ( divisions * 3 + 3 ) * 3 );
  27396. geometry.addAttribute( 'position', new BufferAttribute( positions, 3 ) );
  27397. var materialInnerAngle = new LineBasicMaterial( { color: 0x00ff00 } );
  27398. var materialOuterAngle = new LineBasicMaterial( { color: 0xffff00 } );
  27399. Line.call( this, geometry, [ materialOuterAngle, materialInnerAngle ] );
  27400. this.update();
  27401. }
  27402. PositionalAudioHelper.prototype = Object.create( Line.prototype );
  27403. PositionalAudioHelper.prototype.constructor = PositionalAudioHelper;
  27404. PositionalAudioHelper.prototype.update = function () {
  27405. var audio = this.audio;
  27406. var range = this.range;
  27407. var divisionsInnerAngle = this.divisionsInnerAngle;
  27408. var divisionsOuterAngle = this.divisionsOuterAngle;
  27409. var coneInnerAngle = _Math.degToRad( audio.panner.coneInnerAngle );
  27410. var coneOuterAngle = _Math.degToRad( audio.panner.coneOuterAngle );
  27411. var halfConeInnerAngle = coneInnerAngle / 2;
  27412. var halfConeOuterAngle = coneOuterAngle / 2;
  27413. var start = 0;
  27414. var count = 0;
  27415. var i, stride;
  27416. var geometry = this.geometry;
  27417. var positionAttribute = geometry.attributes.position;
  27418. geometry.clearGroups();
  27419. //
  27420. function generateSegment( from, to, divisions, materialIndex ) {
  27421. var step = ( to - from ) / divisions;
  27422. positionAttribute.setXYZ( start, 0, 0, 0 );
  27423. count ++;
  27424. for ( i = from; i < to; i += step ) {
  27425. stride = start + count;
  27426. positionAttribute.setXYZ( stride, Math.sin( i ) * range, 0, Math.cos( i ) * range );
  27427. positionAttribute.setXYZ( stride + 1, Math.sin( Math.min( i + step, to ) ) * range, 0, Math.cos( Math.min( i + step, to ) ) * range );
  27428. positionAttribute.setXYZ( stride + 2, 0, 0, 0 );
  27429. count += 3;
  27430. }
  27431. geometry.addGroup( start, count, materialIndex );
  27432. start += count;
  27433. count = 0;
  27434. }
  27435. //
  27436. generateSegment( - halfConeOuterAngle, - halfConeInnerAngle, divisionsOuterAngle, 0 );
  27437. generateSegment( - halfConeInnerAngle, halfConeInnerAngle, divisionsInnerAngle, 1 );
  27438. generateSegment( halfConeInnerAngle, halfConeOuterAngle, divisionsOuterAngle, 0 );
  27439. //
  27440. positionAttribute.needsUpdate = true;
  27441. if ( coneInnerAngle === coneOuterAngle ) this.material[ 0 ].visible = false;
  27442. };
  27443. PositionalAudioHelper.prototype.dispose = function () {
  27444. this.geometry.dispose();
  27445. this.material[ 0 ].dispose();
  27446. this.material[ 1 ].dispose();
  27447. };
  27448. /**
  27449. * @author mrdoob / http://mrdoob.com/
  27450. * @author WestLangley / http://github.com/WestLangley
  27451. */
  27452. function FaceNormalsHelper( object, size, hex, linewidth ) {
  27453. // FaceNormalsHelper only supports THREE.Geometry
  27454. this.object = object;
  27455. this.size = ( size !== undefined ) ? size : 1;
  27456. var color = ( hex !== undefined ) ? hex : 0xffff00;
  27457. var width = ( linewidth !== undefined ) ? linewidth : 1;
  27458. //
  27459. var nNormals = 0;
  27460. var objGeometry = this.object.geometry;
  27461. if ( objGeometry && objGeometry.isGeometry ) {
  27462. nNormals = objGeometry.faces.length;
  27463. } else {
  27464. console.warn( 'THREE.FaceNormalsHelper: only THREE.Geometry is supported. Use THREE.VertexNormalsHelper, instead.' );
  27465. }
  27466. //
  27467. var geometry = new BufferGeometry();
  27468. var positions = new Float32BufferAttribute( nNormals * 2 * 3, 3 );
  27469. geometry.addAttribute( 'position', positions );
  27470. LineSegments.call( this, geometry, new LineBasicMaterial( { color: color, linewidth: width } ) );
  27471. //
  27472. this.matrixAutoUpdate = false;
  27473. this.update();
  27474. }
  27475. FaceNormalsHelper.prototype = Object.create( LineSegments.prototype );
  27476. FaceNormalsHelper.prototype.constructor = FaceNormalsHelper;
  27477. FaceNormalsHelper.prototype.update = ( function () {
  27478. var v1 = new Vector3();
  27479. var v2 = new Vector3();
  27480. var normalMatrix = new Matrix3();
  27481. return function update() {
  27482. this.object.updateMatrixWorld( true );
  27483. normalMatrix.getNormalMatrix( this.object.matrixWorld );
  27484. var matrixWorld = this.object.matrixWorld;
  27485. var position = this.geometry.attributes.position;
  27486. //
  27487. var objGeometry = this.object.geometry;
  27488. var vertices = objGeometry.vertices;
  27489. var faces = objGeometry.faces;
  27490. var idx = 0;
  27491. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  27492. var face = faces[ i ];
  27493. var normal = face.normal;
  27494. v1.copy( vertices[ face.a ] )
  27495. .add( vertices[ face.b ] )
  27496. .add( vertices[ face.c ] )
  27497. .divideScalar( 3 )
  27498. .applyMatrix4( matrixWorld );
  27499. v2.copy( normal ).applyMatrix3( normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
  27500. position.setXYZ( idx, v1.x, v1.y, v1.z );
  27501. idx = idx + 1;
  27502. position.setXYZ( idx, v2.x, v2.y, v2.z );
  27503. idx = idx + 1;
  27504. }
  27505. position.needsUpdate = true;
  27506. };
  27507. }() );
  27508. /**
  27509. * @author alteredq / http://alteredqualia.com/
  27510. * @author mrdoob / http://mrdoob.com/
  27511. * @author WestLangley / http://github.com/WestLangley
  27512. */
  27513. function DirectionalLightHelper( light, size, color ) {
  27514. Object3D.call( this );
  27515. this.light = light;
  27516. this.light.updateMatrixWorld();
  27517. this.matrix = light.matrixWorld;
  27518. this.matrixAutoUpdate = false;
  27519. this.color = color;
  27520. if ( size === undefined ) size = 1;
  27521. var geometry = new BufferGeometry();
  27522. geometry.addAttribute( 'position', new Float32BufferAttribute( [
  27523. - size, size, 0,
  27524. size, size, 0,
  27525. size, - size, 0,
  27526. - size, - size, 0,
  27527. - size, size, 0
  27528. ], 3 ) );
  27529. var material = new LineBasicMaterial( { fog: false } );
  27530. this.lightPlane = new Line( geometry, material );
  27531. this.add( this.lightPlane );
  27532. geometry = new BufferGeometry();
  27533. geometry.addAttribute( 'position', new Float32BufferAttribute( [ 0, 0, 0, 0, 0, 1 ], 3 ) );
  27534. this.targetLine = new Line( geometry, material );
  27535. this.add( this.targetLine );
  27536. this.update();
  27537. }
  27538. DirectionalLightHelper.prototype = Object.create( Object3D.prototype );
  27539. DirectionalLightHelper.prototype.constructor = DirectionalLightHelper;
  27540. DirectionalLightHelper.prototype.dispose = function () {
  27541. this.lightPlane.geometry.dispose();
  27542. this.lightPlane.material.dispose();
  27543. this.targetLine.geometry.dispose();
  27544. this.targetLine.material.dispose();
  27545. };
  27546. DirectionalLightHelper.prototype.update = function () {
  27547. var v1 = new Vector3();
  27548. var v2 = new Vector3();
  27549. var v3 = new Vector3();
  27550. return function update() {
  27551. v1.setFromMatrixPosition( this.light.matrixWorld );
  27552. v2.setFromMatrixPosition( this.light.target.matrixWorld );
  27553. v3.subVectors( v2, v1 );
  27554. this.lightPlane.lookAt( v2 );
  27555. if ( this.color !== undefined ) {
  27556. this.lightPlane.material.color.set( this.color );
  27557. this.targetLine.material.color.set( this.color );
  27558. } else {
  27559. this.lightPlane.material.color.copy( this.light.color );
  27560. this.targetLine.material.color.copy( this.light.color );
  27561. }
  27562. this.targetLine.lookAt( v2 );
  27563. this.targetLine.scale.z = v3.length();
  27564. };
  27565. }();
  27566. /**
  27567. * @author alteredq / http://alteredqualia.com/
  27568. * @author Mugen87 / https://github.com/Mugen87
  27569. *
  27570. * - shows frustum, line of sight and up of the camera
  27571. * - suitable for fast updates
  27572. * - based on frustum visualization in lightgl.js shadowmap example
  27573. * http://evanw.github.com/lightgl.js/tests/shadowmap.html
  27574. */
  27575. function CameraHelper( camera ) {
  27576. var geometry = new BufferGeometry();
  27577. var material = new LineBasicMaterial( { color: 0xffffff, vertexColors: FaceColors } );
  27578. var vertices = [];
  27579. var colors = [];
  27580. var pointMap = {};
  27581. // colors
  27582. var colorFrustum = new Color( 0xffaa00 );
  27583. var colorCone = new Color( 0xff0000 );
  27584. var colorUp = new Color( 0x00aaff );
  27585. var colorTarget = new Color( 0xffffff );
  27586. var colorCross = new Color( 0x333333 );
  27587. // near
  27588. addLine( 'n1', 'n2', colorFrustum );
  27589. addLine( 'n2', 'n4', colorFrustum );
  27590. addLine( 'n4', 'n3', colorFrustum );
  27591. addLine( 'n3', 'n1', colorFrustum );
  27592. // far
  27593. addLine( 'f1', 'f2', colorFrustum );
  27594. addLine( 'f2', 'f4', colorFrustum );
  27595. addLine( 'f4', 'f3', colorFrustum );
  27596. addLine( 'f3', 'f1', colorFrustum );
  27597. // sides
  27598. addLine( 'n1', 'f1', colorFrustum );
  27599. addLine( 'n2', 'f2', colorFrustum );
  27600. addLine( 'n3', 'f3', colorFrustum );
  27601. addLine( 'n4', 'f4', colorFrustum );
  27602. // cone
  27603. addLine( 'p', 'n1', colorCone );
  27604. addLine( 'p', 'n2', colorCone );
  27605. addLine( 'p', 'n3', colorCone );
  27606. addLine( 'p', 'n4', colorCone );
  27607. // up
  27608. addLine( 'u1', 'u2', colorUp );
  27609. addLine( 'u2', 'u3', colorUp );
  27610. addLine( 'u3', 'u1', colorUp );
  27611. // target
  27612. addLine( 'c', 't', colorTarget );
  27613. addLine( 'p', 'c', colorCross );
  27614. // cross
  27615. addLine( 'cn1', 'cn2', colorCross );
  27616. addLine( 'cn3', 'cn4', colorCross );
  27617. addLine( 'cf1', 'cf2', colorCross );
  27618. addLine( 'cf3', 'cf4', colorCross );
  27619. function addLine( a, b, color ) {
  27620. addPoint( a, color );
  27621. addPoint( b, color );
  27622. }
  27623. function addPoint( id, color ) {
  27624. vertices.push( 0, 0, 0 );
  27625. colors.push( color.r, color.g, color.b );
  27626. if ( pointMap[ id ] === undefined ) {
  27627. pointMap[ id ] = [];
  27628. }
  27629. pointMap[ id ].push( ( vertices.length / 3 ) - 1 );
  27630. }
  27631. geometry.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  27632. geometry.addAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  27633. LineSegments.call( this, geometry, material );
  27634. this.camera = camera;
  27635. if ( this.camera.updateProjectionMatrix ) this.camera.updateProjectionMatrix();
  27636. this.matrix = camera.matrixWorld;
  27637. this.matrixAutoUpdate = false;
  27638. this.pointMap = pointMap;
  27639. this.update();
  27640. }
  27641. CameraHelper.prototype = Object.create( LineSegments.prototype );
  27642. CameraHelper.prototype.constructor = CameraHelper;
  27643. CameraHelper.prototype.update = function () {
  27644. var geometry, pointMap;
  27645. var vector = new Vector3();
  27646. var camera = new Camera();
  27647. function setPoint( point, x, y, z ) {
  27648. vector.set( x, y, z ).unproject( camera );
  27649. var points = pointMap[ point ];
  27650. if ( points !== undefined ) {
  27651. var position = geometry.getAttribute( 'position' );
  27652. for ( var i = 0, l = points.length; i < l; i ++ ) {
  27653. position.setXYZ( points[ i ], vector.x, vector.y, vector.z );
  27654. }
  27655. }
  27656. }
  27657. return function update() {
  27658. geometry = this.geometry;
  27659. pointMap = this.pointMap;
  27660. var w = 1, h = 1;
  27661. // we need just camera projection matrix inverse
  27662. // world matrix must be identity
  27663. camera.projectionMatrixInverse.copy( this.camera.projectionMatrixInverse );
  27664. // center / target
  27665. setPoint( 'c', 0, 0, - 1 );
  27666. setPoint( 't', 0, 0, 1 );
  27667. // near
  27668. setPoint( 'n1', - w, - h, - 1 );
  27669. setPoint( 'n2', w, - h, - 1 );
  27670. setPoint( 'n3', - w, h, - 1 );
  27671. setPoint( 'n4', w, h, - 1 );
  27672. // far
  27673. setPoint( 'f1', - w, - h, 1 );
  27674. setPoint( 'f2', w, - h, 1 );
  27675. setPoint( 'f3', - w, h, 1 );
  27676. setPoint( 'f4', w, h, 1 );
  27677. // up
  27678. setPoint( 'u1', w * 0.7, h * 1.1, - 1 );
  27679. setPoint( 'u2', - w * 0.7, h * 1.1, - 1 );
  27680. setPoint( 'u3', 0, h * 2, - 1 );
  27681. // cross
  27682. setPoint( 'cf1', - w, 0, 1 );
  27683. setPoint( 'cf2', w, 0, 1 );
  27684. setPoint( 'cf3', 0, - h, 1 );
  27685. setPoint( 'cf4', 0, h, 1 );
  27686. setPoint( 'cn1', - w, 0, - 1 );
  27687. setPoint( 'cn2', w, 0, - 1 );
  27688. setPoint( 'cn3', 0, - h, - 1 );
  27689. setPoint( 'cn4', 0, h, - 1 );
  27690. geometry.getAttribute( 'position' ).needsUpdate = true;
  27691. };
  27692. }();
  27693. /**
  27694. * @author mrdoob / http://mrdoob.com/
  27695. * @author Mugen87 / http://github.com/Mugen87
  27696. */
  27697. function BoxHelper( object, color ) {
  27698. this.object = object;
  27699. if ( color === undefined ) color = 0xffff00;
  27700. 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 ] );
  27701. var positions = new Float32Array( 8 * 3 );
  27702. var geometry = new BufferGeometry();
  27703. geometry.setIndex( new BufferAttribute( indices, 1 ) );
  27704. geometry.addAttribute( 'position', new BufferAttribute( positions, 3 ) );
  27705. LineSegments.call( this, geometry, new LineBasicMaterial( { color: color } ) );
  27706. this.matrixAutoUpdate = false;
  27707. this.update();
  27708. }
  27709. BoxHelper.prototype = Object.create( LineSegments.prototype );
  27710. BoxHelper.prototype.constructor = BoxHelper;
  27711. BoxHelper.prototype.update = ( function () {
  27712. var box = new Box3();
  27713. return function update( object ) {
  27714. if ( object !== undefined ) {
  27715. console.warn( 'THREE.BoxHelper: .update() has no longer arguments.' );
  27716. }
  27717. if ( this.object !== undefined ) {
  27718. box.setFromObject( this.object );
  27719. }
  27720. if ( box.isEmpty() ) return;
  27721. var min = box.min;
  27722. var max = box.max;
  27723. /*
  27724. 5____4
  27725. 1/___0/|
  27726. | 6__|_7
  27727. 2/___3/
  27728. 0: max.x, max.y, max.z
  27729. 1: min.x, max.y, max.z
  27730. 2: min.x, min.y, max.z
  27731. 3: max.x, min.y, max.z
  27732. 4: max.x, max.y, min.z
  27733. 5: min.x, max.y, min.z
  27734. 6: min.x, min.y, min.z
  27735. 7: max.x, min.y, min.z
  27736. */
  27737. var position = this.geometry.attributes.position;
  27738. var array = position.array;
  27739. array[ 0 ] = max.x; array[ 1 ] = max.y; array[ 2 ] = max.z;
  27740. array[ 3 ] = min.x; array[ 4 ] = max.y; array[ 5 ] = max.z;
  27741. array[ 6 ] = min.x; array[ 7 ] = min.y; array[ 8 ] = max.z;
  27742. array[ 9 ] = max.x; array[ 10 ] = min.y; array[ 11 ] = max.z;
  27743. array[ 12 ] = max.x; array[ 13 ] = max.y; array[ 14 ] = min.z;
  27744. array[ 15 ] = min.x; array[ 16 ] = max.y; array[ 17 ] = min.z;
  27745. array[ 18 ] = min.x; array[ 19 ] = min.y; array[ 20 ] = min.z;
  27746. array[ 21 ] = max.x; array[ 22 ] = min.y; array[ 23 ] = min.z;
  27747. position.needsUpdate = true;
  27748. this.geometry.computeBoundingSphere();
  27749. };
  27750. } )();
  27751. BoxHelper.prototype.setFromObject = function ( object ) {
  27752. this.object = object;
  27753. this.update();
  27754. return this;
  27755. };
  27756. BoxHelper.prototype.copy = function ( source ) {
  27757. LineSegments.prototype.copy.call( this, source );
  27758. this.object = source.object;
  27759. return this;
  27760. };
  27761. BoxHelper.prototype.clone = function () {
  27762. return new this.constructor().copy( this );
  27763. };
  27764. /**
  27765. * @author WestLangley / http://github.com/WestLangley
  27766. */
  27767. function Box3Helper( box, hex ) {
  27768. this.type = 'Box3Helper';
  27769. this.box = box;
  27770. var color = ( hex !== undefined ) ? hex : 0xffff00;
  27771. 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 ] );
  27772. 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 ];
  27773. var geometry = new BufferGeometry();
  27774. geometry.setIndex( new BufferAttribute( indices, 1 ) );
  27775. geometry.addAttribute( 'position', new Float32BufferAttribute( positions, 3 ) );
  27776. LineSegments.call( this, geometry, new LineBasicMaterial( { color: color } ) );
  27777. this.geometry.computeBoundingSphere();
  27778. }
  27779. Box3Helper.prototype = Object.create( LineSegments.prototype );
  27780. Box3Helper.prototype.constructor = Box3Helper;
  27781. Box3Helper.prototype.updateMatrixWorld = function ( force ) {
  27782. var box = this.box;
  27783. if ( box.isEmpty() ) return;
  27784. box.getCenter( this.position );
  27785. box.getSize( this.scale );
  27786. this.scale.multiplyScalar( 0.5 );
  27787. Object3D.prototype.updateMatrixWorld.call( this, force );
  27788. };
  27789. /**
  27790. * @author WestLangley / http://github.com/WestLangley
  27791. */
  27792. function PlaneHelper( plane, size, hex ) {
  27793. this.type = 'PlaneHelper';
  27794. this.plane = plane;
  27795. this.size = ( size === undefined ) ? 1 : size;
  27796. var color = ( hex !== undefined ) ? hex : 0xffff00;
  27797. 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 ];
  27798. var geometry = new BufferGeometry();
  27799. geometry.addAttribute( 'position', new Float32BufferAttribute( positions, 3 ) );
  27800. geometry.computeBoundingSphere();
  27801. Line.call( this, geometry, new LineBasicMaterial( { color: color } ) );
  27802. //
  27803. var positions2 = [ 1, 1, 1, - 1, 1, 1, - 1, - 1, 1, 1, 1, 1, - 1, - 1, 1, 1, - 1, 1 ];
  27804. var geometry2 = new BufferGeometry();
  27805. geometry2.addAttribute( 'position', new Float32BufferAttribute( positions2, 3 ) );
  27806. geometry2.computeBoundingSphere();
  27807. this.add( new Mesh( geometry2, new MeshBasicMaterial( { color: color, opacity: 0.2, transparent: true, depthWrite: false } ) ) );
  27808. }
  27809. PlaneHelper.prototype = Object.create( Line.prototype );
  27810. PlaneHelper.prototype.constructor = PlaneHelper;
  27811. PlaneHelper.prototype.updateMatrixWorld = function ( force ) {
  27812. var scale = - this.plane.constant;
  27813. if ( Math.abs( scale ) < 1e-8 ) scale = 1e-8; // sign does not matter
  27814. this.scale.set( 0.5 * this.size, 0.5 * this.size, scale );
  27815. this.children[ 0 ].material.side = ( scale < 0 ) ? BackSide : FrontSide; // renderer flips side when determinant < 0; flipping not wanted here
  27816. this.lookAt( this.plane.normal );
  27817. Object3D.prototype.updateMatrixWorld.call( this, force );
  27818. };
  27819. /**
  27820. * @author WestLangley / http://github.com/WestLangley
  27821. * @author zz85 / http://github.com/zz85
  27822. * @author bhouston / http://clara.io
  27823. *
  27824. * Creates an arrow for visualizing directions
  27825. *
  27826. * Parameters:
  27827. * dir - Vector3
  27828. * origin - Vector3
  27829. * length - Number
  27830. * color - color in hex value
  27831. * headLength - Number
  27832. * headWidth - Number
  27833. */
  27834. var lineGeometry, coneGeometry;
  27835. function ArrowHelper( dir, origin, length, color, headLength, headWidth ) {
  27836. // dir is assumed to be normalized
  27837. Object3D.call( this );
  27838. if ( dir === undefined ) dir = new Vector3( 0, 0, 1 );
  27839. if ( origin === undefined ) origin = new Vector3( 0, 0, 0 );
  27840. if ( length === undefined ) length = 1;
  27841. if ( color === undefined ) color = 0xffff00;
  27842. if ( headLength === undefined ) headLength = 0.2 * length;
  27843. if ( headWidth === undefined ) headWidth = 0.2 * headLength;
  27844. if ( lineGeometry === undefined ) {
  27845. lineGeometry = new BufferGeometry();
  27846. lineGeometry.addAttribute( 'position', new Float32BufferAttribute( [ 0, 0, 0, 0, 1, 0 ], 3 ) );
  27847. coneGeometry = new CylinderBufferGeometry( 0, 0.5, 1, 5, 1 );
  27848. coneGeometry.translate( 0, - 0.5, 0 );
  27849. }
  27850. this.position.copy( origin );
  27851. this.line = new Line( lineGeometry, new LineBasicMaterial( { color: color } ) );
  27852. this.line.matrixAutoUpdate = false;
  27853. this.add( this.line );
  27854. this.cone = new Mesh( coneGeometry, new MeshBasicMaterial( { color: color } ) );
  27855. this.cone.matrixAutoUpdate = false;
  27856. this.add( this.cone );
  27857. this.setDirection( dir );
  27858. this.setLength( length, headLength, headWidth );
  27859. }
  27860. ArrowHelper.prototype = Object.create( Object3D.prototype );
  27861. ArrowHelper.prototype.constructor = ArrowHelper;
  27862. ArrowHelper.prototype.setDirection = ( function () {
  27863. var axis = new Vector3();
  27864. var radians;
  27865. return function setDirection( dir ) {
  27866. // dir is assumed to be normalized
  27867. if ( dir.y > 0.99999 ) {
  27868. this.quaternion.set( 0, 0, 0, 1 );
  27869. } else if ( dir.y < - 0.99999 ) {
  27870. this.quaternion.set( 1, 0, 0, 0 );
  27871. } else {
  27872. axis.set( dir.z, 0, - dir.x ).normalize();
  27873. radians = Math.acos( dir.y );
  27874. this.quaternion.setFromAxisAngle( axis, radians );
  27875. }
  27876. };
  27877. }() );
  27878. ArrowHelper.prototype.setLength = function ( length, headLength, headWidth ) {
  27879. if ( headLength === undefined ) headLength = 0.2 * length;
  27880. if ( headWidth === undefined ) headWidth = 0.2 * headLength;
  27881. this.line.scale.set( 1, Math.max( 0, length - headLength ), 1 );
  27882. this.line.updateMatrix();
  27883. this.cone.scale.set( headWidth, headLength, headWidth );
  27884. this.cone.position.y = length;
  27885. this.cone.updateMatrix();
  27886. };
  27887. ArrowHelper.prototype.setColor = function ( color ) {
  27888. this.line.material.color.copy( color );
  27889. this.cone.material.color.copy( color );
  27890. };
  27891. ArrowHelper.prototype.copy = function ( source ) {
  27892. Object3D.prototype.copy.call( this, source, false );
  27893. this.line.copy( source.line );
  27894. this.cone.copy( source.cone );
  27895. return this;
  27896. };
  27897. ArrowHelper.prototype.clone = function () {
  27898. return new this.constructor().copy( this );
  27899. };
  27900. /**
  27901. * @author sroucheray / http://sroucheray.org/
  27902. * @author mrdoob / http://mrdoob.com/
  27903. */
  27904. function AxesHelper( size ) {
  27905. size = size || 1;
  27906. var vertices = [
  27907. 0, 0, 0, size, 0, 0,
  27908. 0, 0, 0, 0, size, 0,
  27909. 0, 0, 0, 0, 0, size
  27910. ];
  27911. var colors = [
  27912. 1, 0, 0, 1, 0.6, 0,
  27913. 0, 1, 0, 0.6, 1, 0,
  27914. 0, 0, 1, 0, 0.6, 1
  27915. ];
  27916. var geometry = new BufferGeometry();
  27917. geometry.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  27918. geometry.addAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  27919. var material = new LineBasicMaterial( { vertexColors: VertexColors } );
  27920. LineSegments.call( this, geometry, material );
  27921. }
  27922. AxesHelper.prototype = Object.create( LineSegments.prototype );
  27923. AxesHelper.prototype.constructor = AxesHelper;
  27924. /**
  27925. * @author mrdoob / http://mrdoob.com/
  27926. */
  27927. function Face4( a, b, c, d, normal, color, materialIndex ) {
  27928. console.warn( 'THREE.Face4 has been removed. A THREE.Face3 will be created instead.' );
  27929. return new Face3( a, b, c, normal, color, materialIndex );
  27930. }
  27931. var LineStrip = 0;
  27932. var LinePieces = 1;
  27933. function MeshFaceMaterial( materials ) {
  27934. console.warn( 'THREE.MeshFaceMaterial has been removed. Use an Array instead.' );
  27935. return materials;
  27936. }
  27937. function MultiMaterial( materials ) {
  27938. if ( materials === undefined ) materials = [];
  27939. console.warn( 'THREE.MultiMaterial has been removed. Use an Array instead.' );
  27940. materials.isMultiMaterial = true;
  27941. materials.materials = materials;
  27942. materials.clone = function () {
  27943. return materials.slice();
  27944. };
  27945. return materials;
  27946. }
  27947. function PointCloud( geometry, material ) {
  27948. console.warn( 'THREE.PointCloud has been renamed to THREE.Points.' );
  27949. return new Points( geometry, material );
  27950. }
  27951. function Particle( material ) {
  27952. console.warn( 'THREE.Particle has been renamed to THREE.Sprite.' );
  27953. return new Sprite( material );
  27954. }
  27955. function ParticleSystem( geometry, material ) {
  27956. console.warn( 'THREE.ParticleSystem has been renamed to THREE.Points.' );
  27957. return new Points( geometry, material );
  27958. }
  27959. function PointCloudMaterial( parameters ) {
  27960. console.warn( 'THREE.PointCloudMaterial has been renamed to THREE.PointsMaterial.' );
  27961. return new PointsMaterial( parameters );
  27962. }
  27963. function ParticleBasicMaterial( parameters ) {
  27964. console.warn( 'THREE.ParticleBasicMaterial has been renamed to THREE.PointsMaterial.' );
  27965. return new PointsMaterial( parameters );
  27966. }
  27967. function ParticleSystemMaterial( parameters ) {
  27968. console.warn( 'THREE.ParticleSystemMaterial has been renamed to THREE.PointsMaterial.' );
  27969. return new PointsMaterial( parameters );
  27970. }
  27971. function Vertex( x, y, z ) {
  27972. console.warn( 'THREE.Vertex has been removed. Use THREE.Vector3 instead.' );
  27973. return new Vector3( x, y, z );
  27974. }
  27975. //
  27976. function DynamicBufferAttribute( array, itemSize ) {
  27977. console.warn( 'THREE.DynamicBufferAttribute has been removed. Use new THREE.BufferAttribute().setDynamic( true ) instead.' );
  27978. return new BufferAttribute( array, itemSize ).setDynamic( true );
  27979. }
  27980. function Int8Attribute( array, itemSize ) {
  27981. console.warn( 'THREE.Int8Attribute has been removed. Use new THREE.Int8BufferAttribute() instead.' );
  27982. return new Int8BufferAttribute( array, itemSize );
  27983. }
  27984. function Uint8Attribute( array, itemSize ) {
  27985. console.warn( 'THREE.Uint8Attribute has been removed. Use new THREE.Uint8BufferAttribute() instead.' );
  27986. return new Uint8BufferAttribute( array, itemSize );
  27987. }
  27988. function Uint8ClampedAttribute( array, itemSize ) {
  27989. console.warn( 'THREE.Uint8ClampedAttribute has been removed. Use new THREE.Uint8ClampedBufferAttribute() instead.' );
  27990. return new Uint8ClampedBufferAttribute( array, itemSize );
  27991. }
  27992. function Int16Attribute( array, itemSize ) {
  27993. console.warn( 'THREE.Int16Attribute has been removed. Use new THREE.Int16BufferAttribute() instead.' );
  27994. return new Int16BufferAttribute( array, itemSize );
  27995. }
  27996. function Uint16Attribute( array, itemSize ) {
  27997. console.warn( 'THREE.Uint16Attribute has been removed. Use new THREE.Uint16BufferAttribute() instead.' );
  27998. return new Uint16BufferAttribute( array, itemSize );
  27999. }
  28000. function Int32Attribute( array, itemSize ) {
  28001. console.warn( 'THREE.Int32Attribute has been removed. Use new THREE.Int32BufferAttribute() instead.' );
  28002. return new Int32BufferAttribute( array, itemSize );
  28003. }
  28004. function Uint32Attribute( array, itemSize ) {
  28005. console.warn( 'THREE.Uint32Attribute has been removed. Use new THREE.Uint32BufferAttribute() instead.' );
  28006. return new Uint32BufferAttribute( array, itemSize );
  28007. }
  28008. function Float32Attribute( array, itemSize ) {
  28009. console.warn( 'THREE.Float32Attribute has been removed. Use new THREE.Float32BufferAttribute() instead.' );
  28010. return new Float32BufferAttribute( array, itemSize );
  28011. }
  28012. function Float64Attribute( array, itemSize ) {
  28013. console.warn( 'THREE.Float64Attribute has been removed. Use new THREE.Float64BufferAttribute() instead.' );
  28014. return new Float64BufferAttribute( array, itemSize );
  28015. }
  28016. //
  28017. Curve.create = function ( construct, getPoint ) {
  28018. console.log( 'THREE.Curve.create() has been deprecated' );
  28019. construct.prototype = Object.create( Curve.prototype );
  28020. construct.prototype.constructor = construct;
  28021. construct.prototype.getPoint = getPoint;
  28022. return construct;
  28023. };
  28024. //
  28025. Object.assign( CurvePath.prototype, {
  28026. createPointsGeometry: function ( divisions ) {
  28027. console.warn( 'THREE.CurvePath: .createPointsGeometry() has been removed. Use new THREE.Geometry().setFromPoints( points ) instead.' );
  28028. // generate geometry from path points (for Line or Points objects)
  28029. var pts = this.getPoints( divisions );
  28030. return this.createGeometry( pts );
  28031. },
  28032. createSpacedPointsGeometry: function ( divisions ) {
  28033. console.warn( 'THREE.CurvePath: .createSpacedPointsGeometry() has been removed. Use new THREE.Geometry().setFromPoints( points ) instead.' );
  28034. // generate geometry from equidistant sampling along the path
  28035. var pts = this.getSpacedPoints( divisions );
  28036. return this.createGeometry( pts );
  28037. },
  28038. createGeometry: function ( points ) {
  28039. console.warn( 'THREE.CurvePath: .createGeometry() has been removed. Use new THREE.Geometry().setFromPoints( points ) instead.' );
  28040. var geometry = new Geometry();
  28041. for ( var i = 0, l = points.length; i < l; i ++ ) {
  28042. var point = points[ i ];
  28043. geometry.vertices.push( new Vector3( point.x, point.y, point.z || 0 ) );
  28044. }
  28045. return geometry;
  28046. }
  28047. } );
  28048. //
  28049. Object.assign( Path.prototype, {
  28050. fromPoints: function ( points ) {
  28051. console.warn( 'THREE.Path: .fromPoints() has been renamed to .setFromPoints().' );
  28052. this.setFromPoints( points );
  28053. }
  28054. } );
  28055. //
  28056. function ClosedSplineCurve3( points ) {
  28057. console.warn( 'THREE.ClosedSplineCurve3 has been deprecated. Use THREE.CatmullRomCurve3 instead.' );
  28058. CatmullRomCurve3.call( this, points );
  28059. this.type = 'catmullrom';
  28060. this.closed = true;
  28061. }
  28062. ClosedSplineCurve3.prototype = Object.create( CatmullRomCurve3.prototype );
  28063. //
  28064. function SplineCurve3( points ) {
  28065. console.warn( 'THREE.SplineCurve3 has been deprecated. Use THREE.CatmullRomCurve3 instead.' );
  28066. CatmullRomCurve3.call( this, points );
  28067. this.type = 'catmullrom';
  28068. }
  28069. SplineCurve3.prototype = Object.create( CatmullRomCurve3.prototype );
  28070. //
  28071. function Spline( points ) {
  28072. console.warn( 'THREE.Spline has been removed. Use THREE.CatmullRomCurve3 instead.' );
  28073. CatmullRomCurve3.call( this, points );
  28074. this.type = 'catmullrom';
  28075. }
  28076. Spline.prototype = Object.create( CatmullRomCurve3.prototype );
  28077. Object.assign( Spline.prototype, {
  28078. initFromArray: function ( /* a */ ) {
  28079. console.error( 'THREE.Spline: .initFromArray() has been removed.' );
  28080. },
  28081. getControlPointsArray: function ( /* optionalTarget */ ) {
  28082. console.error( 'THREE.Spline: .getControlPointsArray() has been removed.' );
  28083. },
  28084. reparametrizeByArcLength: function ( /* samplingCoef */ ) {
  28085. console.error( 'THREE.Spline: .reparametrizeByArcLength() has been removed.' );
  28086. }
  28087. } );
  28088. //
  28089. function AxisHelper( size ) {
  28090. console.warn( 'THREE.AxisHelper has been renamed to THREE.AxesHelper.' );
  28091. return new AxesHelper( size );
  28092. }
  28093. function BoundingBoxHelper( object, color ) {
  28094. console.warn( 'THREE.BoundingBoxHelper has been deprecated. Creating a THREE.BoxHelper instead.' );
  28095. return new BoxHelper( object, color );
  28096. }
  28097. function EdgesHelper( object, hex ) {
  28098. console.warn( 'THREE.EdgesHelper has been removed. Use THREE.EdgesGeometry instead.' );
  28099. return new LineSegments( new EdgesGeometry( object.geometry ), new LineBasicMaterial( { color: hex !== undefined ? hex : 0xffffff } ) );
  28100. }
  28101. GridHelper.prototype.setColors = function () {
  28102. console.error( 'THREE.GridHelper: setColors() has been deprecated, pass them in the constructor instead.' );
  28103. };
  28104. SkeletonHelper.prototype.update = function () {
  28105. console.error( 'THREE.SkeletonHelper: update() no longer needs to be called.' );
  28106. };
  28107. function WireframeHelper( object, hex ) {
  28108. console.warn( 'THREE.WireframeHelper has been removed. Use THREE.WireframeGeometry instead.' );
  28109. return new LineSegments( new WireframeGeometry( object.geometry ), new LineBasicMaterial( { color: hex !== undefined ? hex : 0xffffff } ) );
  28110. }
  28111. //
  28112. Object.assign( Loader.prototype, {
  28113. extractUrlBase: function ( url ) {
  28114. console.warn( 'THREE.Loader: .extractUrlBase() has been deprecated. Use THREE.LoaderUtils.extractUrlBase() instead.' );
  28115. return LoaderUtils.extractUrlBase( url );
  28116. }
  28117. } );
  28118. function XHRLoader( manager ) {
  28119. console.warn( 'THREE.XHRLoader has been renamed to THREE.FileLoader.' );
  28120. return new FileLoader( manager );
  28121. }
  28122. function BinaryTextureLoader( manager ) {
  28123. console.warn( 'THREE.BinaryTextureLoader has been renamed to THREE.DataTextureLoader.' );
  28124. return new DataTextureLoader( manager );
  28125. }
  28126. Object.assign( ObjectLoader.prototype, {
  28127. setTexturePath: function ( value ) {
  28128. console.warn( 'THREE.ObjectLoader: .setTexturePath() has been renamed to .setResourcePath().' );
  28129. return this.setResourcePath( value );
  28130. }
  28131. } );
  28132. //
  28133. Object.assign( Box2.prototype, {
  28134. center: function ( optionalTarget ) {
  28135. console.warn( 'THREE.Box2: .center() has been renamed to .getCenter().' );
  28136. return this.getCenter( optionalTarget );
  28137. },
  28138. empty: function () {
  28139. console.warn( 'THREE.Box2: .empty() has been renamed to .isEmpty().' );
  28140. return this.isEmpty();
  28141. },
  28142. isIntersectionBox: function ( box ) {
  28143. console.warn( 'THREE.Box2: .isIntersectionBox() has been renamed to .intersectsBox().' );
  28144. return this.intersectsBox( box );
  28145. },
  28146. size: function ( optionalTarget ) {
  28147. console.warn( 'THREE.Box2: .size() has been renamed to .getSize().' );
  28148. return this.getSize( optionalTarget );
  28149. }
  28150. } );
  28151. Object.assign( Box3.prototype, {
  28152. center: function ( optionalTarget ) {
  28153. console.warn( 'THREE.Box3: .center() has been renamed to .getCenter().' );
  28154. return this.getCenter( optionalTarget );
  28155. },
  28156. empty: function () {
  28157. console.warn( 'THREE.Box3: .empty() has been renamed to .isEmpty().' );
  28158. return this.isEmpty();
  28159. },
  28160. isIntersectionBox: function ( box ) {
  28161. console.warn( 'THREE.Box3: .isIntersectionBox() has been renamed to .intersectsBox().' );
  28162. return this.intersectsBox( box );
  28163. },
  28164. isIntersectionSphere: function ( sphere ) {
  28165. console.warn( 'THREE.Box3: .isIntersectionSphere() has been renamed to .intersectsSphere().' );
  28166. return this.intersectsSphere( sphere );
  28167. },
  28168. size: function ( optionalTarget ) {
  28169. console.warn( 'THREE.Box3: .size() has been renamed to .getSize().' );
  28170. return this.getSize( optionalTarget );
  28171. }
  28172. } );
  28173. Line3.prototype.center = function ( optionalTarget ) {
  28174. console.warn( 'THREE.Line3: .center() has been renamed to .getCenter().' );
  28175. return this.getCenter( optionalTarget );
  28176. };
  28177. Object.assign( _Math, {
  28178. random16: function () {
  28179. console.warn( 'THREE.Math: .random16() has been deprecated. Use Math.random() instead.' );
  28180. return Math.random();
  28181. },
  28182. nearestPowerOfTwo: function ( value ) {
  28183. console.warn( 'THREE.Math: .nearestPowerOfTwo() has been renamed to .floorPowerOfTwo().' );
  28184. return _Math.floorPowerOfTwo( value );
  28185. },
  28186. nextPowerOfTwo: function ( value ) {
  28187. console.warn( 'THREE.Math: .nextPowerOfTwo() has been renamed to .ceilPowerOfTwo().' );
  28188. return _Math.ceilPowerOfTwo( value );
  28189. }
  28190. } );
  28191. Object.assign( Matrix3.prototype, {
  28192. flattenToArrayOffset: function ( array, offset ) {
  28193. console.warn( "THREE.Matrix3: .flattenToArrayOffset() has been deprecated. Use .toArray() instead." );
  28194. return this.toArray( array, offset );
  28195. },
  28196. multiplyVector3: function ( vector ) {
  28197. console.warn( 'THREE.Matrix3: .multiplyVector3() has been removed. Use vector.applyMatrix3( matrix ) instead.' );
  28198. return vector.applyMatrix3( this );
  28199. },
  28200. multiplyVector3Array: function ( /* a */ ) {
  28201. console.error( 'THREE.Matrix3: .multiplyVector3Array() has been removed.' );
  28202. },
  28203. applyToBuffer: function ( buffer /*, offset, length */ ) {
  28204. console.warn( 'THREE.Matrix3: .applyToBuffer() has been removed. Use matrix.applyToBufferAttribute( attribute ) instead.' );
  28205. return this.applyToBufferAttribute( buffer );
  28206. },
  28207. applyToVector3Array: function ( /* array, offset, length */ ) {
  28208. console.error( 'THREE.Matrix3: .applyToVector3Array() has been removed.' );
  28209. }
  28210. } );
  28211. Object.assign( Matrix4.prototype, {
  28212. extractPosition: function ( m ) {
  28213. console.warn( 'THREE.Matrix4: .extractPosition() has been renamed to .copyPosition().' );
  28214. return this.copyPosition( m );
  28215. },
  28216. flattenToArrayOffset: function ( array, offset ) {
  28217. console.warn( "THREE.Matrix4: .flattenToArrayOffset() has been deprecated. Use .toArray() instead." );
  28218. return this.toArray( array, offset );
  28219. },
  28220. getPosition: function () {
  28221. var v1;
  28222. return function getPosition() {
  28223. if ( v1 === undefined ) v1 = new Vector3();
  28224. console.warn( 'THREE.Matrix4: .getPosition() has been removed. Use Vector3.setFromMatrixPosition( matrix ) instead.' );
  28225. return v1.setFromMatrixColumn( this, 3 );
  28226. };
  28227. }(),
  28228. setRotationFromQuaternion: function ( q ) {
  28229. console.warn( 'THREE.Matrix4: .setRotationFromQuaternion() has been renamed to .makeRotationFromQuaternion().' );
  28230. return this.makeRotationFromQuaternion( q );
  28231. },
  28232. multiplyToArray: function () {
  28233. console.warn( 'THREE.Matrix4: .multiplyToArray() has been removed.' );
  28234. },
  28235. multiplyVector3: function ( vector ) {
  28236. console.warn( 'THREE.Matrix4: .multiplyVector3() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
  28237. return vector.applyMatrix4( this );
  28238. },
  28239. multiplyVector4: function ( vector ) {
  28240. console.warn( 'THREE.Matrix4: .multiplyVector4() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
  28241. return vector.applyMatrix4( this );
  28242. },
  28243. multiplyVector3Array: function ( /* a */ ) {
  28244. console.error( 'THREE.Matrix4: .multiplyVector3Array() has been removed.' );
  28245. },
  28246. rotateAxis: function ( v ) {
  28247. console.warn( 'THREE.Matrix4: .rotateAxis() has been removed. Use Vector3.transformDirection( matrix ) instead.' );
  28248. v.transformDirection( this );
  28249. },
  28250. crossVector: function ( vector ) {
  28251. console.warn( 'THREE.Matrix4: .crossVector() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
  28252. return vector.applyMatrix4( this );
  28253. },
  28254. translate: function () {
  28255. console.error( 'THREE.Matrix4: .translate() has been removed.' );
  28256. },
  28257. rotateX: function () {
  28258. console.error( 'THREE.Matrix4: .rotateX() has been removed.' );
  28259. },
  28260. rotateY: function () {
  28261. console.error( 'THREE.Matrix4: .rotateY() has been removed.' );
  28262. },
  28263. rotateZ: function () {
  28264. console.error( 'THREE.Matrix4: .rotateZ() has been removed.' );
  28265. },
  28266. rotateByAxis: function () {
  28267. console.error( 'THREE.Matrix4: .rotateByAxis() has been removed.' );
  28268. },
  28269. applyToBuffer: function ( buffer /*, offset, length */ ) {
  28270. console.warn( 'THREE.Matrix4: .applyToBuffer() has been removed. Use matrix.applyToBufferAttribute( attribute ) instead.' );
  28271. return this.applyToBufferAttribute( buffer );
  28272. },
  28273. applyToVector3Array: function ( /* array, offset, length */ ) {
  28274. console.error( 'THREE.Matrix4: .applyToVector3Array() has been removed.' );
  28275. },
  28276. makeFrustum: function ( left, right, bottom, top, near, far ) {
  28277. console.warn( 'THREE.Matrix4: .makeFrustum() has been removed. Use .makePerspective( left, right, top, bottom, near, far ) instead.' );
  28278. return this.makePerspective( left, right, top, bottom, near, far );
  28279. }
  28280. } );
  28281. Plane.prototype.isIntersectionLine = function ( line ) {
  28282. console.warn( 'THREE.Plane: .isIntersectionLine() has been renamed to .intersectsLine().' );
  28283. return this.intersectsLine( line );
  28284. };
  28285. Quaternion.prototype.multiplyVector3 = function ( vector ) {
  28286. console.warn( 'THREE.Quaternion: .multiplyVector3() has been removed. Use is now vector.applyQuaternion( quaternion ) instead.' );
  28287. return vector.applyQuaternion( this );
  28288. };
  28289. Object.assign( Ray.prototype, {
  28290. isIntersectionBox: function ( box ) {
  28291. console.warn( 'THREE.Ray: .isIntersectionBox() has been renamed to .intersectsBox().' );
  28292. return this.intersectsBox( box );
  28293. },
  28294. isIntersectionPlane: function ( plane ) {
  28295. console.warn( 'THREE.Ray: .isIntersectionPlane() has been renamed to .intersectsPlane().' );
  28296. return this.intersectsPlane( plane );
  28297. },
  28298. isIntersectionSphere: function ( sphere ) {
  28299. console.warn( 'THREE.Ray: .isIntersectionSphere() has been renamed to .intersectsSphere().' );
  28300. return this.intersectsSphere( sphere );
  28301. }
  28302. } );
  28303. Object.assign( Triangle.prototype, {
  28304. area: function () {
  28305. console.warn( 'THREE.Triangle: .area() has been renamed to .getArea().' );
  28306. return this.getArea();
  28307. },
  28308. barycoordFromPoint: function ( point, target ) {
  28309. console.warn( 'THREE.Triangle: .barycoordFromPoint() has been renamed to .getBarycoord().' );
  28310. return this.getBarycoord( point, target );
  28311. },
  28312. midpoint: function ( target ) {
  28313. console.warn( 'THREE.Triangle: .midpoint() has been renamed to .getMidpoint().' );
  28314. return this.getMidpoint( target );
  28315. },
  28316. normal: function ( target ) {
  28317. console.warn( 'THREE.Triangle: .normal() has been renamed to .getNormal().' );
  28318. return this.getNormal( target );
  28319. },
  28320. plane: function ( target ) {
  28321. console.warn( 'THREE.Triangle: .plane() has been renamed to .getPlane().' );
  28322. return this.getPlane( target );
  28323. }
  28324. } );
  28325. Object.assign( Triangle, {
  28326. barycoordFromPoint: function ( point, a, b, c, target ) {
  28327. console.warn( 'THREE.Triangle: .barycoordFromPoint() has been renamed to .getBarycoord().' );
  28328. return Triangle.getBarycoord( point, a, b, c, target );
  28329. },
  28330. normal: function ( a, b, c, target ) {
  28331. console.warn( 'THREE.Triangle: .normal() has been renamed to .getNormal().' );
  28332. return Triangle.getNormal( a, b, c, target );
  28333. }
  28334. } );
  28335. Object.assign( Shape.prototype, {
  28336. extractAllPoints: function ( divisions ) {
  28337. console.warn( 'THREE.Shape: .extractAllPoints() has been removed. Use .extractPoints() instead.' );
  28338. return this.extractPoints( divisions );
  28339. },
  28340. extrude: function ( options ) {
  28341. console.warn( 'THREE.Shape: .extrude() has been removed. Use ExtrudeGeometry() instead.' );
  28342. return new ExtrudeGeometry( this, options );
  28343. },
  28344. makeGeometry: function ( options ) {
  28345. console.warn( 'THREE.Shape: .makeGeometry() has been removed. Use ShapeGeometry() instead.' );
  28346. return new ShapeGeometry( this, options );
  28347. }
  28348. } );
  28349. Object.assign( Vector2.prototype, {
  28350. fromAttribute: function ( attribute, index, offset ) {
  28351. console.warn( 'THREE.Vector2: .fromAttribute() has been renamed to .fromBufferAttribute().' );
  28352. return this.fromBufferAttribute( attribute, index, offset );
  28353. },
  28354. distanceToManhattan: function ( v ) {
  28355. console.warn( 'THREE.Vector2: .distanceToManhattan() has been renamed to .manhattanDistanceTo().' );
  28356. return this.manhattanDistanceTo( v );
  28357. },
  28358. lengthManhattan: function () {
  28359. console.warn( 'THREE.Vector2: .lengthManhattan() has been renamed to .manhattanLength().' );
  28360. return this.manhattanLength();
  28361. }
  28362. } );
  28363. Object.assign( Vector3.prototype, {
  28364. setEulerFromRotationMatrix: function () {
  28365. console.error( 'THREE.Vector3: .setEulerFromRotationMatrix() has been removed. Use Euler.setFromRotationMatrix() instead.' );
  28366. },
  28367. setEulerFromQuaternion: function () {
  28368. console.error( 'THREE.Vector3: .setEulerFromQuaternion() has been removed. Use Euler.setFromQuaternion() instead.' );
  28369. },
  28370. getPositionFromMatrix: function ( m ) {
  28371. console.warn( 'THREE.Vector3: .getPositionFromMatrix() has been renamed to .setFromMatrixPosition().' );
  28372. return this.setFromMatrixPosition( m );
  28373. },
  28374. getScaleFromMatrix: function ( m ) {
  28375. console.warn( 'THREE.Vector3: .getScaleFromMatrix() has been renamed to .setFromMatrixScale().' );
  28376. return this.setFromMatrixScale( m );
  28377. },
  28378. getColumnFromMatrix: function ( index, matrix ) {
  28379. console.warn( 'THREE.Vector3: .getColumnFromMatrix() has been renamed to .setFromMatrixColumn().' );
  28380. return this.setFromMatrixColumn( matrix, index );
  28381. },
  28382. applyProjection: function ( m ) {
  28383. console.warn( 'THREE.Vector3: .applyProjection() has been removed. Use .applyMatrix4( m ) instead.' );
  28384. return this.applyMatrix4( m );
  28385. },
  28386. fromAttribute: function ( attribute, index, offset ) {
  28387. console.warn( 'THREE.Vector3: .fromAttribute() has been renamed to .fromBufferAttribute().' );
  28388. return this.fromBufferAttribute( attribute, index, offset );
  28389. },
  28390. distanceToManhattan: function ( v ) {
  28391. console.warn( 'THREE.Vector3: .distanceToManhattan() has been renamed to .manhattanDistanceTo().' );
  28392. return this.manhattanDistanceTo( v );
  28393. },
  28394. lengthManhattan: function () {
  28395. console.warn( 'THREE.Vector3: .lengthManhattan() has been renamed to .manhattanLength().' );
  28396. return this.manhattanLength();
  28397. }
  28398. } );
  28399. Object.assign( Vector4.prototype, {
  28400. fromAttribute: function ( attribute, index, offset ) {
  28401. console.warn( 'THREE.Vector4: .fromAttribute() has been renamed to .fromBufferAttribute().' );
  28402. return this.fromBufferAttribute( attribute, index, offset );
  28403. },
  28404. lengthManhattan: function () {
  28405. console.warn( 'THREE.Vector4: .lengthManhattan() has been renamed to .manhattanLength().' );
  28406. return this.manhattanLength();
  28407. }
  28408. } );
  28409. //
  28410. Object.assign( Geometry.prototype, {
  28411. computeTangents: function () {
  28412. console.error( 'THREE.Geometry: .computeTangents() has been removed.' );
  28413. },
  28414. computeLineDistances: function () {
  28415. console.error( 'THREE.Geometry: .computeLineDistances() has been removed. Use THREE.Line.computeLineDistances() instead.' );
  28416. }
  28417. } );
  28418. Object.assign( Object3D.prototype, {
  28419. getChildByName: function ( name ) {
  28420. console.warn( 'THREE.Object3D: .getChildByName() has been renamed to .getObjectByName().' );
  28421. return this.getObjectByName( name );
  28422. },
  28423. renderDepth: function () {
  28424. console.warn( 'THREE.Object3D: .renderDepth has been removed. Use .renderOrder, instead.' );
  28425. },
  28426. translate: function ( distance, axis ) {
  28427. console.warn( 'THREE.Object3D: .translate() has been removed. Use .translateOnAxis( axis, distance ) instead.' );
  28428. return this.translateOnAxis( axis, distance );
  28429. },
  28430. getWorldRotation: function () {
  28431. console.error( 'THREE.Object3D: .getWorldRotation() has been removed. Use THREE.Object3D.getWorldQuaternion( target ) instead.' );
  28432. }
  28433. } );
  28434. Object.defineProperties( Object3D.prototype, {
  28435. eulerOrder: {
  28436. get: function () {
  28437. console.warn( 'THREE.Object3D: .eulerOrder is now .rotation.order.' );
  28438. return this.rotation.order;
  28439. },
  28440. set: function ( value ) {
  28441. console.warn( 'THREE.Object3D: .eulerOrder is now .rotation.order.' );
  28442. this.rotation.order = value;
  28443. }
  28444. },
  28445. useQuaternion: {
  28446. get: function () {
  28447. console.warn( 'THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.' );
  28448. },
  28449. set: function () {
  28450. console.warn( 'THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.' );
  28451. }
  28452. }
  28453. } );
  28454. Object.defineProperties( LOD.prototype, {
  28455. objects: {
  28456. get: function () {
  28457. console.warn( 'THREE.LOD: .objects has been renamed to .levels.' );
  28458. return this.levels;
  28459. }
  28460. }
  28461. } );
  28462. Object.defineProperty( Skeleton.prototype, 'useVertexTexture', {
  28463. get: function () {
  28464. console.warn( 'THREE.Skeleton: useVertexTexture has been removed.' );
  28465. },
  28466. set: function () {
  28467. console.warn( 'THREE.Skeleton: useVertexTexture has been removed.' );
  28468. }
  28469. } );
  28470. SkinnedMesh.prototype.initBones = function () {
  28471. console.error( 'THREE.SkinnedMesh: initBones() has been removed.' );
  28472. };
  28473. Object.defineProperty( Curve.prototype, '__arcLengthDivisions', {
  28474. get: function () {
  28475. console.warn( 'THREE.Curve: .__arcLengthDivisions is now .arcLengthDivisions.' );
  28476. return this.arcLengthDivisions;
  28477. },
  28478. set: function ( value ) {
  28479. console.warn( 'THREE.Curve: .__arcLengthDivisions is now .arcLengthDivisions.' );
  28480. this.arcLengthDivisions = value;
  28481. }
  28482. } );
  28483. //
  28484. PerspectiveCamera.prototype.setLens = function ( focalLength, filmGauge ) {
  28485. console.warn( "THREE.PerspectiveCamera.setLens is deprecated. " +
  28486. "Use .setFocalLength and .filmGauge for a photographic setup." );
  28487. if ( filmGauge !== undefined ) this.filmGauge = filmGauge;
  28488. this.setFocalLength( focalLength );
  28489. };
  28490. //
  28491. Object.defineProperties( Light.prototype, {
  28492. onlyShadow: {
  28493. set: function () {
  28494. console.warn( 'THREE.Light: .onlyShadow has been removed.' );
  28495. }
  28496. },
  28497. shadowCameraFov: {
  28498. set: function ( value ) {
  28499. console.warn( 'THREE.Light: .shadowCameraFov is now .shadow.camera.fov.' );
  28500. this.shadow.camera.fov = value;
  28501. }
  28502. },
  28503. shadowCameraLeft: {
  28504. set: function ( value ) {
  28505. console.warn( 'THREE.Light: .shadowCameraLeft is now .shadow.camera.left.' );
  28506. this.shadow.camera.left = value;
  28507. }
  28508. },
  28509. shadowCameraRight: {
  28510. set: function ( value ) {
  28511. console.warn( 'THREE.Light: .shadowCameraRight is now .shadow.camera.right.' );
  28512. this.shadow.camera.right = value;
  28513. }
  28514. },
  28515. shadowCameraTop: {
  28516. set: function ( value ) {
  28517. console.warn( 'THREE.Light: .shadowCameraTop is now .shadow.camera.top.' );
  28518. this.shadow.camera.top = value;
  28519. }
  28520. },
  28521. shadowCameraBottom: {
  28522. set: function ( value ) {
  28523. console.warn( 'THREE.Light: .shadowCameraBottom is now .shadow.camera.bottom.' );
  28524. this.shadow.camera.bottom = value;
  28525. }
  28526. },
  28527. shadowCameraNear: {
  28528. set: function ( value ) {
  28529. console.warn( 'THREE.Light: .shadowCameraNear is now .shadow.camera.near.' );
  28530. this.shadow.camera.near = value;
  28531. }
  28532. },
  28533. shadowCameraFar: {
  28534. set: function ( value ) {
  28535. console.warn( 'THREE.Light: .shadowCameraFar is now .shadow.camera.far.' );
  28536. this.shadow.camera.far = value;
  28537. }
  28538. },
  28539. shadowCameraVisible: {
  28540. set: function () {
  28541. console.warn( 'THREE.Light: .shadowCameraVisible has been removed. Use new THREE.CameraHelper( light.shadow.camera ) instead.' );
  28542. }
  28543. },
  28544. shadowBias: {
  28545. set: function ( value ) {
  28546. console.warn( 'THREE.Light: .shadowBias is now .shadow.bias.' );
  28547. this.shadow.bias = value;
  28548. }
  28549. },
  28550. shadowDarkness: {
  28551. set: function () {
  28552. console.warn( 'THREE.Light: .shadowDarkness has been removed.' );
  28553. }
  28554. },
  28555. shadowMapWidth: {
  28556. set: function ( value ) {
  28557. console.warn( 'THREE.Light: .shadowMapWidth is now .shadow.mapSize.width.' );
  28558. this.shadow.mapSize.width = value;
  28559. }
  28560. },
  28561. shadowMapHeight: {
  28562. set: function ( value ) {
  28563. console.warn( 'THREE.Light: .shadowMapHeight is now .shadow.mapSize.height.' );
  28564. this.shadow.mapSize.height = value;
  28565. }
  28566. }
  28567. } );
  28568. //
  28569. Object.defineProperties( BufferAttribute.prototype, {
  28570. length: {
  28571. get: function () {
  28572. console.warn( 'THREE.BufferAttribute: .length has been deprecated. Use .count instead.' );
  28573. return this.array.length;
  28574. }
  28575. },
  28576. copyIndicesArray: function ( /* indices */ ) {
  28577. console.error( 'THREE.BufferAttribute: .copyIndicesArray() has been removed.' );
  28578. }
  28579. } );
  28580. Object.assign( BufferGeometry.prototype, {
  28581. addIndex: function ( index ) {
  28582. console.warn( 'THREE.BufferGeometry: .addIndex() has been renamed to .setIndex().' );
  28583. this.setIndex( index );
  28584. },
  28585. addDrawCall: function ( start, count, indexOffset ) {
  28586. if ( indexOffset !== undefined ) {
  28587. console.warn( 'THREE.BufferGeometry: .addDrawCall() no longer supports indexOffset.' );
  28588. }
  28589. console.warn( 'THREE.BufferGeometry: .addDrawCall() is now .addGroup().' );
  28590. this.addGroup( start, count );
  28591. },
  28592. clearDrawCalls: function () {
  28593. console.warn( 'THREE.BufferGeometry: .clearDrawCalls() is now .clearGroups().' );
  28594. this.clearGroups();
  28595. },
  28596. computeTangents: function () {
  28597. console.warn( 'THREE.BufferGeometry: .computeTangents() has been removed.' );
  28598. },
  28599. computeOffsets: function () {
  28600. console.warn( 'THREE.BufferGeometry: .computeOffsets() has been removed.' );
  28601. }
  28602. } );
  28603. Object.defineProperties( BufferGeometry.prototype, {
  28604. drawcalls: {
  28605. get: function () {
  28606. console.error( 'THREE.BufferGeometry: .drawcalls has been renamed to .groups.' );
  28607. return this.groups;
  28608. }
  28609. },
  28610. offsets: {
  28611. get: function () {
  28612. console.warn( 'THREE.BufferGeometry: .offsets has been renamed to .groups.' );
  28613. return this.groups;
  28614. }
  28615. }
  28616. } );
  28617. //
  28618. Object.assign( ExtrudeBufferGeometry.prototype, {
  28619. getArrays: function () {
  28620. console.error( 'THREE.ExtrudeBufferGeometry: .getArrays() has been removed.' );
  28621. },
  28622. addShapeList: function () {
  28623. console.error( 'THREE.ExtrudeBufferGeometry: .addShapeList() has been removed.' );
  28624. },
  28625. addShape: function () {
  28626. console.error( 'THREE.ExtrudeBufferGeometry: .addShape() has been removed.' );
  28627. }
  28628. } );
  28629. //
  28630. Object.defineProperties( Uniform.prototype, {
  28631. dynamic: {
  28632. set: function () {
  28633. console.warn( 'THREE.Uniform: .dynamic has been removed. Use object.onBeforeRender() instead.' );
  28634. }
  28635. },
  28636. onUpdate: {
  28637. value: function () {
  28638. console.warn( 'THREE.Uniform: .onUpdate() has been removed. Use object.onBeforeRender() instead.' );
  28639. return this;
  28640. }
  28641. }
  28642. } );
  28643. //
  28644. Object.defineProperties( Material.prototype, {
  28645. wrapAround: {
  28646. get: function () {
  28647. console.warn( 'THREE.Material: .wrapAround has been removed.' );
  28648. },
  28649. set: function () {
  28650. console.warn( 'THREE.Material: .wrapAround has been removed.' );
  28651. }
  28652. },
  28653. overdraw: {
  28654. get: function () {
  28655. console.warn( 'THREE.Material: .overdraw has been removed.' );
  28656. },
  28657. set: function () {
  28658. console.warn( 'THREE.Material: .overdraw has been removed.' );
  28659. }
  28660. },
  28661. wrapRGB: {
  28662. get: function () {
  28663. console.warn( 'THREE.Material: .wrapRGB has been removed.' );
  28664. return new Color();
  28665. }
  28666. },
  28667. shading: {
  28668. get: function () {
  28669. console.error( 'THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.' );
  28670. },
  28671. set: function ( value ) {
  28672. console.warn( 'THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.' );
  28673. this.flatShading = ( value === FlatShading );
  28674. }
  28675. }
  28676. } );
  28677. Object.defineProperties( MeshPhongMaterial.prototype, {
  28678. metal: {
  28679. get: function () {
  28680. console.warn( 'THREE.MeshPhongMaterial: .metal has been removed. Use THREE.MeshStandardMaterial instead.' );
  28681. return false;
  28682. },
  28683. set: function () {
  28684. console.warn( 'THREE.MeshPhongMaterial: .metal has been removed. Use THREE.MeshStandardMaterial instead' );
  28685. }
  28686. }
  28687. } );
  28688. Object.defineProperties( ShaderMaterial.prototype, {
  28689. derivatives: {
  28690. get: function () {
  28691. console.warn( 'THREE.ShaderMaterial: .derivatives has been moved to .extensions.derivatives.' );
  28692. return this.extensions.derivatives;
  28693. },
  28694. set: function ( value ) {
  28695. console.warn( 'THREE. ShaderMaterial: .derivatives has been moved to .extensions.derivatives.' );
  28696. this.extensions.derivatives = value;
  28697. }
  28698. }
  28699. } );
  28700. //
  28701. Object.assign( WebGLRenderer.prototype, {
  28702. clearTarget: function ( renderTarget, color, depth, stencil ) {
  28703. console.warn( 'THREE.WebGLRenderer: .clearTarget() has been deprecated. Use .setRenderTarget() and .clear() instead.' );
  28704. this.setRenderTarget( renderTarget );
  28705. this.clear( color, depth, stencil );
  28706. },
  28707. animate: function ( callback ) {
  28708. console.warn( 'THREE.WebGLRenderer: .animate() is now .setAnimationLoop().' );
  28709. this.setAnimationLoop( callback );
  28710. },
  28711. getCurrentRenderTarget: function () {
  28712. console.warn( 'THREE.WebGLRenderer: .getCurrentRenderTarget() is now .getRenderTarget().' );
  28713. return this.getRenderTarget();
  28714. },
  28715. getMaxAnisotropy: function () {
  28716. console.warn( 'THREE.WebGLRenderer: .getMaxAnisotropy() is now .capabilities.getMaxAnisotropy().' );
  28717. return this.capabilities.getMaxAnisotropy();
  28718. },
  28719. getPrecision: function () {
  28720. console.warn( 'THREE.WebGLRenderer: .getPrecision() is now .capabilities.precision.' );
  28721. return this.capabilities.precision;
  28722. },
  28723. resetGLState: function () {
  28724. console.warn( 'THREE.WebGLRenderer: .resetGLState() is now .state.reset().' );
  28725. return this.state.reset();
  28726. },
  28727. supportsFloatTextures: function () {
  28728. console.warn( 'THREE.WebGLRenderer: .supportsFloatTextures() is now .extensions.get( \'OES_texture_float\' ).' );
  28729. return this.extensions.get( 'OES_texture_float' );
  28730. },
  28731. supportsHalfFloatTextures: function () {
  28732. console.warn( 'THREE.WebGLRenderer: .supportsHalfFloatTextures() is now .extensions.get( \'OES_texture_half_float\' ).' );
  28733. return this.extensions.get( 'OES_texture_half_float' );
  28734. },
  28735. supportsStandardDerivatives: function () {
  28736. console.warn( 'THREE.WebGLRenderer: .supportsStandardDerivatives() is now .extensions.get( \'OES_standard_derivatives\' ).' );
  28737. return this.extensions.get( 'OES_standard_derivatives' );
  28738. },
  28739. supportsCompressedTextureS3TC: function () {
  28740. console.warn( 'THREE.WebGLRenderer: .supportsCompressedTextureS3TC() is now .extensions.get( \'WEBGL_compressed_texture_s3tc\' ).' );
  28741. return this.extensions.get( 'WEBGL_compressed_texture_s3tc' );
  28742. },
  28743. supportsCompressedTexturePVRTC: function () {
  28744. console.warn( 'THREE.WebGLRenderer: .supportsCompressedTexturePVRTC() is now .extensions.get( \'WEBGL_compressed_texture_pvrtc\' ).' );
  28745. return this.extensions.get( 'WEBGL_compressed_texture_pvrtc' );
  28746. },
  28747. supportsBlendMinMax: function () {
  28748. console.warn( 'THREE.WebGLRenderer: .supportsBlendMinMax() is now .extensions.get( \'EXT_blend_minmax\' ).' );
  28749. return this.extensions.get( 'EXT_blend_minmax' );
  28750. },
  28751. supportsVertexTextures: function () {
  28752. console.warn( 'THREE.WebGLRenderer: .supportsVertexTextures() is now .capabilities.vertexTextures.' );
  28753. return this.capabilities.vertexTextures;
  28754. },
  28755. supportsInstancedArrays: function () {
  28756. console.warn( 'THREE.WebGLRenderer: .supportsInstancedArrays() is now .extensions.get( \'ANGLE_instanced_arrays\' ).' );
  28757. return this.extensions.get( 'ANGLE_instanced_arrays' );
  28758. },
  28759. enableScissorTest: function ( boolean ) {
  28760. console.warn( 'THREE.WebGLRenderer: .enableScissorTest() is now .setScissorTest().' );
  28761. this.setScissorTest( boolean );
  28762. },
  28763. initMaterial: function () {
  28764. console.warn( 'THREE.WebGLRenderer: .initMaterial() has been removed.' );
  28765. },
  28766. addPrePlugin: function () {
  28767. console.warn( 'THREE.WebGLRenderer: .addPrePlugin() has been removed.' );
  28768. },
  28769. addPostPlugin: function () {
  28770. console.warn( 'THREE.WebGLRenderer: .addPostPlugin() has been removed.' );
  28771. },
  28772. updateShadowMap: function () {
  28773. console.warn( 'THREE.WebGLRenderer: .updateShadowMap() has been removed.' );
  28774. },
  28775. setFaceCulling: function () {
  28776. console.warn( 'THREE.WebGLRenderer: .setFaceCulling() has been removed.' );
  28777. },
  28778. allocTextureUnit: function () {
  28779. console.warn( 'THREE.WebGLRenderer: .allocTextureUnit() has been removed.' );
  28780. },
  28781. setTexture: function () {
  28782. console.warn( 'THREE.WebGLRenderer: .setTexture() has been removed.' );
  28783. },
  28784. setTexture2D: function () {
  28785. console.warn( 'THREE.WebGLRenderer: .setTexture2D() has been removed.' );
  28786. },
  28787. setTextureCube: function () {
  28788. console.warn( 'THREE.WebGLRenderer: .setTextureCube() has been removed.' );
  28789. }
  28790. } );
  28791. Object.defineProperties( WebGLRenderer.prototype, {
  28792. shadowMapEnabled: {
  28793. get: function () {
  28794. return this.shadowMap.enabled;
  28795. },
  28796. set: function ( value ) {
  28797. console.warn( 'THREE.WebGLRenderer: .shadowMapEnabled is now .shadowMap.enabled.' );
  28798. this.shadowMap.enabled = value;
  28799. }
  28800. },
  28801. shadowMapType: {
  28802. get: function () {
  28803. return this.shadowMap.type;
  28804. },
  28805. set: function ( value ) {
  28806. console.warn( 'THREE.WebGLRenderer: .shadowMapType is now .shadowMap.type.' );
  28807. this.shadowMap.type = value;
  28808. }
  28809. },
  28810. shadowMapCullFace: {
  28811. get: function () {
  28812. console.warn( 'THREE.WebGLRenderer: .shadowMapCullFace has been removed. Set Material.shadowSide instead.' );
  28813. return undefined;
  28814. },
  28815. set: function ( /* value */ ) {
  28816. console.warn( 'THREE.WebGLRenderer: .shadowMapCullFace has been removed. Set Material.shadowSide instead.' );
  28817. }
  28818. }
  28819. } );
  28820. Object.defineProperties( WebGLShadowMap.prototype, {
  28821. cullFace: {
  28822. get: function () {
  28823. console.warn( 'THREE.WebGLRenderer: .shadowMap.cullFace has been removed. Set Material.shadowSide instead.' );
  28824. return undefined;
  28825. },
  28826. set: function ( /* cullFace */ ) {
  28827. console.warn( 'THREE.WebGLRenderer: .shadowMap.cullFace has been removed. Set Material.shadowSide instead.' );
  28828. }
  28829. },
  28830. renderReverseSided: {
  28831. get: function () {
  28832. console.warn( 'THREE.WebGLRenderer: .shadowMap.renderReverseSided has been removed. Set Material.shadowSide instead.' );
  28833. return undefined;
  28834. },
  28835. set: function () {
  28836. console.warn( 'THREE.WebGLRenderer: .shadowMap.renderReverseSided has been removed. Set Material.shadowSide instead.' );
  28837. }
  28838. },
  28839. renderSingleSided: {
  28840. get: function () {
  28841. console.warn( 'THREE.WebGLRenderer: .shadowMap.renderSingleSided has been removed. Set Material.shadowSide instead.' );
  28842. return undefined;
  28843. },
  28844. set: function () {
  28845. console.warn( 'THREE.WebGLRenderer: .shadowMap.renderSingleSided has been removed. Set Material.shadowSide instead.' );
  28846. }
  28847. }
  28848. } );
  28849. //
  28850. Object.defineProperties( WebGLRenderTargetCube.prototype, {
  28851. activeCubeFace: {
  28852. set: function ( /* value */ ) {
  28853. console.warn( 'THREE.WebGLRenderTargetCube: .activeCubeFace has been removed. It is now the second parameter of WebGLRenderer.setRenderTarget().' );
  28854. }
  28855. },
  28856. activeMipMapLevel: {
  28857. set: function ( /* value */ ) {
  28858. console.warn( 'THREE.WebGLRenderTargetCube: .activeMipMapLevel has been removed. It is now the third parameter of WebGLRenderer.setRenderTarget().' );
  28859. }
  28860. }
  28861. } );
  28862. //
  28863. Object.defineProperties( WebGLRenderTarget.prototype, {
  28864. wrapS: {
  28865. get: function () {
  28866. console.warn( 'THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.' );
  28867. return this.texture.wrapS;
  28868. },
  28869. set: function ( value ) {
  28870. console.warn( 'THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.' );
  28871. this.texture.wrapS = value;
  28872. }
  28873. },
  28874. wrapT: {
  28875. get: function () {
  28876. console.warn( 'THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.' );
  28877. return this.texture.wrapT;
  28878. },
  28879. set: function ( value ) {
  28880. console.warn( 'THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.' );
  28881. this.texture.wrapT = value;
  28882. }
  28883. },
  28884. magFilter: {
  28885. get: function () {
  28886. console.warn( 'THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.' );
  28887. return this.texture.magFilter;
  28888. },
  28889. set: function ( value ) {
  28890. console.warn( 'THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.' );
  28891. this.texture.magFilter = value;
  28892. }
  28893. },
  28894. minFilter: {
  28895. get: function () {
  28896. console.warn( 'THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.' );
  28897. return this.texture.minFilter;
  28898. },
  28899. set: function ( value ) {
  28900. console.warn( 'THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.' );
  28901. this.texture.minFilter = value;
  28902. }
  28903. },
  28904. anisotropy: {
  28905. get: function () {
  28906. console.warn( 'THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy.' );
  28907. return this.texture.anisotropy;
  28908. },
  28909. set: function ( value ) {
  28910. console.warn( 'THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy.' );
  28911. this.texture.anisotropy = value;
  28912. }
  28913. },
  28914. offset: {
  28915. get: function () {
  28916. console.warn( 'THREE.WebGLRenderTarget: .offset is now .texture.offset.' );
  28917. return this.texture.offset;
  28918. },
  28919. set: function ( value ) {
  28920. console.warn( 'THREE.WebGLRenderTarget: .offset is now .texture.offset.' );
  28921. this.texture.offset = value;
  28922. }
  28923. },
  28924. repeat: {
  28925. get: function () {
  28926. console.warn( 'THREE.WebGLRenderTarget: .repeat is now .texture.repeat.' );
  28927. return this.texture.repeat;
  28928. },
  28929. set: function ( value ) {
  28930. console.warn( 'THREE.WebGLRenderTarget: .repeat is now .texture.repeat.' );
  28931. this.texture.repeat = value;
  28932. }
  28933. },
  28934. format: {
  28935. get: function () {
  28936. console.warn( 'THREE.WebGLRenderTarget: .format is now .texture.format.' );
  28937. return this.texture.format;
  28938. },
  28939. set: function ( value ) {
  28940. console.warn( 'THREE.WebGLRenderTarget: .format is now .texture.format.' );
  28941. this.texture.format = value;
  28942. }
  28943. },
  28944. type: {
  28945. get: function () {
  28946. console.warn( 'THREE.WebGLRenderTarget: .type is now .texture.type.' );
  28947. return this.texture.type;
  28948. },
  28949. set: function ( value ) {
  28950. console.warn( 'THREE.WebGLRenderTarget: .type is now .texture.type.' );
  28951. this.texture.type = value;
  28952. }
  28953. },
  28954. generateMipmaps: {
  28955. get: function () {
  28956. console.warn( 'THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps.' );
  28957. return this.texture.generateMipmaps;
  28958. },
  28959. set: function ( value ) {
  28960. console.warn( 'THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps.' );
  28961. this.texture.generateMipmaps = value;
  28962. }
  28963. }
  28964. } );
  28965. //
  28966. Object.defineProperties( WebVRManager.prototype, {
  28967. standing: {
  28968. set: function ( /* value */ ) {
  28969. console.warn( 'THREE.WebVRManager: .standing has been removed.' );
  28970. }
  28971. },
  28972. userHeight: {
  28973. set: function ( /* value */ ) {
  28974. console.warn( 'THREE.WebVRManager: .userHeight has been removed.' );
  28975. }
  28976. }
  28977. } );
  28978. //
  28979. Audio.prototype.load = function ( file ) {
  28980. console.warn( 'THREE.Audio: .load has been deprecated. Use THREE.AudioLoader instead.' );
  28981. var scope = this;
  28982. var audioLoader = new AudioLoader();
  28983. audioLoader.load( file, function ( buffer ) {
  28984. scope.setBuffer( buffer );
  28985. } );
  28986. return this;
  28987. };
  28988. AudioAnalyser.prototype.getData = function () {
  28989. console.warn( 'THREE.AudioAnalyser: .getData() is now .getFrequencyData().' );
  28990. return this.getFrequencyData();
  28991. };
  28992. //
  28993. CubeCamera.prototype.updateCubeMap = function ( renderer, scene ) {
  28994. console.warn( 'THREE.CubeCamera: .updateCubeMap() is now .update().' );
  28995. return this.update( renderer, scene );
  28996. };
  28997. //
  28998. var GeometryUtils = {
  28999. merge: function ( geometry1, geometry2, materialIndexOffset ) {
  29000. console.warn( 'THREE.GeometryUtils: .merge() has been moved to Geometry. Use geometry.merge( geometry2, matrix, materialIndexOffset ) instead.' );
  29001. var matrix;
  29002. if ( geometry2.isMesh ) {
  29003. geometry2.matrixAutoUpdate && geometry2.updateMatrix();
  29004. matrix = geometry2.matrix;
  29005. geometry2 = geometry2.geometry;
  29006. }
  29007. geometry1.merge( geometry2, matrix, materialIndexOffset );
  29008. },
  29009. center: function ( geometry ) {
  29010. console.warn( 'THREE.GeometryUtils: .center() has been moved to Geometry. Use geometry.center() instead.' );
  29011. return geometry.center();
  29012. }
  29013. };
  29014. ImageUtils.crossOrigin = undefined;
  29015. ImageUtils.loadTexture = function ( url, mapping, onLoad, onError ) {
  29016. console.warn( 'THREE.ImageUtils.loadTexture has been deprecated. Use THREE.TextureLoader() instead.' );
  29017. var loader = new TextureLoader();
  29018. loader.setCrossOrigin( this.crossOrigin );
  29019. var texture = loader.load( url, onLoad, undefined, onError );
  29020. if ( mapping ) texture.mapping = mapping;
  29021. return texture;
  29022. };
  29023. ImageUtils.loadTextureCube = function ( urls, mapping, onLoad, onError ) {
  29024. console.warn( 'THREE.ImageUtils.loadTextureCube has been deprecated. Use THREE.CubeTextureLoader() instead.' );
  29025. var loader = new CubeTextureLoader();
  29026. loader.setCrossOrigin( this.crossOrigin );
  29027. var texture = loader.load( urls, onLoad, undefined, onError );
  29028. if ( mapping ) texture.mapping = mapping;
  29029. return texture;
  29030. };
  29031. ImageUtils.loadCompressedTexture = function () {
  29032. console.error( 'THREE.ImageUtils.loadCompressedTexture has been removed. Use THREE.DDSLoader instead.' );
  29033. };
  29034. ImageUtils.loadCompressedTextureCube = function () {
  29035. console.error( 'THREE.ImageUtils.loadCompressedTextureCube has been removed. Use THREE.DDSLoader instead.' );
  29036. };
  29037. //
  29038. function CanvasRenderer() {
  29039. console.error( 'THREE.CanvasRenderer has been removed' );
  29040. }
  29041. //
  29042. function JSONLoader() {
  29043. console.error( 'THREE.JSONLoader has been removed.' );
  29044. }
  29045. //
  29046. var SceneUtils = {
  29047. createMultiMaterialObject: function ( /* geometry, materials */ ) {
  29048. console.error( 'THREE.SceneUtils has been moved to /examples/js/utils/SceneUtils.js' );
  29049. },
  29050. detach: function ( /* child, parent, scene */ ) {
  29051. console.error( 'THREE.SceneUtils has been moved to /examples/js/utils/SceneUtils.js' );
  29052. },
  29053. attach: function ( /* child, scene, parent */ ) {
  29054. console.error( 'THREE.SceneUtils has been moved to /examples/js/utils/SceneUtils.js' );
  29055. }
  29056. };
  29057. //
  29058. function LensFlare() {
  29059. console.error( 'THREE.LensFlare has been moved to /examples/js/objects/Lensflare.js' );
  29060. }
  29061. exports.ACESFilmicToneMapping = ACESFilmicToneMapping;
  29062. exports.AddEquation = AddEquation;
  29063. exports.AddOperation = AddOperation;
  29064. exports.AdditiveBlending = AdditiveBlending;
  29065. exports.AlphaFormat = AlphaFormat;
  29066. exports.AlwaysDepth = AlwaysDepth;
  29067. exports.AmbientLight = AmbientLight;
  29068. exports.AmbientLightProbe = AmbientLightProbe;
  29069. exports.AnimationClip = AnimationClip;
  29070. exports.AnimationLoader = AnimationLoader;
  29071. exports.AnimationMixer = AnimationMixer;
  29072. exports.AnimationObjectGroup = AnimationObjectGroup;
  29073. exports.AnimationUtils = AnimationUtils;
  29074. exports.ArcCurve = ArcCurve;
  29075. exports.ArrayCamera = ArrayCamera;
  29076. exports.ArrowHelper = ArrowHelper;
  29077. exports.Audio = Audio;
  29078. exports.AudioAnalyser = AudioAnalyser;
  29079. exports.AudioContext = AudioContext;
  29080. exports.AudioListener = AudioListener;
  29081. exports.AudioLoader = AudioLoader;
  29082. exports.AxesHelper = AxesHelper;
  29083. exports.AxisHelper = AxisHelper;
  29084. exports.BackSide = BackSide;
  29085. exports.BasicDepthPacking = BasicDepthPacking;
  29086. exports.BasicShadowMap = BasicShadowMap;
  29087. exports.BinaryTextureLoader = BinaryTextureLoader;
  29088. exports.Bone = Bone;
  29089. exports.BooleanKeyframeTrack = BooleanKeyframeTrack;
  29090. exports.BoundingBoxHelper = BoundingBoxHelper;
  29091. exports.Box2 = Box2;
  29092. exports.Box3 = Box3;
  29093. exports.Box3Helper = Box3Helper;
  29094. exports.BoxBufferGeometry = BoxBufferGeometry;
  29095. exports.BoxGeometry = BoxGeometry;
  29096. exports.BoxHelper = BoxHelper;
  29097. exports.BufferAttribute = BufferAttribute;
  29098. exports.BufferGeometry = BufferGeometry;
  29099. exports.BufferGeometryLoader = BufferGeometryLoader;
  29100. exports.ByteType = ByteType;
  29101. exports.Cache = Cache;
  29102. exports.Camera = Camera;
  29103. exports.CameraHelper = CameraHelper;
  29104. exports.CanvasRenderer = CanvasRenderer;
  29105. exports.CanvasTexture = CanvasTexture;
  29106. exports.CatmullRomCurve3 = CatmullRomCurve3;
  29107. exports.CineonToneMapping = CineonToneMapping;
  29108. exports.CircleBufferGeometry = CircleBufferGeometry;
  29109. exports.CircleGeometry = CircleGeometry;
  29110. exports.ClampToEdgeWrapping = ClampToEdgeWrapping;
  29111. exports.Clock = Clock;
  29112. exports.ClosedSplineCurve3 = ClosedSplineCurve3;
  29113. exports.Color = Color;
  29114. exports.ColorKeyframeTrack = ColorKeyframeTrack;
  29115. exports.CompressedTexture = CompressedTexture;
  29116. exports.CompressedTextureLoader = CompressedTextureLoader;
  29117. exports.ConeBufferGeometry = ConeBufferGeometry;
  29118. exports.ConeGeometry = ConeGeometry;
  29119. exports.CubeCamera = CubeCamera;
  29120. exports.CubeGeometry = BoxGeometry;
  29121. exports.CubeReflectionMapping = CubeReflectionMapping;
  29122. exports.CubeRefractionMapping = CubeRefractionMapping;
  29123. exports.CubeTexture = CubeTexture;
  29124. exports.CubeTextureLoader = CubeTextureLoader;
  29125. exports.CubeUVReflectionMapping = CubeUVReflectionMapping;
  29126. exports.CubeUVRefractionMapping = CubeUVRefractionMapping;
  29127. exports.CubicBezierCurve = CubicBezierCurve;
  29128. exports.CubicBezierCurve3 = CubicBezierCurve3;
  29129. exports.CubicInterpolant = CubicInterpolant;
  29130. exports.CullFaceBack = CullFaceBack;
  29131. exports.CullFaceFront = CullFaceFront;
  29132. exports.CullFaceFrontBack = CullFaceFrontBack;
  29133. exports.CullFaceNone = CullFaceNone;
  29134. exports.Curve = Curve;
  29135. exports.CurvePath = CurvePath;
  29136. exports.CustomBlending = CustomBlending;
  29137. exports.CylinderBufferGeometry = CylinderBufferGeometry;
  29138. exports.CylinderGeometry = CylinderGeometry;
  29139. exports.Cylindrical = Cylindrical;
  29140. exports.DataTexture = DataTexture;
  29141. exports.DataTexture2DArray = DataTexture2DArray;
  29142. exports.DataTexture3D = DataTexture3D;
  29143. exports.DataTextureLoader = DataTextureLoader;
  29144. exports.DefaultLoadingManager = DefaultLoadingManager;
  29145. exports.DepthFormat = DepthFormat;
  29146. exports.DepthStencilFormat = DepthStencilFormat;
  29147. exports.DepthTexture = DepthTexture;
  29148. exports.DirectionalLight = DirectionalLight;
  29149. exports.DirectionalLightHelper = DirectionalLightHelper;
  29150. exports.DirectionalLightShadow = DirectionalLightShadow;
  29151. exports.DiscreteInterpolant = DiscreteInterpolant;
  29152. exports.DodecahedronBufferGeometry = DodecahedronBufferGeometry;
  29153. exports.DodecahedronGeometry = DodecahedronGeometry;
  29154. exports.DoubleSide = DoubleSide;
  29155. exports.DstAlphaFactor = DstAlphaFactor;
  29156. exports.DstColorFactor = DstColorFactor;
  29157. exports.DynamicBufferAttribute = DynamicBufferAttribute;
  29158. exports.EdgesGeometry = EdgesGeometry;
  29159. exports.EdgesHelper = EdgesHelper;
  29160. exports.EllipseCurve = EllipseCurve;
  29161. exports.EqualDepth = EqualDepth;
  29162. exports.EquirectangularReflectionMapping = EquirectangularReflectionMapping;
  29163. exports.EquirectangularRefractionMapping = EquirectangularRefractionMapping;
  29164. exports.Euler = Euler;
  29165. exports.EventDispatcher = EventDispatcher;
  29166. exports.ExtrudeBufferGeometry = ExtrudeBufferGeometry;
  29167. exports.ExtrudeGeometry = ExtrudeGeometry;
  29168. exports.Face3 = Face3;
  29169. exports.Face4 = Face4;
  29170. exports.FaceColors = FaceColors;
  29171. exports.FaceNormalsHelper = FaceNormalsHelper;
  29172. exports.FileLoader = FileLoader;
  29173. exports.FlatShading = FlatShading;
  29174. exports.Float32Attribute = Float32Attribute;
  29175. exports.Float32BufferAttribute = Float32BufferAttribute;
  29176. exports.Float64Attribute = Float64Attribute;
  29177. exports.Float64BufferAttribute = Float64BufferAttribute;
  29178. exports.FloatType = FloatType;
  29179. exports.Fog = Fog;
  29180. exports.FogExp2 = FogExp2;
  29181. exports.Font = Font;
  29182. exports.FontLoader = FontLoader;
  29183. exports.FrontFaceDirectionCCW = FrontFaceDirectionCCW;
  29184. exports.FrontFaceDirectionCW = FrontFaceDirectionCW;
  29185. exports.FrontSide = FrontSide;
  29186. exports.Frustum = Frustum;
  29187. exports.GammaEncoding = GammaEncoding;
  29188. exports.Geometry = Geometry;
  29189. exports.GeometryUtils = GeometryUtils;
  29190. exports.GreaterDepth = GreaterDepth;
  29191. exports.GreaterEqualDepth = GreaterEqualDepth;
  29192. exports.GridHelper = GridHelper;
  29193. exports.Group = Group;
  29194. exports.HalfFloatType = HalfFloatType;
  29195. exports.HemisphereLight = HemisphereLight;
  29196. exports.HemisphereLightHelper = HemisphereLightHelper;
  29197. exports.HemisphereLightProbe = HemisphereLightProbe;
  29198. exports.IcosahedronBufferGeometry = IcosahedronBufferGeometry;
  29199. exports.IcosahedronGeometry = IcosahedronGeometry;
  29200. exports.ImageBitmapLoader = ImageBitmapLoader;
  29201. exports.ImageLoader = ImageLoader;
  29202. exports.ImageUtils = ImageUtils;
  29203. exports.ImmediateRenderObject = ImmediateRenderObject;
  29204. exports.InstancedBufferAttribute = InstancedBufferAttribute;
  29205. exports.InstancedBufferGeometry = InstancedBufferGeometry;
  29206. exports.InstancedInterleavedBuffer = InstancedInterleavedBuffer;
  29207. exports.Int16Attribute = Int16Attribute;
  29208. exports.Int16BufferAttribute = Int16BufferAttribute;
  29209. exports.Int32Attribute = Int32Attribute;
  29210. exports.Int32BufferAttribute = Int32BufferAttribute;
  29211. exports.Int8Attribute = Int8Attribute;
  29212. exports.Int8BufferAttribute = Int8BufferAttribute;
  29213. exports.IntType = IntType;
  29214. exports.InterleavedBuffer = InterleavedBuffer;
  29215. exports.InterleavedBufferAttribute = InterleavedBufferAttribute;
  29216. exports.Interpolant = Interpolant;
  29217. exports.InterpolateDiscrete = InterpolateDiscrete;
  29218. exports.InterpolateLinear = InterpolateLinear;
  29219. exports.InterpolateSmooth = InterpolateSmooth;
  29220. exports.JSONLoader = JSONLoader;
  29221. exports.KeyframeTrack = KeyframeTrack;
  29222. exports.LOD = LOD;
  29223. exports.LatheBufferGeometry = LatheBufferGeometry;
  29224. exports.LatheGeometry = LatheGeometry;
  29225. exports.Layers = Layers;
  29226. exports.LensFlare = LensFlare;
  29227. exports.LessDepth = LessDepth;
  29228. exports.LessEqualDepth = LessEqualDepth;
  29229. exports.Light = Light;
  29230. exports.LightProbe = LightProbe;
  29231. exports.LightProbeHelper = LightProbeHelper;
  29232. exports.LightShadow = LightShadow;
  29233. exports.Line = Line;
  29234. exports.Line3 = Line3;
  29235. exports.LineBasicMaterial = LineBasicMaterial;
  29236. exports.LineCurve = LineCurve;
  29237. exports.LineCurve3 = LineCurve3;
  29238. exports.LineDashedMaterial = LineDashedMaterial;
  29239. exports.LineLoop = LineLoop;
  29240. exports.LinePieces = LinePieces;
  29241. exports.LineSegments = LineSegments;
  29242. exports.LineStrip = LineStrip;
  29243. exports.LinearEncoding = LinearEncoding;
  29244. exports.LinearFilter = LinearFilter;
  29245. exports.LinearInterpolant = LinearInterpolant;
  29246. exports.LinearMipMapLinearFilter = LinearMipMapLinearFilter;
  29247. exports.LinearMipMapNearestFilter = LinearMipMapNearestFilter;
  29248. exports.LinearToneMapping = LinearToneMapping;
  29249. exports.Loader = Loader;
  29250. exports.LoaderUtils = LoaderUtils;
  29251. exports.LoadingManager = LoadingManager;
  29252. exports.LogLuvEncoding = LogLuvEncoding;
  29253. exports.LoopOnce = LoopOnce;
  29254. exports.LoopPingPong = LoopPingPong;
  29255. exports.LoopRepeat = LoopRepeat;
  29256. exports.LuminanceAlphaFormat = LuminanceAlphaFormat;
  29257. exports.LuminanceFormat = LuminanceFormat;
  29258. exports.MOUSE = MOUSE;
  29259. exports.Material = Material;
  29260. exports.MaterialLoader = MaterialLoader;
  29261. exports.Math = _Math;
  29262. exports.Matrix3 = Matrix3;
  29263. exports.Matrix4 = Matrix4;
  29264. exports.MaxEquation = MaxEquation;
  29265. exports.Mesh = Mesh;
  29266. exports.MeshBasicMaterial = MeshBasicMaterial;
  29267. exports.MeshDepthMaterial = MeshDepthMaterial;
  29268. exports.MeshDistanceMaterial = MeshDistanceMaterial;
  29269. exports.MeshFaceMaterial = MeshFaceMaterial;
  29270. exports.MeshLambertMaterial = MeshLambertMaterial;
  29271. exports.MeshMatcapMaterial = MeshMatcapMaterial;
  29272. exports.MeshNormalMaterial = MeshNormalMaterial;
  29273. exports.MeshPhongMaterial = MeshPhongMaterial;
  29274. exports.MeshPhysicalMaterial = MeshPhysicalMaterial;
  29275. exports.MeshStandardMaterial = MeshStandardMaterial;
  29276. exports.MeshToonMaterial = MeshToonMaterial;
  29277. exports.MinEquation = MinEquation;
  29278. exports.MirroredRepeatWrapping = MirroredRepeatWrapping;
  29279. exports.MixOperation = MixOperation;
  29280. exports.MultiMaterial = MultiMaterial;
  29281. exports.MultiplyBlending = MultiplyBlending;
  29282. exports.MultiplyOperation = MultiplyOperation;
  29283. exports.NearestFilter = NearestFilter;
  29284. exports.NearestMipMapLinearFilter = NearestMipMapLinearFilter;
  29285. exports.NearestMipMapNearestFilter = NearestMipMapNearestFilter;
  29286. exports.NeverDepth = NeverDepth;
  29287. exports.NoBlending = NoBlending;
  29288. exports.NoColors = NoColors;
  29289. exports.NoToneMapping = NoToneMapping;
  29290. exports.NormalBlending = NormalBlending;
  29291. exports.NotEqualDepth = NotEqualDepth;
  29292. exports.NumberKeyframeTrack = NumberKeyframeTrack;
  29293. exports.Object3D = Object3D;
  29294. exports.ObjectLoader = ObjectLoader;
  29295. exports.ObjectSpaceNormalMap = ObjectSpaceNormalMap;
  29296. exports.OctahedronBufferGeometry = OctahedronBufferGeometry;
  29297. exports.OctahedronGeometry = OctahedronGeometry;
  29298. exports.OneFactor = OneFactor;
  29299. exports.OneMinusDstAlphaFactor = OneMinusDstAlphaFactor;
  29300. exports.OneMinusDstColorFactor = OneMinusDstColorFactor;
  29301. exports.OneMinusSrcAlphaFactor = OneMinusSrcAlphaFactor;
  29302. exports.OneMinusSrcColorFactor = OneMinusSrcColorFactor;
  29303. exports.OrthographicCamera = OrthographicCamera;
  29304. exports.PCFShadowMap = PCFShadowMap;
  29305. exports.PCFSoftShadowMap = PCFSoftShadowMap;
  29306. exports.ParametricBufferGeometry = ParametricBufferGeometry;
  29307. exports.ParametricGeometry = ParametricGeometry;
  29308. exports.Particle = Particle;
  29309. exports.ParticleBasicMaterial = ParticleBasicMaterial;
  29310. exports.ParticleSystem = ParticleSystem;
  29311. exports.ParticleSystemMaterial = ParticleSystemMaterial;
  29312. exports.Path = Path;
  29313. exports.PerspectiveCamera = PerspectiveCamera;
  29314. exports.Plane = Plane;
  29315. exports.PlaneBufferGeometry = PlaneBufferGeometry;
  29316. exports.PlaneGeometry = PlaneGeometry;
  29317. exports.PlaneHelper = PlaneHelper;
  29318. exports.PointCloud = PointCloud;
  29319. exports.PointCloudMaterial = PointCloudMaterial;
  29320. exports.PointLight = PointLight;
  29321. exports.PointLightHelper = PointLightHelper;
  29322. exports.Points = Points;
  29323. exports.PointsMaterial = PointsMaterial;
  29324. exports.PolarGridHelper = PolarGridHelper;
  29325. exports.PolyhedronBufferGeometry = PolyhedronBufferGeometry;
  29326. exports.PolyhedronGeometry = PolyhedronGeometry;
  29327. exports.PositionalAudio = PositionalAudio;
  29328. exports.PositionalAudioHelper = PositionalAudioHelper;
  29329. exports.PropertyBinding = PropertyBinding;
  29330. exports.PropertyMixer = PropertyMixer;
  29331. exports.QuadraticBezierCurve = QuadraticBezierCurve;
  29332. exports.QuadraticBezierCurve3 = QuadraticBezierCurve3;
  29333. exports.Quaternion = Quaternion;
  29334. exports.QuaternionKeyframeTrack = QuaternionKeyframeTrack;
  29335. exports.QuaternionLinearInterpolant = QuaternionLinearInterpolant;
  29336. exports.REVISION = REVISION;
  29337. exports.RGBADepthPacking = RGBADepthPacking;
  29338. exports.RGBAFormat = RGBAFormat;
  29339. exports.RGBA_ASTC_10x10_Format = RGBA_ASTC_10x10_Format;
  29340. exports.RGBA_ASTC_10x5_Format = RGBA_ASTC_10x5_Format;
  29341. exports.RGBA_ASTC_10x6_Format = RGBA_ASTC_10x6_Format;
  29342. exports.RGBA_ASTC_10x8_Format = RGBA_ASTC_10x8_Format;
  29343. exports.RGBA_ASTC_12x10_Format = RGBA_ASTC_12x10_Format;
  29344. exports.RGBA_ASTC_12x12_Format = RGBA_ASTC_12x12_Format;
  29345. exports.RGBA_ASTC_4x4_Format = RGBA_ASTC_4x4_Format;
  29346. exports.RGBA_ASTC_5x4_Format = RGBA_ASTC_5x4_Format;
  29347. exports.RGBA_ASTC_5x5_Format = RGBA_ASTC_5x5_Format;
  29348. exports.RGBA_ASTC_6x5_Format = RGBA_ASTC_6x5_Format;
  29349. exports.RGBA_ASTC_6x6_Format = RGBA_ASTC_6x6_Format;
  29350. exports.RGBA_ASTC_8x5_Format = RGBA_ASTC_8x5_Format;
  29351. exports.RGBA_ASTC_8x6_Format = RGBA_ASTC_8x6_Format;
  29352. exports.RGBA_ASTC_8x8_Format = RGBA_ASTC_8x8_Format;
  29353. exports.RGBA_PVRTC_2BPPV1_Format = RGBA_PVRTC_2BPPV1_Format;
  29354. exports.RGBA_PVRTC_4BPPV1_Format = RGBA_PVRTC_4BPPV1_Format;
  29355. exports.RGBA_S3TC_DXT1_Format = RGBA_S3TC_DXT1_Format;
  29356. exports.RGBA_S3TC_DXT3_Format = RGBA_S3TC_DXT3_Format;
  29357. exports.RGBA_S3TC_DXT5_Format = RGBA_S3TC_DXT5_Format;
  29358. exports.RGBDEncoding = RGBDEncoding;
  29359. exports.RGBEEncoding = RGBEEncoding;
  29360. exports.RGBEFormat = RGBEFormat;
  29361. exports.RGBFormat = RGBFormat;
  29362. exports.RGBM16Encoding = RGBM16Encoding;
  29363. exports.RGBM7Encoding = RGBM7Encoding;
  29364. exports.RGB_ETC1_Format = RGB_ETC1_Format;
  29365. exports.RGB_PVRTC_2BPPV1_Format = RGB_PVRTC_2BPPV1_Format;
  29366. exports.RGB_PVRTC_4BPPV1_Format = RGB_PVRTC_4BPPV1_Format;
  29367. exports.RGB_S3TC_DXT1_Format = RGB_S3TC_DXT1_Format;
  29368. exports.RawShaderMaterial = RawShaderMaterial;
  29369. exports.Ray = Ray;
  29370. exports.Raycaster = Raycaster;
  29371. exports.RectAreaLight = RectAreaLight;
  29372. exports.RectAreaLightHelper = RectAreaLightHelper;
  29373. exports.RedFormat = RedFormat;
  29374. exports.ReinhardToneMapping = ReinhardToneMapping;
  29375. exports.RepeatWrapping = RepeatWrapping;
  29376. exports.ReverseSubtractEquation = ReverseSubtractEquation;
  29377. exports.RingBufferGeometry = RingBufferGeometry;
  29378. exports.RingGeometry = RingGeometry;
  29379. exports.Scene = Scene;
  29380. exports.SceneUtils = SceneUtils;
  29381. exports.ShaderChunk = ShaderChunk;
  29382. exports.ShaderLib = ShaderLib;
  29383. exports.ShaderMaterial = ShaderMaterial;
  29384. exports.ShadowMaterial = ShadowMaterial;
  29385. exports.Shape = Shape;
  29386. exports.ShapeBufferGeometry = ShapeBufferGeometry;
  29387. exports.ShapeGeometry = ShapeGeometry;
  29388. exports.ShapePath = ShapePath;
  29389. exports.ShapeUtils = ShapeUtils;
  29390. exports.ShortType = ShortType;
  29391. exports.Skeleton = Skeleton;
  29392. exports.SkeletonHelper = SkeletonHelper;
  29393. exports.SkinnedMesh = SkinnedMesh;
  29394. exports.SmoothShading = SmoothShading;
  29395. exports.Sphere = Sphere;
  29396. exports.SphereBufferGeometry = SphereBufferGeometry;
  29397. exports.SphereGeometry = SphereGeometry;
  29398. exports.Spherical = Spherical;
  29399. exports.SphericalHarmonics3 = SphericalHarmonics3;
  29400. exports.SphericalReflectionMapping = SphericalReflectionMapping;
  29401. exports.Spline = Spline;
  29402. exports.SplineCurve = SplineCurve;
  29403. exports.SplineCurve3 = SplineCurve3;
  29404. exports.SpotLight = SpotLight;
  29405. exports.SpotLightHelper = SpotLightHelper;
  29406. exports.SpotLightShadow = SpotLightShadow;
  29407. exports.Sprite = Sprite;
  29408. exports.SpriteMaterial = SpriteMaterial;
  29409. exports.SrcAlphaFactor = SrcAlphaFactor;
  29410. exports.SrcAlphaSaturateFactor = SrcAlphaSaturateFactor;
  29411. exports.SrcColorFactor = SrcColorFactor;
  29412. exports.StereoCamera = StereoCamera;
  29413. exports.StringKeyframeTrack = StringKeyframeTrack;
  29414. exports.SubtractEquation = SubtractEquation;
  29415. exports.SubtractiveBlending = SubtractiveBlending;
  29416. exports.TangentSpaceNormalMap = TangentSpaceNormalMap;
  29417. exports.TetrahedronBufferGeometry = TetrahedronBufferGeometry;
  29418. exports.TetrahedronGeometry = TetrahedronGeometry;
  29419. exports.TextBufferGeometry = TextBufferGeometry;
  29420. exports.TextGeometry = TextGeometry;
  29421. exports.Texture = Texture;
  29422. exports.TextureLoader = TextureLoader;
  29423. exports.TorusBufferGeometry = TorusBufferGeometry;
  29424. exports.TorusGeometry = TorusGeometry;
  29425. exports.TorusKnotBufferGeometry = TorusKnotBufferGeometry;
  29426. exports.TorusKnotGeometry = TorusKnotGeometry;
  29427. exports.Triangle = Triangle;
  29428. exports.TriangleFanDrawMode = TriangleFanDrawMode;
  29429. exports.TriangleStripDrawMode = TriangleStripDrawMode;
  29430. exports.TrianglesDrawMode = TrianglesDrawMode;
  29431. exports.TubeBufferGeometry = TubeBufferGeometry;
  29432. exports.TubeGeometry = TubeGeometry;
  29433. exports.UVMapping = UVMapping;
  29434. exports.Uint16Attribute = Uint16Attribute;
  29435. exports.Uint16BufferAttribute = Uint16BufferAttribute;
  29436. exports.Uint32Attribute = Uint32Attribute;
  29437. exports.Uint32BufferAttribute = Uint32BufferAttribute;
  29438. exports.Uint8Attribute = Uint8Attribute;
  29439. exports.Uint8BufferAttribute = Uint8BufferAttribute;
  29440. exports.Uint8ClampedAttribute = Uint8ClampedAttribute;
  29441. exports.Uint8ClampedBufferAttribute = Uint8ClampedBufferAttribute;
  29442. exports.Uncharted2ToneMapping = Uncharted2ToneMapping;
  29443. exports.Uniform = Uniform;
  29444. exports.UniformsLib = UniformsLib;
  29445. exports.UniformsUtils = UniformsUtils;
  29446. exports.UnsignedByteType = UnsignedByteType;
  29447. exports.UnsignedInt248Type = UnsignedInt248Type;
  29448. exports.UnsignedIntType = UnsignedIntType;
  29449. exports.UnsignedShort4444Type = UnsignedShort4444Type;
  29450. exports.UnsignedShort5551Type = UnsignedShort5551Type;
  29451. exports.UnsignedShort565Type = UnsignedShort565Type;
  29452. exports.UnsignedShortType = UnsignedShortType;
  29453. exports.Vector2 = Vector2;
  29454. exports.Vector3 = Vector3;
  29455. exports.Vector4 = Vector4;
  29456. exports.VectorKeyframeTrack = VectorKeyframeTrack;
  29457. exports.Vertex = Vertex;
  29458. exports.VertexColors = VertexColors;
  29459. exports.VertexNormalsHelper = VertexNormalsHelper;
  29460. exports.VideoTexture = VideoTexture;
  29461. exports.WebGLMultisampleRenderTarget = WebGLMultisampleRenderTarget;
  29462. exports.WebGLRenderTarget = WebGLRenderTarget;
  29463. exports.WebGLRenderTargetCube = WebGLRenderTargetCube;
  29464. exports.WebGLRenderer = WebGLRenderer;
  29465. exports.WebGLUtils = WebGLUtils;
  29466. exports.WireframeGeometry = WireframeGeometry;
  29467. exports.WireframeHelper = WireframeHelper;
  29468. exports.WrapAroundEnding = WrapAroundEnding;
  29469. exports.XHRLoader = XHRLoader;
  29470. exports.ZeroCurvatureEnding = ZeroCurvatureEnding;
  29471. exports.ZeroFactor = ZeroFactor;
  29472. exports.ZeroSlopeEnding = ZeroSlopeEnding;
  29473. exports.sRGBEncoding = sRGBEncoding;
  29474. Object.defineProperty(exports, '__esModule', { value: true });
  29475. }));