three.js 1.1 MB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520225212252222523225242252522526225272252822529225302253122532225332253422535225362253722538225392254022541225422254322544225452254622547225482254922550225512255222553225542255522556225572255822559225602256122562225632256422565225662256722568225692257022571225722257322574225752257622577225782257922580225812258222583225842258522586225872258822589225902259122592225932259422595225962259722598225992260022601226022260322604226052260622607226082260922610226112261222613226142261522616226172261822619226202262122622226232262422625226262262722628226292263022631226322263322634226352263622637226382263922640226412264222643226442264522646226472264822649226502265122652226532265422655226562265722658226592266022661226622266322664226652266622667226682266922670226712267222673226742267522676226772267822679226802268122682226832268422685226862268722688226892269022691226922269322694226952269622697226982269922700227012270222703227042270522706227072270822709227102271122712227132271422715227162271722718227192272022721227222272322724227252272622727227282272922730227312273222733227342273522736227372273822739227402274122742227432274422745227462274722748227492275022751227522275322754227552275622757227582275922760227612276222763227642276522766227672276822769227702277122772227732277422775227762277722778227792278022781227822278322784227852278622787227882278922790227912279222793227942279522796227972279822799228002280122802228032280422805228062280722808228092281022811228122281322814228152281622817228182281922820228212282222823228242282522826228272282822829228302283122832228332283422835228362283722838228392284022841228422284322844228452284622847228482284922850228512285222853228542285522856228572285822859228602286122862228632286422865228662286722868228692287022871228722287322874228752287622877228782287922880228812288222883228842288522886228872288822889228902289122892228932289422895228962289722898228992290022901229022290322904229052290622907229082290922910229112291222913229142291522916229172291822919229202292122922229232292422925229262292722928229292293022931229322293322934229352293622937229382293922940229412294222943229442294522946229472294822949229502295122952229532295422955229562295722958229592296022961229622296322964229652296622967229682296922970229712297222973229742297522976229772297822979229802298122982229832298422985229862298722988229892299022991229922299322994229952299622997229982299923000230012300223003230042300523006230072300823009230102301123012230132301423015230162301723018230192302023021230222302323024230252302623027230282302923030230312303223033230342303523036230372303823039230402304123042230432304423045230462304723048230492305023051230522305323054230552305623057230582305923060230612306223063230642306523066230672306823069230702307123072230732307423075230762307723078230792308023081230822308323084230852308623087230882308923090230912309223093230942309523096230972309823099231002310123102231032310423105231062310723108231092311023111231122311323114231152311623117231182311923120231212312223123231242312523126231272312823129231302313123132231332313423135231362313723138231392314023141231422314323144231452314623147231482314923150231512315223153231542315523156231572315823159231602316123162231632316423165231662316723168231692317023171231722317323174231752317623177231782317923180231812318223183231842318523186231872318823189231902319123192231932319423195231962319723198231992320023201232022320323204232052320623207232082320923210232112321223213232142321523216232172321823219232202322123222232232322423225232262322723228232292323023231232322323323234232352323623237232382323923240232412324223243232442324523246232472324823249232502325123252232532325423255232562325723258232592326023261232622326323264232652326623267232682326923270232712327223273232742327523276232772327823279232802328123282232832328423285232862328723288232892329023291232922329323294232952329623297232982329923300233012330223303233042330523306233072330823309233102331123312233132331423315233162331723318233192332023321233222332323324233252332623327233282332923330233312333223333233342333523336233372333823339233402334123342233432334423345233462334723348233492335023351233522335323354233552335623357233582335923360233612336223363233642336523366233672336823369233702337123372233732337423375233762337723378233792338023381233822338323384233852338623387233882338923390233912339223393233942339523396233972339823399234002340123402234032340423405234062340723408234092341023411234122341323414234152341623417234182341923420234212342223423234242342523426234272342823429234302343123432234332343423435234362343723438234392344023441234422344323444234452344623447234482344923450234512345223453234542345523456234572345823459234602346123462234632346423465234662346723468234692347023471234722347323474234752347623477234782347923480234812348223483234842348523486234872348823489234902349123492234932349423495234962349723498234992350023501235022350323504235052350623507235082350923510235112351223513235142351523516235172351823519235202352123522235232352423525235262352723528235292353023531235322353323534235352353623537235382353923540235412354223543235442354523546235472354823549235502355123552235532355423555235562355723558235592356023561235622356323564235652356623567235682356923570235712357223573235742357523576235772357823579235802358123582235832358423585235862358723588235892359023591235922359323594235952359623597235982359923600236012360223603236042360523606236072360823609236102361123612236132361423615236162361723618236192362023621236222362323624236252362623627236282362923630236312363223633236342363523636236372363823639236402364123642236432364423645236462364723648236492365023651236522365323654236552365623657236582365923660236612366223663236642366523666236672366823669236702367123672236732367423675236762367723678236792368023681236822368323684236852368623687236882368923690236912369223693236942369523696236972369823699237002370123702237032370423705237062370723708237092371023711237122371323714237152371623717237182371923720237212372223723237242372523726237272372823729237302373123732237332373423735237362373723738237392374023741237422374323744237452374623747237482374923750237512375223753237542375523756237572375823759237602376123762237632376423765237662376723768237692377023771237722377323774237752377623777237782377923780237812378223783237842378523786237872378823789237902379123792237932379423795237962379723798237992380023801238022380323804238052380623807238082380923810238112381223813238142381523816238172381823819238202382123822238232382423825238262382723828238292383023831238322383323834238352383623837238382383923840238412384223843238442384523846238472384823849238502385123852238532385423855238562385723858238592386023861238622386323864238652386623867238682386923870238712387223873238742387523876238772387823879238802388123882238832388423885238862388723888238892389023891238922389323894238952389623897238982389923900239012390223903239042390523906239072390823909239102391123912239132391423915239162391723918239192392023921239222392323924239252392623927239282392923930239312393223933239342393523936239372393823939239402394123942239432394423945239462394723948239492395023951239522395323954239552395623957239582395923960239612396223963239642396523966239672396823969239702397123972239732397423975239762397723978239792398023981239822398323984239852398623987239882398923990239912399223993239942399523996239972399823999240002400124002240032400424005240062400724008240092401024011240122401324014240152401624017240182401924020240212402224023240242402524026240272402824029240302403124032240332403424035240362403724038240392404024041240422404324044240452404624047240482404924050240512405224053240542405524056240572405824059240602406124062240632406424065240662406724068240692407024071240722407324074240752407624077240782407924080240812408224083240842408524086240872408824089240902409124092240932409424095240962409724098240992410024101241022410324104241052410624107241082410924110241112411224113241142411524116241172411824119241202412124122241232412424125241262412724128241292413024131241322413324134241352413624137241382413924140241412414224143241442414524146241472414824149241502415124152241532415424155241562415724158241592416024161241622416324164241652416624167241682416924170241712417224173241742417524176241772417824179241802418124182241832418424185241862418724188241892419024191241922419324194241952419624197241982419924200242012420224203242042420524206242072420824209242102421124212242132421424215242162421724218242192422024221242222422324224242252422624227242282422924230242312423224233242342423524236242372423824239242402424124242242432424424245242462424724248242492425024251242522425324254242552425624257242582425924260242612426224263242642426524266242672426824269242702427124272242732427424275242762427724278242792428024281242822428324284242852428624287242882428924290242912429224293242942429524296242972429824299243002430124302243032430424305243062430724308243092431024311243122431324314243152431624317243182431924320243212432224323243242432524326243272432824329243302433124332243332433424335243362433724338243392434024341243422434324344243452434624347243482434924350243512435224353243542435524356243572435824359243602436124362243632436424365243662436724368243692437024371243722437324374243752437624377243782437924380243812438224383243842438524386243872438824389243902439124392243932439424395243962439724398243992440024401244022440324404244052440624407244082440924410244112441224413244142441524416244172441824419244202442124422244232442424425244262442724428244292443024431244322443324434244352443624437244382443924440244412444224443244442444524446244472444824449244502445124452244532445424455244562445724458244592446024461244622446324464244652446624467244682446924470244712447224473244742447524476244772447824479244802448124482244832448424485244862448724488244892449024491244922449324494244952449624497244982449924500245012450224503245042450524506245072450824509245102451124512245132451424515245162451724518245192452024521245222452324524245252452624527245282452924530245312453224533245342453524536245372453824539245402454124542245432454424545245462454724548245492455024551245522455324554245552455624557245582455924560245612456224563245642456524566245672456824569245702457124572245732457424575245762457724578245792458024581245822458324584245852458624587245882458924590245912459224593245942459524596245972459824599246002460124602246032460424605246062460724608246092461024611246122461324614246152461624617246182461924620246212462224623246242462524626246272462824629246302463124632246332463424635246362463724638246392464024641246422464324644246452464624647246482464924650246512465224653246542465524656246572465824659246602466124662246632466424665246662466724668246692467024671246722467324674246752467624677246782467924680246812468224683246842468524686246872468824689246902469124692246932469424695246962469724698246992470024701247022470324704247052470624707247082470924710247112471224713247142471524716247172471824719247202472124722247232472424725247262472724728247292473024731247322473324734247352473624737247382473924740247412474224743247442474524746247472474824749247502475124752247532475424755247562475724758247592476024761247622476324764247652476624767247682476924770247712477224773247742477524776247772477824779247802478124782247832478424785247862478724788247892479024791247922479324794247952479624797247982479924800248012480224803248042480524806248072480824809248102481124812248132481424815248162481724818248192482024821248222482324824248252482624827248282482924830248312483224833248342483524836248372483824839248402484124842248432484424845248462484724848248492485024851248522485324854248552485624857248582485924860248612486224863248642486524866248672486824869248702487124872248732487424875248762487724878248792488024881248822488324884248852488624887248882488924890248912489224893248942489524896248972489824899249002490124902249032490424905249062490724908249092491024911249122491324914249152491624917249182491924920249212492224923249242492524926249272492824929249302493124932249332493424935249362493724938249392494024941249422494324944249452494624947249482494924950249512495224953249542495524956249572495824959249602496124962249632496424965249662496724968249692497024971249722497324974249752497624977249782497924980249812498224983249842498524986249872498824989249902499124992249932499424995249962499724998249992500025001250022500325004250052500625007250082500925010250112501225013250142501525016250172501825019250202502125022250232502425025250262502725028250292503025031250322503325034250352503625037250382503925040250412504225043250442504525046250472504825049250502505125052250532505425055250562505725058250592506025061250622506325064250652506625067250682506925070250712507225073250742507525076250772507825079250802508125082250832508425085250862508725088250892509025091250922509325094250952509625097250982509925100251012510225103251042510525106251072510825109251102511125112251132511425115251162511725118251192512025121251222512325124251252512625127251282512925130251312513225133251342513525136251372513825139251402514125142251432514425145251462514725148251492515025151251522515325154251552515625157251582515925160251612516225163251642516525166251672516825169251702517125172251732517425175251762517725178251792518025181251822518325184251852518625187251882518925190251912519225193251942519525196251972519825199252002520125202252032520425205252062520725208252092521025211252122521325214252152521625217252182521925220252212522225223252242522525226252272522825229252302523125232252332523425235252362523725238252392524025241252422524325244252452524625247252482524925250252512525225253252542525525256252572525825259252602526125262252632526425265252662526725268252692527025271252722527325274252752527625277252782527925280252812528225283252842528525286252872528825289252902529125292252932529425295252962529725298252992530025301253022530325304253052530625307253082530925310253112531225313253142531525316253172531825319253202532125322253232532425325253262532725328253292533025331253322533325334253352533625337253382533925340253412534225343253442534525346253472534825349253502535125352253532535425355253562535725358253592536025361253622536325364253652536625367253682536925370253712537225373253742537525376253772537825379253802538125382253832538425385253862538725388253892539025391253922539325394253952539625397253982539925400254012540225403254042540525406254072540825409254102541125412254132541425415254162541725418254192542025421254222542325424254252542625427254282542925430254312543225433254342543525436254372543825439254402544125442254432544425445254462544725448254492545025451254522545325454254552545625457254582545925460254612546225463254642546525466254672546825469254702547125472254732547425475254762547725478254792548025481254822548325484254852548625487254882548925490254912549225493254942549525496254972549825499255002550125502255032550425505255062550725508255092551025511255122551325514255152551625517255182551925520255212552225523255242552525526255272552825529255302553125532255332553425535255362553725538255392554025541255422554325544255452554625547255482554925550255512555225553255542555525556255572555825559255602556125562255632556425565255662556725568255692557025571255722557325574255752557625577255782557925580255812558225583255842558525586255872558825589255902559125592255932559425595255962559725598255992560025601256022560325604256052560625607256082560925610256112561225613256142561525616256172561825619256202562125622256232562425625256262562725628256292563025631256322563325634256352563625637256382563925640256412564225643256442564525646256472564825649256502565125652256532565425655256562565725658256592566025661256622566325664256652566625667256682566925670256712567225673256742567525676256772567825679256802568125682256832568425685256862568725688256892569025691256922569325694256952569625697256982569925700257012570225703257042570525706257072570825709257102571125712257132571425715257162571725718257192572025721257222572325724257252572625727257282572925730257312573225733257342573525736257372573825739257402574125742257432574425745257462574725748257492575025751257522575325754257552575625757257582575925760257612576225763257642576525766257672576825769257702577125772257732577425775257762577725778257792578025781257822578325784257852578625787257882578925790257912579225793257942579525796257972579825799258002580125802258032580425805258062580725808258092581025811258122581325814258152581625817258182581925820258212582225823258242582525826258272582825829258302583125832258332583425835258362583725838258392584025841258422584325844258452584625847258482584925850258512585225853258542585525856258572585825859258602586125862258632586425865258662586725868258692587025871258722587325874258752587625877258782587925880258812588225883258842588525886258872588825889258902589125892258932589425895258962589725898258992590025901259022590325904259052590625907259082590925910259112591225913259142591525916259172591825919259202592125922259232592425925259262592725928259292593025931259322593325934259352593625937259382593925940259412594225943259442594525946259472594825949259502595125952259532595425955259562595725958259592596025961259622596325964259652596625967259682596925970259712597225973259742597525976259772597825979259802598125982259832598425985259862598725988259892599025991259922599325994259952599625997259982599926000260012600226003260042600526006260072600826009260102601126012260132601426015260162601726018260192602026021260222602326024260252602626027260282602926030260312603226033260342603526036260372603826039260402604126042260432604426045260462604726048260492605026051260522605326054260552605626057260582605926060260612606226063260642606526066260672606826069260702607126072260732607426075260762607726078260792608026081260822608326084260852608626087260882608926090260912609226093260942609526096260972609826099261002610126102261032610426105261062610726108261092611026111261122611326114261152611626117261182611926120261212612226123261242612526126261272612826129261302613126132261332613426135261362613726138261392614026141261422614326144261452614626147261482614926150261512615226153261542615526156261572615826159261602616126162261632616426165261662616726168261692617026171261722617326174261752617626177261782617926180261812618226183261842618526186261872618826189261902619126192261932619426195261962619726198261992620026201262022620326204262052620626207262082620926210262112621226213262142621526216262172621826219262202622126222262232622426225262262622726228262292623026231262322623326234262352623626237262382623926240262412624226243262442624526246262472624826249262502625126252262532625426255262562625726258262592626026261262622626326264262652626626267262682626926270262712627226273262742627526276262772627826279262802628126282262832628426285262862628726288262892629026291262922629326294262952629626297262982629926300263012630226303263042630526306263072630826309263102631126312263132631426315263162631726318263192632026321263222632326324263252632626327263282632926330263312633226333263342633526336263372633826339263402634126342263432634426345263462634726348263492635026351263522635326354263552635626357263582635926360263612636226363263642636526366263672636826369263702637126372263732637426375263762637726378263792638026381263822638326384263852638626387263882638926390263912639226393263942639526396263972639826399264002640126402264032640426405264062640726408264092641026411264122641326414264152641626417264182641926420264212642226423264242642526426264272642826429264302643126432264332643426435264362643726438264392644026441264422644326444264452644626447264482644926450264512645226453264542645526456264572645826459264602646126462264632646426465264662646726468264692647026471264722647326474264752647626477264782647926480264812648226483264842648526486264872648826489264902649126492264932649426495264962649726498264992650026501265022650326504265052650626507265082650926510265112651226513265142651526516265172651826519265202652126522265232652426525265262652726528265292653026531265322653326534265352653626537265382653926540265412654226543265442654526546265472654826549265502655126552265532655426555265562655726558265592656026561265622656326564265652656626567265682656926570265712657226573265742657526576265772657826579265802658126582265832658426585265862658726588265892659026591265922659326594265952659626597265982659926600266012660226603266042660526606266072660826609266102661126612266132661426615266162661726618266192662026621266222662326624266252662626627266282662926630266312663226633266342663526636266372663826639266402664126642266432664426645266462664726648266492665026651266522665326654266552665626657266582665926660266612666226663266642666526666266672666826669266702667126672266732667426675266762667726678266792668026681266822668326684266852668626687266882668926690266912669226693266942669526696266972669826699267002670126702267032670426705267062670726708267092671026711267122671326714267152671626717267182671926720267212672226723267242672526726267272672826729267302673126732267332673426735267362673726738267392674026741267422674326744267452674626747267482674926750267512675226753267542675526756267572675826759267602676126762267632676426765267662676726768267692677026771267722677326774267752677626777267782677926780267812678226783267842678526786267872678826789267902679126792267932679426795267962679726798267992680026801268022680326804268052680626807268082680926810268112681226813268142681526816268172681826819268202682126822268232682426825268262682726828268292683026831268322683326834268352683626837268382683926840268412684226843268442684526846268472684826849268502685126852268532685426855268562685726858268592686026861268622686326864268652686626867268682686926870268712687226873268742687526876268772687826879268802688126882268832688426885268862688726888268892689026891268922689326894268952689626897268982689926900269012690226903269042690526906269072690826909269102691126912269132691426915269162691726918269192692026921269222692326924269252692626927269282692926930269312693226933269342693526936269372693826939269402694126942269432694426945269462694726948269492695026951269522695326954269552695626957269582695926960269612696226963269642696526966269672696826969269702697126972269732697426975269762697726978269792698026981269822698326984269852698626987269882698926990269912699226993269942699526996269972699826999270002700127002270032700427005270062700727008270092701027011270122701327014270152701627017270182701927020270212702227023270242702527026270272702827029270302703127032270332703427035270362703727038270392704027041270422704327044270452704627047270482704927050270512705227053270542705527056270572705827059270602706127062270632706427065270662706727068270692707027071270722707327074270752707627077270782707927080270812708227083270842708527086270872708827089270902709127092270932709427095270962709727098270992710027101271022710327104271052710627107271082710927110271112711227113271142711527116271172711827119271202712127122271232712427125271262712727128271292713027131271322713327134271352713627137271382713927140271412714227143271442714527146271472714827149271502715127152271532715427155271562715727158271592716027161271622716327164271652716627167271682716927170271712717227173271742717527176271772717827179271802718127182271832718427185271862718727188271892719027191271922719327194271952719627197271982719927200272012720227203272042720527206272072720827209272102721127212272132721427215272162721727218272192722027221272222722327224272252722627227272282722927230272312723227233272342723527236272372723827239272402724127242272432724427245272462724727248272492725027251272522725327254272552725627257272582725927260272612726227263272642726527266272672726827269272702727127272272732727427275272762727727278272792728027281272822728327284272852728627287272882728927290272912729227293272942729527296272972729827299273002730127302273032730427305273062730727308273092731027311273122731327314273152731627317273182731927320273212732227323273242732527326273272732827329273302733127332273332733427335273362733727338273392734027341273422734327344273452734627347273482734927350273512735227353273542735527356273572735827359273602736127362273632736427365273662736727368273692737027371273722737327374273752737627377273782737927380273812738227383273842738527386273872738827389273902739127392273932739427395273962739727398273992740027401274022740327404274052740627407274082740927410274112741227413274142741527416274172741827419274202742127422274232742427425274262742727428274292743027431274322743327434274352743627437274382743927440274412744227443274442744527446274472744827449274502745127452274532745427455274562745727458274592746027461274622746327464274652746627467274682746927470274712747227473274742747527476274772747827479274802748127482274832748427485274862748727488274892749027491274922749327494274952749627497274982749927500275012750227503275042750527506275072750827509275102751127512275132751427515275162751727518275192752027521275222752327524275252752627527275282752927530275312753227533275342753527536275372753827539275402754127542275432754427545275462754727548275492755027551275522755327554275552755627557275582755927560275612756227563275642756527566275672756827569275702757127572275732757427575275762757727578275792758027581275822758327584275852758627587275882758927590275912759227593275942759527596275972759827599276002760127602276032760427605276062760727608276092761027611276122761327614276152761627617276182761927620276212762227623276242762527626276272762827629276302763127632276332763427635276362763727638276392764027641276422764327644276452764627647276482764927650276512765227653276542765527656276572765827659276602766127662276632766427665276662766727668276692767027671276722767327674276752767627677276782767927680276812768227683276842768527686276872768827689276902769127692276932769427695276962769727698276992770027701277022770327704277052770627707277082770927710277112771227713277142771527716277172771827719277202772127722277232772427725277262772727728277292773027731277322773327734277352773627737277382773927740277412774227743277442774527746277472774827749277502775127752277532775427755277562775727758277592776027761277622776327764277652776627767277682776927770277712777227773277742777527776277772777827779277802778127782277832778427785277862778727788277892779027791277922779327794277952779627797277982779927800278012780227803278042780527806278072780827809278102781127812278132781427815278162781727818278192782027821278222782327824278252782627827278282782927830278312783227833278342783527836278372783827839278402784127842278432784427845278462784727848278492785027851278522785327854278552785627857278582785927860278612786227863278642786527866278672786827869278702787127872278732787427875278762787727878278792788027881278822788327884278852788627887278882788927890278912789227893278942789527896278972789827899279002790127902279032790427905279062790727908279092791027911279122791327914279152791627917279182791927920279212792227923279242792527926279272792827929279302793127932279332793427935279362793727938279392794027941279422794327944279452794627947279482794927950279512795227953279542795527956279572795827959279602796127962279632796427965279662796727968279692797027971279722797327974279752797627977279782797927980279812798227983279842798527986279872798827989279902799127992279932799427995279962799727998279992800028001280022800328004280052800628007280082800928010280112801228013280142801528016280172801828019280202802128022280232802428025280262802728028280292803028031280322803328034280352803628037280382803928040280412804228043280442804528046280472804828049280502805128052280532805428055280562805728058280592806028061280622806328064280652806628067280682806928070280712807228073280742807528076280772807828079280802808128082280832808428085280862808728088280892809028091280922809328094280952809628097280982809928100281012810228103281042810528106281072810828109281102811128112281132811428115281162811728118281192812028121281222812328124281252812628127281282812928130281312813228133281342813528136281372813828139281402814128142281432814428145281462814728148281492815028151281522815328154281552815628157281582815928160281612816228163281642816528166281672816828169281702817128172281732817428175281762817728178281792818028181281822818328184281852818628187281882818928190281912819228193281942819528196281972819828199282002820128202282032820428205282062820728208282092821028211282122821328214282152821628217282182821928220282212822228223282242822528226282272822828229282302823128232282332823428235282362823728238282392824028241282422824328244282452824628247282482824928250282512825228253282542825528256282572825828259282602826128262282632826428265282662826728268282692827028271282722827328274282752827628277282782827928280282812828228283282842828528286282872828828289282902829128292282932829428295282962829728298282992830028301283022830328304283052830628307283082830928310283112831228313283142831528316283172831828319283202832128322283232832428325283262832728328283292833028331283322833328334283352833628337283382833928340283412834228343283442834528346283472834828349283502835128352283532835428355283562835728358283592836028361283622836328364283652836628367283682836928370283712837228373283742837528376283772837828379283802838128382283832838428385283862838728388283892839028391283922839328394283952839628397283982839928400284012840228403284042840528406284072840828409284102841128412284132841428415284162841728418284192842028421284222842328424284252842628427284282842928430284312843228433284342843528436284372843828439284402844128442284432844428445284462844728448284492845028451284522845328454284552845628457284582845928460284612846228463284642846528466284672846828469284702847128472284732847428475284762847728478284792848028481284822848328484284852848628487284882848928490284912849228493284942849528496284972849828499285002850128502285032850428505285062850728508285092851028511285122851328514285152851628517285182851928520285212852228523285242852528526285272852828529285302853128532285332853428535285362853728538285392854028541285422854328544285452854628547285482854928550285512855228553285542855528556285572855828559285602856128562285632856428565285662856728568285692857028571285722857328574285752857628577285782857928580285812858228583285842858528586285872858828589285902859128592285932859428595285962859728598285992860028601286022860328604286052860628607286082860928610286112861228613286142861528616286172861828619286202862128622286232862428625286262862728628286292863028631286322863328634286352863628637286382863928640286412864228643286442864528646286472864828649286502865128652286532865428655286562865728658286592866028661286622866328664286652866628667286682866928670286712867228673286742867528676286772867828679286802868128682286832868428685286862868728688286892869028691286922869328694286952869628697286982869928700287012870228703287042870528706287072870828709287102871128712287132871428715287162871728718287192872028721287222872328724287252872628727287282872928730287312873228733287342873528736287372873828739287402874128742287432874428745287462874728748287492875028751287522875328754287552875628757287582875928760287612876228763287642876528766287672876828769287702877128772287732877428775287762877728778287792878028781287822878328784287852878628787287882878928790287912879228793287942879528796287972879828799288002880128802288032880428805288062880728808288092881028811288122881328814288152881628817288182881928820288212882228823288242882528826288272882828829288302883128832288332883428835288362883728838288392884028841288422884328844288452884628847288482884928850288512885228853288542885528856288572885828859288602886128862288632886428865288662886728868288692887028871288722887328874288752887628877288782887928880288812888228883288842888528886288872888828889288902889128892288932889428895288962889728898288992890028901289022890328904289052890628907289082890928910289112891228913289142891528916289172891828919289202892128922289232892428925289262892728928289292893028931289322893328934289352893628937289382893928940289412894228943289442894528946289472894828949289502895128952289532895428955289562895728958289592896028961289622896328964289652896628967289682896928970289712897228973289742897528976289772897828979289802898128982289832898428985289862898728988289892899028991289922899328994289952899628997289982899929000290012900229003290042900529006290072900829009290102901129012290132901429015290162901729018290192902029021290222902329024290252902629027290282902929030290312903229033290342903529036290372903829039290402904129042290432904429045290462904729048290492905029051290522905329054290552905629057290582905929060290612906229063290642906529066290672906829069290702907129072290732907429075290762907729078290792908029081290822908329084290852908629087290882908929090290912909229093290942909529096290972909829099291002910129102291032910429105291062910729108291092911029111291122911329114291152911629117291182911929120291212912229123291242912529126291272912829129291302913129132291332913429135291362913729138291392914029141291422914329144291452914629147291482914929150291512915229153291542915529156291572915829159291602916129162291632916429165291662916729168291692917029171291722917329174291752917629177291782917929180291812918229183291842918529186291872918829189291902919129192291932919429195291962919729198291992920029201292022920329204292052920629207292082920929210292112921229213292142921529216292172921829219292202922129222292232922429225292262922729228292292923029231292322923329234292352923629237292382923929240292412924229243292442924529246292472924829249292502925129252292532925429255292562925729258292592926029261292622926329264292652926629267292682926929270292712927229273292742927529276292772927829279292802928129282292832928429285292862928729288292892929029291292922929329294292952929629297292982929929300293012930229303293042930529306293072930829309293102931129312293132931429315293162931729318293192932029321293222932329324293252932629327293282932929330293312933229333293342933529336293372933829339293402934129342293432934429345293462934729348293492935029351293522935329354293552935629357293582935929360293612936229363293642936529366293672936829369293702937129372293732937429375293762937729378293792938029381293822938329384293852938629387293882938929390293912939229393293942939529396293972939829399294002940129402294032940429405294062940729408294092941029411294122941329414294152941629417294182941929420294212942229423294242942529426294272942829429294302943129432294332943429435294362943729438294392944029441294422944329444294452944629447294482944929450294512945229453294542945529456294572945829459294602946129462294632946429465294662946729468294692947029471294722947329474294752947629477294782947929480294812948229483294842948529486294872948829489294902949129492294932949429495294962949729498294992950029501295022950329504295052950629507295082950929510295112951229513295142951529516295172951829519295202952129522295232952429525295262952729528295292953029531295322953329534295352953629537295382953929540295412954229543295442954529546295472954829549295502955129552295532955429555295562955729558295592956029561295622956329564295652956629567295682956929570295712957229573295742957529576295772957829579295802958129582295832958429585295862958729588295892959029591295922959329594295952959629597295982959929600296012960229603296042960529606296072960829609296102961129612296132961429615296162961729618296192962029621296222962329624296252962629627296282962929630296312963229633296342963529636296372963829639296402964129642296432964429645296462964729648296492965029651296522965329654296552965629657296582965929660296612966229663296642966529666296672966829669296702967129672296732967429675296762967729678296792968029681296822968329684296852968629687296882968929690296912969229693296942969529696296972969829699297002970129702297032970429705297062970729708297092971029711297122971329714297152971629717297182971929720297212972229723297242972529726297272972829729297302973129732297332973429735297362973729738297392974029741297422974329744297452974629747297482974929750297512975229753297542975529756297572975829759297602976129762297632976429765297662976729768297692977029771297722977329774297752977629777297782977929780297812978229783297842978529786297872978829789297902979129792297932979429795297962979729798297992980029801298022980329804298052980629807298082980929810298112981229813298142981529816298172981829819298202982129822298232982429825298262982729828298292983029831298322983329834298352983629837298382983929840298412984229843298442984529846298472984829849298502985129852298532985429855298562985729858298592986029861298622986329864298652986629867298682986929870298712987229873298742987529876298772987829879298802988129882298832988429885298862988729888298892989029891298922989329894298952989629897298982989929900299012990229903299042990529906299072990829909299102991129912299132991429915299162991729918299192992029921299222992329924299252992629927299282992929930299312993229933299342993529936299372993829939299402994129942299432994429945299462994729948299492995029951299522995329954299552995629957299582995929960299612996229963299642996529966299672996829969299702997129972299732997429975299762997729978299792998029981299822998329984299852998629987299882998929990299912999229993299942999529996299972999829999300003000130002300033000430005300063000730008300093001030011300123001330014300153001630017300183001930020300213002230023300243002530026300273002830029300303003130032300333003430035300363003730038300393004030041300423004330044300453004630047300483004930050300513005230053300543005530056300573005830059300603006130062300633006430065300663006730068300693007030071300723007330074300753007630077300783007930080300813008230083300843008530086300873008830089300903009130092300933009430095300963009730098300993010030101301023010330104301053010630107301083010930110301113011230113301143011530116301173011830119301203012130122301233012430125301263012730128301293013030131301323013330134301353013630137301383013930140301413014230143301443014530146301473014830149301503015130152301533015430155301563015730158301593016030161301623016330164301653016630167301683016930170301713017230173301743017530176301773017830179301803018130182301833018430185301863018730188301893019030191301923019330194301953019630197301983019930200302013020230203302043020530206302073020830209302103021130212302133021430215302163021730218302193022030221302223022330224302253022630227302283022930230302313023230233302343023530236302373023830239302403024130242302433024430245302463024730248302493025030251302523025330254302553025630257302583025930260302613026230263302643026530266302673026830269302703027130272302733027430275302763027730278302793028030281302823028330284302853028630287302883028930290302913029230293302943029530296302973029830299303003030130302303033030430305303063030730308303093031030311303123031330314303153031630317303183031930320303213032230323303243032530326303273032830329303303033130332303333033430335303363033730338303393034030341303423034330344303453034630347303483034930350303513035230353303543035530356303573035830359303603036130362303633036430365303663036730368303693037030371303723037330374303753037630377303783037930380303813038230383303843038530386303873038830389303903039130392303933039430395303963039730398303993040030401304023040330404304053040630407304083040930410304113041230413304143041530416304173041830419304203042130422304233042430425304263042730428304293043030431304323043330434304353043630437304383043930440304413044230443304443044530446304473044830449304503045130452304533045430455304563045730458304593046030461304623046330464304653046630467304683046930470304713047230473304743047530476304773047830479304803048130482304833048430485304863048730488304893049030491304923049330494304953049630497304983049930500305013050230503305043050530506305073050830509305103051130512305133051430515305163051730518305193052030521305223052330524305253052630527305283052930530305313053230533305343053530536305373053830539305403054130542305433054430545305463054730548305493055030551305523055330554305553055630557305583055930560305613056230563305643056530566305673056830569305703057130572305733057430575305763057730578305793058030581305823058330584305853058630587305883058930590305913059230593305943059530596305973059830599306003060130602306033060430605306063060730608306093061030611306123061330614306153061630617306183061930620306213062230623306243062530626306273062830629306303063130632306333063430635306363063730638306393064030641306423064330644306453064630647306483064930650306513065230653306543065530656306573065830659306603066130662306633066430665306663066730668306693067030671306723067330674306753067630677306783067930680306813068230683306843068530686306873068830689306903069130692306933069430695306963069730698306993070030701307023070330704307053070630707307083070930710307113071230713307143071530716307173071830719307203072130722307233072430725307263072730728307293073030731307323073330734307353073630737307383073930740307413074230743307443074530746307473074830749307503075130752307533075430755307563075730758307593076030761307623076330764307653076630767307683076930770307713077230773307743077530776307773077830779307803078130782307833078430785307863078730788307893079030791307923079330794307953079630797307983079930800308013080230803308043080530806308073080830809308103081130812308133081430815308163081730818308193082030821308223082330824308253082630827308283082930830308313083230833308343083530836308373083830839308403084130842308433084430845308463084730848308493085030851308523085330854308553085630857308583085930860308613086230863308643086530866308673086830869308703087130872308733087430875308763087730878308793088030881308823088330884308853088630887308883088930890308913089230893308943089530896308973089830899309003090130902309033090430905309063090730908309093091030911309123091330914309153091630917309183091930920309213092230923309243092530926309273092830929309303093130932309333093430935309363093730938309393094030941309423094330944309453094630947309483094930950309513095230953309543095530956309573095830959309603096130962309633096430965309663096730968309693097030971309723097330974309753097630977309783097930980309813098230983309843098530986309873098830989309903099130992309933099430995309963099730998309993100031001310023100331004310053100631007310083100931010310113101231013310143101531016310173101831019310203102131022310233102431025310263102731028310293103031031310323103331034310353103631037310383103931040310413104231043310443104531046310473104831049310503105131052310533105431055310563105731058310593106031061310623106331064310653106631067310683106931070310713107231073310743107531076310773107831079310803108131082310833108431085310863108731088310893109031091310923109331094310953109631097310983109931100311013110231103311043110531106311073110831109311103111131112311133111431115311163111731118311193112031121311223112331124311253112631127311283112931130311313113231133311343113531136311373113831139311403114131142311433114431145311463114731148311493115031151311523115331154311553115631157311583115931160311613116231163311643116531166311673116831169311703117131172311733117431175311763117731178311793118031181311823118331184311853118631187311883118931190311913119231193311943119531196311973119831199312003120131202312033120431205312063120731208312093121031211312123121331214312153121631217312183121931220312213122231223312243122531226312273122831229312303123131232312333123431235312363123731238312393124031241312423124331244312453124631247312483124931250312513125231253312543125531256312573125831259312603126131262312633126431265312663126731268312693127031271312723127331274312753127631277312783127931280312813128231283312843128531286312873128831289312903129131292312933129431295312963129731298312993130031301313023130331304313053130631307313083130931310313113131231313313143131531316313173131831319313203132131322313233132431325313263132731328313293133031331313323133331334313353133631337313383133931340313413134231343313443134531346313473134831349313503135131352313533135431355313563135731358313593136031361313623136331364313653136631367313683136931370313713137231373313743137531376313773137831379313803138131382313833138431385313863138731388313893139031391313923139331394313953139631397313983139931400314013140231403314043140531406314073140831409314103141131412314133141431415314163141731418314193142031421314223142331424314253142631427314283142931430314313143231433314343143531436314373143831439314403144131442314433144431445314463144731448314493145031451314523145331454314553145631457314583145931460314613146231463314643146531466314673146831469314703147131472314733147431475314763147731478314793148031481314823148331484314853148631487314883148931490314913149231493314943149531496314973149831499315003150131502315033150431505315063150731508315093151031511315123151331514315153151631517315183151931520315213152231523315243152531526315273152831529315303153131532315333153431535315363153731538315393154031541315423154331544315453154631547315483154931550315513155231553315543155531556315573155831559315603156131562315633156431565315663156731568315693157031571315723157331574315753157631577315783157931580315813158231583315843158531586315873158831589315903159131592315933159431595315963159731598315993160031601316023160331604316053160631607316083160931610316113161231613316143161531616316173161831619316203162131622316233162431625316263162731628316293163031631316323163331634316353163631637316383163931640316413164231643316443164531646316473164831649316503165131652316533165431655316563165731658316593166031661316623166331664316653166631667316683166931670316713167231673316743167531676316773167831679316803168131682316833168431685316863168731688316893169031691316923169331694316953169631697316983169931700317013170231703317043170531706317073170831709317103171131712317133171431715317163171731718317193172031721317223172331724317253172631727317283172931730317313173231733317343173531736317373173831739317403174131742317433174431745317463174731748317493175031751317523175331754317553175631757317583175931760317613176231763317643176531766317673176831769317703177131772317733177431775317763177731778317793178031781317823178331784317853178631787317883178931790317913179231793317943179531796317973179831799318003180131802318033180431805318063180731808318093181031811318123181331814318153181631817318183181931820318213182231823318243182531826318273182831829318303183131832318333183431835318363183731838318393184031841318423184331844318453184631847318483184931850318513185231853318543185531856318573185831859318603186131862318633186431865318663186731868318693187031871318723187331874318753187631877318783187931880318813188231883318843188531886318873188831889318903189131892318933189431895318963189731898318993190031901319023190331904319053190631907319083190931910319113191231913319143191531916319173191831919319203192131922319233192431925319263192731928319293193031931319323193331934319353193631937319383193931940319413194231943319443194531946319473194831949319503195131952319533195431955319563195731958319593196031961319623196331964319653196631967319683196931970319713197231973319743197531976319773197831979319803198131982319833198431985319863198731988319893199031991319923199331994319953199631997319983199932000320013200232003320043200532006320073200832009320103201132012320133201432015320163201732018320193202032021320223202332024320253202632027320283202932030320313203232033320343203532036320373203832039320403204132042320433204432045320463204732048320493205032051320523205332054320553205632057320583205932060320613206232063320643206532066320673206832069320703207132072320733207432075320763207732078320793208032081320823208332084320853208632087320883208932090320913209232093320943209532096320973209832099321003210132102321033210432105321063210732108321093211032111321123211332114321153211632117321183211932120321213212232123321243212532126321273212832129321303213132132321333213432135321363213732138321393214032141321423214332144321453214632147321483214932150321513215232153321543215532156321573215832159321603216132162321633216432165321663216732168321693217032171321723217332174321753217632177321783217932180321813218232183321843218532186321873218832189321903219132192321933219432195321963219732198321993220032201322023220332204322053220632207322083220932210322113221232213322143221532216322173221832219322203222132222322233222432225322263222732228322293223032231322323223332234322353223632237322383223932240322413224232243322443224532246322473224832249322503225132252322533225432255322563225732258322593226032261322623226332264322653226632267322683226932270322713227232273322743227532276322773227832279322803228132282322833228432285322863228732288322893229032291322923229332294322953229632297322983229932300323013230232303323043230532306323073230832309323103231132312323133231432315323163231732318323193232032321323223232332324323253232632327323283232932330323313233232333323343233532336323373233832339323403234132342323433234432345323463234732348323493235032351323523235332354323553235632357323583235932360323613236232363323643236532366323673236832369323703237132372323733237432375323763237732378323793238032381323823238332384323853238632387323883238932390323913239232393323943239532396323973239832399324003240132402324033240432405324063240732408324093241032411324123241332414324153241632417324183241932420324213242232423324243242532426324273242832429324303243132432324333243432435324363243732438324393244032441324423244332444324453244632447324483244932450324513245232453324543245532456324573245832459324603246132462324633246432465324663246732468324693247032471324723247332474324753247632477324783247932480324813248232483324843248532486324873248832489324903249132492324933249432495324963249732498324993250032501325023250332504325053250632507325083250932510325113251232513325143251532516325173251832519325203252132522325233252432525325263252732528325293253032531325323253332534325353253632537325383253932540325413254232543325443254532546325473254832549325503255132552325533255432555325563255732558325593256032561325623256332564325653256632567325683256932570325713257232573325743257532576325773257832579325803258132582325833258432585325863258732588325893259032591325923259332594325953259632597325983259932600326013260232603326043260532606326073260832609326103261132612326133261432615326163261732618326193262032621326223262332624326253262632627326283262932630326313263232633326343263532636326373263832639326403264132642326433264432645326463264732648326493265032651326523265332654326553265632657326583265932660326613266232663326643266532666326673266832669326703267132672326733267432675326763267732678326793268032681326823268332684326853268632687326883268932690326913269232693326943269532696326973269832699327003270132702327033270432705327063270732708327093271032711327123271332714327153271632717327183271932720327213272232723327243272532726327273272832729327303273132732327333273432735327363273732738327393274032741327423274332744327453274632747327483274932750327513275232753327543275532756327573275832759327603276132762327633276432765327663276732768327693277032771327723277332774327753277632777327783277932780327813278232783327843278532786327873278832789327903279132792327933279432795327963279732798327993280032801328023280332804328053280632807328083280932810328113281232813328143281532816328173281832819328203282132822328233282432825328263282732828328293283032831328323283332834328353283632837328383283932840328413284232843328443284532846328473284832849328503285132852328533285432855328563285732858328593286032861328623286332864328653286632867328683286932870328713287232873328743287532876328773287832879328803288132882328833288432885328863288732888328893289032891328923289332894328953289632897328983289932900329013290232903329043290532906329073290832909329103291132912329133291432915329163291732918329193292032921329223292332924329253292632927329283292932930329313293232933329343293532936329373293832939329403294132942329433294432945329463294732948329493295032951329523295332954329553295632957329583295932960329613296232963329643296532966329673296832969329703297132972329733297432975329763297732978329793298032981329823298332984329853298632987329883298932990329913299232993329943299532996329973299832999330003300133002330033300433005330063300733008330093301033011330123301333014330153301633017330183301933020330213302233023330243302533026330273302833029330303303133032330333303433035330363303733038330393304033041330423304333044330453304633047330483304933050330513305233053330543305533056330573305833059330603306133062330633306433065330663306733068330693307033071330723307333074330753307633077330783307933080330813308233083330843308533086330873308833089330903309133092330933309433095330963309733098330993310033101331023310333104331053310633107331083310933110331113311233113331143311533116331173311833119331203312133122331233312433125331263312733128331293313033131331323313333134331353313633137331383313933140331413314233143331443314533146331473314833149331503315133152331533315433155331563315733158331593316033161331623316333164331653316633167331683316933170331713317233173331743317533176331773317833179331803318133182331833318433185331863318733188331893319033191331923319333194331953319633197331983319933200332013320233203332043320533206332073320833209332103321133212332133321433215332163321733218332193322033221332223322333224332253322633227332283322933230332313323233233332343323533236332373323833239332403324133242332433324433245332463324733248332493325033251332523325333254332553325633257332583325933260332613326233263332643326533266332673326833269332703327133272332733327433275332763327733278332793328033281332823328333284332853328633287332883328933290332913329233293332943329533296332973329833299333003330133302333033330433305333063330733308333093331033311333123331333314333153331633317333183331933320333213332233323333243332533326333273332833329333303333133332333333333433335333363333733338333393334033341333423334333344333453334633347333483334933350333513335233353333543335533356333573335833359333603336133362333633336433365333663336733368333693337033371333723337333374333753337633377333783337933380333813338233383333843338533386333873338833389333903339133392333933339433395333963339733398333993340033401334023340333404334053340633407334083340933410334113341233413334143341533416334173341833419334203342133422334233342433425334263342733428334293343033431334323343333434334353343633437334383343933440334413344233443334443344533446334473344833449334503345133452334533345433455334563345733458334593346033461334623346333464334653346633467334683346933470334713347233473334743347533476334773347833479334803348133482334833348433485334863348733488334893349033491334923349333494334953349633497334983349933500335013350233503335043350533506335073350833509335103351133512335133351433515335163351733518335193352033521335223352333524335253352633527335283352933530335313353233533335343353533536335373353833539335403354133542335433354433545335463354733548335493355033551335523355333554335553355633557335583355933560335613356233563335643356533566335673356833569335703357133572335733357433575335763357733578335793358033581335823358333584335853358633587335883358933590335913359233593335943359533596335973359833599336003360133602336033360433605336063360733608336093361033611336123361333614336153361633617336183361933620336213362233623336243362533626336273362833629336303363133632336333363433635336363363733638336393364033641336423364333644336453364633647336483364933650336513365233653336543365533656336573365833659336603366133662336633366433665336663366733668336693367033671336723367333674336753367633677336783367933680336813368233683336843368533686336873368833689336903369133692336933369433695336963369733698336993370033701337023370333704337053370633707337083370933710337113371233713337143371533716337173371833719337203372133722337233372433725337263372733728337293373033731337323373333734337353373633737337383373933740337413374233743337443374533746337473374833749337503375133752337533375433755337563375733758337593376033761337623376333764337653376633767337683376933770337713377233773337743377533776337773377833779337803378133782337833378433785337863378733788337893379033791337923379333794337953379633797337983379933800338013380233803338043380533806338073380833809338103381133812338133381433815338163381733818338193382033821338223382333824338253382633827338283382933830338313383233833338343383533836338373383833839338403384133842338433384433845338463384733848338493385033851338523385333854338553385633857338583385933860338613386233863338643386533866338673386833869338703387133872338733387433875338763387733878338793388033881338823388333884338853388633887338883388933890338913389233893338943389533896338973389833899339003390133902339033390433905339063390733908339093391033911339123391333914339153391633917339183391933920339213392233923339243392533926339273392833929339303393133932339333393433935339363393733938339393394033941339423394333944339453394633947339483394933950339513395233953339543395533956339573395833959339603396133962339633396433965339663396733968339693397033971339723397333974339753397633977339783397933980339813398233983339843398533986339873398833989339903399133992339933399433995339963399733998339993400034001340023400334004340053400634007340083400934010340113401234013340143401534016340173401834019340203402134022340233402434025340263402734028340293403034031340323403334034340353403634037340383403934040340413404234043340443404534046340473404834049340503405134052340533405434055340563405734058340593406034061340623406334064340653406634067340683406934070340713407234073340743407534076340773407834079340803408134082340833408434085340863408734088340893409034091340923409334094340953409634097340983409934100341013410234103341043410534106341073410834109341103411134112341133411434115341163411734118341193412034121341223412334124341253412634127341283412934130341313413234133341343413534136341373413834139341403414134142341433414434145341463414734148341493415034151341523415334154341553415634157341583415934160341613416234163341643416534166341673416834169341703417134172341733417434175341763417734178341793418034181341823418334184341853418634187341883418934190341913419234193341943419534196341973419834199342003420134202342033420434205342063420734208342093421034211342123421334214342153421634217342183421934220342213422234223342243422534226342273422834229342303423134232342333423434235342363423734238342393424034241342423424334244342453424634247342483424934250342513425234253342543425534256342573425834259342603426134262342633426434265342663426734268342693427034271342723427334274342753427634277342783427934280342813428234283342843428534286342873428834289342903429134292342933429434295342963429734298342993430034301343023430334304343053430634307343083430934310343113431234313343143431534316343173431834319343203432134322343233432434325343263432734328343293433034331343323433334334343353433634337343383433934340343413434234343343443434534346343473434834349343503435134352343533435434355343563435734358343593436034361343623436334364343653436634367343683436934370343713437234373343743437534376343773437834379343803438134382343833438434385343863438734388343893439034391343923439334394343953439634397343983439934400344013440234403344043440534406344073440834409344103441134412344133441434415344163441734418344193442034421344223442334424344253442634427344283442934430344313443234433344343443534436344373443834439344403444134442344433444434445344463444734448344493445034451344523445334454344553445634457344583445934460344613446234463344643446534466344673446834469344703447134472344733447434475344763447734478344793448034481344823448334484344853448634487344883448934490344913449234493344943449534496344973449834499345003450134502345033450434505345063450734508345093451034511345123451334514345153451634517345183451934520345213452234523345243452534526345273452834529345303453134532345333453434535345363453734538345393454034541345423454334544345453454634547345483454934550345513455234553345543455534556345573455834559345603456134562345633456434565345663456734568345693457034571345723457334574345753457634577345783457934580345813458234583345843458534586345873458834589345903459134592345933459434595345963459734598345993460034601346023460334604346053460634607346083460934610346113461234613346143461534616346173461834619346203462134622346233462434625346263462734628346293463034631346323463334634346353463634637346383463934640346413464234643346443464534646346473464834649346503465134652346533465434655346563465734658346593466034661346623466334664346653466634667346683466934670346713467234673346743467534676346773467834679346803468134682346833468434685346863468734688346893469034691346923469334694346953469634697346983469934700347013470234703347043470534706347073470834709347103471134712347133471434715347163471734718347193472034721347223472334724347253472634727347283472934730347313473234733347343473534736347373473834739347403474134742347433474434745347463474734748347493475034751347523475334754347553475634757347583475934760347613476234763347643476534766347673476834769347703477134772347733477434775347763477734778347793478034781347823478334784347853478634787347883478934790347913479234793347943479534796347973479834799348003480134802348033480434805348063480734808348093481034811348123481334814348153481634817348183481934820348213482234823348243482534826348273482834829348303483134832348333483434835348363483734838348393484034841348423484334844348453484634847348483484934850348513485234853348543485534856348573485834859348603486134862348633486434865348663486734868348693487034871348723487334874348753487634877348783487934880348813488234883348843488534886348873488834889348903489134892348933489434895348963489734898348993490034901349023490334904349053490634907349083490934910349113491234913349143491534916349173491834919349203492134922349233492434925349263492734928349293493034931349323493334934349353493634937349383493934940349413494234943349443494534946349473494834949349503495134952349533495434955349563495734958349593496034961349623496334964349653496634967349683496934970349713497234973349743497534976349773497834979349803498134982349833498434985349863498734988349893499034991349923499334994349953499634997349983499935000350013500235003350043500535006350073500835009350103501135012350133501435015350163501735018350193502035021350223502335024350253502635027350283502935030350313503235033350343503535036350373503835039350403504135042350433504435045350463504735048350493505035051350523505335054350553505635057350583505935060350613506235063350643506535066350673506835069350703507135072350733507435075350763507735078350793508035081350823508335084350853508635087350883508935090350913509235093350943509535096350973509835099351003510135102351033510435105351063510735108351093511035111351123511335114351153511635117351183511935120351213512235123351243512535126351273512835129351303513135132351333513435135351363513735138351393514035141351423514335144351453514635147351483514935150351513515235153351543515535156351573515835159351603516135162351633516435165351663516735168351693517035171351723517335174351753517635177351783517935180351813518235183351843518535186351873518835189351903519135192351933519435195351963519735198351993520035201352023520335204352053520635207352083520935210352113521235213352143521535216352173521835219352203522135222352233522435225352263522735228352293523035231352323523335234352353523635237352383523935240352413524235243352443524535246352473524835249352503525135252352533525435255352563525735258352593526035261352623526335264352653526635267352683526935270352713527235273352743527535276352773527835279352803528135282352833528435285352863528735288352893529035291352923529335294352953529635297352983529935300353013530235303353043530535306353073530835309353103531135312353133531435315353163531735318353193532035321353223532335324353253532635327353283532935330353313533235333353343533535336353373533835339353403534135342353433534435345353463534735348353493535035351353523535335354353553535635357353583535935360353613536235363353643536535366353673536835369353703537135372353733537435375353763537735378353793538035381353823538335384353853538635387353883538935390353913539235393353943539535396353973539835399354003540135402354033540435405354063540735408354093541035411354123541335414354153541635417354183541935420354213542235423354243542535426354273542835429354303543135432354333543435435354363543735438354393544035441354423544335444354453544635447354483544935450354513545235453354543545535456354573545835459354603546135462354633546435465354663546735468354693547035471354723547335474354753547635477354783547935480354813548235483354843548535486354873548835489354903549135492354933549435495354963549735498354993550035501355023550335504355053550635507355083550935510355113551235513355143551535516355173551835519355203552135522355233552435525355263552735528355293553035531355323553335534355353553635537355383553935540355413554235543355443554535546355473554835549355503555135552355533555435555355563555735558355593556035561355623556335564355653556635567355683556935570355713557235573355743557535576355773557835579355803558135582355833558435585355863558735588355893559035591355923559335594355953559635597355983559935600356013560235603356043560535606356073560835609356103561135612356133561435615356163561735618356193562035621356223562335624356253562635627356283562935630356313563235633356343563535636356373563835639356403564135642356433564435645356463564735648356493565035651356523565335654356553565635657356583565935660356613566235663356643566535666356673566835669356703567135672356733567435675356763567735678356793568035681356823568335684356853568635687356883568935690356913569235693356943569535696356973569835699357003570135702357033570435705357063570735708357093571035711357123571335714357153571635717357183571935720357213572235723357243572535726357273572835729357303573135732357333573435735357363573735738357393574035741357423574335744357453574635747357483574935750357513575235753357543575535756357573575835759357603576135762357633576435765357663576735768357693577035771357723577335774357753577635777357783577935780357813578235783357843578535786357873578835789357903579135792357933579435795357963579735798357993580035801358023580335804358053580635807358083580935810358113581235813358143581535816358173581835819358203582135822358233582435825358263582735828358293583035831358323583335834358353583635837358383583935840358413584235843358443584535846358473584835849358503585135852358533585435855358563585735858358593586035861358623586335864358653586635867358683586935870358713587235873358743587535876358773587835879358803588135882358833588435885358863588735888358893589035891358923589335894358953589635897358983589935900359013590235903359043590535906359073590835909359103591135912359133591435915359163591735918359193592035921359223592335924359253592635927359283592935930359313593235933359343593535936359373593835939359403594135942359433594435945359463594735948359493595035951359523595335954359553595635957359583595935960359613596235963359643596535966359673596835969359703597135972359733597435975359763597735978359793598035981359823598335984359853598635987359883598935990359913599235993359943599535996359973599835999360003600136002360033600436005360063600736008360093601036011360123601336014360153601636017360183601936020360213602236023360243602536026360273602836029360303603136032360333603436035360363603736038360393604036041360423604336044360453604636047360483604936050360513605236053360543605536056360573605836059360603606136062360633606436065360663606736068360693607036071360723607336074360753607636077360783607936080360813608236083360843608536086360873608836089360903609136092360933609436095360963609736098360993610036101361023610336104361053610636107361083610936110361113611236113361143611536116361173611836119361203612136122361233612436125361263612736128361293613036131361323613336134361353613636137361383613936140361413614236143361443614536146361473614836149361503615136152361533615436155361563615736158361593616036161361623616336164361653616636167361683616936170361713617236173361743617536176361773617836179361803618136182361833618436185361863618736188361893619036191361923619336194361953619636197361983619936200362013620236203362043620536206362073620836209362103621136212362133621436215362163621736218362193622036221362223622336224362253622636227362283622936230362313623236233362343623536236362373623836239362403624136242362433624436245362463624736248362493625036251362523625336254362553625636257362583625936260362613626236263362643626536266362673626836269362703627136272362733627436275362763627736278362793628036281362823628336284362853628636287362883628936290362913629236293362943629536296362973629836299363003630136302363033630436305363063630736308363093631036311363123631336314363153631636317363183631936320363213632236323363243632536326363273632836329363303633136332363333633436335363363633736338363393634036341363423634336344363453634636347363483634936350363513635236353363543635536356363573635836359363603636136362363633636436365363663636736368363693637036371363723637336374363753637636377363783637936380363813638236383363843638536386363873638836389363903639136392363933639436395363963639736398363993640036401364023640336404364053640636407364083640936410364113641236413364143641536416364173641836419364203642136422364233642436425364263642736428364293643036431364323643336434364353643636437364383643936440364413644236443364443644536446364473644836449364503645136452364533645436455364563645736458364593646036461364623646336464364653646636467364683646936470364713647236473364743647536476364773647836479364803648136482364833648436485364863648736488364893649036491364923649336494364953649636497364983649936500365013650236503365043650536506365073650836509365103651136512365133651436515365163651736518365193652036521365223652336524365253652636527365283652936530365313653236533365343653536536365373653836539365403654136542365433654436545365463654736548365493655036551365523655336554365553655636557365583655936560365613656236563365643656536566365673656836569365703657136572365733657436575365763657736578365793658036581365823658336584365853658636587365883658936590365913659236593365943659536596365973659836599366003660136602366033660436605366063660736608366093661036611366123661336614366153661636617366183661936620366213662236623366243662536626366273662836629366303663136632366333663436635366363663736638366393664036641366423664336644366453664636647366483664936650366513665236653366543665536656366573665836659366603666136662366633666436665366663666736668366693667036671366723667336674366753667636677366783667936680366813668236683366843668536686366873668836689366903669136692366933669436695366963669736698366993670036701367023670336704367053670636707367083670936710367113671236713367143671536716367173671836719367203672136722367233672436725367263672736728367293673036731367323673336734367353673636737367383673936740367413674236743367443674536746367473674836749367503675136752367533675436755367563675736758367593676036761367623676336764367653676636767367683676936770367713677236773367743677536776367773677836779367803678136782367833678436785367863678736788367893679036791367923679336794367953679636797367983679936800368013680236803368043680536806368073680836809368103681136812368133681436815368163681736818368193682036821368223682336824368253682636827368283682936830368313683236833368343683536836368373683836839368403684136842368433684436845368463684736848368493685036851368523685336854368553685636857368583685936860368613686236863368643686536866368673686836869368703687136872368733687436875368763687736878368793688036881368823688336884368853688636887368883688936890368913689236893368943689536896368973689836899369003690136902369033690436905369063690736908369093691036911369123691336914369153691636917369183691936920369213692236923369243692536926369273692836929369303693136932369333693436935369363693736938369393694036941369423694336944369453694636947369483694936950369513695236953369543695536956369573695836959369603696136962369633696436965369663696736968369693697036971369723697336974369753697636977369783697936980369813698236983369843698536986369873698836989369903699136992369933699436995369963699736998369993700037001370023700337004370053700637007370083700937010370113701237013370143701537016370173701837019370203702137022370233702437025370263702737028370293703037031370323703337034370353703637037370383703937040370413704237043370443704537046370473704837049370503705137052370533705437055370563705737058370593706037061370623706337064370653706637067370683706937070370713707237073370743707537076370773707837079370803708137082370833708437085370863708737088370893709037091370923709337094370953709637097370983709937100371013710237103371043710537106371073710837109371103711137112371133711437115371163711737118371193712037121371223712337124371253712637127371283712937130371313713237133371343713537136371373713837139371403714137142371433714437145371463714737148371493715037151371523715337154371553715637157371583715937160371613716237163371643716537166371673716837169371703717137172371733717437175371763717737178371793718037181371823718337184371853718637187371883718937190371913719237193371943719537196371973719837199372003720137202372033720437205372063720737208372093721037211372123721337214372153721637217372183721937220372213722237223372243722537226372273722837229372303723137232372333723437235372363723737238372393724037241372423724337244372453724637247372483724937250372513725237253372543725537256372573725837259372603726137262372633726437265372663726737268372693727037271372723727337274372753727637277372783727937280372813728237283372843728537286372873728837289372903729137292372933729437295372963729737298372993730037301373023730337304373053730637307373083730937310373113731237313373143731537316373173731837319373203732137322373233732437325373263732737328373293733037331373323733337334373353733637337373383733937340373413734237343373443734537346373473734837349373503735137352373533735437355373563735737358373593736037361373623736337364373653736637367373683736937370373713737237373373743737537376373773737837379373803738137382373833738437385373863738737388373893739037391373923739337394373953739637397373983739937400374013740237403374043740537406374073740837409374103741137412374133741437415374163741737418374193742037421374223742337424374253742637427374283742937430374313743237433374343743537436374373743837439374403744137442374433744437445374463744737448374493745037451374523745337454374553745637457374583745937460374613746237463374643746537466374673746837469374703747137472374733747437475374763747737478374793748037481374823748337484374853748637487374883748937490374913749237493374943749537496374973749837499375003750137502375033750437505375063750737508375093751037511375123751337514375153751637517375183751937520375213752237523375243752537526375273752837529375303753137532375333753437535375363753737538375393754037541375423754337544375453754637547375483754937550375513755237553375543755537556375573755837559375603756137562375633756437565375663756737568375693757037571375723757337574375753757637577375783757937580375813758237583375843758537586375873758837589375903759137592375933759437595375963759737598375993760037601376023760337604376053760637607376083760937610376113761237613376143761537616376173761837619376203762137622376233762437625376263762737628376293763037631376323763337634376353763637637376383763937640376413764237643376443764537646376473764837649376503765137652376533765437655376563765737658376593766037661376623766337664376653766637667376683766937670376713767237673376743767537676376773767837679376803768137682376833768437685376863768737688376893769037691376923769337694376953769637697376983769937700377013770237703377043770537706377073770837709377103771137712377133771437715377163771737718377193772037721377223772337724377253772637727377283772937730377313773237733377343773537736377373773837739377403774137742377433774437745377463774737748377493775037751377523775337754377553775637757377583775937760377613776237763377643776537766377673776837769377703777137772377733777437775377763777737778377793778037781377823778337784377853778637787377883778937790377913779237793377943779537796377973779837799378003780137802378033780437805378063780737808378093781037811378123781337814378153781637817378183781937820378213782237823378243782537826378273782837829378303783137832378333783437835378363783737838378393784037841378423784337844378453784637847378483784937850378513785237853378543785537856378573785837859378603786137862378633786437865378663786737868378693787037871378723787337874378753787637877378783787937880378813788237883378843788537886378873788837889378903789137892378933789437895378963789737898378993790037901379023790337904379053790637907379083790937910379113791237913379143791537916379173791837919379203792137922379233792437925379263792737928379293793037931379323793337934379353793637937379383793937940379413794237943379443794537946379473794837949379503795137952379533795437955379563795737958379593796037961379623796337964379653796637967379683796937970379713797237973379743797537976379773797837979379803798137982379833798437985379863798737988379893799037991379923799337994379953799637997379983799938000380013800238003380043800538006380073800838009380103801138012380133801438015380163801738018380193802038021380223802338024380253802638027380283802938030380313803238033380343803538036380373803838039380403804138042380433804438045380463804738048380493805038051380523805338054380553805638057380583805938060380613806238063380643806538066380673806838069380703807138072380733807438075380763807738078380793808038081380823808338084380853808638087380883808938090380913809238093380943809538096380973809838099381003810138102381033810438105381063810738108381093811038111381123811338114381153811638117381183811938120381213812238123381243812538126381273812838129381303813138132381333813438135381363813738138381393814038141381423814338144381453814638147381483814938150381513815238153381543815538156381573815838159381603816138162381633816438165381663816738168381693817038171381723817338174381753817638177381783817938180381813818238183381843818538186381873818838189381903819138192381933819438195381963819738198381993820038201382023820338204382053820638207382083820938210382113821238213382143821538216382173821838219382203822138222382233822438225382263822738228382293823038231382323823338234382353823638237382383823938240382413824238243382443824538246382473824838249382503825138252382533825438255382563825738258382593826038261382623826338264382653826638267382683826938270382713827238273382743827538276382773827838279382803828138282382833828438285382863828738288382893829038291382923829338294382953829638297382983829938300383013830238303383043830538306383073830838309383103831138312383133831438315383163831738318383193832038321383223832338324383253832638327383283832938330383313833238333383343833538336383373833838339383403834138342383433834438345383463834738348383493835038351383523835338354383553835638357383583835938360383613836238363383643836538366383673836838369383703837138372383733837438375383763837738378383793838038381383823838338384383853838638387383883838938390383913839238393383943839538396383973839838399384003840138402384033840438405384063840738408384093841038411384123841338414384153841638417384183841938420384213842238423384243842538426384273842838429384303843138432384333843438435384363843738438384393844038441384423844338444384453844638447384483844938450384513845238453384543845538456384573845838459384603846138462384633846438465384663846738468384693847038471384723847338474384753847638477384783847938480384813848238483384843848538486384873848838489384903849138492384933849438495384963849738498384993850038501385023850338504385053850638507385083850938510385113851238513385143851538516385173851838519385203852138522385233852438525385263852738528385293853038531385323853338534385353853638537385383853938540385413854238543385443854538546385473854838549385503855138552385533855438555385563855738558385593856038561385623856338564385653856638567385683856938570385713857238573385743857538576385773857838579385803858138582385833858438585385863858738588385893859038591385923859338594385953859638597385983859938600386013860238603386043860538606386073860838609386103861138612386133861438615386163861738618386193862038621386223862338624386253862638627386283862938630386313863238633386343863538636386373863838639386403864138642386433864438645386463864738648386493865038651386523865338654386553865638657386583865938660386613866238663386643866538666386673866838669386703867138672386733867438675386763867738678386793868038681386823868338684386853868638687386883868938690386913869238693386943869538696386973869838699387003870138702387033870438705387063870738708387093871038711387123871338714387153871638717387183871938720387213872238723387243872538726387273872838729387303873138732387333873438735387363873738738387393874038741387423874338744387453874638747387483874938750387513875238753387543875538756387573875838759387603876138762387633876438765387663876738768387693877038771387723877338774387753877638777387783877938780387813878238783387843878538786387873878838789387903879138792387933879438795387963879738798387993880038801388023880338804388053880638807388083880938810388113881238813388143881538816388173881838819388203882138822388233882438825388263882738828388293883038831388323883338834388353883638837388383883938840388413884238843388443884538846388473884838849388503885138852388533885438855388563885738858388593886038861388623886338864388653886638867388683886938870388713887238873388743887538876388773887838879388803888138882388833888438885388863888738888388893889038891388923889338894388953889638897388983889938900389013890238903389043890538906389073890838909389103891138912389133891438915389163891738918389193892038921389223892338924389253892638927389283892938930389313893238933389343893538936389373893838939389403894138942389433894438945389463894738948389493895038951389523895338954389553895638957389583895938960389613896238963389643896538966389673896838969389703897138972389733897438975389763897738978389793898038981389823898338984389853898638987389883898938990389913899238993389943899538996389973899838999390003900139002390033900439005390063900739008390093901039011390123901339014390153901639017390183901939020390213902239023390243902539026390273902839029390303903139032390333903439035390363903739038390393904039041390423904339044390453904639047390483904939050390513905239053390543905539056390573905839059390603906139062390633906439065390663906739068390693907039071390723907339074390753907639077390783907939080390813908239083390843908539086390873908839089390903909139092390933909439095390963909739098390993910039101391023910339104391053910639107391083910939110391113911239113391143911539116391173911839119391203912139122391233912439125391263912739128391293913039131391323913339134391353913639137391383913939140391413914239143391443914539146391473914839149391503915139152391533915439155391563915739158391593916039161391623916339164391653916639167391683916939170391713917239173391743917539176391773917839179391803918139182391833918439185391863918739188391893919039191391923919339194391953919639197391983919939200392013920239203392043920539206392073920839209392103921139212392133921439215392163921739218392193922039221392223922339224392253922639227392283922939230392313923239233392343923539236392373923839239392403924139242392433924439245392463924739248392493925039251392523925339254392553925639257392583925939260392613926239263392643926539266392673926839269392703927139272392733927439275392763927739278392793928039281392823928339284392853928639287392883928939290392913929239293392943929539296392973929839299393003930139302393033930439305393063930739308393093931039311393123931339314393153931639317393183931939320393213932239323393243932539326393273932839329393303933139332393333933439335393363933739338393393934039341393423934339344393453934639347393483934939350393513935239353393543935539356393573935839359393603936139362393633936439365393663936739368393693937039371393723937339374393753937639377393783937939380393813938239383393843938539386393873938839389393903939139392393933939439395393963939739398393993940039401394023940339404394053940639407394083940939410394113941239413394143941539416394173941839419394203942139422394233942439425394263942739428394293943039431394323943339434394353943639437394383943939440394413944239443394443944539446394473944839449394503945139452394533945439455394563945739458394593946039461394623946339464394653946639467394683946939470394713947239473394743947539476394773947839479394803948139482394833948439485394863948739488394893949039491394923949339494394953949639497394983949939500395013950239503395043950539506395073950839509395103951139512395133951439515395163951739518395193952039521395223952339524395253952639527395283952939530395313953239533395343953539536395373953839539395403954139542395433954439545395463954739548395493955039551395523955339554395553955639557395583955939560395613956239563395643956539566395673956839569395703957139572395733957439575395763957739578395793958039581395823958339584395853958639587395883958939590395913959239593395943959539596395973959839599396003960139602396033960439605396063960739608396093961039611396123961339614396153961639617396183961939620396213962239623396243962539626396273962839629396303963139632396333963439635396363963739638396393964039641396423964339644396453964639647396483964939650396513965239653396543965539656396573965839659396603966139662396633966439665396663966739668396693967039671396723967339674396753967639677396783967939680396813968239683396843968539686396873968839689396903969139692396933969439695396963969739698396993970039701397023970339704397053970639707397083970939710397113971239713397143971539716397173971839719397203972139722397233972439725397263972739728397293973039731397323973339734397353973639737397383973939740397413974239743397443974539746397473974839749397503975139752397533975439755397563975739758397593976039761397623976339764397653976639767397683976939770397713977239773397743977539776397773977839779397803978139782397833978439785397863978739788397893979039791397923979339794397953979639797397983979939800398013980239803398043980539806398073980839809398103981139812398133981439815398163981739818398193982039821398223982339824398253982639827398283982939830398313983239833398343983539836398373983839839398403984139842398433984439845398463984739848398493985039851398523985339854398553985639857398583985939860398613986239863398643986539866398673986839869398703987139872398733987439875398763987739878398793988039881398823988339884398853988639887398883988939890398913989239893398943989539896398973989839899399003990139902399033990439905399063990739908399093991039911399123991339914399153991639917399183991939920399213992239923399243992539926399273992839929399303993139932399333993439935399363993739938399393994039941399423994339944399453994639947399483994939950399513995239953399543995539956399573995839959399603996139962399633996439965399663996739968399693997039971399723997339974399753997639977399783997939980399813998239983399843998539986399873998839989399903999139992399933999439995399963999739998399994000040001400024000340004400054000640007400084000940010400114001240013400144001540016400174001840019400204002140022400234002440025400264002740028400294003040031400324003340034400354003640037400384003940040400414004240043400444004540046400474004840049400504005140052400534005440055400564005740058400594006040061400624006340064400654006640067400684006940070400714007240073400744007540076400774007840079400804008140082400834008440085400864008740088400894009040091400924009340094400954009640097400984009940100401014010240103401044010540106401074010840109401104011140112401134011440115401164011740118401194012040121401224012340124401254012640127401284012940130401314013240133401344013540136401374013840139401404014140142401434014440145401464014740148401494015040151401524015340154401554015640157401584015940160401614016240163401644016540166401674016840169401704017140172401734017440175401764017740178401794018040181401824018340184401854018640187401884018940190401914019240193401944019540196401974019840199402004020140202402034020440205402064020740208402094021040211402124021340214402154021640217402184021940220402214022240223402244022540226402274022840229402304023140232402334023440235402364023740238402394024040241402424024340244402454024640247402484024940250402514025240253402544025540256402574025840259402604026140262402634026440265402664026740268402694027040271402724027340274402754027640277402784027940280402814028240283402844028540286402874028840289402904029140292402934029440295402964029740298402994030040301403024030340304403054030640307403084030940310403114031240313403144031540316403174031840319403204032140322403234032440325403264032740328403294033040331403324033340334403354033640337403384033940340403414034240343403444034540346403474034840349403504035140352403534035440355403564035740358403594036040361403624036340364403654036640367403684036940370403714037240373403744037540376403774037840379403804038140382403834038440385403864038740388403894039040391403924039340394403954039640397403984039940400404014040240403404044040540406404074040840409404104041140412404134041440415404164041740418404194042040421404224042340424404254042640427404284042940430404314043240433404344043540436404374043840439404404044140442404434044440445404464044740448404494045040451404524045340454404554045640457404584045940460404614046240463404644046540466404674046840469404704047140472404734047440475404764047740478404794048040481404824048340484404854048640487404884048940490404914049240493404944049540496404974049840499405004050140502405034050440505405064050740508405094051040511405124051340514405154051640517405184051940520405214052240523405244052540526405274052840529405304053140532405334053440535405364053740538405394054040541405424054340544405454054640547405484054940550405514055240553405544055540556405574055840559405604056140562405634056440565405664056740568405694057040571405724057340574405754057640577405784057940580405814058240583405844058540586405874058840589405904059140592405934059440595405964059740598405994060040601406024060340604406054060640607406084060940610406114061240613406144061540616406174061840619406204062140622406234062440625406264062740628406294063040631406324063340634406354063640637406384063940640406414064240643406444064540646406474064840649406504065140652406534065440655406564065740658406594066040661406624066340664406654066640667406684066940670406714067240673406744067540676406774067840679406804068140682406834068440685406864068740688406894069040691406924069340694406954069640697406984069940700407014070240703407044070540706407074070840709407104071140712407134071440715407164071740718407194072040721407224072340724407254072640727407284072940730407314073240733407344073540736407374073840739407404074140742407434074440745407464074740748407494075040751407524075340754407554075640757407584075940760407614076240763407644076540766407674076840769407704077140772407734077440775407764077740778407794078040781407824078340784407854078640787407884078940790407914079240793407944079540796407974079840799408004080140802408034080440805408064080740808408094081040811408124081340814408154081640817408184081940820408214082240823408244082540826408274082840829408304083140832408334083440835408364083740838408394084040841408424084340844408454084640847408484084940850408514085240853408544085540856408574085840859408604086140862408634086440865408664086740868408694087040871408724087340874408754087640877408784087940880408814088240883408844088540886408874088840889408904089140892408934089440895408964089740898408994090040901409024090340904409054090640907409084090940910409114091240913409144091540916409174091840919409204092140922409234092440925409264092740928409294093040931409324093340934409354093640937409384093940940409414094240943409444094540946409474094840949409504095140952409534095440955409564095740958409594096040961409624096340964409654096640967409684096940970409714097240973409744097540976409774097840979409804098140982409834098440985409864098740988409894099040991409924099340994409954099640997409984099941000410014100241003410044100541006410074100841009410104101141012410134101441015410164101741018410194102041021410224102341024410254102641027410284102941030410314103241033410344103541036410374103841039410404104141042410434104441045410464104741048410494105041051410524105341054410554105641057410584105941060410614106241063410644106541066410674106841069410704107141072410734107441075410764107741078410794108041081410824108341084410854108641087410884108941090410914109241093410944109541096410974109841099411004110141102411034110441105411064110741108411094111041111411124111341114411154111641117411184111941120411214112241123411244112541126411274112841129411304113141132411334113441135411364113741138411394114041141411424114341144411454114641147411484114941150411514115241153411544115541156411574115841159411604116141162411634116441165411664116741168411694117041171411724117341174411754117641177411784117941180411814118241183411844118541186411874118841189411904119141192411934119441195411964119741198411994120041201412024120341204412054120641207412084120941210412114121241213412144121541216412174121841219412204122141222412234122441225412264122741228412294123041231412324123341234412354123641237412384123941240412414124241243412444124541246412474124841249412504125141252412534125441255412564125741258412594126041261412624126341264412654126641267412684126941270412714127241273412744127541276412774127841279412804128141282412834128441285412864128741288412894129041291412924129341294412954129641297412984129941300413014130241303413044130541306413074130841309413104131141312413134131441315413164131741318413194132041321413224132341324413254132641327413284132941330413314133241333413344133541336413374133841339413404134141342413434134441345413464134741348413494135041351413524135341354413554135641357413584135941360413614136241363413644136541366413674136841369413704137141372413734137441375413764137741378413794138041381413824138341384413854138641387413884138941390413914139241393413944139541396413974139841399414004140141402414034140441405414064140741408414094141041411414124141341414414154141641417414184141941420414214142241423414244142541426414274142841429414304143141432414334143441435414364143741438414394144041441414424144341444414454144641447414484144941450414514145241453414544145541456414574145841459414604146141462414634146441465414664146741468414694147041471414724147341474414754147641477414784147941480414814148241483414844148541486414874148841489414904149141492414934149441495414964149741498414994150041501415024150341504415054150641507415084150941510415114151241513415144151541516415174151841519415204152141522415234152441525415264152741528415294153041531415324153341534415354153641537415384153941540415414154241543415444154541546415474154841549415504155141552415534155441555415564155741558415594156041561415624156341564415654156641567415684156941570415714157241573415744157541576415774157841579415804158141582415834158441585415864158741588415894159041591415924159341594415954159641597415984159941600416014160241603416044160541606416074160841609416104161141612416134161441615416164161741618416194162041621416224162341624416254162641627416284162941630416314163241633416344163541636416374163841639416404164141642416434164441645416464164741648416494165041651416524165341654416554165641657416584165941660416614166241663416644166541666416674166841669416704167141672416734167441675416764167741678416794168041681416824168341684416854168641687416884168941690416914169241693416944169541696416974169841699417004170141702417034170441705417064170741708417094171041711417124171341714417154171641717417184171941720417214172241723417244172541726417274172841729417304173141732417334173441735417364173741738417394174041741417424174341744417454174641747417484174941750417514175241753417544175541756417574175841759417604176141762417634176441765417664176741768417694177041771417724177341774417754177641777417784177941780417814178241783417844178541786417874178841789417904179141792417934179441795417964179741798417994180041801418024180341804418054180641807418084180941810418114181241813418144181541816418174181841819418204182141822418234182441825418264182741828418294183041831418324183341834418354183641837418384183941840418414184241843418444184541846418474184841849418504185141852418534185441855418564185741858418594186041861418624186341864418654186641867418684186941870418714187241873418744187541876418774187841879418804188141882418834188441885418864188741888418894189041891418924189341894418954189641897418984189941900419014190241903419044190541906419074190841909419104191141912419134191441915419164191741918419194192041921419224192341924419254192641927419284192941930419314193241933419344193541936419374193841939419404194141942419434194441945419464194741948419494195041951419524195341954419554195641957419584195941960419614196241963419644196541966419674196841969419704197141972419734197441975419764197741978419794198041981419824198341984419854198641987419884198941990419914199241993419944199541996419974199841999420004200142002420034200442005420064200742008420094201042011420124201342014420154201642017420184201942020420214202242023420244202542026420274202842029420304203142032420334203442035420364203742038420394204042041420424204342044420454204642047420484204942050420514205242053420544205542056420574205842059420604206142062420634206442065420664206742068420694207042071420724207342074420754207642077420784207942080420814208242083420844208542086420874208842089420904209142092420934209442095420964209742098420994210042101421024210342104421054210642107421084210942110421114211242113421144211542116421174211842119421204212142122421234212442125421264212742128421294213042131421324213342134421354213642137421384213942140421414214242143421444214542146421474214842149421504215142152421534215442155421564215742158421594216042161421624216342164421654216642167421684216942170421714217242173421744217542176421774217842179421804218142182421834218442185421864218742188421894219042191421924219342194421954219642197421984219942200422014220242203422044220542206422074220842209422104221142212422134221442215422164221742218422194222042221422224222342224422254222642227422284222942230422314223242233422344223542236422374223842239422404224142242422434224442245422464224742248422494225042251422524225342254422554225642257422584225942260422614226242263422644226542266422674226842269422704227142272422734227442275422764227742278422794228042281422824228342284422854228642287422884228942290422914229242293422944229542296422974229842299423004230142302423034230442305423064230742308423094231042311423124231342314423154231642317423184231942320423214232242323423244232542326423274232842329423304233142332423334233442335423364233742338423394234042341423424234342344423454234642347423484234942350423514235242353423544235542356423574235842359423604236142362423634236442365423664236742368423694237042371423724237342374423754237642377423784237942380423814238242383423844238542386423874238842389423904239142392423934239442395423964239742398423994240042401424024240342404424054240642407424084240942410424114241242413424144241542416424174241842419424204242142422424234242442425424264242742428424294243042431424324243342434424354243642437424384243942440424414244242443424444244542446424474244842449424504245142452424534245442455424564245742458424594246042461424624246342464424654246642467424684246942470424714247242473424744247542476424774247842479424804248142482424834248442485424864248742488424894249042491424924249342494424954249642497424984249942500425014250242503425044250542506425074250842509425104251142512425134251442515425164251742518425194252042521425224252342524425254252642527425284252942530425314253242533425344253542536425374253842539425404254142542425434254442545425464254742548425494255042551425524255342554425554255642557425584255942560425614256242563425644256542566425674256842569425704257142572425734257442575425764257742578425794258042581425824258342584425854258642587425884258942590425914259242593425944259542596425974259842599426004260142602426034260442605426064260742608426094261042611426124261342614426154261642617426184261942620426214262242623426244262542626426274262842629426304263142632426334263442635426364263742638426394264042641426424264342644426454264642647426484264942650426514265242653426544265542656426574265842659426604266142662426634266442665426664266742668426694267042671426724267342674426754267642677426784267942680426814268242683426844268542686426874268842689426904269142692426934269442695426964269742698426994270042701427024270342704427054270642707427084270942710427114271242713427144271542716427174271842719427204272142722427234272442725427264272742728427294273042731427324273342734427354273642737427384273942740427414274242743427444274542746427474274842749427504275142752427534275442755427564275742758427594276042761427624276342764427654276642767427684276942770427714277242773427744277542776427774277842779427804278142782427834278442785427864278742788427894279042791427924279342794427954279642797427984279942800428014280242803428044280542806428074280842809428104281142812428134281442815428164281742818428194282042821428224282342824428254282642827428284282942830428314283242833428344283542836428374283842839428404284142842428434284442845428464284742848428494285042851428524285342854428554285642857428584285942860428614286242863428644286542866428674286842869428704287142872428734287442875428764287742878428794288042881428824288342884428854288642887428884288942890428914289242893428944289542896428974289842899429004290142902429034290442905429064290742908429094291042911429124291342914429154291642917429184291942920429214292242923429244292542926429274292842929429304293142932429334293442935429364293742938429394294042941429424294342944429454294642947429484294942950429514295242953429544295542956429574295842959429604296142962429634296442965429664296742968429694297042971429724297342974429754297642977429784297942980429814298242983429844298542986429874298842989429904299142992429934299442995429964299742998429994300043001430024300343004430054300643007430084300943010430114301243013430144301543016430174301843019430204302143022430234302443025430264302743028430294303043031430324303343034430354303643037430384303943040430414304243043430444304543046430474304843049430504305143052430534305443055430564305743058430594306043061430624306343064430654306643067430684306943070430714307243073430744307543076430774307843079430804308143082430834308443085430864308743088430894309043091430924309343094430954309643097430984309943100431014310243103431044310543106431074310843109431104311143112431134311443115431164311743118431194312043121431224312343124431254312643127431284312943130431314313243133431344313543136431374313843139431404314143142431434314443145431464314743148431494315043151431524315343154431554315643157431584315943160431614316243163431644316543166431674316843169431704317143172431734317443175431764317743178431794318043181431824318343184431854318643187431884318943190431914319243193431944319543196431974319843199432004320143202432034320443205432064320743208432094321043211432124321343214432154321643217432184321943220432214322243223432244322543226432274322843229432304323143232432334323443235432364323743238432394324043241432424324343244432454324643247432484324943250432514325243253432544325543256432574325843259432604326143262432634326443265432664326743268432694327043271432724327343274432754327643277432784327943280432814328243283432844328543286432874328843289432904329143292432934329443295432964329743298432994330043301433024330343304433054330643307433084330943310433114331243313433144331543316433174331843319433204332143322433234332443325433264332743328433294333043331433324333343334433354333643337433384333943340433414334243343433444334543346433474334843349433504335143352433534335443355433564335743358433594336043361433624336343364433654336643367433684336943370433714337243373433744337543376433774337843379433804338143382433834338443385433864338743388433894339043391433924339343394433954339643397433984339943400434014340243403434044340543406434074340843409434104341143412434134341443415434164341743418434194342043421434224342343424434254342643427434284342943430434314343243433434344343543436434374343843439434404344143442434434344443445434464344743448434494345043451434524345343454434554345643457434584345943460434614346243463434644346543466434674346843469434704347143472434734347443475434764347743478434794348043481434824348343484434854348643487434884348943490434914349243493434944349543496434974349843499435004350143502435034350443505435064350743508435094351043511435124351343514435154351643517435184351943520435214352243523435244352543526435274352843529435304353143532435334353443535435364353743538435394354043541435424354343544435454354643547435484354943550435514355243553435544355543556435574355843559435604356143562435634356443565435664356743568435694357043571435724357343574435754357643577435784357943580435814358243583435844358543586435874358843589435904359143592435934359443595435964359743598435994360043601436024360343604436054360643607436084360943610436114361243613436144361543616436174361843619436204362143622436234362443625436264362743628436294363043631436324363343634436354363643637436384363943640436414364243643436444364543646436474364843649436504365143652436534365443655436564365743658436594366043661436624366343664436654366643667436684366943670436714367243673436744367543676436774367843679436804368143682436834368443685436864368743688436894369043691436924369343694436954369643697436984369943700437014370243703437044370543706437074370843709437104371143712437134371443715437164371743718437194372043721437224372343724437254372643727437284372943730437314373243733437344373543736437374373843739437404374143742437434374443745437464374743748437494375043751437524375343754437554375643757437584375943760437614376243763437644376543766437674376843769437704377143772437734377443775437764377743778437794378043781437824378343784437854378643787437884378943790437914379243793437944379543796437974379843799438004380143802438034380443805438064380743808438094381043811438124381343814438154381643817438184381943820438214382243823438244382543826438274382843829438304383143832438334383443835438364383743838438394384043841438424384343844438454384643847438484384943850438514385243853438544385543856438574385843859438604386143862438634386443865438664386743868438694387043871438724387343874438754387643877438784387943880438814388243883438844388543886438874388843889438904389143892438934389443895438964389743898438994390043901439024390343904439054390643907439084390943910439114391243913439144391543916439174391843919439204392143922439234392443925439264392743928439294393043931439324393343934439354393643937439384393943940439414394243943439444394543946439474394843949439504395143952439534395443955439564395743958439594396043961439624396343964439654396643967439684396943970439714397243973439744397543976439774397843979439804398143982439834398443985439864398743988439894399043991439924399343994439954399643997439984399944000440014400244003440044400544006440074400844009440104401144012440134401444015440164401744018440194402044021440224402344024440254402644027440284402944030440314403244033440344403544036440374403844039440404404144042440434404444045440464404744048440494405044051440524405344054440554405644057440584405944060440614406244063440644406544066440674406844069440704407144072440734407444075440764407744078440794408044081440824408344084440854408644087440884408944090440914409244093440944409544096440974409844099441004410144102441034410444105441064410744108441094411044111441124411344114441154411644117441184411944120441214412244123441244412544126441274412844129441304413144132441334413444135441364413744138441394414044141441424414344144441454414644147441484414944150441514415244153441544415544156441574415844159441604416144162441634416444165441664416744168441694417044171441724417344174441754417644177441784417944180441814418244183441844418544186441874418844189441904419144192441934419444195441964419744198441994420044201442024420344204442054420644207442084420944210442114421244213442144421544216442174421844219442204422144222442234422444225442264422744228442294423044231442324423344234442354423644237442384423944240442414424244243442444424544246442474424844249442504425144252442534425444255442564425744258442594426044261442624426344264442654426644267442684426944270442714427244273442744427544276442774427844279442804428144282442834428444285442864428744288442894429044291442924429344294442954429644297442984429944300443014430244303443044430544306443074430844309443104431144312443134431444315443164431744318443194432044321443224432344324443254432644327443284432944330443314433244333443344433544336443374433844339443404434144342443434434444345443464434744348443494435044351443524435344354443554435644357443584435944360443614436244363443644436544366443674436844369443704437144372443734437444375443764437744378443794438044381443824438344384443854438644387443884438944390443914439244393443944439544396443974439844399444004440144402444034440444405444064440744408444094441044411444124441344414444154441644417444184441944420444214442244423444244442544426444274442844429444304443144432444334443444435444364443744438444394444044441444424444344444444454444644447444484444944450444514445244453444544445544456444574445844459444604446144462444634446444465444664446744468444694447044471444724447344474444754447644477444784447944480444814448244483444844448544486444874448844489444904449144492444934449444495444964449744498444994450044501445024450344504445054450644507445084450944510445114451244513445144451544516445174451844519445204452144522445234452444525445264452744528445294453044531445324453344534445354453644537445384453944540445414454244543445444454544546445474454844549445504455144552445534455444555445564455744558445594456044561445624456344564445654456644567445684456944570445714457244573445744457544576445774457844579445804458144582445834458444585445864458744588445894459044591445924459344594445954459644597445984459944600446014460244603446044460544606446074460844609446104461144612446134461444615446164461744618446194462044621446224462344624446254462644627446284462944630446314463244633446344463544636446374463844639446404464144642446434464444645446464464744648446494465044651446524465344654446554465644657446584465944660446614466244663446644466544666446674466844669446704467144672446734467444675446764467744678446794468044681446824468344684446854468644687446884468944690446914469244693446944469544696446974469844699447004470144702447034470444705447064470744708447094471044711447124471344714447154471644717447184471944720447214472244723447244472544726447274472844729447304473144732447334473444735447364473744738447394474044741447424474344744447454474644747447484474944750447514475244753447544475544756447574475844759447604476144762447634476444765447664476744768447694477044771447724477344774447754477644777447784477944780447814478244783447844478544786447874478844789447904479144792447934479444795447964479744798447994480044801448024480344804448054480644807448084480944810448114481244813448144481544816448174481844819448204482144822448234482444825448264482744828448294483044831448324483344834448354483644837448384483944840448414484244843448444484544846448474484844849448504485144852448534485444855448564485744858448594486044861448624486344864448654486644867448684486944870448714487244873448744487544876448774487844879448804488144882448834488444885448864488744888448894489044891448924489344894448954489644897448984489944900449014490244903449044490544906449074490844909449104491144912449134491444915449164491744918449194492044921449224492344924449254492644927449284492944930449314493244933449344493544936449374493844939449404494144942449434494444945449464494744948449494495044951449524495344954449554495644957449584495944960449614496244963449644496544966449674496844969449704497144972449734497444975449764497744978449794498044981449824498344984449854498644987449884498944990449914499244993449944499544996449974499844999450004500145002450034500445005450064500745008450094501045011450124501345014450154501645017450184501945020450214502245023450244502545026450274502845029450304503145032450334503445035450364503745038450394504045041450424504345044450454504645047450484504945050450514505245053450544505545056450574505845059450604506145062450634506445065450664506745068450694507045071450724507345074450754507645077450784507945080450814508245083450844508545086450874508845089450904509145092450934509445095450964509745098450994510045101451024510345104451054510645107451084510945110451114511245113451144511545116451174511845119451204512145122451234512445125451264512745128451294513045131451324513345134451354513645137451384513945140451414514245143451444514545146451474514845149451504515145152451534515445155451564515745158451594516045161451624516345164451654516645167451684516945170451714517245173451744517545176451774517845179451804518145182451834518445185451864518745188451894519045191451924519345194451954519645197451984519945200452014520245203452044520545206452074520845209452104521145212452134521445215452164521745218452194522045221452224522345224452254522645227452284522945230452314523245233452344523545236452374523845239452404524145242452434524445245452464524745248452494525045251452524525345254452554525645257452584525945260452614526245263452644526545266452674526845269452704527145272452734527445275452764527745278452794528045281452824528345284452854528645287452884528945290452914529245293452944529545296452974529845299453004530145302453034530445305453064530745308453094531045311453124531345314453154531645317453184531945320453214532245323453244532545326453274532845329453304533145332453334533445335453364533745338453394534045341453424534345344453454534645347453484534945350453514535245353453544535545356453574535845359453604536145362453634536445365453664536745368453694537045371453724537345374453754537645377453784537945380453814538245383453844538545386453874538845389453904539145392453934539445395453964539745398453994540045401454024540345404454054540645407454084540945410454114541245413454144541545416454174541845419454204542145422454234542445425454264542745428454294543045431454324543345434454354543645437454384543945440454414544245443454444544545446454474544845449454504545145452454534545445455454564545745458454594546045461454624546345464454654546645467454684546945470454714547245473454744547545476454774547845479454804548145482454834548445485454864548745488454894549045491454924549345494454954549645497454984549945500455014550245503455044550545506455074550845509455104551145512455134551445515455164551745518455194552045521455224552345524455254552645527455284552945530455314553245533455344553545536455374553845539455404554145542455434554445545455464554745548455494555045551455524555345554455554555645557455584555945560455614556245563455644556545566455674556845569455704557145572455734557445575455764557745578455794558045581455824558345584455854558645587455884558945590455914559245593455944559545596455974559845599456004560145602456034560445605456064560745608456094561045611456124561345614456154561645617456184561945620456214562245623456244562545626456274562845629456304563145632456334563445635456364563745638456394564045641456424564345644456454564645647456484564945650456514565245653456544565545656456574565845659456604566145662456634566445665456664566745668456694567045671456724567345674456754567645677456784567945680456814568245683456844568545686456874568845689456904569145692456934569445695456964569745698456994570045701457024570345704457054570645707457084570945710457114571245713457144571545716457174571845719457204572145722457234572445725457264572745728457294573045731457324573345734457354573645737457384573945740457414574245743457444574545746457474574845749457504575145752457534575445755457564575745758457594576045761457624576345764457654576645767457684576945770457714577245773457744577545776457774577845779457804578145782457834578445785457864578745788457894579045791457924579345794457954579645797457984579945800458014580245803458044580545806458074580845809458104581145812458134581445815458164581745818458194582045821458224582345824458254582645827458284582945830458314583245833458344583545836458374583845839458404584145842458434584445845458464584745848458494585045851458524585345854458554585645857458584585945860458614586245863458644586545866458674586845869458704587145872458734587445875458764587745878458794588045881458824588345884458854588645887458884588945890458914589245893458944589545896458974589845899459004590145902459034590445905459064590745908459094591045911459124591345914459154591645917459184591945920459214592245923459244592545926459274592845929459304593145932459334593445935459364593745938459394594045941459424594345944459454594645947459484594945950459514595245953459544595545956459574595845959459604596145962459634596445965459664596745968459694597045971459724597345974459754597645977459784597945980459814598245983459844598545986459874598845989459904599145992459934599445995459964599745998459994600046001460024600346004460054600646007460084600946010460114601246013460144601546016460174601846019460204602146022460234602446025460264602746028460294603046031460324603346034460354603646037460384603946040460414604246043460444604546046460474604846049460504605146052460534605446055460564605746058460594606046061460624606346064460654606646067460684606946070460714607246073460744607546076460774607846079460804608146082460834608446085460864608746088460894609046091460924609346094460954609646097460984609946100461014610246103461044610546106461074610846109461104611146112461134611446115461164611746118461194612046121461224612346124461254612646127461284612946130461314613246133461344613546136461374613846139461404614146142461434614446145461464614746148461494615046151461524615346154461554615646157461584615946160461614616246163461644616546166461674616846169461704617146172461734617446175461764617746178461794618046181461824618346184461854618646187461884618946190461914619246193461944619546196461974619846199462004620146202462034620446205462064620746208462094621046211462124621346214462154621646217462184621946220462214622246223462244622546226462274622846229462304623146232462334623446235462364623746238462394624046241462424624346244462454624646247462484624946250462514625246253462544625546256462574625846259462604626146262462634626446265462664626746268462694627046271462724627346274462754627646277462784627946280462814628246283462844628546286462874628846289462904629146292462934629446295462964629746298462994630046301463024630346304463054630646307463084630946310463114631246313463144631546316463174631846319463204632146322463234632446325463264632746328463294633046331463324633346334463354633646337463384633946340463414634246343463444634546346463474634846349463504635146352463534635446355463564635746358463594636046361463624636346364463654636646367463684636946370463714637246373463744637546376463774637846379463804638146382463834638446385463864638746388463894639046391463924639346394463954639646397463984639946400464014640246403464044640546406464074640846409464104641146412464134641446415464164641746418464194642046421464224642346424464254642646427464284642946430464314643246433464344643546436464374643846439464404644146442464434644446445464464644746448464494645046451464524645346454464554645646457464584645946460464614646246463464644646546466464674646846469464704647146472464734647446475464764647746478464794648046481464824648346484464854648646487464884648946490464914649246493464944649546496464974649846499465004650146502465034650446505465064650746508465094651046511465124651346514465154651646517465184651946520465214652246523465244652546526465274652846529465304653146532465334653446535465364653746538465394654046541465424654346544465454654646547465484654946550465514655246553465544655546556465574655846559465604656146562465634656446565465664656746568465694657046571465724657346574465754657646577465784657946580465814658246583465844658546586465874658846589465904659146592465934659446595465964659746598465994660046601466024660346604466054660646607466084660946610466114661246613466144661546616466174661846619466204662146622466234662446625466264662746628466294663046631466324663346634466354663646637466384663946640466414664246643466444664546646466474664846649466504665146652466534665446655466564665746658466594666046661466624666346664466654666646667466684666946670466714667246673466744667546676466774667846679466804668146682466834668446685466864668746688466894669046691466924669346694466954669646697466984669946700467014670246703467044670546706467074670846709467104671146712467134671446715467164671746718467194672046721467224672346724467254672646727467284672946730467314673246733467344673546736467374673846739467404674146742467434674446745467464674746748467494675046751467524675346754467554675646757467584675946760467614676246763467644676546766467674676846769467704677146772467734677446775467764677746778467794678046781467824678346784467854678646787467884678946790467914679246793467944679546796467974679846799468004680146802468034680446805468064680746808468094681046811468124681346814468154681646817468184681946820468214682246823468244682546826468274682846829468304683146832468334683446835468364683746838468394684046841468424684346844468454684646847468484684946850468514685246853468544685546856468574685846859468604686146862468634686446865468664686746868468694687046871468724687346874468754687646877468784687946880468814688246883468844688546886468874688846889468904689146892468934689446895468964689746898468994690046901469024690346904469054690646907469084690946910469114691246913469144691546916469174691846919469204692146922469234692446925469264692746928469294693046931469324693346934469354693646937469384693946940469414694246943469444694546946469474694846949469504695146952469534695446955469564695746958469594696046961469624696346964469654696646967469684696946970469714697246973469744697546976469774697846979469804698146982469834698446985469864698746988469894699046991469924699346994469954699646997469984699947000470014700247003470044700547006470074700847009470104701147012470134701447015470164701747018470194702047021470224702347024470254702647027470284702947030470314703247033470344703547036470374703847039470404704147042470434704447045470464704747048470494705047051470524705347054470554705647057470584705947060470614706247063470644706547066470674706847069470704707147072470734707447075470764707747078470794708047081470824708347084470854708647087470884708947090470914709247093470944709547096470974709847099471004710147102471034710447105471064710747108471094711047111471124711347114471154711647117471184711947120471214712247123471244712547126471274712847129471304713147132471334713447135471364713747138471394714047141471424714347144471454714647147471484714947150471514715247153471544715547156471574715847159471604716147162471634716447165471664716747168471694717047171471724717347174471754717647177471784717947180471814718247183471844718547186471874718847189471904719147192471934719447195471964719747198471994720047201472024720347204472054720647207472084720947210472114721247213472144721547216472174721847219472204722147222472234722447225472264722747228472294723047231472324723347234472354723647237472384723947240472414724247243472444724547246472474724847249472504725147252472534725447255472564725747258472594726047261472624726347264472654726647267472684726947270472714727247273472744727547276472774727847279472804728147282472834728447285472864728747288472894729047291472924729347294472954729647297472984729947300473014730247303473044730547306473074730847309473104731147312473134731447315473164731747318473194732047321473224732347324473254732647327473284732947330473314733247333473344733547336473374733847339473404734147342473434734447345473464734747348473494735047351473524735347354473554735647357473584735947360473614736247363473644736547366473674736847369473704737147372473734737447375473764737747378473794738047381473824738347384473854738647387473884738947390473914739247393473944739547396473974739847399474004740147402474034740447405474064740747408474094741047411474124741347414474154741647417474184741947420474214742247423474244742547426474274742847429474304743147432474334743447435474364743747438474394744047441474424744347444474454744647447474484744947450474514745247453474544745547456474574745847459474604746147462474634746447465474664746747468474694747047471474724747347474474754747647477474784747947480474814748247483474844748547486474874748847489474904749147492474934749447495474964749747498474994750047501475024750347504475054750647507475084750947510475114751247513475144751547516475174751847519475204752147522475234752447525475264752747528475294753047531475324753347534475354753647537475384753947540475414754247543475444754547546475474754847549475504755147552475534755447555475564755747558475594756047561475624756347564475654756647567475684756947570475714757247573475744757547576475774757847579475804758147582475834758447585475864758747588475894759047591475924759347594475954759647597475984759947600476014760247603476044760547606476074760847609476104761147612476134761447615476164761747618476194762047621476224762347624476254762647627476284762947630476314763247633476344763547636476374763847639476404764147642476434764447645476464764747648476494765047651476524765347654476554765647657476584765947660476614766247663476644766547666476674766847669476704767147672476734767447675476764767747678476794768047681476824768347684476854768647687476884768947690476914769247693476944769547696476974769847699477004770147702477034770447705477064770747708477094771047711477124771347714477154771647717477184771947720477214772247723477244772547726477274772847729477304773147732477334773447735477364773747738477394774047741477424774347744477454774647747477484774947750477514775247753477544775547756477574775847759477604776147762477634776447765477664776747768477694777047771477724777347774477754777647777477784777947780477814778247783477844778547786477874778847789477904779147792477934779447795477964779747798477994780047801478024780347804478054780647807478084780947810478114781247813478144781547816478174781847819478204782147822478234782447825478264782747828478294783047831478324783347834478354783647837478384783947840478414784247843478444784547846478474784847849478504785147852478534785447855478564785747858478594786047861478624786347864478654786647867478684786947870478714787247873478744787547876478774787847879478804788147882478834788447885478864788747888478894789047891478924789347894478954789647897478984789947900479014790247903479044790547906479074790847909479104791147912479134791447915479164791747918479194792047921479224792347924479254792647927479284792947930479314793247933479344793547936479374793847939479404794147942479434794447945479464794747948479494795047951479524795347954479554795647957479584795947960479614796247963479644796547966479674796847969479704797147972479734797447975479764797747978479794798047981479824798347984479854798647987479884798947990479914799247993479944799547996479974799847999480004800148002480034800448005480064800748008480094801048011480124801348014480154801648017480184801948020480214802248023480244802548026480274802848029480304803148032480334803448035480364803748038480394804048041480424804348044480454804648047480484804948050480514805248053480544805548056480574805848059480604806148062480634806448065480664806748068480694807048071480724807348074480754807648077480784807948080480814808248083480844808548086480874808848089480904809148092480934809448095480964809748098480994810048101481024810348104481054810648107481084810948110481114811248113481144811548116481174811848119481204812148122481234812448125481264812748128481294813048131481324813348134481354813648137481384813948140481414814248143481444814548146481474814848149481504815148152481534815448155481564815748158481594816048161481624816348164481654816648167481684816948170481714817248173481744817548176481774817848179481804818148182481834818448185481864818748188481894819048191481924819348194481954819648197481984819948200482014820248203482044820548206482074820848209482104821148212482134821448215482164821748218482194822048221482224822348224482254822648227482284822948230482314823248233482344823548236482374823848239482404824148242482434824448245482464824748248482494825048251482524825348254482554825648257482584825948260482614826248263482644826548266482674826848269482704827148272482734827448275482764827748278482794828048281482824828348284482854828648287482884828948290482914829248293482944829548296482974829848299483004830148302483034830448305483064830748308483094831048311483124831348314483154831648317483184831948320483214832248323483244832548326483274832848329483304833148332483334833448335483364833748338483394834048341483424834348344483454834648347483484834948350483514835248353483544835548356483574835848359483604836148362483634836448365483664836748368483694837048371483724837348374483754837648377483784837948380483814838248383483844838548386483874838848389483904839148392483934839448395483964839748398483994840048401484024840348404484054840648407484084840948410484114841248413484144841548416484174841848419484204842148422484234842448425484264842748428484294843048431484324843348434484354843648437484384843948440484414844248443484444844548446484474844848449484504845148452484534845448455484564845748458484594846048461484624846348464484654846648467484684846948470484714847248473484744847548476484774847848479484804848148482484834848448485484864848748488484894849048491484924849348494484954849648497484984849948500485014850248503485044850548506485074850848509485104851148512485134851448515485164851748518485194852048521485224852348524485254852648527485284852948530485314853248533485344853548536485374853848539485404854148542485434854448545485464854748548485494855048551485524855348554485554855648557485584855948560485614856248563485644856548566485674856848569485704857148572485734857448575485764857748578485794858048581485824858348584485854858648587485884858948590485914859248593485944859548596485974859848599486004860148602486034860448605486064860748608486094861048611486124861348614486154861648617486184861948620486214862248623486244862548626486274862848629486304863148632486334863448635486364863748638486394864048641486424864348644486454864648647486484864948650486514865248653486544865548656486574865848659486604866148662486634866448665486664866748668486694867048671486724867348674486754867648677486784867948680486814868248683486844868548686486874868848689486904869148692486934869448695486964869748698486994870048701487024870348704487054870648707487084870948710487114871248713487144871548716487174871848719487204872148722487234872448725487264872748728487294873048731487324873348734487354873648737487384873948740487414874248743487444874548746487474874848749487504875148752487534875448755487564875748758487594876048761487624876348764487654876648767487684876948770487714877248773487744877548776487774877848779487804878148782487834878448785487864878748788487894879048791487924879348794487954879648797487984879948800488014880248803488044880548806488074880848809488104881148812488134881448815488164881748818488194882048821488224882348824488254882648827488284882948830488314883248833488344883548836488374883848839488404884148842488434884448845488464884748848488494885048851488524885348854488554885648857488584885948860488614886248863488644886548866488674886848869488704887148872488734887448875488764887748878488794888048881488824888348884488854888648887488884888948890488914889248893488944889548896488974889848899489004890148902489034890448905489064890748908489094891048911489124891348914489154891648917489184891948920489214892248923489244892548926489274892848929489304893148932489334893448935489364893748938489394894048941489424894348944489454894648947489484894948950489514895248953489544895548956489574895848959489604896148962489634896448965489664896748968489694897048971489724897348974489754897648977489784897948980489814898248983489844898548986489874898848989489904899148992489934899448995489964899748998489994900049001490024900349004490054900649007490084900949010490114901249013490144901549016490174901849019490204902149022490234902449025490264902749028490294903049031490324903349034490354903649037490384903949040490414904249043490444904549046490474904849049490504905149052490534905449055490564905749058490594906049061490624906349064490654906649067490684906949070490714907249073490744907549076490774907849079490804908149082490834908449085490864908749088490894909049091490924909349094490954909649097490984909949100491014910249103491044910549106491074910849109491104911149112491134911449115491164911749118491194912049121491224912349124491254912649127491284912949130491314913249133491344913549136491374913849139491404914149142491434914449145491464914749148491494915049151491524915349154491554915649157491584915949160491614916249163491644916549166491674916849169491704917149172491734917449175491764917749178491794918049181491824918349184491854918649187491884918949190491914919249193491944919549196491974919849199492004920149202492034920449205492064920749208492094921049211492124921349214492154921649217492184921949220492214922249223492244922549226492274922849229492304923149232492334923449235492364923749238492394924049241492424924349244492454924649247492484924949250492514925249253492544925549256492574925849259492604926149262492634926449265492664926749268492694927049271492724927349274492754927649277492784927949280492814928249283492844928549286492874928849289492904929149292492934929449295492964929749298492994930049301493024930349304493054930649307493084930949310493114931249313493144931549316493174931849319493204932149322493234932449325493264932749328493294933049331493324933349334493354933649337493384933949340493414934249343493444934549346493474934849349493504935149352493534935449355493564935749358493594936049361493624936349364493654936649367493684936949370493714937249373493744937549376493774937849379493804938149382493834938449385493864938749388493894939049391493924939349394493954939649397493984939949400494014940249403
  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 = '107dev';
  101. var MOUSE = { LEFT: 0, MIDDLE: 1, RIGHT: 2, ROTATE: 0, DOLLY: 1, PAN: 2 };
  102. var TOUCH = { ROTATE: 0, PAN: 1, DOLLY_PAN: 2, DOLLY_ROTATE: 3 };
  103. var CullFaceNone = 0;
  104. var CullFaceBack = 1;
  105. var CullFaceFront = 2;
  106. var CullFaceFrontBack = 3;
  107. var FrontFaceDirectionCW = 0;
  108. var FrontFaceDirectionCCW = 1;
  109. var BasicShadowMap = 0;
  110. var PCFShadowMap = 1;
  111. var PCFSoftShadowMap = 2;
  112. var FrontSide = 0;
  113. var BackSide = 1;
  114. var DoubleSide = 2;
  115. var FlatShading = 1;
  116. var SmoothShading = 2;
  117. var NoColors = 0;
  118. var FaceColors = 1;
  119. var VertexColors = 2;
  120. var NoBlending = 0;
  121. var NormalBlending = 1;
  122. var AdditiveBlending = 2;
  123. var SubtractiveBlending = 3;
  124. var MultiplyBlending = 4;
  125. var CustomBlending = 5;
  126. var AddEquation = 100;
  127. var SubtractEquation = 101;
  128. var ReverseSubtractEquation = 102;
  129. var MinEquation = 103;
  130. var MaxEquation = 104;
  131. var ZeroFactor = 200;
  132. var OneFactor = 201;
  133. var SrcColorFactor = 202;
  134. var OneMinusSrcColorFactor = 203;
  135. var SrcAlphaFactor = 204;
  136. var OneMinusSrcAlphaFactor = 205;
  137. var DstAlphaFactor = 206;
  138. var OneMinusDstAlphaFactor = 207;
  139. var DstColorFactor = 208;
  140. var OneMinusDstColorFactor = 209;
  141. var SrcAlphaSaturateFactor = 210;
  142. var NeverDepth = 0;
  143. var AlwaysDepth = 1;
  144. var LessDepth = 2;
  145. var LessEqualDepth = 3;
  146. var EqualDepth = 4;
  147. var GreaterEqualDepth = 5;
  148. var GreaterDepth = 6;
  149. var NotEqualDepth = 7;
  150. var MultiplyOperation = 0;
  151. var MixOperation = 1;
  152. var AddOperation = 2;
  153. var NoToneMapping = 0;
  154. var LinearToneMapping = 1;
  155. var ReinhardToneMapping = 2;
  156. var Uncharted2ToneMapping = 3;
  157. var CineonToneMapping = 4;
  158. var ACESFilmicToneMapping = 5;
  159. var UVMapping = 300;
  160. var CubeReflectionMapping = 301;
  161. var CubeRefractionMapping = 302;
  162. var EquirectangularReflectionMapping = 303;
  163. var EquirectangularRefractionMapping = 304;
  164. var SphericalReflectionMapping = 305;
  165. var CubeUVReflectionMapping = 306;
  166. var CubeUVRefractionMapping = 307;
  167. var RepeatWrapping = 1000;
  168. var ClampToEdgeWrapping = 1001;
  169. var MirroredRepeatWrapping = 1002;
  170. var NearestFilter = 1003;
  171. var NearestMipmapNearestFilter = 1004;
  172. var NearestMipMapNearestFilter = 1004;
  173. var NearestMipmapLinearFilter = 1005;
  174. var NearestMipMapLinearFilter = 1005;
  175. var LinearFilter = 1006;
  176. var LinearMipmapNearestFilter = 1007;
  177. var LinearMipMapNearestFilter = 1007;
  178. var LinearMipmapLinearFilter = 1008;
  179. var LinearMipMapLinearFilter = 1008;
  180. var UnsignedByteType = 1009;
  181. var ByteType = 1010;
  182. var ShortType = 1011;
  183. var UnsignedShortType = 1012;
  184. var IntType = 1013;
  185. var UnsignedIntType = 1014;
  186. var FloatType = 1015;
  187. var HalfFloatType = 1016;
  188. var UnsignedShort4444Type = 1017;
  189. var UnsignedShort5551Type = 1018;
  190. var UnsignedShort565Type = 1019;
  191. var UnsignedInt248Type = 1020;
  192. var AlphaFormat = 1021;
  193. var RGBFormat = 1022;
  194. var RGBAFormat = 1023;
  195. var LuminanceFormat = 1024;
  196. var LuminanceAlphaFormat = 1025;
  197. var RGBEFormat = RGBAFormat;
  198. var DepthFormat = 1026;
  199. var DepthStencilFormat = 1027;
  200. var RedFormat = 1028;
  201. var RGB_S3TC_DXT1_Format = 33776;
  202. var RGBA_S3TC_DXT1_Format = 33777;
  203. var RGBA_S3TC_DXT3_Format = 33778;
  204. var RGBA_S3TC_DXT5_Format = 33779;
  205. var RGB_PVRTC_4BPPV1_Format = 35840;
  206. var RGB_PVRTC_2BPPV1_Format = 35841;
  207. var RGBA_PVRTC_4BPPV1_Format = 35842;
  208. var RGBA_PVRTC_2BPPV1_Format = 35843;
  209. var RGB_ETC1_Format = 36196;
  210. var RGBA_ASTC_4x4_Format = 37808;
  211. var RGBA_ASTC_5x4_Format = 37809;
  212. var RGBA_ASTC_5x5_Format = 37810;
  213. var RGBA_ASTC_6x5_Format = 37811;
  214. var RGBA_ASTC_6x6_Format = 37812;
  215. var RGBA_ASTC_8x5_Format = 37813;
  216. var RGBA_ASTC_8x6_Format = 37814;
  217. var RGBA_ASTC_8x8_Format = 37815;
  218. var RGBA_ASTC_10x5_Format = 37816;
  219. var RGBA_ASTC_10x6_Format = 37817;
  220. var RGBA_ASTC_10x8_Format = 37818;
  221. var RGBA_ASTC_10x10_Format = 37819;
  222. var RGBA_ASTC_12x10_Format = 37820;
  223. var RGBA_ASTC_12x12_Format = 37821;
  224. var LoopOnce = 2200;
  225. var LoopRepeat = 2201;
  226. var LoopPingPong = 2202;
  227. var InterpolateDiscrete = 2300;
  228. var InterpolateLinear = 2301;
  229. var InterpolateSmooth = 2302;
  230. var ZeroCurvatureEnding = 2400;
  231. var ZeroSlopeEnding = 2401;
  232. var WrapAroundEnding = 2402;
  233. var TrianglesDrawMode = 0;
  234. var TriangleStripDrawMode = 1;
  235. var TriangleFanDrawMode = 2;
  236. var LinearEncoding = 3000;
  237. var sRGBEncoding = 3001;
  238. var GammaEncoding = 3007;
  239. var RGBEEncoding = 3002;
  240. var LogLuvEncoding = 3003;
  241. var RGBM7Encoding = 3004;
  242. var RGBM16Encoding = 3005;
  243. var RGBDEncoding = 3006;
  244. var BasicDepthPacking = 3200;
  245. var RGBADepthPacking = 3201;
  246. var TangentSpaceNormalMap = 0;
  247. var ObjectSpaceNormalMap = 1;
  248. var ZeroStencilOp = 0;
  249. var KeepStencilOp = 7680;
  250. var ReplaceStencilOp = 7681;
  251. var IncrementStencilOp = 7682;
  252. var DecrementStencilOp = 7683;
  253. var IncrementWrapStencilOp = 34055;
  254. var DecrementWrapStencilOp = 34056;
  255. var InvertStencilOp = 5386;
  256. var NeverStencilFunc = 512;
  257. var LessStencilFunc = 513;
  258. var EqualStencilFunc = 514;
  259. var LessEqualStencilFunc = 515;
  260. var GreaterStencilFunc = 516;
  261. var NotEqualStencilFunc = 517;
  262. var GreaterEqualStencilFunc = 518;
  263. var AlwaysStencilFunc = 519;
  264. /**
  265. * @author alteredq / http://alteredqualia.com/
  266. * @author mrdoob / http://mrdoob.com/
  267. */
  268. var _Math = {
  269. DEG2RAD: Math.PI / 180,
  270. RAD2DEG: 180 / Math.PI,
  271. generateUUID: ( function () {
  272. // http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript/21963136#21963136
  273. var lut = [];
  274. for ( var i = 0; i < 256; i ++ ) {
  275. lut[ i ] = ( i < 16 ? '0' : '' ) + ( i ).toString( 16 );
  276. }
  277. return function generateUUID() {
  278. var d0 = Math.random() * 0xffffffff | 0;
  279. var d1 = Math.random() * 0xffffffff | 0;
  280. var d2 = Math.random() * 0xffffffff | 0;
  281. var d3 = Math.random() * 0xffffffff | 0;
  282. var uuid = lut[ d0 & 0xff ] + lut[ d0 >> 8 & 0xff ] + lut[ d0 >> 16 & 0xff ] + lut[ d0 >> 24 & 0xff ] + '-' +
  283. lut[ d1 & 0xff ] + lut[ d1 >> 8 & 0xff ] + '-' + lut[ d1 >> 16 & 0x0f | 0x40 ] + lut[ d1 >> 24 & 0xff ] + '-' +
  284. lut[ d2 & 0x3f | 0x80 ] + lut[ d2 >> 8 & 0xff ] + '-' + lut[ d2 >> 16 & 0xff ] + lut[ d2 >> 24 & 0xff ] +
  285. lut[ d3 & 0xff ] + lut[ d3 >> 8 & 0xff ] + lut[ d3 >> 16 & 0xff ] + lut[ d3 >> 24 & 0xff ];
  286. // .toUpperCase() here flattens concatenated strings to save heap memory space.
  287. return uuid.toUpperCase();
  288. };
  289. } )(),
  290. clamp: function ( value, min, max ) {
  291. return Math.max( min, Math.min( max, value ) );
  292. },
  293. // compute euclidian modulo of m % n
  294. // https://en.wikipedia.org/wiki/Modulo_operation
  295. euclideanModulo: function ( n, m ) {
  296. return ( ( n % m ) + m ) % m;
  297. },
  298. // Linear mapping from range <a1, a2> to range <b1, b2>
  299. mapLinear: function ( x, a1, a2, b1, b2 ) {
  300. return b1 + ( x - a1 ) * ( b2 - b1 ) / ( a2 - a1 );
  301. },
  302. // https://en.wikipedia.org/wiki/Linear_interpolation
  303. lerp: function ( x, y, t ) {
  304. return ( 1 - t ) * x + t * y;
  305. },
  306. // http://en.wikipedia.org/wiki/Smoothstep
  307. smoothstep: function ( x, min, max ) {
  308. if ( x <= min ) return 0;
  309. if ( x >= max ) return 1;
  310. x = ( x - min ) / ( max - min );
  311. return x * x * ( 3 - 2 * x );
  312. },
  313. smootherstep: function ( x, min, max ) {
  314. if ( x <= min ) return 0;
  315. if ( x >= max ) return 1;
  316. x = ( x - min ) / ( max - min );
  317. return x * x * x * ( x * ( x * 6 - 15 ) + 10 );
  318. },
  319. // Random integer from <low, high> interval
  320. randInt: function ( low, high ) {
  321. return low + Math.floor( Math.random() * ( high - low + 1 ) );
  322. },
  323. // Random float from <low, high> interval
  324. randFloat: function ( low, high ) {
  325. return low + Math.random() * ( high - low );
  326. },
  327. // Random float from <-range/2, range/2> interval
  328. randFloatSpread: function ( range ) {
  329. return range * ( 0.5 - Math.random() );
  330. },
  331. degToRad: function ( degrees ) {
  332. return degrees * _Math.DEG2RAD;
  333. },
  334. radToDeg: function ( radians ) {
  335. return radians * _Math.RAD2DEG;
  336. },
  337. isPowerOfTwo: function ( value ) {
  338. return ( value & ( value - 1 ) ) === 0 && value !== 0;
  339. },
  340. ceilPowerOfTwo: function ( value ) {
  341. return Math.pow( 2, Math.ceil( Math.log( value ) / Math.LN2 ) );
  342. },
  343. floorPowerOfTwo: function ( value ) {
  344. return Math.pow( 2, Math.floor( Math.log( value ) / Math.LN2 ) );
  345. }
  346. };
  347. /**
  348. * @author mrdoob / http://mrdoob.com/
  349. * @author philogb / http://blog.thejit.org/
  350. * @author egraether / http://egraether.com/
  351. * @author zz85 / http://www.lab4games.net/zz85/blog
  352. */
  353. function Vector2( x, y ) {
  354. this.x = x || 0;
  355. this.y = y || 0;
  356. }
  357. Object.defineProperties( Vector2.prototype, {
  358. "width": {
  359. get: function () {
  360. return this.x;
  361. },
  362. set: function ( value ) {
  363. this.x = value;
  364. }
  365. },
  366. "height": {
  367. get: function () {
  368. return this.y;
  369. },
  370. set: function ( value ) {
  371. this.y = value;
  372. }
  373. }
  374. } );
  375. Object.assign( Vector2.prototype, {
  376. isVector2: true,
  377. set: function ( x, y ) {
  378. this.x = x;
  379. this.y = y;
  380. return this;
  381. },
  382. setScalar: function ( scalar ) {
  383. this.x = scalar;
  384. this.y = scalar;
  385. return this;
  386. },
  387. setX: function ( x ) {
  388. this.x = x;
  389. return this;
  390. },
  391. setY: function ( y ) {
  392. this.y = y;
  393. return this;
  394. },
  395. setComponent: function ( index, value ) {
  396. switch ( index ) {
  397. case 0: this.x = value; break;
  398. case 1: this.y = value; break;
  399. default: throw new Error( 'index is out of range: ' + index );
  400. }
  401. return this;
  402. },
  403. getComponent: function ( index ) {
  404. switch ( index ) {
  405. case 0: return this.x;
  406. case 1: return this.y;
  407. default: throw new Error( 'index is out of range: ' + index );
  408. }
  409. },
  410. clone: function () {
  411. return new this.constructor( this.x, this.y );
  412. },
  413. copy: function ( v ) {
  414. this.x = v.x;
  415. this.y = v.y;
  416. return this;
  417. },
  418. add: function ( v, w ) {
  419. if ( w !== undefined ) {
  420. console.warn( 'THREE.Vector2: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  421. return this.addVectors( v, w );
  422. }
  423. this.x += v.x;
  424. this.y += v.y;
  425. return this;
  426. },
  427. addScalar: function ( s ) {
  428. this.x += s;
  429. this.y += s;
  430. return this;
  431. },
  432. addVectors: function ( a, b ) {
  433. this.x = a.x + b.x;
  434. this.y = a.y + b.y;
  435. return this;
  436. },
  437. addScaledVector: function ( v, s ) {
  438. this.x += v.x * s;
  439. this.y += v.y * s;
  440. return this;
  441. },
  442. sub: function ( v, w ) {
  443. if ( w !== undefined ) {
  444. console.warn( 'THREE.Vector2: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  445. return this.subVectors( v, w );
  446. }
  447. this.x -= v.x;
  448. this.y -= v.y;
  449. return this;
  450. },
  451. subScalar: function ( s ) {
  452. this.x -= s;
  453. this.y -= s;
  454. return this;
  455. },
  456. subVectors: function ( a, b ) {
  457. this.x = a.x - b.x;
  458. this.y = a.y - b.y;
  459. return this;
  460. },
  461. multiply: function ( v ) {
  462. this.x *= v.x;
  463. this.y *= v.y;
  464. return this;
  465. },
  466. multiplyScalar: function ( scalar ) {
  467. this.x *= scalar;
  468. this.y *= scalar;
  469. return this;
  470. },
  471. divide: function ( v ) {
  472. this.x /= v.x;
  473. this.y /= v.y;
  474. return this;
  475. },
  476. divideScalar: function ( scalar ) {
  477. return this.multiplyScalar( 1 / scalar );
  478. },
  479. applyMatrix3: function ( m ) {
  480. var x = this.x, y = this.y;
  481. var e = m.elements;
  482. this.x = e[ 0 ] * x + e[ 3 ] * y + e[ 6 ];
  483. this.y = e[ 1 ] * x + e[ 4 ] * y + e[ 7 ];
  484. return this;
  485. },
  486. min: function ( v ) {
  487. this.x = Math.min( this.x, v.x );
  488. this.y = Math.min( this.y, v.y );
  489. return this;
  490. },
  491. max: function ( v ) {
  492. this.x = Math.max( this.x, v.x );
  493. this.y = Math.max( this.y, v.y );
  494. return this;
  495. },
  496. clamp: function ( min, max ) {
  497. // assumes min < max, componentwise
  498. this.x = Math.max( min.x, Math.min( max.x, this.x ) );
  499. this.y = Math.max( min.y, Math.min( max.y, this.y ) );
  500. return this;
  501. },
  502. clampScalar: function ( minVal, maxVal ) {
  503. this.x = Math.max( minVal, Math.min( maxVal, this.x ) );
  504. this.y = Math.max( minVal, Math.min( maxVal, this.y ) );
  505. return this;
  506. },
  507. clampLength: function ( min, max ) {
  508. var length = this.length();
  509. return this.divideScalar( length || 1 ).multiplyScalar( Math.max( min, Math.min( max, length ) ) );
  510. },
  511. floor: function () {
  512. this.x = Math.floor( this.x );
  513. this.y = Math.floor( this.y );
  514. return this;
  515. },
  516. ceil: function () {
  517. this.x = Math.ceil( this.x );
  518. this.y = Math.ceil( this.y );
  519. return this;
  520. },
  521. round: function () {
  522. this.x = Math.round( this.x );
  523. this.y = Math.round( this.y );
  524. return this;
  525. },
  526. roundToZero: function () {
  527. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  528. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  529. return this;
  530. },
  531. negate: function () {
  532. this.x = - this.x;
  533. this.y = - this.y;
  534. return this;
  535. },
  536. dot: function ( v ) {
  537. return this.x * v.x + this.y * v.y;
  538. },
  539. cross: function ( v ) {
  540. return this.x * v.y - this.y * v.x;
  541. },
  542. lengthSq: function () {
  543. return this.x * this.x + this.y * this.y;
  544. },
  545. length: function () {
  546. return Math.sqrt( this.x * this.x + this.y * this.y );
  547. },
  548. manhattanLength: function () {
  549. return Math.abs( this.x ) + Math.abs( this.y );
  550. },
  551. normalize: function () {
  552. return this.divideScalar( this.length() || 1 );
  553. },
  554. angle: function () {
  555. // computes the angle in radians with respect to the positive x-axis
  556. var angle = Math.atan2( this.y, this.x );
  557. if ( angle < 0 ) angle += 2 * Math.PI;
  558. return angle;
  559. },
  560. distanceTo: function ( v ) {
  561. return Math.sqrt( this.distanceToSquared( v ) );
  562. },
  563. distanceToSquared: function ( v ) {
  564. var dx = this.x - v.x, dy = this.y - v.y;
  565. return dx * dx + dy * dy;
  566. },
  567. manhattanDistanceTo: function ( v ) {
  568. return Math.abs( this.x - v.x ) + Math.abs( this.y - v.y );
  569. },
  570. setLength: function ( length ) {
  571. return this.normalize().multiplyScalar( length );
  572. },
  573. lerp: function ( v, alpha ) {
  574. this.x += ( v.x - this.x ) * alpha;
  575. this.y += ( v.y - this.y ) * alpha;
  576. return this;
  577. },
  578. lerpVectors: function ( v1, v2, alpha ) {
  579. return this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  580. },
  581. equals: function ( v ) {
  582. return ( ( v.x === this.x ) && ( v.y === this.y ) );
  583. },
  584. fromArray: function ( array, offset ) {
  585. if ( offset === undefined ) offset = 0;
  586. this.x = array[ offset ];
  587. this.y = array[ offset + 1 ];
  588. return this;
  589. },
  590. toArray: function ( array, offset ) {
  591. if ( array === undefined ) array = [];
  592. if ( offset === undefined ) offset = 0;
  593. array[ offset ] = this.x;
  594. array[ offset + 1 ] = this.y;
  595. return array;
  596. },
  597. fromBufferAttribute: function ( attribute, index, offset ) {
  598. if ( offset !== undefined ) {
  599. console.warn( 'THREE.Vector2: offset has been removed from .fromBufferAttribute().' );
  600. }
  601. this.x = attribute.getX( index );
  602. this.y = attribute.getY( index );
  603. return this;
  604. },
  605. rotateAround: function ( center, angle ) {
  606. var c = Math.cos( angle ), s = Math.sin( angle );
  607. var x = this.x - center.x;
  608. var y = this.y - center.y;
  609. this.x = x * c - y * s + center.x;
  610. this.y = x * s + y * c + center.y;
  611. return this;
  612. }
  613. } );
  614. /**
  615. * @author mikael emtinger / http://gomo.se/
  616. * @author alteredq / http://alteredqualia.com/
  617. * @author WestLangley / http://github.com/WestLangley
  618. * @author bhouston / http://clara.io
  619. */
  620. function Quaternion( x, y, z, w ) {
  621. this._x = x || 0;
  622. this._y = y || 0;
  623. this._z = z || 0;
  624. this._w = ( w !== undefined ) ? w : 1;
  625. }
  626. Object.assign( Quaternion, {
  627. slerp: function ( qa, qb, qm, t ) {
  628. return qm.copy( qa ).slerp( qb, t );
  629. },
  630. slerpFlat: function ( dst, dstOffset, src0, srcOffset0, src1, srcOffset1, t ) {
  631. // fuzz-free, array-based Quaternion SLERP operation
  632. var x0 = src0[ srcOffset0 + 0 ],
  633. y0 = src0[ srcOffset0 + 1 ],
  634. z0 = src0[ srcOffset0 + 2 ],
  635. w0 = src0[ srcOffset0 + 3 ],
  636. x1 = src1[ srcOffset1 + 0 ],
  637. y1 = src1[ srcOffset1 + 1 ],
  638. z1 = src1[ srcOffset1 + 2 ],
  639. w1 = src1[ srcOffset1 + 3 ];
  640. if ( w0 !== w1 || x0 !== x1 || y0 !== y1 || z0 !== z1 ) {
  641. var s = 1 - t,
  642. cos = x0 * x1 + y0 * y1 + z0 * z1 + w0 * w1,
  643. dir = ( cos >= 0 ? 1 : - 1 ),
  644. sqrSin = 1 - cos * cos;
  645. // Skip the Slerp for tiny steps to avoid numeric problems:
  646. if ( sqrSin > Number.EPSILON ) {
  647. var sin = Math.sqrt( sqrSin ),
  648. len = Math.atan2( sin, cos * dir );
  649. s = Math.sin( s * len ) / sin;
  650. t = Math.sin( t * len ) / sin;
  651. }
  652. var tDir = t * dir;
  653. x0 = x0 * s + x1 * tDir;
  654. y0 = y0 * s + y1 * tDir;
  655. z0 = z0 * s + z1 * tDir;
  656. w0 = w0 * s + w1 * tDir;
  657. // Normalize in case we just did a lerp:
  658. if ( s === 1 - t ) {
  659. var f = 1 / Math.sqrt( x0 * x0 + y0 * y0 + z0 * z0 + w0 * w0 );
  660. x0 *= f;
  661. y0 *= f;
  662. z0 *= f;
  663. w0 *= f;
  664. }
  665. }
  666. dst[ dstOffset ] = x0;
  667. dst[ dstOffset + 1 ] = y0;
  668. dst[ dstOffset + 2 ] = z0;
  669. dst[ dstOffset + 3 ] = w0;
  670. }
  671. } );
  672. Object.defineProperties( Quaternion.prototype, {
  673. x: {
  674. get: function () {
  675. return this._x;
  676. },
  677. set: function ( value ) {
  678. this._x = value;
  679. this._onChangeCallback();
  680. }
  681. },
  682. y: {
  683. get: function () {
  684. return this._y;
  685. },
  686. set: function ( value ) {
  687. this._y = value;
  688. this._onChangeCallback();
  689. }
  690. },
  691. z: {
  692. get: function () {
  693. return this._z;
  694. },
  695. set: function ( value ) {
  696. this._z = value;
  697. this._onChangeCallback();
  698. }
  699. },
  700. w: {
  701. get: function () {
  702. return this._w;
  703. },
  704. set: function ( value ) {
  705. this._w = value;
  706. this._onChangeCallback();
  707. }
  708. }
  709. } );
  710. Object.assign( Quaternion.prototype, {
  711. isQuaternion: true,
  712. set: function ( x, y, z, w ) {
  713. this._x = x;
  714. this._y = y;
  715. this._z = z;
  716. this._w = w;
  717. this._onChangeCallback();
  718. return this;
  719. },
  720. clone: function () {
  721. return new this.constructor( this._x, this._y, this._z, this._w );
  722. },
  723. copy: function ( quaternion ) {
  724. this._x = quaternion.x;
  725. this._y = quaternion.y;
  726. this._z = quaternion.z;
  727. this._w = quaternion.w;
  728. this._onChangeCallback();
  729. return this;
  730. },
  731. setFromEuler: function ( euler, update ) {
  732. if ( ! ( euler && euler.isEuler ) ) {
  733. throw new Error( 'THREE.Quaternion: .setFromEuler() now expects an Euler rotation rather than a Vector3 and order.' );
  734. }
  735. var x = euler._x, y = euler._y, z = euler._z, order = euler.order;
  736. // http://www.mathworks.com/matlabcentral/fileexchange/
  737. // 20696-function-to-convert-between-dcm-euler-angles-quaternions-and-euler-vectors/
  738. // content/SpinCalc.m
  739. var cos = Math.cos;
  740. var sin = Math.sin;
  741. var c1 = cos( x / 2 );
  742. var c2 = cos( y / 2 );
  743. var c3 = cos( z / 2 );
  744. var s1 = sin( x / 2 );
  745. var s2 = sin( y / 2 );
  746. var s3 = sin( z / 2 );
  747. if ( order === 'XYZ' ) {
  748. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  749. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  750. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  751. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  752. } else if ( order === 'YXZ' ) {
  753. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  754. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  755. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  756. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  757. } else if ( order === 'ZXY' ) {
  758. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  759. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  760. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  761. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  762. } else if ( order === 'ZYX' ) {
  763. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  764. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  765. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  766. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  767. } else if ( order === 'YZX' ) {
  768. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  769. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  770. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  771. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  772. } else if ( order === 'XZY' ) {
  773. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  774. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  775. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  776. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  777. }
  778. if ( update !== false ) this._onChangeCallback();
  779. return this;
  780. },
  781. setFromAxisAngle: function ( axis, angle ) {
  782. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToQuaternion/index.htm
  783. // assumes axis is normalized
  784. var halfAngle = angle / 2, s = Math.sin( halfAngle );
  785. this._x = axis.x * s;
  786. this._y = axis.y * s;
  787. this._z = axis.z * s;
  788. this._w = Math.cos( halfAngle );
  789. this._onChangeCallback();
  790. return this;
  791. },
  792. setFromRotationMatrix: function ( m ) {
  793. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm
  794. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  795. var te = m.elements,
  796. m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ],
  797. m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ],
  798. m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ],
  799. trace = m11 + m22 + m33,
  800. s;
  801. if ( trace > 0 ) {
  802. s = 0.5 / Math.sqrt( trace + 1.0 );
  803. this._w = 0.25 / s;
  804. this._x = ( m32 - m23 ) * s;
  805. this._y = ( m13 - m31 ) * s;
  806. this._z = ( m21 - m12 ) * s;
  807. } else if ( m11 > m22 && m11 > m33 ) {
  808. s = 2.0 * Math.sqrt( 1.0 + m11 - m22 - m33 );
  809. this._w = ( m32 - m23 ) / s;
  810. this._x = 0.25 * s;
  811. this._y = ( m12 + m21 ) / s;
  812. this._z = ( m13 + m31 ) / s;
  813. } else if ( m22 > m33 ) {
  814. s = 2.0 * Math.sqrt( 1.0 + m22 - m11 - m33 );
  815. this._w = ( m13 - m31 ) / s;
  816. this._x = ( m12 + m21 ) / s;
  817. this._y = 0.25 * s;
  818. this._z = ( m23 + m32 ) / s;
  819. } else {
  820. s = 2.0 * Math.sqrt( 1.0 + m33 - m11 - m22 );
  821. this._w = ( m21 - m12 ) / s;
  822. this._x = ( m13 + m31 ) / s;
  823. this._y = ( m23 + m32 ) / s;
  824. this._z = 0.25 * s;
  825. }
  826. this._onChangeCallback();
  827. return this;
  828. },
  829. setFromUnitVectors: function ( vFrom, vTo ) {
  830. // assumes direction vectors vFrom and vTo are normalized
  831. var EPS = 0.000001;
  832. var r = vFrom.dot( vTo ) + 1;
  833. if ( r < EPS ) {
  834. r = 0;
  835. if ( Math.abs( vFrom.x ) > Math.abs( vFrom.z ) ) {
  836. this._x = - vFrom.y;
  837. this._y = vFrom.x;
  838. this._z = 0;
  839. this._w = r;
  840. } else {
  841. this._x = 0;
  842. this._y = - vFrom.z;
  843. this._z = vFrom.y;
  844. this._w = r;
  845. }
  846. } else {
  847. // crossVectors( vFrom, vTo ); // inlined to avoid cyclic dependency on Vector3
  848. this._x = vFrom.y * vTo.z - vFrom.z * vTo.y;
  849. this._y = vFrom.z * vTo.x - vFrom.x * vTo.z;
  850. this._z = vFrom.x * vTo.y - vFrom.y * vTo.x;
  851. this._w = r;
  852. }
  853. return this.normalize();
  854. },
  855. angleTo: function ( q ) {
  856. return 2 * Math.acos( Math.abs( _Math.clamp( this.dot( q ), - 1, 1 ) ) );
  857. },
  858. rotateTowards: function ( q, step ) {
  859. var angle = this.angleTo( q );
  860. if ( angle === 0 ) return this;
  861. var t = Math.min( 1, step / angle );
  862. this.slerp( q, t );
  863. return this;
  864. },
  865. inverse: function () {
  866. // quaternion is assumed to have unit length
  867. return this.conjugate();
  868. },
  869. conjugate: function () {
  870. this._x *= - 1;
  871. this._y *= - 1;
  872. this._z *= - 1;
  873. this._onChangeCallback();
  874. return this;
  875. },
  876. dot: function ( v ) {
  877. return this._x * v._x + this._y * v._y + this._z * v._z + this._w * v._w;
  878. },
  879. lengthSq: function () {
  880. return this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w;
  881. },
  882. length: function () {
  883. return Math.sqrt( this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w );
  884. },
  885. normalize: function () {
  886. var l = this.length();
  887. if ( l === 0 ) {
  888. this._x = 0;
  889. this._y = 0;
  890. this._z = 0;
  891. this._w = 1;
  892. } else {
  893. l = 1 / l;
  894. this._x = this._x * l;
  895. this._y = this._y * l;
  896. this._z = this._z * l;
  897. this._w = this._w * l;
  898. }
  899. this._onChangeCallback();
  900. return this;
  901. },
  902. multiply: function ( q, p ) {
  903. if ( p !== undefined ) {
  904. console.warn( 'THREE.Quaternion: .multiply() now only accepts one argument. Use .multiplyQuaternions( a, b ) instead.' );
  905. return this.multiplyQuaternions( q, p );
  906. }
  907. return this.multiplyQuaternions( this, q );
  908. },
  909. premultiply: function ( q ) {
  910. return this.multiplyQuaternions( q, this );
  911. },
  912. multiplyQuaternions: function ( a, b ) {
  913. // from http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/code/index.htm
  914. var qax = a._x, qay = a._y, qaz = a._z, qaw = a._w;
  915. var qbx = b._x, qby = b._y, qbz = b._z, qbw = b._w;
  916. this._x = qax * qbw + qaw * qbx + qay * qbz - qaz * qby;
  917. this._y = qay * qbw + qaw * qby + qaz * qbx - qax * qbz;
  918. this._z = qaz * qbw + qaw * qbz + qax * qby - qay * qbx;
  919. this._w = qaw * qbw - qax * qbx - qay * qby - qaz * qbz;
  920. this._onChangeCallback();
  921. return this;
  922. },
  923. slerp: function ( qb, t ) {
  924. if ( t === 0 ) return this;
  925. if ( t === 1 ) return this.copy( qb );
  926. var x = this._x, y = this._y, z = this._z, w = this._w;
  927. // http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/slerp/
  928. var cosHalfTheta = w * qb._w + x * qb._x + y * qb._y + z * qb._z;
  929. if ( cosHalfTheta < 0 ) {
  930. this._w = - qb._w;
  931. this._x = - qb._x;
  932. this._y = - qb._y;
  933. this._z = - qb._z;
  934. cosHalfTheta = - cosHalfTheta;
  935. } else {
  936. this.copy( qb );
  937. }
  938. if ( cosHalfTheta >= 1.0 ) {
  939. this._w = w;
  940. this._x = x;
  941. this._y = y;
  942. this._z = z;
  943. return this;
  944. }
  945. var sqrSinHalfTheta = 1.0 - cosHalfTheta * cosHalfTheta;
  946. if ( sqrSinHalfTheta <= Number.EPSILON ) {
  947. var s = 1 - t;
  948. this._w = s * w + t * this._w;
  949. this._x = s * x + t * this._x;
  950. this._y = s * y + t * this._y;
  951. this._z = s * z + t * this._z;
  952. this.normalize();
  953. this._onChangeCallback();
  954. return this;
  955. }
  956. var sinHalfTheta = Math.sqrt( sqrSinHalfTheta );
  957. var halfTheta = Math.atan2( sinHalfTheta, cosHalfTheta );
  958. var ratioA = Math.sin( ( 1 - t ) * halfTheta ) / sinHalfTheta,
  959. ratioB = Math.sin( t * halfTheta ) / sinHalfTheta;
  960. this._w = ( w * ratioA + this._w * ratioB );
  961. this._x = ( x * ratioA + this._x * ratioB );
  962. this._y = ( y * ratioA + this._y * ratioB );
  963. this._z = ( z * ratioA + this._z * ratioB );
  964. this._onChangeCallback();
  965. return this;
  966. },
  967. equals: function ( quaternion ) {
  968. return ( quaternion._x === this._x ) && ( quaternion._y === this._y ) && ( quaternion._z === this._z ) && ( quaternion._w === this._w );
  969. },
  970. fromArray: function ( array, offset ) {
  971. if ( offset === undefined ) offset = 0;
  972. this._x = array[ offset ];
  973. this._y = array[ offset + 1 ];
  974. this._z = array[ offset + 2 ];
  975. this._w = array[ offset + 3 ];
  976. this._onChangeCallback();
  977. return this;
  978. },
  979. toArray: function ( array, offset ) {
  980. if ( array === undefined ) array = [];
  981. if ( offset === undefined ) offset = 0;
  982. array[ offset ] = this._x;
  983. array[ offset + 1 ] = this._y;
  984. array[ offset + 2 ] = this._z;
  985. array[ offset + 3 ] = this._w;
  986. return array;
  987. },
  988. _onChange: function ( callback ) {
  989. this._onChangeCallback = callback;
  990. return this;
  991. },
  992. _onChangeCallback: function () {}
  993. } );
  994. /**
  995. * @author mrdoob / http://mrdoob.com/
  996. * @author kile / http://kile.stravaganza.org/
  997. * @author philogb / http://blog.thejit.org/
  998. * @author mikael emtinger / http://gomo.se/
  999. * @author egraether / http://egraether.com/
  1000. * @author WestLangley / http://github.com/WestLangley
  1001. */
  1002. function Vector3( x, y, z ) {
  1003. this.x = x || 0;
  1004. this.y = y || 0;
  1005. this.z = z || 0;
  1006. }
  1007. Object.assign( Vector3.prototype, {
  1008. isVector3: true,
  1009. set: function ( x, y, z ) {
  1010. this.x = x;
  1011. this.y = y;
  1012. this.z = z;
  1013. return this;
  1014. },
  1015. setScalar: function ( scalar ) {
  1016. this.x = scalar;
  1017. this.y = scalar;
  1018. this.z = scalar;
  1019. return this;
  1020. },
  1021. setX: function ( x ) {
  1022. this.x = x;
  1023. return this;
  1024. },
  1025. setY: function ( y ) {
  1026. this.y = y;
  1027. return this;
  1028. },
  1029. setZ: function ( z ) {
  1030. this.z = z;
  1031. return this;
  1032. },
  1033. setComponent: function ( index, value ) {
  1034. switch ( index ) {
  1035. case 0: this.x = value; break;
  1036. case 1: this.y = value; break;
  1037. case 2: this.z = value; break;
  1038. default: throw new Error( 'index is out of range: ' + index );
  1039. }
  1040. return this;
  1041. },
  1042. getComponent: function ( index ) {
  1043. switch ( index ) {
  1044. case 0: return this.x;
  1045. case 1: return this.y;
  1046. case 2: return this.z;
  1047. default: throw new Error( 'index is out of range: ' + index );
  1048. }
  1049. },
  1050. clone: function () {
  1051. return new this.constructor( this.x, this.y, this.z );
  1052. },
  1053. copy: function ( v ) {
  1054. this.x = v.x;
  1055. this.y = v.y;
  1056. this.z = v.z;
  1057. return this;
  1058. },
  1059. add: function ( v, w ) {
  1060. if ( w !== undefined ) {
  1061. console.warn( 'THREE.Vector3: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  1062. return this.addVectors( v, w );
  1063. }
  1064. this.x += v.x;
  1065. this.y += v.y;
  1066. this.z += v.z;
  1067. return this;
  1068. },
  1069. addScalar: function ( s ) {
  1070. this.x += s;
  1071. this.y += s;
  1072. this.z += s;
  1073. return this;
  1074. },
  1075. addVectors: function ( a, b ) {
  1076. this.x = a.x + b.x;
  1077. this.y = a.y + b.y;
  1078. this.z = a.z + b.z;
  1079. return this;
  1080. },
  1081. addScaledVector: function ( v, s ) {
  1082. this.x += v.x * s;
  1083. this.y += v.y * s;
  1084. this.z += v.z * s;
  1085. return this;
  1086. },
  1087. sub: function ( v, w ) {
  1088. if ( w !== undefined ) {
  1089. console.warn( 'THREE.Vector3: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  1090. return this.subVectors( v, w );
  1091. }
  1092. this.x -= v.x;
  1093. this.y -= v.y;
  1094. this.z -= v.z;
  1095. return this;
  1096. },
  1097. subScalar: function ( s ) {
  1098. this.x -= s;
  1099. this.y -= s;
  1100. this.z -= s;
  1101. return this;
  1102. },
  1103. subVectors: function ( a, b ) {
  1104. this.x = a.x - b.x;
  1105. this.y = a.y - b.y;
  1106. this.z = a.z - b.z;
  1107. return this;
  1108. },
  1109. multiply: function ( v, w ) {
  1110. if ( w !== undefined ) {
  1111. console.warn( 'THREE.Vector3: .multiply() now only accepts one argument. Use .multiplyVectors( a, b ) instead.' );
  1112. return this.multiplyVectors( v, w );
  1113. }
  1114. this.x *= v.x;
  1115. this.y *= v.y;
  1116. this.z *= v.z;
  1117. return this;
  1118. },
  1119. multiplyScalar: function ( scalar ) {
  1120. this.x *= scalar;
  1121. this.y *= scalar;
  1122. this.z *= scalar;
  1123. return this;
  1124. },
  1125. multiplyVectors: function ( a, b ) {
  1126. this.x = a.x * b.x;
  1127. this.y = a.y * b.y;
  1128. this.z = a.z * b.z;
  1129. return this;
  1130. },
  1131. applyEuler: function () {
  1132. var quaternion = new Quaternion();
  1133. return function applyEuler( euler ) {
  1134. if ( ! ( euler && euler.isEuler ) ) {
  1135. console.error( 'THREE.Vector3: .applyEuler() now expects an Euler rotation rather than a Vector3 and order.' );
  1136. }
  1137. return this.applyQuaternion( quaternion.setFromEuler( euler ) );
  1138. };
  1139. }(),
  1140. applyAxisAngle: function () {
  1141. var quaternion = new Quaternion();
  1142. return function applyAxisAngle( axis, angle ) {
  1143. return this.applyQuaternion( quaternion.setFromAxisAngle( axis, angle ) );
  1144. };
  1145. }(),
  1146. applyMatrix3: function ( m ) {
  1147. var x = this.x, y = this.y, z = this.z;
  1148. var e = m.elements;
  1149. this.x = e[ 0 ] * x + e[ 3 ] * y + e[ 6 ] * z;
  1150. this.y = e[ 1 ] * x + e[ 4 ] * y + e[ 7 ] * z;
  1151. this.z = e[ 2 ] * x + e[ 5 ] * y + e[ 8 ] * z;
  1152. return this;
  1153. },
  1154. applyMatrix4: function ( m ) {
  1155. var x = this.x, y = this.y, z = this.z;
  1156. var e = m.elements;
  1157. var w = 1 / ( e[ 3 ] * x + e[ 7 ] * y + e[ 11 ] * z + e[ 15 ] );
  1158. this.x = ( e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ] ) * w;
  1159. this.y = ( e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ] ) * w;
  1160. this.z = ( e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ] ) * w;
  1161. return this;
  1162. },
  1163. applyQuaternion: function ( q ) {
  1164. var x = this.x, y = this.y, z = this.z;
  1165. var qx = q.x, qy = q.y, qz = q.z, qw = q.w;
  1166. // calculate quat * vector
  1167. var ix = qw * x + qy * z - qz * y;
  1168. var iy = qw * y + qz * x - qx * z;
  1169. var iz = qw * z + qx * y - qy * x;
  1170. var iw = - qx * x - qy * y - qz * z;
  1171. // calculate result * inverse quat
  1172. this.x = ix * qw + iw * - qx + iy * - qz - iz * - qy;
  1173. this.y = iy * qw + iw * - qy + iz * - qx - ix * - qz;
  1174. this.z = iz * qw + iw * - qz + ix * - qy - iy * - qx;
  1175. return this;
  1176. },
  1177. project: function ( camera ) {
  1178. return this.applyMatrix4( camera.matrixWorldInverse ).applyMatrix4( camera.projectionMatrix );
  1179. },
  1180. unproject: function ( camera ) {
  1181. return this.applyMatrix4( camera.projectionMatrixInverse ).applyMatrix4( camera.matrixWorld );
  1182. },
  1183. transformDirection: function ( m ) {
  1184. // input: THREE.Matrix4 affine matrix
  1185. // vector interpreted as a direction
  1186. var x = this.x, y = this.y, z = this.z;
  1187. var e = m.elements;
  1188. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z;
  1189. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z;
  1190. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z;
  1191. return this.normalize();
  1192. },
  1193. divide: function ( v ) {
  1194. this.x /= v.x;
  1195. this.y /= v.y;
  1196. this.z /= v.z;
  1197. return this;
  1198. },
  1199. divideScalar: function ( scalar ) {
  1200. return this.multiplyScalar( 1 / scalar );
  1201. },
  1202. min: function ( v ) {
  1203. this.x = Math.min( this.x, v.x );
  1204. this.y = Math.min( this.y, v.y );
  1205. this.z = Math.min( this.z, v.z );
  1206. return this;
  1207. },
  1208. max: function ( v ) {
  1209. this.x = Math.max( this.x, v.x );
  1210. this.y = Math.max( this.y, v.y );
  1211. this.z = Math.max( this.z, v.z );
  1212. return this;
  1213. },
  1214. clamp: function ( min, max ) {
  1215. // assumes min < max, componentwise
  1216. this.x = Math.max( min.x, Math.min( max.x, this.x ) );
  1217. this.y = Math.max( min.y, Math.min( max.y, this.y ) );
  1218. this.z = Math.max( min.z, Math.min( max.z, this.z ) );
  1219. return this;
  1220. },
  1221. clampScalar: function ( minVal, maxVal ) {
  1222. this.x = Math.max( minVal, Math.min( maxVal, this.x ) );
  1223. this.y = Math.max( minVal, Math.min( maxVal, this.y ) );
  1224. this.z = Math.max( minVal, Math.min( maxVal, this.z ) );
  1225. return this;
  1226. },
  1227. clampLength: function ( min, max ) {
  1228. var length = this.length();
  1229. return this.divideScalar( length || 1 ).multiplyScalar( Math.max( min, Math.min( max, length ) ) );
  1230. },
  1231. floor: function () {
  1232. this.x = Math.floor( this.x );
  1233. this.y = Math.floor( this.y );
  1234. this.z = Math.floor( this.z );
  1235. return this;
  1236. },
  1237. ceil: function () {
  1238. this.x = Math.ceil( this.x );
  1239. this.y = Math.ceil( this.y );
  1240. this.z = Math.ceil( this.z );
  1241. return this;
  1242. },
  1243. round: function () {
  1244. this.x = Math.round( this.x );
  1245. this.y = Math.round( this.y );
  1246. this.z = Math.round( this.z );
  1247. return this;
  1248. },
  1249. roundToZero: function () {
  1250. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  1251. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  1252. this.z = ( this.z < 0 ) ? Math.ceil( this.z ) : Math.floor( this.z );
  1253. return this;
  1254. },
  1255. negate: function () {
  1256. this.x = - this.x;
  1257. this.y = - this.y;
  1258. this.z = - this.z;
  1259. return this;
  1260. },
  1261. dot: function ( v ) {
  1262. return this.x * v.x + this.y * v.y + this.z * v.z;
  1263. },
  1264. // TODO lengthSquared?
  1265. lengthSq: function () {
  1266. return this.x * this.x + this.y * this.y + this.z * this.z;
  1267. },
  1268. length: function () {
  1269. return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z );
  1270. },
  1271. manhattanLength: function () {
  1272. return Math.abs( this.x ) + Math.abs( this.y ) + Math.abs( this.z );
  1273. },
  1274. normalize: function () {
  1275. return this.divideScalar( this.length() || 1 );
  1276. },
  1277. setLength: function ( length ) {
  1278. return this.normalize().multiplyScalar( length );
  1279. },
  1280. lerp: function ( v, alpha ) {
  1281. this.x += ( v.x - this.x ) * alpha;
  1282. this.y += ( v.y - this.y ) * alpha;
  1283. this.z += ( v.z - this.z ) * alpha;
  1284. return this;
  1285. },
  1286. lerpVectors: function ( v1, v2, alpha ) {
  1287. return this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  1288. },
  1289. cross: function ( v, w ) {
  1290. if ( w !== undefined ) {
  1291. console.warn( 'THREE.Vector3: .cross() now only accepts one argument. Use .crossVectors( a, b ) instead.' );
  1292. return this.crossVectors( v, w );
  1293. }
  1294. return this.crossVectors( this, v );
  1295. },
  1296. crossVectors: function ( a, b ) {
  1297. var ax = a.x, ay = a.y, az = a.z;
  1298. var bx = b.x, by = b.y, bz = b.z;
  1299. this.x = ay * bz - az * by;
  1300. this.y = az * bx - ax * bz;
  1301. this.z = ax * by - ay * bx;
  1302. return this;
  1303. },
  1304. projectOnVector: function ( vector ) {
  1305. var scalar = vector.dot( this ) / vector.lengthSq();
  1306. return this.copy( vector ).multiplyScalar( scalar );
  1307. },
  1308. projectOnPlane: function () {
  1309. var v1 = new Vector3();
  1310. return function projectOnPlane( planeNormal ) {
  1311. v1.copy( this ).projectOnVector( planeNormal );
  1312. return this.sub( v1 );
  1313. };
  1314. }(),
  1315. reflect: function () {
  1316. // reflect incident vector off plane orthogonal to normal
  1317. // normal is assumed to have unit length
  1318. var v1 = new Vector3();
  1319. return function reflect( normal ) {
  1320. return this.sub( v1.copy( normal ).multiplyScalar( 2 * this.dot( normal ) ) );
  1321. };
  1322. }(),
  1323. angleTo: function ( v ) {
  1324. var theta = this.dot( v ) / ( Math.sqrt( this.lengthSq() * v.lengthSq() ) );
  1325. // clamp, to handle numerical problems
  1326. return Math.acos( _Math.clamp( theta, - 1, 1 ) );
  1327. },
  1328. distanceTo: function ( v ) {
  1329. return Math.sqrt( this.distanceToSquared( v ) );
  1330. },
  1331. distanceToSquared: function ( v ) {
  1332. var dx = this.x - v.x, dy = this.y - v.y, dz = this.z - v.z;
  1333. return dx * dx + dy * dy + dz * dz;
  1334. },
  1335. manhattanDistanceTo: function ( v ) {
  1336. return Math.abs( this.x - v.x ) + Math.abs( this.y - v.y ) + Math.abs( this.z - v.z );
  1337. },
  1338. setFromSpherical: function ( s ) {
  1339. return this.setFromSphericalCoords( s.radius, s.phi, s.theta );
  1340. },
  1341. setFromSphericalCoords: function ( radius, phi, theta ) {
  1342. var sinPhiRadius = Math.sin( phi ) * radius;
  1343. this.x = sinPhiRadius * Math.sin( theta );
  1344. this.y = Math.cos( phi ) * radius;
  1345. this.z = sinPhiRadius * Math.cos( theta );
  1346. return this;
  1347. },
  1348. setFromCylindrical: function ( c ) {
  1349. return this.setFromCylindricalCoords( c.radius, c.theta, c.y );
  1350. },
  1351. setFromCylindricalCoords: function ( radius, theta, y ) {
  1352. this.x = radius * Math.sin( theta );
  1353. this.y = y;
  1354. this.z = radius * Math.cos( theta );
  1355. return this;
  1356. },
  1357. setFromMatrixPosition: function ( m ) {
  1358. var e = m.elements;
  1359. this.x = e[ 12 ];
  1360. this.y = e[ 13 ];
  1361. this.z = e[ 14 ];
  1362. return this;
  1363. },
  1364. setFromMatrixScale: function ( m ) {
  1365. var sx = this.setFromMatrixColumn( m, 0 ).length();
  1366. var sy = this.setFromMatrixColumn( m, 1 ).length();
  1367. var sz = this.setFromMatrixColumn( m, 2 ).length();
  1368. this.x = sx;
  1369. this.y = sy;
  1370. this.z = sz;
  1371. return this;
  1372. },
  1373. setFromMatrixColumn: function ( m, index ) {
  1374. return this.fromArray( m.elements, index * 4 );
  1375. },
  1376. equals: function ( v ) {
  1377. return ( ( v.x === this.x ) && ( v.y === this.y ) && ( v.z === this.z ) );
  1378. },
  1379. fromArray: function ( array, offset ) {
  1380. if ( offset === undefined ) offset = 0;
  1381. this.x = array[ offset ];
  1382. this.y = array[ offset + 1 ];
  1383. this.z = array[ offset + 2 ];
  1384. return this;
  1385. },
  1386. toArray: function ( array, offset ) {
  1387. if ( array === undefined ) array = [];
  1388. if ( offset === undefined ) offset = 0;
  1389. array[ offset ] = this.x;
  1390. array[ offset + 1 ] = this.y;
  1391. array[ offset + 2 ] = this.z;
  1392. return array;
  1393. },
  1394. fromBufferAttribute: function ( attribute, index, offset ) {
  1395. if ( offset !== undefined ) {
  1396. console.warn( 'THREE.Vector3: offset has been removed from .fromBufferAttribute().' );
  1397. }
  1398. this.x = attribute.getX( index );
  1399. this.y = attribute.getY( index );
  1400. this.z = attribute.getZ( index );
  1401. return this;
  1402. }
  1403. } );
  1404. /**
  1405. * @author alteredq / http://alteredqualia.com/
  1406. * @author WestLangley / http://github.com/WestLangley
  1407. * @author bhouston / http://clara.io
  1408. * @author tschw
  1409. */
  1410. function Matrix3() {
  1411. this.elements = [
  1412. 1, 0, 0,
  1413. 0, 1, 0,
  1414. 0, 0, 1
  1415. ];
  1416. if ( arguments.length > 0 ) {
  1417. console.error( 'THREE.Matrix3: the constructor no longer reads arguments. use .set() instead.' );
  1418. }
  1419. }
  1420. Object.assign( Matrix3.prototype, {
  1421. isMatrix3: true,
  1422. set: function ( n11, n12, n13, n21, n22, n23, n31, n32, n33 ) {
  1423. var te = this.elements;
  1424. te[ 0 ] = n11; te[ 1 ] = n21; te[ 2 ] = n31;
  1425. te[ 3 ] = n12; te[ 4 ] = n22; te[ 5 ] = n32;
  1426. te[ 6 ] = n13; te[ 7 ] = n23; te[ 8 ] = n33;
  1427. return this;
  1428. },
  1429. identity: function () {
  1430. this.set(
  1431. 1, 0, 0,
  1432. 0, 1, 0,
  1433. 0, 0, 1
  1434. );
  1435. return this;
  1436. },
  1437. clone: function () {
  1438. return new this.constructor().fromArray( this.elements );
  1439. },
  1440. copy: function ( m ) {
  1441. var te = this.elements;
  1442. var me = m.elements;
  1443. te[ 0 ] = me[ 0 ]; te[ 1 ] = me[ 1 ]; te[ 2 ] = me[ 2 ];
  1444. te[ 3 ] = me[ 3 ]; te[ 4 ] = me[ 4 ]; te[ 5 ] = me[ 5 ];
  1445. te[ 6 ] = me[ 6 ]; te[ 7 ] = me[ 7 ]; te[ 8 ] = me[ 8 ];
  1446. return this;
  1447. },
  1448. setFromMatrix4: function ( m ) {
  1449. var me = m.elements;
  1450. this.set(
  1451. me[ 0 ], me[ 4 ], me[ 8 ],
  1452. me[ 1 ], me[ 5 ], me[ 9 ],
  1453. me[ 2 ], me[ 6 ], me[ 10 ]
  1454. );
  1455. return this;
  1456. },
  1457. applyToBufferAttribute: function () {
  1458. var v1 = new Vector3();
  1459. return function applyToBufferAttribute( attribute ) {
  1460. for ( var i = 0, l = attribute.count; i < l; i ++ ) {
  1461. v1.x = attribute.getX( i );
  1462. v1.y = attribute.getY( i );
  1463. v1.z = attribute.getZ( i );
  1464. v1.applyMatrix3( this );
  1465. attribute.setXYZ( i, v1.x, v1.y, v1.z );
  1466. }
  1467. return attribute;
  1468. };
  1469. }(),
  1470. multiply: function ( m ) {
  1471. return this.multiplyMatrices( this, m );
  1472. },
  1473. premultiply: function ( m ) {
  1474. return this.multiplyMatrices( m, this );
  1475. },
  1476. multiplyMatrices: function ( a, b ) {
  1477. var ae = a.elements;
  1478. var be = b.elements;
  1479. var te = this.elements;
  1480. var a11 = ae[ 0 ], a12 = ae[ 3 ], a13 = ae[ 6 ];
  1481. var a21 = ae[ 1 ], a22 = ae[ 4 ], a23 = ae[ 7 ];
  1482. var a31 = ae[ 2 ], a32 = ae[ 5 ], a33 = ae[ 8 ];
  1483. var b11 = be[ 0 ], b12 = be[ 3 ], b13 = be[ 6 ];
  1484. var b21 = be[ 1 ], b22 = be[ 4 ], b23 = be[ 7 ];
  1485. var b31 = be[ 2 ], b32 = be[ 5 ], b33 = be[ 8 ];
  1486. te[ 0 ] = a11 * b11 + a12 * b21 + a13 * b31;
  1487. te[ 3 ] = a11 * b12 + a12 * b22 + a13 * b32;
  1488. te[ 6 ] = a11 * b13 + a12 * b23 + a13 * b33;
  1489. te[ 1 ] = a21 * b11 + a22 * b21 + a23 * b31;
  1490. te[ 4 ] = a21 * b12 + a22 * b22 + a23 * b32;
  1491. te[ 7 ] = a21 * b13 + a22 * b23 + a23 * b33;
  1492. te[ 2 ] = a31 * b11 + a32 * b21 + a33 * b31;
  1493. te[ 5 ] = a31 * b12 + a32 * b22 + a33 * b32;
  1494. te[ 8 ] = a31 * b13 + a32 * b23 + a33 * b33;
  1495. return this;
  1496. },
  1497. multiplyScalar: function ( s ) {
  1498. var te = this.elements;
  1499. te[ 0 ] *= s; te[ 3 ] *= s; te[ 6 ] *= s;
  1500. te[ 1 ] *= s; te[ 4 ] *= s; te[ 7 ] *= s;
  1501. te[ 2 ] *= s; te[ 5 ] *= s; te[ 8 ] *= s;
  1502. return this;
  1503. },
  1504. determinant: function () {
  1505. var te = this.elements;
  1506. var a = te[ 0 ], b = te[ 1 ], c = te[ 2 ],
  1507. d = te[ 3 ], e = te[ 4 ], f = te[ 5 ],
  1508. g = te[ 6 ], h = te[ 7 ], i = te[ 8 ];
  1509. return a * e * i - a * f * h - b * d * i + b * f * g + c * d * h - c * e * g;
  1510. },
  1511. getInverse: function ( matrix, throwOnDegenerate ) {
  1512. if ( matrix && matrix.isMatrix4 ) {
  1513. console.error( "THREE.Matrix3: .getInverse() no longer takes a Matrix4 argument." );
  1514. }
  1515. var me = matrix.elements,
  1516. te = this.elements,
  1517. n11 = me[ 0 ], n21 = me[ 1 ], n31 = me[ 2 ],
  1518. n12 = me[ 3 ], n22 = me[ 4 ], n32 = me[ 5 ],
  1519. n13 = me[ 6 ], n23 = me[ 7 ], n33 = me[ 8 ],
  1520. t11 = n33 * n22 - n32 * n23,
  1521. t12 = n32 * n13 - n33 * n12,
  1522. t13 = n23 * n12 - n22 * n13,
  1523. det = n11 * t11 + n21 * t12 + n31 * t13;
  1524. if ( det === 0 ) {
  1525. var msg = "THREE.Matrix3: .getInverse() can't invert matrix, determinant is 0";
  1526. if ( throwOnDegenerate === true ) {
  1527. throw new Error( msg );
  1528. } else {
  1529. console.warn( msg );
  1530. }
  1531. return this.identity();
  1532. }
  1533. var detInv = 1 / det;
  1534. te[ 0 ] = t11 * detInv;
  1535. te[ 1 ] = ( n31 * n23 - n33 * n21 ) * detInv;
  1536. te[ 2 ] = ( n32 * n21 - n31 * n22 ) * detInv;
  1537. te[ 3 ] = t12 * detInv;
  1538. te[ 4 ] = ( n33 * n11 - n31 * n13 ) * detInv;
  1539. te[ 5 ] = ( n31 * n12 - n32 * n11 ) * detInv;
  1540. te[ 6 ] = t13 * detInv;
  1541. te[ 7 ] = ( n21 * n13 - n23 * n11 ) * detInv;
  1542. te[ 8 ] = ( n22 * n11 - n21 * n12 ) * detInv;
  1543. return this;
  1544. },
  1545. transpose: function () {
  1546. var tmp, m = this.elements;
  1547. tmp = m[ 1 ]; m[ 1 ] = m[ 3 ]; m[ 3 ] = tmp;
  1548. tmp = m[ 2 ]; m[ 2 ] = m[ 6 ]; m[ 6 ] = tmp;
  1549. tmp = m[ 5 ]; m[ 5 ] = m[ 7 ]; m[ 7 ] = tmp;
  1550. return this;
  1551. },
  1552. getNormalMatrix: function ( matrix4 ) {
  1553. return this.setFromMatrix4( matrix4 ).getInverse( this ).transpose();
  1554. },
  1555. transposeIntoArray: function ( r ) {
  1556. var m = this.elements;
  1557. r[ 0 ] = m[ 0 ];
  1558. r[ 1 ] = m[ 3 ];
  1559. r[ 2 ] = m[ 6 ];
  1560. r[ 3 ] = m[ 1 ];
  1561. r[ 4 ] = m[ 4 ];
  1562. r[ 5 ] = m[ 7 ];
  1563. r[ 6 ] = m[ 2 ];
  1564. r[ 7 ] = m[ 5 ];
  1565. r[ 8 ] = m[ 8 ];
  1566. return this;
  1567. },
  1568. setUvTransform: function ( tx, ty, sx, sy, rotation, cx, cy ) {
  1569. var c = Math.cos( rotation );
  1570. var s = Math.sin( rotation );
  1571. this.set(
  1572. sx * c, sx * s, - sx * ( c * cx + s * cy ) + cx + tx,
  1573. - sy * s, sy * c, - sy * ( - s * cx + c * cy ) + cy + ty,
  1574. 0, 0, 1
  1575. );
  1576. },
  1577. scale: function ( sx, sy ) {
  1578. var te = this.elements;
  1579. te[ 0 ] *= sx; te[ 3 ] *= sx; te[ 6 ] *= sx;
  1580. te[ 1 ] *= sy; te[ 4 ] *= sy; te[ 7 ] *= sy;
  1581. return this;
  1582. },
  1583. rotate: function ( theta ) {
  1584. var c = Math.cos( theta );
  1585. var s = Math.sin( theta );
  1586. var te = this.elements;
  1587. var a11 = te[ 0 ], a12 = te[ 3 ], a13 = te[ 6 ];
  1588. var a21 = te[ 1 ], a22 = te[ 4 ], a23 = te[ 7 ];
  1589. te[ 0 ] = c * a11 + s * a21;
  1590. te[ 3 ] = c * a12 + s * a22;
  1591. te[ 6 ] = c * a13 + s * a23;
  1592. te[ 1 ] = - s * a11 + c * a21;
  1593. te[ 4 ] = - s * a12 + c * a22;
  1594. te[ 7 ] = - s * a13 + c * a23;
  1595. return this;
  1596. },
  1597. translate: function ( tx, ty ) {
  1598. var te = this.elements;
  1599. te[ 0 ] += tx * te[ 2 ]; te[ 3 ] += tx * te[ 5 ]; te[ 6 ] += tx * te[ 8 ];
  1600. te[ 1 ] += ty * te[ 2 ]; te[ 4 ] += ty * te[ 5 ]; te[ 7 ] += ty * te[ 8 ];
  1601. return this;
  1602. },
  1603. equals: function ( matrix ) {
  1604. var te = this.elements;
  1605. var me = matrix.elements;
  1606. for ( var i = 0; i < 9; i ++ ) {
  1607. if ( te[ i ] !== me[ i ] ) return false;
  1608. }
  1609. return true;
  1610. },
  1611. fromArray: function ( array, offset ) {
  1612. if ( offset === undefined ) offset = 0;
  1613. for ( var i = 0; i < 9; i ++ ) {
  1614. this.elements[ i ] = array[ i + offset ];
  1615. }
  1616. return this;
  1617. },
  1618. toArray: function ( array, offset ) {
  1619. if ( array === undefined ) array = [];
  1620. if ( offset === undefined ) offset = 0;
  1621. var te = this.elements;
  1622. array[ offset ] = te[ 0 ];
  1623. array[ offset + 1 ] = te[ 1 ];
  1624. array[ offset + 2 ] = te[ 2 ];
  1625. array[ offset + 3 ] = te[ 3 ];
  1626. array[ offset + 4 ] = te[ 4 ];
  1627. array[ offset + 5 ] = te[ 5 ];
  1628. array[ offset + 6 ] = te[ 6 ];
  1629. array[ offset + 7 ] = te[ 7 ];
  1630. array[ offset + 8 ] = te[ 8 ];
  1631. return array;
  1632. }
  1633. } );
  1634. /**
  1635. * @author mrdoob / http://mrdoob.com/
  1636. * @author alteredq / http://alteredqualia.com/
  1637. * @author szimek / https://github.com/szimek/
  1638. */
  1639. var _canvas;
  1640. var ImageUtils = {
  1641. getDataURL: function ( image ) {
  1642. var canvas;
  1643. if ( typeof HTMLCanvasElement == 'undefined' ) {
  1644. return image.src;
  1645. } else if ( image instanceof HTMLCanvasElement ) {
  1646. canvas = image;
  1647. } else {
  1648. if ( _canvas === undefined ) _canvas = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' );
  1649. _canvas.width = image.width;
  1650. _canvas.height = image.height;
  1651. var context = _canvas.getContext( '2d' );
  1652. if ( image instanceof ImageData ) {
  1653. context.putImageData( image, 0, 0 );
  1654. } else {
  1655. context.drawImage( image, 0, 0, image.width, image.height );
  1656. }
  1657. canvas = _canvas;
  1658. }
  1659. if ( canvas.width > 2048 || canvas.height > 2048 ) {
  1660. return canvas.toDataURL( 'image/jpeg', 0.6 );
  1661. } else {
  1662. return canvas.toDataURL( 'image/png' );
  1663. }
  1664. }
  1665. };
  1666. /**
  1667. * @author mrdoob / http://mrdoob.com/
  1668. * @author alteredq / http://alteredqualia.com/
  1669. * @author szimek / https://github.com/szimek/
  1670. */
  1671. var textureId = 0;
  1672. function Texture( image, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding ) {
  1673. Object.defineProperty( this, 'id', { value: textureId ++ } );
  1674. this.uuid = _Math.generateUUID();
  1675. this.name = '';
  1676. this.image = image !== undefined ? image : Texture.DEFAULT_IMAGE;
  1677. this.mipmaps = [];
  1678. this.mapping = mapping !== undefined ? mapping : Texture.DEFAULT_MAPPING;
  1679. this.wrapS = wrapS !== undefined ? wrapS : ClampToEdgeWrapping;
  1680. this.wrapT = wrapT !== undefined ? wrapT : ClampToEdgeWrapping;
  1681. this.magFilter = magFilter !== undefined ? magFilter : LinearFilter;
  1682. this.minFilter = minFilter !== undefined ? minFilter : LinearMipmapLinearFilter;
  1683. this.anisotropy = anisotropy !== undefined ? anisotropy : 1;
  1684. this.format = format !== undefined ? format : RGBAFormat;
  1685. this.type = type !== undefined ? type : UnsignedByteType;
  1686. this.offset = new Vector2( 0, 0 );
  1687. this.repeat = new Vector2( 1, 1 );
  1688. this.center = new Vector2( 0, 0 );
  1689. this.rotation = 0;
  1690. this.matrixAutoUpdate = true;
  1691. this.matrix = new Matrix3();
  1692. this.generateMipmaps = true;
  1693. this.premultiplyAlpha = false;
  1694. this.flipY = true;
  1695. this.unpackAlignment = 4; // valid values: 1, 2, 4, 8 (see http://www.khronos.org/opengles/sdk/docs/man/xhtml/glPixelStorei.xml)
  1696. // Values of encoding !== THREE.LinearEncoding only supported on map, envMap and emissiveMap.
  1697. //
  1698. // Also changing the encoding after already used by a Material will not automatically make the Material
  1699. // update. You need to explicitly call Material.needsUpdate to trigger it to recompile.
  1700. this.encoding = encoding !== undefined ? encoding : LinearEncoding;
  1701. this.version = 0;
  1702. this.onUpdate = null;
  1703. }
  1704. Texture.DEFAULT_IMAGE = undefined;
  1705. Texture.DEFAULT_MAPPING = UVMapping;
  1706. Texture.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  1707. constructor: Texture,
  1708. isTexture: true,
  1709. updateMatrix: function () {
  1710. this.matrix.setUvTransform( this.offset.x, this.offset.y, this.repeat.x, this.repeat.y, this.rotation, this.center.x, this.center.y );
  1711. },
  1712. clone: function () {
  1713. return new this.constructor().copy( this );
  1714. },
  1715. copy: function ( source ) {
  1716. this.name = source.name;
  1717. this.image = source.image;
  1718. this.mipmaps = source.mipmaps.slice( 0 );
  1719. this.mapping = source.mapping;
  1720. this.wrapS = source.wrapS;
  1721. this.wrapT = source.wrapT;
  1722. this.magFilter = source.magFilter;
  1723. this.minFilter = source.minFilter;
  1724. this.anisotropy = source.anisotropy;
  1725. this.format = source.format;
  1726. this.type = source.type;
  1727. this.offset.copy( source.offset );
  1728. this.repeat.copy( source.repeat );
  1729. this.center.copy( source.center );
  1730. this.rotation = source.rotation;
  1731. this.matrixAutoUpdate = source.matrixAutoUpdate;
  1732. this.matrix.copy( source.matrix );
  1733. this.generateMipmaps = source.generateMipmaps;
  1734. this.premultiplyAlpha = source.premultiplyAlpha;
  1735. this.flipY = source.flipY;
  1736. this.unpackAlignment = source.unpackAlignment;
  1737. this.encoding = source.encoding;
  1738. return this;
  1739. },
  1740. toJSON: function ( meta ) {
  1741. var isRootObject = ( meta === undefined || typeof meta === 'string' );
  1742. if ( ! isRootObject && meta.textures[ this.uuid ] !== undefined ) {
  1743. return meta.textures[ this.uuid ];
  1744. }
  1745. var output = {
  1746. metadata: {
  1747. version: 4.5,
  1748. type: 'Texture',
  1749. generator: 'Texture.toJSON'
  1750. },
  1751. uuid: this.uuid,
  1752. name: this.name,
  1753. mapping: this.mapping,
  1754. repeat: [ this.repeat.x, this.repeat.y ],
  1755. offset: [ this.offset.x, this.offset.y ],
  1756. center: [ this.center.x, this.center.y ],
  1757. rotation: this.rotation,
  1758. wrap: [ this.wrapS, this.wrapT ],
  1759. format: this.format,
  1760. type: this.type,
  1761. encoding: this.encoding,
  1762. minFilter: this.minFilter,
  1763. magFilter: this.magFilter,
  1764. anisotropy: this.anisotropy,
  1765. flipY: this.flipY,
  1766. premultiplyAlpha: this.premultiplyAlpha,
  1767. unpackAlignment: this.unpackAlignment
  1768. };
  1769. if ( this.image !== undefined ) {
  1770. // TODO: Move to THREE.Image
  1771. var image = this.image;
  1772. if ( image.uuid === undefined ) {
  1773. image.uuid = _Math.generateUUID(); // UGH
  1774. }
  1775. if ( ! isRootObject && meta.images[ image.uuid ] === undefined ) {
  1776. var url;
  1777. if ( Array.isArray( image ) ) {
  1778. // process array of images e.g. CubeTexture
  1779. url = [];
  1780. for ( var i = 0, l = image.length; i < l; i ++ ) {
  1781. url.push( ImageUtils.getDataURL( image[ i ] ) );
  1782. }
  1783. } else {
  1784. // process single image
  1785. url = ImageUtils.getDataURL( image );
  1786. }
  1787. meta.images[ image.uuid ] = {
  1788. uuid: image.uuid,
  1789. url: url
  1790. };
  1791. }
  1792. output.image = image.uuid;
  1793. }
  1794. if ( ! isRootObject ) {
  1795. meta.textures[ this.uuid ] = output;
  1796. }
  1797. return output;
  1798. },
  1799. dispose: function () {
  1800. this.dispatchEvent( { type: 'dispose' } );
  1801. },
  1802. transformUv: function ( uv ) {
  1803. if ( this.mapping !== UVMapping ) return uv;
  1804. uv.applyMatrix3( this.matrix );
  1805. if ( uv.x < 0 || uv.x > 1 ) {
  1806. switch ( this.wrapS ) {
  1807. case RepeatWrapping:
  1808. uv.x = uv.x - Math.floor( uv.x );
  1809. break;
  1810. case ClampToEdgeWrapping:
  1811. uv.x = uv.x < 0 ? 0 : 1;
  1812. break;
  1813. case MirroredRepeatWrapping:
  1814. if ( Math.abs( Math.floor( uv.x ) % 2 ) === 1 ) {
  1815. uv.x = Math.ceil( uv.x ) - uv.x;
  1816. } else {
  1817. uv.x = uv.x - Math.floor( uv.x );
  1818. }
  1819. break;
  1820. }
  1821. }
  1822. if ( uv.y < 0 || uv.y > 1 ) {
  1823. switch ( this.wrapT ) {
  1824. case RepeatWrapping:
  1825. uv.y = uv.y - Math.floor( uv.y );
  1826. break;
  1827. case ClampToEdgeWrapping:
  1828. uv.y = uv.y < 0 ? 0 : 1;
  1829. break;
  1830. case MirroredRepeatWrapping:
  1831. if ( Math.abs( Math.floor( uv.y ) % 2 ) === 1 ) {
  1832. uv.y = Math.ceil( uv.y ) - uv.y;
  1833. } else {
  1834. uv.y = uv.y - Math.floor( uv.y );
  1835. }
  1836. break;
  1837. }
  1838. }
  1839. if ( this.flipY ) {
  1840. uv.y = 1 - uv.y;
  1841. }
  1842. return uv;
  1843. }
  1844. } );
  1845. Object.defineProperty( Texture.prototype, "needsUpdate", {
  1846. set: function ( value ) {
  1847. if ( value === true ) this.version ++;
  1848. }
  1849. } );
  1850. /**
  1851. * @author supereggbert / http://www.paulbrunt.co.uk/
  1852. * @author philogb / http://blog.thejit.org/
  1853. * @author mikael emtinger / http://gomo.se/
  1854. * @author egraether / http://egraether.com/
  1855. * @author WestLangley / http://github.com/WestLangley
  1856. */
  1857. function Vector4( x, y, z, w ) {
  1858. this.x = x || 0;
  1859. this.y = y || 0;
  1860. this.z = z || 0;
  1861. this.w = ( w !== undefined ) ? w : 1;
  1862. }
  1863. Object.defineProperties( Vector4.prototype, {
  1864. "width": {
  1865. get: function () {
  1866. return this.z;
  1867. },
  1868. set: function ( value ) {
  1869. this.z = value;
  1870. }
  1871. },
  1872. "height": {
  1873. get: function () {
  1874. return this.w;
  1875. },
  1876. set: function ( value ) {
  1877. this.w = value;
  1878. }
  1879. }
  1880. } );
  1881. Object.assign( Vector4.prototype, {
  1882. isVector4: true,
  1883. set: function ( x, y, z, w ) {
  1884. this.x = x;
  1885. this.y = y;
  1886. this.z = z;
  1887. this.w = w;
  1888. return this;
  1889. },
  1890. setScalar: function ( scalar ) {
  1891. this.x = scalar;
  1892. this.y = scalar;
  1893. this.z = scalar;
  1894. this.w = scalar;
  1895. return this;
  1896. },
  1897. setX: function ( x ) {
  1898. this.x = x;
  1899. return this;
  1900. },
  1901. setY: function ( y ) {
  1902. this.y = y;
  1903. return this;
  1904. },
  1905. setZ: function ( z ) {
  1906. this.z = z;
  1907. return this;
  1908. },
  1909. setW: function ( w ) {
  1910. this.w = w;
  1911. return this;
  1912. },
  1913. setComponent: function ( index, value ) {
  1914. switch ( index ) {
  1915. case 0: this.x = value; break;
  1916. case 1: this.y = value; break;
  1917. case 2: this.z = value; break;
  1918. case 3: this.w = value; break;
  1919. default: throw new Error( 'index is out of range: ' + index );
  1920. }
  1921. return this;
  1922. },
  1923. getComponent: function ( index ) {
  1924. switch ( index ) {
  1925. case 0: return this.x;
  1926. case 1: return this.y;
  1927. case 2: return this.z;
  1928. case 3: return this.w;
  1929. default: throw new Error( 'index is out of range: ' + index );
  1930. }
  1931. },
  1932. clone: function () {
  1933. return new this.constructor( this.x, this.y, this.z, this.w );
  1934. },
  1935. copy: function ( v ) {
  1936. this.x = v.x;
  1937. this.y = v.y;
  1938. this.z = v.z;
  1939. this.w = ( v.w !== undefined ) ? v.w : 1;
  1940. return this;
  1941. },
  1942. add: function ( v, w ) {
  1943. if ( w !== undefined ) {
  1944. console.warn( 'THREE.Vector4: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  1945. return this.addVectors( v, w );
  1946. }
  1947. this.x += v.x;
  1948. this.y += v.y;
  1949. this.z += v.z;
  1950. this.w += v.w;
  1951. return this;
  1952. },
  1953. addScalar: function ( s ) {
  1954. this.x += s;
  1955. this.y += s;
  1956. this.z += s;
  1957. this.w += s;
  1958. return this;
  1959. },
  1960. addVectors: function ( a, b ) {
  1961. this.x = a.x + b.x;
  1962. this.y = a.y + b.y;
  1963. this.z = a.z + b.z;
  1964. this.w = a.w + b.w;
  1965. return this;
  1966. },
  1967. addScaledVector: function ( v, s ) {
  1968. this.x += v.x * s;
  1969. this.y += v.y * s;
  1970. this.z += v.z * s;
  1971. this.w += v.w * s;
  1972. return this;
  1973. },
  1974. sub: function ( v, w ) {
  1975. if ( w !== undefined ) {
  1976. console.warn( 'THREE.Vector4: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  1977. return this.subVectors( v, w );
  1978. }
  1979. this.x -= v.x;
  1980. this.y -= v.y;
  1981. this.z -= v.z;
  1982. this.w -= v.w;
  1983. return this;
  1984. },
  1985. subScalar: function ( s ) {
  1986. this.x -= s;
  1987. this.y -= s;
  1988. this.z -= s;
  1989. this.w -= s;
  1990. return this;
  1991. },
  1992. subVectors: function ( a, b ) {
  1993. this.x = a.x - b.x;
  1994. this.y = a.y - b.y;
  1995. this.z = a.z - b.z;
  1996. this.w = a.w - b.w;
  1997. return this;
  1998. },
  1999. multiplyScalar: function ( scalar ) {
  2000. this.x *= scalar;
  2001. this.y *= scalar;
  2002. this.z *= scalar;
  2003. this.w *= scalar;
  2004. return this;
  2005. },
  2006. applyMatrix4: function ( m ) {
  2007. var x = this.x, y = this.y, z = this.z, w = this.w;
  2008. var e = m.elements;
  2009. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ] * w;
  2010. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ] * w;
  2011. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ] * w;
  2012. this.w = e[ 3 ] * x + e[ 7 ] * y + e[ 11 ] * z + e[ 15 ] * w;
  2013. return this;
  2014. },
  2015. divideScalar: function ( scalar ) {
  2016. return this.multiplyScalar( 1 / scalar );
  2017. },
  2018. setAxisAngleFromQuaternion: function ( q ) {
  2019. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToAngle/index.htm
  2020. // q is assumed to be normalized
  2021. this.w = 2 * Math.acos( q.w );
  2022. var s = Math.sqrt( 1 - q.w * q.w );
  2023. if ( s < 0.0001 ) {
  2024. this.x = 1;
  2025. this.y = 0;
  2026. this.z = 0;
  2027. } else {
  2028. this.x = q.x / s;
  2029. this.y = q.y / s;
  2030. this.z = q.z / s;
  2031. }
  2032. return this;
  2033. },
  2034. setAxisAngleFromRotationMatrix: function ( m ) {
  2035. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToAngle/index.htm
  2036. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  2037. var angle, x, y, z, // variables for result
  2038. epsilon = 0.01, // margin to allow for rounding errors
  2039. epsilon2 = 0.1, // margin to distinguish between 0 and 180 degrees
  2040. te = m.elements,
  2041. m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ],
  2042. m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ],
  2043. m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ];
  2044. if ( ( Math.abs( m12 - m21 ) < epsilon ) &&
  2045. ( Math.abs( m13 - m31 ) < epsilon ) &&
  2046. ( Math.abs( m23 - m32 ) < epsilon ) ) {
  2047. // singularity found
  2048. // first check for identity matrix which must have +1 for all terms
  2049. // in leading diagonal and zero in other terms
  2050. if ( ( Math.abs( m12 + m21 ) < epsilon2 ) &&
  2051. ( Math.abs( m13 + m31 ) < epsilon2 ) &&
  2052. ( Math.abs( m23 + m32 ) < epsilon2 ) &&
  2053. ( Math.abs( m11 + m22 + m33 - 3 ) < epsilon2 ) ) {
  2054. // this singularity is identity matrix so angle = 0
  2055. this.set( 1, 0, 0, 0 );
  2056. return this; // zero angle, arbitrary axis
  2057. }
  2058. // otherwise this singularity is angle = 180
  2059. angle = Math.PI;
  2060. var xx = ( m11 + 1 ) / 2;
  2061. var yy = ( m22 + 1 ) / 2;
  2062. var zz = ( m33 + 1 ) / 2;
  2063. var xy = ( m12 + m21 ) / 4;
  2064. var xz = ( m13 + m31 ) / 4;
  2065. var yz = ( m23 + m32 ) / 4;
  2066. if ( ( xx > yy ) && ( xx > zz ) ) {
  2067. // m11 is the largest diagonal term
  2068. if ( xx < epsilon ) {
  2069. x = 0;
  2070. y = 0.707106781;
  2071. z = 0.707106781;
  2072. } else {
  2073. x = Math.sqrt( xx );
  2074. y = xy / x;
  2075. z = xz / x;
  2076. }
  2077. } else if ( yy > zz ) {
  2078. // m22 is the largest diagonal term
  2079. if ( yy < epsilon ) {
  2080. x = 0.707106781;
  2081. y = 0;
  2082. z = 0.707106781;
  2083. } else {
  2084. y = Math.sqrt( yy );
  2085. x = xy / y;
  2086. z = yz / y;
  2087. }
  2088. } else {
  2089. // m33 is the largest diagonal term so base result on this
  2090. if ( zz < epsilon ) {
  2091. x = 0.707106781;
  2092. y = 0.707106781;
  2093. z = 0;
  2094. } else {
  2095. z = Math.sqrt( zz );
  2096. x = xz / z;
  2097. y = yz / z;
  2098. }
  2099. }
  2100. this.set( x, y, z, angle );
  2101. return this; // return 180 deg rotation
  2102. }
  2103. // as we have reached here there are no singularities so we can handle normally
  2104. var s = Math.sqrt( ( m32 - m23 ) * ( m32 - m23 ) +
  2105. ( m13 - m31 ) * ( m13 - m31 ) +
  2106. ( m21 - m12 ) * ( m21 - m12 ) ); // used to normalize
  2107. if ( Math.abs( s ) < 0.001 ) s = 1;
  2108. // prevent divide by zero, should not happen if matrix is orthogonal and should be
  2109. // caught by singularity test above, but I've left it in just in case
  2110. this.x = ( m32 - m23 ) / s;
  2111. this.y = ( m13 - m31 ) / s;
  2112. this.z = ( m21 - m12 ) / s;
  2113. this.w = Math.acos( ( m11 + m22 + m33 - 1 ) / 2 );
  2114. return this;
  2115. },
  2116. min: function ( v ) {
  2117. this.x = Math.min( this.x, v.x );
  2118. this.y = Math.min( this.y, v.y );
  2119. this.z = Math.min( this.z, v.z );
  2120. this.w = Math.min( this.w, v.w );
  2121. return this;
  2122. },
  2123. max: function ( v ) {
  2124. this.x = Math.max( this.x, v.x );
  2125. this.y = Math.max( this.y, v.y );
  2126. this.z = Math.max( this.z, v.z );
  2127. this.w = Math.max( this.w, v.w );
  2128. return this;
  2129. },
  2130. clamp: function ( min, max ) {
  2131. // assumes min < max, componentwise
  2132. this.x = Math.max( min.x, Math.min( max.x, this.x ) );
  2133. this.y = Math.max( min.y, Math.min( max.y, this.y ) );
  2134. this.z = Math.max( min.z, Math.min( max.z, this.z ) );
  2135. this.w = Math.max( min.w, Math.min( max.w, this.w ) );
  2136. return this;
  2137. },
  2138. clampScalar: function () {
  2139. var min, max;
  2140. return function clampScalar( minVal, maxVal ) {
  2141. if ( min === undefined ) {
  2142. min = new Vector4();
  2143. max = new Vector4();
  2144. }
  2145. min.set( minVal, minVal, minVal, minVal );
  2146. max.set( maxVal, maxVal, maxVal, maxVal );
  2147. return this.clamp( min, max );
  2148. };
  2149. }(),
  2150. clampLength: function ( min, max ) {
  2151. var length = this.length();
  2152. return this.divideScalar( length || 1 ).multiplyScalar( Math.max( min, Math.min( max, length ) ) );
  2153. },
  2154. floor: function () {
  2155. this.x = Math.floor( this.x );
  2156. this.y = Math.floor( this.y );
  2157. this.z = Math.floor( this.z );
  2158. this.w = Math.floor( this.w );
  2159. return this;
  2160. },
  2161. ceil: function () {
  2162. this.x = Math.ceil( this.x );
  2163. this.y = Math.ceil( this.y );
  2164. this.z = Math.ceil( this.z );
  2165. this.w = Math.ceil( this.w );
  2166. return this;
  2167. },
  2168. round: function () {
  2169. this.x = Math.round( this.x );
  2170. this.y = Math.round( this.y );
  2171. this.z = Math.round( this.z );
  2172. this.w = Math.round( this.w );
  2173. return this;
  2174. },
  2175. roundToZero: function () {
  2176. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  2177. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  2178. this.z = ( this.z < 0 ) ? Math.ceil( this.z ) : Math.floor( this.z );
  2179. this.w = ( this.w < 0 ) ? Math.ceil( this.w ) : Math.floor( this.w );
  2180. return this;
  2181. },
  2182. negate: function () {
  2183. this.x = - this.x;
  2184. this.y = - this.y;
  2185. this.z = - this.z;
  2186. this.w = - this.w;
  2187. return this;
  2188. },
  2189. dot: function ( v ) {
  2190. return this.x * v.x + this.y * v.y + this.z * v.z + this.w * v.w;
  2191. },
  2192. lengthSq: function () {
  2193. return this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w;
  2194. },
  2195. length: function () {
  2196. return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w );
  2197. },
  2198. manhattanLength: function () {
  2199. return Math.abs( this.x ) + Math.abs( this.y ) + Math.abs( this.z ) + Math.abs( this.w );
  2200. },
  2201. normalize: function () {
  2202. return this.divideScalar( this.length() || 1 );
  2203. },
  2204. setLength: function ( length ) {
  2205. return this.normalize().multiplyScalar( length );
  2206. },
  2207. lerp: function ( v, alpha ) {
  2208. this.x += ( v.x - this.x ) * alpha;
  2209. this.y += ( v.y - this.y ) * alpha;
  2210. this.z += ( v.z - this.z ) * alpha;
  2211. this.w += ( v.w - this.w ) * alpha;
  2212. return this;
  2213. },
  2214. lerpVectors: function ( v1, v2, alpha ) {
  2215. return this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  2216. },
  2217. equals: function ( v ) {
  2218. return ( ( v.x === this.x ) && ( v.y === this.y ) && ( v.z === this.z ) && ( v.w === this.w ) );
  2219. },
  2220. fromArray: function ( array, offset ) {
  2221. if ( offset === undefined ) offset = 0;
  2222. this.x = array[ offset ];
  2223. this.y = array[ offset + 1 ];
  2224. this.z = array[ offset + 2 ];
  2225. this.w = array[ offset + 3 ];
  2226. return this;
  2227. },
  2228. toArray: function ( array, offset ) {
  2229. if ( array === undefined ) array = [];
  2230. if ( offset === undefined ) offset = 0;
  2231. array[ offset ] = this.x;
  2232. array[ offset + 1 ] = this.y;
  2233. array[ offset + 2 ] = this.z;
  2234. array[ offset + 3 ] = this.w;
  2235. return array;
  2236. },
  2237. fromBufferAttribute: function ( attribute, index, offset ) {
  2238. if ( offset !== undefined ) {
  2239. console.warn( 'THREE.Vector4: offset has been removed from .fromBufferAttribute().' );
  2240. }
  2241. this.x = attribute.getX( index );
  2242. this.y = attribute.getY( index );
  2243. this.z = attribute.getZ( index );
  2244. this.w = attribute.getW( index );
  2245. return this;
  2246. }
  2247. } );
  2248. /**
  2249. * @author szimek / https://github.com/szimek/
  2250. * @author alteredq / http://alteredqualia.com/
  2251. * @author Marius Kintel / https://github.com/kintel
  2252. */
  2253. /*
  2254. In options, we can specify:
  2255. * Texture parameters for an auto-generated target texture
  2256. * depthBuffer/stencilBuffer: Booleans to indicate if we should generate these buffers
  2257. */
  2258. function WebGLRenderTarget( width, height, options ) {
  2259. this.width = width;
  2260. this.height = height;
  2261. this.scissor = new Vector4( 0, 0, width, height );
  2262. this.scissorTest = false;
  2263. this.viewport = new Vector4( 0, 0, width, height );
  2264. options = options || {};
  2265. this.texture = new Texture( undefined, undefined, options.wrapS, options.wrapT, options.magFilter, options.minFilter, options.format, options.type, options.anisotropy, options.encoding );
  2266. this.texture.image = {};
  2267. this.texture.image.width = width;
  2268. this.texture.image.height = height;
  2269. this.texture.generateMipmaps = options.generateMipmaps !== undefined ? options.generateMipmaps : false;
  2270. this.texture.minFilter = options.minFilter !== undefined ? options.minFilter : LinearFilter;
  2271. this.depthBuffer = options.depthBuffer !== undefined ? options.depthBuffer : true;
  2272. this.stencilBuffer = options.stencilBuffer !== undefined ? options.stencilBuffer : true;
  2273. this.depthTexture = options.depthTexture !== undefined ? options.depthTexture : null;
  2274. }
  2275. WebGLRenderTarget.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  2276. constructor: WebGLRenderTarget,
  2277. isWebGLRenderTarget: true,
  2278. setSize: function ( width, height ) {
  2279. if ( this.width !== width || this.height !== height ) {
  2280. this.width = width;
  2281. this.height = height;
  2282. this.texture.image.width = width;
  2283. this.texture.image.height = height;
  2284. this.dispose();
  2285. }
  2286. this.viewport.set( 0, 0, width, height );
  2287. this.scissor.set( 0, 0, width, height );
  2288. },
  2289. clone: function () {
  2290. return new this.constructor().copy( this );
  2291. },
  2292. copy: function ( source ) {
  2293. this.width = source.width;
  2294. this.height = source.height;
  2295. this.viewport.copy( source.viewport );
  2296. this.texture = source.texture.clone();
  2297. this.depthBuffer = source.depthBuffer;
  2298. this.stencilBuffer = source.stencilBuffer;
  2299. this.depthTexture = source.depthTexture;
  2300. return this;
  2301. },
  2302. dispose: function () {
  2303. this.dispatchEvent( { type: 'dispose' } );
  2304. }
  2305. } );
  2306. /**
  2307. * @author Mugen87 / https://github.com/Mugen87
  2308. * @author Matt DesLauriers / @mattdesl
  2309. */
  2310. function WebGLMultisampleRenderTarget( width, height, options ) {
  2311. WebGLRenderTarget.call( this, width, height, options );
  2312. this.samples = 4;
  2313. }
  2314. WebGLMultisampleRenderTarget.prototype = Object.assign( Object.create( WebGLRenderTarget.prototype ), {
  2315. constructor: WebGLMultisampleRenderTarget,
  2316. isWebGLMultisampleRenderTarget: true,
  2317. copy: function ( source ) {
  2318. WebGLRenderTarget.prototype.copy.call( this, source );
  2319. this.samples = source.samples;
  2320. return this;
  2321. }
  2322. } );
  2323. /**
  2324. * @author mrdoob / http://mrdoob.com/
  2325. * @author supereggbert / http://www.paulbrunt.co.uk/
  2326. * @author philogb / http://blog.thejit.org/
  2327. * @author jordi_ros / http://plattsoft.com
  2328. * @author D1plo1d / http://github.com/D1plo1d
  2329. * @author alteredq / http://alteredqualia.com/
  2330. * @author mikael emtinger / http://gomo.se/
  2331. * @author timknip / http://www.floorplanner.com/
  2332. * @author bhouston / http://clara.io
  2333. * @author WestLangley / http://github.com/WestLangley
  2334. */
  2335. function Matrix4() {
  2336. this.elements = [
  2337. 1, 0, 0, 0,
  2338. 0, 1, 0, 0,
  2339. 0, 0, 1, 0,
  2340. 0, 0, 0, 1
  2341. ];
  2342. if ( arguments.length > 0 ) {
  2343. console.error( 'THREE.Matrix4: the constructor no longer reads arguments. use .set() instead.' );
  2344. }
  2345. }
  2346. Object.assign( Matrix4.prototype, {
  2347. isMatrix4: true,
  2348. set: function ( n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44 ) {
  2349. var te = this.elements;
  2350. te[ 0 ] = n11; te[ 4 ] = n12; te[ 8 ] = n13; te[ 12 ] = n14;
  2351. te[ 1 ] = n21; te[ 5 ] = n22; te[ 9 ] = n23; te[ 13 ] = n24;
  2352. te[ 2 ] = n31; te[ 6 ] = n32; te[ 10 ] = n33; te[ 14 ] = n34;
  2353. te[ 3 ] = n41; te[ 7 ] = n42; te[ 11 ] = n43; te[ 15 ] = n44;
  2354. return this;
  2355. },
  2356. identity: function () {
  2357. this.set(
  2358. 1, 0, 0, 0,
  2359. 0, 1, 0, 0,
  2360. 0, 0, 1, 0,
  2361. 0, 0, 0, 1
  2362. );
  2363. return this;
  2364. },
  2365. clone: function () {
  2366. return new Matrix4().fromArray( this.elements );
  2367. },
  2368. copy: function ( m ) {
  2369. var te = this.elements;
  2370. var me = m.elements;
  2371. te[ 0 ] = me[ 0 ]; te[ 1 ] = me[ 1 ]; te[ 2 ] = me[ 2 ]; te[ 3 ] = me[ 3 ];
  2372. te[ 4 ] = me[ 4 ]; te[ 5 ] = me[ 5 ]; te[ 6 ] = me[ 6 ]; te[ 7 ] = me[ 7 ];
  2373. te[ 8 ] = me[ 8 ]; te[ 9 ] = me[ 9 ]; te[ 10 ] = me[ 10 ]; te[ 11 ] = me[ 11 ];
  2374. te[ 12 ] = me[ 12 ]; te[ 13 ] = me[ 13 ]; te[ 14 ] = me[ 14 ]; te[ 15 ] = me[ 15 ];
  2375. return this;
  2376. },
  2377. copyPosition: function ( m ) {
  2378. var te = this.elements, me = m.elements;
  2379. te[ 12 ] = me[ 12 ];
  2380. te[ 13 ] = me[ 13 ];
  2381. te[ 14 ] = me[ 14 ];
  2382. return this;
  2383. },
  2384. extractBasis: function ( xAxis, yAxis, zAxis ) {
  2385. xAxis.setFromMatrixColumn( this, 0 );
  2386. yAxis.setFromMatrixColumn( this, 1 );
  2387. zAxis.setFromMatrixColumn( this, 2 );
  2388. return this;
  2389. },
  2390. makeBasis: function ( xAxis, yAxis, zAxis ) {
  2391. this.set(
  2392. xAxis.x, yAxis.x, zAxis.x, 0,
  2393. xAxis.y, yAxis.y, zAxis.y, 0,
  2394. xAxis.z, yAxis.z, zAxis.z, 0,
  2395. 0, 0, 0, 1
  2396. );
  2397. return this;
  2398. },
  2399. extractRotation: function () {
  2400. var v1 = new Vector3();
  2401. return function extractRotation( m ) {
  2402. // this method does not support reflection matrices
  2403. var te = this.elements;
  2404. var me = m.elements;
  2405. var scaleX = 1 / v1.setFromMatrixColumn( m, 0 ).length();
  2406. var scaleY = 1 / v1.setFromMatrixColumn( m, 1 ).length();
  2407. var scaleZ = 1 / v1.setFromMatrixColumn( m, 2 ).length();
  2408. te[ 0 ] = me[ 0 ] * scaleX;
  2409. te[ 1 ] = me[ 1 ] * scaleX;
  2410. te[ 2 ] = me[ 2 ] * scaleX;
  2411. te[ 3 ] = 0;
  2412. te[ 4 ] = me[ 4 ] * scaleY;
  2413. te[ 5 ] = me[ 5 ] * scaleY;
  2414. te[ 6 ] = me[ 6 ] * scaleY;
  2415. te[ 7 ] = 0;
  2416. te[ 8 ] = me[ 8 ] * scaleZ;
  2417. te[ 9 ] = me[ 9 ] * scaleZ;
  2418. te[ 10 ] = me[ 10 ] * scaleZ;
  2419. te[ 11 ] = 0;
  2420. te[ 12 ] = 0;
  2421. te[ 13 ] = 0;
  2422. te[ 14 ] = 0;
  2423. te[ 15 ] = 1;
  2424. return this;
  2425. };
  2426. }(),
  2427. makeRotationFromEuler: function ( euler ) {
  2428. if ( ! ( euler && euler.isEuler ) ) {
  2429. console.error( 'THREE.Matrix4: .makeRotationFromEuler() now expects a Euler rotation rather than a Vector3 and order.' );
  2430. }
  2431. var te = this.elements;
  2432. var x = euler.x, y = euler.y, z = euler.z;
  2433. var a = Math.cos( x ), b = Math.sin( x );
  2434. var c = Math.cos( y ), d = Math.sin( y );
  2435. var e = Math.cos( z ), f = Math.sin( z );
  2436. if ( euler.order === 'XYZ' ) {
  2437. var ae = a * e, af = a * f, be = b * e, bf = b * f;
  2438. te[ 0 ] = c * e;
  2439. te[ 4 ] = - c * f;
  2440. te[ 8 ] = d;
  2441. te[ 1 ] = af + be * d;
  2442. te[ 5 ] = ae - bf * d;
  2443. te[ 9 ] = - b * c;
  2444. te[ 2 ] = bf - ae * d;
  2445. te[ 6 ] = be + af * d;
  2446. te[ 10 ] = a * c;
  2447. } else if ( euler.order === 'YXZ' ) {
  2448. var ce = c * e, cf = c * f, de = d * e, df = d * f;
  2449. te[ 0 ] = ce + df * b;
  2450. te[ 4 ] = de * b - cf;
  2451. te[ 8 ] = a * d;
  2452. te[ 1 ] = a * f;
  2453. te[ 5 ] = a * e;
  2454. te[ 9 ] = - b;
  2455. te[ 2 ] = cf * b - de;
  2456. te[ 6 ] = df + ce * b;
  2457. te[ 10 ] = a * c;
  2458. } else if ( euler.order === 'ZXY' ) {
  2459. var ce = c * e, cf = c * f, de = d * e, df = d * f;
  2460. te[ 0 ] = ce - df * b;
  2461. te[ 4 ] = - a * f;
  2462. te[ 8 ] = de + cf * b;
  2463. te[ 1 ] = cf + de * b;
  2464. te[ 5 ] = a * e;
  2465. te[ 9 ] = df - ce * b;
  2466. te[ 2 ] = - a * d;
  2467. te[ 6 ] = b;
  2468. te[ 10 ] = a * c;
  2469. } else if ( euler.order === 'ZYX' ) {
  2470. var ae = a * e, af = a * f, be = b * e, bf = b * f;
  2471. te[ 0 ] = c * e;
  2472. te[ 4 ] = be * d - af;
  2473. te[ 8 ] = ae * d + bf;
  2474. te[ 1 ] = c * f;
  2475. te[ 5 ] = bf * d + ae;
  2476. te[ 9 ] = af * d - be;
  2477. te[ 2 ] = - d;
  2478. te[ 6 ] = b * c;
  2479. te[ 10 ] = a * c;
  2480. } else if ( euler.order === 'YZX' ) {
  2481. var ac = a * c, ad = a * d, bc = b * c, bd = b * d;
  2482. te[ 0 ] = c * e;
  2483. te[ 4 ] = bd - ac * f;
  2484. te[ 8 ] = bc * f + ad;
  2485. te[ 1 ] = f;
  2486. te[ 5 ] = a * e;
  2487. te[ 9 ] = - b * e;
  2488. te[ 2 ] = - d * e;
  2489. te[ 6 ] = ad * f + bc;
  2490. te[ 10 ] = ac - bd * f;
  2491. } else if ( euler.order === 'XZY' ) {
  2492. var ac = a * c, ad = a * d, bc = b * c, bd = b * d;
  2493. te[ 0 ] = c * e;
  2494. te[ 4 ] = - f;
  2495. te[ 8 ] = d * e;
  2496. te[ 1 ] = ac * f + bd;
  2497. te[ 5 ] = a * e;
  2498. te[ 9 ] = ad * f - bc;
  2499. te[ 2 ] = bc * f - ad;
  2500. te[ 6 ] = b * e;
  2501. te[ 10 ] = bd * f + ac;
  2502. }
  2503. // bottom row
  2504. te[ 3 ] = 0;
  2505. te[ 7 ] = 0;
  2506. te[ 11 ] = 0;
  2507. // last column
  2508. te[ 12 ] = 0;
  2509. te[ 13 ] = 0;
  2510. te[ 14 ] = 0;
  2511. te[ 15 ] = 1;
  2512. return this;
  2513. },
  2514. makeRotationFromQuaternion: function () {
  2515. var zero = new Vector3( 0, 0, 0 );
  2516. var one = new Vector3( 1, 1, 1 );
  2517. return function makeRotationFromQuaternion( q ) {
  2518. return this.compose( zero, q, one );
  2519. };
  2520. }(),
  2521. lookAt: function () {
  2522. var x = new Vector3();
  2523. var y = new Vector3();
  2524. var z = new Vector3();
  2525. return function lookAt( eye, target, up ) {
  2526. var te = this.elements;
  2527. z.subVectors( eye, target );
  2528. if ( z.lengthSq() === 0 ) {
  2529. // eye and target are in the same position
  2530. z.z = 1;
  2531. }
  2532. z.normalize();
  2533. x.crossVectors( up, z );
  2534. if ( x.lengthSq() === 0 ) {
  2535. // up and z are parallel
  2536. if ( Math.abs( up.z ) === 1 ) {
  2537. z.x += 0.0001;
  2538. } else {
  2539. z.z += 0.0001;
  2540. }
  2541. z.normalize();
  2542. x.crossVectors( up, z );
  2543. }
  2544. x.normalize();
  2545. y.crossVectors( z, x );
  2546. te[ 0 ] = x.x; te[ 4 ] = y.x; te[ 8 ] = z.x;
  2547. te[ 1 ] = x.y; te[ 5 ] = y.y; te[ 9 ] = z.y;
  2548. te[ 2 ] = x.z; te[ 6 ] = y.z; te[ 10 ] = z.z;
  2549. return this;
  2550. };
  2551. }(),
  2552. multiply: function ( m, n ) {
  2553. if ( n !== undefined ) {
  2554. console.warn( 'THREE.Matrix4: .multiply() now only accepts one argument. Use .multiplyMatrices( a, b ) instead.' );
  2555. return this.multiplyMatrices( m, n );
  2556. }
  2557. return this.multiplyMatrices( this, m );
  2558. },
  2559. premultiply: function ( m ) {
  2560. return this.multiplyMatrices( m, this );
  2561. },
  2562. multiplyMatrices: function ( a, b ) {
  2563. var ae = a.elements;
  2564. var be = b.elements;
  2565. var te = this.elements;
  2566. var a11 = ae[ 0 ], a12 = ae[ 4 ], a13 = ae[ 8 ], a14 = ae[ 12 ];
  2567. var a21 = ae[ 1 ], a22 = ae[ 5 ], a23 = ae[ 9 ], a24 = ae[ 13 ];
  2568. var a31 = ae[ 2 ], a32 = ae[ 6 ], a33 = ae[ 10 ], a34 = ae[ 14 ];
  2569. var a41 = ae[ 3 ], a42 = ae[ 7 ], a43 = ae[ 11 ], a44 = ae[ 15 ];
  2570. var b11 = be[ 0 ], b12 = be[ 4 ], b13 = be[ 8 ], b14 = be[ 12 ];
  2571. var b21 = be[ 1 ], b22 = be[ 5 ], b23 = be[ 9 ], b24 = be[ 13 ];
  2572. var b31 = be[ 2 ], b32 = be[ 6 ], b33 = be[ 10 ], b34 = be[ 14 ];
  2573. var b41 = be[ 3 ], b42 = be[ 7 ], b43 = be[ 11 ], b44 = be[ 15 ];
  2574. te[ 0 ] = a11 * b11 + a12 * b21 + a13 * b31 + a14 * b41;
  2575. te[ 4 ] = a11 * b12 + a12 * b22 + a13 * b32 + a14 * b42;
  2576. te[ 8 ] = a11 * b13 + a12 * b23 + a13 * b33 + a14 * b43;
  2577. te[ 12 ] = a11 * b14 + a12 * b24 + a13 * b34 + a14 * b44;
  2578. te[ 1 ] = a21 * b11 + a22 * b21 + a23 * b31 + a24 * b41;
  2579. te[ 5 ] = a21 * b12 + a22 * b22 + a23 * b32 + a24 * b42;
  2580. te[ 9 ] = a21 * b13 + a22 * b23 + a23 * b33 + a24 * b43;
  2581. te[ 13 ] = a21 * b14 + a22 * b24 + a23 * b34 + a24 * b44;
  2582. te[ 2 ] = a31 * b11 + a32 * b21 + a33 * b31 + a34 * b41;
  2583. te[ 6 ] = a31 * b12 + a32 * b22 + a33 * b32 + a34 * b42;
  2584. te[ 10 ] = a31 * b13 + a32 * b23 + a33 * b33 + a34 * b43;
  2585. te[ 14 ] = a31 * b14 + a32 * b24 + a33 * b34 + a34 * b44;
  2586. te[ 3 ] = a41 * b11 + a42 * b21 + a43 * b31 + a44 * b41;
  2587. te[ 7 ] = a41 * b12 + a42 * b22 + a43 * b32 + a44 * b42;
  2588. te[ 11 ] = a41 * b13 + a42 * b23 + a43 * b33 + a44 * b43;
  2589. te[ 15 ] = a41 * b14 + a42 * b24 + a43 * b34 + a44 * b44;
  2590. return this;
  2591. },
  2592. multiplyScalar: function ( s ) {
  2593. var te = this.elements;
  2594. te[ 0 ] *= s; te[ 4 ] *= s; te[ 8 ] *= s; te[ 12 ] *= s;
  2595. te[ 1 ] *= s; te[ 5 ] *= s; te[ 9 ] *= s; te[ 13 ] *= s;
  2596. te[ 2 ] *= s; te[ 6 ] *= s; te[ 10 ] *= s; te[ 14 ] *= s;
  2597. te[ 3 ] *= s; te[ 7 ] *= s; te[ 11 ] *= s; te[ 15 ] *= s;
  2598. return this;
  2599. },
  2600. applyToBufferAttribute: function () {
  2601. var v1 = new Vector3();
  2602. return function applyToBufferAttribute( attribute ) {
  2603. for ( var i = 0, l = attribute.count; i < l; i ++ ) {
  2604. v1.x = attribute.getX( i );
  2605. v1.y = attribute.getY( i );
  2606. v1.z = attribute.getZ( i );
  2607. v1.applyMatrix4( this );
  2608. attribute.setXYZ( i, v1.x, v1.y, v1.z );
  2609. }
  2610. return attribute;
  2611. };
  2612. }(),
  2613. determinant: function () {
  2614. var te = this.elements;
  2615. var n11 = te[ 0 ], n12 = te[ 4 ], n13 = te[ 8 ], n14 = te[ 12 ];
  2616. var n21 = te[ 1 ], n22 = te[ 5 ], n23 = te[ 9 ], n24 = te[ 13 ];
  2617. var n31 = te[ 2 ], n32 = te[ 6 ], n33 = te[ 10 ], n34 = te[ 14 ];
  2618. var n41 = te[ 3 ], n42 = te[ 7 ], n43 = te[ 11 ], n44 = te[ 15 ];
  2619. //TODO: make this more efficient
  2620. //( based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm )
  2621. return (
  2622. n41 * (
  2623. + n14 * n23 * n32
  2624. - n13 * n24 * n32
  2625. - n14 * n22 * n33
  2626. + n12 * n24 * n33
  2627. + n13 * n22 * n34
  2628. - n12 * n23 * n34
  2629. ) +
  2630. n42 * (
  2631. + n11 * n23 * n34
  2632. - n11 * n24 * n33
  2633. + n14 * n21 * n33
  2634. - n13 * n21 * n34
  2635. + n13 * n24 * n31
  2636. - n14 * n23 * n31
  2637. ) +
  2638. n43 * (
  2639. + n11 * n24 * n32
  2640. - n11 * n22 * n34
  2641. - n14 * n21 * n32
  2642. + n12 * n21 * n34
  2643. + n14 * n22 * n31
  2644. - n12 * n24 * n31
  2645. ) +
  2646. n44 * (
  2647. - n13 * n22 * n31
  2648. - n11 * n23 * n32
  2649. + n11 * n22 * n33
  2650. + n13 * n21 * n32
  2651. - n12 * n21 * n33
  2652. + n12 * n23 * n31
  2653. )
  2654. );
  2655. },
  2656. transpose: function () {
  2657. var te = this.elements;
  2658. var tmp;
  2659. tmp = te[ 1 ]; te[ 1 ] = te[ 4 ]; te[ 4 ] = tmp;
  2660. tmp = te[ 2 ]; te[ 2 ] = te[ 8 ]; te[ 8 ] = tmp;
  2661. tmp = te[ 6 ]; te[ 6 ] = te[ 9 ]; te[ 9 ] = tmp;
  2662. tmp = te[ 3 ]; te[ 3 ] = te[ 12 ]; te[ 12 ] = tmp;
  2663. tmp = te[ 7 ]; te[ 7 ] = te[ 13 ]; te[ 13 ] = tmp;
  2664. tmp = te[ 11 ]; te[ 11 ] = te[ 14 ]; te[ 14 ] = tmp;
  2665. return this;
  2666. },
  2667. setPosition: function ( x, y, z ) {
  2668. var te = this.elements;
  2669. if ( x.isVector3 ) {
  2670. te[ 12 ] = x.x;
  2671. te[ 13 ] = x.y;
  2672. te[ 14 ] = x.z;
  2673. } else {
  2674. te[ 12 ] = x;
  2675. te[ 13 ] = y;
  2676. te[ 14 ] = z;
  2677. }
  2678. return this;
  2679. },
  2680. getInverse: function ( m, throwOnDegenerate ) {
  2681. // based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm
  2682. var te = this.elements,
  2683. me = m.elements,
  2684. n11 = me[ 0 ], n21 = me[ 1 ], n31 = me[ 2 ], n41 = me[ 3 ],
  2685. n12 = me[ 4 ], n22 = me[ 5 ], n32 = me[ 6 ], n42 = me[ 7 ],
  2686. n13 = me[ 8 ], n23 = me[ 9 ], n33 = me[ 10 ], n43 = me[ 11 ],
  2687. n14 = me[ 12 ], n24 = me[ 13 ], n34 = me[ 14 ], n44 = me[ 15 ],
  2688. t11 = n23 * n34 * n42 - n24 * n33 * n42 + n24 * n32 * n43 - n22 * n34 * n43 - n23 * n32 * n44 + n22 * n33 * n44,
  2689. t12 = n14 * n33 * n42 - n13 * n34 * n42 - n14 * n32 * n43 + n12 * n34 * n43 + n13 * n32 * n44 - n12 * n33 * n44,
  2690. t13 = n13 * n24 * n42 - n14 * n23 * n42 + n14 * n22 * n43 - n12 * n24 * n43 - n13 * n22 * n44 + n12 * n23 * n44,
  2691. t14 = n14 * n23 * n32 - n13 * n24 * n32 - n14 * n22 * n33 + n12 * n24 * n33 + n13 * n22 * n34 - n12 * n23 * n34;
  2692. var det = n11 * t11 + n21 * t12 + n31 * t13 + n41 * t14;
  2693. if ( det === 0 ) {
  2694. var msg = "THREE.Matrix4: .getInverse() can't invert matrix, determinant is 0";
  2695. if ( throwOnDegenerate === true ) {
  2696. throw new Error( msg );
  2697. } else {
  2698. console.warn( msg );
  2699. }
  2700. return this.identity();
  2701. }
  2702. var detInv = 1 / det;
  2703. te[ 0 ] = t11 * detInv;
  2704. te[ 1 ] = ( n24 * n33 * n41 - n23 * n34 * n41 - n24 * n31 * n43 + n21 * n34 * n43 + n23 * n31 * n44 - n21 * n33 * n44 ) * detInv;
  2705. te[ 2 ] = ( n22 * n34 * n41 - n24 * n32 * n41 + n24 * n31 * n42 - n21 * n34 * n42 - n22 * n31 * n44 + n21 * n32 * n44 ) * detInv;
  2706. te[ 3 ] = ( n23 * n32 * n41 - n22 * n33 * n41 - n23 * n31 * n42 + n21 * n33 * n42 + n22 * n31 * n43 - n21 * n32 * n43 ) * detInv;
  2707. te[ 4 ] = t12 * detInv;
  2708. te[ 5 ] = ( n13 * n34 * n41 - n14 * n33 * n41 + n14 * n31 * n43 - n11 * n34 * n43 - n13 * n31 * n44 + n11 * n33 * n44 ) * detInv;
  2709. te[ 6 ] = ( n14 * n32 * n41 - n12 * n34 * n41 - n14 * n31 * n42 + n11 * n34 * n42 + n12 * n31 * n44 - n11 * n32 * n44 ) * detInv;
  2710. te[ 7 ] = ( n12 * n33 * n41 - n13 * n32 * n41 + n13 * n31 * n42 - n11 * n33 * n42 - n12 * n31 * n43 + n11 * n32 * n43 ) * detInv;
  2711. te[ 8 ] = t13 * detInv;
  2712. te[ 9 ] = ( n14 * n23 * n41 - n13 * n24 * n41 - n14 * n21 * n43 + n11 * n24 * n43 + n13 * n21 * n44 - n11 * n23 * n44 ) * detInv;
  2713. te[ 10 ] = ( n12 * n24 * n41 - n14 * n22 * n41 + n14 * n21 * n42 - n11 * n24 * n42 - n12 * n21 * n44 + n11 * n22 * n44 ) * detInv;
  2714. te[ 11 ] = ( n13 * n22 * n41 - n12 * n23 * n41 - n13 * n21 * n42 + n11 * n23 * n42 + n12 * n21 * n43 - n11 * n22 * n43 ) * detInv;
  2715. te[ 12 ] = t14 * detInv;
  2716. te[ 13 ] = ( n13 * n24 * n31 - n14 * n23 * n31 + n14 * n21 * n33 - n11 * n24 * n33 - n13 * n21 * n34 + n11 * n23 * n34 ) * detInv;
  2717. te[ 14 ] = ( n14 * n22 * n31 - n12 * n24 * n31 - n14 * n21 * n32 + n11 * n24 * n32 + n12 * n21 * n34 - n11 * n22 * n34 ) * detInv;
  2718. te[ 15 ] = ( n12 * n23 * n31 - n13 * n22 * n31 + n13 * n21 * n32 - n11 * n23 * n32 - n12 * n21 * n33 + n11 * n22 * n33 ) * detInv;
  2719. return this;
  2720. },
  2721. scale: function ( v ) {
  2722. var te = this.elements;
  2723. var x = v.x, y = v.y, z = v.z;
  2724. te[ 0 ] *= x; te[ 4 ] *= y; te[ 8 ] *= z;
  2725. te[ 1 ] *= x; te[ 5 ] *= y; te[ 9 ] *= z;
  2726. te[ 2 ] *= x; te[ 6 ] *= y; te[ 10 ] *= z;
  2727. te[ 3 ] *= x; te[ 7 ] *= y; te[ 11 ] *= z;
  2728. return this;
  2729. },
  2730. getMaxScaleOnAxis: function () {
  2731. var te = this.elements;
  2732. var scaleXSq = te[ 0 ] * te[ 0 ] + te[ 1 ] * te[ 1 ] + te[ 2 ] * te[ 2 ];
  2733. var scaleYSq = te[ 4 ] * te[ 4 ] + te[ 5 ] * te[ 5 ] + te[ 6 ] * te[ 6 ];
  2734. var scaleZSq = te[ 8 ] * te[ 8 ] + te[ 9 ] * te[ 9 ] + te[ 10 ] * te[ 10 ];
  2735. return Math.sqrt( Math.max( scaleXSq, scaleYSq, scaleZSq ) );
  2736. },
  2737. makeTranslation: function ( x, y, z ) {
  2738. this.set(
  2739. 1, 0, 0, x,
  2740. 0, 1, 0, y,
  2741. 0, 0, 1, z,
  2742. 0, 0, 0, 1
  2743. );
  2744. return this;
  2745. },
  2746. makeRotationX: function ( theta ) {
  2747. var c = Math.cos( theta ), s = Math.sin( theta );
  2748. this.set(
  2749. 1, 0, 0, 0,
  2750. 0, c, - s, 0,
  2751. 0, s, c, 0,
  2752. 0, 0, 0, 1
  2753. );
  2754. return this;
  2755. },
  2756. makeRotationY: function ( theta ) {
  2757. var c = Math.cos( theta ), s = Math.sin( theta );
  2758. this.set(
  2759. c, 0, s, 0,
  2760. 0, 1, 0, 0,
  2761. - s, 0, c, 0,
  2762. 0, 0, 0, 1
  2763. );
  2764. return this;
  2765. },
  2766. makeRotationZ: function ( theta ) {
  2767. var c = Math.cos( theta ), s = Math.sin( theta );
  2768. this.set(
  2769. c, - s, 0, 0,
  2770. s, c, 0, 0,
  2771. 0, 0, 1, 0,
  2772. 0, 0, 0, 1
  2773. );
  2774. return this;
  2775. },
  2776. makeRotationAxis: function ( axis, angle ) {
  2777. // Based on http://www.gamedev.net/reference/articles/article1199.asp
  2778. var c = Math.cos( angle );
  2779. var s = Math.sin( angle );
  2780. var t = 1 - c;
  2781. var x = axis.x, y = axis.y, z = axis.z;
  2782. var tx = t * x, ty = t * y;
  2783. this.set(
  2784. tx * x + c, tx * y - s * z, tx * z + s * y, 0,
  2785. tx * y + s * z, ty * y + c, ty * z - s * x, 0,
  2786. tx * z - s * y, ty * z + s * x, t * z * z + c, 0,
  2787. 0, 0, 0, 1
  2788. );
  2789. return this;
  2790. },
  2791. makeScale: function ( x, y, z ) {
  2792. this.set(
  2793. x, 0, 0, 0,
  2794. 0, y, 0, 0,
  2795. 0, 0, z, 0,
  2796. 0, 0, 0, 1
  2797. );
  2798. return this;
  2799. },
  2800. makeShear: function ( x, y, z ) {
  2801. this.set(
  2802. 1, y, z, 0,
  2803. x, 1, z, 0,
  2804. x, y, 1, 0,
  2805. 0, 0, 0, 1
  2806. );
  2807. return this;
  2808. },
  2809. compose: function ( position, quaternion, scale ) {
  2810. var te = this.elements;
  2811. var x = quaternion._x, y = quaternion._y, z = quaternion._z, w = quaternion._w;
  2812. var x2 = x + x, y2 = y + y, z2 = z + z;
  2813. var xx = x * x2, xy = x * y2, xz = x * z2;
  2814. var yy = y * y2, yz = y * z2, zz = z * z2;
  2815. var wx = w * x2, wy = w * y2, wz = w * z2;
  2816. var sx = scale.x, sy = scale.y, sz = scale.z;
  2817. te[ 0 ] = ( 1 - ( yy + zz ) ) * sx;
  2818. te[ 1 ] = ( xy + wz ) * sx;
  2819. te[ 2 ] = ( xz - wy ) * sx;
  2820. te[ 3 ] = 0;
  2821. te[ 4 ] = ( xy - wz ) * sy;
  2822. te[ 5 ] = ( 1 - ( xx + zz ) ) * sy;
  2823. te[ 6 ] = ( yz + wx ) * sy;
  2824. te[ 7 ] = 0;
  2825. te[ 8 ] = ( xz + wy ) * sz;
  2826. te[ 9 ] = ( yz - wx ) * sz;
  2827. te[ 10 ] = ( 1 - ( xx + yy ) ) * sz;
  2828. te[ 11 ] = 0;
  2829. te[ 12 ] = position.x;
  2830. te[ 13 ] = position.y;
  2831. te[ 14 ] = position.z;
  2832. te[ 15 ] = 1;
  2833. return this;
  2834. },
  2835. decompose: function () {
  2836. var vector = new Vector3();
  2837. var matrix = new Matrix4();
  2838. return function decompose( position, quaternion, scale ) {
  2839. var te = this.elements;
  2840. var sx = vector.set( te[ 0 ], te[ 1 ], te[ 2 ] ).length();
  2841. var sy = vector.set( te[ 4 ], te[ 5 ], te[ 6 ] ).length();
  2842. var sz = vector.set( te[ 8 ], te[ 9 ], te[ 10 ] ).length();
  2843. // if determine is negative, we need to invert one scale
  2844. var det = this.determinant();
  2845. if ( det < 0 ) sx = - sx;
  2846. position.x = te[ 12 ];
  2847. position.y = te[ 13 ];
  2848. position.z = te[ 14 ];
  2849. // scale the rotation part
  2850. matrix.copy( this );
  2851. var invSX = 1 / sx;
  2852. var invSY = 1 / sy;
  2853. var invSZ = 1 / sz;
  2854. matrix.elements[ 0 ] *= invSX;
  2855. matrix.elements[ 1 ] *= invSX;
  2856. matrix.elements[ 2 ] *= invSX;
  2857. matrix.elements[ 4 ] *= invSY;
  2858. matrix.elements[ 5 ] *= invSY;
  2859. matrix.elements[ 6 ] *= invSY;
  2860. matrix.elements[ 8 ] *= invSZ;
  2861. matrix.elements[ 9 ] *= invSZ;
  2862. matrix.elements[ 10 ] *= invSZ;
  2863. quaternion.setFromRotationMatrix( matrix );
  2864. scale.x = sx;
  2865. scale.y = sy;
  2866. scale.z = sz;
  2867. return this;
  2868. };
  2869. }(),
  2870. makePerspective: function ( left, right, top, bottom, near, far ) {
  2871. if ( far === undefined ) {
  2872. console.warn( 'THREE.Matrix4: .makePerspective() has been redefined and has a new signature. Please check the docs.' );
  2873. }
  2874. var te = this.elements;
  2875. var x = 2 * near / ( right - left );
  2876. var y = 2 * near / ( top - bottom );
  2877. var a = ( right + left ) / ( right - left );
  2878. var b = ( top + bottom ) / ( top - bottom );
  2879. var c = - ( far + near ) / ( far - near );
  2880. var d = - 2 * far * near / ( far - near );
  2881. te[ 0 ] = x; te[ 4 ] = 0; te[ 8 ] = a; te[ 12 ] = 0;
  2882. te[ 1 ] = 0; te[ 5 ] = y; te[ 9 ] = b; te[ 13 ] = 0;
  2883. te[ 2 ] = 0; te[ 6 ] = 0; te[ 10 ] = c; te[ 14 ] = d;
  2884. te[ 3 ] = 0; te[ 7 ] = 0; te[ 11 ] = - 1; te[ 15 ] = 0;
  2885. return this;
  2886. },
  2887. makeOrthographic: function ( left, right, top, bottom, near, far ) {
  2888. var te = this.elements;
  2889. var w = 1.0 / ( right - left );
  2890. var h = 1.0 / ( top - bottom );
  2891. var p = 1.0 / ( far - near );
  2892. var x = ( right + left ) * w;
  2893. var y = ( top + bottom ) * h;
  2894. var z = ( far + near ) * p;
  2895. te[ 0 ] = 2 * w; te[ 4 ] = 0; te[ 8 ] = 0; te[ 12 ] = - x;
  2896. te[ 1 ] = 0; te[ 5 ] = 2 * h; te[ 9 ] = 0; te[ 13 ] = - y;
  2897. te[ 2 ] = 0; te[ 6 ] = 0; te[ 10 ] = - 2 * p; te[ 14 ] = - z;
  2898. te[ 3 ] = 0; te[ 7 ] = 0; te[ 11 ] = 0; te[ 15 ] = 1;
  2899. return this;
  2900. },
  2901. equals: function ( matrix ) {
  2902. var te = this.elements;
  2903. var me = matrix.elements;
  2904. for ( var i = 0; i < 16; i ++ ) {
  2905. if ( te[ i ] !== me[ i ] ) return false;
  2906. }
  2907. return true;
  2908. },
  2909. fromArray: function ( array, offset ) {
  2910. if ( offset === undefined ) offset = 0;
  2911. for ( var i = 0; i < 16; i ++ ) {
  2912. this.elements[ i ] = array[ i + offset ];
  2913. }
  2914. return this;
  2915. },
  2916. toArray: function ( array, offset ) {
  2917. if ( array === undefined ) array = [];
  2918. if ( offset === undefined ) offset = 0;
  2919. var te = this.elements;
  2920. array[ offset ] = te[ 0 ];
  2921. array[ offset + 1 ] = te[ 1 ];
  2922. array[ offset + 2 ] = te[ 2 ];
  2923. array[ offset + 3 ] = te[ 3 ];
  2924. array[ offset + 4 ] = te[ 4 ];
  2925. array[ offset + 5 ] = te[ 5 ];
  2926. array[ offset + 6 ] = te[ 6 ];
  2927. array[ offset + 7 ] = te[ 7 ];
  2928. array[ offset + 8 ] = te[ 8 ];
  2929. array[ offset + 9 ] = te[ 9 ];
  2930. array[ offset + 10 ] = te[ 10 ];
  2931. array[ offset + 11 ] = te[ 11 ];
  2932. array[ offset + 12 ] = te[ 12 ];
  2933. array[ offset + 13 ] = te[ 13 ];
  2934. array[ offset + 14 ] = te[ 14 ];
  2935. array[ offset + 15 ] = te[ 15 ];
  2936. return array;
  2937. }
  2938. } );
  2939. /**
  2940. * @author mrdoob / http://mrdoob.com/
  2941. * @author WestLangley / http://github.com/WestLangley
  2942. * @author bhouston / http://clara.io
  2943. */
  2944. function Euler( x, y, z, order ) {
  2945. this._x = x || 0;
  2946. this._y = y || 0;
  2947. this._z = z || 0;
  2948. this._order = order || Euler.DefaultOrder;
  2949. }
  2950. Euler.RotationOrders = [ 'XYZ', 'YZX', 'ZXY', 'XZY', 'YXZ', 'ZYX' ];
  2951. Euler.DefaultOrder = 'XYZ';
  2952. Object.defineProperties( Euler.prototype, {
  2953. x: {
  2954. get: function () {
  2955. return this._x;
  2956. },
  2957. set: function ( value ) {
  2958. this._x = value;
  2959. this._onChangeCallback();
  2960. }
  2961. },
  2962. y: {
  2963. get: function () {
  2964. return this._y;
  2965. },
  2966. set: function ( value ) {
  2967. this._y = value;
  2968. this._onChangeCallback();
  2969. }
  2970. },
  2971. z: {
  2972. get: function () {
  2973. return this._z;
  2974. },
  2975. set: function ( value ) {
  2976. this._z = value;
  2977. this._onChangeCallback();
  2978. }
  2979. },
  2980. order: {
  2981. get: function () {
  2982. return this._order;
  2983. },
  2984. set: function ( value ) {
  2985. this._order = value;
  2986. this._onChangeCallback();
  2987. }
  2988. }
  2989. } );
  2990. Object.assign( Euler.prototype, {
  2991. isEuler: true,
  2992. set: function ( x, y, z, order ) {
  2993. this._x = x;
  2994. this._y = y;
  2995. this._z = z;
  2996. this._order = order || this._order;
  2997. this._onChangeCallback();
  2998. return this;
  2999. },
  3000. clone: function () {
  3001. return new this.constructor( this._x, this._y, this._z, this._order );
  3002. },
  3003. copy: function ( euler ) {
  3004. this._x = euler._x;
  3005. this._y = euler._y;
  3006. this._z = euler._z;
  3007. this._order = euler._order;
  3008. this._onChangeCallback();
  3009. return this;
  3010. },
  3011. setFromRotationMatrix: function ( m, order, update ) {
  3012. var clamp = _Math.clamp;
  3013. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  3014. var te = m.elements;
  3015. var m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ];
  3016. var m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ];
  3017. var m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ];
  3018. order = order || this._order;
  3019. if ( order === 'XYZ' ) {
  3020. this._y = Math.asin( clamp( m13, - 1, 1 ) );
  3021. if ( Math.abs( m13 ) < 0.99999 ) {
  3022. this._x = Math.atan2( - m23, m33 );
  3023. this._z = Math.atan2( - m12, m11 );
  3024. } else {
  3025. this._x = Math.atan2( m32, m22 );
  3026. this._z = 0;
  3027. }
  3028. } else if ( order === 'YXZ' ) {
  3029. this._x = Math.asin( - clamp( m23, - 1, 1 ) );
  3030. if ( Math.abs( m23 ) < 0.99999 ) {
  3031. this._y = Math.atan2( m13, m33 );
  3032. this._z = Math.atan2( m21, m22 );
  3033. } else {
  3034. this._y = Math.atan2( - m31, m11 );
  3035. this._z = 0;
  3036. }
  3037. } else if ( order === 'ZXY' ) {
  3038. this._x = Math.asin( clamp( m32, - 1, 1 ) );
  3039. if ( Math.abs( m32 ) < 0.99999 ) {
  3040. this._y = Math.atan2( - m31, m33 );
  3041. this._z = Math.atan2( - m12, m22 );
  3042. } else {
  3043. this._y = 0;
  3044. this._z = Math.atan2( m21, m11 );
  3045. }
  3046. } else if ( order === 'ZYX' ) {
  3047. this._y = Math.asin( - clamp( m31, - 1, 1 ) );
  3048. if ( Math.abs( m31 ) < 0.99999 ) {
  3049. this._x = Math.atan2( m32, m33 );
  3050. this._z = Math.atan2( m21, m11 );
  3051. } else {
  3052. this._x = 0;
  3053. this._z = Math.atan2( - m12, m22 );
  3054. }
  3055. } else if ( order === 'YZX' ) {
  3056. this._z = Math.asin( clamp( m21, - 1, 1 ) );
  3057. if ( Math.abs( m21 ) < 0.99999 ) {
  3058. this._x = Math.atan2( - m23, m22 );
  3059. this._y = Math.atan2( - m31, m11 );
  3060. } else {
  3061. this._x = 0;
  3062. this._y = Math.atan2( m13, m33 );
  3063. }
  3064. } else if ( order === 'XZY' ) {
  3065. this._z = Math.asin( - clamp( m12, - 1, 1 ) );
  3066. if ( Math.abs( m12 ) < 0.99999 ) {
  3067. this._x = Math.atan2( m32, m22 );
  3068. this._y = Math.atan2( m13, m11 );
  3069. } else {
  3070. this._x = Math.atan2( - m23, m33 );
  3071. this._y = 0;
  3072. }
  3073. } else {
  3074. console.warn( 'THREE.Euler: .setFromRotationMatrix() given unsupported order: ' + order );
  3075. }
  3076. this._order = order;
  3077. if ( update !== false ) this._onChangeCallback();
  3078. return this;
  3079. },
  3080. setFromQuaternion: function () {
  3081. var matrix = new Matrix4();
  3082. return function setFromQuaternion( q, order, update ) {
  3083. matrix.makeRotationFromQuaternion( q );
  3084. return this.setFromRotationMatrix( matrix, order, update );
  3085. };
  3086. }(),
  3087. setFromVector3: function ( v, order ) {
  3088. return this.set( v.x, v.y, v.z, order || this._order );
  3089. },
  3090. reorder: function () {
  3091. // WARNING: this discards revolution information -bhouston
  3092. var q = new Quaternion();
  3093. return function reorder( newOrder ) {
  3094. q.setFromEuler( this );
  3095. return this.setFromQuaternion( q, newOrder );
  3096. };
  3097. }(),
  3098. equals: function ( euler ) {
  3099. return ( euler._x === this._x ) && ( euler._y === this._y ) && ( euler._z === this._z ) && ( euler._order === this._order );
  3100. },
  3101. fromArray: function ( array ) {
  3102. this._x = array[ 0 ];
  3103. this._y = array[ 1 ];
  3104. this._z = array[ 2 ];
  3105. if ( array[ 3 ] !== undefined ) this._order = array[ 3 ];
  3106. this._onChangeCallback();
  3107. return this;
  3108. },
  3109. toArray: function ( array, offset ) {
  3110. if ( array === undefined ) array = [];
  3111. if ( offset === undefined ) offset = 0;
  3112. array[ offset ] = this._x;
  3113. array[ offset + 1 ] = this._y;
  3114. array[ offset + 2 ] = this._z;
  3115. array[ offset + 3 ] = this._order;
  3116. return array;
  3117. },
  3118. toVector3: function ( optionalResult ) {
  3119. if ( optionalResult ) {
  3120. return optionalResult.set( this._x, this._y, this._z );
  3121. } else {
  3122. return new Vector3( this._x, this._y, this._z );
  3123. }
  3124. },
  3125. _onChange: function ( callback ) {
  3126. this._onChangeCallback = callback;
  3127. return this;
  3128. },
  3129. _onChangeCallback: function () {}
  3130. } );
  3131. /**
  3132. * @author mrdoob / http://mrdoob.com/
  3133. */
  3134. function Layers() {
  3135. this.mask = 1 | 0;
  3136. }
  3137. Object.assign( Layers.prototype, {
  3138. set: function ( channel ) {
  3139. this.mask = 1 << channel | 0;
  3140. },
  3141. enable: function ( channel ) {
  3142. this.mask |= 1 << channel | 0;
  3143. },
  3144. toggle: function ( channel ) {
  3145. this.mask ^= 1 << channel | 0;
  3146. },
  3147. disable: function ( channel ) {
  3148. this.mask &= ~ ( 1 << channel | 0 );
  3149. },
  3150. test: function ( layers ) {
  3151. return ( this.mask & layers.mask ) !== 0;
  3152. }
  3153. } );
  3154. /**
  3155. * @author mrdoob / http://mrdoob.com/
  3156. * @author mikael emtinger / http://gomo.se/
  3157. * @author alteredq / http://alteredqualia.com/
  3158. * @author WestLangley / http://github.com/WestLangley
  3159. * @author elephantatwork / www.elephantatwork.ch
  3160. */
  3161. var object3DId = 0;
  3162. function Object3D() {
  3163. Object.defineProperty( this, 'id', { value: object3DId ++ } );
  3164. this.uuid = _Math.generateUUID();
  3165. this.name = '';
  3166. this.type = 'Object3D';
  3167. this.parent = null;
  3168. this.children = [];
  3169. this.up = Object3D.DefaultUp.clone();
  3170. var position = new Vector3();
  3171. var rotation = new Euler();
  3172. var quaternion = new Quaternion();
  3173. var scale = new Vector3( 1, 1, 1 );
  3174. function onRotationChange() {
  3175. quaternion.setFromEuler( rotation, false );
  3176. }
  3177. function onQuaternionChange() {
  3178. rotation.setFromQuaternion( quaternion, undefined, false );
  3179. }
  3180. rotation._onChange( onRotationChange );
  3181. quaternion._onChange( onQuaternionChange );
  3182. Object.defineProperties( this, {
  3183. position: {
  3184. configurable: true,
  3185. enumerable: true,
  3186. value: position
  3187. },
  3188. rotation: {
  3189. configurable: true,
  3190. enumerable: true,
  3191. value: rotation
  3192. },
  3193. quaternion: {
  3194. configurable: true,
  3195. enumerable: true,
  3196. value: quaternion
  3197. },
  3198. scale: {
  3199. configurable: true,
  3200. enumerable: true,
  3201. value: scale
  3202. },
  3203. modelViewMatrix: {
  3204. value: new Matrix4()
  3205. },
  3206. normalMatrix: {
  3207. value: new Matrix3()
  3208. }
  3209. } );
  3210. this.matrix = new Matrix4();
  3211. this.matrixWorld = new Matrix4();
  3212. this.matrixAutoUpdate = Object3D.DefaultMatrixAutoUpdate;
  3213. this.matrixWorldNeedsUpdate = false;
  3214. this.layers = new Layers();
  3215. this.visible = true;
  3216. this.castShadow = false;
  3217. this.receiveShadow = false;
  3218. this.frustumCulled = true;
  3219. this.renderOrder = 0;
  3220. this.userData = {};
  3221. }
  3222. Object3D.DefaultUp = new Vector3( 0, 1, 0 );
  3223. Object3D.DefaultMatrixAutoUpdate = true;
  3224. Object3D.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  3225. constructor: Object3D,
  3226. isObject3D: true,
  3227. onBeforeRender: function () {},
  3228. onAfterRender: function () {},
  3229. applyMatrix: function ( matrix ) {
  3230. if ( this.matrixAutoUpdate ) this.updateMatrix();
  3231. this.matrix.premultiply( matrix );
  3232. this.matrix.decompose( this.position, this.quaternion, this.scale );
  3233. },
  3234. applyQuaternion: function ( q ) {
  3235. this.quaternion.premultiply( q );
  3236. return this;
  3237. },
  3238. setRotationFromAxisAngle: function ( axis, angle ) {
  3239. // assumes axis is normalized
  3240. this.quaternion.setFromAxisAngle( axis, angle );
  3241. },
  3242. setRotationFromEuler: function ( euler ) {
  3243. this.quaternion.setFromEuler( euler, true );
  3244. },
  3245. setRotationFromMatrix: function ( m ) {
  3246. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  3247. this.quaternion.setFromRotationMatrix( m );
  3248. },
  3249. setRotationFromQuaternion: function ( q ) {
  3250. // assumes q is normalized
  3251. this.quaternion.copy( q );
  3252. },
  3253. rotateOnAxis: function () {
  3254. // rotate object on axis in object space
  3255. // axis is assumed to be normalized
  3256. var q1 = new Quaternion();
  3257. return function rotateOnAxis( axis, angle ) {
  3258. q1.setFromAxisAngle( axis, angle );
  3259. this.quaternion.multiply( q1 );
  3260. return this;
  3261. };
  3262. }(),
  3263. rotateOnWorldAxis: function () {
  3264. // rotate object on axis in world space
  3265. // axis is assumed to be normalized
  3266. // method assumes no rotated parent
  3267. var q1 = new Quaternion();
  3268. return function rotateOnWorldAxis( axis, angle ) {
  3269. q1.setFromAxisAngle( axis, angle );
  3270. this.quaternion.premultiply( q1 );
  3271. return this;
  3272. };
  3273. }(),
  3274. rotateX: function () {
  3275. var v1 = new Vector3( 1, 0, 0 );
  3276. return function rotateX( angle ) {
  3277. return this.rotateOnAxis( v1, angle );
  3278. };
  3279. }(),
  3280. rotateY: function () {
  3281. var v1 = new Vector3( 0, 1, 0 );
  3282. return function rotateY( angle ) {
  3283. return this.rotateOnAxis( v1, angle );
  3284. };
  3285. }(),
  3286. rotateZ: function () {
  3287. var v1 = new Vector3( 0, 0, 1 );
  3288. return function rotateZ( angle ) {
  3289. return this.rotateOnAxis( v1, angle );
  3290. };
  3291. }(),
  3292. translateOnAxis: function () {
  3293. // translate object by distance along axis in object space
  3294. // axis is assumed to be normalized
  3295. var v1 = new Vector3();
  3296. return function translateOnAxis( axis, distance ) {
  3297. v1.copy( axis ).applyQuaternion( this.quaternion );
  3298. this.position.add( v1.multiplyScalar( distance ) );
  3299. return this;
  3300. };
  3301. }(),
  3302. translateX: function () {
  3303. var v1 = new Vector3( 1, 0, 0 );
  3304. return function translateX( distance ) {
  3305. return this.translateOnAxis( v1, distance );
  3306. };
  3307. }(),
  3308. translateY: function () {
  3309. var v1 = new Vector3( 0, 1, 0 );
  3310. return function translateY( distance ) {
  3311. return this.translateOnAxis( v1, distance );
  3312. };
  3313. }(),
  3314. translateZ: function () {
  3315. var v1 = new Vector3( 0, 0, 1 );
  3316. return function translateZ( distance ) {
  3317. return this.translateOnAxis( v1, distance );
  3318. };
  3319. }(),
  3320. localToWorld: function ( vector ) {
  3321. return vector.applyMatrix4( this.matrixWorld );
  3322. },
  3323. worldToLocal: function () {
  3324. var m1 = new Matrix4();
  3325. return function worldToLocal( vector ) {
  3326. return vector.applyMatrix4( m1.getInverse( this.matrixWorld ) );
  3327. };
  3328. }(),
  3329. lookAt: function () {
  3330. // This method does not support objects having non-uniformly-scaled parent(s)
  3331. var q1 = new Quaternion();
  3332. var m1 = new Matrix4();
  3333. var target = new Vector3();
  3334. var position = new Vector3();
  3335. return function lookAt( x, y, z ) {
  3336. if ( x.isVector3 ) {
  3337. target.copy( x );
  3338. } else {
  3339. target.set( x, y, z );
  3340. }
  3341. var parent = this.parent;
  3342. this.updateWorldMatrix( true, false );
  3343. position.setFromMatrixPosition( this.matrixWorld );
  3344. if ( this.isCamera || this.isLight ) {
  3345. m1.lookAt( position, target, this.up );
  3346. } else {
  3347. m1.lookAt( target, position, this.up );
  3348. }
  3349. this.quaternion.setFromRotationMatrix( m1 );
  3350. if ( parent ) {
  3351. m1.extractRotation( parent.matrixWorld );
  3352. q1.setFromRotationMatrix( m1 );
  3353. this.quaternion.premultiply( q1.inverse() );
  3354. }
  3355. };
  3356. }(),
  3357. add: function ( object ) {
  3358. if ( arguments.length > 1 ) {
  3359. for ( var i = 0; i < arguments.length; i ++ ) {
  3360. this.add( arguments[ i ] );
  3361. }
  3362. return this;
  3363. }
  3364. if ( object === this ) {
  3365. console.error( "THREE.Object3D.add: object can't be added as a child of itself.", object );
  3366. return this;
  3367. }
  3368. if ( ( object && object.isObject3D ) ) {
  3369. if ( object.parent !== null ) {
  3370. object.parent.remove( object );
  3371. }
  3372. object.parent = this;
  3373. this.children.push( object );
  3374. object.dispatchEvent( { type: 'added' } );
  3375. } else {
  3376. console.error( "THREE.Object3D.add: object not an instance of THREE.Object3D.", object );
  3377. }
  3378. return this;
  3379. },
  3380. remove: function ( object ) {
  3381. if ( arguments.length > 1 ) {
  3382. for ( var i = 0; i < arguments.length; i ++ ) {
  3383. this.remove( arguments[ i ] );
  3384. }
  3385. return this;
  3386. }
  3387. var index = this.children.indexOf( object );
  3388. if ( index !== - 1 ) {
  3389. object.parent = null;
  3390. this.children.splice( index, 1 );
  3391. object.dispatchEvent( { type: 'removed' } );
  3392. }
  3393. return this;
  3394. },
  3395. attach: function () {
  3396. // adds object as a child of this, while maintaining the object's world transform
  3397. var m = new Matrix4();
  3398. return function attach( object ) {
  3399. this.updateWorldMatrix( true, false );
  3400. m.getInverse( this.matrixWorld );
  3401. if ( object.parent !== null ) {
  3402. object.parent.updateWorldMatrix( true, false );
  3403. m.multiply( object.parent.matrixWorld );
  3404. }
  3405. object.applyMatrix( m );
  3406. object.updateWorldMatrix( false, false );
  3407. this.add( object );
  3408. return this;
  3409. };
  3410. }(),
  3411. getObjectById: function ( id ) {
  3412. return this.getObjectByProperty( 'id', id );
  3413. },
  3414. getObjectByName: function ( name ) {
  3415. return this.getObjectByProperty( 'name', name );
  3416. },
  3417. getObjectByProperty: function ( name, value ) {
  3418. if ( this[ name ] === value ) return this;
  3419. for ( var i = 0, l = this.children.length; i < l; i ++ ) {
  3420. var child = this.children[ i ];
  3421. var object = child.getObjectByProperty( name, value );
  3422. if ( object !== undefined ) {
  3423. return object;
  3424. }
  3425. }
  3426. return undefined;
  3427. },
  3428. getWorldPosition: function ( target ) {
  3429. if ( target === undefined ) {
  3430. console.warn( 'THREE.Object3D: .getWorldPosition() target is now required' );
  3431. target = new Vector3();
  3432. }
  3433. this.updateMatrixWorld( true );
  3434. return target.setFromMatrixPosition( this.matrixWorld );
  3435. },
  3436. getWorldQuaternion: function () {
  3437. var position = new Vector3();
  3438. var scale = new Vector3();
  3439. return function getWorldQuaternion( target ) {
  3440. if ( target === undefined ) {
  3441. console.warn( 'THREE.Object3D: .getWorldQuaternion() target is now required' );
  3442. target = new Quaternion();
  3443. }
  3444. this.updateMatrixWorld( true );
  3445. this.matrixWorld.decompose( position, target, scale );
  3446. return target;
  3447. };
  3448. }(),
  3449. getWorldScale: function () {
  3450. var position = new Vector3();
  3451. var quaternion = new Quaternion();
  3452. return function getWorldScale( target ) {
  3453. if ( target === undefined ) {
  3454. console.warn( 'THREE.Object3D: .getWorldScale() target is now required' );
  3455. target = new Vector3();
  3456. }
  3457. this.updateMatrixWorld( true );
  3458. this.matrixWorld.decompose( position, quaternion, target );
  3459. return target;
  3460. };
  3461. }(),
  3462. getWorldDirection: function ( target ) {
  3463. if ( target === undefined ) {
  3464. console.warn( 'THREE.Object3D: .getWorldDirection() target is now required' );
  3465. target = new Vector3();
  3466. }
  3467. this.updateMatrixWorld( true );
  3468. var e = this.matrixWorld.elements;
  3469. return target.set( e[ 8 ], e[ 9 ], e[ 10 ] ).normalize();
  3470. },
  3471. raycast: function () {},
  3472. traverse: function ( callback ) {
  3473. callback( this );
  3474. var children = this.children;
  3475. for ( var i = 0, l = children.length; i < l; i ++ ) {
  3476. children[ i ].traverse( callback );
  3477. }
  3478. },
  3479. traverseVisible: function ( callback ) {
  3480. if ( this.visible === false ) return;
  3481. callback( this );
  3482. var children = this.children;
  3483. for ( var i = 0, l = children.length; i < l; i ++ ) {
  3484. children[ i ].traverseVisible( callback );
  3485. }
  3486. },
  3487. traverseAncestors: function ( callback ) {
  3488. var parent = this.parent;
  3489. if ( parent !== null ) {
  3490. callback( parent );
  3491. parent.traverseAncestors( callback );
  3492. }
  3493. },
  3494. updateMatrix: function () {
  3495. this.matrix.compose( this.position, this.quaternion, this.scale );
  3496. this.matrixWorldNeedsUpdate = true;
  3497. },
  3498. updateMatrixWorld: function ( force ) {
  3499. if ( this.matrixAutoUpdate ) this.updateMatrix();
  3500. if ( this.matrixWorldNeedsUpdate || force ) {
  3501. if ( this.parent === null ) {
  3502. this.matrixWorld.copy( this.matrix );
  3503. } else {
  3504. this.matrixWorld.multiplyMatrices( this.parent.matrixWorld, this.matrix );
  3505. }
  3506. this.matrixWorldNeedsUpdate = false;
  3507. force = true;
  3508. }
  3509. // update children
  3510. var children = this.children;
  3511. for ( var i = 0, l = children.length; i < l; i ++ ) {
  3512. children[ i ].updateMatrixWorld( force );
  3513. }
  3514. },
  3515. updateWorldMatrix: function ( updateParents, updateChildren ) {
  3516. var parent = this.parent;
  3517. if ( updateParents === true && parent !== null ) {
  3518. parent.updateWorldMatrix( true, false );
  3519. }
  3520. if ( this.matrixAutoUpdate ) this.updateMatrix();
  3521. if ( this.parent === null ) {
  3522. this.matrixWorld.copy( this.matrix );
  3523. } else {
  3524. this.matrixWorld.multiplyMatrices( this.parent.matrixWorld, this.matrix );
  3525. }
  3526. // update children
  3527. if ( updateChildren === true ) {
  3528. var children = this.children;
  3529. for ( var i = 0, l = children.length; i < l; i ++ ) {
  3530. children[ i ].updateWorldMatrix( false, true );
  3531. }
  3532. }
  3533. },
  3534. toJSON: function ( meta ) {
  3535. // meta is a string when called from JSON.stringify
  3536. var isRootObject = ( meta === undefined || typeof meta === 'string' );
  3537. var output = {};
  3538. // meta is a hash used to collect geometries, materials.
  3539. // not providing it implies that this is the root object
  3540. // being serialized.
  3541. if ( isRootObject ) {
  3542. // initialize meta obj
  3543. meta = {
  3544. geometries: {},
  3545. materials: {},
  3546. textures: {},
  3547. images: {},
  3548. shapes: {}
  3549. };
  3550. output.metadata = {
  3551. version: 4.5,
  3552. type: 'Object',
  3553. generator: 'Object3D.toJSON'
  3554. };
  3555. }
  3556. // standard Object3D serialization
  3557. var object = {};
  3558. object.uuid = this.uuid;
  3559. object.type = this.type;
  3560. if ( this.name !== '' ) object.name = this.name;
  3561. if ( this.castShadow === true ) object.castShadow = true;
  3562. if ( this.receiveShadow === true ) object.receiveShadow = true;
  3563. if ( this.visible === false ) object.visible = false;
  3564. if ( this.frustumCulled === false ) object.frustumCulled = false;
  3565. if ( this.renderOrder !== 0 ) object.renderOrder = this.renderOrder;
  3566. if ( JSON.stringify( this.userData ) !== '{}' ) object.userData = this.userData;
  3567. object.layers = this.layers.mask;
  3568. object.matrix = this.matrix.toArray();
  3569. if ( this.matrixAutoUpdate === false ) object.matrixAutoUpdate = false;
  3570. // object specific properties
  3571. if ( this.isMesh && this.drawMode !== TrianglesDrawMode ) object.drawMode = this.drawMode;
  3572. //
  3573. function serialize( library, element ) {
  3574. if ( library[ element.uuid ] === undefined ) {
  3575. library[ element.uuid ] = element.toJSON( meta );
  3576. }
  3577. return element.uuid;
  3578. }
  3579. if ( this.isMesh || this.isLine || this.isPoints ) {
  3580. object.geometry = serialize( meta.geometries, this.geometry );
  3581. var parameters = this.geometry.parameters;
  3582. if ( parameters !== undefined && parameters.shapes !== undefined ) {
  3583. var shapes = parameters.shapes;
  3584. if ( Array.isArray( shapes ) ) {
  3585. for ( var i = 0, l = shapes.length; i < l; i ++ ) {
  3586. var shape = shapes[ i ];
  3587. serialize( meta.shapes, shape );
  3588. }
  3589. } else {
  3590. serialize( meta.shapes, shapes );
  3591. }
  3592. }
  3593. }
  3594. if ( this.material !== undefined ) {
  3595. if ( Array.isArray( this.material ) ) {
  3596. var uuids = [];
  3597. for ( var i = 0, l = this.material.length; i < l; i ++ ) {
  3598. uuids.push( serialize( meta.materials, this.material[ i ] ) );
  3599. }
  3600. object.material = uuids;
  3601. } else {
  3602. object.material = serialize( meta.materials, this.material );
  3603. }
  3604. }
  3605. //
  3606. if ( this.children.length > 0 ) {
  3607. object.children = [];
  3608. for ( var i = 0; i < this.children.length; i ++ ) {
  3609. object.children.push( this.children[ i ].toJSON( meta ).object );
  3610. }
  3611. }
  3612. if ( isRootObject ) {
  3613. var geometries = extractFromCache( meta.geometries );
  3614. var materials = extractFromCache( meta.materials );
  3615. var textures = extractFromCache( meta.textures );
  3616. var images = extractFromCache( meta.images );
  3617. var shapes = extractFromCache( meta.shapes );
  3618. if ( geometries.length > 0 ) output.geometries = geometries;
  3619. if ( materials.length > 0 ) output.materials = materials;
  3620. if ( textures.length > 0 ) output.textures = textures;
  3621. if ( images.length > 0 ) output.images = images;
  3622. if ( shapes.length > 0 ) output.shapes = shapes;
  3623. }
  3624. output.object = object;
  3625. return output;
  3626. // extract data from the cache hash
  3627. // remove metadata on each item
  3628. // and return as array
  3629. function extractFromCache( cache ) {
  3630. var values = [];
  3631. for ( var key in cache ) {
  3632. var data = cache[ key ];
  3633. delete data.metadata;
  3634. values.push( data );
  3635. }
  3636. return values;
  3637. }
  3638. },
  3639. clone: function ( recursive ) {
  3640. return new this.constructor().copy( this, recursive );
  3641. },
  3642. copy: function ( source, recursive ) {
  3643. if ( recursive === undefined ) recursive = true;
  3644. this.name = source.name;
  3645. this.up.copy( source.up );
  3646. this.position.copy( source.position );
  3647. this.quaternion.copy( source.quaternion );
  3648. this.scale.copy( source.scale );
  3649. this.matrix.copy( source.matrix );
  3650. this.matrixWorld.copy( source.matrixWorld );
  3651. this.matrixAutoUpdate = source.matrixAutoUpdate;
  3652. this.matrixWorldNeedsUpdate = source.matrixWorldNeedsUpdate;
  3653. this.layers.mask = source.layers.mask;
  3654. this.visible = source.visible;
  3655. this.castShadow = source.castShadow;
  3656. this.receiveShadow = source.receiveShadow;
  3657. this.frustumCulled = source.frustumCulled;
  3658. this.renderOrder = source.renderOrder;
  3659. this.userData = JSON.parse( JSON.stringify( source.userData ) );
  3660. if ( recursive === true ) {
  3661. for ( var i = 0; i < source.children.length; i ++ ) {
  3662. var child = source.children[ i ];
  3663. this.add( child.clone() );
  3664. }
  3665. }
  3666. return this;
  3667. }
  3668. } );
  3669. /**
  3670. * @author mrdoob / http://mrdoob.com/
  3671. */
  3672. function Scene() {
  3673. Object3D.call( this );
  3674. this.type = 'Scene';
  3675. this.background = null;
  3676. this.fog = null;
  3677. this.overrideMaterial = null;
  3678. this.autoUpdate = true; // checked by the renderer
  3679. if ( typeof __THREE_DEVTOOLS__ !== 'undefined' ) {
  3680. __THREE_DEVTOOLS__.dispatchEvent( new CustomEvent( 'observe', { detail: this } ) ); // eslint-disable-line no-undef
  3681. }
  3682. }
  3683. Scene.prototype = Object.assign( Object.create( Object3D.prototype ), {
  3684. constructor: Scene,
  3685. isScene: true,
  3686. copy: function ( source, recursive ) {
  3687. Object3D.prototype.copy.call( this, source, recursive );
  3688. if ( source.background !== null ) this.background = source.background.clone();
  3689. if ( source.fog !== null ) this.fog = source.fog.clone();
  3690. if ( source.overrideMaterial !== null ) this.overrideMaterial = source.overrideMaterial.clone();
  3691. this.autoUpdate = source.autoUpdate;
  3692. this.matrixAutoUpdate = source.matrixAutoUpdate;
  3693. return this;
  3694. },
  3695. toJSON: function ( meta ) {
  3696. var data = Object3D.prototype.toJSON.call( this, meta );
  3697. if ( this.background !== null ) data.object.background = this.background.toJSON( meta );
  3698. if ( this.fog !== null ) data.object.fog = this.fog.toJSON();
  3699. return data;
  3700. },
  3701. dispose: function () {
  3702. this.dispatchEvent( { type: 'dispose' } );
  3703. }
  3704. } );
  3705. /**
  3706. * @author bhouston / http://clara.io
  3707. * @author WestLangley / http://github.com/WestLangley
  3708. */
  3709. function Box3( min, max ) {
  3710. this.min = ( min !== undefined ) ? min : new Vector3( + Infinity, + Infinity, + Infinity );
  3711. this.max = ( max !== undefined ) ? max : new Vector3( - Infinity, - Infinity, - Infinity );
  3712. }
  3713. Object.assign( Box3.prototype, {
  3714. isBox3: true,
  3715. set: function ( min, max ) {
  3716. this.min.copy( min );
  3717. this.max.copy( max );
  3718. return this;
  3719. },
  3720. setFromArray: function ( array ) {
  3721. var minX = + Infinity;
  3722. var minY = + Infinity;
  3723. var minZ = + Infinity;
  3724. var maxX = - Infinity;
  3725. var maxY = - Infinity;
  3726. var maxZ = - Infinity;
  3727. for ( var i = 0, l = array.length; i < l; i += 3 ) {
  3728. var x = array[ i ];
  3729. var y = array[ i + 1 ];
  3730. var z = array[ i + 2 ];
  3731. if ( x < minX ) minX = x;
  3732. if ( y < minY ) minY = y;
  3733. if ( z < minZ ) minZ = z;
  3734. if ( x > maxX ) maxX = x;
  3735. if ( y > maxY ) maxY = y;
  3736. if ( z > maxZ ) maxZ = z;
  3737. }
  3738. this.min.set( minX, minY, minZ );
  3739. this.max.set( maxX, maxY, maxZ );
  3740. return this;
  3741. },
  3742. setFromBufferAttribute: function ( attribute ) {
  3743. var minX = + Infinity;
  3744. var minY = + Infinity;
  3745. var minZ = + Infinity;
  3746. var maxX = - Infinity;
  3747. var maxY = - Infinity;
  3748. var maxZ = - Infinity;
  3749. for ( var i = 0, l = attribute.count; i < l; i ++ ) {
  3750. var x = attribute.getX( i );
  3751. var y = attribute.getY( i );
  3752. var z = attribute.getZ( i );
  3753. if ( x < minX ) minX = x;
  3754. if ( y < minY ) minY = y;
  3755. if ( z < minZ ) minZ = z;
  3756. if ( x > maxX ) maxX = x;
  3757. if ( y > maxY ) maxY = y;
  3758. if ( z > maxZ ) maxZ = z;
  3759. }
  3760. this.min.set( minX, minY, minZ );
  3761. this.max.set( maxX, maxY, maxZ );
  3762. return this;
  3763. },
  3764. setFromPoints: function ( points ) {
  3765. this.makeEmpty();
  3766. for ( var i = 0, il = points.length; i < il; i ++ ) {
  3767. this.expandByPoint( points[ i ] );
  3768. }
  3769. return this;
  3770. },
  3771. setFromCenterAndSize: function () {
  3772. var v1 = new Vector3();
  3773. return function setFromCenterAndSize( center, size ) {
  3774. var halfSize = v1.copy( size ).multiplyScalar( 0.5 );
  3775. this.min.copy( center ).sub( halfSize );
  3776. this.max.copy( center ).add( halfSize );
  3777. return this;
  3778. };
  3779. }(),
  3780. setFromObject: function ( object ) {
  3781. this.makeEmpty();
  3782. return this.expandByObject( object );
  3783. },
  3784. clone: function () {
  3785. return new this.constructor().copy( this );
  3786. },
  3787. copy: function ( box ) {
  3788. this.min.copy( box.min );
  3789. this.max.copy( box.max );
  3790. return this;
  3791. },
  3792. makeEmpty: function () {
  3793. this.min.x = this.min.y = this.min.z = + Infinity;
  3794. this.max.x = this.max.y = this.max.z = - Infinity;
  3795. return this;
  3796. },
  3797. isEmpty: function () {
  3798. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  3799. return ( this.max.x < this.min.x ) || ( this.max.y < this.min.y ) || ( this.max.z < this.min.z );
  3800. },
  3801. getCenter: function ( target ) {
  3802. if ( target === undefined ) {
  3803. console.warn( 'THREE.Box3: .getCenter() target is now required' );
  3804. target = new Vector3();
  3805. }
  3806. return this.isEmpty() ? target.set( 0, 0, 0 ) : target.addVectors( this.min, this.max ).multiplyScalar( 0.5 );
  3807. },
  3808. getSize: function ( target ) {
  3809. if ( target === undefined ) {
  3810. console.warn( 'THREE.Box3: .getSize() target is now required' );
  3811. target = new Vector3();
  3812. }
  3813. return this.isEmpty() ? target.set( 0, 0, 0 ) : target.subVectors( this.max, this.min );
  3814. },
  3815. expandByPoint: function ( point ) {
  3816. this.min.min( point );
  3817. this.max.max( point );
  3818. return this;
  3819. },
  3820. expandByVector: function ( vector ) {
  3821. this.min.sub( vector );
  3822. this.max.add( vector );
  3823. return this;
  3824. },
  3825. expandByScalar: function ( scalar ) {
  3826. this.min.addScalar( - scalar );
  3827. this.max.addScalar( scalar );
  3828. return this;
  3829. },
  3830. expandByObject: function () {
  3831. // Computes the world-axis-aligned bounding box of an object (including its children),
  3832. // accounting for both the object's, and children's, world transforms
  3833. var scope, i, l;
  3834. var v1 = new Vector3();
  3835. function traverse( node ) {
  3836. var geometry = node.geometry;
  3837. if ( geometry !== undefined ) {
  3838. if ( geometry.isGeometry ) {
  3839. var vertices = geometry.vertices;
  3840. for ( i = 0, l = vertices.length; i < l; i ++ ) {
  3841. v1.copy( vertices[ i ] );
  3842. v1.applyMatrix4( node.matrixWorld );
  3843. scope.expandByPoint( v1 );
  3844. }
  3845. } else if ( geometry.isBufferGeometry ) {
  3846. var attribute = geometry.attributes.position;
  3847. if ( attribute !== undefined ) {
  3848. for ( i = 0, l = attribute.count; i < l; i ++ ) {
  3849. v1.fromBufferAttribute( attribute, i ).applyMatrix4( node.matrixWorld );
  3850. scope.expandByPoint( v1 );
  3851. }
  3852. }
  3853. }
  3854. }
  3855. }
  3856. return function expandByObject( object ) {
  3857. scope = this;
  3858. object.updateMatrixWorld( true );
  3859. object.traverse( traverse );
  3860. return this;
  3861. };
  3862. }(),
  3863. containsPoint: function ( point ) {
  3864. return point.x < this.min.x || point.x > this.max.x ||
  3865. point.y < this.min.y || point.y > this.max.y ||
  3866. point.z < this.min.z || point.z > this.max.z ? false : true;
  3867. },
  3868. containsBox: function ( box ) {
  3869. return this.min.x <= box.min.x && box.max.x <= this.max.x &&
  3870. this.min.y <= box.min.y && box.max.y <= this.max.y &&
  3871. this.min.z <= box.min.z && box.max.z <= this.max.z;
  3872. },
  3873. getParameter: function ( point, target ) {
  3874. // This can potentially have a divide by zero if the box
  3875. // has a size dimension of 0.
  3876. if ( target === undefined ) {
  3877. console.warn( 'THREE.Box3: .getParameter() target is now required' );
  3878. target = new Vector3();
  3879. }
  3880. return target.set(
  3881. ( point.x - this.min.x ) / ( this.max.x - this.min.x ),
  3882. ( point.y - this.min.y ) / ( this.max.y - this.min.y ),
  3883. ( point.z - this.min.z ) / ( this.max.z - this.min.z )
  3884. );
  3885. },
  3886. intersectsBox: function ( box ) {
  3887. // using 6 splitting planes to rule out intersections.
  3888. return box.max.x < this.min.x || box.min.x > this.max.x ||
  3889. box.max.y < this.min.y || box.min.y > this.max.y ||
  3890. box.max.z < this.min.z || box.min.z > this.max.z ? false : true;
  3891. },
  3892. intersectsSphere: ( function () {
  3893. var closestPoint = new Vector3();
  3894. return function intersectsSphere( sphere ) {
  3895. // Find the point on the AABB closest to the sphere center.
  3896. this.clampPoint( sphere.center, closestPoint );
  3897. // If that point is inside the sphere, the AABB and sphere intersect.
  3898. return closestPoint.distanceToSquared( sphere.center ) <= ( sphere.radius * sphere.radius );
  3899. };
  3900. } )(),
  3901. intersectsPlane: function ( plane ) {
  3902. // We compute the minimum and maximum dot product values. If those values
  3903. // are on the same side (back or front) of the plane, then there is no intersection.
  3904. var min, max;
  3905. if ( plane.normal.x > 0 ) {
  3906. min = plane.normal.x * this.min.x;
  3907. max = plane.normal.x * this.max.x;
  3908. } else {
  3909. min = plane.normal.x * this.max.x;
  3910. max = plane.normal.x * this.min.x;
  3911. }
  3912. if ( plane.normal.y > 0 ) {
  3913. min += plane.normal.y * this.min.y;
  3914. max += plane.normal.y * this.max.y;
  3915. } else {
  3916. min += plane.normal.y * this.max.y;
  3917. max += plane.normal.y * this.min.y;
  3918. }
  3919. if ( plane.normal.z > 0 ) {
  3920. min += plane.normal.z * this.min.z;
  3921. max += plane.normal.z * this.max.z;
  3922. } else {
  3923. min += plane.normal.z * this.max.z;
  3924. max += plane.normal.z * this.min.z;
  3925. }
  3926. return ( min <= - plane.constant && max >= - plane.constant );
  3927. },
  3928. intersectsTriangle: ( function () {
  3929. // triangle centered vertices
  3930. var v0 = new Vector3();
  3931. var v1 = new Vector3();
  3932. var v2 = new Vector3();
  3933. // triangle edge vectors
  3934. var f0 = new Vector3();
  3935. var f1 = new Vector3();
  3936. var f2 = new Vector3();
  3937. var testAxis = new Vector3();
  3938. var center = new Vector3();
  3939. var extents = new Vector3();
  3940. var triangleNormal = new Vector3();
  3941. function satForAxes( axes ) {
  3942. var i, j;
  3943. for ( i = 0, j = axes.length - 3; i <= j; i += 3 ) {
  3944. testAxis.fromArray( axes, i );
  3945. // project the aabb onto the seperating axis
  3946. var r = extents.x * Math.abs( testAxis.x ) + extents.y * Math.abs( testAxis.y ) + extents.z * Math.abs( testAxis.z );
  3947. // project all 3 vertices of the triangle onto the seperating axis
  3948. var p0 = v0.dot( testAxis );
  3949. var p1 = v1.dot( testAxis );
  3950. var p2 = v2.dot( testAxis );
  3951. // actual test, basically see if either of the most extreme of the triangle points intersects r
  3952. if ( Math.max( - Math.max( p0, p1, p2 ), Math.min( p0, p1, p2 ) ) > r ) {
  3953. // points of the projected triangle are outside the projected half-length of the aabb
  3954. // the axis is seperating and we can exit
  3955. return false;
  3956. }
  3957. }
  3958. return true;
  3959. }
  3960. return function intersectsTriangle( triangle ) {
  3961. if ( this.isEmpty() ) {
  3962. return false;
  3963. }
  3964. // compute box center and extents
  3965. this.getCenter( center );
  3966. extents.subVectors( this.max, center );
  3967. // translate triangle to aabb origin
  3968. v0.subVectors( triangle.a, center );
  3969. v1.subVectors( triangle.b, center );
  3970. v2.subVectors( triangle.c, center );
  3971. // compute edge vectors for triangle
  3972. f0.subVectors( v1, v0 );
  3973. f1.subVectors( v2, v1 );
  3974. f2.subVectors( v0, v2 );
  3975. // test against axes that are given by cross product combinations of the edges of the triangle and the edges of the aabb
  3976. // 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
  3977. // axis_ij = u_i x f_j (u0, u1, u2 = face normals of aabb = x,y,z axes vectors since aabb is axis aligned)
  3978. var axes = [
  3979. 0, - f0.z, f0.y, 0, - f1.z, f1.y, 0, - f2.z, f2.y,
  3980. f0.z, 0, - f0.x, f1.z, 0, - f1.x, f2.z, 0, - f2.x,
  3981. - f0.y, f0.x, 0, - f1.y, f1.x, 0, - f2.y, f2.x, 0
  3982. ];
  3983. if ( ! satForAxes( axes ) ) {
  3984. return false;
  3985. }
  3986. // test 3 face normals from the aabb
  3987. axes = [ 1, 0, 0, 0, 1, 0, 0, 0, 1 ];
  3988. if ( ! satForAxes( axes ) ) {
  3989. return false;
  3990. }
  3991. // finally testing the face normal of the triangle
  3992. // use already existing triangle edge vectors here
  3993. triangleNormal.crossVectors( f0, f1 );
  3994. axes = [ triangleNormal.x, triangleNormal.y, triangleNormal.z ];
  3995. return satForAxes( axes );
  3996. };
  3997. } )(),
  3998. clampPoint: function ( point, target ) {
  3999. if ( target === undefined ) {
  4000. console.warn( 'THREE.Box3: .clampPoint() target is now required' );
  4001. target = new Vector3();
  4002. }
  4003. return target.copy( point ).clamp( this.min, this.max );
  4004. },
  4005. distanceToPoint: function () {
  4006. var v1 = new Vector3();
  4007. return function distanceToPoint( point ) {
  4008. var clampedPoint = v1.copy( point ).clamp( this.min, this.max );
  4009. return clampedPoint.sub( point ).length();
  4010. };
  4011. }(),
  4012. getBoundingSphere: function () {
  4013. var v1 = new Vector3();
  4014. return function getBoundingSphere( target ) {
  4015. if ( target === undefined ) {
  4016. console.error( 'THREE.Box3: .getBoundingSphere() target is now required' );
  4017. //target = new Sphere(); // removed to avoid cyclic dependency
  4018. }
  4019. this.getCenter( target.center );
  4020. target.radius = this.getSize( v1 ).length() * 0.5;
  4021. return target;
  4022. };
  4023. }(),
  4024. intersect: function ( box ) {
  4025. this.min.max( box.min );
  4026. this.max.min( box.max );
  4027. // 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.
  4028. if ( this.isEmpty() ) this.makeEmpty();
  4029. return this;
  4030. },
  4031. union: function ( box ) {
  4032. this.min.min( box.min );
  4033. this.max.max( box.max );
  4034. return this;
  4035. },
  4036. applyMatrix4: function () {
  4037. var points = [
  4038. new Vector3(),
  4039. new Vector3(),
  4040. new Vector3(),
  4041. new Vector3(),
  4042. new Vector3(),
  4043. new Vector3(),
  4044. new Vector3(),
  4045. new Vector3()
  4046. ];
  4047. return function applyMatrix4( matrix ) {
  4048. // transform of empty box is an empty box.
  4049. if ( this.isEmpty() ) return this;
  4050. // NOTE: I am using a binary pattern to specify all 2^3 combinations below
  4051. points[ 0 ].set( this.min.x, this.min.y, this.min.z ).applyMatrix4( matrix ); // 000
  4052. points[ 1 ].set( this.min.x, this.min.y, this.max.z ).applyMatrix4( matrix ); // 001
  4053. points[ 2 ].set( this.min.x, this.max.y, this.min.z ).applyMatrix4( matrix ); // 010
  4054. points[ 3 ].set( this.min.x, this.max.y, this.max.z ).applyMatrix4( matrix ); // 011
  4055. points[ 4 ].set( this.max.x, this.min.y, this.min.z ).applyMatrix4( matrix ); // 100
  4056. points[ 5 ].set( this.max.x, this.min.y, this.max.z ).applyMatrix4( matrix ); // 101
  4057. points[ 6 ].set( this.max.x, this.max.y, this.min.z ).applyMatrix4( matrix ); // 110
  4058. points[ 7 ].set( this.max.x, this.max.y, this.max.z ).applyMatrix4( matrix ); // 111
  4059. this.setFromPoints( points );
  4060. return this;
  4061. };
  4062. }(),
  4063. translate: function ( offset ) {
  4064. this.min.add( offset );
  4065. this.max.add( offset );
  4066. return this;
  4067. },
  4068. equals: function ( box ) {
  4069. return box.min.equals( this.min ) && box.max.equals( this.max );
  4070. }
  4071. } );
  4072. /**
  4073. * @author bhouston / http://clara.io
  4074. * @author mrdoob / http://mrdoob.com/
  4075. */
  4076. function Sphere( center, radius ) {
  4077. this.center = ( center !== undefined ) ? center : new Vector3();
  4078. this.radius = ( radius !== undefined ) ? radius : 0;
  4079. }
  4080. Object.assign( Sphere.prototype, {
  4081. set: function ( center, radius ) {
  4082. this.center.copy( center );
  4083. this.radius = radius;
  4084. return this;
  4085. },
  4086. setFromPoints: function () {
  4087. var box = new Box3();
  4088. return function setFromPoints( points, optionalCenter ) {
  4089. var center = this.center;
  4090. if ( optionalCenter !== undefined ) {
  4091. center.copy( optionalCenter );
  4092. } else {
  4093. box.setFromPoints( points ).getCenter( center );
  4094. }
  4095. var maxRadiusSq = 0;
  4096. for ( var i = 0, il = points.length; i < il; i ++ ) {
  4097. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( points[ i ] ) );
  4098. }
  4099. this.radius = Math.sqrt( maxRadiusSq );
  4100. return this;
  4101. };
  4102. }(),
  4103. clone: function () {
  4104. return new this.constructor().copy( this );
  4105. },
  4106. copy: function ( sphere ) {
  4107. this.center.copy( sphere.center );
  4108. this.radius = sphere.radius;
  4109. return this;
  4110. },
  4111. empty: function () {
  4112. return ( this.radius <= 0 );
  4113. },
  4114. containsPoint: function ( point ) {
  4115. return ( point.distanceToSquared( this.center ) <= ( this.radius * this.radius ) );
  4116. },
  4117. distanceToPoint: function ( point ) {
  4118. return ( point.distanceTo( this.center ) - this.radius );
  4119. },
  4120. intersectsSphere: function ( sphere ) {
  4121. var radiusSum = this.radius + sphere.radius;
  4122. return sphere.center.distanceToSquared( this.center ) <= ( radiusSum * radiusSum );
  4123. },
  4124. intersectsBox: function ( box ) {
  4125. return box.intersectsSphere( this );
  4126. },
  4127. intersectsPlane: function ( plane ) {
  4128. return Math.abs( plane.distanceToPoint( this.center ) ) <= this.radius;
  4129. },
  4130. clampPoint: function ( point, target ) {
  4131. var deltaLengthSq = this.center.distanceToSquared( point );
  4132. if ( target === undefined ) {
  4133. console.warn( 'THREE.Sphere: .clampPoint() target is now required' );
  4134. target = new Vector3();
  4135. }
  4136. target.copy( point );
  4137. if ( deltaLengthSq > ( this.radius * this.radius ) ) {
  4138. target.sub( this.center ).normalize();
  4139. target.multiplyScalar( this.radius ).add( this.center );
  4140. }
  4141. return target;
  4142. },
  4143. getBoundingBox: function ( target ) {
  4144. if ( target === undefined ) {
  4145. console.warn( 'THREE.Sphere: .getBoundingBox() target is now required' );
  4146. target = new Box3();
  4147. }
  4148. target.set( this.center, this.center );
  4149. target.expandByScalar( this.radius );
  4150. return target;
  4151. },
  4152. applyMatrix4: function ( matrix ) {
  4153. this.center.applyMatrix4( matrix );
  4154. this.radius = this.radius * matrix.getMaxScaleOnAxis();
  4155. return this;
  4156. },
  4157. translate: function ( offset ) {
  4158. this.center.add( offset );
  4159. return this;
  4160. },
  4161. equals: function ( sphere ) {
  4162. return sphere.center.equals( this.center ) && ( sphere.radius === this.radius );
  4163. }
  4164. } );
  4165. /**
  4166. * @author bhouston / http://clara.io
  4167. */
  4168. function Ray( origin, direction ) {
  4169. this.origin = ( origin !== undefined ) ? origin : new Vector3();
  4170. this.direction = ( direction !== undefined ) ? direction : new Vector3();
  4171. }
  4172. Object.assign( Ray.prototype, {
  4173. set: function ( origin, direction ) {
  4174. this.origin.copy( origin );
  4175. this.direction.copy( direction );
  4176. return this;
  4177. },
  4178. clone: function () {
  4179. return new this.constructor().copy( this );
  4180. },
  4181. copy: function ( ray ) {
  4182. this.origin.copy( ray.origin );
  4183. this.direction.copy( ray.direction );
  4184. return this;
  4185. },
  4186. at: function ( t, target ) {
  4187. if ( target === undefined ) {
  4188. console.warn( 'THREE.Ray: .at() target is now required' );
  4189. target = new Vector3();
  4190. }
  4191. return target.copy( this.direction ).multiplyScalar( t ).add( this.origin );
  4192. },
  4193. lookAt: function ( v ) {
  4194. this.direction.copy( v ).sub( this.origin ).normalize();
  4195. return this;
  4196. },
  4197. recast: function () {
  4198. var v1 = new Vector3();
  4199. return function recast( t ) {
  4200. this.origin.copy( this.at( t, v1 ) );
  4201. return this;
  4202. };
  4203. }(),
  4204. closestPointToPoint: function ( point, target ) {
  4205. if ( target === undefined ) {
  4206. console.warn( 'THREE.Ray: .closestPointToPoint() target is now required' );
  4207. target = new Vector3();
  4208. }
  4209. target.subVectors( point, this.origin );
  4210. var directionDistance = target.dot( this.direction );
  4211. if ( directionDistance < 0 ) {
  4212. return target.copy( this.origin );
  4213. }
  4214. return target.copy( this.direction ).multiplyScalar( directionDistance ).add( this.origin );
  4215. },
  4216. distanceToPoint: function ( point ) {
  4217. return Math.sqrt( this.distanceSqToPoint( point ) );
  4218. },
  4219. distanceSqToPoint: function () {
  4220. var v1 = new Vector3();
  4221. return function distanceSqToPoint( point ) {
  4222. var directionDistance = v1.subVectors( point, this.origin ).dot( this.direction );
  4223. // point behind the ray
  4224. if ( directionDistance < 0 ) {
  4225. return this.origin.distanceToSquared( point );
  4226. }
  4227. v1.copy( this.direction ).multiplyScalar( directionDistance ).add( this.origin );
  4228. return v1.distanceToSquared( point );
  4229. };
  4230. }(),
  4231. distanceSqToSegment: function () {
  4232. var segCenter = new Vector3();
  4233. var segDir = new Vector3();
  4234. var diff = new Vector3();
  4235. return function distanceSqToSegment( v0, v1, optionalPointOnRay, optionalPointOnSegment ) {
  4236. // from http://www.geometrictools.com/GTEngine/Include/Mathematics/GteDistRaySegment.h
  4237. // It returns the min distance between the ray and the segment
  4238. // defined by v0 and v1
  4239. // It can also set two optional targets :
  4240. // - The closest point on the ray
  4241. // - The closest point on the segment
  4242. segCenter.copy( v0 ).add( v1 ).multiplyScalar( 0.5 );
  4243. segDir.copy( v1 ).sub( v0 ).normalize();
  4244. diff.copy( this.origin ).sub( segCenter );
  4245. var segExtent = v0.distanceTo( v1 ) * 0.5;
  4246. var a01 = - this.direction.dot( segDir );
  4247. var b0 = diff.dot( this.direction );
  4248. var b1 = - diff.dot( segDir );
  4249. var c = diff.lengthSq();
  4250. var det = Math.abs( 1 - a01 * a01 );
  4251. var s0, s1, sqrDist, extDet;
  4252. if ( det > 0 ) {
  4253. // The ray and segment are not parallel.
  4254. s0 = a01 * b1 - b0;
  4255. s1 = a01 * b0 - b1;
  4256. extDet = segExtent * det;
  4257. if ( s0 >= 0 ) {
  4258. if ( s1 >= - extDet ) {
  4259. if ( s1 <= extDet ) {
  4260. // region 0
  4261. // Minimum at interior points of ray and segment.
  4262. var invDet = 1 / det;
  4263. s0 *= invDet;
  4264. s1 *= invDet;
  4265. sqrDist = s0 * ( s0 + a01 * s1 + 2 * b0 ) + s1 * ( a01 * s0 + s1 + 2 * b1 ) + c;
  4266. } else {
  4267. // region 1
  4268. s1 = segExtent;
  4269. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  4270. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  4271. }
  4272. } else {
  4273. // region 5
  4274. s1 = - segExtent;
  4275. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  4276. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  4277. }
  4278. } else {
  4279. if ( s1 <= - extDet ) {
  4280. // region 4
  4281. s0 = Math.max( 0, - ( - a01 * segExtent + b0 ) );
  4282. s1 = ( s0 > 0 ) ? - segExtent : Math.min( Math.max( - segExtent, - b1 ), segExtent );
  4283. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  4284. } else if ( s1 <= extDet ) {
  4285. // region 3
  4286. s0 = 0;
  4287. s1 = Math.min( Math.max( - segExtent, - b1 ), segExtent );
  4288. sqrDist = s1 * ( s1 + 2 * b1 ) + c;
  4289. } else {
  4290. // region 2
  4291. s0 = Math.max( 0, - ( a01 * segExtent + b0 ) );
  4292. s1 = ( s0 > 0 ) ? segExtent : Math.min( Math.max( - segExtent, - b1 ), segExtent );
  4293. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  4294. }
  4295. }
  4296. } else {
  4297. // Ray and segment are parallel.
  4298. s1 = ( a01 > 0 ) ? - segExtent : segExtent;
  4299. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  4300. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  4301. }
  4302. if ( optionalPointOnRay ) {
  4303. optionalPointOnRay.copy( this.direction ).multiplyScalar( s0 ).add( this.origin );
  4304. }
  4305. if ( optionalPointOnSegment ) {
  4306. optionalPointOnSegment.copy( segDir ).multiplyScalar( s1 ).add( segCenter );
  4307. }
  4308. return sqrDist;
  4309. };
  4310. }(),
  4311. intersectSphere: function () {
  4312. var v1 = new Vector3();
  4313. return function intersectSphere( sphere, target ) {
  4314. v1.subVectors( sphere.center, this.origin );
  4315. var tca = v1.dot( this.direction );
  4316. var d2 = v1.dot( v1 ) - tca * tca;
  4317. var radius2 = sphere.radius * sphere.radius;
  4318. if ( d2 > radius2 ) return null;
  4319. var thc = Math.sqrt( radius2 - d2 );
  4320. // t0 = first intersect point - entrance on front of sphere
  4321. var t0 = tca - thc;
  4322. // t1 = second intersect point - exit point on back of sphere
  4323. var t1 = tca + thc;
  4324. // test to see if both t0 and t1 are behind the ray - if so, return null
  4325. if ( t0 < 0 && t1 < 0 ) return null;
  4326. // test to see if t0 is behind the ray:
  4327. // if it is, the ray is inside the sphere, so return the second exit point scaled by t1,
  4328. // in order to always return an intersect point that is in front of the ray.
  4329. if ( t0 < 0 ) return this.at( t1, target );
  4330. // else t0 is in front of the ray, so return the first collision point scaled by t0
  4331. return this.at( t0, target );
  4332. };
  4333. }(),
  4334. intersectsSphere: function ( sphere ) {
  4335. return this.distanceSqToPoint( sphere.center ) <= ( sphere.radius * sphere.radius );
  4336. },
  4337. distanceToPlane: function ( plane ) {
  4338. var denominator = plane.normal.dot( this.direction );
  4339. if ( denominator === 0 ) {
  4340. // line is coplanar, return origin
  4341. if ( plane.distanceToPoint( this.origin ) === 0 ) {
  4342. return 0;
  4343. }
  4344. // Null is preferable to undefined since undefined means.... it is undefined
  4345. return null;
  4346. }
  4347. var t = - ( this.origin.dot( plane.normal ) + plane.constant ) / denominator;
  4348. // Return if the ray never intersects the plane
  4349. return t >= 0 ? t : null;
  4350. },
  4351. intersectPlane: function ( plane, target ) {
  4352. var t = this.distanceToPlane( plane );
  4353. if ( t === null ) {
  4354. return null;
  4355. }
  4356. return this.at( t, target );
  4357. },
  4358. intersectsPlane: function ( plane ) {
  4359. // check if the ray lies on the plane first
  4360. var distToPoint = plane.distanceToPoint( this.origin );
  4361. if ( distToPoint === 0 ) {
  4362. return true;
  4363. }
  4364. var denominator = plane.normal.dot( this.direction );
  4365. if ( denominator * distToPoint < 0 ) {
  4366. return true;
  4367. }
  4368. // ray origin is behind the plane (and is pointing behind it)
  4369. return false;
  4370. },
  4371. intersectBox: function ( box, target ) {
  4372. var tmin, tmax, tymin, tymax, tzmin, tzmax;
  4373. var invdirx = 1 / this.direction.x,
  4374. invdiry = 1 / this.direction.y,
  4375. invdirz = 1 / this.direction.z;
  4376. var origin = this.origin;
  4377. if ( invdirx >= 0 ) {
  4378. tmin = ( box.min.x - origin.x ) * invdirx;
  4379. tmax = ( box.max.x - origin.x ) * invdirx;
  4380. } else {
  4381. tmin = ( box.max.x - origin.x ) * invdirx;
  4382. tmax = ( box.min.x - origin.x ) * invdirx;
  4383. }
  4384. if ( invdiry >= 0 ) {
  4385. tymin = ( box.min.y - origin.y ) * invdiry;
  4386. tymax = ( box.max.y - origin.y ) * invdiry;
  4387. } else {
  4388. tymin = ( box.max.y - origin.y ) * invdiry;
  4389. tymax = ( box.min.y - origin.y ) * invdiry;
  4390. }
  4391. if ( ( tmin > tymax ) || ( tymin > tmax ) ) return null;
  4392. // These lines also handle the case where tmin or tmax is NaN
  4393. // (result of 0 * Infinity). x !== x returns true if x is NaN
  4394. if ( tymin > tmin || tmin !== tmin ) tmin = tymin;
  4395. if ( tymax < tmax || tmax !== tmax ) tmax = tymax;
  4396. if ( invdirz >= 0 ) {
  4397. tzmin = ( box.min.z - origin.z ) * invdirz;
  4398. tzmax = ( box.max.z - origin.z ) * invdirz;
  4399. } else {
  4400. tzmin = ( box.max.z - origin.z ) * invdirz;
  4401. tzmax = ( box.min.z - origin.z ) * invdirz;
  4402. }
  4403. if ( ( tmin > tzmax ) || ( tzmin > tmax ) ) return null;
  4404. if ( tzmin > tmin || tmin !== tmin ) tmin = tzmin;
  4405. if ( tzmax < tmax || tmax !== tmax ) tmax = tzmax;
  4406. //return point closest to the ray (positive side)
  4407. if ( tmax < 0 ) return null;
  4408. return this.at( tmin >= 0 ? tmin : tmax, target );
  4409. },
  4410. intersectsBox: ( function () {
  4411. var v = new Vector3();
  4412. return function intersectsBox( box ) {
  4413. return this.intersectBox( box, v ) !== null;
  4414. };
  4415. } )(),
  4416. intersectTriangle: function () {
  4417. // Compute the offset origin, edges, and normal.
  4418. var diff = new Vector3();
  4419. var edge1 = new Vector3();
  4420. var edge2 = new Vector3();
  4421. var normal = new Vector3();
  4422. return function intersectTriangle( a, b, c, backfaceCulling, target ) {
  4423. // from http://www.geometrictools.com/GTEngine/Include/Mathematics/GteIntrRay3Triangle3.h
  4424. edge1.subVectors( b, a );
  4425. edge2.subVectors( c, a );
  4426. normal.crossVectors( edge1, edge2 );
  4427. // Solve Q + t*D = b1*E1 + b2*E2 (Q = kDiff, D = ray direction,
  4428. // E1 = kEdge1, E2 = kEdge2, N = Cross(E1,E2)) by
  4429. // |Dot(D,N)|*b1 = sign(Dot(D,N))*Dot(D,Cross(Q,E2))
  4430. // |Dot(D,N)|*b2 = sign(Dot(D,N))*Dot(D,Cross(E1,Q))
  4431. // |Dot(D,N)|*t = -sign(Dot(D,N))*Dot(Q,N)
  4432. var DdN = this.direction.dot( normal );
  4433. var sign;
  4434. if ( DdN > 0 ) {
  4435. if ( backfaceCulling ) return null;
  4436. sign = 1;
  4437. } else if ( DdN < 0 ) {
  4438. sign = - 1;
  4439. DdN = - DdN;
  4440. } else {
  4441. return null;
  4442. }
  4443. diff.subVectors( this.origin, a );
  4444. var DdQxE2 = sign * this.direction.dot( edge2.crossVectors( diff, edge2 ) );
  4445. // b1 < 0, no intersection
  4446. if ( DdQxE2 < 0 ) {
  4447. return null;
  4448. }
  4449. var DdE1xQ = sign * this.direction.dot( edge1.cross( diff ) );
  4450. // b2 < 0, no intersection
  4451. if ( DdE1xQ < 0 ) {
  4452. return null;
  4453. }
  4454. // b1+b2 > 1, no intersection
  4455. if ( DdQxE2 + DdE1xQ > DdN ) {
  4456. return null;
  4457. }
  4458. // Line intersects triangle, check if ray does.
  4459. var QdN = - sign * diff.dot( normal );
  4460. // t < 0, no intersection
  4461. if ( QdN < 0 ) {
  4462. return null;
  4463. }
  4464. // Ray intersects triangle.
  4465. return this.at( QdN / DdN, target );
  4466. };
  4467. }(),
  4468. applyMatrix4: function ( matrix4 ) {
  4469. this.origin.applyMatrix4( matrix4 );
  4470. this.direction.transformDirection( matrix4 );
  4471. return this;
  4472. },
  4473. equals: function ( ray ) {
  4474. return ray.origin.equals( this.origin ) && ray.direction.equals( this.direction );
  4475. }
  4476. } );
  4477. /**
  4478. * @author bhouston / http://clara.io
  4479. * @author mrdoob / http://mrdoob.com/
  4480. */
  4481. function Triangle( a, b, c ) {
  4482. this.a = ( a !== undefined ) ? a : new Vector3();
  4483. this.b = ( b !== undefined ) ? b : new Vector3();
  4484. this.c = ( c !== undefined ) ? c : new Vector3();
  4485. }
  4486. Object.assign( Triangle, {
  4487. getNormal: function () {
  4488. var v0 = new Vector3();
  4489. return function getNormal( a, b, c, target ) {
  4490. if ( target === undefined ) {
  4491. console.warn( 'THREE.Triangle: .getNormal() target is now required' );
  4492. target = new Vector3();
  4493. }
  4494. target.subVectors( c, b );
  4495. v0.subVectors( a, b );
  4496. target.cross( v0 );
  4497. var targetLengthSq = target.lengthSq();
  4498. if ( targetLengthSq > 0 ) {
  4499. return target.multiplyScalar( 1 / Math.sqrt( targetLengthSq ) );
  4500. }
  4501. return target.set( 0, 0, 0 );
  4502. };
  4503. }(),
  4504. // static/instance method to calculate barycentric coordinates
  4505. // based on: http://www.blackpawn.com/texts/pointinpoly/default.html
  4506. getBarycoord: function () {
  4507. var v0 = new Vector3();
  4508. var v1 = new Vector3();
  4509. var v2 = new Vector3();
  4510. return function getBarycoord( point, a, b, c, target ) {
  4511. v0.subVectors( c, a );
  4512. v1.subVectors( b, a );
  4513. v2.subVectors( point, a );
  4514. var dot00 = v0.dot( v0 );
  4515. var dot01 = v0.dot( v1 );
  4516. var dot02 = v0.dot( v2 );
  4517. var dot11 = v1.dot( v1 );
  4518. var dot12 = v1.dot( v2 );
  4519. var denom = ( dot00 * dot11 - dot01 * dot01 );
  4520. if ( target === undefined ) {
  4521. console.warn( 'THREE.Triangle: .getBarycoord() target is now required' );
  4522. target = new Vector3();
  4523. }
  4524. // collinear or singular triangle
  4525. if ( denom === 0 ) {
  4526. // arbitrary location outside of triangle?
  4527. // not sure if this is the best idea, maybe should be returning undefined
  4528. return target.set( - 2, - 1, - 1 );
  4529. }
  4530. var invDenom = 1 / denom;
  4531. var u = ( dot11 * dot02 - dot01 * dot12 ) * invDenom;
  4532. var v = ( dot00 * dot12 - dot01 * dot02 ) * invDenom;
  4533. // barycentric coordinates must always sum to 1
  4534. return target.set( 1 - u - v, v, u );
  4535. };
  4536. }(),
  4537. containsPoint: function () {
  4538. var v1 = new Vector3();
  4539. return function containsPoint( point, a, b, c ) {
  4540. Triangle.getBarycoord( point, a, b, c, v1 );
  4541. return ( v1.x >= 0 ) && ( v1.y >= 0 ) && ( ( v1.x + v1.y ) <= 1 );
  4542. };
  4543. }(),
  4544. getUV: function () {
  4545. var barycoord = new Vector3();
  4546. return function getUV( point, p1, p2, p3, uv1, uv2, uv3, target ) {
  4547. this.getBarycoord( point, p1, p2, p3, barycoord );
  4548. target.set( 0, 0 );
  4549. target.addScaledVector( uv1, barycoord.x );
  4550. target.addScaledVector( uv2, barycoord.y );
  4551. target.addScaledVector( uv3, barycoord.z );
  4552. return target;
  4553. };
  4554. }(),
  4555. isFrontFacing: function () {
  4556. var v0 = new Vector3();
  4557. var v1 = new Vector3();
  4558. return function isFrontFacing( a, b, c, direction ) {
  4559. v0.subVectors( c, b );
  4560. v1.subVectors( a, b );
  4561. // strictly front facing
  4562. return ( v0.cross( v1 ).dot( direction ) < 0 ) ? true : false;
  4563. };
  4564. }()
  4565. } );
  4566. Object.assign( Triangle.prototype, {
  4567. set: function ( a, b, c ) {
  4568. this.a.copy( a );
  4569. this.b.copy( b );
  4570. this.c.copy( c );
  4571. return this;
  4572. },
  4573. setFromPointsAndIndices: function ( points, i0, i1, i2 ) {
  4574. this.a.copy( points[ i0 ] );
  4575. this.b.copy( points[ i1 ] );
  4576. this.c.copy( points[ i2 ] );
  4577. return this;
  4578. },
  4579. clone: function () {
  4580. return new this.constructor().copy( this );
  4581. },
  4582. copy: function ( triangle ) {
  4583. this.a.copy( triangle.a );
  4584. this.b.copy( triangle.b );
  4585. this.c.copy( triangle.c );
  4586. return this;
  4587. },
  4588. getArea: function () {
  4589. var v0 = new Vector3();
  4590. var v1 = new Vector3();
  4591. return function getArea() {
  4592. v0.subVectors( this.c, this.b );
  4593. v1.subVectors( this.a, this.b );
  4594. return v0.cross( v1 ).length() * 0.5;
  4595. };
  4596. }(),
  4597. getMidpoint: function ( target ) {
  4598. if ( target === undefined ) {
  4599. console.warn( 'THREE.Triangle: .getMidpoint() target is now required' );
  4600. target = new Vector3();
  4601. }
  4602. return target.addVectors( this.a, this.b ).add( this.c ).multiplyScalar( 1 / 3 );
  4603. },
  4604. getNormal: function ( target ) {
  4605. return Triangle.getNormal( this.a, this.b, this.c, target );
  4606. },
  4607. getPlane: function ( target ) {
  4608. if ( target === undefined ) {
  4609. console.warn( 'THREE.Triangle: .getPlane() target is now required' );
  4610. target = new Vector3();
  4611. }
  4612. return target.setFromCoplanarPoints( this.a, this.b, this.c );
  4613. },
  4614. getBarycoord: function ( point, target ) {
  4615. return Triangle.getBarycoord( point, this.a, this.b, this.c, target );
  4616. },
  4617. getUV: function ( point, uv1, uv2, uv3, target ) {
  4618. return Triangle.getUV( point, this.a, this.b, this.c, uv1, uv2, uv3, target );
  4619. },
  4620. containsPoint: function ( point ) {
  4621. return Triangle.containsPoint( point, this.a, this.b, this.c );
  4622. },
  4623. isFrontFacing: function ( direction ) {
  4624. return Triangle.isFrontFacing( this.a, this.b, this.c, direction );
  4625. },
  4626. intersectsBox: function ( box ) {
  4627. return box.intersectsTriangle( this );
  4628. },
  4629. closestPointToPoint: function () {
  4630. var vab = new Vector3();
  4631. var vac = new Vector3();
  4632. var vbc = new Vector3();
  4633. var vap = new Vector3();
  4634. var vbp = new Vector3();
  4635. var vcp = new Vector3();
  4636. return function closestPointToPoint( p, target ) {
  4637. if ( target === undefined ) {
  4638. console.warn( 'THREE.Triangle: .closestPointToPoint() target is now required' );
  4639. target = new Vector3();
  4640. }
  4641. var a = this.a, b = this.b, c = this.c;
  4642. var v, w;
  4643. // algorithm thanks to Real-Time Collision Detection by Christer Ericson,
  4644. // published by Morgan Kaufmann Publishers, (c) 2005 Elsevier Inc.,
  4645. // under the accompanying license; see chapter 5.1.5 for detailed explanation.
  4646. // basically, we're distinguishing which of the voronoi regions of the triangle
  4647. // the point lies in with the minimum amount of redundant computation.
  4648. vab.subVectors( b, a );
  4649. vac.subVectors( c, a );
  4650. vap.subVectors( p, a );
  4651. var d1 = vab.dot( vap );
  4652. var d2 = vac.dot( vap );
  4653. if ( d1 <= 0 && d2 <= 0 ) {
  4654. // vertex region of A; barycentric coords (1, 0, 0)
  4655. return target.copy( a );
  4656. }
  4657. vbp.subVectors( p, b );
  4658. var d3 = vab.dot( vbp );
  4659. var d4 = vac.dot( vbp );
  4660. if ( d3 >= 0 && d4 <= d3 ) {
  4661. // vertex region of B; barycentric coords (0, 1, 0)
  4662. return target.copy( b );
  4663. }
  4664. var vc = d1 * d4 - d3 * d2;
  4665. if ( vc <= 0 && d1 >= 0 && d3 <= 0 ) {
  4666. v = d1 / ( d1 - d3 );
  4667. // edge region of AB; barycentric coords (1-v, v, 0)
  4668. return target.copy( a ).addScaledVector( vab, v );
  4669. }
  4670. vcp.subVectors( p, c );
  4671. var d5 = vab.dot( vcp );
  4672. var d6 = vac.dot( vcp );
  4673. if ( d6 >= 0 && d5 <= d6 ) {
  4674. // vertex region of C; barycentric coords (0, 0, 1)
  4675. return target.copy( c );
  4676. }
  4677. var vb = d5 * d2 - d1 * d6;
  4678. if ( vb <= 0 && d2 >= 0 && d6 <= 0 ) {
  4679. w = d2 / ( d2 - d6 );
  4680. // edge region of AC; barycentric coords (1-w, 0, w)
  4681. return target.copy( a ).addScaledVector( vac, w );
  4682. }
  4683. var va = d3 * d6 - d5 * d4;
  4684. if ( va <= 0 && ( d4 - d3 ) >= 0 && ( d5 - d6 ) >= 0 ) {
  4685. vbc.subVectors( c, b );
  4686. w = ( d4 - d3 ) / ( ( d4 - d3 ) + ( d5 - d6 ) );
  4687. // edge region of BC; barycentric coords (0, 1-w, w)
  4688. return target.copy( b ).addScaledVector( vbc, w ); // edge region of BC
  4689. }
  4690. // face region
  4691. var denom = 1 / ( va + vb + vc );
  4692. // u = va * denom
  4693. v = vb * denom;
  4694. w = vc * denom;
  4695. return target.copy( a ).addScaledVector( vab, v ).addScaledVector( vac, w );
  4696. };
  4697. }(),
  4698. equals: function ( triangle ) {
  4699. return triangle.a.equals( this.a ) && triangle.b.equals( this.b ) && triangle.c.equals( this.c );
  4700. }
  4701. } );
  4702. /**
  4703. * @author mrdoob / http://mrdoob.com/
  4704. */
  4705. var ColorKeywords = { 'aliceblue': 0xF0F8FF, 'antiquewhite': 0xFAEBD7, 'aqua': 0x00FFFF, 'aquamarine': 0x7FFFD4, 'azure': 0xF0FFFF,
  4706. 'beige': 0xF5F5DC, 'bisque': 0xFFE4C4, 'black': 0x000000, 'blanchedalmond': 0xFFEBCD, 'blue': 0x0000FF, 'blueviolet': 0x8A2BE2,
  4707. 'brown': 0xA52A2A, 'burlywood': 0xDEB887, 'cadetblue': 0x5F9EA0, 'chartreuse': 0x7FFF00, 'chocolate': 0xD2691E, 'coral': 0xFF7F50,
  4708. 'cornflowerblue': 0x6495ED, 'cornsilk': 0xFFF8DC, 'crimson': 0xDC143C, 'cyan': 0x00FFFF, 'darkblue': 0x00008B, 'darkcyan': 0x008B8B,
  4709. 'darkgoldenrod': 0xB8860B, 'darkgray': 0xA9A9A9, 'darkgreen': 0x006400, 'darkgrey': 0xA9A9A9, 'darkkhaki': 0xBDB76B, 'darkmagenta': 0x8B008B,
  4710. 'darkolivegreen': 0x556B2F, 'darkorange': 0xFF8C00, 'darkorchid': 0x9932CC, 'darkred': 0x8B0000, 'darksalmon': 0xE9967A, 'darkseagreen': 0x8FBC8F,
  4711. 'darkslateblue': 0x483D8B, 'darkslategray': 0x2F4F4F, 'darkslategrey': 0x2F4F4F, 'darkturquoise': 0x00CED1, 'darkviolet': 0x9400D3,
  4712. 'deeppink': 0xFF1493, 'deepskyblue': 0x00BFFF, 'dimgray': 0x696969, 'dimgrey': 0x696969, 'dodgerblue': 0x1E90FF, 'firebrick': 0xB22222,
  4713. 'floralwhite': 0xFFFAF0, 'forestgreen': 0x228B22, 'fuchsia': 0xFF00FF, 'gainsboro': 0xDCDCDC, 'ghostwhite': 0xF8F8FF, 'gold': 0xFFD700,
  4714. 'goldenrod': 0xDAA520, 'gray': 0x808080, 'green': 0x008000, 'greenyellow': 0xADFF2F, 'grey': 0x808080, 'honeydew': 0xF0FFF0, 'hotpink': 0xFF69B4,
  4715. 'indianred': 0xCD5C5C, 'indigo': 0x4B0082, 'ivory': 0xFFFFF0, 'khaki': 0xF0E68C, 'lavender': 0xE6E6FA, 'lavenderblush': 0xFFF0F5, 'lawngreen': 0x7CFC00,
  4716. 'lemonchiffon': 0xFFFACD, 'lightblue': 0xADD8E6, 'lightcoral': 0xF08080, 'lightcyan': 0xE0FFFF, 'lightgoldenrodyellow': 0xFAFAD2, 'lightgray': 0xD3D3D3,
  4717. 'lightgreen': 0x90EE90, 'lightgrey': 0xD3D3D3, 'lightpink': 0xFFB6C1, 'lightsalmon': 0xFFA07A, 'lightseagreen': 0x20B2AA, 'lightskyblue': 0x87CEFA,
  4718. 'lightslategray': 0x778899, 'lightslategrey': 0x778899, 'lightsteelblue': 0xB0C4DE, 'lightyellow': 0xFFFFE0, 'lime': 0x00FF00, 'limegreen': 0x32CD32,
  4719. 'linen': 0xFAF0E6, 'magenta': 0xFF00FF, 'maroon': 0x800000, 'mediumaquamarine': 0x66CDAA, 'mediumblue': 0x0000CD, 'mediumorchid': 0xBA55D3,
  4720. 'mediumpurple': 0x9370DB, 'mediumseagreen': 0x3CB371, 'mediumslateblue': 0x7B68EE, 'mediumspringgreen': 0x00FA9A, 'mediumturquoise': 0x48D1CC,
  4721. 'mediumvioletred': 0xC71585, 'midnightblue': 0x191970, 'mintcream': 0xF5FFFA, 'mistyrose': 0xFFE4E1, 'moccasin': 0xFFE4B5, 'navajowhite': 0xFFDEAD,
  4722. 'navy': 0x000080, 'oldlace': 0xFDF5E6, 'olive': 0x808000, 'olivedrab': 0x6B8E23, 'orange': 0xFFA500, 'orangered': 0xFF4500, 'orchid': 0xDA70D6,
  4723. 'palegoldenrod': 0xEEE8AA, 'palegreen': 0x98FB98, 'paleturquoise': 0xAFEEEE, 'palevioletred': 0xDB7093, 'papayawhip': 0xFFEFD5, 'peachpuff': 0xFFDAB9,
  4724. 'peru': 0xCD853F, 'pink': 0xFFC0CB, 'plum': 0xDDA0DD, 'powderblue': 0xB0E0E6, 'purple': 0x800080, 'rebeccapurple': 0x663399, 'red': 0xFF0000, 'rosybrown': 0xBC8F8F,
  4725. 'royalblue': 0x4169E1, 'saddlebrown': 0x8B4513, 'salmon': 0xFA8072, 'sandybrown': 0xF4A460, 'seagreen': 0x2E8B57, 'seashell': 0xFFF5EE,
  4726. 'sienna': 0xA0522D, 'silver': 0xC0C0C0, 'skyblue': 0x87CEEB, 'slateblue': 0x6A5ACD, 'slategray': 0x708090, 'slategrey': 0x708090, 'snow': 0xFFFAFA,
  4727. 'springgreen': 0x00FF7F, 'steelblue': 0x4682B4, 'tan': 0xD2B48C, 'teal': 0x008080, 'thistle': 0xD8BFD8, 'tomato': 0xFF6347, 'turquoise': 0x40E0D0,
  4728. 'violet': 0xEE82EE, 'wheat': 0xF5DEB3, 'white': 0xFFFFFF, 'whitesmoke': 0xF5F5F5, 'yellow': 0xFFFF00, 'yellowgreen': 0x9ACD32 };
  4729. function Color( r, g, b ) {
  4730. if ( g === undefined && b === undefined ) {
  4731. // r is THREE.Color, hex or string
  4732. return this.set( r );
  4733. }
  4734. return this.setRGB( r, g, b );
  4735. }
  4736. function hue2rgb( p, q, t ) {
  4737. if ( t < 0 ) t += 1;
  4738. if ( t > 1 ) t -= 1;
  4739. if ( t < 1 / 6 ) return p + ( q - p ) * 6 * t;
  4740. if ( t < 1 / 2 ) return q;
  4741. if ( t < 2 / 3 ) return p + ( q - p ) * 6 * ( 2 / 3 - t );
  4742. return p;
  4743. }
  4744. function SRGBToLinear( c ) {
  4745. return ( c < 0.04045 ) ? c * 0.0773993808 : Math.pow( c * 0.9478672986 + 0.0521327014, 2.4 );
  4746. }
  4747. function LinearToSRGB( c ) {
  4748. return ( c < 0.0031308 ) ? c * 12.92 : 1.055 * ( Math.pow( c, 0.41666 ) ) - 0.055;
  4749. }
  4750. Object.assign( Color.prototype, {
  4751. isColor: true,
  4752. r: 1, g: 1, b: 1,
  4753. set: function ( value ) {
  4754. if ( value && value.isColor ) {
  4755. this.copy( value );
  4756. } else if ( typeof value === 'number' ) {
  4757. this.setHex( value );
  4758. } else if ( typeof value === 'string' ) {
  4759. this.setStyle( value );
  4760. }
  4761. return this;
  4762. },
  4763. setScalar: function ( scalar ) {
  4764. this.r = scalar;
  4765. this.g = scalar;
  4766. this.b = scalar;
  4767. return this;
  4768. },
  4769. setHex: function ( hex ) {
  4770. hex = Math.floor( hex );
  4771. this.r = ( hex >> 16 & 255 ) / 255;
  4772. this.g = ( hex >> 8 & 255 ) / 255;
  4773. this.b = ( hex & 255 ) / 255;
  4774. return this;
  4775. },
  4776. setRGB: function ( r, g, b ) {
  4777. this.r = r;
  4778. this.g = g;
  4779. this.b = b;
  4780. return this;
  4781. },
  4782. setHSL: function ( h, s, l ) {
  4783. // h,s,l ranges are in 0.0 - 1.0
  4784. h = _Math.euclideanModulo( h, 1 );
  4785. s = _Math.clamp( s, 0, 1 );
  4786. l = _Math.clamp( l, 0, 1 );
  4787. if ( s === 0 ) {
  4788. this.r = this.g = this.b = l;
  4789. } else {
  4790. var p = l <= 0.5 ? l * ( 1 + s ) : l + s - ( l * s );
  4791. var q = ( 2 * l ) - p;
  4792. this.r = hue2rgb( q, p, h + 1 / 3 );
  4793. this.g = hue2rgb( q, p, h );
  4794. this.b = hue2rgb( q, p, h - 1 / 3 );
  4795. }
  4796. return this;
  4797. },
  4798. setStyle: function ( style ) {
  4799. function handleAlpha( string ) {
  4800. if ( string === undefined ) return;
  4801. if ( parseFloat( string ) < 1 ) {
  4802. console.warn( 'THREE.Color: Alpha component of ' + style + ' will be ignored.' );
  4803. }
  4804. }
  4805. var m;
  4806. if ( m = /^((?:rgb|hsl)a?)\(\s*([^\)]*)\)/.exec( style ) ) {
  4807. // rgb / hsl
  4808. var color;
  4809. var name = m[ 1 ];
  4810. var components = m[ 2 ];
  4811. switch ( name ) {
  4812. case 'rgb':
  4813. case 'rgba':
  4814. if ( color = /^(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec( components ) ) {
  4815. // rgb(255,0,0) rgba(255,0,0,0.5)
  4816. this.r = Math.min( 255, parseInt( color[ 1 ], 10 ) ) / 255;
  4817. this.g = Math.min( 255, parseInt( color[ 2 ], 10 ) ) / 255;
  4818. this.b = Math.min( 255, parseInt( color[ 3 ], 10 ) ) / 255;
  4819. handleAlpha( color[ 5 ] );
  4820. return this;
  4821. }
  4822. if ( color = /^(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec( components ) ) {
  4823. // rgb(100%,0%,0%) rgba(100%,0%,0%,0.5)
  4824. this.r = Math.min( 100, parseInt( color[ 1 ], 10 ) ) / 100;
  4825. this.g = Math.min( 100, parseInt( color[ 2 ], 10 ) ) / 100;
  4826. this.b = Math.min( 100, parseInt( color[ 3 ], 10 ) ) / 100;
  4827. handleAlpha( color[ 5 ] );
  4828. return this;
  4829. }
  4830. break;
  4831. case 'hsl':
  4832. case 'hsla':
  4833. if ( color = /^([0-9]*\.?[0-9]+)\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec( components ) ) {
  4834. // hsl(120,50%,50%) hsla(120,50%,50%,0.5)
  4835. var h = parseFloat( color[ 1 ] ) / 360;
  4836. var s = parseInt( color[ 2 ], 10 ) / 100;
  4837. var l = parseInt( color[ 3 ], 10 ) / 100;
  4838. handleAlpha( color[ 5 ] );
  4839. return this.setHSL( h, s, l );
  4840. }
  4841. break;
  4842. }
  4843. } else if ( m = /^\#([A-Fa-f0-9]+)$/.exec( style ) ) {
  4844. // hex color
  4845. var hex = m[ 1 ];
  4846. var size = hex.length;
  4847. if ( size === 3 ) {
  4848. // #ff0
  4849. this.r = parseInt( hex.charAt( 0 ) + hex.charAt( 0 ), 16 ) / 255;
  4850. this.g = parseInt( hex.charAt( 1 ) + hex.charAt( 1 ), 16 ) / 255;
  4851. this.b = parseInt( hex.charAt( 2 ) + hex.charAt( 2 ), 16 ) / 255;
  4852. return this;
  4853. } else if ( size === 6 ) {
  4854. // #ff0000
  4855. this.r = parseInt( hex.charAt( 0 ) + hex.charAt( 1 ), 16 ) / 255;
  4856. this.g = parseInt( hex.charAt( 2 ) + hex.charAt( 3 ), 16 ) / 255;
  4857. this.b = parseInt( hex.charAt( 4 ) + hex.charAt( 5 ), 16 ) / 255;
  4858. return this;
  4859. }
  4860. }
  4861. if ( style && style.length > 0 ) {
  4862. // color keywords
  4863. var hex = ColorKeywords[ style ];
  4864. if ( hex !== undefined ) {
  4865. // red
  4866. this.setHex( hex );
  4867. } else {
  4868. // unknown color
  4869. console.warn( 'THREE.Color: Unknown color ' + style );
  4870. }
  4871. }
  4872. return this;
  4873. },
  4874. clone: function () {
  4875. return new this.constructor( this.r, this.g, this.b );
  4876. },
  4877. copy: function ( color ) {
  4878. this.r = color.r;
  4879. this.g = color.g;
  4880. this.b = color.b;
  4881. return this;
  4882. },
  4883. copyGammaToLinear: function ( color, gammaFactor ) {
  4884. if ( gammaFactor === undefined ) gammaFactor = 2.0;
  4885. this.r = Math.pow( color.r, gammaFactor );
  4886. this.g = Math.pow( color.g, gammaFactor );
  4887. this.b = Math.pow( color.b, gammaFactor );
  4888. return this;
  4889. },
  4890. copyLinearToGamma: function ( color, gammaFactor ) {
  4891. if ( gammaFactor === undefined ) gammaFactor = 2.0;
  4892. var safeInverse = ( gammaFactor > 0 ) ? ( 1.0 / gammaFactor ) : 1.0;
  4893. this.r = Math.pow( color.r, safeInverse );
  4894. this.g = Math.pow( color.g, safeInverse );
  4895. this.b = Math.pow( color.b, safeInverse );
  4896. return this;
  4897. },
  4898. convertGammaToLinear: function ( gammaFactor ) {
  4899. this.copyGammaToLinear( this, gammaFactor );
  4900. return this;
  4901. },
  4902. convertLinearToGamma: function ( gammaFactor ) {
  4903. this.copyLinearToGamma( this, gammaFactor );
  4904. return this;
  4905. },
  4906. copySRGBToLinear: function ( color ) {
  4907. this.r = SRGBToLinear( color.r );
  4908. this.g = SRGBToLinear( color.g );
  4909. this.b = SRGBToLinear( color.b );
  4910. return this;
  4911. },
  4912. copyLinearToSRGB: function ( color ) {
  4913. this.r = LinearToSRGB( color.r );
  4914. this.g = LinearToSRGB( color.g );
  4915. this.b = LinearToSRGB( color.b );
  4916. return this;
  4917. },
  4918. convertSRGBToLinear: function () {
  4919. this.copySRGBToLinear( this );
  4920. return this;
  4921. },
  4922. convertLinearToSRGB: function () {
  4923. this.copyLinearToSRGB( this );
  4924. return this;
  4925. },
  4926. getHex: function () {
  4927. return ( this.r * 255 ) << 16 ^ ( this.g * 255 ) << 8 ^ ( this.b * 255 ) << 0;
  4928. },
  4929. getHexString: function () {
  4930. return ( '000000' + this.getHex().toString( 16 ) ).slice( - 6 );
  4931. },
  4932. getHSL: function ( target ) {
  4933. // h,s,l ranges are in 0.0 - 1.0
  4934. if ( target === undefined ) {
  4935. console.warn( 'THREE.Color: .getHSL() target is now required' );
  4936. target = { h: 0, s: 0, l: 0 };
  4937. }
  4938. var r = this.r, g = this.g, b = this.b;
  4939. var max = Math.max( r, g, b );
  4940. var min = Math.min( r, g, b );
  4941. var hue, saturation;
  4942. var lightness = ( min + max ) / 2.0;
  4943. if ( min === max ) {
  4944. hue = 0;
  4945. saturation = 0;
  4946. } else {
  4947. var delta = max - min;
  4948. saturation = lightness <= 0.5 ? delta / ( max + min ) : delta / ( 2 - max - min );
  4949. switch ( max ) {
  4950. case r: hue = ( g - b ) / delta + ( g < b ? 6 : 0 ); break;
  4951. case g: hue = ( b - r ) / delta + 2; break;
  4952. case b: hue = ( r - g ) / delta + 4; break;
  4953. }
  4954. hue /= 6;
  4955. }
  4956. target.h = hue;
  4957. target.s = saturation;
  4958. target.l = lightness;
  4959. return target;
  4960. },
  4961. getStyle: function () {
  4962. return 'rgb(' + ( ( this.r * 255 ) | 0 ) + ',' + ( ( this.g * 255 ) | 0 ) + ',' + ( ( this.b * 255 ) | 0 ) + ')';
  4963. },
  4964. offsetHSL: function () {
  4965. var hsl = {};
  4966. return function ( h, s, l ) {
  4967. this.getHSL( hsl );
  4968. hsl.h += h; hsl.s += s; hsl.l += l;
  4969. this.setHSL( hsl.h, hsl.s, hsl.l );
  4970. return this;
  4971. };
  4972. }(),
  4973. add: function ( color ) {
  4974. this.r += color.r;
  4975. this.g += color.g;
  4976. this.b += color.b;
  4977. return this;
  4978. },
  4979. addColors: function ( color1, color2 ) {
  4980. this.r = color1.r + color2.r;
  4981. this.g = color1.g + color2.g;
  4982. this.b = color1.b + color2.b;
  4983. return this;
  4984. },
  4985. addScalar: function ( s ) {
  4986. this.r += s;
  4987. this.g += s;
  4988. this.b += s;
  4989. return this;
  4990. },
  4991. sub: function ( color ) {
  4992. this.r = Math.max( 0, this.r - color.r );
  4993. this.g = Math.max( 0, this.g - color.g );
  4994. this.b = Math.max( 0, this.b - color.b );
  4995. return this;
  4996. },
  4997. multiply: function ( color ) {
  4998. this.r *= color.r;
  4999. this.g *= color.g;
  5000. this.b *= color.b;
  5001. return this;
  5002. },
  5003. multiplyScalar: function ( s ) {
  5004. this.r *= s;
  5005. this.g *= s;
  5006. this.b *= s;
  5007. return this;
  5008. },
  5009. lerp: function ( color, alpha ) {
  5010. this.r += ( color.r - this.r ) * alpha;
  5011. this.g += ( color.g - this.g ) * alpha;
  5012. this.b += ( color.b - this.b ) * alpha;
  5013. return this;
  5014. },
  5015. lerpHSL: function () {
  5016. var hslA = { h: 0, s: 0, l: 0 };
  5017. var hslB = { h: 0, s: 0, l: 0 };
  5018. return function lerpHSL( color, alpha ) {
  5019. this.getHSL( hslA );
  5020. color.getHSL( hslB );
  5021. var h = _Math.lerp( hslA.h, hslB.h, alpha );
  5022. var s = _Math.lerp( hslA.s, hslB.s, alpha );
  5023. var l = _Math.lerp( hslA.l, hslB.l, alpha );
  5024. this.setHSL( h, s, l );
  5025. return this;
  5026. };
  5027. }(),
  5028. equals: function ( c ) {
  5029. return ( c.r === this.r ) && ( c.g === this.g ) && ( c.b === this.b );
  5030. },
  5031. fromArray: function ( array, offset ) {
  5032. if ( offset === undefined ) offset = 0;
  5033. this.r = array[ offset ];
  5034. this.g = array[ offset + 1 ];
  5035. this.b = array[ offset + 2 ];
  5036. return this;
  5037. },
  5038. toArray: function ( array, offset ) {
  5039. if ( array === undefined ) array = [];
  5040. if ( offset === undefined ) offset = 0;
  5041. array[ offset ] = this.r;
  5042. array[ offset + 1 ] = this.g;
  5043. array[ offset + 2 ] = this.b;
  5044. return array;
  5045. },
  5046. toJSON: function () {
  5047. return this.getHex();
  5048. }
  5049. } );
  5050. /**
  5051. * @author mrdoob / http://mrdoob.com/
  5052. * @author alteredq / http://alteredqualia.com/
  5053. */
  5054. function Face3( a, b, c, normal, color, materialIndex ) {
  5055. this.a = a;
  5056. this.b = b;
  5057. this.c = c;
  5058. this.normal = ( normal && normal.isVector3 ) ? normal : new Vector3();
  5059. this.vertexNormals = Array.isArray( normal ) ? normal : [];
  5060. this.color = ( color && color.isColor ) ? color : new Color();
  5061. this.vertexColors = Array.isArray( color ) ? color : [];
  5062. this.materialIndex = materialIndex !== undefined ? materialIndex : 0;
  5063. }
  5064. Object.assign( Face3.prototype, {
  5065. clone: function () {
  5066. return new this.constructor().copy( this );
  5067. },
  5068. copy: function ( source ) {
  5069. this.a = source.a;
  5070. this.b = source.b;
  5071. this.c = source.c;
  5072. this.normal.copy( source.normal );
  5073. this.color.copy( source.color );
  5074. this.materialIndex = source.materialIndex;
  5075. for ( var i = 0, il = source.vertexNormals.length; i < il; i ++ ) {
  5076. this.vertexNormals[ i ] = source.vertexNormals[ i ].clone();
  5077. }
  5078. for ( var i = 0, il = source.vertexColors.length; i < il; i ++ ) {
  5079. this.vertexColors[ i ] = source.vertexColors[ i ].clone();
  5080. }
  5081. return this;
  5082. }
  5083. } );
  5084. /**
  5085. * @author mrdoob / http://mrdoob.com/
  5086. * @author alteredq / http://alteredqualia.com/
  5087. */
  5088. var materialId = 0;
  5089. function Material() {
  5090. Object.defineProperty( this, 'id', { value: materialId ++ } );
  5091. this.uuid = _Math.generateUUID();
  5092. this.name = '';
  5093. this.type = 'Material';
  5094. this.fog = true;
  5095. this.lights = true;
  5096. this.blending = NormalBlending;
  5097. this.side = FrontSide;
  5098. this.flatShading = false;
  5099. this.vertexTangents = false;
  5100. this.vertexColors = NoColors; // THREE.NoColors, THREE.VertexColors, THREE.FaceColors
  5101. this.opacity = 1;
  5102. this.transparent = false;
  5103. this.blendSrc = SrcAlphaFactor;
  5104. this.blendDst = OneMinusSrcAlphaFactor;
  5105. this.blendEquation = AddEquation;
  5106. this.blendSrcAlpha = null;
  5107. this.blendDstAlpha = null;
  5108. this.blendEquationAlpha = null;
  5109. this.depthFunc = LessEqualDepth;
  5110. this.depthTest = true;
  5111. this.depthWrite = true;
  5112. this.stencilFunc = AlwaysStencilFunc;
  5113. this.stencilRef = 0;
  5114. this.stencilMask = 0xff;
  5115. this.stencilFail = KeepStencilOp;
  5116. this.stencilZFail = KeepStencilOp;
  5117. this.stencilZPass = KeepStencilOp;
  5118. this.stencilWrite = false;
  5119. this.clippingPlanes = null;
  5120. this.clipIntersection = false;
  5121. this.clipShadows = false;
  5122. this.shadowSide = null;
  5123. this.colorWrite = true;
  5124. this.precision = null; // override the renderer's default precision for this material
  5125. this.polygonOffset = false;
  5126. this.polygonOffsetFactor = 0;
  5127. this.polygonOffsetUnits = 0;
  5128. this.dithering = false;
  5129. this.alphaTest = 0;
  5130. this.premultipliedAlpha = false;
  5131. this.visible = true;
  5132. this.userData = {};
  5133. this.needsUpdate = true;
  5134. }
  5135. Material.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  5136. constructor: Material,
  5137. isMaterial: true,
  5138. onBeforeCompile: function () {},
  5139. setValues: function ( values ) {
  5140. if ( values === undefined ) return;
  5141. for ( var key in values ) {
  5142. var newValue = values[ key ];
  5143. if ( newValue === undefined ) {
  5144. console.warn( "THREE.Material: '" + key + "' parameter is undefined." );
  5145. continue;
  5146. }
  5147. // for backward compatability if shading is set in the constructor
  5148. if ( key === 'shading' ) {
  5149. console.warn( 'THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.' );
  5150. this.flatShading = ( newValue === FlatShading ) ? true : false;
  5151. continue;
  5152. }
  5153. var currentValue = this[ key ];
  5154. if ( currentValue === undefined ) {
  5155. console.warn( "THREE." + this.type + ": '" + key + "' is not a property of this material." );
  5156. continue;
  5157. }
  5158. if ( currentValue && currentValue.isColor ) {
  5159. currentValue.set( newValue );
  5160. } else if ( ( currentValue && currentValue.isVector3 ) && ( newValue && newValue.isVector3 ) ) {
  5161. currentValue.copy( newValue );
  5162. } else {
  5163. this[ key ] = newValue;
  5164. }
  5165. }
  5166. },
  5167. toJSON: function ( meta ) {
  5168. var isRoot = ( meta === undefined || typeof meta === 'string' );
  5169. if ( isRoot ) {
  5170. meta = {
  5171. textures: {},
  5172. images: {}
  5173. };
  5174. }
  5175. var data = {
  5176. metadata: {
  5177. version: 4.5,
  5178. type: 'Material',
  5179. generator: 'Material.toJSON'
  5180. }
  5181. };
  5182. // standard Material serialization
  5183. data.uuid = this.uuid;
  5184. data.type = this.type;
  5185. if ( this.name !== '' ) data.name = this.name;
  5186. if ( this.color && this.color.isColor ) data.color = this.color.getHex();
  5187. if ( this.roughness !== undefined ) data.roughness = this.roughness;
  5188. if ( this.metalness !== undefined ) data.metalness = this.metalness;
  5189. if ( this.emissive && this.emissive.isColor ) data.emissive = this.emissive.getHex();
  5190. if ( this.emissiveIntensity && this.emissiveIntensity !== 1 ) data.emissiveIntensity = this.emissiveIntensity;
  5191. if ( this.specular && this.specular.isColor ) data.specular = this.specular.getHex();
  5192. if ( this.shininess !== undefined ) data.shininess = this.shininess;
  5193. if ( this.clearCoat !== undefined ) data.clearCoat = this.clearCoat;
  5194. if ( this.clearCoatRoughness !== undefined ) data.clearCoatRoughness = this.clearCoatRoughness;
  5195. if ( this.map && this.map.isTexture ) data.map = this.map.toJSON( meta ).uuid;
  5196. if ( this.matcap && this.matcap.isTexture ) data.matcap = this.matcap.toJSON( meta ).uuid;
  5197. if ( this.alphaMap && this.alphaMap.isTexture ) data.alphaMap = this.alphaMap.toJSON( meta ).uuid;
  5198. if ( this.lightMap && this.lightMap.isTexture ) data.lightMap = this.lightMap.toJSON( meta ).uuid;
  5199. if ( this.aoMap && this.aoMap.isTexture ) {
  5200. data.aoMap = this.aoMap.toJSON( meta ).uuid;
  5201. data.aoMapIntensity = this.aoMapIntensity;
  5202. }
  5203. if ( this.bumpMap && this.bumpMap.isTexture ) {
  5204. data.bumpMap = this.bumpMap.toJSON( meta ).uuid;
  5205. data.bumpScale = this.bumpScale;
  5206. }
  5207. if ( this.normalMap && this.normalMap.isTexture ) {
  5208. data.normalMap = this.normalMap.toJSON( meta ).uuid;
  5209. data.normalMapType = this.normalMapType;
  5210. data.normalScale = this.normalScale.toArray();
  5211. }
  5212. if ( this.displacementMap && this.displacementMap.isTexture ) {
  5213. data.displacementMap = this.displacementMap.toJSON( meta ).uuid;
  5214. data.displacementScale = this.displacementScale;
  5215. data.displacementBias = this.displacementBias;
  5216. }
  5217. if ( this.roughnessMap && this.roughnessMap.isTexture ) data.roughnessMap = this.roughnessMap.toJSON( meta ).uuid;
  5218. if ( this.metalnessMap && this.metalnessMap.isTexture ) data.metalnessMap = this.metalnessMap.toJSON( meta ).uuid;
  5219. if ( this.emissiveMap && this.emissiveMap.isTexture ) data.emissiveMap = this.emissiveMap.toJSON( meta ).uuid;
  5220. if ( this.specularMap && this.specularMap.isTexture ) data.specularMap = this.specularMap.toJSON( meta ).uuid;
  5221. if ( this.envMap && this.envMap.isTexture ) {
  5222. data.envMap = this.envMap.toJSON( meta ).uuid;
  5223. data.reflectivity = this.reflectivity; // Scale behind envMap
  5224. data.refractionRatio = this.refractionRatio;
  5225. if ( this.combine !== undefined ) data.combine = this.combine;
  5226. if ( this.envMapIntensity !== undefined ) data.envMapIntensity = this.envMapIntensity;
  5227. }
  5228. if ( this.gradientMap && this.gradientMap.isTexture ) {
  5229. data.gradientMap = this.gradientMap.toJSON( meta ).uuid;
  5230. }
  5231. if ( this.size !== undefined ) data.size = this.size;
  5232. if ( this.sizeAttenuation !== undefined ) data.sizeAttenuation = this.sizeAttenuation;
  5233. if ( this.blending !== NormalBlending ) data.blending = this.blending;
  5234. if ( this.flatShading === true ) data.flatShading = this.flatShading;
  5235. if ( this.side !== FrontSide ) data.side = this.side;
  5236. if ( this.vertexColors !== NoColors ) data.vertexColors = this.vertexColors;
  5237. if ( this.opacity < 1 ) data.opacity = this.opacity;
  5238. if ( this.transparent === true ) data.transparent = this.transparent;
  5239. data.depthFunc = this.depthFunc;
  5240. data.depthTest = this.depthTest;
  5241. data.depthWrite = this.depthWrite;
  5242. data.stencilWrite = this.stencilWrite;
  5243. data.stencilFunc = this.stencilFunc;
  5244. data.stencilRef = this.stencilRef;
  5245. data.stencilMask = this.stencilMask;
  5246. data.stencilFail = this.stencilFail;
  5247. data.stencilZFail = this.stencilZFail;
  5248. data.stencilZPass = this.stencilZPass;
  5249. // rotation (SpriteMaterial)
  5250. if ( this.rotation && this.rotation !== 0 ) data.rotation = this.rotation;
  5251. if ( this.polygonOffset === true ) data.polygonOffset = true;
  5252. if ( this.polygonOffsetFactor !== 0 ) data.polygonOffsetFactor = this.polygonOffsetFactor;
  5253. if ( this.polygonOffsetUnits !== 0 ) data.polygonOffsetUnits = this.polygonOffsetUnits;
  5254. if ( this.linewidth && this.linewidth !== 1 ) data.linewidth = this.linewidth;
  5255. if ( this.dashSize !== undefined ) data.dashSize = this.dashSize;
  5256. if ( this.gapSize !== undefined ) data.gapSize = this.gapSize;
  5257. if ( this.scale !== undefined ) data.scale = this.scale;
  5258. if ( this.dithering === true ) data.dithering = true;
  5259. if ( this.alphaTest > 0 ) data.alphaTest = this.alphaTest;
  5260. if ( this.premultipliedAlpha === true ) data.premultipliedAlpha = this.premultipliedAlpha;
  5261. if ( this.wireframe === true ) data.wireframe = this.wireframe;
  5262. if ( this.wireframeLinewidth > 1 ) data.wireframeLinewidth = this.wireframeLinewidth;
  5263. if ( this.wireframeLinecap !== 'round' ) data.wireframeLinecap = this.wireframeLinecap;
  5264. if ( this.wireframeLinejoin !== 'round' ) data.wireframeLinejoin = this.wireframeLinejoin;
  5265. if ( this.morphTargets === true ) data.morphTargets = true;
  5266. if ( this.morphNormals === true ) data.morphNormals = true;
  5267. if ( this.skinning === true ) data.skinning = true;
  5268. if ( this.visible === false ) data.visible = false;
  5269. if ( JSON.stringify( this.userData ) !== '{}' ) data.userData = this.userData;
  5270. // TODO: Copied from Object3D.toJSON
  5271. function extractFromCache( cache ) {
  5272. var values = [];
  5273. for ( var key in cache ) {
  5274. var data = cache[ key ];
  5275. delete data.metadata;
  5276. values.push( data );
  5277. }
  5278. return values;
  5279. }
  5280. if ( isRoot ) {
  5281. var textures = extractFromCache( meta.textures );
  5282. var images = extractFromCache( meta.images );
  5283. if ( textures.length > 0 ) data.textures = textures;
  5284. if ( images.length > 0 ) data.images = images;
  5285. }
  5286. return data;
  5287. },
  5288. clone: function () {
  5289. return new this.constructor().copy( this );
  5290. },
  5291. copy: function ( source ) {
  5292. this.name = source.name;
  5293. this.fog = source.fog;
  5294. this.lights = source.lights;
  5295. this.blending = source.blending;
  5296. this.side = source.side;
  5297. this.flatShading = source.flatShading;
  5298. this.vertexColors = source.vertexColors;
  5299. this.opacity = source.opacity;
  5300. this.transparent = source.transparent;
  5301. this.blendSrc = source.blendSrc;
  5302. this.blendDst = source.blendDst;
  5303. this.blendEquation = source.blendEquation;
  5304. this.blendSrcAlpha = source.blendSrcAlpha;
  5305. this.blendDstAlpha = source.blendDstAlpha;
  5306. this.blendEquationAlpha = source.blendEquationAlpha;
  5307. this.depthFunc = source.depthFunc;
  5308. this.depthTest = source.depthTest;
  5309. this.depthWrite = source.depthWrite;
  5310. this.stencilWrite = source.stencilWrite;
  5311. this.stencilFunc = source.stencilFunc;
  5312. this.stencilRef = source.stencilRef;
  5313. this.stencilMask = source.stencilMask;
  5314. this.stencilFail = source.stencilFail;
  5315. this.stencilZFail = source.stencilZFail;
  5316. this.stencilZPass = source.stencilZPass;
  5317. this.colorWrite = source.colorWrite;
  5318. this.precision = source.precision;
  5319. this.polygonOffset = source.polygonOffset;
  5320. this.polygonOffsetFactor = source.polygonOffsetFactor;
  5321. this.polygonOffsetUnits = source.polygonOffsetUnits;
  5322. this.dithering = source.dithering;
  5323. this.alphaTest = source.alphaTest;
  5324. this.premultipliedAlpha = source.premultipliedAlpha;
  5325. this.visible = source.visible;
  5326. this.userData = JSON.parse( JSON.stringify( source.userData ) );
  5327. this.clipShadows = source.clipShadows;
  5328. this.clipIntersection = source.clipIntersection;
  5329. var srcPlanes = source.clippingPlanes,
  5330. dstPlanes = null;
  5331. if ( srcPlanes !== null ) {
  5332. var n = srcPlanes.length;
  5333. dstPlanes = new Array( n );
  5334. for ( var i = 0; i !== n; ++ i )
  5335. dstPlanes[ i ] = srcPlanes[ i ].clone();
  5336. }
  5337. this.clippingPlanes = dstPlanes;
  5338. this.shadowSide = source.shadowSide;
  5339. return this;
  5340. },
  5341. dispose: function () {
  5342. this.dispatchEvent( { type: 'dispose' } );
  5343. }
  5344. } );
  5345. /**
  5346. * @author mrdoob / http://mrdoob.com/
  5347. * @author alteredq / http://alteredqualia.com/
  5348. *
  5349. * parameters = {
  5350. * color: <hex>,
  5351. * opacity: <float>,
  5352. * map: new THREE.Texture( <Image> ),
  5353. *
  5354. * lightMap: new THREE.Texture( <Image> ),
  5355. * lightMapIntensity: <float>
  5356. *
  5357. * aoMap: new THREE.Texture( <Image> ),
  5358. * aoMapIntensity: <float>
  5359. *
  5360. * specularMap: new THREE.Texture( <Image> ),
  5361. *
  5362. * alphaMap: new THREE.Texture( <Image> ),
  5363. *
  5364. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  5365. * combine: THREE.Multiply,
  5366. * reflectivity: <float>,
  5367. * refractionRatio: <float>,
  5368. *
  5369. * depthTest: <bool>,
  5370. * depthWrite: <bool>,
  5371. *
  5372. * wireframe: <boolean>,
  5373. * wireframeLinewidth: <float>,
  5374. *
  5375. * skinning: <bool>,
  5376. * morphTargets: <bool>
  5377. * }
  5378. */
  5379. function MeshBasicMaterial( parameters ) {
  5380. Material.call( this );
  5381. this.type = 'MeshBasicMaterial';
  5382. this.color = new Color( 0xffffff ); // emissive
  5383. this.map = null;
  5384. this.lightMap = null;
  5385. this.lightMapIntensity = 1.0;
  5386. this.aoMap = null;
  5387. this.aoMapIntensity = 1.0;
  5388. this.specularMap = null;
  5389. this.alphaMap = null;
  5390. this.envMap = null;
  5391. this.combine = MultiplyOperation;
  5392. this.reflectivity = 1;
  5393. this.refractionRatio = 0.98;
  5394. this.wireframe = false;
  5395. this.wireframeLinewidth = 1;
  5396. this.wireframeLinecap = 'round';
  5397. this.wireframeLinejoin = 'round';
  5398. this.skinning = false;
  5399. this.morphTargets = false;
  5400. this.lights = false;
  5401. this.setValues( parameters );
  5402. }
  5403. MeshBasicMaterial.prototype = Object.create( Material.prototype );
  5404. MeshBasicMaterial.prototype.constructor = MeshBasicMaterial;
  5405. MeshBasicMaterial.prototype.isMeshBasicMaterial = true;
  5406. MeshBasicMaterial.prototype.copy = function ( source ) {
  5407. Material.prototype.copy.call( this, source );
  5408. this.color.copy( source.color );
  5409. this.map = source.map;
  5410. this.lightMap = source.lightMap;
  5411. this.lightMapIntensity = source.lightMapIntensity;
  5412. this.aoMap = source.aoMap;
  5413. this.aoMapIntensity = source.aoMapIntensity;
  5414. this.specularMap = source.specularMap;
  5415. this.alphaMap = source.alphaMap;
  5416. this.envMap = source.envMap;
  5417. this.combine = source.combine;
  5418. this.reflectivity = source.reflectivity;
  5419. this.refractionRatio = source.refractionRatio;
  5420. this.wireframe = source.wireframe;
  5421. this.wireframeLinewidth = source.wireframeLinewidth;
  5422. this.wireframeLinecap = source.wireframeLinecap;
  5423. this.wireframeLinejoin = source.wireframeLinejoin;
  5424. this.skinning = source.skinning;
  5425. this.morphTargets = source.morphTargets;
  5426. return this;
  5427. };
  5428. /**
  5429. * @author mrdoob / http://mrdoob.com/
  5430. */
  5431. function BufferAttribute( array, itemSize, normalized ) {
  5432. if ( Array.isArray( array ) ) {
  5433. throw new TypeError( 'THREE.BufferAttribute: array should be a Typed Array.' );
  5434. }
  5435. this.name = '';
  5436. this.array = array;
  5437. this.itemSize = itemSize;
  5438. this.count = array !== undefined ? array.length / itemSize : 0;
  5439. this.normalized = normalized === true;
  5440. this.dynamic = false;
  5441. this.updateRange = { offset: 0, count: - 1 };
  5442. this.version = 0;
  5443. }
  5444. Object.defineProperty( BufferAttribute.prototype, 'needsUpdate', {
  5445. set: function ( value ) {
  5446. if ( value === true ) this.version ++;
  5447. }
  5448. } );
  5449. Object.assign( BufferAttribute.prototype, {
  5450. isBufferAttribute: true,
  5451. onUploadCallback: function () {},
  5452. setArray: function ( array ) {
  5453. if ( Array.isArray( array ) ) {
  5454. throw new TypeError( 'THREE.BufferAttribute: array should be a Typed Array.' );
  5455. }
  5456. this.count = array !== undefined ? array.length / this.itemSize : 0;
  5457. this.array = array;
  5458. return this;
  5459. },
  5460. setDynamic: function ( value ) {
  5461. this.dynamic = value;
  5462. return this;
  5463. },
  5464. copy: function ( source ) {
  5465. this.name = source.name;
  5466. this.array = new source.array.constructor( source.array );
  5467. this.itemSize = source.itemSize;
  5468. this.count = source.count;
  5469. this.normalized = source.normalized;
  5470. this.dynamic = source.dynamic;
  5471. return this;
  5472. },
  5473. copyAt: function ( index1, attribute, index2 ) {
  5474. index1 *= this.itemSize;
  5475. index2 *= attribute.itemSize;
  5476. for ( var i = 0, l = this.itemSize; i < l; i ++ ) {
  5477. this.array[ index1 + i ] = attribute.array[ index2 + i ];
  5478. }
  5479. return this;
  5480. },
  5481. copyArray: function ( array ) {
  5482. this.array.set( array );
  5483. return this;
  5484. },
  5485. copyColorsArray: function ( colors ) {
  5486. var array = this.array, offset = 0;
  5487. for ( var i = 0, l = colors.length; i < l; i ++ ) {
  5488. var color = colors[ i ];
  5489. if ( color === undefined ) {
  5490. console.warn( 'THREE.BufferAttribute.copyColorsArray(): color is undefined', i );
  5491. color = new Color();
  5492. }
  5493. array[ offset ++ ] = color.r;
  5494. array[ offset ++ ] = color.g;
  5495. array[ offset ++ ] = color.b;
  5496. }
  5497. return this;
  5498. },
  5499. copyVector2sArray: function ( vectors ) {
  5500. var array = this.array, offset = 0;
  5501. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  5502. var vector = vectors[ i ];
  5503. if ( vector === undefined ) {
  5504. console.warn( 'THREE.BufferAttribute.copyVector2sArray(): vector is undefined', i );
  5505. vector = new Vector2();
  5506. }
  5507. array[ offset ++ ] = vector.x;
  5508. array[ offset ++ ] = vector.y;
  5509. }
  5510. return this;
  5511. },
  5512. copyVector3sArray: function ( vectors ) {
  5513. var array = this.array, offset = 0;
  5514. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  5515. var vector = vectors[ i ];
  5516. if ( vector === undefined ) {
  5517. console.warn( 'THREE.BufferAttribute.copyVector3sArray(): vector is undefined', i );
  5518. vector = new Vector3();
  5519. }
  5520. array[ offset ++ ] = vector.x;
  5521. array[ offset ++ ] = vector.y;
  5522. array[ offset ++ ] = vector.z;
  5523. }
  5524. return this;
  5525. },
  5526. copyVector4sArray: function ( vectors ) {
  5527. var array = this.array, offset = 0;
  5528. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  5529. var vector = vectors[ i ];
  5530. if ( vector === undefined ) {
  5531. console.warn( 'THREE.BufferAttribute.copyVector4sArray(): vector is undefined', i );
  5532. vector = new Vector4();
  5533. }
  5534. array[ offset ++ ] = vector.x;
  5535. array[ offset ++ ] = vector.y;
  5536. array[ offset ++ ] = vector.z;
  5537. array[ offset ++ ] = vector.w;
  5538. }
  5539. return this;
  5540. },
  5541. set: function ( value, offset ) {
  5542. if ( offset === undefined ) offset = 0;
  5543. this.array.set( value, offset );
  5544. return this;
  5545. },
  5546. getX: function ( index ) {
  5547. return this.array[ index * this.itemSize ];
  5548. },
  5549. setX: function ( index, x ) {
  5550. this.array[ index * this.itemSize ] = x;
  5551. return this;
  5552. },
  5553. getY: function ( index ) {
  5554. return this.array[ index * this.itemSize + 1 ];
  5555. },
  5556. setY: function ( index, y ) {
  5557. this.array[ index * this.itemSize + 1 ] = y;
  5558. return this;
  5559. },
  5560. getZ: function ( index ) {
  5561. return this.array[ index * this.itemSize + 2 ];
  5562. },
  5563. setZ: function ( index, z ) {
  5564. this.array[ index * this.itemSize + 2 ] = z;
  5565. return this;
  5566. },
  5567. getW: function ( index ) {
  5568. return this.array[ index * this.itemSize + 3 ];
  5569. },
  5570. setW: function ( index, w ) {
  5571. this.array[ index * this.itemSize + 3 ] = w;
  5572. return this;
  5573. },
  5574. setXY: function ( index, x, y ) {
  5575. index *= this.itemSize;
  5576. this.array[ index + 0 ] = x;
  5577. this.array[ index + 1 ] = y;
  5578. return this;
  5579. },
  5580. setXYZ: function ( index, x, y, z ) {
  5581. index *= this.itemSize;
  5582. this.array[ index + 0 ] = x;
  5583. this.array[ index + 1 ] = y;
  5584. this.array[ index + 2 ] = z;
  5585. return this;
  5586. },
  5587. setXYZW: function ( index, x, y, z, w ) {
  5588. index *= this.itemSize;
  5589. this.array[ index + 0 ] = x;
  5590. this.array[ index + 1 ] = y;
  5591. this.array[ index + 2 ] = z;
  5592. this.array[ index + 3 ] = w;
  5593. return this;
  5594. },
  5595. onUpload: function ( callback ) {
  5596. this.onUploadCallback = callback;
  5597. return this;
  5598. },
  5599. clone: function () {
  5600. return new this.constructor( this.array, this.itemSize ).copy( this );
  5601. },
  5602. toJSON: function () {
  5603. return {
  5604. itemSize: this.itemSize,
  5605. type: this.array.constructor.name,
  5606. array: Array.prototype.slice.call( this.array ),
  5607. normalized: this.normalized
  5608. };
  5609. }
  5610. } );
  5611. //
  5612. function Int8BufferAttribute( array, itemSize, normalized ) {
  5613. BufferAttribute.call( this, new Int8Array( array ), itemSize, normalized );
  5614. }
  5615. Int8BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  5616. Int8BufferAttribute.prototype.constructor = Int8BufferAttribute;
  5617. function Uint8BufferAttribute( array, itemSize, normalized ) {
  5618. BufferAttribute.call( this, new Uint8Array( array ), itemSize, normalized );
  5619. }
  5620. Uint8BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  5621. Uint8BufferAttribute.prototype.constructor = Uint8BufferAttribute;
  5622. function Uint8ClampedBufferAttribute( array, itemSize, normalized ) {
  5623. BufferAttribute.call( this, new Uint8ClampedArray( array ), itemSize, normalized );
  5624. }
  5625. Uint8ClampedBufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  5626. Uint8ClampedBufferAttribute.prototype.constructor = Uint8ClampedBufferAttribute;
  5627. function Int16BufferAttribute( array, itemSize, normalized ) {
  5628. BufferAttribute.call( this, new Int16Array( array ), itemSize, normalized );
  5629. }
  5630. Int16BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  5631. Int16BufferAttribute.prototype.constructor = Int16BufferAttribute;
  5632. function Uint16BufferAttribute( array, itemSize, normalized ) {
  5633. BufferAttribute.call( this, new Uint16Array( array ), itemSize, normalized );
  5634. }
  5635. Uint16BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  5636. Uint16BufferAttribute.prototype.constructor = Uint16BufferAttribute;
  5637. function Int32BufferAttribute( array, itemSize, normalized ) {
  5638. BufferAttribute.call( this, new Int32Array( array ), itemSize, normalized );
  5639. }
  5640. Int32BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  5641. Int32BufferAttribute.prototype.constructor = Int32BufferAttribute;
  5642. function Uint32BufferAttribute( array, itemSize, normalized ) {
  5643. BufferAttribute.call( this, new Uint32Array( array ), itemSize, normalized );
  5644. }
  5645. Uint32BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  5646. Uint32BufferAttribute.prototype.constructor = Uint32BufferAttribute;
  5647. function Float32BufferAttribute( array, itemSize, normalized ) {
  5648. BufferAttribute.call( this, new Float32Array( array ), itemSize, normalized );
  5649. }
  5650. Float32BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  5651. Float32BufferAttribute.prototype.constructor = Float32BufferAttribute;
  5652. function Float64BufferAttribute( array, itemSize, normalized ) {
  5653. BufferAttribute.call( this, new Float64Array( array ), itemSize, normalized );
  5654. }
  5655. Float64BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  5656. Float64BufferAttribute.prototype.constructor = Float64BufferAttribute;
  5657. /**
  5658. * @author mrdoob / http://mrdoob.com/
  5659. */
  5660. function DirectGeometry() {
  5661. this.vertices = [];
  5662. this.normals = [];
  5663. this.colors = [];
  5664. this.uvs = [];
  5665. this.uvs2 = [];
  5666. this.groups = [];
  5667. this.morphTargets = {};
  5668. this.skinWeights = [];
  5669. this.skinIndices = [];
  5670. // this.lineDistances = [];
  5671. this.boundingBox = null;
  5672. this.boundingSphere = null;
  5673. // update flags
  5674. this.verticesNeedUpdate = false;
  5675. this.normalsNeedUpdate = false;
  5676. this.colorsNeedUpdate = false;
  5677. this.uvsNeedUpdate = false;
  5678. this.groupsNeedUpdate = false;
  5679. }
  5680. Object.assign( DirectGeometry.prototype, {
  5681. computeGroups: function ( geometry ) {
  5682. var group;
  5683. var groups = [];
  5684. var materialIndex = undefined;
  5685. var faces = geometry.faces;
  5686. for ( var i = 0; i < faces.length; i ++ ) {
  5687. var face = faces[ i ];
  5688. // materials
  5689. if ( face.materialIndex !== materialIndex ) {
  5690. materialIndex = face.materialIndex;
  5691. if ( group !== undefined ) {
  5692. group.count = ( i * 3 ) - group.start;
  5693. groups.push( group );
  5694. }
  5695. group = {
  5696. start: i * 3,
  5697. materialIndex: materialIndex
  5698. };
  5699. }
  5700. }
  5701. if ( group !== undefined ) {
  5702. group.count = ( i * 3 ) - group.start;
  5703. groups.push( group );
  5704. }
  5705. this.groups = groups;
  5706. },
  5707. fromGeometry: function ( geometry ) {
  5708. var faces = geometry.faces;
  5709. var vertices = geometry.vertices;
  5710. var faceVertexUvs = geometry.faceVertexUvs;
  5711. var hasFaceVertexUv = faceVertexUvs[ 0 ] && faceVertexUvs[ 0 ].length > 0;
  5712. var hasFaceVertexUv2 = faceVertexUvs[ 1 ] && faceVertexUvs[ 1 ].length > 0;
  5713. // morphs
  5714. var morphTargets = geometry.morphTargets;
  5715. var morphTargetsLength = morphTargets.length;
  5716. var morphTargetsPosition;
  5717. if ( morphTargetsLength > 0 ) {
  5718. morphTargetsPosition = [];
  5719. for ( var i = 0; i < morphTargetsLength; i ++ ) {
  5720. morphTargetsPosition[ i ] = {
  5721. name: morphTargets[ i ].name,
  5722. data: []
  5723. };
  5724. }
  5725. this.morphTargets.position = morphTargetsPosition;
  5726. }
  5727. var morphNormals = geometry.morphNormals;
  5728. var morphNormalsLength = morphNormals.length;
  5729. var morphTargetsNormal;
  5730. if ( morphNormalsLength > 0 ) {
  5731. morphTargetsNormal = [];
  5732. for ( var i = 0; i < morphNormalsLength; i ++ ) {
  5733. morphTargetsNormal[ i ] = {
  5734. name: morphNormals[ i ].name,
  5735. data: []
  5736. };
  5737. }
  5738. this.morphTargets.normal = morphTargetsNormal;
  5739. }
  5740. // skins
  5741. var skinIndices = geometry.skinIndices;
  5742. var skinWeights = geometry.skinWeights;
  5743. var hasSkinIndices = skinIndices.length === vertices.length;
  5744. var hasSkinWeights = skinWeights.length === vertices.length;
  5745. //
  5746. if ( vertices.length > 0 && faces.length === 0 ) {
  5747. console.error( 'THREE.DirectGeometry: Faceless geometries are not supported.' );
  5748. }
  5749. for ( var i = 0; i < faces.length; i ++ ) {
  5750. var face = faces[ i ];
  5751. this.vertices.push( vertices[ face.a ], vertices[ face.b ], vertices[ face.c ] );
  5752. var vertexNormals = face.vertexNormals;
  5753. if ( vertexNormals.length === 3 ) {
  5754. this.normals.push( vertexNormals[ 0 ], vertexNormals[ 1 ], vertexNormals[ 2 ] );
  5755. } else {
  5756. var normal = face.normal;
  5757. this.normals.push( normal, normal, normal );
  5758. }
  5759. var vertexColors = face.vertexColors;
  5760. if ( vertexColors.length === 3 ) {
  5761. this.colors.push( vertexColors[ 0 ], vertexColors[ 1 ], vertexColors[ 2 ] );
  5762. } else {
  5763. var color = face.color;
  5764. this.colors.push( color, color, color );
  5765. }
  5766. if ( hasFaceVertexUv === true ) {
  5767. var vertexUvs = faceVertexUvs[ 0 ][ i ];
  5768. if ( vertexUvs !== undefined ) {
  5769. this.uvs.push( vertexUvs[ 0 ], vertexUvs[ 1 ], vertexUvs[ 2 ] );
  5770. } else {
  5771. console.warn( 'THREE.DirectGeometry.fromGeometry(): Undefined vertexUv ', i );
  5772. this.uvs.push( new Vector2(), new Vector2(), new Vector2() );
  5773. }
  5774. }
  5775. if ( hasFaceVertexUv2 === true ) {
  5776. var vertexUvs = faceVertexUvs[ 1 ][ i ];
  5777. if ( vertexUvs !== undefined ) {
  5778. this.uvs2.push( vertexUvs[ 0 ], vertexUvs[ 1 ], vertexUvs[ 2 ] );
  5779. } else {
  5780. console.warn( 'THREE.DirectGeometry.fromGeometry(): Undefined vertexUv2 ', i );
  5781. this.uvs2.push( new Vector2(), new Vector2(), new Vector2() );
  5782. }
  5783. }
  5784. // morphs
  5785. for ( var j = 0; j < morphTargetsLength; j ++ ) {
  5786. var morphTarget = morphTargets[ j ].vertices;
  5787. morphTargetsPosition[ j ].data.push( morphTarget[ face.a ], morphTarget[ face.b ], morphTarget[ face.c ] );
  5788. }
  5789. for ( var j = 0; j < morphNormalsLength; j ++ ) {
  5790. var morphNormal = morphNormals[ j ].vertexNormals[ i ];
  5791. morphTargetsNormal[ j ].data.push( morphNormal.a, morphNormal.b, morphNormal.c );
  5792. }
  5793. // skins
  5794. if ( hasSkinIndices ) {
  5795. this.skinIndices.push( skinIndices[ face.a ], skinIndices[ face.b ], skinIndices[ face.c ] );
  5796. }
  5797. if ( hasSkinWeights ) {
  5798. this.skinWeights.push( skinWeights[ face.a ], skinWeights[ face.b ], skinWeights[ face.c ] );
  5799. }
  5800. }
  5801. this.computeGroups( geometry );
  5802. this.verticesNeedUpdate = geometry.verticesNeedUpdate;
  5803. this.normalsNeedUpdate = geometry.normalsNeedUpdate;
  5804. this.colorsNeedUpdate = geometry.colorsNeedUpdate;
  5805. this.uvsNeedUpdate = geometry.uvsNeedUpdate;
  5806. this.groupsNeedUpdate = geometry.groupsNeedUpdate;
  5807. if ( geometry.boundingSphere !== null ) {
  5808. this.boundingSphere = geometry.boundingSphere.clone();
  5809. }
  5810. if ( geometry.boundingBox !== null ) {
  5811. this.boundingBox = geometry.boundingBox.clone();
  5812. }
  5813. return this;
  5814. }
  5815. } );
  5816. /**
  5817. * @author mrdoob / http://mrdoob.com/
  5818. */
  5819. function arrayMax( array ) {
  5820. if ( array.length === 0 ) return - Infinity;
  5821. var max = array[ 0 ];
  5822. for ( var i = 1, l = array.length; i < l; ++ i ) {
  5823. if ( array[ i ] > max ) max = array[ i ];
  5824. }
  5825. return max;
  5826. }
  5827. /**
  5828. * @author alteredq / http://alteredqualia.com/
  5829. * @author mrdoob / http://mrdoob.com/
  5830. */
  5831. var bufferGeometryId = 1; // BufferGeometry uses odd numbers as Id
  5832. function BufferGeometry() {
  5833. Object.defineProperty( this, 'id', { value: bufferGeometryId += 2 } );
  5834. this.uuid = _Math.generateUUID();
  5835. this.name = '';
  5836. this.type = 'BufferGeometry';
  5837. this.index = null;
  5838. this.attributes = {};
  5839. this.morphAttributes = {};
  5840. this.groups = [];
  5841. this.boundingBox = null;
  5842. this.boundingSphere = null;
  5843. this.drawRange = { start: 0, count: Infinity };
  5844. this.userData = {};
  5845. }
  5846. BufferGeometry.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  5847. constructor: BufferGeometry,
  5848. isBufferGeometry: true,
  5849. getIndex: function () {
  5850. return this.index;
  5851. },
  5852. setIndex: function ( index ) {
  5853. if ( Array.isArray( index ) ) {
  5854. this.index = new ( arrayMax( index ) > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute )( index, 1 );
  5855. } else {
  5856. this.index = index;
  5857. }
  5858. },
  5859. addAttribute: function ( name, attribute ) {
  5860. if ( ! ( attribute && attribute.isBufferAttribute ) && ! ( attribute && attribute.isInterleavedBufferAttribute ) ) {
  5861. console.warn( 'THREE.BufferGeometry: .addAttribute() now expects ( name, attribute ).' );
  5862. return this.addAttribute( name, new BufferAttribute( arguments[ 1 ], arguments[ 2 ] ) );
  5863. }
  5864. if ( name === 'index' ) {
  5865. console.warn( 'THREE.BufferGeometry.addAttribute: Use .setIndex() for index attribute.' );
  5866. this.setIndex( attribute );
  5867. return this;
  5868. }
  5869. this.attributes[ name ] = attribute;
  5870. return this;
  5871. },
  5872. getAttribute: function ( name ) {
  5873. return this.attributes[ name ];
  5874. },
  5875. removeAttribute: function ( name ) {
  5876. delete this.attributes[ name ];
  5877. return this;
  5878. },
  5879. addGroup: function ( start, count, materialIndex ) {
  5880. this.groups.push( {
  5881. start: start,
  5882. count: count,
  5883. materialIndex: materialIndex !== undefined ? materialIndex : 0
  5884. } );
  5885. },
  5886. clearGroups: function () {
  5887. this.groups = [];
  5888. },
  5889. setDrawRange: function ( start, count ) {
  5890. this.drawRange.start = start;
  5891. this.drawRange.count = count;
  5892. },
  5893. applyMatrix: function ( matrix ) {
  5894. var position = this.attributes.position;
  5895. if ( position !== undefined ) {
  5896. matrix.applyToBufferAttribute( position );
  5897. position.needsUpdate = true;
  5898. }
  5899. var normal = this.attributes.normal;
  5900. if ( normal !== undefined ) {
  5901. var normalMatrix = new Matrix3().getNormalMatrix( matrix );
  5902. normalMatrix.applyToBufferAttribute( normal );
  5903. normal.needsUpdate = true;
  5904. }
  5905. var tangent = this.attributes.tangent;
  5906. if ( tangent !== undefined ) {
  5907. var normalMatrix = new Matrix3().getNormalMatrix( matrix );
  5908. // Tangent is vec4, but the '.w' component is a sign value (+1/-1).
  5909. normalMatrix.applyToBufferAttribute( tangent );
  5910. tangent.needsUpdate = true;
  5911. }
  5912. if ( this.boundingBox !== null ) {
  5913. this.computeBoundingBox();
  5914. }
  5915. if ( this.boundingSphere !== null ) {
  5916. this.computeBoundingSphere();
  5917. }
  5918. return this;
  5919. },
  5920. rotateX: function () {
  5921. // rotate geometry around world x-axis
  5922. var m1 = new Matrix4();
  5923. return function rotateX( angle ) {
  5924. m1.makeRotationX( angle );
  5925. this.applyMatrix( m1 );
  5926. return this;
  5927. };
  5928. }(),
  5929. rotateY: function () {
  5930. // rotate geometry around world y-axis
  5931. var m1 = new Matrix4();
  5932. return function rotateY( angle ) {
  5933. m1.makeRotationY( angle );
  5934. this.applyMatrix( m1 );
  5935. return this;
  5936. };
  5937. }(),
  5938. rotateZ: function () {
  5939. // rotate geometry around world z-axis
  5940. var m1 = new Matrix4();
  5941. return function rotateZ( angle ) {
  5942. m1.makeRotationZ( angle );
  5943. this.applyMatrix( m1 );
  5944. return this;
  5945. };
  5946. }(),
  5947. translate: function () {
  5948. // translate geometry
  5949. var m1 = new Matrix4();
  5950. return function translate( x, y, z ) {
  5951. m1.makeTranslation( x, y, z );
  5952. this.applyMatrix( m1 );
  5953. return this;
  5954. };
  5955. }(),
  5956. scale: function () {
  5957. // scale geometry
  5958. var m1 = new Matrix4();
  5959. return function scale( x, y, z ) {
  5960. m1.makeScale( x, y, z );
  5961. this.applyMatrix( m1 );
  5962. return this;
  5963. };
  5964. }(),
  5965. lookAt: function () {
  5966. var obj = new Object3D();
  5967. return function lookAt( vector ) {
  5968. obj.lookAt( vector );
  5969. obj.updateMatrix();
  5970. this.applyMatrix( obj.matrix );
  5971. };
  5972. }(),
  5973. center: function () {
  5974. var offset = new Vector3();
  5975. return function center() {
  5976. this.computeBoundingBox();
  5977. this.boundingBox.getCenter( offset ).negate();
  5978. this.translate( offset.x, offset.y, offset.z );
  5979. return this;
  5980. };
  5981. }(),
  5982. setFromObject: function ( object ) {
  5983. // console.log( 'THREE.BufferGeometry.setFromObject(). Converting', object, this );
  5984. var geometry = object.geometry;
  5985. if ( object.isPoints || object.isLine ) {
  5986. var positions = new Float32BufferAttribute( geometry.vertices.length * 3, 3 );
  5987. var colors = new Float32BufferAttribute( geometry.colors.length * 3, 3 );
  5988. this.addAttribute( 'position', positions.copyVector3sArray( geometry.vertices ) );
  5989. this.addAttribute( 'color', colors.copyColorsArray( geometry.colors ) );
  5990. if ( geometry.lineDistances && geometry.lineDistances.length === geometry.vertices.length ) {
  5991. var lineDistances = new Float32BufferAttribute( geometry.lineDistances.length, 1 );
  5992. this.addAttribute( 'lineDistance', lineDistances.copyArray( geometry.lineDistances ) );
  5993. }
  5994. if ( geometry.boundingSphere !== null ) {
  5995. this.boundingSphere = geometry.boundingSphere.clone();
  5996. }
  5997. if ( geometry.boundingBox !== null ) {
  5998. this.boundingBox = geometry.boundingBox.clone();
  5999. }
  6000. } else if ( object.isMesh ) {
  6001. if ( geometry && geometry.isGeometry ) {
  6002. this.fromGeometry( geometry );
  6003. }
  6004. }
  6005. return this;
  6006. },
  6007. setFromPoints: function ( points ) {
  6008. var position = [];
  6009. for ( var i = 0, l = points.length; i < l; i ++ ) {
  6010. var point = points[ i ];
  6011. position.push( point.x, point.y, point.z || 0 );
  6012. }
  6013. this.addAttribute( 'position', new Float32BufferAttribute( position, 3 ) );
  6014. return this;
  6015. },
  6016. updateFromObject: function ( object ) {
  6017. var geometry = object.geometry;
  6018. if ( object.isMesh ) {
  6019. var direct = geometry.__directGeometry;
  6020. if ( geometry.elementsNeedUpdate === true ) {
  6021. direct = undefined;
  6022. geometry.elementsNeedUpdate = false;
  6023. }
  6024. if ( direct === undefined ) {
  6025. return this.fromGeometry( geometry );
  6026. }
  6027. direct.verticesNeedUpdate = geometry.verticesNeedUpdate;
  6028. direct.normalsNeedUpdate = geometry.normalsNeedUpdate;
  6029. direct.colorsNeedUpdate = geometry.colorsNeedUpdate;
  6030. direct.uvsNeedUpdate = geometry.uvsNeedUpdate;
  6031. direct.groupsNeedUpdate = geometry.groupsNeedUpdate;
  6032. geometry.verticesNeedUpdate = false;
  6033. geometry.normalsNeedUpdate = false;
  6034. geometry.colorsNeedUpdate = false;
  6035. geometry.uvsNeedUpdate = false;
  6036. geometry.groupsNeedUpdate = false;
  6037. geometry = direct;
  6038. }
  6039. var attribute;
  6040. if ( geometry.verticesNeedUpdate === true ) {
  6041. attribute = this.attributes.position;
  6042. if ( attribute !== undefined ) {
  6043. attribute.copyVector3sArray( geometry.vertices );
  6044. attribute.needsUpdate = true;
  6045. }
  6046. geometry.verticesNeedUpdate = false;
  6047. }
  6048. if ( geometry.normalsNeedUpdate === true ) {
  6049. attribute = this.attributes.normal;
  6050. if ( attribute !== undefined ) {
  6051. attribute.copyVector3sArray( geometry.normals );
  6052. attribute.needsUpdate = true;
  6053. }
  6054. geometry.normalsNeedUpdate = false;
  6055. }
  6056. if ( geometry.colorsNeedUpdate === true ) {
  6057. attribute = this.attributes.color;
  6058. if ( attribute !== undefined ) {
  6059. attribute.copyColorsArray( geometry.colors );
  6060. attribute.needsUpdate = true;
  6061. }
  6062. geometry.colorsNeedUpdate = false;
  6063. }
  6064. if ( geometry.uvsNeedUpdate ) {
  6065. attribute = this.attributes.uv;
  6066. if ( attribute !== undefined ) {
  6067. attribute.copyVector2sArray( geometry.uvs );
  6068. attribute.needsUpdate = true;
  6069. }
  6070. geometry.uvsNeedUpdate = false;
  6071. }
  6072. if ( geometry.lineDistancesNeedUpdate ) {
  6073. attribute = this.attributes.lineDistance;
  6074. if ( attribute !== undefined ) {
  6075. attribute.copyArray( geometry.lineDistances );
  6076. attribute.needsUpdate = true;
  6077. }
  6078. geometry.lineDistancesNeedUpdate = false;
  6079. }
  6080. if ( geometry.groupsNeedUpdate ) {
  6081. geometry.computeGroups( object.geometry );
  6082. this.groups = geometry.groups;
  6083. geometry.groupsNeedUpdate = false;
  6084. }
  6085. return this;
  6086. },
  6087. fromGeometry: function ( geometry ) {
  6088. geometry.__directGeometry = new DirectGeometry().fromGeometry( geometry );
  6089. return this.fromDirectGeometry( geometry.__directGeometry );
  6090. },
  6091. fromDirectGeometry: function ( geometry ) {
  6092. var positions = new Float32Array( geometry.vertices.length * 3 );
  6093. this.addAttribute( 'position', new BufferAttribute( positions, 3 ).copyVector3sArray( geometry.vertices ) );
  6094. if ( geometry.normals.length > 0 ) {
  6095. var normals = new Float32Array( geometry.normals.length * 3 );
  6096. this.addAttribute( 'normal', new BufferAttribute( normals, 3 ).copyVector3sArray( geometry.normals ) );
  6097. }
  6098. if ( geometry.colors.length > 0 ) {
  6099. var colors = new Float32Array( geometry.colors.length * 3 );
  6100. this.addAttribute( 'color', new BufferAttribute( colors, 3 ).copyColorsArray( geometry.colors ) );
  6101. }
  6102. if ( geometry.uvs.length > 0 ) {
  6103. var uvs = new Float32Array( geometry.uvs.length * 2 );
  6104. this.addAttribute( 'uv', new BufferAttribute( uvs, 2 ).copyVector2sArray( geometry.uvs ) );
  6105. }
  6106. if ( geometry.uvs2.length > 0 ) {
  6107. var uvs2 = new Float32Array( geometry.uvs2.length * 2 );
  6108. this.addAttribute( 'uv2', new BufferAttribute( uvs2, 2 ).copyVector2sArray( geometry.uvs2 ) );
  6109. }
  6110. // groups
  6111. this.groups = geometry.groups;
  6112. // morphs
  6113. for ( var name in geometry.morphTargets ) {
  6114. var array = [];
  6115. var morphTargets = geometry.morphTargets[ name ];
  6116. for ( var i = 0, l = morphTargets.length; i < l; i ++ ) {
  6117. var morphTarget = morphTargets[ i ];
  6118. var attribute = new Float32BufferAttribute( morphTarget.data.length * 3, 3 );
  6119. attribute.name = morphTarget.name;
  6120. array.push( attribute.copyVector3sArray( morphTarget.data ) );
  6121. }
  6122. this.morphAttributes[ name ] = array;
  6123. }
  6124. // skinning
  6125. if ( geometry.skinIndices.length > 0 ) {
  6126. var skinIndices = new Float32BufferAttribute( geometry.skinIndices.length * 4, 4 );
  6127. this.addAttribute( 'skinIndex', skinIndices.copyVector4sArray( geometry.skinIndices ) );
  6128. }
  6129. if ( geometry.skinWeights.length > 0 ) {
  6130. var skinWeights = new Float32BufferAttribute( geometry.skinWeights.length * 4, 4 );
  6131. this.addAttribute( 'skinWeight', skinWeights.copyVector4sArray( geometry.skinWeights ) );
  6132. }
  6133. //
  6134. if ( geometry.boundingSphere !== null ) {
  6135. this.boundingSphere = geometry.boundingSphere.clone();
  6136. }
  6137. if ( geometry.boundingBox !== null ) {
  6138. this.boundingBox = geometry.boundingBox.clone();
  6139. }
  6140. return this;
  6141. },
  6142. computeBoundingBox: function () {
  6143. var box = new Box3();
  6144. return function computeBoundingBox() {
  6145. if ( this.boundingBox === null ) {
  6146. this.boundingBox = new Box3();
  6147. }
  6148. var position = this.attributes.position;
  6149. var morphAttributesPosition = this.morphAttributes.position;
  6150. if ( position !== undefined ) {
  6151. this.boundingBox.setFromBufferAttribute( position );
  6152. // process morph attributes if present
  6153. if ( morphAttributesPosition ) {
  6154. for ( var i = 0, il = morphAttributesPosition.length; i < il; i ++ ) {
  6155. var morphAttribute = morphAttributesPosition[ i ];
  6156. box.setFromBufferAttribute( morphAttribute );
  6157. this.boundingBox.expandByPoint( box.min );
  6158. this.boundingBox.expandByPoint( box.max );
  6159. }
  6160. }
  6161. } else {
  6162. this.boundingBox.makeEmpty();
  6163. }
  6164. if ( isNaN( this.boundingBox.min.x ) || isNaN( this.boundingBox.min.y ) || isNaN( this.boundingBox.min.z ) ) {
  6165. console.error( 'THREE.BufferGeometry.computeBoundingBox: Computed min/max have NaN values. The "position" attribute is likely to have NaN values.', this );
  6166. }
  6167. };
  6168. }(),
  6169. computeBoundingSphere: function () {
  6170. var box = new Box3();
  6171. var boxMorphTargets = new Box3();
  6172. var vector = new Vector3();
  6173. return function computeBoundingSphere() {
  6174. if ( this.boundingSphere === null ) {
  6175. this.boundingSphere = new Sphere();
  6176. }
  6177. var position = this.attributes.position;
  6178. var morphAttributesPosition = this.morphAttributes.position;
  6179. if ( position ) {
  6180. // first, find the center of the bounding sphere
  6181. var center = this.boundingSphere.center;
  6182. box.setFromBufferAttribute( position );
  6183. // process morph attributes if present
  6184. if ( morphAttributesPosition ) {
  6185. for ( var i = 0, il = morphAttributesPosition.length; i < il; i ++ ) {
  6186. var morphAttribute = morphAttributesPosition[ i ];
  6187. boxMorphTargets.setFromBufferAttribute( morphAttribute );
  6188. box.expandByPoint( boxMorphTargets.min );
  6189. box.expandByPoint( boxMorphTargets.max );
  6190. }
  6191. }
  6192. box.getCenter( center );
  6193. // second, try to find a boundingSphere with a radius smaller than the
  6194. // boundingSphere of the boundingBox: sqrt(3) smaller in the best case
  6195. var maxRadiusSq = 0;
  6196. for ( var i = 0, il = position.count; i < il; i ++ ) {
  6197. vector.fromBufferAttribute( position, i );
  6198. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( vector ) );
  6199. }
  6200. // process morph attributes if present
  6201. if ( morphAttributesPosition ) {
  6202. for ( var i = 0, il = morphAttributesPosition.length; i < il; i ++ ) {
  6203. var morphAttribute = morphAttributesPosition[ i ];
  6204. for ( var j = 0, jl = morphAttribute.count; j < jl; j ++ ) {
  6205. vector.fromBufferAttribute( morphAttribute, j );
  6206. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( vector ) );
  6207. }
  6208. }
  6209. }
  6210. this.boundingSphere.radius = Math.sqrt( maxRadiusSq );
  6211. if ( isNaN( this.boundingSphere.radius ) ) {
  6212. console.error( 'THREE.BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.', this );
  6213. }
  6214. }
  6215. };
  6216. }(),
  6217. computeFaceNormals: function () {
  6218. // backwards compatibility
  6219. },
  6220. computeVertexNormals: function () {
  6221. var index = this.index;
  6222. var attributes = this.attributes;
  6223. if ( attributes.position ) {
  6224. var positions = attributes.position.array;
  6225. if ( attributes.normal === undefined ) {
  6226. this.addAttribute( 'normal', new BufferAttribute( new Float32Array( positions.length ), 3 ) );
  6227. } else {
  6228. // reset existing normals to zero
  6229. var array = attributes.normal.array;
  6230. for ( var i = 0, il = array.length; i < il; i ++ ) {
  6231. array[ i ] = 0;
  6232. }
  6233. }
  6234. var normals = attributes.normal.array;
  6235. var vA, vB, vC;
  6236. var pA = new Vector3(), pB = new Vector3(), pC = new Vector3();
  6237. var cb = new Vector3(), ab = new Vector3();
  6238. // indexed elements
  6239. if ( index ) {
  6240. var indices = index.array;
  6241. for ( var i = 0, il = index.count; i < il; i += 3 ) {
  6242. vA = indices[ i + 0 ] * 3;
  6243. vB = indices[ i + 1 ] * 3;
  6244. vC = indices[ i + 2 ] * 3;
  6245. pA.fromArray( positions, vA );
  6246. pB.fromArray( positions, vB );
  6247. pC.fromArray( positions, vC );
  6248. cb.subVectors( pC, pB );
  6249. ab.subVectors( pA, pB );
  6250. cb.cross( ab );
  6251. normals[ vA ] += cb.x;
  6252. normals[ vA + 1 ] += cb.y;
  6253. normals[ vA + 2 ] += cb.z;
  6254. normals[ vB ] += cb.x;
  6255. normals[ vB + 1 ] += cb.y;
  6256. normals[ vB + 2 ] += cb.z;
  6257. normals[ vC ] += cb.x;
  6258. normals[ vC + 1 ] += cb.y;
  6259. normals[ vC + 2 ] += cb.z;
  6260. }
  6261. } else {
  6262. // non-indexed elements (unconnected triangle soup)
  6263. for ( var i = 0, il = positions.length; i < il; i += 9 ) {
  6264. pA.fromArray( positions, i );
  6265. pB.fromArray( positions, i + 3 );
  6266. pC.fromArray( positions, i + 6 );
  6267. cb.subVectors( pC, pB );
  6268. ab.subVectors( pA, pB );
  6269. cb.cross( ab );
  6270. normals[ i ] = cb.x;
  6271. normals[ i + 1 ] = cb.y;
  6272. normals[ i + 2 ] = cb.z;
  6273. normals[ i + 3 ] = cb.x;
  6274. normals[ i + 4 ] = cb.y;
  6275. normals[ i + 5 ] = cb.z;
  6276. normals[ i + 6 ] = cb.x;
  6277. normals[ i + 7 ] = cb.y;
  6278. normals[ i + 8 ] = cb.z;
  6279. }
  6280. }
  6281. this.normalizeNormals();
  6282. attributes.normal.needsUpdate = true;
  6283. }
  6284. },
  6285. merge: function ( geometry, offset ) {
  6286. if ( ! ( geometry && geometry.isBufferGeometry ) ) {
  6287. console.error( 'THREE.BufferGeometry.merge(): geometry not an instance of THREE.BufferGeometry.', geometry );
  6288. return;
  6289. }
  6290. if ( offset === undefined ) {
  6291. offset = 0;
  6292. console.warn(
  6293. 'THREE.BufferGeometry.merge(): Overwriting original geometry, starting at offset=0. '
  6294. + 'Use BufferGeometryUtils.mergeBufferGeometries() for lossless merge.'
  6295. );
  6296. }
  6297. var attributes = this.attributes;
  6298. for ( var key in attributes ) {
  6299. if ( geometry.attributes[ key ] === undefined ) continue;
  6300. var attribute1 = attributes[ key ];
  6301. var attributeArray1 = attribute1.array;
  6302. var attribute2 = geometry.attributes[ key ];
  6303. var attributeArray2 = attribute2.array;
  6304. var attributeOffset = attribute2.itemSize * offset;
  6305. var length = Math.min( attributeArray2.length, attributeArray1.length - attributeOffset );
  6306. for ( var i = 0, j = attributeOffset; i < length; i ++, j ++ ) {
  6307. attributeArray1[ j ] = attributeArray2[ i ];
  6308. }
  6309. }
  6310. return this;
  6311. },
  6312. normalizeNormals: function () {
  6313. var vector = new Vector3();
  6314. return function normalizeNormals() {
  6315. var normals = this.attributes.normal;
  6316. for ( var i = 0, il = normals.count; i < il; i ++ ) {
  6317. vector.x = normals.getX( i );
  6318. vector.y = normals.getY( i );
  6319. vector.z = normals.getZ( i );
  6320. vector.normalize();
  6321. normals.setXYZ( i, vector.x, vector.y, vector.z );
  6322. }
  6323. };
  6324. }(),
  6325. toNonIndexed: function () {
  6326. function convertBufferAttribute( attribute, indices ) {
  6327. var array = attribute.array;
  6328. var itemSize = attribute.itemSize;
  6329. var array2 = new array.constructor( indices.length * itemSize );
  6330. var index = 0, index2 = 0;
  6331. for ( var i = 0, l = indices.length; i < l; i ++ ) {
  6332. index = indices[ i ] * itemSize;
  6333. for ( var j = 0; j < itemSize; j ++ ) {
  6334. array2[ index2 ++ ] = array[ index ++ ];
  6335. }
  6336. }
  6337. return new BufferAttribute( array2, itemSize );
  6338. }
  6339. //
  6340. if ( this.index === null ) {
  6341. console.warn( 'THREE.BufferGeometry.toNonIndexed(): Geometry is already non-indexed.' );
  6342. return this;
  6343. }
  6344. var geometry2 = new BufferGeometry();
  6345. var indices = this.index.array;
  6346. var attributes = this.attributes;
  6347. // attributes
  6348. for ( var name in attributes ) {
  6349. var attribute = attributes[ name ];
  6350. var newAttribute = convertBufferAttribute( attribute, indices );
  6351. geometry2.addAttribute( name, newAttribute );
  6352. }
  6353. // morph attributes
  6354. var morphAttributes = this.morphAttributes;
  6355. for ( name in morphAttributes ) {
  6356. var morphArray = [];
  6357. var morphAttribute = morphAttributes[ name ]; // morphAttribute: array of Float32BufferAttributes
  6358. for ( var i = 0, il = morphAttribute.length; i < il; i ++ ) {
  6359. var attribute = morphAttribute[ i ];
  6360. var newAttribute = convertBufferAttribute( attribute, indices );
  6361. morphArray.push( newAttribute );
  6362. }
  6363. geometry2.morphAttributes[ name ] = morphArray;
  6364. }
  6365. // groups
  6366. var groups = this.groups;
  6367. for ( var i = 0, l = groups.length; i < l; i ++ ) {
  6368. var group = groups[ i ];
  6369. geometry2.addGroup( group.start, group.count, group.materialIndex );
  6370. }
  6371. return geometry2;
  6372. },
  6373. toJSON: function () {
  6374. var data = {
  6375. metadata: {
  6376. version: 4.5,
  6377. type: 'BufferGeometry',
  6378. generator: 'BufferGeometry.toJSON'
  6379. }
  6380. };
  6381. // standard BufferGeometry serialization
  6382. data.uuid = this.uuid;
  6383. data.type = this.type;
  6384. if ( this.name !== '' ) data.name = this.name;
  6385. if ( Object.keys( this.userData ).length > 0 ) data.userData = this.userData;
  6386. if ( this.parameters !== undefined ) {
  6387. var parameters = this.parameters;
  6388. for ( var key in parameters ) {
  6389. if ( parameters[ key ] !== undefined ) data[ key ] = parameters[ key ];
  6390. }
  6391. return data;
  6392. }
  6393. data.data = { attributes: {} };
  6394. var index = this.index;
  6395. if ( index !== null ) {
  6396. data.data.index = {
  6397. type: index.array.constructor.name,
  6398. array: Array.prototype.slice.call( index.array )
  6399. };
  6400. }
  6401. var attributes = this.attributes;
  6402. for ( var key in attributes ) {
  6403. var attribute = attributes[ key ];
  6404. var attributeData = attribute.toJSON();
  6405. if ( attribute.name !== '' ) attributeData.name = attribute.name;
  6406. data.data.attributes[ key ] = attributeData;
  6407. }
  6408. var morphAttributes = {};
  6409. var hasMorphAttributes = false;
  6410. for ( var key in this.morphAttributes ) {
  6411. var attributeArray = this.morphAttributes[ key ];
  6412. var array = [];
  6413. for ( var i = 0, il = attributeArray.length; i < il; i ++ ) {
  6414. var attribute = attributeArray[ i ];
  6415. var attributeData = attribute.toJSON();
  6416. if ( attribute.name !== '' ) attributeData.name = attribute.name;
  6417. array.push( attributeData );
  6418. }
  6419. if ( array.length > 0 ) {
  6420. morphAttributes[ key ] = array;
  6421. hasMorphAttributes = true;
  6422. }
  6423. }
  6424. if ( hasMorphAttributes ) data.data.morphAttributes = morphAttributes;
  6425. var groups = this.groups;
  6426. if ( groups.length > 0 ) {
  6427. data.data.groups = JSON.parse( JSON.stringify( groups ) );
  6428. }
  6429. var boundingSphere = this.boundingSphere;
  6430. if ( boundingSphere !== null ) {
  6431. data.data.boundingSphere = {
  6432. center: boundingSphere.center.toArray(),
  6433. radius: boundingSphere.radius
  6434. };
  6435. }
  6436. return data;
  6437. },
  6438. clone: function () {
  6439. /*
  6440. // Handle primitives
  6441. var parameters = this.parameters;
  6442. if ( parameters !== undefined ) {
  6443. var values = [];
  6444. for ( var key in parameters ) {
  6445. values.push( parameters[ key ] );
  6446. }
  6447. var geometry = Object.create( this.constructor.prototype );
  6448. this.constructor.apply( geometry, values );
  6449. return geometry;
  6450. }
  6451. return new this.constructor().copy( this );
  6452. */
  6453. return new BufferGeometry().copy( this );
  6454. },
  6455. copy: function ( source ) {
  6456. var name, i, l;
  6457. // reset
  6458. this.index = null;
  6459. this.attributes = {};
  6460. this.morphAttributes = {};
  6461. this.groups = [];
  6462. this.boundingBox = null;
  6463. this.boundingSphere = null;
  6464. // name
  6465. this.name = source.name;
  6466. // index
  6467. var index = source.index;
  6468. if ( index !== null ) {
  6469. this.setIndex( index.clone() );
  6470. }
  6471. // attributes
  6472. var attributes = source.attributes;
  6473. for ( name in attributes ) {
  6474. var attribute = attributes[ name ];
  6475. this.addAttribute( name, attribute.clone() );
  6476. }
  6477. // morph attributes
  6478. var morphAttributes = source.morphAttributes;
  6479. for ( name in morphAttributes ) {
  6480. var array = [];
  6481. var morphAttribute = morphAttributes[ name ]; // morphAttribute: array of Float32BufferAttributes
  6482. for ( i = 0, l = morphAttribute.length; i < l; i ++ ) {
  6483. array.push( morphAttribute[ i ].clone() );
  6484. }
  6485. this.morphAttributes[ name ] = array;
  6486. }
  6487. // groups
  6488. var groups = source.groups;
  6489. for ( i = 0, l = groups.length; i < l; i ++ ) {
  6490. var group = groups[ i ];
  6491. this.addGroup( group.start, group.count, group.materialIndex );
  6492. }
  6493. // bounding box
  6494. var boundingBox = source.boundingBox;
  6495. if ( boundingBox !== null ) {
  6496. this.boundingBox = boundingBox.clone();
  6497. }
  6498. // bounding sphere
  6499. var boundingSphere = source.boundingSphere;
  6500. if ( boundingSphere !== null ) {
  6501. this.boundingSphere = boundingSphere.clone();
  6502. }
  6503. // draw range
  6504. this.drawRange.start = source.drawRange.start;
  6505. this.drawRange.count = source.drawRange.count;
  6506. // user data
  6507. this.userData = source.userData;
  6508. return this;
  6509. },
  6510. dispose: function () {
  6511. this.dispatchEvent( { type: 'dispose' } );
  6512. }
  6513. } );
  6514. /**
  6515. * @author mrdoob / http://mrdoob.com/
  6516. * @author alteredq / http://alteredqualia.com/
  6517. * @author mikael emtinger / http://gomo.se/
  6518. * @author jonobr1 / http://jonobr1.com/
  6519. */
  6520. function Mesh( geometry, material ) {
  6521. Object3D.call( this );
  6522. this.type = 'Mesh';
  6523. this.geometry = geometry !== undefined ? geometry : new BufferGeometry();
  6524. this.material = material !== undefined ? material : new MeshBasicMaterial( { color: Math.random() * 0xffffff } );
  6525. this.drawMode = TrianglesDrawMode;
  6526. this.updateMorphTargets();
  6527. }
  6528. Mesh.prototype = Object.assign( Object.create( Object3D.prototype ), {
  6529. constructor: Mesh,
  6530. isMesh: true,
  6531. setDrawMode: function ( value ) {
  6532. this.drawMode = value;
  6533. },
  6534. copy: function ( source ) {
  6535. Object3D.prototype.copy.call( this, source );
  6536. this.drawMode = source.drawMode;
  6537. if ( source.morphTargetInfluences !== undefined ) {
  6538. this.morphTargetInfluences = source.morphTargetInfluences.slice();
  6539. }
  6540. if ( source.morphTargetDictionary !== undefined ) {
  6541. this.morphTargetDictionary = Object.assign( {}, source.morphTargetDictionary );
  6542. }
  6543. return this;
  6544. },
  6545. updateMorphTargets: function () {
  6546. var geometry = this.geometry;
  6547. var m, ml, name;
  6548. if ( geometry.isBufferGeometry ) {
  6549. var morphAttributes = geometry.morphAttributes;
  6550. var keys = Object.keys( morphAttributes );
  6551. if ( keys.length > 0 ) {
  6552. var morphAttribute = morphAttributes[ keys[ 0 ] ];
  6553. if ( morphAttribute !== undefined ) {
  6554. this.morphTargetInfluences = [];
  6555. this.morphTargetDictionary = {};
  6556. for ( m = 0, ml = morphAttribute.length; m < ml; m ++ ) {
  6557. name = morphAttribute[ m ].name || String( m );
  6558. this.morphTargetInfluences.push( 0 );
  6559. this.morphTargetDictionary[ name ] = m;
  6560. }
  6561. }
  6562. }
  6563. } else {
  6564. var morphTargets = geometry.morphTargets;
  6565. if ( morphTargets !== undefined && morphTargets.length > 0 ) {
  6566. console.error( 'THREE.Mesh.updateMorphTargets() no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.' );
  6567. }
  6568. }
  6569. },
  6570. raycast: ( function () {
  6571. var inverseMatrix = new Matrix4();
  6572. var ray = new Ray();
  6573. var sphere = new Sphere();
  6574. var vA = new Vector3();
  6575. var vB = new Vector3();
  6576. var vC = new Vector3();
  6577. var tempA = new Vector3();
  6578. var tempB = new Vector3();
  6579. var tempC = new Vector3();
  6580. var morphA = new Vector3();
  6581. var morphB = new Vector3();
  6582. var morphC = new Vector3();
  6583. var uvA = new Vector2();
  6584. var uvB = new Vector2();
  6585. var uvC = new Vector2();
  6586. var intersectionPoint = new Vector3();
  6587. var intersectionPointWorld = new Vector3();
  6588. function checkIntersection( object, material, raycaster, ray, pA, pB, pC, point ) {
  6589. var intersect;
  6590. if ( material.side === BackSide ) {
  6591. intersect = ray.intersectTriangle( pC, pB, pA, true, point );
  6592. } else {
  6593. intersect = ray.intersectTriangle( pA, pB, pC, material.side !== DoubleSide, point );
  6594. }
  6595. if ( intersect === null ) return null;
  6596. intersectionPointWorld.copy( point );
  6597. intersectionPointWorld.applyMatrix4( object.matrixWorld );
  6598. var distance = raycaster.ray.origin.distanceTo( intersectionPointWorld );
  6599. if ( distance < raycaster.near || distance > raycaster.far ) return null;
  6600. return {
  6601. distance: distance,
  6602. point: intersectionPointWorld.clone(),
  6603. object: object
  6604. };
  6605. }
  6606. function checkBufferGeometryIntersection( object, material, raycaster, ray, position, morphPosition, uv, a, b, c ) {
  6607. vA.fromBufferAttribute( position, a );
  6608. vB.fromBufferAttribute( position, b );
  6609. vC.fromBufferAttribute( position, c );
  6610. var morphInfluences = object.morphTargetInfluences;
  6611. if ( material.morphTargets && morphPosition && morphInfluences ) {
  6612. morphA.set( 0, 0, 0 );
  6613. morphB.set( 0, 0, 0 );
  6614. morphC.set( 0, 0, 0 );
  6615. for ( var i = 0, il = morphPosition.length; i < il; i ++ ) {
  6616. var influence = morphInfluences[ i ];
  6617. var morphAttribute = morphPosition[ i ];
  6618. if ( influence === 0 ) continue;
  6619. tempA.fromBufferAttribute( morphAttribute, a );
  6620. tempB.fromBufferAttribute( morphAttribute, b );
  6621. tempC.fromBufferAttribute( morphAttribute, c );
  6622. morphA.addScaledVector( tempA.sub( vA ), influence );
  6623. morphB.addScaledVector( tempB.sub( vB ), influence );
  6624. morphC.addScaledVector( tempC.sub( vC ), influence );
  6625. }
  6626. vA.add( morphA );
  6627. vB.add( morphB );
  6628. vC.add( morphC );
  6629. }
  6630. var intersection = checkIntersection( object, material, raycaster, ray, vA, vB, vC, intersectionPoint );
  6631. if ( intersection ) {
  6632. if ( uv ) {
  6633. uvA.fromBufferAttribute( uv, a );
  6634. uvB.fromBufferAttribute( uv, b );
  6635. uvC.fromBufferAttribute( uv, c );
  6636. intersection.uv = Triangle.getUV( intersectionPoint, vA, vB, vC, uvA, uvB, uvC, new Vector2() );
  6637. }
  6638. var face = new Face3( a, b, c );
  6639. Triangle.getNormal( vA, vB, vC, face.normal );
  6640. intersection.face = face;
  6641. }
  6642. return intersection;
  6643. }
  6644. return function raycast( raycaster, intersects ) {
  6645. var geometry = this.geometry;
  6646. var material = this.material;
  6647. var matrixWorld = this.matrixWorld;
  6648. if ( material === undefined ) return;
  6649. // Checking boundingSphere distance to ray
  6650. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  6651. sphere.copy( geometry.boundingSphere );
  6652. sphere.applyMatrix4( matrixWorld );
  6653. if ( raycaster.ray.intersectsSphere( sphere ) === false ) return;
  6654. //
  6655. inverseMatrix.getInverse( matrixWorld );
  6656. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  6657. // Check boundingBox before continuing
  6658. if ( geometry.boundingBox !== null ) {
  6659. if ( ray.intersectsBox( geometry.boundingBox ) === false ) return;
  6660. }
  6661. var intersection;
  6662. if ( geometry.isBufferGeometry ) {
  6663. var a, b, c;
  6664. var index = geometry.index;
  6665. var position = geometry.attributes.position;
  6666. var morphPosition = geometry.morphAttributes.position;
  6667. var uv = geometry.attributes.uv;
  6668. var groups = geometry.groups;
  6669. var drawRange = geometry.drawRange;
  6670. var i, j, il, jl;
  6671. var group, groupMaterial;
  6672. var start, end;
  6673. if ( index !== null ) {
  6674. // indexed buffer geometry
  6675. if ( Array.isArray( material ) ) {
  6676. for ( i = 0, il = groups.length; i < il; i ++ ) {
  6677. group = groups[ i ];
  6678. groupMaterial = material[ group.materialIndex ];
  6679. start = Math.max( group.start, drawRange.start );
  6680. end = Math.min( ( group.start + group.count ), ( drawRange.start + drawRange.count ) );
  6681. for ( j = start, jl = end; j < jl; j += 3 ) {
  6682. a = index.getX( j );
  6683. b = index.getX( j + 1 );
  6684. c = index.getX( j + 2 );
  6685. intersection = checkBufferGeometryIntersection( this, groupMaterial, raycaster, ray, position, morphPosition, uv, a, b, c );
  6686. if ( intersection ) {
  6687. intersection.faceIndex = Math.floor( j / 3 ); // triangle number in indexed buffer semantics
  6688. intersection.face.materialIndex = group.materialIndex;
  6689. intersects.push( intersection );
  6690. }
  6691. }
  6692. }
  6693. } else {
  6694. start = Math.max( 0, drawRange.start );
  6695. end = Math.min( index.count, ( drawRange.start + drawRange.count ) );
  6696. for ( i = start, il = end; i < il; i += 3 ) {
  6697. a = index.getX( i );
  6698. b = index.getX( i + 1 );
  6699. c = index.getX( i + 2 );
  6700. intersection = checkBufferGeometryIntersection( this, material, raycaster, ray, position, morphPosition, uv, a, b, c );
  6701. if ( intersection ) {
  6702. intersection.faceIndex = Math.floor( i / 3 ); // triangle number in indexed buffer semantics
  6703. intersects.push( intersection );
  6704. }
  6705. }
  6706. }
  6707. } else if ( position !== undefined ) {
  6708. // non-indexed buffer geometry
  6709. if ( Array.isArray( material ) ) {
  6710. for ( i = 0, il = groups.length; i < il; i ++ ) {
  6711. group = groups[ i ];
  6712. groupMaterial = material[ group.materialIndex ];
  6713. start = Math.max( group.start, drawRange.start );
  6714. end = Math.min( ( group.start + group.count ), ( drawRange.start + drawRange.count ) );
  6715. for ( j = start, jl = end; j < jl; j += 3 ) {
  6716. a = j;
  6717. b = j + 1;
  6718. c = j + 2;
  6719. intersection = checkBufferGeometryIntersection( this, groupMaterial, raycaster, ray, position, morphPosition, uv, a, b, c );
  6720. if ( intersection ) {
  6721. intersection.faceIndex = Math.floor( j / 3 ); // triangle number in non-indexed buffer semantics
  6722. intersection.face.materialIndex = group.materialIndex;
  6723. intersects.push( intersection );
  6724. }
  6725. }
  6726. }
  6727. } else {
  6728. start = Math.max( 0, drawRange.start );
  6729. end = Math.min( position.count, ( drawRange.start + drawRange.count ) );
  6730. for ( i = start, il = end; i < il; i += 3 ) {
  6731. a = i;
  6732. b = i + 1;
  6733. c = i + 2;
  6734. intersection = checkBufferGeometryIntersection( this, material, raycaster, ray, position, morphPosition, uv, a, b, c );
  6735. if ( intersection ) {
  6736. intersection.faceIndex = Math.floor( i / 3 ); // triangle number in non-indexed buffer semantics
  6737. intersects.push( intersection );
  6738. }
  6739. }
  6740. }
  6741. }
  6742. } else if ( geometry.isGeometry ) {
  6743. var fvA, fvB, fvC;
  6744. var isMultiMaterial = Array.isArray( material );
  6745. var vertices = geometry.vertices;
  6746. var faces = geometry.faces;
  6747. var uvs;
  6748. var faceVertexUvs = geometry.faceVertexUvs[ 0 ];
  6749. if ( faceVertexUvs.length > 0 ) uvs = faceVertexUvs;
  6750. for ( var f = 0, fl = faces.length; f < fl; f ++ ) {
  6751. var face = faces[ f ];
  6752. var faceMaterial = isMultiMaterial ? material[ face.materialIndex ] : material;
  6753. if ( faceMaterial === undefined ) continue;
  6754. fvA = vertices[ face.a ];
  6755. fvB = vertices[ face.b ];
  6756. fvC = vertices[ face.c ];
  6757. intersection = checkIntersection( this, faceMaterial, raycaster, ray, fvA, fvB, fvC, intersectionPoint );
  6758. if ( intersection ) {
  6759. if ( uvs && uvs[ f ] ) {
  6760. var uvs_f = uvs[ f ];
  6761. uvA.copy( uvs_f[ 0 ] );
  6762. uvB.copy( uvs_f[ 1 ] );
  6763. uvC.copy( uvs_f[ 2 ] );
  6764. intersection.uv = Triangle.getUV( intersectionPoint, fvA, fvB, fvC, uvA, uvB, uvC, new Vector2() );
  6765. }
  6766. intersection.face = face;
  6767. intersection.faceIndex = f;
  6768. intersects.push( intersection );
  6769. }
  6770. }
  6771. }
  6772. };
  6773. }() ),
  6774. clone: function () {
  6775. return new this.constructor( this.geometry, this.material ).copy( this );
  6776. }
  6777. } );
  6778. /**
  6779. * @author mrdoob / http://mrdoob.com/
  6780. * @author kile / http://kile.stravaganza.org/
  6781. * @author alteredq / http://alteredqualia.com/
  6782. * @author mikael emtinger / http://gomo.se/
  6783. * @author zz85 / http://www.lab4games.net/zz85/blog
  6784. * @author bhouston / http://clara.io
  6785. */
  6786. var geometryId = 0; // Geometry uses even numbers as Id
  6787. function Geometry() {
  6788. Object.defineProperty( this, 'id', { value: geometryId += 2 } );
  6789. this.uuid = _Math.generateUUID();
  6790. this.name = '';
  6791. this.type = 'Geometry';
  6792. this.vertices = [];
  6793. this.colors = [];
  6794. this.faces = [];
  6795. this.faceVertexUvs = [[]];
  6796. this.morphTargets = [];
  6797. this.morphNormals = [];
  6798. this.skinWeights = [];
  6799. this.skinIndices = [];
  6800. this.lineDistances = [];
  6801. this.boundingBox = null;
  6802. this.boundingSphere = null;
  6803. // update flags
  6804. this.elementsNeedUpdate = false;
  6805. this.verticesNeedUpdate = false;
  6806. this.uvsNeedUpdate = false;
  6807. this.normalsNeedUpdate = false;
  6808. this.colorsNeedUpdate = false;
  6809. this.lineDistancesNeedUpdate = false;
  6810. this.groupsNeedUpdate = false;
  6811. }
  6812. Geometry.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  6813. constructor: Geometry,
  6814. isGeometry: true,
  6815. applyMatrix: function ( matrix ) {
  6816. var normalMatrix = new Matrix3().getNormalMatrix( matrix );
  6817. for ( var i = 0, il = this.vertices.length; i < il; i ++ ) {
  6818. var vertex = this.vertices[ i ];
  6819. vertex.applyMatrix4( matrix );
  6820. }
  6821. for ( var i = 0, il = this.faces.length; i < il; i ++ ) {
  6822. var face = this.faces[ i ];
  6823. face.normal.applyMatrix3( normalMatrix ).normalize();
  6824. for ( var j = 0, jl = face.vertexNormals.length; j < jl; j ++ ) {
  6825. face.vertexNormals[ j ].applyMatrix3( normalMatrix ).normalize();
  6826. }
  6827. }
  6828. if ( this.boundingBox !== null ) {
  6829. this.computeBoundingBox();
  6830. }
  6831. if ( this.boundingSphere !== null ) {
  6832. this.computeBoundingSphere();
  6833. }
  6834. this.verticesNeedUpdate = true;
  6835. this.normalsNeedUpdate = true;
  6836. return this;
  6837. },
  6838. rotateX: function () {
  6839. // rotate geometry around world x-axis
  6840. var m1 = new Matrix4();
  6841. return function rotateX( angle ) {
  6842. m1.makeRotationX( angle );
  6843. this.applyMatrix( m1 );
  6844. return this;
  6845. };
  6846. }(),
  6847. rotateY: function () {
  6848. // rotate geometry around world y-axis
  6849. var m1 = new Matrix4();
  6850. return function rotateY( angle ) {
  6851. m1.makeRotationY( angle );
  6852. this.applyMatrix( m1 );
  6853. return this;
  6854. };
  6855. }(),
  6856. rotateZ: function () {
  6857. // rotate geometry around world z-axis
  6858. var m1 = new Matrix4();
  6859. return function rotateZ( angle ) {
  6860. m1.makeRotationZ( angle );
  6861. this.applyMatrix( m1 );
  6862. return this;
  6863. };
  6864. }(),
  6865. translate: function () {
  6866. // translate geometry
  6867. var m1 = new Matrix4();
  6868. return function translate( x, y, z ) {
  6869. m1.makeTranslation( x, y, z );
  6870. this.applyMatrix( m1 );
  6871. return this;
  6872. };
  6873. }(),
  6874. scale: function () {
  6875. // scale geometry
  6876. var m1 = new Matrix4();
  6877. return function scale( x, y, z ) {
  6878. m1.makeScale( x, y, z );
  6879. this.applyMatrix( m1 );
  6880. return this;
  6881. };
  6882. }(),
  6883. lookAt: function () {
  6884. var obj = new Object3D();
  6885. return function lookAt( vector ) {
  6886. obj.lookAt( vector );
  6887. obj.updateMatrix();
  6888. this.applyMatrix( obj.matrix );
  6889. };
  6890. }(),
  6891. fromBufferGeometry: function ( geometry ) {
  6892. var scope = this;
  6893. var indices = geometry.index !== null ? geometry.index.array : undefined;
  6894. var attributes = geometry.attributes;
  6895. var positions = attributes.position.array;
  6896. var normals = attributes.normal !== undefined ? attributes.normal.array : undefined;
  6897. var colors = attributes.color !== undefined ? attributes.color.array : undefined;
  6898. var uvs = attributes.uv !== undefined ? attributes.uv.array : undefined;
  6899. var uvs2 = attributes.uv2 !== undefined ? attributes.uv2.array : undefined;
  6900. if ( uvs2 !== undefined ) this.faceVertexUvs[ 1 ] = [];
  6901. for ( var i = 0; i < positions.length; i += 3 ) {
  6902. scope.vertices.push( new Vector3().fromArray( positions, i ) );
  6903. if ( colors !== undefined ) {
  6904. scope.colors.push( new Color().fromArray( colors, i ) );
  6905. }
  6906. }
  6907. function addFace( a, b, c, materialIndex ) {
  6908. var vertexColors = ( colors === undefined ) ? [] : [
  6909. scope.colors[ a ].clone(),
  6910. scope.colors[ b ].clone(),
  6911. scope.colors[ c ].clone() ];
  6912. var vertexNormals = ( normals === undefined ) ? [] : [
  6913. new Vector3().fromArray( normals, a * 3 ),
  6914. new Vector3().fromArray( normals, b * 3 ),
  6915. new Vector3().fromArray( normals, c * 3 )
  6916. ];
  6917. var face = new Face3( a, b, c, vertexNormals, vertexColors, materialIndex );
  6918. scope.faces.push( face );
  6919. if ( uvs !== undefined ) {
  6920. scope.faceVertexUvs[ 0 ].push( [
  6921. new Vector2().fromArray( uvs, a * 2 ),
  6922. new Vector2().fromArray( uvs, b * 2 ),
  6923. new Vector2().fromArray( uvs, c * 2 )
  6924. ] );
  6925. }
  6926. if ( uvs2 !== undefined ) {
  6927. scope.faceVertexUvs[ 1 ].push( [
  6928. new Vector2().fromArray( uvs2, a * 2 ),
  6929. new Vector2().fromArray( uvs2, b * 2 ),
  6930. new Vector2().fromArray( uvs2, c * 2 )
  6931. ] );
  6932. }
  6933. }
  6934. var groups = geometry.groups;
  6935. if ( groups.length > 0 ) {
  6936. for ( var i = 0; i < groups.length; i ++ ) {
  6937. var group = groups[ i ];
  6938. var start = group.start;
  6939. var count = group.count;
  6940. for ( var j = start, jl = start + count; j < jl; j += 3 ) {
  6941. if ( indices !== undefined ) {
  6942. addFace( indices[ j ], indices[ j + 1 ], indices[ j + 2 ], group.materialIndex );
  6943. } else {
  6944. addFace( j, j + 1, j + 2, group.materialIndex );
  6945. }
  6946. }
  6947. }
  6948. } else {
  6949. if ( indices !== undefined ) {
  6950. for ( var i = 0; i < indices.length; i += 3 ) {
  6951. addFace( indices[ i ], indices[ i + 1 ], indices[ i + 2 ] );
  6952. }
  6953. } else {
  6954. for ( var i = 0; i < positions.length / 3; i += 3 ) {
  6955. addFace( i, i + 1, i + 2 );
  6956. }
  6957. }
  6958. }
  6959. this.computeFaceNormals();
  6960. if ( geometry.boundingBox !== null ) {
  6961. this.boundingBox = geometry.boundingBox.clone();
  6962. }
  6963. if ( geometry.boundingSphere !== null ) {
  6964. this.boundingSphere = geometry.boundingSphere.clone();
  6965. }
  6966. return this;
  6967. },
  6968. center: function () {
  6969. var offset = new Vector3();
  6970. return function center() {
  6971. this.computeBoundingBox();
  6972. this.boundingBox.getCenter( offset ).negate();
  6973. this.translate( offset.x, offset.y, offset.z );
  6974. return this;
  6975. };
  6976. }(),
  6977. normalize: function () {
  6978. this.computeBoundingSphere();
  6979. var center = this.boundingSphere.center;
  6980. var radius = this.boundingSphere.radius;
  6981. var s = radius === 0 ? 1 : 1.0 / radius;
  6982. var matrix = new Matrix4();
  6983. matrix.set(
  6984. s, 0, 0, - s * center.x,
  6985. 0, s, 0, - s * center.y,
  6986. 0, 0, s, - s * center.z,
  6987. 0, 0, 0, 1
  6988. );
  6989. this.applyMatrix( matrix );
  6990. return this;
  6991. },
  6992. computeFaceNormals: function () {
  6993. var cb = new Vector3(), ab = new Vector3();
  6994. for ( var f = 0, fl = this.faces.length; f < fl; f ++ ) {
  6995. var face = this.faces[ f ];
  6996. var vA = this.vertices[ face.a ];
  6997. var vB = this.vertices[ face.b ];
  6998. var vC = this.vertices[ face.c ];
  6999. cb.subVectors( vC, vB );
  7000. ab.subVectors( vA, vB );
  7001. cb.cross( ab );
  7002. cb.normalize();
  7003. face.normal.copy( cb );
  7004. }
  7005. },
  7006. computeVertexNormals: function ( areaWeighted ) {
  7007. if ( areaWeighted === undefined ) areaWeighted = true;
  7008. var v, vl, f, fl, face, vertices;
  7009. vertices = new Array( this.vertices.length );
  7010. for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) {
  7011. vertices[ v ] = new Vector3();
  7012. }
  7013. if ( areaWeighted ) {
  7014. // vertex normals weighted by triangle areas
  7015. // http://www.iquilezles.org/www/articles/normals/normals.htm
  7016. var vA, vB, vC;
  7017. var cb = new Vector3(), ab = new Vector3();
  7018. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  7019. face = this.faces[ f ];
  7020. vA = this.vertices[ face.a ];
  7021. vB = this.vertices[ face.b ];
  7022. vC = this.vertices[ face.c ];
  7023. cb.subVectors( vC, vB );
  7024. ab.subVectors( vA, vB );
  7025. cb.cross( ab );
  7026. vertices[ face.a ].add( cb );
  7027. vertices[ face.b ].add( cb );
  7028. vertices[ face.c ].add( cb );
  7029. }
  7030. } else {
  7031. this.computeFaceNormals();
  7032. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  7033. face = this.faces[ f ];
  7034. vertices[ face.a ].add( face.normal );
  7035. vertices[ face.b ].add( face.normal );
  7036. vertices[ face.c ].add( face.normal );
  7037. }
  7038. }
  7039. for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) {
  7040. vertices[ v ].normalize();
  7041. }
  7042. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  7043. face = this.faces[ f ];
  7044. var vertexNormals = face.vertexNormals;
  7045. if ( vertexNormals.length === 3 ) {
  7046. vertexNormals[ 0 ].copy( vertices[ face.a ] );
  7047. vertexNormals[ 1 ].copy( vertices[ face.b ] );
  7048. vertexNormals[ 2 ].copy( vertices[ face.c ] );
  7049. } else {
  7050. vertexNormals[ 0 ] = vertices[ face.a ].clone();
  7051. vertexNormals[ 1 ] = vertices[ face.b ].clone();
  7052. vertexNormals[ 2 ] = vertices[ face.c ].clone();
  7053. }
  7054. }
  7055. if ( this.faces.length > 0 ) {
  7056. this.normalsNeedUpdate = true;
  7057. }
  7058. },
  7059. computeFlatVertexNormals: function () {
  7060. var f, fl, face;
  7061. this.computeFaceNormals();
  7062. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  7063. face = this.faces[ f ];
  7064. var vertexNormals = face.vertexNormals;
  7065. if ( vertexNormals.length === 3 ) {
  7066. vertexNormals[ 0 ].copy( face.normal );
  7067. vertexNormals[ 1 ].copy( face.normal );
  7068. vertexNormals[ 2 ].copy( face.normal );
  7069. } else {
  7070. vertexNormals[ 0 ] = face.normal.clone();
  7071. vertexNormals[ 1 ] = face.normal.clone();
  7072. vertexNormals[ 2 ] = face.normal.clone();
  7073. }
  7074. }
  7075. if ( this.faces.length > 0 ) {
  7076. this.normalsNeedUpdate = true;
  7077. }
  7078. },
  7079. computeMorphNormals: function () {
  7080. var i, il, f, fl, face;
  7081. // save original normals
  7082. // - create temp variables on first access
  7083. // otherwise just copy (for faster repeated calls)
  7084. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  7085. face = this.faces[ f ];
  7086. if ( ! face.__originalFaceNormal ) {
  7087. face.__originalFaceNormal = face.normal.clone();
  7088. } else {
  7089. face.__originalFaceNormal.copy( face.normal );
  7090. }
  7091. if ( ! face.__originalVertexNormals ) face.__originalVertexNormals = [];
  7092. for ( i = 0, il = face.vertexNormals.length; i < il; i ++ ) {
  7093. if ( ! face.__originalVertexNormals[ i ] ) {
  7094. face.__originalVertexNormals[ i ] = face.vertexNormals[ i ].clone();
  7095. } else {
  7096. face.__originalVertexNormals[ i ].copy( face.vertexNormals[ i ] );
  7097. }
  7098. }
  7099. }
  7100. // use temp geometry to compute face and vertex normals for each morph
  7101. var tmpGeo = new Geometry();
  7102. tmpGeo.faces = this.faces;
  7103. for ( i = 0, il = this.morphTargets.length; i < il; i ++ ) {
  7104. // create on first access
  7105. if ( ! this.morphNormals[ i ] ) {
  7106. this.morphNormals[ i ] = {};
  7107. this.morphNormals[ i ].faceNormals = [];
  7108. this.morphNormals[ i ].vertexNormals = [];
  7109. var dstNormalsFace = this.morphNormals[ i ].faceNormals;
  7110. var dstNormalsVertex = this.morphNormals[ i ].vertexNormals;
  7111. var faceNormal, vertexNormals;
  7112. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  7113. faceNormal = new Vector3();
  7114. vertexNormals = { a: new Vector3(), b: new Vector3(), c: new Vector3() };
  7115. dstNormalsFace.push( faceNormal );
  7116. dstNormalsVertex.push( vertexNormals );
  7117. }
  7118. }
  7119. var morphNormals = this.morphNormals[ i ];
  7120. // set vertices to morph target
  7121. tmpGeo.vertices = this.morphTargets[ i ].vertices;
  7122. // compute morph normals
  7123. tmpGeo.computeFaceNormals();
  7124. tmpGeo.computeVertexNormals();
  7125. // store morph normals
  7126. var faceNormal, vertexNormals;
  7127. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  7128. face = this.faces[ f ];
  7129. faceNormal = morphNormals.faceNormals[ f ];
  7130. vertexNormals = morphNormals.vertexNormals[ f ];
  7131. faceNormal.copy( face.normal );
  7132. vertexNormals.a.copy( face.vertexNormals[ 0 ] );
  7133. vertexNormals.b.copy( face.vertexNormals[ 1 ] );
  7134. vertexNormals.c.copy( face.vertexNormals[ 2 ] );
  7135. }
  7136. }
  7137. // restore original normals
  7138. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  7139. face = this.faces[ f ];
  7140. face.normal = face.__originalFaceNormal;
  7141. face.vertexNormals = face.__originalVertexNormals;
  7142. }
  7143. },
  7144. computeBoundingBox: function () {
  7145. if ( this.boundingBox === null ) {
  7146. this.boundingBox = new Box3();
  7147. }
  7148. this.boundingBox.setFromPoints( this.vertices );
  7149. },
  7150. computeBoundingSphere: function () {
  7151. if ( this.boundingSphere === null ) {
  7152. this.boundingSphere = new Sphere();
  7153. }
  7154. this.boundingSphere.setFromPoints( this.vertices );
  7155. },
  7156. merge: function ( geometry, matrix, materialIndexOffset ) {
  7157. if ( ! ( geometry && geometry.isGeometry ) ) {
  7158. console.error( 'THREE.Geometry.merge(): geometry not an instance of THREE.Geometry.', geometry );
  7159. return;
  7160. }
  7161. var normalMatrix,
  7162. vertexOffset = this.vertices.length,
  7163. vertices1 = this.vertices,
  7164. vertices2 = geometry.vertices,
  7165. faces1 = this.faces,
  7166. faces2 = geometry.faces,
  7167. colors1 = this.colors,
  7168. colors2 = geometry.colors;
  7169. if ( materialIndexOffset === undefined ) materialIndexOffset = 0;
  7170. if ( matrix !== undefined ) {
  7171. normalMatrix = new Matrix3().getNormalMatrix( matrix );
  7172. }
  7173. // vertices
  7174. for ( var i = 0, il = vertices2.length; i < il; i ++ ) {
  7175. var vertex = vertices2[ i ];
  7176. var vertexCopy = vertex.clone();
  7177. if ( matrix !== undefined ) vertexCopy.applyMatrix4( matrix );
  7178. vertices1.push( vertexCopy );
  7179. }
  7180. // colors
  7181. for ( var i = 0, il = colors2.length; i < il; i ++ ) {
  7182. colors1.push( colors2[ i ].clone() );
  7183. }
  7184. // faces
  7185. for ( i = 0, il = faces2.length; i < il; i ++ ) {
  7186. var face = faces2[ i ], faceCopy, normal, color,
  7187. faceVertexNormals = face.vertexNormals,
  7188. faceVertexColors = face.vertexColors;
  7189. faceCopy = new Face3( face.a + vertexOffset, face.b + vertexOffset, face.c + vertexOffset );
  7190. faceCopy.normal.copy( face.normal );
  7191. if ( normalMatrix !== undefined ) {
  7192. faceCopy.normal.applyMatrix3( normalMatrix ).normalize();
  7193. }
  7194. for ( var j = 0, jl = faceVertexNormals.length; j < jl; j ++ ) {
  7195. normal = faceVertexNormals[ j ].clone();
  7196. if ( normalMatrix !== undefined ) {
  7197. normal.applyMatrix3( normalMatrix ).normalize();
  7198. }
  7199. faceCopy.vertexNormals.push( normal );
  7200. }
  7201. faceCopy.color.copy( face.color );
  7202. for ( var j = 0, jl = faceVertexColors.length; j < jl; j ++ ) {
  7203. color = faceVertexColors[ j ];
  7204. faceCopy.vertexColors.push( color.clone() );
  7205. }
  7206. faceCopy.materialIndex = face.materialIndex + materialIndexOffset;
  7207. faces1.push( faceCopy );
  7208. }
  7209. // uvs
  7210. for ( var i = 0, il = geometry.faceVertexUvs.length; i < il; i ++ ) {
  7211. var faceVertexUvs2 = geometry.faceVertexUvs[ i ];
  7212. if ( this.faceVertexUvs[ i ] === undefined ) this.faceVertexUvs[ i ] = [];
  7213. for ( var j = 0, jl = faceVertexUvs2.length; j < jl; j ++ ) {
  7214. var uvs2 = faceVertexUvs2[ j ], uvsCopy = [];
  7215. for ( var k = 0, kl = uvs2.length; k < kl; k ++ ) {
  7216. uvsCopy.push( uvs2[ k ].clone() );
  7217. }
  7218. this.faceVertexUvs[ i ].push( uvsCopy );
  7219. }
  7220. }
  7221. },
  7222. mergeMesh: function ( mesh ) {
  7223. if ( ! ( mesh && mesh.isMesh ) ) {
  7224. console.error( 'THREE.Geometry.mergeMesh(): mesh not an instance of THREE.Mesh.', mesh );
  7225. return;
  7226. }
  7227. if ( mesh.matrixAutoUpdate ) mesh.updateMatrix();
  7228. this.merge( mesh.geometry, mesh.matrix );
  7229. },
  7230. /*
  7231. * Checks for duplicate vertices with hashmap.
  7232. * Duplicated vertices are removed
  7233. * and faces' vertices are updated.
  7234. */
  7235. mergeVertices: function () {
  7236. var verticesMap = {}; // Hashmap for looking up vertices by position coordinates (and making sure they are unique)
  7237. var unique = [], changes = [];
  7238. var v, key;
  7239. var precisionPoints = 4; // number of decimal points, e.g. 4 for epsilon of 0.0001
  7240. var precision = Math.pow( 10, precisionPoints );
  7241. var i, il, face;
  7242. var indices, j, jl;
  7243. for ( i = 0, il = this.vertices.length; i < il; i ++ ) {
  7244. v = this.vertices[ i ];
  7245. key = Math.round( v.x * precision ) + '_' + Math.round( v.y * precision ) + '_' + Math.round( v.z * precision );
  7246. if ( verticesMap[ key ] === undefined ) {
  7247. verticesMap[ key ] = i;
  7248. unique.push( this.vertices[ i ] );
  7249. changes[ i ] = unique.length - 1;
  7250. } else {
  7251. //console.log('Duplicate vertex found. ', i, ' could be using ', verticesMap[key]);
  7252. changes[ i ] = changes[ verticesMap[ key ] ];
  7253. }
  7254. }
  7255. // if faces are completely degenerate after merging vertices, we
  7256. // have to remove them from the geometry.
  7257. var faceIndicesToRemove = [];
  7258. for ( i = 0, il = this.faces.length; i < il; i ++ ) {
  7259. face = this.faces[ i ];
  7260. face.a = changes[ face.a ];
  7261. face.b = changes[ face.b ];
  7262. face.c = changes[ face.c ];
  7263. indices = [ face.a, face.b, face.c ];
  7264. // if any duplicate vertices are found in a Face3
  7265. // we have to remove the face as nothing can be saved
  7266. for ( var n = 0; n < 3; n ++ ) {
  7267. if ( indices[ n ] === indices[ ( n + 1 ) % 3 ] ) {
  7268. faceIndicesToRemove.push( i );
  7269. break;
  7270. }
  7271. }
  7272. }
  7273. for ( i = faceIndicesToRemove.length - 1; i >= 0; i -- ) {
  7274. var idx = faceIndicesToRemove[ i ];
  7275. this.faces.splice( idx, 1 );
  7276. for ( j = 0, jl = this.faceVertexUvs.length; j < jl; j ++ ) {
  7277. this.faceVertexUvs[ j ].splice( idx, 1 );
  7278. }
  7279. }
  7280. // Use unique set of vertices
  7281. var diff = this.vertices.length - unique.length;
  7282. this.vertices = unique;
  7283. return diff;
  7284. },
  7285. setFromPoints: function ( points ) {
  7286. this.vertices = [];
  7287. for ( var i = 0, l = points.length; i < l; i ++ ) {
  7288. var point = points[ i ];
  7289. this.vertices.push( new Vector3( point.x, point.y, point.z || 0 ) );
  7290. }
  7291. return this;
  7292. },
  7293. sortFacesByMaterialIndex: function () {
  7294. var faces = this.faces;
  7295. var length = faces.length;
  7296. // tag faces
  7297. for ( var i = 0; i < length; i ++ ) {
  7298. faces[ i ]._id = i;
  7299. }
  7300. // sort faces
  7301. function materialIndexSort( a, b ) {
  7302. return a.materialIndex - b.materialIndex;
  7303. }
  7304. faces.sort( materialIndexSort );
  7305. // sort uvs
  7306. var uvs1 = this.faceVertexUvs[ 0 ];
  7307. var uvs2 = this.faceVertexUvs[ 1 ];
  7308. var newUvs1, newUvs2;
  7309. if ( uvs1 && uvs1.length === length ) newUvs1 = [];
  7310. if ( uvs2 && uvs2.length === length ) newUvs2 = [];
  7311. for ( var i = 0; i < length; i ++ ) {
  7312. var id = faces[ i ]._id;
  7313. if ( newUvs1 ) newUvs1.push( uvs1[ id ] );
  7314. if ( newUvs2 ) newUvs2.push( uvs2[ id ] );
  7315. }
  7316. if ( newUvs1 ) this.faceVertexUvs[ 0 ] = newUvs1;
  7317. if ( newUvs2 ) this.faceVertexUvs[ 1 ] = newUvs2;
  7318. },
  7319. toJSON: function () {
  7320. var data = {
  7321. metadata: {
  7322. version: 4.5,
  7323. type: 'Geometry',
  7324. generator: 'Geometry.toJSON'
  7325. }
  7326. };
  7327. // standard Geometry serialization
  7328. data.uuid = this.uuid;
  7329. data.type = this.type;
  7330. if ( this.name !== '' ) data.name = this.name;
  7331. if ( this.parameters !== undefined ) {
  7332. var parameters = this.parameters;
  7333. for ( var key in parameters ) {
  7334. if ( parameters[ key ] !== undefined ) data[ key ] = parameters[ key ];
  7335. }
  7336. return data;
  7337. }
  7338. var vertices = [];
  7339. for ( var i = 0; i < this.vertices.length; i ++ ) {
  7340. var vertex = this.vertices[ i ];
  7341. vertices.push( vertex.x, vertex.y, vertex.z );
  7342. }
  7343. var faces = [];
  7344. var normals = [];
  7345. var normalsHash = {};
  7346. var colors = [];
  7347. var colorsHash = {};
  7348. var uvs = [];
  7349. var uvsHash = {};
  7350. for ( var i = 0; i < this.faces.length; i ++ ) {
  7351. var face = this.faces[ i ];
  7352. var hasMaterial = true;
  7353. var hasFaceUv = false; // deprecated
  7354. var hasFaceVertexUv = this.faceVertexUvs[ 0 ][ i ] !== undefined;
  7355. var hasFaceNormal = face.normal.length() > 0;
  7356. var hasFaceVertexNormal = face.vertexNormals.length > 0;
  7357. var hasFaceColor = face.color.r !== 1 || face.color.g !== 1 || face.color.b !== 1;
  7358. var hasFaceVertexColor = face.vertexColors.length > 0;
  7359. var faceType = 0;
  7360. faceType = setBit( faceType, 0, 0 ); // isQuad
  7361. faceType = setBit( faceType, 1, hasMaterial );
  7362. faceType = setBit( faceType, 2, hasFaceUv );
  7363. faceType = setBit( faceType, 3, hasFaceVertexUv );
  7364. faceType = setBit( faceType, 4, hasFaceNormal );
  7365. faceType = setBit( faceType, 5, hasFaceVertexNormal );
  7366. faceType = setBit( faceType, 6, hasFaceColor );
  7367. faceType = setBit( faceType, 7, hasFaceVertexColor );
  7368. faces.push( faceType );
  7369. faces.push( face.a, face.b, face.c );
  7370. faces.push( face.materialIndex );
  7371. if ( hasFaceVertexUv ) {
  7372. var faceVertexUvs = this.faceVertexUvs[ 0 ][ i ];
  7373. faces.push(
  7374. getUvIndex( faceVertexUvs[ 0 ] ),
  7375. getUvIndex( faceVertexUvs[ 1 ] ),
  7376. getUvIndex( faceVertexUvs[ 2 ] )
  7377. );
  7378. }
  7379. if ( hasFaceNormal ) {
  7380. faces.push( getNormalIndex( face.normal ) );
  7381. }
  7382. if ( hasFaceVertexNormal ) {
  7383. var vertexNormals = face.vertexNormals;
  7384. faces.push(
  7385. getNormalIndex( vertexNormals[ 0 ] ),
  7386. getNormalIndex( vertexNormals[ 1 ] ),
  7387. getNormalIndex( vertexNormals[ 2 ] )
  7388. );
  7389. }
  7390. if ( hasFaceColor ) {
  7391. faces.push( getColorIndex( face.color ) );
  7392. }
  7393. if ( hasFaceVertexColor ) {
  7394. var vertexColors = face.vertexColors;
  7395. faces.push(
  7396. getColorIndex( vertexColors[ 0 ] ),
  7397. getColorIndex( vertexColors[ 1 ] ),
  7398. getColorIndex( vertexColors[ 2 ] )
  7399. );
  7400. }
  7401. }
  7402. function setBit( value, position, enabled ) {
  7403. return enabled ? value | ( 1 << position ) : value & ( ~ ( 1 << position ) );
  7404. }
  7405. function getNormalIndex( normal ) {
  7406. var hash = normal.x.toString() + normal.y.toString() + normal.z.toString();
  7407. if ( normalsHash[ hash ] !== undefined ) {
  7408. return normalsHash[ hash ];
  7409. }
  7410. normalsHash[ hash ] = normals.length / 3;
  7411. normals.push( normal.x, normal.y, normal.z );
  7412. return normalsHash[ hash ];
  7413. }
  7414. function getColorIndex( color ) {
  7415. var hash = color.r.toString() + color.g.toString() + color.b.toString();
  7416. if ( colorsHash[ hash ] !== undefined ) {
  7417. return colorsHash[ hash ];
  7418. }
  7419. colorsHash[ hash ] = colors.length;
  7420. colors.push( color.getHex() );
  7421. return colorsHash[ hash ];
  7422. }
  7423. function getUvIndex( uv ) {
  7424. var hash = uv.x.toString() + uv.y.toString();
  7425. if ( uvsHash[ hash ] !== undefined ) {
  7426. return uvsHash[ hash ];
  7427. }
  7428. uvsHash[ hash ] = uvs.length / 2;
  7429. uvs.push( uv.x, uv.y );
  7430. return uvsHash[ hash ];
  7431. }
  7432. data.data = {};
  7433. data.data.vertices = vertices;
  7434. data.data.normals = normals;
  7435. if ( colors.length > 0 ) data.data.colors = colors;
  7436. if ( uvs.length > 0 ) data.data.uvs = [ uvs ]; // temporal backward compatibility
  7437. data.data.faces = faces;
  7438. return data;
  7439. },
  7440. clone: function () {
  7441. /*
  7442. // Handle primitives
  7443. var parameters = this.parameters;
  7444. if ( parameters !== undefined ) {
  7445. var values = [];
  7446. for ( var key in parameters ) {
  7447. values.push( parameters[ key ] );
  7448. }
  7449. var geometry = Object.create( this.constructor.prototype );
  7450. this.constructor.apply( geometry, values );
  7451. return geometry;
  7452. }
  7453. return new this.constructor().copy( this );
  7454. */
  7455. return new Geometry().copy( this );
  7456. },
  7457. copy: function ( source ) {
  7458. var i, il, j, jl, k, kl;
  7459. // reset
  7460. this.vertices = [];
  7461. this.colors = [];
  7462. this.faces = [];
  7463. this.faceVertexUvs = [[]];
  7464. this.morphTargets = [];
  7465. this.morphNormals = [];
  7466. this.skinWeights = [];
  7467. this.skinIndices = [];
  7468. this.lineDistances = [];
  7469. this.boundingBox = null;
  7470. this.boundingSphere = null;
  7471. // name
  7472. this.name = source.name;
  7473. // vertices
  7474. var vertices = source.vertices;
  7475. for ( i = 0, il = vertices.length; i < il; i ++ ) {
  7476. this.vertices.push( vertices[ i ].clone() );
  7477. }
  7478. // colors
  7479. var colors = source.colors;
  7480. for ( i = 0, il = colors.length; i < il; i ++ ) {
  7481. this.colors.push( colors[ i ].clone() );
  7482. }
  7483. // faces
  7484. var faces = source.faces;
  7485. for ( i = 0, il = faces.length; i < il; i ++ ) {
  7486. this.faces.push( faces[ i ].clone() );
  7487. }
  7488. // face vertex uvs
  7489. for ( i = 0, il = source.faceVertexUvs.length; i < il; i ++ ) {
  7490. var faceVertexUvs = source.faceVertexUvs[ i ];
  7491. if ( this.faceVertexUvs[ i ] === undefined ) {
  7492. this.faceVertexUvs[ i ] = [];
  7493. }
  7494. for ( j = 0, jl = faceVertexUvs.length; j < jl; j ++ ) {
  7495. var uvs = faceVertexUvs[ j ], uvsCopy = [];
  7496. for ( k = 0, kl = uvs.length; k < kl; k ++ ) {
  7497. var uv = uvs[ k ];
  7498. uvsCopy.push( uv.clone() );
  7499. }
  7500. this.faceVertexUvs[ i ].push( uvsCopy );
  7501. }
  7502. }
  7503. // morph targets
  7504. var morphTargets = source.morphTargets;
  7505. for ( i = 0, il = morphTargets.length; i < il; i ++ ) {
  7506. var morphTarget = {};
  7507. morphTarget.name = morphTargets[ i ].name;
  7508. // vertices
  7509. if ( morphTargets[ i ].vertices !== undefined ) {
  7510. morphTarget.vertices = [];
  7511. for ( j = 0, jl = morphTargets[ i ].vertices.length; j < jl; j ++ ) {
  7512. morphTarget.vertices.push( morphTargets[ i ].vertices[ j ].clone() );
  7513. }
  7514. }
  7515. // normals
  7516. if ( morphTargets[ i ].normals !== undefined ) {
  7517. morphTarget.normals = [];
  7518. for ( j = 0, jl = morphTargets[ i ].normals.length; j < jl; j ++ ) {
  7519. morphTarget.normals.push( morphTargets[ i ].normals[ j ].clone() );
  7520. }
  7521. }
  7522. this.morphTargets.push( morphTarget );
  7523. }
  7524. // morph normals
  7525. var morphNormals = source.morphNormals;
  7526. for ( i = 0, il = morphNormals.length; i < il; i ++ ) {
  7527. var morphNormal = {};
  7528. // vertex normals
  7529. if ( morphNormals[ i ].vertexNormals !== undefined ) {
  7530. morphNormal.vertexNormals = [];
  7531. for ( j = 0, jl = morphNormals[ i ].vertexNormals.length; j < jl; j ++ ) {
  7532. var srcVertexNormal = morphNormals[ i ].vertexNormals[ j ];
  7533. var destVertexNormal = {};
  7534. destVertexNormal.a = srcVertexNormal.a.clone();
  7535. destVertexNormal.b = srcVertexNormal.b.clone();
  7536. destVertexNormal.c = srcVertexNormal.c.clone();
  7537. morphNormal.vertexNormals.push( destVertexNormal );
  7538. }
  7539. }
  7540. // face normals
  7541. if ( morphNormals[ i ].faceNormals !== undefined ) {
  7542. morphNormal.faceNormals = [];
  7543. for ( j = 0, jl = morphNormals[ i ].faceNormals.length; j < jl; j ++ ) {
  7544. morphNormal.faceNormals.push( morphNormals[ i ].faceNormals[ j ].clone() );
  7545. }
  7546. }
  7547. this.morphNormals.push( morphNormal );
  7548. }
  7549. // skin weights
  7550. var skinWeights = source.skinWeights;
  7551. for ( i = 0, il = skinWeights.length; i < il; i ++ ) {
  7552. this.skinWeights.push( skinWeights[ i ].clone() );
  7553. }
  7554. // skin indices
  7555. var skinIndices = source.skinIndices;
  7556. for ( i = 0, il = skinIndices.length; i < il; i ++ ) {
  7557. this.skinIndices.push( skinIndices[ i ].clone() );
  7558. }
  7559. // line distances
  7560. var lineDistances = source.lineDistances;
  7561. for ( i = 0, il = lineDistances.length; i < il; i ++ ) {
  7562. this.lineDistances.push( lineDistances[ i ] );
  7563. }
  7564. // bounding box
  7565. var boundingBox = source.boundingBox;
  7566. if ( boundingBox !== null ) {
  7567. this.boundingBox = boundingBox.clone();
  7568. }
  7569. // bounding sphere
  7570. var boundingSphere = source.boundingSphere;
  7571. if ( boundingSphere !== null ) {
  7572. this.boundingSphere = boundingSphere.clone();
  7573. }
  7574. // update flags
  7575. this.elementsNeedUpdate = source.elementsNeedUpdate;
  7576. this.verticesNeedUpdate = source.verticesNeedUpdate;
  7577. this.uvsNeedUpdate = source.uvsNeedUpdate;
  7578. this.normalsNeedUpdate = source.normalsNeedUpdate;
  7579. this.colorsNeedUpdate = source.colorsNeedUpdate;
  7580. this.lineDistancesNeedUpdate = source.lineDistancesNeedUpdate;
  7581. this.groupsNeedUpdate = source.groupsNeedUpdate;
  7582. return this;
  7583. },
  7584. dispose: function () {
  7585. this.dispatchEvent( { type: 'dispose' } );
  7586. }
  7587. } );
  7588. /**
  7589. * @author mrdoob / http://mrdoob.com/
  7590. * @author Mugen87 / https://github.com/Mugen87
  7591. */
  7592. // BoxGeometry
  7593. function BoxGeometry( width, height, depth, widthSegments, heightSegments, depthSegments ) {
  7594. Geometry.call( this );
  7595. this.type = 'BoxGeometry';
  7596. this.parameters = {
  7597. width: width,
  7598. height: height,
  7599. depth: depth,
  7600. widthSegments: widthSegments,
  7601. heightSegments: heightSegments,
  7602. depthSegments: depthSegments
  7603. };
  7604. this.fromBufferGeometry( new BoxBufferGeometry( width, height, depth, widthSegments, heightSegments, depthSegments ) );
  7605. this.mergeVertices();
  7606. }
  7607. BoxGeometry.prototype = Object.create( Geometry.prototype );
  7608. BoxGeometry.prototype.constructor = BoxGeometry;
  7609. // BoxBufferGeometry
  7610. function BoxBufferGeometry( width, height, depth, widthSegments, heightSegments, depthSegments ) {
  7611. BufferGeometry.call( this );
  7612. this.type = 'BoxBufferGeometry';
  7613. this.parameters = {
  7614. width: width,
  7615. height: height,
  7616. depth: depth,
  7617. widthSegments: widthSegments,
  7618. heightSegments: heightSegments,
  7619. depthSegments: depthSegments
  7620. };
  7621. var scope = this;
  7622. width = width || 1;
  7623. height = height || 1;
  7624. depth = depth || 1;
  7625. // segments
  7626. widthSegments = Math.floor( widthSegments ) || 1;
  7627. heightSegments = Math.floor( heightSegments ) || 1;
  7628. depthSegments = Math.floor( depthSegments ) || 1;
  7629. // buffers
  7630. var indices = [];
  7631. var vertices = [];
  7632. var normals = [];
  7633. var uvs = [];
  7634. // helper variables
  7635. var numberOfVertices = 0;
  7636. var groupStart = 0;
  7637. // build each side of the box geometry
  7638. buildPlane( 'z', 'y', 'x', - 1, - 1, depth, height, width, depthSegments, heightSegments, 0 ); // px
  7639. buildPlane( 'z', 'y', 'x', 1, - 1, depth, height, - width, depthSegments, heightSegments, 1 ); // nx
  7640. buildPlane( 'x', 'z', 'y', 1, 1, width, depth, height, widthSegments, depthSegments, 2 ); // py
  7641. buildPlane( 'x', 'z', 'y', 1, - 1, width, depth, - height, widthSegments, depthSegments, 3 ); // ny
  7642. buildPlane( 'x', 'y', 'z', 1, - 1, width, height, depth, widthSegments, heightSegments, 4 ); // pz
  7643. buildPlane( 'x', 'y', 'z', - 1, - 1, width, height, - depth, widthSegments, heightSegments, 5 ); // nz
  7644. // build geometry
  7645. this.setIndex( indices );
  7646. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  7647. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  7648. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  7649. function buildPlane( u, v, w, udir, vdir, width, height, depth, gridX, gridY, materialIndex ) {
  7650. var segmentWidth = width / gridX;
  7651. var segmentHeight = height / gridY;
  7652. var widthHalf = width / 2;
  7653. var heightHalf = height / 2;
  7654. var depthHalf = depth / 2;
  7655. var gridX1 = gridX + 1;
  7656. var gridY1 = gridY + 1;
  7657. var vertexCounter = 0;
  7658. var groupCount = 0;
  7659. var ix, iy;
  7660. var vector = new Vector3();
  7661. // generate vertices, normals and uvs
  7662. for ( iy = 0; iy < gridY1; iy ++ ) {
  7663. var y = iy * segmentHeight - heightHalf;
  7664. for ( ix = 0; ix < gridX1; ix ++ ) {
  7665. var x = ix * segmentWidth - widthHalf;
  7666. // set values to correct vector component
  7667. vector[ u ] = x * udir;
  7668. vector[ v ] = y * vdir;
  7669. vector[ w ] = depthHalf;
  7670. // now apply vector to vertex buffer
  7671. vertices.push( vector.x, vector.y, vector.z );
  7672. // set values to correct vector component
  7673. vector[ u ] = 0;
  7674. vector[ v ] = 0;
  7675. vector[ w ] = depth > 0 ? 1 : - 1;
  7676. // now apply vector to normal buffer
  7677. normals.push( vector.x, vector.y, vector.z );
  7678. // uvs
  7679. uvs.push( ix / gridX );
  7680. uvs.push( 1 - ( iy / gridY ) );
  7681. // counters
  7682. vertexCounter += 1;
  7683. }
  7684. }
  7685. // indices
  7686. // 1. you need three indices to draw a single face
  7687. // 2. a single segment consists of two faces
  7688. // 3. so we need to generate six (2*3) indices per segment
  7689. for ( iy = 0; iy < gridY; iy ++ ) {
  7690. for ( ix = 0; ix < gridX; ix ++ ) {
  7691. var a = numberOfVertices + ix + gridX1 * iy;
  7692. var b = numberOfVertices + ix + gridX1 * ( iy + 1 );
  7693. var c = numberOfVertices + ( ix + 1 ) + gridX1 * ( iy + 1 );
  7694. var d = numberOfVertices + ( ix + 1 ) + gridX1 * iy;
  7695. // faces
  7696. indices.push( a, b, d );
  7697. indices.push( b, c, d );
  7698. // increase counter
  7699. groupCount += 6;
  7700. }
  7701. }
  7702. // add a group to the geometry. this will ensure multi material support
  7703. scope.addGroup( groupStart, groupCount, materialIndex );
  7704. // calculate new start value for groups
  7705. groupStart += groupCount;
  7706. // update total number of vertices
  7707. numberOfVertices += vertexCounter;
  7708. }
  7709. }
  7710. BoxBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  7711. BoxBufferGeometry.prototype.constructor = BoxBufferGeometry;
  7712. /**
  7713. * Uniform Utilities
  7714. */
  7715. function cloneUniforms( src ) {
  7716. var dst = {};
  7717. for ( var u in src ) {
  7718. dst[ u ] = {};
  7719. for ( var p in src[ u ] ) {
  7720. var property = src[ u ][ p ];
  7721. if ( property && ( property.isColor ||
  7722. property.isMatrix3 || property.isMatrix4 ||
  7723. property.isVector2 || property.isVector3 || property.isVector4 ||
  7724. property.isTexture ) ) {
  7725. dst[ u ][ p ] = property.clone();
  7726. } else if ( Array.isArray( property ) ) {
  7727. dst[ u ][ p ] = property.slice();
  7728. } else {
  7729. dst[ u ][ p ] = property;
  7730. }
  7731. }
  7732. }
  7733. return dst;
  7734. }
  7735. function mergeUniforms( uniforms ) {
  7736. var merged = {};
  7737. for ( var u = 0; u < uniforms.length; u ++ ) {
  7738. var tmp = cloneUniforms( uniforms[ u ] );
  7739. for ( var p in tmp ) {
  7740. merged[ p ] = tmp[ p ];
  7741. }
  7742. }
  7743. return merged;
  7744. }
  7745. // Legacy
  7746. var UniformsUtils = { clone: cloneUniforms, merge: mergeUniforms };
  7747. var default_vertex = "void main() {\n\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}";
  7748. var default_fragment = "void main() {\n\tgl_FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );\n}";
  7749. /**
  7750. * @author alteredq / http://alteredqualia.com/
  7751. *
  7752. * parameters = {
  7753. * defines: { "label" : "value" },
  7754. * uniforms: { "parameter1": { value: 1.0 }, "parameter2": { value2: 2 } },
  7755. *
  7756. * fragmentShader: <string>,
  7757. * vertexShader: <string>,
  7758. *
  7759. * wireframe: <boolean>,
  7760. * wireframeLinewidth: <float>,
  7761. *
  7762. * lights: <bool>,
  7763. *
  7764. * skinning: <bool>,
  7765. * morphTargets: <bool>,
  7766. * morphNormals: <bool>
  7767. * }
  7768. */
  7769. function ShaderMaterial( parameters ) {
  7770. Material.call( this );
  7771. this.type = 'ShaderMaterial';
  7772. this.defines = {};
  7773. this.uniforms = {};
  7774. this.vertexShader = default_vertex;
  7775. this.fragmentShader = default_fragment;
  7776. this.linewidth = 1;
  7777. this.wireframe = false;
  7778. this.wireframeLinewidth = 1;
  7779. this.fog = false; // set to use scene fog
  7780. this.lights = false; // set to use scene lights
  7781. this.clipping = false; // set to use user-defined clipping planes
  7782. this.skinning = false; // set to use skinning attribute streams
  7783. this.morphTargets = false; // set to use morph targets
  7784. this.morphNormals = false; // set to use morph normals
  7785. this.extensions = {
  7786. derivatives: false, // set to use derivatives
  7787. fragDepth: false, // set to use fragment depth values
  7788. drawBuffers: false, // set to use draw buffers
  7789. shaderTextureLOD: false // set to use shader texture LOD
  7790. };
  7791. // When rendered geometry doesn't include these attributes but the material does,
  7792. // use these default values in WebGL. This avoids errors when buffer data is missing.
  7793. this.defaultAttributeValues = {
  7794. 'color': [ 1, 1, 1 ],
  7795. 'uv': [ 0, 0 ],
  7796. 'uv2': [ 0, 0 ]
  7797. };
  7798. this.index0AttributeName = undefined;
  7799. this.uniformsNeedUpdate = false;
  7800. if ( parameters !== undefined ) {
  7801. if ( parameters.attributes !== undefined ) {
  7802. console.error( 'THREE.ShaderMaterial: attributes should now be defined in THREE.BufferGeometry instead.' );
  7803. }
  7804. this.setValues( parameters );
  7805. }
  7806. }
  7807. ShaderMaterial.prototype = Object.create( Material.prototype );
  7808. ShaderMaterial.prototype.constructor = ShaderMaterial;
  7809. ShaderMaterial.prototype.isShaderMaterial = true;
  7810. ShaderMaterial.prototype.copy = function ( source ) {
  7811. Material.prototype.copy.call( this, source );
  7812. this.fragmentShader = source.fragmentShader;
  7813. this.vertexShader = source.vertexShader;
  7814. this.uniforms = cloneUniforms( source.uniforms );
  7815. this.defines = Object.assign( {}, source.defines );
  7816. this.wireframe = source.wireframe;
  7817. this.wireframeLinewidth = source.wireframeLinewidth;
  7818. this.lights = source.lights;
  7819. this.clipping = source.clipping;
  7820. this.skinning = source.skinning;
  7821. this.morphTargets = source.morphTargets;
  7822. this.morphNormals = source.morphNormals;
  7823. this.extensions = source.extensions;
  7824. return this;
  7825. };
  7826. ShaderMaterial.prototype.toJSON = function ( meta ) {
  7827. var data = Material.prototype.toJSON.call( this, meta );
  7828. data.uniforms = {};
  7829. for ( var name in this.uniforms ) {
  7830. var uniform = this.uniforms[ name ];
  7831. var value = uniform.value;
  7832. if ( value && value.isTexture ) {
  7833. data.uniforms[ name ] = {
  7834. type: 't',
  7835. value: value.toJSON( meta ).uuid
  7836. };
  7837. } else if ( value && value.isColor ) {
  7838. data.uniforms[ name ] = {
  7839. type: 'c',
  7840. value: value.getHex()
  7841. };
  7842. } else if ( value && value.isVector2 ) {
  7843. data.uniforms[ name ] = {
  7844. type: 'v2',
  7845. value: value.toArray()
  7846. };
  7847. } else if ( value && value.isVector3 ) {
  7848. data.uniforms[ name ] = {
  7849. type: 'v3',
  7850. value: value.toArray()
  7851. };
  7852. } else if ( value && value.isVector4 ) {
  7853. data.uniforms[ name ] = {
  7854. type: 'v4',
  7855. value: value.toArray()
  7856. };
  7857. } else if ( value && value.isMatrix3 ) {
  7858. data.uniforms[ name ] = {
  7859. type: 'm3',
  7860. value: value.toArray()
  7861. };
  7862. } else if ( value && value.isMatrix4 ) {
  7863. data.uniforms[ name ] = {
  7864. type: 'm4',
  7865. value: value.toArray()
  7866. };
  7867. } else {
  7868. data.uniforms[ name ] = {
  7869. value: value
  7870. };
  7871. // note: the array variants v2v, v3v, v4v, m4v and tv are not supported so far
  7872. }
  7873. }
  7874. if ( Object.keys( this.defines ).length > 0 ) data.defines = this.defines;
  7875. data.vertexShader = this.vertexShader;
  7876. data.fragmentShader = this.fragmentShader;
  7877. var extensions = {};
  7878. for ( var key in this.extensions ) {
  7879. if ( this.extensions[ key ] === true ) extensions[ key ] = true;
  7880. }
  7881. if ( Object.keys( extensions ).length > 0 ) data.extensions = extensions;
  7882. return data;
  7883. };
  7884. /**
  7885. * @author mrdoob / http://mrdoob.com/
  7886. * @author mikael emtinger / http://gomo.se/
  7887. * @author WestLangley / http://github.com/WestLangley
  7888. */
  7889. function Camera() {
  7890. Object3D.call( this );
  7891. this.type = 'Camera';
  7892. this.matrixWorldInverse = new Matrix4();
  7893. this.projectionMatrix = new Matrix4();
  7894. this.projectionMatrixInverse = new Matrix4();
  7895. }
  7896. Camera.prototype = Object.assign( Object.create( Object3D.prototype ), {
  7897. constructor: Camera,
  7898. isCamera: true,
  7899. copy: function ( source, recursive ) {
  7900. Object3D.prototype.copy.call( this, source, recursive );
  7901. this.matrixWorldInverse.copy( source.matrixWorldInverse );
  7902. this.projectionMatrix.copy( source.projectionMatrix );
  7903. this.projectionMatrixInverse.copy( source.projectionMatrixInverse );
  7904. return this;
  7905. },
  7906. getWorldDirection: function ( target ) {
  7907. if ( target === undefined ) {
  7908. console.warn( 'THREE.Camera: .getWorldDirection() target is now required' );
  7909. target = new Vector3();
  7910. }
  7911. this.updateMatrixWorld( true );
  7912. var e = this.matrixWorld.elements;
  7913. return target.set( - e[ 8 ], - e[ 9 ], - e[ 10 ] ).normalize();
  7914. },
  7915. updateMatrixWorld: function ( force ) {
  7916. Object3D.prototype.updateMatrixWorld.call( this, force );
  7917. this.matrixWorldInverse.getInverse( this.matrixWorld );
  7918. },
  7919. clone: function () {
  7920. return new this.constructor().copy( this );
  7921. }
  7922. } );
  7923. /**
  7924. * @author mrdoob / http://mrdoob.com/
  7925. * @author greggman / http://games.greggman.com/
  7926. * @author zz85 / http://www.lab4games.net/zz85/blog
  7927. * @author tschw
  7928. */
  7929. function PerspectiveCamera( fov, aspect, near, far ) {
  7930. Camera.call( this );
  7931. this.type = 'PerspectiveCamera';
  7932. this.fov = fov !== undefined ? fov : 50;
  7933. this.zoom = 1;
  7934. this.near = near !== undefined ? near : 0.1;
  7935. this.far = far !== undefined ? far : 2000;
  7936. this.focus = 10;
  7937. this.aspect = aspect !== undefined ? aspect : 1;
  7938. this.view = null;
  7939. this.filmGauge = 35; // width of the film (default in millimeters)
  7940. this.filmOffset = 0; // horizontal film offset (same unit as gauge)
  7941. this.updateProjectionMatrix();
  7942. }
  7943. PerspectiveCamera.prototype = Object.assign( Object.create( Camera.prototype ), {
  7944. constructor: PerspectiveCamera,
  7945. isPerspectiveCamera: true,
  7946. copy: function ( source, recursive ) {
  7947. Camera.prototype.copy.call( this, source, recursive );
  7948. this.fov = source.fov;
  7949. this.zoom = source.zoom;
  7950. this.near = source.near;
  7951. this.far = source.far;
  7952. this.focus = source.focus;
  7953. this.aspect = source.aspect;
  7954. this.view = source.view === null ? null : Object.assign( {}, source.view );
  7955. this.filmGauge = source.filmGauge;
  7956. this.filmOffset = source.filmOffset;
  7957. return this;
  7958. },
  7959. /**
  7960. * Sets the FOV by focal length in respect to the current .filmGauge.
  7961. *
  7962. * The default film gauge is 35, so that the focal length can be specified for
  7963. * a 35mm (full frame) camera.
  7964. *
  7965. * Values for focal length and film gauge must have the same unit.
  7966. */
  7967. setFocalLength: function ( focalLength ) {
  7968. // see http://www.bobatkins.com/photography/technical/field_of_view.html
  7969. var vExtentSlope = 0.5 * this.getFilmHeight() / focalLength;
  7970. this.fov = _Math.RAD2DEG * 2 * Math.atan( vExtentSlope );
  7971. this.updateProjectionMatrix();
  7972. },
  7973. /**
  7974. * Calculates the focal length from the current .fov and .filmGauge.
  7975. */
  7976. getFocalLength: function () {
  7977. var vExtentSlope = Math.tan( _Math.DEG2RAD * 0.5 * this.fov );
  7978. return 0.5 * this.getFilmHeight() / vExtentSlope;
  7979. },
  7980. getEffectiveFOV: function () {
  7981. return _Math.RAD2DEG * 2 * Math.atan(
  7982. Math.tan( _Math.DEG2RAD * 0.5 * this.fov ) / this.zoom );
  7983. },
  7984. getFilmWidth: function () {
  7985. // film not completely covered in portrait format (aspect < 1)
  7986. return this.filmGauge * Math.min( this.aspect, 1 );
  7987. },
  7988. getFilmHeight: function () {
  7989. // film not completely covered in landscape format (aspect > 1)
  7990. return this.filmGauge / Math.max( this.aspect, 1 );
  7991. },
  7992. /**
  7993. * Sets an offset in a larger frustum. This is useful for multi-window or
  7994. * multi-monitor/multi-machine setups.
  7995. *
  7996. * For example, if you have 3x2 monitors and each monitor is 1920x1080 and
  7997. * the monitors are in grid like this
  7998. *
  7999. * +---+---+---+
  8000. * | A | B | C |
  8001. * +---+---+---+
  8002. * | D | E | F |
  8003. * +---+---+---+
  8004. *
  8005. * then for each monitor you would call it like this
  8006. *
  8007. * var w = 1920;
  8008. * var h = 1080;
  8009. * var fullWidth = w * 3;
  8010. * var fullHeight = h * 2;
  8011. *
  8012. * --A--
  8013. * camera.setViewOffset( fullWidth, fullHeight, w * 0, h * 0, w, h );
  8014. * --B--
  8015. * camera.setViewOffset( fullWidth, fullHeight, w * 1, h * 0, w, h );
  8016. * --C--
  8017. * camera.setViewOffset( fullWidth, fullHeight, w * 2, h * 0, w, h );
  8018. * --D--
  8019. * camera.setViewOffset( fullWidth, fullHeight, w * 0, h * 1, w, h );
  8020. * --E--
  8021. * camera.setViewOffset( fullWidth, fullHeight, w * 1, h * 1, w, h );
  8022. * --F--
  8023. * camera.setViewOffset( fullWidth, fullHeight, w * 2, h * 1, w, h );
  8024. *
  8025. * Note there is no reason monitors have to be the same size or in a grid.
  8026. */
  8027. setViewOffset: function ( fullWidth, fullHeight, x, y, width, height ) {
  8028. this.aspect = fullWidth / fullHeight;
  8029. if ( this.view === null ) {
  8030. this.view = {
  8031. enabled: true,
  8032. fullWidth: 1,
  8033. fullHeight: 1,
  8034. offsetX: 0,
  8035. offsetY: 0,
  8036. width: 1,
  8037. height: 1
  8038. };
  8039. }
  8040. this.view.enabled = true;
  8041. this.view.fullWidth = fullWidth;
  8042. this.view.fullHeight = fullHeight;
  8043. this.view.offsetX = x;
  8044. this.view.offsetY = y;
  8045. this.view.width = width;
  8046. this.view.height = height;
  8047. this.updateProjectionMatrix();
  8048. },
  8049. clearViewOffset: function () {
  8050. if ( this.view !== null ) {
  8051. this.view.enabled = false;
  8052. }
  8053. this.updateProjectionMatrix();
  8054. },
  8055. updateProjectionMatrix: function () {
  8056. var near = this.near,
  8057. top = near * Math.tan( _Math.DEG2RAD * 0.5 * this.fov ) / this.zoom,
  8058. height = 2 * top,
  8059. width = this.aspect * height,
  8060. left = - 0.5 * width,
  8061. view = this.view;
  8062. if ( this.view !== null && this.view.enabled ) {
  8063. var fullWidth = view.fullWidth,
  8064. fullHeight = view.fullHeight;
  8065. left += view.offsetX * width / fullWidth;
  8066. top -= view.offsetY * height / fullHeight;
  8067. width *= view.width / fullWidth;
  8068. height *= view.height / fullHeight;
  8069. }
  8070. var skew = this.filmOffset;
  8071. if ( skew !== 0 ) left += near * skew / this.getFilmWidth();
  8072. this.projectionMatrix.makePerspective( left, left + width, top, top - height, near, this.far );
  8073. this.projectionMatrixInverse.getInverse( this.projectionMatrix );
  8074. },
  8075. toJSON: function ( meta ) {
  8076. var data = Object3D.prototype.toJSON.call( this, meta );
  8077. data.object.fov = this.fov;
  8078. data.object.zoom = this.zoom;
  8079. data.object.near = this.near;
  8080. data.object.far = this.far;
  8081. data.object.focus = this.focus;
  8082. data.object.aspect = this.aspect;
  8083. if ( this.view !== null ) data.object.view = Object.assign( {}, this.view );
  8084. data.object.filmGauge = this.filmGauge;
  8085. data.object.filmOffset = this.filmOffset;
  8086. return data;
  8087. }
  8088. } );
  8089. /**
  8090. * Camera for rendering cube maps
  8091. * - renders scene into axis-aligned cube
  8092. *
  8093. * @author alteredq / http://alteredqualia.com/
  8094. */
  8095. var fov = 90, aspect = 1;
  8096. function CubeCamera( near, far, cubeResolution, options ) {
  8097. Object3D.call( this );
  8098. this.type = 'CubeCamera';
  8099. var cameraPX = new PerspectiveCamera( fov, aspect, near, far );
  8100. cameraPX.up.set( 0, - 1, 0 );
  8101. cameraPX.lookAt( new Vector3( 1, 0, 0 ) );
  8102. this.add( cameraPX );
  8103. var cameraNX = new PerspectiveCamera( fov, aspect, near, far );
  8104. cameraNX.up.set( 0, - 1, 0 );
  8105. cameraNX.lookAt( new Vector3( - 1, 0, 0 ) );
  8106. this.add( cameraNX );
  8107. var cameraPY = new PerspectiveCamera( fov, aspect, near, far );
  8108. cameraPY.up.set( 0, 0, 1 );
  8109. cameraPY.lookAt( new Vector3( 0, 1, 0 ) );
  8110. this.add( cameraPY );
  8111. var cameraNY = new PerspectiveCamera( fov, aspect, near, far );
  8112. cameraNY.up.set( 0, 0, - 1 );
  8113. cameraNY.lookAt( new Vector3( 0, - 1, 0 ) );
  8114. this.add( cameraNY );
  8115. var cameraPZ = new PerspectiveCamera( fov, aspect, near, far );
  8116. cameraPZ.up.set( 0, - 1, 0 );
  8117. cameraPZ.lookAt( new Vector3( 0, 0, 1 ) );
  8118. this.add( cameraPZ );
  8119. var cameraNZ = new PerspectiveCamera( fov, aspect, near, far );
  8120. cameraNZ.up.set( 0, - 1, 0 );
  8121. cameraNZ.lookAt( new Vector3( 0, 0, - 1 ) );
  8122. this.add( cameraNZ );
  8123. options = options || { format: RGBFormat, magFilter: LinearFilter, minFilter: LinearFilter };
  8124. this.renderTarget = new WebGLRenderTargetCube( cubeResolution, cubeResolution, options );
  8125. this.renderTarget.texture.name = "CubeCamera";
  8126. this.update = function ( renderer, scene ) {
  8127. if ( this.parent === null ) this.updateMatrixWorld();
  8128. var currentRenderTarget = renderer.getRenderTarget();
  8129. var renderTarget = this.renderTarget;
  8130. var generateMipmaps = renderTarget.texture.generateMipmaps;
  8131. renderTarget.texture.generateMipmaps = false;
  8132. renderer.setRenderTarget( renderTarget, 0 );
  8133. renderer.render( scene, cameraPX );
  8134. renderer.setRenderTarget( renderTarget, 1 );
  8135. renderer.render( scene, cameraNX );
  8136. renderer.setRenderTarget( renderTarget, 2 );
  8137. renderer.render( scene, cameraPY );
  8138. renderer.setRenderTarget( renderTarget, 3 );
  8139. renderer.render( scene, cameraNY );
  8140. renderer.setRenderTarget( renderTarget, 4 );
  8141. renderer.render( scene, cameraPZ );
  8142. renderTarget.texture.generateMipmaps = generateMipmaps;
  8143. renderer.setRenderTarget( renderTarget, 5 );
  8144. renderer.render( scene, cameraNZ );
  8145. renderer.setRenderTarget( currentRenderTarget );
  8146. };
  8147. this.clear = function ( renderer, color, depth, stencil ) {
  8148. var currentRenderTarget = renderer.getRenderTarget();
  8149. var renderTarget = this.renderTarget;
  8150. for ( var i = 0; i < 6; i ++ ) {
  8151. renderer.setRenderTarget( renderTarget, i );
  8152. renderer.clear( color, depth, stencil );
  8153. }
  8154. renderer.setRenderTarget( currentRenderTarget );
  8155. };
  8156. }
  8157. CubeCamera.prototype = Object.create( Object3D.prototype );
  8158. CubeCamera.prototype.constructor = CubeCamera;
  8159. /**
  8160. * @author alteredq / http://alteredqualia.com
  8161. * @author WestLangley / http://github.com/WestLangley
  8162. */
  8163. function WebGLRenderTargetCube( width, height, options ) {
  8164. WebGLRenderTarget.call( this, width, height, options );
  8165. }
  8166. WebGLRenderTargetCube.prototype = Object.create( WebGLRenderTarget.prototype );
  8167. WebGLRenderTargetCube.prototype.constructor = WebGLRenderTargetCube;
  8168. WebGLRenderTargetCube.prototype.isWebGLRenderTargetCube = true;
  8169. WebGLRenderTargetCube.prototype.fromEquirectangularTexture = function ( renderer, texture ) {
  8170. this.texture.type = texture.type;
  8171. this.texture.format = texture.format;
  8172. this.texture.encoding = texture.encoding;
  8173. var scene = new Scene();
  8174. var shader = {
  8175. uniforms: {
  8176. tEquirect: { value: null },
  8177. },
  8178. vertexShader: [
  8179. "varying vec3 vWorldDirection;",
  8180. "vec3 transformDirection( in vec3 dir, in mat4 matrix ) {",
  8181. " return normalize( ( matrix * vec4( dir, 0.0 ) ).xyz );",
  8182. "}",
  8183. "void main() {",
  8184. " vWorldDirection = transformDirection( position, modelMatrix );",
  8185. " #include <begin_vertex>",
  8186. " #include <project_vertex>",
  8187. "}"
  8188. ].join( '\n' ),
  8189. fragmentShader: [
  8190. "uniform sampler2D tEquirect;",
  8191. "varying vec3 vWorldDirection;",
  8192. "#define RECIPROCAL_PI 0.31830988618",
  8193. "#define RECIPROCAL_PI2 0.15915494",
  8194. "void main() {",
  8195. " vec3 direction = normalize( vWorldDirection );",
  8196. " vec2 sampleUV;",
  8197. " sampleUV.y = asin( clamp( direction.y, - 1.0, 1.0 ) ) * RECIPROCAL_PI + 0.5;",
  8198. " sampleUV.x = atan( direction.z, direction.x ) * RECIPROCAL_PI2 + 0.5;",
  8199. " gl_FragColor = texture2D( tEquirect, sampleUV );",
  8200. "}"
  8201. ].join( '\n' ),
  8202. };
  8203. var material = new ShaderMaterial( {
  8204. type: 'CubemapFromEquirect',
  8205. uniforms: cloneUniforms( shader.uniforms ),
  8206. vertexShader: shader.vertexShader,
  8207. fragmentShader: shader.fragmentShader,
  8208. side: BackSide,
  8209. blending: NoBlending
  8210. } );
  8211. material.uniforms.tEquirect.value = texture;
  8212. var mesh = new Mesh( new BoxBufferGeometry( 5, 5, 5 ), material );
  8213. scene.add( mesh );
  8214. var camera = new CubeCamera( 1, 10, 1 );
  8215. camera.renderTarget = this;
  8216. camera.renderTarget.texture.name = 'CubeCameraTexture';
  8217. camera.update( renderer, scene );
  8218. mesh.geometry.dispose();
  8219. mesh.material.dispose();
  8220. return this;
  8221. };
  8222. /**
  8223. * @author alteredq / http://alteredqualia.com/
  8224. */
  8225. function DataTexture( data, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, encoding ) {
  8226. Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding );
  8227. this.image = { data: data, width: width, height: height };
  8228. this.magFilter = magFilter !== undefined ? magFilter : NearestFilter;
  8229. this.minFilter = minFilter !== undefined ? minFilter : NearestFilter;
  8230. this.generateMipmaps = false;
  8231. this.flipY = false;
  8232. this.unpackAlignment = 1;
  8233. }
  8234. DataTexture.prototype = Object.create( Texture.prototype );
  8235. DataTexture.prototype.constructor = DataTexture;
  8236. DataTexture.prototype.isDataTexture = true;
  8237. /**
  8238. * @author bhouston / http://clara.io
  8239. */
  8240. function Plane( normal, constant ) {
  8241. // normal is assumed to be normalized
  8242. this.normal = ( normal !== undefined ) ? normal : new Vector3( 1, 0, 0 );
  8243. this.constant = ( constant !== undefined ) ? constant : 0;
  8244. }
  8245. Object.assign( Plane.prototype, {
  8246. isPlane: true,
  8247. set: function ( normal, constant ) {
  8248. this.normal.copy( normal );
  8249. this.constant = constant;
  8250. return this;
  8251. },
  8252. setComponents: function ( x, y, z, w ) {
  8253. this.normal.set( x, y, z );
  8254. this.constant = w;
  8255. return this;
  8256. },
  8257. setFromNormalAndCoplanarPoint: function ( normal, point ) {
  8258. this.normal.copy( normal );
  8259. this.constant = - point.dot( this.normal );
  8260. return this;
  8261. },
  8262. setFromCoplanarPoints: function () {
  8263. var v1 = new Vector3();
  8264. var v2 = new Vector3();
  8265. return function setFromCoplanarPoints( a, b, c ) {
  8266. var normal = v1.subVectors( c, b ).cross( v2.subVectors( a, b ) ).normalize();
  8267. // Q: should an error be thrown if normal is zero (e.g. degenerate plane)?
  8268. this.setFromNormalAndCoplanarPoint( normal, a );
  8269. return this;
  8270. };
  8271. }(),
  8272. clone: function () {
  8273. return new this.constructor().copy( this );
  8274. },
  8275. copy: function ( plane ) {
  8276. this.normal.copy( plane.normal );
  8277. this.constant = plane.constant;
  8278. return this;
  8279. },
  8280. normalize: function () {
  8281. // Note: will lead to a divide by zero if the plane is invalid.
  8282. var inverseNormalLength = 1.0 / this.normal.length();
  8283. this.normal.multiplyScalar( inverseNormalLength );
  8284. this.constant *= inverseNormalLength;
  8285. return this;
  8286. },
  8287. negate: function () {
  8288. this.constant *= - 1;
  8289. this.normal.negate();
  8290. return this;
  8291. },
  8292. distanceToPoint: function ( point ) {
  8293. return this.normal.dot( point ) + this.constant;
  8294. },
  8295. distanceToSphere: function ( sphere ) {
  8296. return this.distanceToPoint( sphere.center ) - sphere.radius;
  8297. },
  8298. projectPoint: function ( point, target ) {
  8299. if ( target === undefined ) {
  8300. console.warn( 'THREE.Plane: .projectPoint() target is now required' );
  8301. target = new Vector3();
  8302. }
  8303. return target.copy( this.normal ).multiplyScalar( - this.distanceToPoint( point ) ).add( point );
  8304. },
  8305. intersectLine: function () {
  8306. var v1 = new Vector3();
  8307. return function intersectLine( line, target ) {
  8308. if ( target === undefined ) {
  8309. console.warn( 'THREE.Plane: .intersectLine() target is now required' );
  8310. target = new Vector3();
  8311. }
  8312. var direction = line.delta( v1 );
  8313. var denominator = this.normal.dot( direction );
  8314. if ( denominator === 0 ) {
  8315. // line is coplanar, return origin
  8316. if ( this.distanceToPoint( line.start ) === 0 ) {
  8317. return target.copy( line.start );
  8318. }
  8319. // Unsure if this is the correct method to handle this case.
  8320. return undefined;
  8321. }
  8322. var t = - ( line.start.dot( this.normal ) + this.constant ) / denominator;
  8323. if ( t < 0 || t > 1 ) {
  8324. return undefined;
  8325. }
  8326. return target.copy( direction ).multiplyScalar( t ).add( line.start );
  8327. };
  8328. }(),
  8329. intersectsLine: function ( line ) {
  8330. // Note: this tests if a line intersects the plane, not whether it (or its end-points) are coplanar with it.
  8331. var startSign = this.distanceToPoint( line.start );
  8332. var endSign = this.distanceToPoint( line.end );
  8333. return ( startSign < 0 && endSign > 0 ) || ( endSign < 0 && startSign > 0 );
  8334. },
  8335. intersectsBox: function ( box ) {
  8336. return box.intersectsPlane( this );
  8337. },
  8338. intersectsSphere: function ( sphere ) {
  8339. return sphere.intersectsPlane( this );
  8340. },
  8341. coplanarPoint: function ( target ) {
  8342. if ( target === undefined ) {
  8343. console.warn( 'THREE.Plane: .coplanarPoint() target is now required' );
  8344. target = new Vector3();
  8345. }
  8346. return target.copy( this.normal ).multiplyScalar( - this.constant );
  8347. },
  8348. applyMatrix4: function () {
  8349. var v1 = new Vector3();
  8350. var m1 = new Matrix3();
  8351. return function applyMatrix4( matrix, optionalNormalMatrix ) {
  8352. var normalMatrix = optionalNormalMatrix || m1.getNormalMatrix( matrix );
  8353. var referencePoint = this.coplanarPoint( v1 ).applyMatrix4( matrix );
  8354. var normal = this.normal.applyMatrix3( normalMatrix ).normalize();
  8355. this.constant = - referencePoint.dot( normal );
  8356. return this;
  8357. };
  8358. }(),
  8359. translate: function ( offset ) {
  8360. this.constant -= offset.dot( this.normal );
  8361. return this;
  8362. },
  8363. equals: function ( plane ) {
  8364. return plane.normal.equals( this.normal ) && ( plane.constant === this.constant );
  8365. }
  8366. } );
  8367. /**
  8368. * @author mrdoob / http://mrdoob.com/
  8369. * @author alteredq / http://alteredqualia.com/
  8370. * @author bhouston / http://clara.io
  8371. */
  8372. function Frustum( p0, p1, p2, p3, p4, p5 ) {
  8373. this.planes = [
  8374. ( p0 !== undefined ) ? p0 : new Plane(),
  8375. ( p1 !== undefined ) ? p1 : new Plane(),
  8376. ( p2 !== undefined ) ? p2 : new Plane(),
  8377. ( p3 !== undefined ) ? p3 : new Plane(),
  8378. ( p4 !== undefined ) ? p4 : new Plane(),
  8379. ( p5 !== undefined ) ? p5 : new Plane()
  8380. ];
  8381. }
  8382. Object.assign( Frustum.prototype, {
  8383. set: function ( p0, p1, p2, p3, p4, p5 ) {
  8384. var planes = this.planes;
  8385. planes[ 0 ].copy( p0 );
  8386. planes[ 1 ].copy( p1 );
  8387. planes[ 2 ].copy( p2 );
  8388. planes[ 3 ].copy( p3 );
  8389. planes[ 4 ].copy( p4 );
  8390. planes[ 5 ].copy( p5 );
  8391. return this;
  8392. },
  8393. clone: function () {
  8394. return new this.constructor().copy( this );
  8395. },
  8396. copy: function ( frustum ) {
  8397. var planes = this.planes;
  8398. for ( var i = 0; i < 6; i ++ ) {
  8399. planes[ i ].copy( frustum.planes[ i ] );
  8400. }
  8401. return this;
  8402. },
  8403. setFromMatrix: function ( m ) {
  8404. var planes = this.planes;
  8405. var me = m.elements;
  8406. var me0 = me[ 0 ], me1 = me[ 1 ], me2 = me[ 2 ], me3 = me[ 3 ];
  8407. var me4 = me[ 4 ], me5 = me[ 5 ], me6 = me[ 6 ], me7 = me[ 7 ];
  8408. var me8 = me[ 8 ], me9 = me[ 9 ], me10 = me[ 10 ], me11 = me[ 11 ];
  8409. var me12 = me[ 12 ], me13 = me[ 13 ], me14 = me[ 14 ], me15 = me[ 15 ];
  8410. planes[ 0 ].setComponents( me3 - me0, me7 - me4, me11 - me8, me15 - me12 ).normalize();
  8411. planes[ 1 ].setComponents( me3 + me0, me7 + me4, me11 + me8, me15 + me12 ).normalize();
  8412. planes[ 2 ].setComponents( me3 + me1, me7 + me5, me11 + me9, me15 + me13 ).normalize();
  8413. planes[ 3 ].setComponents( me3 - me1, me7 - me5, me11 - me9, me15 - me13 ).normalize();
  8414. planes[ 4 ].setComponents( me3 - me2, me7 - me6, me11 - me10, me15 - me14 ).normalize();
  8415. planes[ 5 ].setComponents( me3 + me2, me7 + me6, me11 + me10, me15 + me14 ).normalize();
  8416. return this;
  8417. },
  8418. intersectsObject: function () {
  8419. var sphere = new Sphere();
  8420. return function intersectsObject( object ) {
  8421. var geometry = object.geometry;
  8422. if ( geometry.boundingSphere === null )
  8423. geometry.computeBoundingSphere();
  8424. sphere.copy( geometry.boundingSphere )
  8425. .applyMatrix4( object.matrixWorld );
  8426. return this.intersectsSphere( sphere );
  8427. };
  8428. }(),
  8429. intersectsSprite: function () {
  8430. var sphere = new Sphere();
  8431. return function intersectsSprite( sprite ) {
  8432. sphere.center.set( 0, 0, 0 );
  8433. sphere.radius = 0.7071067811865476;
  8434. sphere.applyMatrix4( sprite.matrixWorld );
  8435. return this.intersectsSphere( sphere );
  8436. };
  8437. }(),
  8438. intersectsSphere: function ( sphere ) {
  8439. var planes = this.planes;
  8440. var center = sphere.center;
  8441. var negRadius = - sphere.radius;
  8442. for ( var i = 0; i < 6; i ++ ) {
  8443. var distance = planes[ i ].distanceToPoint( center );
  8444. if ( distance < negRadius ) {
  8445. return false;
  8446. }
  8447. }
  8448. return true;
  8449. },
  8450. intersectsBox: function () {
  8451. var p = new Vector3();
  8452. return function intersectsBox( box ) {
  8453. var planes = this.planes;
  8454. for ( var i = 0; i < 6; i ++ ) {
  8455. var plane = planes[ i ];
  8456. // corner at max distance
  8457. p.x = plane.normal.x > 0 ? box.max.x : box.min.x;
  8458. p.y = plane.normal.y > 0 ? box.max.y : box.min.y;
  8459. p.z = plane.normal.z > 0 ? box.max.z : box.min.z;
  8460. if ( plane.distanceToPoint( p ) < 0 ) {
  8461. return false;
  8462. }
  8463. }
  8464. return true;
  8465. };
  8466. }(),
  8467. containsPoint: function ( point ) {
  8468. var planes = this.planes;
  8469. for ( var i = 0; i < 6; i ++ ) {
  8470. if ( planes[ i ].distanceToPoint( point ) < 0 ) {
  8471. return false;
  8472. }
  8473. }
  8474. return true;
  8475. }
  8476. } );
  8477. var alphamap_fragment = "#ifdef USE_ALPHAMAP\n\tdiffuseColor.a *= texture2D( alphaMap, vUv ).g;\n#endif";
  8478. var alphamap_pars_fragment = "#ifdef USE_ALPHAMAP\n\tuniform sampler2D alphaMap;\n#endif";
  8479. var alphatest_fragment = "#ifdef ALPHATEST\n\tif ( diffuseColor.a < ALPHATEST ) discard;\n#endif";
  8480. 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";
  8481. var aomap_pars_fragment = "#ifdef USE_AOMAP\n\tuniform sampler2D aoMap;\n\tuniform float aoMapIntensity;\n#endif";
  8482. var begin_vertex = "vec3 transformed = vec3( position );";
  8483. var beginnormal_vertex = "vec3 objectNormal = vec3( normal );\n#ifdef USE_TANGENT\n\tvec3 objectTangent = vec3( tangent.xyz );\n#endif";
  8484. var bsdfs = "vec2 integrateSpecularBRDF( const in float dotNV, const in float roughness ) {\n\tconst vec4 c0 = vec4( - 1, - 0.0275, - 0.572, 0.022 );\n\tconst vec4 c1 = vec4( 1, 0.0425, 1.04, - 0.04 );\n\tvec4 r = roughness * c0 + c1;\n\tfloat a004 = min( r.x * r.x, exp2( - 9.28 * dotNV ) ) * r.x + r.y;\n\treturn vec2( -1.04, 1.04 ) * a004 + r.zw;\n}\nfloat punctualLightIntensityToIrradianceFactor( const in float lightDistance, const in float cutoffDistance, const in float decayExponent ) {\n#if defined ( PHYSICALLY_CORRECT_LIGHTS )\n\tfloat distanceFalloff = 1.0 / max( pow( lightDistance, decayExponent ), 0.01 );\n\tif( cutoffDistance > 0.0 ) {\n\t\tdistanceFalloff *= pow2( saturate( 1.0 - pow4( lightDistance / cutoffDistance ) ) );\n\t}\n\treturn distanceFalloff;\n#else\n\tif( cutoffDistance > 0.0 && decayExponent > 0.0 ) {\n\t\treturn pow( saturate( -lightDistance / cutoffDistance + 1.0 ), decayExponent );\n\t}\n\treturn 1.0;\n#endif\n}\nvec3 BRDF_Diffuse_Lambert( const in vec3 diffuseColor ) {\n\treturn RECIPROCAL_PI * diffuseColor;\n}\nvec3 F_Schlick( const in vec3 specularColor, const in float dotLH ) {\n\tfloat fresnel = exp2( ( -5.55473 * dotLH - 6.98316 ) * dotLH );\n\treturn ( 1.0 - specularColor ) * fresnel + specularColor;\n}\nvec3 F_Schlick_RoughnessDependent( const in vec3 F0, const in float dotNV, const in float roughness ) {\n\tfloat fresnel = exp2( ( -5.55473 * dotNV - 6.98316 ) * dotNV );\n\tvec3 Fr = max( vec3( 1.0 - roughness ), F0 ) - F0;\n\treturn Fr * fresnel + F0;\n}\nfloat G_GGX_Smith( const in float alpha, const in float dotNL, const in float dotNV ) {\n\tfloat a2 = pow2( alpha );\n\tfloat gl = dotNL + sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNL ) );\n\tfloat gv = dotNV + sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNV ) );\n\treturn 1.0 / ( gl * gv );\n}\nfloat G_GGX_SmithCorrelated( const in float alpha, const in float dotNL, const in float dotNV ) {\n\tfloat a2 = pow2( alpha );\n\tfloat gv = dotNL * sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNV ) );\n\tfloat gl = dotNV * sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNL ) );\n\treturn 0.5 / max( gv + gl, EPSILON );\n}\nfloat D_GGX( const in float alpha, const in float dotNH ) {\n\tfloat a2 = pow2( alpha );\n\tfloat denom = pow2( dotNH ) * ( a2 - 1.0 ) + 1.0;\n\treturn RECIPROCAL_PI * a2 / pow2( denom );\n}\nvec3 BRDF_Specular_GGX( const in IncidentLight incidentLight, const in GeometricContext geometry, const in vec3 specularColor, const in float roughness ) {\n\tfloat alpha = pow2( roughness );\n\tvec3 halfDir = normalize( incidentLight.direction + geometry.viewDir );\n\tfloat dotNL = saturate( dot( geometry.normal, incidentLight.direction ) );\n\tfloat dotNV = saturate( dot( geometry.normal, geometry.viewDir ) );\n\tfloat dotNH = saturate( dot( geometry.normal, halfDir ) );\n\tfloat dotLH = saturate( dot( incidentLight.direction, halfDir ) );\n\tvec3 F = F_Schlick( specularColor, dotLH );\n\tfloat G = G_GGX_SmithCorrelated( alpha, dotNL, dotNV );\n\tfloat D = D_GGX( alpha, dotNH );\n\treturn F * ( G * D );\n}\nvec2 LTC_Uv( const in vec3 N, const in vec3 V, const in float roughness ) {\n\tconst float LUT_SIZE = 64.0;\n\tconst float LUT_SCALE = ( LUT_SIZE - 1.0 ) / LUT_SIZE;\n\tconst float LUT_BIAS = 0.5 / LUT_SIZE;\n\tfloat dotNV = saturate( dot( N, V ) );\n\tvec2 uv = vec2( roughness, sqrt( 1.0 - dotNV ) );\n\tuv = uv * LUT_SCALE + LUT_BIAS;\n\treturn uv;\n}\nfloat LTC_ClippedSphereFormFactor( const in vec3 f ) {\n\tfloat l = length( f );\n\treturn max( ( l * l + f.z ) / ( l + 1.0 ), 0.0 );\n}\nvec3 LTC_EdgeVectorFormFactor( const in vec3 v1, const in vec3 v2 ) {\n\tfloat x = dot( v1, v2 );\n\tfloat y = abs( x );\n\tfloat a = 0.8543985 + ( 0.4965155 + 0.0145206 * y ) * y;\n\tfloat b = 3.4175940 + ( 4.1616724 + y ) * y;\n\tfloat v = a / b;\n\tfloat theta_sintheta = ( x > 0.0 ) ? v : 0.5 * inversesqrt( max( 1.0 - x * x, 1e-7 ) ) - v;\n\treturn cross( v1, v2 ) * theta_sintheta;\n}\nvec3 LTC_Evaluate( const in vec3 N, const in vec3 V, const in vec3 P, const in mat3 mInv, const in vec3 rectCoords[ 4 ] ) {\n\tvec3 v1 = rectCoords[ 1 ] - rectCoords[ 0 ];\n\tvec3 v2 = rectCoords[ 3 ] - rectCoords[ 0 ];\n\tvec3 lightNormal = cross( v1, v2 );\n\tif( dot( lightNormal, P - rectCoords[ 0 ] ) < 0.0 ) return vec3( 0.0 );\n\tvec3 T1, T2;\n\tT1 = normalize( V - N * dot( V, N ) );\n\tT2 = - cross( N, T1 );\n\tmat3 mat = mInv * transposeMat3( mat3( T1, T2, N ) );\n\tvec3 coords[ 4 ];\n\tcoords[ 0 ] = mat * ( rectCoords[ 0 ] - P );\n\tcoords[ 1 ] = mat * ( rectCoords[ 1 ] - P );\n\tcoords[ 2 ] = mat * ( rectCoords[ 2 ] - P );\n\tcoords[ 3 ] = mat * ( rectCoords[ 3 ] - P );\n\tcoords[ 0 ] = normalize( coords[ 0 ] );\n\tcoords[ 1 ] = normalize( coords[ 1 ] );\n\tcoords[ 2 ] = normalize( coords[ 2 ] );\n\tcoords[ 3 ] = normalize( coords[ 3 ] );\n\tvec3 vectorFormFactor = vec3( 0.0 );\n\tvectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 0 ], coords[ 1 ] );\n\tvectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 1 ], coords[ 2 ] );\n\tvectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 2 ], coords[ 3 ] );\n\tvectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 3 ], coords[ 0 ] );\n\tfloat result = LTC_ClippedSphereFormFactor( vectorFormFactor );\n\treturn vec3( result );\n}\nvec3 BRDF_Specular_GGX_Environment( const in GeometricContext geometry, const in vec3 specularColor, const in float roughness ) {\n\tfloat dotNV = saturate( dot( geometry.normal, geometry.viewDir ) );\n\tvec2 brdf = integrateSpecularBRDF( dotNV, roughness );\n\treturn specularColor * brdf.x + brdf.y;\n}\nvoid BRDF_Specular_Multiscattering_Environment( const in GeometricContext geometry, const in vec3 specularColor, const in float roughness, inout vec3 singleScatter, inout vec3 multiScatter ) {\n\tfloat dotNV = saturate( dot( geometry.normal, geometry.viewDir ) );\n\tvec3 F = F_Schlick_RoughnessDependent( specularColor, dotNV, roughness );\n\tvec2 brdf = integrateSpecularBRDF( dotNV, roughness );\n\tvec3 FssEss = F * brdf.x + brdf.y;\n\tfloat Ess = brdf.x + brdf.y;\n\tfloat Ems = 1.0 - Ess;\n\tvec3 Favg = specularColor + ( 1.0 - specularColor ) * 0.047619;\tvec3 Fms = FssEss * Favg / ( 1.0 - Ems * Favg );\n\tsingleScatter += FssEss;\n\tmultiScatter += Fms * Ems;\n}\nfloat G_BlinnPhong_Implicit( ) {\n\treturn 0.25;\n}\nfloat D_BlinnPhong( const in float shininess, const in float dotNH ) {\n\treturn RECIPROCAL_PI * ( shininess * 0.5 + 1.0 ) * pow( dotNH, shininess );\n}\nvec3 BRDF_Specular_BlinnPhong( const in IncidentLight incidentLight, const in GeometricContext geometry, const in vec3 specularColor, const in float shininess ) {\n\tvec3 halfDir = normalize( incidentLight.direction + geometry.viewDir );\n\tfloat dotNH = saturate( dot( geometry.normal, halfDir ) );\n\tfloat dotLH = saturate( dot( incidentLight.direction, halfDir ) );\n\tvec3 F = F_Schlick( specularColor, dotLH );\n\tfloat G = G_BlinnPhong_Implicit( );\n\tfloat D = D_BlinnPhong( shininess, dotNH );\n\treturn F * ( G * D );\n}\nfloat GGXRoughnessToBlinnExponent( const in float ggxRoughness ) {\n\treturn ( 2.0 / pow2( ggxRoughness + 0.0001 ) - 2.0 );\n}\nfloat BlinnExponentToGGXRoughness( const in float blinnExponent ) {\n\treturn sqrt( 2.0 / ( blinnExponent + 2.0 ) );\n}";
  8485. 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";
  8486. 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";
  8487. 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";
  8488. var clipping_planes_pars_vertex = "#if NUM_CLIPPING_PLANES > 0 && ! defined( PHYSICAL ) && ! defined( PHONG ) && ! defined( MATCAP )\n\tvarying vec3 vViewPosition;\n#endif";
  8489. var clipping_planes_vertex = "#if NUM_CLIPPING_PLANES > 0 && ! defined( PHYSICAL ) && ! defined( PHONG ) && ! defined( MATCAP )\n\tvViewPosition = - mvPosition.xyz;\n#endif";
  8490. var color_fragment = "#ifdef USE_COLOR\n\tdiffuseColor.rgb *= vColor;\n#endif";
  8491. var color_pars_fragment = "#ifdef USE_COLOR\n\tvarying vec3 vColor;\n#endif";
  8492. var color_pars_vertex = "#ifdef USE_COLOR\n\tvarying vec3 vColor;\n#endif";
  8493. var color_vertex = "#ifdef USE_COLOR\n\tvColor.xyz = color.xyz;\n#endif";
  8494. 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}";
  8495. 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";
  8496. 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";
  8497. var displacementmap_pars_vertex = "#ifdef USE_DISPLACEMENTMAP\n\tuniform sampler2D displacementMap;\n\tuniform float displacementScale;\n\tuniform float displacementBias;\n#endif";
  8498. var displacementmap_vertex = "#ifdef USE_DISPLACEMENTMAP\n\ttransformed += normalize( objectNormal ) * ( texture2D( displacementMap, uv ).x * displacementScale + displacementBias );\n#endif";
  8499. var emissivemap_fragment = "#ifdef USE_EMISSIVEMAP\n\tvec4 emissiveColor = texture2D( emissiveMap, vUv );\n\temissiveColor.rgb = emissiveMapTexelToLinear( emissiveColor ).rgb;\n\ttotalEmissiveRadiance *= emissiveColor.rgb;\n#endif";
  8500. var emissivemap_pars_fragment = "#ifdef USE_EMISSIVEMAP\n\tuniform sampler2D emissiveMap;\n#endif";
  8501. var encodings_fragment = "gl_FragColor = linearToOutputTexel( gl_FragColor );";
  8502. 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}";
  8503. 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";
  8504. 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";
  8505. 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";
  8506. 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";
  8507. var fog_vertex = "#ifdef USE_FOG\n\tfogDepth = -mvPosition.z;\n#endif";
  8508. var fog_pars_vertex = "#ifdef USE_FOG\n\tvarying float fogDepth;\n#endif";
  8509. 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";
  8510. 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";
  8511. 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";
  8512. var lightmap_fragment = "#ifdef USE_LIGHTMAP\n\treflectedLight.indirectDiffuse += PI * texture2D( lightMap, vUv2 ).xyz * lightMapIntensity;\n#endif";
  8513. var lightmap_pars_fragment = "#ifdef USE_LIGHTMAP\n\tuniform sampler2D lightMap;\n\tuniform float lightMapIntensity;\n#endif";
  8514. 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";
  8515. 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";
  8516. 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";
  8517. var lights_phong_fragment = "BlinnPhongMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;\nmaterial.specularColor = specular;\nmaterial.specularShininess = shininess;\nmaterial.specularStrength = specularStrength;";
  8518. 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)";
  8519. 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";
  8520. var lights_physical_pars_fragment = "struct PhysicalMaterial {\n\tvec3\tdiffuseColor;\n\tfloat\tspecularRoughness;\n\tvec3\tspecularColor;\n\t#ifndef STANDARD\n\t\tfloat clearCoat;\n\t\tfloat clearCoatRoughness;\n\t#endif\n};\n#define MAXIMUM_SPECULAR_COEFFICIENT 0.16\n#define DEFAULT_SPECULAR_COEFFICIENT 0.04\nfloat clearCoatDHRApprox( const in float roughness, const in float dotNL ) {\n\treturn DEFAULT_SPECULAR_COEFFICIENT + ( 1.0 - DEFAULT_SPECULAR_COEFFICIENT ) * ( pow( 1.0 - dotNL, 5.0 ) * pow( 1.0 - roughness, 2.0 ) );\n}\n#if NUM_RECT_AREA_LIGHTS > 0\n\tvoid RE_Direct_RectArea_Physical( const in RectAreaLight rectAreaLight, const in GeometricContext geometry, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {\n\t\tvec3 normal = geometry.normal;\n\t\tvec3 viewDir = geometry.viewDir;\n\t\tvec3 position = geometry.position;\n\t\tvec3 lightPos = rectAreaLight.position;\n\t\tvec3 halfWidth = rectAreaLight.halfWidth;\n\t\tvec3 halfHeight = rectAreaLight.halfHeight;\n\t\tvec3 lightColor = rectAreaLight.color;\n\t\tfloat roughness = material.specularRoughness;\n\t\tvec3 rectCoords[ 4 ];\n\t\trectCoords[ 0 ] = lightPos + halfWidth - halfHeight;\t\trectCoords[ 1 ] = lightPos - halfWidth - halfHeight;\n\t\trectCoords[ 2 ] = lightPos - halfWidth + halfHeight;\n\t\trectCoords[ 3 ] = lightPos + halfWidth + halfHeight;\n\t\tvec2 uv = LTC_Uv( normal, viewDir, roughness );\n\t\tvec4 t1 = texture2D( ltc_1, uv );\n\t\tvec4 t2 = texture2D( ltc_2, uv );\n\t\tmat3 mInv = mat3(\n\t\t\tvec3( t1.x, 0, t1.y ),\n\t\t\tvec3( 0, 1, 0 ),\n\t\t\tvec3( t1.z, 0, t1.w )\n\t\t);\n\t\tvec3 fresnel = ( material.specularColor * t2.x + ( vec3( 1.0 ) - material.specularColor ) * t2.y );\n\t\treflectedLight.directSpecular += lightColor * fresnel * LTC_Evaluate( normal, viewDir, position, mInv, rectCoords );\n\t\treflectedLight.directDiffuse += lightColor * material.diffuseColor * LTC_Evaluate( normal, viewDir, position, mat3( 1.0 ), rectCoords );\n\t}\n#endif\nvoid RE_Direct_Physical( const in IncidentLight directLight, const in GeometricContext geometry, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {\n\tfloat dotNL = saturate( dot( geometry.normal, directLight.direction ) );\n\tvec3 irradiance = dotNL * directLight.color;\n\t#ifndef PHYSICALLY_CORRECT_LIGHTS\n\t\tirradiance *= PI;\n\t#endif\n\t#ifndef STANDARD\n\t\tfloat clearCoatDHR = material.clearCoat * clearCoatDHRApprox( material.clearCoatRoughness, dotNL );\n\t#else\n\t\tfloat clearCoatDHR = 0.0;\n\t#endif\n\treflectedLight.directSpecular += ( 1.0 - clearCoatDHR ) * irradiance * BRDF_Specular_GGX( directLight, geometry, material.specularColor, material.specularRoughness );\n\treflectedLight.directDiffuse += ( 1.0 - clearCoatDHR ) * irradiance * BRDF_Diffuse_Lambert( material.diffuseColor );\n\t#ifndef STANDARD\n\t\treflectedLight.directSpecular += irradiance * material.clearCoat * BRDF_Specular_GGX( directLight, geometry, vec3( DEFAULT_SPECULAR_COEFFICIENT ), material.clearCoatRoughness );\n\t#endif\n}\nvoid RE_IndirectDiffuse_Physical( const in vec3 irradiance, const in GeometricContext geometry, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {\n\t#ifndef ENVMAP_TYPE_CUBE_UV\n\t\treflectedLight.indirectDiffuse += irradiance * BRDF_Diffuse_Lambert( material.diffuseColor );\n\t#endif\n}\nvoid RE_IndirectSpecular_Physical( const in vec3 radiance, const in vec3 irradiance, const in vec3 clearCoatRadiance, const in GeometricContext geometry, const in PhysicalMaterial material, inout ReflectedLight reflectedLight) {\n\t#ifndef STANDARD\n\t\tfloat dotNV = saturate( dot( geometry.normal, geometry.viewDir ) );\n\t\tfloat dotNL = dotNV;\n\t\tfloat clearCoatDHR = material.clearCoat * clearCoatDHRApprox( material.clearCoatRoughness, dotNL );\n\t#else\n\t\tfloat clearCoatDHR = 0.0;\n\t#endif\n\tfloat clearCoatInv = 1.0 - clearCoatDHR;\n\t#if defined( ENVMAP_TYPE_CUBE_UV )\n\t\tvec3 singleScattering = vec3( 0.0 );\n\t\tvec3 multiScattering = vec3( 0.0 );\n\t\tvec3 cosineWeightedIrradiance = irradiance * RECIPROCAL_PI;\n\t\tBRDF_Specular_Multiscattering_Environment( geometry, material.specularColor, material.specularRoughness, singleScattering, multiScattering );\n\t\tvec3 diffuse = material.diffuseColor * ( 1.0 - ( singleScattering + multiScattering ) );\n\t\treflectedLight.indirectSpecular += clearCoatInv * radiance * singleScattering;\n\t\treflectedLight.indirectDiffuse += multiScattering * cosineWeightedIrradiance;\n\t\treflectedLight.indirectDiffuse += diffuse * cosineWeightedIrradiance;\n\t#else\n\t\treflectedLight.indirectSpecular += clearCoatInv * radiance * BRDF_Specular_GGX_Environment( geometry, material.specularColor, material.specularRoughness );\n\t#endif\n\t#ifndef STANDARD\n\t\treflectedLight.indirectSpecular += clearCoatRadiance * material.clearCoat * BRDF_Specular_GGX_Environment( geometry, vec3( DEFAULT_SPECULAR_COEFFICIENT ), material.clearCoatRoughness );\n\t#endif\n}\n#define RE_Direct\t\t\t\tRE_Direct_Physical\n#define RE_Direct_RectArea\t\tRE_Direct_RectArea_Physical\n#define RE_IndirectDiffuse\t\tRE_IndirectDiffuse_Physical\n#define RE_IndirectSpecular\t\tRE_IndirectSpecular_Physical\n#define Material_BlinnShininessExponent( material ) GGXRoughnessToBlinnExponent( material.specularRoughness )\n#define Material_ClearCoat_BlinnShininessExponent( material ) GGXRoughnessToBlinnExponent( material.clearCoatRoughness )\nfloat computeSpecularOcclusion( const in float dotNV, const in float ambientOcclusion, const in float roughness ) {\n\treturn saturate( pow( dotNV + ambientOcclusion, exp2( - 16.0 * roughness - 1.0 ) ) - 1.0 + ambientOcclusion );\n}";
  8521. 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";
  8522. 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";
  8523. 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";
  8524. var logdepthbuf_fragment = "#if defined( USE_LOGDEPTHBUF ) && defined( USE_LOGDEPTHBUF_EXT )\n\tgl_FragDepthEXT = log2( vFragDepth ) * logDepthBufFC * 0.5;\n#endif";
  8525. var logdepthbuf_pars_fragment = "#if defined( USE_LOGDEPTHBUF ) && defined( USE_LOGDEPTHBUF_EXT )\n\tuniform float logDepthBufFC;\n\tvarying float vFragDepth;\n#endif";
  8526. 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";
  8527. 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";
  8528. var map_fragment = "#ifdef USE_MAP\n\tvec4 texelColor = texture2D( map, vUv );\n\ttexelColor = mapTexelToLinear( texelColor );\n\tdiffuseColor *= texelColor;\n#endif";
  8529. var map_pars_fragment = "#ifdef USE_MAP\n\tuniform sampler2D map;\n#endif";
  8530. 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";
  8531. var map_particle_pars_fragment = "#ifdef USE_MAP\n\tuniform mat3 uvTransform;\n\tuniform sampler2D map;\n#endif";
  8532. var metalnessmap_fragment = "float metalnessFactor = metalness;\n#ifdef USE_METALNESSMAP\n\tvec4 texelMetalness = texture2D( metalnessMap, vUv );\n\tmetalnessFactor *= texelMetalness.b;\n#endif";
  8533. var metalnessmap_pars_fragment = "#ifdef USE_METALNESSMAP\n\tuniform sampler2D metalnessMap;\n#endif";
  8534. 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";
  8535. 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";
  8536. 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";
  8537. 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";
  8538. 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";
  8539. 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";
  8540. 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}";
  8541. var premultiplied_alpha_fragment = "#ifdef PREMULTIPLIED_ALPHA\n\tgl_FragColor.rgb *= gl_FragColor.a;\n#endif";
  8542. var project_vertex = "vec4 mvPosition = modelViewMatrix * vec4( transformed, 1.0 );\ngl_Position = projectionMatrix * mvPosition;";
  8543. var dithering_fragment = "#if defined( DITHERING )\n\tgl_FragColor.rgb = dithering( gl_FragColor.rgb );\n#endif";
  8544. 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";
  8545. var roughnessmap_fragment = "float roughnessFactor = roughness;\n#ifdef USE_ROUGHNESSMAP\n\tvec4 texelRoughness = texture2D( roughnessMap, vUv );\n\troughnessFactor *= texelRoughness.g;\n#endif";
  8546. var roughnessmap_pars_fragment = "#ifdef USE_ROUGHNESSMAP\n\tuniform sampler2D roughnessMap;\n#endif";
  8547. 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\tfloat dx2 = dx0 / 2.0;\n\t\t\tfloat dy2 = dy0 / 2.0;\n\t\t\tfloat dx3 = dx1 / 2.0;\n\t\t\tfloat dy3 = dy1 / 2.0;\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( dx2, dy2 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy2 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx3, dy2 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, 0.0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx2, 0.0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy, shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx3, 0.0 ), 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( dx2, dy3 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy3 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx3, dy3 ), 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 / 17.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";
  8548. 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";
  8549. 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";
  8550. 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}";
  8551. 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";
  8552. var skinning_pars_vertex = "#ifdef USE_SKINNING\n\tuniform mat4 bindMatrix;\n\tuniform mat4 bindMatrixInverse;\n\t#ifdef BONE_TEXTURE\n\t\tuniform highp 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";
  8553. 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";
  8554. 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";
  8555. 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";
  8556. var specularmap_pars_fragment = "#ifdef USE_SPECULARMAP\n\tuniform sampler2D specularMap;\n#endif";
  8557. var tonemapping_fragment = "#if defined( TONE_MAPPING )\n\tgl_FragColor.rgb = toneMapping( gl_FragColor.rgb );\n#endif";
  8558. 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}";
  8559. 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";
  8560. 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";
  8561. 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";
  8562. var uv2_pars_fragment = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tvarying vec2 vUv2;\n#endif";
  8563. var uv2_pars_vertex = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tattribute vec2 uv2;\n\tvarying vec2 vUv2;\n#endif";
  8564. var uv2_vertex = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tvUv2 = uv2;\n#endif";
  8565. var worldpos_vertex = "#if defined( USE_ENVMAP ) || defined( DISTANCE ) || defined ( USE_SHADOWMAP )\n\tvec4 worldPosition = modelMatrix * vec4( transformed, 1.0 );\n#endif";
  8566. 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}";
  8567. 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}";
  8568. 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}";
  8569. 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}";
  8570. 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}";
  8571. 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}";
  8572. 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}";
  8573. 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}";
  8574. 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}";
  8575. 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}";
  8576. 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}";
  8577. 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}";
  8578. 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}";
  8579. 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}";
  8580. 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}";
  8581. 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}";
  8582. 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}";
  8583. 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}";
  8584. 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}";
  8585. 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}";
  8586. 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}";
  8587. 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}";
  8588. 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>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\t#include <clipping_planes_fragment>\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}";
  8589. 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>\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#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#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || ( defined( USE_NORMALMAP ) && ! defined( OBJECTSPACE_NORMALMAP ) )\n\tvViewPosition = - mvPosition.xyz;\n#endif\n}";
  8590. 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}";
  8591. 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}";
  8592. 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}";
  8593. 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}";
  8594. 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}";
  8595. 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}";
  8596. var ShaderChunk = {
  8597. alphamap_fragment: alphamap_fragment,
  8598. alphamap_pars_fragment: alphamap_pars_fragment,
  8599. alphatest_fragment: alphatest_fragment,
  8600. aomap_fragment: aomap_fragment,
  8601. aomap_pars_fragment: aomap_pars_fragment,
  8602. begin_vertex: begin_vertex,
  8603. beginnormal_vertex: beginnormal_vertex,
  8604. bsdfs: bsdfs,
  8605. bumpmap_pars_fragment: bumpmap_pars_fragment,
  8606. clipping_planes_fragment: clipping_planes_fragment,
  8607. clipping_planes_pars_fragment: clipping_planes_pars_fragment,
  8608. clipping_planes_pars_vertex: clipping_planes_pars_vertex,
  8609. clipping_planes_vertex: clipping_planes_vertex,
  8610. color_fragment: color_fragment,
  8611. color_pars_fragment: color_pars_fragment,
  8612. color_pars_vertex: color_pars_vertex,
  8613. color_vertex: color_vertex,
  8614. common: common,
  8615. cube_uv_reflection_fragment: cube_uv_reflection_fragment,
  8616. defaultnormal_vertex: defaultnormal_vertex,
  8617. displacementmap_pars_vertex: displacementmap_pars_vertex,
  8618. displacementmap_vertex: displacementmap_vertex,
  8619. emissivemap_fragment: emissivemap_fragment,
  8620. emissivemap_pars_fragment: emissivemap_pars_fragment,
  8621. encodings_fragment: encodings_fragment,
  8622. encodings_pars_fragment: encodings_pars_fragment,
  8623. envmap_fragment: envmap_fragment,
  8624. envmap_pars_fragment: envmap_pars_fragment,
  8625. envmap_pars_vertex: envmap_pars_vertex,
  8626. envmap_physical_pars_fragment: envmap_physical_pars_fragment,
  8627. envmap_vertex: envmap_vertex,
  8628. fog_vertex: fog_vertex,
  8629. fog_pars_vertex: fog_pars_vertex,
  8630. fog_fragment: fog_fragment,
  8631. fog_pars_fragment: fog_pars_fragment,
  8632. gradientmap_pars_fragment: gradientmap_pars_fragment,
  8633. lightmap_fragment: lightmap_fragment,
  8634. lightmap_pars_fragment: lightmap_pars_fragment,
  8635. lights_lambert_vertex: lights_lambert_vertex,
  8636. lights_pars_begin: lights_pars_begin,
  8637. lights_phong_fragment: lights_phong_fragment,
  8638. lights_phong_pars_fragment: lights_phong_pars_fragment,
  8639. lights_physical_fragment: lights_physical_fragment,
  8640. lights_physical_pars_fragment: lights_physical_pars_fragment,
  8641. lights_fragment_begin: lights_fragment_begin,
  8642. lights_fragment_maps: lights_fragment_maps,
  8643. lights_fragment_end: lights_fragment_end,
  8644. logdepthbuf_fragment: logdepthbuf_fragment,
  8645. logdepthbuf_pars_fragment: logdepthbuf_pars_fragment,
  8646. logdepthbuf_pars_vertex: logdepthbuf_pars_vertex,
  8647. logdepthbuf_vertex: logdepthbuf_vertex,
  8648. map_fragment: map_fragment,
  8649. map_pars_fragment: map_pars_fragment,
  8650. map_particle_fragment: map_particle_fragment,
  8651. map_particle_pars_fragment: map_particle_pars_fragment,
  8652. metalnessmap_fragment: metalnessmap_fragment,
  8653. metalnessmap_pars_fragment: metalnessmap_pars_fragment,
  8654. morphnormal_vertex: morphnormal_vertex,
  8655. morphtarget_pars_vertex: morphtarget_pars_vertex,
  8656. morphtarget_vertex: morphtarget_vertex,
  8657. normal_fragment_begin: normal_fragment_begin,
  8658. normal_fragment_maps: normal_fragment_maps,
  8659. normalmap_pars_fragment: normalmap_pars_fragment,
  8660. packing: packing,
  8661. premultiplied_alpha_fragment: premultiplied_alpha_fragment,
  8662. project_vertex: project_vertex,
  8663. dithering_fragment: dithering_fragment,
  8664. dithering_pars_fragment: dithering_pars_fragment,
  8665. roughnessmap_fragment: roughnessmap_fragment,
  8666. roughnessmap_pars_fragment: roughnessmap_pars_fragment,
  8667. shadowmap_pars_fragment: shadowmap_pars_fragment,
  8668. shadowmap_pars_vertex: shadowmap_pars_vertex,
  8669. shadowmap_vertex: shadowmap_vertex,
  8670. shadowmask_pars_fragment: shadowmask_pars_fragment,
  8671. skinbase_vertex: skinbase_vertex,
  8672. skinning_pars_vertex: skinning_pars_vertex,
  8673. skinning_vertex: skinning_vertex,
  8674. skinnormal_vertex: skinnormal_vertex,
  8675. specularmap_fragment: specularmap_fragment,
  8676. specularmap_pars_fragment: specularmap_pars_fragment,
  8677. tonemapping_fragment: tonemapping_fragment,
  8678. tonemapping_pars_fragment: tonemapping_pars_fragment,
  8679. uv_pars_fragment: uv_pars_fragment,
  8680. uv_pars_vertex: uv_pars_vertex,
  8681. uv_vertex: uv_vertex,
  8682. uv2_pars_fragment: uv2_pars_fragment,
  8683. uv2_pars_vertex: uv2_pars_vertex,
  8684. uv2_vertex: uv2_vertex,
  8685. worldpos_vertex: worldpos_vertex,
  8686. background_frag: background_frag,
  8687. background_vert: background_vert,
  8688. cube_frag: cube_frag,
  8689. cube_vert: cube_vert,
  8690. depth_frag: depth_frag,
  8691. depth_vert: depth_vert,
  8692. distanceRGBA_frag: distanceRGBA_frag,
  8693. distanceRGBA_vert: distanceRGBA_vert,
  8694. equirect_frag: equirect_frag,
  8695. equirect_vert: equirect_vert,
  8696. linedashed_frag: linedashed_frag,
  8697. linedashed_vert: linedashed_vert,
  8698. meshbasic_frag: meshbasic_frag,
  8699. meshbasic_vert: meshbasic_vert,
  8700. meshlambert_frag: meshlambert_frag,
  8701. meshlambert_vert: meshlambert_vert,
  8702. meshmatcap_frag: meshmatcap_frag,
  8703. meshmatcap_vert: meshmatcap_vert,
  8704. meshphong_frag: meshphong_frag,
  8705. meshphong_vert: meshphong_vert,
  8706. meshphysical_frag: meshphysical_frag,
  8707. meshphysical_vert: meshphysical_vert,
  8708. normal_frag: normal_frag,
  8709. normal_vert: normal_vert,
  8710. points_frag: points_frag,
  8711. points_vert: points_vert,
  8712. shadow_frag: shadow_frag,
  8713. shadow_vert: shadow_vert,
  8714. sprite_frag: sprite_frag,
  8715. sprite_vert: sprite_vert
  8716. };
  8717. /**
  8718. * Uniforms library for shared webgl shaders
  8719. */
  8720. var UniformsLib = {
  8721. common: {
  8722. diffuse: { value: new Color( 0xeeeeee ) },
  8723. opacity: { value: 1.0 },
  8724. map: { value: null },
  8725. uvTransform: { value: new Matrix3() },
  8726. alphaMap: { value: null },
  8727. },
  8728. specularmap: {
  8729. specularMap: { value: null },
  8730. },
  8731. envmap: {
  8732. envMap: { value: null },
  8733. flipEnvMap: { value: - 1 },
  8734. reflectivity: { value: 1.0 },
  8735. refractionRatio: { value: 0.98 },
  8736. maxMipLevel: { value: 0 }
  8737. },
  8738. aomap: {
  8739. aoMap: { value: null },
  8740. aoMapIntensity: { value: 1 }
  8741. },
  8742. lightmap: {
  8743. lightMap: { value: null },
  8744. lightMapIntensity: { value: 1 }
  8745. },
  8746. emissivemap: {
  8747. emissiveMap: { value: null }
  8748. },
  8749. bumpmap: {
  8750. bumpMap: { value: null },
  8751. bumpScale: { value: 1 }
  8752. },
  8753. normalmap: {
  8754. normalMap: { value: null },
  8755. normalScale: { value: new Vector2( 1, 1 ) }
  8756. },
  8757. displacementmap: {
  8758. displacementMap: { value: null },
  8759. displacementScale: { value: 1 },
  8760. displacementBias: { value: 0 }
  8761. },
  8762. roughnessmap: {
  8763. roughnessMap: { value: null }
  8764. },
  8765. metalnessmap: {
  8766. metalnessMap: { value: null }
  8767. },
  8768. gradientmap: {
  8769. gradientMap: { value: null }
  8770. },
  8771. fog: {
  8772. fogDensity: { value: 0.00025 },
  8773. fogNear: { value: 1 },
  8774. fogFar: { value: 2000 },
  8775. fogColor: { value: new Color( 0xffffff ) }
  8776. },
  8777. lights: {
  8778. ambientLightColor: { value: [] },
  8779. lightProbe: { value: [] },
  8780. directionalLights: { value: [], properties: {
  8781. direction: {},
  8782. color: {},
  8783. shadow: {},
  8784. shadowBias: {},
  8785. shadowRadius: {},
  8786. shadowMapSize: {}
  8787. } },
  8788. directionalShadowMap: { value: [] },
  8789. directionalShadowMatrix: { value: [] },
  8790. spotLights: { value: [], properties: {
  8791. color: {},
  8792. position: {},
  8793. direction: {},
  8794. distance: {},
  8795. coneCos: {},
  8796. penumbraCos: {},
  8797. decay: {},
  8798. shadow: {},
  8799. shadowBias: {},
  8800. shadowRadius: {},
  8801. shadowMapSize: {}
  8802. } },
  8803. spotShadowMap: { value: [] },
  8804. spotShadowMatrix: { value: [] },
  8805. pointLights: { value: [], properties: {
  8806. color: {},
  8807. position: {},
  8808. decay: {},
  8809. distance: {},
  8810. shadow: {},
  8811. shadowBias: {},
  8812. shadowRadius: {},
  8813. shadowMapSize: {},
  8814. shadowCameraNear: {},
  8815. shadowCameraFar: {}
  8816. } },
  8817. pointShadowMap: { value: [] },
  8818. pointShadowMatrix: { value: [] },
  8819. hemisphereLights: { value: [], properties: {
  8820. direction: {},
  8821. skyColor: {},
  8822. groundColor: {}
  8823. } },
  8824. // TODO (abelnation): RectAreaLight BRDF data needs to be moved from example to main src
  8825. rectAreaLights: { value: [], properties: {
  8826. color: {},
  8827. position: {},
  8828. width: {},
  8829. height: {}
  8830. } }
  8831. },
  8832. points: {
  8833. diffuse: { value: new Color( 0xeeeeee ) },
  8834. opacity: { value: 1.0 },
  8835. size: { value: 1.0 },
  8836. scale: { value: 1.0 },
  8837. map: { value: null },
  8838. uvTransform: { value: new Matrix3() }
  8839. },
  8840. sprite: {
  8841. diffuse: { value: new Color( 0xeeeeee ) },
  8842. opacity: { value: 1.0 },
  8843. center: { value: new Vector2( 0.5, 0.5 ) },
  8844. rotation: { value: 0.0 },
  8845. map: { value: null },
  8846. uvTransform: { value: new Matrix3() }
  8847. }
  8848. };
  8849. /**
  8850. * @author alteredq / http://alteredqualia.com/
  8851. * @author mrdoob / http://mrdoob.com/
  8852. * @author mikael emtinger / http://gomo.se/
  8853. */
  8854. var ShaderLib = {
  8855. basic: {
  8856. uniforms: mergeUniforms( [
  8857. UniformsLib.common,
  8858. UniformsLib.specularmap,
  8859. UniformsLib.envmap,
  8860. UniformsLib.aomap,
  8861. UniformsLib.lightmap,
  8862. UniformsLib.fog
  8863. ] ),
  8864. vertexShader: ShaderChunk.meshbasic_vert,
  8865. fragmentShader: ShaderChunk.meshbasic_frag
  8866. },
  8867. lambert: {
  8868. uniforms: mergeUniforms( [
  8869. UniformsLib.common,
  8870. UniformsLib.specularmap,
  8871. UniformsLib.envmap,
  8872. UniformsLib.aomap,
  8873. UniformsLib.lightmap,
  8874. UniformsLib.emissivemap,
  8875. UniformsLib.fog,
  8876. UniformsLib.lights,
  8877. {
  8878. emissive: { value: new Color( 0x000000 ) }
  8879. }
  8880. ] ),
  8881. vertexShader: ShaderChunk.meshlambert_vert,
  8882. fragmentShader: ShaderChunk.meshlambert_frag
  8883. },
  8884. phong: {
  8885. uniforms: mergeUniforms( [
  8886. UniformsLib.common,
  8887. UniformsLib.specularmap,
  8888. UniformsLib.envmap,
  8889. UniformsLib.aomap,
  8890. UniformsLib.lightmap,
  8891. UniformsLib.emissivemap,
  8892. UniformsLib.bumpmap,
  8893. UniformsLib.normalmap,
  8894. UniformsLib.displacementmap,
  8895. UniformsLib.gradientmap,
  8896. UniformsLib.fog,
  8897. UniformsLib.lights,
  8898. {
  8899. emissive: { value: new Color( 0x000000 ) },
  8900. specular: { value: new Color( 0x111111 ) },
  8901. shininess: { value: 30 }
  8902. }
  8903. ] ),
  8904. vertexShader: ShaderChunk.meshphong_vert,
  8905. fragmentShader: ShaderChunk.meshphong_frag
  8906. },
  8907. standard: {
  8908. uniforms: mergeUniforms( [
  8909. UniformsLib.common,
  8910. UniformsLib.envmap,
  8911. UniformsLib.aomap,
  8912. UniformsLib.lightmap,
  8913. UniformsLib.emissivemap,
  8914. UniformsLib.bumpmap,
  8915. UniformsLib.normalmap,
  8916. UniformsLib.displacementmap,
  8917. UniformsLib.roughnessmap,
  8918. UniformsLib.metalnessmap,
  8919. UniformsLib.fog,
  8920. UniformsLib.lights,
  8921. {
  8922. emissive: { value: new Color( 0x000000 ) },
  8923. roughness: { value: 0.5 },
  8924. metalness: { value: 0.5 },
  8925. envMapIntensity: { value: 1 } // temporary
  8926. }
  8927. ] ),
  8928. vertexShader: ShaderChunk.meshphysical_vert,
  8929. fragmentShader: ShaderChunk.meshphysical_frag
  8930. },
  8931. matcap: {
  8932. uniforms: mergeUniforms( [
  8933. UniformsLib.common,
  8934. UniformsLib.bumpmap,
  8935. UniformsLib.normalmap,
  8936. UniformsLib.displacementmap,
  8937. UniformsLib.fog,
  8938. {
  8939. matcap: { value: null }
  8940. }
  8941. ] ),
  8942. vertexShader: ShaderChunk.meshmatcap_vert,
  8943. fragmentShader: ShaderChunk.meshmatcap_frag
  8944. },
  8945. points: {
  8946. uniforms: mergeUniforms( [
  8947. UniformsLib.points,
  8948. UniformsLib.fog
  8949. ] ),
  8950. vertexShader: ShaderChunk.points_vert,
  8951. fragmentShader: ShaderChunk.points_frag
  8952. },
  8953. dashed: {
  8954. uniforms: mergeUniforms( [
  8955. UniformsLib.common,
  8956. UniformsLib.fog,
  8957. {
  8958. scale: { value: 1 },
  8959. dashSize: { value: 1 },
  8960. totalSize: { value: 2 }
  8961. }
  8962. ] ),
  8963. vertexShader: ShaderChunk.linedashed_vert,
  8964. fragmentShader: ShaderChunk.linedashed_frag
  8965. },
  8966. depth: {
  8967. uniforms: mergeUniforms( [
  8968. UniformsLib.common,
  8969. UniformsLib.displacementmap
  8970. ] ),
  8971. vertexShader: ShaderChunk.depth_vert,
  8972. fragmentShader: ShaderChunk.depth_frag
  8973. },
  8974. normal: {
  8975. uniforms: mergeUniforms( [
  8976. UniformsLib.common,
  8977. UniformsLib.bumpmap,
  8978. UniformsLib.normalmap,
  8979. UniformsLib.displacementmap,
  8980. {
  8981. opacity: { value: 1.0 }
  8982. }
  8983. ] ),
  8984. vertexShader: ShaderChunk.normal_vert,
  8985. fragmentShader: ShaderChunk.normal_frag
  8986. },
  8987. sprite: {
  8988. uniforms: mergeUniforms( [
  8989. UniformsLib.sprite,
  8990. UniformsLib.fog
  8991. ] ),
  8992. vertexShader: ShaderChunk.sprite_vert,
  8993. fragmentShader: ShaderChunk.sprite_frag
  8994. },
  8995. background: {
  8996. uniforms: {
  8997. uvTransform: { value: new Matrix3() },
  8998. t2D: { value: null },
  8999. },
  9000. vertexShader: ShaderChunk.background_vert,
  9001. fragmentShader: ShaderChunk.background_frag
  9002. },
  9003. /* -------------------------------------------------------------------------
  9004. // Cube map shader
  9005. ------------------------------------------------------------------------- */
  9006. cube: {
  9007. uniforms: {
  9008. tCube: { value: null },
  9009. tFlip: { value: - 1 },
  9010. opacity: { value: 1.0 }
  9011. },
  9012. vertexShader: ShaderChunk.cube_vert,
  9013. fragmentShader: ShaderChunk.cube_frag
  9014. },
  9015. equirect: {
  9016. uniforms: {
  9017. tEquirect: { value: null },
  9018. },
  9019. vertexShader: ShaderChunk.equirect_vert,
  9020. fragmentShader: ShaderChunk.equirect_frag
  9021. },
  9022. distanceRGBA: {
  9023. uniforms: mergeUniforms( [
  9024. UniformsLib.common,
  9025. UniformsLib.displacementmap,
  9026. {
  9027. referencePosition: { value: new Vector3() },
  9028. nearDistance: { value: 1 },
  9029. farDistance: { value: 1000 }
  9030. }
  9031. ] ),
  9032. vertexShader: ShaderChunk.distanceRGBA_vert,
  9033. fragmentShader: ShaderChunk.distanceRGBA_frag
  9034. },
  9035. shadow: {
  9036. uniforms: mergeUniforms( [
  9037. UniformsLib.lights,
  9038. UniformsLib.fog,
  9039. {
  9040. color: { value: new Color( 0x00000 ) },
  9041. opacity: { value: 1.0 }
  9042. },
  9043. ] ),
  9044. vertexShader: ShaderChunk.shadow_vert,
  9045. fragmentShader: ShaderChunk.shadow_frag
  9046. }
  9047. };
  9048. ShaderLib.physical = {
  9049. uniforms: mergeUniforms( [
  9050. ShaderLib.standard.uniforms,
  9051. {
  9052. clearCoat: { value: 0 },
  9053. clearCoatRoughness: { value: 0 }
  9054. }
  9055. ] ),
  9056. vertexShader: ShaderChunk.meshphysical_vert,
  9057. fragmentShader: ShaderChunk.meshphysical_frag
  9058. };
  9059. /**
  9060. * @author mrdoob / http://mrdoob.com/
  9061. */
  9062. function WebGLAnimation() {
  9063. var context = null;
  9064. var isAnimating = false;
  9065. var animationLoop = null;
  9066. function onAnimationFrame( time, frame ) {
  9067. if ( isAnimating === false ) return;
  9068. animationLoop( time, frame );
  9069. context.requestAnimationFrame( onAnimationFrame );
  9070. }
  9071. return {
  9072. start: function () {
  9073. if ( isAnimating === true ) return;
  9074. if ( animationLoop === null ) return;
  9075. context.requestAnimationFrame( onAnimationFrame );
  9076. isAnimating = true;
  9077. },
  9078. stop: function () {
  9079. isAnimating = false;
  9080. },
  9081. setAnimationLoop: function ( callback ) {
  9082. animationLoop = callback;
  9083. },
  9084. setContext: function ( value ) {
  9085. context = value;
  9086. }
  9087. };
  9088. }
  9089. /**
  9090. * @author mrdoob / http://mrdoob.com/
  9091. */
  9092. function WebGLAttributes( gl ) {
  9093. var buffers = new WeakMap();
  9094. function createBuffer( attribute, bufferType ) {
  9095. var array = attribute.array;
  9096. var usage = attribute.dynamic ? 35048 : 35044;
  9097. var buffer = gl.createBuffer();
  9098. gl.bindBuffer( bufferType, buffer );
  9099. gl.bufferData( bufferType, array, usage );
  9100. attribute.onUploadCallback();
  9101. var type = 5126;
  9102. if ( array instanceof Float32Array ) {
  9103. type = 5126;
  9104. } else if ( array instanceof Float64Array ) {
  9105. console.warn( 'THREE.WebGLAttributes: Unsupported data buffer format: Float64Array.' );
  9106. } else if ( array instanceof Uint16Array ) {
  9107. type = 5123;
  9108. } else if ( array instanceof Int16Array ) {
  9109. type = 5122;
  9110. } else if ( array instanceof Uint32Array ) {
  9111. type = 5125;
  9112. } else if ( array instanceof Int32Array ) {
  9113. type = 5124;
  9114. } else if ( array instanceof Int8Array ) {
  9115. type = 5120;
  9116. } else if ( array instanceof Uint8Array ) {
  9117. type = 5121;
  9118. }
  9119. return {
  9120. buffer: buffer,
  9121. type: type,
  9122. bytesPerElement: array.BYTES_PER_ELEMENT,
  9123. version: attribute.version
  9124. };
  9125. }
  9126. function updateBuffer( buffer, attribute, bufferType ) {
  9127. var array = attribute.array;
  9128. var updateRange = attribute.updateRange;
  9129. gl.bindBuffer( bufferType, buffer );
  9130. if ( attribute.dynamic === false ) {
  9131. gl.bufferData( bufferType, array, 35044 );
  9132. } else if ( updateRange.count === - 1 ) {
  9133. // Not using update ranges
  9134. gl.bufferSubData( bufferType, 0, array );
  9135. } else if ( updateRange.count === 0 ) {
  9136. 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.' );
  9137. } else {
  9138. gl.bufferSubData( bufferType, updateRange.offset * array.BYTES_PER_ELEMENT,
  9139. array.subarray( updateRange.offset, updateRange.offset + updateRange.count ) );
  9140. updateRange.count = - 1; // reset range
  9141. }
  9142. }
  9143. //
  9144. function get( attribute ) {
  9145. if ( attribute.isInterleavedBufferAttribute ) attribute = attribute.data;
  9146. return buffers.get( attribute );
  9147. }
  9148. function remove( attribute ) {
  9149. if ( attribute.isInterleavedBufferAttribute ) attribute = attribute.data;
  9150. var data = buffers.get( attribute );
  9151. if ( data ) {
  9152. gl.deleteBuffer( data.buffer );
  9153. buffers.delete( attribute );
  9154. }
  9155. }
  9156. function update( attribute, bufferType ) {
  9157. if ( attribute.isInterleavedBufferAttribute ) attribute = attribute.data;
  9158. var data = buffers.get( attribute );
  9159. if ( data === undefined ) {
  9160. buffers.set( attribute, createBuffer( attribute, bufferType ) );
  9161. } else if ( data.version < attribute.version ) {
  9162. updateBuffer( data.buffer, attribute, bufferType );
  9163. data.version = attribute.version;
  9164. }
  9165. }
  9166. return {
  9167. get: get,
  9168. remove: remove,
  9169. update: update
  9170. };
  9171. }
  9172. /**
  9173. * @author mrdoob / http://mrdoob.com/
  9174. * @author Mugen87 / https://github.com/Mugen87
  9175. */
  9176. // PlaneGeometry
  9177. function PlaneGeometry( width, height, widthSegments, heightSegments ) {
  9178. Geometry.call( this );
  9179. this.type = 'PlaneGeometry';
  9180. this.parameters = {
  9181. width: width,
  9182. height: height,
  9183. widthSegments: widthSegments,
  9184. heightSegments: heightSegments
  9185. };
  9186. this.fromBufferGeometry( new PlaneBufferGeometry( width, height, widthSegments, heightSegments ) );
  9187. this.mergeVertices();
  9188. }
  9189. PlaneGeometry.prototype = Object.create( Geometry.prototype );
  9190. PlaneGeometry.prototype.constructor = PlaneGeometry;
  9191. // PlaneBufferGeometry
  9192. function PlaneBufferGeometry( width, height, widthSegments, heightSegments ) {
  9193. BufferGeometry.call( this );
  9194. this.type = 'PlaneBufferGeometry';
  9195. this.parameters = {
  9196. width: width,
  9197. height: height,
  9198. widthSegments: widthSegments,
  9199. heightSegments: heightSegments
  9200. };
  9201. width = width || 1;
  9202. height = height || 1;
  9203. var width_half = width / 2;
  9204. var height_half = height / 2;
  9205. var gridX = Math.floor( widthSegments ) || 1;
  9206. var gridY = Math.floor( heightSegments ) || 1;
  9207. var gridX1 = gridX + 1;
  9208. var gridY1 = gridY + 1;
  9209. var segment_width = width / gridX;
  9210. var segment_height = height / gridY;
  9211. var ix, iy;
  9212. // buffers
  9213. var indices = [];
  9214. var vertices = [];
  9215. var normals = [];
  9216. var uvs = [];
  9217. // generate vertices, normals and uvs
  9218. for ( iy = 0; iy < gridY1; iy ++ ) {
  9219. var y = iy * segment_height - height_half;
  9220. for ( ix = 0; ix < gridX1; ix ++ ) {
  9221. var x = ix * segment_width - width_half;
  9222. vertices.push( x, - y, 0 );
  9223. normals.push( 0, 0, 1 );
  9224. uvs.push( ix / gridX );
  9225. uvs.push( 1 - ( iy / gridY ) );
  9226. }
  9227. }
  9228. // indices
  9229. for ( iy = 0; iy < gridY; iy ++ ) {
  9230. for ( ix = 0; ix < gridX; ix ++ ) {
  9231. var a = ix + gridX1 * iy;
  9232. var b = ix + gridX1 * ( iy + 1 );
  9233. var c = ( ix + 1 ) + gridX1 * ( iy + 1 );
  9234. var d = ( ix + 1 ) + gridX1 * iy;
  9235. // faces
  9236. indices.push( a, b, d );
  9237. indices.push( b, c, d );
  9238. }
  9239. }
  9240. // build geometry
  9241. this.setIndex( indices );
  9242. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  9243. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  9244. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  9245. }
  9246. PlaneBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  9247. PlaneBufferGeometry.prototype.constructor = PlaneBufferGeometry;
  9248. /**
  9249. * @author mrdoob / http://mrdoob.com/
  9250. */
  9251. function WebGLBackground( renderer, state, objects, premultipliedAlpha ) {
  9252. var clearColor = new Color( 0x000000 );
  9253. var clearAlpha = 0;
  9254. var planeMesh;
  9255. var boxMesh;
  9256. // Store the current background texture and its `version`
  9257. // so we can recompile the material accordingly.
  9258. var currentBackground = null;
  9259. var currentBackgroundVersion = 0;
  9260. function render( renderList, scene, camera, forceClear ) {
  9261. var background = scene.background;
  9262. // Ignore background in AR
  9263. // TODO: Reconsider this.
  9264. var vr = renderer.vr;
  9265. var session = vr.getSession && vr.getSession();
  9266. if ( session && session.environmentBlendMode === 'additive' ) {
  9267. background = null;
  9268. }
  9269. if ( background === null ) {
  9270. setClear( clearColor, clearAlpha );
  9271. currentBackground = null;
  9272. currentBackgroundVersion = 0;
  9273. } else if ( background && background.isColor ) {
  9274. setClear( background, 1 );
  9275. forceClear = true;
  9276. currentBackground = null;
  9277. currentBackgroundVersion = 0;
  9278. }
  9279. if ( renderer.autoClear || forceClear ) {
  9280. renderer.clear( renderer.autoClearColor, renderer.autoClearDepth, renderer.autoClearStencil );
  9281. }
  9282. if ( background && ( background.isCubeTexture || background.isWebGLRenderTargetCube ) ) {
  9283. if ( boxMesh === undefined ) {
  9284. boxMesh = new Mesh(
  9285. new BoxBufferGeometry( 1, 1, 1 ),
  9286. new ShaderMaterial( {
  9287. type: 'BackgroundCubeMaterial',
  9288. uniforms: cloneUniforms( ShaderLib.cube.uniforms ),
  9289. vertexShader: ShaderLib.cube.vertexShader,
  9290. fragmentShader: ShaderLib.cube.fragmentShader,
  9291. side: BackSide,
  9292. depthTest: false,
  9293. depthWrite: false,
  9294. fog: false
  9295. } )
  9296. );
  9297. boxMesh.geometry.removeAttribute( 'normal' );
  9298. boxMesh.geometry.removeAttribute( 'uv' );
  9299. boxMesh.onBeforeRender = function ( renderer, scene, camera ) {
  9300. this.matrixWorld.copyPosition( camera.matrixWorld );
  9301. };
  9302. // enable code injection for non-built-in material
  9303. Object.defineProperty( boxMesh.material, 'map', {
  9304. get: function () {
  9305. return this.uniforms.tCube.value;
  9306. }
  9307. } );
  9308. objects.update( boxMesh );
  9309. }
  9310. var texture = background.isWebGLRenderTargetCube ? background.texture : background;
  9311. boxMesh.material.uniforms.tCube.value = texture;
  9312. boxMesh.material.uniforms.tFlip.value = ( background.isWebGLRenderTargetCube ) ? 1 : - 1;
  9313. if ( currentBackground !== background ||
  9314. currentBackgroundVersion !== texture.version ) {
  9315. boxMesh.material.needsUpdate = true;
  9316. currentBackground = background;
  9317. currentBackgroundVersion = texture.version;
  9318. }
  9319. // push to the pre-sorted opaque render list
  9320. renderList.unshift( boxMesh, boxMesh.geometry, boxMesh.material, 0, 0, null );
  9321. } else if ( background && background.isTexture ) {
  9322. if ( planeMesh === undefined ) {
  9323. planeMesh = new Mesh(
  9324. new PlaneBufferGeometry( 2, 2 ),
  9325. new ShaderMaterial( {
  9326. type: 'BackgroundMaterial',
  9327. uniforms: cloneUniforms( ShaderLib.background.uniforms ),
  9328. vertexShader: ShaderLib.background.vertexShader,
  9329. fragmentShader: ShaderLib.background.fragmentShader,
  9330. side: FrontSide,
  9331. depthTest: false,
  9332. depthWrite: false,
  9333. fog: false
  9334. } )
  9335. );
  9336. planeMesh.geometry.removeAttribute( 'normal' );
  9337. // enable code injection for non-built-in material
  9338. Object.defineProperty( planeMesh.material, 'map', {
  9339. get: function () {
  9340. return this.uniforms.t2D.value;
  9341. }
  9342. } );
  9343. objects.update( planeMesh );
  9344. }
  9345. planeMesh.material.uniforms.t2D.value = background;
  9346. if ( background.matrixAutoUpdate === true ) {
  9347. background.updateMatrix();
  9348. }
  9349. planeMesh.material.uniforms.uvTransform.value.copy( background.matrix );
  9350. if ( currentBackground !== background ||
  9351. currentBackgroundVersion !== background.version ) {
  9352. planeMesh.material.needsUpdate = true;
  9353. currentBackground = background;
  9354. currentBackgroundVersion = background.version;
  9355. }
  9356. // push to the pre-sorted opaque render list
  9357. renderList.unshift( planeMesh, planeMesh.geometry, planeMesh.material, 0, 0, null );
  9358. }
  9359. }
  9360. function setClear( color, alpha ) {
  9361. state.buffers.color.setClear( color.r, color.g, color.b, alpha, premultipliedAlpha );
  9362. }
  9363. return {
  9364. getClearColor: function () {
  9365. return clearColor;
  9366. },
  9367. setClearColor: function ( color, alpha ) {
  9368. clearColor.set( color );
  9369. clearAlpha = alpha !== undefined ? alpha : 1;
  9370. setClear( clearColor, clearAlpha );
  9371. },
  9372. getClearAlpha: function () {
  9373. return clearAlpha;
  9374. },
  9375. setClearAlpha: function ( alpha ) {
  9376. clearAlpha = alpha;
  9377. setClear( clearColor, clearAlpha );
  9378. },
  9379. render: render
  9380. };
  9381. }
  9382. /**
  9383. * @author mrdoob / http://mrdoob.com/
  9384. */
  9385. function WebGLBufferRenderer( gl, extensions, info, capabilities ) {
  9386. var mode;
  9387. function setMode( value ) {
  9388. mode = value;
  9389. }
  9390. function render( start, count ) {
  9391. gl.drawArrays( mode, start, count );
  9392. info.update( count, mode );
  9393. }
  9394. function renderInstances( geometry, start, count ) {
  9395. var extension;
  9396. if ( capabilities.isWebGL2 ) {
  9397. extension = gl;
  9398. } else {
  9399. extension = extensions.get( 'ANGLE_instanced_arrays' );
  9400. if ( extension === null ) {
  9401. console.error( 'THREE.WebGLBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  9402. return;
  9403. }
  9404. }
  9405. extension[ capabilities.isWebGL2 ? 'drawArraysInstanced' : 'drawArraysInstancedANGLE' ]( mode, start, count, geometry.maxInstancedCount );
  9406. info.update( count, mode, geometry.maxInstancedCount );
  9407. }
  9408. //
  9409. this.setMode = setMode;
  9410. this.render = render;
  9411. this.renderInstances = renderInstances;
  9412. }
  9413. /**
  9414. * @author mrdoob / http://mrdoob.com/
  9415. */
  9416. function WebGLCapabilities( gl, extensions, parameters ) {
  9417. var maxAnisotropy;
  9418. function getMaxAnisotropy() {
  9419. if ( maxAnisotropy !== undefined ) return maxAnisotropy;
  9420. var extension = extensions.get( 'EXT_texture_filter_anisotropic' );
  9421. if ( extension !== null ) {
  9422. maxAnisotropy = gl.getParameter( extension.MAX_TEXTURE_MAX_ANISOTROPY_EXT );
  9423. } else {
  9424. maxAnisotropy = 0;
  9425. }
  9426. return maxAnisotropy;
  9427. }
  9428. function getMaxPrecision( precision ) {
  9429. if ( precision === 'highp' ) {
  9430. if ( gl.getShaderPrecisionFormat( 35633, 36338 ).precision > 0 &&
  9431. gl.getShaderPrecisionFormat( 35632, 36338 ).precision > 0 ) {
  9432. return 'highp';
  9433. }
  9434. precision = 'mediump';
  9435. }
  9436. if ( precision === 'mediump' ) {
  9437. if ( gl.getShaderPrecisionFormat( 35633, 36337 ).precision > 0 &&
  9438. gl.getShaderPrecisionFormat( 35632, 36337 ).precision > 0 ) {
  9439. return 'mediump';
  9440. }
  9441. }
  9442. return 'lowp';
  9443. }
  9444. var isWebGL2 = typeof WebGL2RenderingContext !== 'undefined' && gl instanceof WebGL2RenderingContext;
  9445. var precision = parameters.precision !== undefined ? parameters.precision : 'highp';
  9446. var maxPrecision = getMaxPrecision( precision );
  9447. if ( maxPrecision !== precision ) {
  9448. console.warn( 'THREE.WebGLRenderer:', precision, 'not supported, using', maxPrecision, 'instead.' );
  9449. precision = maxPrecision;
  9450. }
  9451. var logarithmicDepthBuffer = parameters.logarithmicDepthBuffer === true;
  9452. var maxTextures = gl.getParameter( 34930 );
  9453. var maxVertexTextures = gl.getParameter( 35660 );
  9454. var maxTextureSize = gl.getParameter( 3379 );
  9455. var maxCubemapSize = gl.getParameter( 34076 );
  9456. var maxAttributes = gl.getParameter( 34921 );
  9457. var maxVertexUniforms = gl.getParameter( 36347 );
  9458. var maxVaryings = gl.getParameter( 36348 );
  9459. var maxFragmentUniforms = gl.getParameter( 36349 );
  9460. var vertexTextures = maxVertexTextures > 0;
  9461. var floatFragmentTextures = isWebGL2 || !! extensions.get( 'OES_texture_float' );
  9462. var floatVertexTextures = vertexTextures && floatFragmentTextures;
  9463. var maxSamples = isWebGL2 ? gl.getParameter( 36183 ) : 0;
  9464. return {
  9465. isWebGL2: isWebGL2,
  9466. getMaxAnisotropy: getMaxAnisotropy,
  9467. getMaxPrecision: getMaxPrecision,
  9468. precision: precision,
  9469. logarithmicDepthBuffer: logarithmicDepthBuffer,
  9470. maxTextures: maxTextures,
  9471. maxVertexTextures: maxVertexTextures,
  9472. maxTextureSize: maxTextureSize,
  9473. maxCubemapSize: maxCubemapSize,
  9474. maxAttributes: maxAttributes,
  9475. maxVertexUniforms: maxVertexUniforms,
  9476. maxVaryings: maxVaryings,
  9477. maxFragmentUniforms: maxFragmentUniforms,
  9478. vertexTextures: vertexTextures,
  9479. floatFragmentTextures: floatFragmentTextures,
  9480. floatVertexTextures: floatVertexTextures,
  9481. maxSamples: maxSamples
  9482. };
  9483. }
  9484. /**
  9485. * @author tschw
  9486. */
  9487. function WebGLClipping() {
  9488. var scope = this,
  9489. globalState = null,
  9490. numGlobalPlanes = 0,
  9491. localClippingEnabled = false,
  9492. renderingShadows = false,
  9493. plane = new Plane(),
  9494. viewNormalMatrix = new Matrix3(),
  9495. uniform = { value: null, needsUpdate: false };
  9496. this.uniform = uniform;
  9497. this.numPlanes = 0;
  9498. this.numIntersection = 0;
  9499. this.init = function ( planes, enableLocalClipping, camera ) {
  9500. var enabled =
  9501. planes.length !== 0 ||
  9502. enableLocalClipping ||
  9503. // enable state of previous frame - the clipping code has to
  9504. // run another frame in order to reset the state:
  9505. numGlobalPlanes !== 0 ||
  9506. localClippingEnabled;
  9507. localClippingEnabled = enableLocalClipping;
  9508. globalState = projectPlanes( planes, camera, 0 );
  9509. numGlobalPlanes = planes.length;
  9510. return enabled;
  9511. };
  9512. this.beginShadows = function () {
  9513. renderingShadows = true;
  9514. projectPlanes( null );
  9515. };
  9516. this.endShadows = function () {
  9517. renderingShadows = false;
  9518. resetGlobalState();
  9519. };
  9520. this.setState = function ( planes, clipIntersection, clipShadows, camera, cache, fromCache ) {
  9521. if ( ! localClippingEnabled || planes === null || planes.length === 0 || renderingShadows && ! clipShadows ) {
  9522. // there's no local clipping
  9523. if ( renderingShadows ) {
  9524. // there's no global clipping
  9525. projectPlanes( null );
  9526. } else {
  9527. resetGlobalState();
  9528. }
  9529. } else {
  9530. var nGlobal = renderingShadows ? 0 : numGlobalPlanes,
  9531. lGlobal = nGlobal * 4,
  9532. dstArray = cache.clippingState || null;
  9533. uniform.value = dstArray; // ensure unique state
  9534. dstArray = projectPlanes( planes, camera, lGlobal, fromCache );
  9535. for ( var i = 0; i !== lGlobal; ++ i ) {
  9536. dstArray[ i ] = globalState[ i ];
  9537. }
  9538. cache.clippingState = dstArray;
  9539. this.numIntersection = clipIntersection ? this.numPlanes : 0;
  9540. this.numPlanes += nGlobal;
  9541. }
  9542. };
  9543. function resetGlobalState() {
  9544. if ( uniform.value !== globalState ) {
  9545. uniform.value = globalState;
  9546. uniform.needsUpdate = numGlobalPlanes > 0;
  9547. }
  9548. scope.numPlanes = numGlobalPlanes;
  9549. scope.numIntersection = 0;
  9550. }
  9551. function projectPlanes( planes, camera, dstOffset, skipTransform ) {
  9552. var nPlanes = planes !== null ? planes.length : 0,
  9553. dstArray = null;
  9554. if ( nPlanes !== 0 ) {
  9555. dstArray = uniform.value;
  9556. if ( skipTransform !== true || dstArray === null ) {
  9557. var flatSize = dstOffset + nPlanes * 4,
  9558. viewMatrix = camera.matrixWorldInverse;
  9559. viewNormalMatrix.getNormalMatrix( viewMatrix );
  9560. if ( dstArray === null || dstArray.length < flatSize ) {
  9561. dstArray = new Float32Array( flatSize );
  9562. }
  9563. for ( var i = 0, i4 = dstOffset; i !== nPlanes; ++ i, i4 += 4 ) {
  9564. plane.copy( planes[ i ] ).applyMatrix4( viewMatrix, viewNormalMatrix );
  9565. plane.normal.toArray( dstArray, i4 );
  9566. dstArray[ i4 + 3 ] = plane.constant;
  9567. }
  9568. }
  9569. uniform.value = dstArray;
  9570. uniform.needsUpdate = true;
  9571. }
  9572. scope.numPlanes = nPlanes;
  9573. return dstArray;
  9574. }
  9575. }
  9576. /**
  9577. * @author mrdoob / http://mrdoob.com/
  9578. */
  9579. function WebGLExtensions( gl ) {
  9580. var extensions = {};
  9581. return {
  9582. get: function ( name ) {
  9583. if ( extensions[ name ] !== undefined ) {
  9584. return extensions[ name ];
  9585. }
  9586. var extension;
  9587. switch ( name ) {
  9588. case 'WEBGL_depth_texture':
  9589. extension = gl.getExtension( 'WEBGL_depth_texture' ) || gl.getExtension( 'MOZ_WEBGL_depth_texture' ) || gl.getExtension( 'WEBKIT_WEBGL_depth_texture' );
  9590. break;
  9591. case 'EXT_texture_filter_anisotropic':
  9592. extension = gl.getExtension( 'EXT_texture_filter_anisotropic' ) || gl.getExtension( 'MOZ_EXT_texture_filter_anisotropic' ) || gl.getExtension( 'WEBKIT_EXT_texture_filter_anisotropic' );
  9593. break;
  9594. case 'WEBGL_compressed_texture_s3tc':
  9595. extension = gl.getExtension( 'WEBGL_compressed_texture_s3tc' ) || gl.getExtension( 'MOZ_WEBGL_compressed_texture_s3tc' ) || gl.getExtension( 'WEBKIT_WEBGL_compressed_texture_s3tc' );
  9596. break;
  9597. case 'WEBGL_compressed_texture_pvrtc':
  9598. extension = gl.getExtension( 'WEBGL_compressed_texture_pvrtc' ) || gl.getExtension( 'WEBKIT_WEBGL_compressed_texture_pvrtc' );
  9599. break;
  9600. default:
  9601. extension = gl.getExtension( name );
  9602. }
  9603. if ( extension === null ) {
  9604. console.warn( 'THREE.WebGLRenderer: ' + name + ' extension not supported.' );
  9605. }
  9606. extensions[ name ] = extension;
  9607. return extension;
  9608. }
  9609. };
  9610. }
  9611. /**
  9612. * @author mrdoob / http://mrdoob.com/
  9613. */
  9614. function WebGLGeometries( gl, attributes, info ) {
  9615. var geometries = {};
  9616. var wireframeAttributes = {};
  9617. function onGeometryDispose( event ) {
  9618. var geometry = event.target;
  9619. var buffergeometry = geometries[ geometry.id ];
  9620. if ( buffergeometry.index !== null ) {
  9621. attributes.remove( buffergeometry.index );
  9622. }
  9623. for ( var name in buffergeometry.attributes ) {
  9624. attributes.remove( buffergeometry.attributes[ name ] );
  9625. }
  9626. geometry.removeEventListener( 'dispose', onGeometryDispose );
  9627. delete geometries[ geometry.id ];
  9628. var attribute = wireframeAttributes[ buffergeometry.id ];
  9629. if ( attribute ) {
  9630. attributes.remove( attribute );
  9631. delete wireframeAttributes[ buffergeometry.id ];
  9632. }
  9633. //
  9634. info.memory.geometries --;
  9635. }
  9636. function get( object, geometry ) {
  9637. var buffergeometry = geometries[ geometry.id ];
  9638. if ( buffergeometry ) return buffergeometry;
  9639. geometry.addEventListener( 'dispose', onGeometryDispose );
  9640. if ( geometry.isBufferGeometry ) {
  9641. buffergeometry = geometry;
  9642. } else if ( geometry.isGeometry ) {
  9643. if ( geometry._bufferGeometry === undefined ) {
  9644. geometry._bufferGeometry = new BufferGeometry().setFromObject( object );
  9645. }
  9646. buffergeometry = geometry._bufferGeometry;
  9647. }
  9648. geometries[ geometry.id ] = buffergeometry;
  9649. info.memory.geometries ++;
  9650. return buffergeometry;
  9651. }
  9652. function update( geometry ) {
  9653. var index = geometry.index;
  9654. var geometryAttributes = geometry.attributes;
  9655. if ( index !== null ) {
  9656. attributes.update( index, 34963 );
  9657. }
  9658. for ( var name in geometryAttributes ) {
  9659. attributes.update( geometryAttributes[ name ], 34962 );
  9660. }
  9661. // morph targets
  9662. var morphAttributes = geometry.morphAttributes;
  9663. for ( var name in morphAttributes ) {
  9664. var array = morphAttributes[ name ];
  9665. for ( var i = 0, l = array.length; i < l; i ++ ) {
  9666. attributes.update( array[ i ], 34962 );
  9667. }
  9668. }
  9669. }
  9670. function updateWireframeAttribute( geometry ) {
  9671. var indices = [];
  9672. var geometryIndex = geometry.index;
  9673. var geometryPosition = geometry.attributes.position;
  9674. var version = 0;
  9675. if ( geometryIndex !== null ) {
  9676. var array = geometryIndex.array;
  9677. version = geometryIndex.version;
  9678. for ( var i = 0, l = array.length; i < l; i += 3 ) {
  9679. var a = array[ i + 0 ];
  9680. var b = array[ i + 1 ];
  9681. var c = array[ i + 2 ];
  9682. indices.push( a, b, b, c, c, a );
  9683. }
  9684. } else {
  9685. var array = geometryPosition.array;
  9686. version = geometryPosition.version;
  9687. for ( var i = 0, l = ( array.length / 3 ) - 1; i < l; i += 3 ) {
  9688. var a = i + 0;
  9689. var b = i + 1;
  9690. var c = i + 2;
  9691. indices.push( a, b, b, c, c, a );
  9692. }
  9693. }
  9694. var attribute = new ( arrayMax( indices ) > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute )( indices, 1 );
  9695. attribute.version = version;
  9696. attributes.update( attribute, 34963 );
  9697. //
  9698. var previousAttribute = wireframeAttributes[ geometry.id ];
  9699. if ( previousAttribute ) attributes.remove( previousAttribute );
  9700. //
  9701. wireframeAttributes[ geometry.id ] = attribute;
  9702. }
  9703. function getWireframeAttribute( geometry ) {
  9704. var currentAttribute = wireframeAttributes[ geometry.id ];
  9705. if ( currentAttribute ) {
  9706. var geometryIndex = geometry.index;
  9707. if ( geometryIndex !== null ) {
  9708. // if the attribute is obsolete, create a new one
  9709. if ( currentAttribute.version < geometryIndex.version ) {
  9710. updateWireframeAttribute( geometry );
  9711. }
  9712. }
  9713. } else {
  9714. updateWireframeAttribute( geometry );
  9715. }
  9716. return wireframeAttributes[ geometry.id ];
  9717. }
  9718. return {
  9719. get: get,
  9720. update: update,
  9721. getWireframeAttribute: getWireframeAttribute
  9722. };
  9723. }
  9724. /**
  9725. * @author mrdoob / http://mrdoob.com/
  9726. */
  9727. function WebGLIndexedBufferRenderer( gl, extensions, info, capabilities ) {
  9728. var mode;
  9729. function setMode( value ) {
  9730. mode = value;
  9731. }
  9732. var type, bytesPerElement;
  9733. function setIndex( value ) {
  9734. type = value.type;
  9735. bytesPerElement = value.bytesPerElement;
  9736. }
  9737. function render( start, count ) {
  9738. gl.drawElements( mode, count, type, start * bytesPerElement );
  9739. info.update( count, mode );
  9740. }
  9741. function renderInstances( geometry, start, count ) {
  9742. var extension;
  9743. if ( capabilities.isWebGL2 ) {
  9744. extension = gl;
  9745. } else {
  9746. var extension = extensions.get( 'ANGLE_instanced_arrays' );
  9747. if ( extension === null ) {
  9748. console.error( 'THREE.WebGLIndexedBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  9749. return;
  9750. }
  9751. }
  9752. extension[ capabilities.isWebGL2 ? 'drawElementsInstanced' : 'drawElementsInstancedANGLE' ]( mode, count, type, start * bytesPerElement, geometry.maxInstancedCount );
  9753. info.update( count, mode, geometry.maxInstancedCount );
  9754. }
  9755. //
  9756. this.setMode = setMode;
  9757. this.setIndex = setIndex;
  9758. this.render = render;
  9759. this.renderInstances = renderInstances;
  9760. }
  9761. /**
  9762. * @author Mugen87 / https://github.com/Mugen87
  9763. */
  9764. function WebGLInfo( gl ) {
  9765. var memory = {
  9766. geometries: 0,
  9767. textures: 0
  9768. };
  9769. var render = {
  9770. frame: 0,
  9771. calls: 0,
  9772. triangles: 0,
  9773. points: 0,
  9774. lines: 0
  9775. };
  9776. function update( count, mode, instanceCount ) {
  9777. instanceCount = instanceCount || 1;
  9778. render.calls ++;
  9779. switch ( mode ) {
  9780. case 4:
  9781. render.triangles += instanceCount * ( count / 3 );
  9782. break;
  9783. case 5:
  9784. case 6:
  9785. render.triangles += instanceCount * ( count - 2 );
  9786. break;
  9787. case 1:
  9788. render.lines += instanceCount * ( count / 2 );
  9789. break;
  9790. case 3:
  9791. render.lines += instanceCount * ( count - 1 );
  9792. break;
  9793. case 2:
  9794. render.lines += instanceCount * count;
  9795. break;
  9796. case 0:
  9797. render.points += instanceCount * count;
  9798. break;
  9799. default:
  9800. console.error( 'THREE.WebGLInfo: Unknown draw mode:', mode );
  9801. break;
  9802. }
  9803. }
  9804. function reset() {
  9805. render.frame ++;
  9806. render.calls = 0;
  9807. render.triangles = 0;
  9808. render.points = 0;
  9809. render.lines = 0;
  9810. }
  9811. return {
  9812. memory: memory,
  9813. render: render,
  9814. programs: null,
  9815. autoReset: true,
  9816. reset: reset,
  9817. update: update
  9818. };
  9819. }
  9820. /**
  9821. * @author mrdoob / http://mrdoob.com/
  9822. */
  9823. function absNumericalSort( a, b ) {
  9824. return Math.abs( b[ 1 ] ) - Math.abs( a[ 1 ] );
  9825. }
  9826. function WebGLMorphtargets( gl ) {
  9827. var influencesList = {};
  9828. var morphInfluences = new Float32Array( 8 );
  9829. function update( object, geometry, material, program ) {
  9830. var objectInfluences = object.morphTargetInfluences;
  9831. var length = objectInfluences.length;
  9832. var influences = influencesList[ geometry.id ];
  9833. if ( influences === undefined ) {
  9834. // initialise list
  9835. influences = [];
  9836. for ( var i = 0; i < length; i ++ ) {
  9837. influences[ i ] = [ i, 0 ];
  9838. }
  9839. influencesList[ geometry.id ] = influences;
  9840. }
  9841. var morphTargets = material.morphTargets && geometry.morphAttributes.position;
  9842. var morphNormals = material.morphNormals && geometry.morphAttributes.normal;
  9843. // Remove current morphAttributes
  9844. for ( var i = 0; i < length; i ++ ) {
  9845. var influence = influences[ i ];
  9846. if ( influence[ 1 ] !== 0 ) {
  9847. if ( morphTargets ) geometry.removeAttribute( 'morphTarget' + i );
  9848. if ( morphNormals ) geometry.removeAttribute( 'morphNormal' + i );
  9849. }
  9850. }
  9851. // Collect influences
  9852. for ( var i = 0; i < length; i ++ ) {
  9853. var influence = influences[ i ];
  9854. influence[ 0 ] = i;
  9855. influence[ 1 ] = objectInfluences[ i ];
  9856. }
  9857. influences.sort( absNumericalSort );
  9858. // Add morphAttributes
  9859. for ( var i = 0; i < 8; i ++ ) {
  9860. var influence = influences[ i ];
  9861. if ( influence ) {
  9862. var index = influence[ 0 ];
  9863. var value = influence[ 1 ];
  9864. if ( value ) {
  9865. if ( morphTargets ) geometry.addAttribute( 'morphTarget' + i, morphTargets[ index ] );
  9866. if ( morphNormals ) geometry.addAttribute( 'morphNormal' + i, morphNormals[ index ] );
  9867. morphInfluences[ i ] = value;
  9868. continue;
  9869. }
  9870. }
  9871. morphInfluences[ i ] = 0;
  9872. }
  9873. program.getUniforms().setValue( gl, 'morphTargetInfluences', morphInfluences );
  9874. }
  9875. return {
  9876. update: update
  9877. };
  9878. }
  9879. /**
  9880. * @author mrdoob / http://mrdoob.com/
  9881. */
  9882. function WebGLObjects( geometries, info ) {
  9883. var updateList = {};
  9884. function update( object ) {
  9885. var frame = info.render.frame;
  9886. var geometry = object.geometry;
  9887. var buffergeometry = geometries.get( object, geometry );
  9888. // Update once per frame
  9889. if ( updateList[ buffergeometry.id ] !== frame ) {
  9890. if ( geometry.isGeometry ) {
  9891. buffergeometry.updateFromObject( object );
  9892. }
  9893. geometries.update( buffergeometry );
  9894. updateList[ buffergeometry.id ] = frame;
  9895. }
  9896. return buffergeometry;
  9897. }
  9898. function dispose() {
  9899. updateList = {};
  9900. }
  9901. return {
  9902. update: update,
  9903. dispose: dispose
  9904. };
  9905. }
  9906. /**
  9907. * @author mrdoob / http://mrdoob.com/
  9908. */
  9909. function CubeTexture( images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding ) {
  9910. images = images !== undefined ? images : [];
  9911. mapping = mapping !== undefined ? mapping : CubeReflectionMapping;
  9912. format = format !== undefined ? format : RGBFormat;
  9913. Texture.call( this, images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding );
  9914. this.flipY = false;
  9915. }
  9916. CubeTexture.prototype = Object.create( Texture.prototype );
  9917. CubeTexture.prototype.constructor = CubeTexture;
  9918. CubeTexture.prototype.isCubeTexture = true;
  9919. Object.defineProperty( CubeTexture.prototype, 'images', {
  9920. get: function () {
  9921. return this.image;
  9922. },
  9923. set: function ( value ) {
  9924. this.image = value;
  9925. }
  9926. } );
  9927. /**
  9928. * @author Takahiro https://github.com/takahirox
  9929. */
  9930. function DataTexture2DArray( data, width, height, depth ) {
  9931. Texture.call( this, null );
  9932. this.image = { data: data, width: width, height: height, depth: depth };
  9933. this.magFilter = NearestFilter;
  9934. this.minFilter = NearestFilter;
  9935. this.wrapR = ClampToEdgeWrapping;
  9936. this.generateMipmaps = false;
  9937. this.flipY = false;
  9938. }
  9939. DataTexture2DArray.prototype = Object.create( Texture.prototype );
  9940. DataTexture2DArray.prototype.constructor = DataTexture2DArray;
  9941. DataTexture2DArray.prototype.isDataTexture2DArray = true;
  9942. /**
  9943. * @author Artur Trzesiok
  9944. */
  9945. function DataTexture3D( data, width, height, depth ) {
  9946. // We're going to add .setXXX() methods for setting properties later.
  9947. // Users can still set in DataTexture3D directly.
  9948. //
  9949. // var texture = new THREE.DataTexture3D( data, width, height, depth );
  9950. // texture.anisotropy = 16;
  9951. //
  9952. // See #14839
  9953. Texture.call( this, null );
  9954. this.image = { data: data, width: width, height: height, depth: depth };
  9955. this.magFilter = NearestFilter;
  9956. this.minFilter = NearestFilter;
  9957. this.wrapR = ClampToEdgeWrapping;
  9958. this.generateMipmaps = false;
  9959. this.flipY = false;
  9960. }
  9961. DataTexture3D.prototype = Object.create( Texture.prototype );
  9962. DataTexture3D.prototype.constructor = DataTexture3D;
  9963. DataTexture3D.prototype.isDataTexture3D = true;
  9964. /**
  9965. * @author tschw
  9966. * @author Mugen87 / https://github.com/Mugen87
  9967. * @author mrdoob / http://mrdoob.com/
  9968. *
  9969. * Uniforms of a program.
  9970. * Those form a tree structure with a special top-level container for the root,
  9971. * which you get by calling 'new WebGLUniforms( gl, program )'.
  9972. *
  9973. *
  9974. * Properties of inner nodes including the top-level container:
  9975. *
  9976. * .seq - array of nested uniforms
  9977. * .map - nested uniforms by name
  9978. *
  9979. *
  9980. * Methods of all nodes except the top-level container:
  9981. *
  9982. * .setValue( gl, value, [textures] )
  9983. *
  9984. * uploads a uniform value(s)
  9985. * the 'textures' parameter is needed for sampler uniforms
  9986. *
  9987. *
  9988. * Static methods of the top-level container (textures factorizations):
  9989. *
  9990. * .upload( gl, seq, values, textures )
  9991. *
  9992. * sets uniforms in 'seq' to 'values[id].value'
  9993. *
  9994. * .seqWithValue( seq, values ) : filteredSeq
  9995. *
  9996. * filters 'seq' entries with corresponding entry in values
  9997. *
  9998. *
  9999. * Methods of the top-level container (textures factorizations):
  10000. *
  10001. * .setValue( gl, name, value, textures )
  10002. *
  10003. * sets uniform with name 'name' to 'value'
  10004. *
  10005. * .setOptional( gl, obj, prop )
  10006. *
  10007. * like .set for an optional property of the object
  10008. *
  10009. */
  10010. var emptyTexture = new Texture();
  10011. var emptyTexture2dArray = new DataTexture2DArray();
  10012. var emptyTexture3d = new DataTexture3D();
  10013. var emptyCubeTexture = new CubeTexture();
  10014. // --- Utilities ---
  10015. // Array Caches (provide typed arrays for temporary by size)
  10016. var arrayCacheF32 = [];
  10017. var arrayCacheI32 = [];
  10018. // Float32Array caches used for uploading Matrix uniforms
  10019. var mat4array = new Float32Array( 16 );
  10020. var mat3array = new Float32Array( 9 );
  10021. var mat2array = new Float32Array( 4 );
  10022. // Flattening for arrays of vectors and matrices
  10023. function flatten( array, nBlocks, blockSize ) {
  10024. var firstElem = array[ 0 ];
  10025. if ( firstElem <= 0 || firstElem > 0 ) return array;
  10026. // unoptimized: ! isNaN( firstElem )
  10027. // see http://jacksondunstan.com/articles/983
  10028. var n = nBlocks * blockSize,
  10029. r = arrayCacheF32[ n ];
  10030. if ( r === undefined ) {
  10031. r = new Float32Array( n );
  10032. arrayCacheF32[ n ] = r;
  10033. }
  10034. if ( nBlocks !== 0 ) {
  10035. firstElem.toArray( r, 0 );
  10036. for ( var i = 1, offset = 0; i !== nBlocks; ++ i ) {
  10037. offset += blockSize;
  10038. array[ i ].toArray( r, offset );
  10039. }
  10040. }
  10041. return r;
  10042. }
  10043. function arraysEqual( a, b ) {
  10044. if ( a.length !== b.length ) return false;
  10045. for ( var i = 0, l = a.length; i < l; i ++ ) {
  10046. if ( a[ i ] !== b[ i ] ) return false;
  10047. }
  10048. return true;
  10049. }
  10050. function copyArray( a, b ) {
  10051. for ( var i = 0, l = b.length; i < l; i ++ ) {
  10052. a[ i ] = b[ i ];
  10053. }
  10054. }
  10055. // Texture unit allocation
  10056. function allocTexUnits( textures, n ) {
  10057. var r = arrayCacheI32[ n ];
  10058. if ( r === undefined ) {
  10059. r = new Int32Array( n );
  10060. arrayCacheI32[ n ] = r;
  10061. }
  10062. for ( var i = 0; i !== n; ++ i )
  10063. r[ i ] = textures.allocateTextureUnit();
  10064. return r;
  10065. }
  10066. // --- Setters ---
  10067. // Note: Defining these methods externally, because they come in a bunch
  10068. // and this way their names minify.
  10069. // Single scalar
  10070. function setValueV1f( gl, v ) {
  10071. var cache = this.cache;
  10072. if ( cache[ 0 ] === v ) return;
  10073. gl.uniform1f( this.addr, v );
  10074. cache[ 0 ] = v;
  10075. }
  10076. // Single float vector (from flat array or THREE.VectorN)
  10077. function setValueV2f( gl, v ) {
  10078. var cache = this.cache;
  10079. if ( v.x !== undefined ) {
  10080. if ( cache[ 0 ] !== v.x || cache[ 1 ] !== v.y ) {
  10081. gl.uniform2f( this.addr, v.x, v.y );
  10082. cache[ 0 ] = v.x;
  10083. cache[ 1 ] = v.y;
  10084. }
  10085. } else {
  10086. if ( arraysEqual( cache, v ) ) return;
  10087. gl.uniform2fv( this.addr, v );
  10088. copyArray( cache, v );
  10089. }
  10090. }
  10091. function setValueV3f( gl, v ) {
  10092. var cache = this.cache;
  10093. if ( v.x !== undefined ) {
  10094. if ( cache[ 0 ] !== v.x || cache[ 1 ] !== v.y || cache[ 2 ] !== v.z ) {
  10095. gl.uniform3f( this.addr, v.x, v.y, v.z );
  10096. cache[ 0 ] = v.x;
  10097. cache[ 1 ] = v.y;
  10098. cache[ 2 ] = v.z;
  10099. }
  10100. } else if ( v.r !== undefined ) {
  10101. if ( cache[ 0 ] !== v.r || cache[ 1 ] !== v.g || cache[ 2 ] !== v.b ) {
  10102. gl.uniform3f( this.addr, v.r, v.g, v.b );
  10103. cache[ 0 ] = v.r;
  10104. cache[ 1 ] = v.g;
  10105. cache[ 2 ] = v.b;
  10106. }
  10107. } else {
  10108. if ( arraysEqual( cache, v ) ) return;
  10109. gl.uniform3fv( this.addr, v );
  10110. copyArray( cache, v );
  10111. }
  10112. }
  10113. function setValueV4f( gl, v ) {
  10114. var cache = this.cache;
  10115. if ( v.x !== undefined ) {
  10116. if ( cache[ 0 ] !== v.x || cache[ 1 ] !== v.y || cache[ 2 ] !== v.z || cache[ 3 ] !== v.w ) {
  10117. gl.uniform4f( this.addr, v.x, v.y, v.z, v.w );
  10118. cache[ 0 ] = v.x;
  10119. cache[ 1 ] = v.y;
  10120. cache[ 2 ] = v.z;
  10121. cache[ 3 ] = v.w;
  10122. }
  10123. } else {
  10124. if ( arraysEqual( cache, v ) ) return;
  10125. gl.uniform4fv( this.addr, v );
  10126. copyArray( cache, v );
  10127. }
  10128. }
  10129. // Single matrix (from flat array or MatrixN)
  10130. function setValueM2( gl, v ) {
  10131. var cache = this.cache;
  10132. var elements = v.elements;
  10133. if ( elements === undefined ) {
  10134. if ( arraysEqual( cache, v ) ) return;
  10135. gl.uniformMatrix2fv( this.addr, false, v );
  10136. copyArray( cache, v );
  10137. } else {
  10138. if ( arraysEqual( cache, elements ) ) return;
  10139. mat2array.set( elements );
  10140. gl.uniformMatrix2fv( this.addr, false, mat2array );
  10141. copyArray( cache, elements );
  10142. }
  10143. }
  10144. function setValueM3( gl, v ) {
  10145. var cache = this.cache;
  10146. var elements = v.elements;
  10147. if ( elements === undefined ) {
  10148. if ( arraysEqual( cache, v ) ) return;
  10149. gl.uniformMatrix3fv( this.addr, false, v );
  10150. copyArray( cache, v );
  10151. } else {
  10152. if ( arraysEqual( cache, elements ) ) return;
  10153. mat3array.set( elements );
  10154. gl.uniformMatrix3fv( this.addr, false, mat3array );
  10155. copyArray( cache, elements );
  10156. }
  10157. }
  10158. function setValueM4( gl, v ) {
  10159. var cache = this.cache;
  10160. var elements = v.elements;
  10161. if ( elements === undefined ) {
  10162. if ( arraysEqual( cache, v ) ) return;
  10163. gl.uniformMatrix4fv( this.addr, false, v );
  10164. copyArray( cache, v );
  10165. } else {
  10166. if ( arraysEqual( cache, elements ) ) return;
  10167. mat4array.set( elements );
  10168. gl.uniformMatrix4fv( this.addr, false, mat4array );
  10169. copyArray( cache, elements );
  10170. }
  10171. }
  10172. // Single texture (2D / Cube)
  10173. function setValueT1( gl, v, textures ) {
  10174. var cache = this.cache;
  10175. var unit = textures.allocateTextureUnit();
  10176. if ( cache[ 0 ] !== unit ) {
  10177. gl.uniform1i( this.addr, unit );
  10178. cache[ 0 ] = unit;
  10179. }
  10180. textures.safeSetTexture2D( v || emptyTexture, unit );
  10181. }
  10182. function setValueT2DArray1( gl, v, textures ) {
  10183. var cache = this.cache;
  10184. var unit = textures.allocateTextureUnit();
  10185. if ( cache[ 0 ] !== unit ) {
  10186. gl.uniform1i( this.addr, unit );
  10187. cache[ 0 ] = unit;
  10188. }
  10189. textures.setTexture2DArray( v || emptyTexture2dArray, unit );
  10190. }
  10191. function setValueT3D1( gl, v, textures ) {
  10192. var cache = this.cache;
  10193. var unit = textures.allocateTextureUnit();
  10194. if ( cache[ 0 ] !== unit ) {
  10195. gl.uniform1i( this.addr, unit );
  10196. cache[ 0 ] = unit;
  10197. }
  10198. textures.setTexture3D( v || emptyTexture3d, unit );
  10199. }
  10200. function setValueT6( gl, v, textures ) {
  10201. var cache = this.cache;
  10202. var unit = textures.allocateTextureUnit();
  10203. if ( cache[ 0 ] !== unit ) {
  10204. gl.uniform1i( this.addr, unit );
  10205. cache[ 0 ] = unit;
  10206. }
  10207. textures.safeSetTextureCube( v || emptyCubeTexture, unit );
  10208. }
  10209. // Integer / Boolean vectors or arrays thereof (always flat arrays)
  10210. function setValueV1i( gl, v ) {
  10211. var cache = this.cache;
  10212. if ( cache[ 0 ] === v ) return;
  10213. gl.uniform1i( this.addr, v );
  10214. cache[ 0 ] = v;
  10215. }
  10216. function setValueV2i( gl, v ) {
  10217. var cache = this.cache;
  10218. if ( arraysEqual( cache, v ) ) return;
  10219. gl.uniform2iv( this.addr, v );
  10220. copyArray( cache, v );
  10221. }
  10222. function setValueV3i( gl, v ) {
  10223. var cache = this.cache;
  10224. if ( arraysEqual( cache, v ) ) return;
  10225. gl.uniform3iv( this.addr, v );
  10226. copyArray( cache, v );
  10227. }
  10228. function setValueV4i( gl, v ) {
  10229. var cache = this.cache;
  10230. if ( arraysEqual( cache, v ) ) return;
  10231. gl.uniform4iv( this.addr, v );
  10232. copyArray( cache, v );
  10233. }
  10234. // Helper to pick the right setter for the singular case
  10235. function getSingularSetter( type ) {
  10236. switch ( type ) {
  10237. case 0x1406: return setValueV1f; // FLOAT
  10238. case 0x8b50: return setValueV2f; // _VEC2
  10239. case 0x8b51: return setValueV3f; // _VEC3
  10240. case 0x8b52: return setValueV4f; // _VEC4
  10241. case 0x8b5a: return setValueM2; // _MAT2
  10242. case 0x8b5b: return setValueM3; // _MAT3
  10243. case 0x8b5c: return setValueM4; // _MAT4
  10244. case 0x8b5e: case 0x8d66: return setValueT1; // SAMPLER_2D, SAMPLER_EXTERNAL_OES
  10245. case 0x8b5f: return setValueT3D1; // SAMPLER_3D
  10246. case 0x8b60: return setValueT6; // SAMPLER_CUBE
  10247. case 0x8DC1: return setValueT2DArray1; // SAMPLER_2D_ARRAY
  10248. case 0x1404: case 0x8b56: return setValueV1i; // INT, BOOL
  10249. case 0x8b53: case 0x8b57: return setValueV2i; // _VEC2
  10250. case 0x8b54: case 0x8b58: return setValueV3i; // _VEC3
  10251. case 0x8b55: case 0x8b59: return setValueV4i; // _VEC4
  10252. }
  10253. }
  10254. // Array of scalars
  10255. function setValueV1fArray( gl, v ) {
  10256. gl.uniform1fv( this.addr, v );
  10257. }
  10258. // Integer / Boolean vectors or arrays thereof (always flat arrays)
  10259. function setValueV1iArray( gl, v ) {
  10260. gl.uniform1iv( this.addr, v );
  10261. }
  10262. function setValueV2iArray( gl, v ) {
  10263. gl.uniform2iv( this.addr, v );
  10264. }
  10265. function setValueV3iArray( gl, v ) {
  10266. gl.uniform3iv( this.addr, v );
  10267. }
  10268. function setValueV4iArray( gl, v ) {
  10269. gl.uniform4iv( this.addr, v );
  10270. }
  10271. // Array of vectors (flat or from THREE classes)
  10272. function setValueV2fArray( gl, v ) {
  10273. var data = flatten( v, this.size, 2 );
  10274. gl.uniform2fv( this.addr, data );
  10275. }
  10276. function setValueV3fArray( gl, v ) {
  10277. var data = flatten( v, this.size, 3 );
  10278. gl.uniform3fv( this.addr, data );
  10279. }
  10280. function setValueV4fArray( gl, v ) {
  10281. var data = flatten( v, this.size, 4 );
  10282. gl.uniform4fv( this.addr, data );
  10283. }
  10284. // Array of matrices (flat or from THREE clases)
  10285. function setValueM2Array( gl, v ) {
  10286. var data = flatten( v, this.size, 4 );
  10287. gl.uniformMatrix2fv( this.addr, false, data );
  10288. }
  10289. function setValueM3Array( gl, v ) {
  10290. var data = flatten( v, this.size, 9 );
  10291. gl.uniformMatrix3fv( this.addr, false, data );
  10292. }
  10293. function setValueM4Array( gl, v ) {
  10294. var data = flatten( v, this.size, 16 );
  10295. gl.uniformMatrix4fv( this.addr, false, data );
  10296. }
  10297. // Array of textures (2D / Cube)
  10298. function setValueT1Array( gl, v, textures ) {
  10299. var n = v.length;
  10300. var units = allocTexUnits( textures, n );
  10301. gl.uniform1iv( this.addr, units );
  10302. for ( var i = 0; i !== n; ++ i ) {
  10303. textures.safeSetTexture2D( v[ i ] || emptyTexture, units[ i ] );
  10304. }
  10305. }
  10306. function setValueT6Array( gl, v, textures ) {
  10307. var n = v.length;
  10308. var units = allocTexUnits( textures, n );
  10309. gl.uniform1iv( this.addr, units );
  10310. for ( var i = 0; i !== n; ++ i ) {
  10311. textures.safeSetTextureCube( v[ i ] || emptyCubeTexture, units[ i ] );
  10312. }
  10313. }
  10314. // Helper to pick the right setter for a pure (bottom-level) array
  10315. function getPureArraySetter( type ) {
  10316. switch ( type ) {
  10317. case 0x1406: return setValueV1fArray; // FLOAT
  10318. case 0x8b50: return setValueV2fArray; // _VEC2
  10319. case 0x8b51: return setValueV3fArray; // _VEC3
  10320. case 0x8b52: return setValueV4fArray; // _VEC4
  10321. case 0x8b5a: return setValueM2Array; // _MAT2
  10322. case 0x8b5b: return setValueM3Array; // _MAT3
  10323. case 0x8b5c: return setValueM4Array; // _MAT4
  10324. case 0x8b5e: return setValueT1Array; // SAMPLER_2D
  10325. case 0x8b60: return setValueT6Array; // SAMPLER_CUBE
  10326. case 0x1404: case 0x8b56: return setValueV1iArray; // INT, BOOL
  10327. case 0x8b53: case 0x8b57: return setValueV2iArray; // _VEC2
  10328. case 0x8b54: case 0x8b58: return setValueV3iArray; // _VEC3
  10329. case 0x8b55: case 0x8b59: return setValueV4iArray; // _VEC4
  10330. }
  10331. }
  10332. // --- Uniform Classes ---
  10333. function SingleUniform( id, activeInfo, addr ) {
  10334. this.id = id;
  10335. this.addr = addr;
  10336. this.cache = [];
  10337. this.setValue = getSingularSetter( activeInfo.type );
  10338. // this.path = activeInfo.name; // DEBUG
  10339. }
  10340. function PureArrayUniform( id, activeInfo, addr ) {
  10341. this.id = id;
  10342. this.addr = addr;
  10343. this.cache = [];
  10344. this.size = activeInfo.size;
  10345. this.setValue = getPureArraySetter( activeInfo.type );
  10346. // this.path = activeInfo.name; // DEBUG
  10347. }
  10348. PureArrayUniform.prototype.updateCache = function ( data ) {
  10349. var cache = this.cache;
  10350. if ( data instanceof Float32Array && cache.length !== data.length ) {
  10351. this.cache = new Float32Array( data.length );
  10352. }
  10353. copyArray( cache, data );
  10354. };
  10355. function StructuredUniform( id ) {
  10356. this.id = id;
  10357. this.seq = [];
  10358. this.map = {};
  10359. }
  10360. StructuredUniform.prototype.setValue = function ( gl, value, textures ) {
  10361. var seq = this.seq;
  10362. for ( var i = 0, n = seq.length; i !== n; ++ i ) {
  10363. var u = seq[ i ];
  10364. u.setValue( gl, value[ u.id ], textures );
  10365. }
  10366. };
  10367. // --- Top-level ---
  10368. // Parser - builds up the property tree from the path strings
  10369. var RePathPart = /([\w\d_]+)(\])?(\[|\.)?/g;
  10370. // extracts
  10371. // - the identifier (member name or array index)
  10372. // - followed by an optional right bracket (found when array index)
  10373. // - followed by an optional left bracket or dot (type of subscript)
  10374. //
  10375. // Note: These portions can be read in a non-overlapping fashion and
  10376. // allow straightforward parsing of the hierarchy that WebGL encodes
  10377. // in the uniform names.
  10378. function addUniform( container, uniformObject ) {
  10379. container.seq.push( uniformObject );
  10380. container.map[ uniformObject.id ] = uniformObject;
  10381. }
  10382. function parseUniform( activeInfo, addr, container ) {
  10383. var path = activeInfo.name,
  10384. pathLength = path.length;
  10385. // reset RegExp object, because of the early exit of a previous run
  10386. RePathPart.lastIndex = 0;
  10387. while ( true ) {
  10388. var match = RePathPart.exec( path ),
  10389. matchEnd = RePathPart.lastIndex,
  10390. id = match[ 1 ],
  10391. idIsIndex = match[ 2 ] === ']',
  10392. subscript = match[ 3 ];
  10393. if ( idIsIndex ) id = id | 0; // convert to integer
  10394. if ( subscript === undefined || subscript === '[' && matchEnd + 2 === pathLength ) {
  10395. // bare name or "pure" bottom-level array "[0]" suffix
  10396. addUniform( container, subscript === undefined ?
  10397. new SingleUniform( id, activeInfo, addr ) :
  10398. new PureArrayUniform( id, activeInfo, addr ) );
  10399. break;
  10400. } else {
  10401. // step into inner node / create it in case it doesn't exist
  10402. var map = container.map, next = map[ id ];
  10403. if ( next === undefined ) {
  10404. next = new StructuredUniform( id );
  10405. addUniform( container, next );
  10406. }
  10407. container = next;
  10408. }
  10409. }
  10410. }
  10411. // Root Container
  10412. function WebGLUniforms( gl, program ) {
  10413. this.seq = [];
  10414. this.map = {};
  10415. var n = gl.getProgramParameter( program, 35718 );
  10416. for ( var i = 0; i < n; ++ i ) {
  10417. var info = gl.getActiveUniform( program, i ),
  10418. addr = gl.getUniformLocation( program, info.name );
  10419. parseUniform( info, addr, this );
  10420. }
  10421. }
  10422. WebGLUniforms.prototype.setValue = function ( gl, name, value, textures ) {
  10423. var u = this.map[ name ];
  10424. if ( u !== undefined ) u.setValue( gl, value, textures );
  10425. };
  10426. WebGLUniforms.prototype.setOptional = function ( gl, object, name ) {
  10427. var v = object[ name ];
  10428. if ( v !== undefined ) this.setValue( gl, name, v );
  10429. };
  10430. // Static interface
  10431. WebGLUniforms.upload = function ( gl, seq, values, textures ) {
  10432. for ( var i = 0, n = seq.length; i !== n; ++ i ) {
  10433. var u = seq[ i ],
  10434. v = values[ u.id ];
  10435. if ( v.needsUpdate !== false ) {
  10436. // note: always updating when .needsUpdate is undefined
  10437. u.setValue( gl, v.value, textures );
  10438. }
  10439. }
  10440. };
  10441. WebGLUniforms.seqWithValue = function ( seq, values ) {
  10442. var r = [];
  10443. for ( var i = 0, n = seq.length; i !== n; ++ i ) {
  10444. var u = seq[ i ];
  10445. if ( u.id in values ) r.push( u );
  10446. }
  10447. return r;
  10448. };
  10449. /**
  10450. * @author mrdoob / http://mrdoob.com/
  10451. */
  10452. function WebGLShader( gl, type, string ) {
  10453. var shader = gl.createShader( type );
  10454. gl.shaderSource( shader, string );
  10455. gl.compileShader( shader );
  10456. return shader;
  10457. }
  10458. /**
  10459. * @author mrdoob / http://mrdoob.com/
  10460. */
  10461. var programIdCount = 0;
  10462. function addLineNumbers( string ) {
  10463. var lines = string.split( '\n' );
  10464. for ( var i = 0; i < lines.length; i ++ ) {
  10465. lines[ i ] = ( i + 1 ) + ': ' + lines[ i ];
  10466. }
  10467. return lines.join( '\n' );
  10468. }
  10469. function getEncodingComponents( encoding ) {
  10470. switch ( encoding ) {
  10471. case LinearEncoding:
  10472. return [ 'Linear', '( value )' ];
  10473. case sRGBEncoding:
  10474. return [ 'sRGB', '( value )' ];
  10475. case RGBEEncoding:
  10476. return [ 'RGBE', '( value )' ];
  10477. case RGBM7Encoding:
  10478. return [ 'RGBM', '( value, 7.0 )' ];
  10479. case RGBM16Encoding:
  10480. return [ 'RGBM', '( value, 16.0 )' ];
  10481. case RGBDEncoding:
  10482. return [ 'RGBD', '( value, 256.0 )' ];
  10483. case GammaEncoding:
  10484. return [ 'Gamma', '( value, float( GAMMA_FACTOR ) )' ];
  10485. default:
  10486. throw new Error( 'unsupported encoding: ' + encoding );
  10487. }
  10488. }
  10489. function getShaderErrors( gl, shader, type ) {
  10490. var status = gl.getShaderParameter( shader, 35713 );
  10491. var log = gl.getShaderInfoLog( shader ).trim();
  10492. if ( status && log === '' ) return '';
  10493. // --enable-privileged-webgl-extension
  10494. // console.log( '**' + type + '**', gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( shader ) );
  10495. var source = gl.getShaderSource( shader );
  10496. return 'THREE.WebGLShader: gl.getShaderInfoLog() ' + type + '\n' + log + addLineNumbers( source );
  10497. }
  10498. function getTexelDecodingFunction( functionName, encoding ) {
  10499. var components = getEncodingComponents( encoding );
  10500. return 'vec4 ' + functionName + '( vec4 value ) { return ' + components[ 0 ] + 'ToLinear' + components[ 1 ] + '; }';
  10501. }
  10502. function getTexelEncodingFunction( functionName, encoding ) {
  10503. var components = getEncodingComponents( encoding );
  10504. return 'vec4 ' + functionName + '( vec4 value ) { return LinearTo' + components[ 0 ] + components[ 1 ] + '; }';
  10505. }
  10506. function getToneMappingFunction( functionName, toneMapping ) {
  10507. var toneMappingName;
  10508. switch ( toneMapping ) {
  10509. case LinearToneMapping:
  10510. toneMappingName = 'Linear';
  10511. break;
  10512. case ReinhardToneMapping:
  10513. toneMappingName = 'Reinhard';
  10514. break;
  10515. case Uncharted2ToneMapping:
  10516. toneMappingName = 'Uncharted2';
  10517. break;
  10518. case CineonToneMapping:
  10519. toneMappingName = 'OptimizedCineon';
  10520. break;
  10521. case ACESFilmicToneMapping:
  10522. toneMappingName = 'ACESFilmic';
  10523. break;
  10524. default:
  10525. throw new Error( 'unsupported toneMapping: ' + toneMapping );
  10526. }
  10527. return 'vec3 ' + functionName + '( vec3 color ) { return ' + toneMappingName + 'ToneMapping( color ); }';
  10528. }
  10529. function generateExtensions( extensions, parameters, rendererExtensions ) {
  10530. extensions = extensions || {};
  10531. var chunks = [
  10532. ( extensions.derivatives || parameters.envMapCubeUV || parameters.bumpMap || ( parameters.normalMap && ! parameters.objectSpaceNormalMap ) || parameters.flatShading ) ? '#extension GL_OES_standard_derivatives : enable' : '',
  10533. ( extensions.fragDepth || parameters.logarithmicDepthBuffer ) && rendererExtensions.get( 'EXT_frag_depth' ) ? '#extension GL_EXT_frag_depth : enable' : '',
  10534. ( extensions.drawBuffers ) && rendererExtensions.get( 'WEBGL_draw_buffers' ) ? '#extension GL_EXT_draw_buffers : require' : '',
  10535. ( extensions.shaderTextureLOD || parameters.envMap ) && rendererExtensions.get( 'EXT_shader_texture_lod' ) ? '#extension GL_EXT_shader_texture_lod : enable' : ''
  10536. ];
  10537. return chunks.filter( filterEmptyLine ).join( '\n' );
  10538. }
  10539. function generateDefines( defines ) {
  10540. var chunks = [];
  10541. for ( var name in defines ) {
  10542. var value = defines[ name ];
  10543. if ( value === false ) continue;
  10544. chunks.push( '#define ' + name + ' ' + value );
  10545. }
  10546. return chunks.join( '\n' );
  10547. }
  10548. function fetchAttributeLocations( gl, program ) {
  10549. var attributes = {};
  10550. var n = gl.getProgramParameter( program, 35721 );
  10551. for ( var i = 0; i < n; i ++ ) {
  10552. var info = gl.getActiveAttrib( program, i );
  10553. var name = info.name;
  10554. // console.log( 'THREE.WebGLProgram: ACTIVE VERTEX ATTRIBUTE:', name, i );
  10555. attributes[ name ] = gl.getAttribLocation( program, name );
  10556. }
  10557. return attributes;
  10558. }
  10559. function filterEmptyLine( string ) {
  10560. return string !== '';
  10561. }
  10562. function replaceLightNums( string, parameters ) {
  10563. return string
  10564. .replace( /NUM_DIR_LIGHTS/g, parameters.numDirLights )
  10565. .replace( /NUM_SPOT_LIGHTS/g, parameters.numSpotLights )
  10566. .replace( /NUM_RECT_AREA_LIGHTS/g, parameters.numRectAreaLights )
  10567. .replace( /NUM_POINT_LIGHTS/g, parameters.numPointLights )
  10568. .replace( /NUM_HEMI_LIGHTS/g, parameters.numHemiLights );
  10569. }
  10570. function replaceClippingPlaneNums( string, parameters ) {
  10571. return string
  10572. .replace( /NUM_CLIPPING_PLANES/g, parameters.numClippingPlanes )
  10573. .replace( /UNION_CLIPPING_PLANES/g, ( parameters.numClippingPlanes - parameters.numClipIntersection ) );
  10574. }
  10575. function parseIncludes( string ) {
  10576. var pattern = /^[ \t]*#include +<([\w\d./]+)>/gm;
  10577. function replace( match, include ) {
  10578. var replace = ShaderChunk[ include ];
  10579. if ( replace === undefined ) {
  10580. throw new Error( 'Can not resolve #include <' + include + '>' );
  10581. }
  10582. return parseIncludes( replace );
  10583. }
  10584. return string.replace( pattern, replace );
  10585. }
  10586. function unrollLoops( string ) {
  10587. var pattern = /#pragma unroll_loop[\s]+?for \( int i \= (\d+)\; i < (\d+)\; i \+\+ \) \{([\s\S]+?)(?=\})\}/g;
  10588. function replace( match, start, end, snippet ) {
  10589. var unroll = '';
  10590. for ( var i = parseInt( start ); i < parseInt( end ); i ++ ) {
  10591. unroll += snippet.replace( /\[ i \]/g, '[ ' + i + ' ]' );
  10592. }
  10593. return unroll;
  10594. }
  10595. return string.replace( pattern, replace );
  10596. }
  10597. function WebGLProgram( renderer, extensions, code, material, shader, parameters, capabilities ) {
  10598. var gl = renderer.getContext();
  10599. var defines = material.defines;
  10600. var vertexShader = shader.vertexShader;
  10601. var fragmentShader = shader.fragmentShader;
  10602. var shadowMapTypeDefine = 'SHADOWMAP_TYPE_BASIC';
  10603. if ( parameters.shadowMapType === PCFShadowMap ) {
  10604. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF';
  10605. } else if ( parameters.shadowMapType === PCFSoftShadowMap ) {
  10606. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF_SOFT';
  10607. }
  10608. var envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  10609. var envMapModeDefine = 'ENVMAP_MODE_REFLECTION';
  10610. var envMapBlendingDefine = 'ENVMAP_BLENDING_MULTIPLY';
  10611. if ( parameters.envMap ) {
  10612. switch ( material.envMap.mapping ) {
  10613. case CubeReflectionMapping:
  10614. case CubeRefractionMapping:
  10615. envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  10616. break;
  10617. case CubeUVReflectionMapping:
  10618. case CubeUVRefractionMapping:
  10619. envMapTypeDefine = 'ENVMAP_TYPE_CUBE_UV';
  10620. break;
  10621. case EquirectangularReflectionMapping:
  10622. case EquirectangularRefractionMapping:
  10623. envMapTypeDefine = 'ENVMAP_TYPE_EQUIREC';
  10624. break;
  10625. case SphericalReflectionMapping:
  10626. envMapTypeDefine = 'ENVMAP_TYPE_SPHERE';
  10627. break;
  10628. }
  10629. switch ( material.envMap.mapping ) {
  10630. case CubeRefractionMapping:
  10631. case EquirectangularRefractionMapping:
  10632. envMapModeDefine = 'ENVMAP_MODE_REFRACTION';
  10633. break;
  10634. }
  10635. switch ( material.combine ) {
  10636. case MultiplyOperation:
  10637. envMapBlendingDefine = 'ENVMAP_BLENDING_MULTIPLY';
  10638. break;
  10639. case MixOperation:
  10640. envMapBlendingDefine = 'ENVMAP_BLENDING_MIX';
  10641. break;
  10642. case AddOperation:
  10643. envMapBlendingDefine = 'ENVMAP_BLENDING_ADD';
  10644. break;
  10645. }
  10646. }
  10647. var gammaFactorDefine = ( renderer.gammaFactor > 0 ) ? renderer.gammaFactor : 1.0;
  10648. // console.log( 'building new program ' );
  10649. //
  10650. var customExtensions = capabilities.isWebGL2 ? '' : generateExtensions( material.extensions, parameters, extensions );
  10651. var customDefines = generateDefines( defines );
  10652. //
  10653. var program = gl.createProgram();
  10654. var prefixVertex, prefixFragment;
  10655. if ( material.isRawShaderMaterial ) {
  10656. prefixVertex = [
  10657. customDefines
  10658. ].filter( filterEmptyLine ).join( '\n' );
  10659. if ( prefixVertex.length > 0 ) {
  10660. prefixVertex += '\n';
  10661. }
  10662. prefixFragment = [
  10663. customExtensions,
  10664. customDefines
  10665. ].filter( filterEmptyLine ).join( '\n' );
  10666. if ( prefixFragment.length > 0 ) {
  10667. prefixFragment += '\n';
  10668. }
  10669. } else {
  10670. prefixVertex = [
  10671. 'precision ' + parameters.precision + ' float;',
  10672. 'precision ' + parameters.precision + ' int;',
  10673. '#define SHADER_NAME ' + shader.name,
  10674. customDefines,
  10675. parameters.supportsVertexTextures ? '#define VERTEX_TEXTURES' : '',
  10676. '#define GAMMA_FACTOR ' + gammaFactorDefine,
  10677. '#define MAX_BONES ' + parameters.maxBones,
  10678. ( parameters.useFog && parameters.fog ) ? '#define USE_FOG' : '',
  10679. ( parameters.useFog && parameters.fogExp ) ? '#define FOG_EXP2' : '',
  10680. parameters.map ? '#define USE_MAP' : '',
  10681. parameters.envMap ? '#define USE_ENVMAP' : '',
  10682. parameters.envMap ? '#define ' + envMapModeDefine : '',
  10683. parameters.lightMap ? '#define USE_LIGHTMAP' : '',
  10684. parameters.aoMap ? '#define USE_AOMAP' : '',
  10685. parameters.emissiveMap ? '#define USE_EMISSIVEMAP' : '',
  10686. parameters.bumpMap ? '#define USE_BUMPMAP' : '',
  10687. parameters.normalMap ? '#define USE_NORMALMAP' : '',
  10688. ( parameters.normalMap && parameters.objectSpaceNormalMap ) ? '#define OBJECTSPACE_NORMALMAP' : '',
  10689. parameters.displacementMap && parameters.supportsVertexTextures ? '#define USE_DISPLACEMENTMAP' : '',
  10690. parameters.specularMap ? '#define USE_SPECULARMAP' : '',
  10691. parameters.roughnessMap ? '#define USE_ROUGHNESSMAP' : '',
  10692. parameters.metalnessMap ? '#define USE_METALNESSMAP' : '',
  10693. parameters.alphaMap ? '#define USE_ALPHAMAP' : '',
  10694. parameters.vertexTangents ? '#define USE_TANGENT' : '',
  10695. parameters.vertexColors ? '#define USE_COLOR' : '',
  10696. parameters.flatShading ? '#define FLAT_SHADED' : '',
  10697. parameters.skinning ? '#define USE_SKINNING' : '',
  10698. parameters.useVertexTexture ? '#define BONE_TEXTURE' : '',
  10699. parameters.morphTargets ? '#define USE_MORPHTARGETS' : '',
  10700. parameters.morphNormals && parameters.flatShading === false ? '#define USE_MORPHNORMALS' : '',
  10701. parameters.doubleSided ? '#define DOUBLE_SIDED' : '',
  10702. parameters.flipSided ? '#define FLIP_SIDED' : '',
  10703. parameters.shadowMapEnabled ? '#define USE_SHADOWMAP' : '',
  10704. parameters.shadowMapEnabled ? '#define ' + shadowMapTypeDefine : '',
  10705. parameters.sizeAttenuation ? '#define USE_SIZEATTENUATION' : '',
  10706. parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
  10707. parameters.logarithmicDepthBuffer && ( capabilities.isWebGL2 || extensions.get( 'EXT_frag_depth' ) ) ? '#define USE_LOGDEPTHBUF_EXT' : '',
  10708. 'uniform mat4 modelMatrix;',
  10709. 'uniform mat4 modelViewMatrix;',
  10710. 'uniform mat4 projectionMatrix;',
  10711. 'uniform mat4 viewMatrix;',
  10712. 'uniform mat3 normalMatrix;',
  10713. 'uniform vec3 cameraPosition;',
  10714. 'attribute vec3 position;',
  10715. 'attribute vec3 normal;',
  10716. 'attribute vec2 uv;',
  10717. '#ifdef USE_TANGENT',
  10718. ' attribute vec4 tangent;',
  10719. '#endif',
  10720. '#ifdef USE_COLOR',
  10721. ' attribute vec3 color;',
  10722. '#endif',
  10723. '#ifdef USE_MORPHTARGETS',
  10724. ' attribute vec3 morphTarget0;',
  10725. ' attribute vec3 morphTarget1;',
  10726. ' attribute vec3 morphTarget2;',
  10727. ' attribute vec3 morphTarget3;',
  10728. ' #ifdef USE_MORPHNORMALS',
  10729. ' attribute vec3 morphNormal0;',
  10730. ' attribute vec3 morphNormal1;',
  10731. ' attribute vec3 morphNormal2;',
  10732. ' attribute vec3 morphNormal3;',
  10733. ' #else',
  10734. ' attribute vec3 morphTarget4;',
  10735. ' attribute vec3 morphTarget5;',
  10736. ' attribute vec3 morphTarget6;',
  10737. ' attribute vec3 morphTarget7;',
  10738. ' #endif',
  10739. '#endif',
  10740. '#ifdef USE_SKINNING',
  10741. ' attribute vec4 skinIndex;',
  10742. ' attribute vec4 skinWeight;',
  10743. '#endif',
  10744. '\n'
  10745. ].filter( filterEmptyLine ).join( '\n' );
  10746. prefixFragment = [
  10747. customExtensions,
  10748. 'precision ' + parameters.precision + ' float;',
  10749. 'precision ' + parameters.precision + ' int;',
  10750. '#define SHADER_NAME ' + shader.name,
  10751. customDefines,
  10752. parameters.alphaTest ? '#define ALPHATEST ' + parameters.alphaTest + ( parameters.alphaTest % 1 ? '' : '.0' ) : '', // add '.0' if integer
  10753. '#define GAMMA_FACTOR ' + gammaFactorDefine,
  10754. ( parameters.useFog && parameters.fog ) ? '#define USE_FOG' : '',
  10755. ( parameters.useFog && parameters.fogExp ) ? '#define FOG_EXP2' : '',
  10756. parameters.map ? '#define USE_MAP' : '',
  10757. parameters.matcap ? '#define USE_MATCAP' : '',
  10758. parameters.envMap ? '#define USE_ENVMAP' : '',
  10759. parameters.envMap ? '#define ' + envMapTypeDefine : '',
  10760. parameters.envMap ? '#define ' + envMapModeDefine : '',
  10761. parameters.envMap ? '#define ' + envMapBlendingDefine : '',
  10762. parameters.lightMap ? '#define USE_LIGHTMAP' : '',
  10763. parameters.aoMap ? '#define USE_AOMAP' : '',
  10764. parameters.emissiveMap ? '#define USE_EMISSIVEMAP' : '',
  10765. parameters.bumpMap ? '#define USE_BUMPMAP' : '',
  10766. parameters.normalMap ? '#define USE_NORMALMAP' : '',
  10767. ( parameters.normalMap && parameters.objectSpaceNormalMap ) ? '#define OBJECTSPACE_NORMALMAP' : '',
  10768. parameters.specularMap ? '#define USE_SPECULARMAP' : '',
  10769. parameters.roughnessMap ? '#define USE_ROUGHNESSMAP' : '',
  10770. parameters.metalnessMap ? '#define USE_METALNESSMAP' : '',
  10771. parameters.alphaMap ? '#define USE_ALPHAMAP' : '',
  10772. parameters.vertexTangents ? '#define USE_TANGENT' : '',
  10773. parameters.vertexColors ? '#define USE_COLOR' : '',
  10774. parameters.gradientMap ? '#define USE_GRADIENTMAP' : '',
  10775. parameters.flatShading ? '#define FLAT_SHADED' : '',
  10776. parameters.doubleSided ? '#define DOUBLE_SIDED' : '',
  10777. parameters.flipSided ? '#define FLIP_SIDED' : '',
  10778. parameters.shadowMapEnabled ? '#define USE_SHADOWMAP' : '',
  10779. parameters.shadowMapEnabled ? '#define ' + shadowMapTypeDefine : '',
  10780. parameters.premultipliedAlpha ? '#define PREMULTIPLIED_ALPHA' : '',
  10781. parameters.physicallyCorrectLights ? '#define PHYSICALLY_CORRECT_LIGHTS' : '',
  10782. parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
  10783. parameters.logarithmicDepthBuffer && ( capabilities.isWebGL2 || extensions.get( 'EXT_frag_depth' ) ) ? '#define USE_LOGDEPTHBUF_EXT' : '',
  10784. parameters.envMap && ( capabilities.isWebGL2 || extensions.get( 'EXT_shader_texture_lod' ) ) ? '#define TEXTURE_LOD_EXT' : '',
  10785. 'uniform mat4 viewMatrix;',
  10786. 'uniform vec3 cameraPosition;',
  10787. ( parameters.toneMapping !== NoToneMapping ) ? '#define TONE_MAPPING' : '',
  10788. ( parameters.toneMapping !== NoToneMapping ) ? ShaderChunk[ 'tonemapping_pars_fragment' ] : '', // this code is required here because it is used by the toneMapping() function defined below
  10789. ( parameters.toneMapping !== NoToneMapping ) ? getToneMappingFunction( 'toneMapping', parameters.toneMapping ) : '',
  10790. parameters.dithering ? '#define DITHERING' : '',
  10791. ( parameters.outputEncoding || parameters.mapEncoding || parameters.matcapEncoding || parameters.envMapEncoding || parameters.emissiveMapEncoding ) ?
  10792. ShaderChunk[ 'encodings_pars_fragment' ] : '', // this code is required here because it is used by the various encoding/decoding function defined below
  10793. parameters.mapEncoding ? getTexelDecodingFunction( 'mapTexelToLinear', parameters.mapEncoding ) : '',
  10794. parameters.matcapEncoding ? getTexelDecodingFunction( 'matcapTexelToLinear', parameters.matcapEncoding ) : '',
  10795. parameters.envMapEncoding ? getTexelDecodingFunction( 'envMapTexelToLinear', parameters.envMapEncoding ) : '',
  10796. parameters.emissiveMapEncoding ? getTexelDecodingFunction( 'emissiveMapTexelToLinear', parameters.emissiveMapEncoding ) : '',
  10797. parameters.outputEncoding ? getTexelEncodingFunction( 'linearToOutputTexel', parameters.outputEncoding ) : '',
  10798. parameters.depthPacking ? '#define DEPTH_PACKING ' + material.depthPacking : '',
  10799. '\n'
  10800. ].filter( filterEmptyLine ).join( '\n' );
  10801. }
  10802. vertexShader = parseIncludes( vertexShader );
  10803. vertexShader = replaceLightNums( vertexShader, parameters );
  10804. vertexShader = replaceClippingPlaneNums( vertexShader, parameters );
  10805. fragmentShader = parseIncludes( fragmentShader );
  10806. fragmentShader = replaceLightNums( fragmentShader, parameters );
  10807. fragmentShader = replaceClippingPlaneNums( fragmentShader, parameters );
  10808. vertexShader = unrollLoops( vertexShader );
  10809. fragmentShader = unrollLoops( fragmentShader );
  10810. if ( capabilities.isWebGL2 && ! material.isRawShaderMaterial ) {
  10811. var isGLSL3ShaderMaterial = false;
  10812. var versionRegex = /^\s*#version\s+300\s+es\s*\n/;
  10813. if ( material.isShaderMaterial &&
  10814. vertexShader.match( versionRegex ) !== null &&
  10815. fragmentShader.match( versionRegex ) !== null ) {
  10816. isGLSL3ShaderMaterial = true;
  10817. vertexShader = vertexShader.replace( versionRegex, '' );
  10818. fragmentShader = fragmentShader.replace( versionRegex, '' );
  10819. }
  10820. // GLSL 3.0 conversion
  10821. prefixVertex = [
  10822. '#version 300 es\n',
  10823. '#define attribute in',
  10824. '#define varying out',
  10825. '#define texture2D texture'
  10826. ].join( '\n' ) + '\n' + prefixVertex;
  10827. prefixFragment = [
  10828. '#version 300 es\n',
  10829. '#define varying in',
  10830. isGLSL3ShaderMaterial ? '' : 'out highp vec4 pc_fragColor;',
  10831. isGLSL3ShaderMaterial ? '' : '#define gl_FragColor pc_fragColor',
  10832. '#define gl_FragDepthEXT gl_FragDepth',
  10833. '#define texture2D texture',
  10834. '#define textureCube texture',
  10835. '#define texture2DProj textureProj',
  10836. '#define texture2DLodEXT textureLod',
  10837. '#define texture2DProjLodEXT textureProjLod',
  10838. '#define textureCubeLodEXT textureLod',
  10839. '#define texture2DGradEXT textureGrad',
  10840. '#define texture2DProjGradEXT textureProjGrad',
  10841. '#define textureCubeGradEXT textureGrad'
  10842. ].join( '\n' ) + '\n' + prefixFragment;
  10843. }
  10844. var vertexGlsl = prefixVertex + vertexShader;
  10845. var fragmentGlsl = prefixFragment + fragmentShader;
  10846. // console.log( '*VERTEX*', vertexGlsl );
  10847. // console.log( '*FRAGMENT*', fragmentGlsl );
  10848. var glVertexShader = WebGLShader( gl, 35633, vertexGlsl );
  10849. var glFragmentShader = WebGLShader( gl, 35632, fragmentGlsl );
  10850. gl.attachShader( program, glVertexShader );
  10851. gl.attachShader( program, glFragmentShader );
  10852. // Force a particular attribute to index 0.
  10853. if ( material.index0AttributeName !== undefined ) {
  10854. gl.bindAttribLocation( program, 0, material.index0AttributeName );
  10855. } else if ( parameters.morphTargets === true ) {
  10856. // programs with morphTargets displace position out of attribute 0
  10857. gl.bindAttribLocation( program, 0, 'position' );
  10858. }
  10859. gl.linkProgram( program );
  10860. // check for link errors
  10861. if ( renderer.debug.checkShaderErrors ) {
  10862. var programLog = gl.getProgramInfoLog( program ).trim();
  10863. var vertexLog = gl.getShaderInfoLog( glVertexShader ).trim();
  10864. var fragmentLog = gl.getShaderInfoLog( glFragmentShader ).trim();
  10865. var runnable = true;
  10866. var haveDiagnostics = true;
  10867. if ( gl.getProgramParameter( program, 35714 ) === false ) {
  10868. runnable = false;
  10869. var vertexErrors = getShaderErrors( gl, glVertexShader, 'vertex' );
  10870. var fragmentErrors = getShaderErrors( gl, glFragmentShader, 'fragment' );
  10871. console.error( 'THREE.WebGLProgram: shader error: ', gl.getError(), '35715', gl.getProgramParameter( program, 35715 ), 'gl.getProgramInfoLog', programLog, vertexErrors, fragmentErrors );
  10872. } else if ( programLog !== '' ) {
  10873. console.warn( 'THREE.WebGLProgram: gl.getProgramInfoLog()', programLog );
  10874. } else if ( vertexLog === '' || fragmentLog === '' ) {
  10875. haveDiagnostics = false;
  10876. }
  10877. if ( haveDiagnostics ) {
  10878. this.diagnostics = {
  10879. runnable: runnable,
  10880. material: material,
  10881. programLog: programLog,
  10882. vertexShader: {
  10883. log: vertexLog,
  10884. prefix: prefixVertex
  10885. },
  10886. fragmentShader: {
  10887. log: fragmentLog,
  10888. prefix: prefixFragment
  10889. }
  10890. };
  10891. }
  10892. }
  10893. // clean up
  10894. gl.deleteShader( glVertexShader );
  10895. gl.deleteShader( glFragmentShader );
  10896. // set up caching for uniform locations
  10897. var cachedUniforms;
  10898. this.getUniforms = function () {
  10899. if ( cachedUniforms === undefined ) {
  10900. cachedUniforms = new WebGLUniforms( gl, program );
  10901. }
  10902. return cachedUniforms;
  10903. };
  10904. // set up caching for attribute locations
  10905. var cachedAttributes;
  10906. this.getAttributes = function () {
  10907. if ( cachedAttributes === undefined ) {
  10908. cachedAttributes = fetchAttributeLocations( gl, program );
  10909. }
  10910. return cachedAttributes;
  10911. };
  10912. // free resource
  10913. this.destroy = function () {
  10914. gl.deleteProgram( program );
  10915. this.program = undefined;
  10916. };
  10917. //
  10918. this.name = shader.name;
  10919. this.id = programIdCount ++;
  10920. this.code = code;
  10921. this.usedTimes = 1;
  10922. this.program = program;
  10923. this.vertexShader = glVertexShader;
  10924. this.fragmentShader = glFragmentShader;
  10925. return this;
  10926. }
  10927. /**
  10928. * @author mrdoob / http://mrdoob.com/
  10929. */
  10930. function WebGLPrograms( renderer, extensions, capabilities ) {
  10931. var programs = [];
  10932. var shaderIDs = {
  10933. MeshDepthMaterial: 'depth',
  10934. MeshDistanceMaterial: 'distanceRGBA',
  10935. MeshNormalMaterial: 'normal',
  10936. MeshBasicMaterial: 'basic',
  10937. MeshLambertMaterial: 'lambert',
  10938. MeshPhongMaterial: 'phong',
  10939. MeshToonMaterial: 'phong',
  10940. MeshStandardMaterial: 'physical',
  10941. MeshPhysicalMaterial: 'physical',
  10942. MeshMatcapMaterial: 'matcap',
  10943. LineBasicMaterial: 'basic',
  10944. LineDashedMaterial: 'dashed',
  10945. PointsMaterial: 'points',
  10946. ShadowMaterial: 'shadow',
  10947. SpriteMaterial: 'sprite'
  10948. };
  10949. var parameterNames = [
  10950. "precision", "supportsVertexTextures", "map", "mapEncoding", "matcap", "matcapEncoding", "envMap", "envMapMode", "envMapEncoding",
  10951. "lightMap", "aoMap", "emissiveMap", "emissiveMapEncoding", "bumpMap", "normalMap", "objectSpaceNormalMap", "displacementMap", "specularMap",
  10952. "roughnessMap", "metalnessMap", "gradientMap",
  10953. "alphaMap", "combine", "vertexColors", "vertexTangents", "fog", "useFog", "fogExp",
  10954. "flatShading", "sizeAttenuation", "logarithmicDepthBuffer", "skinning",
  10955. "maxBones", "useVertexTexture", "morphTargets", "morphNormals",
  10956. "maxMorphTargets", "maxMorphNormals", "premultipliedAlpha",
  10957. "numDirLights", "numPointLights", "numSpotLights", "numHemiLights", "numRectAreaLights",
  10958. "shadowMapEnabled", "shadowMapType", "toneMapping", 'physicallyCorrectLights',
  10959. "alphaTest", "doubleSided", "flipSided", "numClippingPlanes", "numClipIntersection", "depthPacking", "dithering"
  10960. ];
  10961. function allocateBones( object ) {
  10962. var skeleton = object.skeleton;
  10963. var bones = skeleton.bones;
  10964. if ( capabilities.floatVertexTextures ) {
  10965. return 1024;
  10966. } else {
  10967. // default for when object is not specified
  10968. // ( for example when prebuilding shader to be used with multiple objects )
  10969. //
  10970. // - leave some extra space for other uniforms
  10971. // - limit here is ANGLE's 254 max uniform vectors
  10972. // (up to 54 should be safe)
  10973. var nVertexUniforms = capabilities.maxVertexUniforms;
  10974. var nVertexMatrices = Math.floor( ( nVertexUniforms - 20 ) / 4 );
  10975. var maxBones = Math.min( nVertexMatrices, bones.length );
  10976. if ( maxBones < bones.length ) {
  10977. console.warn( 'THREE.WebGLRenderer: Skeleton has ' + bones.length + ' bones. This GPU supports ' + maxBones + '.' );
  10978. return 0;
  10979. }
  10980. return maxBones;
  10981. }
  10982. }
  10983. function getTextureEncodingFromMap( map, gammaOverrideLinear ) {
  10984. var encoding;
  10985. if ( ! map ) {
  10986. encoding = LinearEncoding;
  10987. } else if ( map.isTexture ) {
  10988. encoding = map.encoding;
  10989. } else if ( map.isWebGLRenderTarget ) {
  10990. console.warn( "THREE.WebGLPrograms.getTextureEncodingFromMap: don't use render targets as textures. Use their .texture property instead." );
  10991. encoding = map.texture.encoding;
  10992. }
  10993. // add backwards compatibility for WebGLRenderer.gammaInput/gammaOutput parameter, should probably be removed at some point.
  10994. if ( encoding === LinearEncoding && gammaOverrideLinear ) {
  10995. encoding = GammaEncoding;
  10996. }
  10997. return encoding;
  10998. }
  10999. this.getParameters = function ( material, lights, shadows, fog, nClipPlanes, nClipIntersection, object ) {
  11000. var shaderID = shaderIDs[ material.type ];
  11001. // heuristics to create shader parameters according to lights in the scene
  11002. // (not to blow over maxLights budget)
  11003. var maxBones = object.isSkinnedMesh ? allocateBones( object ) : 0;
  11004. var precision = capabilities.precision;
  11005. if ( material.precision !== null ) {
  11006. precision = capabilities.getMaxPrecision( material.precision );
  11007. if ( precision !== material.precision ) {
  11008. console.warn( 'THREE.WebGLProgram.getParameters:', material.precision, 'not supported, using', precision, 'instead.' );
  11009. }
  11010. }
  11011. var currentRenderTarget = renderer.getRenderTarget();
  11012. var parameters = {
  11013. shaderID: shaderID,
  11014. precision: precision,
  11015. supportsVertexTextures: capabilities.vertexTextures,
  11016. outputEncoding: getTextureEncodingFromMap( ( ! currentRenderTarget ) ? null : currentRenderTarget.texture, renderer.gammaOutput ),
  11017. map: !! material.map,
  11018. mapEncoding: getTextureEncodingFromMap( material.map, renderer.gammaInput ),
  11019. matcap: !! material.matcap,
  11020. matcapEncoding: getTextureEncodingFromMap( material.matcap, renderer.gammaInput ),
  11021. envMap: !! material.envMap,
  11022. envMapMode: material.envMap && material.envMap.mapping,
  11023. envMapEncoding: getTextureEncodingFromMap( material.envMap, renderer.gammaInput ),
  11024. envMapCubeUV: ( !! material.envMap ) && ( ( material.envMap.mapping === CubeUVReflectionMapping ) || ( material.envMap.mapping === CubeUVRefractionMapping ) ),
  11025. lightMap: !! material.lightMap,
  11026. aoMap: !! material.aoMap,
  11027. emissiveMap: !! material.emissiveMap,
  11028. emissiveMapEncoding: getTextureEncodingFromMap( material.emissiveMap, renderer.gammaInput ),
  11029. bumpMap: !! material.bumpMap,
  11030. normalMap: !! material.normalMap,
  11031. objectSpaceNormalMap: material.normalMapType === ObjectSpaceNormalMap,
  11032. displacementMap: !! material.displacementMap,
  11033. roughnessMap: !! material.roughnessMap,
  11034. metalnessMap: !! material.metalnessMap,
  11035. specularMap: !! material.specularMap,
  11036. alphaMap: !! material.alphaMap,
  11037. gradientMap: !! material.gradientMap,
  11038. combine: material.combine,
  11039. vertexTangents: ( material.normalMap && material.vertexTangents ),
  11040. vertexColors: material.vertexColors,
  11041. fog: !! fog,
  11042. useFog: material.fog,
  11043. fogExp: ( fog && fog.isFogExp2 ),
  11044. flatShading: material.flatShading,
  11045. sizeAttenuation: material.sizeAttenuation,
  11046. logarithmicDepthBuffer: capabilities.logarithmicDepthBuffer,
  11047. skinning: material.skinning && maxBones > 0,
  11048. maxBones: maxBones,
  11049. useVertexTexture: capabilities.floatVertexTextures,
  11050. morphTargets: material.morphTargets,
  11051. morphNormals: material.morphNormals,
  11052. maxMorphTargets: renderer.maxMorphTargets,
  11053. maxMorphNormals: renderer.maxMorphNormals,
  11054. numDirLights: lights.directional.length,
  11055. numPointLights: lights.point.length,
  11056. numSpotLights: lights.spot.length,
  11057. numRectAreaLights: lights.rectArea.length,
  11058. numHemiLights: lights.hemi.length,
  11059. numClippingPlanes: nClipPlanes,
  11060. numClipIntersection: nClipIntersection,
  11061. dithering: material.dithering,
  11062. shadowMapEnabled: renderer.shadowMap.enabled && object.receiveShadow && shadows.length > 0,
  11063. shadowMapType: renderer.shadowMap.type,
  11064. toneMapping: renderer.toneMapping,
  11065. physicallyCorrectLights: renderer.physicallyCorrectLights,
  11066. premultipliedAlpha: material.premultipliedAlpha,
  11067. alphaTest: material.alphaTest,
  11068. doubleSided: material.side === DoubleSide,
  11069. flipSided: material.side === BackSide,
  11070. depthPacking: ( material.depthPacking !== undefined ) ? material.depthPacking : false
  11071. };
  11072. return parameters;
  11073. };
  11074. this.getProgramCode = function ( material, parameters ) {
  11075. var array = [];
  11076. if ( parameters.shaderID ) {
  11077. array.push( parameters.shaderID );
  11078. } else {
  11079. array.push( material.fragmentShader );
  11080. array.push( material.vertexShader );
  11081. }
  11082. if ( material.defines !== undefined ) {
  11083. for ( var name in material.defines ) {
  11084. array.push( name );
  11085. array.push( material.defines[ name ] );
  11086. }
  11087. }
  11088. for ( var i = 0; i < parameterNames.length; i ++ ) {
  11089. array.push( parameters[ parameterNames[ i ] ] );
  11090. }
  11091. array.push( material.onBeforeCompile.toString() );
  11092. array.push( renderer.gammaOutput );
  11093. array.push( renderer.gammaFactor );
  11094. return array.join();
  11095. };
  11096. this.acquireProgram = function ( material, shader, parameters, code ) {
  11097. var program;
  11098. // Check if code has been already compiled
  11099. for ( var p = 0, pl = programs.length; p < pl; p ++ ) {
  11100. var programInfo = programs[ p ];
  11101. if ( programInfo.code === code ) {
  11102. program = programInfo;
  11103. ++ program.usedTimes;
  11104. break;
  11105. }
  11106. }
  11107. if ( program === undefined ) {
  11108. program = new WebGLProgram( renderer, extensions, code, material, shader, parameters, capabilities );
  11109. programs.push( program );
  11110. }
  11111. return program;
  11112. };
  11113. this.releaseProgram = function ( program ) {
  11114. if ( -- program.usedTimes === 0 ) {
  11115. // Remove from unordered set
  11116. var i = programs.indexOf( program );
  11117. programs[ i ] = programs[ programs.length - 1 ];
  11118. programs.pop();
  11119. // Free WebGL resources
  11120. program.destroy();
  11121. }
  11122. };
  11123. // Exposed for resource monitoring & error feedback via renderer.info:
  11124. this.programs = programs;
  11125. }
  11126. /**
  11127. * @author fordacious / fordacious.github.io
  11128. */
  11129. function WebGLProperties() {
  11130. var properties = new WeakMap();
  11131. function get( object ) {
  11132. var map = properties.get( object );
  11133. if ( map === undefined ) {
  11134. map = {};
  11135. properties.set( object, map );
  11136. }
  11137. return map;
  11138. }
  11139. function remove( object ) {
  11140. properties.delete( object );
  11141. }
  11142. function update( object, key, value ) {
  11143. properties.get( object )[ key ] = value;
  11144. }
  11145. function dispose() {
  11146. properties = new WeakMap();
  11147. }
  11148. return {
  11149. get: get,
  11150. remove: remove,
  11151. update: update,
  11152. dispose: dispose
  11153. };
  11154. }
  11155. /**
  11156. * @author mrdoob / http://mrdoob.com/
  11157. */
  11158. function painterSortStable( a, b ) {
  11159. if ( a.groupOrder !== b.groupOrder ) {
  11160. return a.groupOrder - b.groupOrder;
  11161. } else if ( a.renderOrder !== b.renderOrder ) {
  11162. return a.renderOrder - b.renderOrder;
  11163. } else if ( a.program !== b.program ) {
  11164. return a.program.id - b.program.id;
  11165. } else if ( a.material.id !== b.material.id ) {
  11166. return a.material.id - b.material.id;
  11167. } else if ( a.z !== b.z ) {
  11168. return a.z - b.z;
  11169. } else {
  11170. return a.id - b.id;
  11171. }
  11172. }
  11173. function reversePainterSortStable( a, b ) {
  11174. if ( a.groupOrder !== b.groupOrder ) {
  11175. return a.groupOrder - b.groupOrder;
  11176. } else if ( a.renderOrder !== b.renderOrder ) {
  11177. return a.renderOrder - b.renderOrder;
  11178. } else if ( a.z !== b.z ) {
  11179. return b.z - a.z;
  11180. } else {
  11181. return a.id - b.id;
  11182. }
  11183. }
  11184. function WebGLRenderList() {
  11185. var renderItems = [];
  11186. var renderItemsIndex = 0;
  11187. var opaque = [];
  11188. var transparent = [];
  11189. var defaultProgram = { id: - 1 };
  11190. function init() {
  11191. renderItemsIndex = 0;
  11192. opaque.length = 0;
  11193. transparent.length = 0;
  11194. }
  11195. function getNextRenderItem( object, geometry, material, groupOrder, z, group ) {
  11196. var renderItem = renderItems[ renderItemsIndex ];
  11197. if ( renderItem === undefined ) {
  11198. renderItem = {
  11199. id: object.id,
  11200. object: object,
  11201. geometry: geometry,
  11202. material: material,
  11203. program: material.program || defaultProgram,
  11204. groupOrder: groupOrder,
  11205. renderOrder: object.renderOrder,
  11206. z: z,
  11207. group: group
  11208. };
  11209. renderItems[ renderItemsIndex ] = renderItem;
  11210. } else {
  11211. renderItem.id = object.id;
  11212. renderItem.object = object;
  11213. renderItem.geometry = geometry;
  11214. renderItem.material = material;
  11215. renderItem.program = material.program || defaultProgram;
  11216. renderItem.groupOrder = groupOrder;
  11217. renderItem.renderOrder = object.renderOrder;
  11218. renderItem.z = z;
  11219. renderItem.group = group;
  11220. }
  11221. renderItemsIndex ++;
  11222. return renderItem;
  11223. }
  11224. function push( object, geometry, material, groupOrder, z, group ) {
  11225. var renderItem = getNextRenderItem( object, geometry, material, groupOrder, z, group );
  11226. ( material.transparent === true ? transparent : opaque ).push( renderItem );
  11227. }
  11228. function unshift( object, geometry, material, groupOrder, z, group ) {
  11229. var renderItem = getNextRenderItem( object, geometry, material, groupOrder, z, group );
  11230. ( material.transparent === true ? transparent : opaque ).unshift( renderItem );
  11231. }
  11232. function sort() {
  11233. if ( opaque.length > 1 ) opaque.sort( painterSortStable );
  11234. if ( transparent.length > 1 ) transparent.sort( reversePainterSortStable );
  11235. }
  11236. return {
  11237. opaque: opaque,
  11238. transparent: transparent,
  11239. init: init,
  11240. push: push,
  11241. unshift: unshift,
  11242. sort: sort
  11243. };
  11244. }
  11245. function WebGLRenderLists() {
  11246. var lists = {};
  11247. function onSceneDispose( event ) {
  11248. var scene = event.target;
  11249. scene.removeEventListener( 'dispose', onSceneDispose );
  11250. delete lists[ scene.id ];
  11251. }
  11252. function get( scene, camera ) {
  11253. var cameras = lists[ scene.id ];
  11254. var list;
  11255. if ( cameras === undefined ) {
  11256. list = new WebGLRenderList();
  11257. lists[ scene.id ] = {};
  11258. lists[ scene.id ][ camera.id ] = list;
  11259. scene.addEventListener( 'dispose', onSceneDispose );
  11260. } else {
  11261. list = cameras[ camera.id ];
  11262. if ( list === undefined ) {
  11263. list = new WebGLRenderList();
  11264. cameras[ camera.id ] = list;
  11265. }
  11266. }
  11267. return list;
  11268. }
  11269. function dispose() {
  11270. lists = {};
  11271. }
  11272. return {
  11273. get: get,
  11274. dispose: dispose
  11275. };
  11276. }
  11277. /**
  11278. * @author mrdoob / http://mrdoob.com/
  11279. */
  11280. function UniformsCache() {
  11281. var lights = {};
  11282. return {
  11283. get: function ( light ) {
  11284. if ( lights[ light.id ] !== undefined ) {
  11285. return lights[ light.id ];
  11286. }
  11287. var uniforms;
  11288. switch ( light.type ) {
  11289. case 'DirectionalLight':
  11290. uniforms = {
  11291. direction: new Vector3(),
  11292. color: new Color(),
  11293. shadow: false,
  11294. shadowBias: 0,
  11295. shadowRadius: 1,
  11296. shadowMapSize: new Vector2()
  11297. };
  11298. break;
  11299. case 'SpotLight':
  11300. uniforms = {
  11301. position: new Vector3(),
  11302. direction: new Vector3(),
  11303. color: new Color(),
  11304. distance: 0,
  11305. coneCos: 0,
  11306. penumbraCos: 0,
  11307. decay: 0,
  11308. shadow: false,
  11309. shadowBias: 0,
  11310. shadowRadius: 1,
  11311. shadowMapSize: new Vector2()
  11312. };
  11313. break;
  11314. case 'PointLight':
  11315. uniforms = {
  11316. position: new Vector3(),
  11317. color: new Color(),
  11318. distance: 0,
  11319. decay: 0,
  11320. shadow: false,
  11321. shadowBias: 0,
  11322. shadowRadius: 1,
  11323. shadowMapSize: new Vector2(),
  11324. shadowCameraNear: 1,
  11325. shadowCameraFar: 1000
  11326. };
  11327. break;
  11328. case 'HemisphereLight':
  11329. uniforms = {
  11330. direction: new Vector3(),
  11331. skyColor: new Color(),
  11332. groundColor: new Color()
  11333. };
  11334. break;
  11335. case 'RectAreaLight':
  11336. uniforms = {
  11337. color: new Color(),
  11338. position: new Vector3(),
  11339. halfWidth: new Vector3(),
  11340. halfHeight: new Vector3()
  11341. // TODO (abelnation): set RectAreaLight shadow uniforms
  11342. };
  11343. break;
  11344. }
  11345. lights[ light.id ] = uniforms;
  11346. return uniforms;
  11347. }
  11348. };
  11349. }
  11350. var nextVersion = 0;
  11351. function WebGLLights() {
  11352. var cache = new UniformsCache();
  11353. var state = {
  11354. version: 0,
  11355. hash: {
  11356. directionalLength: - 1,
  11357. pointLength: - 1,
  11358. spotLength: - 1,
  11359. rectAreaLength: - 1,
  11360. hemiLength: - 1,
  11361. shadowsLength: - 1,
  11362. },
  11363. ambient: [ 0, 0, 0 ],
  11364. probe: [],
  11365. directional: [],
  11366. directionalShadowMap: [],
  11367. directionalShadowMatrix: [],
  11368. spot: [],
  11369. spotShadowMap: [],
  11370. spotShadowMatrix: [],
  11371. rectArea: [],
  11372. point: [],
  11373. pointShadowMap: [],
  11374. pointShadowMatrix: [],
  11375. hemi: []
  11376. };
  11377. for ( var i = 0; i < 9; i ++ ) state.probe.push( new Vector3() );
  11378. var vector3 = new Vector3();
  11379. var matrix4 = new Matrix4();
  11380. var matrix42 = new Matrix4();
  11381. function setup( lights, shadows, camera ) {
  11382. var r = 0, g = 0, b = 0;
  11383. for ( var i = 0; i < 9; i ++ ) state.probe[ i ].set( 0, 0, 0 );
  11384. var directionalLength = 0;
  11385. var pointLength = 0;
  11386. var spotLength = 0;
  11387. var rectAreaLength = 0;
  11388. var hemiLength = 0;
  11389. var viewMatrix = camera.matrixWorldInverse;
  11390. for ( var i = 0, l = lights.length; i < l; i ++ ) {
  11391. var light = lights[ i ];
  11392. var color = light.color;
  11393. var intensity = light.intensity;
  11394. var distance = light.distance;
  11395. var shadowMap = ( light.shadow && light.shadow.map ) ? light.shadow.map.texture : null;
  11396. if ( light.isAmbientLight ) {
  11397. r += color.r * intensity;
  11398. g += color.g * intensity;
  11399. b += color.b * intensity;
  11400. } else if ( light.isLightProbe ) {
  11401. for ( var j = 0; j < 9; j ++ ) {
  11402. state.probe[ j ].addScaledVector( light.sh.coefficients[ j ], intensity );
  11403. }
  11404. } else if ( light.isDirectionalLight ) {
  11405. var uniforms = cache.get( light );
  11406. uniforms.color.copy( light.color ).multiplyScalar( light.intensity );
  11407. uniforms.direction.setFromMatrixPosition( light.matrixWorld );
  11408. vector3.setFromMatrixPosition( light.target.matrixWorld );
  11409. uniforms.direction.sub( vector3 );
  11410. uniforms.direction.transformDirection( viewMatrix );
  11411. uniforms.shadow = light.castShadow;
  11412. if ( light.castShadow ) {
  11413. var shadow = light.shadow;
  11414. uniforms.shadowBias = shadow.bias;
  11415. uniforms.shadowRadius = shadow.radius;
  11416. uniforms.shadowMapSize = shadow.mapSize;
  11417. }
  11418. state.directionalShadowMap[ directionalLength ] = shadowMap;
  11419. state.directionalShadowMatrix[ directionalLength ] = light.shadow.matrix;
  11420. state.directional[ directionalLength ] = uniforms;
  11421. directionalLength ++;
  11422. } else if ( light.isSpotLight ) {
  11423. var uniforms = cache.get( light );
  11424. uniforms.position.setFromMatrixPosition( light.matrixWorld );
  11425. uniforms.position.applyMatrix4( viewMatrix );
  11426. uniforms.color.copy( color ).multiplyScalar( intensity );
  11427. uniforms.distance = distance;
  11428. uniforms.direction.setFromMatrixPosition( light.matrixWorld );
  11429. vector3.setFromMatrixPosition( light.target.matrixWorld );
  11430. uniforms.direction.sub( vector3 );
  11431. uniforms.direction.transformDirection( viewMatrix );
  11432. uniforms.coneCos = Math.cos( light.angle );
  11433. uniforms.penumbraCos = Math.cos( light.angle * ( 1 - light.penumbra ) );
  11434. uniforms.decay = light.decay;
  11435. uniforms.shadow = light.castShadow;
  11436. if ( light.castShadow ) {
  11437. var shadow = light.shadow;
  11438. uniforms.shadowBias = shadow.bias;
  11439. uniforms.shadowRadius = shadow.radius;
  11440. uniforms.shadowMapSize = shadow.mapSize;
  11441. }
  11442. state.spotShadowMap[ spotLength ] = shadowMap;
  11443. state.spotShadowMatrix[ spotLength ] = light.shadow.matrix;
  11444. state.spot[ spotLength ] = uniforms;
  11445. spotLength ++;
  11446. } else if ( light.isRectAreaLight ) {
  11447. var uniforms = cache.get( light );
  11448. // (a) intensity is the total visible light emitted
  11449. //uniforms.color.copy( color ).multiplyScalar( intensity / ( light.width * light.height * Math.PI ) );
  11450. // (b) intensity is the brightness of the light
  11451. uniforms.color.copy( color ).multiplyScalar( intensity );
  11452. uniforms.position.setFromMatrixPosition( light.matrixWorld );
  11453. uniforms.position.applyMatrix4( viewMatrix );
  11454. // extract local rotation of light to derive width/height half vectors
  11455. matrix42.identity();
  11456. matrix4.copy( light.matrixWorld );
  11457. matrix4.premultiply( viewMatrix );
  11458. matrix42.extractRotation( matrix4 );
  11459. uniforms.halfWidth.set( light.width * 0.5, 0.0, 0.0 );
  11460. uniforms.halfHeight.set( 0.0, light.height * 0.5, 0.0 );
  11461. uniforms.halfWidth.applyMatrix4( matrix42 );
  11462. uniforms.halfHeight.applyMatrix4( matrix42 );
  11463. // TODO (abelnation): RectAreaLight distance?
  11464. // uniforms.distance = distance;
  11465. state.rectArea[ rectAreaLength ] = uniforms;
  11466. rectAreaLength ++;
  11467. } else if ( light.isPointLight ) {
  11468. var uniforms = cache.get( light );
  11469. uniforms.position.setFromMatrixPosition( light.matrixWorld );
  11470. uniforms.position.applyMatrix4( viewMatrix );
  11471. uniforms.color.copy( light.color ).multiplyScalar( light.intensity );
  11472. uniforms.distance = light.distance;
  11473. uniforms.decay = light.decay;
  11474. uniforms.shadow = light.castShadow;
  11475. if ( light.castShadow ) {
  11476. var shadow = light.shadow;
  11477. uniforms.shadowBias = shadow.bias;
  11478. uniforms.shadowRadius = shadow.radius;
  11479. uniforms.shadowMapSize = shadow.mapSize;
  11480. uniforms.shadowCameraNear = shadow.camera.near;
  11481. uniforms.shadowCameraFar = shadow.camera.far;
  11482. }
  11483. state.pointShadowMap[ pointLength ] = shadowMap;
  11484. state.pointShadowMatrix[ pointLength ] = light.shadow.matrix;
  11485. state.point[ pointLength ] = uniforms;
  11486. pointLength ++;
  11487. } else if ( light.isHemisphereLight ) {
  11488. var uniforms = cache.get( light );
  11489. uniforms.direction.setFromMatrixPosition( light.matrixWorld );
  11490. uniforms.direction.transformDirection( viewMatrix );
  11491. uniforms.direction.normalize();
  11492. uniforms.skyColor.copy( light.color ).multiplyScalar( intensity );
  11493. uniforms.groundColor.copy( light.groundColor ).multiplyScalar( intensity );
  11494. state.hemi[ hemiLength ] = uniforms;
  11495. hemiLength ++;
  11496. }
  11497. }
  11498. state.ambient[ 0 ] = r;
  11499. state.ambient[ 1 ] = g;
  11500. state.ambient[ 2 ] = b;
  11501. var hash = state.hash;
  11502. if ( hash.directionalLength !== directionalLength ||
  11503. hash.pointLength !== pointLength ||
  11504. hash.spotLength !== spotLength ||
  11505. hash.rectAreaLength !== rectAreaLength ||
  11506. hash.hemiLength !== hemiLength ||
  11507. hash.shadowsLength !== shadows.length ) {
  11508. state.directional.length = directionalLength;
  11509. state.spot.length = spotLength;
  11510. state.rectArea.length = rectAreaLength;
  11511. state.point.length = pointLength;
  11512. state.hemi.length = hemiLength;
  11513. hash.directionalLength = directionalLength;
  11514. hash.pointLength = pointLength;
  11515. hash.spotLength = spotLength;
  11516. hash.rectAreaLength = rectAreaLength;
  11517. hash.hemiLength = hemiLength;
  11518. hash.shadowsLength = shadows.length;
  11519. state.version = nextVersion ++;
  11520. }
  11521. }
  11522. return {
  11523. setup: setup,
  11524. state: state
  11525. };
  11526. }
  11527. /**
  11528. * @author Mugen87 / https://github.com/Mugen87
  11529. */
  11530. function WebGLRenderState() {
  11531. var lights = new WebGLLights();
  11532. var lightsArray = [];
  11533. var shadowsArray = [];
  11534. function init() {
  11535. lightsArray.length = 0;
  11536. shadowsArray.length = 0;
  11537. }
  11538. function pushLight( light ) {
  11539. lightsArray.push( light );
  11540. }
  11541. function pushShadow( shadowLight ) {
  11542. shadowsArray.push( shadowLight );
  11543. }
  11544. function setupLights( camera ) {
  11545. lights.setup( lightsArray, shadowsArray, camera );
  11546. }
  11547. var state = {
  11548. lightsArray: lightsArray,
  11549. shadowsArray: shadowsArray,
  11550. lights: lights
  11551. };
  11552. return {
  11553. init: init,
  11554. state: state,
  11555. setupLights: setupLights,
  11556. pushLight: pushLight,
  11557. pushShadow: pushShadow
  11558. };
  11559. }
  11560. function WebGLRenderStates() {
  11561. var renderStates = {};
  11562. function onSceneDispose( event ) {
  11563. var scene = event.target;
  11564. scene.removeEventListener( 'dispose', onSceneDispose );
  11565. delete renderStates[ scene.id ];
  11566. }
  11567. function get( scene, camera ) {
  11568. var renderState;
  11569. if ( renderStates[ scene.id ] === undefined ) {
  11570. renderState = new WebGLRenderState();
  11571. renderStates[ scene.id ] = {};
  11572. renderStates[ scene.id ][ camera.id ] = renderState;
  11573. scene.addEventListener( 'dispose', onSceneDispose );
  11574. } else {
  11575. if ( renderStates[ scene.id ][ camera.id ] === undefined ) {
  11576. renderState = new WebGLRenderState();
  11577. renderStates[ scene.id ][ camera.id ] = renderState;
  11578. } else {
  11579. renderState = renderStates[ scene.id ][ camera.id ];
  11580. }
  11581. }
  11582. return renderState;
  11583. }
  11584. function dispose() {
  11585. renderStates = {};
  11586. }
  11587. return {
  11588. get: get,
  11589. dispose: dispose
  11590. };
  11591. }
  11592. /**
  11593. * @author mrdoob / http://mrdoob.com/
  11594. * @author alteredq / http://alteredqualia.com/
  11595. * @author bhouston / https://clara.io
  11596. * @author WestLangley / http://github.com/WestLangley
  11597. *
  11598. * parameters = {
  11599. *
  11600. * opacity: <float>,
  11601. *
  11602. * map: new THREE.Texture( <Image> ),
  11603. *
  11604. * alphaMap: new THREE.Texture( <Image> ),
  11605. *
  11606. * displacementMap: new THREE.Texture( <Image> ),
  11607. * displacementScale: <float>,
  11608. * displacementBias: <float>,
  11609. *
  11610. * wireframe: <boolean>,
  11611. * wireframeLinewidth: <float>
  11612. * }
  11613. */
  11614. function MeshDepthMaterial( parameters ) {
  11615. Material.call( this );
  11616. this.type = 'MeshDepthMaterial';
  11617. this.depthPacking = BasicDepthPacking;
  11618. this.skinning = false;
  11619. this.morphTargets = false;
  11620. this.map = null;
  11621. this.alphaMap = null;
  11622. this.displacementMap = null;
  11623. this.displacementScale = 1;
  11624. this.displacementBias = 0;
  11625. this.wireframe = false;
  11626. this.wireframeLinewidth = 1;
  11627. this.fog = false;
  11628. this.lights = false;
  11629. this.setValues( parameters );
  11630. }
  11631. MeshDepthMaterial.prototype = Object.create( Material.prototype );
  11632. MeshDepthMaterial.prototype.constructor = MeshDepthMaterial;
  11633. MeshDepthMaterial.prototype.isMeshDepthMaterial = true;
  11634. MeshDepthMaterial.prototype.copy = function ( source ) {
  11635. Material.prototype.copy.call( this, source );
  11636. this.depthPacking = source.depthPacking;
  11637. this.skinning = source.skinning;
  11638. this.morphTargets = source.morphTargets;
  11639. this.map = source.map;
  11640. this.alphaMap = source.alphaMap;
  11641. this.displacementMap = source.displacementMap;
  11642. this.displacementScale = source.displacementScale;
  11643. this.displacementBias = source.displacementBias;
  11644. this.wireframe = source.wireframe;
  11645. this.wireframeLinewidth = source.wireframeLinewidth;
  11646. return this;
  11647. };
  11648. /**
  11649. * @author WestLangley / http://github.com/WestLangley
  11650. *
  11651. * parameters = {
  11652. *
  11653. * referencePosition: <float>,
  11654. * nearDistance: <float>,
  11655. * farDistance: <float>,
  11656. *
  11657. * skinning: <bool>,
  11658. * morphTargets: <bool>,
  11659. *
  11660. * map: new THREE.Texture( <Image> ),
  11661. *
  11662. * alphaMap: new THREE.Texture( <Image> ),
  11663. *
  11664. * displacementMap: new THREE.Texture( <Image> ),
  11665. * displacementScale: <float>,
  11666. * displacementBias: <float>
  11667. *
  11668. * }
  11669. */
  11670. function MeshDistanceMaterial( parameters ) {
  11671. Material.call( this );
  11672. this.type = 'MeshDistanceMaterial';
  11673. this.referencePosition = new Vector3();
  11674. this.nearDistance = 1;
  11675. this.farDistance = 1000;
  11676. this.skinning = false;
  11677. this.morphTargets = false;
  11678. this.map = null;
  11679. this.alphaMap = null;
  11680. this.displacementMap = null;
  11681. this.displacementScale = 1;
  11682. this.displacementBias = 0;
  11683. this.fog = false;
  11684. this.lights = false;
  11685. this.setValues( parameters );
  11686. }
  11687. MeshDistanceMaterial.prototype = Object.create( Material.prototype );
  11688. MeshDistanceMaterial.prototype.constructor = MeshDistanceMaterial;
  11689. MeshDistanceMaterial.prototype.isMeshDistanceMaterial = true;
  11690. MeshDistanceMaterial.prototype.copy = function ( source ) {
  11691. Material.prototype.copy.call( this, source );
  11692. this.referencePosition.copy( source.referencePosition );
  11693. this.nearDistance = source.nearDistance;
  11694. this.farDistance = source.farDistance;
  11695. this.skinning = source.skinning;
  11696. this.morphTargets = source.morphTargets;
  11697. this.map = source.map;
  11698. this.alphaMap = source.alphaMap;
  11699. this.displacementMap = source.displacementMap;
  11700. this.displacementScale = source.displacementScale;
  11701. this.displacementBias = source.displacementBias;
  11702. return this;
  11703. };
  11704. /**
  11705. * @author alteredq / http://alteredqualia.com/
  11706. * @author mrdoob / http://mrdoob.com/
  11707. */
  11708. function WebGLShadowMap( _renderer, _objects, maxTextureSize ) {
  11709. var _frustum = new Frustum(),
  11710. _projScreenMatrix = new Matrix4(),
  11711. _shadowMapSize = new Vector2(),
  11712. _maxShadowMapSize = new Vector2( maxTextureSize, maxTextureSize ),
  11713. _lookTarget = new Vector3(),
  11714. _lightPositionWorld = new Vector3(),
  11715. _MorphingFlag = 1,
  11716. _SkinningFlag = 2,
  11717. _NumberOfMaterialVariants = ( _MorphingFlag | _SkinningFlag ) + 1,
  11718. _depthMaterials = new Array( _NumberOfMaterialVariants ),
  11719. _distanceMaterials = new Array( _NumberOfMaterialVariants ),
  11720. _materialCache = {};
  11721. var shadowSide = { 0: BackSide, 1: FrontSide, 2: DoubleSide };
  11722. var cubeDirections = [
  11723. new Vector3( 1, 0, 0 ), new Vector3( - 1, 0, 0 ), new Vector3( 0, 0, 1 ),
  11724. new Vector3( 0, 0, - 1 ), new Vector3( 0, 1, 0 ), new Vector3( 0, - 1, 0 )
  11725. ];
  11726. var cubeUps = [
  11727. new Vector3( 0, 1, 0 ), new Vector3( 0, 1, 0 ), new Vector3( 0, 1, 0 ),
  11728. new Vector3( 0, 1, 0 ), new Vector3( 0, 0, 1 ), new Vector3( 0, 0, - 1 )
  11729. ];
  11730. var cube2DViewPorts = [
  11731. new Vector4(), new Vector4(), new Vector4(),
  11732. new Vector4(), new Vector4(), new Vector4()
  11733. ];
  11734. // init
  11735. for ( var i = 0; i !== _NumberOfMaterialVariants; ++ i ) {
  11736. var useMorphing = ( i & _MorphingFlag ) !== 0;
  11737. var useSkinning = ( i & _SkinningFlag ) !== 0;
  11738. var depthMaterial = new MeshDepthMaterial( {
  11739. depthPacking: RGBADepthPacking,
  11740. morphTargets: useMorphing,
  11741. skinning: useSkinning
  11742. } );
  11743. _depthMaterials[ i ] = depthMaterial;
  11744. //
  11745. var distanceMaterial = new MeshDistanceMaterial( {
  11746. morphTargets: useMorphing,
  11747. skinning: useSkinning
  11748. } );
  11749. _distanceMaterials[ i ] = distanceMaterial;
  11750. }
  11751. //
  11752. var scope = this;
  11753. this.enabled = false;
  11754. this.autoUpdate = true;
  11755. this.needsUpdate = false;
  11756. this.type = PCFShadowMap;
  11757. this.render = function ( lights, scene, camera ) {
  11758. if ( scope.enabled === false ) return;
  11759. if ( scope.autoUpdate === false && scope.needsUpdate === false ) return;
  11760. if ( lights.length === 0 ) return;
  11761. var currentRenderTarget = _renderer.getRenderTarget();
  11762. var activeCubeFace = _renderer.getActiveCubeFace();
  11763. var activeMipmapLevel = _renderer.getActiveMipmapLevel();
  11764. var _state = _renderer.state;
  11765. // Set GL state for depth map.
  11766. _state.setBlending( NoBlending );
  11767. _state.buffers.color.setClear( 1, 1, 1, 1 );
  11768. _state.buffers.depth.setTest( true );
  11769. _state.setScissorTest( false );
  11770. // render depth map
  11771. var faceCount;
  11772. for ( var i = 0, il = lights.length; i < il; i ++ ) {
  11773. var light = lights[ i ];
  11774. var shadow = light.shadow;
  11775. var isPointLight = light && light.isPointLight;
  11776. if ( shadow === undefined ) {
  11777. console.warn( 'THREE.WebGLShadowMap:', light, 'has no shadow.' );
  11778. continue;
  11779. }
  11780. var shadowCamera = shadow.camera;
  11781. _shadowMapSize.copy( shadow.mapSize );
  11782. _shadowMapSize.min( _maxShadowMapSize );
  11783. if ( isPointLight ) {
  11784. var vpWidth = _shadowMapSize.x;
  11785. var vpHeight = _shadowMapSize.y;
  11786. // These viewports map a cube-map onto a 2D texture with the
  11787. // following orientation:
  11788. //
  11789. // xzXZ
  11790. // y Y
  11791. //
  11792. // X - Positive x direction
  11793. // x - Negative x direction
  11794. // Y - Positive y direction
  11795. // y - Negative y direction
  11796. // Z - Positive z direction
  11797. // z - Negative z direction
  11798. // positive X
  11799. cube2DViewPorts[ 0 ].set( vpWidth * 2, vpHeight, vpWidth, vpHeight );
  11800. // negative X
  11801. cube2DViewPorts[ 1 ].set( 0, vpHeight, vpWidth, vpHeight );
  11802. // positive Z
  11803. cube2DViewPorts[ 2 ].set( vpWidth * 3, vpHeight, vpWidth, vpHeight );
  11804. // negative Z
  11805. cube2DViewPorts[ 3 ].set( vpWidth, vpHeight, vpWidth, vpHeight );
  11806. // positive Y
  11807. cube2DViewPorts[ 4 ].set( vpWidth * 3, 0, vpWidth, vpHeight );
  11808. // negative Y
  11809. cube2DViewPorts[ 5 ].set( vpWidth, 0, vpWidth, vpHeight );
  11810. _shadowMapSize.x *= 4.0;
  11811. _shadowMapSize.y *= 2.0;
  11812. }
  11813. if ( shadow.map === null ) {
  11814. var pars = { minFilter: NearestFilter, magFilter: NearestFilter, format: RGBAFormat };
  11815. shadow.map = new WebGLRenderTarget( _shadowMapSize.x, _shadowMapSize.y, pars );
  11816. shadow.map.texture.name = light.name + ".shadowMap";
  11817. shadowCamera.updateProjectionMatrix();
  11818. }
  11819. if ( shadow.isSpotLightShadow ) {
  11820. shadow.update( light );
  11821. }
  11822. var shadowMap = shadow.map;
  11823. var shadowMatrix = shadow.matrix;
  11824. _lightPositionWorld.setFromMatrixPosition( light.matrixWorld );
  11825. shadowCamera.position.copy( _lightPositionWorld );
  11826. if ( isPointLight ) {
  11827. faceCount = 6;
  11828. // for point lights we set the shadow matrix to be a translation-only matrix
  11829. // equal to inverse of the light's position
  11830. shadowMatrix.makeTranslation( - _lightPositionWorld.x, - _lightPositionWorld.y, - _lightPositionWorld.z );
  11831. } else {
  11832. faceCount = 1;
  11833. _lookTarget.setFromMatrixPosition( light.target.matrixWorld );
  11834. shadowCamera.lookAt( _lookTarget );
  11835. shadowCamera.updateMatrixWorld();
  11836. // compute shadow matrix
  11837. shadowMatrix.set(
  11838. 0.5, 0.0, 0.0, 0.5,
  11839. 0.0, 0.5, 0.0, 0.5,
  11840. 0.0, 0.0, 0.5, 0.5,
  11841. 0.0, 0.0, 0.0, 1.0
  11842. );
  11843. shadowMatrix.multiply( shadowCamera.projectionMatrix );
  11844. shadowMatrix.multiply( shadowCamera.matrixWorldInverse );
  11845. }
  11846. _renderer.setRenderTarget( shadowMap );
  11847. _renderer.clear();
  11848. // render shadow map for each cube face (if omni-directional) or
  11849. // run a single pass if not
  11850. for ( var face = 0; face < faceCount; face ++ ) {
  11851. if ( isPointLight ) {
  11852. _lookTarget.copy( shadowCamera.position );
  11853. _lookTarget.add( cubeDirections[ face ] );
  11854. shadowCamera.up.copy( cubeUps[ face ] );
  11855. shadowCamera.lookAt( _lookTarget );
  11856. shadowCamera.updateMatrixWorld();
  11857. var vpDimensions = cube2DViewPorts[ face ];
  11858. _state.viewport( vpDimensions );
  11859. }
  11860. // update camera matrices and frustum
  11861. _projScreenMatrix.multiplyMatrices( shadowCamera.projectionMatrix, shadowCamera.matrixWorldInverse );
  11862. _frustum.setFromMatrix( _projScreenMatrix );
  11863. // set object matrices & frustum culling
  11864. renderObject( scene, camera, shadowCamera, isPointLight );
  11865. }
  11866. }
  11867. scope.needsUpdate = false;
  11868. _renderer.setRenderTarget( currentRenderTarget, activeCubeFace, activeMipmapLevel );
  11869. };
  11870. function getDepthMaterial( object, material, isPointLight, lightPositionWorld, shadowCameraNear, shadowCameraFar ) {
  11871. var geometry = object.geometry;
  11872. var result = null;
  11873. var materialVariants = _depthMaterials;
  11874. var customMaterial = object.customDepthMaterial;
  11875. if ( isPointLight ) {
  11876. materialVariants = _distanceMaterials;
  11877. customMaterial = object.customDistanceMaterial;
  11878. }
  11879. if ( ! customMaterial ) {
  11880. var useMorphing = false;
  11881. if ( material.morphTargets ) {
  11882. if ( geometry && geometry.isBufferGeometry ) {
  11883. useMorphing = geometry.morphAttributes && geometry.morphAttributes.position && geometry.morphAttributes.position.length > 0;
  11884. } else if ( geometry && geometry.isGeometry ) {
  11885. useMorphing = geometry.morphTargets && geometry.morphTargets.length > 0;
  11886. }
  11887. }
  11888. if ( object.isSkinnedMesh && material.skinning === false ) {
  11889. console.warn( 'THREE.WebGLShadowMap: THREE.SkinnedMesh with material.skinning set to false:', object );
  11890. }
  11891. var useSkinning = object.isSkinnedMesh && material.skinning;
  11892. var variantIndex = 0;
  11893. if ( useMorphing ) variantIndex |= _MorphingFlag;
  11894. if ( useSkinning ) variantIndex |= _SkinningFlag;
  11895. result = materialVariants[ variantIndex ];
  11896. } else {
  11897. result = customMaterial;
  11898. }
  11899. if ( _renderer.localClippingEnabled &&
  11900. material.clipShadows === true &&
  11901. material.clippingPlanes.length !== 0 ) {
  11902. // in this case we need a unique material instance reflecting the
  11903. // appropriate state
  11904. var keyA = result.uuid, keyB = material.uuid;
  11905. var materialsForVariant = _materialCache[ keyA ];
  11906. if ( materialsForVariant === undefined ) {
  11907. materialsForVariant = {};
  11908. _materialCache[ keyA ] = materialsForVariant;
  11909. }
  11910. var cachedMaterial = materialsForVariant[ keyB ];
  11911. if ( cachedMaterial === undefined ) {
  11912. cachedMaterial = result.clone();
  11913. materialsForVariant[ keyB ] = cachedMaterial;
  11914. }
  11915. result = cachedMaterial;
  11916. }
  11917. result.visible = material.visible;
  11918. result.wireframe = material.wireframe;
  11919. result.side = ( material.shadowSide != null ) ? material.shadowSide : shadowSide[ material.side ];
  11920. result.clipShadows = material.clipShadows;
  11921. result.clippingPlanes = material.clippingPlanes;
  11922. result.clipIntersection = material.clipIntersection;
  11923. result.wireframeLinewidth = material.wireframeLinewidth;
  11924. result.linewidth = material.linewidth;
  11925. if ( isPointLight && result.isMeshDistanceMaterial ) {
  11926. result.referencePosition.copy( lightPositionWorld );
  11927. result.nearDistance = shadowCameraNear;
  11928. result.farDistance = shadowCameraFar;
  11929. }
  11930. return result;
  11931. }
  11932. function renderObject( object, camera, shadowCamera, isPointLight ) {
  11933. if ( object.visible === false ) return;
  11934. var visible = object.layers.test( camera.layers );
  11935. if ( visible && ( object.isMesh || object.isLine || object.isPoints ) ) {
  11936. if ( object.castShadow && ( ! object.frustumCulled || _frustum.intersectsObject( object ) ) ) {
  11937. object.modelViewMatrix.multiplyMatrices( shadowCamera.matrixWorldInverse, object.matrixWorld );
  11938. var geometry = _objects.update( object );
  11939. var material = object.material;
  11940. if ( Array.isArray( material ) ) {
  11941. var groups = geometry.groups;
  11942. for ( var k = 0, kl = groups.length; k < kl; k ++ ) {
  11943. var group = groups[ k ];
  11944. var groupMaterial = material[ group.materialIndex ];
  11945. if ( groupMaterial && groupMaterial.visible ) {
  11946. var depthMaterial = getDepthMaterial( object, groupMaterial, isPointLight, _lightPositionWorld, shadowCamera.near, shadowCamera.far );
  11947. _renderer.renderBufferDirect( shadowCamera, null, geometry, depthMaterial, object, group );
  11948. }
  11949. }
  11950. } else if ( material.visible ) {
  11951. var depthMaterial = getDepthMaterial( object, material, isPointLight, _lightPositionWorld, shadowCamera.near, shadowCamera.far );
  11952. _renderer.renderBufferDirect( shadowCamera, null, geometry, depthMaterial, object, null );
  11953. }
  11954. }
  11955. }
  11956. var children = object.children;
  11957. for ( var i = 0, l = children.length; i < l; i ++ ) {
  11958. renderObject( children[ i ], camera, shadowCamera, isPointLight );
  11959. }
  11960. }
  11961. }
  11962. /**
  11963. * @author mrdoob / http://mrdoob.com/
  11964. */
  11965. function WebGLState( gl, extensions, utils, capabilities ) {
  11966. function ColorBuffer() {
  11967. var locked = false;
  11968. var color = new Vector4();
  11969. var currentColorMask = null;
  11970. var currentColorClear = new Vector4( 0, 0, 0, 0 );
  11971. return {
  11972. setMask: function ( colorMask ) {
  11973. if ( currentColorMask !== colorMask && ! locked ) {
  11974. gl.colorMask( colorMask, colorMask, colorMask, colorMask );
  11975. currentColorMask = colorMask;
  11976. }
  11977. },
  11978. setLocked: function ( lock ) {
  11979. locked = lock;
  11980. },
  11981. setClear: function ( r, g, b, a, premultipliedAlpha ) {
  11982. if ( premultipliedAlpha === true ) {
  11983. r *= a; g *= a; b *= a;
  11984. }
  11985. color.set( r, g, b, a );
  11986. if ( currentColorClear.equals( color ) === false ) {
  11987. gl.clearColor( r, g, b, a );
  11988. currentColorClear.copy( color );
  11989. }
  11990. },
  11991. reset: function () {
  11992. locked = false;
  11993. currentColorMask = null;
  11994. currentColorClear.set( - 1, 0, 0, 0 ); // set to invalid state
  11995. }
  11996. };
  11997. }
  11998. function DepthBuffer() {
  11999. var locked = false;
  12000. var currentDepthMask = null;
  12001. var currentDepthFunc = null;
  12002. var currentDepthClear = null;
  12003. return {
  12004. setTest: function ( depthTest ) {
  12005. if ( depthTest ) {
  12006. enable( 2929 );
  12007. } else {
  12008. disable( 2929 );
  12009. }
  12010. },
  12011. setMask: function ( depthMask ) {
  12012. if ( currentDepthMask !== depthMask && ! locked ) {
  12013. gl.depthMask( depthMask );
  12014. currentDepthMask = depthMask;
  12015. }
  12016. },
  12017. setFunc: function ( depthFunc ) {
  12018. if ( currentDepthFunc !== depthFunc ) {
  12019. if ( depthFunc ) {
  12020. switch ( depthFunc ) {
  12021. case NeverDepth:
  12022. gl.depthFunc( 512 );
  12023. break;
  12024. case AlwaysDepth:
  12025. gl.depthFunc( 519 );
  12026. break;
  12027. case LessDepth:
  12028. gl.depthFunc( 513 );
  12029. break;
  12030. case LessEqualDepth:
  12031. gl.depthFunc( 515 );
  12032. break;
  12033. case EqualDepth:
  12034. gl.depthFunc( 514 );
  12035. break;
  12036. case GreaterEqualDepth:
  12037. gl.depthFunc( 518 );
  12038. break;
  12039. case GreaterDepth:
  12040. gl.depthFunc( 516 );
  12041. break;
  12042. case NotEqualDepth:
  12043. gl.depthFunc( 517 );
  12044. break;
  12045. default:
  12046. gl.depthFunc( 515 );
  12047. }
  12048. } else {
  12049. gl.depthFunc( 515 );
  12050. }
  12051. currentDepthFunc = depthFunc;
  12052. }
  12053. },
  12054. setLocked: function ( lock ) {
  12055. locked = lock;
  12056. },
  12057. setClear: function ( depth ) {
  12058. if ( currentDepthClear !== depth ) {
  12059. gl.clearDepth( depth );
  12060. currentDepthClear = depth;
  12061. }
  12062. },
  12063. reset: function () {
  12064. locked = false;
  12065. currentDepthMask = null;
  12066. currentDepthFunc = null;
  12067. currentDepthClear = null;
  12068. }
  12069. };
  12070. }
  12071. function StencilBuffer() {
  12072. var locked = false;
  12073. var currentStencilMask = null;
  12074. var currentStencilFunc = null;
  12075. var currentStencilRef = null;
  12076. var currentStencilFuncMask = null;
  12077. var currentStencilFail = null;
  12078. var currentStencilZFail = null;
  12079. var currentStencilZPass = null;
  12080. var currentStencilClear = null;
  12081. return {
  12082. setTest: function ( stencilTest ) {
  12083. if ( stencilTest ) {
  12084. enable( 2960 );
  12085. } else {
  12086. disable( 2960 );
  12087. }
  12088. },
  12089. setMask: function ( stencilMask ) {
  12090. if ( currentStencilMask !== stencilMask && ! locked ) {
  12091. gl.stencilMask( stencilMask );
  12092. currentStencilMask = stencilMask;
  12093. }
  12094. },
  12095. setFunc: function ( stencilFunc, stencilRef, stencilMask ) {
  12096. if ( currentStencilFunc !== stencilFunc ||
  12097. currentStencilRef !== stencilRef ||
  12098. currentStencilFuncMask !== stencilMask ) {
  12099. gl.stencilFunc( stencilFunc, stencilRef, stencilMask );
  12100. currentStencilFunc = stencilFunc;
  12101. currentStencilRef = stencilRef;
  12102. currentStencilFuncMask = stencilMask;
  12103. }
  12104. },
  12105. setOp: function ( stencilFail, stencilZFail, stencilZPass ) {
  12106. if ( currentStencilFail !== stencilFail ||
  12107. currentStencilZFail !== stencilZFail ||
  12108. currentStencilZPass !== stencilZPass ) {
  12109. gl.stencilOp( stencilFail, stencilZFail, stencilZPass );
  12110. currentStencilFail = stencilFail;
  12111. currentStencilZFail = stencilZFail;
  12112. currentStencilZPass = stencilZPass;
  12113. }
  12114. },
  12115. setLocked: function ( lock ) {
  12116. locked = lock;
  12117. },
  12118. setClear: function ( stencil ) {
  12119. if ( currentStencilClear !== stencil ) {
  12120. gl.clearStencil( stencil );
  12121. currentStencilClear = stencil;
  12122. }
  12123. },
  12124. reset: function () {
  12125. locked = false;
  12126. currentStencilMask = null;
  12127. currentStencilFunc = null;
  12128. currentStencilRef = null;
  12129. currentStencilFuncMask = null;
  12130. currentStencilFail = null;
  12131. currentStencilZFail = null;
  12132. currentStencilZPass = null;
  12133. currentStencilClear = null;
  12134. }
  12135. };
  12136. }
  12137. //
  12138. var colorBuffer = new ColorBuffer();
  12139. var depthBuffer = new DepthBuffer();
  12140. var stencilBuffer = new StencilBuffer();
  12141. var maxVertexAttributes = gl.getParameter( 34921 );
  12142. var newAttributes = new Uint8Array( maxVertexAttributes );
  12143. var enabledAttributes = new Uint8Array( maxVertexAttributes );
  12144. var attributeDivisors = new Uint8Array( maxVertexAttributes );
  12145. var enabledCapabilities = {};
  12146. var compressedTextureFormats = null;
  12147. var currentProgram = null;
  12148. var currentBlendingEnabled = null;
  12149. var currentBlending = null;
  12150. var currentBlendEquation = null;
  12151. var currentBlendSrc = null;
  12152. var currentBlendDst = null;
  12153. var currentBlendEquationAlpha = null;
  12154. var currentBlendSrcAlpha = null;
  12155. var currentBlendDstAlpha = null;
  12156. var currentPremultipledAlpha = false;
  12157. var currentFlipSided = null;
  12158. var currentCullFace = null;
  12159. var currentLineWidth = null;
  12160. var currentPolygonOffsetFactor = null;
  12161. var currentPolygonOffsetUnits = null;
  12162. var maxTextures = gl.getParameter( 35661 );
  12163. var lineWidthAvailable = false;
  12164. var version = 0;
  12165. var glVersion = gl.getParameter( 7938 );
  12166. if ( glVersion.indexOf( 'WebGL' ) !== - 1 ) {
  12167. version = parseFloat( /^WebGL\ ([0-9])/.exec( glVersion )[ 1 ] );
  12168. lineWidthAvailable = ( version >= 1.0 );
  12169. } else if ( glVersion.indexOf( 'OpenGL ES' ) !== - 1 ) {
  12170. version = parseFloat( /^OpenGL\ ES\ ([0-9])/.exec( glVersion )[ 1 ] );
  12171. lineWidthAvailable = ( version >= 2.0 );
  12172. }
  12173. var currentTextureSlot = null;
  12174. var currentBoundTextures = {};
  12175. var currentScissor = new Vector4();
  12176. var currentViewport = new Vector4();
  12177. function createTexture( type, target, count ) {
  12178. var data = new Uint8Array( 4 ); // 4 is required to match default unpack alignment of 4.
  12179. var texture = gl.createTexture();
  12180. gl.bindTexture( type, texture );
  12181. gl.texParameteri( type, 10241, 9728 );
  12182. gl.texParameteri( type, 10240, 9728 );
  12183. for ( var i = 0; i < count; i ++ ) {
  12184. gl.texImage2D( target + i, 0, 6408, 1, 1, 0, 6408, 5121, data );
  12185. }
  12186. return texture;
  12187. }
  12188. var emptyTextures = {};
  12189. emptyTextures[ 3553 ] = createTexture( 3553, 3553, 1 );
  12190. emptyTextures[ 34067 ] = createTexture( 34067, 34069, 6 );
  12191. // init
  12192. colorBuffer.setClear( 0, 0, 0, 1 );
  12193. depthBuffer.setClear( 1 );
  12194. stencilBuffer.setClear( 0 );
  12195. enable( 2929 );
  12196. depthBuffer.setFunc( LessEqualDepth );
  12197. setFlipSided( false );
  12198. setCullFace( CullFaceBack );
  12199. enable( 2884 );
  12200. setBlending( NoBlending );
  12201. //
  12202. function initAttributes() {
  12203. for ( var i = 0, l = newAttributes.length; i < l; i ++ ) {
  12204. newAttributes[ i ] = 0;
  12205. }
  12206. }
  12207. function enableAttribute( attribute ) {
  12208. enableAttributeAndDivisor( attribute, 0 );
  12209. }
  12210. function enableAttributeAndDivisor( attribute, meshPerAttribute ) {
  12211. newAttributes[ attribute ] = 1;
  12212. if ( enabledAttributes[ attribute ] === 0 ) {
  12213. gl.enableVertexAttribArray( attribute );
  12214. enabledAttributes[ attribute ] = 1;
  12215. }
  12216. if ( attributeDivisors[ attribute ] !== meshPerAttribute ) {
  12217. var extension = capabilities.isWebGL2 ? gl : extensions.get( 'ANGLE_instanced_arrays' );
  12218. extension[ capabilities.isWebGL2 ? 'vertexAttribDivisor' : 'vertexAttribDivisorANGLE' ]( attribute, meshPerAttribute );
  12219. attributeDivisors[ attribute ] = meshPerAttribute;
  12220. }
  12221. }
  12222. function disableUnusedAttributes() {
  12223. for ( var i = 0, l = enabledAttributes.length; i !== l; ++ i ) {
  12224. if ( enabledAttributes[ i ] !== newAttributes[ i ] ) {
  12225. gl.disableVertexAttribArray( i );
  12226. enabledAttributes[ i ] = 0;
  12227. }
  12228. }
  12229. }
  12230. function enable( id ) {
  12231. if ( enabledCapabilities[ id ] !== true ) {
  12232. gl.enable( id );
  12233. enabledCapabilities[ id ] = true;
  12234. }
  12235. }
  12236. function disable( id ) {
  12237. if ( enabledCapabilities[ id ] !== false ) {
  12238. gl.disable( id );
  12239. enabledCapabilities[ id ] = false;
  12240. }
  12241. }
  12242. function getCompressedTextureFormats() {
  12243. if ( compressedTextureFormats === null ) {
  12244. compressedTextureFormats = [];
  12245. if ( extensions.get( 'WEBGL_compressed_texture_pvrtc' ) ||
  12246. extensions.get( 'WEBGL_compressed_texture_s3tc' ) ||
  12247. extensions.get( 'WEBGL_compressed_texture_etc1' ) ||
  12248. extensions.get( 'WEBGL_compressed_texture_astc' ) ) {
  12249. var formats = gl.getParameter( 34467 );
  12250. for ( var i = 0; i < formats.length; i ++ ) {
  12251. compressedTextureFormats.push( formats[ i ] );
  12252. }
  12253. }
  12254. }
  12255. return compressedTextureFormats;
  12256. }
  12257. function useProgram( program ) {
  12258. if ( currentProgram !== program ) {
  12259. gl.useProgram( program );
  12260. currentProgram = program;
  12261. return true;
  12262. }
  12263. return false;
  12264. }
  12265. function setBlending( blending, blendEquation, blendSrc, blendDst, blendEquationAlpha, blendSrcAlpha, blendDstAlpha, premultipliedAlpha ) {
  12266. if ( blending === NoBlending ) {
  12267. if ( currentBlendingEnabled ) {
  12268. disable( 3042 );
  12269. currentBlendingEnabled = false;
  12270. }
  12271. return;
  12272. }
  12273. if ( ! currentBlendingEnabled ) {
  12274. enable( 3042 );
  12275. currentBlendingEnabled = true;
  12276. }
  12277. if ( blending !== CustomBlending ) {
  12278. if ( blending !== currentBlending || premultipliedAlpha !== currentPremultipledAlpha ) {
  12279. if ( currentBlendEquation !== AddEquation || currentBlendEquationAlpha !== AddEquation ) {
  12280. gl.blendEquation( 32774 );
  12281. currentBlendEquation = AddEquation;
  12282. currentBlendEquationAlpha = AddEquation;
  12283. }
  12284. if ( premultipliedAlpha ) {
  12285. switch ( blending ) {
  12286. case NormalBlending:
  12287. gl.blendFuncSeparate( 1, 771, 1, 771 );
  12288. break;
  12289. case AdditiveBlending:
  12290. gl.blendFunc( 1, 1 );
  12291. break;
  12292. case SubtractiveBlending:
  12293. gl.blendFuncSeparate( 0, 0, 769, 771 );
  12294. break;
  12295. case MultiplyBlending:
  12296. gl.blendFuncSeparate( 0, 768, 0, 770 );
  12297. break;
  12298. default:
  12299. console.error( 'THREE.WebGLState: Invalid blending: ', blending );
  12300. break;
  12301. }
  12302. } else {
  12303. switch ( blending ) {
  12304. case NormalBlending:
  12305. gl.blendFuncSeparate( 770, 771, 1, 771 );
  12306. break;
  12307. case AdditiveBlending:
  12308. gl.blendFunc( 770, 1 );
  12309. break;
  12310. case SubtractiveBlending:
  12311. gl.blendFunc( 0, 769 );
  12312. break;
  12313. case MultiplyBlending:
  12314. gl.blendFunc( 0, 768 );
  12315. break;
  12316. default:
  12317. console.error( 'THREE.WebGLState: Invalid blending: ', blending );
  12318. break;
  12319. }
  12320. }
  12321. currentBlendSrc = null;
  12322. currentBlendDst = null;
  12323. currentBlendSrcAlpha = null;
  12324. currentBlendDstAlpha = null;
  12325. currentBlending = blending;
  12326. currentPremultipledAlpha = premultipliedAlpha;
  12327. }
  12328. return;
  12329. }
  12330. // custom blending
  12331. blendEquationAlpha = blendEquationAlpha || blendEquation;
  12332. blendSrcAlpha = blendSrcAlpha || blendSrc;
  12333. blendDstAlpha = blendDstAlpha || blendDst;
  12334. if ( blendEquation !== currentBlendEquation || blendEquationAlpha !== currentBlendEquationAlpha ) {
  12335. gl.blendEquationSeparate( utils.convert( blendEquation ), utils.convert( blendEquationAlpha ) );
  12336. currentBlendEquation = blendEquation;
  12337. currentBlendEquationAlpha = blendEquationAlpha;
  12338. }
  12339. if ( blendSrc !== currentBlendSrc || blendDst !== currentBlendDst || blendSrcAlpha !== currentBlendSrcAlpha || blendDstAlpha !== currentBlendDstAlpha ) {
  12340. gl.blendFuncSeparate( utils.convert( blendSrc ), utils.convert( blendDst ), utils.convert( blendSrcAlpha ), utils.convert( blendDstAlpha ) );
  12341. currentBlendSrc = blendSrc;
  12342. currentBlendDst = blendDst;
  12343. currentBlendSrcAlpha = blendSrcAlpha;
  12344. currentBlendDstAlpha = blendDstAlpha;
  12345. }
  12346. currentBlending = blending;
  12347. currentPremultipledAlpha = null;
  12348. }
  12349. function setMaterial( material, frontFaceCW ) {
  12350. material.side === DoubleSide
  12351. ? disable( 2884 )
  12352. : enable( 2884 );
  12353. var flipSided = ( material.side === BackSide );
  12354. if ( frontFaceCW ) flipSided = ! flipSided;
  12355. setFlipSided( flipSided );
  12356. ( material.blending === NormalBlending && material.transparent === false )
  12357. ? setBlending( NoBlending )
  12358. : setBlending( material.blending, material.blendEquation, material.blendSrc, material.blendDst, material.blendEquationAlpha, material.blendSrcAlpha, material.blendDstAlpha, material.premultipliedAlpha );
  12359. depthBuffer.setFunc( material.depthFunc );
  12360. depthBuffer.setTest( material.depthTest );
  12361. depthBuffer.setMask( material.depthWrite );
  12362. colorBuffer.setMask( material.colorWrite );
  12363. var stencilWrite = material.stencilWrite;
  12364. stencilBuffer.setTest( stencilWrite );
  12365. if ( stencilWrite ) {
  12366. stencilBuffer.setFunc( material.stencilFunc, material.stencilRef, material.stencilMask );
  12367. stencilBuffer.setOp( material.stencilFail, material.stencilZFail, material.stencilZPass );
  12368. }
  12369. setPolygonOffset( material.polygonOffset, material.polygonOffsetFactor, material.polygonOffsetUnits );
  12370. }
  12371. //
  12372. function setFlipSided( flipSided ) {
  12373. if ( currentFlipSided !== flipSided ) {
  12374. if ( flipSided ) {
  12375. gl.frontFace( 2304 );
  12376. } else {
  12377. gl.frontFace( 2305 );
  12378. }
  12379. currentFlipSided = flipSided;
  12380. }
  12381. }
  12382. function setCullFace( cullFace ) {
  12383. if ( cullFace !== CullFaceNone ) {
  12384. enable( 2884 );
  12385. if ( cullFace !== currentCullFace ) {
  12386. if ( cullFace === CullFaceBack ) {
  12387. gl.cullFace( 1029 );
  12388. } else if ( cullFace === CullFaceFront ) {
  12389. gl.cullFace( 1028 );
  12390. } else {
  12391. gl.cullFace( 1032 );
  12392. }
  12393. }
  12394. } else {
  12395. disable( 2884 );
  12396. }
  12397. currentCullFace = cullFace;
  12398. }
  12399. function setLineWidth( width ) {
  12400. if ( width !== currentLineWidth ) {
  12401. if ( lineWidthAvailable ) gl.lineWidth( width );
  12402. currentLineWidth = width;
  12403. }
  12404. }
  12405. function setPolygonOffset( polygonOffset, factor, units ) {
  12406. if ( polygonOffset ) {
  12407. enable( 32823 );
  12408. if ( currentPolygonOffsetFactor !== factor || currentPolygonOffsetUnits !== units ) {
  12409. gl.polygonOffset( factor, units );
  12410. currentPolygonOffsetFactor = factor;
  12411. currentPolygonOffsetUnits = units;
  12412. }
  12413. } else {
  12414. disable( 32823 );
  12415. }
  12416. }
  12417. function setScissorTest( scissorTest ) {
  12418. if ( scissorTest ) {
  12419. enable( 3089 );
  12420. } else {
  12421. disable( 3089 );
  12422. }
  12423. }
  12424. // texture
  12425. function activeTexture( webglSlot ) {
  12426. if ( webglSlot === undefined ) webglSlot = 33984 + maxTextures - 1;
  12427. if ( currentTextureSlot !== webglSlot ) {
  12428. gl.activeTexture( webglSlot );
  12429. currentTextureSlot = webglSlot;
  12430. }
  12431. }
  12432. function bindTexture( webglType, webglTexture ) {
  12433. if ( currentTextureSlot === null ) {
  12434. activeTexture();
  12435. }
  12436. var boundTexture = currentBoundTextures[ currentTextureSlot ];
  12437. if ( boundTexture === undefined ) {
  12438. boundTexture = { type: undefined, texture: undefined };
  12439. currentBoundTextures[ currentTextureSlot ] = boundTexture;
  12440. }
  12441. if ( boundTexture.type !== webglType || boundTexture.texture !== webglTexture ) {
  12442. gl.bindTexture( webglType, webglTexture || emptyTextures[ webglType ] );
  12443. boundTexture.type = webglType;
  12444. boundTexture.texture = webglTexture;
  12445. }
  12446. }
  12447. function compressedTexImage2D() {
  12448. try {
  12449. gl.compressedTexImage2D.apply( gl, arguments );
  12450. } catch ( error ) {
  12451. console.error( 'THREE.WebGLState:', error );
  12452. }
  12453. }
  12454. function texImage2D() {
  12455. try {
  12456. gl.texImage2D.apply( gl, arguments );
  12457. } catch ( error ) {
  12458. console.error( 'THREE.WebGLState:', error );
  12459. }
  12460. }
  12461. function texImage3D() {
  12462. try {
  12463. gl.texImage3D.apply( gl, arguments );
  12464. } catch ( error ) {
  12465. console.error( 'THREE.WebGLState:', error );
  12466. }
  12467. }
  12468. //
  12469. function scissor( scissor ) {
  12470. if ( currentScissor.equals( scissor ) === false ) {
  12471. gl.scissor( scissor.x, scissor.y, scissor.z, scissor.w );
  12472. currentScissor.copy( scissor );
  12473. }
  12474. }
  12475. function viewport( viewport ) {
  12476. if ( currentViewport.equals( viewport ) === false ) {
  12477. gl.viewport( viewport.x, viewport.y, viewport.z, viewport.w );
  12478. currentViewport.copy( viewport );
  12479. }
  12480. }
  12481. //
  12482. function reset() {
  12483. for ( var i = 0; i < enabledAttributes.length; i ++ ) {
  12484. if ( enabledAttributes[ i ] === 1 ) {
  12485. gl.disableVertexAttribArray( i );
  12486. enabledAttributes[ i ] = 0;
  12487. }
  12488. }
  12489. enabledCapabilities = {};
  12490. compressedTextureFormats = null;
  12491. currentTextureSlot = null;
  12492. currentBoundTextures = {};
  12493. currentProgram = null;
  12494. currentBlending = null;
  12495. currentFlipSided = null;
  12496. currentCullFace = null;
  12497. colorBuffer.reset();
  12498. depthBuffer.reset();
  12499. stencilBuffer.reset();
  12500. }
  12501. return {
  12502. buffers: {
  12503. color: colorBuffer,
  12504. depth: depthBuffer,
  12505. stencil: stencilBuffer
  12506. },
  12507. initAttributes: initAttributes,
  12508. enableAttribute: enableAttribute,
  12509. enableAttributeAndDivisor: enableAttributeAndDivisor,
  12510. disableUnusedAttributes: disableUnusedAttributes,
  12511. enable: enable,
  12512. disable: disable,
  12513. getCompressedTextureFormats: getCompressedTextureFormats,
  12514. useProgram: useProgram,
  12515. setBlending: setBlending,
  12516. setMaterial: setMaterial,
  12517. setFlipSided: setFlipSided,
  12518. setCullFace: setCullFace,
  12519. setLineWidth: setLineWidth,
  12520. setPolygonOffset: setPolygonOffset,
  12521. setScissorTest: setScissorTest,
  12522. activeTexture: activeTexture,
  12523. bindTexture: bindTexture,
  12524. compressedTexImage2D: compressedTexImage2D,
  12525. texImage2D: texImage2D,
  12526. texImage3D: texImage3D,
  12527. scissor: scissor,
  12528. viewport: viewport,
  12529. reset: reset
  12530. };
  12531. }
  12532. /**
  12533. * @author mrdoob / http://mrdoob.com/
  12534. */
  12535. function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, info ) {
  12536. var _videoTextures = {};
  12537. var _canvas;
  12538. //
  12539. var useOffscreenCanvas = typeof OffscreenCanvas !== 'undefined';
  12540. function createCanvas( width, height ) {
  12541. // Use OffscreenCanvas when available. Specially needed in web workers
  12542. return useOffscreenCanvas ?
  12543. new OffscreenCanvas( width, height ) :
  12544. document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' );
  12545. }
  12546. function resizeImage( image, needsPowerOfTwo, needsNewCanvas, maxSize ) {
  12547. var scale = 1;
  12548. // handle case if texture exceeds max size
  12549. if ( image.width > maxSize || image.height > maxSize ) {
  12550. scale = maxSize / Math.max( image.width, image.height );
  12551. }
  12552. // only perform resize if necessary
  12553. if ( scale < 1 || needsPowerOfTwo === true ) {
  12554. // only perform resize for certain image types
  12555. if ( ( typeof HTMLImageElement !== 'undefined' && image instanceof HTMLImageElement ) ||
  12556. ( typeof HTMLCanvasElement !== 'undefined' && image instanceof HTMLCanvasElement ) ||
  12557. ( typeof ImageBitmap !== 'undefined' && image instanceof ImageBitmap ) ) {
  12558. var floor = needsPowerOfTwo ? _Math.floorPowerOfTwo : Math.floor;
  12559. var width = floor( scale * image.width );
  12560. var height = floor( scale * image.height );
  12561. if ( _canvas === undefined ) _canvas = createCanvas( width, height );
  12562. // cube textures can't reuse the same canvas
  12563. var canvas = needsNewCanvas ? createCanvas( width, height ) : _canvas;
  12564. canvas.width = width;
  12565. canvas.height = height;
  12566. var context = canvas.getContext( '2d' );
  12567. context.drawImage( image, 0, 0, width, height );
  12568. console.warn( 'THREE.WebGLRenderer: Texture has been resized from (' + image.width + 'x' + image.height + ') to (' + width + 'x' + height + ').' );
  12569. return canvas;
  12570. } else {
  12571. if ( 'data' in image ) {
  12572. console.warn( 'THREE.WebGLRenderer: Image in DataTexture is too big (' + image.width + 'x' + image.height + ').' );
  12573. }
  12574. return image;
  12575. }
  12576. }
  12577. return image;
  12578. }
  12579. function isPowerOfTwo( image ) {
  12580. return _Math.isPowerOfTwo( image.width ) && _Math.isPowerOfTwo( image.height );
  12581. }
  12582. function textureNeedsPowerOfTwo( texture ) {
  12583. if ( capabilities.isWebGL2 ) return false;
  12584. return ( texture.wrapS !== ClampToEdgeWrapping || texture.wrapT !== ClampToEdgeWrapping ) ||
  12585. ( texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter );
  12586. }
  12587. function textureNeedsGenerateMipmaps( texture, supportsMips ) {
  12588. return texture.generateMipmaps && supportsMips &&
  12589. texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter;
  12590. }
  12591. function generateMipmap( target, texture, width, height ) {
  12592. _gl.generateMipmap( target );
  12593. var textureProperties = properties.get( texture );
  12594. // Note: Math.log( x ) * Math.LOG2E used instead of Math.log2( x ) which is not supported by IE11
  12595. textureProperties.__maxMipLevel = Math.log( Math.max( width, height ) ) * Math.LOG2E;
  12596. }
  12597. function getInternalFormat( glFormat, glType ) {
  12598. if ( ! capabilities.isWebGL2 ) return glFormat;
  12599. var internalFormat = glFormat;
  12600. if ( glFormat === 6403 ) {
  12601. if ( glType === 5126 ) internalFormat = 33326;
  12602. if ( glType === 5131 ) internalFormat = 33325;
  12603. if ( glType === 5121 ) internalFormat = 33321;
  12604. }
  12605. if ( glFormat === 6407 ) {
  12606. if ( glType === 5126 ) internalFormat = 34837;
  12607. if ( glType === 5131 ) internalFormat = 34843;
  12608. if ( glType === 5121 ) internalFormat = 32849;
  12609. }
  12610. if ( glFormat === 6408 ) {
  12611. if ( glType === 5126 ) internalFormat = 34836;
  12612. if ( glType === 5131 ) internalFormat = 34842;
  12613. if ( glType === 5121 ) internalFormat = 32856;
  12614. }
  12615. if ( internalFormat === 33325 || internalFormat === 33326 ||
  12616. internalFormat === 34842 || internalFormat === 34836 ) {
  12617. extensions.get( 'EXT_color_buffer_float' );
  12618. } else if ( internalFormat === 34843 || internalFormat === 34837 ) {
  12619. console.warn( 'THREE.WebGLRenderer: Floating point textures with RGB format not supported. Please use RGBA instead.' );
  12620. }
  12621. return internalFormat;
  12622. }
  12623. // Fallback filters for non-power-of-2 textures
  12624. function filterFallback( f ) {
  12625. if ( f === NearestFilter || f === NearestMipmapNearestFilter || f === NearestMipmapLinearFilter ) {
  12626. return 9728;
  12627. }
  12628. return 9729;
  12629. }
  12630. //
  12631. function onTextureDispose( event ) {
  12632. var texture = event.target;
  12633. texture.removeEventListener( 'dispose', onTextureDispose );
  12634. deallocateTexture( texture );
  12635. if ( texture.isVideoTexture ) {
  12636. delete _videoTextures[ texture.id ];
  12637. }
  12638. info.memory.textures --;
  12639. }
  12640. function onRenderTargetDispose( event ) {
  12641. var renderTarget = event.target;
  12642. renderTarget.removeEventListener( 'dispose', onRenderTargetDispose );
  12643. deallocateRenderTarget( renderTarget );
  12644. info.memory.textures --;
  12645. }
  12646. //
  12647. function deallocateTexture( texture ) {
  12648. var textureProperties = properties.get( texture );
  12649. if ( textureProperties.__webglInit === undefined ) return;
  12650. _gl.deleteTexture( textureProperties.__webglTexture );
  12651. properties.remove( texture );
  12652. }
  12653. function deallocateRenderTarget( renderTarget ) {
  12654. var renderTargetProperties = properties.get( renderTarget );
  12655. var textureProperties = properties.get( renderTarget.texture );
  12656. if ( ! renderTarget ) return;
  12657. if ( textureProperties.__webglTexture !== undefined ) {
  12658. _gl.deleteTexture( textureProperties.__webglTexture );
  12659. }
  12660. if ( renderTarget.depthTexture ) {
  12661. renderTarget.depthTexture.dispose();
  12662. }
  12663. if ( renderTarget.isWebGLRenderTargetCube ) {
  12664. for ( var i = 0; i < 6; i ++ ) {
  12665. _gl.deleteFramebuffer( renderTargetProperties.__webglFramebuffer[ i ] );
  12666. if ( renderTargetProperties.__webglDepthbuffer ) _gl.deleteRenderbuffer( renderTargetProperties.__webglDepthbuffer[ i ] );
  12667. }
  12668. } else {
  12669. _gl.deleteFramebuffer( renderTargetProperties.__webglFramebuffer );
  12670. if ( renderTargetProperties.__webglDepthbuffer ) _gl.deleteRenderbuffer( renderTargetProperties.__webglDepthbuffer );
  12671. }
  12672. properties.remove( renderTarget.texture );
  12673. properties.remove( renderTarget );
  12674. }
  12675. //
  12676. var textureUnits = 0;
  12677. function resetTextureUnits() {
  12678. textureUnits = 0;
  12679. }
  12680. function allocateTextureUnit() {
  12681. var textureUnit = textureUnits;
  12682. if ( textureUnit >= capabilities.maxTextures ) {
  12683. console.warn( 'THREE.WebGLTextures: Trying to use ' + textureUnit + ' texture units while this GPU supports only ' + capabilities.maxTextures );
  12684. }
  12685. textureUnits += 1;
  12686. return textureUnit;
  12687. }
  12688. //
  12689. function setTexture2D( texture, slot ) {
  12690. var textureProperties = properties.get( texture );
  12691. if ( texture.isVideoTexture ) updateVideoTexture( texture );
  12692. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  12693. var image = texture.image;
  12694. if ( image === undefined ) {
  12695. console.warn( 'THREE.WebGLRenderer: Texture marked for update but image is undefined' );
  12696. } else if ( image.complete === false ) {
  12697. console.warn( 'THREE.WebGLRenderer: Texture marked for update but image is incomplete' );
  12698. } else {
  12699. uploadTexture( textureProperties, texture, slot );
  12700. return;
  12701. }
  12702. }
  12703. state.activeTexture( 33984 + slot );
  12704. state.bindTexture( 3553, textureProperties.__webglTexture );
  12705. }
  12706. function setTexture2DArray( texture, slot ) {
  12707. var textureProperties = properties.get( texture );
  12708. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  12709. uploadTexture( textureProperties, texture, slot );
  12710. return;
  12711. }
  12712. state.activeTexture( 33984 + slot );
  12713. state.bindTexture( 35866, textureProperties.__webglTexture );
  12714. }
  12715. function setTexture3D( texture, slot ) {
  12716. var textureProperties = properties.get( texture );
  12717. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  12718. uploadTexture( textureProperties, texture, slot );
  12719. return;
  12720. }
  12721. state.activeTexture( 33984 + slot );
  12722. state.bindTexture( 32879, textureProperties.__webglTexture );
  12723. }
  12724. function setTextureCube( texture, slot ) {
  12725. var textureProperties = properties.get( texture );
  12726. if ( texture.image.length === 6 ) {
  12727. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  12728. initTexture( textureProperties, texture );
  12729. state.activeTexture( 33984 + slot );
  12730. state.bindTexture( 34067, textureProperties.__webglTexture );
  12731. _gl.pixelStorei( 37440, texture.flipY );
  12732. var isCompressed = ( texture && texture.isCompressedTexture );
  12733. var isDataTexture = ( texture.image[ 0 ] && texture.image[ 0 ].isDataTexture );
  12734. var cubeImage = [];
  12735. for ( var i = 0; i < 6; i ++ ) {
  12736. if ( ! isCompressed && ! isDataTexture ) {
  12737. cubeImage[ i ] = resizeImage( texture.image[ i ], false, true, capabilities.maxCubemapSize );
  12738. } else {
  12739. cubeImage[ i ] = isDataTexture ? texture.image[ i ].image : texture.image[ i ];
  12740. }
  12741. }
  12742. var image = cubeImage[ 0 ],
  12743. supportsMips = isPowerOfTwo( image ) || capabilities.isWebGL2,
  12744. glFormat = utils.convert( texture.format ),
  12745. glType = utils.convert( texture.type ),
  12746. glInternalFormat = getInternalFormat( glFormat, glType );
  12747. setTextureParameters( 34067, texture, supportsMips );
  12748. for ( var i = 0; i < 6; i ++ ) {
  12749. if ( ! isCompressed ) {
  12750. if ( isDataTexture ) {
  12751. state.texImage2D( 34069 + i, 0, glInternalFormat, cubeImage[ i ].width, cubeImage[ i ].height, 0, glFormat, glType, cubeImage[ i ].data );
  12752. } else {
  12753. state.texImage2D( 34069 + i, 0, glInternalFormat, glFormat, glType, cubeImage[ i ] );
  12754. }
  12755. } else {
  12756. var mipmap, mipmaps = cubeImage[ i ].mipmaps;
  12757. for ( var j = 0, jl = mipmaps.length; j < jl; j ++ ) {
  12758. mipmap = mipmaps[ j ];
  12759. if ( texture.format !== RGBAFormat && texture.format !== RGBFormat ) {
  12760. if ( state.getCompressedTextureFormats().indexOf( glFormat ) > - 1 ) {
  12761. state.compressedTexImage2D( 34069 + i, j, glInternalFormat, mipmap.width, mipmap.height, 0, mipmap.data );
  12762. } else {
  12763. console.warn( 'THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .setTextureCube()' );
  12764. }
  12765. } else {
  12766. state.texImage2D( 34069 + i, j, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  12767. }
  12768. }
  12769. }
  12770. }
  12771. if ( ! isCompressed ) {
  12772. textureProperties.__maxMipLevel = 0;
  12773. } else {
  12774. textureProperties.__maxMipLevel = mipmaps.length - 1;
  12775. }
  12776. if ( textureNeedsGenerateMipmaps( texture, supportsMips ) ) {
  12777. // We assume images for cube map have the same size.
  12778. generateMipmap( 34067, texture, image.width, image.height );
  12779. }
  12780. textureProperties.__version = texture.version;
  12781. if ( texture.onUpdate ) texture.onUpdate( texture );
  12782. } else {
  12783. state.activeTexture( 33984 + slot );
  12784. state.bindTexture( 34067, textureProperties.__webglTexture );
  12785. }
  12786. }
  12787. }
  12788. function setTextureCubeDynamic( texture, slot ) {
  12789. state.activeTexture( 33984 + slot );
  12790. state.bindTexture( 34067, properties.get( texture ).__webglTexture );
  12791. }
  12792. function setTextureParameters( textureType, texture, supportsMips ) {
  12793. var extension;
  12794. if ( supportsMips ) {
  12795. _gl.texParameteri( textureType, 10242, utils.convert( texture.wrapS ) );
  12796. _gl.texParameteri( textureType, 10243, utils.convert( texture.wrapT ) );
  12797. if ( textureType === 32879 || textureType === 35866 ) {
  12798. _gl.texParameteri( textureType, 32882, utils.convert( texture.wrapR ) );
  12799. }
  12800. _gl.texParameteri( textureType, 10240, utils.convert( texture.magFilter ) );
  12801. _gl.texParameteri( textureType, 10241, utils.convert( texture.minFilter ) );
  12802. } else {
  12803. _gl.texParameteri( textureType, 10242, 33071 );
  12804. _gl.texParameteri( textureType, 10243, 33071 );
  12805. if ( textureType === 32879 || textureType === 35866 ) {
  12806. _gl.texParameteri( textureType, 32882, 33071 );
  12807. }
  12808. if ( texture.wrapS !== ClampToEdgeWrapping || texture.wrapT !== ClampToEdgeWrapping ) {
  12809. console.warn( 'THREE.WebGLRenderer: Texture is not power of two. Texture.wrapS and Texture.wrapT should be set to THREE.ClampToEdgeWrapping.' );
  12810. }
  12811. _gl.texParameteri( textureType, 10240, filterFallback( texture.magFilter ) );
  12812. _gl.texParameteri( textureType, 10241, filterFallback( texture.minFilter ) );
  12813. if ( texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter ) {
  12814. console.warn( 'THREE.WebGLRenderer: Texture is not power of two. Texture.minFilter should be set to THREE.NearestFilter or THREE.LinearFilter.' );
  12815. }
  12816. }
  12817. extension = extensions.get( 'EXT_texture_filter_anisotropic' );
  12818. if ( extension ) {
  12819. if ( texture.type === FloatType && extensions.get( 'OES_texture_float_linear' ) === null ) return;
  12820. if ( texture.type === HalfFloatType && ( capabilities.isWebGL2 || extensions.get( 'OES_texture_half_float_linear' ) ) === null ) return;
  12821. if ( texture.anisotropy > 1 || properties.get( texture ).__currentAnisotropy ) {
  12822. _gl.texParameterf( textureType, extension.TEXTURE_MAX_ANISOTROPY_EXT, Math.min( texture.anisotropy, capabilities.getMaxAnisotropy() ) );
  12823. properties.get( texture ).__currentAnisotropy = texture.anisotropy;
  12824. }
  12825. }
  12826. }
  12827. function initTexture( textureProperties, texture ) {
  12828. if ( textureProperties.__webglInit === undefined ) {
  12829. textureProperties.__webglInit = true;
  12830. texture.addEventListener( 'dispose', onTextureDispose );
  12831. textureProperties.__webglTexture = _gl.createTexture();
  12832. info.memory.textures ++;
  12833. }
  12834. }
  12835. function uploadTexture( textureProperties, texture, slot ) {
  12836. var textureType = 3553;
  12837. if ( texture.isDataTexture2DArray ) textureType = 35866;
  12838. if ( texture.isDataTexture3D ) textureType = 32879;
  12839. initTexture( textureProperties, texture );
  12840. state.activeTexture( 33984 + slot );
  12841. state.bindTexture( textureType, textureProperties.__webglTexture );
  12842. _gl.pixelStorei( 37440, texture.flipY );
  12843. _gl.pixelStorei( 37441, texture.premultiplyAlpha );
  12844. _gl.pixelStorei( 3317, texture.unpackAlignment );
  12845. var needsPowerOfTwo = textureNeedsPowerOfTwo( texture ) && isPowerOfTwo( texture.image ) === false;
  12846. var image = resizeImage( texture.image, needsPowerOfTwo, false, capabilities.maxTextureSize );
  12847. var supportsMips = isPowerOfTwo( image ) || capabilities.isWebGL2,
  12848. glFormat = utils.convert( texture.format ),
  12849. glType = utils.convert( texture.type ),
  12850. glInternalFormat = getInternalFormat( glFormat, glType );
  12851. setTextureParameters( textureType, texture, supportsMips );
  12852. var mipmap, mipmaps = texture.mipmaps;
  12853. if ( texture.isDepthTexture ) {
  12854. // populate depth texture with dummy data
  12855. glInternalFormat = 6402;
  12856. if ( texture.type === FloatType ) {
  12857. if ( ! capabilities.isWebGL2 ) throw new Error( 'Float Depth Texture only supported in WebGL2.0' );
  12858. glInternalFormat = 36012;
  12859. } else if ( capabilities.isWebGL2 ) {
  12860. // WebGL 2.0 requires signed internalformat for glTexImage2D
  12861. glInternalFormat = 33189;
  12862. }
  12863. if ( texture.format === DepthFormat && glInternalFormat === 6402 ) {
  12864. // The error INVALID_OPERATION is generated by texImage2D if format and internalformat are
  12865. // DEPTH_COMPONENT and type is not UNSIGNED_SHORT or UNSIGNED_INT
  12866. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  12867. if ( texture.type !== UnsignedShortType && texture.type !== UnsignedIntType ) {
  12868. console.warn( 'THREE.WebGLRenderer: Use UnsignedShortType or UnsignedIntType for DepthFormat DepthTexture.' );
  12869. texture.type = UnsignedShortType;
  12870. glType = utils.convert( texture.type );
  12871. }
  12872. }
  12873. // Depth stencil textures need the DEPTH_STENCIL internal format
  12874. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  12875. if ( texture.format === DepthStencilFormat ) {
  12876. glInternalFormat = 34041;
  12877. // The error INVALID_OPERATION is generated by texImage2D if format and internalformat are
  12878. // DEPTH_STENCIL and type is not UNSIGNED_INT_24_8_WEBGL.
  12879. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  12880. if ( texture.type !== UnsignedInt248Type ) {
  12881. console.warn( 'THREE.WebGLRenderer: Use UnsignedInt248Type for DepthStencilFormat DepthTexture.' );
  12882. texture.type = UnsignedInt248Type;
  12883. glType = utils.convert( texture.type );
  12884. }
  12885. }
  12886. state.texImage2D( 3553, 0, glInternalFormat, image.width, image.height, 0, glFormat, glType, null );
  12887. } else if ( texture.isDataTexture ) {
  12888. // use manually created mipmaps if available
  12889. // if there are no manual mipmaps
  12890. // set 0 level mipmap and then use GL to generate other mipmap levels
  12891. if ( mipmaps.length > 0 && supportsMips ) {
  12892. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  12893. mipmap = mipmaps[ i ];
  12894. state.texImage2D( 3553, i, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  12895. }
  12896. texture.generateMipmaps = false;
  12897. textureProperties.__maxMipLevel = mipmaps.length - 1;
  12898. } else {
  12899. state.texImage2D( 3553, 0, glInternalFormat, image.width, image.height, 0, glFormat, glType, image.data );
  12900. textureProperties.__maxMipLevel = 0;
  12901. }
  12902. } else if ( texture.isCompressedTexture ) {
  12903. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  12904. mipmap = mipmaps[ i ];
  12905. if ( texture.format !== RGBAFormat && texture.format !== RGBFormat ) {
  12906. if ( state.getCompressedTextureFormats().indexOf( glFormat ) > - 1 ) {
  12907. state.compressedTexImage2D( 3553, i, glInternalFormat, mipmap.width, mipmap.height, 0, mipmap.data );
  12908. } else {
  12909. console.warn( 'THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()' );
  12910. }
  12911. } else {
  12912. state.texImage2D( 3553, i, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  12913. }
  12914. }
  12915. textureProperties.__maxMipLevel = mipmaps.length - 1;
  12916. } else if ( texture.isDataTexture2DArray ) {
  12917. state.texImage3D( 35866, 0, glInternalFormat, image.width, image.height, image.depth, 0, glFormat, glType, image.data );
  12918. textureProperties.__maxMipLevel = 0;
  12919. } else if ( texture.isDataTexture3D ) {
  12920. state.texImage3D( 32879, 0, glInternalFormat, image.width, image.height, image.depth, 0, glFormat, glType, image.data );
  12921. textureProperties.__maxMipLevel = 0;
  12922. } else {
  12923. // regular Texture (image, video, canvas)
  12924. // use manually created mipmaps if available
  12925. // if there are no manual mipmaps
  12926. // set 0 level mipmap and then use GL to generate other mipmap levels
  12927. if ( mipmaps.length > 0 && supportsMips ) {
  12928. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  12929. mipmap = mipmaps[ i ];
  12930. state.texImage2D( 3553, i, glInternalFormat, glFormat, glType, mipmap );
  12931. }
  12932. texture.generateMipmaps = false;
  12933. textureProperties.__maxMipLevel = mipmaps.length - 1;
  12934. } else {
  12935. state.texImage2D( 3553, 0, glInternalFormat, glFormat, glType, image );
  12936. textureProperties.__maxMipLevel = 0;
  12937. }
  12938. }
  12939. if ( textureNeedsGenerateMipmaps( texture, supportsMips ) ) {
  12940. generateMipmap( 3553, texture, image.width, image.height );
  12941. }
  12942. textureProperties.__version = texture.version;
  12943. if ( texture.onUpdate ) texture.onUpdate( texture );
  12944. }
  12945. // Render targets
  12946. // Setup storage for target texture and bind it to correct framebuffer
  12947. function setupFrameBufferTexture( framebuffer, renderTarget, attachment, textureTarget ) {
  12948. var glFormat = utils.convert( renderTarget.texture.format );
  12949. var glType = utils.convert( renderTarget.texture.type );
  12950. var glInternalFormat = getInternalFormat( glFormat, glType );
  12951. state.texImage2D( textureTarget, 0, glInternalFormat, renderTarget.width, renderTarget.height, 0, glFormat, glType, null );
  12952. _gl.bindFramebuffer( 36160, framebuffer );
  12953. _gl.framebufferTexture2D( 36160, attachment, textureTarget, properties.get( renderTarget.texture ).__webglTexture, 0 );
  12954. _gl.bindFramebuffer( 36160, null );
  12955. }
  12956. // Setup storage for internal depth/stencil buffers and bind to correct framebuffer
  12957. function setupRenderBufferStorage( renderbuffer, renderTarget, isMultisample ) {
  12958. _gl.bindRenderbuffer( 36161, renderbuffer );
  12959. if ( renderTarget.depthBuffer && ! renderTarget.stencilBuffer ) {
  12960. if ( isMultisample ) {
  12961. var samples = getRenderTargetSamples( renderTarget );
  12962. _gl.renderbufferStorageMultisample( 36161, samples, 33189, renderTarget.width, renderTarget.height );
  12963. } else {
  12964. _gl.renderbufferStorage( 36161, 33189, renderTarget.width, renderTarget.height );
  12965. }
  12966. _gl.framebufferRenderbuffer( 36160, 36096, 36161, renderbuffer );
  12967. } else if ( renderTarget.depthBuffer && renderTarget.stencilBuffer ) {
  12968. if ( isMultisample ) {
  12969. var samples = getRenderTargetSamples( renderTarget );
  12970. _gl.renderbufferStorageMultisample( 36161, samples, 35056, renderTarget.width, renderTarget.height );
  12971. } else {
  12972. _gl.renderbufferStorage( 36161, 34041, renderTarget.width, renderTarget.height );
  12973. }
  12974. _gl.framebufferRenderbuffer( 36160, 33306, 36161, renderbuffer );
  12975. } else {
  12976. var glFormat = utils.convert( renderTarget.texture.format );
  12977. var glType = utils.convert( renderTarget.texture.type );
  12978. var glInternalFormat = getInternalFormat( glFormat, glType );
  12979. if ( isMultisample ) {
  12980. var samples = getRenderTargetSamples( renderTarget );
  12981. _gl.renderbufferStorageMultisample( 36161, samples, glInternalFormat, renderTarget.width, renderTarget.height );
  12982. } else {
  12983. _gl.renderbufferStorage( 36161, glInternalFormat, renderTarget.width, renderTarget.height );
  12984. }
  12985. }
  12986. _gl.bindRenderbuffer( 36161, null );
  12987. }
  12988. // Setup resources for a Depth Texture for a FBO (needs an extension)
  12989. function setupDepthTexture( framebuffer, renderTarget ) {
  12990. var isCube = ( renderTarget && renderTarget.isWebGLRenderTargetCube );
  12991. if ( isCube ) throw new Error( 'Depth Texture with cube render targets is not supported' );
  12992. _gl.bindFramebuffer( 36160, framebuffer );
  12993. if ( ! ( renderTarget.depthTexture && renderTarget.depthTexture.isDepthTexture ) ) {
  12994. throw new Error( 'renderTarget.depthTexture must be an instance of THREE.DepthTexture' );
  12995. }
  12996. // upload an empty depth texture with framebuffer size
  12997. if ( ! properties.get( renderTarget.depthTexture ).__webglTexture ||
  12998. renderTarget.depthTexture.image.width !== renderTarget.width ||
  12999. renderTarget.depthTexture.image.height !== renderTarget.height ) {
  13000. renderTarget.depthTexture.image.width = renderTarget.width;
  13001. renderTarget.depthTexture.image.height = renderTarget.height;
  13002. renderTarget.depthTexture.needsUpdate = true;
  13003. }
  13004. setTexture2D( renderTarget.depthTexture, 0 );
  13005. var webglDepthTexture = properties.get( renderTarget.depthTexture ).__webglTexture;
  13006. if ( renderTarget.depthTexture.format === DepthFormat ) {
  13007. _gl.framebufferTexture2D( 36160, 36096, 3553, webglDepthTexture, 0 );
  13008. } else if ( renderTarget.depthTexture.format === DepthStencilFormat ) {
  13009. _gl.framebufferTexture2D( 36160, 33306, 3553, webglDepthTexture, 0 );
  13010. } else {
  13011. throw new Error( 'Unknown depthTexture format' );
  13012. }
  13013. }
  13014. // Setup GL resources for a non-texture depth buffer
  13015. function setupDepthRenderbuffer( renderTarget ) {
  13016. var renderTargetProperties = properties.get( renderTarget );
  13017. var isCube = ( renderTarget.isWebGLRenderTargetCube === true );
  13018. if ( renderTarget.depthTexture ) {
  13019. if ( isCube ) throw new Error( 'target.depthTexture not supported in Cube render targets' );
  13020. setupDepthTexture( renderTargetProperties.__webglFramebuffer, renderTarget );
  13021. } else {
  13022. if ( isCube ) {
  13023. renderTargetProperties.__webglDepthbuffer = [];
  13024. for ( var i = 0; i < 6; i ++ ) {
  13025. _gl.bindFramebuffer( 36160, renderTargetProperties.__webglFramebuffer[ i ] );
  13026. renderTargetProperties.__webglDepthbuffer[ i ] = _gl.createRenderbuffer();
  13027. setupRenderBufferStorage( renderTargetProperties.__webglDepthbuffer[ i ], renderTarget );
  13028. }
  13029. } else {
  13030. _gl.bindFramebuffer( 36160, renderTargetProperties.__webglFramebuffer );
  13031. renderTargetProperties.__webglDepthbuffer = _gl.createRenderbuffer();
  13032. setupRenderBufferStorage( renderTargetProperties.__webglDepthbuffer, renderTarget );
  13033. }
  13034. }
  13035. _gl.bindFramebuffer( 36160, null );
  13036. }
  13037. // Set up GL resources for the render target
  13038. function setupRenderTarget( renderTarget ) {
  13039. var renderTargetProperties = properties.get( renderTarget );
  13040. var textureProperties = properties.get( renderTarget.texture );
  13041. renderTarget.addEventListener( 'dispose', onRenderTargetDispose );
  13042. textureProperties.__webglTexture = _gl.createTexture();
  13043. info.memory.textures ++;
  13044. var isCube = ( renderTarget.isWebGLRenderTargetCube === true );
  13045. var isMultisample = ( renderTarget.isWebGLMultisampleRenderTarget === true );
  13046. var supportsMips = isPowerOfTwo( renderTarget ) || capabilities.isWebGL2;
  13047. // Setup framebuffer
  13048. if ( isCube ) {
  13049. renderTargetProperties.__webglFramebuffer = [];
  13050. for ( var i = 0; i < 6; i ++ ) {
  13051. renderTargetProperties.__webglFramebuffer[ i ] = _gl.createFramebuffer();
  13052. }
  13053. } else {
  13054. renderTargetProperties.__webglFramebuffer = _gl.createFramebuffer();
  13055. if ( isMultisample ) {
  13056. if ( capabilities.isWebGL2 ) {
  13057. renderTargetProperties.__webglMultisampledFramebuffer = _gl.createFramebuffer();
  13058. renderTargetProperties.__webglColorRenderbuffer = _gl.createRenderbuffer();
  13059. _gl.bindRenderbuffer( 36161, renderTargetProperties.__webglColorRenderbuffer );
  13060. var glFormat = utils.convert( renderTarget.texture.format );
  13061. var glType = utils.convert( renderTarget.texture.type );
  13062. var glInternalFormat = getInternalFormat( glFormat, glType );
  13063. var samples = getRenderTargetSamples( renderTarget );
  13064. _gl.renderbufferStorageMultisample( 36161, samples, glInternalFormat, renderTarget.width, renderTarget.height );
  13065. _gl.bindFramebuffer( 36160, renderTargetProperties.__webglMultisampledFramebuffer );
  13066. _gl.framebufferRenderbuffer( 36160, 36064, 36161, renderTargetProperties.__webglColorRenderbuffer );
  13067. _gl.bindRenderbuffer( 36161, null );
  13068. if ( renderTarget.depthBuffer ) {
  13069. renderTargetProperties.__webglDepthRenderbuffer = _gl.createRenderbuffer();
  13070. setupRenderBufferStorage( renderTargetProperties.__webglDepthRenderbuffer, renderTarget, true );
  13071. }
  13072. _gl.bindFramebuffer( 36160, null );
  13073. } else {
  13074. console.warn( 'THREE.WebGLRenderer: WebGLMultisampleRenderTarget can only be used with WebGL2.' );
  13075. }
  13076. }
  13077. }
  13078. // Setup color buffer
  13079. if ( isCube ) {
  13080. state.bindTexture( 34067, textureProperties.__webglTexture );
  13081. setTextureParameters( 34067, renderTarget.texture, supportsMips );
  13082. for ( var i = 0; i < 6; i ++ ) {
  13083. setupFrameBufferTexture( renderTargetProperties.__webglFramebuffer[ i ], renderTarget, 36064, 34069 + i );
  13084. }
  13085. if ( textureNeedsGenerateMipmaps( renderTarget.texture, supportsMips ) ) {
  13086. generateMipmap( 34067, renderTarget.texture, renderTarget.width, renderTarget.height );
  13087. }
  13088. state.bindTexture( 34067, null );
  13089. } else {
  13090. state.bindTexture( 3553, textureProperties.__webglTexture );
  13091. setTextureParameters( 3553, renderTarget.texture, supportsMips );
  13092. setupFrameBufferTexture( renderTargetProperties.__webglFramebuffer, renderTarget, 36064, 3553 );
  13093. if ( textureNeedsGenerateMipmaps( renderTarget.texture, supportsMips ) ) {
  13094. generateMipmap( 3553, renderTarget.texture, renderTarget.width, renderTarget.height );
  13095. }
  13096. state.bindTexture( 3553, null );
  13097. }
  13098. // Setup depth and stencil buffers
  13099. if ( renderTarget.depthBuffer ) {
  13100. setupDepthRenderbuffer( renderTarget );
  13101. }
  13102. }
  13103. function updateRenderTargetMipmap( renderTarget ) {
  13104. var texture = renderTarget.texture;
  13105. var supportsMips = isPowerOfTwo( renderTarget ) || capabilities.isWebGL2;
  13106. if ( textureNeedsGenerateMipmaps( texture, supportsMips ) ) {
  13107. var target = renderTarget.isWebGLRenderTargetCube ? 34067 : 3553;
  13108. var webglTexture = properties.get( texture ).__webglTexture;
  13109. state.bindTexture( target, webglTexture );
  13110. generateMipmap( target, texture, renderTarget.width, renderTarget.height );
  13111. state.bindTexture( target, null );
  13112. }
  13113. }
  13114. function updateMultisampleRenderTarget( renderTarget ) {
  13115. if ( renderTarget.isWebGLMultisampleRenderTarget ) {
  13116. if ( capabilities.isWebGL2 ) {
  13117. var renderTargetProperties = properties.get( renderTarget );
  13118. _gl.bindFramebuffer( 36008, renderTargetProperties.__webglMultisampledFramebuffer );
  13119. _gl.bindFramebuffer( 36009, renderTargetProperties.__webglFramebuffer );
  13120. var width = renderTarget.width;
  13121. var height = renderTarget.height;
  13122. var mask = 16384;
  13123. if ( renderTarget.depthBuffer ) mask |= 256;
  13124. if ( renderTarget.stencilBuffer ) mask |= 1024;
  13125. _gl.blitFramebuffer( 0, 0, width, height, 0, 0, width, height, mask, 9728 );
  13126. } else {
  13127. console.warn( 'THREE.WebGLRenderer: WebGLMultisampleRenderTarget can only be used with WebGL2.' );
  13128. }
  13129. }
  13130. }
  13131. function getRenderTargetSamples( renderTarget ) {
  13132. return ( capabilities.isWebGL2 && renderTarget.isWebGLMultisampleRenderTarget ) ?
  13133. Math.min( capabilities.maxSamples, renderTarget.samples ) : 0;
  13134. }
  13135. function updateVideoTexture( texture ) {
  13136. var id = texture.id;
  13137. var frame = info.render.frame;
  13138. // Check the last frame we updated the VideoTexture
  13139. if ( _videoTextures[ id ] !== frame ) {
  13140. _videoTextures[ id ] = frame;
  13141. texture.update();
  13142. }
  13143. }
  13144. // backwards compatibility
  13145. var warnedTexture2D = false;
  13146. var warnedTextureCube = false;
  13147. function safeSetTexture2D( texture, slot ) {
  13148. if ( texture && texture.isWebGLRenderTarget ) {
  13149. if ( warnedTexture2D === false ) {
  13150. console.warn( "THREE.WebGLTextures.safeSetTexture2D: don't use render targets as textures. Use their .texture property instead." );
  13151. warnedTexture2D = true;
  13152. }
  13153. texture = texture.texture;
  13154. }
  13155. setTexture2D( texture, slot );
  13156. }
  13157. function safeSetTextureCube( texture, slot ) {
  13158. if ( texture && texture.isWebGLRenderTargetCube ) {
  13159. if ( warnedTextureCube === false ) {
  13160. console.warn( "THREE.WebGLTextures.safeSetTextureCube: don't use cube render targets as textures. Use their .texture property instead." );
  13161. warnedTextureCube = true;
  13162. }
  13163. texture = texture.texture;
  13164. }
  13165. // currently relying on the fact that WebGLRenderTargetCube.texture is a Texture and NOT a CubeTexture
  13166. // TODO: unify these code paths
  13167. if ( ( texture && texture.isCubeTexture ) ||
  13168. ( Array.isArray( texture.image ) && texture.image.length === 6 ) ) {
  13169. // CompressedTexture can have Array in image :/
  13170. // this function alone should take care of cube textures
  13171. setTextureCube( texture, slot );
  13172. } else {
  13173. // assumed: texture property of THREE.WebGLRenderTargetCube
  13174. setTextureCubeDynamic( texture, slot );
  13175. }
  13176. }
  13177. //
  13178. this.allocateTextureUnit = allocateTextureUnit;
  13179. this.resetTextureUnits = resetTextureUnits;
  13180. this.setTexture2D = setTexture2D;
  13181. this.setTexture2DArray = setTexture2DArray;
  13182. this.setTexture3D = setTexture3D;
  13183. this.setTextureCube = setTextureCube;
  13184. this.setTextureCubeDynamic = setTextureCubeDynamic;
  13185. this.setupRenderTarget = setupRenderTarget;
  13186. this.updateRenderTargetMipmap = updateRenderTargetMipmap;
  13187. this.updateMultisampleRenderTarget = updateMultisampleRenderTarget;
  13188. this.safeSetTexture2D = safeSetTexture2D;
  13189. this.safeSetTextureCube = safeSetTextureCube;
  13190. }
  13191. /**
  13192. * @author thespite / http://www.twitter.com/thespite
  13193. */
  13194. function WebGLUtils( gl, extensions, capabilities ) {
  13195. function convert( p ) {
  13196. var extension;
  13197. if ( p === RepeatWrapping ) return 10497;
  13198. if ( p === ClampToEdgeWrapping ) return 33071;
  13199. if ( p === MirroredRepeatWrapping ) return 33648;
  13200. if ( p === NearestFilter ) return 9728;
  13201. if ( p === NearestMipmapNearestFilter ) return 9984;
  13202. if ( p === NearestMipmapLinearFilter ) return 9986;
  13203. if ( p === LinearFilter ) return 9729;
  13204. if ( p === LinearMipmapNearestFilter ) return 9985;
  13205. if ( p === LinearMipmapLinearFilter ) return 9987;
  13206. if ( p === UnsignedByteType ) return 5121;
  13207. if ( p === UnsignedShort4444Type ) return 32819;
  13208. if ( p === UnsignedShort5551Type ) return 32820;
  13209. if ( p === UnsignedShort565Type ) return 33635;
  13210. if ( p === ByteType ) return 5120;
  13211. if ( p === ShortType ) return 5122;
  13212. if ( p === UnsignedShortType ) return 5123;
  13213. if ( p === IntType ) return 5124;
  13214. if ( p === UnsignedIntType ) return 5125;
  13215. if ( p === FloatType ) return 5126;
  13216. if ( p === HalfFloatType ) {
  13217. if ( capabilities.isWebGL2 ) return 5131;
  13218. extension = extensions.get( 'OES_texture_half_float' );
  13219. if ( extension !== null ) return extension.HALF_FLOAT_OES;
  13220. }
  13221. if ( p === AlphaFormat ) return 6406;
  13222. if ( p === RGBFormat ) return 6407;
  13223. if ( p === RGBAFormat ) return 6408;
  13224. if ( p === LuminanceFormat ) return 6409;
  13225. if ( p === LuminanceAlphaFormat ) return 6410;
  13226. if ( p === DepthFormat ) return 6402;
  13227. if ( p === DepthStencilFormat ) return 34041;
  13228. if ( p === RedFormat ) return 6403;
  13229. if ( p === AddEquation ) return 32774;
  13230. if ( p === SubtractEquation ) return 32778;
  13231. if ( p === ReverseSubtractEquation ) return 32779;
  13232. if ( p === ZeroFactor ) return 0;
  13233. if ( p === OneFactor ) return 1;
  13234. if ( p === SrcColorFactor ) return 768;
  13235. if ( p === OneMinusSrcColorFactor ) return 769;
  13236. if ( p === SrcAlphaFactor ) return 770;
  13237. if ( p === OneMinusSrcAlphaFactor ) return 771;
  13238. if ( p === DstAlphaFactor ) return 772;
  13239. if ( p === OneMinusDstAlphaFactor ) return 773;
  13240. if ( p === DstColorFactor ) return 774;
  13241. if ( p === OneMinusDstColorFactor ) return 775;
  13242. if ( p === SrcAlphaSaturateFactor ) return 776;
  13243. if ( p === RGB_S3TC_DXT1_Format || p === RGBA_S3TC_DXT1_Format ||
  13244. p === RGBA_S3TC_DXT3_Format || p === RGBA_S3TC_DXT5_Format ) {
  13245. extension = extensions.get( 'WEBGL_compressed_texture_s3tc' );
  13246. if ( extension !== null ) {
  13247. if ( p === RGB_S3TC_DXT1_Format ) return extension.COMPRESSED_RGB_S3TC_DXT1_EXT;
  13248. if ( p === RGBA_S3TC_DXT1_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT1_EXT;
  13249. if ( p === RGBA_S3TC_DXT3_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT3_EXT;
  13250. if ( p === RGBA_S3TC_DXT5_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT5_EXT;
  13251. }
  13252. }
  13253. if ( p === RGB_PVRTC_4BPPV1_Format || p === RGB_PVRTC_2BPPV1_Format ||
  13254. p === RGBA_PVRTC_4BPPV1_Format || p === RGBA_PVRTC_2BPPV1_Format ) {
  13255. extension = extensions.get( 'WEBGL_compressed_texture_pvrtc' );
  13256. if ( extension !== null ) {
  13257. if ( p === RGB_PVRTC_4BPPV1_Format ) return extension.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;
  13258. if ( p === RGB_PVRTC_2BPPV1_Format ) return extension.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;
  13259. if ( p === RGBA_PVRTC_4BPPV1_Format ) return extension.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;
  13260. if ( p === RGBA_PVRTC_2BPPV1_Format ) return extension.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG;
  13261. }
  13262. }
  13263. if ( p === RGB_ETC1_Format ) {
  13264. extension = extensions.get( 'WEBGL_compressed_texture_etc1' );
  13265. if ( extension !== null ) return extension.COMPRESSED_RGB_ETC1_WEBGL;
  13266. }
  13267. if ( p === RGBA_ASTC_4x4_Format || p === RGBA_ASTC_5x4_Format || p === RGBA_ASTC_5x5_Format ||
  13268. p === RGBA_ASTC_6x5_Format || p === RGBA_ASTC_6x6_Format || p === RGBA_ASTC_8x5_Format ||
  13269. p === RGBA_ASTC_8x6_Format || p === RGBA_ASTC_8x8_Format || p === RGBA_ASTC_10x5_Format ||
  13270. p === RGBA_ASTC_10x6_Format || p === RGBA_ASTC_10x8_Format || p === RGBA_ASTC_10x10_Format ||
  13271. p === RGBA_ASTC_12x10_Format || p === RGBA_ASTC_12x12_Format ) {
  13272. extension = extensions.get( 'WEBGL_compressed_texture_astc' );
  13273. if ( extension !== null ) {
  13274. return p;
  13275. }
  13276. }
  13277. if ( p === MinEquation || p === MaxEquation ) {
  13278. if ( capabilities.isWebGL2 ) {
  13279. if ( p === MinEquation ) return 32775;
  13280. if ( p === MaxEquation ) return 32776;
  13281. }
  13282. extension = extensions.get( 'EXT_blend_minmax' );
  13283. if ( extension !== null ) {
  13284. if ( p === MinEquation ) return extension.MIN_EXT;
  13285. if ( p === MaxEquation ) return extension.MAX_EXT;
  13286. }
  13287. }
  13288. if ( p === UnsignedInt248Type ) {
  13289. if ( capabilities.isWebGL2 ) return 34042;
  13290. extension = extensions.get( 'WEBGL_depth_texture' );
  13291. if ( extension !== null ) return extension.UNSIGNED_INT_24_8_WEBGL;
  13292. }
  13293. return 0;
  13294. }
  13295. return { convert: convert };
  13296. }
  13297. /**
  13298. * @author mrdoob / http://mrdoob.com/
  13299. */
  13300. function Group() {
  13301. Object3D.call( this );
  13302. this.type = 'Group';
  13303. }
  13304. Group.prototype = Object.assign( Object.create( Object3D.prototype ), {
  13305. constructor: Group,
  13306. isGroup: true
  13307. } );
  13308. /**
  13309. * @author mrdoob / http://mrdoob.com/
  13310. */
  13311. function ArrayCamera( array ) {
  13312. PerspectiveCamera.call( this );
  13313. this.cameras = array || [];
  13314. }
  13315. ArrayCamera.prototype = Object.assign( Object.create( PerspectiveCamera.prototype ), {
  13316. constructor: ArrayCamera,
  13317. isArrayCamera: true
  13318. } );
  13319. /**
  13320. * @author jsantell / https://www.jsantell.com/
  13321. * @author mrdoob / http://mrdoob.com/
  13322. */
  13323. var cameraLPos = new Vector3();
  13324. var cameraRPos = new Vector3();
  13325. /**
  13326. * Assumes 2 cameras that are parallel and share an X-axis, and that
  13327. * the cameras' projection and world matrices have already been set.
  13328. * And that near and far planes are identical for both cameras.
  13329. * Visualization of this technique: https://computergraphics.stackexchange.com/a/4765
  13330. */
  13331. function setProjectionFromUnion( camera, cameraL, cameraR ) {
  13332. cameraLPos.setFromMatrixPosition( cameraL.matrixWorld );
  13333. cameraRPos.setFromMatrixPosition( cameraR.matrixWorld );
  13334. var ipd = cameraLPos.distanceTo( cameraRPos );
  13335. var projL = cameraL.projectionMatrix.elements;
  13336. var projR = cameraR.projectionMatrix.elements;
  13337. // VR systems will have identical far and near planes, and
  13338. // most likely identical top and bottom frustum extents.
  13339. // Use the left camera for these values.
  13340. var near = projL[ 14 ] / ( projL[ 10 ] - 1 );
  13341. var far = projL[ 14 ] / ( projL[ 10 ] + 1 );
  13342. var topFov = ( projL[ 9 ] + 1 ) / projL[ 5 ];
  13343. var bottomFov = ( projL[ 9 ] - 1 ) / projL[ 5 ];
  13344. var leftFov = ( projL[ 8 ] - 1 ) / projL[ 0 ];
  13345. var rightFov = ( projR[ 8 ] + 1 ) / projR[ 0 ];
  13346. var left = near * leftFov;
  13347. var right = near * rightFov;
  13348. // Calculate the new camera's position offset from the
  13349. // left camera. xOffset should be roughly half `ipd`.
  13350. var zOffset = ipd / ( - leftFov + rightFov );
  13351. var xOffset = zOffset * - leftFov;
  13352. // TODO: Better way to apply this offset?
  13353. cameraL.matrixWorld.decompose( camera.position, camera.quaternion, camera.scale );
  13354. camera.translateX( xOffset );
  13355. camera.translateZ( zOffset );
  13356. camera.matrixWorld.compose( camera.position, camera.quaternion, camera.scale );
  13357. camera.matrixWorldInverse.getInverse( camera.matrixWorld );
  13358. // Find the union of the frustum values of the cameras and scale
  13359. // the values so that the near plane's position does not change in world space,
  13360. // although must now be relative to the new union camera.
  13361. var near2 = near + zOffset;
  13362. var far2 = far + zOffset;
  13363. var left2 = left - xOffset;
  13364. var right2 = right + ( ipd - xOffset );
  13365. var top2 = topFov * far / far2 * near2;
  13366. var bottom2 = bottomFov * far / far2 * near2;
  13367. camera.projectionMatrix.makePerspective( left2, right2, top2, bottom2, near2, far2 );
  13368. }
  13369. /**
  13370. * @author mrdoob / http://mrdoob.com/
  13371. */
  13372. function WebVRManager( renderer ) {
  13373. var renderWidth, renderHeight;
  13374. var scope = this;
  13375. var device = null;
  13376. var frameData = null;
  13377. var poseTarget = null;
  13378. var controllers = [];
  13379. var standingMatrix = new Matrix4();
  13380. var standingMatrixInverse = new Matrix4();
  13381. var framebufferScaleFactor = 1.0;
  13382. var referenceSpaceType = 'local-floor';
  13383. if ( typeof window !== 'undefined' && 'VRFrameData' in window ) {
  13384. frameData = new window.VRFrameData();
  13385. window.addEventListener( 'vrdisplaypresentchange', onVRDisplayPresentChange, false );
  13386. }
  13387. var matrixWorldInverse = new Matrix4();
  13388. var tempQuaternion = new Quaternion();
  13389. var tempPosition = new Vector3();
  13390. var cameraL = new PerspectiveCamera();
  13391. cameraL.viewport = new Vector4();
  13392. cameraL.layers.enable( 1 );
  13393. var cameraR = new PerspectiveCamera();
  13394. cameraR.viewport = new Vector4();
  13395. cameraR.layers.enable( 2 );
  13396. var cameraVR = new ArrayCamera( [ cameraL, cameraR ] );
  13397. cameraVR.layers.enable( 1 );
  13398. cameraVR.layers.enable( 2 );
  13399. //
  13400. function isPresenting() {
  13401. return device !== null && device.isPresenting === true;
  13402. }
  13403. var currentSize = new Vector2(), currentPixelRatio;
  13404. function onVRDisplayPresentChange() {
  13405. if ( isPresenting() ) {
  13406. var eyeParameters = device.getEyeParameters( 'left' );
  13407. renderWidth = 2 * eyeParameters.renderWidth * framebufferScaleFactor;
  13408. renderHeight = eyeParameters.renderHeight * framebufferScaleFactor;
  13409. currentPixelRatio = renderer.getPixelRatio();
  13410. renderer.getSize( currentSize );
  13411. renderer.setDrawingBufferSize( renderWidth, renderHeight, 1 );
  13412. cameraL.viewport.set( 0, 0, renderWidth / 2, renderHeight );
  13413. cameraR.viewport.set( renderWidth / 2, 0, renderWidth / 2, renderHeight );
  13414. animation.start();
  13415. scope.dispatchEvent( { type: 'sessionstart' } );
  13416. } else {
  13417. if ( scope.enabled ) {
  13418. renderer.setDrawingBufferSize( currentSize.width, currentSize.height, currentPixelRatio );
  13419. }
  13420. animation.stop();
  13421. scope.dispatchEvent( { type: 'sessionend' } );
  13422. }
  13423. }
  13424. //
  13425. var triggers = [];
  13426. function findGamepad( id ) {
  13427. var gamepads = navigator.getGamepads && navigator.getGamepads();
  13428. for ( var i = 0, j = 0, l = gamepads.length; i < l; i ++ ) {
  13429. var gamepad = gamepads[ i ];
  13430. if ( gamepad && ( gamepad.id === 'Daydream Controller' ||
  13431. gamepad.id === 'Gear VR Controller' || gamepad.id === 'Oculus Go Controller' ||
  13432. gamepad.id === 'OpenVR Gamepad' || gamepad.id.startsWith( 'Oculus Touch' ) ||
  13433. gamepad.id.startsWith( 'HTC Vive Focus' ) ||
  13434. gamepad.id.startsWith( 'Spatial Controller' ) ) ) {
  13435. if ( j === id ) return gamepad;
  13436. j ++;
  13437. }
  13438. }
  13439. }
  13440. function updateControllers() {
  13441. for ( var i = 0; i < controllers.length; i ++ ) {
  13442. var controller = controllers[ i ];
  13443. var gamepad = findGamepad( i );
  13444. if ( gamepad !== undefined && gamepad.pose !== undefined ) {
  13445. if ( gamepad.pose === null ) return;
  13446. // Pose
  13447. var pose = gamepad.pose;
  13448. if ( pose.hasPosition === false ) controller.position.set( 0.2, - 0.6, - 0.05 );
  13449. if ( pose.position !== null ) controller.position.fromArray( pose.position );
  13450. if ( pose.orientation !== null ) controller.quaternion.fromArray( pose.orientation );
  13451. controller.matrix.compose( controller.position, controller.quaternion, controller.scale );
  13452. controller.matrix.premultiply( standingMatrix );
  13453. controller.matrix.decompose( controller.position, controller.quaternion, controller.scale );
  13454. controller.matrixWorldNeedsUpdate = true;
  13455. controller.visible = true;
  13456. // Trigger
  13457. var buttonId = gamepad.id === 'Daydream Controller' ? 0 : 1;
  13458. if ( triggers[ i ] === undefined ) triggers[ i ] = false;
  13459. if ( triggers[ i ] !== gamepad.buttons[ buttonId ].pressed ) {
  13460. triggers[ i ] = gamepad.buttons[ buttonId ].pressed;
  13461. if ( triggers[ i ] === true ) {
  13462. controller.dispatchEvent( { type: 'selectstart' } );
  13463. } else {
  13464. controller.dispatchEvent( { type: 'selectend' } );
  13465. controller.dispatchEvent( { type: 'select' } );
  13466. }
  13467. }
  13468. } else {
  13469. controller.visible = false;
  13470. }
  13471. }
  13472. }
  13473. function updateViewportFromBounds( viewport, bounds ) {
  13474. if ( bounds !== null && bounds.length === 4 ) {
  13475. viewport.set( bounds[ 0 ] * renderWidth, bounds[ 1 ] * renderHeight, bounds[ 2 ] * renderWidth, bounds[ 3 ] * renderHeight );
  13476. }
  13477. }
  13478. //
  13479. this.enabled = false;
  13480. this.getController = function ( id ) {
  13481. var controller = controllers[ id ];
  13482. if ( controller === undefined ) {
  13483. controller = new Group();
  13484. controller.matrixAutoUpdate = false;
  13485. controller.visible = false;
  13486. controllers[ id ] = controller;
  13487. }
  13488. return controller;
  13489. };
  13490. this.getDevice = function () {
  13491. return device;
  13492. };
  13493. this.setDevice = function ( value ) {
  13494. if ( value !== undefined ) device = value;
  13495. animation.setContext( value );
  13496. };
  13497. this.setFramebufferScaleFactor = function ( value ) {
  13498. framebufferScaleFactor = value;
  13499. };
  13500. this.setReferenceSpaceType = function ( value ) {
  13501. referenceSpaceType = value;
  13502. };
  13503. this.setPoseTarget = function ( object ) {
  13504. if ( object !== undefined ) poseTarget = object;
  13505. };
  13506. this.getCamera = function ( camera ) {
  13507. var userHeight = referenceSpaceType === 'local-floor' ? 1.6 : 0;
  13508. if ( isPresenting() === false ) {
  13509. camera.position.set( 0, userHeight, 0 );
  13510. camera.rotation.set( 0, 0, 0 );
  13511. return camera;
  13512. }
  13513. device.depthNear = camera.near;
  13514. device.depthFar = camera.far;
  13515. device.getFrameData( frameData );
  13516. //
  13517. if ( referenceSpaceType === 'local-floor' ) {
  13518. var stageParameters = device.stageParameters;
  13519. if ( stageParameters ) {
  13520. standingMatrix.fromArray( stageParameters.sittingToStandingTransform );
  13521. } else {
  13522. standingMatrix.makeTranslation( 0, userHeight, 0 );
  13523. }
  13524. }
  13525. var pose = frameData.pose;
  13526. var poseObject = poseTarget !== null ? poseTarget : camera;
  13527. // We want to manipulate poseObject by its position and quaternion components since users may rely on them.
  13528. poseObject.matrix.copy( standingMatrix );
  13529. poseObject.matrix.decompose( poseObject.position, poseObject.quaternion, poseObject.scale );
  13530. if ( pose.orientation !== null ) {
  13531. tempQuaternion.fromArray( pose.orientation );
  13532. poseObject.quaternion.multiply( tempQuaternion );
  13533. }
  13534. if ( pose.position !== null ) {
  13535. tempQuaternion.setFromRotationMatrix( standingMatrix );
  13536. tempPosition.fromArray( pose.position );
  13537. tempPosition.applyQuaternion( tempQuaternion );
  13538. poseObject.position.add( tempPosition );
  13539. }
  13540. poseObject.updateMatrixWorld();
  13541. //
  13542. cameraL.near = camera.near;
  13543. cameraR.near = camera.near;
  13544. cameraL.far = camera.far;
  13545. cameraR.far = camera.far;
  13546. cameraL.matrixWorldInverse.fromArray( frameData.leftViewMatrix );
  13547. cameraR.matrixWorldInverse.fromArray( frameData.rightViewMatrix );
  13548. // TODO (mrdoob) Double check this code
  13549. standingMatrixInverse.getInverse( standingMatrix );
  13550. if ( referenceSpaceType === 'local-floor' ) {
  13551. cameraL.matrixWorldInverse.multiply( standingMatrixInverse );
  13552. cameraR.matrixWorldInverse.multiply( standingMatrixInverse );
  13553. }
  13554. var parent = poseObject.parent;
  13555. if ( parent !== null ) {
  13556. matrixWorldInverse.getInverse( parent.matrixWorld );
  13557. cameraL.matrixWorldInverse.multiply( matrixWorldInverse );
  13558. cameraR.matrixWorldInverse.multiply( matrixWorldInverse );
  13559. }
  13560. // envMap and Mirror needs camera.matrixWorld
  13561. cameraL.matrixWorld.getInverse( cameraL.matrixWorldInverse );
  13562. cameraR.matrixWorld.getInverse( cameraR.matrixWorldInverse );
  13563. cameraL.projectionMatrix.fromArray( frameData.leftProjectionMatrix );
  13564. cameraR.projectionMatrix.fromArray( frameData.rightProjectionMatrix );
  13565. setProjectionFromUnion( cameraVR, cameraL, cameraR );
  13566. //
  13567. var layers = device.getLayers();
  13568. if ( layers.length ) {
  13569. var layer = layers[ 0 ];
  13570. updateViewportFromBounds( cameraL.viewport, layer.leftBounds );
  13571. updateViewportFromBounds( cameraR.viewport, layer.rightBounds );
  13572. }
  13573. updateControllers();
  13574. return cameraVR;
  13575. };
  13576. this.getStandingMatrix = function () {
  13577. return standingMatrix;
  13578. };
  13579. this.isPresenting = isPresenting;
  13580. // Animation Loop
  13581. var animation = new WebGLAnimation();
  13582. this.setAnimationLoop = function ( callback ) {
  13583. animation.setAnimationLoop( callback );
  13584. if ( isPresenting() ) animation.start();
  13585. };
  13586. this.submitFrame = function () {
  13587. if ( isPresenting() ) device.submitFrame();
  13588. };
  13589. this.dispose = function () {
  13590. if ( typeof window !== 'undefined' ) {
  13591. window.removeEventListener( 'vrdisplaypresentchange', onVRDisplayPresentChange );
  13592. }
  13593. };
  13594. // DEPRECATED
  13595. this.setFrameOfReferenceType = function () {
  13596. console.warn( 'THREE.WebVRManager: setFrameOfReferenceType() has been deprecated.' );
  13597. };
  13598. }
  13599. Object.assign( WebVRManager.prototype, EventDispatcher.prototype );
  13600. /**
  13601. * @author mrdoob / http://mrdoob.com/
  13602. */
  13603. function WebXRManager( renderer, gl ) {
  13604. var scope = this;
  13605. var session = null;
  13606. var referenceSpace = null;
  13607. var referenceSpaceType = 'local-floor';
  13608. var pose = null;
  13609. var controllers = [];
  13610. var inputSources = [];
  13611. function isPresenting() {
  13612. return session !== null && referenceSpace !== null;
  13613. }
  13614. //
  13615. var cameraL = new PerspectiveCamera();
  13616. cameraL.layers.enable( 1 );
  13617. cameraL.viewport = new Vector4();
  13618. var cameraR = new PerspectiveCamera();
  13619. cameraR.layers.enable( 2 );
  13620. cameraR.viewport = new Vector4();
  13621. var cameraVR = new ArrayCamera( [ cameraL, cameraR ] );
  13622. cameraVR.layers.enable( 1 );
  13623. cameraVR.layers.enable( 2 );
  13624. //
  13625. this.enabled = false;
  13626. this.getController = function ( id ) {
  13627. var controller = controllers[ id ];
  13628. if ( controller === undefined ) {
  13629. controller = new Group();
  13630. controller.matrixAutoUpdate = false;
  13631. controller.visible = false;
  13632. controllers[ id ] = controller;
  13633. }
  13634. return controller;
  13635. };
  13636. //
  13637. function onSessionEvent( event ) {
  13638. for ( var i = 0; i < controllers.length; i ++ ) {
  13639. if ( inputSources[ i ] === event.inputSource ) {
  13640. controllers[ i ].dispatchEvent( { type: event.type } );
  13641. }
  13642. }
  13643. }
  13644. function onSessionEnd() {
  13645. renderer.setFramebuffer( null );
  13646. renderer.setRenderTarget( renderer.getRenderTarget() ); // Hack #15830
  13647. animation.stop();
  13648. scope.dispatchEvent( { type: 'sessionend' } );
  13649. }
  13650. function onRequestReferenceSpace( value ) {
  13651. referenceSpace = value;
  13652. animation.setContext( session );
  13653. animation.start();
  13654. scope.dispatchEvent( { type: 'sessionstart' } );
  13655. }
  13656. this.setFramebufferScaleFactor = function ( value ) {
  13657. };
  13658. this.setReferenceSpaceType = function ( value ) {
  13659. referenceSpaceType = value;
  13660. };
  13661. this.getSession = function () {
  13662. return session;
  13663. };
  13664. this.setSession = function ( value ) {
  13665. session = value;
  13666. if ( session !== null ) {
  13667. session.addEventListener( 'select', onSessionEvent );
  13668. session.addEventListener( 'selectstart', onSessionEvent );
  13669. session.addEventListener( 'selectend', onSessionEvent );
  13670. session.addEventListener( 'end', onSessionEnd );
  13671. session.updateRenderState( { baseLayer: new XRWebGLLayer( session, gl ) } );
  13672. session.requestReferenceSpace( referenceSpaceType ).then( onRequestReferenceSpace );
  13673. //
  13674. inputSources = session.inputSources;
  13675. session.addEventListener( 'inputsourceschange', function () {
  13676. inputSources = session.inputSources;
  13677. console.log( inputSources );
  13678. for ( var i = 0; i < controllers.length; i ++ ) {
  13679. var controller = controllers[ i ];
  13680. controller.userData.inputSource = inputSources[ i ];
  13681. }
  13682. } );
  13683. }
  13684. };
  13685. function updateCamera( camera, parent ) {
  13686. if ( parent === null ) {
  13687. camera.matrixWorld.copy( camera.matrix );
  13688. } else {
  13689. camera.matrixWorld.multiplyMatrices( parent.matrixWorld, camera.matrix );
  13690. }
  13691. camera.matrixWorldInverse.getInverse( camera.matrixWorld );
  13692. }
  13693. this.getCamera = function ( camera ) {
  13694. if ( isPresenting() ) {
  13695. var parent = camera.parent;
  13696. var cameras = cameraVR.cameras;
  13697. updateCamera( cameraVR, parent );
  13698. for ( var i = 0; i < cameras.length; i ++ ) {
  13699. updateCamera( cameras[ i ], parent );
  13700. }
  13701. // update camera and its children
  13702. camera.matrixWorld.copy( cameraVR.matrixWorld );
  13703. var children = camera.children;
  13704. for ( var i = 0, l = children.length; i < l; i ++ ) {
  13705. children[ i ].updateMatrixWorld( true );
  13706. }
  13707. setProjectionFromUnion( cameraVR, cameraL, cameraR );
  13708. return cameraVR;
  13709. }
  13710. return camera;
  13711. };
  13712. this.isPresenting = isPresenting;
  13713. // Animation Loop
  13714. var onAnimationFrameCallback = null;
  13715. function onAnimationFrame( time, frame ) {
  13716. pose = frame.getViewerPose( referenceSpace );
  13717. if ( pose !== null ) {
  13718. var views = pose.views;
  13719. var baseLayer = session.renderState.baseLayer;
  13720. renderer.setFramebuffer( baseLayer.framebuffer );
  13721. for ( var i = 0; i < views.length; i ++ ) {
  13722. var view = views[ i ];
  13723. var viewport = baseLayer.getViewport( view );
  13724. var viewMatrix = view.transform.inverse.matrix;
  13725. var camera = cameraVR.cameras[ i ];
  13726. camera.matrix.fromArray( viewMatrix ).getInverse( camera.matrix );
  13727. camera.projectionMatrix.fromArray( view.projectionMatrix );
  13728. camera.viewport.set( viewport.x, viewport.y, viewport.width, viewport.height );
  13729. if ( i === 0 ) {
  13730. cameraVR.matrix.copy( camera.matrix );
  13731. }
  13732. }
  13733. }
  13734. //
  13735. for ( var i = 0; i < controllers.length; i ++ ) {
  13736. var controller = controllers[ i ];
  13737. var inputSource = inputSources[ i ];
  13738. if ( inputSource ) {
  13739. var inputPose = frame.getPose( inputSource.targetRaySpace, referenceSpace );
  13740. if ( inputPose !== null ) {
  13741. controller.matrix.fromArray( inputPose.transform.matrix );
  13742. controller.matrix.decompose( controller.position, controller.rotation, controller.scale );
  13743. controller.visible = true;
  13744. continue;
  13745. }
  13746. }
  13747. controller.visible = false;
  13748. }
  13749. if ( onAnimationFrameCallback ) onAnimationFrameCallback( time );
  13750. }
  13751. var animation = new WebGLAnimation();
  13752. animation.setAnimationLoop( onAnimationFrame );
  13753. this.setAnimationLoop = function ( callback ) {
  13754. onAnimationFrameCallback = callback;
  13755. };
  13756. this.dispose = function () {};
  13757. // DEPRECATED
  13758. this.getStandingMatrix = function () {
  13759. console.warn( 'THREE.WebXRManager: getStandingMatrix() is no longer needed.' );
  13760. return new Matrix4();
  13761. };
  13762. this.getDevice = function () {
  13763. console.warn( 'THREE.WebXRManager: getDevice() has been deprecated.' );
  13764. };
  13765. this.setDevice = function () {
  13766. console.warn( 'THREE.WebXRManager: setDevice() has been deprecated.' );
  13767. };
  13768. this.setFrameOfReferenceType = function () {
  13769. console.warn( 'THREE.WebXRManager: setFrameOfReferenceType() has been deprecated.' );
  13770. };
  13771. this.submitFrame = function () {};
  13772. }
  13773. Object.assign( WebXRManager.prototype, EventDispatcher.prototype );
  13774. /**
  13775. * @author supereggbert / http://www.paulbrunt.co.uk/
  13776. * @author mrdoob / http://mrdoob.com/
  13777. * @author alteredq / http://alteredqualia.com/
  13778. * @author szimek / https://github.com/szimek/
  13779. * @author tschw
  13780. */
  13781. function WebGLRenderer( parameters ) {
  13782. console.log( 'THREE.WebGLRenderer', REVISION );
  13783. parameters = parameters || {};
  13784. var _canvas = parameters.canvas !== undefined ? parameters.canvas : document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' ),
  13785. _context = parameters.context !== undefined ? parameters.context : null,
  13786. _alpha = parameters.alpha !== undefined ? parameters.alpha : false,
  13787. _depth = parameters.depth !== undefined ? parameters.depth : true,
  13788. _stencil = parameters.stencil !== undefined ? parameters.stencil : true,
  13789. _antialias = parameters.antialias !== undefined ? parameters.antialias : false,
  13790. _premultipliedAlpha = parameters.premultipliedAlpha !== undefined ? parameters.premultipliedAlpha : true,
  13791. _preserveDrawingBuffer = parameters.preserveDrawingBuffer !== undefined ? parameters.preserveDrawingBuffer : false,
  13792. _powerPreference = parameters.powerPreference !== undefined ? parameters.powerPreference : 'default',
  13793. _failIfMajorPerformanceCaveat = parameters.failIfMajorPerformanceCaveat !== undefined ? parameters.failIfMajorPerformanceCaveat : false;
  13794. var currentRenderList = null;
  13795. var currentRenderState = null;
  13796. // public properties
  13797. this.domElement = _canvas;
  13798. // Debug configuration container
  13799. this.debug = {
  13800. /**
  13801. * Enables error checking and reporting when shader programs are being compiled
  13802. * @type {boolean}
  13803. */
  13804. checkShaderErrors: true
  13805. };
  13806. // clearing
  13807. this.autoClear = true;
  13808. this.autoClearColor = true;
  13809. this.autoClearDepth = true;
  13810. this.autoClearStencil = true;
  13811. // scene graph
  13812. this.sortObjects = true;
  13813. // user-defined clipping
  13814. this.clippingPlanes = [];
  13815. this.localClippingEnabled = false;
  13816. // physically based shading
  13817. this.gammaFactor = 2.0; // for backwards compatibility
  13818. this.gammaInput = false;
  13819. this.gammaOutput = false;
  13820. // physical lights
  13821. this.physicallyCorrectLights = false;
  13822. // tone mapping
  13823. this.toneMapping = LinearToneMapping;
  13824. this.toneMappingExposure = 1.0;
  13825. this.toneMappingWhitePoint = 1.0;
  13826. // morphs
  13827. this.maxMorphTargets = 8;
  13828. this.maxMorphNormals = 4;
  13829. // internal properties
  13830. var _this = this,
  13831. _isContextLost = false,
  13832. // internal state cache
  13833. _framebuffer = null,
  13834. _currentActiveCubeFace = 0,
  13835. _currentActiveMipmapLevel = 0,
  13836. _currentRenderTarget = null,
  13837. _currentFramebuffer = null,
  13838. _currentMaterialId = - 1,
  13839. // geometry and program caching
  13840. _currentGeometryProgram = {
  13841. geometry: null,
  13842. program: null,
  13843. wireframe: false
  13844. },
  13845. _currentCamera = null,
  13846. _currentArrayCamera = null,
  13847. _currentViewport = new Vector4(),
  13848. _currentScissor = new Vector4(),
  13849. _currentScissorTest = null,
  13850. //
  13851. _width = _canvas.width,
  13852. _height = _canvas.height,
  13853. _pixelRatio = 1,
  13854. _viewport = new Vector4( 0, 0, _width, _height ),
  13855. _scissor = new Vector4( 0, 0, _width, _height ),
  13856. _scissorTest = false,
  13857. // frustum
  13858. _frustum = new Frustum(),
  13859. // clipping
  13860. _clipping = new WebGLClipping(),
  13861. _clippingEnabled = false,
  13862. _localClippingEnabled = false,
  13863. // camera matrices cache
  13864. _projScreenMatrix = new Matrix4(),
  13865. _vector3 = new Vector3();
  13866. function getTargetPixelRatio() {
  13867. return _currentRenderTarget === null ? _pixelRatio : 1;
  13868. }
  13869. // initialize
  13870. var _gl;
  13871. try {
  13872. var contextAttributes = {
  13873. alpha: _alpha,
  13874. depth: _depth,
  13875. stencil: _stencil,
  13876. antialias: _antialias,
  13877. premultipliedAlpha: _premultipliedAlpha,
  13878. preserveDrawingBuffer: _preserveDrawingBuffer,
  13879. powerPreference: _powerPreference,
  13880. failIfMajorPerformanceCaveat: _failIfMajorPerformanceCaveat,
  13881. xrCompatible: true
  13882. };
  13883. // event listeners must be registered before WebGL context is created, see #12753
  13884. _canvas.addEventListener( 'webglcontextlost', onContextLost, false );
  13885. _canvas.addEventListener( 'webglcontextrestored', onContextRestore, false );
  13886. _gl = _context || _canvas.getContext( 'webgl', contextAttributes ) || _canvas.getContext( 'experimental-webgl', contextAttributes );
  13887. if ( _gl === null ) {
  13888. if ( _canvas.getContext( 'webgl' ) !== null ) {
  13889. throw new Error( 'Error creating WebGL context with your selected attributes.' );
  13890. } else {
  13891. throw new Error( 'Error creating WebGL context.' );
  13892. }
  13893. }
  13894. // Some experimental-webgl implementations do not have getShaderPrecisionFormat
  13895. if ( _gl.getShaderPrecisionFormat === undefined ) {
  13896. _gl.getShaderPrecisionFormat = function () {
  13897. return { 'rangeMin': 1, 'rangeMax': 1, 'precision': 1 };
  13898. };
  13899. }
  13900. } catch ( error ) {
  13901. console.error( 'THREE.WebGLRenderer: ' + error.message );
  13902. throw error;
  13903. }
  13904. var extensions, capabilities, state, info;
  13905. var properties, textures, attributes, geometries, objects;
  13906. var programCache, renderLists, renderStates;
  13907. var background, morphtargets, bufferRenderer, indexedBufferRenderer;
  13908. var utils;
  13909. function initGLContext() {
  13910. extensions = new WebGLExtensions( _gl );
  13911. capabilities = new WebGLCapabilities( _gl, extensions, parameters );
  13912. if ( ! capabilities.isWebGL2 ) {
  13913. extensions.get( 'WEBGL_depth_texture' );
  13914. extensions.get( 'OES_texture_float' );
  13915. extensions.get( 'OES_texture_half_float' );
  13916. extensions.get( 'OES_texture_half_float_linear' );
  13917. extensions.get( 'OES_standard_derivatives' );
  13918. extensions.get( 'OES_element_index_uint' );
  13919. extensions.get( 'ANGLE_instanced_arrays' );
  13920. }
  13921. extensions.get( 'OES_texture_float_linear' );
  13922. utils = new WebGLUtils( _gl, extensions, capabilities );
  13923. state = new WebGLState( _gl, extensions, utils, capabilities );
  13924. state.scissor( _currentScissor.copy( _scissor ).multiplyScalar( _pixelRatio ).floor() );
  13925. state.viewport( _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio ).floor() );
  13926. info = new WebGLInfo( _gl );
  13927. properties = new WebGLProperties();
  13928. textures = new WebGLTextures( _gl, extensions, state, properties, capabilities, utils, info );
  13929. attributes = new WebGLAttributes( _gl );
  13930. geometries = new WebGLGeometries( _gl, attributes, info );
  13931. objects = new WebGLObjects( geometries, info );
  13932. morphtargets = new WebGLMorphtargets( _gl );
  13933. programCache = new WebGLPrograms( _this, extensions, capabilities );
  13934. renderLists = new WebGLRenderLists();
  13935. renderStates = new WebGLRenderStates();
  13936. background = new WebGLBackground( _this, state, objects, _premultipliedAlpha );
  13937. bufferRenderer = new WebGLBufferRenderer( _gl, extensions, info, capabilities );
  13938. indexedBufferRenderer = new WebGLIndexedBufferRenderer( _gl, extensions, info, capabilities );
  13939. info.programs = programCache.programs;
  13940. _this.capabilities = capabilities;
  13941. _this.extensions = extensions;
  13942. _this.properties = properties;
  13943. _this.renderLists = renderLists;
  13944. _this.state = state;
  13945. _this.info = info;
  13946. }
  13947. initGLContext();
  13948. // vr
  13949. var vr = ( typeof navigator !== 'undefined' && 'xr' in navigator && 'supportsSession' in navigator.xr ) ? new WebXRManager( _this, _gl ) : new WebVRManager( _this );
  13950. this.vr = vr;
  13951. // shadow map
  13952. var shadowMap = new WebGLShadowMap( _this, objects, capabilities.maxTextureSize );
  13953. this.shadowMap = shadowMap;
  13954. // API
  13955. this.getContext = function () {
  13956. return _gl;
  13957. };
  13958. this.getContextAttributes = function () {
  13959. return _gl.getContextAttributes();
  13960. };
  13961. this.forceContextLoss = function () {
  13962. var extension = extensions.get( 'WEBGL_lose_context' );
  13963. if ( extension ) extension.loseContext();
  13964. };
  13965. this.forceContextRestore = function () {
  13966. var extension = extensions.get( 'WEBGL_lose_context' );
  13967. if ( extension ) extension.restoreContext();
  13968. };
  13969. this.getPixelRatio = function () {
  13970. return _pixelRatio;
  13971. };
  13972. this.setPixelRatio = function ( value ) {
  13973. if ( value === undefined ) return;
  13974. _pixelRatio = value;
  13975. this.setSize( _width, _height, false );
  13976. };
  13977. this.getSize = function ( target ) {
  13978. if ( target === undefined ) {
  13979. console.warn( 'WebGLRenderer: .getsize() now requires a Vector2 as an argument' );
  13980. target = new Vector2();
  13981. }
  13982. return target.set( _width, _height );
  13983. };
  13984. this.setSize = function ( width, height, updateStyle ) {
  13985. if ( vr.isPresenting() ) {
  13986. console.warn( 'THREE.WebGLRenderer: Can\'t change size while VR device is presenting.' );
  13987. return;
  13988. }
  13989. _width = width;
  13990. _height = height;
  13991. _canvas.width = Math.floor( width * _pixelRatio );
  13992. _canvas.height = Math.floor( height * _pixelRatio );
  13993. if ( updateStyle !== false ) {
  13994. _canvas.style.width = width + 'px';
  13995. _canvas.style.height = height + 'px';
  13996. }
  13997. this.setViewport( 0, 0, width, height );
  13998. };
  13999. this.getDrawingBufferSize = function ( target ) {
  14000. if ( target === undefined ) {
  14001. console.warn( 'WebGLRenderer: .getdrawingBufferSize() now requires a Vector2 as an argument' );
  14002. target = new Vector2();
  14003. }
  14004. return target.set( _width * _pixelRatio, _height * _pixelRatio ).floor();
  14005. };
  14006. this.setDrawingBufferSize = function ( width, height, pixelRatio ) {
  14007. _width = width;
  14008. _height = height;
  14009. _pixelRatio = pixelRatio;
  14010. _canvas.width = Math.floor( width * pixelRatio );
  14011. _canvas.height = Math.floor( height * pixelRatio );
  14012. this.setViewport( 0, 0, width, height );
  14013. };
  14014. this.getCurrentViewport = function ( target ) {
  14015. if ( target === undefined ) {
  14016. console.warn( 'WebGLRenderer: .getCurrentViewport() now requires a Vector4 as an argument' );
  14017. target = new Vector4();
  14018. }
  14019. return target.copy( _currentViewport );
  14020. };
  14021. this.getViewport = function ( target ) {
  14022. return target.copy( _viewport );
  14023. };
  14024. this.setViewport = function ( x, y, width, height ) {
  14025. if ( x.isVector4 ) {
  14026. _viewport.set( x.x, x.y, x.z, x.w );
  14027. } else {
  14028. _viewport.set( x, y, width, height );
  14029. }
  14030. state.viewport( _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio ).floor() );
  14031. };
  14032. this.getScissor = function ( target ) {
  14033. return target.copy( _scissor );
  14034. };
  14035. this.setScissor = function ( x, y, width, height ) {
  14036. if ( x.isVector4 ) {
  14037. _scissor.set( x.x, x.y, x.z, x.w );
  14038. } else {
  14039. _scissor.set( x, y, width, height );
  14040. }
  14041. state.scissor( _currentScissor.copy( _scissor ).multiplyScalar( _pixelRatio ).floor() );
  14042. };
  14043. this.getScissorTest = function () {
  14044. return _scissorTest;
  14045. };
  14046. this.setScissorTest = function ( boolean ) {
  14047. state.setScissorTest( _scissorTest = boolean );
  14048. };
  14049. // Clearing
  14050. this.getClearColor = function () {
  14051. return background.getClearColor();
  14052. };
  14053. this.setClearColor = function () {
  14054. background.setClearColor.apply( background, arguments );
  14055. };
  14056. this.getClearAlpha = function () {
  14057. return background.getClearAlpha();
  14058. };
  14059. this.setClearAlpha = function () {
  14060. background.setClearAlpha.apply( background, arguments );
  14061. };
  14062. this.clear = function ( color, depth, stencil ) {
  14063. var bits = 0;
  14064. if ( color === undefined || color ) bits |= 16384;
  14065. if ( depth === undefined || depth ) bits |= 256;
  14066. if ( stencil === undefined || stencil ) bits |= 1024;
  14067. _gl.clear( bits );
  14068. };
  14069. this.clearColor = function () {
  14070. this.clear( true, false, false );
  14071. };
  14072. this.clearDepth = function () {
  14073. this.clear( false, true, false );
  14074. };
  14075. this.clearStencil = function () {
  14076. this.clear( false, false, true );
  14077. };
  14078. //
  14079. this.dispose = function () {
  14080. _canvas.removeEventListener( 'webglcontextlost', onContextLost, false );
  14081. _canvas.removeEventListener( 'webglcontextrestored', onContextRestore, false );
  14082. renderLists.dispose();
  14083. renderStates.dispose();
  14084. properties.dispose();
  14085. objects.dispose();
  14086. vr.dispose();
  14087. animation.stop();
  14088. };
  14089. // Events
  14090. function onContextLost( event ) {
  14091. event.preventDefault();
  14092. console.log( 'THREE.WebGLRenderer: Context Lost.' );
  14093. _isContextLost = true;
  14094. }
  14095. function onContextRestore( /* event */ ) {
  14096. console.log( 'THREE.WebGLRenderer: Context Restored.' );
  14097. _isContextLost = false;
  14098. initGLContext();
  14099. }
  14100. function onMaterialDispose( event ) {
  14101. var material = event.target;
  14102. material.removeEventListener( 'dispose', onMaterialDispose );
  14103. deallocateMaterial( material );
  14104. }
  14105. // Buffer deallocation
  14106. function deallocateMaterial( material ) {
  14107. releaseMaterialProgramReference( material );
  14108. properties.remove( material );
  14109. }
  14110. function releaseMaterialProgramReference( material ) {
  14111. var programInfo = properties.get( material ).program;
  14112. material.program = undefined;
  14113. if ( programInfo !== undefined ) {
  14114. programCache.releaseProgram( programInfo );
  14115. }
  14116. }
  14117. // Buffer rendering
  14118. function renderObjectImmediate( object, program ) {
  14119. object.render( function ( object ) {
  14120. _this.renderBufferImmediate( object, program );
  14121. } );
  14122. }
  14123. this.renderBufferImmediate = function ( object, program ) {
  14124. state.initAttributes();
  14125. var buffers = properties.get( object );
  14126. if ( object.hasPositions && ! buffers.position ) buffers.position = _gl.createBuffer();
  14127. if ( object.hasNormals && ! buffers.normal ) buffers.normal = _gl.createBuffer();
  14128. if ( object.hasUvs && ! buffers.uv ) buffers.uv = _gl.createBuffer();
  14129. if ( object.hasColors && ! buffers.color ) buffers.color = _gl.createBuffer();
  14130. var programAttributes = program.getAttributes();
  14131. if ( object.hasPositions ) {
  14132. _gl.bindBuffer( 34962, buffers.position );
  14133. _gl.bufferData( 34962, object.positionArray, 35048 );
  14134. state.enableAttribute( programAttributes.position );
  14135. _gl.vertexAttribPointer( programAttributes.position, 3, 5126, false, 0, 0 );
  14136. }
  14137. if ( object.hasNormals ) {
  14138. _gl.bindBuffer( 34962, buffers.normal );
  14139. _gl.bufferData( 34962, object.normalArray, 35048 );
  14140. state.enableAttribute( programAttributes.normal );
  14141. _gl.vertexAttribPointer( programAttributes.normal, 3, 5126, false, 0, 0 );
  14142. }
  14143. if ( object.hasUvs ) {
  14144. _gl.bindBuffer( 34962, buffers.uv );
  14145. _gl.bufferData( 34962, object.uvArray, 35048 );
  14146. state.enableAttribute( programAttributes.uv );
  14147. _gl.vertexAttribPointer( programAttributes.uv, 2, 5126, false, 0, 0 );
  14148. }
  14149. if ( object.hasColors ) {
  14150. _gl.bindBuffer( 34962, buffers.color );
  14151. _gl.bufferData( 34962, object.colorArray, 35048 );
  14152. state.enableAttribute( programAttributes.color );
  14153. _gl.vertexAttribPointer( programAttributes.color, 3, 5126, false, 0, 0 );
  14154. }
  14155. state.disableUnusedAttributes();
  14156. _gl.drawArrays( 4, 0, object.count );
  14157. object.count = 0;
  14158. };
  14159. this.renderBufferDirect = function ( camera, fog, geometry, material, object, group ) {
  14160. var frontFaceCW = ( object.isMesh && object.matrixWorld.determinant() < 0 );
  14161. state.setMaterial( material, frontFaceCW );
  14162. var program = setProgram( camera, fog, material, object );
  14163. var updateBuffers = false;
  14164. if ( _currentGeometryProgram.geometry !== geometry.id ||
  14165. _currentGeometryProgram.program !== program.id ||
  14166. _currentGeometryProgram.wireframe !== ( material.wireframe === true ) ) {
  14167. _currentGeometryProgram.geometry = geometry.id;
  14168. _currentGeometryProgram.program = program.id;
  14169. _currentGeometryProgram.wireframe = material.wireframe === true;
  14170. updateBuffers = true;
  14171. }
  14172. if ( object.morphTargetInfluences ) {
  14173. morphtargets.update( object, geometry, material, program );
  14174. updateBuffers = true;
  14175. }
  14176. //
  14177. var index = geometry.index;
  14178. var position = geometry.attributes.position;
  14179. var rangeFactor = 1;
  14180. if ( material.wireframe === true ) {
  14181. index = geometries.getWireframeAttribute( geometry );
  14182. rangeFactor = 2;
  14183. }
  14184. var attribute;
  14185. var renderer = bufferRenderer;
  14186. if ( index !== null ) {
  14187. attribute = attributes.get( index );
  14188. renderer = indexedBufferRenderer;
  14189. renderer.setIndex( attribute );
  14190. }
  14191. if ( updateBuffers ) {
  14192. setupVertexAttributes( material, program, geometry );
  14193. if ( index !== null ) {
  14194. _gl.bindBuffer( 34963, attribute.buffer );
  14195. }
  14196. }
  14197. //
  14198. var dataCount = Infinity;
  14199. if ( index !== null ) {
  14200. dataCount = index.count;
  14201. } else if ( position !== undefined ) {
  14202. dataCount = position.count;
  14203. }
  14204. var rangeStart = geometry.drawRange.start * rangeFactor;
  14205. var rangeCount = geometry.drawRange.count * rangeFactor;
  14206. var groupStart = group !== null ? group.start * rangeFactor : 0;
  14207. var groupCount = group !== null ? group.count * rangeFactor : Infinity;
  14208. var drawStart = Math.max( rangeStart, groupStart );
  14209. var drawEnd = Math.min( dataCount, rangeStart + rangeCount, groupStart + groupCount ) - 1;
  14210. var drawCount = Math.max( 0, drawEnd - drawStart + 1 );
  14211. if ( drawCount === 0 ) return;
  14212. //
  14213. if ( object.isMesh ) {
  14214. if ( material.wireframe === true ) {
  14215. state.setLineWidth( material.wireframeLinewidth * getTargetPixelRatio() );
  14216. renderer.setMode( 1 );
  14217. } else {
  14218. switch ( object.drawMode ) {
  14219. case TrianglesDrawMode:
  14220. renderer.setMode( 4 );
  14221. break;
  14222. case TriangleStripDrawMode:
  14223. renderer.setMode( 5 );
  14224. break;
  14225. case TriangleFanDrawMode:
  14226. renderer.setMode( 6 );
  14227. break;
  14228. }
  14229. }
  14230. } else if ( object.isLine ) {
  14231. var lineWidth = material.linewidth;
  14232. if ( lineWidth === undefined ) lineWidth = 1; // Not using Line*Material
  14233. state.setLineWidth( lineWidth * getTargetPixelRatio() );
  14234. if ( object.isLineSegments ) {
  14235. renderer.setMode( 1 );
  14236. } else if ( object.isLineLoop ) {
  14237. renderer.setMode( 2 );
  14238. } else {
  14239. renderer.setMode( 3 );
  14240. }
  14241. } else if ( object.isPoints ) {
  14242. renderer.setMode( 0 );
  14243. } else if ( object.isSprite ) {
  14244. renderer.setMode( 4 );
  14245. }
  14246. if ( geometry && geometry.isInstancedBufferGeometry ) {
  14247. if ( geometry.maxInstancedCount > 0 ) {
  14248. renderer.renderInstances( geometry, drawStart, drawCount );
  14249. }
  14250. } else {
  14251. renderer.render( drawStart, drawCount );
  14252. }
  14253. };
  14254. function setupVertexAttributes( material, program, geometry ) {
  14255. if ( geometry && geometry.isInstancedBufferGeometry && ! capabilities.isWebGL2 ) {
  14256. if ( extensions.get( 'ANGLE_instanced_arrays' ) === null ) {
  14257. console.error( 'THREE.WebGLRenderer.setupVertexAttributes: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  14258. return;
  14259. }
  14260. }
  14261. state.initAttributes();
  14262. var geometryAttributes = geometry.attributes;
  14263. var programAttributes = program.getAttributes();
  14264. var materialDefaultAttributeValues = material.defaultAttributeValues;
  14265. for ( var name in programAttributes ) {
  14266. var programAttribute = programAttributes[ name ];
  14267. if ( programAttribute >= 0 ) {
  14268. var geometryAttribute = geometryAttributes[ name ];
  14269. if ( geometryAttribute !== undefined ) {
  14270. var normalized = geometryAttribute.normalized;
  14271. var size = geometryAttribute.itemSize;
  14272. var attribute = attributes.get( geometryAttribute );
  14273. // TODO Attribute may not be available on context restore
  14274. if ( attribute === undefined ) continue;
  14275. var buffer = attribute.buffer;
  14276. var type = attribute.type;
  14277. var bytesPerElement = attribute.bytesPerElement;
  14278. if ( geometryAttribute.isInterleavedBufferAttribute ) {
  14279. var data = geometryAttribute.data;
  14280. var stride = data.stride;
  14281. var offset = geometryAttribute.offset;
  14282. if ( data && data.isInstancedInterleavedBuffer ) {
  14283. state.enableAttributeAndDivisor( programAttribute, data.meshPerAttribute );
  14284. if ( geometry.maxInstancedCount === undefined ) {
  14285. geometry.maxInstancedCount = data.meshPerAttribute * data.count;
  14286. }
  14287. } else {
  14288. state.enableAttribute( programAttribute );
  14289. }
  14290. _gl.bindBuffer( 34962, buffer );
  14291. _gl.vertexAttribPointer( programAttribute, size, type, normalized, stride * bytesPerElement, offset * bytesPerElement );
  14292. } else {
  14293. if ( geometryAttribute.isInstancedBufferAttribute ) {
  14294. state.enableAttributeAndDivisor( programAttribute, geometryAttribute.meshPerAttribute );
  14295. if ( geometry.maxInstancedCount === undefined ) {
  14296. geometry.maxInstancedCount = geometryAttribute.meshPerAttribute * geometryAttribute.count;
  14297. }
  14298. } else {
  14299. state.enableAttribute( programAttribute );
  14300. }
  14301. _gl.bindBuffer( 34962, buffer );
  14302. _gl.vertexAttribPointer( programAttribute, size, type, normalized, 0, 0 );
  14303. }
  14304. } else if ( materialDefaultAttributeValues !== undefined ) {
  14305. var value = materialDefaultAttributeValues[ name ];
  14306. if ( value !== undefined ) {
  14307. switch ( value.length ) {
  14308. case 2:
  14309. _gl.vertexAttrib2fv( programAttribute, value );
  14310. break;
  14311. case 3:
  14312. _gl.vertexAttrib3fv( programAttribute, value );
  14313. break;
  14314. case 4:
  14315. _gl.vertexAttrib4fv( programAttribute, value );
  14316. break;
  14317. default:
  14318. _gl.vertexAttrib1fv( programAttribute, value );
  14319. }
  14320. }
  14321. }
  14322. }
  14323. }
  14324. state.disableUnusedAttributes();
  14325. }
  14326. // Compile
  14327. this.compile = function ( scene, camera ) {
  14328. currentRenderState = renderStates.get( scene, camera );
  14329. currentRenderState.init();
  14330. scene.traverse( function ( object ) {
  14331. if ( object.isLight ) {
  14332. currentRenderState.pushLight( object );
  14333. if ( object.castShadow ) {
  14334. currentRenderState.pushShadow( object );
  14335. }
  14336. }
  14337. } );
  14338. currentRenderState.setupLights( camera );
  14339. scene.traverse( function ( object ) {
  14340. if ( object.material ) {
  14341. if ( Array.isArray( object.material ) ) {
  14342. for ( var i = 0; i < object.material.length; i ++ ) {
  14343. initMaterial( object.material[ i ], scene.fog, object );
  14344. }
  14345. } else {
  14346. initMaterial( object.material, scene.fog, object );
  14347. }
  14348. }
  14349. } );
  14350. };
  14351. // Animation Loop
  14352. var onAnimationFrameCallback = null;
  14353. function onAnimationFrame( time ) {
  14354. if ( vr.isPresenting() ) return;
  14355. if ( onAnimationFrameCallback ) onAnimationFrameCallback( time );
  14356. }
  14357. var animation = new WebGLAnimation();
  14358. animation.setAnimationLoop( onAnimationFrame );
  14359. if ( typeof window !== 'undefined' ) animation.setContext( window );
  14360. this.setAnimationLoop = function ( callback ) {
  14361. onAnimationFrameCallback = callback;
  14362. vr.setAnimationLoop( callback );
  14363. animation.start();
  14364. };
  14365. // Rendering
  14366. this.render = function ( scene, camera ) {
  14367. var renderTarget, forceClear;
  14368. if ( arguments[ 2 ] !== undefined ) {
  14369. console.warn( 'THREE.WebGLRenderer.render(): the renderTarget argument has been removed. Use .setRenderTarget() instead.' );
  14370. renderTarget = arguments[ 2 ];
  14371. }
  14372. if ( arguments[ 3 ] !== undefined ) {
  14373. console.warn( 'THREE.WebGLRenderer.render(): the forceClear argument has been removed. Use .clear() instead.' );
  14374. forceClear = arguments[ 3 ];
  14375. }
  14376. if ( ! ( camera && camera.isCamera ) ) {
  14377. console.error( 'THREE.WebGLRenderer.render: camera is not an instance of THREE.Camera.' );
  14378. return;
  14379. }
  14380. if ( _isContextLost ) return;
  14381. // reset caching for this frame
  14382. _currentGeometryProgram.geometry = null;
  14383. _currentGeometryProgram.program = null;
  14384. _currentGeometryProgram.wireframe = false;
  14385. _currentMaterialId = - 1;
  14386. _currentCamera = null;
  14387. // update scene graph
  14388. if ( scene.autoUpdate === true ) scene.updateMatrixWorld();
  14389. // update camera matrices and frustum
  14390. if ( camera.parent === null ) camera.updateMatrixWorld();
  14391. if ( vr.enabled ) {
  14392. camera = vr.getCamera( camera );
  14393. }
  14394. //
  14395. currentRenderState = renderStates.get( scene, camera );
  14396. currentRenderState.init();
  14397. scene.onBeforeRender( _this, scene, camera, renderTarget || _currentRenderTarget );
  14398. _projScreenMatrix.multiplyMatrices( camera.projectionMatrix, camera.matrixWorldInverse );
  14399. _frustum.setFromMatrix( _projScreenMatrix );
  14400. _localClippingEnabled = this.localClippingEnabled;
  14401. _clippingEnabled = _clipping.init( this.clippingPlanes, _localClippingEnabled, camera );
  14402. currentRenderList = renderLists.get( scene, camera );
  14403. currentRenderList.init();
  14404. projectObject( scene, camera, 0, _this.sortObjects );
  14405. if ( _this.sortObjects === true ) {
  14406. currentRenderList.sort();
  14407. }
  14408. //
  14409. if ( _clippingEnabled ) _clipping.beginShadows();
  14410. var shadowsArray = currentRenderState.state.shadowsArray;
  14411. shadowMap.render( shadowsArray, scene, camera );
  14412. currentRenderState.setupLights( camera );
  14413. if ( _clippingEnabled ) _clipping.endShadows();
  14414. //
  14415. if ( this.info.autoReset ) this.info.reset();
  14416. if ( renderTarget !== undefined ) {
  14417. this.setRenderTarget( renderTarget );
  14418. }
  14419. //
  14420. background.render( currentRenderList, scene, camera, forceClear );
  14421. // render scene
  14422. var opaqueObjects = currentRenderList.opaque;
  14423. var transparentObjects = currentRenderList.transparent;
  14424. if ( scene.overrideMaterial ) {
  14425. var overrideMaterial = scene.overrideMaterial;
  14426. if ( opaqueObjects.length ) renderObjects( opaqueObjects, scene, camera, overrideMaterial );
  14427. if ( transparentObjects.length ) renderObjects( transparentObjects, scene, camera, overrideMaterial );
  14428. } else {
  14429. // opaque pass (front-to-back order)
  14430. if ( opaqueObjects.length ) renderObjects( opaqueObjects, scene, camera );
  14431. // transparent pass (back-to-front order)
  14432. if ( transparentObjects.length ) renderObjects( transparentObjects, scene, camera );
  14433. }
  14434. //
  14435. scene.onAfterRender( _this, scene, camera );
  14436. //
  14437. if ( _currentRenderTarget !== null ) {
  14438. // Generate mipmap if we're using any kind of mipmap filtering
  14439. textures.updateRenderTargetMipmap( _currentRenderTarget );
  14440. // resolve multisample renderbuffers to a single-sample texture if necessary
  14441. textures.updateMultisampleRenderTarget( _currentRenderTarget );
  14442. }
  14443. // Ensure depth buffer writing is enabled so it can be cleared on next render
  14444. state.buffers.depth.setTest( true );
  14445. state.buffers.depth.setMask( true );
  14446. state.buffers.color.setMask( true );
  14447. state.setPolygonOffset( false );
  14448. if ( vr.enabled ) {
  14449. vr.submitFrame();
  14450. }
  14451. // _gl.finish();
  14452. currentRenderList = null;
  14453. currentRenderState = null;
  14454. };
  14455. function projectObject( object, camera, groupOrder, sortObjects ) {
  14456. if ( object.visible === false ) return;
  14457. var visible = object.layers.test( camera.layers );
  14458. if ( visible ) {
  14459. if ( object.isGroup ) {
  14460. groupOrder = object.renderOrder;
  14461. } else if ( object.isLOD ) {
  14462. if ( object.autoUpdate === true ) object.update( camera );
  14463. } else if ( object.isLight ) {
  14464. currentRenderState.pushLight( object );
  14465. if ( object.castShadow ) {
  14466. currentRenderState.pushShadow( object );
  14467. }
  14468. } else if ( object.isSprite ) {
  14469. if ( ! object.frustumCulled || _frustum.intersectsSprite( object ) ) {
  14470. if ( sortObjects ) {
  14471. _vector3.setFromMatrixPosition( object.matrixWorld )
  14472. .applyMatrix4( _projScreenMatrix );
  14473. }
  14474. var geometry = objects.update( object );
  14475. var material = object.material;
  14476. if ( material.visible ) {
  14477. currentRenderList.push( object, geometry, material, groupOrder, _vector3.z, null );
  14478. }
  14479. }
  14480. } else if ( object.isImmediateRenderObject ) {
  14481. if ( sortObjects ) {
  14482. _vector3.setFromMatrixPosition( object.matrixWorld )
  14483. .applyMatrix4( _projScreenMatrix );
  14484. }
  14485. currentRenderList.push( object, null, object.material, groupOrder, _vector3.z, null );
  14486. } else if ( object.isMesh || object.isLine || object.isPoints ) {
  14487. if ( object.isSkinnedMesh ) {
  14488. object.skeleton.update();
  14489. }
  14490. if ( ! object.frustumCulled || _frustum.intersectsObject( object ) ) {
  14491. if ( sortObjects ) {
  14492. _vector3.setFromMatrixPosition( object.matrixWorld )
  14493. .applyMatrix4( _projScreenMatrix );
  14494. }
  14495. var geometry = objects.update( object );
  14496. var material = object.material;
  14497. if ( Array.isArray( material ) ) {
  14498. var groups = geometry.groups;
  14499. for ( var i = 0, l = groups.length; i < l; i ++ ) {
  14500. var group = groups[ i ];
  14501. var groupMaterial = material[ group.materialIndex ];
  14502. if ( groupMaterial && groupMaterial.visible ) {
  14503. currentRenderList.push( object, geometry, groupMaterial, groupOrder, _vector3.z, group );
  14504. }
  14505. }
  14506. } else if ( material.visible ) {
  14507. currentRenderList.push( object, geometry, material, groupOrder, _vector3.z, null );
  14508. }
  14509. }
  14510. }
  14511. }
  14512. var children = object.children;
  14513. for ( var i = 0, l = children.length; i < l; i ++ ) {
  14514. projectObject( children[ i ], camera, groupOrder, sortObjects );
  14515. }
  14516. }
  14517. function renderObjects( renderList, scene, camera, overrideMaterial ) {
  14518. for ( var i = 0, l = renderList.length; i < l; i ++ ) {
  14519. var renderItem = renderList[ i ];
  14520. var object = renderItem.object;
  14521. var geometry = renderItem.geometry;
  14522. var material = overrideMaterial === undefined ? renderItem.material : overrideMaterial;
  14523. var group = renderItem.group;
  14524. if ( camera.isArrayCamera ) {
  14525. _currentArrayCamera = camera;
  14526. var cameras = camera.cameras;
  14527. for ( var j = 0, jl = cameras.length; j < jl; j ++ ) {
  14528. var camera2 = cameras[ j ];
  14529. if ( object.layers.test( camera2.layers ) ) {
  14530. state.viewport( _currentViewport.copy( camera2.viewport ) );
  14531. currentRenderState.setupLights( camera2 );
  14532. renderObject( object, scene, camera2, geometry, material, group );
  14533. }
  14534. }
  14535. } else {
  14536. _currentArrayCamera = null;
  14537. renderObject( object, scene, camera, geometry, material, group );
  14538. }
  14539. }
  14540. }
  14541. function renderObject( object, scene, camera, geometry, material, group ) {
  14542. object.onBeforeRender( _this, scene, camera, geometry, material, group );
  14543. currentRenderState = renderStates.get( scene, _currentArrayCamera || camera );
  14544. object.modelViewMatrix.multiplyMatrices( camera.matrixWorldInverse, object.matrixWorld );
  14545. object.normalMatrix.getNormalMatrix( object.modelViewMatrix );
  14546. if ( object.isImmediateRenderObject ) {
  14547. state.setMaterial( material );
  14548. var program = setProgram( camera, scene.fog, material, object );
  14549. _currentGeometryProgram.geometry = null;
  14550. _currentGeometryProgram.program = null;
  14551. _currentGeometryProgram.wireframe = false;
  14552. renderObjectImmediate( object, program );
  14553. } else {
  14554. _this.renderBufferDirect( camera, scene.fog, geometry, material, object, group );
  14555. }
  14556. object.onAfterRender( _this, scene, camera, geometry, material, group );
  14557. currentRenderState = renderStates.get( scene, _currentArrayCamera || camera );
  14558. }
  14559. function initMaterial( material, fog, object ) {
  14560. var materialProperties = properties.get( material );
  14561. var lights = currentRenderState.state.lights;
  14562. var shadowsArray = currentRenderState.state.shadowsArray;
  14563. var lightsStateVersion = lights.state.version;
  14564. var parameters = programCache.getParameters(
  14565. material, lights.state, shadowsArray, fog, _clipping.numPlanes, _clipping.numIntersection, object );
  14566. var code = programCache.getProgramCode( material, parameters );
  14567. var program = materialProperties.program;
  14568. var programChange = true;
  14569. if ( program === undefined ) {
  14570. // new material
  14571. material.addEventListener( 'dispose', onMaterialDispose );
  14572. } else if ( program.code !== code ) {
  14573. // changed glsl or parameters
  14574. releaseMaterialProgramReference( material );
  14575. } else if ( materialProperties.lightsStateVersion !== lightsStateVersion ) {
  14576. materialProperties.lightsStateVersion = lightsStateVersion;
  14577. programChange = false;
  14578. } else if ( parameters.shaderID !== undefined ) {
  14579. // same glsl and uniform list
  14580. return;
  14581. } else {
  14582. // only rebuild uniform list
  14583. programChange = false;
  14584. }
  14585. if ( programChange ) {
  14586. if ( parameters.shaderID ) {
  14587. var shader = ShaderLib[ parameters.shaderID ];
  14588. materialProperties.shader = {
  14589. name: material.type,
  14590. uniforms: cloneUniforms( shader.uniforms ),
  14591. vertexShader: shader.vertexShader,
  14592. fragmentShader: shader.fragmentShader
  14593. };
  14594. } else {
  14595. materialProperties.shader = {
  14596. name: material.type,
  14597. uniforms: material.uniforms,
  14598. vertexShader: material.vertexShader,
  14599. fragmentShader: material.fragmentShader
  14600. };
  14601. }
  14602. material.onBeforeCompile( materialProperties.shader, _this );
  14603. // Computing code again as onBeforeCompile may have changed the shaders
  14604. code = programCache.getProgramCode( material, parameters );
  14605. program = programCache.acquireProgram( material, materialProperties.shader, parameters, code );
  14606. materialProperties.program = program;
  14607. material.program = program;
  14608. }
  14609. var programAttributes = program.getAttributes();
  14610. if ( material.morphTargets ) {
  14611. material.numSupportedMorphTargets = 0;
  14612. for ( var i = 0; i < _this.maxMorphTargets; i ++ ) {
  14613. if ( programAttributes[ 'morphTarget' + i ] >= 0 ) {
  14614. material.numSupportedMorphTargets ++;
  14615. }
  14616. }
  14617. }
  14618. if ( material.morphNormals ) {
  14619. material.numSupportedMorphNormals = 0;
  14620. for ( var i = 0; i < _this.maxMorphNormals; i ++ ) {
  14621. if ( programAttributes[ 'morphNormal' + i ] >= 0 ) {
  14622. material.numSupportedMorphNormals ++;
  14623. }
  14624. }
  14625. }
  14626. var uniforms = materialProperties.shader.uniforms;
  14627. if ( ! material.isShaderMaterial &&
  14628. ! material.isRawShaderMaterial ||
  14629. material.clipping === true ) {
  14630. materialProperties.numClippingPlanes = _clipping.numPlanes;
  14631. materialProperties.numIntersection = _clipping.numIntersection;
  14632. uniforms.clippingPlanes = _clipping.uniform;
  14633. }
  14634. materialProperties.fog = fog;
  14635. // store the light setup it was created for
  14636. materialProperties.lightsStateVersion = lightsStateVersion;
  14637. if ( material.lights ) {
  14638. // wire up the material to this renderer's lighting state
  14639. uniforms.ambientLightColor.value = lights.state.ambient;
  14640. uniforms.lightProbe.value = lights.state.probe;
  14641. uniforms.directionalLights.value = lights.state.directional;
  14642. uniforms.spotLights.value = lights.state.spot;
  14643. uniforms.rectAreaLights.value = lights.state.rectArea;
  14644. uniforms.pointLights.value = lights.state.point;
  14645. uniforms.hemisphereLights.value = lights.state.hemi;
  14646. uniforms.directionalShadowMap.value = lights.state.directionalShadowMap;
  14647. uniforms.directionalShadowMatrix.value = lights.state.directionalShadowMatrix;
  14648. uniforms.spotShadowMap.value = lights.state.spotShadowMap;
  14649. uniforms.spotShadowMatrix.value = lights.state.spotShadowMatrix;
  14650. uniforms.pointShadowMap.value = lights.state.pointShadowMap;
  14651. uniforms.pointShadowMatrix.value = lights.state.pointShadowMatrix;
  14652. // TODO (abelnation): add area lights shadow info to uniforms
  14653. }
  14654. var progUniforms = materialProperties.program.getUniforms(),
  14655. uniformsList =
  14656. WebGLUniforms.seqWithValue( progUniforms.seq, uniforms );
  14657. materialProperties.uniformsList = uniformsList;
  14658. }
  14659. function setProgram( camera, fog, material, object ) {
  14660. textures.resetTextureUnits();
  14661. var materialProperties = properties.get( material );
  14662. var lights = currentRenderState.state.lights;
  14663. if ( _clippingEnabled ) {
  14664. if ( _localClippingEnabled || camera !== _currentCamera ) {
  14665. var useCache =
  14666. camera === _currentCamera &&
  14667. material.id === _currentMaterialId;
  14668. // we might want to call this function with some ClippingGroup
  14669. // object instead of the material, once it becomes feasible
  14670. // (#8465, #8379)
  14671. _clipping.setState(
  14672. material.clippingPlanes, material.clipIntersection, material.clipShadows,
  14673. camera, materialProperties, useCache );
  14674. }
  14675. }
  14676. if ( material.needsUpdate === false ) {
  14677. if ( materialProperties.program === undefined ) {
  14678. material.needsUpdate = true;
  14679. } else if ( material.fog && materialProperties.fog !== fog ) {
  14680. material.needsUpdate = true;
  14681. } else if ( material.lights && materialProperties.lightsStateVersion !== lights.state.version ) {
  14682. material.needsUpdate = true;
  14683. } else if ( materialProperties.numClippingPlanes !== undefined &&
  14684. ( materialProperties.numClippingPlanes !== _clipping.numPlanes ||
  14685. materialProperties.numIntersection !== _clipping.numIntersection ) ) {
  14686. material.needsUpdate = true;
  14687. }
  14688. }
  14689. if ( material.needsUpdate ) {
  14690. initMaterial( material, fog, object );
  14691. material.needsUpdate = false;
  14692. }
  14693. var refreshProgram = false;
  14694. var refreshMaterial = false;
  14695. var refreshLights = false;
  14696. var program = materialProperties.program,
  14697. p_uniforms = program.getUniforms(),
  14698. m_uniforms = materialProperties.shader.uniforms;
  14699. if ( state.useProgram( program.program ) ) {
  14700. refreshProgram = true;
  14701. refreshMaterial = true;
  14702. refreshLights = true;
  14703. }
  14704. if ( material.id !== _currentMaterialId ) {
  14705. _currentMaterialId = material.id;
  14706. refreshMaterial = true;
  14707. }
  14708. if ( refreshProgram || _currentCamera !== camera ) {
  14709. p_uniforms.setValue( _gl, 'projectionMatrix', camera.projectionMatrix );
  14710. if ( capabilities.logarithmicDepthBuffer ) {
  14711. p_uniforms.setValue( _gl, 'logDepthBufFC',
  14712. 2.0 / ( Math.log( camera.far + 1.0 ) / Math.LN2 ) );
  14713. }
  14714. if ( _currentCamera !== camera ) {
  14715. _currentCamera = camera;
  14716. // lighting uniforms depend on the camera so enforce an update
  14717. // now, in case this material supports lights - or later, when
  14718. // the next material that does gets activated:
  14719. refreshMaterial = true; // set to true on material change
  14720. refreshLights = true; // remains set until update done
  14721. }
  14722. // load material specific uniforms
  14723. // (shader material also gets them for the sake of genericity)
  14724. if ( material.isShaderMaterial ||
  14725. material.isMeshPhongMaterial ||
  14726. material.isMeshStandardMaterial ||
  14727. material.envMap ) {
  14728. var uCamPos = p_uniforms.map.cameraPosition;
  14729. if ( uCamPos !== undefined ) {
  14730. uCamPos.setValue( _gl,
  14731. _vector3.setFromMatrixPosition( camera.matrixWorld ) );
  14732. }
  14733. }
  14734. if ( material.isMeshPhongMaterial ||
  14735. material.isMeshLambertMaterial ||
  14736. material.isMeshBasicMaterial ||
  14737. material.isMeshStandardMaterial ||
  14738. material.isShaderMaterial ||
  14739. material.skinning ) {
  14740. p_uniforms.setValue( _gl, 'viewMatrix', camera.matrixWorldInverse );
  14741. }
  14742. }
  14743. // skinning uniforms must be set even if material didn't change
  14744. // auto-setting of texture unit for bone texture must go before other textures
  14745. // not sure why, but otherwise weird things happen
  14746. if ( material.skinning ) {
  14747. p_uniforms.setOptional( _gl, object, 'bindMatrix' );
  14748. p_uniforms.setOptional( _gl, object, 'bindMatrixInverse' );
  14749. var skeleton = object.skeleton;
  14750. if ( skeleton ) {
  14751. var bones = skeleton.bones;
  14752. if ( capabilities.floatVertexTextures ) {
  14753. if ( skeleton.boneTexture === undefined ) {
  14754. // layout (1 matrix = 4 pixels)
  14755. // RGBA RGBA RGBA RGBA (=> column1, column2, column3, column4)
  14756. // with 8x8 pixel texture max 16 bones * 4 pixels = (8 * 8)
  14757. // 16x16 pixel texture max 64 bones * 4 pixels = (16 * 16)
  14758. // 32x32 pixel texture max 256 bones * 4 pixels = (32 * 32)
  14759. // 64x64 pixel texture max 1024 bones * 4 pixels = (64 * 64)
  14760. var size = Math.sqrt( bones.length * 4 ); // 4 pixels needed for 1 matrix
  14761. size = _Math.ceilPowerOfTwo( size );
  14762. size = Math.max( size, 4 );
  14763. var boneMatrices = new Float32Array( size * size * 4 ); // 4 floats per RGBA pixel
  14764. boneMatrices.set( skeleton.boneMatrices ); // copy current values
  14765. var boneTexture = new DataTexture( boneMatrices, size, size, RGBAFormat, FloatType );
  14766. boneTexture.needsUpdate = true;
  14767. skeleton.boneMatrices = boneMatrices;
  14768. skeleton.boneTexture = boneTexture;
  14769. skeleton.boneTextureSize = size;
  14770. }
  14771. p_uniforms.setValue( _gl, 'boneTexture', skeleton.boneTexture, textures );
  14772. p_uniforms.setValue( _gl, 'boneTextureSize', skeleton.boneTextureSize );
  14773. } else {
  14774. p_uniforms.setOptional( _gl, skeleton, 'boneMatrices' );
  14775. }
  14776. }
  14777. }
  14778. if ( refreshMaterial ) {
  14779. p_uniforms.setValue( _gl, 'toneMappingExposure', _this.toneMappingExposure );
  14780. p_uniforms.setValue( _gl, 'toneMappingWhitePoint', _this.toneMappingWhitePoint );
  14781. if ( material.lights ) {
  14782. // the current material requires lighting info
  14783. // note: all lighting uniforms are always set correctly
  14784. // they simply reference the renderer's state for their
  14785. // values
  14786. //
  14787. // use the current material's .needsUpdate flags to set
  14788. // the GL state when required
  14789. markUniformsLightsNeedsUpdate( m_uniforms, refreshLights );
  14790. }
  14791. // refresh uniforms common to several materials
  14792. if ( fog && material.fog ) {
  14793. refreshUniformsFog( m_uniforms, fog );
  14794. }
  14795. if ( material.isMeshBasicMaterial ) {
  14796. refreshUniformsCommon( m_uniforms, material );
  14797. } else if ( material.isMeshLambertMaterial ) {
  14798. refreshUniformsCommon( m_uniforms, material );
  14799. refreshUniformsLambert( m_uniforms, material );
  14800. } else if ( material.isMeshPhongMaterial ) {
  14801. refreshUniformsCommon( m_uniforms, material );
  14802. if ( material.isMeshToonMaterial ) {
  14803. refreshUniformsToon( m_uniforms, material );
  14804. } else {
  14805. refreshUniformsPhong( m_uniforms, material );
  14806. }
  14807. } else if ( material.isMeshStandardMaterial ) {
  14808. refreshUniformsCommon( m_uniforms, material );
  14809. if ( material.isMeshPhysicalMaterial ) {
  14810. refreshUniformsPhysical( m_uniforms, material );
  14811. } else {
  14812. refreshUniformsStandard( m_uniforms, material );
  14813. }
  14814. } else if ( material.isMeshMatcapMaterial ) {
  14815. refreshUniformsCommon( m_uniforms, material );
  14816. refreshUniformsMatcap( m_uniforms, material );
  14817. } else if ( material.isMeshDepthMaterial ) {
  14818. refreshUniformsCommon( m_uniforms, material );
  14819. refreshUniformsDepth( m_uniforms, material );
  14820. } else if ( material.isMeshDistanceMaterial ) {
  14821. refreshUniformsCommon( m_uniforms, material );
  14822. refreshUniformsDistance( m_uniforms, material );
  14823. } else if ( material.isMeshNormalMaterial ) {
  14824. refreshUniformsCommon( m_uniforms, material );
  14825. refreshUniformsNormal( m_uniforms, material );
  14826. } else if ( material.isLineBasicMaterial ) {
  14827. refreshUniformsLine( m_uniforms, material );
  14828. if ( material.isLineDashedMaterial ) {
  14829. refreshUniformsDash( m_uniforms, material );
  14830. }
  14831. } else if ( material.isPointsMaterial ) {
  14832. refreshUniformsPoints( m_uniforms, material );
  14833. } else if ( material.isSpriteMaterial ) {
  14834. refreshUniformsSprites( m_uniforms, material );
  14835. } else if ( material.isShadowMaterial ) {
  14836. m_uniforms.color.value.copy( material.color );
  14837. m_uniforms.opacity.value = material.opacity;
  14838. }
  14839. // RectAreaLight Texture
  14840. // TODO (mrdoob): Find a nicer implementation
  14841. if ( m_uniforms.ltc_1 !== undefined ) m_uniforms.ltc_1.value = UniformsLib.LTC_1;
  14842. if ( m_uniforms.ltc_2 !== undefined ) m_uniforms.ltc_2.value = UniformsLib.LTC_2;
  14843. WebGLUniforms.upload( _gl, materialProperties.uniformsList, m_uniforms, textures );
  14844. }
  14845. if ( material.isShaderMaterial && material.uniformsNeedUpdate === true ) {
  14846. WebGLUniforms.upload( _gl, materialProperties.uniformsList, m_uniforms, textures );
  14847. material.uniformsNeedUpdate = false;
  14848. }
  14849. if ( material.isSpriteMaterial ) {
  14850. p_uniforms.setValue( _gl, 'center', object.center );
  14851. }
  14852. // common matrices
  14853. p_uniforms.setValue( _gl, 'modelViewMatrix', object.modelViewMatrix );
  14854. p_uniforms.setValue( _gl, 'normalMatrix', object.normalMatrix );
  14855. p_uniforms.setValue( _gl, 'modelMatrix', object.matrixWorld );
  14856. return program;
  14857. }
  14858. // Uniforms (refresh uniforms objects)
  14859. function refreshUniformsCommon( uniforms, material ) {
  14860. uniforms.opacity.value = material.opacity;
  14861. if ( material.color ) {
  14862. uniforms.diffuse.value.copy( material.color );
  14863. }
  14864. if ( material.emissive ) {
  14865. uniforms.emissive.value.copy( material.emissive ).multiplyScalar( material.emissiveIntensity );
  14866. }
  14867. if ( material.map ) {
  14868. uniforms.map.value = material.map;
  14869. }
  14870. if ( material.alphaMap ) {
  14871. uniforms.alphaMap.value = material.alphaMap;
  14872. }
  14873. if ( material.specularMap ) {
  14874. uniforms.specularMap.value = material.specularMap;
  14875. }
  14876. if ( material.envMap ) {
  14877. uniforms.envMap.value = material.envMap;
  14878. // don't flip CubeTexture envMaps, flip everything else:
  14879. // WebGLRenderTargetCube will be flipped for backwards compatibility
  14880. // WebGLRenderTargetCube.texture will be flipped because it's a Texture and NOT a CubeTexture
  14881. // this check must be handled differently, or removed entirely, if WebGLRenderTargetCube uses a CubeTexture in the future
  14882. uniforms.flipEnvMap.value = material.envMap.isCubeTexture ? - 1 : 1;
  14883. uniforms.reflectivity.value = material.reflectivity;
  14884. uniforms.refractionRatio.value = material.refractionRatio;
  14885. uniforms.maxMipLevel.value = properties.get( material.envMap ).__maxMipLevel;
  14886. }
  14887. if ( material.lightMap ) {
  14888. uniforms.lightMap.value = material.lightMap;
  14889. uniforms.lightMapIntensity.value = material.lightMapIntensity;
  14890. }
  14891. if ( material.aoMap ) {
  14892. uniforms.aoMap.value = material.aoMap;
  14893. uniforms.aoMapIntensity.value = material.aoMapIntensity;
  14894. }
  14895. // uv repeat and offset setting priorities
  14896. // 1. color map
  14897. // 2. specular map
  14898. // 3. normal map
  14899. // 4. bump map
  14900. // 5. alpha map
  14901. // 6. emissive map
  14902. var uvScaleMap;
  14903. if ( material.map ) {
  14904. uvScaleMap = material.map;
  14905. } else if ( material.specularMap ) {
  14906. uvScaleMap = material.specularMap;
  14907. } else if ( material.displacementMap ) {
  14908. uvScaleMap = material.displacementMap;
  14909. } else if ( material.normalMap ) {
  14910. uvScaleMap = material.normalMap;
  14911. } else if ( material.bumpMap ) {
  14912. uvScaleMap = material.bumpMap;
  14913. } else if ( material.roughnessMap ) {
  14914. uvScaleMap = material.roughnessMap;
  14915. } else if ( material.metalnessMap ) {
  14916. uvScaleMap = material.metalnessMap;
  14917. } else if ( material.alphaMap ) {
  14918. uvScaleMap = material.alphaMap;
  14919. } else if ( material.emissiveMap ) {
  14920. uvScaleMap = material.emissiveMap;
  14921. }
  14922. if ( uvScaleMap !== undefined ) {
  14923. // backwards compatibility
  14924. if ( uvScaleMap.isWebGLRenderTarget ) {
  14925. uvScaleMap = uvScaleMap.texture;
  14926. }
  14927. if ( uvScaleMap.matrixAutoUpdate === true ) {
  14928. uvScaleMap.updateMatrix();
  14929. }
  14930. uniforms.uvTransform.value.copy( uvScaleMap.matrix );
  14931. }
  14932. }
  14933. function refreshUniformsLine( uniforms, material ) {
  14934. uniforms.diffuse.value.copy( material.color );
  14935. uniforms.opacity.value = material.opacity;
  14936. }
  14937. function refreshUniformsDash( uniforms, material ) {
  14938. uniforms.dashSize.value = material.dashSize;
  14939. uniforms.totalSize.value = material.dashSize + material.gapSize;
  14940. uniforms.scale.value = material.scale;
  14941. }
  14942. function refreshUniformsPoints( uniforms, material ) {
  14943. uniforms.diffuse.value.copy( material.color );
  14944. uniforms.opacity.value = material.opacity;
  14945. uniforms.size.value = material.size * _pixelRatio;
  14946. uniforms.scale.value = _height * 0.5;
  14947. uniforms.map.value = material.map;
  14948. if ( material.map !== null ) {
  14949. if ( material.map.matrixAutoUpdate === true ) {
  14950. material.map.updateMatrix();
  14951. }
  14952. uniforms.uvTransform.value.copy( material.map.matrix );
  14953. }
  14954. }
  14955. function refreshUniformsSprites( uniforms, material ) {
  14956. uniforms.diffuse.value.copy( material.color );
  14957. uniforms.opacity.value = material.opacity;
  14958. uniforms.rotation.value = material.rotation;
  14959. uniforms.map.value = material.map;
  14960. if ( material.map !== null ) {
  14961. if ( material.map.matrixAutoUpdate === true ) {
  14962. material.map.updateMatrix();
  14963. }
  14964. uniforms.uvTransform.value.copy( material.map.matrix );
  14965. }
  14966. }
  14967. function refreshUniformsFog( uniforms, fog ) {
  14968. uniforms.fogColor.value.copy( fog.color );
  14969. if ( fog.isFog ) {
  14970. uniforms.fogNear.value = fog.near;
  14971. uniforms.fogFar.value = fog.far;
  14972. } else if ( fog.isFogExp2 ) {
  14973. uniforms.fogDensity.value = fog.density;
  14974. }
  14975. }
  14976. function refreshUniformsLambert( uniforms, material ) {
  14977. if ( material.emissiveMap ) {
  14978. uniforms.emissiveMap.value = material.emissiveMap;
  14979. }
  14980. }
  14981. function refreshUniformsPhong( uniforms, material ) {
  14982. uniforms.specular.value.copy( material.specular );
  14983. uniforms.shininess.value = Math.max( material.shininess, 1e-4 ); // to prevent pow( 0.0, 0.0 )
  14984. if ( material.emissiveMap ) {
  14985. uniforms.emissiveMap.value = material.emissiveMap;
  14986. }
  14987. if ( material.bumpMap ) {
  14988. uniforms.bumpMap.value = material.bumpMap;
  14989. uniforms.bumpScale.value = material.bumpScale;
  14990. if ( material.side === BackSide ) uniforms.bumpScale.value *= - 1;
  14991. }
  14992. if ( material.normalMap ) {
  14993. uniforms.normalMap.value = material.normalMap;
  14994. uniforms.normalScale.value.copy( material.normalScale );
  14995. if ( material.side === BackSide ) uniforms.normalScale.value.negate();
  14996. }
  14997. if ( material.displacementMap ) {
  14998. uniforms.displacementMap.value = material.displacementMap;
  14999. uniforms.displacementScale.value = material.displacementScale;
  15000. uniforms.displacementBias.value = material.displacementBias;
  15001. }
  15002. }
  15003. function refreshUniformsToon( uniforms, material ) {
  15004. refreshUniformsPhong( uniforms, material );
  15005. if ( material.gradientMap ) {
  15006. uniforms.gradientMap.value = material.gradientMap;
  15007. }
  15008. }
  15009. function refreshUniformsStandard( uniforms, material ) {
  15010. uniforms.roughness.value = material.roughness;
  15011. uniforms.metalness.value = material.metalness;
  15012. if ( material.roughnessMap ) {
  15013. uniforms.roughnessMap.value = material.roughnessMap;
  15014. }
  15015. if ( material.metalnessMap ) {
  15016. uniforms.metalnessMap.value = material.metalnessMap;
  15017. }
  15018. if ( material.emissiveMap ) {
  15019. uniforms.emissiveMap.value = material.emissiveMap;
  15020. }
  15021. if ( material.bumpMap ) {
  15022. uniforms.bumpMap.value = material.bumpMap;
  15023. uniforms.bumpScale.value = material.bumpScale;
  15024. if ( material.side === BackSide ) uniforms.bumpScale.value *= - 1;
  15025. }
  15026. if ( material.normalMap ) {
  15027. uniforms.normalMap.value = material.normalMap;
  15028. uniforms.normalScale.value.copy( material.normalScale );
  15029. if ( material.side === BackSide ) uniforms.normalScale.value.negate();
  15030. }
  15031. if ( material.displacementMap ) {
  15032. uniforms.displacementMap.value = material.displacementMap;
  15033. uniforms.displacementScale.value = material.displacementScale;
  15034. uniforms.displacementBias.value = material.displacementBias;
  15035. }
  15036. if ( material.envMap ) {
  15037. //uniforms.envMap.value = material.envMap; // part of uniforms common
  15038. uniforms.envMapIntensity.value = material.envMapIntensity;
  15039. }
  15040. }
  15041. function refreshUniformsPhysical( uniforms, material ) {
  15042. refreshUniformsStandard( uniforms, material );
  15043. uniforms.reflectivity.value = material.reflectivity; // also part of uniforms common
  15044. uniforms.clearCoat.value = material.clearCoat;
  15045. uniforms.clearCoatRoughness.value = material.clearCoatRoughness;
  15046. }
  15047. function refreshUniformsMatcap( uniforms, material ) {
  15048. if ( material.matcap ) {
  15049. uniforms.matcap.value = material.matcap;
  15050. }
  15051. if ( material.bumpMap ) {
  15052. uniforms.bumpMap.value = material.bumpMap;
  15053. uniforms.bumpScale.value = material.bumpScale;
  15054. if ( material.side === BackSide ) uniforms.bumpScale.value *= - 1;
  15055. }
  15056. if ( material.normalMap ) {
  15057. uniforms.normalMap.value = material.normalMap;
  15058. uniforms.normalScale.value.copy( material.normalScale );
  15059. if ( material.side === BackSide ) uniforms.normalScale.value.negate();
  15060. }
  15061. if ( material.displacementMap ) {
  15062. uniforms.displacementMap.value = material.displacementMap;
  15063. uniforms.displacementScale.value = material.displacementScale;
  15064. uniforms.displacementBias.value = material.displacementBias;
  15065. }
  15066. }
  15067. function refreshUniformsDepth( uniforms, material ) {
  15068. if ( material.displacementMap ) {
  15069. uniforms.displacementMap.value = material.displacementMap;
  15070. uniforms.displacementScale.value = material.displacementScale;
  15071. uniforms.displacementBias.value = material.displacementBias;
  15072. }
  15073. }
  15074. function refreshUniformsDistance( uniforms, material ) {
  15075. if ( material.displacementMap ) {
  15076. uniforms.displacementMap.value = material.displacementMap;
  15077. uniforms.displacementScale.value = material.displacementScale;
  15078. uniforms.displacementBias.value = material.displacementBias;
  15079. }
  15080. uniforms.referencePosition.value.copy( material.referencePosition );
  15081. uniforms.nearDistance.value = material.nearDistance;
  15082. uniforms.farDistance.value = material.farDistance;
  15083. }
  15084. function refreshUniformsNormal( uniforms, material ) {
  15085. if ( material.bumpMap ) {
  15086. uniforms.bumpMap.value = material.bumpMap;
  15087. uniforms.bumpScale.value = material.bumpScale;
  15088. if ( material.side === BackSide ) uniforms.bumpScale.value *= - 1;
  15089. }
  15090. if ( material.normalMap ) {
  15091. uniforms.normalMap.value = material.normalMap;
  15092. uniforms.normalScale.value.copy( material.normalScale );
  15093. if ( material.side === BackSide ) uniforms.normalScale.value.negate();
  15094. }
  15095. if ( material.displacementMap ) {
  15096. uniforms.displacementMap.value = material.displacementMap;
  15097. uniforms.displacementScale.value = material.displacementScale;
  15098. uniforms.displacementBias.value = material.displacementBias;
  15099. }
  15100. }
  15101. // If uniforms are marked as clean, they don't need to be loaded to the GPU.
  15102. function markUniformsLightsNeedsUpdate( uniforms, value ) {
  15103. uniforms.ambientLightColor.needsUpdate = value;
  15104. uniforms.lightProbe.needsUpdate = value;
  15105. uniforms.directionalLights.needsUpdate = value;
  15106. uniforms.pointLights.needsUpdate = value;
  15107. uniforms.spotLights.needsUpdate = value;
  15108. uniforms.rectAreaLights.needsUpdate = value;
  15109. uniforms.hemisphereLights.needsUpdate = value;
  15110. }
  15111. //
  15112. this.setFramebuffer = function ( value ) {
  15113. if ( _framebuffer !== value ) _gl.bindFramebuffer( 36160, value );
  15114. _framebuffer = value;
  15115. };
  15116. this.getActiveCubeFace = function () {
  15117. return _currentActiveCubeFace;
  15118. };
  15119. this.getActiveMipmapLevel = function () {
  15120. return _currentActiveMipmapLevel;
  15121. };
  15122. this.getRenderTarget = function () {
  15123. return _currentRenderTarget;
  15124. };
  15125. this.setRenderTarget = function ( renderTarget, activeCubeFace, activeMipmapLevel ) {
  15126. _currentRenderTarget = renderTarget;
  15127. _currentActiveCubeFace = activeCubeFace;
  15128. _currentActiveMipmapLevel = activeMipmapLevel;
  15129. if ( renderTarget && properties.get( renderTarget ).__webglFramebuffer === undefined ) {
  15130. textures.setupRenderTarget( renderTarget );
  15131. }
  15132. var framebuffer = _framebuffer;
  15133. var isCube = false;
  15134. if ( renderTarget ) {
  15135. var __webglFramebuffer = properties.get( renderTarget ).__webglFramebuffer;
  15136. if ( renderTarget.isWebGLRenderTargetCube ) {
  15137. framebuffer = __webglFramebuffer[ activeCubeFace || 0 ];
  15138. isCube = true;
  15139. } else if ( renderTarget.isWebGLMultisampleRenderTarget ) {
  15140. framebuffer = properties.get( renderTarget ).__webglMultisampledFramebuffer;
  15141. } else {
  15142. framebuffer = __webglFramebuffer;
  15143. }
  15144. _currentViewport.copy( renderTarget.viewport );
  15145. _currentScissor.copy( renderTarget.scissor );
  15146. _currentScissorTest = renderTarget.scissorTest;
  15147. } else {
  15148. _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio ).floor();
  15149. _currentScissor.copy( _scissor ).multiplyScalar( _pixelRatio ).floor();
  15150. _currentScissorTest = _scissorTest;
  15151. }
  15152. if ( _currentFramebuffer !== framebuffer ) {
  15153. _gl.bindFramebuffer( 36160, framebuffer );
  15154. _currentFramebuffer = framebuffer;
  15155. }
  15156. state.viewport( _currentViewport );
  15157. state.scissor( _currentScissor );
  15158. state.setScissorTest( _currentScissorTest );
  15159. if ( isCube ) {
  15160. var textureProperties = properties.get( renderTarget.texture );
  15161. _gl.framebufferTexture2D( 36160, 36064, 34069 + ( activeCubeFace || 0 ), textureProperties.__webglTexture, activeMipmapLevel || 0 );
  15162. }
  15163. };
  15164. this.readRenderTargetPixels = function ( renderTarget, x, y, width, height, buffer, activeCubeFaceIndex ) {
  15165. if ( ! ( renderTarget && renderTarget.isWebGLRenderTarget ) ) {
  15166. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.' );
  15167. return;
  15168. }
  15169. var framebuffer = properties.get( renderTarget ).__webglFramebuffer;
  15170. if ( renderTarget.isWebGLRenderTargetCube && activeCubeFaceIndex !== undefined ) {
  15171. framebuffer = framebuffer[ activeCubeFaceIndex ];
  15172. }
  15173. if ( framebuffer ) {
  15174. var restore = false;
  15175. if ( framebuffer !== _currentFramebuffer ) {
  15176. _gl.bindFramebuffer( 36160, framebuffer );
  15177. restore = true;
  15178. }
  15179. try {
  15180. var texture = renderTarget.texture;
  15181. var textureFormat = texture.format;
  15182. var textureType = texture.type;
  15183. if ( textureFormat !== RGBAFormat && utils.convert( textureFormat ) !== _gl.getParameter( 35739 ) ) {
  15184. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA or implementation defined format.' );
  15185. return;
  15186. }
  15187. if ( textureType !== UnsignedByteType && utils.convert( textureType ) !== _gl.getParameter( 35738 ) && // IE11, Edge and Chrome Mac < 52 (#9513)
  15188. ! ( textureType === FloatType && ( capabilities.isWebGL2 || extensions.get( 'OES_texture_float' ) || extensions.get( 'WEBGL_color_buffer_float' ) ) ) && // Chrome Mac >= 52 and Firefox
  15189. ! ( textureType === HalfFloatType && ( capabilities.isWebGL2 ? extensions.get( 'EXT_color_buffer_float' ) : extensions.get( 'EXT_color_buffer_half_float' ) ) ) ) {
  15190. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in UnsignedByteType or implementation defined type.' );
  15191. return;
  15192. }
  15193. if ( _gl.checkFramebufferStatus( 36160 ) === 36053 ) {
  15194. // the following if statement ensures valid read requests (no out-of-bounds pixels, see #8604)
  15195. if ( ( x >= 0 && x <= ( renderTarget.width - width ) ) && ( y >= 0 && y <= ( renderTarget.height - height ) ) ) {
  15196. _gl.readPixels( x, y, width, height, utils.convert( textureFormat ), utils.convert( textureType ), buffer );
  15197. }
  15198. } else {
  15199. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: readPixels from renderTarget failed. Framebuffer not complete.' );
  15200. }
  15201. } finally {
  15202. if ( restore ) {
  15203. _gl.bindFramebuffer( 36160, _currentFramebuffer );
  15204. }
  15205. }
  15206. }
  15207. };
  15208. this.copyFramebufferToTexture = function ( position, texture, level ) {
  15209. var width = texture.image.width;
  15210. var height = texture.image.height;
  15211. var glFormat = utils.convert( texture.format );
  15212. textures.setTexture2D( texture, 0 );
  15213. _gl.copyTexImage2D( 3553, level || 0, glFormat, position.x, position.y, width, height, 0 );
  15214. };
  15215. this.copyTextureToTexture = function ( position, srcTexture, dstTexture, level ) {
  15216. var width = srcTexture.image.width;
  15217. var height = srcTexture.image.height;
  15218. var glFormat = utils.convert( dstTexture.format );
  15219. var glType = utils.convert( dstTexture.type );
  15220. textures.setTexture2D( dstTexture, 0 );
  15221. if ( srcTexture.isDataTexture ) {
  15222. _gl.texSubImage2D( 3553, level || 0, position.x, position.y, width, height, glFormat, glType, srcTexture.image.data );
  15223. } else {
  15224. _gl.texSubImage2D( 3553, level || 0, position.x, position.y, glFormat, glType, srcTexture.image );
  15225. }
  15226. };
  15227. if ( typeof __THREE_DEVTOOLS__ !== 'undefined' ) {
  15228. __THREE_DEVTOOLS__.dispatchEvent( new CustomEvent( 'observe', { detail: this } ) ); // eslint-disable-line no-undef
  15229. }
  15230. }
  15231. /**
  15232. * @author mrdoob / http://mrdoob.com/
  15233. * @author alteredq / http://alteredqualia.com/
  15234. */
  15235. function FogExp2( color, density ) {
  15236. this.name = '';
  15237. this.color = new Color( color );
  15238. this.density = ( density !== undefined ) ? density : 0.00025;
  15239. }
  15240. Object.assign( FogExp2.prototype, {
  15241. isFogExp2: true,
  15242. clone: function () {
  15243. return new FogExp2( this.color, this.density );
  15244. },
  15245. toJSON: function ( /* meta */ ) {
  15246. return {
  15247. type: 'FogExp2',
  15248. color: this.color.getHex(),
  15249. density: this.density
  15250. };
  15251. }
  15252. } );
  15253. /**
  15254. * @author mrdoob / http://mrdoob.com/
  15255. * @author alteredq / http://alteredqualia.com/
  15256. */
  15257. function Fog( color, near, far ) {
  15258. this.name = '';
  15259. this.color = new Color( color );
  15260. this.near = ( near !== undefined ) ? near : 1;
  15261. this.far = ( far !== undefined ) ? far : 1000;
  15262. }
  15263. Object.assign( Fog.prototype, {
  15264. isFog: true,
  15265. clone: function () {
  15266. return new Fog( this.color, this.near, this.far );
  15267. },
  15268. toJSON: function ( /* meta */ ) {
  15269. return {
  15270. type: 'Fog',
  15271. color: this.color.getHex(),
  15272. near: this.near,
  15273. far: this.far
  15274. };
  15275. }
  15276. } );
  15277. /**
  15278. * @author benaadams / https://twitter.com/ben_a_adams
  15279. */
  15280. function InterleavedBuffer( array, stride ) {
  15281. this.array = array;
  15282. this.stride = stride;
  15283. this.count = array !== undefined ? array.length / stride : 0;
  15284. this.dynamic = false;
  15285. this.updateRange = { offset: 0, count: - 1 };
  15286. this.version = 0;
  15287. }
  15288. Object.defineProperty( InterleavedBuffer.prototype, 'needsUpdate', {
  15289. set: function ( value ) {
  15290. if ( value === true ) this.version ++;
  15291. }
  15292. } );
  15293. Object.assign( InterleavedBuffer.prototype, {
  15294. isInterleavedBuffer: true,
  15295. onUploadCallback: function () {},
  15296. setArray: function ( array ) {
  15297. if ( Array.isArray( array ) ) {
  15298. throw new TypeError( 'THREE.BufferAttribute: array should be a Typed Array.' );
  15299. }
  15300. this.count = array !== undefined ? array.length / this.stride : 0;
  15301. this.array = array;
  15302. return this;
  15303. },
  15304. setDynamic: function ( value ) {
  15305. this.dynamic = value;
  15306. return this;
  15307. },
  15308. copy: function ( source ) {
  15309. this.array = new source.array.constructor( source.array );
  15310. this.count = source.count;
  15311. this.stride = source.stride;
  15312. this.dynamic = source.dynamic;
  15313. return this;
  15314. },
  15315. copyAt: function ( index1, attribute, index2 ) {
  15316. index1 *= this.stride;
  15317. index2 *= attribute.stride;
  15318. for ( var i = 0, l = this.stride; i < l; i ++ ) {
  15319. this.array[ index1 + i ] = attribute.array[ index2 + i ];
  15320. }
  15321. return this;
  15322. },
  15323. set: function ( value, offset ) {
  15324. if ( offset === undefined ) offset = 0;
  15325. this.array.set( value, offset );
  15326. return this;
  15327. },
  15328. clone: function () {
  15329. return new this.constructor().copy( this );
  15330. },
  15331. onUpload: function ( callback ) {
  15332. this.onUploadCallback = callback;
  15333. return this;
  15334. }
  15335. } );
  15336. /**
  15337. * @author benaadams / https://twitter.com/ben_a_adams
  15338. */
  15339. function InterleavedBufferAttribute( interleavedBuffer, itemSize, offset, normalized ) {
  15340. this.data = interleavedBuffer;
  15341. this.itemSize = itemSize;
  15342. this.offset = offset;
  15343. this.normalized = normalized === true;
  15344. }
  15345. Object.defineProperties( InterleavedBufferAttribute.prototype, {
  15346. count: {
  15347. get: function () {
  15348. return this.data.count;
  15349. }
  15350. },
  15351. array: {
  15352. get: function () {
  15353. return this.data.array;
  15354. }
  15355. }
  15356. } );
  15357. Object.assign( InterleavedBufferAttribute.prototype, {
  15358. isInterleavedBufferAttribute: true,
  15359. setX: function ( index, x ) {
  15360. this.data.array[ index * this.data.stride + this.offset ] = x;
  15361. return this;
  15362. },
  15363. setY: function ( index, y ) {
  15364. this.data.array[ index * this.data.stride + this.offset + 1 ] = y;
  15365. return this;
  15366. },
  15367. setZ: function ( index, z ) {
  15368. this.data.array[ index * this.data.stride + this.offset + 2 ] = z;
  15369. return this;
  15370. },
  15371. setW: function ( index, w ) {
  15372. this.data.array[ index * this.data.stride + this.offset + 3 ] = w;
  15373. return this;
  15374. },
  15375. getX: function ( index ) {
  15376. return this.data.array[ index * this.data.stride + this.offset ];
  15377. },
  15378. getY: function ( index ) {
  15379. return this.data.array[ index * this.data.stride + this.offset + 1 ];
  15380. },
  15381. getZ: function ( index ) {
  15382. return this.data.array[ index * this.data.stride + this.offset + 2 ];
  15383. },
  15384. getW: function ( index ) {
  15385. return this.data.array[ index * this.data.stride + this.offset + 3 ];
  15386. },
  15387. setXY: function ( index, x, y ) {
  15388. index = index * this.data.stride + this.offset;
  15389. this.data.array[ index + 0 ] = x;
  15390. this.data.array[ index + 1 ] = y;
  15391. return this;
  15392. },
  15393. setXYZ: function ( index, x, y, z ) {
  15394. index = index * this.data.stride + this.offset;
  15395. this.data.array[ index + 0 ] = x;
  15396. this.data.array[ index + 1 ] = y;
  15397. this.data.array[ index + 2 ] = z;
  15398. return this;
  15399. },
  15400. setXYZW: function ( index, x, y, z, w ) {
  15401. index = index * this.data.stride + this.offset;
  15402. this.data.array[ index + 0 ] = x;
  15403. this.data.array[ index + 1 ] = y;
  15404. this.data.array[ index + 2 ] = z;
  15405. this.data.array[ index + 3 ] = w;
  15406. return this;
  15407. }
  15408. } );
  15409. /**
  15410. * @author alteredq / http://alteredqualia.com/
  15411. *
  15412. * parameters = {
  15413. * color: <hex>,
  15414. * map: new THREE.Texture( <Image> ),
  15415. * rotation: <float>,
  15416. * sizeAttenuation: <bool>
  15417. * }
  15418. */
  15419. function SpriteMaterial( parameters ) {
  15420. Material.call( this );
  15421. this.type = 'SpriteMaterial';
  15422. this.color = new Color( 0xffffff );
  15423. this.map = null;
  15424. this.rotation = 0;
  15425. this.sizeAttenuation = true;
  15426. this.lights = false;
  15427. this.transparent = true;
  15428. this.setValues( parameters );
  15429. }
  15430. SpriteMaterial.prototype = Object.create( Material.prototype );
  15431. SpriteMaterial.prototype.constructor = SpriteMaterial;
  15432. SpriteMaterial.prototype.isSpriteMaterial = true;
  15433. SpriteMaterial.prototype.copy = function ( source ) {
  15434. Material.prototype.copy.call( this, source );
  15435. this.color.copy( source.color );
  15436. this.map = source.map;
  15437. this.rotation = source.rotation;
  15438. this.sizeAttenuation = source.sizeAttenuation;
  15439. return this;
  15440. };
  15441. /**
  15442. * @author mikael emtinger / http://gomo.se/
  15443. * @author alteredq / http://alteredqualia.com/
  15444. */
  15445. var geometry;
  15446. function Sprite( material ) {
  15447. Object3D.call( this );
  15448. this.type = 'Sprite';
  15449. if ( geometry === undefined ) {
  15450. geometry = new BufferGeometry();
  15451. var float32Array = new Float32Array( [
  15452. - 0.5, - 0.5, 0, 0, 0,
  15453. 0.5, - 0.5, 0, 1, 0,
  15454. 0.5, 0.5, 0, 1, 1,
  15455. - 0.5, 0.5, 0, 0, 1
  15456. ] );
  15457. var interleavedBuffer = new InterleavedBuffer( float32Array, 5 );
  15458. geometry.setIndex( [ 0, 1, 2, 0, 2, 3 ] );
  15459. geometry.addAttribute( 'position', new InterleavedBufferAttribute( interleavedBuffer, 3, 0, false ) );
  15460. geometry.addAttribute( 'uv', new InterleavedBufferAttribute( interleavedBuffer, 2, 3, false ) );
  15461. }
  15462. this.geometry = geometry;
  15463. this.material = ( material !== undefined ) ? material : new SpriteMaterial();
  15464. this.center = new Vector2( 0.5, 0.5 );
  15465. }
  15466. Sprite.prototype = Object.assign( Object.create( Object3D.prototype ), {
  15467. constructor: Sprite,
  15468. isSprite: true,
  15469. raycast: ( function () {
  15470. var intersectPoint = new Vector3();
  15471. var worldScale = new Vector3();
  15472. var mvPosition = new Vector3();
  15473. var alignedPosition = new Vector2();
  15474. var rotatedPosition = new Vector2();
  15475. var viewWorldMatrix = new Matrix4();
  15476. var vA = new Vector3();
  15477. var vB = new Vector3();
  15478. var vC = new Vector3();
  15479. var uvA = new Vector2();
  15480. var uvB = new Vector2();
  15481. var uvC = new Vector2();
  15482. function transformVertex( vertexPosition, mvPosition, center, scale, sin, cos ) {
  15483. // compute position in camera space
  15484. alignedPosition.subVectors( vertexPosition, center ).addScalar( 0.5 ).multiply( scale );
  15485. // to check if rotation is not zero
  15486. if ( sin !== undefined ) {
  15487. rotatedPosition.x = ( cos * alignedPosition.x ) - ( sin * alignedPosition.y );
  15488. rotatedPosition.y = ( sin * alignedPosition.x ) + ( cos * alignedPosition.y );
  15489. } else {
  15490. rotatedPosition.copy( alignedPosition );
  15491. }
  15492. vertexPosition.copy( mvPosition );
  15493. vertexPosition.x += rotatedPosition.x;
  15494. vertexPosition.y += rotatedPosition.y;
  15495. // transform to world space
  15496. vertexPosition.applyMatrix4( viewWorldMatrix );
  15497. }
  15498. return function raycast( raycaster, intersects ) {
  15499. worldScale.setFromMatrixScale( this.matrixWorld );
  15500. viewWorldMatrix.copy( raycaster._camera.matrixWorld );
  15501. this.modelViewMatrix.multiplyMatrices( raycaster._camera.matrixWorldInverse, this.matrixWorld );
  15502. mvPosition.setFromMatrixPosition( this.modelViewMatrix );
  15503. if ( raycaster._camera.isPerspectiveCamera && this.material.sizeAttenuation === false ) {
  15504. worldScale.multiplyScalar( - mvPosition.z );
  15505. }
  15506. var rotation = this.material.rotation;
  15507. var sin, cos;
  15508. if ( rotation !== 0 ) {
  15509. cos = Math.cos( rotation );
  15510. sin = Math.sin( rotation );
  15511. }
  15512. var center = this.center;
  15513. transformVertex( vA.set( - 0.5, - 0.5, 0 ), mvPosition, center, worldScale, sin, cos );
  15514. transformVertex( vB.set( 0.5, - 0.5, 0 ), mvPosition, center, worldScale, sin, cos );
  15515. transformVertex( vC.set( 0.5, 0.5, 0 ), mvPosition, center, worldScale, sin, cos );
  15516. uvA.set( 0, 0 );
  15517. uvB.set( 1, 0 );
  15518. uvC.set( 1, 1 );
  15519. // check first triangle
  15520. var intersect = raycaster.ray.intersectTriangle( vA, vB, vC, false, intersectPoint );
  15521. if ( intersect === null ) {
  15522. // check second triangle
  15523. transformVertex( vB.set( - 0.5, 0.5, 0 ), mvPosition, center, worldScale, sin, cos );
  15524. uvB.set( 0, 1 );
  15525. intersect = raycaster.ray.intersectTriangle( vA, vC, vB, false, intersectPoint );
  15526. if ( intersect === null ) {
  15527. return;
  15528. }
  15529. }
  15530. var distance = raycaster.ray.origin.distanceTo( intersectPoint );
  15531. if ( distance < raycaster.near || distance > raycaster.far ) return;
  15532. intersects.push( {
  15533. distance: distance,
  15534. point: intersectPoint.clone(),
  15535. uv: Triangle.getUV( intersectPoint, vA, vB, vC, uvA, uvB, uvC, new Vector2() ),
  15536. face: null,
  15537. object: this
  15538. } );
  15539. };
  15540. }() ),
  15541. clone: function () {
  15542. return new this.constructor( this.material ).copy( this );
  15543. },
  15544. copy: function ( source ) {
  15545. Object3D.prototype.copy.call( this, source );
  15546. if ( source.center !== undefined ) this.center.copy( source.center );
  15547. return this;
  15548. }
  15549. } );
  15550. /**
  15551. * @author mikael emtinger / http://gomo.se/
  15552. * @author alteredq / http://alteredqualia.com/
  15553. * @author mrdoob / http://mrdoob.com/
  15554. */
  15555. function LOD() {
  15556. Object3D.call( this );
  15557. this.type = 'LOD';
  15558. Object.defineProperties( this, {
  15559. levels: {
  15560. enumerable: true,
  15561. value: []
  15562. }
  15563. } );
  15564. this.autoUpdate = true;
  15565. }
  15566. LOD.prototype = Object.assign( Object.create( Object3D.prototype ), {
  15567. constructor: LOD,
  15568. isLOD: true,
  15569. copy: function ( source ) {
  15570. Object3D.prototype.copy.call( this, source, false );
  15571. var levels = source.levels;
  15572. for ( var i = 0, l = levels.length; i < l; i ++ ) {
  15573. var level = levels[ i ];
  15574. this.addLevel( level.object.clone(), level.distance );
  15575. }
  15576. return this;
  15577. },
  15578. addLevel: function ( object, distance ) {
  15579. if ( distance === undefined ) distance = 0;
  15580. distance = Math.abs( distance );
  15581. var levels = this.levels;
  15582. for ( var l = 0; l < levels.length; l ++ ) {
  15583. if ( distance < levels[ l ].distance ) {
  15584. break;
  15585. }
  15586. }
  15587. levels.splice( l, 0, { distance: distance, object: object } );
  15588. this.add( object );
  15589. return this;
  15590. },
  15591. getObjectForDistance: function ( distance ) {
  15592. var levels = this.levels;
  15593. for ( var i = 1, l = levels.length; i < l; i ++ ) {
  15594. if ( distance < levels[ i ].distance ) {
  15595. break;
  15596. }
  15597. }
  15598. return levels[ i - 1 ].object;
  15599. },
  15600. raycast: ( function () {
  15601. var matrixPosition = new Vector3();
  15602. return function raycast( raycaster, intersects ) {
  15603. matrixPosition.setFromMatrixPosition( this.matrixWorld );
  15604. var distance = raycaster.ray.origin.distanceTo( matrixPosition );
  15605. this.getObjectForDistance( distance ).raycast( raycaster, intersects );
  15606. };
  15607. }() ),
  15608. update: function () {
  15609. var v1 = new Vector3();
  15610. var v2 = new Vector3();
  15611. return function update( camera ) {
  15612. var levels = this.levels;
  15613. if ( levels.length > 1 ) {
  15614. v1.setFromMatrixPosition( camera.matrixWorld );
  15615. v2.setFromMatrixPosition( this.matrixWorld );
  15616. var distance = v1.distanceTo( v2 );
  15617. levels[ 0 ].object.visible = true;
  15618. for ( var i = 1, l = levels.length; i < l; i ++ ) {
  15619. if ( distance >= levels[ i ].distance ) {
  15620. levels[ i - 1 ].object.visible = false;
  15621. levels[ i ].object.visible = true;
  15622. } else {
  15623. break;
  15624. }
  15625. }
  15626. for ( ; i < l; i ++ ) {
  15627. levels[ i ].object.visible = false;
  15628. }
  15629. }
  15630. };
  15631. }(),
  15632. toJSON: function ( meta ) {
  15633. var data = Object3D.prototype.toJSON.call( this, meta );
  15634. data.object.levels = [];
  15635. var levels = this.levels;
  15636. for ( var i = 0, l = levels.length; i < l; i ++ ) {
  15637. var level = levels[ i ];
  15638. data.object.levels.push( {
  15639. object: level.object.uuid,
  15640. distance: level.distance
  15641. } );
  15642. }
  15643. return data;
  15644. }
  15645. } );
  15646. /**
  15647. * @author mikael emtinger / http://gomo.se/
  15648. * @author alteredq / http://alteredqualia.com/
  15649. * @author ikerr / http://verold.com
  15650. */
  15651. function SkinnedMesh( geometry, material ) {
  15652. if ( geometry && geometry.isGeometry ) {
  15653. console.error( 'THREE.SkinnedMesh no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.' );
  15654. }
  15655. Mesh.call( this, geometry, material );
  15656. this.type = 'SkinnedMesh';
  15657. this.bindMode = 'attached';
  15658. this.bindMatrix = new Matrix4();
  15659. this.bindMatrixInverse = new Matrix4();
  15660. }
  15661. SkinnedMesh.prototype = Object.assign( Object.create( Mesh.prototype ), {
  15662. constructor: SkinnedMesh,
  15663. isSkinnedMesh: true,
  15664. bind: function ( skeleton, bindMatrix ) {
  15665. this.skeleton = skeleton;
  15666. if ( bindMatrix === undefined ) {
  15667. this.updateMatrixWorld( true );
  15668. this.skeleton.calculateInverses();
  15669. bindMatrix = this.matrixWorld;
  15670. }
  15671. this.bindMatrix.copy( bindMatrix );
  15672. this.bindMatrixInverse.getInverse( bindMatrix );
  15673. },
  15674. pose: function () {
  15675. this.skeleton.pose();
  15676. },
  15677. normalizeSkinWeights: function () {
  15678. var vector = new Vector4();
  15679. var skinWeight = this.geometry.attributes.skinWeight;
  15680. for ( var i = 0, l = skinWeight.count; i < l; i ++ ) {
  15681. vector.x = skinWeight.getX( i );
  15682. vector.y = skinWeight.getY( i );
  15683. vector.z = skinWeight.getZ( i );
  15684. vector.w = skinWeight.getW( i );
  15685. var scale = 1.0 / vector.manhattanLength();
  15686. if ( scale !== Infinity ) {
  15687. vector.multiplyScalar( scale );
  15688. } else {
  15689. vector.set( 1, 0, 0, 0 ); // do something reasonable
  15690. }
  15691. skinWeight.setXYZW( i, vector.x, vector.y, vector.z, vector.w );
  15692. }
  15693. },
  15694. updateMatrixWorld: function ( force ) {
  15695. Mesh.prototype.updateMatrixWorld.call( this, force );
  15696. if ( this.bindMode === 'attached' ) {
  15697. this.bindMatrixInverse.getInverse( this.matrixWorld );
  15698. } else if ( this.bindMode === 'detached' ) {
  15699. this.bindMatrixInverse.getInverse( this.bindMatrix );
  15700. } else {
  15701. console.warn( 'THREE.SkinnedMesh: Unrecognized bindMode: ' + this.bindMode );
  15702. }
  15703. },
  15704. clone: function () {
  15705. return new this.constructor( this.geometry, this.material ).copy( this );
  15706. }
  15707. } );
  15708. /**
  15709. * @author mikael emtinger / http://gomo.se/
  15710. * @author alteredq / http://alteredqualia.com/
  15711. * @author michael guerrero / http://realitymeltdown.com
  15712. * @author ikerr / http://verold.com
  15713. */
  15714. function Skeleton( bones, boneInverses ) {
  15715. // copy the bone array
  15716. bones = bones || [];
  15717. this.bones = bones.slice( 0 );
  15718. this.boneMatrices = new Float32Array( this.bones.length * 16 );
  15719. // use the supplied bone inverses or calculate the inverses
  15720. if ( boneInverses === undefined ) {
  15721. this.calculateInverses();
  15722. } else {
  15723. if ( this.bones.length === boneInverses.length ) {
  15724. this.boneInverses = boneInverses.slice( 0 );
  15725. } else {
  15726. console.warn( 'THREE.Skeleton boneInverses is the wrong length.' );
  15727. this.boneInverses = [];
  15728. for ( var i = 0, il = this.bones.length; i < il; i ++ ) {
  15729. this.boneInverses.push( new Matrix4() );
  15730. }
  15731. }
  15732. }
  15733. }
  15734. Object.assign( Skeleton.prototype, {
  15735. calculateInverses: function () {
  15736. this.boneInverses = [];
  15737. for ( var i = 0, il = this.bones.length; i < il; i ++ ) {
  15738. var inverse = new Matrix4();
  15739. if ( this.bones[ i ] ) {
  15740. inverse.getInverse( this.bones[ i ].matrixWorld );
  15741. }
  15742. this.boneInverses.push( inverse );
  15743. }
  15744. },
  15745. pose: function () {
  15746. var bone, i, il;
  15747. // recover the bind-time world matrices
  15748. for ( i = 0, il = this.bones.length; i < il; i ++ ) {
  15749. bone = this.bones[ i ];
  15750. if ( bone ) {
  15751. bone.matrixWorld.getInverse( this.boneInverses[ i ] );
  15752. }
  15753. }
  15754. // compute the local matrices, positions, rotations and scales
  15755. for ( i = 0, il = this.bones.length; i < il; i ++ ) {
  15756. bone = this.bones[ i ];
  15757. if ( bone ) {
  15758. if ( bone.parent && bone.parent.isBone ) {
  15759. bone.matrix.getInverse( bone.parent.matrixWorld );
  15760. bone.matrix.multiply( bone.matrixWorld );
  15761. } else {
  15762. bone.matrix.copy( bone.matrixWorld );
  15763. }
  15764. bone.matrix.decompose( bone.position, bone.quaternion, bone.scale );
  15765. }
  15766. }
  15767. },
  15768. update: ( function () {
  15769. var offsetMatrix = new Matrix4();
  15770. var identityMatrix = new Matrix4();
  15771. return function update() {
  15772. var bones = this.bones;
  15773. var boneInverses = this.boneInverses;
  15774. var boneMatrices = this.boneMatrices;
  15775. var boneTexture = this.boneTexture;
  15776. // flatten bone matrices to array
  15777. for ( var i = 0, il = bones.length; i < il; i ++ ) {
  15778. // compute the offset between the current and the original transform
  15779. var matrix = bones[ i ] ? bones[ i ].matrixWorld : identityMatrix;
  15780. offsetMatrix.multiplyMatrices( matrix, boneInverses[ i ] );
  15781. offsetMatrix.toArray( boneMatrices, i * 16 );
  15782. }
  15783. if ( boneTexture !== undefined ) {
  15784. boneTexture.needsUpdate = true;
  15785. }
  15786. };
  15787. } )(),
  15788. clone: function () {
  15789. return new Skeleton( this.bones, this.boneInverses );
  15790. },
  15791. getBoneByName: function ( name ) {
  15792. for ( var i = 0, il = this.bones.length; i < il; i ++ ) {
  15793. var bone = this.bones[ i ];
  15794. if ( bone.name === name ) {
  15795. return bone;
  15796. }
  15797. }
  15798. return undefined;
  15799. }
  15800. } );
  15801. /**
  15802. * @author mikael emtinger / http://gomo.se/
  15803. * @author alteredq / http://alteredqualia.com/
  15804. * @author ikerr / http://verold.com
  15805. */
  15806. function Bone() {
  15807. Object3D.call( this );
  15808. this.type = 'Bone';
  15809. }
  15810. Bone.prototype = Object.assign( Object.create( Object3D.prototype ), {
  15811. constructor: Bone,
  15812. isBone: true
  15813. } );
  15814. /**
  15815. * @author mrdoob / http://mrdoob.com/
  15816. * @author alteredq / http://alteredqualia.com/
  15817. *
  15818. * parameters = {
  15819. * color: <hex>,
  15820. * opacity: <float>,
  15821. *
  15822. * linewidth: <float>,
  15823. * linecap: "round",
  15824. * linejoin: "round"
  15825. * }
  15826. */
  15827. function LineBasicMaterial( parameters ) {
  15828. Material.call( this );
  15829. this.type = 'LineBasicMaterial';
  15830. this.color = new Color( 0xffffff );
  15831. this.linewidth = 1;
  15832. this.linecap = 'round';
  15833. this.linejoin = 'round';
  15834. this.lights = false;
  15835. this.setValues( parameters );
  15836. }
  15837. LineBasicMaterial.prototype = Object.create( Material.prototype );
  15838. LineBasicMaterial.prototype.constructor = LineBasicMaterial;
  15839. LineBasicMaterial.prototype.isLineBasicMaterial = true;
  15840. LineBasicMaterial.prototype.copy = function ( source ) {
  15841. Material.prototype.copy.call( this, source );
  15842. this.color.copy( source.color );
  15843. this.linewidth = source.linewidth;
  15844. this.linecap = source.linecap;
  15845. this.linejoin = source.linejoin;
  15846. return this;
  15847. };
  15848. /**
  15849. * @author mrdoob / http://mrdoob.com/
  15850. */
  15851. function Line( geometry, material, mode ) {
  15852. if ( mode === 1 ) {
  15853. console.error( 'THREE.Line: parameter THREE.LinePieces no longer supported. Use THREE.LineSegments instead.' );
  15854. }
  15855. Object3D.call( this );
  15856. this.type = 'Line';
  15857. this.geometry = geometry !== undefined ? geometry : new BufferGeometry();
  15858. this.material = material !== undefined ? material : new LineBasicMaterial( { color: Math.random() * 0xffffff } );
  15859. }
  15860. Line.prototype = Object.assign( Object.create( Object3D.prototype ), {
  15861. constructor: Line,
  15862. isLine: true,
  15863. computeLineDistances: ( function () {
  15864. var start = new Vector3();
  15865. var end = new Vector3();
  15866. return function computeLineDistances() {
  15867. var geometry = this.geometry;
  15868. if ( geometry.isBufferGeometry ) {
  15869. // we assume non-indexed geometry
  15870. if ( geometry.index === null ) {
  15871. var positionAttribute = geometry.attributes.position;
  15872. var lineDistances = [ 0 ];
  15873. for ( var i = 1, l = positionAttribute.count; i < l; i ++ ) {
  15874. start.fromBufferAttribute( positionAttribute, i - 1 );
  15875. end.fromBufferAttribute( positionAttribute, i );
  15876. lineDistances[ i ] = lineDistances[ i - 1 ];
  15877. lineDistances[ i ] += start.distanceTo( end );
  15878. }
  15879. geometry.addAttribute( 'lineDistance', new Float32BufferAttribute( lineDistances, 1 ) );
  15880. } else {
  15881. console.warn( 'THREE.Line.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.' );
  15882. }
  15883. } else if ( geometry.isGeometry ) {
  15884. var vertices = geometry.vertices;
  15885. var lineDistances = geometry.lineDistances;
  15886. lineDistances[ 0 ] = 0;
  15887. for ( var i = 1, l = vertices.length; i < l; i ++ ) {
  15888. lineDistances[ i ] = lineDistances[ i - 1 ];
  15889. lineDistances[ i ] += vertices[ i - 1 ].distanceTo( vertices[ i ] );
  15890. }
  15891. }
  15892. return this;
  15893. };
  15894. }() ),
  15895. raycast: ( function () {
  15896. var inverseMatrix = new Matrix4();
  15897. var ray = new Ray();
  15898. var sphere = new Sphere();
  15899. return function raycast( raycaster, intersects ) {
  15900. var precision = raycaster.linePrecision;
  15901. var geometry = this.geometry;
  15902. var matrixWorld = this.matrixWorld;
  15903. // Checking boundingSphere distance to ray
  15904. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  15905. sphere.copy( geometry.boundingSphere );
  15906. sphere.applyMatrix4( matrixWorld );
  15907. sphere.radius += precision;
  15908. if ( raycaster.ray.intersectsSphere( sphere ) === false ) return;
  15909. //
  15910. inverseMatrix.getInverse( matrixWorld );
  15911. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  15912. var localPrecision = precision / ( ( this.scale.x + this.scale.y + this.scale.z ) / 3 );
  15913. var localPrecisionSq = localPrecision * localPrecision;
  15914. var vStart = new Vector3();
  15915. var vEnd = new Vector3();
  15916. var interSegment = new Vector3();
  15917. var interRay = new Vector3();
  15918. var step = ( this && this.isLineSegments ) ? 2 : 1;
  15919. if ( geometry.isBufferGeometry ) {
  15920. var index = geometry.index;
  15921. var attributes = geometry.attributes;
  15922. var positions = attributes.position.array;
  15923. if ( index !== null ) {
  15924. var indices = index.array;
  15925. for ( var i = 0, l = indices.length - 1; i < l; i += step ) {
  15926. var a = indices[ i ];
  15927. var b = indices[ i + 1 ];
  15928. vStart.fromArray( positions, a * 3 );
  15929. vEnd.fromArray( positions, b * 3 );
  15930. var distSq = ray.distanceSqToSegment( vStart, vEnd, interRay, interSegment );
  15931. if ( distSq > localPrecisionSq ) continue;
  15932. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  15933. var distance = raycaster.ray.origin.distanceTo( interRay );
  15934. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  15935. intersects.push( {
  15936. distance: distance,
  15937. // What do we want? intersection point on the ray or on the segment??
  15938. // point: raycaster.ray.at( distance ),
  15939. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  15940. index: i,
  15941. face: null,
  15942. faceIndex: null,
  15943. object: this
  15944. } );
  15945. }
  15946. } else {
  15947. for ( var i = 0, l = positions.length / 3 - 1; i < l; i += step ) {
  15948. vStart.fromArray( positions, 3 * i );
  15949. vEnd.fromArray( positions, 3 * i + 3 );
  15950. var distSq = ray.distanceSqToSegment( vStart, vEnd, interRay, interSegment );
  15951. if ( distSq > localPrecisionSq ) continue;
  15952. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  15953. var distance = raycaster.ray.origin.distanceTo( interRay );
  15954. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  15955. intersects.push( {
  15956. distance: distance,
  15957. // What do we want? intersection point on the ray or on the segment??
  15958. // point: raycaster.ray.at( distance ),
  15959. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  15960. index: i,
  15961. face: null,
  15962. faceIndex: null,
  15963. object: this
  15964. } );
  15965. }
  15966. }
  15967. } else if ( geometry.isGeometry ) {
  15968. var vertices = geometry.vertices;
  15969. var nbVertices = vertices.length;
  15970. for ( var i = 0; i < nbVertices - 1; i += step ) {
  15971. var distSq = ray.distanceSqToSegment( vertices[ i ], vertices[ i + 1 ], interRay, interSegment );
  15972. if ( distSq > localPrecisionSq ) continue;
  15973. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  15974. var distance = raycaster.ray.origin.distanceTo( interRay );
  15975. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  15976. intersects.push( {
  15977. distance: distance,
  15978. // What do we want? intersection point on the ray or on the segment??
  15979. // point: raycaster.ray.at( distance ),
  15980. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  15981. index: i,
  15982. face: null,
  15983. faceIndex: null,
  15984. object: this
  15985. } );
  15986. }
  15987. }
  15988. };
  15989. }() ),
  15990. clone: function () {
  15991. return new this.constructor( this.geometry, this.material ).copy( this );
  15992. }
  15993. } );
  15994. /**
  15995. * @author mrdoob / http://mrdoob.com/
  15996. */
  15997. function LineSegments( geometry, material ) {
  15998. Line.call( this, geometry, material );
  15999. this.type = 'LineSegments';
  16000. }
  16001. LineSegments.prototype = Object.assign( Object.create( Line.prototype ), {
  16002. constructor: LineSegments,
  16003. isLineSegments: true,
  16004. computeLineDistances: ( function () {
  16005. var start = new Vector3();
  16006. var end = new Vector3();
  16007. return function computeLineDistances() {
  16008. var geometry = this.geometry;
  16009. if ( geometry.isBufferGeometry ) {
  16010. // we assume non-indexed geometry
  16011. if ( geometry.index === null ) {
  16012. var positionAttribute = geometry.attributes.position;
  16013. var lineDistances = [];
  16014. for ( var i = 0, l = positionAttribute.count; i < l; i += 2 ) {
  16015. start.fromBufferAttribute( positionAttribute, i );
  16016. end.fromBufferAttribute( positionAttribute, i + 1 );
  16017. lineDistances[ i ] = ( i === 0 ) ? 0 : lineDistances[ i - 1 ];
  16018. lineDistances[ i + 1 ] = lineDistances[ i ] + start.distanceTo( end );
  16019. }
  16020. geometry.addAttribute( 'lineDistance', new Float32BufferAttribute( lineDistances, 1 ) );
  16021. } else {
  16022. console.warn( 'THREE.LineSegments.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.' );
  16023. }
  16024. } else if ( geometry.isGeometry ) {
  16025. var vertices = geometry.vertices;
  16026. var lineDistances = geometry.lineDistances;
  16027. for ( var i = 0, l = vertices.length; i < l; i += 2 ) {
  16028. start.copy( vertices[ i ] );
  16029. end.copy( vertices[ i + 1 ] );
  16030. lineDistances[ i ] = ( i === 0 ) ? 0 : lineDistances[ i - 1 ];
  16031. lineDistances[ i + 1 ] = lineDistances[ i ] + start.distanceTo( end );
  16032. }
  16033. }
  16034. return this;
  16035. };
  16036. }() )
  16037. } );
  16038. /**
  16039. * @author mgreter / http://github.com/mgreter
  16040. */
  16041. function LineLoop( geometry, material ) {
  16042. Line.call( this, geometry, material );
  16043. this.type = 'LineLoop';
  16044. }
  16045. LineLoop.prototype = Object.assign( Object.create( Line.prototype ), {
  16046. constructor: LineLoop,
  16047. isLineLoop: true,
  16048. } );
  16049. /**
  16050. * @author mrdoob / http://mrdoob.com/
  16051. * @author alteredq / http://alteredqualia.com/
  16052. *
  16053. * parameters = {
  16054. * color: <hex>,
  16055. * opacity: <float>,
  16056. * map: new THREE.Texture( <Image> ),
  16057. *
  16058. * size: <float>,
  16059. * sizeAttenuation: <bool>
  16060. *
  16061. * morphTargets: <bool>
  16062. * }
  16063. */
  16064. function PointsMaterial( parameters ) {
  16065. Material.call( this );
  16066. this.type = 'PointsMaterial';
  16067. this.color = new Color( 0xffffff );
  16068. this.map = null;
  16069. this.size = 1;
  16070. this.sizeAttenuation = true;
  16071. this.morphTargets = false;
  16072. this.lights = false;
  16073. this.setValues( parameters );
  16074. }
  16075. PointsMaterial.prototype = Object.create( Material.prototype );
  16076. PointsMaterial.prototype.constructor = PointsMaterial;
  16077. PointsMaterial.prototype.isPointsMaterial = true;
  16078. PointsMaterial.prototype.copy = function ( source ) {
  16079. Material.prototype.copy.call( this, source );
  16080. this.color.copy( source.color );
  16081. this.map = source.map;
  16082. this.size = source.size;
  16083. this.sizeAttenuation = source.sizeAttenuation;
  16084. this.morphTargets = source.morphTargets;
  16085. return this;
  16086. };
  16087. /**
  16088. * @author alteredq / http://alteredqualia.com/
  16089. */
  16090. function Points( geometry, material ) {
  16091. Object3D.call( this );
  16092. this.type = 'Points';
  16093. this.geometry = geometry !== undefined ? geometry : new BufferGeometry();
  16094. this.material = material !== undefined ? material : new PointsMaterial( { color: Math.random() * 0xffffff } );
  16095. this.updateMorphTargets();
  16096. }
  16097. Points.prototype = Object.assign( Object.create( Object3D.prototype ), {
  16098. constructor: Points,
  16099. isPoints: true,
  16100. raycast: ( function () {
  16101. var inverseMatrix = new Matrix4();
  16102. var ray = new Ray();
  16103. var sphere = new Sphere();
  16104. return function raycast( raycaster, intersects ) {
  16105. var object = this;
  16106. var geometry = this.geometry;
  16107. var matrixWorld = this.matrixWorld;
  16108. var threshold = raycaster.params.Points.threshold;
  16109. // Checking boundingSphere distance to ray
  16110. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  16111. sphere.copy( geometry.boundingSphere );
  16112. sphere.applyMatrix4( matrixWorld );
  16113. sphere.radius += threshold;
  16114. if ( raycaster.ray.intersectsSphere( sphere ) === false ) return;
  16115. //
  16116. inverseMatrix.getInverse( matrixWorld );
  16117. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  16118. var localThreshold = threshold / ( ( this.scale.x + this.scale.y + this.scale.z ) / 3 );
  16119. var localThresholdSq = localThreshold * localThreshold;
  16120. var position = new Vector3();
  16121. var intersectPoint = new Vector3();
  16122. function testPoint( point, index ) {
  16123. var rayPointDistanceSq = ray.distanceSqToPoint( point );
  16124. if ( rayPointDistanceSq < localThresholdSq ) {
  16125. ray.closestPointToPoint( point, intersectPoint );
  16126. intersectPoint.applyMatrix4( matrixWorld );
  16127. var distance = raycaster.ray.origin.distanceTo( intersectPoint );
  16128. if ( distance < raycaster.near || distance > raycaster.far ) return;
  16129. intersects.push( {
  16130. distance: distance,
  16131. distanceToRay: Math.sqrt( rayPointDistanceSq ),
  16132. point: intersectPoint.clone(),
  16133. index: index,
  16134. face: null,
  16135. object: object
  16136. } );
  16137. }
  16138. }
  16139. if ( geometry.isBufferGeometry ) {
  16140. var index = geometry.index;
  16141. var attributes = geometry.attributes;
  16142. var positions = attributes.position.array;
  16143. if ( index !== null ) {
  16144. var indices = index.array;
  16145. for ( var i = 0, il = indices.length; i < il; i ++ ) {
  16146. var a = indices[ i ];
  16147. position.fromArray( positions, a * 3 );
  16148. testPoint( position, a );
  16149. }
  16150. } else {
  16151. for ( var i = 0, l = positions.length / 3; i < l; i ++ ) {
  16152. position.fromArray( positions, i * 3 );
  16153. testPoint( position, i );
  16154. }
  16155. }
  16156. } else {
  16157. var vertices = geometry.vertices;
  16158. for ( var i = 0, l = vertices.length; i < l; i ++ ) {
  16159. testPoint( vertices[ i ], i );
  16160. }
  16161. }
  16162. };
  16163. }() ),
  16164. updateMorphTargets: function () {
  16165. var geometry = this.geometry;
  16166. var m, ml, name;
  16167. if ( geometry.isBufferGeometry ) {
  16168. var morphAttributes = geometry.morphAttributes;
  16169. var keys = Object.keys( morphAttributes );
  16170. if ( keys.length > 0 ) {
  16171. var morphAttribute = morphAttributes[ keys[ 0 ] ];
  16172. if ( morphAttribute !== undefined ) {
  16173. this.morphTargetInfluences = [];
  16174. this.morphTargetDictionary = {};
  16175. for ( m = 0, ml = morphAttribute.length; m < ml; m ++ ) {
  16176. name = morphAttribute[ m ].name || String( m );
  16177. this.morphTargetInfluences.push( 0 );
  16178. this.morphTargetDictionary[ name ] = m;
  16179. }
  16180. }
  16181. }
  16182. } else {
  16183. var morphTargets = geometry.morphTargets;
  16184. if ( morphTargets !== undefined && morphTargets.length > 0 ) {
  16185. console.error( 'THREE.Points.updateMorphTargets() does not support THREE.Geometry. Use THREE.BufferGeometry instead.' );
  16186. }
  16187. }
  16188. },
  16189. clone: function () {
  16190. return new this.constructor( this.geometry, this.material ).copy( this );
  16191. }
  16192. } );
  16193. /**
  16194. * @author mrdoob / http://mrdoob.com/
  16195. */
  16196. function VideoTexture( video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  16197. Texture.call( this, video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  16198. this.format = format !== undefined ? format : RGBFormat;
  16199. this.minFilter = minFilter !== undefined ? minFilter : LinearFilter;
  16200. this.magFilter = magFilter !== undefined ? magFilter : LinearFilter;
  16201. this.generateMipmaps = false;
  16202. }
  16203. VideoTexture.prototype = Object.assign( Object.create( Texture.prototype ), {
  16204. constructor: VideoTexture,
  16205. isVideoTexture: true,
  16206. update: function () {
  16207. var video = this.image;
  16208. if ( video.readyState >= video.HAVE_CURRENT_DATA ) {
  16209. this.needsUpdate = true;
  16210. }
  16211. }
  16212. } );
  16213. /**
  16214. * @author alteredq / http://alteredqualia.com/
  16215. */
  16216. function CompressedTexture( mipmaps, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, encoding ) {
  16217. Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding );
  16218. this.image = { width: width, height: height };
  16219. this.mipmaps = mipmaps;
  16220. // no flipping for cube textures
  16221. // (also flipping doesn't work for compressed textures )
  16222. this.flipY = false;
  16223. // can't generate mipmaps for compressed textures
  16224. // mips must be embedded in DDS files
  16225. this.generateMipmaps = false;
  16226. }
  16227. CompressedTexture.prototype = Object.create( Texture.prototype );
  16228. CompressedTexture.prototype.constructor = CompressedTexture;
  16229. CompressedTexture.prototype.isCompressedTexture = true;
  16230. /**
  16231. * @author mrdoob / http://mrdoob.com/
  16232. */
  16233. function CanvasTexture( canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  16234. Texture.call( this, canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  16235. this.needsUpdate = true;
  16236. }
  16237. CanvasTexture.prototype = Object.create( Texture.prototype );
  16238. CanvasTexture.prototype.constructor = CanvasTexture;
  16239. CanvasTexture.prototype.isCanvasTexture = true;
  16240. /**
  16241. * @author Matt DesLauriers / @mattdesl
  16242. * @author atix / arthursilber.de
  16243. */
  16244. function DepthTexture( width, height, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, format ) {
  16245. format = format !== undefined ? format : DepthFormat;
  16246. if ( format !== DepthFormat && format !== DepthStencilFormat ) {
  16247. throw new Error( 'DepthTexture format must be either THREE.DepthFormat or THREE.DepthStencilFormat' );
  16248. }
  16249. if ( type === undefined && format === DepthFormat ) type = UnsignedShortType;
  16250. if ( type === undefined && format === DepthStencilFormat ) type = UnsignedInt248Type;
  16251. Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  16252. this.image = { width: width, height: height };
  16253. this.magFilter = magFilter !== undefined ? magFilter : NearestFilter;
  16254. this.minFilter = minFilter !== undefined ? minFilter : NearestFilter;
  16255. this.flipY = false;
  16256. this.generateMipmaps = false;
  16257. }
  16258. DepthTexture.prototype = Object.create( Texture.prototype );
  16259. DepthTexture.prototype.constructor = DepthTexture;
  16260. DepthTexture.prototype.isDepthTexture = true;
  16261. /**
  16262. * @author mrdoob / http://mrdoob.com/
  16263. * @author Mugen87 / https://github.com/Mugen87
  16264. */
  16265. function WireframeGeometry( geometry ) {
  16266. BufferGeometry.call( this );
  16267. this.type = 'WireframeGeometry';
  16268. // buffer
  16269. var vertices = [];
  16270. // helper variables
  16271. var i, j, l, o, ol;
  16272. var edge = [ 0, 0 ], edges = {}, e, edge1, edge2;
  16273. var key, keys = [ 'a', 'b', 'c' ];
  16274. var vertex;
  16275. // different logic for Geometry and BufferGeometry
  16276. if ( geometry && geometry.isGeometry ) {
  16277. // create a data structure that contains all edges without duplicates
  16278. var faces = geometry.faces;
  16279. for ( i = 0, l = faces.length; i < l; i ++ ) {
  16280. var face = faces[ i ];
  16281. for ( j = 0; j < 3; j ++ ) {
  16282. edge1 = face[ keys[ j ] ];
  16283. edge2 = face[ keys[ ( j + 1 ) % 3 ] ];
  16284. edge[ 0 ] = Math.min( edge1, edge2 ); // sorting prevents duplicates
  16285. edge[ 1 ] = Math.max( edge1, edge2 );
  16286. key = edge[ 0 ] + ',' + edge[ 1 ];
  16287. if ( edges[ key ] === undefined ) {
  16288. edges[ key ] = { index1: edge[ 0 ], index2: edge[ 1 ] };
  16289. }
  16290. }
  16291. }
  16292. // generate vertices
  16293. for ( key in edges ) {
  16294. e = edges[ key ];
  16295. vertex = geometry.vertices[ e.index1 ];
  16296. vertices.push( vertex.x, vertex.y, vertex.z );
  16297. vertex = geometry.vertices[ e.index2 ];
  16298. vertices.push( vertex.x, vertex.y, vertex.z );
  16299. }
  16300. } else if ( geometry && geometry.isBufferGeometry ) {
  16301. var position, indices, groups;
  16302. var group, start, count;
  16303. var index1, index2;
  16304. vertex = new Vector3();
  16305. if ( geometry.index !== null ) {
  16306. // indexed BufferGeometry
  16307. position = geometry.attributes.position;
  16308. indices = geometry.index;
  16309. groups = geometry.groups;
  16310. if ( groups.length === 0 ) {
  16311. groups = [ { start: 0, count: indices.count, materialIndex: 0 } ];
  16312. }
  16313. // create a data structure that contains all eges without duplicates
  16314. for ( o = 0, ol = groups.length; o < ol; ++ o ) {
  16315. group = groups[ o ];
  16316. start = group.start;
  16317. count = group.count;
  16318. for ( i = start, l = ( start + count ); i < l; i += 3 ) {
  16319. for ( j = 0; j < 3; j ++ ) {
  16320. edge1 = indices.getX( i + j );
  16321. edge2 = indices.getX( i + ( j + 1 ) % 3 );
  16322. edge[ 0 ] = Math.min( edge1, edge2 ); // sorting prevents duplicates
  16323. edge[ 1 ] = Math.max( edge1, edge2 );
  16324. key = edge[ 0 ] + ',' + edge[ 1 ];
  16325. if ( edges[ key ] === undefined ) {
  16326. edges[ key ] = { index1: edge[ 0 ], index2: edge[ 1 ] };
  16327. }
  16328. }
  16329. }
  16330. }
  16331. // generate vertices
  16332. for ( key in edges ) {
  16333. e = edges[ key ];
  16334. vertex.fromBufferAttribute( position, e.index1 );
  16335. vertices.push( vertex.x, vertex.y, vertex.z );
  16336. vertex.fromBufferAttribute( position, e.index2 );
  16337. vertices.push( vertex.x, vertex.y, vertex.z );
  16338. }
  16339. } else {
  16340. // non-indexed BufferGeometry
  16341. position = geometry.attributes.position;
  16342. for ( i = 0, l = ( position.count / 3 ); i < l; i ++ ) {
  16343. for ( j = 0; j < 3; j ++ ) {
  16344. // three edges per triangle, an edge is represented as (index1, index2)
  16345. // e.g. the first triangle has the following edges: (0,1),(1,2),(2,0)
  16346. index1 = 3 * i + j;
  16347. vertex.fromBufferAttribute( position, index1 );
  16348. vertices.push( vertex.x, vertex.y, vertex.z );
  16349. index2 = 3 * i + ( ( j + 1 ) % 3 );
  16350. vertex.fromBufferAttribute( position, index2 );
  16351. vertices.push( vertex.x, vertex.y, vertex.z );
  16352. }
  16353. }
  16354. }
  16355. }
  16356. // build geometry
  16357. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  16358. }
  16359. WireframeGeometry.prototype = Object.create( BufferGeometry.prototype );
  16360. WireframeGeometry.prototype.constructor = WireframeGeometry;
  16361. /**
  16362. * @author zz85 / https://github.com/zz85
  16363. * @author Mugen87 / https://github.com/Mugen87
  16364. *
  16365. * Parametric Surfaces Geometry
  16366. * based on the brilliant article by @prideout http://prideout.net/blog/?p=44
  16367. */
  16368. // ParametricGeometry
  16369. function ParametricGeometry( func, slices, stacks ) {
  16370. Geometry.call( this );
  16371. this.type = 'ParametricGeometry';
  16372. this.parameters = {
  16373. func: func,
  16374. slices: slices,
  16375. stacks: stacks
  16376. };
  16377. this.fromBufferGeometry( new ParametricBufferGeometry( func, slices, stacks ) );
  16378. this.mergeVertices();
  16379. }
  16380. ParametricGeometry.prototype = Object.create( Geometry.prototype );
  16381. ParametricGeometry.prototype.constructor = ParametricGeometry;
  16382. // ParametricBufferGeometry
  16383. function ParametricBufferGeometry( func, slices, stacks ) {
  16384. BufferGeometry.call( this );
  16385. this.type = 'ParametricBufferGeometry';
  16386. this.parameters = {
  16387. func: func,
  16388. slices: slices,
  16389. stacks: stacks
  16390. };
  16391. // buffers
  16392. var indices = [];
  16393. var vertices = [];
  16394. var normals = [];
  16395. var uvs = [];
  16396. var EPS = 0.00001;
  16397. var normal = new Vector3();
  16398. var p0 = new Vector3(), p1 = new Vector3();
  16399. var pu = new Vector3(), pv = new Vector3();
  16400. var i, j;
  16401. if ( func.length < 3 ) {
  16402. console.error( 'THREE.ParametricGeometry: Function must now modify a Vector3 as third parameter.' );
  16403. }
  16404. // generate vertices, normals and uvs
  16405. var sliceCount = slices + 1;
  16406. for ( i = 0; i <= stacks; i ++ ) {
  16407. var v = i / stacks;
  16408. for ( j = 0; j <= slices; j ++ ) {
  16409. var u = j / slices;
  16410. // vertex
  16411. func( u, v, p0 );
  16412. vertices.push( p0.x, p0.y, p0.z );
  16413. // normal
  16414. // approximate tangent vectors via finite differences
  16415. if ( u - EPS >= 0 ) {
  16416. func( u - EPS, v, p1 );
  16417. pu.subVectors( p0, p1 );
  16418. } else {
  16419. func( u + EPS, v, p1 );
  16420. pu.subVectors( p1, p0 );
  16421. }
  16422. if ( v - EPS >= 0 ) {
  16423. func( u, v - EPS, p1 );
  16424. pv.subVectors( p0, p1 );
  16425. } else {
  16426. func( u, v + EPS, p1 );
  16427. pv.subVectors( p1, p0 );
  16428. }
  16429. // cross product of tangent vectors returns surface normal
  16430. normal.crossVectors( pu, pv ).normalize();
  16431. normals.push( normal.x, normal.y, normal.z );
  16432. // uv
  16433. uvs.push( u, v );
  16434. }
  16435. }
  16436. // generate indices
  16437. for ( i = 0; i < stacks; i ++ ) {
  16438. for ( j = 0; j < slices; j ++ ) {
  16439. var a = i * sliceCount + j;
  16440. var b = i * sliceCount + j + 1;
  16441. var c = ( i + 1 ) * sliceCount + j + 1;
  16442. var d = ( i + 1 ) * sliceCount + j;
  16443. // faces one and two
  16444. indices.push( a, b, d );
  16445. indices.push( b, c, d );
  16446. }
  16447. }
  16448. // build geometry
  16449. this.setIndex( indices );
  16450. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  16451. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  16452. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  16453. }
  16454. ParametricBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  16455. ParametricBufferGeometry.prototype.constructor = ParametricBufferGeometry;
  16456. /**
  16457. * @author clockworkgeek / https://github.com/clockworkgeek
  16458. * @author timothypratley / https://github.com/timothypratley
  16459. * @author WestLangley / http://github.com/WestLangley
  16460. * @author Mugen87 / https://github.com/Mugen87
  16461. */
  16462. // PolyhedronGeometry
  16463. function PolyhedronGeometry( vertices, indices, radius, detail ) {
  16464. Geometry.call( this );
  16465. this.type = 'PolyhedronGeometry';
  16466. this.parameters = {
  16467. vertices: vertices,
  16468. indices: indices,
  16469. radius: radius,
  16470. detail: detail
  16471. };
  16472. this.fromBufferGeometry( new PolyhedronBufferGeometry( vertices, indices, radius, detail ) );
  16473. this.mergeVertices();
  16474. }
  16475. PolyhedronGeometry.prototype = Object.create( Geometry.prototype );
  16476. PolyhedronGeometry.prototype.constructor = PolyhedronGeometry;
  16477. // PolyhedronBufferGeometry
  16478. function PolyhedronBufferGeometry( vertices, indices, radius, detail ) {
  16479. BufferGeometry.call( this );
  16480. this.type = 'PolyhedronBufferGeometry';
  16481. this.parameters = {
  16482. vertices: vertices,
  16483. indices: indices,
  16484. radius: radius,
  16485. detail: detail
  16486. };
  16487. radius = radius || 1;
  16488. detail = detail || 0;
  16489. // default buffer data
  16490. var vertexBuffer = [];
  16491. var uvBuffer = [];
  16492. // the subdivision creates the vertex buffer data
  16493. subdivide( detail );
  16494. // all vertices should lie on a conceptual sphere with a given radius
  16495. appplyRadius( radius );
  16496. // finally, create the uv data
  16497. generateUVs();
  16498. // build non-indexed geometry
  16499. this.addAttribute( 'position', new Float32BufferAttribute( vertexBuffer, 3 ) );
  16500. this.addAttribute( 'normal', new Float32BufferAttribute( vertexBuffer.slice(), 3 ) );
  16501. this.addAttribute( 'uv', new Float32BufferAttribute( uvBuffer, 2 ) );
  16502. if ( detail === 0 ) {
  16503. this.computeVertexNormals(); // flat normals
  16504. } else {
  16505. this.normalizeNormals(); // smooth normals
  16506. }
  16507. // helper functions
  16508. function subdivide( detail ) {
  16509. var a = new Vector3();
  16510. var b = new Vector3();
  16511. var c = new Vector3();
  16512. // iterate over all faces and apply a subdivison with the given detail value
  16513. for ( var i = 0; i < indices.length; i += 3 ) {
  16514. // get the vertices of the face
  16515. getVertexByIndex( indices[ i + 0 ], a );
  16516. getVertexByIndex( indices[ i + 1 ], b );
  16517. getVertexByIndex( indices[ i + 2 ], c );
  16518. // perform subdivision
  16519. subdivideFace( a, b, c, detail );
  16520. }
  16521. }
  16522. function subdivideFace( a, b, c, detail ) {
  16523. var cols = Math.pow( 2, detail );
  16524. // we use this multidimensional array as a data structure for creating the subdivision
  16525. var v = [];
  16526. var i, j;
  16527. // construct all of the vertices for this subdivision
  16528. for ( i = 0; i <= cols; i ++ ) {
  16529. v[ i ] = [];
  16530. var aj = a.clone().lerp( c, i / cols );
  16531. var bj = b.clone().lerp( c, i / cols );
  16532. var rows = cols - i;
  16533. for ( j = 0; j <= rows; j ++ ) {
  16534. if ( j === 0 && i === cols ) {
  16535. v[ i ][ j ] = aj;
  16536. } else {
  16537. v[ i ][ j ] = aj.clone().lerp( bj, j / rows );
  16538. }
  16539. }
  16540. }
  16541. // construct all of the faces
  16542. for ( i = 0; i < cols; i ++ ) {
  16543. for ( j = 0; j < 2 * ( cols - i ) - 1; j ++ ) {
  16544. var k = Math.floor( j / 2 );
  16545. if ( j % 2 === 0 ) {
  16546. pushVertex( v[ i ][ k + 1 ] );
  16547. pushVertex( v[ i + 1 ][ k ] );
  16548. pushVertex( v[ i ][ k ] );
  16549. } else {
  16550. pushVertex( v[ i ][ k + 1 ] );
  16551. pushVertex( v[ i + 1 ][ k + 1 ] );
  16552. pushVertex( v[ i + 1 ][ k ] );
  16553. }
  16554. }
  16555. }
  16556. }
  16557. function appplyRadius( radius ) {
  16558. var vertex = new Vector3();
  16559. // iterate over the entire buffer and apply the radius to each vertex
  16560. for ( var i = 0; i < vertexBuffer.length; i += 3 ) {
  16561. vertex.x = vertexBuffer[ i + 0 ];
  16562. vertex.y = vertexBuffer[ i + 1 ];
  16563. vertex.z = vertexBuffer[ i + 2 ];
  16564. vertex.normalize().multiplyScalar( radius );
  16565. vertexBuffer[ i + 0 ] = vertex.x;
  16566. vertexBuffer[ i + 1 ] = vertex.y;
  16567. vertexBuffer[ i + 2 ] = vertex.z;
  16568. }
  16569. }
  16570. function generateUVs() {
  16571. var vertex = new Vector3();
  16572. for ( var i = 0; i < vertexBuffer.length; i += 3 ) {
  16573. vertex.x = vertexBuffer[ i + 0 ];
  16574. vertex.y = vertexBuffer[ i + 1 ];
  16575. vertex.z = vertexBuffer[ i + 2 ];
  16576. var u = azimuth( vertex ) / 2 / Math.PI + 0.5;
  16577. var v = inclination( vertex ) / Math.PI + 0.5;
  16578. uvBuffer.push( u, 1 - v );
  16579. }
  16580. correctUVs();
  16581. correctSeam();
  16582. }
  16583. function correctSeam() {
  16584. // handle case when face straddles the seam, see #3269
  16585. for ( var i = 0; i < uvBuffer.length; i += 6 ) {
  16586. // uv data of a single face
  16587. var x0 = uvBuffer[ i + 0 ];
  16588. var x1 = uvBuffer[ i + 2 ];
  16589. var x2 = uvBuffer[ i + 4 ];
  16590. var max = Math.max( x0, x1, x2 );
  16591. var min = Math.min( x0, x1, x2 );
  16592. // 0.9 is somewhat arbitrary
  16593. if ( max > 0.9 && min < 0.1 ) {
  16594. if ( x0 < 0.2 ) uvBuffer[ i + 0 ] += 1;
  16595. if ( x1 < 0.2 ) uvBuffer[ i + 2 ] += 1;
  16596. if ( x2 < 0.2 ) uvBuffer[ i + 4 ] += 1;
  16597. }
  16598. }
  16599. }
  16600. function pushVertex( vertex ) {
  16601. vertexBuffer.push( vertex.x, vertex.y, vertex.z );
  16602. }
  16603. function getVertexByIndex( index, vertex ) {
  16604. var stride = index * 3;
  16605. vertex.x = vertices[ stride + 0 ];
  16606. vertex.y = vertices[ stride + 1 ];
  16607. vertex.z = vertices[ stride + 2 ];
  16608. }
  16609. function correctUVs() {
  16610. var a = new Vector3();
  16611. var b = new Vector3();
  16612. var c = new Vector3();
  16613. var centroid = new Vector3();
  16614. var uvA = new Vector2();
  16615. var uvB = new Vector2();
  16616. var uvC = new Vector2();
  16617. for ( var i = 0, j = 0; i < vertexBuffer.length; i += 9, j += 6 ) {
  16618. a.set( vertexBuffer[ i + 0 ], vertexBuffer[ i + 1 ], vertexBuffer[ i + 2 ] );
  16619. b.set( vertexBuffer[ i + 3 ], vertexBuffer[ i + 4 ], vertexBuffer[ i + 5 ] );
  16620. c.set( vertexBuffer[ i + 6 ], vertexBuffer[ i + 7 ], vertexBuffer[ i + 8 ] );
  16621. uvA.set( uvBuffer[ j + 0 ], uvBuffer[ j + 1 ] );
  16622. uvB.set( uvBuffer[ j + 2 ], uvBuffer[ j + 3 ] );
  16623. uvC.set( uvBuffer[ j + 4 ], uvBuffer[ j + 5 ] );
  16624. centroid.copy( a ).add( b ).add( c ).divideScalar( 3 );
  16625. var azi = azimuth( centroid );
  16626. correctUV( uvA, j + 0, a, azi );
  16627. correctUV( uvB, j + 2, b, azi );
  16628. correctUV( uvC, j + 4, c, azi );
  16629. }
  16630. }
  16631. function correctUV( uv, stride, vector, azimuth ) {
  16632. if ( ( azimuth < 0 ) && ( uv.x === 1 ) ) {
  16633. uvBuffer[ stride ] = uv.x - 1;
  16634. }
  16635. if ( ( vector.x === 0 ) && ( vector.z === 0 ) ) {
  16636. uvBuffer[ stride ] = azimuth / 2 / Math.PI + 0.5;
  16637. }
  16638. }
  16639. // Angle around the Y axis, counter-clockwise when looking from above.
  16640. function azimuth( vector ) {
  16641. return Math.atan2( vector.z, - vector.x );
  16642. }
  16643. // Angle above the XZ plane.
  16644. function inclination( vector ) {
  16645. return Math.atan2( - vector.y, Math.sqrt( ( vector.x * vector.x ) + ( vector.z * vector.z ) ) );
  16646. }
  16647. }
  16648. PolyhedronBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  16649. PolyhedronBufferGeometry.prototype.constructor = PolyhedronBufferGeometry;
  16650. /**
  16651. * @author timothypratley / https://github.com/timothypratley
  16652. * @author Mugen87 / https://github.com/Mugen87
  16653. */
  16654. // TetrahedronGeometry
  16655. function TetrahedronGeometry( radius, detail ) {
  16656. Geometry.call( this );
  16657. this.type = 'TetrahedronGeometry';
  16658. this.parameters = {
  16659. radius: radius,
  16660. detail: detail
  16661. };
  16662. this.fromBufferGeometry( new TetrahedronBufferGeometry( radius, detail ) );
  16663. this.mergeVertices();
  16664. }
  16665. TetrahedronGeometry.prototype = Object.create( Geometry.prototype );
  16666. TetrahedronGeometry.prototype.constructor = TetrahedronGeometry;
  16667. // TetrahedronBufferGeometry
  16668. function TetrahedronBufferGeometry( radius, detail ) {
  16669. var vertices = [
  16670. 1, 1, 1, - 1, - 1, 1, - 1, 1, - 1, 1, - 1, - 1
  16671. ];
  16672. var indices = [
  16673. 2, 1, 0, 0, 3, 2, 1, 3, 0, 2, 3, 1
  16674. ];
  16675. PolyhedronBufferGeometry.call( this, vertices, indices, radius, detail );
  16676. this.type = 'TetrahedronBufferGeometry';
  16677. this.parameters = {
  16678. radius: radius,
  16679. detail: detail
  16680. };
  16681. }
  16682. TetrahedronBufferGeometry.prototype = Object.create( PolyhedronBufferGeometry.prototype );
  16683. TetrahedronBufferGeometry.prototype.constructor = TetrahedronBufferGeometry;
  16684. /**
  16685. * @author timothypratley / https://github.com/timothypratley
  16686. * @author Mugen87 / https://github.com/Mugen87
  16687. */
  16688. // OctahedronGeometry
  16689. function OctahedronGeometry( radius, detail ) {
  16690. Geometry.call( this );
  16691. this.type = 'OctahedronGeometry';
  16692. this.parameters = {
  16693. radius: radius,
  16694. detail: detail
  16695. };
  16696. this.fromBufferGeometry( new OctahedronBufferGeometry( radius, detail ) );
  16697. this.mergeVertices();
  16698. }
  16699. OctahedronGeometry.prototype = Object.create( Geometry.prototype );
  16700. OctahedronGeometry.prototype.constructor = OctahedronGeometry;
  16701. // OctahedronBufferGeometry
  16702. function OctahedronBufferGeometry( radius, detail ) {
  16703. var vertices = [
  16704. 1, 0, 0, - 1, 0, 0, 0, 1, 0,
  16705. 0, - 1, 0, 0, 0, 1, 0, 0, - 1
  16706. ];
  16707. var indices = [
  16708. 0, 2, 4, 0, 4, 3, 0, 3, 5,
  16709. 0, 5, 2, 1, 2, 5, 1, 5, 3,
  16710. 1, 3, 4, 1, 4, 2
  16711. ];
  16712. PolyhedronBufferGeometry.call( this, vertices, indices, radius, detail );
  16713. this.type = 'OctahedronBufferGeometry';
  16714. this.parameters = {
  16715. radius: radius,
  16716. detail: detail
  16717. };
  16718. }
  16719. OctahedronBufferGeometry.prototype = Object.create( PolyhedronBufferGeometry.prototype );
  16720. OctahedronBufferGeometry.prototype.constructor = OctahedronBufferGeometry;
  16721. /**
  16722. * @author timothypratley / https://github.com/timothypratley
  16723. * @author Mugen87 / https://github.com/Mugen87
  16724. */
  16725. // IcosahedronGeometry
  16726. function IcosahedronGeometry( radius, detail ) {
  16727. Geometry.call( this );
  16728. this.type = 'IcosahedronGeometry';
  16729. this.parameters = {
  16730. radius: radius,
  16731. detail: detail
  16732. };
  16733. this.fromBufferGeometry( new IcosahedronBufferGeometry( radius, detail ) );
  16734. this.mergeVertices();
  16735. }
  16736. IcosahedronGeometry.prototype = Object.create( Geometry.prototype );
  16737. IcosahedronGeometry.prototype.constructor = IcosahedronGeometry;
  16738. // IcosahedronBufferGeometry
  16739. function IcosahedronBufferGeometry( radius, detail ) {
  16740. var t = ( 1 + Math.sqrt( 5 ) ) / 2;
  16741. var vertices = [
  16742. - 1, t, 0, 1, t, 0, - 1, - t, 0, 1, - t, 0,
  16743. 0, - 1, t, 0, 1, t, 0, - 1, - t, 0, 1, - t,
  16744. t, 0, - 1, t, 0, 1, - t, 0, - 1, - t, 0, 1
  16745. ];
  16746. var indices = [
  16747. 0, 11, 5, 0, 5, 1, 0, 1, 7, 0, 7, 10, 0, 10, 11,
  16748. 1, 5, 9, 5, 11, 4, 11, 10, 2, 10, 7, 6, 7, 1, 8,
  16749. 3, 9, 4, 3, 4, 2, 3, 2, 6, 3, 6, 8, 3, 8, 9,
  16750. 4, 9, 5, 2, 4, 11, 6, 2, 10, 8, 6, 7, 9, 8, 1
  16751. ];
  16752. PolyhedronBufferGeometry.call( this, vertices, indices, radius, detail );
  16753. this.type = 'IcosahedronBufferGeometry';
  16754. this.parameters = {
  16755. radius: radius,
  16756. detail: detail
  16757. };
  16758. }
  16759. IcosahedronBufferGeometry.prototype = Object.create( PolyhedronBufferGeometry.prototype );
  16760. IcosahedronBufferGeometry.prototype.constructor = IcosahedronBufferGeometry;
  16761. /**
  16762. * @author Abe Pazos / https://hamoid.com
  16763. * @author Mugen87 / https://github.com/Mugen87
  16764. */
  16765. // DodecahedronGeometry
  16766. function DodecahedronGeometry( radius, detail ) {
  16767. Geometry.call( this );
  16768. this.type = 'DodecahedronGeometry';
  16769. this.parameters = {
  16770. radius: radius,
  16771. detail: detail
  16772. };
  16773. this.fromBufferGeometry( new DodecahedronBufferGeometry( radius, detail ) );
  16774. this.mergeVertices();
  16775. }
  16776. DodecahedronGeometry.prototype = Object.create( Geometry.prototype );
  16777. DodecahedronGeometry.prototype.constructor = DodecahedronGeometry;
  16778. // DodecahedronBufferGeometry
  16779. function DodecahedronBufferGeometry( radius, detail ) {
  16780. var t = ( 1 + Math.sqrt( 5 ) ) / 2;
  16781. var r = 1 / t;
  16782. var vertices = [
  16783. // (±1, ±1, ±1)
  16784. - 1, - 1, - 1, - 1, - 1, 1,
  16785. - 1, 1, - 1, - 1, 1, 1,
  16786. 1, - 1, - 1, 1, - 1, 1,
  16787. 1, 1, - 1, 1, 1, 1,
  16788. // (0, ±1/φ, ±φ)
  16789. 0, - r, - t, 0, - r, t,
  16790. 0, r, - t, 0, r, t,
  16791. // (±1/φ, ±φ, 0)
  16792. - r, - t, 0, - r, t, 0,
  16793. r, - t, 0, r, t, 0,
  16794. // (±φ, 0, ±1/φ)
  16795. - t, 0, - r, t, 0, - r,
  16796. - t, 0, r, t, 0, r
  16797. ];
  16798. var indices = [
  16799. 3, 11, 7, 3, 7, 15, 3, 15, 13,
  16800. 7, 19, 17, 7, 17, 6, 7, 6, 15,
  16801. 17, 4, 8, 17, 8, 10, 17, 10, 6,
  16802. 8, 0, 16, 8, 16, 2, 8, 2, 10,
  16803. 0, 12, 1, 0, 1, 18, 0, 18, 16,
  16804. 6, 10, 2, 6, 2, 13, 6, 13, 15,
  16805. 2, 16, 18, 2, 18, 3, 2, 3, 13,
  16806. 18, 1, 9, 18, 9, 11, 18, 11, 3,
  16807. 4, 14, 12, 4, 12, 0, 4, 0, 8,
  16808. 11, 9, 5, 11, 5, 19, 11, 19, 7,
  16809. 19, 5, 14, 19, 14, 4, 19, 4, 17,
  16810. 1, 12, 14, 1, 14, 5, 1, 5, 9
  16811. ];
  16812. PolyhedronBufferGeometry.call( this, vertices, indices, radius, detail );
  16813. this.type = 'DodecahedronBufferGeometry';
  16814. this.parameters = {
  16815. radius: radius,
  16816. detail: detail
  16817. };
  16818. }
  16819. DodecahedronBufferGeometry.prototype = Object.create( PolyhedronBufferGeometry.prototype );
  16820. DodecahedronBufferGeometry.prototype.constructor = DodecahedronBufferGeometry;
  16821. /**
  16822. * @author oosmoxiecode / https://github.com/oosmoxiecode
  16823. * @author WestLangley / https://github.com/WestLangley
  16824. * @author zz85 / https://github.com/zz85
  16825. * @author miningold / https://github.com/miningold
  16826. * @author jonobr1 / https://github.com/jonobr1
  16827. * @author Mugen87 / https://github.com/Mugen87
  16828. *
  16829. */
  16830. // TubeGeometry
  16831. function TubeGeometry( path, tubularSegments, radius, radialSegments, closed, taper ) {
  16832. Geometry.call( this );
  16833. this.type = 'TubeGeometry';
  16834. this.parameters = {
  16835. path: path,
  16836. tubularSegments: tubularSegments,
  16837. radius: radius,
  16838. radialSegments: radialSegments,
  16839. closed: closed
  16840. };
  16841. if ( taper !== undefined ) console.warn( 'THREE.TubeGeometry: taper has been removed.' );
  16842. var bufferGeometry = new TubeBufferGeometry( path, tubularSegments, radius, radialSegments, closed );
  16843. // expose internals
  16844. this.tangents = bufferGeometry.tangents;
  16845. this.normals = bufferGeometry.normals;
  16846. this.binormals = bufferGeometry.binormals;
  16847. // create geometry
  16848. this.fromBufferGeometry( bufferGeometry );
  16849. this.mergeVertices();
  16850. }
  16851. TubeGeometry.prototype = Object.create( Geometry.prototype );
  16852. TubeGeometry.prototype.constructor = TubeGeometry;
  16853. // TubeBufferGeometry
  16854. function TubeBufferGeometry( path, tubularSegments, radius, radialSegments, closed ) {
  16855. BufferGeometry.call( this );
  16856. this.type = 'TubeBufferGeometry';
  16857. this.parameters = {
  16858. path: path,
  16859. tubularSegments: tubularSegments,
  16860. radius: radius,
  16861. radialSegments: radialSegments,
  16862. closed: closed
  16863. };
  16864. tubularSegments = tubularSegments || 64;
  16865. radius = radius || 1;
  16866. radialSegments = radialSegments || 8;
  16867. closed = closed || false;
  16868. var frames = path.computeFrenetFrames( tubularSegments, closed );
  16869. // expose internals
  16870. this.tangents = frames.tangents;
  16871. this.normals = frames.normals;
  16872. this.binormals = frames.binormals;
  16873. // helper variables
  16874. var vertex = new Vector3();
  16875. var normal = new Vector3();
  16876. var uv = new Vector2();
  16877. var P = new Vector3();
  16878. var i, j;
  16879. // buffer
  16880. var vertices = [];
  16881. var normals = [];
  16882. var uvs = [];
  16883. var indices = [];
  16884. // create buffer data
  16885. generateBufferData();
  16886. // build geometry
  16887. this.setIndex( indices );
  16888. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  16889. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  16890. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  16891. // functions
  16892. function generateBufferData() {
  16893. for ( i = 0; i < tubularSegments; i ++ ) {
  16894. generateSegment( i );
  16895. }
  16896. // if the geometry is not closed, generate the last row of vertices and normals
  16897. // at the regular position on the given path
  16898. //
  16899. // if the geometry is closed, duplicate the first row of vertices and normals (uvs will differ)
  16900. generateSegment( ( closed === false ) ? tubularSegments : 0 );
  16901. // uvs are generated in a separate function.
  16902. // this makes it easy compute correct values for closed geometries
  16903. generateUVs();
  16904. // finally create faces
  16905. generateIndices();
  16906. }
  16907. function generateSegment( i ) {
  16908. // we use getPointAt to sample evenly distributed points from the given path
  16909. P = path.getPointAt( i / tubularSegments, P );
  16910. // retrieve corresponding normal and binormal
  16911. var N = frames.normals[ i ];
  16912. var B = frames.binormals[ i ];
  16913. // generate normals and vertices for the current segment
  16914. for ( j = 0; j <= radialSegments; j ++ ) {
  16915. var v = j / radialSegments * Math.PI * 2;
  16916. var sin = Math.sin( v );
  16917. var cos = - Math.cos( v );
  16918. // normal
  16919. normal.x = ( cos * N.x + sin * B.x );
  16920. normal.y = ( cos * N.y + sin * B.y );
  16921. normal.z = ( cos * N.z + sin * B.z );
  16922. normal.normalize();
  16923. normals.push( normal.x, normal.y, normal.z );
  16924. // vertex
  16925. vertex.x = P.x + radius * normal.x;
  16926. vertex.y = P.y + radius * normal.y;
  16927. vertex.z = P.z + radius * normal.z;
  16928. vertices.push( vertex.x, vertex.y, vertex.z );
  16929. }
  16930. }
  16931. function generateIndices() {
  16932. for ( j = 1; j <= tubularSegments; j ++ ) {
  16933. for ( i = 1; i <= radialSegments; i ++ ) {
  16934. var a = ( radialSegments + 1 ) * ( j - 1 ) + ( i - 1 );
  16935. var b = ( radialSegments + 1 ) * j + ( i - 1 );
  16936. var c = ( radialSegments + 1 ) * j + i;
  16937. var d = ( radialSegments + 1 ) * ( j - 1 ) + i;
  16938. // faces
  16939. indices.push( a, b, d );
  16940. indices.push( b, c, d );
  16941. }
  16942. }
  16943. }
  16944. function generateUVs() {
  16945. for ( i = 0; i <= tubularSegments; i ++ ) {
  16946. for ( j = 0; j <= radialSegments; j ++ ) {
  16947. uv.x = i / tubularSegments;
  16948. uv.y = j / radialSegments;
  16949. uvs.push( uv.x, uv.y );
  16950. }
  16951. }
  16952. }
  16953. }
  16954. TubeBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  16955. TubeBufferGeometry.prototype.constructor = TubeBufferGeometry;
  16956. TubeBufferGeometry.prototype.toJSON = function () {
  16957. var data = BufferGeometry.prototype.toJSON.call( this );
  16958. data.path = this.parameters.path.toJSON();
  16959. return data;
  16960. };
  16961. /**
  16962. * @author oosmoxiecode
  16963. * @author Mugen87 / https://github.com/Mugen87
  16964. *
  16965. * based on http://www.blackpawn.com/texts/pqtorus/
  16966. */
  16967. // TorusKnotGeometry
  16968. function TorusKnotGeometry( radius, tube, tubularSegments, radialSegments, p, q, heightScale ) {
  16969. Geometry.call( this );
  16970. this.type = 'TorusKnotGeometry';
  16971. this.parameters = {
  16972. radius: radius,
  16973. tube: tube,
  16974. tubularSegments: tubularSegments,
  16975. radialSegments: radialSegments,
  16976. p: p,
  16977. q: q
  16978. };
  16979. if ( heightScale !== undefined ) console.warn( 'THREE.TorusKnotGeometry: heightScale has been deprecated. Use .scale( x, y, z ) instead.' );
  16980. this.fromBufferGeometry( new TorusKnotBufferGeometry( radius, tube, tubularSegments, radialSegments, p, q ) );
  16981. this.mergeVertices();
  16982. }
  16983. TorusKnotGeometry.prototype = Object.create( Geometry.prototype );
  16984. TorusKnotGeometry.prototype.constructor = TorusKnotGeometry;
  16985. // TorusKnotBufferGeometry
  16986. function TorusKnotBufferGeometry( radius, tube, tubularSegments, radialSegments, p, q ) {
  16987. BufferGeometry.call( this );
  16988. this.type = 'TorusKnotBufferGeometry';
  16989. this.parameters = {
  16990. radius: radius,
  16991. tube: tube,
  16992. tubularSegments: tubularSegments,
  16993. radialSegments: radialSegments,
  16994. p: p,
  16995. q: q
  16996. };
  16997. radius = radius || 1;
  16998. tube = tube || 0.4;
  16999. tubularSegments = Math.floor( tubularSegments ) || 64;
  17000. radialSegments = Math.floor( radialSegments ) || 8;
  17001. p = p || 2;
  17002. q = q || 3;
  17003. // buffers
  17004. var indices = [];
  17005. var vertices = [];
  17006. var normals = [];
  17007. var uvs = [];
  17008. // helper variables
  17009. var i, j;
  17010. var vertex = new Vector3();
  17011. var normal = new Vector3();
  17012. var P1 = new Vector3();
  17013. var P2 = new Vector3();
  17014. var B = new Vector3();
  17015. var T = new Vector3();
  17016. var N = new Vector3();
  17017. // generate vertices, normals and uvs
  17018. for ( i = 0; i <= tubularSegments; ++ i ) {
  17019. // the radian "u" is used to calculate the position on the torus curve of the current tubular segement
  17020. var u = i / tubularSegments * p * Math.PI * 2;
  17021. // now we calculate two points. P1 is our current position on the curve, P2 is a little farther ahead.
  17022. // these points are used to create a special "coordinate space", which is necessary to calculate the correct vertex positions
  17023. calculatePositionOnCurve( u, p, q, radius, P1 );
  17024. calculatePositionOnCurve( u + 0.01, p, q, radius, P2 );
  17025. // calculate orthonormal basis
  17026. T.subVectors( P2, P1 );
  17027. N.addVectors( P2, P1 );
  17028. B.crossVectors( T, N );
  17029. N.crossVectors( B, T );
  17030. // normalize B, N. T can be ignored, we don't use it
  17031. B.normalize();
  17032. N.normalize();
  17033. for ( j = 0; j <= radialSegments; ++ j ) {
  17034. // now calculate the vertices. they are nothing more than an extrusion of the torus curve.
  17035. // because we extrude a shape in the xy-plane, there is no need to calculate a z-value.
  17036. var v = j / radialSegments * Math.PI * 2;
  17037. var cx = - tube * Math.cos( v );
  17038. var cy = tube * Math.sin( v );
  17039. // now calculate the final vertex position.
  17040. // first we orient the extrusion with our basis vectos, then we add it to the current position on the curve
  17041. vertex.x = P1.x + ( cx * N.x + cy * B.x );
  17042. vertex.y = P1.y + ( cx * N.y + cy * B.y );
  17043. vertex.z = P1.z + ( cx * N.z + cy * B.z );
  17044. vertices.push( vertex.x, vertex.y, vertex.z );
  17045. // normal (P1 is always the center/origin of the extrusion, thus we can use it to calculate the normal)
  17046. normal.subVectors( vertex, P1 ).normalize();
  17047. normals.push( normal.x, normal.y, normal.z );
  17048. // uv
  17049. uvs.push( i / tubularSegments );
  17050. uvs.push( j / radialSegments );
  17051. }
  17052. }
  17053. // generate indices
  17054. for ( j = 1; j <= tubularSegments; j ++ ) {
  17055. for ( i = 1; i <= radialSegments; i ++ ) {
  17056. // indices
  17057. var a = ( radialSegments + 1 ) * ( j - 1 ) + ( i - 1 );
  17058. var b = ( radialSegments + 1 ) * j + ( i - 1 );
  17059. var c = ( radialSegments + 1 ) * j + i;
  17060. var d = ( radialSegments + 1 ) * ( j - 1 ) + i;
  17061. // faces
  17062. indices.push( a, b, d );
  17063. indices.push( b, c, d );
  17064. }
  17065. }
  17066. // build geometry
  17067. this.setIndex( indices );
  17068. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  17069. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  17070. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  17071. // this function calculates the current position on the torus curve
  17072. function calculatePositionOnCurve( u, p, q, radius, position ) {
  17073. var cu = Math.cos( u );
  17074. var su = Math.sin( u );
  17075. var quOverP = q / p * u;
  17076. var cs = Math.cos( quOverP );
  17077. position.x = radius * ( 2 + cs ) * 0.5 * cu;
  17078. position.y = radius * ( 2 + cs ) * su * 0.5;
  17079. position.z = radius * Math.sin( quOverP ) * 0.5;
  17080. }
  17081. }
  17082. TorusKnotBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  17083. TorusKnotBufferGeometry.prototype.constructor = TorusKnotBufferGeometry;
  17084. /**
  17085. * @author oosmoxiecode
  17086. * @author mrdoob / http://mrdoob.com/
  17087. * @author Mugen87 / https://github.com/Mugen87
  17088. */
  17089. // TorusGeometry
  17090. function TorusGeometry( radius, tube, radialSegments, tubularSegments, arc ) {
  17091. Geometry.call( this );
  17092. this.type = 'TorusGeometry';
  17093. this.parameters = {
  17094. radius: radius,
  17095. tube: tube,
  17096. radialSegments: radialSegments,
  17097. tubularSegments: tubularSegments,
  17098. arc: arc
  17099. };
  17100. this.fromBufferGeometry( new TorusBufferGeometry( radius, tube, radialSegments, tubularSegments, arc ) );
  17101. this.mergeVertices();
  17102. }
  17103. TorusGeometry.prototype = Object.create( Geometry.prototype );
  17104. TorusGeometry.prototype.constructor = TorusGeometry;
  17105. // TorusBufferGeometry
  17106. function TorusBufferGeometry( radius, tube, radialSegments, tubularSegments, arc ) {
  17107. BufferGeometry.call( this );
  17108. this.type = 'TorusBufferGeometry';
  17109. this.parameters = {
  17110. radius: radius,
  17111. tube: tube,
  17112. radialSegments: radialSegments,
  17113. tubularSegments: tubularSegments,
  17114. arc: arc
  17115. };
  17116. radius = radius || 1;
  17117. tube = tube || 0.4;
  17118. radialSegments = Math.floor( radialSegments ) || 8;
  17119. tubularSegments = Math.floor( tubularSegments ) || 6;
  17120. arc = arc || Math.PI * 2;
  17121. // buffers
  17122. var indices = [];
  17123. var vertices = [];
  17124. var normals = [];
  17125. var uvs = [];
  17126. // helper variables
  17127. var center = new Vector3();
  17128. var vertex = new Vector3();
  17129. var normal = new Vector3();
  17130. var j, i;
  17131. // generate vertices, normals and uvs
  17132. for ( j = 0; j <= radialSegments; j ++ ) {
  17133. for ( i = 0; i <= tubularSegments; i ++ ) {
  17134. var u = i / tubularSegments * arc;
  17135. var v = j / radialSegments * Math.PI * 2;
  17136. // vertex
  17137. vertex.x = ( radius + tube * Math.cos( v ) ) * Math.cos( u );
  17138. vertex.y = ( radius + tube * Math.cos( v ) ) * Math.sin( u );
  17139. vertex.z = tube * Math.sin( v );
  17140. vertices.push( vertex.x, vertex.y, vertex.z );
  17141. // normal
  17142. center.x = radius * Math.cos( u );
  17143. center.y = radius * Math.sin( u );
  17144. normal.subVectors( vertex, center ).normalize();
  17145. normals.push( normal.x, normal.y, normal.z );
  17146. // uv
  17147. uvs.push( i / tubularSegments );
  17148. uvs.push( j / radialSegments );
  17149. }
  17150. }
  17151. // generate indices
  17152. for ( j = 1; j <= radialSegments; j ++ ) {
  17153. for ( i = 1; i <= tubularSegments; i ++ ) {
  17154. // indices
  17155. var a = ( tubularSegments + 1 ) * j + i - 1;
  17156. var b = ( tubularSegments + 1 ) * ( j - 1 ) + i - 1;
  17157. var c = ( tubularSegments + 1 ) * ( j - 1 ) + i;
  17158. var d = ( tubularSegments + 1 ) * j + i;
  17159. // faces
  17160. indices.push( a, b, d );
  17161. indices.push( b, c, d );
  17162. }
  17163. }
  17164. // build geometry
  17165. this.setIndex( indices );
  17166. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  17167. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  17168. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  17169. }
  17170. TorusBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  17171. TorusBufferGeometry.prototype.constructor = TorusBufferGeometry;
  17172. /**
  17173. * @author Mugen87 / https://github.com/Mugen87
  17174. * Port from https://github.com/mapbox/earcut (v2.1.5)
  17175. */
  17176. var Earcut = {
  17177. triangulate: function ( data, holeIndices, dim ) {
  17178. dim = dim || 2;
  17179. var hasHoles = holeIndices && holeIndices.length,
  17180. outerLen = hasHoles ? holeIndices[ 0 ] * dim : data.length,
  17181. outerNode = linkedList( data, 0, outerLen, dim, true ),
  17182. triangles = [];
  17183. if ( ! outerNode || outerNode.next === outerNode.prev ) return triangles;
  17184. var minX, minY, maxX, maxY, x, y, invSize;
  17185. if ( hasHoles ) outerNode = eliminateHoles( data, holeIndices, outerNode, dim );
  17186. // if the shape is not too simple, we'll use z-order curve hash later; calculate polygon bbox
  17187. if ( data.length > 80 * dim ) {
  17188. minX = maxX = data[ 0 ];
  17189. minY = maxY = data[ 1 ];
  17190. for ( var i = dim; i < outerLen; i += dim ) {
  17191. x = data[ i ];
  17192. y = data[ i + 1 ];
  17193. if ( x < minX ) minX = x;
  17194. if ( y < minY ) minY = y;
  17195. if ( x > maxX ) maxX = x;
  17196. if ( y > maxY ) maxY = y;
  17197. }
  17198. // minX, minY and invSize are later used to transform coords into integers for z-order calculation
  17199. invSize = Math.max( maxX - minX, maxY - minY );
  17200. invSize = invSize !== 0 ? 1 / invSize : 0;
  17201. }
  17202. earcutLinked( outerNode, triangles, dim, minX, minY, invSize );
  17203. return triangles;
  17204. }
  17205. };
  17206. // create a circular doubly linked list from polygon points in the specified winding order
  17207. function linkedList( data, start, end, dim, clockwise ) {
  17208. var i, last;
  17209. if ( clockwise === ( signedArea( data, start, end, dim ) > 0 ) ) {
  17210. for ( i = start; i < end; i += dim ) last = insertNode( i, data[ i ], data[ i + 1 ], last );
  17211. } else {
  17212. for ( i = end - dim; i >= start; i -= dim ) last = insertNode( i, data[ i ], data[ i + 1 ], last );
  17213. }
  17214. if ( last && equals( last, last.next ) ) {
  17215. removeNode( last );
  17216. last = last.next;
  17217. }
  17218. return last;
  17219. }
  17220. // eliminate colinear or duplicate points
  17221. function filterPoints( start, end ) {
  17222. if ( ! start ) return start;
  17223. if ( ! end ) end = start;
  17224. var p = start,
  17225. again;
  17226. do {
  17227. again = false;
  17228. if ( ! p.steiner && ( equals( p, p.next ) || area( p.prev, p, p.next ) === 0 ) ) {
  17229. removeNode( p );
  17230. p = end = p.prev;
  17231. if ( p === p.next ) break;
  17232. again = true;
  17233. } else {
  17234. p = p.next;
  17235. }
  17236. } while ( again || p !== end );
  17237. return end;
  17238. }
  17239. // main ear slicing loop which triangulates a polygon (given as a linked list)
  17240. function earcutLinked( ear, triangles, dim, minX, minY, invSize, pass ) {
  17241. if ( ! ear ) return;
  17242. // interlink polygon nodes in z-order
  17243. if ( ! pass && invSize ) indexCurve( ear, minX, minY, invSize );
  17244. var stop = ear,
  17245. prev, next;
  17246. // iterate through ears, slicing them one by one
  17247. while ( ear.prev !== ear.next ) {
  17248. prev = ear.prev;
  17249. next = ear.next;
  17250. if ( invSize ? isEarHashed( ear, minX, minY, invSize ) : isEar( ear ) ) {
  17251. // cut off the triangle
  17252. triangles.push( prev.i / dim );
  17253. triangles.push( ear.i / dim );
  17254. triangles.push( next.i / dim );
  17255. removeNode( ear );
  17256. // skipping the next vertex leads to less sliver triangles
  17257. ear = next.next;
  17258. stop = next.next;
  17259. continue;
  17260. }
  17261. ear = next;
  17262. // if we looped through the whole remaining polygon and can't find any more ears
  17263. if ( ear === stop ) {
  17264. // try filtering points and slicing again
  17265. if ( ! pass ) {
  17266. earcutLinked( filterPoints( ear ), triangles, dim, minX, minY, invSize, 1 );
  17267. // if this didn't work, try curing all small self-intersections locally
  17268. } else if ( pass === 1 ) {
  17269. ear = cureLocalIntersections( ear, triangles, dim );
  17270. earcutLinked( ear, triangles, dim, minX, minY, invSize, 2 );
  17271. // as a last resort, try splitting the remaining polygon into two
  17272. } else if ( pass === 2 ) {
  17273. splitEarcut( ear, triangles, dim, minX, minY, invSize );
  17274. }
  17275. break;
  17276. }
  17277. }
  17278. }
  17279. // check whether a polygon node forms a valid ear with adjacent nodes
  17280. function isEar( ear ) {
  17281. var a = ear.prev,
  17282. b = ear,
  17283. c = ear.next;
  17284. if ( area( a, b, c ) >= 0 ) return false; // reflex, can't be an ear
  17285. // now make sure we don't have other points inside the potential ear
  17286. var p = ear.next.next;
  17287. while ( p !== ear.prev ) {
  17288. if ( pointInTriangle( a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y ) &&
  17289. area( p.prev, p, p.next ) >= 0 ) return false;
  17290. p = p.next;
  17291. }
  17292. return true;
  17293. }
  17294. function isEarHashed( ear, minX, minY, invSize ) {
  17295. var a = ear.prev,
  17296. b = ear,
  17297. c = ear.next;
  17298. if ( area( a, b, c ) >= 0 ) return false; // reflex, can't be an ear
  17299. // triangle bbox; min & max are calculated like this for speed
  17300. var minTX = a.x < b.x ? ( a.x < c.x ? a.x : c.x ) : ( b.x < c.x ? b.x : c.x ),
  17301. minTY = a.y < b.y ? ( a.y < c.y ? a.y : c.y ) : ( b.y < c.y ? b.y : c.y ),
  17302. maxTX = a.x > b.x ? ( a.x > c.x ? a.x : c.x ) : ( b.x > c.x ? b.x : c.x ),
  17303. maxTY = a.y > b.y ? ( a.y > c.y ? a.y : c.y ) : ( b.y > c.y ? b.y : c.y );
  17304. // z-order range for the current triangle bbox;
  17305. var minZ = zOrder( minTX, minTY, minX, minY, invSize ),
  17306. maxZ = zOrder( maxTX, maxTY, minX, minY, invSize );
  17307. var p = ear.prevZ,
  17308. n = ear.nextZ;
  17309. // look for points inside the triangle in both directions
  17310. while ( p && p.z >= minZ && n && n.z <= maxZ ) {
  17311. if ( p !== ear.prev && p !== ear.next &&
  17312. pointInTriangle( a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y ) &&
  17313. area( p.prev, p, p.next ) >= 0 ) return false;
  17314. p = p.prevZ;
  17315. if ( n !== ear.prev && n !== ear.next &&
  17316. pointInTriangle( a.x, a.y, b.x, b.y, c.x, c.y, n.x, n.y ) &&
  17317. area( n.prev, n, n.next ) >= 0 ) return false;
  17318. n = n.nextZ;
  17319. }
  17320. // look for remaining points in decreasing z-order
  17321. while ( p && p.z >= minZ ) {
  17322. if ( p !== ear.prev && p !== ear.next &&
  17323. pointInTriangle( a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y ) &&
  17324. area( p.prev, p, p.next ) >= 0 ) return false;
  17325. p = p.prevZ;
  17326. }
  17327. // look for remaining points in increasing z-order
  17328. while ( n && n.z <= maxZ ) {
  17329. if ( n !== ear.prev && n !== ear.next &&
  17330. pointInTriangle( a.x, a.y, b.x, b.y, c.x, c.y, n.x, n.y ) &&
  17331. area( n.prev, n, n.next ) >= 0 ) return false;
  17332. n = n.nextZ;
  17333. }
  17334. return true;
  17335. }
  17336. // go through all polygon nodes and cure small local self-intersections
  17337. function cureLocalIntersections( start, triangles, dim ) {
  17338. var p = start;
  17339. do {
  17340. var a = p.prev,
  17341. b = p.next.next;
  17342. if ( ! equals( a, b ) && intersects( a, p, p.next, b ) && locallyInside( a, b ) && locallyInside( b, a ) ) {
  17343. triangles.push( a.i / dim );
  17344. triangles.push( p.i / dim );
  17345. triangles.push( b.i / dim );
  17346. // remove two nodes involved
  17347. removeNode( p );
  17348. removeNode( p.next );
  17349. p = start = b;
  17350. }
  17351. p = p.next;
  17352. } while ( p !== start );
  17353. return p;
  17354. }
  17355. // try splitting polygon into two and triangulate them independently
  17356. function splitEarcut( start, triangles, dim, minX, minY, invSize ) {
  17357. // look for a valid diagonal that divides the polygon into two
  17358. var a = start;
  17359. do {
  17360. var b = a.next.next;
  17361. while ( b !== a.prev ) {
  17362. if ( a.i !== b.i && isValidDiagonal( a, b ) ) {
  17363. // split the polygon in two by the diagonal
  17364. var c = splitPolygon( a, b );
  17365. // filter colinear points around the cuts
  17366. a = filterPoints( a, a.next );
  17367. c = filterPoints( c, c.next );
  17368. // run earcut on each half
  17369. earcutLinked( a, triangles, dim, minX, minY, invSize );
  17370. earcutLinked( c, triangles, dim, minX, minY, invSize );
  17371. return;
  17372. }
  17373. b = b.next;
  17374. }
  17375. a = a.next;
  17376. } while ( a !== start );
  17377. }
  17378. // link every hole into the outer loop, producing a single-ring polygon without holes
  17379. function eliminateHoles( data, holeIndices, outerNode, dim ) {
  17380. var queue = [],
  17381. i, len, start, end, list;
  17382. for ( i = 0, len = holeIndices.length; i < len; i ++ ) {
  17383. start = holeIndices[ i ] * dim;
  17384. end = i < len - 1 ? holeIndices[ i + 1 ] * dim : data.length;
  17385. list = linkedList( data, start, end, dim, false );
  17386. if ( list === list.next ) list.steiner = true;
  17387. queue.push( getLeftmost( list ) );
  17388. }
  17389. queue.sort( compareX );
  17390. // process holes from left to right
  17391. for ( i = 0; i < queue.length; i ++ ) {
  17392. eliminateHole( queue[ i ], outerNode );
  17393. outerNode = filterPoints( outerNode, outerNode.next );
  17394. }
  17395. return outerNode;
  17396. }
  17397. function compareX( a, b ) {
  17398. return a.x - b.x;
  17399. }
  17400. // find a bridge between vertices that connects hole with an outer ring and and link it
  17401. function eliminateHole( hole, outerNode ) {
  17402. outerNode = findHoleBridge( hole, outerNode );
  17403. if ( outerNode ) {
  17404. var b = splitPolygon( outerNode, hole );
  17405. filterPoints( b, b.next );
  17406. }
  17407. }
  17408. // David Eberly's algorithm for finding a bridge between hole and outer polygon
  17409. function findHoleBridge( hole, outerNode ) {
  17410. var p = outerNode,
  17411. hx = hole.x,
  17412. hy = hole.y,
  17413. qx = - Infinity,
  17414. m;
  17415. // find a segment intersected by a ray from the hole's leftmost point to the left;
  17416. // segment's endpoint with lesser x will be potential connection point
  17417. do {
  17418. if ( hy <= p.y && hy >= p.next.y && p.next.y !== p.y ) {
  17419. var x = p.x + ( hy - p.y ) * ( p.next.x - p.x ) / ( p.next.y - p.y );
  17420. if ( x <= hx && x > qx ) {
  17421. qx = x;
  17422. if ( x === hx ) {
  17423. if ( hy === p.y ) return p;
  17424. if ( hy === p.next.y ) return p.next;
  17425. }
  17426. m = p.x < p.next.x ? p : p.next;
  17427. }
  17428. }
  17429. p = p.next;
  17430. } while ( p !== outerNode );
  17431. if ( ! m ) return null;
  17432. if ( hx === qx ) return m.prev; // hole touches outer segment; pick lower endpoint
  17433. // look for points inside the triangle of hole point, segment intersection and endpoint;
  17434. // if there are no points found, we have a valid connection;
  17435. // otherwise choose the point of the minimum angle with the ray as connection point
  17436. var stop = m,
  17437. mx = m.x,
  17438. my = m.y,
  17439. tanMin = Infinity,
  17440. tan;
  17441. p = m.next;
  17442. while ( p !== stop ) {
  17443. if ( hx >= p.x && p.x >= mx && hx !== p.x &&
  17444. pointInTriangle( hy < my ? hx : qx, hy, mx, my, hy < my ? qx : hx, hy, p.x, p.y ) ) {
  17445. tan = Math.abs( hy - p.y ) / ( hx - p.x ); // tangential
  17446. if ( ( tan < tanMin || ( tan === tanMin && p.x > m.x ) ) && locallyInside( p, hole ) ) {
  17447. m = p;
  17448. tanMin = tan;
  17449. }
  17450. }
  17451. p = p.next;
  17452. }
  17453. return m;
  17454. }
  17455. // interlink polygon nodes in z-order
  17456. function indexCurve( start, minX, minY, invSize ) {
  17457. var p = start;
  17458. do {
  17459. if ( p.z === null ) p.z = zOrder( p.x, p.y, minX, minY, invSize );
  17460. p.prevZ = p.prev;
  17461. p.nextZ = p.next;
  17462. p = p.next;
  17463. } while ( p !== start );
  17464. p.prevZ.nextZ = null;
  17465. p.prevZ = null;
  17466. sortLinked( p );
  17467. }
  17468. // Simon Tatham's linked list merge sort algorithm
  17469. // http://www.chiark.greenend.org.uk/~sgtatham/algorithms/listsort.html
  17470. function sortLinked( list ) {
  17471. var i, p, q, e, tail, numMerges, pSize, qSize,
  17472. inSize = 1;
  17473. do {
  17474. p = list;
  17475. list = null;
  17476. tail = null;
  17477. numMerges = 0;
  17478. while ( p ) {
  17479. numMerges ++;
  17480. q = p;
  17481. pSize = 0;
  17482. for ( i = 0; i < inSize; i ++ ) {
  17483. pSize ++;
  17484. q = q.nextZ;
  17485. if ( ! q ) break;
  17486. }
  17487. qSize = inSize;
  17488. while ( pSize > 0 || ( qSize > 0 && q ) ) {
  17489. if ( pSize !== 0 && ( qSize === 0 || ! q || p.z <= q.z ) ) {
  17490. e = p;
  17491. p = p.nextZ;
  17492. pSize --;
  17493. } else {
  17494. e = q;
  17495. q = q.nextZ;
  17496. qSize --;
  17497. }
  17498. if ( tail ) tail.nextZ = e;
  17499. else list = e;
  17500. e.prevZ = tail;
  17501. tail = e;
  17502. }
  17503. p = q;
  17504. }
  17505. tail.nextZ = null;
  17506. inSize *= 2;
  17507. } while ( numMerges > 1 );
  17508. return list;
  17509. }
  17510. // z-order of a point given coords and inverse of the longer side of data bbox
  17511. function zOrder( x, y, minX, minY, invSize ) {
  17512. // coords are transformed into non-negative 15-bit integer range
  17513. x = 32767 * ( x - minX ) * invSize;
  17514. y = 32767 * ( y - minY ) * invSize;
  17515. x = ( x | ( x << 8 ) ) & 0x00FF00FF;
  17516. x = ( x | ( x << 4 ) ) & 0x0F0F0F0F;
  17517. x = ( x | ( x << 2 ) ) & 0x33333333;
  17518. x = ( x | ( x << 1 ) ) & 0x55555555;
  17519. y = ( y | ( y << 8 ) ) & 0x00FF00FF;
  17520. y = ( y | ( y << 4 ) ) & 0x0F0F0F0F;
  17521. y = ( y | ( y << 2 ) ) & 0x33333333;
  17522. y = ( y | ( y << 1 ) ) & 0x55555555;
  17523. return x | ( y << 1 );
  17524. }
  17525. // find the leftmost node of a polygon ring
  17526. function getLeftmost( start ) {
  17527. var p = start,
  17528. leftmost = start;
  17529. do {
  17530. if ( p.x < leftmost.x || ( p.x === leftmost.x && p.y < leftmost.y ) ) leftmost = p;
  17531. p = p.next;
  17532. } while ( p !== start );
  17533. return leftmost;
  17534. }
  17535. // check if a point lies within a convex triangle
  17536. function pointInTriangle( ax, ay, bx, by, cx, cy, px, py ) {
  17537. return ( cx - px ) * ( ay - py ) - ( ax - px ) * ( cy - py ) >= 0 &&
  17538. ( ax - px ) * ( by - py ) - ( bx - px ) * ( ay - py ) >= 0 &&
  17539. ( bx - px ) * ( cy - py ) - ( cx - px ) * ( by - py ) >= 0;
  17540. }
  17541. // check if a diagonal between two polygon nodes is valid (lies in polygon interior)
  17542. function isValidDiagonal( a, b ) {
  17543. return a.next.i !== b.i && a.prev.i !== b.i && ! intersectsPolygon( a, b ) &&
  17544. locallyInside( a, b ) && locallyInside( b, a ) && middleInside( a, b );
  17545. }
  17546. // signed area of a triangle
  17547. function area( p, q, r ) {
  17548. return ( q.y - p.y ) * ( r.x - q.x ) - ( q.x - p.x ) * ( r.y - q.y );
  17549. }
  17550. // check if two points are equal
  17551. function equals( p1, p2 ) {
  17552. return p1.x === p2.x && p1.y === p2.y;
  17553. }
  17554. // check if two segments intersect
  17555. function intersects( p1, q1, p2, q2 ) {
  17556. if ( ( equals( p1, p2 ) && equals( q1, q2 ) ) ||
  17557. ( equals( p1, q2 ) && equals( p2, q1 ) ) ) return true;
  17558. return area( p1, q1, p2 ) > 0 !== area( p1, q1, q2 ) > 0 &&
  17559. area( p2, q2, p1 ) > 0 !== area( p2, q2, q1 ) > 0;
  17560. }
  17561. // check if a polygon diagonal intersects any polygon segments
  17562. function intersectsPolygon( a, b ) {
  17563. var p = a;
  17564. do {
  17565. if ( p.i !== a.i && p.next.i !== a.i && p.i !== b.i && p.next.i !== b.i &&
  17566. intersects( p, p.next, a, b ) ) return true;
  17567. p = p.next;
  17568. } while ( p !== a );
  17569. return false;
  17570. }
  17571. // check if a polygon diagonal is locally inside the polygon
  17572. function locallyInside( a, b ) {
  17573. return area( a.prev, a, a.next ) < 0 ?
  17574. area( a, b, a.next ) >= 0 && area( a, a.prev, b ) >= 0 :
  17575. area( a, b, a.prev ) < 0 || area( a, a.next, b ) < 0;
  17576. }
  17577. // check if the middle point of a polygon diagonal is inside the polygon
  17578. function middleInside( a, b ) {
  17579. var p = a,
  17580. inside = false,
  17581. px = ( a.x + b.x ) / 2,
  17582. py = ( a.y + b.y ) / 2;
  17583. do {
  17584. if ( ( ( p.y > py ) !== ( p.next.y > py ) ) && p.next.y !== p.y &&
  17585. ( px < ( p.next.x - p.x ) * ( py - p.y ) / ( p.next.y - p.y ) + p.x ) )
  17586. inside = ! inside;
  17587. p = p.next;
  17588. } while ( p !== a );
  17589. return inside;
  17590. }
  17591. // link two polygon vertices with a bridge; if the vertices belong to the same ring, it splits polygon into two;
  17592. // if one belongs to the outer ring and another to a hole, it merges it into a single ring
  17593. function splitPolygon( a, b ) {
  17594. var a2 = new Node( a.i, a.x, a.y ),
  17595. b2 = new Node( b.i, b.x, b.y ),
  17596. an = a.next,
  17597. bp = b.prev;
  17598. a.next = b;
  17599. b.prev = a;
  17600. a2.next = an;
  17601. an.prev = a2;
  17602. b2.next = a2;
  17603. a2.prev = b2;
  17604. bp.next = b2;
  17605. b2.prev = bp;
  17606. return b2;
  17607. }
  17608. // create a node and optionally link it with previous one (in a circular doubly linked list)
  17609. function insertNode( i, x, y, last ) {
  17610. var p = new Node( i, x, y );
  17611. if ( ! last ) {
  17612. p.prev = p;
  17613. p.next = p;
  17614. } else {
  17615. p.next = last.next;
  17616. p.prev = last;
  17617. last.next.prev = p;
  17618. last.next = p;
  17619. }
  17620. return p;
  17621. }
  17622. function removeNode( p ) {
  17623. p.next.prev = p.prev;
  17624. p.prev.next = p.next;
  17625. if ( p.prevZ ) p.prevZ.nextZ = p.nextZ;
  17626. if ( p.nextZ ) p.nextZ.prevZ = p.prevZ;
  17627. }
  17628. function Node( i, x, y ) {
  17629. // vertex index in coordinates array
  17630. this.i = i;
  17631. // vertex coordinates
  17632. this.x = x;
  17633. this.y = y;
  17634. // previous and next vertex nodes in a polygon ring
  17635. this.prev = null;
  17636. this.next = null;
  17637. // z-order curve value
  17638. this.z = null;
  17639. // previous and next nodes in z-order
  17640. this.prevZ = null;
  17641. this.nextZ = null;
  17642. // indicates whether this is a steiner point
  17643. this.steiner = false;
  17644. }
  17645. function signedArea( data, start, end, dim ) {
  17646. var sum = 0;
  17647. for ( var i = start, j = end - dim; i < end; i += dim ) {
  17648. sum += ( data[ j ] - data[ i ] ) * ( data[ i + 1 ] + data[ j + 1 ] );
  17649. j = i;
  17650. }
  17651. return sum;
  17652. }
  17653. /**
  17654. * @author zz85 / http://www.lab4games.net/zz85/blog
  17655. */
  17656. var ShapeUtils = {
  17657. // calculate area of the contour polygon
  17658. area: function ( contour ) {
  17659. var n = contour.length;
  17660. var a = 0.0;
  17661. for ( var p = n - 1, q = 0; q < n; p = q ++ ) {
  17662. a += contour[ p ].x * contour[ q ].y - contour[ q ].x * contour[ p ].y;
  17663. }
  17664. return a * 0.5;
  17665. },
  17666. isClockWise: function ( pts ) {
  17667. return ShapeUtils.area( pts ) < 0;
  17668. },
  17669. triangulateShape: function ( contour, holes ) {
  17670. var vertices = []; // flat array of vertices like [ x0,y0, x1,y1, x2,y2, ... ]
  17671. var holeIndices = []; // array of hole indices
  17672. var faces = []; // final array of vertex indices like [ [ a,b,d ], [ b,c,d ] ]
  17673. removeDupEndPts( contour );
  17674. addContour( vertices, contour );
  17675. //
  17676. var holeIndex = contour.length;
  17677. holes.forEach( removeDupEndPts );
  17678. for ( var i = 0; i < holes.length; i ++ ) {
  17679. holeIndices.push( holeIndex );
  17680. holeIndex += holes[ i ].length;
  17681. addContour( vertices, holes[ i ] );
  17682. }
  17683. //
  17684. var triangles = Earcut.triangulate( vertices, holeIndices );
  17685. //
  17686. for ( var i = 0; i < triangles.length; i += 3 ) {
  17687. faces.push( triangles.slice( i, i + 3 ) );
  17688. }
  17689. return faces;
  17690. }
  17691. };
  17692. function removeDupEndPts( points ) {
  17693. var l = points.length;
  17694. if ( l > 2 && points[ l - 1 ].equals( points[ 0 ] ) ) {
  17695. points.pop();
  17696. }
  17697. }
  17698. function addContour( vertices, contour ) {
  17699. for ( var i = 0; i < contour.length; i ++ ) {
  17700. vertices.push( contour[ i ].x );
  17701. vertices.push( contour[ i ].y );
  17702. }
  17703. }
  17704. /**
  17705. * @author zz85 / http://www.lab4games.net/zz85/blog
  17706. *
  17707. * Creates extruded geometry from a path shape.
  17708. *
  17709. * parameters = {
  17710. *
  17711. * curveSegments: <int>, // number of points on the curves
  17712. * steps: <int>, // number of points for z-side extrusions / used for subdividing segments of extrude spline too
  17713. * depth: <float>, // Depth to extrude the shape
  17714. *
  17715. * bevelEnabled: <bool>, // turn on bevel
  17716. * bevelThickness: <float>, // how deep into the original shape bevel goes
  17717. * bevelSize: <float>, // how far from shape outline (including bevelOffset) is bevel
  17718. * bevelOffset: <float>, // how far from shape outline does bevel start
  17719. * bevelSegments: <int>, // number of bevel layers
  17720. *
  17721. * extrudePath: <THREE.Curve> // curve to extrude shape along
  17722. *
  17723. * UVGenerator: <Object> // object that provides UV generator functions
  17724. *
  17725. * }
  17726. */
  17727. // ExtrudeGeometry
  17728. function ExtrudeGeometry( shapes, options ) {
  17729. Geometry.call( this );
  17730. this.type = 'ExtrudeGeometry';
  17731. this.parameters = {
  17732. shapes: shapes,
  17733. options: options
  17734. };
  17735. this.fromBufferGeometry( new ExtrudeBufferGeometry( shapes, options ) );
  17736. this.mergeVertices();
  17737. }
  17738. ExtrudeGeometry.prototype = Object.create( Geometry.prototype );
  17739. ExtrudeGeometry.prototype.constructor = ExtrudeGeometry;
  17740. ExtrudeGeometry.prototype.toJSON = function () {
  17741. var data = Geometry.prototype.toJSON.call( this );
  17742. var shapes = this.parameters.shapes;
  17743. var options = this.parameters.options;
  17744. return toJSON( shapes, options, data );
  17745. };
  17746. // ExtrudeBufferGeometry
  17747. function ExtrudeBufferGeometry( shapes, options ) {
  17748. BufferGeometry.call( this );
  17749. this.type = 'ExtrudeBufferGeometry';
  17750. this.parameters = {
  17751. shapes: shapes,
  17752. options: options
  17753. };
  17754. shapes = Array.isArray( shapes ) ? shapes : [ shapes ];
  17755. var scope = this;
  17756. var verticesArray = [];
  17757. var uvArray = [];
  17758. for ( var i = 0, l = shapes.length; i < l; i ++ ) {
  17759. var shape = shapes[ i ];
  17760. addShape( shape );
  17761. }
  17762. // build geometry
  17763. this.addAttribute( 'position', new Float32BufferAttribute( verticesArray, 3 ) );
  17764. this.addAttribute( 'uv', new Float32BufferAttribute( uvArray, 2 ) );
  17765. this.computeVertexNormals();
  17766. // functions
  17767. function addShape( shape ) {
  17768. var placeholder = [];
  17769. // options
  17770. var curveSegments = options.curveSegments !== undefined ? options.curveSegments : 12;
  17771. var steps = options.steps !== undefined ? options.steps : 1;
  17772. var depth = options.depth !== undefined ? options.depth : 100;
  17773. var bevelEnabled = options.bevelEnabled !== undefined ? options.bevelEnabled : true;
  17774. var bevelThickness = options.bevelThickness !== undefined ? options.bevelThickness : 6;
  17775. var bevelSize = options.bevelSize !== undefined ? options.bevelSize : bevelThickness - 2;
  17776. var bevelOffset = options.bevelOffset !== undefined ? options.bevelOffset : 0;
  17777. var bevelSegments = options.bevelSegments !== undefined ? options.bevelSegments : 3;
  17778. var extrudePath = options.extrudePath;
  17779. var uvgen = options.UVGenerator !== undefined ? options.UVGenerator : WorldUVGenerator;
  17780. // deprecated options
  17781. if ( options.amount !== undefined ) {
  17782. console.warn( 'THREE.ExtrudeBufferGeometry: amount has been renamed to depth.' );
  17783. depth = options.amount;
  17784. }
  17785. //
  17786. var extrudePts, extrudeByPath = false;
  17787. var splineTube, binormal, normal, position2;
  17788. if ( extrudePath ) {
  17789. extrudePts = extrudePath.getSpacedPoints( steps );
  17790. extrudeByPath = true;
  17791. bevelEnabled = false; // bevels not supported for path extrusion
  17792. // SETUP TNB variables
  17793. // TODO1 - have a .isClosed in spline?
  17794. splineTube = extrudePath.computeFrenetFrames( steps, false );
  17795. // console.log(splineTube, 'splineTube', splineTube.normals.length, 'steps', steps, 'extrudePts', extrudePts.length);
  17796. binormal = new Vector3();
  17797. normal = new Vector3();
  17798. position2 = new Vector3();
  17799. }
  17800. // Safeguards if bevels are not enabled
  17801. if ( ! bevelEnabled ) {
  17802. bevelSegments = 0;
  17803. bevelThickness = 0;
  17804. bevelSize = 0;
  17805. bevelOffset = 0;
  17806. }
  17807. // Variables initialization
  17808. var ahole, h, hl; // looping of holes
  17809. var shapePoints = shape.extractPoints( curveSegments );
  17810. var vertices = shapePoints.shape;
  17811. var holes = shapePoints.holes;
  17812. var reverse = ! ShapeUtils.isClockWise( vertices );
  17813. if ( reverse ) {
  17814. vertices = vertices.reverse();
  17815. // Maybe we should also check if holes are in the opposite direction, just to be safe ...
  17816. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  17817. ahole = holes[ h ];
  17818. if ( ShapeUtils.isClockWise( ahole ) ) {
  17819. holes[ h ] = ahole.reverse();
  17820. }
  17821. }
  17822. }
  17823. var faces = ShapeUtils.triangulateShape( vertices, holes );
  17824. /* Vertices */
  17825. var contour = vertices; // vertices has all points but contour has only points of circumference
  17826. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  17827. ahole = holes[ h ];
  17828. vertices = vertices.concat( ahole );
  17829. }
  17830. function scalePt2( pt, vec, size ) {
  17831. if ( ! vec ) console.error( "THREE.ExtrudeGeometry: vec does not exist" );
  17832. return vec.clone().multiplyScalar( size ).add( pt );
  17833. }
  17834. var b, bs, t, z,
  17835. vert, vlen = vertices.length,
  17836. face, flen = faces.length;
  17837. // Find directions for point movement
  17838. function getBevelVec( inPt, inPrev, inNext ) {
  17839. // computes for inPt the corresponding point inPt' on a new contour
  17840. // shifted by 1 unit (length of normalized vector) to the left
  17841. // if we walk along contour clockwise, this new contour is outside the old one
  17842. //
  17843. // inPt' is the intersection of the two lines parallel to the two
  17844. // adjacent edges of inPt at a distance of 1 unit on the left side.
  17845. var v_trans_x, v_trans_y, shrink_by; // resulting translation vector for inPt
  17846. // good reading for geometry algorithms (here: line-line intersection)
  17847. // http://geomalgorithms.com/a05-_intersect-1.html
  17848. var v_prev_x = inPt.x - inPrev.x,
  17849. v_prev_y = inPt.y - inPrev.y;
  17850. var v_next_x = inNext.x - inPt.x,
  17851. v_next_y = inNext.y - inPt.y;
  17852. var v_prev_lensq = ( v_prev_x * v_prev_x + v_prev_y * v_prev_y );
  17853. // check for collinear edges
  17854. var collinear0 = ( v_prev_x * v_next_y - v_prev_y * v_next_x );
  17855. if ( Math.abs( collinear0 ) > Number.EPSILON ) {
  17856. // not collinear
  17857. // length of vectors for normalizing
  17858. var v_prev_len = Math.sqrt( v_prev_lensq );
  17859. var v_next_len = Math.sqrt( v_next_x * v_next_x + v_next_y * v_next_y );
  17860. // shift adjacent points by unit vectors to the left
  17861. var ptPrevShift_x = ( inPrev.x - v_prev_y / v_prev_len );
  17862. var ptPrevShift_y = ( inPrev.y + v_prev_x / v_prev_len );
  17863. var ptNextShift_x = ( inNext.x - v_next_y / v_next_len );
  17864. var ptNextShift_y = ( inNext.y + v_next_x / v_next_len );
  17865. // scaling factor for v_prev to intersection point
  17866. var sf = ( ( ptNextShift_x - ptPrevShift_x ) * v_next_y -
  17867. ( ptNextShift_y - ptPrevShift_y ) * v_next_x ) /
  17868. ( v_prev_x * v_next_y - v_prev_y * v_next_x );
  17869. // vector from inPt to intersection point
  17870. v_trans_x = ( ptPrevShift_x + v_prev_x * sf - inPt.x );
  17871. v_trans_y = ( ptPrevShift_y + v_prev_y * sf - inPt.y );
  17872. // Don't normalize!, otherwise sharp corners become ugly
  17873. // but prevent crazy spikes
  17874. var v_trans_lensq = ( v_trans_x * v_trans_x + v_trans_y * v_trans_y );
  17875. if ( v_trans_lensq <= 2 ) {
  17876. return new Vector2( v_trans_x, v_trans_y );
  17877. } else {
  17878. shrink_by = Math.sqrt( v_trans_lensq / 2 );
  17879. }
  17880. } else {
  17881. // handle special case of collinear edges
  17882. var direction_eq = false; // assumes: opposite
  17883. if ( v_prev_x > Number.EPSILON ) {
  17884. if ( v_next_x > Number.EPSILON ) {
  17885. direction_eq = true;
  17886. }
  17887. } else {
  17888. if ( v_prev_x < - Number.EPSILON ) {
  17889. if ( v_next_x < - Number.EPSILON ) {
  17890. direction_eq = true;
  17891. }
  17892. } else {
  17893. if ( Math.sign( v_prev_y ) === Math.sign( v_next_y ) ) {
  17894. direction_eq = true;
  17895. }
  17896. }
  17897. }
  17898. if ( direction_eq ) {
  17899. // console.log("Warning: lines are a straight sequence");
  17900. v_trans_x = - v_prev_y;
  17901. v_trans_y = v_prev_x;
  17902. shrink_by = Math.sqrt( v_prev_lensq );
  17903. } else {
  17904. // console.log("Warning: lines are a straight spike");
  17905. v_trans_x = v_prev_x;
  17906. v_trans_y = v_prev_y;
  17907. shrink_by = Math.sqrt( v_prev_lensq / 2 );
  17908. }
  17909. }
  17910. return new Vector2( v_trans_x / shrink_by, v_trans_y / shrink_by );
  17911. }
  17912. var contourMovements = [];
  17913. for ( var i = 0, il = contour.length, j = il - 1, k = i + 1; i < il; i ++, j ++, k ++ ) {
  17914. if ( j === il ) j = 0;
  17915. if ( k === il ) k = 0;
  17916. // (j)---(i)---(k)
  17917. // console.log('i,j,k', i, j , k)
  17918. contourMovements[ i ] = getBevelVec( contour[ i ], contour[ j ], contour[ k ] );
  17919. }
  17920. var holesMovements = [],
  17921. oneHoleMovements, verticesMovements = contourMovements.concat();
  17922. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  17923. ahole = holes[ h ];
  17924. oneHoleMovements = [];
  17925. for ( i = 0, il = ahole.length, j = il - 1, k = i + 1; i < il; i ++, j ++, k ++ ) {
  17926. if ( j === il ) j = 0;
  17927. if ( k === il ) k = 0;
  17928. // (j)---(i)---(k)
  17929. oneHoleMovements[ i ] = getBevelVec( ahole[ i ], ahole[ j ], ahole[ k ] );
  17930. }
  17931. holesMovements.push( oneHoleMovements );
  17932. verticesMovements = verticesMovements.concat( oneHoleMovements );
  17933. }
  17934. // Loop bevelSegments, 1 for the front, 1 for the back
  17935. for ( b = 0; b < bevelSegments; b ++ ) {
  17936. //for ( b = bevelSegments; b > 0; b -- ) {
  17937. t = b / bevelSegments;
  17938. z = bevelThickness * Math.cos( t * Math.PI / 2 );
  17939. bs = bevelSize * Math.sin( t * Math.PI / 2 ) + bevelOffset;
  17940. // contract shape
  17941. for ( i = 0, il = contour.length; i < il; i ++ ) {
  17942. vert = scalePt2( contour[ i ], contourMovements[ i ], bs );
  17943. v( vert.x, vert.y, - z );
  17944. }
  17945. // expand holes
  17946. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  17947. ahole = holes[ h ];
  17948. oneHoleMovements = holesMovements[ h ];
  17949. for ( i = 0, il = ahole.length; i < il; i ++ ) {
  17950. vert = scalePt2( ahole[ i ], oneHoleMovements[ i ], bs );
  17951. v( vert.x, vert.y, - z );
  17952. }
  17953. }
  17954. }
  17955. bs = bevelSize + bevelOffset;
  17956. // Back facing vertices
  17957. for ( i = 0; i < vlen; i ++ ) {
  17958. vert = bevelEnabled ? scalePt2( vertices[ i ], verticesMovements[ i ], bs ) : vertices[ i ];
  17959. if ( ! extrudeByPath ) {
  17960. v( vert.x, vert.y, 0 );
  17961. } else {
  17962. // v( vert.x, vert.y + extrudePts[ 0 ].y, extrudePts[ 0 ].x );
  17963. normal.copy( splineTube.normals[ 0 ] ).multiplyScalar( vert.x );
  17964. binormal.copy( splineTube.binormals[ 0 ] ).multiplyScalar( vert.y );
  17965. position2.copy( extrudePts[ 0 ] ).add( normal ).add( binormal );
  17966. v( position2.x, position2.y, position2.z );
  17967. }
  17968. }
  17969. // Add stepped vertices...
  17970. // Including front facing vertices
  17971. var s;
  17972. for ( s = 1; s <= steps; s ++ ) {
  17973. for ( i = 0; i < vlen; i ++ ) {
  17974. vert = bevelEnabled ? scalePt2( vertices[ i ], verticesMovements[ i ], bs ) : vertices[ i ];
  17975. if ( ! extrudeByPath ) {
  17976. v( vert.x, vert.y, depth / steps * s );
  17977. } else {
  17978. // v( vert.x, vert.y + extrudePts[ s - 1 ].y, extrudePts[ s - 1 ].x );
  17979. normal.copy( splineTube.normals[ s ] ).multiplyScalar( vert.x );
  17980. binormal.copy( splineTube.binormals[ s ] ).multiplyScalar( vert.y );
  17981. position2.copy( extrudePts[ s ] ).add( normal ).add( binormal );
  17982. v( position2.x, position2.y, position2.z );
  17983. }
  17984. }
  17985. }
  17986. // Add bevel segments planes
  17987. //for ( b = 1; b <= bevelSegments; b ++ ) {
  17988. for ( b = bevelSegments - 1; b >= 0; b -- ) {
  17989. t = b / bevelSegments;
  17990. z = bevelThickness * Math.cos( t * Math.PI / 2 );
  17991. bs = bevelSize * Math.sin( t * Math.PI / 2 ) + bevelOffset;
  17992. // contract shape
  17993. for ( i = 0, il = contour.length; i < il; i ++ ) {
  17994. vert = scalePt2( contour[ i ], contourMovements[ i ], bs );
  17995. v( vert.x, vert.y, depth + z );
  17996. }
  17997. // expand holes
  17998. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  17999. ahole = holes[ h ];
  18000. oneHoleMovements = holesMovements[ h ];
  18001. for ( i = 0, il = ahole.length; i < il; i ++ ) {
  18002. vert = scalePt2( ahole[ i ], oneHoleMovements[ i ], bs );
  18003. if ( ! extrudeByPath ) {
  18004. v( vert.x, vert.y, depth + z );
  18005. } else {
  18006. v( vert.x, vert.y + extrudePts[ steps - 1 ].y, extrudePts[ steps - 1 ].x + z );
  18007. }
  18008. }
  18009. }
  18010. }
  18011. /* Faces */
  18012. // Top and bottom faces
  18013. buildLidFaces();
  18014. // Sides faces
  18015. buildSideFaces();
  18016. ///// Internal functions
  18017. function buildLidFaces() {
  18018. var start = verticesArray.length / 3;
  18019. if ( bevelEnabled ) {
  18020. var layer = 0; // steps + 1
  18021. var offset = vlen * layer;
  18022. // Bottom faces
  18023. for ( i = 0; i < flen; i ++ ) {
  18024. face = faces[ i ];
  18025. f3( face[ 2 ] + offset, face[ 1 ] + offset, face[ 0 ] + offset );
  18026. }
  18027. layer = steps + bevelSegments * 2;
  18028. offset = vlen * layer;
  18029. // Top faces
  18030. for ( i = 0; i < flen; i ++ ) {
  18031. face = faces[ i ];
  18032. f3( face[ 0 ] + offset, face[ 1 ] + offset, face[ 2 ] + offset );
  18033. }
  18034. } else {
  18035. // Bottom faces
  18036. for ( i = 0; i < flen; i ++ ) {
  18037. face = faces[ i ];
  18038. f3( face[ 2 ], face[ 1 ], face[ 0 ] );
  18039. }
  18040. // Top faces
  18041. for ( i = 0; i < flen; i ++ ) {
  18042. face = faces[ i ];
  18043. f3( face[ 0 ] + vlen * steps, face[ 1 ] + vlen * steps, face[ 2 ] + vlen * steps );
  18044. }
  18045. }
  18046. scope.addGroup( start, verticesArray.length / 3 - start, 0 );
  18047. }
  18048. // Create faces for the z-sides of the shape
  18049. function buildSideFaces() {
  18050. var start = verticesArray.length / 3;
  18051. var layeroffset = 0;
  18052. sidewalls( contour, layeroffset );
  18053. layeroffset += contour.length;
  18054. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  18055. ahole = holes[ h ];
  18056. sidewalls( ahole, layeroffset );
  18057. //, true
  18058. layeroffset += ahole.length;
  18059. }
  18060. scope.addGroup( start, verticesArray.length / 3 - start, 1 );
  18061. }
  18062. function sidewalls( contour, layeroffset ) {
  18063. var j, k;
  18064. i = contour.length;
  18065. while ( -- i >= 0 ) {
  18066. j = i;
  18067. k = i - 1;
  18068. if ( k < 0 ) k = contour.length - 1;
  18069. //console.log('b', i,j, i-1, k,vertices.length);
  18070. var s = 0,
  18071. sl = steps + bevelSegments * 2;
  18072. for ( s = 0; s < sl; s ++ ) {
  18073. var slen1 = vlen * s;
  18074. var slen2 = vlen * ( s + 1 );
  18075. var a = layeroffset + j + slen1,
  18076. b = layeroffset + k + slen1,
  18077. c = layeroffset + k + slen2,
  18078. d = layeroffset + j + slen2;
  18079. f4( a, b, c, d );
  18080. }
  18081. }
  18082. }
  18083. function v( x, y, z ) {
  18084. placeholder.push( x );
  18085. placeholder.push( y );
  18086. placeholder.push( z );
  18087. }
  18088. function f3( a, b, c ) {
  18089. addVertex( a );
  18090. addVertex( b );
  18091. addVertex( c );
  18092. var nextIndex = verticesArray.length / 3;
  18093. var uvs = uvgen.generateTopUV( scope, verticesArray, nextIndex - 3, nextIndex - 2, nextIndex - 1 );
  18094. addUV( uvs[ 0 ] );
  18095. addUV( uvs[ 1 ] );
  18096. addUV( uvs[ 2 ] );
  18097. }
  18098. function f4( a, b, c, d ) {
  18099. addVertex( a );
  18100. addVertex( b );
  18101. addVertex( d );
  18102. addVertex( b );
  18103. addVertex( c );
  18104. addVertex( d );
  18105. var nextIndex = verticesArray.length / 3;
  18106. var uvs = uvgen.generateSideWallUV( scope, verticesArray, nextIndex - 6, nextIndex - 3, nextIndex - 2, nextIndex - 1 );
  18107. addUV( uvs[ 0 ] );
  18108. addUV( uvs[ 1 ] );
  18109. addUV( uvs[ 3 ] );
  18110. addUV( uvs[ 1 ] );
  18111. addUV( uvs[ 2 ] );
  18112. addUV( uvs[ 3 ] );
  18113. }
  18114. function addVertex( index ) {
  18115. verticesArray.push( placeholder[ index * 3 + 0 ] );
  18116. verticesArray.push( placeholder[ index * 3 + 1 ] );
  18117. verticesArray.push( placeholder[ index * 3 + 2 ] );
  18118. }
  18119. function addUV( vector2 ) {
  18120. uvArray.push( vector2.x );
  18121. uvArray.push( vector2.y );
  18122. }
  18123. }
  18124. }
  18125. ExtrudeBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  18126. ExtrudeBufferGeometry.prototype.constructor = ExtrudeBufferGeometry;
  18127. ExtrudeBufferGeometry.prototype.toJSON = function () {
  18128. var data = BufferGeometry.prototype.toJSON.call( this );
  18129. var shapes = this.parameters.shapes;
  18130. var options = this.parameters.options;
  18131. return toJSON( shapes, options, data );
  18132. };
  18133. //
  18134. var WorldUVGenerator = {
  18135. generateTopUV: function ( geometry, vertices, indexA, indexB, indexC ) {
  18136. var a_x = vertices[ indexA * 3 ];
  18137. var a_y = vertices[ indexA * 3 + 1 ];
  18138. var b_x = vertices[ indexB * 3 ];
  18139. var b_y = vertices[ indexB * 3 + 1 ];
  18140. var c_x = vertices[ indexC * 3 ];
  18141. var c_y = vertices[ indexC * 3 + 1 ];
  18142. return [
  18143. new Vector2( a_x, a_y ),
  18144. new Vector2( b_x, b_y ),
  18145. new Vector2( c_x, c_y )
  18146. ];
  18147. },
  18148. generateSideWallUV: function ( geometry, vertices, indexA, indexB, indexC, indexD ) {
  18149. var a_x = vertices[ indexA * 3 ];
  18150. var a_y = vertices[ indexA * 3 + 1 ];
  18151. var a_z = vertices[ indexA * 3 + 2 ];
  18152. var b_x = vertices[ indexB * 3 ];
  18153. var b_y = vertices[ indexB * 3 + 1 ];
  18154. var b_z = vertices[ indexB * 3 + 2 ];
  18155. var c_x = vertices[ indexC * 3 ];
  18156. var c_y = vertices[ indexC * 3 + 1 ];
  18157. var c_z = vertices[ indexC * 3 + 2 ];
  18158. var d_x = vertices[ indexD * 3 ];
  18159. var d_y = vertices[ indexD * 3 + 1 ];
  18160. var d_z = vertices[ indexD * 3 + 2 ];
  18161. if ( Math.abs( a_y - b_y ) < 0.01 ) {
  18162. return [
  18163. new Vector2( a_x, 1 - a_z ),
  18164. new Vector2( b_x, 1 - b_z ),
  18165. new Vector2( c_x, 1 - c_z ),
  18166. new Vector2( d_x, 1 - d_z )
  18167. ];
  18168. } else {
  18169. return [
  18170. new Vector2( a_y, 1 - a_z ),
  18171. new Vector2( b_y, 1 - b_z ),
  18172. new Vector2( c_y, 1 - c_z ),
  18173. new Vector2( d_y, 1 - d_z )
  18174. ];
  18175. }
  18176. }
  18177. };
  18178. function toJSON( shapes, options, data ) {
  18179. //
  18180. data.shapes = [];
  18181. if ( Array.isArray( shapes ) ) {
  18182. for ( var i = 0, l = shapes.length; i < l; i ++ ) {
  18183. var shape = shapes[ i ];
  18184. data.shapes.push( shape.uuid );
  18185. }
  18186. } else {
  18187. data.shapes.push( shapes.uuid );
  18188. }
  18189. //
  18190. if ( options.extrudePath !== undefined ) data.options.extrudePath = options.extrudePath.toJSON();
  18191. return data;
  18192. }
  18193. /**
  18194. * @author zz85 / http://www.lab4games.net/zz85/blog
  18195. * @author alteredq / http://alteredqualia.com/
  18196. *
  18197. * Text = 3D Text
  18198. *
  18199. * parameters = {
  18200. * font: <THREE.Font>, // font
  18201. *
  18202. * size: <float>, // size of the text
  18203. * height: <float>, // thickness to extrude text
  18204. * curveSegments: <int>, // number of points on the curves
  18205. *
  18206. * bevelEnabled: <bool>, // turn on bevel
  18207. * bevelThickness: <float>, // how deep into text bevel goes
  18208. * bevelSize: <float>, // how far from text outline (including bevelOffset) is bevel
  18209. * bevelOffset: <float> // how far from text outline does bevel start
  18210. * }
  18211. */
  18212. // TextGeometry
  18213. function TextGeometry( text, parameters ) {
  18214. Geometry.call( this );
  18215. this.type = 'TextGeometry';
  18216. this.parameters = {
  18217. text: text,
  18218. parameters: parameters
  18219. };
  18220. this.fromBufferGeometry( new TextBufferGeometry( text, parameters ) );
  18221. this.mergeVertices();
  18222. }
  18223. TextGeometry.prototype = Object.create( Geometry.prototype );
  18224. TextGeometry.prototype.constructor = TextGeometry;
  18225. // TextBufferGeometry
  18226. function TextBufferGeometry( text, parameters ) {
  18227. parameters = parameters || {};
  18228. var font = parameters.font;
  18229. if ( ! ( font && font.isFont ) ) {
  18230. console.error( 'THREE.TextGeometry: font parameter is not an instance of THREE.Font.' );
  18231. return new Geometry();
  18232. }
  18233. var shapes = font.generateShapes( text, parameters.size );
  18234. // translate parameters to ExtrudeGeometry API
  18235. parameters.depth = parameters.height !== undefined ? parameters.height : 50;
  18236. // defaults
  18237. if ( parameters.bevelThickness === undefined ) parameters.bevelThickness = 10;
  18238. if ( parameters.bevelSize === undefined ) parameters.bevelSize = 8;
  18239. if ( parameters.bevelEnabled === undefined ) parameters.bevelEnabled = false;
  18240. ExtrudeBufferGeometry.call( this, shapes, parameters );
  18241. this.type = 'TextBufferGeometry';
  18242. }
  18243. TextBufferGeometry.prototype = Object.create( ExtrudeBufferGeometry.prototype );
  18244. TextBufferGeometry.prototype.constructor = TextBufferGeometry;
  18245. /**
  18246. * @author mrdoob / http://mrdoob.com/
  18247. * @author benaadams / https://twitter.com/ben_a_adams
  18248. * @author Mugen87 / https://github.com/Mugen87
  18249. */
  18250. // SphereGeometry
  18251. function SphereGeometry( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) {
  18252. Geometry.call( this );
  18253. this.type = 'SphereGeometry';
  18254. this.parameters = {
  18255. radius: radius,
  18256. widthSegments: widthSegments,
  18257. heightSegments: heightSegments,
  18258. phiStart: phiStart,
  18259. phiLength: phiLength,
  18260. thetaStart: thetaStart,
  18261. thetaLength: thetaLength
  18262. };
  18263. this.fromBufferGeometry( new SphereBufferGeometry( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) );
  18264. this.mergeVertices();
  18265. }
  18266. SphereGeometry.prototype = Object.create( Geometry.prototype );
  18267. SphereGeometry.prototype.constructor = SphereGeometry;
  18268. // SphereBufferGeometry
  18269. function SphereBufferGeometry( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) {
  18270. BufferGeometry.call( this );
  18271. this.type = 'SphereBufferGeometry';
  18272. this.parameters = {
  18273. radius: radius,
  18274. widthSegments: widthSegments,
  18275. heightSegments: heightSegments,
  18276. phiStart: phiStart,
  18277. phiLength: phiLength,
  18278. thetaStart: thetaStart,
  18279. thetaLength: thetaLength
  18280. };
  18281. radius = radius || 1;
  18282. widthSegments = Math.max( 3, Math.floor( widthSegments ) || 8 );
  18283. heightSegments = Math.max( 2, Math.floor( heightSegments ) || 6 );
  18284. phiStart = phiStart !== undefined ? phiStart : 0;
  18285. phiLength = phiLength !== undefined ? phiLength : Math.PI * 2;
  18286. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  18287. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI;
  18288. var thetaEnd = Math.min( thetaStart + thetaLength, Math.PI );
  18289. var ix, iy;
  18290. var index = 0;
  18291. var grid = [];
  18292. var vertex = new Vector3();
  18293. var normal = new Vector3();
  18294. // buffers
  18295. var indices = [];
  18296. var vertices = [];
  18297. var normals = [];
  18298. var uvs = [];
  18299. // generate vertices, normals and uvs
  18300. for ( iy = 0; iy <= heightSegments; iy ++ ) {
  18301. var verticesRow = [];
  18302. var v = iy / heightSegments;
  18303. // special case for the poles
  18304. var uOffset = 0;
  18305. if ( iy == 0 && thetaStart == 0 ) {
  18306. uOffset = 0.5 / widthSegments;
  18307. } else if ( iy == heightSegments && thetaEnd == Math.PI ) {
  18308. uOffset = - 0.5 / widthSegments;
  18309. }
  18310. for ( ix = 0; ix <= widthSegments; ix ++ ) {
  18311. var u = ix / widthSegments;
  18312. // vertex
  18313. vertex.x = - radius * Math.cos( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  18314. vertex.y = radius * Math.cos( thetaStart + v * thetaLength );
  18315. vertex.z = radius * Math.sin( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  18316. vertices.push( vertex.x, vertex.y, vertex.z );
  18317. // normal
  18318. normal.copy( vertex ).normalize();
  18319. normals.push( normal.x, normal.y, normal.z );
  18320. // uv
  18321. uvs.push( u + uOffset, 1 - v );
  18322. verticesRow.push( index ++ );
  18323. }
  18324. grid.push( verticesRow );
  18325. }
  18326. // indices
  18327. for ( iy = 0; iy < heightSegments; iy ++ ) {
  18328. for ( ix = 0; ix < widthSegments; ix ++ ) {
  18329. var a = grid[ iy ][ ix + 1 ];
  18330. var b = grid[ iy ][ ix ];
  18331. var c = grid[ iy + 1 ][ ix ];
  18332. var d = grid[ iy + 1 ][ ix + 1 ];
  18333. if ( iy !== 0 || thetaStart > 0 ) indices.push( a, b, d );
  18334. if ( iy !== heightSegments - 1 || thetaEnd < Math.PI ) indices.push( b, c, d );
  18335. }
  18336. }
  18337. // build geometry
  18338. this.setIndex( indices );
  18339. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  18340. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  18341. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  18342. }
  18343. SphereBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  18344. SphereBufferGeometry.prototype.constructor = SphereBufferGeometry;
  18345. /**
  18346. * @author Kaleb Murphy
  18347. * @author Mugen87 / https://github.com/Mugen87
  18348. */
  18349. // RingGeometry
  18350. function RingGeometry( innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength ) {
  18351. Geometry.call( this );
  18352. this.type = 'RingGeometry';
  18353. this.parameters = {
  18354. innerRadius: innerRadius,
  18355. outerRadius: outerRadius,
  18356. thetaSegments: thetaSegments,
  18357. phiSegments: phiSegments,
  18358. thetaStart: thetaStart,
  18359. thetaLength: thetaLength
  18360. };
  18361. this.fromBufferGeometry( new RingBufferGeometry( innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength ) );
  18362. this.mergeVertices();
  18363. }
  18364. RingGeometry.prototype = Object.create( Geometry.prototype );
  18365. RingGeometry.prototype.constructor = RingGeometry;
  18366. // RingBufferGeometry
  18367. function RingBufferGeometry( innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength ) {
  18368. BufferGeometry.call( this );
  18369. this.type = 'RingBufferGeometry';
  18370. this.parameters = {
  18371. innerRadius: innerRadius,
  18372. outerRadius: outerRadius,
  18373. thetaSegments: thetaSegments,
  18374. phiSegments: phiSegments,
  18375. thetaStart: thetaStart,
  18376. thetaLength: thetaLength
  18377. };
  18378. innerRadius = innerRadius || 0.5;
  18379. outerRadius = outerRadius || 1;
  18380. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  18381. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  18382. thetaSegments = thetaSegments !== undefined ? Math.max( 3, thetaSegments ) : 8;
  18383. phiSegments = phiSegments !== undefined ? Math.max( 1, phiSegments ) : 1;
  18384. // buffers
  18385. var indices = [];
  18386. var vertices = [];
  18387. var normals = [];
  18388. var uvs = [];
  18389. // some helper variables
  18390. var segment;
  18391. var radius = innerRadius;
  18392. var radiusStep = ( ( outerRadius - innerRadius ) / phiSegments );
  18393. var vertex = new Vector3();
  18394. var uv = new Vector2();
  18395. var j, i;
  18396. // generate vertices, normals and uvs
  18397. for ( j = 0; j <= phiSegments; j ++ ) {
  18398. for ( i = 0; i <= thetaSegments; i ++ ) {
  18399. // values are generate from the inside of the ring to the outside
  18400. segment = thetaStart + i / thetaSegments * thetaLength;
  18401. // vertex
  18402. vertex.x = radius * Math.cos( segment );
  18403. vertex.y = radius * Math.sin( segment );
  18404. vertices.push( vertex.x, vertex.y, vertex.z );
  18405. // normal
  18406. normals.push( 0, 0, 1 );
  18407. // uv
  18408. uv.x = ( vertex.x / outerRadius + 1 ) / 2;
  18409. uv.y = ( vertex.y / outerRadius + 1 ) / 2;
  18410. uvs.push( uv.x, uv.y );
  18411. }
  18412. // increase the radius for next row of vertices
  18413. radius += radiusStep;
  18414. }
  18415. // indices
  18416. for ( j = 0; j < phiSegments; j ++ ) {
  18417. var thetaSegmentLevel = j * ( thetaSegments + 1 );
  18418. for ( i = 0; i < thetaSegments; i ++ ) {
  18419. segment = i + thetaSegmentLevel;
  18420. var a = segment;
  18421. var b = segment + thetaSegments + 1;
  18422. var c = segment + thetaSegments + 2;
  18423. var d = segment + 1;
  18424. // faces
  18425. indices.push( a, b, d );
  18426. indices.push( b, c, d );
  18427. }
  18428. }
  18429. // build geometry
  18430. this.setIndex( indices );
  18431. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  18432. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  18433. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  18434. }
  18435. RingBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  18436. RingBufferGeometry.prototype.constructor = RingBufferGeometry;
  18437. /**
  18438. * @author zz85 / https://github.com/zz85
  18439. * @author bhouston / http://clara.io
  18440. * @author Mugen87 / https://github.com/Mugen87
  18441. */
  18442. // LatheGeometry
  18443. function LatheGeometry( points, segments, phiStart, phiLength ) {
  18444. Geometry.call( this );
  18445. this.type = 'LatheGeometry';
  18446. this.parameters = {
  18447. points: points,
  18448. segments: segments,
  18449. phiStart: phiStart,
  18450. phiLength: phiLength
  18451. };
  18452. this.fromBufferGeometry( new LatheBufferGeometry( points, segments, phiStart, phiLength ) );
  18453. this.mergeVertices();
  18454. }
  18455. LatheGeometry.prototype = Object.create( Geometry.prototype );
  18456. LatheGeometry.prototype.constructor = LatheGeometry;
  18457. // LatheBufferGeometry
  18458. function LatheBufferGeometry( points, segments, phiStart, phiLength ) {
  18459. BufferGeometry.call( this );
  18460. this.type = 'LatheBufferGeometry';
  18461. this.parameters = {
  18462. points: points,
  18463. segments: segments,
  18464. phiStart: phiStart,
  18465. phiLength: phiLength
  18466. };
  18467. segments = Math.floor( segments ) || 12;
  18468. phiStart = phiStart || 0;
  18469. phiLength = phiLength || Math.PI * 2;
  18470. // clamp phiLength so it's in range of [ 0, 2PI ]
  18471. phiLength = _Math.clamp( phiLength, 0, Math.PI * 2 );
  18472. // buffers
  18473. var indices = [];
  18474. var vertices = [];
  18475. var uvs = [];
  18476. // helper variables
  18477. var base;
  18478. var inverseSegments = 1.0 / segments;
  18479. var vertex = new Vector3();
  18480. var uv = new Vector2();
  18481. var i, j;
  18482. // generate vertices and uvs
  18483. for ( i = 0; i <= segments; i ++ ) {
  18484. var phi = phiStart + i * inverseSegments * phiLength;
  18485. var sin = Math.sin( phi );
  18486. var cos = Math.cos( phi );
  18487. for ( j = 0; j <= ( points.length - 1 ); j ++ ) {
  18488. // vertex
  18489. vertex.x = points[ j ].x * sin;
  18490. vertex.y = points[ j ].y;
  18491. vertex.z = points[ j ].x * cos;
  18492. vertices.push( vertex.x, vertex.y, vertex.z );
  18493. // uv
  18494. uv.x = i / segments;
  18495. uv.y = j / ( points.length - 1 );
  18496. uvs.push( uv.x, uv.y );
  18497. }
  18498. }
  18499. // indices
  18500. for ( i = 0; i < segments; i ++ ) {
  18501. for ( j = 0; j < ( points.length - 1 ); j ++ ) {
  18502. base = j + i * points.length;
  18503. var a = base;
  18504. var b = base + points.length;
  18505. var c = base + points.length + 1;
  18506. var d = base + 1;
  18507. // faces
  18508. indices.push( a, b, d );
  18509. indices.push( b, c, d );
  18510. }
  18511. }
  18512. // build geometry
  18513. this.setIndex( indices );
  18514. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  18515. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  18516. // generate normals
  18517. this.computeVertexNormals();
  18518. // if the geometry is closed, we need to average the normals along the seam.
  18519. // because the corresponding vertices are identical (but still have different UVs).
  18520. if ( phiLength === Math.PI * 2 ) {
  18521. var normals = this.attributes.normal.array;
  18522. var n1 = new Vector3();
  18523. var n2 = new Vector3();
  18524. var n = new Vector3();
  18525. // this is the buffer offset for the last line of vertices
  18526. base = segments * points.length * 3;
  18527. for ( i = 0, j = 0; i < points.length; i ++, j += 3 ) {
  18528. // select the normal of the vertex in the first line
  18529. n1.x = normals[ j + 0 ];
  18530. n1.y = normals[ j + 1 ];
  18531. n1.z = normals[ j + 2 ];
  18532. // select the normal of the vertex in the last line
  18533. n2.x = normals[ base + j + 0 ];
  18534. n2.y = normals[ base + j + 1 ];
  18535. n2.z = normals[ base + j + 2 ];
  18536. // average normals
  18537. n.addVectors( n1, n2 ).normalize();
  18538. // assign the new values to both normals
  18539. normals[ j + 0 ] = normals[ base + j + 0 ] = n.x;
  18540. normals[ j + 1 ] = normals[ base + j + 1 ] = n.y;
  18541. normals[ j + 2 ] = normals[ base + j + 2 ] = n.z;
  18542. }
  18543. }
  18544. }
  18545. LatheBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  18546. LatheBufferGeometry.prototype.constructor = LatheBufferGeometry;
  18547. /**
  18548. * @author jonobr1 / http://jonobr1.com
  18549. * @author Mugen87 / https://github.com/Mugen87
  18550. */
  18551. // ShapeGeometry
  18552. function ShapeGeometry( shapes, curveSegments ) {
  18553. Geometry.call( this );
  18554. this.type = 'ShapeGeometry';
  18555. if ( typeof curveSegments === 'object' ) {
  18556. console.warn( 'THREE.ShapeGeometry: Options parameter has been removed.' );
  18557. curveSegments = curveSegments.curveSegments;
  18558. }
  18559. this.parameters = {
  18560. shapes: shapes,
  18561. curveSegments: curveSegments
  18562. };
  18563. this.fromBufferGeometry( new ShapeBufferGeometry( shapes, curveSegments ) );
  18564. this.mergeVertices();
  18565. }
  18566. ShapeGeometry.prototype = Object.create( Geometry.prototype );
  18567. ShapeGeometry.prototype.constructor = ShapeGeometry;
  18568. ShapeGeometry.prototype.toJSON = function () {
  18569. var data = Geometry.prototype.toJSON.call( this );
  18570. var shapes = this.parameters.shapes;
  18571. return toJSON$1( shapes, data );
  18572. };
  18573. // ShapeBufferGeometry
  18574. function ShapeBufferGeometry( shapes, curveSegments ) {
  18575. BufferGeometry.call( this );
  18576. this.type = 'ShapeBufferGeometry';
  18577. this.parameters = {
  18578. shapes: shapes,
  18579. curveSegments: curveSegments
  18580. };
  18581. curveSegments = curveSegments || 12;
  18582. // buffers
  18583. var indices = [];
  18584. var vertices = [];
  18585. var normals = [];
  18586. var uvs = [];
  18587. // helper variables
  18588. var groupStart = 0;
  18589. var groupCount = 0;
  18590. // allow single and array values for "shapes" parameter
  18591. if ( Array.isArray( shapes ) === false ) {
  18592. addShape( shapes );
  18593. } else {
  18594. for ( var i = 0; i < shapes.length; i ++ ) {
  18595. addShape( shapes[ i ] );
  18596. this.addGroup( groupStart, groupCount, i ); // enables MultiMaterial support
  18597. groupStart += groupCount;
  18598. groupCount = 0;
  18599. }
  18600. }
  18601. // build geometry
  18602. this.setIndex( indices );
  18603. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  18604. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  18605. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  18606. // helper functions
  18607. function addShape( shape ) {
  18608. var i, l, shapeHole;
  18609. var indexOffset = vertices.length / 3;
  18610. var points = shape.extractPoints( curveSegments );
  18611. var shapeVertices = points.shape;
  18612. var shapeHoles = points.holes;
  18613. // check direction of vertices
  18614. if ( ShapeUtils.isClockWise( shapeVertices ) === false ) {
  18615. shapeVertices = shapeVertices.reverse();
  18616. }
  18617. for ( i = 0, l = shapeHoles.length; i < l; i ++ ) {
  18618. shapeHole = shapeHoles[ i ];
  18619. if ( ShapeUtils.isClockWise( shapeHole ) === true ) {
  18620. shapeHoles[ i ] = shapeHole.reverse();
  18621. }
  18622. }
  18623. var faces = ShapeUtils.triangulateShape( shapeVertices, shapeHoles );
  18624. // join vertices of inner and outer paths to a single array
  18625. for ( i = 0, l = shapeHoles.length; i < l; i ++ ) {
  18626. shapeHole = shapeHoles[ i ];
  18627. shapeVertices = shapeVertices.concat( shapeHole );
  18628. }
  18629. // vertices, normals, uvs
  18630. for ( i = 0, l = shapeVertices.length; i < l; i ++ ) {
  18631. var vertex = shapeVertices[ i ];
  18632. vertices.push( vertex.x, vertex.y, 0 );
  18633. normals.push( 0, 0, 1 );
  18634. uvs.push( vertex.x, vertex.y ); // world uvs
  18635. }
  18636. // incides
  18637. for ( i = 0, l = faces.length; i < l; i ++ ) {
  18638. var face = faces[ i ];
  18639. var a = face[ 0 ] + indexOffset;
  18640. var b = face[ 1 ] + indexOffset;
  18641. var c = face[ 2 ] + indexOffset;
  18642. indices.push( a, b, c );
  18643. groupCount += 3;
  18644. }
  18645. }
  18646. }
  18647. ShapeBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  18648. ShapeBufferGeometry.prototype.constructor = ShapeBufferGeometry;
  18649. ShapeBufferGeometry.prototype.toJSON = function () {
  18650. var data = BufferGeometry.prototype.toJSON.call( this );
  18651. var shapes = this.parameters.shapes;
  18652. return toJSON$1( shapes, data );
  18653. };
  18654. //
  18655. function toJSON$1( shapes, data ) {
  18656. data.shapes = [];
  18657. if ( Array.isArray( shapes ) ) {
  18658. for ( var i = 0, l = shapes.length; i < l; i ++ ) {
  18659. var shape = shapes[ i ];
  18660. data.shapes.push( shape.uuid );
  18661. }
  18662. } else {
  18663. data.shapes.push( shapes.uuid );
  18664. }
  18665. return data;
  18666. }
  18667. /**
  18668. * @author WestLangley / http://github.com/WestLangley
  18669. * @author Mugen87 / https://github.com/Mugen87
  18670. */
  18671. function EdgesGeometry( geometry, thresholdAngle ) {
  18672. BufferGeometry.call( this );
  18673. this.type = 'EdgesGeometry';
  18674. this.parameters = {
  18675. thresholdAngle: thresholdAngle
  18676. };
  18677. thresholdAngle = ( thresholdAngle !== undefined ) ? thresholdAngle : 1;
  18678. // buffer
  18679. var vertices = [];
  18680. // helper variables
  18681. var thresholdDot = Math.cos( _Math.DEG2RAD * thresholdAngle );
  18682. var edge = [ 0, 0 ], edges = {}, edge1, edge2;
  18683. var key, keys = [ 'a', 'b', 'c' ];
  18684. // prepare source geometry
  18685. var geometry2;
  18686. if ( geometry.isBufferGeometry ) {
  18687. geometry2 = new Geometry();
  18688. geometry2.fromBufferGeometry( geometry );
  18689. } else {
  18690. geometry2 = geometry.clone();
  18691. }
  18692. geometry2.mergeVertices();
  18693. geometry2.computeFaceNormals();
  18694. var sourceVertices = geometry2.vertices;
  18695. var faces = geometry2.faces;
  18696. // now create a data structure where each entry represents an edge with its adjoining faces
  18697. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  18698. var face = faces[ i ];
  18699. for ( var j = 0; j < 3; j ++ ) {
  18700. edge1 = face[ keys[ j ] ];
  18701. edge2 = face[ keys[ ( j + 1 ) % 3 ] ];
  18702. edge[ 0 ] = Math.min( edge1, edge2 );
  18703. edge[ 1 ] = Math.max( edge1, edge2 );
  18704. key = edge[ 0 ] + ',' + edge[ 1 ];
  18705. if ( edges[ key ] === undefined ) {
  18706. edges[ key ] = { index1: edge[ 0 ], index2: edge[ 1 ], face1: i, face2: undefined };
  18707. } else {
  18708. edges[ key ].face2 = i;
  18709. }
  18710. }
  18711. }
  18712. // generate vertices
  18713. for ( key in edges ) {
  18714. var e = edges[ key ];
  18715. // an edge is only rendered if the angle (in degrees) between the face normals of the adjoining faces exceeds this value. default = 1 degree.
  18716. if ( e.face2 === undefined || faces[ e.face1 ].normal.dot( faces[ e.face2 ].normal ) <= thresholdDot ) {
  18717. var vertex = sourceVertices[ e.index1 ];
  18718. vertices.push( vertex.x, vertex.y, vertex.z );
  18719. vertex = sourceVertices[ e.index2 ];
  18720. vertices.push( vertex.x, vertex.y, vertex.z );
  18721. }
  18722. }
  18723. // build geometry
  18724. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  18725. }
  18726. EdgesGeometry.prototype = Object.create( BufferGeometry.prototype );
  18727. EdgesGeometry.prototype.constructor = EdgesGeometry;
  18728. /**
  18729. * @author mrdoob / http://mrdoob.com/
  18730. * @author Mugen87 / https://github.com/Mugen87
  18731. */
  18732. // CylinderGeometry
  18733. function CylinderGeometry( radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  18734. Geometry.call( this );
  18735. this.type = 'CylinderGeometry';
  18736. this.parameters = {
  18737. radiusTop: radiusTop,
  18738. radiusBottom: radiusBottom,
  18739. height: height,
  18740. radialSegments: radialSegments,
  18741. heightSegments: heightSegments,
  18742. openEnded: openEnded,
  18743. thetaStart: thetaStart,
  18744. thetaLength: thetaLength
  18745. };
  18746. this.fromBufferGeometry( new CylinderBufferGeometry( radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) );
  18747. this.mergeVertices();
  18748. }
  18749. CylinderGeometry.prototype = Object.create( Geometry.prototype );
  18750. CylinderGeometry.prototype.constructor = CylinderGeometry;
  18751. // CylinderBufferGeometry
  18752. function CylinderBufferGeometry( radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  18753. BufferGeometry.call( this );
  18754. this.type = 'CylinderBufferGeometry';
  18755. this.parameters = {
  18756. radiusTop: radiusTop,
  18757. radiusBottom: radiusBottom,
  18758. height: height,
  18759. radialSegments: radialSegments,
  18760. heightSegments: heightSegments,
  18761. openEnded: openEnded,
  18762. thetaStart: thetaStart,
  18763. thetaLength: thetaLength
  18764. };
  18765. var scope = this;
  18766. radiusTop = radiusTop !== undefined ? radiusTop : 1;
  18767. radiusBottom = radiusBottom !== undefined ? radiusBottom : 1;
  18768. height = height || 1;
  18769. radialSegments = Math.floor( radialSegments ) || 8;
  18770. heightSegments = Math.floor( heightSegments ) || 1;
  18771. openEnded = openEnded !== undefined ? openEnded : false;
  18772. thetaStart = thetaStart !== undefined ? thetaStart : 0.0;
  18773. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  18774. // buffers
  18775. var indices = [];
  18776. var vertices = [];
  18777. var normals = [];
  18778. var uvs = [];
  18779. // helper variables
  18780. var index = 0;
  18781. var indexArray = [];
  18782. var halfHeight = height / 2;
  18783. var groupStart = 0;
  18784. // generate geometry
  18785. generateTorso();
  18786. if ( openEnded === false ) {
  18787. if ( radiusTop > 0 ) generateCap( true );
  18788. if ( radiusBottom > 0 ) generateCap( false );
  18789. }
  18790. // build geometry
  18791. this.setIndex( indices );
  18792. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  18793. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  18794. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  18795. function generateTorso() {
  18796. var x, y;
  18797. var normal = new Vector3();
  18798. var vertex = new Vector3();
  18799. var groupCount = 0;
  18800. // this will be used to calculate the normal
  18801. var slope = ( radiusBottom - radiusTop ) / height;
  18802. // generate vertices, normals and uvs
  18803. for ( y = 0; y <= heightSegments; y ++ ) {
  18804. var indexRow = [];
  18805. var v = y / heightSegments;
  18806. // calculate the radius of the current row
  18807. var radius = v * ( radiusBottom - radiusTop ) + radiusTop;
  18808. for ( x = 0; x <= radialSegments; x ++ ) {
  18809. var u = x / radialSegments;
  18810. var theta = u * thetaLength + thetaStart;
  18811. var sinTheta = Math.sin( theta );
  18812. var cosTheta = Math.cos( theta );
  18813. // vertex
  18814. vertex.x = radius * sinTheta;
  18815. vertex.y = - v * height + halfHeight;
  18816. vertex.z = radius * cosTheta;
  18817. vertices.push( vertex.x, vertex.y, vertex.z );
  18818. // normal
  18819. normal.set( sinTheta, slope, cosTheta ).normalize();
  18820. normals.push( normal.x, normal.y, normal.z );
  18821. // uv
  18822. uvs.push( u, 1 - v );
  18823. // save index of vertex in respective row
  18824. indexRow.push( index ++ );
  18825. }
  18826. // now save vertices of the row in our index array
  18827. indexArray.push( indexRow );
  18828. }
  18829. // generate indices
  18830. for ( x = 0; x < radialSegments; x ++ ) {
  18831. for ( y = 0; y < heightSegments; y ++ ) {
  18832. // we use the index array to access the correct indices
  18833. var a = indexArray[ y ][ x ];
  18834. var b = indexArray[ y + 1 ][ x ];
  18835. var c = indexArray[ y + 1 ][ x + 1 ];
  18836. var d = indexArray[ y ][ x + 1 ];
  18837. // faces
  18838. indices.push( a, b, d );
  18839. indices.push( b, c, d );
  18840. // update group counter
  18841. groupCount += 6;
  18842. }
  18843. }
  18844. // add a group to the geometry. this will ensure multi material support
  18845. scope.addGroup( groupStart, groupCount, 0 );
  18846. // calculate new start value for groups
  18847. groupStart += groupCount;
  18848. }
  18849. function generateCap( top ) {
  18850. var x, centerIndexStart, centerIndexEnd;
  18851. var uv = new Vector2();
  18852. var vertex = new Vector3();
  18853. var groupCount = 0;
  18854. var radius = ( top === true ) ? radiusTop : radiusBottom;
  18855. var sign = ( top === true ) ? 1 : - 1;
  18856. // save the index of the first center vertex
  18857. centerIndexStart = index;
  18858. // first we generate the center vertex data of the cap.
  18859. // because the geometry needs one set of uvs per face,
  18860. // we must generate a center vertex per face/segment
  18861. for ( x = 1; x <= radialSegments; x ++ ) {
  18862. // vertex
  18863. vertices.push( 0, halfHeight * sign, 0 );
  18864. // normal
  18865. normals.push( 0, sign, 0 );
  18866. // uv
  18867. uvs.push( 0.5, 0.5 );
  18868. // increase index
  18869. index ++;
  18870. }
  18871. // save the index of the last center vertex
  18872. centerIndexEnd = index;
  18873. // now we generate the surrounding vertices, normals and uvs
  18874. for ( x = 0; x <= radialSegments; x ++ ) {
  18875. var u = x / radialSegments;
  18876. var theta = u * thetaLength + thetaStart;
  18877. var cosTheta = Math.cos( theta );
  18878. var sinTheta = Math.sin( theta );
  18879. // vertex
  18880. vertex.x = radius * sinTheta;
  18881. vertex.y = halfHeight * sign;
  18882. vertex.z = radius * cosTheta;
  18883. vertices.push( vertex.x, vertex.y, vertex.z );
  18884. // normal
  18885. normals.push( 0, sign, 0 );
  18886. // uv
  18887. uv.x = ( cosTheta * 0.5 ) + 0.5;
  18888. uv.y = ( sinTheta * 0.5 * sign ) + 0.5;
  18889. uvs.push( uv.x, uv.y );
  18890. // increase index
  18891. index ++;
  18892. }
  18893. // generate indices
  18894. for ( x = 0; x < radialSegments; x ++ ) {
  18895. var c = centerIndexStart + x;
  18896. var i = centerIndexEnd + x;
  18897. if ( top === true ) {
  18898. // face top
  18899. indices.push( i, i + 1, c );
  18900. } else {
  18901. // face bottom
  18902. indices.push( i + 1, i, c );
  18903. }
  18904. groupCount += 3;
  18905. }
  18906. // add a group to the geometry. this will ensure multi material support
  18907. scope.addGroup( groupStart, groupCount, top === true ? 1 : 2 );
  18908. // calculate new start value for groups
  18909. groupStart += groupCount;
  18910. }
  18911. }
  18912. CylinderBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  18913. CylinderBufferGeometry.prototype.constructor = CylinderBufferGeometry;
  18914. /**
  18915. * @author abelnation / http://github.com/abelnation
  18916. */
  18917. // ConeGeometry
  18918. function ConeGeometry( radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  18919. CylinderGeometry.call( this, 0, radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength );
  18920. this.type = 'ConeGeometry';
  18921. this.parameters = {
  18922. radius: radius,
  18923. height: height,
  18924. radialSegments: radialSegments,
  18925. heightSegments: heightSegments,
  18926. openEnded: openEnded,
  18927. thetaStart: thetaStart,
  18928. thetaLength: thetaLength
  18929. };
  18930. }
  18931. ConeGeometry.prototype = Object.create( CylinderGeometry.prototype );
  18932. ConeGeometry.prototype.constructor = ConeGeometry;
  18933. // ConeBufferGeometry
  18934. function ConeBufferGeometry( radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  18935. CylinderBufferGeometry.call( this, 0, radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength );
  18936. this.type = 'ConeBufferGeometry';
  18937. this.parameters = {
  18938. radius: radius,
  18939. height: height,
  18940. radialSegments: radialSegments,
  18941. heightSegments: heightSegments,
  18942. openEnded: openEnded,
  18943. thetaStart: thetaStart,
  18944. thetaLength: thetaLength
  18945. };
  18946. }
  18947. ConeBufferGeometry.prototype = Object.create( CylinderBufferGeometry.prototype );
  18948. ConeBufferGeometry.prototype.constructor = ConeBufferGeometry;
  18949. /**
  18950. * @author benaadams / https://twitter.com/ben_a_adams
  18951. * @author Mugen87 / https://github.com/Mugen87
  18952. * @author hughes
  18953. */
  18954. // CircleGeometry
  18955. function CircleGeometry( radius, segments, thetaStart, thetaLength ) {
  18956. Geometry.call( this );
  18957. this.type = 'CircleGeometry';
  18958. this.parameters = {
  18959. radius: radius,
  18960. segments: segments,
  18961. thetaStart: thetaStart,
  18962. thetaLength: thetaLength
  18963. };
  18964. this.fromBufferGeometry( new CircleBufferGeometry( radius, segments, thetaStart, thetaLength ) );
  18965. this.mergeVertices();
  18966. }
  18967. CircleGeometry.prototype = Object.create( Geometry.prototype );
  18968. CircleGeometry.prototype.constructor = CircleGeometry;
  18969. // CircleBufferGeometry
  18970. function CircleBufferGeometry( radius, segments, thetaStart, thetaLength ) {
  18971. BufferGeometry.call( this );
  18972. this.type = 'CircleBufferGeometry';
  18973. this.parameters = {
  18974. radius: radius,
  18975. segments: segments,
  18976. thetaStart: thetaStart,
  18977. thetaLength: thetaLength
  18978. };
  18979. radius = radius || 1;
  18980. segments = segments !== undefined ? Math.max( 3, segments ) : 8;
  18981. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  18982. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  18983. // buffers
  18984. var indices = [];
  18985. var vertices = [];
  18986. var normals = [];
  18987. var uvs = [];
  18988. // helper variables
  18989. var i, s;
  18990. var vertex = new Vector3();
  18991. var uv = new Vector2();
  18992. // center point
  18993. vertices.push( 0, 0, 0 );
  18994. normals.push( 0, 0, 1 );
  18995. uvs.push( 0.5, 0.5 );
  18996. for ( s = 0, i = 3; s <= segments; s ++, i += 3 ) {
  18997. var segment = thetaStart + s / segments * thetaLength;
  18998. // vertex
  18999. vertex.x = radius * Math.cos( segment );
  19000. vertex.y = radius * Math.sin( segment );
  19001. vertices.push( vertex.x, vertex.y, vertex.z );
  19002. // normal
  19003. normals.push( 0, 0, 1 );
  19004. // uvs
  19005. uv.x = ( vertices[ i ] / radius + 1 ) / 2;
  19006. uv.y = ( vertices[ i + 1 ] / radius + 1 ) / 2;
  19007. uvs.push( uv.x, uv.y );
  19008. }
  19009. // indices
  19010. for ( i = 1; i <= segments; i ++ ) {
  19011. indices.push( i, i + 1, 0 );
  19012. }
  19013. // build geometry
  19014. this.setIndex( indices );
  19015. this.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  19016. this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  19017. this.addAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  19018. }
  19019. CircleBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  19020. CircleBufferGeometry.prototype.constructor = CircleBufferGeometry;
  19021. var Geometries = /*#__PURE__*/Object.freeze({
  19022. WireframeGeometry: WireframeGeometry,
  19023. ParametricGeometry: ParametricGeometry,
  19024. ParametricBufferGeometry: ParametricBufferGeometry,
  19025. TetrahedronGeometry: TetrahedronGeometry,
  19026. TetrahedronBufferGeometry: TetrahedronBufferGeometry,
  19027. OctahedronGeometry: OctahedronGeometry,
  19028. OctahedronBufferGeometry: OctahedronBufferGeometry,
  19029. IcosahedronGeometry: IcosahedronGeometry,
  19030. IcosahedronBufferGeometry: IcosahedronBufferGeometry,
  19031. DodecahedronGeometry: DodecahedronGeometry,
  19032. DodecahedronBufferGeometry: DodecahedronBufferGeometry,
  19033. PolyhedronGeometry: PolyhedronGeometry,
  19034. PolyhedronBufferGeometry: PolyhedronBufferGeometry,
  19035. TubeGeometry: TubeGeometry,
  19036. TubeBufferGeometry: TubeBufferGeometry,
  19037. TorusKnotGeometry: TorusKnotGeometry,
  19038. TorusKnotBufferGeometry: TorusKnotBufferGeometry,
  19039. TorusGeometry: TorusGeometry,
  19040. TorusBufferGeometry: TorusBufferGeometry,
  19041. TextGeometry: TextGeometry,
  19042. TextBufferGeometry: TextBufferGeometry,
  19043. SphereGeometry: SphereGeometry,
  19044. SphereBufferGeometry: SphereBufferGeometry,
  19045. RingGeometry: RingGeometry,
  19046. RingBufferGeometry: RingBufferGeometry,
  19047. PlaneGeometry: PlaneGeometry,
  19048. PlaneBufferGeometry: PlaneBufferGeometry,
  19049. LatheGeometry: LatheGeometry,
  19050. LatheBufferGeometry: LatheBufferGeometry,
  19051. ShapeGeometry: ShapeGeometry,
  19052. ShapeBufferGeometry: ShapeBufferGeometry,
  19053. ExtrudeGeometry: ExtrudeGeometry,
  19054. ExtrudeBufferGeometry: ExtrudeBufferGeometry,
  19055. EdgesGeometry: EdgesGeometry,
  19056. ConeGeometry: ConeGeometry,
  19057. ConeBufferGeometry: ConeBufferGeometry,
  19058. CylinderGeometry: CylinderGeometry,
  19059. CylinderBufferGeometry: CylinderBufferGeometry,
  19060. CircleGeometry: CircleGeometry,
  19061. CircleBufferGeometry: CircleBufferGeometry,
  19062. BoxGeometry: BoxGeometry,
  19063. BoxBufferGeometry: BoxBufferGeometry
  19064. });
  19065. /**
  19066. * @author mrdoob / http://mrdoob.com/
  19067. *
  19068. * parameters = {
  19069. * color: <THREE.Color>
  19070. * }
  19071. */
  19072. function ShadowMaterial( parameters ) {
  19073. Material.call( this );
  19074. this.type = 'ShadowMaterial';
  19075. this.color = new Color( 0x000000 );
  19076. this.transparent = true;
  19077. this.setValues( parameters );
  19078. }
  19079. ShadowMaterial.prototype = Object.create( Material.prototype );
  19080. ShadowMaterial.prototype.constructor = ShadowMaterial;
  19081. ShadowMaterial.prototype.isShadowMaterial = true;
  19082. ShadowMaterial.prototype.copy = function ( source ) {
  19083. Material.prototype.copy.call( this, source );
  19084. this.color.copy( source.color );
  19085. return this;
  19086. };
  19087. /**
  19088. * @author mrdoob / http://mrdoob.com/
  19089. */
  19090. function RawShaderMaterial( parameters ) {
  19091. ShaderMaterial.call( this, parameters );
  19092. this.type = 'RawShaderMaterial';
  19093. }
  19094. RawShaderMaterial.prototype = Object.create( ShaderMaterial.prototype );
  19095. RawShaderMaterial.prototype.constructor = RawShaderMaterial;
  19096. RawShaderMaterial.prototype.isRawShaderMaterial = true;
  19097. /**
  19098. * @author WestLangley / http://github.com/WestLangley
  19099. *
  19100. * parameters = {
  19101. * color: <hex>,
  19102. * roughness: <float>,
  19103. * metalness: <float>,
  19104. * opacity: <float>,
  19105. *
  19106. * map: new THREE.Texture( <Image> ),
  19107. *
  19108. * lightMap: new THREE.Texture( <Image> ),
  19109. * lightMapIntensity: <float>
  19110. *
  19111. * aoMap: new THREE.Texture( <Image> ),
  19112. * aoMapIntensity: <float>
  19113. *
  19114. * emissive: <hex>,
  19115. * emissiveIntensity: <float>
  19116. * emissiveMap: new THREE.Texture( <Image> ),
  19117. *
  19118. * bumpMap: new THREE.Texture( <Image> ),
  19119. * bumpScale: <float>,
  19120. *
  19121. * normalMap: new THREE.Texture( <Image> ),
  19122. * normalMapType: THREE.TangentSpaceNormalMap,
  19123. * normalScale: <Vector2>,
  19124. *
  19125. * displacementMap: new THREE.Texture( <Image> ),
  19126. * displacementScale: <float>,
  19127. * displacementBias: <float>,
  19128. *
  19129. * roughnessMap: new THREE.Texture( <Image> ),
  19130. *
  19131. * metalnessMap: new THREE.Texture( <Image> ),
  19132. *
  19133. * alphaMap: new THREE.Texture( <Image> ),
  19134. *
  19135. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  19136. * envMapIntensity: <float>
  19137. *
  19138. * refractionRatio: <float>,
  19139. *
  19140. * wireframe: <boolean>,
  19141. * wireframeLinewidth: <float>,
  19142. *
  19143. * skinning: <bool>,
  19144. * morphTargets: <bool>,
  19145. * morphNormals: <bool>
  19146. * }
  19147. */
  19148. function MeshStandardMaterial( parameters ) {
  19149. Material.call( this );
  19150. this.defines = { 'STANDARD': '' };
  19151. this.type = 'MeshStandardMaterial';
  19152. this.color = new Color( 0xffffff ); // diffuse
  19153. this.roughness = 0.5;
  19154. this.metalness = 0.5;
  19155. this.map = null;
  19156. this.lightMap = null;
  19157. this.lightMapIntensity = 1.0;
  19158. this.aoMap = null;
  19159. this.aoMapIntensity = 1.0;
  19160. this.emissive = new Color( 0x000000 );
  19161. this.emissiveIntensity = 1.0;
  19162. this.emissiveMap = null;
  19163. this.bumpMap = null;
  19164. this.bumpScale = 1;
  19165. this.normalMap = null;
  19166. this.normalMapType = TangentSpaceNormalMap;
  19167. this.normalScale = new Vector2( 1, 1 );
  19168. this.displacementMap = null;
  19169. this.displacementScale = 1;
  19170. this.displacementBias = 0;
  19171. this.roughnessMap = null;
  19172. this.metalnessMap = null;
  19173. this.alphaMap = null;
  19174. this.envMap = null;
  19175. this.envMapIntensity = 1.0;
  19176. this.refractionRatio = 0.98;
  19177. this.wireframe = false;
  19178. this.wireframeLinewidth = 1;
  19179. this.wireframeLinecap = 'round';
  19180. this.wireframeLinejoin = 'round';
  19181. this.skinning = false;
  19182. this.morphTargets = false;
  19183. this.morphNormals = false;
  19184. this.setValues( parameters );
  19185. }
  19186. MeshStandardMaterial.prototype = Object.create( Material.prototype );
  19187. MeshStandardMaterial.prototype.constructor = MeshStandardMaterial;
  19188. MeshStandardMaterial.prototype.isMeshStandardMaterial = true;
  19189. MeshStandardMaterial.prototype.copy = function ( source ) {
  19190. Material.prototype.copy.call( this, source );
  19191. this.defines = { 'STANDARD': '' };
  19192. this.color.copy( source.color );
  19193. this.roughness = source.roughness;
  19194. this.metalness = source.metalness;
  19195. this.map = source.map;
  19196. this.lightMap = source.lightMap;
  19197. this.lightMapIntensity = source.lightMapIntensity;
  19198. this.aoMap = source.aoMap;
  19199. this.aoMapIntensity = source.aoMapIntensity;
  19200. this.emissive.copy( source.emissive );
  19201. this.emissiveMap = source.emissiveMap;
  19202. this.emissiveIntensity = source.emissiveIntensity;
  19203. this.bumpMap = source.bumpMap;
  19204. this.bumpScale = source.bumpScale;
  19205. this.normalMap = source.normalMap;
  19206. this.normalMapType = source.normalMapType;
  19207. this.normalScale.copy( source.normalScale );
  19208. this.displacementMap = source.displacementMap;
  19209. this.displacementScale = source.displacementScale;
  19210. this.displacementBias = source.displacementBias;
  19211. this.roughnessMap = source.roughnessMap;
  19212. this.metalnessMap = source.metalnessMap;
  19213. this.alphaMap = source.alphaMap;
  19214. this.envMap = source.envMap;
  19215. this.envMapIntensity = source.envMapIntensity;
  19216. this.refractionRatio = source.refractionRatio;
  19217. this.wireframe = source.wireframe;
  19218. this.wireframeLinewidth = source.wireframeLinewidth;
  19219. this.wireframeLinecap = source.wireframeLinecap;
  19220. this.wireframeLinejoin = source.wireframeLinejoin;
  19221. this.skinning = source.skinning;
  19222. this.morphTargets = source.morphTargets;
  19223. this.morphNormals = source.morphNormals;
  19224. return this;
  19225. };
  19226. /**
  19227. * @author WestLangley / http://github.com/WestLangley
  19228. *
  19229. * parameters = {
  19230. * reflectivity: <float>
  19231. * clearCoat: <float>
  19232. * clearCoatRoughness: <float>
  19233. * }
  19234. */
  19235. function MeshPhysicalMaterial( parameters ) {
  19236. MeshStandardMaterial.call( this );
  19237. this.defines = { 'PHYSICAL': '' };
  19238. this.type = 'MeshPhysicalMaterial';
  19239. this.reflectivity = 0.5; // maps to F0 = 0.04
  19240. this.clearCoat = 0.0;
  19241. this.clearCoatRoughness = 0.0;
  19242. this.setValues( parameters );
  19243. }
  19244. MeshPhysicalMaterial.prototype = Object.create( MeshStandardMaterial.prototype );
  19245. MeshPhysicalMaterial.prototype.constructor = MeshPhysicalMaterial;
  19246. MeshPhysicalMaterial.prototype.isMeshPhysicalMaterial = true;
  19247. MeshPhysicalMaterial.prototype.copy = function ( source ) {
  19248. MeshStandardMaterial.prototype.copy.call( this, source );
  19249. this.defines = { 'PHYSICAL': '' };
  19250. this.reflectivity = source.reflectivity;
  19251. this.clearCoat = source.clearCoat;
  19252. this.clearCoatRoughness = source.clearCoatRoughness;
  19253. return this;
  19254. };
  19255. /**
  19256. * @author mrdoob / http://mrdoob.com/
  19257. * @author alteredq / http://alteredqualia.com/
  19258. *
  19259. * parameters = {
  19260. * color: <hex>,
  19261. * specular: <hex>,
  19262. * shininess: <float>,
  19263. * opacity: <float>,
  19264. *
  19265. * map: new THREE.Texture( <Image> ),
  19266. *
  19267. * lightMap: new THREE.Texture( <Image> ),
  19268. * lightMapIntensity: <float>
  19269. *
  19270. * aoMap: new THREE.Texture( <Image> ),
  19271. * aoMapIntensity: <float>
  19272. *
  19273. * emissive: <hex>,
  19274. * emissiveIntensity: <float>
  19275. * emissiveMap: new THREE.Texture( <Image> ),
  19276. *
  19277. * bumpMap: new THREE.Texture( <Image> ),
  19278. * bumpScale: <float>,
  19279. *
  19280. * normalMap: new THREE.Texture( <Image> ),
  19281. * normalMapType: THREE.TangentSpaceNormalMap,
  19282. * normalScale: <Vector2>,
  19283. *
  19284. * displacementMap: new THREE.Texture( <Image> ),
  19285. * displacementScale: <float>,
  19286. * displacementBias: <float>,
  19287. *
  19288. * specularMap: new THREE.Texture( <Image> ),
  19289. *
  19290. * alphaMap: new THREE.Texture( <Image> ),
  19291. *
  19292. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  19293. * combine: THREE.Multiply,
  19294. * reflectivity: <float>,
  19295. * refractionRatio: <float>,
  19296. *
  19297. * wireframe: <boolean>,
  19298. * wireframeLinewidth: <float>,
  19299. *
  19300. * skinning: <bool>,
  19301. * morphTargets: <bool>,
  19302. * morphNormals: <bool>
  19303. * }
  19304. */
  19305. function MeshPhongMaterial( parameters ) {
  19306. Material.call( this );
  19307. this.type = 'MeshPhongMaterial';
  19308. this.color = new Color( 0xffffff ); // diffuse
  19309. this.specular = new Color( 0x111111 );
  19310. this.shininess = 30;
  19311. this.map = null;
  19312. this.lightMap = null;
  19313. this.lightMapIntensity = 1.0;
  19314. this.aoMap = null;
  19315. this.aoMapIntensity = 1.0;
  19316. this.emissive = new Color( 0x000000 );
  19317. this.emissiveIntensity = 1.0;
  19318. this.emissiveMap = null;
  19319. this.bumpMap = null;
  19320. this.bumpScale = 1;
  19321. this.normalMap = null;
  19322. this.normalMapType = TangentSpaceNormalMap;
  19323. this.normalScale = new Vector2( 1, 1 );
  19324. this.displacementMap = null;
  19325. this.displacementScale = 1;
  19326. this.displacementBias = 0;
  19327. this.specularMap = null;
  19328. this.alphaMap = null;
  19329. this.envMap = null;
  19330. this.combine = MultiplyOperation;
  19331. this.reflectivity = 1;
  19332. this.refractionRatio = 0.98;
  19333. this.wireframe = false;
  19334. this.wireframeLinewidth = 1;
  19335. this.wireframeLinecap = 'round';
  19336. this.wireframeLinejoin = 'round';
  19337. this.skinning = false;
  19338. this.morphTargets = false;
  19339. this.morphNormals = false;
  19340. this.setValues( parameters );
  19341. }
  19342. MeshPhongMaterial.prototype = Object.create( Material.prototype );
  19343. MeshPhongMaterial.prototype.constructor = MeshPhongMaterial;
  19344. MeshPhongMaterial.prototype.isMeshPhongMaterial = true;
  19345. MeshPhongMaterial.prototype.copy = function ( source ) {
  19346. Material.prototype.copy.call( this, source );
  19347. this.color.copy( source.color );
  19348. this.specular.copy( source.specular );
  19349. this.shininess = source.shininess;
  19350. this.map = source.map;
  19351. this.lightMap = source.lightMap;
  19352. this.lightMapIntensity = source.lightMapIntensity;
  19353. this.aoMap = source.aoMap;
  19354. this.aoMapIntensity = source.aoMapIntensity;
  19355. this.emissive.copy( source.emissive );
  19356. this.emissiveMap = source.emissiveMap;
  19357. this.emissiveIntensity = source.emissiveIntensity;
  19358. this.bumpMap = source.bumpMap;
  19359. this.bumpScale = source.bumpScale;
  19360. this.normalMap = source.normalMap;
  19361. this.normalMapType = source.normalMapType;
  19362. this.normalScale.copy( source.normalScale );
  19363. this.displacementMap = source.displacementMap;
  19364. this.displacementScale = source.displacementScale;
  19365. this.displacementBias = source.displacementBias;
  19366. this.specularMap = source.specularMap;
  19367. this.alphaMap = source.alphaMap;
  19368. this.envMap = source.envMap;
  19369. this.combine = source.combine;
  19370. this.reflectivity = source.reflectivity;
  19371. this.refractionRatio = source.refractionRatio;
  19372. this.wireframe = source.wireframe;
  19373. this.wireframeLinewidth = source.wireframeLinewidth;
  19374. this.wireframeLinecap = source.wireframeLinecap;
  19375. this.wireframeLinejoin = source.wireframeLinejoin;
  19376. this.skinning = source.skinning;
  19377. this.morphTargets = source.morphTargets;
  19378. this.morphNormals = source.morphNormals;
  19379. return this;
  19380. };
  19381. /**
  19382. * @author takahirox / http://github.com/takahirox
  19383. *
  19384. * parameters = {
  19385. * gradientMap: new THREE.Texture( <Image> )
  19386. * }
  19387. */
  19388. function MeshToonMaterial( parameters ) {
  19389. MeshPhongMaterial.call( this );
  19390. this.defines = { 'TOON': '' };
  19391. this.type = 'MeshToonMaterial';
  19392. this.gradientMap = null;
  19393. this.setValues( parameters );
  19394. }
  19395. MeshToonMaterial.prototype = Object.create( MeshPhongMaterial.prototype );
  19396. MeshToonMaterial.prototype.constructor = MeshToonMaterial;
  19397. MeshToonMaterial.prototype.isMeshToonMaterial = true;
  19398. MeshToonMaterial.prototype.copy = function ( source ) {
  19399. MeshPhongMaterial.prototype.copy.call( this, source );
  19400. this.gradientMap = source.gradientMap;
  19401. return this;
  19402. };
  19403. /**
  19404. * @author mrdoob / http://mrdoob.com/
  19405. * @author WestLangley / http://github.com/WestLangley
  19406. *
  19407. * parameters = {
  19408. * opacity: <float>,
  19409. *
  19410. * bumpMap: new THREE.Texture( <Image> ),
  19411. * bumpScale: <float>,
  19412. *
  19413. * normalMap: new THREE.Texture( <Image> ),
  19414. * normalMapType: THREE.TangentSpaceNormalMap,
  19415. * normalScale: <Vector2>,
  19416. *
  19417. * displacementMap: new THREE.Texture( <Image> ),
  19418. * displacementScale: <float>,
  19419. * displacementBias: <float>,
  19420. *
  19421. * wireframe: <boolean>,
  19422. * wireframeLinewidth: <float>
  19423. *
  19424. * skinning: <bool>,
  19425. * morphTargets: <bool>,
  19426. * morphNormals: <bool>
  19427. * }
  19428. */
  19429. function MeshNormalMaterial( parameters ) {
  19430. Material.call( this );
  19431. this.type = 'MeshNormalMaterial';
  19432. this.bumpMap = null;
  19433. this.bumpScale = 1;
  19434. this.normalMap = null;
  19435. this.normalMapType = TangentSpaceNormalMap;
  19436. this.normalScale = new Vector2( 1, 1 );
  19437. this.displacementMap = null;
  19438. this.displacementScale = 1;
  19439. this.displacementBias = 0;
  19440. this.wireframe = false;
  19441. this.wireframeLinewidth = 1;
  19442. this.fog = false;
  19443. this.lights = false;
  19444. this.skinning = false;
  19445. this.morphTargets = false;
  19446. this.morphNormals = false;
  19447. this.setValues( parameters );
  19448. }
  19449. MeshNormalMaterial.prototype = Object.create( Material.prototype );
  19450. MeshNormalMaterial.prototype.constructor = MeshNormalMaterial;
  19451. MeshNormalMaterial.prototype.isMeshNormalMaterial = true;
  19452. MeshNormalMaterial.prototype.copy = function ( source ) {
  19453. Material.prototype.copy.call( this, source );
  19454. this.bumpMap = source.bumpMap;
  19455. this.bumpScale = source.bumpScale;
  19456. this.normalMap = source.normalMap;
  19457. this.normalMapType = source.normalMapType;
  19458. this.normalScale.copy( source.normalScale );
  19459. this.displacementMap = source.displacementMap;
  19460. this.displacementScale = source.displacementScale;
  19461. this.displacementBias = source.displacementBias;
  19462. this.wireframe = source.wireframe;
  19463. this.wireframeLinewidth = source.wireframeLinewidth;
  19464. this.skinning = source.skinning;
  19465. this.morphTargets = source.morphTargets;
  19466. this.morphNormals = source.morphNormals;
  19467. return this;
  19468. };
  19469. /**
  19470. * @author mrdoob / http://mrdoob.com/
  19471. * @author alteredq / http://alteredqualia.com/
  19472. *
  19473. * parameters = {
  19474. * color: <hex>,
  19475. * opacity: <float>,
  19476. *
  19477. * map: new THREE.Texture( <Image> ),
  19478. *
  19479. * lightMap: new THREE.Texture( <Image> ),
  19480. * lightMapIntensity: <float>
  19481. *
  19482. * aoMap: new THREE.Texture( <Image> ),
  19483. * aoMapIntensity: <float>
  19484. *
  19485. * emissive: <hex>,
  19486. * emissiveIntensity: <float>
  19487. * emissiveMap: new THREE.Texture( <Image> ),
  19488. *
  19489. * specularMap: new THREE.Texture( <Image> ),
  19490. *
  19491. * alphaMap: new THREE.Texture( <Image> ),
  19492. *
  19493. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  19494. * combine: THREE.Multiply,
  19495. * reflectivity: <float>,
  19496. * refractionRatio: <float>,
  19497. *
  19498. * wireframe: <boolean>,
  19499. * wireframeLinewidth: <float>,
  19500. *
  19501. * skinning: <bool>,
  19502. * morphTargets: <bool>,
  19503. * morphNormals: <bool>
  19504. * }
  19505. */
  19506. function MeshLambertMaterial( parameters ) {
  19507. Material.call( this );
  19508. this.type = 'MeshLambertMaterial';
  19509. this.color = new Color( 0xffffff ); // diffuse
  19510. this.map = null;
  19511. this.lightMap = null;
  19512. this.lightMapIntensity = 1.0;
  19513. this.aoMap = null;
  19514. this.aoMapIntensity = 1.0;
  19515. this.emissive = new Color( 0x000000 );
  19516. this.emissiveIntensity = 1.0;
  19517. this.emissiveMap = null;
  19518. this.specularMap = null;
  19519. this.alphaMap = null;
  19520. this.envMap = null;
  19521. this.combine = MultiplyOperation;
  19522. this.reflectivity = 1;
  19523. this.refractionRatio = 0.98;
  19524. this.wireframe = false;
  19525. this.wireframeLinewidth = 1;
  19526. this.wireframeLinecap = 'round';
  19527. this.wireframeLinejoin = 'round';
  19528. this.skinning = false;
  19529. this.morphTargets = false;
  19530. this.morphNormals = false;
  19531. this.setValues( parameters );
  19532. }
  19533. MeshLambertMaterial.prototype = Object.create( Material.prototype );
  19534. MeshLambertMaterial.prototype.constructor = MeshLambertMaterial;
  19535. MeshLambertMaterial.prototype.isMeshLambertMaterial = true;
  19536. MeshLambertMaterial.prototype.copy = function ( source ) {
  19537. Material.prototype.copy.call( this, source );
  19538. this.color.copy( source.color );
  19539. this.map = source.map;
  19540. this.lightMap = source.lightMap;
  19541. this.lightMapIntensity = source.lightMapIntensity;
  19542. this.aoMap = source.aoMap;
  19543. this.aoMapIntensity = source.aoMapIntensity;
  19544. this.emissive.copy( source.emissive );
  19545. this.emissiveMap = source.emissiveMap;
  19546. this.emissiveIntensity = source.emissiveIntensity;
  19547. this.specularMap = source.specularMap;
  19548. this.alphaMap = source.alphaMap;
  19549. this.envMap = source.envMap;
  19550. this.combine = source.combine;
  19551. this.reflectivity = source.reflectivity;
  19552. this.refractionRatio = source.refractionRatio;
  19553. this.wireframe = source.wireframe;
  19554. this.wireframeLinewidth = source.wireframeLinewidth;
  19555. this.wireframeLinecap = source.wireframeLinecap;
  19556. this.wireframeLinejoin = source.wireframeLinejoin;
  19557. this.skinning = source.skinning;
  19558. this.morphTargets = source.morphTargets;
  19559. this.morphNormals = source.morphNormals;
  19560. return this;
  19561. };
  19562. /**
  19563. * @author WestLangley / http://github.com/WestLangley
  19564. *
  19565. * parameters = {
  19566. * color: <hex>,
  19567. * opacity: <float>,
  19568. *
  19569. * matcap: new THREE.Texture( <Image> ),
  19570. *
  19571. * map: new THREE.Texture( <Image> ),
  19572. *
  19573. * bumpMap: new THREE.Texture( <Image> ),
  19574. * bumpScale: <float>,
  19575. *
  19576. * normalMap: new THREE.Texture( <Image> ),
  19577. * normalMapType: THREE.TangentSpaceNormalMap,
  19578. * normalScale: <Vector2>,
  19579. *
  19580. * displacementMap: new THREE.Texture( <Image> ),
  19581. * displacementScale: <float>,
  19582. * displacementBias: <float>,
  19583. *
  19584. * alphaMap: new THREE.Texture( <Image> ),
  19585. *
  19586. * skinning: <bool>,
  19587. * morphTargets: <bool>,
  19588. * morphNormals: <bool>
  19589. * }
  19590. */
  19591. function MeshMatcapMaterial( parameters ) {
  19592. Material.call( this );
  19593. this.defines = { 'MATCAP': '' };
  19594. this.type = 'MeshMatcapMaterial';
  19595. this.color = new Color( 0xffffff ); // diffuse
  19596. this.matcap = null;
  19597. this.map = null;
  19598. this.bumpMap = null;
  19599. this.bumpScale = 1;
  19600. this.normalMap = null;
  19601. this.normalMapType = TangentSpaceNormalMap;
  19602. this.normalScale = new Vector2( 1, 1 );
  19603. this.displacementMap = null;
  19604. this.displacementScale = 1;
  19605. this.displacementBias = 0;
  19606. this.alphaMap = null;
  19607. this.skinning = false;
  19608. this.morphTargets = false;
  19609. this.morphNormals = false;
  19610. this.lights = false;
  19611. this.setValues( parameters );
  19612. }
  19613. MeshMatcapMaterial.prototype = Object.create( Material.prototype );
  19614. MeshMatcapMaterial.prototype.constructor = MeshMatcapMaterial;
  19615. MeshMatcapMaterial.prototype.isMeshMatcapMaterial = true;
  19616. MeshMatcapMaterial.prototype.copy = function ( source ) {
  19617. Material.prototype.copy.call( this, source );
  19618. this.defines = { 'MATCAP': '' };
  19619. this.color.copy( source.color );
  19620. this.matcap = source.matcap;
  19621. this.map = source.map;
  19622. this.bumpMap = source.bumpMap;
  19623. this.bumpScale = source.bumpScale;
  19624. this.normalMap = source.normalMap;
  19625. this.normalMapType = source.normalMapType;
  19626. this.normalScale.copy( source.normalScale );
  19627. this.displacementMap = source.displacementMap;
  19628. this.displacementScale = source.displacementScale;
  19629. this.displacementBias = source.displacementBias;
  19630. this.alphaMap = source.alphaMap;
  19631. this.skinning = source.skinning;
  19632. this.morphTargets = source.morphTargets;
  19633. this.morphNormals = source.morphNormals;
  19634. return this;
  19635. };
  19636. /**
  19637. * @author alteredq / http://alteredqualia.com/
  19638. *
  19639. * parameters = {
  19640. * color: <hex>,
  19641. * opacity: <float>,
  19642. *
  19643. * linewidth: <float>,
  19644. *
  19645. * scale: <float>,
  19646. * dashSize: <float>,
  19647. * gapSize: <float>
  19648. * }
  19649. */
  19650. function LineDashedMaterial( parameters ) {
  19651. LineBasicMaterial.call( this );
  19652. this.type = 'LineDashedMaterial';
  19653. this.scale = 1;
  19654. this.dashSize = 3;
  19655. this.gapSize = 1;
  19656. this.setValues( parameters );
  19657. }
  19658. LineDashedMaterial.prototype = Object.create( LineBasicMaterial.prototype );
  19659. LineDashedMaterial.prototype.constructor = LineDashedMaterial;
  19660. LineDashedMaterial.prototype.isLineDashedMaterial = true;
  19661. LineDashedMaterial.prototype.copy = function ( source ) {
  19662. LineBasicMaterial.prototype.copy.call( this, source );
  19663. this.scale = source.scale;
  19664. this.dashSize = source.dashSize;
  19665. this.gapSize = source.gapSize;
  19666. return this;
  19667. };
  19668. var Materials = /*#__PURE__*/Object.freeze({
  19669. ShadowMaterial: ShadowMaterial,
  19670. SpriteMaterial: SpriteMaterial,
  19671. RawShaderMaterial: RawShaderMaterial,
  19672. ShaderMaterial: ShaderMaterial,
  19673. PointsMaterial: PointsMaterial,
  19674. MeshPhysicalMaterial: MeshPhysicalMaterial,
  19675. MeshStandardMaterial: MeshStandardMaterial,
  19676. MeshPhongMaterial: MeshPhongMaterial,
  19677. MeshToonMaterial: MeshToonMaterial,
  19678. MeshNormalMaterial: MeshNormalMaterial,
  19679. MeshLambertMaterial: MeshLambertMaterial,
  19680. MeshDepthMaterial: MeshDepthMaterial,
  19681. MeshDistanceMaterial: MeshDistanceMaterial,
  19682. MeshBasicMaterial: MeshBasicMaterial,
  19683. MeshMatcapMaterial: MeshMatcapMaterial,
  19684. LineDashedMaterial: LineDashedMaterial,
  19685. LineBasicMaterial: LineBasicMaterial,
  19686. Material: Material
  19687. });
  19688. /**
  19689. * @author tschw
  19690. * @author Ben Houston / http://clara.io/
  19691. * @author David Sarno / http://lighthaus.us/
  19692. */
  19693. var AnimationUtils = {
  19694. // same as Array.prototype.slice, but also works on typed arrays
  19695. arraySlice: function ( array, from, to ) {
  19696. if ( AnimationUtils.isTypedArray( array ) ) {
  19697. // in ios9 array.subarray(from, undefined) will return empty array
  19698. // but array.subarray(from) or array.subarray(from, len) is correct
  19699. return new array.constructor( array.subarray( from, to !== undefined ? to : array.length ) );
  19700. }
  19701. return array.slice( from, to );
  19702. },
  19703. // converts an array to a specific type
  19704. convertArray: function ( array, type, forceClone ) {
  19705. if ( ! array || // let 'undefined' and 'null' pass
  19706. ! forceClone && array.constructor === type ) return array;
  19707. if ( typeof type.BYTES_PER_ELEMENT === 'number' ) {
  19708. return new type( array ); // create typed array
  19709. }
  19710. return Array.prototype.slice.call( array ); // create Array
  19711. },
  19712. isTypedArray: function ( object ) {
  19713. return ArrayBuffer.isView( object ) &&
  19714. ! ( object instanceof DataView );
  19715. },
  19716. // returns an array by which times and values can be sorted
  19717. getKeyframeOrder: function ( times ) {
  19718. function compareTime( i, j ) {
  19719. return times[ i ] - times[ j ];
  19720. }
  19721. var n = times.length;
  19722. var result = new Array( n );
  19723. for ( var i = 0; i !== n; ++ i ) result[ i ] = i;
  19724. result.sort( compareTime );
  19725. return result;
  19726. },
  19727. // uses the array previously returned by 'getKeyframeOrder' to sort data
  19728. sortedArray: function ( values, stride, order ) {
  19729. var nValues = values.length;
  19730. var result = new values.constructor( nValues );
  19731. for ( var i = 0, dstOffset = 0; dstOffset !== nValues; ++ i ) {
  19732. var srcOffset = order[ i ] * stride;
  19733. for ( var j = 0; j !== stride; ++ j ) {
  19734. result[ dstOffset ++ ] = values[ srcOffset + j ];
  19735. }
  19736. }
  19737. return result;
  19738. },
  19739. // function for parsing AOS keyframe formats
  19740. flattenJSON: function ( jsonKeys, times, values, valuePropertyName ) {
  19741. var i = 1, key = jsonKeys[ 0 ];
  19742. while ( key !== undefined && key[ valuePropertyName ] === undefined ) {
  19743. key = jsonKeys[ i ++ ];
  19744. }
  19745. if ( key === undefined ) return; // no data
  19746. var value = key[ valuePropertyName ];
  19747. if ( value === undefined ) return; // no data
  19748. if ( Array.isArray( value ) ) {
  19749. do {
  19750. value = key[ valuePropertyName ];
  19751. if ( value !== undefined ) {
  19752. times.push( key.time );
  19753. values.push.apply( values, value ); // push all elements
  19754. }
  19755. key = jsonKeys[ i ++ ];
  19756. } while ( key !== undefined );
  19757. } else if ( value.toArray !== undefined ) {
  19758. // ...assume THREE.Math-ish
  19759. do {
  19760. value = key[ valuePropertyName ];
  19761. if ( value !== undefined ) {
  19762. times.push( key.time );
  19763. value.toArray( values, values.length );
  19764. }
  19765. key = jsonKeys[ i ++ ];
  19766. } while ( key !== undefined );
  19767. } else {
  19768. // otherwise push as-is
  19769. do {
  19770. value = key[ valuePropertyName ];
  19771. if ( value !== undefined ) {
  19772. times.push( key.time );
  19773. values.push( value );
  19774. }
  19775. key = jsonKeys[ i ++ ];
  19776. } while ( key !== undefined );
  19777. }
  19778. }
  19779. };
  19780. /**
  19781. * Abstract base class of interpolants over parametric samples.
  19782. *
  19783. * The parameter domain is one dimensional, typically the time or a path
  19784. * along a curve defined by the data.
  19785. *
  19786. * The sample values can have any dimensionality and derived classes may
  19787. * apply special interpretations to the data.
  19788. *
  19789. * This class provides the interval seek in a Template Method, deferring
  19790. * the actual interpolation to derived classes.
  19791. *
  19792. * Time complexity is O(1) for linear access crossing at most two points
  19793. * and O(log N) for random access, where N is the number of positions.
  19794. *
  19795. * References:
  19796. *
  19797. * http://www.oodesign.com/template-method-pattern.html
  19798. *
  19799. * @author tschw
  19800. */
  19801. function Interpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  19802. this.parameterPositions = parameterPositions;
  19803. this._cachedIndex = 0;
  19804. this.resultBuffer = resultBuffer !== undefined ?
  19805. resultBuffer : new sampleValues.constructor( sampleSize );
  19806. this.sampleValues = sampleValues;
  19807. this.valueSize = sampleSize;
  19808. }
  19809. Object.assign( Interpolant.prototype, {
  19810. evaluate: function ( t ) {
  19811. var pp = this.parameterPositions,
  19812. i1 = this._cachedIndex,
  19813. t1 = pp[ i1 ],
  19814. t0 = pp[ i1 - 1 ];
  19815. validate_interval: {
  19816. seek: {
  19817. var right;
  19818. linear_scan: {
  19819. //- See http://jsperf.com/comparison-to-undefined/3
  19820. //- slower code:
  19821. //-
  19822. //- if ( t >= t1 || t1 === undefined ) {
  19823. forward_scan: if ( ! ( t < t1 ) ) {
  19824. for ( var giveUpAt = i1 + 2; ; ) {
  19825. if ( t1 === undefined ) {
  19826. if ( t < t0 ) break forward_scan;
  19827. // after end
  19828. i1 = pp.length;
  19829. this._cachedIndex = i1;
  19830. return this.afterEnd_( i1 - 1, t, t0 );
  19831. }
  19832. if ( i1 === giveUpAt ) break; // this loop
  19833. t0 = t1;
  19834. t1 = pp[ ++ i1 ];
  19835. if ( t < t1 ) {
  19836. // we have arrived at the sought interval
  19837. break seek;
  19838. }
  19839. }
  19840. // prepare binary search on the right side of the index
  19841. right = pp.length;
  19842. break linear_scan;
  19843. }
  19844. //- slower code:
  19845. //- if ( t < t0 || t0 === undefined ) {
  19846. if ( ! ( t >= t0 ) ) {
  19847. // looping?
  19848. var t1global = pp[ 1 ];
  19849. if ( t < t1global ) {
  19850. i1 = 2; // + 1, using the scan for the details
  19851. t0 = t1global;
  19852. }
  19853. // linear reverse scan
  19854. for ( var giveUpAt = i1 - 2; ; ) {
  19855. if ( t0 === undefined ) {
  19856. // before start
  19857. this._cachedIndex = 0;
  19858. return this.beforeStart_( 0, t, t1 );
  19859. }
  19860. if ( i1 === giveUpAt ) break; // this loop
  19861. t1 = t0;
  19862. t0 = pp[ -- i1 - 1 ];
  19863. if ( t >= t0 ) {
  19864. // we have arrived at the sought interval
  19865. break seek;
  19866. }
  19867. }
  19868. // prepare binary search on the left side of the index
  19869. right = i1;
  19870. i1 = 0;
  19871. break linear_scan;
  19872. }
  19873. // the interval is valid
  19874. break validate_interval;
  19875. } // linear scan
  19876. // binary search
  19877. while ( i1 < right ) {
  19878. var mid = ( i1 + right ) >>> 1;
  19879. if ( t < pp[ mid ] ) {
  19880. right = mid;
  19881. } else {
  19882. i1 = mid + 1;
  19883. }
  19884. }
  19885. t1 = pp[ i1 ];
  19886. t0 = pp[ i1 - 1 ];
  19887. // check boundary cases, again
  19888. if ( t0 === undefined ) {
  19889. this._cachedIndex = 0;
  19890. return this.beforeStart_( 0, t, t1 );
  19891. }
  19892. if ( t1 === undefined ) {
  19893. i1 = pp.length;
  19894. this._cachedIndex = i1;
  19895. return this.afterEnd_( i1 - 1, t0, t );
  19896. }
  19897. } // seek
  19898. this._cachedIndex = i1;
  19899. this.intervalChanged_( i1, t0, t1 );
  19900. } // validate_interval
  19901. return this.interpolate_( i1, t0, t, t1 );
  19902. },
  19903. settings: null, // optional, subclass-specific settings structure
  19904. // Note: The indirection allows central control of many interpolants.
  19905. // --- Protected interface
  19906. DefaultSettings_: {},
  19907. getSettings_: function () {
  19908. return this.settings || this.DefaultSettings_;
  19909. },
  19910. copySampleValue_: function ( index ) {
  19911. // copies a sample value to the result buffer
  19912. var result = this.resultBuffer,
  19913. values = this.sampleValues,
  19914. stride = this.valueSize,
  19915. offset = index * stride;
  19916. for ( var i = 0; i !== stride; ++ i ) {
  19917. result[ i ] = values[ offset + i ];
  19918. }
  19919. return result;
  19920. },
  19921. // Template methods for derived classes:
  19922. interpolate_: function ( /* i1, t0, t, t1 */ ) {
  19923. throw new Error( 'call to abstract method' );
  19924. // implementations shall return this.resultBuffer
  19925. },
  19926. intervalChanged_: function ( /* i1, t0, t1 */ ) {
  19927. // empty
  19928. }
  19929. } );
  19930. //!\ DECLARE ALIAS AFTER assign prototype !
  19931. Object.assign( Interpolant.prototype, {
  19932. //( 0, t, t0 ), returns this.resultBuffer
  19933. beforeStart_: Interpolant.prototype.copySampleValue_,
  19934. //( N-1, tN-1, t ), returns this.resultBuffer
  19935. afterEnd_: Interpolant.prototype.copySampleValue_,
  19936. } );
  19937. /**
  19938. * Fast and simple cubic spline interpolant.
  19939. *
  19940. * It was derived from a Hermitian construction setting the first derivative
  19941. * at each sample position to the linear slope between neighboring positions
  19942. * over their parameter interval.
  19943. *
  19944. * @author tschw
  19945. */
  19946. function CubicInterpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  19947. Interpolant.call( this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  19948. this._weightPrev = - 0;
  19949. this._offsetPrev = - 0;
  19950. this._weightNext = - 0;
  19951. this._offsetNext = - 0;
  19952. }
  19953. CubicInterpolant.prototype = Object.assign( Object.create( Interpolant.prototype ), {
  19954. constructor: CubicInterpolant,
  19955. DefaultSettings_: {
  19956. endingStart: ZeroCurvatureEnding,
  19957. endingEnd: ZeroCurvatureEnding
  19958. },
  19959. intervalChanged_: function ( i1, t0, t1 ) {
  19960. var pp = this.parameterPositions,
  19961. iPrev = i1 - 2,
  19962. iNext = i1 + 1,
  19963. tPrev = pp[ iPrev ],
  19964. tNext = pp[ iNext ];
  19965. if ( tPrev === undefined ) {
  19966. switch ( this.getSettings_().endingStart ) {
  19967. case ZeroSlopeEnding:
  19968. // f'(t0) = 0
  19969. iPrev = i1;
  19970. tPrev = 2 * t0 - t1;
  19971. break;
  19972. case WrapAroundEnding:
  19973. // use the other end of the curve
  19974. iPrev = pp.length - 2;
  19975. tPrev = t0 + pp[ iPrev ] - pp[ iPrev + 1 ];
  19976. break;
  19977. default: // ZeroCurvatureEnding
  19978. // f''(t0) = 0 a.k.a. Natural Spline
  19979. iPrev = i1;
  19980. tPrev = t1;
  19981. }
  19982. }
  19983. if ( tNext === undefined ) {
  19984. switch ( this.getSettings_().endingEnd ) {
  19985. case ZeroSlopeEnding:
  19986. // f'(tN) = 0
  19987. iNext = i1;
  19988. tNext = 2 * t1 - t0;
  19989. break;
  19990. case WrapAroundEnding:
  19991. // use the other end of the curve
  19992. iNext = 1;
  19993. tNext = t1 + pp[ 1 ] - pp[ 0 ];
  19994. break;
  19995. default: // ZeroCurvatureEnding
  19996. // f''(tN) = 0, a.k.a. Natural Spline
  19997. iNext = i1 - 1;
  19998. tNext = t0;
  19999. }
  20000. }
  20001. var halfDt = ( t1 - t0 ) * 0.5,
  20002. stride = this.valueSize;
  20003. this._weightPrev = halfDt / ( t0 - tPrev );
  20004. this._weightNext = halfDt / ( tNext - t1 );
  20005. this._offsetPrev = iPrev * stride;
  20006. this._offsetNext = iNext * stride;
  20007. },
  20008. interpolate_: function ( i1, t0, t, t1 ) {
  20009. var result = this.resultBuffer,
  20010. values = this.sampleValues,
  20011. stride = this.valueSize,
  20012. o1 = i1 * stride, o0 = o1 - stride,
  20013. oP = this._offsetPrev, oN = this._offsetNext,
  20014. wP = this._weightPrev, wN = this._weightNext,
  20015. p = ( t - t0 ) / ( t1 - t0 ),
  20016. pp = p * p,
  20017. ppp = pp * p;
  20018. // evaluate polynomials
  20019. var sP = - wP * ppp + 2 * wP * pp - wP * p;
  20020. var s0 = ( 1 + wP ) * ppp + ( - 1.5 - 2 * wP ) * pp + ( - 0.5 + wP ) * p + 1;
  20021. var s1 = ( - 1 - wN ) * ppp + ( 1.5 + wN ) * pp + 0.5 * p;
  20022. var sN = wN * ppp - wN * pp;
  20023. // combine data linearly
  20024. for ( var i = 0; i !== stride; ++ i ) {
  20025. result[ i ] =
  20026. sP * values[ oP + i ] +
  20027. s0 * values[ o0 + i ] +
  20028. s1 * values[ o1 + i ] +
  20029. sN * values[ oN + i ];
  20030. }
  20031. return result;
  20032. }
  20033. } );
  20034. /**
  20035. * @author tschw
  20036. */
  20037. function LinearInterpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  20038. Interpolant.call( this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  20039. }
  20040. LinearInterpolant.prototype = Object.assign( Object.create( Interpolant.prototype ), {
  20041. constructor: LinearInterpolant,
  20042. interpolate_: function ( i1, t0, t, t1 ) {
  20043. var result = this.resultBuffer,
  20044. values = this.sampleValues,
  20045. stride = this.valueSize,
  20046. offset1 = i1 * stride,
  20047. offset0 = offset1 - stride,
  20048. weight1 = ( t - t0 ) / ( t1 - t0 ),
  20049. weight0 = 1 - weight1;
  20050. for ( var i = 0; i !== stride; ++ i ) {
  20051. result[ i ] =
  20052. values[ offset0 + i ] * weight0 +
  20053. values[ offset1 + i ] * weight1;
  20054. }
  20055. return result;
  20056. }
  20057. } );
  20058. /**
  20059. *
  20060. * Interpolant that evaluates to the sample value at the position preceeding
  20061. * the parameter.
  20062. *
  20063. * @author tschw
  20064. */
  20065. function DiscreteInterpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  20066. Interpolant.call( this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  20067. }
  20068. DiscreteInterpolant.prototype = Object.assign( Object.create( Interpolant.prototype ), {
  20069. constructor: DiscreteInterpolant,
  20070. interpolate_: function ( i1 /*, t0, t, t1 */ ) {
  20071. return this.copySampleValue_( i1 - 1 );
  20072. }
  20073. } );
  20074. /**
  20075. *
  20076. * A timed sequence of keyframes for a specific property.
  20077. *
  20078. *
  20079. * @author Ben Houston / http://clara.io/
  20080. * @author David Sarno / http://lighthaus.us/
  20081. * @author tschw
  20082. */
  20083. function KeyframeTrack( name, times, values, interpolation ) {
  20084. if ( name === undefined ) throw new Error( 'THREE.KeyframeTrack: track name is undefined' );
  20085. if ( times === undefined || times.length === 0 ) throw new Error( 'THREE.KeyframeTrack: no keyframes in track named ' + name );
  20086. this.name = name;
  20087. this.times = AnimationUtils.convertArray( times, this.TimeBufferType );
  20088. this.values = AnimationUtils.convertArray( values, this.ValueBufferType );
  20089. this.setInterpolation( interpolation || this.DefaultInterpolation );
  20090. }
  20091. // Static methods
  20092. Object.assign( KeyframeTrack, {
  20093. // Serialization (in static context, because of constructor invocation
  20094. // and automatic invocation of .toJSON):
  20095. toJSON: function ( track ) {
  20096. var trackType = track.constructor;
  20097. var json;
  20098. // derived classes can define a static toJSON method
  20099. if ( trackType.toJSON !== undefined ) {
  20100. json = trackType.toJSON( track );
  20101. } else {
  20102. // by default, we assume the data can be serialized as-is
  20103. json = {
  20104. 'name': track.name,
  20105. 'times': AnimationUtils.convertArray( track.times, Array ),
  20106. 'values': AnimationUtils.convertArray( track.values, Array )
  20107. };
  20108. var interpolation = track.getInterpolation();
  20109. if ( interpolation !== track.DefaultInterpolation ) {
  20110. json.interpolation = interpolation;
  20111. }
  20112. }
  20113. json.type = track.ValueTypeName; // mandatory
  20114. return json;
  20115. }
  20116. } );
  20117. Object.assign( KeyframeTrack.prototype, {
  20118. constructor: KeyframeTrack,
  20119. TimeBufferType: Float32Array,
  20120. ValueBufferType: Float32Array,
  20121. DefaultInterpolation: InterpolateLinear,
  20122. InterpolantFactoryMethodDiscrete: function ( result ) {
  20123. return new DiscreteInterpolant( this.times, this.values, this.getValueSize(), result );
  20124. },
  20125. InterpolantFactoryMethodLinear: function ( result ) {
  20126. return new LinearInterpolant( this.times, this.values, this.getValueSize(), result );
  20127. },
  20128. InterpolantFactoryMethodSmooth: function ( result ) {
  20129. return new CubicInterpolant( this.times, this.values, this.getValueSize(), result );
  20130. },
  20131. setInterpolation: function ( interpolation ) {
  20132. var factoryMethod;
  20133. switch ( interpolation ) {
  20134. case InterpolateDiscrete:
  20135. factoryMethod = this.InterpolantFactoryMethodDiscrete;
  20136. break;
  20137. case InterpolateLinear:
  20138. factoryMethod = this.InterpolantFactoryMethodLinear;
  20139. break;
  20140. case InterpolateSmooth:
  20141. factoryMethod = this.InterpolantFactoryMethodSmooth;
  20142. break;
  20143. }
  20144. if ( factoryMethod === undefined ) {
  20145. var message = "unsupported interpolation for " +
  20146. this.ValueTypeName + " keyframe track named " + this.name;
  20147. if ( this.createInterpolant === undefined ) {
  20148. // fall back to default, unless the default itself is messed up
  20149. if ( interpolation !== this.DefaultInterpolation ) {
  20150. this.setInterpolation( this.DefaultInterpolation );
  20151. } else {
  20152. throw new Error( message ); // fatal, in this case
  20153. }
  20154. }
  20155. console.warn( 'THREE.KeyframeTrack:', message );
  20156. return this;
  20157. }
  20158. this.createInterpolant = factoryMethod;
  20159. return this;
  20160. },
  20161. getInterpolation: function () {
  20162. switch ( this.createInterpolant ) {
  20163. case this.InterpolantFactoryMethodDiscrete:
  20164. return InterpolateDiscrete;
  20165. case this.InterpolantFactoryMethodLinear:
  20166. return InterpolateLinear;
  20167. case this.InterpolantFactoryMethodSmooth:
  20168. return InterpolateSmooth;
  20169. }
  20170. },
  20171. getValueSize: function () {
  20172. return this.values.length / this.times.length;
  20173. },
  20174. // move all keyframes either forwards or backwards in time
  20175. shift: function ( timeOffset ) {
  20176. if ( timeOffset !== 0.0 ) {
  20177. var times = this.times;
  20178. for ( var i = 0, n = times.length; i !== n; ++ i ) {
  20179. times[ i ] += timeOffset;
  20180. }
  20181. }
  20182. return this;
  20183. },
  20184. // scale all keyframe times by a factor (useful for frame <-> seconds conversions)
  20185. scale: function ( timeScale ) {
  20186. if ( timeScale !== 1.0 ) {
  20187. var times = this.times;
  20188. for ( var i = 0, n = times.length; i !== n; ++ i ) {
  20189. times[ i ] *= timeScale;
  20190. }
  20191. }
  20192. return this;
  20193. },
  20194. // removes keyframes before and after animation without changing any values within the range [startTime, endTime].
  20195. // IMPORTANT: We do not shift around keys to the start of the track time, because for interpolated keys this will change their values
  20196. trim: function ( startTime, endTime ) {
  20197. var times = this.times,
  20198. nKeys = times.length,
  20199. from = 0,
  20200. to = nKeys - 1;
  20201. while ( from !== nKeys && times[ from ] < startTime ) {
  20202. ++ from;
  20203. }
  20204. while ( to !== - 1 && times[ to ] > endTime ) {
  20205. -- to;
  20206. }
  20207. ++ to; // inclusive -> exclusive bound
  20208. if ( from !== 0 || to !== nKeys ) {
  20209. // empty tracks are forbidden, so keep at least one keyframe
  20210. if ( from >= to ) to = Math.max( to, 1 ), from = to - 1;
  20211. var stride = this.getValueSize();
  20212. this.times = AnimationUtils.arraySlice( times, from, to );
  20213. this.values = AnimationUtils.arraySlice( this.values, from * stride, to * stride );
  20214. }
  20215. return this;
  20216. },
  20217. // ensure we do not get a GarbageInGarbageOut situation, make sure tracks are at least minimally viable
  20218. validate: function () {
  20219. var valid = true;
  20220. var valueSize = this.getValueSize();
  20221. if ( valueSize - Math.floor( valueSize ) !== 0 ) {
  20222. console.error( 'THREE.KeyframeTrack: Invalid value size in track.', this );
  20223. valid = false;
  20224. }
  20225. var times = this.times,
  20226. values = this.values,
  20227. nKeys = times.length;
  20228. if ( nKeys === 0 ) {
  20229. console.error( 'THREE.KeyframeTrack: Track is empty.', this );
  20230. valid = false;
  20231. }
  20232. var prevTime = null;
  20233. for ( var i = 0; i !== nKeys; i ++ ) {
  20234. var currTime = times[ i ];
  20235. if ( typeof currTime === 'number' && isNaN( currTime ) ) {
  20236. console.error( 'THREE.KeyframeTrack: Time is not a valid number.', this, i, currTime );
  20237. valid = false;
  20238. break;
  20239. }
  20240. if ( prevTime !== null && prevTime > currTime ) {
  20241. console.error( 'THREE.KeyframeTrack: Out of order keys.', this, i, currTime, prevTime );
  20242. valid = false;
  20243. break;
  20244. }
  20245. prevTime = currTime;
  20246. }
  20247. if ( values !== undefined ) {
  20248. if ( AnimationUtils.isTypedArray( values ) ) {
  20249. for ( var i = 0, n = values.length; i !== n; ++ i ) {
  20250. var value = values[ i ];
  20251. if ( isNaN( value ) ) {
  20252. console.error( 'THREE.KeyframeTrack: Value is not a valid number.', this, i, value );
  20253. valid = false;
  20254. break;
  20255. }
  20256. }
  20257. }
  20258. }
  20259. return valid;
  20260. },
  20261. // removes equivalent sequential keys as common in morph target sequences
  20262. // (0,0,0,0,1,1,1,0,0,0,0,0,0,0) --> (0,0,1,1,0,0)
  20263. optimize: function () {
  20264. var times = this.times,
  20265. values = this.values,
  20266. stride = this.getValueSize(),
  20267. smoothInterpolation = this.getInterpolation() === InterpolateSmooth,
  20268. writeIndex = 1,
  20269. lastIndex = times.length - 1;
  20270. for ( var i = 1; i < lastIndex; ++ i ) {
  20271. var keep = false;
  20272. var time = times[ i ];
  20273. var timeNext = times[ i + 1 ];
  20274. // remove adjacent keyframes scheduled at the same time
  20275. if ( time !== timeNext && ( i !== 1 || time !== time[ 0 ] ) ) {
  20276. if ( ! smoothInterpolation ) {
  20277. // remove unnecessary keyframes same as their neighbors
  20278. var offset = i * stride,
  20279. offsetP = offset - stride,
  20280. offsetN = offset + stride;
  20281. for ( var j = 0; j !== stride; ++ j ) {
  20282. var value = values[ offset + j ];
  20283. if ( value !== values[ offsetP + j ] ||
  20284. value !== values[ offsetN + j ] ) {
  20285. keep = true;
  20286. break;
  20287. }
  20288. }
  20289. } else {
  20290. keep = true;
  20291. }
  20292. }
  20293. // in-place compaction
  20294. if ( keep ) {
  20295. if ( i !== writeIndex ) {
  20296. times[ writeIndex ] = times[ i ];
  20297. var readOffset = i * stride,
  20298. writeOffset = writeIndex * stride;
  20299. for ( var j = 0; j !== stride; ++ j ) {
  20300. values[ writeOffset + j ] = values[ readOffset + j ];
  20301. }
  20302. }
  20303. ++ writeIndex;
  20304. }
  20305. }
  20306. // flush last keyframe (compaction looks ahead)
  20307. if ( lastIndex > 0 ) {
  20308. times[ writeIndex ] = times[ lastIndex ];
  20309. for ( var readOffset = lastIndex * stride, writeOffset = writeIndex * stride, j = 0; j !== stride; ++ j ) {
  20310. values[ writeOffset + j ] = values[ readOffset + j ];
  20311. }
  20312. ++ writeIndex;
  20313. }
  20314. if ( writeIndex !== times.length ) {
  20315. this.times = AnimationUtils.arraySlice( times, 0, writeIndex );
  20316. this.values = AnimationUtils.arraySlice( values, 0, writeIndex * stride );
  20317. }
  20318. return this;
  20319. },
  20320. clone: function () {
  20321. var times = AnimationUtils.arraySlice( this.times, 0 );
  20322. var values = AnimationUtils.arraySlice( this.values, 0 );
  20323. var TypedKeyframeTrack = this.constructor;
  20324. var track = new TypedKeyframeTrack( this.name, times, values );
  20325. // Interpolant argument to constructor is not saved, so copy the factory method directly.
  20326. track.createInterpolant = this.createInterpolant;
  20327. return track;
  20328. }
  20329. } );
  20330. /**
  20331. *
  20332. * A Track of Boolean keyframe values.
  20333. *
  20334. *
  20335. * @author Ben Houston / http://clara.io/
  20336. * @author David Sarno / http://lighthaus.us/
  20337. * @author tschw
  20338. */
  20339. function BooleanKeyframeTrack( name, times, values ) {
  20340. KeyframeTrack.call( this, name, times, values );
  20341. }
  20342. BooleanKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), {
  20343. constructor: BooleanKeyframeTrack,
  20344. ValueTypeName: 'bool',
  20345. ValueBufferType: Array,
  20346. DefaultInterpolation: InterpolateDiscrete,
  20347. InterpolantFactoryMethodLinear: undefined,
  20348. InterpolantFactoryMethodSmooth: undefined
  20349. // Note: Actually this track could have a optimized / compressed
  20350. // representation of a single value and a custom interpolant that
  20351. // computes "firstValue ^ isOdd( index )".
  20352. } );
  20353. /**
  20354. *
  20355. * A Track of keyframe values that represent color.
  20356. *
  20357. *
  20358. * @author Ben Houston / http://clara.io/
  20359. * @author David Sarno / http://lighthaus.us/
  20360. * @author tschw
  20361. */
  20362. function ColorKeyframeTrack( name, times, values, interpolation ) {
  20363. KeyframeTrack.call( this, name, times, values, interpolation );
  20364. }
  20365. ColorKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), {
  20366. constructor: ColorKeyframeTrack,
  20367. ValueTypeName: 'color'
  20368. // ValueBufferType is inherited
  20369. // DefaultInterpolation is inherited
  20370. // Note: Very basic implementation and nothing special yet.
  20371. // However, this is the place for color space parameterization.
  20372. } );
  20373. /**
  20374. *
  20375. * A Track of numeric keyframe values.
  20376. *
  20377. * @author Ben Houston / http://clara.io/
  20378. * @author David Sarno / http://lighthaus.us/
  20379. * @author tschw
  20380. */
  20381. function NumberKeyframeTrack( name, times, values, interpolation ) {
  20382. KeyframeTrack.call( this, name, times, values, interpolation );
  20383. }
  20384. NumberKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), {
  20385. constructor: NumberKeyframeTrack,
  20386. ValueTypeName: 'number'
  20387. // ValueBufferType is inherited
  20388. // DefaultInterpolation is inherited
  20389. } );
  20390. /**
  20391. * Spherical linear unit quaternion interpolant.
  20392. *
  20393. * @author tschw
  20394. */
  20395. function QuaternionLinearInterpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  20396. Interpolant.call( this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  20397. }
  20398. QuaternionLinearInterpolant.prototype = Object.assign( Object.create( Interpolant.prototype ), {
  20399. constructor: QuaternionLinearInterpolant,
  20400. interpolate_: function ( i1, t0, t, t1 ) {
  20401. var result = this.resultBuffer,
  20402. values = this.sampleValues,
  20403. stride = this.valueSize,
  20404. offset = i1 * stride,
  20405. alpha = ( t - t0 ) / ( t1 - t0 );
  20406. for ( var end = offset + stride; offset !== end; offset += 4 ) {
  20407. Quaternion.slerpFlat( result, 0, values, offset - stride, values, offset, alpha );
  20408. }
  20409. return result;
  20410. }
  20411. } );
  20412. /**
  20413. *
  20414. * A Track of quaternion keyframe values.
  20415. *
  20416. * @author Ben Houston / http://clara.io/
  20417. * @author David Sarno / http://lighthaus.us/
  20418. * @author tschw
  20419. */
  20420. function QuaternionKeyframeTrack( name, times, values, interpolation ) {
  20421. KeyframeTrack.call( this, name, times, values, interpolation );
  20422. }
  20423. QuaternionKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), {
  20424. constructor: QuaternionKeyframeTrack,
  20425. ValueTypeName: 'quaternion',
  20426. // ValueBufferType is inherited
  20427. DefaultInterpolation: InterpolateLinear,
  20428. InterpolantFactoryMethodLinear: function ( result ) {
  20429. return new QuaternionLinearInterpolant( this.times, this.values, this.getValueSize(), result );
  20430. },
  20431. InterpolantFactoryMethodSmooth: undefined // not yet implemented
  20432. } );
  20433. /**
  20434. *
  20435. * A Track that interpolates Strings
  20436. *
  20437. *
  20438. * @author Ben Houston / http://clara.io/
  20439. * @author David Sarno / http://lighthaus.us/
  20440. * @author tschw
  20441. */
  20442. function StringKeyframeTrack( name, times, values, interpolation ) {
  20443. KeyframeTrack.call( this, name, times, values, interpolation );
  20444. }
  20445. StringKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), {
  20446. constructor: StringKeyframeTrack,
  20447. ValueTypeName: 'string',
  20448. ValueBufferType: Array,
  20449. DefaultInterpolation: InterpolateDiscrete,
  20450. InterpolantFactoryMethodLinear: undefined,
  20451. InterpolantFactoryMethodSmooth: undefined
  20452. } );
  20453. /**
  20454. *
  20455. * A Track of vectored keyframe values.
  20456. *
  20457. *
  20458. * @author Ben Houston / http://clara.io/
  20459. * @author David Sarno / http://lighthaus.us/
  20460. * @author tschw
  20461. */
  20462. function VectorKeyframeTrack( name, times, values, interpolation ) {
  20463. KeyframeTrack.call( this, name, times, values, interpolation );
  20464. }
  20465. VectorKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), {
  20466. constructor: VectorKeyframeTrack,
  20467. ValueTypeName: 'vector'
  20468. // ValueBufferType is inherited
  20469. // DefaultInterpolation is inherited
  20470. } );
  20471. /**
  20472. *
  20473. * Reusable set of Tracks that represent an animation.
  20474. *
  20475. * @author Ben Houston / http://clara.io/
  20476. * @author David Sarno / http://lighthaus.us/
  20477. */
  20478. function AnimationClip( name, duration, tracks ) {
  20479. this.name = name;
  20480. this.tracks = tracks;
  20481. this.duration = ( duration !== undefined ) ? duration : - 1;
  20482. this.uuid = _Math.generateUUID();
  20483. // this means it should figure out its duration by scanning the tracks
  20484. if ( this.duration < 0 ) {
  20485. this.resetDuration();
  20486. }
  20487. }
  20488. function getTrackTypeForValueTypeName( typeName ) {
  20489. switch ( typeName.toLowerCase() ) {
  20490. case 'scalar':
  20491. case 'double':
  20492. case 'float':
  20493. case 'number':
  20494. case 'integer':
  20495. return NumberKeyframeTrack;
  20496. case 'vector':
  20497. case 'vector2':
  20498. case 'vector3':
  20499. case 'vector4':
  20500. return VectorKeyframeTrack;
  20501. case 'color':
  20502. return ColorKeyframeTrack;
  20503. case 'quaternion':
  20504. return QuaternionKeyframeTrack;
  20505. case 'bool':
  20506. case 'boolean':
  20507. return BooleanKeyframeTrack;
  20508. case 'string':
  20509. return StringKeyframeTrack;
  20510. }
  20511. throw new Error( 'THREE.KeyframeTrack: Unsupported typeName: ' + typeName );
  20512. }
  20513. function parseKeyframeTrack( json ) {
  20514. if ( json.type === undefined ) {
  20515. throw new Error( 'THREE.KeyframeTrack: track type undefined, can not parse' );
  20516. }
  20517. var trackType = getTrackTypeForValueTypeName( json.type );
  20518. if ( json.times === undefined ) {
  20519. var times = [], values = [];
  20520. AnimationUtils.flattenJSON( json.keys, times, values, 'value' );
  20521. json.times = times;
  20522. json.values = values;
  20523. }
  20524. // derived classes can define a static parse method
  20525. if ( trackType.parse !== undefined ) {
  20526. return trackType.parse( json );
  20527. } else {
  20528. // by default, we assume a constructor compatible with the base
  20529. return new trackType( json.name, json.times, json.values, json.interpolation );
  20530. }
  20531. }
  20532. Object.assign( AnimationClip, {
  20533. parse: function ( json ) {
  20534. var tracks = [],
  20535. jsonTracks = json.tracks,
  20536. frameTime = 1.0 / ( json.fps || 1.0 );
  20537. for ( var i = 0, n = jsonTracks.length; i !== n; ++ i ) {
  20538. tracks.push( parseKeyframeTrack( jsonTracks[ i ] ).scale( frameTime ) );
  20539. }
  20540. return new AnimationClip( json.name, json.duration, tracks );
  20541. },
  20542. toJSON: function ( clip ) {
  20543. var tracks = [],
  20544. clipTracks = clip.tracks;
  20545. var json = {
  20546. 'name': clip.name,
  20547. 'duration': clip.duration,
  20548. 'tracks': tracks,
  20549. 'uuid': clip.uuid
  20550. };
  20551. for ( var i = 0, n = clipTracks.length; i !== n; ++ i ) {
  20552. tracks.push( KeyframeTrack.toJSON( clipTracks[ i ] ) );
  20553. }
  20554. return json;
  20555. },
  20556. CreateFromMorphTargetSequence: function ( name, morphTargetSequence, fps, noLoop ) {
  20557. var numMorphTargets = morphTargetSequence.length;
  20558. var tracks = [];
  20559. for ( var i = 0; i < numMorphTargets; i ++ ) {
  20560. var times = [];
  20561. var values = [];
  20562. times.push(
  20563. ( i + numMorphTargets - 1 ) % numMorphTargets,
  20564. i,
  20565. ( i + 1 ) % numMorphTargets );
  20566. values.push( 0, 1, 0 );
  20567. var order = AnimationUtils.getKeyframeOrder( times );
  20568. times = AnimationUtils.sortedArray( times, 1, order );
  20569. values = AnimationUtils.sortedArray( values, 1, order );
  20570. // if there is a key at the first frame, duplicate it as the
  20571. // last frame as well for perfect loop.
  20572. if ( ! noLoop && times[ 0 ] === 0 ) {
  20573. times.push( numMorphTargets );
  20574. values.push( values[ 0 ] );
  20575. }
  20576. tracks.push(
  20577. new NumberKeyframeTrack(
  20578. '.morphTargetInfluences[' + morphTargetSequence[ i ].name + ']',
  20579. times, values
  20580. ).scale( 1.0 / fps ) );
  20581. }
  20582. return new AnimationClip( name, - 1, tracks );
  20583. },
  20584. findByName: function ( objectOrClipArray, name ) {
  20585. var clipArray = objectOrClipArray;
  20586. if ( ! Array.isArray( objectOrClipArray ) ) {
  20587. var o = objectOrClipArray;
  20588. clipArray = o.geometry && o.geometry.animations || o.animations;
  20589. }
  20590. for ( var i = 0; i < clipArray.length; i ++ ) {
  20591. if ( clipArray[ i ].name === name ) {
  20592. return clipArray[ i ];
  20593. }
  20594. }
  20595. return null;
  20596. },
  20597. CreateClipsFromMorphTargetSequences: function ( morphTargets, fps, noLoop ) {
  20598. var animationToMorphTargets = {};
  20599. // tested with https://regex101.com/ on trick sequences
  20600. // such flamingo_flyA_003, flamingo_run1_003, crdeath0059
  20601. var pattern = /^([\w-]*?)([\d]+)$/;
  20602. // sort morph target names into animation groups based
  20603. // patterns like Walk_001, Walk_002, Run_001, Run_002
  20604. for ( var i = 0, il = morphTargets.length; i < il; i ++ ) {
  20605. var morphTarget = morphTargets[ i ];
  20606. var parts = morphTarget.name.match( pattern );
  20607. if ( parts && parts.length > 1 ) {
  20608. var name = parts[ 1 ];
  20609. var animationMorphTargets = animationToMorphTargets[ name ];
  20610. if ( ! animationMorphTargets ) {
  20611. animationToMorphTargets[ name ] = animationMorphTargets = [];
  20612. }
  20613. animationMorphTargets.push( morphTarget );
  20614. }
  20615. }
  20616. var clips = [];
  20617. for ( var name in animationToMorphTargets ) {
  20618. clips.push( AnimationClip.CreateFromMorphTargetSequence( name, animationToMorphTargets[ name ], fps, noLoop ) );
  20619. }
  20620. return clips;
  20621. },
  20622. // parse the animation.hierarchy format
  20623. parseAnimation: function ( animation, bones ) {
  20624. if ( ! animation ) {
  20625. console.error( 'THREE.AnimationClip: No animation in JSONLoader data.' );
  20626. return null;
  20627. }
  20628. var addNonemptyTrack = function ( trackType, trackName, animationKeys, propertyName, destTracks ) {
  20629. // only return track if there are actually keys.
  20630. if ( animationKeys.length !== 0 ) {
  20631. var times = [];
  20632. var values = [];
  20633. AnimationUtils.flattenJSON( animationKeys, times, values, propertyName );
  20634. // empty keys are filtered out, so check again
  20635. if ( times.length !== 0 ) {
  20636. destTracks.push( new trackType( trackName, times, values ) );
  20637. }
  20638. }
  20639. };
  20640. var tracks = [];
  20641. var clipName = animation.name || 'default';
  20642. // automatic length determination in AnimationClip.
  20643. var duration = animation.length || - 1;
  20644. var fps = animation.fps || 30;
  20645. var hierarchyTracks = animation.hierarchy || [];
  20646. for ( var h = 0; h < hierarchyTracks.length; h ++ ) {
  20647. var animationKeys = hierarchyTracks[ h ].keys;
  20648. // skip empty tracks
  20649. if ( ! animationKeys || animationKeys.length === 0 ) continue;
  20650. // process morph targets
  20651. if ( animationKeys[ 0 ].morphTargets ) {
  20652. // figure out all morph targets used in this track
  20653. var morphTargetNames = {};
  20654. for ( var k = 0; k < animationKeys.length; k ++ ) {
  20655. if ( animationKeys[ k ].morphTargets ) {
  20656. for ( var m = 0; m < animationKeys[ k ].morphTargets.length; m ++ ) {
  20657. morphTargetNames[ animationKeys[ k ].morphTargets[ m ] ] = - 1;
  20658. }
  20659. }
  20660. }
  20661. // create a track for each morph target with all zero
  20662. // morphTargetInfluences except for the keys in which
  20663. // the morphTarget is named.
  20664. for ( var morphTargetName in morphTargetNames ) {
  20665. var times = [];
  20666. var values = [];
  20667. for ( var m = 0; m !== animationKeys[ k ].morphTargets.length; ++ m ) {
  20668. var animationKey = animationKeys[ k ];
  20669. times.push( animationKey.time );
  20670. values.push( ( animationKey.morphTarget === morphTargetName ) ? 1 : 0 );
  20671. }
  20672. tracks.push( new NumberKeyframeTrack( '.morphTargetInfluence[' + morphTargetName + ']', times, values ) );
  20673. }
  20674. duration = morphTargetNames.length * ( fps || 1.0 );
  20675. } else {
  20676. // ...assume skeletal animation
  20677. var boneName = '.bones[' + bones[ h ].name + ']';
  20678. addNonemptyTrack(
  20679. VectorKeyframeTrack, boneName + '.position',
  20680. animationKeys, 'pos', tracks );
  20681. addNonemptyTrack(
  20682. QuaternionKeyframeTrack, boneName + '.quaternion',
  20683. animationKeys, 'rot', tracks );
  20684. addNonemptyTrack(
  20685. VectorKeyframeTrack, boneName + '.scale',
  20686. animationKeys, 'scl', tracks );
  20687. }
  20688. }
  20689. if ( tracks.length === 0 ) {
  20690. return null;
  20691. }
  20692. var clip = new AnimationClip( clipName, duration, tracks );
  20693. return clip;
  20694. }
  20695. } );
  20696. Object.assign( AnimationClip.prototype, {
  20697. resetDuration: function () {
  20698. var tracks = this.tracks, duration = 0;
  20699. for ( var i = 0, n = tracks.length; i !== n; ++ i ) {
  20700. var track = this.tracks[ i ];
  20701. duration = Math.max( duration, track.times[ track.times.length - 1 ] );
  20702. }
  20703. this.duration = duration;
  20704. return this;
  20705. },
  20706. trim: function () {
  20707. for ( var i = 0; i < this.tracks.length; i ++ ) {
  20708. this.tracks[ i ].trim( 0, this.duration );
  20709. }
  20710. return this;
  20711. },
  20712. validate: function () {
  20713. var valid = true;
  20714. for ( var i = 0; i < this.tracks.length; i ++ ) {
  20715. valid = valid && this.tracks[ i ].validate();
  20716. }
  20717. return valid;
  20718. },
  20719. optimize: function () {
  20720. for ( var i = 0; i < this.tracks.length; i ++ ) {
  20721. this.tracks[ i ].optimize();
  20722. }
  20723. return this;
  20724. },
  20725. clone: function () {
  20726. var tracks = [];
  20727. for ( var i = 0; i < this.tracks.length; i ++ ) {
  20728. tracks.push( this.tracks[ i ].clone() );
  20729. }
  20730. return new AnimationClip( this.name, this.duration, tracks );
  20731. }
  20732. } );
  20733. /**
  20734. * @author mrdoob / http://mrdoob.com/
  20735. */
  20736. var Cache = {
  20737. enabled: false,
  20738. files: {},
  20739. add: function ( key, file ) {
  20740. if ( this.enabled === false ) return;
  20741. // console.log( 'THREE.Cache', 'Adding key:', key );
  20742. this.files[ key ] = file;
  20743. },
  20744. get: function ( key ) {
  20745. if ( this.enabled === false ) return;
  20746. // console.log( 'THREE.Cache', 'Checking key:', key );
  20747. return this.files[ key ];
  20748. },
  20749. remove: function ( key ) {
  20750. delete this.files[ key ];
  20751. },
  20752. clear: function () {
  20753. this.files = {};
  20754. }
  20755. };
  20756. /**
  20757. * @author mrdoob / http://mrdoob.com/
  20758. */
  20759. function LoadingManager( onLoad, onProgress, onError ) {
  20760. var scope = this;
  20761. var isLoading = false;
  20762. var itemsLoaded = 0;
  20763. var itemsTotal = 0;
  20764. var urlModifier = undefined;
  20765. // Refer to #5689 for the reason why we don't set .onStart
  20766. // in the constructor
  20767. this.onStart = undefined;
  20768. this.onLoad = onLoad;
  20769. this.onProgress = onProgress;
  20770. this.onError = onError;
  20771. this.itemStart = function ( url ) {
  20772. itemsTotal ++;
  20773. if ( isLoading === false ) {
  20774. if ( scope.onStart !== undefined ) {
  20775. scope.onStart( url, itemsLoaded, itemsTotal );
  20776. }
  20777. }
  20778. isLoading = true;
  20779. };
  20780. this.itemEnd = function ( url ) {
  20781. itemsLoaded ++;
  20782. if ( scope.onProgress !== undefined ) {
  20783. scope.onProgress( url, itemsLoaded, itemsTotal );
  20784. }
  20785. if ( itemsLoaded === itemsTotal ) {
  20786. isLoading = false;
  20787. if ( scope.onLoad !== undefined ) {
  20788. scope.onLoad();
  20789. }
  20790. }
  20791. };
  20792. this.itemError = function ( url ) {
  20793. if ( scope.onError !== undefined ) {
  20794. scope.onError( url );
  20795. }
  20796. };
  20797. this.resolveURL = function ( url ) {
  20798. if ( urlModifier ) {
  20799. return urlModifier( url );
  20800. }
  20801. return url;
  20802. };
  20803. this.setURLModifier = function ( transform ) {
  20804. urlModifier = transform;
  20805. return this;
  20806. };
  20807. }
  20808. var DefaultLoadingManager = new LoadingManager();
  20809. /**
  20810. * @author mrdoob / http://mrdoob.com/
  20811. */
  20812. var loading = {};
  20813. function FileLoader( manager ) {
  20814. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  20815. }
  20816. Object.assign( FileLoader.prototype, {
  20817. load: function ( url, onLoad, onProgress, onError ) {
  20818. if ( url === undefined ) url = '';
  20819. if ( this.path !== undefined ) url = this.path + url;
  20820. url = this.manager.resolveURL( url );
  20821. var scope = this;
  20822. var cached = Cache.get( url );
  20823. if ( cached !== undefined ) {
  20824. scope.manager.itemStart( url );
  20825. setTimeout( function () {
  20826. if ( onLoad ) onLoad( cached );
  20827. scope.manager.itemEnd( url );
  20828. }, 0 );
  20829. return cached;
  20830. }
  20831. // Check if request is duplicate
  20832. if ( loading[ url ] !== undefined ) {
  20833. loading[ url ].push( {
  20834. onLoad: onLoad,
  20835. onProgress: onProgress,
  20836. onError: onError
  20837. } );
  20838. return;
  20839. }
  20840. // Check for data: URI
  20841. var dataUriRegex = /^data:(.*?)(;base64)?,(.*)$/;
  20842. var dataUriRegexResult = url.match( dataUriRegex );
  20843. // Safari can not handle Data URIs through XMLHttpRequest so process manually
  20844. if ( dataUriRegexResult ) {
  20845. var mimeType = dataUriRegexResult[ 1 ];
  20846. var isBase64 = !! dataUriRegexResult[ 2 ];
  20847. var data = dataUriRegexResult[ 3 ];
  20848. data = decodeURIComponent( data );
  20849. if ( isBase64 ) data = atob( data );
  20850. try {
  20851. var response;
  20852. var responseType = ( this.responseType || '' ).toLowerCase();
  20853. switch ( responseType ) {
  20854. case 'arraybuffer':
  20855. case 'blob':
  20856. var view = new Uint8Array( data.length );
  20857. for ( var i = 0; i < data.length; i ++ ) {
  20858. view[ i ] = data.charCodeAt( i );
  20859. }
  20860. if ( responseType === 'blob' ) {
  20861. response = new Blob( [ view.buffer ], { type: mimeType } );
  20862. } else {
  20863. response = view.buffer;
  20864. }
  20865. break;
  20866. case 'document':
  20867. var parser = new DOMParser();
  20868. response = parser.parseFromString( data, mimeType );
  20869. break;
  20870. case 'json':
  20871. response = JSON.parse( data );
  20872. break;
  20873. default: // 'text' or other
  20874. response = data;
  20875. break;
  20876. }
  20877. // Wait for next browser tick like standard XMLHttpRequest event dispatching does
  20878. setTimeout( function () {
  20879. if ( onLoad ) onLoad( response );
  20880. scope.manager.itemEnd( url );
  20881. }, 0 );
  20882. } catch ( error ) {
  20883. // Wait for next browser tick like standard XMLHttpRequest event dispatching does
  20884. setTimeout( function () {
  20885. if ( onError ) onError( error );
  20886. scope.manager.itemError( url );
  20887. scope.manager.itemEnd( url );
  20888. }, 0 );
  20889. }
  20890. } else {
  20891. // Initialise array for duplicate requests
  20892. loading[ url ] = [];
  20893. loading[ url ].push( {
  20894. onLoad: onLoad,
  20895. onProgress: onProgress,
  20896. onError: onError
  20897. } );
  20898. var request = new XMLHttpRequest();
  20899. request.open( 'GET', url, true );
  20900. request.addEventListener( 'load', function ( event ) {
  20901. var response = this.response;
  20902. Cache.add( url, response );
  20903. var callbacks = loading[ url ];
  20904. delete loading[ url ];
  20905. if ( this.status === 200 || this.status === 0 ) {
  20906. // Some browsers return HTTP Status 0 when using non-http protocol
  20907. // e.g. 'file://' or 'data://'. Handle as success.
  20908. if ( this.status === 0 ) console.warn( 'THREE.FileLoader: HTTP Status 0 received.' );
  20909. for ( var i = 0, il = callbacks.length; i < il; i ++ ) {
  20910. var callback = callbacks[ i ];
  20911. if ( callback.onLoad ) callback.onLoad( response );
  20912. }
  20913. scope.manager.itemEnd( url );
  20914. } else {
  20915. for ( var i = 0, il = callbacks.length; i < il; i ++ ) {
  20916. var callback = callbacks[ i ];
  20917. if ( callback.onError ) callback.onError( event );
  20918. }
  20919. scope.manager.itemError( url );
  20920. scope.manager.itemEnd( url );
  20921. }
  20922. }, false );
  20923. request.addEventListener( 'progress', function ( event ) {
  20924. var callbacks = loading[ url ];
  20925. for ( var i = 0, il = callbacks.length; i < il; i ++ ) {
  20926. var callback = callbacks[ i ];
  20927. if ( callback.onProgress ) callback.onProgress( event );
  20928. }
  20929. }, false );
  20930. request.addEventListener( 'error', function ( event ) {
  20931. var callbacks = loading[ url ];
  20932. delete loading[ url ];
  20933. for ( var i = 0, il = callbacks.length; i < il; i ++ ) {
  20934. var callback = callbacks[ i ];
  20935. if ( callback.onError ) callback.onError( event );
  20936. }
  20937. scope.manager.itemError( url );
  20938. scope.manager.itemEnd( url );
  20939. }, false );
  20940. request.addEventListener( 'abort', function ( event ) {
  20941. var callbacks = loading[ url ];
  20942. delete loading[ url ];
  20943. for ( var i = 0, il = callbacks.length; i < il; i ++ ) {
  20944. var callback = callbacks[ i ];
  20945. if ( callback.onError ) callback.onError( event );
  20946. }
  20947. scope.manager.itemError( url );
  20948. scope.manager.itemEnd( url );
  20949. }, false );
  20950. if ( this.responseType !== undefined ) request.responseType = this.responseType;
  20951. if ( this.withCredentials !== undefined ) request.withCredentials = this.withCredentials;
  20952. if ( request.overrideMimeType ) request.overrideMimeType( this.mimeType !== undefined ? this.mimeType : 'text/plain' );
  20953. for ( var header in this.requestHeader ) {
  20954. request.setRequestHeader( header, this.requestHeader[ header ] );
  20955. }
  20956. request.send( null );
  20957. }
  20958. scope.manager.itemStart( url );
  20959. return request;
  20960. },
  20961. setPath: function ( value ) {
  20962. this.path = value;
  20963. return this;
  20964. },
  20965. setResponseType: function ( value ) {
  20966. this.responseType = value;
  20967. return this;
  20968. },
  20969. setWithCredentials: function ( value ) {
  20970. this.withCredentials = value;
  20971. return this;
  20972. },
  20973. setMimeType: function ( value ) {
  20974. this.mimeType = value;
  20975. return this;
  20976. },
  20977. setRequestHeader: function ( value ) {
  20978. this.requestHeader = value;
  20979. return this;
  20980. }
  20981. } );
  20982. /**
  20983. * @author bhouston / http://clara.io/
  20984. */
  20985. function AnimationLoader( manager ) {
  20986. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  20987. }
  20988. Object.assign( AnimationLoader.prototype, {
  20989. load: function ( url, onLoad, onProgress, onError ) {
  20990. var scope = this;
  20991. var loader = new FileLoader( scope.manager );
  20992. loader.setPath( scope.path );
  20993. loader.load( url, function ( text ) {
  20994. onLoad( scope.parse( JSON.parse( text ) ) );
  20995. }, onProgress, onError );
  20996. },
  20997. parse: function ( json ) {
  20998. var animations = [];
  20999. for ( var i = 0; i < json.length; i ++ ) {
  21000. var clip = AnimationClip.parse( json[ i ] );
  21001. animations.push( clip );
  21002. }
  21003. return animations;
  21004. },
  21005. setPath: function ( value ) {
  21006. this.path = value;
  21007. return this;
  21008. }
  21009. } );
  21010. /**
  21011. * @author mrdoob / http://mrdoob.com/
  21012. *
  21013. * Abstract Base class to block based textures loader (dds, pvr, ...)
  21014. */
  21015. function CompressedTextureLoader( manager ) {
  21016. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  21017. // override in sub classes
  21018. this._parser = null;
  21019. }
  21020. Object.assign( CompressedTextureLoader.prototype, {
  21021. load: function ( url, onLoad, onProgress, onError ) {
  21022. var scope = this;
  21023. var images = [];
  21024. var texture = new CompressedTexture();
  21025. texture.image = images;
  21026. var loader = new FileLoader( this.manager );
  21027. loader.setPath( this.path );
  21028. loader.setResponseType( 'arraybuffer' );
  21029. function loadTexture( i ) {
  21030. loader.load( url[ i ], function ( buffer ) {
  21031. var texDatas = scope._parser( buffer, true );
  21032. images[ i ] = {
  21033. width: texDatas.width,
  21034. height: texDatas.height,
  21035. format: texDatas.format,
  21036. mipmaps: texDatas.mipmaps
  21037. };
  21038. loaded += 1;
  21039. if ( loaded === 6 ) {
  21040. if ( texDatas.mipmapCount === 1 )
  21041. texture.minFilter = LinearFilter;
  21042. texture.format = texDatas.format;
  21043. texture.needsUpdate = true;
  21044. if ( onLoad ) onLoad( texture );
  21045. }
  21046. }, onProgress, onError );
  21047. }
  21048. if ( Array.isArray( url ) ) {
  21049. var loaded = 0;
  21050. for ( var i = 0, il = url.length; i < il; ++ i ) {
  21051. loadTexture( i );
  21052. }
  21053. } else {
  21054. // compressed cubemap texture stored in a single DDS file
  21055. loader.load( url, function ( buffer ) {
  21056. var texDatas = scope._parser( buffer, true );
  21057. if ( texDatas.isCubemap ) {
  21058. var faces = texDatas.mipmaps.length / texDatas.mipmapCount;
  21059. for ( var f = 0; f < faces; f ++ ) {
  21060. images[ f ] = { mipmaps: [] };
  21061. for ( var i = 0; i < texDatas.mipmapCount; i ++ ) {
  21062. images[ f ].mipmaps.push( texDatas.mipmaps[ f * texDatas.mipmapCount + i ] );
  21063. images[ f ].format = texDatas.format;
  21064. images[ f ].width = texDatas.width;
  21065. images[ f ].height = texDatas.height;
  21066. }
  21067. }
  21068. } else {
  21069. texture.image.width = texDatas.width;
  21070. texture.image.height = texDatas.height;
  21071. texture.mipmaps = texDatas.mipmaps;
  21072. }
  21073. if ( texDatas.mipmapCount === 1 ) {
  21074. texture.minFilter = LinearFilter;
  21075. }
  21076. texture.format = texDatas.format;
  21077. texture.needsUpdate = true;
  21078. if ( onLoad ) onLoad( texture );
  21079. }, onProgress, onError );
  21080. }
  21081. return texture;
  21082. },
  21083. setPath: function ( value ) {
  21084. this.path = value;
  21085. return this;
  21086. }
  21087. } );
  21088. /**
  21089. * @author Nikos M. / https://github.com/foo123/
  21090. *
  21091. * Abstract Base class to load generic binary textures formats (rgbe, hdr, ...)
  21092. */
  21093. function DataTextureLoader( manager ) {
  21094. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  21095. // override in sub classes
  21096. this._parser = null;
  21097. }
  21098. Object.assign( DataTextureLoader.prototype, {
  21099. load: function ( url, onLoad, onProgress, onError ) {
  21100. var scope = this;
  21101. var texture = new DataTexture();
  21102. var loader = new FileLoader( this.manager );
  21103. loader.setResponseType( 'arraybuffer' );
  21104. loader.setPath( this.path );
  21105. loader.load( url, function ( buffer ) {
  21106. var texData = scope._parser( buffer );
  21107. if ( ! texData ) return;
  21108. if ( texData.image !== undefined ) {
  21109. texture.image = texData.image;
  21110. } else if ( texData.data !== undefined ) {
  21111. texture.image.width = texData.width;
  21112. texture.image.height = texData.height;
  21113. texture.image.data = texData.data;
  21114. }
  21115. texture.wrapS = texData.wrapS !== undefined ? texData.wrapS : ClampToEdgeWrapping;
  21116. texture.wrapT = texData.wrapT !== undefined ? texData.wrapT : ClampToEdgeWrapping;
  21117. texture.magFilter = texData.magFilter !== undefined ? texData.magFilter : LinearFilter;
  21118. texture.minFilter = texData.minFilter !== undefined ? texData.minFilter : LinearMipmapLinearFilter;
  21119. texture.anisotropy = texData.anisotropy !== undefined ? texData.anisotropy : 1;
  21120. if ( texData.format !== undefined ) {
  21121. texture.format = texData.format;
  21122. }
  21123. if ( texData.type !== undefined ) {
  21124. texture.type = texData.type;
  21125. }
  21126. if ( texData.mipmaps !== undefined ) {
  21127. texture.mipmaps = texData.mipmaps;
  21128. }
  21129. if ( texData.mipmapCount === 1 ) {
  21130. texture.minFilter = LinearFilter;
  21131. }
  21132. texture.needsUpdate = true;
  21133. if ( onLoad ) onLoad( texture, texData );
  21134. }, onProgress, onError );
  21135. return texture;
  21136. },
  21137. setPath: function ( value ) {
  21138. this.path = value;
  21139. return this;
  21140. }
  21141. } );
  21142. /**
  21143. * @author mrdoob / http://mrdoob.com/
  21144. */
  21145. function ImageLoader( manager ) {
  21146. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  21147. }
  21148. Object.assign( ImageLoader.prototype, {
  21149. crossOrigin: 'anonymous',
  21150. load: function ( url, onLoad, onProgress, onError ) {
  21151. if ( url === undefined ) url = '';
  21152. if ( this.path !== undefined ) url = this.path + url;
  21153. url = this.manager.resolveURL( url );
  21154. var scope = this;
  21155. var cached = Cache.get( url );
  21156. if ( cached !== undefined ) {
  21157. scope.manager.itemStart( url );
  21158. setTimeout( function () {
  21159. if ( onLoad ) onLoad( cached );
  21160. scope.manager.itemEnd( url );
  21161. }, 0 );
  21162. return cached;
  21163. }
  21164. var image = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'img' );
  21165. function onImageLoad() {
  21166. image.removeEventListener( 'load', onImageLoad, false );
  21167. image.removeEventListener( 'error', onImageError, false );
  21168. Cache.add( url, this );
  21169. if ( onLoad ) onLoad( this );
  21170. scope.manager.itemEnd( url );
  21171. }
  21172. function onImageError( event ) {
  21173. image.removeEventListener( 'load', onImageLoad, false );
  21174. image.removeEventListener( 'error', onImageError, false );
  21175. if ( onError ) onError( event );
  21176. scope.manager.itemError( url );
  21177. scope.manager.itemEnd( url );
  21178. }
  21179. image.addEventListener( 'load', onImageLoad, false );
  21180. image.addEventListener( 'error', onImageError, false );
  21181. if ( url.substr( 0, 5 ) !== 'data:' ) {
  21182. if ( this.crossOrigin !== undefined ) image.crossOrigin = this.crossOrigin;
  21183. }
  21184. scope.manager.itemStart( url );
  21185. image.src = url;
  21186. return image;
  21187. },
  21188. setCrossOrigin: function ( value ) {
  21189. this.crossOrigin = value;
  21190. return this;
  21191. },
  21192. setPath: function ( value ) {
  21193. this.path = value;
  21194. return this;
  21195. }
  21196. } );
  21197. /**
  21198. * @author mrdoob / http://mrdoob.com/
  21199. */
  21200. function CubeTextureLoader( manager ) {
  21201. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  21202. }
  21203. Object.assign( CubeTextureLoader.prototype, {
  21204. crossOrigin: 'anonymous',
  21205. load: function ( urls, onLoad, onProgress, onError ) {
  21206. var texture = new CubeTexture();
  21207. var loader = new ImageLoader( this.manager );
  21208. loader.setCrossOrigin( this.crossOrigin );
  21209. loader.setPath( this.path );
  21210. var loaded = 0;
  21211. function loadTexture( i ) {
  21212. loader.load( urls[ i ], function ( image ) {
  21213. texture.images[ i ] = image;
  21214. loaded ++;
  21215. if ( loaded === 6 ) {
  21216. texture.needsUpdate = true;
  21217. if ( onLoad ) onLoad( texture );
  21218. }
  21219. }, undefined, onError );
  21220. }
  21221. for ( var i = 0; i < urls.length; ++ i ) {
  21222. loadTexture( i );
  21223. }
  21224. return texture;
  21225. },
  21226. setCrossOrigin: function ( value ) {
  21227. this.crossOrigin = value;
  21228. return this;
  21229. },
  21230. setPath: function ( value ) {
  21231. this.path = value;
  21232. return this;
  21233. }
  21234. } );
  21235. /**
  21236. * @author mrdoob / http://mrdoob.com/
  21237. */
  21238. function TextureLoader( manager ) {
  21239. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  21240. }
  21241. Object.assign( TextureLoader.prototype, {
  21242. crossOrigin: 'anonymous',
  21243. load: function ( url, onLoad, onProgress, onError ) {
  21244. var texture = new Texture();
  21245. var loader = new ImageLoader( this.manager );
  21246. loader.setCrossOrigin( this.crossOrigin );
  21247. loader.setPath( this.path );
  21248. loader.load( url, function ( image ) {
  21249. texture.image = image;
  21250. // JPEGs can't have an alpha channel, so memory can be saved by storing them as RGB.
  21251. var isJPEG = url.search( /\.jpe?g($|\?)/i ) > 0 || url.search( /^data\:image\/jpeg/ ) === 0;
  21252. texture.format = isJPEG ? RGBFormat : RGBAFormat;
  21253. texture.needsUpdate = true;
  21254. if ( onLoad !== undefined ) {
  21255. onLoad( texture );
  21256. }
  21257. }, onProgress, onError );
  21258. return texture;
  21259. },
  21260. setCrossOrigin: function ( value ) {
  21261. this.crossOrigin = value;
  21262. return this;
  21263. },
  21264. setPath: function ( value ) {
  21265. this.path = value;
  21266. return this;
  21267. }
  21268. } );
  21269. /**
  21270. * @author zz85 / http://www.lab4games.net/zz85/blog
  21271. * Extensible curve object
  21272. *
  21273. * Some common of curve methods:
  21274. * .getPoint( t, optionalTarget ), .getTangent( t )
  21275. * .getPointAt( u, optionalTarget ), .getTangentAt( u )
  21276. * .getPoints(), .getSpacedPoints()
  21277. * .getLength()
  21278. * .updateArcLengths()
  21279. *
  21280. * This following curves inherit from THREE.Curve:
  21281. *
  21282. * -- 2D curves --
  21283. * THREE.ArcCurve
  21284. * THREE.CubicBezierCurve
  21285. * THREE.EllipseCurve
  21286. * THREE.LineCurve
  21287. * THREE.QuadraticBezierCurve
  21288. * THREE.SplineCurve
  21289. *
  21290. * -- 3D curves --
  21291. * THREE.CatmullRomCurve3
  21292. * THREE.CubicBezierCurve3
  21293. * THREE.LineCurve3
  21294. * THREE.QuadraticBezierCurve3
  21295. *
  21296. * A series of curves can be represented as a THREE.CurvePath.
  21297. *
  21298. **/
  21299. /**************************************************************
  21300. * Abstract Curve base class
  21301. **************************************************************/
  21302. function Curve() {
  21303. this.type = 'Curve';
  21304. this.arcLengthDivisions = 200;
  21305. }
  21306. Object.assign( Curve.prototype, {
  21307. // Virtual base class method to overwrite and implement in subclasses
  21308. // - t [0 .. 1]
  21309. getPoint: function ( /* t, optionalTarget */ ) {
  21310. console.warn( 'THREE.Curve: .getPoint() not implemented.' );
  21311. return null;
  21312. },
  21313. // Get point at relative position in curve according to arc length
  21314. // - u [0 .. 1]
  21315. getPointAt: function ( u, optionalTarget ) {
  21316. var t = this.getUtoTmapping( u );
  21317. return this.getPoint( t, optionalTarget );
  21318. },
  21319. // Get sequence of points using getPoint( t )
  21320. getPoints: function ( divisions ) {
  21321. if ( divisions === undefined ) divisions = 5;
  21322. var points = [];
  21323. for ( var d = 0; d <= divisions; d ++ ) {
  21324. points.push( this.getPoint( d / divisions ) );
  21325. }
  21326. return points;
  21327. },
  21328. // Get sequence of points using getPointAt( u )
  21329. getSpacedPoints: function ( divisions ) {
  21330. if ( divisions === undefined ) divisions = 5;
  21331. var points = [];
  21332. for ( var d = 0; d <= divisions; d ++ ) {
  21333. points.push( this.getPointAt( d / divisions ) );
  21334. }
  21335. return points;
  21336. },
  21337. // Get total curve arc length
  21338. getLength: function () {
  21339. var lengths = this.getLengths();
  21340. return lengths[ lengths.length - 1 ];
  21341. },
  21342. // Get list of cumulative segment lengths
  21343. getLengths: function ( divisions ) {
  21344. if ( divisions === undefined ) divisions = this.arcLengthDivisions;
  21345. if ( this.cacheArcLengths &&
  21346. ( this.cacheArcLengths.length === divisions + 1 ) &&
  21347. ! this.needsUpdate ) {
  21348. return this.cacheArcLengths;
  21349. }
  21350. this.needsUpdate = false;
  21351. var cache = [];
  21352. var current, last = this.getPoint( 0 );
  21353. var p, sum = 0;
  21354. cache.push( 0 );
  21355. for ( p = 1; p <= divisions; p ++ ) {
  21356. current = this.getPoint( p / divisions );
  21357. sum += current.distanceTo( last );
  21358. cache.push( sum );
  21359. last = current;
  21360. }
  21361. this.cacheArcLengths = cache;
  21362. return cache; // { sums: cache, sum: sum }; Sum is in the last element.
  21363. },
  21364. updateArcLengths: function () {
  21365. this.needsUpdate = true;
  21366. this.getLengths();
  21367. },
  21368. // Given u ( 0 .. 1 ), get a t to find p. This gives you points which are equidistant
  21369. getUtoTmapping: function ( u, distance ) {
  21370. var arcLengths = this.getLengths();
  21371. var i = 0, il = arcLengths.length;
  21372. var targetArcLength; // The targeted u distance value to get
  21373. if ( distance ) {
  21374. targetArcLength = distance;
  21375. } else {
  21376. targetArcLength = u * arcLengths[ il - 1 ];
  21377. }
  21378. // binary search for the index with largest value smaller than target u distance
  21379. var low = 0, high = il - 1, comparison;
  21380. while ( low <= high ) {
  21381. 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
  21382. comparison = arcLengths[ i ] - targetArcLength;
  21383. if ( comparison < 0 ) {
  21384. low = i + 1;
  21385. } else if ( comparison > 0 ) {
  21386. high = i - 1;
  21387. } else {
  21388. high = i;
  21389. break;
  21390. // DONE
  21391. }
  21392. }
  21393. i = high;
  21394. if ( arcLengths[ i ] === targetArcLength ) {
  21395. return i / ( il - 1 );
  21396. }
  21397. // we could get finer grain at lengths, or use simple interpolation between two points
  21398. var lengthBefore = arcLengths[ i ];
  21399. var lengthAfter = arcLengths[ i + 1 ];
  21400. var segmentLength = lengthAfter - lengthBefore;
  21401. // determine where we are between the 'before' and 'after' points
  21402. var segmentFraction = ( targetArcLength - lengthBefore ) / segmentLength;
  21403. // add that fractional amount to t
  21404. var t = ( i + segmentFraction ) / ( il - 1 );
  21405. return t;
  21406. },
  21407. // Returns a unit vector tangent at t
  21408. // In case any sub curve does not implement its tangent derivation,
  21409. // 2 points a small delta apart will be used to find its gradient
  21410. // which seems to give a reasonable approximation
  21411. getTangent: function ( t ) {
  21412. var delta = 0.0001;
  21413. var t1 = t - delta;
  21414. var t2 = t + delta;
  21415. // Capping in case of danger
  21416. if ( t1 < 0 ) t1 = 0;
  21417. if ( t2 > 1 ) t2 = 1;
  21418. var pt1 = this.getPoint( t1 );
  21419. var pt2 = this.getPoint( t2 );
  21420. var vec = pt2.clone().sub( pt1 );
  21421. return vec.normalize();
  21422. },
  21423. getTangentAt: function ( u ) {
  21424. var t = this.getUtoTmapping( u );
  21425. return this.getTangent( t );
  21426. },
  21427. computeFrenetFrames: function ( segments, closed ) {
  21428. // see http://www.cs.indiana.edu/pub/techreports/TR425.pdf
  21429. var normal = new Vector3();
  21430. var tangents = [];
  21431. var normals = [];
  21432. var binormals = [];
  21433. var vec = new Vector3();
  21434. var mat = new Matrix4();
  21435. var i, u, theta;
  21436. // compute the tangent vectors for each segment on the curve
  21437. for ( i = 0; i <= segments; i ++ ) {
  21438. u = i / segments;
  21439. tangents[ i ] = this.getTangentAt( u );
  21440. tangents[ i ].normalize();
  21441. }
  21442. // select an initial normal vector perpendicular to the first tangent vector,
  21443. // and in the direction of the minimum tangent xyz component
  21444. normals[ 0 ] = new Vector3();
  21445. binormals[ 0 ] = new Vector3();
  21446. var min = Number.MAX_VALUE;
  21447. var tx = Math.abs( tangents[ 0 ].x );
  21448. var ty = Math.abs( tangents[ 0 ].y );
  21449. var tz = Math.abs( tangents[ 0 ].z );
  21450. if ( tx <= min ) {
  21451. min = tx;
  21452. normal.set( 1, 0, 0 );
  21453. }
  21454. if ( ty <= min ) {
  21455. min = ty;
  21456. normal.set( 0, 1, 0 );
  21457. }
  21458. if ( tz <= min ) {
  21459. normal.set( 0, 0, 1 );
  21460. }
  21461. vec.crossVectors( tangents[ 0 ], normal ).normalize();
  21462. normals[ 0 ].crossVectors( tangents[ 0 ], vec );
  21463. binormals[ 0 ].crossVectors( tangents[ 0 ], normals[ 0 ] );
  21464. // compute the slowly-varying normal and binormal vectors for each segment on the curve
  21465. for ( i = 1; i <= segments; i ++ ) {
  21466. normals[ i ] = normals[ i - 1 ].clone();
  21467. binormals[ i ] = binormals[ i - 1 ].clone();
  21468. vec.crossVectors( tangents[ i - 1 ], tangents[ i ] );
  21469. if ( vec.length() > Number.EPSILON ) {
  21470. vec.normalize();
  21471. theta = Math.acos( _Math.clamp( tangents[ i - 1 ].dot( tangents[ i ] ), - 1, 1 ) ); // clamp for floating pt errors
  21472. normals[ i ].applyMatrix4( mat.makeRotationAxis( vec, theta ) );
  21473. }
  21474. binormals[ i ].crossVectors( tangents[ i ], normals[ i ] );
  21475. }
  21476. // if the curve is closed, postprocess the vectors so the first and last normal vectors are the same
  21477. if ( closed === true ) {
  21478. theta = Math.acos( _Math.clamp( normals[ 0 ].dot( normals[ segments ] ), - 1, 1 ) );
  21479. theta /= segments;
  21480. if ( tangents[ 0 ].dot( vec.crossVectors( normals[ 0 ], normals[ segments ] ) ) > 0 ) {
  21481. theta = - theta;
  21482. }
  21483. for ( i = 1; i <= segments; i ++ ) {
  21484. // twist a little...
  21485. normals[ i ].applyMatrix4( mat.makeRotationAxis( tangents[ i ], theta * i ) );
  21486. binormals[ i ].crossVectors( tangents[ i ], normals[ i ] );
  21487. }
  21488. }
  21489. return {
  21490. tangents: tangents,
  21491. normals: normals,
  21492. binormals: binormals
  21493. };
  21494. },
  21495. clone: function () {
  21496. return new this.constructor().copy( this );
  21497. },
  21498. copy: function ( source ) {
  21499. this.arcLengthDivisions = source.arcLengthDivisions;
  21500. return this;
  21501. },
  21502. toJSON: function () {
  21503. var data = {
  21504. metadata: {
  21505. version: 4.5,
  21506. type: 'Curve',
  21507. generator: 'Curve.toJSON'
  21508. }
  21509. };
  21510. data.arcLengthDivisions = this.arcLengthDivisions;
  21511. data.type = this.type;
  21512. return data;
  21513. },
  21514. fromJSON: function ( json ) {
  21515. this.arcLengthDivisions = json.arcLengthDivisions;
  21516. return this;
  21517. }
  21518. } );
  21519. function EllipseCurve( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  21520. Curve.call( this );
  21521. this.type = 'EllipseCurve';
  21522. this.aX = aX || 0;
  21523. this.aY = aY || 0;
  21524. this.xRadius = xRadius || 1;
  21525. this.yRadius = yRadius || 1;
  21526. this.aStartAngle = aStartAngle || 0;
  21527. this.aEndAngle = aEndAngle || 2 * Math.PI;
  21528. this.aClockwise = aClockwise || false;
  21529. this.aRotation = aRotation || 0;
  21530. }
  21531. EllipseCurve.prototype = Object.create( Curve.prototype );
  21532. EllipseCurve.prototype.constructor = EllipseCurve;
  21533. EllipseCurve.prototype.isEllipseCurve = true;
  21534. EllipseCurve.prototype.getPoint = function ( t, optionalTarget ) {
  21535. var point = optionalTarget || new Vector2();
  21536. var twoPi = Math.PI * 2;
  21537. var deltaAngle = this.aEndAngle - this.aStartAngle;
  21538. var samePoints = Math.abs( deltaAngle ) < Number.EPSILON;
  21539. // ensures that deltaAngle is 0 .. 2 PI
  21540. while ( deltaAngle < 0 ) deltaAngle += twoPi;
  21541. while ( deltaAngle > twoPi ) deltaAngle -= twoPi;
  21542. if ( deltaAngle < Number.EPSILON ) {
  21543. if ( samePoints ) {
  21544. deltaAngle = 0;
  21545. } else {
  21546. deltaAngle = twoPi;
  21547. }
  21548. }
  21549. if ( this.aClockwise === true && ! samePoints ) {
  21550. if ( deltaAngle === twoPi ) {
  21551. deltaAngle = - twoPi;
  21552. } else {
  21553. deltaAngle = deltaAngle - twoPi;
  21554. }
  21555. }
  21556. var angle = this.aStartAngle + t * deltaAngle;
  21557. var x = this.aX + this.xRadius * Math.cos( angle );
  21558. var y = this.aY + this.yRadius * Math.sin( angle );
  21559. if ( this.aRotation !== 0 ) {
  21560. var cos = Math.cos( this.aRotation );
  21561. var sin = Math.sin( this.aRotation );
  21562. var tx = x - this.aX;
  21563. var ty = y - this.aY;
  21564. // Rotate the point about the center of the ellipse.
  21565. x = tx * cos - ty * sin + this.aX;
  21566. y = tx * sin + ty * cos + this.aY;
  21567. }
  21568. return point.set( x, y );
  21569. };
  21570. EllipseCurve.prototype.copy = function ( source ) {
  21571. Curve.prototype.copy.call( this, source );
  21572. this.aX = source.aX;
  21573. this.aY = source.aY;
  21574. this.xRadius = source.xRadius;
  21575. this.yRadius = source.yRadius;
  21576. this.aStartAngle = source.aStartAngle;
  21577. this.aEndAngle = source.aEndAngle;
  21578. this.aClockwise = source.aClockwise;
  21579. this.aRotation = source.aRotation;
  21580. return this;
  21581. };
  21582. EllipseCurve.prototype.toJSON = function () {
  21583. var data = Curve.prototype.toJSON.call( this );
  21584. data.aX = this.aX;
  21585. data.aY = this.aY;
  21586. data.xRadius = this.xRadius;
  21587. data.yRadius = this.yRadius;
  21588. data.aStartAngle = this.aStartAngle;
  21589. data.aEndAngle = this.aEndAngle;
  21590. data.aClockwise = this.aClockwise;
  21591. data.aRotation = this.aRotation;
  21592. return data;
  21593. };
  21594. EllipseCurve.prototype.fromJSON = function ( json ) {
  21595. Curve.prototype.fromJSON.call( this, json );
  21596. this.aX = json.aX;
  21597. this.aY = json.aY;
  21598. this.xRadius = json.xRadius;
  21599. this.yRadius = json.yRadius;
  21600. this.aStartAngle = json.aStartAngle;
  21601. this.aEndAngle = json.aEndAngle;
  21602. this.aClockwise = json.aClockwise;
  21603. this.aRotation = json.aRotation;
  21604. return this;
  21605. };
  21606. function ArcCurve( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  21607. EllipseCurve.call( this, aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise );
  21608. this.type = 'ArcCurve';
  21609. }
  21610. ArcCurve.prototype = Object.create( EllipseCurve.prototype );
  21611. ArcCurve.prototype.constructor = ArcCurve;
  21612. ArcCurve.prototype.isArcCurve = true;
  21613. /**
  21614. * @author zz85 https://github.com/zz85
  21615. *
  21616. * Centripetal CatmullRom Curve - which is useful for avoiding
  21617. * cusps and self-intersections in non-uniform catmull rom curves.
  21618. * http://www.cemyuksel.com/research/catmullrom_param/catmullrom.pdf
  21619. *
  21620. * curve.type accepts centripetal(default), chordal and catmullrom
  21621. * curve.tension is used for catmullrom which defaults to 0.5
  21622. */
  21623. /*
  21624. Based on an optimized c++ solution in
  21625. - http://stackoverflow.com/questions/9489736/catmull-rom-curve-with-no-cusps-and-no-self-intersections/
  21626. - http://ideone.com/NoEbVM
  21627. This CubicPoly class could be used for reusing some variables and calculations,
  21628. but for three.js curve use, it could be possible inlined and flatten into a single function call
  21629. which can be placed in CurveUtils.
  21630. */
  21631. function CubicPoly() {
  21632. var c0 = 0, c1 = 0, c2 = 0, c3 = 0;
  21633. /*
  21634. * Compute coefficients for a cubic polynomial
  21635. * p(s) = c0 + c1*s + c2*s^2 + c3*s^3
  21636. * such that
  21637. * p(0) = x0, p(1) = x1
  21638. * and
  21639. * p'(0) = t0, p'(1) = t1.
  21640. */
  21641. function init( x0, x1, t0, t1 ) {
  21642. c0 = x0;
  21643. c1 = t0;
  21644. c2 = - 3 * x0 + 3 * x1 - 2 * t0 - t1;
  21645. c3 = 2 * x0 - 2 * x1 + t0 + t1;
  21646. }
  21647. return {
  21648. initCatmullRom: function ( x0, x1, x2, x3, tension ) {
  21649. init( x1, x2, tension * ( x2 - x0 ), tension * ( x3 - x1 ) );
  21650. },
  21651. initNonuniformCatmullRom: function ( x0, x1, x2, x3, dt0, dt1, dt2 ) {
  21652. // compute tangents when parameterized in [t1,t2]
  21653. var t1 = ( x1 - x0 ) / dt0 - ( x2 - x0 ) / ( dt0 + dt1 ) + ( x2 - x1 ) / dt1;
  21654. var t2 = ( x2 - x1 ) / dt1 - ( x3 - x1 ) / ( dt1 + dt2 ) + ( x3 - x2 ) / dt2;
  21655. // rescale tangents for parametrization in [0,1]
  21656. t1 *= dt1;
  21657. t2 *= dt1;
  21658. init( x1, x2, t1, t2 );
  21659. },
  21660. calc: function ( t ) {
  21661. var t2 = t * t;
  21662. var t3 = t2 * t;
  21663. return c0 + c1 * t + c2 * t2 + c3 * t3;
  21664. }
  21665. };
  21666. }
  21667. //
  21668. var tmp = new Vector3();
  21669. var px = new CubicPoly(), py = new CubicPoly(), pz = new CubicPoly();
  21670. function CatmullRomCurve3( points, closed, curveType, tension ) {
  21671. Curve.call( this );
  21672. this.type = 'CatmullRomCurve3';
  21673. this.points = points || [];
  21674. this.closed = closed || false;
  21675. this.curveType = curveType || 'centripetal';
  21676. this.tension = tension || 0.5;
  21677. }
  21678. CatmullRomCurve3.prototype = Object.create( Curve.prototype );
  21679. CatmullRomCurve3.prototype.constructor = CatmullRomCurve3;
  21680. CatmullRomCurve3.prototype.isCatmullRomCurve3 = true;
  21681. CatmullRomCurve3.prototype.getPoint = function ( t, optionalTarget ) {
  21682. var point = optionalTarget || new Vector3();
  21683. var points = this.points;
  21684. var l = points.length;
  21685. var p = ( l - ( this.closed ? 0 : 1 ) ) * t;
  21686. var intPoint = Math.floor( p );
  21687. var weight = p - intPoint;
  21688. if ( this.closed ) {
  21689. intPoint += intPoint > 0 ? 0 : ( Math.floor( Math.abs( intPoint ) / l ) + 1 ) * l;
  21690. } else if ( weight === 0 && intPoint === l - 1 ) {
  21691. intPoint = l - 2;
  21692. weight = 1;
  21693. }
  21694. var p0, p1, p2, p3; // 4 points
  21695. if ( this.closed || intPoint > 0 ) {
  21696. p0 = points[ ( intPoint - 1 ) % l ];
  21697. } else {
  21698. // extrapolate first point
  21699. tmp.subVectors( points[ 0 ], points[ 1 ] ).add( points[ 0 ] );
  21700. p0 = tmp;
  21701. }
  21702. p1 = points[ intPoint % l ];
  21703. p2 = points[ ( intPoint + 1 ) % l ];
  21704. if ( this.closed || intPoint + 2 < l ) {
  21705. p3 = points[ ( intPoint + 2 ) % l ];
  21706. } else {
  21707. // extrapolate last point
  21708. tmp.subVectors( points[ l - 1 ], points[ l - 2 ] ).add( points[ l - 1 ] );
  21709. p3 = tmp;
  21710. }
  21711. if ( this.curveType === 'centripetal' || this.curveType === 'chordal' ) {
  21712. // init Centripetal / Chordal Catmull-Rom
  21713. var pow = this.curveType === 'chordal' ? 0.5 : 0.25;
  21714. var dt0 = Math.pow( p0.distanceToSquared( p1 ), pow );
  21715. var dt1 = Math.pow( p1.distanceToSquared( p2 ), pow );
  21716. var dt2 = Math.pow( p2.distanceToSquared( p3 ), pow );
  21717. // safety check for repeated points
  21718. if ( dt1 < 1e-4 ) dt1 = 1.0;
  21719. if ( dt0 < 1e-4 ) dt0 = dt1;
  21720. if ( dt2 < 1e-4 ) dt2 = dt1;
  21721. px.initNonuniformCatmullRom( p0.x, p1.x, p2.x, p3.x, dt0, dt1, dt2 );
  21722. py.initNonuniformCatmullRom( p0.y, p1.y, p2.y, p3.y, dt0, dt1, dt2 );
  21723. pz.initNonuniformCatmullRom( p0.z, p1.z, p2.z, p3.z, dt0, dt1, dt2 );
  21724. } else if ( this.curveType === 'catmullrom' ) {
  21725. px.initCatmullRom( p0.x, p1.x, p2.x, p3.x, this.tension );
  21726. py.initCatmullRom( p0.y, p1.y, p2.y, p3.y, this.tension );
  21727. pz.initCatmullRom( p0.z, p1.z, p2.z, p3.z, this.tension );
  21728. }
  21729. point.set(
  21730. px.calc( weight ),
  21731. py.calc( weight ),
  21732. pz.calc( weight )
  21733. );
  21734. return point;
  21735. };
  21736. CatmullRomCurve3.prototype.copy = function ( source ) {
  21737. Curve.prototype.copy.call( this, source );
  21738. this.points = [];
  21739. for ( var i = 0, l = source.points.length; i < l; i ++ ) {
  21740. var point = source.points[ i ];
  21741. this.points.push( point.clone() );
  21742. }
  21743. this.closed = source.closed;
  21744. this.curveType = source.curveType;
  21745. this.tension = source.tension;
  21746. return this;
  21747. };
  21748. CatmullRomCurve3.prototype.toJSON = function () {
  21749. var data = Curve.prototype.toJSON.call( this );
  21750. data.points = [];
  21751. for ( var i = 0, l = this.points.length; i < l; i ++ ) {
  21752. var point = this.points[ i ];
  21753. data.points.push( point.toArray() );
  21754. }
  21755. data.closed = this.closed;
  21756. data.curveType = this.curveType;
  21757. data.tension = this.tension;
  21758. return data;
  21759. };
  21760. CatmullRomCurve3.prototype.fromJSON = function ( json ) {
  21761. Curve.prototype.fromJSON.call( this, json );
  21762. this.points = [];
  21763. for ( var i = 0, l = json.points.length; i < l; i ++ ) {
  21764. var point = json.points[ i ];
  21765. this.points.push( new Vector3().fromArray( point ) );
  21766. }
  21767. this.closed = json.closed;
  21768. this.curveType = json.curveType;
  21769. this.tension = json.tension;
  21770. return this;
  21771. };
  21772. /**
  21773. * @author zz85 / http://www.lab4games.net/zz85/blog
  21774. *
  21775. * Bezier Curves formulas obtained from
  21776. * http://en.wikipedia.org/wiki/Bézier_curve
  21777. */
  21778. function CatmullRom( t, p0, p1, p2, p3 ) {
  21779. var v0 = ( p2 - p0 ) * 0.5;
  21780. var v1 = ( p3 - p1 ) * 0.5;
  21781. var t2 = t * t;
  21782. var t3 = t * t2;
  21783. return ( 2 * p1 - 2 * p2 + v0 + v1 ) * t3 + ( - 3 * p1 + 3 * p2 - 2 * v0 - v1 ) * t2 + v0 * t + p1;
  21784. }
  21785. //
  21786. function QuadraticBezierP0( t, p ) {
  21787. var k = 1 - t;
  21788. return k * k * p;
  21789. }
  21790. function QuadraticBezierP1( t, p ) {
  21791. return 2 * ( 1 - t ) * t * p;
  21792. }
  21793. function QuadraticBezierP2( t, p ) {
  21794. return t * t * p;
  21795. }
  21796. function QuadraticBezier( t, p0, p1, p2 ) {
  21797. return QuadraticBezierP0( t, p0 ) + QuadraticBezierP1( t, p1 ) +
  21798. QuadraticBezierP2( t, p2 );
  21799. }
  21800. //
  21801. function CubicBezierP0( t, p ) {
  21802. var k = 1 - t;
  21803. return k * k * k * p;
  21804. }
  21805. function CubicBezierP1( t, p ) {
  21806. var k = 1 - t;
  21807. return 3 * k * k * t * p;
  21808. }
  21809. function CubicBezierP2( t, p ) {
  21810. return 3 * ( 1 - t ) * t * t * p;
  21811. }
  21812. function CubicBezierP3( t, p ) {
  21813. return t * t * t * p;
  21814. }
  21815. function CubicBezier( t, p0, p1, p2, p3 ) {
  21816. return CubicBezierP0( t, p0 ) + CubicBezierP1( t, p1 ) + CubicBezierP2( t, p2 ) +
  21817. CubicBezierP3( t, p3 );
  21818. }
  21819. function CubicBezierCurve( v0, v1, v2, v3 ) {
  21820. Curve.call( this );
  21821. this.type = 'CubicBezierCurve';
  21822. this.v0 = v0 || new Vector2();
  21823. this.v1 = v1 || new Vector2();
  21824. this.v2 = v2 || new Vector2();
  21825. this.v3 = v3 || new Vector2();
  21826. }
  21827. CubicBezierCurve.prototype = Object.create( Curve.prototype );
  21828. CubicBezierCurve.prototype.constructor = CubicBezierCurve;
  21829. CubicBezierCurve.prototype.isCubicBezierCurve = true;
  21830. CubicBezierCurve.prototype.getPoint = function ( t, optionalTarget ) {
  21831. var point = optionalTarget || new Vector2();
  21832. var v0 = this.v0, v1 = this.v1, v2 = this.v2, v3 = this.v3;
  21833. point.set(
  21834. CubicBezier( t, v0.x, v1.x, v2.x, v3.x ),
  21835. CubicBezier( t, v0.y, v1.y, v2.y, v3.y )
  21836. );
  21837. return point;
  21838. };
  21839. CubicBezierCurve.prototype.copy = function ( source ) {
  21840. Curve.prototype.copy.call( this, source );
  21841. this.v0.copy( source.v0 );
  21842. this.v1.copy( source.v1 );
  21843. this.v2.copy( source.v2 );
  21844. this.v3.copy( source.v3 );
  21845. return this;
  21846. };
  21847. CubicBezierCurve.prototype.toJSON = function () {
  21848. var data = Curve.prototype.toJSON.call( this );
  21849. data.v0 = this.v0.toArray();
  21850. data.v1 = this.v1.toArray();
  21851. data.v2 = this.v2.toArray();
  21852. data.v3 = this.v3.toArray();
  21853. return data;
  21854. };
  21855. CubicBezierCurve.prototype.fromJSON = function ( json ) {
  21856. Curve.prototype.fromJSON.call( this, json );
  21857. this.v0.fromArray( json.v0 );
  21858. this.v1.fromArray( json.v1 );
  21859. this.v2.fromArray( json.v2 );
  21860. this.v3.fromArray( json.v3 );
  21861. return this;
  21862. };
  21863. function CubicBezierCurve3( v0, v1, v2, v3 ) {
  21864. Curve.call( this );
  21865. this.type = 'CubicBezierCurve3';
  21866. this.v0 = v0 || new Vector3();
  21867. this.v1 = v1 || new Vector3();
  21868. this.v2 = v2 || new Vector3();
  21869. this.v3 = v3 || new Vector3();
  21870. }
  21871. CubicBezierCurve3.prototype = Object.create( Curve.prototype );
  21872. CubicBezierCurve3.prototype.constructor = CubicBezierCurve3;
  21873. CubicBezierCurve3.prototype.isCubicBezierCurve3 = true;
  21874. CubicBezierCurve3.prototype.getPoint = function ( t, optionalTarget ) {
  21875. var point = optionalTarget || new Vector3();
  21876. var v0 = this.v0, v1 = this.v1, v2 = this.v2, v3 = this.v3;
  21877. point.set(
  21878. CubicBezier( t, v0.x, v1.x, v2.x, v3.x ),
  21879. CubicBezier( t, v0.y, v1.y, v2.y, v3.y ),
  21880. CubicBezier( t, v0.z, v1.z, v2.z, v3.z )
  21881. );
  21882. return point;
  21883. };
  21884. CubicBezierCurve3.prototype.copy = function ( source ) {
  21885. Curve.prototype.copy.call( this, source );
  21886. this.v0.copy( source.v0 );
  21887. this.v1.copy( source.v1 );
  21888. this.v2.copy( source.v2 );
  21889. this.v3.copy( source.v3 );
  21890. return this;
  21891. };
  21892. CubicBezierCurve3.prototype.toJSON = function () {
  21893. var data = Curve.prototype.toJSON.call( this );
  21894. data.v0 = this.v0.toArray();
  21895. data.v1 = this.v1.toArray();
  21896. data.v2 = this.v2.toArray();
  21897. data.v3 = this.v3.toArray();
  21898. return data;
  21899. };
  21900. CubicBezierCurve3.prototype.fromJSON = function ( json ) {
  21901. Curve.prototype.fromJSON.call( this, json );
  21902. this.v0.fromArray( json.v0 );
  21903. this.v1.fromArray( json.v1 );
  21904. this.v2.fromArray( json.v2 );
  21905. this.v3.fromArray( json.v3 );
  21906. return this;
  21907. };
  21908. function LineCurve( v1, v2 ) {
  21909. Curve.call( this );
  21910. this.type = 'LineCurve';
  21911. this.v1 = v1 || new Vector2();
  21912. this.v2 = v2 || new Vector2();
  21913. }
  21914. LineCurve.prototype = Object.create( Curve.prototype );
  21915. LineCurve.prototype.constructor = LineCurve;
  21916. LineCurve.prototype.isLineCurve = true;
  21917. LineCurve.prototype.getPoint = function ( t, optionalTarget ) {
  21918. var point = optionalTarget || new Vector2();
  21919. if ( t === 1 ) {
  21920. point.copy( this.v2 );
  21921. } else {
  21922. point.copy( this.v2 ).sub( this.v1 );
  21923. point.multiplyScalar( t ).add( this.v1 );
  21924. }
  21925. return point;
  21926. };
  21927. // Line curve is linear, so we can overwrite default getPointAt
  21928. LineCurve.prototype.getPointAt = function ( u, optionalTarget ) {
  21929. return this.getPoint( u, optionalTarget );
  21930. };
  21931. LineCurve.prototype.getTangent = function ( /* t */ ) {
  21932. var tangent = this.v2.clone().sub( this.v1 );
  21933. return tangent.normalize();
  21934. };
  21935. LineCurve.prototype.copy = function ( source ) {
  21936. Curve.prototype.copy.call( this, source );
  21937. this.v1.copy( source.v1 );
  21938. this.v2.copy( source.v2 );
  21939. return this;
  21940. };
  21941. LineCurve.prototype.toJSON = function () {
  21942. var data = Curve.prototype.toJSON.call( this );
  21943. data.v1 = this.v1.toArray();
  21944. data.v2 = this.v2.toArray();
  21945. return data;
  21946. };
  21947. LineCurve.prototype.fromJSON = function ( json ) {
  21948. Curve.prototype.fromJSON.call( this, json );
  21949. this.v1.fromArray( json.v1 );
  21950. this.v2.fromArray( json.v2 );
  21951. return this;
  21952. };
  21953. function LineCurve3( v1, v2 ) {
  21954. Curve.call( this );
  21955. this.type = 'LineCurve3';
  21956. this.v1 = v1 || new Vector3();
  21957. this.v2 = v2 || new Vector3();
  21958. }
  21959. LineCurve3.prototype = Object.create( Curve.prototype );
  21960. LineCurve3.prototype.constructor = LineCurve3;
  21961. LineCurve3.prototype.isLineCurve3 = true;
  21962. LineCurve3.prototype.getPoint = function ( t, optionalTarget ) {
  21963. var point = optionalTarget || new Vector3();
  21964. if ( t === 1 ) {
  21965. point.copy( this.v2 );
  21966. } else {
  21967. point.copy( this.v2 ).sub( this.v1 );
  21968. point.multiplyScalar( t ).add( this.v1 );
  21969. }
  21970. return point;
  21971. };
  21972. // Line curve is linear, so we can overwrite default getPointAt
  21973. LineCurve3.prototype.getPointAt = function ( u, optionalTarget ) {
  21974. return this.getPoint( u, optionalTarget );
  21975. };
  21976. LineCurve3.prototype.copy = function ( source ) {
  21977. Curve.prototype.copy.call( this, source );
  21978. this.v1.copy( source.v1 );
  21979. this.v2.copy( source.v2 );
  21980. return this;
  21981. };
  21982. LineCurve3.prototype.toJSON = function () {
  21983. var data = Curve.prototype.toJSON.call( this );
  21984. data.v1 = this.v1.toArray();
  21985. data.v2 = this.v2.toArray();
  21986. return data;
  21987. };
  21988. LineCurve3.prototype.fromJSON = function ( json ) {
  21989. Curve.prototype.fromJSON.call( this, json );
  21990. this.v1.fromArray( json.v1 );
  21991. this.v2.fromArray( json.v2 );
  21992. return this;
  21993. };
  21994. function QuadraticBezierCurve( v0, v1, v2 ) {
  21995. Curve.call( this );
  21996. this.type = 'QuadraticBezierCurve';
  21997. this.v0 = v0 || new Vector2();
  21998. this.v1 = v1 || new Vector2();
  21999. this.v2 = v2 || new Vector2();
  22000. }
  22001. QuadraticBezierCurve.prototype = Object.create( Curve.prototype );
  22002. QuadraticBezierCurve.prototype.constructor = QuadraticBezierCurve;
  22003. QuadraticBezierCurve.prototype.isQuadraticBezierCurve = true;
  22004. QuadraticBezierCurve.prototype.getPoint = function ( t, optionalTarget ) {
  22005. var point = optionalTarget || new Vector2();
  22006. var v0 = this.v0, v1 = this.v1, v2 = this.v2;
  22007. point.set(
  22008. QuadraticBezier( t, v0.x, v1.x, v2.x ),
  22009. QuadraticBezier( t, v0.y, v1.y, v2.y )
  22010. );
  22011. return point;
  22012. };
  22013. QuadraticBezierCurve.prototype.copy = function ( source ) {
  22014. Curve.prototype.copy.call( this, source );
  22015. this.v0.copy( source.v0 );
  22016. this.v1.copy( source.v1 );
  22017. this.v2.copy( source.v2 );
  22018. return this;
  22019. };
  22020. QuadraticBezierCurve.prototype.toJSON = function () {
  22021. var data = Curve.prototype.toJSON.call( this );
  22022. data.v0 = this.v0.toArray();
  22023. data.v1 = this.v1.toArray();
  22024. data.v2 = this.v2.toArray();
  22025. return data;
  22026. };
  22027. QuadraticBezierCurve.prototype.fromJSON = function ( json ) {
  22028. Curve.prototype.fromJSON.call( this, json );
  22029. this.v0.fromArray( json.v0 );
  22030. this.v1.fromArray( json.v1 );
  22031. this.v2.fromArray( json.v2 );
  22032. return this;
  22033. };
  22034. function QuadraticBezierCurve3( v0, v1, v2 ) {
  22035. Curve.call( this );
  22036. this.type = 'QuadraticBezierCurve3';
  22037. this.v0 = v0 || new Vector3();
  22038. this.v1 = v1 || new Vector3();
  22039. this.v2 = v2 || new Vector3();
  22040. }
  22041. QuadraticBezierCurve3.prototype = Object.create( Curve.prototype );
  22042. QuadraticBezierCurve3.prototype.constructor = QuadraticBezierCurve3;
  22043. QuadraticBezierCurve3.prototype.isQuadraticBezierCurve3 = true;
  22044. QuadraticBezierCurve3.prototype.getPoint = function ( t, optionalTarget ) {
  22045. var point = optionalTarget || new Vector3();
  22046. var v0 = this.v0, v1 = this.v1, v2 = this.v2;
  22047. point.set(
  22048. QuadraticBezier( t, v0.x, v1.x, v2.x ),
  22049. QuadraticBezier( t, v0.y, v1.y, v2.y ),
  22050. QuadraticBezier( t, v0.z, v1.z, v2.z )
  22051. );
  22052. return point;
  22053. };
  22054. QuadraticBezierCurve3.prototype.copy = function ( source ) {
  22055. Curve.prototype.copy.call( this, source );
  22056. this.v0.copy( source.v0 );
  22057. this.v1.copy( source.v1 );
  22058. this.v2.copy( source.v2 );
  22059. return this;
  22060. };
  22061. QuadraticBezierCurve3.prototype.toJSON = function () {
  22062. var data = Curve.prototype.toJSON.call( this );
  22063. data.v0 = this.v0.toArray();
  22064. data.v1 = this.v1.toArray();
  22065. data.v2 = this.v2.toArray();
  22066. return data;
  22067. };
  22068. QuadraticBezierCurve3.prototype.fromJSON = function ( json ) {
  22069. Curve.prototype.fromJSON.call( this, json );
  22070. this.v0.fromArray( json.v0 );
  22071. this.v1.fromArray( json.v1 );
  22072. this.v2.fromArray( json.v2 );
  22073. return this;
  22074. };
  22075. function SplineCurve( points /* array of Vector2 */ ) {
  22076. Curve.call( this );
  22077. this.type = 'SplineCurve';
  22078. this.points = points || [];
  22079. }
  22080. SplineCurve.prototype = Object.create( Curve.prototype );
  22081. SplineCurve.prototype.constructor = SplineCurve;
  22082. SplineCurve.prototype.isSplineCurve = true;
  22083. SplineCurve.prototype.getPoint = function ( t, optionalTarget ) {
  22084. var point = optionalTarget || new Vector2();
  22085. var points = this.points;
  22086. var p = ( points.length - 1 ) * t;
  22087. var intPoint = Math.floor( p );
  22088. var weight = p - intPoint;
  22089. var p0 = points[ intPoint === 0 ? intPoint : intPoint - 1 ];
  22090. var p1 = points[ intPoint ];
  22091. var p2 = points[ intPoint > points.length - 2 ? points.length - 1 : intPoint + 1 ];
  22092. var p3 = points[ intPoint > points.length - 3 ? points.length - 1 : intPoint + 2 ];
  22093. point.set(
  22094. CatmullRom( weight, p0.x, p1.x, p2.x, p3.x ),
  22095. CatmullRom( weight, p0.y, p1.y, p2.y, p3.y )
  22096. );
  22097. return point;
  22098. };
  22099. SplineCurve.prototype.copy = function ( source ) {
  22100. Curve.prototype.copy.call( this, source );
  22101. this.points = [];
  22102. for ( var i = 0, l = source.points.length; i < l; i ++ ) {
  22103. var point = source.points[ i ];
  22104. this.points.push( point.clone() );
  22105. }
  22106. return this;
  22107. };
  22108. SplineCurve.prototype.toJSON = function () {
  22109. var data = Curve.prototype.toJSON.call( this );
  22110. data.points = [];
  22111. for ( var i = 0, l = this.points.length; i < l; i ++ ) {
  22112. var point = this.points[ i ];
  22113. data.points.push( point.toArray() );
  22114. }
  22115. return data;
  22116. };
  22117. SplineCurve.prototype.fromJSON = function ( json ) {
  22118. Curve.prototype.fromJSON.call( this, json );
  22119. this.points = [];
  22120. for ( var i = 0, l = json.points.length; i < l; i ++ ) {
  22121. var point = json.points[ i ];
  22122. this.points.push( new Vector2().fromArray( point ) );
  22123. }
  22124. return this;
  22125. };
  22126. var Curves = /*#__PURE__*/Object.freeze({
  22127. ArcCurve: ArcCurve,
  22128. CatmullRomCurve3: CatmullRomCurve3,
  22129. CubicBezierCurve: CubicBezierCurve,
  22130. CubicBezierCurve3: CubicBezierCurve3,
  22131. EllipseCurve: EllipseCurve,
  22132. LineCurve: LineCurve,
  22133. LineCurve3: LineCurve3,
  22134. QuadraticBezierCurve: QuadraticBezierCurve,
  22135. QuadraticBezierCurve3: QuadraticBezierCurve3,
  22136. SplineCurve: SplineCurve
  22137. });
  22138. /**
  22139. * @author zz85 / http://www.lab4games.net/zz85/blog
  22140. *
  22141. **/
  22142. /**************************************************************
  22143. * Curved Path - a curve path is simply a array of connected
  22144. * curves, but retains the api of a curve
  22145. **************************************************************/
  22146. function CurvePath() {
  22147. Curve.call( this );
  22148. this.type = 'CurvePath';
  22149. this.curves = [];
  22150. this.autoClose = false; // Automatically closes the path
  22151. }
  22152. CurvePath.prototype = Object.assign( Object.create( Curve.prototype ), {
  22153. constructor: CurvePath,
  22154. add: function ( curve ) {
  22155. this.curves.push( curve );
  22156. },
  22157. closePath: function () {
  22158. // Add a line curve if start and end of lines are not connected
  22159. var startPoint = this.curves[ 0 ].getPoint( 0 );
  22160. var endPoint = this.curves[ this.curves.length - 1 ].getPoint( 1 );
  22161. if ( ! startPoint.equals( endPoint ) ) {
  22162. this.curves.push( new LineCurve( endPoint, startPoint ) );
  22163. }
  22164. },
  22165. // To get accurate point with reference to
  22166. // entire path distance at time t,
  22167. // following has to be done:
  22168. // 1. Length of each sub path have to be known
  22169. // 2. Locate and identify type of curve
  22170. // 3. Get t for the curve
  22171. // 4. Return curve.getPointAt(t')
  22172. getPoint: function ( t ) {
  22173. var d = t * this.getLength();
  22174. var curveLengths = this.getCurveLengths();
  22175. var i = 0;
  22176. // To think about boundaries points.
  22177. while ( i < curveLengths.length ) {
  22178. if ( curveLengths[ i ] >= d ) {
  22179. var diff = curveLengths[ i ] - d;
  22180. var curve = this.curves[ i ];
  22181. var segmentLength = curve.getLength();
  22182. var u = segmentLength === 0 ? 0 : 1 - diff / segmentLength;
  22183. return curve.getPointAt( u );
  22184. }
  22185. i ++;
  22186. }
  22187. return null;
  22188. // loop where sum != 0, sum > d , sum+1 <d
  22189. },
  22190. // We cannot use the default THREE.Curve getPoint() with getLength() because in
  22191. // THREE.Curve, getLength() depends on getPoint() but in THREE.CurvePath
  22192. // getPoint() depends on getLength
  22193. getLength: function () {
  22194. var lens = this.getCurveLengths();
  22195. return lens[ lens.length - 1 ];
  22196. },
  22197. // cacheLengths must be recalculated.
  22198. updateArcLengths: function () {
  22199. this.needsUpdate = true;
  22200. this.cacheLengths = null;
  22201. this.getCurveLengths();
  22202. },
  22203. // Compute lengths and cache them
  22204. // We cannot overwrite getLengths() because UtoT mapping uses it.
  22205. getCurveLengths: function () {
  22206. // We use cache values if curves and cache array are same length
  22207. if ( this.cacheLengths && this.cacheLengths.length === this.curves.length ) {
  22208. return this.cacheLengths;
  22209. }
  22210. // Get length of sub-curve
  22211. // Push sums into cached array
  22212. var lengths = [], sums = 0;
  22213. for ( var i = 0, l = this.curves.length; i < l; i ++ ) {
  22214. sums += this.curves[ i ].getLength();
  22215. lengths.push( sums );
  22216. }
  22217. this.cacheLengths = lengths;
  22218. return lengths;
  22219. },
  22220. getSpacedPoints: function ( divisions ) {
  22221. if ( divisions === undefined ) divisions = 40;
  22222. var points = [];
  22223. for ( var i = 0; i <= divisions; i ++ ) {
  22224. points.push( this.getPoint( i / divisions ) );
  22225. }
  22226. if ( this.autoClose ) {
  22227. points.push( points[ 0 ] );
  22228. }
  22229. return points;
  22230. },
  22231. getPoints: function ( divisions ) {
  22232. divisions = divisions || 12;
  22233. var points = [], last;
  22234. for ( var i = 0, curves = this.curves; i < curves.length; i ++ ) {
  22235. var curve = curves[ i ];
  22236. var resolution = ( curve && curve.isEllipseCurve ) ? divisions * 2
  22237. : ( curve && ( curve.isLineCurve || curve.isLineCurve3 ) ) ? 1
  22238. : ( curve && curve.isSplineCurve ) ? divisions * curve.points.length
  22239. : divisions;
  22240. var pts = curve.getPoints( resolution );
  22241. for ( var j = 0; j < pts.length; j ++ ) {
  22242. var point = pts[ j ];
  22243. if ( last && last.equals( point ) ) continue; // ensures no consecutive points are duplicates
  22244. points.push( point );
  22245. last = point;
  22246. }
  22247. }
  22248. if ( this.autoClose && points.length > 1 && ! points[ points.length - 1 ].equals( points[ 0 ] ) ) {
  22249. points.push( points[ 0 ] );
  22250. }
  22251. return points;
  22252. },
  22253. copy: function ( source ) {
  22254. Curve.prototype.copy.call( this, source );
  22255. this.curves = [];
  22256. for ( var i = 0, l = source.curves.length; i < l; i ++ ) {
  22257. var curve = source.curves[ i ];
  22258. this.curves.push( curve.clone() );
  22259. }
  22260. this.autoClose = source.autoClose;
  22261. return this;
  22262. },
  22263. toJSON: function () {
  22264. var data = Curve.prototype.toJSON.call( this );
  22265. data.autoClose = this.autoClose;
  22266. data.curves = [];
  22267. for ( var i = 0, l = this.curves.length; i < l; i ++ ) {
  22268. var curve = this.curves[ i ];
  22269. data.curves.push( curve.toJSON() );
  22270. }
  22271. return data;
  22272. },
  22273. fromJSON: function ( json ) {
  22274. Curve.prototype.fromJSON.call( this, json );
  22275. this.autoClose = json.autoClose;
  22276. this.curves = [];
  22277. for ( var i = 0, l = json.curves.length; i < l; i ++ ) {
  22278. var curve = json.curves[ i ];
  22279. this.curves.push( new Curves[ curve.type ]().fromJSON( curve ) );
  22280. }
  22281. return this;
  22282. }
  22283. } );
  22284. /**
  22285. * @author zz85 / http://www.lab4games.net/zz85/blog
  22286. * Creates free form 2d path using series of points, lines or curves.
  22287. **/
  22288. function Path( points ) {
  22289. CurvePath.call( this );
  22290. this.type = 'Path';
  22291. this.currentPoint = new Vector2();
  22292. if ( points ) {
  22293. this.setFromPoints( points );
  22294. }
  22295. }
  22296. Path.prototype = Object.assign( Object.create( CurvePath.prototype ), {
  22297. constructor: Path,
  22298. setFromPoints: function ( points ) {
  22299. this.moveTo( points[ 0 ].x, points[ 0 ].y );
  22300. for ( var i = 1, l = points.length; i < l; i ++ ) {
  22301. this.lineTo( points[ i ].x, points[ i ].y );
  22302. }
  22303. },
  22304. moveTo: function ( x, y ) {
  22305. this.currentPoint.set( x, y ); // TODO consider referencing vectors instead of copying?
  22306. },
  22307. lineTo: function ( x, y ) {
  22308. var curve = new LineCurve( this.currentPoint.clone(), new Vector2( x, y ) );
  22309. this.curves.push( curve );
  22310. this.currentPoint.set( x, y );
  22311. },
  22312. quadraticCurveTo: function ( aCPx, aCPy, aX, aY ) {
  22313. var curve = new QuadraticBezierCurve(
  22314. this.currentPoint.clone(),
  22315. new Vector2( aCPx, aCPy ),
  22316. new Vector2( aX, aY )
  22317. );
  22318. this.curves.push( curve );
  22319. this.currentPoint.set( aX, aY );
  22320. },
  22321. bezierCurveTo: function ( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY ) {
  22322. var curve = new CubicBezierCurve(
  22323. this.currentPoint.clone(),
  22324. new Vector2( aCP1x, aCP1y ),
  22325. new Vector2( aCP2x, aCP2y ),
  22326. new Vector2( aX, aY )
  22327. );
  22328. this.curves.push( curve );
  22329. this.currentPoint.set( aX, aY );
  22330. },
  22331. splineThru: function ( pts /*Array of Vector*/ ) {
  22332. var npts = [ this.currentPoint.clone() ].concat( pts );
  22333. var curve = new SplineCurve( npts );
  22334. this.curves.push( curve );
  22335. this.currentPoint.copy( pts[ pts.length - 1 ] );
  22336. },
  22337. arc: function ( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  22338. var x0 = this.currentPoint.x;
  22339. var y0 = this.currentPoint.y;
  22340. this.absarc( aX + x0, aY + y0, aRadius,
  22341. aStartAngle, aEndAngle, aClockwise );
  22342. },
  22343. absarc: function ( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  22344. this.absellipse( aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise );
  22345. },
  22346. ellipse: function ( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  22347. var x0 = this.currentPoint.x;
  22348. var y0 = this.currentPoint.y;
  22349. this.absellipse( aX + x0, aY + y0, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation );
  22350. },
  22351. absellipse: function ( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  22352. var curve = new EllipseCurve( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation );
  22353. if ( this.curves.length > 0 ) {
  22354. // if a previous curve is present, attempt to join
  22355. var firstPoint = curve.getPoint( 0 );
  22356. if ( ! firstPoint.equals( this.currentPoint ) ) {
  22357. this.lineTo( firstPoint.x, firstPoint.y );
  22358. }
  22359. }
  22360. this.curves.push( curve );
  22361. var lastPoint = curve.getPoint( 1 );
  22362. this.currentPoint.copy( lastPoint );
  22363. },
  22364. copy: function ( source ) {
  22365. CurvePath.prototype.copy.call( this, source );
  22366. this.currentPoint.copy( source.currentPoint );
  22367. return this;
  22368. },
  22369. toJSON: function () {
  22370. var data = CurvePath.prototype.toJSON.call( this );
  22371. data.currentPoint = this.currentPoint.toArray();
  22372. return data;
  22373. },
  22374. fromJSON: function ( json ) {
  22375. CurvePath.prototype.fromJSON.call( this, json );
  22376. this.currentPoint.fromArray( json.currentPoint );
  22377. return this;
  22378. }
  22379. } );
  22380. /**
  22381. * @author zz85 / http://www.lab4games.net/zz85/blog
  22382. * Defines a 2d shape plane using paths.
  22383. **/
  22384. // STEP 1 Create a path.
  22385. // STEP 2 Turn path into shape.
  22386. // STEP 3 ExtrudeGeometry takes in Shape/Shapes
  22387. // STEP 3a - Extract points from each shape, turn to vertices
  22388. // STEP 3b - Triangulate each shape, add faces.
  22389. function Shape( points ) {
  22390. Path.call( this, points );
  22391. this.uuid = _Math.generateUUID();
  22392. this.type = 'Shape';
  22393. this.holes = [];
  22394. }
  22395. Shape.prototype = Object.assign( Object.create( Path.prototype ), {
  22396. constructor: Shape,
  22397. getPointsHoles: function ( divisions ) {
  22398. var holesPts = [];
  22399. for ( var i = 0, l = this.holes.length; i < l; i ++ ) {
  22400. holesPts[ i ] = this.holes[ i ].getPoints( divisions );
  22401. }
  22402. return holesPts;
  22403. },
  22404. // get points of shape and holes (keypoints based on segments parameter)
  22405. extractPoints: function ( divisions ) {
  22406. return {
  22407. shape: this.getPoints( divisions ),
  22408. holes: this.getPointsHoles( divisions )
  22409. };
  22410. },
  22411. copy: function ( source ) {
  22412. Path.prototype.copy.call( this, source );
  22413. this.holes = [];
  22414. for ( var i = 0, l = source.holes.length; i < l; i ++ ) {
  22415. var hole = source.holes[ i ];
  22416. this.holes.push( hole.clone() );
  22417. }
  22418. return this;
  22419. },
  22420. toJSON: function () {
  22421. var data = Path.prototype.toJSON.call( this );
  22422. data.uuid = this.uuid;
  22423. data.holes = [];
  22424. for ( var i = 0, l = this.holes.length; i < l; i ++ ) {
  22425. var hole = this.holes[ i ];
  22426. data.holes.push( hole.toJSON() );
  22427. }
  22428. return data;
  22429. },
  22430. fromJSON: function ( json ) {
  22431. Path.prototype.fromJSON.call( this, json );
  22432. this.uuid = json.uuid;
  22433. this.holes = [];
  22434. for ( var i = 0, l = json.holes.length; i < l; i ++ ) {
  22435. var hole = json.holes[ i ];
  22436. this.holes.push( new Path().fromJSON( hole ) );
  22437. }
  22438. return this;
  22439. }
  22440. } );
  22441. /**
  22442. * @author mrdoob / http://mrdoob.com/
  22443. * @author alteredq / http://alteredqualia.com/
  22444. */
  22445. function Light( color, intensity ) {
  22446. Object3D.call( this );
  22447. this.type = 'Light';
  22448. this.color = new Color( color );
  22449. this.intensity = intensity !== undefined ? intensity : 1;
  22450. this.receiveShadow = undefined;
  22451. }
  22452. Light.prototype = Object.assign( Object.create( Object3D.prototype ), {
  22453. constructor: Light,
  22454. isLight: true,
  22455. copy: function ( source ) {
  22456. Object3D.prototype.copy.call( this, source );
  22457. this.color.copy( source.color );
  22458. this.intensity = source.intensity;
  22459. return this;
  22460. },
  22461. toJSON: function ( meta ) {
  22462. var data = Object3D.prototype.toJSON.call( this, meta );
  22463. data.object.color = this.color.getHex();
  22464. data.object.intensity = this.intensity;
  22465. if ( this.groundColor !== undefined ) data.object.groundColor = this.groundColor.getHex();
  22466. if ( this.distance !== undefined ) data.object.distance = this.distance;
  22467. if ( this.angle !== undefined ) data.object.angle = this.angle;
  22468. if ( this.decay !== undefined ) data.object.decay = this.decay;
  22469. if ( this.penumbra !== undefined ) data.object.penumbra = this.penumbra;
  22470. if ( this.shadow !== undefined ) data.object.shadow = this.shadow.toJSON();
  22471. return data;
  22472. }
  22473. } );
  22474. /**
  22475. * @author alteredq / http://alteredqualia.com/
  22476. */
  22477. function HemisphereLight( skyColor, groundColor, intensity ) {
  22478. Light.call( this, skyColor, intensity );
  22479. this.type = 'HemisphereLight';
  22480. this.castShadow = undefined;
  22481. this.position.copy( Object3D.DefaultUp );
  22482. this.updateMatrix();
  22483. this.groundColor = new Color( groundColor );
  22484. }
  22485. HemisphereLight.prototype = Object.assign( Object.create( Light.prototype ), {
  22486. constructor: HemisphereLight,
  22487. isHemisphereLight: true,
  22488. copy: function ( source ) {
  22489. Light.prototype.copy.call( this, source );
  22490. this.groundColor.copy( source.groundColor );
  22491. return this;
  22492. }
  22493. } );
  22494. /**
  22495. * @author mrdoob / http://mrdoob.com/
  22496. */
  22497. function LightShadow( camera ) {
  22498. this.camera = camera;
  22499. this.bias = 0;
  22500. this.radius = 1;
  22501. this.mapSize = new Vector2( 512, 512 );
  22502. this.map = null;
  22503. this.matrix = new Matrix4();
  22504. }
  22505. Object.assign( LightShadow.prototype, {
  22506. copy: function ( source ) {
  22507. this.camera = source.camera.clone();
  22508. this.bias = source.bias;
  22509. this.radius = source.radius;
  22510. this.mapSize.copy( source.mapSize );
  22511. return this;
  22512. },
  22513. clone: function () {
  22514. return new this.constructor().copy( this );
  22515. },
  22516. toJSON: function () {
  22517. var object = {};
  22518. if ( this.bias !== 0 ) object.bias = this.bias;
  22519. if ( this.radius !== 1 ) object.radius = this.radius;
  22520. if ( this.mapSize.x !== 512 || this.mapSize.y !== 512 ) object.mapSize = this.mapSize.toArray();
  22521. object.camera = this.camera.toJSON( false ).object;
  22522. delete object.camera.matrix;
  22523. return object;
  22524. }
  22525. } );
  22526. /**
  22527. * @author mrdoob / http://mrdoob.com/
  22528. */
  22529. function SpotLightShadow() {
  22530. LightShadow.call( this, new PerspectiveCamera( 50, 1, 0.5, 500 ) );
  22531. }
  22532. SpotLightShadow.prototype = Object.assign( Object.create( LightShadow.prototype ), {
  22533. constructor: SpotLightShadow,
  22534. isSpotLightShadow: true,
  22535. update: function ( light ) {
  22536. var camera = this.camera;
  22537. var fov = _Math.RAD2DEG * 2 * light.angle;
  22538. var aspect = this.mapSize.width / this.mapSize.height;
  22539. var far = light.distance || camera.far;
  22540. if ( fov !== camera.fov || aspect !== camera.aspect || far !== camera.far ) {
  22541. camera.fov = fov;
  22542. camera.aspect = aspect;
  22543. camera.far = far;
  22544. camera.updateProjectionMatrix();
  22545. }
  22546. }
  22547. } );
  22548. /**
  22549. * @author alteredq / http://alteredqualia.com/
  22550. */
  22551. function SpotLight( color, intensity, distance, angle, penumbra, decay ) {
  22552. Light.call( this, color, intensity );
  22553. this.type = 'SpotLight';
  22554. this.position.copy( Object3D.DefaultUp );
  22555. this.updateMatrix();
  22556. this.target = new Object3D();
  22557. Object.defineProperty( this, 'power', {
  22558. get: function () {
  22559. // intensity = power per solid angle.
  22560. // ref: equation (17) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  22561. return this.intensity * Math.PI;
  22562. },
  22563. set: function ( power ) {
  22564. // intensity = power per solid angle.
  22565. // ref: equation (17) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  22566. this.intensity = power / Math.PI;
  22567. }
  22568. } );
  22569. this.distance = ( distance !== undefined ) ? distance : 0;
  22570. this.angle = ( angle !== undefined ) ? angle : Math.PI / 3;
  22571. this.penumbra = ( penumbra !== undefined ) ? penumbra : 0;
  22572. this.decay = ( decay !== undefined ) ? decay : 1; // for physically correct lights, should be 2.
  22573. this.shadow = new SpotLightShadow();
  22574. }
  22575. SpotLight.prototype = Object.assign( Object.create( Light.prototype ), {
  22576. constructor: SpotLight,
  22577. isSpotLight: true,
  22578. copy: function ( source ) {
  22579. Light.prototype.copy.call( this, source );
  22580. this.distance = source.distance;
  22581. this.angle = source.angle;
  22582. this.penumbra = source.penumbra;
  22583. this.decay = source.decay;
  22584. this.target = source.target.clone();
  22585. this.shadow = source.shadow.clone();
  22586. return this;
  22587. }
  22588. } );
  22589. /**
  22590. * @author mrdoob / http://mrdoob.com/
  22591. */
  22592. function PointLight( color, intensity, distance, decay ) {
  22593. Light.call( this, color, intensity );
  22594. this.type = 'PointLight';
  22595. Object.defineProperty( this, 'power', {
  22596. get: function () {
  22597. // intensity = power per solid angle.
  22598. // ref: equation (15) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  22599. return this.intensity * 4 * Math.PI;
  22600. },
  22601. set: function ( power ) {
  22602. // intensity = power per solid angle.
  22603. // ref: equation (15) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  22604. this.intensity = power / ( 4 * Math.PI );
  22605. }
  22606. } );
  22607. this.distance = ( distance !== undefined ) ? distance : 0;
  22608. this.decay = ( decay !== undefined ) ? decay : 1; // for physically correct lights, should be 2.
  22609. this.shadow = new LightShadow( new PerspectiveCamera( 90, 1, 0.5, 500 ) );
  22610. }
  22611. PointLight.prototype = Object.assign( Object.create( Light.prototype ), {
  22612. constructor: PointLight,
  22613. isPointLight: true,
  22614. copy: function ( source ) {
  22615. Light.prototype.copy.call( this, source );
  22616. this.distance = source.distance;
  22617. this.decay = source.decay;
  22618. this.shadow = source.shadow.clone();
  22619. return this;
  22620. }
  22621. } );
  22622. /**
  22623. * @author alteredq / http://alteredqualia.com/
  22624. * @author arose / http://github.com/arose
  22625. */
  22626. function OrthographicCamera( left, right, top, bottom, near, far ) {
  22627. Camera.call( this );
  22628. this.type = 'OrthographicCamera';
  22629. this.zoom = 1;
  22630. this.view = null;
  22631. this.left = ( left !== undefined ) ? left : - 1;
  22632. this.right = ( right !== undefined ) ? right : 1;
  22633. this.top = ( top !== undefined ) ? top : 1;
  22634. this.bottom = ( bottom !== undefined ) ? bottom : - 1;
  22635. this.near = ( near !== undefined ) ? near : 0.1;
  22636. this.far = ( far !== undefined ) ? far : 2000;
  22637. this.updateProjectionMatrix();
  22638. }
  22639. OrthographicCamera.prototype = Object.assign( Object.create( Camera.prototype ), {
  22640. constructor: OrthographicCamera,
  22641. isOrthographicCamera: true,
  22642. copy: function ( source, recursive ) {
  22643. Camera.prototype.copy.call( this, source, recursive );
  22644. this.left = source.left;
  22645. this.right = source.right;
  22646. this.top = source.top;
  22647. this.bottom = source.bottom;
  22648. this.near = source.near;
  22649. this.far = source.far;
  22650. this.zoom = source.zoom;
  22651. this.view = source.view === null ? null : Object.assign( {}, source.view );
  22652. return this;
  22653. },
  22654. setViewOffset: function ( fullWidth, fullHeight, x, y, width, height ) {
  22655. if ( this.view === null ) {
  22656. this.view = {
  22657. enabled: true,
  22658. fullWidth: 1,
  22659. fullHeight: 1,
  22660. offsetX: 0,
  22661. offsetY: 0,
  22662. width: 1,
  22663. height: 1
  22664. };
  22665. }
  22666. this.view.enabled = true;
  22667. this.view.fullWidth = fullWidth;
  22668. this.view.fullHeight = fullHeight;
  22669. this.view.offsetX = x;
  22670. this.view.offsetY = y;
  22671. this.view.width = width;
  22672. this.view.height = height;
  22673. this.updateProjectionMatrix();
  22674. },
  22675. clearViewOffset: function () {
  22676. if ( this.view !== null ) {
  22677. this.view.enabled = false;
  22678. }
  22679. this.updateProjectionMatrix();
  22680. },
  22681. updateProjectionMatrix: function () {
  22682. var dx = ( this.right - this.left ) / ( 2 * this.zoom );
  22683. var dy = ( this.top - this.bottom ) / ( 2 * this.zoom );
  22684. var cx = ( this.right + this.left ) / 2;
  22685. var cy = ( this.top + this.bottom ) / 2;
  22686. var left = cx - dx;
  22687. var right = cx + dx;
  22688. var top = cy + dy;
  22689. var bottom = cy - dy;
  22690. if ( this.view !== null && this.view.enabled ) {
  22691. var zoomW = this.zoom / ( this.view.width / this.view.fullWidth );
  22692. var zoomH = this.zoom / ( this.view.height / this.view.fullHeight );
  22693. var scaleW = ( this.right - this.left ) / this.view.width;
  22694. var scaleH = ( this.top - this.bottom ) / this.view.height;
  22695. left += scaleW * ( this.view.offsetX / zoomW );
  22696. right = left + scaleW * ( this.view.width / zoomW );
  22697. top -= scaleH * ( this.view.offsetY / zoomH );
  22698. bottom = top - scaleH * ( this.view.height / zoomH );
  22699. }
  22700. this.projectionMatrix.makeOrthographic( left, right, top, bottom, this.near, this.far );
  22701. this.projectionMatrixInverse.getInverse( this.projectionMatrix );
  22702. },
  22703. toJSON: function ( meta ) {
  22704. var data = Object3D.prototype.toJSON.call( this, meta );
  22705. data.object.zoom = this.zoom;
  22706. data.object.left = this.left;
  22707. data.object.right = this.right;
  22708. data.object.top = this.top;
  22709. data.object.bottom = this.bottom;
  22710. data.object.near = this.near;
  22711. data.object.far = this.far;
  22712. if ( this.view !== null ) data.object.view = Object.assign( {}, this.view );
  22713. return data;
  22714. }
  22715. } );
  22716. /**
  22717. * @author mrdoob / http://mrdoob.com/
  22718. */
  22719. function DirectionalLightShadow( ) {
  22720. LightShadow.call( this, new OrthographicCamera( - 5, 5, 5, - 5, 0.5, 500 ) );
  22721. }
  22722. DirectionalLightShadow.prototype = Object.assign( Object.create( LightShadow.prototype ), {
  22723. constructor: DirectionalLightShadow
  22724. } );
  22725. /**
  22726. * @author mrdoob / http://mrdoob.com/
  22727. * @author alteredq / http://alteredqualia.com/
  22728. */
  22729. function DirectionalLight( color, intensity ) {
  22730. Light.call( this, color, intensity );
  22731. this.type = 'DirectionalLight';
  22732. this.position.copy( Object3D.DefaultUp );
  22733. this.updateMatrix();
  22734. this.target = new Object3D();
  22735. this.shadow = new DirectionalLightShadow();
  22736. }
  22737. DirectionalLight.prototype = Object.assign( Object.create( Light.prototype ), {
  22738. constructor: DirectionalLight,
  22739. isDirectionalLight: true,
  22740. copy: function ( source ) {
  22741. Light.prototype.copy.call( this, source );
  22742. this.target = source.target.clone();
  22743. this.shadow = source.shadow.clone();
  22744. return this;
  22745. }
  22746. } );
  22747. /**
  22748. * @author mrdoob / http://mrdoob.com/
  22749. */
  22750. function AmbientLight( color, intensity ) {
  22751. Light.call( this, color, intensity );
  22752. this.type = 'AmbientLight';
  22753. this.castShadow = undefined;
  22754. }
  22755. AmbientLight.prototype = Object.assign( Object.create( Light.prototype ), {
  22756. constructor: AmbientLight,
  22757. isAmbientLight: true
  22758. } );
  22759. /**
  22760. * @author abelnation / http://github.com/abelnation
  22761. */
  22762. function RectAreaLight( color, intensity, width, height ) {
  22763. Light.call( this, color, intensity );
  22764. this.type = 'RectAreaLight';
  22765. this.width = ( width !== undefined ) ? width : 10;
  22766. this.height = ( height !== undefined ) ? height : 10;
  22767. }
  22768. RectAreaLight.prototype = Object.assign( Object.create( Light.prototype ), {
  22769. constructor: RectAreaLight,
  22770. isRectAreaLight: true,
  22771. copy: function ( source ) {
  22772. Light.prototype.copy.call( this, source );
  22773. this.width = source.width;
  22774. this.height = source.height;
  22775. return this;
  22776. },
  22777. toJSON: function ( meta ) {
  22778. var data = Light.prototype.toJSON.call( this, meta );
  22779. data.object.width = this.width;
  22780. data.object.height = this.height;
  22781. return data;
  22782. }
  22783. } );
  22784. /**
  22785. * @author mrdoob / http://mrdoob.com/
  22786. */
  22787. function MaterialLoader( manager ) {
  22788. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  22789. this.textures = {};
  22790. }
  22791. Object.assign( MaterialLoader.prototype, {
  22792. load: function ( url, onLoad, onProgress, onError ) {
  22793. var scope = this;
  22794. var loader = new FileLoader( scope.manager );
  22795. loader.setPath( scope.path );
  22796. loader.load( url, function ( text ) {
  22797. onLoad( scope.parse( JSON.parse( text ) ) );
  22798. }, onProgress, onError );
  22799. },
  22800. parse: function ( json ) {
  22801. var textures = this.textures;
  22802. function getTexture( name ) {
  22803. if ( textures[ name ] === undefined ) {
  22804. console.warn( 'THREE.MaterialLoader: Undefined texture', name );
  22805. }
  22806. return textures[ name ];
  22807. }
  22808. var material = new Materials[ json.type ]();
  22809. if ( json.uuid !== undefined ) material.uuid = json.uuid;
  22810. if ( json.name !== undefined ) material.name = json.name;
  22811. if ( json.color !== undefined ) material.color.setHex( json.color );
  22812. if ( json.roughness !== undefined ) material.roughness = json.roughness;
  22813. if ( json.metalness !== undefined ) material.metalness = json.metalness;
  22814. if ( json.emissive !== undefined ) material.emissive.setHex( json.emissive );
  22815. if ( json.specular !== undefined ) material.specular.setHex( json.specular );
  22816. if ( json.shininess !== undefined ) material.shininess = json.shininess;
  22817. if ( json.clearCoat !== undefined ) material.clearCoat = json.clearCoat;
  22818. if ( json.clearCoatRoughness !== undefined ) material.clearCoatRoughness = json.clearCoatRoughness;
  22819. if ( json.vertexColors !== undefined ) material.vertexColors = json.vertexColors;
  22820. if ( json.fog !== undefined ) material.fog = json.fog;
  22821. if ( json.flatShading !== undefined ) material.flatShading = json.flatShading;
  22822. if ( json.blending !== undefined ) material.blending = json.blending;
  22823. if ( json.combine !== undefined ) material.combine = json.combine;
  22824. if ( json.side !== undefined ) material.side = json.side;
  22825. if ( json.opacity !== undefined ) material.opacity = json.opacity;
  22826. if ( json.transparent !== undefined ) material.transparent = json.transparent;
  22827. if ( json.alphaTest !== undefined ) material.alphaTest = json.alphaTest;
  22828. if ( json.depthTest !== undefined ) material.depthTest = json.depthTest;
  22829. if ( json.depthWrite !== undefined ) material.depthWrite = json.depthWrite;
  22830. if ( json.colorWrite !== undefined ) material.colorWrite = json.colorWrite;
  22831. if ( json.wireframe !== undefined ) material.wireframe = json.wireframe;
  22832. if ( json.wireframeLinewidth !== undefined ) material.wireframeLinewidth = json.wireframeLinewidth;
  22833. if ( json.wireframeLinecap !== undefined ) material.wireframeLinecap = json.wireframeLinecap;
  22834. if ( json.wireframeLinejoin !== undefined ) material.wireframeLinejoin = json.wireframeLinejoin;
  22835. if ( json.rotation !== undefined ) material.rotation = json.rotation;
  22836. if ( json.linewidth !== 1 ) material.linewidth = json.linewidth;
  22837. if ( json.dashSize !== undefined ) material.dashSize = json.dashSize;
  22838. if ( json.gapSize !== undefined ) material.gapSize = json.gapSize;
  22839. if ( json.scale !== undefined ) material.scale = json.scale;
  22840. if ( json.polygonOffset !== undefined ) material.polygonOffset = json.polygonOffset;
  22841. if ( json.polygonOffsetFactor !== undefined ) material.polygonOffsetFactor = json.polygonOffsetFactor;
  22842. if ( json.polygonOffsetUnits !== undefined ) material.polygonOffsetUnits = json.polygonOffsetUnits;
  22843. if ( json.skinning !== undefined ) material.skinning = json.skinning;
  22844. if ( json.morphTargets !== undefined ) material.morphTargets = json.morphTargets;
  22845. if ( json.morphNormals !== undefined ) material.morphNormals = json.morphNormals;
  22846. if ( json.dithering !== undefined ) material.dithering = json.dithering;
  22847. if ( json.visible !== undefined ) material.visible = json.visible;
  22848. if ( json.userData !== undefined ) material.userData = json.userData;
  22849. // Shader Material
  22850. if ( json.uniforms !== undefined ) {
  22851. for ( var name in json.uniforms ) {
  22852. var uniform = json.uniforms[ name ];
  22853. material.uniforms[ name ] = {};
  22854. switch ( uniform.type ) {
  22855. case 't':
  22856. material.uniforms[ name ].value = getTexture( uniform.value );
  22857. break;
  22858. case 'c':
  22859. material.uniforms[ name ].value = new Color().setHex( uniform.value );
  22860. break;
  22861. case 'v2':
  22862. material.uniforms[ name ].value = new Vector2().fromArray( uniform.value );
  22863. break;
  22864. case 'v3':
  22865. material.uniforms[ name ].value = new Vector3().fromArray( uniform.value );
  22866. break;
  22867. case 'v4':
  22868. material.uniforms[ name ].value = new Vector4().fromArray( uniform.value );
  22869. break;
  22870. case 'm3':
  22871. material.uniforms[ name ].value = new Matrix3().fromArray( uniform.value );
  22872. case 'm4':
  22873. material.uniforms[ name ].value = new Matrix4().fromArray( uniform.value );
  22874. break;
  22875. default:
  22876. material.uniforms[ name ].value = uniform.value;
  22877. }
  22878. }
  22879. }
  22880. if ( json.defines !== undefined ) material.defines = json.defines;
  22881. if ( json.vertexShader !== undefined ) material.vertexShader = json.vertexShader;
  22882. if ( json.fragmentShader !== undefined ) material.fragmentShader = json.fragmentShader;
  22883. if ( json.extensions !== undefined ) {
  22884. for ( var key in json.extensions ) {
  22885. material.extensions[ key ] = json.extensions[ key ];
  22886. }
  22887. }
  22888. // Deprecated
  22889. if ( json.shading !== undefined ) material.flatShading = json.shading === 1; // THREE.FlatShading
  22890. // for PointsMaterial
  22891. if ( json.size !== undefined ) material.size = json.size;
  22892. if ( json.sizeAttenuation !== undefined ) material.sizeAttenuation = json.sizeAttenuation;
  22893. // maps
  22894. if ( json.map !== undefined ) material.map = getTexture( json.map );
  22895. if ( json.matcap !== undefined ) material.matcap = getTexture( json.matcap );
  22896. if ( json.alphaMap !== undefined ) {
  22897. material.alphaMap = getTexture( json.alphaMap );
  22898. material.transparent = true;
  22899. }
  22900. if ( json.bumpMap !== undefined ) material.bumpMap = getTexture( json.bumpMap );
  22901. if ( json.bumpScale !== undefined ) material.bumpScale = json.bumpScale;
  22902. if ( json.normalMap !== undefined ) material.normalMap = getTexture( json.normalMap );
  22903. if ( json.normalMapType !== undefined ) material.normalMapType = json.normalMapType;
  22904. if ( json.normalScale !== undefined ) {
  22905. var normalScale = json.normalScale;
  22906. if ( Array.isArray( normalScale ) === false ) {
  22907. // Blender exporter used to export a scalar. See #7459
  22908. normalScale = [ normalScale, normalScale ];
  22909. }
  22910. material.normalScale = new Vector2().fromArray( normalScale );
  22911. }
  22912. if ( json.displacementMap !== undefined ) material.displacementMap = getTexture( json.displacementMap );
  22913. if ( json.displacementScale !== undefined ) material.displacementScale = json.displacementScale;
  22914. if ( json.displacementBias !== undefined ) material.displacementBias = json.displacementBias;
  22915. if ( json.roughnessMap !== undefined ) material.roughnessMap = getTexture( json.roughnessMap );
  22916. if ( json.metalnessMap !== undefined ) material.metalnessMap = getTexture( json.metalnessMap );
  22917. if ( json.emissiveMap !== undefined ) material.emissiveMap = getTexture( json.emissiveMap );
  22918. if ( json.emissiveIntensity !== undefined ) material.emissiveIntensity = json.emissiveIntensity;
  22919. if ( json.specularMap !== undefined ) material.specularMap = getTexture( json.specularMap );
  22920. if ( json.envMap !== undefined ) material.envMap = getTexture( json.envMap );
  22921. if ( json.envMapIntensity !== undefined ) material.envMapIntensity = json.envMapIntensity;
  22922. if ( json.reflectivity !== undefined ) material.reflectivity = json.reflectivity;
  22923. if ( json.refractionRatio !== undefined ) material.refractionRatio = json.refractionRatio;
  22924. if ( json.lightMap !== undefined ) material.lightMap = getTexture( json.lightMap );
  22925. if ( json.lightMapIntensity !== undefined ) material.lightMapIntensity = json.lightMapIntensity;
  22926. if ( json.aoMap !== undefined ) material.aoMap = getTexture( json.aoMap );
  22927. if ( json.aoMapIntensity !== undefined ) material.aoMapIntensity = json.aoMapIntensity;
  22928. if ( json.gradientMap !== undefined ) material.gradientMap = getTexture( json.gradientMap );
  22929. return material;
  22930. },
  22931. setPath: function ( value ) {
  22932. this.path = value;
  22933. return this;
  22934. },
  22935. setTextures: function ( value ) {
  22936. this.textures = value;
  22937. return this;
  22938. }
  22939. } );
  22940. /**
  22941. * @author Don McCurdy / https://www.donmccurdy.com
  22942. */
  22943. var LoaderUtils = {
  22944. decodeText: function ( array ) {
  22945. if ( typeof TextDecoder !== 'undefined' ) {
  22946. return new TextDecoder().decode( array );
  22947. }
  22948. // Avoid the String.fromCharCode.apply(null, array) shortcut, which
  22949. // throws a "maximum call stack size exceeded" error for large arrays.
  22950. var s = '';
  22951. for ( var i = 0, il = array.length; i < il; i ++ ) {
  22952. // Implicitly assumes little-endian.
  22953. s += String.fromCharCode( array[ i ] );
  22954. }
  22955. try {
  22956. // merges multi-byte utf-8 characters.
  22957. return decodeURIComponent( escape( s ) );
  22958. } catch ( e ) { // see #16358
  22959. return s;
  22960. }
  22961. },
  22962. extractUrlBase: function ( url ) {
  22963. var index = url.lastIndexOf( '/' );
  22964. if ( index === - 1 ) return './';
  22965. return url.substr( 0, index + 1 );
  22966. }
  22967. };
  22968. /**
  22969. * @author benaadams / https://twitter.com/ben_a_adams
  22970. */
  22971. function InstancedBufferGeometry() {
  22972. BufferGeometry.call( this );
  22973. this.type = 'InstancedBufferGeometry';
  22974. this.maxInstancedCount = undefined;
  22975. }
  22976. InstancedBufferGeometry.prototype = Object.assign( Object.create( BufferGeometry.prototype ), {
  22977. constructor: InstancedBufferGeometry,
  22978. isInstancedBufferGeometry: true,
  22979. copy: function ( source ) {
  22980. BufferGeometry.prototype.copy.call( this, source );
  22981. this.maxInstancedCount = source.maxInstancedCount;
  22982. return this;
  22983. },
  22984. clone: function () {
  22985. return new this.constructor().copy( this );
  22986. },
  22987. toJSON: function () {
  22988. var data = BufferGeometry.prototype.toJSON.call( this );
  22989. data.maxInstancedCount = this.maxInstancedCount;
  22990. data.isInstancedBufferGeometry = true;
  22991. return data;
  22992. }
  22993. } );
  22994. /**
  22995. * @author benaadams / https://twitter.com/ben_a_adams
  22996. */
  22997. function InstancedBufferAttribute( array, itemSize, normalized, meshPerAttribute ) {
  22998. if ( typeof ( normalized ) === 'number' ) {
  22999. meshPerAttribute = normalized;
  23000. normalized = false;
  23001. console.error( 'THREE.InstancedBufferAttribute: The constructor now expects normalized as the third argument.' );
  23002. }
  23003. BufferAttribute.call( this, array, itemSize, normalized );
  23004. this.meshPerAttribute = meshPerAttribute || 1;
  23005. }
  23006. InstancedBufferAttribute.prototype = Object.assign( Object.create( BufferAttribute.prototype ), {
  23007. constructor: InstancedBufferAttribute,
  23008. isInstancedBufferAttribute: true,
  23009. copy: function ( source ) {
  23010. BufferAttribute.prototype.copy.call( this, source );
  23011. this.meshPerAttribute = source.meshPerAttribute;
  23012. return this;
  23013. },
  23014. toJSON: function () {
  23015. var data = BufferAttribute.prototype.toJSON.call( this );
  23016. data.meshPerAttribute = this.meshPerAttribute;
  23017. data.isInstancedBufferAttribute = true;
  23018. return data;
  23019. }
  23020. } );
  23021. /**
  23022. * @author mrdoob / http://mrdoob.com/
  23023. */
  23024. function BufferGeometryLoader( manager ) {
  23025. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  23026. }
  23027. Object.assign( BufferGeometryLoader.prototype, {
  23028. load: function ( url, onLoad, onProgress, onError ) {
  23029. var scope = this;
  23030. var loader = new FileLoader( scope.manager );
  23031. loader.setPath( scope.path );
  23032. loader.load( url, function ( text ) {
  23033. onLoad( scope.parse( JSON.parse( text ) ) );
  23034. }, onProgress, onError );
  23035. },
  23036. parse: function ( json ) {
  23037. var geometry = json.isInstancedBufferGeometry ? new InstancedBufferGeometry() : new BufferGeometry();
  23038. var index = json.data.index;
  23039. if ( index !== undefined ) {
  23040. var typedArray = new TYPED_ARRAYS[ index.type ]( index.array );
  23041. geometry.setIndex( new BufferAttribute( typedArray, 1 ) );
  23042. }
  23043. var attributes = json.data.attributes;
  23044. for ( var key in attributes ) {
  23045. var attribute = attributes[ key ];
  23046. var typedArray = new TYPED_ARRAYS[ attribute.type ]( attribute.array );
  23047. var bufferAttributeConstr = attribute.isInstancedBufferAttribute ? InstancedBufferAttribute : BufferAttribute;
  23048. var bufferAttribute = new bufferAttributeConstr( typedArray, attribute.itemSize, attribute.normalized );
  23049. if ( attribute.name !== undefined ) bufferAttribute.name = attribute.name;
  23050. geometry.addAttribute( key, bufferAttribute );
  23051. }
  23052. var morphAttributes = json.data.morphAttributes;
  23053. if ( morphAttributes ) {
  23054. for ( var key in morphAttributes ) {
  23055. var attributeArray = morphAttributes[ key ];
  23056. var array = [];
  23057. for ( var i = 0, il = attributeArray.length; i < il; i ++ ) {
  23058. var attribute = attributeArray[ i ];
  23059. var typedArray = new TYPED_ARRAYS[ attribute.type ]( attribute.array );
  23060. var bufferAttribute = new BufferAttribute( typedArray, attribute.itemSize, attribute.normalized );
  23061. if ( attribute.name !== undefined ) bufferAttribute.name = attribute.name;
  23062. array.push( bufferAttribute );
  23063. }
  23064. geometry.morphAttributes[ key ] = array;
  23065. }
  23066. }
  23067. var groups = json.data.groups || json.data.drawcalls || json.data.offsets;
  23068. if ( groups !== undefined ) {
  23069. for ( var i = 0, n = groups.length; i !== n; ++ i ) {
  23070. var group = groups[ i ];
  23071. geometry.addGroup( group.start, group.count, group.materialIndex );
  23072. }
  23073. }
  23074. var boundingSphere = json.data.boundingSphere;
  23075. if ( boundingSphere !== undefined ) {
  23076. var center = new Vector3();
  23077. if ( boundingSphere.center !== undefined ) {
  23078. center.fromArray( boundingSphere.center );
  23079. }
  23080. geometry.boundingSphere = new Sphere( center, boundingSphere.radius );
  23081. }
  23082. if ( json.name ) geometry.name = json.name;
  23083. if ( json.userData ) geometry.userData = json.userData;
  23084. return geometry;
  23085. },
  23086. setPath: function ( value ) {
  23087. this.path = value;
  23088. return this;
  23089. }
  23090. } );
  23091. var TYPED_ARRAYS = {
  23092. Int8Array: Int8Array,
  23093. Uint8Array: Uint8Array,
  23094. // Workaround for IE11 pre KB2929437. See #11440
  23095. Uint8ClampedArray: typeof Uint8ClampedArray !== 'undefined' ? Uint8ClampedArray : Uint8Array,
  23096. Int16Array: Int16Array,
  23097. Uint16Array: Uint16Array,
  23098. Int32Array: Int32Array,
  23099. Uint32Array: Uint32Array,
  23100. Float32Array: Float32Array,
  23101. Float64Array: Float64Array
  23102. };
  23103. /**
  23104. * @author mrdoob / http://mrdoob.com/
  23105. */
  23106. function ObjectLoader( manager ) {
  23107. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  23108. this.resourcePath = '';
  23109. }
  23110. Object.assign( ObjectLoader.prototype, {
  23111. crossOrigin: 'anonymous',
  23112. load: function ( url, onLoad, onProgress, onError ) {
  23113. var scope = this;
  23114. var path = ( this.path === undefined ) ? LoaderUtils.extractUrlBase( url ) : this.path;
  23115. this.resourcePath = this.resourcePath || path;
  23116. var loader = new FileLoader( scope.manager );
  23117. loader.setPath( this.path );
  23118. loader.load( url, function ( text ) {
  23119. var json = null;
  23120. try {
  23121. json = JSON.parse( text );
  23122. } catch ( error ) {
  23123. if ( onError !== undefined ) onError( error );
  23124. console.error( 'THREE:ObjectLoader: Can\'t parse ' + url + '.', error.message );
  23125. return;
  23126. }
  23127. var metadata = json.metadata;
  23128. if ( metadata === undefined || metadata.type === undefined || metadata.type.toLowerCase() === 'geometry' ) {
  23129. console.error( 'THREE.ObjectLoader: Can\'t load ' + url );
  23130. return;
  23131. }
  23132. scope.parse( json, onLoad );
  23133. }, onProgress, onError );
  23134. },
  23135. setPath: function ( value ) {
  23136. this.path = value;
  23137. return this;
  23138. },
  23139. setResourcePath: function ( value ) {
  23140. this.resourcePath = value;
  23141. return this;
  23142. },
  23143. setCrossOrigin: function ( value ) {
  23144. this.crossOrigin = value;
  23145. return this;
  23146. },
  23147. parse: function ( json, onLoad ) {
  23148. var shapes = this.parseShape( json.shapes );
  23149. var geometries = this.parseGeometries( json.geometries, shapes );
  23150. var images = this.parseImages( json.images, function () {
  23151. if ( onLoad !== undefined ) onLoad( object );
  23152. } );
  23153. var textures = this.parseTextures( json.textures, images );
  23154. var materials = this.parseMaterials( json.materials, textures );
  23155. var object = this.parseObject( json.object, geometries, materials );
  23156. if ( json.animations ) {
  23157. object.animations = this.parseAnimations( json.animations );
  23158. }
  23159. if ( json.images === undefined || json.images.length === 0 ) {
  23160. if ( onLoad !== undefined ) onLoad( object );
  23161. }
  23162. return object;
  23163. },
  23164. parseShape: function ( json ) {
  23165. var shapes = {};
  23166. if ( json !== undefined ) {
  23167. for ( var i = 0, l = json.length; i < l; i ++ ) {
  23168. var shape = new Shape().fromJSON( json[ i ] );
  23169. shapes[ shape.uuid ] = shape;
  23170. }
  23171. }
  23172. return shapes;
  23173. },
  23174. parseGeometries: function ( json, shapes ) {
  23175. var geometries = {};
  23176. if ( json !== undefined ) {
  23177. var bufferGeometryLoader = new BufferGeometryLoader();
  23178. for ( var i = 0, l = json.length; i < l; i ++ ) {
  23179. var geometry;
  23180. var data = json[ i ];
  23181. switch ( data.type ) {
  23182. case 'PlaneGeometry':
  23183. case 'PlaneBufferGeometry':
  23184. geometry = new Geometries[ data.type ](
  23185. data.width,
  23186. data.height,
  23187. data.widthSegments,
  23188. data.heightSegments
  23189. );
  23190. break;
  23191. case 'BoxGeometry':
  23192. case 'BoxBufferGeometry':
  23193. case 'CubeGeometry': // backwards compatible
  23194. geometry = new Geometries[ data.type ](
  23195. data.width,
  23196. data.height,
  23197. data.depth,
  23198. data.widthSegments,
  23199. data.heightSegments,
  23200. data.depthSegments
  23201. );
  23202. break;
  23203. case 'CircleGeometry':
  23204. case 'CircleBufferGeometry':
  23205. geometry = new Geometries[ data.type ](
  23206. data.radius,
  23207. data.segments,
  23208. data.thetaStart,
  23209. data.thetaLength
  23210. );
  23211. break;
  23212. case 'CylinderGeometry':
  23213. case 'CylinderBufferGeometry':
  23214. geometry = new Geometries[ data.type ](
  23215. data.radiusTop,
  23216. data.radiusBottom,
  23217. data.height,
  23218. data.radialSegments,
  23219. data.heightSegments,
  23220. data.openEnded,
  23221. data.thetaStart,
  23222. data.thetaLength
  23223. );
  23224. break;
  23225. case 'ConeGeometry':
  23226. case 'ConeBufferGeometry':
  23227. geometry = new Geometries[ data.type ](
  23228. data.radius,
  23229. data.height,
  23230. data.radialSegments,
  23231. data.heightSegments,
  23232. data.openEnded,
  23233. data.thetaStart,
  23234. data.thetaLength
  23235. );
  23236. break;
  23237. case 'SphereGeometry':
  23238. case 'SphereBufferGeometry':
  23239. geometry = new Geometries[ data.type ](
  23240. data.radius,
  23241. data.widthSegments,
  23242. data.heightSegments,
  23243. data.phiStart,
  23244. data.phiLength,
  23245. data.thetaStart,
  23246. data.thetaLength
  23247. );
  23248. break;
  23249. case 'DodecahedronGeometry':
  23250. case 'DodecahedronBufferGeometry':
  23251. case 'IcosahedronGeometry':
  23252. case 'IcosahedronBufferGeometry':
  23253. case 'OctahedronGeometry':
  23254. case 'OctahedronBufferGeometry':
  23255. case 'TetrahedronGeometry':
  23256. case 'TetrahedronBufferGeometry':
  23257. geometry = new Geometries[ data.type ](
  23258. data.radius,
  23259. data.detail
  23260. );
  23261. break;
  23262. case 'RingGeometry':
  23263. case 'RingBufferGeometry':
  23264. geometry = new Geometries[ data.type ](
  23265. data.innerRadius,
  23266. data.outerRadius,
  23267. data.thetaSegments,
  23268. data.phiSegments,
  23269. data.thetaStart,
  23270. data.thetaLength
  23271. );
  23272. break;
  23273. case 'TorusGeometry':
  23274. case 'TorusBufferGeometry':
  23275. geometry = new Geometries[ data.type ](
  23276. data.radius,
  23277. data.tube,
  23278. data.radialSegments,
  23279. data.tubularSegments,
  23280. data.arc
  23281. );
  23282. break;
  23283. case 'TorusKnotGeometry':
  23284. case 'TorusKnotBufferGeometry':
  23285. geometry = new Geometries[ data.type ](
  23286. data.radius,
  23287. data.tube,
  23288. data.tubularSegments,
  23289. data.radialSegments,
  23290. data.p,
  23291. data.q
  23292. );
  23293. break;
  23294. case 'TubeGeometry':
  23295. case 'TubeBufferGeometry':
  23296. // This only works for built-in curves (e.g. CatmullRomCurve3).
  23297. // User defined curves or instances of CurvePath will not be deserialized.
  23298. geometry = new Geometries[ data.type ](
  23299. new Curves[ data.path.type ]().fromJSON( data.path ),
  23300. data.tubularSegments,
  23301. data.radius,
  23302. data.radialSegments,
  23303. data.closed
  23304. );
  23305. break;
  23306. case 'LatheGeometry':
  23307. case 'LatheBufferGeometry':
  23308. geometry = new Geometries[ data.type ](
  23309. data.points,
  23310. data.segments,
  23311. data.phiStart,
  23312. data.phiLength
  23313. );
  23314. break;
  23315. case 'PolyhedronGeometry':
  23316. case 'PolyhedronBufferGeometry':
  23317. geometry = new Geometries[ data.type ](
  23318. data.vertices,
  23319. data.indices,
  23320. data.radius,
  23321. data.details
  23322. );
  23323. break;
  23324. case 'ShapeGeometry':
  23325. case 'ShapeBufferGeometry':
  23326. var geometryShapes = [];
  23327. for ( var j = 0, jl = data.shapes.length; j < jl; j ++ ) {
  23328. var shape = shapes[ data.shapes[ j ] ];
  23329. geometryShapes.push( shape );
  23330. }
  23331. geometry = new Geometries[ data.type ](
  23332. geometryShapes,
  23333. data.curveSegments
  23334. );
  23335. break;
  23336. case 'ExtrudeGeometry':
  23337. case 'ExtrudeBufferGeometry':
  23338. var geometryShapes = [];
  23339. for ( var j = 0, jl = data.shapes.length; j < jl; j ++ ) {
  23340. var shape = shapes[ data.shapes[ j ] ];
  23341. geometryShapes.push( shape );
  23342. }
  23343. var extrudePath = data.options.extrudePath;
  23344. if ( extrudePath !== undefined ) {
  23345. data.options.extrudePath = new Curves[ extrudePath.type ]().fromJSON( extrudePath );
  23346. }
  23347. geometry = new Geometries[ data.type ](
  23348. geometryShapes,
  23349. data.options
  23350. );
  23351. break;
  23352. case 'BufferGeometry':
  23353. case 'InstancedBufferGeometry':
  23354. geometry = bufferGeometryLoader.parse( data );
  23355. break;
  23356. case 'Geometry':
  23357. if ( 'THREE' in window && 'LegacyJSONLoader' in THREE ) {
  23358. var geometryLoader = new THREE.LegacyJSONLoader();
  23359. geometry = geometryLoader.parse( data, this.resourcePath ).geometry;
  23360. } else {
  23361. console.error( 'THREE.ObjectLoader: You have to import LegacyJSONLoader in order load geometry data of type "Geometry".' );
  23362. }
  23363. break;
  23364. default:
  23365. console.warn( 'THREE.ObjectLoader: Unsupported geometry type "' + data.type + '"' );
  23366. continue;
  23367. }
  23368. geometry.uuid = data.uuid;
  23369. if ( data.name !== undefined ) geometry.name = data.name;
  23370. if ( geometry.isBufferGeometry === true && data.userData !== undefined ) geometry.userData = data.userData;
  23371. geometries[ data.uuid ] = geometry;
  23372. }
  23373. }
  23374. return geometries;
  23375. },
  23376. parseMaterials: function ( json, textures ) {
  23377. var cache = {}; // MultiMaterial
  23378. var materials = {};
  23379. if ( json !== undefined ) {
  23380. var loader = new MaterialLoader();
  23381. loader.setTextures( textures );
  23382. for ( var i = 0, l = json.length; i < l; i ++ ) {
  23383. var data = json[ i ];
  23384. if ( data.type === 'MultiMaterial' ) {
  23385. // Deprecated
  23386. var array = [];
  23387. for ( var j = 0; j < data.materials.length; j ++ ) {
  23388. var material = data.materials[ j ];
  23389. if ( cache[ material.uuid ] === undefined ) {
  23390. cache[ material.uuid ] = loader.parse( material );
  23391. }
  23392. array.push( cache[ material.uuid ] );
  23393. }
  23394. materials[ data.uuid ] = array;
  23395. } else {
  23396. if ( cache[ data.uuid ] === undefined ) {
  23397. cache[ data.uuid ] = loader.parse( data );
  23398. }
  23399. materials[ data.uuid ] = cache[ data.uuid ];
  23400. }
  23401. }
  23402. }
  23403. return materials;
  23404. },
  23405. parseAnimations: function ( json ) {
  23406. var animations = [];
  23407. for ( var i = 0; i < json.length; i ++ ) {
  23408. var data = json[ i ];
  23409. var clip = AnimationClip.parse( data );
  23410. if ( data.uuid !== undefined ) clip.uuid = data.uuid;
  23411. animations.push( clip );
  23412. }
  23413. return animations;
  23414. },
  23415. parseImages: function ( json, onLoad ) {
  23416. var scope = this;
  23417. var images = {};
  23418. function loadImage( url ) {
  23419. scope.manager.itemStart( url );
  23420. return loader.load( url, function () {
  23421. scope.manager.itemEnd( url );
  23422. }, undefined, function () {
  23423. scope.manager.itemError( url );
  23424. scope.manager.itemEnd( url );
  23425. } );
  23426. }
  23427. if ( json !== undefined && json.length > 0 ) {
  23428. var manager = new LoadingManager( onLoad );
  23429. var loader = new ImageLoader( manager );
  23430. loader.setCrossOrigin( this.crossOrigin );
  23431. for ( var i = 0, il = json.length; i < il; i ++ ) {
  23432. var image = json[ i ];
  23433. var url = image.url;
  23434. if ( Array.isArray( url ) ) {
  23435. // load array of images e.g CubeTexture
  23436. images[ image.uuid ] = [];
  23437. for ( var j = 0, jl = url.length; j < jl; j ++ ) {
  23438. var currentUrl = url[ j ];
  23439. var path = /^(\/\/)|([a-z]+:(\/\/)?)/i.test( currentUrl ) ? currentUrl : scope.resourcePath + currentUrl;
  23440. images[ image.uuid ].push( loadImage( path ) );
  23441. }
  23442. } else {
  23443. // load single image
  23444. var path = /^(\/\/)|([a-z]+:(\/\/)?)/i.test( image.url ) ? image.url : scope.resourcePath + image.url;
  23445. images[ image.uuid ] = loadImage( path );
  23446. }
  23447. }
  23448. }
  23449. return images;
  23450. },
  23451. parseTextures: function ( json, images ) {
  23452. function parseConstant( value, type ) {
  23453. if ( typeof value === 'number' ) return value;
  23454. console.warn( 'THREE.ObjectLoader.parseTexture: Constant should be in numeric form.', value );
  23455. return type[ value ];
  23456. }
  23457. var textures = {};
  23458. if ( json !== undefined ) {
  23459. for ( var i = 0, l = json.length; i < l; i ++ ) {
  23460. var data = json[ i ];
  23461. if ( data.image === undefined ) {
  23462. console.warn( 'THREE.ObjectLoader: No "image" specified for', data.uuid );
  23463. }
  23464. if ( images[ data.image ] === undefined ) {
  23465. console.warn( 'THREE.ObjectLoader: Undefined image', data.image );
  23466. }
  23467. var texture;
  23468. if ( Array.isArray( images[ data.image ] ) ) {
  23469. texture = new CubeTexture( images[ data.image ] );
  23470. } else {
  23471. texture = new Texture( images[ data.image ] );
  23472. }
  23473. texture.needsUpdate = true;
  23474. texture.uuid = data.uuid;
  23475. if ( data.name !== undefined ) texture.name = data.name;
  23476. if ( data.mapping !== undefined ) texture.mapping = parseConstant( data.mapping, TEXTURE_MAPPING );
  23477. if ( data.offset !== undefined ) texture.offset.fromArray( data.offset );
  23478. if ( data.repeat !== undefined ) texture.repeat.fromArray( data.repeat );
  23479. if ( data.center !== undefined ) texture.center.fromArray( data.center );
  23480. if ( data.rotation !== undefined ) texture.rotation = data.rotation;
  23481. if ( data.wrap !== undefined ) {
  23482. texture.wrapS = parseConstant( data.wrap[ 0 ], TEXTURE_WRAPPING );
  23483. texture.wrapT = parseConstant( data.wrap[ 1 ], TEXTURE_WRAPPING );
  23484. }
  23485. if ( data.format !== undefined ) texture.format = data.format;
  23486. if ( data.type !== undefined ) texture.type = data.type;
  23487. if ( data.encoding !== undefined ) texture.encoding = data.encoding;
  23488. if ( data.minFilter !== undefined ) texture.minFilter = parseConstant( data.minFilter, TEXTURE_FILTER );
  23489. if ( data.magFilter !== undefined ) texture.magFilter = parseConstant( data.magFilter, TEXTURE_FILTER );
  23490. if ( data.anisotropy !== undefined ) texture.anisotropy = data.anisotropy;
  23491. if ( data.flipY !== undefined ) texture.flipY = data.flipY;
  23492. if ( data.premultiplyAlpha !== undefined ) texture.premultiplyAlpha = data.premultiplyAlpha;
  23493. if ( data.unpackAlignment !== undefined ) texture.unpackAlignment = data.unpackAlignment;
  23494. textures[ data.uuid ] = texture;
  23495. }
  23496. }
  23497. return textures;
  23498. },
  23499. parseObject: function ( data, geometries, materials ) {
  23500. var object;
  23501. function getGeometry( name ) {
  23502. if ( geometries[ name ] === undefined ) {
  23503. console.warn( 'THREE.ObjectLoader: Undefined geometry', name );
  23504. }
  23505. return geometries[ name ];
  23506. }
  23507. function getMaterial( name ) {
  23508. if ( name === undefined ) return undefined;
  23509. if ( Array.isArray( name ) ) {
  23510. var array = [];
  23511. for ( var i = 0, l = name.length; i < l; i ++ ) {
  23512. var uuid = name[ i ];
  23513. if ( materials[ uuid ] === undefined ) {
  23514. console.warn( 'THREE.ObjectLoader: Undefined material', uuid );
  23515. }
  23516. array.push( materials[ uuid ] );
  23517. }
  23518. return array;
  23519. }
  23520. if ( materials[ name ] === undefined ) {
  23521. console.warn( 'THREE.ObjectLoader: Undefined material', name );
  23522. }
  23523. return materials[ name ];
  23524. }
  23525. switch ( data.type ) {
  23526. case 'Scene':
  23527. object = new Scene();
  23528. if ( data.background !== undefined ) {
  23529. if ( Number.isInteger( data.background ) ) {
  23530. object.background = new Color( data.background );
  23531. }
  23532. }
  23533. if ( data.fog !== undefined ) {
  23534. if ( data.fog.type === 'Fog' ) {
  23535. object.fog = new Fog( data.fog.color, data.fog.near, data.fog.far );
  23536. } else if ( data.fog.type === 'FogExp2' ) {
  23537. object.fog = new FogExp2( data.fog.color, data.fog.density );
  23538. }
  23539. }
  23540. break;
  23541. case 'PerspectiveCamera':
  23542. object = new PerspectiveCamera( data.fov, data.aspect, data.near, data.far );
  23543. if ( data.focus !== undefined ) object.focus = data.focus;
  23544. if ( data.zoom !== undefined ) object.zoom = data.zoom;
  23545. if ( data.filmGauge !== undefined ) object.filmGauge = data.filmGauge;
  23546. if ( data.filmOffset !== undefined ) object.filmOffset = data.filmOffset;
  23547. if ( data.view !== undefined ) object.view = Object.assign( {}, data.view );
  23548. break;
  23549. case 'OrthographicCamera':
  23550. object = new OrthographicCamera( data.left, data.right, data.top, data.bottom, data.near, data.far );
  23551. if ( data.zoom !== undefined ) object.zoom = data.zoom;
  23552. if ( data.view !== undefined ) object.view = Object.assign( {}, data.view );
  23553. break;
  23554. case 'AmbientLight':
  23555. object = new AmbientLight( data.color, data.intensity );
  23556. break;
  23557. case 'DirectionalLight':
  23558. object = new DirectionalLight( data.color, data.intensity );
  23559. break;
  23560. case 'PointLight':
  23561. object = new PointLight( data.color, data.intensity, data.distance, data.decay );
  23562. break;
  23563. case 'RectAreaLight':
  23564. object = new RectAreaLight( data.color, data.intensity, data.width, data.height );
  23565. break;
  23566. case 'SpotLight':
  23567. object = new SpotLight( data.color, data.intensity, data.distance, data.angle, data.penumbra, data.decay );
  23568. break;
  23569. case 'HemisphereLight':
  23570. object = new HemisphereLight( data.color, data.groundColor, data.intensity );
  23571. break;
  23572. case 'SkinnedMesh':
  23573. console.warn( 'THREE.ObjectLoader.parseObject() does not support SkinnedMesh yet.' );
  23574. case 'Mesh':
  23575. var geometry = getGeometry( data.geometry );
  23576. var material = getMaterial( data.material );
  23577. if ( geometry.bones && geometry.bones.length > 0 ) {
  23578. object = new SkinnedMesh( geometry, material );
  23579. } else {
  23580. object = new Mesh( geometry, material );
  23581. }
  23582. if ( data.drawMode !== undefined ) object.setDrawMode( data.drawMode );
  23583. break;
  23584. case 'LOD':
  23585. object = new LOD();
  23586. break;
  23587. case 'Line':
  23588. object = new Line( getGeometry( data.geometry ), getMaterial( data.material ), data.mode );
  23589. break;
  23590. case 'LineLoop':
  23591. object = new LineLoop( getGeometry( data.geometry ), getMaterial( data.material ) );
  23592. break;
  23593. case 'LineSegments':
  23594. object = new LineSegments( getGeometry( data.geometry ), getMaterial( data.material ) );
  23595. break;
  23596. case 'PointCloud':
  23597. case 'Points':
  23598. object = new Points( getGeometry( data.geometry ), getMaterial( data.material ) );
  23599. break;
  23600. case 'Sprite':
  23601. object = new Sprite( getMaterial( data.material ) );
  23602. break;
  23603. case 'Group':
  23604. object = new Group();
  23605. break;
  23606. default:
  23607. object = new Object3D();
  23608. }
  23609. object.uuid = data.uuid;
  23610. if ( data.name !== undefined ) object.name = data.name;
  23611. if ( data.matrix !== undefined ) {
  23612. object.matrix.fromArray( data.matrix );
  23613. if ( data.matrixAutoUpdate !== undefined ) object.matrixAutoUpdate = data.matrixAutoUpdate;
  23614. if ( object.matrixAutoUpdate ) object.matrix.decompose( object.position, object.quaternion, object.scale );
  23615. } else {
  23616. if ( data.position !== undefined ) object.position.fromArray( data.position );
  23617. if ( data.rotation !== undefined ) object.rotation.fromArray( data.rotation );
  23618. if ( data.quaternion !== undefined ) object.quaternion.fromArray( data.quaternion );
  23619. if ( data.scale !== undefined ) object.scale.fromArray( data.scale );
  23620. }
  23621. if ( data.castShadow !== undefined ) object.castShadow = data.castShadow;
  23622. if ( data.receiveShadow !== undefined ) object.receiveShadow = data.receiveShadow;
  23623. if ( data.shadow ) {
  23624. if ( data.shadow.bias !== undefined ) object.shadow.bias = data.shadow.bias;
  23625. if ( data.shadow.radius !== undefined ) object.shadow.radius = data.shadow.radius;
  23626. if ( data.shadow.mapSize !== undefined ) object.shadow.mapSize.fromArray( data.shadow.mapSize );
  23627. if ( data.shadow.camera !== undefined ) object.shadow.camera = this.parseObject( data.shadow.camera );
  23628. }
  23629. if ( data.visible !== undefined ) object.visible = data.visible;
  23630. if ( data.frustumCulled !== undefined ) object.frustumCulled = data.frustumCulled;
  23631. if ( data.renderOrder !== undefined ) object.renderOrder = data.renderOrder;
  23632. if ( data.userData !== undefined ) object.userData = data.userData;
  23633. if ( data.layers !== undefined ) object.layers.mask = data.layers;
  23634. if ( data.children !== undefined ) {
  23635. var children = data.children;
  23636. for ( var i = 0; i < children.length; i ++ ) {
  23637. object.add( this.parseObject( children[ i ], geometries, materials ) );
  23638. }
  23639. }
  23640. if ( data.type === 'LOD' ) {
  23641. var levels = data.levels;
  23642. for ( var l = 0; l < levels.length; l ++ ) {
  23643. var level = levels[ l ];
  23644. var child = object.getObjectByProperty( 'uuid', level.object );
  23645. if ( child !== undefined ) {
  23646. object.addLevel( child, level.distance );
  23647. }
  23648. }
  23649. }
  23650. return object;
  23651. }
  23652. } );
  23653. var TEXTURE_MAPPING = {
  23654. UVMapping: UVMapping,
  23655. CubeReflectionMapping: CubeReflectionMapping,
  23656. CubeRefractionMapping: CubeRefractionMapping,
  23657. EquirectangularReflectionMapping: EquirectangularReflectionMapping,
  23658. EquirectangularRefractionMapping: EquirectangularRefractionMapping,
  23659. SphericalReflectionMapping: SphericalReflectionMapping,
  23660. CubeUVReflectionMapping: CubeUVReflectionMapping,
  23661. CubeUVRefractionMapping: CubeUVRefractionMapping
  23662. };
  23663. var TEXTURE_WRAPPING = {
  23664. RepeatWrapping: RepeatWrapping,
  23665. ClampToEdgeWrapping: ClampToEdgeWrapping,
  23666. MirroredRepeatWrapping: MirroredRepeatWrapping
  23667. };
  23668. var TEXTURE_FILTER = {
  23669. NearestFilter: NearestFilter,
  23670. NearestMipmapNearestFilter: NearestMipmapNearestFilter,
  23671. NearestMipmapLinearFilter: NearestMipmapLinearFilter,
  23672. LinearFilter: LinearFilter,
  23673. LinearMipmapNearestFilter: LinearMipmapNearestFilter,
  23674. LinearMipmapLinearFilter: LinearMipmapLinearFilter
  23675. };
  23676. /**
  23677. * @author thespite / http://clicktorelease.com/
  23678. */
  23679. function ImageBitmapLoader( manager ) {
  23680. if ( typeof createImageBitmap === 'undefined' ) {
  23681. console.warn( 'THREE.ImageBitmapLoader: createImageBitmap() not supported.' );
  23682. }
  23683. if ( typeof fetch === 'undefined' ) {
  23684. console.warn( 'THREE.ImageBitmapLoader: fetch() not supported.' );
  23685. }
  23686. this.manager = manager !== undefined ? manager : DefaultLoadingManager;
  23687. this.options = undefined;
  23688. }
  23689. ImageBitmapLoader.prototype = {
  23690. constructor: ImageBitmapLoader,
  23691. setOptions: function setOptions( options ) {
  23692. this.options = options;
  23693. return this;
  23694. },
  23695. load: function ( url, onLoad, onProgress, onError ) {
  23696. if ( url === undefined ) url = '';
  23697. if ( this.path !== undefined ) url = this.path + url;
  23698. url = this.manager.resolveURL( url );
  23699. var scope = this;
  23700. var cached = Cache.get( url );
  23701. if ( cached !== undefined ) {
  23702. scope.manager.itemStart( url );
  23703. setTimeout( function () {
  23704. if ( onLoad ) onLoad( cached );
  23705. scope.manager.itemEnd( url );
  23706. }, 0 );
  23707. return cached;
  23708. }
  23709. fetch( url ).then( function ( res ) {
  23710. return res.blob();
  23711. } ).then( function ( blob ) {
  23712. if ( scope.options === undefined ) {
  23713. // Workaround for FireFox. It causes an error if you pass options.
  23714. return createImageBitmap( blob );
  23715. } else {
  23716. return createImageBitmap( blob, scope.options );
  23717. }
  23718. } ).then( function ( imageBitmap ) {
  23719. Cache.add( url, imageBitmap );
  23720. if ( onLoad ) onLoad( imageBitmap );
  23721. scope.manager.itemEnd( url );
  23722. } ).catch( function ( e ) {
  23723. if ( onError ) onError( e );
  23724. scope.manager.itemError( url );
  23725. scope.manager.itemEnd( url );
  23726. } );
  23727. scope.manager.itemStart( url );
  23728. },
  23729. setCrossOrigin: function ( /* value */ ) {
  23730. return this;
  23731. },
  23732. setPath: function ( value ) {
  23733. this.path = value;
  23734. return this;
  23735. }
  23736. };
  23737. /**
  23738. * @author zz85 / http://www.lab4games.net/zz85/blog
  23739. * minimal class for proxing functions to Path. Replaces old "extractSubpaths()"
  23740. **/
  23741. function ShapePath() {
  23742. this.type = 'ShapePath';
  23743. this.color = new Color();
  23744. this.subPaths = [];
  23745. this.currentPath = null;
  23746. }
  23747. Object.assign( ShapePath.prototype, {
  23748. moveTo: function ( x, y ) {
  23749. this.currentPath = new Path();
  23750. this.subPaths.push( this.currentPath );
  23751. this.currentPath.moveTo( x, y );
  23752. },
  23753. lineTo: function ( x, y ) {
  23754. this.currentPath.lineTo( x, y );
  23755. },
  23756. quadraticCurveTo: function ( aCPx, aCPy, aX, aY ) {
  23757. this.currentPath.quadraticCurveTo( aCPx, aCPy, aX, aY );
  23758. },
  23759. bezierCurveTo: function ( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY ) {
  23760. this.currentPath.bezierCurveTo( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY );
  23761. },
  23762. splineThru: function ( pts ) {
  23763. this.currentPath.splineThru( pts );
  23764. },
  23765. toShapes: function ( isCCW, noHoles ) {
  23766. function toShapesNoHoles( inSubpaths ) {
  23767. var shapes = [];
  23768. for ( var i = 0, l = inSubpaths.length; i < l; i ++ ) {
  23769. var tmpPath = inSubpaths[ i ];
  23770. var tmpShape = new Shape();
  23771. tmpShape.curves = tmpPath.curves;
  23772. shapes.push( tmpShape );
  23773. }
  23774. return shapes;
  23775. }
  23776. function isPointInsidePolygon( inPt, inPolygon ) {
  23777. var polyLen = inPolygon.length;
  23778. // inPt on polygon contour => immediate success or
  23779. // toggling of inside/outside at every single! intersection point of an edge
  23780. // with the horizontal line through inPt, left of inPt
  23781. // not counting lowerY endpoints of edges and whole edges on that line
  23782. var inside = false;
  23783. for ( var p = polyLen - 1, q = 0; q < polyLen; p = q ++ ) {
  23784. var edgeLowPt = inPolygon[ p ];
  23785. var edgeHighPt = inPolygon[ q ];
  23786. var edgeDx = edgeHighPt.x - edgeLowPt.x;
  23787. var edgeDy = edgeHighPt.y - edgeLowPt.y;
  23788. if ( Math.abs( edgeDy ) > Number.EPSILON ) {
  23789. // not parallel
  23790. if ( edgeDy < 0 ) {
  23791. edgeLowPt = inPolygon[ q ]; edgeDx = - edgeDx;
  23792. edgeHighPt = inPolygon[ p ]; edgeDy = - edgeDy;
  23793. }
  23794. if ( ( inPt.y < edgeLowPt.y ) || ( inPt.y > edgeHighPt.y ) ) continue;
  23795. if ( inPt.y === edgeLowPt.y ) {
  23796. if ( inPt.x === edgeLowPt.x ) return true; // inPt is on contour ?
  23797. // continue; // no intersection or edgeLowPt => doesn't count !!!
  23798. } else {
  23799. var perpEdge = edgeDy * ( inPt.x - edgeLowPt.x ) - edgeDx * ( inPt.y - edgeLowPt.y );
  23800. if ( perpEdge === 0 ) return true; // inPt is on contour ?
  23801. if ( perpEdge < 0 ) continue;
  23802. inside = ! inside; // true intersection left of inPt
  23803. }
  23804. } else {
  23805. // parallel or collinear
  23806. if ( inPt.y !== edgeLowPt.y ) continue; // parallel
  23807. // edge lies on the same horizontal line as inPt
  23808. if ( ( ( edgeHighPt.x <= inPt.x ) && ( inPt.x <= edgeLowPt.x ) ) ||
  23809. ( ( edgeLowPt.x <= inPt.x ) && ( inPt.x <= edgeHighPt.x ) ) ) return true; // inPt: Point on contour !
  23810. // continue;
  23811. }
  23812. }
  23813. return inside;
  23814. }
  23815. var isClockWise = ShapeUtils.isClockWise;
  23816. var subPaths = this.subPaths;
  23817. if ( subPaths.length === 0 ) return [];
  23818. if ( noHoles === true ) return toShapesNoHoles( subPaths );
  23819. var solid, tmpPath, tmpShape, shapes = [];
  23820. if ( subPaths.length === 1 ) {
  23821. tmpPath = subPaths[ 0 ];
  23822. tmpShape = new Shape();
  23823. tmpShape.curves = tmpPath.curves;
  23824. shapes.push( tmpShape );
  23825. return shapes;
  23826. }
  23827. var holesFirst = ! isClockWise( subPaths[ 0 ].getPoints() );
  23828. holesFirst = isCCW ? ! holesFirst : holesFirst;
  23829. // console.log("Holes first", holesFirst);
  23830. var betterShapeHoles = [];
  23831. var newShapes = [];
  23832. var newShapeHoles = [];
  23833. var mainIdx = 0;
  23834. var tmpPoints;
  23835. newShapes[ mainIdx ] = undefined;
  23836. newShapeHoles[ mainIdx ] = [];
  23837. for ( var i = 0, l = subPaths.length; i < l; i ++ ) {
  23838. tmpPath = subPaths[ i ];
  23839. tmpPoints = tmpPath.getPoints();
  23840. solid = isClockWise( tmpPoints );
  23841. solid = isCCW ? ! solid : solid;
  23842. if ( solid ) {
  23843. if ( ( ! holesFirst ) && ( newShapes[ mainIdx ] ) ) mainIdx ++;
  23844. newShapes[ mainIdx ] = { s: new Shape(), p: tmpPoints };
  23845. newShapes[ mainIdx ].s.curves = tmpPath.curves;
  23846. if ( holesFirst ) mainIdx ++;
  23847. newShapeHoles[ mainIdx ] = [];
  23848. //console.log('cw', i);
  23849. } else {
  23850. newShapeHoles[ mainIdx ].push( { h: tmpPath, p: tmpPoints[ 0 ] } );
  23851. //console.log('ccw', i);
  23852. }
  23853. }
  23854. // only Holes? -> probably all Shapes with wrong orientation
  23855. if ( ! newShapes[ 0 ] ) return toShapesNoHoles( subPaths );
  23856. if ( newShapes.length > 1 ) {
  23857. var ambiguous = false;
  23858. var toChange = [];
  23859. for ( var sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx ++ ) {
  23860. betterShapeHoles[ sIdx ] = [];
  23861. }
  23862. for ( var sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx ++ ) {
  23863. var sho = newShapeHoles[ sIdx ];
  23864. for ( var hIdx = 0; hIdx < sho.length; hIdx ++ ) {
  23865. var ho = sho[ hIdx ];
  23866. var hole_unassigned = true;
  23867. for ( var s2Idx = 0; s2Idx < newShapes.length; s2Idx ++ ) {
  23868. if ( isPointInsidePolygon( ho.p, newShapes[ s2Idx ].p ) ) {
  23869. if ( sIdx !== s2Idx ) toChange.push( { froms: sIdx, tos: s2Idx, hole: hIdx } );
  23870. if ( hole_unassigned ) {
  23871. hole_unassigned = false;
  23872. betterShapeHoles[ s2Idx ].push( ho );
  23873. } else {
  23874. ambiguous = true;
  23875. }
  23876. }
  23877. }
  23878. if ( hole_unassigned ) {
  23879. betterShapeHoles[ sIdx ].push( ho );
  23880. }
  23881. }
  23882. }
  23883. // console.log("ambiguous: ", ambiguous);
  23884. if ( toChange.length > 0 ) {
  23885. // console.log("to change: ", toChange);
  23886. if ( ! ambiguous ) newShapeHoles = betterShapeHoles;
  23887. }
  23888. }
  23889. var tmpHoles;
  23890. for ( var i = 0, il = newShapes.length; i < il; i ++ ) {
  23891. tmpShape = newShapes[ i ].s;
  23892. shapes.push( tmpShape );
  23893. tmpHoles = newShapeHoles[ i ];
  23894. for ( var j = 0, jl = tmpHoles.length; j < jl; j ++ ) {
  23895. tmpShape.holes.push( tmpHoles[ j ].h );
  23896. }
  23897. }
  23898. //console.log("shape", shapes);
  23899. return shapes;
  23900. }
  23901. } );
  23902. /**
  23903. * @author zz85 / http://www.lab4games.net/zz85/blog
  23904. * @author mrdoob / http://mrdoob.com/
  23905. */
  23906. function Font( data ) {
  23907. this.type = 'Font';
  23908. this.data = data;
  23909. }
  23910. Object.assign( Font.prototype, {
  23911. isFont: true,
  23912. generateShapes: function ( text, size ) {
  23913. if ( size === undefined ) size = 100;
  23914. var shapes = [];
  23915. var paths = createPaths( text, size, this.data );
  23916. for ( var p = 0, pl = paths.length; p < pl; p ++ ) {
  23917. Array.prototype.push.apply( shapes, paths[ p ].toShapes() );
  23918. }
  23919. return shapes;
  23920. }
  23921. } );
  23922. function createPaths( text, size, data ) {
  23923. var chars = Array.from ? Array.from( text ) : String( text ).split( '' ); // see #13988
  23924. var scale = size / data.resolution;
  23925. var line_height = ( data.boundingBox.yMax - data.boundingBox.yMin + data.underlineThickness ) * scale;
  23926. var paths = [];
  23927. var offsetX = 0, offsetY = 0;
  23928. for ( var i = 0; i < chars.length; i ++ ) {
  23929. var char = chars[ i ];
  23930. if ( char === '\n' ) {
  23931. offsetX = 0;
  23932. offsetY -= line_height;
  23933. } else {
  23934. var ret = createPath( char, scale, offsetX, offsetY, data );
  23935. offsetX += ret.offsetX;
  23936. paths.push( ret.path );
  23937. }
  23938. }
  23939. return paths;
  23940. }
  23941. function createPath( char, scale, offsetX, offsetY, data ) {
  23942. var glyph = data.glyphs[ char ] || data.glyphs[ '?' ];
  23943. if ( ! glyph ) return;
  23944. var path = new ShapePath();
  23945. var x, y, cpx, cpy, cpx1, cpy1, cpx2, cpy2;
  23946. if ( glyph.o ) {
  23947. var outline = glyph._cachedOutline || ( glyph._cachedOutline = glyph.o.split( ' ' ) );
  23948. for ( var i = 0, l = outline.length; i < l; ) {
  23949. var action = outline[ i ++ ];
  23950. switch ( action ) {
  23951. case 'm': // moveTo
  23952. x = outline[ i ++ ] * scale + offsetX;
  23953. y = outline[ i ++ ] * scale + offsetY;
  23954. path.moveTo( x, y );
  23955. break;
  23956. case 'l': // lineTo
  23957. x = outline[ i ++ ] * scale + offsetX;
  23958. y = outline[ i ++ ] * scale + offsetY;
  23959. path.lineTo( x, y );
  23960. break;
  23961. case 'q': // quadraticCurveTo
  23962. cpx = outline[ i ++ ] * scale + offsetX;
  23963. cpy = outline[ i ++ ] * scale + offsetY;
  23964. cpx1 = outline[ i ++ ] * scale + offsetX;
  23965. cpy1 = outline[ i ++ ] * scale + offsetY;
  23966. path.quadraticCurveTo( cpx1, cpy1, cpx, cpy );
  23967. break;
  23968. case 'b': // bezierCurveTo
  23969. cpx = outline[ i ++ ] * scale + offsetX;
  23970. cpy = outline[ i ++ ] * scale + offsetY;
  23971. cpx1 = outline[ i ++ ] * scale + offsetX;
  23972. cpy1 = outline[ i ++ ] * scale + offsetY;
  23973. cpx2 = outline[ i ++ ] * scale + offsetX;
  23974. cpy2 = outline[ i ++ ] * scale + offsetY;
  23975. path.bezierCurveTo( cpx1, cpy1, cpx2, cpy2, cpx, cpy );
  23976. break;
  23977. }
  23978. }
  23979. }
  23980. return { offsetX: glyph.ha * scale, path: path };
  23981. }
  23982. /**
  23983. * @author mrdoob / http://mrdoob.com/
  23984. */
  23985. function FontLoader( manager ) {
  23986. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  23987. }
  23988. Object.assign( FontLoader.prototype, {
  23989. load: function ( url, onLoad, onProgress, onError ) {
  23990. var scope = this;
  23991. var loader = new FileLoader( this.manager );
  23992. loader.setPath( this.path );
  23993. loader.load( url, function ( text ) {
  23994. var json;
  23995. try {
  23996. json = JSON.parse( text );
  23997. } catch ( e ) {
  23998. console.warn( 'THREE.FontLoader: typeface.js support is being deprecated. Use typeface.json instead.' );
  23999. json = JSON.parse( text.substring( 65, text.length - 2 ) );
  24000. }
  24001. var font = scope.parse( json );
  24002. if ( onLoad ) onLoad( font );
  24003. }, onProgress, onError );
  24004. },
  24005. parse: function ( json ) {
  24006. return new Font( json );
  24007. },
  24008. setPath: function ( value ) {
  24009. this.path = value;
  24010. return this;
  24011. }
  24012. } );
  24013. /**
  24014. * @author alteredq / http://alteredqualia.com/
  24015. */
  24016. function Loader() {}
  24017. Loader.Handlers = {
  24018. handlers: [],
  24019. add: function ( regex, loader ) {
  24020. this.handlers.push( regex, loader );
  24021. },
  24022. get: function ( file ) {
  24023. var handlers = this.handlers;
  24024. for ( var i = 0, l = handlers.length; i < l; i += 2 ) {
  24025. var regex = handlers[ i ];
  24026. var loader = handlers[ i + 1 ];
  24027. if ( regex.test( file ) ) {
  24028. return loader;
  24029. }
  24030. }
  24031. return null;
  24032. }
  24033. };
  24034. Object.assign( Loader.prototype, {
  24035. crossOrigin: 'anonymous',
  24036. onLoadStart: function () {},
  24037. onLoadProgress: function () {},
  24038. onLoadComplete: function () {},
  24039. initMaterials: function ( materials, texturePath, crossOrigin ) {
  24040. var array = [];
  24041. for ( var i = 0; i < materials.length; ++ i ) {
  24042. array[ i ] = this.createMaterial( materials[ i ], texturePath, crossOrigin );
  24043. }
  24044. return array;
  24045. },
  24046. createMaterial: ( function () {
  24047. var BlendingMode = {
  24048. NoBlending: NoBlending,
  24049. NormalBlending: NormalBlending,
  24050. AdditiveBlending: AdditiveBlending,
  24051. SubtractiveBlending: SubtractiveBlending,
  24052. MultiplyBlending: MultiplyBlending,
  24053. CustomBlending: CustomBlending
  24054. };
  24055. var color = new Color();
  24056. var textureLoader = new TextureLoader();
  24057. var materialLoader = new MaterialLoader();
  24058. return function createMaterial( m, texturePath, crossOrigin ) {
  24059. // convert from old material format
  24060. var textures = {};
  24061. function loadTexture( path, repeat, offset, wrap, anisotropy ) {
  24062. var fullPath = texturePath + path;
  24063. var loader = Loader.Handlers.get( fullPath );
  24064. var texture;
  24065. if ( loader !== null ) {
  24066. texture = loader.load( fullPath );
  24067. } else {
  24068. textureLoader.setCrossOrigin( crossOrigin );
  24069. texture = textureLoader.load( fullPath );
  24070. }
  24071. if ( repeat !== undefined ) {
  24072. texture.repeat.fromArray( repeat );
  24073. if ( repeat[ 0 ] !== 1 ) texture.wrapS = RepeatWrapping;
  24074. if ( repeat[ 1 ] !== 1 ) texture.wrapT = RepeatWrapping;
  24075. }
  24076. if ( offset !== undefined ) {
  24077. texture.offset.fromArray( offset );
  24078. }
  24079. if ( wrap !== undefined ) {
  24080. if ( wrap[ 0 ] === 'repeat' ) texture.wrapS = RepeatWrapping;
  24081. if ( wrap[ 0 ] === 'mirror' ) texture.wrapS = MirroredRepeatWrapping;
  24082. if ( wrap[ 1 ] === 'repeat' ) texture.wrapT = RepeatWrapping;
  24083. if ( wrap[ 1 ] === 'mirror' ) texture.wrapT = MirroredRepeatWrapping;
  24084. }
  24085. if ( anisotropy !== undefined ) {
  24086. texture.anisotropy = anisotropy;
  24087. }
  24088. var uuid = _Math.generateUUID();
  24089. textures[ uuid ] = texture;
  24090. return uuid;
  24091. }
  24092. //
  24093. var json = {
  24094. uuid: _Math.generateUUID(),
  24095. type: 'MeshLambertMaterial'
  24096. };
  24097. for ( var name in m ) {
  24098. var value = m[ name ];
  24099. switch ( name ) {
  24100. case 'DbgColor':
  24101. case 'DbgIndex':
  24102. case 'opticalDensity':
  24103. case 'illumination':
  24104. break;
  24105. case 'DbgName':
  24106. json.name = value;
  24107. break;
  24108. case 'blending':
  24109. json.blending = BlendingMode[ value ];
  24110. break;
  24111. case 'colorAmbient':
  24112. case 'mapAmbient':
  24113. console.warn( 'THREE.Loader.createMaterial:', name, 'is no longer supported.' );
  24114. break;
  24115. case 'colorDiffuse':
  24116. json.color = color.fromArray( value ).getHex();
  24117. break;
  24118. case 'colorSpecular':
  24119. json.specular = color.fromArray( value ).getHex();
  24120. break;
  24121. case 'colorEmissive':
  24122. json.emissive = color.fromArray( value ).getHex();
  24123. break;
  24124. case 'specularCoef':
  24125. json.shininess = value;
  24126. break;
  24127. case 'shading':
  24128. if ( value.toLowerCase() === 'basic' ) json.type = 'MeshBasicMaterial';
  24129. if ( value.toLowerCase() === 'phong' ) json.type = 'MeshPhongMaterial';
  24130. if ( value.toLowerCase() === 'standard' ) json.type = 'MeshStandardMaterial';
  24131. break;
  24132. case 'mapDiffuse':
  24133. json.map = loadTexture( value, m.mapDiffuseRepeat, m.mapDiffuseOffset, m.mapDiffuseWrap, m.mapDiffuseAnisotropy );
  24134. break;
  24135. case 'mapDiffuseRepeat':
  24136. case 'mapDiffuseOffset':
  24137. case 'mapDiffuseWrap':
  24138. case 'mapDiffuseAnisotropy':
  24139. break;
  24140. case 'mapEmissive':
  24141. json.emissiveMap = loadTexture( value, m.mapEmissiveRepeat, m.mapEmissiveOffset, m.mapEmissiveWrap, m.mapEmissiveAnisotropy );
  24142. break;
  24143. case 'mapEmissiveRepeat':
  24144. case 'mapEmissiveOffset':
  24145. case 'mapEmissiveWrap':
  24146. case 'mapEmissiveAnisotropy':
  24147. break;
  24148. case 'mapLight':
  24149. json.lightMap = loadTexture( value, m.mapLightRepeat, m.mapLightOffset, m.mapLightWrap, m.mapLightAnisotropy );
  24150. break;
  24151. case 'mapLightRepeat':
  24152. case 'mapLightOffset':
  24153. case 'mapLightWrap':
  24154. case 'mapLightAnisotropy':
  24155. break;
  24156. case 'mapAO':
  24157. json.aoMap = loadTexture( value, m.mapAORepeat, m.mapAOOffset, m.mapAOWrap, m.mapAOAnisotropy );
  24158. break;
  24159. case 'mapAORepeat':
  24160. case 'mapAOOffset':
  24161. case 'mapAOWrap':
  24162. case 'mapAOAnisotropy':
  24163. break;
  24164. case 'mapBump':
  24165. json.bumpMap = loadTexture( value, m.mapBumpRepeat, m.mapBumpOffset, m.mapBumpWrap, m.mapBumpAnisotropy );
  24166. break;
  24167. case 'mapBumpScale':
  24168. json.bumpScale = value;
  24169. break;
  24170. case 'mapBumpRepeat':
  24171. case 'mapBumpOffset':
  24172. case 'mapBumpWrap':
  24173. case 'mapBumpAnisotropy':
  24174. break;
  24175. case 'mapNormal':
  24176. json.normalMap = loadTexture( value, m.mapNormalRepeat, m.mapNormalOffset, m.mapNormalWrap, m.mapNormalAnisotropy );
  24177. break;
  24178. case 'mapNormalFactor':
  24179. json.normalScale = value;
  24180. break;
  24181. case 'mapNormalRepeat':
  24182. case 'mapNormalOffset':
  24183. case 'mapNormalWrap':
  24184. case 'mapNormalAnisotropy':
  24185. break;
  24186. case 'mapSpecular':
  24187. json.specularMap = loadTexture( value, m.mapSpecularRepeat, m.mapSpecularOffset, m.mapSpecularWrap, m.mapSpecularAnisotropy );
  24188. break;
  24189. case 'mapSpecularRepeat':
  24190. case 'mapSpecularOffset':
  24191. case 'mapSpecularWrap':
  24192. case 'mapSpecularAnisotropy':
  24193. break;
  24194. case 'mapMetalness':
  24195. json.metalnessMap = loadTexture( value, m.mapMetalnessRepeat, m.mapMetalnessOffset, m.mapMetalnessWrap, m.mapMetalnessAnisotropy );
  24196. break;
  24197. case 'mapMetalnessRepeat':
  24198. case 'mapMetalnessOffset':
  24199. case 'mapMetalnessWrap':
  24200. case 'mapMetalnessAnisotropy':
  24201. break;
  24202. case 'mapRoughness':
  24203. json.roughnessMap = loadTexture( value, m.mapRoughnessRepeat, m.mapRoughnessOffset, m.mapRoughnessWrap, m.mapRoughnessAnisotropy );
  24204. break;
  24205. case 'mapRoughnessRepeat':
  24206. case 'mapRoughnessOffset':
  24207. case 'mapRoughnessWrap':
  24208. case 'mapRoughnessAnisotropy':
  24209. break;
  24210. case 'mapAlpha':
  24211. json.alphaMap = loadTexture( value, m.mapAlphaRepeat, m.mapAlphaOffset, m.mapAlphaWrap, m.mapAlphaAnisotropy );
  24212. break;
  24213. case 'mapAlphaRepeat':
  24214. case 'mapAlphaOffset':
  24215. case 'mapAlphaWrap':
  24216. case 'mapAlphaAnisotropy':
  24217. break;
  24218. case 'flipSided':
  24219. json.side = BackSide;
  24220. break;
  24221. case 'doubleSided':
  24222. json.side = DoubleSide;
  24223. break;
  24224. case 'transparency':
  24225. console.warn( 'THREE.Loader.createMaterial: transparency has been renamed to opacity' );
  24226. json.opacity = value;
  24227. break;
  24228. case 'depthTest':
  24229. case 'depthWrite':
  24230. case 'colorWrite':
  24231. case 'opacity':
  24232. case 'reflectivity':
  24233. case 'transparent':
  24234. case 'visible':
  24235. case 'wireframe':
  24236. json[ name ] = value;
  24237. break;
  24238. case 'vertexColors':
  24239. if ( value === true ) json.vertexColors = VertexColors;
  24240. if ( value === 'face' ) json.vertexColors = FaceColors;
  24241. break;
  24242. default:
  24243. console.error( 'THREE.Loader.createMaterial: Unsupported', name, value );
  24244. break;
  24245. }
  24246. }
  24247. if ( json.type === 'MeshBasicMaterial' ) delete json.emissive;
  24248. if ( json.type !== 'MeshPhongMaterial' ) delete json.specular;
  24249. if ( json.opacity < 1 ) json.transparent = true;
  24250. materialLoader.setTextures( textures );
  24251. return materialLoader.parse( json );
  24252. };
  24253. } )()
  24254. } );
  24255. /**
  24256. * @author mrdoob / http://mrdoob.com/
  24257. */
  24258. var context;
  24259. var AudioContext = {
  24260. getContext: function () {
  24261. if ( context === undefined ) {
  24262. context = new ( window.AudioContext || window.webkitAudioContext )();
  24263. }
  24264. return context;
  24265. },
  24266. setContext: function ( value ) {
  24267. context = value;
  24268. }
  24269. };
  24270. /**
  24271. * @author Reece Aaron Lecrivain / http://reecenotes.com/
  24272. */
  24273. function AudioLoader( manager ) {
  24274. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  24275. }
  24276. Object.assign( AudioLoader.prototype, {
  24277. load: function ( url, onLoad, onProgress, onError ) {
  24278. var loader = new FileLoader( this.manager );
  24279. loader.setResponseType( 'arraybuffer' );
  24280. loader.setPath( this.path );
  24281. loader.load( url, function ( buffer ) {
  24282. // Create a copy of the buffer. The `decodeAudioData` method
  24283. // detaches the buffer when complete, preventing reuse.
  24284. var bufferCopy = buffer.slice( 0 );
  24285. var context = AudioContext.getContext();
  24286. context.decodeAudioData( bufferCopy, function ( audioBuffer ) {
  24287. onLoad( audioBuffer );
  24288. } );
  24289. }, onProgress, onError );
  24290. },
  24291. setPath: function ( value ) {
  24292. this.path = value;
  24293. return this;
  24294. }
  24295. } );
  24296. /**
  24297. * @author bhouston / http://clara.io
  24298. * @author WestLangley / http://github.com/WestLangley
  24299. *
  24300. * Primary reference:
  24301. * https://graphics.stanford.edu/papers/envmap/envmap.pdf
  24302. *
  24303. * Secondary reference:
  24304. * https://www.ppsloan.org/publications/StupidSH36.pdf
  24305. */
  24306. // 3-band SH defined by 9 coefficients
  24307. function SphericalHarmonics3() {
  24308. this.coefficients = [];
  24309. for ( var i = 0; i < 9; i ++ ) {
  24310. this.coefficients.push( new Vector3() );
  24311. }
  24312. }
  24313. Object.assign( SphericalHarmonics3.prototype, {
  24314. isSphericalHarmonics3: true,
  24315. set: function ( coefficients ) {
  24316. for ( var i = 0; i < 9; i ++ ) {
  24317. this.coefficients[ i ].copy( coefficients[ i ] );
  24318. }
  24319. return this;
  24320. },
  24321. zero: function () {
  24322. for ( var i = 0; i < 9; i ++ ) {
  24323. this.coefficients[ i ].set( 0, 0, 0 );
  24324. }
  24325. return this;
  24326. },
  24327. // get the radiance in the direction of the normal
  24328. // target is a Vector3
  24329. getAt: function ( normal, target ) {
  24330. // normal is assumed to be unit length
  24331. var x = normal.x, y = normal.y, z = normal.z;
  24332. var coeff = this.coefficients;
  24333. // band 0
  24334. target.copy( coeff[ 0 ] ).multiplyScalar( 0.282095 );
  24335. // band 1
  24336. target.addScale( coeff[ 1 ], 0.488603 * y );
  24337. target.addScale( coeff[ 2 ], 0.488603 * z );
  24338. target.addScale( coeff[ 3 ], 0.488603 * x );
  24339. // band 2
  24340. target.addScale( coeff[ 4 ], 1.092548 * ( x * y ) );
  24341. target.addScale( coeff[ 5 ], 1.092548 * ( y * z ) );
  24342. target.addScale( coeff[ 6 ], 0.315392 * ( 3.0 * z * z - 1.0 ) );
  24343. target.addScale( coeff[ 7 ], 1.092548 * ( x * z ) );
  24344. target.addScale( coeff[ 8 ], 0.546274 * ( x * x - y * y ) );
  24345. return target;
  24346. },
  24347. // get the irradiance (radiance convolved with cosine lobe) in the direction of the normal
  24348. // target is a Vector3
  24349. // https://graphics.stanford.edu/papers/envmap/envmap.pdf
  24350. getIrradianceAt: function ( normal, target ) {
  24351. // normal is assumed to be unit length
  24352. var x = normal.x, y = normal.y, z = normal.z;
  24353. var coeff = this.coefficients;
  24354. // band 0
  24355. target.copy( coeff[ 0 ] ).multiplyScalar( 0.886227 ); // π * 0.282095
  24356. // band 1
  24357. target.addScale( coeff[ 1 ], 2.0 * 0.511664 * y ); // ( 2 * π / 3 ) * 0.488603
  24358. target.addScale( coeff[ 2 ], 2.0 * 0.511664 * z );
  24359. target.addScale( coeff[ 3 ], 2.0 * 0.511664 * x );
  24360. // band 2
  24361. target.addScale( coeff[ 4 ], 2.0 * 0.429043 * x * y ); // ( π / 4 ) * 1.092548
  24362. target.addScale( coeff[ 5 ], 2.0 * 0.429043 * y * z );
  24363. target.addScale( coeff[ 6 ], 0.743125 * z * z - 0.247708 ); // ( π / 4 ) * 0.315392 * 3
  24364. target.addScale( coeff[ 7 ], 2.0 * 0.429043 * x * z );
  24365. target.addScale( coeff[ 8 ], 0.429043 * ( x * x - y * y ) ); // ( π / 4 ) * 0.546274
  24366. return target;
  24367. },
  24368. add: function ( sh ) {
  24369. for ( var i = 0; i < 9; i ++ ) {
  24370. this.coefficients[ i ].add( sh.coefficients[ i ] );
  24371. }
  24372. return this;
  24373. },
  24374. scale: function ( s ) {
  24375. for ( var i = 0; i < 9; i ++ ) {
  24376. this.coefficients[ i ].multiplyScalar( s );
  24377. }
  24378. return this;
  24379. },
  24380. lerp: function ( sh, alpha ) {
  24381. for ( var i = 0; i < 9; i ++ ) {
  24382. this.coefficients[ i ].lerp( sh.coefficients[ i ], alpha );
  24383. }
  24384. return this;
  24385. },
  24386. equals: function ( sh ) {
  24387. for ( var i = 0; i < 9; i ++ ) {
  24388. if ( ! this.coefficients[ i ].equals( sh.coefficients[ i ] ) ) {
  24389. return false;
  24390. }
  24391. }
  24392. return true;
  24393. },
  24394. copy: function ( sh ) {
  24395. return this.set( sh.coefficients );
  24396. },
  24397. clone: function () {
  24398. return new this.constructor().copy( this );
  24399. },
  24400. fromArray: function ( array ) {
  24401. var coefficients = this.coefficients;
  24402. for ( var i = 0; i < 9; i ++ ) {
  24403. coefficients[ i ].fromArray( array, i * 3 );
  24404. }
  24405. return this;
  24406. },
  24407. toArray: function () {
  24408. var array = [];
  24409. var coefficients = this.coefficients;
  24410. for ( var i = 0; i < 9; i ++ ) {
  24411. coefficients[ i ].toArray( array, i * 3 );
  24412. }
  24413. return array;
  24414. }
  24415. } );
  24416. Object.assign( SphericalHarmonics3, {
  24417. // evaluate the basis functions
  24418. // shBasis is an Array[ 9 ]
  24419. getBasisAt: function ( normal, shBasis ) {
  24420. // normal is assumed to be unit length
  24421. var x = normal.x, y = normal.y, z = normal.z;
  24422. // band 0
  24423. shBasis[ 0 ] = 0.282095;
  24424. // band 1
  24425. shBasis[ 1 ] = 0.488603 * y;
  24426. shBasis[ 2 ] = 0.488603 * z;
  24427. shBasis[ 3 ] = 0.488603 * x;
  24428. // band 2
  24429. shBasis[ 4 ] = 1.092548 * x * y;
  24430. shBasis[ 5 ] = 1.092548 * y * z;
  24431. shBasis[ 6 ] = 0.315392 * ( 3 * z * z - 1 );
  24432. shBasis[ 7 ] = 1.092548 * x * z;
  24433. shBasis[ 8 ] = 0.546274 * ( x * x - y * y );
  24434. }
  24435. } );
  24436. /**
  24437. * @author WestLangley / http://github.com/WestLangley
  24438. *
  24439. * A LightProbe is a source of indirect-diffuse light
  24440. */
  24441. function LightProbe( sh, intensity ) {
  24442. Light.call( this, undefined, intensity );
  24443. this.sh = ( sh !== undefined ) ? sh : new SphericalHarmonics3();
  24444. }
  24445. LightProbe.prototype = Object.assign( Object.create( Light.prototype ), {
  24446. constructor: LightProbe,
  24447. isLightProbe: true,
  24448. copy: function ( source ) {
  24449. Light.prototype.copy.call( this, source );
  24450. this.sh.copy( source.sh );
  24451. this.intensity = source.intensity;
  24452. return this;
  24453. },
  24454. toJSON: function ( meta ) {
  24455. var data = Light.prototype.toJSON.call( this, meta );
  24456. // data.sh = this.sh.toArray(); // todo
  24457. return data;
  24458. }
  24459. } );
  24460. /**
  24461. * @author WestLangley / http://github.com/WestLangley
  24462. */
  24463. function HemisphereLightProbe( skyColor, groundColor, intensity ) {
  24464. LightProbe.call( this, undefined, intensity );
  24465. var color1 = new Color().set( skyColor );
  24466. var color2 = new Color().set( groundColor );
  24467. var sky = new Vector3( color1.r, color1.g, color1.b );
  24468. var ground = new Vector3( color2.r, color2.g, color2.b );
  24469. // without extra factor of PI in the shader, should = 1 / Math.sqrt( Math.PI );
  24470. var c0 = Math.sqrt( Math.PI );
  24471. var c1 = c0 * Math.sqrt( 0.75 );
  24472. this.sh.coefficients[ 0 ].copy( sky ).add( ground ).multiplyScalar( c0 );
  24473. this.sh.coefficients[ 1 ].copy( sky ).sub( ground ).multiplyScalar( c1 );
  24474. }
  24475. HemisphereLightProbe.prototype = Object.assign( Object.create( LightProbe.prototype ), {
  24476. constructor: HemisphereLightProbe,
  24477. isHemisphereLightProbe: true,
  24478. copy: function ( source ) { // modifying colors not currently supported
  24479. LightProbe.prototype.copy.call( this, source );
  24480. return this;
  24481. },
  24482. toJSON: function ( meta ) {
  24483. var data = LightProbe.prototype.toJSON.call( this, meta );
  24484. // data.sh = this.sh.toArray(); // todo
  24485. return data;
  24486. }
  24487. } );
  24488. /**
  24489. * @author WestLangley / http://github.com/WestLangley
  24490. */
  24491. function AmbientLightProbe( color, intensity ) {
  24492. LightProbe.call( this, undefined, intensity );
  24493. var color1 = new Color().set( color );
  24494. // without extra factor of PI in the shader, would be 2 / Math.sqrt( Math.PI );
  24495. this.sh.coefficients[ 0 ].set( color1.r, color1.g, color1.b ).multiplyScalar( 2 * Math.sqrt( Math.PI ) );
  24496. }
  24497. AmbientLightProbe.prototype = Object.assign( Object.create( LightProbe.prototype ), {
  24498. constructor: AmbientLightProbe,
  24499. isAmbientLightProbe: true,
  24500. copy: function ( source ) { // modifying color not currently supported
  24501. LightProbe.prototype.copy.call( this, source );
  24502. return this;
  24503. },
  24504. toJSON: function ( meta ) {
  24505. var data = LightProbe.prototype.toJSON.call( this, meta );
  24506. // data.sh = this.sh.toArray(); // todo
  24507. return data;
  24508. }
  24509. } );
  24510. /**
  24511. * @author mrdoob / http://mrdoob.com/
  24512. */
  24513. function StereoCamera() {
  24514. this.type = 'StereoCamera';
  24515. this.aspect = 1;
  24516. this.eyeSep = 0.064;
  24517. this.cameraL = new PerspectiveCamera();
  24518. this.cameraL.layers.enable( 1 );
  24519. this.cameraL.matrixAutoUpdate = false;
  24520. this.cameraR = new PerspectiveCamera();
  24521. this.cameraR.layers.enable( 2 );
  24522. this.cameraR.matrixAutoUpdate = false;
  24523. }
  24524. Object.assign( StereoCamera.prototype, {
  24525. update: ( function () {
  24526. var instance, focus, fov, aspect, near, far, zoom, eyeSep;
  24527. var eyeRight = new Matrix4();
  24528. var eyeLeft = new Matrix4();
  24529. return function update( camera ) {
  24530. var needsUpdate = instance !== this || focus !== camera.focus || fov !== camera.fov ||
  24531. aspect !== camera.aspect * this.aspect || near !== camera.near ||
  24532. far !== camera.far || zoom !== camera.zoom || eyeSep !== this.eyeSep;
  24533. if ( needsUpdate ) {
  24534. instance = this;
  24535. focus = camera.focus;
  24536. fov = camera.fov;
  24537. aspect = camera.aspect * this.aspect;
  24538. near = camera.near;
  24539. far = camera.far;
  24540. zoom = camera.zoom;
  24541. // Off-axis stereoscopic effect based on
  24542. // http://paulbourke.net/stereographics/stereorender/
  24543. var projectionMatrix = camera.projectionMatrix.clone();
  24544. eyeSep = this.eyeSep / 2;
  24545. var eyeSepOnProjection = eyeSep * near / focus;
  24546. var ymax = ( near * Math.tan( _Math.DEG2RAD * fov * 0.5 ) ) / zoom;
  24547. var xmin, xmax;
  24548. // translate xOffset
  24549. eyeLeft.elements[ 12 ] = - eyeSep;
  24550. eyeRight.elements[ 12 ] = eyeSep;
  24551. // for left eye
  24552. xmin = - ymax * aspect + eyeSepOnProjection;
  24553. xmax = ymax * aspect + eyeSepOnProjection;
  24554. projectionMatrix.elements[ 0 ] = 2 * near / ( xmax - xmin );
  24555. projectionMatrix.elements[ 8 ] = ( xmax + xmin ) / ( xmax - xmin );
  24556. this.cameraL.projectionMatrix.copy( projectionMatrix );
  24557. // for right eye
  24558. xmin = - ymax * aspect - eyeSepOnProjection;
  24559. xmax = ymax * aspect - eyeSepOnProjection;
  24560. projectionMatrix.elements[ 0 ] = 2 * near / ( xmax - xmin );
  24561. projectionMatrix.elements[ 8 ] = ( xmax + xmin ) / ( xmax - xmin );
  24562. this.cameraR.projectionMatrix.copy( projectionMatrix );
  24563. }
  24564. this.cameraL.matrixWorld.copy( camera.matrixWorld ).multiply( eyeLeft );
  24565. this.cameraR.matrixWorld.copy( camera.matrixWorld ).multiply( eyeRight );
  24566. };
  24567. } )()
  24568. } );
  24569. /**
  24570. * @author alteredq / http://alteredqualia.com/
  24571. */
  24572. function Clock( autoStart ) {
  24573. this.autoStart = ( autoStart !== undefined ) ? autoStart : true;
  24574. this.startTime = 0;
  24575. this.oldTime = 0;
  24576. this.elapsedTime = 0;
  24577. this.running = false;
  24578. }
  24579. Object.assign( Clock.prototype, {
  24580. start: function () {
  24581. this.startTime = ( typeof performance === 'undefined' ? Date : performance ).now(); // see #10732
  24582. this.oldTime = this.startTime;
  24583. this.elapsedTime = 0;
  24584. this.running = true;
  24585. },
  24586. stop: function () {
  24587. this.getElapsedTime();
  24588. this.running = false;
  24589. this.autoStart = false;
  24590. },
  24591. getElapsedTime: function () {
  24592. this.getDelta();
  24593. return this.elapsedTime;
  24594. },
  24595. getDelta: function () {
  24596. var diff = 0;
  24597. if ( this.autoStart && ! this.running ) {
  24598. this.start();
  24599. return 0;
  24600. }
  24601. if ( this.running ) {
  24602. var newTime = ( typeof performance === 'undefined' ? Date : performance ).now();
  24603. diff = ( newTime - this.oldTime ) / 1000;
  24604. this.oldTime = newTime;
  24605. this.elapsedTime += diff;
  24606. }
  24607. return diff;
  24608. }
  24609. } );
  24610. /**
  24611. * @author mrdoob / http://mrdoob.com/
  24612. */
  24613. function AudioListener() {
  24614. Object3D.call( this );
  24615. this.type = 'AudioListener';
  24616. this.context = AudioContext.getContext();
  24617. this.gain = this.context.createGain();
  24618. this.gain.connect( this.context.destination );
  24619. this.filter = null;
  24620. this.timeDelta = 0;
  24621. }
  24622. AudioListener.prototype = Object.assign( Object.create( Object3D.prototype ), {
  24623. constructor: AudioListener,
  24624. getInput: function () {
  24625. return this.gain;
  24626. },
  24627. removeFilter: function ( ) {
  24628. if ( this.filter !== null ) {
  24629. this.gain.disconnect( this.filter );
  24630. this.filter.disconnect( this.context.destination );
  24631. this.gain.connect( this.context.destination );
  24632. this.filter = null;
  24633. }
  24634. return this;
  24635. },
  24636. getFilter: function () {
  24637. return this.filter;
  24638. },
  24639. setFilter: function ( value ) {
  24640. if ( this.filter !== null ) {
  24641. this.gain.disconnect( this.filter );
  24642. this.filter.disconnect( this.context.destination );
  24643. } else {
  24644. this.gain.disconnect( this.context.destination );
  24645. }
  24646. this.filter = value;
  24647. this.gain.connect( this.filter );
  24648. this.filter.connect( this.context.destination );
  24649. return this;
  24650. },
  24651. getMasterVolume: function () {
  24652. return this.gain.gain.value;
  24653. },
  24654. setMasterVolume: function ( value ) {
  24655. this.gain.gain.setTargetAtTime( value, this.context.currentTime, 0.01 );
  24656. return this;
  24657. },
  24658. updateMatrixWorld: ( function () {
  24659. var position = new Vector3();
  24660. var quaternion = new Quaternion();
  24661. var scale = new Vector3();
  24662. var orientation = new Vector3();
  24663. var clock = new Clock();
  24664. return function updateMatrixWorld( force ) {
  24665. Object3D.prototype.updateMatrixWorld.call( this, force );
  24666. var listener = this.context.listener;
  24667. var up = this.up;
  24668. this.timeDelta = clock.getDelta();
  24669. this.matrixWorld.decompose( position, quaternion, scale );
  24670. orientation.set( 0, 0, - 1 ).applyQuaternion( quaternion );
  24671. if ( listener.positionX ) {
  24672. // code path for Chrome (see #14393)
  24673. var endTime = this.context.currentTime + this.timeDelta;
  24674. listener.positionX.linearRampToValueAtTime( position.x, endTime );
  24675. listener.positionY.linearRampToValueAtTime( position.y, endTime );
  24676. listener.positionZ.linearRampToValueAtTime( position.z, endTime );
  24677. listener.forwardX.linearRampToValueAtTime( orientation.x, endTime );
  24678. listener.forwardY.linearRampToValueAtTime( orientation.y, endTime );
  24679. listener.forwardZ.linearRampToValueAtTime( orientation.z, endTime );
  24680. listener.upX.linearRampToValueAtTime( up.x, endTime );
  24681. listener.upY.linearRampToValueAtTime( up.y, endTime );
  24682. listener.upZ.linearRampToValueAtTime( up.z, endTime );
  24683. } else {
  24684. listener.setPosition( position.x, position.y, position.z );
  24685. listener.setOrientation( orientation.x, orientation.y, orientation.z, up.x, up.y, up.z );
  24686. }
  24687. };
  24688. } )()
  24689. } );
  24690. /**
  24691. * @author mrdoob / http://mrdoob.com/
  24692. * @author Reece Aaron Lecrivain / http://reecenotes.com/
  24693. */
  24694. function Audio( listener ) {
  24695. Object3D.call( this );
  24696. this.type = 'Audio';
  24697. this.listener = listener;
  24698. this.context = listener.context;
  24699. this.gain = this.context.createGain();
  24700. this.gain.connect( listener.getInput() );
  24701. this.autoplay = false;
  24702. this.buffer = null;
  24703. this.detune = 0;
  24704. this.loop = false;
  24705. this.startTime = 0;
  24706. this.offset = 0;
  24707. this.playbackRate = 1;
  24708. this.isPlaying = false;
  24709. this.hasPlaybackControl = true;
  24710. this.sourceType = 'empty';
  24711. this.filters = [];
  24712. }
  24713. Audio.prototype = Object.assign( Object.create( Object3D.prototype ), {
  24714. constructor: Audio,
  24715. getOutput: function () {
  24716. return this.gain;
  24717. },
  24718. setNodeSource: function ( audioNode ) {
  24719. this.hasPlaybackControl = false;
  24720. this.sourceType = 'audioNode';
  24721. this.source = audioNode;
  24722. this.connect();
  24723. return this;
  24724. },
  24725. setMediaElementSource: function ( mediaElement ) {
  24726. this.hasPlaybackControl = false;
  24727. this.sourceType = 'mediaNode';
  24728. this.source = this.context.createMediaElementSource( mediaElement );
  24729. this.connect();
  24730. return this;
  24731. },
  24732. setBuffer: function ( audioBuffer ) {
  24733. this.buffer = audioBuffer;
  24734. this.sourceType = 'buffer';
  24735. if ( this.autoplay ) this.play();
  24736. return this;
  24737. },
  24738. play: function () {
  24739. if ( this.isPlaying === true ) {
  24740. console.warn( 'THREE.Audio: Audio is already playing.' );
  24741. return;
  24742. }
  24743. if ( this.hasPlaybackControl === false ) {
  24744. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  24745. return;
  24746. }
  24747. var source = this.context.createBufferSource();
  24748. source.buffer = this.buffer;
  24749. source.loop = this.loop;
  24750. source.onended = this.onEnded.bind( this );
  24751. this.startTime = this.context.currentTime;
  24752. source.start( this.startTime, this.offset );
  24753. this.isPlaying = true;
  24754. this.source = source;
  24755. this.setDetune( this.detune );
  24756. this.setPlaybackRate( this.playbackRate );
  24757. return this.connect();
  24758. },
  24759. pause: function () {
  24760. if ( this.hasPlaybackControl === false ) {
  24761. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  24762. return;
  24763. }
  24764. if ( this.isPlaying === true ) {
  24765. this.source.stop();
  24766. this.source.onended = null;
  24767. this.offset += ( this.context.currentTime - this.startTime ) * this.playbackRate;
  24768. this.isPlaying = false;
  24769. }
  24770. return this;
  24771. },
  24772. stop: function () {
  24773. if ( this.hasPlaybackControl === false ) {
  24774. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  24775. return;
  24776. }
  24777. this.source.stop();
  24778. this.source.onended = null;
  24779. this.offset = 0;
  24780. this.isPlaying = false;
  24781. return this;
  24782. },
  24783. connect: function () {
  24784. if ( this.filters.length > 0 ) {
  24785. this.source.connect( this.filters[ 0 ] );
  24786. for ( var i = 1, l = this.filters.length; i < l; i ++ ) {
  24787. this.filters[ i - 1 ].connect( this.filters[ i ] );
  24788. }
  24789. this.filters[ this.filters.length - 1 ].connect( this.getOutput() );
  24790. } else {
  24791. this.source.connect( this.getOutput() );
  24792. }
  24793. return this;
  24794. },
  24795. disconnect: function () {
  24796. if ( this.filters.length > 0 ) {
  24797. this.source.disconnect( this.filters[ 0 ] );
  24798. for ( var i = 1, l = this.filters.length; i < l; i ++ ) {
  24799. this.filters[ i - 1 ].disconnect( this.filters[ i ] );
  24800. }
  24801. this.filters[ this.filters.length - 1 ].disconnect( this.getOutput() );
  24802. } else {
  24803. this.source.disconnect( this.getOutput() );
  24804. }
  24805. return this;
  24806. },
  24807. getFilters: function () {
  24808. return this.filters;
  24809. },
  24810. setFilters: function ( value ) {
  24811. if ( ! value ) value = [];
  24812. if ( this.isPlaying === true ) {
  24813. this.disconnect();
  24814. this.filters = value;
  24815. this.connect();
  24816. } else {
  24817. this.filters = value;
  24818. }
  24819. return this;
  24820. },
  24821. setDetune: function ( value ) {
  24822. this.detune = value;
  24823. if ( this.source.detune === undefined ) return; // only set detune when available
  24824. if ( this.isPlaying === true ) {
  24825. this.source.detune.setTargetAtTime( this.detune, this.context.currentTime, 0.01 );
  24826. }
  24827. return this;
  24828. },
  24829. getDetune: function () {
  24830. return this.detune;
  24831. },
  24832. getFilter: function () {
  24833. return this.getFilters()[ 0 ];
  24834. },
  24835. setFilter: function ( filter ) {
  24836. return this.setFilters( filter ? [ filter ] : [] );
  24837. },
  24838. setPlaybackRate: function ( value ) {
  24839. if ( this.hasPlaybackControl === false ) {
  24840. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  24841. return;
  24842. }
  24843. this.playbackRate = value;
  24844. if ( this.isPlaying === true ) {
  24845. this.source.playbackRate.setTargetAtTime( this.playbackRate, this.context.currentTime, 0.01 );
  24846. }
  24847. return this;
  24848. },
  24849. getPlaybackRate: function () {
  24850. return this.playbackRate;
  24851. },
  24852. onEnded: function () {
  24853. this.isPlaying = false;
  24854. },
  24855. getLoop: function () {
  24856. if ( this.hasPlaybackControl === false ) {
  24857. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  24858. return false;
  24859. }
  24860. return this.loop;
  24861. },
  24862. setLoop: function ( value ) {
  24863. if ( this.hasPlaybackControl === false ) {
  24864. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  24865. return;
  24866. }
  24867. this.loop = value;
  24868. if ( this.isPlaying === true ) {
  24869. this.source.loop = this.loop;
  24870. }
  24871. return this;
  24872. },
  24873. getVolume: function () {
  24874. return this.gain.gain.value;
  24875. },
  24876. setVolume: function ( value ) {
  24877. this.gain.gain.setTargetAtTime( value, this.context.currentTime, 0.01 );
  24878. return this;
  24879. }
  24880. } );
  24881. /**
  24882. * @author mrdoob / http://mrdoob.com/
  24883. */
  24884. function PositionalAudio( listener ) {
  24885. Audio.call( this, listener );
  24886. this.panner = this.context.createPanner();
  24887. this.panner.panningModel = 'HRTF';
  24888. this.panner.connect( this.gain );
  24889. }
  24890. PositionalAudio.prototype = Object.assign( Object.create( Audio.prototype ), {
  24891. constructor: PositionalAudio,
  24892. getOutput: function () {
  24893. return this.panner;
  24894. },
  24895. getRefDistance: function () {
  24896. return this.panner.refDistance;
  24897. },
  24898. setRefDistance: function ( value ) {
  24899. this.panner.refDistance = value;
  24900. return this;
  24901. },
  24902. getRolloffFactor: function () {
  24903. return this.panner.rolloffFactor;
  24904. },
  24905. setRolloffFactor: function ( value ) {
  24906. this.panner.rolloffFactor = value;
  24907. return this;
  24908. },
  24909. getDistanceModel: function () {
  24910. return this.panner.distanceModel;
  24911. },
  24912. setDistanceModel: function ( value ) {
  24913. this.panner.distanceModel = value;
  24914. return this;
  24915. },
  24916. getMaxDistance: function () {
  24917. return this.panner.maxDistance;
  24918. },
  24919. setMaxDistance: function ( value ) {
  24920. this.panner.maxDistance = value;
  24921. return this;
  24922. },
  24923. setDirectionalCone: function ( coneInnerAngle, coneOuterAngle, coneOuterGain ) {
  24924. this.panner.coneInnerAngle = coneInnerAngle;
  24925. this.panner.coneOuterAngle = coneOuterAngle;
  24926. this.panner.coneOuterGain = coneOuterGain;
  24927. return this;
  24928. },
  24929. updateMatrixWorld: ( function () {
  24930. var position = new Vector3();
  24931. var quaternion = new Quaternion();
  24932. var scale = new Vector3();
  24933. var orientation = new Vector3();
  24934. return function updateMatrixWorld( force ) {
  24935. Object3D.prototype.updateMatrixWorld.call( this, force );
  24936. if ( this.hasPlaybackControl === true && this.isPlaying === false ) return;
  24937. this.matrixWorld.decompose( position, quaternion, scale );
  24938. orientation.set( 0, 0, 1 ).applyQuaternion( quaternion );
  24939. var panner = this.panner;
  24940. if ( panner.positionX ) {
  24941. // code path for Chrome and Firefox (see #14393)
  24942. var endTime = this.context.currentTime + this.listener.timeDelta;
  24943. panner.positionX.linearRampToValueAtTime( position.x, endTime );
  24944. panner.positionY.linearRampToValueAtTime( position.y, endTime );
  24945. panner.positionZ.linearRampToValueAtTime( position.z, endTime );
  24946. panner.orientationX.linearRampToValueAtTime( orientation.x, endTime );
  24947. panner.orientationY.linearRampToValueAtTime( orientation.y, endTime );
  24948. panner.orientationZ.linearRampToValueAtTime( orientation.z, endTime );
  24949. } else {
  24950. panner.setPosition( position.x, position.y, position.z );
  24951. panner.setOrientation( orientation.x, orientation.y, orientation.z );
  24952. }
  24953. };
  24954. } )()
  24955. } );
  24956. /**
  24957. * @author mrdoob / http://mrdoob.com/
  24958. */
  24959. function AudioAnalyser( audio, fftSize ) {
  24960. this.analyser = audio.context.createAnalyser();
  24961. this.analyser.fftSize = fftSize !== undefined ? fftSize : 2048;
  24962. this.data = new Uint8Array( this.analyser.frequencyBinCount );
  24963. audio.getOutput().connect( this.analyser );
  24964. }
  24965. Object.assign( AudioAnalyser.prototype, {
  24966. getFrequencyData: function () {
  24967. this.analyser.getByteFrequencyData( this.data );
  24968. return this.data;
  24969. },
  24970. getAverageFrequency: function () {
  24971. var value = 0, data = this.getFrequencyData();
  24972. for ( var i = 0; i < data.length; i ++ ) {
  24973. value += data[ i ];
  24974. }
  24975. return value / data.length;
  24976. }
  24977. } );
  24978. /**
  24979. *
  24980. * Buffered scene graph property that allows weighted accumulation.
  24981. *
  24982. *
  24983. * @author Ben Houston / http://clara.io/
  24984. * @author David Sarno / http://lighthaus.us/
  24985. * @author tschw
  24986. */
  24987. function PropertyMixer( binding, typeName, valueSize ) {
  24988. this.binding = binding;
  24989. this.valueSize = valueSize;
  24990. var bufferType = Float64Array,
  24991. mixFunction;
  24992. switch ( typeName ) {
  24993. case 'quaternion':
  24994. mixFunction = this._slerp;
  24995. break;
  24996. case 'string':
  24997. case 'bool':
  24998. bufferType = Array;
  24999. mixFunction = this._select;
  25000. break;
  25001. default:
  25002. mixFunction = this._lerp;
  25003. }
  25004. this.buffer = new bufferType( valueSize * 4 );
  25005. // layout: [ incoming | accu0 | accu1 | orig ]
  25006. //
  25007. // interpolators can use .buffer as their .result
  25008. // the data then goes to 'incoming'
  25009. //
  25010. // 'accu0' and 'accu1' are used frame-interleaved for
  25011. // the cumulative result and are compared to detect
  25012. // changes
  25013. //
  25014. // 'orig' stores the original state of the property
  25015. this._mixBufferRegion = mixFunction;
  25016. this.cumulativeWeight = 0;
  25017. this.useCount = 0;
  25018. this.referenceCount = 0;
  25019. }
  25020. Object.assign( PropertyMixer.prototype, {
  25021. // accumulate data in the 'incoming' region into 'accu<i>'
  25022. accumulate: function ( accuIndex, weight ) {
  25023. // note: happily accumulating nothing when weight = 0, the caller knows
  25024. // the weight and shouldn't have made the call in the first place
  25025. var buffer = this.buffer,
  25026. stride = this.valueSize,
  25027. offset = accuIndex * stride + stride,
  25028. currentWeight = this.cumulativeWeight;
  25029. if ( currentWeight === 0 ) {
  25030. // accuN := incoming * weight
  25031. for ( var i = 0; i !== stride; ++ i ) {
  25032. buffer[ offset + i ] = buffer[ i ];
  25033. }
  25034. currentWeight = weight;
  25035. } else {
  25036. // accuN := accuN + incoming * weight
  25037. currentWeight += weight;
  25038. var mix = weight / currentWeight;
  25039. this._mixBufferRegion( buffer, offset, 0, mix, stride );
  25040. }
  25041. this.cumulativeWeight = currentWeight;
  25042. },
  25043. // apply the state of 'accu<i>' to the binding when accus differ
  25044. apply: function ( accuIndex ) {
  25045. var stride = this.valueSize,
  25046. buffer = this.buffer,
  25047. offset = accuIndex * stride + stride,
  25048. weight = this.cumulativeWeight,
  25049. binding = this.binding;
  25050. this.cumulativeWeight = 0;
  25051. if ( weight < 1 ) {
  25052. // accuN := accuN + original * ( 1 - cumulativeWeight )
  25053. var originalValueOffset = stride * 3;
  25054. this._mixBufferRegion(
  25055. buffer, offset, originalValueOffset, 1 - weight, stride );
  25056. }
  25057. for ( var i = stride, e = stride + stride; i !== e; ++ i ) {
  25058. if ( buffer[ i ] !== buffer[ i + stride ] ) {
  25059. // value has changed -> update scene graph
  25060. binding.setValue( buffer, offset );
  25061. break;
  25062. }
  25063. }
  25064. },
  25065. // remember the state of the bound property and copy it to both accus
  25066. saveOriginalState: function () {
  25067. var binding = this.binding;
  25068. var buffer = this.buffer,
  25069. stride = this.valueSize,
  25070. originalValueOffset = stride * 3;
  25071. binding.getValue( buffer, originalValueOffset );
  25072. // accu[0..1] := orig -- initially detect changes against the original
  25073. for ( var i = stride, e = originalValueOffset; i !== e; ++ i ) {
  25074. buffer[ i ] = buffer[ originalValueOffset + ( i % stride ) ];
  25075. }
  25076. this.cumulativeWeight = 0;
  25077. },
  25078. // apply the state previously taken via 'saveOriginalState' to the binding
  25079. restoreOriginalState: function () {
  25080. var originalValueOffset = this.valueSize * 3;
  25081. this.binding.setValue( this.buffer, originalValueOffset );
  25082. },
  25083. // mix functions
  25084. _select: function ( buffer, dstOffset, srcOffset, t, stride ) {
  25085. if ( t >= 0.5 ) {
  25086. for ( var i = 0; i !== stride; ++ i ) {
  25087. buffer[ dstOffset + i ] = buffer[ srcOffset + i ];
  25088. }
  25089. }
  25090. },
  25091. _slerp: function ( buffer, dstOffset, srcOffset, t ) {
  25092. Quaternion.slerpFlat( buffer, dstOffset, buffer, dstOffset, buffer, srcOffset, t );
  25093. },
  25094. _lerp: function ( buffer, dstOffset, srcOffset, t, stride ) {
  25095. var s = 1 - t;
  25096. for ( var i = 0; i !== stride; ++ i ) {
  25097. var j = dstOffset + i;
  25098. buffer[ j ] = buffer[ j ] * s + buffer[ srcOffset + i ] * t;
  25099. }
  25100. }
  25101. } );
  25102. /**
  25103. *
  25104. * A reference to a real property in the scene graph.
  25105. *
  25106. *
  25107. * @author Ben Houston / http://clara.io/
  25108. * @author David Sarno / http://lighthaus.us/
  25109. * @author tschw
  25110. */
  25111. // Characters [].:/ are reserved for track binding syntax.
  25112. var RESERVED_CHARS_RE = '\\[\\]\\.:\\/';
  25113. function Composite( targetGroup, path, optionalParsedPath ) {
  25114. var parsedPath = optionalParsedPath || PropertyBinding.parseTrackName( path );
  25115. this._targetGroup = targetGroup;
  25116. this._bindings = targetGroup.subscribe_( path, parsedPath );
  25117. }
  25118. Object.assign( Composite.prototype, {
  25119. getValue: function ( array, offset ) {
  25120. this.bind(); // bind all binding
  25121. var firstValidIndex = this._targetGroup.nCachedObjects_,
  25122. binding = this._bindings[ firstValidIndex ];
  25123. // and only call .getValue on the first
  25124. if ( binding !== undefined ) binding.getValue( array, offset );
  25125. },
  25126. setValue: function ( array, offset ) {
  25127. var bindings = this._bindings;
  25128. for ( var i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++ i ) {
  25129. bindings[ i ].setValue( array, offset );
  25130. }
  25131. },
  25132. bind: function () {
  25133. var bindings = this._bindings;
  25134. for ( var i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++ i ) {
  25135. bindings[ i ].bind();
  25136. }
  25137. },
  25138. unbind: function () {
  25139. var bindings = this._bindings;
  25140. for ( var i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++ i ) {
  25141. bindings[ i ].unbind();
  25142. }
  25143. }
  25144. } );
  25145. function PropertyBinding( rootNode, path, parsedPath ) {
  25146. this.path = path;
  25147. this.parsedPath = parsedPath || PropertyBinding.parseTrackName( path );
  25148. this.node = PropertyBinding.findNode( rootNode, this.parsedPath.nodeName ) || rootNode;
  25149. this.rootNode = rootNode;
  25150. }
  25151. Object.assign( PropertyBinding, {
  25152. Composite: Composite,
  25153. create: function ( root, path, parsedPath ) {
  25154. if ( ! ( root && root.isAnimationObjectGroup ) ) {
  25155. return new PropertyBinding( root, path, parsedPath );
  25156. } else {
  25157. return new PropertyBinding.Composite( root, path, parsedPath );
  25158. }
  25159. },
  25160. /**
  25161. * Replaces spaces with underscores and removes unsupported characters from
  25162. * node names, to ensure compatibility with parseTrackName().
  25163. *
  25164. * @param {string} name Node name to be sanitized.
  25165. * @return {string}
  25166. */
  25167. sanitizeNodeName: ( function () {
  25168. var reservedRe = new RegExp( '[' + RESERVED_CHARS_RE + ']', 'g' );
  25169. return function sanitizeNodeName( name ) {
  25170. return name.replace( /\s/g, '_' ).replace( reservedRe, '' );
  25171. };
  25172. }() ),
  25173. parseTrackName: function () {
  25174. // Attempts to allow node names from any language. ES5's `\w` regexp matches
  25175. // only latin characters, and the unicode \p{L} is not yet supported. So
  25176. // instead, we exclude reserved characters and match everything else.
  25177. var wordChar = '[^' + RESERVED_CHARS_RE + ']';
  25178. var wordCharOrDot = '[^' + RESERVED_CHARS_RE.replace( '\\.', '' ) + ']';
  25179. // Parent directories, delimited by '/' or ':'. Currently unused, but must
  25180. // be matched to parse the rest of the track name.
  25181. var directoryRe = /((?:WC+[\/:])*)/.source.replace( 'WC', wordChar );
  25182. // Target node. May contain word characters (a-zA-Z0-9_) and '.' or '-'.
  25183. var nodeRe = /(WCOD+)?/.source.replace( 'WCOD', wordCharOrDot );
  25184. // Object on target node, and accessor. May not contain reserved
  25185. // characters. Accessor may contain any character except closing bracket.
  25186. var objectRe = /(?:\.(WC+)(?:\[(.+)\])?)?/.source.replace( 'WC', wordChar );
  25187. // Property and accessor. May not contain reserved characters. Accessor may
  25188. // contain any non-bracket characters.
  25189. var propertyRe = /\.(WC+)(?:\[(.+)\])?/.source.replace( 'WC', wordChar );
  25190. var trackRe = new RegExp( ''
  25191. + '^'
  25192. + directoryRe
  25193. + nodeRe
  25194. + objectRe
  25195. + propertyRe
  25196. + '$'
  25197. );
  25198. var supportedObjectNames = [ 'material', 'materials', 'bones' ];
  25199. return function parseTrackName( trackName ) {
  25200. var matches = trackRe.exec( trackName );
  25201. if ( ! matches ) {
  25202. throw new Error( 'PropertyBinding: Cannot parse trackName: ' + trackName );
  25203. }
  25204. var results = {
  25205. // directoryName: matches[ 1 ], // (tschw) currently unused
  25206. nodeName: matches[ 2 ],
  25207. objectName: matches[ 3 ],
  25208. objectIndex: matches[ 4 ],
  25209. propertyName: matches[ 5 ], // required
  25210. propertyIndex: matches[ 6 ]
  25211. };
  25212. var lastDot = results.nodeName && results.nodeName.lastIndexOf( '.' );
  25213. if ( lastDot !== undefined && lastDot !== - 1 ) {
  25214. var objectName = results.nodeName.substring( lastDot + 1 );
  25215. // Object names must be checked against a whitelist. Otherwise, there
  25216. // is no way to parse 'foo.bar.baz': 'baz' must be a property, but
  25217. // 'bar' could be the objectName, or part of a nodeName (which can
  25218. // include '.' characters).
  25219. if ( supportedObjectNames.indexOf( objectName ) !== - 1 ) {
  25220. results.nodeName = results.nodeName.substring( 0, lastDot );
  25221. results.objectName = objectName;
  25222. }
  25223. }
  25224. if ( results.propertyName === null || results.propertyName.length === 0 ) {
  25225. throw new Error( 'PropertyBinding: can not parse propertyName from trackName: ' + trackName );
  25226. }
  25227. return results;
  25228. };
  25229. }(),
  25230. findNode: function ( root, nodeName ) {
  25231. if ( ! nodeName || nodeName === "" || nodeName === "root" || nodeName === "." || nodeName === - 1 || nodeName === root.name || nodeName === root.uuid ) {
  25232. return root;
  25233. }
  25234. // search into skeleton bones.
  25235. if ( root.skeleton ) {
  25236. var bone = root.skeleton.getBoneByName( nodeName );
  25237. if ( bone !== undefined ) {
  25238. return bone;
  25239. }
  25240. }
  25241. // search into node subtree.
  25242. if ( root.children ) {
  25243. var searchNodeSubtree = function ( children ) {
  25244. for ( var i = 0; i < children.length; i ++ ) {
  25245. var childNode = children[ i ];
  25246. if ( childNode.name === nodeName || childNode.uuid === nodeName ) {
  25247. return childNode;
  25248. }
  25249. var result = searchNodeSubtree( childNode.children );
  25250. if ( result ) return result;
  25251. }
  25252. return null;
  25253. };
  25254. var subTreeNode = searchNodeSubtree( root.children );
  25255. if ( subTreeNode ) {
  25256. return subTreeNode;
  25257. }
  25258. }
  25259. return null;
  25260. }
  25261. } );
  25262. Object.assign( PropertyBinding.prototype, { // prototype, continued
  25263. // these are used to "bind" a nonexistent property
  25264. _getValue_unavailable: function () {},
  25265. _setValue_unavailable: function () {},
  25266. BindingType: {
  25267. Direct: 0,
  25268. EntireArray: 1,
  25269. ArrayElement: 2,
  25270. HasFromToArray: 3
  25271. },
  25272. Versioning: {
  25273. None: 0,
  25274. NeedsUpdate: 1,
  25275. MatrixWorldNeedsUpdate: 2
  25276. },
  25277. GetterByBindingType: [
  25278. function getValue_direct( buffer, offset ) {
  25279. buffer[ offset ] = this.node[ this.propertyName ];
  25280. },
  25281. function getValue_array( buffer, offset ) {
  25282. var source = this.resolvedProperty;
  25283. for ( var i = 0, n = source.length; i !== n; ++ i ) {
  25284. buffer[ offset ++ ] = source[ i ];
  25285. }
  25286. },
  25287. function getValue_arrayElement( buffer, offset ) {
  25288. buffer[ offset ] = this.resolvedProperty[ this.propertyIndex ];
  25289. },
  25290. function getValue_toArray( buffer, offset ) {
  25291. this.resolvedProperty.toArray( buffer, offset );
  25292. }
  25293. ],
  25294. SetterByBindingTypeAndVersioning: [
  25295. [
  25296. // Direct
  25297. function setValue_direct( buffer, offset ) {
  25298. this.targetObject[ this.propertyName ] = buffer[ offset ];
  25299. },
  25300. function setValue_direct_setNeedsUpdate( buffer, offset ) {
  25301. this.targetObject[ this.propertyName ] = buffer[ offset ];
  25302. this.targetObject.needsUpdate = true;
  25303. },
  25304. function setValue_direct_setMatrixWorldNeedsUpdate( buffer, offset ) {
  25305. this.targetObject[ this.propertyName ] = buffer[ offset ];
  25306. this.targetObject.matrixWorldNeedsUpdate = true;
  25307. }
  25308. ], [
  25309. // EntireArray
  25310. function setValue_array( buffer, offset ) {
  25311. var dest = this.resolvedProperty;
  25312. for ( var i = 0, n = dest.length; i !== n; ++ i ) {
  25313. dest[ i ] = buffer[ offset ++ ];
  25314. }
  25315. },
  25316. function setValue_array_setNeedsUpdate( buffer, offset ) {
  25317. var dest = this.resolvedProperty;
  25318. for ( var i = 0, n = dest.length; i !== n; ++ i ) {
  25319. dest[ i ] = buffer[ offset ++ ];
  25320. }
  25321. this.targetObject.needsUpdate = true;
  25322. },
  25323. function setValue_array_setMatrixWorldNeedsUpdate( buffer, offset ) {
  25324. var dest = this.resolvedProperty;
  25325. for ( var i = 0, n = dest.length; i !== n; ++ i ) {
  25326. dest[ i ] = buffer[ offset ++ ];
  25327. }
  25328. this.targetObject.matrixWorldNeedsUpdate = true;
  25329. }
  25330. ], [
  25331. // ArrayElement
  25332. function setValue_arrayElement( buffer, offset ) {
  25333. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  25334. },
  25335. function setValue_arrayElement_setNeedsUpdate( buffer, offset ) {
  25336. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  25337. this.targetObject.needsUpdate = true;
  25338. },
  25339. function setValue_arrayElement_setMatrixWorldNeedsUpdate( buffer, offset ) {
  25340. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  25341. this.targetObject.matrixWorldNeedsUpdate = true;
  25342. }
  25343. ], [
  25344. // HasToFromArray
  25345. function setValue_fromArray( buffer, offset ) {
  25346. this.resolvedProperty.fromArray( buffer, offset );
  25347. },
  25348. function setValue_fromArray_setNeedsUpdate( buffer, offset ) {
  25349. this.resolvedProperty.fromArray( buffer, offset );
  25350. this.targetObject.needsUpdate = true;
  25351. },
  25352. function setValue_fromArray_setMatrixWorldNeedsUpdate( buffer, offset ) {
  25353. this.resolvedProperty.fromArray( buffer, offset );
  25354. this.targetObject.matrixWorldNeedsUpdate = true;
  25355. }
  25356. ]
  25357. ],
  25358. getValue: function getValue_unbound( targetArray, offset ) {
  25359. this.bind();
  25360. this.getValue( targetArray, offset );
  25361. // Note: This class uses a State pattern on a per-method basis:
  25362. // 'bind' sets 'this.getValue' / 'setValue' and shadows the
  25363. // prototype version of these methods with one that represents
  25364. // the bound state. When the property is not found, the methods
  25365. // become no-ops.
  25366. },
  25367. setValue: function getValue_unbound( sourceArray, offset ) {
  25368. this.bind();
  25369. this.setValue( sourceArray, offset );
  25370. },
  25371. // create getter / setter pair for a property in the scene graph
  25372. bind: function () {
  25373. var targetObject = this.node,
  25374. parsedPath = this.parsedPath,
  25375. objectName = parsedPath.objectName,
  25376. propertyName = parsedPath.propertyName,
  25377. propertyIndex = parsedPath.propertyIndex;
  25378. if ( ! targetObject ) {
  25379. targetObject = PropertyBinding.findNode( this.rootNode, parsedPath.nodeName ) || this.rootNode;
  25380. this.node = targetObject;
  25381. }
  25382. // set fail state so we can just 'return' on error
  25383. this.getValue = this._getValue_unavailable;
  25384. this.setValue = this._setValue_unavailable;
  25385. // ensure there is a value node
  25386. if ( ! targetObject ) {
  25387. console.error( 'THREE.PropertyBinding: Trying to update node for track: ' + this.path + ' but it wasn\'t found.' );
  25388. return;
  25389. }
  25390. if ( objectName ) {
  25391. var objectIndex = parsedPath.objectIndex;
  25392. // special cases were we need to reach deeper into the hierarchy to get the face materials....
  25393. switch ( objectName ) {
  25394. case 'materials':
  25395. if ( ! targetObject.material ) {
  25396. console.error( 'THREE.PropertyBinding: Can not bind to material as node does not have a material.', this );
  25397. return;
  25398. }
  25399. if ( ! targetObject.material.materials ) {
  25400. console.error( 'THREE.PropertyBinding: Can not bind to material.materials as node.material does not have a materials array.', this );
  25401. return;
  25402. }
  25403. targetObject = targetObject.material.materials;
  25404. break;
  25405. case 'bones':
  25406. if ( ! targetObject.skeleton ) {
  25407. console.error( 'THREE.PropertyBinding: Can not bind to bones as node does not have a skeleton.', this );
  25408. return;
  25409. }
  25410. // potential future optimization: skip this if propertyIndex is already an integer
  25411. // and convert the integer string to a true integer.
  25412. targetObject = targetObject.skeleton.bones;
  25413. // support resolving morphTarget names into indices.
  25414. for ( var i = 0; i < targetObject.length; i ++ ) {
  25415. if ( targetObject[ i ].name === objectIndex ) {
  25416. objectIndex = i;
  25417. break;
  25418. }
  25419. }
  25420. break;
  25421. default:
  25422. if ( targetObject[ objectName ] === undefined ) {
  25423. console.error( 'THREE.PropertyBinding: Can not bind to objectName of node undefined.', this );
  25424. return;
  25425. }
  25426. targetObject = targetObject[ objectName ];
  25427. }
  25428. if ( objectIndex !== undefined ) {
  25429. if ( targetObject[ objectIndex ] === undefined ) {
  25430. console.error( 'THREE.PropertyBinding: Trying to bind to objectIndex of objectName, but is undefined.', this, targetObject );
  25431. return;
  25432. }
  25433. targetObject = targetObject[ objectIndex ];
  25434. }
  25435. }
  25436. // resolve property
  25437. var nodeProperty = targetObject[ propertyName ];
  25438. if ( nodeProperty === undefined ) {
  25439. var nodeName = parsedPath.nodeName;
  25440. console.error( 'THREE.PropertyBinding: Trying to update property for track: ' + nodeName +
  25441. '.' + propertyName + ' but it wasn\'t found.', targetObject );
  25442. return;
  25443. }
  25444. // determine versioning scheme
  25445. var versioning = this.Versioning.None;
  25446. this.targetObject = targetObject;
  25447. if ( targetObject.needsUpdate !== undefined ) { // material
  25448. versioning = this.Versioning.NeedsUpdate;
  25449. } else if ( targetObject.matrixWorldNeedsUpdate !== undefined ) { // node transform
  25450. versioning = this.Versioning.MatrixWorldNeedsUpdate;
  25451. }
  25452. // determine how the property gets bound
  25453. var bindingType = this.BindingType.Direct;
  25454. if ( propertyIndex !== undefined ) {
  25455. // access a sub element of the property array (only primitives are supported right now)
  25456. if ( propertyName === "morphTargetInfluences" ) {
  25457. // potential optimization, skip this if propertyIndex is already an integer, and convert the integer string to a true integer.
  25458. // support resolving morphTarget names into indices.
  25459. if ( ! targetObject.geometry ) {
  25460. console.error( 'THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.', this );
  25461. return;
  25462. }
  25463. if ( targetObject.geometry.isBufferGeometry ) {
  25464. if ( ! targetObject.geometry.morphAttributes ) {
  25465. console.error( 'THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.morphAttributes.', this );
  25466. return;
  25467. }
  25468. for ( var i = 0; i < this.node.geometry.morphAttributes.position.length; i ++ ) {
  25469. if ( targetObject.geometry.morphAttributes.position[ i ].name === propertyIndex ) {
  25470. propertyIndex = i;
  25471. break;
  25472. }
  25473. }
  25474. } else {
  25475. if ( ! targetObject.geometry.morphTargets ) {
  25476. console.error( 'THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.morphTargets.', this );
  25477. return;
  25478. }
  25479. for ( var i = 0; i < this.node.geometry.morphTargets.length; i ++ ) {
  25480. if ( targetObject.geometry.morphTargets[ i ].name === propertyIndex ) {
  25481. propertyIndex = i;
  25482. break;
  25483. }
  25484. }
  25485. }
  25486. }
  25487. bindingType = this.BindingType.ArrayElement;
  25488. this.resolvedProperty = nodeProperty;
  25489. this.propertyIndex = propertyIndex;
  25490. } else if ( nodeProperty.fromArray !== undefined && nodeProperty.toArray !== undefined ) {
  25491. // must use copy for Object3D.Euler/Quaternion
  25492. bindingType = this.BindingType.HasFromToArray;
  25493. this.resolvedProperty = nodeProperty;
  25494. } else if ( Array.isArray( nodeProperty ) ) {
  25495. bindingType = this.BindingType.EntireArray;
  25496. this.resolvedProperty = nodeProperty;
  25497. } else {
  25498. this.propertyName = propertyName;
  25499. }
  25500. // select getter / setter
  25501. this.getValue = this.GetterByBindingType[ bindingType ];
  25502. this.setValue = this.SetterByBindingTypeAndVersioning[ bindingType ][ versioning ];
  25503. },
  25504. unbind: function () {
  25505. this.node = null;
  25506. // back to the prototype version of getValue / setValue
  25507. // note: avoiding to mutate the shape of 'this' via 'delete'
  25508. this.getValue = this._getValue_unbound;
  25509. this.setValue = this._setValue_unbound;
  25510. }
  25511. } );
  25512. //!\ DECLARE ALIAS AFTER assign prototype !
  25513. Object.assign( PropertyBinding.prototype, {
  25514. // initial state of these methods that calls 'bind'
  25515. _getValue_unbound: PropertyBinding.prototype.getValue,
  25516. _setValue_unbound: PropertyBinding.prototype.setValue,
  25517. } );
  25518. /**
  25519. *
  25520. * A group of objects that receives a shared animation state.
  25521. *
  25522. * Usage:
  25523. *
  25524. * - Add objects you would otherwise pass as 'root' to the
  25525. * constructor or the .clipAction method of AnimationMixer.
  25526. *
  25527. * - Instead pass this object as 'root'.
  25528. *
  25529. * - You can also add and remove objects later when the mixer
  25530. * is running.
  25531. *
  25532. * Note:
  25533. *
  25534. * Objects of this class appear as one object to the mixer,
  25535. * so cache control of the individual objects must be done
  25536. * on the group.
  25537. *
  25538. * Limitation:
  25539. *
  25540. * - The animated properties must be compatible among the
  25541. * all objects in the group.
  25542. *
  25543. * - A single property can either be controlled through a
  25544. * target group or directly, but not both.
  25545. *
  25546. * @author tschw
  25547. */
  25548. function AnimationObjectGroup() {
  25549. this.uuid = _Math.generateUUID();
  25550. // cached objects followed by the active ones
  25551. this._objects = Array.prototype.slice.call( arguments );
  25552. this.nCachedObjects_ = 0; // threshold
  25553. // note: read by PropertyBinding.Composite
  25554. var indices = {};
  25555. this._indicesByUUID = indices; // for bookkeeping
  25556. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  25557. indices[ arguments[ i ].uuid ] = i;
  25558. }
  25559. this._paths = []; // inside: string
  25560. this._parsedPaths = []; // inside: { we don't care, here }
  25561. this._bindings = []; // inside: Array< PropertyBinding >
  25562. this._bindingsIndicesByPath = {}; // inside: indices in these arrays
  25563. var scope = this;
  25564. this.stats = {
  25565. objects: {
  25566. get total() {
  25567. return scope._objects.length;
  25568. },
  25569. get inUse() {
  25570. return this.total - scope.nCachedObjects_;
  25571. }
  25572. },
  25573. get bindingsPerObject() {
  25574. return scope._bindings.length;
  25575. }
  25576. };
  25577. }
  25578. Object.assign( AnimationObjectGroup.prototype, {
  25579. isAnimationObjectGroup: true,
  25580. add: function () {
  25581. var objects = this._objects,
  25582. nObjects = objects.length,
  25583. nCachedObjects = this.nCachedObjects_,
  25584. indicesByUUID = this._indicesByUUID,
  25585. paths = this._paths,
  25586. parsedPaths = this._parsedPaths,
  25587. bindings = this._bindings,
  25588. nBindings = bindings.length,
  25589. knownObject = undefined;
  25590. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  25591. var object = arguments[ i ],
  25592. uuid = object.uuid,
  25593. index = indicesByUUID[ uuid ];
  25594. if ( index === undefined ) {
  25595. // unknown object -> add it to the ACTIVE region
  25596. index = nObjects ++;
  25597. indicesByUUID[ uuid ] = index;
  25598. objects.push( object );
  25599. // accounting is done, now do the same for all bindings
  25600. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  25601. bindings[ j ].push( new PropertyBinding( object, paths[ j ], parsedPaths[ j ] ) );
  25602. }
  25603. } else if ( index < nCachedObjects ) {
  25604. knownObject = objects[ index ];
  25605. // move existing object to the ACTIVE region
  25606. var firstActiveIndex = -- nCachedObjects,
  25607. lastCachedObject = objects[ firstActiveIndex ];
  25608. indicesByUUID[ lastCachedObject.uuid ] = index;
  25609. objects[ index ] = lastCachedObject;
  25610. indicesByUUID[ uuid ] = firstActiveIndex;
  25611. objects[ firstActiveIndex ] = object;
  25612. // accounting is done, now do the same for all bindings
  25613. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  25614. var bindingsForPath = bindings[ j ],
  25615. lastCached = bindingsForPath[ firstActiveIndex ],
  25616. binding = bindingsForPath[ index ];
  25617. bindingsForPath[ index ] = lastCached;
  25618. if ( binding === undefined ) {
  25619. // since we do not bother to create new bindings
  25620. // for objects that are cached, the binding may
  25621. // or may not exist
  25622. binding = new PropertyBinding( object, paths[ j ], parsedPaths[ j ] );
  25623. }
  25624. bindingsForPath[ firstActiveIndex ] = binding;
  25625. }
  25626. } else if ( objects[ index ] !== knownObject ) {
  25627. console.error( 'THREE.AnimationObjectGroup: Different objects with the same UUID ' +
  25628. 'detected. Clean the caches or recreate your infrastructure when reloading scenes.' );
  25629. } // else the object is already where we want it to be
  25630. } // for arguments
  25631. this.nCachedObjects_ = nCachedObjects;
  25632. },
  25633. remove: function () {
  25634. var objects = this._objects,
  25635. nCachedObjects = this.nCachedObjects_,
  25636. indicesByUUID = this._indicesByUUID,
  25637. bindings = this._bindings,
  25638. nBindings = bindings.length;
  25639. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  25640. var object = arguments[ i ],
  25641. uuid = object.uuid,
  25642. index = indicesByUUID[ uuid ];
  25643. if ( index !== undefined && index >= nCachedObjects ) {
  25644. // move existing object into the CACHED region
  25645. var lastCachedIndex = nCachedObjects ++,
  25646. firstActiveObject = objects[ lastCachedIndex ];
  25647. indicesByUUID[ firstActiveObject.uuid ] = index;
  25648. objects[ index ] = firstActiveObject;
  25649. indicesByUUID[ uuid ] = lastCachedIndex;
  25650. objects[ lastCachedIndex ] = object;
  25651. // accounting is done, now do the same for all bindings
  25652. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  25653. var bindingsForPath = bindings[ j ],
  25654. firstActive = bindingsForPath[ lastCachedIndex ],
  25655. binding = bindingsForPath[ index ];
  25656. bindingsForPath[ index ] = firstActive;
  25657. bindingsForPath[ lastCachedIndex ] = binding;
  25658. }
  25659. }
  25660. } // for arguments
  25661. this.nCachedObjects_ = nCachedObjects;
  25662. },
  25663. // remove & forget
  25664. uncache: function () {
  25665. var objects = this._objects,
  25666. nObjects = objects.length,
  25667. nCachedObjects = this.nCachedObjects_,
  25668. indicesByUUID = this._indicesByUUID,
  25669. bindings = this._bindings,
  25670. nBindings = bindings.length;
  25671. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  25672. var object = arguments[ i ],
  25673. uuid = object.uuid,
  25674. index = indicesByUUID[ uuid ];
  25675. if ( index !== undefined ) {
  25676. delete indicesByUUID[ uuid ];
  25677. if ( index < nCachedObjects ) {
  25678. // object is cached, shrink the CACHED region
  25679. var firstActiveIndex = -- nCachedObjects,
  25680. lastCachedObject = objects[ firstActiveIndex ],
  25681. lastIndex = -- nObjects,
  25682. lastObject = objects[ lastIndex ];
  25683. // last cached object takes this object's place
  25684. indicesByUUID[ lastCachedObject.uuid ] = index;
  25685. objects[ index ] = lastCachedObject;
  25686. // last object goes to the activated slot and pop
  25687. indicesByUUID[ lastObject.uuid ] = firstActiveIndex;
  25688. objects[ firstActiveIndex ] = lastObject;
  25689. objects.pop();
  25690. // accounting is done, now do the same for all bindings
  25691. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  25692. var bindingsForPath = bindings[ j ],
  25693. lastCached = bindingsForPath[ firstActiveIndex ],
  25694. last = bindingsForPath[ lastIndex ];
  25695. bindingsForPath[ index ] = lastCached;
  25696. bindingsForPath[ firstActiveIndex ] = last;
  25697. bindingsForPath.pop();
  25698. }
  25699. } else {
  25700. // object is active, just swap with the last and pop
  25701. var lastIndex = -- nObjects,
  25702. lastObject = objects[ lastIndex ];
  25703. indicesByUUID[ lastObject.uuid ] = index;
  25704. objects[ index ] = lastObject;
  25705. objects.pop();
  25706. // accounting is done, now do the same for all bindings
  25707. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  25708. var bindingsForPath = bindings[ j ];
  25709. bindingsForPath[ index ] = bindingsForPath[ lastIndex ];
  25710. bindingsForPath.pop();
  25711. }
  25712. } // cached or active
  25713. } // if object is known
  25714. } // for arguments
  25715. this.nCachedObjects_ = nCachedObjects;
  25716. },
  25717. // Internal interface used by befriended PropertyBinding.Composite:
  25718. subscribe_: function ( path, parsedPath ) {
  25719. // returns an array of bindings for the given path that is changed
  25720. // according to the contained objects in the group
  25721. var indicesByPath = this._bindingsIndicesByPath,
  25722. index = indicesByPath[ path ],
  25723. bindings = this._bindings;
  25724. if ( index !== undefined ) return bindings[ index ];
  25725. var paths = this._paths,
  25726. parsedPaths = this._parsedPaths,
  25727. objects = this._objects,
  25728. nObjects = objects.length,
  25729. nCachedObjects = this.nCachedObjects_,
  25730. bindingsForPath = new Array( nObjects );
  25731. index = bindings.length;
  25732. indicesByPath[ path ] = index;
  25733. paths.push( path );
  25734. parsedPaths.push( parsedPath );
  25735. bindings.push( bindingsForPath );
  25736. for ( var i = nCachedObjects, n = objects.length; i !== n; ++ i ) {
  25737. var object = objects[ i ];
  25738. bindingsForPath[ i ] = new PropertyBinding( object, path, parsedPath );
  25739. }
  25740. return bindingsForPath;
  25741. },
  25742. unsubscribe_: function ( path ) {
  25743. // tells the group to forget about a property path and no longer
  25744. // update the array previously obtained with 'subscribe_'
  25745. var indicesByPath = this._bindingsIndicesByPath,
  25746. index = indicesByPath[ path ];
  25747. if ( index !== undefined ) {
  25748. var paths = this._paths,
  25749. parsedPaths = this._parsedPaths,
  25750. bindings = this._bindings,
  25751. lastBindingsIndex = bindings.length - 1,
  25752. lastBindings = bindings[ lastBindingsIndex ],
  25753. lastBindingsPath = path[ lastBindingsIndex ];
  25754. indicesByPath[ lastBindingsPath ] = index;
  25755. bindings[ index ] = lastBindings;
  25756. bindings.pop();
  25757. parsedPaths[ index ] = parsedPaths[ lastBindingsIndex ];
  25758. parsedPaths.pop();
  25759. paths[ index ] = paths[ lastBindingsIndex ];
  25760. paths.pop();
  25761. }
  25762. }
  25763. } );
  25764. /**
  25765. *
  25766. * Action provided by AnimationMixer for scheduling clip playback on specific
  25767. * objects.
  25768. *
  25769. * @author Ben Houston / http://clara.io/
  25770. * @author David Sarno / http://lighthaus.us/
  25771. * @author tschw
  25772. *
  25773. */
  25774. function AnimationAction( mixer, clip, localRoot ) {
  25775. this._mixer = mixer;
  25776. this._clip = clip;
  25777. this._localRoot = localRoot || null;
  25778. var tracks = clip.tracks,
  25779. nTracks = tracks.length,
  25780. interpolants = new Array( nTracks );
  25781. var interpolantSettings = {
  25782. endingStart: ZeroCurvatureEnding,
  25783. endingEnd: ZeroCurvatureEnding
  25784. };
  25785. for ( var i = 0; i !== nTracks; ++ i ) {
  25786. var interpolant = tracks[ i ].createInterpolant( null );
  25787. interpolants[ i ] = interpolant;
  25788. interpolant.settings = interpolantSettings;
  25789. }
  25790. this._interpolantSettings = interpolantSettings;
  25791. this._interpolants = interpolants; // bound by the mixer
  25792. // inside: PropertyMixer (managed by the mixer)
  25793. this._propertyBindings = new Array( nTracks );
  25794. this._cacheIndex = null; // for the memory manager
  25795. this._byClipCacheIndex = null; // for the memory manager
  25796. this._timeScaleInterpolant = null;
  25797. this._weightInterpolant = null;
  25798. this.loop = LoopRepeat;
  25799. this._loopCount = - 1;
  25800. // global mixer time when the action is to be started
  25801. // it's set back to 'null' upon start of the action
  25802. this._startTime = null;
  25803. // scaled local time of the action
  25804. // gets clamped or wrapped to 0..clip.duration according to loop
  25805. this.time = 0;
  25806. this.timeScale = 1;
  25807. this._effectiveTimeScale = 1;
  25808. this.weight = 1;
  25809. this._effectiveWeight = 1;
  25810. this.repetitions = Infinity; // no. of repetitions when looping
  25811. this.paused = false; // true -> zero effective time scale
  25812. this.enabled = true; // false -> zero effective weight
  25813. this.clampWhenFinished = false;// keep feeding the last frame?
  25814. this.zeroSlopeAtStart = true;// for smooth interpolation w/o separate
  25815. this.zeroSlopeAtEnd = true;// clips for start, loop and end
  25816. }
  25817. Object.assign( AnimationAction.prototype, {
  25818. // State & Scheduling
  25819. play: function () {
  25820. this._mixer._activateAction( this );
  25821. return this;
  25822. },
  25823. stop: function () {
  25824. this._mixer._deactivateAction( this );
  25825. return this.reset();
  25826. },
  25827. reset: function () {
  25828. this.paused = false;
  25829. this.enabled = true;
  25830. this.time = 0; // restart clip
  25831. this._loopCount = - 1;// forget previous loops
  25832. this._startTime = null;// forget scheduling
  25833. return this.stopFading().stopWarping();
  25834. },
  25835. isRunning: function () {
  25836. return this.enabled && ! this.paused && this.timeScale !== 0 &&
  25837. this._startTime === null && this._mixer._isActiveAction( this );
  25838. },
  25839. // return true when play has been called
  25840. isScheduled: function () {
  25841. return this._mixer._isActiveAction( this );
  25842. },
  25843. startAt: function ( time ) {
  25844. this._startTime = time;
  25845. return this;
  25846. },
  25847. setLoop: function ( mode, repetitions ) {
  25848. this.loop = mode;
  25849. this.repetitions = repetitions;
  25850. return this;
  25851. },
  25852. // Weight
  25853. // set the weight stopping any scheduled fading
  25854. // although .enabled = false yields an effective weight of zero, this
  25855. // method does *not* change .enabled, because it would be confusing
  25856. setEffectiveWeight: function ( weight ) {
  25857. this.weight = weight;
  25858. // note: same logic as when updated at runtime
  25859. this._effectiveWeight = this.enabled ? weight : 0;
  25860. return this.stopFading();
  25861. },
  25862. // return the weight considering fading and .enabled
  25863. getEffectiveWeight: function () {
  25864. return this._effectiveWeight;
  25865. },
  25866. fadeIn: function ( duration ) {
  25867. return this._scheduleFading( duration, 0, 1 );
  25868. },
  25869. fadeOut: function ( duration ) {
  25870. return this._scheduleFading( duration, 1, 0 );
  25871. },
  25872. crossFadeFrom: function ( fadeOutAction, duration, warp ) {
  25873. fadeOutAction.fadeOut( duration );
  25874. this.fadeIn( duration );
  25875. if ( warp ) {
  25876. var fadeInDuration = this._clip.duration,
  25877. fadeOutDuration = fadeOutAction._clip.duration,
  25878. startEndRatio = fadeOutDuration / fadeInDuration,
  25879. endStartRatio = fadeInDuration / fadeOutDuration;
  25880. fadeOutAction.warp( 1.0, startEndRatio, duration );
  25881. this.warp( endStartRatio, 1.0, duration );
  25882. }
  25883. return this;
  25884. },
  25885. crossFadeTo: function ( fadeInAction, duration, warp ) {
  25886. return fadeInAction.crossFadeFrom( this, duration, warp );
  25887. },
  25888. stopFading: function () {
  25889. var weightInterpolant = this._weightInterpolant;
  25890. if ( weightInterpolant !== null ) {
  25891. this._weightInterpolant = null;
  25892. this._mixer._takeBackControlInterpolant( weightInterpolant );
  25893. }
  25894. return this;
  25895. },
  25896. // Time Scale Control
  25897. // set the time scale stopping any scheduled warping
  25898. // although .paused = true yields an effective time scale of zero, this
  25899. // method does *not* change .paused, because it would be confusing
  25900. setEffectiveTimeScale: function ( timeScale ) {
  25901. this.timeScale = timeScale;
  25902. this._effectiveTimeScale = this.paused ? 0 : timeScale;
  25903. return this.stopWarping();
  25904. },
  25905. // return the time scale considering warping and .paused
  25906. getEffectiveTimeScale: function () {
  25907. return this._effectiveTimeScale;
  25908. },
  25909. setDuration: function ( duration ) {
  25910. this.timeScale = this._clip.duration / duration;
  25911. return this.stopWarping();
  25912. },
  25913. syncWith: function ( action ) {
  25914. this.time = action.time;
  25915. this.timeScale = action.timeScale;
  25916. return this.stopWarping();
  25917. },
  25918. halt: function ( duration ) {
  25919. return this.warp( this._effectiveTimeScale, 0, duration );
  25920. },
  25921. warp: function ( startTimeScale, endTimeScale, duration ) {
  25922. var mixer = this._mixer, now = mixer.time,
  25923. interpolant = this._timeScaleInterpolant,
  25924. timeScale = this.timeScale;
  25925. if ( interpolant === null ) {
  25926. interpolant = mixer._lendControlInterpolant();
  25927. this._timeScaleInterpolant = interpolant;
  25928. }
  25929. var times = interpolant.parameterPositions,
  25930. values = interpolant.sampleValues;
  25931. times[ 0 ] = now;
  25932. times[ 1 ] = now + duration;
  25933. values[ 0 ] = startTimeScale / timeScale;
  25934. values[ 1 ] = endTimeScale / timeScale;
  25935. return this;
  25936. },
  25937. stopWarping: function () {
  25938. var timeScaleInterpolant = this._timeScaleInterpolant;
  25939. if ( timeScaleInterpolant !== null ) {
  25940. this._timeScaleInterpolant = null;
  25941. this._mixer._takeBackControlInterpolant( timeScaleInterpolant );
  25942. }
  25943. return this;
  25944. },
  25945. // Object Accessors
  25946. getMixer: function () {
  25947. return this._mixer;
  25948. },
  25949. getClip: function () {
  25950. return this._clip;
  25951. },
  25952. getRoot: function () {
  25953. return this._localRoot || this._mixer._root;
  25954. },
  25955. // Interna
  25956. _update: function ( time, deltaTime, timeDirection, accuIndex ) {
  25957. // called by the mixer
  25958. if ( ! this.enabled ) {
  25959. // call ._updateWeight() to update ._effectiveWeight
  25960. this._updateWeight( time );
  25961. return;
  25962. }
  25963. var startTime = this._startTime;
  25964. if ( startTime !== null ) {
  25965. // check for scheduled start of action
  25966. var timeRunning = ( time - startTime ) * timeDirection;
  25967. if ( timeRunning < 0 || timeDirection === 0 ) {
  25968. return; // yet to come / don't decide when delta = 0
  25969. }
  25970. // start
  25971. this._startTime = null; // unschedule
  25972. deltaTime = timeDirection * timeRunning;
  25973. }
  25974. // apply time scale and advance time
  25975. deltaTime *= this._updateTimeScale( time );
  25976. var clipTime = this._updateTime( deltaTime );
  25977. // note: _updateTime may disable the action resulting in
  25978. // an effective weight of 0
  25979. var weight = this._updateWeight( time );
  25980. if ( weight > 0 ) {
  25981. var interpolants = this._interpolants;
  25982. var propertyMixers = this._propertyBindings;
  25983. for ( var j = 0, m = interpolants.length; j !== m; ++ j ) {
  25984. interpolants[ j ].evaluate( clipTime );
  25985. propertyMixers[ j ].accumulate( accuIndex, weight );
  25986. }
  25987. }
  25988. },
  25989. _updateWeight: function ( time ) {
  25990. var weight = 0;
  25991. if ( this.enabled ) {
  25992. weight = this.weight;
  25993. var interpolant = this._weightInterpolant;
  25994. if ( interpolant !== null ) {
  25995. var interpolantValue = interpolant.evaluate( time )[ 0 ];
  25996. weight *= interpolantValue;
  25997. if ( time > interpolant.parameterPositions[ 1 ] ) {
  25998. this.stopFading();
  25999. if ( interpolantValue === 0 ) {
  26000. // faded out, disable
  26001. this.enabled = false;
  26002. }
  26003. }
  26004. }
  26005. }
  26006. this._effectiveWeight = weight;
  26007. return weight;
  26008. },
  26009. _updateTimeScale: function ( time ) {
  26010. var timeScale = 0;
  26011. if ( ! this.paused ) {
  26012. timeScale = this.timeScale;
  26013. var interpolant = this._timeScaleInterpolant;
  26014. if ( interpolant !== null ) {
  26015. var interpolantValue = interpolant.evaluate( time )[ 0 ];
  26016. timeScale *= interpolantValue;
  26017. if ( time > interpolant.parameterPositions[ 1 ] ) {
  26018. this.stopWarping();
  26019. if ( timeScale === 0 ) {
  26020. // motion has halted, pause
  26021. this.paused = true;
  26022. } else {
  26023. // warp done - apply final time scale
  26024. this.timeScale = timeScale;
  26025. }
  26026. }
  26027. }
  26028. }
  26029. this._effectiveTimeScale = timeScale;
  26030. return timeScale;
  26031. },
  26032. _updateTime: function ( deltaTime ) {
  26033. var time = this.time + deltaTime;
  26034. var duration = this._clip.duration;
  26035. var loop = this.loop;
  26036. var loopCount = this._loopCount;
  26037. var pingPong = ( loop === LoopPingPong );
  26038. if ( deltaTime === 0 ) {
  26039. if ( loopCount === - 1 ) return time;
  26040. return ( pingPong && ( loopCount & 1 ) === 1 ) ? duration - time : time;
  26041. }
  26042. if ( loop === LoopOnce ) {
  26043. if ( loopCount === - 1 ) {
  26044. // just started
  26045. this._loopCount = 0;
  26046. this._setEndings( true, true, false );
  26047. }
  26048. handle_stop: {
  26049. if ( time >= duration ) {
  26050. time = duration;
  26051. } else if ( time < 0 ) {
  26052. time = 0;
  26053. } else {
  26054. this.time = time;
  26055. break handle_stop;
  26056. }
  26057. if ( this.clampWhenFinished ) this.paused = true;
  26058. else this.enabled = false;
  26059. this.time = time;
  26060. this._mixer.dispatchEvent( {
  26061. type: 'finished', action: this,
  26062. direction: deltaTime < 0 ? - 1 : 1
  26063. } );
  26064. }
  26065. } else { // repetitive Repeat or PingPong
  26066. if ( loopCount === - 1 ) {
  26067. // just started
  26068. if ( deltaTime >= 0 ) {
  26069. loopCount = 0;
  26070. this._setEndings( true, this.repetitions === 0, pingPong );
  26071. } else {
  26072. // when looping in reverse direction, the initial
  26073. // transition through zero counts as a repetition,
  26074. // so leave loopCount at -1
  26075. this._setEndings( this.repetitions === 0, true, pingPong );
  26076. }
  26077. }
  26078. if ( time >= duration || time < 0 ) {
  26079. // wrap around
  26080. var loopDelta = Math.floor( time / duration ); // signed
  26081. time -= duration * loopDelta;
  26082. loopCount += Math.abs( loopDelta );
  26083. var pending = this.repetitions - loopCount;
  26084. if ( pending <= 0 ) {
  26085. // have to stop (switch state, clamp time, fire event)
  26086. if ( this.clampWhenFinished ) this.paused = true;
  26087. else this.enabled = false;
  26088. time = deltaTime > 0 ? duration : 0;
  26089. this.time = time;
  26090. this._mixer.dispatchEvent( {
  26091. type: 'finished', action: this,
  26092. direction: deltaTime > 0 ? 1 : - 1
  26093. } );
  26094. } else {
  26095. // keep running
  26096. if ( pending === 1 ) {
  26097. // entering the last round
  26098. var atStart = deltaTime < 0;
  26099. this._setEndings( atStart, ! atStart, pingPong );
  26100. } else {
  26101. this._setEndings( false, false, pingPong );
  26102. }
  26103. this._loopCount = loopCount;
  26104. this.time = time;
  26105. this._mixer.dispatchEvent( {
  26106. type: 'loop', action: this, loopDelta: loopDelta
  26107. } );
  26108. }
  26109. } else {
  26110. this.time = time;
  26111. }
  26112. if ( pingPong && ( loopCount & 1 ) === 1 ) {
  26113. // invert time for the "pong round"
  26114. return duration - time;
  26115. }
  26116. }
  26117. return time;
  26118. },
  26119. _setEndings: function ( atStart, atEnd, pingPong ) {
  26120. var settings = this._interpolantSettings;
  26121. if ( pingPong ) {
  26122. settings.endingStart = ZeroSlopeEnding;
  26123. settings.endingEnd = ZeroSlopeEnding;
  26124. } else {
  26125. // assuming for LoopOnce atStart == atEnd == true
  26126. if ( atStart ) {
  26127. settings.endingStart = this.zeroSlopeAtStart ? ZeroSlopeEnding : ZeroCurvatureEnding;
  26128. } else {
  26129. settings.endingStart = WrapAroundEnding;
  26130. }
  26131. if ( atEnd ) {
  26132. settings.endingEnd = this.zeroSlopeAtEnd ? ZeroSlopeEnding : ZeroCurvatureEnding;
  26133. } else {
  26134. settings.endingEnd = WrapAroundEnding;
  26135. }
  26136. }
  26137. },
  26138. _scheduleFading: function ( duration, weightNow, weightThen ) {
  26139. var mixer = this._mixer, now = mixer.time,
  26140. interpolant = this._weightInterpolant;
  26141. if ( interpolant === null ) {
  26142. interpolant = mixer._lendControlInterpolant();
  26143. this._weightInterpolant = interpolant;
  26144. }
  26145. var times = interpolant.parameterPositions,
  26146. values = interpolant.sampleValues;
  26147. times[ 0 ] = now;
  26148. values[ 0 ] = weightNow;
  26149. times[ 1 ] = now + duration;
  26150. values[ 1 ] = weightThen;
  26151. return this;
  26152. }
  26153. } );
  26154. /**
  26155. *
  26156. * Player for AnimationClips.
  26157. *
  26158. *
  26159. * @author Ben Houston / http://clara.io/
  26160. * @author David Sarno / http://lighthaus.us/
  26161. * @author tschw
  26162. */
  26163. function AnimationMixer( root ) {
  26164. this._root = root;
  26165. this._initMemoryManager();
  26166. this._accuIndex = 0;
  26167. this.time = 0;
  26168. this.timeScale = 1.0;
  26169. }
  26170. AnimationMixer.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  26171. constructor: AnimationMixer,
  26172. _bindAction: function ( action, prototypeAction ) {
  26173. var root = action._localRoot || this._root,
  26174. tracks = action._clip.tracks,
  26175. nTracks = tracks.length,
  26176. bindings = action._propertyBindings,
  26177. interpolants = action._interpolants,
  26178. rootUuid = root.uuid,
  26179. bindingsByRoot = this._bindingsByRootAndName,
  26180. bindingsByName = bindingsByRoot[ rootUuid ];
  26181. if ( bindingsByName === undefined ) {
  26182. bindingsByName = {};
  26183. bindingsByRoot[ rootUuid ] = bindingsByName;
  26184. }
  26185. for ( var i = 0; i !== nTracks; ++ i ) {
  26186. var track = tracks[ i ],
  26187. trackName = track.name,
  26188. binding = bindingsByName[ trackName ];
  26189. if ( binding !== undefined ) {
  26190. bindings[ i ] = binding;
  26191. } else {
  26192. binding = bindings[ i ];
  26193. if ( binding !== undefined ) {
  26194. // existing binding, make sure the cache knows
  26195. if ( binding._cacheIndex === null ) {
  26196. ++ binding.referenceCount;
  26197. this._addInactiveBinding( binding, rootUuid, trackName );
  26198. }
  26199. continue;
  26200. }
  26201. var path = prototypeAction && prototypeAction.
  26202. _propertyBindings[ i ].binding.parsedPath;
  26203. binding = new PropertyMixer(
  26204. PropertyBinding.create( root, trackName, path ),
  26205. track.ValueTypeName, track.getValueSize() );
  26206. ++ binding.referenceCount;
  26207. this._addInactiveBinding( binding, rootUuid, trackName );
  26208. bindings[ i ] = binding;
  26209. }
  26210. interpolants[ i ].resultBuffer = binding.buffer;
  26211. }
  26212. },
  26213. _activateAction: function ( action ) {
  26214. if ( ! this._isActiveAction( action ) ) {
  26215. if ( action._cacheIndex === null ) {
  26216. // this action has been forgotten by the cache, but the user
  26217. // appears to be still using it -> rebind
  26218. var rootUuid = ( action._localRoot || this._root ).uuid,
  26219. clipUuid = action._clip.uuid,
  26220. actionsForClip = this._actionsByClip[ clipUuid ];
  26221. this._bindAction( action,
  26222. actionsForClip && actionsForClip.knownActions[ 0 ] );
  26223. this._addInactiveAction( action, clipUuid, rootUuid );
  26224. }
  26225. var bindings = action._propertyBindings;
  26226. // increment reference counts / sort out state
  26227. for ( var i = 0, n = bindings.length; i !== n; ++ i ) {
  26228. var binding = bindings[ i ];
  26229. if ( binding.useCount ++ === 0 ) {
  26230. this._lendBinding( binding );
  26231. binding.saveOriginalState();
  26232. }
  26233. }
  26234. this._lendAction( action );
  26235. }
  26236. },
  26237. _deactivateAction: function ( action ) {
  26238. if ( this._isActiveAction( action ) ) {
  26239. var bindings = action._propertyBindings;
  26240. // decrement reference counts / sort out state
  26241. for ( var i = 0, n = bindings.length; i !== n; ++ i ) {
  26242. var binding = bindings[ i ];
  26243. if ( -- binding.useCount === 0 ) {
  26244. binding.restoreOriginalState();
  26245. this._takeBackBinding( binding );
  26246. }
  26247. }
  26248. this._takeBackAction( action );
  26249. }
  26250. },
  26251. // Memory manager
  26252. _initMemoryManager: function () {
  26253. this._actions = []; // 'nActiveActions' followed by inactive ones
  26254. this._nActiveActions = 0;
  26255. this._actionsByClip = {};
  26256. // inside:
  26257. // {
  26258. // knownActions: Array< AnimationAction > - used as prototypes
  26259. // actionByRoot: AnimationAction - lookup
  26260. // }
  26261. this._bindings = []; // 'nActiveBindings' followed by inactive ones
  26262. this._nActiveBindings = 0;
  26263. this._bindingsByRootAndName = {}; // inside: Map< name, PropertyMixer >
  26264. this._controlInterpolants = []; // same game as above
  26265. this._nActiveControlInterpolants = 0;
  26266. var scope = this;
  26267. this.stats = {
  26268. actions: {
  26269. get total() {
  26270. return scope._actions.length;
  26271. },
  26272. get inUse() {
  26273. return scope._nActiveActions;
  26274. }
  26275. },
  26276. bindings: {
  26277. get total() {
  26278. return scope._bindings.length;
  26279. },
  26280. get inUse() {
  26281. return scope._nActiveBindings;
  26282. }
  26283. },
  26284. controlInterpolants: {
  26285. get total() {
  26286. return scope._controlInterpolants.length;
  26287. },
  26288. get inUse() {
  26289. return scope._nActiveControlInterpolants;
  26290. }
  26291. }
  26292. };
  26293. },
  26294. // Memory management for AnimationAction objects
  26295. _isActiveAction: function ( action ) {
  26296. var index = action._cacheIndex;
  26297. return index !== null && index < this._nActiveActions;
  26298. },
  26299. _addInactiveAction: function ( action, clipUuid, rootUuid ) {
  26300. var actions = this._actions,
  26301. actionsByClip = this._actionsByClip,
  26302. actionsForClip = actionsByClip[ clipUuid ];
  26303. if ( actionsForClip === undefined ) {
  26304. actionsForClip = {
  26305. knownActions: [ action ],
  26306. actionByRoot: {}
  26307. };
  26308. action._byClipCacheIndex = 0;
  26309. actionsByClip[ clipUuid ] = actionsForClip;
  26310. } else {
  26311. var knownActions = actionsForClip.knownActions;
  26312. action._byClipCacheIndex = knownActions.length;
  26313. knownActions.push( action );
  26314. }
  26315. action._cacheIndex = actions.length;
  26316. actions.push( action );
  26317. actionsForClip.actionByRoot[ rootUuid ] = action;
  26318. },
  26319. _removeInactiveAction: function ( action ) {
  26320. var actions = this._actions,
  26321. lastInactiveAction = actions[ actions.length - 1 ],
  26322. cacheIndex = action._cacheIndex;
  26323. lastInactiveAction._cacheIndex = cacheIndex;
  26324. actions[ cacheIndex ] = lastInactiveAction;
  26325. actions.pop();
  26326. action._cacheIndex = null;
  26327. var clipUuid = action._clip.uuid,
  26328. actionsByClip = this._actionsByClip,
  26329. actionsForClip = actionsByClip[ clipUuid ],
  26330. knownActionsForClip = actionsForClip.knownActions,
  26331. lastKnownAction =
  26332. knownActionsForClip[ knownActionsForClip.length - 1 ],
  26333. byClipCacheIndex = action._byClipCacheIndex;
  26334. lastKnownAction._byClipCacheIndex = byClipCacheIndex;
  26335. knownActionsForClip[ byClipCacheIndex ] = lastKnownAction;
  26336. knownActionsForClip.pop();
  26337. action._byClipCacheIndex = null;
  26338. var actionByRoot = actionsForClip.actionByRoot,
  26339. rootUuid = ( action._localRoot || this._root ).uuid;
  26340. delete actionByRoot[ rootUuid ];
  26341. if ( knownActionsForClip.length === 0 ) {
  26342. delete actionsByClip[ clipUuid ];
  26343. }
  26344. this._removeInactiveBindingsForAction( action );
  26345. },
  26346. _removeInactiveBindingsForAction: function ( action ) {
  26347. var bindings = action._propertyBindings;
  26348. for ( var i = 0, n = bindings.length; i !== n; ++ i ) {
  26349. var binding = bindings[ i ];
  26350. if ( -- binding.referenceCount === 0 ) {
  26351. this._removeInactiveBinding( binding );
  26352. }
  26353. }
  26354. },
  26355. _lendAction: function ( action ) {
  26356. // [ active actions | inactive actions ]
  26357. // [ active actions >| inactive actions ]
  26358. // s a
  26359. // <-swap->
  26360. // a s
  26361. var actions = this._actions,
  26362. prevIndex = action._cacheIndex,
  26363. lastActiveIndex = this._nActiveActions ++,
  26364. firstInactiveAction = actions[ lastActiveIndex ];
  26365. action._cacheIndex = lastActiveIndex;
  26366. actions[ lastActiveIndex ] = action;
  26367. firstInactiveAction._cacheIndex = prevIndex;
  26368. actions[ prevIndex ] = firstInactiveAction;
  26369. },
  26370. _takeBackAction: function ( action ) {
  26371. // [ active actions | inactive actions ]
  26372. // [ active actions |< inactive actions ]
  26373. // a s
  26374. // <-swap->
  26375. // s a
  26376. var actions = this._actions,
  26377. prevIndex = action._cacheIndex,
  26378. firstInactiveIndex = -- this._nActiveActions,
  26379. lastActiveAction = actions[ firstInactiveIndex ];
  26380. action._cacheIndex = firstInactiveIndex;
  26381. actions[ firstInactiveIndex ] = action;
  26382. lastActiveAction._cacheIndex = prevIndex;
  26383. actions[ prevIndex ] = lastActiveAction;
  26384. },
  26385. // Memory management for PropertyMixer objects
  26386. _addInactiveBinding: function ( binding, rootUuid, trackName ) {
  26387. var bindingsByRoot = this._bindingsByRootAndName,
  26388. bindingByName = bindingsByRoot[ rootUuid ],
  26389. bindings = this._bindings;
  26390. if ( bindingByName === undefined ) {
  26391. bindingByName = {};
  26392. bindingsByRoot[ rootUuid ] = bindingByName;
  26393. }
  26394. bindingByName[ trackName ] = binding;
  26395. binding._cacheIndex = bindings.length;
  26396. bindings.push( binding );
  26397. },
  26398. _removeInactiveBinding: function ( binding ) {
  26399. var bindings = this._bindings,
  26400. propBinding = binding.binding,
  26401. rootUuid = propBinding.rootNode.uuid,
  26402. trackName = propBinding.path,
  26403. bindingsByRoot = this._bindingsByRootAndName,
  26404. bindingByName = bindingsByRoot[ rootUuid ],
  26405. lastInactiveBinding = bindings[ bindings.length - 1 ],
  26406. cacheIndex = binding._cacheIndex;
  26407. lastInactiveBinding._cacheIndex = cacheIndex;
  26408. bindings[ cacheIndex ] = lastInactiveBinding;
  26409. bindings.pop();
  26410. delete bindingByName[ trackName ];
  26411. if ( Object.keys( bindingByName ).length === 0 ) {
  26412. delete bindingsByRoot[ rootUuid ];
  26413. }
  26414. },
  26415. _lendBinding: function ( binding ) {
  26416. var bindings = this._bindings,
  26417. prevIndex = binding._cacheIndex,
  26418. lastActiveIndex = this._nActiveBindings ++,
  26419. firstInactiveBinding = bindings[ lastActiveIndex ];
  26420. binding._cacheIndex = lastActiveIndex;
  26421. bindings[ lastActiveIndex ] = binding;
  26422. firstInactiveBinding._cacheIndex = prevIndex;
  26423. bindings[ prevIndex ] = firstInactiveBinding;
  26424. },
  26425. _takeBackBinding: function ( binding ) {
  26426. var bindings = this._bindings,
  26427. prevIndex = binding._cacheIndex,
  26428. firstInactiveIndex = -- this._nActiveBindings,
  26429. lastActiveBinding = bindings[ firstInactiveIndex ];
  26430. binding._cacheIndex = firstInactiveIndex;
  26431. bindings[ firstInactiveIndex ] = binding;
  26432. lastActiveBinding._cacheIndex = prevIndex;
  26433. bindings[ prevIndex ] = lastActiveBinding;
  26434. },
  26435. // Memory management of Interpolants for weight and time scale
  26436. _lendControlInterpolant: function () {
  26437. var interpolants = this._controlInterpolants,
  26438. lastActiveIndex = this._nActiveControlInterpolants ++,
  26439. interpolant = interpolants[ lastActiveIndex ];
  26440. if ( interpolant === undefined ) {
  26441. interpolant = new LinearInterpolant(
  26442. new Float32Array( 2 ), new Float32Array( 2 ),
  26443. 1, this._controlInterpolantsResultBuffer );
  26444. interpolant.__cacheIndex = lastActiveIndex;
  26445. interpolants[ lastActiveIndex ] = interpolant;
  26446. }
  26447. return interpolant;
  26448. },
  26449. _takeBackControlInterpolant: function ( interpolant ) {
  26450. var interpolants = this._controlInterpolants,
  26451. prevIndex = interpolant.__cacheIndex,
  26452. firstInactiveIndex = -- this._nActiveControlInterpolants,
  26453. lastActiveInterpolant = interpolants[ firstInactiveIndex ];
  26454. interpolant.__cacheIndex = firstInactiveIndex;
  26455. interpolants[ firstInactiveIndex ] = interpolant;
  26456. lastActiveInterpolant.__cacheIndex = prevIndex;
  26457. interpolants[ prevIndex ] = lastActiveInterpolant;
  26458. },
  26459. _controlInterpolantsResultBuffer: new Float32Array( 1 ),
  26460. // return an action for a clip optionally using a custom root target
  26461. // object (this method allocates a lot of dynamic memory in case a
  26462. // previously unknown clip/root combination is specified)
  26463. clipAction: function ( clip, optionalRoot ) {
  26464. var root = optionalRoot || this._root,
  26465. rootUuid = root.uuid,
  26466. clipObject = typeof clip === 'string' ?
  26467. AnimationClip.findByName( root, clip ) : clip,
  26468. clipUuid = clipObject !== null ? clipObject.uuid : clip,
  26469. actionsForClip = this._actionsByClip[ clipUuid ],
  26470. prototypeAction = null;
  26471. if ( actionsForClip !== undefined ) {
  26472. var existingAction =
  26473. actionsForClip.actionByRoot[ rootUuid ];
  26474. if ( existingAction !== undefined ) {
  26475. return existingAction;
  26476. }
  26477. // we know the clip, so we don't have to parse all
  26478. // the bindings again but can just copy
  26479. prototypeAction = actionsForClip.knownActions[ 0 ];
  26480. // also, take the clip from the prototype action
  26481. if ( clipObject === null )
  26482. clipObject = prototypeAction._clip;
  26483. }
  26484. // clip must be known when specified via string
  26485. if ( clipObject === null ) return null;
  26486. // allocate all resources required to run it
  26487. var newAction = new AnimationAction( this, clipObject, optionalRoot );
  26488. this._bindAction( newAction, prototypeAction );
  26489. // and make the action known to the memory manager
  26490. this._addInactiveAction( newAction, clipUuid, rootUuid );
  26491. return newAction;
  26492. },
  26493. // get an existing action
  26494. existingAction: function ( clip, optionalRoot ) {
  26495. var root = optionalRoot || this._root,
  26496. rootUuid = root.uuid,
  26497. clipObject = typeof clip === 'string' ?
  26498. AnimationClip.findByName( root, clip ) : clip,
  26499. clipUuid = clipObject ? clipObject.uuid : clip,
  26500. actionsForClip = this._actionsByClip[ clipUuid ];
  26501. if ( actionsForClip !== undefined ) {
  26502. return actionsForClip.actionByRoot[ rootUuid ] || null;
  26503. }
  26504. return null;
  26505. },
  26506. // deactivates all previously scheduled actions
  26507. stopAllAction: function () {
  26508. var actions = this._actions,
  26509. nActions = this._nActiveActions,
  26510. bindings = this._bindings,
  26511. nBindings = this._nActiveBindings;
  26512. this._nActiveActions = 0;
  26513. this._nActiveBindings = 0;
  26514. for ( var i = 0; i !== nActions; ++ i ) {
  26515. actions[ i ].reset();
  26516. }
  26517. for ( var i = 0; i !== nBindings; ++ i ) {
  26518. bindings[ i ].useCount = 0;
  26519. }
  26520. return this;
  26521. },
  26522. // advance the time and update apply the animation
  26523. update: function ( deltaTime ) {
  26524. deltaTime *= this.timeScale;
  26525. var actions = this._actions,
  26526. nActions = this._nActiveActions,
  26527. time = this.time += deltaTime,
  26528. timeDirection = Math.sign( deltaTime ),
  26529. accuIndex = this._accuIndex ^= 1;
  26530. // run active actions
  26531. for ( var i = 0; i !== nActions; ++ i ) {
  26532. var action = actions[ i ];
  26533. action._update( time, deltaTime, timeDirection, accuIndex );
  26534. }
  26535. // update scene graph
  26536. var bindings = this._bindings,
  26537. nBindings = this._nActiveBindings;
  26538. for ( var i = 0; i !== nBindings; ++ i ) {
  26539. bindings[ i ].apply( accuIndex );
  26540. }
  26541. return this;
  26542. },
  26543. // return this mixer's root target object
  26544. getRoot: function () {
  26545. return this._root;
  26546. },
  26547. // free all resources specific to a particular clip
  26548. uncacheClip: function ( clip ) {
  26549. var actions = this._actions,
  26550. clipUuid = clip.uuid,
  26551. actionsByClip = this._actionsByClip,
  26552. actionsForClip = actionsByClip[ clipUuid ];
  26553. if ( actionsForClip !== undefined ) {
  26554. // note: just calling _removeInactiveAction would mess up the
  26555. // iteration state and also require updating the state we can
  26556. // just throw away
  26557. var actionsToRemove = actionsForClip.knownActions;
  26558. for ( var i = 0, n = actionsToRemove.length; i !== n; ++ i ) {
  26559. var action = actionsToRemove[ i ];
  26560. this._deactivateAction( action );
  26561. var cacheIndex = action._cacheIndex,
  26562. lastInactiveAction = actions[ actions.length - 1 ];
  26563. action._cacheIndex = null;
  26564. action._byClipCacheIndex = null;
  26565. lastInactiveAction._cacheIndex = cacheIndex;
  26566. actions[ cacheIndex ] = lastInactiveAction;
  26567. actions.pop();
  26568. this._removeInactiveBindingsForAction( action );
  26569. }
  26570. delete actionsByClip[ clipUuid ];
  26571. }
  26572. },
  26573. // free all resources specific to a particular root target object
  26574. uncacheRoot: function ( root ) {
  26575. var rootUuid = root.uuid,
  26576. actionsByClip = this._actionsByClip;
  26577. for ( var clipUuid in actionsByClip ) {
  26578. var actionByRoot = actionsByClip[ clipUuid ].actionByRoot,
  26579. action = actionByRoot[ rootUuid ];
  26580. if ( action !== undefined ) {
  26581. this._deactivateAction( action );
  26582. this._removeInactiveAction( action );
  26583. }
  26584. }
  26585. var bindingsByRoot = this._bindingsByRootAndName,
  26586. bindingByName = bindingsByRoot[ rootUuid ];
  26587. if ( bindingByName !== undefined ) {
  26588. for ( var trackName in bindingByName ) {
  26589. var binding = bindingByName[ trackName ];
  26590. binding.restoreOriginalState();
  26591. this._removeInactiveBinding( binding );
  26592. }
  26593. }
  26594. },
  26595. // remove a targeted clip from the cache
  26596. uncacheAction: function ( clip, optionalRoot ) {
  26597. var action = this.existingAction( clip, optionalRoot );
  26598. if ( action !== null ) {
  26599. this._deactivateAction( action );
  26600. this._removeInactiveAction( action );
  26601. }
  26602. }
  26603. } );
  26604. /**
  26605. * @author mrdoob / http://mrdoob.com/
  26606. */
  26607. function Uniform( value ) {
  26608. if ( typeof value === 'string' ) {
  26609. console.warn( 'THREE.Uniform: Type parameter is no longer needed.' );
  26610. value = arguments[ 1 ];
  26611. }
  26612. this.value = value;
  26613. }
  26614. Uniform.prototype.clone = function () {
  26615. return new Uniform( this.value.clone === undefined ? this.value : this.value.clone() );
  26616. };
  26617. /**
  26618. * @author benaadams / https://twitter.com/ben_a_adams
  26619. */
  26620. function InstancedInterleavedBuffer( array, stride, meshPerAttribute ) {
  26621. InterleavedBuffer.call( this, array, stride );
  26622. this.meshPerAttribute = meshPerAttribute || 1;
  26623. }
  26624. InstancedInterleavedBuffer.prototype = Object.assign( Object.create( InterleavedBuffer.prototype ), {
  26625. constructor: InstancedInterleavedBuffer,
  26626. isInstancedInterleavedBuffer: true,
  26627. copy: function ( source ) {
  26628. InterleavedBuffer.prototype.copy.call( this, source );
  26629. this.meshPerAttribute = source.meshPerAttribute;
  26630. return this;
  26631. }
  26632. } );
  26633. /**
  26634. * @author mrdoob / http://mrdoob.com/
  26635. * @author bhouston / http://clara.io/
  26636. * @author stephomi / http://stephaneginier.com/
  26637. */
  26638. function Raycaster( origin, direction, near, far ) {
  26639. this.ray = new Ray( origin, direction );
  26640. // direction is assumed to be normalized (for accurate distance calculations)
  26641. this.near = near || 0;
  26642. this.far = far || Infinity;
  26643. this.params = {
  26644. Mesh: {},
  26645. Line: {},
  26646. LOD: {},
  26647. Points: { threshold: 1 },
  26648. Sprite: {}
  26649. };
  26650. Object.defineProperties( this.params, {
  26651. PointCloud: {
  26652. get: function () {
  26653. console.warn( 'THREE.Raycaster: params.PointCloud has been renamed to params.Points.' );
  26654. return this.Points;
  26655. }
  26656. }
  26657. } );
  26658. }
  26659. function ascSort( a, b ) {
  26660. return a.distance - b.distance;
  26661. }
  26662. function intersectObject( object, raycaster, intersects, recursive ) {
  26663. if ( object.visible === false ) return;
  26664. object.raycast( raycaster, intersects );
  26665. if ( recursive === true ) {
  26666. var children = object.children;
  26667. for ( var i = 0, l = children.length; i < l; i ++ ) {
  26668. intersectObject( children[ i ], raycaster, intersects, true );
  26669. }
  26670. }
  26671. }
  26672. Object.assign( Raycaster.prototype, {
  26673. linePrecision: 1,
  26674. set: function ( origin, direction ) {
  26675. // direction is assumed to be normalized (for accurate distance calculations)
  26676. this.ray.set( origin, direction );
  26677. },
  26678. setFromCamera: function ( coords, camera ) {
  26679. if ( ( camera && camera.isPerspectiveCamera ) ) {
  26680. this.ray.origin.setFromMatrixPosition( camera.matrixWorld );
  26681. this.ray.direction.set( coords.x, coords.y, 0.5 ).unproject( camera ).sub( this.ray.origin ).normalize();
  26682. this._camera = camera;
  26683. } else if ( ( camera && camera.isOrthographicCamera ) ) {
  26684. this.ray.origin.set( coords.x, coords.y, ( camera.near + camera.far ) / ( camera.near - camera.far ) ).unproject( camera ); // set origin in plane of camera
  26685. this.ray.direction.set( 0, 0, - 1 ).transformDirection( camera.matrixWorld );
  26686. this._camera = camera;
  26687. } else {
  26688. console.error( 'THREE.Raycaster: Unsupported camera type.' );
  26689. }
  26690. },
  26691. intersectObject: function ( object, recursive, optionalTarget ) {
  26692. var intersects = optionalTarget || [];
  26693. intersectObject( object, this, intersects, recursive );
  26694. intersects.sort( ascSort );
  26695. return intersects;
  26696. },
  26697. intersectObjects: function ( objects, recursive, optionalTarget ) {
  26698. var intersects = optionalTarget || [];
  26699. if ( Array.isArray( objects ) === false ) {
  26700. console.warn( 'THREE.Raycaster.intersectObjects: objects is not an Array.' );
  26701. return intersects;
  26702. }
  26703. for ( var i = 0, l = objects.length; i < l; i ++ ) {
  26704. intersectObject( objects[ i ], this, intersects, recursive );
  26705. }
  26706. intersects.sort( ascSort );
  26707. return intersects;
  26708. }
  26709. } );
  26710. /**
  26711. * @author bhouston / http://clara.io
  26712. * @author WestLangley / http://github.com/WestLangley
  26713. *
  26714. * Ref: https://en.wikipedia.org/wiki/Spherical_coordinate_system
  26715. *
  26716. * The polar angle (phi) is measured from the positive y-axis. The positive y-axis is up.
  26717. * The azimuthal angle (theta) is measured from the positive z-axiz.
  26718. */
  26719. function Spherical( radius, phi, theta ) {
  26720. this.radius = ( radius !== undefined ) ? radius : 1.0;
  26721. this.phi = ( phi !== undefined ) ? phi : 0; // polar angle
  26722. this.theta = ( theta !== undefined ) ? theta : 0; // azimuthal angle
  26723. return this;
  26724. }
  26725. Object.assign( Spherical.prototype, {
  26726. set: function ( radius, phi, theta ) {
  26727. this.radius = radius;
  26728. this.phi = phi;
  26729. this.theta = theta;
  26730. return this;
  26731. },
  26732. clone: function () {
  26733. return new this.constructor().copy( this );
  26734. },
  26735. copy: function ( other ) {
  26736. this.radius = other.radius;
  26737. this.phi = other.phi;
  26738. this.theta = other.theta;
  26739. return this;
  26740. },
  26741. // restrict phi to be betwee EPS and PI-EPS
  26742. makeSafe: function () {
  26743. var EPS = 0.000001;
  26744. this.phi = Math.max( EPS, Math.min( Math.PI - EPS, this.phi ) );
  26745. return this;
  26746. },
  26747. setFromVector3: function ( v ) {
  26748. return this.setFromCartesianCoords( v.x, v.y, v.z );
  26749. },
  26750. setFromCartesianCoords: function ( x, y, z ) {
  26751. this.radius = Math.sqrt( x * x + y * y + z * z );
  26752. if ( this.radius === 0 ) {
  26753. this.theta = 0;
  26754. this.phi = 0;
  26755. } else {
  26756. this.theta = Math.atan2( x, z );
  26757. this.phi = Math.acos( _Math.clamp( y / this.radius, - 1, 1 ) );
  26758. }
  26759. return this;
  26760. }
  26761. } );
  26762. /**
  26763. * @author Mugen87 / https://github.com/Mugen87
  26764. *
  26765. * Ref: https://en.wikipedia.org/wiki/Cylindrical_coordinate_system
  26766. *
  26767. */
  26768. function Cylindrical( radius, theta, y ) {
  26769. this.radius = ( radius !== undefined ) ? radius : 1.0; // distance from the origin to a point in the x-z plane
  26770. this.theta = ( theta !== undefined ) ? theta : 0; // counterclockwise angle in the x-z plane measured in radians from the positive z-axis
  26771. this.y = ( y !== undefined ) ? y : 0; // height above the x-z plane
  26772. return this;
  26773. }
  26774. Object.assign( Cylindrical.prototype, {
  26775. set: function ( radius, theta, y ) {
  26776. this.radius = radius;
  26777. this.theta = theta;
  26778. this.y = y;
  26779. return this;
  26780. },
  26781. clone: function () {
  26782. return new this.constructor().copy( this );
  26783. },
  26784. copy: function ( other ) {
  26785. this.radius = other.radius;
  26786. this.theta = other.theta;
  26787. this.y = other.y;
  26788. return this;
  26789. },
  26790. setFromVector3: function ( v ) {
  26791. return this.setFromCartesianCoords( v.x, v.y, v.z );
  26792. },
  26793. setFromCartesianCoords: function ( x, y, z ) {
  26794. this.radius = Math.sqrt( x * x + z * z );
  26795. this.theta = Math.atan2( x, z );
  26796. this.y = y;
  26797. return this;
  26798. }
  26799. } );
  26800. /**
  26801. * @author bhouston / http://clara.io
  26802. */
  26803. function Box2( min, max ) {
  26804. this.min = ( min !== undefined ) ? min : new Vector2( + Infinity, + Infinity );
  26805. this.max = ( max !== undefined ) ? max : new Vector2( - Infinity, - Infinity );
  26806. }
  26807. Object.assign( Box2.prototype, {
  26808. set: function ( min, max ) {
  26809. this.min.copy( min );
  26810. this.max.copy( max );
  26811. return this;
  26812. },
  26813. setFromPoints: function ( points ) {
  26814. this.makeEmpty();
  26815. for ( var i = 0, il = points.length; i < il; i ++ ) {
  26816. this.expandByPoint( points[ i ] );
  26817. }
  26818. return this;
  26819. },
  26820. setFromCenterAndSize: function () {
  26821. var v1 = new Vector2();
  26822. return function setFromCenterAndSize( center, size ) {
  26823. var halfSize = v1.copy( size ).multiplyScalar( 0.5 );
  26824. this.min.copy( center ).sub( halfSize );
  26825. this.max.copy( center ).add( halfSize );
  26826. return this;
  26827. };
  26828. }(),
  26829. clone: function () {
  26830. return new this.constructor().copy( this );
  26831. },
  26832. copy: function ( box ) {
  26833. this.min.copy( box.min );
  26834. this.max.copy( box.max );
  26835. return this;
  26836. },
  26837. makeEmpty: function () {
  26838. this.min.x = this.min.y = + Infinity;
  26839. this.max.x = this.max.y = - Infinity;
  26840. return this;
  26841. },
  26842. isEmpty: function () {
  26843. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  26844. return ( this.max.x < this.min.x ) || ( this.max.y < this.min.y );
  26845. },
  26846. getCenter: function ( target ) {
  26847. if ( target === undefined ) {
  26848. console.warn( 'THREE.Box2: .getCenter() target is now required' );
  26849. target = new Vector2();
  26850. }
  26851. return this.isEmpty() ? target.set( 0, 0 ) : target.addVectors( this.min, this.max ).multiplyScalar( 0.5 );
  26852. },
  26853. getSize: function ( target ) {
  26854. if ( target === undefined ) {
  26855. console.warn( 'THREE.Box2: .getSize() target is now required' );
  26856. target = new Vector2();
  26857. }
  26858. return this.isEmpty() ? target.set( 0, 0 ) : target.subVectors( this.max, this.min );
  26859. },
  26860. expandByPoint: function ( point ) {
  26861. this.min.min( point );
  26862. this.max.max( point );
  26863. return this;
  26864. },
  26865. expandByVector: function ( vector ) {
  26866. this.min.sub( vector );
  26867. this.max.add( vector );
  26868. return this;
  26869. },
  26870. expandByScalar: function ( scalar ) {
  26871. this.min.addScalar( - scalar );
  26872. this.max.addScalar( scalar );
  26873. return this;
  26874. },
  26875. containsPoint: function ( point ) {
  26876. return point.x < this.min.x || point.x > this.max.x ||
  26877. point.y < this.min.y || point.y > this.max.y ? false : true;
  26878. },
  26879. containsBox: function ( box ) {
  26880. return this.min.x <= box.min.x && box.max.x <= this.max.x &&
  26881. this.min.y <= box.min.y && box.max.y <= this.max.y;
  26882. },
  26883. getParameter: function ( point, target ) {
  26884. // This can potentially have a divide by zero if the box
  26885. // has a size dimension of 0.
  26886. if ( target === undefined ) {
  26887. console.warn( 'THREE.Box2: .getParameter() target is now required' );
  26888. target = new Vector2();
  26889. }
  26890. return target.set(
  26891. ( point.x - this.min.x ) / ( this.max.x - this.min.x ),
  26892. ( point.y - this.min.y ) / ( this.max.y - this.min.y )
  26893. );
  26894. },
  26895. intersectsBox: function ( box ) {
  26896. // using 4 splitting planes to rule out intersections
  26897. return box.max.x < this.min.x || box.min.x > this.max.x ||
  26898. box.max.y < this.min.y || box.min.y > this.max.y ? false : true;
  26899. },
  26900. clampPoint: function ( point, target ) {
  26901. if ( target === undefined ) {
  26902. console.warn( 'THREE.Box2: .clampPoint() target is now required' );
  26903. target = new Vector2();
  26904. }
  26905. return target.copy( point ).clamp( this.min, this.max );
  26906. },
  26907. distanceToPoint: function () {
  26908. var v1 = new Vector2();
  26909. return function distanceToPoint( point ) {
  26910. var clampedPoint = v1.copy( point ).clamp( this.min, this.max );
  26911. return clampedPoint.sub( point ).length();
  26912. };
  26913. }(),
  26914. intersect: function ( box ) {
  26915. this.min.max( box.min );
  26916. this.max.min( box.max );
  26917. return this;
  26918. },
  26919. union: function ( box ) {
  26920. this.min.min( box.min );
  26921. this.max.max( box.max );
  26922. return this;
  26923. },
  26924. translate: function ( offset ) {
  26925. this.min.add( offset );
  26926. this.max.add( offset );
  26927. return this;
  26928. },
  26929. equals: function ( box ) {
  26930. return box.min.equals( this.min ) && box.max.equals( this.max );
  26931. }
  26932. } );
  26933. /**
  26934. * @author bhouston / http://clara.io
  26935. */
  26936. function Line3( start, end ) {
  26937. this.start = ( start !== undefined ) ? start : new Vector3();
  26938. this.end = ( end !== undefined ) ? end : new Vector3();
  26939. }
  26940. Object.assign( Line3.prototype, {
  26941. set: function ( start, end ) {
  26942. this.start.copy( start );
  26943. this.end.copy( end );
  26944. return this;
  26945. },
  26946. clone: function () {
  26947. return new this.constructor().copy( this );
  26948. },
  26949. copy: function ( line ) {
  26950. this.start.copy( line.start );
  26951. this.end.copy( line.end );
  26952. return this;
  26953. },
  26954. getCenter: function ( target ) {
  26955. if ( target === undefined ) {
  26956. console.warn( 'THREE.Line3: .getCenter() target is now required' );
  26957. target = new Vector3();
  26958. }
  26959. return target.addVectors( this.start, this.end ).multiplyScalar( 0.5 );
  26960. },
  26961. delta: function ( target ) {
  26962. if ( target === undefined ) {
  26963. console.warn( 'THREE.Line3: .delta() target is now required' );
  26964. target = new Vector3();
  26965. }
  26966. return target.subVectors( this.end, this.start );
  26967. },
  26968. distanceSq: function () {
  26969. return this.start.distanceToSquared( this.end );
  26970. },
  26971. distance: function () {
  26972. return this.start.distanceTo( this.end );
  26973. },
  26974. at: function ( t, target ) {
  26975. if ( target === undefined ) {
  26976. console.warn( 'THREE.Line3: .at() target is now required' );
  26977. target = new Vector3();
  26978. }
  26979. return this.delta( target ).multiplyScalar( t ).add( this.start );
  26980. },
  26981. closestPointToPointParameter: function () {
  26982. var startP = new Vector3();
  26983. var startEnd = new Vector3();
  26984. return function closestPointToPointParameter( point, clampToLine ) {
  26985. startP.subVectors( point, this.start );
  26986. startEnd.subVectors( this.end, this.start );
  26987. var startEnd2 = startEnd.dot( startEnd );
  26988. var startEnd_startP = startEnd.dot( startP );
  26989. var t = startEnd_startP / startEnd2;
  26990. if ( clampToLine ) {
  26991. t = _Math.clamp( t, 0, 1 );
  26992. }
  26993. return t;
  26994. };
  26995. }(),
  26996. closestPointToPoint: function ( point, clampToLine, target ) {
  26997. var t = this.closestPointToPointParameter( point, clampToLine );
  26998. if ( target === undefined ) {
  26999. console.warn( 'THREE.Line3: .closestPointToPoint() target is now required' );
  27000. target = new Vector3();
  27001. }
  27002. return this.delta( target ).multiplyScalar( t ).add( this.start );
  27003. },
  27004. applyMatrix4: function ( matrix ) {
  27005. this.start.applyMatrix4( matrix );
  27006. this.end.applyMatrix4( matrix );
  27007. return this;
  27008. },
  27009. equals: function ( line ) {
  27010. return line.start.equals( this.start ) && line.end.equals( this.end );
  27011. }
  27012. } );
  27013. /**
  27014. * @author alteredq / http://alteredqualia.com/
  27015. */
  27016. function ImmediateRenderObject( material ) {
  27017. Object3D.call( this );
  27018. this.material = material;
  27019. this.render = function ( /* renderCallback */ ) {};
  27020. }
  27021. ImmediateRenderObject.prototype = Object.create( Object3D.prototype );
  27022. ImmediateRenderObject.prototype.constructor = ImmediateRenderObject;
  27023. ImmediateRenderObject.prototype.isImmediateRenderObject = true;
  27024. /**
  27025. * @author mrdoob / http://mrdoob.com/
  27026. * @author WestLangley / http://github.com/WestLangley
  27027. */
  27028. function VertexNormalsHelper( object, size, hex, linewidth ) {
  27029. this.object = object;
  27030. this.size = ( size !== undefined ) ? size : 1;
  27031. var color = ( hex !== undefined ) ? hex : 0xff0000;
  27032. var width = ( linewidth !== undefined ) ? linewidth : 1;
  27033. //
  27034. var nNormals = 0;
  27035. var objGeometry = this.object.geometry;
  27036. if ( objGeometry && objGeometry.isGeometry ) {
  27037. nNormals = objGeometry.faces.length * 3;
  27038. } else if ( objGeometry && objGeometry.isBufferGeometry ) {
  27039. nNormals = objGeometry.attributes.normal.count;
  27040. }
  27041. //
  27042. var geometry = new BufferGeometry();
  27043. var positions = new Float32BufferAttribute( nNormals * 2 * 3, 3 );
  27044. geometry.addAttribute( 'position', positions );
  27045. LineSegments.call( this, geometry, new LineBasicMaterial( { color: color, linewidth: width } ) );
  27046. //
  27047. this.matrixAutoUpdate = false;
  27048. this.update();
  27049. }
  27050. VertexNormalsHelper.prototype = Object.create( LineSegments.prototype );
  27051. VertexNormalsHelper.prototype.constructor = VertexNormalsHelper;
  27052. VertexNormalsHelper.prototype.update = ( function () {
  27053. var v1 = new Vector3();
  27054. var v2 = new Vector3();
  27055. var normalMatrix = new Matrix3();
  27056. return function update() {
  27057. var keys = [ 'a', 'b', 'c' ];
  27058. this.object.updateMatrixWorld( true );
  27059. normalMatrix.getNormalMatrix( this.object.matrixWorld );
  27060. var matrixWorld = this.object.matrixWorld;
  27061. var position = this.geometry.attributes.position;
  27062. //
  27063. var objGeometry = this.object.geometry;
  27064. if ( objGeometry && objGeometry.isGeometry ) {
  27065. var vertices = objGeometry.vertices;
  27066. var faces = objGeometry.faces;
  27067. var idx = 0;
  27068. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  27069. var face = faces[ i ];
  27070. for ( var j = 0, jl = face.vertexNormals.length; j < jl; j ++ ) {
  27071. var vertex = vertices[ face[ keys[ j ] ] ];
  27072. var normal = face.vertexNormals[ j ];
  27073. v1.copy( vertex ).applyMatrix4( matrixWorld );
  27074. v2.copy( normal ).applyMatrix3( normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
  27075. position.setXYZ( idx, v1.x, v1.y, v1.z );
  27076. idx = idx + 1;
  27077. position.setXYZ( idx, v2.x, v2.y, v2.z );
  27078. idx = idx + 1;
  27079. }
  27080. }
  27081. } else if ( objGeometry && objGeometry.isBufferGeometry ) {
  27082. var objPos = objGeometry.attributes.position;
  27083. var objNorm = objGeometry.attributes.normal;
  27084. var idx = 0;
  27085. // for simplicity, ignore index and drawcalls, and render every normal
  27086. for ( var j = 0, jl = objPos.count; j < jl; j ++ ) {
  27087. v1.set( objPos.getX( j ), objPos.getY( j ), objPos.getZ( j ) ).applyMatrix4( matrixWorld );
  27088. v2.set( objNorm.getX( j ), objNorm.getY( j ), objNorm.getZ( j ) );
  27089. v2.applyMatrix3( normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
  27090. position.setXYZ( idx, v1.x, v1.y, v1.z );
  27091. idx = idx + 1;
  27092. position.setXYZ( idx, v2.x, v2.y, v2.z );
  27093. idx = idx + 1;
  27094. }
  27095. }
  27096. position.needsUpdate = true;
  27097. };
  27098. }() );
  27099. /**
  27100. * @author alteredq / http://alteredqualia.com/
  27101. * @author mrdoob / http://mrdoob.com/
  27102. * @author WestLangley / http://github.com/WestLangley
  27103. */
  27104. function SpotLightHelper( light, color ) {
  27105. Object3D.call( this );
  27106. this.light = light;
  27107. this.light.updateMatrixWorld();
  27108. this.matrix = light.matrixWorld;
  27109. this.matrixAutoUpdate = false;
  27110. this.color = color;
  27111. var geometry = new BufferGeometry();
  27112. var positions = [
  27113. 0, 0, 0, 0, 0, 1,
  27114. 0, 0, 0, 1, 0, 1,
  27115. 0, 0, 0, - 1, 0, 1,
  27116. 0, 0, 0, 0, 1, 1,
  27117. 0, 0, 0, 0, - 1, 1
  27118. ];
  27119. for ( var i = 0, j = 1, l = 32; i < l; i ++, j ++ ) {
  27120. var p1 = ( i / l ) * Math.PI * 2;
  27121. var p2 = ( j / l ) * Math.PI * 2;
  27122. positions.push(
  27123. Math.cos( p1 ), Math.sin( p1 ), 1,
  27124. Math.cos( p2 ), Math.sin( p2 ), 1
  27125. );
  27126. }
  27127. geometry.addAttribute( 'position', new Float32BufferAttribute( positions, 3 ) );
  27128. var material = new LineBasicMaterial( { fog: false } );
  27129. this.cone = new LineSegments( geometry, material );
  27130. this.add( this.cone );
  27131. this.update();
  27132. }
  27133. SpotLightHelper.prototype = Object.create( Object3D.prototype );
  27134. SpotLightHelper.prototype.constructor = SpotLightHelper;
  27135. SpotLightHelper.prototype.dispose = function () {
  27136. this.cone.geometry.dispose();
  27137. this.cone.material.dispose();
  27138. };
  27139. SpotLightHelper.prototype.update = function () {
  27140. var vector = new Vector3();
  27141. return function update() {
  27142. this.light.updateMatrixWorld();
  27143. var coneLength = this.light.distance ? this.light.distance : 1000;
  27144. var coneWidth = coneLength * Math.tan( this.light.angle );
  27145. this.cone.scale.set( coneWidth, coneWidth, coneLength );
  27146. vector.setFromMatrixPosition( this.light.target.matrixWorld );
  27147. this.cone.lookAt( vector );
  27148. if ( this.color !== undefined ) {
  27149. this.cone.material.color.set( this.color );
  27150. } else {
  27151. this.cone.material.color.copy( this.light.color );
  27152. }
  27153. };
  27154. }();
  27155. /**
  27156. * @author Sean Griffin / http://twitter.com/sgrif
  27157. * @author Michael Guerrero / http://realitymeltdown.com
  27158. * @author mrdoob / http://mrdoob.com/
  27159. * @author ikerr / http://verold.com
  27160. * @author Mugen87 / https://github.com/Mugen87
  27161. */
  27162. function getBoneList( object ) {
  27163. var boneList = [];
  27164. if ( object && object.isBone ) {
  27165. boneList.push( object );
  27166. }
  27167. for ( var i = 0; i < object.children.length; i ++ ) {
  27168. boneList.push.apply( boneList, getBoneList( object.children[ i ] ) );
  27169. }
  27170. return boneList;
  27171. }
  27172. function SkeletonHelper( object ) {
  27173. var bones = getBoneList( object );
  27174. var geometry = new BufferGeometry();
  27175. var vertices = [];
  27176. var colors = [];
  27177. var color1 = new Color( 0, 0, 1 );
  27178. var color2 = new Color( 0, 1, 0 );
  27179. for ( var i = 0; i < bones.length; i ++ ) {
  27180. var bone = bones[ i ];
  27181. if ( bone.parent && bone.parent.isBone ) {
  27182. vertices.push( 0, 0, 0 );
  27183. vertices.push( 0, 0, 0 );
  27184. colors.push( color1.r, color1.g, color1.b );
  27185. colors.push( color2.r, color2.g, color2.b );
  27186. }
  27187. }
  27188. geometry.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  27189. geometry.addAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  27190. var material = new LineBasicMaterial( { vertexColors: VertexColors, depthTest: false, depthWrite: false, transparent: true } );
  27191. LineSegments.call( this, geometry, material );
  27192. this.root = object;
  27193. this.bones = bones;
  27194. this.matrix = object.matrixWorld;
  27195. this.matrixAutoUpdate = false;
  27196. }
  27197. SkeletonHelper.prototype = Object.create( LineSegments.prototype );
  27198. SkeletonHelper.prototype.constructor = SkeletonHelper;
  27199. SkeletonHelper.prototype.updateMatrixWorld = function () {
  27200. var vector = new Vector3();
  27201. var boneMatrix = new Matrix4();
  27202. var matrixWorldInv = new Matrix4();
  27203. return function updateMatrixWorld( force ) {
  27204. var bones = this.bones;
  27205. var geometry = this.geometry;
  27206. var position = geometry.getAttribute( 'position' );
  27207. matrixWorldInv.getInverse( this.root.matrixWorld );
  27208. for ( var i = 0, j = 0; i < bones.length; i ++ ) {
  27209. var bone = bones[ i ];
  27210. if ( bone.parent && bone.parent.isBone ) {
  27211. boneMatrix.multiplyMatrices( matrixWorldInv, bone.matrixWorld );
  27212. vector.setFromMatrixPosition( boneMatrix );
  27213. position.setXYZ( j, vector.x, vector.y, vector.z );
  27214. boneMatrix.multiplyMatrices( matrixWorldInv, bone.parent.matrixWorld );
  27215. vector.setFromMatrixPosition( boneMatrix );
  27216. position.setXYZ( j + 1, vector.x, vector.y, vector.z );
  27217. j += 2;
  27218. }
  27219. }
  27220. geometry.getAttribute( 'position' ).needsUpdate = true;
  27221. Object3D.prototype.updateMatrixWorld.call( this, force );
  27222. };
  27223. }();
  27224. /**
  27225. * @author alteredq / http://alteredqualia.com/
  27226. * @author mrdoob / http://mrdoob.com/
  27227. */
  27228. function PointLightHelper( light, sphereSize, color ) {
  27229. this.light = light;
  27230. this.light.updateMatrixWorld();
  27231. this.color = color;
  27232. var geometry = new SphereBufferGeometry( sphereSize, 4, 2 );
  27233. var material = new MeshBasicMaterial( { wireframe: true, fog: false } );
  27234. Mesh.call( this, geometry, material );
  27235. this.matrix = this.light.matrixWorld;
  27236. this.matrixAutoUpdate = false;
  27237. this.update();
  27238. /*
  27239. var distanceGeometry = new THREE.IcosahedronBufferGeometry( 1, 2 );
  27240. var distanceMaterial = new THREE.MeshBasicMaterial( { color: hexColor, fog: false, wireframe: true, opacity: 0.1, transparent: true } );
  27241. this.lightSphere = new THREE.Mesh( bulbGeometry, bulbMaterial );
  27242. this.lightDistance = new THREE.Mesh( distanceGeometry, distanceMaterial );
  27243. var d = light.distance;
  27244. if ( d === 0.0 ) {
  27245. this.lightDistance.visible = false;
  27246. } else {
  27247. this.lightDistance.scale.set( d, d, d );
  27248. }
  27249. this.add( this.lightDistance );
  27250. */
  27251. }
  27252. PointLightHelper.prototype = Object.create( Mesh.prototype );
  27253. PointLightHelper.prototype.constructor = PointLightHelper;
  27254. PointLightHelper.prototype.dispose = function () {
  27255. this.geometry.dispose();
  27256. this.material.dispose();
  27257. };
  27258. PointLightHelper.prototype.update = function () {
  27259. if ( this.color !== undefined ) {
  27260. this.material.color.set( this.color );
  27261. } else {
  27262. this.material.color.copy( this.light.color );
  27263. }
  27264. /*
  27265. var d = this.light.distance;
  27266. if ( d === 0.0 ) {
  27267. this.lightDistance.visible = false;
  27268. } else {
  27269. this.lightDistance.visible = true;
  27270. this.lightDistance.scale.set( d, d, d );
  27271. }
  27272. */
  27273. };
  27274. /**
  27275. * @author abelnation / http://github.com/abelnation
  27276. * @author Mugen87 / http://github.com/Mugen87
  27277. * @author WestLangley / http://github.com/WestLangley
  27278. *
  27279. * This helper must be added as a child of the light
  27280. */
  27281. function RectAreaLightHelper( light, color ) {
  27282. this.type = 'RectAreaLightHelper';
  27283. this.light = light;
  27284. this.color = color; // optional hardwired color for the helper
  27285. var positions = [ 1, 1, 0, - 1, 1, 0, - 1, - 1, 0, 1, - 1, 0, 1, 1, 0 ];
  27286. var geometry = new BufferGeometry();
  27287. geometry.addAttribute( 'position', new Float32BufferAttribute( positions, 3 ) );
  27288. geometry.computeBoundingSphere();
  27289. var material = new LineBasicMaterial( { fog: false } );
  27290. Line.call( this, geometry, material );
  27291. //
  27292. var positions2 = [ 1, 1, 0, - 1, 1, 0, - 1, - 1, 0, 1, 1, 0, - 1, - 1, 0, 1, - 1, 0 ];
  27293. var geometry2 = new BufferGeometry();
  27294. geometry2.addAttribute( 'position', new Float32BufferAttribute( positions2, 3 ) );
  27295. geometry2.computeBoundingSphere();
  27296. this.add( new Mesh( geometry2, new MeshBasicMaterial( { side: BackSide, fog: false } ) ) );
  27297. this.update();
  27298. }
  27299. RectAreaLightHelper.prototype = Object.create( Line.prototype );
  27300. RectAreaLightHelper.prototype.constructor = RectAreaLightHelper;
  27301. RectAreaLightHelper.prototype.update = function () {
  27302. this.scale.set( 0.5 * this.light.width, 0.5 * this.light.height, 1 );
  27303. if ( this.color !== undefined ) {
  27304. this.material.color.set( this.color );
  27305. this.children[ 0 ].material.color.set( this.color );
  27306. } else {
  27307. this.material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  27308. // prevent hue shift
  27309. var c = this.material.color;
  27310. var max = Math.max( c.r, c.g, c.b );
  27311. if ( max > 1 ) c.multiplyScalar( 1 / max );
  27312. this.children[ 0 ].material.color.copy( this.material.color );
  27313. }
  27314. };
  27315. RectAreaLightHelper.prototype.dispose = function () {
  27316. this.geometry.dispose();
  27317. this.material.dispose();
  27318. this.children[ 0 ].geometry.dispose();
  27319. this.children[ 0 ].material.dispose();
  27320. };
  27321. /**
  27322. * @author alteredq / http://alteredqualia.com/
  27323. * @author mrdoob / http://mrdoob.com/
  27324. * @author Mugen87 / https://github.com/Mugen87
  27325. */
  27326. function HemisphereLightHelper( light, size, color ) {
  27327. Object3D.call( this );
  27328. this.light = light;
  27329. this.light.updateMatrixWorld();
  27330. this.matrix = light.matrixWorld;
  27331. this.matrixAutoUpdate = false;
  27332. this.color = color;
  27333. var geometry = new OctahedronBufferGeometry( size );
  27334. geometry.rotateY( Math.PI * 0.5 );
  27335. this.material = new MeshBasicMaterial( { wireframe: true, fog: false } );
  27336. if ( this.color === undefined ) this.material.vertexColors = VertexColors;
  27337. var position = geometry.getAttribute( 'position' );
  27338. var colors = new Float32Array( position.count * 3 );
  27339. geometry.addAttribute( 'color', new BufferAttribute( colors, 3 ) );
  27340. this.add( new Mesh( geometry, this.material ) );
  27341. this.update();
  27342. }
  27343. HemisphereLightHelper.prototype = Object.create( Object3D.prototype );
  27344. HemisphereLightHelper.prototype.constructor = HemisphereLightHelper;
  27345. HemisphereLightHelper.prototype.dispose = function () {
  27346. this.children[ 0 ].geometry.dispose();
  27347. this.children[ 0 ].material.dispose();
  27348. };
  27349. HemisphereLightHelper.prototype.update = function () {
  27350. var vector = new Vector3();
  27351. var color1 = new Color();
  27352. var color2 = new Color();
  27353. return function update() {
  27354. var mesh = this.children[ 0 ];
  27355. if ( this.color !== undefined ) {
  27356. this.material.color.set( this.color );
  27357. } else {
  27358. var colors = mesh.geometry.getAttribute( 'color' );
  27359. color1.copy( this.light.color );
  27360. color2.copy( this.light.groundColor );
  27361. for ( var i = 0, l = colors.count; i < l; i ++ ) {
  27362. var color = ( i < ( l / 2 ) ) ? color1 : color2;
  27363. colors.setXYZ( i, color.r, color.g, color.b );
  27364. }
  27365. colors.needsUpdate = true;
  27366. }
  27367. mesh.lookAt( vector.setFromMatrixPosition( this.light.matrixWorld ).negate() );
  27368. };
  27369. }();
  27370. /**
  27371. * @author WestLangley / http://github.com/WestLangley
  27372. */
  27373. function LightProbeHelper( lightProbe, size ) {
  27374. this.lightProbe = lightProbe;
  27375. this.size = size;
  27376. var defines = {};
  27377. defines[ 'GAMMA_OUTPUT' ] = "";
  27378. // material
  27379. var material = new ShaderMaterial( {
  27380. defines: defines,
  27381. uniforms: {
  27382. sh: { value: this.lightProbe.sh.coefficients }, // by reference
  27383. intensity: { value: this.lightProbe.intensity }
  27384. },
  27385. vertexShader: [
  27386. 'varying vec3 vNormal;',
  27387. 'void main() {',
  27388. ' vNormal = normalize( normalMatrix * normal );',
  27389. ' gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );',
  27390. '}',
  27391. ].join( '\n' ),
  27392. fragmentShader: [
  27393. '#define RECIPROCAL_PI 0.318309886',
  27394. 'vec3 inverseTransformDirection( in vec3 normal, in mat4 matrix ) {',
  27395. ' // matrix is assumed to be orthogonal',
  27396. ' return normalize( ( vec4( normal, 0.0 ) * matrix ).xyz );',
  27397. '}',
  27398. 'vec3 linearToOutput( in vec3 a ) {',
  27399. ' #ifdef GAMMA_OUTPUT',
  27400. ' return pow( a, vec3( 1.0 / float( GAMMA_FACTOR ) ) );',
  27401. ' #else',
  27402. ' return a;',
  27403. ' #endif',
  27404. '}',
  27405. '// source: https://graphics.stanford.edu/papers/envmap/envmap.pdf',
  27406. 'vec3 shGetIrradianceAt( in vec3 normal, in vec3 shCoefficients[ 9 ] ) {',
  27407. ' // normal is assumed to have unit length',
  27408. ' float x = normal.x, y = normal.y, z = normal.z;',
  27409. ' // band 0',
  27410. ' vec3 result = shCoefficients[ 0 ] * 0.886227;',
  27411. ' // band 1',
  27412. ' result += shCoefficients[ 1 ] * 2.0 * 0.511664 * y;',
  27413. ' result += shCoefficients[ 2 ] * 2.0 * 0.511664 * z;',
  27414. ' result += shCoefficients[ 3 ] * 2.0 * 0.511664 * x;',
  27415. ' // band 2',
  27416. ' result += shCoefficients[ 4 ] * 2.0 * 0.429043 * x * y;',
  27417. ' result += shCoefficients[ 5 ] * 2.0 * 0.429043 * y * z;',
  27418. ' result += shCoefficients[ 6 ] * ( 0.743125 * z * z - 0.247708 );',
  27419. ' result += shCoefficients[ 7 ] * 2.0 * 0.429043 * x * z;',
  27420. ' result += shCoefficients[ 8 ] * 0.429043 * ( x * x - y * y );',
  27421. ' return result;',
  27422. '}',
  27423. 'uniform vec3 sh[ 9 ]; // sh coefficients',
  27424. 'uniform float intensity; // light probe intensity',
  27425. 'varying vec3 vNormal;',
  27426. 'void main() {',
  27427. ' vec3 normal = normalize( vNormal );',
  27428. ' vec3 worldNormal = inverseTransformDirection( normal, viewMatrix );',
  27429. ' vec3 irradiance = shGetIrradianceAt( worldNormal, sh );',
  27430. ' vec3 outgoingLight = RECIPROCAL_PI * irradiance * intensity;',
  27431. ' outgoingLight = linearToOutput( outgoingLight );',
  27432. ' gl_FragColor = vec4( outgoingLight, 1.0 );',
  27433. '}'
  27434. ].join( '\n' )
  27435. } );
  27436. var geometry = new SphereBufferGeometry( 1, 32, 16 );
  27437. Mesh.call( this, geometry, material );
  27438. this.onBeforeRender();
  27439. }
  27440. LightProbeHelper.prototype = Object.create( Mesh.prototype );
  27441. LightProbeHelper.prototype.constructor = LightProbeHelper;
  27442. LightProbeHelper.prototype.dispose = function () {
  27443. this.geometry.dispose();
  27444. this.material.dispose();
  27445. };
  27446. LightProbeHelper.prototype.onBeforeRender = function () {
  27447. return function update() {
  27448. this.position.copy( this.lightProbe.position );
  27449. this.scale.set( 1, 1, 1 ).multiplyScalar( this.size );
  27450. this.material.uniforms.intensity.value = this.lightProbe.intensity;
  27451. };
  27452. }();
  27453. /**
  27454. * @author mrdoob / http://mrdoob.com/
  27455. */
  27456. function GridHelper( size, divisions, color1, color2 ) {
  27457. size = size || 10;
  27458. divisions = divisions || 10;
  27459. color1 = new Color( color1 !== undefined ? color1 : 0x444444 );
  27460. color2 = new Color( color2 !== undefined ? color2 : 0x888888 );
  27461. var center = divisions / 2;
  27462. var step = size / divisions;
  27463. var halfSize = size / 2;
  27464. var vertices = [], colors = [];
  27465. for ( var i = 0, j = 0, k = - halfSize; i <= divisions; i ++, k += step ) {
  27466. vertices.push( - halfSize, 0, k, halfSize, 0, k );
  27467. vertices.push( k, 0, - halfSize, k, 0, halfSize );
  27468. var color = i === center ? color1 : color2;
  27469. color.toArray( colors, j ); j += 3;
  27470. color.toArray( colors, j ); j += 3;
  27471. color.toArray( colors, j ); j += 3;
  27472. color.toArray( colors, j ); j += 3;
  27473. }
  27474. var geometry = new BufferGeometry();
  27475. geometry.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  27476. geometry.addAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  27477. var material = new LineBasicMaterial( { vertexColors: VertexColors } );
  27478. LineSegments.call( this, geometry, material );
  27479. }
  27480. GridHelper.prototype = Object.assign( Object.create( LineSegments.prototype ), {
  27481. constructor: GridHelper,
  27482. copy: function ( source ) {
  27483. LineSegments.prototype.copy.call( this, source );
  27484. this.geometry.copy( source.geometry );
  27485. this.material.copy( source.material );
  27486. return this;
  27487. },
  27488. clone: function () {
  27489. return new this.constructor().copy( this );
  27490. }
  27491. } );
  27492. /**
  27493. * @author mrdoob / http://mrdoob.com/
  27494. * @author Mugen87 / http://github.com/Mugen87
  27495. * @author Hectate / http://www.github.com/Hectate
  27496. */
  27497. function PolarGridHelper( radius, radials, circles, divisions, color1, color2 ) {
  27498. radius = radius || 10;
  27499. radials = radials || 16;
  27500. circles = circles || 8;
  27501. divisions = divisions || 64;
  27502. color1 = new Color( color1 !== undefined ? color1 : 0x444444 );
  27503. color2 = new Color( color2 !== undefined ? color2 : 0x888888 );
  27504. var vertices = [];
  27505. var colors = [];
  27506. var x, z;
  27507. var v, i, j, r, color;
  27508. // create the radials
  27509. for ( i = 0; i <= radials; i ++ ) {
  27510. v = ( i / radials ) * ( Math.PI * 2 );
  27511. x = Math.sin( v ) * radius;
  27512. z = Math.cos( v ) * radius;
  27513. vertices.push( 0, 0, 0 );
  27514. vertices.push( x, 0, z );
  27515. color = ( i & 1 ) ? color1 : color2;
  27516. colors.push( color.r, color.g, color.b );
  27517. colors.push( color.r, color.g, color.b );
  27518. }
  27519. // create the circles
  27520. for ( i = 0; i <= circles; i ++ ) {
  27521. color = ( i & 1 ) ? color1 : color2;
  27522. r = radius - ( radius / circles * i );
  27523. for ( j = 0; j < divisions; j ++ ) {
  27524. // first vertex
  27525. v = ( j / divisions ) * ( Math.PI * 2 );
  27526. x = Math.sin( v ) * r;
  27527. z = Math.cos( v ) * r;
  27528. vertices.push( x, 0, z );
  27529. colors.push( color.r, color.g, color.b );
  27530. // second vertex
  27531. v = ( ( j + 1 ) / divisions ) * ( Math.PI * 2 );
  27532. x = Math.sin( v ) * r;
  27533. z = Math.cos( v ) * r;
  27534. vertices.push( x, 0, z );
  27535. colors.push( color.r, color.g, color.b );
  27536. }
  27537. }
  27538. var geometry = new BufferGeometry();
  27539. geometry.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  27540. geometry.addAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  27541. var material = new LineBasicMaterial( { vertexColors: VertexColors } );
  27542. LineSegments.call( this, geometry, material );
  27543. }
  27544. PolarGridHelper.prototype = Object.create( LineSegments.prototype );
  27545. PolarGridHelper.prototype.constructor = PolarGridHelper;
  27546. /**
  27547. * @author Mugen87 / http://github.com/Mugen87
  27548. */
  27549. function PositionalAudioHelper( audio, range, divisionsInnerAngle, divisionsOuterAngle ) {
  27550. this.audio = audio;
  27551. this.range = range || 1;
  27552. this.divisionsInnerAngle = divisionsInnerAngle || 16;
  27553. this.divisionsOuterAngle = divisionsOuterAngle || 2;
  27554. var geometry = new BufferGeometry();
  27555. var divisions = this.divisionsInnerAngle + this.divisionsOuterAngle * 2;
  27556. var positions = new Float32Array( ( divisions * 3 + 3 ) * 3 );
  27557. geometry.addAttribute( 'position', new BufferAttribute( positions, 3 ) );
  27558. var materialInnerAngle = new LineBasicMaterial( { color: 0x00ff00 } );
  27559. var materialOuterAngle = new LineBasicMaterial( { color: 0xffff00 } );
  27560. Line.call( this, geometry, [ materialOuterAngle, materialInnerAngle ] );
  27561. this.update();
  27562. }
  27563. PositionalAudioHelper.prototype = Object.create( Line.prototype );
  27564. PositionalAudioHelper.prototype.constructor = PositionalAudioHelper;
  27565. PositionalAudioHelper.prototype.update = function () {
  27566. var audio = this.audio;
  27567. var range = this.range;
  27568. var divisionsInnerAngle = this.divisionsInnerAngle;
  27569. var divisionsOuterAngle = this.divisionsOuterAngle;
  27570. var coneInnerAngle = _Math.degToRad( audio.panner.coneInnerAngle );
  27571. var coneOuterAngle = _Math.degToRad( audio.panner.coneOuterAngle );
  27572. var halfConeInnerAngle = coneInnerAngle / 2;
  27573. var halfConeOuterAngle = coneOuterAngle / 2;
  27574. var start = 0;
  27575. var count = 0;
  27576. var i, stride;
  27577. var geometry = this.geometry;
  27578. var positionAttribute = geometry.attributes.position;
  27579. geometry.clearGroups();
  27580. //
  27581. function generateSegment( from, to, divisions, materialIndex ) {
  27582. var step = ( to - from ) / divisions;
  27583. positionAttribute.setXYZ( start, 0, 0, 0 );
  27584. count ++;
  27585. for ( i = from; i < to; i += step ) {
  27586. stride = start + count;
  27587. positionAttribute.setXYZ( stride, Math.sin( i ) * range, 0, Math.cos( i ) * range );
  27588. positionAttribute.setXYZ( stride + 1, Math.sin( Math.min( i + step, to ) ) * range, 0, Math.cos( Math.min( i + step, to ) ) * range );
  27589. positionAttribute.setXYZ( stride + 2, 0, 0, 0 );
  27590. count += 3;
  27591. }
  27592. geometry.addGroup( start, count, materialIndex );
  27593. start += count;
  27594. count = 0;
  27595. }
  27596. //
  27597. generateSegment( - halfConeOuterAngle, - halfConeInnerAngle, divisionsOuterAngle, 0 );
  27598. generateSegment( - halfConeInnerAngle, halfConeInnerAngle, divisionsInnerAngle, 1 );
  27599. generateSegment( halfConeInnerAngle, halfConeOuterAngle, divisionsOuterAngle, 0 );
  27600. //
  27601. positionAttribute.needsUpdate = true;
  27602. if ( coneInnerAngle === coneOuterAngle ) this.material[ 0 ].visible = false;
  27603. };
  27604. PositionalAudioHelper.prototype.dispose = function () {
  27605. this.geometry.dispose();
  27606. this.material[ 0 ].dispose();
  27607. this.material[ 1 ].dispose();
  27608. };
  27609. /**
  27610. * @author mrdoob / http://mrdoob.com/
  27611. * @author WestLangley / http://github.com/WestLangley
  27612. */
  27613. function FaceNormalsHelper( object, size, hex, linewidth ) {
  27614. // FaceNormalsHelper only supports THREE.Geometry
  27615. this.object = object;
  27616. this.size = ( size !== undefined ) ? size : 1;
  27617. var color = ( hex !== undefined ) ? hex : 0xffff00;
  27618. var width = ( linewidth !== undefined ) ? linewidth : 1;
  27619. //
  27620. var nNormals = 0;
  27621. var objGeometry = this.object.geometry;
  27622. if ( objGeometry && objGeometry.isGeometry ) {
  27623. nNormals = objGeometry.faces.length;
  27624. } else {
  27625. console.warn( 'THREE.FaceNormalsHelper: only THREE.Geometry is supported. Use THREE.VertexNormalsHelper, instead.' );
  27626. }
  27627. //
  27628. var geometry = new BufferGeometry();
  27629. var positions = new Float32BufferAttribute( nNormals * 2 * 3, 3 );
  27630. geometry.addAttribute( 'position', positions );
  27631. LineSegments.call( this, geometry, new LineBasicMaterial( { color: color, linewidth: width } ) );
  27632. //
  27633. this.matrixAutoUpdate = false;
  27634. this.update();
  27635. }
  27636. FaceNormalsHelper.prototype = Object.create( LineSegments.prototype );
  27637. FaceNormalsHelper.prototype.constructor = FaceNormalsHelper;
  27638. FaceNormalsHelper.prototype.update = ( function () {
  27639. var v1 = new Vector3();
  27640. var v2 = new Vector3();
  27641. var normalMatrix = new Matrix3();
  27642. return function update() {
  27643. this.object.updateMatrixWorld( true );
  27644. normalMatrix.getNormalMatrix( this.object.matrixWorld );
  27645. var matrixWorld = this.object.matrixWorld;
  27646. var position = this.geometry.attributes.position;
  27647. //
  27648. var objGeometry = this.object.geometry;
  27649. var vertices = objGeometry.vertices;
  27650. var faces = objGeometry.faces;
  27651. var idx = 0;
  27652. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  27653. var face = faces[ i ];
  27654. var normal = face.normal;
  27655. v1.copy( vertices[ face.a ] )
  27656. .add( vertices[ face.b ] )
  27657. .add( vertices[ face.c ] )
  27658. .divideScalar( 3 )
  27659. .applyMatrix4( matrixWorld );
  27660. v2.copy( normal ).applyMatrix3( normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
  27661. position.setXYZ( idx, v1.x, v1.y, v1.z );
  27662. idx = idx + 1;
  27663. position.setXYZ( idx, v2.x, v2.y, v2.z );
  27664. idx = idx + 1;
  27665. }
  27666. position.needsUpdate = true;
  27667. };
  27668. }() );
  27669. /**
  27670. * @author alteredq / http://alteredqualia.com/
  27671. * @author mrdoob / http://mrdoob.com/
  27672. * @author WestLangley / http://github.com/WestLangley
  27673. */
  27674. function DirectionalLightHelper( light, size, color ) {
  27675. Object3D.call( this );
  27676. this.light = light;
  27677. this.light.updateMatrixWorld();
  27678. this.matrix = light.matrixWorld;
  27679. this.matrixAutoUpdate = false;
  27680. this.color = color;
  27681. if ( size === undefined ) size = 1;
  27682. var geometry = new BufferGeometry();
  27683. geometry.addAttribute( 'position', new Float32BufferAttribute( [
  27684. - size, size, 0,
  27685. size, size, 0,
  27686. size, - size, 0,
  27687. - size, - size, 0,
  27688. - size, size, 0
  27689. ], 3 ) );
  27690. var material = new LineBasicMaterial( { fog: false } );
  27691. this.lightPlane = new Line( geometry, material );
  27692. this.add( this.lightPlane );
  27693. geometry = new BufferGeometry();
  27694. geometry.addAttribute( 'position', new Float32BufferAttribute( [ 0, 0, 0, 0, 0, 1 ], 3 ) );
  27695. this.targetLine = new Line( geometry, material );
  27696. this.add( this.targetLine );
  27697. this.update();
  27698. }
  27699. DirectionalLightHelper.prototype = Object.create( Object3D.prototype );
  27700. DirectionalLightHelper.prototype.constructor = DirectionalLightHelper;
  27701. DirectionalLightHelper.prototype.dispose = function () {
  27702. this.lightPlane.geometry.dispose();
  27703. this.lightPlane.material.dispose();
  27704. this.targetLine.geometry.dispose();
  27705. this.targetLine.material.dispose();
  27706. };
  27707. DirectionalLightHelper.prototype.update = function () {
  27708. var v1 = new Vector3();
  27709. var v2 = new Vector3();
  27710. var v3 = new Vector3();
  27711. return function update() {
  27712. v1.setFromMatrixPosition( this.light.matrixWorld );
  27713. v2.setFromMatrixPosition( this.light.target.matrixWorld );
  27714. v3.subVectors( v2, v1 );
  27715. this.lightPlane.lookAt( v2 );
  27716. if ( this.color !== undefined ) {
  27717. this.lightPlane.material.color.set( this.color );
  27718. this.targetLine.material.color.set( this.color );
  27719. } else {
  27720. this.lightPlane.material.color.copy( this.light.color );
  27721. this.targetLine.material.color.copy( this.light.color );
  27722. }
  27723. this.targetLine.lookAt( v2 );
  27724. this.targetLine.scale.z = v3.length();
  27725. };
  27726. }();
  27727. /**
  27728. * @author alteredq / http://alteredqualia.com/
  27729. * @author Mugen87 / https://github.com/Mugen87
  27730. *
  27731. * - shows frustum, line of sight and up of the camera
  27732. * - suitable for fast updates
  27733. * - based on frustum visualization in lightgl.js shadowmap example
  27734. * http://evanw.github.com/lightgl.js/tests/shadowmap.html
  27735. */
  27736. function CameraHelper( camera ) {
  27737. var geometry = new BufferGeometry();
  27738. var material = new LineBasicMaterial( { color: 0xffffff, vertexColors: FaceColors } );
  27739. var vertices = [];
  27740. var colors = [];
  27741. var pointMap = {};
  27742. // colors
  27743. var colorFrustum = new Color( 0xffaa00 );
  27744. var colorCone = new Color( 0xff0000 );
  27745. var colorUp = new Color( 0x00aaff );
  27746. var colorTarget = new Color( 0xffffff );
  27747. var colorCross = new Color( 0x333333 );
  27748. // near
  27749. addLine( 'n1', 'n2', colorFrustum );
  27750. addLine( 'n2', 'n4', colorFrustum );
  27751. addLine( 'n4', 'n3', colorFrustum );
  27752. addLine( 'n3', 'n1', colorFrustum );
  27753. // far
  27754. addLine( 'f1', 'f2', colorFrustum );
  27755. addLine( 'f2', 'f4', colorFrustum );
  27756. addLine( 'f4', 'f3', colorFrustum );
  27757. addLine( 'f3', 'f1', colorFrustum );
  27758. // sides
  27759. addLine( 'n1', 'f1', colorFrustum );
  27760. addLine( 'n2', 'f2', colorFrustum );
  27761. addLine( 'n3', 'f3', colorFrustum );
  27762. addLine( 'n4', 'f4', colorFrustum );
  27763. // cone
  27764. addLine( 'p', 'n1', colorCone );
  27765. addLine( 'p', 'n2', colorCone );
  27766. addLine( 'p', 'n3', colorCone );
  27767. addLine( 'p', 'n4', colorCone );
  27768. // up
  27769. addLine( 'u1', 'u2', colorUp );
  27770. addLine( 'u2', 'u3', colorUp );
  27771. addLine( 'u3', 'u1', colorUp );
  27772. // target
  27773. addLine( 'c', 't', colorTarget );
  27774. addLine( 'p', 'c', colorCross );
  27775. // cross
  27776. addLine( 'cn1', 'cn2', colorCross );
  27777. addLine( 'cn3', 'cn4', colorCross );
  27778. addLine( 'cf1', 'cf2', colorCross );
  27779. addLine( 'cf3', 'cf4', colorCross );
  27780. function addLine( a, b, color ) {
  27781. addPoint( a, color );
  27782. addPoint( b, color );
  27783. }
  27784. function addPoint( id, color ) {
  27785. vertices.push( 0, 0, 0 );
  27786. colors.push( color.r, color.g, color.b );
  27787. if ( pointMap[ id ] === undefined ) {
  27788. pointMap[ id ] = [];
  27789. }
  27790. pointMap[ id ].push( ( vertices.length / 3 ) - 1 );
  27791. }
  27792. geometry.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  27793. geometry.addAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  27794. LineSegments.call( this, geometry, material );
  27795. this.camera = camera;
  27796. if ( this.camera.updateProjectionMatrix ) this.camera.updateProjectionMatrix();
  27797. this.matrix = camera.matrixWorld;
  27798. this.matrixAutoUpdate = false;
  27799. this.pointMap = pointMap;
  27800. this.update();
  27801. }
  27802. CameraHelper.prototype = Object.create( LineSegments.prototype );
  27803. CameraHelper.prototype.constructor = CameraHelper;
  27804. CameraHelper.prototype.update = function () {
  27805. var geometry, pointMap;
  27806. var vector = new Vector3();
  27807. var camera = new Camera();
  27808. function setPoint( point, x, y, z ) {
  27809. vector.set( x, y, z ).unproject( camera );
  27810. var points = pointMap[ point ];
  27811. if ( points !== undefined ) {
  27812. var position = geometry.getAttribute( 'position' );
  27813. for ( var i = 0, l = points.length; i < l; i ++ ) {
  27814. position.setXYZ( points[ i ], vector.x, vector.y, vector.z );
  27815. }
  27816. }
  27817. }
  27818. return function update() {
  27819. geometry = this.geometry;
  27820. pointMap = this.pointMap;
  27821. var w = 1, h = 1;
  27822. // we need just camera projection matrix inverse
  27823. // world matrix must be identity
  27824. camera.projectionMatrixInverse.copy( this.camera.projectionMatrixInverse );
  27825. // center / target
  27826. setPoint( 'c', 0, 0, - 1 );
  27827. setPoint( 't', 0, 0, 1 );
  27828. // near
  27829. setPoint( 'n1', - w, - h, - 1 );
  27830. setPoint( 'n2', w, - h, - 1 );
  27831. setPoint( 'n3', - w, h, - 1 );
  27832. setPoint( 'n4', w, h, - 1 );
  27833. // far
  27834. setPoint( 'f1', - w, - h, 1 );
  27835. setPoint( 'f2', w, - h, 1 );
  27836. setPoint( 'f3', - w, h, 1 );
  27837. setPoint( 'f4', w, h, 1 );
  27838. // up
  27839. setPoint( 'u1', w * 0.7, h * 1.1, - 1 );
  27840. setPoint( 'u2', - w * 0.7, h * 1.1, - 1 );
  27841. setPoint( 'u3', 0, h * 2, - 1 );
  27842. // cross
  27843. setPoint( 'cf1', - w, 0, 1 );
  27844. setPoint( 'cf2', w, 0, 1 );
  27845. setPoint( 'cf3', 0, - h, 1 );
  27846. setPoint( 'cf4', 0, h, 1 );
  27847. setPoint( 'cn1', - w, 0, - 1 );
  27848. setPoint( 'cn2', w, 0, - 1 );
  27849. setPoint( 'cn3', 0, - h, - 1 );
  27850. setPoint( 'cn4', 0, h, - 1 );
  27851. geometry.getAttribute( 'position' ).needsUpdate = true;
  27852. };
  27853. }();
  27854. /**
  27855. * @author mrdoob / http://mrdoob.com/
  27856. * @author Mugen87 / http://github.com/Mugen87
  27857. */
  27858. function BoxHelper( object, color ) {
  27859. this.object = object;
  27860. if ( color === undefined ) color = 0xffff00;
  27861. 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 ] );
  27862. var positions = new Float32Array( 8 * 3 );
  27863. var geometry = new BufferGeometry();
  27864. geometry.setIndex( new BufferAttribute( indices, 1 ) );
  27865. geometry.addAttribute( 'position', new BufferAttribute( positions, 3 ) );
  27866. LineSegments.call( this, geometry, new LineBasicMaterial( { color: color } ) );
  27867. this.matrixAutoUpdate = false;
  27868. this.update();
  27869. }
  27870. BoxHelper.prototype = Object.create( LineSegments.prototype );
  27871. BoxHelper.prototype.constructor = BoxHelper;
  27872. BoxHelper.prototype.update = ( function () {
  27873. var box = new Box3();
  27874. return function update( object ) {
  27875. if ( object !== undefined ) {
  27876. console.warn( 'THREE.BoxHelper: .update() has no longer arguments.' );
  27877. }
  27878. if ( this.object !== undefined ) {
  27879. box.setFromObject( this.object );
  27880. }
  27881. if ( box.isEmpty() ) return;
  27882. var min = box.min;
  27883. var max = box.max;
  27884. /*
  27885. 5____4
  27886. 1/___0/|
  27887. | 6__|_7
  27888. 2/___3/
  27889. 0: max.x, max.y, max.z
  27890. 1: min.x, max.y, max.z
  27891. 2: min.x, min.y, max.z
  27892. 3: max.x, min.y, max.z
  27893. 4: max.x, max.y, min.z
  27894. 5: min.x, max.y, min.z
  27895. 6: min.x, min.y, min.z
  27896. 7: max.x, min.y, min.z
  27897. */
  27898. var position = this.geometry.attributes.position;
  27899. var array = position.array;
  27900. array[ 0 ] = max.x; array[ 1 ] = max.y; array[ 2 ] = max.z;
  27901. array[ 3 ] = min.x; array[ 4 ] = max.y; array[ 5 ] = max.z;
  27902. array[ 6 ] = min.x; array[ 7 ] = min.y; array[ 8 ] = max.z;
  27903. array[ 9 ] = max.x; array[ 10 ] = min.y; array[ 11 ] = max.z;
  27904. array[ 12 ] = max.x; array[ 13 ] = max.y; array[ 14 ] = min.z;
  27905. array[ 15 ] = min.x; array[ 16 ] = max.y; array[ 17 ] = min.z;
  27906. array[ 18 ] = min.x; array[ 19 ] = min.y; array[ 20 ] = min.z;
  27907. array[ 21 ] = max.x; array[ 22 ] = min.y; array[ 23 ] = min.z;
  27908. position.needsUpdate = true;
  27909. this.geometry.computeBoundingSphere();
  27910. };
  27911. } )();
  27912. BoxHelper.prototype.setFromObject = function ( object ) {
  27913. this.object = object;
  27914. this.update();
  27915. return this;
  27916. };
  27917. BoxHelper.prototype.copy = function ( source ) {
  27918. LineSegments.prototype.copy.call( this, source );
  27919. this.object = source.object;
  27920. return this;
  27921. };
  27922. BoxHelper.prototype.clone = function () {
  27923. return new this.constructor().copy( this );
  27924. };
  27925. /**
  27926. * @author WestLangley / http://github.com/WestLangley
  27927. */
  27928. function Box3Helper( box, color ) {
  27929. this.type = 'Box3Helper';
  27930. this.box = box;
  27931. color = color || 0xffff00;
  27932. 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 ] );
  27933. 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 ];
  27934. var geometry = new BufferGeometry();
  27935. geometry.setIndex( new BufferAttribute( indices, 1 ) );
  27936. geometry.addAttribute( 'position', new Float32BufferAttribute( positions, 3 ) );
  27937. LineSegments.call( this, geometry, new LineBasicMaterial( { color: color } ) );
  27938. this.geometry.computeBoundingSphere();
  27939. }
  27940. Box3Helper.prototype = Object.create( LineSegments.prototype );
  27941. Box3Helper.prototype.constructor = Box3Helper;
  27942. Box3Helper.prototype.updateMatrixWorld = function ( force ) {
  27943. var box = this.box;
  27944. if ( box.isEmpty() ) return;
  27945. box.getCenter( this.position );
  27946. box.getSize( this.scale );
  27947. this.scale.multiplyScalar( 0.5 );
  27948. Object3D.prototype.updateMatrixWorld.call( this, force );
  27949. };
  27950. /**
  27951. * @author WestLangley / http://github.com/WestLangley
  27952. */
  27953. function PlaneHelper( plane, size, hex ) {
  27954. this.type = 'PlaneHelper';
  27955. this.plane = plane;
  27956. this.size = ( size === undefined ) ? 1 : size;
  27957. var color = ( hex !== undefined ) ? hex : 0xffff00;
  27958. 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 ];
  27959. var geometry = new BufferGeometry();
  27960. geometry.addAttribute( 'position', new Float32BufferAttribute( positions, 3 ) );
  27961. geometry.computeBoundingSphere();
  27962. Line.call( this, geometry, new LineBasicMaterial( { color: color } ) );
  27963. //
  27964. var positions2 = [ 1, 1, 1, - 1, 1, 1, - 1, - 1, 1, 1, 1, 1, - 1, - 1, 1, 1, - 1, 1 ];
  27965. var geometry2 = new BufferGeometry();
  27966. geometry2.addAttribute( 'position', new Float32BufferAttribute( positions2, 3 ) );
  27967. geometry2.computeBoundingSphere();
  27968. this.add( new Mesh( geometry2, new MeshBasicMaterial( { color: color, opacity: 0.2, transparent: true, depthWrite: false } ) ) );
  27969. }
  27970. PlaneHelper.prototype = Object.create( Line.prototype );
  27971. PlaneHelper.prototype.constructor = PlaneHelper;
  27972. PlaneHelper.prototype.updateMatrixWorld = function ( force ) {
  27973. var scale = - this.plane.constant;
  27974. if ( Math.abs( scale ) < 1e-8 ) scale = 1e-8; // sign does not matter
  27975. this.scale.set( 0.5 * this.size, 0.5 * this.size, scale );
  27976. this.children[ 0 ].material.side = ( scale < 0 ) ? BackSide : FrontSide; // renderer flips side when determinant < 0; flipping not wanted here
  27977. this.lookAt( this.plane.normal );
  27978. Object3D.prototype.updateMatrixWorld.call( this, force );
  27979. };
  27980. /**
  27981. * @author WestLangley / http://github.com/WestLangley
  27982. * @author zz85 / http://github.com/zz85
  27983. * @author bhouston / http://clara.io
  27984. *
  27985. * Creates an arrow for visualizing directions
  27986. *
  27987. * Parameters:
  27988. * dir - Vector3
  27989. * origin - Vector3
  27990. * length - Number
  27991. * color - color in hex value
  27992. * headLength - Number
  27993. * headWidth - Number
  27994. */
  27995. var lineGeometry, coneGeometry;
  27996. function ArrowHelper( dir, origin, length, color, headLength, headWidth ) {
  27997. // dir is assumed to be normalized
  27998. Object3D.call( this );
  27999. if ( dir === undefined ) dir = new Vector3( 0, 0, 1 );
  28000. if ( origin === undefined ) origin = new Vector3( 0, 0, 0 );
  28001. if ( length === undefined ) length = 1;
  28002. if ( color === undefined ) color = 0xffff00;
  28003. if ( headLength === undefined ) headLength = 0.2 * length;
  28004. if ( headWidth === undefined ) headWidth = 0.2 * headLength;
  28005. if ( lineGeometry === undefined ) {
  28006. lineGeometry = new BufferGeometry();
  28007. lineGeometry.addAttribute( 'position', new Float32BufferAttribute( [ 0, 0, 0, 0, 1, 0 ], 3 ) );
  28008. coneGeometry = new CylinderBufferGeometry( 0, 0.5, 1, 5, 1 );
  28009. coneGeometry.translate( 0, - 0.5, 0 );
  28010. }
  28011. this.position.copy( origin );
  28012. this.line = new Line( lineGeometry, new LineBasicMaterial( { color: color } ) );
  28013. this.line.matrixAutoUpdate = false;
  28014. this.add( this.line );
  28015. this.cone = new Mesh( coneGeometry, new MeshBasicMaterial( { color: color } ) );
  28016. this.cone.matrixAutoUpdate = false;
  28017. this.add( this.cone );
  28018. this.setDirection( dir );
  28019. this.setLength( length, headLength, headWidth );
  28020. }
  28021. ArrowHelper.prototype = Object.create( Object3D.prototype );
  28022. ArrowHelper.prototype.constructor = ArrowHelper;
  28023. ArrowHelper.prototype.setDirection = ( function () {
  28024. var axis = new Vector3();
  28025. var radians;
  28026. return function setDirection( dir ) {
  28027. // dir is assumed to be normalized
  28028. if ( dir.y > 0.99999 ) {
  28029. this.quaternion.set( 0, 0, 0, 1 );
  28030. } else if ( dir.y < - 0.99999 ) {
  28031. this.quaternion.set( 1, 0, 0, 0 );
  28032. } else {
  28033. axis.set( dir.z, 0, - dir.x ).normalize();
  28034. radians = Math.acos( dir.y );
  28035. this.quaternion.setFromAxisAngle( axis, radians );
  28036. }
  28037. };
  28038. }() );
  28039. ArrowHelper.prototype.setLength = function ( length, headLength, headWidth ) {
  28040. if ( headLength === undefined ) headLength = 0.2 * length;
  28041. if ( headWidth === undefined ) headWidth = 0.2 * headLength;
  28042. this.line.scale.set( 1, Math.max( 0, length - headLength ), 1 );
  28043. this.line.updateMatrix();
  28044. this.cone.scale.set( headWidth, headLength, headWidth );
  28045. this.cone.position.y = length;
  28046. this.cone.updateMatrix();
  28047. };
  28048. ArrowHelper.prototype.setColor = function ( color ) {
  28049. this.line.material.color.set( color );
  28050. this.cone.material.color.set( color );
  28051. };
  28052. ArrowHelper.prototype.copy = function ( source ) {
  28053. Object3D.prototype.copy.call( this, source, false );
  28054. this.line.copy( source.line );
  28055. this.cone.copy( source.cone );
  28056. return this;
  28057. };
  28058. ArrowHelper.prototype.clone = function () {
  28059. return new this.constructor().copy( this );
  28060. };
  28061. /**
  28062. * @author sroucheray / http://sroucheray.org/
  28063. * @author mrdoob / http://mrdoob.com/
  28064. */
  28065. function AxesHelper( size ) {
  28066. size = size || 1;
  28067. var vertices = [
  28068. 0, 0, 0, size, 0, 0,
  28069. 0, 0, 0, 0, size, 0,
  28070. 0, 0, 0, 0, 0, size
  28071. ];
  28072. var colors = [
  28073. 1, 0, 0, 1, 0.6, 0,
  28074. 0, 1, 0, 0.6, 1, 0,
  28075. 0, 0, 1, 0, 0.6, 1
  28076. ];
  28077. var geometry = new BufferGeometry();
  28078. geometry.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  28079. geometry.addAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  28080. var material = new LineBasicMaterial( { vertexColors: VertexColors } );
  28081. LineSegments.call( this, geometry, material );
  28082. }
  28083. AxesHelper.prototype = Object.create( LineSegments.prototype );
  28084. AxesHelper.prototype.constructor = AxesHelper;
  28085. /**
  28086. * @author mrdoob / http://mrdoob.com/
  28087. */
  28088. function Face4( a, b, c, d, normal, color, materialIndex ) {
  28089. console.warn( 'THREE.Face4 has been removed. A THREE.Face3 will be created instead.' );
  28090. return new Face3( a, b, c, normal, color, materialIndex );
  28091. }
  28092. var LineStrip = 0;
  28093. var LinePieces = 1;
  28094. function MeshFaceMaterial( materials ) {
  28095. console.warn( 'THREE.MeshFaceMaterial has been removed. Use an Array instead.' );
  28096. return materials;
  28097. }
  28098. function MultiMaterial( materials ) {
  28099. if ( materials === undefined ) materials = [];
  28100. console.warn( 'THREE.MultiMaterial has been removed. Use an Array instead.' );
  28101. materials.isMultiMaterial = true;
  28102. materials.materials = materials;
  28103. materials.clone = function () {
  28104. return materials.slice();
  28105. };
  28106. return materials;
  28107. }
  28108. function PointCloud( geometry, material ) {
  28109. console.warn( 'THREE.PointCloud has been renamed to THREE.Points.' );
  28110. return new Points( geometry, material );
  28111. }
  28112. function Particle( material ) {
  28113. console.warn( 'THREE.Particle has been renamed to THREE.Sprite.' );
  28114. return new Sprite( material );
  28115. }
  28116. function ParticleSystem( geometry, material ) {
  28117. console.warn( 'THREE.ParticleSystem has been renamed to THREE.Points.' );
  28118. return new Points( geometry, material );
  28119. }
  28120. function PointCloudMaterial( parameters ) {
  28121. console.warn( 'THREE.PointCloudMaterial has been renamed to THREE.PointsMaterial.' );
  28122. return new PointsMaterial( parameters );
  28123. }
  28124. function ParticleBasicMaterial( parameters ) {
  28125. console.warn( 'THREE.ParticleBasicMaterial has been renamed to THREE.PointsMaterial.' );
  28126. return new PointsMaterial( parameters );
  28127. }
  28128. function ParticleSystemMaterial( parameters ) {
  28129. console.warn( 'THREE.ParticleSystemMaterial has been renamed to THREE.PointsMaterial.' );
  28130. return new PointsMaterial( parameters );
  28131. }
  28132. function Vertex( x, y, z ) {
  28133. console.warn( 'THREE.Vertex has been removed. Use THREE.Vector3 instead.' );
  28134. return new Vector3( x, y, z );
  28135. }
  28136. //
  28137. function DynamicBufferAttribute( array, itemSize ) {
  28138. console.warn( 'THREE.DynamicBufferAttribute has been removed. Use new THREE.BufferAttribute().setDynamic( true ) instead.' );
  28139. return new BufferAttribute( array, itemSize ).setDynamic( true );
  28140. }
  28141. function Int8Attribute( array, itemSize ) {
  28142. console.warn( 'THREE.Int8Attribute has been removed. Use new THREE.Int8BufferAttribute() instead.' );
  28143. return new Int8BufferAttribute( array, itemSize );
  28144. }
  28145. function Uint8Attribute( array, itemSize ) {
  28146. console.warn( 'THREE.Uint8Attribute has been removed. Use new THREE.Uint8BufferAttribute() instead.' );
  28147. return new Uint8BufferAttribute( array, itemSize );
  28148. }
  28149. function Uint8ClampedAttribute( array, itemSize ) {
  28150. console.warn( 'THREE.Uint8ClampedAttribute has been removed. Use new THREE.Uint8ClampedBufferAttribute() instead.' );
  28151. return new Uint8ClampedBufferAttribute( array, itemSize );
  28152. }
  28153. function Int16Attribute( array, itemSize ) {
  28154. console.warn( 'THREE.Int16Attribute has been removed. Use new THREE.Int16BufferAttribute() instead.' );
  28155. return new Int16BufferAttribute( array, itemSize );
  28156. }
  28157. function Uint16Attribute( array, itemSize ) {
  28158. console.warn( 'THREE.Uint16Attribute has been removed. Use new THREE.Uint16BufferAttribute() instead.' );
  28159. return new Uint16BufferAttribute( array, itemSize );
  28160. }
  28161. function Int32Attribute( array, itemSize ) {
  28162. console.warn( 'THREE.Int32Attribute has been removed. Use new THREE.Int32BufferAttribute() instead.' );
  28163. return new Int32BufferAttribute( array, itemSize );
  28164. }
  28165. function Uint32Attribute( array, itemSize ) {
  28166. console.warn( 'THREE.Uint32Attribute has been removed. Use new THREE.Uint32BufferAttribute() instead.' );
  28167. return new Uint32BufferAttribute( array, itemSize );
  28168. }
  28169. function Float32Attribute( array, itemSize ) {
  28170. console.warn( 'THREE.Float32Attribute has been removed. Use new THREE.Float32BufferAttribute() instead.' );
  28171. return new Float32BufferAttribute( array, itemSize );
  28172. }
  28173. function Float64Attribute( array, itemSize ) {
  28174. console.warn( 'THREE.Float64Attribute has been removed. Use new THREE.Float64BufferAttribute() instead.' );
  28175. return new Float64BufferAttribute( array, itemSize );
  28176. }
  28177. //
  28178. Curve.create = function ( construct, getPoint ) {
  28179. console.log( 'THREE.Curve.create() has been deprecated' );
  28180. construct.prototype = Object.create( Curve.prototype );
  28181. construct.prototype.constructor = construct;
  28182. construct.prototype.getPoint = getPoint;
  28183. return construct;
  28184. };
  28185. //
  28186. Object.assign( CurvePath.prototype, {
  28187. createPointsGeometry: function ( divisions ) {
  28188. console.warn( 'THREE.CurvePath: .createPointsGeometry() has been removed. Use new THREE.Geometry().setFromPoints( points ) instead.' );
  28189. // generate geometry from path points (for Line or Points objects)
  28190. var pts = this.getPoints( divisions );
  28191. return this.createGeometry( pts );
  28192. },
  28193. createSpacedPointsGeometry: function ( divisions ) {
  28194. console.warn( 'THREE.CurvePath: .createSpacedPointsGeometry() has been removed. Use new THREE.Geometry().setFromPoints( points ) instead.' );
  28195. // generate geometry from equidistant sampling along the path
  28196. var pts = this.getSpacedPoints( divisions );
  28197. return this.createGeometry( pts );
  28198. },
  28199. createGeometry: function ( points ) {
  28200. console.warn( 'THREE.CurvePath: .createGeometry() has been removed. Use new THREE.Geometry().setFromPoints( points ) instead.' );
  28201. var geometry = new Geometry();
  28202. for ( var i = 0, l = points.length; i < l; i ++ ) {
  28203. var point = points[ i ];
  28204. geometry.vertices.push( new Vector3( point.x, point.y, point.z || 0 ) );
  28205. }
  28206. return geometry;
  28207. }
  28208. } );
  28209. //
  28210. Object.assign( Path.prototype, {
  28211. fromPoints: function ( points ) {
  28212. console.warn( 'THREE.Path: .fromPoints() has been renamed to .setFromPoints().' );
  28213. this.setFromPoints( points );
  28214. }
  28215. } );
  28216. //
  28217. function ClosedSplineCurve3( points ) {
  28218. console.warn( 'THREE.ClosedSplineCurve3 has been deprecated. Use THREE.CatmullRomCurve3 instead.' );
  28219. CatmullRomCurve3.call( this, points );
  28220. this.type = 'catmullrom';
  28221. this.closed = true;
  28222. }
  28223. ClosedSplineCurve3.prototype = Object.create( CatmullRomCurve3.prototype );
  28224. //
  28225. function SplineCurve3( points ) {
  28226. console.warn( 'THREE.SplineCurve3 has been deprecated. Use THREE.CatmullRomCurve3 instead.' );
  28227. CatmullRomCurve3.call( this, points );
  28228. this.type = 'catmullrom';
  28229. }
  28230. SplineCurve3.prototype = Object.create( CatmullRomCurve3.prototype );
  28231. //
  28232. function Spline( points ) {
  28233. console.warn( 'THREE.Spline has been removed. Use THREE.CatmullRomCurve3 instead.' );
  28234. CatmullRomCurve3.call( this, points );
  28235. this.type = 'catmullrom';
  28236. }
  28237. Spline.prototype = Object.create( CatmullRomCurve3.prototype );
  28238. Object.assign( Spline.prototype, {
  28239. initFromArray: function ( /* a */ ) {
  28240. console.error( 'THREE.Spline: .initFromArray() has been removed.' );
  28241. },
  28242. getControlPointsArray: function ( /* optionalTarget */ ) {
  28243. console.error( 'THREE.Spline: .getControlPointsArray() has been removed.' );
  28244. },
  28245. reparametrizeByArcLength: function ( /* samplingCoef */ ) {
  28246. console.error( 'THREE.Spline: .reparametrizeByArcLength() has been removed.' );
  28247. }
  28248. } );
  28249. //
  28250. function AxisHelper( size ) {
  28251. console.warn( 'THREE.AxisHelper has been renamed to THREE.AxesHelper.' );
  28252. return new AxesHelper( size );
  28253. }
  28254. function BoundingBoxHelper( object, color ) {
  28255. console.warn( 'THREE.BoundingBoxHelper has been deprecated. Creating a THREE.BoxHelper instead.' );
  28256. return new BoxHelper( object, color );
  28257. }
  28258. function EdgesHelper( object, hex ) {
  28259. console.warn( 'THREE.EdgesHelper has been removed. Use THREE.EdgesGeometry instead.' );
  28260. return new LineSegments( new EdgesGeometry( object.geometry ), new LineBasicMaterial( { color: hex !== undefined ? hex : 0xffffff } ) );
  28261. }
  28262. GridHelper.prototype.setColors = function () {
  28263. console.error( 'THREE.GridHelper: setColors() has been deprecated, pass them in the constructor instead.' );
  28264. };
  28265. SkeletonHelper.prototype.update = function () {
  28266. console.error( 'THREE.SkeletonHelper: update() no longer needs to be called.' );
  28267. };
  28268. function WireframeHelper( object, hex ) {
  28269. console.warn( 'THREE.WireframeHelper has been removed. Use THREE.WireframeGeometry instead.' );
  28270. return new LineSegments( new WireframeGeometry( object.geometry ), new LineBasicMaterial( { color: hex !== undefined ? hex : 0xffffff } ) );
  28271. }
  28272. //
  28273. Object.assign( Loader.prototype, {
  28274. extractUrlBase: function ( url ) {
  28275. console.warn( 'THREE.Loader: .extractUrlBase() has been deprecated. Use THREE.LoaderUtils.extractUrlBase() instead.' );
  28276. return LoaderUtils.extractUrlBase( url );
  28277. }
  28278. } );
  28279. function XHRLoader( manager ) {
  28280. console.warn( 'THREE.XHRLoader has been renamed to THREE.FileLoader.' );
  28281. return new FileLoader( manager );
  28282. }
  28283. function BinaryTextureLoader( manager ) {
  28284. console.warn( 'THREE.BinaryTextureLoader has been renamed to THREE.DataTextureLoader.' );
  28285. return new DataTextureLoader( manager );
  28286. }
  28287. Object.assign( ObjectLoader.prototype, {
  28288. setTexturePath: function ( value ) {
  28289. console.warn( 'THREE.ObjectLoader: .setTexturePath() has been renamed to .setResourcePath().' );
  28290. return this.setResourcePath( value );
  28291. }
  28292. } );
  28293. //
  28294. Object.assign( Box2.prototype, {
  28295. center: function ( optionalTarget ) {
  28296. console.warn( 'THREE.Box2: .center() has been renamed to .getCenter().' );
  28297. return this.getCenter( optionalTarget );
  28298. },
  28299. empty: function () {
  28300. console.warn( 'THREE.Box2: .empty() has been renamed to .isEmpty().' );
  28301. return this.isEmpty();
  28302. },
  28303. isIntersectionBox: function ( box ) {
  28304. console.warn( 'THREE.Box2: .isIntersectionBox() has been renamed to .intersectsBox().' );
  28305. return this.intersectsBox( box );
  28306. },
  28307. size: function ( optionalTarget ) {
  28308. console.warn( 'THREE.Box2: .size() has been renamed to .getSize().' );
  28309. return this.getSize( optionalTarget );
  28310. }
  28311. } );
  28312. Object.assign( Box3.prototype, {
  28313. center: function ( optionalTarget ) {
  28314. console.warn( 'THREE.Box3: .center() has been renamed to .getCenter().' );
  28315. return this.getCenter( optionalTarget );
  28316. },
  28317. empty: function () {
  28318. console.warn( 'THREE.Box3: .empty() has been renamed to .isEmpty().' );
  28319. return this.isEmpty();
  28320. },
  28321. isIntersectionBox: function ( box ) {
  28322. console.warn( 'THREE.Box3: .isIntersectionBox() has been renamed to .intersectsBox().' );
  28323. return this.intersectsBox( box );
  28324. },
  28325. isIntersectionSphere: function ( sphere ) {
  28326. console.warn( 'THREE.Box3: .isIntersectionSphere() has been renamed to .intersectsSphere().' );
  28327. return this.intersectsSphere( sphere );
  28328. },
  28329. size: function ( optionalTarget ) {
  28330. console.warn( 'THREE.Box3: .size() has been renamed to .getSize().' );
  28331. return this.getSize( optionalTarget );
  28332. }
  28333. } );
  28334. Line3.prototype.center = function ( optionalTarget ) {
  28335. console.warn( 'THREE.Line3: .center() has been renamed to .getCenter().' );
  28336. return this.getCenter( optionalTarget );
  28337. };
  28338. Object.assign( _Math, {
  28339. random16: function () {
  28340. console.warn( 'THREE.Math: .random16() has been deprecated. Use Math.random() instead.' );
  28341. return Math.random();
  28342. },
  28343. nearestPowerOfTwo: function ( value ) {
  28344. console.warn( 'THREE.Math: .nearestPowerOfTwo() has been renamed to .floorPowerOfTwo().' );
  28345. return _Math.floorPowerOfTwo( value );
  28346. },
  28347. nextPowerOfTwo: function ( value ) {
  28348. console.warn( 'THREE.Math: .nextPowerOfTwo() has been renamed to .ceilPowerOfTwo().' );
  28349. return _Math.ceilPowerOfTwo( value );
  28350. }
  28351. } );
  28352. Object.assign( Matrix3.prototype, {
  28353. flattenToArrayOffset: function ( array, offset ) {
  28354. console.warn( "THREE.Matrix3: .flattenToArrayOffset() has been deprecated. Use .toArray() instead." );
  28355. return this.toArray( array, offset );
  28356. },
  28357. multiplyVector3: function ( vector ) {
  28358. console.warn( 'THREE.Matrix3: .multiplyVector3() has been removed. Use vector.applyMatrix3( matrix ) instead.' );
  28359. return vector.applyMatrix3( this );
  28360. },
  28361. multiplyVector3Array: function ( /* a */ ) {
  28362. console.error( 'THREE.Matrix3: .multiplyVector3Array() has been removed.' );
  28363. },
  28364. applyToBuffer: function ( buffer /*, offset, length */ ) {
  28365. console.warn( 'THREE.Matrix3: .applyToBuffer() has been removed. Use matrix.applyToBufferAttribute( attribute ) instead.' );
  28366. return this.applyToBufferAttribute( buffer );
  28367. },
  28368. applyToVector3Array: function ( /* array, offset, length */ ) {
  28369. console.error( 'THREE.Matrix3: .applyToVector3Array() has been removed.' );
  28370. }
  28371. } );
  28372. Object.assign( Matrix4.prototype, {
  28373. extractPosition: function ( m ) {
  28374. console.warn( 'THREE.Matrix4: .extractPosition() has been renamed to .copyPosition().' );
  28375. return this.copyPosition( m );
  28376. },
  28377. flattenToArrayOffset: function ( array, offset ) {
  28378. console.warn( "THREE.Matrix4: .flattenToArrayOffset() has been deprecated. Use .toArray() instead." );
  28379. return this.toArray( array, offset );
  28380. },
  28381. getPosition: function () {
  28382. var v1;
  28383. return function getPosition() {
  28384. if ( v1 === undefined ) v1 = new Vector3();
  28385. console.warn( 'THREE.Matrix4: .getPosition() has been removed. Use Vector3.setFromMatrixPosition( matrix ) instead.' );
  28386. return v1.setFromMatrixColumn( this, 3 );
  28387. };
  28388. }(),
  28389. setRotationFromQuaternion: function ( q ) {
  28390. console.warn( 'THREE.Matrix4: .setRotationFromQuaternion() has been renamed to .makeRotationFromQuaternion().' );
  28391. return this.makeRotationFromQuaternion( q );
  28392. },
  28393. multiplyToArray: function () {
  28394. console.warn( 'THREE.Matrix4: .multiplyToArray() has been removed.' );
  28395. },
  28396. multiplyVector3: function ( vector ) {
  28397. console.warn( 'THREE.Matrix4: .multiplyVector3() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
  28398. return vector.applyMatrix4( this );
  28399. },
  28400. multiplyVector4: function ( vector ) {
  28401. console.warn( 'THREE.Matrix4: .multiplyVector4() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
  28402. return vector.applyMatrix4( this );
  28403. },
  28404. multiplyVector3Array: function ( /* a */ ) {
  28405. console.error( 'THREE.Matrix4: .multiplyVector3Array() has been removed.' );
  28406. },
  28407. rotateAxis: function ( v ) {
  28408. console.warn( 'THREE.Matrix4: .rotateAxis() has been removed. Use Vector3.transformDirection( matrix ) instead.' );
  28409. v.transformDirection( this );
  28410. },
  28411. crossVector: function ( vector ) {
  28412. console.warn( 'THREE.Matrix4: .crossVector() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
  28413. return vector.applyMatrix4( this );
  28414. },
  28415. translate: function () {
  28416. console.error( 'THREE.Matrix4: .translate() has been removed.' );
  28417. },
  28418. rotateX: function () {
  28419. console.error( 'THREE.Matrix4: .rotateX() has been removed.' );
  28420. },
  28421. rotateY: function () {
  28422. console.error( 'THREE.Matrix4: .rotateY() has been removed.' );
  28423. },
  28424. rotateZ: function () {
  28425. console.error( 'THREE.Matrix4: .rotateZ() has been removed.' );
  28426. },
  28427. rotateByAxis: function () {
  28428. console.error( 'THREE.Matrix4: .rotateByAxis() has been removed.' );
  28429. },
  28430. applyToBuffer: function ( buffer /*, offset, length */ ) {
  28431. console.warn( 'THREE.Matrix4: .applyToBuffer() has been removed. Use matrix.applyToBufferAttribute( attribute ) instead.' );
  28432. return this.applyToBufferAttribute( buffer );
  28433. },
  28434. applyToVector3Array: function ( /* array, offset, length */ ) {
  28435. console.error( 'THREE.Matrix4: .applyToVector3Array() has been removed.' );
  28436. },
  28437. makeFrustum: function ( left, right, bottom, top, near, far ) {
  28438. console.warn( 'THREE.Matrix4: .makeFrustum() has been removed. Use .makePerspective( left, right, top, bottom, near, far ) instead.' );
  28439. return this.makePerspective( left, right, top, bottom, near, far );
  28440. }
  28441. } );
  28442. Plane.prototype.isIntersectionLine = function ( line ) {
  28443. console.warn( 'THREE.Plane: .isIntersectionLine() has been renamed to .intersectsLine().' );
  28444. return this.intersectsLine( line );
  28445. };
  28446. Quaternion.prototype.multiplyVector3 = function ( vector ) {
  28447. console.warn( 'THREE.Quaternion: .multiplyVector3() has been removed. Use is now vector.applyQuaternion( quaternion ) instead.' );
  28448. return vector.applyQuaternion( this );
  28449. };
  28450. Object.assign( Ray.prototype, {
  28451. isIntersectionBox: function ( box ) {
  28452. console.warn( 'THREE.Ray: .isIntersectionBox() has been renamed to .intersectsBox().' );
  28453. return this.intersectsBox( box );
  28454. },
  28455. isIntersectionPlane: function ( plane ) {
  28456. console.warn( 'THREE.Ray: .isIntersectionPlane() has been renamed to .intersectsPlane().' );
  28457. return this.intersectsPlane( plane );
  28458. },
  28459. isIntersectionSphere: function ( sphere ) {
  28460. console.warn( 'THREE.Ray: .isIntersectionSphere() has been renamed to .intersectsSphere().' );
  28461. return this.intersectsSphere( sphere );
  28462. }
  28463. } );
  28464. Object.assign( Triangle.prototype, {
  28465. area: function () {
  28466. console.warn( 'THREE.Triangle: .area() has been renamed to .getArea().' );
  28467. return this.getArea();
  28468. },
  28469. barycoordFromPoint: function ( point, target ) {
  28470. console.warn( 'THREE.Triangle: .barycoordFromPoint() has been renamed to .getBarycoord().' );
  28471. return this.getBarycoord( point, target );
  28472. },
  28473. midpoint: function ( target ) {
  28474. console.warn( 'THREE.Triangle: .midpoint() has been renamed to .getMidpoint().' );
  28475. return this.getMidpoint( target );
  28476. },
  28477. normal: function ( target ) {
  28478. console.warn( 'THREE.Triangle: .normal() has been renamed to .getNormal().' );
  28479. return this.getNormal( target );
  28480. },
  28481. plane: function ( target ) {
  28482. console.warn( 'THREE.Triangle: .plane() has been renamed to .getPlane().' );
  28483. return this.getPlane( target );
  28484. }
  28485. } );
  28486. Object.assign( Triangle, {
  28487. barycoordFromPoint: function ( point, a, b, c, target ) {
  28488. console.warn( 'THREE.Triangle: .barycoordFromPoint() has been renamed to .getBarycoord().' );
  28489. return Triangle.getBarycoord( point, a, b, c, target );
  28490. },
  28491. normal: function ( a, b, c, target ) {
  28492. console.warn( 'THREE.Triangle: .normal() has been renamed to .getNormal().' );
  28493. return Triangle.getNormal( a, b, c, target );
  28494. }
  28495. } );
  28496. Object.assign( Shape.prototype, {
  28497. extractAllPoints: function ( divisions ) {
  28498. console.warn( 'THREE.Shape: .extractAllPoints() has been removed. Use .extractPoints() instead.' );
  28499. return this.extractPoints( divisions );
  28500. },
  28501. extrude: function ( options ) {
  28502. console.warn( 'THREE.Shape: .extrude() has been removed. Use ExtrudeGeometry() instead.' );
  28503. return new ExtrudeGeometry( this, options );
  28504. },
  28505. makeGeometry: function ( options ) {
  28506. console.warn( 'THREE.Shape: .makeGeometry() has been removed. Use ShapeGeometry() instead.' );
  28507. return new ShapeGeometry( this, options );
  28508. }
  28509. } );
  28510. Object.assign( Vector2.prototype, {
  28511. fromAttribute: function ( attribute, index, offset ) {
  28512. console.warn( 'THREE.Vector2: .fromAttribute() has been renamed to .fromBufferAttribute().' );
  28513. return this.fromBufferAttribute( attribute, index, offset );
  28514. },
  28515. distanceToManhattan: function ( v ) {
  28516. console.warn( 'THREE.Vector2: .distanceToManhattan() has been renamed to .manhattanDistanceTo().' );
  28517. return this.manhattanDistanceTo( v );
  28518. },
  28519. lengthManhattan: function () {
  28520. console.warn( 'THREE.Vector2: .lengthManhattan() has been renamed to .manhattanLength().' );
  28521. return this.manhattanLength();
  28522. }
  28523. } );
  28524. Object.assign( Vector3.prototype, {
  28525. setEulerFromRotationMatrix: function () {
  28526. console.error( 'THREE.Vector3: .setEulerFromRotationMatrix() has been removed. Use Euler.setFromRotationMatrix() instead.' );
  28527. },
  28528. setEulerFromQuaternion: function () {
  28529. console.error( 'THREE.Vector3: .setEulerFromQuaternion() has been removed. Use Euler.setFromQuaternion() instead.' );
  28530. },
  28531. getPositionFromMatrix: function ( m ) {
  28532. console.warn( 'THREE.Vector3: .getPositionFromMatrix() has been renamed to .setFromMatrixPosition().' );
  28533. return this.setFromMatrixPosition( m );
  28534. },
  28535. getScaleFromMatrix: function ( m ) {
  28536. console.warn( 'THREE.Vector3: .getScaleFromMatrix() has been renamed to .setFromMatrixScale().' );
  28537. return this.setFromMatrixScale( m );
  28538. },
  28539. getColumnFromMatrix: function ( index, matrix ) {
  28540. console.warn( 'THREE.Vector3: .getColumnFromMatrix() has been renamed to .setFromMatrixColumn().' );
  28541. return this.setFromMatrixColumn( matrix, index );
  28542. },
  28543. applyProjection: function ( m ) {
  28544. console.warn( 'THREE.Vector3: .applyProjection() has been removed. Use .applyMatrix4( m ) instead.' );
  28545. return this.applyMatrix4( m );
  28546. },
  28547. fromAttribute: function ( attribute, index, offset ) {
  28548. console.warn( 'THREE.Vector3: .fromAttribute() has been renamed to .fromBufferAttribute().' );
  28549. return this.fromBufferAttribute( attribute, index, offset );
  28550. },
  28551. distanceToManhattan: function ( v ) {
  28552. console.warn( 'THREE.Vector3: .distanceToManhattan() has been renamed to .manhattanDistanceTo().' );
  28553. return this.manhattanDistanceTo( v );
  28554. },
  28555. lengthManhattan: function () {
  28556. console.warn( 'THREE.Vector3: .lengthManhattan() has been renamed to .manhattanLength().' );
  28557. return this.manhattanLength();
  28558. }
  28559. } );
  28560. Object.assign( Vector4.prototype, {
  28561. fromAttribute: function ( attribute, index, offset ) {
  28562. console.warn( 'THREE.Vector4: .fromAttribute() has been renamed to .fromBufferAttribute().' );
  28563. return this.fromBufferAttribute( attribute, index, offset );
  28564. },
  28565. lengthManhattan: function () {
  28566. console.warn( 'THREE.Vector4: .lengthManhattan() has been renamed to .manhattanLength().' );
  28567. return this.manhattanLength();
  28568. }
  28569. } );
  28570. //
  28571. Object.assign( Geometry.prototype, {
  28572. computeTangents: function () {
  28573. console.error( 'THREE.Geometry: .computeTangents() has been removed.' );
  28574. },
  28575. computeLineDistances: function () {
  28576. console.error( 'THREE.Geometry: .computeLineDistances() has been removed. Use THREE.Line.computeLineDistances() instead.' );
  28577. }
  28578. } );
  28579. Object.assign( Object3D.prototype, {
  28580. getChildByName: function ( name ) {
  28581. console.warn( 'THREE.Object3D: .getChildByName() has been renamed to .getObjectByName().' );
  28582. return this.getObjectByName( name );
  28583. },
  28584. renderDepth: function () {
  28585. console.warn( 'THREE.Object3D: .renderDepth has been removed. Use .renderOrder, instead.' );
  28586. },
  28587. translate: function ( distance, axis ) {
  28588. console.warn( 'THREE.Object3D: .translate() has been removed. Use .translateOnAxis( axis, distance ) instead.' );
  28589. return this.translateOnAxis( axis, distance );
  28590. },
  28591. getWorldRotation: function () {
  28592. console.error( 'THREE.Object3D: .getWorldRotation() has been removed. Use THREE.Object3D.getWorldQuaternion( target ) instead.' );
  28593. }
  28594. } );
  28595. Object.defineProperties( Object3D.prototype, {
  28596. eulerOrder: {
  28597. get: function () {
  28598. console.warn( 'THREE.Object3D: .eulerOrder is now .rotation.order.' );
  28599. return this.rotation.order;
  28600. },
  28601. set: function ( value ) {
  28602. console.warn( 'THREE.Object3D: .eulerOrder is now .rotation.order.' );
  28603. this.rotation.order = value;
  28604. }
  28605. },
  28606. useQuaternion: {
  28607. get: function () {
  28608. console.warn( 'THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.' );
  28609. },
  28610. set: function () {
  28611. console.warn( 'THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.' );
  28612. }
  28613. }
  28614. } );
  28615. Object.defineProperties( LOD.prototype, {
  28616. objects: {
  28617. get: function () {
  28618. console.warn( 'THREE.LOD: .objects has been renamed to .levels.' );
  28619. return this.levels;
  28620. }
  28621. }
  28622. } );
  28623. Object.defineProperty( Skeleton.prototype, 'useVertexTexture', {
  28624. get: function () {
  28625. console.warn( 'THREE.Skeleton: useVertexTexture has been removed.' );
  28626. },
  28627. set: function () {
  28628. console.warn( 'THREE.Skeleton: useVertexTexture has been removed.' );
  28629. }
  28630. } );
  28631. SkinnedMesh.prototype.initBones = function () {
  28632. console.error( 'THREE.SkinnedMesh: initBones() has been removed.' );
  28633. };
  28634. Object.defineProperty( Curve.prototype, '__arcLengthDivisions', {
  28635. get: function () {
  28636. console.warn( 'THREE.Curve: .__arcLengthDivisions is now .arcLengthDivisions.' );
  28637. return this.arcLengthDivisions;
  28638. },
  28639. set: function ( value ) {
  28640. console.warn( 'THREE.Curve: .__arcLengthDivisions is now .arcLengthDivisions.' );
  28641. this.arcLengthDivisions = value;
  28642. }
  28643. } );
  28644. //
  28645. PerspectiveCamera.prototype.setLens = function ( focalLength, filmGauge ) {
  28646. console.warn( "THREE.PerspectiveCamera.setLens is deprecated. " +
  28647. "Use .setFocalLength and .filmGauge for a photographic setup." );
  28648. if ( filmGauge !== undefined ) this.filmGauge = filmGauge;
  28649. this.setFocalLength( focalLength );
  28650. };
  28651. //
  28652. Object.defineProperties( Light.prototype, {
  28653. onlyShadow: {
  28654. set: function () {
  28655. console.warn( 'THREE.Light: .onlyShadow has been removed.' );
  28656. }
  28657. },
  28658. shadowCameraFov: {
  28659. set: function ( value ) {
  28660. console.warn( 'THREE.Light: .shadowCameraFov is now .shadow.camera.fov.' );
  28661. this.shadow.camera.fov = value;
  28662. }
  28663. },
  28664. shadowCameraLeft: {
  28665. set: function ( value ) {
  28666. console.warn( 'THREE.Light: .shadowCameraLeft is now .shadow.camera.left.' );
  28667. this.shadow.camera.left = value;
  28668. }
  28669. },
  28670. shadowCameraRight: {
  28671. set: function ( value ) {
  28672. console.warn( 'THREE.Light: .shadowCameraRight is now .shadow.camera.right.' );
  28673. this.shadow.camera.right = value;
  28674. }
  28675. },
  28676. shadowCameraTop: {
  28677. set: function ( value ) {
  28678. console.warn( 'THREE.Light: .shadowCameraTop is now .shadow.camera.top.' );
  28679. this.shadow.camera.top = value;
  28680. }
  28681. },
  28682. shadowCameraBottom: {
  28683. set: function ( value ) {
  28684. console.warn( 'THREE.Light: .shadowCameraBottom is now .shadow.camera.bottom.' );
  28685. this.shadow.camera.bottom = value;
  28686. }
  28687. },
  28688. shadowCameraNear: {
  28689. set: function ( value ) {
  28690. console.warn( 'THREE.Light: .shadowCameraNear is now .shadow.camera.near.' );
  28691. this.shadow.camera.near = value;
  28692. }
  28693. },
  28694. shadowCameraFar: {
  28695. set: function ( value ) {
  28696. console.warn( 'THREE.Light: .shadowCameraFar is now .shadow.camera.far.' );
  28697. this.shadow.camera.far = value;
  28698. }
  28699. },
  28700. shadowCameraVisible: {
  28701. set: function () {
  28702. console.warn( 'THREE.Light: .shadowCameraVisible has been removed. Use new THREE.CameraHelper( light.shadow.camera ) instead.' );
  28703. }
  28704. },
  28705. shadowBias: {
  28706. set: function ( value ) {
  28707. console.warn( 'THREE.Light: .shadowBias is now .shadow.bias.' );
  28708. this.shadow.bias = value;
  28709. }
  28710. },
  28711. shadowDarkness: {
  28712. set: function () {
  28713. console.warn( 'THREE.Light: .shadowDarkness has been removed.' );
  28714. }
  28715. },
  28716. shadowMapWidth: {
  28717. set: function ( value ) {
  28718. console.warn( 'THREE.Light: .shadowMapWidth is now .shadow.mapSize.width.' );
  28719. this.shadow.mapSize.width = value;
  28720. }
  28721. },
  28722. shadowMapHeight: {
  28723. set: function ( value ) {
  28724. console.warn( 'THREE.Light: .shadowMapHeight is now .shadow.mapSize.height.' );
  28725. this.shadow.mapSize.height = value;
  28726. }
  28727. }
  28728. } );
  28729. //
  28730. Object.defineProperties( BufferAttribute.prototype, {
  28731. length: {
  28732. get: function () {
  28733. console.warn( 'THREE.BufferAttribute: .length has been deprecated. Use .count instead.' );
  28734. return this.array.length;
  28735. }
  28736. },
  28737. copyIndicesArray: function ( /* indices */ ) {
  28738. console.error( 'THREE.BufferAttribute: .copyIndicesArray() has been removed.' );
  28739. }
  28740. } );
  28741. Object.assign( BufferGeometry.prototype, {
  28742. addIndex: function ( index ) {
  28743. console.warn( 'THREE.BufferGeometry: .addIndex() has been renamed to .setIndex().' );
  28744. this.setIndex( index );
  28745. },
  28746. addDrawCall: function ( start, count, indexOffset ) {
  28747. if ( indexOffset !== undefined ) {
  28748. console.warn( 'THREE.BufferGeometry: .addDrawCall() no longer supports indexOffset.' );
  28749. }
  28750. console.warn( 'THREE.BufferGeometry: .addDrawCall() is now .addGroup().' );
  28751. this.addGroup( start, count );
  28752. },
  28753. clearDrawCalls: function () {
  28754. console.warn( 'THREE.BufferGeometry: .clearDrawCalls() is now .clearGroups().' );
  28755. this.clearGroups();
  28756. },
  28757. computeTangents: function () {
  28758. console.warn( 'THREE.BufferGeometry: .computeTangents() has been removed.' );
  28759. },
  28760. computeOffsets: function () {
  28761. console.warn( 'THREE.BufferGeometry: .computeOffsets() has been removed.' );
  28762. }
  28763. } );
  28764. Object.defineProperties( BufferGeometry.prototype, {
  28765. drawcalls: {
  28766. get: function () {
  28767. console.error( 'THREE.BufferGeometry: .drawcalls has been renamed to .groups.' );
  28768. return this.groups;
  28769. }
  28770. },
  28771. offsets: {
  28772. get: function () {
  28773. console.warn( 'THREE.BufferGeometry: .offsets has been renamed to .groups.' );
  28774. return this.groups;
  28775. }
  28776. }
  28777. } );
  28778. //
  28779. Object.assign( ExtrudeBufferGeometry.prototype, {
  28780. getArrays: function () {
  28781. console.error( 'THREE.ExtrudeBufferGeometry: .getArrays() has been removed.' );
  28782. },
  28783. addShapeList: function () {
  28784. console.error( 'THREE.ExtrudeBufferGeometry: .addShapeList() has been removed.' );
  28785. },
  28786. addShape: function () {
  28787. console.error( 'THREE.ExtrudeBufferGeometry: .addShape() has been removed.' );
  28788. }
  28789. } );
  28790. //
  28791. Object.defineProperties( Uniform.prototype, {
  28792. dynamic: {
  28793. set: function () {
  28794. console.warn( 'THREE.Uniform: .dynamic has been removed. Use object.onBeforeRender() instead.' );
  28795. }
  28796. },
  28797. onUpdate: {
  28798. value: function () {
  28799. console.warn( 'THREE.Uniform: .onUpdate() has been removed. Use object.onBeforeRender() instead.' );
  28800. return this;
  28801. }
  28802. }
  28803. } );
  28804. //
  28805. Object.defineProperties( Material.prototype, {
  28806. wrapAround: {
  28807. get: function () {
  28808. console.warn( 'THREE.Material: .wrapAround has been removed.' );
  28809. },
  28810. set: function () {
  28811. console.warn( 'THREE.Material: .wrapAround has been removed.' );
  28812. }
  28813. },
  28814. overdraw: {
  28815. get: function () {
  28816. console.warn( 'THREE.Material: .overdraw has been removed.' );
  28817. },
  28818. set: function () {
  28819. console.warn( 'THREE.Material: .overdraw has been removed.' );
  28820. }
  28821. },
  28822. wrapRGB: {
  28823. get: function () {
  28824. console.warn( 'THREE.Material: .wrapRGB has been removed.' );
  28825. return new Color();
  28826. }
  28827. },
  28828. shading: {
  28829. get: function () {
  28830. console.error( 'THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.' );
  28831. },
  28832. set: function ( value ) {
  28833. console.warn( 'THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.' );
  28834. this.flatShading = ( value === FlatShading );
  28835. }
  28836. }
  28837. } );
  28838. Object.defineProperties( MeshPhongMaterial.prototype, {
  28839. metal: {
  28840. get: function () {
  28841. console.warn( 'THREE.MeshPhongMaterial: .metal has been removed. Use THREE.MeshStandardMaterial instead.' );
  28842. return false;
  28843. },
  28844. set: function () {
  28845. console.warn( 'THREE.MeshPhongMaterial: .metal has been removed. Use THREE.MeshStandardMaterial instead' );
  28846. }
  28847. }
  28848. } );
  28849. Object.defineProperties( ShaderMaterial.prototype, {
  28850. derivatives: {
  28851. get: function () {
  28852. console.warn( 'THREE.ShaderMaterial: .derivatives has been moved to .extensions.derivatives.' );
  28853. return this.extensions.derivatives;
  28854. },
  28855. set: function ( value ) {
  28856. console.warn( 'THREE. ShaderMaterial: .derivatives has been moved to .extensions.derivatives.' );
  28857. this.extensions.derivatives = value;
  28858. }
  28859. }
  28860. } );
  28861. //
  28862. Object.assign( WebGLRenderer.prototype, {
  28863. clearTarget: function ( renderTarget, color, depth, stencil ) {
  28864. console.warn( 'THREE.WebGLRenderer: .clearTarget() has been deprecated. Use .setRenderTarget() and .clear() instead.' );
  28865. this.setRenderTarget( renderTarget );
  28866. this.clear( color, depth, stencil );
  28867. },
  28868. animate: function ( callback ) {
  28869. console.warn( 'THREE.WebGLRenderer: .animate() is now .setAnimationLoop().' );
  28870. this.setAnimationLoop( callback );
  28871. },
  28872. getCurrentRenderTarget: function () {
  28873. console.warn( 'THREE.WebGLRenderer: .getCurrentRenderTarget() is now .getRenderTarget().' );
  28874. return this.getRenderTarget();
  28875. },
  28876. getMaxAnisotropy: function () {
  28877. console.warn( 'THREE.WebGLRenderer: .getMaxAnisotropy() is now .capabilities.getMaxAnisotropy().' );
  28878. return this.capabilities.getMaxAnisotropy();
  28879. },
  28880. getPrecision: function () {
  28881. console.warn( 'THREE.WebGLRenderer: .getPrecision() is now .capabilities.precision.' );
  28882. return this.capabilities.precision;
  28883. },
  28884. resetGLState: function () {
  28885. console.warn( 'THREE.WebGLRenderer: .resetGLState() is now .state.reset().' );
  28886. return this.state.reset();
  28887. },
  28888. supportsFloatTextures: function () {
  28889. console.warn( 'THREE.WebGLRenderer: .supportsFloatTextures() is now .extensions.get( \'OES_texture_float\' ).' );
  28890. return this.extensions.get( 'OES_texture_float' );
  28891. },
  28892. supportsHalfFloatTextures: function () {
  28893. console.warn( 'THREE.WebGLRenderer: .supportsHalfFloatTextures() is now .extensions.get( \'OES_texture_half_float\' ).' );
  28894. return this.extensions.get( 'OES_texture_half_float' );
  28895. },
  28896. supportsStandardDerivatives: function () {
  28897. console.warn( 'THREE.WebGLRenderer: .supportsStandardDerivatives() is now .extensions.get( \'OES_standard_derivatives\' ).' );
  28898. return this.extensions.get( 'OES_standard_derivatives' );
  28899. },
  28900. supportsCompressedTextureS3TC: function () {
  28901. console.warn( 'THREE.WebGLRenderer: .supportsCompressedTextureS3TC() is now .extensions.get( \'WEBGL_compressed_texture_s3tc\' ).' );
  28902. return this.extensions.get( 'WEBGL_compressed_texture_s3tc' );
  28903. },
  28904. supportsCompressedTexturePVRTC: function () {
  28905. console.warn( 'THREE.WebGLRenderer: .supportsCompressedTexturePVRTC() is now .extensions.get( \'WEBGL_compressed_texture_pvrtc\' ).' );
  28906. return this.extensions.get( 'WEBGL_compressed_texture_pvrtc' );
  28907. },
  28908. supportsBlendMinMax: function () {
  28909. console.warn( 'THREE.WebGLRenderer: .supportsBlendMinMax() is now .extensions.get( \'EXT_blend_minmax\' ).' );
  28910. return this.extensions.get( 'EXT_blend_minmax' );
  28911. },
  28912. supportsVertexTextures: function () {
  28913. console.warn( 'THREE.WebGLRenderer: .supportsVertexTextures() is now .capabilities.vertexTextures.' );
  28914. return this.capabilities.vertexTextures;
  28915. },
  28916. supportsInstancedArrays: function () {
  28917. console.warn( 'THREE.WebGLRenderer: .supportsInstancedArrays() is now .extensions.get( \'ANGLE_instanced_arrays\' ).' );
  28918. return this.extensions.get( 'ANGLE_instanced_arrays' );
  28919. },
  28920. enableScissorTest: function ( boolean ) {
  28921. console.warn( 'THREE.WebGLRenderer: .enableScissorTest() is now .setScissorTest().' );
  28922. this.setScissorTest( boolean );
  28923. },
  28924. initMaterial: function () {
  28925. console.warn( 'THREE.WebGLRenderer: .initMaterial() has been removed.' );
  28926. },
  28927. addPrePlugin: function () {
  28928. console.warn( 'THREE.WebGLRenderer: .addPrePlugin() has been removed.' );
  28929. },
  28930. addPostPlugin: function () {
  28931. console.warn( 'THREE.WebGLRenderer: .addPostPlugin() has been removed.' );
  28932. },
  28933. updateShadowMap: function () {
  28934. console.warn( 'THREE.WebGLRenderer: .updateShadowMap() has been removed.' );
  28935. },
  28936. setFaceCulling: function () {
  28937. console.warn( 'THREE.WebGLRenderer: .setFaceCulling() has been removed.' );
  28938. },
  28939. allocTextureUnit: function () {
  28940. console.warn( 'THREE.WebGLRenderer: .allocTextureUnit() has been removed.' );
  28941. },
  28942. setTexture: function () {
  28943. console.warn( 'THREE.WebGLRenderer: .setTexture() has been removed.' );
  28944. },
  28945. setTexture2D: function () {
  28946. console.warn( 'THREE.WebGLRenderer: .setTexture2D() has been removed.' );
  28947. },
  28948. setTextureCube: function () {
  28949. console.warn( 'THREE.WebGLRenderer: .setTextureCube() has been removed.' );
  28950. },
  28951. getActiveMipMapLevel: function () {
  28952. console.warn( 'THREE.WebGLRenderer: .getActiveMipMapLevel() is now .getActiveMipmapLevel().' );
  28953. return this.getActiveMipmapLevel();
  28954. }
  28955. } );
  28956. Object.defineProperties( WebGLRenderer.prototype, {
  28957. shadowMapEnabled: {
  28958. get: function () {
  28959. return this.shadowMap.enabled;
  28960. },
  28961. set: function ( value ) {
  28962. console.warn( 'THREE.WebGLRenderer: .shadowMapEnabled is now .shadowMap.enabled.' );
  28963. this.shadowMap.enabled = value;
  28964. }
  28965. },
  28966. shadowMapType: {
  28967. get: function () {
  28968. return this.shadowMap.type;
  28969. },
  28970. set: function ( value ) {
  28971. console.warn( 'THREE.WebGLRenderer: .shadowMapType is now .shadowMap.type.' );
  28972. this.shadowMap.type = value;
  28973. }
  28974. },
  28975. shadowMapCullFace: {
  28976. get: function () {
  28977. console.warn( 'THREE.WebGLRenderer: .shadowMapCullFace has been removed. Set Material.shadowSide instead.' );
  28978. return undefined;
  28979. },
  28980. set: function ( /* value */ ) {
  28981. console.warn( 'THREE.WebGLRenderer: .shadowMapCullFace has been removed. Set Material.shadowSide instead.' );
  28982. }
  28983. },
  28984. context: {
  28985. get: function () {
  28986. console.warn( 'THREE.WebGLRenderer: .context has been removed. Use .getContext() instead.' );
  28987. return this.getContext();
  28988. }
  28989. }
  28990. } );
  28991. Object.defineProperties( WebGLShadowMap.prototype, {
  28992. cullFace: {
  28993. get: function () {
  28994. console.warn( 'THREE.WebGLRenderer: .shadowMap.cullFace has been removed. Set Material.shadowSide instead.' );
  28995. return undefined;
  28996. },
  28997. set: function ( /* cullFace */ ) {
  28998. console.warn( 'THREE.WebGLRenderer: .shadowMap.cullFace has been removed. Set Material.shadowSide instead.' );
  28999. }
  29000. },
  29001. renderReverseSided: {
  29002. get: function () {
  29003. console.warn( 'THREE.WebGLRenderer: .shadowMap.renderReverseSided has been removed. Set Material.shadowSide instead.' );
  29004. return undefined;
  29005. },
  29006. set: function () {
  29007. console.warn( 'THREE.WebGLRenderer: .shadowMap.renderReverseSided has been removed. Set Material.shadowSide instead.' );
  29008. }
  29009. },
  29010. renderSingleSided: {
  29011. get: function () {
  29012. console.warn( 'THREE.WebGLRenderer: .shadowMap.renderSingleSided has been removed. Set Material.shadowSide instead.' );
  29013. return undefined;
  29014. },
  29015. set: function () {
  29016. console.warn( 'THREE.WebGLRenderer: .shadowMap.renderSingleSided has been removed. Set Material.shadowSide instead.' );
  29017. }
  29018. }
  29019. } );
  29020. //
  29021. Object.defineProperties( WebGLRenderTargetCube.prototype, {
  29022. activeCubeFace: {
  29023. set: function ( /* value */ ) {
  29024. console.warn( 'THREE.WebGLRenderTargetCube: .activeCubeFace has been removed. It is now the second parameter of WebGLRenderer.setRenderTarget().' );
  29025. }
  29026. },
  29027. activeMipMapLevel: {
  29028. set: function ( /* value */ ) {
  29029. console.warn( 'THREE.WebGLRenderTargetCube: .activeMipMapLevel has been removed. It is now the third parameter of WebGLRenderer.setRenderTarget().' );
  29030. }
  29031. }
  29032. } );
  29033. //
  29034. Object.defineProperties( WebGLRenderTarget.prototype, {
  29035. wrapS: {
  29036. get: function () {
  29037. console.warn( 'THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.' );
  29038. return this.texture.wrapS;
  29039. },
  29040. set: function ( value ) {
  29041. console.warn( 'THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.' );
  29042. this.texture.wrapS = value;
  29043. }
  29044. },
  29045. wrapT: {
  29046. get: function () {
  29047. console.warn( 'THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.' );
  29048. return this.texture.wrapT;
  29049. },
  29050. set: function ( value ) {
  29051. console.warn( 'THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.' );
  29052. this.texture.wrapT = value;
  29053. }
  29054. },
  29055. magFilter: {
  29056. get: function () {
  29057. console.warn( 'THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.' );
  29058. return this.texture.magFilter;
  29059. },
  29060. set: function ( value ) {
  29061. console.warn( 'THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.' );
  29062. this.texture.magFilter = value;
  29063. }
  29064. },
  29065. minFilter: {
  29066. get: function () {
  29067. console.warn( 'THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.' );
  29068. return this.texture.minFilter;
  29069. },
  29070. set: function ( value ) {
  29071. console.warn( 'THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.' );
  29072. this.texture.minFilter = value;
  29073. }
  29074. },
  29075. anisotropy: {
  29076. get: function () {
  29077. console.warn( 'THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy.' );
  29078. return this.texture.anisotropy;
  29079. },
  29080. set: function ( value ) {
  29081. console.warn( 'THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy.' );
  29082. this.texture.anisotropy = value;
  29083. }
  29084. },
  29085. offset: {
  29086. get: function () {
  29087. console.warn( 'THREE.WebGLRenderTarget: .offset is now .texture.offset.' );
  29088. return this.texture.offset;
  29089. },
  29090. set: function ( value ) {
  29091. console.warn( 'THREE.WebGLRenderTarget: .offset is now .texture.offset.' );
  29092. this.texture.offset = value;
  29093. }
  29094. },
  29095. repeat: {
  29096. get: function () {
  29097. console.warn( 'THREE.WebGLRenderTarget: .repeat is now .texture.repeat.' );
  29098. return this.texture.repeat;
  29099. },
  29100. set: function ( value ) {
  29101. console.warn( 'THREE.WebGLRenderTarget: .repeat is now .texture.repeat.' );
  29102. this.texture.repeat = value;
  29103. }
  29104. },
  29105. format: {
  29106. get: function () {
  29107. console.warn( 'THREE.WebGLRenderTarget: .format is now .texture.format.' );
  29108. return this.texture.format;
  29109. },
  29110. set: function ( value ) {
  29111. console.warn( 'THREE.WebGLRenderTarget: .format is now .texture.format.' );
  29112. this.texture.format = value;
  29113. }
  29114. },
  29115. type: {
  29116. get: function () {
  29117. console.warn( 'THREE.WebGLRenderTarget: .type is now .texture.type.' );
  29118. return this.texture.type;
  29119. },
  29120. set: function ( value ) {
  29121. console.warn( 'THREE.WebGLRenderTarget: .type is now .texture.type.' );
  29122. this.texture.type = value;
  29123. }
  29124. },
  29125. generateMipmaps: {
  29126. get: function () {
  29127. console.warn( 'THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps.' );
  29128. return this.texture.generateMipmaps;
  29129. },
  29130. set: function ( value ) {
  29131. console.warn( 'THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps.' );
  29132. this.texture.generateMipmaps = value;
  29133. }
  29134. }
  29135. } );
  29136. //
  29137. Object.defineProperties( WebVRManager.prototype, {
  29138. standing: {
  29139. set: function ( /* value */ ) {
  29140. console.warn( 'THREE.WebVRManager: .standing has been removed.' );
  29141. }
  29142. },
  29143. userHeight: {
  29144. set: function ( /* value */ ) {
  29145. console.warn( 'THREE.WebVRManager: .userHeight has been removed.' );
  29146. }
  29147. }
  29148. } );
  29149. //
  29150. Audio.prototype.load = function ( file ) {
  29151. console.warn( 'THREE.Audio: .load has been deprecated. Use THREE.AudioLoader instead.' );
  29152. var scope = this;
  29153. var audioLoader = new AudioLoader();
  29154. audioLoader.load( file, function ( buffer ) {
  29155. scope.setBuffer( buffer );
  29156. } );
  29157. return this;
  29158. };
  29159. AudioAnalyser.prototype.getData = function () {
  29160. console.warn( 'THREE.AudioAnalyser: .getData() is now .getFrequencyData().' );
  29161. return this.getFrequencyData();
  29162. };
  29163. //
  29164. CubeCamera.prototype.updateCubeMap = function ( renderer, scene ) {
  29165. console.warn( 'THREE.CubeCamera: .updateCubeMap() is now .update().' );
  29166. return this.update( renderer, scene );
  29167. };
  29168. //
  29169. var GeometryUtils = {
  29170. merge: function ( geometry1, geometry2, materialIndexOffset ) {
  29171. console.warn( 'THREE.GeometryUtils: .merge() has been moved to Geometry. Use geometry.merge( geometry2, matrix, materialIndexOffset ) instead.' );
  29172. var matrix;
  29173. if ( geometry2.isMesh ) {
  29174. geometry2.matrixAutoUpdate && geometry2.updateMatrix();
  29175. matrix = geometry2.matrix;
  29176. geometry2 = geometry2.geometry;
  29177. }
  29178. geometry1.merge( geometry2, matrix, materialIndexOffset );
  29179. },
  29180. center: function ( geometry ) {
  29181. console.warn( 'THREE.GeometryUtils: .center() has been moved to Geometry. Use geometry.center() instead.' );
  29182. return geometry.center();
  29183. }
  29184. };
  29185. ImageUtils.crossOrigin = undefined;
  29186. ImageUtils.loadTexture = function ( url, mapping, onLoad, onError ) {
  29187. console.warn( 'THREE.ImageUtils.loadTexture has been deprecated. Use THREE.TextureLoader() instead.' );
  29188. var loader = new TextureLoader();
  29189. loader.setCrossOrigin( this.crossOrigin );
  29190. var texture = loader.load( url, onLoad, undefined, onError );
  29191. if ( mapping ) texture.mapping = mapping;
  29192. return texture;
  29193. };
  29194. ImageUtils.loadTextureCube = function ( urls, mapping, onLoad, onError ) {
  29195. console.warn( 'THREE.ImageUtils.loadTextureCube has been deprecated. Use THREE.CubeTextureLoader() instead.' );
  29196. var loader = new CubeTextureLoader();
  29197. loader.setCrossOrigin( this.crossOrigin );
  29198. var texture = loader.load( urls, onLoad, undefined, onError );
  29199. if ( mapping ) texture.mapping = mapping;
  29200. return texture;
  29201. };
  29202. ImageUtils.loadCompressedTexture = function () {
  29203. console.error( 'THREE.ImageUtils.loadCompressedTexture has been removed. Use THREE.DDSLoader instead.' );
  29204. };
  29205. ImageUtils.loadCompressedTextureCube = function () {
  29206. console.error( 'THREE.ImageUtils.loadCompressedTextureCube has been removed. Use THREE.DDSLoader instead.' );
  29207. };
  29208. //
  29209. function CanvasRenderer() {
  29210. console.error( 'THREE.CanvasRenderer has been removed' );
  29211. }
  29212. //
  29213. function JSONLoader() {
  29214. console.error( 'THREE.JSONLoader has been removed.' );
  29215. }
  29216. //
  29217. var SceneUtils = {
  29218. createMultiMaterialObject: function ( /* geometry, materials */ ) {
  29219. console.error( 'THREE.SceneUtils has been moved to /examples/js/utils/SceneUtils.js' );
  29220. },
  29221. detach: function ( /* child, parent, scene */ ) {
  29222. console.error( 'THREE.SceneUtils has been moved to /examples/js/utils/SceneUtils.js' );
  29223. },
  29224. attach: function ( /* child, scene, parent */ ) {
  29225. console.error( 'THREE.SceneUtils has been moved to /examples/js/utils/SceneUtils.js' );
  29226. }
  29227. };
  29228. //
  29229. function LensFlare() {
  29230. console.error( 'THREE.LensFlare has been moved to /examples/js/objects/Lensflare.js' );
  29231. }
  29232. exports.ACESFilmicToneMapping = ACESFilmicToneMapping;
  29233. exports.AddEquation = AddEquation;
  29234. exports.AddOperation = AddOperation;
  29235. exports.AdditiveBlending = AdditiveBlending;
  29236. exports.AlphaFormat = AlphaFormat;
  29237. exports.AlwaysDepth = AlwaysDepth;
  29238. exports.AlwaysStencilFunc = AlwaysStencilFunc;
  29239. exports.AmbientLight = AmbientLight;
  29240. exports.AmbientLightProbe = AmbientLightProbe;
  29241. exports.AnimationClip = AnimationClip;
  29242. exports.AnimationLoader = AnimationLoader;
  29243. exports.AnimationMixer = AnimationMixer;
  29244. exports.AnimationObjectGroup = AnimationObjectGroup;
  29245. exports.AnimationUtils = AnimationUtils;
  29246. exports.ArcCurve = ArcCurve;
  29247. exports.ArrayCamera = ArrayCamera;
  29248. exports.ArrowHelper = ArrowHelper;
  29249. exports.Audio = Audio;
  29250. exports.AudioAnalyser = AudioAnalyser;
  29251. exports.AudioContext = AudioContext;
  29252. exports.AudioListener = AudioListener;
  29253. exports.AudioLoader = AudioLoader;
  29254. exports.AxesHelper = AxesHelper;
  29255. exports.AxisHelper = AxisHelper;
  29256. exports.BackSide = BackSide;
  29257. exports.BasicDepthPacking = BasicDepthPacking;
  29258. exports.BasicShadowMap = BasicShadowMap;
  29259. exports.BinaryTextureLoader = BinaryTextureLoader;
  29260. exports.Bone = Bone;
  29261. exports.BooleanKeyframeTrack = BooleanKeyframeTrack;
  29262. exports.BoundingBoxHelper = BoundingBoxHelper;
  29263. exports.Box2 = Box2;
  29264. exports.Box3 = Box3;
  29265. exports.Box3Helper = Box3Helper;
  29266. exports.BoxBufferGeometry = BoxBufferGeometry;
  29267. exports.BoxGeometry = BoxGeometry;
  29268. exports.BoxHelper = BoxHelper;
  29269. exports.BufferAttribute = BufferAttribute;
  29270. exports.BufferGeometry = BufferGeometry;
  29271. exports.BufferGeometryLoader = BufferGeometryLoader;
  29272. exports.ByteType = ByteType;
  29273. exports.Cache = Cache;
  29274. exports.Camera = Camera;
  29275. exports.CameraHelper = CameraHelper;
  29276. exports.CanvasRenderer = CanvasRenderer;
  29277. exports.CanvasTexture = CanvasTexture;
  29278. exports.CatmullRomCurve3 = CatmullRomCurve3;
  29279. exports.CineonToneMapping = CineonToneMapping;
  29280. exports.CircleBufferGeometry = CircleBufferGeometry;
  29281. exports.CircleGeometry = CircleGeometry;
  29282. exports.ClampToEdgeWrapping = ClampToEdgeWrapping;
  29283. exports.Clock = Clock;
  29284. exports.ClosedSplineCurve3 = ClosedSplineCurve3;
  29285. exports.Color = Color;
  29286. exports.ColorKeyframeTrack = ColorKeyframeTrack;
  29287. exports.CompressedTexture = CompressedTexture;
  29288. exports.CompressedTextureLoader = CompressedTextureLoader;
  29289. exports.ConeBufferGeometry = ConeBufferGeometry;
  29290. exports.ConeGeometry = ConeGeometry;
  29291. exports.CubeCamera = CubeCamera;
  29292. exports.CubeGeometry = BoxGeometry;
  29293. exports.CubeReflectionMapping = CubeReflectionMapping;
  29294. exports.CubeRefractionMapping = CubeRefractionMapping;
  29295. exports.CubeTexture = CubeTexture;
  29296. exports.CubeTextureLoader = CubeTextureLoader;
  29297. exports.CubeUVReflectionMapping = CubeUVReflectionMapping;
  29298. exports.CubeUVRefractionMapping = CubeUVRefractionMapping;
  29299. exports.CubicBezierCurve = CubicBezierCurve;
  29300. exports.CubicBezierCurve3 = CubicBezierCurve3;
  29301. exports.CubicInterpolant = CubicInterpolant;
  29302. exports.CullFaceBack = CullFaceBack;
  29303. exports.CullFaceFront = CullFaceFront;
  29304. exports.CullFaceFrontBack = CullFaceFrontBack;
  29305. exports.CullFaceNone = CullFaceNone;
  29306. exports.Curve = Curve;
  29307. exports.CurvePath = CurvePath;
  29308. exports.CustomBlending = CustomBlending;
  29309. exports.CylinderBufferGeometry = CylinderBufferGeometry;
  29310. exports.CylinderGeometry = CylinderGeometry;
  29311. exports.Cylindrical = Cylindrical;
  29312. exports.DataTexture = DataTexture;
  29313. exports.DataTexture2DArray = DataTexture2DArray;
  29314. exports.DataTexture3D = DataTexture3D;
  29315. exports.DataTextureLoader = DataTextureLoader;
  29316. exports.DecrementStencilOp = DecrementStencilOp;
  29317. exports.DecrementWrapStencilOp = DecrementWrapStencilOp;
  29318. exports.DefaultLoadingManager = DefaultLoadingManager;
  29319. exports.DepthFormat = DepthFormat;
  29320. exports.DepthStencilFormat = DepthStencilFormat;
  29321. exports.DepthTexture = DepthTexture;
  29322. exports.DirectionalLight = DirectionalLight;
  29323. exports.DirectionalLightHelper = DirectionalLightHelper;
  29324. exports.DirectionalLightShadow = DirectionalLightShadow;
  29325. exports.DiscreteInterpolant = DiscreteInterpolant;
  29326. exports.DodecahedronBufferGeometry = DodecahedronBufferGeometry;
  29327. exports.DodecahedronGeometry = DodecahedronGeometry;
  29328. exports.DoubleSide = DoubleSide;
  29329. exports.DstAlphaFactor = DstAlphaFactor;
  29330. exports.DstColorFactor = DstColorFactor;
  29331. exports.DynamicBufferAttribute = DynamicBufferAttribute;
  29332. exports.EdgesGeometry = EdgesGeometry;
  29333. exports.EdgesHelper = EdgesHelper;
  29334. exports.EllipseCurve = EllipseCurve;
  29335. exports.EqualDepth = EqualDepth;
  29336. exports.EqualStencilFunc = EqualStencilFunc;
  29337. exports.EquirectangularReflectionMapping = EquirectangularReflectionMapping;
  29338. exports.EquirectangularRefractionMapping = EquirectangularRefractionMapping;
  29339. exports.Euler = Euler;
  29340. exports.EventDispatcher = EventDispatcher;
  29341. exports.ExtrudeBufferGeometry = ExtrudeBufferGeometry;
  29342. exports.ExtrudeGeometry = ExtrudeGeometry;
  29343. exports.Face3 = Face3;
  29344. exports.Face4 = Face4;
  29345. exports.FaceColors = FaceColors;
  29346. exports.FaceNormalsHelper = FaceNormalsHelper;
  29347. exports.FileLoader = FileLoader;
  29348. exports.FlatShading = FlatShading;
  29349. exports.Float32Attribute = Float32Attribute;
  29350. exports.Float32BufferAttribute = Float32BufferAttribute;
  29351. exports.Float64Attribute = Float64Attribute;
  29352. exports.Float64BufferAttribute = Float64BufferAttribute;
  29353. exports.FloatType = FloatType;
  29354. exports.Fog = Fog;
  29355. exports.FogExp2 = FogExp2;
  29356. exports.Font = Font;
  29357. exports.FontLoader = FontLoader;
  29358. exports.FrontFaceDirectionCCW = FrontFaceDirectionCCW;
  29359. exports.FrontFaceDirectionCW = FrontFaceDirectionCW;
  29360. exports.FrontSide = FrontSide;
  29361. exports.Frustum = Frustum;
  29362. exports.GammaEncoding = GammaEncoding;
  29363. exports.Geometry = Geometry;
  29364. exports.GeometryUtils = GeometryUtils;
  29365. exports.GreaterDepth = GreaterDepth;
  29366. exports.GreaterEqualDepth = GreaterEqualDepth;
  29367. exports.GreaterEqualStencilFunc = GreaterEqualStencilFunc;
  29368. exports.GreaterStencilFunc = GreaterStencilFunc;
  29369. exports.GridHelper = GridHelper;
  29370. exports.Group = Group;
  29371. exports.HalfFloatType = HalfFloatType;
  29372. exports.HemisphereLight = HemisphereLight;
  29373. exports.HemisphereLightHelper = HemisphereLightHelper;
  29374. exports.HemisphereLightProbe = HemisphereLightProbe;
  29375. exports.IcosahedronBufferGeometry = IcosahedronBufferGeometry;
  29376. exports.IcosahedronGeometry = IcosahedronGeometry;
  29377. exports.ImageBitmapLoader = ImageBitmapLoader;
  29378. exports.ImageLoader = ImageLoader;
  29379. exports.ImageUtils = ImageUtils;
  29380. exports.ImmediateRenderObject = ImmediateRenderObject;
  29381. exports.IncrementStencilOp = IncrementStencilOp;
  29382. exports.IncrementWrapStencilOp = IncrementWrapStencilOp;
  29383. exports.InstancedBufferAttribute = InstancedBufferAttribute;
  29384. exports.InstancedBufferGeometry = InstancedBufferGeometry;
  29385. exports.InstancedInterleavedBuffer = InstancedInterleavedBuffer;
  29386. exports.Int16Attribute = Int16Attribute;
  29387. exports.Int16BufferAttribute = Int16BufferAttribute;
  29388. exports.Int32Attribute = Int32Attribute;
  29389. exports.Int32BufferAttribute = Int32BufferAttribute;
  29390. exports.Int8Attribute = Int8Attribute;
  29391. exports.Int8BufferAttribute = Int8BufferAttribute;
  29392. exports.IntType = IntType;
  29393. exports.InterleavedBuffer = InterleavedBuffer;
  29394. exports.InterleavedBufferAttribute = InterleavedBufferAttribute;
  29395. exports.Interpolant = Interpolant;
  29396. exports.InterpolateDiscrete = InterpolateDiscrete;
  29397. exports.InterpolateLinear = InterpolateLinear;
  29398. exports.InterpolateSmooth = InterpolateSmooth;
  29399. exports.InvertStencilOp = InvertStencilOp;
  29400. exports.JSONLoader = JSONLoader;
  29401. exports.KeepStencilOp = KeepStencilOp;
  29402. exports.KeyframeTrack = KeyframeTrack;
  29403. exports.LOD = LOD;
  29404. exports.LatheBufferGeometry = LatheBufferGeometry;
  29405. exports.LatheGeometry = LatheGeometry;
  29406. exports.Layers = Layers;
  29407. exports.LensFlare = LensFlare;
  29408. exports.LessDepth = LessDepth;
  29409. exports.LessEqualDepth = LessEqualDepth;
  29410. exports.LessEqualStencilFunc = LessEqualStencilFunc;
  29411. exports.LessStencilFunc = LessStencilFunc;
  29412. exports.Light = Light;
  29413. exports.LightProbe = LightProbe;
  29414. exports.LightProbeHelper = LightProbeHelper;
  29415. exports.LightShadow = LightShadow;
  29416. exports.Line = Line;
  29417. exports.Line3 = Line3;
  29418. exports.LineBasicMaterial = LineBasicMaterial;
  29419. exports.LineCurve = LineCurve;
  29420. exports.LineCurve3 = LineCurve3;
  29421. exports.LineDashedMaterial = LineDashedMaterial;
  29422. exports.LineLoop = LineLoop;
  29423. exports.LinePieces = LinePieces;
  29424. exports.LineSegments = LineSegments;
  29425. exports.LineStrip = LineStrip;
  29426. exports.LinearEncoding = LinearEncoding;
  29427. exports.LinearFilter = LinearFilter;
  29428. exports.LinearInterpolant = LinearInterpolant;
  29429. exports.LinearMipMapLinearFilter = LinearMipMapLinearFilter;
  29430. exports.LinearMipMapNearestFilter = LinearMipMapNearestFilter;
  29431. exports.LinearMipmapLinearFilter = LinearMipmapLinearFilter;
  29432. exports.LinearMipmapNearestFilter = LinearMipmapNearestFilter;
  29433. exports.LinearToneMapping = LinearToneMapping;
  29434. exports.Loader = Loader;
  29435. exports.LoaderUtils = LoaderUtils;
  29436. exports.LoadingManager = LoadingManager;
  29437. exports.LogLuvEncoding = LogLuvEncoding;
  29438. exports.LoopOnce = LoopOnce;
  29439. exports.LoopPingPong = LoopPingPong;
  29440. exports.LoopRepeat = LoopRepeat;
  29441. exports.LuminanceAlphaFormat = LuminanceAlphaFormat;
  29442. exports.LuminanceFormat = LuminanceFormat;
  29443. exports.MOUSE = MOUSE;
  29444. exports.Material = Material;
  29445. exports.MaterialLoader = MaterialLoader;
  29446. exports.Math = _Math;
  29447. exports.Matrix3 = Matrix3;
  29448. exports.Matrix4 = Matrix4;
  29449. exports.MaxEquation = MaxEquation;
  29450. exports.Mesh = Mesh;
  29451. exports.MeshBasicMaterial = MeshBasicMaterial;
  29452. exports.MeshDepthMaterial = MeshDepthMaterial;
  29453. exports.MeshDistanceMaterial = MeshDistanceMaterial;
  29454. exports.MeshFaceMaterial = MeshFaceMaterial;
  29455. exports.MeshLambertMaterial = MeshLambertMaterial;
  29456. exports.MeshMatcapMaterial = MeshMatcapMaterial;
  29457. exports.MeshNormalMaterial = MeshNormalMaterial;
  29458. exports.MeshPhongMaterial = MeshPhongMaterial;
  29459. exports.MeshPhysicalMaterial = MeshPhysicalMaterial;
  29460. exports.MeshStandardMaterial = MeshStandardMaterial;
  29461. exports.MeshToonMaterial = MeshToonMaterial;
  29462. exports.MinEquation = MinEquation;
  29463. exports.MirroredRepeatWrapping = MirroredRepeatWrapping;
  29464. exports.MixOperation = MixOperation;
  29465. exports.MultiMaterial = MultiMaterial;
  29466. exports.MultiplyBlending = MultiplyBlending;
  29467. exports.MultiplyOperation = MultiplyOperation;
  29468. exports.NearestFilter = NearestFilter;
  29469. exports.NearestMipMapLinearFilter = NearestMipMapLinearFilter;
  29470. exports.NearestMipMapNearestFilter = NearestMipMapNearestFilter;
  29471. exports.NearestMipmapLinearFilter = NearestMipmapLinearFilter;
  29472. exports.NearestMipmapNearestFilter = NearestMipmapNearestFilter;
  29473. exports.NeverDepth = NeverDepth;
  29474. exports.NeverStencilFunc = NeverStencilFunc;
  29475. exports.NoBlending = NoBlending;
  29476. exports.NoColors = NoColors;
  29477. exports.NoToneMapping = NoToneMapping;
  29478. exports.NormalBlending = NormalBlending;
  29479. exports.NotEqualDepth = NotEqualDepth;
  29480. exports.NotEqualStencilFunc = NotEqualStencilFunc;
  29481. exports.NumberKeyframeTrack = NumberKeyframeTrack;
  29482. exports.Object3D = Object3D;
  29483. exports.ObjectLoader = ObjectLoader;
  29484. exports.ObjectSpaceNormalMap = ObjectSpaceNormalMap;
  29485. exports.OctahedronBufferGeometry = OctahedronBufferGeometry;
  29486. exports.OctahedronGeometry = OctahedronGeometry;
  29487. exports.OneFactor = OneFactor;
  29488. exports.OneMinusDstAlphaFactor = OneMinusDstAlphaFactor;
  29489. exports.OneMinusDstColorFactor = OneMinusDstColorFactor;
  29490. exports.OneMinusSrcAlphaFactor = OneMinusSrcAlphaFactor;
  29491. exports.OneMinusSrcColorFactor = OneMinusSrcColorFactor;
  29492. exports.OrthographicCamera = OrthographicCamera;
  29493. exports.PCFShadowMap = PCFShadowMap;
  29494. exports.PCFSoftShadowMap = PCFSoftShadowMap;
  29495. exports.ParametricBufferGeometry = ParametricBufferGeometry;
  29496. exports.ParametricGeometry = ParametricGeometry;
  29497. exports.Particle = Particle;
  29498. exports.ParticleBasicMaterial = ParticleBasicMaterial;
  29499. exports.ParticleSystem = ParticleSystem;
  29500. exports.ParticleSystemMaterial = ParticleSystemMaterial;
  29501. exports.Path = Path;
  29502. exports.PerspectiveCamera = PerspectiveCamera;
  29503. exports.Plane = Plane;
  29504. exports.PlaneBufferGeometry = PlaneBufferGeometry;
  29505. exports.PlaneGeometry = PlaneGeometry;
  29506. exports.PlaneHelper = PlaneHelper;
  29507. exports.PointCloud = PointCloud;
  29508. exports.PointCloudMaterial = PointCloudMaterial;
  29509. exports.PointLight = PointLight;
  29510. exports.PointLightHelper = PointLightHelper;
  29511. exports.Points = Points;
  29512. exports.PointsMaterial = PointsMaterial;
  29513. exports.PolarGridHelper = PolarGridHelper;
  29514. exports.PolyhedronBufferGeometry = PolyhedronBufferGeometry;
  29515. exports.PolyhedronGeometry = PolyhedronGeometry;
  29516. exports.PositionalAudio = PositionalAudio;
  29517. exports.PositionalAudioHelper = PositionalAudioHelper;
  29518. exports.PropertyBinding = PropertyBinding;
  29519. exports.PropertyMixer = PropertyMixer;
  29520. exports.QuadraticBezierCurve = QuadraticBezierCurve;
  29521. exports.QuadraticBezierCurve3 = QuadraticBezierCurve3;
  29522. exports.Quaternion = Quaternion;
  29523. exports.QuaternionKeyframeTrack = QuaternionKeyframeTrack;
  29524. exports.QuaternionLinearInterpolant = QuaternionLinearInterpolant;
  29525. exports.REVISION = REVISION;
  29526. exports.RGBADepthPacking = RGBADepthPacking;
  29527. exports.RGBAFormat = RGBAFormat;
  29528. exports.RGBA_ASTC_10x10_Format = RGBA_ASTC_10x10_Format;
  29529. exports.RGBA_ASTC_10x5_Format = RGBA_ASTC_10x5_Format;
  29530. exports.RGBA_ASTC_10x6_Format = RGBA_ASTC_10x6_Format;
  29531. exports.RGBA_ASTC_10x8_Format = RGBA_ASTC_10x8_Format;
  29532. exports.RGBA_ASTC_12x10_Format = RGBA_ASTC_12x10_Format;
  29533. exports.RGBA_ASTC_12x12_Format = RGBA_ASTC_12x12_Format;
  29534. exports.RGBA_ASTC_4x4_Format = RGBA_ASTC_4x4_Format;
  29535. exports.RGBA_ASTC_5x4_Format = RGBA_ASTC_5x4_Format;
  29536. exports.RGBA_ASTC_5x5_Format = RGBA_ASTC_5x5_Format;
  29537. exports.RGBA_ASTC_6x5_Format = RGBA_ASTC_6x5_Format;
  29538. exports.RGBA_ASTC_6x6_Format = RGBA_ASTC_6x6_Format;
  29539. exports.RGBA_ASTC_8x5_Format = RGBA_ASTC_8x5_Format;
  29540. exports.RGBA_ASTC_8x6_Format = RGBA_ASTC_8x6_Format;
  29541. exports.RGBA_ASTC_8x8_Format = RGBA_ASTC_8x8_Format;
  29542. exports.RGBA_PVRTC_2BPPV1_Format = RGBA_PVRTC_2BPPV1_Format;
  29543. exports.RGBA_PVRTC_4BPPV1_Format = RGBA_PVRTC_4BPPV1_Format;
  29544. exports.RGBA_S3TC_DXT1_Format = RGBA_S3TC_DXT1_Format;
  29545. exports.RGBA_S3TC_DXT3_Format = RGBA_S3TC_DXT3_Format;
  29546. exports.RGBA_S3TC_DXT5_Format = RGBA_S3TC_DXT5_Format;
  29547. exports.RGBDEncoding = RGBDEncoding;
  29548. exports.RGBEEncoding = RGBEEncoding;
  29549. exports.RGBEFormat = RGBEFormat;
  29550. exports.RGBFormat = RGBFormat;
  29551. exports.RGBM16Encoding = RGBM16Encoding;
  29552. exports.RGBM7Encoding = RGBM7Encoding;
  29553. exports.RGB_ETC1_Format = RGB_ETC1_Format;
  29554. exports.RGB_PVRTC_2BPPV1_Format = RGB_PVRTC_2BPPV1_Format;
  29555. exports.RGB_PVRTC_4BPPV1_Format = RGB_PVRTC_4BPPV1_Format;
  29556. exports.RGB_S3TC_DXT1_Format = RGB_S3TC_DXT1_Format;
  29557. exports.RawShaderMaterial = RawShaderMaterial;
  29558. exports.Ray = Ray;
  29559. exports.Raycaster = Raycaster;
  29560. exports.RectAreaLight = RectAreaLight;
  29561. exports.RectAreaLightHelper = RectAreaLightHelper;
  29562. exports.RedFormat = RedFormat;
  29563. exports.ReinhardToneMapping = ReinhardToneMapping;
  29564. exports.RepeatWrapping = RepeatWrapping;
  29565. exports.ReplaceStencilOp = ReplaceStencilOp;
  29566. exports.ReverseSubtractEquation = ReverseSubtractEquation;
  29567. exports.RingBufferGeometry = RingBufferGeometry;
  29568. exports.RingGeometry = RingGeometry;
  29569. exports.Scene = Scene;
  29570. exports.SceneUtils = SceneUtils;
  29571. exports.ShaderChunk = ShaderChunk;
  29572. exports.ShaderLib = ShaderLib;
  29573. exports.ShaderMaterial = ShaderMaterial;
  29574. exports.ShadowMaterial = ShadowMaterial;
  29575. exports.Shape = Shape;
  29576. exports.ShapeBufferGeometry = ShapeBufferGeometry;
  29577. exports.ShapeGeometry = ShapeGeometry;
  29578. exports.ShapePath = ShapePath;
  29579. exports.ShapeUtils = ShapeUtils;
  29580. exports.ShortType = ShortType;
  29581. exports.Skeleton = Skeleton;
  29582. exports.SkeletonHelper = SkeletonHelper;
  29583. exports.SkinnedMesh = SkinnedMesh;
  29584. exports.SmoothShading = SmoothShading;
  29585. exports.Sphere = Sphere;
  29586. exports.SphereBufferGeometry = SphereBufferGeometry;
  29587. exports.SphereGeometry = SphereGeometry;
  29588. exports.Spherical = Spherical;
  29589. exports.SphericalHarmonics3 = SphericalHarmonics3;
  29590. exports.SphericalReflectionMapping = SphericalReflectionMapping;
  29591. exports.Spline = Spline;
  29592. exports.SplineCurve = SplineCurve;
  29593. exports.SplineCurve3 = SplineCurve3;
  29594. exports.SpotLight = SpotLight;
  29595. exports.SpotLightHelper = SpotLightHelper;
  29596. exports.SpotLightShadow = SpotLightShadow;
  29597. exports.Sprite = Sprite;
  29598. exports.SpriteMaterial = SpriteMaterial;
  29599. exports.SrcAlphaFactor = SrcAlphaFactor;
  29600. exports.SrcAlphaSaturateFactor = SrcAlphaSaturateFactor;
  29601. exports.SrcColorFactor = SrcColorFactor;
  29602. exports.StereoCamera = StereoCamera;
  29603. exports.StringKeyframeTrack = StringKeyframeTrack;
  29604. exports.SubtractEquation = SubtractEquation;
  29605. exports.SubtractiveBlending = SubtractiveBlending;
  29606. exports.TOUCH = TOUCH;
  29607. exports.TangentSpaceNormalMap = TangentSpaceNormalMap;
  29608. exports.TetrahedronBufferGeometry = TetrahedronBufferGeometry;
  29609. exports.TetrahedronGeometry = TetrahedronGeometry;
  29610. exports.TextBufferGeometry = TextBufferGeometry;
  29611. exports.TextGeometry = TextGeometry;
  29612. exports.Texture = Texture;
  29613. exports.TextureLoader = TextureLoader;
  29614. exports.TorusBufferGeometry = TorusBufferGeometry;
  29615. exports.TorusGeometry = TorusGeometry;
  29616. exports.TorusKnotBufferGeometry = TorusKnotBufferGeometry;
  29617. exports.TorusKnotGeometry = TorusKnotGeometry;
  29618. exports.Triangle = Triangle;
  29619. exports.TriangleFanDrawMode = TriangleFanDrawMode;
  29620. exports.TriangleStripDrawMode = TriangleStripDrawMode;
  29621. exports.TrianglesDrawMode = TrianglesDrawMode;
  29622. exports.TubeBufferGeometry = TubeBufferGeometry;
  29623. exports.TubeGeometry = TubeGeometry;
  29624. exports.UVMapping = UVMapping;
  29625. exports.Uint16Attribute = Uint16Attribute;
  29626. exports.Uint16BufferAttribute = Uint16BufferAttribute;
  29627. exports.Uint32Attribute = Uint32Attribute;
  29628. exports.Uint32BufferAttribute = Uint32BufferAttribute;
  29629. exports.Uint8Attribute = Uint8Attribute;
  29630. exports.Uint8BufferAttribute = Uint8BufferAttribute;
  29631. exports.Uint8ClampedAttribute = Uint8ClampedAttribute;
  29632. exports.Uint8ClampedBufferAttribute = Uint8ClampedBufferAttribute;
  29633. exports.Uncharted2ToneMapping = Uncharted2ToneMapping;
  29634. exports.Uniform = Uniform;
  29635. exports.UniformsLib = UniformsLib;
  29636. exports.UniformsUtils = UniformsUtils;
  29637. exports.UnsignedByteType = UnsignedByteType;
  29638. exports.UnsignedInt248Type = UnsignedInt248Type;
  29639. exports.UnsignedIntType = UnsignedIntType;
  29640. exports.UnsignedShort4444Type = UnsignedShort4444Type;
  29641. exports.UnsignedShort5551Type = UnsignedShort5551Type;
  29642. exports.UnsignedShort565Type = UnsignedShort565Type;
  29643. exports.UnsignedShortType = UnsignedShortType;
  29644. exports.Vector2 = Vector2;
  29645. exports.Vector3 = Vector3;
  29646. exports.Vector4 = Vector4;
  29647. exports.VectorKeyframeTrack = VectorKeyframeTrack;
  29648. exports.Vertex = Vertex;
  29649. exports.VertexColors = VertexColors;
  29650. exports.VertexNormalsHelper = VertexNormalsHelper;
  29651. exports.VideoTexture = VideoTexture;
  29652. exports.WebGLMultisampleRenderTarget = WebGLMultisampleRenderTarget;
  29653. exports.WebGLRenderTarget = WebGLRenderTarget;
  29654. exports.WebGLRenderTargetCube = WebGLRenderTargetCube;
  29655. exports.WebGLRenderer = WebGLRenderer;
  29656. exports.WebGLUtils = WebGLUtils;
  29657. exports.WireframeGeometry = WireframeGeometry;
  29658. exports.WireframeHelper = WireframeHelper;
  29659. exports.WrapAroundEnding = WrapAroundEnding;
  29660. exports.XHRLoader = XHRLoader;
  29661. exports.ZeroCurvatureEnding = ZeroCurvatureEnding;
  29662. exports.ZeroFactor = ZeroFactor;
  29663. exports.ZeroSlopeEnding = ZeroSlopeEnding;
  29664. exports.ZeroStencilOp = ZeroStencilOp;
  29665. exports.sRGBEncoding = sRGBEncoding;
  29666. Object.defineProperty(exports, '__esModule', { value: true });
  29667. }));
粤ICP备19079148号