three.js 1.1 MB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520225212252222523225242252522526225272252822529225302253122532225332253422535225362253722538225392254022541225422254322544225452254622547225482254922550225512255222553225542255522556225572255822559225602256122562225632256422565225662256722568225692257022571225722257322574225752257622577225782257922580225812258222583225842258522586225872258822589225902259122592225932259422595225962259722598225992260022601226022260322604226052260622607226082260922610226112261222613226142261522616226172261822619226202262122622226232262422625226262262722628226292263022631226322263322634226352263622637226382263922640226412264222643226442264522646226472264822649226502265122652226532265422655226562265722658226592266022661226622266322664226652266622667226682266922670226712267222673226742267522676226772267822679226802268122682226832268422685226862268722688226892269022691226922269322694226952269622697226982269922700227012270222703227042270522706227072270822709227102271122712227132271422715227162271722718227192272022721227222272322724227252272622727227282272922730227312273222733227342273522736227372273822739227402274122742227432274422745227462274722748227492275022751227522275322754227552275622757227582275922760227612276222763227642276522766227672276822769227702277122772227732277422775227762277722778227792278022781227822278322784227852278622787227882278922790227912279222793227942279522796227972279822799228002280122802228032280422805228062280722808228092281022811228122281322814228152281622817228182281922820228212282222823228242282522826228272282822829228302283122832228332283422835228362283722838228392284022841228422284322844228452284622847228482284922850228512285222853228542285522856228572285822859228602286122862228632286422865228662286722868228692287022871228722287322874228752287622877228782287922880228812288222883228842288522886228872288822889228902289122892228932289422895228962289722898228992290022901229022290322904229052290622907229082290922910229112291222913229142291522916229172291822919229202292122922229232292422925229262292722928229292293022931229322293322934229352293622937229382293922940229412294222943229442294522946229472294822949229502295122952229532295422955229562295722958229592296022961229622296322964229652296622967229682296922970229712297222973229742297522976229772297822979229802298122982229832298422985229862298722988229892299022991229922299322994229952299622997229982299923000230012300223003230042300523006230072300823009230102301123012230132301423015230162301723018230192302023021230222302323024230252302623027230282302923030230312303223033230342303523036230372303823039230402304123042230432304423045230462304723048230492305023051230522305323054230552305623057230582305923060230612306223063230642306523066230672306823069230702307123072230732307423075230762307723078230792308023081230822308323084230852308623087230882308923090230912309223093230942309523096230972309823099231002310123102231032310423105231062310723108231092311023111231122311323114231152311623117231182311923120231212312223123231242312523126231272312823129231302313123132231332313423135231362313723138231392314023141231422314323144231452314623147231482314923150231512315223153231542315523156231572315823159231602316123162231632316423165231662316723168231692317023171231722317323174231752317623177231782317923180231812318223183231842318523186231872318823189231902319123192231932319423195231962319723198231992320023201232022320323204232052320623207232082320923210232112321223213232142321523216232172321823219232202322123222232232322423225232262322723228232292323023231232322323323234232352323623237232382323923240232412324223243232442324523246232472324823249232502325123252232532325423255232562325723258232592326023261232622326323264232652326623267232682326923270232712327223273232742327523276232772327823279232802328123282232832328423285232862328723288232892329023291232922329323294232952329623297232982329923300233012330223303233042330523306233072330823309233102331123312233132331423315233162331723318233192332023321233222332323324233252332623327233282332923330233312333223333233342333523336233372333823339233402334123342233432334423345233462334723348233492335023351233522335323354233552335623357233582335923360233612336223363233642336523366233672336823369233702337123372233732337423375233762337723378233792338023381233822338323384233852338623387233882338923390233912339223393233942339523396233972339823399234002340123402234032340423405234062340723408234092341023411234122341323414234152341623417234182341923420234212342223423234242342523426234272342823429234302343123432234332343423435234362343723438234392344023441234422344323444234452344623447234482344923450234512345223453234542345523456234572345823459234602346123462234632346423465234662346723468234692347023471234722347323474234752347623477234782347923480234812348223483234842348523486234872348823489234902349123492234932349423495234962349723498234992350023501235022350323504235052350623507235082350923510235112351223513235142351523516235172351823519235202352123522235232352423525235262352723528235292353023531235322353323534235352353623537235382353923540235412354223543235442354523546235472354823549235502355123552235532355423555235562355723558235592356023561235622356323564235652356623567235682356923570235712357223573235742357523576235772357823579235802358123582235832358423585235862358723588235892359023591235922359323594235952359623597235982359923600236012360223603236042360523606236072360823609236102361123612236132361423615236162361723618236192362023621236222362323624236252362623627236282362923630236312363223633236342363523636236372363823639236402364123642236432364423645236462364723648236492365023651236522365323654236552365623657236582365923660236612366223663236642366523666236672366823669236702367123672236732367423675236762367723678236792368023681236822368323684236852368623687236882368923690236912369223693236942369523696236972369823699237002370123702237032370423705237062370723708237092371023711237122371323714237152371623717237182371923720237212372223723237242372523726237272372823729237302373123732237332373423735237362373723738237392374023741237422374323744237452374623747237482374923750237512375223753237542375523756237572375823759237602376123762237632376423765237662376723768237692377023771237722377323774237752377623777237782377923780237812378223783237842378523786237872378823789237902379123792237932379423795237962379723798237992380023801238022380323804238052380623807238082380923810238112381223813238142381523816238172381823819238202382123822238232382423825238262382723828238292383023831238322383323834238352383623837238382383923840238412384223843238442384523846238472384823849238502385123852238532385423855238562385723858238592386023861238622386323864238652386623867238682386923870238712387223873238742387523876238772387823879238802388123882238832388423885238862388723888238892389023891238922389323894238952389623897238982389923900239012390223903239042390523906239072390823909239102391123912239132391423915239162391723918239192392023921239222392323924239252392623927239282392923930239312393223933239342393523936239372393823939239402394123942239432394423945239462394723948239492395023951239522395323954239552395623957239582395923960239612396223963239642396523966239672396823969239702397123972239732397423975239762397723978239792398023981239822398323984239852398623987239882398923990239912399223993239942399523996239972399823999240002400124002240032400424005240062400724008240092401024011240122401324014240152401624017240182401924020240212402224023240242402524026240272402824029240302403124032240332403424035240362403724038240392404024041240422404324044240452404624047240482404924050240512405224053240542405524056240572405824059240602406124062240632406424065240662406724068240692407024071240722407324074240752407624077240782407924080240812408224083240842408524086240872408824089240902409124092240932409424095240962409724098240992410024101241022410324104241052410624107241082410924110241112411224113241142411524116241172411824119241202412124122241232412424125241262412724128241292413024131241322413324134241352413624137241382413924140241412414224143241442414524146241472414824149241502415124152241532415424155241562415724158241592416024161241622416324164241652416624167241682416924170241712417224173241742417524176241772417824179241802418124182241832418424185241862418724188241892419024191241922419324194241952419624197241982419924200242012420224203242042420524206242072420824209242102421124212242132421424215242162421724218242192422024221242222422324224242252422624227242282422924230242312423224233242342423524236242372423824239242402424124242242432424424245242462424724248242492425024251242522425324254242552425624257242582425924260242612426224263242642426524266242672426824269242702427124272242732427424275242762427724278242792428024281242822428324284242852428624287242882428924290242912429224293242942429524296242972429824299243002430124302243032430424305243062430724308243092431024311243122431324314243152431624317243182431924320243212432224323243242432524326243272432824329243302433124332243332433424335243362433724338243392434024341243422434324344243452434624347243482434924350243512435224353243542435524356243572435824359243602436124362243632436424365243662436724368243692437024371243722437324374243752437624377243782437924380243812438224383243842438524386243872438824389243902439124392243932439424395243962439724398243992440024401244022440324404244052440624407244082440924410244112441224413244142441524416244172441824419244202442124422244232442424425244262442724428244292443024431244322443324434244352443624437244382443924440244412444224443244442444524446244472444824449244502445124452244532445424455244562445724458244592446024461244622446324464244652446624467244682446924470244712447224473244742447524476244772447824479244802448124482244832448424485244862448724488244892449024491244922449324494244952449624497244982449924500245012450224503245042450524506245072450824509245102451124512245132451424515245162451724518245192452024521245222452324524245252452624527245282452924530245312453224533245342453524536245372453824539245402454124542245432454424545245462454724548245492455024551245522455324554245552455624557245582455924560245612456224563245642456524566245672456824569245702457124572245732457424575245762457724578245792458024581245822458324584245852458624587245882458924590245912459224593245942459524596245972459824599246002460124602246032460424605246062460724608246092461024611246122461324614246152461624617246182461924620246212462224623246242462524626246272462824629246302463124632246332463424635246362463724638246392464024641246422464324644246452464624647246482464924650246512465224653246542465524656246572465824659246602466124662246632466424665246662466724668246692467024671246722467324674246752467624677246782467924680246812468224683246842468524686246872468824689246902469124692246932469424695246962469724698246992470024701247022470324704247052470624707247082470924710247112471224713247142471524716247172471824719247202472124722247232472424725247262472724728247292473024731247322473324734247352473624737247382473924740247412474224743247442474524746247472474824749247502475124752247532475424755247562475724758247592476024761247622476324764247652476624767247682476924770247712477224773247742477524776247772477824779247802478124782247832478424785247862478724788247892479024791247922479324794247952479624797247982479924800248012480224803248042480524806248072480824809248102481124812248132481424815248162481724818248192482024821248222482324824248252482624827248282482924830248312483224833248342483524836248372483824839248402484124842248432484424845248462484724848248492485024851248522485324854248552485624857248582485924860248612486224863248642486524866248672486824869248702487124872248732487424875248762487724878248792488024881248822488324884248852488624887248882488924890248912489224893248942489524896248972489824899249002490124902249032490424905249062490724908249092491024911249122491324914249152491624917249182491924920249212492224923249242492524926249272492824929249302493124932249332493424935249362493724938249392494024941249422494324944249452494624947249482494924950249512495224953249542495524956249572495824959249602496124962249632496424965249662496724968249692497024971249722497324974249752497624977249782497924980249812498224983249842498524986249872498824989249902499124992249932499424995249962499724998249992500025001250022500325004250052500625007250082500925010250112501225013250142501525016250172501825019250202502125022250232502425025250262502725028250292503025031250322503325034250352503625037250382503925040250412504225043250442504525046250472504825049250502505125052250532505425055250562505725058250592506025061250622506325064250652506625067250682506925070250712507225073250742507525076250772507825079250802508125082250832508425085250862508725088250892509025091250922509325094250952509625097250982509925100251012510225103251042510525106251072510825109251102511125112251132511425115251162511725118251192512025121251222512325124251252512625127251282512925130251312513225133251342513525136251372513825139251402514125142251432514425145251462514725148251492515025151251522515325154251552515625157251582515925160251612516225163251642516525166251672516825169251702517125172251732517425175251762517725178251792518025181251822518325184251852518625187251882518925190251912519225193251942519525196251972519825199252002520125202252032520425205252062520725208252092521025211252122521325214252152521625217252182521925220252212522225223252242522525226252272522825229252302523125232252332523425235252362523725238252392524025241252422524325244252452524625247252482524925250252512525225253252542525525256252572525825259252602526125262252632526425265252662526725268252692527025271252722527325274252752527625277252782527925280252812528225283252842528525286252872528825289252902529125292252932529425295252962529725298252992530025301253022530325304253052530625307253082530925310253112531225313253142531525316253172531825319253202532125322253232532425325253262532725328253292533025331253322533325334253352533625337253382533925340253412534225343253442534525346253472534825349253502535125352253532535425355253562535725358253592536025361253622536325364253652536625367253682536925370253712537225373253742537525376253772537825379253802538125382253832538425385253862538725388253892539025391253922539325394253952539625397253982539925400254012540225403254042540525406254072540825409254102541125412254132541425415254162541725418254192542025421254222542325424254252542625427254282542925430254312543225433254342543525436254372543825439254402544125442254432544425445254462544725448254492545025451254522545325454254552545625457254582545925460254612546225463254642546525466254672546825469254702547125472254732547425475254762547725478254792548025481254822548325484254852548625487254882548925490254912549225493254942549525496254972549825499255002550125502255032550425505255062550725508255092551025511255122551325514255152551625517255182551925520255212552225523255242552525526255272552825529255302553125532255332553425535255362553725538255392554025541255422554325544255452554625547255482554925550255512555225553255542555525556255572555825559255602556125562255632556425565255662556725568255692557025571255722557325574255752557625577255782557925580255812558225583255842558525586255872558825589255902559125592255932559425595255962559725598255992560025601256022560325604256052560625607256082560925610256112561225613256142561525616256172561825619256202562125622256232562425625256262562725628256292563025631256322563325634256352563625637256382563925640256412564225643256442564525646256472564825649256502565125652256532565425655256562565725658256592566025661256622566325664256652566625667256682566925670256712567225673256742567525676256772567825679256802568125682256832568425685256862568725688256892569025691256922569325694256952569625697256982569925700257012570225703257042570525706257072570825709257102571125712257132571425715257162571725718257192572025721257222572325724257252572625727257282572925730257312573225733257342573525736257372573825739257402574125742257432574425745257462574725748257492575025751257522575325754257552575625757257582575925760257612576225763257642576525766257672576825769257702577125772257732577425775257762577725778257792578025781257822578325784257852578625787257882578925790257912579225793257942579525796257972579825799258002580125802258032580425805258062580725808258092581025811258122581325814258152581625817258182581925820258212582225823258242582525826258272582825829258302583125832258332583425835258362583725838258392584025841258422584325844258452584625847258482584925850258512585225853258542585525856258572585825859258602586125862258632586425865258662586725868258692587025871258722587325874258752587625877258782587925880258812588225883258842588525886258872588825889258902589125892258932589425895258962589725898258992590025901259022590325904259052590625907259082590925910259112591225913259142591525916259172591825919259202592125922259232592425925259262592725928259292593025931259322593325934259352593625937259382593925940259412594225943259442594525946259472594825949259502595125952259532595425955259562595725958259592596025961259622596325964259652596625967259682596925970259712597225973259742597525976259772597825979259802598125982259832598425985259862598725988259892599025991259922599325994259952599625997259982599926000260012600226003260042600526006260072600826009260102601126012260132601426015260162601726018260192602026021260222602326024260252602626027260282602926030260312603226033260342603526036260372603826039260402604126042260432604426045260462604726048260492605026051260522605326054260552605626057260582605926060260612606226063260642606526066260672606826069260702607126072260732607426075260762607726078260792608026081260822608326084260852608626087260882608926090260912609226093260942609526096260972609826099261002610126102261032610426105261062610726108261092611026111261122611326114261152611626117261182611926120261212612226123261242612526126261272612826129261302613126132261332613426135261362613726138261392614026141261422614326144261452614626147261482614926150261512615226153261542615526156261572615826159261602616126162261632616426165261662616726168261692617026171261722617326174261752617626177261782617926180261812618226183261842618526186261872618826189261902619126192261932619426195261962619726198261992620026201262022620326204262052620626207262082620926210262112621226213262142621526216262172621826219262202622126222262232622426225262262622726228262292623026231262322623326234262352623626237262382623926240262412624226243262442624526246262472624826249262502625126252262532625426255262562625726258262592626026261262622626326264262652626626267262682626926270262712627226273262742627526276262772627826279262802628126282262832628426285262862628726288262892629026291262922629326294262952629626297262982629926300263012630226303263042630526306263072630826309263102631126312263132631426315263162631726318263192632026321263222632326324263252632626327263282632926330263312633226333263342633526336263372633826339263402634126342263432634426345263462634726348263492635026351263522635326354263552635626357263582635926360263612636226363263642636526366263672636826369263702637126372263732637426375263762637726378263792638026381263822638326384263852638626387263882638926390263912639226393263942639526396263972639826399264002640126402264032640426405264062640726408264092641026411264122641326414264152641626417264182641926420264212642226423264242642526426264272642826429264302643126432264332643426435264362643726438264392644026441264422644326444264452644626447264482644926450264512645226453264542645526456264572645826459264602646126462264632646426465264662646726468264692647026471264722647326474264752647626477264782647926480264812648226483264842648526486264872648826489264902649126492264932649426495264962649726498264992650026501265022650326504265052650626507265082650926510265112651226513265142651526516265172651826519265202652126522265232652426525265262652726528265292653026531265322653326534265352653626537265382653926540265412654226543265442654526546265472654826549265502655126552265532655426555265562655726558265592656026561265622656326564265652656626567265682656926570265712657226573265742657526576265772657826579265802658126582265832658426585265862658726588265892659026591265922659326594265952659626597265982659926600266012660226603266042660526606266072660826609266102661126612266132661426615266162661726618266192662026621266222662326624266252662626627266282662926630266312663226633266342663526636266372663826639266402664126642266432664426645266462664726648266492665026651266522665326654266552665626657266582665926660266612666226663266642666526666266672666826669266702667126672266732667426675266762667726678266792668026681266822668326684266852668626687266882668926690266912669226693266942669526696266972669826699267002670126702267032670426705267062670726708267092671026711267122671326714267152671626717267182671926720267212672226723267242672526726267272672826729267302673126732267332673426735267362673726738267392674026741267422674326744267452674626747267482674926750267512675226753267542675526756267572675826759267602676126762267632676426765267662676726768267692677026771267722677326774267752677626777267782677926780267812678226783267842678526786267872678826789267902679126792267932679426795267962679726798267992680026801268022680326804268052680626807268082680926810268112681226813268142681526816268172681826819268202682126822268232682426825268262682726828268292683026831268322683326834268352683626837268382683926840268412684226843268442684526846268472684826849268502685126852268532685426855268562685726858268592686026861268622686326864268652686626867268682686926870268712687226873268742687526876268772687826879268802688126882268832688426885268862688726888268892689026891268922689326894268952689626897268982689926900269012690226903269042690526906269072690826909269102691126912269132691426915269162691726918269192692026921269222692326924269252692626927269282692926930269312693226933269342693526936269372693826939269402694126942269432694426945269462694726948269492695026951269522695326954269552695626957269582695926960269612696226963269642696526966269672696826969269702697126972269732697426975269762697726978269792698026981269822698326984269852698626987269882698926990269912699226993269942699526996269972699826999270002700127002270032700427005270062700727008270092701027011270122701327014270152701627017270182701927020270212702227023270242702527026270272702827029270302703127032270332703427035270362703727038270392704027041270422704327044270452704627047270482704927050270512705227053270542705527056270572705827059270602706127062270632706427065270662706727068270692707027071270722707327074270752707627077270782707927080270812708227083270842708527086270872708827089270902709127092270932709427095270962709727098270992710027101271022710327104271052710627107271082710927110271112711227113271142711527116271172711827119271202712127122271232712427125271262712727128271292713027131271322713327134271352713627137271382713927140271412714227143271442714527146271472714827149271502715127152271532715427155271562715727158271592716027161271622716327164271652716627167271682716927170271712717227173271742717527176271772717827179271802718127182271832718427185271862718727188271892719027191271922719327194271952719627197271982719927200272012720227203272042720527206272072720827209272102721127212272132721427215272162721727218272192722027221272222722327224272252722627227272282722927230272312723227233272342723527236272372723827239272402724127242272432724427245272462724727248272492725027251272522725327254272552725627257272582725927260272612726227263272642726527266272672726827269272702727127272272732727427275272762727727278272792728027281272822728327284272852728627287272882728927290272912729227293272942729527296272972729827299273002730127302273032730427305273062730727308273092731027311273122731327314273152731627317273182731927320273212732227323273242732527326273272732827329273302733127332273332733427335273362733727338273392734027341273422734327344273452734627347273482734927350273512735227353273542735527356273572735827359273602736127362273632736427365273662736727368273692737027371273722737327374273752737627377273782737927380273812738227383273842738527386273872738827389273902739127392273932739427395273962739727398273992740027401274022740327404274052740627407274082740927410274112741227413274142741527416274172741827419274202742127422274232742427425274262742727428274292743027431274322743327434274352743627437274382743927440274412744227443274442744527446274472744827449274502745127452274532745427455274562745727458274592746027461274622746327464274652746627467274682746927470274712747227473274742747527476274772747827479274802748127482274832748427485274862748727488274892749027491274922749327494274952749627497274982749927500275012750227503275042750527506275072750827509275102751127512275132751427515275162751727518275192752027521275222752327524275252752627527275282752927530275312753227533275342753527536275372753827539275402754127542275432754427545275462754727548275492755027551275522755327554275552755627557275582755927560275612756227563275642756527566275672756827569275702757127572275732757427575275762757727578275792758027581275822758327584275852758627587275882758927590275912759227593275942759527596275972759827599276002760127602276032760427605276062760727608276092761027611276122761327614276152761627617276182761927620276212762227623276242762527626276272762827629276302763127632276332763427635276362763727638276392764027641276422764327644276452764627647276482764927650276512765227653276542765527656276572765827659276602766127662276632766427665276662766727668276692767027671276722767327674276752767627677276782767927680276812768227683276842768527686276872768827689276902769127692276932769427695276962769727698276992770027701277022770327704277052770627707277082770927710277112771227713277142771527716277172771827719277202772127722277232772427725277262772727728277292773027731277322773327734277352773627737277382773927740277412774227743277442774527746277472774827749277502775127752277532775427755277562775727758277592776027761277622776327764277652776627767277682776927770277712777227773277742777527776277772777827779277802778127782277832778427785277862778727788277892779027791277922779327794277952779627797277982779927800278012780227803278042780527806278072780827809278102781127812278132781427815278162781727818278192782027821278222782327824278252782627827278282782927830278312783227833278342783527836278372783827839278402784127842278432784427845278462784727848278492785027851278522785327854278552785627857278582785927860278612786227863278642786527866278672786827869278702787127872278732787427875278762787727878278792788027881278822788327884278852788627887278882788927890278912789227893278942789527896278972789827899279002790127902279032790427905279062790727908279092791027911279122791327914279152791627917279182791927920279212792227923279242792527926279272792827929279302793127932279332793427935279362793727938279392794027941279422794327944279452794627947279482794927950279512795227953279542795527956279572795827959279602796127962279632796427965279662796727968279692797027971279722797327974279752797627977279782797927980279812798227983279842798527986279872798827989279902799127992279932799427995279962799727998279992800028001280022800328004280052800628007280082800928010280112801228013280142801528016280172801828019280202802128022280232802428025280262802728028280292803028031280322803328034280352803628037280382803928040280412804228043280442804528046280472804828049280502805128052280532805428055280562805728058280592806028061280622806328064280652806628067280682806928070280712807228073280742807528076280772807828079280802808128082280832808428085280862808728088280892809028091280922809328094280952809628097280982809928100281012810228103281042810528106281072810828109281102811128112281132811428115281162811728118281192812028121281222812328124281252812628127281282812928130281312813228133281342813528136281372813828139281402814128142281432814428145281462814728148281492815028151281522815328154281552815628157281582815928160281612816228163281642816528166281672816828169281702817128172281732817428175281762817728178281792818028181281822818328184281852818628187281882818928190281912819228193281942819528196281972819828199282002820128202282032820428205282062820728208282092821028211282122821328214282152821628217282182821928220282212822228223282242822528226282272822828229282302823128232282332823428235282362823728238282392824028241282422824328244282452824628247282482824928250282512825228253282542825528256282572825828259282602826128262282632826428265282662826728268282692827028271282722827328274282752827628277282782827928280282812828228283282842828528286282872828828289282902829128292282932829428295282962829728298282992830028301283022830328304283052830628307283082830928310283112831228313283142831528316283172831828319283202832128322283232832428325283262832728328283292833028331283322833328334283352833628337283382833928340283412834228343283442834528346283472834828349283502835128352283532835428355283562835728358283592836028361283622836328364283652836628367283682836928370283712837228373283742837528376283772837828379283802838128382283832838428385283862838728388283892839028391283922839328394283952839628397283982839928400284012840228403284042840528406284072840828409284102841128412284132841428415284162841728418284192842028421284222842328424284252842628427284282842928430284312843228433284342843528436284372843828439284402844128442284432844428445284462844728448284492845028451284522845328454284552845628457284582845928460284612846228463284642846528466284672846828469284702847128472284732847428475284762847728478284792848028481284822848328484284852848628487284882848928490284912849228493284942849528496284972849828499285002850128502285032850428505285062850728508285092851028511285122851328514285152851628517285182851928520285212852228523285242852528526285272852828529285302853128532285332853428535285362853728538285392854028541285422854328544285452854628547285482854928550285512855228553285542855528556285572855828559285602856128562285632856428565285662856728568285692857028571285722857328574285752857628577285782857928580285812858228583285842858528586285872858828589285902859128592285932859428595285962859728598285992860028601286022860328604286052860628607286082860928610286112861228613286142861528616286172861828619286202862128622286232862428625286262862728628286292863028631286322863328634286352863628637286382863928640286412864228643286442864528646286472864828649286502865128652286532865428655286562865728658286592866028661286622866328664286652866628667286682866928670286712867228673286742867528676286772867828679286802868128682286832868428685286862868728688286892869028691286922869328694286952869628697286982869928700287012870228703287042870528706287072870828709287102871128712287132871428715287162871728718287192872028721287222872328724287252872628727287282872928730287312873228733287342873528736287372873828739287402874128742287432874428745287462874728748287492875028751287522875328754287552875628757287582875928760287612876228763287642876528766287672876828769287702877128772287732877428775287762877728778287792878028781287822878328784287852878628787287882878928790287912879228793287942879528796287972879828799288002880128802288032880428805288062880728808288092881028811288122881328814288152881628817288182881928820288212882228823288242882528826288272882828829288302883128832288332883428835288362883728838288392884028841288422884328844288452884628847288482884928850288512885228853288542885528856288572885828859288602886128862288632886428865288662886728868288692887028871288722887328874288752887628877288782887928880288812888228883288842888528886288872888828889288902889128892288932889428895288962889728898288992890028901289022890328904289052890628907289082890928910289112891228913289142891528916289172891828919289202892128922289232892428925289262892728928289292893028931289322893328934289352893628937289382893928940289412894228943289442894528946289472894828949289502895128952289532895428955289562895728958289592896028961289622896328964289652896628967289682896928970289712897228973289742897528976289772897828979289802898128982289832898428985289862898728988289892899028991289922899328994289952899628997289982899929000290012900229003290042900529006290072900829009290102901129012290132901429015290162901729018290192902029021290222902329024290252902629027290282902929030290312903229033290342903529036290372903829039290402904129042290432904429045290462904729048290492905029051290522905329054290552905629057290582905929060290612906229063290642906529066290672906829069290702907129072290732907429075290762907729078290792908029081290822908329084290852908629087290882908929090290912909229093290942909529096290972909829099291002910129102291032910429105291062910729108291092911029111291122911329114291152911629117291182911929120291212912229123291242912529126291272912829129291302913129132291332913429135291362913729138291392914029141291422914329144291452914629147291482914929150291512915229153291542915529156291572915829159291602916129162291632916429165291662916729168291692917029171291722917329174291752917629177291782917929180291812918229183291842918529186291872918829189291902919129192291932919429195291962919729198291992920029201292022920329204292052920629207292082920929210292112921229213292142921529216292172921829219292202922129222292232922429225292262922729228292292923029231292322923329234292352923629237292382923929240292412924229243292442924529246292472924829249292502925129252292532925429255292562925729258292592926029261292622926329264292652926629267292682926929270292712927229273292742927529276292772927829279292802928129282292832928429285292862928729288292892929029291292922929329294292952929629297292982929929300293012930229303293042930529306293072930829309293102931129312293132931429315293162931729318293192932029321293222932329324293252932629327293282932929330293312933229333293342933529336293372933829339293402934129342293432934429345293462934729348293492935029351293522935329354293552935629357293582935929360293612936229363293642936529366293672936829369293702937129372293732937429375293762937729378293792938029381293822938329384293852938629387293882938929390293912939229393293942939529396293972939829399294002940129402294032940429405294062940729408294092941029411294122941329414294152941629417294182941929420294212942229423294242942529426294272942829429294302943129432294332943429435294362943729438294392944029441294422944329444294452944629447294482944929450294512945229453294542945529456294572945829459294602946129462294632946429465294662946729468294692947029471294722947329474294752947629477294782947929480294812948229483294842948529486294872948829489294902949129492294932949429495294962949729498294992950029501295022950329504295052950629507295082950929510295112951229513295142951529516295172951829519295202952129522295232952429525295262952729528295292953029531295322953329534295352953629537295382953929540295412954229543295442954529546295472954829549295502955129552295532955429555295562955729558295592956029561295622956329564295652956629567295682956929570295712957229573295742957529576295772957829579295802958129582295832958429585295862958729588295892959029591295922959329594295952959629597295982959929600296012960229603296042960529606296072960829609296102961129612296132961429615296162961729618296192962029621296222962329624296252962629627296282962929630296312963229633296342963529636296372963829639296402964129642296432964429645296462964729648296492965029651296522965329654296552965629657296582965929660296612966229663296642966529666296672966829669296702967129672296732967429675296762967729678296792968029681296822968329684296852968629687296882968929690296912969229693296942969529696296972969829699297002970129702297032970429705297062970729708297092971029711297122971329714297152971629717297182971929720297212972229723297242972529726297272972829729297302973129732297332973429735297362973729738297392974029741297422974329744297452974629747297482974929750297512975229753297542975529756297572975829759297602976129762297632976429765297662976729768297692977029771297722977329774297752977629777297782977929780297812978229783297842978529786297872978829789297902979129792297932979429795297962979729798297992980029801298022980329804298052980629807298082980929810298112981229813298142981529816298172981829819298202982129822298232982429825298262982729828298292983029831298322983329834298352983629837298382983929840298412984229843298442984529846298472984829849298502985129852298532985429855298562985729858298592986029861298622986329864298652986629867298682986929870298712987229873298742987529876298772987829879298802988129882298832988429885298862988729888298892989029891298922989329894298952989629897298982989929900299012990229903299042990529906299072990829909299102991129912299132991429915299162991729918299192992029921299222992329924299252992629927299282992929930299312993229933299342993529936299372993829939299402994129942299432994429945299462994729948299492995029951299522995329954299552995629957299582995929960299612996229963299642996529966299672996829969299702997129972299732997429975299762997729978299792998029981299822998329984299852998629987299882998929990299912999229993299942999529996299972999829999300003000130002300033000430005300063000730008300093001030011300123001330014300153001630017300183001930020300213002230023300243002530026300273002830029300303003130032300333003430035300363003730038300393004030041300423004330044300453004630047300483004930050300513005230053300543005530056300573005830059300603006130062300633006430065300663006730068300693007030071300723007330074300753007630077300783007930080300813008230083300843008530086300873008830089300903009130092300933009430095300963009730098300993010030101301023010330104301053010630107301083010930110301113011230113301143011530116301173011830119301203012130122301233012430125301263012730128301293013030131301323013330134301353013630137301383013930140301413014230143301443014530146301473014830149301503015130152301533015430155301563015730158301593016030161301623016330164301653016630167301683016930170301713017230173301743017530176301773017830179301803018130182301833018430185301863018730188301893019030191301923019330194301953019630197301983019930200302013020230203302043020530206302073020830209302103021130212302133021430215302163021730218302193022030221302223022330224302253022630227302283022930230302313023230233302343023530236302373023830239302403024130242302433024430245302463024730248302493025030251302523025330254302553025630257302583025930260302613026230263302643026530266302673026830269302703027130272302733027430275302763027730278302793028030281302823028330284302853028630287302883028930290302913029230293302943029530296302973029830299303003030130302303033030430305303063030730308303093031030311303123031330314303153031630317303183031930320303213032230323303243032530326303273032830329303303033130332303333033430335303363033730338303393034030341303423034330344303453034630347303483034930350303513035230353303543035530356303573035830359303603036130362303633036430365303663036730368303693037030371303723037330374303753037630377303783037930380303813038230383303843038530386303873038830389303903039130392303933039430395303963039730398303993040030401304023040330404304053040630407304083040930410304113041230413304143041530416304173041830419304203042130422304233042430425304263042730428304293043030431304323043330434304353043630437304383043930440304413044230443304443044530446304473044830449304503045130452304533045430455304563045730458304593046030461304623046330464304653046630467304683046930470304713047230473304743047530476304773047830479304803048130482304833048430485304863048730488304893049030491304923049330494304953049630497304983049930500305013050230503305043050530506305073050830509305103051130512305133051430515305163051730518305193052030521305223052330524305253052630527305283052930530305313053230533305343053530536305373053830539305403054130542305433054430545305463054730548305493055030551305523055330554305553055630557305583055930560305613056230563305643056530566305673056830569305703057130572305733057430575305763057730578305793058030581305823058330584305853058630587305883058930590305913059230593305943059530596305973059830599306003060130602306033060430605306063060730608306093061030611306123061330614306153061630617306183061930620306213062230623306243062530626306273062830629306303063130632306333063430635306363063730638306393064030641306423064330644306453064630647306483064930650306513065230653306543065530656306573065830659306603066130662306633066430665306663066730668306693067030671306723067330674306753067630677306783067930680306813068230683306843068530686306873068830689306903069130692306933069430695306963069730698306993070030701307023070330704307053070630707307083070930710307113071230713307143071530716307173071830719307203072130722307233072430725307263072730728307293073030731307323073330734307353073630737307383073930740307413074230743307443074530746307473074830749307503075130752307533075430755307563075730758307593076030761307623076330764307653076630767307683076930770307713077230773307743077530776307773077830779307803078130782307833078430785307863078730788307893079030791307923079330794307953079630797307983079930800308013080230803308043080530806308073080830809308103081130812308133081430815308163081730818308193082030821308223082330824308253082630827308283082930830308313083230833308343083530836308373083830839308403084130842308433084430845308463084730848308493085030851308523085330854308553085630857308583085930860308613086230863308643086530866308673086830869308703087130872308733087430875308763087730878308793088030881308823088330884308853088630887308883088930890308913089230893308943089530896308973089830899309003090130902309033090430905309063090730908309093091030911309123091330914309153091630917309183091930920309213092230923309243092530926309273092830929309303093130932309333093430935309363093730938309393094030941309423094330944309453094630947309483094930950309513095230953309543095530956309573095830959309603096130962309633096430965309663096730968309693097030971309723097330974309753097630977309783097930980309813098230983309843098530986309873098830989309903099130992309933099430995309963099730998309993100031001310023100331004310053100631007310083100931010310113101231013310143101531016310173101831019310203102131022310233102431025310263102731028310293103031031310323103331034310353103631037310383103931040310413104231043310443104531046310473104831049310503105131052310533105431055310563105731058310593106031061310623106331064310653106631067310683106931070310713107231073310743107531076310773107831079310803108131082310833108431085310863108731088310893109031091310923109331094310953109631097310983109931100311013110231103311043110531106311073110831109311103111131112311133111431115311163111731118311193112031121311223112331124311253112631127311283112931130311313113231133311343113531136311373113831139311403114131142311433114431145311463114731148311493115031151311523115331154311553115631157311583115931160311613116231163311643116531166311673116831169311703117131172311733117431175311763117731178311793118031181311823118331184311853118631187311883118931190311913119231193311943119531196311973119831199312003120131202312033120431205312063120731208312093121031211312123121331214312153121631217312183121931220312213122231223312243122531226312273122831229312303123131232312333123431235312363123731238312393124031241312423124331244312453124631247312483124931250312513125231253312543125531256312573125831259312603126131262312633126431265312663126731268312693127031271312723127331274312753127631277312783127931280312813128231283312843128531286312873128831289312903129131292312933129431295312963129731298312993130031301313023130331304313053130631307313083130931310313113131231313313143131531316313173131831319313203132131322313233132431325313263132731328313293133031331313323133331334313353133631337313383133931340313413134231343313443134531346313473134831349313503135131352313533135431355313563135731358313593136031361313623136331364313653136631367313683136931370313713137231373313743137531376313773137831379313803138131382313833138431385313863138731388313893139031391313923139331394313953139631397313983139931400314013140231403314043140531406314073140831409314103141131412314133141431415314163141731418314193142031421314223142331424314253142631427314283142931430314313143231433314343143531436314373143831439314403144131442314433144431445314463144731448314493145031451314523145331454314553145631457314583145931460314613146231463314643146531466314673146831469314703147131472314733147431475314763147731478314793148031481314823148331484314853148631487314883148931490314913149231493314943149531496314973149831499315003150131502315033150431505315063150731508315093151031511315123151331514315153151631517315183151931520315213152231523315243152531526315273152831529315303153131532315333153431535315363153731538315393154031541315423154331544315453154631547315483154931550315513155231553315543155531556315573155831559315603156131562315633156431565315663156731568315693157031571315723157331574315753157631577315783157931580315813158231583315843158531586315873158831589315903159131592315933159431595315963159731598315993160031601316023160331604316053160631607316083160931610316113161231613316143161531616316173161831619316203162131622316233162431625316263162731628316293163031631316323163331634316353163631637316383163931640316413164231643316443164531646316473164831649316503165131652316533165431655316563165731658316593166031661316623166331664316653166631667316683166931670316713167231673316743167531676316773167831679316803168131682316833168431685316863168731688316893169031691316923169331694316953169631697316983169931700317013170231703317043170531706317073170831709317103171131712317133171431715317163171731718317193172031721317223172331724317253172631727317283172931730317313173231733317343173531736317373173831739317403174131742317433174431745317463174731748317493175031751317523175331754317553175631757317583175931760317613176231763317643176531766317673176831769317703177131772317733177431775317763177731778317793178031781317823178331784317853178631787317883178931790317913179231793317943179531796317973179831799318003180131802318033180431805318063180731808318093181031811318123181331814318153181631817318183181931820318213182231823318243182531826318273182831829318303183131832318333183431835318363183731838318393184031841318423184331844318453184631847318483184931850318513185231853318543185531856318573185831859318603186131862318633186431865318663186731868318693187031871318723187331874318753187631877318783187931880318813188231883318843188531886318873188831889318903189131892318933189431895318963189731898318993190031901319023190331904319053190631907319083190931910319113191231913319143191531916319173191831919319203192131922319233192431925319263192731928319293193031931319323193331934319353193631937319383193931940319413194231943319443194531946319473194831949319503195131952319533195431955319563195731958319593196031961319623196331964319653196631967319683196931970319713197231973319743197531976319773197831979319803198131982319833198431985319863198731988319893199031991319923199331994319953199631997319983199932000320013200232003320043200532006320073200832009320103201132012320133201432015320163201732018320193202032021320223202332024320253202632027320283202932030320313203232033320343203532036320373203832039320403204132042320433204432045320463204732048320493205032051320523205332054320553205632057320583205932060320613206232063320643206532066320673206832069320703207132072320733207432075320763207732078320793208032081320823208332084320853208632087320883208932090320913209232093320943209532096320973209832099321003210132102321033210432105321063210732108321093211032111321123211332114321153211632117321183211932120321213212232123321243212532126321273212832129321303213132132321333213432135321363213732138321393214032141321423214332144321453214632147321483214932150321513215232153321543215532156321573215832159321603216132162321633216432165321663216732168321693217032171321723217332174321753217632177321783217932180321813218232183321843218532186321873218832189321903219132192321933219432195321963219732198321993220032201322023220332204322053220632207322083220932210322113221232213322143221532216322173221832219322203222132222322233222432225322263222732228322293223032231322323223332234322353223632237322383223932240322413224232243322443224532246322473224832249322503225132252322533225432255322563225732258322593226032261322623226332264322653226632267322683226932270322713227232273322743227532276322773227832279322803228132282322833228432285322863228732288322893229032291322923229332294322953229632297322983229932300323013230232303323043230532306323073230832309323103231132312323133231432315323163231732318323193232032321323223232332324323253232632327323283232932330323313233232333323343233532336323373233832339323403234132342323433234432345323463234732348323493235032351323523235332354323553235632357323583235932360323613236232363323643236532366323673236832369323703237132372323733237432375323763237732378323793238032381323823238332384323853238632387323883238932390323913239232393323943239532396323973239832399324003240132402324033240432405324063240732408324093241032411324123241332414324153241632417324183241932420324213242232423324243242532426324273242832429324303243132432324333243432435324363243732438324393244032441324423244332444324453244632447324483244932450324513245232453324543245532456324573245832459324603246132462324633246432465324663246732468324693247032471324723247332474324753247632477324783247932480324813248232483324843248532486324873248832489324903249132492324933249432495324963249732498324993250032501325023250332504325053250632507325083250932510325113251232513325143251532516325173251832519325203252132522325233252432525325263252732528325293253032531325323253332534325353253632537325383253932540325413254232543325443254532546325473254832549325503255132552325533255432555325563255732558325593256032561325623256332564325653256632567325683256932570325713257232573325743257532576325773257832579325803258132582325833258432585325863258732588325893259032591325923259332594325953259632597325983259932600326013260232603326043260532606326073260832609326103261132612326133261432615326163261732618326193262032621326223262332624326253262632627326283262932630326313263232633326343263532636326373263832639326403264132642326433264432645326463264732648326493265032651326523265332654326553265632657326583265932660326613266232663326643266532666326673266832669326703267132672326733267432675326763267732678326793268032681326823268332684326853268632687326883268932690326913269232693326943269532696326973269832699327003270132702327033270432705327063270732708327093271032711327123271332714327153271632717327183271932720327213272232723327243272532726327273272832729327303273132732327333273432735327363273732738327393274032741327423274332744327453274632747327483274932750327513275232753327543275532756327573275832759327603276132762327633276432765327663276732768327693277032771327723277332774327753277632777327783277932780327813278232783327843278532786327873278832789327903279132792327933279432795327963279732798327993280032801328023280332804328053280632807328083280932810328113281232813328143281532816328173281832819328203282132822328233282432825328263282732828328293283032831328323283332834328353283632837328383283932840328413284232843328443284532846328473284832849328503285132852328533285432855328563285732858328593286032861328623286332864328653286632867328683286932870328713287232873328743287532876328773287832879328803288132882328833288432885328863288732888328893289032891328923289332894328953289632897328983289932900329013290232903329043290532906329073290832909329103291132912329133291432915329163291732918329193292032921329223292332924329253292632927329283292932930329313293232933329343293532936329373293832939329403294132942329433294432945329463294732948329493295032951329523295332954329553295632957329583295932960329613296232963329643296532966329673296832969329703297132972329733297432975329763297732978329793298032981329823298332984329853298632987329883298932990329913299232993329943299532996329973299832999330003300133002330033300433005330063300733008330093301033011330123301333014330153301633017330183301933020330213302233023330243302533026330273302833029330303303133032330333303433035330363303733038330393304033041330423304333044330453304633047330483304933050330513305233053330543305533056330573305833059330603306133062330633306433065330663306733068330693307033071330723307333074330753307633077330783307933080330813308233083330843308533086330873308833089330903309133092330933309433095330963309733098330993310033101331023310333104331053310633107331083310933110331113311233113331143311533116331173311833119331203312133122331233312433125331263312733128331293313033131331323313333134331353313633137331383313933140331413314233143331443314533146331473314833149331503315133152331533315433155331563315733158331593316033161331623316333164331653316633167331683316933170331713317233173331743317533176331773317833179331803318133182331833318433185331863318733188331893319033191331923319333194331953319633197331983319933200332013320233203332043320533206332073320833209332103321133212332133321433215332163321733218332193322033221332223322333224332253322633227332283322933230332313323233233332343323533236332373323833239332403324133242332433324433245332463324733248332493325033251332523325333254332553325633257332583325933260332613326233263332643326533266332673326833269332703327133272332733327433275332763327733278332793328033281332823328333284332853328633287332883328933290332913329233293332943329533296332973329833299333003330133302333033330433305333063330733308333093331033311333123331333314333153331633317333183331933320333213332233323333243332533326333273332833329333303333133332333333333433335333363333733338333393334033341333423334333344333453334633347333483334933350333513335233353333543335533356333573335833359333603336133362333633336433365333663336733368333693337033371333723337333374333753337633377333783337933380333813338233383333843338533386333873338833389333903339133392333933339433395333963339733398333993340033401334023340333404334053340633407334083340933410334113341233413334143341533416334173341833419334203342133422334233342433425334263342733428334293343033431334323343333434334353343633437334383343933440334413344233443334443344533446334473344833449334503345133452334533345433455334563345733458334593346033461334623346333464334653346633467334683346933470334713347233473334743347533476334773347833479334803348133482334833348433485334863348733488334893349033491334923349333494334953349633497334983349933500335013350233503335043350533506335073350833509335103351133512335133351433515335163351733518335193352033521335223352333524335253352633527335283352933530335313353233533335343353533536335373353833539335403354133542335433354433545335463354733548335493355033551335523355333554335553355633557335583355933560335613356233563335643356533566335673356833569335703357133572335733357433575335763357733578335793358033581335823358333584335853358633587335883358933590335913359233593335943359533596335973359833599336003360133602336033360433605336063360733608336093361033611336123361333614336153361633617336183361933620336213362233623336243362533626336273362833629336303363133632336333363433635336363363733638336393364033641336423364333644336453364633647336483364933650336513365233653336543365533656336573365833659336603366133662336633366433665336663366733668336693367033671336723367333674336753367633677336783367933680336813368233683336843368533686336873368833689336903369133692336933369433695336963369733698336993370033701337023370333704337053370633707337083370933710337113371233713337143371533716337173371833719337203372133722337233372433725337263372733728337293373033731337323373333734337353373633737337383373933740337413374233743337443374533746337473374833749337503375133752337533375433755337563375733758337593376033761337623376333764337653376633767337683376933770337713377233773337743377533776337773377833779337803378133782337833378433785337863378733788337893379033791337923379333794337953379633797337983379933800338013380233803338043380533806338073380833809338103381133812338133381433815338163381733818338193382033821338223382333824338253382633827338283382933830338313383233833338343383533836338373383833839338403384133842338433384433845338463384733848338493385033851338523385333854338553385633857338583385933860338613386233863338643386533866338673386833869338703387133872338733387433875338763387733878338793388033881338823388333884338853388633887338883388933890338913389233893338943389533896338973389833899339003390133902339033390433905339063390733908339093391033911339123391333914339153391633917339183391933920339213392233923339243392533926339273392833929339303393133932339333393433935339363393733938339393394033941339423394333944339453394633947339483394933950339513395233953339543395533956339573395833959339603396133962339633396433965339663396733968339693397033971339723397333974339753397633977339783397933980339813398233983339843398533986339873398833989339903399133992339933399433995339963399733998339993400034001340023400334004340053400634007340083400934010340113401234013340143401534016340173401834019340203402134022340233402434025340263402734028340293403034031340323403334034340353403634037340383403934040340413404234043340443404534046340473404834049340503405134052340533405434055340563405734058340593406034061340623406334064340653406634067340683406934070340713407234073340743407534076340773407834079340803408134082340833408434085340863408734088340893409034091340923409334094340953409634097340983409934100341013410234103341043410534106341073410834109341103411134112341133411434115341163411734118341193412034121341223412334124341253412634127341283412934130341313413234133341343413534136341373413834139341403414134142341433414434145341463414734148341493415034151341523415334154341553415634157341583415934160341613416234163341643416534166341673416834169341703417134172341733417434175341763417734178341793418034181341823418334184341853418634187341883418934190341913419234193341943419534196341973419834199342003420134202342033420434205342063420734208342093421034211342123421334214342153421634217342183421934220342213422234223342243422534226342273422834229342303423134232342333423434235342363423734238342393424034241342423424334244342453424634247342483424934250342513425234253342543425534256342573425834259342603426134262342633426434265342663426734268342693427034271342723427334274342753427634277342783427934280342813428234283342843428534286342873428834289342903429134292342933429434295342963429734298342993430034301343023430334304343053430634307343083430934310343113431234313343143431534316343173431834319343203432134322343233432434325343263432734328343293433034331343323433334334343353433634337343383433934340343413434234343343443434534346343473434834349343503435134352343533435434355343563435734358343593436034361343623436334364343653436634367343683436934370343713437234373343743437534376343773437834379343803438134382343833438434385343863438734388343893439034391343923439334394343953439634397343983439934400344013440234403344043440534406344073440834409344103441134412344133441434415344163441734418344193442034421344223442334424344253442634427344283442934430344313443234433344343443534436344373443834439344403444134442344433444434445344463444734448344493445034451344523445334454344553445634457344583445934460344613446234463344643446534466344673446834469344703447134472344733447434475344763447734478344793448034481344823448334484344853448634487344883448934490344913449234493344943449534496344973449834499345003450134502345033450434505345063450734508345093451034511345123451334514345153451634517345183451934520345213452234523345243452534526345273452834529345303453134532345333453434535345363453734538345393454034541345423454334544345453454634547345483454934550345513455234553345543455534556345573455834559345603456134562345633456434565345663456734568345693457034571345723457334574345753457634577345783457934580345813458234583345843458534586345873458834589345903459134592345933459434595345963459734598345993460034601346023460334604346053460634607346083460934610346113461234613346143461534616346173461834619346203462134622346233462434625346263462734628346293463034631346323463334634346353463634637346383463934640346413464234643346443464534646346473464834649346503465134652346533465434655346563465734658346593466034661346623466334664346653466634667346683466934670346713467234673346743467534676346773467834679346803468134682346833468434685346863468734688346893469034691346923469334694346953469634697346983469934700347013470234703347043470534706347073470834709347103471134712347133471434715347163471734718347193472034721347223472334724347253472634727347283472934730347313473234733347343473534736347373473834739347403474134742347433474434745347463474734748347493475034751347523475334754347553475634757347583475934760347613476234763347643476534766347673476834769347703477134772347733477434775347763477734778347793478034781347823478334784347853478634787347883478934790347913479234793347943479534796347973479834799348003480134802348033480434805348063480734808348093481034811348123481334814348153481634817348183481934820348213482234823348243482534826348273482834829348303483134832348333483434835348363483734838348393484034841348423484334844348453484634847348483484934850348513485234853348543485534856348573485834859348603486134862348633486434865348663486734868348693487034871348723487334874348753487634877348783487934880348813488234883348843488534886348873488834889348903489134892348933489434895348963489734898348993490034901349023490334904349053490634907349083490934910349113491234913349143491534916349173491834919349203492134922349233492434925349263492734928349293493034931349323493334934349353493634937349383493934940349413494234943349443494534946349473494834949349503495134952349533495434955349563495734958349593496034961349623496334964349653496634967349683496934970349713497234973349743497534976349773497834979349803498134982349833498434985349863498734988349893499034991349923499334994349953499634997349983499935000350013500235003350043500535006350073500835009350103501135012350133501435015350163501735018350193502035021350223502335024350253502635027350283502935030350313503235033350343503535036350373503835039350403504135042350433504435045350463504735048350493505035051350523505335054350553505635057350583505935060350613506235063350643506535066350673506835069350703507135072350733507435075350763507735078350793508035081350823508335084350853508635087350883508935090350913509235093350943509535096350973509835099351003510135102351033510435105351063510735108351093511035111351123511335114351153511635117351183511935120351213512235123351243512535126351273512835129351303513135132351333513435135351363513735138351393514035141351423514335144351453514635147351483514935150351513515235153351543515535156351573515835159351603516135162351633516435165351663516735168351693517035171351723517335174351753517635177351783517935180351813518235183351843518535186351873518835189351903519135192351933519435195351963519735198351993520035201352023520335204352053520635207352083520935210352113521235213352143521535216352173521835219352203522135222352233522435225352263522735228352293523035231352323523335234352353523635237352383523935240352413524235243352443524535246352473524835249352503525135252352533525435255352563525735258352593526035261352623526335264352653526635267352683526935270352713527235273352743527535276352773527835279352803528135282352833528435285352863528735288352893529035291352923529335294352953529635297352983529935300353013530235303353043530535306353073530835309353103531135312353133531435315353163531735318353193532035321353223532335324353253532635327353283532935330353313533235333353343533535336353373533835339353403534135342353433534435345353463534735348353493535035351353523535335354353553535635357353583535935360353613536235363353643536535366353673536835369353703537135372353733537435375353763537735378353793538035381353823538335384353853538635387353883538935390353913539235393353943539535396353973539835399354003540135402354033540435405354063540735408354093541035411354123541335414354153541635417354183541935420354213542235423354243542535426354273542835429354303543135432354333543435435354363543735438354393544035441354423544335444354453544635447354483544935450354513545235453354543545535456354573545835459354603546135462354633546435465354663546735468354693547035471354723547335474354753547635477354783547935480354813548235483354843548535486354873548835489354903549135492354933549435495354963549735498354993550035501355023550335504355053550635507355083550935510355113551235513355143551535516355173551835519355203552135522355233552435525355263552735528355293553035531355323553335534355353553635537355383553935540355413554235543355443554535546355473554835549355503555135552355533555435555355563555735558355593556035561355623556335564355653556635567355683556935570355713557235573355743557535576355773557835579355803558135582355833558435585355863558735588355893559035591355923559335594355953559635597355983559935600356013560235603356043560535606356073560835609356103561135612356133561435615356163561735618356193562035621356223562335624356253562635627356283562935630356313563235633356343563535636356373563835639356403564135642356433564435645356463564735648356493565035651356523565335654356553565635657356583565935660356613566235663356643566535666356673566835669356703567135672356733567435675356763567735678356793568035681356823568335684356853568635687356883568935690356913569235693356943569535696356973569835699357003570135702357033570435705357063570735708357093571035711357123571335714357153571635717357183571935720357213572235723357243572535726357273572835729357303573135732357333573435735357363573735738357393574035741357423574335744357453574635747357483574935750357513575235753357543575535756357573575835759357603576135762357633576435765357663576735768357693577035771357723577335774357753577635777357783577935780357813578235783357843578535786357873578835789357903579135792357933579435795357963579735798357993580035801358023580335804358053580635807358083580935810358113581235813358143581535816358173581835819358203582135822358233582435825358263582735828358293583035831358323583335834358353583635837358383583935840358413584235843358443584535846358473584835849358503585135852358533585435855358563585735858358593586035861358623586335864358653586635867358683586935870358713587235873358743587535876358773587835879358803588135882358833588435885358863588735888358893589035891358923589335894358953589635897358983589935900359013590235903359043590535906359073590835909359103591135912359133591435915359163591735918359193592035921359223592335924359253592635927359283592935930359313593235933359343593535936359373593835939359403594135942359433594435945359463594735948359493595035951359523595335954359553595635957359583595935960359613596235963359643596535966359673596835969359703597135972359733597435975359763597735978359793598035981359823598335984359853598635987359883598935990359913599235993359943599535996359973599835999360003600136002360033600436005360063600736008360093601036011360123601336014360153601636017360183601936020360213602236023360243602536026360273602836029360303603136032360333603436035360363603736038360393604036041360423604336044360453604636047360483604936050360513605236053360543605536056360573605836059360603606136062360633606436065360663606736068360693607036071360723607336074360753607636077360783607936080360813608236083360843608536086360873608836089360903609136092360933609436095360963609736098360993610036101361023610336104361053610636107361083610936110361113611236113361143611536116361173611836119361203612136122361233612436125361263612736128361293613036131361323613336134361353613636137361383613936140361413614236143361443614536146361473614836149361503615136152361533615436155361563615736158361593616036161361623616336164361653616636167361683616936170361713617236173361743617536176361773617836179361803618136182361833618436185361863618736188361893619036191361923619336194361953619636197361983619936200362013620236203362043620536206362073620836209362103621136212362133621436215362163621736218362193622036221362223622336224362253622636227362283622936230362313623236233362343623536236362373623836239362403624136242362433624436245362463624736248362493625036251362523625336254362553625636257362583625936260362613626236263362643626536266362673626836269362703627136272362733627436275362763627736278362793628036281362823628336284362853628636287362883628936290362913629236293362943629536296362973629836299363003630136302363033630436305363063630736308363093631036311363123631336314363153631636317363183631936320363213632236323363243632536326363273632836329363303633136332363333633436335363363633736338363393634036341363423634336344363453634636347363483634936350363513635236353363543635536356363573635836359363603636136362363633636436365363663636736368363693637036371363723637336374363753637636377363783637936380363813638236383363843638536386363873638836389363903639136392363933639436395363963639736398363993640036401364023640336404364053640636407364083640936410364113641236413364143641536416364173641836419364203642136422364233642436425364263642736428364293643036431364323643336434364353643636437364383643936440364413644236443364443644536446364473644836449364503645136452364533645436455364563645736458364593646036461364623646336464364653646636467364683646936470364713647236473364743647536476364773647836479364803648136482364833648436485364863648736488364893649036491364923649336494364953649636497364983649936500365013650236503365043650536506365073650836509365103651136512365133651436515365163651736518365193652036521365223652336524365253652636527365283652936530365313653236533365343653536536365373653836539365403654136542365433654436545365463654736548365493655036551365523655336554365553655636557365583655936560365613656236563365643656536566365673656836569365703657136572365733657436575365763657736578365793658036581365823658336584365853658636587365883658936590365913659236593365943659536596365973659836599366003660136602366033660436605366063660736608366093661036611366123661336614366153661636617366183661936620366213662236623366243662536626366273662836629366303663136632366333663436635366363663736638366393664036641366423664336644366453664636647366483664936650366513665236653366543665536656366573665836659366603666136662366633666436665366663666736668366693667036671366723667336674366753667636677366783667936680366813668236683366843668536686366873668836689366903669136692366933669436695366963669736698366993670036701367023670336704367053670636707367083670936710367113671236713367143671536716367173671836719367203672136722367233672436725367263672736728367293673036731367323673336734367353673636737367383673936740367413674236743367443674536746367473674836749367503675136752367533675436755367563675736758367593676036761367623676336764367653676636767367683676936770367713677236773367743677536776367773677836779367803678136782367833678436785367863678736788367893679036791367923679336794367953679636797367983679936800368013680236803368043680536806368073680836809368103681136812368133681436815368163681736818368193682036821368223682336824368253682636827368283682936830368313683236833368343683536836368373683836839368403684136842368433684436845368463684736848368493685036851368523685336854368553685636857368583685936860368613686236863368643686536866368673686836869368703687136872368733687436875368763687736878368793688036881368823688336884368853688636887368883688936890368913689236893368943689536896368973689836899369003690136902369033690436905369063690736908369093691036911369123691336914369153691636917369183691936920369213692236923369243692536926369273692836929369303693136932369333693436935369363693736938369393694036941369423694336944369453694636947369483694936950369513695236953369543695536956369573695836959369603696136962369633696436965369663696736968369693697036971369723697336974369753697636977369783697936980369813698236983369843698536986369873698836989369903699136992369933699436995369963699736998369993700037001370023700337004370053700637007370083700937010370113701237013370143701537016370173701837019370203702137022370233702437025370263702737028370293703037031370323703337034370353703637037370383703937040370413704237043370443704537046370473704837049370503705137052370533705437055370563705737058370593706037061370623706337064370653706637067370683706937070370713707237073370743707537076370773707837079370803708137082370833708437085370863708737088370893709037091370923709337094370953709637097370983709937100371013710237103371043710537106371073710837109371103711137112371133711437115371163711737118371193712037121371223712337124371253712637127371283712937130371313713237133371343713537136371373713837139371403714137142371433714437145371463714737148371493715037151371523715337154371553715637157371583715937160371613716237163371643716537166371673716837169371703717137172371733717437175371763717737178371793718037181371823718337184371853718637187371883718937190371913719237193371943719537196371973719837199372003720137202372033720437205372063720737208372093721037211372123721337214372153721637217372183721937220372213722237223372243722537226372273722837229372303723137232372333723437235372363723737238372393724037241372423724337244372453724637247372483724937250372513725237253372543725537256372573725837259372603726137262372633726437265372663726737268372693727037271372723727337274372753727637277372783727937280372813728237283372843728537286372873728837289372903729137292372933729437295372963729737298372993730037301373023730337304373053730637307373083730937310373113731237313373143731537316373173731837319373203732137322373233732437325373263732737328373293733037331373323733337334373353733637337373383733937340373413734237343373443734537346373473734837349373503735137352373533735437355373563735737358373593736037361373623736337364373653736637367373683736937370373713737237373373743737537376373773737837379373803738137382373833738437385373863738737388373893739037391373923739337394373953739637397373983739937400374013740237403374043740537406374073740837409374103741137412374133741437415374163741737418374193742037421374223742337424374253742637427374283742937430374313743237433374343743537436374373743837439374403744137442374433744437445374463744737448374493745037451374523745337454374553745637457374583745937460374613746237463374643746537466374673746837469374703747137472374733747437475374763747737478374793748037481374823748337484374853748637487374883748937490374913749237493374943749537496374973749837499375003750137502375033750437505375063750737508375093751037511375123751337514375153751637517375183751937520375213752237523375243752537526375273752837529375303753137532375333753437535375363753737538375393754037541375423754337544375453754637547375483754937550375513755237553375543755537556375573755837559375603756137562375633756437565375663756737568375693757037571375723757337574375753757637577375783757937580375813758237583375843758537586375873758837589375903759137592375933759437595375963759737598375993760037601376023760337604376053760637607376083760937610376113761237613376143761537616376173761837619376203762137622376233762437625376263762737628376293763037631376323763337634376353763637637376383763937640376413764237643376443764537646376473764837649376503765137652376533765437655376563765737658376593766037661376623766337664376653766637667376683766937670376713767237673376743767537676376773767837679376803768137682376833768437685376863768737688376893769037691376923769337694376953769637697376983769937700377013770237703377043770537706377073770837709377103771137712377133771437715377163771737718377193772037721377223772337724377253772637727377283772937730377313773237733377343773537736377373773837739377403774137742377433774437745377463774737748377493775037751377523775337754377553775637757377583775937760377613776237763377643776537766377673776837769377703777137772377733777437775377763777737778377793778037781377823778337784377853778637787377883778937790377913779237793377943779537796377973779837799378003780137802378033780437805378063780737808378093781037811378123781337814378153781637817378183781937820378213782237823378243782537826378273782837829378303783137832378333783437835378363783737838378393784037841378423784337844378453784637847378483784937850378513785237853378543785537856378573785837859378603786137862378633786437865378663786737868378693787037871378723787337874378753787637877378783787937880378813788237883378843788537886378873788837889378903789137892378933789437895378963789737898378993790037901379023790337904379053790637907379083790937910379113791237913379143791537916379173791837919379203792137922379233792437925379263792737928379293793037931379323793337934379353793637937379383793937940379413794237943379443794537946379473794837949379503795137952379533795437955379563795737958379593796037961379623796337964379653796637967379683796937970379713797237973379743797537976379773797837979379803798137982379833798437985379863798737988379893799037991379923799337994379953799637997379983799938000380013800238003380043800538006380073800838009380103801138012380133801438015380163801738018380193802038021380223802338024380253802638027380283802938030380313803238033380343803538036380373803838039380403804138042380433804438045380463804738048380493805038051380523805338054380553805638057380583805938060380613806238063380643806538066380673806838069380703807138072380733807438075380763807738078380793808038081380823808338084380853808638087380883808938090380913809238093380943809538096380973809838099381003810138102381033810438105381063810738108381093811038111381123811338114381153811638117381183811938120381213812238123381243812538126381273812838129381303813138132381333813438135381363813738138381393814038141381423814338144381453814638147381483814938150381513815238153381543815538156381573815838159381603816138162381633816438165381663816738168381693817038171381723817338174381753817638177381783817938180381813818238183381843818538186381873818838189381903819138192381933819438195381963819738198381993820038201382023820338204382053820638207382083820938210382113821238213382143821538216382173821838219382203822138222382233822438225382263822738228382293823038231382323823338234382353823638237382383823938240382413824238243382443824538246382473824838249382503825138252382533825438255382563825738258382593826038261382623826338264382653826638267382683826938270382713827238273382743827538276382773827838279382803828138282382833828438285382863828738288382893829038291382923829338294382953829638297382983829938300383013830238303383043830538306383073830838309383103831138312383133831438315383163831738318383193832038321383223832338324383253832638327383283832938330383313833238333383343833538336383373833838339383403834138342383433834438345383463834738348383493835038351383523835338354383553835638357383583835938360383613836238363383643836538366383673836838369383703837138372383733837438375383763837738378383793838038381383823838338384383853838638387383883838938390383913839238393383943839538396383973839838399384003840138402384033840438405384063840738408384093841038411384123841338414384153841638417384183841938420384213842238423384243842538426384273842838429384303843138432384333843438435384363843738438384393844038441384423844338444384453844638447384483844938450384513845238453384543845538456384573845838459384603846138462384633846438465384663846738468384693847038471384723847338474384753847638477384783847938480384813848238483384843848538486384873848838489384903849138492384933849438495384963849738498384993850038501385023850338504385053850638507385083850938510385113851238513385143851538516385173851838519385203852138522385233852438525385263852738528385293853038531385323853338534385353853638537385383853938540385413854238543385443854538546385473854838549385503855138552385533855438555385563855738558385593856038561385623856338564385653856638567385683856938570385713857238573385743857538576385773857838579385803858138582385833858438585385863858738588385893859038591385923859338594385953859638597385983859938600386013860238603386043860538606386073860838609386103861138612386133861438615386163861738618386193862038621386223862338624386253862638627386283862938630386313863238633386343863538636386373863838639386403864138642386433864438645386463864738648386493865038651386523865338654386553865638657386583865938660386613866238663386643866538666386673866838669386703867138672386733867438675386763867738678386793868038681386823868338684386853868638687386883868938690386913869238693386943869538696386973869838699387003870138702387033870438705387063870738708387093871038711387123871338714387153871638717387183871938720387213872238723387243872538726387273872838729387303873138732387333873438735387363873738738387393874038741387423874338744387453874638747387483874938750387513875238753387543875538756387573875838759387603876138762387633876438765387663876738768387693877038771387723877338774387753877638777387783877938780387813878238783387843878538786387873878838789387903879138792387933879438795387963879738798387993880038801388023880338804388053880638807388083880938810388113881238813388143881538816388173881838819388203882138822388233882438825388263882738828388293883038831388323883338834388353883638837388383883938840388413884238843388443884538846388473884838849388503885138852388533885438855388563885738858388593886038861388623886338864388653886638867388683886938870388713887238873388743887538876388773887838879388803888138882388833888438885388863888738888388893889038891388923889338894388953889638897388983889938900389013890238903389043890538906389073890838909389103891138912389133891438915389163891738918389193892038921389223892338924389253892638927389283892938930389313893238933389343893538936389373893838939389403894138942389433894438945389463894738948389493895038951389523895338954389553895638957389583895938960389613896238963389643896538966389673896838969389703897138972389733897438975389763897738978389793898038981389823898338984389853898638987389883898938990389913899238993389943899538996389973899838999390003900139002390033900439005390063900739008390093901039011390123901339014390153901639017390183901939020390213902239023390243902539026390273902839029390303903139032390333903439035390363903739038390393904039041390423904339044390453904639047390483904939050390513905239053390543905539056390573905839059390603906139062390633906439065390663906739068390693907039071390723907339074390753907639077390783907939080390813908239083390843908539086390873908839089390903909139092390933909439095390963909739098390993910039101391023910339104391053910639107391083910939110391113911239113391143911539116391173911839119391203912139122391233912439125391263912739128391293913039131391323913339134391353913639137391383913939140391413914239143391443914539146391473914839149391503915139152391533915439155391563915739158391593916039161391623916339164391653916639167391683916939170391713917239173391743917539176391773917839179391803918139182391833918439185391863918739188391893919039191391923919339194391953919639197391983919939200392013920239203392043920539206392073920839209392103921139212392133921439215392163921739218392193922039221392223922339224392253922639227392283922939230392313923239233392343923539236392373923839239392403924139242392433924439245392463924739248392493925039251392523925339254392553925639257392583925939260392613926239263392643926539266392673926839269392703927139272392733927439275392763927739278392793928039281392823928339284392853928639287392883928939290392913929239293392943929539296392973929839299393003930139302393033930439305393063930739308393093931039311393123931339314393153931639317393183931939320393213932239323393243932539326393273932839329393303933139332393333933439335393363933739338393393934039341393423934339344393453934639347393483934939350393513935239353393543935539356393573935839359393603936139362393633936439365393663936739368393693937039371393723937339374393753937639377393783937939380393813938239383393843938539386393873938839389393903939139392393933939439395393963939739398393993940039401394023940339404394053940639407394083940939410394113941239413394143941539416394173941839419394203942139422394233942439425394263942739428394293943039431394323943339434394353943639437394383943939440394413944239443394443944539446394473944839449394503945139452394533945439455394563945739458394593946039461394623946339464394653946639467394683946939470394713947239473394743947539476394773947839479394803948139482394833948439485394863948739488394893949039491394923949339494394953949639497394983949939500395013950239503395043950539506395073950839509395103951139512395133951439515395163951739518395193952039521395223952339524395253952639527395283952939530395313953239533395343953539536395373953839539395403954139542395433954439545395463954739548395493955039551395523955339554395553955639557395583955939560395613956239563395643956539566395673956839569395703957139572395733957439575395763957739578395793958039581395823958339584395853958639587395883958939590395913959239593395943959539596395973959839599396003960139602396033960439605396063960739608396093961039611396123961339614396153961639617396183961939620396213962239623396243962539626396273962839629396303963139632396333963439635396363963739638396393964039641396423964339644396453964639647396483964939650396513965239653396543965539656396573965839659396603966139662396633966439665396663966739668396693967039671396723967339674396753967639677396783967939680396813968239683396843968539686396873968839689396903969139692396933969439695396963969739698396993970039701397023970339704397053970639707397083970939710397113971239713397143971539716397173971839719397203972139722397233972439725397263972739728397293973039731397323973339734397353973639737397383973939740397413974239743397443974539746397473974839749397503975139752397533975439755397563975739758397593976039761397623976339764397653976639767397683976939770397713977239773397743977539776397773977839779397803978139782397833978439785397863978739788397893979039791397923979339794397953979639797397983979939800398013980239803398043980539806398073980839809398103981139812398133981439815398163981739818398193982039821398223982339824398253982639827398283982939830398313983239833398343983539836398373983839839398403984139842398433984439845398463984739848398493985039851398523985339854398553985639857398583985939860398613986239863398643986539866398673986839869398703987139872398733987439875398763987739878398793988039881398823988339884398853988639887398883988939890398913989239893398943989539896398973989839899399003990139902399033990439905399063990739908399093991039911399123991339914399153991639917399183991939920399213992239923399243992539926399273992839929399303993139932399333993439935399363993739938399393994039941399423994339944399453994639947399483994939950399513995239953399543995539956399573995839959399603996139962399633996439965399663996739968399693997039971399723997339974399753997639977399783997939980399813998239983399843998539986399873998839989399903999139992399933999439995399963999739998399994000040001400024000340004400054000640007400084000940010400114001240013400144001540016400174001840019400204002140022400234002440025400264002740028400294003040031400324003340034400354003640037400384003940040400414004240043400444004540046400474004840049400504005140052400534005440055400564005740058400594006040061400624006340064400654006640067400684006940070400714007240073400744007540076400774007840079400804008140082400834008440085400864008740088400894009040091400924009340094400954009640097400984009940100401014010240103401044010540106401074010840109401104011140112401134011440115401164011740118401194012040121401224012340124401254012640127401284012940130401314013240133401344013540136401374013840139401404014140142401434014440145401464014740148401494015040151401524015340154401554015640157401584015940160401614016240163401644016540166401674016840169401704017140172401734017440175401764017740178401794018040181401824018340184401854018640187401884018940190401914019240193401944019540196401974019840199402004020140202402034020440205402064020740208402094021040211402124021340214402154021640217402184021940220402214022240223402244022540226402274022840229402304023140232402334023440235402364023740238402394024040241402424024340244402454024640247402484024940250402514025240253402544025540256402574025840259402604026140262402634026440265402664026740268402694027040271402724027340274402754027640277402784027940280402814028240283402844028540286402874028840289402904029140292402934029440295402964029740298402994030040301403024030340304403054030640307403084030940310403114031240313403144031540316403174031840319403204032140322403234032440325403264032740328403294033040331403324033340334403354033640337403384033940340403414034240343403444034540346403474034840349403504035140352403534035440355403564035740358403594036040361403624036340364403654036640367403684036940370403714037240373403744037540376403774037840379403804038140382403834038440385403864038740388403894039040391403924039340394403954039640397403984039940400404014040240403404044040540406404074040840409404104041140412404134041440415404164041740418404194042040421404224042340424404254042640427404284042940430404314043240433404344043540436404374043840439404404044140442404434044440445404464044740448404494045040451404524045340454404554045640457404584045940460404614046240463404644046540466404674046840469404704047140472404734047440475404764047740478404794048040481404824048340484404854048640487404884048940490404914049240493404944049540496404974049840499405004050140502405034050440505405064050740508405094051040511405124051340514405154051640517405184051940520405214052240523405244052540526405274052840529405304053140532405334053440535405364053740538405394054040541405424054340544405454054640547405484054940550405514055240553405544055540556405574055840559405604056140562405634056440565405664056740568405694057040571405724057340574405754057640577405784057940580405814058240583405844058540586405874058840589405904059140592405934059440595405964059740598405994060040601406024060340604406054060640607406084060940610406114061240613406144061540616406174061840619406204062140622406234062440625406264062740628406294063040631406324063340634406354063640637406384063940640406414064240643406444064540646406474064840649406504065140652406534065440655406564065740658406594066040661406624066340664406654066640667406684066940670406714067240673406744067540676406774067840679406804068140682406834068440685406864068740688406894069040691406924069340694406954069640697406984069940700407014070240703407044070540706407074070840709407104071140712407134071440715407164071740718407194072040721407224072340724407254072640727407284072940730407314073240733407344073540736407374073840739407404074140742407434074440745407464074740748407494075040751407524075340754407554075640757407584075940760407614076240763407644076540766407674076840769407704077140772407734077440775407764077740778407794078040781407824078340784407854078640787407884078940790407914079240793407944079540796407974079840799408004080140802408034080440805408064080740808408094081040811408124081340814408154081640817408184081940820408214082240823408244082540826408274082840829408304083140832408334083440835408364083740838408394084040841408424084340844408454084640847408484084940850408514085240853408544085540856408574085840859408604086140862408634086440865408664086740868408694087040871408724087340874408754087640877408784087940880408814088240883408844088540886408874088840889408904089140892408934089440895408964089740898408994090040901409024090340904409054090640907409084090940910409114091240913409144091540916409174091840919409204092140922409234092440925409264092740928409294093040931409324093340934409354093640937409384093940940409414094240943409444094540946409474094840949409504095140952409534095440955409564095740958409594096040961409624096340964409654096640967409684096940970409714097240973409744097540976409774097840979409804098140982409834098440985409864098740988409894099040991409924099340994409954099640997409984099941000410014100241003410044100541006410074100841009410104101141012410134101441015410164101741018410194102041021410224102341024410254102641027410284102941030410314103241033410344103541036410374103841039410404104141042410434104441045410464104741048410494105041051410524105341054410554105641057410584105941060410614106241063410644106541066410674106841069410704107141072410734107441075410764107741078410794108041081410824108341084410854108641087410884108941090410914109241093410944109541096410974109841099411004110141102411034110441105411064110741108411094111041111411124111341114411154111641117411184111941120411214112241123411244112541126411274112841129411304113141132411334113441135411364113741138411394114041141411424114341144411454114641147411484114941150411514115241153411544115541156411574115841159411604116141162411634116441165411664116741168411694117041171411724117341174411754117641177411784117941180411814118241183411844118541186411874118841189411904119141192411934119441195411964119741198411994120041201412024120341204412054120641207412084120941210412114121241213412144121541216412174121841219412204122141222412234122441225412264122741228412294123041231412324123341234412354123641237412384123941240412414124241243412444124541246412474124841249412504125141252412534125441255412564125741258412594126041261412624126341264412654126641267412684126941270412714127241273412744127541276412774127841279412804128141282412834128441285412864128741288412894129041291412924129341294412954129641297412984129941300413014130241303413044130541306413074130841309413104131141312413134131441315413164131741318413194132041321413224132341324413254132641327413284132941330413314133241333413344133541336413374133841339413404134141342413434134441345413464134741348413494135041351413524135341354413554135641357413584135941360413614136241363413644136541366413674136841369413704137141372413734137441375413764137741378413794138041381413824138341384413854138641387413884138941390413914139241393413944139541396413974139841399414004140141402414034140441405414064140741408414094141041411414124141341414414154141641417414184141941420414214142241423414244142541426414274142841429414304143141432414334143441435414364143741438414394144041441414424144341444414454144641447414484144941450414514145241453414544145541456414574145841459414604146141462414634146441465414664146741468414694147041471414724147341474414754147641477414784147941480414814148241483414844148541486414874148841489414904149141492414934149441495414964149741498414994150041501415024150341504415054150641507415084150941510415114151241513415144151541516415174151841519415204152141522415234152441525415264152741528415294153041531415324153341534415354153641537415384153941540415414154241543415444154541546415474154841549415504155141552415534155441555415564155741558415594156041561415624156341564415654156641567415684156941570415714157241573415744157541576415774157841579415804158141582415834158441585415864158741588415894159041591415924159341594415954159641597415984159941600416014160241603416044160541606416074160841609416104161141612416134161441615416164161741618416194162041621416224162341624416254162641627416284162941630416314163241633416344163541636416374163841639416404164141642416434164441645416464164741648416494165041651416524165341654416554165641657416584165941660416614166241663416644166541666416674166841669416704167141672416734167441675416764167741678416794168041681416824168341684416854168641687416884168941690416914169241693416944169541696416974169841699417004170141702417034170441705417064170741708417094171041711417124171341714417154171641717417184171941720417214172241723417244172541726417274172841729417304173141732417334173441735417364173741738417394174041741417424174341744417454174641747417484174941750417514175241753417544175541756417574175841759417604176141762417634176441765417664176741768417694177041771417724177341774417754177641777417784177941780417814178241783417844178541786417874178841789417904179141792417934179441795417964179741798417994180041801418024180341804418054180641807418084180941810418114181241813418144181541816418174181841819418204182141822418234182441825418264182741828418294183041831418324183341834418354183641837418384183941840418414184241843418444184541846418474184841849418504185141852418534185441855418564185741858418594186041861418624186341864418654186641867418684186941870418714187241873418744187541876418774187841879418804188141882418834188441885418864188741888418894189041891418924189341894418954189641897418984189941900419014190241903419044190541906419074190841909419104191141912419134191441915419164191741918419194192041921419224192341924419254192641927419284192941930419314193241933419344193541936419374193841939419404194141942419434194441945419464194741948419494195041951419524195341954419554195641957419584195941960419614196241963419644196541966419674196841969419704197141972419734197441975419764197741978419794198041981419824198341984419854198641987419884198941990419914199241993419944199541996419974199841999420004200142002420034200442005420064200742008420094201042011420124201342014420154201642017420184201942020420214202242023420244202542026420274202842029420304203142032420334203442035420364203742038420394204042041420424204342044420454204642047420484204942050420514205242053420544205542056420574205842059420604206142062420634206442065420664206742068420694207042071420724207342074420754207642077420784207942080420814208242083420844208542086420874208842089420904209142092420934209442095420964209742098420994210042101421024210342104421054210642107421084210942110421114211242113421144211542116421174211842119421204212142122421234212442125421264212742128421294213042131421324213342134421354213642137421384213942140421414214242143421444214542146421474214842149421504215142152421534215442155421564215742158421594216042161421624216342164421654216642167421684216942170421714217242173421744217542176421774217842179421804218142182421834218442185421864218742188421894219042191421924219342194421954219642197421984219942200422014220242203422044220542206422074220842209422104221142212422134221442215422164221742218422194222042221422224222342224422254222642227422284222942230422314223242233422344223542236422374223842239422404224142242422434224442245422464224742248422494225042251422524225342254422554225642257422584225942260422614226242263422644226542266422674226842269422704227142272422734227442275422764227742278422794228042281422824228342284422854228642287422884228942290422914229242293422944229542296422974229842299423004230142302423034230442305423064230742308423094231042311423124231342314423154231642317423184231942320423214232242323423244232542326423274232842329423304233142332423334233442335423364233742338423394234042341423424234342344423454234642347423484234942350423514235242353423544235542356423574235842359423604236142362423634236442365423664236742368423694237042371423724237342374423754237642377423784237942380423814238242383423844238542386423874238842389423904239142392423934239442395423964239742398423994240042401424024240342404424054240642407424084240942410424114241242413424144241542416424174241842419424204242142422424234242442425424264242742428424294243042431424324243342434424354243642437424384243942440424414244242443424444244542446424474244842449424504245142452424534245442455424564245742458424594246042461424624246342464424654246642467424684246942470424714247242473424744247542476424774247842479424804248142482424834248442485424864248742488424894249042491424924249342494424954249642497424984249942500425014250242503425044250542506425074250842509425104251142512425134251442515425164251742518425194252042521425224252342524425254252642527425284252942530425314253242533425344253542536425374253842539425404254142542425434254442545425464254742548425494255042551425524255342554425554255642557425584255942560425614256242563425644256542566425674256842569425704257142572425734257442575425764257742578425794258042581425824258342584425854258642587425884258942590425914259242593425944259542596425974259842599426004260142602426034260442605426064260742608426094261042611426124261342614426154261642617426184261942620426214262242623426244262542626426274262842629426304263142632426334263442635426364263742638426394264042641426424264342644426454264642647426484264942650426514265242653426544265542656426574265842659426604266142662426634266442665426664266742668426694267042671426724267342674426754267642677426784267942680426814268242683426844268542686426874268842689426904269142692426934269442695426964269742698426994270042701427024270342704427054270642707427084270942710427114271242713427144271542716427174271842719427204272142722427234272442725427264272742728427294273042731427324273342734427354273642737427384273942740427414274242743427444274542746427474274842749427504275142752427534275442755427564275742758427594276042761427624276342764427654276642767427684276942770427714277242773427744277542776427774277842779427804278142782427834278442785427864278742788427894279042791427924279342794427954279642797427984279942800428014280242803428044280542806428074280842809428104281142812428134281442815428164281742818428194282042821428224282342824428254282642827428284282942830428314283242833428344283542836428374283842839428404284142842428434284442845428464284742848428494285042851428524285342854428554285642857428584285942860428614286242863428644286542866428674286842869428704287142872428734287442875428764287742878428794288042881428824288342884428854288642887428884288942890428914289242893428944289542896428974289842899429004290142902429034290442905429064290742908429094291042911429124291342914429154291642917429184291942920429214292242923429244292542926429274292842929429304293142932429334293442935429364293742938429394294042941429424294342944429454294642947429484294942950429514295242953429544295542956429574295842959429604296142962429634296442965429664296742968429694297042971429724297342974429754297642977429784297942980429814298242983429844298542986429874298842989429904299142992429934299442995429964299742998429994300043001430024300343004430054300643007430084300943010430114301243013430144301543016430174301843019430204302143022430234302443025430264302743028430294303043031430324303343034430354303643037430384303943040430414304243043430444304543046430474304843049430504305143052430534305443055430564305743058430594306043061430624306343064430654306643067430684306943070430714307243073430744307543076430774307843079430804308143082430834308443085430864308743088430894309043091430924309343094430954309643097430984309943100431014310243103431044310543106431074310843109431104311143112431134311443115431164311743118431194312043121431224312343124431254312643127431284312943130431314313243133431344313543136431374313843139431404314143142431434314443145431464314743148431494315043151431524315343154431554315643157431584315943160431614316243163431644316543166431674316843169431704317143172431734317443175431764317743178431794318043181431824318343184431854318643187431884318943190431914319243193431944319543196431974319843199432004320143202432034320443205432064320743208432094321043211432124321343214432154321643217432184321943220432214322243223432244322543226432274322843229432304323143232432334323443235432364323743238432394324043241432424324343244432454324643247432484324943250432514325243253432544325543256432574325843259432604326143262432634326443265432664326743268432694327043271432724327343274432754327643277432784327943280432814328243283432844328543286432874328843289432904329143292432934329443295432964329743298432994330043301433024330343304433054330643307433084330943310433114331243313433144331543316433174331843319433204332143322433234332443325433264332743328433294333043331433324333343334433354333643337433384333943340433414334243343433444334543346433474334843349433504335143352433534335443355433564335743358433594336043361433624336343364433654336643367433684336943370433714337243373433744337543376433774337843379433804338143382433834338443385433864338743388433894339043391433924339343394433954339643397433984339943400434014340243403434044340543406434074340843409434104341143412434134341443415434164341743418434194342043421434224342343424434254342643427434284342943430434314343243433434344343543436434374343843439434404344143442434434344443445434464344743448434494345043451434524345343454434554345643457434584345943460434614346243463434644346543466434674346843469434704347143472434734347443475434764347743478434794348043481434824348343484434854348643487434884348943490434914349243493434944349543496434974349843499435004350143502435034350443505435064350743508435094351043511435124351343514435154351643517435184351943520435214352243523435244352543526435274352843529435304353143532435334353443535435364353743538435394354043541435424354343544435454354643547435484354943550435514355243553435544355543556435574355843559435604356143562435634356443565435664356743568435694357043571435724357343574435754357643577435784357943580435814358243583435844358543586435874358843589435904359143592435934359443595435964359743598435994360043601436024360343604436054360643607436084360943610436114361243613436144361543616436174361843619436204362143622436234362443625436264362743628436294363043631436324363343634436354363643637436384363943640436414364243643436444364543646436474364843649436504365143652436534365443655436564365743658436594366043661436624366343664436654366643667436684366943670436714367243673436744367543676436774367843679436804368143682436834368443685436864368743688436894369043691436924369343694436954369643697436984369943700437014370243703437044370543706437074370843709437104371143712437134371443715437164371743718437194372043721437224372343724437254372643727437284372943730437314373243733437344373543736437374373843739437404374143742437434374443745437464374743748437494375043751437524375343754437554375643757437584375943760437614376243763437644376543766437674376843769437704377143772437734377443775437764377743778437794378043781437824378343784437854378643787437884378943790437914379243793437944379543796437974379843799438004380143802438034380443805438064380743808438094381043811438124381343814438154381643817438184381943820438214382243823438244382543826438274382843829438304383143832438334383443835438364383743838438394384043841438424384343844438454384643847438484384943850438514385243853438544385543856438574385843859438604386143862438634386443865438664386743868438694387043871438724387343874438754387643877438784387943880438814388243883438844388543886438874388843889438904389143892438934389443895438964389743898438994390043901439024390343904439054390643907439084390943910439114391243913439144391543916439174391843919439204392143922439234392443925439264392743928439294393043931439324393343934439354393643937439384393943940439414394243943439444394543946439474394843949439504395143952439534395443955439564395743958439594396043961439624396343964439654396643967439684396943970439714397243973439744397543976439774397843979439804398143982439834398443985439864398743988439894399043991439924399343994439954399643997439984399944000440014400244003440044400544006440074400844009440104401144012440134401444015440164401744018440194402044021440224402344024440254402644027440284402944030440314403244033440344403544036440374403844039440404404144042440434404444045440464404744048440494405044051440524405344054440554405644057440584405944060440614406244063440644406544066440674406844069440704407144072440734407444075440764407744078440794408044081440824408344084440854408644087440884408944090440914409244093440944409544096440974409844099441004410144102441034410444105441064410744108441094411044111441124411344114441154411644117441184411944120441214412244123441244412544126441274412844129441304413144132441334413444135441364413744138441394414044141441424414344144441454414644147441484414944150441514415244153441544415544156441574415844159441604416144162441634416444165441664416744168441694417044171441724417344174441754417644177441784417944180441814418244183441844418544186441874418844189441904419144192441934419444195441964419744198441994420044201442024420344204442054420644207442084420944210442114421244213442144421544216442174421844219442204422144222442234422444225442264422744228442294423044231442324423344234442354423644237442384423944240442414424244243442444424544246442474424844249442504425144252442534425444255442564425744258442594426044261442624426344264442654426644267442684426944270442714427244273442744427544276442774427844279442804428144282442834428444285442864428744288442894429044291442924429344294442954429644297442984429944300443014430244303443044430544306443074430844309443104431144312443134431444315443164431744318443194432044321443224432344324443254432644327443284432944330443314433244333443344433544336443374433844339443404434144342443434434444345443464434744348443494435044351443524435344354443554435644357443584435944360443614436244363443644436544366443674436844369443704437144372443734437444375443764437744378443794438044381443824438344384443854438644387443884438944390443914439244393443944439544396443974439844399444004440144402444034440444405444064440744408444094441044411444124441344414444154441644417444184441944420444214442244423444244442544426444274442844429444304443144432444334443444435444364443744438444394444044441444424444344444444454444644447444484444944450444514445244453444544445544456444574445844459444604446144462444634446444465444664446744468444694447044471444724447344474444754447644477444784447944480444814448244483444844448544486444874448844489444904449144492444934449444495444964449744498444994450044501445024450344504445054450644507445084450944510445114451244513445144451544516445174451844519445204452144522445234452444525445264452744528445294453044531445324453344534445354453644537445384453944540445414454244543445444454544546445474454844549445504455144552445534455444555445564455744558445594456044561445624456344564445654456644567445684456944570445714457244573445744457544576445774457844579445804458144582445834458444585445864458744588445894459044591445924459344594445954459644597445984459944600446014460244603446044460544606446074460844609446104461144612446134461444615446164461744618446194462044621446224462344624446254462644627446284462944630446314463244633446344463544636446374463844639446404464144642446434464444645446464464744648446494465044651446524465344654446554465644657446584465944660446614466244663446644466544666446674466844669446704467144672446734467444675446764467744678446794468044681446824468344684446854468644687446884468944690446914469244693446944469544696446974469844699447004470144702447034470444705447064470744708447094471044711447124471344714447154471644717447184471944720447214472244723447244472544726447274472844729447304473144732447334473444735447364473744738447394474044741447424474344744447454474644747447484474944750447514475244753447544475544756447574475844759447604476144762447634476444765447664476744768447694477044771447724477344774447754477644777447784477944780447814478244783447844478544786447874478844789447904479144792447934479444795447964479744798447994480044801448024480344804448054480644807448084480944810448114481244813448144481544816448174481844819448204482144822448234482444825448264482744828448294483044831448324483344834448354483644837448384483944840448414484244843448444484544846448474484844849448504485144852448534485444855448564485744858448594486044861448624486344864448654486644867448684486944870448714487244873448744487544876448774487844879448804488144882448834488444885448864488744888448894489044891448924489344894448954489644897448984489944900449014490244903449044490544906449074490844909449104491144912449134491444915449164491744918449194492044921449224492344924449254492644927449284492944930449314493244933449344493544936449374493844939449404494144942449434494444945449464494744948449494495044951449524495344954449554495644957449584495944960449614496244963449644496544966449674496844969449704497144972449734497444975449764497744978449794498044981449824498344984449854498644987449884498944990449914499244993449944499544996449974499844999450004500145002450034500445005450064500745008450094501045011450124501345014450154501645017450184501945020450214502245023450244502545026450274502845029450304503145032450334503445035450364503745038450394504045041450424504345044450454504645047450484504945050450514505245053450544505545056450574505845059450604506145062450634506445065450664506745068450694507045071450724507345074450754507645077450784507945080450814508245083450844508545086450874508845089450904509145092450934509445095450964509745098450994510045101451024510345104451054510645107451084510945110451114511245113451144511545116451174511845119451204512145122451234512445125451264512745128451294513045131451324513345134451354513645137451384513945140451414514245143451444514545146451474514845149451504515145152451534515445155451564515745158451594516045161451624516345164451654516645167451684516945170451714517245173451744517545176451774517845179451804518145182451834518445185451864518745188451894519045191451924519345194451954519645197451984519945200452014520245203452044520545206452074520845209452104521145212452134521445215452164521745218452194522045221452224522345224452254522645227452284522945230452314523245233452344523545236452374523845239452404524145242452434524445245452464524745248452494525045251452524525345254452554525645257452584525945260452614526245263452644526545266452674526845269452704527145272452734527445275452764527745278452794528045281452824528345284452854528645287452884528945290452914529245293452944529545296452974529845299453004530145302453034530445305453064530745308453094531045311453124531345314453154531645317453184531945320453214532245323453244532545326453274532845329453304533145332453334533445335453364533745338453394534045341453424534345344453454534645347453484534945350453514535245353453544535545356453574535845359453604536145362453634536445365453664536745368453694537045371453724537345374453754537645377453784537945380453814538245383453844538545386453874538845389453904539145392453934539445395453964539745398453994540045401454024540345404454054540645407454084540945410454114541245413454144541545416454174541845419454204542145422454234542445425454264542745428454294543045431454324543345434454354543645437454384543945440454414544245443454444544545446454474544845449454504545145452454534545445455454564545745458454594546045461454624546345464454654546645467454684546945470454714547245473454744547545476454774547845479454804548145482454834548445485454864548745488454894549045491454924549345494454954549645497454984549945500455014550245503455044550545506455074550845509455104551145512455134551445515455164551745518455194552045521455224552345524455254552645527455284552945530455314553245533455344553545536455374553845539455404554145542455434554445545455464554745548455494555045551455524555345554455554555645557455584555945560455614556245563455644556545566455674556845569455704557145572455734557445575455764557745578455794558045581455824558345584455854558645587455884558945590455914559245593455944559545596455974559845599456004560145602456034560445605456064560745608456094561045611456124561345614456154561645617456184561945620456214562245623456244562545626456274562845629456304563145632456334563445635456364563745638456394564045641456424564345644456454564645647456484564945650456514565245653456544565545656456574565845659456604566145662456634566445665456664566745668456694567045671456724567345674456754567645677456784567945680456814568245683456844568545686456874568845689456904569145692456934569445695456964569745698456994570045701457024570345704457054570645707457084570945710457114571245713457144571545716457174571845719457204572145722457234572445725457264572745728457294573045731457324573345734457354573645737457384573945740457414574245743457444574545746457474574845749457504575145752457534575445755457564575745758457594576045761457624576345764457654576645767457684576945770457714577245773457744577545776457774577845779457804578145782457834578445785457864578745788457894579045791457924579345794457954579645797457984579945800458014580245803458044580545806458074580845809458104581145812458134581445815458164581745818458194582045821458224582345824458254582645827458284582945830458314583245833458344583545836458374583845839458404584145842458434584445845458464584745848458494585045851458524585345854458554585645857458584585945860458614586245863458644586545866458674586845869458704587145872458734587445875458764587745878458794588045881458824588345884458854588645887458884588945890458914589245893458944589545896458974589845899459004590145902459034590445905459064590745908459094591045911459124591345914459154591645917459184591945920459214592245923459244592545926459274592845929459304593145932459334593445935459364593745938459394594045941459424594345944459454594645947459484594945950459514595245953459544595545956459574595845959459604596145962459634596445965459664596745968459694597045971459724597345974459754597645977459784597945980459814598245983459844598545986459874598845989459904599145992459934599445995459964599745998459994600046001460024600346004460054600646007460084600946010460114601246013460144601546016460174601846019460204602146022460234602446025460264602746028460294603046031460324603346034460354603646037460384603946040460414604246043460444604546046460474604846049460504605146052460534605446055460564605746058460594606046061460624606346064460654606646067460684606946070460714607246073460744607546076460774607846079460804608146082460834608446085460864608746088460894609046091460924609346094460954609646097460984609946100461014610246103461044610546106461074610846109461104611146112461134611446115461164611746118461194612046121461224612346124461254612646127461284612946130461314613246133461344613546136461374613846139461404614146142461434614446145461464614746148461494615046151461524615346154461554615646157461584615946160461614616246163461644616546166461674616846169461704617146172461734617446175461764617746178461794618046181461824618346184461854618646187461884618946190461914619246193461944619546196461974619846199462004620146202462034620446205462064620746208462094621046211462124621346214462154621646217462184621946220462214622246223462244622546226462274622846229462304623146232462334623446235462364623746238462394624046241462424624346244462454624646247462484624946250462514625246253462544625546256462574625846259462604626146262462634626446265462664626746268462694627046271462724627346274462754627646277462784627946280462814628246283462844628546286462874628846289462904629146292462934629446295462964629746298462994630046301463024630346304463054630646307463084630946310463114631246313463144631546316463174631846319463204632146322463234632446325463264632746328463294633046331463324633346334463354633646337463384633946340463414634246343463444634546346463474634846349463504635146352463534635446355463564635746358463594636046361463624636346364463654636646367463684636946370463714637246373463744637546376463774637846379463804638146382463834638446385463864638746388463894639046391463924639346394463954639646397463984639946400464014640246403464044640546406464074640846409464104641146412464134641446415464164641746418464194642046421464224642346424464254642646427464284642946430464314643246433464344643546436464374643846439464404644146442464434644446445464464644746448464494645046451464524645346454464554645646457464584645946460464614646246463464644646546466464674646846469464704647146472464734647446475464764647746478464794648046481464824648346484464854648646487464884648946490464914649246493464944649546496464974649846499465004650146502465034650446505465064650746508465094651046511465124651346514465154651646517465184651946520465214652246523465244652546526465274652846529465304653146532465334653446535465364653746538465394654046541465424654346544465454654646547465484654946550465514655246553465544655546556465574655846559465604656146562465634656446565465664656746568465694657046571465724657346574465754657646577465784657946580465814658246583465844658546586465874658846589465904659146592465934659446595465964659746598465994660046601466024660346604466054660646607466084660946610466114661246613466144661546616466174661846619466204662146622466234662446625466264662746628466294663046631466324663346634466354663646637466384663946640466414664246643466444664546646466474664846649466504665146652466534665446655466564665746658466594666046661466624666346664466654666646667466684666946670466714667246673466744667546676466774667846679466804668146682466834668446685466864668746688466894669046691466924669346694466954669646697466984669946700467014670246703467044670546706467074670846709467104671146712467134671446715467164671746718467194672046721467224672346724467254672646727467284672946730467314673246733467344673546736467374673846739467404674146742467434674446745467464674746748467494675046751467524675346754467554675646757467584675946760467614676246763467644676546766467674676846769467704677146772467734677446775467764677746778467794678046781467824678346784467854678646787467884678946790467914679246793467944679546796467974679846799468004680146802468034680446805468064680746808468094681046811468124681346814468154681646817468184681946820468214682246823468244682546826468274682846829468304683146832468334683446835468364683746838468394684046841468424684346844468454684646847468484684946850468514685246853468544685546856468574685846859468604686146862468634686446865468664686746868468694687046871468724687346874468754687646877468784687946880468814688246883468844688546886468874688846889468904689146892468934689446895468964689746898468994690046901469024690346904469054690646907469084690946910469114691246913469144691546916469174691846919469204692146922469234692446925469264692746928469294693046931469324693346934469354693646937469384693946940469414694246943469444694546946469474694846949469504695146952469534695446955469564695746958469594696046961469624696346964469654696646967469684696946970469714697246973469744697546976469774697846979469804698146982469834698446985469864698746988469894699046991469924699346994469954699646997469984699947000470014700247003470044700547006470074700847009470104701147012470134701447015470164701747018470194702047021470224702347024470254702647027470284702947030470314703247033470344703547036470374703847039470404704147042470434704447045470464704747048470494705047051470524705347054470554705647057470584705947060470614706247063470644706547066470674706847069470704707147072470734707447075470764707747078470794708047081470824708347084470854708647087470884708947090470914709247093470944709547096470974709847099471004710147102471034710447105471064710747108471094711047111471124711347114471154711647117471184711947120471214712247123471244712547126471274712847129471304713147132471334713447135471364713747138471394714047141471424714347144471454714647147471484714947150471514715247153471544715547156471574715847159471604716147162471634716447165471664716747168471694717047171471724717347174471754717647177471784717947180471814718247183471844718547186471874718847189471904719147192471934719447195471964719747198471994720047201472024720347204472054720647207472084720947210472114721247213472144721547216472174721847219472204722147222472234722447225472264722747228472294723047231472324723347234472354723647237472384723947240472414724247243472444724547246472474724847249472504725147252472534725447255472564725747258472594726047261472624726347264472654726647267472684726947270472714727247273472744727547276472774727847279472804728147282472834728447285472864728747288472894729047291472924729347294472954729647297472984729947300473014730247303473044730547306473074730847309473104731147312473134731447315473164731747318473194732047321473224732347324473254732647327473284732947330473314733247333473344733547336473374733847339473404734147342473434734447345473464734747348473494735047351473524735347354473554735647357473584735947360473614736247363473644736547366473674736847369473704737147372473734737447375473764737747378473794738047381473824738347384473854738647387473884738947390473914739247393473944739547396473974739847399474004740147402474034740447405474064740747408474094741047411474124741347414474154741647417474184741947420474214742247423474244742547426474274742847429474304743147432474334743447435474364743747438474394744047441474424744347444474454744647447474484744947450474514745247453474544745547456474574745847459474604746147462474634746447465474664746747468474694747047471474724747347474474754747647477474784747947480474814748247483474844748547486474874748847489474904749147492474934749447495474964749747498474994750047501475024750347504475054750647507475084750947510475114751247513475144751547516475174751847519475204752147522475234752447525475264752747528475294753047531475324753347534475354753647537475384753947540475414754247543475444754547546475474754847549475504755147552475534755447555475564755747558475594756047561475624756347564475654756647567475684756947570475714757247573475744757547576475774757847579475804758147582475834758447585475864758747588475894759047591475924759347594475954759647597475984759947600476014760247603476044760547606476074760847609476104761147612476134761447615476164761747618476194762047621476224762347624476254762647627476284762947630476314763247633476344763547636476374763847639476404764147642476434764447645476464764747648476494765047651476524765347654476554765647657476584765947660476614766247663476644766547666476674766847669476704767147672476734767447675476764767747678476794768047681476824768347684476854768647687476884768947690476914769247693476944769547696476974769847699477004770147702477034770447705477064770747708477094771047711477124771347714477154771647717477184771947720477214772247723477244772547726477274772847729477304773147732477334773447735477364773747738477394774047741477424774347744477454774647747477484774947750477514775247753477544775547756477574775847759477604776147762477634776447765477664776747768477694777047771477724777347774477754777647777477784777947780477814778247783477844778547786477874778847789477904779147792477934779447795477964779747798477994780047801478024780347804478054780647807478084780947810478114781247813478144781547816478174781847819478204782147822478234782447825478264782747828478294783047831478324783347834478354783647837478384783947840478414784247843478444784547846478474784847849478504785147852478534785447855478564785747858478594786047861478624786347864478654786647867478684786947870478714787247873478744787547876478774787847879478804788147882478834788447885478864788747888478894789047891478924789347894478954789647897478984789947900479014790247903479044790547906479074790847909479104791147912479134791447915479164791747918479194792047921479224792347924479254792647927479284792947930479314793247933479344793547936479374793847939479404794147942479434794447945479464794747948479494795047951479524795347954479554795647957479584795947960479614796247963479644796547966479674796847969479704797147972479734797447975479764797747978479794798047981479824798347984479854798647987479884798947990479914799247993479944799547996479974799847999480004800148002480034800448005480064800748008480094801048011480124801348014480154801648017480184801948020480214802248023480244802548026480274802848029480304803148032480334803448035480364803748038480394804048041480424804348044480454804648047480484804948050480514805248053480544805548056480574805848059480604806148062480634806448065480664806748068480694807048071480724807348074480754807648077480784807948080480814808248083480844808548086480874808848089480904809148092480934809448095480964809748098480994810048101481024810348104481054810648107481084810948110481114811248113481144811548116481174811848119481204812148122481234812448125481264812748128481294813048131481324813348134481354813648137481384813948140481414814248143481444814548146481474814848149481504815148152481534815448155481564815748158481594816048161481624816348164481654816648167481684816948170481714817248173481744817548176481774817848179481804818148182481834818448185481864818748188481894819048191481924819348194481954819648197481984819948200482014820248203482044820548206482074820848209482104821148212482134821448215482164821748218482194822048221482224822348224482254822648227482284822948230482314823248233482344823548236482374823848239482404824148242482434824448245482464824748248482494825048251482524825348254482554825648257482584825948260482614826248263482644826548266482674826848269482704827148272482734827448275482764827748278482794828048281482824828348284482854828648287482884828948290482914829248293482944829548296482974829848299483004830148302483034830448305483064830748308483094831048311483124831348314483154831648317483184831948320483214832248323483244832548326483274832848329483304833148332483334833448335483364833748338483394834048341483424834348344483454834648347483484834948350483514835248353483544835548356483574835848359483604836148362483634836448365483664836748368483694837048371483724837348374483754837648377483784837948380483814838248383483844838548386483874838848389483904839148392483934839448395483964839748398483994840048401484024840348404484054840648407484084840948410484114841248413484144841548416484174841848419484204842148422484234842448425484264842748428484294843048431484324843348434484354843648437484384843948440484414844248443484444844548446484474844848449484504845148452484534845448455484564845748458484594846048461484624846348464484654846648467484684846948470484714847248473484744847548476484774847848479484804848148482484834848448485484864848748488484894849048491484924849348494484954849648497484984849948500485014850248503485044850548506485074850848509485104851148512485134851448515485164851748518485194852048521485224852348524485254852648527485284852948530485314853248533485344853548536485374853848539485404854148542485434854448545485464854748548485494855048551485524855348554485554855648557485584855948560485614856248563485644856548566485674856848569485704857148572485734857448575485764857748578485794858048581485824858348584485854858648587485884858948590485914859248593485944859548596485974859848599486004860148602486034860448605486064860748608486094861048611486124861348614486154861648617486184861948620486214862248623486244862548626486274862848629486304863148632486334863448635486364863748638486394864048641486424864348644486454864648647486484864948650486514865248653486544865548656486574865848659486604866148662486634866448665486664866748668486694867048671486724867348674486754867648677486784867948680486814868248683486844868548686486874868848689486904869148692486934869448695486964869748698486994870048701487024870348704487054870648707487084870948710487114871248713487144871548716487174871848719487204872148722487234872448725487264872748728487294873048731487324873348734487354873648737487384873948740487414874248743487444874548746487474874848749487504875148752487534875448755487564875748758487594876048761487624876348764487654876648767487684876948770487714877248773487744877548776487774877848779487804878148782487834878448785487864878748788487894879048791487924879348794487954879648797487984879948800488014880248803488044880548806488074880848809488104881148812488134881448815488164881748818488194882048821488224882348824488254882648827488284882948830488314883248833488344883548836488374883848839488404884148842488434884448845488464884748848488494885048851488524885348854488554885648857488584885948860488614886248863488644886548866488674886848869488704887148872488734887448875488764887748878488794888048881488824888348884488854888648887488884888948890488914889248893488944889548896488974889848899489004890148902489034890448905489064890748908489094891048911489124891348914489154891648917489184891948920489214892248923489244892548926489274892848929489304893148932489334893448935489364893748938489394894048941489424894348944489454894648947489484894948950489514895248953489544895548956489574895848959489604896148962489634896448965489664896748968489694897048971489724897348974489754897648977489784897948980489814898248983489844898548986489874898848989489904899148992489934899448995489964899748998489994900049001490024900349004490054900649007490084900949010490114901249013490144901549016490174901849019490204902149022490234902449025490264902749028490294903049031490324903349034490354903649037490384903949040490414904249043490444904549046490474904849049490504905149052
  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 = '104dev';
  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 ( v ) {
  3345. var te = this.elements;
  3346. te[ 12 ] = v.x;
  3347. te[ 13 ] = v.y;
  3348. te[ 14 ] = v.z;
  3349. return this;
  3350. },
  3351. getInverse: function ( m, throwOnDegenerate ) {
  3352. // based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm
  3353. var te = this.elements,
  3354. me = m.elements,
  3355. n11 = me[ 0 ], n21 = me[ 1 ], n31 = me[ 2 ], n41 = me[ 3 ],
  3356. n12 = me[ 4 ], n22 = me[ 5 ], n32 = me[ 6 ], n42 = me[ 7 ],
  3357. n13 = me[ 8 ], n23 = me[ 9 ], n33 = me[ 10 ], n43 = me[ 11 ],
  3358. n14 = me[ 12 ], n24 = me[ 13 ], n34 = me[ 14 ], n44 = me[ 15 ],
  3359. t11 = n23 * n34 * n42 - n24 * n33 * n42 + n24 * n32 * n43 - n22 * n34 * n43 - n23 * n32 * n44 + n22 * n33 * n44,
  3360. t12 = n14 * n33 * n42 - n13 * n34 * n42 - n14 * n32 * n43 + n12 * n34 * n43 + n13 * n32 * n44 - n12 * n33 * n44,
  3361. t13 = n13 * n24 * n42 - n14 * n23 * n42 + n14 * n22 * n43 - n12 * n24 * n43 - n13 * n22 * n44 + n12 * n23 * n44,
  3362. t14 = n14 * n23 * n32 - n13 * n24 * n32 - n14 * n22 * n33 + n12 * n24 * n33 + n13 * n22 * n34 - n12 * n23 * n34;
  3363. var det = n11 * t11 + n21 * t12 + n31 * t13 + n41 * t14;
  3364. if ( det === 0 ) {
  3365. var msg = "THREE.Matrix4: .getInverse() can't invert matrix, determinant is 0";
  3366. if ( throwOnDegenerate === true ) {
  3367. throw new Error( msg );
  3368. } else {
  3369. console.warn( msg );
  3370. }
  3371. return this.identity();
  3372. }
  3373. var detInv = 1 / det;
  3374. te[ 0 ] = t11 * detInv;
  3375. te[ 1 ] = ( n24 * n33 * n41 - n23 * n34 * n41 - n24 * n31 * n43 + n21 * n34 * n43 + n23 * n31 * n44 - n21 * n33 * n44 ) * detInv;
  3376. te[ 2 ] = ( n22 * n34 * n41 - n24 * n32 * n41 + n24 * n31 * n42 - n21 * n34 * n42 - n22 * n31 * n44 + n21 * n32 * n44 ) * detInv;
  3377. te[ 3 ] = ( n23 * n32 * n41 - n22 * n33 * n41 - n23 * n31 * n42 + n21 * n33 * n42 + n22 * n31 * n43 - n21 * n32 * n43 ) * detInv;
  3378. te[ 4 ] = t12 * detInv;
  3379. te[ 5 ] = ( n13 * n34 * n41 - n14 * n33 * n41 + n14 * n31 * n43 - n11 * n34 * n43 - n13 * n31 * n44 + n11 * n33 * n44 ) * detInv;
  3380. te[ 6 ] = ( n14 * n32 * n41 - n12 * n34 * n41 - n14 * n31 * n42 + n11 * n34 * n42 + n12 * n31 * n44 - n11 * n32 * n44 ) * detInv;
  3381. te[ 7 ] = ( n12 * n33 * n41 - n13 * n32 * n41 + n13 * n31 * n42 - n11 * n33 * n42 - n12 * n31 * n43 + n11 * n32 * n43 ) * detInv;
  3382. te[ 8 ] = t13 * detInv;
  3383. te[ 9 ] = ( n14 * n23 * n41 - n13 * n24 * n41 - n14 * n21 * n43 + n11 * n24 * n43 + n13 * n21 * n44 - n11 * n23 * n44 ) * detInv;
  3384. te[ 10 ] = ( n12 * n24 * n41 - n14 * n22 * n41 + n14 * n21 * n42 - n11 * n24 * n42 - n12 * n21 * n44 + n11 * n22 * n44 ) * detInv;
  3385. te[ 11 ] = ( n13 * n22 * n41 - n12 * n23 * n41 - n13 * n21 * n42 + n11 * n23 * n42 + n12 * n21 * n43 - n11 * n22 * n43 ) * detInv;
  3386. te[ 12 ] = t14 * detInv;
  3387. te[ 13 ] = ( n13 * n24 * n31 - n14 * n23 * n31 + n14 * n21 * n33 - n11 * n24 * n33 - n13 * n21 * n34 + n11 * n23 * n34 ) * detInv;
  3388. te[ 14 ] = ( n14 * n22 * n31 - n12 * n24 * n31 - n14 * n21 * n32 + n11 * n24 * n32 + n12 * n21 * n34 - n11 * n22 * n34 ) * detInv;
  3389. te[ 15 ] = ( n12 * n23 * n31 - n13 * n22 * n31 + n13 * n21 * n32 - n11 * n23 * n32 - n12 * n21 * n33 + n11 * n22 * n33 ) * detInv;
  3390. return this;
  3391. },
  3392. scale: function ( v ) {
  3393. var te = this.elements;
  3394. var x = v.x, y = v.y, z = v.z;
  3395. te[ 0 ] *= x; te[ 4 ] *= y; te[ 8 ] *= z;
  3396. te[ 1 ] *= x; te[ 5 ] *= y; te[ 9 ] *= z;
  3397. te[ 2 ] *= x; te[ 6 ] *= y; te[ 10 ] *= z;
  3398. te[ 3 ] *= x; te[ 7 ] *= y; te[ 11 ] *= z;
  3399. return this;
  3400. },
  3401. getMaxScaleOnAxis: function () {
  3402. var te = this.elements;
  3403. var scaleXSq = te[ 0 ] * te[ 0 ] + te[ 1 ] * te[ 1 ] + te[ 2 ] * te[ 2 ];
  3404. var scaleYSq = te[ 4 ] * te[ 4 ] + te[ 5 ] * te[ 5 ] + te[ 6 ] * te[ 6 ];
  3405. var scaleZSq = te[ 8 ] * te[ 8 ] + te[ 9 ] * te[ 9 ] + te[ 10 ] * te[ 10 ];
  3406. return Math.sqrt( Math.max( scaleXSq, scaleYSq, scaleZSq ) );
  3407. },
  3408. makeTranslation: function ( x, y, z ) {
  3409. this.set(
  3410. 1, 0, 0, x,
  3411. 0, 1, 0, y,
  3412. 0, 0, 1, z,
  3413. 0, 0, 0, 1
  3414. );
  3415. return this;
  3416. },
  3417. makeRotationX: function ( theta ) {
  3418. var c = Math.cos( theta ), s = Math.sin( theta );
  3419. this.set(
  3420. 1, 0, 0, 0,
  3421. 0, c, - s, 0,
  3422. 0, s, c, 0,
  3423. 0, 0, 0, 1
  3424. );
  3425. return this;
  3426. },
  3427. makeRotationY: function ( theta ) {
  3428. var c = Math.cos( theta ), s = Math.sin( theta );
  3429. this.set(
  3430. c, 0, s, 0,
  3431. 0, 1, 0, 0,
  3432. - s, 0, c, 0,
  3433. 0, 0, 0, 1
  3434. );
  3435. return this;
  3436. },
  3437. makeRotationZ: function ( theta ) {
  3438. var c = Math.cos( theta ), s = Math.sin( theta );
  3439. this.set(
  3440. c, - s, 0, 0,
  3441. s, c, 0, 0,
  3442. 0, 0, 1, 0,
  3443. 0, 0, 0, 1
  3444. );
  3445. return this;
  3446. },
  3447. makeRotationAxis: function ( axis, angle ) {
  3448. // Based on http://www.gamedev.net/reference/articles/article1199.asp
  3449. var c = Math.cos( angle );
  3450. var s = Math.sin( angle );
  3451. var t = 1 - c;
  3452. var x = axis.x, y = axis.y, z = axis.z;
  3453. var tx = t * x, ty = t * y;
  3454. this.set(
  3455. tx * x + c, tx * y - s * z, tx * z + s * y, 0,
  3456. tx * y + s * z, ty * y + c, ty * z - s * x, 0,
  3457. tx * z - s * y, ty * z + s * x, t * z * z + c, 0,
  3458. 0, 0, 0, 1
  3459. );
  3460. return this;
  3461. },
  3462. makeScale: function ( x, y, z ) {
  3463. this.set(
  3464. x, 0, 0, 0,
  3465. 0, y, 0, 0,
  3466. 0, 0, z, 0,
  3467. 0, 0, 0, 1
  3468. );
  3469. return this;
  3470. },
  3471. makeShear: function ( x, y, z ) {
  3472. this.set(
  3473. 1, y, z, 0,
  3474. x, 1, z, 0,
  3475. x, y, 1, 0,
  3476. 0, 0, 0, 1
  3477. );
  3478. return this;
  3479. },
  3480. compose: function ( position, quaternion, scale ) {
  3481. var te = this.elements;
  3482. var x = quaternion._x, y = quaternion._y, z = quaternion._z, w = quaternion._w;
  3483. var x2 = x + x, y2 = y + y, z2 = z + z;
  3484. var xx = x * x2, xy = x * y2, xz = x * z2;
  3485. var yy = y * y2, yz = y * z2, zz = z * z2;
  3486. var wx = w * x2, wy = w * y2, wz = w * z2;
  3487. var sx = scale.x, sy = scale.y, sz = scale.z;
  3488. te[ 0 ] = ( 1 - ( yy + zz ) ) * sx;
  3489. te[ 1 ] = ( xy + wz ) * sx;
  3490. te[ 2 ] = ( xz - wy ) * sx;
  3491. te[ 3 ] = 0;
  3492. te[ 4 ] = ( xy - wz ) * sy;
  3493. te[ 5 ] = ( 1 - ( xx + zz ) ) * sy;
  3494. te[ 6 ] = ( yz + wx ) * sy;
  3495. te[ 7 ] = 0;
  3496. te[ 8 ] = ( xz + wy ) * sz;
  3497. te[ 9 ] = ( yz - wx ) * sz;
  3498. te[ 10 ] = ( 1 - ( xx + yy ) ) * sz;
  3499. te[ 11 ] = 0;
  3500. te[ 12 ] = position.x;
  3501. te[ 13 ] = position.y;
  3502. te[ 14 ] = position.z;
  3503. te[ 15 ] = 1;
  3504. return this;
  3505. },
  3506. decompose: function () {
  3507. var vector = new Vector3();
  3508. var matrix = new Matrix4();
  3509. return function decompose( position, quaternion, scale ) {
  3510. var te = this.elements;
  3511. var sx = vector.set( te[ 0 ], te[ 1 ], te[ 2 ] ).length();
  3512. var sy = vector.set( te[ 4 ], te[ 5 ], te[ 6 ] ).length();
  3513. var sz = vector.set( te[ 8 ], te[ 9 ], te[ 10 ] ).length();
  3514. // if determine is negative, we need to invert one scale
  3515. var det = this.determinant();
  3516. if ( det < 0 ) sx = - sx;
  3517. position.x = te[ 12 ];
  3518. position.y = te[ 13 ];
  3519. position.z = te[ 14 ];
  3520. // scale the rotation part
  3521. matrix.copy( this );
  3522. var invSX = 1 / sx;
  3523. var invSY = 1 / sy;
  3524. var invSZ = 1 / sz;
  3525. matrix.elements[ 0 ] *= invSX;
  3526. matrix.elements[ 1 ] *= invSX;
  3527. matrix.elements[ 2 ] *= invSX;
  3528. matrix.elements[ 4 ] *= invSY;
  3529. matrix.elements[ 5 ] *= invSY;
  3530. matrix.elements[ 6 ] *= invSY;
  3531. matrix.elements[ 8 ] *= invSZ;
  3532. matrix.elements[ 9 ] *= invSZ;
  3533. matrix.elements[ 10 ] *= invSZ;
  3534. quaternion.setFromRotationMatrix( matrix );
  3535. scale.x = sx;
  3536. scale.y = sy;
  3537. scale.z = sz;
  3538. return this;
  3539. };
  3540. }(),
  3541. makePerspective: function ( left, right, top, bottom, near, far ) {
  3542. if ( far === undefined ) {
  3543. console.warn( 'THREE.Matrix4: .makePerspective() has been redefined and has a new signature. Please check the docs.' );
  3544. }
  3545. var te = this.elements;
  3546. var x = 2 * near / ( right - left );
  3547. var y = 2 * near / ( top - bottom );
  3548. var a = ( right + left ) / ( right - left );
  3549. var b = ( top + bottom ) / ( top - bottom );
  3550. var c = - ( far + near ) / ( far - near );
  3551. var d = - 2 * far * near / ( far - near );
  3552. te[ 0 ] = x; te[ 4 ] = 0; te[ 8 ] = a; te[ 12 ] = 0;
  3553. te[ 1 ] = 0; te[ 5 ] = y; te[ 9 ] = b; te[ 13 ] = 0;
  3554. te[ 2 ] = 0; te[ 6 ] = 0; te[ 10 ] = c; te[ 14 ] = d;
  3555. te[ 3 ] = 0; te[ 7 ] = 0; te[ 11 ] = - 1; te[ 15 ] = 0;
  3556. return this;
  3557. },
  3558. makeOrthographic: function ( left, right, top, bottom, near, far ) {
  3559. var te = this.elements;
  3560. var w = 1.0 / ( right - left );
  3561. var h = 1.0 / ( top - bottom );
  3562. var p = 1.0 / ( far - near );
  3563. var x = ( right + left ) * w;
  3564. var y = ( top + bottom ) * h;
  3565. var z = ( far + near ) * p;
  3566. te[ 0 ] = 2 * w; te[ 4 ] = 0; te[ 8 ] = 0; te[ 12 ] = - x;
  3567. te[ 1 ] = 0; te[ 5 ] = 2 * h; te[ 9 ] = 0; te[ 13 ] = - y;
  3568. te[ 2 ] = 0; te[ 6 ] = 0; te[ 10 ] = - 2 * p; te[ 14 ] = - z;
  3569. te[ 3 ] = 0; te[ 7 ] = 0; te[ 11 ] = 0; te[ 15 ] = 1;
  3570. return this;
  3571. },
  3572. equals: function ( matrix ) {
  3573. var te = this.elements;
  3574. var me = matrix.elements;
  3575. for ( var i = 0; i < 16; i ++ ) {
  3576. if ( te[ i ] !== me[ i ] ) return false;
  3577. }
  3578. return true;
  3579. },
  3580. fromArray: function ( array, offset ) {
  3581. if ( offset === undefined ) offset = 0;
  3582. for ( var i = 0; i < 16; i ++ ) {
  3583. this.elements[ i ] = array[ i + offset ];
  3584. }
  3585. return this;
  3586. },
  3587. toArray: function ( array, offset ) {
  3588. if ( array === undefined ) array = [];
  3589. if ( offset === undefined ) offset = 0;
  3590. var te = this.elements;
  3591. array[ offset ] = te[ 0 ];
  3592. array[ offset + 1 ] = te[ 1 ];
  3593. array[ offset + 2 ] = te[ 2 ];
  3594. array[ offset + 3 ] = te[ 3 ];
  3595. array[ offset + 4 ] = te[ 4 ];
  3596. array[ offset + 5 ] = te[ 5 ];
  3597. array[ offset + 6 ] = te[ 6 ];
  3598. array[ offset + 7 ] = te[ 7 ];
  3599. array[ offset + 8 ] = te[ 8 ];
  3600. array[ offset + 9 ] = te[ 9 ];
  3601. array[ offset + 10 ] = te[ 10 ];
  3602. array[ offset + 11 ] = te[ 11 ];
  3603. array[ offset + 12 ] = te[ 12 ];
  3604. array[ offset + 13 ] = te[ 13 ];
  3605. array[ offset + 14 ] = te[ 14 ];
  3606. array[ offset + 15 ] = te[ 15 ];
  3607. return array;
  3608. }
  3609. } );
  3610. var alphamap_fragment = "#ifdef USE_ALPHAMAP\n\tdiffuseColor.a *= texture2D( alphaMap, vUv ).g;\n#endif";
  3611. var alphamap_pars_fragment = "#ifdef USE_ALPHAMAP\n\tuniform sampler2D alphaMap;\n#endif";
  3612. var alphatest_fragment = "#ifdef ALPHATEST\n\tif ( diffuseColor.a < ALPHATEST ) discard;\n#endif";
  3613. 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";
  3614. var aomap_pars_fragment = "#ifdef USE_AOMAP\n\tuniform sampler2D aoMap;\n\tuniform float aoMapIntensity;\n#endif";
  3615. var begin_vertex = "vec3 transformed = vec3( position );";
  3616. var beginnormal_vertex = "vec3 objectNormal = vec3( normal );\n#ifdef USE_TANGENT\n\tvec3 objectTangent = vec3( tangent.xyz );\n#endif";
  3617. var bsdfs = "vec2 integrateSpecularBRDF( const in float dotNV, const in float roughness ) {\n\tconst vec4 c0 = vec4( - 1, - 0.0275, - 0.572, 0.022 );\n\tconst vec4 c1 = vec4( 1, 0.0425, 1.04, - 0.04 );\n\tvec4 r = roughness * c0 + c1;\n\tfloat a004 = min( r.x * r.x, exp2( - 9.28 * dotNV ) ) * r.x + r.y;\n\treturn vec2( -1.04, 1.04 ) * a004 + r.zw;\n}\nfloat punctualLightIntensityToIrradianceFactor( const in float lightDistance, const in float cutoffDistance, const in float decayExponent ) {\n#if defined ( PHYSICALLY_CORRECT_LIGHTS )\n\tfloat distanceFalloff = 1.0 / max( pow( lightDistance, decayExponent ), 0.01 );\n\tif( cutoffDistance > 0.0 ) {\n\t\tdistanceFalloff *= pow2( saturate( 1.0 - pow4( lightDistance / cutoffDistance ) ) );\n\t}\n\treturn distanceFalloff;\n#else\n\tif( cutoffDistance > 0.0 && decayExponent > 0.0 ) {\n\t\treturn pow( saturate( -lightDistance / cutoffDistance + 1.0 ), decayExponent );\n\t}\n\treturn 1.0;\n#endif\n}\nvec3 BRDF_Diffuse_Lambert( const in vec3 diffuseColor ) {\n\treturn RECIPROCAL_PI * diffuseColor;\n}\nvec3 F_Schlick( const in vec3 specularColor, const in float dotLH ) {\n\tfloat fresnel = exp2( ( -5.55473 * dotLH - 6.98316 ) * dotLH );\n\treturn ( 1.0 - specularColor ) * fresnel + specularColor;\n}\nfloat G_GGX_Smith( const in float alpha, const in float dotNL, const in float dotNV ) {\n\tfloat a2 = pow2( alpha );\n\tfloat gl = dotNL + sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNL ) );\n\tfloat gv = dotNV + sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNV ) );\n\treturn 1.0 / ( gl * gv );\n}\nfloat G_GGX_SmithCorrelated( const in float alpha, const in float dotNL, const in float dotNV ) {\n\tfloat a2 = pow2( alpha );\n\tfloat gv = dotNL * sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNV ) );\n\tfloat gl = dotNV * sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNL ) );\n\treturn 0.5 / max( gv + gl, EPSILON );\n}\nfloat D_GGX( const in float alpha, const in float dotNH ) {\n\tfloat a2 = pow2( alpha );\n\tfloat denom = pow2( dotNH ) * ( a2 - 1.0 ) + 1.0;\n\treturn RECIPROCAL_PI * a2 / pow2( denom );\n}\nvec3 BRDF_Specular_GGX( const in IncidentLight incidentLight, const in GeometricContext geometry, const in vec3 specularColor, const in float roughness ) {\n\tfloat alpha = pow2( roughness );\n\tvec3 halfDir = normalize( incidentLight.direction + geometry.viewDir );\n\tfloat dotNL = saturate( dot( geometry.normal, incidentLight.direction ) );\n\tfloat dotNV = saturate( dot( geometry.normal, geometry.viewDir ) );\n\tfloat dotNH = saturate( dot( geometry.normal, halfDir ) );\n\tfloat dotLH = saturate( dot( incidentLight.direction, halfDir ) );\n\tvec3 F = F_Schlick( specularColor, dotLH );\n\tfloat G = G_GGX_SmithCorrelated( alpha, dotNL, dotNV );\n\tfloat D = D_GGX( alpha, dotNH );\n\treturn F * ( G * D );\n}\nvec2 LTC_Uv( const in vec3 N, const in vec3 V, const in float roughness ) {\n\tconst float LUT_SIZE = 64.0;\n\tconst float LUT_SCALE = ( LUT_SIZE - 1.0 ) / LUT_SIZE;\n\tconst float LUT_BIAS = 0.5 / LUT_SIZE;\n\tfloat dotNV = saturate( dot( N, V ) );\n\tvec2 uv = vec2( roughness, sqrt( 1.0 - dotNV ) );\n\tuv = uv * LUT_SCALE + LUT_BIAS;\n\treturn uv;\n}\nfloat LTC_ClippedSphereFormFactor( const in vec3 f ) {\n\tfloat l = length( f );\n\treturn max( ( l * l + f.z ) / ( l + 1.0 ), 0.0 );\n}\nvec3 LTC_EdgeVectorFormFactor( const in vec3 v1, const in vec3 v2 ) {\n\tfloat x = dot( v1, v2 );\n\tfloat y = abs( x );\n\tfloat a = 0.8543985 + ( 0.4965155 + 0.0145206 * y ) * y;\n\tfloat b = 3.4175940 + ( 4.1616724 + y ) * y;\n\tfloat v = a / b;\n\tfloat theta_sintheta = ( x > 0.0 ) ? v : 0.5 * inversesqrt( max( 1.0 - x * x, 1e-7 ) ) - v;\n\treturn cross( v1, v2 ) * theta_sintheta;\n}\nvec3 LTC_Evaluate( const in vec3 N, const in vec3 V, const in vec3 P, const in mat3 mInv, const in vec3 rectCoords[ 4 ] ) {\n\tvec3 v1 = rectCoords[ 1 ] - rectCoords[ 0 ];\n\tvec3 v2 = rectCoords[ 3 ] - rectCoords[ 0 ];\n\tvec3 lightNormal = cross( v1, v2 );\n\tif( dot( lightNormal, P - rectCoords[ 0 ] ) < 0.0 ) return vec3( 0.0 );\n\tvec3 T1, T2;\n\tT1 = normalize( V - N * dot( V, N ) );\n\tT2 = - cross( N, T1 );\n\tmat3 mat = mInv * transposeMat3( mat3( T1, T2, N ) );\n\tvec3 coords[ 4 ];\n\tcoords[ 0 ] = mat * ( rectCoords[ 0 ] - P );\n\tcoords[ 1 ] = mat * ( rectCoords[ 1 ] - P );\n\tcoords[ 2 ] = mat * ( rectCoords[ 2 ] - P );\n\tcoords[ 3 ] = mat * ( rectCoords[ 3 ] - P );\n\tcoords[ 0 ] = normalize( coords[ 0 ] );\n\tcoords[ 1 ] = normalize( coords[ 1 ] );\n\tcoords[ 2 ] = normalize( coords[ 2 ] );\n\tcoords[ 3 ] = normalize( coords[ 3 ] );\n\tvec3 vectorFormFactor = vec3( 0.0 );\n\tvectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 0 ], coords[ 1 ] );\n\tvectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 1 ], coords[ 2 ] );\n\tvectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 2 ], coords[ 3 ] );\n\tvectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 3 ], coords[ 0 ] );\n\tfloat result = LTC_ClippedSphereFormFactor( vectorFormFactor );\n\treturn vec3( result );\n}\nvec3 BRDF_Specular_GGX_Environment( const in GeometricContext geometry, const in vec3 specularColor, const in float roughness ) {\n\tfloat dotNV = saturate( dot( geometry.normal, geometry.viewDir ) );\n\tvec2 brdf = integrateSpecularBRDF( dotNV, roughness );\n\treturn specularColor * brdf.x + brdf.y;\n}\nvoid BRDF_Specular_Multiscattering_Environment( const in GeometricContext geometry, const in vec3 specularColor, const in float roughness, inout vec3 singleScatter, inout vec3 multiScatter ) {\n\tfloat dotNV = saturate( dot( geometry.normal, geometry.viewDir ) );\n\tvec3 F = F_Schlick( specularColor, dotNV );\n\tvec2 brdf = integrateSpecularBRDF( dotNV, roughness );\n\tvec3 FssEss = F * brdf.x + brdf.y;\n\tfloat Ess = brdf.x + brdf.y;\n\tfloat Ems = 1.0 - Ess;\n\tvec3 Favg = specularColor + ( 1.0 - specularColor ) * 0.047619;\tvec3 Fms = FssEss * Favg / ( 1.0 - Ems * Favg );\n\tsingleScatter += FssEss;\n\tmultiScatter += Fms * Ems;\n}\nfloat G_BlinnPhong_Implicit( ) {\n\treturn 0.25;\n}\nfloat D_BlinnPhong( const in float shininess, const in float dotNH ) {\n\treturn RECIPROCAL_PI * ( shininess * 0.5 + 1.0 ) * pow( dotNH, shininess );\n}\nvec3 BRDF_Specular_BlinnPhong( const in IncidentLight incidentLight, const in GeometricContext geometry, const in vec3 specularColor, const in float shininess ) {\n\tvec3 halfDir = normalize( incidentLight.direction + geometry.viewDir );\n\tfloat dotNH = saturate( dot( geometry.normal, halfDir ) );\n\tfloat dotLH = saturate( dot( incidentLight.direction, halfDir ) );\n\tvec3 F = F_Schlick( specularColor, dotLH );\n\tfloat G = G_BlinnPhong_Implicit( );\n\tfloat D = D_BlinnPhong( shininess, dotNH );\n\treturn F * ( G * D );\n}\nfloat GGXRoughnessToBlinnExponent( const in float ggxRoughness ) {\n\treturn ( 2.0 / pow2( ggxRoughness + 0.0001 ) - 2.0 );\n}\nfloat BlinnExponentToGGXRoughness( const in float blinnExponent ) {\n\treturn sqrt( 2.0 / ( blinnExponent + 2.0 ) );\n}";
  3618. 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";
  3619. 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";
  3620. 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";
  3621. var clipping_planes_pars_vertex = "#if NUM_CLIPPING_PLANES > 0 && ! defined( PHYSICAL ) && ! defined( PHONG ) && ! defined( MATCAP )\n\tvarying vec3 vViewPosition;\n#endif";
  3622. var clipping_planes_vertex = "#if NUM_CLIPPING_PLANES > 0 && ! defined( PHYSICAL ) && ! defined( PHONG ) && ! defined( MATCAP )\n\tvViewPosition = - mvPosition.xyz;\n#endif";
  3623. var color_fragment = "#ifdef USE_COLOR\n\tdiffuseColor.rgb *= vColor;\n#endif";
  3624. var color_pars_fragment = "#ifdef USE_COLOR\n\tvarying vec3 vColor;\n#endif";
  3625. var color_pars_vertex = "#ifdef USE_COLOR\n\tvarying vec3 vColor;\n#endif";
  3626. var color_vertex = "#ifdef USE_COLOR\n\tvColor.xyz = color.xyz;\n#endif";
  3627. 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}";
  3628. 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";
  3629. 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";
  3630. var displacementmap_pars_vertex = "#ifdef USE_DISPLACEMENTMAP\n\tuniform sampler2D displacementMap;\n\tuniform float displacementScale;\n\tuniform float displacementBias;\n#endif";
  3631. var displacementmap_vertex = "#ifdef USE_DISPLACEMENTMAP\n\ttransformed += normalize( objectNormal ) * ( texture2D( displacementMap, uv ).x * displacementScale + displacementBias );\n#endif";
  3632. var emissivemap_fragment = "#ifdef USE_EMISSIVEMAP\n\tvec4 emissiveColor = texture2D( emissiveMap, vUv );\n\temissiveColor.rgb = emissiveMapTexelToLinear( emissiveColor ).rgb;\n\ttotalEmissiveRadiance *= emissiveColor.rgb;\n#endif";
  3633. var emissivemap_pars_fragment = "#ifdef USE_EMISSIVEMAP\n\tuniform sampler2D emissiveMap;\n#endif";
  3634. var encodings_fragment = "gl_FragColor = linearToOutputTexel( gl_FragColor );";
  3635. 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}";
  3636. 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";
  3637. 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";
  3638. 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";
  3639. 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";
  3640. var fog_vertex = "#ifdef USE_FOG\n\tfogDepth = -mvPosition.z;\n#endif";
  3641. var fog_pars_vertex = "#ifdef USE_FOG\n\tvarying float fogDepth;\n#endif";
  3642. 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";
  3643. 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";
  3644. 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";
  3645. var lightmap_fragment = "#ifdef USE_LIGHTMAP\n\treflectedLight.indirectDiffuse += PI * texture2D( lightMap, vUv2 ).xyz * lightMapIntensity;\n#endif";
  3646. var lightmap_pars_fragment = "#ifdef USE_LIGHTMAP\n\tuniform sampler2D lightMap;\n\tuniform float lightMapIntensity;\n#endif";
  3647. 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";
  3648. 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";
  3649. 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";
  3650. var lights_phong_fragment = "BlinnPhongMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;\nmaterial.specularColor = specular;\nmaterial.specularShininess = shininess;\nmaterial.specularStrength = specularStrength;";
  3651. 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)";
  3652. 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";
  3653. var lights_physical_pars_fragment = "struct PhysicalMaterial {\n\tvec3\tdiffuseColor;\n\tfloat\tspecularRoughness;\n\tvec3\tspecularColor;\n\t#ifndef STANDARD\n\t\tfloat clearCoat;\n\t\tfloat clearCoatRoughness;\n\t#endif\n};\n#define MAXIMUM_SPECULAR_COEFFICIENT 0.16\n#define DEFAULT_SPECULAR_COEFFICIENT 0.04\nfloat clearCoatDHRApprox( const in float roughness, const in float dotNL ) {\n\treturn DEFAULT_SPECULAR_COEFFICIENT + ( 1.0 - DEFAULT_SPECULAR_COEFFICIENT ) * ( pow( 1.0 - dotNL, 5.0 ) * pow( 1.0 - roughness, 2.0 ) );\n}\n#if NUM_RECT_AREA_LIGHTS > 0\n\tvoid RE_Direct_RectArea_Physical( const in RectAreaLight rectAreaLight, const in GeometricContext geometry, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {\n\t\tvec3 normal = geometry.normal;\n\t\tvec3 viewDir = geometry.viewDir;\n\t\tvec3 position = geometry.position;\n\t\tvec3 lightPos = rectAreaLight.position;\n\t\tvec3 halfWidth = rectAreaLight.halfWidth;\n\t\tvec3 halfHeight = rectAreaLight.halfHeight;\n\t\tvec3 lightColor = rectAreaLight.color;\n\t\tfloat roughness = material.specularRoughness;\n\t\tvec3 rectCoords[ 4 ];\n\t\trectCoords[ 0 ] = lightPos + halfWidth - halfHeight;\t\trectCoords[ 1 ] = lightPos - halfWidth - halfHeight;\n\t\trectCoords[ 2 ] = lightPos - halfWidth + halfHeight;\n\t\trectCoords[ 3 ] = lightPos + halfWidth + halfHeight;\n\t\tvec2 uv = LTC_Uv( normal, viewDir, roughness );\n\t\tvec4 t1 = texture2D( ltc_1, uv );\n\t\tvec4 t2 = texture2D( ltc_2, uv );\n\t\tmat3 mInv = mat3(\n\t\t\tvec3( t1.x, 0, t1.y ),\n\t\t\tvec3( 0, 1, 0 ),\n\t\t\tvec3( t1.z, 0, t1.w )\n\t\t);\n\t\tvec3 fresnel = ( material.specularColor * t2.x + ( vec3( 1.0 ) - material.specularColor ) * t2.y );\n\t\treflectedLight.directSpecular += lightColor * fresnel * LTC_Evaluate( normal, viewDir, position, mInv, rectCoords );\n\t\treflectedLight.directDiffuse += lightColor * material.diffuseColor * LTC_Evaluate( normal, viewDir, position, mat3( 1.0 ), rectCoords );\n\t}\n#endif\nvoid RE_Direct_Physical( const in IncidentLight directLight, const in GeometricContext geometry, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {\n\tfloat dotNL = saturate( dot( geometry.normal, directLight.direction ) );\n\tvec3 irradiance = dotNL * directLight.color;\n\t#ifndef PHYSICALLY_CORRECT_LIGHTS\n\t\tirradiance *= PI;\n\t#endif\n\t#ifndef STANDARD\n\t\tfloat clearCoatDHR = material.clearCoat * clearCoatDHRApprox( material.clearCoatRoughness, dotNL );\n\t#else\n\t\tfloat clearCoatDHR = 0.0;\n\t#endif\n\treflectedLight.directSpecular += ( 1.0 - clearCoatDHR ) * irradiance * BRDF_Specular_GGX( directLight, geometry, material.specularColor, material.specularRoughness );\n\treflectedLight.directDiffuse += ( 1.0 - clearCoatDHR ) * irradiance * BRDF_Diffuse_Lambert( material.diffuseColor );\n\t#ifndef STANDARD\n\t\treflectedLight.directSpecular += irradiance * material.clearCoat * BRDF_Specular_GGX( directLight, geometry, vec3( DEFAULT_SPECULAR_COEFFICIENT ), material.clearCoatRoughness );\n\t#endif\n}\nvoid RE_IndirectDiffuse_Physical( const in vec3 irradiance, const in GeometricContext geometry, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {\n\t#ifndef ENVMAP_TYPE_CUBE_UV\n\t\treflectedLight.indirectDiffuse += irradiance * BRDF_Diffuse_Lambert( material.diffuseColor );\n\t#endif\n}\nvoid RE_IndirectSpecular_Physical( const in vec3 radiance, const in vec3 irradiance, const in vec3 clearCoatRadiance, const in GeometricContext geometry, const in PhysicalMaterial material, inout ReflectedLight reflectedLight) {\n\t#ifndef STANDARD\n\t\tfloat dotNV = saturate( dot( geometry.normal, geometry.viewDir ) );\n\t\tfloat dotNL = dotNV;\n\t\tfloat clearCoatDHR = material.clearCoat * clearCoatDHRApprox( material.clearCoatRoughness, dotNL );\n\t#else\n\t\tfloat clearCoatDHR = 0.0;\n\t#endif\n\tfloat clearCoatInv = 1.0 - clearCoatDHR;\n\t#if defined( ENVMAP_TYPE_CUBE_UV )\n\t\tvec3 singleScattering = vec3( 0.0 );\n\t\tvec3 multiScattering = vec3( 0.0 );\n\t\tvec3 cosineWeightedIrradiance = irradiance * RECIPROCAL_PI;\n\t\tBRDF_Specular_Multiscattering_Environment( geometry, material.specularColor, material.specularRoughness, singleScattering, multiScattering );\n\t\tvec3 diffuse = material.diffuseColor;\n\t\treflectedLight.indirectSpecular += clearCoatInv * radiance * singleScattering;\n\t\treflectedLight.indirectDiffuse += multiScattering * cosineWeightedIrradiance;\n\t\treflectedLight.indirectDiffuse += diffuse * cosineWeightedIrradiance;\n\t#else\n\t\treflectedLight.indirectSpecular += clearCoatInv * radiance * BRDF_Specular_GGX_Environment( geometry, material.specularColor, material.specularRoughness );\n\t#endif\n\t#ifndef STANDARD\n\t\treflectedLight.indirectSpecular += clearCoatRadiance * material.clearCoat * BRDF_Specular_GGX_Environment( geometry, vec3( DEFAULT_SPECULAR_COEFFICIENT ), material.clearCoatRoughness );\n\t#endif\n}\n#define RE_Direct\t\t\t\tRE_Direct_Physical\n#define RE_Direct_RectArea\t\tRE_Direct_RectArea_Physical\n#define RE_IndirectDiffuse\t\tRE_IndirectDiffuse_Physical\n#define RE_IndirectSpecular\t\tRE_IndirectSpecular_Physical\n#define Material_BlinnShininessExponent( material ) GGXRoughnessToBlinnExponent( material.specularRoughness )\n#define Material_ClearCoat_BlinnShininessExponent( material ) GGXRoughnessToBlinnExponent( material.clearCoatRoughness )\nfloat computeSpecularOcclusion( const in float dotNV, const in float ambientOcclusion, const in float roughness ) {\n\treturn saturate( pow( dotNV + ambientOcclusion, exp2( - 16.0 * roughness - 1.0 ) ) - 1.0 + ambientOcclusion );\n}";
  3654. 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";
  3655. 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";
  3656. 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";
  3657. var logdepthbuf_fragment = "#if defined( USE_LOGDEPTHBUF ) && defined( USE_LOGDEPTHBUF_EXT )\n\tgl_FragDepthEXT = log2( vFragDepth ) * logDepthBufFC * 0.5;\n#endif";
  3658. var logdepthbuf_pars_fragment = "#if defined( USE_LOGDEPTHBUF ) && defined( USE_LOGDEPTHBUF_EXT )\n\tuniform float logDepthBufFC;\n\tvarying float vFragDepth;\n#endif";
  3659. 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";
  3660. 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";
  3661. var map_fragment = "#ifdef USE_MAP\n\tvec4 texelColor = texture2D( map, vUv );\n\ttexelColor = mapTexelToLinear( texelColor );\n\tdiffuseColor *= texelColor;\n#endif";
  3662. var map_pars_fragment = "#ifdef USE_MAP\n\tuniform sampler2D map;\n#endif";
  3663. 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";
  3664. var map_particle_pars_fragment = "#ifdef USE_MAP\n\tuniform mat3 uvTransform;\n\tuniform sampler2D map;\n#endif";
  3665. var metalnessmap_fragment = "float metalnessFactor = metalness;\n#ifdef USE_METALNESSMAP\n\tvec4 texelMetalness = texture2D( metalnessMap, vUv );\n\tmetalnessFactor *= texelMetalness.b;\n#endif";
  3666. var metalnessmap_pars_fragment = "#ifdef USE_METALNESSMAP\n\tuniform sampler2D metalnessMap;\n#endif";
  3667. 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";
  3668. 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";
  3669. 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";
  3670. 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";
  3671. 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";
  3672. 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";
  3673. 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}";
  3674. var premultiplied_alpha_fragment = "#ifdef PREMULTIPLIED_ALPHA\n\tgl_FragColor.rgb *= gl_FragColor.a;\n#endif";
  3675. var project_vertex = "vec4 mvPosition = modelViewMatrix * vec4( transformed, 1.0 );\ngl_Position = projectionMatrix * mvPosition;";
  3676. var dithering_fragment = "#if defined( DITHERING )\n\tgl_FragColor.rgb = dithering( gl_FragColor.rgb );\n#endif";
  3677. 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";
  3678. var roughnessmap_fragment = "float roughnessFactor = roughness;\n#ifdef USE_ROUGHNESSMAP\n\tvec4 texelRoughness = texture2D( roughnessMap, vUv );\n\troughnessFactor *= texelRoughness.g;\n#endif";
  3679. var roughnessmap_pars_fragment = "#ifdef USE_ROUGHNESSMAP\n\tuniform sampler2D roughnessMap;\n#endif";
  3680. 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";
  3681. 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";
  3682. 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";
  3683. 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}";
  3684. 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";
  3685. 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";
  3686. 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";
  3687. 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";
  3688. 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";
  3689. var specularmap_pars_fragment = "#ifdef USE_SPECULARMAP\n\tuniform sampler2D specularMap;\n#endif";
  3690. var tonemapping_fragment = "#if defined( TONE_MAPPING )\n\tgl_FragColor.rgb = toneMapping( gl_FragColor.rgb );\n#endif";
  3691. 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}";
  3692. 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";
  3693. 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";
  3694. 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";
  3695. var uv2_pars_fragment = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tvarying vec2 vUv2;\n#endif";
  3696. var uv2_pars_vertex = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tattribute vec2 uv2;\n\tvarying vec2 vUv2;\n#endif";
  3697. var uv2_vertex = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tvUv2 = uv2;\n#endif";
  3698. var worldpos_vertex = "#if defined( USE_ENVMAP ) || defined( DISTANCE ) || defined ( USE_SHADOWMAP )\n\tvec4 worldPosition = modelMatrix * vec4( transformed, 1.0 );\n#endif";
  3699. 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}";
  3700. 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}";
  3701. 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}";
  3702. 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}";
  3703. 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}";
  3704. 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}";
  3705. 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}";
  3706. 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}";
  3707. 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}";
  3708. 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}";
  3709. 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}";
  3710. 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}";
  3711. 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}";
  3712. 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}";
  3713. 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}";
  3714. 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}";
  3715. 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}";
  3716. 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}";
  3717. 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}";
  3718. 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}";
  3719. 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}";
  3720. 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}";
  3721. 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}";
  3722. 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}";
  3723. 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}";
  3724. 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}";
  3725. 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}";
  3726. 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}";
  3727. 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}";
  3728. 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}";
  3729. var ShaderChunk = {
  3730. alphamap_fragment: alphamap_fragment,
  3731. alphamap_pars_fragment: alphamap_pars_fragment,
  3732. alphatest_fragment: alphatest_fragment,
  3733. aomap_fragment: aomap_fragment,
  3734. aomap_pars_fragment: aomap_pars_fragment,
  3735. begin_vertex: begin_vertex,
  3736. beginnormal_vertex: beginnormal_vertex,
  3737. bsdfs: bsdfs,
  3738. bumpmap_pars_fragment: bumpmap_pars_fragment,
  3739. clipping_planes_fragment: clipping_planes_fragment,
  3740. clipping_planes_pars_fragment: clipping_planes_pars_fragment,
  3741. clipping_planes_pars_vertex: clipping_planes_pars_vertex,
  3742. clipping_planes_vertex: clipping_planes_vertex,
  3743. color_fragment: color_fragment,
  3744. color_pars_fragment: color_pars_fragment,
  3745. color_pars_vertex: color_pars_vertex,
  3746. color_vertex: color_vertex,
  3747. common: common,
  3748. cube_uv_reflection_fragment: cube_uv_reflection_fragment,
  3749. defaultnormal_vertex: defaultnormal_vertex,
  3750. displacementmap_pars_vertex: displacementmap_pars_vertex,
  3751. displacementmap_vertex: displacementmap_vertex,
  3752. emissivemap_fragment: emissivemap_fragment,
  3753. emissivemap_pars_fragment: emissivemap_pars_fragment,
  3754. encodings_fragment: encodings_fragment,
  3755. encodings_pars_fragment: encodings_pars_fragment,
  3756. envmap_fragment: envmap_fragment,
  3757. envmap_pars_fragment: envmap_pars_fragment,
  3758. envmap_pars_vertex: envmap_pars_vertex,
  3759. envmap_physical_pars_fragment: envmap_physical_pars_fragment,
  3760. envmap_vertex: envmap_vertex,
  3761. fog_vertex: fog_vertex,
  3762. fog_pars_vertex: fog_pars_vertex,
  3763. fog_fragment: fog_fragment,
  3764. fog_pars_fragment: fog_pars_fragment,
  3765. gradientmap_pars_fragment: gradientmap_pars_fragment,
  3766. lightmap_fragment: lightmap_fragment,
  3767. lightmap_pars_fragment: lightmap_pars_fragment,
  3768. lights_lambert_vertex: lights_lambert_vertex,
  3769. lights_pars_begin: lights_pars_begin,
  3770. lights_phong_fragment: lights_phong_fragment,
  3771. lights_phong_pars_fragment: lights_phong_pars_fragment,
  3772. lights_physical_fragment: lights_physical_fragment,
  3773. lights_physical_pars_fragment: lights_physical_pars_fragment,
  3774. lights_fragment_begin: lights_fragment_begin,
  3775. lights_fragment_maps: lights_fragment_maps,
  3776. lights_fragment_end: lights_fragment_end,
  3777. logdepthbuf_fragment: logdepthbuf_fragment,
  3778. logdepthbuf_pars_fragment: logdepthbuf_pars_fragment,
  3779. logdepthbuf_pars_vertex: logdepthbuf_pars_vertex,
  3780. logdepthbuf_vertex: logdepthbuf_vertex,
  3781. map_fragment: map_fragment,
  3782. map_pars_fragment: map_pars_fragment,
  3783. map_particle_fragment: map_particle_fragment,
  3784. map_particle_pars_fragment: map_particle_pars_fragment,
  3785. metalnessmap_fragment: metalnessmap_fragment,
  3786. metalnessmap_pars_fragment: metalnessmap_pars_fragment,
  3787. morphnormal_vertex: morphnormal_vertex,
  3788. morphtarget_pars_vertex: morphtarget_pars_vertex,
  3789. morphtarget_vertex: morphtarget_vertex,
  3790. normal_fragment_begin: normal_fragment_begin,
  3791. normal_fragment_maps: normal_fragment_maps,
  3792. normalmap_pars_fragment: normalmap_pars_fragment,
  3793. packing: packing,
  3794. premultiplied_alpha_fragment: premultiplied_alpha_fragment,
  3795. project_vertex: project_vertex,
  3796. dithering_fragment: dithering_fragment,
  3797. dithering_pars_fragment: dithering_pars_fragment,
  3798. roughnessmap_fragment: roughnessmap_fragment,
  3799. roughnessmap_pars_fragment: roughnessmap_pars_fragment,
  3800. shadowmap_pars_fragment: shadowmap_pars_fragment,
  3801. shadowmap_pars_vertex: shadowmap_pars_vertex,
  3802. shadowmap_vertex: shadowmap_vertex,
  3803. shadowmask_pars_fragment: shadowmask_pars_fragment,
  3804. skinbase_vertex: skinbase_vertex,
  3805. skinning_pars_vertex: skinning_pars_vertex,
  3806. skinning_vertex: skinning_vertex,
  3807. skinnormal_vertex: skinnormal_vertex,
  3808. specularmap_fragment: specularmap_fragment,
  3809. specularmap_pars_fragment: specularmap_pars_fragment,
  3810. tonemapping_fragment: tonemapping_fragment,
  3811. tonemapping_pars_fragment: tonemapping_pars_fragment,
  3812. uv_pars_fragment: uv_pars_fragment,
  3813. uv_pars_vertex: uv_pars_vertex,
  3814. uv_vertex: uv_vertex,
  3815. uv2_pars_fragment: uv2_pars_fragment,
  3816. uv2_pars_vertex: uv2_pars_vertex,
  3817. uv2_vertex: uv2_vertex,
  3818. worldpos_vertex: worldpos_vertex,
  3819. background_frag: background_frag,
  3820. background_vert: background_vert,
  3821. cube_frag: cube_frag,
  3822. cube_vert: cube_vert,
  3823. depth_frag: depth_frag,
  3824. depth_vert: depth_vert,
  3825. distanceRGBA_frag: distanceRGBA_frag,
  3826. distanceRGBA_vert: distanceRGBA_vert,
  3827. equirect_frag: equirect_frag,
  3828. equirect_vert: equirect_vert,
  3829. linedashed_frag: linedashed_frag,
  3830. linedashed_vert: linedashed_vert,
  3831. meshbasic_frag: meshbasic_frag,
  3832. meshbasic_vert: meshbasic_vert,
  3833. meshlambert_frag: meshlambert_frag,
  3834. meshlambert_vert: meshlambert_vert,
  3835. meshmatcap_frag: meshmatcap_frag,
  3836. meshmatcap_vert: meshmatcap_vert,
  3837. meshphong_frag: meshphong_frag,
  3838. meshphong_vert: meshphong_vert,
  3839. meshphysical_frag: meshphysical_frag,
  3840. meshphysical_vert: meshphysical_vert,
  3841. normal_frag: normal_frag,
  3842. normal_vert: normal_vert,
  3843. points_frag: points_frag,
  3844. points_vert: points_vert,
  3845. shadow_frag: shadow_frag,
  3846. shadow_vert: shadow_vert,
  3847. sprite_frag: sprite_frag,
  3848. sprite_vert: sprite_vert
  3849. };
  3850. /**
  3851. * Uniform Utilities
  3852. */
  3853. function cloneUniforms( src ) {
  3854. var dst = {};
  3855. for ( var u in src ) {
  3856. dst[ u ] = {};
  3857. for ( var p in src[ u ] ) {
  3858. var property = src[ u ][ p ];
  3859. if ( property && ( property.isColor ||
  3860. property.isMatrix3 || property.isMatrix4 ||
  3861. property.isVector2 || property.isVector3 || property.isVector4 ||
  3862. property.isTexture ) ) {
  3863. dst[ u ][ p ] = property.clone();
  3864. } else if ( Array.isArray( property ) ) {
  3865. dst[ u ][ p ] = property.slice();
  3866. } else {
  3867. dst[ u ][ p ] = property;
  3868. }
  3869. }
  3870. }
  3871. return dst;
  3872. }
  3873. function mergeUniforms( uniforms ) {
  3874. var merged = {};
  3875. for ( var u = 0; u < uniforms.length; u ++ ) {
  3876. var tmp = cloneUniforms( uniforms[ u ] );
  3877. for ( var p in tmp ) {
  3878. merged[ p ] = tmp[ p ];
  3879. }
  3880. }
  3881. return merged;
  3882. }
  3883. // Legacy
  3884. var UniformsUtils = { clone: cloneUniforms, merge: mergeUniforms };
  3885. /**
  3886. * @author mrdoob / http://mrdoob.com/
  3887. */
  3888. var ColorKeywords = { 'aliceblue': 0xF0F8FF, 'antiquewhite': 0xFAEBD7, 'aqua': 0x00FFFF, 'aquamarine': 0x7FFFD4, 'azure': 0xF0FFFF,
  3889. 'beige': 0xF5F5DC, 'bisque': 0xFFE4C4, 'black': 0x000000, 'blanchedalmond': 0xFFEBCD, 'blue': 0x0000FF, 'blueviolet': 0x8A2BE2,
  3890. 'brown': 0xA52A2A, 'burlywood': 0xDEB887, 'cadetblue': 0x5F9EA0, 'chartreuse': 0x7FFF00, 'chocolate': 0xD2691E, 'coral': 0xFF7F50,
  3891. 'cornflowerblue': 0x6495ED, 'cornsilk': 0xFFF8DC, 'crimson': 0xDC143C, 'cyan': 0x00FFFF, 'darkblue': 0x00008B, 'darkcyan': 0x008B8B,
  3892. 'darkgoldenrod': 0xB8860B, 'darkgray': 0xA9A9A9, 'darkgreen': 0x006400, 'darkgrey': 0xA9A9A9, 'darkkhaki': 0xBDB76B, 'darkmagenta': 0x8B008B,
  3893. 'darkolivegreen': 0x556B2F, 'darkorange': 0xFF8C00, 'darkorchid': 0x9932CC, 'darkred': 0x8B0000, 'darksalmon': 0xE9967A, 'darkseagreen': 0x8FBC8F,
  3894. 'darkslateblue': 0x483D8B, 'darkslategray': 0x2F4F4F, 'darkslategrey': 0x2F4F4F, 'darkturquoise': 0x00CED1, 'darkviolet': 0x9400D3,
  3895. 'deeppink': 0xFF1493, 'deepskyblue': 0x00BFFF, 'dimgray': 0x696969, 'dimgrey': 0x696969, 'dodgerblue': 0x1E90FF, 'firebrick': 0xB22222,
  3896. 'floralwhite': 0xFFFAF0, 'forestgreen': 0x228B22, 'fuchsia': 0xFF00FF, 'gainsboro': 0xDCDCDC, 'ghostwhite': 0xF8F8FF, 'gold': 0xFFD700,
  3897. 'goldenrod': 0xDAA520, 'gray': 0x808080, 'green': 0x008000, 'greenyellow': 0xADFF2F, 'grey': 0x808080, 'honeydew': 0xF0FFF0, 'hotpink': 0xFF69B4,
  3898. 'indianred': 0xCD5C5C, 'indigo': 0x4B0082, 'ivory': 0xFFFFF0, 'khaki': 0xF0E68C, 'lavender': 0xE6E6FA, 'lavenderblush': 0xFFF0F5, 'lawngreen': 0x7CFC00,
  3899. 'lemonchiffon': 0xFFFACD, 'lightblue': 0xADD8E6, 'lightcoral': 0xF08080, 'lightcyan': 0xE0FFFF, 'lightgoldenrodyellow': 0xFAFAD2, 'lightgray': 0xD3D3D3,
  3900. 'lightgreen': 0x90EE90, 'lightgrey': 0xD3D3D3, 'lightpink': 0xFFB6C1, 'lightsalmon': 0xFFA07A, 'lightseagreen': 0x20B2AA, 'lightskyblue': 0x87CEFA,
  3901. 'lightslategray': 0x778899, 'lightslategrey': 0x778899, 'lightsteelblue': 0xB0C4DE, 'lightyellow': 0xFFFFE0, 'lime': 0x00FF00, 'limegreen': 0x32CD32,
  3902. 'linen': 0xFAF0E6, 'magenta': 0xFF00FF, 'maroon': 0x800000, 'mediumaquamarine': 0x66CDAA, 'mediumblue': 0x0000CD, 'mediumorchid': 0xBA55D3,
  3903. 'mediumpurple': 0x9370DB, 'mediumseagreen': 0x3CB371, 'mediumslateblue': 0x7B68EE, 'mediumspringgreen': 0x00FA9A, 'mediumturquoise': 0x48D1CC,
  3904. 'mediumvioletred': 0xC71585, 'midnightblue': 0x191970, 'mintcream': 0xF5FFFA, 'mistyrose': 0xFFE4E1, 'moccasin': 0xFFE4B5, 'navajowhite': 0xFFDEAD,
  3905. 'navy': 0x000080, 'oldlace': 0xFDF5E6, 'olive': 0x808000, 'olivedrab': 0x6B8E23, 'orange': 0xFFA500, 'orangered': 0xFF4500, 'orchid': 0xDA70D6,
  3906. 'palegoldenrod': 0xEEE8AA, 'palegreen': 0x98FB98, 'paleturquoise': 0xAFEEEE, 'palevioletred': 0xDB7093, 'papayawhip': 0xFFEFD5, 'peachpuff': 0xFFDAB9,
  3907. 'peru': 0xCD853F, 'pink': 0xFFC0CB, 'plum': 0xDDA0DD, 'powderblue': 0xB0E0E6, 'purple': 0x800080, 'rebeccapurple': 0x663399, 'red': 0xFF0000, 'rosybrown': 0xBC8F8F,
  3908. 'royalblue': 0x4169E1, 'saddlebrown': 0x8B4513, 'salmon': 0xFA8072, 'sandybrown': 0xF4A460, 'seagreen': 0x2E8B57, 'seashell': 0xFFF5EE,
  3909. 'sienna': 0xA0522D, 'silver': 0xC0C0C0, 'skyblue': 0x87CEEB, 'slateblue': 0x6A5ACD, 'slategray': 0x708090, 'slategrey': 0x708090, 'snow': 0xFFFAFA,
  3910. 'springgreen': 0x00FF7F, 'steelblue': 0x4682B4, 'tan': 0xD2B48C, 'teal': 0x008080, 'thistle': 0xD8BFD8, 'tomato': 0xFF6347, 'turquoise': 0x40E0D0,
  3911. 'violet': 0xEE82EE, 'wheat': 0xF5DEB3, 'white': 0xFFFFFF, 'whitesmoke': 0xF5F5F5, 'yellow': 0xFFFF00, 'yellowgreen': 0x9ACD32 };
  3912. function Color( r, g, b ) {
  3913. if ( g === undefined && b === undefined ) {
  3914. // r is THREE.Color, hex or string
  3915. return this.set( r );
  3916. }
  3917. return this.setRGB( r, g, b );
  3918. }
  3919. Object.assign( Color.prototype, {
  3920. isColor: true,
  3921. r: 1, g: 1, b: 1,
  3922. set: function ( value ) {
  3923. if ( value && value.isColor ) {
  3924. this.copy( value );
  3925. } else if ( typeof value === 'number' ) {
  3926. this.setHex( value );
  3927. } else if ( typeof value === 'string' ) {
  3928. this.setStyle( value );
  3929. }
  3930. return this;
  3931. },
  3932. setScalar: function ( scalar ) {
  3933. this.r = scalar;
  3934. this.g = scalar;
  3935. this.b = scalar;
  3936. return this;
  3937. },
  3938. setHex: function ( hex ) {
  3939. hex = Math.floor( hex );
  3940. this.r = ( hex >> 16 & 255 ) / 255;
  3941. this.g = ( hex >> 8 & 255 ) / 255;
  3942. this.b = ( hex & 255 ) / 255;
  3943. return this;
  3944. },
  3945. setRGB: function ( r, g, b ) {
  3946. this.r = r;
  3947. this.g = g;
  3948. this.b = b;
  3949. return this;
  3950. },
  3951. setHSL: function () {
  3952. function hue2rgb( p, q, t ) {
  3953. if ( t < 0 ) t += 1;
  3954. if ( t > 1 ) t -= 1;
  3955. if ( t < 1 / 6 ) return p + ( q - p ) * 6 * t;
  3956. if ( t < 1 / 2 ) return q;
  3957. if ( t < 2 / 3 ) return p + ( q - p ) * 6 * ( 2 / 3 - t );
  3958. return p;
  3959. }
  3960. return function setHSL( h, s, l ) {
  3961. // h,s,l ranges are in 0.0 - 1.0
  3962. h = _Math.euclideanModulo( h, 1 );
  3963. s = _Math.clamp( s, 0, 1 );
  3964. l = _Math.clamp( l, 0, 1 );
  3965. if ( s === 0 ) {
  3966. this.r = this.g = this.b = l;
  3967. } else {
  3968. var p = l <= 0.5 ? l * ( 1 + s ) : l + s - ( l * s );
  3969. var q = ( 2 * l ) - p;
  3970. this.r = hue2rgb( q, p, h + 1 / 3 );
  3971. this.g = hue2rgb( q, p, h );
  3972. this.b = hue2rgb( q, p, h - 1 / 3 );
  3973. }
  3974. return this;
  3975. };
  3976. }(),
  3977. setStyle: function ( style ) {
  3978. function handleAlpha( string ) {
  3979. if ( string === undefined ) return;
  3980. if ( parseFloat( string ) < 1 ) {
  3981. console.warn( 'THREE.Color: Alpha component of ' + style + ' will be ignored.' );
  3982. }
  3983. }
  3984. var m;
  3985. if ( m = /^((?:rgb|hsl)a?)\(\s*([^\)]*)\)/.exec( style ) ) {
  3986. // rgb / hsl
  3987. var color;
  3988. var name = m[ 1 ];
  3989. var components = m[ 2 ];
  3990. switch ( name ) {
  3991. case 'rgb':
  3992. case 'rgba':
  3993. if ( color = /^(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec( components ) ) {
  3994. // rgb(255,0,0) rgba(255,0,0,0.5)
  3995. this.r = Math.min( 255, parseInt( color[ 1 ], 10 ) ) / 255;
  3996. this.g = Math.min( 255, parseInt( color[ 2 ], 10 ) ) / 255;
  3997. this.b = Math.min( 255, parseInt( color[ 3 ], 10 ) ) / 255;
  3998. handleAlpha( color[ 5 ] );
  3999. return this;
  4000. }
  4001. if ( color = /^(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec( components ) ) {
  4002. // rgb(100%,0%,0%) rgba(100%,0%,0%,0.5)
  4003. this.r = Math.min( 100, parseInt( color[ 1 ], 10 ) ) / 100;
  4004. this.g = Math.min( 100, parseInt( color[ 2 ], 10 ) ) / 100;
  4005. this.b = Math.min( 100, parseInt( color[ 3 ], 10 ) ) / 100;
  4006. handleAlpha( color[ 5 ] );
  4007. return this;
  4008. }
  4009. break;
  4010. case 'hsl':
  4011. case 'hsla':
  4012. if ( color = /^([0-9]*\.?[0-9]+)\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec( components ) ) {
  4013. // hsl(120,50%,50%) hsla(120,50%,50%,0.5)
  4014. var h = parseFloat( color[ 1 ] ) / 360;
  4015. var s = parseInt( color[ 2 ], 10 ) / 100;
  4016. var l = parseInt( color[ 3 ], 10 ) / 100;
  4017. handleAlpha( color[ 5 ] );
  4018. return this.setHSL( h, s, l );
  4019. }
  4020. break;
  4021. }
  4022. } else if ( m = /^\#([A-Fa-f0-9]+)$/.exec( style ) ) {
  4023. // hex color
  4024. var hex = m[ 1 ];
  4025. var size = hex.length;
  4026. if ( size === 3 ) {
  4027. // #ff0
  4028. this.r = parseInt( hex.charAt( 0 ) + hex.charAt( 0 ), 16 ) / 255;
  4029. this.g = parseInt( hex.charAt( 1 ) + hex.charAt( 1 ), 16 ) / 255;
  4030. this.b = parseInt( hex.charAt( 2 ) + hex.charAt( 2 ), 16 ) / 255;
  4031. return this;
  4032. } else if ( size === 6 ) {
  4033. // #ff0000
  4034. this.r = parseInt( hex.charAt( 0 ) + hex.charAt( 1 ), 16 ) / 255;
  4035. this.g = parseInt( hex.charAt( 2 ) + hex.charAt( 3 ), 16 ) / 255;
  4036. this.b = parseInt( hex.charAt( 4 ) + hex.charAt( 5 ), 16 ) / 255;
  4037. return this;
  4038. }
  4039. }
  4040. if ( style && style.length > 0 ) {
  4041. // color keywords
  4042. var hex = ColorKeywords[ style ];
  4043. if ( hex !== undefined ) {
  4044. // red
  4045. this.setHex( hex );
  4046. } else {
  4047. // unknown color
  4048. console.warn( 'THREE.Color: Unknown color ' + style );
  4049. }
  4050. }
  4051. return this;
  4052. },
  4053. clone: function () {
  4054. return new this.constructor( this.r, this.g, this.b );
  4055. },
  4056. copy: function ( color ) {
  4057. this.r = color.r;
  4058. this.g = color.g;
  4059. this.b = color.b;
  4060. return this;
  4061. },
  4062. copyGammaToLinear: function ( color, gammaFactor ) {
  4063. if ( gammaFactor === undefined ) gammaFactor = 2.0;
  4064. this.r = Math.pow( color.r, gammaFactor );
  4065. this.g = Math.pow( color.g, gammaFactor );
  4066. this.b = Math.pow( color.b, gammaFactor );
  4067. return this;
  4068. },
  4069. copyLinearToGamma: function ( color, gammaFactor ) {
  4070. if ( gammaFactor === undefined ) gammaFactor = 2.0;
  4071. var safeInverse = ( gammaFactor > 0 ) ? ( 1.0 / gammaFactor ) : 1.0;
  4072. this.r = Math.pow( color.r, safeInverse );
  4073. this.g = Math.pow( color.g, safeInverse );
  4074. this.b = Math.pow( color.b, safeInverse );
  4075. return this;
  4076. },
  4077. convertGammaToLinear: function ( gammaFactor ) {
  4078. this.copyGammaToLinear( this, gammaFactor );
  4079. return this;
  4080. },
  4081. convertLinearToGamma: function ( gammaFactor ) {
  4082. this.copyLinearToGamma( this, gammaFactor );
  4083. return this;
  4084. },
  4085. copySRGBToLinear: function () {
  4086. function SRGBToLinear( c ) {
  4087. return ( c < 0.04045 ) ? c * 0.0773993808 : Math.pow( c * 0.9478672986 + 0.0521327014, 2.4 );
  4088. }
  4089. return function copySRGBToLinear( color ) {
  4090. this.r = SRGBToLinear( color.r );
  4091. this.g = SRGBToLinear( color.g );
  4092. this.b = SRGBToLinear( color.b );
  4093. return this;
  4094. };
  4095. }(),
  4096. copyLinearToSRGB: function () {
  4097. function LinearToSRGB( c ) {
  4098. return ( c < 0.0031308 ) ? c * 12.92 : 1.055 * ( Math.pow( c, 0.41666 ) ) - 0.055;
  4099. }
  4100. return function copyLinearToSRGB( color ) {
  4101. this.r = LinearToSRGB( color.r );
  4102. this.g = LinearToSRGB( color.g );
  4103. this.b = LinearToSRGB( color.b );
  4104. return this;
  4105. };
  4106. }(),
  4107. convertSRGBToLinear: function () {
  4108. this.copySRGBToLinear( this );
  4109. return this;
  4110. },
  4111. convertLinearToSRGB: function () {
  4112. this.copyLinearToSRGB( this );
  4113. return this;
  4114. },
  4115. getHex: function () {
  4116. return ( this.r * 255 ) << 16 ^ ( this.g * 255 ) << 8 ^ ( this.b * 255 ) << 0;
  4117. },
  4118. getHexString: function () {
  4119. return ( '000000' + this.getHex().toString( 16 ) ).slice( - 6 );
  4120. },
  4121. getHSL: function ( target ) {
  4122. // h,s,l ranges are in 0.0 - 1.0
  4123. if ( target === undefined ) {
  4124. console.warn( 'THREE.Color: .getHSL() target is now required' );
  4125. target = { h: 0, s: 0, l: 0 };
  4126. }
  4127. var r = this.r, g = this.g, b = this.b;
  4128. var max = Math.max( r, g, b );
  4129. var min = Math.min( r, g, b );
  4130. var hue, saturation;
  4131. var lightness = ( min + max ) / 2.0;
  4132. if ( min === max ) {
  4133. hue = 0;
  4134. saturation = 0;
  4135. } else {
  4136. var delta = max - min;
  4137. saturation = lightness <= 0.5 ? delta / ( max + min ) : delta / ( 2 - max - min );
  4138. switch ( max ) {
  4139. case r: hue = ( g - b ) / delta + ( g < b ? 6 : 0 ); break;
  4140. case g: hue = ( b - r ) / delta + 2; break;
  4141. case b: hue = ( r - g ) / delta + 4; break;
  4142. }
  4143. hue /= 6;
  4144. }
  4145. target.h = hue;
  4146. target.s = saturation;
  4147. target.l = lightness;
  4148. return target;
  4149. },
  4150. getStyle: function () {
  4151. return 'rgb(' + ( ( this.r * 255 ) | 0 ) + ',' + ( ( this.g * 255 ) | 0 ) + ',' + ( ( this.b * 255 ) | 0 ) + ')';
  4152. },
  4153. offsetHSL: function () {
  4154. var hsl = {};
  4155. return function ( h, s, l ) {
  4156. this.getHSL( hsl );
  4157. hsl.h += h; hsl.s += s; hsl.l += l;
  4158. this.setHSL( hsl.h, hsl.s, hsl.l );
  4159. return this;
  4160. };
  4161. }(),
  4162. add: function ( color ) {
  4163. this.r += color.r;
  4164. this.g += color.g;
  4165. this.b += color.b;
  4166. return this;
  4167. },
  4168. addColors: function ( color1, color2 ) {
  4169. this.r = color1.r + color2.r;
  4170. this.g = color1.g + color2.g;
  4171. this.b = color1.b + color2.b;
  4172. return this;
  4173. },
  4174. addScalar: function ( s ) {
  4175. this.r += s;
  4176. this.g += s;
  4177. this.b += s;
  4178. return this;
  4179. },
  4180. sub: function ( color ) {
  4181. this.r = Math.max( 0, this.r - color.r );
  4182. this.g = Math.max( 0, this.g - color.g );
  4183. this.b = Math.max( 0, this.b - color.b );
  4184. return this;
  4185. },
  4186. multiply: function ( color ) {
  4187. this.r *= color.r;
  4188. this.g *= color.g;
  4189. this.b *= color.b;
  4190. return this;
  4191. },
  4192. multiplyScalar: function ( s ) {
  4193. this.r *= s;
  4194. this.g *= s;
  4195. this.b *= s;
  4196. return this;
  4197. },
  4198. lerp: function ( color, alpha ) {
  4199. this.r += ( color.r - this.r ) * alpha;
  4200. this.g += ( color.g - this.g ) * alpha;
  4201. this.b += ( color.b - this.b ) * alpha;
  4202. return this;
  4203. },
  4204. lerpHSL: function () {
  4205. var hslA = { h: 0, s: 0, l: 0 };
  4206. var hslB = { h: 0, s: 0, l: 0 };
  4207. return function lerpHSL( color, alpha ) {
  4208. this.getHSL( hslA );
  4209. color.getHSL( hslB );
  4210. var h = _Math.lerp( hslA.h, hslB.h, alpha );
  4211. var s = _Math.lerp( hslA.s, hslB.s, alpha );
  4212. var l = _Math.lerp( hslA.l, hslB.l, alpha );
  4213. this.setHSL( h, s, l );
  4214. return this;
  4215. };
  4216. }(),
  4217. equals: function ( c ) {
  4218. return ( c.r === this.r ) && ( c.g === this.g ) && ( c.b === this.b );
  4219. },
  4220. fromArray: function ( array, offset ) {
  4221. if ( offset === undefined ) offset = 0;
  4222. this.r = array[ offset ];
  4223. this.g = array[ offset + 1 ];
  4224. this.b = array[ offset + 2 ];
  4225. return this;
  4226. },
  4227. toArray: function ( array, offset ) {
  4228. if ( array === undefined ) array = [];
  4229. if ( offset === undefined ) offset = 0;
  4230. array[ offset ] = this.r;
  4231. array[ offset + 1 ] = this.g;
  4232. array[ offset + 2 ] = this.b;
  4233. return array;
  4234. },
  4235. toJSON: function () {
  4236. return this.getHex();
  4237. }
  4238. } );
  4239. /**
  4240. * Uniforms library for shared webgl shaders
  4241. */
  4242. var UniformsLib = {
  4243. common: {
  4244. diffuse: { value: new Color( 0xeeeeee ) },
  4245. opacity: { value: 1.0 },
  4246. map: { value: null },
  4247. uvTransform: { value: new Matrix3() },
  4248. alphaMap: { value: null },
  4249. },
  4250. specularmap: {
  4251. specularMap: { value: null },
  4252. },
  4253. envmap: {
  4254. envMap: { value: null },
  4255. flipEnvMap: { value: - 1 },
  4256. reflectivity: { value: 1.0 },
  4257. refractionRatio: { value: 0.98 },
  4258. maxMipLevel: { value: 0 }
  4259. },
  4260. aomap: {
  4261. aoMap: { value: null },
  4262. aoMapIntensity: { value: 1 }
  4263. },
  4264. lightmap: {
  4265. lightMap: { value: null },
  4266. lightMapIntensity: { value: 1 }
  4267. },
  4268. emissivemap: {
  4269. emissiveMap: { value: null }
  4270. },
  4271. bumpmap: {
  4272. bumpMap: { value: null },
  4273. bumpScale: { value: 1 }
  4274. },
  4275. normalmap: {
  4276. normalMap: { value: null },
  4277. normalScale: { value: new Vector2( 1, 1 ) }
  4278. },
  4279. displacementmap: {
  4280. displacementMap: { value: null },
  4281. displacementScale: { value: 1 },
  4282. displacementBias: { value: 0 }
  4283. },
  4284. roughnessmap: {
  4285. roughnessMap: { value: null }
  4286. },
  4287. metalnessmap: {
  4288. metalnessMap: { value: null }
  4289. },
  4290. gradientmap: {
  4291. gradientMap: { value: null }
  4292. },
  4293. fog: {
  4294. fogDensity: { value: 0.00025 },
  4295. fogNear: { value: 1 },
  4296. fogFar: { value: 2000 },
  4297. fogColor: { value: new Color( 0xffffff ) }
  4298. },
  4299. lights: {
  4300. ambientLightColor: { value: [] },
  4301. lightProbe: { value: [] },
  4302. directionalLights: { value: [], properties: {
  4303. direction: {},
  4304. color: {},
  4305. shadow: {},
  4306. shadowBias: {},
  4307. shadowRadius: {},
  4308. shadowMapSize: {}
  4309. } },
  4310. directionalShadowMap: { value: [] },
  4311. directionalShadowMatrix: { value: [] },
  4312. spotLights: { value: [], properties: {
  4313. color: {},
  4314. position: {},
  4315. direction: {},
  4316. distance: {},
  4317. coneCos: {},
  4318. penumbraCos: {},
  4319. decay: {},
  4320. shadow: {},
  4321. shadowBias: {},
  4322. shadowRadius: {},
  4323. shadowMapSize: {}
  4324. } },
  4325. spotShadowMap: { value: [] },
  4326. spotShadowMatrix: { value: [] },
  4327. pointLights: { value: [], properties: {
  4328. color: {},
  4329. position: {},
  4330. decay: {},
  4331. distance: {},
  4332. shadow: {},
  4333. shadowBias: {},
  4334. shadowRadius: {},
  4335. shadowMapSize: {},
  4336. shadowCameraNear: {},
  4337. shadowCameraFar: {}
  4338. } },
  4339. pointShadowMap: { value: [] },
  4340. pointShadowMatrix: { value: [] },
  4341. hemisphereLights: { value: [], properties: {
  4342. direction: {},
  4343. skyColor: {},
  4344. groundColor: {}
  4345. } },
  4346. // TODO (abelnation): RectAreaLight BRDF data needs to be moved from example to main src
  4347. rectAreaLights: { value: [], properties: {
  4348. color: {},
  4349. position: {},
  4350. width: {},
  4351. height: {}
  4352. } }
  4353. },
  4354. points: {
  4355. diffuse: { value: new Color( 0xeeeeee ) },
  4356. opacity: { value: 1.0 },
  4357. size: { value: 1.0 },
  4358. scale: { value: 1.0 },
  4359. map: { value: null },
  4360. uvTransform: { value: new Matrix3() }
  4361. },
  4362. sprite: {
  4363. diffuse: { value: new Color( 0xeeeeee ) },
  4364. opacity: { value: 1.0 },
  4365. center: { value: new Vector2( 0.5, 0.5 ) },
  4366. rotation: { value: 0.0 },
  4367. map: { value: null },
  4368. uvTransform: { value: new Matrix3() }
  4369. }
  4370. };
  4371. /**
  4372. * @author alteredq / http://alteredqualia.com/
  4373. * @author mrdoob / http://mrdoob.com/
  4374. * @author mikael emtinger / http://gomo.se/
  4375. */
  4376. var ShaderLib = {
  4377. basic: {
  4378. uniforms: mergeUniforms( [
  4379. UniformsLib.common,
  4380. UniformsLib.specularmap,
  4381. UniformsLib.envmap,
  4382. UniformsLib.aomap,
  4383. UniformsLib.lightmap,
  4384. UniformsLib.fog
  4385. ] ),
  4386. vertexShader: ShaderChunk.meshbasic_vert,
  4387. fragmentShader: ShaderChunk.meshbasic_frag
  4388. },
  4389. lambert: {
  4390. uniforms: mergeUniforms( [
  4391. UniformsLib.common,
  4392. UniformsLib.specularmap,
  4393. UniformsLib.envmap,
  4394. UniformsLib.aomap,
  4395. UniformsLib.lightmap,
  4396. UniformsLib.emissivemap,
  4397. UniformsLib.fog,
  4398. UniformsLib.lights,
  4399. {
  4400. emissive: { value: new Color( 0x000000 ) }
  4401. }
  4402. ] ),
  4403. vertexShader: ShaderChunk.meshlambert_vert,
  4404. fragmentShader: ShaderChunk.meshlambert_frag
  4405. },
  4406. phong: {
  4407. uniforms: mergeUniforms( [
  4408. UniformsLib.common,
  4409. UniformsLib.specularmap,
  4410. UniformsLib.envmap,
  4411. UniformsLib.aomap,
  4412. UniformsLib.lightmap,
  4413. UniformsLib.emissivemap,
  4414. UniformsLib.bumpmap,
  4415. UniformsLib.normalmap,
  4416. UniformsLib.displacementmap,
  4417. UniformsLib.gradientmap,
  4418. UniformsLib.fog,
  4419. UniformsLib.lights,
  4420. {
  4421. emissive: { value: new Color( 0x000000 ) },
  4422. specular: { value: new Color( 0x111111 ) },
  4423. shininess: { value: 30 }
  4424. }
  4425. ] ),
  4426. vertexShader: ShaderChunk.meshphong_vert,
  4427. fragmentShader: ShaderChunk.meshphong_frag
  4428. },
  4429. standard: {
  4430. uniforms: mergeUniforms( [
  4431. UniformsLib.common,
  4432. UniformsLib.envmap,
  4433. UniformsLib.aomap,
  4434. UniformsLib.lightmap,
  4435. UniformsLib.emissivemap,
  4436. UniformsLib.bumpmap,
  4437. UniformsLib.normalmap,
  4438. UniformsLib.displacementmap,
  4439. UniformsLib.roughnessmap,
  4440. UniformsLib.metalnessmap,
  4441. UniformsLib.fog,
  4442. UniformsLib.lights,
  4443. {
  4444. emissive: { value: new Color( 0x000000 ) },
  4445. roughness: { value: 0.5 },
  4446. metalness: { value: 0.5 },
  4447. envMapIntensity: { value: 1 } // temporary
  4448. }
  4449. ] ),
  4450. vertexShader: ShaderChunk.meshphysical_vert,
  4451. fragmentShader: ShaderChunk.meshphysical_frag
  4452. },
  4453. matcap: {
  4454. uniforms: mergeUniforms( [
  4455. UniformsLib.common,
  4456. UniformsLib.bumpmap,
  4457. UniformsLib.normalmap,
  4458. UniformsLib.displacementmap,
  4459. UniformsLib.fog,
  4460. {
  4461. matcap: { value: null }
  4462. }
  4463. ] ),
  4464. vertexShader: ShaderChunk.meshmatcap_vert,
  4465. fragmentShader: ShaderChunk.meshmatcap_frag
  4466. },
  4467. points: {
  4468. uniforms: mergeUniforms( [
  4469. UniformsLib.points,
  4470. UniformsLib.fog
  4471. ] ),
  4472. vertexShader: ShaderChunk.points_vert,
  4473. fragmentShader: ShaderChunk.points_frag
  4474. },
  4475. dashed: {
  4476. uniforms: mergeUniforms( [
  4477. UniformsLib.common,
  4478. UniformsLib.fog,
  4479. {
  4480. scale: { value: 1 },
  4481. dashSize: { value: 1 },
  4482. totalSize: { value: 2 }
  4483. }
  4484. ] ),
  4485. vertexShader: ShaderChunk.linedashed_vert,
  4486. fragmentShader: ShaderChunk.linedashed_frag
  4487. },
  4488. depth: {
  4489. uniforms: mergeUniforms( [
  4490. UniformsLib.common,
  4491. UniformsLib.displacementmap
  4492. ] ),
  4493. vertexShader: ShaderChunk.depth_vert,
  4494. fragmentShader: ShaderChunk.depth_frag
  4495. },
  4496. normal: {
  4497. uniforms: mergeUniforms( [
  4498. UniformsLib.common,
  4499. UniformsLib.bumpmap,
  4500. UniformsLib.normalmap,
  4501. UniformsLib.displacementmap,
  4502. {
  4503. opacity: { value: 1.0 }
  4504. }
  4505. ] ),
  4506. vertexShader: ShaderChunk.normal_vert,
  4507. fragmentShader: ShaderChunk.normal_frag
  4508. },
  4509. sprite: {
  4510. uniforms: mergeUniforms( [
  4511. UniformsLib.sprite,
  4512. UniformsLib.fog
  4513. ] ),
  4514. vertexShader: ShaderChunk.sprite_vert,
  4515. fragmentShader: ShaderChunk.sprite_frag
  4516. },
  4517. background: {
  4518. uniforms: {
  4519. uvTransform: { value: new Matrix3() },
  4520. t2D: { value: null },
  4521. },
  4522. vertexShader: ShaderChunk.background_vert,
  4523. fragmentShader: ShaderChunk.background_frag
  4524. },
  4525. /* -------------------------------------------------------------------------
  4526. // Cube map shader
  4527. ------------------------------------------------------------------------- */
  4528. cube: {
  4529. uniforms: {
  4530. tCube: { value: null },
  4531. tFlip: { value: - 1 },
  4532. opacity: { value: 1.0 }
  4533. },
  4534. vertexShader: ShaderChunk.cube_vert,
  4535. fragmentShader: ShaderChunk.cube_frag
  4536. },
  4537. equirect: {
  4538. uniforms: {
  4539. tEquirect: { value: null },
  4540. },
  4541. vertexShader: ShaderChunk.equirect_vert,
  4542. fragmentShader: ShaderChunk.equirect_frag
  4543. },
  4544. distanceRGBA: {
  4545. uniforms: mergeUniforms( [
  4546. UniformsLib.common,
  4547. UniformsLib.displacementmap,
  4548. {
  4549. referencePosition: { value: new Vector3() },
  4550. nearDistance: { value: 1 },
  4551. farDistance: { value: 1000 }
  4552. }
  4553. ] ),
  4554. vertexShader: ShaderChunk.distanceRGBA_vert,
  4555. fragmentShader: ShaderChunk.distanceRGBA_frag
  4556. },
  4557. shadow: {
  4558. uniforms: mergeUniforms( [
  4559. UniformsLib.lights,
  4560. UniformsLib.fog,
  4561. {
  4562. color: { value: new Color( 0x00000 ) },
  4563. opacity: { value: 1.0 }
  4564. },
  4565. ] ),
  4566. vertexShader: ShaderChunk.shadow_vert,
  4567. fragmentShader: ShaderChunk.shadow_frag
  4568. }
  4569. };
  4570. ShaderLib.physical = {
  4571. uniforms: mergeUniforms( [
  4572. ShaderLib.standard.uniforms,
  4573. {
  4574. clearCoat: { value: 0 },
  4575. clearCoatRoughness: { value: 0 }
  4576. }
  4577. ] ),
  4578. vertexShader: ShaderChunk.meshphysical_vert,
  4579. fragmentShader: ShaderChunk.meshphysical_frag
  4580. };
  4581. /**
  4582. * @author mrdoob / http://mrdoob.com/
  4583. */
  4584. function WebGLAnimation() {
  4585. var context = null;
  4586. var isAnimating = false;
  4587. var animationLoop = null;
  4588. function onAnimationFrame( time, frame ) {
  4589. if ( isAnimating === false ) return;
  4590. animationLoop( time, frame );
  4591. context.requestAnimationFrame( onAnimationFrame );
  4592. }
  4593. return {
  4594. start: function () {
  4595. if ( isAnimating === true ) return;
  4596. if ( animationLoop === null ) return;
  4597. context.requestAnimationFrame( onAnimationFrame );
  4598. isAnimating = true;
  4599. },
  4600. stop: function () {
  4601. isAnimating = false;
  4602. },
  4603. setAnimationLoop: function ( callback ) {
  4604. animationLoop = callback;
  4605. },
  4606. setContext: function ( value ) {
  4607. context = value;
  4608. }
  4609. };
  4610. }
  4611. /**
  4612. * @author mrdoob / http://mrdoob.com/
  4613. */
  4614. function WebGLAttributes( gl ) {
  4615. var buffers = new WeakMap();
  4616. function createBuffer( attribute, bufferType ) {
  4617. var array = attribute.array;
  4618. var usage = attribute.dynamic ? 35048 : 35044;
  4619. var buffer = gl.createBuffer();
  4620. gl.bindBuffer( bufferType, buffer );
  4621. gl.bufferData( bufferType, array, usage );
  4622. attribute.onUploadCallback();
  4623. var type = 5126;
  4624. if ( array instanceof Float32Array ) {
  4625. type = 5126;
  4626. } else if ( array instanceof Float64Array ) {
  4627. console.warn( 'THREE.WebGLAttributes: Unsupported data buffer format: Float64Array.' );
  4628. } else if ( array instanceof Uint16Array ) {
  4629. type = 5123;
  4630. } else if ( array instanceof Int16Array ) {
  4631. type = 5122;
  4632. } else if ( array instanceof Uint32Array ) {
  4633. type = 5125;
  4634. } else if ( array instanceof Int32Array ) {
  4635. type = 5124;
  4636. } else if ( array instanceof Int8Array ) {
  4637. type = 5120;
  4638. } else if ( array instanceof Uint8Array ) {
  4639. type = 5121;
  4640. }
  4641. return {
  4642. buffer: buffer,
  4643. type: type,
  4644. bytesPerElement: array.BYTES_PER_ELEMENT,
  4645. version: attribute.version
  4646. };
  4647. }
  4648. function updateBuffer( buffer, attribute, bufferType ) {
  4649. var array = attribute.array;
  4650. var updateRange = attribute.updateRange;
  4651. gl.bindBuffer( bufferType, buffer );
  4652. if ( attribute.dynamic === false ) {
  4653. gl.bufferData( bufferType, array, 35044 );
  4654. } else if ( updateRange.count === - 1 ) {
  4655. // Not using update ranges
  4656. gl.bufferSubData( bufferType, 0, array );
  4657. } else if ( updateRange.count === 0 ) {
  4658. 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.' );
  4659. } else {
  4660. gl.bufferSubData( bufferType, updateRange.offset * array.BYTES_PER_ELEMENT,
  4661. array.subarray( updateRange.offset, updateRange.offset + updateRange.count ) );
  4662. updateRange.count = - 1; // reset range
  4663. }
  4664. }
  4665. //
  4666. function get( attribute ) {
  4667. if ( attribute.isInterleavedBufferAttribute ) attribute = attribute.data;
  4668. return buffers.get( attribute );
  4669. }
  4670. function remove( attribute ) {
  4671. if ( attribute.isInterleavedBufferAttribute ) attribute = attribute.data;
  4672. var data = buffers.get( attribute );
  4673. if ( data ) {
  4674. gl.deleteBuffer( data.buffer );
  4675. buffers.delete( attribute );
  4676. }
  4677. }
  4678. function update( attribute, bufferType ) {
  4679. if ( attribute.isInterleavedBufferAttribute ) attribute = attribute.data;
  4680. var data = buffers.get( attribute );
  4681. if ( data === undefined ) {
  4682. buffers.set( attribute, createBuffer( attribute, bufferType ) );
  4683. } else if ( data.version < attribute.version ) {
  4684. updateBuffer( data.buffer, attribute, bufferType );
  4685. data.version = attribute.version;
  4686. }
  4687. }
  4688. return {
  4689. get: get,
  4690. remove: remove,
  4691. update: update
  4692. };
  4693. }
  4694. /**
  4695. * @author mrdoob / http://mrdoob.com/
  4696. * @author alteredq / http://alteredqualia.com/
  4697. */
  4698. function Face3( a, b, c, normal, color, materialIndex ) {
  4699. this.a = a;
  4700. this.b = b;
  4701. this.c = c;
  4702. this.normal = ( normal && normal.isVector3 ) ? normal : new Vector3();
  4703. this.vertexNormals = Array.isArray( normal ) ? normal : [];
  4704. this.color = ( color && color.isColor ) ? color : new Color();
  4705. this.vertexColors = Array.isArray( color ) ? color : [];
  4706. this.materialIndex = materialIndex !== undefined ? materialIndex : 0;
  4707. }
  4708. Object.assign( Face3.prototype, {
  4709. clone: function () {
  4710. return new this.constructor().copy( this );
  4711. },
  4712. copy: function ( source ) {
  4713. this.a = source.a;
  4714. this.b = source.b;
  4715. this.c = source.c;
  4716. this.normal.copy( source.normal );
  4717. this.color.copy( source.color );
  4718. this.materialIndex = source.materialIndex;
  4719. for ( var i = 0, il = source.vertexNormals.length; i < il; i ++ ) {
  4720. this.vertexNormals[ i ] = source.vertexNormals[ i ].clone();
  4721. }
  4722. for ( var i = 0, il = source.vertexColors.length; i < il; i ++ ) {
  4723. this.vertexColors[ i ] = source.vertexColors[ i ].clone();
  4724. }
  4725. return this;
  4726. }
  4727. } );
  4728. /**
  4729. * @author mrdoob / http://mrdoob.com/
  4730. * @author WestLangley / http://github.com/WestLangley
  4731. * @author bhouston / http://clara.io
  4732. */
  4733. function Euler( x, y, z, order ) {
  4734. this._x = x || 0;
  4735. this._y = y || 0;
  4736. this._z = z || 0;
  4737. this._order = order || Euler.DefaultOrder;
  4738. }
  4739. Euler.RotationOrders = [ 'XYZ', 'YZX', 'ZXY', 'XZY', 'YXZ', 'ZYX' ];
  4740. Euler.DefaultOrder = 'XYZ';
  4741. Object.defineProperties( Euler.prototype, {
  4742. x: {
  4743. get: function () {
  4744. return this._x;
  4745. },
  4746. set: function ( value ) {
  4747. this._x = value;
  4748. this.onChangeCallback();
  4749. }
  4750. },
  4751. y: {
  4752. get: function () {
  4753. return this._y;
  4754. },
  4755. set: function ( value ) {
  4756. this._y = value;
  4757. this.onChangeCallback();
  4758. }
  4759. },
  4760. z: {
  4761. get: function () {
  4762. return this._z;
  4763. },
  4764. set: function ( value ) {
  4765. this._z = value;
  4766. this.onChangeCallback();
  4767. }
  4768. },
  4769. order: {
  4770. get: function () {
  4771. return this._order;
  4772. },
  4773. set: function ( value ) {
  4774. this._order = value;
  4775. this.onChangeCallback();
  4776. }
  4777. }
  4778. } );
  4779. Object.assign( Euler.prototype, {
  4780. isEuler: true,
  4781. set: function ( x, y, z, order ) {
  4782. this._x = x;
  4783. this._y = y;
  4784. this._z = z;
  4785. this._order = order || this._order;
  4786. this.onChangeCallback();
  4787. return this;
  4788. },
  4789. clone: function () {
  4790. return new this.constructor( this._x, this._y, this._z, this._order );
  4791. },
  4792. copy: function ( euler ) {
  4793. this._x = euler._x;
  4794. this._y = euler._y;
  4795. this._z = euler._z;
  4796. this._order = euler._order;
  4797. this.onChangeCallback();
  4798. return this;
  4799. },
  4800. setFromRotationMatrix: function ( m, order, update ) {
  4801. var clamp = _Math.clamp;
  4802. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  4803. var te = m.elements;
  4804. var m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ];
  4805. var m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ];
  4806. var m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ];
  4807. order = order || this._order;
  4808. if ( order === 'XYZ' ) {
  4809. this._y = Math.asin( clamp( m13, - 1, 1 ) );
  4810. if ( Math.abs( m13 ) < 0.99999 ) {
  4811. this._x = Math.atan2( - m23, m33 );
  4812. this._z = Math.atan2( - m12, m11 );
  4813. } else {
  4814. this._x = Math.atan2( m32, m22 );
  4815. this._z = 0;
  4816. }
  4817. } else if ( order === 'YXZ' ) {
  4818. this._x = Math.asin( - clamp( m23, - 1, 1 ) );
  4819. if ( Math.abs( m23 ) < 0.99999 ) {
  4820. this._y = Math.atan2( m13, m33 );
  4821. this._z = Math.atan2( m21, m22 );
  4822. } else {
  4823. this._y = Math.atan2( - m31, m11 );
  4824. this._z = 0;
  4825. }
  4826. } else if ( order === 'ZXY' ) {
  4827. this._x = Math.asin( clamp( m32, - 1, 1 ) );
  4828. if ( Math.abs( m32 ) < 0.99999 ) {
  4829. this._y = Math.atan2( - m31, m33 );
  4830. this._z = Math.atan2( - m12, m22 );
  4831. } else {
  4832. this._y = 0;
  4833. this._z = Math.atan2( m21, m11 );
  4834. }
  4835. } else if ( order === 'ZYX' ) {
  4836. this._y = Math.asin( - clamp( m31, - 1, 1 ) );
  4837. if ( Math.abs( m31 ) < 0.99999 ) {
  4838. this._x = Math.atan2( m32, m33 );
  4839. this._z = Math.atan2( m21, m11 );
  4840. } else {
  4841. this._x = 0;
  4842. this._z = Math.atan2( - m12, m22 );
  4843. }
  4844. } else if ( order === 'YZX' ) {
  4845. this._z = Math.asin( clamp( m21, - 1, 1 ) );
  4846. if ( Math.abs( m21 ) < 0.99999 ) {
  4847. this._x = Math.atan2( - m23, m22 );
  4848. this._y = Math.atan2( - m31, m11 );
  4849. } else {
  4850. this._x = 0;
  4851. this._y = Math.atan2( m13, m33 );
  4852. }
  4853. } else if ( order === 'XZY' ) {
  4854. this._z = Math.asin( - clamp( m12, - 1, 1 ) );
  4855. if ( Math.abs( m12 ) < 0.99999 ) {
  4856. this._x = Math.atan2( m32, m22 );
  4857. this._y = Math.atan2( m13, m11 );
  4858. } else {
  4859. this._x = Math.atan2( - m23, m33 );
  4860. this._y = 0;
  4861. }
  4862. } else {
  4863. console.warn( 'THREE.Euler: .setFromRotationMatrix() given unsupported order: ' + order );
  4864. }
  4865. this._order = order;
  4866. if ( update !== false ) this.onChangeCallback();
  4867. return this;
  4868. },
  4869. setFromQuaternion: function () {
  4870. var matrix = new Matrix4();
  4871. return function setFromQuaternion( q, order, update ) {
  4872. matrix.makeRotationFromQuaternion( q );
  4873. return this.setFromRotationMatrix( matrix, order, update );
  4874. };
  4875. }(),
  4876. setFromVector3: function ( v, order ) {
  4877. return this.set( v.x, v.y, v.z, order || this._order );
  4878. },
  4879. reorder: function () {
  4880. // WARNING: this discards revolution information -bhouston
  4881. var q = new Quaternion();
  4882. return function reorder( newOrder ) {
  4883. q.setFromEuler( this );
  4884. return this.setFromQuaternion( q, newOrder );
  4885. };
  4886. }(),
  4887. equals: function ( euler ) {
  4888. return ( euler._x === this._x ) && ( euler._y === this._y ) && ( euler._z === this._z ) && ( euler._order === this._order );
  4889. },
  4890. fromArray: function ( array ) {
  4891. this._x = array[ 0 ];
  4892. this._y = array[ 1 ];
  4893. this._z = array[ 2 ];
  4894. if ( array[ 3 ] !== undefined ) this._order = array[ 3 ];
  4895. this.onChangeCallback();
  4896. return this;
  4897. },
  4898. toArray: function ( array, offset ) {
  4899. if ( array === undefined ) array = [];
  4900. if ( offset === undefined ) offset = 0;
  4901. array[ offset ] = this._x;
  4902. array[ offset + 1 ] = this._y;
  4903. array[ offset + 2 ] = this._z;
  4904. array[ offset + 3 ] = this._order;
  4905. return array;
  4906. },
  4907. toVector3: function ( optionalResult ) {
  4908. if ( optionalResult ) {
  4909. return optionalResult.set( this._x, this._y, this._z );
  4910. } else {
  4911. return new Vector3( this._x, this._y, this._z );
  4912. }
  4913. },
  4914. onChange: function ( callback ) {
  4915. this.onChangeCallback = callback;
  4916. return this;
  4917. },
  4918. onChangeCallback: function () {}
  4919. } );
  4920. /**
  4921. * @author mrdoob / http://mrdoob.com/
  4922. */
  4923. function Layers() {
  4924. this.mask = 1 | 0;
  4925. }
  4926. Object.assign( Layers.prototype, {
  4927. set: function ( channel ) {
  4928. this.mask = 1 << channel | 0;
  4929. },
  4930. enable: function ( channel ) {
  4931. this.mask |= 1 << channel | 0;
  4932. },
  4933. toggle: function ( channel ) {
  4934. this.mask ^= 1 << channel | 0;
  4935. },
  4936. disable: function ( channel ) {
  4937. this.mask &= ~ ( 1 << channel | 0 );
  4938. },
  4939. test: function ( layers ) {
  4940. return ( this.mask & layers.mask ) !== 0;
  4941. }
  4942. } );
  4943. /**
  4944. * @author mrdoob / http://mrdoob.com/
  4945. * @author mikael emtinger / http://gomo.se/
  4946. * @author alteredq / http://alteredqualia.com/
  4947. * @author WestLangley / http://github.com/WestLangley
  4948. * @author elephantatwork / www.elephantatwork.ch
  4949. */
  4950. var object3DId = 0;
  4951. function Object3D() {
  4952. Object.defineProperty( this, 'id', { value: object3DId ++ } );
  4953. this.uuid = _Math.generateUUID();
  4954. this.name = '';
  4955. this.type = 'Object3D';
  4956. this.parent = null;
  4957. this.children = [];
  4958. this.up = Object3D.DefaultUp.clone();
  4959. var position = new Vector3();
  4960. var rotation = new Euler();
  4961. var quaternion = new Quaternion();
  4962. var scale = new Vector3( 1, 1, 1 );
  4963. function onRotationChange() {
  4964. quaternion.setFromEuler( rotation, false );
  4965. }
  4966. function onQuaternionChange() {
  4967. rotation.setFromQuaternion( quaternion, undefined, false );
  4968. }
  4969. rotation.onChange( onRotationChange );
  4970. quaternion.onChange( onQuaternionChange );
  4971. Object.defineProperties( this, {
  4972. position: {
  4973. configurable: true,
  4974. enumerable: true,
  4975. value: position
  4976. },
  4977. rotation: {
  4978. configurable: true,
  4979. enumerable: true,
  4980. value: rotation
  4981. },
  4982. quaternion: {
  4983. configurable: true,
  4984. enumerable: true,
  4985. value: quaternion
  4986. },
  4987. scale: {
  4988. configurable: true,
  4989. enumerable: true,
  4990. value: scale
  4991. },
  4992. modelViewMatrix: {
  4993. value: new Matrix4()
  4994. },
  4995. normalMatrix: {
  4996. value: new Matrix3()
  4997. }
  4998. } );
  4999. this.matrix = new Matrix4();
  5000. this.matrixWorld = new Matrix4();
  5001. this.matrixAutoUpdate = Object3D.DefaultMatrixAutoUpdate;
  5002. this.matrixWorldNeedsUpdate = false;
  5003. this.layers = new Layers();
  5004. this.visible = true;
  5005. this.castShadow = false;
  5006. this.receiveShadow = false;
  5007. this.frustumCulled = true;
  5008. this.renderOrder = 0;
  5009. this.userData = {};
  5010. }
  5011. Object3D.DefaultUp = new Vector3( 0, 1, 0 );
  5012. Object3D.DefaultMatrixAutoUpdate = true;
  5013. Object3D.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  5014. constructor: Object3D,
  5015. isObject3D: true,
  5016. onBeforeRender: function () {},
  5017. onAfterRender: function () {},
  5018. applyMatrix: function ( matrix ) {
  5019. if ( this.matrixAutoUpdate ) this.updateMatrix();
  5020. this.matrix.premultiply( matrix );
  5021. this.matrix.decompose( this.position, this.quaternion, this.scale );
  5022. },
  5023. applyQuaternion: function ( q ) {
  5024. this.quaternion.premultiply( q );
  5025. return this;
  5026. },
  5027. setRotationFromAxisAngle: function ( axis, angle ) {
  5028. // assumes axis is normalized
  5029. this.quaternion.setFromAxisAngle( axis, angle );
  5030. },
  5031. setRotationFromEuler: function ( euler ) {
  5032. this.quaternion.setFromEuler( euler, true );
  5033. },
  5034. setRotationFromMatrix: function ( m ) {
  5035. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  5036. this.quaternion.setFromRotationMatrix( m );
  5037. },
  5038. setRotationFromQuaternion: function ( q ) {
  5039. // assumes q is normalized
  5040. this.quaternion.copy( q );
  5041. },
  5042. rotateOnAxis: function () {
  5043. // rotate object on axis in object space
  5044. // axis is assumed to be normalized
  5045. var q1 = new Quaternion();
  5046. return function rotateOnAxis( axis, angle ) {
  5047. q1.setFromAxisAngle( axis, angle );
  5048. this.quaternion.multiply( q1 );
  5049. return this;
  5050. };
  5051. }(),
  5052. rotateOnWorldAxis: function () {
  5053. // rotate object on axis in world space
  5054. // axis is assumed to be normalized
  5055. // method assumes no rotated parent
  5056. var q1 = new Quaternion();
  5057. return function rotateOnWorldAxis( axis, angle ) {
  5058. q1.setFromAxisAngle( axis, angle );
  5059. this.quaternion.premultiply( q1 );
  5060. return this;
  5061. };
  5062. }(),
  5063. rotateX: function () {
  5064. var v1 = new Vector3( 1, 0, 0 );
  5065. return function rotateX( angle ) {
  5066. return this.rotateOnAxis( v1, angle );
  5067. };
  5068. }(),
  5069. rotateY: function () {
  5070. var v1 = new Vector3( 0, 1, 0 );
  5071. return function rotateY( angle ) {
  5072. return this.rotateOnAxis( v1, angle );
  5073. };
  5074. }(),
  5075. rotateZ: function () {
  5076. var v1 = new Vector3( 0, 0, 1 );
  5077. return function rotateZ( angle ) {
  5078. return this.rotateOnAxis( v1, angle );
  5079. };
  5080. }(),
  5081. translateOnAxis: function () {
  5082. // translate object by distance along axis in object space
  5083. // axis is assumed to be normalized
  5084. var v1 = new Vector3();
  5085. return function translateOnAxis( axis, distance ) {
  5086. v1.copy( axis ).applyQuaternion( this.quaternion );
  5087. this.position.add( v1.multiplyScalar( distance ) );
  5088. return this;
  5089. };
  5090. }(),
  5091. translateX: function () {
  5092. var v1 = new Vector3( 1, 0, 0 );
  5093. return function translateX( distance ) {
  5094. return this.translateOnAxis( v1, distance );
  5095. };
  5096. }(),
  5097. translateY: function () {
  5098. var v1 = new Vector3( 0, 1, 0 );
  5099. return function translateY( distance ) {
  5100. return this.translateOnAxis( v1, distance );
  5101. };
  5102. }(),
  5103. translateZ: function () {
  5104. var v1 = new Vector3( 0, 0, 1 );
  5105. return function translateZ( distance ) {
  5106. return this.translateOnAxis( v1, distance );
  5107. };
  5108. }(),
  5109. localToWorld: function ( vector ) {
  5110. return vector.applyMatrix4( this.matrixWorld );
  5111. },
  5112. worldToLocal: function () {
  5113. var m1 = new Matrix4();
  5114. return function worldToLocal( vector ) {
  5115. return vector.applyMatrix4( m1.getInverse( this.matrixWorld ) );
  5116. };
  5117. }(),
  5118. lookAt: function () {
  5119. // This method does not support objects having non-uniformly-scaled parent(s)
  5120. var q1 = new Quaternion();
  5121. var m1 = new Matrix4();
  5122. var target = new Vector3();
  5123. var position = new Vector3();
  5124. return function lookAt( x, y, z ) {
  5125. if ( x.isVector3 ) {
  5126. target.copy( x );
  5127. } else {
  5128. target.set( x, y, z );
  5129. }
  5130. var parent = this.parent;
  5131. this.updateWorldMatrix( true, false );
  5132. position.setFromMatrixPosition( this.matrixWorld );
  5133. if ( this.isCamera || this.isLight ) {
  5134. m1.lookAt( position, target, this.up );
  5135. } else {
  5136. m1.lookAt( target, position, this.up );
  5137. }
  5138. this.quaternion.setFromRotationMatrix( m1 );
  5139. if ( parent ) {
  5140. m1.extractRotation( parent.matrixWorld );
  5141. q1.setFromRotationMatrix( m1 );
  5142. this.quaternion.premultiply( q1.inverse() );
  5143. }
  5144. };
  5145. }(),
  5146. add: function ( object ) {
  5147. if ( arguments.length > 1 ) {
  5148. for ( var i = 0; i < arguments.length; i ++ ) {
  5149. this.add( arguments[ i ] );
  5150. }
  5151. return this;
  5152. }
  5153. if ( object === this ) {
  5154. console.error( "THREE.Object3D.add: object can't be added as a child of itself.", object );
  5155. return this;
  5156. }
  5157. if ( ( object && object.isObject3D ) ) {
  5158. if ( object.parent !== null ) {
  5159. object.parent.remove( object );
  5160. }
  5161. object.parent = this;
  5162. object.dispatchEvent( { type: 'added' } );
  5163. this.children.push( object );
  5164. } else {
  5165. console.error( "THREE.Object3D.add: object not an instance of THREE.Object3D.", object );
  5166. }
  5167. return this;
  5168. },
  5169. remove: function ( object ) {
  5170. if ( arguments.length > 1 ) {
  5171. for ( var i = 0; i < arguments.length; i ++ ) {
  5172. this.remove( arguments[ i ] );
  5173. }
  5174. return this;
  5175. }
  5176. var index = this.children.indexOf( object );
  5177. if ( index !== - 1 ) {
  5178. object.parent = null;
  5179. object.dispatchEvent( { type: 'removed' } );
  5180. this.children.splice( index, 1 );
  5181. }
  5182. return this;
  5183. },
  5184. getObjectById: function ( id ) {
  5185. return this.getObjectByProperty( 'id', id );
  5186. },
  5187. getObjectByName: function ( name ) {
  5188. return this.getObjectByProperty( 'name', name );
  5189. },
  5190. getObjectByProperty: function ( name, value ) {
  5191. if ( this[ name ] === value ) return this;
  5192. for ( var i = 0, l = this.children.length; i < l; i ++ ) {
  5193. var child = this.children[ i ];
  5194. var object = child.getObjectByProperty( name, value );
  5195. if ( object !== undefined ) {
  5196. return object;
  5197. }
  5198. }
  5199. return undefined;
  5200. },
  5201. getWorldPosition: function ( target ) {
  5202. if ( target === undefined ) {
  5203. console.warn( 'THREE.Object3D: .getWorldPosition() target is now required' );
  5204. target = new Vector3();
  5205. }
  5206. this.updateMatrixWorld( true );
  5207. return target.setFromMatrixPosition( this.matrixWorld );
  5208. },
  5209. getWorldQuaternion: function () {
  5210. var position = new Vector3();
  5211. var scale = new Vector3();
  5212. return function getWorldQuaternion( target ) {
  5213. if ( target === undefined ) {
  5214. console.warn( 'THREE.Object3D: .getWorldQuaternion() target is now required' );
  5215. target = new Quaternion();
  5216. }
  5217. this.updateMatrixWorld( true );
  5218. this.matrixWorld.decompose( position, target, scale );
  5219. return target;
  5220. };
  5221. }(),
  5222. getWorldScale: function () {
  5223. var position = new Vector3();
  5224. var quaternion = new Quaternion();
  5225. return function getWorldScale( target ) {
  5226. if ( target === undefined ) {
  5227. console.warn( 'THREE.Object3D: .getWorldScale() target is now required' );
  5228. target = new Vector3();
  5229. }
  5230. this.updateMatrixWorld( true );
  5231. this.matrixWorld.decompose( position, quaternion, target );
  5232. return target;
  5233. };
  5234. }(),
  5235. getWorldDirection: function ( target ) {
  5236. if ( target === undefined ) {
  5237. console.warn( 'THREE.Object3D: .getWorldDirection() target is now required' );
  5238. target = new Vector3();
  5239. }
  5240. this.updateMatrixWorld( true );
  5241. var e = this.matrixWorld.elements;
  5242. return target.set( e[ 8 ], e[ 9 ], e[ 10 ] ).normalize();
  5243. },
  5244. raycast: function () {},
  5245. traverse: function ( callback ) {
  5246. callback( this );
  5247. var children = this.children;
  5248. for ( var i = 0, l = children.length; i < l; i ++ ) {
  5249. children[ i ].traverse( callback );
  5250. }
  5251. },
  5252. traverseVisible: function ( callback ) {
  5253. if ( this.visible === false ) return;
  5254. callback( this );
  5255. var children = this.children;
  5256. for ( var i = 0, l = children.length; i < l; i ++ ) {
  5257. children[ i ].traverseVisible( callback );
  5258. }
  5259. },
  5260. traverseAncestors: function ( callback ) {
  5261. var parent = this.parent;
  5262. if ( parent !== null ) {
  5263. callback( parent );
  5264. parent.traverseAncestors( callback );
  5265. }
  5266. },
  5267. updateMatrix: function () {
  5268. this.matrix.compose( this.position, this.quaternion, this.scale );
  5269. this.matrixWorldNeedsUpdate = true;
  5270. },
  5271. updateMatrixWorld: function ( force ) {
  5272. if ( this.matrixAutoUpdate ) this.updateMatrix();
  5273. if ( this.matrixWorldNeedsUpdate || force ) {
  5274. if ( this.parent === null ) {
  5275. this.matrixWorld.copy( this.matrix );
  5276. } else {
  5277. this.matrixWorld.multiplyMatrices( this.parent.matrixWorld, this.matrix );
  5278. }
  5279. this.matrixWorldNeedsUpdate = false;
  5280. force = true;
  5281. }
  5282. // update children
  5283. var children = this.children;
  5284. for ( var i = 0, l = children.length; i < l; i ++ ) {
  5285. children[ i ].updateMatrixWorld( force );
  5286. }
  5287. },
  5288. updateWorldMatrix: function ( updateParents, updateChildren ) {
  5289. var parent = this.parent;
  5290. if ( updateParents === true && parent !== null ) {
  5291. parent.updateWorldMatrix( true, false );
  5292. }
  5293. if ( this.matrixAutoUpdate ) this.updateMatrix();
  5294. if ( this.parent === null ) {
  5295. this.matrixWorld.copy( this.matrix );
  5296. } else {
  5297. this.matrixWorld.multiplyMatrices( this.parent.matrixWorld, this.matrix );
  5298. }
  5299. // update children
  5300. if ( updateChildren === true ) {
  5301. var children = this.children;
  5302. for ( var i = 0, l = children.length; i < l; i ++ ) {
  5303. children[ i ].updateWorldMatrix( false, true );
  5304. }
  5305. }
  5306. },
  5307. toJSON: function ( meta ) {
  5308. // meta is a string when called from JSON.stringify
  5309. var isRootObject = ( meta === undefined || typeof meta === 'string' );
  5310. var output = {};
  5311. // meta is a hash used to collect geometries, materials.
  5312. // not providing it implies that this is the root object
  5313. // being serialized.
  5314. if ( isRootObject ) {
  5315. // initialize meta obj
  5316. meta = {
  5317. geometries: {},
  5318. materials: {},
  5319. textures: {},
  5320. images: {},
  5321. shapes: {}
  5322. };
  5323. output.metadata = {
  5324. version: 4.5,
  5325. type: 'Object',
  5326. generator: 'Object3D.toJSON'
  5327. };
  5328. }
  5329. // standard Object3D serialization
  5330. var object = {};
  5331. object.uuid = this.uuid;
  5332. object.type = this.type;
  5333. if ( this.name !== '' ) object.name = this.name;
  5334. if ( this.castShadow === true ) object.castShadow = true;
  5335. if ( this.receiveShadow === true ) object.receiveShadow = true;
  5336. if ( this.visible === false ) object.visible = false;
  5337. if ( this.frustumCulled === false ) object.frustumCulled = false;
  5338. if ( this.renderOrder !== 0 ) object.renderOrder = this.renderOrder;
  5339. if ( JSON.stringify( this.userData ) !== '{}' ) object.userData = this.userData;
  5340. object.layers = this.layers.mask;
  5341. object.matrix = this.matrix.toArray();
  5342. if ( this.matrixAutoUpdate === false ) object.matrixAutoUpdate = false;
  5343. // object specific properties
  5344. if ( this.isMesh && this.drawMode !== TrianglesDrawMode ) object.drawMode = this.drawMode;
  5345. //
  5346. function serialize( library, element ) {
  5347. if ( library[ element.uuid ] === undefined ) {
  5348. library[ element.uuid ] = element.toJSON( meta );
  5349. }
  5350. return element.uuid;
  5351. }
  5352. if ( this.isMesh || this.isLine || this.isPoints ) {
  5353. object.geometry = serialize( meta.geometries, this.geometry );
  5354. var parameters = this.geometry.parameters;
  5355. if ( parameters !== undefined && parameters.shapes !== undefined ) {
  5356. var shapes = parameters.shapes;
  5357. if ( Array.isArray( shapes ) ) {
  5358. for ( var i = 0, l = shapes.length; i < l; i ++ ) {
  5359. var shape = shapes[ i ];
  5360. serialize( meta.shapes, shape );
  5361. }
  5362. } else {
  5363. serialize( meta.shapes, shapes );
  5364. }
  5365. }
  5366. }
  5367. if ( this.material !== undefined ) {
  5368. if ( Array.isArray( this.material ) ) {
  5369. var uuids = [];
  5370. for ( var i = 0, l = this.material.length; i < l; i ++ ) {
  5371. uuids.push( serialize( meta.materials, this.material[ i ] ) );
  5372. }
  5373. object.material = uuids;
  5374. } else {
  5375. object.material = serialize( meta.materials, this.material );
  5376. }
  5377. }
  5378. //
  5379. if ( this.children.length > 0 ) {
  5380. object.children = [];
  5381. for ( var i = 0; i < this.children.length; i ++ ) {
  5382. object.children.push( this.children[ i ].toJSON( meta ).object );
  5383. }
  5384. }
  5385. if ( isRootObject ) {
  5386. var geometries = extractFromCache( meta.geometries );
  5387. var materials = extractFromCache( meta.materials );
  5388. var textures = extractFromCache( meta.textures );
  5389. var images = extractFromCache( meta.images );
  5390. var shapes = extractFromCache( meta.shapes );
  5391. if ( geometries.length > 0 ) output.geometries = geometries;
  5392. if ( materials.length > 0 ) output.materials = materials;
  5393. if ( textures.length > 0 ) output.textures = textures;
  5394. if ( images.length > 0 ) output.images = images;
  5395. if ( shapes.length > 0 ) output.shapes = shapes;
  5396. }
  5397. output.object = object;
  5398. return output;
  5399. // extract data from the cache hash
  5400. // remove metadata on each item
  5401. // and return as array
  5402. function extractFromCache( cache ) {
  5403. var values = [];
  5404. for ( var key in cache ) {
  5405. var data = cache[ key ];
  5406. delete data.metadata;
  5407. values.push( data );
  5408. }
  5409. return values;
  5410. }
  5411. },
  5412. clone: function ( recursive ) {
  5413. return new this.constructor().copy( this, recursive );
  5414. },
  5415. copy: function ( source, recursive ) {
  5416. if ( recursive === undefined ) recursive = true;
  5417. this.name = source.name;
  5418. this.up.copy( source.up );
  5419. this.position.copy( source.position );
  5420. this.quaternion.copy( source.quaternion );
  5421. this.scale.copy( source.scale );
  5422. this.matrix.copy( source.matrix );
  5423. this.matrixWorld.copy( source.matrixWorld );
  5424. this.matrixAutoUpdate = source.matrixAutoUpdate;
  5425. this.matrixWorldNeedsUpdate = source.matrixWorldNeedsUpdate;
  5426. this.layers.mask = source.layers.mask;
  5427. this.visible = source.visible;
  5428. this.castShadow = source.castShadow;
  5429. this.receiveShadow = source.receiveShadow;
  5430. this.frustumCulled = source.frustumCulled;
  5431. this.renderOrder = source.renderOrder;
  5432. this.userData = JSON.parse( JSON.stringify( source.userData ) );
  5433. if ( recursive === true ) {
  5434. for ( var i = 0; i < source.children.length; i ++ ) {
  5435. var child = source.children[ i ];
  5436. this.add( child.clone() );
  5437. }
  5438. }
  5439. return this;
  5440. }
  5441. } );
  5442. /**
  5443. * @author mrdoob / http://mrdoob.com/
  5444. * @author kile / http://kile.stravaganza.org/
  5445. * @author alteredq / http://alteredqualia.com/
  5446. * @author mikael emtinger / http://gomo.se/
  5447. * @author zz85 / http://www.lab4games.net/zz85/blog
  5448. * @author bhouston / http://clara.io
  5449. */
  5450. var geometryId = 0; // Geometry uses even numbers as Id
  5451. function Geometry() {
  5452. Object.defineProperty( this, 'id', { value: geometryId += 2 } );
  5453. this.uuid = _Math.generateUUID();
  5454. this.name = '';
  5455. this.type = 'Geometry';
  5456. this.vertices = [];
  5457. this.colors = [];
  5458. this.faces = [];
  5459. this.faceVertexUvs = [[]];
  5460. this.morphTargets = [];
  5461. this.morphNormals = [];
  5462. this.skinWeights = [];
  5463. this.skinIndices = [];
  5464. this.lineDistances = [];
  5465. this.boundingBox = null;
  5466. this.boundingSphere = null;
  5467. // update flags
  5468. this.elementsNeedUpdate = false;
  5469. this.verticesNeedUpdate = false;
  5470. this.uvsNeedUpdate = false;
  5471. this.normalsNeedUpdate = false;
  5472. this.colorsNeedUpdate = false;
  5473. this.lineDistancesNeedUpdate = false;
  5474. this.groupsNeedUpdate = false;
  5475. }
  5476. Geometry.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  5477. constructor: Geometry,
  5478. isGeometry: true,
  5479. applyMatrix: function ( matrix ) {
  5480. var normalMatrix = new Matrix3().getNormalMatrix( matrix );
  5481. for ( var i = 0, il = this.vertices.length; i < il; i ++ ) {
  5482. var vertex = this.vertices[ i ];
  5483. vertex.applyMatrix4( matrix );
  5484. }
  5485. for ( var i = 0, il = this.faces.length; i < il; i ++ ) {
  5486. var face = this.faces[ i ];
  5487. face.normal.applyMatrix3( normalMatrix ).normalize();
  5488. for ( var j = 0, jl = face.vertexNormals.length; j < jl; j ++ ) {
  5489. face.vertexNormals[ j ].applyMatrix3( normalMatrix ).normalize();
  5490. }
  5491. }
  5492. if ( this.boundingBox !== null ) {
  5493. this.computeBoundingBox();
  5494. }
  5495. if ( this.boundingSphere !== null ) {
  5496. this.computeBoundingSphere();
  5497. }
  5498. this.verticesNeedUpdate = true;
  5499. this.normalsNeedUpdate = true;
  5500. return this;
  5501. },
  5502. rotateX: function () {
  5503. // rotate geometry around world x-axis
  5504. var m1 = new Matrix4();
  5505. return function rotateX( angle ) {
  5506. m1.makeRotationX( angle );
  5507. this.applyMatrix( m1 );
  5508. return this;
  5509. };
  5510. }(),
  5511. rotateY: function () {
  5512. // rotate geometry around world y-axis
  5513. var m1 = new Matrix4();
  5514. return function rotateY( angle ) {
  5515. m1.makeRotationY( angle );
  5516. this.applyMatrix( m1 );
  5517. return this;
  5518. };
  5519. }(),
  5520. rotateZ: function () {
  5521. // rotate geometry around world z-axis
  5522. var m1 = new Matrix4();
  5523. return function rotateZ( angle ) {
  5524. m1.makeRotationZ( angle );
  5525. this.applyMatrix( m1 );
  5526. return this;
  5527. };
  5528. }(),
  5529. translate: function () {
  5530. // translate geometry
  5531. var m1 = new Matrix4();
  5532. return function translate( x, y, z ) {
  5533. m1.makeTranslation( x, y, z );
  5534. this.applyMatrix( m1 );
  5535. return this;
  5536. };
  5537. }(),
  5538. scale: function () {
  5539. // scale geometry
  5540. var m1 = new Matrix4();
  5541. return function scale( x, y, z ) {
  5542. m1.makeScale( x, y, z );
  5543. this.applyMatrix( m1 );
  5544. return this;
  5545. };
  5546. }(),
  5547. lookAt: function () {
  5548. var obj = new Object3D();
  5549. return function lookAt( vector ) {
  5550. obj.lookAt( vector );
  5551. obj.updateMatrix();
  5552. this.applyMatrix( obj.matrix );
  5553. };
  5554. }(),
  5555. fromBufferGeometry: function ( geometry ) {
  5556. var scope = this;
  5557. var indices = geometry.index !== null ? geometry.index.array : undefined;
  5558. var attributes = geometry.attributes;
  5559. var positions = attributes.position.array;
  5560. var normals = attributes.normal !== undefined ? attributes.normal.array : undefined;
  5561. var colors = attributes.color !== undefined ? attributes.color.array : undefined;
  5562. var uvs = attributes.uv !== undefined ? attributes.uv.array : undefined;
  5563. var uvs2 = attributes.uv2 !== undefined ? attributes.uv2.array : undefined;
  5564. if ( uvs2 !== undefined ) this.faceVertexUvs[ 1 ] = [];
  5565. for ( var i = 0, j = 0; i < positions.length; i += 3, j += 2 ) {
  5566. scope.vertices.push( new Vector3().fromArray( positions, i ) );
  5567. if ( colors !== undefined ) {
  5568. scope.colors.push( new Color().fromArray( colors, i ) );
  5569. }
  5570. }
  5571. function addFace( a, b, c, materialIndex ) {
  5572. var vertexColors = ( colors === undefined ) ? [] : [
  5573. scope.colors[ a ].clone(),
  5574. scope.colors[ b ].clone(),
  5575. scope.colors[ c ].clone() ];
  5576. var vertexNormals = ( normals === undefined ) ? [] : [
  5577. new Vector3().fromArray( normals, a * 3 ),
  5578. new Vector3().fromArray( normals, b * 3 ),
  5579. new Vector3().fromArray( normals, c * 3 )
  5580. ];
  5581. var face = new Face3( a, b, c, vertexNormals, vertexColors, materialIndex );
  5582. scope.faces.push( face );
  5583. if ( uvs !== undefined ) {
  5584. scope.faceVertexUvs[ 0 ].push( [
  5585. new Vector2().fromArray( uvs, a * 2 ),
  5586. new Vector2().fromArray( uvs, b * 2 ),
  5587. new Vector2().fromArray( uvs, c * 2 )
  5588. ] );
  5589. }
  5590. if ( uvs2 !== undefined ) {
  5591. scope.faceVertexUvs[ 1 ].push( [
  5592. new Vector2().fromArray( uvs2, a * 2 ),
  5593. new Vector2().fromArray( uvs2, b * 2 ),
  5594. new Vector2().fromArray( uvs2, c * 2 )
  5595. ] );
  5596. }
  5597. }
  5598. var groups = geometry.groups;
  5599. if ( groups.length > 0 ) {
  5600. for ( var i = 0; i < groups.length; i ++ ) {
  5601. var group = groups[ i ];
  5602. var start = group.start;
  5603. var count = group.count;
  5604. for ( var j = start, jl = start + count; j < jl; j += 3 ) {
  5605. if ( indices !== undefined ) {
  5606. addFace( indices[ j ], indices[ j + 1 ], indices[ j + 2 ], group.materialIndex );
  5607. } else {
  5608. addFace( j, j + 1, j + 2, group.materialIndex );
  5609. }
  5610. }
  5611. }
  5612. } else {
  5613. if ( indices !== undefined ) {
  5614. for ( var i = 0; i < indices.length; i += 3 ) {
  5615. addFace( indices[ i ], indices[ i + 1 ], indices[ i + 2 ] );
  5616. }
  5617. } else {
  5618. for ( var i = 0; i < positions.length / 3; i += 3 ) {
  5619. addFace( i, i + 1, i + 2 );
  5620. }
  5621. }
  5622. }
  5623. this.computeFaceNormals();
  5624. if ( geometry.boundingBox !== null ) {
  5625. this.boundingBox = geometry.boundingBox.clone();
  5626. }
  5627. if ( geometry.boundingSphere !== null ) {
  5628. this.boundingSphere = geometry.boundingSphere.clone();
  5629. }
  5630. return this;
  5631. },
  5632. center: function () {
  5633. var offset = new Vector3();
  5634. return function center() {
  5635. this.computeBoundingBox();
  5636. this.boundingBox.getCenter( offset ).negate();
  5637. this.translate( offset.x, offset.y, offset.z );
  5638. return this;
  5639. };
  5640. }(),
  5641. normalize: function () {
  5642. this.computeBoundingSphere();
  5643. var center = this.boundingSphere.center;
  5644. var radius = this.boundingSphere.radius;
  5645. var s = radius === 0 ? 1 : 1.0 / radius;
  5646. var matrix = new Matrix4();
  5647. matrix.set(
  5648. s, 0, 0, - s * center.x,
  5649. 0, s, 0, - s * center.y,
  5650. 0, 0, s, - s * center.z,
  5651. 0, 0, 0, 1
  5652. );
  5653. this.applyMatrix( matrix );
  5654. return this;
  5655. },
  5656. computeFaceNormals: function () {
  5657. var cb = new Vector3(), ab = new Vector3();
  5658. for ( var f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5659. var face = this.faces[ f ];
  5660. var vA = this.vertices[ face.a ];
  5661. var vB = this.vertices[ face.b ];
  5662. var vC = this.vertices[ face.c ];
  5663. cb.subVectors( vC, vB );
  5664. ab.subVectors( vA, vB );
  5665. cb.cross( ab );
  5666. cb.normalize();
  5667. face.normal.copy( cb );
  5668. }
  5669. },
  5670. computeVertexNormals: function ( areaWeighted ) {
  5671. if ( areaWeighted === undefined ) areaWeighted = true;
  5672. var v, vl, f, fl, face, vertices;
  5673. vertices = new Array( this.vertices.length );
  5674. for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) {
  5675. vertices[ v ] = new Vector3();
  5676. }
  5677. if ( areaWeighted ) {
  5678. // vertex normals weighted by triangle areas
  5679. // http://www.iquilezles.org/www/articles/normals/normals.htm
  5680. var vA, vB, vC;
  5681. var cb = new Vector3(), ab = new Vector3();
  5682. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5683. face = this.faces[ f ];
  5684. vA = this.vertices[ face.a ];
  5685. vB = this.vertices[ face.b ];
  5686. vC = this.vertices[ face.c ];
  5687. cb.subVectors( vC, vB );
  5688. ab.subVectors( vA, vB );
  5689. cb.cross( ab );
  5690. vertices[ face.a ].add( cb );
  5691. vertices[ face.b ].add( cb );
  5692. vertices[ face.c ].add( cb );
  5693. }
  5694. } else {
  5695. this.computeFaceNormals();
  5696. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5697. face = this.faces[ f ];
  5698. vertices[ face.a ].add( face.normal );
  5699. vertices[ face.b ].add( face.normal );
  5700. vertices[ face.c ].add( face.normal );
  5701. }
  5702. }
  5703. for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) {
  5704. vertices[ v ].normalize();
  5705. }
  5706. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5707. face = this.faces[ f ];
  5708. var vertexNormals = face.vertexNormals;
  5709. if ( vertexNormals.length === 3 ) {
  5710. vertexNormals[ 0 ].copy( vertices[ face.a ] );
  5711. vertexNormals[ 1 ].copy( vertices[ face.b ] );
  5712. vertexNormals[ 2 ].copy( vertices[ face.c ] );
  5713. } else {
  5714. vertexNormals[ 0 ] = vertices[ face.a ].clone();
  5715. vertexNormals[ 1 ] = vertices[ face.b ].clone();
  5716. vertexNormals[ 2 ] = vertices[ face.c ].clone();
  5717. }
  5718. }
  5719. if ( this.faces.length > 0 ) {
  5720. this.normalsNeedUpdate = true;
  5721. }
  5722. },
  5723. computeFlatVertexNormals: function () {
  5724. var f, fl, face;
  5725. this.computeFaceNormals();
  5726. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5727. face = this.faces[ f ];
  5728. var vertexNormals = face.vertexNormals;
  5729. if ( vertexNormals.length === 3 ) {
  5730. vertexNormals[ 0 ].copy( face.normal );
  5731. vertexNormals[ 1 ].copy( face.normal );
  5732. vertexNormals[ 2 ].copy( face.normal );
  5733. } else {
  5734. vertexNormals[ 0 ] = face.normal.clone();
  5735. vertexNormals[ 1 ] = face.normal.clone();
  5736. vertexNormals[ 2 ] = face.normal.clone();
  5737. }
  5738. }
  5739. if ( this.faces.length > 0 ) {
  5740. this.normalsNeedUpdate = true;
  5741. }
  5742. },
  5743. computeMorphNormals: function () {
  5744. var i, il, f, fl, face;
  5745. // save original normals
  5746. // - create temp variables on first access
  5747. // otherwise just copy (for faster repeated calls)
  5748. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5749. face = this.faces[ f ];
  5750. if ( ! face.__originalFaceNormal ) {
  5751. face.__originalFaceNormal = face.normal.clone();
  5752. } else {
  5753. face.__originalFaceNormal.copy( face.normal );
  5754. }
  5755. if ( ! face.__originalVertexNormals ) face.__originalVertexNormals = [];
  5756. for ( i = 0, il = face.vertexNormals.length; i < il; i ++ ) {
  5757. if ( ! face.__originalVertexNormals[ i ] ) {
  5758. face.__originalVertexNormals[ i ] = face.vertexNormals[ i ].clone();
  5759. } else {
  5760. face.__originalVertexNormals[ i ].copy( face.vertexNormals[ i ] );
  5761. }
  5762. }
  5763. }
  5764. // use temp geometry to compute face and vertex normals for each morph
  5765. var tmpGeo = new Geometry();
  5766. tmpGeo.faces = this.faces;
  5767. for ( i = 0, il = this.morphTargets.length; i < il; i ++ ) {
  5768. // create on first access
  5769. if ( ! this.morphNormals[ i ] ) {
  5770. this.morphNormals[ i ] = {};
  5771. this.morphNormals[ i ].faceNormals = [];
  5772. this.morphNormals[ i ].vertexNormals = [];
  5773. var dstNormalsFace = this.morphNormals[ i ].faceNormals;
  5774. var dstNormalsVertex = this.morphNormals[ i ].vertexNormals;
  5775. var faceNormal, vertexNormals;
  5776. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5777. faceNormal = new Vector3();
  5778. vertexNormals = { a: new Vector3(), b: new Vector3(), c: new Vector3() };
  5779. dstNormalsFace.push( faceNormal );
  5780. dstNormalsVertex.push( vertexNormals );
  5781. }
  5782. }
  5783. var morphNormals = this.morphNormals[ i ];
  5784. // set vertices to morph target
  5785. tmpGeo.vertices = this.morphTargets[ i ].vertices;
  5786. // compute morph normals
  5787. tmpGeo.computeFaceNormals();
  5788. tmpGeo.computeVertexNormals();
  5789. // store morph normals
  5790. var faceNormal, vertexNormals;
  5791. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5792. face = this.faces[ f ];
  5793. faceNormal = morphNormals.faceNormals[ f ];
  5794. vertexNormals = morphNormals.vertexNormals[ f ];
  5795. faceNormal.copy( face.normal );
  5796. vertexNormals.a.copy( face.vertexNormals[ 0 ] );
  5797. vertexNormals.b.copy( face.vertexNormals[ 1 ] );
  5798. vertexNormals.c.copy( face.vertexNormals[ 2 ] );
  5799. }
  5800. }
  5801. // restore original normals
  5802. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5803. face = this.faces[ f ];
  5804. face.normal = face.__originalFaceNormal;
  5805. face.vertexNormals = face.__originalVertexNormals;
  5806. }
  5807. },
  5808. computeBoundingBox: function () {
  5809. if ( this.boundingBox === null ) {
  5810. this.boundingBox = new Box3();
  5811. }
  5812. this.boundingBox.setFromPoints( this.vertices );
  5813. },
  5814. computeBoundingSphere: function () {
  5815. if ( this.boundingSphere === null ) {
  5816. this.boundingSphere = new Sphere();
  5817. }
  5818. this.boundingSphere.setFromPoints( this.vertices );
  5819. },
  5820. merge: function ( geometry, matrix, materialIndexOffset ) {
  5821. if ( ! ( geometry && geometry.isGeometry ) ) {
  5822. console.error( 'THREE.Geometry.merge(): geometry not an instance of THREE.Geometry.', geometry );
  5823. return;
  5824. }
  5825. var normalMatrix,
  5826. vertexOffset = this.vertices.length,
  5827. vertices1 = this.vertices,
  5828. vertices2 = geometry.vertices,
  5829. faces1 = this.faces,
  5830. faces2 = geometry.faces,
  5831. uvs1 = this.faceVertexUvs[ 0 ],
  5832. uvs2 = geometry.faceVertexUvs[ 0 ],
  5833. colors1 = this.colors,
  5834. colors2 = geometry.colors;
  5835. if ( materialIndexOffset === undefined ) materialIndexOffset = 0;
  5836. if ( matrix !== undefined ) {
  5837. normalMatrix = new Matrix3().getNormalMatrix( matrix );
  5838. }
  5839. // vertices
  5840. for ( var i = 0, il = vertices2.length; i < il; i ++ ) {
  5841. var vertex = vertices2[ i ];
  5842. var vertexCopy = vertex.clone();
  5843. if ( matrix !== undefined ) vertexCopy.applyMatrix4( matrix );
  5844. vertices1.push( vertexCopy );
  5845. }
  5846. // colors
  5847. for ( var i = 0, il = colors2.length; i < il; i ++ ) {
  5848. colors1.push( colors2[ i ].clone() );
  5849. }
  5850. // faces
  5851. for ( i = 0, il = faces2.length; i < il; i ++ ) {
  5852. var face = faces2[ i ], faceCopy, normal, color,
  5853. faceVertexNormals = face.vertexNormals,
  5854. faceVertexColors = face.vertexColors;
  5855. faceCopy = new Face3( face.a + vertexOffset, face.b + vertexOffset, face.c + vertexOffset );
  5856. faceCopy.normal.copy( face.normal );
  5857. if ( normalMatrix !== undefined ) {
  5858. faceCopy.normal.applyMatrix3( normalMatrix ).normalize();
  5859. }
  5860. for ( var j = 0, jl = faceVertexNormals.length; j < jl; j ++ ) {
  5861. normal = faceVertexNormals[ j ].clone();
  5862. if ( normalMatrix !== undefined ) {
  5863. normal.applyMatrix3( normalMatrix ).normalize();
  5864. }
  5865. faceCopy.vertexNormals.push( normal );
  5866. }
  5867. faceCopy.color.copy( face.color );
  5868. for ( var j = 0, jl = faceVertexColors.length; j < jl; j ++ ) {
  5869. color = faceVertexColors[ j ];
  5870. faceCopy.vertexColors.push( color.clone() );
  5871. }
  5872. faceCopy.materialIndex = face.materialIndex + materialIndexOffset;
  5873. faces1.push( faceCopy );
  5874. }
  5875. // uvs
  5876. for ( i = 0, il = uvs2.length; i < il; i ++ ) {
  5877. var uv = uvs2[ i ], uvCopy = [];
  5878. if ( uv === undefined ) {
  5879. continue;
  5880. }
  5881. for ( var j = 0, jl = uv.length; j < jl; j ++ ) {
  5882. uvCopy.push( uv[ j ].clone() );
  5883. }
  5884. uvs1.push( uvCopy );
  5885. }
  5886. },
  5887. mergeMesh: function ( mesh ) {
  5888. if ( ! ( mesh && mesh.isMesh ) ) {
  5889. console.error( 'THREE.Geometry.mergeMesh(): mesh not an instance of THREE.Mesh.', mesh );
  5890. return;
  5891. }
  5892. if ( mesh.matrixAutoUpdate ) mesh.updateMatrix();
  5893. this.merge( mesh.geometry, mesh.matrix );
  5894. },
  5895. /*
  5896. * Checks for duplicate vertices with hashmap.
  5897. * Duplicated vertices are removed
  5898. * and faces' vertices are updated.
  5899. */
  5900. mergeVertices: function () {
  5901. var verticesMap = {}; // Hashmap for looking up vertices by position coordinates (and making sure they are unique)
  5902. var unique = [], changes = [];
  5903. var v, key;
  5904. var precisionPoints = 4; // number of decimal points, e.g. 4 for epsilon of 0.0001
  5905. var precision = Math.pow( 10, precisionPoints );
  5906. var i, il, face;
  5907. var indices, j, jl;
  5908. for ( i = 0, il = this.vertices.length; i < il; i ++ ) {
  5909. v = this.vertices[ i ];
  5910. key = Math.round( v.x * precision ) + '_' + Math.round( v.y * precision ) + '_' + Math.round( v.z * precision );
  5911. if ( verticesMap[ key ] === undefined ) {
  5912. verticesMap[ key ] = i;
  5913. unique.push( this.vertices[ i ] );
  5914. changes[ i ] = unique.length - 1;
  5915. } else {
  5916. //console.log('Duplicate vertex found. ', i, ' could be using ', verticesMap[key]);
  5917. changes[ i ] = changes[ verticesMap[ key ] ];
  5918. }
  5919. }
  5920. // if faces are completely degenerate after merging vertices, we
  5921. // have to remove them from the geometry.
  5922. var faceIndicesToRemove = [];
  5923. for ( i = 0, il = this.faces.length; i < il; i ++ ) {
  5924. face = this.faces[ i ];
  5925. face.a = changes[ face.a ];
  5926. face.b = changes[ face.b ];
  5927. face.c = changes[ face.c ];
  5928. indices = [ face.a, face.b, face.c ];
  5929. // if any duplicate vertices are found in a Face3
  5930. // we have to remove the face as nothing can be saved
  5931. for ( var n = 0; n < 3; n ++ ) {
  5932. if ( indices[ n ] === indices[ ( n + 1 ) % 3 ] ) {
  5933. faceIndicesToRemove.push( i );
  5934. break;
  5935. }
  5936. }
  5937. }
  5938. for ( i = faceIndicesToRemove.length - 1; i >= 0; i -- ) {
  5939. var idx = faceIndicesToRemove[ i ];
  5940. this.faces.splice( idx, 1 );
  5941. for ( j = 0, jl = this.faceVertexUvs.length; j < jl; j ++ ) {
  5942. this.faceVertexUvs[ j ].splice( idx, 1 );
  5943. }
  5944. }
  5945. // Use unique set of vertices
  5946. var diff = this.vertices.length - unique.length;
  5947. this.vertices = unique;
  5948. return diff;
  5949. },
  5950. setFromPoints: function ( points ) {
  5951. this.vertices = [];
  5952. for ( var i = 0, l = points.length; i < l; i ++ ) {
  5953. var point = points[ i ];
  5954. this.vertices.push( new Vector3( point.x, point.y, point.z || 0 ) );
  5955. }
  5956. return this;
  5957. },
  5958. sortFacesByMaterialIndex: function () {
  5959. var faces = this.faces;
  5960. var length = faces.length;
  5961. // tag faces
  5962. for ( var i = 0; i < length; i ++ ) {
  5963. faces[ i ]._id = i;
  5964. }
  5965. // sort faces
  5966. function materialIndexSort( a, b ) {
  5967. return a.materialIndex - b.materialIndex;
  5968. }
  5969. faces.sort( materialIndexSort );
  5970. // sort uvs
  5971. var uvs1 = this.faceVertexUvs[ 0 ];
  5972. var uvs2 = this.faceVertexUvs[ 1 ];
  5973. var newUvs1, newUvs2;
  5974. if ( uvs1 && uvs1.length === length ) newUvs1 = [];
  5975. if ( uvs2 && uvs2.length === length ) newUvs2 = [];
  5976. for ( var i = 0; i < length; i ++ ) {
  5977. var id = faces[ i ]._id;
  5978. if ( newUvs1 ) newUvs1.push( uvs1[ id ] );
  5979. if ( newUvs2 ) newUvs2.push( uvs2[ id ] );
  5980. }
  5981. if ( newUvs1 ) this.faceVertexUvs[ 0 ] = newUvs1;
  5982. if ( newUvs2 ) this.faceVertexUvs[ 1 ] = newUvs2;
  5983. },
  5984. toJSON: function () {
  5985. var data = {
  5986. metadata: {
  5987. version: 4.5,
  5988. type: 'Geometry',
  5989. generator: 'Geometry.toJSON'
  5990. }
  5991. };
  5992. // standard Geometry serialization
  5993. data.uuid = this.uuid;
  5994. data.type = this.type;
  5995. if ( this.name !== '' ) data.name = this.name;
  5996. if ( this.parameters !== undefined ) {
  5997. var parameters = this.parameters;
  5998. for ( var key in parameters ) {
  5999. if ( parameters[ key ] !== undefined ) data[ key ] = parameters[ key ];
  6000. }
  6001. return data;
  6002. }
  6003. var vertices = [];
  6004. for ( var i = 0; i < this.vertices.length; i ++ ) {
  6005. var vertex = this.vertices[ i ];
  6006. vertices.push( vertex.x, vertex.y, vertex.z );
  6007. }
  6008. var faces = [];
  6009. var normals = [];
  6010. var normalsHash = {};
  6011. var colors = [];
  6012. var colorsHash = {};
  6013. var uvs = [];
  6014. var uvsHash = {};
  6015. for ( var i = 0; i < this.faces.length; i ++ ) {
  6016. var face = this.faces[ i ];
  6017. var hasMaterial = true;
  6018. var hasFaceUv = false; // deprecated
  6019. var hasFaceVertexUv = this.faceVertexUvs[ 0 ][ i ] !== undefined;
  6020. var hasFaceNormal = face.normal.length() > 0;
  6021. var hasFaceVertexNormal = face.vertexNormals.length > 0;
  6022. var hasFaceColor = face.color.r !== 1 || face.color.g !== 1 || face.color.b !== 1;
  6023. var hasFaceVertexColor = face.vertexColors.length > 0;
  6024. var faceType = 0;
  6025. faceType = setBit( faceType, 0, 0 ); // isQuad
  6026. faceType = setBit( faceType, 1, hasMaterial );
  6027. faceType = setBit( faceType, 2, hasFaceUv );
  6028. faceType = setBit( faceType, 3, hasFaceVertexUv );
  6029. faceType = setBit( faceType, 4, hasFaceNormal );
  6030. faceType = setBit( faceType, 5, hasFaceVertexNormal );
  6031. faceType = setBit( faceType, 6, hasFaceColor );
  6032. faceType = setBit( faceType, 7, hasFaceVertexColor );
  6033. faces.push( faceType );
  6034. faces.push( face.a, face.b, face.c );
  6035. faces.push( face.materialIndex );
  6036. if ( hasFaceVertexUv ) {
  6037. var faceVertexUvs = this.faceVertexUvs[ 0 ][ i ];
  6038. faces.push(
  6039. getUvIndex( faceVertexUvs[ 0 ] ),
  6040. getUvIndex( faceVertexUvs[ 1 ] ),
  6041. getUvIndex( faceVertexUvs[ 2 ] )
  6042. );
  6043. }
  6044. if ( hasFaceNormal ) {
  6045. faces.push( getNormalIndex( face.normal ) );
  6046. }
  6047. if ( hasFaceVertexNormal ) {
  6048. var vertexNormals = face.vertexNormals;
  6049. faces.push(
  6050. getNormalIndex( vertexNormals[ 0 ] ),
  6051. getNormalIndex( vertexNormals[ 1 ] ),
  6052. getNormalIndex( vertexNormals[ 2 ] )
  6053. );
  6054. }
  6055. if ( hasFaceColor ) {
  6056. faces.push( getColorIndex( face.color ) );
  6057. }
  6058. if ( hasFaceVertexColor ) {
  6059. var vertexColors = face.vertexColors;
  6060. faces.push(
  6061. getColorIndex( vertexColors[ 0 ] ),
  6062. getColorIndex( vertexColors[ 1 ] ),
  6063. getColorIndex( vertexColors[ 2 ] )
  6064. );
  6065. }
  6066. }
  6067. function setBit( value, position, enabled ) {
  6068. return enabled ? value | ( 1 << position ) : value & ( ~ ( 1 << position ) );
  6069. }
  6070. function getNormalIndex( normal ) {
  6071. var hash = normal.x.toString() + normal.y.toString() + normal.z.toString();
  6072. if ( normalsHash[ hash ] !== undefined ) {
  6073. return normalsHash[ hash ];
  6074. }
  6075. normalsHash[ hash ] = normals.length / 3;
  6076. normals.push( normal.x, normal.y, normal.z );
  6077. return normalsHash[ hash ];
  6078. }
  6079. function getColorIndex( color ) {
  6080. var hash = color.r.toString() + color.g.toString() + color.b.toString();
  6081. if ( colorsHash[ hash ] !== undefined ) {
  6082. return colorsHash[ hash ];
  6083. }
  6084. colorsHash[ hash ] = colors.length;
  6085. colors.push( color.getHex() );
  6086. return colorsHash[ hash ];
  6087. }
  6088. function getUvIndex( uv ) {
  6089. var hash = uv.x.toString() + uv.y.toString();
  6090. if ( uvsHash[ hash ] !== undefined ) {
  6091. return uvsHash[ hash ];
  6092. }
  6093. uvsHash[ hash ] = uvs.length / 2;
  6094. uvs.push( uv.x, uv.y );
  6095. return uvsHash[ hash ];
  6096. }
  6097. data.data = {};
  6098. data.data.vertices = vertices;
  6099. data.data.normals = normals;
  6100. if ( colors.length > 0 ) data.data.colors = colors;
  6101. if ( uvs.length > 0 ) data.data.uvs = [ uvs ]; // temporal backward compatibility
  6102. data.data.faces = faces;
  6103. return data;
  6104. },
  6105. clone: function () {
  6106. /*
  6107. // Handle primitives
  6108. var parameters = this.parameters;
  6109. if ( parameters !== undefined ) {
  6110. var values = [];
  6111. for ( var key in parameters ) {
  6112. values.push( parameters[ key ] );
  6113. }
  6114. var geometry = Object.create( this.constructor.prototype );
  6115. this.constructor.apply( geometry, values );
  6116. return geometry;
  6117. }
  6118. return new this.constructor().copy( this );
  6119. */
  6120. return new Geometry().copy( this );
  6121. },
  6122. copy: function ( source ) {
  6123. var i, il, j, jl, k, kl;
  6124. // reset
  6125. this.vertices = [];
  6126. this.colors = [];
  6127. this.faces = [];
  6128. this.faceVertexUvs = [[]];
  6129. this.morphTargets = [];
  6130. this.morphNormals = [];
  6131. this.skinWeights = [];
  6132. this.skinIndices = [];
  6133. this.lineDistances = [];
  6134. this.boundingBox = null;
  6135. this.boundingSphere = null;
  6136. // name
  6137. this.name = source.name;
  6138. // vertices
  6139. var vertices = source.vertices;
  6140. for ( i = 0, il = vertices.length; i < il; i ++ ) {
  6141. this.vertices.push( vertices[ i ].clone() );
  6142. }
  6143. // colors
  6144. var colors = source.colors;
  6145. for ( i = 0, il = colors.length; i < il; i ++ ) {
  6146. this.colors.push( colors[ i ].clone() );
  6147. }
  6148. // faces
  6149. var faces = source.faces;
  6150. for ( i = 0, il = faces.length; i < il; i ++ ) {
  6151. this.faces.push( faces[ i ].clone() );
  6152. }
  6153. // face vertex uvs
  6154. for ( i = 0, il = source.faceVertexUvs.length; i < il; i ++ ) {
  6155. var faceVertexUvs = source.faceVertexUvs[ i ];
  6156. if ( this.faceVertexUvs[ i ] === undefined ) {
  6157. this.faceVertexUvs[ i ] = [];
  6158. }
  6159. for ( j = 0, jl = faceVertexUvs.length; j < jl; j ++ ) {
  6160. var uvs = faceVertexUvs[ j ], uvsCopy = [];
  6161. for ( k = 0, kl = uvs.length; k < kl; k ++ ) {
  6162. var uv = uvs[ k ];
  6163. uvsCopy.push( uv.clone() );
  6164. }
  6165. this.faceVertexUvs[ i ].push( uvsCopy );
  6166. }
  6167. }
  6168. // morph targets
  6169. var morphTargets = source.morphTargets;
  6170. for ( i = 0, il = morphTargets.length; i < il; i ++ ) {
  6171. var morphTarget = {};
  6172. morphTarget.name = morphTargets[ i ].name;
  6173. // vertices
  6174. if ( morphTargets[ i ].vertices !== undefined ) {
  6175. morphTarget.vertices = [];
  6176. for ( j = 0, jl = morphTargets[ i ].vertices.length; j < jl; j ++ ) {
  6177. morphTarget.vertices.push( morphTargets[ i ].vertices[ j ].clone() );
  6178. }
  6179. }
  6180. // normals
  6181. if ( morphTargets[ i ].normals !== undefined ) {
  6182. morphTarget.normals = [];
  6183. for ( j = 0, jl = morphTargets[ i ].normals.length; j < jl; j ++ ) {
  6184. morphTarget.normals.push( morphTargets[ i ].normals[ j ].clone() );
  6185. }
  6186. }
  6187. this.morphTargets.push( morphTarget );
  6188. }
  6189. // morph normals
  6190. var morphNormals = source.morphNormals;
  6191. for ( i = 0, il = morphNormals.length; i < il; i ++ ) {
  6192. var morphNormal = {};
  6193. // vertex normals
  6194. if ( morphNormals[ i ].vertexNormals !== undefined ) {
  6195. morphNormal.vertexNormals = [];
  6196. for ( j = 0, jl = morphNormals[ i ].vertexNormals.length; j < jl; j ++ ) {
  6197. var srcVertexNormal = morphNormals[ i ].vertexNormals[ j ];
  6198. var destVertexNormal = {};
  6199. destVertexNormal.a = srcVertexNormal.a.clone();
  6200. destVertexNormal.b = srcVertexNormal.b.clone();
  6201. destVertexNormal.c = srcVertexNormal.c.clone();
  6202. morphNormal.vertexNormals.push( destVertexNormal );
  6203. }
  6204. }
  6205. // face normals
  6206. if ( morphNormals[ i ].faceNormals !== undefined ) {
  6207. morphNormal.faceNormals = [];
  6208. for ( j = 0, jl = morphNormals[ i ].faceNormals.length; j < jl; j ++ ) {
  6209. morphNormal.faceNormals.push( morphNormals[ i ].faceNormals[ j ].clone() );
  6210. }
  6211. }
  6212. this.morphNormals.push( morphNormal );
  6213. }
  6214. // skin weights
  6215. var skinWeights = source.skinWeights;
  6216. for ( i = 0, il = skinWeights.length; i < il; i ++ ) {
  6217. this.skinWeights.push( skinWeights[ i ].clone() );
  6218. }
  6219. // skin indices
  6220. var skinIndices = source.skinIndices;
  6221. for ( i = 0, il = skinIndices.length; i < il; i ++ ) {
  6222. this.skinIndices.push( skinIndices[ i ].clone() );
  6223. }
  6224. // line distances
  6225. var lineDistances = source.lineDistances;
  6226. for ( i = 0, il = lineDistances.length; i < il; i ++ ) {
  6227. this.lineDistances.push( lineDistances[ i ] );
  6228. }
  6229. // bounding box
  6230. var boundingBox = source.boundingBox;
  6231. if ( boundingBox !== null ) {
  6232. this.boundingBox = boundingBox.clone();
  6233. }
  6234. // bounding sphere
  6235. var boundingSphere = source.boundingSphere;
  6236. if ( boundingSphere !== null ) {
  6237. this.boundingSphere = boundingSphere.clone();
  6238. }
  6239. // update flags
  6240. this.elementsNeedUpdate = source.elementsNeedUpdate;
  6241. this.verticesNeedUpdate = source.verticesNeedUpdate;
  6242. this.uvsNeedUpdate = source.uvsNeedUpdate;
  6243. this.normalsNeedUpdate = source.normalsNeedUpdate;
  6244. this.colorsNeedUpdate = source.colorsNeedUpdate;
  6245. this.lineDistancesNeedUpdate = source.lineDistancesNeedUpdate;
  6246. this.groupsNeedUpdate = source.groupsNeedUpdate;
  6247. return this;
  6248. },
  6249. dispose: function () {
  6250. this.dispatchEvent( { type: 'dispose' } );
  6251. }
  6252. } );
  6253. /**
  6254. * @author mrdoob / http://mrdoob.com/
  6255. */
  6256. function BufferAttribute( array, itemSize, normalized ) {
  6257. if ( Array.isArray( array ) ) {
  6258. throw new TypeError( 'THREE.BufferAttribute: array should be a Typed Array.' );
  6259. }
  6260. this.name = '';
  6261. this.array = array;
  6262. this.itemSize = itemSize;
  6263. this.count = array !== undefined ? array.length / itemSize : 0;
  6264. this.normalized = normalized === true;
  6265. this.dynamic = false;
  6266. this.updateRange = { offset: 0, count: - 1 };
  6267. this.version = 0;
  6268. }
  6269. Object.defineProperty( BufferAttribute.prototype, 'needsUpdate', {
  6270. set: function ( value ) {
  6271. if ( value === true ) this.version ++;
  6272. }
  6273. } );
  6274. Object.assign( BufferAttribute.prototype, {
  6275. isBufferAttribute: true,
  6276. onUploadCallback: function () {},
  6277. setArray: function ( array ) {
  6278. if ( Array.isArray( array ) ) {
  6279. throw new TypeError( 'THREE.BufferAttribute: array should be a Typed Array.' );
  6280. }
  6281. this.count = array !== undefined ? array.length / this.itemSize : 0;
  6282. this.array = array;
  6283. return this;
  6284. },
  6285. setDynamic: function ( value ) {
  6286. this.dynamic = value;
  6287. return this;
  6288. },
  6289. copy: function ( source ) {
  6290. this.name = source.name;
  6291. this.array = new source.array.constructor( source.array );
  6292. this.itemSize = source.itemSize;
  6293. this.count = source.count;
  6294. this.normalized = source.normalized;
  6295. this.dynamic = source.dynamic;
  6296. return this;
  6297. },
  6298. copyAt: function ( index1, attribute, index2 ) {
  6299. index1 *= this.itemSize;
  6300. index2 *= attribute.itemSize;
  6301. for ( var i = 0, l = this.itemSize; i < l; i ++ ) {
  6302. this.array[ index1 + i ] = attribute.array[ index2 + i ];
  6303. }
  6304. return this;
  6305. },
  6306. copyArray: function ( array ) {
  6307. this.array.set( array );
  6308. return this;
  6309. },
  6310. copyColorsArray: function ( colors ) {
  6311. var array = this.array, offset = 0;
  6312. for ( var i = 0, l = colors.length; i < l; i ++ ) {
  6313. var color = colors[ i ];
  6314. if ( color === undefined ) {
  6315. console.warn( 'THREE.BufferAttribute.copyColorsArray(): color is undefined', i );
  6316. color = new Color();
  6317. }
  6318. array[ offset ++ ] = color.r;
  6319. array[ offset ++ ] = color.g;
  6320. array[ offset ++ ] = color.b;
  6321. }
  6322. return this;
  6323. },
  6324. copyVector2sArray: function ( vectors ) {
  6325. var array = this.array, offset = 0;
  6326. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  6327. var vector = vectors[ i ];
  6328. if ( vector === undefined ) {
  6329. console.warn( 'THREE.BufferAttribute.copyVector2sArray(): vector is undefined', i );
  6330. vector = new Vector2();
  6331. }
  6332. array[ offset ++ ] = vector.x;
  6333. array[ offset ++ ] = vector.y;
  6334. }
  6335. return this;
  6336. },
  6337. copyVector3sArray: function ( vectors ) {
  6338. var array = this.array, offset = 0;
  6339. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  6340. var vector = vectors[ i ];
  6341. if ( vector === undefined ) {
  6342. console.warn( 'THREE.BufferAttribute.copyVector3sArray(): vector is undefined', i );
  6343. vector = new Vector3();
  6344. }
  6345. array[ offset ++ ] = vector.x;
  6346. array[ offset ++ ] = vector.y;
  6347. array[ offset ++ ] = vector.z;
  6348. }
  6349. return this;
  6350. },
  6351. copyVector4sArray: function ( vectors ) {
  6352. var array = this.array, offset = 0;
  6353. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  6354. var vector = vectors[ i ];
  6355. if ( vector === undefined ) {
  6356. console.warn( 'THREE.BufferAttribute.copyVector4sArray(): vector is undefined', i );
  6357. vector = new Vector4();
  6358. }
  6359. array[ offset ++ ] = vector.x;
  6360. array[ offset ++ ] = vector.y;
  6361. array[ offset ++ ] = vector.z;
  6362. array[ offset ++ ] = vector.w;
  6363. }
  6364. return this;
  6365. },
  6366. set: function ( value, offset ) {
  6367. if ( offset === undefined ) offset = 0;
  6368. this.array.set( value, offset );
  6369. return this;
  6370. },
  6371. getX: function ( index ) {
  6372. return this.array[ index * this.itemSize ];
  6373. },
  6374. setX: function ( index, x ) {
  6375. this.array[ index * this.itemSize ] = x;
  6376. return this;
  6377. },
  6378. getY: function ( index ) {
  6379. return this.array[ index * this.itemSize + 1 ];
  6380. },
  6381. setY: function ( index, y ) {
  6382. this.array[ index * this.itemSize + 1 ] = y;
  6383. return this;
  6384. },
  6385. getZ: function ( index ) {
  6386. return this.array[ index * this.itemSize + 2 ];
  6387. },
  6388. setZ: function ( index, z ) {
  6389. this.array[ index * this.itemSize + 2 ] = z;
  6390. return this;
  6391. },
  6392. getW: function ( index ) {
  6393. return this.array[ index * this.itemSize + 3 ];
  6394. },
  6395. setW: function ( index, w ) {
  6396. this.array[ index * this.itemSize + 3 ] = w;
  6397. return this;
  6398. },
  6399. setXY: function ( index, x, y ) {
  6400. index *= this.itemSize;
  6401. this.array[ index + 0 ] = x;
  6402. this.array[ index + 1 ] = y;
  6403. return this;
  6404. },
  6405. setXYZ: function ( index, x, y, z ) {
  6406. index *= this.itemSize;
  6407. this.array[ index + 0 ] = x;
  6408. this.array[ index + 1 ] = y;
  6409. this.array[ index + 2 ] = z;
  6410. return this;
  6411. },
  6412. setXYZW: function ( index, x, y, z, w ) {
  6413. index *= this.itemSize;
  6414. this.array[ index + 0 ] = x;
  6415. this.array[ index + 1 ] = y;
  6416. this.array[ index + 2 ] = z;
  6417. this.array[ index + 3 ] = w;
  6418. return this;
  6419. },
  6420. onUpload: function ( callback ) {
  6421. this.onUploadCallback = callback;
  6422. return this;
  6423. },
  6424. clone: function () {
  6425. return new this.constructor( this.array, this.itemSize ).copy( this );
  6426. }
  6427. } );
  6428. //
  6429. function Int8BufferAttribute( array, itemSize, normalized ) {
  6430. BufferAttribute.call( this, new Int8Array( array ), itemSize, normalized );
  6431. }
  6432. Int8BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  6433. Int8BufferAttribute.prototype.constructor = Int8BufferAttribute;
  6434. function Uint8BufferAttribute( array, itemSize, normalized ) {
  6435. BufferAttribute.call( this, new Uint8Array( array ), itemSize, normalized );
  6436. }
  6437. Uint8BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  6438. Uint8BufferAttribute.prototype.constructor = Uint8BufferAttribute;
  6439. function Uint8ClampedBufferAttribute( array, itemSize, normalized ) {
  6440. BufferAttribute.call( this, new Uint8ClampedArray( array ), itemSize, normalized );
  6441. }
  6442. Uint8ClampedBufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  6443. Uint8ClampedBufferAttribute.prototype.constructor = Uint8ClampedBufferAttribute;
  6444. function Int16BufferAttribute( array, itemSize, normalized ) {
  6445. BufferAttribute.call( this, new Int16Array( array ), itemSize, normalized );
  6446. }
  6447. Int16BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  6448. Int16BufferAttribute.prototype.constructor = Int16BufferAttribute;
  6449. function Uint16BufferAttribute( array, itemSize, normalized ) {
  6450. BufferAttribute.call( this, new Uint16Array( array ), itemSize, normalized );
  6451. }
  6452. Uint16BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  6453. Uint16BufferAttribute.prototype.constructor = Uint16BufferAttribute;
  6454. function Int32BufferAttribute( array, itemSize, normalized ) {
  6455. BufferAttribute.call( this, new Int32Array( array ), itemSize, normalized );
  6456. }
  6457. Int32BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  6458. Int32BufferAttribute.prototype.constructor = Int32BufferAttribute;
  6459. function Uint32BufferAttribute( array, itemSize, normalized ) {
  6460. BufferAttribute.call( this, new Uint32Array( array ), itemSize, normalized );
  6461. }
  6462. Uint32BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  6463. Uint32BufferAttribute.prototype.constructor = Uint32BufferAttribute;
  6464. function Float32BufferAttribute( array, itemSize, normalized ) {
  6465. BufferAttribute.call( this, new Float32Array( array ), itemSize, normalized );
  6466. }
  6467. Float32BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  6468. Float32BufferAttribute.prototype.constructor = Float32BufferAttribute;
  6469. function Float64BufferAttribute( array, itemSize, normalized ) {
  6470. BufferAttribute.call( this, new Float64Array( array ), itemSize, normalized );
  6471. }
  6472. Float64BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  6473. Float64BufferAttribute.prototype.constructor = Float64BufferAttribute;
  6474. /**
  6475. * @author mrdoob / http://mrdoob.com/
  6476. */
  6477. function DirectGeometry() {
  6478. this.vertices = [];
  6479. this.normals = [];
  6480. this.colors = [];
  6481. this.uvs = [];
  6482. this.uvs2 = [];
  6483. this.groups = [];
  6484. this.morphTargets = {};
  6485. this.skinWeights = [];
  6486. this.skinIndices = [];
  6487. // this.lineDistances = [];
  6488. this.boundingBox = null;
  6489. this.boundingSphere = null;
  6490. // update flags
  6491. this.verticesNeedUpdate = false;
  6492. this.normalsNeedUpdate = false;
  6493. this.colorsNeedUpdate = false;
  6494. this.uvsNeedUpdate = false;
  6495. this.groupsNeedUpdate = false;
  6496. }
  6497. Object.assign( DirectGeometry.prototype, {
  6498. computeGroups: function ( geometry ) {
  6499. var group;
  6500. var groups = [];
  6501. var materialIndex = undefined;
  6502. var faces = geometry.faces;
  6503. for ( var i = 0; i < faces.length; i ++ ) {
  6504. var face = faces[ i ];
  6505. // materials
  6506. if ( face.materialIndex !== materialIndex ) {
  6507. materialIndex = face.materialIndex;
  6508. if ( group !== undefined ) {
  6509. group.count = ( i * 3 ) - group.start;
  6510. groups.push( group );
  6511. }
  6512. group = {
  6513. start: i * 3,
  6514. materialIndex: materialIndex
  6515. };
  6516. }
  6517. }
  6518. if ( group !== undefined ) {
  6519. group.count = ( i * 3 ) - group.start;
  6520. groups.push( group );
  6521. }
  6522. this.groups = groups;
  6523. },
  6524. fromGeometry: function ( geometry ) {
  6525. var faces = geometry.faces;
  6526. var vertices = geometry.vertices;
  6527. var faceVertexUvs = geometry.faceVertexUvs;
  6528. var hasFaceVertexUv = faceVertexUvs[ 0 ] && faceVertexUvs[ 0 ].length > 0;
  6529. var hasFaceVertexUv2 = faceVertexUvs[ 1 ] && faceVertexUvs[ 1 ].length > 0;
  6530. // morphs
  6531. var morphTargets = geometry.morphTargets;
  6532. var morphTargetsLength = morphTargets.length;
  6533. var morphTargetsPosition;
  6534. if ( morphTargetsLength > 0 ) {
  6535. morphTargetsPosition = [];
  6536. for ( var i = 0; i < morphTargetsLength; i ++ ) {
  6537. morphTargetsPosition[ i ] = {
  6538. name: morphTargets[ i ].name,
  6539. data: []
  6540. };
  6541. }
  6542. this.morphTargets.position = morphTargetsPosition;
  6543. }
  6544. var morphNormals = geometry.morphNormals;
  6545. var morphNormalsLength = morphNormals.length;
  6546. var morphTargetsNormal;
  6547. if ( morphNormalsLength > 0 ) {
  6548. morphTargetsNormal = [];
  6549. for ( var i = 0; i < morphNormalsLength; i ++ ) {
  6550. morphTargetsNormal[ i ] = {
  6551. name: morphNormals[ i ].name,
  6552. data: []
  6553. };
  6554. }
  6555. this.morphTargets.normal = morphTargetsNormal;
  6556. }
  6557. // skins
  6558. var skinIndices = geometry.skinIndices;
  6559. var skinWeights = geometry.skinWeights;
  6560. var hasSkinIndices = skinIndices.length === vertices.length;
  6561. var hasSkinWeights = skinWeights.length === vertices.length;
  6562. //
  6563. if ( vertices.length > 0 && faces.length === 0 ) {
  6564. console.error( 'THREE.DirectGeometry: Faceless geometries are not supported.' );
  6565. }
  6566. for ( var i = 0; i < faces.length; i ++ ) {
  6567. var face = faces[ i ];
  6568. this.vertices.push( vertices[ face.a ], vertices[ face.b ], vertices[ face.c ] );
  6569. var vertexNormals = face.vertexNormals;
  6570. if ( vertexNormals.length === 3 ) {
  6571. this.normals.push( vertexNormals[ 0 ], vertexNormals[ 1 ], vertexNormals[ 2 ] );
  6572. } else {
  6573. var normal = face.normal;
  6574. this.normals.push( normal, normal, normal );
  6575. }
  6576. var vertexColors = face.vertexColors;
  6577. if ( vertexColors.length === 3 ) {
  6578. this.colors.push( vertexColors[ 0 ], vertexColors[ 1 ], vertexColors[ 2 ] );
  6579. } else {
  6580. var color = face.color;
  6581. this.colors.push( color, color, color );
  6582. }
  6583. if ( hasFaceVertexUv === true ) {
  6584. var vertexUvs = faceVertexUvs[ 0 ][ i ];
  6585. if ( vertexUvs !== undefined ) {
  6586. this.uvs.push( vertexUvs[ 0 ], vertexUvs[ 1 ], vertexUvs[ 2 ] );
  6587. } else {
  6588. console.warn( 'THREE.DirectGeometry.fromGeometry(): Undefined vertexUv ', i );
  6589. this.uvs.push( new Vector2(), new Vector2(), new Vector2() );
  6590. }
  6591. }
  6592. if ( hasFaceVertexUv2 === true ) {
  6593. var vertexUvs = faceVertexUvs[ 1 ][ i ];
  6594. if ( vertexUvs !== undefined ) {
  6595. this.uvs2.push( vertexUvs[ 0 ], vertexUvs[ 1 ], vertexUvs[ 2 ] );
  6596. } else {
  6597. console.warn( 'THREE.DirectGeometry.fromGeometry(): Undefined vertexUv2 ', i );
  6598. this.uvs2.push( new Vector2(), new Vector2(), new Vector2() );
  6599. }
  6600. }
  6601. // morphs
  6602. for ( var j = 0; j < morphTargetsLength; j ++ ) {
  6603. var morphTarget = morphTargets[ j ].vertices;
  6604. morphTargetsPosition[ j ].data.push( morphTarget[ face.a ], morphTarget[ face.b ], morphTarget[ face.c ] );
  6605. }
  6606. for ( var j = 0; j < morphNormalsLength; j ++ ) {
  6607. var morphNormal = morphNormals[ j ].vertexNormals[ i ];
  6608. morphTargetsNormal[ j ].data.push( morphNormal.a, morphNormal.b, morphNormal.c );
  6609. }
  6610. // skins
  6611. if ( hasSkinIndices ) {
  6612. this.skinIndices.push( skinIndices[ face.a ], skinIndices[ face.b ], skinIndices[ face.c ] );
  6613. }
  6614. if ( hasSkinWeights ) {
  6615. this.skinWeights.push( skinWeights[ face.a ], skinWeights[ face.b ], skinWeights[ face.c ] );
  6616. }
  6617. }
  6618. this.computeGroups( geometry );
  6619. this.verticesNeedUpdate = geometry.verticesNeedUpdate;
  6620. this.normalsNeedUpdate = geometry.normalsNeedUpdate;
  6621. this.colorsNeedUpdate = geometry.colorsNeedUpdate;
  6622. this.uvsNeedUpdate = geometry.uvsNeedUpdate;
  6623. this.groupsNeedUpdate = geometry.groupsNeedUpdate;
  6624. return this;
  6625. }
  6626. } );
  6627. /**
  6628. * @author mrdoob / http://mrdoob.com/
  6629. */
  6630. function arrayMax( array ) {
  6631. if ( array.length === 0 ) return - Infinity;
  6632. var max = array[ 0 ];
  6633. for ( var i = 1, l = array.length; i < l; ++ i ) {
  6634. if ( array[ i ] > max ) max = array[ i ];
  6635. }
  6636. return max;
  6637. }
  6638. /**
  6639. * @author alteredq / http://alteredqualia.com/
  6640. * @author mrdoob / http://mrdoob.com/
  6641. */
  6642. var bufferGeometryId = 1; // BufferGeometry uses odd numbers as Id
  6643. function BufferGeometry() {
  6644. Object.defineProperty( this, 'id', { value: bufferGeometryId += 2 } );
  6645. this.uuid = _Math.generateUUID();
  6646. this.name = '';
  6647. this.type = 'BufferGeometry';
  6648. this.index = null;
  6649. this.attributes = {};
  6650. this.morphAttributes = {};
  6651. this.groups = [];
  6652. this.boundingBox = null;
  6653. this.boundingSphere = null;
  6654. this.drawRange = { start: 0, count: Infinity };
  6655. this.userData = {};
  6656. }
  6657. BufferGeometry.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  6658. constructor: BufferGeometry,
  6659. isBufferGeometry: true,
  6660. getIndex: function () {
  6661. return this.index;
  6662. },
  6663. setIndex: function ( index ) {
  6664. if ( Array.isArray( index ) ) {
  6665. this.index = new ( arrayMax( index ) > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute )( index, 1 );
  6666. } else {
  6667. this.index = index;
  6668. }
  6669. },
  6670. addAttribute: function ( name, attribute ) {
  6671. if ( ! ( attribute && attribute.isBufferAttribute ) && ! ( attribute && attribute.isInterleavedBufferAttribute ) ) {
  6672. console.warn( 'THREE.BufferGeometry: .addAttribute() now expects ( name, attribute ).' );
  6673. return this.addAttribute( name, new BufferAttribute( arguments[ 1 ], arguments[ 2 ] ) );
  6674. }
  6675. if ( name === 'index' ) {
  6676. console.warn( 'THREE.BufferGeometry.addAttribute: Use .setIndex() for index attribute.' );
  6677. this.setIndex( attribute );
  6678. return this;
  6679. }
  6680. this.attributes[ name ] = attribute;
  6681. return this;
  6682. },
  6683. getAttribute: function ( name ) {
  6684. return this.attributes[ name ];
  6685. },
  6686. removeAttribute: function ( name ) {
  6687. delete this.attributes[ name ];
  6688. return this;
  6689. },
  6690. addGroup: function ( start, count, materialIndex ) {
  6691. this.groups.push( {
  6692. start: start,
  6693. count: count,
  6694. materialIndex: materialIndex !== undefined ? materialIndex : 0
  6695. } );
  6696. },
  6697. clearGroups: function () {
  6698. this.groups = [];
  6699. },
  6700. setDrawRange: function ( start, count ) {
  6701. this.drawRange.start = start;
  6702. this.drawRange.count = count;
  6703. },
  6704. applyMatrix: function ( matrix ) {
  6705. var position = this.attributes.position;
  6706. if ( position !== undefined ) {
  6707. matrix.applyToBufferAttribute( position );
  6708. position.needsUpdate = true;
  6709. }
  6710. var normal = this.attributes.normal;
  6711. if ( normal !== undefined ) {
  6712. var normalMatrix = new Matrix3().getNormalMatrix( matrix );
  6713. normalMatrix.applyToBufferAttribute( normal );
  6714. normal.needsUpdate = true;
  6715. }
  6716. var tangent = this.attributes.tangent;
  6717. if ( tangent !== undefined ) {
  6718. var normalMatrix = new Matrix3().getNormalMatrix( matrix );
  6719. // Tangent is vec4, but the '.w' component is a sign value (+1/-1).
  6720. normalMatrix.applyToBufferAttribute( tangent );
  6721. tangent.needsUpdate = true;
  6722. }
  6723. if ( this.boundingBox !== null ) {
  6724. this.computeBoundingBox();
  6725. }
  6726. if ( this.boundingSphere !== null ) {
  6727. this.computeBoundingSphere();
  6728. }
  6729. return this;
  6730. },
  6731. rotateX: function () {
  6732. // rotate geometry around world x-axis
  6733. var m1 = new Matrix4();
  6734. return function rotateX( angle ) {
  6735. m1.makeRotationX( angle );
  6736. this.applyMatrix( m1 );
  6737. return this;
  6738. };
  6739. }(),
  6740. rotateY: function () {
  6741. // rotate geometry around world y-axis
  6742. var m1 = new Matrix4();
  6743. return function rotateY( angle ) {
  6744. m1.makeRotationY( angle );
  6745. this.applyMatrix( m1 );
  6746. return this;
  6747. };
  6748. }(),
  6749. rotateZ: function () {
  6750. // rotate geometry around world z-axis
  6751. var m1 = new Matrix4();
  6752. return function rotateZ( angle ) {
  6753. m1.makeRotationZ( angle );
  6754. this.applyMatrix( m1 );
  6755. return this;
  6756. };
  6757. }(),
  6758. translate: function () {
  6759. // translate geometry
  6760. var m1 = new Matrix4();
  6761. return function translate( x, y, z ) {
  6762. m1.makeTranslation( x, y, z );
  6763. this.applyMatrix( m1 );
  6764. return this;
  6765. };
  6766. }(),
  6767. scale: function () {
  6768. // scale geometry
  6769. var m1 = new Matrix4();
  6770. return function scale( x, y, z ) {
  6771. m1.makeScale( x, y, z );
  6772. this.applyMatrix( m1 );
  6773. return this;
  6774. };
  6775. }(),
  6776. lookAt: function () {
  6777. var obj = new Object3D();
  6778. return function lookAt( vector ) {
  6779. obj.lookAt( vector );
  6780. obj.updateMatrix();
  6781. this.applyMatrix( obj.matrix );
  6782. };
  6783. }(),
  6784. center: function () {
  6785. var offset = new Vector3();
  6786. return function center() {
  6787. this.computeBoundingBox();
  6788. this.boundingBox.getCenter( offset ).negate();
  6789. this.translate( offset.x, offset.y, offset.z );
  6790. return this;
  6791. };
  6792. }(),
  6793. setFromObject: function ( object ) {
  6794. // console.log( 'THREE.BufferGeometry.setFromObject(). Converting', object, this );
  6795. var geometry = object.geometry;
  6796. if ( object.isPoints || object.isLine ) {
  6797. var positions = new Float32BufferAttribute( geometry.vertices.length * 3, 3 );
  6798. var colors = new Float32BufferAttribute( geometry.colors.length * 3, 3 );
  6799. this.addAttribute( 'position', positions.copyVector3sArray( geometry.vertices ) );
  6800. this.addAttribute( 'color', colors.copyColorsArray( geometry.colors ) );
  6801. if ( geometry.lineDistances && geometry.lineDistances.length === geometry.vertices.length ) {
  6802. var lineDistances = new Float32BufferAttribute( geometry.lineDistances.length, 1 );
  6803. this.addAttribute( 'lineDistance', lineDistances.copyArray( geometry.lineDistances ) );
  6804. }
  6805. if ( geometry.boundingSphere !== null ) {
  6806. this.boundingSphere = geometry.boundingSphere.clone();
  6807. }
  6808. if ( geometry.boundingBox !== null ) {
  6809. this.boundingBox = geometry.boundingBox.clone();
  6810. }
  6811. } else if ( object.isMesh ) {
  6812. if ( geometry && geometry.isGeometry ) {
  6813. this.fromGeometry( geometry );
  6814. }
  6815. }
  6816. return this;
  6817. },
  6818. setFromPoints: function ( points ) {
  6819. var position = [];
  6820. for ( var i = 0, l = points.length; i < l; i ++ ) {
  6821. var point = points[ i ];
  6822. position.push( point.x, point.y, point.z || 0 );
  6823. }
  6824. this.addAttribute( 'position', new Float32BufferAttribute( position, 3 ) );
  6825. return this;
  6826. },
  6827. updateFromObject: function ( object ) {
  6828. var geometry = object.geometry;
  6829. if ( object.isMesh ) {
  6830. var direct = geometry.__directGeometry;
  6831. if ( geometry.elementsNeedUpdate === true ) {
  6832. direct = undefined;
  6833. geometry.elementsNeedUpdate = false;
  6834. }
  6835. if ( direct === undefined ) {
  6836. return this.fromGeometry( geometry );
  6837. }
  6838. direct.verticesNeedUpdate = geometry.verticesNeedUpdate;
  6839. direct.normalsNeedUpdate = geometry.normalsNeedUpdate;
  6840. direct.colorsNeedUpdate = geometry.colorsNeedUpdate;
  6841. direct.uvsNeedUpdate = geometry.uvsNeedUpdate;
  6842. direct.groupsNeedUpdate = geometry.groupsNeedUpdate;
  6843. geometry.verticesNeedUpdate = false;
  6844. geometry.normalsNeedUpdate = false;
  6845. geometry.colorsNeedUpdate = false;
  6846. geometry.uvsNeedUpdate = false;
  6847. geometry.groupsNeedUpdate = false;
  6848. geometry = direct;
  6849. }
  6850. var attribute;
  6851. if ( geometry.verticesNeedUpdate === true ) {
  6852. attribute = this.attributes.position;
  6853. if ( attribute !== undefined ) {
  6854. attribute.copyVector3sArray( geometry.vertices );
  6855. attribute.needsUpdate = true;
  6856. }
  6857. geometry.verticesNeedUpdate = false;
  6858. }
  6859. if ( geometry.normalsNeedUpdate === true ) {
  6860. attribute = this.attributes.normal;
  6861. if ( attribute !== undefined ) {
  6862. attribute.copyVector3sArray( geometry.normals );
  6863. attribute.needsUpdate = true;
  6864. }
  6865. geometry.normalsNeedUpdate = false;
  6866. }
  6867. if ( geometry.colorsNeedUpdate === true ) {
  6868. attribute = this.attributes.color;
  6869. if ( attribute !== undefined ) {
  6870. attribute.copyColorsArray( geometry.colors );
  6871. attribute.needsUpdate = true;
  6872. }
  6873. geometry.colorsNeedUpdate = false;
  6874. }
  6875. if ( geometry.uvsNeedUpdate ) {
  6876. attribute = this.attributes.uv;
  6877. if ( attribute !== undefined ) {
  6878. attribute.copyVector2sArray( geometry.uvs );
  6879. attribute.needsUpdate = true;
  6880. }
  6881. geometry.uvsNeedUpdate = false;
  6882. }
  6883. if ( geometry.lineDistancesNeedUpdate ) {
  6884. attribute = this.attributes.lineDistance;
  6885. if ( attribute !== undefined ) {
  6886. attribute.copyArray( geometry.lineDistances );
  6887. attribute.needsUpdate = true;
  6888. }
  6889. geometry.lineDistancesNeedUpdate = false;
  6890. }
  6891. if ( geometry.groupsNeedUpdate ) {
  6892. geometry.computeGroups( object.geometry );
  6893. this.groups = geometry.groups;
  6894. geometry.groupsNeedUpdate = false;
  6895. }
  6896. return this;
  6897. },
  6898. fromGeometry: function ( geometry ) {
  6899. geometry.__directGeometry = new DirectGeometry().fromGeometry( geometry );
  6900. return this.fromDirectGeometry( geometry.__directGeometry );
  6901. },
  6902. fromDirectGeometry: function ( geometry ) {
  6903. var positions = new Float32Array( geometry.vertices.length * 3 );
  6904. this.addAttribute( 'position', new BufferAttribute( positions, 3 ).copyVector3sArray( geometry.vertices ) );
  6905. if ( geometry.normals.length > 0 ) {
  6906. var normals = new Float32Array( geometry.normals.length * 3 );
  6907. this.addAttribute( 'normal', new BufferAttribute( normals, 3 ).copyVector3sArray( geometry.normals ) );
  6908. }
  6909. if ( geometry.colors.length > 0 ) {
  6910. var colors = new Float32Array( geometry.colors.length * 3 );
  6911. this.addAttribute( 'color', new BufferAttribute( colors, 3 ).copyColorsArray( geometry.colors ) );
  6912. }
  6913. if ( geometry.uvs.length > 0 ) {
  6914. var uvs = new Float32Array( geometry.uvs.length * 2 );
  6915. this.addAttribute( 'uv', new BufferAttribute( uvs, 2 ).copyVector2sArray( geometry.uvs ) );
  6916. }
  6917. if ( geometry.uvs2.length > 0 ) {
  6918. var uvs2 = new Float32Array( geometry.uvs2.length * 2 );
  6919. this.addAttribute( 'uv2', new BufferAttribute( uvs2, 2 ).copyVector2sArray( geometry.uvs2 ) );
  6920. }
  6921. // groups
  6922. this.groups = geometry.groups;
  6923. // morphs
  6924. for ( var name in geometry.morphTargets ) {
  6925. var array = [];
  6926. var morphTargets = geometry.morphTargets[ name ];
  6927. for ( var i = 0, l = morphTargets.length; i < l; i ++ ) {
  6928. var morphTarget = morphTargets[ i ];
  6929. var attribute = new Float32BufferAttribute( morphTarget.data.length * 3, 3 );
  6930. attribute.name = morphTarget.name;
  6931. array.push( attribute.copyVector3sArray( morphTarget.data ) );
  6932. }
  6933. this.morphAttributes[ name ] = array;
  6934. }
  6935. // skinning
  6936. if ( geometry.skinIndices.length > 0 ) {
  6937. var skinIndices = new Float32BufferAttribute( geometry.skinIndices.length * 4, 4 );
  6938. this.addAttribute( 'skinIndex', skinIndices.copyVector4sArray( geometry.skinIndices ) );
  6939. }
  6940. if ( geometry.skinWeights.length > 0 ) {
  6941. var skinWeights = new Float32BufferAttribute( geometry.skinWeights.length * 4, 4 );
  6942. this.addAttribute( 'skinWeight', skinWeights.copyVector4sArray( geometry.skinWeights ) );
  6943. }
  6944. //
  6945. if ( geometry.boundingSphere !== null ) {
  6946. this.boundingSphere = geometry.boundingSphere.clone();
  6947. }
  6948. if ( geometry.boundingBox !== null ) {
  6949. this.boundingBox = geometry.boundingBox.clone();
  6950. }
  6951. return this;
  6952. },
  6953. computeBoundingBox: function () {
  6954. var box = new Box3();
  6955. return function computeBoundingBox() {
  6956. if ( this.boundingBox === null ) {
  6957. this.boundingBox = new Box3();
  6958. }
  6959. var position = this.attributes.position;
  6960. var morphAttributesPosition = this.morphAttributes.position;
  6961. if ( position !== undefined ) {
  6962. this.boundingBox.setFromBufferAttribute( position );
  6963. // process morph attributes if present
  6964. if ( morphAttributesPosition ) {
  6965. for ( var i = 0, il = morphAttributesPosition.length; i < il; i ++ ) {
  6966. var morphAttribute = morphAttributesPosition[ i ];
  6967. box.setFromBufferAttribute( morphAttribute );
  6968. this.boundingBox.expandByPoint( box.min );
  6969. this.boundingBox.expandByPoint( box.max );
  6970. }
  6971. }
  6972. } else {
  6973. this.boundingBox.makeEmpty();
  6974. }
  6975. if ( isNaN( this.boundingBox.min.x ) || isNaN( this.boundingBox.min.y ) || isNaN( this.boundingBox.min.z ) ) {
  6976. console.error( 'THREE.BufferGeometry.computeBoundingBox: Computed min/max have NaN values. The "position" attribute is likely to have NaN values.', this );
  6977. }
  6978. };
  6979. }(),
  6980. computeBoundingSphere: function () {
  6981. var box = new Box3();
  6982. var boxMorphTargets = new Box3();
  6983. var vector = new Vector3();
  6984. return function computeBoundingSphere() {
  6985. if ( this.boundingSphere === null ) {
  6986. this.boundingSphere = new Sphere();
  6987. }
  6988. var position = this.attributes.position;
  6989. var morphAttributesPosition = this.morphAttributes.position;
  6990. if ( position ) {
  6991. // first, find the center of the bounding sphere
  6992. var center = this.boundingSphere.center;
  6993. box.setFromBufferAttribute( position );
  6994. // process morph attributes if present
  6995. if ( morphAttributesPosition ) {
  6996. for ( var i = 0, il = morphAttributesPosition.length; i < il; i ++ ) {
  6997. var morphAttribute = morphAttributesPosition[ i ];
  6998. boxMorphTargets.setFromBufferAttribute( morphAttribute );
  6999. box.expandByPoint( boxMorphTargets.min );
  7000. box.expandByPoint( boxMorphTargets.max );
  7001. }
  7002. }
  7003. box.getCenter( center );
  7004. // second, try to find a boundingSphere with a radius smaller than the
  7005. // boundingSphere of the boundingBox: sqrt(3) smaller in the best case
  7006. var maxRadiusSq = 0;
  7007. for ( var i = 0, il = position.count; i < il; i ++ ) {
  7008. vector.fromBufferAttribute( position, i );
  7009. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( vector ) );
  7010. }
  7011. // process morph attributes if present
  7012. if ( morphAttributesPosition ) {
  7013. for ( var i = 0, il = morphAttributesPosition.length; i < il; i ++ ) {
  7014. var morphAttribute = morphAttributesPosition[ i ];
  7015. for ( var j = 0, jl = morphAttribute.count; j < jl; j ++ ) {
  7016. vector.fromBufferAttribute( morphAttribute, j );
  7017. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( vector ) );
  7018. }
  7019. }
  7020. }
  7021. this.boundingSphere.radius = Math.sqrt( maxRadiusSq );
  7022. if ( isNaN( this.boundingSphere.radius ) ) {
  7023. console.error( 'THREE.BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.', this );
  7024. }
  7025. }
  7026. };
  7027. }(),
  7028. computeFaceNormals: function () {
  7029. // backwards compatibility
  7030. },
  7031. computeVertexNormals: function () {
  7032. var index = this.index;
  7033. var attributes = this.attributes;
  7034. if ( attributes.position ) {
  7035. var positions = attributes.position.array;
  7036. if ( attributes.normal === undefined ) {
  7037. this.addAttribute( 'normal', new BufferAttribute( new Float32Array( positions.length ), 3 ) );
  7038. } else {
  7039. // reset existing normals to zero
  7040. var array = attributes.normal.array;
  7041. for ( var i = 0, il = array.length; i < il; i ++ ) {
  7042. array[ i ] = 0;
  7043. }
  7044. }
  7045. var normals = attributes.normal.array;
  7046. var vA, vB, vC;
  7047. var pA = new Vector3(), pB = new Vector3(), pC = new Vector3();
  7048. var cb = new Vector3(), ab = new Vector3();
  7049. // indexed elements
  7050. if ( index ) {
  7051. var indices = index.array;
  7052. for ( var i = 0, il = index.count; i < il; i += 3 ) {
  7053. vA = indices[ i + 0 ] * 3;
  7054. vB = indices[ i + 1 ] * 3;
  7055. vC = indices[ i + 2 ] * 3;
  7056. pA.fromArray( positions, vA );
  7057. pB.fromArray( positions, vB );
  7058. pC.fromArray( positions, vC );
  7059. cb.subVectors( pC, pB );
  7060. ab.subVectors( pA, pB );
  7061. cb.cross( ab );
  7062. normals[ vA ] += cb.x;
  7063. normals[ vA + 1 ] += cb.y;
  7064. normals[ vA + 2 ] += cb.z;
  7065. normals[ vB ] += cb.x;
  7066. normals[ vB + 1 ] += cb.y;
  7067. normals[ vB + 2 ] += cb.z;
  7068. normals[ vC ] += cb.x;
  7069. normals[ vC + 1 ] += cb.y;
  7070. normals[ vC + 2 ] += cb.z;
  7071. }
  7072. } else {
  7073. // non-indexed elements (unconnected triangle soup)
  7074. for ( var i = 0, il = positions.length; i < il; i += 9 ) {
  7075. pA.fromArray( positions, i );
  7076. pB.fromArray( positions, i + 3 );
  7077. pC.fromArray( positions, i + 6 );
  7078. cb.subVectors( pC, pB );
  7079. ab.subVectors( pA, pB );
  7080. cb.cross( ab );
  7081. normals[ i ] = cb.x;
  7082. normals[ i + 1 ] = cb.y;
  7083. normals[ i + 2 ] = cb.z;
  7084. normals[ i + 3 ] = cb.x;
  7085. normals[ i + 4 ] = cb.y;
  7086. normals[ i + 5 ] = cb.z;
  7087. normals[ i + 6 ] = cb.x;
  7088. normals[ i + 7 ] = cb.y;
  7089. normals[ i + 8 ] = cb.z;
  7090. }
  7091. }
  7092. this.normalizeNormals();
  7093. attributes.normal.needsUpdate = true;
  7094. }
  7095. },
  7096. merge: function ( geometry, offset ) {
  7097. if ( ! ( geometry && geometry.isBufferGeometry ) ) {
  7098. console.error( 'THREE.BufferGeometry.merge(): geometry not an instance of THREE.BufferGeometry.', geometry );
  7099. return;
  7100. }
  7101. if ( offset === undefined ) {
  7102. offset = 0;
  7103. console.warn(
  7104. 'THREE.BufferGeometry.merge(): Overwriting original geometry, starting at offset=0. '
  7105. + 'Use BufferGeometryUtils.mergeBufferGeometries() for lossless merge.'
  7106. );
  7107. }
  7108. var attributes = this.attributes;
  7109. for ( var key in attributes ) {
  7110. if ( geometry.attributes[ key ] === undefined ) continue;
  7111. var attribute1 = attributes[ key ];
  7112. var attributeArray1 = attribute1.array;
  7113. var attribute2 = geometry.attributes[ key ];
  7114. var attributeArray2 = attribute2.array;
  7115. var attributeSize = attribute2.itemSize;
  7116. for ( var i = 0, j = attributeSize * offset; i < attributeArray2.length; i ++, j ++ ) {
  7117. attributeArray1[ j ] = attributeArray2[ i ];
  7118. }
  7119. }
  7120. return this;
  7121. },
  7122. normalizeNormals: function () {
  7123. var vector = new Vector3();
  7124. return function normalizeNormals() {
  7125. var normals = this.attributes.normal;
  7126. for ( var i = 0, il = normals.count; i < il; i ++ ) {
  7127. vector.x = normals.getX( i );
  7128. vector.y = normals.getY( i );
  7129. vector.z = normals.getZ( i );
  7130. vector.normalize();
  7131. normals.setXYZ( i, vector.x, vector.y, vector.z );
  7132. }
  7133. };
  7134. }(),
  7135. toNonIndexed: function () {
  7136. function convertBufferAttribute( attribute, indices ) {
  7137. var array = attribute.array;
  7138. var itemSize = attribute.itemSize;
  7139. var array2 = new array.constructor( indices.length * itemSize );
  7140. var index = 0, index2 = 0;
  7141. for ( var i = 0, l = indices.length; i < l; i ++ ) {
  7142. index = indices[ i ] * itemSize;
  7143. for ( var j = 0; j < itemSize; j ++ ) {
  7144. array2[ index2 ++ ] = array[ index ++ ];
  7145. }
  7146. }
  7147. return new BufferAttribute( array2, itemSize );
  7148. }
  7149. //
  7150. if ( this.index === null ) {
  7151. console.warn( 'THREE.BufferGeometry.toNonIndexed(): Geometry is already non-indexed.' );
  7152. return this;
  7153. }
  7154. var geometry2 = new BufferGeometry();
  7155. var indices = this.index.array;
  7156. var attributes = this.attributes;
  7157. // attributes
  7158. for ( var name in attributes ) {
  7159. var attribute = attributes[ name ];
  7160. var newAttribute = convertBufferAttribute( attribute, indices );
  7161. geometry2.addAttribute( name, newAttribute );
  7162. }
  7163. // morph attributes
  7164. var morphAttributes = this.morphAttributes;
  7165. for ( name in morphAttributes ) {
  7166. var morphArray = [];
  7167. var morphAttribute = morphAttributes[ name ]; // morphAttribute: array of Float32BufferAttributes
  7168. for ( var i = 0, il = morphAttribute.length; i < il; i ++ ) {
  7169. var attribute = morphAttribute[ i ];
  7170. var newAttribute = convertBufferAttribute( attribute, indices );
  7171. morphArray.push( newAttribute );
  7172. }
  7173. geometry2.morphAttributes[ name ] = morphArray;
  7174. }
  7175. // groups
  7176. var groups = this.groups;
  7177. for ( var i = 0, l = groups.length; i < l; i ++ ) {
  7178. var group = groups[ i ];
  7179. geometry2.addGroup( group.start, group.count, group.materialIndex );
  7180. }
  7181. return geometry2;
  7182. },
  7183. toJSON: function () {
  7184. var data = {
  7185. metadata: {
  7186. version: 4.5,
  7187. type: 'BufferGeometry',
  7188. generator: 'BufferGeometry.toJSON'
  7189. }
  7190. };
  7191. // standard BufferGeometry serialization
  7192. data.uuid = this.uuid;
  7193. data.type = this.type;
  7194. if ( this.name !== '' ) data.name = this.name;
  7195. if ( Object.keys( this.userData ).length > 0 ) data.userData = this.userData;
  7196. if ( this.parameters !== undefined ) {
  7197. var parameters = this.parameters;
  7198. for ( var key in parameters ) {
  7199. if ( parameters[ key ] !== undefined ) data[ key ] = parameters[ key ];
  7200. }
  7201. return data;
  7202. }
  7203. data.data = { attributes: {} };
  7204. var index = this.index;
  7205. if ( index !== null ) {
  7206. data.data.index = {
  7207. type: index.array.constructor.name,
  7208. array: Array.prototype.slice.call( index.array )
  7209. };
  7210. }
  7211. var attributes = this.attributes;
  7212. for ( var key in attributes ) {
  7213. var attribute = attributes[ key ];
  7214. var attributeData = {
  7215. itemSize: attribute.itemSize,
  7216. type: attribute.array.constructor.name,
  7217. array: Array.prototype.slice.call( attribute.array ),
  7218. normalized: attribute.normalized
  7219. };
  7220. if ( attribute.name !== '' ) attributeData.name = attribute.name;
  7221. data.data.attributes[ key ] = attributeData;
  7222. }
  7223. var morphAttributes = {};
  7224. var hasMorphAttributes = false;
  7225. for ( var key in this.morphAttributes ) {
  7226. var attributeArray = this.morphAttributes[ key ];
  7227. var array = [];
  7228. for ( var i = 0, il = attributeArray.length; i < il; i ++ ) {
  7229. var attribute = attributeArray[ i ];
  7230. var attributeData = {
  7231. itemSize: attribute.itemSize,
  7232. type: attribute.array.constructor.name,
  7233. array: Array.prototype.slice.call( attribute.array ),
  7234. normalized: attribute.normalized
  7235. };
  7236. if ( attribute.name !== '' ) attributeData.name = attribute.name;
  7237. array.push( attributeData );
  7238. }
  7239. if ( array.length > 0 ) {
  7240. morphAttributes[ key ] = array;
  7241. hasMorphAttributes = true;
  7242. }
  7243. }
  7244. if ( hasMorphAttributes ) data.data.morphAttributes = morphAttributes;
  7245. var groups = this.groups;
  7246. if ( groups.length > 0 ) {
  7247. data.data.groups = JSON.parse( JSON.stringify( groups ) );
  7248. }
  7249. var boundingSphere = this.boundingSphere;
  7250. if ( boundingSphere !== null ) {
  7251. data.data.boundingSphere = {
  7252. center: boundingSphere.center.toArray(),
  7253. radius: boundingSphere.radius
  7254. };
  7255. }
  7256. return data;
  7257. },
  7258. clone: function () {
  7259. /*
  7260. // Handle primitives
  7261. var parameters = this.parameters;
  7262. if ( parameters !== undefined ) {
  7263. var values = [];
  7264. for ( var key in parameters ) {
  7265. values.push( parameters[ key ] );
  7266. }
  7267. var geometry = Object.create( this.constructor.prototype );
  7268. this.constructor.apply( geometry, values );
  7269. return geometry;
  7270. }
  7271. return new this.constructor().copy( this );
  7272. */
  7273. return new BufferGeometry().copy( this );
  7274. },
  7275. copy: function ( source ) {
  7276. var name, i, l;
  7277. // reset
  7278. this.index = null;
  7279. this.attributes = {};
  7280. this.morphAttributes = {};
  7281. this.groups = [];
  7282. this.boundingBox = null;
  7283. this.boundingSphere = null;
  7284. // name
  7285. this.name = source.name;
  7286. // index
  7287. var index = source.index;
  7288. if ( index !== null ) {
  7289. this.setIndex( index.clone() );
  7290. }
  7291. // attributes
  7292. var attributes = source.attributes;
  7293. for ( name in attributes ) {
  7294. var attribute = attributes[ name ];
  7295. this.addAttribute( name, attribute.clone() );
  7296. }
  7297. // morph attributes
  7298. var morphAttributes = source.morphAttributes;
  7299. for ( name in morphAttributes ) {
  7300. var array = [];
  7301. var morphAttribute = morphAttributes[ name ]; // morphAttribute: array of Float32BufferAttributes
  7302. for ( i = 0, l = morphAttribute.length; i < l; i ++ ) {
  7303. array.push( morphAttribute[ i ].clone() );
  7304. }
  7305. this.morphAttributes[ name ] = array;
  7306. }
  7307. // groups
  7308. var groups = source.groups;
  7309. for ( i = 0, l = groups.length; i < l; i ++ ) {
  7310. var group = groups[ i ];
  7311. this.addGroup( group.start, group.count, group.materialIndex );
  7312. }
  7313. // bounding box
  7314. var boundingBox = source.boundingBox;
  7315. if ( boundingBox !== null ) {
  7316. this.boundingBox = boundingBox.clone();
  7317. }
  7318. // bounding sphere
  7319. var boundingSphere = source.boundingSphere;
  7320. if ( boundingSphere !== null ) {
  7321. this.boundingSphere = boundingSphere.clone();
  7322. }
  7323. // draw range
  7324. this.drawRange.start = source.drawRange.start;
  7325. this.drawRange.count = source.drawRange.count;
  7326. // user data
  7327. this.userData = source.userData;
  7328. return this;
  7329. },
  7330. dispose: function () {
  7331. this.dispatchEvent( { type: 'dispose' } );
  7332. }
  7333. } );
  7334. /**
  7335. * @author mrdoob / http://mrdoob.com/
  7336. * @author Mugen87 / https://github.com/Mugen87
  7337. */
  7338. // BoxGeometry
  7339. function BoxGeometry( width, height, depth, widthSegments, heightSegments, depthSegments ) {
  7340. Geometry.call( this );
  7341. this.type = 'BoxGeometry';
  7342. this.parameters = {
  7343. width: width,
  7344. height: height,
  7345. depth: depth,
  7346. widthSegments: widthSegments,
  7347. heightSegments: heightSegments,
  7348. depthSegments: depthSegments
  7349. };
  7350. this.fromBufferGeometry( new BoxBufferGeometry( width, height, depth, widthSegments, heightSegments, depthSegments ) );
  7351. this.mergeVertices();
  7352. }
  7353. BoxGeometry.prototype = Object.create( Geometry.prototype );
  7354. BoxGeometry.prototype.constructor = BoxGeometry;
  7355. // BoxBufferGeometry
  7356. function BoxBufferGeometry( width, height, depth, widthSegments, heightSegments, depthSegments ) {
  7357. BufferGeometry.call( this );
  7358. this.type = 'BoxBufferGeometry';
  7359. this.parameters = {
  7360. width: width,
  7361. height: height,
  7362. depth: depth,
  7363. widthSegments: widthSegments,
  7364. heightSegments: heightSegments,
  7365. depthSegments: depthSegments
  7366. };
  7367. var scope = this;
  7368. width = width || 1;
  7369. height = height || 1;
  7370. depth = depth || 1;
  7371. // segments
  7372. widthSegments = Math.floor( widthSegments ) || 1;
  7373. heightSegments = Math.floor( heightSegments ) || 1;
  7374. depthSegments = Math.floor( depthSegments ) || 1;
  7375. // buffers
  7376. var indices = [];
  7377. var vertices = [];
  7378. var normals = [];
  7379. var uvs = [];
  7380. // helper variables
  7381. var numberOfVertices = 0;
  7382. var groupStart = 0;
  7383. // build each side of the box geometry
  7384. buildPlane( 'z', 'y', 'x', - 1, - 1, depth, height, width, depthSegments, heightSegments, 0 ); // px
  7385. buildPlane( 'z', 'y', 'x', 1, - 1, depth, height, - width, depthSegments, heightSegments, 1 ); // nx
  7386. buildPlane( 'x', 'z', 'y', 1, 1, width, depth, height, widthSegments, depthSegments, 2 ); // py
  7387. buildPlane( 'x', 'z', 'y', 1, - 1, width, depth, - height, widthSegments, depthSegments, 3 ); // ny
  7388. buildPlane( 'x', 'y', 'z', 1, - 1, width, height, depth, widthSegments, heightSegments, 4 ); // pz
  7389. buildPlane( 'x', 'y', 'z', - 1, - 1, width, height, - depth, widthSegments, heightSegments, 5 ); // nz
  7390. // build geometry
  7391. this.setIndex( indices );
  7392. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  7393. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  7394. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  7395. function buildPlane( u, v, w, udir, vdir, width, height, depth, gridX, gridY, materialIndex ) {
  7396. var segmentWidth = width / gridX;
  7397. var segmentHeight = height / gridY;
  7398. var widthHalf = width / 2;
  7399. var heightHalf = height / 2;
  7400. var depthHalf = depth / 2;
  7401. var gridX1 = gridX + 1;
  7402. var gridY1 = gridY + 1;
  7403. var vertexCounter = 0;
  7404. var groupCount = 0;
  7405. var ix, iy;
  7406. var vector = new Vector3();
  7407. // generate vertices, normals and uvs
  7408. for ( iy = 0; iy < gridY1; iy ++ ) {
  7409. var y = iy * segmentHeight - heightHalf;
  7410. for ( ix = 0; ix < gridX1; ix ++ ) {
  7411. var x = ix * segmentWidth - widthHalf;
  7412. // set values to correct vector component
  7413. vector[ u ] = x * udir;
  7414. vector[ v ] = y * vdir;
  7415. vector[ w ] = depthHalf;
  7416. // now apply vector to vertex buffer
  7417. vertices.push( vector.x, vector.y, vector.z );
  7418. // set values to correct vector component
  7419. vector[ u ] = 0;
  7420. vector[ v ] = 0;
  7421. vector[ w ] = depth > 0 ? 1 : - 1;
  7422. // now apply vector to normal buffer
  7423. normals.push( vector.x, vector.y, vector.z );
  7424. // uvs
  7425. uvs.push( ix / gridX );
  7426. uvs.push( 1 - ( iy / gridY ) );
  7427. // counters
  7428. vertexCounter += 1;
  7429. }
  7430. }
  7431. // indices
  7432. // 1. you need three indices to draw a single face
  7433. // 2. a single segment consists of two faces
  7434. // 3. so we need to generate six (2*3) indices per segment
  7435. for ( iy = 0; iy < gridY; iy ++ ) {
  7436. for ( ix = 0; ix < gridX; ix ++ ) {
  7437. var a = numberOfVertices + ix + gridX1 * iy;
  7438. var b = numberOfVertices + ix + gridX1 * ( iy + 1 );
  7439. var c = numberOfVertices + ( ix + 1 ) + gridX1 * ( iy + 1 );
  7440. var d = numberOfVertices + ( ix + 1 ) + gridX1 * iy;
  7441. // faces
  7442. indices.push( a, b, d );
  7443. indices.push( b, c, d );
  7444. // increase counter
  7445. groupCount += 6;
  7446. }
  7447. }
  7448. // add a group to the geometry. this will ensure multi material support
  7449. scope.addGroup( groupStart, groupCount, materialIndex );
  7450. // calculate new start value for groups
  7451. groupStart += groupCount;
  7452. // update total number of vertices
  7453. numberOfVertices += vertexCounter;
  7454. }
  7455. }
  7456. BoxBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  7457. BoxBufferGeometry.prototype.constructor = BoxBufferGeometry;
  7458. /**
  7459. * @author mrdoob / http://mrdoob.com/
  7460. * @author Mugen87 / https://github.com/Mugen87
  7461. */
  7462. // PlaneGeometry
  7463. function PlaneGeometry( width, height, widthSegments, heightSegments ) {
  7464. Geometry.call( this );
  7465. this.type = 'PlaneGeometry';
  7466. this.parameters = {
  7467. width: width,
  7468. height: height,
  7469. widthSegments: widthSegments,
  7470. heightSegments: heightSegments
  7471. };
  7472. this.fromBufferGeometry( new PlaneBufferGeometry( width, height, widthSegments, heightSegments ) );
  7473. this.mergeVertices();
  7474. }
  7475. PlaneGeometry.prototype = Object.create( Geometry.prototype );
  7476. PlaneGeometry.prototype.constructor = PlaneGeometry;
  7477. // PlaneBufferGeometry
  7478. function PlaneBufferGeometry( width, height, widthSegments, heightSegments ) {
  7479. BufferGeometry.call( this );
  7480. this.type = 'PlaneBufferGeometry';
  7481. this.parameters = {
  7482. width: width,
  7483. height: height,
  7484. widthSegments: widthSegments,
  7485. heightSegments: heightSegments
  7486. };
  7487. width = width || 1;
  7488. height = height || 1;
  7489. var width_half = width / 2;
  7490. var height_half = height / 2;
  7491. var gridX = Math.floor( widthSegments ) || 1;
  7492. var gridY = Math.floor( heightSegments ) || 1;
  7493. var gridX1 = gridX + 1;
  7494. var gridY1 = gridY + 1;
  7495. var segment_width = width / gridX;
  7496. var segment_height = height / gridY;
  7497. var ix, iy;
  7498. // buffers
  7499. var indices = [];
  7500. var vertices = [];
  7501. var normals = [];
  7502. var uvs = [];
  7503. // generate vertices, normals and uvs
  7504. for ( iy = 0; iy < gridY1; iy ++ ) {
  7505. var y = iy * segment_height - height_half;
  7506. for ( ix = 0; ix < gridX1; ix ++ ) {
  7507. var x = ix * segment_width - width_half;
  7508. vertices.push( x, - y, 0 );
  7509. normals.push( 0, 0, 1 );
  7510. uvs.push( ix / gridX );
  7511. uvs.push( 1 - ( iy / gridY ) );
  7512. }
  7513. }
  7514. // indices
  7515. for ( iy = 0; iy < gridY; iy ++ ) {
  7516. for ( ix = 0; ix < gridX; ix ++ ) {
  7517. var a = ix + gridX1 * iy;
  7518. var b = ix + gridX1 * ( iy + 1 );
  7519. var c = ( ix + 1 ) + gridX1 * ( iy + 1 );
  7520. var d = ( ix + 1 ) + gridX1 * iy;
  7521. // faces
  7522. indices.push( a, b, d );
  7523. indices.push( b, c, d );
  7524. }
  7525. }
  7526. // build geometry
  7527. this.setIndex( indices );
  7528. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  7529. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  7530. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  7531. }
  7532. PlaneBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  7533. PlaneBufferGeometry.prototype.constructor = PlaneBufferGeometry;
  7534. /**
  7535. * @author mrdoob / http://mrdoob.com/
  7536. * @author alteredq / http://alteredqualia.com/
  7537. */
  7538. var materialId = 0;
  7539. function Material() {
  7540. Object.defineProperty( this, 'id', { value: materialId ++ } );
  7541. this.uuid = _Math.generateUUID();
  7542. this.name = '';
  7543. this.type = 'Material';
  7544. this.fog = true;
  7545. this.lights = true;
  7546. this.blending = NormalBlending;
  7547. this.side = FrontSide;
  7548. this.flatShading = false;
  7549. this.vertexTangents = false;
  7550. this.vertexColors = NoColors; // THREE.NoColors, THREE.VertexColors, THREE.FaceColors
  7551. this.opacity = 1;
  7552. this.transparent = false;
  7553. this.blendSrc = SrcAlphaFactor;
  7554. this.blendDst = OneMinusSrcAlphaFactor;
  7555. this.blendEquation = AddEquation;
  7556. this.blendSrcAlpha = null;
  7557. this.blendDstAlpha = null;
  7558. this.blendEquationAlpha = null;
  7559. this.depthFunc = LessEqualDepth;
  7560. this.depthTest = true;
  7561. this.depthWrite = true;
  7562. this.clippingPlanes = null;
  7563. this.clipIntersection = false;
  7564. this.clipShadows = false;
  7565. this.shadowSide = null;
  7566. this.colorWrite = true;
  7567. this.precision = null; // override the renderer's default precision for this material
  7568. this.polygonOffset = false;
  7569. this.polygonOffsetFactor = 0;
  7570. this.polygonOffsetUnits = 0;
  7571. this.dithering = false;
  7572. this.alphaTest = 0;
  7573. this.premultipliedAlpha = false;
  7574. this.visible = true;
  7575. this.userData = {};
  7576. this.needsUpdate = true;
  7577. }
  7578. Material.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  7579. constructor: Material,
  7580. isMaterial: true,
  7581. onBeforeCompile: function () {},
  7582. setValues: function ( values ) {
  7583. if ( values === undefined ) return;
  7584. for ( var key in values ) {
  7585. var newValue = values[ key ];
  7586. if ( newValue === undefined ) {
  7587. console.warn( "THREE.Material: '" + key + "' parameter is undefined." );
  7588. continue;
  7589. }
  7590. // for backward compatability if shading is set in the constructor
  7591. if ( key === 'shading' ) {
  7592. console.warn( 'THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.' );
  7593. this.flatShading = ( newValue === FlatShading ) ? true : false;
  7594. continue;
  7595. }
  7596. var currentValue = this[ key ];
  7597. if ( currentValue === undefined ) {
  7598. console.warn( "THREE." + this.type + ": '" + key + "' is not a property of this material." );
  7599. continue;
  7600. }
  7601. if ( currentValue && currentValue.isColor ) {
  7602. currentValue.set( newValue );
  7603. } else if ( ( currentValue && currentValue.isVector3 ) && ( newValue && newValue.isVector3 ) ) {
  7604. currentValue.copy( newValue );
  7605. } else {
  7606. this[ key ] = newValue;
  7607. }
  7608. }
  7609. },
  7610. toJSON: function ( meta ) {
  7611. var isRoot = ( meta === undefined || typeof meta === 'string' );
  7612. if ( isRoot ) {
  7613. meta = {
  7614. textures: {},
  7615. images: {}
  7616. };
  7617. }
  7618. var data = {
  7619. metadata: {
  7620. version: 4.5,
  7621. type: 'Material',
  7622. generator: 'Material.toJSON'
  7623. }
  7624. };
  7625. // standard Material serialization
  7626. data.uuid = this.uuid;
  7627. data.type = this.type;
  7628. if ( this.name !== '' ) data.name = this.name;
  7629. if ( this.color && this.color.isColor ) data.color = this.color.getHex();
  7630. if ( this.roughness !== undefined ) data.roughness = this.roughness;
  7631. if ( this.metalness !== undefined ) data.metalness = this.metalness;
  7632. if ( this.emissive && this.emissive.isColor ) data.emissive = this.emissive.getHex();
  7633. if ( this.emissiveIntensity !== 1 ) data.emissiveIntensity = this.emissiveIntensity;
  7634. if ( this.specular && this.specular.isColor ) data.specular = this.specular.getHex();
  7635. if ( this.shininess !== undefined ) data.shininess = this.shininess;
  7636. if ( this.clearCoat !== undefined ) data.clearCoat = this.clearCoat;
  7637. if ( this.clearCoatRoughness !== undefined ) data.clearCoatRoughness = this.clearCoatRoughness;
  7638. if ( this.map && this.map.isTexture ) data.map = this.map.toJSON( meta ).uuid;
  7639. if ( this.matcap && this.matcap.isTexture ) data.matcap = this.matcap.toJSON( meta ).uuid;
  7640. if ( this.alphaMap && this.alphaMap.isTexture ) data.alphaMap = this.alphaMap.toJSON( meta ).uuid;
  7641. if ( this.lightMap && this.lightMap.isTexture ) data.lightMap = this.lightMap.toJSON( meta ).uuid;
  7642. if ( this.aoMap && this.aoMap.isTexture ) {
  7643. data.aoMap = this.aoMap.toJSON( meta ).uuid;
  7644. data.aoMapIntensity = this.aoMapIntensity;
  7645. }
  7646. if ( this.bumpMap && this.bumpMap.isTexture ) {
  7647. data.bumpMap = this.bumpMap.toJSON( meta ).uuid;
  7648. data.bumpScale = this.bumpScale;
  7649. }
  7650. if ( this.normalMap && this.normalMap.isTexture ) {
  7651. data.normalMap = this.normalMap.toJSON( meta ).uuid;
  7652. data.normalMapType = this.normalMapType;
  7653. data.normalScale = this.normalScale.toArray();
  7654. }
  7655. if ( this.displacementMap && this.displacementMap.isTexture ) {
  7656. data.displacementMap = this.displacementMap.toJSON( meta ).uuid;
  7657. data.displacementScale = this.displacementScale;
  7658. data.displacementBias = this.displacementBias;
  7659. }
  7660. if ( this.roughnessMap && this.roughnessMap.isTexture ) data.roughnessMap = this.roughnessMap.toJSON( meta ).uuid;
  7661. if ( this.metalnessMap && this.metalnessMap.isTexture ) data.metalnessMap = this.metalnessMap.toJSON( meta ).uuid;
  7662. if ( this.emissiveMap && this.emissiveMap.isTexture ) data.emissiveMap = this.emissiveMap.toJSON( meta ).uuid;
  7663. if ( this.specularMap && this.specularMap.isTexture ) data.specularMap = this.specularMap.toJSON( meta ).uuid;
  7664. if ( this.envMap && this.envMap.isTexture ) {
  7665. data.envMap = this.envMap.toJSON( meta ).uuid;
  7666. data.reflectivity = this.reflectivity; // Scale behind envMap
  7667. if ( this.combine !== undefined ) data.combine = this.combine;
  7668. if ( this.envMapIntensity !== undefined ) data.envMapIntensity = this.envMapIntensity;
  7669. }
  7670. if ( this.gradientMap && this.gradientMap.isTexture ) {
  7671. data.gradientMap = this.gradientMap.toJSON( meta ).uuid;
  7672. }
  7673. if ( this.size !== undefined ) data.size = this.size;
  7674. if ( this.sizeAttenuation !== undefined ) data.sizeAttenuation = this.sizeAttenuation;
  7675. if ( this.blending !== NormalBlending ) data.blending = this.blending;
  7676. if ( this.flatShading === true ) data.flatShading = this.flatShading;
  7677. if ( this.side !== FrontSide ) data.side = this.side;
  7678. if ( this.vertexColors !== NoColors ) data.vertexColors = this.vertexColors;
  7679. if ( this.opacity < 1 ) data.opacity = this.opacity;
  7680. if ( this.transparent === true ) data.transparent = this.transparent;
  7681. data.depthFunc = this.depthFunc;
  7682. data.depthTest = this.depthTest;
  7683. data.depthWrite = this.depthWrite;
  7684. // rotation (SpriteMaterial)
  7685. if ( this.rotation !== 0 ) data.rotation = this.rotation;
  7686. if ( this.polygonOffset === true ) data.polygonOffset = true;
  7687. if ( this.polygonOffsetFactor !== 0 ) data.polygonOffsetFactor = this.polygonOffsetFactor;
  7688. if ( this.polygonOffsetUnits !== 0 ) data.polygonOffsetUnits = this.polygonOffsetUnits;
  7689. if ( this.linewidth !== 1 ) data.linewidth = this.linewidth;
  7690. if ( this.dashSize !== undefined ) data.dashSize = this.dashSize;
  7691. if ( this.gapSize !== undefined ) data.gapSize = this.gapSize;
  7692. if ( this.scale !== undefined ) data.scale = this.scale;
  7693. if ( this.dithering === true ) data.dithering = true;
  7694. if ( this.alphaTest > 0 ) data.alphaTest = this.alphaTest;
  7695. if ( this.premultipliedAlpha === true ) data.premultipliedAlpha = this.premultipliedAlpha;
  7696. if ( this.wireframe === true ) data.wireframe = this.wireframe;
  7697. if ( this.wireframeLinewidth > 1 ) data.wireframeLinewidth = this.wireframeLinewidth;
  7698. if ( this.wireframeLinecap !== 'round' ) data.wireframeLinecap = this.wireframeLinecap;
  7699. if ( this.wireframeLinejoin !== 'round' ) data.wireframeLinejoin = this.wireframeLinejoin;
  7700. if ( this.morphTargets === true ) data.morphTargets = true;
  7701. if ( this.skinning === true ) data.skinning = true;
  7702. if ( this.visible === false ) data.visible = false;
  7703. if ( JSON.stringify( this.userData ) !== '{}' ) data.userData = this.userData;
  7704. // TODO: Copied from Object3D.toJSON
  7705. function extractFromCache( cache ) {
  7706. var values = [];
  7707. for ( var key in cache ) {
  7708. var data = cache[ key ];
  7709. delete data.metadata;
  7710. values.push( data );
  7711. }
  7712. return values;
  7713. }
  7714. if ( isRoot ) {
  7715. var textures = extractFromCache( meta.textures );
  7716. var images = extractFromCache( meta.images );
  7717. if ( textures.length > 0 ) data.textures = textures;
  7718. if ( images.length > 0 ) data.images = images;
  7719. }
  7720. return data;
  7721. },
  7722. clone: function () {
  7723. return new this.constructor().copy( this );
  7724. },
  7725. copy: function ( source ) {
  7726. this.name = source.name;
  7727. this.fog = source.fog;
  7728. this.lights = source.lights;
  7729. this.blending = source.blending;
  7730. this.side = source.side;
  7731. this.flatShading = source.flatShading;
  7732. this.vertexColors = source.vertexColors;
  7733. this.opacity = source.opacity;
  7734. this.transparent = source.transparent;
  7735. this.blendSrc = source.blendSrc;
  7736. this.blendDst = source.blendDst;
  7737. this.blendEquation = source.blendEquation;
  7738. this.blendSrcAlpha = source.blendSrcAlpha;
  7739. this.blendDstAlpha = source.blendDstAlpha;
  7740. this.blendEquationAlpha = source.blendEquationAlpha;
  7741. this.depthFunc = source.depthFunc;
  7742. this.depthTest = source.depthTest;
  7743. this.depthWrite = source.depthWrite;
  7744. this.colorWrite = source.colorWrite;
  7745. this.precision = source.precision;
  7746. this.polygonOffset = source.polygonOffset;
  7747. this.polygonOffsetFactor = source.polygonOffsetFactor;
  7748. this.polygonOffsetUnits = source.polygonOffsetUnits;
  7749. this.dithering = source.dithering;
  7750. this.alphaTest = source.alphaTest;
  7751. this.premultipliedAlpha = source.premultipliedAlpha;
  7752. this.visible = source.visible;
  7753. this.userData = JSON.parse( JSON.stringify( source.userData ) );
  7754. this.clipShadows = source.clipShadows;
  7755. this.clipIntersection = source.clipIntersection;
  7756. var srcPlanes = source.clippingPlanes,
  7757. dstPlanes = null;
  7758. if ( srcPlanes !== null ) {
  7759. var n = srcPlanes.length;
  7760. dstPlanes = new Array( n );
  7761. for ( var i = 0; i !== n; ++ i )
  7762. dstPlanes[ i ] = srcPlanes[ i ].clone();
  7763. }
  7764. this.clippingPlanes = dstPlanes;
  7765. this.shadowSide = source.shadowSide;
  7766. return this;
  7767. },
  7768. dispose: function () {
  7769. this.dispatchEvent( { type: 'dispose' } );
  7770. }
  7771. } );
  7772. var default_vertex = "void main() {\n\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}";
  7773. var default_fragment = "void main() {\n\tgl_FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );\n}";
  7774. /**
  7775. * @author alteredq / http://alteredqualia.com/
  7776. *
  7777. * parameters = {
  7778. * defines: { "label" : "value" },
  7779. * uniforms: { "parameter1": { value: 1.0 }, "parameter2": { value2: 2 } },
  7780. *
  7781. * fragmentShader: <string>,
  7782. * vertexShader: <string>,
  7783. *
  7784. * wireframe: <boolean>,
  7785. * wireframeLinewidth: <float>,
  7786. *
  7787. * lights: <bool>,
  7788. *
  7789. * skinning: <bool>,
  7790. * morphTargets: <bool>,
  7791. * morphNormals: <bool>
  7792. * }
  7793. */
  7794. function ShaderMaterial( parameters ) {
  7795. Material.call( this );
  7796. this.type = 'ShaderMaterial';
  7797. this.defines = {};
  7798. this.uniforms = {};
  7799. this.vertexShader = default_vertex;
  7800. this.fragmentShader = default_fragment;
  7801. this.linewidth = 1;
  7802. this.wireframe = false;
  7803. this.wireframeLinewidth = 1;
  7804. this.fog = false; // set to use scene fog
  7805. this.lights = false; // set to use scene lights
  7806. this.clipping = false; // set to use user-defined clipping planes
  7807. this.skinning = false; // set to use skinning attribute streams
  7808. this.morphTargets = false; // set to use morph targets
  7809. this.morphNormals = false; // set to use morph normals
  7810. this.extensions = {
  7811. derivatives: false, // set to use derivatives
  7812. fragDepth: false, // set to use fragment depth values
  7813. drawBuffers: false, // set to use draw buffers
  7814. shaderTextureLOD: false // set to use shader texture LOD
  7815. };
  7816. // When rendered geometry doesn't include these attributes but the material does,
  7817. // use these default values in WebGL. This avoids errors when buffer data is missing.
  7818. this.defaultAttributeValues = {
  7819. 'color': [ 1, 1, 1 ],
  7820. 'uv': [ 0, 0 ],
  7821. 'uv2': [ 0, 0 ]
  7822. };
  7823. this.index0AttributeName = undefined;
  7824. this.uniformsNeedUpdate = false;
  7825. if ( parameters !== undefined ) {
  7826. if ( parameters.attributes !== undefined ) {
  7827. console.error( 'THREE.ShaderMaterial: attributes should now be defined in THREE.BufferGeometry instead.' );
  7828. }
  7829. this.setValues( parameters );
  7830. }
  7831. }
  7832. ShaderMaterial.prototype = Object.create( Material.prototype );
  7833. ShaderMaterial.prototype.constructor = ShaderMaterial;
  7834. ShaderMaterial.prototype.isShaderMaterial = true;
  7835. ShaderMaterial.prototype.copy = function ( source ) {
  7836. Material.prototype.copy.call( this, source );
  7837. this.fragmentShader = source.fragmentShader;
  7838. this.vertexShader = source.vertexShader;
  7839. this.uniforms = cloneUniforms( source.uniforms );
  7840. this.defines = Object.assign( {}, source.defines );
  7841. this.wireframe = source.wireframe;
  7842. this.wireframeLinewidth = source.wireframeLinewidth;
  7843. this.lights = source.lights;
  7844. this.clipping = source.clipping;
  7845. this.skinning = source.skinning;
  7846. this.morphTargets = source.morphTargets;
  7847. this.morphNormals = source.morphNormals;
  7848. this.extensions = source.extensions;
  7849. return this;
  7850. };
  7851. ShaderMaterial.prototype.toJSON = function ( meta ) {
  7852. var data = Material.prototype.toJSON.call( this, meta );
  7853. data.uniforms = {};
  7854. for ( var name in this.uniforms ) {
  7855. var uniform = this.uniforms[ name ];
  7856. var value = uniform.value;
  7857. if ( value && value.isTexture ) {
  7858. data.uniforms[ name ] = {
  7859. type: 't',
  7860. value: value.toJSON( meta ).uuid
  7861. };
  7862. } else if ( value && value.isColor ) {
  7863. data.uniforms[ name ] = {
  7864. type: 'c',
  7865. value: value.getHex()
  7866. };
  7867. } else if ( value && value.isVector2 ) {
  7868. data.uniforms[ name ] = {
  7869. type: 'v2',
  7870. value: value.toArray()
  7871. };
  7872. } else if ( value && value.isVector3 ) {
  7873. data.uniforms[ name ] = {
  7874. type: 'v3',
  7875. value: value.toArray()
  7876. };
  7877. } else if ( value && value.isVector4 ) {
  7878. data.uniforms[ name ] = {
  7879. type: 'v4',
  7880. value: value.toArray()
  7881. };
  7882. } else if ( value && value.isMatrix3 ) {
  7883. data.uniforms[ name ] = {
  7884. type: 'm3',
  7885. value: value.toArray()
  7886. };
  7887. } else if ( value && value.isMatrix4 ) {
  7888. data.uniforms[ name ] = {
  7889. type: 'm4',
  7890. value: value.toArray()
  7891. };
  7892. } else {
  7893. data.uniforms[ name ] = {
  7894. value: value
  7895. };
  7896. // note: the array variants v2v, v3v, v4v, m4v and tv are not supported so far
  7897. }
  7898. }
  7899. if ( Object.keys( this.defines ).length > 0 ) data.defines = this.defines;
  7900. data.vertexShader = this.vertexShader;
  7901. data.fragmentShader = this.fragmentShader;
  7902. var extensions = {};
  7903. for ( var key in this.extensions ) {
  7904. if ( this.extensions[ key ] === true ) extensions[ key ] = true;
  7905. }
  7906. if ( Object.keys( extensions ).length > 0 ) data.extensions = extensions;
  7907. return data;
  7908. };
  7909. /**
  7910. * @author bhouston / http://clara.io
  7911. */
  7912. function Ray( origin, direction ) {
  7913. this.origin = ( origin !== undefined ) ? origin : new Vector3();
  7914. this.direction = ( direction !== undefined ) ? direction : new Vector3();
  7915. }
  7916. Object.assign( Ray.prototype, {
  7917. set: function ( origin, direction ) {
  7918. this.origin.copy( origin );
  7919. this.direction.copy( direction );
  7920. return this;
  7921. },
  7922. clone: function () {
  7923. return new this.constructor().copy( this );
  7924. },
  7925. copy: function ( ray ) {
  7926. this.origin.copy( ray.origin );
  7927. this.direction.copy( ray.direction );
  7928. return this;
  7929. },
  7930. at: function ( t, target ) {
  7931. if ( target === undefined ) {
  7932. console.warn( 'THREE.Ray: .at() target is now required' );
  7933. target = new Vector3();
  7934. }
  7935. return target.copy( this.direction ).multiplyScalar( t ).add( this.origin );
  7936. },
  7937. lookAt: function ( v ) {
  7938. this.direction.copy( v ).sub( this.origin ).normalize();
  7939. return this;
  7940. },
  7941. recast: function () {
  7942. var v1 = new Vector3();
  7943. return function recast( t ) {
  7944. this.origin.copy( this.at( t, v1 ) );
  7945. return this;
  7946. };
  7947. }(),
  7948. closestPointToPoint: function ( point, target ) {
  7949. if ( target === undefined ) {
  7950. console.warn( 'THREE.Ray: .closestPointToPoint() target is now required' );
  7951. target = new Vector3();
  7952. }
  7953. target.subVectors( point, this.origin );
  7954. var directionDistance = target.dot( this.direction );
  7955. if ( directionDistance < 0 ) {
  7956. return target.copy( this.origin );
  7957. }
  7958. return target.copy( this.direction ).multiplyScalar( directionDistance ).add( this.origin );
  7959. },
  7960. distanceToPoint: function ( point ) {
  7961. return Math.sqrt( this.distanceSqToPoint( point ) );
  7962. },
  7963. distanceSqToPoint: function () {
  7964. var v1 = new Vector3();
  7965. return function distanceSqToPoint( point ) {
  7966. var directionDistance = v1.subVectors( point, this.origin ).dot( this.direction );
  7967. // point behind the ray
  7968. if ( directionDistance < 0 ) {
  7969. return this.origin.distanceToSquared( point );
  7970. }
  7971. v1.copy( this.direction ).multiplyScalar( directionDistance ).add( this.origin );
  7972. return v1.distanceToSquared( point );
  7973. };
  7974. }(),
  7975. distanceSqToSegment: function () {
  7976. var segCenter = new Vector3();
  7977. var segDir = new Vector3();
  7978. var diff = new Vector3();
  7979. return function distanceSqToSegment( v0, v1, optionalPointOnRay, optionalPointOnSegment ) {
  7980. // from http://www.geometrictools.com/GTEngine/Include/Mathematics/GteDistRaySegment.h
  7981. // It returns the min distance between the ray and the segment
  7982. // defined by v0 and v1
  7983. // It can also set two optional targets :
  7984. // - The closest point on the ray
  7985. // - The closest point on the segment
  7986. segCenter.copy( v0 ).add( v1 ).multiplyScalar( 0.5 );
  7987. segDir.copy( v1 ).sub( v0 ).normalize();
  7988. diff.copy( this.origin ).sub( segCenter );
  7989. var segExtent = v0.distanceTo( v1 ) * 0.5;
  7990. var a01 = - this.direction.dot( segDir );
  7991. var b0 = diff.dot( this.direction );
  7992. var b1 = - diff.dot( segDir );
  7993. var c = diff.lengthSq();
  7994. var det = Math.abs( 1 - a01 * a01 );
  7995. var s0, s1, sqrDist, extDet;
  7996. if ( det > 0 ) {
  7997. // The ray and segment are not parallel.
  7998. s0 = a01 * b1 - b0;
  7999. s1 = a01 * b0 - b1;
  8000. extDet = segExtent * det;
  8001. if ( s0 >= 0 ) {
  8002. if ( s1 >= - extDet ) {
  8003. if ( s1 <= extDet ) {
  8004. // region 0
  8005. // Minimum at interior points of ray and segment.
  8006. var invDet = 1 / det;
  8007. s0 *= invDet;
  8008. s1 *= invDet;
  8009. sqrDist = s0 * ( s0 + a01 * s1 + 2 * b0 ) + s1 * ( a01 * s0 + s1 + 2 * b1 ) + c;
  8010. } else {
  8011. // region 1
  8012. s1 = segExtent;
  8013. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  8014. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  8015. }
  8016. } else {
  8017. // region 5
  8018. s1 = - segExtent;
  8019. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  8020. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  8021. }
  8022. } else {
  8023. if ( s1 <= - extDet ) {
  8024. // region 4
  8025. s0 = Math.max( 0, - ( - a01 * segExtent + b0 ) );
  8026. s1 = ( s0 > 0 ) ? - segExtent : Math.min( Math.max( - segExtent, - b1 ), segExtent );
  8027. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  8028. } else if ( s1 <= extDet ) {
  8029. // region 3
  8030. s0 = 0;
  8031. s1 = Math.min( Math.max( - segExtent, - b1 ), segExtent );
  8032. sqrDist = s1 * ( s1 + 2 * b1 ) + c;
  8033. } else {
  8034. // region 2
  8035. s0 = Math.max( 0, - ( a01 * segExtent + b0 ) );
  8036. s1 = ( s0 > 0 ) ? segExtent : Math.min( Math.max( - segExtent, - b1 ), segExtent );
  8037. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  8038. }
  8039. }
  8040. } else {
  8041. // Ray and segment are parallel.
  8042. s1 = ( a01 > 0 ) ? - segExtent : segExtent;
  8043. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  8044. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  8045. }
  8046. if ( optionalPointOnRay ) {
  8047. optionalPointOnRay.copy( this.direction ).multiplyScalar( s0 ).add( this.origin );
  8048. }
  8049. if ( optionalPointOnSegment ) {
  8050. optionalPointOnSegment.copy( segDir ).multiplyScalar( s1 ).add( segCenter );
  8051. }
  8052. return sqrDist;
  8053. };
  8054. }(),
  8055. intersectSphere: function () {
  8056. var v1 = new Vector3();
  8057. return function intersectSphere( sphere, target ) {
  8058. v1.subVectors( sphere.center, this.origin );
  8059. var tca = v1.dot( this.direction );
  8060. var d2 = v1.dot( v1 ) - tca * tca;
  8061. var radius2 = sphere.radius * sphere.radius;
  8062. if ( d2 > radius2 ) return null;
  8063. var thc = Math.sqrt( radius2 - d2 );
  8064. // t0 = first intersect point - entrance on front of sphere
  8065. var t0 = tca - thc;
  8066. // t1 = second intersect point - exit point on back of sphere
  8067. var t1 = tca + thc;
  8068. // test to see if both t0 and t1 are behind the ray - if so, return null
  8069. if ( t0 < 0 && t1 < 0 ) return null;
  8070. // test to see if t0 is behind the ray:
  8071. // if it is, the ray is inside the sphere, so return the second exit point scaled by t1,
  8072. // in order to always return an intersect point that is in front of the ray.
  8073. if ( t0 < 0 ) return this.at( t1, target );
  8074. // else t0 is in front of the ray, so return the first collision point scaled by t0
  8075. return this.at( t0, target );
  8076. };
  8077. }(),
  8078. intersectsSphere: function ( sphere ) {
  8079. return this.distanceSqToPoint( sphere.center ) <= ( sphere.radius * sphere.radius );
  8080. },
  8081. distanceToPlane: function ( plane ) {
  8082. var denominator = plane.normal.dot( this.direction );
  8083. if ( denominator === 0 ) {
  8084. // line is coplanar, return origin
  8085. if ( plane.distanceToPoint( this.origin ) === 0 ) {
  8086. return 0;
  8087. }
  8088. // Null is preferable to undefined since undefined means.... it is undefined
  8089. return null;
  8090. }
  8091. var t = - ( this.origin.dot( plane.normal ) + plane.constant ) / denominator;
  8092. // Return if the ray never intersects the plane
  8093. return t >= 0 ? t : null;
  8094. },
  8095. intersectPlane: function ( plane, target ) {
  8096. var t = this.distanceToPlane( plane );
  8097. if ( t === null ) {
  8098. return null;
  8099. }
  8100. return this.at( t, target );
  8101. },
  8102. intersectsPlane: function ( plane ) {
  8103. // check if the ray lies on the plane first
  8104. var distToPoint = plane.distanceToPoint( this.origin );
  8105. if ( distToPoint === 0 ) {
  8106. return true;
  8107. }
  8108. var denominator = plane.normal.dot( this.direction );
  8109. if ( denominator * distToPoint < 0 ) {
  8110. return true;
  8111. }
  8112. // ray origin is behind the plane (and is pointing behind it)
  8113. return false;
  8114. },
  8115. intersectBox: function ( box, target ) {
  8116. var tmin, tmax, tymin, tymax, tzmin, tzmax;
  8117. var invdirx = 1 / this.direction.x,
  8118. invdiry = 1 / this.direction.y,
  8119. invdirz = 1 / this.direction.z;
  8120. var origin = this.origin;
  8121. if ( invdirx >= 0 ) {
  8122. tmin = ( box.min.x - origin.x ) * invdirx;
  8123. tmax = ( box.max.x - origin.x ) * invdirx;
  8124. } else {
  8125. tmin = ( box.max.x - origin.x ) * invdirx;
  8126. tmax = ( box.min.x - origin.x ) * invdirx;
  8127. }
  8128. if ( invdiry >= 0 ) {
  8129. tymin = ( box.min.y - origin.y ) * invdiry;
  8130. tymax = ( box.max.y - origin.y ) * invdiry;
  8131. } else {
  8132. tymin = ( box.max.y - origin.y ) * invdiry;
  8133. tymax = ( box.min.y - origin.y ) * invdiry;
  8134. }
  8135. if ( ( tmin > tymax ) || ( tymin > tmax ) ) return null;
  8136. // These lines also handle the case where tmin or tmax is NaN
  8137. // (result of 0 * Infinity). x !== x returns true if x is NaN
  8138. if ( tymin > tmin || tmin !== tmin ) tmin = tymin;
  8139. if ( tymax < tmax || tmax !== tmax ) tmax = tymax;
  8140. if ( invdirz >= 0 ) {
  8141. tzmin = ( box.min.z - origin.z ) * invdirz;
  8142. tzmax = ( box.max.z - origin.z ) * invdirz;
  8143. } else {
  8144. tzmin = ( box.max.z - origin.z ) * invdirz;
  8145. tzmax = ( box.min.z - origin.z ) * invdirz;
  8146. }
  8147. if ( ( tmin > tzmax ) || ( tzmin > tmax ) ) return null;
  8148. if ( tzmin > tmin || tmin !== tmin ) tmin = tzmin;
  8149. if ( tzmax < tmax || tmax !== tmax ) tmax = tzmax;
  8150. //return point closest to the ray (positive side)
  8151. if ( tmax < 0 ) return null;
  8152. return this.at( tmin >= 0 ? tmin : tmax, target );
  8153. },
  8154. intersectsBox: ( function () {
  8155. var v = new Vector3();
  8156. return function intersectsBox( box ) {
  8157. return this.intersectBox( box, v ) !== null;
  8158. };
  8159. } )(),
  8160. intersectTriangle: function () {
  8161. // Compute the offset origin, edges, and normal.
  8162. var diff = new Vector3();
  8163. var edge1 = new Vector3();
  8164. var edge2 = new Vector3();
  8165. var normal = new Vector3();
  8166. return function intersectTriangle( a, b, c, backfaceCulling, target ) {
  8167. // from http://www.geometrictools.com/GTEngine/Include/Mathematics/GteIntrRay3Triangle3.h
  8168. edge1.subVectors( b, a );
  8169. edge2.subVectors( c, a );
  8170. normal.crossVectors( edge1, edge2 );
  8171. // Solve Q + t*D = b1*E1 + b2*E2 (Q = kDiff, D = ray direction,
  8172. // E1 = kEdge1, E2 = kEdge2, N = Cross(E1,E2)) by
  8173. // |Dot(D,N)|*b1 = sign(Dot(D,N))*Dot(D,Cross(Q,E2))
  8174. // |Dot(D,N)|*b2 = sign(Dot(D,N))*Dot(D,Cross(E1,Q))
  8175. // |Dot(D,N)|*t = -sign(Dot(D,N))*Dot(Q,N)
  8176. var DdN = this.direction.dot( normal );
  8177. var sign;
  8178. if ( DdN > 0 ) {
  8179. if ( backfaceCulling ) return null;
  8180. sign = 1;
  8181. } else if ( DdN < 0 ) {
  8182. sign = - 1;
  8183. DdN = - DdN;
  8184. } else {
  8185. return null;
  8186. }
  8187. diff.subVectors( this.origin, a );
  8188. var DdQxE2 = sign * this.direction.dot( edge2.crossVectors( diff, edge2 ) );
  8189. // b1 < 0, no intersection
  8190. if ( DdQxE2 < 0 ) {
  8191. return null;
  8192. }
  8193. var DdE1xQ = sign * this.direction.dot( edge1.cross( diff ) );
  8194. // b2 < 0, no intersection
  8195. if ( DdE1xQ < 0 ) {
  8196. return null;
  8197. }
  8198. // b1+b2 > 1, no intersection
  8199. if ( DdQxE2 + DdE1xQ > DdN ) {
  8200. return null;
  8201. }
  8202. // Line intersects triangle, check if ray does.
  8203. var QdN = - sign * diff.dot( normal );
  8204. // t < 0, no intersection
  8205. if ( QdN < 0 ) {
  8206. return null;
  8207. }
  8208. // Ray intersects triangle.
  8209. return this.at( QdN / DdN, target );
  8210. };
  8211. }(),
  8212. applyMatrix4: function ( matrix4 ) {
  8213. this.origin.applyMatrix4( matrix4 );
  8214. this.direction.transformDirection( matrix4 );
  8215. return this;
  8216. },
  8217. equals: function ( ray ) {
  8218. return ray.origin.equals( this.origin ) && ray.direction.equals( this.direction );
  8219. }
  8220. } );
  8221. /**
  8222. * @author bhouston / http://clara.io
  8223. * @author mrdoob / http://mrdoob.com/
  8224. */
  8225. function Triangle( a, b, c ) {
  8226. this.a = ( a !== undefined ) ? a : new Vector3();
  8227. this.b = ( b !== undefined ) ? b : new Vector3();
  8228. this.c = ( c !== undefined ) ? c : new Vector3();
  8229. }
  8230. Object.assign( Triangle, {
  8231. getNormal: function () {
  8232. var v0 = new Vector3();
  8233. return function getNormal( a, b, c, target ) {
  8234. if ( target === undefined ) {
  8235. console.warn( 'THREE.Triangle: .getNormal() target is now required' );
  8236. target = new Vector3();
  8237. }
  8238. target.subVectors( c, b );
  8239. v0.subVectors( a, b );
  8240. target.cross( v0 );
  8241. var targetLengthSq = target.lengthSq();
  8242. if ( targetLengthSq > 0 ) {
  8243. return target.multiplyScalar( 1 / Math.sqrt( targetLengthSq ) );
  8244. }
  8245. return target.set( 0, 0, 0 );
  8246. };
  8247. }(),
  8248. // static/instance method to calculate barycentric coordinates
  8249. // based on: http://www.blackpawn.com/texts/pointinpoly/default.html
  8250. getBarycoord: function () {
  8251. var v0 = new Vector3();
  8252. var v1 = new Vector3();
  8253. var v2 = new Vector3();
  8254. return function getBarycoord( point, a, b, c, target ) {
  8255. v0.subVectors( c, a );
  8256. v1.subVectors( b, a );
  8257. v2.subVectors( point, a );
  8258. var dot00 = v0.dot( v0 );
  8259. var dot01 = v0.dot( v1 );
  8260. var dot02 = v0.dot( v2 );
  8261. var dot11 = v1.dot( v1 );
  8262. var dot12 = v1.dot( v2 );
  8263. var denom = ( dot00 * dot11 - dot01 * dot01 );
  8264. if ( target === undefined ) {
  8265. console.warn( 'THREE.Triangle: .getBarycoord() target is now required' );
  8266. target = new Vector3();
  8267. }
  8268. // collinear or singular triangle
  8269. if ( denom === 0 ) {
  8270. // arbitrary location outside of triangle?
  8271. // not sure if this is the best idea, maybe should be returning undefined
  8272. return target.set( - 2, - 1, - 1 );
  8273. }
  8274. var invDenom = 1 / denom;
  8275. var u = ( dot11 * dot02 - dot01 * dot12 ) * invDenom;
  8276. var v = ( dot00 * dot12 - dot01 * dot02 ) * invDenom;
  8277. // barycentric coordinates must always sum to 1
  8278. return target.set( 1 - u - v, v, u );
  8279. };
  8280. }(),
  8281. containsPoint: function () {
  8282. var v1 = new Vector3();
  8283. return function containsPoint( point, a, b, c ) {
  8284. Triangle.getBarycoord( point, a, b, c, v1 );
  8285. return ( v1.x >= 0 ) && ( v1.y >= 0 ) && ( ( v1.x + v1.y ) <= 1 );
  8286. };
  8287. }(),
  8288. getUV: function () {
  8289. var barycoord = new Vector3();
  8290. return function getUV( point, p1, p2, p3, uv1, uv2, uv3, target ) {
  8291. this.getBarycoord( point, p1, p2, p3, barycoord );
  8292. target.set( 0, 0 );
  8293. target.addScaledVector( uv1, barycoord.x );
  8294. target.addScaledVector( uv2, barycoord.y );
  8295. target.addScaledVector( uv3, barycoord.z );
  8296. return target;
  8297. };
  8298. }()
  8299. } );
  8300. Object.assign( Triangle.prototype, {
  8301. set: function ( a, b, c ) {
  8302. this.a.copy( a );
  8303. this.b.copy( b );
  8304. this.c.copy( c );
  8305. return this;
  8306. },
  8307. setFromPointsAndIndices: function ( points, i0, i1, i2 ) {
  8308. this.a.copy( points[ i0 ] );
  8309. this.b.copy( points[ i1 ] );
  8310. this.c.copy( points[ i2 ] );
  8311. return this;
  8312. },
  8313. clone: function () {
  8314. return new this.constructor().copy( this );
  8315. },
  8316. copy: function ( triangle ) {
  8317. this.a.copy( triangle.a );
  8318. this.b.copy( triangle.b );
  8319. this.c.copy( triangle.c );
  8320. return this;
  8321. },
  8322. getArea: function () {
  8323. var v0 = new Vector3();
  8324. var v1 = new Vector3();
  8325. return function getArea() {
  8326. v0.subVectors( this.c, this.b );
  8327. v1.subVectors( this.a, this.b );
  8328. return v0.cross( v1 ).length() * 0.5;
  8329. };
  8330. }(),
  8331. getMidpoint: function ( target ) {
  8332. if ( target === undefined ) {
  8333. console.warn( 'THREE.Triangle: .getMidpoint() target is now required' );
  8334. target = new Vector3();
  8335. }
  8336. return target.addVectors( this.a, this.b ).add( this.c ).multiplyScalar( 1 / 3 );
  8337. },
  8338. getNormal: function ( target ) {
  8339. return Triangle.getNormal( this.a, this.b, this.c, target );
  8340. },
  8341. getPlane: function ( target ) {
  8342. if ( target === undefined ) {
  8343. console.warn( 'THREE.Triangle: .getPlane() target is now required' );
  8344. target = new Vector3();
  8345. }
  8346. return target.setFromCoplanarPoints( this.a, this.b, this.c );
  8347. },
  8348. getBarycoord: function ( point, target ) {
  8349. return Triangle.getBarycoord( point, this.a, this.b, this.c, target );
  8350. },
  8351. containsPoint: function ( point ) {
  8352. return Triangle.containsPoint( point, this.a, this.b, this.c );
  8353. },
  8354. getUV: function ( point, uv1, uv2, uv3, result ) {
  8355. return Triangle.getUV( point, this.a, this.b, this.c, uv1, uv2, uv3, result );
  8356. },
  8357. intersectsBox: function ( box ) {
  8358. return box.intersectsTriangle( this );
  8359. },
  8360. closestPointToPoint: function () {
  8361. var vab = new Vector3();
  8362. var vac = new Vector3();
  8363. var vbc = new Vector3();
  8364. var vap = new Vector3();
  8365. var vbp = new Vector3();
  8366. var vcp = new Vector3();
  8367. return function closestPointToPoint( p, target ) {
  8368. if ( target === undefined ) {
  8369. console.warn( 'THREE.Triangle: .closestPointToPoint() target is now required' );
  8370. target = new Vector3();
  8371. }
  8372. var a = this.a, b = this.b, c = this.c;
  8373. var v, w;
  8374. // algorithm thanks to Real-Time Collision Detection by Christer Ericson,
  8375. // published by Morgan Kaufmann Publishers, (c) 2005 Elsevier Inc.,
  8376. // under the accompanying license; see chapter 5.1.5 for detailed explanation.
  8377. // basically, we're distinguishing which of the voronoi regions of the triangle
  8378. // the point lies in with the minimum amount of redundant computation.
  8379. vab.subVectors( b, a );
  8380. vac.subVectors( c, a );
  8381. vap.subVectors( p, a );
  8382. var d1 = vab.dot( vap );
  8383. var d2 = vac.dot( vap );
  8384. if ( d1 <= 0 && d2 <= 0 ) {
  8385. // vertex region of A; barycentric coords (1, 0, 0)
  8386. return target.copy( a );
  8387. }
  8388. vbp.subVectors( p, b );
  8389. var d3 = vab.dot( vbp );
  8390. var d4 = vac.dot( vbp );
  8391. if ( d3 >= 0 && d4 <= d3 ) {
  8392. // vertex region of B; barycentric coords (0, 1, 0)
  8393. return target.copy( b );
  8394. }
  8395. var vc = d1 * d4 - d3 * d2;
  8396. if ( vc <= 0 && d1 >= 0 && d3 <= 0 ) {
  8397. v = d1 / ( d1 - d3 );
  8398. // edge region of AB; barycentric coords (1-v, v, 0)
  8399. return target.copy( a ).addScaledVector( vab, v );
  8400. }
  8401. vcp.subVectors( p, c );
  8402. var d5 = vab.dot( vcp );
  8403. var d6 = vac.dot( vcp );
  8404. if ( d6 >= 0 && d5 <= d6 ) {
  8405. // vertex region of C; barycentric coords (0, 0, 1)
  8406. return target.copy( c );
  8407. }
  8408. var vb = d5 * d2 - d1 * d6;
  8409. if ( vb <= 0 && d2 >= 0 && d6 <= 0 ) {
  8410. w = d2 / ( d2 - d6 );
  8411. // edge region of AC; barycentric coords (1-w, 0, w)
  8412. return target.copy( a ).addScaledVector( vac, w );
  8413. }
  8414. var va = d3 * d6 - d5 * d4;
  8415. if ( va <= 0 && ( d4 - d3 ) >= 0 && ( d5 - d6 ) >= 0 ) {
  8416. vbc.subVectors( c, b );
  8417. w = ( d4 - d3 ) / ( ( d4 - d3 ) + ( d5 - d6 ) );
  8418. // edge region of BC; barycentric coords (0, 1-w, w)
  8419. return target.copy( b ).addScaledVector( vbc, w ); // edge region of BC
  8420. }
  8421. // face region
  8422. var denom = 1 / ( va + vb + vc );
  8423. // u = va * denom
  8424. v = vb * denom;
  8425. w = vc * denom;
  8426. return target.copy( a ).addScaledVector( vab, v ).addScaledVector( vac, w );
  8427. };
  8428. }(),
  8429. equals: function ( triangle ) {
  8430. return triangle.a.equals( this.a ) && triangle.b.equals( this.b ) && triangle.c.equals( this.c );
  8431. }
  8432. } );
  8433. /**
  8434. * @author mrdoob / http://mrdoob.com/
  8435. * @author alteredq / http://alteredqualia.com/
  8436. *
  8437. * parameters = {
  8438. * color: <hex>,
  8439. * opacity: <float>,
  8440. * map: new THREE.Texture( <Image> ),
  8441. *
  8442. * lightMap: new THREE.Texture( <Image> ),
  8443. * lightMapIntensity: <float>
  8444. *
  8445. * aoMap: new THREE.Texture( <Image> ),
  8446. * aoMapIntensity: <float>
  8447. *
  8448. * specularMap: new THREE.Texture( <Image> ),
  8449. *
  8450. * alphaMap: new THREE.Texture( <Image> ),
  8451. *
  8452. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  8453. * combine: THREE.Multiply,
  8454. * reflectivity: <float>,
  8455. * refractionRatio: <float>,
  8456. *
  8457. * depthTest: <bool>,
  8458. * depthWrite: <bool>,
  8459. *
  8460. * wireframe: <boolean>,
  8461. * wireframeLinewidth: <float>,
  8462. *
  8463. * skinning: <bool>,
  8464. * morphTargets: <bool>
  8465. * }
  8466. */
  8467. function MeshBasicMaterial( parameters ) {
  8468. Material.call( this );
  8469. this.type = 'MeshBasicMaterial';
  8470. this.color = new Color( 0xffffff ); // emissive
  8471. this.map = null;
  8472. this.lightMap = null;
  8473. this.lightMapIntensity = 1.0;
  8474. this.aoMap = null;
  8475. this.aoMapIntensity = 1.0;
  8476. this.specularMap = null;
  8477. this.alphaMap = null;
  8478. this.envMap = null;
  8479. this.combine = MultiplyOperation;
  8480. this.reflectivity = 1;
  8481. this.refractionRatio = 0.98;
  8482. this.wireframe = false;
  8483. this.wireframeLinewidth = 1;
  8484. this.wireframeLinecap = 'round';
  8485. this.wireframeLinejoin = 'round';
  8486. this.skinning = false;
  8487. this.morphTargets = false;
  8488. this.lights = false;
  8489. this.setValues( parameters );
  8490. }
  8491. MeshBasicMaterial.prototype = Object.create( Material.prototype );
  8492. MeshBasicMaterial.prototype.constructor = MeshBasicMaterial;
  8493. MeshBasicMaterial.prototype.isMeshBasicMaterial = true;
  8494. MeshBasicMaterial.prototype.copy = function ( source ) {
  8495. Material.prototype.copy.call( this, source );
  8496. this.color.copy( source.color );
  8497. this.map = source.map;
  8498. this.lightMap = source.lightMap;
  8499. this.lightMapIntensity = source.lightMapIntensity;
  8500. this.aoMap = source.aoMap;
  8501. this.aoMapIntensity = source.aoMapIntensity;
  8502. this.specularMap = source.specularMap;
  8503. this.alphaMap = source.alphaMap;
  8504. this.envMap = source.envMap;
  8505. this.combine = source.combine;
  8506. this.reflectivity = source.reflectivity;
  8507. this.refractionRatio = source.refractionRatio;
  8508. this.wireframe = source.wireframe;
  8509. this.wireframeLinewidth = source.wireframeLinewidth;
  8510. this.wireframeLinecap = source.wireframeLinecap;
  8511. this.wireframeLinejoin = source.wireframeLinejoin;
  8512. this.skinning = source.skinning;
  8513. this.morphTargets = source.morphTargets;
  8514. return this;
  8515. };
  8516. /**
  8517. * @author mrdoob / http://mrdoob.com/
  8518. * @author alteredq / http://alteredqualia.com/
  8519. * @author mikael emtinger / http://gomo.se/
  8520. * @author jonobr1 / http://jonobr1.com/
  8521. */
  8522. function Mesh( geometry, material ) {
  8523. Object3D.call( this );
  8524. this.type = 'Mesh';
  8525. this.geometry = geometry !== undefined ? geometry : new BufferGeometry();
  8526. this.material = material !== undefined ? material : new MeshBasicMaterial( { color: Math.random() * 0xffffff } );
  8527. this.drawMode = TrianglesDrawMode;
  8528. this.updateMorphTargets();
  8529. }
  8530. Mesh.prototype = Object.assign( Object.create( Object3D.prototype ), {
  8531. constructor: Mesh,
  8532. isMesh: true,
  8533. setDrawMode: function ( value ) {
  8534. this.drawMode = value;
  8535. },
  8536. copy: function ( source ) {
  8537. Object3D.prototype.copy.call( this, source );
  8538. this.drawMode = source.drawMode;
  8539. if ( source.morphTargetInfluences !== undefined ) {
  8540. this.morphTargetInfluences = source.morphTargetInfluences.slice();
  8541. }
  8542. if ( source.morphTargetDictionary !== undefined ) {
  8543. this.morphTargetDictionary = Object.assign( {}, source.morphTargetDictionary );
  8544. }
  8545. return this;
  8546. },
  8547. updateMorphTargets: function () {
  8548. var geometry = this.geometry;
  8549. var m, ml, name;
  8550. if ( geometry.isBufferGeometry ) {
  8551. var morphAttributes = geometry.morphAttributes;
  8552. var keys = Object.keys( morphAttributes );
  8553. if ( keys.length > 0 ) {
  8554. var morphAttribute = morphAttributes[ keys[ 0 ] ];
  8555. if ( morphAttribute !== undefined ) {
  8556. this.morphTargetInfluences = [];
  8557. this.morphTargetDictionary = {};
  8558. for ( m = 0, ml = morphAttribute.length; m < ml; m ++ ) {
  8559. name = morphAttribute[ m ].name || String( m );
  8560. this.morphTargetInfluences.push( 0 );
  8561. this.morphTargetDictionary[ name ] = m;
  8562. }
  8563. }
  8564. }
  8565. } else {
  8566. var morphTargets = geometry.morphTargets;
  8567. if ( morphTargets !== undefined && morphTargets.length > 0 ) {
  8568. console.error( 'THREE.Mesh.updateMorphTargets() no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.' );
  8569. }
  8570. }
  8571. },
  8572. raycast: ( function () {
  8573. var inverseMatrix = new Matrix4();
  8574. var ray = new Ray();
  8575. var sphere = new Sphere();
  8576. var vA = new Vector3();
  8577. var vB = new Vector3();
  8578. var vC = new Vector3();
  8579. var tempA = new Vector3();
  8580. var tempB = new Vector3();
  8581. var tempC = new Vector3();
  8582. var morphA = new Vector3();
  8583. var morphB = new Vector3();
  8584. var morphC = new Vector3();
  8585. var uvA = new Vector2();
  8586. var uvB = new Vector2();
  8587. var uvC = new Vector2();
  8588. var intersectionPoint = new Vector3();
  8589. var intersectionPointWorld = new Vector3();
  8590. function checkIntersection( object, material, raycaster, ray, pA, pB, pC, point ) {
  8591. var intersect;
  8592. if ( material.side === BackSide ) {
  8593. intersect = ray.intersectTriangle( pC, pB, pA, true, point );
  8594. } else {
  8595. intersect = ray.intersectTriangle( pA, pB, pC, material.side !== DoubleSide, point );
  8596. }
  8597. if ( intersect === null ) return null;
  8598. intersectionPointWorld.copy( point );
  8599. intersectionPointWorld.applyMatrix4( object.matrixWorld );
  8600. var distance = raycaster.ray.origin.distanceTo( intersectionPointWorld );
  8601. if ( distance < raycaster.near || distance > raycaster.far ) return null;
  8602. return {
  8603. distance: distance,
  8604. point: intersectionPointWorld.clone(),
  8605. object: object
  8606. };
  8607. }
  8608. function checkBufferGeometryIntersection( object, material, raycaster, ray, position, morphPosition, uv, a, b, c ) {
  8609. vA.fromBufferAttribute( position, a );
  8610. vB.fromBufferAttribute( position, b );
  8611. vC.fromBufferAttribute( position, c );
  8612. var morphInfluences = object.morphTargetInfluences;
  8613. if ( material.morphTargets && morphPosition && morphInfluences ) {
  8614. morphA.set( 0, 0, 0 );
  8615. morphB.set( 0, 0, 0 );
  8616. morphC.set( 0, 0, 0 );
  8617. for ( var i = 0, il = morphPosition.length; i < il; i ++ ) {
  8618. var influence = morphInfluences[ i ];
  8619. var morphAttribute = morphPosition[ i ];
  8620. if ( influence === 0 ) continue;
  8621. tempA.fromBufferAttribute( morphAttribute, a );
  8622. tempB.fromBufferAttribute( morphAttribute, b );
  8623. tempC.fromBufferAttribute( morphAttribute, c );
  8624. morphA.addScaledVector( tempA.sub( vA ), influence );
  8625. morphB.addScaledVector( tempB.sub( vB ), influence );
  8626. morphC.addScaledVector( tempC.sub( vC ), influence );
  8627. }
  8628. vA.add( morphA );
  8629. vB.add( morphB );
  8630. vC.add( morphC );
  8631. }
  8632. var intersection = checkIntersection( object, material, raycaster, ray, vA, vB, vC, intersectionPoint );
  8633. if ( intersection ) {
  8634. if ( uv ) {
  8635. uvA.fromBufferAttribute( uv, a );
  8636. uvB.fromBufferAttribute( uv, b );
  8637. uvC.fromBufferAttribute( uv, c );
  8638. intersection.uv = Triangle.getUV( intersectionPoint, vA, vB, vC, uvA, uvB, uvC, new Vector2() );
  8639. }
  8640. var face = new Face3( a, b, c );
  8641. Triangle.getNormal( vA, vB, vC, face.normal );
  8642. intersection.face = face;
  8643. }
  8644. return intersection;
  8645. }
  8646. return function raycast( raycaster, intersects ) {
  8647. var geometry = this.geometry;
  8648. var material = this.material;
  8649. var matrixWorld = this.matrixWorld;
  8650. if ( material === undefined ) return;
  8651. // Checking boundingSphere distance to ray
  8652. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  8653. sphere.copy( geometry.boundingSphere );
  8654. sphere.applyMatrix4( matrixWorld );
  8655. if ( raycaster.ray.intersectsSphere( sphere ) === false ) return;
  8656. //
  8657. inverseMatrix.getInverse( matrixWorld );
  8658. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  8659. // Check boundingBox before continuing
  8660. if ( geometry.boundingBox !== null ) {
  8661. if ( ray.intersectsBox( geometry.boundingBox ) === false ) return;
  8662. }
  8663. var intersection;
  8664. if ( geometry.isBufferGeometry ) {
  8665. var a, b, c;
  8666. var index = geometry.index;
  8667. var position = geometry.attributes.position;
  8668. var morphPosition = geometry.morphAttributes.position;
  8669. var uv = geometry.attributes.uv;
  8670. var groups = geometry.groups;
  8671. var drawRange = geometry.drawRange;
  8672. var i, j, il, jl;
  8673. var group, groupMaterial;
  8674. var start, end;
  8675. if ( index !== null ) {
  8676. // indexed buffer geometry
  8677. if ( Array.isArray( material ) ) {
  8678. for ( i = 0, il = groups.length; i < il; i ++ ) {
  8679. group = groups[ i ];
  8680. groupMaterial = material[ group.materialIndex ];
  8681. start = Math.max( group.start, drawRange.start );
  8682. end = Math.min( ( group.start + group.count ), ( drawRange.start + drawRange.count ) );
  8683. for ( j = start, jl = end; j < jl; j += 3 ) {
  8684. a = index.getX( j );
  8685. b = index.getX( j + 1 );
  8686. c = index.getX( j + 2 );
  8687. intersection = checkBufferGeometryIntersection( this, groupMaterial, raycaster, ray, position, morphPosition, uv, a, b, c );
  8688. if ( intersection ) {
  8689. intersection.faceIndex = Math.floor( j / 3 ); // triangle number in indexed buffer semantics
  8690. intersection.face.materialIndex = group.materialIndex;
  8691. intersects.push( intersection );
  8692. }
  8693. }
  8694. }
  8695. } else {
  8696. start = Math.max( 0, drawRange.start );
  8697. end = Math.min( index.count, ( drawRange.start + drawRange.count ) );
  8698. for ( i = start, il = end; i < il; i += 3 ) {
  8699. a = index.getX( i );
  8700. b = index.getX( i + 1 );
  8701. c = index.getX( i + 2 );
  8702. intersection = checkBufferGeometryIntersection( this, material, raycaster, ray, position, morphPosition, uv, a, b, c );
  8703. if ( intersection ) {
  8704. intersection.faceIndex = Math.floor( i / 3 ); // triangle number in indexed buffer semantics
  8705. intersects.push( intersection );
  8706. }
  8707. }
  8708. }
  8709. } else if ( position !== undefined ) {
  8710. // non-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 = j;
  8719. b = j + 1;
  8720. c = 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 non-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( position.count, ( drawRange.start + drawRange.count ) );
  8732. for ( i = start, il = end; i < il; i += 3 ) {
  8733. a = i;
  8734. b = i + 1;
  8735. c = 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 non-indexed buffer semantics
  8739. intersects.push( intersection );
  8740. }
  8741. }
  8742. }
  8743. }
  8744. } else if ( geometry.isGeometry ) {
  8745. var fvA, fvB, fvC;
  8746. var isMultiMaterial = Array.isArray( material );
  8747. var vertices = geometry.vertices;
  8748. var faces = geometry.faces;
  8749. var uvs;
  8750. var faceVertexUvs = geometry.faceVertexUvs[ 0 ];
  8751. if ( faceVertexUvs.length > 0 ) uvs = faceVertexUvs;
  8752. for ( var f = 0, fl = faces.length; f < fl; f ++ ) {
  8753. var face = faces[ f ];
  8754. var faceMaterial = isMultiMaterial ? material[ face.materialIndex ] : material;
  8755. if ( faceMaterial === undefined ) continue;
  8756. fvA = vertices[ face.a ];
  8757. fvB = vertices[ face.b ];
  8758. fvC = vertices[ face.c ];
  8759. intersection = checkIntersection( this, faceMaterial, raycaster, ray, fvA, fvB, fvC, intersectionPoint );
  8760. if ( intersection ) {
  8761. if ( uvs && uvs[ f ] ) {
  8762. var uvs_f = uvs[ f ];
  8763. uvA.copy( uvs_f[ 0 ] );
  8764. uvB.copy( uvs_f[ 1 ] );
  8765. uvC.copy( uvs_f[ 2 ] );
  8766. intersection.uv = Triangle.getUV( intersectionPoint, fvA, fvB, fvC, uvA, uvB, uvC, new Vector2() );
  8767. }
  8768. intersection.face = face;
  8769. intersection.faceIndex = f;
  8770. intersects.push( intersection );
  8771. }
  8772. }
  8773. }
  8774. };
  8775. }() ),
  8776. clone: function () {
  8777. return new this.constructor( this.geometry, this.material ).copy( this );
  8778. }
  8779. } );
  8780. /**
  8781. * @author mrdoob / http://mrdoob.com/
  8782. */
  8783. function WebGLBackground( renderer, state, objects, premultipliedAlpha ) {
  8784. var clearColor = new Color( 0x000000 );
  8785. var clearAlpha = 0;
  8786. var planeMesh;
  8787. var boxMesh;
  8788. // Store the current background texture and its `version`
  8789. // so we can recompile the material accordingly.
  8790. var currentBackground = null;
  8791. var currentBackgroundVersion = 0;
  8792. function render( renderList, scene, camera, forceClear ) {
  8793. var background = scene.background;
  8794. // Ignore background in AR
  8795. // TODO: Reconsider this.
  8796. var vr = renderer.vr;
  8797. var session = vr.getSession && vr.getSession();
  8798. if ( session && session.environmentBlendMode === 'additive' ) {
  8799. background = null;
  8800. }
  8801. if ( background === null ) {
  8802. setClear( clearColor, clearAlpha );
  8803. currentBackground = null;
  8804. currentBackgroundVersion = 0;
  8805. } else if ( background && background.isColor ) {
  8806. setClear( background, 1 );
  8807. forceClear = true;
  8808. currentBackground = null;
  8809. currentBackgroundVersion = 0;
  8810. }
  8811. if ( renderer.autoClear || forceClear ) {
  8812. renderer.clear( renderer.autoClearColor, renderer.autoClearDepth, renderer.autoClearStencil );
  8813. }
  8814. if ( background && ( background.isCubeTexture || background.isWebGLRenderTargetCube ) ) {
  8815. if ( boxMesh === undefined ) {
  8816. boxMesh = new Mesh(
  8817. new BoxBufferGeometry( 1, 1, 1 ),
  8818. new ShaderMaterial( {
  8819. type: 'BackgroundCubeMaterial',
  8820. uniforms: cloneUniforms( ShaderLib.cube.uniforms ),
  8821. vertexShader: ShaderLib.cube.vertexShader,
  8822. fragmentShader: ShaderLib.cube.fragmentShader,
  8823. side: BackSide,
  8824. depthTest: false,
  8825. depthWrite: false,
  8826. fog: false
  8827. } )
  8828. );
  8829. boxMesh.geometry.removeAttribute( 'normal' );
  8830. boxMesh.geometry.removeAttribute( 'uv' );
  8831. boxMesh.onBeforeRender = function ( renderer, scene, camera ) {
  8832. this.matrixWorld.copyPosition( camera.matrixWorld );
  8833. };
  8834. // enable code injection for non-built-in material
  8835. Object.defineProperty( boxMesh.material, 'map', {
  8836. get: function () {
  8837. return this.uniforms.tCube.value;
  8838. }
  8839. } );
  8840. objects.update( boxMesh );
  8841. }
  8842. var texture = background.isWebGLRenderTargetCube ? background.texture : background;
  8843. boxMesh.material.uniforms.tCube.value = texture;
  8844. boxMesh.material.uniforms.tFlip.value = ( background.isWebGLRenderTargetCube ) ? 1 : - 1;
  8845. if ( currentBackground !== background ||
  8846. currentBackgroundVersion !== texture.version ) {
  8847. boxMesh.material.needsUpdate = true;
  8848. currentBackground = background;
  8849. currentBackgroundVersion = texture.version;
  8850. }
  8851. // push to the pre-sorted opaque render list
  8852. renderList.unshift( boxMesh, boxMesh.geometry, boxMesh.material, 0, 0, null );
  8853. } else if ( background && background.isTexture ) {
  8854. if ( planeMesh === undefined ) {
  8855. planeMesh = new Mesh(
  8856. new PlaneBufferGeometry( 2, 2 ),
  8857. new ShaderMaterial( {
  8858. type: 'BackgroundMaterial',
  8859. uniforms: cloneUniforms( ShaderLib.background.uniforms ),
  8860. vertexShader: ShaderLib.background.vertexShader,
  8861. fragmentShader: ShaderLib.background.fragmentShader,
  8862. side: FrontSide,
  8863. depthTest: false,
  8864. depthWrite: false,
  8865. fog: false
  8866. } )
  8867. );
  8868. planeMesh.geometry.removeAttribute( 'normal' );
  8869. // enable code injection for non-built-in material
  8870. Object.defineProperty( planeMesh.material, 'map', {
  8871. get: function () {
  8872. return this.uniforms.t2D.value;
  8873. }
  8874. } );
  8875. objects.update( planeMesh );
  8876. }
  8877. planeMesh.material.uniforms.t2D.value = background;
  8878. if ( background.matrixAutoUpdate === true ) {
  8879. background.updateMatrix();
  8880. }
  8881. planeMesh.material.uniforms.uvTransform.value.copy( background.matrix );
  8882. if ( currentBackground !== background ||
  8883. currentBackgroundVersion !== background.version ) {
  8884. planeMesh.material.needsUpdate = true;
  8885. currentBackground = background;
  8886. currentBackgroundVersion = background.version;
  8887. }
  8888. // push to the pre-sorted opaque render list
  8889. renderList.unshift( planeMesh, planeMesh.geometry, planeMesh.material, 0, 0, null );
  8890. }
  8891. }
  8892. function setClear( color, alpha ) {
  8893. state.buffers.color.setClear( color.r, color.g, color.b, alpha, premultipliedAlpha );
  8894. }
  8895. return {
  8896. getClearColor: function () {
  8897. return clearColor;
  8898. },
  8899. setClearColor: function ( color, alpha ) {
  8900. clearColor.set( color );
  8901. clearAlpha = alpha !== undefined ? alpha : 1;
  8902. setClear( clearColor, clearAlpha );
  8903. },
  8904. getClearAlpha: function () {
  8905. return clearAlpha;
  8906. },
  8907. setClearAlpha: function ( alpha ) {
  8908. clearAlpha = alpha;
  8909. setClear( clearColor, clearAlpha );
  8910. },
  8911. render: render
  8912. };
  8913. }
  8914. /**
  8915. * @author mrdoob / http://mrdoob.com/
  8916. */
  8917. function WebGLBufferRenderer( gl, extensions, info, capabilities ) {
  8918. var mode;
  8919. function setMode( value ) {
  8920. mode = value;
  8921. }
  8922. function render( start, count ) {
  8923. gl.drawArrays( mode, start, count );
  8924. info.update( count, mode );
  8925. }
  8926. function renderInstances( geometry, start, count ) {
  8927. var extension;
  8928. if ( capabilities.isWebGL2 ) {
  8929. extension = gl;
  8930. } else {
  8931. extension = extensions.get( 'ANGLE_instanced_arrays' );
  8932. if ( extension === null ) {
  8933. console.error( 'THREE.WebGLBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  8934. return;
  8935. }
  8936. }
  8937. extension[ capabilities.isWebGL2 ? 'drawArraysInstanced' : 'drawArraysInstancedANGLE' ]( mode, start, count, geometry.maxInstancedCount );
  8938. info.update( count, mode, geometry.maxInstancedCount );
  8939. }
  8940. //
  8941. this.setMode = setMode;
  8942. this.render = render;
  8943. this.renderInstances = renderInstances;
  8944. }
  8945. /**
  8946. * @author mrdoob / http://mrdoob.com/
  8947. */
  8948. function WebGLCapabilities( gl, extensions, parameters ) {
  8949. var maxAnisotropy;
  8950. function getMaxAnisotropy() {
  8951. if ( maxAnisotropy !== undefined ) return maxAnisotropy;
  8952. var extension = extensions.get( 'EXT_texture_filter_anisotropic' );
  8953. if ( extension !== null ) {
  8954. maxAnisotropy = gl.getParameter( extension.MAX_TEXTURE_MAX_ANISOTROPY_EXT );
  8955. } else {
  8956. maxAnisotropy = 0;
  8957. }
  8958. return maxAnisotropy;
  8959. }
  8960. function getMaxPrecision( precision ) {
  8961. if ( precision === 'highp' ) {
  8962. if ( gl.getShaderPrecisionFormat( 35633, 36338 ).precision > 0 &&
  8963. gl.getShaderPrecisionFormat( 35632, 36338 ).precision > 0 ) {
  8964. return 'highp';
  8965. }
  8966. precision = 'mediump';
  8967. }
  8968. if ( precision === 'mediump' ) {
  8969. if ( gl.getShaderPrecisionFormat( 35633, 36337 ).precision > 0 &&
  8970. gl.getShaderPrecisionFormat( 35632, 36337 ).precision > 0 ) {
  8971. return 'mediump';
  8972. }
  8973. }
  8974. return 'lowp';
  8975. }
  8976. var isWebGL2 = typeof WebGL2RenderingContext !== 'undefined' && gl instanceof WebGL2RenderingContext;
  8977. var precision = parameters.precision !== undefined ? parameters.precision : 'highp';
  8978. var maxPrecision = getMaxPrecision( precision );
  8979. if ( maxPrecision !== precision ) {
  8980. console.warn( 'THREE.WebGLRenderer:', precision, 'not supported, using', maxPrecision, 'instead.' );
  8981. precision = maxPrecision;
  8982. }
  8983. var logarithmicDepthBuffer = parameters.logarithmicDepthBuffer === true;
  8984. var maxTextures = gl.getParameter( 34930 );
  8985. var maxVertexTextures = gl.getParameter( 35660 );
  8986. var maxTextureSize = gl.getParameter( 3379 );
  8987. var maxCubemapSize = gl.getParameter( 34076 );
  8988. var maxAttributes = gl.getParameter( 34921 );
  8989. var maxVertexUniforms = gl.getParameter( 36347 );
  8990. var maxVaryings = gl.getParameter( 36348 );
  8991. var maxFragmentUniforms = gl.getParameter( 36349 );
  8992. var vertexTextures = maxVertexTextures > 0;
  8993. var floatFragmentTextures = isWebGL2 || !! extensions.get( 'OES_texture_float' );
  8994. var floatVertexTextures = vertexTextures && floatFragmentTextures;
  8995. var maxSamples = isWebGL2 ? gl.getParameter( 36183 ) : 0;
  8996. return {
  8997. isWebGL2: isWebGL2,
  8998. getMaxAnisotropy: getMaxAnisotropy,
  8999. getMaxPrecision: getMaxPrecision,
  9000. precision: precision,
  9001. logarithmicDepthBuffer: logarithmicDepthBuffer,
  9002. maxTextures: maxTextures,
  9003. maxVertexTextures: maxVertexTextures,
  9004. maxTextureSize: maxTextureSize,
  9005. maxCubemapSize: maxCubemapSize,
  9006. maxAttributes: maxAttributes,
  9007. maxVertexUniforms: maxVertexUniforms,
  9008. maxVaryings: maxVaryings,
  9009. maxFragmentUniforms: maxFragmentUniforms,
  9010. vertexTextures: vertexTextures,
  9011. floatFragmentTextures: floatFragmentTextures,
  9012. floatVertexTextures: floatVertexTextures,
  9013. maxSamples: maxSamples
  9014. };
  9015. }
  9016. /**
  9017. * @author tschw
  9018. */
  9019. function WebGLClipping() {
  9020. var scope = this,
  9021. globalState = null,
  9022. numGlobalPlanes = 0,
  9023. localClippingEnabled = false,
  9024. renderingShadows = false,
  9025. plane = new Plane(),
  9026. viewNormalMatrix = new Matrix3(),
  9027. uniform = { value: null, needsUpdate: false };
  9028. this.uniform = uniform;
  9029. this.numPlanes = 0;
  9030. this.numIntersection = 0;
  9031. this.init = function ( planes, enableLocalClipping, camera ) {
  9032. var enabled =
  9033. planes.length !== 0 ||
  9034. enableLocalClipping ||
  9035. // enable state of previous frame - the clipping code has to
  9036. // run another frame in order to reset the state:
  9037. numGlobalPlanes !== 0 ||
  9038. localClippingEnabled;
  9039. localClippingEnabled = enableLocalClipping;
  9040. globalState = projectPlanes( planes, camera, 0 );
  9041. numGlobalPlanes = planes.length;
  9042. return enabled;
  9043. };
  9044. this.beginShadows = function () {
  9045. renderingShadows = true;
  9046. projectPlanes( null );
  9047. };
  9048. this.endShadows = function () {
  9049. renderingShadows = false;
  9050. resetGlobalState();
  9051. };
  9052. this.setState = function ( planes, clipIntersection, clipShadows, camera, cache, fromCache ) {
  9053. if ( ! localClippingEnabled || planes === null || planes.length === 0 || renderingShadows && ! clipShadows ) {
  9054. // there's no local clipping
  9055. if ( renderingShadows ) {
  9056. // there's no global clipping
  9057. projectPlanes( null );
  9058. } else {
  9059. resetGlobalState();
  9060. }
  9061. } else {
  9062. var nGlobal = renderingShadows ? 0 : numGlobalPlanes,
  9063. lGlobal = nGlobal * 4,
  9064. dstArray = cache.clippingState || null;
  9065. uniform.value = dstArray; // ensure unique state
  9066. dstArray = projectPlanes( planes, camera, lGlobal, fromCache );
  9067. for ( var i = 0; i !== lGlobal; ++ i ) {
  9068. dstArray[ i ] = globalState[ i ];
  9069. }
  9070. cache.clippingState = dstArray;
  9071. this.numIntersection = clipIntersection ? this.numPlanes : 0;
  9072. this.numPlanes += nGlobal;
  9073. }
  9074. };
  9075. function resetGlobalState() {
  9076. if ( uniform.value !== globalState ) {
  9077. uniform.value = globalState;
  9078. uniform.needsUpdate = numGlobalPlanes > 0;
  9079. }
  9080. scope.numPlanes = numGlobalPlanes;
  9081. scope.numIntersection = 0;
  9082. }
  9083. function projectPlanes( planes, camera, dstOffset, skipTransform ) {
  9084. var nPlanes = planes !== null ? planes.length : 0,
  9085. dstArray = null;
  9086. if ( nPlanes !== 0 ) {
  9087. dstArray = uniform.value;
  9088. if ( skipTransform !== true || dstArray === null ) {
  9089. var flatSize = dstOffset + nPlanes * 4,
  9090. viewMatrix = camera.matrixWorldInverse;
  9091. viewNormalMatrix.getNormalMatrix( viewMatrix );
  9092. if ( dstArray === null || dstArray.length < flatSize ) {
  9093. dstArray = new Float32Array( flatSize );
  9094. }
  9095. for ( var i = 0, i4 = dstOffset; i !== nPlanes; ++ i, i4 += 4 ) {
  9096. plane.copy( planes[ i ] ).applyMatrix4( viewMatrix, viewNormalMatrix );
  9097. plane.normal.toArray( dstArray, i4 );
  9098. dstArray[ i4 + 3 ] = plane.constant;
  9099. }
  9100. }
  9101. uniform.value = dstArray;
  9102. uniform.needsUpdate = true;
  9103. }
  9104. scope.numPlanes = nPlanes;
  9105. return dstArray;
  9106. }
  9107. }
  9108. /**
  9109. * @author mrdoob / http://mrdoob.com/
  9110. */
  9111. function WebGLExtensions( gl ) {
  9112. var extensions = {};
  9113. return {
  9114. get: function ( name ) {
  9115. if ( extensions[ name ] !== undefined ) {
  9116. return extensions[ name ];
  9117. }
  9118. var extension;
  9119. switch ( name ) {
  9120. case 'WEBGL_depth_texture':
  9121. extension = gl.getExtension( 'WEBGL_depth_texture' ) || gl.getExtension( 'MOZ_WEBGL_depth_texture' ) || gl.getExtension( 'WEBKIT_WEBGL_depth_texture' );
  9122. break;
  9123. case 'EXT_texture_filter_anisotropic':
  9124. extension = gl.getExtension( 'EXT_texture_filter_anisotropic' ) || gl.getExtension( 'MOZ_EXT_texture_filter_anisotropic' ) || gl.getExtension( 'WEBKIT_EXT_texture_filter_anisotropic' );
  9125. break;
  9126. case 'WEBGL_compressed_texture_s3tc':
  9127. extension = gl.getExtension( 'WEBGL_compressed_texture_s3tc' ) || gl.getExtension( 'MOZ_WEBGL_compressed_texture_s3tc' ) || gl.getExtension( 'WEBKIT_WEBGL_compressed_texture_s3tc' );
  9128. break;
  9129. case 'WEBGL_compressed_texture_pvrtc':
  9130. extension = gl.getExtension( 'WEBGL_compressed_texture_pvrtc' ) || gl.getExtension( 'WEBKIT_WEBGL_compressed_texture_pvrtc' );
  9131. break;
  9132. default:
  9133. extension = gl.getExtension( name );
  9134. }
  9135. if ( extension === null ) {
  9136. console.warn( 'THREE.WebGLRenderer: ' + name + ' extension not supported.' );
  9137. }
  9138. extensions[ name ] = extension;
  9139. return extension;
  9140. }
  9141. };
  9142. }
  9143. /**
  9144. * @author mrdoob / http://mrdoob.com/
  9145. */
  9146. function WebGLGeometries( gl, attributes, info ) {
  9147. var geometries = {};
  9148. var wireframeAttributes = {};
  9149. function onGeometryDispose( event ) {
  9150. var geometry = event.target;
  9151. var buffergeometry = geometries[ geometry.id ];
  9152. if ( buffergeometry.index !== null ) {
  9153. attributes.remove( buffergeometry.index );
  9154. }
  9155. for ( var name in buffergeometry.attributes ) {
  9156. attributes.remove( buffergeometry.attributes[ name ] );
  9157. }
  9158. geometry.removeEventListener( 'dispose', onGeometryDispose );
  9159. delete geometries[ geometry.id ];
  9160. var attribute = wireframeAttributes[ buffergeometry.id ];
  9161. if ( attribute ) {
  9162. attributes.remove( attribute );
  9163. delete wireframeAttributes[ buffergeometry.id ];
  9164. }
  9165. //
  9166. info.memory.geometries --;
  9167. }
  9168. function get( object, geometry ) {
  9169. var buffergeometry = geometries[ geometry.id ];
  9170. if ( buffergeometry ) return buffergeometry;
  9171. geometry.addEventListener( 'dispose', onGeometryDispose );
  9172. if ( geometry.isBufferGeometry ) {
  9173. buffergeometry = geometry;
  9174. } else if ( geometry.isGeometry ) {
  9175. if ( geometry._bufferGeometry === undefined ) {
  9176. geometry._bufferGeometry = new BufferGeometry().setFromObject( object );
  9177. }
  9178. buffergeometry = geometry._bufferGeometry;
  9179. }
  9180. geometries[ geometry.id ] = buffergeometry;
  9181. info.memory.geometries ++;
  9182. return buffergeometry;
  9183. }
  9184. function update( geometry ) {
  9185. var index = geometry.index;
  9186. var geometryAttributes = geometry.attributes;
  9187. if ( index !== null ) {
  9188. attributes.update( index, 34963 );
  9189. }
  9190. for ( var name in geometryAttributes ) {
  9191. attributes.update( geometryAttributes[ name ], 34962 );
  9192. }
  9193. // morph targets
  9194. var morphAttributes = geometry.morphAttributes;
  9195. for ( var name in morphAttributes ) {
  9196. var array = morphAttributes[ name ];
  9197. for ( var i = 0, l = array.length; i < l; i ++ ) {
  9198. attributes.update( array[ i ], 34962 );
  9199. }
  9200. }
  9201. }
  9202. function getWireframeAttribute( geometry ) {
  9203. var attribute = wireframeAttributes[ geometry.id ];
  9204. if ( attribute ) return attribute;
  9205. var indices = [];
  9206. var geometryIndex = geometry.index;
  9207. var geometryAttributes = geometry.attributes;
  9208. // console.time( 'wireframe' );
  9209. if ( geometryIndex !== null ) {
  9210. var array = geometryIndex.array;
  9211. for ( var i = 0, l = array.length; i < l; i += 3 ) {
  9212. var a = array[ i + 0 ];
  9213. var b = array[ i + 1 ];
  9214. var c = array[ i + 2 ];
  9215. indices.push( a, b, b, c, c, a );
  9216. }
  9217. } else {
  9218. var array = geometryAttributes.position.array;
  9219. for ( var i = 0, l = ( array.length / 3 ) - 1; i < l; i += 3 ) {
  9220. var a = i + 0;
  9221. var b = i + 1;
  9222. var c = i + 2;
  9223. indices.push( a, b, b, c, c, a );
  9224. }
  9225. }
  9226. // console.timeEnd( 'wireframe' );
  9227. attribute = new ( arrayMax( indices ) > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute )( indices, 1 );
  9228. attributes.update( attribute, 34963 );
  9229. wireframeAttributes[ geometry.id ] = attribute;
  9230. return attribute;
  9231. }
  9232. return {
  9233. get: get,
  9234. update: update,
  9235. getWireframeAttribute: getWireframeAttribute
  9236. };
  9237. }
  9238. /**
  9239. * @author mrdoob / http://mrdoob.com/
  9240. */
  9241. function WebGLIndexedBufferRenderer( gl, extensions, info, capabilities ) {
  9242. var mode;
  9243. function setMode( value ) {
  9244. mode = value;
  9245. }
  9246. var type, bytesPerElement;
  9247. function setIndex( value ) {
  9248. type = value.type;
  9249. bytesPerElement = value.bytesPerElement;
  9250. }
  9251. function render( start, count ) {
  9252. gl.drawElements( mode, count, type, start * bytesPerElement );
  9253. info.update( count, mode );
  9254. }
  9255. function renderInstances( geometry, start, count ) {
  9256. var extension;
  9257. if ( capabilities.isWebGL2 ) {
  9258. extension = gl;
  9259. } else {
  9260. var extension = extensions.get( 'ANGLE_instanced_arrays' );
  9261. if ( extension === null ) {
  9262. console.error( 'THREE.WebGLIndexedBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  9263. return;
  9264. }
  9265. }
  9266. extension[ capabilities.isWebGL2 ? 'drawElementsInstanced' : 'drawElementsInstancedANGLE' ]( mode, count, type, start * bytesPerElement, geometry.maxInstancedCount );
  9267. info.update( count, mode, geometry.maxInstancedCount );
  9268. }
  9269. //
  9270. this.setMode = setMode;
  9271. this.setIndex = setIndex;
  9272. this.render = render;
  9273. this.renderInstances = renderInstances;
  9274. }
  9275. /**
  9276. * @author Mugen87 / https://github.com/Mugen87
  9277. */
  9278. function WebGLInfo( gl ) {
  9279. var memory = {
  9280. geometries: 0,
  9281. textures: 0
  9282. };
  9283. var render = {
  9284. frame: 0,
  9285. calls: 0,
  9286. triangles: 0,
  9287. points: 0,
  9288. lines: 0
  9289. };
  9290. function update( count, mode, instanceCount ) {
  9291. instanceCount = instanceCount || 1;
  9292. render.calls ++;
  9293. switch ( mode ) {
  9294. case 4:
  9295. render.triangles += instanceCount * ( count / 3 );
  9296. break;
  9297. case 5:
  9298. case 6:
  9299. render.triangles += instanceCount * ( count - 2 );
  9300. break;
  9301. case 1:
  9302. render.lines += instanceCount * ( count / 2 );
  9303. break;
  9304. case 3:
  9305. render.lines += instanceCount * ( count - 1 );
  9306. break;
  9307. case 2:
  9308. render.lines += instanceCount * count;
  9309. break;
  9310. case 0:
  9311. render.points += instanceCount * count;
  9312. break;
  9313. default:
  9314. console.error( 'THREE.WebGLInfo: Unknown draw mode:', mode );
  9315. break;
  9316. }
  9317. }
  9318. function reset() {
  9319. render.frame ++;
  9320. render.calls = 0;
  9321. render.triangles = 0;
  9322. render.points = 0;
  9323. render.lines = 0;
  9324. }
  9325. return {
  9326. memory: memory,
  9327. render: render,
  9328. programs: null,
  9329. autoReset: true,
  9330. reset: reset,
  9331. update: update
  9332. };
  9333. }
  9334. /**
  9335. * @author mrdoob / http://mrdoob.com/
  9336. */
  9337. function absNumericalSort( a, b ) {
  9338. return Math.abs( b[ 1 ] ) - Math.abs( a[ 1 ] );
  9339. }
  9340. function WebGLMorphtargets( gl ) {
  9341. var influencesList = {};
  9342. var morphInfluences = new Float32Array( 8 );
  9343. function update( object, geometry, material, program ) {
  9344. var objectInfluences = object.morphTargetInfluences;
  9345. var length = objectInfluences.length;
  9346. var influences = influencesList[ geometry.id ];
  9347. if ( influences === undefined ) {
  9348. // initialise list
  9349. influences = [];
  9350. for ( var i = 0; i < length; i ++ ) {
  9351. influences[ i ] = [ i, 0 ];
  9352. }
  9353. influencesList[ geometry.id ] = influences;
  9354. }
  9355. var morphTargets = material.morphTargets && geometry.morphAttributes.position;
  9356. var morphNormals = material.morphNormals && geometry.morphAttributes.normal;
  9357. // Remove current morphAttributes
  9358. for ( var i = 0; i < length; i ++ ) {
  9359. var influence = influences[ i ];
  9360. if ( influence[ 1 ] !== 0 ) {
  9361. if ( morphTargets ) geometry.removeAttribute( 'morphTarget' + i );
  9362. if ( morphNormals ) geometry.removeAttribute( 'morphNormal' + i );
  9363. }
  9364. }
  9365. // Collect influences
  9366. for ( var i = 0; i < length; i ++ ) {
  9367. var influence = influences[ i ];
  9368. influence[ 0 ] = i;
  9369. influence[ 1 ] = objectInfluences[ i ];
  9370. }
  9371. influences.sort( absNumericalSort );
  9372. // Add morphAttributes
  9373. for ( var i = 0; i < 8; i ++ ) {
  9374. var influence = influences[ i ];
  9375. if ( influence ) {
  9376. var index = influence[ 0 ];
  9377. var value = influence[ 1 ];
  9378. if ( value ) {
  9379. if ( morphTargets ) geometry.addAttribute( 'morphTarget' + i, morphTargets[ index ] );
  9380. if ( morphNormals ) geometry.addAttribute( 'morphNormal' + i, morphNormals[ index ] );
  9381. morphInfluences[ i ] = value;
  9382. continue;
  9383. }
  9384. }
  9385. morphInfluences[ i ] = 0;
  9386. }
  9387. program.getUniforms().setValue( gl, 'morphTargetInfluences', morphInfluences );
  9388. }
  9389. return {
  9390. update: update
  9391. };
  9392. }
  9393. /**
  9394. * @author mrdoob / http://mrdoob.com/
  9395. */
  9396. function WebGLObjects( geometries, info ) {
  9397. var updateList = {};
  9398. function update( object ) {
  9399. var frame = info.render.frame;
  9400. var geometry = object.geometry;
  9401. var buffergeometry = geometries.get( object, geometry );
  9402. // Update once per frame
  9403. if ( updateList[ buffergeometry.id ] !== frame ) {
  9404. if ( geometry.isGeometry ) {
  9405. buffergeometry.updateFromObject( object );
  9406. }
  9407. geometries.update( buffergeometry );
  9408. updateList[ buffergeometry.id ] = frame;
  9409. }
  9410. return buffergeometry;
  9411. }
  9412. function dispose() {
  9413. updateList = {};
  9414. }
  9415. return {
  9416. update: update,
  9417. dispose: dispose
  9418. };
  9419. }
  9420. /**
  9421. * @author mrdoob / http://mrdoob.com/
  9422. */
  9423. function CubeTexture( images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding ) {
  9424. images = images !== undefined ? images : [];
  9425. mapping = mapping !== undefined ? mapping : CubeReflectionMapping;
  9426. format = format !== undefined ? format : RGBFormat;
  9427. Texture.call( this, images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding );
  9428. this.flipY = false;
  9429. }
  9430. CubeTexture.prototype = Object.create( Texture.prototype );
  9431. CubeTexture.prototype.constructor = CubeTexture;
  9432. CubeTexture.prototype.isCubeTexture = true;
  9433. Object.defineProperty( CubeTexture.prototype, 'images', {
  9434. get: function () {
  9435. return this.image;
  9436. },
  9437. set: function ( value ) {
  9438. this.image = value;
  9439. }
  9440. } );
  9441. /**
  9442. * @author Takahiro https://github.com/takahirox
  9443. */
  9444. function DataTexture2DArray( data, width, height, depth ) {
  9445. Texture.call( this, null );
  9446. this.image = { data: data, width: width, height: height, depth: depth };
  9447. this.magFilter = NearestFilter;
  9448. this.minFilter = NearestFilter;
  9449. this.wrapR = ClampToEdgeWrapping;
  9450. this.generateMipmaps = false;
  9451. this.flipY = false;
  9452. }
  9453. DataTexture2DArray.prototype = Object.create( Texture.prototype );
  9454. DataTexture2DArray.prototype.constructor = DataTexture2DArray;
  9455. DataTexture2DArray.prototype.isDataTexture2DArray = true;
  9456. /**
  9457. * @author Artur Trzesiok
  9458. */
  9459. function DataTexture3D( data, width, height, depth ) {
  9460. // We're going to add .setXXX() methods for setting properties later.
  9461. // Users can still set in DataTexture3D directly.
  9462. //
  9463. // var texture = new THREE.DataTexture3D( data, width, height, depth );
  9464. // texture.anisotropy = 16;
  9465. //
  9466. // See #14839
  9467. Texture.call( this, null );
  9468. this.image = { data: data, width: width, height: height, depth: depth };
  9469. this.magFilter = NearestFilter;
  9470. this.minFilter = NearestFilter;
  9471. this.wrapR = ClampToEdgeWrapping;
  9472. this.generateMipmaps = false;
  9473. this.flipY = false;
  9474. }
  9475. DataTexture3D.prototype = Object.create( Texture.prototype );
  9476. DataTexture3D.prototype.constructor = DataTexture3D;
  9477. DataTexture3D.prototype.isDataTexture3D = true;
  9478. /**
  9479. * @author tschw
  9480. * @author Mugen87 / https://github.com/Mugen87
  9481. * @author mrdoob / http://mrdoob.com/
  9482. *
  9483. * Uniforms of a program.
  9484. * Those form a tree structure with a special top-level container for the root,
  9485. * which you get by calling 'new WebGLUniforms( gl, program )'.
  9486. *
  9487. *
  9488. * Properties of inner nodes including the top-level container:
  9489. *
  9490. * .seq - array of nested uniforms
  9491. * .map - nested uniforms by name
  9492. *
  9493. *
  9494. * Methods of all nodes except the top-level container:
  9495. *
  9496. * .setValue( gl, value, [textures] )
  9497. *
  9498. * uploads a uniform value(s)
  9499. * the 'textures' parameter is needed for sampler uniforms
  9500. *
  9501. *
  9502. * Static methods of the top-level container (textures factorizations):
  9503. *
  9504. * .upload( gl, seq, values, textures )
  9505. *
  9506. * sets uniforms in 'seq' to 'values[id].value'
  9507. *
  9508. * .seqWithValue( seq, values ) : filteredSeq
  9509. *
  9510. * filters 'seq' entries with corresponding entry in values
  9511. *
  9512. *
  9513. * Methods of the top-level container (textures factorizations):
  9514. *
  9515. * .setValue( gl, name, value, textures )
  9516. *
  9517. * sets uniform with name 'name' to 'value'
  9518. *
  9519. * .setOptional( gl, obj, prop )
  9520. *
  9521. * like .set for an optional property of the object
  9522. *
  9523. */
  9524. var emptyTexture = new Texture();
  9525. var emptyTexture2dArray = new DataTexture2DArray();
  9526. var emptyTexture3d = new DataTexture3D();
  9527. var emptyCubeTexture = new CubeTexture();
  9528. // --- Utilities ---
  9529. // Array Caches (provide typed arrays for temporary by size)
  9530. var arrayCacheF32 = [];
  9531. var arrayCacheI32 = [];
  9532. // Float32Array caches used for uploading Matrix uniforms
  9533. var mat4array = new Float32Array( 16 );
  9534. var mat3array = new Float32Array( 9 );
  9535. var mat2array = new Float32Array( 4 );
  9536. // Flattening for arrays of vectors and matrices
  9537. function flatten( array, nBlocks, blockSize ) {
  9538. var firstElem = array[ 0 ];
  9539. if ( firstElem <= 0 || firstElem > 0 ) return array;
  9540. // unoptimized: ! isNaN( firstElem )
  9541. // see http://jacksondunstan.com/articles/983
  9542. var n = nBlocks * blockSize,
  9543. r = arrayCacheF32[ n ];
  9544. if ( r === undefined ) {
  9545. r = new Float32Array( n );
  9546. arrayCacheF32[ n ] = r;
  9547. }
  9548. if ( nBlocks !== 0 ) {
  9549. firstElem.toArray( r, 0 );
  9550. for ( var i = 1, offset = 0; i !== nBlocks; ++ i ) {
  9551. offset += blockSize;
  9552. array[ i ].toArray( r, offset );
  9553. }
  9554. }
  9555. return r;
  9556. }
  9557. function arraysEqual( a, b ) {
  9558. if ( a.length !== b.length ) return false;
  9559. for ( var i = 0, l = a.length; i < l; i ++ ) {
  9560. if ( a[ i ] !== b[ i ] ) return false;
  9561. }
  9562. return true;
  9563. }
  9564. function copyArray( a, b ) {
  9565. for ( var i = 0, l = b.length; i < l; i ++ ) {
  9566. a[ i ] = b[ i ];
  9567. }
  9568. }
  9569. // Texture unit allocation
  9570. function allocTexUnits( textures, n ) {
  9571. var r = arrayCacheI32[ n ];
  9572. if ( r === undefined ) {
  9573. r = new Int32Array( n );
  9574. arrayCacheI32[ n ] = r;
  9575. }
  9576. for ( var i = 0; i !== n; ++ i )
  9577. r[ i ] = textures.allocateTextureUnit();
  9578. return r;
  9579. }
  9580. // --- Setters ---
  9581. // Note: Defining these methods externally, because they come in a bunch
  9582. // and this way their names minify.
  9583. // Single scalar
  9584. function setValue1f( gl, v ) {
  9585. var cache = this.cache;
  9586. if ( cache[ 0 ] === v ) return;
  9587. gl.uniform1f( this.addr, v );
  9588. cache[ 0 ] = v;
  9589. }
  9590. function setValue1i( gl, v ) {
  9591. var cache = this.cache;
  9592. if ( cache[ 0 ] === v ) return;
  9593. gl.uniform1i( this.addr, v );
  9594. cache[ 0 ] = v;
  9595. }
  9596. // Single float vector (from flat array or THREE.VectorN)
  9597. function setValue2fv( gl, v ) {
  9598. var cache = this.cache;
  9599. if ( v.x !== undefined ) {
  9600. if ( cache[ 0 ] !== v.x || cache[ 1 ] !== v.y ) {
  9601. gl.uniform2f( this.addr, v.x, v.y );
  9602. cache[ 0 ] = v.x;
  9603. cache[ 1 ] = v.y;
  9604. }
  9605. } else {
  9606. if ( arraysEqual( cache, v ) ) return;
  9607. gl.uniform2fv( this.addr, v );
  9608. copyArray( cache, v );
  9609. }
  9610. }
  9611. function setValue3fv( gl, v ) {
  9612. var cache = this.cache;
  9613. if ( v.x !== undefined ) {
  9614. if ( cache[ 0 ] !== v.x || cache[ 1 ] !== v.y || cache[ 2 ] !== v.z ) {
  9615. gl.uniform3f( this.addr, v.x, v.y, v.z );
  9616. cache[ 0 ] = v.x;
  9617. cache[ 1 ] = v.y;
  9618. cache[ 2 ] = v.z;
  9619. }
  9620. } else if ( v.r !== undefined ) {
  9621. if ( cache[ 0 ] !== v.r || cache[ 1 ] !== v.g || cache[ 2 ] !== v.b ) {
  9622. gl.uniform3f( this.addr, v.r, v.g, v.b );
  9623. cache[ 0 ] = v.r;
  9624. cache[ 1 ] = v.g;
  9625. cache[ 2 ] = v.b;
  9626. }
  9627. } else {
  9628. if ( arraysEqual( cache, v ) ) return;
  9629. gl.uniform3fv( this.addr, v );
  9630. copyArray( cache, v );
  9631. }
  9632. }
  9633. function setValue4fv( gl, v ) {
  9634. var cache = this.cache;
  9635. if ( v.x !== undefined ) {
  9636. if ( cache[ 0 ] !== v.x || cache[ 1 ] !== v.y || cache[ 2 ] !== v.z || cache[ 3 ] !== v.w ) {
  9637. gl.uniform4f( this.addr, v.x, v.y, v.z, v.w );
  9638. cache[ 0 ] = v.x;
  9639. cache[ 1 ] = v.y;
  9640. cache[ 2 ] = v.z;
  9641. cache[ 3 ] = v.w;
  9642. }
  9643. } else {
  9644. if ( arraysEqual( cache, v ) ) return;
  9645. gl.uniform4fv( this.addr, v );
  9646. copyArray( cache, v );
  9647. }
  9648. }
  9649. // Single matrix (from flat array or MatrixN)
  9650. function setValue2fm( gl, v ) {
  9651. var cache = this.cache;
  9652. var elements = v.elements;
  9653. if ( elements === undefined ) {
  9654. if ( arraysEqual( cache, v ) ) return;
  9655. gl.uniformMatrix2fv( this.addr, false, v );
  9656. copyArray( cache, v );
  9657. } else {
  9658. if ( arraysEqual( cache, elements ) ) return;
  9659. mat2array.set( elements );
  9660. gl.uniformMatrix2fv( this.addr, false, mat2array );
  9661. copyArray( cache, elements );
  9662. }
  9663. }
  9664. function setValue3fm( gl, v ) {
  9665. var cache = this.cache;
  9666. var elements = v.elements;
  9667. if ( elements === undefined ) {
  9668. if ( arraysEqual( cache, v ) ) return;
  9669. gl.uniformMatrix3fv( this.addr, false, v );
  9670. copyArray( cache, v );
  9671. } else {
  9672. if ( arraysEqual( cache, elements ) ) return;
  9673. mat3array.set( elements );
  9674. gl.uniformMatrix3fv( this.addr, false, mat3array );
  9675. copyArray( cache, elements );
  9676. }
  9677. }
  9678. function setValue4fm( gl, v ) {
  9679. var cache = this.cache;
  9680. var elements = v.elements;
  9681. if ( elements === undefined ) {
  9682. if ( arraysEqual( cache, v ) ) return;
  9683. gl.uniformMatrix4fv( this.addr, false, v );
  9684. copyArray( cache, v );
  9685. } else {
  9686. if ( arraysEqual( cache, elements ) ) return;
  9687. mat4array.set( elements );
  9688. gl.uniformMatrix4fv( this.addr, false, mat4array );
  9689. copyArray( cache, elements );
  9690. }
  9691. }
  9692. // Single texture (2D / Cube)
  9693. function setValueT1( gl, v, textures ) {
  9694. var cache = this.cache;
  9695. var unit = textures.allocateTextureUnit();
  9696. if ( cache[ 0 ] !== unit ) {
  9697. gl.uniform1i( this.addr, unit );
  9698. cache[ 0 ] = unit;
  9699. }
  9700. textures.safeSetTexture2D( v || emptyTexture, unit );
  9701. }
  9702. function setValueT2DArray1( gl, v, textures ) {
  9703. var cache = this.cache;
  9704. var unit = textures.allocateTextureUnit();
  9705. if ( cache[ 0 ] !== unit ) {
  9706. gl.uniform1i( this.addr, unit );
  9707. cache[ 0 ] = unit;
  9708. }
  9709. textures.setTexture2DArray( v || emptyTexture2dArray, unit );
  9710. }
  9711. function setValueT3D1( gl, v, textures ) {
  9712. var cache = this.cache;
  9713. var unit = textures.allocateTextureUnit();
  9714. if ( cache[ 0 ] !== unit ) {
  9715. gl.uniform1i( this.addr, unit );
  9716. cache[ 0 ] = unit;
  9717. }
  9718. textures.setTexture3D( v || emptyTexture3d, unit );
  9719. }
  9720. function setValueT6( gl, v, textures ) {
  9721. var cache = this.cache;
  9722. var unit = textures.allocateTextureUnit();
  9723. if ( cache[ 0 ] !== unit ) {
  9724. gl.uniform1i( this.addr, unit );
  9725. cache[ 0 ] = unit;
  9726. }
  9727. textures.safeSetTextureCube( v || emptyCubeTexture, unit );
  9728. }
  9729. // Integer / Boolean vectors or arrays thereof (always flat arrays)
  9730. function setValue2iv( gl, v ) {
  9731. var cache = this.cache;
  9732. if ( arraysEqual( cache, v ) ) return;
  9733. gl.uniform2iv( this.addr, v );
  9734. copyArray( cache, v );
  9735. }
  9736. function setValue3iv( gl, v ) {
  9737. var cache = this.cache;
  9738. if ( arraysEqual( cache, v ) ) return;
  9739. gl.uniform3iv( this.addr, v );
  9740. copyArray( cache, v );
  9741. }
  9742. function setValue4iv( gl, v ) {
  9743. var cache = this.cache;
  9744. if ( arraysEqual( cache, v ) ) return;
  9745. gl.uniform4iv( this.addr, v );
  9746. copyArray( cache, v );
  9747. }
  9748. // Helper to pick the right setter for the singular case
  9749. function getSingularSetter( type ) {
  9750. switch ( type ) {
  9751. case 0x1406: return setValue1f; // FLOAT
  9752. case 0x8b50: return setValue2fv; // _VEC2
  9753. case 0x8b51: return setValue3fv; // _VEC3
  9754. case 0x8b52: return setValue4fv; // _VEC4
  9755. case 0x8b5a: return setValue2fm; // _MAT2
  9756. case 0x8b5b: return setValue3fm; // _MAT3
  9757. case 0x8b5c: return setValue4fm; // _MAT4
  9758. case 0x8b5e: case 0x8d66: return setValueT1; // SAMPLER_2D, SAMPLER_EXTERNAL_OES
  9759. case 0x8b5f: return setValueT3D1; // SAMPLER_3D
  9760. case 0x8b60: return setValueT6; // SAMPLER_CUBE
  9761. case 0x8DC1: return setValueT2DArray1; // SAMPLER_2D_ARRAY
  9762. case 0x1404: case 0x8b56: return setValue1i; // INT, BOOL
  9763. case 0x8b53: case 0x8b57: return setValue2iv; // _VEC2
  9764. case 0x8b54: case 0x8b58: return setValue3iv; // _VEC3
  9765. case 0x8b55: case 0x8b59: return setValue4iv; // _VEC4
  9766. }
  9767. }
  9768. // Array of scalars
  9769. function setValue1fv( gl, v ) {
  9770. var cache = this.cache;
  9771. if ( arraysEqual( cache, v ) ) return;
  9772. gl.uniform1fv( this.addr, v );
  9773. copyArray( cache, v );
  9774. }
  9775. function setValue1iv( gl, v ) {
  9776. var cache = this.cache;
  9777. if ( arraysEqual( cache, v ) ) return;
  9778. gl.uniform1iv( this.addr, v );
  9779. copyArray( cache, v );
  9780. }
  9781. // Array of vectors (flat or from THREE classes)
  9782. function setValueV2a( gl, v ) {
  9783. var cache = this.cache;
  9784. var data = flatten( v, this.size, 2 );
  9785. if ( arraysEqual( cache, data ) ) return;
  9786. gl.uniform2fv( this.addr, data );
  9787. this.updateCache( data );
  9788. }
  9789. function setValueV3a( gl, v ) {
  9790. var cache = this.cache;
  9791. var data = flatten( v, this.size, 3 );
  9792. if ( arraysEqual( cache, data ) ) return;
  9793. gl.uniform3fv( this.addr, data );
  9794. this.updateCache( data );
  9795. }
  9796. function setValueV4a( gl, v ) {
  9797. var cache = this.cache;
  9798. var data = flatten( v, this.size, 4 );
  9799. if ( arraysEqual( cache, data ) ) return;
  9800. gl.uniform4fv( this.addr, data );
  9801. this.updateCache( data );
  9802. }
  9803. // Array of matrices (flat or from THREE clases)
  9804. function setValueM2a( gl, v ) {
  9805. var cache = this.cache;
  9806. var data = flatten( v, this.size, 4 );
  9807. if ( arraysEqual( cache, data ) ) return;
  9808. gl.uniformMatrix2fv( this.addr, false, data );
  9809. this.updateCache( data );
  9810. }
  9811. function setValueM3a( gl, v ) {
  9812. var cache = this.cache;
  9813. var data = flatten( v, this.size, 9 );
  9814. if ( arraysEqual( cache, data ) ) return;
  9815. gl.uniformMatrix3fv( this.addr, false, data );
  9816. this.updateCache( data );
  9817. }
  9818. function setValueM4a( gl, v ) {
  9819. var cache = this.cache;
  9820. var data = flatten( v, this.size, 16 );
  9821. if ( arraysEqual( cache, data ) ) return;
  9822. gl.uniformMatrix4fv( this.addr, false, data );
  9823. this.updateCache( data );
  9824. }
  9825. // Array of textures (2D / Cube)
  9826. function setValueT1a( gl, v, textures ) {
  9827. var cache = this.cache;
  9828. var n = v.length;
  9829. var units = allocTexUnits( textures, n );
  9830. if ( arraysEqual( cache, units ) === false ) {
  9831. gl.uniform1iv( this.addr, units );
  9832. copyArray( cache, units );
  9833. }
  9834. for ( var i = 0; i !== n; ++ i ) {
  9835. textures.safeSetTexture2D( v[ i ] || emptyTexture, units[ i ] );
  9836. }
  9837. }
  9838. function setValueT6a( gl, v, textures ) {
  9839. var cache = this.cache;
  9840. var n = v.length;
  9841. var units = allocTexUnits( textures, n );
  9842. if ( arraysEqual( cache, units ) === false ) {
  9843. gl.uniform1iv( this.addr, units );
  9844. copyArray( cache, units );
  9845. }
  9846. for ( var i = 0; i !== n; ++ i ) {
  9847. textures.safeSetTextureCube( v[ i ] || emptyCubeTexture, units[ i ] );
  9848. }
  9849. }
  9850. // Helper to pick the right setter for a pure (bottom-level) array
  9851. function getPureArraySetter( type ) {
  9852. switch ( type ) {
  9853. case 0x1406: return setValue1fv; // FLOAT
  9854. case 0x8b50: return setValueV2a; // _VEC2
  9855. case 0x8b51: return setValueV3a; // _VEC3
  9856. case 0x8b52: return setValueV4a; // _VEC4
  9857. case 0x8b5a: return setValueM2a; // _MAT2
  9858. case 0x8b5b: return setValueM3a; // _MAT3
  9859. case 0x8b5c: return setValueM4a; // _MAT4
  9860. case 0x8b5e: return setValueT1a; // SAMPLER_2D
  9861. case 0x8b60: return setValueT6a; // SAMPLER_CUBE
  9862. case 0x1404: case 0x8b56: return setValue1iv; // INT, BOOL
  9863. case 0x8b53: case 0x8b57: return setValue2iv; // _VEC2
  9864. case 0x8b54: case 0x8b58: return setValue3iv; // _VEC3
  9865. case 0x8b55: case 0x8b59: return setValue4iv; // _VEC4
  9866. }
  9867. }
  9868. // --- Uniform Classes ---
  9869. function SingleUniform( id, activeInfo, addr ) {
  9870. this.id = id;
  9871. this.addr = addr;
  9872. this.cache = [];
  9873. this.setValue = getSingularSetter( activeInfo.type );
  9874. // this.path = activeInfo.name; // DEBUG
  9875. }
  9876. function PureArrayUniform( id, activeInfo, addr ) {
  9877. this.id = id;
  9878. this.addr = addr;
  9879. this.cache = [];
  9880. this.size = activeInfo.size;
  9881. this.setValue = getPureArraySetter( activeInfo.type );
  9882. // this.path = activeInfo.name; // DEBUG
  9883. }
  9884. PureArrayUniform.prototype.updateCache = function ( data ) {
  9885. var cache = this.cache;
  9886. if ( data instanceof Float32Array && cache.length !== data.length ) {
  9887. this.cache = new Float32Array( data.length );
  9888. }
  9889. copyArray( cache, data );
  9890. };
  9891. function StructuredUniform( id ) {
  9892. this.id = id;
  9893. this.seq = [];
  9894. this.map = {};
  9895. }
  9896. StructuredUniform.prototype.setValue = function ( gl, value, textures ) {
  9897. var seq = this.seq;
  9898. for ( var i = 0, n = seq.length; i !== n; ++ i ) {
  9899. var u = seq[ i ];
  9900. u.setValue( gl, value[ u.id ], textures );
  9901. }
  9902. };
  9903. // --- Top-level ---
  9904. // Parser - builds up the property tree from the path strings
  9905. var RePathPart = /([\w\d_]+)(\])?(\[|\.)?/g;
  9906. // extracts
  9907. // - the identifier (member name or array index)
  9908. // - followed by an optional right bracket (found when array index)
  9909. // - followed by an optional left bracket or dot (type of subscript)
  9910. //
  9911. // Note: These portions can be read in a non-overlapping fashion and
  9912. // allow straightforward parsing of the hierarchy that WebGL encodes
  9913. // in the uniform names.
  9914. function addUniform( container, uniformObject ) {
  9915. container.seq.push( uniformObject );
  9916. container.map[ uniformObject.id ] = uniformObject;
  9917. }
  9918. function parseUniform( activeInfo, addr, container ) {
  9919. var path = activeInfo.name,
  9920. pathLength = path.length;
  9921. // reset RegExp object, because of the early exit of a previous run
  9922. RePathPart.lastIndex = 0;
  9923. while ( true ) {
  9924. var match = RePathPart.exec( path ),
  9925. matchEnd = RePathPart.lastIndex,
  9926. id = match[ 1 ],
  9927. idIsIndex = match[ 2 ] === ']',
  9928. subscript = match[ 3 ];
  9929. if ( idIsIndex ) id = id | 0; // convert to integer
  9930. if ( subscript === undefined || subscript === '[' && matchEnd + 2 === pathLength ) {
  9931. // bare name or "pure" bottom-level array "[0]" suffix
  9932. addUniform( container, subscript === undefined ?
  9933. new SingleUniform( id, activeInfo, addr ) :
  9934. new PureArrayUniform( id, activeInfo, addr ) );
  9935. break;
  9936. } else {
  9937. // step into inner node / create it in case it doesn't exist
  9938. var map = container.map, next = map[ id ];
  9939. if ( next === undefined ) {
  9940. next = new StructuredUniform( id );
  9941. addUniform( container, next );
  9942. }
  9943. container = next;
  9944. }
  9945. }
  9946. }
  9947. // Root Container
  9948. function WebGLUniforms( gl, program ) {
  9949. this.seq = [];
  9950. this.map = {};
  9951. var n = gl.getProgramParameter( program, 35718 );
  9952. for ( var i = 0; i < n; ++ i ) {
  9953. var info = gl.getActiveUniform( program, i ),
  9954. addr = gl.getUniformLocation( program, info.name );
  9955. parseUniform( info, addr, this );
  9956. }
  9957. }
  9958. WebGLUniforms.prototype.setValue = function ( gl, name, value, textures ) {
  9959. var u = this.map[ name ];
  9960. if ( u !== undefined ) u.setValue( gl, value, textures );
  9961. };
  9962. WebGLUniforms.prototype.setOptional = function ( gl, object, name ) {
  9963. var v = object[ name ];
  9964. if ( v !== undefined ) this.setValue( gl, name, v );
  9965. };
  9966. // Static interface
  9967. WebGLUniforms.upload = function ( gl, seq, values, textures ) {
  9968. for ( var i = 0, n = seq.length; i !== n; ++ i ) {
  9969. var u = seq[ i ],
  9970. v = values[ u.id ];
  9971. if ( v.needsUpdate !== false ) {
  9972. // note: always updating when .needsUpdate is undefined
  9973. u.setValue( gl, v.value, textures );
  9974. }
  9975. }
  9976. };
  9977. WebGLUniforms.seqWithValue = function ( seq, values ) {
  9978. var r = [];
  9979. for ( var i = 0, n = seq.length; i !== n; ++ i ) {
  9980. var u = seq[ i ];
  9981. if ( u.id in values ) r.push( u );
  9982. }
  9983. return r;
  9984. };
  9985. /**
  9986. * @author mrdoob / http://mrdoob.com/
  9987. */
  9988. function addLineNumbers( string ) {
  9989. var lines = string.split( '\n' );
  9990. for ( var i = 0; i < lines.length; i ++ ) {
  9991. lines[ i ] = ( i + 1 ) + ': ' + lines[ i ];
  9992. }
  9993. return lines.join( '\n' );
  9994. }
  9995. function WebGLShader( gl, type, string, debug ) {
  9996. var shader = gl.createShader( type );
  9997. gl.shaderSource( shader, string );
  9998. gl.compileShader( shader );
  9999. if ( debug === true ) {
  10000. if ( gl.getShaderParameter( shader, 35713 ) === false ) {
  10001. console.error( 'THREE.WebGLShader: Shader couldn\'t compile.' );
  10002. }
  10003. if ( gl.getShaderInfoLog( shader ) !== '' ) {
  10004. console.warn( 'THREE.WebGLShader: gl.getShaderInfoLog()', type === 35633 ? 'vertex' : 'fragment', gl.getShaderInfoLog( shader ), addLineNumbers( string ) );
  10005. }
  10006. }
  10007. // --enable-privileged-webgl-extension
  10008. // console.log( type, gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( shader ) );
  10009. return shader;
  10010. }
  10011. /**
  10012. * @author mrdoob / http://mrdoob.com/
  10013. */
  10014. var programIdCount = 0;
  10015. function getEncodingComponents( encoding ) {
  10016. switch ( encoding ) {
  10017. case LinearEncoding:
  10018. return [ 'Linear', '( value )' ];
  10019. case sRGBEncoding:
  10020. return [ 'sRGB', '( value )' ];
  10021. case RGBEEncoding:
  10022. return [ 'RGBE', '( value )' ];
  10023. case RGBM7Encoding:
  10024. return [ 'RGBM', '( value, 7.0 )' ];
  10025. case RGBM16Encoding:
  10026. return [ 'RGBM', '( value, 16.0 )' ];
  10027. case RGBDEncoding:
  10028. return [ 'RGBD', '( value, 256.0 )' ];
  10029. case GammaEncoding:
  10030. return [ 'Gamma', '( value, float( GAMMA_FACTOR ) )' ];
  10031. default:
  10032. throw new Error( 'unsupported encoding: ' + encoding );
  10033. }
  10034. }
  10035. function getTexelDecodingFunction( functionName, encoding ) {
  10036. var components = getEncodingComponents( encoding );
  10037. return 'vec4 ' + functionName + '( vec4 value ) { return ' + components[ 0 ] + 'ToLinear' + components[ 1 ] + '; }';
  10038. }
  10039. function getTexelEncodingFunction( functionName, encoding ) {
  10040. var components = getEncodingComponents( encoding );
  10041. return 'vec4 ' + functionName + '( vec4 value ) { return LinearTo' + components[ 0 ] + components[ 1 ] + '; }';
  10042. }
  10043. function getToneMappingFunction( functionName, toneMapping ) {
  10044. var toneMappingName;
  10045. switch ( toneMapping ) {
  10046. case LinearToneMapping:
  10047. toneMappingName = 'Linear';
  10048. break;
  10049. case ReinhardToneMapping:
  10050. toneMappingName = 'Reinhard';
  10051. break;
  10052. case Uncharted2ToneMapping:
  10053. toneMappingName = 'Uncharted2';
  10054. break;
  10055. case CineonToneMapping:
  10056. toneMappingName = 'OptimizedCineon';
  10057. break;
  10058. case ACESFilmicToneMapping:
  10059. toneMappingName = 'ACESFilmic';
  10060. break;
  10061. default:
  10062. throw new Error( 'unsupported toneMapping: ' + toneMapping );
  10063. }
  10064. return 'vec3 ' + functionName + '( vec3 color ) { return ' + toneMappingName + 'ToneMapping( color ); }';
  10065. }
  10066. function generateExtensions( extensions, parameters, rendererExtensions ) {
  10067. extensions = extensions || {};
  10068. var chunks = [
  10069. ( extensions.derivatives || parameters.envMapCubeUV || parameters.bumpMap || ( parameters.normalMap && ! parameters.objectSpaceNormalMap ) || parameters.flatShading ) ? '#extension GL_OES_standard_derivatives : enable' : '',
  10070. ( extensions.fragDepth || parameters.logarithmicDepthBuffer ) && rendererExtensions.get( 'EXT_frag_depth' ) ? '#extension GL_EXT_frag_depth : enable' : '',
  10071. ( extensions.drawBuffers ) && rendererExtensions.get( 'WEBGL_draw_buffers' ) ? '#extension GL_EXT_draw_buffers : require' : '',
  10072. ( extensions.shaderTextureLOD || parameters.envMap ) && rendererExtensions.get( 'EXT_shader_texture_lod' ) ? '#extension GL_EXT_shader_texture_lod : enable' : ''
  10073. ];
  10074. return chunks.filter( filterEmptyLine ).join( '\n' );
  10075. }
  10076. function generateDefines( defines ) {
  10077. var chunks = [];
  10078. for ( var name in defines ) {
  10079. var value = defines[ name ];
  10080. if ( value === false ) continue;
  10081. chunks.push( '#define ' + name + ' ' + value );
  10082. }
  10083. return chunks.join( '\n' );
  10084. }
  10085. function fetchAttributeLocations( gl, program ) {
  10086. var attributes = {};
  10087. var n = gl.getProgramParameter( program, 35721 );
  10088. for ( var i = 0; i < n; i ++ ) {
  10089. var info = gl.getActiveAttrib( program, i );
  10090. var name = info.name;
  10091. // console.log( 'THREE.WebGLProgram: ACTIVE VERTEX ATTRIBUTE:', name, i );
  10092. attributes[ name ] = gl.getAttribLocation( program, name );
  10093. }
  10094. return attributes;
  10095. }
  10096. function filterEmptyLine( string ) {
  10097. return string !== '';
  10098. }
  10099. function replaceLightNums( string, parameters ) {
  10100. return string
  10101. .replace( /NUM_DIR_LIGHTS/g, parameters.numDirLights )
  10102. .replace( /NUM_SPOT_LIGHTS/g, parameters.numSpotLights )
  10103. .replace( /NUM_RECT_AREA_LIGHTS/g, parameters.numRectAreaLights )
  10104. .replace( /NUM_POINT_LIGHTS/g, parameters.numPointLights )
  10105. .replace( /NUM_HEMI_LIGHTS/g, parameters.numHemiLights );
  10106. }
  10107. function replaceClippingPlaneNums( string, parameters ) {
  10108. return string
  10109. .replace( /NUM_CLIPPING_PLANES/g, parameters.numClippingPlanes )
  10110. .replace( /UNION_CLIPPING_PLANES/g, ( parameters.numClippingPlanes - parameters.numClipIntersection ) );
  10111. }
  10112. function parseIncludes( string ) {
  10113. var pattern = /^[ \t]*#include +<([\w\d./]+)>/gm;
  10114. function replace( match, include ) {
  10115. var replace = ShaderChunk[ include ];
  10116. if ( replace === undefined ) {
  10117. throw new Error( 'Can not resolve #include <' + include + '>' );
  10118. }
  10119. return parseIncludes( replace );
  10120. }
  10121. return string.replace( pattern, replace );
  10122. }
  10123. function unrollLoops( string ) {
  10124. var pattern = /#pragma unroll_loop[\s]+?for \( int i \= (\d+)\; i < (\d+)\; i \+\+ \) \{([\s\S]+?)(?=\})\}/g;
  10125. function replace( match, start, end, snippet ) {
  10126. var unroll = '';
  10127. for ( var i = parseInt( start ); i < parseInt( end ); i ++ ) {
  10128. unroll += snippet.replace( /\[ i \]/g, '[ ' + i + ' ]' );
  10129. }
  10130. return unroll;
  10131. }
  10132. return string.replace( pattern, replace );
  10133. }
  10134. function WebGLProgram( renderer, extensions, code, material, shader, parameters, capabilities, textures ) {
  10135. var gl = renderer.context;
  10136. var defines = material.defines;
  10137. var vertexShader = shader.vertexShader;
  10138. var fragmentShader = shader.fragmentShader;
  10139. var shadowMapTypeDefine = 'SHADOWMAP_TYPE_BASIC';
  10140. if ( parameters.shadowMapType === PCFShadowMap ) {
  10141. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF';
  10142. } else if ( parameters.shadowMapType === PCFSoftShadowMap ) {
  10143. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF_SOFT';
  10144. }
  10145. var envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  10146. var envMapModeDefine = 'ENVMAP_MODE_REFLECTION';
  10147. var envMapBlendingDefine = 'ENVMAP_BLENDING_MULTIPLY';
  10148. if ( parameters.envMap ) {
  10149. switch ( material.envMap.mapping ) {
  10150. case CubeReflectionMapping:
  10151. case CubeRefractionMapping:
  10152. envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  10153. break;
  10154. case CubeUVReflectionMapping:
  10155. case CubeUVRefractionMapping:
  10156. envMapTypeDefine = 'ENVMAP_TYPE_CUBE_UV';
  10157. break;
  10158. case EquirectangularReflectionMapping:
  10159. case EquirectangularRefractionMapping:
  10160. envMapTypeDefine = 'ENVMAP_TYPE_EQUIREC';
  10161. break;
  10162. case SphericalReflectionMapping:
  10163. envMapTypeDefine = 'ENVMAP_TYPE_SPHERE';
  10164. break;
  10165. }
  10166. switch ( material.envMap.mapping ) {
  10167. case CubeRefractionMapping:
  10168. case EquirectangularRefractionMapping:
  10169. envMapModeDefine = 'ENVMAP_MODE_REFRACTION';
  10170. break;
  10171. }
  10172. switch ( material.combine ) {
  10173. case MultiplyOperation:
  10174. envMapBlendingDefine = 'ENVMAP_BLENDING_MULTIPLY';
  10175. break;
  10176. case MixOperation:
  10177. envMapBlendingDefine = 'ENVMAP_BLENDING_MIX';
  10178. break;
  10179. case AddOperation:
  10180. envMapBlendingDefine = 'ENVMAP_BLENDING_ADD';
  10181. break;
  10182. }
  10183. }
  10184. var gammaFactorDefine = ( renderer.gammaFactor > 0 ) ? renderer.gammaFactor : 1.0;
  10185. // console.log( 'building new program ' );
  10186. //
  10187. var customExtensions = capabilities.isWebGL2 ? '' : generateExtensions( material.extensions, parameters, extensions );
  10188. var customDefines = generateDefines( defines );
  10189. //
  10190. var program = gl.createProgram();
  10191. var prefixVertex, prefixFragment;
  10192. if ( material.isRawShaderMaterial ) {
  10193. prefixVertex = [
  10194. customDefines
  10195. ].filter( filterEmptyLine ).join( '\n' );
  10196. if ( prefixVertex.length > 0 ) {
  10197. prefixVertex += '\n';
  10198. }
  10199. prefixFragment = [
  10200. customExtensions,
  10201. customDefines
  10202. ].filter( filterEmptyLine ).join( '\n' );
  10203. if ( prefixFragment.length > 0 ) {
  10204. prefixFragment += '\n';
  10205. }
  10206. } else {
  10207. prefixVertex = [
  10208. 'precision ' + parameters.precision + ' float;',
  10209. 'precision ' + parameters.precision + ' int;',
  10210. '#define SHADER_NAME ' + shader.name,
  10211. customDefines,
  10212. parameters.supportsVertexTextures ? '#define VERTEX_TEXTURES' : '',
  10213. '#define GAMMA_FACTOR ' + gammaFactorDefine,
  10214. '#define MAX_BONES ' + parameters.maxBones,
  10215. ( parameters.useFog && parameters.fog ) ? '#define USE_FOG' : '',
  10216. ( parameters.useFog && parameters.fogExp ) ? '#define FOG_EXP2' : '',
  10217. parameters.map ? '#define USE_MAP' : '',
  10218. parameters.envMap ? '#define USE_ENVMAP' : '',
  10219. parameters.envMap ? '#define ' + envMapModeDefine : '',
  10220. parameters.lightMap ? '#define USE_LIGHTMAP' : '',
  10221. parameters.aoMap ? '#define USE_AOMAP' : '',
  10222. parameters.emissiveMap ? '#define USE_EMISSIVEMAP' : '',
  10223. parameters.bumpMap ? '#define USE_BUMPMAP' : '',
  10224. parameters.normalMap ? '#define USE_NORMALMAP' : '',
  10225. ( parameters.normalMap && parameters.objectSpaceNormalMap ) ? '#define OBJECTSPACE_NORMALMAP' : '',
  10226. parameters.displacementMap && parameters.supportsVertexTextures ? '#define USE_DISPLACEMENTMAP' : '',
  10227. parameters.specularMap ? '#define USE_SPECULARMAP' : '',
  10228. parameters.roughnessMap ? '#define USE_ROUGHNESSMAP' : '',
  10229. parameters.metalnessMap ? '#define USE_METALNESSMAP' : '',
  10230. parameters.alphaMap ? '#define USE_ALPHAMAP' : '',
  10231. parameters.vertexTangents ? '#define USE_TANGENT' : '',
  10232. parameters.vertexColors ? '#define USE_COLOR' : '',
  10233. parameters.flatShading ? '#define FLAT_SHADED' : '',
  10234. parameters.skinning ? '#define USE_SKINNING' : '',
  10235. parameters.useVertexTexture ? '#define BONE_TEXTURE' : '',
  10236. parameters.morphTargets ? '#define USE_MORPHTARGETS' : '',
  10237. parameters.morphNormals && parameters.flatShading === false ? '#define USE_MORPHNORMALS' : '',
  10238. parameters.doubleSided ? '#define DOUBLE_SIDED' : '',
  10239. parameters.flipSided ? '#define FLIP_SIDED' : '',
  10240. parameters.shadowMapEnabled ? '#define USE_SHADOWMAP' : '',
  10241. parameters.shadowMapEnabled ? '#define ' + shadowMapTypeDefine : '',
  10242. parameters.sizeAttenuation ? '#define USE_SIZEATTENUATION' : '',
  10243. parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
  10244. parameters.logarithmicDepthBuffer && ( capabilities.isWebGL2 || extensions.get( 'EXT_frag_depth' ) ) ? '#define USE_LOGDEPTHBUF_EXT' : '',
  10245. 'uniform mat4 modelMatrix;',
  10246. 'uniform mat4 modelViewMatrix;',
  10247. 'uniform mat4 projectionMatrix;',
  10248. 'uniform mat4 viewMatrix;',
  10249. 'uniform mat3 normalMatrix;',
  10250. 'uniform vec3 cameraPosition;',
  10251. 'attribute vec3 position;',
  10252. 'attribute vec3 normal;',
  10253. 'attribute vec2 uv;',
  10254. '#ifdef USE_TANGENT',
  10255. ' attribute vec4 tangent;',
  10256. '#endif',
  10257. '#ifdef USE_COLOR',
  10258. ' attribute vec3 color;',
  10259. '#endif',
  10260. '#ifdef USE_MORPHTARGETS',
  10261. ' attribute vec3 morphTarget0;',
  10262. ' attribute vec3 morphTarget1;',
  10263. ' attribute vec3 morphTarget2;',
  10264. ' attribute vec3 morphTarget3;',
  10265. ' #ifdef USE_MORPHNORMALS',
  10266. ' attribute vec3 morphNormal0;',
  10267. ' attribute vec3 morphNormal1;',
  10268. ' attribute vec3 morphNormal2;',
  10269. ' attribute vec3 morphNormal3;',
  10270. ' #else',
  10271. ' attribute vec3 morphTarget4;',
  10272. ' attribute vec3 morphTarget5;',
  10273. ' attribute vec3 morphTarget6;',
  10274. ' attribute vec3 morphTarget7;',
  10275. ' #endif',
  10276. '#endif',
  10277. '#ifdef USE_SKINNING',
  10278. ' attribute vec4 skinIndex;',
  10279. ' attribute vec4 skinWeight;',
  10280. '#endif',
  10281. '\n'
  10282. ].filter( filterEmptyLine ).join( '\n' );
  10283. prefixFragment = [
  10284. customExtensions,
  10285. 'precision ' + parameters.precision + ' float;',
  10286. 'precision ' + parameters.precision + ' int;',
  10287. '#define SHADER_NAME ' + shader.name,
  10288. customDefines,
  10289. parameters.alphaTest ? '#define ALPHATEST ' + parameters.alphaTest + ( parameters.alphaTest % 1 ? '' : '.0' ) : '', // add '.0' if integer
  10290. '#define GAMMA_FACTOR ' + gammaFactorDefine,
  10291. ( parameters.useFog && parameters.fog ) ? '#define USE_FOG' : '',
  10292. ( parameters.useFog && parameters.fogExp ) ? '#define FOG_EXP2' : '',
  10293. parameters.map ? '#define USE_MAP' : '',
  10294. parameters.matcap ? '#define USE_MATCAP' : '',
  10295. parameters.envMap ? '#define USE_ENVMAP' : '',
  10296. parameters.envMap ? '#define ' + envMapTypeDefine : '',
  10297. parameters.envMap ? '#define ' + envMapModeDefine : '',
  10298. parameters.envMap ? '#define ' + envMapBlendingDefine : '',
  10299. parameters.lightMap ? '#define USE_LIGHTMAP' : '',
  10300. parameters.aoMap ? '#define USE_AOMAP' : '',
  10301. parameters.emissiveMap ? '#define USE_EMISSIVEMAP' : '',
  10302. parameters.bumpMap ? '#define USE_BUMPMAP' : '',
  10303. parameters.normalMap ? '#define USE_NORMALMAP' : '',
  10304. ( parameters.normalMap && parameters.objectSpaceNormalMap ) ? '#define OBJECTSPACE_NORMALMAP' : '',
  10305. parameters.specularMap ? '#define USE_SPECULARMAP' : '',
  10306. parameters.roughnessMap ? '#define USE_ROUGHNESSMAP' : '',
  10307. parameters.metalnessMap ? '#define USE_METALNESSMAP' : '',
  10308. parameters.alphaMap ? '#define USE_ALPHAMAP' : '',
  10309. parameters.vertexTangents ? '#define USE_TANGENT' : '',
  10310. parameters.vertexColors ? '#define USE_COLOR' : '',
  10311. parameters.gradientMap ? '#define USE_GRADIENTMAP' : '',
  10312. parameters.flatShading ? '#define FLAT_SHADED' : '',
  10313. parameters.doubleSided ? '#define DOUBLE_SIDED' : '',
  10314. parameters.flipSided ? '#define FLIP_SIDED' : '',
  10315. parameters.shadowMapEnabled ? '#define USE_SHADOWMAP' : '',
  10316. parameters.shadowMapEnabled ? '#define ' + shadowMapTypeDefine : '',
  10317. parameters.premultipliedAlpha ? '#define PREMULTIPLIED_ALPHA' : '',
  10318. parameters.physicallyCorrectLights ? '#define PHYSICALLY_CORRECT_LIGHTS' : '',
  10319. parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
  10320. parameters.logarithmicDepthBuffer && ( capabilities.isWebGL2 || extensions.get( 'EXT_frag_depth' ) ) ? '#define USE_LOGDEPTHBUF_EXT' : '',
  10321. parameters.envMap && ( capabilities.isWebGL2 || extensions.get( 'EXT_shader_texture_lod' ) ) ? '#define TEXTURE_LOD_EXT' : '',
  10322. 'uniform mat4 viewMatrix;',
  10323. 'uniform vec3 cameraPosition;',
  10324. ( parameters.toneMapping !== NoToneMapping ) ? '#define TONE_MAPPING' : '',
  10325. ( parameters.toneMapping !== NoToneMapping ) ? ShaderChunk[ 'tonemapping_pars_fragment' ] : '', // this code is required here because it is used by the toneMapping() function defined below
  10326. ( parameters.toneMapping !== NoToneMapping ) ? getToneMappingFunction( 'toneMapping', parameters.toneMapping ) : '',
  10327. parameters.dithering ? '#define DITHERING' : '',
  10328. ( parameters.outputEncoding || parameters.mapEncoding || parameters.matcapEncoding || parameters.envMapEncoding || parameters.emissiveMapEncoding ) ?
  10329. ShaderChunk[ 'encodings_pars_fragment' ] : '', // this code is required here because it is used by the various encoding/decoding function defined below
  10330. parameters.mapEncoding ? getTexelDecodingFunction( 'mapTexelToLinear', parameters.mapEncoding ) : '',
  10331. parameters.matcapEncoding ? getTexelDecodingFunction( 'matcapTexelToLinear', parameters.matcapEncoding ) : '',
  10332. parameters.envMapEncoding ? getTexelDecodingFunction( 'envMapTexelToLinear', parameters.envMapEncoding ) : '',
  10333. parameters.emissiveMapEncoding ? getTexelDecodingFunction( 'emissiveMapTexelToLinear', parameters.emissiveMapEncoding ) : '',
  10334. parameters.outputEncoding ? getTexelEncodingFunction( 'linearToOutputTexel', parameters.outputEncoding ) : '',
  10335. parameters.depthPacking ? '#define DEPTH_PACKING ' + material.depthPacking : '',
  10336. '\n'
  10337. ].filter( filterEmptyLine ).join( '\n' );
  10338. }
  10339. vertexShader = parseIncludes( vertexShader );
  10340. vertexShader = replaceLightNums( vertexShader, parameters );
  10341. vertexShader = replaceClippingPlaneNums( vertexShader, parameters );
  10342. fragmentShader = parseIncludes( fragmentShader );
  10343. fragmentShader = replaceLightNums( fragmentShader, parameters );
  10344. fragmentShader = replaceClippingPlaneNums( fragmentShader, parameters );
  10345. vertexShader = unrollLoops( vertexShader );
  10346. fragmentShader = unrollLoops( fragmentShader );
  10347. if ( capabilities.isWebGL2 && ! material.isRawShaderMaterial ) {
  10348. var isGLSL3ShaderMaterial = false;
  10349. var versionRegex = /^\s*#version\s+300\s+es\s*\n/;
  10350. if ( material.isShaderMaterial &&
  10351. vertexShader.match( versionRegex ) !== null &&
  10352. fragmentShader.match( versionRegex ) !== null ) {
  10353. isGLSL3ShaderMaterial = true;
  10354. vertexShader = vertexShader.replace( versionRegex, '' );
  10355. fragmentShader = fragmentShader.replace( versionRegex, '' );
  10356. }
  10357. // GLSL 3.0 conversion
  10358. prefixVertex = [
  10359. '#version 300 es\n',
  10360. '#define attribute in',
  10361. '#define varying out',
  10362. '#define texture2D texture'
  10363. ].join( '\n' ) + '\n' + prefixVertex;
  10364. prefixFragment = [
  10365. '#version 300 es\n',
  10366. '#define varying in',
  10367. isGLSL3ShaderMaterial ? '' : 'out highp vec4 pc_fragColor;',
  10368. isGLSL3ShaderMaterial ? '' : '#define gl_FragColor pc_fragColor',
  10369. '#define gl_FragDepthEXT gl_FragDepth',
  10370. '#define texture2D texture',
  10371. '#define textureCube texture',
  10372. '#define texture2DProj textureProj',
  10373. '#define texture2DLodEXT textureLod',
  10374. '#define texture2DProjLodEXT textureProjLod',
  10375. '#define textureCubeLodEXT textureLod',
  10376. '#define texture2DGradEXT textureGrad',
  10377. '#define texture2DProjGradEXT textureProjGrad',
  10378. '#define textureCubeGradEXT textureGrad'
  10379. ].join( '\n' ) + '\n' + prefixFragment;
  10380. }
  10381. var vertexGlsl = prefixVertex + vertexShader;
  10382. var fragmentGlsl = prefixFragment + fragmentShader;
  10383. // console.log( '*VERTEX*', vertexGlsl );
  10384. // console.log( '*FRAGMENT*', fragmentGlsl );
  10385. var glVertexShader = WebGLShader( gl, 35633, vertexGlsl, renderer.debug.checkShaderErrors );
  10386. var glFragmentShader = WebGLShader( gl, 35632, fragmentGlsl, renderer.debug.checkShaderErrors );
  10387. gl.attachShader( program, glVertexShader );
  10388. gl.attachShader( program, glFragmentShader );
  10389. // Force a particular attribute to index 0.
  10390. if ( material.index0AttributeName !== undefined ) {
  10391. gl.bindAttribLocation( program, 0, material.index0AttributeName );
  10392. } else if ( parameters.morphTargets === true ) {
  10393. // programs with morphTargets displace position out of attribute 0
  10394. gl.bindAttribLocation( program, 0, 'position' );
  10395. }
  10396. gl.linkProgram( program );
  10397. // check for link errors
  10398. if ( renderer.debug.checkShaderErrors ) {
  10399. var programLog = gl.getProgramInfoLog( program ).trim();
  10400. var vertexLog = gl.getShaderInfoLog( glVertexShader ).trim();
  10401. var fragmentLog = gl.getShaderInfoLog( glFragmentShader ).trim();
  10402. var runnable = true;
  10403. var haveDiagnostics = true;
  10404. // console.log( '**VERTEX**', gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( glVertexShader ) );
  10405. // console.log( '**FRAGMENT**', gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( glFragmentShader ) );
  10406. if ( gl.getProgramParameter( program, 35714 ) === false ) {
  10407. runnable = false;
  10408. console.error( 'THREE.WebGLProgram: shader error: ', gl.getError(), '35715', gl.getProgramParameter( program, 35715 ), 'gl.getProgramInfoLog', programLog, vertexLog, fragmentLog );
  10409. } else if ( programLog !== '' ) {
  10410. console.warn( 'THREE.WebGLProgram: gl.getProgramInfoLog()', programLog );
  10411. } else if ( vertexLog === '' || fragmentLog === '' ) {
  10412. haveDiagnostics = false;
  10413. }
  10414. if ( haveDiagnostics ) {
  10415. this.diagnostics = {
  10416. runnable: runnable,
  10417. material: material,
  10418. programLog: programLog,
  10419. vertexShader: {
  10420. log: vertexLog,
  10421. prefix: prefixVertex
  10422. },
  10423. fragmentShader: {
  10424. log: fragmentLog,
  10425. prefix: prefixFragment
  10426. }
  10427. };
  10428. }
  10429. }
  10430. // clean up
  10431. gl.deleteShader( glVertexShader );
  10432. gl.deleteShader( glFragmentShader );
  10433. // set up caching for uniform locations
  10434. var cachedUniforms;
  10435. this.getUniforms = function () {
  10436. if ( cachedUniforms === undefined ) {
  10437. cachedUniforms = new WebGLUniforms( gl, program, textures );
  10438. }
  10439. return cachedUniforms;
  10440. };
  10441. // set up caching for attribute locations
  10442. var cachedAttributes;
  10443. this.getAttributes = function () {
  10444. if ( cachedAttributes === undefined ) {
  10445. cachedAttributes = fetchAttributeLocations( gl, program );
  10446. }
  10447. return cachedAttributes;
  10448. };
  10449. // free resource
  10450. this.destroy = function () {
  10451. gl.deleteProgram( program );
  10452. this.program = undefined;
  10453. };
  10454. // DEPRECATED
  10455. Object.defineProperties( this, {
  10456. uniforms: {
  10457. get: function () {
  10458. console.warn( 'THREE.WebGLProgram: .uniforms is now .getUniforms().' );
  10459. return this.getUniforms();
  10460. }
  10461. },
  10462. attributes: {
  10463. get: function () {
  10464. console.warn( 'THREE.WebGLProgram: .attributes is now .getAttributes().' );
  10465. return this.getAttributes();
  10466. }
  10467. }
  10468. } );
  10469. //
  10470. this.name = shader.name;
  10471. this.id = programIdCount ++;
  10472. this.code = code;
  10473. this.usedTimes = 1;
  10474. this.program = program;
  10475. this.vertexShader = glVertexShader;
  10476. this.fragmentShader = glFragmentShader;
  10477. return this;
  10478. }
  10479. /**
  10480. * @author mrdoob / http://mrdoob.com/
  10481. */
  10482. function WebGLPrograms( renderer, extensions, capabilities, textures ) {
  10483. var programs = [];
  10484. var shaderIDs = {
  10485. MeshDepthMaterial: 'depth',
  10486. MeshDistanceMaterial: 'distanceRGBA',
  10487. MeshNormalMaterial: 'normal',
  10488. MeshBasicMaterial: 'basic',
  10489. MeshLambertMaterial: 'lambert',
  10490. MeshPhongMaterial: 'phong',
  10491. MeshToonMaterial: 'phong',
  10492. MeshStandardMaterial: 'physical',
  10493. MeshPhysicalMaterial: 'physical',
  10494. MeshMatcapMaterial: 'matcap',
  10495. LineBasicMaterial: 'basic',
  10496. LineDashedMaterial: 'dashed',
  10497. PointsMaterial: 'points',
  10498. ShadowMaterial: 'shadow',
  10499. SpriteMaterial: 'sprite'
  10500. };
  10501. var parameterNames = [
  10502. "precision", "supportsVertexTextures", "map", "mapEncoding", "matcap", "matcapEncoding", "envMap", "envMapMode", "envMapEncoding",
  10503. "lightMap", "aoMap", "emissiveMap", "emissiveMapEncoding", "bumpMap", "normalMap", "objectSpaceNormalMap", "displacementMap", "specularMap",
  10504. "roughnessMap", "metalnessMap", "gradientMap",
  10505. "alphaMap", "combine", "vertexColors", "vertexTangents", "fog", "useFog", "fogExp",
  10506. "flatShading", "sizeAttenuation", "logarithmicDepthBuffer", "skinning",
  10507. "maxBones", "useVertexTexture", "morphTargets", "morphNormals",
  10508. "maxMorphTargets", "maxMorphNormals", "premultipliedAlpha",
  10509. "numDirLights", "numPointLights", "numSpotLights", "numHemiLights", "numRectAreaLights",
  10510. "shadowMapEnabled", "shadowMapType", "toneMapping", 'physicallyCorrectLights',
  10511. "alphaTest", "doubleSided", "flipSided", "numClippingPlanes", "numClipIntersection", "depthPacking", "dithering"
  10512. ];
  10513. function allocateBones( object ) {
  10514. var skeleton = object.skeleton;
  10515. var bones = skeleton.bones;
  10516. if ( capabilities.floatVertexTextures ) {
  10517. return 1024;
  10518. } else {
  10519. // default for when object is not specified
  10520. // ( for example when prebuilding shader to be used with multiple objects )
  10521. //
  10522. // - leave some extra space for other uniforms
  10523. // - limit here is ANGLE's 254 max uniform vectors
  10524. // (up to 54 should be safe)
  10525. var nVertexUniforms = capabilities.maxVertexUniforms;
  10526. var nVertexMatrices = Math.floor( ( nVertexUniforms - 20 ) / 4 );
  10527. var maxBones = Math.min( nVertexMatrices, bones.length );
  10528. if ( maxBones < bones.length ) {
  10529. console.warn( 'THREE.WebGLRenderer: Skeleton has ' + bones.length + ' bones. This GPU supports ' + maxBones + '.' );
  10530. return 0;
  10531. }
  10532. return maxBones;
  10533. }
  10534. }
  10535. function getTextureEncodingFromMap( map, gammaOverrideLinear ) {
  10536. var encoding;
  10537. if ( ! map ) {
  10538. encoding = LinearEncoding;
  10539. } else if ( map.isTexture ) {
  10540. encoding = map.encoding;
  10541. } else if ( map.isWebGLRenderTarget ) {
  10542. console.warn( "THREE.WebGLPrograms.getTextureEncodingFromMap: don't use render targets as textures. Use their .texture property instead." );
  10543. encoding = map.texture.encoding;
  10544. }
  10545. // add backwards compatibility for WebGLRenderer.gammaInput/gammaOutput parameter, should probably be removed at some point.
  10546. if ( encoding === LinearEncoding && gammaOverrideLinear ) {
  10547. encoding = GammaEncoding;
  10548. }
  10549. return encoding;
  10550. }
  10551. this.getParameters = function ( material, lights, shadows, fog, nClipPlanes, nClipIntersection, object ) {
  10552. var shaderID = shaderIDs[ material.type ];
  10553. // heuristics to create shader parameters according to lights in the scene
  10554. // (not to blow over maxLights budget)
  10555. var maxBones = object.isSkinnedMesh ? allocateBones( object ) : 0;
  10556. var precision = capabilities.precision;
  10557. if ( material.precision !== null ) {
  10558. precision = capabilities.getMaxPrecision( material.precision );
  10559. if ( precision !== material.precision ) {
  10560. console.warn( 'THREE.WebGLProgram.getParameters:', material.precision, 'not supported, using', precision, 'instead.' );
  10561. }
  10562. }
  10563. var currentRenderTarget = renderer.getRenderTarget();
  10564. var parameters = {
  10565. shaderID: shaderID,
  10566. precision: precision,
  10567. supportsVertexTextures: capabilities.vertexTextures,
  10568. outputEncoding: getTextureEncodingFromMap( ( ! currentRenderTarget ) ? null : currentRenderTarget.texture, renderer.gammaOutput ),
  10569. map: !! material.map,
  10570. mapEncoding: getTextureEncodingFromMap( material.map, renderer.gammaInput ),
  10571. matcap: !! material.matcap,
  10572. matcapEncoding: getTextureEncodingFromMap( material.matcap, renderer.gammaInput ),
  10573. envMap: !! material.envMap,
  10574. envMapMode: material.envMap && material.envMap.mapping,
  10575. envMapEncoding: getTextureEncodingFromMap( material.envMap, renderer.gammaInput ),
  10576. envMapCubeUV: ( !! material.envMap ) && ( ( material.envMap.mapping === CubeUVReflectionMapping ) || ( material.envMap.mapping === CubeUVRefractionMapping ) ),
  10577. lightMap: !! material.lightMap,
  10578. aoMap: !! material.aoMap,
  10579. emissiveMap: !! material.emissiveMap,
  10580. emissiveMapEncoding: getTextureEncodingFromMap( material.emissiveMap, renderer.gammaInput ),
  10581. bumpMap: !! material.bumpMap,
  10582. normalMap: !! material.normalMap,
  10583. objectSpaceNormalMap: material.normalMapType === ObjectSpaceNormalMap,
  10584. displacementMap: !! material.displacementMap,
  10585. roughnessMap: !! material.roughnessMap,
  10586. metalnessMap: !! material.metalnessMap,
  10587. specularMap: !! material.specularMap,
  10588. alphaMap: !! material.alphaMap,
  10589. gradientMap: !! material.gradientMap,
  10590. combine: material.combine,
  10591. vertexTangents: ( material.normalMap && material.vertexTangents ),
  10592. vertexColors: material.vertexColors,
  10593. fog: !! fog,
  10594. useFog: material.fog,
  10595. fogExp: ( fog && fog.isFogExp2 ),
  10596. flatShading: material.flatShading,
  10597. sizeAttenuation: material.sizeAttenuation,
  10598. logarithmicDepthBuffer: capabilities.logarithmicDepthBuffer,
  10599. skinning: material.skinning && maxBones > 0,
  10600. maxBones: maxBones,
  10601. useVertexTexture: capabilities.floatVertexTextures,
  10602. morphTargets: material.morphTargets,
  10603. morphNormals: material.morphNormals,
  10604. maxMorphTargets: renderer.maxMorphTargets,
  10605. maxMorphNormals: renderer.maxMorphNormals,
  10606. numDirLights: lights.directional.length,
  10607. numPointLights: lights.point.length,
  10608. numSpotLights: lights.spot.length,
  10609. numRectAreaLights: lights.rectArea.length,
  10610. numHemiLights: lights.hemi.length,
  10611. numClippingPlanes: nClipPlanes,
  10612. numClipIntersection: nClipIntersection,
  10613. dithering: material.dithering,
  10614. shadowMapEnabled: renderer.shadowMap.enabled && object.receiveShadow && shadows.length > 0,
  10615. shadowMapType: renderer.shadowMap.type,
  10616. toneMapping: renderer.toneMapping,
  10617. physicallyCorrectLights: renderer.physicallyCorrectLights,
  10618. premultipliedAlpha: material.premultipliedAlpha,
  10619. alphaTest: material.alphaTest,
  10620. doubleSided: material.side === DoubleSide,
  10621. flipSided: material.side === BackSide,
  10622. depthPacking: ( material.depthPacking !== undefined ) ? material.depthPacking : false
  10623. };
  10624. return parameters;
  10625. };
  10626. this.getProgramCode = function ( material, parameters ) {
  10627. var array = [];
  10628. if ( parameters.shaderID ) {
  10629. array.push( parameters.shaderID );
  10630. } else {
  10631. array.push( material.fragmentShader );
  10632. array.push( material.vertexShader );
  10633. }
  10634. if ( material.defines !== undefined ) {
  10635. for ( var name in material.defines ) {
  10636. array.push( name );
  10637. array.push( material.defines[ name ] );
  10638. }
  10639. }
  10640. for ( var i = 0; i < parameterNames.length; i ++ ) {
  10641. array.push( parameters[ parameterNames[ i ] ] );
  10642. }
  10643. array.push( material.onBeforeCompile.toString() );
  10644. array.push( renderer.gammaOutput );
  10645. array.push( renderer.gammaFactor );
  10646. return array.join();
  10647. };
  10648. this.acquireProgram = function ( material, shader, parameters, code ) {
  10649. var program;
  10650. // Check if code has been already compiled
  10651. for ( var p = 0, pl = programs.length; p < pl; p ++ ) {
  10652. var programInfo = programs[ p ];
  10653. if ( programInfo.code === code ) {
  10654. program = programInfo;
  10655. ++ program.usedTimes;
  10656. break;
  10657. }
  10658. }
  10659. if ( program === undefined ) {
  10660. program = new WebGLProgram( renderer, extensions, code, material, shader, parameters, capabilities, textures );
  10661. programs.push( program );
  10662. }
  10663. return program;
  10664. };
  10665. this.releaseProgram = function ( program ) {
  10666. if ( -- program.usedTimes === 0 ) {
  10667. // Remove from unordered set
  10668. var i = programs.indexOf( program );
  10669. programs[ i ] = programs[ programs.length - 1 ];
  10670. programs.pop();
  10671. // Free WebGL resources
  10672. program.destroy();
  10673. }
  10674. };
  10675. // Exposed for resource monitoring & error feedback via renderer.info:
  10676. this.programs = programs;
  10677. }
  10678. /**
  10679. * @author fordacious / fordacious.github.io
  10680. */
  10681. function WebGLProperties() {
  10682. var properties = new WeakMap();
  10683. function get( object ) {
  10684. var map = properties.get( object );
  10685. if ( map === undefined ) {
  10686. map = {};
  10687. properties.set( object, map );
  10688. }
  10689. return map;
  10690. }
  10691. function remove( object ) {
  10692. properties.delete( object );
  10693. }
  10694. function update( object, key, value ) {
  10695. properties.get( object )[ key ] = value;
  10696. }
  10697. function dispose() {
  10698. properties = new WeakMap();
  10699. }
  10700. return {
  10701. get: get,
  10702. remove: remove,
  10703. update: update,
  10704. dispose: dispose
  10705. };
  10706. }
  10707. /**
  10708. * @author mrdoob / http://mrdoob.com/
  10709. */
  10710. function painterSortStable( a, b ) {
  10711. if ( a.groupOrder !== b.groupOrder ) {
  10712. return a.groupOrder - b.groupOrder;
  10713. } else if ( a.renderOrder !== b.renderOrder ) {
  10714. return a.renderOrder - b.renderOrder;
  10715. } else if ( a.program !== b.program ) {
  10716. return a.program.id - b.program.id;
  10717. } else if ( a.material.id !== b.material.id ) {
  10718. return a.material.id - b.material.id;
  10719. } else if ( a.z !== b.z ) {
  10720. return a.z - b.z;
  10721. } else {
  10722. return a.id - b.id;
  10723. }
  10724. }
  10725. function reversePainterSortStable( a, b ) {
  10726. if ( a.groupOrder !== b.groupOrder ) {
  10727. return a.groupOrder - b.groupOrder;
  10728. } else if ( a.renderOrder !== b.renderOrder ) {
  10729. return a.renderOrder - b.renderOrder;
  10730. } else if ( a.z !== b.z ) {
  10731. return b.z - a.z;
  10732. } else {
  10733. return a.id - b.id;
  10734. }
  10735. }
  10736. function WebGLRenderList() {
  10737. var renderItems = [];
  10738. var renderItemsIndex = 0;
  10739. var opaque = [];
  10740. var transparent = [];
  10741. var defaultProgram = { id: - 1 };
  10742. function init() {
  10743. renderItemsIndex = 0;
  10744. opaque.length = 0;
  10745. transparent.length = 0;
  10746. }
  10747. function getNextRenderItem( object, geometry, material, groupOrder, z, group ) {
  10748. var renderItem = renderItems[ renderItemsIndex ];
  10749. if ( renderItem === undefined ) {
  10750. renderItem = {
  10751. id: object.id,
  10752. object: object,
  10753. geometry: geometry,
  10754. material: material,
  10755. program: material.program || defaultProgram,
  10756. groupOrder: groupOrder,
  10757. renderOrder: object.renderOrder,
  10758. z: z,
  10759. group: group
  10760. };
  10761. renderItems[ renderItemsIndex ] = renderItem;
  10762. } else {
  10763. renderItem.id = object.id;
  10764. renderItem.object = object;
  10765. renderItem.geometry = geometry;
  10766. renderItem.material = material;
  10767. renderItem.program = material.program || defaultProgram;
  10768. renderItem.groupOrder = groupOrder;
  10769. renderItem.renderOrder = object.renderOrder;
  10770. renderItem.z = z;
  10771. renderItem.group = group;
  10772. }
  10773. renderItemsIndex ++;
  10774. return renderItem;
  10775. }
  10776. function push( object, geometry, material, groupOrder, z, group ) {
  10777. var renderItem = getNextRenderItem( object, geometry, material, groupOrder, z, group );
  10778. ( material.transparent === true ? transparent : opaque ).push( renderItem );
  10779. }
  10780. function unshift( object, geometry, material, groupOrder, z, group ) {
  10781. var renderItem = getNextRenderItem( object, geometry, material, groupOrder, z, group );
  10782. ( material.transparent === true ? transparent : opaque ).unshift( renderItem );
  10783. }
  10784. function sort() {
  10785. if ( opaque.length > 1 ) opaque.sort( painterSortStable );
  10786. if ( transparent.length > 1 ) transparent.sort( reversePainterSortStable );
  10787. }
  10788. return {
  10789. opaque: opaque,
  10790. transparent: transparent,
  10791. init: init,
  10792. push: push,
  10793. unshift: unshift,
  10794. sort: sort
  10795. };
  10796. }
  10797. function WebGLRenderLists() {
  10798. var lists = {};
  10799. function onSceneDispose( event ) {
  10800. var scene = event.target;
  10801. scene.removeEventListener( 'dispose', onSceneDispose );
  10802. delete lists[ scene.id ];
  10803. }
  10804. function get( scene, camera ) {
  10805. var cameras = lists[ scene.id ];
  10806. var list;
  10807. if ( cameras === undefined ) {
  10808. list = new WebGLRenderList();
  10809. lists[ scene.id ] = {};
  10810. lists[ scene.id ][ camera.id ] = list;
  10811. scene.addEventListener( 'dispose', onSceneDispose );
  10812. } else {
  10813. list = cameras[ camera.id ];
  10814. if ( list === undefined ) {
  10815. list = new WebGLRenderList();
  10816. cameras[ camera.id ] = list;
  10817. }
  10818. }
  10819. return list;
  10820. }
  10821. function dispose() {
  10822. lists = {};
  10823. }
  10824. return {
  10825. get: get,
  10826. dispose: dispose
  10827. };
  10828. }
  10829. /**
  10830. * @author mrdoob / http://mrdoob.com/
  10831. */
  10832. function UniformsCache() {
  10833. var lights = {};
  10834. return {
  10835. get: function ( light ) {
  10836. if ( lights[ light.id ] !== undefined ) {
  10837. return lights[ light.id ];
  10838. }
  10839. var uniforms;
  10840. switch ( light.type ) {
  10841. case 'DirectionalLight':
  10842. uniforms = {
  10843. direction: new Vector3(),
  10844. color: new Color(),
  10845. shadow: false,
  10846. shadowBias: 0,
  10847. shadowRadius: 1,
  10848. shadowMapSize: new Vector2()
  10849. };
  10850. break;
  10851. case 'SpotLight':
  10852. uniforms = {
  10853. position: new Vector3(),
  10854. direction: new Vector3(),
  10855. color: new Color(),
  10856. distance: 0,
  10857. coneCos: 0,
  10858. penumbraCos: 0,
  10859. decay: 0,
  10860. shadow: false,
  10861. shadowBias: 0,
  10862. shadowRadius: 1,
  10863. shadowMapSize: new Vector2()
  10864. };
  10865. break;
  10866. case 'PointLight':
  10867. uniforms = {
  10868. position: new Vector3(),
  10869. color: new Color(),
  10870. distance: 0,
  10871. decay: 0,
  10872. shadow: false,
  10873. shadowBias: 0,
  10874. shadowRadius: 1,
  10875. shadowMapSize: new Vector2(),
  10876. shadowCameraNear: 1,
  10877. shadowCameraFar: 1000
  10878. };
  10879. break;
  10880. case 'HemisphereLight':
  10881. uniforms = {
  10882. direction: new Vector3(),
  10883. skyColor: new Color(),
  10884. groundColor: new Color()
  10885. };
  10886. break;
  10887. case 'RectAreaLight':
  10888. uniforms = {
  10889. color: new Color(),
  10890. position: new Vector3(),
  10891. halfWidth: new Vector3(),
  10892. halfHeight: new Vector3()
  10893. // TODO (abelnation): set RectAreaLight shadow uniforms
  10894. };
  10895. break;
  10896. }
  10897. lights[ light.id ] = uniforms;
  10898. return uniforms;
  10899. }
  10900. };
  10901. }
  10902. var count = 0;
  10903. function WebGLLights() {
  10904. var cache = new UniformsCache();
  10905. var state = {
  10906. id: count ++,
  10907. hash: {
  10908. stateID: - 1,
  10909. directionalLength: - 1,
  10910. pointLength: - 1,
  10911. spotLength: - 1,
  10912. rectAreaLength: - 1,
  10913. hemiLength: - 1,
  10914. shadowsLength: - 1
  10915. },
  10916. ambient: [ 0, 0, 0 ],
  10917. probe: [],
  10918. directional: [],
  10919. directionalShadowMap: [],
  10920. directionalShadowMatrix: [],
  10921. spot: [],
  10922. spotShadowMap: [],
  10923. spotShadowMatrix: [],
  10924. rectArea: [],
  10925. point: [],
  10926. pointShadowMap: [],
  10927. pointShadowMatrix: [],
  10928. hemi: []
  10929. };
  10930. for ( var i = 0; i < 9; i ++ ) state.probe.push( new Vector3() );
  10931. var vector3 = new Vector3();
  10932. var matrix4 = new Matrix4();
  10933. var matrix42 = new Matrix4();
  10934. function setup( lights, shadows, camera ) {
  10935. var r = 0, g = 0, b = 0;
  10936. for ( var i = 0; i < 9; i ++ ) state.probe[ i ].set( 0, 0, 0 );
  10937. var directionalLength = 0;
  10938. var pointLength = 0;
  10939. var spotLength = 0;
  10940. var rectAreaLength = 0;
  10941. var hemiLength = 0;
  10942. var viewMatrix = camera.matrixWorldInverse;
  10943. for ( var i = 0, l = lights.length; i < l; i ++ ) {
  10944. var light = lights[ i ];
  10945. var color = light.color;
  10946. var intensity = light.intensity;
  10947. var distance = light.distance;
  10948. var shadowMap = ( light.shadow && light.shadow.map ) ? light.shadow.map.texture : null;
  10949. if ( light.isAmbientLight ) {
  10950. r += color.r * intensity;
  10951. g += color.g * intensity;
  10952. b += color.b * intensity;
  10953. } else if ( light.isLightProbe ) {
  10954. for ( var j = 0; j < 9; j ++ ) {
  10955. state.probe[ j ].addScaledVector( light.sh.coefficients[ j ], intensity );
  10956. }
  10957. } else if ( light.isDirectionalLight ) {
  10958. var uniforms = cache.get( light );
  10959. uniforms.color.copy( light.color ).multiplyScalar( light.intensity );
  10960. uniforms.direction.setFromMatrixPosition( light.matrixWorld );
  10961. vector3.setFromMatrixPosition( light.target.matrixWorld );
  10962. uniforms.direction.sub( vector3 );
  10963. uniforms.direction.transformDirection( viewMatrix );
  10964. uniforms.shadow = light.castShadow;
  10965. if ( light.castShadow ) {
  10966. var shadow = light.shadow;
  10967. uniforms.shadowBias = shadow.bias;
  10968. uniforms.shadowRadius = shadow.radius;
  10969. uniforms.shadowMapSize = shadow.mapSize;
  10970. }
  10971. state.directionalShadowMap[ directionalLength ] = shadowMap;
  10972. state.directionalShadowMatrix[ directionalLength ] = light.shadow.matrix;
  10973. state.directional[ directionalLength ] = uniforms;
  10974. directionalLength ++;
  10975. } else if ( light.isSpotLight ) {
  10976. var uniforms = cache.get( light );
  10977. uniforms.position.setFromMatrixPosition( light.matrixWorld );
  10978. uniforms.position.applyMatrix4( viewMatrix );
  10979. uniforms.color.copy( color ).multiplyScalar( intensity );
  10980. uniforms.distance = distance;
  10981. uniforms.direction.setFromMatrixPosition( light.matrixWorld );
  10982. vector3.setFromMatrixPosition( light.target.matrixWorld );
  10983. uniforms.direction.sub( vector3 );
  10984. uniforms.direction.transformDirection( viewMatrix );
  10985. uniforms.coneCos = Math.cos( light.angle );
  10986. uniforms.penumbraCos = Math.cos( light.angle * ( 1 - light.penumbra ) );
  10987. uniforms.decay = light.decay;
  10988. uniforms.shadow = light.castShadow;
  10989. if ( light.castShadow ) {
  10990. var shadow = light.shadow;
  10991. uniforms.shadowBias = shadow.bias;
  10992. uniforms.shadowRadius = shadow.radius;
  10993. uniforms.shadowMapSize = shadow.mapSize;
  10994. }
  10995. state.spotShadowMap[ spotLength ] = shadowMap;
  10996. state.spotShadowMatrix[ spotLength ] = light.shadow.matrix;
  10997. state.spot[ spotLength ] = uniforms;
  10998. spotLength ++;
  10999. } else if ( light.isRectAreaLight ) {
  11000. var uniforms = cache.get( light );
  11001. // (a) intensity is the total visible light emitted
  11002. //uniforms.color.copy( color ).multiplyScalar( intensity / ( light.width * light.height * Math.PI ) );
  11003. // (b) intensity is the brightness of the light
  11004. uniforms.color.copy( color ).multiplyScalar( intensity );
  11005. uniforms.position.setFromMatrixPosition( light.matrixWorld );
  11006. uniforms.position.applyMatrix4( viewMatrix );
  11007. // extract local rotation of light to derive width/height half vectors
  11008. matrix42.identity();
  11009. matrix4.copy( light.matrixWorld );
  11010. matrix4.premultiply( viewMatrix );
  11011. matrix42.extractRotation( matrix4 );
  11012. uniforms.halfWidth.set( light.width * 0.5, 0.0, 0.0 );
  11013. uniforms.halfHeight.set( 0.0, light.height * 0.5, 0.0 );
  11014. uniforms.halfWidth.applyMatrix4( matrix42 );
  11015. uniforms.halfHeight.applyMatrix4( matrix42 );
  11016. // TODO (abelnation): RectAreaLight distance?
  11017. // uniforms.distance = distance;
  11018. state.rectArea[ rectAreaLength ] = uniforms;
  11019. rectAreaLength ++;
  11020. } else if ( light.isPointLight ) {
  11021. var uniforms = cache.get( light );
  11022. uniforms.position.setFromMatrixPosition( light.matrixWorld );
  11023. uniforms.position.applyMatrix4( viewMatrix );
  11024. uniforms.color.copy( light.color ).multiplyScalar( light.intensity );
  11025. uniforms.distance = light.distance;
  11026. uniforms.decay = light.decay;
  11027. uniforms.shadow = light.castShadow;
  11028. if ( light.castShadow ) {
  11029. var shadow = light.shadow;
  11030. uniforms.shadowBias = shadow.bias;
  11031. uniforms.shadowRadius = shadow.radius;
  11032. uniforms.shadowMapSize = shadow.mapSize;
  11033. uniforms.shadowCameraNear = shadow.camera.near;
  11034. uniforms.shadowCameraFar = shadow.camera.far;
  11035. }
  11036. state.pointShadowMap[ pointLength ] = shadowMap;
  11037. state.pointShadowMatrix[ pointLength ] = light.shadow.matrix;
  11038. state.point[ pointLength ] = uniforms;
  11039. pointLength ++;
  11040. } else if ( light.isHemisphereLight ) {
  11041. var uniforms = cache.get( light );
  11042. uniforms.direction.setFromMatrixPosition( light.matrixWorld );
  11043. uniforms.direction.transformDirection( viewMatrix );
  11044. uniforms.direction.normalize();
  11045. uniforms.skyColor.copy( light.color ).multiplyScalar( intensity );
  11046. uniforms.groundColor.copy( light.groundColor ).multiplyScalar( intensity );
  11047. state.hemi[ hemiLength ] = uniforms;
  11048. hemiLength ++;
  11049. }
  11050. }
  11051. state.ambient[ 0 ] = r;
  11052. state.ambient[ 1 ] = g;
  11053. state.ambient[ 2 ] = b;
  11054. state.directional.length = directionalLength;
  11055. state.spot.length = spotLength;
  11056. state.rectArea.length = rectAreaLength;
  11057. state.point.length = pointLength;
  11058. state.hemi.length = hemiLength;
  11059. state.hash.stateID = state.id;
  11060. state.hash.directionalLength = directionalLength;
  11061. state.hash.pointLength = pointLength;
  11062. state.hash.spotLength = spotLength;
  11063. state.hash.rectAreaLength = rectAreaLength;
  11064. state.hash.hemiLength = hemiLength;
  11065. state.hash.shadowsLength = shadows.length;
  11066. }
  11067. return {
  11068. setup: setup,
  11069. state: state
  11070. };
  11071. }
  11072. /**
  11073. * @author Mugen87 / https://github.com/Mugen87
  11074. */
  11075. function WebGLRenderState() {
  11076. var lights = new WebGLLights();
  11077. var lightsArray = [];
  11078. var shadowsArray = [];
  11079. function init() {
  11080. lightsArray.length = 0;
  11081. shadowsArray.length = 0;
  11082. }
  11083. function pushLight( light ) {
  11084. lightsArray.push( light );
  11085. }
  11086. function pushShadow( shadowLight ) {
  11087. shadowsArray.push( shadowLight );
  11088. }
  11089. function setupLights( camera ) {
  11090. lights.setup( lightsArray, shadowsArray, camera );
  11091. }
  11092. var state = {
  11093. lightsArray: lightsArray,
  11094. shadowsArray: shadowsArray,
  11095. lights: lights
  11096. };
  11097. return {
  11098. init: init,
  11099. state: state,
  11100. setupLights: setupLights,
  11101. pushLight: pushLight,
  11102. pushShadow: pushShadow
  11103. };
  11104. }
  11105. function WebGLRenderStates() {
  11106. var renderStates = {};
  11107. function onSceneDispose( event ) {
  11108. var scene = event.target;
  11109. scene.removeEventListener( 'dispose', onSceneDispose );
  11110. delete renderStates[ scene.id ];
  11111. }
  11112. function get( scene, camera ) {
  11113. var renderState;
  11114. if ( renderStates[ scene.id ] === undefined ) {
  11115. renderState = new WebGLRenderState();
  11116. renderStates[ scene.id ] = {};
  11117. renderStates[ scene.id ][ camera.id ] = renderState;
  11118. scene.addEventListener( 'dispose', onSceneDispose );
  11119. } else {
  11120. if ( renderStates[ scene.id ][ camera.id ] === undefined ) {
  11121. renderState = new WebGLRenderState();
  11122. renderStates[ scene.id ][ camera.id ] = renderState;
  11123. } else {
  11124. renderState = renderStates[ scene.id ][ camera.id ];
  11125. }
  11126. }
  11127. return renderState;
  11128. }
  11129. function dispose() {
  11130. renderStates = {};
  11131. }
  11132. return {
  11133. get: get,
  11134. dispose: dispose
  11135. };
  11136. }
  11137. /**
  11138. * @author mrdoob / http://mrdoob.com/
  11139. * @author alteredq / http://alteredqualia.com/
  11140. * @author bhouston / https://clara.io
  11141. * @author WestLangley / http://github.com/WestLangley
  11142. *
  11143. * parameters = {
  11144. *
  11145. * opacity: <float>,
  11146. *
  11147. * map: new THREE.Texture( <Image> ),
  11148. *
  11149. * alphaMap: new THREE.Texture( <Image> ),
  11150. *
  11151. * displacementMap: new THREE.Texture( <Image> ),
  11152. * displacementScale: <float>,
  11153. * displacementBias: <float>,
  11154. *
  11155. * wireframe: <boolean>,
  11156. * wireframeLinewidth: <float>
  11157. * }
  11158. */
  11159. function MeshDepthMaterial( parameters ) {
  11160. Material.call( this );
  11161. this.type = 'MeshDepthMaterial';
  11162. this.depthPacking = BasicDepthPacking;
  11163. this.skinning = false;
  11164. this.morphTargets = false;
  11165. this.map = null;
  11166. this.alphaMap = null;
  11167. this.displacementMap = null;
  11168. this.displacementScale = 1;
  11169. this.displacementBias = 0;
  11170. this.wireframe = false;
  11171. this.wireframeLinewidth = 1;
  11172. this.fog = false;
  11173. this.lights = false;
  11174. this.setValues( parameters );
  11175. }
  11176. MeshDepthMaterial.prototype = Object.create( Material.prototype );
  11177. MeshDepthMaterial.prototype.constructor = MeshDepthMaterial;
  11178. MeshDepthMaterial.prototype.isMeshDepthMaterial = true;
  11179. MeshDepthMaterial.prototype.copy = function ( source ) {
  11180. Material.prototype.copy.call( this, source );
  11181. this.depthPacking = source.depthPacking;
  11182. this.skinning = source.skinning;
  11183. this.morphTargets = source.morphTargets;
  11184. this.map = source.map;
  11185. this.alphaMap = source.alphaMap;
  11186. this.displacementMap = source.displacementMap;
  11187. this.displacementScale = source.displacementScale;
  11188. this.displacementBias = source.displacementBias;
  11189. this.wireframe = source.wireframe;
  11190. this.wireframeLinewidth = source.wireframeLinewidth;
  11191. return this;
  11192. };
  11193. /**
  11194. * @author WestLangley / http://github.com/WestLangley
  11195. *
  11196. * parameters = {
  11197. *
  11198. * referencePosition: <float>,
  11199. * nearDistance: <float>,
  11200. * farDistance: <float>,
  11201. *
  11202. * skinning: <bool>,
  11203. * morphTargets: <bool>,
  11204. *
  11205. * map: new THREE.Texture( <Image> ),
  11206. *
  11207. * alphaMap: new THREE.Texture( <Image> ),
  11208. *
  11209. * displacementMap: new THREE.Texture( <Image> ),
  11210. * displacementScale: <float>,
  11211. * displacementBias: <float>
  11212. *
  11213. * }
  11214. */
  11215. function MeshDistanceMaterial( parameters ) {
  11216. Material.call( this );
  11217. this.type = 'MeshDistanceMaterial';
  11218. this.referencePosition = new Vector3();
  11219. this.nearDistance = 1;
  11220. this.farDistance = 1000;
  11221. this.skinning = false;
  11222. this.morphTargets = false;
  11223. this.map = null;
  11224. this.alphaMap = null;
  11225. this.displacementMap = null;
  11226. this.displacementScale = 1;
  11227. this.displacementBias = 0;
  11228. this.fog = false;
  11229. this.lights = false;
  11230. this.setValues( parameters );
  11231. }
  11232. MeshDistanceMaterial.prototype = Object.create( Material.prototype );
  11233. MeshDistanceMaterial.prototype.constructor = MeshDistanceMaterial;
  11234. MeshDistanceMaterial.prototype.isMeshDistanceMaterial = true;
  11235. MeshDistanceMaterial.prototype.copy = function ( source ) {
  11236. Material.prototype.copy.call( this, source );
  11237. this.referencePosition.copy( source.referencePosition );
  11238. this.nearDistance = source.nearDistance;
  11239. this.farDistance = source.farDistance;
  11240. this.skinning = source.skinning;
  11241. this.morphTargets = source.morphTargets;
  11242. this.map = source.map;
  11243. this.alphaMap = source.alphaMap;
  11244. this.displacementMap = source.displacementMap;
  11245. this.displacementScale = source.displacementScale;
  11246. this.displacementBias = source.displacementBias;
  11247. return this;
  11248. };
  11249. /**
  11250. * @author alteredq / http://alteredqualia.com/
  11251. * @author mrdoob / http://mrdoob.com/
  11252. */
  11253. function WebGLShadowMap( _renderer, _objects, maxTextureSize ) {
  11254. var _frustum = new Frustum(),
  11255. _projScreenMatrix = new Matrix4(),
  11256. _shadowMapSize = new Vector2(),
  11257. _maxShadowMapSize = new Vector2( maxTextureSize, maxTextureSize ),
  11258. _lookTarget = new Vector3(),
  11259. _lightPositionWorld = new Vector3(),
  11260. _MorphingFlag = 1,
  11261. _SkinningFlag = 2,
  11262. _NumberOfMaterialVariants = ( _MorphingFlag | _SkinningFlag ) + 1,
  11263. _depthMaterials = new Array( _NumberOfMaterialVariants ),
  11264. _distanceMaterials = new Array( _NumberOfMaterialVariants ),
  11265. _materialCache = {};
  11266. var shadowSide = { 0: BackSide, 1: FrontSide, 2: DoubleSide };
  11267. var cubeDirections = [
  11268. new Vector3( 1, 0, 0 ), new Vector3( - 1, 0, 0 ), new Vector3( 0, 0, 1 ),
  11269. new Vector3( 0, 0, - 1 ), new Vector3( 0, 1, 0 ), new Vector3( 0, - 1, 0 )
  11270. ];
  11271. var cubeUps = [
  11272. new Vector3( 0, 1, 0 ), new Vector3( 0, 1, 0 ), new Vector3( 0, 1, 0 ),
  11273. new Vector3( 0, 1, 0 ), new Vector3( 0, 0, 1 ), new Vector3( 0, 0, - 1 )
  11274. ];
  11275. var cube2DViewPorts = [
  11276. new Vector4(), new Vector4(), new Vector4(),
  11277. new Vector4(), new Vector4(), new Vector4()
  11278. ];
  11279. // init
  11280. for ( var i = 0; i !== _NumberOfMaterialVariants; ++ i ) {
  11281. var useMorphing = ( i & _MorphingFlag ) !== 0;
  11282. var useSkinning = ( i & _SkinningFlag ) !== 0;
  11283. var depthMaterial = new MeshDepthMaterial( {
  11284. depthPacking: RGBADepthPacking,
  11285. morphTargets: useMorphing,
  11286. skinning: useSkinning
  11287. } );
  11288. _depthMaterials[ i ] = depthMaterial;
  11289. //
  11290. var distanceMaterial = new MeshDistanceMaterial( {
  11291. morphTargets: useMorphing,
  11292. skinning: useSkinning
  11293. } );
  11294. _distanceMaterials[ i ] = distanceMaterial;
  11295. }
  11296. //
  11297. var scope = this;
  11298. this.enabled = false;
  11299. this.autoUpdate = true;
  11300. this.needsUpdate = false;
  11301. this.type = PCFShadowMap;
  11302. this.render = function ( lights, scene, camera ) {
  11303. if ( scope.enabled === false ) return;
  11304. if ( scope.autoUpdate === false && scope.needsUpdate === false ) return;
  11305. if ( lights.length === 0 ) return;
  11306. var currentRenderTarget = _renderer.getRenderTarget();
  11307. var _state = _renderer.state;
  11308. // Set GL state for depth map.
  11309. _state.setBlending( NoBlending );
  11310. _state.buffers.color.setClear( 1, 1, 1, 1 );
  11311. _state.buffers.depth.setTest( true );
  11312. _state.setScissorTest( false );
  11313. // render depth map
  11314. var faceCount;
  11315. for ( var i = 0, il = lights.length; i < il; i ++ ) {
  11316. var light = lights[ i ];
  11317. var shadow = light.shadow;
  11318. var isPointLight = light && light.isPointLight;
  11319. if ( shadow === undefined ) {
  11320. console.warn( 'THREE.WebGLShadowMap:', light, 'has no shadow.' );
  11321. continue;
  11322. }
  11323. var shadowCamera = shadow.camera;
  11324. _shadowMapSize.copy( shadow.mapSize );
  11325. _shadowMapSize.min( _maxShadowMapSize );
  11326. if ( isPointLight ) {
  11327. var vpWidth = _shadowMapSize.x;
  11328. var vpHeight = _shadowMapSize.y;
  11329. // These viewports map a cube-map onto a 2D texture with the
  11330. // following orientation:
  11331. //
  11332. // xzXZ
  11333. // y Y
  11334. //
  11335. // X - Positive x direction
  11336. // x - Negative x direction
  11337. // Y - Positive y direction
  11338. // y - Negative y direction
  11339. // Z - Positive z direction
  11340. // z - Negative z direction
  11341. // positive X
  11342. cube2DViewPorts[ 0 ].set( vpWidth * 2, vpHeight, vpWidth, vpHeight );
  11343. // negative X
  11344. cube2DViewPorts[ 1 ].set( 0, vpHeight, vpWidth, vpHeight );
  11345. // positive Z
  11346. cube2DViewPorts[ 2 ].set( vpWidth * 3, vpHeight, vpWidth, vpHeight );
  11347. // negative Z
  11348. cube2DViewPorts[ 3 ].set( vpWidth, vpHeight, vpWidth, vpHeight );
  11349. // positive Y
  11350. cube2DViewPorts[ 4 ].set( vpWidth * 3, 0, vpWidth, vpHeight );
  11351. // negative Y
  11352. cube2DViewPorts[ 5 ].set( vpWidth, 0, vpWidth, vpHeight );
  11353. _shadowMapSize.x *= 4.0;
  11354. _shadowMapSize.y *= 2.0;
  11355. }
  11356. if ( shadow.map === null ) {
  11357. var pars = { minFilter: NearestFilter, magFilter: NearestFilter, format: RGBAFormat };
  11358. shadow.map = new WebGLRenderTarget( _shadowMapSize.x, _shadowMapSize.y, pars );
  11359. shadow.map.texture.name = light.name + ".shadowMap";
  11360. shadowCamera.updateProjectionMatrix();
  11361. }
  11362. if ( shadow.isSpotLightShadow ) {
  11363. shadow.update( light );
  11364. }
  11365. var shadowMap = shadow.map;
  11366. var shadowMatrix = shadow.matrix;
  11367. _lightPositionWorld.setFromMatrixPosition( light.matrixWorld );
  11368. shadowCamera.position.copy( _lightPositionWorld );
  11369. if ( isPointLight ) {
  11370. faceCount = 6;
  11371. // for point lights we set the shadow matrix to be a translation-only matrix
  11372. // equal to inverse of the light's position
  11373. shadowMatrix.makeTranslation( - _lightPositionWorld.x, - _lightPositionWorld.y, - _lightPositionWorld.z );
  11374. } else {
  11375. faceCount = 1;
  11376. _lookTarget.setFromMatrixPosition( light.target.matrixWorld );
  11377. shadowCamera.lookAt( _lookTarget );
  11378. shadowCamera.updateMatrixWorld();
  11379. // compute shadow matrix
  11380. shadowMatrix.set(
  11381. 0.5, 0.0, 0.0, 0.5,
  11382. 0.0, 0.5, 0.0, 0.5,
  11383. 0.0, 0.0, 0.5, 0.5,
  11384. 0.0, 0.0, 0.0, 1.0
  11385. );
  11386. shadowMatrix.multiply( shadowCamera.projectionMatrix );
  11387. shadowMatrix.multiply( shadowCamera.matrixWorldInverse );
  11388. }
  11389. _renderer.setRenderTarget( shadowMap );
  11390. _renderer.clear();
  11391. // render shadow map for each cube face (if omni-directional) or
  11392. // run a single pass if not
  11393. for ( var face = 0; face < faceCount; face ++ ) {
  11394. if ( isPointLight ) {
  11395. _lookTarget.copy( shadowCamera.position );
  11396. _lookTarget.add( cubeDirections[ face ] );
  11397. shadowCamera.up.copy( cubeUps[ face ] );
  11398. shadowCamera.lookAt( _lookTarget );
  11399. shadowCamera.updateMatrixWorld();
  11400. var vpDimensions = cube2DViewPorts[ face ];
  11401. _state.viewport( vpDimensions );
  11402. }
  11403. // update camera matrices and frustum
  11404. _projScreenMatrix.multiplyMatrices( shadowCamera.projectionMatrix, shadowCamera.matrixWorldInverse );
  11405. _frustum.setFromMatrix( _projScreenMatrix );
  11406. // set object matrices & frustum culling
  11407. renderObject( scene, camera, shadowCamera, isPointLight );
  11408. }
  11409. }
  11410. scope.needsUpdate = false;
  11411. _renderer.setRenderTarget( currentRenderTarget );
  11412. };
  11413. function getDepthMaterial( object, material, isPointLight, lightPositionWorld, shadowCameraNear, shadowCameraFar ) {
  11414. var geometry = object.geometry;
  11415. var result = null;
  11416. var materialVariants = _depthMaterials;
  11417. var customMaterial = object.customDepthMaterial;
  11418. if ( isPointLight ) {
  11419. materialVariants = _distanceMaterials;
  11420. customMaterial = object.customDistanceMaterial;
  11421. }
  11422. if ( ! customMaterial ) {
  11423. var useMorphing = false;
  11424. if ( material.morphTargets ) {
  11425. if ( geometry && geometry.isBufferGeometry ) {
  11426. useMorphing = geometry.morphAttributes && geometry.morphAttributes.position && geometry.morphAttributes.position.length > 0;
  11427. } else if ( geometry && geometry.isGeometry ) {
  11428. useMorphing = geometry.morphTargets && geometry.morphTargets.length > 0;
  11429. }
  11430. }
  11431. if ( object.isSkinnedMesh && material.skinning === false ) {
  11432. console.warn( 'THREE.WebGLShadowMap: THREE.SkinnedMesh with material.skinning set to false:', object );
  11433. }
  11434. var useSkinning = object.isSkinnedMesh && material.skinning;
  11435. var variantIndex = 0;
  11436. if ( useMorphing ) variantIndex |= _MorphingFlag;
  11437. if ( useSkinning ) variantIndex |= _SkinningFlag;
  11438. result = materialVariants[ variantIndex ];
  11439. } else {
  11440. result = customMaterial;
  11441. }
  11442. if ( _renderer.localClippingEnabled &&
  11443. material.clipShadows === true &&
  11444. material.clippingPlanes.length !== 0 ) {
  11445. // in this case we need a unique material instance reflecting the
  11446. // appropriate state
  11447. var keyA = result.uuid, keyB = material.uuid;
  11448. var materialsForVariant = _materialCache[ keyA ];
  11449. if ( materialsForVariant === undefined ) {
  11450. materialsForVariant = {};
  11451. _materialCache[ keyA ] = materialsForVariant;
  11452. }
  11453. var cachedMaterial = materialsForVariant[ keyB ];
  11454. if ( cachedMaterial === undefined ) {
  11455. cachedMaterial = result.clone();
  11456. materialsForVariant[ keyB ] = cachedMaterial;
  11457. }
  11458. result = cachedMaterial;
  11459. }
  11460. result.visible = material.visible;
  11461. result.wireframe = material.wireframe;
  11462. result.side = ( material.shadowSide != null ) ? material.shadowSide : shadowSide[ material.side ];
  11463. result.clipShadows = material.clipShadows;
  11464. result.clippingPlanes = material.clippingPlanes;
  11465. result.clipIntersection = material.clipIntersection;
  11466. result.wireframeLinewidth = material.wireframeLinewidth;
  11467. result.linewidth = material.linewidth;
  11468. if ( isPointLight && result.isMeshDistanceMaterial ) {
  11469. result.referencePosition.copy( lightPositionWorld );
  11470. result.nearDistance = shadowCameraNear;
  11471. result.farDistance = shadowCameraFar;
  11472. }
  11473. return result;
  11474. }
  11475. function renderObject( object, camera, shadowCamera, isPointLight ) {
  11476. if ( object.visible === false ) return;
  11477. var visible = object.layers.test( camera.layers );
  11478. if ( visible && ( object.isMesh || object.isLine || object.isPoints ) ) {
  11479. if ( object.castShadow && ( ! object.frustumCulled || _frustum.intersectsObject( object ) ) ) {
  11480. object.modelViewMatrix.multiplyMatrices( shadowCamera.matrixWorldInverse, object.matrixWorld );
  11481. var geometry = _objects.update( object );
  11482. var material = object.material;
  11483. if ( Array.isArray( material ) ) {
  11484. var groups = geometry.groups;
  11485. for ( var k = 0, kl = groups.length; k < kl; k ++ ) {
  11486. var group = groups[ k ];
  11487. var groupMaterial = material[ group.materialIndex ];
  11488. if ( groupMaterial && groupMaterial.visible ) {
  11489. var depthMaterial = getDepthMaterial( object, groupMaterial, isPointLight, _lightPositionWorld, shadowCamera.near, shadowCamera.far );
  11490. _renderer.renderBufferDirect( shadowCamera, null, geometry, depthMaterial, object, group );
  11491. }
  11492. }
  11493. } else if ( material.visible ) {
  11494. var depthMaterial = getDepthMaterial( object, material, isPointLight, _lightPositionWorld, shadowCamera.near, shadowCamera.far );
  11495. _renderer.renderBufferDirect( shadowCamera, null, geometry, depthMaterial, object, null );
  11496. }
  11497. }
  11498. }
  11499. var children = object.children;
  11500. for ( var i = 0, l = children.length; i < l; i ++ ) {
  11501. renderObject( children[ i ], camera, shadowCamera, isPointLight );
  11502. }
  11503. }
  11504. }
  11505. /**
  11506. * @author mrdoob / http://mrdoob.com/
  11507. */
  11508. function WebGLState( gl, extensions, utils, capabilities ) {
  11509. function ColorBuffer() {
  11510. var locked = false;
  11511. var color = new Vector4();
  11512. var currentColorMask = null;
  11513. var currentColorClear = new Vector4( 0, 0, 0, 0 );
  11514. return {
  11515. setMask: function ( colorMask ) {
  11516. if ( currentColorMask !== colorMask && ! locked ) {
  11517. gl.colorMask( colorMask, colorMask, colorMask, colorMask );
  11518. currentColorMask = colorMask;
  11519. }
  11520. },
  11521. setLocked: function ( lock ) {
  11522. locked = lock;
  11523. },
  11524. setClear: function ( r, g, b, a, premultipliedAlpha ) {
  11525. if ( premultipliedAlpha === true ) {
  11526. r *= a; g *= a; b *= a;
  11527. }
  11528. color.set( r, g, b, a );
  11529. if ( currentColorClear.equals( color ) === false ) {
  11530. gl.clearColor( r, g, b, a );
  11531. currentColorClear.copy( color );
  11532. }
  11533. },
  11534. reset: function () {
  11535. locked = false;
  11536. currentColorMask = null;
  11537. currentColorClear.set( - 1, 0, 0, 0 ); // set to invalid state
  11538. }
  11539. };
  11540. }
  11541. function DepthBuffer() {
  11542. var locked = false;
  11543. var currentDepthMask = null;
  11544. var currentDepthFunc = null;
  11545. var currentDepthClear = null;
  11546. return {
  11547. setTest: function ( depthTest ) {
  11548. if ( depthTest ) {
  11549. enable( 2929 );
  11550. } else {
  11551. disable( 2929 );
  11552. }
  11553. },
  11554. setMask: function ( depthMask ) {
  11555. if ( currentDepthMask !== depthMask && ! locked ) {
  11556. gl.depthMask( depthMask );
  11557. currentDepthMask = depthMask;
  11558. }
  11559. },
  11560. setFunc: function ( depthFunc ) {
  11561. if ( currentDepthFunc !== depthFunc ) {
  11562. if ( depthFunc ) {
  11563. switch ( depthFunc ) {
  11564. case NeverDepth:
  11565. gl.depthFunc( 512 );
  11566. break;
  11567. case AlwaysDepth:
  11568. gl.depthFunc( 519 );
  11569. break;
  11570. case LessDepth:
  11571. gl.depthFunc( 513 );
  11572. break;
  11573. case LessEqualDepth:
  11574. gl.depthFunc( 515 );
  11575. break;
  11576. case EqualDepth:
  11577. gl.depthFunc( 514 );
  11578. break;
  11579. case GreaterEqualDepth:
  11580. gl.depthFunc( 518 );
  11581. break;
  11582. case GreaterDepth:
  11583. gl.depthFunc( 516 );
  11584. break;
  11585. case NotEqualDepth:
  11586. gl.depthFunc( 517 );
  11587. break;
  11588. default:
  11589. gl.depthFunc( 515 );
  11590. }
  11591. } else {
  11592. gl.depthFunc( 515 );
  11593. }
  11594. currentDepthFunc = depthFunc;
  11595. }
  11596. },
  11597. setLocked: function ( lock ) {
  11598. locked = lock;
  11599. },
  11600. setClear: function ( depth ) {
  11601. if ( currentDepthClear !== depth ) {
  11602. gl.clearDepth( depth );
  11603. currentDepthClear = depth;
  11604. }
  11605. },
  11606. reset: function () {
  11607. locked = false;
  11608. currentDepthMask = null;
  11609. currentDepthFunc = null;
  11610. currentDepthClear = null;
  11611. }
  11612. };
  11613. }
  11614. function StencilBuffer() {
  11615. var locked = false;
  11616. var currentStencilMask = null;
  11617. var currentStencilFunc = null;
  11618. var currentStencilRef = null;
  11619. var currentStencilFuncMask = null;
  11620. var currentStencilFail = null;
  11621. var currentStencilZFail = null;
  11622. var currentStencilZPass = null;
  11623. var currentStencilClear = null;
  11624. return {
  11625. setTest: function ( stencilTest ) {
  11626. if ( stencilTest ) {
  11627. enable( 2960 );
  11628. } else {
  11629. disable( 2960 );
  11630. }
  11631. },
  11632. setMask: function ( stencilMask ) {
  11633. if ( currentStencilMask !== stencilMask && ! locked ) {
  11634. gl.stencilMask( stencilMask );
  11635. currentStencilMask = stencilMask;
  11636. }
  11637. },
  11638. setFunc: function ( stencilFunc, stencilRef, stencilMask ) {
  11639. if ( currentStencilFunc !== stencilFunc ||
  11640. currentStencilRef !== stencilRef ||
  11641. currentStencilFuncMask !== stencilMask ) {
  11642. gl.stencilFunc( stencilFunc, stencilRef, stencilMask );
  11643. currentStencilFunc = stencilFunc;
  11644. currentStencilRef = stencilRef;
  11645. currentStencilFuncMask = stencilMask;
  11646. }
  11647. },
  11648. setOp: function ( stencilFail, stencilZFail, stencilZPass ) {
  11649. if ( currentStencilFail !== stencilFail ||
  11650. currentStencilZFail !== stencilZFail ||
  11651. currentStencilZPass !== stencilZPass ) {
  11652. gl.stencilOp( stencilFail, stencilZFail, stencilZPass );
  11653. currentStencilFail = stencilFail;
  11654. currentStencilZFail = stencilZFail;
  11655. currentStencilZPass = stencilZPass;
  11656. }
  11657. },
  11658. setLocked: function ( lock ) {
  11659. locked = lock;
  11660. },
  11661. setClear: function ( stencil ) {
  11662. if ( currentStencilClear !== stencil ) {
  11663. gl.clearStencil( stencil );
  11664. currentStencilClear = stencil;
  11665. }
  11666. },
  11667. reset: function () {
  11668. locked = false;
  11669. currentStencilMask = null;
  11670. currentStencilFunc = null;
  11671. currentStencilRef = null;
  11672. currentStencilFuncMask = null;
  11673. currentStencilFail = null;
  11674. currentStencilZFail = null;
  11675. currentStencilZPass = null;
  11676. currentStencilClear = null;
  11677. }
  11678. };
  11679. }
  11680. //
  11681. var colorBuffer = new ColorBuffer();
  11682. var depthBuffer = new DepthBuffer();
  11683. var stencilBuffer = new StencilBuffer();
  11684. var maxVertexAttributes = gl.getParameter( 34921 );
  11685. var newAttributes = new Uint8Array( maxVertexAttributes );
  11686. var enabledAttributes = new Uint8Array( maxVertexAttributes );
  11687. var attributeDivisors = new Uint8Array( maxVertexAttributes );
  11688. var enabledCapabilities = {};
  11689. var compressedTextureFormats = null;
  11690. var currentProgram = null;
  11691. var currentBlendingEnabled = null;
  11692. var currentBlending = null;
  11693. var currentBlendEquation = null;
  11694. var currentBlendSrc = null;
  11695. var currentBlendDst = null;
  11696. var currentBlendEquationAlpha = null;
  11697. var currentBlendSrcAlpha = null;
  11698. var currentBlendDstAlpha = null;
  11699. var currentPremultipledAlpha = false;
  11700. var currentFlipSided = null;
  11701. var currentCullFace = null;
  11702. var currentLineWidth = null;
  11703. var currentPolygonOffsetFactor = null;
  11704. var currentPolygonOffsetUnits = null;
  11705. var maxTextures = gl.getParameter( 35661 );
  11706. var lineWidthAvailable = false;
  11707. var version = 0;
  11708. var glVersion = gl.getParameter( 7938 );
  11709. if ( glVersion.indexOf( 'WebGL' ) !== - 1 ) {
  11710. version = parseFloat( /^WebGL\ ([0-9])/.exec( glVersion )[ 1 ] );
  11711. lineWidthAvailable = ( version >= 1.0 );
  11712. } else if ( glVersion.indexOf( 'OpenGL ES' ) !== - 1 ) {
  11713. version = parseFloat( /^OpenGL\ ES\ ([0-9])/.exec( glVersion )[ 1 ] );
  11714. lineWidthAvailable = ( version >= 2.0 );
  11715. }
  11716. var currentTextureSlot = null;
  11717. var currentBoundTextures = {};
  11718. var currentScissor = new Vector4();
  11719. var currentViewport = new Vector4();
  11720. function createTexture( type, target, count ) {
  11721. var data = new Uint8Array( 4 ); // 4 is required to match default unpack alignment of 4.
  11722. var texture = gl.createTexture();
  11723. gl.bindTexture( type, texture );
  11724. gl.texParameteri( type, 10241, 9728 );
  11725. gl.texParameteri( type, 10240, 9728 );
  11726. for ( var i = 0; i < count; i ++ ) {
  11727. gl.texImage2D( target + i, 0, 6408, 1, 1, 0, 6408, 5121, data );
  11728. }
  11729. return texture;
  11730. }
  11731. var emptyTextures = {};
  11732. emptyTextures[ 3553 ] = createTexture( 3553, 3553, 1 );
  11733. emptyTextures[ 34067 ] = createTexture( 34067, 34069, 6 );
  11734. // init
  11735. colorBuffer.setClear( 0, 0, 0, 1 );
  11736. depthBuffer.setClear( 1 );
  11737. stencilBuffer.setClear( 0 );
  11738. enable( 2929 );
  11739. depthBuffer.setFunc( LessEqualDepth );
  11740. setFlipSided( false );
  11741. setCullFace( CullFaceBack );
  11742. enable( 2884 );
  11743. setBlending( NoBlending );
  11744. //
  11745. function initAttributes() {
  11746. for ( var i = 0, l = newAttributes.length; i < l; i ++ ) {
  11747. newAttributes[ i ] = 0;
  11748. }
  11749. }
  11750. function enableAttribute( attribute ) {
  11751. enableAttributeAndDivisor( attribute, 0 );
  11752. }
  11753. function enableAttributeAndDivisor( attribute, meshPerAttribute ) {
  11754. newAttributes[ attribute ] = 1;
  11755. if ( enabledAttributes[ attribute ] === 0 ) {
  11756. gl.enableVertexAttribArray( attribute );
  11757. enabledAttributes[ attribute ] = 1;
  11758. }
  11759. if ( attributeDivisors[ attribute ] !== meshPerAttribute ) {
  11760. var extension = capabilities.isWebGL2 ? gl : extensions.get( 'ANGLE_instanced_arrays' );
  11761. extension[ capabilities.isWebGL2 ? 'vertexAttribDivisor' : 'vertexAttribDivisorANGLE' ]( attribute, meshPerAttribute );
  11762. attributeDivisors[ attribute ] = meshPerAttribute;
  11763. }
  11764. }
  11765. function disableUnusedAttributes() {
  11766. for ( var i = 0, l = enabledAttributes.length; i !== l; ++ i ) {
  11767. if ( enabledAttributes[ i ] !== newAttributes[ i ] ) {
  11768. gl.disableVertexAttribArray( i );
  11769. enabledAttributes[ i ] = 0;
  11770. }
  11771. }
  11772. }
  11773. function enable( id ) {
  11774. if ( enabledCapabilities[ id ] !== true ) {
  11775. gl.enable( id );
  11776. enabledCapabilities[ id ] = true;
  11777. }
  11778. }
  11779. function disable( id ) {
  11780. if ( enabledCapabilities[ id ] !== false ) {
  11781. gl.disable( id );
  11782. enabledCapabilities[ id ] = false;
  11783. }
  11784. }
  11785. function getCompressedTextureFormats() {
  11786. if ( compressedTextureFormats === null ) {
  11787. compressedTextureFormats = [];
  11788. if ( extensions.get( 'WEBGL_compressed_texture_pvrtc' ) ||
  11789. extensions.get( 'WEBGL_compressed_texture_s3tc' ) ||
  11790. extensions.get( 'WEBGL_compressed_texture_etc1' ) ||
  11791. extensions.get( 'WEBGL_compressed_texture_astc' ) ) {
  11792. var formats = gl.getParameter( 34467 );
  11793. for ( var i = 0; i < formats.length; i ++ ) {
  11794. compressedTextureFormats.push( formats[ i ] );
  11795. }
  11796. }
  11797. }
  11798. return compressedTextureFormats;
  11799. }
  11800. function useProgram( program ) {
  11801. if ( currentProgram !== program ) {
  11802. gl.useProgram( program );
  11803. currentProgram = program;
  11804. return true;
  11805. }
  11806. return false;
  11807. }
  11808. function setBlending( blending, blendEquation, blendSrc, blendDst, blendEquationAlpha, blendSrcAlpha, blendDstAlpha, premultipliedAlpha ) {
  11809. if ( blending === NoBlending ) {
  11810. if ( currentBlendingEnabled ) {
  11811. disable( 3042 );
  11812. currentBlendingEnabled = false;
  11813. }
  11814. return;
  11815. }
  11816. if ( ! currentBlendingEnabled ) {
  11817. enable( 3042 );
  11818. currentBlendingEnabled = true;
  11819. }
  11820. if ( blending !== CustomBlending ) {
  11821. if ( blending !== currentBlending || premultipliedAlpha !== currentPremultipledAlpha ) {
  11822. if ( currentBlendEquation !== AddEquation || currentBlendEquationAlpha !== AddEquation ) {
  11823. gl.blendEquation( 32774 );
  11824. currentBlendEquation = AddEquation;
  11825. currentBlendEquationAlpha = AddEquation;
  11826. }
  11827. if ( premultipliedAlpha ) {
  11828. switch ( blending ) {
  11829. case NormalBlending:
  11830. gl.blendFuncSeparate( 1, 771, 1, 771 );
  11831. break;
  11832. case AdditiveBlending:
  11833. gl.blendFunc( 1, 1 );
  11834. break;
  11835. case SubtractiveBlending:
  11836. gl.blendFuncSeparate( 0, 0, 769, 771 );
  11837. break;
  11838. case MultiplyBlending:
  11839. gl.blendFuncSeparate( 0, 768, 0, 770 );
  11840. break;
  11841. default:
  11842. console.error( 'THREE.WebGLState: Invalid blending: ', blending );
  11843. break;
  11844. }
  11845. } else {
  11846. switch ( blending ) {
  11847. case NormalBlending:
  11848. gl.blendFuncSeparate( 770, 771, 1, 771 );
  11849. break;
  11850. case AdditiveBlending:
  11851. gl.blendFunc( 770, 1 );
  11852. break;
  11853. case SubtractiveBlending:
  11854. gl.blendFunc( 0, 769 );
  11855. break;
  11856. case MultiplyBlending:
  11857. gl.blendFunc( 0, 768 );
  11858. break;
  11859. default:
  11860. console.error( 'THREE.WebGLState: Invalid blending: ', blending );
  11861. break;
  11862. }
  11863. }
  11864. currentBlendSrc = null;
  11865. currentBlendDst = null;
  11866. currentBlendSrcAlpha = null;
  11867. currentBlendDstAlpha = null;
  11868. currentBlending = blending;
  11869. currentPremultipledAlpha = premultipliedAlpha;
  11870. }
  11871. return;
  11872. }
  11873. // custom blending
  11874. blendEquationAlpha = blendEquationAlpha || blendEquation;
  11875. blendSrcAlpha = blendSrcAlpha || blendSrc;
  11876. blendDstAlpha = blendDstAlpha || blendDst;
  11877. if ( blendEquation !== currentBlendEquation || blendEquationAlpha !== currentBlendEquationAlpha ) {
  11878. gl.blendEquationSeparate( utils.convert( blendEquation ), utils.convert( blendEquationAlpha ) );
  11879. currentBlendEquation = blendEquation;
  11880. currentBlendEquationAlpha = blendEquationAlpha;
  11881. }
  11882. if ( blendSrc !== currentBlendSrc || blendDst !== currentBlendDst || blendSrcAlpha !== currentBlendSrcAlpha || blendDstAlpha !== currentBlendDstAlpha ) {
  11883. gl.blendFuncSeparate( utils.convert( blendSrc ), utils.convert( blendDst ), utils.convert( blendSrcAlpha ), utils.convert( blendDstAlpha ) );
  11884. currentBlendSrc = blendSrc;
  11885. currentBlendDst = blendDst;
  11886. currentBlendSrcAlpha = blendSrcAlpha;
  11887. currentBlendDstAlpha = blendDstAlpha;
  11888. }
  11889. currentBlending = blending;
  11890. currentPremultipledAlpha = null;
  11891. }
  11892. function setMaterial( material, frontFaceCW ) {
  11893. material.side === DoubleSide
  11894. ? disable( 2884 )
  11895. : enable( 2884 );
  11896. var flipSided = ( material.side === BackSide );
  11897. if ( frontFaceCW ) flipSided = ! flipSided;
  11898. setFlipSided( flipSided );
  11899. ( material.blending === NormalBlending && material.transparent === false )
  11900. ? setBlending( NoBlending )
  11901. : setBlending( material.blending, material.blendEquation, material.blendSrc, material.blendDst, material.blendEquationAlpha, material.blendSrcAlpha, material.blendDstAlpha, material.premultipliedAlpha );
  11902. depthBuffer.setFunc( material.depthFunc );
  11903. depthBuffer.setTest( material.depthTest );
  11904. depthBuffer.setMask( material.depthWrite );
  11905. colorBuffer.setMask( material.colorWrite );
  11906. setPolygonOffset( material.polygonOffset, material.polygonOffsetFactor, material.polygonOffsetUnits );
  11907. }
  11908. //
  11909. function setFlipSided( flipSided ) {
  11910. if ( currentFlipSided !== flipSided ) {
  11911. if ( flipSided ) {
  11912. gl.frontFace( 2304 );
  11913. } else {
  11914. gl.frontFace( 2305 );
  11915. }
  11916. currentFlipSided = flipSided;
  11917. }
  11918. }
  11919. function setCullFace( cullFace ) {
  11920. if ( cullFace !== CullFaceNone ) {
  11921. enable( 2884 );
  11922. if ( cullFace !== currentCullFace ) {
  11923. if ( cullFace === CullFaceBack ) {
  11924. gl.cullFace( 1029 );
  11925. } else if ( cullFace === CullFaceFront ) {
  11926. gl.cullFace( 1028 );
  11927. } else {
  11928. gl.cullFace( 1032 );
  11929. }
  11930. }
  11931. } else {
  11932. disable( 2884 );
  11933. }
  11934. currentCullFace = cullFace;
  11935. }
  11936. function setLineWidth( width ) {
  11937. if ( width !== currentLineWidth ) {
  11938. if ( lineWidthAvailable ) gl.lineWidth( width );
  11939. currentLineWidth = width;
  11940. }
  11941. }
  11942. function setPolygonOffset( polygonOffset, factor, units ) {
  11943. if ( polygonOffset ) {
  11944. enable( 32823 );
  11945. if ( currentPolygonOffsetFactor !== factor || currentPolygonOffsetUnits !== units ) {
  11946. gl.polygonOffset( factor, units );
  11947. currentPolygonOffsetFactor = factor;
  11948. currentPolygonOffsetUnits = units;
  11949. }
  11950. } else {
  11951. disable( 32823 );
  11952. }
  11953. }
  11954. function setScissorTest( scissorTest ) {
  11955. if ( scissorTest ) {
  11956. enable( 3089 );
  11957. } else {
  11958. disable( 3089 );
  11959. }
  11960. }
  11961. // texture
  11962. function activeTexture( webglSlot ) {
  11963. if ( webglSlot === undefined ) webglSlot = 33984 + maxTextures - 1;
  11964. if ( currentTextureSlot !== webglSlot ) {
  11965. gl.activeTexture( webglSlot );
  11966. currentTextureSlot = webglSlot;
  11967. }
  11968. }
  11969. function bindTexture( webglType, webglTexture ) {
  11970. if ( currentTextureSlot === null ) {
  11971. activeTexture();
  11972. }
  11973. var boundTexture = currentBoundTextures[ currentTextureSlot ];
  11974. if ( boundTexture === undefined ) {
  11975. boundTexture = { type: undefined, texture: undefined };
  11976. currentBoundTextures[ currentTextureSlot ] = boundTexture;
  11977. }
  11978. if ( boundTexture.type !== webglType || boundTexture.texture !== webglTexture ) {
  11979. gl.bindTexture( webglType, webglTexture || emptyTextures[ webglType ] );
  11980. boundTexture.type = webglType;
  11981. boundTexture.texture = webglTexture;
  11982. }
  11983. }
  11984. function compressedTexImage2D() {
  11985. try {
  11986. gl.compressedTexImage2D.apply( gl, arguments );
  11987. } catch ( error ) {
  11988. console.error( 'THREE.WebGLState:', error );
  11989. }
  11990. }
  11991. function texImage2D() {
  11992. try {
  11993. gl.texImage2D.apply( gl, arguments );
  11994. } catch ( error ) {
  11995. console.error( 'THREE.WebGLState:', error );
  11996. }
  11997. }
  11998. function texImage3D() {
  11999. try {
  12000. gl.texImage3D.apply( gl, arguments );
  12001. } catch ( error ) {
  12002. console.error( 'THREE.WebGLState:', error );
  12003. }
  12004. }
  12005. //
  12006. function scissor( scissor ) {
  12007. if ( currentScissor.equals( scissor ) === false ) {
  12008. gl.scissor( scissor.x, scissor.y, scissor.z, scissor.w );
  12009. currentScissor.copy( scissor );
  12010. }
  12011. }
  12012. function viewport( viewport ) {
  12013. if ( currentViewport.equals( viewport ) === false ) {
  12014. gl.viewport( viewport.x, viewport.y, viewport.z, viewport.w );
  12015. currentViewport.copy( viewport );
  12016. }
  12017. }
  12018. //
  12019. function reset() {
  12020. for ( var i = 0; i < enabledAttributes.length; i ++ ) {
  12021. if ( enabledAttributes[ i ] === 1 ) {
  12022. gl.disableVertexAttribArray( i );
  12023. enabledAttributes[ i ] = 0;
  12024. }
  12025. }
  12026. enabledCapabilities = {};
  12027. compressedTextureFormats = null;
  12028. currentTextureSlot = null;
  12029. currentBoundTextures = {};
  12030. currentProgram = null;
  12031. currentBlending = null;
  12032. currentFlipSided = null;
  12033. currentCullFace = null;
  12034. colorBuffer.reset();
  12035. depthBuffer.reset();
  12036. stencilBuffer.reset();
  12037. }
  12038. return {
  12039. buffers: {
  12040. color: colorBuffer,
  12041. depth: depthBuffer,
  12042. stencil: stencilBuffer
  12043. },
  12044. initAttributes: initAttributes,
  12045. enableAttribute: enableAttribute,
  12046. enableAttributeAndDivisor: enableAttributeAndDivisor,
  12047. disableUnusedAttributes: disableUnusedAttributes,
  12048. enable: enable,
  12049. disable: disable,
  12050. getCompressedTextureFormats: getCompressedTextureFormats,
  12051. useProgram: useProgram,
  12052. setBlending: setBlending,
  12053. setMaterial: setMaterial,
  12054. setFlipSided: setFlipSided,
  12055. setCullFace: setCullFace,
  12056. setLineWidth: setLineWidth,
  12057. setPolygonOffset: setPolygonOffset,
  12058. setScissorTest: setScissorTest,
  12059. activeTexture: activeTexture,
  12060. bindTexture: bindTexture,
  12061. compressedTexImage2D: compressedTexImage2D,
  12062. texImage2D: texImage2D,
  12063. texImage3D: texImage3D,
  12064. scissor: scissor,
  12065. viewport: viewport,
  12066. reset: reset
  12067. };
  12068. }
  12069. /**
  12070. * @author mrdoob / http://mrdoob.com/
  12071. */
  12072. function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, info ) {
  12073. var _videoTextures = {};
  12074. var _canvas;
  12075. //
  12076. var useOffscreenCanvas = typeof OffscreenCanvas !== 'undefined';
  12077. function createCanvas( width, height ) {
  12078. // Use OffscreenCanvas when available. Specially needed in web workers
  12079. return useOffscreenCanvas ?
  12080. new OffscreenCanvas( width, height ) :
  12081. document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' );
  12082. }
  12083. function resizeImage( image, needsPowerOfTwo, needsNewCanvas, maxSize ) {
  12084. var scale = 1;
  12085. // handle case if texture exceeds max size
  12086. if ( image.width > maxSize || image.height > maxSize ) {
  12087. scale = maxSize / Math.max( image.width, image.height );
  12088. }
  12089. // only perform resize if necessary
  12090. if ( scale < 1 || needsPowerOfTwo === true ) {
  12091. // only perform resize for certain image types
  12092. if ( ( typeof HTMLImageElement !== 'undefined' && image instanceof HTMLImageElement ) ||
  12093. ( typeof HTMLCanvasElement !== 'undefined' && image instanceof HTMLCanvasElement ) ||
  12094. ( typeof ImageBitmap !== 'undefined' && image instanceof ImageBitmap ) ) {
  12095. var floor = needsPowerOfTwo ? _Math.floorPowerOfTwo : Math.floor;
  12096. var width = floor( scale * image.width );
  12097. var height = floor( scale * image.height );
  12098. if ( _canvas === undefined ) _canvas = createCanvas( width, height );
  12099. // cube textures can't reuse the same canvas
  12100. var canvas = needsNewCanvas ? createCanvas( width, height ) : _canvas;
  12101. canvas.width = width;
  12102. canvas.height = height;
  12103. var context = canvas.getContext( '2d' );
  12104. context.drawImage( image, 0, 0, width, height );
  12105. console.warn( 'THREE.WebGLRenderer: Texture has been resized from (' + image.width + 'x' + image.height + ') to (' + width + 'x' + height + ').' );
  12106. return canvas;
  12107. } else {
  12108. if ( 'data' in image ) {
  12109. console.warn( 'THREE.WebGLRenderer: Image in DataTexture is too big (' + image.width + 'x' + image.height + ').' );
  12110. }
  12111. return image;
  12112. }
  12113. }
  12114. return image;
  12115. }
  12116. function isPowerOfTwo( image ) {
  12117. return _Math.isPowerOfTwo( image.width ) && _Math.isPowerOfTwo( image.height );
  12118. }
  12119. function textureNeedsPowerOfTwo( texture ) {
  12120. if ( capabilities.isWebGL2 ) return false;
  12121. return ( texture.wrapS !== ClampToEdgeWrapping || texture.wrapT !== ClampToEdgeWrapping ) ||
  12122. ( texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter );
  12123. }
  12124. function textureNeedsGenerateMipmaps( texture, supportsMips ) {
  12125. return texture.generateMipmaps && supportsMips &&
  12126. texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter;
  12127. }
  12128. function generateMipmap( target, texture, width, height ) {
  12129. _gl.generateMipmap( target );
  12130. var textureProperties = properties.get( texture );
  12131. // Note: Math.log( x ) * Math.LOG2E used instead of Math.log2( x ) which is not supported by IE11
  12132. textureProperties.__maxMipLevel = Math.log( Math.max( width, height ) ) * Math.LOG2E;
  12133. }
  12134. function getInternalFormat( glFormat, glType ) {
  12135. if ( ! capabilities.isWebGL2 ) return glFormat;
  12136. var internalFormat = glFormat;
  12137. if ( glFormat === 6403 ) {
  12138. if ( glType === 5126 ) internalFormat = 33326;
  12139. if ( glType === 5131 ) internalFormat = 33325;
  12140. if ( glType === 5121 ) internalFormat = 33321;
  12141. }
  12142. if ( glFormat === 6407 ) {
  12143. if ( glType === 5126 ) internalFormat = 34837;
  12144. if ( glType === 5131 ) internalFormat = 34843;
  12145. if ( glType === 5121 ) internalFormat = 32849;
  12146. }
  12147. if ( glFormat === 6408 ) {
  12148. if ( glType === 5126 ) internalFormat = 34836;
  12149. if ( glType === 5131 ) internalFormat = 34842;
  12150. if ( glType === 5121 ) internalFormat = 32856;
  12151. }
  12152. if ( internalFormat === 33325 || internalFormat === 33326 ||
  12153. internalFormat === 34842 || internalFormat === 34836 ) {
  12154. extensions.get( 'EXT_color_buffer_float' );
  12155. } else if ( internalFormat === 34843 || internalFormat === 34837 ) {
  12156. console.warn( 'THREE.WebGLRenderer: Floating point textures with RGB format not supported. Please use RGBA instead.' );
  12157. }
  12158. return internalFormat;
  12159. }
  12160. // Fallback filters for non-power-of-2 textures
  12161. function filterFallback( f ) {
  12162. if ( f === NearestFilter || f === NearestMipMapNearestFilter || f === NearestMipMapLinearFilter ) {
  12163. return 9728;
  12164. }
  12165. return 9729;
  12166. }
  12167. //
  12168. function onTextureDispose( event ) {
  12169. var texture = event.target;
  12170. texture.removeEventListener( 'dispose', onTextureDispose );
  12171. deallocateTexture( texture );
  12172. if ( texture.isVideoTexture ) {
  12173. delete _videoTextures[ texture.id ];
  12174. }
  12175. info.memory.textures --;
  12176. }
  12177. function onRenderTargetDispose( event ) {
  12178. var renderTarget = event.target;
  12179. renderTarget.removeEventListener( 'dispose', onRenderTargetDispose );
  12180. deallocateRenderTarget( renderTarget );
  12181. info.memory.textures --;
  12182. }
  12183. //
  12184. function deallocateTexture( texture ) {
  12185. var textureProperties = properties.get( texture );
  12186. if ( textureProperties.__webglInit === undefined ) return;
  12187. _gl.deleteTexture( textureProperties.__webglTexture );
  12188. properties.remove( texture );
  12189. }
  12190. function deallocateRenderTarget( renderTarget ) {
  12191. var renderTargetProperties = properties.get( renderTarget );
  12192. var textureProperties = properties.get( renderTarget.texture );
  12193. if ( ! renderTarget ) return;
  12194. if ( textureProperties.__webglTexture !== undefined ) {
  12195. _gl.deleteTexture( textureProperties.__webglTexture );
  12196. }
  12197. if ( renderTarget.depthTexture ) {
  12198. renderTarget.depthTexture.dispose();
  12199. }
  12200. if ( renderTarget.isWebGLRenderTargetCube ) {
  12201. for ( var i = 0; i < 6; i ++ ) {
  12202. _gl.deleteFramebuffer( renderTargetProperties.__webglFramebuffer[ i ] );
  12203. if ( renderTargetProperties.__webglDepthbuffer ) _gl.deleteRenderbuffer( renderTargetProperties.__webglDepthbuffer[ i ] );
  12204. }
  12205. } else {
  12206. _gl.deleteFramebuffer( renderTargetProperties.__webglFramebuffer );
  12207. if ( renderTargetProperties.__webglDepthbuffer ) _gl.deleteRenderbuffer( renderTargetProperties.__webglDepthbuffer );
  12208. }
  12209. properties.remove( renderTarget.texture );
  12210. properties.remove( renderTarget );
  12211. }
  12212. //
  12213. var textureUnits = 0;
  12214. function resetTextureUnits() {
  12215. textureUnits = 0;
  12216. }
  12217. function allocateTextureUnit() {
  12218. var textureUnit = textureUnits;
  12219. if ( textureUnit >= capabilities.maxTextures ) {
  12220. console.warn( 'THREE.WebGLTextures: Trying to use ' + textureUnit + ' texture units while this GPU supports only ' + capabilities.maxTextures );
  12221. }
  12222. textureUnits += 1;
  12223. return textureUnit;
  12224. }
  12225. //
  12226. function setTexture2D( texture, slot ) {
  12227. var textureProperties = properties.get( texture );
  12228. if ( texture.isVideoTexture ) updateVideoTexture( texture );
  12229. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  12230. var image = texture.image;
  12231. if ( image === undefined ) {
  12232. console.warn( 'THREE.WebGLRenderer: Texture marked for update but image is undefined' );
  12233. } else if ( image.complete === false ) {
  12234. console.warn( 'THREE.WebGLRenderer: Texture marked for update but image is incomplete' );
  12235. } else {
  12236. uploadTexture( textureProperties, texture, slot );
  12237. return;
  12238. }
  12239. }
  12240. state.activeTexture( 33984 + slot );
  12241. state.bindTexture( 3553, textureProperties.__webglTexture );
  12242. }
  12243. function setTexture2DArray( texture, slot ) {
  12244. var textureProperties = properties.get( texture );
  12245. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  12246. uploadTexture( textureProperties, texture, slot );
  12247. return;
  12248. }
  12249. state.activeTexture( 33984 + slot );
  12250. state.bindTexture( 35866, textureProperties.__webglTexture );
  12251. }
  12252. function setTexture3D( texture, slot ) {
  12253. var textureProperties = properties.get( texture );
  12254. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  12255. uploadTexture( textureProperties, texture, slot );
  12256. return;
  12257. }
  12258. state.activeTexture( 33984 + slot );
  12259. state.bindTexture( 32879, textureProperties.__webglTexture );
  12260. }
  12261. function setTextureCube( texture, slot ) {
  12262. var textureProperties = properties.get( texture );
  12263. if ( texture.image.length === 6 ) {
  12264. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  12265. initTexture( textureProperties, texture );
  12266. state.activeTexture( 33984 + slot );
  12267. state.bindTexture( 34067, textureProperties.__webglTexture );
  12268. _gl.pixelStorei( 37440, texture.flipY );
  12269. var isCompressed = ( texture && texture.isCompressedTexture );
  12270. var isDataTexture = ( texture.image[ 0 ] && texture.image[ 0 ].isDataTexture );
  12271. var cubeImage = [];
  12272. for ( var i = 0; i < 6; i ++ ) {
  12273. if ( ! isCompressed && ! isDataTexture ) {
  12274. cubeImage[ i ] = resizeImage( texture.image[ i ], false, true, capabilities.maxCubemapSize );
  12275. } else {
  12276. cubeImage[ i ] = isDataTexture ? texture.image[ i ].image : texture.image[ i ];
  12277. }
  12278. }
  12279. var image = cubeImage[ 0 ],
  12280. supportsMips = isPowerOfTwo( image ) || capabilities.isWebGL2,
  12281. glFormat = utils.convert( texture.format ),
  12282. glType = utils.convert( texture.type ),
  12283. glInternalFormat = getInternalFormat( glFormat, glType );
  12284. setTextureParameters( 34067, texture, supportsMips );
  12285. for ( var i = 0; i < 6; i ++ ) {
  12286. if ( ! isCompressed ) {
  12287. if ( isDataTexture ) {
  12288. state.texImage2D( 34069 + i, 0, glInternalFormat, cubeImage[ i ].width, cubeImage[ i ].height, 0, glFormat, glType, cubeImage[ i ].data );
  12289. } else {
  12290. state.texImage2D( 34069 + i, 0, glInternalFormat, glFormat, glType, cubeImage[ i ] );
  12291. }
  12292. } else {
  12293. var mipmap, mipmaps = cubeImage[ i ].mipmaps;
  12294. for ( var j = 0, jl = mipmaps.length; j < jl; j ++ ) {
  12295. mipmap = mipmaps[ j ];
  12296. if ( texture.format !== RGBAFormat && texture.format !== RGBFormat ) {
  12297. if ( state.getCompressedTextureFormats().indexOf( glFormat ) > - 1 ) {
  12298. state.compressedTexImage2D( 34069 + i, j, glInternalFormat, mipmap.width, mipmap.height, 0, mipmap.data );
  12299. } else {
  12300. console.warn( 'THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .setTextureCube()' );
  12301. }
  12302. } else {
  12303. state.texImage2D( 34069 + i, j, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  12304. }
  12305. }
  12306. }
  12307. }
  12308. if ( ! isCompressed ) {
  12309. textureProperties.__maxMipLevel = 0;
  12310. } else {
  12311. textureProperties.__maxMipLevel = mipmaps.length - 1;
  12312. }
  12313. if ( textureNeedsGenerateMipmaps( texture, supportsMips ) ) {
  12314. // We assume images for cube map have the same size.
  12315. generateMipmap( 34067, texture, image.width, image.height );
  12316. }
  12317. textureProperties.__version = texture.version;
  12318. if ( texture.onUpdate ) texture.onUpdate( texture );
  12319. } else {
  12320. state.activeTexture( 33984 + slot );
  12321. state.bindTexture( 34067, textureProperties.__webglTexture );
  12322. }
  12323. }
  12324. }
  12325. function setTextureCubeDynamic( texture, slot ) {
  12326. state.activeTexture( 33984 + slot );
  12327. state.bindTexture( 34067, properties.get( texture ).__webglTexture );
  12328. }
  12329. function setTextureParameters( textureType, texture, supportsMips ) {
  12330. var extension;
  12331. if ( supportsMips ) {
  12332. _gl.texParameteri( textureType, 10242, utils.convert( texture.wrapS ) );
  12333. _gl.texParameteri( textureType, 10243, utils.convert( texture.wrapT ) );
  12334. if ( textureType === 32879 || textureType === 35866 ) {
  12335. _gl.texParameteri( textureType, 32882, utils.convert( texture.wrapR ) );
  12336. }
  12337. _gl.texParameteri( textureType, 10240, utils.convert( texture.magFilter ) );
  12338. _gl.texParameteri( textureType, 10241, utils.convert( texture.minFilter ) );
  12339. } else {
  12340. _gl.texParameteri( textureType, 10242, 33071 );
  12341. _gl.texParameteri( textureType, 10243, 33071 );
  12342. if ( textureType === 32879 || textureType === 35866 ) {
  12343. _gl.texParameteri( textureType, 32882, 33071 );
  12344. }
  12345. if ( texture.wrapS !== ClampToEdgeWrapping || texture.wrapT !== ClampToEdgeWrapping ) {
  12346. console.warn( 'THREE.WebGLRenderer: Texture is not power of two. Texture.wrapS and Texture.wrapT should be set to THREE.ClampToEdgeWrapping.' );
  12347. }
  12348. _gl.texParameteri( textureType, 10240, filterFallback( texture.magFilter ) );
  12349. _gl.texParameteri( textureType, 10241, filterFallback( texture.minFilter ) );
  12350. if ( texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter ) {
  12351. console.warn( 'THREE.WebGLRenderer: Texture is not power of two. Texture.minFilter should be set to THREE.NearestFilter or THREE.LinearFilter.' );
  12352. }
  12353. }
  12354. extension = extensions.get( 'EXT_texture_filter_anisotropic' );
  12355. if ( extension ) {
  12356. if ( texture.type === FloatType && extensions.get( 'OES_texture_float_linear' ) === null ) return;
  12357. if ( texture.type === HalfFloatType && ( capabilities.isWebGL2 || extensions.get( 'OES_texture_half_float_linear' ) ) === null ) return;
  12358. if ( texture.anisotropy > 1 || properties.get( texture ).__currentAnisotropy ) {
  12359. _gl.texParameterf( textureType, extension.TEXTURE_MAX_ANISOTROPY_EXT, Math.min( texture.anisotropy, capabilities.getMaxAnisotropy() ) );
  12360. properties.get( texture ).__currentAnisotropy = texture.anisotropy;
  12361. }
  12362. }
  12363. }
  12364. function initTexture( textureProperties, texture ) {
  12365. if ( textureProperties.__webglInit === undefined ) {
  12366. textureProperties.__webglInit = true;
  12367. texture.addEventListener( 'dispose', onTextureDispose );
  12368. textureProperties.__webglTexture = _gl.createTexture();
  12369. info.memory.textures ++;
  12370. }
  12371. }
  12372. function uploadTexture( textureProperties, texture, slot ) {
  12373. var textureType = 3553;
  12374. if ( texture.isDataTexture2DArray ) textureType = 35866;
  12375. if ( texture.isDataTexture3D ) textureType = 32879;
  12376. initTexture( textureProperties, texture );
  12377. state.activeTexture( 33984 + slot );
  12378. state.bindTexture( textureType, textureProperties.__webglTexture );
  12379. _gl.pixelStorei( 37440, texture.flipY );
  12380. _gl.pixelStorei( 37441, texture.premultiplyAlpha );
  12381. _gl.pixelStorei( 3317, texture.unpackAlignment );
  12382. var needsPowerOfTwo = textureNeedsPowerOfTwo( texture ) && isPowerOfTwo( texture.image ) === false;
  12383. var image = resizeImage( texture.image, needsPowerOfTwo, false, capabilities.maxTextureSize );
  12384. var supportsMips = isPowerOfTwo( image ) || capabilities.isWebGL2,
  12385. glFormat = utils.convert( texture.format ),
  12386. glType = utils.convert( texture.type ),
  12387. glInternalFormat = getInternalFormat( glFormat, glType );
  12388. setTextureParameters( textureType, texture, supportsMips );
  12389. var mipmap, mipmaps = texture.mipmaps;
  12390. if ( texture.isDepthTexture ) {
  12391. // populate depth texture with dummy data
  12392. glInternalFormat = 6402;
  12393. if ( texture.type === FloatType ) {
  12394. if ( ! capabilities.isWebGL2 ) throw new Error( 'Float Depth Texture only supported in WebGL2.0' );
  12395. glInternalFormat = 36012;
  12396. } else if ( capabilities.isWebGL2 ) {
  12397. // WebGL 2.0 requires signed internalformat for glTexImage2D
  12398. glInternalFormat = 33189;
  12399. }
  12400. if ( texture.format === DepthFormat && glInternalFormat === 6402 ) {
  12401. // The error INVALID_OPERATION is generated by texImage2D if format and internalformat are
  12402. // DEPTH_COMPONENT and type is not UNSIGNED_SHORT or UNSIGNED_INT
  12403. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  12404. if ( texture.type !== UnsignedShortType && texture.type !== UnsignedIntType ) {
  12405. console.warn( 'THREE.WebGLRenderer: Use UnsignedShortType or UnsignedIntType for DepthFormat DepthTexture.' );
  12406. texture.type = UnsignedShortType;
  12407. glType = utils.convert( texture.type );
  12408. }
  12409. }
  12410. // Depth stencil textures need the DEPTH_STENCIL internal format
  12411. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  12412. if ( texture.format === DepthStencilFormat ) {
  12413. glInternalFormat = 34041;
  12414. // The error INVALID_OPERATION is generated by texImage2D if format and internalformat are
  12415. // DEPTH_STENCIL and type is not UNSIGNED_INT_24_8_WEBGL.
  12416. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  12417. if ( texture.type !== UnsignedInt248Type ) {
  12418. console.warn( 'THREE.WebGLRenderer: Use UnsignedInt248Type for DepthStencilFormat DepthTexture.' );
  12419. texture.type = UnsignedInt248Type;
  12420. glType = utils.convert( texture.type );
  12421. }
  12422. }
  12423. state.texImage2D( 3553, 0, glInternalFormat, image.width, image.height, 0, glFormat, glType, null );
  12424. } else if ( texture.isDataTexture ) {
  12425. // use manually created mipmaps if available
  12426. // if there are no manual mipmaps
  12427. // set 0 level mipmap and then use GL to generate other mipmap levels
  12428. if ( mipmaps.length > 0 && supportsMips ) {
  12429. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  12430. mipmap = mipmaps[ i ];
  12431. state.texImage2D( 3553, i, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  12432. }
  12433. texture.generateMipmaps = false;
  12434. textureProperties.__maxMipLevel = mipmaps.length - 1;
  12435. } else {
  12436. state.texImage2D( 3553, 0, glInternalFormat, image.width, image.height, 0, glFormat, glType, image.data );
  12437. textureProperties.__maxMipLevel = 0;
  12438. }
  12439. } else if ( texture.isCompressedTexture ) {
  12440. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  12441. mipmap = mipmaps[ i ];
  12442. if ( texture.format !== RGBAFormat && texture.format !== RGBFormat ) {
  12443. if ( state.getCompressedTextureFormats().indexOf( glFormat ) > - 1 ) {
  12444. state.compressedTexImage2D( 3553, i, glInternalFormat, mipmap.width, mipmap.height, 0, mipmap.data );
  12445. } else {
  12446. console.warn( 'THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()' );
  12447. }
  12448. } else {
  12449. state.texImage2D( 3553, i, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  12450. }
  12451. }
  12452. textureProperties.__maxMipLevel = mipmaps.length - 1;
  12453. } else if ( texture.isDataTexture2DArray ) {
  12454. state.texImage3D( 35866, 0, glInternalFormat, image.width, image.height, image.depth, 0, glFormat, glType, image.data );
  12455. textureProperties.__maxMipLevel = 0;
  12456. } else if ( texture.isDataTexture3D ) {
  12457. state.texImage3D( 32879, 0, glInternalFormat, image.width, image.height, image.depth, 0, glFormat, glType, image.data );
  12458. textureProperties.__maxMipLevel = 0;
  12459. } else {
  12460. // regular Texture (image, video, canvas)
  12461. // use manually created mipmaps if available
  12462. // if there are no manual mipmaps
  12463. // set 0 level mipmap and then use GL to generate other mipmap levels
  12464. if ( mipmaps.length > 0 && supportsMips ) {
  12465. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  12466. mipmap = mipmaps[ i ];
  12467. state.texImage2D( 3553, i, glInternalFormat, glFormat, glType, mipmap );
  12468. }
  12469. texture.generateMipmaps = false;
  12470. textureProperties.__maxMipLevel = mipmaps.length - 1;
  12471. } else {
  12472. state.texImage2D( 3553, 0, glInternalFormat, glFormat, glType, image );
  12473. textureProperties.__maxMipLevel = 0;
  12474. }
  12475. }
  12476. if ( textureNeedsGenerateMipmaps( texture, supportsMips ) ) {
  12477. generateMipmap( 3553, texture, image.width, image.height );
  12478. }
  12479. textureProperties.__version = texture.version;
  12480. if ( texture.onUpdate ) texture.onUpdate( texture );
  12481. }
  12482. // Render targets
  12483. // Setup storage for target texture and bind it to correct framebuffer
  12484. function setupFrameBufferTexture( framebuffer, renderTarget, attachment, textureTarget ) {
  12485. var glFormat = utils.convert( renderTarget.texture.format );
  12486. var glType = utils.convert( renderTarget.texture.type );
  12487. var glInternalFormat = getInternalFormat( glFormat, glType );
  12488. state.texImage2D( textureTarget, 0, glInternalFormat, renderTarget.width, renderTarget.height, 0, glFormat, glType, null );
  12489. _gl.bindFramebuffer( 36160, framebuffer );
  12490. _gl.framebufferTexture2D( 36160, attachment, textureTarget, properties.get( renderTarget.texture ).__webglTexture, 0 );
  12491. _gl.bindFramebuffer( 36160, null );
  12492. }
  12493. // Setup storage for internal depth/stencil buffers and bind to correct framebuffer
  12494. function setupRenderBufferStorage( renderbuffer, renderTarget, isMultisample ) {
  12495. _gl.bindRenderbuffer( 36161, renderbuffer );
  12496. if ( renderTarget.depthBuffer && ! renderTarget.stencilBuffer ) {
  12497. if ( isMultisample ) {
  12498. var samples = getRenderTargetSamples( renderTarget );
  12499. _gl.renderbufferStorageMultisample( 36161, samples, 33189, renderTarget.width, renderTarget.height );
  12500. } else {
  12501. _gl.renderbufferStorage( 36161, 33189, renderTarget.width, renderTarget.height );
  12502. }
  12503. _gl.framebufferRenderbuffer( 36160, 36096, 36161, renderbuffer );
  12504. } else if ( renderTarget.depthBuffer && renderTarget.stencilBuffer ) {
  12505. if ( isMultisample ) {
  12506. var samples = getRenderTargetSamples( renderTarget );
  12507. _gl.renderbufferStorageMultisample( 36161, samples, 34041, renderTarget.width, renderTarget.height );
  12508. } else {
  12509. _gl.renderbufferStorage( 36161, 34041, renderTarget.width, renderTarget.height );
  12510. }
  12511. _gl.framebufferRenderbuffer( 36160, 33306, 36161, renderbuffer );
  12512. } else {
  12513. var glFormat = utils.convert( renderTarget.texture.format );
  12514. var glType = utils.convert( renderTarget.texture.type );
  12515. var glInternalFormat = getInternalFormat( glFormat, glType );
  12516. if ( isMultisample ) {
  12517. var samples = getRenderTargetSamples( renderTarget );
  12518. _gl.renderbufferStorageMultisample( 36161, samples, glInternalFormat, renderTarget.width, renderTarget.height );
  12519. } else {
  12520. _gl.renderbufferStorage( 36161, glInternalFormat, renderTarget.width, renderTarget.height );
  12521. }
  12522. }
  12523. _gl.bindRenderbuffer( 36161, null );
  12524. }
  12525. // Setup resources for a Depth Texture for a FBO (needs an extension)
  12526. function setupDepthTexture( framebuffer, renderTarget ) {
  12527. var isCube = ( renderTarget && renderTarget.isWebGLRenderTargetCube );
  12528. if ( isCube ) throw new Error( 'Depth Texture with cube render targets is not supported' );
  12529. _gl.bindFramebuffer( 36160, framebuffer );
  12530. if ( ! ( renderTarget.depthTexture && renderTarget.depthTexture.isDepthTexture ) ) {
  12531. throw new Error( 'renderTarget.depthTexture must be an instance of THREE.DepthTexture' );
  12532. }
  12533. // upload an empty depth texture with framebuffer size
  12534. if ( ! properties.get( renderTarget.depthTexture ).__webglTexture ||
  12535. renderTarget.depthTexture.image.width !== renderTarget.width ||
  12536. renderTarget.depthTexture.image.height !== renderTarget.height ) {
  12537. renderTarget.depthTexture.image.width = renderTarget.width;
  12538. renderTarget.depthTexture.image.height = renderTarget.height;
  12539. renderTarget.depthTexture.needsUpdate = true;
  12540. }
  12541. setTexture2D( renderTarget.depthTexture, 0 );
  12542. var webglDepthTexture = properties.get( renderTarget.depthTexture ).__webglTexture;
  12543. if ( renderTarget.depthTexture.format === DepthFormat ) {
  12544. _gl.framebufferTexture2D( 36160, 36096, 3553, webglDepthTexture, 0 );
  12545. } else if ( renderTarget.depthTexture.format === DepthStencilFormat ) {
  12546. _gl.framebufferTexture2D( 36160, 33306, 3553, webglDepthTexture, 0 );
  12547. } else {
  12548. throw new Error( 'Unknown depthTexture format' );
  12549. }
  12550. }
  12551. // Setup GL resources for a non-texture depth buffer
  12552. function setupDepthRenderbuffer( renderTarget ) {
  12553. var renderTargetProperties = properties.get( renderTarget );
  12554. var isCube = ( renderTarget.isWebGLRenderTargetCube === true );
  12555. if ( renderTarget.depthTexture ) {
  12556. if ( isCube ) throw new Error( 'target.depthTexture not supported in Cube render targets' );
  12557. setupDepthTexture( renderTargetProperties.__webglFramebuffer, renderTarget );
  12558. } else {
  12559. if ( isCube ) {
  12560. renderTargetProperties.__webglDepthbuffer = [];
  12561. for ( var i = 0; i < 6; i ++ ) {
  12562. _gl.bindFramebuffer( 36160, renderTargetProperties.__webglFramebuffer[ i ] );
  12563. renderTargetProperties.__webglDepthbuffer[ i ] = _gl.createRenderbuffer();
  12564. setupRenderBufferStorage( renderTargetProperties.__webglDepthbuffer[ i ], renderTarget );
  12565. }
  12566. } else {
  12567. _gl.bindFramebuffer( 36160, renderTargetProperties.__webglFramebuffer );
  12568. renderTargetProperties.__webglDepthbuffer = _gl.createRenderbuffer();
  12569. setupRenderBufferStorage( renderTargetProperties.__webglDepthbuffer, renderTarget );
  12570. }
  12571. }
  12572. _gl.bindFramebuffer( 36160, null );
  12573. }
  12574. // Set up GL resources for the render target
  12575. function setupRenderTarget( renderTarget ) {
  12576. var renderTargetProperties = properties.get( renderTarget );
  12577. var textureProperties = properties.get( renderTarget.texture );
  12578. renderTarget.addEventListener( 'dispose', onRenderTargetDispose );
  12579. textureProperties.__webglTexture = _gl.createTexture();
  12580. info.memory.textures ++;
  12581. var isCube = ( renderTarget.isWebGLRenderTargetCube === true );
  12582. var isMultisample = ( renderTarget.isWebGLMultisampleRenderTarget === true );
  12583. var supportsMips = isPowerOfTwo( renderTarget ) || capabilities.isWebGL2;
  12584. // Setup framebuffer
  12585. if ( isCube ) {
  12586. renderTargetProperties.__webglFramebuffer = [];
  12587. for ( var i = 0; i < 6; i ++ ) {
  12588. renderTargetProperties.__webglFramebuffer[ i ] = _gl.createFramebuffer();
  12589. }
  12590. } else {
  12591. renderTargetProperties.__webglFramebuffer = _gl.createFramebuffer();
  12592. if ( isMultisample ) {
  12593. if ( capabilities.isWebGL2 ) {
  12594. renderTargetProperties.__webglMultisampledFramebuffer = _gl.createFramebuffer();
  12595. renderTargetProperties.__webglColorRenderbuffer = _gl.createRenderbuffer();
  12596. _gl.bindRenderbuffer( 36161, renderTargetProperties.__webglColorRenderbuffer );
  12597. var glFormat = utils.convert( renderTarget.texture.format );
  12598. var glType = utils.convert( renderTarget.texture.type );
  12599. var glInternalFormat = getInternalFormat( glFormat, glType );
  12600. var samples = getRenderTargetSamples( renderTarget );
  12601. _gl.renderbufferStorageMultisample( 36161, samples, glInternalFormat, renderTarget.width, renderTarget.height );
  12602. _gl.bindFramebuffer( 36160, renderTargetProperties.__webglMultisampledFramebuffer );
  12603. _gl.framebufferRenderbuffer( 36160, 36064, 36161, renderTargetProperties.__webglColorRenderbuffer );
  12604. _gl.bindRenderbuffer( 36161, null );
  12605. if ( renderTarget.depthBuffer ) {
  12606. renderTargetProperties.__webglDepthRenderbuffer = _gl.createRenderbuffer();
  12607. setupRenderBufferStorage( renderTargetProperties.__webglDepthRenderbuffer, renderTarget, true );
  12608. }
  12609. _gl.bindFramebuffer( 36160, null );
  12610. } else {
  12611. console.warn( 'THREE.WebGLRenderer: WebGLMultisampleRenderTarget can only be used with WebGL2.' );
  12612. }
  12613. }
  12614. }
  12615. // Setup color buffer
  12616. if ( isCube ) {
  12617. state.bindTexture( 34067, textureProperties.__webglTexture );
  12618. setTextureParameters( 34067, renderTarget.texture, supportsMips );
  12619. for ( var i = 0; i < 6; i ++ ) {
  12620. setupFrameBufferTexture( renderTargetProperties.__webglFramebuffer[ i ], renderTarget, 36064, 34069 + i );
  12621. }
  12622. if ( textureNeedsGenerateMipmaps( renderTarget.texture, supportsMips ) ) {
  12623. generateMipmap( 34067, renderTarget.texture, renderTarget.width, renderTarget.height );
  12624. }
  12625. state.bindTexture( 34067, null );
  12626. } else {
  12627. state.bindTexture( 3553, textureProperties.__webglTexture );
  12628. setTextureParameters( 3553, renderTarget.texture, supportsMips );
  12629. setupFrameBufferTexture( renderTargetProperties.__webglFramebuffer, renderTarget, 36064, 3553 );
  12630. if ( textureNeedsGenerateMipmaps( renderTarget.texture, supportsMips ) ) {
  12631. generateMipmap( 3553, renderTarget.texture, renderTarget.width, renderTarget.height );
  12632. }
  12633. state.bindTexture( 3553, null );
  12634. }
  12635. // Setup depth and stencil buffers
  12636. if ( renderTarget.depthBuffer ) {
  12637. setupDepthRenderbuffer( renderTarget );
  12638. }
  12639. }
  12640. function updateRenderTargetMipmap( renderTarget ) {
  12641. var texture = renderTarget.texture;
  12642. var supportsMips = isPowerOfTwo( renderTarget ) || capabilities.isWebGL2;
  12643. if ( textureNeedsGenerateMipmaps( texture, supportsMips ) ) {
  12644. var target = renderTarget.isWebGLRenderTargetCube ? 34067 : 3553;
  12645. var webglTexture = properties.get( texture ).__webglTexture;
  12646. state.bindTexture( target, webglTexture );
  12647. generateMipmap( target, texture, renderTarget.width, renderTarget.height );
  12648. state.bindTexture( target, null );
  12649. }
  12650. }
  12651. function updateMultisampleRenderTarget( renderTarget ) {
  12652. if ( renderTarget.isWebGLMultisampleRenderTarget ) {
  12653. if ( capabilities.isWebGL2 ) {
  12654. var renderTargetProperties = properties.get( renderTarget );
  12655. _gl.bindFramebuffer( 36008, renderTargetProperties.__webglMultisampledFramebuffer );
  12656. _gl.bindFramebuffer( 36009, renderTargetProperties.__webglFramebuffer );
  12657. var width = renderTarget.width;
  12658. var height = renderTarget.height;
  12659. var mask = 16384;
  12660. if ( renderTarget.depthBuffer ) mask |= 256;
  12661. if ( renderTarget.stencilBuffer ) mask |= 1024;
  12662. _gl.blitFramebuffer( 0, 0, width, height, 0, 0, width, height, mask, 9728 );
  12663. } else {
  12664. console.warn( 'THREE.WebGLRenderer: WebGLMultisampleRenderTarget can only be used with WebGL2.' );
  12665. }
  12666. }
  12667. }
  12668. function getRenderTargetSamples( renderTarget ) {
  12669. return ( capabilities.isWebGL2 && renderTarget.isWebGLMultisampleRenderTarget ) ?
  12670. Math.min( capabilities.maxSamples, renderTarget.samples ) : 0;
  12671. }
  12672. function updateVideoTexture( texture ) {
  12673. var id = texture.id;
  12674. var frame = info.render.frame;
  12675. // Check the last frame we updated the VideoTexture
  12676. if ( _videoTextures[ id ] !== frame ) {
  12677. _videoTextures[ id ] = frame;
  12678. texture.update();
  12679. }
  12680. }
  12681. // backwards compatibility
  12682. var warnedTexture2D = false;
  12683. var warnedTextureCube = false;
  12684. function safeSetTexture2D( texture, slot ) {
  12685. if ( texture && texture.isWebGLRenderTarget ) {
  12686. if ( warnedTexture2D === false ) {
  12687. console.warn( "THREE.WebGLTextures.safeSetTexture2D: don't use render targets as textures. Use their .texture property instead." );
  12688. warnedTexture2D = true;
  12689. }
  12690. texture = texture.texture;
  12691. }
  12692. setTexture2D( texture, slot );
  12693. }
  12694. function safeSetTextureCube( texture, slot ) {
  12695. if ( texture && texture.isWebGLRenderTargetCube ) {
  12696. if ( warnedTextureCube === false ) {
  12697. console.warn( "THREE.WebGLTextures.safeSetTextureCube: don't use cube render targets as textures. Use their .texture property instead." );
  12698. warnedTextureCube = true;
  12699. }
  12700. texture = texture.texture;
  12701. }
  12702. // currently relying on the fact that WebGLRenderTargetCube.texture is a Texture and NOT a CubeTexture
  12703. // TODO: unify these code paths
  12704. if ( ( texture && texture.isCubeTexture ) ||
  12705. ( Array.isArray( texture.image ) && texture.image.length === 6 ) ) {
  12706. // CompressedTexture can have Array in image :/
  12707. // this function alone should take care of cube textures
  12708. setTextureCube( texture, slot );
  12709. } else {
  12710. // assumed: texture property of THREE.WebGLRenderTargetCube
  12711. setTextureCubeDynamic( texture, slot );
  12712. }
  12713. }
  12714. //
  12715. this.allocateTextureUnit = allocateTextureUnit;
  12716. this.resetTextureUnits = resetTextureUnits;
  12717. this.setTexture2D = setTexture2D;
  12718. this.setTexture2DArray = setTexture2DArray;
  12719. this.setTexture3D = setTexture3D;
  12720. this.setTextureCube = setTextureCube;
  12721. this.setTextureCubeDynamic = setTextureCubeDynamic;
  12722. this.setupRenderTarget = setupRenderTarget;
  12723. this.updateRenderTargetMipmap = updateRenderTargetMipmap;
  12724. this.updateMultisampleRenderTarget = updateMultisampleRenderTarget;
  12725. this.safeSetTexture2D = safeSetTexture2D;
  12726. this.safeSetTextureCube = safeSetTextureCube;
  12727. }
  12728. /**
  12729. * @author thespite / http://www.twitter.com/thespite
  12730. */
  12731. function WebGLUtils( gl, extensions, capabilities ) {
  12732. function convert( p ) {
  12733. var extension;
  12734. if ( p === RepeatWrapping ) return 10497;
  12735. if ( p === ClampToEdgeWrapping ) return 33071;
  12736. if ( p === MirroredRepeatWrapping ) return 33648;
  12737. if ( p === NearestFilter ) return 9728;
  12738. if ( p === NearestMipMapNearestFilter ) return 9984;
  12739. if ( p === NearestMipMapLinearFilter ) return 9986;
  12740. if ( p === LinearFilter ) return 9729;
  12741. if ( p === LinearMipMapNearestFilter ) return 9985;
  12742. if ( p === LinearMipMapLinearFilter ) return 9987;
  12743. if ( p === UnsignedByteType ) return 5121;
  12744. if ( p === UnsignedShort4444Type ) return 32819;
  12745. if ( p === UnsignedShort5551Type ) return 32820;
  12746. if ( p === UnsignedShort565Type ) return 33635;
  12747. if ( p === ByteType ) return 5120;
  12748. if ( p === ShortType ) return 5122;
  12749. if ( p === UnsignedShortType ) return 5123;
  12750. if ( p === IntType ) return 5124;
  12751. if ( p === UnsignedIntType ) return 5125;
  12752. if ( p === FloatType ) return 5126;
  12753. if ( p === HalfFloatType ) {
  12754. if ( capabilities.isWebGL2 ) return 5131;
  12755. extension = extensions.get( 'OES_texture_half_float' );
  12756. if ( extension !== null ) return extension.HALF_FLOAT_OES;
  12757. }
  12758. if ( p === AlphaFormat ) return 6406;
  12759. if ( p === RGBFormat ) return 6407;
  12760. if ( p === RGBAFormat ) return 6408;
  12761. if ( p === LuminanceFormat ) return 6409;
  12762. if ( p === LuminanceAlphaFormat ) return 6410;
  12763. if ( p === DepthFormat ) return 6402;
  12764. if ( p === DepthStencilFormat ) return 34041;
  12765. if ( p === RedFormat ) return 6403;
  12766. if ( p === AddEquation ) return 32774;
  12767. if ( p === SubtractEquation ) return 32778;
  12768. if ( p === ReverseSubtractEquation ) return 32779;
  12769. if ( p === ZeroFactor ) return 0;
  12770. if ( p === OneFactor ) return 1;
  12771. if ( p === SrcColorFactor ) return 768;
  12772. if ( p === OneMinusSrcColorFactor ) return 769;
  12773. if ( p === SrcAlphaFactor ) return 770;
  12774. if ( p === OneMinusSrcAlphaFactor ) return 771;
  12775. if ( p === DstAlphaFactor ) return 772;
  12776. if ( p === OneMinusDstAlphaFactor ) return 773;
  12777. if ( p === DstColorFactor ) return 774;
  12778. if ( p === OneMinusDstColorFactor ) return 775;
  12779. if ( p === SrcAlphaSaturateFactor ) return 776;
  12780. if ( p === RGB_S3TC_DXT1_Format || p === RGBA_S3TC_DXT1_Format ||
  12781. p === RGBA_S3TC_DXT3_Format || p === RGBA_S3TC_DXT5_Format ) {
  12782. extension = extensions.get( 'WEBGL_compressed_texture_s3tc' );
  12783. if ( extension !== null ) {
  12784. if ( p === RGB_S3TC_DXT1_Format ) return extension.COMPRESSED_RGB_S3TC_DXT1_EXT;
  12785. if ( p === RGBA_S3TC_DXT1_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT1_EXT;
  12786. if ( p === RGBA_S3TC_DXT3_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT3_EXT;
  12787. if ( p === RGBA_S3TC_DXT5_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT5_EXT;
  12788. }
  12789. }
  12790. if ( p === RGB_PVRTC_4BPPV1_Format || p === RGB_PVRTC_2BPPV1_Format ||
  12791. p === RGBA_PVRTC_4BPPV1_Format || p === RGBA_PVRTC_2BPPV1_Format ) {
  12792. extension = extensions.get( 'WEBGL_compressed_texture_pvrtc' );
  12793. if ( extension !== null ) {
  12794. if ( p === RGB_PVRTC_4BPPV1_Format ) return extension.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;
  12795. if ( p === RGB_PVRTC_2BPPV1_Format ) return extension.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;
  12796. if ( p === RGBA_PVRTC_4BPPV1_Format ) return extension.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;
  12797. if ( p === RGBA_PVRTC_2BPPV1_Format ) return extension.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG;
  12798. }
  12799. }
  12800. if ( p === RGB_ETC1_Format ) {
  12801. extension = extensions.get( 'WEBGL_compressed_texture_etc1' );
  12802. if ( extension !== null ) return extension.COMPRESSED_RGB_ETC1_WEBGL;
  12803. }
  12804. if ( p === RGBA_ASTC_4x4_Format || p === RGBA_ASTC_5x4_Format || p === RGBA_ASTC_5x5_Format ||
  12805. p === RGBA_ASTC_6x5_Format || p === RGBA_ASTC_6x6_Format || p === RGBA_ASTC_8x5_Format ||
  12806. p === RGBA_ASTC_8x6_Format || p === RGBA_ASTC_8x8_Format || p === RGBA_ASTC_10x5_Format ||
  12807. p === RGBA_ASTC_10x6_Format || p === RGBA_ASTC_10x8_Format || p === RGBA_ASTC_10x10_Format ||
  12808. p === RGBA_ASTC_12x10_Format || p === RGBA_ASTC_12x12_Format ) {
  12809. extension = extensions.get( 'WEBGL_compressed_texture_astc' );
  12810. if ( extension !== null ) {
  12811. return p;
  12812. }
  12813. }
  12814. if ( p === MinEquation || p === MaxEquation ) {
  12815. if ( capabilities.isWebGL2 ) {
  12816. if ( p === MinEquation ) return 32775;
  12817. if ( p === MaxEquation ) return 32776;
  12818. }
  12819. extension = extensions.get( 'EXT_blend_minmax' );
  12820. if ( extension !== null ) {
  12821. if ( p === MinEquation ) return extension.MIN_EXT;
  12822. if ( p === MaxEquation ) return extension.MAX_EXT;
  12823. }
  12824. }
  12825. if ( p === UnsignedInt248Type ) {
  12826. if ( capabilities.isWebGL2 ) return 34042;
  12827. extension = extensions.get( 'WEBGL_depth_texture' );
  12828. if ( extension !== null ) return extension.UNSIGNED_INT_24_8_WEBGL;
  12829. }
  12830. return 0;
  12831. }
  12832. return { convert: convert };
  12833. }
  12834. /**
  12835. * @author mrdoob / http://mrdoob.com/
  12836. */
  12837. function Group() {
  12838. Object3D.call( this );
  12839. this.type = 'Group';
  12840. }
  12841. Group.prototype = Object.assign( Object.create( Object3D.prototype ), {
  12842. constructor: Group,
  12843. isGroup: true
  12844. } );
  12845. /**
  12846. * @author mrdoob / http://mrdoob.com/
  12847. * @author mikael emtinger / http://gomo.se/
  12848. * @author WestLangley / http://github.com/WestLangley
  12849. */
  12850. function Camera() {
  12851. Object3D.call( this );
  12852. this.type = 'Camera';
  12853. this.matrixWorldInverse = new Matrix4();
  12854. this.projectionMatrix = new Matrix4();
  12855. this.projectionMatrixInverse = new Matrix4();
  12856. }
  12857. Camera.prototype = Object.assign( Object.create( Object3D.prototype ), {
  12858. constructor: Camera,
  12859. isCamera: true,
  12860. copy: function ( source, recursive ) {
  12861. Object3D.prototype.copy.call( this, source, recursive );
  12862. this.matrixWorldInverse.copy( source.matrixWorldInverse );
  12863. this.projectionMatrix.copy( source.projectionMatrix );
  12864. this.projectionMatrixInverse.copy( source.projectionMatrixInverse );
  12865. return this;
  12866. },
  12867. getWorldDirection: function ( target ) {
  12868. if ( target === undefined ) {
  12869. console.warn( 'THREE.Camera: .getWorldDirection() target is now required' );
  12870. target = new Vector3();
  12871. }
  12872. this.updateMatrixWorld( true );
  12873. var e = this.matrixWorld.elements;
  12874. return target.set( - e[ 8 ], - e[ 9 ], - e[ 10 ] ).normalize();
  12875. },
  12876. updateMatrixWorld: function ( force ) {
  12877. Object3D.prototype.updateMatrixWorld.call( this, force );
  12878. this.matrixWorldInverse.getInverse( this.matrixWorld );
  12879. },
  12880. clone: function () {
  12881. return new this.constructor().copy( this );
  12882. }
  12883. } );
  12884. /**
  12885. * @author mrdoob / http://mrdoob.com/
  12886. * @author greggman / http://games.greggman.com/
  12887. * @author zz85 / http://www.lab4games.net/zz85/blog
  12888. * @author tschw
  12889. */
  12890. function PerspectiveCamera( fov, aspect, near, far ) {
  12891. Camera.call( this );
  12892. this.type = 'PerspectiveCamera';
  12893. this.fov = fov !== undefined ? fov : 50;
  12894. this.zoom = 1;
  12895. this.near = near !== undefined ? near : 0.1;
  12896. this.far = far !== undefined ? far : 2000;
  12897. this.focus = 10;
  12898. this.aspect = aspect !== undefined ? aspect : 1;
  12899. this.view = null;
  12900. this.filmGauge = 35; // width of the film (default in millimeters)
  12901. this.filmOffset = 0; // horizontal film offset (same unit as gauge)
  12902. this.updateProjectionMatrix();
  12903. }
  12904. PerspectiveCamera.prototype = Object.assign( Object.create( Camera.prototype ), {
  12905. constructor: PerspectiveCamera,
  12906. isPerspectiveCamera: true,
  12907. copy: function ( source, recursive ) {
  12908. Camera.prototype.copy.call( this, source, recursive );
  12909. this.fov = source.fov;
  12910. this.zoom = source.zoom;
  12911. this.near = source.near;
  12912. this.far = source.far;
  12913. this.focus = source.focus;
  12914. this.aspect = source.aspect;
  12915. this.view = source.view === null ? null : Object.assign( {}, source.view );
  12916. this.filmGauge = source.filmGauge;
  12917. this.filmOffset = source.filmOffset;
  12918. return this;
  12919. },
  12920. /**
  12921. * Sets the FOV by focal length in respect to the current .filmGauge.
  12922. *
  12923. * The default film gauge is 35, so that the focal length can be specified for
  12924. * a 35mm (full frame) camera.
  12925. *
  12926. * Values for focal length and film gauge must have the same unit.
  12927. */
  12928. setFocalLength: function ( focalLength ) {
  12929. // see http://www.bobatkins.com/photography/technical/field_of_view.html
  12930. var vExtentSlope = 0.5 * this.getFilmHeight() / focalLength;
  12931. this.fov = _Math.RAD2DEG * 2 * Math.atan( vExtentSlope );
  12932. this.updateProjectionMatrix();
  12933. },
  12934. /**
  12935. * Calculates the focal length from the current .fov and .filmGauge.
  12936. */
  12937. getFocalLength: function () {
  12938. var vExtentSlope = Math.tan( _Math.DEG2RAD * 0.5 * this.fov );
  12939. return 0.5 * this.getFilmHeight() / vExtentSlope;
  12940. },
  12941. getEffectiveFOV: function () {
  12942. return _Math.RAD2DEG * 2 * Math.atan(
  12943. Math.tan( _Math.DEG2RAD * 0.5 * this.fov ) / this.zoom );
  12944. },
  12945. getFilmWidth: function () {
  12946. // film not completely covered in portrait format (aspect < 1)
  12947. return this.filmGauge * Math.min( this.aspect, 1 );
  12948. },
  12949. getFilmHeight: function () {
  12950. // film not completely covered in landscape format (aspect > 1)
  12951. return this.filmGauge / Math.max( this.aspect, 1 );
  12952. },
  12953. /**
  12954. * Sets an offset in a larger frustum. This is useful for multi-window or
  12955. * multi-monitor/multi-machine setups.
  12956. *
  12957. * For example, if you have 3x2 monitors and each monitor is 1920x1080 and
  12958. * the monitors are in grid like this
  12959. *
  12960. * +---+---+---+
  12961. * | A | B | C |
  12962. * +---+---+---+
  12963. * | D | E | F |
  12964. * +---+---+---+
  12965. *
  12966. * then for each monitor you would call it like this
  12967. *
  12968. * var w = 1920;
  12969. * var h = 1080;
  12970. * var fullWidth = w * 3;
  12971. * var fullHeight = h * 2;
  12972. *
  12973. * --A--
  12974. * camera.setViewOffset( fullWidth, fullHeight, w * 0, h * 0, w, h );
  12975. * --B--
  12976. * camera.setViewOffset( fullWidth, fullHeight, w * 1, h * 0, w, h );
  12977. * --C--
  12978. * camera.setViewOffset( fullWidth, fullHeight, w * 2, h * 0, w, h );
  12979. * --D--
  12980. * camera.setViewOffset( fullWidth, fullHeight, w * 0, h * 1, w, h );
  12981. * --E--
  12982. * camera.setViewOffset( fullWidth, fullHeight, w * 1, h * 1, w, h );
  12983. * --F--
  12984. * camera.setViewOffset( fullWidth, fullHeight, w * 2, h * 1, w, h );
  12985. *
  12986. * Note there is no reason monitors have to be the same size or in a grid.
  12987. */
  12988. setViewOffset: function ( fullWidth, fullHeight, x, y, width, height ) {
  12989. this.aspect = fullWidth / fullHeight;
  12990. if ( this.view === null ) {
  12991. this.view = {
  12992. enabled: true,
  12993. fullWidth: 1,
  12994. fullHeight: 1,
  12995. offsetX: 0,
  12996. offsetY: 0,
  12997. width: 1,
  12998. height: 1
  12999. };
  13000. }
  13001. this.view.enabled = true;
  13002. this.view.fullWidth = fullWidth;
  13003. this.view.fullHeight = fullHeight;
  13004. this.view.offsetX = x;
  13005. this.view.offsetY = y;
  13006. this.view.width = width;
  13007. this.view.height = height;
  13008. this.updateProjectionMatrix();
  13009. },
  13010. clearViewOffset: function () {
  13011. if ( this.view !== null ) {
  13012. this.view.enabled = false;
  13013. }
  13014. this.updateProjectionMatrix();
  13015. },
  13016. updateProjectionMatrix: function () {
  13017. var near = this.near,
  13018. top = near * Math.tan( _Math.DEG2RAD * 0.5 * this.fov ) / this.zoom,
  13019. height = 2 * top,
  13020. width = this.aspect * height,
  13021. left = - 0.5 * width,
  13022. view = this.view;
  13023. if ( this.view !== null && this.view.enabled ) {
  13024. var fullWidth = view.fullWidth,
  13025. fullHeight = view.fullHeight;
  13026. left += view.offsetX * width / fullWidth;
  13027. top -= view.offsetY * height / fullHeight;
  13028. width *= view.width / fullWidth;
  13029. height *= view.height / fullHeight;
  13030. }
  13031. var skew = this.filmOffset;
  13032. if ( skew !== 0 ) left += near * skew / this.getFilmWidth();
  13033. this.projectionMatrix.makePerspective( left, left + width, top, top - height, near, this.far );
  13034. this.projectionMatrixInverse.getInverse( this.projectionMatrix );
  13035. },
  13036. toJSON: function ( meta ) {
  13037. var data = Object3D.prototype.toJSON.call( this, meta );
  13038. data.object.fov = this.fov;
  13039. data.object.zoom = this.zoom;
  13040. data.object.near = this.near;
  13041. data.object.far = this.far;
  13042. data.object.focus = this.focus;
  13043. data.object.aspect = this.aspect;
  13044. if ( this.view !== null ) data.object.view = Object.assign( {}, this.view );
  13045. data.object.filmGauge = this.filmGauge;
  13046. data.object.filmOffset = this.filmOffset;
  13047. return data;
  13048. }
  13049. } );
  13050. /**
  13051. * @author mrdoob / http://mrdoob.com/
  13052. */
  13053. function ArrayCamera( array ) {
  13054. PerspectiveCamera.call( this );
  13055. this.cameras = array || [];
  13056. }
  13057. ArrayCamera.prototype = Object.assign( Object.create( PerspectiveCamera.prototype ), {
  13058. constructor: ArrayCamera,
  13059. isArrayCamera: true
  13060. } );
  13061. /**
  13062. * @author jsantell / https://www.jsantell.com/
  13063. * @author mrdoob / http://mrdoob.com/
  13064. */
  13065. var cameraLPos = new Vector3();
  13066. var cameraRPos = new Vector3();
  13067. /**
  13068. * Assumes 2 cameras that are parallel and share an X-axis, and that
  13069. * the cameras' projection and world matrices have already been set.
  13070. * And that near and far planes are identical for both cameras.
  13071. * Visualization of this technique: https://computergraphics.stackexchange.com/a/4765
  13072. */
  13073. function setProjectionFromUnion( camera, cameraL, cameraR ) {
  13074. cameraLPos.setFromMatrixPosition( cameraL.matrixWorld );
  13075. cameraRPos.setFromMatrixPosition( cameraR.matrixWorld );
  13076. var ipd = cameraLPos.distanceTo( cameraRPos );
  13077. var projL = cameraL.projectionMatrix.elements;
  13078. var projR = cameraR.projectionMatrix.elements;
  13079. // VR systems will have identical far and near planes, and
  13080. // most likely identical top and bottom frustum extents.
  13081. // Use the left camera for these values.
  13082. var near = projL[ 14 ] / ( projL[ 10 ] - 1 );
  13083. var far = projL[ 14 ] / ( projL[ 10 ] + 1 );
  13084. var topFov = ( projL[ 9 ] + 1 ) / projL[ 5 ];
  13085. var bottomFov = ( projL[ 9 ] - 1 ) / projL[ 5 ];
  13086. var leftFov = ( projL[ 8 ] - 1 ) / projL[ 0 ];
  13087. var rightFov = ( projR[ 8 ] + 1 ) / projR[ 0 ];
  13088. var left = near * leftFov;
  13089. var right = near * rightFov;
  13090. // Calculate the new camera's position offset from the
  13091. // left camera. xOffset should be roughly half `ipd`.
  13092. var zOffset = ipd / ( - leftFov + rightFov );
  13093. var xOffset = zOffset * - leftFov;
  13094. // TODO: Better way to apply this offset?
  13095. cameraL.matrixWorld.decompose( camera.position, camera.quaternion, camera.scale );
  13096. camera.translateX( xOffset );
  13097. camera.translateZ( zOffset );
  13098. camera.matrixWorld.compose( camera.position, camera.quaternion, camera.scale );
  13099. camera.matrixWorldInverse.getInverse( camera.matrixWorld );
  13100. // Find the union of the frustum values of the cameras and scale
  13101. // the values so that the near plane's position does not change in world space,
  13102. // although must now be relative to the new union camera.
  13103. var near2 = near + zOffset;
  13104. var far2 = far + zOffset;
  13105. var left2 = left - xOffset;
  13106. var right2 = right + ( ipd - xOffset );
  13107. var top2 = topFov * far / far2 * near2;
  13108. var bottom2 = bottomFov * far / far2 * near2;
  13109. camera.projectionMatrix.makePerspective( left2, right2, top2, bottom2, near2, far2 );
  13110. }
  13111. /**
  13112. * @author mrdoob / http://mrdoob.com/
  13113. */
  13114. function WebVRManager( renderer ) {
  13115. var scope = this;
  13116. var device = null;
  13117. var frameData = null;
  13118. var poseTarget = null;
  13119. var controllers = [];
  13120. var standingMatrix = new Matrix4();
  13121. var standingMatrixInverse = new Matrix4();
  13122. var framebufferScaleFactor = 1.0;
  13123. var frameOfReferenceType = 'stage';
  13124. if ( typeof window !== 'undefined' && 'VRFrameData' in window ) {
  13125. frameData = new window.VRFrameData();
  13126. window.addEventListener( 'vrdisplaypresentchange', onVRDisplayPresentChange, false );
  13127. }
  13128. var matrixWorldInverse = new Matrix4();
  13129. var tempQuaternion = new Quaternion();
  13130. var tempPosition = new Vector3();
  13131. var cameraL = new PerspectiveCamera();
  13132. cameraL.bounds = new Vector4( 0.0, 0.0, 0.5, 1.0 );
  13133. cameraL.layers.enable( 1 );
  13134. var cameraR = new PerspectiveCamera();
  13135. cameraR.bounds = new Vector4( 0.5, 0.0, 0.5, 1.0 );
  13136. cameraR.layers.enable( 2 );
  13137. var cameraVR = new ArrayCamera( [ cameraL, cameraR ] );
  13138. cameraVR.layers.enable( 1 );
  13139. cameraVR.layers.enable( 2 );
  13140. //
  13141. function isPresenting() {
  13142. return device !== null && device.isPresenting === true;
  13143. }
  13144. var currentSize = new Vector2(), currentPixelRatio;
  13145. function onVRDisplayPresentChange() {
  13146. if ( isPresenting() ) {
  13147. var eyeParameters = device.getEyeParameters( 'left' );
  13148. var renderWidth = eyeParameters.renderWidth * framebufferScaleFactor;
  13149. var renderHeight = eyeParameters.renderHeight * framebufferScaleFactor;
  13150. currentPixelRatio = renderer.getPixelRatio();
  13151. renderer.getSize( currentSize );
  13152. renderer.setDrawingBufferSize( renderWidth * 2, renderHeight, 1 );
  13153. animation.start();
  13154. } else {
  13155. if ( scope.enabled ) {
  13156. renderer.setDrawingBufferSize( currentSize.width, currentSize.height, currentPixelRatio );
  13157. }
  13158. animation.stop();
  13159. }
  13160. }
  13161. //
  13162. var triggers = [];
  13163. function findGamepad( id ) {
  13164. var gamepads = navigator.getGamepads && navigator.getGamepads();
  13165. for ( var i = 0, j = 0, l = gamepads.length; i < l; i ++ ) {
  13166. var gamepad = gamepads[ i ];
  13167. if ( gamepad && ( gamepad.id === 'Daydream Controller' ||
  13168. gamepad.id === 'Gear VR Controller' || gamepad.id === 'Oculus Go Controller' ||
  13169. gamepad.id === 'OpenVR Gamepad' || gamepad.id.startsWith( 'Oculus Touch' ) ||
  13170. gamepad.id.startsWith( 'Spatial Controller' ) ) ) {
  13171. if ( j === id ) return gamepad;
  13172. j ++;
  13173. }
  13174. }
  13175. }
  13176. function updateControllers() {
  13177. for ( var i = 0; i < controllers.length; i ++ ) {
  13178. var controller = controllers[ i ];
  13179. var gamepad = findGamepad( i );
  13180. if ( gamepad !== undefined && gamepad.pose !== undefined ) {
  13181. if ( gamepad.pose === null ) return;
  13182. // Pose
  13183. var pose = gamepad.pose;
  13184. if ( pose.hasPosition === false ) controller.position.set( 0.2, - 0.6, - 0.05 );
  13185. if ( pose.position !== null ) controller.position.fromArray( pose.position );
  13186. if ( pose.orientation !== null ) controller.quaternion.fromArray( pose.orientation );
  13187. controller.matrix.compose( controller.position, controller.quaternion, controller.scale );
  13188. controller.matrix.premultiply( standingMatrix );
  13189. controller.matrix.decompose( controller.position, controller.quaternion, controller.scale );
  13190. controller.matrixWorldNeedsUpdate = true;
  13191. controller.visible = true;
  13192. // Trigger
  13193. var buttonId = gamepad.id === 'Daydream Controller' ? 0 : 1;
  13194. if ( triggers[ i ] !== gamepad.buttons[ buttonId ].pressed ) {
  13195. triggers[ i ] = gamepad.buttons[ buttonId ].pressed;
  13196. if ( triggers[ i ] === true ) {
  13197. controller.dispatchEvent( { type: 'selectstart' } );
  13198. } else {
  13199. controller.dispatchEvent( { type: 'selectend' } );
  13200. controller.dispatchEvent( { type: 'select' } );
  13201. }
  13202. }
  13203. } else {
  13204. controller.visible = false;
  13205. }
  13206. }
  13207. }
  13208. //
  13209. this.enabled = false;
  13210. this.getController = function ( id ) {
  13211. var controller = controllers[ id ];
  13212. if ( controller === undefined ) {
  13213. controller = new Group();
  13214. controller.matrixAutoUpdate = false;
  13215. controller.visible = false;
  13216. controllers[ id ] = controller;
  13217. }
  13218. return controller;
  13219. };
  13220. this.getDevice = function () {
  13221. return device;
  13222. };
  13223. this.setDevice = function ( value ) {
  13224. if ( value !== undefined ) device = value;
  13225. animation.setContext( value );
  13226. };
  13227. this.setFramebufferScaleFactor = function ( value ) {
  13228. framebufferScaleFactor = value;
  13229. };
  13230. this.setFrameOfReferenceType = function ( value ) {
  13231. frameOfReferenceType = value;
  13232. };
  13233. this.setPoseTarget = function ( object ) {
  13234. if ( object !== undefined ) poseTarget = object;
  13235. };
  13236. this.getCamera = function ( camera ) {
  13237. var userHeight = frameOfReferenceType === 'stage' ? 1.6 : 0;
  13238. if ( isPresenting() === false ) {
  13239. camera.position.set( 0, userHeight, 0 );
  13240. camera.rotation.set( 0, 0, 0 );
  13241. return camera;
  13242. }
  13243. device.depthNear = camera.near;
  13244. device.depthFar = camera.far;
  13245. device.getFrameData( frameData );
  13246. //
  13247. if ( frameOfReferenceType === 'stage' ) {
  13248. var stageParameters = device.stageParameters;
  13249. if ( stageParameters ) {
  13250. standingMatrix.fromArray( stageParameters.sittingToStandingTransform );
  13251. } else {
  13252. standingMatrix.makeTranslation( 0, userHeight, 0 );
  13253. }
  13254. }
  13255. var pose = frameData.pose;
  13256. var poseObject = poseTarget !== null ? poseTarget : camera;
  13257. // We want to manipulate poseObject by its position and quaternion components since users may rely on them.
  13258. poseObject.matrix.copy( standingMatrix );
  13259. poseObject.matrix.decompose( poseObject.position, poseObject.quaternion, poseObject.scale );
  13260. if ( pose.orientation !== null ) {
  13261. tempQuaternion.fromArray( pose.orientation );
  13262. poseObject.quaternion.multiply( tempQuaternion );
  13263. }
  13264. if ( pose.position !== null ) {
  13265. tempQuaternion.setFromRotationMatrix( standingMatrix );
  13266. tempPosition.fromArray( pose.position );
  13267. tempPosition.applyQuaternion( tempQuaternion );
  13268. poseObject.position.add( tempPosition );
  13269. }
  13270. poseObject.updateMatrixWorld();
  13271. //
  13272. cameraL.near = camera.near;
  13273. cameraR.near = camera.near;
  13274. cameraL.far = camera.far;
  13275. cameraR.far = camera.far;
  13276. cameraL.matrixWorldInverse.fromArray( frameData.leftViewMatrix );
  13277. cameraR.matrixWorldInverse.fromArray( frameData.rightViewMatrix );
  13278. // TODO (mrdoob) Double check this code
  13279. standingMatrixInverse.getInverse( standingMatrix );
  13280. if ( frameOfReferenceType === 'stage' ) {
  13281. cameraL.matrixWorldInverse.multiply( standingMatrixInverse );
  13282. cameraR.matrixWorldInverse.multiply( standingMatrixInverse );
  13283. }
  13284. var parent = poseObject.parent;
  13285. if ( parent !== null ) {
  13286. matrixWorldInverse.getInverse( parent.matrixWorld );
  13287. cameraL.matrixWorldInverse.multiply( matrixWorldInverse );
  13288. cameraR.matrixWorldInverse.multiply( matrixWorldInverse );
  13289. }
  13290. // envMap and Mirror needs camera.matrixWorld
  13291. cameraL.matrixWorld.getInverse( cameraL.matrixWorldInverse );
  13292. cameraR.matrixWorld.getInverse( cameraR.matrixWorldInverse );
  13293. cameraL.projectionMatrix.fromArray( frameData.leftProjectionMatrix );
  13294. cameraR.projectionMatrix.fromArray( frameData.rightProjectionMatrix );
  13295. setProjectionFromUnion( cameraVR, cameraL, cameraR );
  13296. //
  13297. var layers = device.getLayers();
  13298. if ( layers.length ) {
  13299. var layer = layers[ 0 ];
  13300. if ( layer.leftBounds !== null && layer.leftBounds.length === 4 ) {
  13301. cameraL.bounds.fromArray( layer.leftBounds );
  13302. }
  13303. if ( layer.rightBounds !== null && layer.rightBounds.length === 4 ) {
  13304. cameraR.bounds.fromArray( layer.rightBounds );
  13305. }
  13306. }
  13307. updateControllers();
  13308. return cameraVR;
  13309. };
  13310. this.getStandingMatrix = function () {
  13311. return standingMatrix;
  13312. };
  13313. this.isPresenting = isPresenting;
  13314. // Animation Loop
  13315. var animation = new WebGLAnimation();
  13316. this.setAnimationLoop = function ( callback ) {
  13317. animation.setAnimationLoop( callback );
  13318. if ( isPresenting() ) animation.start();
  13319. };
  13320. this.submitFrame = function () {
  13321. if ( isPresenting() ) device.submitFrame();
  13322. };
  13323. this.dispose = function () {
  13324. if ( typeof window !== 'undefined' ) {
  13325. window.removeEventListener( 'vrdisplaypresentchange', onVRDisplayPresentChange );
  13326. }
  13327. };
  13328. }
  13329. /**
  13330. * @author mrdoob / http://mrdoob.com/
  13331. */
  13332. function WebXRManager( renderer ) {
  13333. var gl = renderer.context;
  13334. var device = null;
  13335. var session = null;
  13336. var framebufferScaleFactor = 1.0;
  13337. var frameOfReference = null;
  13338. var frameOfReferenceType = 'stage';
  13339. var pose = null;
  13340. var controllers = [];
  13341. var inputSources = [];
  13342. function isPresenting() {
  13343. return session !== null && frameOfReference !== null;
  13344. }
  13345. //
  13346. var cameraL = new PerspectiveCamera();
  13347. cameraL.layers.enable( 1 );
  13348. cameraL.viewport = new Vector4();
  13349. var cameraR = new PerspectiveCamera();
  13350. cameraR.layers.enable( 2 );
  13351. cameraR.viewport = new Vector4();
  13352. var cameraVR = new ArrayCamera( [ cameraL, cameraR ] );
  13353. cameraVR.layers.enable( 1 );
  13354. cameraVR.layers.enable( 2 );
  13355. //
  13356. this.enabled = false;
  13357. this.getController = function ( id ) {
  13358. var controller = controllers[ id ];
  13359. if ( controller === undefined ) {
  13360. controller = new Group();
  13361. controller.matrixAutoUpdate = false;
  13362. controller.visible = false;
  13363. controllers[ id ] = controller;
  13364. }
  13365. return controller;
  13366. };
  13367. this.getDevice = function () {
  13368. return device;
  13369. };
  13370. this.setDevice = function ( value ) {
  13371. if ( value !== undefined ) device = value;
  13372. if ( value instanceof XRDevice ) gl.setCompatibleXRDevice( value );
  13373. };
  13374. //
  13375. function onSessionEvent( event ) {
  13376. var controller = controllers[ inputSources.indexOf( event.inputSource ) ];
  13377. if ( controller ) controller.dispatchEvent( { type: event.type } );
  13378. }
  13379. function onSessionEnd() {
  13380. renderer.setFramebuffer( null );
  13381. renderer.setRenderTarget( renderer.getRenderTarget() ); // Hack #15830
  13382. animation.stop();
  13383. }
  13384. this.setFramebufferScaleFactor = function ( value ) {
  13385. framebufferScaleFactor = value;
  13386. };
  13387. this.setFrameOfReferenceType = function ( value ) {
  13388. frameOfReferenceType = value;
  13389. };
  13390. this.setSession = function ( value ) {
  13391. session = value;
  13392. if ( session !== null ) {
  13393. session.addEventListener( 'select', onSessionEvent );
  13394. session.addEventListener( 'selectstart', onSessionEvent );
  13395. session.addEventListener( 'selectend', onSessionEvent );
  13396. session.addEventListener( 'end', onSessionEnd );
  13397. session.baseLayer = new XRWebGLLayer( session, gl, { framebufferScaleFactor: framebufferScaleFactor } );
  13398. session.requestFrameOfReference( frameOfReferenceType ).then( function ( value ) {
  13399. frameOfReference = value;
  13400. renderer.setFramebuffer( session.baseLayer.framebuffer );
  13401. animation.setContext( session );
  13402. animation.start();
  13403. } );
  13404. //
  13405. inputSources = session.getInputSources();
  13406. session.addEventListener( 'inputsourceschange', function () {
  13407. inputSources = session.getInputSources();
  13408. console.log( inputSources );
  13409. for ( var i = 0; i < controllers.length; i ++ ) {
  13410. var controller = controllers[ i ];
  13411. controller.userData.inputSource = inputSources[ i ];
  13412. }
  13413. } );
  13414. }
  13415. };
  13416. function updateCamera( camera, parent ) {
  13417. if ( parent === null ) {
  13418. camera.matrixWorld.copy( camera.matrix );
  13419. } else {
  13420. camera.matrixWorld.multiplyMatrices( parent.matrixWorld, camera.matrix );
  13421. }
  13422. camera.matrixWorldInverse.getInverse( camera.matrixWorld );
  13423. }
  13424. this.getCamera = function ( camera ) {
  13425. if ( isPresenting() ) {
  13426. var parent = camera.parent;
  13427. var cameras = cameraVR.cameras;
  13428. updateCamera( cameraVR, parent );
  13429. for ( var i = 0; i < cameras.length; i ++ ) {
  13430. updateCamera( cameras[ i ], parent );
  13431. }
  13432. // update camera and its children
  13433. camera.matrixWorld.copy( cameraVR.matrixWorld );
  13434. var children = camera.children;
  13435. for ( var i = 0, l = children.length; i < l; i ++ ) {
  13436. children[ i ].updateMatrixWorld( true );
  13437. }
  13438. setProjectionFromUnion( cameraVR, cameraL, cameraR );
  13439. return cameraVR;
  13440. }
  13441. return camera;
  13442. };
  13443. this.isPresenting = isPresenting;
  13444. // Animation Loop
  13445. var onAnimationFrameCallback = null;
  13446. function onAnimationFrame( time, frame ) {
  13447. pose = frame.getDevicePose( frameOfReference );
  13448. if ( pose !== null ) {
  13449. var layer = session.baseLayer;
  13450. var views = frame.views;
  13451. for ( var i = 0; i < views.length; i ++ ) {
  13452. var view = views[ i ];
  13453. var viewport = layer.getViewport( view );
  13454. var viewMatrix = pose.getViewMatrix( view );
  13455. var camera = cameraVR.cameras[ i ];
  13456. camera.matrix.fromArray( viewMatrix ).getInverse( camera.matrix );
  13457. camera.projectionMatrix.fromArray( view.projectionMatrix );
  13458. camera.viewport.set( viewport.x, viewport.y, viewport.width, viewport.height );
  13459. if ( i === 0 ) {
  13460. cameraVR.matrix.copy( camera.matrix );
  13461. }
  13462. }
  13463. }
  13464. //
  13465. for ( var i = 0; i < controllers.length; i ++ ) {
  13466. var controller = controllers[ i ];
  13467. var inputSource = inputSources[ i ];
  13468. if ( inputSource ) {
  13469. var inputPose = frame.getInputPose( inputSource, frameOfReference );
  13470. if ( inputPose !== null ) {
  13471. if ( 'targetRay' in inputPose ) {
  13472. controller.matrix.elements = inputPose.targetRay.transformMatrix;
  13473. } else if ( 'pointerMatrix' in inputPose ) {
  13474. // DEPRECATED
  13475. controller.matrix.elements = inputPose.pointerMatrix;
  13476. }
  13477. controller.matrix.decompose( controller.position, controller.rotation, controller.scale );
  13478. controller.visible = true;
  13479. continue;
  13480. }
  13481. }
  13482. controller.visible = false;
  13483. }
  13484. if ( onAnimationFrameCallback ) onAnimationFrameCallback( time );
  13485. }
  13486. var animation = new WebGLAnimation();
  13487. animation.setAnimationLoop( onAnimationFrame );
  13488. this.setAnimationLoop = function ( callback ) {
  13489. onAnimationFrameCallback = callback;
  13490. };
  13491. this.dispose = function () {};
  13492. // DEPRECATED
  13493. this.getStandingMatrix = function () {
  13494. console.warn( 'THREE.WebXRManager: getStandingMatrix() is no longer needed.' );
  13495. return new Matrix4();
  13496. };
  13497. this.submitFrame = function () {};
  13498. }
  13499. /**
  13500. * @author supereggbert / http://www.paulbrunt.co.uk/
  13501. * @author mrdoob / http://mrdoob.com/
  13502. * @author alteredq / http://alteredqualia.com/
  13503. * @author szimek / https://github.com/szimek/
  13504. * @author tschw
  13505. */
  13506. function WebGLRenderer( parameters ) {
  13507. console.log( 'THREE.WebGLRenderer', REVISION );
  13508. parameters = parameters || {};
  13509. var _canvas = parameters.canvas !== undefined ? parameters.canvas : document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' ),
  13510. _context = parameters.context !== undefined ? parameters.context : null,
  13511. _alpha = parameters.alpha !== undefined ? parameters.alpha : false,
  13512. _depth = parameters.depth !== undefined ? parameters.depth : true,
  13513. _stencil = parameters.stencil !== undefined ? parameters.stencil : true,
  13514. _antialias = parameters.antialias !== undefined ? parameters.antialias : false,
  13515. _premultipliedAlpha = parameters.premultipliedAlpha !== undefined ? parameters.premultipliedAlpha : true,
  13516. _preserveDrawingBuffer = parameters.preserveDrawingBuffer !== undefined ? parameters.preserveDrawingBuffer : false,
  13517. _powerPreference = parameters.powerPreference !== undefined ? parameters.powerPreference : 'default';
  13518. var currentRenderList = null;
  13519. var currentRenderState = null;
  13520. // public properties
  13521. this.domElement = _canvas;
  13522. this.context = null;
  13523. // Debug configuration container
  13524. this.debug = {
  13525. /**
  13526. * Enables error checking and reporting when shader programs are being compiled
  13527. * @type {boolean}
  13528. */
  13529. checkShaderErrors: false
  13530. };
  13531. // clearing
  13532. this.autoClear = true;
  13533. this.autoClearColor = true;
  13534. this.autoClearDepth = true;
  13535. this.autoClearStencil = true;
  13536. // scene graph
  13537. this.sortObjects = true;
  13538. // user-defined clipping
  13539. this.clippingPlanes = [];
  13540. this.localClippingEnabled = false;
  13541. // physically based shading
  13542. this.gammaFactor = 2.0; // for backwards compatibility
  13543. this.gammaInput = false;
  13544. this.gammaOutput = false;
  13545. // physical lights
  13546. this.physicallyCorrectLights = false;
  13547. // tone mapping
  13548. this.toneMapping = LinearToneMapping;
  13549. this.toneMappingExposure = 1.0;
  13550. this.toneMappingWhitePoint = 1.0;
  13551. // morphs
  13552. this.maxMorphTargets = 8;
  13553. this.maxMorphNormals = 4;
  13554. // internal properties
  13555. var _this = this,
  13556. _isContextLost = false,
  13557. // internal state cache
  13558. _framebuffer = null,
  13559. _currentRenderTarget = null,
  13560. _currentFramebuffer = null,
  13561. _currentMaterialId = - 1,
  13562. // geometry and program caching
  13563. _currentGeometryProgram = {
  13564. geometry: null,
  13565. program: null,
  13566. wireframe: false
  13567. },
  13568. _currentCamera = null,
  13569. _currentArrayCamera = null,
  13570. _currentViewport = new Vector4(),
  13571. _currentScissor = new Vector4(),
  13572. _currentScissorTest = null,
  13573. //
  13574. _width = _canvas.width,
  13575. _height = _canvas.height,
  13576. _pixelRatio = 1,
  13577. _viewport = new Vector4( 0, 0, _width, _height ),
  13578. _scissor = new Vector4( 0, 0, _width, _height ),
  13579. _scissorTest = false,
  13580. // frustum
  13581. _frustum = new Frustum(),
  13582. // clipping
  13583. _clipping = new WebGLClipping(),
  13584. _clippingEnabled = false,
  13585. _localClippingEnabled = false,
  13586. // camera matrices cache
  13587. _projScreenMatrix = new Matrix4(),
  13588. _vector3 = new Vector3();
  13589. function getTargetPixelRatio() {
  13590. return _currentRenderTarget === null ? _pixelRatio : 1;
  13591. }
  13592. // initialize
  13593. var _gl;
  13594. try {
  13595. var contextAttributes = {
  13596. alpha: _alpha,
  13597. depth: _depth,
  13598. stencil: _stencil,
  13599. antialias: _antialias,
  13600. premultipliedAlpha: _premultipliedAlpha,
  13601. preserveDrawingBuffer: _preserveDrawingBuffer,
  13602. powerPreference: _powerPreference
  13603. };
  13604. // event listeners must be registered before WebGL context is created, see #12753
  13605. _canvas.addEventListener( 'webglcontextlost', onContextLost, false );
  13606. _canvas.addEventListener( 'webglcontextrestored', onContextRestore, false );
  13607. _gl = _context || _canvas.getContext( 'webgl', contextAttributes ) || _canvas.getContext( 'experimental-webgl', contextAttributes );
  13608. if ( _gl === null ) {
  13609. if ( _canvas.getContext( 'webgl' ) !== null ) {
  13610. throw new Error( 'Error creating WebGL context with your selected attributes.' );
  13611. } else {
  13612. throw new Error( 'Error creating WebGL context.' );
  13613. }
  13614. }
  13615. // Some experimental-webgl implementations do not have getShaderPrecisionFormat
  13616. if ( _gl.getShaderPrecisionFormat === undefined ) {
  13617. _gl.getShaderPrecisionFormat = function () {
  13618. return { 'rangeMin': 1, 'rangeMax': 1, 'precision': 1 };
  13619. };
  13620. }
  13621. } catch ( error ) {
  13622. console.error( 'THREE.WebGLRenderer: ' + error.message );
  13623. throw error;
  13624. }
  13625. var extensions, capabilities, state, info;
  13626. var properties, textures, attributes, geometries, objects;
  13627. var programCache, renderLists, renderStates;
  13628. var background, morphtargets, bufferRenderer, indexedBufferRenderer;
  13629. var utils;
  13630. function initGLContext() {
  13631. extensions = new WebGLExtensions( _gl );
  13632. capabilities = new WebGLCapabilities( _gl, extensions, parameters );
  13633. if ( ! capabilities.isWebGL2 ) {
  13634. extensions.get( 'WEBGL_depth_texture' );
  13635. extensions.get( 'OES_texture_float' );
  13636. extensions.get( 'OES_texture_half_float' );
  13637. extensions.get( 'OES_texture_half_float_linear' );
  13638. extensions.get( 'OES_standard_derivatives' );
  13639. extensions.get( 'OES_element_index_uint' );
  13640. extensions.get( 'ANGLE_instanced_arrays' );
  13641. }
  13642. extensions.get( 'OES_texture_float_linear' );
  13643. utils = new WebGLUtils( _gl, extensions, capabilities );
  13644. state = new WebGLState( _gl, extensions, utils, capabilities );
  13645. state.scissor( _currentScissor.copy( _scissor ).multiplyScalar( _pixelRatio ) );
  13646. state.viewport( _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio ) );
  13647. info = new WebGLInfo( _gl );
  13648. properties = new WebGLProperties();
  13649. textures = new WebGLTextures( _gl, extensions, state, properties, capabilities, utils, info );
  13650. attributes = new WebGLAttributes( _gl );
  13651. geometries = new WebGLGeometries( _gl, attributes, info );
  13652. objects = new WebGLObjects( geometries, info );
  13653. morphtargets = new WebGLMorphtargets( _gl );
  13654. programCache = new WebGLPrograms( _this, extensions, capabilities, textures );
  13655. renderLists = new WebGLRenderLists();
  13656. renderStates = new WebGLRenderStates();
  13657. background = new WebGLBackground( _this, state, objects, _premultipliedAlpha );
  13658. bufferRenderer = new WebGLBufferRenderer( _gl, extensions, info, capabilities );
  13659. indexedBufferRenderer = new WebGLIndexedBufferRenderer( _gl, extensions, info, capabilities );
  13660. info.programs = programCache.programs;
  13661. _this.context = _gl;
  13662. _this.capabilities = capabilities;
  13663. _this.extensions = extensions;
  13664. _this.properties = properties;
  13665. _this.renderLists = renderLists;
  13666. _this.state = state;
  13667. _this.info = info;
  13668. }
  13669. initGLContext();
  13670. // vr
  13671. var vr = ( typeof navigator !== 'undefined' && 'xr' in navigator ) ? new WebXRManager( _this ) : new WebVRManager( _this );
  13672. this.vr = vr;
  13673. // shadow map
  13674. var shadowMap = new WebGLShadowMap( _this, objects, capabilities.maxTextureSize );
  13675. this.shadowMap = shadowMap;
  13676. // API
  13677. this.getContext = function () {
  13678. return _gl;
  13679. };
  13680. this.getContextAttributes = function () {
  13681. return _gl.getContextAttributes();
  13682. };
  13683. this.forceContextLoss = function () {
  13684. var extension = extensions.get( 'WEBGL_lose_context' );
  13685. if ( extension ) extension.loseContext();
  13686. };
  13687. this.forceContextRestore = function () {
  13688. var extension = extensions.get( 'WEBGL_lose_context' );
  13689. if ( extension ) extension.restoreContext();
  13690. };
  13691. this.getPixelRatio = function () {
  13692. return _pixelRatio;
  13693. };
  13694. this.setPixelRatio = function ( value ) {
  13695. if ( value === undefined ) return;
  13696. _pixelRatio = value;
  13697. this.setSize( _width, _height, false );
  13698. };
  13699. this.getSize = function ( target ) {
  13700. if ( target === undefined ) {
  13701. console.warn( 'WebGLRenderer: .getsize() now requires a Vector2 as an argument' );
  13702. target = new Vector2();
  13703. }
  13704. return target.set( _width, _height );
  13705. };
  13706. this.setSize = function ( width, height, updateStyle ) {
  13707. if ( vr.isPresenting() ) {
  13708. console.warn( 'THREE.WebGLRenderer: Can\'t change size while VR device is presenting.' );
  13709. return;
  13710. }
  13711. _width = width;
  13712. _height = height;
  13713. _canvas.width = width * _pixelRatio;
  13714. _canvas.height = height * _pixelRatio;
  13715. if ( updateStyle !== false ) {
  13716. _canvas.style.width = width + 'px';
  13717. _canvas.style.height = height + 'px';
  13718. }
  13719. this.setViewport( 0, 0, width, height );
  13720. };
  13721. this.getDrawingBufferSize = function ( target ) {
  13722. if ( target === undefined ) {
  13723. console.warn( 'WebGLRenderer: .getdrawingBufferSize() now requires a Vector2 as an argument' );
  13724. target = new Vector2();
  13725. }
  13726. return target.set( _width * _pixelRatio, _height * _pixelRatio );
  13727. };
  13728. this.setDrawingBufferSize = function ( width, height, pixelRatio ) {
  13729. _width = width;
  13730. _height = height;
  13731. _pixelRatio = pixelRatio;
  13732. _canvas.width = width * pixelRatio;
  13733. _canvas.height = height * pixelRatio;
  13734. this.setViewport( 0, 0, width, height );
  13735. };
  13736. this.getCurrentViewport = function ( target ) {
  13737. if ( target === undefined ) {
  13738. console.warn( 'WebGLRenderer: .getCurrentViewport() now requires a Vector4 as an argument' );
  13739. target = new Vector4();
  13740. }
  13741. return target.copy( _currentViewport );
  13742. };
  13743. this.getViewport = function ( target ) {
  13744. return target.copy( _viewport );
  13745. };
  13746. this.setViewport = function ( x, y, width, height ) {
  13747. if ( x.isVector4 ) {
  13748. _viewport.set( x.x, x.y, x.z, x.w );
  13749. } else {
  13750. _viewport.set( x, y, width, height );
  13751. }
  13752. state.viewport( _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio ) );
  13753. };
  13754. this.getScissor = function ( target ) {
  13755. return target.copy( _scissor );
  13756. };
  13757. this.setScissor = function ( x, y, width, height ) {
  13758. if ( x.isVector4 ) {
  13759. _scissor.set( x.x, x.y, x.z, x.w );
  13760. } else {
  13761. _scissor.set( x, y, width, height );
  13762. }
  13763. state.scissor( _currentScissor.copy( _scissor ).multiplyScalar( _pixelRatio ) );
  13764. };
  13765. this.getScissorTest = function () {
  13766. return _scissorTest;
  13767. };
  13768. this.setScissorTest = function ( boolean ) {
  13769. state.setScissorTest( _scissorTest = boolean );
  13770. };
  13771. // Clearing
  13772. this.getClearColor = function () {
  13773. return background.getClearColor();
  13774. };
  13775. this.setClearColor = function () {
  13776. background.setClearColor.apply( background, arguments );
  13777. };
  13778. this.getClearAlpha = function () {
  13779. return background.getClearAlpha();
  13780. };
  13781. this.setClearAlpha = function () {
  13782. background.setClearAlpha.apply( background, arguments );
  13783. };
  13784. this.clear = function ( color, depth, stencil ) {
  13785. var bits = 0;
  13786. if ( color === undefined || color ) bits |= 16384;
  13787. if ( depth === undefined || depth ) bits |= 256;
  13788. if ( stencil === undefined || stencil ) bits |= 1024;
  13789. _gl.clear( bits );
  13790. };
  13791. this.clearColor = function () {
  13792. this.clear( true, false, false );
  13793. };
  13794. this.clearDepth = function () {
  13795. this.clear( false, true, false );
  13796. };
  13797. this.clearStencil = function () {
  13798. this.clear( false, false, true );
  13799. };
  13800. //
  13801. this.dispose = function () {
  13802. _canvas.removeEventListener( 'webglcontextlost', onContextLost, false );
  13803. _canvas.removeEventListener( 'webglcontextrestored', onContextRestore, false );
  13804. renderLists.dispose();
  13805. renderStates.dispose();
  13806. properties.dispose();
  13807. objects.dispose();
  13808. vr.dispose();
  13809. animation.stop();
  13810. };
  13811. // Events
  13812. function onContextLost( event ) {
  13813. event.preventDefault();
  13814. console.log( 'THREE.WebGLRenderer: Context Lost.' );
  13815. _isContextLost = true;
  13816. }
  13817. function onContextRestore( /* event */ ) {
  13818. console.log( 'THREE.WebGLRenderer: Context Restored.' );
  13819. _isContextLost = false;
  13820. initGLContext();
  13821. }
  13822. function onMaterialDispose( event ) {
  13823. var material = event.target;
  13824. material.removeEventListener( 'dispose', onMaterialDispose );
  13825. deallocateMaterial( material );
  13826. }
  13827. // Buffer deallocation
  13828. function deallocateMaterial( material ) {
  13829. releaseMaterialProgramReference( material );
  13830. properties.remove( material );
  13831. }
  13832. function releaseMaterialProgramReference( material ) {
  13833. var programInfo = properties.get( material ).program;
  13834. material.program = undefined;
  13835. if ( programInfo !== undefined ) {
  13836. programCache.releaseProgram( programInfo );
  13837. }
  13838. }
  13839. // Buffer rendering
  13840. function renderObjectImmediate( object, program ) {
  13841. object.render( function ( object ) {
  13842. _this.renderBufferImmediate( object, program );
  13843. } );
  13844. }
  13845. this.renderBufferImmediate = function ( object, program ) {
  13846. state.initAttributes();
  13847. var buffers = properties.get( object );
  13848. if ( object.hasPositions && ! buffers.position ) buffers.position = _gl.createBuffer();
  13849. if ( object.hasNormals && ! buffers.normal ) buffers.normal = _gl.createBuffer();
  13850. if ( object.hasUvs && ! buffers.uv ) buffers.uv = _gl.createBuffer();
  13851. if ( object.hasColors && ! buffers.color ) buffers.color = _gl.createBuffer();
  13852. var programAttributes = program.getAttributes();
  13853. if ( object.hasPositions ) {
  13854. _gl.bindBuffer( 34962, buffers.position );
  13855. _gl.bufferData( 34962, object.positionArray, 35048 );
  13856. state.enableAttribute( programAttributes.position );
  13857. _gl.vertexAttribPointer( programAttributes.position, 3, 5126, false, 0, 0 );
  13858. }
  13859. if ( object.hasNormals ) {
  13860. _gl.bindBuffer( 34962, buffers.normal );
  13861. _gl.bufferData( 34962, object.normalArray, 35048 );
  13862. state.enableAttribute( programAttributes.normal );
  13863. _gl.vertexAttribPointer( programAttributes.normal, 3, 5126, false, 0, 0 );
  13864. }
  13865. if ( object.hasUvs ) {
  13866. _gl.bindBuffer( 34962, buffers.uv );
  13867. _gl.bufferData( 34962, object.uvArray, 35048 );
  13868. state.enableAttribute( programAttributes.uv );
  13869. _gl.vertexAttribPointer( programAttributes.uv, 2, 5126, false, 0, 0 );
  13870. }
  13871. if ( object.hasColors ) {
  13872. _gl.bindBuffer( 34962, buffers.color );
  13873. _gl.bufferData( 34962, object.colorArray, 35048 );
  13874. state.enableAttribute( programAttributes.color );
  13875. _gl.vertexAttribPointer( programAttributes.color, 3, 5126, false, 0, 0 );
  13876. }
  13877. state.disableUnusedAttributes();
  13878. _gl.drawArrays( 4, 0, object.count );
  13879. object.count = 0;
  13880. };
  13881. this.renderBufferDirect = function ( camera, fog, geometry, material, object, group ) {
  13882. var frontFaceCW = ( object.isMesh && object.matrixWorld.determinant() < 0 );
  13883. state.setMaterial( material, frontFaceCW );
  13884. var program = setProgram( camera, fog, material, object );
  13885. var updateBuffers = false;
  13886. if ( _currentGeometryProgram.geometry !== geometry.id ||
  13887. _currentGeometryProgram.program !== program.id ||
  13888. _currentGeometryProgram.wireframe !== ( material.wireframe === true ) ) {
  13889. _currentGeometryProgram.geometry = geometry.id;
  13890. _currentGeometryProgram.program = program.id;
  13891. _currentGeometryProgram.wireframe = material.wireframe === true;
  13892. updateBuffers = true;
  13893. }
  13894. if ( object.morphTargetInfluences ) {
  13895. morphtargets.update( object, geometry, material, program );
  13896. updateBuffers = true;
  13897. }
  13898. //
  13899. var index = geometry.index;
  13900. var position = geometry.attributes.position;
  13901. var rangeFactor = 1;
  13902. if ( material.wireframe === true ) {
  13903. index = geometries.getWireframeAttribute( geometry );
  13904. rangeFactor = 2;
  13905. }
  13906. var attribute;
  13907. var renderer = bufferRenderer;
  13908. if ( index !== null ) {
  13909. attribute = attributes.get( index );
  13910. renderer = indexedBufferRenderer;
  13911. renderer.setIndex( attribute );
  13912. }
  13913. if ( updateBuffers ) {
  13914. setupVertexAttributes( material, program, geometry );
  13915. if ( index !== null ) {
  13916. _gl.bindBuffer( 34963, attribute.buffer );
  13917. }
  13918. }
  13919. //
  13920. var dataCount = Infinity;
  13921. if ( index !== null ) {
  13922. dataCount = index.count;
  13923. } else if ( position !== undefined ) {
  13924. dataCount = position.count;
  13925. }
  13926. var rangeStart = geometry.drawRange.start * rangeFactor;
  13927. var rangeCount = geometry.drawRange.count * rangeFactor;
  13928. var groupStart = group !== null ? group.start * rangeFactor : 0;
  13929. var groupCount = group !== null ? group.count * rangeFactor : Infinity;
  13930. var drawStart = Math.max( rangeStart, groupStart );
  13931. var drawEnd = Math.min( dataCount, rangeStart + rangeCount, groupStart + groupCount ) - 1;
  13932. var drawCount = Math.max( 0, drawEnd - drawStart + 1 );
  13933. if ( drawCount === 0 ) return;
  13934. //
  13935. if ( object.isMesh ) {
  13936. if ( material.wireframe === true ) {
  13937. state.setLineWidth( material.wireframeLinewidth * getTargetPixelRatio() );
  13938. renderer.setMode( 1 );
  13939. } else {
  13940. switch ( object.drawMode ) {
  13941. case TrianglesDrawMode:
  13942. renderer.setMode( 4 );
  13943. break;
  13944. case TriangleStripDrawMode:
  13945. renderer.setMode( 5 );
  13946. break;
  13947. case TriangleFanDrawMode:
  13948. renderer.setMode( 6 );
  13949. break;
  13950. }
  13951. }
  13952. } else if ( object.isLine ) {
  13953. var lineWidth = material.linewidth;
  13954. if ( lineWidth === undefined ) lineWidth = 1; // Not using Line*Material
  13955. state.setLineWidth( lineWidth * getTargetPixelRatio() );
  13956. if ( object.isLineSegments ) {
  13957. renderer.setMode( 1 );
  13958. } else if ( object.isLineLoop ) {
  13959. renderer.setMode( 2 );
  13960. } else {
  13961. renderer.setMode( 3 );
  13962. }
  13963. } else if ( object.isPoints ) {
  13964. renderer.setMode( 0 );
  13965. } else if ( object.isSprite ) {
  13966. renderer.setMode( 4 );
  13967. }
  13968. if ( geometry && geometry.isInstancedBufferGeometry ) {
  13969. if ( geometry.maxInstancedCount > 0 ) {
  13970. renderer.renderInstances( geometry, drawStart, drawCount );
  13971. }
  13972. } else {
  13973. renderer.render( drawStart, drawCount );
  13974. }
  13975. };
  13976. function setupVertexAttributes( material, program, geometry ) {
  13977. if ( geometry && geometry.isInstancedBufferGeometry && ! capabilities.isWebGL2 ) {
  13978. if ( extensions.get( 'ANGLE_instanced_arrays' ) === null ) {
  13979. console.error( 'THREE.WebGLRenderer.setupVertexAttributes: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  13980. return;
  13981. }
  13982. }
  13983. state.initAttributes();
  13984. var geometryAttributes = geometry.attributes;
  13985. var programAttributes = program.getAttributes();
  13986. var materialDefaultAttributeValues = material.defaultAttributeValues;
  13987. for ( var name in programAttributes ) {
  13988. var programAttribute = programAttributes[ name ];
  13989. if ( programAttribute >= 0 ) {
  13990. var geometryAttribute = geometryAttributes[ name ];
  13991. if ( geometryAttribute !== undefined ) {
  13992. var normalized = geometryAttribute.normalized;
  13993. var size = geometryAttribute.itemSize;
  13994. var attribute = attributes.get( geometryAttribute );
  13995. // TODO Attribute may not be available on context restore
  13996. if ( attribute === undefined ) continue;
  13997. var buffer = attribute.buffer;
  13998. var type = attribute.type;
  13999. var bytesPerElement = attribute.bytesPerElement;
  14000. if ( geometryAttribute.isInterleavedBufferAttribute ) {
  14001. var data = geometryAttribute.data;
  14002. var stride = data.stride;
  14003. var offset = geometryAttribute.offset;
  14004. if ( data && data.isInstancedInterleavedBuffer ) {
  14005. state.enableAttributeAndDivisor( programAttribute, data.meshPerAttribute );
  14006. if ( geometry.maxInstancedCount === undefined ) {
  14007. geometry.maxInstancedCount = data.meshPerAttribute * data.count;
  14008. }
  14009. } else {
  14010. state.enableAttribute( programAttribute );
  14011. }
  14012. _gl.bindBuffer( 34962, buffer );
  14013. _gl.vertexAttribPointer( programAttribute, size, type, normalized, stride * bytesPerElement, offset * bytesPerElement );
  14014. } else {
  14015. if ( geometryAttribute.isInstancedBufferAttribute ) {
  14016. state.enableAttributeAndDivisor( programAttribute, geometryAttribute.meshPerAttribute );
  14017. if ( geometry.maxInstancedCount === undefined ) {
  14018. geometry.maxInstancedCount = geometryAttribute.meshPerAttribute * geometryAttribute.count;
  14019. }
  14020. } else {
  14021. state.enableAttribute( programAttribute );
  14022. }
  14023. _gl.bindBuffer( 34962, buffer );
  14024. _gl.vertexAttribPointer( programAttribute, size, type, normalized, 0, 0 );
  14025. }
  14026. } else if ( materialDefaultAttributeValues !== undefined ) {
  14027. var value = materialDefaultAttributeValues[ name ];
  14028. if ( value !== undefined ) {
  14029. switch ( value.length ) {
  14030. case 2:
  14031. _gl.vertexAttrib2fv( programAttribute, value );
  14032. break;
  14033. case 3:
  14034. _gl.vertexAttrib3fv( programAttribute, value );
  14035. break;
  14036. case 4:
  14037. _gl.vertexAttrib4fv( programAttribute, value );
  14038. break;
  14039. default:
  14040. _gl.vertexAttrib1fv( programAttribute, value );
  14041. }
  14042. }
  14043. }
  14044. }
  14045. }
  14046. state.disableUnusedAttributes();
  14047. }
  14048. // Compile
  14049. this.compile = function ( scene, camera ) {
  14050. currentRenderState = renderStates.get( scene, camera );
  14051. currentRenderState.init();
  14052. scene.traverse( function ( object ) {
  14053. if ( object.isLight ) {
  14054. currentRenderState.pushLight( object );
  14055. if ( object.castShadow ) {
  14056. currentRenderState.pushShadow( object );
  14057. }
  14058. }
  14059. } );
  14060. currentRenderState.setupLights( camera );
  14061. scene.traverse( function ( object ) {
  14062. if ( object.material ) {
  14063. if ( Array.isArray( object.material ) ) {
  14064. for ( var i = 0; i < object.material.length; i ++ ) {
  14065. initMaterial( object.material[ i ], scene.fog, object );
  14066. }
  14067. } else {
  14068. initMaterial( object.material, scene.fog, object );
  14069. }
  14070. }
  14071. } );
  14072. };
  14073. // Animation Loop
  14074. var onAnimationFrameCallback = null;
  14075. function onAnimationFrame( time ) {
  14076. if ( vr.isPresenting() ) return;
  14077. if ( onAnimationFrameCallback ) onAnimationFrameCallback( time );
  14078. }
  14079. var animation = new WebGLAnimation();
  14080. animation.setAnimationLoop( onAnimationFrame );
  14081. if ( typeof window !== 'undefined' ) animation.setContext( window );
  14082. this.setAnimationLoop = function ( callback ) {
  14083. onAnimationFrameCallback = callback;
  14084. vr.setAnimationLoop( callback );
  14085. animation.start();
  14086. };
  14087. // Rendering
  14088. this.render = function ( scene, camera ) {
  14089. var renderTarget, forceClear;
  14090. if ( arguments[ 2 ] !== undefined ) {
  14091. console.warn( 'THREE.WebGLRenderer.render(): the renderTarget argument has been removed. Use .setRenderTarget() instead.' );
  14092. renderTarget = arguments[ 2 ];
  14093. }
  14094. if ( arguments[ 3 ] !== undefined ) {
  14095. console.warn( 'THREE.WebGLRenderer.render(): the forceClear argument has been removed. Use .clear() instead.' );
  14096. forceClear = arguments[ 3 ];
  14097. }
  14098. if ( ! ( camera && camera.isCamera ) ) {
  14099. console.error( 'THREE.WebGLRenderer.render: camera is not an instance of THREE.Camera.' );
  14100. return;
  14101. }
  14102. if ( _isContextLost ) return;
  14103. // reset caching for this frame
  14104. _currentGeometryProgram.geometry = null;
  14105. _currentGeometryProgram.program = null;
  14106. _currentGeometryProgram.wireframe = false;
  14107. _currentMaterialId = - 1;
  14108. _currentCamera = null;
  14109. // update scene graph
  14110. if ( scene.autoUpdate === true ) scene.updateMatrixWorld();
  14111. // update camera matrices and frustum
  14112. if ( camera.parent === null ) camera.updateMatrixWorld();
  14113. if ( vr.enabled ) {
  14114. camera = vr.getCamera( camera );
  14115. }
  14116. //
  14117. currentRenderState = renderStates.get( scene, camera );
  14118. currentRenderState.init();
  14119. scene.onBeforeRender( _this, scene, camera, renderTarget || _currentRenderTarget );
  14120. _projScreenMatrix.multiplyMatrices( camera.projectionMatrix, camera.matrixWorldInverse );
  14121. _frustum.setFromMatrix( _projScreenMatrix );
  14122. _localClippingEnabled = this.localClippingEnabled;
  14123. _clippingEnabled = _clipping.init( this.clippingPlanes, _localClippingEnabled, camera );
  14124. currentRenderList = renderLists.get( scene, camera );
  14125. currentRenderList.init();
  14126. projectObject( scene, camera, 0, _this.sortObjects );
  14127. if ( _this.sortObjects === true ) {
  14128. currentRenderList.sort();
  14129. }
  14130. //
  14131. if ( _clippingEnabled ) _clipping.beginShadows();
  14132. var shadowsArray = currentRenderState.state.shadowsArray;
  14133. shadowMap.render( shadowsArray, scene, camera );
  14134. currentRenderState.setupLights( camera );
  14135. if ( _clippingEnabled ) _clipping.endShadows();
  14136. //
  14137. if ( this.info.autoReset ) this.info.reset();
  14138. if ( renderTarget !== undefined ) {
  14139. this.setRenderTarget( renderTarget );
  14140. }
  14141. //
  14142. background.render( currentRenderList, scene, camera, forceClear );
  14143. // render scene
  14144. var opaqueObjects = currentRenderList.opaque;
  14145. var transparentObjects = currentRenderList.transparent;
  14146. if ( scene.overrideMaterial ) {
  14147. var overrideMaterial = scene.overrideMaterial;
  14148. if ( opaqueObjects.length ) renderObjects( opaqueObjects, scene, camera, overrideMaterial );
  14149. if ( transparentObjects.length ) renderObjects( transparentObjects, scene, camera, overrideMaterial );
  14150. } else {
  14151. // opaque pass (front-to-back order)
  14152. if ( opaqueObjects.length ) renderObjects( opaqueObjects, scene, camera );
  14153. // transparent pass (back-to-front order)
  14154. if ( transparentObjects.length ) renderObjects( transparentObjects, scene, camera );
  14155. }
  14156. //
  14157. scene.onAfterRender( _this, scene, camera );
  14158. //
  14159. if ( _currentRenderTarget !== null ) {
  14160. // Generate mipmap if we're using any kind of mipmap filtering
  14161. textures.updateRenderTargetMipmap( _currentRenderTarget );
  14162. // resolve multisample renderbuffers to a single-sample texture if necessary
  14163. textures.updateMultisampleRenderTarget( _currentRenderTarget );
  14164. }
  14165. // Ensure depth buffer writing is enabled so it can be cleared on next render
  14166. state.buffers.depth.setTest( true );
  14167. state.buffers.depth.setMask( true );
  14168. state.buffers.color.setMask( true );
  14169. state.setPolygonOffset( false );
  14170. if ( vr.enabled ) {
  14171. vr.submitFrame();
  14172. }
  14173. // _gl.finish();
  14174. currentRenderList = null;
  14175. currentRenderState = null;
  14176. };
  14177. function projectObject( object, camera, groupOrder, sortObjects ) {
  14178. if ( object.visible === false ) return;
  14179. var visible = object.layers.test( camera.layers );
  14180. if ( visible ) {
  14181. if ( object.isGroup ) {
  14182. groupOrder = object.renderOrder;
  14183. } else if ( object.isLight ) {
  14184. currentRenderState.pushLight( object );
  14185. if ( object.castShadow ) {
  14186. currentRenderState.pushShadow( object );
  14187. }
  14188. } else if ( object.isSprite ) {
  14189. if ( ! object.frustumCulled || _frustum.intersectsSprite( object ) ) {
  14190. if ( sortObjects ) {
  14191. _vector3.setFromMatrixPosition( object.matrixWorld )
  14192. .applyMatrix4( _projScreenMatrix );
  14193. }
  14194. var geometry = objects.update( object );
  14195. var material = object.material;
  14196. if ( material.visible ) {
  14197. currentRenderList.push( object, geometry, material, groupOrder, _vector3.z, null );
  14198. }
  14199. }
  14200. } else if ( object.isImmediateRenderObject ) {
  14201. if ( sortObjects ) {
  14202. _vector3.setFromMatrixPosition( object.matrixWorld )
  14203. .applyMatrix4( _projScreenMatrix );
  14204. }
  14205. currentRenderList.push( object, null, object.material, groupOrder, _vector3.z, null );
  14206. } else if ( object.isMesh || object.isLine || object.isPoints ) {
  14207. if ( object.isSkinnedMesh ) {
  14208. object.skeleton.update();
  14209. }
  14210. if ( ! object.frustumCulled || _frustum.intersectsObject( object ) ) {
  14211. if ( sortObjects ) {
  14212. _vector3.setFromMatrixPosition( object.matrixWorld )
  14213. .applyMatrix4( _projScreenMatrix );
  14214. }
  14215. var geometry = objects.update( object );
  14216. var material = object.material;
  14217. if ( Array.isArray( material ) ) {
  14218. var groups = geometry.groups;
  14219. for ( var i = 0, l = groups.length; i < l; i ++ ) {
  14220. var group = groups[ i ];
  14221. var groupMaterial = material[ group.materialIndex ];
  14222. if ( groupMaterial && groupMaterial.visible ) {
  14223. currentRenderList.push( object, geometry, groupMaterial, groupOrder, _vector3.z, group );
  14224. }
  14225. }
  14226. } else if ( material.visible ) {
  14227. currentRenderList.push( object, geometry, material, groupOrder, _vector3.z, null );
  14228. }
  14229. }
  14230. }
  14231. }
  14232. var children = object.children;
  14233. for ( var i = 0, l = children.length; i < l; i ++ ) {
  14234. projectObject( children[ i ], camera, groupOrder, sortObjects );
  14235. }
  14236. }
  14237. function renderObjects( renderList, scene, camera, overrideMaterial ) {
  14238. for ( var i = 0, l = renderList.length; i < l; i ++ ) {
  14239. var renderItem = renderList[ i ];
  14240. var object = renderItem.object;
  14241. var geometry = renderItem.geometry;
  14242. var material = overrideMaterial === undefined ? renderItem.material : overrideMaterial;
  14243. var group = renderItem.group;
  14244. if ( camera.isArrayCamera ) {
  14245. _currentArrayCamera = camera;
  14246. var cameras = camera.cameras;
  14247. for ( var j = 0, jl = cameras.length; j < jl; j ++ ) {
  14248. var camera2 = cameras[ j ];
  14249. if ( object.layers.test( camera2.layers ) ) {
  14250. if ( 'viewport' in camera2 ) { // XR
  14251. state.viewport( _currentViewport.copy( camera2.viewport ) );
  14252. } else {
  14253. var bounds = camera2.bounds;
  14254. var x = bounds.x * _width;
  14255. var y = bounds.y * _height;
  14256. var width = bounds.z * _width;
  14257. var height = bounds.w * _height;
  14258. state.viewport( _currentViewport.set( x, y, width, height ).multiplyScalar( _pixelRatio ) );
  14259. }
  14260. currentRenderState.setupLights( camera2 );
  14261. renderObject( object, scene, camera2, geometry, material, group );
  14262. }
  14263. }
  14264. } else {
  14265. _currentArrayCamera = null;
  14266. renderObject( object, scene, camera, geometry, material, group );
  14267. }
  14268. }
  14269. }
  14270. function renderObject( object, scene, camera, geometry, material, group ) {
  14271. object.onBeforeRender( _this, scene, camera, geometry, material, group );
  14272. currentRenderState = renderStates.get( scene, _currentArrayCamera || camera );
  14273. object.modelViewMatrix.multiplyMatrices( camera.matrixWorldInverse, object.matrixWorld );
  14274. object.normalMatrix.getNormalMatrix( object.modelViewMatrix );
  14275. if ( object.isImmediateRenderObject ) {
  14276. state.setMaterial( material );
  14277. var program = setProgram( camera, scene.fog, material, object );
  14278. _currentGeometryProgram.geometry = null;
  14279. _currentGeometryProgram.program = null;
  14280. _currentGeometryProgram.wireframe = false;
  14281. renderObjectImmediate( object, program );
  14282. } else {
  14283. _this.renderBufferDirect( camera, scene.fog, geometry, material, object, group );
  14284. }
  14285. object.onAfterRender( _this, scene, camera, geometry, material, group );
  14286. currentRenderState = renderStates.get( scene, _currentArrayCamera || camera );
  14287. }
  14288. function initMaterial( material, fog, object ) {
  14289. var materialProperties = properties.get( material );
  14290. var lights = currentRenderState.state.lights;
  14291. var shadowsArray = currentRenderState.state.shadowsArray;
  14292. var lightsHash = materialProperties.lightsHash;
  14293. var lightsStateHash = lights.state.hash;
  14294. var parameters = programCache.getParameters(
  14295. material, lights.state, shadowsArray, fog, _clipping.numPlanes, _clipping.numIntersection, object );
  14296. var code = programCache.getProgramCode( material, parameters );
  14297. var program = materialProperties.program;
  14298. var programChange = true;
  14299. if ( program === undefined ) {
  14300. // new material
  14301. material.addEventListener( 'dispose', onMaterialDispose );
  14302. } else if ( program.code !== code ) {
  14303. // changed glsl or parameters
  14304. releaseMaterialProgramReference( material );
  14305. } else if ( lightsHash.stateID !== lightsStateHash.stateID ||
  14306. lightsHash.directionalLength !== lightsStateHash.directionalLength ||
  14307. lightsHash.pointLength !== lightsStateHash.pointLength ||
  14308. lightsHash.spotLength !== lightsStateHash.spotLength ||
  14309. lightsHash.rectAreaLength !== lightsStateHash.rectAreaLength ||
  14310. lightsHash.hemiLength !== lightsStateHash.hemiLength ||
  14311. lightsHash.shadowsLength !== lightsStateHash.shadowsLength ) {
  14312. lightsHash.stateID = lightsStateHash.stateID;
  14313. lightsHash.directionalLength = lightsStateHash.directionalLength;
  14314. lightsHash.pointLength = lightsStateHash.pointLength;
  14315. lightsHash.spotLength = lightsStateHash.spotLength;
  14316. lightsHash.rectAreaLength = lightsStateHash.rectAreaLength;
  14317. lightsHash.hemiLength = lightsStateHash.hemiLength;
  14318. lightsHash.shadowsLength = lightsStateHash.shadowsLength;
  14319. programChange = false;
  14320. } else if ( parameters.shaderID !== undefined ) {
  14321. // same glsl and uniform list
  14322. return;
  14323. } else {
  14324. // only rebuild uniform list
  14325. programChange = false;
  14326. }
  14327. if ( programChange ) {
  14328. if ( parameters.shaderID ) {
  14329. var shader = ShaderLib[ parameters.shaderID ];
  14330. materialProperties.shader = {
  14331. name: material.type,
  14332. uniforms: cloneUniforms( shader.uniforms ),
  14333. vertexShader: shader.vertexShader,
  14334. fragmentShader: shader.fragmentShader
  14335. };
  14336. } else {
  14337. materialProperties.shader = {
  14338. name: material.type,
  14339. uniforms: material.uniforms,
  14340. vertexShader: material.vertexShader,
  14341. fragmentShader: material.fragmentShader
  14342. };
  14343. }
  14344. material.onBeforeCompile( materialProperties.shader, _this );
  14345. // Computing code again as onBeforeCompile may have changed the shaders
  14346. code = programCache.getProgramCode( material, parameters );
  14347. program = programCache.acquireProgram( material, materialProperties.shader, parameters, code );
  14348. materialProperties.program = program;
  14349. material.program = program;
  14350. }
  14351. var programAttributes = program.getAttributes();
  14352. if ( material.morphTargets ) {
  14353. material.numSupportedMorphTargets = 0;
  14354. for ( var i = 0; i < _this.maxMorphTargets; i ++ ) {
  14355. if ( programAttributes[ 'morphTarget' + i ] >= 0 ) {
  14356. material.numSupportedMorphTargets ++;
  14357. }
  14358. }
  14359. }
  14360. if ( material.morphNormals ) {
  14361. material.numSupportedMorphNormals = 0;
  14362. for ( var i = 0; i < _this.maxMorphNormals; i ++ ) {
  14363. if ( programAttributes[ 'morphNormal' + i ] >= 0 ) {
  14364. material.numSupportedMorphNormals ++;
  14365. }
  14366. }
  14367. }
  14368. var uniforms = materialProperties.shader.uniforms;
  14369. if ( ! material.isShaderMaterial &&
  14370. ! material.isRawShaderMaterial ||
  14371. material.clipping === true ) {
  14372. materialProperties.numClippingPlanes = _clipping.numPlanes;
  14373. materialProperties.numIntersection = _clipping.numIntersection;
  14374. uniforms.clippingPlanes = _clipping.uniform;
  14375. }
  14376. materialProperties.fog = fog;
  14377. // store the light setup it was created for
  14378. if ( lightsHash === undefined ) {
  14379. materialProperties.lightsHash = lightsHash = {};
  14380. }
  14381. lightsHash.stateID = lightsStateHash.stateID;
  14382. lightsHash.directionalLength = lightsStateHash.directionalLength;
  14383. lightsHash.pointLength = lightsStateHash.pointLength;
  14384. lightsHash.spotLength = lightsStateHash.spotLength;
  14385. lightsHash.rectAreaLength = lightsStateHash.rectAreaLength;
  14386. lightsHash.hemiLength = lightsStateHash.hemiLength;
  14387. lightsHash.shadowsLength = lightsStateHash.shadowsLength;
  14388. if ( material.lights ) {
  14389. // wire up the material to this renderer's lighting state
  14390. uniforms.ambientLightColor.value = lights.state.ambient;
  14391. uniforms.lightProbe.value = lights.state.probe;
  14392. uniforms.directionalLights.value = lights.state.directional;
  14393. uniforms.spotLights.value = lights.state.spot;
  14394. uniforms.rectAreaLights.value = lights.state.rectArea;
  14395. uniforms.pointLights.value = lights.state.point;
  14396. uniforms.hemisphereLights.value = lights.state.hemi;
  14397. uniforms.directionalShadowMap.value = lights.state.directionalShadowMap;
  14398. uniforms.directionalShadowMatrix.value = lights.state.directionalShadowMatrix;
  14399. uniforms.spotShadowMap.value = lights.state.spotShadowMap;
  14400. uniforms.spotShadowMatrix.value = lights.state.spotShadowMatrix;
  14401. uniforms.pointShadowMap.value = lights.state.pointShadowMap;
  14402. uniforms.pointShadowMatrix.value = lights.state.pointShadowMatrix;
  14403. // TODO (abelnation): add area lights shadow info to uniforms
  14404. }
  14405. var progUniforms = materialProperties.program.getUniforms(),
  14406. uniformsList =
  14407. WebGLUniforms.seqWithValue( progUniforms.seq, uniforms );
  14408. materialProperties.uniformsList = uniformsList;
  14409. }
  14410. function setProgram( camera, fog, material, object ) {
  14411. textures.resetTextureUnits();
  14412. var materialProperties = properties.get( material );
  14413. var lights = currentRenderState.state.lights;
  14414. var lightsHash = materialProperties.lightsHash;
  14415. var lightsStateHash = lights.state.hash;
  14416. if ( _clippingEnabled ) {
  14417. if ( _localClippingEnabled || camera !== _currentCamera ) {
  14418. var useCache =
  14419. camera === _currentCamera &&
  14420. material.id === _currentMaterialId;
  14421. // we might want to call this function with some ClippingGroup
  14422. // object instead of the material, once it becomes feasible
  14423. // (#8465, #8379)
  14424. _clipping.setState(
  14425. material.clippingPlanes, material.clipIntersection, material.clipShadows,
  14426. camera, materialProperties, useCache );
  14427. }
  14428. }
  14429. if ( material.needsUpdate === false ) {
  14430. if ( materialProperties.program === undefined ) {
  14431. material.needsUpdate = true;
  14432. } else if ( material.fog && materialProperties.fog !== fog ) {
  14433. material.needsUpdate = true;
  14434. } else if ( material.lights && ( lightsHash.stateID !== lightsStateHash.stateID ||
  14435. lightsHash.directionalLength !== lightsStateHash.directionalLength ||
  14436. lightsHash.pointLength !== lightsStateHash.pointLength ||
  14437. lightsHash.spotLength !== lightsStateHash.spotLength ||
  14438. lightsHash.rectAreaLength !== lightsStateHash.rectAreaLength ||
  14439. lightsHash.hemiLength !== lightsStateHash.hemiLength ||
  14440. lightsHash.shadowsLength !== lightsStateHash.shadowsLength ) ) {
  14441. material.needsUpdate = true;
  14442. } else if ( materialProperties.numClippingPlanes !== undefined &&
  14443. ( materialProperties.numClippingPlanes !== _clipping.numPlanes ||
  14444. materialProperties.numIntersection !== _clipping.numIntersection ) ) {
  14445. material.needsUpdate = true;
  14446. }
  14447. }
  14448. if ( material.needsUpdate ) {
  14449. initMaterial( material, fog, object );
  14450. material.needsUpdate = false;
  14451. }
  14452. var refreshProgram = false;
  14453. var refreshMaterial = false;
  14454. var refreshLights = false;
  14455. var program = materialProperties.program,
  14456. p_uniforms = program.getUniforms(),
  14457. m_uniforms = materialProperties.shader.uniforms;
  14458. if ( state.useProgram( program.program ) ) {
  14459. refreshProgram = true;
  14460. refreshMaterial = true;
  14461. refreshLights = true;
  14462. }
  14463. if ( material.id !== _currentMaterialId ) {
  14464. _currentMaterialId = material.id;
  14465. refreshMaterial = true;
  14466. }
  14467. if ( refreshProgram || _currentCamera !== camera ) {
  14468. p_uniforms.setValue( _gl, 'projectionMatrix', camera.projectionMatrix );
  14469. if ( capabilities.logarithmicDepthBuffer ) {
  14470. p_uniforms.setValue( _gl, 'logDepthBufFC',
  14471. 2.0 / ( Math.log( camera.far + 1.0 ) / Math.LN2 ) );
  14472. }
  14473. if ( _currentCamera !== camera ) {
  14474. _currentCamera = camera;
  14475. // lighting uniforms depend on the camera so enforce an update
  14476. // now, in case this material supports lights - or later, when
  14477. // the next material that does gets activated:
  14478. refreshMaterial = true; // set to true on material change
  14479. refreshLights = true; // remains set until update done
  14480. }
  14481. // load material specific uniforms
  14482. // (shader material also gets them for the sake of genericity)
  14483. if ( material.isShaderMaterial ||
  14484. material.isMeshPhongMaterial ||
  14485. material.isMeshStandardMaterial ||
  14486. material.envMap ) {
  14487. var uCamPos = p_uniforms.map.cameraPosition;
  14488. if ( uCamPos !== undefined ) {
  14489. uCamPos.setValue( _gl,
  14490. _vector3.setFromMatrixPosition( camera.matrixWorld ) );
  14491. }
  14492. }
  14493. if ( material.isMeshPhongMaterial ||
  14494. material.isMeshLambertMaterial ||
  14495. material.isMeshBasicMaterial ||
  14496. material.isMeshStandardMaterial ||
  14497. material.isShaderMaterial ||
  14498. material.skinning ) {
  14499. p_uniforms.setValue( _gl, 'viewMatrix', camera.matrixWorldInverse );
  14500. }
  14501. }
  14502. // skinning uniforms must be set even if material didn't change
  14503. // auto-setting of texture unit for bone texture must go before other textures
  14504. // not sure why, but otherwise weird things happen
  14505. if ( material.skinning ) {
  14506. p_uniforms.setOptional( _gl, object, 'bindMatrix' );
  14507. p_uniforms.setOptional( _gl, object, 'bindMatrixInverse' );
  14508. var skeleton = object.skeleton;
  14509. if ( skeleton ) {
  14510. var bones = skeleton.bones;
  14511. if ( capabilities.floatVertexTextures ) {
  14512. if ( skeleton.boneTexture === undefined ) {
  14513. // layout (1 matrix = 4 pixels)
  14514. // RGBA RGBA RGBA RGBA (=> column1, column2, column3, column4)
  14515. // with 8x8 pixel texture max 16 bones * 4 pixels = (8 * 8)
  14516. // 16x16 pixel texture max 64 bones * 4 pixels = (16 * 16)
  14517. // 32x32 pixel texture max 256 bones * 4 pixels = (32 * 32)
  14518. // 64x64 pixel texture max 1024 bones * 4 pixels = (64 * 64)
  14519. var size = Math.sqrt( bones.length * 4 ); // 4 pixels needed for 1 matrix
  14520. size = _Math.ceilPowerOfTwo( size );
  14521. size = Math.max( size, 4 );
  14522. var boneMatrices = new Float32Array( size * size * 4 ); // 4 floats per RGBA pixel
  14523. boneMatrices.set( skeleton.boneMatrices ); // copy current values
  14524. var boneTexture = new DataTexture( boneMatrices, size, size, RGBAFormat, FloatType );
  14525. boneTexture.needsUpdate = true;
  14526. skeleton.boneMatrices = boneMatrices;
  14527. skeleton.boneTexture = boneTexture;
  14528. skeleton.boneTextureSize = size;
  14529. }
  14530. p_uniforms.setValue( _gl, 'boneTexture', skeleton.boneTexture, textures );
  14531. p_uniforms.setValue( _gl, 'boneTextureSize', skeleton.boneTextureSize );
  14532. } else {
  14533. p_uniforms.setOptional( _gl, skeleton, 'boneMatrices' );
  14534. }
  14535. }
  14536. }
  14537. if ( refreshMaterial ) {
  14538. p_uniforms.setValue( _gl, 'toneMappingExposure', _this.toneMappingExposure );
  14539. p_uniforms.setValue( _gl, 'toneMappingWhitePoint', _this.toneMappingWhitePoint );
  14540. if ( material.lights ) {
  14541. // the current material requires lighting info
  14542. // note: all lighting uniforms are always set correctly
  14543. // they simply reference the renderer's state for their
  14544. // values
  14545. //
  14546. // use the current material's .needsUpdate flags to set
  14547. // the GL state when required
  14548. markUniformsLightsNeedsUpdate( m_uniforms, refreshLights );
  14549. }
  14550. // refresh uniforms common to several materials
  14551. if ( fog && material.fog ) {
  14552. refreshUniformsFog( m_uniforms, fog );
  14553. }
  14554. if ( material.isMeshBasicMaterial ) {
  14555. refreshUniformsCommon( m_uniforms, material );
  14556. } else if ( material.isMeshLambertMaterial ) {
  14557. refreshUniformsCommon( m_uniforms, material );
  14558. refreshUniformsLambert( m_uniforms, material );
  14559. } else if ( material.isMeshPhongMaterial ) {
  14560. refreshUniformsCommon( m_uniforms, material );
  14561. if ( material.isMeshToonMaterial ) {
  14562. refreshUniformsToon( m_uniforms, material );
  14563. } else {
  14564. refreshUniformsPhong( m_uniforms, material );
  14565. }
  14566. } else if ( material.isMeshStandardMaterial ) {
  14567. refreshUniformsCommon( m_uniforms, material );
  14568. if ( material.isMeshPhysicalMaterial ) {
  14569. refreshUniformsPhysical( m_uniforms, material );
  14570. } else {
  14571. refreshUniformsStandard( m_uniforms, material );
  14572. }
  14573. } else if ( material.isMeshMatcapMaterial ) {
  14574. refreshUniformsCommon( m_uniforms, material );
  14575. refreshUniformsMatcap( m_uniforms, material );
  14576. } else if ( material.isMeshDepthMaterial ) {
  14577. refreshUniformsCommon( m_uniforms, material );
  14578. refreshUniformsDepth( m_uniforms, material );
  14579. } else if ( material.isMeshDistanceMaterial ) {
  14580. refreshUniformsCommon( m_uniforms, material );
  14581. refreshUniformsDistance( m_uniforms, material );
  14582. } else if ( material.isMeshNormalMaterial ) {
  14583. refreshUniformsCommon( m_uniforms, material );
  14584. refreshUniformsNormal( m_uniforms, material );
  14585. } else if ( material.isLineBasicMaterial ) {
  14586. refreshUniformsLine( m_uniforms, material );
  14587. if ( material.isLineDashedMaterial ) {
  14588. refreshUniformsDash( m_uniforms, material );
  14589. }
  14590. } else if ( material.isPointsMaterial ) {
  14591. refreshUniformsPoints( m_uniforms, material );
  14592. } else if ( material.isSpriteMaterial ) {
  14593. refreshUniformsSprites( m_uniforms, material );
  14594. } else if ( material.isShadowMaterial ) {
  14595. m_uniforms.color.value = material.color;
  14596. m_uniforms.opacity.value = material.opacity;
  14597. }
  14598. // RectAreaLight Texture
  14599. // TODO (mrdoob): Find a nicer implementation
  14600. if ( m_uniforms.ltc_1 !== undefined ) m_uniforms.ltc_1.value = UniformsLib.LTC_1;
  14601. if ( m_uniforms.ltc_2 !== undefined ) m_uniforms.ltc_2.value = UniformsLib.LTC_2;
  14602. WebGLUniforms.upload( _gl, materialProperties.uniformsList, m_uniforms, textures );
  14603. }
  14604. if ( material.isShaderMaterial && material.uniformsNeedUpdate === true ) {
  14605. WebGLUniforms.upload( _gl, materialProperties.uniformsList, m_uniforms, textures );
  14606. material.uniformsNeedUpdate = false;
  14607. }
  14608. if ( material.isSpriteMaterial ) {
  14609. p_uniforms.setValue( _gl, 'center', object.center );
  14610. }
  14611. // common matrices
  14612. p_uniforms.setValue( _gl, 'modelViewMatrix', object.modelViewMatrix );
  14613. p_uniforms.setValue( _gl, 'normalMatrix', object.normalMatrix );
  14614. p_uniforms.setValue( _gl, 'modelMatrix', object.matrixWorld );
  14615. return program;
  14616. }
  14617. // Uniforms (refresh uniforms objects)
  14618. function refreshUniformsCommon( uniforms, material ) {
  14619. uniforms.opacity.value = material.opacity;
  14620. if ( material.color ) {
  14621. uniforms.diffuse.value = material.color;
  14622. }
  14623. if ( material.emissive ) {
  14624. uniforms.emissive.value.copy( material.emissive ).multiplyScalar( material.emissiveIntensity );
  14625. }
  14626. if ( material.map ) {
  14627. uniforms.map.value = material.map;
  14628. }
  14629. if ( material.alphaMap ) {
  14630. uniforms.alphaMap.value = material.alphaMap;
  14631. }
  14632. if ( material.specularMap ) {
  14633. uniforms.specularMap.value = material.specularMap;
  14634. }
  14635. if ( material.envMap ) {
  14636. uniforms.envMap.value = material.envMap;
  14637. // don't flip CubeTexture envMaps, flip everything else:
  14638. // WebGLRenderTargetCube will be flipped for backwards compatibility
  14639. // WebGLRenderTargetCube.texture will be flipped because it's a Texture and NOT a CubeTexture
  14640. // this check must be handled differently, or removed entirely, if WebGLRenderTargetCube uses a CubeTexture in the future
  14641. uniforms.flipEnvMap.value = material.envMap.isCubeTexture ? - 1 : 1;
  14642. uniforms.reflectivity.value = material.reflectivity;
  14643. uniforms.refractionRatio.value = material.refractionRatio;
  14644. uniforms.maxMipLevel.value = properties.get( material.envMap ).__maxMipLevel;
  14645. }
  14646. if ( material.lightMap ) {
  14647. uniforms.lightMap.value = material.lightMap;
  14648. uniforms.lightMapIntensity.value = material.lightMapIntensity;
  14649. }
  14650. if ( material.aoMap ) {
  14651. uniforms.aoMap.value = material.aoMap;
  14652. uniforms.aoMapIntensity.value = material.aoMapIntensity;
  14653. }
  14654. // uv repeat and offset setting priorities
  14655. // 1. color map
  14656. // 2. specular map
  14657. // 3. normal map
  14658. // 4. bump map
  14659. // 5. alpha map
  14660. // 6. emissive map
  14661. var uvScaleMap;
  14662. if ( material.map ) {
  14663. uvScaleMap = material.map;
  14664. } else if ( material.specularMap ) {
  14665. uvScaleMap = material.specularMap;
  14666. } else if ( material.displacementMap ) {
  14667. uvScaleMap = material.displacementMap;
  14668. } else if ( material.normalMap ) {
  14669. uvScaleMap = material.normalMap;
  14670. } else if ( material.bumpMap ) {
  14671. uvScaleMap = material.bumpMap;
  14672. } else if ( material.roughnessMap ) {
  14673. uvScaleMap = material.roughnessMap;
  14674. } else if ( material.metalnessMap ) {
  14675. uvScaleMap = material.metalnessMap;
  14676. } else if ( material.alphaMap ) {
  14677. uvScaleMap = material.alphaMap;
  14678. } else if ( material.emissiveMap ) {
  14679. uvScaleMap = material.emissiveMap;
  14680. }
  14681. if ( uvScaleMap !== undefined ) {
  14682. // backwards compatibility
  14683. if ( uvScaleMap.isWebGLRenderTarget ) {
  14684. uvScaleMap = uvScaleMap.texture;
  14685. }
  14686. if ( uvScaleMap.matrixAutoUpdate === true ) {
  14687. uvScaleMap.updateMatrix();
  14688. }
  14689. uniforms.uvTransform.value.copy( uvScaleMap.matrix );
  14690. }
  14691. }
  14692. function refreshUniformsLine( uniforms, material ) {
  14693. uniforms.diffuse.value = material.color;
  14694. uniforms.opacity.value = material.opacity;
  14695. }
  14696. function refreshUniformsDash( uniforms, material ) {
  14697. uniforms.dashSize.value = material.dashSize;
  14698. uniforms.totalSize.value = material.dashSize + material.gapSize;
  14699. uniforms.scale.value = material.scale;
  14700. }
  14701. function refreshUniformsPoints( uniforms, material ) {
  14702. uniforms.diffuse.value = material.color;
  14703. uniforms.opacity.value = material.opacity;
  14704. uniforms.size.value = material.size * _pixelRatio;
  14705. uniforms.scale.value = _height * 0.5;
  14706. uniforms.map.value = material.map;
  14707. if ( material.map !== null ) {
  14708. if ( material.map.matrixAutoUpdate === true ) {
  14709. material.map.updateMatrix();
  14710. }
  14711. uniforms.uvTransform.value.copy( material.map.matrix );
  14712. }
  14713. }
  14714. function refreshUniformsSprites( uniforms, material ) {
  14715. uniforms.diffuse.value = material.color;
  14716. uniforms.opacity.value = material.opacity;
  14717. uniforms.rotation.value = material.rotation;
  14718. uniforms.map.value = material.map;
  14719. if ( material.map !== null ) {
  14720. if ( material.map.matrixAutoUpdate === true ) {
  14721. material.map.updateMatrix();
  14722. }
  14723. uniforms.uvTransform.value.copy( material.map.matrix );
  14724. }
  14725. }
  14726. function refreshUniformsFog( uniforms, fog ) {
  14727. uniforms.fogColor.value = fog.color;
  14728. if ( fog.isFog ) {
  14729. uniforms.fogNear.value = fog.near;
  14730. uniforms.fogFar.value = fog.far;
  14731. } else if ( fog.isFogExp2 ) {
  14732. uniforms.fogDensity.value = fog.density;
  14733. }
  14734. }
  14735. function refreshUniformsLambert( uniforms, material ) {
  14736. if ( material.emissiveMap ) {
  14737. uniforms.emissiveMap.value = material.emissiveMap;
  14738. }
  14739. }
  14740. function refreshUniformsPhong( uniforms, material ) {
  14741. uniforms.specular.value = material.specular;
  14742. uniforms.shininess.value = Math.max( material.shininess, 1e-4 ); // to prevent pow( 0.0, 0.0 )
  14743. if ( material.emissiveMap ) {
  14744. uniforms.emissiveMap.value = material.emissiveMap;
  14745. }
  14746. if ( material.bumpMap ) {
  14747. uniforms.bumpMap.value = material.bumpMap;
  14748. uniforms.bumpScale.value = material.bumpScale;
  14749. if ( material.side === BackSide ) uniforms.bumpScale.value *= - 1;
  14750. }
  14751. if ( material.normalMap ) {
  14752. uniforms.normalMap.value = material.normalMap;
  14753. uniforms.normalScale.value.copy( material.normalScale );
  14754. if ( material.side === BackSide ) uniforms.normalScale.value.negate();
  14755. }
  14756. if ( material.displacementMap ) {
  14757. uniforms.displacementMap.value = material.displacementMap;
  14758. uniforms.displacementScale.value = material.displacementScale;
  14759. uniforms.displacementBias.value = material.displacementBias;
  14760. }
  14761. }
  14762. function refreshUniformsToon( uniforms, material ) {
  14763. refreshUniformsPhong( uniforms, material );
  14764. if ( material.gradientMap ) {
  14765. uniforms.gradientMap.value = material.gradientMap;
  14766. }
  14767. }
  14768. function refreshUniformsStandard( uniforms, material ) {
  14769. uniforms.roughness.value = material.roughness;
  14770. uniforms.metalness.value = material.metalness;
  14771. if ( material.roughnessMap ) {
  14772. uniforms.roughnessMap.value = material.roughnessMap;
  14773. }
  14774. if ( material.metalnessMap ) {
  14775. uniforms.metalnessMap.value = material.metalnessMap;
  14776. }
  14777. if ( material.emissiveMap ) {
  14778. uniforms.emissiveMap.value = material.emissiveMap;
  14779. }
  14780. if ( material.bumpMap ) {
  14781. uniforms.bumpMap.value = material.bumpMap;
  14782. uniforms.bumpScale.value = material.bumpScale;
  14783. if ( material.side === BackSide ) uniforms.bumpScale.value *= - 1;
  14784. }
  14785. if ( material.normalMap ) {
  14786. uniforms.normalMap.value = material.normalMap;
  14787. uniforms.normalScale.value.copy( material.normalScale );
  14788. if ( material.side === BackSide ) uniforms.normalScale.value.negate();
  14789. }
  14790. if ( material.displacementMap ) {
  14791. uniforms.displacementMap.value = material.displacementMap;
  14792. uniforms.displacementScale.value = material.displacementScale;
  14793. uniforms.displacementBias.value = material.displacementBias;
  14794. }
  14795. if ( material.envMap ) {
  14796. //uniforms.envMap.value = material.envMap; // part of uniforms common
  14797. uniforms.envMapIntensity.value = material.envMapIntensity;
  14798. }
  14799. }
  14800. function refreshUniformsPhysical( uniforms, material ) {
  14801. refreshUniformsStandard( uniforms, material );
  14802. uniforms.reflectivity.value = material.reflectivity; // also part of uniforms common
  14803. uniforms.clearCoat.value = material.clearCoat;
  14804. uniforms.clearCoatRoughness.value = material.clearCoatRoughness;
  14805. }
  14806. function refreshUniformsMatcap( uniforms, material ) {
  14807. if ( material.matcap ) {
  14808. uniforms.matcap.value = material.matcap;
  14809. }
  14810. if ( material.bumpMap ) {
  14811. uniforms.bumpMap.value = material.bumpMap;
  14812. uniforms.bumpScale.value = material.bumpScale;
  14813. if ( material.side === BackSide ) uniforms.bumpScale.value *= - 1;
  14814. }
  14815. if ( material.normalMap ) {
  14816. uniforms.normalMap.value = material.normalMap;
  14817. uniforms.normalScale.value.copy( material.normalScale );
  14818. if ( material.side === BackSide ) uniforms.normalScale.value.negate();
  14819. }
  14820. if ( material.displacementMap ) {
  14821. uniforms.displacementMap.value = material.displacementMap;
  14822. uniforms.displacementScale.value = material.displacementScale;
  14823. uniforms.displacementBias.value = material.displacementBias;
  14824. }
  14825. }
  14826. function refreshUniformsDepth( uniforms, material ) {
  14827. if ( material.displacementMap ) {
  14828. uniforms.displacementMap.value = material.displacementMap;
  14829. uniforms.displacementScale.value = material.displacementScale;
  14830. uniforms.displacementBias.value = material.displacementBias;
  14831. }
  14832. }
  14833. function refreshUniformsDistance( uniforms, material ) {
  14834. if ( material.displacementMap ) {
  14835. uniforms.displacementMap.value = material.displacementMap;
  14836. uniforms.displacementScale.value = material.displacementScale;
  14837. uniforms.displacementBias.value = material.displacementBias;
  14838. }
  14839. uniforms.referencePosition.value.copy( material.referencePosition );
  14840. uniforms.nearDistance.value = material.nearDistance;
  14841. uniforms.farDistance.value = material.farDistance;
  14842. }
  14843. function refreshUniformsNormal( uniforms, material ) {
  14844. if ( material.bumpMap ) {
  14845. uniforms.bumpMap.value = material.bumpMap;
  14846. uniforms.bumpScale.value = material.bumpScale;
  14847. if ( material.side === BackSide ) uniforms.bumpScale.value *= - 1;
  14848. }
  14849. if ( material.normalMap ) {
  14850. uniforms.normalMap.value = material.normalMap;
  14851. uniforms.normalScale.value.copy( material.normalScale );
  14852. if ( material.side === BackSide ) uniforms.normalScale.value.negate();
  14853. }
  14854. if ( material.displacementMap ) {
  14855. uniforms.displacementMap.value = material.displacementMap;
  14856. uniforms.displacementScale.value = material.displacementScale;
  14857. uniforms.displacementBias.value = material.displacementBias;
  14858. }
  14859. }
  14860. // If uniforms are marked as clean, they don't need to be loaded to the GPU.
  14861. function markUniformsLightsNeedsUpdate( uniforms, value ) {
  14862. uniforms.ambientLightColor.needsUpdate = value;
  14863. uniforms.lightProbe.needsUpdate = value;
  14864. uniforms.directionalLights.needsUpdate = value;
  14865. uniforms.pointLights.needsUpdate = value;
  14866. uniforms.spotLights.needsUpdate = value;
  14867. uniforms.rectAreaLights.needsUpdate = value;
  14868. uniforms.hemisphereLights.needsUpdate = value;
  14869. }
  14870. //
  14871. this.setFramebuffer = function ( value ) {
  14872. _framebuffer = value;
  14873. };
  14874. this.getRenderTarget = function () {
  14875. return _currentRenderTarget;
  14876. };
  14877. this.setRenderTarget = function ( renderTarget, activeCubeFace, activeMipMapLevel ) {
  14878. _currentRenderTarget = renderTarget;
  14879. if ( renderTarget && properties.get( renderTarget ).__webglFramebuffer === undefined ) {
  14880. textures.setupRenderTarget( renderTarget );
  14881. }
  14882. var framebuffer = _framebuffer;
  14883. var isCube = false;
  14884. if ( renderTarget ) {
  14885. var __webglFramebuffer = properties.get( renderTarget ).__webglFramebuffer;
  14886. if ( renderTarget.isWebGLRenderTargetCube ) {
  14887. framebuffer = __webglFramebuffer[ activeCubeFace || 0 ];
  14888. isCube = true;
  14889. } else if ( renderTarget.isWebGLMultisampleRenderTarget ) {
  14890. framebuffer = properties.get( renderTarget ).__webglMultisampledFramebuffer;
  14891. } else {
  14892. framebuffer = __webglFramebuffer;
  14893. }
  14894. _currentViewport.copy( renderTarget.viewport );
  14895. _currentScissor.copy( renderTarget.scissor );
  14896. _currentScissorTest = renderTarget.scissorTest;
  14897. } else {
  14898. _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio );
  14899. _currentScissor.copy( _scissor ).multiplyScalar( _pixelRatio );
  14900. _currentScissorTest = _scissorTest;
  14901. }
  14902. if ( _currentFramebuffer !== framebuffer ) {
  14903. _gl.bindFramebuffer( 36160, framebuffer );
  14904. _currentFramebuffer = framebuffer;
  14905. }
  14906. state.viewport( _currentViewport );
  14907. state.scissor( _currentScissor );
  14908. state.setScissorTest( _currentScissorTest );
  14909. if ( isCube ) {
  14910. var textureProperties = properties.get( renderTarget.texture );
  14911. _gl.framebufferTexture2D( 36160, 36064, 34069 + ( activeCubeFace || 0 ), textureProperties.__webglTexture, activeMipMapLevel || 0 );
  14912. }
  14913. };
  14914. this.readRenderTargetPixels = function ( renderTarget, x, y, width, height, buffer ) {
  14915. if ( ! ( renderTarget && renderTarget.isWebGLRenderTarget ) ) {
  14916. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.' );
  14917. return;
  14918. }
  14919. var framebuffer = properties.get( renderTarget ).__webglFramebuffer;
  14920. if ( framebuffer ) {
  14921. var restore = false;
  14922. if ( framebuffer !== _currentFramebuffer ) {
  14923. _gl.bindFramebuffer( 36160, framebuffer );
  14924. restore = true;
  14925. }
  14926. try {
  14927. var texture = renderTarget.texture;
  14928. var textureFormat = texture.format;
  14929. var textureType = texture.type;
  14930. if ( textureFormat !== RGBAFormat && utils.convert( textureFormat ) !== _gl.getParameter( 35739 ) ) {
  14931. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA or implementation defined format.' );
  14932. return;
  14933. }
  14934. if ( textureType !== UnsignedByteType && utils.convert( textureType ) !== _gl.getParameter( 35738 ) && // IE11, Edge and Chrome Mac < 52 (#9513)
  14935. ! ( textureType === FloatType && ( capabilities.isWebGL2 || extensions.get( 'OES_texture_float' ) || extensions.get( 'WEBGL_color_buffer_float' ) ) ) && // Chrome Mac >= 52 and Firefox
  14936. ! ( textureType === HalfFloatType && ( capabilities.isWebGL2 ? extensions.get( 'EXT_color_buffer_float' ) : extensions.get( 'EXT_color_buffer_half_float' ) ) ) ) {
  14937. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in UnsignedByteType or implementation defined type.' );
  14938. return;
  14939. }
  14940. if ( _gl.checkFramebufferStatus( 36160 ) === 36053 ) {
  14941. // the following if statement ensures valid read requests (no out-of-bounds pixels, see #8604)
  14942. if ( ( x >= 0 && x <= ( renderTarget.width - width ) ) && ( y >= 0 && y <= ( renderTarget.height - height ) ) ) {
  14943. _gl.readPixels( x, y, width, height, utils.convert( textureFormat ), utils.convert( textureType ), buffer );
  14944. }
  14945. } else {
  14946. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: readPixels from renderTarget failed. Framebuffer not complete.' );
  14947. }
  14948. } finally {
  14949. if ( restore ) {
  14950. _gl.bindFramebuffer( 36160, _currentFramebuffer );
  14951. }
  14952. }
  14953. }
  14954. };
  14955. this.copyFramebufferToTexture = function ( position, texture, level ) {
  14956. var width = texture.image.width;
  14957. var height = texture.image.height;
  14958. var glFormat = utils.convert( texture.format );
  14959. textures.setTexture2D( texture, 0 );
  14960. _gl.copyTexImage2D( 3553, level || 0, glFormat, position.x, position.y, width, height, 0 );
  14961. };
  14962. this.copyTextureToTexture = function ( position, srcTexture, dstTexture, level ) {
  14963. var width = srcTexture.image.width;
  14964. var height = srcTexture.image.height;
  14965. var glFormat = utils.convert( dstTexture.format );
  14966. var glType = utils.convert( dstTexture.type );
  14967. textures.setTexture2D( dstTexture, 0 );
  14968. if ( srcTexture.isDataTexture ) {
  14969. _gl.texSubImage2D( 3553, level || 0, position.x, position.y, width, height, glFormat, glType, srcTexture.image.data );
  14970. } else {
  14971. _gl.texSubImage2D( 3553, level || 0, position.x, position.y, glFormat, glType, srcTexture.image );
  14972. }
  14973. };
  14974. }
  14975. /**
  14976. * @author mrdoob / http://mrdoob.com/
  14977. * @author alteredq / http://alteredqualia.com/
  14978. */
  14979. function FogExp2( color, density ) {
  14980. this.name = '';
  14981. this.color = new Color( color );
  14982. this.density = ( density !== undefined ) ? density : 0.00025;
  14983. }
  14984. Object.assign( FogExp2.prototype, {
  14985. isFogExp2: true,
  14986. clone: function () {
  14987. return new FogExp2( this.color, this.density );
  14988. },
  14989. toJSON: function ( /* meta */ ) {
  14990. return {
  14991. type: 'FogExp2',
  14992. color: this.color.getHex(),
  14993. density: this.density
  14994. };
  14995. }
  14996. } );
  14997. /**
  14998. * @author mrdoob / http://mrdoob.com/
  14999. * @author alteredq / http://alteredqualia.com/
  15000. */
  15001. function Fog( color, near, far ) {
  15002. this.name = '';
  15003. this.color = new Color( color );
  15004. this.near = ( near !== undefined ) ? near : 1;
  15005. this.far = ( far !== undefined ) ? far : 1000;
  15006. }
  15007. Object.assign( Fog.prototype, {
  15008. isFog: true,
  15009. clone: function () {
  15010. return new Fog( this.color, this.near, this.far );
  15011. },
  15012. toJSON: function ( /* meta */ ) {
  15013. return {
  15014. type: 'Fog',
  15015. color: this.color.getHex(),
  15016. near: this.near,
  15017. far: this.far
  15018. };
  15019. }
  15020. } );
  15021. /**
  15022. * @author mrdoob / http://mrdoob.com/
  15023. */
  15024. function Scene() {
  15025. Object3D.call( this );
  15026. this.type = 'Scene';
  15027. this.background = null;
  15028. this.fog = null;
  15029. this.overrideMaterial = null;
  15030. this.autoUpdate = true; // checked by the renderer
  15031. }
  15032. Scene.prototype = Object.assign( Object.create( Object3D.prototype ), {
  15033. constructor: Scene,
  15034. isScene: true,
  15035. copy: function ( source, recursive ) {
  15036. Object3D.prototype.copy.call( this, source, recursive );
  15037. if ( source.background !== null ) this.background = source.background.clone();
  15038. if ( source.fog !== null ) this.fog = source.fog.clone();
  15039. if ( source.overrideMaterial !== null ) this.overrideMaterial = source.overrideMaterial.clone();
  15040. this.autoUpdate = source.autoUpdate;
  15041. this.matrixAutoUpdate = source.matrixAutoUpdate;
  15042. return this;
  15043. },
  15044. toJSON: function ( meta ) {
  15045. var data = Object3D.prototype.toJSON.call( this, meta );
  15046. if ( this.background !== null ) data.object.background = this.background.toJSON( meta );
  15047. if ( this.fog !== null ) data.object.fog = this.fog.toJSON();
  15048. return data;
  15049. },
  15050. dispose: function () {
  15051. this.dispatchEvent( { type: 'dispose' } );
  15052. }
  15053. } );
  15054. /**
  15055. * @author benaadams / https://twitter.com/ben_a_adams
  15056. */
  15057. function InterleavedBuffer( array, stride ) {
  15058. this.array = array;
  15059. this.stride = stride;
  15060. this.count = array !== undefined ? array.length / stride : 0;
  15061. this.dynamic = false;
  15062. this.updateRange = { offset: 0, count: - 1 };
  15063. this.version = 0;
  15064. }
  15065. Object.defineProperty( InterleavedBuffer.prototype, 'needsUpdate', {
  15066. set: function ( value ) {
  15067. if ( value === true ) this.version ++;
  15068. }
  15069. } );
  15070. Object.assign( InterleavedBuffer.prototype, {
  15071. isInterleavedBuffer: true,
  15072. onUploadCallback: function () {},
  15073. setArray: function ( array ) {
  15074. if ( Array.isArray( array ) ) {
  15075. throw new TypeError( 'THREE.BufferAttribute: array should be a Typed Array.' );
  15076. }
  15077. this.count = array !== undefined ? array.length / this.stride : 0;
  15078. this.array = array;
  15079. return this;
  15080. },
  15081. setDynamic: function ( value ) {
  15082. this.dynamic = value;
  15083. return this;
  15084. },
  15085. copy: function ( source ) {
  15086. this.array = new source.array.constructor( source.array );
  15087. this.count = source.count;
  15088. this.stride = source.stride;
  15089. this.dynamic = source.dynamic;
  15090. return this;
  15091. },
  15092. copyAt: function ( index1, attribute, index2 ) {
  15093. index1 *= this.stride;
  15094. index2 *= attribute.stride;
  15095. for ( var i = 0, l = this.stride; i < l; i ++ ) {
  15096. this.array[ index1 + i ] = attribute.array[ index2 + i ];
  15097. }
  15098. return this;
  15099. },
  15100. set: function ( value, offset ) {
  15101. if ( offset === undefined ) offset = 0;
  15102. this.array.set( value, offset );
  15103. return this;
  15104. },
  15105. clone: function () {
  15106. return new this.constructor().copy( this );
  15107. },
  15108. onUpload: function ( callback ) {
  15109. this.onUploadCallback = callback;
  15110. return this;
  15111. }
  15112. } );
  15113. /**
  15114. * @author benaadams / https://twitter.com/ben_a_adams
  15115. */
  15116. function InterleavedBufferAttribute( interleavedBuffer, itemSize, offset, normalized ) {
  15117. this.data = interleavedBuffer;
  15118. this.itemSize = itemSize;
  15119. this.offset = offset;
  15120. this.normalized = normalized === true;
  15121. }
  15122. Object.defineProperties( InterleavedBufferAttribute.prototype, {
  15123. count: {
  15124. get: function () {
  15125. return this.data.count;
  15126. }
  15127. },
  15128. array: {
  15129. get: function () {
  15130. return this.data.array;
  15131. }
  15132. }
  15133. } );
  15134. Object.assign( InterleavedBufferAttribute.prototype, {
  15135. isInterleavedBufferAttribute: true,
  15136. setX: function ( index, x ) {
  15137. this.data.array[ index * this.data.stride + this.offset ] = x;
  15138. return this;
  15139. },
  15140. setY: function ( index, y ) {
  15141. this.data.array[ index * this.data.stride + this.offset + 1 ] = y;
  15142. return this;
  15143. },
  15144. setZ: function ( index, z ) {
  15145. this.data.array[ index * this.data.stride + this.offset + 2 ] = z;
  15146. return this;
  15147. },
  15148. setW: function ( index, w ) {
  15149. this.data.array[ index * this.data.stride + this.offset + 3 ] = w;
  15150. return this;
  15151. },
  15152. getX: function ( index ) {
  15153. return this.data.array[ index * this.data.stride + this.offset ];
  15154. },
  15155. getY: function ( index ) {
  15156. return this.data.array[ index * this.data.stride + this.offset + 1 ];
  15157. },
  15158. getZ: function ( index ) {
  15159. return this.data.array[ index * this.data.stride + this.offset + 2 ];
  15160. },
  15161. getW: function ( index ) {
  15162. return this.data.array[ index * this.data.stride + this.offset + 3 ];
  15163. },
  15164. setXY: function ( index, x, y ) {
  15165. index = index * this.data.stride + this.offset;
  15166. this.data.array[ index + 0 ] = x;
  15167. this.data.array[ index + 1 ] = y;
  15168. return this;
  15169. },
  15170. setXYZ: function ( index, x, y, z ) {
  15171. index = index * this.data.stride + this.offset;
  15172. this.data.array[ index + 0 ] = x;
  15173. this.data.array[ index + 1 ] = y;
  15174. this.data.array[ index + 2 ] = z;
  15175. return this;
  15176. },
  15177. setXYZW: function ( index, x, y, z, w ) {
  15178. index = index * this.data.stride + this.offset;
  15179. this.data.array[ index + 0 ] = x;
  15180. this.data.array[ index + 1 ] = y;
  15181. this.data.array[ index + 2 ] = z;
  15182. this.data.array[ index + 3 ] = w;
  15183. return this;
  15184. }
  15185. } );
  15186. /**
  15187. * @author alteredq / http://alteredqualia.com/
  15188. *
  15189. * parameters = {
  15190. * color: <hex>,
  15191. * map: new THREE.Texture( <Image> ),
  15192. * rotation: <float>,
  15193. * sizeAttenuation: <bool>
  15194. * }
  15195. */
  15196. function SpriteMaterial( parameters ) {
  15197. Material.call( this );
  15198. this.type = 'SpriteMaterial';
  15199. this.color = new Color( 0xffffff );
  15200. this.map = null;
  15201. this.rotation = 0;
  15202. this.sizeAttenuation = true;
  15203. this.lights = false;
  15204. this.transparent = true;
  15205. this.setValues( parameters );
  15206. }
  15207. SpriteMaterial.prototype = Object.create( Material.prototype );
  15208. SpriteMaterial.prototype.constructor = SpriteMaterial;
  15209. SpriteMaterial.prototype.isSpriteMaterial = true;
  15210. SpriteMaterial.prototype.copy = function ( source ) {
  15211. Material.prototype.copy.call( this, source );
  15212. this.color.copy( source.color );
  15213. this.map = source.map;
  15214. this.rotation = source.rotation;
  15215. this.sizeAttenuation = source.sizeAttenuation;
  15216. return this;
  15217. };
  15218. /**
  15219. * @author mikael emtinger / http://gomo.se/
  15220. * @author alteredq / http://alteredqualia.com/
  15221. */
  15222. var geometry;
  15223. function Sprite( material ) {
  15224. Object3D.call( this );
  15225. this.type = 'Sprite';
  15226. if ( geometry === undefined ) {
  15227. geometry = new BufferGeometry();
  15228. var float32Array = new Float32Array( [
  15229. - 0.5, - 0.5, 0, 0, 0,
  15230. 0.5, - 0.5, 0, 1, 0,
  15231. 0.5, 0.5, 0, 1, 1,
  15232. - 0.5, 0.5, 0, 0, 1
  15233. ] );
  15234. var interleavedBuffer = new InterleavedBuffer( float32Array, 5 );
  15235. geometry.setIndex( [ 0, 1, 2, 0, 2, 3 ] );
  15236. geometry.addAttribute( 'position', new InterleavedBufferAttribute( interleavedBuffer, 3, 0, false ) );
  15237. geometry.addAttribute( 'uv', new InterleavedBufferAttribute( interleavedBuffer, 2, 3, false ) );
  15238. }
  15239. this.geometry = geometry;
  15240. this.material = ( material !== undefined ) ? material : new SpriteMaterial();
  15241. this.center = new Vector2( 0.5, 0.5 );
  15242. }
  15243. Sprite.prototype = Object.assign( Object.create( Object3D.prototype ), {
  15244. constructor: Sprite,
  15245. isSprite: true,
  15246. raycast: ( function () {
  15247. var intersectPoint = new Vector3();
  15248. var worldScale = new Vector3();
  15249. var mvPosition = new Vector3();
  15250. var alignedPosition = new Vector2();
  15251. var rotatedPosition = new Vector2();
  15252. var viewWorldMatrix = new Matrix4();
  15253. var vA = new Vector3();
  15254. var vB = new Vector3();
  15255. var vC = new Vector3();
  15256. var uvA = new Vector2();
  15257. var uvB = new Vector2();
  15258. var uvC = new Vector2();
  15259. function transformVertex( vertexPosition, mvPosition, center, scale, sin, cos ) {
  15260. // compute position in camera space
  15261. alignedPosition.subVectors( vertexPosition, center ).addScalar( 0.5 ).multiply( scale );
  15262. // to check if rotation is not zero
  15263. if ( sin !== undefined ) {
  15264. rotatedPosition.x = ( cos * alignedPosition.x ) - ( sin * alignedPosition.y );
  15265. rotatedPosition.y = ( sin * alignedPosition.x ) + ( cos * alignedPosition.y );
  15266. } else {
  15267. rotatedPosition.copy( alignedPosition );
  15268. }
  15269. vertexPosition.copy( mvPosition );
  15270. vertexPosition.x += rotatedPosition.x;
  15271. vertexPosition.y += rotatedPosition.y;
  15272. // transform to world space
  15273. vertexPosition.applyMatrix4( viewWorldMatrix );
  15274. }
  15275. return function raycast( raycaster, intersects ) {
  15276. worldScale.setFromMatrixScale( this.matrixWorld );
  15277. viewWorldMatrix.getInverse( this.modelViewMatrix ).premultiply( this.matrixWorld );
  15278. mvPosition.setFromMatrixPosition( this.modelViewMatrix );
  15279. var rotation = this.material.rotation;
  15280. var sin, cos;
  15281. if ( rotation !== 0 ) {
  15282. cos = Math.cos( rotation );
  15283. sin = Math.sin( rotation );
  15284. }
  15285. var center = this.center;
  15286. transformVertex( vA.set( - 0.5, - 0.5, 0 ), mvPosition, center, worldScale, sin, cos );
  15287. transformVertex( vB.set( 0.5, - 0.5, 0 ), mvPosition, center, worldScale, sin, cos );
  15288. transformVertex( vC.set( 0.5, 0.5, 0 ), mvPosition, center, worldScale, sin, cos );
  15289. uvA.set( 0, 0 );
  15290. uvB.set( 1, 0 );
  15291. uvC.set( 1, 1 );
  15292. // check first triangle
  15293. var intersect = raycaster.ray.intersectTriangle( vA, vB, vC, false, intersectPoint );
  15294. if ( intersect === null ) {
  15295. // check second triangle
  15296. transformVertex( vB.set( - 0.5, 0.5, 0 ), mvPosition, center, worldScale, sin, cos );
  15297. uvB.set( 0, 1 );
  15298. intersect = raycaster.ray.intersectTriangle( vA, vC, vB, false, intersectPoint );
  15299. if ( intersect === null ) {
  15300. return;
  15301. }
  15302. }
  15303. var distance = raycaster.ray.origin.distanceTo( intersectPoint );
  15304. if ( distance < raycaster.near || distance > raycaster.far ) return;
  15305. intersects.push( {
  15306. distance: distance,
  15307. point: intersectPoint.clone(),
  15308. uv: Triangle.getUV( intersectPoint, vA, vB, vC, uvA, uvB, uvC, new Vector2() ),
  15309. face: null,
  15310. object: this
  15311. } );
  15312. };
  15313. }() ),
  15314. clone: function () {
  15315. return new this.constructor( this.material ).copy( this );
  15316. },
  15317. copy: function ( source ) {
  15318. Object3D.prototype.copy.call( this, source );
  15319. if ( source.center !== undefined ) this.center.copy( source.center );
  15320. return this;
  15321. }
  15322. } );
  15323. /**
  15324. * @author mikael emtinger / http://gomo.se/
  15325. * @author alteredq / http://alteredqualia.com/
  15326. * @author mrdoob / http://mrdoob.com/
  15327. */
  15328. function LOD() {
  15329. Object3D.call( this );
  15330. this.type = 'LOD';
  15331. Object.defineProperties( this, {
  15332. levels: {
  15333. enumerable: true,
  15334. value: []
  15335. }
  15336. } );
  15337. }
  15338. LOD.prototype = Object.assign( Object.create( Object3D.prototype ), {
  15339. constructor: LOD,
  15340. isLOD: true,
  15341. copy: function ( source ) {
  15342. Object3D.prototype.copy.call( this, source, false );
  15343. var levels = source.levels;
  15344. for ( var i = 0, l = levels.length; i < l; i ++ ) {
  15345. var level = levels[ i ];
  15346. this.addLevel( level.object.clone(), level.distance );
  15347. }
  15348. return this;
  15349. },
  15350. addLevel: function ( object, distance ) {
  15351. if ( distance === undefined ) distance = 0;
  15352. distance = Math.abs( distance );
  15353. var levels = this.levels;
  15354. for ( var l = 0; l < levels.length; l ++ ) {
  15355. if ( distance < levels[ l ].distance ) {
  15356. break;
  15357. }
  15358. }
  15359. levels.splice( l, 0, { distance: distance, object: object } );
  15360. this.add( object );
  15361. return this;
  15362. },
  15363. getObjectForDistance: function ( distance ) {
  15364. var levels = this.levels;
  15365. for ( var i = 1, l = levels.length; i < l; i ++ ) {
  15366. if ( distance < levels[ i ].distance ) {
  15367. break;
  15368. }
  15369. }
  15370. return levels[ i - 1 ].object;
  15371. },
  15372. raycast: ( function () {
  15373. var matrixPosition = new Vector3();
  15374. return function raycast( raycaster, intersects ) {
  15375. matrixPosition.setFromMatrixPosition( this.matrixWorld );
  15376. var distance = raycaster.ray.origin.distanceTo( matrixPosition );
  15377. this.getObjectForDistance( distance ).raycast( raycaster, intersects );
  15378. };
  15379. }() ),
  15380. update: function () {
  15381. var v1 = new Vector3();
  15382. var v2 = new Vector3();
  15383. return function update( camera ) {
  15384. var levels = this.levels;
  15385. if ( levels.length > 1 ) {
  15386. v1.setFromMatrixPosition( camera.matrixWorld );
  15387. v2.setFromMatrixPosition( this.matrixWorld );
  15388. var distance = v1.distanceTo( v2 );
  15389. levels[ 0 ].object.visible = true;
  15390. for ( var i = 1, l = levels.length; i < l; i ++ ) {
  15391. if ( distance >= levels[ i ].distance ) {
  15392. levels[ i - 1 ].object.visible = false;
  15393. levels[ i ].object.visible = true;
  15394. } else {
  15395. break;
  15396. }
  15397. }
  15398. for ( ; i < l; i ++ ) {
  15399. levels[ i ].object.visible = false;
  15400. }
  15401. }
  15402. };
  15403. }(),
  15404. toJSON: function ( meta ) {
  15405. var data = Object3D.prototype.toJSON.call( this, meta );
  15406. data.object.levels = [];
  15407. var levels = this.levels;
  15408. for ( var i = 0, l = levels.length; i < l; i ++ ) {
  15409. var level = levels[ i ];
  15410. data.object.levels.push( {
  15411. object: level.object.uuid,
  15412. distance: level.distance
  15413. } );
  15414. }
  15415. return data;
  15416. }
  15417. } );
  15418. /**
  15419. * @author mikael emtinger / http://gomo.se/
  15420. * @author alteredq / http://alteredqualia.com/
  15421. * @author ikerr / http://verold.com
  15422. */
  15423. function SkinnedMesh( geometry, material ) {
  15424. if ( geometry && geometry.isGeometry ) {
  15425. console.error( 'THREE.SkinnedMesh no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.' );
  15426. }
  15427. Mesh.call( this, geometry, material );
  15428. this.type = 'SkinnedMesh';
  15429. this.bindMode = 'attached';
  15430. this.bindMatrix = new Matrix4();
  15431. this.bindMatrixInverse = new Matrix4();
  15432. }
  15433. SkinnedMesh.prototype = Object.assign( Object.create( Mesh.prototype ), {
  15434. constructor: SkinnedMesh,
  15435. isSkinnedMesh: true,
  15436. bind: function ( skeleton, bindMatrix ) {
  15437. this.skeleton = skeleton;
  15438. if ( bindMatrix === undefined ) {
  15439. this.updateMatrixWorld( true );
  15440. this.skeleton.calculateInverses();
  15441. bindMatrix = this.matrixWorld;
  15442. }
  15443. this.bindMatrix.copy( bindMatrix );
  15444. this.bindMatrixInverse.getInverse( bindMatrix );
  15445. },
  15446. pose: function () {
  15447. this.skeleton.pose();
  15448. },
  15449. normalizeSkinWeights: function () {
  15450. var vector = new Vector4();
  15451. var skinWeight = this.geometry.attributes.skinWeight;
  15452. for ( var i = 0, l = skinWeight.count; i < l; i ++ ) {
  15453. vector.x = skinWeight.getX( i );
  15454. vector.y = skinWeight.getY( i );
  15455. vector.z = skinWeight.getZ( i );
  15456. vector.w = skinWeight.getW( i );
  15457. var scale = 1.0 / vector.manhattanLength();
  15458. if ( scale !== Infinity ) {
  15459. vector.multiplyScalar( scale );
  15460. } else {
  15461. vector.set( 1, 0, 0, 0 ); // do something reasonable
  15462. }
  15463. skinWeight.setXYZW( i, vector.x, vector.y, vector.z, vector.w );
  15464. }
  15465. },
  15466. updateMatrixWorld: function ( force ) {
  15467. Mesh.prototype.updateMatrixWorld.call( this, force );
  15468. if ( this.bindMode === 'attached' ) {
  15469. this.bindMatrixInverse.getInverse( this.matrixWorld );
  15470. } else if ( this.bindMode === 'detached' ) {
  15471. this.bindMatrixInverse.getInverse( this.bindMatrix );
  15472. } else {
  15473. console.warn( 'THREE.SkinnedMesh: Unrecognized bindMode: ' + this.bindMode );
  15474. }
  15475. },
  15476. clone: function () {
  15477. return new this.constructor( this.geometry, this.material ).copy( this );
  15478. }
  15479. } );
  15480. /**
  15481. * @author mikael emtinger / http://gomo.se/
  15482. * @author alteredq / http://alteredqualia.com/
  15483. * @author michael guerrero / http://realitymeltdown.com
  15484. * @author ikerr / http://verold.com
  15485. */
  15486. function Skeleton( bones, boneInverses ) {
  15487. // copy the bone array
  15488. bones = bones || [];
  15489. this.bones = bones.slice( 0 );
  15490. this.boneMatrices = new Float32Array( this.bones.length * 16 );
  15491. // use the supplied bone inverses or calculate the inverses
  15492. if ( boneInverses === undefined ) {
  15493. this.calculateInverses();
  15494. } else {
  15495. if ( this.bones.length === boneInverses.length ) {
  15496. this.boneInverses = boneInverses.slice( 0 );
  15497. } else {
  15498. console.warn( 'THREE.Skeleton boneInverses is the wrong length.' );
  15499. this.boneInverses = [];
  15500. for ( var i = 0, il = this.bones.length; i < il; i ++ ) {
  15501. this.boneInverses.push( new Matrix4() );
  15502. }
  15503. }
  15504. }
  15505. }
  15506. Object.assign( Skeleton.prototype, {
  15507. calculateInverses: function () {
  15508. this.boneInverses = [];
  15509. for ( var i = 0, il = this.bones.length; i < il; i ++ ) {
  15510. var inverse = new Matrix4();
  15511. if ( this.bones[ i ] ) {
  15512. inverse.getInverse( this.bones[ i ].matrixWorld );
  15513. }
  15514. this.boneInverses.push( inverse );
  15515. }
  15516. },
  15517. pose: function () {
  15518. var bone, i, il;
  15519. // recover the bind-time world matrices
  15520. for ( i = 0, il = this.bones.length; i < il; i ++ ) {
  15521. bone = this.bones[ i ];
  15522. if ( bone ) {
  15523. bone.matrixWorld.getInverse( this.boneInverses[ i ] );
  15524. }
  15525. }
  15526. // compute the local matrices, positions, rotations and scales
  15527. for ( i = 0, il = this.bones.length; i < il; i ++ ) {
  15528. bone = this.bones[ i ];
  15529. if ( bone ) {
  15530. if ( bone.parent && bone.parent.isBone ) {
  15531. bone.matrix.getInverse( bone.parent.matrixWorld );
  15532. bone.matrix.multiply( bone.matrixWorld );
  15533. } else {
  15534. bone.matrix.copy( bone.matrixWorld );
  15535. }
  15536. bone.matrix.decompose( bone.position, bone.quaternion, bone.scale );
  15537. }
  15538. }
  15539. },
  15540. update: ( function () {
  15541. var offsetMatrix = new Matrix4();
  15542. var identityMatrix = new Matrix4();
  15543. return function update() {
  15544. var bones = this.bones;
  15545. var boneInverses = this.boneInverses;
  15546. var boneMatrices = this.boneMatrices;
  15547. var boneTexture = this.boneTexture;
  15548. // flatten bone matrices to array
  15549. for ( var i = 0, il = bones.length; i < il; i ++ ) {
  15550. // compute the offset between the current and the original transform
  15551. var matrix = bones[ i ] ? bones[ i ].matrixWorld : identityMatrix;
  15552. offsetMatrix.multiplyMatrices( matrix, boneInverses[ i ] );
  15553. offsetMatrix.toArray( boneMatrices, i * 16 );
  15554. }
  15555. if ( boneTexture !== undefined ) {
  15556. boneTexture.needsUpdate = true;
  15557. }
  15558. };
  15559. } )(),
  15560. clone: function () {
  15561. return new Skeleton( this.bones, this.boneInverses );
  15562. },
  15563. getBoneByName: function ( name ) {
  15564. for ( var i = 0, il = this.bones.length; i < il; i ++ ) {
  15565. var bone = this.bones[ i ];
  15566. if ( bone.name === name ) {
  15567. return bone;
  15568. }
  15569. }
  15570. return undefined;
  15571. }
  15572. } );
  15573. /**
  15574. * @author mikael emtinger / http://gomo.se/
  15575. * @author alteredq / http://alteredqualia.com/
  15576. * @author ikerr / http://verold.com
  15577. */
  15578. function Bone() {
  15579. Object3D.call( this );
  15580. this.type = 'Bone';
  15581. }
  15582. Bone.prototype = Object.assign( Object.create( Object3D.prototype ), {
  15583. constructor: Bone,
  15584. isBone: true
  15585. } );
  15586. /**
  15587. * @author mrdoob / http://mrdoob.com/
  15588. * @author alteredq / http://alteredqualia.com/
  15589. *
  15590. * parameters = {
  15591. * color: <hex>,
  15592. * opacity: <float>,
  15593. *
  15594. * linewidth: <float>,
  15595. * linecap: "round",
  15596. * linejoin: "round"
  15597. * }
  15598. */
  15599. function LineBasicMaterial( parameters ) {
  15600. Material.call( this );
  15601. this.type = 'LineBasicMaterial';
  15602. this.color = new Color( 0xffffff );
  15603. this.linewidth = 1;
  15604. this.linecap = 'round';
  15605. this.linejoin = 'round';
  15606. this.lights = false;
  15607. this.setValues( parameters );
  15608. }
  15609. LineBasicMaterial.prototype = Object.create( Material.prototype );
  15610. LineBasicMaterial.prototype.constructor = LineBasicMaterial;
  15611. LineBasicMaterial.prototype.isLineBasicMaterial = true;
  15612. LineBasicMaterial.prototype.copy = function ( source ) {
  15613. Material.prototype.copy.call( this, source );
  15614. this.color.copy( source.color );
  15615. this.linewidth = source.linewidth;
  15616. this.linecap = source.linecap;
  15617. this.linejoin = source.linejoin;
  15618. return this;
  15619. };
  15620. /**
  15621. * @author mrdoob / http://mrdoob.com/
  15622. */
  15623. function Line( geometry, material, mode ) {
  15624. if ( mode === 1 ) {
  15625. console.error( 'THREE.Line: parameter THREE.LinePieces no longer supported. Use THREE.LineSegments instead.' );
  15626. }
  15627. Object3D.call( this );
  15628. this.type = 'Line';
  15629. this.geometry = geometry !== undefined ? geometry : new BufferGeometry();
  15630. this.material = material !== undefined ? material : new LineBasicMaterial( { color: Math.random() * 0xffffff } );
  15631. }
  15632. Line.prototype = Object.assign( Object.create( Object3D.prototype ), {
  15633. constructor: Line,
  15634. isLine: true,
  15635. computeLineDistances: ( function () {
  15636. var start = new Vector3();
  15637. var end = new Vector3();
  15638. return function computeLineDistances() {
  15639. var geometry = this.geometry;
  15640. if ( geometry.isBufferGeometry ) {
  15641. // we assume non-indexed geometry
  15642. if ( geometry.index === null ) {
  15643. var positionAttribute = geometry.attributes.position;
  15644. var lineDistances = [ 0 ];
  15645. for ( var i = 1, l = positionAttribute.count; i < l; i ++ ) {
  15646. start.fromBufferAttribute( positionAttribute, i - 1 );
  15647. end.fromBufferAttribute( positionAttribute, i );
  15648. lineDistances[ i ] = lineDistances[ i - 1 ];
  15649. lineDistances[ i ] += start.distanceTo( end );
  15650. }
  15651. geometry.addAttribute( 'lineDistance', new Float32BufferAttribute( lineDistances, 1 ) );
  15652. } else {
  15653. console.warn( 'THREE.Line.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.' );
  15654. }
  15655. } else if ( geometry.isGeometry ) {
  15656. var vertices = geometry.vertices;
  15657. var lineDistances = geometry.lineDistances;
  15658. lineDistances[ 0 ] = 0;
  15659. for ( var i = 1, l = vertices.length; i < l; i ++ ) {
  15660. lineDistances[ i ] = lineDistances[ i - 1 ];
  15661. lineDistances[ i ] += vertices[ i - 1 ].distanceTo( vertices[ i ] );
  15662. }
  15663. }
  15664. return this;
  15665. };
  15666. }() ),
  15667. raycast: ( function () {
  15668. var inverseMatrix = new Matrix4();
  15669. var ray = new Ray();
  15670. var sphere = new Sphere();
  15671. return function raycast( raycaster, intersects ) {
  15672. var precision = raycaster.linePrecision;
  15673. var geometry = this.geometry;
  15674. var matrixWorld = this.matrixWorld;
  15675. // Checking boundingSphere distance to ray
  15676. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  15677. sphere.copy( geometry.boundingSphere );
  15678. sphere.applyMatrix4( matrixWorld );
  15679. sphere.radius += precision;
  15680. if ( raycaster.ray.intersectsSphere( sphere ) === false ) return;
  15681. //
  15682. inverseMatrix.getInverse( matrixWorld );
  15683. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  15684. var localPrecision = precision / ( ( this.scale.x + this.scale.y + this.scale.z ) / 3 );
  15685. var localPrecisionSq = localPrecision * localPrecision;
  15686. var vStart = new Vector3();
  15687. var vEnd = new Vector3();
  15688. var interSegment = new Vector3();
  15689. var interRay = new Vector3();
  15690. var step = ( this && this.isLineSegments ) ? 2 : 1;
  15691. if ( geometry.isBufferGeometry ) {
  15692. var index = geometry.index;
  15693. var attributes = geometry.attributes;
  15694. var positions = attributes.position.array;
  15695. if ( index !== null ) {
  15696. var indices = index.array;
  15697. for ( var i = 0, l = indices.length - 1; i < l; i += step ) {
  15698. var a = indices[ i ];
  15699. var b = indices[ i + 1 ];
  15700. vStart.fromArray( positions, a * 3 );
  15701. vEnd.fromArray( positions, b * 3 );
  15702. var distSq = ray.distanceSqToSegment( vStart, vEnd, interRay, interSegment );
  15703. if ( distSq > localPrecisionSq ) continue;
  15704. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  15705. var distance = raycaster.ray.origin.distanceTo( interRay );
  15706. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  15707. intersects.push( {
  15708. distance: distance,
  15709. // What do we want? intersection point on the ray or on the segment??
  15710. // point: raycaster.ray.at( distance ),
  15711. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  15712. index: i,
  15713. face: null,
  15714. faceIndex: null,
  15715. object: this
  15716. } );
  15717. }
  15718. } else {
  15719. for ( var i = 0, l = positions.length / 3 - 1; i < l; i += step ) {
  15720. vStart.fromArray( positions, 3 * i );
  15721. vEnd.fromArray( positions, 3 * i + 3 );
  15722. var distSq = ray.distanceSqToSegment( vStart, vEnd, interRay, interSegment );
  15723. if ( distSq > localPrecisionSq ) continue;
  15724. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  15725. var distance = raycaster.ray.origin.distanceTo( interRay );
  15726. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  15727. intersects.push( {
  15728. distance: distance,
  15729. // What do we want? intersection point on the ray or on the segment??
  15730. // point: raycaster.ray.at( distance ),
  15731. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  15732. index: i,
  15733. face: null,
  15734. faceIndex: null,
  15735. object: this
  15736. } );
  15737. }
  15738. }
  15739. } else if ( geometry.isGeometry ) {
  15740. var vertices = geometry.vertices;
  15741. var nbVertices = vertices.length;
  15742. for ( var i = 0; i < nbVertices - 1; i += step ) {
  15743. var distSq = ray.distanceSqToSegment( vertices[ i ], vertices[ i + 1 ], interRay, interSegment );
  15744. if ( distSq > localPrecisionSq ) continue;
  15745. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  15746. var distance = raycaster.ray.origin.distanceTo( interRay );
  15747. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  15748. intersects.push( {
  15749. distance: distance,
  15750. // What do we want? intersection point on the ray or on the segment??
  15751. // point: raycaster.ray.at( distance ),
  15752. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  15753. index: i,
  15754. face: null,
  15755. faceIndex: null,
  15756. object: this
  15757. } );
  15758. }
  15759. }
  15760. };
  15761. }() ),
  15762. clone: function () {
  15763. return new this.constructor( this.geometry, this.material ).copy( this );
  15764. }
  15765. } );
  15766. /**
  15767. * @author mrdoob / http://mrdoob.com/
  15768. */
  15769. function LineSegments( geometry, material ) {
  15770. Line.call( this, geometry, material );
  15771. this.type = 'LineSegments';
  15772. }
  15773. LineSegments.prototype = Object.assign( Object.create( Line.prototype ), {
  15774. constructor: LineSegments,
  15775. isLineSegments: true,
  15776. computeLineDistances: ( function () {
  15777. var start = new Vector3();
  15778. var end = new Vector3();
  15779. return function computeLineDistances() {
  15780. var geometry = this.geometry;
  15781. if ( geometry.isBufferGeometry ) {
  15782. // we assume non-indexed geometry
  15783. if ( geometry.index === null ) {
  15784. var positionAttribute = geometry.attributes.position;
  15785. var lineDistances = [];
  15786. for ( var i = 0, l = positionAttribute.count; i < l; i += 2 ) {
  15787. start.fromBufferAttribute( positionAttribute, i );
  15788. end.fromBufferAttribute( positionAttribute, i + 1 );
  15789. lineDistances[ i ] = ( i === 0 ) ? 0 : lineDistances[ i - 1 ];
  15790. lineDistances[ i + 1 ] = lineDistances[ i ] + start.distanceTo( end );
  15791. }
  15792. geometry.addAttribute( 'lineDistance', new Float32BufferAttribute( lineDistances, 1 ) );
  15793. } else {
  15794. console.warn( 'THREE.LineSegments.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.' );
  15795. }
  15796. } else if ( geometry.isGeometry ) {
  15797. var vertices = geometry.vertices;
  15798. var lineDistances = geometry.lineDistances;
  15799. for ( var i = 0, l = vertices.length; i < l; i += 2 ) {
  15800. start.copy( vertices[ i ] );
  15801. end.copy( vertices[ i + 1 ] );
  15802. lineDistances[ i ] = ( i === 0 ) ? 0 : lineDistances[ i - 1 ];
  15803. lineDistances[ i + 1 ] = lineDistances[ i ] + start.distanceTo( end );
  15804. }
  15805. }
  15806. return this;
  15807. };
  15808. }() )
  15809. } );
  15810. /**
  15811. * @author mgreter / http://github.com/mgreter
  15812. */
  15813. function LineLoop( geometry, material ) {
  15814. Line.call( this, geometry, material );
  15815. this.type = 'LineLoop';
  15816. }
  15817. LineLoop.prototype = Object.assign( Object.create( Line.prototype ), {
  15818. constructor: LineLoop,
  15819. isLineLoop: true,
  15820. } );
  15821. /**
  15822. * @author mrdoob / http://mrdoob.com/
  15823. * @author alteredq / http://alteredqualia.com/
  15824. *
  15825. * parameters = {
  15826. * color: <hex>,
  15827. * opacity: <float>,
  15828. * map: new THREE.Texture( <Image> ),
  15829. *
  15830. * size: <float>,
  15831. * sizeAttenuation: <bool>
  15832. *
  15833. * morphTargets: <bool>
  15834. * }
  15835. */
  15836. function PointsMaterial( parameters ) {
  15837. Material.call( this );
  15838. this.type = 'PointsMaterial';
  15839. this.color = new Color( 0xffffff );
  15840. this.map = null;
  15841. this.size = 1;
  15842. this.sizeAttenuation = true;
  15843. this.morphTargets = false;
  15844. this.lights = false;
  15845. this.setValues( parameters );
  15846. }
  15847. PointsMaterial.prototype = Object.create( Material.prototype );
  15848. PointsMaterial.prototype.constructor = PointsMaterial;
  15849. PointsMaterial.prototype.isPointsMaterial = true;
  15850. PointsMaterial.prototype.copy = function ( source ) {
  15851. Material.prototype.copy.call( this, source );
  15852. this.color.copy( source.color );
  15853. this.map = source.map;
  15854. this.size = source.size;
  15855. this.sizeAttenuation = source.sizeAttenuation;
  15856. this.morphTargets = source.morphTargets;
  15857. return this;
  15858. };
  15859. /**
  15860. * @author alteredq / http://alteredqualia.com/
  15861. */
  15862. function Points( geometry, material ) {
  15863. Object3D.call( this );
  15864. this.type = 'Points';
  15865. this.geometry = geometry !== undefined ? geometry : new BufferGeometry();
  15866. this.material = material !== undefined ? material : new PointsMaterial( { color: Math.random() * 0xffffff } );
  15867. }
  15868. Points.prototype = Object.assign( Object.create( Object3D.prototype ), {
  15869. constructor: Points,
  15870. isPoints: true,
  15871. raycast: ( function () {
  15872. var inverseMatrix = new Matrix4();
  15873. var ray = new Ray();
  15874. var sphere = new Sphere();
  15875. return function raycast( raycaster, intersects ) {
  15876. var object = this;
  15877. var geometry = this.geometry;
  15878. var matrixWorld = this.matrixWorld;
  15879. var threshold = raycaster.params.Points.threshold;
  15880. // Checking boundingSphere distance to ray
  15881. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  15882. sphere.copy( geometry.boundingSphere );
  15883. sphere.applyMatrix4( matrixWorld );
  15884. sphere.radius += threshold;
  15885. if ( raycaster.ray.intersectsSphere( sphere ) === false ) return;
  15886. //
  15887. inverseMatrix.getInverse( matrixWorld );
  15888. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  15889. var localThreshold = threshold / ( ( this.scale.x + this.scale.y + this.scale.z ) / 3 );
  15890. var localThresholdSq = localThreshold * localThreshold;
  15891. var position = new Vector3();
  15892. var intersectPoint = new Vector3();
  15893. function testPoint( point, index ) {
  15894. var rayPointDistanceSq = ray.distanceSqToPoint( point );
  15895. if ( rayPointDistanceSq < localThresholdSq ) {
  15896. ray.closestPointToPoint( point, intersectPoint );
  15897. intersectPoint.applyMatrix4( matrixWorld );
  15898. var distance = raycaster.ray.origin.distanceTo( intersectPoint );
  15899. if ( distance < raycaster.near || distance > raycaster.far ) return;
  15900. intersects.push( {
  15901. distance: distance,
  15902. distanceToRay: Math.sqrt( rayPointDistanceSq ),
  15903. point: intersectPoint.clone(),
  15904. index: index,
  15905. face: null,
  15906. object: object
  15907. } );
  15908. }
  15909. }
  15910. if ( geometry.isBufferGeometry ) {
  15911. var index = geometry.index;
  15912. var attributes = geometry.attributes;
  15913. var positions = attributes.position.array;
  15914. if ( index !== null ) {
  15915. var indices = index.array;
  15916. for ( var i = 0, il = indices.length; i < il; i ++ ) {
  15917. var a = indices[ i ];
  15918. position.fromArray( positions, a * 3 );
  15919. testPoint( position, a );
  15920. }
  15921. } else {
  15922. for ( var i = 0, l = positions.length / 3; i < l; i ++ ) {
  15923. position.fromArray( positions, i * 3 );
  15924. testPoint( position, i );
  15925. }
  15926. }
  15927. } else {
  15928. var vertices = geometry.vertices;
  15929. for ( var i = 0, l = vertices.length; i < l; i ++ ) {
  15930. testPoint( vertices[ i ], i );
  15931. }
  15932. }
  15933. };
  15934. }() ),
  15935. clone: function () {
  15936. return new this.constructor( this.geometry, this.material ).copy( this );
  15937. }
  15938. } );
  15939. /**
  15940. * @author mrdoob / http://mrdoob.com/
  15941. */
  15942. function VideoTexture( video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  15943. Texture.call( this, video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  15944. this.format = format !== undefined ? format : RGBFormat;
  15945. this.minFilter = minFilter !== undefined ? minFilter : LinearFilter;
  15946. this.magFilter = magFilter !== undefined ? magFilter : LinearFilter;
  15947. this.generateMipmaps = false;
  15948. }
  15949. VideoTexture.prototype = Object.assign( Object.create( Texture.prototype ), {
  15950. constructor: VideoTexture,
  15951. isVideoTexture: true,
  15952. update: function () {
  15953. var video = this.image;
  15954. if ( video.readyState >= video.HAVE_CURRENT_DATA ) {
  15955. this.needsUpdate = true;
  15956. }
  15957. }
  15958. } );
  15959. /**
  15960. * @author alteredq / http://alteredqualia.com/
  15961. */
  15962. function CompressedTexture( mipmaps, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, encoding ) {
  15963. Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding );
  15964. this.image = { width: width, height: height };
  15965. this.mipmaps = mipmaps;
  15966. // no flipping for cube textures
  15967. // (also flipping doesn't work for compressed textures )
  15968. this.flipY = false;
  15969. // can't generate mipmaps for compressed textures
  15970. // mips must be embedded in DDS files
  15971. this.generateMipmaps = false;
  15972. }
  15973. CompressedTexture.prototype = Object.create( Texture.prototype );
  15974. CompressedTexture.prototype.constructor = CompressedTexture;
  15975. CompressedTexture.prototype.isCompressedTexture = true;
  15976. /**
  15977. * @author mrdoob / http://mrdoob.com/
  15978. */
  15979. function CanvasTexture( canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  15980. Texture.call( this, canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  15981. this.needsUpdate = true;
  15982. }
  15983. CanvasTexture.prototype = Object.create( Texture.prototype );
  15984. CanvasTexture.prototype.constructor = CanvasTexture;
  15985. CanvasTexture.prototype.isCanvasTexture = true;
  15986. /**
  15987. * @author Matt DesLauriers / @mattdesl
  15988. * @author atix / arthursilber.de
  15989. */
  15990. function DepthTexture( width, height, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, format ) {
  15991. format = format !== undefined ? format : DepthFormat;
  15992. if ( format !== DepthFormat && format !== DepthStencilFormat ) {
  15993. throw new Error( 'DepthTexture format must be either THREE.DepthFormat or THREE.DepthStencilFormat' );
  15994. }
  15995. if ( type === undefined && format === DepthFormat ) type = UnsignedShortType;
  15996. if ( type === undefined && format === DepthStencilFormat ) type = UnsignedInt248Type;
  15997. Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  15998. this.image = { width: width, height: height };
  15999. this.magFilter = magFilter !== undefined ? magFilter : NearestFilter;
  16000. this.minFilter = minFilter !== undefined ? minFilter : NearestFilter;
  16001. this.flipY = false;
  16002. this.generateMipmaps = false;
  16003. }
  16004. DepthTexture.prototype = Object.create( Texture.prototype );
  16005. DepthTexture.prototype.constructor = DepthTexture;
  16006. DepthTexture.prototype.isDepthTexture = true;
  16007. /**
  16008. * @author mrdoob / http://mrdoob.com/
  16009. * @author Mugen87 / https://github.com/Mugen87
  16010. */
  16011. function WireframeGeometry( geometry ) {
  16012. BufferGeometry.call( this );
  16013. this.type = 'WireframeGeometry';
  16014. // buffer
  16015. var vertices = [];
  16016. // helper variables
  16017. var i, j, l, o, ol;
  16018. var edge = [ 0, 0 ], edges = {}, e, edge1, edge2;
  16019. var key, keys = [ 'a', 'b', 'c' ];
  16020. var vertex;
  16021. // different logic for Geometry and BufferGeometry
  16022. if ( geometry && geometry.isGeometry ) {
  16023. // create a data structure that contains all edges without duplicates
  16024. var faces = geometry.faces;
  16025. for ( i = 0, l = faces.length; i < l; i ++ ) {
  16026. var face = faces[ i ];
  16027. for ( j = 0; j < 3; j ++ ) {
  16028. edge1 = face[ keys[ j ] ];
  16029. edge2 = face[ keys[ ( j + 1 ) % 3 ] ];
  16030. edge[ 0 ] = Math.min( edge1, edge2 ); // sorting prevents duplicates
  16031. edge[ 1 ] = Math.max( edge1, edge2 );
  16032. key = edge[ 0 ] + ',' + edge[ 1 ];
  16033. if ( edges[ key ] === undefined ) {
  16034. edges[ key ] = { index1: edge[ 0 ], index2: edge[ 1 ] };
  16035. }
  16036. }
  16037. }
  16038. // generate vertices
  16039. for ( key in edges ) {
  16040. e = edges[ key ];
  16041. vertex = geometry.vertices[ e.index1 ];
  16042. vertices.push( vertex.x, vertex.y, vertex.z );
  16043. vertex = geometry.vertices[ e.index2 ];
  16044. vertices.push( vertex.x, vertex.y, vertex.z );
  16045. }
  16046. } else if ( geometry && geometry.isBufferGeometry ) {
  16047. var position, indices, groups;
  16048. var group, start, count;
  16049. var index1, index2;
  16050. vertex = new Vector3();
  16051. if ( geometry.index !== null ) {
  16052. // indexed BufferGeometry
  16053. position = geometry.attributes.position;
  16054. indices = geometry.index;
  16055. groups = geometry.groups;
  16056. if ( groups.length === 0 ) {
  16057. groups = [ { start: 0, count: indices.count, materialIndex: 0 } ];
  16058. }
  16059. // create a data structure that contains all eges without duplicates
  16060. for ( o = 0, ol = groups.length; o < ol; ++ o ) {
  16061. group = groups[ o ];
  16062. start = group.start;
  16063. count = group.count;
  16064. for ( i = start, l = ( start + count ); i < l; i += 3 ) {
  16065. for ( j = 0; j < 3; j ++ ) {
  16066. edge1 = indices.getX( i + j );
  16067. edge2 = indices.getX( i + ( j + 1 ) % 3 );
  16068. edge[ 0 ] = Math.min( edge1, edge2 ); // sorting prevents duplicates
  16069. edge[ 1 ] = Math.max( edge1, edge2 );
  16070. key = edge[ 0 ] + ',' + edge[ 1 ];
  16071. if ( edges[ key ] === undefined ) {
  16072. edges[ key ] = { index1: edge[ 0 ], index2: edge[ 1 ] };
  16073. }
  16074. }
  16075. }
  16076. }
  16077. // generate vertices
  16078. for ( key in edges ) {
  16079. e = edges[ key ];
  16080. vertex.fromBufferAttribute( position, e.index1 );
  16081. vertices.push( vertex.x, vertex.y, vertex.z );
  16082. vertex.fromBufferAttribute( position, e.index2 );
  16083. vertices.push( vertex.x, vertex.y, vertex.z );
  16084. }
  16085. } else {
  16086. // non-indexed BufferGeometry
  16087. position = geometry.attributes.position;
  16088. for ( i = 0, l = ( position.count / 3 ); i < l; i ++ ) {
  16089. for ( j = 0; j < 3; j ++ ) {
  16090. // three edges per triangle, an edge is represented as (index1, index2)
  16091. // e.g. the first triangle has the following edges: (0,1),(1,2),(2,0)
  16092. index1 = 3 * i + j;
  16093. vertex.fromBufferAttribute( position, index1 );
  16094. vertices.push( vertex.x, vertex.y, vertex.z );
  16095. index2 = 3 * i + ( ( j + 1 ) % 3 );
  16096. vertex.fromBufferAttribute( position, index2 );
  16097. vertices.push( vertex.x, vertex.y, vertex.z );
  16098. }
  16099. }
  16100. }
  16101. }
  16102. // build geometry
  16103. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  16104. }
  16105. WireframeGeometry.prototype = Object.create( BufferGeometry.prototype );
  16106. WireframeGeometry.prototype.constructor = WireframeGeometry;
  16107. /**
  16108. * @author zz85 / https://github.com/zz85
  16109. * @author Mugen87 / https://github.com/Mugen87
  16110. *
  16111. * Parametric Surfaces Geometry
  16112. * based on the brilliant article by @prideout http://prideout.net/blog/?p=44
  16113. */
  16114. // ParametricGeometry
  16115. function ParametricGeometry( func, slices, stacks ) {
  16116. Geometry.call( this );
  16117. this.type = 'ParametricGeometry';
  16118. this.parameters = {
  16119. func: func,
  16120. slices: slices,
  16121. stacks: stacks
  16122. };
  16123. this.fromBufferGeometry( new ParametricBufferGeometry( func, slices, stacks ) );
  16124. this.mergeVertices();
  16125. }
  16126. ParametricGeometry.prototype = Object.create( Geometry.prototype );
  16127. ParametricGeometry.prototype.constructor = ParametricGeometry;
  16128. // ParametricBufferGeometry
  16129. function ParametricBufferGeometry( func, slices, stacks ) {
  16130. BufferGeometry.call( this );
  16131. this.type = 'ParametricBufferGeometry';
  16132. this.parameters = {
  16133. func: func,
  16134. slices: slices,
  16135. stacks: stacks
  16136. };
  16137. // buffers
  16138. var indices = [];
  16139. var vertices = [];
  16140. var normals = [];
  16141. var uvs = [];
  16142. var EPS = 0.00001;
  16143. var normal = new Vector3();
  16144. var p0 = new Vector3(), p1 = new Vector3();
  16145. var pu = new Vector3(), pv = new Vector3();
  16146. var i, j;
  16147. if ( func.length < 3 ) {
  16148. console.error( 'THREE.ParametricGeometry: Function must now modify a Vector3 as third parameter.' );
  16149. }
  16150. // generate vertices, normals and uvs
  16151. var sliceCount = slices + 1;
  16152. for ( i = 0; i <= stacks; i ++ ) {
  16153. var v = i / stacks;
  16154. for ( j = 0; j <= slices; j ++ ) {
  16155. var u = j / slices;
  16156. // vertex
  16157. func( u, v, p0 );
  16158. vertices.push( p0.x, p0.y, p0.z );
  16159. // normal
  16160. // approximate tangent vectors via finite differences
  16161. if ( u - EPS >= 0 ) {
  16162. func( u - EPS, v, p1 );
  16163. pu.subVectors( p0, p1 );
  16164. } else {
  16165. func( u + EPS, v, p1 );
  16166. pu.subVectors( p1, p0 );
  16167. }
  16168. if ( v - EPS >= 0 ) {
  16169. func( u, v - EPS, p1 );
  16170. pv.subVectors( p0, p1 );
  16171. } else {
  16172. func( u, v + EPS, p1 );
  16173. pv.subVectors( p1, p0 );
  16174. }
  16175. // cross product of tangent vectors returns surface normal
  16176. normal.crossVectors( pu, pv ).normalize();
  16177. normals.push( normal.x, normal.y, normal.z );
  16178. // uv
  16179. uvs.push( u, v );
  16180. }
  16181. }
  16182. // generate indices
  16183. for ( i = 0; i < stacks; i ++ ) {
  16184. for ( j = 0; j < slices; j ++ ) {
  16185. var a = i * sliceCount + j;
  16186. var b = i * sliceCount + j + 1;
  16187. var c = ( i + 1 ) * sliceCount + j + 1;
  16188. var d = ( i + 1 ) * sliceCount + j;
  16189. // faces one and two
  16190. indices.push( a, b, d );
  16191. indices.push( b, c, d );
  16192. }
  16193. }
  16194. // build geometry
  16195. this.setIndex( indices );
  16196. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  16197. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  16198. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  16199. }
  16200. ParametricBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  16201. ParametricBufferGeometry.prototype.constructor = ParametricBufferGeometry;
  16202. /**
  16203. * @author clockworkgeek / https://github.com/clockworkgeek
  16204. * @author timothypratley / https://github.com/timothypratley
  16205. * @author WestLangley / http://github.com/WestLangley
  16206. * @author Mugen87 / https://github.com/Mugen87
  16207. */
  16208. // PolyhedronGeometry
  16209. function PolyhedronGeometry( vertices, indices, radius, detail ) {
  16210. Geometry.call( this );
  16211. this.type = 'PolyhedronGeometry';
  16212. this.parameters = {
  16213. vertices: vertices,
  16214. indices: indices,
  16215. radius: radius,
  16216. detail: detail
  16217. };
  16218. this.fromBufferGeometry( new PolyhedronBufferGeometry( vertices, indices, radius, detail ) );
  16219. this.mergeVertices();
  16220. }
  16221. PolyhedronGeometry.prototype = Object.create( Geometry.prototype );
  16222. PolyhedronGeometry.prototype.constructor = PolyhedronGeometry;
  16223. // PolyhedronBufferGeometry
  16224. function PolyhedronBufferGeometry( vertices, indices, radius, detail ) {
  16225. BufferGeometry.call( this );
  16226. this.type = 'PolyhedronBufferGeometry';
  16227. this.parameters = {
  16228. vertices: vertices,
  16229. indices: indices,
  16230. radius: radius,
  16231. detail: detail
  16232. };
  16233. radius = radius || 1;
  16234. detail = detail || 0;
  16235. // default buffer data
  16236. var vertexBuffer = [];
  16237. var uvBuffer = [];
  16238. // the subdivision creates the vertex buffer data
  16239. subdivide( detail );
  16240. // all vertices should lie on a conceptual sphere with a given radius
  16241. appplyRadius( radius );
  16242. // finally, create the uv data
  16243. generateUVs();
  16244. // build non-indexed geometry
  16245. this.addAttribute( 'position', new Float32BufferAttribute( vertexBuffer, 3 ) );
  16246. this.addAttribute( 'normal', new Float32BufferAttribute( vertexBuffer.slice(), 3 ) );
  16247. this.addAttribute( 'uv', new Float32BufferAttribute( uvBuffer, 2 ) );
  16248. if ( detail === 0 ) {
  16249. this.computeVertexNormals(); // flat normals
  16250. } else {
  16251. this.normalizeNormals(); // smooth normals
  16252. }
  16253. // helper functions
  16254. function subdivide( detail ) {
  16255. var a = new Vector3();
  16256. var b = new Vector3();
  16257. var c = new Vector3();
  16258. // iterate over all faces and apply a subdivison with the given detail value
  16259. for ( var i = 0; i < indices.length; i += 3 ) {
  16260. // get the vertices of the face
  16261. getVertexByIndex( indices[ i + 0 ], a );
  16262. getVertexByIndex( indices[ i + 1 ], b );
  16263. getVertexByIndex( indices[ i + 2 ], c );
  16264. // perform subdivision
  16265. subdivideFace( a, b, c, detail );
  16266. }
  16267. }
  16268. function subdivideFace( a, b, c, detail ) {
  16269. var cols = Math.pow( 2, detail );
  16270. // we use this multidimensional array as a data structure for creating the subdivision
  16271. var v = [];
  16272. var i, j;
  16273. // construct all of the vertices for this subdivision
  16274. for ( i = 0; i <= cols; i ++ ) {
  16275. v[ i ] = [];
  16276. var aj = a.clone().lerp( c, i / cols );
  16277. var bj = b.clone().lerp( c, i / cols );
  16278. var rows = cols - i;
  16279. for ( j = 0; j <= rows; j ++ ) {
  16280. if ( j === 0 && i === cols ) {
  16281. v[ i ][ j ] = aj;
  16282. } else {
  16283. v[ i ][ j ] = aj.clone().lerp( bj, j / rows );
  16284. }
  16285. }
  16286. }
  16287. // construct all of the faces
  16288. for ( i = 0; i < cols; i ++ ) {
  16289. for ( j = 0; j < 2 * ( cols - i ) - 1; j ++ ) {
  16290. var k = Math.floor( j / 2 );
  16291. if ( j % 2 === 0 ) {
  16292. pushVertex( v[ i ][ k + 1 ] );
  16293. pushVertex( v[ i + 1 ][ k ] );
  16294. pushVertex( v[ i ][ k ] );
  16295. } else {
  16296. pushVertex( v[ i ][ k + 1 ] );
  16297. pushVertex( v[ i + 1 ][ k + 1 ] );
  16298. pushVertex( v[ i + 1 ][ k ] );
  16299. }
  16300. }
  16301. }
  16302. }
  16303. function appplyRadius( radius ) {
  16304. var vertex = new Vector3();
  16305. // iterate over the entire buffer and apply the radius to each vertex
  16306. for ( var i = 0; i < vertexBuffer.length; i += 3 ) {
  16307. vertex.x = vertexBuffer[ i + 0 ];
  16308. vertex.y = vertexBuffer[ i + 1 ];
  16309. vertex.z = vertexBuffer[ i + 2 ];
  16310. vertex.normalize().multiplyScalar( radius );
  16311. vertexBuffer[ i + 0 ] = vertex.x;
  16312. vertexBuffer[ i + 1 ] = vertex.y;
  16313. vertexBuffer[ i + 2 ] = vertex.z;
  16314. }
  16315. }
  16316. function generateUVs() {
  16317. var vertex = new Vector3();
  16318. for ( var i = 0; i < vertexBuffer.length; i += 3 ) {
  16319. vertex.x = vertexBuffer[ i + 0 ];
  16320. vertex.y = vertexBuffer[ i + 1 ];
  16321. vertex.z = vertexBuffer[ i + 2 ];
  16322. var u = azimuth( vertex ) / 2 / Math.PI + 0.5;
  16323. var v = inclination( vertex ) / Math.PI + 0.5;
  16324. uvBuffer.push( u, 1 - v );
  16325. }
  16326. correctUVs();
  16327. correctSeam();
  16328. }
  16329. function correctSeam() {
  16330. // handle case when face straddles the seam, see #3269
  16331. for ( var i = 0; i < uvBuffer.length; i += 6 ) {
  16332. // uv data of a single face
  16333. var x0 = uvBuffer[ i + 0 ];
  16334. var x1 = uvBuffer[ i + 2 ];
  16335. var x2 = uvBuffer[ i + 4 ];
  16336. var max = Math.max( x0, x1, x2 );
  16337. var min = Math.min( x0, x1, x2 );
  16338. // 0.9 is somewhat arbitrary
  16339. if ( max > 0.9 && min < 0.1 ) {
  16340. if ( x0 < 0.2 ) uvBuffer[ i + 0 ] += 1;
  16341. if ( x1 < 0.2 ) uvBuffer[ i + 2 ] += 1;
  16342. if ( x2 < 0.2 ) uvBuffer[ i + 4 ] += 1;
  16343. }
  16344. }
  16345. }
  16346. function pushVertex( vertex ) {
  16347. vertexBuffer.push( vertex.x, vertex.y, vertex.z );
  16348. }
  16349. function getVertexByIndex( index, vertex ) {
  16350. var stride = index * 3;
  16351. vertex.x = vertices[ stride + 0 ];
  16352. vertex.y = vertices[ stride + 1 ];
  16353. vertex.z = vertices[ stride + 2 ];
  16354. }
  16355. function correctUVs() {
  16356. var a = new Vector3();
  16357. var b = new Vector3();
  16358. var c = new Vector3();
  16359. var centroid = new Vector3();
  16360. var uvA = new Vector2();
  16361. var uvB = new Vector2();
  16362. var uvC = new Vector2();
  16363. for ( var i = 0, j = 0; i < vertexBuffer.length; i += 9, j += 6 ) {
  16364. a.set( vertexBuffer[ i + 0 ], vertexBuffer[ i + 1 ], vertexBuffer[ i + 2 ] );
  16365. b.set( vertexBuffer[ i + 3 ], vertexBuffer[ i + 4 ], vertexBuffer[ i + 5 ] );
  16366. c.set( vertexBuffer[ i + 6 ], vertexBuffer[ i + 7 ], vertexBuffer[ i + 8 ] );
  16367. uvA.set( uvBuffer[ j + 0 ], uvBuffer[ j + 1 ] );
  16368. uvB.set( uvBuffer[ j + 2 ], uvBuffer[ j + 3 ] );
  16369. uvC.set( uvBuffer[ j + 4 ], uvBuffer[ j + 5 ] );
  16370. centroid.copy( a ).add( b ).add( c ).divideScalar( 3 );
  16371. var azi = azimuth( centroid );
  16372. correctUV( uvA, j + 0, a, azi );
  16373. correctUV( uvB, j + 2, b, azi );
  16374. correctUV( uvC, j + 4, c, azi );
  16375. }
  16376. }
  16377. function correctUV( uv, stride, vector, azimuth ) {
  16378. if ( ( azimuth < 0 ) && ( uv.x === 1 ) ) {
  16379. uvBuffer[ stride ] = uv.x - 1;
  16380. }
  16381. if ( ( vector.x === 0 ) && ( vector.z === 0 ) ) {
  16382. uvBuffer[ stride ] = azimuth / 2 / Math.PI + 0.5;
  16383. }
  16384. }
  16385. // Angle around the Y axis, counter-clockwise when looking from above.
  16386. function azimuth( vector ) {
  16387. return Math.atan2( vector.z, - vector.x );
  16388. }
  16389. // Angle above the XZ plane.
  16390. function inclination( vector ) {
  16391. return Math.atan2( - vector.y, Math.sqrt( ( vector.x * vector.x ) + ( vector.z * vector.z ) ) );
  16392. }
  16393. }
  16394. PolyhedronBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  16395. PolyhedronBufferGeometry.prototype.constructor = PolyhedronBufferGeometry;
  16396. /**
  16397. * @author timothypratley / https://github.com/timothypratley
  16398. * @author Mugen87 / https://github.com/Mugen87
  16399. */
  16400. // TetrahedronGeometry
  16401. function TetrahedronGeometry( radius, detail ) {
  16402. Geometry.call( this );
  16403. this.type = 'TetrahedronGeometry';
  16404. this.parameters = {
  16405. radius: radius,
  16406. detail: detail
  16407. };
  16408. this.fromBufferGeometry( new TetrahedronBufferGeometry( radius, detail ) );
  16409. this.mergeVertices();
  16410. }
  16411. TetrahedronGeometry.prototype = Object.create( Geometry.prototype );
  16412. TetrahedronGeometry.prototype.constructor = TetrahedronGeometry;
  16413. // TetrahedronBufferGeometry
  16414. function TetrahedronBufferGeometry( radius, detail ) {
  16415. var vertices = [
  16416. 1, 1, 1, - 1, - 1, 1, - 1, 1, - 1, 1, - 1, - 1
  16417. ];
  16418. var indices = [
  16419. 2, 1, 0, 0, 3, 2, 1, 3, 0, 2, 3, 1
  16420. ];
  16421. PolyhedronBufferGeometry.call( this, vertices, indices, radius, detail );
  16422. this.type = 'TetrahedronBufferGeometry';
  16423. this.parameters = {
  16424. radius: radius,
  16425. detail: detail
  16426. };
  16427. }
  16428. TetrahedronBufferGeometry.prototype = Object.create( PolyhedronBufferGeometry.prototype );
  16429. TetrahedronBufferGeometry.prototype.constructor = TetrahedronBufferGeometry;
  16430. /**
  16431. * @author timothypratley / https://github.com/timothypratley
  16432. * @author Mugen87 / https://github.com/Mugen87
  16433. */
  16434. // OctahedronGeometry
  16435. function OctahedronGeometry( radius, detail ) {
  16436. Geometry.call( this );
  16437. this.type = 'OctahedronGeometry';
  16438. this.parameters = {
  16439. radius: radius,
  16440. detail: detail
  16441. };
  16442. this.fromBufferGeometry( new OctahedronBufferGeometry( radius, detail ) );
  16443. this.mergeVertices();
  16444. }
  16445. OctahedronGeometry.prototype = Object.create( Geometry.prototype );
  16446. OctahedronGeometry.prototype.constructor = OctahedronGeometry;
  16447. // OctahedronBufferGeometry
  16448. function OctahedronBufferGeometry( radius, detail ) {
  16449. var vertices = [
  16450. 1, 0, 0, - 1, 0, 0, 0, 1, 0,
  16451. 0, - 1, 0, 0, 0, 1, 0, 0, - 1
  16452. ];
  16453. var indices = [
  16454. 0, 2, 4, 0, 4, 3, 0, 3, 5,
  16455. 0, 5, 2, 1, 2, 5, 1, 5, 3,
  16456. 1, 3, 4, 1, 4, 2
  16457. ];
  16458. PolyhedronBufferGeometry.call( this, vertices, indices, radius, detail );
  16459. this.type = 'OctahedronBufferGeometry';
  16460. this.parameters = {
  16461. radius: radius,
  16462. detail: detail
  16463. };
  16464. }
  16465. OctahedronBufferGeometry.prototype = Object.create( PolyhedronBufferGeometry.prototype );
  16466. OctahedronBufferGeometry.prototype.constructor = OctahedronBufferGeometry;
  16467. /**
  16468. * @author timothypratley / https://github.com/timothypratley
  16469. * @author Mugen87 / https://github.com/Mugen87
  16470. */
  16471. // IcosahedronGeometry
  16472. function IcosahedronGeometry( radius, detail ) {
  16473. Geometry.call( this );
  16474. this.type = 'IcosahedronGeometry';
  16475. this.parameters = {
  16476. radius: radius,
  16477. detail: detail
  16478. };
  16479. this.fromBufferGeometry( new IcosahedronBufferGeometry( radius, detail ) );
  16480. this.mergeVertices();
  16481. }
  16482. IcosahedronGeometry.prototype = Object.create( Geometry.prototype );
  16483. IcosahedronGeometry.prototype.constructor = IcosahedronGeometry;
  16484. // IcosahedronBufferGeometry
  16485. function IcosahedronBufferGeometry( radius, detail ) {
  16486. var t = ( 1 + Math.sqrt( 5 ) ) / 2;
  16487. var vertices = [
  16488. - 1, t, 0, 1, t, 0, - 1, - t, 0, 1, - t, 0,
  16489. 0, - 1, t, 0, 1, t, 0, - 1, - t, 0, 1, - t,
  16490. t, 0, - 1, t, 0, 1, - t, 0, - 1, - t, 0, 1
  16491. ];
  16492. var indices = [
  16493. 0, 11, 5, 0, 5, 1, 0, 1, 7, 0, 7, 10, 0, 10, 11,
  16494. 1, 5, 9, 5, 11, 4, 11, 10, 2, 10, 7, 6, 7, 1, 8,
  16495. 3, 9, 4, 3, 4, 2, 3, 2, 6, 3, 6, 8, 3, 8, 9,
  16496. 4, 9, 5, 2, 4, 11, 6, 2, 10, 8, 6, 7, 9, 8, 1
  16497. ];
  16498. PolyhedronBufferGeometry.call( this, vertices, indices, radius, detail );
  16499. this.type = 'IcosahedronBufferGeometry';
  16500. this.parameters = {
  16501. radius: radius,
  16502. detail: detail
  16503. };
  16504. }
  16505. IcosahedronBufferGeometry.prototype = Object.create( PolyhedronBufferGeometry.prototype );
  16506. IcosahedronBufferGeometry.prototype.constructor = IcosahedronBufferGeometry;
  16507. /**
  16508. * @author Abe Pazos / https://hamoid.com
  16509. * @author Mugen87 / https://github.com/Mugen87
  16510. */
  16511. // DodecahedronGeometry
  16512. function DodecahedronGeometry( radius, detail ) {
  16513. Geometry.call( this );
  16514. this.type = 'DodecahedronGeometry';
  16515. this.parameters = {
  16516. radius: radius,
  16517. detail: detail
  16518. };
  16519. this.fromBufferGeometry( new DodecahedronBufferGeometry( radius, detail ) );
  16520. this.mergeVertices();
  16521. }
  16522. DodecahedronGeometry.prototype = Object.create( Geometry.prototype );
  16523. DodecahedronGeometry.prototype.constructor = DodecahedronGeometry;
  16524. // DodecahedronBufferGeometry
  16525. function DodecahedronBufferGeometry( radius, detail ) {
  16526. var t = ( 1 + Math.sqrt( 5 ) ) / 2;
  16527. var r = 1 / t;
  16528. var vertices = [
  16529. // (±1, ±1, ±1)
  16530. - 1, - 1, - 1, - 1, - 1, 1,
  16531. - 1, 1, - 1, - 1, 1, 1,
  16532. 1, - 1, - 1, 1, - 1, 1,
  16533. 1, 1, - 1, 1, 1, 1,
  16534. // (0, ±1/φ, ±φ)
  16535. 0, - r, - t, 0, - r, t,
  16536. 0, r, - t, 0, r, t,
  16537. // (±1/φ, ±φ, 0)
  16538. - r, - t, 0, - r, t, 0,
  16539. r, - t, 0, r, t, 0,
  16540. // (±φ, 0, ±1/φ)
  16541. - t, 0, - r, t, 0, - r,
  16542. - t, 0, r, t, 0, r
  16543. ];
  16544. var indices = [
  16545. 3, 11, 7, 3, 7, 15, 3, 15, 13,
  16546. 7, 19, 17, 7, 17, 6, 7, 6, 15,
  16547. 17, 4, 8, 17, 8, 10, 17, 10, 6,
  16548. 8, 0, 16, 8, 16, 2, 8, 2, 10,
  16549. 0, 12, 1, 0, 1, 18, 0, 18, 16,
  16550. 6, 10, 2, 6, 2, 13, 6, 13, 15,
  16551. 2, 16, 18, 2, 18, 3, 2, 3, 13,
  16552. 18, 1, 9, 18, 9, 11, 18, 11, 3,
  16553. 4, 14, 12, 4, 12, 0, 4, 0, 8,
  16554. 11, 9, 5, 11, 5, 19, 11, 19, 7,
  16555. 19, 5, 14, 19, 14, 4, 19, 4, 17,
  16556. 1, 12, 14, 1, 14, 5, 1, 5, 9
  16557. ];
  16558. PolyhedronBufferGeometry.call( this, vertices, indices, radius, detail );
  16559. this.type = 'DodecahedronBufferGeometry';
  16560. this.parameters = {
  16561. radius: radius,
  16562. detail: detail
  16563. };
  16564. }
  16565. DodecahedronBufferGeometry.prototype = Object.create( PolyhedronBufferGeometry.prototype );
  16566. DodecahedronBufferGeometry.prototype.constructor = DodecahedronBufferGeometry;
  16567. /**
  16568. * @author oosmoxiecode / https://github.com/oosmoxiecode
  16569. * @author WestLangley / https://github.com/WestLangley
  16570. * @author zz85 / https://github.com/zz85
  16571. * @author miningold / https://github.com/miningold
  16572. * @author jonobr1 / https://github.com/jonobr1
  16573. * @author Mugen87 / https://github.com/Mugen87
  16574. *
  16575. */
  16576. // TubeGeometry
  16577. function TubeGeometry( path, tubularSegments, radius, radialSegments, closed, taper ) {
  16578. Geometry.call( this );
  16579. this.type = 'TubeGeometry';
  16580. this.parameters = {
  16581. path: path,
  16582. tubularSegments: tubularSegments,
  16583. radius: radius,
  16584. radialSegments: radialSegments,
  16585. closed: closed
  16586. };
  16587. if ( taper !== undefined ) console.warn( 'THREE.TubeGeometry: taper has been removed.' );
  16588. var bufferGeometry = new TubeBufferGeometry( path, tubularSegments, radius, radialSegments, closed );
  16589. // expose internals
  16590. this.tangents = bufferGeometry.tangents;
  16591. this.normals = bufferGeometry.normals;
  16592. this.binormals = bufferGeometry.binormals;
  16593. // create geometry
  16594. this.fromBufferGeometry( bufferGeometry );
  16595. this.mergeVertices();
  16596. }
  16597. TubeGeometry.prototype = Object.create( Geometry.prototype );
  16598. TubeGeometry.prototype.constructor = TubeGeometry;
  16599. // TubeBufferGeometry
  16600. function TubeBufferGeometry( path, tubularSegments, radius, radialSegments, closed ) {
  16601. BufferGeometry.call( this );
  16602. this.type = 'TubeBufferGeometry';
  16603. this.parameters = {
  16604. path: path,
  16605. tubularSegments: tubularSegments,
  16606. radius: radius,
  16607. radialSegments: radialSegments,
  16608. closed: closed
  16609. };
  16610. tubularSegments = tubularSegments || 64;
  16611. radius = radius || 1;
  16612. radialSegments = radialSegments || 8;
  16613. closed = closed || false;
  16614. var frames = path.computeFrenetFrames( tubularSegments, closed );
  16615. // expose internals
  16616. this.tangents = frames.tangents;
  16617. this.normals = frames.normals;
  16618. this.binormals = frames.binormals;
  16619. // helper variables
  16620. var vertex = new Vector3();
  16621. var normal = new Vector3();
  16622. var uv = new Vector2();
  16623. var P = new Vector3();
  16624. var i, j;
  16625. // buffer
  16626. var vertices = [];
  16627. var normals = [];
  16628. var uvs = [];
  16629. var indices = [];
  16630. // create buffer data
  16631. generateBufferData();
  16632. // build geometry
  16633. this.setIndex( indices );
  16634. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  16635. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  16636. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  16637. // functions
  16638. function generateBufferData() {
  16639. for ( i = 0; i < tubularSegments; i ++ ) {
  16640. generateSegment( i );
  16641. }
  16642. // if the geometry is not closed, generate the last row of vertices and normals
  16643. // at the regular position on the given path
  16644. //
  16645. // if the geometry is closed, duplicate the first row of vertices and normals (uvs will differ)
  16646. generateSegment( ( closed === false ) ? tubularSegments : 0 );
  16647. // uvs are generated in a separate function.
  16648. // this makes it easy compute correct values for closed geometries
  16649. generateUVs();
  16650. // finally create faces
  16651. generateIndices();
  16652. }
  16653. function generateSegment( i ) {
  16654. // we use getPointAt to sample evenly distributed points from the given path
  16655. P = path.getPointAt( i / tubularSegments, P );
  16656. // retrieve corresponding normal and binormal
  16657. var N = frames.normals[ i ];
  16658. var B = frames.binormals[ i ];
  16659. // generate normals and vertices for the current segment
  16660. for ( j = 0; j <= radialSegments; j ++ ) {
  16661. var v = j / radialSegments * Math.PI * 2;
  16662. var sin = Math.sin( v );
  16663. var cos = - Math.cos( v );
  16664. // normal
  16665. normal.x = ( cos * N.x + sin * B.x );
  16666. normal.y = ( cos * N.y + sin * B.y );
  16667. normal.z = ( cos * N.z + sin * B.z );
  16668. normal.normalize();
  16669. normals.push( normal.x, normal.y, normal.z );
  16670. // vertex
  16671. vertex.x = P.x + radius * normal.x;
  16672. vertex.y = P.y + radius * normal.y;
  16673. vertex.z = P.z + radius * normal.z;
  16674. vertices.push( vertex.x, vertex.y, vertex.z );
  16675. }
  16676. }
  16677. function generateIndices() {
  16678. for ( j = 1; j <= tubularSegments; j ++ ) {
  16679. for ( i = 1; i <= radialSegments; i ++ ) {
  16680. var a = ( radialSegments + 1 ) * ( j - 1 ) + ( i - 1 );
  16681. var b = ( radialSegments + 1 ) * j + ( i - 1 );
  16682. var c = ( radialSegments + 1 ) * j + i;
  16683. var d = ( radialSegments + 1 ) * ( j - 1 ) + i;
  16684. // faces
  16685. indices.push( a, b, d );
  16686. indices.push( b, c, d );
  16687. }
  16688. }
  16689. }
  16690. function generateUVs() {
  16691. for ( i = 0; i <= tubularSegments; i ++ ) {
  16692. for ( j = 0; j <= radialSegments; j ++ ) {
  16693. uv.x = i / tubularSegments;
  16694. uv.y = j / radialSegments;
  16695. uvs.push( uv.x, uv.y );
  16696. }
  16697. }
  16698. }
  16699. }
  16700. TubeBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  16701. TubeBufferGeometry.prototype.constructor = TubeBufferGeometry;
  16702. TubeBufferGeometry.prototype.toJSON = function () {
  16703. var data = BufferGeometry.prototype.toJSON.call( this );
  16704. data.path = this.parameters.path.toJSON();
  16705. return data;
  16706. };
  16707. /**
  16708. * @author oosmoxiecode
  16709. * @author Mugen87 / https://github.com/Mugen87
  16710. *
  16711. * based on http://www.blackpawn.com/texts/pqtorus/
  16712. */
  16713. // TorusKnotGeometry
  16714. function TorusKnotGeometry( radius, tube, tubularSegments, radialSegments, p, q, heightScale ) {
  16715. Geometry.call( this );
  16716. this.type = 'TorusKnotGeometry';
  16717. this.parameters = {
  16718. radius: radius,
  16719. tube: tube,
  16720. tubularSegments: tubularSegments,
  16721. radialSegments: radialSegments,
  16722. p: p,
  16723. q: q
  16724. };
  16725. if ( heightScale !== undefined ) console.warn( 'THREE.TorusKnotGeometry: heightScale has been deprecated. Use .scale( x, y, z ) instead.' );
  16726. this.fromBufferGeometry( new TorusKnotBufferGeometry( radius, tube, tubularSegments, radialSegments, p, q ) );
  16727. this.mergeVertices();
  16728. }
  16729. TorusKnotGeometry.prototype = Object.create( Geometry.prototype );
  16730. TorusKnotGeometry.prototype.constructor = TorusKnotGeometry;
  16731. // TorusKnotBufferGeometry
  16732. function TorusKnotBufferGeometry( radius, tube, tubularSegments, radialSegments, p, q ) {
  16733. BufferGeometry.call( this );
  16734. this.type = 'TorusKnotBufferGeometry';
  16735. this.parameters = {
  16736. radius: radius,
  16737. tube: tube,
  16738. tubularSegments: tubularSegments,
  16739. radialSegments: radialSegments,
  16740. p: p,
  16741. q: q
  16742. };
  16743. radius = radius || 1;
  16744. tube = tube || 0.4;
  16745. tubularSegments = Math.floor( tubularSegments ) || 64;
  16746. radialSegments = Math.floor( radialSegments ) || 8;
  16747. p = p || 2;
  16748. q = q || 3;
  16749. // buffers
  16750. var indices = [];
  16751. var vertices = [];
  16752. var normals = [];
  16753. var uvs = [];
  16754. // helper variables
  16755. var i, j;
  16756. var vertex = new Vector3();
  16757. var normal = new Vector3();
  16758. var P1 = new Vector3();
  16759. var P2 = new Vector3();
  16760. var B = new Vector3();
  16761. var T = new Vector3();
  16762. var N = new Vector3();
  16763. // generate vertices, normals and uvs
  16764. for ( i = 0; i <= tubularSegments; ++ i ) {
  16765. // the radian "u" is used to calculate the position on the torus curve of the current tubular segement
  16766. var u = i / tubularSegments * p * Math.PI * 2;
  16767. // now we calculate two points. P1 is our current position on the curve, P2 is a little farther ahead.
  16768. // these points are used to create a special "coordinate space", which is necessary to calculate the correct vertex positions
  16769. calculatePositionOnCurve( u, p, q, radius, P1 );
  16770. calculatePositionOnCurve( u + 0.01, p, q, radius, P2 );
  16771. // calculate orthonormal basis
  16772. T.subVectors( P2, P1 );
  16773. N.addVectors( P2, P1 );
  16774. B.crossVectors( T, N );
  16775. N.crossVectors( B, T );
  16776. // normalize B, N. T can be ignored, we don't use it
  16777. B.normalize();
  16778. N.normalize();
  16779. for ( j = 0; j <= radialSegments; ++ j ) {
  16780. // now calculate the vertices. they are nothing more than an extrusion of the torus curve.
  16781. // because we extrude a shape in the xy-plane, there is no need to calculate a z-value.
  16782. var v = j / radialSegments * Math.PI * 2;
  16783. var cx = - tube * Math.cos( v );
  16784. var cy = tube * Math.sin( v );
  16785. // now calculate the final vertex position.
  16786. // first we orient the extrusion with our basis vectos, then we add it to the current position on the curve
  16787. vertex.x = P1.x + ( cx * N.x + cy * B.x );
  16788. vertex.y = P1.y + ( cx * N.y + cy * B.y );
  16789. vertex.z = P1.z + ( cx * N.z + cy * B.z );
  16790. vertices.push( vertex.x, vertex.y, vertex.z );
  16791. // normal (P1 is always the center/origin of the extrusion, thus we can use it to calculate the normal)
  16792. normal.subVectors( vertex, P1 ).normalize();
  16793. normals.push( normal.x, normal.y, normal.z );
  16794. // uv
  16795. uvs.push( i / tubularSegments );
  16796. uvs.push( j / radialSegments );
  16797. }
  16798. }
  16799. // generate indices
  16800. for ( j = 1; j <= tubularSegments; j ++ ) {
  16801. for ( i = 1; i <= radialSegments; i ++ ) {
  16802. // indices
  16803. var a = ( radialSegments + 1 ) * ( j - 1 ) + ( i - 1 );
  16804. var b = ( radialSegments + 1 ) * j + ( i - 1 );
  16805. var c = ( radialSegments + 1 ) * j + i;
  16806. var d = ( radialSegments + 1 ) * ( j - 1 ) + i;
  16807. // faces
  16808. indices.push( a, b, d );
  16809. indices.push( b, c, d );
  16810. }
  16811. }
  16812. // build geometry
  16813. this.setIndex( indices );
  16814. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  16815. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  16816. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  16817. // this function calculates the current position on the torus curve
  16818. function calculatePositionOnCurve( u, p, q, radius, position ) {
  16819. var cu = Math.cos( u );
  16820. var su = Math.sin( u );
  16821. var quOverP = q / p * u;
  16822. var cs = Math.cos( quOverP );
  16823. position.x = radius * ( 2 + cs ) * 0.5 * cu;
  16824. position.y = radius * ( 2 + cs ) * su * 0.5;
  16825. position.z = radius * Math.sin( quOverP ) * 0.5;
  16826. }
  16827. }
  16828. TorusKnotBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  16829. TorusKnotBufferGeometry.prototype.constructor = TorusKnotBufferGeometry;
  16830. /**
  16831. * @author oosmoxiecode
  16832. * @author mrdoob / http://mrdoob.com/
  16833. * @author Mugen87 / https://github.com/Mugen87
  16834. */
  16835. // TorusGeometry
  16836. function TorusGeometry( radius, tube, radialSegments, tubularSegments, arc ) {
  16837. Geometry.call( this );
  16838. this.type = 'TorusGeometry';
  16839. this.parameters = {
  16840. radius: radius,
  16841. tube: tube,
  16842. radialSegments: radialSegments,
  16843. tubularSegments: tubularSegments,
  16844. arc: arc
  16845. };
  16846. this.fromBufferGeometry( new TorusBufferGeometry( radius, tube, radialSegments, tubularSegments, arc ) );
  16847. this.mergeVertices();
  16848. }
  16849. TorusGeometry.prototype = Object.create( Geometry.prototype );
  16850. TorusGeometry.prototype.constructor = TorusGeometry;
  16851. // TorusBufferGeometry
  16852. function TorusBufferGeometry( radius, tube, radialSegments, tubularSegments, arc ) {
  16853. BufferGeometry.call( this );
  16854. this.type = 'TorusBufferGeometry';
  16855. this.parameters = {
  16856. radius: radius,
  16857. tube: tube,
  16858. radialSegments: radialSegments,
  16859. tubularSegments: tubularSegments,
  16860. arc: arc
  16861. };
  16862. radius = radius || 1;
  16863. tube = tube || 0.4;
  16864. radialSegments = Math.floor( radialSegments ) || 8;
  16865. tubularSegments = Math.floor( tubularSegments ) || 6;
  16866. arc = arc || Math.PI * 2;
  16867. // buffers
  16868. var indices = [];
  16869. var vertices = [];
  16870. var normals = [];
  16871. var uvs = [];
  16872. // helper variables
  16873. var center = new Vector3();
  16874. var vertex = new Vector3();
  16875. var normal = new Vector3();
  16876. var j, i;
  16877. // generate vertices, normals and uvs
  16878. for ( j = 0; j <= radialSegments; j ++ ) {
  16879. for ( i = 0; i <= tubularSegments; i ++ ) {
  16880. var u = i / tubularSegments * arc;
  16881. var v = j / radialSegments * Math.PI * 2;
  16882. // vertex
  16883. vertex.x = ( radius + tube * Math.cos( v ) ) * Math.cos( u );
  16884. vertex.y = ( radius + tube * Math.cos( v ) ) * Math.sin( u );
  16885. vertex.z = tube * Math.sin( v );
  16886. vertices.push( vertex.x, vertex.y, vertex.z );
  16887. // normal
  16888. center.x = radius * Math.cos( u );
  16889. center.y = radius * Math.sin( u );
  16890. normal.subVectors( vertex, center ).normalize();
  16891. normals.push( normal.x, normal.y, normal.z );
  16892. // uv
  16893. uvs.push( i / tubularSegments );
  16894. uvs.push( j / radialSegments );
  16895. }
  16896. }
  16897. // generate indices
  16898. for ( j = 1; j <= radialSegments; j ++ ) {
  16899. for ( i = 1; i <= tubularSegments; i ++ ) {
  16900. // indices
  16901. var a = ( tubularSegments + 1 ) * j + i - 1;
  16902. var b = ( tubularSegments + 1 ) * ( j - 1 ) + i - 1;
  16903. var c = ( tubularSegments + 1 ) * ( j - 1 ) + i;
  16904. var d = ( tubularSegments + 1 ) * j + i;
  16905. // faces
  16906. indices.push( a, b, d );
  16907. indices.push( b, c, d );
  16908. }
  16909. }
  16910. // build geometry
  16911. this.setIndex( indices );
  16912. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  16913. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  16914. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  16915. }
  16916. TorusBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  16917. TorusBufferGeometry.prototype.constructor = TorusBufferGeometry;
  16918. /**
  16919. * @author Mugen87 / https://github.com/Mugen87
  16920. * Port from https://github.com/mapbox/earcut (v2.1.2)
  16921. */
  16922. var Earcut = {
  16923. triangulate: function ( data, holeIndices, dim ) {
  16924. dim = dim || 2;
  16925. var hasHoles = holeIndices && holeIndices.length,
  16926. outerLen = hasHoles ? holeIndices[ 0 ] * dim : data.length,
  16927. outerNode = linkedList( data, 0, outerLen, dim, true ),
  16928. triangles = [];
  16929. if ( ! outerNode ) return triangles;
  16930. var minX, minY, maxX, maxY, x, y, invSize;
  16931. if ( hasHoles ) outerNode = eliminateHoles( data, holeIndices, outerNode, dim );
  16932. // if the shape is not too simple, we'll use z-order curve hash later; calculate polygon bbox
  16933. if ( data.length > 80 * dim ) {
  16934. minX = maxX = data[ 0 ];
  16935. minY = maxY = data[ 1 ];
  16936. for ( var i = dim; i < outerLen; i += dim ) {
  16937. x = data[ i ];
  16938. y = data[ i + 1 ];
  16939. if ( x < minX ) minX = x;
  16940. if ( y < minY ) minY = y;
  16941. if ( x > maxX ) maxX = x;
  16942. if ( y > maxY ) maxY = y;
  16943. }
  16944. // minX, minY and invSize are later used to transform coords into integers for z-order calculation
  16945. invSize = Math.max( maxX - minX, maxY - minY );
  16946. invSize = invSize !== 0 ? 1 / invSize : 0;
  16947. }
  16948. earcutLinked( outerNode, triangles, dim, minX, minY, invSize );
  16949. return triangles;
  16950. }
  16951. };
  16952. // create a circular doubly linked list from polygon points in the specified winding order
  16953. function linkedList( data, start, end, dim, clockwise ) {
  16954. var i, last;
  16955. if ( clockwise === ( signedArea( data, start, end, dim ) > 0 ) ) {
  16956. for ( i = start; i < end; i += dim ) last = insertNode( i, data[ i ], data[ i + 1 ], last );
  16957. } else {
  16958. for ( i = end - dim; i >= start; i -= dim ) last = insertNode( i, data[ i ], data[ i + 1 ], last );
  16959. }
  16960. if ( last && equals( last, last.next ) ) {
  16961. removeNode( last );
  16962. last = last.next;
  16963. }
  16964. return last;
  16965. }
  16966. // eliminate colinear or duplicate points
  16967. function filterPoints( start, end ) {
  16968. if ( ! start ) return start;
  16969. if ( ! end ) end = start;
  16970. var p = start, again;
  16971. do {
  16972. again = false;
  16973. if ( ! p.steiner && ( equals( p, p.next ) || area( p.prev, p, p.next ) === 0 ) ) {
  16974. removeNode( p );
  16975. p = end = p.prev;
  16976. if ( p === p.next ) break;
  16977. again = true;
  16978. } else {
  16979. p = p.next;
  16980. }
  16981. } while ( again || p !== end );
  16982. return end;
  16983. }
  16984. // main ear slicing loop which triangulates a polygon (given as a linked list)
  16985. function earcutLinked( ear, triangles, dim, minX, minY, invSize, pass ) {
  16986. if ( ! ear ) return;
  16987. // interlink polygon nodes in z-order
  16988. if ( ! pass && invSize ) indexCurve( ear, minX, minY, invSize );
  16989. var stop = ear, prev, next;
  16990. // iterate through ears, slicing them one by one
  16991. while ( ear.prev !== ear.next ) {
  16992. prev = ear.prev;
  16993. next = ear.next;
  16994. if ( invSize ? isEarHashed( ear, minX, minY, invSize ) : isEar( ear ) ) {
  16995. // cut off the triangle
  16996. triangles.push( prev.i / dim );
  16997. triangles.push( ear.i / dim );
  16998. triangles.push( next.i / dim );
  16999. removeNode( ear );
  17000. // skipping the next vertice leads to less sliver triangles
  17001. ear = next.next;
  17002. stop = next.next;
  17003. continue;
  17004. }
  17005. ear = next;
  17006. // if we looped through the whole remaining polygon and can't find any more ears
  17007. if ( ear === stop ) {
  17008. // try filtering points and slicing again
  17009. if ( ! pass ) {
  17010. earcutLinked( filterPoints( ear ), triangles, dim, minX, minY, invSize, 1 );
  17011. // if this didn't work, try curing all small self-intersections locally
  17012. } else if ( pass === 1 ) {
  17013. ear = cureLocalIntersections( ear, triangles, dim );
  17014. earcutLinked( ear, triangles, dim, minX, minY, invSize, 2 );
  17015. // as a last resort, try splitting the remaining polygon into two
  17016. } else if ( pass === 2 ) {
  17017. splitEarcut( ear, triangles, dim, minX, minY, invSize );
  17018. }
  17019. break;
  17020. }
  17021. }
  17022. }
  17023. // check whether a polygon node forms a valid ear with adjacent nodes
  17024. function isEar( ear ) {
  17025. var a = ear.prev,
  17026. b = ear,
  17027. c = ear.next;
  17028. if ( area( a, b, c ) >= 0 ) return false; // reflex, can't be an ear
  17029. // now make sure we don't have other points inside the potential ear
  17030. var p = ear.next.next;
  17031. while ( p !== ear.prev ) {
  17032. 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 ) {
  17033. return false;
  17034. }
  17035. p = p.next;
  17036. }
  17037. return true;
  17038. }
  17039. function isEarHashed( ear, minX, minY, invSize ) {
  17040. var a = ear.prev,
  17041. b = ear,
  17042. c = ear.next;
  17043. if ( area( a, b, c ) >= 0 ) return false; // reflex, can't be an ear
  17044. // triangle bbox; min & max are calculated like this for speed
  17045. var minTX = a.x < b.x ? ( a.x < c.x ? a.x : c.x ) : ( b.x < c.x ? b.x : c.x ),
  17046. minTY = a.y < b.y ? ( a.y < c.y ? a.y : c.y ) : ( b.y < c.y ? b.y : c.y ),
  17047. maxTX = a.x > b.x ? ( a.x > c.x ? a.x : c.x ) : ( b.x > c.x ? b.x : c.x ),
  17048. maxTY = a.y > b.y ? ( a.y > c.y ? a.y : c.y ) : ( b.y > c.y ? b.y : c.y );
  17049. // z-order range for the current triangle bbox;
  17050. var minZ = zOrder( minTX, minTY, minX, minY, invSize ),
  17051. maxZ = zOrder( maxTX, maxTY, minX, minY, invSize );
  17052. // first look for points inside the triangle in increasing z-order
  17053. var p = ear.nextZ;
  17054. while ( p && p.z <= maxZ ) {
  17055. if ( p !== ear.prev && p !== ear.next &&
  17056. pointInTriangle( a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y ) &&
  17057. area( p.prev, p, p.next ) >= 0 ) return false;
  17058. p = p.nextZ;
  17059. }
  17060. // then look for points in decreasing z-order
  17061. p = ear.prevZ;
  17062. while ( p && p.z >= minZ ) {
  17063. if ( p !== ear.prev && p !== ear.next &&
  17064. pointInTriangle( a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y ) &&
  17065. area( p.prev, p, p.next ) >= 0 ) return false;
  17066. p = p.prevZ;
  17067. }
  17068. return true;
  17069. }
  17070. // go through all polygon nodes and cure small local self-intersections
  17071. function cureLocalIntersections( start, triangles, dim ) {
  17072. var p = start;
  17073. do {
  17074. var a = p.prev, b = p.next.next;
  17075. if ( ! equals( a, b ) && intersects( a, p, p.next, b ) && locallyInside( a, b ) && locallyInside( b, a ) ) {
  17076. triangles.push( a.i / dim );
  17077. triangles.push( p.i / dim );
  17078. triangles.push( b.i / dim );
  17079. // remove two nodes involved
  17080. removeNode( p );
  17081. removeNode( p.next );
  17082. p = start = b;
  17083. }
  17084. p = p.next;
  17085. } while ( p !== start );
  17086. return p;
  17087. }
  17088. // try splitting polygon into two and triangulate them independently
  17089. function splitEarcut( start, triangles, dim, minX, minY, invSize ) {
  17090. // look for a valid diagonal that divides the polygon into two
  17091. var a = start;
  17092. do {
  17093. var b = a.next.next;
  17094. while ( b !== a.prev ) {
  17095. if ( a.i !== b.i && isValidDiagonal( a, b ) ) {
  17096. // split the polygon in two by the diagonal
  17097. var c = splitPolygon( a, b );
  17098. // filter colinear points around the cuts
  17099. a = filterPoints( a, a.next );
  17100. c = filterPoints( c, c.next );
  17101. // run earcut on each half
  17102. earcutLinked( a, triangles, dim, minX, minY, invSize );
  17103. earcutLinked( c, triangles, dim, minX, minY, invSize );
  17104. return;
  17105. }
  17106. b = b.next;
  17107. }
  17108. a = a.next;
  17109. } while ( a !== start );
  17110. }
  17111. // link every hole into the outer loop, producing a single-ring polygon without holes
  17112. function eliminateHoles( data, holeIndices, outerNode, dim ) {
  17113. var queue = [], i, len, start, end, list;
  17114. for ( i = 0, len = holeIndices.length; i < len; i ++ ) {
  17115. start = holeIndices[ i ] * dim;
  17116. end = i < len - 1 ? holeIndices[ i + 1 ] * dim : data.length;
  17117. list = linkedList( data, start, end, dim, false );
  17118. if ( list === list.next ) list.steiner = true;
  17119. queue.push( getLeftmost( list ) );
  17120. }
  17121. queue.sort( compareX );
  17122. // process holes from left to right
  17123. for ( i = 0; i < queue.length; i ++ ) {
  17124. eliminateHole( queue[ i ], outerNode );
  17125. outerNode = filterPoints( outerNode, outerNode.next );
  17126. }
  17127. return outerNode;
  17128. }
  17129. function compareX( a, b ) {
  17130. return a.x - b.x;
  17131. }
  17132. // find a bridge between vertices that connects hole with an outer ring and and link it
  17133. function eliminateHole( hole, outerNode ) {
  17134. outerNode = findHoleBridge( hole, outerNode );
  17135. if ( outerNode ) {
  17136. var b = splitPolygon( outerNode, hole );
  17137. filterPoints( b, b.next );
  17138. }
  17139. }
  17140. // David Eberly's algorithm for finding a bridge between hole and outer polygon
  17141. function findHoleBridge( hole, outerNode ) {
  17142. var p = outerNode,
  17143. hx = hole.x,
  17144. hy = hole.y,
  17145. qx = - Infinity,
  17146. m;
  17147. // find a segment intersected by a ray from the hole's leftmost point to the left;
  17148. // segment's endpoint with lesser x will be potential connection point
  17149. do {
  17150. if ( hy <= p.y && hy >= p.next.y && p.next.y !== p.y ) {
  17151. var x = p.x + ( hy - p.y ) * ( p.next.x - p.x ) / ( p.next.y - p.y );
  17152. if ( x <= hx && x > qx ) {
  17153. qx = x;
  17154. if ( x === hx ) {
  17155. if ( hy === p.y ) return p;
  17156. if ( hy === p.next.y ) return p.next;
  17157. }
  17158. m = p.x < p.next.x ? p : p.next;
  17159. }
  17160. }
  17161. p = p.next;
  17162. } while ( p !== outerNode );
  17163. if ( ! m ) return null;
  17164. if ( hx === qx ) return m.prev; // hole touches outer segment; pick lower endpoint
  17165. // look for points inside the triangle of hole point, segment intersection and endpoint;
  17166. // if there are no points found, we have a valid connection;
  17167. // otherwise choose the point of the minimum angle with the ray as connection point
  17168. var stop = m,
  17169. mx = m.x,
  17170. my = m.y,
  17171. tanMin = Infinity,
  17172. tan;
  17173. p = m.next;
  17174. while ( p !== stop ) {
  17175. if ( hx >= p.x && p.x >= mx && hx !== p.x &&
  17176. pointInTriangle( hy < my ? hx : qx, hy, mx, my, hy < my ? qx : hx, hy, p.x, p.y ) ) {
  17177. tan = Math.abs( hy - p.y ) / ( hx - p.x ); // tangential
  17178. if ( ( tan < tanMin || ( tan === tanMin && p.x > m.x ) ) && locallyInside( p, hole ) ) {
  17179. m = p;
  17180. tanMin = tan;
  17181. }
  17182. }
  17183. p = p.next;
  17184. }
  17185. return m;
  17186. }
  17187. // interlink polygon nodes in z-order
  17188. function indexCurve( start, minX, minY, invSize ) {
  17189. var p = start;
  17190. do {
  17191. if ( p.z === null ) p.z = zOrder( p.x, p.y, minX, minY, invSize );
  17192. p.prevZ = p.prev;
  17193. p.nextZ = p.next;
  17194. p = p.next;
  17195. } while ( p !== start );
  17196. p.prevZ.nextZ = null;
  17197. p.prevZ = null;
  17198. sortLinked( p );
  17199. }
  17200. // Simon Tatham's linked list merge sort algorithm
  17201. // http://www.chiark.greenend.org.uk/~sgtatham/algorithms/listsort.html
  17202. function sortLinked( list ) {
  17203. var i, p, q, e, tail, numMerges, pSize, qSize, inSize = 1;
  17204. do {
  17205. p = list;
  17206. list = null;
  17207. tail = null;
  17208. numMerges = 0;
  17209. while ( p ) {
  17210. numMerges ++;
  17211. q = p;
  17212. pSize = 0;
  17213. for ( i = 0; i < inSize; i ++ ) {
  17214. pSize ++;
  17215. q = q.nextZ;
  17216. if ( ! q ) break;
  17217. }
  17218. qSize = inSize;
  17219. while ( pSize > 0 || ( qSize > 0 && q ) ) {
  17220. if ( pSize !== 0 && ( qSize === 0 || ! q || p.z <= q.z ) ) {
  17221. e = p;
  17222. p = p.nextZ;
  17223. pSize --;
  17224. } else {
  17225. e = q;
  17226. q = q.nextZ;
  17227. qSize --;
  17228. }
  17229. if ( tail ) tail.nextZ = e;
  17230. else list = e;
  17231. e.prevZ = tail;
  17232. tail = e;
  17233. }
  17234. p = q;
  17235. }
  17236. tail.nextZ = null;
  17237. inSize *= 2;
  17238. } while ( numMerges > 1 );
  17239. return list;
  17240. }
  17241. // z-order of a point given coords and inverse of the longer side of data bbox
  17242. function zOrder( x, y, minX, minY, invSize ) {
  17243. // coords are transformed into non-negative 15-bit integer range
  17244. x = 32767 * ( x - minX ) * invSize;
  17245. y = 32767 * ( y - minY ) * invSize;
  17246. x = ( x | ( x << 8 ) ) & 0x00FF00FF;
  17247. x = ( x | ( x << 4 ) ) & 0x0F0F0F0F;
  17248. x = ( x | ( x << 2 ) ) & 0x33333333;
  17249. x = ( x | ( x << 1 ) ) & 0x55555555;
  17250. y = ( y | ( y << 8 ) ) & 0x00FF00FF;
  17251. y = ( y | ( y << 4 ) ) & 0x0F0F0F0F;
  17252. y = ( y | ( y << 2 ) ) & 0x33333333;
  17253. y = ( y | ( y << 1 ) ) & 0x55555555;
  17254. return x | ( y << 1 );
  17255. }
  17256. // find the leftmost node of a polygon ring
  17257. function getLeftmost( start ) {
  17258. var p = start, leftmost = start;
  17259. do {
  17260. if ( p.x < leftmost.x ) leftmost = p;
  17261. p = p.next;
  17262. } while ( p !== start );
  17263. return leftmost;
  17264. }
  17265. // check if a point lies within a convex triangle
  17266. function pointInTriangle( ax, ay, bx, by, cx, cy, px, py ) {
  17267. return ( cx - px ) * ( ay - py ) - ( ax - px ) * ( cy - py ) >= 0 &&
  17268. ( ax - px ) * ( by - py ) - ( bx - px ) * ( ay - py ) >= 0 &&
  17269. ( bx - px ) * ( cy - py ) - ( cx - px ) * ( by - py ) >= 0;
  17270. }
  17271. // check if a diagonal between two polygon nodes is valid (lies in polygon interior)
  17272. function isValidDiagonal( a, b ) {
  17273. return a.next.i !== b.i && a.prev.i !== b.i && ! intersectsPolygon( a, b ) &&
  17274. locallyInside( a, b ) && locallyInside( b, a ) && middleInside( a, b );
  17275. }
  17276. // signed area of a triangle
  17277. function area( p, q, r ) {
  17278. return ( q.y - p.y ) * ( r.x - q.x ) - ( q.x - p.x ) * ( r.y - q.y );
  17279. }
  17280. // check if two points are equal
  17281. function equals( p1, p2 ) {
  17282. return p1.x === p2.x && p1.y === p2.y;
  17283. }
  17284. // check if two segments intersect
  17285. function intersects( p1, q1, p2, q2 ) {
  17286. if ( ( equals( p1, q1 ) && equals( p2, q2 ) ) ||
  17287. ( equals( p1, q2 ) && equals( p2, q1 ) ) ) return true;
  17288. return area( p1, q1, p2 ) > 0 !== area( p1, q1, q2 ) > 0 &&
  17289. area( p2, q2, p1 ) > 0 !== area( p2, q2, q1 ) > 0;
  17290. }
  17291. // check if a polygon diagonal intersects any polygon segments
  17292. function intersectsPolygon( a, b ) {
  17293. var p = a;
  17294. do {
  17295. if ( p.i !== a.i && p.next.i !== a.i && p.i !== b.i && p.next.i !== b.i &&
  17296. intersects( p, p.next, a, b ) ) {
  17297. return true;
  17298. }
  17299. p = p.next;
  17300. } while ( p !== a );
  17301. return false;
  17302. }
  17303. // check if a polygon diagonal is locally inside the polygon
  17304. function locallyInside( a, b ) {
  17305. return area( a.prev, a, a.next ) < 0 ?
  17306. area( a, b, a.next ) >= 0 && area( a, a.prev, b ) >= 0 :
  17307. area( a, b, a.prev ) < 0 || area( a, a.next, b ) < 0;
  17308. }
  17309. // check if the middle point of a polygon diagonal is inside the polygon
  17310. function middleInside( a, b ) {
  17311. var p = a,
  17312. inside = false,
  17313. px = ( a.x + b.x ) / 2,
  17314. py = ( a.y + b.y ) / 2;
  17315. do {
  17316. if ( ( ( p.y > py ) !== ( p.next.y > py ) ) && p.next.y !== p.y &&
  17317. ( px < ( p.next.x - p.x ) * ( py - p.y ) / ( p.next.y - p.y ) + p.x ) ) {
  17318. inside = ! inside;
  17319. }
  17320. p = p.next;
  17321. } while ( p !== a );
  17322. return inside;
  17323. }
  17324. // link two polygon vertices with a bridge; if the vertices belong to the same ring, it splits polygon into two;
  17325. // if one belongs to the outer ring and another to a hole, it merges it into a single ring
  17326. function splitPolygon( a, b ) {
  17327. var a2 = new Node( a.i, a.x, a.y ),
  17328. b2 = new Node( b.i, b.x, b.y ),
  17329. an = a.next,
  17330. bp = b.prev;
  17331. a.next = b;
  17332. b.prev = a;
  17333. a2.next = an;
  17334. an.prev = a2;
  17335. b2.next = a2;
  17336. a2.prev = b2;
  17337. bp.next = b2;
  17338. b2.prev = bp;
  17339. return b2;
  17340. }
  17341. // create a node and optionally link it with previous one (in a circular doubly linked list)
  17342. function insertNode( i, x, y, last ) {
  17343. var p = new Node( i, x, y );
  17344. if ( ! last ) {
  17345. p.prev = p;
  17346. p.next = p;
  17347. } else {
  17348. p.next = last.next;
  17349. p.prev = last;
  17350. last.next.prev = p;
  17351. last.next = p;
  17352. }
  17353. return p;
  17354. }
  17355. function removeNode( p ) {
  17356. p.next.prev = p.prev;
  17357. p.prev.next = p.next;
  17358. if ( p.prevZ ) p.prevZ.nextZ = p.nextZ;
  17359. if ( p.nextZ ) p.nextZ.prevZ = p.prevZ;
  17360. }
  17361. function Node( i, x, y ) {
  17362. // vertice index in coordinates array
  17363. this.i = i;
  17364. // vertex coordinates
  17365. this.x = x;
  17366. this.y = y;
  17367. // previous and next vertice nodes in a polygon ring
  17368. this.prev = null;
  17369. this.next = null;
  17370. // z-order curve value
  17371. this.z = null;
  17372. // previous and next nodes in z-order
  17373. this.prevZ = null;
  17374. this.nextZ = null;
  17375. // indicates whether this is a steiner point
  17376. this.steiner = false;
  17377. }
  17378. function signedArea( data, start, end, dim ) {
  17379. var sum = 0;
  17380. for ( var i = start, j = end - dim; i < end; i += dim ) {
  17381. sum += ( data[ j ] - data[ i ] ) * ( data[ i + 1 ] + data[ j + 1 ] );
  17382. j = i;
  17383. }
  17384. return sum;
  17385. }
  17386. /**
  17387. * @author zz85 / http://www.lab4games.net/zz85/blog
  17388. */
  17389. var ShapeUtils = {
  17390. // calculate area of the contour polygon
  17391. area: function ( contour ) {
  17392. var n = contour.length;
  17393. var a = 0.0;
  17394. for ( var p = n - 1, q = 0; q < n; p = q ++ ) {
  17395. a += contour[ p ].x * contour[ q ].y - contour[ q ].x * contour[ p ].y;
  17396. }
  17397. return a * 0.5;
  17398. },
  17399. isClockWise: function ( pts ) {
  17400. return ShapeUtils.area( pts ) < 0;
  17401. },
  17402. triangulateShape: function ( contour, holes ) {
  17403. var vertices = []; // flat array of vertices like [ x0,y0, x1,y1, x2,y2, ... ]
  17404. var holeIndices = []; // array of hole indices
  17405. var faces = []; // final array of vertex indices like [ [ a,b,d ], [ b,c,d ] ]
  17406. removeDupEndPts( contour );
  17407. addContour( vertices, contour );
  17408. //
  17409. var holeIndex = contour.length;
  17410. holes.forEach( removeDupEndPts );
  17411. for ( var i = 0; i < holes.length; i ++ ) {
  17412. holeIndices.push( holeIndex );
  17413. holeIndex += holes[ i ].length;
  17414. addContour( vertices, holes[ i ] );
  17415. }
  17416. //
  17417. var triangles = Earcut.triangulate( vertices, holeIndices );
  17418. //
  17419. for ( var i = 0; i < triangles.length; i += 3 ) {
  17420. faces.push( triangles.slice( i, i + 3 ) );
  17421. }
  17422. return faces;
  17423. }
  17424. };
  17425. function removeDupEndPts( points ) {
  17426. var l = points.length;
  17427. if ( l > 2 && points[ l - 1 ].equals( points[ 0 ] ) ) {
  17428. points.pop();
  17429. }
  17430. }
  17431. function addContour( vertices, contour ) {
  17432. for ( var i = 0; i < contour.length; i ++ ) {
  17433. vertices.push( contour[ i ].x );
  17434. vertices.push( contour[ i ].y );
  17435. }
  17436. }
  17437. /**
  17438. * @author zz85 / http://www.lab4games.net/zz85/blog
  17439. *
  17440. * Creates extruded geometry from a path shape.
  17441. *
  17442. * parameters = {
  17443. *
  17444. * curveSegments: <int>, // number of points on the curves
  17445. * steps: <int>, // number of points for z-side extrusions / used for subdividing segments of extrude spline too
  17446. * depth: <float>, // Depth to extrude the shape
  17447. *
  17448. * bevelEnabled: <bool>, // turn on bevel
  17449. * bevelThickness: <float>, // how deep into the original shape bevel goes
  17450. * bevelSize: <float>, // how far from shape outline (including bevelOffset) is bevel
  17451. * bevelOffset: <float>, // how far from shape outline does bevel start
  17452. * bevelSegments: <int>, // number of bevel layers
  17453. *
  17454. * extrudePath: <THREE.Curve> // curve to extrude shape along
  17455. *
  17456. * UVGenerator: <Object> // object that provides UV generator functions
  17457. *
  17458. * }
  17459. */
  17460. // ExtrudeGeometry
  17461. function ExtrudeGeometry( shapes, options ) {
  17462. Geometry.call( this );
  17463. this.type = 'ExtrudeGeometry';
  17464. this.parameters = {
  17465. shapes: shapes,
  17466. options: options
  17467. };
  17468. this.fromBufferGeometry( new ExtrudeBufferGeometry( shapes, options ) );
  17469. this.mergeVertices();
  17470. }
  17471. ExtrudeGeometry.prototype = Object.create( Geometry.prototype );
  17472. ExtrudeGeometry.prototype.constructor = ExtrudeGeometry;
  17473. ExtrudeGeometry.prototype.toJSON = function () {
  17474. var data = Geometry.prototype.toJSON.call( this );
  17475. var shapes = this.parameters.shapes;
  17476. var options = this.parameters.options;
  17477. return toJSON( shapes, options, data );
  17478. };
  17479. // ExtrudeBufferGeometry
  17480. function ExtrudeBufferGeometry( shapes, options ) {
  17481. BufferGeometry.call( this );
  17482. this.type = 'ExtrudeBufferGeometry';
  17483. this.parameters = {
  17484. shapes: shapes,
  17485. options: options
  17486. };
  17487. shapes = Array.isArray( shapes ) ? shapes : [ shapes ];
  17488. var scope = this;
  17489. var verticesArray = [];
  17490. var uvArray = [];
  17491. for ( var i = 0, l = shapes.length; i < l; i ++ ) {
  17492. var shape = shapes[ i ];
  17493. addShape( shape );
  17494. }
  17495. // build geometry
  17496. this.addAttribute( 'position', new Float32BufferAttribute( verticesArray, 3 ) );
  17497. this.addAttribute( 'uv', new Float32BufferAttribute( uvArray, 2 ) );
  17498. this.computeVertexNormals();
  17499. // functions
  17500. function addShape( shape ) {
  17501. var placeholder = [];
  17502. // options
  17503. var curveSegments = options.curveSegments !== undefined ? options.curveSegments : 12;
  17504. var steps = options.steps !== undefined ? options.steps : 1;
  17505. var depth = options.depth !== undefined ? options.depth : 100;
  17506. var bevelEnabled = options.bevelEnabled !== undefined ? options.bevelEnabled : true;
  17507. var bevelThickness = options.bevelThickness !== undefined ? options.bevelThickness : 6;
  17508. var bevelSize = options.bevelSize !== undefined ? options.bevelSize : bevelThickness - 2;
  17509. var bevelOffset = options.bevelOffset !== undefined ? options.bevelOffset : 0;
  17510. var bevelSegments = options.bevelSegments !== undefined ? options.bevelSegments : 3;
  17511. var extrudePath = options.extrudePath;
  17512. var uvgen = options.UVGenerator !== undefined ? options.UVGenerator : WorldUVGenerator;
  17513. // deprecated options
  17514. if ( options.amount !== undefined ) {
  17515. console.warn( 'THREE.ExtrudeBufferGeometry: amount has been renamed to depth.' );
  17516. depth = options.amount;
  17517. }
  17518. //
  17519. var extrudePts, extrudeByPath = false;
  17520. var splineTube, binormal, normal, position2;
  17521. if ( extrudePath ) {
  17522. extrudePts = extrudePath.getSpacedPoints( steps );
  17523. extrudeByPath = true;
  17524. bevelEnabled = false; // bevels not supported for path extrusion
  17525. // SETUP TNB variables
  17526. // TODO1 - have a .isClosed in spline?
  17527. splineTube = extrudePath.computeFrenetFrames( steps, false );
  17528. // console.log(splineTube, 'splineTube', splineTube.normals.length, 'steps', steps, 'extrudePts', extrudePts.length);
  17529. binormal = new Vector3();
  17530. normal = new Vector3();
  17531. position2 = new Vector3();
  17532. }
  17533. // Safeguards if bevels are not enabled
  17534. if ( ! bevelEnabled ) {
  17535. bevelSegments = 0;
  17536. bevelThickness = 0;
  17537. bevelSize = 0;
  17538. bevelOffset = 0;
  17539. }
  17540. // Variables initialization
  17541. var ahole, h, hl; // looping of holes
  17542. var shapePoints = shape.extractPoints( curveSegments );
  17543. var vertices = shapePoints.shape;
  17544. var holes = shapePoints.holes;
  17545. var reverse = ! ShapeUtils.isClockWise( vertices );
  17546. if ( reverse ) {
  17547. vertices = vertices.reverse();
  17548. // Maybe we should also check if holes are in the opposite direction, just to be safe ...
  17549. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  17550. ahole = holes[ h ];
  17551. if ( ShapeUtils.isClockWise( ahole ) ) {
  17552. holes[ h ] = ahole.reverse();
  17553. }
  17554. }
  17555. }
  17556. var faces = ShapeUtils.triangulateShape( vertices, holes );
  17557. /* Vertices */
  17558. var contour = vertices; // vertices has all points but contour has only points of circumference
  17559. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  17560. ahole = holes[ h ];
  17561. vertices = vertices.concat( ahole );
  17562. }
  17563. function scalePt2( pt, vec, size ) {
  17564. if ( ! vec ) console.error( "THREE.ExtrudeGeometry: vec does not exist" );
  17565. return vec.clone().multiplyScalar( size ).add( pt );
  17566. }
  17567. var b, bs, t, z,
  17568. vert, vlen = vertices.length,
  17569. face, flen = faces.length;
  17570. // Find directions for point movement
  17571. function getBevelVec( inPt, inPrev, inNext ) {
  17572. // computes for inPt the corresponding point inPt' on a new contour
  17573. // shifted by 1 unit (length of normalized vector) to the left
  17574. // if we walk along contour clockwise, this new contour is outside the old one
  17575. //
  17576. // inPt' is the intersection of the two lines parallel to the two
  17577. // adjacent edges of inPt at a distance of 1 unit on the left side.
  17578. var v_trans_x, v_trans_y, shrink_by; // resulting translation vector for inPt
  17579. // good reading for geometry algorithms (here: line-line intersection)
  17580. // http://geomalgorithms.com/a05-_intersect-1.html
  17581. var v_prev_x = inPt.x - inPrev.x,
  17582. v_prev_y = inPt.y - inPrev.y;
  17583. var v_next_x = inNext.x - inPt.x,
  17584. v_next_y = inNext.y - inPt.y;
  17585. var v_prev_lensq = ( v_prev_x * v_prev_x + v_prev_y * v_prev_y );
  17586. // check for collinear edges
  17587. var collinear0 = ( v_prev_x * v_next_y - v_prev_y * v_next_x );
  17588. if ( Math.abs( collinear0 ) > Number.EPSILON ) {
  17589. // not collinear
  17590. // length of vectors for normalizing
  17591. var v_prev_len = Math.sqrt( v_prev_lensq );
  17592. var v_next_len = Math.sqrt( v_next_x * v_next_x + v_next_y * v_next_y );
  17593. // shift adjacent points by unit vectors to the left
  17594. var ptPrevShift_x = ( inPrev.x - v_prev_y / v_prev_len );
  17595. var ptPrevShift_y = ( inPrev.y + v_prev_x / v_prev_len );
  17596. var ptNextShift_x = ( inNext.x - v_next_y / v_next_len );
  17597. var ptNextShift_y = ( inNext.y + v_next_x / v_next_len );
  17598. // scaling factor for v_prev to intersection point
  17599. var sf = ( ( ptNextShift_x - ptPrevShift_x ) * v_next_y -
  17600. ( ptNextShift_y - ptPrevShift_y ) * v_next_x ) /
  17601. ( v_prev_x * v_next_y - v_prev_y * v_next_x );
  17602. // vector from inPt to intersection point
  17603. v_trans_x = ( ptPrevShift_x + v_prev_x * sf - inPt.x );
  17604. v_trans_y = ( ptPrevShift_y + v_prev_y * sf - inPt.y );
  17605. // Don't normalize!, otherwise sharp corners become ugly
  17606. // but prevent crazy spikes
  17607. var v_trans_lensq = ( v_trans_x * v_trans_x + v_trans_y * v_trans_y );
  17608. if ( v_trans_lensq <= 2 ) {
  17609. return new Vector2( v_trans_x, v_trans_y );
  17610. } else {
  17611. shrink_by = Math.sqrt( v_trans_lensq / 2 );
  17612. }
  17613. } else {
  17614. // handle special case of collinear edges
  17615. var direction_eq = false; // assumes: opposite
  17616. if ( v_prev_x > Number.EPSILON ) {
  17617. if ( v_next_x > Number.EPSILON ) {
  17618. direction_eq = true;
  17619. }
  17620. } else {
  17621. if ( v_prev_x < - Number.EPSILON ) {
  17622. if ( v_next_x < - Number.EPSILON ) {
  17623. direction_eq = true;
  17624. }
  17625. } else {
  17626. if ( Math.sign( v_prev_y ) === Math.sign( v_next_y ) ) {
  17627. direction_eq = true;
  17628. }
  17629. }
  17630. }
  17631. if ( direction_eq ) {
  17632. // console.log("Warning: lines are a straight sequence");
  17633. v_trans_x = - v_prev_y;
  17634. v_trans_y = v_prev_x;
  17635. shrink_by = Math.sqrt( v_prev_lensq );
  17636. } else {
  17637. // console.log("Warning: lines are a straight spike");
  17638. v_trans_x = v_prev_x;
  17639. v_trans_y = v_prev_y;
  17640. shrink_by = Math.sqrt( v_prev_lensq / 2 );
  17641. }
  17642. }
  17643. return new Vector2( v_trans_x / shrink_by, v_trans_y / shrink_by );
  17644. }
  17645. var contourMovements = [];
  17646. for ( var i = 0, il = contour.length, j = il - 1, k = i + 1; i < il; i ++, j ++, k ++ ) {
  17647. if ( j === il ) j = 0;
  17648. if ( k === il ) k = 0;
  17649. // (j)---(i)---(k)
  17650. // console.log('i,j,k', i, j , k)
  17651. contourMovements[ i ] = getBevelVec( contour[ i ], contour[ j ], contour[ k ] );
  17652. }
  17653. var holesMovements = [],
  17654. oneHoleMovements, verticesMovements = contourMovements.concat();
  17655. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  17656. ahole = holes[ h ];
  17657. oneHoleMovements = [];
  17658. for ( i = 0, il = ahole.length, j = il - 1, k = i + 1; i < il; i ++, j ++, k ++ ) {
  17659. if ( j === il ) j = 0;
  17660. if ( k === il ) k = 0;
  17661. // (j)---(i)---(k)
  17662. oneHoleMovements[ i ] = getBevelVec( ahole[ i ], ahole[ j ], ahole[ k ] );
  17663. }
  17664. holesMovements.push( oneHoleMovements );
  17665. verticesMovements = verticesMovements.concat( oneHoleMovements );
  17666. }
  17667. // Loop bevelSegments, 1 for the front, 1 for the back
  17668. for ( b = 0; b < bevelSegments; b ++ ) {
  17669. //for ( b = bevelSegments; b > 0; b -- ) {
  17670. t = b / bevelSegments;
  17671. z = bevelThickness * Math.cos( t * Math.PI / 2 );
  17672. bs = bevelSize * Math.sin( t * Math.PI / 2 ) + bevelOffset;
  17673. // contract shape
  17674. for ( i = 0, il = contour.length; i < il; i ++ ) {
  17675. vert = scalePt2( contour[ i ], contourMovements[ i ], bs );
  17676. v( vert.x, vert.y, - z );
  17677. }
  17678. // expand holes
  17679. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  17680. ahole = holes[ h ];
  17681. oneHoleMovements = holesMovements[ h ];
  17682. for ( i = 0, il = ahole.length; i < il; i ++ ) {
  17683. vert = scalePt2( ahole[ i ], oneHoleMovements[ i ], bs );
  17684. v( vert.x, vert.y, - z );
  17685. }
  17686. }
  17687. }
  17688. bs = bevelSize + bevelOffset;
  17689. // Back facing vertices
  17690. for ( i = 0; i < vlen; i ++ ) {
  17691. vert = bevelEnabled ? scalePt2( vertices[ i ], verticesMovements[ i ], bs ) : vertices[ i ];
  17692. if ( ! extrudeByPath ) {
  17693. v( vert.x, vert.y, 0 );
  17694. } else {
  17695. // v( vert.x, vert.y + extrudePts[ 0 ].y, extrudePts[ 0 ].x );
  17696. normal.copy( splineTube.normals[ 0 ] ).multiplyScalar( vert.x );
  17697. binormal.copy( splineTube.binormals[ 0 ] ).multiplyScalar( vert.y );
  17698. position2.copy( extrudePts[ 0 ] ).add( normal ).add( binormal );
  17699. v( position2.x, position2.y, position2.z );
  17700. }
  17701. }
  17702. // Add stepped vertices...
  17703. // Including front facing vertices
  17704. var s;
  17705. for ( s = 1; s <= steps; s ++ ) {
  17706. for ( i = 0; i < vlen; i ++ ) {
  17707. vert = bevelEnabled ? scalePt2( vertices[ i ], verticesMovements[ i ], bs ) : vertices[ i ];
  17708. if ( ! extrudeByPath ) {
  17709. v( vert.x, vert.y, depth / steps * s );
  17710. } else {
  17711. // v( vert.x, vert.y + extrudePts[ s - 1 ].y, extrudePts[ s - 1 ].x );
  17712. normal.copy( splineTube.normals[ s ] ).multiplyScalar( vert.x );
  17713. binormal.copy( splineTube.binormals[ s ] ).multiplyScalar( vert.y );
  17714. position2.copy( extrudePts[ s ] ).add( normal ).add( binormal );
  17715. v( position2.x, position2.y, position2.z );
  17716. }
  17717. }
  17718. }
  17719. // Add bevel segments planes
  17720. //for ( b = 1; b <= bevelSegments; b ++ ) {
  17721. for ( b = bevelSegments - 1; b >= 0; b -- ) {
  17722. t = b / bevelSegments;
  17723. z = bevelThickness * Math.cos( t * Math.PI / 2 );
  17724. bs = bevelSize * Math.sin( t * Math.PI / 2 ) + bevelOffset;
  17725. // contract shape
  17726. for ( i = 0, il = contour.length; i < il; i ++ ) {
  17727. vert = scalePt2( contour[ i ], contourMovements[ i ], bs );
  17728. v( vert.x, vert.y, depth + z );
  17729. }
  17730. // expand holes
  17731. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  17732. ahole = holes[ h ];
  17733. oneHoleMovements = holesMovements[ h ];
  17734. for ( i = 0, il = ahole.length; i < il; i ++ ) {
  17735. vert = scalePt2( ahole[ i ], oneHoleMovements[ i ], bs );
  17736. if ( ! extrudeByPath ) {
  17737. v( vert.x, vert.y, depth + z );
  17738. } else {
  17739. v( vert.x, vert.y + extrudePts[ steps - 1 ].y, extrudePts[ steps - 1 ].x + z );
  17740. }
  17741. }
  17742. }
  17743. }
  17744. /* Faces */
  17745. // Top and bottom faces
  17746. buildLidFaces();
  17747. // Sides faces
  17748. buildSideFaces();
  17749. ///// Internal functions
  17750. function buildLidFaces() {
  17751. var start = verticesArray.length / 3;
  17752. if ( bevelEnabled ) {
  17753. var layer = 0; // steps + 1
  17754. var offset = vlen * layer;
  17755. // Bottom faces
  17756. for ( i = 0; i < flen; i ++ ) {
  17757. face = faces[ i ];
  17758. f3( face[ 2 ] + offset, face[ 1 ] + offset, face[ 0 ] + offset );
  17759. }
  17760. layer = steps + bevelSegments * 2;
  17761. offset = vlen * layer;
  17762. // Top faces
  17763. for ( i = 0; i < flen; i ++ ) {
  17764. face = faces[ i ];
  17765. f3( face[ 0 ] + offset, face[ 1 ] + offset, face[ 2 ] + offset );
  17766. }
  17767. } else {
  17768. // Bottom faces
  17769. for ( i = 0; i < flen; i ++ ) {
  17770. face = faces[ i ];
  17771. f3( face[ 2 ], face[ 1 ], face[ 0 ] );
  17772. }
  17773. // Top faces
  17774. for ( i = 0; i < flen; i ++ ) {
  17775. face = faces[ i ];
  17776. f3( face[ 0 ] + vlen * steps, face[ 1 ] + vlen * steps, face[ 2 ] + vlen * steps );
  17777. }
  17778. }
  17779. scope.addGroup( start, verticesArray.length / 3 - start, 0 );
  17780. }
  17781. // Create faces for the z-sides of the shape
  17782. function buildSideFaces() {
  17783. var start = verticesArray.length / 3;
  17784. var layeroffset = 0;
  17785. sidewalls( contour, layeroffset );
  17786. layeroffset += contour.length;
  17787. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  17788. ahole = holes[ h ];
  17789. sidewalls( ahole, layeroffset );
  17790. //, true
  17791. layeroffset += ahole.length;
  17792. }
  17793. scope.addGroup( start, verticesArray.length / 3 - start, 1 );
  17794. }
  17795. function sidewalls( contour, layeroffset ) {
  17796. var j, k;
  17797. i = contour.length;
  17798. while ( -- i >= 0 ) {
  17799. j = i;
  17800. k = i - 1;
  17801. if ( k < 0 ) k = contour.length - 1;
  17802. //console.log('b', i,j, i-1, k,vertices.length);
  17803. var s = 0,
  17804. sl = steps + bevelSegments * 2;
  17805. for ( s = 0; s < sl; s ++ ) {
  17806. var slen1 = vlen * s;
  17807. var slen2 = vlen * ( s + 1 );
  17808. var a = layeroffset + j + slen1,
  17809. b = layeroffset + k + slen1,
  17810. c = layeroffset + k + slen2,
  17811. d = layeroffset + j + slen2;
  17812. f4( a, b, c, d );
  17813. }
  17814. }
  17815. }
  17816. function v( x, y, z ) {
  17817. placeholder.push( x );
  17818. placeholder.push( y );
  17819. placeholder.push( z );
  17820. }
  17821. function f3( a, b, c ) {
  17822. addVertex( a );
  17823. addVertex( b );
  17824. addVertex( c );
  17825. var nextIndex = verticesArray.length / 3;
  17826. var uvs = uvgen.generateTopUV( scope, verticesArray, nextIndex - 3, nextIndex - 2, nextIndex - 1 );
  17827. addUV( uvs[ 0 ] );
  17828. addUV( uvs[ 1 ] );
  17829. addUV( uvs[ 2 ] );
  17830. }
  17831. function f4( a, b, c, d ) {
  17832. addVertex( a );
  17833. addVertex( b );
  17834. addVertex( d );
  17835. addVertex( b );
  17836. addVertex( c );
  17837. addVertex( d );
  17838. var nextIndex = verticesArray.length / 3;
  17839. var uvs = uvgen.generateSideWallUV( scope, verticesArray, nextIndex - 6, nextIndex - 3, nextIndex - 2, nextIndex - 1 );
  17840. addUV( uvs[ 0 ] );
  17841. addUV( uvs[ 1 ] );
  17842. addUV( uvs[ 3 ] );
  17843. addUV( uvs[ 1 ] );
  17844. addUV( uvs[ 2 ] );
  17845. addUV( uvs[ 3 ] );
  17846. }
  17847. function addVertex( index ) {
  17848. verticesArray.push( placeholder[ index * 3 + 0 ] );
  17849. verticesArray.push( placeholder[ index * 3 + 1 ] );
  17850. verticesArray.push( placeholder[ index * 3 + 2 ] );
  17851. }
  17852. function addUV( vector2 ) {
  17853. uvArray.push( vector2.x );
  17854. uvArray.push( vector2.y );
  17855. }
  17856. }
  17857. }
  17858. ExtrudeBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  17859. ExtrudeBufferGeometry.prototype.constructor = ExtrudeBufferGeometry;
  17860. ExtrudeBufferGeometry.prototype.toJSON = function () {
  17861. var data = BufferGeometry.prototype.toJSON.call( this );
  17862. var shapes = this.parameters.shapes;
  17863. var options = this.parameters.options;
  17864. return toJSON( shapes, options, data );
  17865. };
  17866. //
  17867. var WorldUVGenerator = {
  17868. generateTopUV: function ( geometry, vertices, indexA, indexB, indexC ) {
  17869. var a_x = vertices[ indexA * 3 ];
  17870. var a_y = vertices[ indexA * 3 + 1 ];
  17871. var b_x = vertices[ indexB * 3 ];
  17872. var b_y = vertices[ indexB * 3 + 1 ];
  17873. var c_x = vertices[ indexC * 3 ];
  17874. var c_y = vertices[ indexC * 3 + 1 ];
  17875. return [
  17876. new Vector2( a_x, a_y ),
  17877. new Vector2( b_x, b_y ),
  17878. new Vector2( c_x, c_y )
  17879. ];
  17880. },
  17881. generateSideWallUV: function ( geometry, vertices, indexA, indexB, indexC, indexD ) {
  17882. var a_x = vertices[ indexA * 3 ];
  17883. var a_y = vertices[ indexA * 3 + 1 ];
  17884. var a_z = vertices[ indexA * 3 + 2 ];
  17885. var b_x = vertices[ indexB * 3 ];
  17886. var b_y = vertices[ indexB * 3 + 1 ];
  17887. var b_z = vertices[ indexB * 3 + 2 ];
  17888. var c_x = vertices[ indexC * 3 ];
  17889. var c_y = vertices[ indexC * 3 + 1 ];
  17890. var c_z = vertices[ indexC * 3 + 2 ];
  17891. var d_x = vertices[ indexD * 3 ];
  17892. var d_y = vertices[ indexD * 3 + 1 ];
  17893. var d_z = vertices[ indexD * 3 + 2 ];
  17894. if ( Math.abs( a_y - b_y ) < 0.01 ) {
  17895. return [
  17896. new Vector2( a_x, 1 - a_z ),
  17897. new Vector2( b_x, 1 - b_z ),
  17898. new Vector2( c_x, 1 - c_z ),
  17899. new Vector2( d_x, 1 - d_z )
  17900. ];
  17901. } else {
  17902. return [
  17903. new Vector2( a_y, 1 - a_z ),
  17904. new Vector2( b_y, 1 - b_z ),
  17905. new Vector2( c_y, 1 - c_z ),
  17906. new Vector2( d_y, 1 - d_z )
  17907. ];
  17908. }
  17909. }
  17910. };
  17911. function toJSON( shapes, options, data ) {
  17912. //
  17913. data.shapes = [];
  17914. if ( Array.isArray( shapes ) ) {
  17915. for ( var i = 0, l = shapes.length; i < l; i ++ ) {
  17916. var shape = shapes[ i ];
  17917. data.shapes.push( shape.uuid );
  17918. }
  17919. } else {
  17920. data.shapes.push( shapes.uuid );
  17921. }
  17922. //
  17923. if ( options.extrudePath !== undefined ) data.options.extrudePath = options.extrudePath.toJSON();
  17924. return data;
  17925. }
  17926. /**
  17927. * @author zz85 / http://www.lab4games.net/zz85/blog
  17928. * @author alteredq / http://alteredqualia.com/
  17929. *
  17930. * Text = 3D Text
  17931. *
  17932. * parameters = {
  17933. * font: <THREE.Font>, // font
  17934. *
  17935. * size: <float>, // size of the text
  17936. * height: <float>, // thickness to extrude text
  17937. * curveSegments: <int>, // number of points on the curves
  17938. *
  17939. * bevelEnabled: <bool>, // turn on bevel
  17940. * bevelThickness: <float>, // how deep into text bevel goes
  17941. * bevelSize: <float>, // how far from text outline (including bevelOffset) is bevel
  17942. * bevelOffset: <float> // how far from text outline does bevel start
  17943. * }
  17944. */
  17945. // TextGeometry
  17946. function TextGeometry( text, parameters ) {
  17947. Geometry.call( this );
  17948. this.type = 'TextGeometry';
  17949. this.parameters = {
  17950. text: text,
  17951. parameters: parameters
  17952. };
  17953. this.fromBufferGeometry( new TextBufferGeometry( text, parameters ) );
  17954. this.mergeVertices();
  17955. }
  17956. TextGeometry.prototype = Object.create( Geometry.prototype );
  17957. TextGeometry.prototype.constructor = TextGeometry;
  17958. // TextBufferGeometry
  17959. function TextBufferGeometry( text, parameters ) {
  17960. parameters = parameters || {};
  17961. var font = parameters.font;
  17962. if ( ! ( font && font.isFont ) ) {
  17963. console.error( 'THREE.TextGeometry: font parameter is not an instance of THREE.Font.' );
  17964. return new Geometry();
  17965. }
  17966. var shapes = font.generateShapes( text, parameters.size );
  17967. // translate parameters to ExtrudeGeometry API
  17968. parameters.depth = parameters.height !== undefined ? parameters.height : 50;
  17969. // defaults
  17970. if ( parameters.bevelThickness === undefined ) parameters.bevelThickness = 10;
  17971. if ( parameters.bevelSize === undefined ) parameters.bevelSize = 8;
  17972. if ( parameters.bevelEnabled === undefined ) parameters.bevelEnabled = false;
  17973. ExtrudeBufferGeometry.call( this, shapes, parameters );
  17974. this.type = 'TextBufferGeometry';
  17975. }
  17976. TextBufferGeometry.prototype = Object.create( ExtrudeBufferGeometry.prototype );
  17977. TextBufferGeometry.prototype.constructor = TextBufferGeometry;
  17978. /**
  17979. * @author mrdoob / http://mrdoob.com/
  17980. * @author benaadams / https://twitter.com/ben_a_adams
  17981. * @author Mugen87 / https://github.com/Mugen87
  17982. */
  17983. // SphereGeometry
  17984. function SphereGeometry( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) {
  17985. Geometry.call( this );
  17986. this.type = 'SphereGeometry';
  17987. this.parameters = {
  17988. radius: radius,
  17989. widthSegments: widthSegments,
  17990. heightSegments: heightSegments,
  17991. phiStart: phiStart,
  17992. phiLength: phiLength,
  17993. thetaStart: thetaStart,
  17994. thetaLength: thetaLength
  17995. };
  17996. this.fromBufferGeometry( new SphereBufferGeometry( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) );
  17997. this.mergeVertices();
  17998. }
  17999. SphereGeometry.prototype = Object.create( Geometry.prototype );
  18000. SphereGeometry.prototype.constructor = SphereGeometry;
  18001. // SphereBufferGeometry
  18002. function SphereBufferGeometry( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) {
  18003. BufferGeometry.call( this );
  18004. this.type = 'SphereBufferGeometry';
  18005. this.parameters = {
  18006. radius: radius,
  18007. widthSegments: widthSegments,
  18008. heightSegments: heightSegments,
  18009. phiStart: phiStart,
  18010. phiLength: phiLength,
  18011. thetaStart: thetaStart,
  18012. thetaLength: thetaLength
  18013. };
  18014. radius = radius || 1;
  18015. widthSegments = Math.max( 3, Math.floor( widthSegments ) || 8 );
  18016. heightSegments = Math.max( 2, Math.floor( heightSegments ) || 6 );
  18017. phiStart = phiStart !== undefined ? phiStart : 0;
  18018. phiLength = phiLength !== undefined ? phiLength : Math.PI * 2;
  18019. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  18020. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI;
  18021. var thetaEnd = thetaStart + thetaLength;
  18022. var ix, iy;
  18023. var index = 0;
  18024. var grid = [];
  18025. var vertex = new Vector3();
  18026. var normal = new Vector3();
  18027. // buffers
  18028. var indices = [];
  18029. var vertices = [];
  18030. var normals = [];
  18031. var uvs = [];
  18032. // generate vertices, normals and uvs
  18033. for ( iy = 0; iy <= heightSegments; iy ++ ) {
  18034. var verticesRow = [];
  18035. var v = iy / heightSegments;
  18036. // special case for the poles
  18037. var uOffset = ( iy == 0 ) ? 0.5 / widthSegments : ( ( iy == heightSegments ) ? - 0.5 / widthSegments : 0 );
  18038. for ( ix = 0; ix <= widthSegments; ix ++ ) {
  18039. var u = ix / widthSegments;
  18040. // vertex
  18041. vertex.x = - radius * Math.cos( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  18042. vertex.y = radius * Math.cos( thetaStart + v * thetaLength );
  18043. vertex.z = radius * Math.sin( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  18044. vertices.push( vertex.x, vertex.y, vertex.z );
  18045. // normal
  18046. normal.copy( vertex ).normalize();
  18047. normals.push( normal.x, normal.y, normal.z );
  18048. // uv
  18049. uvs.push( u + uOffset, 1 - v );
  18050. verticesRow.push( index ++ );
  18051. }
  18052. grid.push( verticesRow );
  18053. }
  18054. // indices
  18055. for ( iy = 0; iy < heightSegments; iy ++ ) {
  18056. for ( ix = 0; ix < widthSegments; ix ++ ) {
  18057. var a = grid[ iy ][ ix + 1 ];
  18058. var b = grid[ iy ][ ix ];
  18059. var c = grid[ iy + 1 ][ ix ];
  18060. var d = grid[ iy + 1 ][ ix + 1 ];
  18061. if ( iy !== 0 || thetaStart > 0 ) indices.push( a, b, d );
  18062. if ( iy !== heightSegments - 1 || thetaEnd < Math.PI ) indices.push( b, c, d );
  18063. }
  18064. }
  18065. // build geometry
  18066. this.setIndex( indices );
  18067. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  18068. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  18069. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  18070. }
  18071. SphereBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  18072. SphereBufferGeometry.prototype.constructor = SphereBufferGeometry;
  18073. /**
  18074. * @author Kaleb Murphy
  18075. * @author Mugen87 / https://github.com/Mugen87
  18076. */
  18077. // RingGeometry
  18078. function RingGeometry( innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength ) {
  18079. Geometry.call( this );
  18080. this.type = 'RingGeometry';
  18081. this.parameters = {
  18082. innerRadius: innerRadius,
  18083. outerRadius: outerRadius,
  18084. thetaSegments: thetaSegments,
  18085. phiSegments: phiSegments,
  18086. thetaStart: thetaStart,
  18087. thetaLength: thetaLength
  18088. };
  18089. this.fromBufferGeometry( new RingBufferGeometry( innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength ) );
  18090. this.mergeVertices();
  18091. }
  18092. RingGeometry.prototype = Object.create( Geometry.prototype );
  18093. RingGeometry.prototype.constructor = RingGeometry;
  18094. // RingBufferGeometry
  18095. function RingBufferGeometry( innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength ) {
  18096. BufferGeometry.call( this );
  18097. this.type = 'RingBufferGeometry';
  18098. this.parameters = {
  18099. innerRadius: innerRadius,
  18100. outerRadius: outerRadius,
  18101. thetaSegments: thetaSegments,
  18102. phiSegments: phiSegments,
  18103. thetaStart: thetaStart,
  18104. thetaLength: thetaLength
  18105. };
  18106. innerRadius = innerRadius || 0.5;
  18107. outerRadius = outerRadius || 1;
  18108. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  18109. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  18110. thetaSegments = thetaSegments !== undefined ? Math.max( 3, thetaSegments ) : 8;
  18111. phiSegments = phiSegments !== undefined ? Math.max( 1, phiSegments ) : 1;
  18112. // buffers
  18113. var indices = [];
  18114. var vertices = [];
  18115. var normals = [];
  18116. var uvs = [];
  18117. // some helper variables
  18118. var segment;
  18119. var radius = innerRadius;
  18120. var radiusStep = ( ( outerRadius - innerRadius ) / phiSegments );
  18121. var vertex = new Vector3();
  18122. var uv = new Vector2();
  18123. var j, i;
  18124. // generate vertices, normals and uvs
  18125. for ( j = 0; j <= phiSegments; j ++ ) {
  18126. for ( i = 0; i <= thetaSegments; i ++ ) {
  18127. // values are generate from the inside of the ring to the outside
  18128. segment = thetaStart + i / thetaSegments * thetaLength;
  18129. // vertex
  18130. vertex.x = radius * Math.cos( segment );
  18131. vertex.y = radius * Math.sin( segment );
  18132. vertices.push( vertex.x, vertex.y, vertex.z );
  18133. // normal
  18134. normals.push( 0, 0, 1 );
  18135. // uv
  18136. uv.x = ( vertex.x / outerRadius + 1 ) / 2;
  18137. uv.y = ( vertex.y / outerRadius + 1 ) / 2;
  18138. uvs.push( uv.x, uv.y );
  18139. }
  18140. // increase the radius for next row of vertices
  18141. radius += radiusStep;
  18142. }
  18143. // indices
  18144. for ( j = 0; j < phiSegments; j ++ ) {
  18145. var thetaSegmentLevel = j * ( thetaSegments + 1 );
  18146. for ( i = 0; i < thetaSegments; i ++ ) {
  18147. segment = i + thetaSegmentLevel;
  18148. var a = segment;
  18149. var b = segment + thetaSegments + 1;
  18150. var c = segment + thetaSegments + 2;
  18151. var d = segment + 1;
  18152. // faces
  18153. indices.push( a, b, d );
  18154. indices.push( b, c, d );
  18155. }
  18156. }
  18157. // build geometry
  18158. this.setIndex( indices );
  18159. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  18160. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  18161. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  18162. }
  18163. RingBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  18164. RingBufferGeometry.prototype.constructor = RingBufferGeometry;
  18165. /**
  18166. * @author zz85 / https://github.com/zz85
  18167. * @author bhouston / http://clara.io
  18168. * @author Mugen87 / https://github.com/Mugen87
  18169. */
  18170. // LatheGeometry
  18171. function LatheGeometry( points, segments, phiStart, phiLength ) {
  18172. Geometry.call( this );
  18173. this.type = 'LatheGeometry';
  18174. this.parameters = {
  18175. points: points,
  18176. segments: segments,
  18177. phiStart: phiStart,
  18178. phiLength: phiLength
  18179. };
  18180. this.fromBufferGeometry( new LatheBufferGeometry( points, segments, phiStart, phiLength ) );
  18181. this.mergeVertices();
  18182. }
  18183. LatheGeometry.prototype = Object.create( Geometry.prototype );
  18184. LatheGeometry.prototype.constructor = LatheGeometry;
  18185. // LatheBufferGeometry
  18186. function LatheBufferGeometry( points, segments, phiStart, phiLength ) {
  18187. BufferGeometry.call( this );
  18188. this.type = 'LatheBufferGeometry';
  18189. this.parameters = {
  18190. points: points,
  18191. segments: segments,
  18192. phiStart: phiStart,
  18193. phiLength: phiLength
  18194. };
  18195. segments = Math.floor( segments ) || 12;
  18196. phiStart = phiStart || 0;
  18197. phiLength = phiLength || Math.PI * 2;
  18198. // clamp phiLength so it's in range of [ 0, 2PI ]
  18199. phiLength = _Math.clamp( phiLength, 0, Math.PI * 2 );
  18200. // buffers
  18201. var indices = [];
  18202. var vertices = [];
  18203. var uvs = [];
  18204. // helper variables
  18205. var base;
  18206. var inverseSegments = 1.0 / segments;
  18207. var vertex = new Vector3();
  18208. var uv = new Vector2();
  18209. var i, j;
  18210. // generate vertices and uvs
  18211. for ( i = 0; i <= segments; i ++ ) {
  18212. var phi = phiStart + i * inverseSegments * phiLength;
  18213. var sin = Math.sin( phi );
  18214. var cos = Math.cos( phi );
  18215. for ( j = 0; j <= ( points.length - 1 ); j ++ ) {
  18216. // vertex
  18217. vertex.x = points[ j ].x * sin;
  18218. vertex.y = points[ j ].y;
  18219. vertex.z = points[ j ].x * cos;
  18220. vertices.push( vertex.x, vertex.y, vertex.z );
  18221. // uv
  18222. uv.x = i / segments;
  18223. uv.y = j / ( points.length - 1 );
  18224. uvs.push( uv.x, uv.y );
  18225. }
  18226. }
  18227. // indices
  18228. for ( i = 0; i < segments; i ++ ) {
  18229. for ( j = 0; j < ( points.length - 1 ); j ++ ) {
  18230. base = j + i * points.length;
  18231. var a = base;
  18232. var b = base + points.length;
  18233. var c = base + points.length + 1;
  18234. var d = base + 1;
  18235. // faces
  18236. indices.push( a, b, d );
  18237. indices.push( b, c, d );
  18238. }
  18239. }
  18240. // build geometry
  18241. this.setIndex( indices );
  18242. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  18243. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  18244. // generate normals
  18245. this.computeVertexNormals();
  18246. // if the geometry is closed, we need to average the normals along the seam.
  18247. // because the corresponding vertices are identical (but still have different UVs).
  18248. if ( phiLength === Math.PI * 2 ) {
  18249. var normals = this.attributes.normal.array;
  18250. var n1 = new Vector3();
  18251. var n2 = new Vector3();
  18252. var n = new Vector3();
  18253. // this is the buffer offset for the last line of vertices
  18254. base = segments * points.length * 3;
  18255. for ( i = 0, j = 0; i < points.length; i ++, j += 3 ) {
  18256. // select the normal of the vertex in the first line
  18257. n1.x = normals[ j + 0 ];
  18258. n1.y = normals[ j + 1 ];
  18259. n1.z = normals[ j + 2 ];
  18260. // select the normal of the vertex in the last line
  18261. n2.x = normals[ base + j + 0 ];
  18262. n2.y = normals[ base + j + 1 ];
  18263. n2.z = normals[ base + j + 2 ];
  18264. // average normals
  18265. n.addVectors( n1, n2 ).normalize();
  18266. // assign the new values to both normals
  18267. normals[ j + 0 ] = normals[ base + j + 0 ] = n.x;
  18268. normals[ j + 1 ] = normals[ base + j + 1 ] = n.y;
  18269. normals[ j + 2 ] = normals[ base + j + 2 ] = n.z;
  18270. }
  18271. }
  18272. }
  18273. LatheBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  18274. LatheBufferGeometry.prototype.constructor = LatheBufferGeometry;
  18275. /**
  18276. * @author jonobr1 / http://jonobr1.com
  18277. * @author Mugen87 / https://github.com/Mugen87
  18278. */
  18279. // ShapeGeometry
  18280. function ShapeGeometry( shapes, curveSegments ) {
  18281. Geometry.call( this );
  18282. this.type = 'ShapeGeometry';
  18283. if ( typeof curveSegments === 'object' ) {
  18284. console.warn( 'THREE.ShapeGeometry: Options parameter has been removed.' );
  18285. curveSegments = curveSegments.curveSegments;
  18286. }
  18287. this.parameters = {
  18288. shapes: shapes,
  18289. curveSegments: curveSegments
  18290. };
  18291. this.fromBufferGeometry( new ShapeBufferGeometry( shapes, curveSegments ) );
  18292. this.mergeVertices();
  18293. }
  18294. ShapeGeometry.prototype = Object.create( Geometry.prototype );
  18295. ShapeGeometry.prototype.constructor = ShapeGeometry;
  18296. ShapeGeometry.prototype.toJSON = function () {
  18297. var data = Geometry.prototype.toJSON.call( this );
  18298. var shapes = this.parameters.shapes;
  18299. return toJSON$1( shapes, data );
  18300. };
  18301. // ShapeBufferGeometry
  18302. function ShapeBufferGeometry( shapes, curveSegments ) {
  18303. BufferGeometry.call( this );
  18304. this.type = 'ShapeBufferGeometry';
  18305. this.parameters = {
  18306. shapes: shapes,
  18307. curveSegments: curveSegments
  18308. };
  18309. curveSegments = curveSegments || 12;
  18310. // buffers
  18311. var indices = [];
  18312. var vertices = [];
  18313. var normals = [];
  18314. var uvs = [];
  18315. // helper variables
  18316. var groupStart = 0;
  18317. var groupCount = 0;
  18318. // allow single and array values for "shapes" parameter
  18319. if ( Array.isArray( shapes ) === false ) {
  18320. addShape( shapes );
  18321. } else {
  18322. for ( var i = 0; i < shapes.length; i ++ ) {
  18323. addShape( shapes[ i ] );
  18324. this.addGroup( groupStart, groupCount, i ); // enables MultiMaterial support
  18325. groupStart += groupCount;
  18326. groupCount = 0;
  18327. }
  18328. }
  18329. // build geometry
  18330. this.setIndex( indices );
  18331. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  18332. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  18333. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  18334. // helper functions
  18335. function addShape( shape ) {
  18336. var i, l, shapeHole;
  18337. var indexOffset = vertices.length / 3;
  18338. var points = shape.extractPoints( curveSegments );
  18339. var shapeVertices = points.shape;
  18340. var shapeHoles = points.holes;
  18341. // check direction of vertices
  18342. if ( ShapeUtils.isClockWise( shapeVertices ) === false ) {
  18343. shapeVertices = shapeVertices.reverse();
  18344. }
  18345. for ( i = 0, l = shapeHoles.length; i < l; i ++ ) {
  18346. shapeHole = shapeHoles[ i ];
  18347. if ( ShapeUtils.isClockWise( shapeHole ) === true ) {
  18348. shapeHoles[ i ] = shapeHole.reverse();
  18349. }
  18350. }
  18351. var faces = ShapeUtils.triangulateShape( shapeVertices, shapeHoles );
  18352. // join vertices of inner and outer paths to a single array
  18353. for ( i = 0, l = shapeHoles.length; i < l; i ++ ) {
  18354. shapeHole = shapeHoles[ i ];
  18355. shapeVertices = shapeVertices.concat( shapeHole );
  18356. }
  18357. // vertices, normals, uvs
  18358. for ( i = 0, l = shapeVertices.length; i < l; i ++ ) {
  18359. var vertex = shapeVertices[ i ];
  18360. vertices.push( vertex.x, vertex.y, 0 );
  18361. normals.push( 0, 0, 1 );
  18362. uvs.push( vertex.x, vertex.y ); // world uvs
  18363. }
  18364. // incides
  18365. for ( i = 0, l = faces.length; i < l; i ++ ) {
  18366. var face = faces[ i ];
  18367. var a = face[ 0 ] + indexOffset;
  18368. var b = face[ 1 ] + indexOffset;
  18369. var c = face[ 2 ] + indexOffset;
  18370. indices.push( a, b, c );
  18371. groupCount += 3;
  18372. }
  18373. }
  18374. }
  18375. ShapeBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  18376. ShapeBufferGeometry.prototype.constructor = ShapeBufferGeometry;
  18377. ShapeBufferGeometry.prototype.toJSON = function () {
  18378. var data = BufferGeometry.prototype.toJSON.call( this );
  18379. var shapes = this.parameters.shapes;
  18380. return toJSON$1( shapes, data );
  18381. };
  18382. //
  18383. function toJSON$1( shapes, data ) {
  18384. data.shapes = [];
  18385. if ( Array.isArray( shapes ) ) {
  18386. for ( var i = 0, l = shapes.length; i < l; i ++ ) {
  18387. var shape = shapes[ i ];
  18388. data.shapes.push( shape.uuid );
  18389. }
  18390. } else {
  18391. data.shapes.push( shapes.uuid );
  18392. }
  18393. return data;
  18394. }
  18395. /**
  18396. * @author WestLangley / http://github.com/WestLangley
  18397. * @author Mugen87 / https://github.com/Mugen87
  18398. */
  18399. function EdgesGeometry( geometry, thresholdAngle ) {
  18400. BufferGeometry.call( this );
  18401. this.type = 'EdgesGeometry';
  18402. this.parameters = {
  18403. thresholdAngle: thresholdAngle
  18404. };
  18405. thresholdAngle = ( thresholdAngle !== undefined ) ? thresholdAngle : 1;
  18406. // buffer
  18407. var vertices = [];
  18408. // helper variables
  18409. var thresholdDot = Math.cos( _Math.DEG2RAD * thresholdAngle );
  18410. var edge = [ 0, 0 ], edges = {}, edge1, edge2;
  18411. var key, keys = [ 'a', 'b', 'c' ];
  18412. // prepare source geometry
  18413. var geometry2;
  18414. if ( geometry.isBufferGeometry ) {
  18415. geometry2 = new Geometry();
  18416. geometry2.fromBufferGeometry( geometry );
  18417. } else {
  18418. geometry2 = geometry.clone();
  18419. }
  18420. geometry2.mergeVertices();
  18421. geometry2.computeFaceNormals();
  18422. var sourceVertices = geometry2.vertices;
  18423. var faces = geometry2.faces;
  18424. // now create a data structure where each entry represents an edge with its adjoining faces
  18425. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  18426. var face = faces[ i ];
  18427. for ( var j = 0; j < 3; j ++ ) {
  18428. edge1 = face[ keys[ j ] ];
  18429. edge2 = face[ keys[ ( j + 1 ) % 3 ] ];
  18430. edge[ 0 ] = Math.min( edge1, edge2 );
  18431. edge[ 1 ] = Math.max( edge1, edge2 );
  18432. key = edge[ 0 ] + ',' + edge[ 1 ];
  18433. if ( edges[ key ] === undefined ) {
  18434. edges[ key ] = { index1: edge[ 0 ], index2: edge[ 1 ], face1: i, face2: undefined };
  18435. } else {
  18436. edges[ key ].face2 = i;
  18437. }
  18438. }
  18439. }
  18440. // generate vertices
  18441. for ( key in edges ) {
  18442. var e = edges[ key ];
  18443. // an edge is only rendered if the angle (in degrees) between the face normals of the adjoining faces exceeds this value. default = 1 degree.
  18444. if ( e.face2 === undefined || faces[ e.face1 ].normal.dot( faces[ e.face2 ].normal ) <= thresholdDot ) {
  18445. var vertex = sourceVertices[ e.index1 ];
  18446. vertices.push( vertex.x, vertex.y, vertex.z );
  18447. vertex = sourceVertices[ e.index2 ];
  18448. vertices.push( vertex.x, vertex.y, vertex.z );
  18449. }
  18450. }
  18451. // build geometry
  18452. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  18453. }
  18454. EdgesGeometry.prototype = Object.create( BufferGeometry.prototype );
  18455. EdgesGeometry.prototype.constructor = EdgesGeometry;
  18456. /**
  18457. * @author mrdoob / http://mrdoob.com/
  18458. * @author Mugen87 / https://github.com/Mugen87
  18459. */
  18460. // CylinderGeometry
  18461. function CylinderGeometry( radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  18462. Geometry.call( this );
  18463. this.type = 'CylinderGeometry';
  18464. this.parameters = {
  18465. radiusTop: radiusTop,
  18466. radiusBottom: radiusBottom,
  18467. height: height,
  18468. radialSegments: radialSegments,
  18469. heightSegments: heightSegments,
  18470. openEnded: openEnded,
  18471. thetaStart: thetaStart,
  18472. thetaLength: thetaLength
  18473. };
  18474. this.fromBufferGeometry( new CylinderBufferGeometry( radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) );
  18475. this.mergeVertices();
  18476. }
  18477. CylinderGeometry.prototype = Object.create( Geometry.prototype );
  18478. CylinderGeometry.prototype.constructor = CylinderGeometry;
  18479. // CylinderBufferGeometry
  18480. function CylinderBufferGeometry( radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  18481. BufferGeometry.call( this );
  18482. this.type = 'CylinderBufferGeometry';
  18483. this.parameters = {
  18484. radiusTop: radiusTop,
  18485. radiusBottom: radiusBottom,
  18486. height: height,
  18487. radialSegments: radialSegments,
  18488. heightSegments: heightSegments,
  18489. openEnded: openEnded,
  18490. thetaStart: thetaStart,
  18491. thetaLength: thetaLength
  18492. };
  18493. var scope = this;
  18494. radiusTop = radiusTop !== undefined ? radiusTop : 1;
  18495. radiusBottom = radiusBottom !== undefined ? radiusBottom : 1;
  18496. height = height || 1;
  18497. radialSegments = Math.floor( radialSegments ) || 8;
  18498. heightSegments = Math.floor( heightSegments ) || 1;
  18499. openEnded = openEnded !== undefined ? openEnded : false;
  18500. thetaStart = thetaStart !== undefined ? thetaStart : 0.0;
  18501. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  18502. // buffers
  18503. var indices = [];
  18504. var vertices = [];
  18505. var normals = [];
  18506. var uvs = [];
  18507. // helper variables
  18508. var index = 0;
  18509. var indexArray = [];
  18510. var halfHeight = height / 2;
  18511. var groupStart = 0;
  18512. // generate geometry
  18513. generateTorso();
  18514. if ( openEnded === false ) {
  18515. if ( radiusTop > 0 ) generateCap( true );
  18516. if ( radiusBottom > 0 ) generateCap( false );
  18517. }
  18518. // build geometry
  18519. this.setIndex( indices );
  18520. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  18521. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  18522. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  18523. function generateTorso() {
  18524. var x, y;
  18525. var normal = new Vector3();
  18526. var vertex = new Vector3();
  18527. var groupCount = 0;
  18528. // this will be used to calculate the normal
  18529. var slope = ( radiusBottom - radiusTop ) / height;
  18530. // generate vertices, normals and uvs
  18531. for ( y = 0; y <= heightSegments; y ++ ) {
  18532. var indexRow = [];
  18533. var v = y / heightSegments;
  18534. // calculate the radius of the current row
  18535. var radius = v * ( radiusBottom - radiusTop ) + radiusTop;
  18536. for ( x = 0; x <= radialSegments; x ++ ) {
  18537. var u = x / radialSegments;
  18538. var theta = u * thetaLength + thetaStart;
  18539. var sinTheta = Math.sin( theta );
  18540. var cosTheta = Math.cos( theta );
  18541. // vertex
  18542. vertex.x = radius * sinTheta;
  18543. vertex.y = - v * height + halfHeight;
  18544. vertex.z = radius * cosTheta;
  18545. vertices.push( vertex.x, vertex.y, vertex.z );
  18546. // normal
  18547. normal.set( sinTheta, slope, cosTheta ).normalize();
  18548. normals.push( normal.x, normal.y, normal.z );
  18549. // uv
  18550. uvs.push( u, 1 - v );
  18551. // save index of vertex in respective row
  18552. indexRow.push( index ++ );
  18553. }
  18554. // now save vertices of the row in our index array
  18555. indexArray.push( indexRow );
  18556. }
  18557. // generate indices
  18558. for ( x = 0; x < radialSegments; x ++ ) {
  18559. for ( y = 0; y < heightSegments; y ++ ) {
  18560. // we use the index array to access the correct indices
  18561. var a = indexArray[ y ][ x ];
  18562. var b = indexArray[ y + 1 ][ x ];
  18563. var c = indexArray[ y + 1 ][ x + 1 ];
  18564. var d = indexArray[ y ][ x + 1 ];
  18565. // faces
  18566. indices.push( a, b, d );
  18567. indices.push( b, c, d );
  18568. // update group counter
  18569. groupCount += 6;
  18570. }
  18571. }
  18572. // add a group to the geometry. this will ensure multi material support
  18573. scope.addGroup( groupStart, groupCount, 0 );
  18574. // calculate new start value for groups
  18575. groupStart += groupCount;
  18576. }
  18577. function generateCap( top ) {
  18578. var x, centerIndexStart, centerIndexEnd;
  18579. var uv = new Vector2();
  18580. var vertex = new Vector3();
  18581. var groupCount = 0;
  18582. var radius = ( top === true ) ? radiusTop : radiusBottom;
  18583. var sign = ( top === true ) ? 1 : - 1;
  18584. // save the index of the first center vertex
  18585. centerIndexStart = index;
  18586. // first we generate the center vertex data of the cap.
  18587. // because the geometry needs one set of uvs per face,
  18588. // we must generate a center vertex per face/segment
  18589. for ( x = 1; x <= radialSegments; x ++ ) {
  18590. // vertex
  18591. vertices.push( 0, halfHeight * sign, 0 );
  18592. // normal
  18593. normals.push( 0, sign, 0 );
  18594. // uv
  18595. uvs.push( 0.5, 0.5 );
  18596. // increase index
  18597. index ++;
  18598. }
  18599. // save the index of the last center vertex
  18600. centerIndexEnd = index;
  18601. // now we generate the surrounding vertices, normals and uvs
  18602. for ( x = 0; x <= radialSegments; x ++ ) {
  18603. var u = x / radialSegments;
  18604. var theta = u * thetaLength + thetaStart;
  18605. var cosTheta = Math.cos( theta );
  18606. var sinTheta = Math.sin( theta );
  18607. // vertex
  18608. vertex.x = radius * sinTheta;
  18609. vertex.y = halfHeight * sign;
  18610. vertex.z = radius * cosTheta;
  18611. vertices.push( vertex.x, vertex.y, vertex.z );
  18612. // normal
  18613. normals.push( 0, sign, 0 );
  18614. // uv
  18615. uv.x = ( cosTheta * 0.5 ) + 0.5;
  18616. uv.y = ( sinTheta * 0.5 * sign ) + 0.5;
  18617. uvs.push( uv.x, uv.y );
  18618. // increase index
  18619. index ++;
  18620. }
  18621. // generate indices
  18622. for ( x = 0; x < radialSegments; x ++ ) {
  18623. var c = centerIndexStart + x;
  18624. var i = centerIndexEnd + x;
  18625. if ( top === true ) {
  18626. // face top
  18627. indices.push( i, i + 1, c );
  18628. } else {
  18629. // face bottom
  18630. indices.push( i + 1, i, c );
  18631. }
  18632. groupCount += 3;
  18633. }
  18634. // add a group to the geometry. this will ensure multi material support
  18635. scope.addGroup( groupStart, groupCount, top === true ? 1 : 2 );
  18636. // calculate new start value for groups
  18637. groupStart += groupCount;
  18638. }
  18639. }
  18640. CylinderBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  18641. CylinderBufferGeometry.prototype.constructor = CylinderBufferGeometry;
  18642. /**
  18643. * @author abelnation / http://github.com/abelnation
  18644. */
  18645. // ConeGeometry
  18646. function ConeGeometry( radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  18647. CylinderGeometry.call( this, 0, radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength );
  18648. this.type = 'ConeGeometry';
  18649. this.parameters = {
  18650. radius: radius,
  18651. height: height,
  18652. radialSegments: radialSegments,
  18653. heightSegments: heightSegments,
  18654. openEnded: openEnded,
  18655. thetaStart: thetaStart,
  18656. thetaLength: thetaLength
  18657. };
  18658. }
  18659. ConeGeometry.prototype = Object.create( CylinderGeometry.prototype );
  18660. ConeGeometry.prototype.constructor = ConeGeometry;
  18661. // ConeBufferGeometry
  18662. function ConeBufferGeometry( radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  18663. CylinderBufferGeometry.call( this, 0, radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength );
  18664. this.type = 'ConeBufferGeometry';
  18665. this.parameters = {
  18666. radius: radius,
  18667. height: height,
  18668. radialSegments: radialSegments,
  18669. heightSegments: heightSegments,
  18670. openEnded: openEnded,
  18671. thetaStart: thetaStart,
  18672. thetaLength: thetaLength
  18673. };
  18674. }
  18675. ConeBufferGeometry.prototype = Object.create( CylinderBufferGeometry.prototype );
  18676. ConeBufferGeometry.prototype.constructor = ConeBufferGeometry;
  18677. /**
  18678. * @author benaadams / https://twitter.com/ben_a_adams
  18679. * @author Mugen87 / https://github.com/Mugen87
  18680. * @author hughes
  18681. */
  18682. // CircleGeometry
  18683. function CircleGeometry( radius, segments, thetaStart, thetaLength ) {
  18684. Geometry.call( this );
  18685. this.type = 'CircleGeometry';
  18686. this.parameters = {
  18687. radius: radius,
  18688. segments: segments,
  18689. thetaStart: thetaStart,
  18690. thetaLength: thetaLength
  18691. };
  18692. this.fromBufferGeometry( new CircleBufferGeometry( radius, segments, thetaStart, thetaLength ) );
  18693. this.mergeVertices();
  18694. }
  18695. CircleGeometry.prototype = Object.create( Geometry.prototype );
  18696. CircleGeometry.prototype.constructor = CircleGeometry;
  18697. // CircleBufferGeometry
  18698. function CircleBufferGeometry( radius, segments, thetaStart, thetaLength ) {
  18699. BufferGeometry.call( this );
  18700. this.type = 'CircleBufferGeometry';
  18701. this.parameters = {
  18702. radius: radius,
  18703. segments: segments,
  18704. thetaStart: thetaStart,
  18705. thetaLength: thetaLength
  18706. };
  18707. radius = radius || 1;
  18708. segments = segments !== undefined ? Math.max( 3, segments ) : 8;
  18709. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  18710. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  18711. // buffers
  18712. var indices = [];
  18713. var vertices = [];
  18714. var normals = [];
  18715. var uvs = [];
  18716. // helper variables
  18717. var i, s;
  18718. var vertex = new Vector3();
  18719. var uv = new Vector2();
  18720. // center point
  18721. vertices.push( 0, 0, 0 );
  18722. normals.push( 0, 0, 1 );
  18723. uvs.push( 0.5, 0.5 );
  18724. for ( s = 0, i = 3; s <= segments; s ++, i += 3 ) {
  18725. var segment = thetaStart + s / segments * thetaLength;
  18726. // vertex
  18727. vertex.x = radius * Math.cos( segment );
  18728. vertex.y = radius * Math.sin( segment );
  18729. vertices.push( vertex.x, vertex.y, vertex.z );
  18730. // normal
  18731. normals.push( 0, 0, 1 );
  18732. // uvs
  18733. uv.x = ( vertices[ i ] / radius + 1 ) / 2;
  18734. uv.y = ( vertices[ i + 1 ] / radius + 1 ) / 2;
  18735. uvs.push( uv.x, uv.y );
  18736. }
  18737. // indices
  18738. for ( i = 1; i <= segments; i ++ ) {
  18739. indices.push( i, i + 1, 0 );
  18740. }
  18741. // build geometry
  18742. this.setIndex( indices );
  18743. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  18744. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  18745. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  18746. }
  18747. CircleBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  18748. CircleBufferGeometry.prototype.constructor = CircleBufferGeometry;
  18749. var Geometries = /*#__PURE__*/Object.freeze({
  18750. WireframeGeometry: WireframeGeometry,
  18751. ParametricGeometry: ParametricGeometry,
  18752. ParametricBufferGeometry: ParametricBufferGeometry,
  18753. TetrahedronGeometry: TetrahedronGeometry,
  18754. TetrahedronBufferGeometry: TetrahedronBufferGeometry,
  18755. OctahedronGeometry: OctahedronGeometry,
  18756. OctahedronBufferGeometry: OctahedronBufferGeometry,
  18757. IcosahedronGeometry: IcosahedronGeometry,
  18758. IcosahedronBufferGeometry: IcosahedronBufferGeometry,
  18759. DodecahedronGeometry: DodecahedronGeometry,
  18760. DodecahedronBufferGeometry: DodecahedronBufferGeometry,
  18761. PolyhedronGeometry: PolyhedronGeometry,
  18762. PolyhedronBufferGeometry: PolyhedronBufferGeometry,
  18763. TubeGeometry: TubeGeometry,
  18764. TubeBufferGeometry: TubeBufferGeometry,
  18765. TorusKnotGeometry: TorusKnotGeometry,
  18766. TorusKnotBufferGeometry: TorusKnotBufferGeometry,
  18767. TorusGeometry: TorusGeometry,
  18768. TorusBufferGeometry: TorusBufferGeometry,
  18769. TextGeometry: TextGeometry,
  18770. TextBufferGeometry: TextBufferGeometry,
  18771. SphereGeometry: SphereGeometry,
  18772. SphereBufferGeometry: SphereBufferGeometry,
  18773. RingGeometry: RingGeometry,
  18774. RingBufferGeometry: RingBufferGeometry,
  18775. PlaneGeometry: PlaneGeometry,
  18776. PlaneBufferGeometry: PlaneBufferGeometry,
  18777. LatheGeometry: LatheGeometry,
  18778. LatheBufferGeometry: LatheBufferGeometry,
  18779. ShapeGeometry: ShapeGeometry,
  18780. ShapeBufferGeometry: ShapeBufferGeometry,
  18781. ExtrudeGeometry: ExtrudeGeometry,
  18782. ExtrudeBufferGeometry: ExtrudeBufferGeometry,
  18783. EdgesGeometry: EdgesGeometry,
  18784. ConeGeometry: ConeGeometry,
  18785. ConeBufferGeometry: ConeBufferGeometry,
  18786. CylinderGeometry: CylinderGeometry,
  18787. CylinderBufferGeometry: CylinderBufferGeometry,
  18788. CircleGeometry: CircleGeometry,
  18789. CircleBufferGeometry: CircleBufferGeometry,
  18790. BoxGeometry: BoxGeometry,
  18791. BoxBufferGeometry: BoxBufferGeometry
  18792. });
  18793. /**
  18794. * @author mrdoob / http://mrdoob.com/
  18795. *
  18796. * parameters = {
  18797. * color: <THREE.Color>
  18798. * }
  18799. */
  18800. function ShadowMaterial( parameters ) {
  18801. Material.call( this );
  18802. this.type = 'ShadowMaterial';
  18803. this.color = new Color( 0x000000 );
  18804. this.transparent = true;
  18805. this.setValues( parameters );
  18806. }
  18807. ShadowMaterial.prototype = Object.create( Material.prototype );
  18808. ShadowMaterial.prototype.constructor = ShadowMaterial;
  18809. ShadowMaterial.prototype.isShadowMaterial = true;
  18810. ShadowMaterial.prototype.copy = function ( source ) {
  18811. Material.prototype.copy.call( this, source );
  18812. this.color.copy( source.color );
  18813. return this;
  18814. };
  18815. /**
  18816. * @author mrdoob / http://mrdoob.com/
  18817. */
  18818. function RawShaderMaterial( parameters ) {
  18819. ShaderMaterial.call( this, parameters );
  18820. this.type = 'RawShaderMaterial';
  18821. }
  18822. RawShaderMaterial.prototype = Object.create( ShaderMaterial.prototype );
  18823. RawShaderMaterial.prototype.constructor = RawShaderMaterial;
  18824. RawShaderMaterial.prototype.isRawShaderMaterial = true;
  18825. /**
  18826. * @author WestLangley / http://github.com/WestLangley
  18827. *
  18828. * parameters = {
  18829. * color: <hex>,
  18830. * roughness: <float>,
  18831. * metalness: <float>,
  18832. * opacity: <float>,
  18833. *
  18834. * map: new THREE.Texture( <Image> ),
  18835. *
  18836. * lightMap: new THREE.Texture( <Image> ),
  18837. * lightMapIntensity: <float>
  18838. *
  18839. * aoMap: new THREE.Texture( <Image> ),
  18840. * aoMapIntensity: <float>
  18841. *
  18842. * emissive: <hex>,
  18843. * emissiveIntensity: <float>
  18844. * emissiveMap: new THREE.Texture( <Image> ),
  18845. *
  18846. * bumpMap: new THREE.Texture( <Image> ),
  18847. * bumpScale: <float>,
  18848. *
  18849. * normalMap: new THREE.Texture( <Image> ),
  18850. * normalMapType: THREE.TangentSpaceNormalMap,
  18851. * normalScale: <Vector2>,
  18852. *
  18853. * displacementMap: new THREE.Texture( <Image> ),
  18854. * displacementScale: <float>,
  18855. * displacementBias: <float>,
  18856. *
  18857. * roughnessMap: new THREE.Texture( <Image> ),
  18858. *
  18859. * metalnessMap: new THREE.Texture( <Image> ),
  18860. *
  18861. * alphaMap: new THREE.Texture( <Image> ),
  18862. *
  18863. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  18864. * envMapIntensity: <float>
  18865. *
  18866. * refractionRatio: <float>,
  18867. *
  18868. * wireframe: <boolean>,
  18869. * wireframeLinewidth: <float>,
  18870. *
  18871. * skinning: <bool>,
  18872. * morphTargets: <bool>,
  18873. * morphNormals: <bool>
  18874. * }
  18875. */
  18876. function MeshStandardMaterial( parameters ) {
  18877. Material.call( this );
  18878. this.defines = { 'STANDARD': '' };
  18879. this.type = 'MeshStandardMaterial';
  18880. this.color = new Color( 0xffffff ); // diffuse
  18881. this.roughness = 0.5;
  18882. this.metalness = 0.5;
  18883. this.map = null;
  18884. this.lightMap = null;
  18885. this.lightMapIntensity = 1.0;
  18886. this.aoMap = null;
  18887. this.aoMapIntensity = 1.0;
  18888. this.emissive = new Color( 0x000000 );
  18889. this.emissiveIntensity = 1.0;
  18890. this.emissiveMap = null;
  18891. this.bumpMap = null;
  18892. this.bumpScale = 1;
  18893. this.normalMap = null;
  18894. this.normalMapType = TangentSpaceNormalMap;
  18895. this.normalScale = new Vector2( 1, 1 );
  18896. this.displacementMap = null;
  18897. this.displacementScale = 1;
  18898. this.displacementBias = 0;
  18899. this.roughnessMap = null;
  18900. this.metalnessMap = null;
  18901. this.alphaMap = null;
  18902. this.envMap = null;
  18903. this.envMapIntensity = 1.0;
  18904. this.refractionRatio = 0.98;
  18905. this.wireframe = false;
  18906. this.wireframeLinewidth = 1;
  18907. this.wireframeLinecap = 'round';
  18908. this.wireframeLinejoin = 'round';
  18909. this.skinning = false;
  18910. this.morphTargets = false;
  18911. this.morphNormals = false;
  18912. this.setValues( parameters );
  18913. }
  18914. MeshStandardMaterial.prototype = Object.create( Material.prototype );
  18915. MeshStandardMaterial.prototype.constructor = MeshStandardMaterial;
  18916. MeshStandardMaterial.prototype.isMeshStandardMaterial = true;
  18917. MeshStandardMaterial.prototype.copy = function ( source ) {
  18918. Material.prototype.copy.call( this, source );
  18919. this.defines = { 'STANDARD': '' };
  18920. this.color.copy( source.color );
  18921. this.roughness = source.roughness;
  18922. this.metalness = source.metalness;
  18923. this.map = source.map;
  18924. this.lightMap = source.lightMap;
  18925. this.lightMapIntensity = source.lightMapIntensity;
  18926. this.aoMap = source.aoMap;
  18927. this.aoMapIntensity = source.aoMapIntensity;
  18928. this.emissive.copy( source.emissive );
  18929. this.emissiveMap = source.emissiveMap;
  18930. this.emissiveIntensity = source.emissiveIntensity;
  18931. this.bumpMap = source.bumpMap;
  18932. this.bumpScale = source.bumpScale;
  18933. this.normalMap = source.normalMap;
  18934. this.normalMapType = source.normalMapType;
  18935. this.normalScale.copy( source.normalScale );
  18936. this.displacementMap = source.displacementMap;
  18937. this.displacementScale = source.displacementScale;
  18938. this.displacementBias = source.displacementBias;
  18939. this.roughnessMap = source.roughnessMap;
  18940. this.metalnessMap = source.metalnessMap;
  18941. this.alphaMap = source.alphaMap;
  18942. this.envMap = source.envMap;
  18943. this.envMapIntensity = source.envMapIntensity;
  18944. this.refractionRatio = source.refractionRatio;
  18945. this.wireframe = source.wireframe;
  18946. this.wireframeLinewidth = source.wireframeLinewidth;
  18947. this.wireframeLinecap = source.wireframeLinecap;
  18948. this.wireframeLinejoin = source.wireframeLinejoin;
  18949. this.skinning = source.skinning;
  18950. this.morphTargets = source.morphTargets;
  18951. this.morphNormals = source.morphNormals;
  18952. return this;
  18953. };
  18954. /**
  18955. * @author WestLangley / http://github.com/WestLangley
  18956. *
  18957. * parameters = {
  18958. * reflectivity: <float>
  18959. * clearCoat: <float>
  18960. * clearCoatRoughness: <float>
  18961. * }
  18962. */
  18963. function MeshPhysicalMaterial( parameters ) {
  18964. MeshStandardMaterial.call( this );
  18965. this.defines = { 'PHYSICAL': '' };
  18966. this.type = 'MeshPhysicalMaterial';
  18967. this.reflectivity = 0.5; // maps to F0 = 0.04
  18968. this.clearCoat = 0.0;
  18969. this.clearCoatRoughness = 0.0;
  18970. this.setValues( parameters );
  18971. }
  18972. MeshPhysicalMaterial.prototype = Object.create( MeshStandardMaterial.prototype );
  18973. MeshPhysicalMaterial.prototype.constructor = MeshPhysicalMaterial;
  18974. MeshPhysicalMaterial.prototype.isMeshPhysicalMaterial = true;
  18975. MeshPhysicalMaterial.prototype.copy = function ( source ) {
  18976. MeshStandardMaterial.prototype.copy.call( this, source );
  18977. this.defines = { 'PHYSICAL': '' };
  18978. this.reflectivity = source.reflectivity;
  18979. this.clearCoat = source.clearCoat;
  18980. this.clearCoatRoughness = source.clearCoatRoughness;
  18981. return this;
  18982. };
  18983. /**
  18984. * @author mrdoob / http://mrdoob.com/
  18985. * @author alteredq / http://alteredqualia.com/
  18986. *
  18987. * parameters = {
  18988. * color: <hex>,
  18989. * specular: <hex>,
  18990. * shininess: <float>,
  18991. * opacity: <float>,
  18992. *
  18993. * map: new THREE.Texture( <Image> ),
  18994. *
  18995. * lightMap: new THREE.Texture( <Image> ),
  18996. * lightMapIntensity: <float>
  18997. *
  18998. * aoMap: new THREE.Texture( <Image> ),
  18999. * aoMapIntensity: <float>
  19000. *
  19001. * emissive: <hex>,
  19002. * emissiveIntensity: <float>
  19003. * emissiveMap: new THREE.Texture( <Image> ),
  19004. *
  19005. * bumpMap: new THREE.Texture( <Image> ),
  19006. * bumpScale: <float>,
  19007. *
  19008. * normalMap: new THREE.Texture( <Image> ),
  19009. * normalMapType: THREE.TangentSpaceNormalMap,
  19010. * normalScale: <Vector2>,
  19011. *
  19012. * displacementMap: new THREE.Texture( <Image> ),
  19013. * displacementScale: <float>,
  19014. * displacementBias: <float>,
  19015. *
  19016. * specularMap: new THREE.Texture( <Image> ),
  19017. *
  19018. * alphaMap: new THREE.Texture( <Image> ),
  19019. *
  19020. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  19021. * combine: THREE.Multiply,
  19022. * reflectivity: <float>,
  19023. * refractionRatio: <float>,
  19024. *
  19025. * wireframe: <boolean>,
  19026. * wireframeLinewidth: <float>,
  19027. *
  19028. * skinning: <bool>,
  19029. * morphTargets: <bool>,
  19030. * morphNormals: <bool>
  19031. * }
  19032. */
  19033. function MeshPhongMaterial( parameters ) {
  19034. Material.call( this );
  19035. this.type = 'MeshPhongMaterial';
  19036. this.color = new Color( 0xffffff ); // diffuse
  19037. this.specular = new Color( 0x111111 );
  19038. this.shininess = 30;
  19039. this.map = null;
  19040. this.lightMap = null;
  19041. this.lightMapIntensity = 1.0;
  19042. this.aoMap = null;
  19043. this.aoMapIntensity = 1.0;
  19044. this.emissive = new Color( 0x000000 );
  19045. this.emissiveIntensity = 1.0;
  19046. this.emissiveMap = null;
  19047. this.bumpMap = null;
  19048. this.bumpScale = 1;
  19049. this.normalMap = null;
  19050. this.normalMapType = TangentSpaceNormalMap;
  19051. this.normalScale = new Vector2( 1, 1 );
  19052. this.displacementMap = null;
  19053. this.displacementScale = 1;
  19054. this.displacementBias = 0;
  19055. this.specularMap = null;
  19056. this.alphaMap = null;
  19057. this.envMap = null;
  19058. this.combine = MultiplyOperation;
  19059. this.reflectivity = 1;
  19060. this.refractionRatio = 0.98;
  19061. this.wireframe = false;
  19062. this.wireframeLinewidth = 1;
  19063. this.wireframeLinecap = 'round';
  19064. this.wireframeLinejoin = 'round';
  19065. this.skinning = false;
  19066. this.morphTargets = false;
  19067. this.morphNormals = false;
  19068. this.setValues( parameters );
  19069. }
  19070. MeshPhongMaterial.prototype = Object.create( Material.prototype );
  19071. MeshPhongMaterial.prototype.constructor = MeshPhongMaterial;
  19072. MeshPhongMaterial.prototype.isMeshPhongMaterial = true;
  19073. MeshPhongMaterial.prototype.copy = function ( source ) {
  19074. Material.prototype.copy.call( this, source );
  19075. this.color.copy( source.color );
  19076. this.specular.copy( source.specular );
  19077. this.shininess = source.shininess;
  19078. this.map = source.map;
  19079. this.lightMap = source.lightMap;
  19080. this.lightMapIntensity = source.lightMapIntensity;
  19081. this.aoMap = source.aoMap;
  19082. this.aoMapIntensity = source.aoMapIntensity;
  19083. this.emissive.copy( source.emissive );
  19084. this.emissiveMap = source.emissiveMap;
  19085. this.emissiveIntensity = source.emissiveIntensity;
  19086. this.bumpMap = source.bumpMap;
  19087. this.bumpScale = source.bumpScale;
  19088. this.normalMap = source.normalMap;
  19089. this.normalMapType = source.normalMapType;
  19090. this.normalScale.copy( source.normalScale );
  19091. this.displacementMap = source.displacementMap;
  19092. this.displacementScale = source.displacementScale;
  19093. this.displacementBias = source.displacementBias;
  19094. this.specularMap = source.specularMap;
  19095. this.alphaMap = source.alphaMap;
  19096. this.envMap = source.envMap;
  19097. this.combine = source.combine;
  19098. this.reflectivity = source.reflectivity;
  19099. this.refractionRatio = source.refractionRatio;
  19100. this.wireframe = source.wireframe;
  19101. this.wireframeLinewidth = source.wireframeLinewidth;
  19102. this.wireframeLinecap = source.wireframeLinecap;
  19103. this.wireframeLinejoin = source.wireframeLinejoin;
  19104. this.skinning = source.skinning;
  19105. this.morphTargets = source.morphTargets;
  19106. this.morphNormals = source.morphNormals;
  19107. return this;
  19108. };
  19109. /**
  19110. * @author takahirox / http://github.com/takahirox
  19111. *
  19112. * parameters = {
  19113. * gradientMap: new THREE.Texture( <Image> )
  19114. * }
  19115. */
  19116. function MeshToonMaterial( parameters ) {
  19117. MeshPhongMaterial.call( this );
  19118. this.defines = { 'TOON': '' };
  19119. this.type = 'MeshToonMaterial';
  19120. this.gradientMap = null;
  19121. this.setValues( parameters );
  19122. }
  19123. MeshToonMaterial.prototype = Object.create( MeshPhongMaterial.prototype );
  19124. MeshToonMaterial.prototype.constructor = MeshToonMaterial;
  19125. MeshToonMaterial.prototype.isMeshToonMaterial = true;
  19126. MeshToonMaterial.prototype.copy = function ( source ) {
  19127. MeshPhongMaterial.prototype.copy.call( this, source );
  19128. this.gradientMap = source.gradientMap;
  19129. return this;
  19130. };
  19131. /**
  19132. * @author mrdoob / http://mrdoob.com/
  19133. * @author WestLangley / http://github.com/WestLangley
  19134. *
  19135. * parameters = {
  19136. * opacity: <float>,
  19137. *
  19138. * bumpMap: new THREE.Texture( <Image> ),
  19139. * bumpScale: <float>,
  19140. *
  19141. * normalMap: new THREE.Texture( <Image> ),
  19142. * normalMapType: THREE.TangentSpaceNormalMap,
  19143. * normalScale: <Vector2>,
  19144. *
  19145. * displacementMap: new THREE.Texture( <Image> ),
  19146. * displacementScale: <float>,
  19147. * displacementBias: <float>,
  19148. *
  19149. * wireframe: <boolean>,
  19150. * wireframeLinewidth: <float>
  19151. *
  19152. * skinning: <bool>,
  19153. * morphTargets: <bool>,
  19154. * morphNormals: <bool>
  19155. * }
  19156. */
  19157. function MeshNormalMaterial( parameters ) {
  19158. Material.call( this );
  19159. this.type = 'MeshNormalMaterial';
  19160. this.bumpMap = null;
  19161. this.bumpScale = 1;
  19162. this.normalMap = null;
  19163. this.normalMapType = TangentSpaceNormalMap;
  19164. this.normalScale = new Vector2( 1, 1 );
  19165. this.displacementMap = null;
  19166. this.displacementScale = 1;
  19167. this.displacementBias = 0;
  19168. this.wireframe = false;
  19169. this.wireframeLinewidth = 1;
  19170. this.fog = false;
  19171. this.lights = false;
  19172. this.skinning = false;
  19173. this.morphTargets = false;
  19174. this.morphNormals = false;
  19175. this.setValues( parameters );
  19176. }
  19177. MeshNormalMaterial.prototype = Object.create( Material.prototype );
  19178. MeshNormalMaterial.prototype.constructor = MeshNormalMaterial;
  19179. MeshNormalMaterial.prototype.isMeshNormalMaterial = true;
  19180. MeshNormalMaterial.prototype.copy = function ( source ) {
  19181. Material.prototype.copy.call( this, source );
  19182. this.bumpMap = source.bumpMap;
  19183. this.bumpScale = source.bumpScale;
  19184. this.normalMap = source.normalMap;
  19185. this.normalMapType = source.normalMapType;
  19186. this.normalScale.copy( source.normalScale );
  19187. this.displacementMap = source.displacementMap;
  19188. this.displacementScale = source.displacementScale;
  19189. this.displacementBias = source.displacementBias;
  19190. this.wireframe = source.wireframe;
  19191. this.wireframeLinewidth = source.wireframeLinewidth;
  19192. this.skinning = source.skinning;
  19193. this.morphTargets = source.morphTargets;
  19194. this.morphNormals = source.morphNormals;
  19195. return this;
  19196. };
  19197. /**
  19198. * @author mrdoob / http://mrdoob.com/
  19199. * @author alteredq / http://alteredqualia.com/
  19200. *
  19201. * parameters = {
  19202. * color: <hex>,
  19203. * opacity: <float>,
  19204. *
  19205. * map: new THREE.Texture( <Image> ),
  19206. *
  19207. * lightMap: new THREE.Texture( <Image> ),
  19208. * lightMapIntensity: <float>
  19209. *
  19210. * aoMap: new THREE.Texture( <Image> ),
  19211. * aoMapIntensity: <float>
  19212. *
  19213. * emissive: <hex>,
  19214. * emissiveIntensity: <float>
  19215. * emissiveMap: new THREE.Texture( <Image> ),
  19216. *
  19217. * specularMap: new THREE.Texture( <Image> ),
  19218. *
  19219. * alphaMap: new THREE.Texture( <Image> ),
  19220. *
  19221. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  19222. * combine: THREE.Multiply,
  19223. * reflectivity: <float>,
  19224. * refractionRatio: <float>,
  19225. *
  19226. * wireframe: <boolean>,
  19227. * wireframeLinewidth: <float>,
  19228. *
  19229. * skinning: <bool>,
  19230. * morphTargets: <bool>,
  19231. * morphNormals: <bool>
  19232. * }
  19233. */
  19234. function MeshLambertMaterial( parameters ) {
  19235. Material.call( this );
  19236. this.type = 'MeshLambertMaterial';
  19237. this.color = new Color( 0xffffff ); // diffuse
  19238. this.map = null;
  19239. this.lightMap = null;
  19240. this.lightMapIntensity = 1.0;
  19241. this.aoMap = null;
  19242. this.aoMapIntensity = 1.0;
  19243. this.emissive = new Color( 0x000000 );
  19244. this.emissiveIntensity = 1.0;
  19245. this.emissiveMap = null;
  19246. this.specularMap = null;
  19247. this.alphaMap = null;
  19248. this.envMap = null;
  19249. this.combine = MultiplyOperation;
  19250. this.reflectivity = 1;
  19251. this.refractionRatio = 0.98;
  19252. this.wireframe = false;
  19253. this.wireframeLinewidth = 1;
  19254. this.wireframeLinecap = 'round';
  19255. this.wireframeLinejoin = 'round';
  19256. this.skinning = false;
  19257. this.morphTargets = false;
  19258. this.morphNormals = false;
  19259. this.setValues( parameters );
  19260. }
  19261. MeshLambertMaterial.prototype = Object.create( Material.prototype );
  19262. MeshLambertMaterial.prototype.constructor = MeshLambertMaterial;
  19263. MeshLambertMaterial.prototype.isMeshLambertMaterial = true;
  19264. MeshLambertMaterial.prototype.copy = function ( source ) {
  19265. Material.prototype.copy.call( this, source );
  19266. this.color.copy( source.color );
  19267. this.map = source.map;
  19268. this.lightMap = source.lightMap;
  19269. this.lightMapIntensity = source.lightMapIntensity;
  19270. this.aoMap = source.aoMap;
  19271. this.aoMapIntensity = source.aoMapIntensity;
  19272. this.emissive.copy( source.emissive );
  19273. this.emissiveMap = source.emissiveMap;
  19274. this.emissiveIntensity = source.emissiveIntensity;
  19275. this.specularMap = source.specularMap;
  19276. this.alphaMap = source.alphaMap;
  19277. this.envMap = source.envMap;
  19278. this.combine = source.combine;
  19279. this.reflectivity = source.reflectivity;
  19280. this.refractionRatio = source.refractionRatio;
  19281. this.wireframe = source.wireframe;
  19282. this.wireframeLinewidth = source.wireframeLinewidth;
  19283. this.wireframeLinecap = source.wireframeLinecap;
  19284. this.wireframeLinejoin = source.wireframeLinejoin;
  19285. this.skinning = source.skinning;
  19286. this.morphTargets = source.morphTargets;
  19287. this.morphNormals = source.morphNormals;
  19288. return this;
  19289. };
  19290. /**
  19291. * @author WestLangley / http://github.com/WestLangley
  19292. *
  19293. * parameters = {
  19294. * color: <hex>,
  19295. * opacity: <float>,
  19296. *
  19297. * matcap: new THREE.Texture( <Image> ),
  19298. *
  19299. * map: new THREE.Texture( <Image> ),
  19300. *
  19301. * bumpMap: new THREE.Texture( <Image> ),
  19302. * bumpScale: <float>,
  19303. *
  19304. * normalMap: new THREE.Texture( <Image> ),
  19305. * normalMapType: THREE.TangentSpaceNormalMap,
  19306. * normalScale: <Vector2>,
  19307. *
  19308. * displacementMap: new THREE.Texture( <Image> ),
  19309. * displacementScale: <float>,
  19310. * displacementBias: <float>,
  19311. *
  19312. * alphaMap: new THREE.Texture( <Image> ),
  19313. *
  19314. * skinning: <bool>,
  19315. * morphTargets: <bool>,
  19316. * morphNormals: <bool>
  19317. * }
  19318. */
  19319. function MeshMatcapMaterial( parameters ) {
  19320. Material.call( this );
  19321. this.defines = { 'MATCAP': '' };
  19322. this.type = 'MeshMatcapMaterial';
  19323. this.color = new Color( 0xffffff ); // diffuse
  19324. this.matcap = null;
  19325. this.map = null;
  19326. this.bumpMap = null;
  19327. this.bumpScale = 1;
  19328. this.normalMap = null;
  19329. this.normalMapType = TangentSpaceNormalMap;
  19330. this.normalScale = new Vector2( 1, 1 );
  19331. this.displacementMap = null;
  19332. this.displacementScale = 1;
  19333. this.displacementBias = 0;
  19334. this.alphaMap = null;
  19335. this.skinning = false;
  19336. this.morphTargets = false;
  19337. this.morphNormals = false;
  19338. this.lights = false;
  19339. this.setValues( parameters );
  19340. }
  19341. MeshMatcapMaterial.prototype = Object.create( Material.prototype );
  19342. MeshMatcapMaterial.prototype.constructor = MeshMatcapMaterial;
  19343. MeshMatcapMaterial.prototype.isMeshMatcapMaterial = true;
  19344. MeshMatcapMaterial.prototype.copy = function ( source ) {
  19345. Material.prototype.copy.call( this, source );
  19346. this.defines = { 'MATCAP': '' };
  19347. this.color.copy( source.color );
  19348. this.matcap = source.matcap;
  19349. this.map = source.map;
  19350. this.bumpMap = source.bumpMap;
  19351. this.bumpScale = source.bumpScale;
  19352. this.normalMap = source.normalMap;
  19353. this.normalMapType = source.normalMapType;
  19354. this.normalScale.copy( source.normalScale );
  19355. this.displacementMap = source.displacementMap;
  19356. this.displacementScale = source.displacementScale;
  19357. this.displacementBias = source.displacementBias;
  19358. this.alphaMap = source.alphaMap;
  19359. this.skinning = source.skinning;
  19360. this.morphTargets = source.morphTargets;
  19361. this.morphNormals = source.morphNormals;
  19362. return this;
  19363. };
  19364. /**
  19365. * @author alteredq / http://alteredqualia.com/
  19366. *
  19367. * parameters = {
  19368. * color: <hex>,
  19369. * opacity: <float>,
  19370. *
  19371. * linewidth: <float>,
  19372. *
  19373. * scale: <float>,
  19374. * dashSize: <float>,
  19375. * gapSize: <float>
  19376. * }
  19377. */
  19378. function LineDashedMaterial( parameters ) {
  19379. LineBasicMaterial.call( this );
  19380. this.type = 'LineDashedMaterial';
  19381. this.scale = 1;
  19382. this.dashSize = 3;
  19383. this.gapSize = 1;
  19384. this.setValues( parameters );
  19385. }
  19386. LineDashedMaterial.prototype = Object.create( LineBasicMaterial.prototype );
  19387. LineDashedMaterial.prototype.constructor = LineDashedMaterial;
  19388. LineDashedMaterial.prototype.isLineDashedMaterial = true;
  19389. LineDashedMaterial.prototype.copy = function ( source ) {
  19390. LineBasicMaterial.prototype.copy.call( this, source );
  19391. this.scale = source.scale;
  19392. this.dashSize = source.dashSize;
  19393. this.gapSize = source.gapSize;
  19394. return this;
  19395. };
  19396. var Materials = /*#__PURE__*/Object.freeze({
  19397. ShadowMaterial: ShadowMaterial,
  19398. SpriteMaterial: SpriteMaterial,
  19399. RawShaderMaterial: RawShaderMaterial,
  19400. ShaderMaterial: ShaderMaterial,
  19401. PointsMaterial: PointsMaterial,
  19402. MeshPhysicalMaterial: MeshPhysicalMaterial,
  19403. MeshStandardMaterial: MeshStandardMaterial,
  19404. MeshPhongMaterial: MeshPhongMaterial,
  19405. MeshToonMaterial: MeshToonMaterial,
  19406. MeshNormalMaterial: MeshNormalMaterial,
  19407. MeshLambertMaterial: MeshLambertMaterial,
  19408. MeshDepthMaterial: MeshDepthMaterial,
  19409. MeshDistanceMaterial: MeshDistanceMaterial,
  19410. MeshBasicMaterial: MeshBasicMaterial,
  19411. MeshMatcapMaterial: MeshMatcapMaterial,
  19412. LineDashedMaterial: LineDashedMaterial,
  19413. LineBasicMaterial: LineBasicMaterial,
  19414. Material: Material
  19415. });
  19416. /**
  19417. * @author tschw
  19418. * @author Ben Houston / http://clara.io/
  19419. * @author David Sarno / http://lighthaus.us/
  19420. */
  19421. var AnimationUtils = {
  19422. // same as Array.prototype.slice, but also works on typed arrays
  19423. arraySlice: function ( array, from, to ) {
  19424. if ( AnimationUtils.isTypedArray( array ) ) {
  19425. // in ios9 array.subarray(from, undefined) will return empty array
  19426. // but array.subarray(from) or array.subarray(from, len) is correct
  19427. return new array.constructor( array.subarray( from, to !== undefined ? to : array.length ) );
  19428. }
  19429. return array.slice( from, to );
  19430. },
  19431. // converts an array to a specific type
  19432. convertArray: function ( array, type, forceClone ) {
  19433. if ( ! array || // let 'undefined' and 'null' pass
  19434. ! forceClone && array.constructor === type ) return array;
  19435. if ( typeof type.BYTES_PER_ELEMENT === 'number' ) {
  19436. return new type( array ); // create typed array
  19437. }
  19438. return Array.prototype.slice.call( array ); // create Array
  19439. },
  19440. isTypedArray: function ( object ) {
  19441. return ArrayBuffer.isView( object ) &&
  19442. ! ( object instanceof DataView );
  19443. },
  19444. // returns an array by which times and values can be sorted
  19445. getKeyframeOrder: function ( times ) {
  19446. function compareTime( i, j ) {
  19447. return times[ i ] - times[ j ];
  19448. }
  19449. var n = times.length;
  19450. var result = new Array( n );
  19451. for ( var i = 0; i !== n; ++ i ) result[ i ] = i;
  19452. result.sort( compareTime );
  19453. return result;
  19454. },
  19455. // uses the array previously returned by 'getKeyframeOrder' to sort data
  19456. sortedArray: function ( values, stride, order ) {
  19457. var nValues = values.length;
  19458. var result = new values.constructor( nValues );
  19459. for ( var i = 0, dstOffset = 0; dstOffset !== nValues; ++ i ) {
  19460. var srcOffset = order[ i ] * stride;
  19461. for ( var j = 0; j !== stride; ++ j ) {
  19462. result[ dstOffset ++ ] = values[ srcOffset + j ];
  19463. }
  19464. }
  19465. return result;
  19466. },
  19467. // function for parsing AOS keyframe formats
  19468. flattenJSON: function ( jsonKeys, times, values, valuePropertyName ) {
  19469. var i = 1, key = jsonKeys[ 0 ];
  19470. while ( key !== undefined && key[ valuePropertyName ] === undefined ) {
  19471. key = jsonKeys[ i ++ ];
  19472. }
  19473. if ( key === undefined ) return; // no data
  19474. var value = key[ valuePropertyName ];
  19475. if ( value === undefined ) return; // no data
  19476. if ( Array.isArray( value ) ) {
  19477. do {
  19478. value = key[ valuePropertyName ];
  19479. if ( value !== undefined ) {
  19480. times.push( key.time );
  19481. values.push.apply( values, value ); // push all elements
  19482. }
  19483. key = jsonKeys[ i ++ ];
  19484. } while ( key !== undefined );
  19485. } else if ( value.toArray !== undefined ) {
  19486. // ...assume THREE.Math-ish
  19487. do {
  19488. value = key[ valuePropertyName ];
  19489. if ( value !== undefined ) {
  19490. times.push( key.time );
  19491. value.toArray( values, values.length );
  19492. }
  19493. key = jsonKeys[ i ++ ];
  19494. } while ( key !== undefined );
  19495. } else {
  19496. // otherwise push as-is
  19497. do {
  19498. value = key[ valuePropertyName ];
  19499. if ( value !== undefined ) {
  19500. times.push( key.time );
  19501. values.push( value );
  19502. }
  19503. key = jsonKeys[ i ++ ];
  19504. } while ( key !== undefined );
  19505. }
  19506. }
  19507. };
  19508. /**
  19509. * Abstract base class of interpolants over parametric samples.
  19510. *
  19511. * The parameter domain is one dimensional, typically the time or a path
  19512. * along a curve defined by the data.
  19513. *
  19514. * The sample values can have any dimensionality and derived classes may
  19515. * apply special interpretations to the data.
  19516. *
  19517. * This class provides the interval seek in a Template Method, deferring
  19518. * the actual interpolation to derived classes.
  19519. *
  19520. * Time complexity is O(1) for linear access crossing at most two points
  19521. * and O(log N) for random access, where N is the number of positions.
  19522. *
  19523. * References:
  19524. *
  19525. * http://www.oodesign.com/template-method-pattern.html
  19526. *
  19527. * @author tschw
  19528. */
  19529. function Interpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  19530. this.parameterPositions = parameterPositions;
  19531. this._cachedIndex = 0;
  19532. this.resultBuffer = resultBuffer !== undefined ?
  19533. resultBuffer : new sampleValues.constructor( sampleSize );
  19534. this.sampleValues = sampleValues;
  19535. this.valueSize = sampleSize;
  19536. }
  19537. Object.assign( Interpolant.prototype, {
  19538. evaluate: function ( t ) {
  19539. var pp = this.parameterPositions,
  19540. i1 = this._cachedIndex,
  19541. t1 = pp[ i1 ],
  19542. t0 = pp[ i1 - 1 ];
  19543. validate_interval: {
  19544. seek: {
  19545. var right;
  19546. linear_scan: {
  19547. //- See http://jsperf.com/comparison-to-undefined/3
  19548. //- slower code:
  19549. //-
  19550. //- if ( t >= t1 || t1 === undefined ) {
  19551. forward_scan: if ( ! ( t < t1 ) ) {
  19552. for ( var giveUpAt = i1 + 2; ; ) {
  19553. if ( t1 === undefined ) {
  19554. if ( t < t0 ) break forward_scan;
  19555. // after end
  19556. i1 = pp.length;
  19557. this._cachedIndex = i1;
  19558. return this.afterEnd_( i1 - 1, t, t0 );
  19559. }
  19560. if ( i1 === giveUpAt ) break; // this loop
  19561. t0 = t1;
  19562. t1 = pp[ ++ i1 ];
  19563. if ( t < t1 ) {
  19564. // we have arrived at the sought interval
  19565. break seek;
  19566. }
  19567. }
  19568. // prepare binary search on the right side of the index
  19569. right = pp.length;
  19570. break linear_scan;
  19571. }
  19572. //- slower code:
  19573. //- if ( t < t0 || t0 === undefined ) {
  19574. if ( ! ( t >= t0 ) ) {
  19575. // looping?
  19576. var t1global = pp[ 1 ];
  19577. if ( t < t1global ) {
  19578. i1 = 2; // + 1, using the scan for the details
  19579. t0 = t1global;
  19580. }
  19581. // linear reverse scan
  19582. for ( var giveUpAt = i1 - 2; ; ) {
  19583. if ( t0 === undefined ) {
  19584. // before start
  19585. this._cachedIndex = 0;
  19586. return this.beforeStart_( 0, t, t1 );
  19587. }
  19588. if ( i1 === giveUpAt ) break; // this loop
  19589. t1 = t0;
  19590. t0 = pp[ -- i1 - 1 ];
  19591. if ( t >= t0 ) {
  19592. // we have arrived at the sought interval
  19593. break seek;
  19594. }
  19595. }
  19596. // prepare binary search on the left side of the index
  19597. right = i1;
  19598. i1 = 0;
  19599. break linear_scan;
  19600. }
  19601. // the interval is valid
  19602. break validate_interval;
  19603. } // linear scan
  19604. // binary search
  19605. while ( i1 < right ) {
  19606. var mid = ( i1 + right ) >>> 1;
  19607. if ( t < pp[ mid ] ) {
  19608. right = mid;
  19609. } else {
  19610. i1 = mid + 1;
  19611. }
  19612. }
  19613. t1 = pp[ i1 ];
  19614. t0 = pp[ i1 - 1 ];
  19615. // check boundary cases, again
  19616. if ( t0 === undefined ) {
  19617. this._cachedIndex = 0;
  19618. return this.beforeStart_( 0, t, t1 );
  19619. }
  19620. if ( t1 === undefined ) {
  19621. i1 = pp.length;
  19622. this._cachedIndex = i1;
  19623. return this.afterEnd_( i1 - 1, t0, t );
  19624. }
  19625. } // seek
  19626. this._cachedIndex = i1;
  19627. this.intervalChanged_( i1, t0, t1 );
  19628. } // validate_interval
  19629. return this.interpolate_( i1, t0, t, t1 );
  19630. },
  19631. settings: null, // optional, subclass-specific settings structure
  19632. // Note: The indirection allows central control of many interpolants.
  19633. // --- Protected interface
  19634. DefaultSettings_: {},
  19635. getSettings_: function () {
  19636. return this.settings || this.DefaultSettings_;
  19637. },
  19638. copySampleValue_: function ( index ) {
  19639. // copies a sample value to the result buffer
  19640. var result = this.resultBuffer,
  19641. values = this.sampleValues,
  19642. stride = this.valueSize,
  19643. offset = index * stride;
  19644. for ( var i = 0; i !== stride; ++ i ) {
  19645. result[ i ] = values[ offset + i ];
  19646. }
  19647. return result;
  19648. },
  19649. // Template methods for derived classes:
  19650. interpolate_: function ( /* i1, t0, t, t1 */ ) {
  19651. throw new Error( 'call to abstract method' );
  19652. // implementations shall return this.resultBuffer
  19653. },
  19654. intervalChanged_: function ( /* i1, t0, t1 */ ) {
  19655. // empty
  19656. }
  19657. } );
  19658. //!\ DECLARE ALIAS AFTER assign prototype !
  19659. Object.assign( Interpolant.prototype, {
  19660. //( 0, t, t0 ), returns this.resultBuffer
  19661. beforeStart_: Interpolant.prototype.copySampleValue_,
  19662. //( N-1, tN-1, t ), returns this.resultBuffer
  19663. afterEnd_: Interpolant.prototype.copySampleValue_,
  19664. } );
  19665. /**
  19666. * Fast and simple cubic spline interpolant.
  19667. *
  19668. * It was derived from a Hermitian construction setting the first derivative
  19669. * at each sample position to the linear slope between neighboring positions
  19670. * over their parameter interval.
  19671. *
  19672. * @author tschw
  19673. */
  19674. function CubicInterpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  19675. Interpolant.call( this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  19676. this._weightPrev = - 0;
  19677. this._offsetPrev = - 0;
  19678. this._weightNext = - 0;
  19679. this._offsetNext = - 0;
  19680. }
  19681. CubicInterpolant.prototype = Object.assign( Object.create( Interpolant.prototype ), {
  19682. constructor: CubicInterpolant,
  19683. DefaultSettings_: {
  19684. endingStart: ZeroCurvatureEnding,
  19685. endingEnd: ZeroCurvatureEnding
  19686. },
  19687. intervalChanged_: function ( i1, t0, t1 ) {
  19688. var pp = this.parameterPositions,
  19689. iPrev = i1 - 2,
  19690. iNext = i1 + 1,
  19691. tPrev = pp[ iPrev ],
  19692. tNext = pp[ iNext ];
  19693. if ( tPrev === undefined ) {
  19694. switch ( this.getSettings_().endingStart ) {
  19695. case ZeroSlopeEnding:
  19696. // f'(t0) = 0
  19697. iPrev = i1;
  19698. tPrev = 2 * t0 - t1;
  19699. break;
  19700. case WrapAroundEnding:
  19701. // use the other end of the curve
  19702. iPrev = pp.length - 2;
  19703. tPrev = t0 + pp[ iPrev ] - pp[ iPrev + 1 ];
  19704. break;
  19705. default: // ZeroCurvatureEnding
  19706. // f''(t0) = 0 a.k.a. Natural Spline
  19707. iPrev = i1;
  19708. tPrev = t1;
  19709. }
  19710. }
  19711. if ( tNext === undefined ) {
  19712. switch ( this.getSettings_().endingEnd ) {
  19713. case ZeroSlopeEnding:
  19714. // f'(tN) = 0
  19715. iNext = i1;
  19716. tNext = 2 * t1 - t0;
  19717. break;
  19718. case WrapAroundEnding:
  19719. // use the other end of the curve
  19720. iNext = 1;
  19721. tNext = t1 + pp[ 1 ] - pp[ 0 ];
  19722. break;
  19723. default: // ZeroCurvatureEnding
  19724. // f''(tN) = 0, a.k.a. Natural Spline
  19725. iNext = i1 - 1;
  19726. tNext = t0;
  19727. }
  19728. }
  19729. var halfDt = ( t1 - t0 ) * 0.5,
  19730. stride = this.valueSize;
  19731. this._weightPrev = halfDt / ( t0 - tPrev );
  19732. this._weightNext = halfDt / ( tNext - t1 );
  19733. this._offsetPrev = iPrev * stride;
  19734. this._offsetNext = iNext * stride;
  19735. },
  19736. interpolate_: function ( i1, t0, t, t1 ) {
  19737. var result = this.resultBuffer,
  19738. values = this.sampleValues,
  19739. stride = this.valueSize,
  19740. o1 = i1 * stride, o0 = o1 - stride,
  19741. oP = this._offsetPrev, oN = this._offsetNext,
  19742. wP = this._weightPrev, wN = this._weightNext,
  19743. p = ( t - t0 ) / ( t1 - t0 ),
  19744. pp = p * p,
  19745. ppp = pp * p;
  19746. // evaluate polynomials
  19747. var sP = - wP * ppp + 2 * wP * pp - wP * p;
  19748. var s0 = ( 1 + wP ) * ppp + ( - 1.5 - 2 * wP ) * pp + ( - 0.5 + wP ) * p + 1;
  19749. var s1 = ( - 1 - wN ) * ppp + ( 1.5 + wN ) * pp + 0.5 * p;
  19750. var sN = wN * ppp - wN * pp;
  19751. // combine data linearly
  19752. for ( var i = 0; i !== stride; ++ i ) {
  19753. result[ i ] =
  19754. sP * values[ oP + i ] +
  19755. s0 * values[ o0 + i ] +
  19756. s1 * values[ o1 + i ] +
  19757. sN * values[ oN + i ];
  19758. }
  19759. return result;
  19760. }
  19761. } );
  19762. /**
  19763. * @author tschw
  19764. */
  19765. function LinearInterpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  19766. Interpolant.call( this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  19767. }
  19768. LinearInterpolant.prototype = Object.assign( Object.create( Interpolant.prototype ), {
  19769. constructor: LinearInterpolant,
  19770. interpolate_: function ( i1, t0, t, t1 ) {
  19771. var result = this.resultBuffer,
  19772. values = this.sampleValues,
  19773. stride = this.valueSize,
  19774. offset1 = i1 * stride,
  19775. offset0 = offset1 - stride,
  19776. weight1 = ( t - t0 ) / ( t1 - t0 ),
  19777. weight0 = 1 - weight1;
  19778. for ( var i = 0; i !== stride; ++ i ) {
  19779. result[ i ] =
  19780. values[ offset0 + i ] * weight0 +
  19781. values[ offset1 + i ] * weight1;
  19782. }
  19783. return result;
  19784. }
  19785. } );
  19786. /**
  19787. *
  19788. * Interpolant that evaluates to the sample value at the position preceeding
  19789. * the parameter.
  19790. *
  19791. * @author tschw
  19792. */
  19793. function DiscreteInterpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  19794. Interpolant.call( this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  19795. }
  19796. DiscreteInterpolant.prototype = Object.assign( Object.create( Interpolant.prototype ), {
  19797. constructor: DiscreteInterpolant,
  19798. interpolate_: function ( i1 /*, t0, t, t1 */ ) {
  19799. return this.copySampleValue_( i1 - 1 );
  19800. }
  19801. } );
  19802. /**
  19803. *
  19804. * A timed sequence of keyframes for a specific property.
  19805. *
  19806. *
  19807. * @author Ben Houston / http://clara.io/
  19808. * @author David Sarno / http://lighthaus.us/
  19809. * @author tschw
  19810. */
  19811. function KeyframeTrack( name, times, values, interpolation ) {
  19812. if ( name === undefined ) throw new Error( 'THREE.KeyframeTrack: track name is undefined' );
  19813. if ( times === undefined || times.length === 0 ) throw new Error( 'THREE.KeyframeTrack: no keyframes in track named ' + name );
  19814. this.name = name;
  19815. this.times = AnimationUtils.convertArray( times, this.TimeBufferType );
  19816. this.values = AnimationUtils.convertArray( values, this.ValueBufferType );
  19817. this.setInterpolation( interpolation || this.DefaultInterpolation );
  19818. }
  19819. // Static methods
  19820. Object.assign( KeyframeTrack, {
  19821. // Serialization (in static context, because of constructor invocation
  19822. // and automatic invocation of .toJSON):
  19823. toJSON: function ( track ) {
  19824. var trackType = track.constructor;
  19825. var json;
  19826. // derived classes can define a static toJSON method
  19827. if ( trackType.toJSON !== undefined ) {
  19828. json = trackType.toJSON( track );
  19829. } else {
  19830. // by default, we assume the data can be serialized as-is
  19831. json = {
  19832. 'name': track.name,
  19833. 'times': AnimationUtils.convertArray( track.times, Array ),
  19834. 'values': AnimationUtils.convertArray( track.values, Array )
  19835. };
  19836. var interpolation = track.getInterpolation();
  19837. if ( interpolation !== track.DefaultInterpolation ) {
  19838. json.interpolation = interpolation;
  19839. }
  19840. }
  19841. json.type = track.ValueTypeName; // mandatory
  19842. return json;
  19843. }
  19844. } );
  19845. Object.assign( KeyframeTrack.prototype, {
  19846. constructor: KeyframeTrack,
  19847. TimeBufferType: Float32Array,
  19848. ValueBufferType: Float32Array,
  19849. DefaultInterpolation: InterpolateLinear,
  19850. InterpolantFactoryMethodDiscrete: function ( result ) {
  19851. return new DiscreteInterpolant( this.times, this.values, this.getValueSize(), result );
  19852. },
  19853. InterpolantFactoryMethodLinear: function ( result ) {
  19854. return new LinearInterpolant( this.times, this.values, this.getValueSize(), result );
  19855. },
  19856. InterpolantFactoryMethodSmooth: function ( result ) {
  19857. return new CubicInterpolant( this.times, this.values, this.getValueSize(), result );
  19858. },
  19859. setInterpolation: function ( interpolation ) {
  19860. var factoryMethod;
  19861. switch ( interpolation ) {
  19862. case InterpolateDiscrete:
  19863. factoryMethod = this.InterpolantFactoryMethodDiscrete;
  19864. break;
  19865. case InterpolateLinear:
  19866. factoryMethod = this.InterpolantFactoryMethodLinear;
  19867. break;
  19868. case InterpolateSmooth:
  19869. factoryMethod = this.InterpolantFactoryMethodSmooth;
  19870. break;
  19871. }
  19872. if ( factoryMethod === undefined ) {
  19873. var message = "unsupported interpolation for " +
  19874. this.ValueTypeName + " keyframe track named " + this.name;
  19875. if ( this.createInterpolant === undefined ) {
  19876. // fall back to default, unless the default itself is messed up
  19877. if ( interpolation !== this.DefaultInterpolation ) {
  19878. this.setInterpolation( this.DefaultInterpolation );
  19879. } else {
  19880. throw new Error( message ); // fatal, in this case
  19881. }
  19882. }
  19883. console.warn( 'THREE.KeyframeTrack:', message );
  19884. return this;
  19885. }
  19886. this.createInterpolant = factoryMethod;
  19887. return this;
  19888. },
  19889. getInterpolation: function () {
  19890. switch ( this.createInterpolant ) {
  19891. case this.InterpolantFactoryMethodDiscrete:
  19892. return InterpolateDiscrete;
  19893. case this.InterpolantFactoryMethodLinear:
  19894. return InterpolateLinear;
  19895. case this.InterpolantFactoryMethodSmooth:
  19896. return InterpolateSmooth;
  19897. }
  19898. },
  19899. getValueSize: function () {
  19900. return this.values.length / this.times.length;
  19901. },
  19902. // move all keyframes either forwards or backwards in time
  19903. shift: function ( timeOffset ) {
  19904. if ( timeOffset !== 0.0 ) {
  19905. var times = this.times;
  19906. for ( var i = 0, n = times.length; i !== n; ++ i ) {
  19907. times[ i ] += timeOffset;
  19908. }
  19909. }
  19910. return this;
  19911. },
  19912. // scale all keyframe times by a factor (useful for frame <-> seconds conversions)
  19913. scale: function ( timeScale ) {
  19914. if ( timeScale !== 1.0 ) {
  19915. var times = this.times;
  19916. for ( var i = 0, n = times.length; i !== n; ++ i ) {
  19917. times[ i ] *= timeScale;
  19918. }
  19919. }
  19920. return this;
  19921. },
  19922. // removes keyframes before and after animation without changing any values within the range [startTime, endTime].
  19923. // IMPORTANT: We do not shift around keys to the start of the track time, because for interpolated keys this will change their values
  19924. trim: function ( startTime, endTime ) {
  19925. var times = this.times,
  19926. nKeys = times.length,
  19927. from = 0,
  19928. to = nKeys - 1;
  19929. while ( from !== nKeys && times[ from ] < startTime ) {
  19930. ++ from;
  19931. }
  19932. while ( to !== - 1 && times[ to ] > endTime ) {
  19933. -- to;
  19934. }
  19935. ++ to; // inclusive -> exclusive bound
  19936. if ( from !== 0 || to !== nKeys ) {
  19937. // empty tracks are forbidden, so keep at least one keyframe
  19938. if ( from >= to ) to = Math.max( to, 1 ), from = to - 1;
  19939. var stride = this.getValueSize();
  19940. this.times = AnimationUtils.arraySlice( times, from, to );
  19941. this.values = AnimationUtils.arraySlice( this.values, from * stride, to * stride );
  19942. }
  19943. return this;
  19944. },
  19945. // ensure we do not get a GarbageInGarbageOut situation, make sure tracks are at least minimally viable
  19946. validate: function () {
  19947. var valid = true;
  19948. var valueSize = this.getValueSize();
  19949. if ( valueSize - Math.floor( valueSize ) !== 0 ) {
  19950. console.error( 'THREE.KeyframeTrack: Invalid value size in track.', this );
  19951. valid = false;
  19952. }
  19953. var times = this.times,
  19954. values = this.values,
  19955. nKeys = times.length;
  19956. if ( nKeys === 0 ) {
  19957. console.error( 'THREE.KeyframeTrack: Track is empty.', this );
  19958. valid = false;
  19959. }
  19960. var prevTime = null;
  19961. for ( var i = 0; i !== nKeys; i ++ ) {
  19962. var currTime = times[ i ];
  19963. if ( typeof currTime === 'number' && isNaN( currTime ) ) {
  19964. console.error( 'THREE.KeyframeTrack: Time is not a valid number.', this, i, currTime );
  19965. valid = false;
  19966. break;
  19967. }
  19968. if ( prevTime !== null && prevTime > currTime ) {
  19969. console.error( 'THREE.KeyframeTrack: Out of order keys.', this, i, currTime, prevTime );
  19970. valid = false;
  19971. break;
  19972. }
  19973. prevTime = currTime;
  19974. }
  19975. if ( values !== undefined ) {
  19976. if ( AnimationUtils.isTypedArray( values ) ) {
  19977. for ( var i = 0, n = values.length; i !== n; ++ i ) {
  19978. var value = values[ i ];
  19979. if ( isNaN( value ) ) {
  19980. console.error( 'THREE.KeyframeTrack: Value is not a valid number.', this, i, value );
  19981. valid = false;
  19982. break;
  19983. }
  19984. }
  19985. }
  19986. }
  19987. return valid;
  19988. },
  19989. // removes equivalent sequential keys as common in morph target sequences
  19990. // (0,0,0,0,1,1,1,0,0,0,0,0,0,0) --> (0,0,1,1,0,0)
  19991. optimize: function () {
  19992. var times = this.times,
  19993. values = this.values,
  19994. stride = this.getValueSize(),
  19995. smoothInterpolation = this.getInterpolation() === InterpolateSmooth,
  19996. writeIndex = 1,
  19997. lastIndex = times.length - 1;
  19998. for ( var i = 1; i < lastIndex; ++ i ) {
  19999. var keep = false;
  20000. var time = times[ i ];
  20001. var timeNext = times[ i + 1 ];
  20002. // remove adjacent keyframes scheduled at the same time
  20003. if ( time !== timeNext && ( i !== 1 || time !== time[ 0 ] ) ) {
  20004. if ( ! smoothInterpolation ) {
  20005. // remove unnecessary keyframes same as their neighbors
  20006. var offset = i * stride,
  20007. offsetP = offset - stride,
  20008. offsetN = offset + stride;
  20009. for ( var j = 0; j !== stride; ++ j ) {
  20010. var value = values[ offset + j ];
  20011. if ( value !== values[ offsetP + j ] ||
  20012. value !== values[ offsetN + j ] ) {
  20013. keep = true;
  20014. break;
  20015. }
  20016. }
  20017. } else {
  20018. keep = true;
  20019. }
  20020. }
  20021. // in-place compaction
  20022. if ( keep ) {
  20023. if ( i !== writeIndex ) {
  20024. times[ writeIndex ] = times[ i ];
  20025. var readOffset = i * stride,
  20026. writeOffset = writeIndex * stride;
  20027. for ( var j = 0; j !== stride; ++ j ) {
  20028. values[ writeOffset + j ] = values[ readOffset + j ];
  20029. }
  20030. }
  20031. ++ writeIndex;
  20032. }
  20033. }
  20034. // flush last keyframe (compaction looks ahead)
  20035. if ( lastIndex > 0 ) {
  20036. times[ writeIndex ] = times[ lastIndex ];
  20037. for ( var readOffset = lastIndex * stride, writeOffset = writeIndex * stride, j = 0; j !== stride; ++ j ) {
  20038. values[ writeOffset + j ] = values[ readOffset + j ];
  20039. }
  20040. ++ writeIndex;
  20041. }
  20042. if ( writeIndex !== times.length ) {
  20043. this.times = AnimationUtils.arraySlice( times, 0, writeIndex );
  20044. this.values = AnimationUtils.arraySlice( values, 0, writeIndex * stride );
  20045. }
  20046. return this;
  20047. },
  20048. clone: function () {
  20049. var times = AnimationUtils.arraySlice( this.times, 0 );
  20050. var values = AnimationUtils.arraySlice( this.values, 0 );
  20051. var TypedKeyframeTrack = this.constructor;
  20052. var track = new TypedKeyframeTrack( this.name, times, values );
  20053. // Interpolant argument to constructor is not saved, so copy the factory method directly.
  20054. track.createInterpolant = this.createInterpolant;
  20055. return track;
  20056. }
  20057. } );
  20058. /**
  20059. *
  20060. * A Track of Boolean keyframe values.
  20061. *
  20062. *
  20063. * @author Ben Houston / http://clara.io/
  20064. * @author David Sarno / http://lighthaus.us/
  20065. * @author tschw
  20066. */
  20067. function BooleanKeyframeTrack( name, times, values ) {
  20068. KeyframeTrack.call( this, name, times, values );
  20069. }
  20070. BooleanKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), {
  20071. constructor: BooleanKeyframeTrack,
  20072. ValueTypeName: 'bool',
  20073. ValueBufferType: Array,
  20074. DefaultInterpolation: InterpolateDiscrete,
  20075. InterpolantFactoryMethodLinear: undefined,
  20076. InterpolantFactoryMethodSmooth: undefined
  20077. // Note: Actually this track could have a optimized / compressed
  20078. // representation of a single value and a custom interpolant that
  20079. // computes "firstValue ^ isOdd( index )".
  20080. } );
  20081. /**
  20082. *
  20083. * A Track of keyframe values that represent color.
  20084. *
  20085. *
  20086. * @author Ben Houston / http://clara.io/
  20087. * @author David Sarno / http://lighthaus.us/
  20088. * @author tschw
  20089. */
  20090. function ColorKeyframeTrack( name, times, values, interpolation ) {
  20091. KeyframeTrack.call( this, name, times, values, interpolation );
  20092. }
  20093. ColorKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), {
  20094. constructor: ColorKeyframeTrack,
  20095. ValueTypeName: 'color'
  20096. // ValueBufferType is inherited
  20097. // DefaultInterpolation is inherited
  20098. // Note: Very basic implementation and nothing special yet.
  20099. // However, this is the place for color space parameterization.
  20100. } );
  20101. /**
  20102. *
  20103. * A Track of numeric keyframe values.
  20104. *
  20105. * @author Ben Houston / http://clara.io/
  20106. * @author David Sarno / http://lighthaus.us/
  20107. * @author tschw
  20108. */
  20109. function NumberKeyframeTrack( name, times, values, interpolation ) {
  20110. KeyframeTrack.call( this, name, times, values, interpolation );
  20111. }
  20112. NumberKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), {
  20113. constructor: NumberKeyframeTrack,
  20114. ValueTypeName: 'number'
  20115. // ValueBufferType is inherited
  20116. // DefaultInterpolation is inherited
  20117. } );
  20118. /**
  20119. * Spherical linear unit quaternion interpolant.
  20120. *
  20121. * @author tschw
  20122. */
  20123. function QuaternionLinearInterpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  20124. Interpolant.call( this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  20125. }
  20126. QuaternionLinearInterpolant.prototype = Object.assign( Object.create( Interpolant.prototype ), {
  20127. constructor: QuaternionLinearInterpolant,
  20128. interpolate_: function ( i1, t0, t, t1 ) {
  20129. var result = this.resultBuffer,
  20130. values = this.sampleValues,
  20131. stride = this.valueSize,
  20132. offset = i1 * stride,
  20133. alpha = ( t - t0 ) / ( t1 - t0 );
  20134. for ( var end = offset + stride; offset !== end; offset += 4 ) {
  20135. Quaternion.slerpFlat( result, 0, values, offset - stride, values, offset, alpha );
  20136. }
  20137. return result;
  20138. }
  20139. } );
  20140. /**
  20141. *
  20142. * A Track of quaternion keyframe values.
  20143. *
  20144. * @author Ben Houston / http://clara.io/
  20145. * @author David Sarno / http://lighthaus.us/
  20146. * @author tschw
  20147. */
  20148. function QuaternionKeyframeTrack( name, times, values, interpolation ) {
  20149. KeyframeTrack.call( this, name, times, values, interpolation );
  20150. }
  20151. QuaternionKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), {
  20152. constructor: QuaternionKeyframeTrack,
  20153. ValueTypeName: 'quaternion',
  20154. // ValueBufferType is inherited
  20155. DefaultInterpolation: InterpolateLinear,
  20156. InterpolantFactoryMethodLinear: function ( result ) {
  20157. return new QuaternionLinearInterpolant( this.times, this.values, this.getValueSize(), result );
  20158. },
  20159. InterpolantFactoryMethodSmooth: undefined // not yet implemented
  20160. } );
  20161. /**
  20162. *
  20163. * A Track that interpolates Strings
  20164. *
  20165. *
  20166. * @author Ben Houston / http://clara.io/
  20167. * @author David Sarno / http://lighthaus.us/
  20168. * @author tschw
  20169. */
  20170. function StringKeyframeTrack( name, times, values, interpolation ) {
  20171. KeyframeTrack.call( this, name, times, values, interpolation );
  20172. }
  20173. StringKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), {
  20174. constructor: StringKeyframeTrack,
  20175. ValueTypeName: 'string',
  20176. ValueBufferType: Array,
  20177. DefaultInterpolation: InterpolateDiscrete,
  20178. InterpolantFactoryMethodLinear: undefined,
  20179. InterpolantFactoryMethodSmooth: undefined
  20180. } );
  20181. /**
  20182. *
  20183. * A Track of vectored keyframe values.
  20184. *
  20185. *
  20186. * @author Ben Houston / http://clara.io/
  20187. * @author David Sarno / http://lighthaus.us/
  20188. * @author tschw
  20189. */
  20190. function VectorKeyframeTrack( name, times, values, interpolation ) {
  20191. KeyframeTrack.call( this, name, times, values, interpolation );
  20192. }
  20193. VectorKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), {
  20194. constructor: VectorKeyframeTrack,
  20195. ValueTypeName: 'vector'
  20196. // ValueBufferType is inherited
  20197. // DefaultInterpolation is inherited
  20198. } );
  20199. /**
  20200. *
  20201. * Reusable set of Tracks that represent an animation.
  20202. *
  20203. * @author Ben Houston / http://clara.io/
  20204. * @author David Sarno / http://lighthaus.us/
  20205. */
  20206. function AnimationClip( name, duration, tracks ) {
  20207. this.name = name;
  20208. this.tracks = tracks;
  20209. this.duration = ( duration !== undefined ) ? duration : - 1;
  20210. this.uuid = _Math.generateUUID();
  20211. // this means it should figure out its duration by scanning the tracks
  20212. if ( this.duration < 0 ) {
  20213. this.resetDuration();
  20214. }
  20215. }
  20216. function getTrackTypeForValueTypeName( typeName ) {
  20217. switch ( typeName.toLowerCase() ) {
  20218. case 'scalar':
  20219. case 'double':
  20220. case 'float':
  20221. case 'number':
  20222. case 'integer':
  20223. return NumberKeyframeTrack;
  20224. case 'vector':
  20225. case 'vector2':
  20226. case 'vector3':
  20227. case 'vector4':
  20228. return VectorKeyframeTrack;
  20229. case 'color':
  20230. return ColorKeyframeTrack;
  20231. case 'quaternion':
  20232. return QuaternionKeyframeTrack;
  20233. case 'bool':
  20234. case 'boolean':
  20235. return BooleanKeyframeTrack;
  20236. case 'string':
  20237. return StringKeyframeTrack;
  20238. }
  20239. throw new Error( 'THREE.KeyframeTrack: Unsupported typeName: ' + typeName );
  20240. }
  20241. function parseKeyframeTrack( json ) {
  20242. if ( json.type === undefined ) {
  20243. throw new Error( 'THREE.KeyframeTrack: track type undefined, can not parse' );
  20244. }
  20245. var trackType = getTrackTypeForValueTypeName( json.type );
  20246. if ( json.times === undefined ) {
  20247. var times = [], values = [];
  20248. AnimationUtils.flattenJSON( json.keys, times, values, 'value' );
  20249. json.times = times;
  20250. json.values = values;
  20251. }
  20252. // derived classes can define a static parse method
  20253. if ( trackType.parse !== undefined ) {
  20254. return trackType.parse( json );
  20255. } else {
  20256. // by default, we assume a constructor compatible with the base
  20257. return new trackType( json.name, json.times, json.values, json.interpolation );
  20258. }
  20259. }
  20260. Object.assign( AnimationClip, {
  20261. parse: function ( json ) {
  20262. var tracks = [],
  20263. jsonTracks = json.tracks,
  20264. frameTime = 1.0 / ( json.fps || 1.0 );
  20265. for ( var i = 0, n = jsonTracks.length; i !== n; ++ i ) {
  20266. tracks.push( parseKeyframeTrack( jsonTracks[ i ] ).scale( frameTime ) );
  20267. }
  20268. return new AnimationClip( json.name, json.duration, tracks );
  20269. },
  20270. toJSON: function ( clip ) {
  20271. var tracks = [],
  20272. clipTracks = clip.tracks;
  20273. var json = {
  20274. 'name': clip.name,
  20275. 'duration': clip.duration,
  20276. 'tracks': tracks,
  20277. 'uuid': clip.uuid
  20278. };
  20279. for ( var i = 0, n = clipTracks.length; i !== n; ++ i ) {
  20280. tracks.push( KeyframeTrack.toJSON( clipTracks[ i ] ) );
  20281. }
  20282. return json;
  20283. },
  20284. CreateFromMorphTargetSequence: function ( name, morphTargetSequence, fps, noLoop ) {
  20285. var numMorphTargets = morphTargetSequence.length;
  20286. var tracks = [];
  20287. for ( var i = 0; i < numMorphTargets; i ++ ) {
  20288. var times = [];
  20289. var values = [];
  20290. times.push(
  20291. ( i + numMorphTargets - 1 ) % numMorphTargets,
  20292. i,
  20293. ( i + 1 ) % numMorphTargets );
  20294. values.push( 0, 1, 0 );
  20295. var order = AnimationUtils.getKeyframeOrder( times );
  20296. times = AnimationUtils.sortedArray( times, 1, order );
  20297. values = AnimationUtils.sortedArray( values, 1, order );
  20298. // if there is a key at the first frame, duplicate it as the
  20299. // last frame as well for perfect loop.
  20300. if ( ! noLoop && times[ 0 ] === 0 ) {
  20301. times.push( numMorphTargets );
  20302. values.push( values[ 0 ] );
  20303. }
  20304. tracks.push(
  20305. new NumberKeyframeTrack(
  20306. '.morphTargetInfluences[' + morphTargetSequence[ i ].name + ']',
  20307. times, values
  20308. ).scale( 1.0 / fps ) );
  20309. }
  20310. return new AnimationClip( name, - 1, tracks );
  20311. },
  20312. findByName: function ( objectOrClipArray, name ) {
  20313. var clipArray = objectOrClipArray;
  20314. if ( ! Array.isArray( objectOrClipArray ) ) {
  20315. var o = objectOrClipArray;
  20316. clipArray = o.geometry && o.geometry.animations || o.animations;
  20317. }
  20318. for ( var i = 0; i < clipArray.length; i ++ ) {
  20319. if ( clipArray[ i ].name === name ) {
  20320. return clipArray[ i ];
  20321. }
  20322. }
  20323. return null;
  20324. },
  20325. CreateClipsFromMorphTargetSequences: function ( morphTargets, fps, noLoop ) {
  20326. var animationToMorphTargets = {};
  20327. // tested with https://regex101.com/ on trick sequences
  20328. // such flamingo_flyA_003, flamingo_run1_003, crdeath0059
  20329. var pattern = /^([\w-]*?)([\d]+)$/;
  20330. // sort morph target names into animation groups based
  20331. // patterns like Walk_001, Walk_002, Run_001, Run_002
  20332. for ( var i = 0, il = morphTargets.length; i < il; i ++ ) {
  20333. var morphTarget = morphTargets[ i ];
  20334. var parts = morphTarget.name.match( pattern );
  20335. if ( parts && parts.length > 1 ) {
  20336. var name = parts[ 1 ];
  20337. var animationMorphTargets = animationToMorphTargets[ name ];
  20338. if ( ! animationMorphTargets ) {
  20339. animationToMorphTargets[ name ] = animationMorphTargets = [];
  20340. }
  20341. animationMorphTargets.push( morphTarget );
  20342. }
  20343. }
  20344. var clips = [];
  20345. for ( var name in animationToMorphTargets ) {
  20346. clips.push( AnimationClip.CreateFromMorphTargetSequence( name, animationToMorphTargets[ name ], fps, noLoop ) );
  20347. }
  20348. return clips;
  20349. },
  20350. // parse the animation.hierarchy format
  20351. parseAnimation: function ( animation, bones ) {
  20352. if ( ! animation ) {
  20353. console.error( 'THREE.AnimationClip: No animation in JSONLoader data.' );
  20354. return null;
  20355. }
  20356. var addNonemptyTrack = function ( trackType, trackName, animationKeys, propertyName, destTracks ) {
  20357. // only return track if there are actually keys.
  20358. if ( animationKeys.length !== 0 ) {
  20359. var times = [];
  20360. var values = [];
  20361. AnimationUtils.flattenJSON( animationKeys, times, values, propertyName );
  20362. // empty keys are filtered out, so check again
  20363. if ( times.length !== 0 ) {
  20364. destTracks.push( new trackType( trackName, times, values ) );
  20365. }
  20366. }
  20367. };
  20368. var tracks = [];
  20369. var clipName = animation.name || 'default';
  20370. // automatic length determination in AnimationClip.
  20371. var duration = animation.length || - 1;
  20372. var fps = animation.fps || 30;
  20373. var hierarchyTracks = animation.hierarchy || [];
  20374. for ( var h = 0; h < hierarchyTracks.length; h ++ ) {
  20375. var animationKeys = hierarchyTracks[ h ].keys;
  20376. // skip empty tracks
  20377. if ( ! animationKeys || animationKeys.length === 0 ) continue;
  20378. // process morph targets
  20379. if ( animationKeys[ 0 ].morphTargets ) {
  20380. // figure out all morph targets used in this track
  20381. var morphTargetNames = {};
  20382. for ( var k = 0; k < animationKeys.length; k ++ ) {
  20383. if ( animationKeys[ k ].morphTargets ) {
  20384. for ( var m = 0; m < animationKeys[ k ].morphTargets.length; m ++ ) {
  20385. morphTargetNames[ animationKeys[ k ].morphTargets[ m ] ] = - 1;
  20386. }
  20387. }
  20388. }
  20389. // create a track for each morph target with all zero
  20390. // morphTargetInfluences except for the keys in which
  20391. // the morphTarget is named.
  20392. for ( var morphTargetName in morphTargetNames ) {
  20393. var times = [];
  20394. var values = [];
  20395. for ( var m = 0; m !== animationKeys[ k ].morphTargets.length; ++ m ) {
  20396. var animationKey = animationKeys[ k ];
  20397. times.push( animationKey.time );
  20398. values.push( ( animationKey.morphTarget === morphTargetName ) ? 1 : 0 );
  20399. }
  20400. tracks.push( new NumberKeyframeTrack( '.morphTargetInfluence[' + morphTargetName + ']', times, values ) );
  20401. }
  20402. duration = morphTargetNames.length * ( fps || 1.0 );
  20403. } else {
  20404. // ...assume skeletal animation
  20405. var boneName = '.bones[' + bones[ h ].name + ']';
  20406. addNonemptyTrack(
  20407. VectorKeyframeTrack, boneName + '.position',
  20408. animationKeys, 'pos', tracks );
  20409. addNonemptyTrack(
  20410. QuaternionKeyframeTrack, boneName + '.quaternion',
  20411. animationKeys, 'rot', tracks );
  20412. addNonemptyTrack(
  20413. VectorKeyframeTrack, boneName + '.scale',
  20414. animationKeys, 'scl', tracks );
  20415. }
  20416. }
  20417. if ( tracks.length === 0 ) {
  20418. return null;
  20419. }
  20420. var clip = new AnimationClip( clipName, duration, tracks );
  20421. return clip;
  20422. }
  20423. } );
  20424. Object.assign( AnimationClip.prototype, {
  20425. resetDuration: function () {
  20426. var tracks = this.tracks, duration = 0;
  20427. for ( var i = 0, n = tracks.length; i !== n; ++ i ) {
  20428. var track = this.tracks[ i ];
  20429. duration = Math.max( duration, track.times[ track.times.length - 1 ] );
  20430. }
  20431. this.duration = duration;
  20432. return this;
  20433. },
  20434. trim: function () {
  20435. for ( var i = 0; i < this.tracks.length; i ++ ) {
  20436. this.tracks[ i ].trim( 0, this.duration );
  20437. }
  20438. return this;
  20439. },
  20440. validate: function () {
  20441. var valid = true;
  20442. for ( var i = 0; i < this.tracks.length; i ++ ) {
  20443. valid = valid && this.tracks[ i ].validate();
  20444. }
  20445. return valid;
  20446. },
  20447. optimize: function () {
  20448. for ( var i = 0; i < this.tracks.length; i ++ ) {
  20449. this.tracks[ i ].optimize();
  20450. }
  20451. return this;
  20452. },
  20453. clone: function () {
  20454. var tracks = [];
  20455. for ( var i = 0; i < this.tracks.length; i ++ ) {
  20456. tracks.push( this.tracks[ i ].clone() );
  20457. }
  20458. return new AnimationClip( this.name, this.duration, tracks );
  20459. }
  20460. } );
  20461. /**
  20462. * @author mrdoob / http://mrdoob.com/
  20463. */
  20464. var Cache = {
  20465. enabled: false,
  20466. files: {},
  20467. add: function ( key, file ) {
  20468. if ( this.enabled === false ) return;
  20469. // console.log( 'THREE.Cache', 'Adding key:', key );
  20470. this.files[ key ] = file;
  20471. },
  20472. get: function ( key ) {
  20473. if ( this.enabled === false ) return;
  20474. // console.log( 'THREE.Cache', 'Checking key:', key );
  20475. return this.files[ key ];
  20476. },
  20477. remove: function ( key ) {
  20478. delete this.files[ key ];
  20479. },
  20480. clear: function () {
  20481. this.files = {};
  20482. }
  20483. };
  20484. /**
  20485. * @author mrdoob / http://mrdoob.com/
  20486. */
  20487. function LoadingManager( onLoad, onProgress, onError ) {
  20488. var scope = this;
  20489. var isLoading = false;
  20490. var itemsLoaded = 0;
  20491. var itemsTotal = 0;
  20492. var urlModifier = undefined;
  20493. // Refer to #5689 for the reason why we don't set .onStart
  20494. // in the constructor
  20495. this.onStart = undefined;
  20496. this.onLoad = onLoad;
  20497. this.onProgress = onProgress;
  20498. this.onError = onError;
  20499. this.itemStart = function ( url ) {
  20500. itemsTotal ++;
  20501. if ( isLoading === false ) {
  20502. if ( scope.onStart !== undefined ) {
  20503. scope.onStart( url, itemsLoaded, itemsTotal );
  20504. }
  20505. }
  20506. isLoading = true;
  20507. };
  20508. this.itemEnd = function ( url ) {
  20509. itemsLoaded ++;
  20510. if ( scope.onProgress !== undefined ) {
  20511. scope.onProgress( url, itemsLoaded, itemsTotal );
  20512. }
  20513. if ( itemsLoaded === itemsTotal ) {
  20514. isLoading = false;
  20515. if ( scope.onLoad !== undefined ) {
  20516. scope.onLoad();
  20517. }
  20518. }
  20519. };
  20520. this.itemError = function ( url ) {
  20521. if ( scope.onError !== undefined ) {
  20522. scope.onError( url );
  20523. }
  20524. };
  20525. this.resolveURL = function ( url ) {
  20526. if ( urlModifier ) {
  20527. return urlModifier( url );
  20528. }
  20529. return url;
  20530. };
  20531. this.setURLModifier = function ( transform ) {
  20532. urlModifier = transform;
  20533. return this;
  20534. };
  20535. }
  20536. var DefaultLoadingManager = new LoadingManager();
  20537. /**
  20538. * @author mrdoob / http://mrdoob.com/
  20539. */
  20540. var loading = {};
  20541. function FileLoader( manager ) {
  20542. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  20543. }
  20544. Object.assign( FileLoader.prototype, {
  20545. load: function ( url, onLoad, onProgress, onError ) {
  20546. if ( url === undefined ) url = '';
  20547. if ( this.path !== undefined ) url = this.path + url;
  20548. url = this.manager.resolveURL( url );
  20549. var scope = this;
  20550. var cached = Cache.get( url );
  20551. if ( cached !== undefined ) {
  20552. scope.manager.itemStart( url );
  20553. setTimeout( function () {
  20554. if ( onLoad ) onLoad( cached );
  20555. scope.manager.itemEnd( url );
  20556. }, 0 );
  20557. return cached;
  20558. }
  20559. // Check if request is duplicate
  20560. if ( loading[ url ] !== undefined ) {
  20561. loading[ url ].push( {
  20562. onLoad: onLoad,
  20563. onProgress: onProgress,
  20564. onError: onError
  20565. } );
  20566. return;
  20567. }
  20568. // Check for data: URI
  20569. var dataUriRegex = /^data:(.*?)(;base64)?,(.*)$/;
  20570. var dataUriRegexResult = url.match( dataUriRegex );
  20571. // Safari can not handle Data URIs through XMLHttpRequest so process manually
  20572. if ( dataUriRegexResult ) {
  20573. var mimeType = dataUriRegexResult[ 1 ];
  20574. var isBase64 = !! dataUriRegexResult[ 2 ];
  20575. var data = dataUriRegexResult[ 3 ];
  20576. data = decodeURIComponent( data );
  20577. if ( isBase64 ) data = atob( data );
  20578. try {
  20579. var response;
  20580. var responseType = ( this.responseType || '' ).toLowerCase();
  20581. switch ( responseType ) {
  20582. case 'arraybuffer':
  20583. case 'blob':
  20584. var view = new Uint8Array( data.length );
  20585. for ( var i = 0; i < data.length; i ++ ) {
  20586. view[ i ] = data.charCodeAt( i );
  20587. }
  20588. if ( responseType === 'blob' ) {
  20589. response = new Blob( [ view.buffer ], { type: mimeType } );
  20590. } else {
  20591. response = view.buffer;
  20592. }
  20593. break;
  20594. case 'document':
  20595. var parser = new DOMParser();
  20596. response = parser.parseFromString( data, mimeType );
  20597. break;
  20598. case 'json':
  20599. response = JSON.parse( data );
  20600. break;
  20601. default: // 'text' or other
  20602. response = data;
  20603. break;
  20604. }
  20605. // Wait for next browser tick like standard XMLHttpRequest event dispatching does
  20606. setTimeout( function () {
  20607. if ( onLoad ) onLoad( response );
  20608. scope.manager.itemEnd( url );
  20609. }, 0 );
  20610. } catch ( error ) {
  20611. // Wait for next browser tick like standard XMLHttpRequest event dispatching does
  20612. setTimeout( function () {
  20613. if ( onError ) onError( error );
  20614. scope.manager.itemError( url );
  20615. scope.manager.itemEnd( url );
  20616. }, 0 );
  20617. }
  20618. } else {
  20619. // Initialise array for duplicate requests
  20620. loading[ url ] = [];
  20621. loading[ url ].push( {
  20622. onLoad: onLoad,
  20623. onProgress: onProgress,
  20624. onError: onError
  20625. } );
  20626. var request = new XMLHttpRequest();
  20627. request.open( 'GET', url, true );
  20628. request.addEventListener( 'load', function ( event ) {
  20629. var response = this.response;
  20630. Cache.add( url, response );
  20631. var callbacks = loading[ url ];
  20632. delete loading[ url ];
  20633. if ( this.status === 200 || this.status === 0 ) {
  20634. // Some browsers return HTTP Status 0 when using non-http protocol
  20635. // e.g. 'file://' or 'data://'. Handle as success.
  20636. if ( this.status === 0 ) console.warn( 'THREE.FileLoader: HTTP Status 0 received.' );
  20637. for ( var i = 0, il = callbacks.length; i < il; i ++ ) {
  20638. var callback = callbacks[ i ];
  20639. if ( callback.onLoad ) callback.onLoad( response );
  20640. }
  20641. scope.manager.itemEnd( url );
  20642. } else {
  20643. for ( var i = 0, il = callbacks.length; i < il; i ++ ) {
  20644. var callback = callbacks[ i ];
  20645. if ( callback.onError ) callback.onError( event );
  20646. }
  20647. scope.manager.itemError( url );
  20648. scope.manager.itemEnd( url );
  20649. }
  20650. }, false );
  20651. request.addEventListener( 'progress', function ( event ) {
  20652. var callbacks = loading[ url ];
  20653. for ( var i = 0, il = callbacks.length; i < il; i ++ ) {
  20654. var callback = callbacks[ i ];
  20655. if ( callback.onProgress ) callback.onProgress( event );
  20656. }
  20657. }, false );
  20658. request.addEventListener( 'error', function ( event ) {
  20659. var callbacks = loading[ url ];
  20660. delete loading[ url ];
  20661. for ( var i = 0, il = callbacks.length; i < il; i ++ ) {
  20662. var callback = callbacks[ i ];
  20663. if ( callback.onError ) callback.onError( event );
  20664. }
  20665. scope.manager.itemError( url );
  20666. scope.manager.itemEnd( url );
  20667. }, false );
  20668. request.addEventListener( 'abort', function ( event ) {
  20669. var callbacks = loading[ url ];
  20670. delete loading[ url ];
  20671. for ( var i = 0, il = callbacks.length; i < il; i ++ ) {
  20672. var callback = callbacks[ i ];
  20673. if ( callback.onError ) callback.onError( event );
  20674. }
  20675. scope.manager.itemError( url );
  20676. scope.manager.itemEnd( url );
  20677. }, false );
  20678. if ( this.responseType !== undefined ) request.responseType = this.responseType;
  20679. if ( this.withCredentials !== undefined ) request.withCredentials = this.withCredentials;
  20680. if ( request.overrideMimeType ) request.overrideMimeType( this.mimeType !== undefined ? this.mimeType : 'text/plain' );
  20681. for ( var header in this.requestHeader ) {
  20682. request.setRequestHeader( header, this.requestHeader[ header ] );
  20683. }
  20684. request.send( null );
  20685. }
  20686. scope.manager.itemStart( url );
  20687. return request;
  20688. },
  20689. setPath: function ( value ) {
  20690. this.path = value;
  20691. return this;
  20692. },
  20693. setResponseType: function ( value ) {
  20694. this.responseType = value;
  20695. return this;
  20696. },
  20697. setWithCredentials: function ( value ) {
  20698. this.withCredentials = value;
  20699. return this;
  20700. },
  20701. setMimeType: function ( value ) {
  20702. this.mimeType = value;
  20703. return this;
  20704. },
  20705. setRequestHeader: function ( value ) {
  20706. this.requestHeader = value;
  20707. return this;
  20708. }
  20709. } );
  20710. /**
  20711. * @author bhouston / http://clara.io/
  20712. */
  20713. function AnimationLoader( manager ) {
  20714. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  20715. }
  20716. Object.assign( AnimationLoader.prototype, {
  20717. load: function ( url, onLoad, onProgress, onError ) {
  20718. var scope = this;
  20719. var loader = new FileLoader( scope.manager );
  20720. loader.setPath( scope.path );
  20721. loader.load( url, function ( text ) {
  20722. onLoad( scope.parse( JSON.parse( text ) ) );
  20723. }, onProgress, onError );
  20724. },
  20725. parse: function ( json ) {
  20726. var animations = [];
  20727. for ( var i = 0; i < json.length; i ++ ) {
  20728. var clip = AnimationClip.parse( json[ i ] );
  20729. animations.push( clip );
  20730. }
  20731. return animations;
  20732. },
  20733. setPath: function ( value ) {
  20734. this.path = value;
  20735. return this;
  20736. }
  20737. } );
  20738. /**
  20739. * @author mrdoob / http://mrdoob.com/
  20740. *
  20741. * Abstract Base class to block based textures loader (dds, pvr, ...)
  20742. */
  20743. function CompressedTextureLoader( manager ) {
  20744. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  20745. // override in sub classes
  20746. this._parser = null;
  20747. }
  20748. Object.assign( CompressedTextureLoader.prototype, {
  20749. load: function ( url, onLoad, onProgress, onError ) {
  20750. var scope = this;
  20751. var images = [];
  20752. var texture = new CompressedTexture();
  20753. texture.image = images;
  20754. var loader = new FileLoader( this.manager );
  20755. loader.setPath( this.path );
  20756. loader.setResponseType( 'arraybuffer' );
  20757. function loadTexture( i ) {
  20758. loader.load( url[ i ], function ( buffer ) {
  20759. var texDatas = scope._parser( buffer, true );
  20760. images[ i ] = {
  20761. width: texDatas.width,
  20762. height: texDatas.height,
  20763. format: texDatas.format,
  20764. mipmaps: texDatas.mipmaps
  20765. };
  20766. loaded += 1;
  20767. if ( loaded === 6 ) {
  20768. if ( texDatas.mipmapCount === 1 )
  20769. texture.minFilter = LinearFilter;
  20770. texture.format = texDatas.format;
  20771. texture.needsUpdate = true;
  20772. if ( onLoad ) onLoad( texture );
  20773. }
  20774. }, onProgress, onError );
  20775. }
  20776. if ( Array.isArray( url ) ) {
  20777. var loaded = 0;
  20778. for ( var i = 0, il = url.length; i < il; ++ i ) {
  20779. loadTexture( i );
  20780. }
  20781. } else {
  20782. // compressed cubemap texture stored in a single DDS file
  20783. loader.load( url, function ( buffer ) {
  20784. var texDatas = scope._parser( buffer, true );
  20785. if ( texDatas.isCubemap ) {
  20786. var faces = texDatas.mipmaps.length / texDatas.mipmapCount;
  20787. for ( var f = 0; f < faces; f ++ ) {
  20788. images[ f ] = { mipmaps: [] };
  20789. for ( var i = 0; i < texDatas.mipmapCount; i ++ ) {
  20790. images[ f ].mipmaps.push( texDatas.mipmaps[ f * texDatas.mipmapCount + i ] );
  20791. images[ f ].format = texDatas.format;
  20792. images[ f ].width = texDatas.width;
  20793. images[ f ].height = texDatas.height;
  20794. }
  20795. }
  20796. } else {
  20797. texture.image.width = texDatas.width;
  20798. texture.image.height = texDatas.height;
  20799. texture.mipmaps = texDatas.mipmaps;
  20800. }
  20801. if ( texDatas.mipmapCount === 1 ) {
  20802. texture.minFilter = LinearFilter;
  20803. }
  20804. texture.format = texDatas.format;
  20805. texture.needsUpdate = true;
  20806. if ( onLoad ) onLoad( texture );
  20807. }, onProgress, onError );
  20808. }
  20809. return texture;
  20810. },
  20811. setPath: function ( value ) {
  20812. this.path = value;
  20813. return this;
  20814. }
  20815. } );
  20816. /**
  20817. * @author Nikos M. / https://github.com/foo123/
  20818. *
  20819. * Abstract Base class to load generic binary textures formats (rgbe, hdr, ...)
  20820. */
  20821. function DataTextureLoader( manager ) {
  20822. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  20823. // override in sub classes
  20824. this._parser = null;
  20825. }
  20826. Object.assign( DataTextureLoader.prototype, {
  20827. load: function ( url, onLoad, onProgress, onError ) {
  20828. var scope = this;
  20829. var texture = new DataTexture();
  20830. var loader = new FileLoader( this.manager );
  20831. loader.setResponseType( 'arraybuffer' );
  20832. loader.setPath( this.path );
  20833. loader.load( url, function ( buffer ) {
  20834. var texData = scope._parser( buffer );
  20835. if ( ! texData ) return;
  20836. if ( texData.image !== undefined ) {
  20837. texture.image = texData.image;
  20838. } else if ( texData.data !== undefined ) {
  20839. texture.image.width = texData.width;
  20840. texture.image.height = texData.height;
  20841. texture.image.data = texData.data;
  20842. }
  20843. texture.wrapS = texData.wrapS !== undefined ? texData.wrapS : ClampToEdgeWrapping;
  20844. texture.wrapT = texData.wrapT !== undefined ? texData.wrapT : ClampToEdgeWrapping;
  20845. texture.magFilter = texData.magFilter !== undefined ? texData.magFilter : LinearFilter;
  20846. texture.minFilter = texData.minFilter !== undefined ? texData.minFilter : LinearMipMapLinearFilter;
  20847. texture.anisotropy = texData.anisotropy !== undefined ? texData.anisotropy : 1;
  20848. if ( texData.format !== undefined ) {
  20849. texture.format = texData.format;
  20850. }
  20851. if ( texData.type !== undefined ) {
  20852. texture.type = texData.type;
  20853. }
  20854. if ( texData.mipmaps !== undefined ) {
  20855. texture.mipmaps = texData.mipmaps;
  20856. }
  20857. if ( texData.mipmapCount === 1 ) {
  20858. texture.minFilter = LinearFilter;
  20859. }
  20860. texture.needsUpdate = true;
  20861. if ( onLoad ) onLoad( texture, texData );
  20862. }, onProgress, onError );
  20863. return texture;
  20864. },
  20865. setPath: function ( value ) {
  20866. this.path = value;
  20867. return this;
  20868. }
  20869. } );
  20870. /**
  20871. * @author mrdoob / http://mrdoob.com/
  20872. */
  20873. function ImageLoader( manager ) {
  20874. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  20875. }
  20876. Object.assign( ImageLoader.prototype, {
  20877. crossOrigin: 'anonymous',
  20878. load: function ( url, onLoad, onProgress, onError ) {
  20879. if ( url === undefined ) url = '';
  20880. if ( this.path !== undefined ) url = this.path + url;
  20881. url = this.manager.resolveURL( url );
  20882. var scope = this;
  20883. var cached = Cache.get( url );
  20884. if ( cached !== undefined ) {
  20885. scope.manager.itemStart( url );
  20886. setTimeout( function () {
  20887. if ( onLoad ) onLoad( cached );
  20888. scope.manager.itemEnd( url );
  20889. }, 0 );
  20890. return cached;
  20891. }
  20892. var image = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'img' );
  20893. function onImageLoad() {
  20894. image.removeEventListener( 'load', onImageLoad, false );
  20895. image.removeEventListener( 'error', onImageError, false );
  20896. Cache.add( url, this );
  20897. if ( onLoad ) onLoad( this );
  20898. scope.manager.itemEnd( url );
  20899. }
  20900. function onImageError( event ) {
  20901. image.removeEventListener( 'load', onImageLoad, false );
  20902. image.removeEventListener( 'error', onImageError, false );
  20903. if ( onError ) onError( event );
  20904. scope.manager.itemError( url );
  20905. scope.manager.itemEnd( url );
  20906. }
  20907. image.addEventListener( 'load', onImageLoad, false );
  20908. image.addEventListener( 'error', onImageError, false );
  20909. if ( url.substr( 0, 5 ) !== 'data:' ) {
  20910. if ( this.crossOrigin !== undefined ) image.crossOrigin = this.crossOrigin;
  20911. }
  20912. scope.manager.itemStart( url );
  20913. image.src = url;
  20914. return image;
  20915. },
  20916. setCrossOrigin: function ( value ) {
  20917. this.crossOrigin = value;
  20918. return this;
  20919. },
  20920. setPath: function ( value ) {
  20921. this.path = value;
  20922. return this;
  20923. }
  20924. } );
  20925. /**
  20926. * @author mrdoob / http://mrdoob.com/
  20927. */
  20928. function CubeTextureLoader( manager ) {
  20929. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  20930. }
  20931. Object.assign( CubeTextureLoader.prototype, {
  20932. crossOrigin: 'anonymous',
  20933. load: function ( urls, onLoad, onProgress, onError ) {
  20934. var texture = new CubeTexture();
  20935. var loader = new ImageLoader( this.manager );
  20936. loader.setCrossOrigin( this.crossOrigin );
  20937. loader.setPath( this.path );
  20938. var loaded = 0;
  20939. function loadTexture( i ) {
  20940. loader.load( urls[ i ], function ( image ) {
  20941. texture.images[ i ] = image;
  20942. loaded ++;
  20943. if ( loaded === 6 ) {
  20944. texture.needsUpdate = true;
  20945. if ( onLoad ) onLoad( texture );
  20946. }
  20947. }, undefined, onError );
  20948. }
  20949. for ( var i = 0; i < urls.length; ++ i ) {
  20950. loadTexture( i );
  20951. }
  20952. return texture;
  20953. },
  20954. setCrossOrigin: function ( value ) {
  20955. this.crossOrigin = value;
  20956. return this;
  20957. },
  20958. setPath: function ( value ) {
  20959. this.path = value;
  20960. return this;
  20961. }
  20962. } );
  20963. /**
  20964. * @author mrdoob / http://mrdoob.com/
  20965. */
  20966. function TextureLoader( manager ) {
  20967. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  20968. }
  20969. Object.assign( TextureLoader.prototype, {
  20970. crossOrigin: 'anonymous',
  20971. load: function ( url, onLoad, onProgress, onError ) {
  20972. var texture = new Texture();
  20973. var loader = new ImageLoader( this.manager );
  20974. loader.setCrossOrigin( this.crossOrigin );
  20975. loader.setPath( this.path );
  20976. loader.load( url, function ( image ) {
  20977. texture.image = image;
  20978. // JPEGs can't have an alpha channel, so memory can be saved by storing them as RGB.
  20979. var isJPEG = url.search( /\.jpe?g($|\?)/i ) > 0 || url.search( /^data\:image\/jpeg/ ) === 0;
  20980. texture.format = isJPEG ? RGBFormat : RGBAFormat;
  20981. texture.needsUpdate = true;
  20982. if ( onLoad !== undefined ) {
  20983. onLoad( texture );
  20984. }
  20985. }, onProgress, onError );
  20986. return texture;
  20987. },
  20988. setCrossOrigin: function ( value ) {
  20989. this.crossOrigin = value;
  20990. return this;
  20991. },
  20992. setPath: function ( value ) {
  20993. this.path = value;
  20994. return this;
  20995. }
  20996. } );
  20997. /**
  20998. * @author zz85 / http://www.lab4games.net/zz85/blog
  20999. * Extensible curve object
  21000. *
  21001. * Some common of curve methods:
  21002. * .getPoint( t, optionalTarget ), .getTangent( t )
  21003. * .getPointAt( u, optionalTarget ), .getTangentAt( u )
  21004. * .getPoints(), .getSpacedPoints()
  21005. * .getLength()
  21006. * .updateArcLengths()
  21007. *
  21008. * This following curves inherit from THREE.Curve:
  21009. *
  21010. * -- 2D curves --
  21011. * THREE.ArcCurve
  21012. * THREE.CubicBezierCurve
  21013. * THREE.EllipseCurve
  21014. * THREE.LineCurve
  21015. * THREE.QuadraticBezierCurve
  21016. * THREE.SplineCurve
  21017. *
  21018. * -- 3D curves --
  21019. * THREE.CatmullRomCurve3
  21020. * THREE.CubicBezierCurve3
  21021. * THREE.LineCurve3
  21022. * THREE.QuadraticBezierCurve3
  21023. *
  21024. * A series of curves can be represented as a THREE.CurvePath.
  21025. *
  21026. **/
  21027. /**************************************************************
  21028. * Abstract Curve base class
  21029. **************************************************************/
  21030. function Curve() {
  21031. this.type = 'Curve';
  21032. this.arcLengthDivisions = 200;
  21033. }
  21034. Object.assign( Curve.prototype, {
  21035. // Virtual base class method to overwrite and implement in subclasses
  21036. // - t [0 .. 1]
  21037. getPoint: function ( /* t, optionalTarget */ ) {
  21038. console.warn( 'THREE.Curve: .getPoint() not implemented.' );
  21039. return null;
  21040. },
  21041. // Get point at relative position in curve according to arc length
  21042. // - u [0 .. 1]
  21043. getPointAt: function ( u, optionalTarget ) {
  21044. var t = this.getUtoTmapping( u );
  21045. return this.getPoint( t, optionalTarget );
  21046. },
  21047. // Get sequence of points using getPoint( t )
  21048. getPoints: function ( divisions ) {
  21049. if ( divisions === undefined ) divisions = 5;
  21050. var points = [];
  21051. for ( var d = 0; d <= divisions; d ++ ) {
  21052. points.push( this.getPoint( d / divisions ) );
  21053. }
  21054. return points;
  21055. },
  21056. // Get sequence of points using getPointAt( u )
  21057. getSpacedPoints: function ( divisions ) {
  21058. if ( divisions === undefined ) divisions = 5;
  21059. var points = [];
  21060. for ( var d = 0; d <= divisions; d ++ ) {
  21061. points.push( this.getPointAt( d / divisions ) );
  21062. }
  21063. return points;
  21064. },
  21065. // Get total curve arc length
  21066. getLength: function () {
  21067. var lengths = this.getLengths();
  21068. return lengths[ lengths.length - 1 ];
  21069. },
  21070. // Get list of cumulative segment lengths
  21071. getLengths: function ( divisions ) {
  21072. if ( divisions === undefined ) divisions = this.arcLengthDivisions;
  21073. if ( this.cacheArcLengths &&
  21074. ( this.cacheArcLengths.length === divisions + 1 ) &&
  21075. ! this.needsUpdate ) {
  21076. return this.cacheArcLengths;
  21077. }
  21078. this.needsUpdate = false;
  21079. var cache = [];
  21080. var current, last = this.getPoint( 0 );
  21081. var p, sum = 0;
  21082. cache.push( 0 );
  21083. for ( p = 1; p <= divisions; p ++ ) {
  21084. current = this.getPoint( p / divisions );
  21085. sum += current.distanceTo( last );
  21086. cache.push( sum );
  21087. last = current;
  21088. }
  21089. this.cacheArcLengths = cache;
  21090. return cache; // { sums: cache, sum: sum }; Sum is in the last element.
  21091. },
  21092. updateArcLengths: function () {
  21093. this.needsUpdate = true;
  21094. this.getLengths();
  21095. },
  21096. // Given u ( 0 .. 1 ), get a t to find p. This gives you points which are equidistant
  21097. getUtoTmapping: function ( u, distance ) {
  21098. var arcLengths = this.getLengths();
  21099. var i = 0, il = arcLengths.length;
  21100. var targetArcLength; // The targeted u distance value to get
  21101. if ( distance ) {
  21102. targetArcLength = distance;
  21103. } else {
  21104. targetArcLength = u * arcLengths[ il - 1 ];
  21105. }
  21106. // binary search for the index with largest value smaller than target u distance
  21107. var low = 0, high = il - 1, comparison;
  21108. while ( low <= high ) {
  21109. 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
  21110. comparison = arcLengths[ i ] - targetArcLength;
  21111. if ( comparison < 0 ) {
  21112. low = i + 1;
  21113. } else if ( comparison > 0 ) {
  21114. high = i - 1;
  21115. } else {
  21116. high = i;
  21117. break;
  21118. // DONE
  21119. }
  21120. }
  21121. i = high;
  21122. if ( arcLengths[ i ] === targetArcLength ) {
  21123. return i / ( il - 1 );
  21124. }
  21125. // we could get finer grain at lengths, or use simple interpolation between two points
  21126. var lengthBefore = arcLengths[ i ];
  21127. var lengthAfter = arcLengths[ i + 1 ];
  21128. var segmentLength = lengthAfter - lengthBefore;
  21129. // determine where we are between the 'before' and 'after' points
  21130. var segmentFraction = ( targetArcLength - lengthBefore ) / segmentLength;
  21131. // add that fractional amount to t
  21132. var t = ( i + segmentFraction ) / ( il - 1 );
  21133. return t;
  21134. },
  21135. // Returns a unit vector tangent at t
  21136. // In case any sub curve does not implement its tangent derivation,
  21137. // 2 points a small delta apart will be used to find its gradient
  21138. // which seems to give a reasonable approximation
  21139. getTangent: function ( t ) {
  21140. var delta = 0.0001;
  21141. var t1 = t - delta;
  21142. var t2 = t + delta;
  21143. // Capping in case of danger
  21144. if ( t1 < 0 ) t1 = 0;
  21145. if ( t2 > 1 ) t2 = 1;
  21146. var pt1 = this.getPoint( t1 );
  21147. var pt2 = this.getPoint( t2 );
  21148. var vec = pt2.clone().sub( pt1 );
  21149. return vec.normalize();
  21150. },
  21151. getTangentAt: function ( u ) {
  21152. var t = this.getUtoTmapping( u );
  21153. return this.getTangent( t );
  21154. },
  21155. computeFrenetFrames: function ( segments, closed ) {
  21156. // see http://www.cs.indiana.edu/pub/techreports/TR425.pdf
  21157. var normal = new Vector3();
  21158. var tangents = [];
  21159. var normals = [];
  21160. var binormals = [];
  21161. var vec = new Vector3();
  21162. var mat = new Matrix4();
  21163. var i, u, theta;
  21164. // compute the tangent vectors for each segment on the curve
  21165. for ( i = 0; i <= segments; i ++ ) {
  21166. u = i / segments;
  21167. tangents[ i ] = this.getTangentAt( u );
  21168. tangents[ i ].normalize();
  21169. }
  21170. // select an initial normal vector perpendicular to the first tangent vector,
  21171. // and in the direction of the minimum tangent xyz component
  21172. normals[ 0 ] = new Vector3();
  21173. binormals[ 0 ] = new Vector3();
  21174. var min = Number.MAX_VALUE;
  21175. var tx = Math.abs( tangents[ 0 ].x );
  21176. var ty = Math.abs( tangents[ 0 ].y );
  21177. var tz = Math.abs( tangents[ 0 ].z );
  21178. if ( tx <= min ) {
  21179. min = tx;
  21180. normal.set( 1, 0, 0 );
  21181. }
  21182. if ( ty <= min ) {
  21183. min = ty;
  21184. normal.set( 0, 1, 0 );
  21185. }
  21186. if ( tz <= min ) {
  21187. normal.set( 0, 0, 1 );
  21188. }
  21189. vec.crossVectors( tangents[ 0 ], normal ).normalize();
  21190. normals[ 0 ].crossVectors( tangents[ 0 ], vec );
  21191. binormals[ 0 ].crossVectors( tangents[ 0 ], normals[ 0 ] );
  21192. // compute the slowly-varying normal and binormal vectors for each segment on the curve
  21193. for ( i = 1; i <= segments; i ++ ) {
  21194. normals[ i ] = normals[ i - 1 ].clone();
  21195. binormals[ i ] = binormals[ i - 1 ].clone();
  21196. vec.crossVectors( tangents[ i - 1 ], tangents[ i ] );
  21197. if ( vec.length() > Number.EPSILON ) {
  21198. vec.normalize();
  21199. theta = Math.acos( _Math.clamp( tangents[ i - 1 ].dot( tangents[ i ] ), - 1, 1 ) ); // clamp for floating pt errors
  21200. normals[ i ].applyMatrix4( mat.makeRotationAxis( vec, theta ) );
  21201. }
  21202. binormals[ i ].crossVectors( tangents[ i ], normals[ i ] );
  21203. }
  21204. // if the curve is closed, postprocess the vectors so the first and last normal vectors are the same
  21205. if ( closed === true ) {
  21206. theta = Math.acos( _Math.clamp( normals[ 0 ].dot( normals[ segments ] ), - 1, 1 ) );
  21207. theta /= segments;
  21208. if ( tangents[ 0 ].dot( vec.crossVectors( normals[ 0 ], normals[ segments ] ) ) > 0 ) {
  21209. theta = - theta;
  21210. }
  21211. for ( i = 1; i <= segments; i ++ ) {
  21212. // twist a little...
  21213. normals[ i ].applyMatrix4( mat.makeRotationAxis( tangents[ i ], theta * i ) );
  21214. binormals[ i ].crossVectors( tangents[ i ], normals[ i ] );
  21215. }
  21216. }
  21217. return {
  21218. tangents: tangents,
  21219. normals: normals,
  21220. binormals: binormals
  21221. };
  21222. },
  21223. clone: function () {
  21224. return new this.constructor().copy( this );
  21225. },
  21226. copy: function ( source ) {
  21227. this.arcLengthDivisions = source.arcLengthDivisions;
  21228. return this;
  21229. },
  21230. toJSON: function () {
  21231. var data = {
  21232. metadata: {
  21233. version: 4.5,
  21234. type: 'Curve',
  21235. generator: 'Curve.toJSON'
  21236. }
  21237. };
  21238. data.arcLengthDivisions = this.arcLengthDivisions;
  21239. data.type = this.type;
  21240. return data;
  21241. },
  21242. fromJSON: function ( json ) {
  21243. this.arcLengthDivisions = json.arcLengthDivisions;
  21244. return this;
  21245. }
  21246. } );
  21247. function EllipseCurve( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  21248. Curve.call( this );
  21249. this.type = 'EllipseCurve';
  21250. this.aX = aX || 0;
  21251. this.aY = aY || 0;
  21252. this.xRadius = xRadius || 1;
  21253. this.yRadius = yRadius || 1;
  21254. this.aStartAngle = aStartAngle || 0;
  21255. this.aEndAngle = aEndAngle || 2 * Math.PI;
  21256. this.aClockwise = aClockwise || false;
  21257. this.aRotation = aRotation || 0;
  21258. }
  21259. EllipseCurve.prototype = Object.create( Curve.prototype );
  21260. EllipseCurve.prototype.constructor = EllipseCurve;
  21261. EllipseCurve.prototype.isEllipseCurve = true;
  21262. EllipseCurve.prototype.getPoint = function ( t, optionalTarget ) {
  21263. var point = optionalTarget || new Vector2();
  21264. var twoPi = Math.PI * 2;
  21265. var deltaAngle = this.aEndAngle - this.aStartAngle;
  21266. var samePoints = Math.abs( deltaAngle ) < Number.EPSILON;
  21267. // ensures that deltaAngle is 0 .. 2 PI
  21268. while ( deltaAngle < 0 ) deltaAngle += twoPi;
  21269. while ( deltaAngle > twoPi ) deltaAngle -= twoPi;
  21270. if ( deltaAngle < Number.EPSILON ) {
  21271. if ( samePoints ) {
  21272. deltaAngle = 0;
  21273. } else {
  21274. deltaAngle = twoPi;
  21275. }
  21276. }
  21277. if ( this.aClockwise === true && ! samePoints ) {
  21278. if ( deltaAngle === twoPi ) {
  21279. deltaAngle = - twoPi;
  21280. } else {
  21281. deltaAngle = deltaAngle - twoPi;
  21282. }
  21283. }
  21284. var angle = this.aStartAngle + t * deltaAngle;
  21285. var x = this.aX + this.xRadius * Math.cos( angle );
  21286. var y = this.aY + this.yRadius * Math.sin( angle );
  21287. if ( this.aRotation !== 0 ) {
  21288. var cos = Math.cos( this.aRotation );
  21289. var sin = Math.sin( this.aRotation );
  21290. var tx = x - this.aX;
  21291. var ty = y - this.aY;
  21292. // Rotate the point about the center of the ellipse.
  21293. x = tx * cos - ty * sin + this.aX;
  21294. y = tx * sin + ty * cos + this.aY;
  21295. }
  21296. return point.set( x, y );
  21297. };
  21298. EllipseCurve.prototype.copy = function ( source ) {
  21299. Curve.prototype.copy.call( this, source );
  21300. this.aX = source.aX;
  21301. this.aY = source.aY;
  21302. this.xRadius = source.xRadius;
  21303. this.yRadius = source.yRadius;
  21304. this.aStartAngle = source.aStartAngle;
  21305. this.aEndAngle = source.aEndAngle;
  21306. this.aClockwise = source.aClockwise;
  21307. this.aRotation = source.aRotation;
  21308. return this;
  21309. };
  21310. EllipseCurve.prototype.toJSON = function () {
  21311. var data = Curve.prototype.toJSON.call( this );
  21312. data.aX = this.aX;
  21313. data.aY = this.aY;
  21314. data.xRadius = this.xRadius;
  21315. data.yRadius = this.yRadius;
  21316. data.aStartAngle = this.aStartAngle;
  21317. data.aEndAngle = this.aEndAngle;
  21318. data.aClockwise = this.aClockwise;
  21319. data.aRotation = this.aRotation;
  21320. return data;
  21321. };
  21322. EllipseCurve.prototype.fromJSON = function ( json ) {
  21323. Curve.prototype.fromJSON.call( this, json );
  21324. this.aX = json.aX;
  21325. this.aY = json.aY;
  21326. this.xRadius = json.xRadius;
  21327. this.yRadius = json.yRadius;
  21328. this.aStartAngle = json.aStartAngle;
  21329. this.aEndAngle = json.aEndAngle;
  21330. this.aClockwise = json.aClockwise;
  21331. this.aRotation = json.aRotation;
  21332. return this;
  21333. };
  21334. function ArcCurve( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  21335. EllipseCurve.call( this, aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise );
  21336. this.type = 'ArcCurve';
  21337. }
  21338. ArcCurve.prototype = Object.create( EllipseCurve.prototype );
  21339. ArcCurve.prototype.constructor = ArcCurve;
  21340. ArcCurve.prototype.isArcCurve = true;
  21341. /**
  21342. * @author zz85 https://github.com/zz85
  21343. *
  21344. * Centripetal CatmullRom Curve - which is useful for avoiding
  21345. * cusps and self-intersections in non-uniform catmull rom curves.
  21346. * http://www.cemyuksel.com/research/catmullrom_param/catmullrom.pdf
  21347. *
  21348. * curve.type accepts centripetal(default), chordal and catmullrom
  21349. * curve.tension is used for catmullrom which defaults to 0.5
  21350. */
  21351. /*
  21352. Based on an optimized c++ solution in
  21353. - http://stackoverflow.com/questions/9489736/catmull-rom-curve-with-no-cusps-and-no-self-intersections/
  21354. - http://ideone.com/NoEbVM
  21355. This CubicPoly class could be used for reusing some variables and calculations,
  21356. but for three.js curve use, it could be possible inlined and flatten into a single function call
  21357. which can be placed in CurveUtils.
  21358. */
  21359. function CubicPoly() {
  21360. var c0 = 0, c1 = 0, c2 = 0, c3 = 0;
  21361. /*
  21362. * Compute coefficients for a cubic polynomial
  21363. * p(s) = c0 + c1*s + c2*s^2 + c3*s^3
  21364. * such that
  21365. * p(0) = x0, p(1) = x1
  21366. * and
  21367. * p'(0) = t0, p'(1) = t1.
  21368. */
  21369. function init( x0, x1, t0, t1 ) {
  21370. c0 = x0;
  21371. c1 = t0;
  21372. c2 = - 3 * x0 + 3 * x1 - 2 * t0 - t1;
  21373. c3 = 2 * x0 - 2 * x1 + t0 + t1;
  21374. }
  21375. return {
  21376. initCatmullRom: function ( x0, x1, x2, x3, tension ) {
  21377. init( x1, x2, tension * ( x2 - x0 ), tension * ( x3 - x1 ) );
  21378. },
  21379. initNonuniformCatmullRom: function ( x0, x1, x2, x3, dt0, dt1, dt2 ) {
  21380. // compute tangents when parameterized in [t1,t2]
  21381. var t1 = ( x1 - x0 ) / dt0 - ( x2 - x0 ) / ( dt0 + dt1 ) + ( x2 - x1 ) / dt1;
  21382. var t2 = ( x2 - x1 ) / dt1 - ( x3 - x1 ) / ( dt1 + dt2 ) + ( x3 - x2 ) / dt2;
  21383. // rescale tangents for parametrization in [0,1]
  21384. t1 *= dt1;
  21385. t2 *= dt1;
  21386. init( x1, x2, t1, t2 );
  21387. },
  21388. calc: function ( t ) {
  21389. var t2 = t * t;
  21390. var t3 = t2 * t;
  21391. return c0 + c1 * t + c2 * t2 + c3 * t3;
  21392. }
  21393. };
  21394. }
  21395. //
  21396. var tmp = new Vector3();
  21397. var px = new CubicPoly(), py = new CubicPoly(), pz = new CubicPoly();
  21398. function CatmullRomCurve3( points, closed, curveType, tension ) {
  21399. Curve.call( this );
  21400. this.type = 'CatmullRomCurve3';
  21401. this.points = points || [];
  21402. this.closed = closed || false;
  21403. this.curveType = curveType || 'centripetal';
  21404. this.tension = tension || 0.5;
  21405. }
  21406. CatmullRomCurve3.prototype = Object.create( Curve.prototype );
  21407. CatmullRomCurve3.prototype.constructor = CatmullRomCurve3;
  21408. CatmullRomCurve3.prototype.isCatmullRomCurve3 = true;
  21409. CatmullRomCurve3.prototype.getPoint = function ( t, optionalTarget ) {
  21410. var point = optionalTarget || new Vector3();
  21411. var points = this.points;
  21412. var l = points.length;
  21413. var p = ( l - ( this.closed ? 0 : 1 ) ) * t;
  21414. var intPoint = Math.floor( p );
  21415. var weight = p - intPoint;
  21416. if ( this.closed ) {
  21417. intPoint += intPoint > 0 ? 0 : ( Math.floor( Math.abs( intPoint ) / l ) + 1 ) * l;
  21418. } else if ( weight === 0 && intPoint === l - 1 ) {
  21419. intPoint = l - 2;
  21420. weight = 1;
  21421. }
  21422. var p0, p1, p2, p3; // 4 points
  21423. if ( this.closed || intPoint > 0 ) {
  21424. p0 = points[ ( intPoint - 1 ) % l ];
  21425. } else {
  21426. // extrapolate first point
  21427. tmp.subVectors( points[ 0 ], points[ 1 ] ).add( points[ 0 ] );
  21428. p0 = tmp;
  21429. }
  21430. p1 = points[ intPoint % l ];
  21431. p2 = points[ ( intPoint + 1 ) % l ];
  21432. if ( this.closed || intPoint + 2 < l ) {
  21433. p3 = points[ ( intPoint + 2 ) % l ];
  21434. } else {
  21435. // extrapolate last point
  21436. tmp.subVectors( points[ l - 1 ], points[ l - 2 ] ).add( points[ l - 1 ] );
  21437. p3 = tmp;
  21438. }
  21439. if ( this.curveType === 'centripetal' || this.curveType === 'chordal' ) {
  21440. // init Centripetal / Chordal Catmull-Rom
  21441. var pow = this.curveType === 'chordal' ? 0.5 : 0.25;
  21442. var dt0 = Math.pow( p0.distanceToSquared( p1 ), pow );
  21443. var dt1 = Math.pow( p1.distanceToSquared( p2 ), pow );
  21444. var dt2 = Math.pow( p2.distanceToSquared( p3 ), pow );
  21445. // safety check for repeated points
  21446. if ( dt1 < 1e-4 ) dt1 = 1.0;
  21447. if ( dt0 < 1e-4 ) dt0 = dt1;
  21448. if ( dt2 < 1e-4 ) dt2 = dt1;
  21449. px.initNonuniformCatmullRom( p0.x, p1.x, p2.x, p3.x, dt0, dt1, dt2 );
  21450. py.initNonuniformCatmullRom( p0.y, p1.y, p2.y, p3.y, dt0, dt1, dt2 );
  21451. pz.initNonuniformCatmullRom( p0.z, p1.z, p2.z, p3.z, dt0, dt1, dt2 );
  21452. } else if ( this.curveType === 'catmullrom' ) {
  21453. px.initCatmullRom( p0.x, p1.x, p2.x, p3.x, this.tension );
  21454. py.initCatmullRom( p0.y, p1.y, p2.y, p3.y, this.tension );
  21455. pz.initCatmullRom( p0.z, p1.z, p2.z, p3.z, this.tension );
  21456. }
  21457. point.set(
  21458. px.calc( weight ),
  21459. py.calc( weight ),
  21460. pz.calc( weight )
  21461. );
  21462. return point;
  21463. };
  21464. CatmullRomCurve3.prototype.copy = function ( source ) {
  21465. Curve.prototype.copy.call( this, source );
  21466. this.points = [];
  21467. for ( var i = 0, l = source.points.length; i < l; i ++ ) {
  21468. var point = source.points[ i ];
  21469. this.points.push( point.clone() );
  21470. }
  21471. this.closed = source.closed;
  21472. this.curveType = source.curveType;
  21473. this.tension = source.tension;
  21474. return this;
  21475. };
  21476. CatmullRomCurve3.prototype.toJSON = function () {
  21477. var data = Curve.prototype.toJSON.call( this );
  21478. data.points = [];
  21479. for ( var i = 0, l = this.points.length; i < l; i ++ ) {
  21480. var point = this.points[ i ];
  21481. data.points.push( point.toArray() );
  21482. }
  21483. data.closed = this.closed;
  21484. data.curveType = this.curveType;
  21485. data.tension = this.tension;
  21486. return data;
  21487. };
  21488. CatmullRomCurve3.prototype.fromJSON = function ( json ) {
  21489. Curve.prototype.fromJSON.call( this, json );
  21490. this.points = [];
  21491. for ( var i = 0, l = json.points.length; i < l; i ++ ) {
  21492. var point = json.points[ i ];
  21493. this.points.push( new Vector3().fromArray( point ) );
  21494. }
  21495. this.closed = json.closed;
  21496. this.curveType = json.curveType;
  21497. this.tension = json.tension;
  21498. return this;
  21499. };
  21500. /**
  21501. * @author zz85 / http://www.lab4games.net/zz85/blog
  21502. *
  21503. * Bezier Curves formulas obtained from
  21504. * http://en.wikipedia.org/wiki/Bézier_curve
  21505. */
  21506. function CatmullRom( t, p0, p1, p2, p3 ) {
  21507. var v0 = ( p2 - p0 ) * 0.5;
  21508. var v1 = ( p3 - p1 ) * 0.5;
  21509. var t2 = t * t;
  21510. var t3 = t * t2;
  21511. return ( 2 * p1 - 2 * p2 + v0 + v1 ) * t3 + ( - 3 * p1 + 3 * p2 - 2 * v0 - v1 ) * t2 + v0 * t + p1;
  21512. }
  21513. //
  21514. function QuadraticBezierP0( t, p ) {
  21515. var k = 1 - t;
  21516. return k * k * p;
  21517. }
  21518. function QuadraticBezierP1( t, p ) {
  21519. return 2 * ( 1 - t ) * t * p;
  21520. }
  21521. function QuadraticBezierP2( t, p ) {
  21522. return t * t * p;
  21523. }
  21524. function QuadraticBezier( t, p0, p1, p2 ) {
  21525. return QuadraticBezierP0( t, p0 ) + QuadraticBezierP1( t, p1 ) +
  21526. QuadraticBezierP2( t, p2 );
  21527. }
  21528. //
  21529. function CubicBezierP0( t, p ) {
  21530. var k = 1 - t;
  21531. return k * k * k * p;
  21532. }
  21533. function CubicBezierP1( t, p ) {
  21534. var k = 1 - t;
  21535. return 3 * k * k * t * p;
  21536. }
  21537. function CubicBezierP2( t, p ) {
  21538. return 3 * ( 1 - t ) * t * t * p;
  21539. }
  21540. function CubicBezierP3( t, p ) {
  21541. return t * t * t * p;
  21542. }
  21543. function CubicBezier( t, p0, p1, p2, p3 ) {
  21544. return CubicBezierP0( t, p0 ) + CubicBezierP1( t, p1 ) + CubicBezierP2( t, p2 ) +
  21545. CubicBezierP3( t, p3 );
  21546. }
  21547. function CubicBezierCurve( v0, v1, v2, v3 ) {
  21548. Curve.call( this );
  21549. this.type = 'CubicBezierCurve';
  21550. this.v0 = v0 || new Vector2();
  21551. this.v1 = v1 || new Vector2();
  21552. this.v2 = v2 || new Vector2();
  21553. this.v3 = v3 || new Vector2();
  21554. }
  21555. CubicBezierCurve.prototype = Object.create( Curve.prototype );
  21556. CubicBezierCurve.prototype.constructor = CubicBezierCurve;
  21557. CubicBezierCurve.prototype.isCubicBezierCurve = true;
  21558. CubicBezierCurve.prototype.getPoint = function ( t, optionalTarget ) {
  21559. var point = optionalTarget || new Vector2();
  21560. var v0 = this.v0, v1 = this.v1, v2 = this.v2, v3 = this.v3;
  21561. point.set(
  21562. CubicBezier( t, v0.x, v1.x, v2.x, v3.x ),
  21563. CubicBezier( t, v0.y, v1.y, v2.y, v3.y )
  21564. );
  21565. return point;
  21566. };
  21567. CubicBezierCurve.prototype.copy = function ( source ) {
  21568. Curve.prototype.copy.call( this, source );
  21569. this.v0.copy( source.v0 );
  21570. this.v1.copy( source.v1 );
  21571. this.v2.copy( source.v2 );
  21572. this.v3.copy( source.v3 );
  21573. return this;
  21574. };
  21575. CubicBezierCurve.prototype.toJSON = function () {
  21576. var data = Curve.prototype.toJSON.call( this );
  21577. data.v0 = this.v0.toArray();
  21578. data.v1 = this.v1.toArray();
  21579. data.v2 = this.v2.toArray();
  21580. data.v3 = this.v3.toArray();
  21581. return data;
  21582. };
  21583. CubicBezierCurve.prototype.fromJSON = function ( json ) {
  21584. Curve.prototype.fromJSON.call( this, json );
  21585. this.v0.fromArray( json.v0 );
  21586. this.v1.fromArray( json.v1 );
  21587. this.v2.fromArray( json.v2 );
  21588. this.v3.fromArray( json.v3 );
  21589. return this;
  21590. };
  21591. function CubicBezierCurve3( v0, v1, v2, v3 ) {
  21592. Curve.call( this );
  21593. this.type = 'CubicBezierCurve3';
  21594. this.v0 = v0 || new Vector3();
  21595. this.v1 = v1 || new Vector3();
  21596. this.v2 = v2 || new Vector3();
  21597. this.v3 = v3 || new Vector3();
  21598. }
  21599. CubicBezierCurve3.prototype = Object.create( Curve.prototype );
  21600. CubicBezierCurve3.prototype.constructor = CubicBezierCurve3;
  21601. CubicBezierCurve3.prototype.isCubicBezierCurve3 = true;
  21602. CubicBezierCurve3.prototype.getPoint = function ( t, optionalTarget ) {
  21603. var point = optionalTarget || new Vector3();
  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. CubicBezier( t, v0.z, v1.z, v2.z, v3.z )
  21609. );
  21610. return point;
  21611. };
  21612. CubicBezierCurve3.prototype.copy = function ( source ) {
  21613. Curve.prototype.copy.call( this, source );
  21614. this.v0.copy( source.v0 );
  21615. this.v1.copy( source.v1 );
  21616. this.v2.copy( source.v2 );
  21617. this.v3.copy( source.v3 );
  21618. return this;
  21619. };
  21620. CubicBezierCurve3.prototype.toJSON = function () {
  21621. var data = Curve.prototype.toJSON.call( this );
  21622. data.v0 = this.v0.toArray();
  21623. data.v1 = this.v1.toArray();
  21624. data.v2 = this.v2.toArray();
  21625. data.v3 = this.v3.toArray();
  21626. return data;
  21627. };
  21628. CubicBezierCurve3.prototype.fromJSON = function ( json ) {
  21629. Curve.prototype.fromJSON.call( this, json );
  21630. this.v0.fromArray( json.v0 );
  21631. this.v1.fromArray( json.v1 );
  21632. this.v2.fromArray( json.v2 );
  21633. this.v3.fromArray( json.v3 );
  21634. return this;
  21635. };
  21636. function LineCurve( v1, v2 ) {
  21637. Curve.call( this );
  21638. this.type = 'LineCurve';
  21639. this.v1 = v1 || new Vector2();
  21640. this.v2 = v2 || new Vector2();
  21641. }
  21642. LineCurve.prototype = Object.create( Curve.prototype );
  21643. LineCurve.prototype.constructor = LineCurve;
  21644. LineCurve.prototype.isLineCurve = true;
  21645. LineCurve.prototype.getPoint = function ( t, optionalTarget ) {
  21646. var point = optionalTarget || new Vector2();
  21647. if ( t === 1 ) {
  21648. point.copy( this.v2 );
  21649. } else {
  21650. point.copy( this.v2 ).sub( this.v1 );
  21651. point.multiplyScalar( t ).add( this.v1 );
  21652. }
  21653. return point;
  21654. };
  21655. // Line curve is linear, so we can overwrite default getPointAt
  21656. LineCurve.prototype.getPointAt = function ( u, optionalTarget ) {
  21657. return this.getPoint( u, optionalTarget );
  21658. };
  21659. LineCurve.prototype.getTangent = function ( /* t */ ) {
  21660. var tangent = this.v2.clone().sub( this.v1 );
  21661. return tangent.normalize();
  21662. };
  21663. LineCurve.prototype.copy = function ( source ) {
  21664. Curve.prototype.copy.call( this, source );
  21665. this.v1.copy( source.v1 );
  21666. this.v2.copy( source.v2 );
  21667. return this;
  21668. };
  21669. LineCurve.prototype.toJSON = function () {
  21670. var data = Curve.prototype.toJSON.call( this );
  21671. data.v1 = this.v1.toArray();
  21672. data.v2 = this.v2.toArray();
  21673. return data;
  21674. };
  21675. LineCurve.prototype.fromJSON = function ( json ) {
  21676. Curve.prototype.fromJSON.call( this, json );
  21677. this.v1.fromArray( json.v1 );
  21678. this.v2.fromArray( json.v2 );
  21679. return this;
  21680. };
  21681. function LineCurve3( v1, v2 ) {
  21682. Curve.call( this );
  21683. this.type = 'LineCurve3';
  21684. this.v1 = v1 || new Vector3();
  21685. this.v2 = v2 || new Vector3();
  21686. }
  21687. LineCurve3.prototype = Object.create( Curve.prototype );
  21688. LineCurve3.prototype.constructor = LineCurve3;
  21689. LineCurve3.prototype.isLineCurve3 = true;
  21690. LineCurve3.prototype.getPoint = function ( t, optionalTarget ) {
  21691. var point = optionalTarget || new Vector3();
  21692. if ( t === 1 ) {
  21693. point.copy( this.v2 );
  21694. } else {
  21695. point.copy( this.v2 ).sub( this.v1 );
  21696. point.multiplyScalar( t ).add( this.v1 );
  21697. }
  21698. return point;
  21699. };
  21700. // Line curve is linear, so we can overwrite default getPointAt
  21701. LineCurve3.prototype.getPointAt = function ( u, optionalTarget ) {
  21702. return this.getPoint( u, optionalTarget );
  21703. };
  21704. LineCurve3.prototype.copy = function ( source ) {
  21705. Curve.prototype.copy.call( this, source );
  21706. this.v1.copy( source.v1 );
  21707. this.v2.copy( source.v2 );
  21708. return this;
  21709. };
  21710. LineCurve3.prototype.toJSON = function () {
  21711. var data = Curve.prototype.toJSON.call( this );
  21712. data.v1 = this.v1.toArray();
  21713. data.v2 = this.v2.toArray();
  21714. return data;
  21715. };
  21716. LineCurve3.prototype.fromJSON = function ( json ) {
  21717. Curve.prototype.fromJSON.call( this, json );
  21718. this.v1.fromArray( json.v1 );
  21719. this.v2.fromArray( json.v2 );
  21720. return this;
  21721. };
  21722. function QuadraticBezierCurve( v0, v1, v2 ) {
  21723. Curve.call( this );
  21724. this.type = 'QuadraticBezierCurve';
  21725. this.v0 = v0 || new Vector2();
  21726. this.v1 = v1 || new Vector2();
  21727. this.v2 = v2 || new Vector2();
  21728. }
  21729. QuadraticBezierCurve.prototype = Object.create( Curve.prototype );
  21730. QuadraticBezierCurve.prototype.constructor = QuadraticBezierCurve;
  21731. QuadraticBezierCurve.prototype.isQuadraticBezierCurve = true;
  21732. QuadraticBezierCurve.prototype.getPoint = function ( t, optionalTarget ) {
  21733. var point = optionalTarget || new Vector2();
  21734. var v0 = this.v0, v1 = this.v1, v2 = this.v2;
  21735. point.set(
  21736. QuadraticBezier( t, v0.x, v1.x, v2.x ),
  21737. QuadraticBezier( t, v0.y, v1.y, v2.y )
  21738. );
  21739. return point;
  21740. };
  21741. QuadraticBezierCurve.prototype.copy = function ( source ) {
  21742. Curve.prototype.copy.call( this, source );
  21743. this.v0.copy( source.v0 );
  21744. this.v1.copy( source.v1 );
  21745. this.v2.copy( source.v2 );
  21746. return this;
  21747. };
  21748. QuadraticBezierCurve.prototype.toJSON = function () {
  21749. var data = Curve.prototype.toJSON.call( this );
  21750. data.v0 = this.v0.toArray();
  21751. data.v1 = this.v1.toArray();
  21752. data.v2 = this.v2.toArray();
  21753. return data;
  21754. };
  21755. QuadraticBezierCurve.prototype.fromJSON = function ( json ) {
  21756. Curve.prototype.fromJSON.call( this, json );
  21757. this.v0.fromArray( json.v0 );
  21758. this.v1.fromArray( json.v1 );
  21759. this.v2.fromArray( json.v2 );
  21760. return this;
  21761. };
  21762. function QuadraticBezierCurve3( v0, v1, v2 ) {
  21763. Curve.call( this );
  21764. this.type = 'QuadraticBezierCurve3';
  21765. this.v0 = v0 || new Vector3();
  21766. this.v1 = v1 || new Vector3();
  21767. this.v2 = v2 || new Vector3();
  21768. }
  21769. QuadraticBezierCurve3.prototype = Object.create( Curve.prototype );
  21770. QuadraticBezierCurve3.prototype.constructor = QuadraticBezierCurve3;
  21771. QuadraticBezierCurve3.prototype.isQuadraticBezierCurve3 = true;
  21772. QuadraticBezierCurve3.prototype.getPoint = function ( t, optionalTarget ) {
  21773. var point = optionalTarget || new Vector3();
  21774. var v0 = this.v0, v1 = this.v1, v2 = this.v2;
  21775. point.set(
  21776. QuadraticBezier( t, v0.x, v1.x, v2.x ),
  21777. QuadraticBezier( t, v0.y, v1.y, v2.y ),
  21778. QuadraticBezier( t, v0.z, v1.z, v2.z )
  21779. );
  21780. return point;
  21781. };
  21782. QuadraticBezierCurve3.prototype.copy = function ( source ) {
  21783. Curve.prototype.copy.call( this, source );
  21784. this.v0.copy( source.v0 );
  21785. this.v1.copy( source.v1 );
  21786. this.v2.copy( source.v2 );
  21787. return this;
  21788. };
  21789. QuadraticBezierCurve3.prototype.toJSON = function () {
  21790. var data = Curve.prototype.toJSON.call( this );
  21791. data.v0 = this.v0.toArray();
  21792. data.v1 = this.v1.toArray();
  21793. data.v2 = this.v2.toArray();
  21794. return data;
  21795. };
  21796. QuadraticBezierCurve3.prototype.fromJSON = function ( json ) {
  21797. Curve.prototype.fromJSON.call( this, json );
  21798. this.v0.fromArray( json.v0 );
  21799. this.v1.fromArray( json.v1 );
  21800. this.v2.fromArray( json.v2 );
  21801. return this;
  21802. };
  21803. function SplineCurve( points /* array of Vector2 */ ) {
  21804. Curve.call( this );
  21805. this.type = 'SplineCurve';
  21806. this.points = points || [];
  21807. }
  21808. SplineCurve.prototype = Object.create( Curve.prototype );
  21809. SplineCurve.prototype.constructor = SplineCurve;
  21810. SplineCurve.prototype.isSplineCurve = true;
  21811. SplineCurve.prototype.getPoint = function ( t, optionalTarget ) {
  21812. var point = optionalTarget || new Vector2();
  21813. var points = this.points;
  21814. var p = ( points.length - 1 ) * t;
  21815. var intPoint = Math.floor( p );
  21816. var weight = p - intPoint;
  21817. var p0 = points[ intPoint === 0 ? intPoint : intPoint - 1 ];
  21818. var p1 = points[ intPoint ];
  21819. var p2 = points[ intPoint > points.length - 2 ? points.length - 1 : intPoint + 1 ];
  21820. var p3 = points[ intPoint > points.length - 3 ? points.length - 1 : intPoint + 2 ];
  21821. point.set(
  21822. CatmullRom( weight, p0.x, p1.x, p2.x, p3.x ),
  21823. CatmullRom( weight, p0.y, p1.y, p2.y, p3.y )
  21824. );
  21825. return point;
  21826. };
  21827. SplineCurve.prototype.copy = function ( source ) {
  21828. Curve.prototype.copy.call( this, source );
  21829. this.points = [];
  21830. for ( var i = 0, l = source.points.length; i < l; i ++ ) {
  21831. var point = source.points[ i ];
  21832. this.points.push( point.clone() );
  21833. }
  21834. return this;
  21835. };
  21836. SplineCurve.prototype.toJSON = function () {
  21837. var data = Curve.prototype.toJSON.call( this );
  21838. data.points = [];
  21839. for ( var i = 0, l = this.points.length; i < l; i ++ ) {
  21840. var point = this.points[ i ];
  21841. data.points.push( point.toArray() );
  21842. }
  21843. return data;
  21844. };
  21845. SplineCurve.prototype.fromJSON = function ( json ) {
  21846. Curve.prototype.fromJSON.call( this, json );
  21847. this.points = [];
  21848. for ( var i = 0, l = json.points.length; i < l; i ++ ) {
  21849. var point = json.points[ i ];
  21850. this.points.push( new Vector2().fromArray( point ) );
  21851. }
  21852. return this;
  21853. };
  21854. var Curves = /*#__PURE__*/Object.freeze({
  21855. ArcCurve: ArcCurve,
  21856. CatmullRomCurve3: CatmullRomCurve3,
  21857. CubicBezierCurve: CubicBezierCurve,
  21858. CubicBezierCurve3: CubicBezierCurve3,
  21859. EllipseCurve: EllipseCurve,
  21860. LineCurve: LineCurve,
  21861. LineCurve3: LineCurve3,
  21862. QuadraticBezierCurve: QuadraticBezierCurve,
  21863. QuadraticBezierCurve3: QuadraticBezierCurve3,
  21864. SplineCurve: SplineCurve
  21865. });
  21866. /**
  21867. * @author zz85 / http://www.lab4games.net/zz85/blog
  21868. *
  21869. **/
  21870. /**************************************************************
  21871. * Curved Path - a curve path is simply a array of connected
  21872. * curves, but retains the api of a curve
  21873. **************************************************************/
  21874. function CurvePath() {
  21875. Curve.call( this );
  21876. this.type = 'CurvePath';
  21877. this.curves = [];
  21878. this.autoClose = false; // Automatically closes the path
  21879. }
  21880. CurvePath.prototype = Object.assign( Object.create( Curve.prototype ), {
  21881. constructor: CurvePath,
  21882. add: function ( curve ) {
  21883. this.curves.push( curve );
  21884. },
  21885. closePath: function () {
  21886. // Add a line curve if start and end of lines are not connected
  21887. var startPoint = this.curves[ 0 ].getPoint( 0 );
  21888. var endPoint = this.curves[ this.curves.length - 1 ].getPoint( 1 );
  21889. if ( ! startPoint.equals( endPoint ) ) {
  21890. this.curves.push( new LineCurve( endPoint, startPoint ) );
  21891. }
  21892. },
  21893. // To get accurate point with reference to
  21894. // entire path distance at time t,
  21895. // following has to be done:
  21896. // 1. Length of each sub path have to be known
  21897. // 2. Locate and identify type of curve
  21898. // 3. Get t for the curve
  21899. // 4. Return curve.getPointAt(t')
  21900. getPoint: function ( t ) {
  21901. var d = t * this.getLength();
  21902. var curveLengths = this.getCurveLengths();
  21903. var i = 0;
  21904. // To think about boundaries points.
  21905. while ( i < curveLengths.length ) {
  21906. if ( curveLengths[ i ] >= d ) {
  21907. var diff = curveLengths[ i ] - d;
  21908. var curve = this.curves[ i ];
  21909. var segmentLength = curve.getLength();
  21910. var u = segmentLength === 0 ? 0 : 1 - diff / segmentLength;
  21911. return curve.getPointAt( u );
  21912. }
  21913. i ++;
  21914. }
  21915. return null;
  21916. // loop where sum != 0, sum > d , sum+1 <d
  21917. },
  21918. // We cannot use the default THREE.Curve getPoint() with getLength() because in
  21919. // THREE.Curve, getLength() depends on getPoint() but in THREE.CurvePath
  21920. // getPoint() depends on getLength
  21921. getLength: function () {
  21922. var lens = this.getCurveLengths();
  21923. return lens[ lens.length - 1 ];
  21924. },
  21925. // cacheLengths must be recalculated.
  21926. updateArcLengths: function () {
  21927. this.needsUpdate = true;
  21928. this.cacheLengths = null;
  21929. this.getCurveLengths();
  21930. },
  21931. // Compute lengths and cache them
  21932. // We cannot overwrite getLengths() because UtoT mapping uses it.
  21933. getCurveLengths: function () {
  21934. // We use cache values if curves and cache array are same length
  21935. if ( this.cacheLengths && this.cacheLengths.length === this.curves.length ) {
  21936. return this.cacheLengths;
  21937. }
  21938. // Get length of sub-curve
  21939. // Push sums into cached array
  21940. var lengths = [], sums = 0;
  21941. for ( var i = 0, l = this.curves.length; i < l; i ++ ) {
  21942. sums += this.curves[ i ].getLength();
  21943. lengths.push( sums );
  21944. }
  21945. this.cacheLengths = lengths;
  21946. return lengths;
  21947. },
  21948. getSpacedPoints: function ( divisions ) {
  21949. if ( divisions === undefined ) divisions = 40;
  21950. var points = [];
  21951. for ( var i = 0; i <= divisions; i ++ ) {
  21952. points.push( this.getPoint( i / divisions ) );
  21953. }
  21954. if ( this.autoClose ) {
  21955. points.push( points[ 0 ] );
  21956. }
  21957. return points;
  21958. },
  21959. getPoints: function ( divisions ) {
  21960. divisions = divisions || 12;
  21961. var points = [], last;
  21962. for ( var i = 0, curves = this.curves; i < curves.length; i ++ ) {
  21963. var curve = curves[ i ];
  21964. var resolution = ( curve && curve.isEllipseCurve ) ? divisions * 2
  21965. : ( curve && ( curve.isLineCurve || curve.isLineCurve3 ) ) ? 1
  21966. : ( curve && curve.isSplineCurve ) ? divisions * curve.points.length
  21967. : divisions;
  21968. var pts = curve.getPoints( resolution );
  21969. for ( var j = 0; j < pts.length; j ++ ) {
  21970. var point = pts[ j ];
  21971. if ( last && last.equals( point ) ) continue; // ensures no consecutive points are duplicates
  21972. points.push( point );
  21973. last = point;
  21974. }
  21975. }
  21976. if ( this.autoClose && points.length > 1 && ! points[ points.length - 1 ].equals( points[ 0 ] ) ) {
  21977. points.push( points[ 0 ] );
  21978. }
  21979. return points;
  21980. },
  21981. copy: function ( source ) {
  21982. Curve.prototype.copy.call( this, source );
  21983. this.curves = [];
  21984. for ( var i = 0, l = source.curves.length; i < l; i ++ ) {
  21985. var curve = source.curves[ i ];
  21986. this.curves.push( curve.clone() );
  21987. }
  21988. this.autoClose = source.autoClose;
  21989. return this;
  21990. },
  21991. toJSON: function () {
  21992. var data = Curve.prototype.toJSON.call( this );
  21993. data.autoClose = this.autoClose;
  21994. data.curves = [];
  21995. for ( var i = 0, l = this.curves.length; i < l; i ++ ) {
  21996. var curve = this.curves[ i ];
  21997. data.curves.push( curve.toJSON() );
  21998. }
  21999. return data;
  22000. },
  22001. fromJSON: function ( json ) {
  22002. Curve.prototype.fromJSON.call( this, json );
  22003. this.autoClose = json.autoClose;
  22004. this.curves = [];
  22005. for ( var i = 0, l = json.curves.length; i < l; i ++ ) {
  22006. var curve = json.curves[ i ];
  22007. this.curves.push( new Curves[ curve.type ]().fromJSON( curve ) );
  22008. }
  22009. return this;
  22010. }
  22011. } );
  22012. /**
  22013. * @author zz85 / http://www.lab4games.net/zz85/blog
  22014. * Creates free form 2d path using series of points, lines or curves.
  22015. **/
  22016. function Path( points ) {
  22017. CurvePath.call( this );
  22018. this.type = 'Path';
  22019. this.currentPoint = new Vector2();
  22020. if ( points ) {
  22021. this.setFromPoints( points );
  22022. }
  22023. }
  22024. Path.prototype = Object.assign( Object.create( CurvePath.prototype ), {
  22025. constructor: Path,
  22026. setFromPoints: function ( points ) {
  22027. this.moveTo( points[ 0 ].x, points[ 0 ].y );
  22028. for ( var i = 1, l = points.length; i < l; i ++ ) {
  22029. this.lineTo( points[ i ].x, points[ i ].y );
  22030. }
  22031. },
  22032. moveTo: function ( x, y ) {
  22033. this.currentPoint.set( x, y ); // TODO consider referencing vectors instead of copying?
  22034. },
  22035. lineTo: function ( x, y ) {
  22036. var curve = new LineCurve( this.currentPoint.clone(), new Vector2( x, y ) );
  22037. this.curves.push( curve );
  22038. this.currentPoint.set( x, y );
  22039. },
  22040. quadraticCurveTo: function ( aCPx, aCPy, aX, aY ) {
  22041. var curve = new QuadraticBezierCurve(
  22042. this.currentPoint.clone(),
  22043. new Vector2( aCPx, aCPy ),
  22044. new Vector2( aX, aY )
  22045. );
  22046. this.curves.push( curve );
  22047. this.currentPoint.set( aX, aY );
  22048. },
  22049. bezierCurveTo: function ( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY ) {
  22050. var curve = new CubicBezierCurve(
  22051. this.currentPoint.clone(),
  22052. new Vector2( aCP1x, aCP1y ),
  22053. new Vector2( aCP2x, aCP2y ),
  22054. new Vector2( aX, aY )
  22055. );
  22056. this.curves.push( curve );
  22057. this.currentPoint.set( aX, aY );
  22058. },
  22059. splineThru: function ( pts /*Array of Vector*/ ) {
  22060. var npts = [ this.currentPoint.clone() ].concat( pts );
  22061. var curve = new SplineCurve( npts );
  22062. this.curves.push( curve );
  22063. this.currentPoint.copy( pts[ pts.length - 1 ] );
  22064. },
  22065. arc: function ( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  22066. var x0 = this.currentPoint.x;
  22067. var y0 = this.currentPoint.y;
  22068. this.absarc( aX + x0, aY + y0, aRadius,
  22069. aStartAngle, aEndAngle, aClockwise );
  22070. },
  22071. absarc: function ( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  22072. this.absellipse( aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise );
  22073. },
  22074. ellipse: function ( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  22075. var x0 = this.currentPoint.x;
  22076. var y0 = this.currentPoint.y;
  22077. this.absellipse( aX + x0, aY + y0, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation );
  22078. },
  22079. absellipse: function ( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  22080. var curve = new EllipseCurve( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation );
  22081. if ( this.curves.length > 0 ) {
  22082. // if a previous curve is present, attempt to join
  22083. var firstPoint = curve.getPoint( 0 );
  22084. if ( ! firstPoint.equals( this.currentPoint ) ) {
  22085. this.lineTo( firstPoint.x, firstPoint.y );
  22086. }
  22087. }
  22088. this.curves.push( curve );
  22089. var lastPoint = curve.getPoint( 1 );
  22090. this.currentPoint.copy( lastPoint );
  22091. },
  22092. copy: function ( source ) {
  22093. CurvePath.prototype.copy.call( this, source );
  22094. this.currentPoint.copy( source.currentPoint );
  22095. return this;
  22096. },
  22097. toJSON: function () {
  22098. var data = CurvePath.prototype.toJSON.call( this );
  22099. data.currentPoint = this.currentPoint.toArray();
  22100. return data;
  22101. },
  22102. fromJSON: function ( json ) {
  22103. CurvePath.prototype.fromJSON.call( this, json );
  22104. this.currentPoint.fromArray( json.currentPoint );
  22105. return this;
  22106. }
  22107. } );
  22108. /**
  22109. * @author zz85 / http://www.lab4games.net/zz85/blog
  22110. * Defines a 2d shape plane using paths.
  22111. **/
  22112. // STEP 1 Create a path.
  22113. // STEP 2 Turn path into shape.
  22114. // STEP 3 ExtrudeGeometry takes in Shape/Shapes
  22115. // STEP 3a - Extract points from each shape, turn to vertices
  22116. // STEP 3b - Triangulate each shape, add faces.
  22117. function Shape( points ) {
  22118. Path.call( this, points );
  22119. this.uuid = _Math.generateUUID();
  22120. this.type = 'Shape';
  22121. this.holes = [];
  22122. }
  22123. Shape.prototype = Object.assign( Object.create( Path.prototype ), {
  22124. constructor: Shape,
  22125. getPointsHoles: function ( divisions ) {
  22126. var holesPts = [];
  22127. for ( var i = 0, l = this.holes.length; i < l; i ++ ) {
  22128. holesPts[ i ] = this.holes[ i ].getPoints( divisions );
  22129. }
  22130. return holesPts;
  22131. },
  22132. // get points of shape and holes (keypoints based on segments parameter)
  22133. extractPoints: function ( divisions ) {
  22134. return {
  22135. shape: this.getPoints( divisions ),
  22136. holes: this.getPointsHoles( divisions )
  22137. };
  22138. },
  22139. copy: function ( source ) {
  22140. Path.prototype.copy.call( this, source );
  22141. this.holes = [];
  22142. for ( var i = 0, l = source.holes.length; i < l; i ++ ) {
  22143. var hole = source.holes[ i ];
  22144. this.holes.push( hole.clone() );
  22145. }
  22146. return this;
  22147. },
  22148. toJSON: function () {
  22149. var data = Path.prototype.toJSON.call( this );
  22150. data.uuid = this.uuid;
  22151. data.holes = [];
  22152. for ( var i = 0, l = this.holes.length; i < l; i ++ ) {
  22153. var hole = this.holes[ i ];
  22154. data.holes.push( hole.toJSON() );
  22155. }
  22156. return data;
  22157. },
  22158. fromJSON: function ( json ) {
  22159. Path.prototype.fromJSON.call( this, json );
  22160. this.uuid = json.uuid;
  22161. this.holes = [];
  22162. for ( var i = 0, l = json.holes.length; i < l; i ++ ) {
  22163. var hole = json.holes[ i ];
  22164. this.holes.push( new Path().fromJSON( hole ) );
  22165. }
  22166. return this;
  22167. }
  22168. } );
  22169. /**
  22170. * @author mrdoob / http://mrdoob.com/
  22171. * @author alteredq / http://alteredqualia.com/
  22172. */
  22173. function Light( color, intensity ) {
  22174. Object3D.call( this );
  22175. this.type = 'Light';
  22176. this.color = new Color( color );
  22177. this.intensity = intensity !== undefined ? intensity : 1;
  22178. this.receiveShadow = undefined;
  22179. }
  22180. Light.prototype = Object.assign( Object.create( Object3D.prototype ), {
  22181. constructor: Light,
  22182. isLight: true,
  22183. copy: function ( source ) {
  22184. Object3D.prototype.copy.call( this, source );
  22185. this.color.copy( source.color );
  22186. this.intensity = source.intensity;
  22187. return this;
  22188. },
  22189. toJSON: function ( meta ) {
  22190. var data = Object3D.prototype.toJSON.call( this, meta );
  22191. data.object.color = this.color.getHex();
  22192. data.object.intensity = this.intensity;
  22193. if ( this.groundColor !== undefined ) data.object.groundColor = this.groundColor.getHex();
  22194. if ( this.distance !== undefined ) data.object.distance = this.distance;
  22195. if ( this.angle !== undefined ) data.object.angle = this.angle;
  22196. if ( this.decay !== undefined ) data.object.decay = this.decay;
  22197. if ( this.penumbra !== undefined ) data.object.penumbra = this.penumbra;
  22198. if ( this.shadow !== undefined ) data.object.shadow = this.shadow.toJSON();
  22199. return data;
  22200. }
  22201. } );
  22202. /**
  22203. * @author alteredq / http://alteredqualia.com/
  22204. */
  22205. function HemisphereLight( skyColor, groundColor, intensity ) {
  22206. Light.call( this, skyColor, intensity );
  22207. this.type = 'HemisphereLight';
  22208. this.castShadow = undefined;
  22209. this.position.copy( Object3D.DefaultUp );
  22210. this.updateMatrix();
  22211. this.groundColor = new Color( groundColor );
  22212. }
  22213. HemisphereLight.prototype = Object.assign( Object.create( Light.prototype ), {
  22214. constructor: HemisphereLight,
  22215. isHemisphereLight: true,
  22216. copy: function ( source ) {
  22217. Light.prototype.copy.call( this, source );
  22218. this.groundColor.copy( source.groundColor );
  22219. return this;
  22220. }
  22221. } );
  22222. /**
  22223. * @author mrdoob / http://mrdoob.com/
  22224. */
  22225. function LightShadow( camera ) {
  22226. this.camera = camera;
  22227. this.bias = 0;
  22228. this.radius = 1;
  22229. this.mapSize = new Vector2( 512, 512 );
  22230. this.map = null;
  22231. this.matrix = new Matrix4();
  22232. }
  22233. Object.assign( LightShadow.prototype, {
  22234. copy: function ( source ) {
  22235. this.camera = source.camera.clone();
  22236. this.bias = source.bias;
  22237. this.radius = source.radius;
  22238. this.mapSize.copy( source.mapSize );
  22239. return this;
  22240. },
  22241. clone: function () {
  22242. return new this.constructor().copy( this );
  22243. },
  22244. toJSON: function () {
  22245. var object = {};
  22246. if ( this.bias !== 0 ) object.bias = this.bias;
  22247. if ( this.radius !== 1 ) object.radius = this.radius;
  22248. if ( this.mapSize.x !== 512 || this.mapSize.y !== 512 ) object.mapSize = this.mapSize.toArray();
  22249. object.camera = this.camera.toJSON( false ).object;
  22250. delete object.camera.matrix;
  22251. return object;
  22252. }
  22253. } );
  22254. /**
  22255. * @author mrdoob / http://mrdoob.com/
  22256. */
  22257. function SpotLightShadow() {
  22258. LightShadow.call( this, new PerspectiveCamera( 50, 1, 0.5, 500 ) );
  22259. }
  22260. SpotLightShadow.prototype = Object.assign( Object.create( LightShadow.prototype ), {
  22261. constructor: SpotLightShadow,
  22262. isSpotLightShadow: true,
  22263. update: function ( light ) {
  22264. var camera = this.camera;
  22265. var fov = _Math.RAD2DEG * 2 * light.angle;
  22266. var aspect = this.mapSize.width / this.mapSize.height;
  22267. var far = light.distance || camera.far;
  22268. if ( fov !== camera.fov || aspect !== camera.aspect || far !== camera.far ) {
  22269. camera.fov = fov;
  22270. camera.aspect = aspect;
  22271. camera.far = far;
  22272. camera.updateProjectionMatrix();
  22273. }
  22274. }
  22275. } );
  22276. /**
  22277. * @author alteredq / http://alteredqualia.com/
  22278. */
  22279. function SpotLight( color, intensity, distance, angle, penumbra, decay ) {
  22280. Light.call( this, color, intensity );
  22281. this.type = 'SpotLight';
  22282. this.position.copy( Object3D.DefaultUp );
  22283. this.updateMatrix();
  22284. this.target = new Object3D();
  22285. Object.defineProperty( this, 'power', {
  22286. get: function () {
  22287. // intensity = power per solid angle.
  22288. // ref: equation (17) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  22289. return this.intensity * Math.PI;
  22290. },
  22291. set: function ( power ) {
  22292. // intensity = power per solid angle.
  22293. // ref: equation (17) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  22294. this.intensity = power / Math.PI;
  22295. }
  22296. } );
  22297. this.distance = ( distance !== undefined ) ? distance : 0;
  22298. this.angle = ( angle !== undefined ) ? angle : Math.PI / 3;
  22299. this.penumbra = ( penumbra !== undefined ) ? penumbra : 0;
  22300. this.decay = ( decay !== undefined ) ? decay : 1; // for physically correct lights, should be 2.
  22301. this.shadow = new SpotLightShadow();
  22302. }
  22303. SpotLight.prototype = Object.assign( Object.create( Light.prototype ), {
  22304. constructor: SpotLight,
  22305. isSpotLight: true,
  22306. copy: function ( source ) {
  22307. Light.prototype.copy.call( this, source );
  22308. this.distance = source.distance;
  22309. this.angle = source.angle;
  22310. this.penumbra = source.penumbra;
  22311. this.decay = source.decay;
  22312. this.target = source.target.clone();
  22313. this.shadow = source.shadow.clone();
  22314. return this;
  22315. }
  22316. } );
  22317. /**
  22318. * @author mrdoob / http://mrdoob.com/
  22319. */
  22320. function PointLight( color, intensity, distance, decay ) {
  22321. Light.call( this, color, intensity );
  22322. this.type = 'PointLight';
  22323. Object.defineProperty( this, 'power', {
  22324. get: function () {
  22325. // intensity = power per solid angle.
  22326. // ref: equation (15) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  22327. return this.intensity * 4 * Math.PI;
  22328. },
  22329. set: function ( power ) {
  22330. // intensity = power per solid angle.
  22331. // ref: equation (15) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  22332. this.intensity = power / ( 4 * Math.PI );
  22333. }
  22334. } );
  22335. this.distance = ( distance !== undefined ) ? distance : 0;
  22336. this.decay = ( decay !== undefined ) ? decay : 1; // for physically correct lights, should be 2.
  22337. this.shadow = new LightShadow( new PerspectiveCamera( 90, 1, 0.5, 500 ) );
  22338. }
  22339. PointLight.prototype = Object.assign( Object.create( Light.prototype ), {
  22340. constructor: PointLight,
  22341. isPointLight: true,
  22342. copy: function ( source ) {
  22343. Light.prototype.copy.call( this, source );
  22344. this.distance = source.distance;
  22345. this.decay = source.decay;
  22346. this.shadow = source.shadow.clone();
  22347. return this;
  22348. }
  22349. } );
  22350. /**
  22351. * @author alteredq / http://alteredqualia.com/
  22352. * @author arose / http://github.com/arose
  22353. */
  22354. function OrthographicCamera( left, right, top, bottom, near, far ) {
  22355. Camera.call( this );
  22356. this.type = 'OrthographicCamera';
  22357. this.zoom = 1;
  22358. this.view = null;
  22359. this.left = ( left !== undefined ) ? left : - 1;
  22360. this.right = ( right !== undefined ) ? right : 1;
  22361. this.top = ( top !== undefined ) ? top : 1;
  22362. this.bottom = ( bottom !== undefined ) ? bottom : - 1;
  22363. this.near = ( near !== undefined ) ? near : 0.1;
  22364. this.far = ( far !== undefined ) ? far : 2000;
  22365. this.updateProjectionMatrix();
  22366. }
  22367. OrthographicCamera.prototype = Object.assign( Object.create( Camera.prototype ), {
  22368. constructor: OrthographicCamera,
  22369. isOrthographicCamera: true,
  22370. copy: function ( source, recursive ) {
  22371. Camera.prototype.copy.call( this, source, recursive );
  22372. this.left = source.left;
  22373. this.right = source.right;
  22374. this.top = source.top;
  22375. this.bottom = source.bottom;
  22376. this.near = source.near;
  22377. this.far = source.far;
  22378. this.zoom = source.zoom;
  22379. this.view = source.view === null ? null : Object.assign( {}, source.view );
  22380. return this;
  22381. },
  22382. setViewOffset: function ( fullWidth, fullHeight, x, y, width, height ) {
  22383. if ( this.view === null ) {
  22384. this.view = {
  22385. enabled: true,
  22386. fullWidth: 1,
  22387. fullHeight: 1,
  22388. offsetX: 0,
  22389. offsetY: 0,
  22390. width: 1,
  22391. height: 1
  22392. };
  22393. }
  22394. this.view.enabled = true;
  22395. this.view.fullWidth = fullWidth;
  22396. this.view.fullHeight = fullHeight;
  22397. this.view.offsetX = x;
  22398. this.view.offsetY = y;
  22399. this.view.width = width;
  22400. this.view.height = height;
  22401. this.updateProjectionMatrix();
  22402. },
  22403. clearViewOffset: function () {
  22404. if ( this.view !== null ) {
  22405. this.view.enabled = false;
  22406. }
  22407. this.updateProjectionMatrix();
  22408. },
  22409. updateProjectionMatrix: function () {
  22410. var dx = ( this.right - this.left ) / ( 2 * this.zoom );
  22411. var dy = ( this.top - this.bottom ) / ( 2 * this.zoom );
  22412. var cx = ( this.right + this.left ) / 2;
  22413. var cy = ( this.top + this.bottom ) / 2;
  22414. var left = cx - dx;
  22415. var right = cx + dx;
  22416. var top = cy + dy;
  22417. var bottom = cy - dy;
  22418. if ( this.view !== null && this.view.enabled ) {
  22419. var zoomW = this.zoom / ( this.view.width / this.view.fullWidth );
  22420. var zoomH = this.zoom / ( this.view.height / this.view.fullHeight );
  22421. var scaleW = ( this.right - this.left ) / this.view.width;
  22422. var scaleH = ( this.top - this.bottom ) / this.view.height;
  22423. left += scaleW * ( this.view.offsetX / zoomW );
  22424. right = left + scaleW * ( this.view.width / zoomW );
  22425. top -= scaleH * ( this.view.offsetY / zoomH );
  22426. bottom = top - scaleH * ( this.view.height / zoomH );
  22427. }
  22428. this.projectionMatrix.makeOrthographic( left, right, top, bottom, this.near, this.far );
  22429. this.projectionMatrixInverse.getInverse( this.projectionMatrix );
  22430. },
  22431. toJSON: function ( meta ) {
  22432. var data = Object3D.prototype.toJSON.call( this, meta );
  22433. data.object.zoom = this.zoom;
  22434. data.object.left = this.left;
  22435. data.object.right = this.right;
  22436. data.object.top = this.top;
  22437. data.object.bottom = this.bottom;
  22438. data.object.near = this.near;
  22439. data.object.far = this.far;
  22440. if ( this.view !== null ) data.object.view = Object.assign( {}, this.view );
  22441. return data;
  22442. }
  22443. } );
  22444. /**
  22445. * @author mrdoob / http://mrdoob.com/
  22446. */
  22447. function DirectionalLightShadow( ) {
  22448. LightShadow.call( this, new OrthographicCamera( - 5, 5, 5, - 5, 0.5, 500 ) );
  22449. }
  22450. DirectionalLightShadow.prototype = Object.assign( Object.create( LightShadow.prototype ), {
  22451. constructor: DirectionalLightShadow
  22452. } );
  22453. /**
  22454. * @author mrdoob / http://mrdoob.com/
  22455. * @author alteredq / http://alteredqualia.com/
  22456. */
  22457. function DirectionalLight( color, intensity ) {
  22458. Light.call( this, color, intensity );
  22459. this.type = 'DirectionalLight';
  22460. this.position.copy( Object3D.DefaultUp );
  22461. this.updateMatrix();
  22462. this.target = new Object3D();
  22463. this.shadow = new DirectionalLightShadow();
  22464. }
  22465. DirectionalLight.prototype = Object.assign( Object.create( Light.prototype ), {
  22466. constructor: DirectionalLight,
  22467. isDirectionalLight: true,
  22468. copy: function ( source ) {
  22469. Light.prototype.copy.call( this, source );
  22470. this.target = source.target.clone();
  22471. this.shadow = source.shadow.clone();
  22472. return this;
  22473. }
  22474. } );
  22475. /**
  22476. * @author mrdoob / http://mrdoob.com/
  22477. */
  22478. function AmbientLight( color, intensity ) {
  22479. Light.call( this, color, intensity );
  22480. this.type = 'AmbientLight';
  22481. this.castShadow = undefined;
  22482. }
  22483. AmbientLight.prototype = Object.assign( Object.create( Light.prototype ), {
  22484. constructor: AmbientLight,
  22485. isAmbientLight: true
  22486. } );
  22487. /**
  22488. * @author abelnation / http://github.com/abelnation
  22489. */
  22490. function RectAreaLight( color, intensity, width, height ) {
  22491. Light.call( this, color, intensity );
  22492. this.type = 'RectAreaLight';
  22493. this.width = ( width !== undefined ) ? width : 10;
  22494. this.height = ( height !== undefined ) ? height : 10;
  22495. }
  22496. RectAreaLight.prototype = Object.assign( Object.create( Light.prototype ), {
  22497. constructor: RectAreaLight,
  22498. isRectAreaLight: true,
  22499. copy: function ( source ) {
  22500. Light.prototype.copy.call( this, source );
  22501. this.width = source.width;
  22502. this.height = source.height;
  22503. return this;
  22504. },
  22505. toJSON: function ( meta ) {
  22506. var data = Light.prototype.toJSON.call( this, meta );
  22507. data.object.width = this.width;
  22508. data.object.height = this.height;
  22509. return data;
  22510. }
  22511. } );
  22512. /**
  22513. * @author mrdoob / http://mrdoob.com/
  22514. */
  22515. function MaterialLoader( manager ) {
  22516. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  22517. this.textures = {};
  22518. }
  22519. Object.assign( MaterialLoader.prototype, {
  22520. load: function ( url, onLoad, onProgress, onError ) {
  22521. var scope = this;
  22522. var loader = new FileLoader( scope.manager );
  22523. loader.setPath( scope.path );
  22524. loader.load( url, function ( text ) {
  22525. onLoad( scope.parse( JSON.parse( text ) ) );
  22526. }, onProgress, onError );
  22527. },
  22528. parse: function ( json ) {
  22529. var textures = this.textures;
  22530. function getTexture( name ) {
  22531. if ( textures[ name ] === undefined ) {
  22532. console.warn( 'THREE.MaterialLoader: Undefined texture', name );
  22533. }
  22534. return textures[ name ];
  22535. }
  22536. var material = new Materials[ json.type ]();
  22537. if ( json.uuid !== undefined ) material.uuid = json.uuid;
  22538. if ( json.name !== undefined ) material.name = json.name;
  22539. if ( json.color !== undefined ) material.color.setHex( json.color );
  22540. if ( json.roughness !== undefined ) material.roughness = json.roughness;
  22541. if ( json.metalness !== undefined ) material.metalness = json.metalness;
  22542. if ( json.emissive !== undefined ) material.emissive.setHex( json.emissive );
  22543. if ( json.specular !== undefined ) material.specular.setHex( json.specular );
  22544. if ( json.shininess !== undefined ) material.shininess = json.shininess;
  22545. if ( json.clearCoat !== undefined ) material.clearCoat = json.clearCoat;
  22546. if ( json.clearCoatRoughness !== undefined ) material.clearCoatRoughness = json.clearCoatRoughness;
  22547. if ( json.vertexColors !== undefined ) material.vertexColors = json.vertexColors;
  22548. if ( json.fog !== undefined ) material.fog = json.fog;
  22549. if ( json.flatShading !== undefined ) material.flatShading = json.flatShading;
  22550. if ( json.blending !== undefined ) material.blending = json.blending;
  22551. if ( json.combine !== undefined ) material.combine = json.combine;
  22552. if ( json.side !== undefined ) material.side = json.side;
  22553. if ( json.opacity !== undefined ) material.opacity = json.opacity;
  22554. if ( json.transparent !== undefined ) material.transparent = json.transparent;
  22555. if ( json.alphaTest !== undefined ) material.alphaTest = json.alphaTest;
  22556. if ( json.depthTest !== undefined ) material.depthTest = json.depthTest;
  22557. if ( json.depthWrite !== undefined ) material.depthWrite = json.depthWrite;
  22558. if ( json.colorWrite !== undefined ) material.colorWrite = json.colorWrite;
  22559. if ( json.wireframe !== undefined ) material.wireframe = json.wireframe;
  22560. if ( json.wireframeLinewidth !== undefined ) material.wireframeLinewidth = json.wireframeLinewidth;
  22561. if ( json.wireframeLinecap !== undefined ) material.wireframeLinecap = json.wireframeLinecap;
  22562. if ( json.wireframeLinejoin !== undefined ) material.wireframeLinejoin = json.wireframeLinejoin;
  22563. if ( json.rotation !== undefined ) material.rotation = json.rotation;
  22564. if ( json.linewidth !== 1 ) material.linewidth = json.linewidth;
  22565. if ( json.dashSize !== undefined ) material.dashSize = json.dashSize;
  22566. if ( json.gapSize !== undefined ) material.gapSize = json.gapSize;
  22567. if ( json.scale !== undefined ) material.scale = json.scale;
  22568. if ( json.polygonOffset !== undefined ) material.polygonOffset = json.polygonOffset;
  22569. if ( json.polygonOffsetFactor !== undefined ) material.polygonOffsetFactor = json.polygonOffsetFactor;
  22570. if ( json.polygonOffsetUnits !== undefined ) material.polygonOffsetUnits = json.polygonOffsetUnits;
  22571. if ( json.skinning !== undefined ) material.skinning = json.skinning;
  22572. if ( json.morphTargets !== undefined ) material.morphTargets = json.morphTargets;
  22573. if ( json.dithering !== undefined ) material.dithering = json.dithering;
  22574. if ( json.visible !== undefined ) material.visible = json.visible;
  22575. if ( json.userData !== undefined ) material.userData = json.userData;
  22576. // Shader Material
  22577. if ( json.uniforms !== undefined ) {
  22578. for ( var name in json.uniforms ) {
  22579. var uniform = json.uniforms[ name ];
  22580. material.uniforms[ name ] = {};
  22581. switch ( uniform.type ) {
  22582. case 't':
  22583. material.uniforms[ name ].value = getTexture( uniform.value );
  22584. break;
  22585. case 'c':
  22586. material.uniforms[ name ].value = new Color().setHex( uniform.value );
  22587. break;
  22588. case 'v2':
  22589. material.uniforms[ name ].value = new Vector2().fromArray( uniform.value );
  22590. break;
  22591. case 'v3':
  22592. material.uniforms[ name ].value = new Vector3().fromArray( uniform.value );
  22593. break;
  22594. case 'v4':
  22595. material.uniforms[ name ].value = new Vector4().fromArray( uniform.value );
  22596. break;
  22597. case 'm3':
  22598. material.uniforms[ name ].value = new Matrix3().fromArray( uniform.value );
  22599. case 'm4':
  22600. material.uniforms[ name ].value = new Matrix4().fromArray( uniform.value );
  22601. break;
  22602. default:
  22603. material.uniforms[ name ].value = uniform.value;
  22604. }
  22605. }
  22606. }
  22607. if ( json.defines !== undefined ) material.defines = json.defines;
  22608. if ( json.vertexShader !== undefined ) material.vertexShader = json.vertexShader;
  22609. if ( json.fragmentShader !== undefined ) material.fragmentShader = json.fragmentShader;
  22610. if ( json.extensions !== undefined ) {
  22611. for ( var key in json.extensions ) {
  22612. material.extensions[ key ] = json.extensions[ key ];
  22613. }
  22614. }
  22615. // Deprecated
  22616. if ( json.shading !== undefined ) material.flatShading = json.shading === 1; // THREE.FlatShading
  22617. // for PointsMaterial
  22618. if ( json.size !== undefined ) material.size = json.size;
  22619. if ( json.sizeAttenuation !== undefined ) material.sizeAttenuation = json.sizeAttenuation;
  22620. // maps
  22621. if ( json.map !== undefined ) material.map = getTexture( json.map );
  22622. if ( json.matcap !== undefined ) material.matcap = getTexture( json.matcap );
  22623. if ( json.alphaMap !== undefined ) {
  22624. material.alphaMap = getTexture( json.alphaMap );
  22625. material.transparent = true;
  22626. }
  22627. if ( json.bumpMap !== undefined ) material.bumpMap = getTexture( json.bumpMap );
  22628. if ( json.bumpScale !== undefined ) material.bumpScale = json.bumpScale;
  22629. if ( json.normalMap !== undefined ) material.normalMap = getTexture( json.normalMap );
  22630. if ( json.normalMapType !== undefined ) material.normalMapType = json.normalMapType;
  22631. if ( json.normalScale !== undefined ) {
  22632. var normalScale = json.normalScale;
  22633. if ( Array.isArray( normalScale ) === false ) {
  22634. // Blender exporter used to export a scalar. See #7459
  22635. normalScale = [ normalScale, normalScale ];
  22636. }
  22637. material.normalScale = new Vector2().fromArray( normalScale );
  22638. }
  22639. if ( json.displacementMap !== undefined ) material.displacementMap = getTexture( json.displacementMap );
  22640. if ( json.displacementScale !== undefined ) material.displacementScale = json.displacementScale;
  22641. if ( json.displacementBias !== undefined ) material.displacementBias = json.displacementBias;
  22642. if ( json.roughnessMap !== undefined ) material.roughnessMap = getTexture( json.roughnessMap );
  22643. if ( json.metalnessMap !== undefined ) material.metalnessMap = getTexture( json.metalnessMap );
  22644. if ( json.emissiveMap !== undefined ) material.emissiveMap = getTexture( json.emissiveMap );
  22645. if ( json.emissiveIntensity !== undefined ) material.emissiveIntensity = json.emissiveIntensity;
  22646. if ( json.specularMap !== undefined ) material.specularMap = getTexture( json.specularMap );
  22647. if ( json.envMap !== undefined ) material.envMap = getTexture( json.envMap );
  22648. if ( json.envMapIntensity !== undefined ) material.envMapIntensity = json.envMapIntensity;
  22649. if ( json.reflectivity !== undefined ) material.reflectivity = json.reflectivity;
  22650. if ( json.lightMap !== undefined ) material.lightMap = getTexture( json.lightMap );
  22651. if ( json.lightMapIntensity !== undefined ) material.lightMapIntensity = json.lightMapIntensity;
  22652. if ( json.aoMap !== undefined ) material.aoMap = getTexture( json.aoMap );
  22653. if ( json.aoMapIntensity !== undefined ) material.aoMapIntensity = json.aoMapIntensity;
  22654. if ( json.gradientMap !== undefined ) material.gradientMap = getTexture( json.gradientMap );
  22655. return material;
  22656. },
  22657. setPath: function ( value ) {
  22658. this.path = value;
  22659. return this;
  22660. },
  22661. setTextures: function ( value ) {
  22662. this.textures = value;
  22663. return this;
  22664. }
  22665. } );
  22666. /**
  22667. * @author Don McCurdy / https://www.donmccurdy.com
  22668. */
  22669. var LoaderUtils = {
  22670. decodeText: function ( array ) {
  22671. if ( typeof TextDecoder !== 'undefined' ) {
  22672. return new TextDecoder().decode( array );
  22673. }
  22674. // Avoid the String.fromCharCode.apply(null, array) shortcut, which
  22675. // throws a "maximum call stack size exceeded" error for large arrays.
  22676. var s = '';
  22677. for ( var i = 0, il = array.length; i < il; i ++ ) {
  22678. // Implicitly assumes little-endian.
  22679. s += String.fromCharCode( array[ i ] );
  22680. }
  22681. // Merges multi-byte utf-8 characters.
  22682. return decodeURIComponent( escape( s ) );
  22683. },
  22684. extractUrlBase: function ( url ) {
  22685. var index = url.lastIndexOf( '/' );
  22686. if ( index === - 1 ) return './';
  22687. return url.substr( 0, index + 1 );
  22688. }
  22689. };
  22690. /**
  22691. * @author mrdoob / http://mrdoob.com/
  22692. */
  22693. function BufferGeometryLoader( manager ) {
  22694. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  22695. }
  22696. Object.assign( BufferGeometryLoader.prototype, {
  22697. load: function ( url, onLoad, onProgress, onError ) {
  22698. var scope = this;
  22699. var loader = new FileLoader( scope.manager );
  22700. loader.setPath( scope.path );
  22701. loader.load( url, function ( text ) {
  22702. onLoad( scope.parse( JSON.parse( text ) ) );
  22703. }, onProgress, onError );
  22704. },
  22705. parse: function ( json ) {
  22706. var geometry = new BufferGeometry();
  22707. var index = json.data.index;
  22708. if ( index !== undefined ) {
  22709. var typedArray = new TYPED_ARRAYS[ index.type ]( index.array );
  22710. geometry.setIndex( new BufferAttribute( typedArray, 1 ) );
  22711. }
  22712. var attributes = json.data.attributes;
  22713. for ( var key in attributes ) {
  22714. var attribute = attributes[ key ];
  22715. var typedArray = new TYPED_ARRAYS[ attribute.type ]( attribute.array );
  22716. var bufferAttribute = new BufferAttribute( typedArray, attribute.itemSize, attribute.normalized );
  22717. if ( attribute.name !== undefined ) bufferAttribute.name = attribute.name;
  22718. geometry.addAttribute( key, bufferAttribute );
  22719. }
  22720. var morphAttributes = json.data.morphAttributes;
  22721. if ( morphAttributes ) {
  22722. for ( var key in morphAttributes ) {
  22723. var attributeArray = morphAttributes[ key ];
  22724. var array = [];
  22725. for ( var i = 0, il = attributeArray.length; i < il; i ++ ) {
  22726. var attribute = attributeArray[ i ];
  22727. var typedArray = new TYPED_ARRAYS[ attribute.type ]( attribute.array );
  22728. var bufferAttribute = new BufferAttribute( typedArray, attribute.itemSize, attribute.normalized );
  22729. if ( attribute.name !== undefined ) bufferAttribute.name = attribute.name;
  22730. array.push( bufferAttribute );
  22731. }
  22732. geometry.morphAttributes[ key ] = array;
  22733. }
  22734. }
  22735. var groups = json.data.groups || json.data.drawcalls || json.data.offsets;
  22736. if ( groups !== undefined ) {
  22737. for ( var i = 0, n = groups.length; i !== n; ++ i ) {
  22738. var group = groups[ i ];
  22739. geometry.addGroup( group.start, group.count, group.materialIndex );
  22740. }
  22741. }
  22742. var boundingSphere = json.data.boundingSphere;
  22743. if ( boundingSphere !== undefined ) {
  22744. var center = new Vector3();
  22745. if ( boundingSphere.center !== undefined ) {
  22746. center.fromArray( boundingSphere.center );
  22747. }
  22748. geometry.boundingSphere = new Sphere( center, boundingSphere.radius );
  22749. }
  22750. if ( json.name ) geometry.name = json.name;
  22751. if ( json.userData ) geometry.userData = json.userData;
  22752. return geometry;
  22753. },
  22754. setPath: function ( value ) {
  22755. this.path = value;
  22756. return this;
  22757. }
  22758. } );
  22759. var TYPED_ARRAYS = {
  22760. Int8Array: Int8Array,
  22761. Uint8Array: Uint8Array,
  22762. // Workaround for IE11 pre KB2929437. See #11440
  22763. Uint8ClampedArray: typeof Uint8ClampedArray !== 'undefined' ? Uint8ClampedArray : Uint8Array,
  22764. Int16Array: Int16Array,
  22765. Uint16Array: Uint16Array,
  22766. Int32Array: Int32Array,
  22767. Uint32Array: Uint32Array,
  22768. Float32Array: Float32Array,
  22769. Float64Array: Float64Array
  22770. };
  22771. /**
  22772. * @author mrdoob / http://mrdoob.com/
  22773. */
  22774. function ObjectLoader( manager ) {
  22775. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  22776. this.resourcePath = '';
  22777. }
  22778. Object.assign( ObjectLoader.prototype, {
  22779. crossOrigin: 'anonymous',
  22780. load: function ( url, onLoad, onProgress, onError ) {
  22781. var scope = this;
  22782. var path = ( this.path === undefined ) ? LoaderUtils.extractUrlBase( url ) : this.path;
  22783. this.resourcePath = this.resourcePath || path;
  22784. var loader = new FileLoader( scope.manager );
  22785. loader.setPath( this.path );
  22786. loader.load( url, function ( text ) {
  22787. var json = null;
  22788. try {
  22789. json = JSON.parse( text );
  22790. } catch ( error ) {
  22791. if ( onError !== undefined ) onError( error );
  22792. console.error( 'THREE:ObjectLoader: Can\'t parse ' + url + '.', error.message );
  22793. return;
  22794. }
  22795. var metadata = json.metadata;
  22796. if ( metadata === undefined || metadata.type === undefined || metadata.type.toLowerCase() === 'geometry' ) {
  22797. console.error( 'THREE.ObjectLoader: Can\'t load ' + url );
  22798. return;
  22799. }
  22800. scope.parse( json, onLoad );
  22801. }, onProgress, onError );
  22802. },
  22803. setPath: function ( value ) {
  22804. this.path = value;
  22805. return this;
  22806. },
  22807. setResourcePath: function ( value ) {
  22808. this.resourcePath = value;
  22809. return this;
  22810. },
  22811. setCrossOrigin: function ( value ) {
  22812. this.crossOrigin = value;
  22813. return this;
  22814. },
  22815. parse: function ( json, onLoad ) {
  22816. var shapes = this.parseShape( json.shapes );
  22817. var geometries = this.parseGeometries( json.geometries, shapes );
  22818. var images = this.parseImages( json.images, function () {
  22819. if ( onLoad !== undefined ) onLoad( object );
  22820. } );
  22821. var textures = this.parseTextures( json.textures, images );
  22822. var materials = this.parseMaterials( json.materials, textures );
  22823. var object = this.parseObject( json.object, geometries, materials );
  22824. if ( json.animations ) {
  22825. object.animations = this.parseAnimations( json.animations );
  22826. }
  22827. if ( json.images === undefined || json.images.length === 0 ) {
  22828. if ( onLoad !== undefined ) onLoad( object );
  22829. }
  22830. return object;
  22831. },
  22832. parseShape: function ( json ) {
  22833. var shapes = {};
  22834. if ( json !== undefined ) {
  22835. for ( var i = 0, l = json.length; i < l; i ++ ) {
  22836. var shape = new Shape().fromJSON( json[ i ] );
  22837. shapes[ shape.uuid ] = shape;
  22838. }
  22839. }
  22840. return shapes;
  22841. },
  22842. parseGeometries: function ( json, shapes ) {
  22843. var geometries = {};
  22844. if ( json !== undefined ) {
  22845. var bufferGeometryLoader = new BufferGeometryLoader();
  22846. for ( var i = 0, l = json.length; i < l; i ++ ) {
  22847. var geometry;
  22848. var data = json[ i ];
  22849. switch ( data.type ) {
  22850. case 'PlaneGeometry':
  22851. case 'PlaneBufferGeometry':
  22852. geometry = new Geometries[ data.type ](
  22853. data.width,
  22854. data.height,
  22855. data.widthSegments,
  22856. data.heightSegments
  22857. );
  22858. break;
  22859. case 'BoxGeometry':
  22860. case 'BoxBufferGeometry':
  22861. case 'CubeGeometry': // backwards compatible
  22862. geometry = new Geometries[ data.type ](
  22863. data.width,
  22864. data.height,
  22865. data.depth,
  22866. data.widthSegments,
  22867. data.heightSegments,
  22868. data.depthSegments
  22869. );
  22870. break;
  22871. case 'CircleGeometry':
  22872. case 'CircleBufferGeometry':
  22873. geometry = new Geometries[ data.type ](
  22874. data.radius,
  22875. data.segments,
  22876. data.thetaStart,
  22877. data.thetaLength
  22878. );
  22879. break;
  22880. case 'CylinderGeometry':
  22881. case 'CylinderBufferGeometry':
  22882. geometry = new Geometries[ data.type ](
  22883. data.radiusTop,
  22884. data.radiusBottom,
  22885. data.height,
  22886. data.radialSegments,
  22887. data.heightSegments,
  22888. data.openEnded,
  22889. data.thetaStart,
  22890. data.thetaLength
  22891. );
  22892. break;
  22893. case 'ConeGeometry':
  22894. case 'ConeBufferGeometry':
  22895. geometry = new Geometries[ data.type ](
  22896. data.radius,
  22897. data.height,
  22898. data.radialSegments,
  22899. data.heightSegments,
  22900. data.openEnded,
  22901. data.thetaStart,
  22902. data.thetaLength
  22903. );
  22904. break;
  22905. case 'SphereGeometry':
  22906. case 'SphereBufferGeometry':
  22907. geometry = new Geometries[ data.type ](
  22908. data.radius,
  22909. data.widthSegments,
  22910. data.heightSegments,
  22911. data.phiStart,
  22912. data.phiLength,
  22913. data.thetaStart,
  22914. data.thetaLength
  22915. );
  22916. break;
  22917. case 'DodecahedronGeometry':
  22918. case 'DodecahedronBufferGeometry':
  22919. case 'IcosahedronGeometry':
  22920. case 'IcosahedronBufferGeometry':
  22921. case 'OctahedronGeometry':
  22922. case 'OctahedronBufferGeometry':
  22923. case 'TetrahedronGeometry':
  22924. case 'TetrahedronBufferGeometry':
  22925. geometry = new Geometries[ data.type ](
  22926. data.radius,
  22927. data.detail
  22928. );
  22929. break;
  22930. case 'RingGeometry':
  22931. case 'RingBufferGeometry':
  22932. geometry = new Geometries[ data.type ](
  22933. data.innerRadius,
  22934. data.outerRadius,
  22935. data.thetaSegments,
  22936. data.phiSegments,
  22937. data.thetaStart,
  22938. data.thetaLength
  22939. );
  22940. break;
  22941. case 'TorusGeometry':
  22942. case 'TorusBufferGeometry':
  22943. geometry = new Geometries[ data.type ](
  22944. data.radius,
  22945. data.tube,
  22946. data.radialSegments,
  22947. data.tubularSegments,
  22948. data.arc
  22949. );
  22950. break;
  22951. case 'TorusKnotGeometry':
  22952. case 'TorusKnotBufferGeometry':
  22953. geometry = new Geometries[ data.type ](
  22954. data.radius,
  22955. data.tube,
  22956. data.tubularSegments,
  22957. data.radialSegments,
  22958. data.p,
  22959. data.q
  22960. );
  22961. break;
  22962. case 'TubeGeometry':
  22963. case 'TubeBufferGeometry':
  22964. // This only works for built-in curves (e.g. CatmullRomCurve3).
  22965. // User defined curves or instances of CurvePath will not be deserialized.
  22966. geometry = new Geometries[ data.type ](
  22967. new Curves[ data.path.type ]().fromJSON( data.path ),
  22968. data.tubularSegments,
  22969. data.radius,
  22970. data.radialSegments,
  22971. data.closed
  22972. );
  22973. break;
  22974. case 'LatheGeometry':
  22975. case 'LatheBufferGeometry':
  22976. geometry = new Geometries[ data.type ](
  22977. data.points,
  22978. data.segments,
  22979. data.phiStart,
  22980. data.phiLength
  22981. );
  22982. break;
  22983. case 'PolyhedronGeometry':
  22984. case 'PolyhedronBufferGeometry':
  22985. geometry = new Geometries[ data.type ](
  22986. data.vertices,
  22987. data.indices,
  22988. data.radius,
  22989. data.details
  22990. );
  22991. break;
  22992. case 'ShapeGeometry':
  22993. case 'ShapeBufferGeometry':
  22994. var geometryShapes = [];
  22995. for ( var j = 0, jl = data.shapes.length; j < jl; j ++ ) {
  22996. var shape = shapes[ data.shapes[ j ] ];
  22997. geometryShapes.push( shape );
  22998. }
  22999. geometry = new Geometries[ data.type ](
  23000. geometryShapes,
  23001. data.curveSegments
  23002. );
  23003. break;
  23004. case 'ExtrudeGeometry':
  23005. case 'ExtrudeBufferGeometry':
  23006. var geometryShapes = [];
  23007. for ( var j = 0, jl = data.shapes.length; j < jl; j ++ ) {
  23008. var shape = shapes[ data.shapes[ j ] ];
  23009. geometryShapes.push( shape );
  23010. }
  23011. var extrudePath = data.options.extrudePath;
  23012. if ( extrudePath !== undefined ) {
  23013. data.options.extrudePath = new Curves[ extrudePath.type ]().fromJSON( extrudePath );
  23014. }
  23015. geometry = new Geometries[ data.type ](
  23016. geometryShapes,
  23017. data.options
  23018. );
  23019. break;
  23020. case 'BufferGeometry':
  23021. geometry = bufferGeometryLoader.parse( data );
  23022. break;
  23023. case 'Geometry':
  23024. if ( 'THREE' in window && 'LegacyJSONLoader' in THREE ) {
  23025. var geometryLoader = new THREE.LegacyJSONLoader();
  23026. geometry = geometryLoader.parse( data, this.resourcePath ).geometry;
  23027. } else {
  23028. console.error( 'THREE.ObjectLoader: You have to import LegacyJSONLoader in order load geometry data of type "Geometry".' );
  23029. }
  23030. break;
  23031. default:
  23032. console.warn( 'THREE.ObjectLoader: Unsupported geometry type "' + data.type + '"' );
  23033. continue;
  23034. }
  23035. geometry.uuid = data.uuid;
  23036. if ( data.name !== undefined ) geometry.name = data.name;
  23037. if ( geometry.isBufferGeometry === true && data.userData !== undefined ) geometry.userData = data.userData;
  23038. geometries[ data.uuid ] = geometry;
  23039. }
  23040. }
  23041. return geometries;
  23042. },
  23043. parseMaterials: function ( json, textures ) {
  23044. var cache = {}; // MultiMaterial
  23045. var materials = {};
  23046. if ( json !== undefined ) {
  23047. var loader = new MaterialLoader();
  23048. loader.setTextures( textures );
  23049. for ( var i = 0, l = json.length; i < l; i ++ ) {
  23050. var data = json[ i ];
  23051. if ( data.type === 'MultiMaterial' ) {
  23052. // Deprecated
  23053. var array = [];
  23054. for ( var j = 0; j < data.materials.length; j ++ ) {
  23055. var material = data.materials[ j ];
  23056. if ( cache[ material.uuid ] === undefined ) {
  23057. cache[ material.uuid ] = loader.parse( material );
  23058. }
  23059. array.push( cache[ material.uuid ] );
  23060. }
  23061. materials[ data.uuid ] = array;
  23062. } else {
  23063. if ( cache[ data.uuid ] === undefined ) {
  23064. cache[ data.uuid ] = loader.parse( data );
  23065. }
  23066. materials[ data.uuid ] = cache[ data.uuid ];
  23067. }
  23068. }
  23069. }
  23070. return materials;
  23071. },
  23072. parseAnimations: function ( json ) {
  23073. var animations = [];
  23074. for ( var i = 0; i < json.length; i ++ ) {
  23075. var data = json[ i ];
  23076. var clip = AnimationClip.parse( data );
  23077. if ( data.uuid !== undefined ) clip.uuid = data.uuid;
  23078. animations.push( clip );
  23079. }
  23080. return animations;
  23081. },
  23082. parseImages: function ( json, onLoad ) {
  23083. var scope = this;
  23084. var images = {};
  23085. function loadImage( url ) {
  23086. scope.manager.itemStart( url );
  23087. return loader.load( url, function () {
  23088. scope.manager.itemEnd( url );
  23089. }, undefined, function () {
  23090. scope.manager.itemError( url );
  23091. scope.manager.itemEnd( url );
  23092. } );
  23093. }
  23094. if ( json !== undefined && json.length > 0 ) {
  23095. var manager = new LoadingManager( onLoad );
  23096. var loader = new ImageLoader( manager );
  23097. loader.setCrossOrigin( this.crossOrigin );
  23098. for ( var i = 0, il = json.length; i < il; i ++ ) {
  23099. var image = json[ i ];
  23100. var url = image.url;
  23101. if ( Array.isArray( url ) ) {
  23102. // load array of images e.g CubeTexture
  23103. images[ image.uuid ] = [];
  23104. for ( var j = 0, jl = url.length; j < jl; j ++ ) {
  23105. var currentUrl = url[ j ];
  23106. var path = /^(\/\/)|([a-z]+:(\/\/)?)/i.test( currentUrl ) ? currentUrl : scope.resourcePath + currentUrl;
  23107. images[ image.uuid ].push( loadImage( path ) );
  23108. }
  23109. } else {
  23110. // load single image
  23111. var path = /^(\/\/)|([a-z]+:(\/\/)?)/i.test( image.url ) ? image.url : scope.resourcePath + image.url;
  23112. images[ image.uuid ] = loadImage( path );
  23113. }
  23114. }
  23115. }
  23116. return images;
  23117. },
  23118. parseTextures: function ( json, images ) {
  23119. function parseConstant( value, type ) {
  23120. if ( typeof value === 'number' ) return value;
  23121. console.warn( 'THREE.ObjectLoader.parseTexture: Constant should be in numeric form.', value );
  23122. return type[ value ];
  23123. }
  23124. var textures = {};
  23125. if ( json !== undefined ) {
  23126. for ( var i = 0, l = json.length; i < l; i ++ ) {
  23127. var data = json[ i ];
  23128. if ( data.image === undefined ) {
  23129. console.warn( 'THREE.ObjectLoader: No "image" specified for', data.uuid );
  23130. }
  23131. if ( images[ data.image ] === undefined ) {
  23132. console.warn( 'THREE.ObjectLoader: Undefined image', data.image );
  23133. }
  23134. var texture;
  23135. if ( Array.isArray( images[ data.image ] ) ) {
  23136. texture = new CubeTexture( images[ data.image ] );
  23137. } else {
  23138. texture = new Texture( images[ data.image ] );
  23139. }
  23140. texture.needsUpdate = true;
  23141. texture.uuid = data.uuid;
  23142. if ( data.name !== undefined ) texture.name = data.name;
  23143. if ( data.mapping !== undefined ) texture.mapping = parseConstant( data.mapping, TEXTURE_MAPPING );
  23144. if ( data.offset !== undefined ) texture.offset.fromArray( data.offset );
  23145. if ( data.repeat !== undefined ) texture.repeat.fromArray( data.repeat );
  23146. if ( data.center !== undefined ) texture.center.fromArray( data.center );
  23147. if ( data.rotation !== undefined ) texture.rotation = data.rotation;
  23148. if ( data.wrap !== undefined ) {
  23149. texture.wrapS = parseConstant( data.wrap[ 0 ], TEXTURE_WRAPPING );
  23150. texture.wrapT = parseConstant( data.wrap[ 1 ], TEXTURE_WRAPPING );
  23151. }
  23152. if ( data.format !== undefined ) texture.format = data.format;
  23153. if ( data.type !== undefined ) texture.type = data.type;
  23154. if ( data.encoding !== undefined ) texture.encoding = data.encoding;
  23155. if ( data.minFilter !== undefined ) texture.minFilter = parseConstant( data.minFilter, TEXTURE_FILTER );
  23156. if ( data.magFilter !== undefined ) texture.magFilter = parseConstant( data.magFilter, TEXTURE_FILTER );
  23157. if ( data.anisotropy !== undefined ) texture.anisotropy = data.anisotropy;
  23158. if ( data.flipY !== undefined ) texture.flipY = data.flipY;
  23159. if ( data.premultiplyAlpha !== undefined ) texture.premultiplyAlpha = data.premultiplyAlpha;
  23160. if ( data.unpackAlignment !== undefined ) texture.unpackAlignment = data.unpackAlignment;
  23161. textures[ data.uuid ] = texture;
  23162. }
  23163. }
  23164. return textures;
  23165. },
  23166. parseObject: function ( data, geometries, materials ) {
  23167. var object;
  23168. function getGeometry( name ) {
  23169. if ( geometries[ name ] === undefined ) {
  23170. console.warn( 'THREE.ObjectLoader: Undefined geometry', name );
  23171. }
  23172. return geometries[ name ];
  23173. }
  23174. function getMaterial( name ) {
  23175. if ( name === undefined ) return undefined;
  23176. if ( Array.isArray( name ) ) {
  23177. var array = [];
  23178. for ( var i = 0, l = name.length; i < l; i ++ ) {
  23179. var uuid = name[ i ];
  23180. if ( materials[ uuid ] === undefined ) {
  23181. console.warn( 'THREE.ObjectLoader: Undefined material', uuid );
  23182. }
  23183. array.push( materials[ uuid ] );
  23184. }
  23185. return array;
  23186. }
  23187. if ( materials[ name ] === undefined ) {
  23188. console.warn( 'THREE.ObjectLoader: Undefined material', name );
  23189. }
  23190. return materials[ name ];
  23191. }
  23192. switch ( data.type ) {
  23193. case 'Scene':
  23194. object = new Scene();
  23195. if ( data.background !== undefined ) {
  23196. if ( Number.isInteger( data.background ) ) {
  23197. object.background = new Color( data.background );
  23198. }
  23199. }
  23200. if ( data.fog !== undefined ) {
  23201. if ( data.fog.type === 'Fog' ) {
  23202. object.fog = new Fog( data.fog.color, data.fog.near, data.fog.far );
  23203. } else if ( data.fog.type === 'FogExp2' ) {
  23204. object.fog = new FogExp2( data.fog.color, data.fog.density );
  23205. }
  23206. }
  23207. break;
  23208. case 'PerspectiveCamera':
  23209. object = new PerspectiveCamera( data.fov, data.aspect, data.near, data.far );
  23210. if ( data.focus !== undefined ) object.focus = data.focus;
  23211. if ( data.zoom !== undefined ) object.zoom = data.zoom;
  23212. if ( data.filmGauge !== undefined ) object.filmGauge = data.filmGauge;
  23213. if ( data.filmOffset !== undefined ) object.filmOffset = data.filmOffset;
  23214. if ( data.view !== undefined ) object.view = Object.assign( {}, data.view );
  23215. break;
  23216. case 'OrthographicCamera':
  23217. object = new OrthographicCamera( data.left, data.right, data.top, data.bottom, data.near, data.far );
  23218. if ( data.zoom !== undefined ) object.zoom = data.zoom;
  23219. if ( data.view !== undefined ) object.view = Object.assign( {}, data.view );
  23220. break;
  23221. case 'AmbientLight':
  23222. object = new AmbientLight( data.color, data.intensity );
  23223. break;
  23224. case 'DirectionalLight':
  23225. object = new DirectionalLight( data.color, data.intensity );
  23226. break;
  23227. case 'PointLight':
  23228. object = new PointLight( data.color, data.intensity, data.distance, data.decay );
  23229. break;
  23230. case 'RectAreaLight':
  23231. object = new RectAreaLight( data.color, data.intensity, data.width, data.height );
  23232. break;
  23233. case 'SpotLight':
  23234. object = new SpotLight( data.color, data.intensity, data.distance, data.angle, data.penumbra, data.decay );
  23235. break;
  23236. case 'HemisphereLight':
  23237. object = new HemisphereLight( data.color, data.groundColor, data.intensity );
  23238. break;
  23239. case 'SkinnedMesh':
  23240. console.warn( 'THREE.ObjectLoader.parseObject() does not support SkinnedMesh yet.' );
  23241. case 'Mesh':
  23242. var geometry = getGeometry( data.geometry );
  23243. var material = getMaterial( data.material );
  23244. if ( geometry.bones && geometry.bones.length > 0 ) {
  23245. object = new SkinnedMesh( geometry, material );
  23246. } else {
  23247. object = new Mesh( geometry, material );
  23248. }
  23249. if ( data.drawMode !== undefined ) object.setDrawMode( data.drawMode );
  23250. break;
  23251. case 'LOD':
  23252. object = new LOD();
  23253. break;
  23254. case 'Line':
  23255. object = new Line( getGeometry( data.geometry ), getMaterial( data.material ), data.mode );
  23256. break;
  23257. case 'LineLoop':
  23258. object = new LineLoop( getGeometry( data.geometry ), getMaterial( data.material ) );
  23259. break;
  23260. case 'LineSegments':
  23261. object = new LineSegments( getGeometry( data.geometry ), getMaterial( data.material ) );
  23262. break;
  23263. case 'PointCloud':
  23264. case 'Points':
  23265. object = new Points( getGeometry( data.geometry ), getMaterial( data.material ) );
  23266. break;
  23267. case 'Sprite':
  23268. object = new Sprite( getMaterial( data.material ) );
  23269. break;
  23270. case 'Group':
  23271. object = new Group();
  23272. break;
  23273. default:
  23274. object = new Object3D();
  23275. }
  23276. object.uuid = data.uuid;
  23277. if ( data.name !== undefined ) object.name = data.name;
  23278. if ( data.matrix !== undefined ) {
  23279. object.matrix.fromArray( data.matrix );
  23280. if ( data.matrixAutoUpdate !== undefined ) object.matrixAutoUpdate = data.matrixAutoUpdate;
  23281. if ( object.matrixAutoUpdate ) object.matrix.decompose( object.position, object.quaternion, object.scale );
  23282. } else {
  23283. if ( data.position !== undefined ) object.position.fromArray( data.position );
  23284. if ( data.rotation !== undefined ) object.rotation.fromArray( data.rotation );
  23285. if ( data.quaternion !== undefined ) object.quaternion.fromArray( data.quaternion );
  23286. if ( data.scale !== undefined ) object.scale.fromArray( data.scale );
  23287. }
  23288. if ( data.castShadow !== undefined ) object.castShadow = data.castShadow;
  23289. if ( data.receiveShadow !== undefined ) object.receiveShadow = data.receiveShadow;
  23290. if ( data.shadow ) {
  23291. if ( data.shadow.bias !== undefined ) object.shadow.bias = data.shadow.bias;
  23292. if ( data.shadow.radius !== undefined ) object.shadow.radius = data.shadow.radius;
  23293. if ( data.shadow.mapSize !== undefined ) object.shadow.mapSize.fromArray( data.shadow.mapSize );
  23294. if ( data.shadow.camera !== undefined ) object.shadow.camera = this.parseObject( data.shadow.camera );
  23295. }
  23296. if ( data.visible !== undefined ) object.visible = data.visible;
  23297. if ( data.frustumCulled !== undefined ) object.frustumCulled = data.frustumCulled;
  23298. if ( data.renderOrder !== undefined ) object.renderOrder = data.renderOrder;
  23299. if ( data.userData !== undefined ) object.userData = data.userData;
  23300. if ( data.layers !== undefined ) object.layers.mask = data.layers;
  23301. if ( data.children !== undefined ) {
  23302. var children = data.children;
  23303. for ( var i = 0; i < children.length; i ++ ) {
  23304. object.add( this.parseObject( children[ i ], geometries, materials ) );
  23305. }
  23306. }
  23307. if ( data.type === 'LOD' ) {
  23308. var levels = data.levels;
  23309. for ( var l = 0; l < levels.length; l ++ ) {
  23310. var level = levels[ l ];
  23311. var child = object.getObjectByProperty( 'uuid', level.object );
  23312. if ( child !== undefined ) {
  23313. object.addLevel( child, level.distance );
  23314. }
  23315. }
  23316. }
  23317. return object;
  23318. }
  23319. } );
  23320. var TEXTURE_MAPPING = {
  23321. UVMapping: UVMapping,
  23322. CubeReflectionMapping: CubeReflectionMapping,
  23323. CubeRefractionMapping: CubeRefractionMapping,
  23324. EquirectangularReflectionMapping: EquirectangularReflectionMapping,
  23325. EquirectangularRefractionMapping: EquirectangularRefractionMapping,
  23326. SphericalReflectionMapping: SphericalReflectionMapping,
  23327. CubeUVReflectionMapping: CubeUVReflectionMapping,
  23328. CubeUVRefractionMapping: CubeUVRefractionMapping
  23329. };
  23330. var TEXTURE_WRAPPING = {
  23331. RepeatWrapping: RepeatWrapping,
  23332. ClampToEdgeWrapping: ClampToEdgeWrapping,
  23333. MirroredRepeatWrapping: MirroredRepeatWrapping
  23334. };
  23335. var TEXTURE_FILTER = {
  23336. NearestFilter: NearestFilter,
  23337. NearestMipMapNearestFilter: NearestMipMapNearestFilter,
  23338. NearestMipMapLinearFilter: NearestMipMapLinearFilter,
  23339. LinearFilter: LinearFilter,
  23340. LinearMipMapNearestFilter: LinearMipMapNearestFilter,
  23341. LinearMipMapLinearFilter: LinearMipMapLinearFilter
  23342. };
  23343. /**
  23344. * @author thespite / http://clicktorelease.com/
  23345. */
  23346. function ImageBitmapLoader( manager ) {
  23347. if ( typeof createImageBitmap === 'undefined' ) {
  23348. console.warn( 'THREE.ImageBitmapLoader: createImageBitmap() not supported.' );
  23349. }
  23350. if ( typeof fetch === 'undefined' ) {
  23351. console.warn( 'THREE.ImageBitmapLoader: fetch() not supported.' );
  23352. }
  23353. this.manager = manager !== undefined ? manager : DefaultLoadingManager;
  23354. this.options = undefined;
  23355. }
  23356. ImageBitmapLoader.prototype = {
  23357. constructor: ImageBitmapLoader,
  23358. setOptions: function setOptions( options ) {
  23359. this.options = options;
  23360. return this;
  23361. },
  23362. load: function ( url, onLoad, onProgress, onError ) {
  23363. if ( url === undefined ) url = '';
  23364. if ( this.path !== undefined ) url = this.path + url;
  23365. url = this.manager.resolveURL( url );
  23366. var scope = this;
  23367. var cached = Cache.get( url );
  23368. if ( cached !== undefined ) {
  23369. scope.manager.itemStart( url );
  23370. setTimeout( function () {
  23371. if ( onLoad ) onLoad( cached );
  23372. scope.manager.itemEnd( url );
  23373. }, 0 );
  23374. return cached;
  23375. }
  23376. fetch( url ).then( function ( res ) {
  23377. return res.blob();
  23378. } ).then( function ( blob ) {
  23379. if ( scope.options === undefined ) {
  23380. // Workaround for FireFox. It causes an error if you pass options.
  23381. return createImageBitmap( blob );
  23382. } else {
  23383. return createImageBitmap( blob, scope.options );
  23384. }
  23385. } ).then( function ( imageBitmap ) {
  23386. Cache.add( url, imageBitmap );
  23387. if ( onLoad ) onLoad( imageBitmap );
  23388. scope.manager.itemEnd( url );
  23389. } ).catch( function ( e ) {
  23390. if ( onError ) onError( e );
  23391. scope.manager.itemError( url );
  23392. scope.manager.itemEnd( url );
  23393. } );
  23394. scope.manager.itemStart( url );
  23395. },
  23396. setCrossOrigin: function ( /* value */ ) {
  23397. return this;
  23398. },
  23399. setPath: function ( value ) {
  23400. this.path = value;
  23401. return this;
  23402. }
  23403. };
  23404. /**
  23405. * @author zz85 / http://www.lab4games.net/zz85/blog
  23406. * minimal class for proxing functions to Path. Replaces old "extractSubpaths()"
  23407. **/
  23408. function ShapePath() {
  23409. this.type = 'ShapePath';
  23410. this.color = new Color();
  23411. this.subPaths = [];
  23412. this.currentPath = null;
  23413. }
  23414. Object.assign( ShapePath.prototype, {
  23415. moveTo: function ( x, y ) {
  23416. this.currentPath = new Path();
  23417. this.subPaths.push( this.currentPath );
  23418. this.currentPath.moveTo( x, y );
  23419. },
  23420. lineTo: function ( x, y ) {
  23421. this.currentPath.lineTo( x, y );
  23422. },
  23423. quadraticCurveTo: function ( aCPx, aCPy, aX, aY ) {
  23424. this.currentPath.quadraticCurveTo( aCPx, aCPy, aX, aY );
  23425. },
  23426. bezierCurveTo: function ( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY ) {
  23427. this.currentPath.bezierCurveTo( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY );
  23428. },
  23429. splineThru: function ( pts ) {
  23430. this.currentPath.splineThru( pts );
  23431. },
  23432. toShapes: function ( isCCW, noHoles ) {
  23433. function toShapesNoHoles( inSubpaths ) {
  23434. var shapes = [];
  23435. for ( var i = 0, l = inSubpaths.length; i < l; i ++ ) {
  23436. var tmpPath = inSubpaths[ i ];
  23437. var tmpShape = new Shape();
  23438. tmpShape.curves = tmpPath.curves;
  23439. shapes.push( tmpShape );
  23440. }
  23441. return shapes;
  23442. }
  23443. function isPointInsidePolygon( inPt, inPolygon ) {
  23444. var polyLen = inPolygon.length;
  23445. // inPt on polygon contour => immediate success or
  23446. // toggling of inside/outside at every single! intersection point of an edge
  23447. // with the horizontal line through inPt, left of inPt
  23448. // not counting lowerY endpoints of edges and whole edges on that line
  23449. var inside = false;
  23450. for ( var p = polyLen - 1, q = 0; q < polyLen; p = q ++ ) {
  23451. var edgeLowPt = inPolygon[ p ];
  23452. var edgeHighPt = inPolygon[ q ];
  23453. var edgeDx = edgeHighPt.x - edgeLowPt.x;
  23454. var edgeDy = edgeHighPt.y - edgeLowPt.y;
  23455. if ( Math.abs( edgeDy ) > Number.EPSILON ) {
  23456. // not parallel
  23457. if ( edgeDy < 0 ) {
  23458. edgeLowPt = inPolygon[ q ]; edgeDx = - edgeDx;
  23459. edgeHighPt = inPolygon[ p ]; edgeDy = - edgeDy;
  23460. }
  23461. if ( ( inPt.y < edgeLowPt.y ) || ( inPt.y > edgeHighPt.y ) ) continue;
  23462. if ( inPt.y === edgeLowPt.y ) {
  23463. if ( inPt.x === edgeLowPt.x ) return true; // inPt is on contour ?
  23464. // continue; // no intersection or edgeLowPt => doesn't count !!!
  23465. } else {
  23466. var perpEdge = edgeDy * ( inPt.x - edgeLowPt.x ) - edgeDx * ( inPt.y - edgeLowPt.y );
  23467. if ( perpEdge === 0 ) return true; // inPt is on contour ?
  23468. if ( perpEdge < 0 ) continue;
  23469. inside = ! inside; // true intersection left of inPt
  23470. }
  23471. } else {
  23472. // parallel or collinear
  23473. if ( inPt.y !== edgeLowPt.y ) continue; // parallel
  23474. // edge lies on the same horizontal line as inPt
  23475. if ( ( ( edgeHighPt.x <= inPt.x ) && ( inPt.x <= edgeLowPt.x ) ) ||
  23476. ( ( edgeLowPt.x <= inPt.x ) && ( inPt.x <= edgeHighPt.x ) ) ) return true; // inPt: Point on contour !
  23477. // continue;
  23478. }
  23479. }
  23480. return inside;
  23481. }
  23482. var isClockWise = ShapeUtils.isClockWise;
  23483. var subPaths = this.subPaths;
  23484. if ( subPaths.length === 0 ) return [];
  23485. if ( noHoles === true ) return toShapesNoHoles( subPaths );
  23486. var solid, tmpPath, tmpShape, shapes = [];
  23487. if ( subPaths.length === 1 ) {
  23488. tmpPath = subPaths[ 0 ];
  23489. tmpShape = new Shape();
  23490. tmpShape.curves = tmpPath.curves;
  23491. shapes.push( tmpShape );
  23492. return shapes;
  23493. }
  23494. var holesFirst = ! isClockWise( subPaths[ 0 ].getPoints() );
  23495. holesFirst = isCCW ? ! holesFirst : holesFirst;
  23496. // console.log("Holes first", holesFirst);
  23497. var betterShapeHoles = [];
  23498. var newShapes = [];
  23499. var newShapeHoles = [];
  23500. var mainIdx = 0;
  23501. var tmpPoints;
  23502. newShapes[ mainIdx ] = undefined;
  23503. newShapeHoles[ mainIdx ] = [];
  23504. for ( var i = 0, l = subPaths.length; i < l; i ++ ) {
  23505. tmpPath = subPaths[ i ];
  23506. tmpPoints = tmpPath.getPoints();
  23507. solid = isClockWise( tmpPoints );
  23508. solid = isCCW ? ! solid : solid;
  23509. if ( solid ) {
  23510. if ( ( ! holesFirst ) && ( newShapes[ mainIdx ] ) ) mainIdx ++;
  23511. newShapes[ mainIdx ] = { s: new Shape(), p: tmpPoints };
  23512. newShapes[ mainIdx ].s.curves = tmpPath.curves;
  23513. if ( holesFirst ) mainIdx ++;
  23514. newShapeHoles[ mainIdx ] = [];
  23515. //console.log('cw', i);
  23516. } else {
  23517. newShapeHoles[ mainIdx ].push( { h: tmpPath, p: tmpPoints[ 0 ] } );
  23518. //console.log('ccw', i);
  23519. }
  23520. }
  23521. // only Holes? -> probably all Shapes with wrong orientation
  23522. if ( ! newShapes[ 0 ] ) return toShapesNoHoles( subPaths );
  23523. if ( newShapes.length > 1 ) {
  23524. var ambiguous = false;
  23525. var toChange = [];
  23526. for ( var sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx ++ ) {
  23527. betterShapeHoles[ sIdx ] = [];
  23528. }
  23529. for ( var sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx ++ ) {
  23530. var sho = newShapeHoles[ sIdx ];
  23531. for ( var hIdx = 0; hIdx < sho.length; hIdx ++ ) {
  23532. var ho = sho[ hIdx ];
  23533. var hole_unassigned = true;
  23534. for ( var s2Idx = 0; s2Idx < newShapes.length; s2Idx ++ ) {
  23535. if ( isPointInsidePolygon( ho.p, newShapes[ s2Idx ].p ) ) {
  23536. if ( sIdx !== s2Idx ) toChange.push( { froms: sIdx, tos: s2Idx, hole: hIdx } );
  23537. if ( hole_unassigned ) {
  23538. hole_unassigned = false;
  23539. betterShapeHoles[ s2Idx ].push( ho );
  23540. } else {
  23541. ambiguous = true;
  23542. }
  23543. }
  23544. }
  23545. if ( hole_unassigned ) {
  23546. betterShapeHoles[ sIdx ].push( ho );
  23547. }
  23548. }
  23549. }
  23550. // console.log("ambiguous: ", ambiguous);
  23551. if ( toChange.length > 0 ) {
  23552. // console.log("to change: ", toChange);
  23553. if ( ! ambiguous ) newShapeHoles = betterShapeHoles;
  23554. }
  23555. }
  23556. var tmpHoles;
  23557. for ( var i = 0, il = newShapes.length; i < il; i ++ ) {
  23558. tmpShape = newShapes[ i ].s;
  23559. shapes.push( tmpShape );
  23560. tmpHoles = newShapeHoles[ i ];
  23561. for ( var j = 0, jl = tmpHoles.length; j < jl; j ++ ) {
  23562. tmpShape.holes.push( tmpHoles[ j ].h );
  23563. }
  23564. }
  23565. //console.log("shape", shapes);
  23566. return shapes;
  23567. }
  23568. } );
  23569. /**
  23570. * @author zz85 / http://www.lab4games.net/zz85/blog
  23571. * @author mrdoob / http://mrdoob.com/
  23572. */
  23573. function Font( data ) {
  23574. this.type = 'Font';
  23575. this.data = data;
  23576. }
  23577. Object.assign( Font.prototype, {
  23578. isFont: true,
  23579. generateShapes: function ( text, size ) {
  23580. if ( size === undefined ) size = 100;
  23581. var shapes = [];
  23582. var paths = createPaths( text, size, this.data );
  23583. for ( var p = 0, pl = paths.length; p < pl; p ++ ) {
  23584. Array.prototype.push.apply( shapes, paths[ p ].toShapes() );
  23585. }
  23586. return shapes;
  23587. }
  23588. } );
  23589. function createPaths( text, size, data ) {
  23590. var chars = Array.from ? Array.from( text ) : String( text ).split( '' ); // see #13988
  23591. var scale = size / data.resolution;
  23592. var line_height = ( data.boundingBox.yMax - data.boundingBox.yMin + data.underlineThickness ) * scale;
  23593. var paths = [];
  23594. var offsetX = 0, offsetY = 0;
  23595. for ( var i = 0; i < chars.length; i ++ ) {
  23596. var char = chars[ i ];
  23597. if ( char === '\n' ) {
  23598. offsetX = 0;
  23599. offsetY -= line_height;
  23600. } else {
  23601. var ret = createPath( char, scale, offsetX, offsetY, data );
  23602. offsetX += ret.offsetX;
  23603. paths.push( ret.path );
  23604. }
  23605. }
  23606. return paths;
  23607. }
  23608. function createPath( char, scale, offsetX, offsetY, data ) {
  23609. var glyph = data.glyphs[ char ] || data.glyphs[ '?' ];
  23610. if ( ! glyph ) return;
  23611. var path = new ShapePath();
  23612. var x, y, cpx, cpy, cpx1, cpy1, cpx2, cpy2;
  23613. if ( glyph.o ) {
  23614. var outline = glyph._cachedOutline || ( glyph._cachedOutline = glyph.o.split( ' ' ) );
  23615. for ( var i = 0, l = outline.length; i < l; ) {
  23616. var action = outline[ i ++ ];
  23617. switch ( action ) {
  23618. case 'm': // moveTo
  23619. x = outline[ i ++ ] * scale + offsetX;
  23620. y = outline[ i ++ ] * scale + offsetY;
  23621. path.moveTo( x, y );
  23622. break;
  23623. case 'l': // lineTo
  23624. x = outline[ i ++ ] * scale + offsetX;
  23625. y = outline[ i ++ ] * scale + offsetY;
  23626. path.lineTo( x, y );
  23627. break;
  23628. case 'q': // quadraticCurveTo
  23629. cpx = outline[ i ++ ] * scale + offsetX;
  23630. cpy = outline[ i ++ ] * scale + offsetY;
  23631. cpx1 = outline[ i ++ ] * scale + offsetX;
  23632. cpy1 = outline[ i ++ ] * scale + offsetY;
  23633. path.quadraticCurveTo( cpx1, cpy1, cpx, cpy );
  23634. break;
  23635. case 'b': // bezierCurveTo
  23636. cpx = outline[ i ++ ] * scale + offsetX;
  23637. cpy = outline[ i ++ ] * scale + offsetY;
  23638. cpx1 = outline[ i ++ ] * scale + offsetX;
  23639. cpy1 = outline[ i ++ ] * scale + offsetY;
  23640. cpx2 = outline[ i ++ ] * scale + offsetX;
  23641. cpy2 = outline[ i ++ ] * scale + offsetY;
  23642. path.bezierCurveTo( cpx1, cpy1, cpx2, cpy2, cpx, cpy );
  23643. break;
  23644. }
  23645. }
  23646. }
  23647. return { offsetX: glyph.ha * scale, path: path };
  23648. }
  23649. /**
  23650. * @author mrdoob / http://mrdoob.com/
  23651. */
  23652. function FontLoader( manager ) {
  23653. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  23654. }
  23655. Object.assign( FontLoader.prototype, {
  23656. load: function ( url, onLoad, onProgress, onError ) {
  23657. var scope = this;
  23658. var loader = new FileLoader( this.manager );
  23659. loader.setPath( this.path );
  23660. loader.load( url, function ( text ) {
  23661. var json;
  23662. try {
  23663. json = JSON.parse( text );
  23664. } catch ( e ) {
  23665. console.warn( 'THREE.FontLoader: typeface.js support is being deprecated. Use typeface.json instead.' );
  23666. json = JSON.parse( text.substring( 65, text.length - 2 ) );
  23667. }
  23668. var font = scope.parse( json );
  23669. if ( onLoad ) onLoad( font );
  23670. }, onProgress, onError );
  23671. },
  23672. parse: function ( json ) {
  23673. return new Font( json );
  23674. },
  23675. setPath: function ( value ) {
  23676. this.path = value;
  23677. return this;
  23678. }
  23679. } );
  23680. /**
  23681. * @author alteredq / http://alteredqualia.com/
  23682. */
  23683. function Loader() {}
  23684. Loader.Handlers = {
  23685. handlers: [],
  23686. add: function ( regex, loader ) {
  23687. this.handlers.push( regex, loader );
  23688. },
  23689. get: function ( file ) {
  23690. var handlers = this.handlers;
  23691. for ( var i = 0, l = handlers.length; i < l; i += 2 ) {
  23692. var regex = handlers[ i ];
  23693. var loader = handlers[ i + 1 ];
  23694. if ( regex.test( file ) ) {
  23695. return loader;
  23696. }
  23697. }
  23698. return null;
  23699. }
  23700. };
  23701. Object.assign( Loader.prototype, {
  23702. crossOrigin: 'anonymous',
  23703. onLoadStart: function () {},
  23704. onLoadProgress: function () {},
  23705. onLoadComplete: function () {},
  23706. initMaterials: function ( materials, texturePath, crossOrigin ) {
  23707. var array = [];
  23708. for ( var i = 0; i < materials.length; ++ i ) {
  23709. array[ i ] = this.createMaterial( materials[ i ], texturePath, crossOrigin );
  23710. }
  23711. return array;
  23712. },
  23713. createMaterial: ( function () {
  23714. var BlendingMode = {
  23715. NoBlending: NoBlending,
  23716. NormalBlending: NormalBlending,
  23717. AdditiveBlending: AdditiveBlending,
  23718. SubtractiveBlending: SubtractiveBlending,
  23719. MultiplyBlending: MultiplyBlending,
  23720. CustomBlending: CustomBlending
  23721. };
  23722. var color = new Color();
  23723. var textureLoader = new TextureLoader();
  23724. var materialLoader = new MaterialLoader();
  23725. return function createMaterial( m, texturePath, crossOrigin ) {
  23726. // convert from old material format
  23727. var textures = {};
  23728. function loadTexture( path, repeat, offset, wrap, anisotropy ) {
  23729. var fullPath = texturePath + path;
  23730. var loader = Loader.Handlers.get( fullPath );
  23731. var texture;
  23732. if ( loader !== null ) {
  23733. texture = loader.load( fullPath );
  23734. } else {
  23735. textureLoader.setCrossOrigin( crossOrigin );
  23736. texture = textureLoader.load( fullPath );
  23737. }
  23738. if ( repeat !== undefined ) {
  23739. texture.repeat.fromArray( repeat );
  23740. if ( repeat[ 0 ] !== 1 ) texture.wrapS = RepeatWrapping;
  23741. if ( repeat[ 1 ] !== 1 ) texture.wrapT = RepeatWrapping;
  23742. }
  23743. if ( offset !== undefined ) {
  23744. texture.offset.fromArray( offset );
  23745. }
  23746. if ( wrap !== undefined ) {
  23747. if ( wrap[ 0 ] === 'repeat' ) texture.wrapS = RepeatWrapping;
  23748. if ( wrap[ 0 ] === 'mirror' ) texture.wrapS = MirroredRepeatWrapping;
  23749. if ( wrap[ 1 ] === 'repeat' ) texture.wrapT = RepeatWrapping;
  23750. if ( wrap[ 1 ] === 'mirror' ) texture.wrapT = MirroredRepeatWrapping;
  23751. }
  23752. if ( anisotropy !== undefined ) {
  23753. texture.anisotropy = anisotropy;
  23754. }
  23755. var uuid = _Math.generateUUID();
  23756. textures[ uuid ] = texture;
  23757. return uuid;
  23758. }
  23759. //
  23760. var json = {
  23761. uuid: _Math.generateUUID(),
  23762. type: 'MeshLambertMaterial'
  23763. };
  23764. for ( var name in m ) {
  23765. var value = m[ name ];
  23766. switch ( name ) {
  23767. case 'DbgColor':
  23768. case 'DbgIndex':
  23769. case 'opticalDensity':
  23770. case 'illumination':
  23771. break;
  23772. case 'DbgName':
  23773. json.name = value;
  23774. break;
  23775. case 'blending':
  23776. json.blending = BlendingMode[ value ];
  23777. break;
  23778. case 'colorAmbient':
  23779. case 'mapAmbient':
  23780. console.warn( 'THREE.Loader.createMaterial:', name, 'is no longer supported.' );
  23781. break;
  23782. case 'colorDiffuse':
  23783. json.color = color.fromArray( value ).getHex();
  23784. break;
  23785. case 'colorSpecular':
  23786. json.specular = color.fromArray( value ).getHex();
  23787. break;
  23788. case 'colorEmissive':
  23789. json.emissive = color.fromArray( value ).getHex();
  23790. break;
  23791. case 'specularCoef':
  23792. json.shininess = value;
  23793. break;
  23794. case 'shading':
  23795. if ( value.toLowerCase() === 'basic' ) json.type = 'MeshBasicMaterial';
  23796. if ( value.toLowerCase() === 'phong' ) json.type = 'MeshPhongMaterial';
  23797. if ( value.toLowerCase() === 'standard' ) json.type = 'MeshStandardMaterial';
  23798. break;
  23799. case 'mapDiffuse':
  23800. json.map = loadTexture( value, m.mapDiffuseRepeat, m.mapDiffuseOffset, m.mapDiffuseWrap, m.mapDiffuseAnisotropy );
  23801. break;
  23802. case 'mapDiffuseRepeat':
  23803. case 'mapDiffuseOffset':
  23804. case 'mapDiffuseWrap':
  23805. case 'mapDiffuseAnisotropy':
  23806. break;
  23807. case 'mapEmissive':
  23808. json.emissiveMap = loadTexture( value, m.mapEmissiveRepeat, m.mapEmissiveOffset, m.mapEmissiveWrap, m.mapEmissiveAnisotropy );
  23809. break;
  23810. case 'mapEmissiveRepeat':
  23811. case 'mapEmissiveOffset':
  23812. case 'mapEmissiveWrap':
  23813. case 'mapEmissiveAnisotropy':
  23814. break;
  23815. case 'mapLight':
  23816. json.lightMap = loadTexture( value, m.mapLightRepeat, m.mapLightOffset, m.mapLightWrap, m.mapLightAnisotropy );
  23817. break;
  23818. case 'mapLightRepeat':
  23819. case 'mapLightOffset':
  23820. case 'mapLightWrap':
  23821. case 'mapLightAnisotropy':
  23822. break;
  23823. case 'mapAO':
  23824. json.aoMap = loadTexture( value, m.mapAORepeat, m.mapAOOffset, m.mapAOWrap, m.mapAOAnisotropy );
  23825. break;
  23826. case 'mapAORepeat':
  23827. case 'mapAOOffset':
  23828. case 'mapAOWrap':
  23829. case 'mapAOAnisotropy':
  23830. break;
  23831. case 'mapBump':
  23832. json.bumpMap = loadTexture( value, m.mapBumpRepeat, m.mapBumpOffset, m.mapBumpWrap, m.mapBumpAnisotropy );
  23833. break;
  23834. case 'mapBumpScale':
  23835. json.bumpScale = value;
  23836. break;
  23837. case 'mapBumpRepeat':
  23838. case 'mapBumpOffset':
  23839. case 'mapBumpWrap':
  23840. case 'mapBumpAnisotropy':
  23841. break;
  23842. case 'mapNormal':
  23843. json.normalMap = loadTexture( value, m.mapNormalRepeat, m.mapNormalOffset, m.mapNormalWrap, m.mapNormalAnisotropy );
  23844. break;
  23845. case 'mapNormalFactor':
  23846. json.normalScale = value;
  23847. break;
  23848. case 'mapNormalRepeat':
  23849. case 'mapNormalOffset':
  23850. case 'mapNormalWrap':
  23851. case 'mapNormalAnisotropy':
  23852. break;
  23853. case 'mapSpecular':
  23854. json.specularMap = loadTexture( value, m.mapSpecularRepeat, m.mapSpecularOffset, m.mapSpecularWrap, m.mapSpecularAnisotropy );
  23855. break;
  23856. case 'mapSpecularRepeat':
  23857. case 'mapSpecularOffset':
  23858. case 'mapSpecularWrap':
  23859. case 'mapSpecularAnisotropy':
  23860. break;
  23861. case 'mapMetalness':
  23862. json.metalnessMap = loadTexture( value, m.mapMetalnessRepeat, m.mapMetalnessOffset, m.mapMetalnessWrap, m.mapMetalnessAnisotropy );
  23863. break;
  23864. case 'mapMetalnessRepeat':
  23865. case 'mapMetalnessOffset':
  23866. case 'mapMetalnessWrap':
  23867. case 'mapMetalnessAnisotropy':
  23868. break;
  23869. case 'mapRoughness':
  23870. json.roughnessMap = loadTexture( value, m.mapRoughnessRepeat, m.mapRoughnessOffset, m.mapRoughnessWrap, m.mapRoughnessAnisotropy );
  23871. break;
  23872. case 'mapRoughnessRepeat':
  23873. case 'mapRoughnessOffset':
  23874. case 'mapRoughnessWrap':
  23875. case 'mapRoughnessAnisotropy':
  23876. break;
  23877. case 'mapAlpha':
  23878. json.alphaMap = loadTexture( value, m.mapAlphaRepeat, m.mapAlphaOffset, m.mapAlphaWrap, m.mapAlphaAnisotropy );
  23879. break;
  23880. case 'mapAlphaRepeat':
  23881. case 'mapAlphaOffset':
  23882. case 'mapAlphaWrap':
  23883. case 'mapAlphaAnisotropy':
  23884. break;
  23885. case 'flipSided':
  23886. json.side = BackSide;
  23887. break;
  23888. case 'doubleSided':
  23889. json.side = DoubleSide;
  23890. break;
  23891. case 'transparency':
  23892. console.warn( 'THREE.Loader.createMaterial: transparency has been renamed to opacity' );
  23893. json.opacity = value;
  23894. break;
  23895. case 'depthTest':
  23896. case 'depthWrite':
  23897. case 'colorWrite':
  23898. case 'opacity':
  23899. case 'reflectivity':
  23900. case 'transparent':
  23901. case 'visible':
  23902. case 'wireframe':
  23903. json[ name ] = value;
  23904. break;
  23905. case 'vertexColors':
  23906. if ( value === true ) json.vertexColors = VertexColors;
  23907. if ( value === 'face' ) json.vertexColors = FaceColors;
  23908. break;
  23909. default:
  23910. console.error( 'THREE.Loader.createMaterial: Unsupported', name, value );
  23911. break;
  23912. }
  23913. }
  23914. if ( json.type === 'MeshBasicMaterial' ) delete json.emissive;
  23915. if ( json.type !== 'MeshPhongMaterial' ) delete json.specular;
  23916. if ( json.opacity < 1 ) json.transparent = true;
  23917. materialLoader.setTextures( textures );
  23918. return materialLoader.parse( json );
  23919. };
  23920. } )()
  23921. } );
  23922. /**
  23923. * @author mrdoob / http://mrdoob.com/
  23924. */
  23925. var context;
  23926. var AudioContext = {
  23927. getContext: function () {
  23928. if ( context === undefined ) {
  23929. context = new ( window.AudioContext || window.webkitAudioContext )();
  23930. }
  23931. return context;
  23932. },
  23933. setContext: function ( value ) {
  23934. context = value;
  23935. }
  23936. };
  23937. /**
  23938. * @author Reece Aaron Lecrivain / http://reecenotes.com/
  23939. */
  23940. function AudioLoader( manager ) {
  23941. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  23942. }
  23943. Object.assign( AudioLoader.prototype, {
  23944. load: function ( url, onLoad, onProgress, onError ) {
  23945. var loader = new FileLoader( this.manager );
  23946. loader.setResponseType( 'arraybuffer' );
  23947. loader.setPath( this.path );
  23948. loader.load( url, function ( buffer ) {
  23949. // Create a copy of the buffer. The `decodeAudioData` method
  23950. // detaches the buffer when complete, preventing reuse.
  23951. var bufferCopy = buffer.slice( 0 );
  23952. var context = AudioContext.getContext();
  23953. context.decodeAudioData( bufferCopy, function ( audioBuffer ) {
  23954. onLoad( audioBuffer );
  23955. } );
  23956. }, onProgress, onError );
  23957. },
  23958. setPath: function ( value ) {
  23959. this.path = value;
  23960. return this;
  23961. }
  23962. } );
  23963. /**
  23964. * @author bhouston / http://clara.io
  23965. * @author WestLangley / http://github.com/WestLangley
  23966. *
  23967. * Primary reference:
  23968. * https://graphics.stanford.edu/papers/envmap/envmap.pdf
  23969. *
  23970. * Secondary reference:
  23971. * https://www.ppsloan.org/publications/StupidSH36.pdf
  23972. */
  23973. // 3-band SH defined by 9 coefficients
  23974. function SphericalHarmonics3() {
  23975. this.coefficients = [];
  23976. for ( var i = 0; i < 9; i ++ ) {
  23977. this.coefficients.push( new Vector3() );
  23978. }
  23979. }
  23980. Object.assign( SphericalHarmonics3.prototype, {
  23981. isSphericalHarmonics3: true,
  23982. set: function ( coefficients ) {
  23983. for ( var i = 0; i < 9; i ++ ) {
  23984. this.coefficients[ i ].copy( coefficients[ i ] );
  23985. }
  23986. return this;
  23987. },
  23988. zero: function () {
  23989. for ( var i = 0; i < 9; i ++ ) {
  23990. this.coefficients[ i ].set( 0, 0, 0 );
  23991. }
  23992. return this;
  23993. },
  23994. // get the radiance in the direction of the normal
  23995. // target is a Vector3
  23996. getAt: function ( normal, target ) {
  23997. // normal is assumed to be unit length
  23998. var x = normal.x, y = normal.y, z = normal.z;
  23999. var coeff = this.coefficients;
  24000. // band 0
  24001. target = coeff[ 0 ] * 0.282095;
  24002. // band 1
  24003. target += coeff[ 1 ] * 0.488603 * y;
  24004. target += coeff[ 2 ] * 0.488603 * z;
  24005. target += coeff[ 3 ] * 0.488603 * x;
  24006. // band 2
  24007. target += coeff[ 4 ] * 1.092548 * ( x * y );
  24008. target += coeff[ 5 ] * 1.092548 * ( y * z );
  24009. target += coeff[ 6 ] * 0.315392 * ( 3.0 * z * z - 1.0 );
  24010. target += coeff[ 7 ] * 1.092548 * ( x * z );
  24011. target += coeff[ 8 ] * 0.546274 * ( x * x - y * y );
  24012. return target;
  24013. },
  24014. // get the irradiance (radiance convolved with cosine lobe) in the direction of the normal
  24015. // target is a Vector3
  24016. // https://graphics.stanford.edu/papers/envmap/envmap.pdf
  24017. getIrradianceAt: function ( normal, target ) {
  24018. // normal is assumed to be unit length
  24019. var x = normal.x, y = normal.y, z = normal.z;
  24020. var coeff = this.coefficients;
  24021. // band 0
  24022. target = coeff[ 0 ] * 0.886227; // π * 0.282095
  24023. // band 1
  24024. target += coeff[ 1 ] * 2.0 * 0.511664 * y; // ( 2 * π / 3 ) * 0.488603
  24025. target += coeff[ 2 ] * 2.0 * 0.511664 * z;
  24026. target += coeff[ 3 ] * 2.0 * 0.511664 * x;
  24027. // band 2
  24028. target += coeff[ 4 ] * 2.0 * 0.429043 * x * y; // ( π / 4 ) * 1.092548
  24029. target += coeff[ 5 ] * 2.0 * 0.429043 * y * z;
  24030. target += coeff[ 6 ] * ( 0.743125 * z * z - 0.247708 ); // ( π / 4 ) * 0.315392 * 3
  24031. target += coeff[ 7 ] * 2.0 * 0.429043 * x * z;
  24032. target += coeff[ 8 ] * 0.429043 * ( x * x - y * y ); // ( π / 4 ) * 0.546274
  24033. return target;
  24034. },
  24035. add: function ( sh ) {
  24036. for ( var i = 0; i < 9; i ++ ) {
  24037. this.coefficients[ i ].add( sh.coefficients[ i ] );
  24038. }
  24039. return this;
  24040. },
  24041. scale: function ( s ) {
  24042. for ( var i = 0; i < 9; i ++ ) {
  24043. this.coefficients[ i ].multiplyScalar( s );
  24044. }
  24045. return this;
  24046. },
  24047. lerp: function ( sh, alpha ) {
  24048. for ( var i = 0; i < 9; i ++ ) {
  24049. this.coefficients[ i ].lerp( sh.coefficients[ i ], alpha );
  24050. }
  24051. return this;
  24052. },
  24053. equals: function ( sh ) {
  24054. for ( var i = 0; i < 9; i ++ ) {
  24055. if ( ! this.coefficients[ i ].equals( sh.coefficients[ i ] ) ) {
  24056. return false;
  24057. }
  24058. }
  24059. return true;
  24060. },
  24061. copy: function ( sh ) {
  24062. return this.set( sh.coefficients );
  24063. },
  24064. clone: function () {
  24065. return new this.constructor().copy( this );
  24066. },
  24067. fromArray: function ( array ) {
  24068. var coefficients = this.coefficients;
  24069. for ( var i = 0; i < 9; i ++ ) {
  24070. coefficients[ i ].fromArray( array, i * 3 );
  24071. }
  24072. return this;
  24073. },
  24074. toArray: function () {
  24075. var array = [];
  24076. var coefficients = this.coefficients;
  24077. for ( var i = 0; i < 9; i ++ ) {
  24078. coefficients[ i ].toArray( array, i * 3 );
  24079. }
  24080. return array;
  24081. }
  24082. } );
  24083. Object.assign( SphericalHarmonics3, {
  24084. // evaluate the basis functions
  24085. // shBasis is an Array[ 9 ]
  24086. getBasisAt: function ( normal, shBasis ) {
  24087. // normal is assumed to be unit length
  24088. var x = normal.x, y = normal.y, z = normal.z;
  24089. // band 0
  24090. shBasis[ 0 ] = 0.282095;
  24091. // band 1
  24092. shBasis[ 1 ] = 0.488603 * y;
  24093. shBasis[ 2 ] = 0.488603 * z;
  24094. shBasis[ 3 ] = 0.488603 * x;
  24095. // band 2
  24096. shBasis[ 4 ] = 1.092548 * x * y;
  24097. shBasis[ 5 ] = 1.092548 * y * z;
  24098. shBasis[ 6 ] = 0.315392 * ( 3 * z * z - 1 );
  24099. shBasis[ 7 ] = 1.092548 * x * z;
  24100. shBasis[ 8 ] = 0.546274 * ( x * x - y * y );
  24101. }
  24102. } );
  24103. /**
  24104. * @author WestLangley / http://github.com/WestLangley
  24105. *
  24106. * A LightProbe is a source of indirect-diffuse light
  24107. */
  24108. function LightProbe( sh, intensity ) {
  24109. Light.call( this, undefined, intensity );
  24110. this.sh = ( sh !== undefined ) ? sh : new SphericalHarmonics3();
  24111. }
  24112. LightProbe.prototype = Object.assign( Object.create( Light.prototype ), {
  24113. constructor: LightProbe,
  24114. isLightProbe: true,
  24115. copy: function ( source ) {
  24116. Light.prototype.copy.call( this, source );
  24117. this.sh.copy( source.sh );
  24118. this.intensity = source.intensity;
  24119. return this;
  24120. },
  24121. toJSON: function ( meta ) {
  24122. var data = Light.prototype.toJSON.call( this, meta );
  24123. // data.sh = this.sh.toArray(); // todo
  24124. return data;
  24125. }
  24126. } );
  24127. /**
  24128. * @author WestLangley / http://github.com/WestLangley
  24129. */
  24130. function HemisphereLightProbe( skyColor, groundColor, intensity ) {
  24131. LightProbe.call( this, undefined, intensity );
  24132. var color1 = new Color().set( skyColor );
  24133. var color2 = new Color().set( groundColor );
  24134. var sky = new Vector3( color1.r, color1.g, color1.b );
  24135. var ground = new Vector3( color2.r, color2.g, color2.b );
  24136. // without extra factor of PI in the shader, should = 1 / Math.sqrt( Math.PI );
  24137. var c0 = Math.sqrt( Math.PI );
  24138. var c1 = c0 * Math.sqrt( 0.75 );
  24139. this.sh.coefficients[ 0 ].copy( sky ).add( ground ).multiplyScalar( c0 );
  24140. this.sh.coefficients[ 1 ].copy( sky ).sub( ground ).multiplyScalar( c1 );
  24141. }
  24142. HemisphereLightProbe.prototype = Object.assign( Object.create( LightProbe.prototype ), {
  24143. constructor: HemisphereLightProbe,
  24144. isHemisphereLightProbe: true,
  24145. copy: function ( source ) { // modifying colors not currently supported
  24146. LightProbe.prototype.copy.call( this, source );
  24147. return this;
  24148. },
  24149. toJSON: function ( meta ) {
  24150. var data = LightProbe.prototype.toJSON.call( this, meta );
  24151. // data.sh = this.sh.toArray(); // todo
  24152. return data;
  24153. }
  24154. } );
  24155. /**
  24156. * @author WestLangley / http://github.com/WestLangley
  24157. */
  24158. function AmbientLightProbe( color, intensity ) {
  24159. LightProbe.call( this, undefined, intensity );
  24160. var color1 = new Color().set( color );
  24161. // without extra factor of PI in the shader, would be 2 / Math.sqrt( Math.PI );
  24162. this.sh.coefficients[ 0 ].set( color1.r, color1.g, color1.b ).multiplyScalar( 2 * Math.sqrt( Math.PI ) );
  24163. }
  24164. AmbientLightProbe.prototype = Object.assign( Object.create( LightProbe.prototype ), {
  24165. constructor: AmbientLightProbe,
  24166. isAmbientLightProbe: true,
  24167. copy: function ( source ) { // modifying color not currently supported
  24168. LightProbe.prototype.copy.call( this, source );
  24169. return this;
  24170. },
  24171. toJSON: function ( meta ) {
  24172. var data = LightProbe.prototype.toJSON.call( this, meta );
  24173. // data.sh = this.sh.toArray(); // todo
  24174. return data;
  24175. }
  24176. } );
  24177. /**
  24178. * @author mrdoob / http://mrdoob.com/
  24179. */
  24180. function StereoCamera() {
  24181. this.type = 'StereoCamera';
  24182. this.aspect = 1;
  24183. this.eyeSep = 0.064;
  24184. this.cameraL = new PerspectiveCamera();
  24185. this.cameraL.layers.enable( 1 );
  24186. this.cameraL.matrixAutoUpdate = false;
  24187. this.cameraR = new PerspectiveCamera();
  24188. this.cameraR.layers.enable( 2 );
  24189. this.cameraR.matrixAutoUpdate = false;
  24190. }
  24191. Object.assign( StereoCamera.prototype, {
  24192. update: ( function () {
  24193. var instance, focus, fov, aspect, near, far, zoom, eyeSep;
  24194. var eyeRight = new Matrix4();
  24195. var eyeLeft = new Matrix4();
  24196. return function update( camera ) {
  24197. var needsUpdate = instance !== this || focus !== camera.focus || fov !== camera.fov ||
  24198. aspect !== camera.aspect * this.aspect || near !== camera.near ||
  24199. far !== camera.far || zoom !== camera.zoom || eyeSep !== this.eyeSep;
  24200. if ( needsUpdate ) {
  24201. instance = this;
  24202. focus = camera.focus;
  24203. fov = camera.fov;
  24204. aspect = camera.aspect * this.aspect;
  24205. near = camera.near;
  24206. far = camera.far;
  24207. zoom = camera.zoom;
  24208. // Off-axis stereoscopic effect based on
  24209. // http://paulbourke.net/stereographics/stereorender/
  24210. var projectionMatrix = camera.projectionMatrix.clone();
  24211. eyeSep = this.eyeSep / 2;
  24212. var eyeSepOnProjection = eyeSep * near / focus;
  24213. var ymax = ( near * Math.tan( _Math.DEG2RAD * fov * 0.5 ) ) / zoom;
  24214. var xmin, xmax;
  24215. // translate xOffset
  24216. eyeLeft.elements[ 12 ] = - eyeSep;
  24217. eyeRight.elements[ 12 ] = eyeSep;
  24218. // for left eye
  24219. xmin = - ymax * aspect + eyeSepOnProjection;
  24220. xmax = ymax * aspect + eyeSepOnProjection;
  24221. projectionMatrix.elements[ 0 ] = 2 * near / ( xmax - xmin );
  24222. projectionMatrix.elements[ 8 ] = ( xmax + xmin ) / ( xmax - xmin );
  24223. this.cameraL.projectionMatrix.copy( projectionMatrix );
  24224. // for right eye
  24225. xmin = - ymax * aspect - eyeSepOnProjection;
  24226. xmax = ymax * aspect - eyeSepOnProjection;
  24227. projectionMatrix.elements[ 0 ] = 2 * near / ( xmax - xmin );
  24228. projectionMatrix.elements[ 8 ] = ( xmax + xmin ) / ( xmax - xmin );
  24229. this.cameraR.projectionMatrix.copy( projectionMatrix );
  24230. }
  24231. this.cameraL.matrixWorld.copy( camera.matrixWorld ).multiply( eyeLeft );
  24232. this.cameraR.matrixWorld.copy( camera.matrixWorld ).multiply( eyeRight );
  24233. };
  24234. } )()
  24235. } );
  24236. /**
  24237. * Camera for rendering cube maps
  24238. * - renders scene into axis-aligned cube
  24239. *
  24240. * @author alteredq / http://alteredqualia.com/
  24241. */
  24242. var fov = 90, aspect = 1;
  24243. function CubeCamera( near, far, cubeResolution, options ) {
  24244. Object3D.call( this );
  24245. this.type = 'CubeCamera';
  24246. var cameraPX = new PerspectiveCamera( fov, aspect, near, far );
  24247. cameraPX.up.set( 0, - 1, 0 );
  24248. cameraPX.lookAt( new Vector3( 1, 0, 0 ) );
  24249. this.add( cameraPX );
  24250. var cameraNX = new PerspectiveCamera( fov, aspect, near, far );
  24251. cameraNX.up.set( 0, - 1, 0 );
  24252. cameraNX.lookAt( new Vector3( - 1, 0, 0 ) );
  24253. this.add( cameraNX );
  24254. var cameraPY = new PerspectiveCamera( fov, aspect, near, far );
  24255. cameraPY.up.set( 0, 0, 1 );
  24256. cameraPY.lookAt( new Vector3( 0, 1, 0 ) );
  24257. this.add( cameraPY );
  24258. var cameraNY = new PerspectiveCamera( fov, aspect, near, far );
  24259. cameraNY.up.set( 0, 0, - 1 );
  24260. cameraNY.lookAt( new Vector3( 0, - 1, 0 ) );
  24261. this.add( cameraNY );
  24262. var cameraPZ = new PerspectiveCamera( fov, aspect, near, far );
  24263. cameraPZ.up.set( 0, - 1, 0 );
  24264. cameraPZ.lookAt( new Vector3( 0, 0, 1 ) );
  24265. this.add( cameraPZ );
  24266. var cameraNZ = new PerspectiveCamera( fov, aspect, near, far );
  24267. cameraNZ.up.set( 0, - 1, 0 );
  24268. cameraNZ.lookAt( new Vector3( 0, 0, - 1 ) );
  24269. this.add( cameraNZ );
  24270. options = options || { format: RGBFormat, magFilter: LinearFilter, minFilter: LinearFilter };
  24271. this.renderTarget = new WebGLRenderTargetCube( cubeResolution, cubeResolution, options );
  24272. this.renderTarget.texture.name = "CubeCamera";
  24273. this.update = function ( renderer, scene ) {
  24274. if ( this.parent === null ) this.updateMatrixWorld();
  24275. var currentRenderTarget = renderer.getRenderTarget();
  24276. var renderTarget = this.renderTarget;
  24277. var generateMipmaps = renderTarget.texture.generateMipmaps;
  24278. renderTarget.texture.generateMipmaps = false;
  24279. renderer.setRenderTarget( renderTarget, 0 );
  24280. renderer.render( scene, cameraPX );
  24281. renderer.setRenderTarget( renderTarget, 1 );
  24282. renderer.render( scene, cameraNX );
  24283. renderer.setRenderTarget( renderTarget, 2 );
  24284. renderer.render( scene, cameraPY );
  24285. renderer.setRenderTarget( renderTarget, 3 );
  24286. renderer.render( scene, cameraNY );
  24287. renderer.setRenderTarget( renderTarget, 4 );
  24288. renderer.render( scene, cameraPZ );
  24289. renderTarget.texture.generateMipmaps = generateMipmaps;
  24290. renderer.setRenderTarget( renderTarget, 5 );
  24291. renderer.render( scene, cameraNZ );
  24292. renderer.setRenderTarget( currentRenderTarget );
  24293. };
  24294. this.clear = function ( renderer, color, depth, stencil ) {
  24295. var currentRenderTarget = renderer.getRenderTarget();
  24296. var renderTarget = this.renderTarget;
  24297. for ( var i = 0; i < 6; i ++ ) {
  24298. renderer.setRenderTarget( renderTarget, i );
  24299. renderer.clear( color, depth, stencil );
  24300. }
  24301. renderer.setRenderTarget( currentRenderTarget );
  24302. };
  24303. }
  24304. CubeCamera.prototype = Object.create( Object3D.prototype );
  24305. CubeCamera.prototype.constructor = CubeCamera;
  24306. /**
  24307. * @author alteredq / http://alteredqualia.com/
  24308. */
  24309. function Clock( autoStart ) {
  24310. this.autoStart = ( autoStart !== undefined ) ? autoStart : true;
  24311. this.startTime = 0;
  24312. this.oldTime = 0;
  24313. this.elapsedTime = 0;
  24314. this.running = false;
  24315. }
  24316. Object.assign( Clock.prototype, {
  24317. start: function () {
  24318. this.startTime = ( typeof performance === 'undefined' ? Date : performance ).now(); // see #10732
  24319. this.oldTime = this.startTime;
  24320. this.elapsedTime = 0;
  24321. this.running = true;
  24322. },
  24323. stop: function () {
  24324. this.getElapsedTime();
  24325. this.running = false;
  24326. this.autoStart = false;
  24327. },
  24328. getElapsedTime: function () {
  24329. this.getDelta();
  24330. return this.elapsedTime;
  24331. },
  24332. getDelta: function () {
  24333. var diff = 0;
  24334. if ( this.autoStart && ! this.running ) {
  24335. this.start();
  24336. return 0;
  24337. }
  24338. if ( this.running ) {
  24339. var newTime = ( typeof performance === 'undefined' ? Date : performance ).now();
  24340. diff = ( newTime - this.oldTime ) / 1000;
  24341. this.oldTime = newTime;
  24342. this.elapsedTime += diff;
  24343. }
  24344. return diff;
  24345. }
  24346. } );
  24347. /**
  24348. * @author mrdoob / http://mrdoob.com/
  24349. */
  24350. function AudioListener() {
  24351. Object3D.call( this );
  24352. this.type = 'AudioListener';
  24353. this.context = AudioContext.getContext();
  24354. this.gain = this.context.createGain();
  24355. this.gain.connect( this.context.destination );
  24356. this.filter = null;
  24357. this.timeDelta = 0;
  24358. }
  24359. AudioListener.prototype = Object.assign( Object.create( Object3D.prototype ), {
  24360. constructor: AudioListener,
  24361. getInput: function () {
  24362. return this.gain;
  24363. },
  24364. removeFilter: function ( ) {
  24365. if ( this.filter !== null ) {
  24366. this.gain.disconnect( this.filter );
  24367. this.filter.disconnect( this.context.destination );
  24368. this.gain.connect( this.context.destination );
  24369. this.filter = null;
  24370. }
  24371. return this;
  24372. },
  24373. getFilter: function () {
  24374. return this.filter;
  24375. },
  24376. setFilter: function ( value ) {
  24377. if ( this.filter !== null ) {
  24378. this.gain.disconnect( this.filter );
  24379. this.filter.disconnect( this.context.destination );
  24380. } else {
  24381. this.gain.disconnect( this.context.destination );
  24382. }
  24383. this.filter = value;
  24384. this.gain.connect( this.filter );
  24385. this.filter.connect( this.context.destination );
  24386. return this;
  24387. },
  24388. getMasterVolume: function () {
  24389. return this.gain.gain.value;
  24390. },
  24391. setMasterVolume: function ( value ) {
  24392. this.gain.gain.setTargetAtTime( value, this.context.currentTime, 0.01 );
  24393. return this;
  24394. },
  24395. updateMatrixWorld: ( function () {
  24396. var position = new Vector3();
  24397. var quaternion = new Quaternion();
  24398. var scale = new Vector3();
  24399. var orientation = new Vector3();
  24400. var clock = new Clock();
  24401. return function updateMatrixWorld( force ) {
  24402. Object3D.prototype.updateMatrixWorld.call( this, force );
  24403. var listener = this.context.listener;
  24404. var up = this.up;
  24405. this.timeDelta = clock.getDelta();
  24406. this.matrixWorld.decompose( position, quaternion, scale );
  24407. orientation.set( 0, 0, - 1 ).applyQuaternion( quaternion );
  24408. if ( listener.positionX ) {
  24409. // code path for Chrome (see #14393)
  24410. var endTime = this.context.currentTime + this.timeDelta;
  24411. listener.positionX.linearRampToValueAtTime( position.x, endTime );
  24412. listener.positionY.linearRampToValueAtTime( position.y, endTime );
  24413. listener.positionZ.linearRampToValueAtTime( position.z, endTime );
  24414. listener.forwardX.linearRampToValueAtTime( orientation.x, endTime );
  24415. listener.forwardY.linearRampToValueAtTime( orientation.y, endTime );
  24416. listener.forwardZ.linearRampToValueAtTime( orientation.z, endTime );
  24417. listener.upX.linearRampToValueAtTime( up.x, endTime );
  24418. listener.upY.linearRampToValueAtTime( up.y, endTime );
  24419. listener.upZ.linearRampToValueAtTime( up.z, endTime );
  24420. } else {
  24421. listener.setPosition( position.x, position.y, position.z );
  24422. listener.setOrientation( orientation.x, orientation.y, orientation.z, up.x, up.y, up.z );
  24423. }
  24424. };
  24425. } )()
  24426. } );
  24427. /**
  24428. * @author mrdoob / http://mrdoob.com/
  24429. * @author Reece Aaron Lecrivain / http://reecenotes.com/
  24430. */
  24431. function Audio( listener ) {
  24432. Object3D.call( this );
  24433. this.type = 'Audio';
  24434. this.listener = listener;
  24435. this.context = listener.context;
  24436. this.gain = this.context.createGain();
  24437. this.gain.connect( listener.getInput() );
  24438. this.autoplay = false;
  24439. this.buffer = null;
  24440. this.detune = 0;
  24441. this.loop = false;
  24442. this.startTime = 0;
  24443. this.offset = 0;
  24444. this.playbackRate = 1;
  24445. this.isPlaying = false;
  24446. this.hasPlaybackControl = true;
  24447. this.sourceType = 'empty';
  24448. this.filters = [];
  24449. }
  24450. Audio.prototype = Object.assign( Object.create( Object3D.prototype ), {
  24451. constructor: Audio,
  24452. getOutput: function () {
  24453. return this.gain;
  24454. },
  24455. setNodeSource: function ( audioNode ) {
  24456. this.hasPlaybackControl = false;
  24457. this.sourceType = 'audioNode';
  24458. this.source = audioNode;
  24459. this.connect();
  24460. return this;
  24461. },
  24462. setMediaElementSource: function ( mediaElement ) {
  24463. this.hasPlaybackControl = false;
  24464. this.sourceType = 'mediaNode';
  24465. this.source = this.context.createMediaElementSource( mediaElement );
  24466. this.connect();
  24467. return this;
  24468. },
  24469. setBuffer: function ( audioBuffer ) {
  24470. this.buffer = audioBuffer;
  24471. this.sourceType = 'buffer';
  24472. if ( this.autoplay ) this.play();
  24473. return this;
  24474. },
  24475. play: function () {
  24476. if ( this.isPlaying === true ) {
  24477. console.warn( 'THREE.Audio: Audio is already playing.' );
  24478. return;
  24479. }
  24480. if ( this.hasPlaybackControl === false ) {
  24481. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  24482. return;
  24483. }
  24484. var source = this.context.createBufferSource();
  24485. source.buffer = this.buffer;
  24486. source.loop = this.loop;
  24487. source.onended = this.onEnded.bind( this );
  24488. this.startTime = this.context.currentTime;
  24489. source.start( this.startTime, this.offset );
  24490. this.isPlaying = true;
  24491. this.source = source;
  24492. this.setDetune( this.detune );
  24493. this.setPlaybackRate( this.playbackRate );
  24494. return this.connect();
  24495. },
  24496. pause: function () {
  24497. if ( this.hasPlaybackControl === false ) {
  24498. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  24499. return;
  24500. }
  24501. if ( this.isPlaying === true ) {
  24502. this.source.stop();
  24503. this.source.onended = null;
  24504. this.offset += ( this.context.currentTime - this.startTime ) * this.playbackRate;
  24505. this.isPlaying = false;
  24506. }
  24507. return this;
  24508. },
  24509. stop: function () {
  24510. if ( this.hasPlaybackControl === false ) {
  24511. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  24512. return;
  24513. }
  24514. this.source.stop();
  24515. this.source.onended = null;
  24516. this.offset = 0;
  24517. this.isPlaying = false;
  24518. return this;
  24519. },
  24520. connect: function () {
  24521. if ( this.filters.length > 0 ) {
  24522. this.source.connect( this.filters[ 0 ] );
  24523. for ( var i = 1, l = this.filters.length; i < l; i ++ ) {
  24524. this.filters[ i - 1 ].connect( this.filters[ i ] );
  24525. }
  24526. this.filters[ this.filters.length - 1 ].connect( this.getOutput() );
  24527. } else {
  24528. this.source.connect( this.getOutput() );
  24529. }
  24530. return this;
  24531. },
  24532. disconnect: function () {
  24533. if ( this.filters.length > 0 ) {
  24534. this.source.disconnect( this.filters[ 0 ] );
  24535. for ( var i = 1, l = this.filters.length; i < l; i ++ ) {
  24536. this.filters[ i - 1 ].disconnect( this.filters[ i ] );
  24537. }
  24538. this.filters[ this.filters.length - 1 ].disconnect( this.getOutput() );
  24539. } else {
  24540. this.source.disconnect( this.getOutput() );
  24541. }
  24542. return this;
  24543. },
  24544. getFilters: function () {
  24545. return this.filters;
  24546. },
  24547. setFilters: function ( value ) {
  24548. if ( ! value ) value = [];
  24549. if ( this.isPlaying === true ) {
  24550. this.disconnect();
  24551. this.filters = value;
  24552. this.connect();
  24553. } else {
  24554. this.filters = value;
  24555. }
  24556. return this;
  24557. },
  24558. setDetune: function ( value ) {
  24559. this.detune = value;
  24560. if ( this.source.detune === undefined ) return; // only set detune when available
  24561. if ( this.isPlaying === true ) {
  24562. this.source.detune.setTargetAtTime( this.detune, this.context.currentTime, 0.01 );
  24563. }
  24564. return this;
  24565. },
  24566. getDetune: function () {
  24567. return this.detune;
  24568. },
  24569. getFilter: function () {
  24570. return this.getFilters()[ 0 ];
  24571. },
  24572. setFilter: function ( filter ) {
  24573. return this.setFilters( filter ? [ filter ] : [] );
  24574. },
  24575. setPlaybackRate: function ( value ) {
  24576. if ( this.hasPlaybackControl === false ) {
  24577. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  24578. return;
  24579. }
  24580. this.playbackRate = value;
  24581. if ( this.isPlaying === true ) {
  24582. this.source.playbackRate.setTargetAtTime( this.playbackRate, this.context.currentTime, 0.01 );
  24583. }
  24584. return this;
  24585. },
  24586. getPlaybackRate: function () {
  24587. return this.playbackRate;
  24588. },
  24589. onEnded: function () {
  24590. this.isPlaying = false;
  24591. },
  24592. getLoop: function () {
  24593. if ( this.hasPlaybackControl === false ) {
  24594. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  24595. return false;
  24596. }
  24597. return this.loop;
  24598. },
  24599. setLoop: function ( value ) {
  24600. if ( this.hasPlaybackControl === false ) {
  24601. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  24602. return;
  24603. }
  24604. this.loop = value;
  24605. if ( this.isPlaying === true ) {
  24606. this.source.loop = this.loop;
  24607. }
  24608. return this;
  24609. },
  24610. getVolume: function () {
  24611. return this.gain.gain.value;
  24612. },
  24613. setVolume: function ( value ) {
  24614. this.gain.gain.setTargetAtTime( value, this.context.currentTime, 0.01 );
  24615. return this;
  24616. }
  24617. } );
  24618. /**
  24619. * @author mrdoob / http://mrdoob.com/
  24620. */
  24621. function PositionalAudio( listener ) {
  24622. Audio.call( this, listener );
  24623. this.panner = this.context.createPanner();
  24624. this.panner.connect( this.gain );
  24625. }
  24626. PositionalAudio.prototype = Object.assign( Object.create( Audio.prototype ), {
  24627. constructor: PositionalAudio,
  24628. getOutput: function () {
  24629. return this.panner;
  24630. },
  24631. getRefDistance: function () {
  24632. return this.panner.refDistance;
  24633. },
  24634. setRefDistance: function ( value ) {
  24635. this.panner.refDistance = value;
  24636. return this;
  24637. },
  24638. getRolloffFactor: function () {
  24639. return this.panner.rolloffFactor;
  24640. },
  24641. setRolloffFactor: function ( value ) {
  24642. this.panner.rolloffFactor = value;
  24643. return this;
  24644. },
  24645. getDistanceModel: function () {
  24646. return this.panner.distanceModel;
  24647. },
  24648. setDistanceModel: function ( value ) {
  24649. this.panner.distanceModel = value;
  24650. return this;
  24651. },
  24652. getMaxDistance: function () {
  24653. return this.panner.maxDistance;
  24654. },
  24655. setMaxDistance: function ( value ) {
  24656. this.panner.maxDistance = value;
  24657. return this;
  24658. },
  24659. setDirectionalCone: function ( coneInnerAngle, coneOuterAngle, coneOuterGain ) {
  24660. this.panner.coneInnerAngle = coneInnerAngle;
  24661. this.panner.coneOuterAngle = coneOuterAngle;
  24662. this.panner.coneOuterGain = coneOuterGain;
  24663. return this;
  24664. },
  24665. updateMatrixWorld: ( function () {
  24666. var position = new Vector3();
  24667. var quaternion = new Quaternion();
  24668. var scale = new Vector3();
  24669. var orientation = new Vector3();
  24670. return function updateMatrixWorld( force ) {
  24671. Object3D.prototype.updateMatrixWorld.call( this, force );
  24672. if ( this.hasPlaybackControl === true && this.isPlaying === false ) return;
  24673. this.matrixWorld.decompose( position, quaternion, scale );
  24674. orientation.set( 0, 0, 1 ).applyQuaternion( quaternion );
  24675. var panner = this.panner;
  24676. if ( panner.positionX ) {
  24677. // code path for Chrome and Firefox (see #14393)
  24678. var endTime = this.context.currentTime + this.listener.timeDelta;
  24679. panner.positionX.linearRampToValueAtTime( position.x, endTime );
  24680. panner.positionY.linearRampToValueAtTime( position.y, endTime );
  24681. panner.positionZ.linearRampToValueAtTime( position.z, endTime );
  24682. panner.orientationX.linearRampToValueAtTime( orientation.x, endTime );
  24683. panner.orientationY.linearRampToValueAtTime( orientation.y, endTime );
  24684. panner.orientationZ.linearRampToValueAtTime( orientation.z, endTime );
  24685. } else {
  24686. panner.setPosition( position.x, position.y, position.z );
  24687. panner.setOrientation( orientation.x, orientation.y, orientation.z );
  24688. }
  24689. };
  24690. } )()
  24691. } );
  24692. /**
  24693. * @author mrdoob / http://mrdoob.com/
  24694. */
  24695. function AudioAnalyser( audio, fftSize ) {
  24696. this.analyser = audio.context.createAnalyser();
  24697. this.analyser.fftSize = fftSize !== undefined ? fftSize : 2048;
  24698. this.data = new Uint8Array( this.analyser.frequencyBinCount );
  24699. audio.getOutput().connect( this.analyser );
  24700. }
  24701. Object.assign( AudioAnalyser.prototype, {
  24702. getFrequencyData: function () {
  24703. this.analyser.getByteFrequencyData( this.data );
  24704. return this.data;
  24705. },
  24706. getAverageFrequency: function () {
  24707. var value = 0, data = this.getFrequencyData();
  24708. for ( var i = 0; i < data.length; i ++ ) {
  24709. value += data[ i ];
  24710. }
  24711. return value / data.length;
  24712. }
  24713. } );
  24714. /**
  24715. *
  24716. * Buffered scene graph property that allows weighted accumulation.
  24717. *
  24718. *
  24719. * @author Ben Houston / http://clara.io/
  24720. * @author David Sarno / http://lighthaus.us/
  24721. * @author tschw
  24722. */
  24723. function PropertyMixer( binding, typeName, valueSize ) {
  24724. this.binding = binding;
  24725. this.valueSize = valueSize;
  24726. var bufferType = Float64Array,
  24727. mixFunction;
  24728. switch ( typeName ) {
  24729. case 'quaternion':
  24730. mixFunction = this._slerp;
  24731. break;
  24732. case 'string':
  24733. case 'bool':
  24734. bufferType = Array;
  24735. mixFunction = this._select;
  24736. break;
  24737. default:
  24738. mixFunction = this._lerp;
  24739. }
  24740. this.buffer = new bufferType( valueSize * 4 );
  24741. // layout: [ incoming | accu0 | accu1 | orig ]
  24742. //
  24743. // interpolators can use .buffer as their .result
  24744. // the data then goes to 'incoming'
  24745. //
  24746. // 'accu0' and 'accu1' are used frame-interleaved for
  24747. // the cumulative result and are compared to detect
  24748. // changes
  24749. //
  24750. // 'orig' stores the original state of the property
  24751. this._mixBufferRegion = mixFunction;
  24752. this.cumulativeWeight = 0;
  24753. this.useCount = 0;
  24754. this.referenceCount = 0;
  24755. }
  24756. Object.assign( PropertyMixer.prototype, {
  24757. // accumulate data in the 'incoming' region into 'accu<i>'
  24758. accumulate: function ( accuIndex, weight ) {
  24759. // note: happily accumulating nothing when weight = 0, the caller knows
  24760. // the weight and shouldn't have made the call in the first place
  24761. var buffer = this.buffer,
  24762. stride = this.valueSize,
  24763. offset = accuIndex * stride + stride,
  24764. currentWeight = this.cumulativeWeight;
  24765. if ( currentWeight === 0 ) {
  24766. // accuN := incoming * weight
  24767. for ( var i = 0; i !== stride; ++ i ) {
  24768. buffer[ offset + i ] = buffer[ i ];
  24769. }
  24770. currentWeight = weight;
  24771. } else {
  24772. // accuN := accuN + incoming * weight
  24773. currentWeight += weight;
  24774. var mix = weight / currentWeight;
  24775. this._mixBufferRegion( buffer, offset, 0, mix, stride );
  24776. }
  24777. this.cumulativeWeight = currentWeight;
  24778. },
  24779. // apply the state of 'accu<i>' to the binding when accus differ
  24780. apply: function ( accuIndex ) {
  24781. var stride = this.valueSize,
  24782. buffer = this.buffer,
  24783. offset = accuIndex * stride + stride,
  24784. weight = this.cumulativeWeight,
  24785. binding = this.binding;
  24786. this.cumulativeWeight = 0;
  24787. if ( weight < 1 ) {
  24788. // accuN := accuN + original * ( 1 - cumulativeWeight )
  24789. var originalValueOffset = stride * 3;
  24790. this._mixBufferRegion(
  24791. buffer, offset, originalValueOffset, 1 - weight, stride );
  24792. }
  24793. for ( var i = stride, e = stride + stride; i !== e; ++ i ) {
  24794. if ( buffer[ i ] !== buffer[ i + stride ] ) {
  24795. // value has changed -> update scene graph
  24796. binding.setValue( buffer, offset );
  24797. break;
  24798. }
  24799. }
  24800. },
  24801. // remember the state of the bound property and copy it to both accus
  24802. saveOriginalState: function () {
  24803. var binding = this.binding;
  24804. var buffer = this.buffer,
  24805. stride = this.valueSize,
  24806. originalValueOffset = stride * 3;
  24807. binding.getValue( buffer, originalValueOffset );
  24808. // accu[0..1] := orig -- initially detect changes against the original
  24809. for ( var i = stride, e = originalValueOffset; i !== e; ++ i ) {
  24810. buffer[ i ] = buffer[ originalValueOffset + ( i % stride ) ];
  24811. }
  24812. this.cumulativeWeight = 0;
  24813. },
  24814. // apply the state previously taken via 'saveOriginalState' to the binding
  24815. restoreOriginalState: function () {
  24816. var originalValueOffset = this.valueSize * 3;
  24817. this.binding.setValue( this.buffer, originalValueOffset );
  24818. },
  24819. // mix functions
  24820. _select: function ( buffer, dstOffset, srcOffset, t, stride ) {
  24821. if ( t >= 0.5 ) {
  24822. for ( var i = 0; i !== stride; ++ i ) {
  24823. buffer[ dstOffset + i ] = buffer[ srcOffset + i ];
  24824. }
  24825. }
  24826. },
  24827. _slerp: function ( buffer, dstOffset, srcOffset, t ) {
  24828. Quaternion.slerpFlat( buffer, dstOffset, buffer, dstOffset, buffer, srcOffset, t );
  24829. },
  24830. _lerp: function ( buffer, dstOffset, srcOffset, t, stride ) {
  24831. var s = 1 - t;
  24832. for ( var i = 0; i !== stride; ++ i ) {
  24833. var j = dstOffset + i;
  24834. buffer[ j ] = buffer[ j ] * s + buffer[ srcOffset + i ] * t;
  24835. }
  24836. }
  24837. } );
  24838. /**
  24839. *
  24840. * A reference to a real property in the scene graph.
  24841. *
  24842. *
  24843. * @author Ben Houston / http://clara.io/
  24844. * @author David Sarno / http://lighthaus.us/
  24845. * @author tschw
  24846. */
  24847. // Characters [].:/ are reserved for track binding syntax.
  24848. var RESERVED_CHARS_RE = '\\[\\]\\.:\\/';
  24849. function Composite( targetGroup, path, optionalParsedPath ) {
  24850. var parsedPath = optionalParsedPath || PropertyBinding.parseTrackName( path );
  24851. this._targetGroup = targetGroup;
  24852. this._bindings = targetGroup.subscribe_( path, parsedPath );
  24853. }
  24854. Object.assign( Composite.prototype, {
  24855. getValue: function ( array, offset ) {
  24856. this.bind(); // bind all binding
  24857. var firstValidIndex = this._targetGroup.nCachedObjects_,
  24858. binding = this._bindings[ firstValidIndex ];
  24859. // and only call .getValue on the first
  24860. if ( binding !== undefined ) binding.getValue( array, offset );
  24861. },
  24862. setValue: function ( array, offset ) {
  24863. var bindings = this._bindings;
  24864. for ( var i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++ i ) {
  24865. bindings[ i ].setValue( array, offset );
  24866. }
  24867. },
  24868. bind: function () {
  24869. var bindings = this._bindings;
  24870. for ( var i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++ i ) {
  24871. bindings[ i ].bind();
  24872. }
  24873. },
  24874. unbind: function () {
  24875. var bindings = this._bindings;
  24876. for ( var i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++ i ) {
  24877. bindings[ i ].unbind();
  24878. }
  24879. }
  24880. } );
  24881. function PropertyBinding( rootNode, path, parsedPath ) {
  24882. this.path = path;
  24883. this.parsedPath = parsedPath || PropertyBinding.parseTrackName( path );
  24884. this.node = PropertyBinding.findNode( rootNode, this.parsedPath.nodeName ) || rootNode;
  24885. this.rootNode = rootNode;
  24886. }
  24887. Object.assign( PropertyBinding, {
  24888. Composite: Composite,
  24889. create: function ( root, path, parsedPath ) {
  24890. if ( ! ( root && root.isAnimationObjectGroup ) ) {
  24891. return new PropertyBinding( root, path, parsedPath );
  24892. } else {
  24893. return new PropertyBinding.Composite( root, path, parsedPath );
  24894. }
  24895. },
  24896. /**
  24897. * Replaces spaces with underscores and removes unsupported characters from
  24898. * node names, to ensure compatibility with parseTrackName().
  24899. *
  24900. * @param {string} name Node name to be sanitized.
  24901. * @return {string}
  24902. */
  24903. sanitizeNodeName: ( function () {
  24904. var reservedRe = new RegExp( '[' + RESERVED_CHARS_RE + ']', 'g' );
  24905. return function sanitizeNodeName( name ) {
  24906. return name.replace( /\s/g, '_' ).replace( reservedRe, '' );
  24907. };
  24908. }() ),
  24909. parseTrackName: function () {
  24910. // Attempts to allow node names from any language. ES5's `\w` regexp matches
  24911. // only latin characters, and the unicode \p{L} is not yet supported. So
  24912. // instead, we exclude reserved characters and match everything else.
  24913. var wordChar = '[^' + RESERVED_CHARS_RE + ']';
  24914. var wordCharOrDot = '[^' + RESERVED_CHARS_RE.replace( '\\.', '' ) + ']';
  24915. // Parent directories, delimited by '/' or ':'. Currently unused, but must
  24916. // be matched to parse the rest of the track name.
  24917. var directoryRe = /((?:WC+[\/:])*)/.source.replace( 'WC', wordChar );
  24918. // Target node. May contain word characters (a-zA-Z0-9_) and '.' or '-'.
  24919. var nodeRe = /(WCOD+)?/.source.replace( 'WCOD', wordCharOrDot );
  24920. // Object on target node, and accessor. May not contain reserved
  24921. // characters. Accessor may contain any character except closing bracket.
  24922. var objectRe = /(?:\.(WC+)(?:\[(.+)\])?)?/.source.replace( 'WC', wordChar );
  24923. // Property and accessor. May not contain reserved characters. Accessor may
  24924. // contain any non-bracket characters.
  24925. var propertyRe = /\.(WC+)(?:\[(.+)\])?/.source.replace( 'WC', wordChar );
  24926. var trackRe = new RegExp( ''
  24927. + '^'
  24928. + directoryRe
  24929. + nodeRe
  24930. + objectRe
  24931. + propertyRe
  24932. + '$'
  24933. );
  24934. var supportedObjectNames = [ 'material', 'materials', 'bones' ];
  24935. return function parseTrackName( trackName ) {
  24936. var matches = trackRe.exec( trackName );
  24937. if ( ! matches ) {
  24938. throw new Error( 'PropertyBinding: Cannot parse trackName: ' + trackName );
  24939. }
  24940. var results = {
  24941. // directoryName: matches[ 1 ], // (tschw) currently unused
  24942. nodeName: matches[ 2 ],
  24943. objectName: matches[ 3 ],
  24944. objectIndex: matches[ 4 ],
  24945. propertyName: matches[ 5 ], // required
  24946. propertyIndex: matches[ 6 ]
  24947. };
  24948. var lastDot = results.nodeName && results.nodeName.lastIndexOf( '.' );
  24949. if ( lastDot !== undefined && lastDot !== - 1 ) {
  24950. var objectName = results.nodeName.substring( lastDot + 1 );
  24951. // Object names must be checked against a whitelist. Otherwise, there
  24952. // is no way to parse 'foo.bar.baz': 'baz' must be a property, but
  24953. // 'bar' could be the objectName, or part of a nodeName (which can
  24954. // include '.' characters).
  24955. if ( supportedObjectNames.indexOf( objectName ) !== - 1 ) {
  24956. results.nodeName = results.nodeName.substring( 0, lastDot );
  24957. results.objectName = objectName;
  24958. }
  24959. }
  24960. if ( results.propertyName === null || results.propertyName.length === 0 ) {
  24961. throw new Error( 'PropertyBinding: can not parse propertyName from trackName: ' + trackName );
  24962. }
  24963. return results;
  24964. };
  24965. }(),
  24966. findNode: function ( root, nodeName ) {
  24967. if ( ! nodeName || nodeName === "" || nodeName === "root" || nodeName === "." || nodeName === - 1 || nodeName === root.name || nodeName === root.uuid ) {
  24968. return root;
  24969. }
  24970. // search into skeleton bones.
  24971. if ( root.skeleton ) {
  24972. var bone = root.skeleton.getBoneByName( nodeName );
  24973. if ( bone !== undefined ) {
  24974. return bone;
  24975. }
  24976. }
  24977. // search into node subtree.
  24978. if ( root.children ) {
  24979. var searchNodeSubtree = function ( children ) {
  24980. for ( var i = 0; i < children.length; i ++ ) {
  24981. var childNode = children[ i ];
  24982. if ( childNode.name === nodeName || childNode.uuid === nodeName ) {
  24983. return childNode;
  24984. }
  24985. var result = searchNodeSubtree( childNode.children );
  24986. if ( result ) return result;
  24987. }
  24988. return null;
  24989. };
  24990. var subTreeNode = searchNodeSubtree( root.children );
  24991. if ( subTreeNode ) {
  24992. return subTreeNode;
  24993. }
  24994. }
  24995. return null;
  24996. }
  24997. } );
  24998. Object.assign( PropertyBinding.prototype, { // prototype, continued
  24999. // these are used to "bind" a nonexistent property
  25000. _getValue_unavailable: function () {},
  25001. _setValue_unavailable: function () {},
  25002. BindingType: {
  25003. Direct: 0,
  25004. EntireArray: 1,
  25005. ArrayElement: 2,
  25006. HasFromToArray: 3
  25007. },
  25008. Versioning: {
  25009. None: 0,
  25010. NeedsUpdate: 1,
  25011. MatrixWorldNeedsUpdate: 2
  25012. },
  25013. GetterByBindingType: [
  25014. function getValue_direct( buffer, offset ) {
  25015. buffer[ offset ] = this.node[ this.propertyName ];
  25016. },
  25017. function getValue_array( buffer, offset ) {
  25018. var source = this.resolvedProperty;
  25019. for ( var i = 0, n = source.length; i !== n; ++ i ) {
  25020. buffer[ offset ++ ] = source[ i ];
  25021. }
  25022. },
  25023. function getValue_arrayElement( buffer, offset ) {
  25024. buffer[ offset ] = this.resolvedProperty[ this.propertyIndex ];
  25025. },
  25026. function getValue_toArray( buffer, offset ) {
  25027. this.resolvedProperty.toArray( buffer, offset );
  25028. }
  25029. ],
  25030. SetterByBindingTypeAndVersioning: [
  25031. [
  25032. // Direct
  25033. function setValue_direct( buffer, offset ) {
  25034. this.targetObject[ this.propertyName ] = buffer[ offset ];
  25035. },
  25036. function setValue_direct_setNeedsUpdate( buffer, offset ) {
  25037. this.targetObject[ this.propertyName ] = buffer[ offset ];
  25038. this.targetObject.needsUpdate = true;
  25039. },
  25040. function setValue_direct_setMatrixWorldNeedsUpdate( buffer, offset ) {
  25041. this.targetObject[ this.propertyName ] = buffer[ offset ];
  25042. this.targetObject.matrixWorldNeedsUpdate = true;
  25043. }
  25044. ], [
  25045. // EntireArray
  25046. function setValue_array( buffer, offset ) {
  25047. var dest = this.resolvedProperty;
  25048. for ( var i = 0, n = dest.length; i !== n; ++ i ) {
  25049. dest[ i ] = buffer[ offset ++ ];
  25050. }
  25051. },
  25052. function setValue_array_setNeedsUpdate( buffer, offset ) {
  25053. var dest = this.resolvedProperty;
  25054. for ( var i = 0, n = dest.length; i !== n; ++ i ) {
  25055. dest[ i ] = buffer[ offset ++ ];
  25056. }
  25057. this.targetObject.needsUpdate = true;
  25058. },
  25059. function setValue_array_setMatrixWorldNeedsUpdate( buffer, offset ) {
  25060. var dest = this.resolvedProperty;
  25061. for ( var i = 0, n = dest.length; i !== n; ++ i ) {
  25062. dest[ i ] = buffer[ offset ++ ];
  25063. }
  25064. this.targetObject.matrixWorldNeedsUpdate = true;
  25065. }
  25066. ], [
  25067. // ArrayElement
  25068. function setValue_arrayElement( buffer, offset ) {
  25069. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  25070. },
  25071. function setValue_arrayElement_setNeedsUpdate( buffer, offset ) {
  25072. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  25073. this.targetObject.needsUpdate = true;
  25074. },
  25075. function setValue_arrayElement_setMatrixWorldNeedsUpdate( buffer, offset ) {
  25076. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  25077. this.targetObject.matrixWorldNeedsUpdate = true;
  25078. }
  25079. ], [
  25080. // HasToFromArray
  25081. function setValue_fromArray( buffer, offset ) {
  25082. this.resolvedProperty.fromArray( buffer, offset );
  25083. },
  25084. function setValue_fromArray_setNeedsUpdate( buffer, offset ) {
  25085. this.resolvedProperty.fromArray( buffer, offset );
  25086. this.targetObject.needsUpdate = true;
  25087. },
  25088. function setValue_fromArray_setMatrixWorldNeedsUpdate( buffer, offset ) {
  25089. this.resolvedProperty.fromArray( buffer, offset );
  25090. this.targetObject.matrixWorldNeedsUpdate = true;
  25091. }
  25092. ]
  25093. ],
  25094. getValue: function getValue_unbound( targetArray, offset ) {
  25095. this.bind();
  25096. this.getValue( targetArray, offset );
  25097. // Note: This class uses a State pattern on a per-method basis:
  25098. // 'bind' sets 'this.getValue' / 'setValue' and shadows the
  25099. // prototype version of these methods with one that represents
  25100. // the bound state. When the property is not found, the methods
  25101. // become no-ops.
  25102. },
  25103. setValue: function getValue_unbound( sourceArray, offset ) {
  25104. this.bind();
  25105. this.setValue( sourceArray, offset );
  25106. },
  25107. // create getter / setter pair for a property in the scene graph
  25108. bind: function () {
  25109. var targetObject = this.node,
  25110. parsedPath = this.parsedPath,
  25111. objectName = parsedPath.objectName,
  25112. propertyName = parsedPath.propertyName,
  25113. propertyIndex = parsedPath.propertyIndex;
  25114. if ( ! targetObject ) {
  25115. targetObject = PropertyBinding.findNode( this.rootNode, parsedPath.nodeName ) || this.rootNode;
  25116. this.node = targetObject;
  25117. }
  25118. // set fail state so we can just 'return' on error
  25119. this.getValue = this._getValue_unavailable;
  25120. this.setValue = this._setValue_unavailable;
  25121. // ensure there is a value node
  25122. if ( ! targetObject ) {
  25123. console.error( 'THREE.PropertyBinding: Trying to update node for track: ' + this.path + ' but it wasn\'t found.' );
  25124. return;
  25125. }
  25126. if ( objectName ) {
  25127. var objectIndex = parsedPath.objectIndex;
  25128. // special cases were we need to reach deeper into the hierarchy to get the face materials....
  25129. switch ( objectName ) {
  25130. case 'materials':
  25131. if ( ! targetObject.material ) {
  25132. console.error( 'THREE.PropertyBinding: Can not bind to material as node does not have a material.', this );
  25133. return;
  25134. }
  25135. if ( ! targetObject.material.materials ) {
  25136. console.error( 'THREE.PropertyBinding: Can not bind to material.materials as node.material does not have a materials array.', this );
  25137. return;
  25138. }
  25139. targetObject = targetObject.material.materials;
  25140. break;
  25141. case 'bones':
  25142. if ( ! targetObject.skeleton ) {
  25143. console.error( 'THREE.PropertyBinding: Can not bind to bones as node does not have a skeleton.', this );
  25144. return;
  25145. }
  25146. // potential future optimization: skip this if propertyIndex is already an integer
  25147. // and convert the integer string to a true integer.
  25148. targetObject = targetObject.skeleton.bones;
  25149. // support resolving morphTarget names into indices.
  25150. for ( var i = 0; i < targetObject.length; i ++ ) {
  25151. if ( targetObject[ i ].name === objectIndex ) {
  25152. objectIndex = i;
  25153. break;
  25154. }
  25155. }
  25156. break;
  25157. default:
  25158. if ( targetObject[ objectName ] === undefined ) {
  25159. console.error( 'THREE.PropertyBinding: Can not bind to objectName of node undefined.', this );
  25160. return;
  25161. }
  25162. targetObject = targetObject[ objectName ];
  25163. }
  25164. if ( objectIndex !== undefined ) {
  25165. if ( targetObject[ objectIndex ] === undefined ) {
  25166. console.error( 'THREE.PropertyBinding: Trying to bind to objectIndex of objectName, but is undefined.', this, targetObject );
  25167. return;
  25168. }
  25169. targetObject = targetObject[ objectIndex ];
  25170. }
  25171. }
  25172. // resolve property
  25173. var nodeProperty = targetObject[ propertyName ];
  25174. if ( nodeProperty === undefined ) {
  25175. var nodeName = parsedPath.nodeName;
  25176. console.error( 'THREE.PropertyBinding: Trying to update property for track: ' + nodeName +
  25177. '.' + propertyName + ' but it wasn\'t found.', targetObject );
  25178. return;
  25179. }
  25180. // determine versioning scheme
  25181. var versioning = this.Versioning.None;
  25182. this.targetObject = targetObject;
  25183. if ( targetObject.needsUpdate !== undefined ) { // material
  25184. versioning = this.Versioning.NeedsUpdate;
  25185. } else if ( targetObject.matrixWorldNeedsUpdate !== undefined ) { // node transform
  25186. versioning = this.Versioning.MatrixWorldNeedsUpdate;
  25187. }
  25188. // determine how the property gets bound
  25189. var bindingType = this.BindingType.Direct;
  25190. if ( propertyIndex !== undefined ) {
  25191. // access a sub element of the property array (only primitives are supported right now)
  25192. if ( propertyName === "morphTargetInfluences" ) {
  25193. // potential optimization, skip this if propertyIndex is already an integer, and convert the integer string to a true integer.
  25194. // support resolving morphTarget names into indices.
  25195. if ( ! targetObject.geometry ) {
  25196. console.error( 'THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.', this );
  25197. return;
  25198. }
  25199. if ( targetObject.geometry.isBufferGeometry ) {
  25200. if ( ! targetObject.geometry.morphAttributes ) {
  25201. console.error( 'THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.morphAttributes.', this );
  25202. return;
  25203. }
  25204. for ( var i = 0; i < this.node.geometry.morphAttributes.position.length; i ++ ) {
  25205. if ( targetObject.geometry.morphAttributes.position[ i ].name === propertyIndex ) {
  25206. propertyIndex = i;
  25207. break;
  25208. }
  25209. }
  25210. } else {
  25211. if ( ! targetObject.geometry.morphTargets ) {
  25212. console.error( 'THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.morphTargets.', this );
  25213. return;
  25214. }
  25215. for ( var i = 0; i < this.node.geometry.morphTargets.length; i ++ ) {
  25216. if ( targetObject.geometry.morphTargets[ i ].name === propertyIndex ) {
  25217. propertyIndex = i;
  25218. break;
  25219. }
  25220. }
  25221. }
  25222. }
  25223. bindingType = this.BindingType.ArrayElement;
  25224. this.resolvedProperty = nodeProperty;
  25225. this.propertyIndex = propertyIndex;
  25226. } else if ( nodeProperty.fromArray !== undefined && nodeProperty.toArray !== undefined ) {
  25227. // must use copy for Object3D.Euler/Quaternion
  25228. bindingType = this.BindingType.HasFromToArray;
  25229. this.resolvedProperty = nodeProperty;
  25230. } else if ( Array.isArray( nodeProperty ) ) {
  25231. bindingType = this.BindingType.EntireArray;
  25232. this.resolvedProperty = nodeProperty;
  25233. } else {
  25234. this.propertyName = propertyName;
  25235. }
  25236. // select getter / setter
  25237. this.getValue = this.GetterByBindingType[ bindingType ];
  25238. this.setValue = this.SetterByBindingTypeAndVersioning[ bindingType ][ versioning ];
  25239. },
  25240. unbind: function () {
  25241. this.node = null;
  25242. // back to the prototype version of getValue / setValue
  25243. // note: avoiding to mutate the shape of 'this' via 'delete'
  25244. this.getValue = this._getValue_unbound;
  25245. this.setValue = this._setValue_unbound;
  25246. }
  25247. } );
  25248. //!\ DECLARE ALIAS AFTER assign prototype !
  25249. Object.assign( PropertyBinding.prototype, {
  25250. // initial state of these methods that calls 'bind'
  25251. _getValue_unbound: PropertyBinding.prototype.getValue,
  25252. _setValue_unbound: PropertyBinding.prototype.setValue,
  25253. } );
  25254. /**
  25255. *
  25256. * A group of objects that receives a shared animation state.
  25257. *
  25258. * Usage:
  25259. *
  25260. * - Add objects you would otherwise pass as 'root' to the
  25261. * constructor or the .clipAction method of AnimationMixer.
  25262. *
  25263. * - Instead pass this object as 'root'.
  25264. *
  25265. * - You can also add and remove objects later when the mixer
  25266. * is running.
  25267. *
  25268. * Note:
  25269. *
  25270. * Objects of this class appear as one object to the mixer,
  25271. * so cache control of the individual objects must be done
  25272. * on the group.
  25273. *
  25274. * Limitation:
  25275. *
  25276. * - The animated properties must be compatible among the
  25277. * all objects in the group.
  25278. *
  25279. * - A single property can either be controlled through a
  25280. * target group or directly, but not both.
  25281. *
  25282. * @author tschw
  25283. */
  25284. function AnimationObjectGroup() {
  25285. this.uuid = _Math.generateUUID();
  25286. // cached objects followed by the active ones
  25287. this._objects = Array.prototype.slice.call( arguments );
  25288. this.nCachedObjects_ = 0; // threshold
  25289. // note: read by PropertyBinding.Composite
  25290. var indices = {};
  25291. this._indicesByUUID = indices; // for bookkeeping
  25292. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  25293. indices[ arguments[ i ].uuid ] = i;
  25294. }
  25295. this._paths = []; // inside: string
  25296. this._parsedPaths = []; // inside: { we don't care, here }
  25297. this._bindings = []; // inside: Array< PropertyBinding >
  25298. this._bindingsIndicesByPath = {}; // inside: indices in these arrays
  25299. var scope = this;
  25300. this.stats = {
  25301. objects: {
  25302. get total() {
  25303. return scope._objects.length;
  25304. },
  25305. get inUse() {
  25306. return this.total - scope.nCachedObjects_;
  25307. }
  25308. },
  25309. get bindingsPerObject() {
  25310. return scope._bindings.length;
  25311. }
  25312. };
  25313. }
  25314. Object.assign( AnimationObjectGroup.prototype, {
  25315. isAnimationObjectGroup: true,
  25316. add: function () {
  25317. var objects = this._objects,
  25318. nObjects = objects.length,
  25319. nCachedObjects = this.nCachedObjects_,
  25320. indicesByUUID = this._indicesByUUID,
  25321. paths = this._paths,
  25322. parsedPaths = this._parsedPaths,
  25323. bindings = this._bindings,
  25324. nBindings = bindings.length,
  25325. knownObject = undefined;
  25326. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  25327. var object = arguments[ i ],
  25328. uuid = object.uuid,
  25329. index = indicesByUUID[ uuid ];
  25330. if ( index === undefined ) {
  25331. // unknown object -> add it to the ACTIVE region
  25332. index = nObjects ++;
  25333. indicesByUUID[ uuid ] = index;
  25334. objects.push( object );
  25335. // accounting is done, now do the same for all bindings
  25336. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  25337. bindings[ j ].push( new PropertyBinding( object, paths[ j ], parsedPaths[ j ] ) );
  25338. }
  25339. } else if ( index < nCachedObjects ) {
  25340. knownObject = objects[ index ];
  25341. // move existing object to the ACTIVE region
  25342. var firstActiveIndex = -- nCachedObjects,
  25343. lastCachedObject = objects[ firstActiveIndex ];
  25344. indicesByUUID[ lastCachedObject.uuid ] = index;
  25345. objects[ index ] = lastCachedObject;
  25346. indicesByUUID[ uuid ] = firstActiveIndex;
  25347. objects[ firstActiveIndex ] = object;
  25348. // accounting is done, now do the same for all bindings
  25349. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  25350. var bindingsForPath = bindings[ j ],
  25351. lastCached = bindingsForPath[ firstActiveIndex ],
  25352. binding = bindingsForPath[ index ];
  25353. bindingsForPath[ index ] = lastCached;
  25354. if ( binding === undefined ) {
  25355. // since we do not bother to create new bindings
  25356. // for objects that are cached, the binding may
  25357. // or may not exist
  25358. binding = new PropertyBinding( object, paths[ j ], parsedPaths[ j ] );
  25359. }
  25360. bindingsForPath[ firstActiveIndex ] = binding;
  25361. }
  25362. } else if ( objects[ index ] !== knownObject ) {
  25363. console.error( 'THREE.AnimationObjectGroup: Different objects with the same UUID ' +
  25364. 'detected. Clean the caches or recreate your infrastructure when reloading scenes.' );
  25365. } // else the object is already where we want it to be
  25366. } // for arguments
  25367. this.nCachedObjects_ = nCachedObjects;
  25368. },
  25369. remove: function () {
  25370. var objects = this._objects,
  25371. nCachedObjects = this.nCachedObjects_,
  25372. indicesByUUID = this._indicesByUUID,
  25373. bindings = this._bindings,
  25374. nBindings = bindings.length;
  25375. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  25376. var object = arguments[ i ],
  25377. uuid = object.uuid,
  25378. index = indicesByUUID[ uuid ];
  25379. if ( index !== undefined && index >= nCachedObjects ) {
  25380. // move existing object into the CACHED region
  25381. var lastCachedIndex = nCachedObjects ++,
  25382. firstActiveObject = objects[ lastCachedIndex ];
  25383. indicesByUUID[ firstActiveObject.uuid ] = index;
  25384. objects[ index ] = firstActiveObject;
  25385. indicesByUUID[ uuid ] = lastCachedIndex;
  25386. objects[ lastCachedIndex ] = object;
  25387. // accounting is done, now do the same for all bindings
  25388. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  25389. var bindingsForPath = bindings[ j ],
  25390. firstActive = bindingsForPath[ lastCachedIndex ],
  25391. binding = bindingsForPath[ index ];
  25392. bindingsForPath[ index ] = firstActive;
  25393. bindingsForPath[ lastCachedIndex ] = binding;
  25394. }
  25395. }
  25396. } // for arguments
  25397. this.nCachedObjects_ = nCachedObjects;
  25398. },
  25399. // remove & forget
  25400. uncache: function () {
  25401. var objects = this._objects,
  25402. nObjects = objects.length,
  25403. nCachedObjects = this.nCachedObjects_,
  25404. indicesByUUID = this._indicesByUUID,
  25405. bindings = this._bindings,
  25406. nBindings = bindings.length;
  25407. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  25408. var object = arguments[ i ],
  25409. uuid = object.uuid,
  25410. index = indicesByUUID[ uuid ];
  25411. if ( index !== undefined ) {
  25412. delete indicesByUUID[ uuid ];
  25413. if ( index < nCachedObjects ) {
  25414. // object is cached, shrink the CACHED region
  25415. var firstActiveIndex = -- nCachedObjects,
  25416. lastCachedObject = objects[ firstActiveIndex ],
  25417. lastIndex = -- nObjects,
  25418. lastObject = objects[ lastIndex ];
  25419. // last cached object takes this object's place
  25420. indicesByUUID[ lastCachedObject.uuid ] = index;
  25421. objects[ index ] = lastCachedObject;
  25422. // last object goes to the activated slot and pop
  25423. indicesByUUID[ lastObject.uuid ] = firstActiveIndex;
  25424. objects[ firstActiveIndex ] = lastObject;
  25425. objects.pop();
  25426. // accounting is done, now do the same for all bindings
  25427. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  25428. var bindingsForPath = bindings[ j ],
  25429. lastCached = bindingsForPath[ firstActiveIndex ],
  25430. last = bindingsForPath[ lastIndex ];
  25431. bindingsForPath[ index ] = lastCached;
  25432. bindingsForPath[ firstActiveIndex ] = last;
  25433. bindingsForPath.pop();
  25434. }
  25435. } else {
  25436. // object is active, just swap with the last and pop
  25437. var lastIndex = -- nObjects,
  25438. lastObject = objects[ lastIndex ];
  25439. indicesByUUID[ lastObject.uuid ] = index;
  25440. objects[ index ] = lastObject;
  25441. objects.pop();
  25442. // accounting is done, now do the same for all bindings
  25443. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  25444. var bindingsForPath = bindings[ j ];
  25445. bindingsForPath[ index ] = bindingsForPath[ lastIndex ];
  25446. bindingsForPath.pop();
  25447. }
  25448. } // cached or active
  25449. } // if object is known
  25450. } // for arguments
  25451. this.nCachedObjects_ = nCachedObjects;
  25452. },
  25453. // Internal interface used by befriended PropertyBinding.Composite:
  25454. subscribe_: function ( path, parsedPath ) {
  25455. // returns an array of bindings for the given path that is changed
  25456. // according to the contained objects in the group
  25457. var indicesByPath = this._bindingsIndicesByPath,
  25458. index = indicesByPath[ path ],
  25459. bindings = this._bindings;
  25460. if ( index !== undefined ) return bindings[ index ];
  25461. var paths = this._paths,
  25462. parsedPaths = this._parsedPaths,
  25463. objects = this._objects,
  25464. nObjects = objects.length,
  25465. nCachedObjects = this.nCachedObjects_,
  25466. bindingsForPath = new Array( nObjects );
  25467. index = bindings.length;
  25468. indicesByPath[ path ] = index;
  25469. paths.push( path );
  25470. parsedPaths.push( parsedPath );
  25471. bindings.push( bindingsForPath );
  25472. for ( var i = nCachedObjects, n = objects.length; i !== n; ++ i ) {
  25473. var object = objects[ i ];
  25474. bindingsForPath[ i ] = new PropertyBinding( object, path, parsedPath );
  25475. }
  25476. return bindingsForPath;
  25477. },
  25478. unsubscribe_: function ( path ) {
  25479. // tells the group to forget about a property path and no longer
  25480. // update the array previously obtained with 'subscribe_'
  25481. var indicesByPath = this._bindingsIndicesByPath,
  25482. index = indicesByPath[ path ];
  25483. if ( index !== undefined ) {
  25484. var paths = this._paths,
  25485. parsedPaths = this._parsedPaths,
  25486. bindings = this._bindings,
  25487. lastBindingsIndex = bindings.length - 1,
  25488. lastBindings = bindings[ lastBindingsIndex ],
  25489. lastBindingsPath = path[ lastBindingsIndex ];
  25490. indicesByPath[ lastBindingsPath ] = index;
  25491. bindings[ index ] = lastBindings;
  25492. bindings.pop();
  25493. parsedPaths[ index ] = parsedPaths[ lastBindingsIndex ];
  25494. parsedPaths.pop();
  25495. paths[ index ] = paths[ lastBindingsIndex ];
  25496. paths.pop();
  25497. }
  25498. }
  25499. } );
  25500. /**
  25501. *
  25502. * Action provided by AnimationMixer for scheduling clip playback on specific
  25503. * objects.
  25504. *
  25505. * @author Ben Houston / http://clara.io/
  25506. * @author David Sarno / http://lighthaus.us/
  25507. * @author tschw
  25508. *
  25509. */
  25510. function AnimationAction( mixer, clip, localRoot ) {
  25511. this._mixer = mixer;
  25512. this._clip = clip;
  25513. this._localRoot = localRoot || null;
  25514. var tracks = clip.tracks,
  25515. nTracks = tracks.length,
  25516. interpolants = new Array( nTracks );
  25517. var interpolantSettings = {
  25518. endingStart: ZeroCurvatureEnding,
  25519. endingEnd: ZeroCurvatureEnding
  25520. };
  25521. for ( var i = 0; i !== nTracks; ++ i ) {
  25522. var interpolant = tracks[ i ].createInterpolant( null );
  25523. interpolants[ i ] = interpolant;
  25524. interpolant.settings = interpolantSettings;
  25525. }
  25526. this._interpolantSettings = interpolantSettings;
  25527. this._interpolants = interpolants; // bound by the mixer
  25528. // inside: PropertyMixer (managed by the mixer)
  25529. this._propertyBindings = new Array( nTracks );
  25530. this._cacheIndex = null; // for the memory manager
  25531. this._byClipCacheIndex = null; // for the memory manager
  25532. this._timeScaleInterpolant = null;
  25533. this._weightInterpolant = null;
  25534. this.loop = LoopRepeat;
  25535. this._loopCount = - 1;
  25536. // global mixer time when the action is to be started
  25537. // it's set back to 'null' upon start of the action
  25538. this._startTime = null;
  25539. // scaled local time of the action
  25540. // gets clamped or wrapped to 0..clip.duration according to loop
  25541. this.time = 0;
  25542. this.timeScale = 1;
  25543. this._effectiveTimeScale = 1;
  25544. this.weight = 1;
  25545. this._effectiveWeight = 1;
  25546. this.repetitions = Infinity; // no. of repetitions when looping
  25547. this.paused = false; // true -> zero effective time scale
  25548. this.enabled = true; // false -> zero effective weight
  25549. this.clampWhenFinished = false;// keep feeding the last frame?
  25550. this.zeroSlopeAtStart = true;// for smooth interpolation w/o separate
  25551. this.zeroSlopeAtEnd = true;// clips for start, loop and end
  25552. }
  25553. Object.assign( AnimationAction.prototype, {
  25554. // State & Scheduling
  25555. play: function () {
  25556. this._mixer._activateAction( this );
  25557. return this;
  25558. },
  25559. stop: function () {
  25560. this._mixer._deactivateAction( this );
  25561. return this.reset();
  25562. },
  25563. reset: function () {
  25564. this.paused = false;
  25565. this.enabled = true;
  25566. this.time = 0; // restart clip
  25567. this._loopCount = - 1;// forget previous loops
  25568. this._startTime = null;// forget scheduling
  25569. return this.stopFading().stopWarping();
  25570. },
  25571. isRunning: function () {
  25572. return this.enabled && ! this.paused && this.timeScale !== 0 &&
  25573. this._startTime === null && this._mixer._isActiveAction( this );
  25574. },
  25575. // return true when play has been called
  25576. isScheduled: function () {
  25577. return this._mixer._isActiveAction( this );
  25578. },
  25579. startAt: function ( time ) {
  25580. this._startTime = time;
  25581. return this;
  25582. },
  25583. setLoop: function ( mode, repetitions ) {
  25584. this.loop = mode;
  25585. this.repetitions = repetitions;
  25586. return this;
  25587. },
  25588. // Weight
  25589. // set the weight stopping any scheduled fading
  25590. // although .enabled = false yields an effective weight of zero, this
  25591. // method does *not* change .enabled, because it would be confusing
  25592. setEffectiveWeight: function ( weight ) {
  25593. this.weight = weight;
  25594. // note: same logic as when updated at runtime
  25595. this._effectiveWeight = this.enabled ? weight : 0;
  25596. return this.stopFading();
  25597. },
  25598. // return the weight considering fading and .enabled
  25599. getEffectiveWeight: function () {
  25600. return this._effectiveWeight;
  25601. },
  25602. fadeIn: function ( duration ) {
  25603. return this._scheduleFading( duration, 0, 1 );
  25604. },
  25605. fadeOut: function ( duration ) {
  25606. return this._scheduleFading( duration, 1, 0 );
  25607. },
  25608. crossFadeFrom: function ( fadeOutAction, duration, warp ) {
  25609. fadeOutAction.fadeOut( duration );
  25610. this.fadeIn( duration );
  25611. if ( warp ) {
  25612. var fadeInDuration = this._clip.duration,
  25613. fadeOutDuration = fadeOutAction._clip.duration,
  25614. startEndRatio = fadeOutDuration / fadeInDuration,
  25615. endStartRatio = fadeInDuration / fadeOutDuration;
  25616. fadeOutAction.warp( 1.0, startEndRatio, duration );
  25617. this.warp( endStartRatio, 1.0, duration );
  25618. }
  25619. return this;
  25620. },
  25621. crossFadeTo: function ( fadeInAction, duration, warp ) {
  25622. return fadeInAction.crossFadeFrom( this, duration, warp );
  25623. },
  25624. stopFading: function () {
  25625. var weightInterpolant = this._weightInterpolant;
  25626. if ( weightInterpolant !== null ) {
  25627. this._weightInterpolant = null;
  25628. this._mixer._takeBackControlInterpolant( weightInterpolant );
  25629. }
  25630. return this;
  25631. },
  25632. // Time Scale Control
  25633. // set the time scale stopping any scheduled warping
  25634. // although .paused = true yields an effective time scale of zero, this
  25635. // method does *not* change .paused, because it would be confusing
  25636. setEffectiveTimeScale: function ( timeScale ) {
  25637. this.timeScale = timeScale;
  25638. this._effectiveTimeScale = this.paused ? 0 : timeScale;
  25639. return this.stopWarping();
  25640. },
  25641. // return the time scale considering warping and .paused
  25642. getEffectiveTimeScale: function () {
  25643. return this._effectiveTimeScale;
  25644. },
  25645. setDuration: function ( duration ) {
  25646. this.timeScale = this._clip.duration / duration;
  25647. return this.stopWarping();
  25648. },
  25649. syncWith: function ( action ) {
  25650. this.time = action.time;
  25651. this.timeScale = action.timeScale;
  25652. return this.stopWarping();
  25653. },
  25654. halt: function ( duration ) {
  25655. return this.warp( this._effectiveTimeScale, 0, duration );
  25656. },
  25657. warp: function ( startTimeScale, endTimeScale, duration ) {
  25658. var mixer = this._mixer, now = mixer.time,
  25659. interpolant = this._timeScaleInterpolant,
  25660. timeScale = this.timeScale;
  25661. if ( interpolant === null ) {
  25662. interpolant = mixer._lendControlInterpolant();
  25663. this._timeScaleInterpolant = interpolant;
  25664. }
  25665. var times = interpolant.parameterPositions,
  25666. values = interpolant.sampleValues;
  25667. times[ 0 ] = now;
  25668. times[ 1 ] = now + duration;
  25669. values[ 0 ] = startTimeScale / timeScale;
  25670. values[ 1 ] = endTimeScale / timeScale;
  25671. return this;
  25672. },
  25673. stopWarping: function () {
  25674. var timeScaleInterpolant = this._timeScaleInterpolant;
  25675. if ( timeScaleInterpolant !== null ) {
  25676. this._timeScaleInterpolant = null;
  25677. this._mixer._takeBackControlInterpolant( timeScaleInterpolant );
  25678. }
  25679. return this;
  25680. },
  25681. // Object Accessors
  25682. getMixer: function () {
  25683. return this._mixer;
  25684. },
  25685. getClip: function () {
  25686. return this._clip;
  25687. },
  25688. getRoot: function () {
  25689. return this._localRoot || this._mixer._root;
  25690. },
  25691. // Interna
  25692. _update: function ( time, deltaTime, timeDirection, accuIndex ) {
  25693. // called by the mixer
  25694. if ( ! this.enabled ) {
  25695. // call ._updateWeight() to update ._effectiveWeight
  25696. this._updateWeight( time );
  25697. return;
  25698. }
  25699. var startTime = this._startTime;
  25700. if ( startTime !== null ) {
  25701. // check for scheduled start of action
  25702. var timeRunning = ( time - startTime ) * timeDirection;
  25703. if ( timeRunning < 0 || timeDirection === 0 ) {
  25704. return; // yet to come / don't decide when delta = 0
  25705. }
  25706. // start
  25707. this._startTime = null; // unschedule
  25708. deltaTime = timeDirection * timeRunning;
  25709. }
  25710. // apply time scale and advance time
  25711. deltaTime *= this._updateTimeScale( time );
  25712. var clipTime = this._updateTime( deltaTime );
  25713. // note: _updateTime may disable the action resulting in
  25714. // an effective weight of 0
  25715. var weight = this._updateWeight( time );
  25716. if ( weight > 0 ) {
  25717. var interpolants = this._interpolants;
  25718. var propertyMixers = this._propertyBindings;
  25719. for ( var j = 0, m = interpolants.length; j !== m; ++ j ) {
  25720. interpolants[ j ].evaluate( clipTime );
  25721. propertyMixers[ j ].accumulate( accuIndex, weight );
  25722. }
  25723. }
  25724. },
  25725. _updateWeight: function ( time ) {
  25726. var weight = 0;
  25727. if ( this.enabled ) {
  25728. weight = this.weight;
  25729. var interpolant = this._weightInterpolant;
  25730. if ( interpolant !== null ) {
  25731. var interpolantValue = interpolant.evaluate( time )[ 0 ];
  25732. weight *= interpolantValue;
  25733. if ( time > interpolant.parameterPositions[ 1 ] ) {
  25734. this.stopFading();
  25735. if ( interpolantValue === 0 ) {
  25736. // faded out, disable
  25737. this.enabled = false;
  25738. }
  25739. }
  25740. }
  25741. }
  25742. this._effectiveWeight = weight;
  25743. return weight;
  25744. },
  25745. _updateTimeScale: function ( time ) {
  25746. var timeScale = 0;
  25747. if ( ! this.paused ) {
  25748. timeScale = this.timeScale;
  25749. var interpolant = this._timeScaleInterpolant;
  25750. if ( interpolant !== null ) {
  25751. var interpolantValue = interpolant.evaluate( time )[ 0 ];
  25752. timeScale *= interpolantValue;
  25753. if ( time > interpolant.parameterPositions[ 1 ] ) {
  25754. this.stopWarping();
  25755. if ( timeScale === 0 ) {
  25756. // motion has halted, pause
  25757. this.paused = true;
  25758. } else {
  25759. // warp done - apply final time scale
  25760. this.timeScale = timeScale;
  25761. }
  25762. }
  25763. }
  25764. }
  25765. this._effectiveTimeScale = timeScale;
  25766. return timeScale;
  25767. },
  25768. _updateTime: function ( deltaTime ) {
  25769. var time = this.time + deltaTime;
  25770. var duration = this._clip.duration;
  25771. var loop = this.loop;
  25772. var loopCount = this._loopCount;
  25773. var pingPong = ( loop === LoopPingPong );
  25774. if ( deltaTime === 0 ) {
  25775. if ( loopCount === - 1 ) return time;
  25776. return ( pingPong && ( loopCount & 1 ) === 1 ) ? duration - time : time;
  25777. }
  25778. if ( loop === LoopOnce ) {
  25779. if ( loopCount === - 1 ) {
  25780. // just started
  25781. this._loopCount = 0;
  25782. this._setEndings( true, true, false );
  25783. }
  25784. handle_stop: {
  25785. if ( time >= duration ) {
  25786. time = duration;
  25787. } else if ( time < 0 ) {
  25788. time = 0;
  25789. } else break handle_stop;
  25790. if ( this.clampWhenFinished ) this.paused = true;
  25791. else this.enabled = false;
  25792. this._mixer.dispatchEvent( {
  25793. type: 'finished', action: this,
  25794. direction: deltaTime < 0 ? - 1 : 1
  25795. } );
  25796. }
  25797. } else { // repetitive Repeat or PingPong
  25798. if ( loopCount === - 1 ) {
  25799. // just started
  25800. if ( deltaTime >= 0 ) {
  25801. loopCount = 0;
  25802. this._setEndings( true, this.repetitions === 0, pingPong );
  25803. } else {
  25804. // when looping in reverse direction, the initial
  25805. // transition through zero counts as a repetition,
  25806. // so leave loopCount at -1
  25807. this._setEndings( this.repetitions === 0, true, pingPong );
  25808. }
  25809. }
  25810. if ( time >= duration || time < 0 ) {
  25811. // wrap around
  25812. var loopDelta = Math.floor( time / duration ); // signed
  25813. time -= duration * loopDelta;
  25814. loopCount += Math.abs( loopDelta );
  25815. var pending = this.repetitions - loopCount;
  25816. if ( pending <= 0 ) {
  25817. // have to stop (switch state, clamp time, fire event)
  25818. if ( this.clampWhenFinished ) this.paused = true;
  25819. else this.enabled = false;
  25820. time = deltaTime > 0 ? duration : 0;
  25821. this._mixer.dispatchEvent( {
  25822. type: 'finished', action: this,
  25823. direction: deltaTime > 0 ? 1 : - 1
  25824. } );
  25825. } else {
  25826. // keep running
  25827. if ( pending === 1 ) {
  25828. // entering the last round
  25829. var atStart = deltaTime < 0;
  25830. this._setEndings( atStart, ! atStart, pingPong );
  25831. } else {
  25832. this._setEndings( false, false, pingPong );
  25833. }
  25834. this._loopCount = loopCount;
  25835. this._mixer.dispatchEvent( {
  25836. type: 'loop', action: this, loopDelta: loopDelta
  25837. } );
  25838. }
  25839. }
  25840. if ( pingPong && ( loopCount & 1 ) === 1 ) {
  25841. // invert time for the "pong round"
  25842. this.time = time;
  25843. return duration - time;
  25844. }
  25845. }
  25846. this.time = time;
  25847. return time;
  25848. },
  25849. _setEndings: function ( atStart, atEnd, pingPong ) {
  25850. var settings = this._interpolantSettings;
  25851. if ( pingPong ) {
  25852. settings.endingStart = ZeroSlopeEnding;
  25853. settings.endingEnd = ZeroSlopeEnding;
  25854. } else {
  25855. // assuming for LoopOnce atStart == atEnd == true
  25856. if ( atStart ) {
  25857. settings.endingStart = this.zeroSlopeAtStart ? ZeroSlopeEnding : ZeroCurvatureEnding;
  25858. } else {
  25859. settings.endingStart = WrapAroundEnding;
  25860. }
  25861. if ( atEnd ) {
  25862. settings.endingEnd = this.zeroSlopeAtEnd ? ZeroSlopeEnding : ZeroCurvatureEnding;
  25863. } else {
  25864. settings.endingEnd = WrapAroundEnding;
  25865. }
  25866. }
  25867. },
  25868. _scheduleFading: function ( duration, weightNow, weightThen ) {
  25869. var mixer = this._mixer, now = mixer.time,
  25870. interpolant = this._weightInterpolant;
  25871. if ( interpolant === null ) {
  25872. interpolant = mixer._lendControlInterpolant();
  25873. this._weightInterpolant = interpolant;
  25874. }
  25875. var times = interpolant.parameterPositions,
  25876. values = interpolant.sampleValues;
  25877. times[ 0 ] = now;
  25878. values[ 0 ] = weightNow;
  25879. times[ 1 ] = now + duration;
  25880. values[ 1 ] = weightThen;
  25881. return this;
  25882. }
  25883. } );
  25884. /**
  25885. *
  25886. * Player for AnimationClips.
  25887. *
  25888. *
  25889. * @author Ben Houston / http://clara.io/
  25890. * @author David Sarno / http://lighthaus.us/
  25891. * @author tschw
  25892. */
  25893. function AnimationMixer( root ) {
  25894. this._root = root;
  25895. this._initMemoryManager();
  25896. this._accuIndex = 0;
  25897. this.time = 0;
  25898. this.timeScale = 1.0;
  25899. }
  25900. AnimationMixer.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  25901. constructor: AnimationMixer,
  25902. _bindAction: function ( action, prototypeAction ) {
  25903. var root = action._localRoot || this._root,
  25904. tracks = action._clip.tracks,
  25905. nTracks = tracks.length,
  25906. bindings = action._propertyBindings,
  25907. interpolants = action._interpolants,
  25908. rootUuid = root.uuid,
  25909. bindingsByRoot = this._bindingsByRootAndName,
  25910. bindingsByName = bindingsByRoot[ rootUuid ];
  25911. if ( bindingsByName === undefined ) {
  25912. bindingsByName = {};
  25913. bindingsByRoot[ rootUuid ] = bindingsByName;
  25914. }
  25915. for ( var i = 0; i !== nTracks; ++ i ) {
  25916. var track = tracks[ i ],
  25917. trackName = track.name,
  25918. binding = bindingsByName[ trackName ];
  25919. if ( binding !== undefined ) {
  25920. bindings[ i ] = binding;
  25921. } else {
  25922. binding = bindings[ i ];
  25923. if ( binding !== undefined ) {
  25924. // existing binding, make sure the cache knows
  25925. if ( binding._cacheIndex === null ) {
  25926. ++ binding.referenceCount;
  25927. this._addInactiveBinding( binding, rootUuid, trackName );
  25928. }
  25929. continue;
  25930. }
  25931. var path = prototypeAction && prototypeAction.
  25932. _propertyBindings[ i ].binding.parsedPath;
  25933. binding = new PropertyMixer(
  25934. PropertyBinding.create( root, trackName, path ),
  25935. track.ValueTypeName, track.getValueSize() );
  25936. ++ binding.referenceCount;
  25937. this._addInactiveBinding( binding, rootUuid, trackName );
  25938. bindings[ i ] = binding;
  25939. }
  25940. interpolants[ i ].resultBuffer = binding.buffer;
  25941. }
  25942. },
  25943. _activateAction: function ( action ) {
  25944. if ( ! this._isActiveAction( action ) ) {
  25945. if ( action._cacheIndex === null ) {
  25946. // this action has been forgotten by the cache, but the user
  25947. // appears to be still using it -> rebind
  25948. var rootUuid = ( action._localRoot || this._root ).uuid,
  25949. clipUuid = action._clip.uuid,
  25950. actionsForClip = this._actionsByClip[ clipUuid ];
  25951. this._bindAction( action,
  25952. actionsForClip && actionsForClip.knownActions[ 0 ] );
  25953. this._addInactiveAction( action, clipUuid, rootUuid );
  25954. }
  25955. var bindings = action._propertyBindings;
  25956. // increment reference counts / sort out state
  25957. for ( var i = 0, n = bindings.length; i !== n; ++ i ) {
  25958. var binding = bindings[ i ];
  25959. if ( binding.useCount ++ === 0 ) {
  25960. this._lendBinding( binding );
  25961. binding.saveOriginalState();
  25962. }
  25963. }
  25964. this._lendAction( action );
  25965. }
  25966. },
  25967. _deactivateAction: function ( action ) {
  25968. if ( this._isActiveAction( action ) ) {
  25969. var bindings = action._propertyBindings;
  25970. // decrement reference counts / sort out state
  25971. for ( var i = 0, n = bindings.length; i !== n; ++ i ) {
  25972. var binding = bindings[ i ];
  25973. if ( -- binding.useCount === 0 ) {
  25974. binding.restoreOriginalState();
  25975. this._takeBackBinding( binding );
  25976. }
  25977. }
  25978. this._takeBackAction( action );
  25979. }
  25980. },
  25981. // Memory manager
  25982. _initMemoryManager: function () {
  25983. this._actions = []; // 'nActiveActions' followed by inactive ones
  25984. this._nActiveActions = 0;
  25985. this._actionsByClip = {};
  25986. // inside:
  25987. // {
  25988. // knownActions: Array< AnimationAction > - used as prototypes
  25989. // actionByRoot: AnimationAction - lookup
  25990. // }
  25991. this._bindings = []; // 'nActiveBindings' followed by inactive ones
  25992. this._nActiveBindings = 0;
  25993. this._bindingsByRootAndName = {}; // inside: Map< name, PropertyMixer >
  25994. this._controlInterpolants = []; // same game as above
  25995. this._nActiveControlInterpolants = 0;
  25996. var scope = this;
  25997. this.stats = {
  25998. actions: {
  25999. get total() {
  26000. return scope._actions.length;
  26001. },
  26002. get inUse() {
  26003. return scope._nActiveActions;
  26004. }
  26005. },
  26006. bindings: {
  26007. get total() {
  26008. return scope._bindings.length;
  26009. },
  26010. get inUse() {
  26011. return scope._nActiveBindings;
  26012. }
  26013. },
  26014. controlInterpolants: {
  26015. get total() {
  26016. return scope._controlInterpolants.length;
  26017. },
  26018. get inUse() {
  26019. return scope._nActiveControlInterpolants;
  26020. }
  26021. }
  26022. };
  26023. },
  26024. // Memory management for AnimationAction objects
  26025. _isActiveAction: function ( action ) {
  26026. var index = action._cacheIndex;
  26027. return index !== null && index < this._nActiveActions;
  26028. },
  26029. _addInactiveAction: function ( action, clipUuid, rootUuid ) {
  26030. var actions = this._actions,
  26031. actionsByClip = this._actionsByClip,
  26032. actionsForClip = actionsByClip[ clipUuid ];
  26033. if ( actionsForClip === undefined ) {
  26034. actionsForClip = {
  26035. knownActions: [ action ],
  26036. actionByRoot: {}
  26037. };
  26038. action._byClipCacheIndex = 0;
  26039. actionsByClip[ clipUuid ] = actionsForClip;
  26040. } else {
  26041. var knownActions = actionsForClip.knownActions;
  26042. action._byClipCacheIndex = knownActions.length;
  26043. knownActions.push( action );
  26044. }
  26045. action._cacheIndex = actions.length;
  26046. actions.push( action );
  26047. actionsForClip.actionByRoot[ rootUuid ] = action;
  26048. },
  26049. _removeInactiveAction: function ( action ) {
  26050. var actions = this._actions,
  26051. lastInactiveAction = actions[ actions.length - 1 ],
  26052. cacheIndex = action._cacheIndex;
  26053. lastInactiveAction._cacheIndex = cacheIndex;
  26054. actions[ cacheIndex ] = lastInactiveAction;
  26055. actions.pop();
  26056. action._cacheIndex = null;
  26057. var clipUuid = action._clip.uuid,
  26058. actionsByClip = this._actionsByClip,
  26059. actionsForClip = actionsByClip[ clipUuid ],
  26060. knownActionsForClip = actionsForClip.knownActions,
  26061. lastKnownAction =
  26062. knownActionsForClip[ knownActionsForClip.length - 1 ],
  26063. byClipCacheIndex = action._byClipCacheIndex;
  26064. lastKnownAction._byClipCacheIndex = byClipCacheIndex;
  26065. knownActionsForClip[ byClipCacheIndex ] = lastKnownAction;
  26066. knownActionsForClip.pop();
  26067. action._byClipCacheIndex = null;
  26068. var actionByRoot = actionsForClip.actionByRoot,
  26069. rootUuid = ( action._localRoot || this._root ).uuid;
  26070. delete actionByRoot[ rootUuid ];
  26071. if ( knownActionsForClip.length === 0 ) {
  26072. delete actionsByClip[ clipUuid ];
  26073. }
  26074. this._removeInactiveBindingsForAction( action );
  26075. },
  26076. _removeInactiveBindingsForAction: function ( action ) {
  26077. var bindings = action._propertyBindings;
  26078. for ( var i = 0, n = bindings.length; i !== n; ++ i ) {
  26079. var binding = bindings[ i ];
  26080. if ( -- binding.referenceCount === 0 ) {
  26081. this._removeInactiveBinding( binding );
  26082. }
  26083. }
  26084. },
  26085. _lendAction: function ( action ) {
  26086. // [ active actions | inactive actions ]
  26087. // [ active actions >| inactive actions ]
  26088. // s a
  26089. // <-swap->
  26090. // a s
  26091. var actions = this._actions,
  26092. prevIndex = action._cacheIndex,
  26093. lastActiveIndex = this._nActiveActions ++,
  26094. firstInactiveAction = actions[ lastActiveIndex ];
  26095. action._cacheIndex = lastActiveIndex;
  26096. actions[ lastActiveIndex ] = action;
  26097. firstInactiveAction._cacheIndex = prevIndex;
  26098. actions[ prevIndex ] = firstInactiveAction;
  26099. },
  26100. _takeBackAction: function ( action ) {
  26101. // [ active actions | inactive actions ]
  26102. // [ active actions |< inactive actions ]
  26103. // a s
  26104. // <-swap->
  26105. // s a
  26106. var actions = this._actions,
  26107. prevIndex = action._cacheIndex,
  26108. firstInactiveIndex = -- this._nActiveActions,
  26109. lastActiveAction = actions[ firstInactiveIndex ];
  26110. action._cacheIndex = firstInactiveIndex;
  26111. actions[ firstInactiveIndex ] = action;
  26112. lastActiveAction._cacheIndex = prevIndex;
  26113. actions[ prevIndex ] = lastActiveAction;
  26114. },
  26115. // Memory management for PropertyMixer objects
  26116. _addInactiveBinding: function ( binding, rootUuid, trackName ) {
  26117. var bindingsByRoot = this._bindingsByRootAndName,
  26118. bindingByName = bindingsByRoot[ rootUuid ],
  26119. bindings = this._bindings;
  26120. if ( bindingByName === undefined ) {
  26121. bindingByName = {};
  26122. bindingsByRoot[ rootUuid ] = bindingByName;
  26123. }
  26124. bindingByName[ trackName ] = binding;
  26125. binding._cacheIndex = bindings.length;
  26126. bindings.push( binding );
  26127. },
  26128. _removeInactiveBinding: function ( binding ) {
  26129. var bindings = this._bindings,
  26130. propBinding = binding.binding,
  26131. rootUuid = propBinding.rootNode.uuid,
  26132. trackName = propBinding.path,
  26133. bindingsByRoot = this._bindingsByRootAndName,
  26134. bindingByName = bindingsByRoot[ rootUuid ],
  26135. lastInactiveBinding = bindings[ bindings.length - 1 ],
  26136. cacheIndex = binding._cacheIndex;
  26137. lastInactiveBinding._cacheIndex = cacheIndex;
  26138. bindings[ cacheIndex ] = lastInactiveBinding;
  26139. bindings.pop();
  26140. delete bindingByName[ trackName ];
  26141. remove_empty_map: {
  26142. for ( var _ in bindingByName ) break remove_empty_map; // eslint-disable-line no-unused-vars
  26143. delete bindingsByRoot[ rootUuid ];
  26144. }
  26145. },
  26146. _lendBinding: function ( binding ) {
  26147. var bindings = this._bindings,
  26148. prevIndex = binding._cacheIndex,
  26149. lastActiveIndex = this._nActiveBindings ++,
  26150. firstInactiveBinding = bindings[ lastActiveIndex ];
  26151. binding._cacheIndex = lastActiveIndex;
  26152. bindings[ lastActiveIndex ] = binding;
  26153. firstInactiveBinding._cacheIndex = prevIndex;
  26154. bindings[ prevIndex ] = firstInactiveBinding;
  26155. },
  26156. _takeBackBinding: function ( binding ) {
  26157. var bindings = this._bindings,
  26158. prevIndex = binding._cacheIndex,
  26159. firstInactiveIndex = -- this._nActiveBindings,
  26160. lastActiveBinding = bindings[ firstInactiveIndex ];
  26161. binding._cacheIndex = firstInactiveIndex;
  26162. bindings[ firstInactiveIndex ] = binding;
  26163. lastActiveBinding._cacheIndex = prevIndex;
  26164. bindings[ prevIndex ] = lastActiveBinding;
  26165. },
  26166. // Memory management of Interpolants for weight and time scale
  26167. _lendControlInterpolant: function () {
  26168. var interpolants = this._controlInterpolants,
  26169. lastActiveIndex = this._nActiveControlInterpolants ++,
  26170. interpolant = interpolants[ lastActiveIndex ];
  26171. if ( interpolant === undefined ) {
  26172. interpolant = new LinearInterpolant(
  26173. new Float32Array( 2 ), new Float32Array( 2 ),
  26174. 1, this._controlInterpolantsResultBuffer );
  26175. interpolant.__cacheIndex = lastActiveIndex;
  26176. interpolants[ lastActiveIndex ] = interpolant;
  26177. }
  26178. return interpolant;
  26179. },
  26180. _takeBackControlInterpolant: function ( interpolant ) {
  26181. var interpolants = this._controlInterpolants,
  26182. prevIndex = interpolant.__cacheIndex,
  26183. firstInactiveIndex = -- this._nActiveControlInterpolants,
  26184. lastActiveInterpolant = interpolants[ firstInactiveIndex ];
  26185. interpolant.__cacheIndex = firstInactiveIndex;
  26186. interpolants[ firstInactiveIndex ] = interpolant;
  26187. lastActiveInterpolant.__cacheIndex = prevIndex;
  26188. interpolants[ prevIndex ] = lastActiveInterpolant;
  26189. },
  26190. _controlInterpolantsResultBuffer: new Float32Array( 1 ),
  26191. // return an action for a clip optionally using a custom root target
  26192. // object (this method allocates a lot of dynamic memory in case a
  26193. // previously unknown clip/root combination is specified)
  26194. clipAction: function ( clip, optionalRoot ) {
  26195. var root = optionalRoot || this._root,
  26196. rootUuid = root.uuid,
  26197. clipObject = typeof clip === 'string' ?
  26198. AnimationClip.findByName( root, clip ) : clip,
  26199. clipUuid = clipObject !== null ? clipObject.uuid : clip,
  26200. actionsForClip = this._actionsByClip[ clipUuid ],
  26201. prototypeAction = null;
  26202. if ( actionsForClip !== undefined ) {
  26203. var existingAction =
  26204. actionsForClip.actionByRoot[ rootUuid ];
  26205. if ( existingAction !== undefined ) {
  26206. return existingAction;
  26207. }
  26208. // we know the clip, so we don't have to parse all
  26209. // the bindings again but can just copy
  26210. prototypeAction = actionsForClip.knownActions[ 0 ];
  26211. // also, take the clip from the prototype action
  26212. if ( clipObject === null )
  26213. clipObject = prototypeAction._clip;
  26214. }
  26215. // clip must be known when specified via string
  26216. if ( clipObject === null ) return null;
  26217. // allocate all resources required to run it
  26218. var newAction = new AnimationAction( this, clipObject, optionalRoot );
  26219. this._bindAction( newAction, prototypeAction );
  26220. // and make the action known to the memory manager
  26221. this._addInactiveAction( newAction, clipUuid, rootUuid );
  26222. return newAction;
  26223. },
  26224. // get an existing action
  26225. existingAction: function ( clip, optionalRoot ) {
  26226. var root = optionalRoot || this._root,
  26227. rootUuid = root.uuid,
  26228. clipObject = typeof clip === 'string' ?
  26229. AnimationClip.findByName( root, clip ) : clip,
  26230. clipUuid = clipObject ? clipObject.uuid : clip,
  26231. actionsForClip = this._actionsByClip[ clipUuid ];
  26232. if ( actionsForClip !== undefined ) {
  26233. return actionsForClip.actionByRoot[ rootUuid ] || null;
  26234. }
  26235. return null;
  26236. },
  26237. // deactivates all previously scheduled actions
  26238. stopAllAction: function () {
  26239. var actions = this._actions,
  26240. nActions = this._nActiveActions,
  26241. bindings = this._bindings,
  26242. nBindings = this._nActiveBindings;
  26243. this._nActiveActions = 0;
  26244. this._nActiveBindings = 0;
  26245. for ( var i = 0; i !== nActions; ++ i ) {
  26246. actions[ i ].reset();
  26247. }
  26248. for ( var i = 0; i !== nBindings; ++ i ) {
  26249. bindings[ i ].useCount = 0;
  26250. }
  26251. return this;
  26252. },
  26253. // advance the time and update apply the animation
  26254. update: function ( deltaTime ) {
  26255. deltaTime *= this.timeScale;
  26256. var actions = this._actions,
  26257. nActions = this._nActiveActions,
  26258. time = this.time += deltaTime,
  26259. timeDirection = Math.sign( deltaTime ),
  26260. accuIndex = this._accuIndex ^= 1;
  26261. // run active actions
  26262. for ( var i = 0; i !== nActions; ++ i ) {
  26263. var action = actions[ i ];
  26264. action._update( time, deltaTime, timeDirection, accuIndex );
  26265. }
  26266. // update scene graph
  26267. var bindings = this._bindings,
  26268. nBindings = this._nActiveBindings;
  26269. for ( var i = 0; i !== nBindings; ++ i ) {
  26270. bindings[ i ].apply( accuIndex );
  26271. }
  26272. return this;
  26273. },
  26274. // return this mixer's root target object
  26275. getRoot: function () {
  26276. return this._root;
  26277. },
  26278. // free all resources specific to a particular clip
  26279. uncacheClip: function ( clip ) {
  26280. var actions = this._actions,
  26281. clipUuid = clip.uuid,
  26282. actionsByClip = this._actionsByClip,
  26283. actionsForClip = actionsByClip[ clipUuid ];
  26284. if ( actionsForClip !== undefined ) {
  26285. // note: just calling _removeInactiveAction would mess up the
  26286. // iteration state and also require updating the state we can
  26287. // just throw away
  26288. var actionsToRemove = actionsForClip.knownActions;
  26289. for ( var i = 0, n = actionsToRemove.length; i !== n; ++ i ) {
  26290. var action = actionsToRemove[ i ];
  26291. this._deactivateAction( action );
  26292. var cacheIndex = action._cacheIndex,
  26293. lastInactiveAction = actions[ actions.length - 1 ];
  26294. action._cacheIndex = null;
  26295. action._byClipCacheIndex = null;
  26296. lastInactiveAction._cacheIndex = cacheIndex;
  26297. actions[ cacheIndex ] = lastInactiveAction;
  26298. actions.pop();
  26299. this._removeInactiveBindingsForAction( action );
  26300. }
  26301. delete actionsByClip[ clipUuid ];
  26302. }
  26303. },
  26304. // free all resources specific to a particular root target object
  26305. uncacheRoot: function ( root ) {
  26306. var rootUuid = root.uuid,
  26307. actionsByClip = this._actionsByClip;
  26308. for ( var clipUuid in actionsByClip ) {
  26309. var actionByRoot = actionsByClip[ clipUuid ].actionByRoot,
  26310. action = actionByRoot[ rootUuid ];
  26311. if ( action !== undefined ) {
  26312. this._deactivateAction( action );
  26313. this._removeInactiveAction( action );
  26314. }
  26315. }
  26316. var bindingsByRoot = this._bindingsByRootAndName,
  26317. bindingByName = bindingsByRoot[ rootUuid ];
  26318. if ( bindingByName !== undefined ) {
  26319. for ( var trackName in bindingByName ) {
  26320. var binding = bindingByName[ trackName ];
  26321. binding.restoreOriginalState();
  26322. this._removeInactiveBinding( binding );
  26323. }
  26324. }
  26325. },
  26326. // remove a targeted clip from the cache
  26327. uncacheAction: function ( clip, optionalRoot ) {
  26328. var action = this.existingAction( clip, optionalRoot );
  26329. if ( action !== null ) {
  26330. this._deactivateAction( action );
  26331. this._removeInactiveAction( action );
  26332. }
  26333. }
  26334. } );
  26335. /**
  26336. * @author mrdoob / http://mrdoob.com/
  26337. */
  26338. function Uniform( value ) {
  26339. if ( typeof value === 'string' ) {
  26340. console.warn( 'THREE.Uniform: Type parameter is no longer needed.' );
  26341. value = arguments[ 1 ];
  26342. }
  26343. this.value = value;
  26344. }
  26345. Uniform.prototype.clone = function () {
  26346. return new Uniform( this.value.clone === undefined ? this.value : this.value.clone() );
  26347. };
  26348. /**
  26349. * @author benaadams / https://twitter.com/ben_a_adams
  26350. */
  26351. function InstancedBufferGeometry() {
  26352. BufferGeometry.call( this );
  26353. this.type = 'InstancedBufferGeometry';
  26354. this.maxInstancedCount = undefined;
  26355. }
  26356. InstancedBufferGeometry.prototype = Object.assign( Object.create( BufferGeometry.prototype ), {
  26357. constructor: InstancedBufferGeometry,
  26358. isInstancedBufferGeometry: true,
  26359. copy: function ( source ) {
  26360. BufferGeometry.prototype.copy.call( this, source );
  26361. this.maxInstancedCount = source.maxInstancedCount;
  26362. return this;
  26363. },
  26364. clone: function () {
  26365. return new this.constructor().copy( this );
  26366. }
  26367. } );
  26368. /**
  26369. * @author benaadams / https://twitter.com/ben_a_adams
  26370. */
  26371. function InstancedInterleavedBuffer( array, stride, meshPerAttribute ) {
  26372. InterleavedBuffer.call( this, array, stride );
  26373. this.meshPerAttribute = meshPerAttribute || 1;
  26374. }
  26375. InstancedInterleavedBuffer.prototype = Object.assign( Object.create( InterleavedBuffer.prototype ), {
  26376. constructor: InstancedInterleavedBuffer,
  26377. isInstancedInterleavedBuffer: true,
  26378. copy: function ( source ) {
  26379. InterleavedBuffer.prototype.copy.call( this, source );
  26380. this.meshPerAttribute = source.meshPerAttribute;
  26381. return this;
  26382. }
  26383. } );
  26384. /**
  26385. * @author benaadams / https://twitter.com/ben_a_adams
  26386. */
  26387. function InstancedBufferAttribute( array, itemSize, normalized, meshPerAttribute ) {
  26388. if ( typeof ( normalized ) === 'number' ) {
  26389. meshPerAttribute = normalized;
  26390. normalized = false;
  26391. console.error( 'THREE.InstancedBufferAttribute: The constructor now expects normalized as the third argument.' );
  26392. }
  26393. BufferAttribute.call( this, array, itemSize, normalized );
  26394. this.meshPerAttribute = meshPerAttribute || 1;
  26395. }
  26396. InstancedBufferAttribute.prototype = Object.assign( Object.create( BufferAttribute.prototype ), {
  26397. constructor: InstancedBufferAttribute,
  26398. isInstancedBufferAttribute: true,
  26399. copy: function ( source ) {
  26400. BufferAttribute.prototype.copy.call( this, source );
  26401. this.meshPerAttribute = source.meshPerAttribute;
  26402. return this;
  26403. }
  26404. } );
  26405. /**
  26406. * @author mrdoob / http://mrdoob.com/
  26407. * @author bhouston / http://clara.io/
  26408. * @author stephomi / http://stephaneginier.com/
  26409. */
  26410. function Raycaster( origin, direction, near, far ) {
  26411. this.ray = new Ray( origin, direction );
  26412. // direction is assumed to be normalized (for accurate distance calculations)
  26413. this.near = near || 0;
  26414. this.far = far || Infinity;
  26415. this.params = {
  26416. Mesh: {},
  26417. Line: {},
  26418. LOD: {},
  26419. Points: { threshold: 1 },
  26420. Sprite: {}
  26421. };
  26422. Object.defineProperties( this.params, {
  26423. PointCloud: {
  26424. get: function () {
  26425. console.warn( 'THREE.Raycaster: params.PointCloud has been renamed to params.Points.' );
  26426. return this.Points;
  26427. }
  26428. }
  26429. } );
  26430. }
  26431. function ascSort( a, b ) {
  26432. return a.distance - b.distance;
  26433. }
  26434. function intersectObject( object, raycaster, intersects, recursive ) {
  26435. if ( object.visible === false ) return;
  26436. object.raycast( raycaster, intersects );
  26437. if ( recursive === true ) {
  26438. var children = object.children;
  26439. for ( var i = 0, l = children.length; i < l; i ++ ) {
  26440. intersectObject( children[ i ], raycaster, intersects, true );
  26441. }
  26442. }
  26443. }
  26444. Object.assign( Raycaster.prototype, {
  26445. linePrecision: 1,
  26446. set: function ( origin, direction ) {
  26447. // direction is assumed to be normalized (for accurate distance calculations)
  26448. this.ray.set( origin, direction );
  26449. },
  26450. setFromCamera: function ( coords, camera ) {
  26451. if ( ( camera && camera.isPerspectiveCamera ) ) {
  26452. this.ray.origin.setFromMatrixPosition( camera.matrixWorld );
  26453. this.ray.direction.set( coords.x, coords.y, 0.5 ).unproject( camera ).sub( this.ray.origin ).normalize();
  26454. } else if ( ( camera && camera.isOrthographicCamera ) ) {
  26455. this.ray.origin.set( coords.x, coords.y, ( camera.near + camera.far ) / ( camera.near - camera.far ) ).unproject( camera ); // set origin in plane of camera
  26456. this.ray.direction.set( 0, 0, - 1 ).transformDirection( camera.matrixWorld );
  26457. } else {
  26458. console.error( 'THREE.Raycaster: Unsupported camera type.' );
  26459. }
  26460. },
  26461. intersectObject: function ( object, recursive, optionalTarget ) {
  26462. var intersects = optionalTarget || [];
  26463. intersectObject( object, this, intersects, recursive );
  26464. intersects.sort( ascSort );
  26465. return intersects;
  26466. },
  26467. intersectObjects: function ( objects, recursive, optionalTarget ) {
  26468. var intersects = optionalTarget || [];
  26469. if ( Array.isArray( objects ) === false ) {
  26470. console.warn( 'THREE.Raycaster.intersectObjects: objects is not an Array.' );
  26471. return intersects;
  26472. }
  26473. for ( var i = 0, l = objects.length; i < l; i ++ ) {
  26474. intersectObject( objects[ i ], this, intersects, recursive );
  26475. }
  26476. intersects.sort( ascSort );
  26477. return intersects;
  26478. }
  26479. } );
  26480. /**
  26481. * @author bhouston / http://clara.io
  26482. * @author WestLangley / http://github.com/WestLangley
  26483. *
  26484. * Ref: https://en.wikipedia.org/wiki/Spherical_coordinate_system
  26485. *
  26486. * The polar angle (phi) is measured from the positive y-axis. The positive y-axis is up.
  26487. * The azimuthal angle (theta) is measured from the positive z-axiz.
  26488. */
  26489. function Spherical( radius, phi, theta ) {
  26490. this.radius = ( radius !== undefined ) ? radius : 1.0;
  26491. this.phi = ( phi !== undefined ) ? phi : 0; // polar angle
  26492. this.theta = ( theta !== undefined ) ? theta : 0; // azimuthal angle
  26493. return this;
  26494. }
  26495. Object.assign( Spherical.prototype, {
  26496. set: function ( radius, phi, theta ) {
  26497. this.radius = radius;
  26498. this.phi = phi;
  26499. this.theta = theta;
  26500. return this;
  26501. },
  26502. clone: function () {
  26503. return new this.constructor().copy( this );
  26504. },
  26505. copy: function ( other ) {
  26506. this.radius = other.radius;
  26507. this.phi = other.phi;
  26508. this.theta = other.theta;
  26509. return this;
  26510. },
  26511. // restrict phi to be betwee EPS and PI-EPS
  26512. makeSafe: function () {
  26513. var EPS = 0.000001;
  26514. this.phi = Math.max( EPS, Math.min( Math.PI - EPS, this.phi ) );
  26515. return this;
  26516. },
  26517. setFromVector3: function ( v ) {
  26518. return this.setFromCartesianCoords( v.x, v.y, v.z );
  26519. },
  26520. setFromCartesianCoords: function ( x, y, z ) {
  26521. this.radius = Math.sqrt( x * x + y * y + z * z );
  26522. if ( this.radius === 0 ) {
  26523. this.theta = 0;
  26524. this.phi = 0;
  26525. } else {
  26526. this.theta = Math.atan2( x, z );
  26527. this.phi = Math.acos( _Math.clamp( y / this.radius, - 1, 1 ) );
  26528. }
  26529. return this;
  26530. }
  26531. } );
  26532. /**
  26533. * @author Mugen87 / https://github.com/Mugen87
  26534. *
  26535. * Ref: https://en.wikipedia.org/wiki/Cylindrical_coordinate_system
  26536. *
  26537. */
  26538. function Cylindrical( radius, theta, y ) {
  26539. this.radius = ( radius !== undefined ) ? radius : 1.0; // distance from the origin to a point in the x-z plane
  26540. this.theta = ( theta !== undefined ) ? theta : 0; // counterclockwise angle in the x-z plane measured in radians from the positive z-axis
  26541. this.y = ( y !== undefined ) ? y : 0; // height above the x-z plane
  26542. return this;
  26543. }
  26544. Object.assign( Cylindrical.prototype, {
  26545. set: function ( radius, theta, y ) {
  26546. this.radius = radius;
  26547. this.theta = theta;
  26548. this.y = y;
  26549. return this;
  26550. },
  26551. clone: function () {
  26552. return new this.constructor().copy( this );
  26553. },
  26554. copy: function ( other ) {
  26555. this.radius = other.radius;
  26556. this.theta = other.theta;
  26557. this.y = other.y;
  26558. return this;
  26559. },
  26560. setFromVector3: function ( v ) {
  26561. return this.setFromCartesianCoords( v.x, v.y, v.z );
  26562. },
  26563. setFromCartesianCoords: function ( x, y, z ) {
  26564. this.radius = Math.sqrt( x * x + z * z );
  26565. this.theta = Math.atan2( x, z );
  26566. this.y = y;
  26567. return this;
  26568. }
  26569. } );
  26570. /**
  26571. * @author bhouston / http://clara.io
  26572. */
  26573. function Box2( min, max ) {
  26574. this.min = ( min !== undefined ) ? min : new Vector2( + Infinity, + Infinity );
  26575. this.max = ( max !== undefined ) ? max : new Vector2( - Infinity, - Infinity );
  26576. }
  26577. Object.assign( Box2.prototype, {
  26578. set: function ( min, max ) {
  26579. this.min.copy( min );
  26580. this.max.copy( max );
  26581. return this;
  26582. },
  26583. setFromPoints: function ( points ) {
  26584. this.makeEmpty();
  26585. for ( var i = 0, il = points.length; i < il; i ++ ) {
  26586. this.expandByPoint( points[ i ] );
  26587. }
  26588. return this;
  26589. },
  26590. setFromCenterAndSize: function () {
  26591. var v1 = new Vector2();
  26592. return function setFromCenterAndSize( center, size ) {
  26593. var halfSize = v1.copy( size ).multiplyScalar( 0.5 );
  26594. this.min.copy( center ).sub( halfSize );
  26595. this.max.copy( center ).add( halfSize );
  26596. return this;
  26597. };
  26598. }(),
  26599. clone: function () {
  26600. return new this.constructor().copy( this );
  26601. },
  26602. copy: function ( box ) {
  26603. this.min.copy( box.min );
  26604. this.max.copy( box.max );
  26605. return this;
  26606. },
  26607. makeEmpty: function () {
  26608. this.min.x = this.min.y = + Infinity;
  26609. this.max.x = this.max.y = - Infinity;
  26610. return this;
  26611. },
  26612. isEmpty: function () {
  26613. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  26614. return ( this.max.x < this.min.x ) || ( this.max.y < this.min.y );
  26615. },
  26616. getCenter: function ( target ) {
  26617. if ( target === undefined ) {
  26618. console.warn( 'THREE.Box2: .getCenter() target is now required' );
  26619. target = new Vector2();
  26620. }
  26621. return this.isEmpty() ? target.set( 0, 0 ) : target.addVectors( this.min, this.max ).multiplyScalar( 0.5 );
  26622. },
  26623. getSize: function ( target ) {
  26624. if ( target === undefined ) {
  26625. console.warn( 'THREE.Box2: .getSize() target is now required' );
  26626. target = new Vector2();
  26627. }
  26628. return this.isEmpty() ? target.set( 0, 0 ) : target.subVectors( this.max, this.min );
  26629. },
  26630. expandByPoint: function ( point ) {
  26631. this.min.min( point );
  26632. this.max.max( point );
  26633. return this;
  26634. },
  26635. expandByVector: function ( vector ) {
  26636. this.min.sub( vector );
  26637. this.max.add( vector );
  26638. return this;
  26639. },
  26640. expandByScalar: function ( scalar ) {
  26641. this.min.addScalar( - scalar );
  26642. this.max.addScalar( scalar );
  26643. return this;
  26644. },
  26645. containsPoint: function ( point ) {
  26646. return point.x < this.min.x || point.x > this.max.x ||
  26647. point.y < this.min.y || point.y > this.max.y ? false : true;
  26648. },
  26649. containsBox: function ( box ) {
  26650. return this.min.x <= box.min.x && box.max.x <= this.max.x &&
  26651. this.min.y <= box.min.y && box.max.y <= this.max.y;
  26652. },
  26653. getParameter: function ( point, target ) {
  26654. // This can potentially have a divide by zero if the box
  26655. // has a size dimension of 0.
  26656. if ( target === undefined ) {
  26657. console.warn( 'THREE.Box2: .getParameter() target is now required' );
  26658. target = new Vector2();
  26659. }
  26660. return target.set(
  26661. ( point.x - this.min.x ) / ( this.max.x - this.min.x ),
  26662. ( point.y - this.min.y ) / ( this.max.y - this.min.y )
  26663. );
  26664. },
  26665. intersectsBox: function ( box ) {
  26666. // using 4 splitting planes to rule out intersections
  26667. return box.max.x < this.min.x || box.min.x > this.max.x ||
  26668. box.max.y < this.min.y || box.min.y > this.max.y ? false : true;
  26669. },
  26670. clampPoint: function ( point, target ) {
  26671. if ( target === undefined ) {
  26672. console.warn( 'THREE.Box2: .clampPoint() target is now required' );
  26673. target = new Vector2();
  26674. }
  26675. return target.copy( point ).clamp( this.min, this.max );
  26676. },
  26677. distanceToPoint: function () {
  26678. var v1 = new Vector2();
  26679. return function distanceToPoint( point ) {
  26680. var clampedPoint = v1.copy( point ).clamp( this.min, this.max );
  26681. return clampedPoint.sub( point ).length();
  26682. };
  26683. }(),
  26684. intersect: function ( box ) {
  26685. this.min.max( box.min );
  26686. this.max.min( box.max );
  26687. return this;
  26688. },
  26689. union: function ( box ) {
  26690. this.min.min( box.min );
  26691. this.max.max( box.max );
  26692. return this;
  26693. },
  26694. translate: function ( offset ) {
  26695. this.min.add( offset );
  26696. this.max.add( offset );
  26697. return this;
  26698. },
  26699. equals: function ( box ) {
  26700. return box.min.equals( this.min ) && box.max.equals( this.max );
  26701. }
  26702. } );
  26703. /**
  26704. * @author bhouston / http://clara.io
  26705. */
  26706. function Line3( start, end ) {
  26707. this.start = ( start !== undefined ) ? start : new Vector3();
  26708. this.end = ( end !== undefined ) ? end : new Vector3();
  26709. }
  26710. Object.assign( Line3.prototype, {
  26711. set: function ( start, end ) {
  26712. this.start.copy( start );
  26713. this.end.copy( end );
  26714. return this;
  26715. },
  26716. clone: function () {
  26717. return new this.constructor().copy( this );
  26718. },
  26719. copy: function ( line ) {
  26720. this.start.copy( line.start );
  26721. this.end.copy( line.end );
  26722. return this;
  26723. },
  26724. getCenter: function ( target ) {
  26725. if ( target === undefined ) {
  26726. console.warn( 'THREE.Line3: .getCenter() target is now required' );
  26727. target = new Vector3();
  26728. }
  26729. return target.addVectors( this.start, this.end ).multiplyScalar( 0.5 );
  26730. },
  26731. delta: function ( target ) {
  26732. if ( target === undefined ) {
  26733. console.warn( 'THREE.Line3: .delta() target is now required' );
  26734. target = new Vector3();
  26735. }
  26736. return target.subVectors( this.end, this.start );
  26737. },
  26738. distanceSq: function () {
  26739. return this.start.distanceToSquared( this.end );
  26740. },
  26741. distance: function () {
  26742. return this.start.distanceTo( this.end );
  26743. },
  26744. at: function ( t, target ) {
  26745. if ( target === undefined ) {
  26746. console.warn( 'THREE.Line3: .at() target is now required' );
  26747. target = new Vector3();
  26748. }
  26749. return this.delta( target ).multiplyScalar( t ).add( this.start );
  26750. },
  26751. closestPointToPointParameter: function () {
  26752. var startP = new Vector3();
  26753. var startEnd = new Vector3();
  26754. return function closestPointToPointParameter( point, clampToLine ) {
  26755. startP.subVectors( point, this.start );
  26756. startEnd.subVectors( this.end, this.start );
  26757. var startEnd2 = startEnd.dot( startEnd );
  26758. var startEnd_startP = startEnd.dot( startP );
  26759. var t = startEnd_startP / startEnd2;
  26760. if ( clampToLine ) {
  26761. t = _Math.clamp( t, 0, 1 );
  26762. }
  26763. return t;
  26764. };
  26765. }(),
  26766. closestPointToPoint: function ( point, clampToLine, target ) {
  26767. var t = this.closestPointToPointParameter( point, clampToLine );
  26768. if ( target === undefined ) {
  26769. console.warn( 'THREE.Line3: .closestPointToPoint() target is now required' );
  26770. target = new Vector3();
  26771. }
  26772. return this.delta( target ).multiplyScalar( t ).add( this.start );
  26773. },
  26774. applyMatrix4: function ( matrix ) {
  26775. this.start.applyMatrix4( matrix );
  26776. this.end.applyMatrix4( matrix );
  26777. return this;
  26778. },
  26779. equals: function ( line ) {
  26780. return line.start.equals( this.start ) && line.end.equals( this.end );
  26781. }
  26782. } );
  26783. /**
  26784. * @author alteredq / http://alteredqualia.com/
  26785. */
  26786. function ImmediateRenderObject( material ) {
  26787. Object3D.call( this );
  26788. this.material = material;
  26789. this.render = function ( /* renderCallback */ ) {};
  26790. }
  26791. ImmediateRenderObject.prototype = Object.create( Object3D.prototype );
  26792. ImmediateRenderObject.prototype.constructor = ImmediateRenderObject;
  26793. ImmediateRenderObject.prototype.isImmediateRenderObject = true;
  26794. /**
  26795. * @author mrdoob / http://mrdoob.com/
  26796. * @author WestLangley / http://github.com/WestLangley
  26797. */
  26798. function VertexNormalsHelper( object, size, hex, linewidth ) {
  26799. this.object = object;
  26800. this.size = ( size !== undefined ) ? size : 1;
  26801. var color = ( hex !== undefined ) ? hex : 0xff0000;
  26802. var width = ( linewidth !== undefined ) ? linewidth : 1;
  26803. //
  26804. var nNormals = 0;
  26805. var objGeometry = this.object.geometry;
  26806. if ( objGeometry && objGeometry.isGeometry ) {
  26807. nNormals = objGeometry.faces.length * 3;
  26808. } else if ( objGeometry && objGeometry.isBufferGeometry ) {
  26809. nNormals = objGeometry.attributes.normal.count;
  26810. }
  26811. //
  26812. var geometry = new BufferGeometry();
  26813. var positions = new Float32BufferAttribute( nNormals * 2 * 3, 3 );
  26814. geometry.addAttribute( 'position', positions );
  26815. LineSegments.call( this, geometry, new LineBasicMaterial( { color: color, linewidth: width } ) );
  26816. //
  26817. this.matrixAutoUpdate = false;
  26818. this.update();
  26819. }
  26820. VertexNormalsHelper.prototype = Object.create( LineSegments.prototype );
  26821. VertexNormalsHelper.prototype.constructor = VertexNormalsHelper;
  26822. VertexNormalsHelper.prototype.update = ( function () {
  26823. var v1 = new Vector3();
  26824. var v2 = new Vector3();
  26825. var normalMatrix = new Matrix3();
  26826. return function update() {
  26827. var keys = [ 'a', 'b', 'c' ];
  26828. this.object.updateMatrixWorld( true );
  26829. normalMatrix.getNormalMatrix( this.object.matrixWorld );
  26830. var matrixWorld = this.object.matrixWorld;
  26831. var position = this.geometry.attributes.position;
  26832. //
  26833. var objGeometry = this.object.geometry;
  26834. if ( objGeometry && objGeometry.isGeometry ) {
  26835. var vertices = objGeometry.vertices;
  26836. var faces = objGeometry.faces;
  26837. var idx = 0;
  26838. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  26839. var face = faces[ i ];
  26840. for ( var j = 0, jl = face.vertexNormals.length; j < jl; j ++ ) {
  26841. var vertex = vertices[ face[ keys[ j ] ] ];
  26842. var normal = face.vertexNormals[ j ];
  26843. v1.copy( vertex ).applyMatrix4( matrixWorld );
  26844. v2.copy( normal ).applyMatrix3( normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
  26845. position.setXYZ( idx, v1.x, v1.y, v1.z );
  26846. idx = idx + 1;
  26847. position.setXYZ( idx, v2.x, v2.y, v2.z );
  26848. idx = idx + 1;
  26849. }
  26850. }
  26851. } else if ( objGeometry && objGeometry.isBufferGeometry ) {
  26852. var objPos = objGeometry.attributes.position;
  26853. var objNorm = objGeometry.attributes.normal;
  26854. var idx = 0;
  26855. // for simplicity, ignore index and drawcalls, and render every normal
  26856. for ( var j = 0, jl = objPos.count; j < jl; j ++ ) {
  26857. v1.set( objPos.getX( j ), objPos.getY( j ), objPos.getZ( j ) ).applyMatrix4( matrixWorld );
  26858. v2.set( objNorm.getX( j ), objNorm.getY( j ), objNorm.getZ( j ) );
  26859. v2.applyMatrix3( normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
  26860. position.setXYZ( idx, v1.x, v1.y, v1.z );
  26861. idx = idx + 1;
  26862. position.setXYZ( idx, v2.x, v2.y, v2.z );
  26863. idx = idx + 1;
  26864. }
  26865. }
  26866. position.needsUpdate = true;
  26867. };
  26868. }() );
  26869. /**
  26870. * @author alteredq / http://alteredqualia.com/
  26871. * @author mrdoob / http://mrdoob.com/
  26872. * @author WestLangley / http://github.com/WestLangley
  26873. */
  26874. function SpotLightHelper( light, color ) {
  26875. Object3D.call( this );
  26876. this.light = light;
  26877. this.light.updateMatrixWorld();
  26878. this.matrix = light.matrixWorld;
  26879. this.matrixAutoUpdate = false;
  26880. this.color = color;
  26881. var geometry = new BufferGeometry();
  26882. var positions = [
  26883. 0, 0, 0, 0, 0, 1,
  26884. 0, 0, 0, 1, 0, 1,
  26885. 0, 0, 0, - 1, 0, 1,
  26886. 0, 0, 0, 0, 1, 1,
  26887. 0, 0, 0, 0, - 1, 1
  26888. ];
  26889. for ( var i = 0, j = 1, l = 32; i < l; i ++, j ++ ) {
  26890. var p1 = ( i / l ) * Math.PI * 2;
  26891. var p2 = ( j / l ) * Math.PI * 2;
  26892. positions.push(
  26893. Math.cos( p1 ), Math.sin( p1 ), 1,
  26894. Math.cos( p2 ), Math.sin( p2 ), 1
  26895. );
  26896. }
  26897. geometry.addAttribute( 'position', new Float32BufferAttribute( positions, 3 ) );
  26898. var material = new LineBasicMaterial( { fog: false } );
  26899. this.cone = new LineSegments( geometry, material );
  26900. this.add( this.cone );
  26901. this.update();
  26902. }
  26903. SpotLightHelper.prototype = Object.create( Object3D.prototype );
  26904. SpotLightHelper.prototype.constructor = SpotLightHelper;
  26905. SpotLightHelper.prototype.dispose = function () {
  26906. this.cone.geometry.dispose();
  26907. this.cone.material.dispose();
  26908. };
  26909. SpotLightHelper.prototype.update = function () {
  26910. var vector = new Vector3();
  26911. return function update() {
  26912. this.light.updateMatrixWorld();
  26913. var coneLength = this.light.distance ? this.light.distance : 1000;
  26914. var coneWidth = coneLength * Math.tan( this.light.angle );
  26915. this.cone.scale.set( coneWidth, coneWidth, coneLength );
  26916. vector.setFromMatrixPosition( this.light.target.matrixWorld );
  26917. this.cone.lookAt( vector );
  26918. if ( this.color !== undefined ) {
  26919. this.cone.material.color.set( this.color );
  26920. } else {
  26921. this.cone.material.color.copy( this.light.color );
  26922. }
  26923. };
  26924. }();
  26925. /**
  26926. * @author Sean Griffin / http://twitter.com/sgrif
  26927. * @author Michael Guerrero / http://realitymeltdown.com
  26928. * @author mrdoob / http://mrdoob.com/
  26929. * @author ikerr / http://verold.com
  26930. * @author Mugen87 / https://github.com/Mugen87
  26931. */
  26932. function getBoneList( object ) {
  26933. var boneList = [];
  26934. if ( object && object.isBone ) {
  26935. boneList.push( object );
  26936. }
  26937. for ( var i = 0; i < object.children.length; i ++ ) {
  26938. boneList.push.apply( boneList, getBoneList( object.children[ i ] ) );
  26939. }
  26940. return boneList;
  26941. }
  26942. function SkeletonHelper( object ) {
  26943. var bones = getBoneList( object );
  26944. var geometry = new BufferGeometry();
  26945. var vertices = [];
  26946. var colors = [];
  26947. var color1 = new Color( 0, 0, 1 );
  26948. var color2 = new Color( 0, 1, 0 );
  26949. for ( var i = 0; i < bones.length; i ++ ) {
  26950. var bone = bones[ i ];
  26951. if ( bone.parent && bone.parent.isBone ) {
  26952. vertices.push( 0, 0, 0 );
  26953. vertices.push( 0, 0, 0 );
  26954. colors.push( color1.r, color1.g, color1.b );
  26955. colors.push( color2.r, color2.g, color2.b );
  26956. }
  26957. }
  26958. geometry.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  26959. geometry.addAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  26960. var material = new LineBasicMaterial( { vertexColors: VertexColors, depthTest: false, depthWrite: false, transparent: true } );
  26961. LineSegments.call( this, geometry, material );
  26962. this.root = object;
  26963. this.bones = bones;
  26964. this.matrix = object.matrixWorld;
  26965. this.matrixAutoUpdate = false;
  26966. }
  26967. SkeletonHelper.prototype = Object.create( LineSegments.prototype );
  26968. SkeletonHelper.prototype.constructor = SkeletonHelper;
  26969. SkeletonHelper.prototype.updateMatrixWorld = function () {
  26970. var vector = new Vector3();
  26971. var boneMatrix = new Matrix4();
  26972. var matrixWorldInv = new Matrix4();
  26973. return function updateMatrixWorld( force ) {
  26974. var bones = this.bones;
  26975. var geometry = this.geometry;
  26976. var position = geometry.getAttribute( 'position' );
  26977. matrixWorldInv.getInverse( this.root.matrixWorld );
  26978. for ( var i = 0, j = 0; i < bones.length; i ++ ) {
  26979. var bone = bones[ i ];
  26980. if ( bone.parent && bone.parent.isBone ) {
  26981. boneMatrix.multiplyMatrices( matrixWorldInv, bone.matrixWorld );
  26982. vector.setFromMatrixPosition( boneMatrix );
  26983. position.setXYZ( j, vector.x, vector.y, vector.z );
  26984. boneMatrix.multiplyMatrices( matrixWorldInv, bone.parent.matrixWorld );
  26985. vector.setFromMatrixPosition( boneMatrix );
  26986. position.setXYZ( j + 1, vector.x, vector.y, vector.z );
  26987. j += 2;
  26988. }
  26989. }
  26990. geometry.getAttribute( 'position' ).needsUpdate = true;
  26991. Object3D.prototype.updateMatrixWorld.call( this, force );
  26992. };
  26993. }();
  26994. /**
  26995. * @author alteredq / http://alteredqualia.com/
  26996. * @author mrdoob / http://mrdoob.com/
  26997. */
  26998. function PointLightHelper( light, sphereSize, color ) {
  26999. this.light = light;
  27000. this.light.updateMatrixWorld();
  27001. this.color = color;
  27002. var geometry = new SphereBufferGeometry( sphereSize, 4, 2 );
  27003. var material = new MeshBasicMaterial( { wireframe: true, fog: false } );
  27004. Mesh.call( this, geometry, material );
  27005. this.matrix = this.light.matrixWorld;
  27006. this.matrixAutoUpdate = false;
  27007. this.update();
  27008. /*
  27009. var distanceGeometry = new THREE.IcosahedronBufferGeometry( 1, 2 );
  27010. var distanceMaterial = new THREE.MeshBasicMaterial( { color: hexColor, fog: false, wireframe: true, opacity: 0.1, transparent: true } );
  27011. this.lightSphere = new THREE.Mesh( bulbGeometry, bulbMaterial );
  27012. this.lightDistance = new THREE.Mesh( distanceGeometry, distanceMaterial );
  27013. var d = light.distance;
  27014. if ( d === 0.0 ) {
  27015. this.lightDistance.visible = false;
  27016. } else {
  27017. this.lightDistance.scale.set( d, d, d );
  27018. }
  27019. this.add( this.lightDistance );
  27020. */
  27021. }
  27022. PointLightHelper.prototype = Object.create( Mesh.prototype );
  27023. PointLightHelper.prototype.constructor = PointLightHelper;
  27024. PointLightHelper.prototype.dispose = function () {
  27025. this.geometry.dispose();
  27026. this.material.dispose();
  27027. };
  27028. PointLightHelper.prototype.update = function () {
  27029. if ( this.color !== undefined ) {
  27030. this.material.color.set( this.color );
  27031. } else {
  27032. this.material.color.copy( this.light.color );
  27033. }
  27034. /*
  27035. var d = this.light.distance;
  27036. if ( d === 0.0 ) {
  27037. this.lightDistance.visible = false;
  27038. } else {
  27039. this.lightDistance.visible = true;
  27040. this.lightDistance.scale.set( d, d, d );
  27041. }
  27042. */
  27043. };
  27044. /**
  27045. * @author abelnation / http://github.com/abelnation
  27046. * @author Mugen87 / http://github.com/Mugen87
  27047. * @author WestLangley / http://github.com/WestLangley
  27048. *
  27049. * This helper must be added as a child of the light
  27050. */
  27051. function RectAreaLightHelper( light, color ) {
  27052. this.type = 'RectAreaLightHelper';
  27053. this.light = light;
  27054. this.color = color; // optional hardwired color for the helper
  27055. var positions = [ 1, 1, 0, - 1, 1, 0, - 1, - 1, 0, 1, - 1, 0, 1, 1, 0 ];
  27056. var geometry = new BufferGeometry();
  27057. geometry.addAttribute( 'position', new Float32BufferAttribute( positions, 3 ) );
  27058. geometry.computeBoundingSphere();
  27059. var material = new LineBasicMaterial( { fog: false } );
  27060. Line.call( this, geometry, material );
  27061. //
  27062. var positions2 = [ 1, 1, 0, - 1, 1, 0, - 1, - 1, 0, 1, 1, 0, - 1, - 1, 0, 1, - 1, 0 ];
  27063. var geometry2 = new BufferGeometry();
  27064. geometry2.addAttribute( 'position', new Float32BufferAttribute( positions2, 3 ) );
  27065. geometry2.computeBoundingSphere();
  27066. this.add( new Mesh( geometry2, new MeshBasicMaterial( { side: BackSide, fog: false } ) ) );
  27067. this.update();
  27068. }
  27069. RectAreaLightHelper.prototype = Object.create( Line.prototype );
  27070. RectAreaLightHelper.prototype.constructor = RectAreaLightHelper;
  27071. RectAreaLightHelper.prototype.update = function () {
  27072. this.scale.set( 0.5 * this.light.width, 0.5 * this.light.height, 1 );
  27073. if ( this.color !== undefined ) {
  27074. this.material.color.set( this.color );
  27075. this.children[ 0 ].material.color.set( this.color );
  27076. } else {
  27077. this.material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  27078. // prevent hue shift
  27079. var c = this.material.color;
  27080. var max = Math.max( c.r, c.g, c.b );
  27081. if ( max > 1 ) c.multiplyScalar( 1 / max );
  27082. this.children[ 0 ].material.color.copy( this.material.color );
  27083. }
  27084. };
  27085. RectAreaLightHelper.prototype.dispose = function () {
  27086. this.geometry.dispose();
  27087. this.material.dispose();
  27088. this.children[ 0 ].geometry.dispose();
  27089. this.children[ 0 ].material.dispose();
  27090. };
  27091. /**
  27092. * @author alteredq / http://alteredqualia.com/
  27093. * @author mrdoob / http://mrdoob.com/
  27094. * @author Mugen87 / https://github.com/Mugen87
  27095. */
  27096. function HemisphereLightHelper( light, size, color ) {
  27097. Object3D.call( this );
  27098. this.light = light;
  27099. this.light.updateMatrixWorld();
  27100. this.matrix = light.matrixWorld;
  27101. this.matrixAutoUpdate = false;
  27102. this.color = color;
  27103. var geometry = new OctahedronBufferGeometry( size );
  27104. geometry.rotateY( Math.PI * 0.5 );
  27105. this.material = new MeshBasicMaterial( { wireframe: true, fog: false } );
  27106. if ( this.color === undefined ) this.material.vertexColors = VertexColors;
  27107. var position = geometry.getAttribute( 'position' );
  27108. var colors = new Float32Array( position.count * 3 );
  27109. geometry.addAttribute( 'color', new BufferAttribute( colors, 3 ) );
  27110. this.add( new Mesh( geometry, this.material ) );
  27111. this.update();
  27112. }
  27113. HemisphereLightHelper.prototype = Object.create( Object3D.prototype );
  27114. HemisphereLightHelper.prototype.constructor = HemisphereLightHelper;
  27115. HemisphereLightHelper.prototype.dispose = function () {
  27116. this.children[ 0 ].geometry.dispose();
  27117. this.children[ 0 ].material.dispose();
  27118. };
  27119. HemisphereLightHelper.prototype.update = function () {
  27120. var vector = new Vector3();
  27121. var color1 = new Color();
  27122. var color2 = new Color();
  27123. return function update() {
  27124. var mesh = this.children[ 0 ];
  27125. if ( this.color !== undefined ) {
  27126. this.material.color.set( this.color );
  27127. } else {
  27128. var colors = mesh.geometry.getAttribute( 'color' );
  27129. color1.copy( this.light.color );
  27130. color2.copy( this.light.groundColor );
  27131. for ( var i = 0, l = colors.count; i < l; i ++ ) {
  27132. var color = ( i < ( l / 2 ) ) ? color1 : color2;
  27133. colors.setXYZ( i, color.r, color.g, color.b );
  27134. }
  27135. colors.needsUpdate = true;
  27136. }
  27137. mesh.lookAt( vector.setFromMatrixPosition( this.light.matrixWorld ).negate() );
  27138. };
  27139. }();
  27140. /**
  27141. * @author WestLangley / http://github.com/WestLangley
  27142. */
  27143. function LightProbeHelper( lightProbe, size ) {
  27144. this.lightProbe = lightProbe;
  27145. this.size = size;
  27146. var defines = {};
  27147. defines[ 'GAMMA_OUTPUT' ] = "";
  27148. // material
  27149. var material = new ShaderMaterial( {
  27150. defines: defines,
  27151. uniforms: {
  27152. sh: { value: this.lightProbe.sh.coefficients }, // by reference
  27153. intensity: { value: this.lightProbe.intensity }
  27154. },
  27155. vertexShader: [
  27156. 'varying vec3 vNormal;',
  27157. 'void main() {',
  27158. ' vNormal = normalize( normalMatrix * normal );',
  27159. ' gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );',
  27160. '}',
  27161. ].join( '\n' ),
  27162. fragmentShader: [
  27163. '#define RECIPROCAL_PI 0.318309886',
  27164. 'vec3 inverseTransformDirection( in vec3 normal, in mat4 matrix ) {',
  27165. ' // matrix is assumed to be orthogonal',
  27166. ' return normalize( ( vec4( normal, 0.0 ) * matrix ).xyz );',
  27167. '}',
  27168. 'vec3 linearToOutput( in vec3 a ) {',
  27169. ' #ifdef GAMMA_OUTPUT',
  27170. ' return pow( a, vec3( 1.0 / float( GAMMA_FACTOR ) ) );',
  27171. ' #else',
  27172. ' return a;',
  27173. ' #endif',
  27174. '}',
  27175. '// source: https://graphics.stanford.edu/papers/envmap/envmap.pdf',
  27176. 'vec3 shGetIrradianceAt( in vec3 normal, in vec3 shCoefficients[ 9 ] ) {',
  27177. ' // normal is assumed to have unit length',
  27178. ' float x = normal.x, y = normal.y, z = normal.z;',
  27179. ' // band 0',
  27180. ' vec3 result = shCoefficients[ 0 ] * 0.886227;',
  27181. ' // band 1',
  27182. ' result += shCoefficients[ 1 ] * 2.0 * 0.511664 * y;',
  27183. ' result += shCoefficients[ 2 ] * 2.0 * 0.511664 * z;',
  27184. ' result += shCoefficients[ 3 ] * 2.0 * 0.511664 * x;',
  27185. ' // band 2',
  27186. ' result += shCoefficients[ 4 ] * 2.0 * 0.429043 * x * y;',
  27187. ' result += shCoefficients[ 5 ] * 2.0 * 0.429043 * y * z;',
  27188. ' result += shCoefficients[ 6 ] * ( 0.743125 * z * z - 0.247708 );',
  27189. ' result += shCoefficients[ 7 ] * 2.0 * 0.429043 * x * z;',
  27190. ' result += shCoefficients[ 8 ] * 0.429043 * ( x * x - y * y );',
  27191. ' return result;',
  27192. '}',
  27193. 'uniform vec3 sh[ 9 ]; // sh coefficients',
  27194. 'uniform float intensity; // light probe intensity',
  27195. 'varying vec3 vNormal;',
  27196. 'void main() {',
  27197. ' vec3 normal = normalize( vNormal );',
  27198. ' vec3 worldNormal = inverseTransformDirection( normal, viewMatrix );',
  27199. ' vec3 irradiance = shGetIrradianceAt( worldNormal, sh );',
  27200. ' vec3 outgoingLight = RECIPROCAL_PI * irradiance * intensity;',
  27201. ' outgoingLight = linearToOutput( outgoingLight );',
  27202. ' gl_FragColor = vec4( outgoingLight, 1.0 );',
  27203. '}'
  27204. ].join( '\n' )
  27205. } );
  27206. var geometry = new SphereBufferGeometry( 1, 32, 16 );
  27207. Mesh.call( this, geometry, material );
  27208. this.onBeforeRender();
  27209. }
  27210. LightProbeHelper.prototype = Object.create( Mesh.prototype );
  27211. LightProbeHelper.prototype.constructor = LightProbeHelper;
  27212. LightProbeHelper.prototype.dispose = function () {
  27213. this.geometry.dispose();
  27214. this.material.dispose();
  27215. };
  27216. LightProbeHelper.prototype.onBeforeRender = function () {
  27217. return function update() {
  27218. this.position.copy( this.lightProbe.position );
  27219. this.scale.set( 1, 1, 1 ).multiplyScalar( this.size );
  27220. this.material.uniforms.intensity.value = this.lightProbe.intensity;
  27221. };
  27222. }();
  27223. /**
  27224. * @author mrdoob / http://mrdoob.com/
  27225. */
  27226. function GridHelper( size, divisions, color1, color2 ) {
  27227. size = size || 10;
  27228. divisions = divisions || 10;
  27229. color1 = new Color( color1 !== undefined ? color1 : 0x444444 );
  27230. color2 = new Color( color2 !== undefined ? color2 : 0x888888 );
  27231. var center = divisions / 2;
  27232. var step = size / divisions;
  27233. var halfSize = size / 2;
  27234. var vertices = [], colors = [];
  27235. for ( var i = 0, j = 0, k = - halfSize; i <= divisions; i ++, k += step ) {
  27236. vertices.push( - halfSize, 0, k, halfSize, 0, k );
  27237. vertices.push( k, 0, - halfSize, k, 0, halfSize );
  27238. var color = i === center ? color1 : color2;
  27239. color.toArray( colors, j ); j += 3;
  27240. color.toArray( colors, j ); j += 3;
  27241. color.toArray( colors, j ); j += 3;
  27242. color.toArray( colors, j ); j += 3;
  27243. }
  27244. var geometry = new BufferGeometry();
  27245. geometry.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  27246. geometry.addAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  27247. var material = new LineBasicMaterial( { vertexColors: VertexColors } );
  27248. LineSegments.call( this, geometry, material );
  27249. }
  27250. GridHelper.prototype = Object.assign( Object.create( LineSegments.prototype ), {
  27251. constructor: GridHelper,
  27252. copy: function ( source ) {
  27253. LineSegments.prototype.copy.call( this, source );
  27254. this.geometry.copy( source.geometry );
  27255. this.material.copy( source.material );
  27256. return this;
  27257. },
  27258. clone: function () {
  27259. return new this.constructor().copy( this );
  27260. }
  27261. } );
  27262. /**
  27263. * @author mrdoob / http://mrdoob.com/
  27264. * @author Mugen87 / http://github.com/Mugen87
  27265. * @author Hectate / http://www.github.com/Hectate
  27266. */
  27267. function PolarGridHelper( radius, radials, circles, divisions, color1, color2 ) {
  27268. radius = radius || 10;
  27269. radials = radials || 16;
  27270. circles = circles || 8;
  27271. divisions = divisions || 64;
  27272. color1 = new Color( color1 !== undefined ? color1 : 0x444444 );
  27273. color2 = new Color( color2 !== undefined ? color2 : 0x888888 );
  27274. var vertices = [];
  27275. var colors = [];
  27276. var x, z;
  27277. var v, i, j, r, color;
  27278. // create the radials
  27279. for ( i = 0; i <= radials; i ++ ) {
  27280. v = ( i / radials ) * ( Math.PI * 2 );
  27281. x = Math.sin( v ) * radius;
  27282. z = Math.cos( v ) * radius;
  27283. vertices.push( 0, 0, 0 );
  27284. vertices.push( x, 0, z );
  27285. color = ( i & 1 ) ? color1 : color2;
  27286. colors.push( color.r, color.g, color.b );
  27287. colors.push( color.r, color.g, color.b );
  27288. }
  27289. // create the circles
  27290. for ( i = 0; i <= circles; i ++ ) {
  27291. color = ( i & 1 ) ? color1 : color2;
  27292. r = radius - ( radius / circles * i );
  27293. for ( j = 0; j < divisions; j ++ ) {
  27294. // first vertex
  27295. v = ( j / divisions ) * ( Math.PI * 2 );
  27296. x = Math.sin( v ) * r;
  27297. z = Math.cos( v ) * r;
  27298. vertices.push( x, 0, z );
  27299. colors.push( color.r, color.g, color.b );
  27300. // second vertex
  27301. v = ( ( j + 1 ) / divisions ) * ( Math.PI * 2 );
  27302. x = Math.sin( v ) * r;
  27303. z = Math.cos( v ) * r;
  27304. vertices.push( x, 0, z );
  27305. colors.push( color.r, color.g, color.b );
  27306. }
  27307. }
  27308. var geometry = new BufferGeometry();
  27309. geometry.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  27310. geometry.addAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  27311. var material = new LineBasicMaterial( { vertexColors: VertexColors } );
  27312. LineSegments.call( this, geometry, material );
  27313. }
  27314. PolarGridHelper.prototype = Object.create( LineSegments.prototype );
  27315. PolarGridHelper.prototype.constructor = PolarGridHelper;
  27316. /**
  27317. * @author Mugen87 / http://github.com/Mugen87
  27318. */
  27319. function PositionalAudioHelper( audio, range, divisionsInnerAngle, divisionsOuterAngle ) {
  27320. this.audio = audio;
  27321. this.range = range || 1;
  27322. this.divisionsInnerAngle = divisionsInnerAngle || 16;
  27323. this.divisionsOuterAngle = divisionsOuterAngle || 2;
  27324. var geometry = new BufferGeometry();
  27325. var divisions = this.divisionsInnerAngle + this.divisionsOuterAngle * 2;
  27326. var positions = new Float32Array( ( divisions * 3 + 3 ) * 3 );
  27327. geometry.addAttribute( 'position', new BufferAttribute( positions, 3 ) );
  27328. var materialInnerAngle = new LineBasicMaterial( { color: 0x00ff00 } );
  27329. var materialOuterAngle = new LineBasicMaterial( { color: 0xffff00 } );
  27330. Line.call( this, geometry, [ materialOuterAngle, materialInnerAngle ] );
  27331. this.update();
  27332. }
  27333. PositionalAudioHelper.prototype = Object.create( Line.prototype );
  27334. PositionalAudioHelper.prototype.constructor = PositionalAudioHelper;
  27335. PositionalAudioHelper.prototype.update = function () {
  27336. var audio = this.audio;
  27337. var range = this.range;
  27338. var divisionsInnerAngle = this.divisionsInnerAngle;
  27339. var divisionsOuterAngle = this.divisionsOuterAngle;
  27340. var coneInnerAngle = _Math.degToRad( audio.panner.coneInnerAngle );
  27341. var coneOuterAngle = _Math.degToRad( audio.panner.coneOuterAngle );
  27342. var halfConeInnerAngle = coneInnerAngle / 2;
  27343. var halfConeOuterAngle = coneOuterAngle / 2;
  27344. var start = 0;
  27345. var count = 0;
  27346. var i, stride;
  27347. var geometry = this.geometry;
  27348. var positionAttribute = geometry.attributes.position;
  27349. geometry.clearGroups();
  27350. //
  27351. function generateSegment( from, to, divisions, materialIndex ) {
  27352. var step = ( to - from ) / divisions;
  27353. positionAttribute.setXYZ( start, 0, 0, 0 );
  27354. count ++;
  27355. for ( i = from; i < to; i += step ) {
  27356. stride = start + count;
  27357. positionAttribute.setXYZ( stride, Math.sin( i ) * range, 0, Math.cos( i ) * range );
  27358. positionAttribute.setXYZ( stride + 1, Math.sin( Math.min( i + step, to ) ) * range, 0, Math.cos( Math.min( i + step, to ) ) * range );
  27359. positionAttribute.setXYZ( stride + 2, 0, 0, 0 );
  27360. count += 3;
  27361. }
  27362. geometry.addGroup( start, count, materialIndex );
  27363. start += count;
  27364. count = 0;
  27365. }
  27366. //
  27367. generateSegment( - halfConeOuterAngle, - halfConeInnerAngle, divisionsOuterAngle, 0 );
  27368. generateSegment( - halfConeInnerAngle, halfConeInnerAngle, divisionsInnerAngle, 1 );
  27369. generateSegment( halfConeInnerAngle, halfConeOuterAngle, divisionsOuterAngle, 0 );
  27370. //
  27371. positionAttribute.needsUpdate = true;
  27372. if ( coneInnerAngle === coneOuterAngle ) this.material[ 0 ].visible = false;
  27373. };
  27374. PositionalAudioHelper.prototype.dispose = function () {
  27375. this.geometry.dispose();
  27376. this.material[ 0 ].dispose();
  27377. this.material[ 1 ].dispose();
  27378. };
  27379. /**
  27380. * @author mrdoob / http://mrdoob.com/
  27381. * @author WestLangley / http://github.com/WestLangley
  27382. */
  27383. function FaceNormalsHelper( object, size, hex, linewidth ) {
  27384. // FaceNormalsHelper only supports THREE.Geometry
  27385. this.object = object;
  27386. this.size = ( size !== undefined ) ? size : 1;
  27387. var color = ( hex !== undefined ) ? hex : 0xffff00;
  27388. var width = ( linewidth !== undefined ) ? linewidth : 1;
  27389. //
  27390. var nNormals = 0;
  27391. var objGeometry = this.object.geometry;
  27392. if ( objGeometry && objGeometry.isGeometry ) {
  27393. nNormals = objGeometry.faces.length;
  27394. } else {
  27395. console.warn( 'THREE.FaceNormalsHelper: only THREE.Geometry is supported. Use THREE.VertexNormalsHelper, instead.' );
  27396. }
  27397. //
  27398. var geometry = new BufferGeometry();
  27399. var positions = new Float32BufferAttribute( nNormals * 2 * 3, 3 );
  27400. geometry.addAttribute( 'position', positions );
  27401. LineSegments.call( this, geometry, new LineBasicMaterial( { color: color, linewidth: width } ) );
  27402. //
  27403. this.matrixAutoUpdate = false;
  27404. this.update();
  27405. }
  27406. FaceNormalsHelper.prototype = Object.create( LineSegments.prototype );
  27407. FaceNormalsHelper.prototype.constructor = FaceNormalsHelper;
  27408. FaceNormalsHelper.prototype.update = ( function () {
  27409. var v1 = new Vector3();
  27410. var v2 = new Vector3();
  27411. var normalMatrix = new Matrix3();
  27412. return function update() {
  27413. this.object.updateMatrixWorld( true );
  27414. normalMatrix.getNormalMatrix( this.object.matrixWorld );
  27415. var matrixWorld = this.object.matrixWorld;
  27416. var position = this.geometry.attributes.position;
  27417. //
  27418. var objGeometry = this.object.geometry;
  27419. var vertices = objGeometry.vertices;
  27420. var faces = objGeometry.faces;
  27421. var idx = 0;
  27422. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  27423. var face = faces[ i ];
  27424. var normal = face.normal;
  27425. v1.copy( vertices[ face.a ] )
  27426. .add( vertices[ face.b ] )
  27427. .add( vertices[ face.c ] )
  27428. .divideScalar( 3 )
  27429. .applyMatrix4( matrixWorld );
  27430. v2.copy( normal ).applyMatrix3( normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
  27431. position.setXYZ( idx, v1.x, v1.y, v1.z );
  27432. idx = idx + 1;
  27433. position.setXYZ( idx, v2.x, v2.y, v2.z );
  27434. idx = idx + 1;
  27435. }
  27436. position.needsUpdate = true;
  27437. };
  27438. }() );
  27439. /**
  27440. * @author alteredq / http://alteredqualia.com/
  27441. * @author mrdoob / http://mrdoob.com/
  27442. * @author WestLangley / http://github.com/WestLangley
  27443. */
  27444. function DirectionalLightHelper( light, size, color ) {
  27445. Object3D.call( this );
  27446. this.light = light;
  27447. this.light.updateMatrixWorld();
  27448. this.matrix = light.matrixWorld;
  27449. this.matrixAutoUpdate = false;
  27450. this.color = color;
  27451. if ( size === undefined ) size = 1;
  27452. var geometry = new BufferGeometry();
  27453. geometry.addAttribute( 'position', new Float32BufferAttribute( [
  27454. - size, size, 0,
  27455. size, size, 0,
  27456. size, - size, 0,
  27457. - size, - size, 0,
  27458. - size, size, 0
  27459. ], 3 ) );
  27460. var material = new LineBasicMaterial( { fog: false } );
  27461. this.lightPlane = new Line( geometry, material );
  27462. this.add( this.lightPlane );
  27463. geometry = new BufferGeometry();
  27464. geometry.addAttribute( 'position', new Float32BufferAttribute( [ 0, 0, 0, 0, 0, 1 ], 3 ) );
  27465. this.targetLine = new Line( geometry, material );
  27466. this.add( this.targetLine );
  27467. this.update();
  27468. }
  27469. DirectionalLightHelper.prototype = Object.create( Object3D.prototype );
  27470. DirectionalLightHelper.prototype.constructor = DirectionalLightHelper;
  27471. DirectionalLightHelper.prototype.dispose = function () {
  27472. this.lightPlane.geometry.dispose();
  27473. this.lightPlane.material.dispose();
  27474. this.targetLine.geometry.dispose();
  27475. this.targetLine.material.dispose();
  27476. };
  27477. DirectionalLightHelper.prototype.update = function () {
  27478. var v1 = new Vector3();
  27479. var v2 = new Vector3();
  27480. var v3 = new Vector3();
  27481. return function update() {
  27482. v1.setFromMatrixPosition( this.light.matrixWorld );
  27483. v2.setFromMatrixPosition( this.light.target.matrixWorld );
  27484. v3.subVectors( v2, v1 );
  27485. this.lightPlane.lookAt( v2 );
  27486. if ( this.color !== undefined ) {
  27487. this.lightPlane.material.color.set( this.color );
  27488. this.targetLine.material.color.set( this.color );
  27489. } else {
  27490. this.lightPlane.material.color.copy( this.light.color );
  27491. this.targetLine.material.color.copy( this.light.color );
  27492. }
  27493. this.targetLine.lookAt( v2 );
  27494. this.targetLine.scale.z = v3.length();
  27495. };
  27496. }();
  27497. /**
  27498. * @author alteredq / http://alteredqualia.com/
  27499. * @author Mugen87 / https://github.com/Mugen87
  27500. *
  27501. * - shows frustum, line of sight and up of the camera
  27502. * - suitable for fast updates
  27503. * - based on frustum visualization in lightgl.js shadowmap example
  27504. * http://evanw.github.com/lightgl.js/tests/shadowmap.html
  27505. */
  27506. function CameraHelper( camera ) {
  27507. var geometry = new BufferGeometry();
  27508. var material = new LineBasicMaterial( { color: 0xffffff, vertexColors: FaceColors } );
  27509. var vertices = [];
  27510. var colors = [];
  27511. var pointMap = {};
  27512. // colors
  27513. var colorFrustum = new Color( 0xffaa00 );
  27514. var colorCone = new Color( 0xff0000 );
  27515. var colorUp = new Color( 0x00aaff );
  27516. var colorTarget = new Color( 0xffffff );
  27517. var colorCross = new Color( 0x333333 );
  27518. // near
  27519. addLine( 'n1', 'n2', colorFrustum );
  27520. addLine( 'n2', 'n4', colorFrustum );
  27521. addLine( 'n4', 'n3', colorFrustum );
  27522. addLine( 'n3', 'n1', colorFrustum );
  27523. // far
  27524. addLine( 'f1', 'f2', colorFrustum );
  27525. addLine( 'f2', 'f4', colorFrustum );
  27526. addLine( 'f4', 'f3', colorFrustum );
  27527. addLine( 'f3', 'f1', colorFrustum );
  27528. // sides
  27529. addLine( 'n1', 'f1', colorFrustum );
  27530. addLine( 'n2', 'f2', colorFrustum );
  27531. addLine( 'n3', 'f3', colorFrustum );
  27532. addLine( 'n4', 'f4', colorFrustum );
  27533. // cone
  27534. addLine( 'p', 'n1', colorCone );
  27535. addLine( 'p', 'n2', colorCone );
  27536. addLine( 'p', 'n3', colorCone );
  27537. addLine( 'p', 'n4', colorCone );
  27538. // up
  27539. addLine( 'u1', 'u2', colorUp );
  27540. addLine( 'u2', 'u3', colorUp );
  27541. addLine( 'u3', 'u1', colorUp );
  27542. // target
  27543. addLine( 'c', 't', colorTarget );
  27544. addLine( 'p', 'c', colorCross );
  27545. // cross
  27546. addLine( 'cn1', 'cn2', colorCross );
  27547. addLine( 'cn3', 'cn4', colorCross );
  27548. addLine( 'cf1', 'cf2', colorCross );
  27549. addLine( 'cf3', 'cf4', colorCross );
  27550. function addLine( a, b, color ) {
  27551. addPoint( a, color );
  27552. addPoint( b, color );
  27553. }
  27554. function addPoint( id, color ) {
  27555. vertices.push( 0, 0, 0 );
  27556. colors.push( color.r, color.g, color.b );
  27557. if ( pointMap[ id ] === undefined ) {
  27558. pointMap[ id ] = [];
  27559. }
  27560. pointMap[ id ].push( ( vertices.length / 3 ) - 1 );
  27561. }
  27562. geometry.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  27563. geometry.addAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  27564. LineSegments.call( this, geometry, material );
  27565. this.camera = camera;
  27566. if ( this.camera.updateProjectionMatrix ) this.camera.updateProjectionMatrix();
  27567. this.matrix = camera.matrixWorld;
  27568. this.matrixAutoUpdate = false;
  27569. this.pointMap = pointMap;
  27570. this.update();
  27571. }
  27572. CameraHelper.prototype = Object.create( LineSegments.prototype );
  27573. CameraHelper.prototype.constructor = CameraHelper;
  27574. CameraHelper.prototype.update = function () {
  27575. var geometry, pointMap;
  27576. var vector = new Vector3();
  27577. var camera = new Camera();
  27578. function setPoint( point, x, y, z ) {
  27579. vector.set( x, y, z ).unproject( camera );
  27580. var points = pointMap[ point ];
  27581. if ( points !== undefined ) {
  27582. var position = geometry.getAttribute( 'position' );
  27583. for ( var i = 0, l = points.length; i < l; i ++ ) {
  27584. position.setXYZ( points[ i ], vector.x, vector.y, vector.z );
  27585. }
  27586. }
  27587. }
  27588. return function update() {
  27589. geometry = this.geometry;
  27590. pointMap = this.pointMap;
  27591. var w = 1, h = 1;
  27592. // we need just camera projection matrix inverse
  27593. // world matrix must be identity
  27594. camera.projectionMatrixInverse.copy( this.camera.projectionMatrixInverse );
  27595. // center / target
  27596. setPoint( 'c', 0, 0, - 1 );
  27597. setPoint( 't', 0, 0, 1 );
  27598. // near
  27599. setPoint( 'n1', - w, - h, - 1 );
  27600. setPoint( 'n2', w, - h, - 1 );
  27601. setPoint( 'n3', - w, h, - 1 );
  27602. setPoint( 'n4', w, h, - 1 );
  27603. // far
  27604. setPoint( 'f1', - w, - h, 1 );
  27605. setPoint( 'f2', w, - h, 1 );
  27606. setPoint( 'f3', - w, h, 1 );
  27607. setPoint( 'f4', w, h, 1 );
  27608. // up
  27609. setPoint( 'u1', w * 0.7, h * 1.1, - 1 );
  27610. setPoint( 'u2', - w * 0.7, h * 1.1, - 1 );
  27611. setPoint( 'u3', 0, h * 2, - 1 );
  27612. // cross
  27613. setPoint( 'cf1', - w, 0, 1 );
  27614. setPoint( 'cf2', w, 0, 1 );
  27615. setPoint( 'cf3', 0, - h, 1 );
  27616. setPoint( 'cf4', 0, h, 1 );
  27617. setPoint( 'cn1', - w, 0, - 1 );
  27618. setPoint( 'cn2', w, 0, - 1 );
  27619. setPoint( 'cn3', 0, - h, - 1 );
  27620. setPoint( 'cn4', 0, h, - 1 );
  27621. geometry.getAttribute( 'position' ).needsUpdate = true;
  27622. };
  27623. }();
  27624. /**
  27625. * @author mrdoob / http://mrdoob.com/
  27626. * @author Mugen87 / http://github.com/Mugen87
  27627. */
  27628. function BoxHelper( object, color ) {
  27629. this.object = object;
  27630. if ( color === undefined ) color = 0xffff00;
  27631. 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 ] );
  27632. var positions = new Float32Array( 8 * 3 );
  27633. var geometry = new BufferGeometry();
  27634. geometry.setIndex( new BufferAttribute( indices, 1 ) );
  27635. geometry.addAttribute( 'position', new BufferAttribute( positions, 3 ) );
  27636. LineSegments.call( this, geometry, new LineBasicMaterial( { color: color } ) );
  27637. this.matrixAutoUpdate = false;
  27638. this.update();
  27639. }
  27640. BoxHelper.prototype = Object.create( LineSegments.prototype );
  27641. BoxHelper.prototype.constructor = BoxHelper;
  27642. BoxHelper.prototype.update = ( function () {
  27643. var box = new Box3();
  27644. return function update( object ) {
  27645. if ( object !== undefined ) {
  27646. console.warn( 'THREE.BoxHelper: .update() has no longer arguments.' );
  27647. }
  27648. if ( this.object !== undefined ) {
  27649. box.setFromObject( this.object );
  27650. }
  27651. if ( box.isEmpty() ) return;
  27652. var min = box.min;
  27653. var max = box.max;
  27654. /*
  27655. 5____4
  27656. 1/___0/|
  27657. | 6__|_7
  27658. 2/___3/
  27659. 0: max.x, max.y, max.z
  27660. 1: min.x, max.y, max.z
  27661. 2: min.x, min.y, max.z
  27662. 3: max.x, min.y, max.z
  27663. 4: max.x, max.y, min.z
  27664. 5: min.x, max.y, min.z
  27665. 6: min.x, min.y, min.z
  27666. 7: max.x, min.y, min.z
  27667. */
  27668. var position = this.geometry.attributes.position;
  27669. var array = position.array;
  27670. array[ 0 ] = max.x; array[ 1 ] = max.y; array[ 2 ] = max.z;
  27671. array[ 3 ] = min.x; array[ 4 ] = max.y; array[ 5 ] = max.z;
  27672. array[ 6 ] = min.x; array[ 7 ] = min.y; array[ 8 ] = max.z;
  27673. array[ 9 ] = max.x; array[ 10 ] = min.y; array[ 11 ] = max.z;
  27674. array[ 12 ] = max.x; array[ 13 ] = max.y; array[ 14 ] = min.z;
  27675. array[ 15 ] = min.x; array[ 16 ] = max.y; array[ 17 ] = min.z;
  27676. array[ 18 ] = min.x; array[ 19 ] = min.y; array[ 20 ] = min.z;
  27677. array[ 21 ] = max.x; array[ 22 ] = min.y; array[ 23 ] = min.z;
  27678. position.needsUpdate = true;
  27679. this.geometry.computeBoundingSphere();
  27680. };
  27681. } )();
  27682. BoxHelper.prototype.setFromObject = function ( object ) {
  27683. this.object = object;
  27684. this.update();
  27685. return this;
  27686. };
  27687. BoxHelper.prototype.copy = function ( source ) {
  27688. LineSegments.prototype.copy.call( this, source );
  27689. this.object = source.object;
  27690. return this;
  27691. };
  27692. BoxHelper.prototype.clone = function () {
  27693. return new this.constructor().copy( this );
  27694. };
  27695. /**
  27696. * @author WestLangley / http://github.com/WestLangley
  27697. */
  27698. function Box3Helper( box, hex ) {
  27699. this.type = 'Box3Helper';
  27700. this.box = box;
  27701. var color = ( hex !== undefined ) ? hex : 0xffff00;
  27702. 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 ] );
  27703. 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 ];
  27704. var geometry = new BufferGeometry();
  27705. geometry.setIndex( new BufferAttribute( indices, 1 ) );
  27706. geometry.addAttribute( 'position', new Float32BufferAttribute( positions, 3 ) );
  27707. LineSegments.call( this, geometry, new LineBasicMaterial( { color: color } ) );
  27708. this.geometry.computeBoundingSphere();
  27709. }
  27710. Box3Helper.prototype = Object.create( LineSegments.prototype );
  27711. Box3Helper.prototype.constructor = Box3Helper;
  27712. Box3Helper.prototype.updateMatrixWorld = function ( force ) {
  27713. var box = this.box;
  27714. if ( box.isEmpty() ) return;
  27715. box.getCenter( this.position );
  27716. box.getSize( this.scale );
  27717. this.scale.multiplyScalar( 0.5 );
  27718. Object3D.prototype.updateMatrixWorld.call( this, force );
  27719. };
  27720. /**
  27721. * @author WestLangley / http://github.com/WestLangley
  27722. */
  27723. function PlaneHelper( plane, size, hex ) {
  27724. this.type = 'PlaneHelper';
  27725. this.plane = plane;
  27726. this.size = ( size === undefined ) ? 1 : size;
  27727. var color = ( hex !== undefined ) ? hex : 0xffff00;
  27728. 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 ];
  27729. var geometry = new BufferGeometry();
  27730. geometry.addAttribute( 'position', new Float32BufferAttribute( positions, 3 ) );
  27731. geometry.computeBoundingSphere();
  27732. Line.call( this, geometry, new LineBasicMaterial( { color: color } ) );
  27733. //
  27734. var positions2 = [ 1, 1, 1, - 1, 1, 1, - 1, - 1, 1, 1, 1, 1, - 1, - 1, 1, 1, - 1, 1 ];
  27735. var geometry2 = new BufferGeometry();
  27736. geometry2.addAttribute( 'position', new Float32BufferAttribute( positions2, 3 ) );
  27737. geometry2.computeBoundingSphere();
  27738. this.add( new Mesh( geometry2, new MeshBasicMaterial( { color: color, opacity: 0.2, transparent: true, depthWrite: false } ) ) );
  27739. }
  27740. PlaneHelper.prototype = Object.create( Line.prototype );
  27741. PlaneHelper.prototype.constructor = PlaneHelper;
  27742. PlaneHelper.prototype.updateMatrixWorld = function ( force ) {
  27743. var scale = - this.plane.constant;
  27744. if ( Math.abs( scale ) < 1e-8 ) scale = 1e-8; // sign does not matter
  27745. this.scale.set( 0.5 * this.size, 0.5 * this.size, scale );
  27746. this.children[ 0 ].material.side = ( scale < 0 ) ? BackSide : FrontSide; // renderer flips side when determinant < 0; flipping not wanted here
  27747. this.lookAt( this.plane.normal );
  27748. Object3D.prototype.updateMatrixWorld.call( this, force );
  27749. };
  27750. /**
  27751. * @author WestLangley / http://github.com/WestLangley
  27752. * @author zz85 / http://github.com/zz85
  27753. * @author bhouston / http://clara.io
  27754. *
  27755. * Creates an arrow for visualizing directions
  27756. *
  27757. * Parameters:
  27758. * dir - Vector3
  27759. * origin - Vector3
  27760. * length - Number
  27761. * color - color in hex value
  27762. * headLength - Number
  27763. * headWidth - Number
  27764. */
  27765. var lineGeometry, coneGeometry;
  27766. function ArrowHelper( dir, origin, length, color, headLength, headWidth ) {
  27767. // dir is assumed to be normalized
  27768. Object3D.call( this );
  27769. if ( dir === undefined ) dir = new Vector3( 0, 0, 1 );
  27770. if ( origin === undefined ) origin = new Vector3( 0, 0, 0 );
  27771. if ( length === undefined ) length = 1;
  27772. if ( color === undefined ) color = 0xffff00;
  27773. if ( headLength === undefined ) headLength = 0.2 * length;
  27774. if ( headWidth === undefined ) headWidth = 0.2 * headLength;
  27775. if ( lineGeometry === undefined ) {
  27776. lineGeometry = new BufferGeometry();
  27777. lineGeometry.addAttribute( 'position', new Float32BufferAttribute( [ 0, 0, 0, 0, 1, 0 ], 3 ) );
  27778. coneGeometry = new CylinderBufferGeometry( 0, 0.5, 1, 5, 1 );
  27779. coneGeometry.translate( 0, - 0.5, 0 );
  27780. }
  27781. this.position.copy( origin );
  27782. this.line = new Line( lineGeometry, new LineBasicMaterial( { color: color } ) );
  27783. this.line.matrixAutoUpdate = false;
  27784. this.add( this.line );
  27785. this.cone = new Mesh( coneGeometry, new MeshBasicMaterial( { color: color } ) );
  27786. this.cone.matrixAutoUpdate = false;
  27787. this.add( this.cone );
  27788. this.setDirection( dir );
  27789. this.setLength( length, headLength, headWidth );
  27790. }
  27791. ArrowHelper.prototype = Object.create( Object3D.prototype );
  27792. ArrowHelper.prototype.constructor = ArrowHelper;
  27793. ArrowHelper.prototype.setDirection = ( function () {
  27794. var axis = new Vector3();
  27795. var radians;
  27796. return function setDirection( dir ) {
  27797. // dir is assumed to be normalized
  27798. if ( dir.y > 0.99999 ) {
  27799. this.quaternion.set( 0, 0, 0, 1 );
  27800. } else if ( dir.y < - 0.99999 ) {
  27801. this.quaternion.set( 1, 0, 0, 0 );
  27802. } else {
  27803. axis.set( dir.z, 0, - dir.x ).normalize();
  27804. radians = Math.acos( dir.y );
  27805. this.quaternion.setFromAxisAngle( axis, radians );
  27806. }
  27807. };
  27808. }() );
  27809. ArrowHelper.prototype.setLength = function ( length, headLength, headWidth ) {
  27810. if ( headLength === undefined ) headLength = 0.2 * length;
  27811. if ( headWidth === undefined ) headWidth = 0.2 * headLength;
  27812. this.line.scale.set( 1, Math.max( 0, length - headLength ), 1 );
  27813. this.line.updateMatrix();
  27814. this.cone.scale.set( headWidth, headLength, headWidth );
  27815. this.cone.position.y = length;
  27816. this.cone.updateMatrix();
  27817. };
  27818. ArrowHelper.prototype.setColor = function ( color ) {
  27819. this.line.material.color.copy( color );
  27820. this.cone.material.color.copy( color );
  27821. };
  27822. ArrowHelper.prototype.copy = function ( source ) {
  27823. Object3D.prototype.copy.call( this, source, false );
  27824. this.line.copy( source.line );
  27825. this.cone.copy( source.cone );
  27826. return this;
  27827. };
  27828. ArrowHelper.prototype.clone = function () {
  27829. return new this.constructor().copy( this );
  27830. };
  27831. /**
  27832. * @author sroucheray / http://sroucheray.org/
  27833. * @author mrdoob / http://mrdoob.com/
  27834. */
  27835. function AxesHelper( size ) {
  27836. size = size || 1;
  27837. var vertices = [
  27838. 0, 0, 0, size, 0, 0,
  27839. 0, 0, 0, 0, size, 0,
  27840. 0, 0, 0, 0, 0, size
  27841. ];
  27842. var colors = [
  27843. 1, 0, 0, 1, 0.6, 0,
  27844. 0, 1, 0, 0.6, 1, 0,
  27845. 0, 0, 1, 0, 0.6, 1
  27846. ];
  27847. var geometry = new BufferGeometry();
  27848. geometry.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  27849. geometry.addAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  27850. var material = new LineBasicMaterial( { vertexColors: VertexColors } );
  27851. LineSegments.call( this, geometry, material );
  27852. }
  27853. AxesHelper.prototype = Object.create( LineSegments.prototype );
  27854. AxesHelper.prototype.constructor = AxesHelper;
  27855. /**
  27856. * @author mrdoob / http://mrdoob.com/
  27857. */
  27858. function Face4( a, b, c, d, normal, color, materialIndex ) {
  27859. console.warn( 'THREE.Face4 has been removed. A THREE.Face3 will be created instead.' );
  27860. return new Face3( a, b, c, normal, color, materialIndex );
  27861. }
  27862. var LineStrip = 0;
  27863. var LinePieces = 1;
  27864. function MeshFaceMaterial( materials ) {
  27865. console.warn( 'THREE.MeshFaceMaterial has been removed. Use an Array instead.' );
  27866. return materials;
  27867. }
  27868. function MultiMaterial( materials ) {
  27869. if ( materials === undefined ) materials = [];
  27870. console.warn( 'THREE.MultiMaterial has been removed. Use an Array instead.' );
  27871. materials.isMultiMaterial = true;
  27872. materials.materials = materials;
  27873. materials.clone = function () {
  27874. return materials.slice();
  27875. };
  27876. return materials;
  27877. }
  27878. function PointCloud( geometry, material ) {
  27879. console.warn( 'THREE.PointCloud has been renamed to THREE.Points.' );
  27880. return new Points( geometry, material );
  27881. }
  27882. function Particle( material ) {
  27883. console.warn( 'THREE.Particle has been renamed to THREE.Sprite.' );
  27884. return new Sprite( material );
  27885. }
  27886. function ParticleSystem( geometry, material ) {
  27887. console.warn( 'THREE.ParticleSystem has been renamed to THREE.Points.' );
  27888. return new Points( geometry, material );
  27889. }
  27890. function PointCloudMaterial( parameters ) {
  27891. console.warn( 'THREE.PointCloudMaterial has been renamed to THREE.PointsMaterial.' );
  27892. return new PointsMaterial( parameters );
  27893. }
  27894. function ParticleBasicMaterial( parameters ) {
  27895. console.warn( 'THREE.ParticleBasicMaterial has been renamed to THREE.PointsMaterial.' );
  27896. return new PointsMaterial( parameters );
  27897. }
  27898. function ParticleSystemMaterial( parameters ) {
  27899. console.warn( 'THREE.ParticleSystemMaterial has been renamed to THREE.PointsMaterial.' );
  27900. return new PointsMaterial( parameters );
  27901. }
  27902. function Vertex( x, y, z ) {
  27903. console.warn( 'THREE.Vertex has been removed. Use THREE.Vector3 instead.' );
  27904. return new Vector3( x, y, z );
  27905. }
  27906. //
  27907. function DynamicBufferAttribute( array, itemSize ) {
  27908. console.warn( 'THREE.DynamicBufferAttribute has been removed. Use new THREE.BufferAttribute().setDynamic( true ) instead.' );
  27909. return new BufferAttribute( array, itemSize ).setDynamic( true );
  27910. }
  27911. function Int8Attribute( array, itemSize ) {
  27912. console.warn( 'THREE.Int8Attribute has been removed. Use new THREE.Int8BufferAttribute() instead.' );
  27913. return new Int8BufferAttribute( array, itemSize );
  27914. }
  27915. function Uint8Attribute( array, itemSize ) {
  27916. console.warn( 'THREE.Uint8Attribute has been removed. Use new THREE.Uint8BufferAttribute() instead.' );
  27917. return new Uint8BufferAttribute( array, itemSize );
  27918. }
  27919. function Uint8ClampedAttribute( array, itemSize ) {
  27920. console.warn( 'THREE.Uint8ClampedAttribute has been removed. Use new THREE.Uint8ClampedBufferAttribute() instead.' );
  27921. return new Uint8ClampedBufferAttribute( array, itemSize );
  27922. }
  27923. function Int16Attribute( array, itemSize ) {
  27924. console.warn( 'THREE.Int16Attribute has been removed. Use new THREE.Int16BufferAttribute() instead.' );
  27925. return new Int16BufferAttribute( array, itemSize );
  27926. }
  27927. function Uint16Attribute( array, itemSize ) {
  27928. console.warn( 'THREE.Uint16Attribute has been removed. Use new THREE.Uint16BufferAttribute() instead.' );
  27929. return new Uint16BufferAttribute( array, itemSize );
  27930. }
  27931. function Int32Attribute( array, itemSize ) {
  27932. console.warn( 'THREE.Int32Attribute has been removed. Use new THREE.Int32BufferAttribute() instead.' );
  27933. return new Int32BufferAttribute( array, itemSize );
  27934. }
  27935. function Uint32Attribute( array, itemSize ) {
  27936. console.warn( 'THREE.Uint32Attribute has been removed. Use new THREE.Uint32BufferAttribute() instead.' );
  27937. return new Uint32BufferAttribute( array, itemSize );
  27938. }
  27939. function Float32Attribute( array, itemSize ) {
  27940. console.warn( 'THREE.Float32Attribute has been removed. Use new THREE.Float32BufferAttribute() instead.' );
  27941. return new Float32BufferAttribute( array, itemSize );
  27942. }
  27943. function Float64Attribute( array, itemSize ) {
  27944. console.warn( 'THREE.Float64Attribute has been removed. Use new THREE.Float64BufferAttribute() instead.' );
  27945. return new Float64BufferAttribute( array, itemSize );
  27946. }
  27947. //
  27948. Curve.create = function ( construct, getPoint ) {
  27949. console.log( 'THREE.Curve.create() has been deprecated' );
  27950. construct.prototype = Object.create( Curve.prototype );
  27951. construct.prototype.constructor = construct;
  27952. construct.prototype.getPoint = getPoint;
  27953. return construct;
  27954. };
  27955. //
  27956. Object.assign( CurvePath.prototype, {
  27957. createPointsGeometry: function ( divisions ) {
  27958. console.warn( 'THREE.CurvePath: .createPointsGeometry() has been removed. Use new THREE.Geometry().setFromPoints( points ) instead.' );
  27959. // generate geometry from path points (for Line or Points objects)
  27960. var pts = this.getPoints( divisions );
  27961. return this.createGeometry( pts );
  27962. },
  27963. createSpacedPointsGeometry: function ( divisions ) {
  27964. console.warn( 'THREE.CurvePath: .createSpacedPointsGeometry() has been removed. Use new THREE.Geometry().setFromPoints( points ) instead.' );
  27965. // generate geometry from equidistant sampling along the path
  27966. var pts = this.getSpacedPoints( divisions );
  27967. return this.createGeometry( pts );
  27968. },
  27969. createGeometry: function ( points ) {
  27970. console.warn( 'THREE.CurvePath: .createGeometry() has been removed. Use new THREE.Geometry().setFromPoints( points ) instead.' );
  27971. var geometry = new Geometry();
  27972. for ( var i = 0, l = points.length; i < l; i ++ ) {
  27973. var point = points[ i ];
  27974. geometry.vertices.push( new Vector3( point.x, point.y, point.z || 0 ) );
  27975. }
  27976. return geometry;
  27977. }
  27978. } );
  27979. //
  27980. Object.assign( Path.prototype, {
  27981. fromPoints: function ( points ) {
  27982. console.warn( 'THREE.Path: .fromPoints() has been renamed to .setFromPoints().' );
  27983. this.setFromPoints( points );
  27984. }
  27985. } );
  27986. //
  27987. function ClosedSplineCurve3( points ) {
  27988. console.warn( 'THREE.ClosedSplineCurve3 has been deprecated. Use THREE.CatmullRomCurve3 instead.' );
  27989. CatmullRomCurve3.call( this, points );
  27990. this.type = 'catmullrom';
  27991. this.closed = true;
  27992. }
  27993. ClosedSplineCurve3.prototype = Object.create( CatmullRomCurve3.prototype );
  27994. //
  27995. function SplineCurve3( points ) {
  27996. console.warn( 'THREE.SplineCurve3 has been deprecated. Use THREE.CatmullRomCurve3 instead.' );
  27997. CatmullRomCurve3.call( this, points );
  27998. this.type = 'catmullrom';
  27999. }
  28000. SplineCurve3.prototype = Object.create( CatmullRomCurve3.prototype );
  28001. //
  28002. function Spline( points ) {
  28003. console.warn( 'THREE.Spline has been removed. Use THREE.CatmullRomCurve3 instead.' );
  28004. CatmullRomCurve3.call( this, points );
  28005. this.type = 'catmullrom';
  28006. }
  28007. Spline.prototype = Object.create( CatmullRomCurve3.prototype );
  28008. Object.assign( Spline.prototype, {
  28009. initFromArray: function ( /* a */ ) {
  28010. console.error( 'THREE.Spline: .initFromArray() has been removed.' );
  28011. },
  28012. getControlPointsArray: function ( /* optionalTarget */ ) {
  28013. console.error( 'THREE.Spline: .getControlPointsArray() has been removed.' );
  28014. },
  28015. reparametrizeByArcLength: function ( /* samplingCoef */ ) {
  28016. console.error( 'THREE.Spline: .reparametrizeByArcLength() has been removed.' );
  28017. }
  28018. } );
  28019. //
  28020. function AxisHelper( size ) {
  28021. console.warn( 'THREE.AxisHelper has been renamed to THREE.AxesHelper.' );
  28022. return new AxesHelper( size );
  28023. }
  28024. function BoundingBoxHelper( object, color ) {
  28025. console.warn( 'THREE.BoundingBoxHelper has been deprecated. Creating a THREE.BoxHelper instead.' );
  28026. return new BoxHelper( object, color );
  28027. }
  28028. function EdgesHelper( object, hex ) {
  28029. console.warn( 'THREE.EdgesHelper has been removed. Use THREE.EdgesGeometry instead.' );
  28030. return new LineSegments( new EdgesGeometry( object.geometry ), new LineBasicMaterial( { color: hex !== undefined ? hex : 0xffffff } ) );
  28031. }
  28032. GridHelper.prototype.setColors = function () {
  28033. console.error( 'THREE.GridHelper: setColors() has been deprecated, pass them in the constructor instead.' );
  28034. };
  28035. SkeletonHelper.prototype.update = function () {
  28036. console.error( 'THREE.SkeletonHelper: update() no longer needs to be called.' );
  28037. };
  28038. function WireframeHelper( object, hex ) {
  28039. console.warn( 'THREE.WireframeHelper has been removed. Use THREE.WireframeGeometry instead.' );
  28040. return new LineSegments( new WireframeGeometry( object.geometry ), new LineBasicMaterial( { color: hex !== undefined ? hex : 0xffffff } ) );
  28041. }
  28042. //
  28043. Object.assign( Loader.prototype, {
  28044. extractUrlBase: function ( url ) {
  28045. console.warn( 'THREE.Loader: .extractUrlBase() has been deprecated. Use THREE.LoaderUtils.extractUrlBase() instead.' );
  28046. return LoaderUtils.extractUrlBase( url );
  28047. }
  28048. } );
  28049. function XHRLoader( manager ) {
  28050. console.warn( 'THREE.XHRLoader has been renamed to THREE.FileLoader.' );
  28051. return new FileLoader( manager );
  28052. }
  28053. function BinaryTextureLoader( manager ) {
  28054. console.warn( 'THREE.BinaryTextureLoader has been renamed to THREE.DataTextureLoader.' );
  28055. return new DataTextureLoader( manager );
  28056. }
  28057. Object.assign( ObjectLoader.prototype, {
  28058. setTexturePath: function ( value ) {
  28059. console.warn( 'THREE.ObjectLoader: .setTexturePath() has been renamed to .setResourcePath().' );
  28060. return this.setResourcePath( value );
  28061. }
  28062. } );
  28063. //
  28064. Object.assign( Box2.prototype, {
  28065. center: function ( optionalTarget ) {
  28066. console.warn( 'THREE.Box2: .center() has been renamed to .getCenter().' );
  28067. return this.getCenter( optionalTarget );
  28068. },
  28069. empty: function () {
  28070. console.warn( 'THREE.Box2: .empty() has been renamed to .isEmpty().' );
  28071. return this.isEmpty();
  28072. },
  28073. isIntersectionBox: function ( box ) {
  28074. console.warn( 'THREE.Box2: .isIntersectionBox() has been renamed to .intersectsBox().' );
  28075. return this.intersectsBox( box );
  28076. },
  28077. size: function ( optionalTarget ) {
  28078. console.warn( 'THREE.Box2: .size() has been renamed to .getSize().' );
  28079. return this.getSize( optionalTarget );
  28080. }
  28081. } );
  28082. Object.assign( Box3.prototype, {
  28083. center: function ( optionalTarget ) {
  28084. console.warn( 'THREE.Box3: .center() has been renamed to .getCenter().' );
  28085. return this.getCenter( optionalTarget );
  28086. },
  28087. empty: function () {
  28088. console.warn( 'THREE.Box3: .empty() has been renamed to .isEmpty().' );
  28089. return this.isEmpty();
  28090. },
  28091. isIntersectionBox: function ( box ) {
  28092. console.warn( 'THREE.Box3: .isIntersectionBox() has been renamed to .intersectsBox().' );
  28093. return this.intersectsBox( box );
  28094. },
  28095. isIntersectionSphere: function ( sphere ) {
  28096. console.warn( 'THREE.Box3: .isIntersectionSphere() has been renamed to .intersectsSphere().' );
  28097. return this.intersectsSphere( sphere );
  28098. },
  28099. size: function ( optionalTarget ) {
  28100. console.warn( 'THREE.Box3: .size() has been renamed to .getSize().' );
  28101. return this.getSize( optionalTarget );
  28102. }
  28103. } );
  28104. Line3.prototype.center = function ( optionalTarget ) {
  28105. console.warn( 'THREE.Line3: .center() has been renamed to .getCenter().' );
  28106. return this.getCenter( optionalTarget );
  28107. };
  28108. Object.assign( _Math, {
  28109. random16: function () {
  28110. console.warn( 'THREE.Math: .random16() has been deprecated. Use Math.random() instead.' );
  28111. return Math.random();
  28112. },
  28113. nearestPowerOfTwo: function ( value ) {
  28114. console.warn( 'THREE.Math: .nearestPowerOfTwo() has been renamed to .floorPowerOfTwo().' );
  28115. return _Math.floorPowerOfTwo( value );
  28116. },
  28117. nextPowerOfTwo: function ( value ) {
  28118. console.warn( 'THREE.Math: .nextPowerOfTwo() has been renamed to .ceilPowerOfTwo().' );
  28119. return _Math.ceilPowerOfTwo( value );
  28120. }
  28121. } );
  28122. Object.assign( Matrix3.prototype, {
  28123. flattenToArrayOffset: function ( array, offset ) {
  28124. console.warn( "THREE.Matrix3: .flattenToArrayOffset() has been deprecated. Use .toArray() instead." );
  28125. return this.toArray( array, offset );
  28126. },
  28127. multiplyVector3: function ( vector ) {
  28128. console.warn( 'THREE.Matrix3: .multiplyVector3() has been removed. Use vector.applyMatrix3( matrix ) instead.' );
  28129. return vector.applyMatrix3( this );
  28130. },
  28131. multiplyVector3Array: function ( /* a */ ) {
  28132. console.error( 'THREE.Matrix3: .multiplyVector3Array() has been removed.' );
  28133. },
  28134. applyToBuffer: function ( buffer /*, offset, length */ ) {
  28135. console.warn( 'THREE.Matrix3: .applyToBuffer() has been removed. Use matrix.applyToBufferAttribute( attribute ) instead.' );
  28136. return this.applyToBufferAttribute( buffer );
  28137. },
  28138. applyToVector3Array: function ( /* array, offset, length */ ) {
  28139. console.error( 'THREE.Matrix3: .applyToVector3Array() has been removed.' );
  28140. }
  28141. } );
  28142. Object.assign( Matrix4.prototype, {
  28143. extractPosition: function ( m ) {
  28144. console.warn( 'THREE.Matrix4: .extractPosition() has been renamed to .copyPosition().' );
  28145. return this.copyPosition( m );
  28146. },
  28147. flattenToArrayOffset: function ( array, offset ) {
  28148. console.warn( "THREE.Matrix4: .flattenToArrayOffset() has been deprecated. Use .toArray() instead." );
  28149. return this.toArray( array, offset );
  28150. },
  28151. getPosition: function () {
  28152. var v1;
  28153. return function getPosition() {
  28154. if ( v1 === undefined ) v1 = new Vector3();
  28155. console.warn( 'THREE.Matrix4: .getPosition() has been removed. Use Vector3.setFromMatrixPosition( matrix ) instead.' );
  28156. return v1.setFromMatrixColumn( this, 3 );
  28157. };
  28158. }(),
  28159. setRotationFromQuaternion: function ( q ) {
  28160. console.warn( 'THREE.Matrix4: .setRotationFromQuaternion() has been renamed to .makeRotationFromQuaternion().' );
  28161. return this.makeRotationFromQuaternion( q );
  28162. },
  28163. multiplyToArray: function () {
  28164. console.warn( 'THREE.Matrix4: .multiplyToArray() has been removed.' );
  28165. },
  28166. multiplyVector3: function ( vector ) {
  28167. console.warn( 'THREE.Matrix4: .multiplyVector3() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
  28168. return vector.applyMatrix4( this );
  28169. },
  28170. multiplyVector4: function ( vector ) {
  28171. console.warn( 'THREE.Matrix4: .multiplyVector4() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
  28172. return vector.applyMatrix4( this );
  28173. },
  28174. multiplyVector3Array: function ( /* a */ ) {
  28175. console.error( 'THREE.Matrix4: .multiplyVector3Array() has been removed.' );
  28176. },
  28177. rotateAxis: function ( v ) {
  28178. console.warn( 'THREE.Matrix4: .rotateAxis() has been removed. Use Vector3.transformDirection( matrix ) instead.' );
  28179. v.transformDirection( this );
  28180. },
  28181. crossVector: function ( vector ) {
  28182. console.warn( 'THREE.Matrix4: .crossVector() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
  28183. return vector.applyMatrix4( this );
  28184. },
  28185. translate: function () {
  28186. console.error( 'THREE.Matrix4: .translate() has been removed.' );
  28187. },
  28188. rotateX: function () {
  28189. console.error( 'THREE.Matrix4: .rotateX() has been removed.' );
  28190. },
  28191. rotateY: function () {
  28192. console.error( 'THREE.Matrix4: .rotateY() has been removed.' );
  28193. },
  28194. rotateZ: function () {
  28195. console.error( 'THREE.Matrix4: .rotateZ() has been removed.' );
  28196. },
  28197. rotateByAxis: function () {
  28198. console.error( 'THREE.Matrix4: .rotateByAxis() has been removed.' );
  28199. },
  28200. applyToBuffer: function ( buffer /*, offset, length */ ) {
  28201. console.warn( 'THREE.Matrix4: .applyToBuffer() has been removed. Use matrix.applyToBufferAttribute( attribute ) instead.' );
  28202. return this.applyToBufferAttribute( buffer );
  28203. },
  28204. applyToVector3Array: function ( /* array, offset, length */ ) {
  28205. console.error( 'THREE.Matrix4: .applyToVector3Array() has been removed.' );
  28206. },
  28207. makeFrustum: function ( left, right, bottom, top, near, far ) {
  28208. console.warn( 'THREE.Matrix4: .makeFrustum() has been removed. Use .makePerspective( left, right, top, bottom, near, far ) instead.' );
  28209. return this.makePerspective( left, right, top, bottom, near, far );
  28210. }
  28211. } );
  28212. Plane.prototype.isIntersectionLine = function ( line ) {
  28213. console.warn( 'THREE.Plane: .isIntersectionLine() has been renamed to .intersectsLine().' );
  28214. return this.intersectsLine( line );
  28215. };
  28216. Quaternion.prototype.multiplyVector3 = function ( vector ) {
  28217. console.warn( 'THREE.Quaternion: .multiplyVector3() has been removed. Use is now vector.applyQuaternion( quaternion ) instead.' );
  28218. return vector.applyQuaternion( this );
  28219. };
  28220. Object.assign( Ray.prototype, {
  28221. isIntersectionBox: function ( box ) {
  28222. console.warn( 'THREE.Ray: .isIntersectionBox() has been renamed to .intersectsBox().' );
  28223. return this.intersectsBox( box );
  28224. },
  28225. isIntersectionPlane: function ( plane ) {
  28226. console.warn( 'THREE.Ray: .isIntersectionPlane() has been renamed to .intersectsPlane().' );
  28227. return this.intersectsPlane( plane );
  28228. },
  28229. isIntersectionSphere: function ( sphere ) {
  28230. console.warn( 'THREE.Ray: .isIntersectionSphere() has been renamed to .intersectsSphere().' );
  28231. return this.intersectsSphere( sphere );
  28232. }
  28233. } );
  28234. Object.assign( Triangle.prototype, {
  28235. area: function () {
  28236. console.warn( 'THREE.Triangle: .area() has been renamed to .getArea().' );
  28237. return this.getArea();
  28238. },
  28239. barycoordFromPoint: function ( point, target ) {
  28240. console.warn( 'THREE.Triangle: .barycoordFromPoint() has been renamed to .getBarycoord().' );
  28241. return this.getBarycoord( point, target );
  28242. },
  28243. midpoint: function ( target ) {
  28244. console.warn( 'THREE.Triangle: .midpoint() has been renamed to .getMidpoint().' );
  28245. return this.getMidpoint( target );
  28246. },
  28247. normal: function ( target ) {
  28248. console.warn( 'THREE.Triangle: .normal() has been renamed to .getNormal().' );
  28249. return this.getNormal( target );
  28250. },
  28251. plane: function ( target ) {
  28252. console.warn( 'THREE.Triangle: .plane() has been renamed to .getPlane().' );
  28253. return this.getPlane( target );
  28254. }
  28255. } );
  28256. Object.assign( Triangle, {
  28257. barycoordFromPoint: function ( point, a, b, c, target ) {
  28258. console.warn( 'THREE.Triangle: .barycoordFromPoint() has been renamed to .getBarycoord().' );
  28259. return Triangle.getBarycoord( point, a, b, c, target );
  28260. },
  28261. normal: function ( a, b, c, target ) {
  28262. console.warn( 'THREE.Triangle: .normal() has been renamed to .getNormal().' );
  28263. return Triangle.getNormal( a, b, c, target );
  28264. }
  28265. } );
  28266. Object.assign( Shape.prototype, {
  28267. extractAllPoints: function ( divisions ) {
  28268. console.warn( 'THREE.Shape: .extractAllPoints() has been removed. Use .extractPoints() instead.' );
  28269. return this.extractPoints( divisions );
  28270. },
  28271. extrude: function ( options ) {
  28272. console.warn( 'THREE.Shape: .extrude() has been removed. Use ExtrudeGeometry() instead.' );
  28273. return new ExtrudeGeometry( this, options );
  28274. },
  28275. makeGeometry: function ( options ) {
  28276. console.warn( 'THREE.Shape: .makeGeometry() has been removed. Use ShapeGeometry() instead.' );
  28277. return new ShapeGeometry( this, options );
  28278. }
  28279. } );
  28280. Object.assign( Vector2.prototype, {
  28281. fromAttribute: function ( attribute, index, offset ) {
  28282. console.warn( 'THREE.Vector2: .fromAttribute() has been renamed to .fromBufferAttribute().' );
  28283. return this.fromBufferAttribute( attribute, index, offset );
  28284. },
  28285. distanceToManhattan: function ( v ) {
  28286. console.warn( 'THREE.Vector2: .distanceToManhattan() has been renamed to .manhattanDistanceTo().' );
  28287. return this.manhattanDistanceTo( v );
  28288. },
  28289. lengthManhattan: function () {
  28290. console.warn( 'THREE.Vector2: .lengthManhattan() has been renamed to .manhattanLength().' );
  28291. return this.manhattanLength();
  28292. }
  28293. } );
  28294. Object.assign( Vector3.prototype, {
  28295. setEulerFromRotationMatrix: function () {
  28296. console.error( 'THREE.Vector3: .setEulerFromRotationMatrix() has been removed. Use Euler.setFromRotationMatrix() instead.' );
  28297. },
  28298. setEulerFromQuaternion: function () {
  28299. console.error( 'THREE.Vector3: .setEulerFromQuaternion() has been removed. Use Euler.setFromQuaternion() instead.' );
  28300. },
  28301. getPositionFromMatrix: function ( m ) {
  28302. console.warn( 'THREE.Vector3: .getPositionFromMatrix() has been renamed to .setFromMatrixPosition().' );
  28303. return this.setFromMatrixPosition( m );
  28304. },
  28305. getScaleFromMatrix: function ( m ) {
  28306. console.warn( 'THREE.Vector3: .getScaleFromMatrix() has been renamed to .setFromMatrixScale().' );
  28307. return this.setFromMatrixScale( m );
  28308. },
  28309. getColumnFromMatrix: function ( index, matrix ) {
  28310. console.warn( 'THREE.Vector3: .getColumnFromMatrix() has been renamed to .setFromMatrixColumn().' );
  28311. return this.setFromMatrixColumn( matrix, index );
  28312. },
  28313. applyProjection: function ( m ) {
  28314. console.warn( 'THREE.Vector3: .applyProjection() has been removed. Use .applyMatrix4( m ) instead.' );
  28315. return this.applyMatrix4( m );
  28316. },
  28317. fromAttribute: function ( attribute, index, offset ) {
  28318. console.warn( 'THREE.Vector3: .fromAttribute() has been renamed to .fromBufferAttribute().' );
  28319. return this.fromBufferAttribute( attribute, index, offset );
  28320. },
  28321. distanceToManhattan: function ( v ) {
  28322. console.warn( 'THREE.Vector3: .distanceToManhattan() has been renamed to .manhattanDistanceTo().' );
  28323. return this.manhattanDistanceTo( v );
  28324. },
  28325. lengthManhattan: function () {
  28326. console.warn( 'THREE.Vector3: .lengthManhattan() has been renamed to .manhattanLength().' );
  28327. return this.manhattanLength();
  28328. }
  28329. } );
  28330. Object.assign( Vector4.prototype, {
  28331. fromAttribute: function ( attribute, index, offset ) {
  28332. console.warn( 'THREE.Vector4: .fromAttribute() has been renamed to .fromBufferAttribute().' );
  28333. return this.fromBufferAttribute( attribute, index, offset );
  28334. },
  28335. lengthManhattan: function () {
  28336. console.warn( 'THREE.Vector4: .lengthManhattan() has been renamed to .manhattanLength().' );
  28337. return this.manhattanLength();
  28338. }
  28339. } );
  28340. //
  28341. Object.assign( Geometry.prototype, {
  28342. computeTangents: function () {
  28343. console.error( 'THREE.Geometry: .computeTangents() has been removed.' );
  28344. },
  28345. computeLineDistances: function () {
  28346. console.error( 'THREE.Geometry: .computeLineDistances() has been removed. Use THREE.Line.computeLineDistances() instead.' );
  28347. }
  28348. } );
  28349. Object.assign( Object3D.prototype, {
  28350. getChildByName: function ( name ) {
  28351. console.warn( 'THREE.Object3D: .getChildByName() has been renamed to .getObjectByName().' );
  28352. return this.getObjectByName( name );
  28353. },
  28354. renderDepth: function () {
  28355. console.warn( 'THREE.Object3D: .renderDepth has been removed. Use .renderOrder, instead.' );
  28356. },
  28357. translate: function ( distance, axis ) {
  28358. console.warn( 'THREE.Object3D: .translate() has been removed. Use .translateOnAxis( axis, distance ) instead.' );
  28359. return this.translateOnAxis( axis, distance );
  28360. },
  28361. getWorldRotation: function () {
  28362. console.error( 'THREE.Object3D: .getWorldRotation() has been removed. Use THREE.Object3D.getWorldQuaternion( target ) instead.' );
  28363. }
  28364. } );
  28365. Object.defineProperties( Object3D.prototype, {
  28366. eulerOrder: {
  28367. get: function () {
  28368. console.warn( 'THREE.Object3D: .eulerOrder is now .rotation.order.' );
  28369. return this.rotation.order;
  28370. },
  28371. set: function ( value ) {
  28372. console.warn( 'THREE.Object3D: .eulerOrder is now .rotation.order.' );
  28373. this.rotation.order = value;
  28374. }
  28375. },
  28376. useQuaternion: {
  28377. get: function () {
  28378. console.warn( 'THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.' );
  28379. },
  28380. set: function () {
  28381. console.warn( 'THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.' );
  28382. }
  28383. }
  28384. } );
  28385. Object.defineProperties( LOD.prototype, {
  28386. objects: {
  28387. get: function () {
  28388. console.warn( 'THREE.LOD: .objects has been renamed to .levels.' );
  28389. return this.levels;
  28390. }
  28391. }
  28392. } );
  28393. Object.defineProperty( Skeleton.prototype, 'useVertexTexture', {
  28394. get: function () {
  28395. console.warn( 'THREE.Skeleton: useVertexTexture has been removed.' );
  28396. },
  28397. set: function () {
  28398. console.warn( 'THREE.Skeleton: useVertexTexture has been removed.' );
  28399. }
  28400. } );
  28401. SkinnedMesh.prototype.initBones = function () {
  28402. console.error( 'THREE.SkinnedMesh: initBones() has been removed.' );
  28403. };
  28404. Object.defineProperty( Curve.prototype, '__arcLengthDivisions', {
  28405. get: function () {
  28406. console.warn( 'THREE.Curve: .__arcLengthDivisions is now .arcLengthDivisions.' );
  28407. return this.arcLengthDivisions;
  28408. },
  28409. set: function ( value ) {
  28410. console.warn( 'THREE.Curve: .__arcLengthDivisions is now .arcLengthDivisions.' );
  28411. this.arcLengthDivisions = value;
  28412. }
  28413. } );
  28414. //
  28415. PerspectiveCamera.prototype.setLens = function ( focalLength, filmGauge ) {
  28416. console.warn( "THREE.PerspectiveCamera.setLens is deprecated. " +
  28417. "Use .setFocalLength and .filmGauge for a photographic setup." );
  28418. if ( filmGauge !== undefined ) this.filmGauge = filmGauge;
  28419. this.setFocalLength( focalLength );
  28420. };
  28421. //
  28422. Object.defineProperties( Light.prototype, {
  28423. onlyShadow: {
  28424. set: function () {
  28425. console.warn( 'THREE.Light: .onlyShadow has been removed.' );
  28426. }
  28427. },
  28428. shadowCameraFov: {
  28429. set: function ( value ) {
  28430. console.warn( 'THREE.Light: .shadowCameraFov is now .shadow.camera.fov.' );
  28431. this.shadow.camera.fov = value;
  28432. }
  28433. },
  28434. shadowCameraLeft: {
  28435. set: function ( value ) {
  28436. console.warn( 'THREE.Light: .shadowCameraLeft is now .shadow.camera.left.' );
  28437. this.shadow.camera.left = value;
  28438. }
  28439. },
  28440. shadowCameraRight: {
  28441. set: function ( value ) {
  28442. console.warn( 'THREE.Light: .shadowCameraRight is now .shadow.camera.right.' );
  28443. this.shadow.camera.right = value;
  28444. }
  28445. },
  28446. shadowCameraTop: {
  28447. set: function ( value ) {
  28448. console.warn( 'THREE.Light: .shadowCameraTop is now .shadow.camera.top.' );
  28449. this.shadow.camera.top = value;
  28450. }
  28451. },
  28452. shadowCameraBottom: {
  28453. set: function ( value ) {
  28454. console.warn( 'THREE.Light: .shadowCameraBottom is now .shadow.camera.bottom.' );
  28455. this.shadow.camera.bottom = value;
  28456. }
  28457. },
  28458. shadowCameraNear: {
  28459. set: function ( value ) {
  28460. console.warn( 'THREE.Light: .shadowCameraNear is now .shadow.camera.near.' );
  28461. this.shadow.camera.near = value;
  28462. }
  28463. },
  28464. shadowCameraFar: {
  28465. set: function ( value ) {
  28466. console.warn( 'THREE.Light: .shadowCameraFar is now .shadow.camera.far.' );
  28467. this.shadow.camera.far = value;
  28468. }
  28469. },
  28470. shadowCameraVisible: {
  28471. set: function () {
  28472. console.warn( 'THREE.Light: .shadowCameraVisible has been removed. Use new THREE.CameraHelper( light.shadow.camera ) instead.' );
  28473. }
  28474. },
  28475. shadowBias: {
  28476. set: function ( value ) {
  28477. console.warn( 'THREE.Light: .shadowBias is now .shadow.bias.' );
  28478. this.shadow.bias = value;
  28479. }
  28480. },
  28481. shadowDarkness: {
  28482. set: function () {
  28483. console.warn( 'THREE.Light: .shadowDarkness has been removed.' );
  28484. }
  28485. },
  28486. shadowMapWidth: {
  28487. set: function ( value ) {
  28488. console.warn( 'THREE.Light: .shadowMapWidth is now .shadow.mapSize.width.' );
  28489. this.shadow.mapSize.width = value;
  28490. }
  28491. },
  28492. shadowMapHeight: {
  28493. set: function ( value ) {
  28494. console.warn( 'THREE.Light: .shadowMapHeight is now .shadow.mapSize.height.' );
  28495. this.shadow.mapSize.height = value;
  28496. }
  28497. }
  28498. } );
  28499. //
  28500. Object.defineProperties( BufferAttribute.prototype, {
  28501. length: {
  28502. get: function () {
  28503. console.warn( 'THREE.BufferAttribute: .length has been deprecated. Use .count instead.' );
  28504. return this.array.length;
  28505. }
  28506. },
  28507. copyIndicesArray: function ( /* indices */ ) {
  28508. console.error( 'THREE.BufferAttribute: .copyIndicesArray() has been removed.' );
  28509. }
  28510. } );
  28511. Object.assign( BufferGeometry.prototype, {
  28512. addIndex: function ( index ) {
  28513. console.warn( 'THREE.BufferGeometry: .addIndex() has been renamed to .setIndex().' );
  28514. this.setIndex( index );
  28515. },
  28516. addDrawCall: function ( start, count, indexOffset ) {
  28517. if ( indexOffset !== undefined ) {
  28518. console.warn( 'THREE.BufferGeometry: .addDrawCall() no longer supports indexOffset.' );
  28519. }
  28520. console.warn( 'THREE.BufferGeometry: .addDrawCall() is now .addGroup().' );
  28521. this.addGroup( start, count );
  28522. },
  28523. clearDrawCalls: function () {
  28524. console.warn( 'THREE.BufferGeometry: .clearDrawCalls() is now .clearGroups().' );
  28525. this.clearGroups();
  28526. },
  28527. computeTangents: function () {
  28528. console.warn( 'THREE.BufferGeometry: .computeTangents() has been removed.' );
  28529. },
  28530. computeOffsets: function () {
  28531. console.warn( 'THREE.BufferGeometry: .computeOffsets() has been removed.' );
  28532. }
  28533. } );
  28534. Object.defineProperties( BufferGeometry.prototype, {
  28535. drawcalls: {
  28536. get: function () {
  28537. console.error( 'THREE.BufferGeometry: .drawcalls has been renamed to .groups.' );
  28538. return this.groups;
  28539. }
  28540. },
  28541. offsets: {
  28542. get: function () {
  28543. console.warn( 'THREE.BufferGeometry: .offsets has been renamed to .groups.' );
  28544. return this.groups;
  28545. }
  28546. }
  28547. } );
  28548. //
  28549. Object.assign( ExtrudeBufferGeometry.prototype, {
  28550. getArrays: function () {
  28551. console.error( 'THREE.ExtrudeBufferGeometry: .getArrays() has been removed.' );
  28552. },
  28553. addShapeList: function () {
  28554. console.error( 'THREE.ExtrudeBufferGeometry: .addShapeList() has been removed.' );
  28555. },
  28556. addShape: function () {
  28557. console.error( 'THREE.ExtrudeBufferGeometry: .addShape() has been removed.' );
  28558. }
  28559. } );
  28560. //
  28561. Object.defineProperties( Uniform.prototype, {
  28562. dynamic: {
  28563. set: function () {
  28564. console.warn( 'THREE.Uniform: .dynamic has been removed. Use object.onBeforeRender() instead.' );
  28565. }
  28566. },
  28567. onUpdate: {
  28568. value: function () {
  28569. console.warn( 'THREE.Uniform: .onUpdate() has been removed. Use object.onBeforeRender() instead.' );
  28570. return this;
  28571. }
  28572. }
  28573. } );
  28574. //
  28575. Object.defineProperties( Material.prototype, {
  28576. wrapAround: {
  28577. get: function () {
  28578. console.warn( 'THREE.Material: .wrapAround has been removed.' );
  28579. },
  28580. set: function () {
  28581. console.warn( 'THREE.Material: .wrapAround has been removed.' );
  28582. }
  28583. },
  28584. overdraw: {
  28585. get: function () {
  28586. console.warn( 'THREE.Material: .overdraw has been removed.' );
  28587. },
  28588. set: function () {
  28589. console.warn( 'THREE.Material: .overdraw has been removed.' );
  28590. }
  28591. },
  28592. wrapRGB: {
  28593. get: function () {
  28594. console.warn( 'THREE.Material: .wrapRGB has been removed.' );
  28595. return new Color();
  28596. }
  28597. },
  28598. shading: {
  28599. get: function () {
  28600. console.error( 'THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.' );
  28601. },
  28602. set: function ( value ) {
  28603. console.warn( 'THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.' );
  28604. this.flatShading = ( value === FlatShading );
  28605. }
  28606. }
  28607. } );
  28608. Object.defineProperties( MeshPhongMaterial.prototype, {
  28609. metal: {
  28610. get: function () {
  28611. console.warn( 'THREE.MeshPhongMaterial: .metal has been removed. Use THREE.MeshStandardMaterial instead.' );
  28612. return false;
  28613. },
  28614. set: function () {
  28615. console.warn( 'THREE.MeshPhongMaterial: .metal has been removed. Use THREE.MeshStandardMaterial instead' );
  28616. }
  28617. }
  28618. } );
  28619. Object.defineProperties( ShaderMaterial.prototype, {
  28620. derivatives: {
  28621. get: function () {
  28622. console.warn( 'THREE.ShaderMaterial: .derivatives has been moved to .extensions.derivatives.' );
  28623. return this.extensions.derivatives;
  28624. },
  28625. set: function ( value ) {
  28626. console.warn( 'THREE. ShaderMaterial: .derivatives has been moved to .extensions.derivatives.' );
  28627. this.extensions.derivatives = value;
  28628. }
  28629. }
  28630. } );
  28631. //
  28632. Object.assign( WebGLRenderer.prototype, {
  28633. clearTarget: function ( renderTarget, color, depth, stencil ) {
  28634. console.warn( 'THREE.WebGLRenderer: .clearTarget() has been deprecated. Use .setRenderTarget() and .clear() instead.' );
  28635. this.setRenderTarget( renderTarget );
  28636. this.clear( color, depth, stencil );
  28637. },
  28638. animate: function ( callback ) {
  28639. console.warn( 'THREE.WebGLRenderer: .animate() is now .setAnimationLoop().' );
  28640. this.setAnimationLoop( callback );
  28641. },
  28642. getCurrentRenderTarget: function () {
  28643. console.warn( 'THREE.WebGLRenderer: .getCurrentRenderTarget() is now .getRenderTarget().' );
  28644. return this.getRenderTarget();
  28645. },
  28646. getMaxAnisotropy: function () {
  28647. console.warn( 'THREE.WebGLRenderer: .getMaxAnisotropy() is now .capabilities.getMaxAnisotropy().' );
  28648. return this.capabilities.getMaxAnisotropy();
  28649. },
  28650. getPrecision: function () {
  28651. console.warn( 'THREE.WebGLRenderer: .getPrecision() is now .capabilities.precision.' );
  28652. return this.capabilities.precision;
  28653. },
  28654. resetGLState: function () {
  28655. console.warn( 'THREE.WebGLRenderer: .resetGLState() is now .state.reset().' );
  28656. return this.state.reset();
  28657. },
  28658. supportsFloatTextures: function () {
  28659. console.warn( 'THREE.WebGLRenderer: .supportsFloatTextures() is now .extensions.get( \'OES_texture_float\' ).' );
  28660. return this.extensions.get( 'OES_texture_float' );
  28661. },
  28662. supportsHalfFloatTextures: function () {
  28663. console.warn( 'THREE.WebGLRenderer: .supportsHalfFloatTextures() is now .extensions.get( \'OES_texture_half_float\' ).' );
  28664. return this.extensions.get( 'OES_texture_half_float' );
  28665. },
  28666. supportsStandardDerivatives: function () {
  28667. console.warn( 'THREE.WebGLRenderer: .supportsStandardDerivatives() is now .extensions.get( \'OES_standard_derivatives\' ).' );
  28668. return this.extensions.get( 'OES_standard_derivatives' );
  28669. },
  28670. supportsCompressedTextureS3TC: function () {
  28671. console.warn( 'THREE.WebGLRenderer: .supportsCompressedTextureS3TC() is now .extensions.get( \'WEBGL_compressed_texture_s3tc\' ).' );
  28672. return this.extensions.get( 'WEBGL_compressed_texture_s3tc' );
  28673. },
  28674. supportsCompressedTexturePVRTC: function () {
  28675. console.warn( 'THREE.WebGLRenderer: .supportsCompressedTexturePVRTC() is now .extensions.get( \'WEBGL_compressed_texture_pvrtc\' ).' );
  28676. return this.extensions.get( 'WEBGL_compressed_texture_pvrtc' );
  28677. },
  28678. supportsBlendMinMax: function () {
  28679. console.warn( 'THREE.WebGLRenderer: .supportsBlendMinMax() is now .extensions.get( \'EXT_blend_minmax\' ).' );
  28680. return this.extensions.get( 'EXT_blend_minmax' );
  28681. },
  28682. supportsVertexTextures: function () {
  28683. console.warn( 'THREE.WebGLRenderer: .supportsVertexTextures() is now .capabilities.vertexTextures.' );
  28684. return this.capabilities.vertexTextures;
  28685. },
  28686. supportsInstancedArrays: function () {
  28687. console.warn( 'THREE.WebGLRenderer: .supportsInstancedArrays() is now .extensions.get( \'ANGLE_instanced_arrays\' ).' );
  28688. return this.extensions.get( 'ANGLE_instanced_arrays' );
  28689. },
  28690. enableScissorTest: function ( boolean ) {
  28691. console.warn( 'THREE.WebGLRenderer: .enableScissorTest() is now .setScissorTest().' );
  28692. this.setScissorTest( boolean );
  28693. },
  28694. initMaterial: function () {
  28695. console.warn( 'THREE.WebGLRenderer: .initMaterial() has been removed.' );
  28696. },
  28697. addPrePlugin: function () {
  28698. console.warn( 'THREE.WebGLRenderer: .addPrePlugin() has been removed.' );
  28699. },
  28700. addPostPlugin: function () {
  28701. console.warn( 'THREE.WebGLRenderer: .addPostPlugin() has been removed.' );
  28702. },
  28703. updateShadowMap: function () {
  28704. console.warn( 'THREE.WebGLRenderer: .updateShadowMap() has been removed.' );
  28705. },
  28706. setFaceCulling: function () {
  28707. console.warn( 'THREE.WebGLRenderer: .setFaceCulling() has been removed.' );
  28708. },
  28709. allocTextureUnit: function () {
  28710. console.warn( 'THREE.WebGLRenderer: .allocTextureUnit() has been removed.' );
  28711. },
  28712. setTexture: function () {
  28713. console.warn( 'THREE.WebGLRenderer: .setTexture() has been removed.' );
  28714. },
  28715. setTexture2D: function () {
  28716. console.warn( 'THREE.WebGLRenderer: .setTexture2D() has been removed.' );
  28717. },
  28718. setTextureCube: function () {
  28719. console.warn( 'THREE.WebGLRenderer: .setTextureCube() has been removed.' );
  28720. }
  28721. } );
  28722. Object.defineProperties( WebGLRenderer.prototype, {
  28723. shadowMapEnabled: {
  28724. get: function () {
  28725. return this.shadowMap.enabled;
  28726. },
  28727. set: function ( value ) {
  28728. console.warn( 'THREE.WebGLRenderer: .shadowMapEnabled is now .shadowMap.enabled.' );
  28729. this.shadowMap.enabled = value;
  28730. }
  28731. },
  28732. shadowMapType: {
  28733. get: function () {
  28734. return this.shadowMap.type;
  28735. },
  28736. set: function ( value ) {
  28737. console.warn( 'THREE.WebGLRenderer: .shadowMapType is now .shadowMap.type.' );
  28738. this.shadowMap.type = value;
  28739. }
  28740. },
  28741. shadowMapCullFace: {
  28742. get: function () {
  28743. console.warn( 'THREE.WebGLRenderer: .shadowMapCullFace has been removed. Set Material.shadowSide instead.' );
  28744. return undefined;
  28745. },
  28746. set: function ( /* value */ ) {
  28747. console.warn( 'THREE.WebGLRenderer: .shadowMapCullFace has been removed. Set Material.shadowSide instead.' );
  28748. }
  28749. }
  28750. } );
  28751. Object.defineProperties( WebGLShadowMap.prototype, {
  28752. cullFace: {
  28753. get: function () {
  28754. console.warn( 'THREE.WebGLRenderer: .shadowMap.cullFace has been removed. Set Material.shadowSide instead.' );
  28755. return undefined;
  28756. },
  28757. set: function ( /* cullFace */ ) {
  28758. console.warn( 'THREE.WebGLRenderer: .shadowMap.cullFace has been removed. Set Material.shadowSide instead.' );
  28759. }
  28760. },
  28761. renderReverseSided: {
  28762. get: function () {
  28763. console.warn( 'THREE.WebGLRenderer: .shadowMap.renderReverseSided has been removed. Set Material.shadowSide instead.' );
  28764. return undefined;
  28765. },
  28766. set: function () {
  28767. console.warn( 'THREE.WebGLRenderer: .shadowMap.renderReverseSided has been removed. Set Material.shadowSide instead.' );
  28768. }
  28769. },
  28770. renderSingleSided: {
  28771. get: function () {
  28772. console.warn( 'THREE.WebGLRenderer: .shadowMap.renderSingleSided has been removed. Set Material.shadowSide instead.' );
  28773. return undefined;
  28774. },
  28775. set: function () {
  28776. console.warn( 'THREE.WebGLRenderer: .shadowMap.renderSingleSided has been removed. Set Material.shadowSide instead.' );
  28777. }
  28778. }
  28779. } );
  28780. //
  28781. Object.defineProperties( WebGLRenderTargetCube.prototype, {
  28782. activeCubeFace: {
  28783. set: function ( /* value */ ) {
  28784. console.warn( 'THREE.WebGLRenderTargetCube: .activeCubeFace has been removed. It is now the second parameter of WebGLRenderer.setRenderTarget().' );
  28785. }
  28786. },
  28787. activeMipMapLevel: {
  28788. set: function ( /* value */ ) {
  28789. console.warn( 'THREE.WebGLRenderTargetCube: .activeMipMapLevel has been removed. It is now the third parameter of WebGLRenderer.setRenderTarget().' );
  28790. }
  28791. }
  28792. } );
  28793. //
  28794. Object.defineProperties( WebGLRenderTarget.prototype, {
  28795. wrapS: {
  28796. get: function () {
  28797. console.warn( 'THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.' );
  28798. return this.texture.wrapS;
  28799. },
  28800. set: function ( value ) {
  28801. console.warn( 'THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.' );
  28802. this.texture.wrapS = value;
  28803. }
  28804. },
  28805. wrapT: {
  28806. get: function () {
  28807. console.warn( 'THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.' );
  28808. return this.texture.wrapT;
  28809. },
  28810. set: function ( value ) {
  28811. console.warn( 'THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.' );
  28812. this.texture.wrapT = value;
  28813. }
  28814. },
  28815. magFilter: {
  28816. get: function () {
  28817. console.warn( 'THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.' );
  28818. return this.texture.magFilter;
  28819. },
  28820. set: function ( value ) {
  28821. console.warn( 'THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.' );
  28822. this.texture.magFilter = value;
  28823. }
  28824. },
  28825. minFilter: {
  28826. get: function () {
  28827. console.warn( 'THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.' );
  28828. return this.texture.minFilter;
  28829. },
  28830. set: function ( value ) {
  28831. console.warn( 'THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.' );
  28832. this.texture.minFilter = value;
  28833. }
  28834. },
  28835. anisotropy: {
  28836. get: function () {
  28837. console.warn( 'THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy.' );
  28838. return this.texture.anisotropy;
  28839. },
  28840. set: function ( value ) {
  28841. console.warn( 'THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy.' );
  28842. this.texture.anisotropy = value;
  28843. }
  28844. },
  28845. offset: {
  28846. get: function () {
  28847. console.warn( 'THREE.WebGLRenderTarget: .offset is now .texture.offset.' );
  28848. return this.texture.offset;
  28849. },
  28850. set: function ( value ) {
  28851. console.warn( 'THREE.WebGLRenderTarget: .offset is now .texture.offset.' );
  28852. this.texture.offset = value;
  28853. }
  28854. },
  28855. repeat: {
  28856. get: function () {
  28857. console.warn( 'THREE.WebGLRenderTarget: .repeat is now .texture.repeat.' );
  28858. return this.texture.repeat;
  28859. },
  28860. set: function ( value ) {
  28861. console.warn( 'THREE.WebGLRenderTarget: .repeat is now .texture.repeat.' );
  28862. this.texture.repeat = value;
  28863. }
  28864. },
  28865. format: {
  28866. get: function () {
  28867. console.warn( 'THREE.WebGLRenderTarget: .format is now .texture.format.' );
  28868. return this.texture.format;
  28869. },
  28870. set: function ( value ) {
  28871. console.warn( 'THREE.WebGLRenderTarget: .format is now .texture.format.' );
  28872. this.texture.format = value;
  28873. }
  28874. },
  28875. type: {
  28876. get: function () {
  28877. console.warn( 'THREE.WebGLRenderTarget: .type is now .texture.type.' );
  28878. return this.texture.type;
  28879. },
  28880. set: function ( value ) {
  28881. console.warn( 'THREE.WebGLRenderTarget: .type is now .texture.type.' );
  28882. this.texture.type = value;
  28883. }
  28884. },
  28885. generateMipmaps: {
  28886. get: function () {
  28887. console.warn( 'THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps.' );
  28888. return this.texture.generateMipmaps;
  28889. },
  28890. set: function ( value ) {
  28891. console.warn( 'THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps.' );
  28892. this.texture.generateMipmaps = value;
  28893. }
  28894. }
  28895. } );
  28896. //
  28897. Object.defineProperties( WebVRManager.prototype, {
  28898. standing: {
  28899. set: function ( /* value */ ) {
  28900. console.warn( 'THREE.WebVRManager: .standing has been removed.' );
  28901. }
  28902. },
  28903. userHeight: {
  28904. set: function ( /* value */ ) {
  28905. console.warn( 'THREE.WebVRManager: .userHeight has been removed.' );
  28906. }
  28907. }
  28908. } );
  28909. //
  28910. Audio.prototype.load = function ( file ) {
  28911. console.warn( 'THREE.Audio: .load has been deprecated. Use THREE.AudioLoader instead.' );
  28912. var scope = this;
  28913. var audioLoader = new AudioLoader();
  28914. audioLoader.load( file, function ( buffer ) {
  28915. scope.setBuffer( buffer );
  28916. } );
  28917. return this;
  28918. };
  28919. AudioAnalyser.prototype.getData = function () {
  28920. console.warn( 'THREE.AudioAnalyser: .getData() is now .getFrequencyData().' );
  28921. return this.getFrequencyData();
  28922. };
  28923. //
  28924. CubeCamera.prototype.updateCubeMap = function ( renderer, scene ) {
  28925. console.warn( 'THREE.CubeCamera: .updateCubeMap() is now .update().' );
  28926. return this.update( renderer, scene );
  28927. };
  28928. //
  28929. var GeometryUtils = {
  28930. merge: function ( geometry1, geometry2, materialIndexOffset ) {
  28931. console.warn( 'THREE.GeometryUtils: .merge() has been moved to Geometry. Use geometry.merge( geometry2, matrix, materialIndexOffset ) instead.' );
  28932. var matrix;
  28933. if ( geometry2.isMesh ) {
  28934. geometry2.matrixAutoUpdate && geometry2.updateMatrix();
  28935. matrix = geometry2.matrix;
  28936. geometry2 = geometry2.geometry;
  28937. }
  28938. geometry1.merge( geometry2, matrix, materialIndexOffset );
  28939. },
  28940. center: function ( geometry ) {
  28941. console.warn( 'THREE.GeometryUtils: .center() has been moved to Geometry. Use geometry.center() instead.' );
  28942. return geometry.center();
  28943. }
  28944. };
  28945. ImageUtils.crossOrigin = undefined;
  28946. ImageUtils.loadTexture = function ( url, mapping, onLoad, onError ) {
  28947. console.warn( 'THREE.ImageUtils.loadTexture has been deprecated. Use THREE.TextureLoader() instead.' );
  28948. var loader = new TextureLoader();
  28949. loader.setCrossOrigin( this.crossOrigin );
  28950. var texture = loader.load( url, onLoad, undefined, onError );
  28951. if ( mapping ) texture.mapping = mapping;
  28952. return texture;
  28953. };
  28954. ImageUtils.loadTextureCube = function ( urls, mapping, onLoad, onError ) {
  28955. console.warn( 'THREE.ImageUtils.loadTextureCube has been deprecated. Use THREE.CubeTextureLoader() instead.' );
  28956. var loader = new CubeTextureLoader();
  28957. loader.setCrossOrigin( this.crossOrigin );
  28958. var texture = loader.load( urls, onLoad, undefined, onError );
  28959. if ( mapping ) texture.mapping = mapping;
  28960. return texture;
  28961. };
  28962. ImageUtils.loadCompressedTexture = function () {
  28963. console.error( 'THREE.ImageUtils.loadCompressedTexture has been removed. Use THREE.DDSLoader instead.' );
  28964. };
  28965. ImageUtils.loadCompressedTextureCube = function () {
  28966. console.error( 'THREE.ImageUtils.loadCompressedTextureCube has been removed. Use THREE.DDSLoader instead.' );
  28967. };
  28968. //
  28969. function Projector() {
  28970. console.error( 'THREE.Projector has been moved to /examples/js/renderers/Projector.js.' );
  28971. this.projectVector = function ( vector, camera ) {
  28972. console.warn( 'THREE.Projector: .projectVector() is now vector.project().' );
  28973. vector.project( camera );
  28974. };
  28975. this.unprojectVector = function ( vector, camera ) {
  28976. console.warn( 'THREE.Projector: .unprojectVector() is now vector.unproject().' );
  28977. vector.unproject( camera );
  28978. };
  28979. this.pickingRay = function () {
  28980. console.error( 'THREE.Projector: .pickingRay() is now raycaster.setFromCamera().' );
  28981. };
  28982. }
  28983. //
  28984. function CanvasRenderer() {
  28985. console.error( 'THREE.CanvasRenderer has been removed' );
  28986. }
  28987. //
  28988. function JSONLoader() {
  28989. console.error( 'THREE.JSONLoader has been removed.' );
  28990. }
  28991. //
  28992. var SceneUtils = {
  28993. createMultiMaterialObject: function ( /* geometry, materials */ ) {
  28994. console.error( 'THREE.SceneUtils has been moved to /examples/js/utils/SceneUtils.js' );
  28995. },
  28996. detach: function ( /* child, parent, scene */ ) {
  28997. console.error( 'THREE.SceneUtils has been moved to /examples/js/utils/SceneUtils.js' );
  28998. },
  28999. attach: function ( /* child, scene, parent */ ) {
  29000. console.error( 'THREE.SceneUtils has been moved to /examples/js/utils/SceneUtils.js' );
  29001. }
  29002. };
  29003. //
  29004. function LensFlare() {
  29005. console.error( 'THREE.LensFlare has been moved to /examples/js/objects/Lensflare.js' );
  29006. }
  29007. exports.WebGLMultisampleRenderTarget = WebGLMultisampleRenderTarget;
  29008. exports.WebGLRenderTargetCube = WebGLRenderTargetCube;
  29009. exports.WebGLRenderTarget = WebGLRenderTarget;
  29010. exports.WebGLRenderer = WebGLRenderer;
  29011. exports.ShaderLib = ShaderLib;
  29012. exports.UniformsLib = UniformsLib;
  29013. exports.UniformsUtils = UniformsUtils;
  29014. exports.ShaderChunk = ShaderChunk;
  29015. exports.FogExp2 = FogExp2;
  29016. exports.Fog = Fog;
  29017. exports.Scene = Scene;
  29018. exports.Sprite = Sprite;
  29019. exports.LOD = LOD;
  29020. exports.SkinnedMesh = SkinnedMesh;
  29021. exports.Skeleton = Skeleton;
  29022. exports.Bone = Bone;
  29023. exports.Mesh = Mesh;
  29024. exports.LineSegments = LineSegments;
  29025. exports.LineLoop = LineLoop;
  29026. exports.Line = Line;
  29027. exports.Points = Points;
  29028. exports.Group = Group;
  29029. exports.VideoTexture = VideoTexture;
  29030. exports.DataTexture = DataTexture;
  29031. exports.DataTexture2DArray = DataTexture2DArray;
  29032. exports.DataTexture3D = DataTexture3D;
  29033. exports.CompressedTexture = CompressedTexture;
  29034. exports.CubeTexture = CubeTexture;
  29035. exports.CanvasTexture = CanvasTexture;
  29036. exports.DepthTexture = DepthTexture;
  29037. exports.Texture = Texture;
  29038. exports.AnimationLoader = AnimationLoader;
  29039. exports.CompressedTextureLoader = CompressedTextureLoader;
  29040. exports.DataTextureLoader = DataTextureLoader;
  29041. exports.CubeTextureLoader = CubeTextureLoader;
  29042. exports.TextureLoader = TextureLoader;
  29043. exports.ObjectLoader = ObjectLoader;
  29044. exports.MaterialLoader = MaterialLoader;
  29045. exports.BufferGeometryLoader = BufferGeometryLoader;
  29046. exports.DefaultLoadingManager = DefaultLoadingManager;
  29047. exports.LoadingManager = LoadingManager;
  29048. exports.ImageLoader = ImageLoader;
  29049. exports.ImageBitmapLoader = ImageBitmapLoader;
  29050. exports.FontLoader = FontLoader;
  29051. exports.FileLoader = FileLoader;
  29052. exports.Loader = Loader;
  29053. exports.LoaderUtils = LoaderUtils;
  29054. exports.Cache = Cache;
  29055. exports.AudioLoader = AudioLoader;
  29056. exports.SpotLightShadow = SpotLightShadow;
  29057. exports.SpotLight = SpotLight;
  29058. exports.PointLight = PointLight;
  29059. exports.RectAreaLight = RectAreaLight;
  29060. exports.HemisphereLight = HemisphereLight;
  29061. exports.HemisphereLightProbe = HemisphereLightProbe;
  29062. exports.DirectionalLightShadow = DirectionalLightShadow;
  29063. exports.DirectionalLight = DirectionalLight;
  29064. exports.AmbientLight = AmbientLight;
  29065. exports.AmbientLightProbe = AmbientLightProbe;
  29066. exports.LightShadow = LightShadow;
  29067. exports.Light = Light;
  29068. exports.LightProbe = LightProbe;
  29069. exports.StereoCamera = StereoCamera;
  29070. exports.PerspectiveCamera = PerspectiveCamera;
  29071. exports.OrthographicCamera = OrthographicCamera;
  29072. exports.CubeCamera = CubeCamera;
  29073. exports.ArrayCamera = ArrayCamera;
  29074. exports.Camera = Camera;
  29075. exports.AudioListener = AudioListener;
  29076. exports.PositionalAudio = PositionalAudio;
  29077. exports.AudioContext = AudioContext;
  29078. exports.AudioAnalyser = AudioAnalyser;
  29079. exports.Audio = Audio;
  29080. exports.VectorKeyframeTrack = VectorKeyframeTrack;
  29081. exports.StringKeyframeTrack = StringKeyframeTrack;
  29082. exports.QuaternionKeyframeTrack = QuaternionKeyframeTrack;
  29083. exports.NumberKeyframeTrack = NumberKeyframeTrack;
  29084. exports.ColorKeyframeTrack = ColorKeyframeTrack;
  29085. exports.BooleanKeyframeTrack = BooleanKeyframeTrack;
  29086. exports.PropertyMixer = PropertyMixer;
  29087. exports.PropertyBinding = PropertyBinding;
  29088. exports.KeyframeTrack = KeyframeTrack;
  29089. exports.AnimationUtils = AnimationUtils;
  29090. exports.AnimationObjectGroup = AnimationObjectGroup;
  29091. exports.AnimationMixer = AnimationMixer;
  29092. exports.AnimationClip = AnimationClip;
  29093. exports.Uniform = Uniform;
  29094. exports.InstancedBufferGeometry = InstancedBufferGeometry;
  29095. exports.BufferGeometry = BufferGeometry;
  29096. exports.Geometry = Geometry;
  29097. exports.InterleavedBufferAttribute = InterleavedBufferAttribute;
  29098. exports.InstancedInterleavedBuffer = InstancedInterleavedBuffer;
  29099. exports.InterleavedBuffer = InterleavedBuffer;
  29100. exports.InstancedBufferAttribute = InstancedBufferAttribute;
  29101. exports.Face3 = Face3;
  29102. exports.Object3D = Object3D;
  29103. exports.Raycaster = Raycaster;
  29104. exports.Layers = Layers;
  29105. exports.EventDispatcher = EventDispatcher;
  29106. exports.Clock = Clock;
  29107. exports.QuaternionLinearInterpolant = QuaternionLinearInterpolant;
  29108. exports.LinearInterpolant = LinearInterpolant;
  29109. exports.DiscreteInterpolant = DiscreteInterpolant;
  29110. exports.CubicInterpolant = CubicInterpolant;
  29111. exports.Interpolant = Interpolant;
  29112. exports.Triangle = Triangle;
  29113. exports.Math = _Math;
  29114. exports.Spherical = Spherical;
  29115. exports.Cylindrical = Cylindrical;
  29116. exports.Plane = Plane;
  29117. exports.Frustum = Frustum;
  29118. exports.Sphere = Sphere;
  29119. exports.Ray = Ray;
  29120. exports.Matrix4 = Matrix4;
  29121. exports.Matrix3 = Matrix3;
  29122. exports.Box3 = Box3;
  29123. exports.Box2 = Box2;
  29124. exports.Line3 = Line3;
  29125. exports.Euler = Euler;
  29126. exports.Vector4 = Vector4;
  29127. exports.Vector3 = Vector3;
  29128. exports.Vector2 = Vector2;
  29129. exports.Quaternion = Quaternion;
  29130. exports.Color = Color;
  29131. exports.SphericalHarmonics3 = SphericalHarmonics3;
  29132. exports.ImmediateRenderObject = ImmediateRenderObject;
  29133. exports.VertexNormalsHelper = VertexNormalsHelper;
  29134. exports.SpotLightHelper = SpotLightHelper;
  29135. exports.SkeletonHelper = SkeletonHelper;
  29136. exports.PointLightHelper = PointLightHelper;
  29137. exports.RectAreaLightHelper = RectAreaLightHelper;
  29138. exports.HemisphereLightHelper = HemisphereLightHelper;
  29139. exports.LightProbeHelper = LightProbeHelper;
  29140. exports.GridHelper = GridHelper;
  29141. exports.PolarGridHelper = PolarGridHelper;
  29142. exports.PositionalAudioHelper = PositionalAudioHelper;
  29143. exports.FaceNormalsHelper = FaceNormalsHelper;
  29144. exports.DirectionalLightHelper = DirectionalLightHelper;
  29145. exports.CameraHelper = CameraHelper;
  29146. exports.BoxHelper = BoxHelper;
  29147. exports.Box3Helper = Box3Helper;
  29148. exports.PlaneHelper = PlaneHelper;
  29149. exports.ArrowHelper = ArrowHelper;
  29150. exports.AxesHelper = AxesHelper;
  29151. exports.Shape = Shape;
  29152. exports.Path = Path;
  29153. exports.ShapePath = ShapePath;
  29154. exports.Font = Font;
  29155. exports.CurvePath = CurvePath;
  29156. exports.Curve = Curve;
  29157. exports.ImageUtils = ImageUtils;
  29158. exports.ShapeUtils = ShapeUtils;
  29159. exports.WebGLUtils = WebGLUtils;
  29160. exports.WireframeGeometry = WireframeGeometry;
  29161. exports.ParametricGeometry = ParametricGeometry;
  29162. exports.ParametricBufferGeometry = ParametricBufferGeometry;
  29163. exports.TetrahedronGeometry = TetrahedronGeometry;
  29164. exports.TetrahedronBufferGeometry = TetrahedronBufferGeometry;
  29165. exports.OctahedronGeometry = OctahedronGeometry;
  29166. exports.OctahedronBufferGeometry = OctahedronBufferGeometry;
  29167. exports.IcosahedronGeometry = IcosahedronGeometry;
  29168. exports.IcosahedronBufferGeometry = IcosahedronBufferGeometry;
  29169. exports.DodecahedronGeometry = DodecahedronGeometry;
  29170. exports.DodecahedronBufferGeometry = DodecahedronBufferGeometry;
  29171. exports.PolyhedronGeometry = PolyhedronGeometry;
  29172. exports.PolyhedronBufferGeometry = PolyhedronBufferGeometry;
  29173. exports.TubeGeometry = TubeGeometry;
  29174. exports.TubeBufferGeometry = TubeBufferGeometry;
  29175. exports.TorusKnotGeometry = TorusKnotGeometry;
  29176. exports.TorusKnotBufferGeometry = TorusKnotBufferGeometry;
  29177. exports.TorusGeometry = TorusGeometry;
  29178. exports.TorusBufferGeometry = TorusBufferGeometry;
  29179. exports.TextGeometry = TextGeometry;
  29180. exports.TextBufferGeometry = TextBufferGeometry;
  29181. exports.SphereGeometry = SphereGeometry;
  29182. exports.SphereBufferGeometry = SphereBufferGeometry;
  29183. exports.RingGeometry = RingGeometry;
  29184. exports.RingBufferGeometry = RingBufferGeometry;
  29185. exports.PlaneGeometry = PlaneGeometry;
  29186. exports.PlaneBufferGeometry = PlaneBufferGeometry;
  29187. exports.LatheGeometry = LatheGeometry;
  29188. exports.LatheBufferGeometry = LatheBufferGeometry;
  29189. exports.ShapeGeometry = ShapeGeometry;
  29190. exports.ShapeBufferGeometry = ShapeBufferGeometry;
  29191. exports.ExtrudeGeometry = ExtrudeGeometry;
  29192. exports.ExtrudeBufferGeometry = ExtrudeBufferGeometry;
  29193. exports.EdgesGeometry = EdgesGeometry;
  29194. exports.ConeGeometry = ConeGeometry;
  29195. exports.ConeBufferGeometry = ConeBufferGeometry;
  29196. exports.CylinderGeometry = CylinderGeometry;
  29197. exports.CylinderBufferGeometry = CylinderBufferGeometry;
  29198. exports.CircleGeometry = CircleGeometry;
  29199. exports.CircleBufferGeometry = CircleBufferGeometry;
  29200. exports.BoxGeometry = BoxGeometry;
  29201. exports.CubeGeometry = BoxGeometry;
  29202. exports.BoxBufferGeometry = BoxBufferGeometry;
  29203. exports.ShadowMaterial = ShadowMaterial;
  29204. exports.SpriteMaterial = SpriteMaterial;
  29205. exports.RawShaderMaterial = RawShaderMaterial;
  29206. exports.ShaderMaterial = ShaderMaterial;
  29207. exports.PointsMaterial = PointsMaterial;
  29208. exports.MeshPhysicalMaterial = MeshPhysicalMaterial;
  29209. exports.MeshStandardMaterial = MeshStandardMaterial;
  29210. exports.MeshPhongMaterial = MeshPhongMaterial;
  29211. exports.MeshToonMaterial = MeshToonMaterial;
  29212. exports.MeshNormalMaterial = MeshNormalMaterial;
  29213. exports.MeshLambertMaterial = MeshLambertMaterial;
  29214. exports.MeshDepthMaterial = MeshDepthMaterial;
  29215. exports.MeshDistanceMaterial = MeshDistanceMaterial;
  29216. exports.MeshBasicMaterial = MeshBasicMaterial;
  29217. exports.MeshMatcapMaterial = MeshMatcapMaterial;
  29218. exports.LineDashedMaterial = LineDashedMaterial;
  29219. exports.LineBasicMaterial = LineBasicMaterial;
  29220. exports.Material = Material;
  29221. exports.Float64BufferAttribute = Float64BufferAttribute;
  29222. exports.Float32BufferAttribute = Float32BufferAttribute;
  29223. exports.Uint32BufferAttribute = Uint32BufferAttribute;
  29224. exports.Int32BufferAttribute = Int32BufferAttribute;
  29225. exports.Uint16BufferAttribute = Uint16BufferAttribute;
  29226. exports.Int16BufferAttribute = Int16BufferAttribute;
  29227. exports.Uint8ClampedBufferAttribute = Uint8ClampedBufferAttribute;
  29228. exports.Uint8BufferAttribute = Uint8BufferAttribute;
  29229. exports.Int8BufferAttribute = Int8BufferAttribute;
  29230. exports.BufferAttribute = BufferAttribute;
  29231. exports.ArcCurve = ArcCurve;
  29232. exports.CatmullRomCurve3 = CatmullRomCurve3;
  29233. exports.CubicBezierCurve = CubicBezierCurve;
  29234. exports.CubicBezierCurve3 = CubicBezierCurve3;
  29235. exports.EllipseCurve = EllipseCurve;
  29236. exports.LineCurve = LineCurve;
  29237. exports.LineCurve3 = LineCurve3;
  29238. exports.QuadraticBezierCurve = QuadraticBezierCurve;
  29239. exports.QuadraticBezierCurve3 = QuadraticBezierCurve3;
  29240. exports.SplineCurve = SplineCurve;
  29241. exports.REVISION = REVISION;
  29242. exports.MOUSE = MOUSE;
  29243. exports.CullFaceNone = CullFaceNone;
  29244. exports.CullFaceBack = CullFaceBack;
  29245. exports.CullFaceFront = CullFaceFront;
  29246. exports.CullFaceFrontBack = CullFaceFrontBack;
  29247. exports.FrontFaceDirectionCW = FrontFaceDirectionCW;
  29248. exports.FrontFaceDirectionCCW = FrontFaceDirectionCCW;
  29249. exports.BasicShadowMap = BasicShadowMap;
  29250. exports.PCFShadowMap = PCFShadowMap;
  29251. exports.PCFSoftShadowMap = PCFSoftShadowMap;
  29252. exports.FrontSide = FrontSide;
  29253. exports.BackSide = BackSide;
  29254. exports.DoubleSide = DoubleSide;
  29255. exports.FlatShading = FlatShading;
  29256. exports.SmoothShading = SmoothShading;
  29257. exports.NoColors = NoColors;
  29258. exports.FaceColors = FaceColors;
  29259. exports.VertexColors = VertexColors;
  29260. exports.NoBlending = NoBlending;
  29261. exports.NormalBlending = NormalBlending;
  29262. exports.AdditiveBlending = AdditiveBlending;
  29263. exports.SubtractiveBlending = SubtractiveBlending;
  29264. exports.MultiplyBlending = MultiplyBlending;
  29265. exports.CustomBlending = CustomBlending;
  29266. exports.AddEquation = AddEquation;
  29267. exports.SubtractEquation = SubtractEquation;
  29268. exports.ReverseSubtractEquation = ReverseSubtractEquation;
  29269. exports.MinEquation = MinEquation;
  29270. exports.MaxEquation = MaxEquation;
  29271. exports.ZeroFactor = ZeroFactor;
  29272. exports.OneFactor = OneFactor;
  29273. exports.SrcColorFactor = SrcColorFactor;
  29274. exports.OneMinusSrcColorFactor = OneMinusSrcColorFactor;
  29275. exports.SrcAlphaFactor = SrcAlphaFactor;
  29276. exports.OneMinusSrcAlphaFactor = OneMinusSrcAlphaFactor;
  29277. exports.DstAlphaFactor = DstAlphaFactor;
  29278. exports.OneMinusDstAlphaFactor = OneMinusDstAlphaFactor;
  29279. exports.DstColorFactor = DstColorFactor;
  29280. exports.OneMinusDstColorFactor = OneMinusDstColorFactor;
  29281. exports.SrcAlphaSaturateFactor = SrcAlphaSaturateFactor;
  29282. exports.NeverDepth = NeverDepth;
  29283. exports.AlwaysDepth = AlwaysDepth;
  29284. exports.LessDepth = LessDepth;
  29285. exports.LessEqualDepth = LessEqualDepth;
  29286. exports.EqualDepth = EqualDepth;
  29287. exports.GreaterEqualDepth = GreaterEqualDepth;
  29288. exports.GreaterDepth = GreaterDepth;
  29289. exports.NotEqualDepth = NotEqualDepth;
  29290. exports.MultiplyOperation = MultiplyOperation;
  29291. exports.MixOperation = MixOperation;
  29292. exports.AddOperation = AddOperation;
  29293. exports.NoToneMapping = NoToneMapping;
  29294. exports.LinearToneMapping = LinearToneMapping;
  29295. exports.ReinhardToneMapping = ReinhardToneMapping;
  29296. exports.Uncharted2ToneMapping = Uncharted2ToneMapping;
  29297. exports.CineonToneMapping = CineonToneMapping;
  29298. exports.ACESFilmicToneMapping = ACESFilmicToneMapping;
  29299. exports.UVMapping = UVMapping;
  29300. exports.CubeReflectionMapping = CubeReflectionMapping;
  29301. exports.CubeRefractionMapping = CubeRefractionMapping;
  29302. exports.EquirectangularReflectionMapping = EquirectangularReflectionMapping;
  29303. exports.EquirectangularRefractionMapping = EquirectangularRefractionMapping;
  29304. exports.SphericalReflectionMapping = SphericalReflectionMapping;
  29305. exports.CubeUVReflectionMapping = CubeUVReflectionMapping;
  29306. exports.CubeUVRefractionMapping = CubeUVRefractionMapping;
  29307. exports.RepeatWrapping = RepeatWrapping;
  29308. exports.ClampToEdgeWrapping = ClampToEdgeWrapping;
  29309. exports.MirroredRepeatWrapping = MirroredRepeatWrapping;
  29310. exports.NearestFilter = NearestFilter;
  29311. exports.NearestMipMapNearestFilter = NearestMipMapNearestFilter;
  29312. exports.NearestMipMapLinearFilter = NearestMipMapLinearFilter;
  29313. exports.LinearFilter = LinearFilter;
  29314. exports.LinearMipMapNearestFilter = LinearMipMapNearestFilter;
  29315. exports.LinearMipMapLinearFilter = LinearMipMapLinearFilter;
  29316. exports.UnsignedByteType = UnsignedByteType;
  29317. exports.ByteType = ByteType;
  29318. exports.ShortType = ShortType;
  29319. exports.UnsignedShortType = UnsignedShortType;
  29320. exports.IntType = IntType;
  29321. exports.UnsignedIntType = UnsignedIntType;
  29322. exports.FloatType = FloatType;
  29323. exports.HalfFloatType = HalfFloatType;
  29324. exports.UnsignedShort4444Type = UnsignedShort4444Type;
  29325. exports.UnsignedShort5551Type = UnsignedShort5551Type;
  29326. exports.UnsignedShort565Type = UnsignedShort565Type;
  29327. exports.UnsignedInt248Type = UnsignedInt248Type;
  29328. exports.AlphaFormat = AlphaFormat;
  29329. exports.RGBFormat = RGBFormat;
  29330. exports.RGBAFormat = RGBAFormat;
  29331. exports.LuminanceFormat = LuminanceFormat;
  29332. exports.LuminanceAlphaFormat = LuminanceAlphaFormat;
  29333. exports.RGBEFormat = RGBEFormat;
  29334. exports.DepthFormat = DepthFormat;
  29335. exports.DepthStencilFormat = DepthStencilFormat;
  29336. exports.RedFormat = RedFormat;
  29337. exports.RGB_S3TC_DXT1_Format = RGB_S3TC_DXT1_Format;
  29338. exports.RGBA_S3TC_DXT1_Format = RGBA_S3TC_DXT1_Format;
  29339. exports.RGBA_S3TC_DXT3_Format = RGBA_S3TC_DXT3_Format;
  29340. exports.RGBA_S3TC_DXT5_Format = RGBA_S3TC_DXT5_Format;
  29341. exports.RGB_PVRTC_4BPPV1_Format = RGB_PVRTC_4BPPV1_Format;
  29342. exports.RGB_PVRTC_2BPPV1_Format = RGB_PVRTC_2BPPV1_Format;
  29343. exports.RGBA_PVRTC_4BPPV1_Format = RGBA_PVRTC_4BPPV1_Format;
  29344. exports.RGBA_PVRTC_2BPPV1_Format = RGBA_PVRTC_2BPPV1_Format;
  29345. exports.RGB_ETC1_Format = RGB_ETC1_Format;
  29346. exports.RGBA_ASTC_4x4_Format = RGBA_ASTC_4x4_Format;
  29347. exports.RGBA_ASTC_5x4_Format = RGBA_ASTC_5x4_Format;
  29348. exports.RGBA_ASTC_5x5_Format = RGBA_ASTC_5x5_Format;
  29349. exports.RGBA_ASTC_6x5_Format = RGBA_ASTC_6x5_Format;
  29350. exports.RGBA_ASTC_6x6_Format = RGBA_ASTC_6x6_Format;
  29351. exports.RGBA_ASTC_8x5_Format = RGBA_ASTC_8x5_Format;
  29352. exports.RGBA_ASTC_8x6_Format = RGBA_ASTC_8x6_Format;
  29353. exports.RGBA_ASTC_8x8_Format = RGBA_ASTC_8x8_Format;
  29354. exports.RGBA_ASTC_10x5_Format = RGBA_ASTC_10x5_Format;
  29355. exports.RGBA_ASTC_10x6_Format = RGBA_ASTC_10x6_Format;
  29356. exports.RGBA_ASTC_10x8_Format = RGBA_ASTC_10x8_Format;
  29357. exports.RGBA_ASTC_10x10_Format = RGBA_ASTC_10x10_Format;
  29358. exports.RGBA_ASTC_12x10_Format = RGBA_ASTC_12x10_Format;
  29359. exports.RGBA_ASTC_12x12_Format = RGBA_ASTC_12x12_Format;
  29360. exports.LoopOnce = LoopOnce;
  29361. exports.LoopRepeat = LoopRepeat;
  29362. exports.LoopPingPong = LoopPingPong;
  29363. exports.InterpolateDiscrete = InterpolateDiscrete;
  29364. exports.InterpolateLinear = InterpolateLinear;
  29365. exports.InterpolateSmooth = InterpolateSmooth;
  29366. exports.ZeroCurvatureEnding = ZeroCurvatureEnding;
  29367. exports.ZeroSlopeEnding = ZeroSlopeEnding;
  29368. exports.WrapAroundEnding = WrapAroundEnding;
  29369. exports.TrianglesDrawMode = TrianglesDrawMode;
  29370. exports.TriangleStripDrawMode = TriangleStripDrawMode;
  29371. exports.TriangleFanDrawMode = TriangleFanDrawMode;
  29372. exports.LinearEncoding = LinearEncoding;
  29373. exports.sRGBEncoding = sRGBEncoding;
  29374. exports.GammaEncoding = GammaEncoding;
  29375. exports.RGBEEncoding = RGBEEncoding;
  29376. exports.LogLuvEncoding = LogLuvEncoding;
  29377. exports.RGBM7Encoding = RGBM7Encoding;
  29378. exports.RGBM16Encoding = RGBM16Encoding;
  29379. exports.RGBDEncoding = RGBDEncoding;
  29380. exports.BasicDepthPacking = BasicDepthPacking;
  29381. exports.RGBADepthPacking = RGBADepthPacking;
  29382. exports.TangentSpaceNormalMap = TangentSpaceNormalMap;
  29383. exports.ObjectSpaceNormalMap = ObjectSpaceNormalMap;
  29384. exports.Face4 = Face4;
  29385. exports.LineStrip = LineStrip;
  29386. exports.LinePieces = LinePieces;
  29387. exports.MeshFaceMaterial = MeshFaceMaterial;
  29388. exports.MultiMaterial = MultiMaterial;
  29389. exports.PointCloud = PointCloud;
  29390. exports.Particle = Particle;
  29391. exports.ParticleSystem = ParticleSystem;
  29392. exports.PointCloudMaterial = PointCloudMaterial;
  29393. exports.ParticleBasicMaterial = ParticleBasicMaterial;
  29394. exports.ParticleSystemMaterial = ParticleSystemMaterial;
  29395. exports.Vertex = Vertex;
  29396. exports.DynamicBufferAttribute = DynamicBufferAttribute;
  29397. exports.Int8Attribute = Int8Attribute;
  29398. exports.Uint8Attribute = Uint8Attribute;
  29399. exports.Uint8ClampedAttribute = Uint8ClampedAttribute;
  29400. exports.Int16Attribute = Int16Attribute;
  29401. exports.Uint16Attribute = Uint16Attribute;
  29402. exports.Int32Attribute = Int32Attribute;
  29403. exports.Uint32Attribute = Uint32Attribute;
  29404. exports.Float32Attribute = Float32Attribute;
  29405. exports.Float64Attribute = Float64Attribute;
  29406. exports.ClosedSplineCurve3 = ClosedSplineCurve3;
  29407. exports.SplineCurve3 = SplineCurve3;
  29408. exports.Spline = Spline;
  29409. exports.AxisHelper = AxisHelper;
  29410. exports.BoundingBoxHelper = BoundingBoxHelper;
  29411. exports.EdgesHelper = EdgesHelper;
  29412. exports.WireframeHelper = WireframeHelper;
  29413. exports.XHRLoader = XHRLoader;
  29414. exports.BinaryTextureLoader = BinaryTextureLoader;
  29415. exports.GeometryUtils = GeometryUtils;
  29416. exports.Projector = Projector;
  29417. exports.CanvasRenderer = CanvasRenderer;
  29418. exports.JSONLoader = JSONLoader;
  29419. exports.SceneUtils = SceneUtils;
  29420. exports.LensFlare = LensFlare;
  29421. Object.defineProperty(exports, '__esModule', { value: true });
  29422. }));